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 18.1.0-rc / trunk crash when generating code with coverage information - `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed #79957

Closed
jeremiahar opened this issue Jan 30, 2024 · 3 comments
Labels
clang:codegen coverage crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@jeremiahar
Copy link

jeremiahar commented Jan 30, 2024

The following code crashes clang when compiled with code coverage enabled:

typedef void (*FunctionType)();

template <FunctionType table[]>
void Dispatch()
{
 table[1]();
}

void Handler()
{

}

FunctionType Funcs[2] = {
 &Dispatch<Funcs>,
 &Handler
};

void Foo()
{
 Funcs[0]();
}

Compiled with:

clang++-18 -std=c++17 -fprofile-instr-generate -fcoverage-mapping -c main.cpp

Clang 18.1.0 version:

root@90719c8e4fca:/test# clang++-18 -v
Debian clang version 18.1.0 (++20240129063153+3df71e5a3f5d-1~exp1~20240129183258.13)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64

Backtrace from clang 18.1.0:

root@90719c8e4fca:/test# clang++-18 -std=c++17 -fprofile-instr-generate -fcoverage-mapping -c main.cpp
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++-18 -std=c++17 -fprofile-instr-generate -fcoverage-mapping -c main.cpp
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      main.cpp:5:6: Generating code for declaration 'Dispatch'
 #0 0x000071b570df2bd6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd90bd6)
 #1 0x000071b570df0c00 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd8ec00)
 #2 0x000071b570d3ce40 (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xcdae40)
 #3 0x000071b56fb9afd0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bfd0)
 #4 0x000071b57967fff7 getStmtClass build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Stmt.h:1357:44
 #5 0x000071b57967fff7 classof build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Expr.h:3980:15
 #6 0x000071b57967fff7 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:64:53
 #7 0x000071b57967fff7 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:110:12
 #8 0x000071b57967fff7 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:137:12
 #9 0x000071b57967fff7 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:127:12
#10 0x000071b57967fff7 isPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:255:12
#11 0x000071b57967fff7 doCastIfPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:493:10
#12 0x000071b57967fff7 dyn_cast<clang::BinaryOperator, const clang::Stmt> build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:663:10
#13 0x000071b57967fff7 Visit build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/StmtVisitor.h:47:37
#14 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#15 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#16 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#17 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#18 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#19 0x000071b5796812d0 getTrailingStmts build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Expr.h:2832:51
#20 0x000071b5796812d0 getTrailingStmts build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Expr.h:2835:42
#21 0x000071b5796812d0 getCallee build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Expr.h:2947:53
#22 0x000071b5796812d0 VisitCallExpr build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:1481:30
#23 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#24 0x000071b57967fe33 begin build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/SmallVector.h:280:45
#25 0x000071b57967fe33 end build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/SmallVector.h:282:27
#26 0x000071b57967fe33 back build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/SmallVector.h:323:12
#27 0x000071b57967fe33 getRegion build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:998:24
#28 0x000071b57967fe33 propagateCounts build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:1010:25
#29 0x000071b57967e591 clang::CodeGen::CoverageMappingGen::emitCounterMapping(clang::Decl const*, llvm::raw_ostream&) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#30 0x000071b57964f025 flush build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/raw_ostream.h:186:9
#31 0x000071b57964f025 clang::CodeGen::CodeGenPGO::emitCounterRegionMapping(clang::Decl const*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenPGO.cpp:1042:6
#32 0x000071b57964eba2 clang::CodeGen::CodeGenPGO::assignRegionCounters(clang::GlobalDecl, llvm::Function*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenPGO.cpp:0:5
#33 0x000071b5795f89ed getKind build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/DeclBase.h:447:51
#34 0x000071b5795f89ed classof build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/DeclCXX.h:2841:62
#35 0x000071b5795f89ed doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:64:53
#36 0x000071b5795f89ed doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:110:12
#37 0x000071b5795f89ed doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:137:12
#38 0x000071b5795f89ed doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:127:12
#39 0x000071b5795f89ed isPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:255:12
#40 0x000071b5795f89ed isPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:509:12
#41 0x000071b5795f89ed isa<clang::CXXDestructorDecl, const clang::FunctionDecl *> build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:549:10
#42 0x000071b5795f89ed clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenFunction.cpp:1449:7
#43 0x000071b579619935 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:5834:3
#44 0x000071b5796131fb clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:0:12
#45 0x000071b579606613 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_iterator.h:1073:20
#46 0x000071b579606613 begin /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_vector.h:879:16
#47 0x000071b579606613 empty /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_vector.h:1084:16
#48 0x000071b579606613 clang::CodeGen::CodeGenModule::EmitDeferred() build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:3192:26
#49 0x000071b57960428b empty build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/DenseMap.h:98:61
#50 0x000071b57960428b begin build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/DenseMap.h:78:9
#51 0x000071b57960428b clang::CodeGen::CodeGenModule::Release() build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:807:45
#52 0x000071b5796b0d98 HandleTranslationUnit build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/ModuleBuilder.cpp:291:11
#53 0x000071b5795e9240 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenAction.cpp:306:9
#54 0x000071b57821a846 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_iterator.h:1073:20
#55 0x000071b57821a846 begin /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_vector.h:869:16
#56 0x000071b57821a846 finalize<std::vector<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> >, std::allocator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> > > > > build-llvm/tools/clang/stage2-bins/clang/include/clang/Sema/TemplateInstCallback.h:54:16
#57 0x000071b57821a846 clang::ParseAST(clang::Sema&, bool, bool) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/ParseAST.cpp:183:3
#58 0x000071b57a049025 clang::FrontendAction::Execute() build-llvm/tools/clang/stage2-bins/clang/lib/Frontend/FrontendAction.cpp:1073:10
#59 0x000071b579fbfef4 getPtr build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Error.h:279:12
#60 0x000071b579fbfef4 operator bool build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Error.h:239:16
#61 0x000071b579fbfef4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) build-llvm/tools/clang/stage2-bins/clang/lib/Frontend/CompilerInstance.cpp:1057:23
#62 0x000071b57a0c401e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) build-llvm/tools/clang/stage2-bins/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:25
#63 0x000064712c40fe0a cc1_main(llvm::ArrayRef<char const*>, char const*, void*) build-llvm/tools/clang/stage2-bins/clang/tools/driver/cc1_main.cpp:294:15
#64 0x000064712c40d195 ExecuteCC1Tool build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:365:12
#65 0x000071b579c79e99 operator() build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Job.cpp:440:30
#66 0x000071b579c79e99 callback_fn<(lambda at clang/lib/Driver/Job.cpp:440:22)> build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#67 0x000071b570d3cbdc llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xcdabdc)
#68 0x000071b579c7981e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Job.cpp:440:7
#69 0x000071b579c41a11 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Compilation.cpp:199:15
#70 0x000071b579c41c5e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Compilation.cpp:253:13
#71 0x000071b579c5e29d empty build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/SmallVector.h:94:46
#72 0x000071b579c5e29d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Driver.cpp:1921:23
#73 0x000064712c40cb04 clang_main(int, char**, llvm::ToolContext const&) build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:540:21
#74 0x000064712c419f16 main build-llvm/tools/clang/stage2-bins/build-llvm/tools/clang/stage2-bins/tools/clang/tools/driver/clang-driver.cpp:17:10
#75 0x000071b56fb861ca (/lib/x86_64-linux-gnu/libc.so.6+0x271ca)
#76 0x000071b56fb86285 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27285)
#77 0x000064712c409bc1 _start (/usr/lib/llvm-18/bin/clang+0xcbc1)
clang++-18: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Debian clang version 18.1.0 (++20240129063153+3df71e5a3f5d-1~exp1~20240129183258.13)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang++-18: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++-18: note: diagnostic msg: /tmp/main-469ae6.cpp
clang++-18: note: diagnostic msg: /tmp/main-469ae6.sh
clang++-18: note: diagnostic msg: 

********************

Clang trunk (assertions enabled) Godbolt link:
https://godbolt.org/z/8T5GqcfTs

Backtrace from clang trunk:

clang++: /root/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = clang::BinaryOperator; From = const clang::Stmt]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' 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++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++17 -fprofile-instr-generate -fcoverage-mapping <source>
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
3.	<source>:4:6: Generating code for declaration 'Dispatch'
 #0 0x0000000003878878 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3878878)
 #1 0x000000000387655c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x387655c)
 #2 0x00000000037bf4c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f4ea9442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f4ea94969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f4ea9442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f4ea94287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f4ea942871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f4ea9439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000003cd17c9 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void>::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#10 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#11 0x0000000003cd19e4 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void>::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#12 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#13 0x0000000003cd1697 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void>::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#14 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#15 0x0000000003cd1db4 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void>::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#16 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#17 0x0000000003cd1af4 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void>::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#18 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#19 0x0000000003cd3b72 (anonymous namespace)::CounterCoverageMappingBuilder::VisitCallExpr(clang::CallExpr const*) CoverageMappingGen.cpp:0:0
#20 0x0000000003cd1b94 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void>::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#21 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#22 0x0000000003cd29c8 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void>::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#23 0x0000000003cd89ab clang::CodeGen::CoverageMappingGen::emitCounterMapping(clang::Decl const*, llvm::raw_ostream&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cd89ab)
#24 0x0000000003c85b50 clang::CodeGen::CodeGenPGO::emitCounterRegionMapping(clang::Decl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c85b50)
#25 0x0000000003cb8f1b clang::CodeGen::CodeGenPGO::assignRegionCounters(clang::GlobalDecl, llvm::Function*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cb8f1b)
#26 0x0000000003c154d3 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c154d3)
#27 0x0000000003c78412 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c78412)
#28 0x0000000003c72d15 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c72d15)
#29 0x0000000003c7e3fd clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c7e3fd)
#30 0x0000000003c811d3 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c811d3)
#31 0x0000000004104ada (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#32 0x00000000041035fd clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41035fd)
#33 0x00000000060a4979 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x60a4979)
#34 0x0000000004102eb8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4102eb8)
#35 0x0000000004371739 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4371739)
#36 0x00000000042f139e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42f139e)
#37 0x0000000004451e1e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4451e1e)
#38 0x0000000000c13226 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc13226)
#39 0x0000000000c0aa6a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#40 0x00000000041443f9 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
#41 0x00000000037bf974 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x37bf974)
#42 0x00000000041449ef 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
#43 0x000000000410c755 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x410c755)
#44 0x000000000410d1bd 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+++0x410d1bd)
#45 0x00000000041150f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41150f5)
#46 0x0000000000c105dc clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc105dc)
#47 0x0000000000b07a74 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb07a74)
#48 0x00007f4ea9429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#49 0x00007f4ea9429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#50 0x0000000000c0a54e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc0a54e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

The test case is reduced from Highway's dispatch code https://github.com/google/highway/blob/cc0a171fb9bf8af5e8904b77259ce4ca5461172b/hwy/highway.h#L379 .

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jan 30, 2024
@EugeneZelenko EugeneZelenko added clang:codegen coverage crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Jan 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2024

@llvm/issue-subscribers-clang-codegen

Author: Jeremiah Rodriguez (jeremiahar)

The following code crashes clang when compiled with code coverage enabled:
typedef void (*FunctionType)();

template &lt;FunctionType table[]&gt;
void Dispatch()
{
 table[1]();
}

void Handler()
{

}

FunctionType Funcs[2] = {
 &amp;Dispatch&lt;Funcs&gt;,
 &amp;Handler
};

void Foo()
{
 Funcs[0]();
}

Compiled with:

clang++-18 -std=c++17 -fprofile-instr-generate -fcoverage-mapping -c main.cpp

Clang 18.1.0 version:

root@<!-- -->90719c8e4fca:/test# clang++-18 -v
Debian clang version 18.1.0 (++20240129063153+3df71e5a3f5d-1~exp1~20240129183258.13)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@<!-- -->m64
Selected multilib: .;@<!-- -->m64

Backtrace from clang 18.1.0:

root@<!-- -->90719c8e4fca:/test# clang++-18 -std=c++17 -fprofile-instr-generate -fcoverage-mapping -c main.cpp
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++-18 -std=c++17 -fprofile-instr-generate -fcoverage-mapping -c main.cpp
1.      &lt;eof&gt; parser at end of file
2.      Per-file LLVM IR generation
3.      main.cpp:5:6: Generating code for declaration 'Dispatch'
 #<!-- -->0 0x000071b570df2bd6 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd90bd6)
 #<!-- -->1 0x000071b570df0c00 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd8ec00)
 #<!-- -->2 0x000071b570d3ce40 (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xcdae40)
 #<!-- -->3 0x000071b56fb9afd0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bfd0)
 #<!-- -->4 0x000071b57967fff7 getStmtClass build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Stmt.h:1357:44
 #<!-- -->5 0x000071b57967fff7 classof build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Expr.h:3980:15
 #<!-- -->6 0x000071b57967fff7 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:64:53
 #<!-- -->7 0x000071b57967fff7 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:110:12
 #<!-- -->8 0x000071b57967fff7 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:137:12
 #<!-- -->9 0x000071b57967fff7 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:127:12
#<!-- -->10 0x000071b57967fff7 isPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:255:12
#<!-- -->11 0x000071b57967fff7 doCastIfPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:493:10
#<!-- -->12 0x000071b57967fff7 dyn_cast&lt;clang::BinaryOperator, const clang::Stmt&gt; build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:663:10
#<!-- -->13 0x000071b57967fff7 Visit build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/StmtVisitor.h:47:37
#<!-- -->14 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#<!-- -->15 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#<!-- -->16 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#<!-- -->17 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#<!-- -->18 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#<!-- -->19 0x000071b5796812d0 getTrailingStmts build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Expr.h:2832:51
#<!-- -->20 0x000071b5796812d0 getTrailingStmts build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Expr.h:2835:42
#<!-- -->21 0x000071b5796812d0 getCallee build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Expr.h:2947:53
#<!-- -->22 0x000071b5796812d0 VisitCallExpr build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:1481:30
#<!-- -->23 0x000071b5796858a2 VisitStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#<!-- -->24 0x000071b57967fe33 begin build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/SmallVector.h:280:45
#<!-- -->25 0x000071b57967fe33 end build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/SmallVector.h:282:27
#<!-- -->26 0x000071b57967fe33 back build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/SmallVector.h:323:12
#<!-- -->27 0x000071b57967fe33 getRegion build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:998:24
#<!-- -->28 0x000071b57967fe33 propagateCounts build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:1010:25
#<!-- -->29 0x000071b57967e591 clang::CodeGen::CoverageMappingGen::emitCounterMapping(clang::Decl const*, llvm::raw_ostream&amp;) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CoverageMappingGen.cpp:0:0
#<!-- -->30 0x000071b57964f025 flush build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/raw_ostream.h:186:9
#<!-- -->31 0x000071b57964f025 clang::CodeGen::CodeGenPGO::emitCounterRegionMapping(clang::Decl const*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenPGO.cpp:1042:6
#<!-- -->32 0x000071b57964eba2 clang::CodeGen::CodeGenPGO::assignRegionCounters(clang::GlobalDecl, llvm::Function*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenPGO.cpp:0:5
#<!-- -->33 0x000071b5795f89ed getKind build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/DeclBase.h:447:51
#<!-- -->34 0x000071b5795f89ed classof build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/DeclCXX.h:2841:62
#<!-- -->35 0x000071b5795f89ed doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:64:53
#<!-- -->36 0x000071b5795f89ed doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:110:12
#<!-- -->37 0x000071b5795f89ed doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:137:12
#<!-- -->38 0x000071b5795f89ed doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:127:12
#<!-- -->39 0x000071b5795f89ed isPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:255:12
#<!-- -->40 0x000071b5795f89ed isPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:509:12
#<!-- -->41 0x000071b5795f89ed isa&lt;clang::CXXDestructorDecl, const clang::FunctionDecl *&gt; build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:549:10
#<!-- -->42 0x000071b5795f89ed clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&amp;) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenFunction.cpp:1449:7
#<!-- -->43 0x000071b579619935 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:5834:3
#<!-- -->44 0x000071b5796131fb clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:0:12
#<!-- -->45 0x000071b579606613 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_iterator.h:1073:20
#<!-- -->46 0x000071b579606613 begin /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_vector.h:879:16
#<!-- -->47 0x000071b579606613 empty /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_vector.h:1084:16
#<!-- -->48 0x000071b579606613 clang::CodeGen::CodeGenModule::EmitDeferred() build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:3192:26
#<!-- -->49 0x000071b57960428b empty build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/DenseMap.h:98:61
#<!-- -->50 0x000071b57960428b begin build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/DenseMap.h:78:9
#<!-- -->51 0x000071b57960428b clang::CodeGen::CodeGenModule::Release() build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:807:45
#<!-- -->52 0x000071b5796b0d98 HandleTranslationUnit build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/ModuleBuilder.cpp:291:11
#<!-- -->53 0x000071b5795e9240 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenAction.cpp:306:9
#<!-- -->54 0x000071b57821a846 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_iterator.h:1073:20
#<!-- -->55 0x000071b57821a846 begin /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_vector.h:869:16
#<!-- -->56 0x000071b57821a846 finalize&lt;std::vector&lt;std::unique_ptr&lt;clang::TemplateInstantiationCallback, std::default_delete&lt;clang::TemplateInstantiationCallback&gt; &gt;, std::allocator&lt;std::unique_ptr&lt;clang::TemplateInstantiationCallback, std::default_delete&lt;clang::TemplateInstantiationCallback&gt; &gt; &gt; &gt; &gt; build-llvm/tools/clang/stage2-bins/clang/include/clang/Sema/TemplateInstCallback.h:54:16
#<!-- -->57 0x000071b57821a846 clang::ParseAST(clang::Sema&amp;, bool, bool) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/ParseAST.cpp:183:3
#<!-- -->58 0x000071b57a049025 clang::FrontendAction::Execute() build-llvm/tools/clang/stage2-bins/clang/lib/Frontend/FrontendAction.cpp:1073:10
#<!-- -->59 0x000071b579fbfef4 getPtr build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Error.h:279:12
#<!-- -->60 0x000071b579fbfef4 operator bool build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Error.h:239:16
#<!-- -->61 0x000071b579fbfef4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) build-llvm/tools/clang/stage2-bins/clang/lib/Frontend/CompilerInstance.cpp:1057:23
#<!-- -->62 0x000071b57a0c401e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) build-llvm/tools/clang/stage2-bins/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:25
#<!-- -->63 0x000064712c40fe0a cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) build-llvm/tools/clang/stage2-bins/clang/tools/driver/cc1_main.cpp:294:15
#<!-- -->64 0x000064712c40d195 ExecuteCC1Tool build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:365:12
#<!-- -->65 0x000071b579c79e99 operator() build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Job.cpp:440:30
#<!-- -->66 0x000071b579c79e99 callback_fn&lt;(lambda at clang/lib/Driver/Job.cpp:440:22)&gt; build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#<!-- -->67 0x000071b570d3cbdc llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xcdabdc)
#<!-- -->68 0x000071b579c7981e clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Job.cpp:440:7
#<!-- -->69 0x000071b579c41a11 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Compilation.cpp:199:15
#<!-- -->70 0x000071b579c41c5e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Compilation.cpp:253:13
#<!-- -->71 0x000071b579c5e29d empty build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/SmallVector.h:94:46
#<!-- -->72 0x000071b579c5e29d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Driver.cpp:1921:23
#<!-- -->73 0x000064712c40cb04 clang_main(int, char**, llvm::ToolContext const&amp;) build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:540:21
#<!-- -->74 0x000064712c419f16 main build-llvm/tools/clang/stage2-bins/build-llvm/tools/clang/stage2-bins/tools/clang/tools/driver/clang-driver.cpp:17:10
#<!-- -->75 0x000071b56fb861ca (/lib/x86_64-linux-gnu/libc.so.6+0x271ca)
#<!-- -->76 0x000071b56fb86285 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27285)
#<!-- -->77 0x000064712c409bc1 _start (/usr/lib/llvm-18/bin/clang+0xcbc1)
clang++-18: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Debian clang version 18.1.0 (++20240129063153+3df71e5a3f5d-1~exp1~20240129183258.13)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang++-18: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++-18: note: diagnostic msg: /tmp/main-469ae6.cpp
clang++-18: note: diagnostic msg: /tmp/main-469ae6.sh
clang++-18: note: diagnostic msg: 

********************

Clang trunk (assertions enabled) Godbolt link:
https://godbolt.org/z/8T5GqcfTs

Backtrace from clang trunk:

clang++: /root/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = clang::BinaryOperator; From = const clang::Stmt]: Assertion `detail::isPresent(Val) &amp;&amp; "dyn_cast on a non-existent value"' 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++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++17 -fprofile-instr-generate -fcoverage-mapping &lt;source&gt;
1.	&lt;eof&gt; parser at end of file
2.	Per-file LLVM IR generation
3.	&lt;source&gt;:4:6: Generating code for declaration 'Dispatch'
 #<!-- -->0 0x0000000003878878 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3878878)
 #<!-- -->1 0x000000000387655c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x387655c)
 #<!-- -->2 0x00000000037bf4c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #<!-- -->3 0x00007f4ea9442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->4 0x00007f4ea94969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #<!-- -->5 0x00007f4ea9442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #<!-- -->6 0x00007f4ea94287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #<!-- -->7 0x00007f4ea942871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #<!-- -->8 0x00007f4ea9439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #<!-- -->9 0x0000000003cd17c9 clang::StmtVisitorBase&lt;llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void&gt;::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->10 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->11 0x0000000003cd19e4 clang::StmtVisitorBase&lt;llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void&gt;::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->12 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->13 0x0000000003cd1697 clang::StmtVisitorBase&lt;llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void&gt;::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->14 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->15 0x0000000003cd1db4 clang::StmtVisitorBase&lt;llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void&gt;::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->16 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->17 0x0000000003cd1af4 clang::StmtVisitorBase&lt;llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void&gt;::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->18 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->19 0x0000000003cd3b72 (anonymous namespace)::CounterCoverageMappingBuilder::VisitCallExpr(clang::CallExpr const*) CoverageMappingGen.cpp:0:0
#<!-- -->20 0x0000000003cd1b94 clang::StmtVisitorBase&lt;llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void&gt;::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->21 0x0000000003cd3a43 (anonymous namespace)::CounterCoverageMappingBuilder::VisitStmt(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->22 0x0000000003cd29c8 clang::StmtVisitorBase&lt;llvm::make_const_ptr, (anonymous namespace)::CounterCoverageMappingBuilder, void&gt;::Visit(clang::Stmt const*) CoverageMappingGen.cpp:0:0
#<!-- -->23 0x0000000003cd89ab clang::CodeGen::CoverageMappingGen::emitCounterMapping(clang::Decl const*, llvm::raw_ostream&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cd89ab)
#<!-- -->24 0x0000000003c85b50 clang::CodeGen::CodeGenPGO::emitCounterRegionMapping(clang::Decl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c85b50)
#<!-- -->25 0x0000000003cb8f1b clang::CodeGen::CodeGenPGO::assignRegionCounters(clang::GlobalDecl, llvm::Function*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cb8f1b)
#<!-- -->26 0x0000000003c154d3 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c154d3)
#<!-- -->27 0x0000000003c78412 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c78412)
#<!-- -->28 0x0000000003c72d15 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c72d15)
#<!-- -->29 0x0000000003c7e3fd clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c7e3fd)
#<!-- -->30 0x0000000003c811d3 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c811d3)
#<!-- -->31 0x0000000004104ada (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&amp;) ModuleBuilder.cpp:0:0
#<!-- -->32 0x00000000041035fd clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41035fd)
#<!-- -->33 0x00000000060a4979 clang::ParseAST(clang::Sema&amp;, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x60a4979)
#<!-- -->34 0x0000000004102eb8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4102eb8)
#<!-- -->35 0x0000000004371739 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4371739)
#<!-- -->36 0x00000000042f139e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42f139e)
#<!-- -->37 0x0000000004451e1e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4451e1e)
#<!-- -->38 0x0000000000c13226 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc13226)
#<!-- -->39 0x0000000000c0aa6a ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->40 0x00000000041443f9 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->41 0x00000000037bf974 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x37bf974)
#<!-- -->42 0x00000000041449ef clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->43 0x000000000410c755 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x410c755)
#<!-- -->44 0x000000000410d1bd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x410d1bd)
#<!-- -->45 0x00000000041150f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41150f5)
#<!-- -->46 0x0000000000c105dc clang_main(int, char**, llvm::ToolContext const&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc105dc)
#<!-- -->47 0x0000000000b07a74 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb07a74)
#<!-- -->48 0x00007f4ea9429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->49 0x00007f4ea9429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->50 0x0000000000c0a54e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc0a54e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

The test case is reduced from Highway's dispatch code https://github.com/google/highway/blob/cc0a171fb9bf8af5e8904b77259ce4ca5461172b/hwy/highway.h#L379 .

@jeremiahar
Copy link
Author

Bisection between 400a02b (bad release/18.x) and 6009708 (good - 17.0.6) reveals that the first bad commit is 5518a9d.

@jeremiahar
Copy link
Author

This is no longer an issue now that the problematic code was reverted and a test was added to prevent the regression. #80050 It was also backported to the release/18.x branch in #80150 .

bolshakov-a added a commit to bolshakov-a/llvm-project that referenced this issue Mar 20, 2024
Introduced in llvm#78041, originally reported as llvm#79957 and fixed partially
in llvm#80050.

`OpaqueValueExpr` used with `TemplateArgument::StructuralValue` has no
corresponding source expression.

A test case with subobject-referring NTTP added.
efriedma-quic pushed a commit that referenced this issue May 24, 2024
…#85837)

Introduced in #78041, originally reported as #79957 and fixed partially
in #80050.

`OpaqueValueExpr` used with `TemplateArgument::StructuralValue` has no
corresponding source expression.

A test case with subobject-referring NTTP added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen coverage crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

3 participants