Skip to content

Crash with #pragma weak a = b when a is defined #111319

@tgross35

Description

@tgross35

Sample code:

int foo() { return 20; }
int bar();

// Also fails with `_Pragma("weak foo = bar")`
#pragma weak foo = bar

void test() {
    foo();
}

Output:

Could not execute the program
Compiler returned: 254
Compiler stderr

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-trunk-20241006/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-trunk-20241006/lib/clang/20 -internal-isystem /opt/compiler-explorer/clang-trunk-20241006/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-0bc861.o -x c <source>
1.	<source>:10:9: current parser token ')'
2.	<source>:9:13: parsing function body 'test'
3.	<source>:9:13: in compound statement ('{}')
 #0 0x000000000393ab48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x393ab48)
 #1 0x000000000393872c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007be4e3842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000000006c8f59c clang::Sema::AddOverloadCandidate(clang::FunctionDecl*, clang::DeclAccessPair, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool, bool, bool, clang::CallExpr::ADLCallKind, llvm::MutableArrayRef<clang::ImplicitConversionSequence>, clang::OverloadCandidateParamOrder, bool) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x6c8f59c)
 #4 0x00000000067c2717 clang::Sema::DiagnoseEmptyLookup(clang::Scope*, clang::CXXScopeSpec&, clang::LookupResult&, clang::CorrectionCandidateCallback&, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::DeclContext*, clang::TypoExpr**) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x67c2717)
 #5 0x0000000006caf208 FinishOverloadedCallExpr(clang::Sema&, clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, clang::OverloadCandidateSet*, clang::OverloadCandidate**, clang::OverloadingResult, bool) SemaOverload.cpp:0:0
 #6 0x0000000006cafd3c clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x6cafd3c)
 #7 0x0000000006849dfa clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x6849dfa)
 #8 0x000000000685009c clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x685009c)
 #9 0x00000000062ae847 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x62ae847)
#10 0x00000000062a6601 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x62a6601)
#11 0x00000000062a882a clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x62a882a)
#12 0x00000000062a89f9 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x62a89f9)
#13 0x00000000062adc49 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x62adc49)
#14 0x0000000006339fb7 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x6339fb7)
#15 0x000000000632d767 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x632d767)
#16 0x000000000632e15d clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x632e15d)
#17 0x000000000632f471 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x632f471)
#18 0x000000000633169a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x633169a)
#19 0x000000000622e176 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x622e176)
#20 0x00000000062773df clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x62773df)
#21 0x0000000006226727 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x6226727)
#22 0x0000000006227543 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x6227543)
#23 0x0000000006230e32 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x6230e32)
#24 0x00000000062326c8 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x62326c8)
#25 0x0000000006220d9a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x6220d9a)
#26 0x0000000004257705 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x4257705)
#27 0x000000000451df31 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x451df31)
#28 0x000000000449db7b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x449db7b)
#29 0x0000000004602493 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0x4602493)
#30 0x0000000000ce01ec cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0xce01ec)
#31 0x0000000000cd8c4d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#32 0x0000000000cdcdbf clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0xcdcdbf)
#33 0x0000000000bb04f4 main (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0xbb04f4)
#34 0x00007be4e3829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x00007be4e3829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x0000000000cd86ee _start (/opt/compiler-explorer/clang-trunk-20241006/bin/clang-20+0xcd86ee)
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)

I typed the parameters wrong, it is attempting to declare foo as a weak alias of bar but foo is already defined (correct usage would be bar = foo). GCC reports the following with the test case:

<source>:3:5: error: 'foo' defined both normally and as 'alias' attribute
    3 | int foo() { return 20; }
      |     ^~~
<source>:3:5: error: 'foo' aliased to undefined symbol 'bar'
Compiler returned: 1

Explorer: https://gcc.godbolt.org/z/nYYGecd5W

Version at time of testing.

clang version 20.0.0git (https://github.com/llvm/llvm-project.git 46944b0cbc9a9d8daad0182c40fcd3560bc9ca35)

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"crashPrefer [crash-on-valid] or [crash-on-invalid]duplicateResolved as duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions