Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE on decltype of dependent member of argument to generic lambda in trailing return type #37792

Closed
eracpp opened this issue Aug 4, 2018 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@eracpp
Copy link

eracpp commented Aug 4, 2018

Bugzilla Link 38444
Version trunk
OS Linux
Attachments [https://user-images.githubusercontent.com/92601314/143757855-e2c4cb61-58e7-416c-bc30-2c3f1c327188.gz), [https://user-images.githubusercontent.com/92601314/143757856-27faa27d-406a-432a-8be7-2a799a996911.gz)
CC @DougGregor

Extended Description

The following code ICEs all known versions of Clang dating back to Clang 3.4
(https://wandbox.org/permlink/HzVyaW9GZcHdNG7g):

struct A { int x; };

int main() {
  [](auto t) -> decltype(decltype(t)::x) { return 0; }(A());
}

Clang ICE's when x is a member of decltype(t).
Oddly, it does not ICE if x is not a member of A.
It also does not ICE if it is not within the trailing return type.
e.g. the following does not ICE:

struct A { int x; };

int main() {
  [](auto t) { return decltype(decltype(t)::x)(0); }(A());
}

#​0 0x00007f68d9bf164b llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/bin/../lib/libLLVM-6.0.so+0x85464b)
#​1 0x00007f68d9bef33e llvm::sys::RunSignalHandlers() (/usr/bin/../lib/libLLVM-6.0.so+0x85233e)
#​2 0x00007f68d9bef5ab (/usr/bin/../lib/libLLVM-6.0.so+0x8525ab)
#​3 0x00007f68d786e8f0 __restore_rt (/usr/bin/../lib/libc.so.6+0x368f0)
#​4 0x00007f68d4d3676b clang::Sema::BuildPossibleImplicitMemberExpr(clang::CXXScopeSpec const&, clang::SourceLocation, clang::LookupResult&, clang::TemplateArgumentListInfo const*, clang::Scope const*) (/usr/bin/../lib/../lib/libclangSema.so.6+0x3f676b)
#​5 0x00007f68d4c99c79 clang::Sema::BuildQualifiedDeclarationNameExpr(clang::CXXScopeSpec&, clang::DeclarationNameInfo const&, bool, clang::Scope const*, clang::TypeSourceInfo**) (/usr/bin/../lib/../lib/libclangSema.so.6+0x359c79)
#​6 0x00007f68d4f3d633 (/usr/bin/../lib/../lib/libclangSema.so.6+0x5fd633)
#​7 0x00007f68d4f25608 (/usr/bin/../lib/../lib/libclangSema.so.6+0x5e5608)
#​8 0x00007f68d4f2d05a (/usr/bin/../lib/../lib/libclangSema.so.6+0x5ed05a)
#​9 0x00007f68d4f41c6b clang::Sema::SubstFunctionDeclType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, clang::CXXRecordDecl*, unsigned int) (/usr/bin/../lib/../lib/libclangSema.so.6+0x601c6b)
#&#8203;10 0x00007f68d4f4aea4 clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*, llvm::SmallVectorImpl<clang::ParmVarDecl*>&) (/usr/bin/../lib/../lib/libclangSema.so.6+0x60aea4)
#&#8203;11 0x00007f68d4f5cdcb clang::TemplateDeclInstantiator::VisitCXXMethodDecl(clang::CXXMethodDecl*, clang::TemplateParameterList*, bool) (/usr/bin/../lib/../lib/libclangSema.so.6+0x61cdcb)
#&#8203;12 0x00007f68d4f5992b clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) (/usr/bin/../lib/../lib/libclangSema.so.6+0x61992b)
#&#8203;13 0x00007f68d4f10cdc clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> const*, bool, llvm::function_ref<bool ()>) (/usr/bin/../lib/../lib/libclangSema.so.6+0x5d0cdc)
#&#8203;14 0x00007f68d4f15ead clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) (/usr/bin/../lib/../lib/libclangSema.so.6+0x5d5ead)
#&#8203;15 0x00007f68d4e26c17 clang::Sema::AddMethodTemplateCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::CXXRecordDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool) (/usr/bin/../lib/../lib/libclangSema.so.6+0x4e6c17)
#&#8203;16 0x00007f68d4e27325 clang::Sema::AddMethodCandidate(clang::DeclAccessPair, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool) (/usr/bin/../lib/../lib/libclangSema.so.6+0x4e7325)
#&#8203;17 0x00007f68d4e39fb3 clang::Sema::BuildCallToObjectOfClassType(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation) (/usr/bin/../lib/../lib/libclangSema.so.6+0x4f9fb3)
#&#8203;18 0x00007f68d4ca1be7 clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool) (/usr/bin/../lib/../lib/libclangSema.so.6+0x361be7)
#&#8203;19 0x00007f68d52cd85a clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/usr/bin/../lib/../lib/libclangParse.so.6+0x6b85a)
#&#8203;20 0x00007f68d52c8124 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState, bool) (/usr/bin/../lib/../lib/libclangParse.so.6+0x66124)
#&#8203;21 0x00007f68d52ca465 clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState, bool) (/usr/bin/../lib/../lib/libclangParse.so.6+0x68465)
#&#8203;22 0x00007f68d52cbb3d clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/usr/bin/../lib/../lib/libclangParse.so.6+0x69b3d)
#&#8203;23 0x00007f68d52cc68a clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/usr/bin/../lib/../lib/libclangParse.so.6+0x6a68a)
#&#8203;24 0x00007f68d53102fb clang::Parser::ParseExprStatement() (/usr/bin/../lib/../lib/libclangParse.so.6+0xae2fb)
#&#8203;25 0x00007f68d5311366 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) (/usr/bin/../lib/../lib/libclangParse.so.6+0xaf366)
#&#8203;26 0x00007f68d53115d6 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*) (/usr/bin/../lib/../lib/libclangParse.so.6+0xaf5d6)
#&#8203;27 0x00007f68d5315370 clang::Parser::ParseCompoundStatementBody(bool) (/usr/bin/../lib/../lib/libclangParse.so.6+0xb3370)
#&#8203;28 0x00007f68d5317cc8 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/usr/bin/../lib/../lib/libclangParse.so.6+0xb5cc8)
#&#8203;29 0x00007f68d5333577 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/usr/bin/../lib/../lib/libclangParse.so.6+0xd1577)
#&#8203;30 0x00007f68d52aa40b clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/usr/bin/../lib/../lib/libclangParse.so.6+0x4840b)
#&#8203;31 0x00007f68d532d5e3 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/usr/bin/../lib/../lib/libclangParse.so.6+0xcb5e3)
#&#8203;32 0x00007f68d532db82 (/usr/bin/../lib/../lib/libclangParse.so.6+0xcbb82)
#&#8203;33 0x00007f68d53347c1 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/bin/../lib/../lib/libclangParse.so.6+0xd27c1)
#&#8203;34 0x00007f68d5335896 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) (/usr/bin/../lib/../lib/libclangParse.so.6+0xd3896)
#&#8203;35 0x00007f68d528c113 clang::ParseAST(clang::Sema&, bool, bool) (/usr/bin/../lib/../lib/libclangParse.so.6+0x2a113)
#&#8203;36 0x00007f68d8b136e8 clang::CodeGenAction::ExecuteAction() (/usr/bin/../lib/libclangCodeGen.so.6+0x2916e8)
#&#8203;37 0x00007f68d8257f26 clang::FrontendAction::Execute() (/usr/bin/../lib/libclangFrontend.so.6+0xd4f26)
#&#8203;38 0x00007f68d82174d9 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/bin/../lib/libclangFrontend.so.6+0x944d9)
#&#8203;39 0x00007f68d7f802d6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/bin/../lib/libclangFrontendTool.so.6+0x32d6)
#&#8203;40 0x0000564f525bd4d9 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang-6.0+0x104d9)
#&#8203;41 0x0000564f525b9b01 main (/usr/bin/clang-6.0+0xcb01)
#&#8203;42 0x00007f68d785b06b __libc_start_main (/usr/bin/../lib/libc.so.6+0x2306b)
#&#8203;43 0x0000564f525baf6a _start (/usr/bin/clang-6.0+0xdf6a)
Stack dump:
0.      Program arguments: /usr/bin/clang-6.0 -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/lib/clang/6.0.1 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/x86_64-pc-linux-gnu -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/clang/6.0.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/eraz/Projects/cpp/shop -ferror-limit 19 -fmessage-length 157 -stack-protector 2 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/main-eb7950.o -x c++ main.cpp 
1.      main.cpp:4:61: current parser token ')'
2.      main.cpp:3:12: parsing function body 'main'
3.      main.cpp:3:12: in compound statement ('{}')
clang-6.0: error: unable to execute command: Segmentation fault (core dumped)
clang-6.0: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-6.0: note: diagnostic msg: PLEASE submit a bug report to  and include the crash backtrace, preprocessed source, and associated run script.
clang-6.0: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-6.0: note: diagnostic msg: /tmp/main-763743.cpp
clang-6.0: note: diagnostic msg: /tmp/main-763743.sh
clang-6.0: note: diagnostic msg: 

********************
@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@oToToT oToToT added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jan 20, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 20, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Jan 20, 2023

Confirmed: https://godbolt.org/z/c4eWdzdzv

Assertion:

clang++: /root/llvm-project/llvm/include/llvm/Support/Casting.h:579: 
decltype(auto) llvm::cast(From*) [with To = clang::CXXRecordDecl; From = clang::DeclContext]:
Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

backtrace:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.	<source>:4:59: current parser token ')'
2.	<source>:3:12: parsing function body 'main'
3.	<source>:3:12: in compound statement ('{}')
 #0 0x000055610310704f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40bc04f)
 #1 0x0000556103104fec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40b9fec)
 #2 0x0000556103052368 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f24bcc33420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f24bc70000b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f24bc6df859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f24bc6df729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f24bc6f0fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x0000556105e6578b clang::Sema::BuildPossibleImplicitMemberExpr(clang::CXXScopeSpec const&, clang::SourceLocation, clang::LookupResult&, clang::TemplateArgumentListInfo const*, clang::Scope const*, clang::UnresolvedLookupExpr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1a78b)
 #9 0x0000556105ca4915 clang::Sema::BuildQualifiedDeclarationNameExpr(clang::CXXScopeSpec&, clang::DeclarationNameInfo const&, bool, clang::Scope const*, clang::TypeSourceInfo**) (.part.0) SemaExpr.cpp:0:0
#10 0x0000556105ca4a57 clang::Sema::BuildQualifiedDeclarationNameExpr(clang::CXXScopeSpec&, clang::DeclarationNameInfo const&, bool, clang::Scope const*, clang::TypeSourceInfo**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c59a57)
#11 0x0000556106279feb clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformDependentScopeDeclRefExpr(clang::DependentScopeDeclRefExpr*, bool, clang::TypeSourceInfo**) SemaTemplateInstantiate.cpp:0:0
#12 0x0000556106256d5d clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#13 0x0000556106265e17 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#14 0x00005561062835f7 clang::Sema::SubstFunctionDeclType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, clang::CXXRecordDecl*, clang::Qualifiers, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72385f7)
#15 0x000055610629beb9 clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*, llvm::SmallVectorImpl<clang::ParmVarDecl*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7250eb9)
#16 0x00005561062e980a clang::TemplateDeclInstantiator::VisitCXXMethodDecl(clang::CXXMethodDecl*, clang::TemplateParameterList*, std::optional<clang::ASTTemplateArgumentListInfo const*>, clang::TemplateDeclInstantiator::RewriteKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x729e80a)
#17 0x00005561062eb5e8 void llvm::function_ref<void ()>::callback_fn<clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&)::'lambda'()>(long) SemaTemplateInstantiateDecl.cpp:0:0
#18 0x00005561058c7dd5 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x687cdd5)
#19 0x000055610629bd31 clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7250d31)
#20 0x0000556106218df2 clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> const*, bool, llvm::function_ref<bool ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71cddf2)
#21 0x000055610621a6ce void llvm::function_ref<void ()>::callback_fn<clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>)::'lambda1'()>(long) SemaTemplateDeduction.cpp:0:0
#22 0x00005561058c7dd5 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x687cdd5)
#23 0x0000556106224d5f clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71d9d5f)
#24 0x0000556106049aac clang::Sema::AddMethodTemplateCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::CXXRecordDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool, clang::OverloadCandidateParamOrder) (.constprop.0) SemaOverload.cpp:0:0
#25 0x0000556106049f07 clang::Sema::AddMethodCandidate(clang::DeclAccessPair, clang::QualType, clang::Expr::Classification, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, clang::OverloadCandidateParamOrder) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ffef07)
#26 0x000055610604b41e clang::Sema::BuildCallToObjectOfClassType(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x700041e)
#27 0x0000556105ce3ca4 clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c98ca4)
#28 0x0000556105d0659b clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cbb59b)
#29 0x00005561057eac39 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x679fc39)
#30 0x00005561057e2d37 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6797d37)
#31 0x00005561057e5ebe clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x679aebe)
#32 0x00005561057e60ad clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x679b0ad)
#33 0x00005561057ea1bd clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x679f1bd)
#34 0x000055610586456e clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x681956e)
#35 0x000055610585abdc clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x680fbdc)
#36 0x000055610585bae5 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6810ae5)
#37 0x000055610585caba clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6811aba)
#38 0x000055610585e46a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x681346a)
#39 0x000055610578dfe1 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6742fe1)
#40 0x00005561057b8d50 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x676dd50)
#41 0x0000556105782402 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6737402)
#42 0x0000556105782caf clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#43 0x0000556105788f99 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x673df99)
#44 0x00005561057898ed clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x673e8ed)
#45 0x000055610577d83a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x673283a)
#46 0x0000556104483338 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5438338)
#47 0x0000556103cf43a9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca93a9)
#48 0x0000556103c7a2ae clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c2f2ae)
#49 0x0000556103dda053 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d8f053)
#50 0x00005561005a0e7d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1555e7d)
#51 0x000055610059cf97 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#52 0x0000556103ae1f19 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#53 0x0000556103052850 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4007850)
#54 0x0000556103ae27cf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#55 0x0000556103aaafac clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a5ffac)
#56 0x0000556103aaba2d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a60a2d)
#57 0x0000556103ab4bfc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a69bfc)
#58 0x000055610059f5e2 clang_main(int, char**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x15545e2)
#59 0x00007f24bc6e1083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#60 0x0000556100597c7e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x154cc7e)
clang-16: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

@shafik shafik added the confirmed Verified by a second party label Jan 20, 2023
@shafik
Copy link
Collaborator

shafik commented Jan 23, 2023

It looks like we end up in ClassifyImplicitMemberAccess(...) in an unevaluated context that is not within a CXXMethodDecl or a CXXRecordDecl but the code is assuming that unless we are in a static context this is the case.

It looks like change the code where we attempt to resolve contextClass to the following fixes this case and a related case:

CXXRecordDecl *contextClass = nullptr;
  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
    contextClass = MD->getParent()->getCanonicalDecl();
  else if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC))
    contextClass = cast<CXXRecordDecl>(DC);
  else 
     return AbstractInstanceResult ? AbstractInstanceResult
                                  : IMA_Error_StaticContext;

We also have some C related cases like: #31295

that are dealing with invalid code which seems trickier to deal with. it seems like in these cases around ActOnIdExpression and on we need some gating based on C++ Vs C but not clear where to do that.

@shafik
Copy link
Collaborator

shafik commented Jan 28, 2023

@shafik shafik self-assigned this Jan 28, 2023
@shafik shafik closed this as completed in c41be8f Mar 14, 2023
CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this issue Mar 17, 2023
…cess in an unevaluated context is not within a CXXRecordDecl or CXXMethodDecl

ClassifyImplicitMemberAccess assumes that if we are not in a static context then
the DeclContext must be a CXXRecordDecl or a CXXMethodDecl. In the case of the
unevaluated context this may not be true.

This will lead to a crash because contextClass will remain a nullptr.

Fixes: llvm/llvm-project#37792
Fixes: llvm/llvm-project#48405

Differential Revision: https://reviews.llvm.org/D142490
agozillon pushed a commit to ROCm-Developer-Tools/llvm-project that referenced this issue Mar 17, 2023
…cess in an unevaluated context is not within a CXXRecordDecl or CXXMethodDecl

ClassifyImplicitMemberAccess assumes that if we are not in a static context then
the DeclContext must be a CXXRecordDecl or a CXXMethodDecl. In the case of the
unevaluated context this may not be true.

This will lead to a crash because contextClass will remain a nullptr.

Fixes: llvm/llvm-project#37792
Fixes: llvm/llvm-project#48405

Differential Revision: https://reviews.llvm.org/D142490
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

4 participants