Open llvmbot opened 8 years ago
OK, so the real problem is that this code is simply not supposed to be reachable for an enumeration defined in a dependent context. The check at the start of ActOnEnumBody is supposed to bail out in this case, but EnumDecl::isDependentType is unable to cope with the (ill-formed) case of an enum defined within an alias template.
Ideally, we should fix DeclContext::isDependentContext to -- somehow -- correctly detect the case where a context is dependent because it's nested within a variable template.
Alternatively, we could fix this by detecting the problematic case sooner (perhaps in the parser).
With the attached patch the code is rejected at a later point in GetDeclSpecTypeForDeclarator
:
clang -std=c++11 t.cpp
/home/rcraik/defects/127660/t.cpp:1:35: error: 'B' cannot be defined in a type alias template
template <class T> using A = enum B : T {};
^
1 error generated.
I did not send the patch to cfe-commits because, as you say, it is not a general solution; I just attached it as a starting point. Perhaps I should have worded it better in the initial description.
And for your future reference, patches should be posted to cfe-commits@ rather than bugzilla.
The right fix would be to just reject this:
template <class T> using A = enum B : T {};
... because ([dcl.typedef]/2) "The defining-type-specifier-seq of the defining-type-id shall not define a class or enumeration if the alias-declaration is the declaration of a template-declaration."
(Also, the attached patch doesn't fix the assert in full generality -- the enum-base might be some other kind of dependent type, not necessarily just a template parameter type.)
Still crashing as of post-16 trunk: https://godbolt.org/z/dMbco848E
clang++: /root/build/tools/clang/include/clang/AST/TypeNodes.inc:73:
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 <source>
1. <source>:1:43: current parser token ';'
#0 0x000055f2aea9ac1a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9ac1a)
#1 0x000055f2aea9884c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9884c)
#2 0x000055f2ae9e7020 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007fd217c36420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007fd21770300b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#5 0x00007fd2176e2859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#6 0x00007fd2176e2729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#7 0x00007fd2176f3fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#8 0x000055f2b1b06446 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b06446)
#9 0x000055f2b1b051b2 clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b051b2)
#10 0x000055f2b1b16b83 clang::ASTContext::getIntWidth(clang::QualType) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b16b83)
#11 0x000055f2b110c535 clang::Sema::ActOnEnumBody(clang::SourceLocation, clang::SourceRange, clang::Decl*, llvm::ArrayRef<clang::Decl*>, clang::Scope*, clang::ParsedAttributesView const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x610c535)
#12 0x000055f2b0e63ae8 clang::Parser::ParseEnumBody(clang::SourceLocation, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e63ae8)
#13 0x000055f2b0e68b92 clang::Parser::ParseEnumSpecifier(clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e68b92)
#14 0x000055f2b0e6a354 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e6a354)
#15 0x000055f2b0e6d2a4 clang::Parser::ParseSpecifierQualifierList(clang::DeclSpec&, clang::ImplicitTypenameContext, clang::AccessSpecifier, clang::Parser::DeclSpecContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e6d2a4)
#16 0x000055f2b0e6d7a1 clang::Parser::ParseTypeName(clang::SourceRange*, clang::DeclaratorContext, clang::AccessSpecifier, clang::Decl**, clang::ParsedAttributes*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e6d7a1)
#17 0x000055f2b0e79ef2 clang::Parser::ParseAliasDeclarationAfterDeclarator(clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation, clang::Parser::UsingDeclarator&, clang::SourceLocation&, clang::AccessSpecifier, clang::ParsedAttributes&, clang::Decl**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e79ef2)
#18 0x000055f2b0e82241 clang::Parser::ParseUsingDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e82241)
#19 0x000055f2b0e82c25 clang::Parser::ParseUsingDirectiveOrDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e82c25)
#20 0x000055f2b0f1196f clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f1196f)
#21 0x000055f2b0f176f3 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f176f3)
#22 0x000055f2b0f17a96 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f17a96)
#23 0x000055f2b0e737f4 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e737f4)
#24 0x000055f2b0e439c0 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e439c0)
#25 0x000055f2b0e45176 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e45176)
#26 0x000055f2b0e4549f clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e4549f)
#27 0x000055f2b0e3a1f3 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3a1f3)
#28 0x000055f2afb67560 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b67560)
#29 0x000055f2af4892e9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44892e9)
#30 0x000055f2af41dc42 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441dc42)
#31 0x000055f2af560c9f clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4560c9f)
#32 0x000055f2ac222cc3 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1222cc3)
#33 0x000055f2ac21ade8 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#34 0x000055f2af2912f9 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
#35 0x000055f2ae9e74a5 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39e74a5)
#36 0x000055f2af293eee clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4293eee)
#37 0x000055f2af26060b clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x426060b)
#38 0x000055f2af2611e3 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+++0x42611e3)
#39 0x000055f2af269fd6 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4269fd6)
#40 0x000055f2ac220a8e clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1220a8e)
#41 0x000055f2ac151cb1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1151cb1)
#42 0x00007fd2176e4083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#43 0x000055f2ac21a4da _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x121a4da)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
@llvm/issue-subscribers-clang-frontend
Extended Description
With the following testcase:
clang hits an assertion failure:
This failure was introduced in r222906 - Create a new 'flag_enum' attribute, specifically the change in
Sema::ActOnEnumBody
:I have attached a patch with a potential fix for this issue