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

incorrect error on correct code and crash on bad code in forward declaration of enum in template #23317

Open
llvmbot opened this issue Mar 17, 2015 · 4 comments
Labels
bugzilla Issues migrated from bugzilla c++11 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 17, 2015

Bugzilla Link 22943
Version 3.5
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

template struct A {
enum E : T;
};
A a;
template enum A::E : T { e1, e2 };
#if _WRONG
A::E er = e1;
#else
A::E e = A::e1;
#endif

Should compile clean but with

clang++ -std=c++11
a.cpp:9:15: error: no member named 'e1' in 'A'; did you mean simply 'e1'?
A::E e = A::e1;
^~~~~~~~~~
e1
a.cpp:5:38: note: 'e1' declared here
template enum A::E : T { e1, e2 };

clang++ -std=c++11 -D_WRONG
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.5.0 (tags/RELEASE_350/final)
Target: powerpc64le-unknown-linux-gnu
Thread model: posix
clang: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang: note: diagnostic msg:


Testcase (not _WRONG) section is taken directly from the C++2011 standard
14.5.1.4 Enumeration members of class templates

the _WRONG section was an attempt to fix according to the clang diagnostic message.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@Endilll
Copy link
Contributor

Endilll commented Aug 9, 2023

Still crashing as of post-17 trunk: https://godbolt.org/z/9qeerY691

clang++: /root/llvm-project/clang/lib/AST/Decl.cpp:2539:
clang::APValue* clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic> >&, bool) const:
Assertion `!Init->isValueDependent()' 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++11 -D_WRONG <source>
1.	<eof> parser at end of file
2.	<source>:7:11: LLVM IR generation of declaration 'er'
3.	<source>:7:11: Generating code for declaration 'er'
 #0 0x0000000003678548 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3678548)
 #1 0x00000000036763cc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36763cc)
 #2 0x00000000035c3c28 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f4fc2c54420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f4fc271700b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f4fc26f6859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f4fc26f6729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f4fc2707fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x0000000006de3353 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de3353)
 #9 0x0000000006de33db clang::VarDecl::evaluateValue() const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de33db)
#10 0x000000000396e1cb clang::CodeGen::ConstantEmitter::tryEmitPrivateForVarInit(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x396e1cb)
#11 0x000000000396e581 clang::CodeGen::ConstantEmitter::tryEmitForInitializer(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x396e581)
#12 0x0000000003a40897 clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a40897)
#13 0x0000000003a62861 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a62861)
#14 0x0000000003a62eb3 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a62eb3)
#15 0x0000000003a6bfeb clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#16 0x00000000048d3636 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#17 0x00000000048c5dd8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48c5dd8)
#18 0x0000000005d905f4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5d905f4)
#19 0x00000000048d06a8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48d06a8)
#20 0x0000000004138c59 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4138c59)
#21 0x00000000040bcfee clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40bcfee)
#22 0x0000000004219096 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4219096)
#23 0x0000000000bcd462 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbcd462)
#24 0x0000000000bc5c4a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x0000000003f1d239 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
#26 0x00000000035c40d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x35c40d4)
#27 0x0000000003f1d82f 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
#28 0x0000000003ee5795 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ee5795)
#29 0x0000000003ee61fd 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+++0x3ee61fd)
#30 0x0000000003eedd25 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3eedd25)
#31 0x0000000000bcb717 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbcb717)
#32 0x0000000000ac5481 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xac5481)
#33 0x00007f4fc26f8083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#34 0x0000000000bc572e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbc572e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)

@Endilll Endilll added clang:codegen confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid] labels Aug 9, 2023
@llvmbot
Copy link
Collaborator Author

llvmbot commented Aug 9, 2023

@llvm/issue-subscribers-clang-codegen

@shafik
Copy link
Collaborator

shafik commented Aug 17, 2023

If we look at this simpler example: https://godbolt.org/z/4sGr3TKPM

struct A {
    enum E :int ;
};

enum A::E :int  { e1, e2 };

A::E er = e1;

clang accepts while gcc/MSVC reject. It looks like we are missing a diagnostic here which would prevent this from going into codegen.

@shafik shafik added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang:codegen labels Aug 17, 2023
@llvmbot
Copy link
Collaborator Author

llvmbot commented Aug 17, 2023

@llvm/issue-subscribers-clang-frontend

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++11 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

3 participants