llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.73k stars 11.43k forks source link

ICE: checkAttributesAfterMerging(clang::Sema&, clang::NamedDecl&): Assertion `VD->isThisDeclarationADefinition() && !VD->isExternallyVisible() && "Broken AliasAttr handled late!"' failed. #50535

Open chengniansun opened 3 years ago

chengniansun commented 3 years ago
Bugzilla Link 51191
Version trunk
OS All
CC @zygoloid

Extended Description

$ clang-trunk -v

clang version 13.0.0 (https://github.com/llvm/llvm-project.git ab5ac659c81a453a3f58df94f39fe8ba3cd35918)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cnsun/usr/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

$ cat mutant.c

extern int b __attribute__((alias("a"))) (VariableWithParentheses);

$ clang-trunk mutant.c

mutant.c:1:43: error: use of undeclared identifier 'VariableWithParentheses'
extern int b __attribute__((alias("a"))) (VariableWithParentheses);
                                          ^
mutant.c:1:12: warning: 'extern' variable has an initializer [-Wextern-initializer]
extern int b __attribute__((alias("a"))) (VariableWithParentheses);
           ^
clang-13: /tmp/tmp.Gcp8nSn9Hr-clang-builder/llvm-project/clang/lib/Sema/SemaDecl.cpp:6481: void checkAttributesAfterMerging(clang::Sema&, clang::NamedDecl&): Assertion `VD->isThisDeclarationADefinition() && !VD->isExternallyVisible() && "Broken AliasAttr handled late!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /scratch/software/clang-trunk/bin/clang-13 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-file-name mutant.c -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/scratch/cnsun/workspace/perses-fuzzer/temp_testing_campaigns/default_finding_folder_c/crash_20210722_062432_0327/delta/perses_result -resource-dir /scratch/software/clang-trunk/lib/clang/13.0.0 -c-isystem . -c-isystem /usr/local/include/cmsith -internal-isystem /scratch/software/clang-trunk/lib/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/scratch/cnsun/workspace/perses-fuzzer/temp_testing_campaigns/default_finding_folder_c/crash_20210722_062432_0327/delta/perses_result -ferror-limit 19 -fgnuc-version=4.2.1 -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/mutant-d88b05.o -x c mutant.c
1.  mutant.c:1:67: current parser token ';'
 #0 0x000055b207af6754 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055b207af3e6e SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f7ff45bd3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #3 0x00007f7ff405c18b raise /build/glibc-ZN95T4/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007f7ff403b859 abort /build/glibc-ZN95T4/glibc-2.31/stdlib/abort.c:81:7
 #5 0x00007f7ff403b729 get_sysdep_segment_value /build/glibc-ZN95T4/glibc-2.31/intl/loadmsgcat.c:509:8
 #6 0x00007f7ff403b729 _nl_load_domain /build/glibc-ZN95T4/glibc-2.31/intl/loadmsgcat.c:970:34
 #7 0x00007f7ff404cf36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
 #8 0x000055b20a004e3a checkAttributesAfterMerging(clang::Sema&, clang::NamedDecl&) SemaDecl.cpp:0:0
 #9 0x000055b20a00d634 clang::Sema::FinalizeDeclaration(clang::Decl*) (/scratch/software/clang-trunk/bin/clang-13+0x603c634)
#10 0x000055b209d72e42 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/scratch/software/clang-trunk/bin/clang-13+0x5da1e42)
#11 0x000055b209d8613b clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/scratch/software/clang-trunk/bin/clang-13+0x5db513b)
#12 0x000055b209d54176 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/scratch/software/clang-trunk/bin/clang-13+0x5d83176)
#13 0x000055b209d54761 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#14 0x000055b209d5af87 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/scratch/software/clang-trunk/bin/clang-13+0x5d89f87)
#15 0x000055b209d5c51e clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/scratch/software/clang-trunk/bin/clang-13+0x5d8b51e)
#16 0x000055b209d5c8c9 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) (/scratch/software/clang-trunk/bin/clang-13+0x5d8b8c9)
#17 0x000055b209d4ed1a clang::ParseAST(clang::Sema&, bool, bool) (/scratch/software/clang-trunk/bin/clang-13+0x5d7dd1a)
#18 0x000055b208c892f8 clang::CodeGenAction::ExecuteAction() (/scratch/software/clang-trunk/bin/clang-13+0x4cb82f8)
#19 0x000055b208527419 clang::FrontendAction::Execute() (/scratch/software/clang-trunk/bin/clang-13+0x4556419)
#20 0x000055b2084bd07e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/scratch/software/clang-trunk/bin/clang-13+0x44ec07e)
#21 0x000055b208605710 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/scratch/software/clang-trunk/bin/clang-13+0x4634710)
#22 0x000055b20537115d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/scratch/software/clang-trunk/bin/clang-13+0x13a015d)
#23 0x000055b20536d4a8 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#24 0x000055b205298126 main (/scratch/software/clang-trunk/bin/clang-13+0x12c7126)
#25 0x00007f7ff403d0b3 __libc_start_main /build/glibc-ZN95T4/glibc-2.31/csu/../csu/libc-start.c:342:3
#26 0x000055b20536d01e _start (/scratch/software/clang-trunk/bin/clang-13+0x139c01e)
clang-13: error: unable to execute command: Aborted (core dumped)
clang-13: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 13.0.0 (https://github.com/llvm/llvm-project.git ab5ac659c81a453a3f58df94f39fe8ba3cd35918)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cnsun/usr/bin
clang-13: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-13: note: diagnostic msg: /tmp/mutant-338b7a.c
clang-13: note: diagnostic msg: /tmp/mutant-338b7a.sh
clang-13: note: diagnostic msg:

********************
Endilll commented 1 year ago

Assertions build is still crashing: https://godbolt.org/z/hP74EGdx9 Diagnostics:

<source>:1:43: error: use of undeclared identifier 'VariableWithParentheses'
    1 | extern int b __attribute__((alias("a"))) (VariableWithParentheses);
      |                                           ^
<source>:1:12: warning: 'extern' variable has an initializer [-Wextern-initializer]
    1 | extern int b __attribute__((alias("a"))) (VariableWithParentheses);
      |            ^

Assertion:

clang: /root/llvm-project/clang/lib/Sema/SemaDecl.cpp:6950: void checkAttributesAfterMerging(clang::Sema&, clang::NamedDecl&): Assertion `VD->isThisDeclarationADefinition() && !VD->isExternallyVisible() && "Broken AliasAttr handled late!"' failed.

Stack:

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-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics <source>
1.  <source>:1:67: current parser token ';'
 #0 0x00005572f9cc1dbf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c12dbf)
 #1 0x00005572f9cbfb2c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c10b2c)
 #2 0x00005572f9c091a8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f22e53a9420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f22e4e7600b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f22e4e55859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f22e4e55729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f22e4e66fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00005572fc75912a checkAttributesAfterMerging(clang::Sema&, clang::NamedDecl&) SemaDecl.cpp:0:0
 #9 0x00005572fc761915 clang::Sema::FinalizeDeclaration(clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66b2915)
#10 0x00005572fc4357b2 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x63867b2)
#11 0x00005572fc442d98 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6393d98)
#12 0x00005572fc40fcc1 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6360cc1)
#13 0x00005572fc41057f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#14 0x00005572fc416f21 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6367f21)
#15 0x00005572fc417896 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6368896)
#16 0x00005572fc417d34 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6368d34)
#17 0x00005572fc40b62a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x635c62a)
#18 0x00005572faf0f7c8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4e607c8)
#19 0x00005572fa766f09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x46b7f09)
#20 0x00005572fa6eb3d6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x463c3d6)
#21 0x00005572fa8499e6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x479a9e6)
#22 0x00005572f717d46d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10ce46d)
#23 0x00005572f717916a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x00005572fa55339d 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
#25 0x00005572f9c096b0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b5a6b0)
#26 0x00005572fa5539bf 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
#27 0x00005572fa51b0ec clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x446c0ec)
#28 0x00005572fa51bb7d 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+0x446cb7d)
#29 0x00005572fa523c5d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4474c5d)
#30 0x00005572f717b6ca clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10cc6ca)
#31 0x00005572f7082235 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xfd3235)
#32 0x00007f22e4e57083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#33 0x00005572f7173f4e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10c4f4e)
llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend