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

crash on invalid after "error: 'foo' cannot be defined in a type alias template" #75221

Closed
wheatman opened this issue Dec 12, 2023 · 4 comments · Fixed by #87173
Closed

crash on invalid after "error: 'foo' cannot be defined in a type alias template" #75221

wheatman opened this issue Dec 12, 2023 · 4 comments · Fixed by #87173
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash-on-invalid

Comments

@wheatman
Copy link
Contributor

The following invalid code crashes on the current post 17 trunk(2e19760)
https://godbolt.org/z/e7GqqKEKf

template <class T> using foo = struct foo {
  T size = 0;
};
foo a;

It triggers the following assert

clang++: /root/build/tools/clang/include/clang/AST/TypeNodes.inc:74: 
clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type*) const: 
Assertion `!T->isDependentType() && "should not see dependent types here"' failed.

The full dump is

<source>:1:39: error: 'foo' cannot be defined in a type alias template
    1 | template <class T> using foo = struct foo {
      |                                       ^
clang++: /root/build/tools/clang/include/clang/AST/TypeNodes.inc:74: clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type*) const: Assertion `!T->isDependentType() && "should not see dependent types here"' failed.
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 -std=c++14 -pedantic-errors <source>
1.	<source>:4:6: current parser token ';'
 #0 0x000000000379d408 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x379d408)
 #1 0x000000000379b0ec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x379b0ec)
 #2 0x00000000036e3bd8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f0798c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f0798c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f0798c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f0798c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f0798c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f0798c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000006e9af1c clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9af1c)
#10 0x0000000006e82df7 clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e82df7)
#11 0x0000000006e9b09b clang::ASTContext::getTypeInfoInChars(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9b09b)
#12 0x0000000006e9b1b3 clang::ASTContext::getTypeInfoInChars(clang::QualType) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9b1b3)
#13 0x0000000007340f25 (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutField(clang::FieldDecl const*, bool) RecordLayoutBuilder.cpp:0:0
#14 0x00000000073427af (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutFields(clang::RecordDecl const*) RecordLayoutBuilder.cpp:0:0
#15 0x000000000733e076 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x733e076)
#16 0x0000000006e9ac51 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9ac51)
#17 0x0000000006e82df7 clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e82df7)
#18 0x0000000006e99db7 clang::ASTContext::getTypeAlignInChars(clang::QualType) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e99db7)
#19 0x000000000613ca20 clang::Sema::CheckArgAlignment(clang::SourceLocation, clang::NamedDecl*, llvm::StringRef, clang::QualType, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x613ca20)
#20 0x000000000616e327 clang::Sema::CheckConstructorCall(clang::FunctionDecl*, clang::QualType, llvm::ArrayRef<clang::Expr const*>, clang::FunctionProtoType const*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x616e327)
#21 0x000000000635cebc clang::Sema::CompleteConstructorCall(clang::CXXConstructorDecl*, clang::QualType, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, llvm::SmallVectorImpl<clang::Expr*>&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x635cebc)
#22 0x00000000066a6050 PerformConstructorInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::InitializationSequence::Step const&, bool&, bool, bool, clang::SourceLocation, clang::SourceLocation) SemaInit.cpp:0:0
#23 0x00000000066b93f2 clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b93f2)
#24 0x00000000062b5114 clang::Sema::ActOnUninitializedDecl(clang::Decl*) (.part.0) SemaDecl.cpp:0:0
#25 0x0000000005f872d6 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f872d6)
#26 0x0000000005f96170 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f96170)
#27 0x0000000005f5f42b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f5f42b)
#28 0x0000000005f5fbb1 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f5fbb1)
#29 0x0000000005f66e66 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f66e66)
#30 0x0000000005f67d0d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f67d0d)
#31 0x0000000005f5acfa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f5acfa)
#32 0x000000000401e378 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x401e378)
#33 0x000000000428a9b9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x428a9b9)
#34 0x0000000004208c9e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4208c9e)
#35 0x000000000436974e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x436974e)
#36 0x0000000000c01496 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc01496)
#37 0x0000000000bf8d2a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#38 0x000000000405f3a9 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
#39 0x00000000036e4084 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36e4084)
#40 0x000000000405f99f 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
#41 0x0000000004027c05 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4027c05)
#42 0x000000000402866d 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+++0x402866d)
#43 0x0000000004030585 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4030585)
#44 0x0000000000bfe90c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbfe90c)
#45 0x0000000000af7a71 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xaf7a71)
#46 0x00007f0798c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#47 0x00007f0798c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#48 0x0000000000bf880e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbf880e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
@wheatman wheatman added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash-on-invalid labels Dec 12, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 12, 2023

@llvm/issue-subscribers-clang-frontend

Author: None (wheatman)

The following invalid code crashes on the current post 17 trunk(2e19760) https://godbolt.org/z/e7GqqKEKf
template &lt;class T&gt; using foo = struct foo {
  T size = 0;
};
foo a;

It triggers the following assert

clang++: /root/build/tools/clang/include/clang/AST/TypeNodes.inc:74: 
clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type*) const: 
Assertion `!T-&gt;isDependentType() &amp;&amp; "should not see dependent types here"' failed.

The full dump is

&lt;source&gt;:1:39: error: 'foo' cannot be defined in a type alias template
    1 | template &lt;class T&gt; using foo = struct foo {
      |                                       ^
clang++: /root/build/tools/clang/include/clang/AST/TypeNodes.inc:74: clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type*) const: Assertion `!T-&gt;isDependentType() &amp;&amp; "should not see dependent types here"' failed.
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 -std=c++14 -pedantic-errors &lt;source&gt;
1.	&lt;source&gt;:4:6: current parser token ';'
 #<!-- -->0 0x000000000379d408 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x379d408)
 #<!-- -->1 0x000000000379b0ec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x379b0ec)
 #<!-- -->2 0x00000000036e3bd8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #<!-- -->3 0x00007f0798c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->4 0x00007f0798c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #<!-- -->5 0x00007f0798c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #<!-- -->6 0x00007f0798c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #<!-- -->7 0x00007f0798c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #<!-- -->8 0x00007f0798c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #<!-- -->9 0x0000000006e9af1c clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9af1c)
#<!-- -->10 0x0000000006e82df7 clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e82df7)
#<!-- -->11 0x0000000006e9b09b clang::ASTContext::getTypeInfoInChars(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9b09b)
#<!-- -->12 0x0000000006e9b1b3 clang::ASTContext::getTypeInfoInChars(clang::QualType) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9b1b3)
#<!-- -->13 0x0000000007340f25 (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutField(clang::FieldDecl const*, bool) RecordLayoutBuilder.cpp:0:0
#<!-- -->14 0x00000000073427af (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutFields(clang::RecordDecl const*) RecordLayoutBuilder.cpp:0:0
#<!-- -->15 0x000000000733e076 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x733e076)
#<!-- -->16 0x0000000006e9ac51 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9ac51)
#<!-- -->17 0x0000000006e82df7 clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e82df7)
#<!-- -->18 0x0000000006e99db7 clang::ASTContext::getTypeAlignInChars(clang::QualType) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e99db7)
#<!-- -->19 0x000000000613ca20 clang::Sema::CheckArgAlignment(clang::SourceLocation, clang::NamedDecl*, llvm::StringRef, clang::QualType, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x613ca20)
#<!-- -->20 0x000000000616e327 clang::Sema::CheckConstructorCall(clang::FunctionDecl*, clang::QualType, llvm::ArrayRef&lt;clang::Expr const*&gt;, clang::FunctionProtoType const*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x616e327)
#<!-- -->21 0x000000000635cebc clang::Sema::CompleteConstructorCall(clang::CXXConstructorDecl*, clang::QualType, llvm::MutableArrayRef&lt;clang::Expr*&gt;, clang::SourceLocation, llvm::SmallVectorImpl&lt;clang::Expr*&gt;&amp;, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x635cebc)
#<!-- -->22 0x00000000066a6050 PerformConstructorInitialization(clang::Sema&amp;, clang::InitializedEntity const&amp;, clang::InitializationKind const&amp;, llvm::MutableArrayRef&lt;clang::Expr*&gt;, clang::InitializationSequence::Step const&amp;, bool&amp;, bool, bool, clang::SourceLocation, clang::SourceLocation) SemaInit.cpp:0:0
#<!-- -->23 0x00000000066b93f2 clang::InitializationSequence::Perform(clang::Sema&amp;, clang::InitializedEntity const&amp;, clang::InitializationKind const&amp;, llvm::MutableArrayRef&lt;clang::Expr*&gt;, clang::QualType*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b93f2)
#<!-- -->24 0x00000000062b5114 clang::Sema::ActOnUninitializedDecl(clang::Decl*) (.part.0) SemaDecl.cpp:0:0
#<!-- -->25 0x0000000005f872d6 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&amp;, clang::Parser::ParsedTemplateInfo const&amp;, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f872d6)
#<!-- -->26 0x0000000005f96170 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&amp;, clang::DeclaratorContext, clang::ParsedAttributes&amp;, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f96170)
#<!-- -->27 0x0000000005f5f42b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec&amp;, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f5f42b)
#<!-- -->28 0x0000000005f5fbb1 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f5fbb1)
#<!-- -->29 0x0000000005f66e66 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f66e66)
#<!-- -->30 0x0000000005f67d0d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f67d0d)
#<!-- -->31 0x0000000005f5acfa clang::ParseAST(clang::Sema&amp;, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f5acfa)
#<!-- -->32 0x000000000401e378 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x401e378)
#<!-- -->33 0x000000000428a9b9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x428a9b9)
#<!-- -->34 0x0000000004208c9e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4208c9e)
#<!-- -->35 0x000000000436974e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x436974e)
#<!-- -->36 0x0000000000c01496 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc01496)
#<!-- -->37 0x0000000000bf8d2a ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->38 0x000000000405f3a9 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->39 0x00000000036e4084 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36e4084)
#<!-- -->40 0x000000000405f99f clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->41 0x0000000004027c05 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4027c05)
#<!-- -->42 0x000000000402866d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x402866d)
#<!-- -->43 0x0000000004030585 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4030585)
#<!-- -->44 0x0000000000bfe90c clang_main(int, char**, llvm::ToolContext const&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbfe90c)
#<!-- -->45 0x0000000000af7a71 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xaf7a71)
#<!-- -->46 0x00007f0798c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->47 0x00007f0798c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->48 0x0000000000bf880e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbf880e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

@hokein
Copy link
Collaborator

hokein commented Dec 12, 2023

The AST for the struct foo is:

TranslationUnitDecl
|- ...
|--CXXRecordDecl  foo
     |-...
     |-FieldDecl size 'T'
     | `-IntegerLiteral 'int' 0 

The CXXRecordDecl is ill-formed: it is a valid decl, and it has a FieldDecl with a dangling dependent type.
I think we should at least mark it as invalid (doing the invalidation at https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaType.cpp#L3837 is too late, the definition of CXXRecordDecl at this point is completed, we can't call setInvalidDecl()), or just drop it.

@shafik
Copy link
Collaborator

shafik commented Dec 13, 2023

Looks like this regressed after clang-12: https://godbolt.org/z/x17zaM7oM

It looks like if it is too late in GetTypeSourceInfoForDeclarator then perhaps we can diagnose this in Parser::ParseTypeName

@shafik
Copy link
Collaborator

shafik commented Dec 13, 2023

I think we need to mark it invalid here:

tok::TokenKind Kind = Tok.getKind();

but we would need to add DeclSpecContext::DSC_alias_template_declaration to tell when we are in a alias template b/c right now we treat them both as DeclSpecContext::DSC_alias_declaration.

Then we could do something like this:

if (DSContext == DeclSpecContext::DSC_alias_template_declaration) {
         isInvalid = true;
          PrevSpec = Tok.getIdentifierInfo()->getNameStart();
          DiagID = diag::err_type_defined_in_alias_template;
          break;
      }

which works but breaks two tests b/c of additional diagnostics. Additional work may be needed to get this into shape.

CC @zygoloid @cor3ntin

jcsxky added a commit that referenced this issue Apr 18, 2024
…culating record layout (#87173)

Try to fix #75221
This crash caused by calculating record layout which contains a field
declaration with dependent type. Make it invalid before it is a complete
definition to prevent this crash. Define a new scope type to record this
type alias and set the record declaration invalid when it is defined in
a type alias template.

Co-authored-by: huqizhi <836744285@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash-on-invalid
Projects
None yet
4 participants