Skip to content

[clang][SYCL] Unreacheable executed for SYCL device compilation #167358

@Fznamznon

Description

@Fznamznon

For the following sample (https://godbolt.org/z/W4d7G148K):

template <typename KN, typename KT>
[[clang::sycl_kernel_entry_point(KN)]] void k(KT) {}

int main() {
    k<struct K>([](){});
    return 0;
}

Compiled with:

clang -cc1 t.cpp -fsycl-is-device -emit-llvm

results in the following assertion hit

Unknown kernel calling convention
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/CodeGen/TargetInfo.cpp:129!
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 -Xclang -fsycl-is-device <source>
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
 #0 0x000000000424f278 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x424f278)
 #1 0x000000000424c6a4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x424c6a4)
 #2 0x0000000004190908 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007deb48a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007deb48a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007deb48a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007deb48a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000000000419c4ea (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x419c4ea)
 #8 0x00000000049bc8a0 clang::CodeGen::TargetCodeGenInfo::createEnqueuedBlockKernel(clang::CodeGen::CodeGenFunction&, llvm::Function*, llvm::Type*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49bc8a0)
 #9 0x0000000004a92f60 clang::CodeGen::CodeGenTypes::arrangeLLVMFunctionInfo(clang::CanQual<clang::Type>, clang::CodeGen::FnInfoOpts, llvm::ArrayRef<clang::CanQual<clang::Type>>, clang::FunctionType::ExtInfo, llvm::ArrayRef<clang::FunctionType::ExtParameterInfo>, clang::CodeGen::RequiredArgs) (.constprop.0) CGCall.cpp:0:0
#10 0x0000000004a93912 clang::CodeGen::CodeGenTypes::arrangeDeviceKernelCallerDeclaration(clang::QualType, clang::CodeGen::FunctionArgList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a93912)
#11 0x000000000487652e clang::CodeGen::CodeGenModule::EmitSYCLKernelCaller(clang::FunctionDecl const*, clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x487652e)
#12 0x000000000483cd2c clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x483cd2c)
#13 0x000000000483f1e3 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x483f1e3)
#14 0x0000000004b9f54e (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#15 0x0000000004b9b555 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b9b555)
#16 0x000000000694c15c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x694c15c)
#17 0x0000000004b9bd38 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b9bd38)
#18 0x0000000004e8a285 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e8a285)
#19 0x0000000004e0b08e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e0b08e)
#20 0x0000000004f8242d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f8242d)
#21 0x0000000000dd3d00 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdd3d00)
#22 0x0000000000dca87a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#23 0x0000000000dca9fd int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#24 0x0000000004c05bb9 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 0x0000000004190da4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4190da4)
#26 0x0000000004c061cf 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 0x0000000004bc6c22 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bc6c22)
#28 0x0000000004bc7bce 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+++0x4bc7bce)
#29 0x0000000004bcf325 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bcf325)
#30 0x0000000000dd0221 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdd0221)
#31 0x0000000000c7e7b4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc7e7b4)
#32 0x00007deb48a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#33 0x00007deb48a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#34 0x0000000000dca315 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdca315)

this happens when a target supplied is not a correct offloading target. It should be either accepted or rejected with a message saying that the target is not a valid offloading target for sycl device compilation.

This issue is annoying because each time the target is forgotten in the command line, the host target is substituted and it is usually not an offloading target.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SYCLhttps://registry.khronos.org/SYCLclang:codegenIR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions