<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/88038>88038</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Segfault with `-fcoverage-mapping -fcs-profile-generate -fprofile-instr-generate`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          patrick-rivos
      </td>
    </tr>
</table>

<pre>
    Testcase:
```c
int main()
{
        return 0;
}
```

Backtrace:
```
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: /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19 -cc1 -triple riscv64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir rv64gcv.out- -disable-free -clear-ast-before-backend -main-file-name red.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic-rv64 -target-feature +m -target-feature +a -target-feature +f -target-feature +d -target-feature +c -target-feature +zicsr -target-feature -e -target-feature -h -target-feature -shcounterenw -target-feature -shgatpa -target-feature -shtvala -target-feature -shvsatpa -target-feature -shvstvala -target-feature -shvstvecd -target-feature -smaia -target-feature -smepmp -target-feature -ssaia -target-feature -ssccptr -target-feature -sscofpmf -target-feature -sscounterenw -target-feature -ssstateen -target-feature -ssstrict -target-feature -sstc -target-feature -sstvala -target-feature -sstvecd -target-feature -ssu64xl -target-feature -svade -target-feature -svadu -target-feature -svbare -target-feature -svinval -target-feature -svnapot -target-feature -svpbmt -target-feature -v -target-feature -xcvalu -target-feature -xcvbi -target-feature -xcvbitmanip -target-feature -xcvelw -target-feature -xcvmac -target-feature -xcvmem -target-feature -xcvsimd -target-feature -xsfcease -target-feature -xsfvcp -target-feature -xsfvfnrclipxfqf -target-feature -xsfvfwmaccqqq -target-feature -xsfvqmaccdod -target-feature -xsfvqmaccqoq -target-feature -xsifivecdiscarddlone -target-feature -xsifivecflushdlone -target-feature -xtheadba -target-feature -xtheadbb -target-feature -xtheadbs -target-feature -xtheadcmo -target-feature -xtheadcondmov -target-feature -xtheadfmemidx -target-feature -xtheadmac -target-feature -xtheadmemidx -target-feature -xtheadmempair -target-feature -xtheadsync -target-feature -xtheadvdot -target-feature -xventanacondops -target-feature -za128rs -target-feature -za64rs -target-feature -zacas -target-feature -zawrs -target-feature -zba -target-feature -zbb -target-feature -zbc -target-feature -zbkb -target-feature -zbkc -target-feature -zbkx -target-feature -zbs -target-feature -zca -target-feature -zcb -target-feature -zcd -target-feature -zce -target-feature -zcf -target-feature -zcmp -target-feature -zcmt -target-feature -zdinx -target-feature -zfa -target-feature -zfh -target-feature -zfhmin -target-feature -zfinx -target-feature -zhinx -target-feature -zhinxmin -target-feature -zic64b -target-feature -zicbom -target-feature -zicbop -target-feature -zicboz -target-feature -ziccamoa -target-feature -ziccif -target-feature -zicclsm -target-feature -ziccrse -target-feature -zicntr -target-feature -zicond -target-feature -zifencei -target-feature -zihintntl -target-feature -zihintpause -target-feature -zihpm -target-feature -zk -target-feature -zkn -target-feature -zknd -target-feature -zkne -target-feature -zknh -target-feature -zkr -target-feature -zks -target-feature -zksed -target-feature -zksh -target-feature -zkt -target-feature -zmmul -target-feature -zvbb -target-feature -zvbc -target-feature -zve32f -target-feature -zve32x -target-feature -zve64d -target-feature -zve64f -target-feature -zve64x -target-feature -zvfh -target-feature -zvfhmin -target-feature -zvkb -target-feature -zvkg -target-feature -zvkn -target-feature -zvknc -target-feature -zvkned -target-feature -zvkng -target-feature -zvknha -target-feature -zvknhb -target-feature -zvks -target-feature -zvksc -target-feature -zvksed -target-feature -zvksg -target-feature -zvksh -target-feature -zvkt -target-feature -zvl1024b -target-feature -zvl128b -target-feature -zvl16384b -target-feature -zvl2048b -target-feature -zvl256b -target-feature -zvl32768b -target-feature -zvl32b -target-feature -zvl4096b -target-feature -zvl512b -target-feature -zvl64b -target-feature -zvl65536b -target-feature -zvl8192b -target-feature -experimental-smmpm -target-feature -experimental-smnpm -target-feature -experimental-ssnpm -target-feature -experimental-sspm -target-feature -experimental-ssqosid -target-feature -experimental-supm -target-feature -experimental-zaamo -target-feature -experimental-zabha -target-feature -experimental-zalasr -target-feature -experimental-zalrsc -target-feature -experimental-zcmop -target-feature -experimental-zfbfmin -target-feature -experimental-zicfilp -target-feature -experimental-zicfiss -target-feature -experimental-zimop -target-feature -experimental-ztso -target-feature -experimental-zvfbfmin -target-feature -experimental-zvfbfwma -target-feature +relax -target-abi lp64d -msmall-data-limit 8 -debugger-tuning=gdb -fdebug-compilation-dir=/scratch/tc-testing/compiler-fuzz-ci/csmith-discoveries/llvm-rand-opt-12-7 -fprofile-instrument=clang -fprofile-instrument=csllvm -fcoverage-mapping -fcoverage-compilation-dir=/scratch/tc-testing/compiler-fuzz-ci/csmith-discoveries/llvm-rand-opt-12-7 -resource-dir /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/lib/clang/19 -isysroot /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/../sysroot -internal-isystem /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/lib/clang/19/include -internal-isystem /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/../sysroot/usr/local/include -internal-isystem /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/../sysroot/lib/gcc/riscv64-unknown-linux-gnu/14.0.1/../../../../riscv64-unknown-linux-gnu/include -internal-externc-isystem /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/../sysroot/include -internal-externc-isystem /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/../sysroot/usr/include -w -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scratch/tmp/red-821828.o -x c red.c
1. <eof> parser at end of file
2.      Per-file LLVM IR generation
 #0 0x00006451a8f09730 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x1e50730)
 #1 0x00006451a8f06b3f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x1e4db3f)
 #2 0x00006451a8f06c95 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007bcb42a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00006451a88a1e53 llvm::ConstantArray::getImpl(llvm::ArrayType*, llvm::ArrayRef<llvm::Constant*>) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x17e8e53)
 #5 0x00006451a88a7bc6 llvm::ConstantArray::get(llvm::ArrayType*, llvm::ArrayRef<llvm::Constant*>) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x17eebc6)
 #6 0x00006451a9322b9b clang::CodeGen::CoverageMappingModuleGen::emit() (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x2269b9b)
 #7 0x00006451a92d61e0 clang::CodeGen::CodeGenModule::Release() (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x221d1e0)
 #8 0x00006451a9785f26 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
 #9 0x00006451a9783793 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x26ca793)
#10 0x00006451ab40215c clang::ParseAST(clang::Sema&, bool, bool) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x434915c)
#11 0x00006451a9a1b539 clang::FrontendAction::Execute() (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x2962539)
#12 0x00006451a999f856 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x28e6856)
#13 0x00006451a9aecee5 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0x2a33ee5)
#14 0x00006451a7db6eaf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0xcfdeaf)
#15 0x00006451a7db0593 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#16 0x00006451a7db330f clang_main(int, char**, llvm::ToolContext const&) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0xcfa30f)
#17 0x00006451a7cf19eb main (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0xc389eb)
#18 0x00007bcb42a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#19 0x00007bcb42a29e40 call_init ./csu/../csu/libc-start.c:128:20
#20 0x00007bcb42a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#21 0x00006451a7daf845 _start (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang-19+0xcf6845)
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 19.0.0git (https://github.com/llvm/llvm-project.git 1b761205f2686516cebadbcbc37f798197d9c482)
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/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: /scratch/tmp/red-935bc8.c
clang: note: diagnostic msg: /scratch/tmp/red-935bc8.sh
clang: note: diagnostic msg:

********************
```

Godbolt: https://godbolt.org/z/8je4971YM

Reproducer: 
[red-935bc8.zip](https://github.com/llvm/llvm-project/files/14910724/red-935bc8.zip)

Found via fuzzer.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWl9z27iu_zTKC4ceifpj6SEPTlJ3O9Pe7TQ5e-Y-ZSgKsrmmSJWkFNef_g4p548cuu2es-nO7aSJDYAgfgAISiCpMXwjAS6j_CrKby7oYLdKX_bUas52WPNRmYtaNd8u78BYRg1E6SqKb6J4FRXx9MOm71xa1FEuI1JGpDrKLK-mD-j4T4MdtERxlF49StycqDt-9b-vKNtZTVlg1unr54_vVrfvkBnqjltEUT1skIZeaYusQltre-OGknVE1htut0O9YKqLyFqI8fEP7rX6E5iNyJobM4CJyBpR2SAumRgaQHYLiGlqtqh-sodco15DrxUDY6BBRg16IruR1BjFOLXQID1IZJjmvV1MJt9aynaoGbr-CVS8QJ-12mjaIao3QwfSOrNRRNaGaWrZNiJry7AFY7ncTF9or3EWkXU9cNFgPRbZho1P3z0wweWwdyQXlTUTVG5wUiHMWIKw1bwXgDQ3bCwyPMidVA9yGoM3ckAYOm6xqv9EuNMg6B5TIRB2ljdco-OMCzVYjHDDDa0F4FYDIMwEUI2psbiGVmnAznEgG4RdhuCWC8CSdoA0NAs26VeMWq4k7lQDAvWcIdxzhgWMIBCZvnCDew4Id62mHeBecWlBR-mNt6ztqN1i0FoqhNu2x0xJFy0bpTdKItxKhbUaZMPlBjtZhDumpLF6YFZpTAWnBgzC7SAfuGywdZBMlN4QhC3VG7CY9QPagATNmff5E6MFagcNKCJXXYhIQ8Q2RGxCRBYiHjgz-hUDw2vS9jXJbJ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