<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74634>74634</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[openmp] Clang assertion failure with `declare target indirect`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
markdewing
</td>
</tr>
</table>
<pre>
Triggering the assertion involves template functions and function pointers.
The assertion message is
```
llvm-project/clang/include/clang/AST/Decl.h:275: llvm::StringRef clang::NamedDecl::getName() const: Assertion `Name.isIdentifier() && "Name is not a simple identifier"' failed.
```
Test case: (`indirect.cpp`)
```
// Compiler assertion does not trigger unless "indirect" is present
#pragma omp begin declare target indirect
template <typename T> class Cmp {
public:
bool operator()(T a) const {
return a == 1;
}
};
#pragma omp end declare target
typedef bool (*func_ptr_ty)(int *);
template <typename Cmp> bool func_wrapper(int *a) {
Cmp c;
return c(*(int *)a);
}
int main()
{
int i = 1;
func_ptr_ty f = &func_wrapper<Cmp<int>>;
}
```
Compile command is `clang++ -c indirect.cpp -fopenmp`.
(It's interesting that even though `declare target` is an offloading construct, the assertion occurs even if no offloading is specified on the command line)
<details>
<summary>Stack Trace</summary>
```
clang++: /home/mdewing/prev/software/llvm/llvm-project/clang/include/clang/AST/Decl.h:275: llvm::StringRef clang::NamedDecl::getName() const: Assertion `Name.isIdentifier() && "Name is not a simple identifier"' 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: clang++ -c indirect.cpp -fopenmp
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. indirect.cpp:7:8: Generating code for declaration 'Cmp<int>::operator()'
#0 0x0000561ab89e6810 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x224d810)
#1 0x0000561ab89e3c1f llvm::sys::RunSignalHandlers() (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x224ac1f)
#2 0x0000561ab8931b48 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f5947642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f59476969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f59476969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007f59476969fc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007f5947642476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007f59476287f3 abort ./stdlib/abort.c:81:7
#9 0x00007f594762871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f5947639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x0000561ab91a5d65 clang::CodeGen::CGOpenMPRuntime::emitDeclareTargetFunction(clang::FunctionDecl const*, llvm::GlobalValue*) (.part.0) CGOpenMPRuntime.cpp:0:0
#12 0x0000561ab8d9fccd clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2606ccd)
#13 0x0000561ab8daa8ab clang::CodeGen::CodeGenModule::EmitDeferred() (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x26118ab)
#14 0x0000561ab8daa800 clang::CodeGen::CodeGenModule::EmitDeferred() (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2611800)
#15 0x0000561ab8daa800 clang::CodeGen::CodeGenModule::EmitDeferred() (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2611800)
#16 0x0000561ab8dad104 clang::CodeGen::CodeGenModule::Release() (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2614104)
#17 0x0000561ab9c18832 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#18 0x0000561ab9c159e5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x347c9e5)
#19 0x0000561abad3e449 clang::ParseAST(clang::Sema&, bool, bool) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x45a5449)
#20 0x0000561ab94a3519 clang::FrontendAction::Execute() (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2d0a519)
#21 0x0000561ab941f1f5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2c861f5)
#22 0x0000561ab956d9f5 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2dd49f5)
#23 0x0000561ab7560359 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0xdc7359)
#24 0x0000561ab7558343 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x0000561ab926821d 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
#26 0x0000561ab8932010 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2199010)
#27 0x0000561ab9268a9e 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
#28 0x0000561ab922e8ca clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2a958ca)
#29 0x0000561ab922f39d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2a9639d)
#30 0x0000561ab923ac34 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0x2aa1c34)
#31 0x0000561ab755d840 clang_main(int, char**, llvm::ToolContext const&) (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0xdc4840)
#32 0x0000561ab74b0663 main (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0xd17663)
#33 0x00007f5947629d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#34 0x00007f5947629e40 call_init ./csu/../csu/libc-start.c:128:20
#35 0x00007f5947629e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#36 0x0000561ab7556f85 _start (/home/mdewing/prev/software/llvm/usr_main/bin/clang-18+0xdbdf85)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 3cd2a0bc1a2dcf851f1821765946b77d0e65bd2e)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/mdewing/prev/software/llvm/usr_main/bin
clang++: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/indirect-34385a.cpp
clang++: note: diagnostic msg: /tmp/indirect-34385a.sh
clang++: note: diagnostic msg:
********************
```
</details>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWt1y46izfxrlhopLQt8XuXCceHa2ZnemEu-eSxeClsMZCVSAMsnbnwJkWzhOarMns_X_qMpoLGiaXzfdTdOIaM13AuAqyq-j_OaCjOZBqqueqO8MfnCxu2gke77aKL7bgeJih8wDIKI1KMOlQFw8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