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

[Clang][OpenMP] Weak alias fails on OpenMP targets #117369

Open
Jason-VanBeusekom opened this issue Nov 22, 2024 · 2 comments
Open

[Clang][OpenMP] Weak alias fails on OpenMP targets #117369

Jason-VanBeusekom opened this issue Nov 22, 2024 · 2 comments
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@Jason-VanBeusekom
Copy link

Reproducer test file:

int __One(void) { return 1;  }

int One(void) __attribute__ ((weak, alias("__One")));

int main(){
    return One();
}

When compiling:

clang -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa test.c 
test.c:3:37: error: alias must point to a defined variable or function
    3 | int One(void) __attribute__ ((weak, alias("__One")));
      |                                     ^
test.c:3:37: note: the function or variable specified in an alias must refer to its mangled name
test.c:3:37: note: function by that name is mangled as "__One"
    3 | int One(void) __attribute__ ((weak, alias("__One")));
      |                                     ^~~~~~~~~~~~~~
      |                                     alias("__One")
test.c:3:37: error: alias must point to a defined variable or function
    3 | int One(void) __attribute__ ((weak, alias("__One")));
      |                                     ^
test.c:3:37: note: the function or variable specified in an alias must refer to its mangled name
test.c:3:37: note: function by that name is mangled as "__One"
    3 | int One(void) __attribute__ ((weak, alias("__One")));
      |                                     ^~~~~~~~~~~~~~
      |                                     alias("__One")
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: /ptmp2/vanbeuse-ptmp2/clang_install/bin/clang-20 -cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -Werror=atomic-alignment -emit-llvm-bc -emit-llvm-uselists -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name test.c -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/ocml.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_daz_opt_off.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_unsafe_math_off.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_finite_only_off.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_wavefrontsize64_on.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_isa_version_908.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_abi_version_500.bc -target-cpu gfx908 -debugger-tuning=gdb -fdebug-compilation-dir=/ptmp2/vanbeuse-ptmp2/CAST-30331 -resource-dir /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20 -internal-isystem /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20/include/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20/include/llvm_libc_wrappers -internal-isystem /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fvisibility=protected -fopenmp -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -fopenmp-is-target-device -fopenmp-host-ir-file-path /tmp/test-3dcfd8.bc -faddrsig -o /tmp/test-223d72.bc -x c test.c
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
 #0 0x00007fe39a249c1d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11
 #1 0x00007fe39a24a0db PrintStackTraceSignalHandler(void*) /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x00007fe39a24827f llvm::sys::RunSignalHandlers() /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/lib/Support/Signals.cpp:105:5
 #3 0x00007fe39a24a7ae SignalHandler(int) /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007fe397a3fdc0 __restore_rt (/lib64/libc.so.6+0x4adc0)
 #5 0x00007fe3a1efe2fc llvm::Value::getType() const /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/include/llvm/IR/Value.h:255:34
 #6 0x00007fe3a1f8bff5 llvm::GlobalValue::getType() const /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/include/llvm/IR/GlobalValue.h:294:65
 #7 0x00007fe3a287ddbc clang::CodeGen::CodeGenModule::checkAliases() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:736:61
 #8 0x00007fe3a287f0bc clang::CodeGen::CodeGenModule::Release() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:898:3
 #9 0x00007fe3a2a652dd (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:0:18
#10 0x00007fe3a28401e5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:273:10
#11 0x00007fe391c28e4b clang::ParseAST(clang::Sema&, bool, bool) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/Parse/ParseAST.cpp:191:12
#12 0x00007fe39ed0b057 clang::ASTFrontendAction::ExecuteAction() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1193:1
#13 0x00007fe3a2844692 clang::CodeGenAction::ExecuteAction() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1140:5
#14 0x00007fe39ed0aab2 clang::FrontendAction::Execute() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1081:7
#15 0x00007fe39ec06ff5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1062:23
#16 0x00007fe3a34292ba clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:296:8
#17 0x00000000002487e8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/tools/driver/cc1_main.cpp:286:13
#18 0x000000000023b8ae ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/tools/driver/driver.cpp:218:5
#19 0x000000000023a652 clang_main(int, char**, llvm::ToolContext const&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/tools/driver/driver.cpp:259:5
#20 0x000000000026cc45 main /ptmp2/vanbeuse-ptmp2/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:3
#21 0x00007fe397a2a24d __libc_start_main (/lib64/libc.so.6+0x3524d)
#22 0x000000000023a11a _start /home/abuild/rpmbuild/BUILD/glibc-2.31/csu/../sysdeps/x86_64/start.S:122:0
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 20.0.0git
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /ptmp2/vanbeuse-ptmp2/clang_install/bin
Build config: +unoptimized, +assertions
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 22, 2024
@EugeneZelenko EugeneZelenko added clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Nov 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 22, 2024

@llvm/issue-subscribers-clang-codegen

Author: None (Jason-VanBeusekom)

Reproducer test file: ``` int __One(void) { return 1; }

int One(void) attribute ((weak, alias("__One")));

int main(){
return One();
}

When compiling:

clang -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa test.c
test.c:3:37: error: alias must point to a defined variable or function
3 | int One(void) attribute ((weak, alias("__One")));
| ^
test.c:3:37: note: the function or variable specified in an alias must refer to its mangled name
test.c:3:37: note: function by that name is mangled as "__One"
3 | int One(void) attribute ((weak, alias("__One")));
| ^~~~~~~~~~~~~~
| alias("__One")
test.c:3:37: error: alias must point to a defined variable or function
3 | int One(void) attribute ((weak, alias("__One")));
| ^
test.c:3:37: note: the function or variable specified in an alias must refer to its mangled name
test.c:3:37: note: function by that name is mangled as "__One"
3 | int One(void) attribute ((weak, alias("__One")));
| ^~~~~~~~~~~~~~
| alias("__One")
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: /ptmp2/vanbeuse-ptmp2/clang_install/bin/clang-20 -cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -Werror=atomic-alignment -emit-llvm-bc -emit-llvm-uselists -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name test.c -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/ocml.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_daz_opt_off.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_unsafe_math_off.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_finite_only_off.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_correctly_rounded_sqrt_on.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_wavefrontsize64_on.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_isa_version_908.bc -mlink-builtin-bitcode /opt/rocm-6.2.0/amdgcn/bitcode/oclc_abi_version_500.bc -target-cpu gfx908 -debugger-tuning=gdb -fdebug-compilation-dir=/ptmp2/vanbeuse-ptmp2/CAST-30331 -resource-dir /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20 -internal-isystem /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20/include/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20/include/llvm_libc_wrappers -internal-isystem /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /ptmp2/vanbeuse-ptmp2/clang_install/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fvisibility=protected -fopenmp -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -fopenmp-is-target-device -fopenmp-host-ir-file-path /tmp/test-3dcfd8.bc -faddrsig -o /tmp/test-223d72.bc -x c test.c

  1.  &lt;eof&gt; parser at end of file
    
  2.  Per-file LLVM IR generation
    

#0 0x00007fe39a249c1d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11
#1 0x00007fe39a24a0db PrintStackTraceSignalHandler(void*) /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
#2 0x00007fe39a24827f llvm::sys::RunSignalHandlers() /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/lib/Support/Signals.cpp:105:5
#3 0x00007fe39a24a7ae SignalHandler(int) /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
#4 0x00007fe397a3fdc0 __restore_rt (/lib64/libc.so.6+0x4adc0)
#5 0x00007fe3a1efe2fc llvm::Value::getType() const /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/include/llvm/IR/Value.h:255:34
#6 0x00007fe3a1f8bff5 llvm::GlobalValue::getType() const /ptmp2/vanbeuse-ptmp2/llvm-project/llvm/include/llvm/IR/GlobalValue.h:294:65
#7 0x00007fe3a287ddbc clang::CodeGen::CodeGenModule::checkAliases() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:736:61
#8 0x00007fe3a287f0bc clang::CodeGen::CodeGenModule::Release() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:898:3
#9 0x00007fe3a2a652dd (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:0:18
#10 0x00007fe3a28401e5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:273:10
#11 0x00007fe391c28e4b clang::ParseAST(clang::Sema&, bool, bool) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/Parse/ParseAST.cpp:191:12
#12 0x00007fe39ed0b057 clang::ASTFrontendAction::ExecuteAction() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1193:1
#13 0x00007fe3a2844692 clang::CodeGenAction::ExecuteAction() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1140:5
#14 0x00007fe39ed0aab2 clang::FrontendAction::Execute() /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1081:7
#15 0x00007fe39ec06ff5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1062:23
#16 0x00007fe3a34292ba clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:296:8
#17 0x00000000002487e8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/tools/driver/cc1_main.cpp:286:13
#18 0x000000000023b8ae ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/tools/driver/driver.cpp:218:5
#19 0x000000000023a652 clang_main(int, char**, llvm::ToolContext const&) /ptmp2/vanbeuse-ptmp2/llvm-project/clang/tools/driver/driver.cpp:259:5
#20 0x000000000026cc45 main /ptmp2/vanbeuse-ptmp2/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:3
#21 0x00007fe397a2a24d __libc_start_main (/lib64/libc.so.6+0x3524d)
#22 0x000000000023a11a _start /home/abuild/rpmbuild/BUILD/glibc-2.31/csu/../sysdeps/x86_64/start.S:122:0
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 20.0.0git
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /ptmp2/vanbeuse-ptmp2/clang_install/bin
Build config: +unoptimized, +assertions


</details>

@Jason-VanBeusekom
Copy link
Author

Godbolt compilation for NVIDIA and AMD targets: https://godbolt.org/z/1rjf6KKrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

3 participants