llvm-project/clang/lib/Sema
Nathan Sidwell c138f3ce5c [clang] Fix ICE with typeid & polymorphic class (pr50497)
This addresses pr50497. The argument of a typeid expression is
unevaluated, *except* when it's a polymorphic type. We handle this by
parsing as unevaluated and then transforming to evaluated if we
discover it should have been an evaluated context.

We do the same in TreeTransform<Derived>::TransformCXXTypeidExpr,
entering unevaluated context before transforming and rebuilding the
typeid. But that's incorrect and can lead us to converting to
evaluated context twice -- and hitting an assert.

During normal template instantiation we're always cloning the
expression, but during generic lambda processing we do not necessarily
AlwaysRebuild, and end up with TransformDeclRefExpr unconditionally
calling MarkDeclRefReferenced around line 10226. That triggers the
assert.

// Mark it referenced in the new context regardless.
// FIXME: this is a bit instantiation-specific.
SemaRef.MarkDeclRefReferenced(E);

This patch makes 2 changes.

a) TreeTransform<Derived>::TransformCXXTypeidExpr only enters
unevaluated context if the typeid's operand is not a polymorphic
glvalue. If it is, it keeps the same evaluation context.

b) Sema::BuildCXXTypeId is altered to only transform to evaluated, if
the current context is unevaluated.

Differential Revision: https://reviews.llvm.org/D103258
2021-06-01 12:55:29 -07:00
..
AnalysisBasedWarnings.cpp [-Wcalled-once] Do not run analysis on Obj-C++ 2021-04-22 15:20:52 +03:00
CMakeLists.txt [clang] Make libBasic not depend on MC 2021-04-28 12:16:22 -04:00
CodeCompleteConsumer.cpp [Sema] Use isa<> instead of dyn_cast<> as pointer is never dereferenced. NFCI. 2020-11-15 12:58:36 +00:00
CoroutineStmtBuilder.h
DeclSpec.cpp Re-commit [clang] Add support for the "abstract" contextual keyword of MSVC 2021-05-31 18:45:26 +02:00
DelayedDiagnostic.cpp
IdentifierResolver.cpp
JumpDiagnostics.cpp [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1 2021-05-17 22:42:17 -07:00
MultiplexExternalSemaSource.cpp [clang][AST] Improve AST Reader/Writer memory footprint 2021-05-20 15:34:29 -07:00
OpenCLBuiltins.td [OpenCL] Add inc/dec/cmpxchg C++ legacy atomics with generic 2021-04-26 09:46:11 +01:00
ParsedAttr.cpp Correct the tablegen for checking mutually exclusive stmt attrs 2021-04-13 15:20:30 -04:00
Scope.cpp
ScopeInfo.cpp [clang] Enable support for #pragma STDC FENV_ACCESS 2020-10-25 06:46:25 -07:00
Sema.cpp [OpenCL] Drop pragma handling for extension types/decls. 2021-05-17 12:09:43 +01:00
SemaAccess.cpp Treat implicit deduction guides as being equivalent to their 2021-05-19 13:31:53 -07:00
SemaAttr.cpp [clang] Make libBasic not depend on MC 2021-04-28 12:16:22 -04:00
SemaAvailability.cpp [clang] RecursiveASTVisitor visits ObjCPropertyRefExpr's class receiver 2021-06-01 14:45:25 -04:00
SemaCUDA.cpp [CUDA][HIP] Fix device variables used by host 2021-05-20 17:04:29 -04:00
SemaCXXScopeSpec.cpp [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00
SemaCast.cpp [Matrix] Move C++ matrix cast checks to TryStaticCast. 2021-05-28 13:00:28 +01:00
SemaChecking.cpp [clang] Fix a crash on CheckArgAlignment. 2021-05-19 13:29:28 +02:00
SemaCodeComplete.cpp Add support for #elifdef and #elifndef 2021-05-27 08:57:47 -04:00
SemaConcept.cpp PR50402: Use proper constant evaluation rules for checking constraint 2021-05-19 16:02:53 -07:00
SemaConsumer.cpp
SemaCoroutine.cpp [C++20] [P1825] More implicit moves 2021-02-16 17:24:20 -05:00
SemaDecl.cpp Re-commit [clang] Add support for the "abstract" contextual keyword of MSVC 2021-05-31 18:45:26 +02:00
SemaDeclAttr.cpp [clang][Parse] Add parsing support for C++ attributes on using-declarations 2021-06-01 08:47:50 -04:00
SemaDeclCXX.cpp [clang][Parse] Add parsing support for C++ attributes on using-declarations 2021-06-01 08:47:50 -04:00
SemaDeclObjC.cpp [ObjC] Add a command line flag that disables recognition of objc_direct for testability 2021-04-06 11:17:01 -04:00
SemaExceptionSpec.cpp Reimplement __builtin_unique_stable_name- 2021-05-27 07:12:20 -07:00
SemaExpr.cpp Reimplement __builtin_unique_stable_name- 2021-05-27 07:12:20 -07:00
SemaExprCXX.cpp [clang] Fix ICE with typeid & polymorphic class (pr50497) 2021-06-01 12:55:29 -07:00
SemaExprMember.cpp [OpenCL] Accept .rgba in OpenCL 3.0 2021-04-12 09:30:06 +01:00
SemaExprObjC.cpp [Sema] Don't set BlockDecl's DoesNotEscape bit if the parameter type of 2021-04-29 16:19:48 -07:00
SemaFixItUtils.cpp
SemaInit.cpp Remove warning "suggest braces" for aggregate initialization of an empty class with an aggregate base class. 2021-04-13 15:45:09 -04:00
SemaLambda.cpp Reimplement __builtin_unique_stable_name- 2021-05-27 07:12:20 -07:00
SemaLookup.cpp [OpenCL] Do not add builtins with unavailable types 2021-04-21 11:59:29 +01:00
SemaModule.cpp Change Module::ASTFile and ModuleFile::File => Optional<FileEntryRef>, NFC 2020-11-02 15:11:51 -05:00
SemaObjCProperty.cpp Make iteration over the DeclContext::lookup_result safe. 2021-03-17 08:59:04 +00:00
SemaOpenMP.cpp [OpenMP] Use compound operators for reduction combiner if available. 2021-05-11 11:39:12 -07:00
SemaOverload.cpp [OpenCL] Drop pragma handling for extension types/decls. 2021-05-17 12:09:43 +01:00
SemaPseudoObject.cpp Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)" 2021-01-04 23:17:45 +01:00
SemaSYCL.cpp Reimplement __builtin_unique_stable_name- 2021-05-27 07:12:20 -07:00
SemaStmt.cpp Introduce -Wreserved-identifier 2021-05-04 11:19:01 +02:00
SemaStmtAsm.cpp Support unwinding from inline assembly 2021-05-13 19:13:03 +01:00
SemaStmtAttr.cpp Implemented [[clang::musttail]] attribute for guaranteed tail calls. 2021-04-15 17:12:21 -07:00
SemaTemplate.cpp Treat implicit deduction guides as being equivalent to their 2021-05-19 13:31:53 -07:00
SemaTemplateDeduction.cpp Add type information to integral template argument if required. 2021-05-12 19:00:08 +00:00
SemaTemplateInstantiate.cpp Clean up handling of constrained parameters in lambdas. 2021-05-12 18:45:33 -07:00
SemaTemplateInstantiateDecl.cpp Reimplement __builtin_unique_stable_name- 2021-05-27 07:12:20 -07:00
SemaTemplateVariadic.cpp Revert "Following up on PR48517, fix handling of template arguments that refer" 2021-01-20 15:55:35 +01:00
SemaType.cpp SwiftAsync: add Clang attribute to apply the LLVM `swiftasync` one. 2021-05-28 12:31:12 +01:00
TreeTransform.h [clang] Fix ICE with typeid & polymorphic class (pr50497) 2021-06-01 12:55:29 -07:00
TypeLocBuilder.cpp [NFC] avoid AlignedCharArray in clang 2019-07-29 23:12:48 +00:00
TypeLocBuilder.h [NFC] avoid AlignedCharArray in clang 2019-07-29 23:12:48 +00:00
UsedDeclVisitor.h DeferredDiagnosticsEmitter crashes 2020-10-08 11:42:21 -04:00