clang Assertion isLinkageValid() failed in Redeclarable::setPreviousDecl when using __attribute__((alias))
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
### Link for quick verification: https://godbolt.org/z/WKsWbjasa
```c
#include
extern const __m128 kAlias;
const __m128 kAlias __attribute__((alias("kOne")));
```
Go back to `clang 3.7.0 (assertions)`. While the stack trace is similar to [#112737](https://github.com/llvm/llvm-project/issues/112737), the triggering code patterns are distinct and involve different AST node types (`VarDecl` and `FunctionDecl`).
## Stack dump
```console
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/Decl.h:5354: void clang::Redeclarable::setPreviousDecl(decl_type*) [with decl_type = clang::VarDecl]: Assertion `!isa(static_cast(this)) || cast(static_cast(this))->isLinkageValid()' 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++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics
1. :5:51: current parser token ';'
#0 0x00000000042ebc28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42ebc28)
#1 0x00000000042e9054 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42e9054)
#2 0x000000000422de38 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000778700442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007787004969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000778700442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007787004287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000077870042871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000778700439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000006dad960 clang::Redeclarable::setPreviousDecl(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dad960)
#10 0x0000000006df3e42 clang::Sema::MergeVarDecl(clang::VarDecl*, clang::LookupResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df3e42)
#11 0x0000000006df4eea clang::Sema::CheckVariableDeclaration(clang::VarDecl*, clang::LookupResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df4eea)
#12 0x0000000006df9c7d clang::Sema::ActOnVariableDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef, bool&, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df9c7d)
#13 0x0000000006e19d1f clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e19d1f)
#14 0x0000000006e1a660 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1a660)
#15 0x0000000006a51483 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a51483)
#16 0x0000000006a5f29a clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a5f29a)
#17 0x0000000006a1c94b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a1c94b)
#18 0x0000000006a1d13f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a1d13f)
#19 0x0000000006a24f6a clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a24f6a)
#20 0x0000000006a25f05 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a25f05)
#21 0x0000000006a06f8a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a06f8a)
#22 0x0000000004c4cfb8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c4cfb8)
#23 0x0000000004f438b5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f438b5)
#24 0x0000000004ec3b4e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ec3b4e)
#25 0x000000000503dc3d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x503dc3d)
#26 0x0000000000de5a6c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde5a6c)
#27 0x0000000000ddc4ba ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#28 0x0000000000ddc63d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#29 0x0000000004cbf909 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#30 0x000000000422e2d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x422e2d4)
#31 0x0000000004cbff1f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#32 0x0000000004c80a02 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c80a02)
#33 0x0000000004c819ae clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c819ae)
#34 0x0000000004c88e05 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c88e05)
#35 0x0000000000de1e61 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde1e61)
#36 0x0000000000c8ceb4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc8ceb4)
#37 0x0000778700429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x0000778700429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x0000000000ddbf55 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddbf55)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Start with the reproducer in the issue and inspect clang/AST/Decl.h around Redeclarable::setPreviousDecl, then follow the stack into Sema::MergeVarDecl and CheckVariableDeclaration. Confirm the alias declaration no longer triggers the assertion and add regression coverage for this VarDecl case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100