Avoid a crash if a function is imported that has auto return type that
references to a template with an expression-type of argument that
references into the function's body.
Fixes issue #56047
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks, nice work!
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3242 | ||
3242 | The first call of getParents will create the parent map, via a full-blown AST visitation. I am concerned a bit about the additional performance overhead. Could you please run some measurements? (E.g. a CTU run on protobuf and bitcoin with our internal CI infra) | |
3256–3259 | Should this be handled in a switch rather, perhaps with an llvm_unreachable at the default case? Just to make sure that no "kind" is left out. | |
3278–3282 | Is it possible that T is both a RecordType and a TemplateSpecializationType at the same time? From the hierarchy this seems impossible (?) | |
clang/unittests/AST/ASTImporterTest.cpp | ||
6323 | Nice test! |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3278–3282 | The type dump shows that a RecordType is contained within the TemplateSpecializationType and it looks like that the get function handles this case. When the else is added the check of TemplateSpecializationType is skipped and the template argument expression X is not found (only integer constant 1). TemplateSpecializationType 0x23fd8c0 'Tmpl<X>' sugar Tmpl |-TemplateArgument expr | `-ConstantExpr 0x23fd798 'int' | |-value: Int 1 | `-ImplicitCastExpr 0x23fd780 'int' <LValueToRValue> | `-DeclRefExpr 0x23fd760 'const int' lvalue Var 0x23fd648 'X' 'const int' non_odr_use_constant `-RecordType 0x23fd8a0 'struct Tmpl<1>' `-ClassTemplateSpecialization 0x23fd7b8 'Tmpl' |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3278–3282 | Okay. I've dug deeper to understand how that is working. So, in the TemplateSpecializationType 'Tmpl<X>' is actually a "sugar" to the RecordType 'struct Tmpl<1>'. // If this is a typedef for the type, strip the typedef off without // losing all typedef information. return cast<T>(getUnqualifiedDesugaredType()); Thus, to answer my own question, it is possible that T is both a RecordType and a TemplateSpecializationType at the same time! |
LGTM
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3242 |
I've seen the measurement results, they look good. We have errors in the CTU analysis of 'qtbase' and 'contour' even with the base line. The duration for the remaining 3 (xerces, protobuf, bincoin) looks good. |