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

    <tr>
        <th>Summary</th>
        <td>
            Segfault in llvm::SwitchInst::init when building Linux fixdep
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          aik
      </td>
    </tr>
</table>

<pre>
    Found on POWER8 PPC64LE Ubuntu2104.

Upstream LLVM (sha1 e29dc0c6fde2 ) crashes when compiling Linux kernel if LLVM is built with gcc but does not crash if built with LLVM.
Crashes at `HOSTCC  scripts/basic/fixdep`.

The bad LLVM is built as:
`cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TARGETS_TO_BUILD=PowerPC ~/p/llvm/llvm-latest/llvm/ -DLLVM_ENABLE_LTO=ON -DLLVM_BINUTILS_INCDIR=/usr/include -DCMAKE_BUILD_TYPE=Release`

The good LLVM is built as:
`CC='clang' CXX='clang++' cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TARGETS_TO_BUILD=PowerPC ~/p/llvm/llvm-latest/llvm/ -DLLVM_ENABLE_LTO=ON   -DLLVM_ENABLE_LLD=ON -DLLVM_BINUTILS_INCDIR=/usr/include -DCMAKE_BUILD_TYPE=Release`

Ubuntu PPC64LE 21.04 host, gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0, Ubuntu clang version 12.0.0-3ubuntu1~21.04.2

Attaching the reproducer.
[fixdep-b209d4.tar.gz](https://github.com/llvm/llvm-project/files/8628754/fixdep-b209d4.tar.gz)

Backtrace looks like:
```
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: /mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15 -cc1 -triple powerpc64le-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name fixdep.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu ppc64le -mfloat-abi hard -target-abi elfv2 -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/mnt/sdb/pbuild/kernels-llvm/llvm-wip-llvm-latest-lto-full-cleanbuild -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -Wdeclaration-after-statement -std=gnu11 -fdebug-compilation-dir=/mnt/sdb/pbuild/kernels-llvm/llvm-wip-llvm-latest-lto-full-cleanbuild -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c fixdep-b209d4.c
1.      <eof> parser at end of file
2.      Optimizer
 #0 0x00000a757bf50a6c PrintStackTraceSignalHandler(void*) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x19a0a6c)
 #1 0x00000a757bef27d0 SignalHandler(int) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x19427d0)
 #2 0x000074666da70444 (linux-vdso64.so.1+0x444)
 #3 0x00000a757b8667a8 llvm::SwitchInst::init(llvm::Value*, llvm::BasicBlock*, unsigned int) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x12b67a8)
 #4 0x00000a757f1dd79c llvm::IRBuilderBase::CreateSwitch(llvm::Value*, llvm::BasicBlock*, unsigned int, llvm::MDNode*, llvm::MDNode*) (.constprop.0) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x4c2d79c)
 #5 0x00000a757c0c7ea0 (anonymous namespace)::SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(llvm::Instruction*, llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x1b17ea0)
 #6 0x00000a757c0f7e58 (anonymous namespace)::SimplifyCFGOpt::simplifyCondBranch(llvm::BranchInst*, llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x1b47e58)
 #7 0x00000a757c0f9a2c llvm::simplifyCFG(llvm::BasicBlock*, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&, llvm::ArrayRef<llvm::WeakVH>) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x1b49a2c)
 #8 0x00000a757be8f214 iterativelySimplifyCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x18df214)
 #9 0x00000a757bebfe48 simplifyFunctionCFGImpl(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) (.lto_priv.0) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x190fe48)
#10 0x00000a757cf1b770 llvm::detail::PassModel<llvm::Function, llvm::SimplifyCFGPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x296b770)
#11 0x00000a757b90d5d0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x135d5d0)
#12 0x00000a757c24f720 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x1c9f720)
#13 0x00000a757b925fc4 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x1375fc4)
#14 0x00000a757c24f6a0 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x1c9f6a0)
#15 0x00000a757b90cc94 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x135cc94)
#16 0x00000a757f09d15c (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile> >&) (.constprop.0) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x4aed15c)
#17 0x00000a757c26e7c4 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x1cbe7c4)
#18 0x00000a757ce593c4 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x28a93c4)
#19 0x00000a757daaf7a4 clang::ParseAST(clang::Sema&, bool, bool) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x34ff7a4)
#20 0x00000a757c891d40 clang::ASTFrontendAction::ExecuteAction() (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x22e1d40)
#21 0x00000a757ce5de04 clang::CodeGenAction::ExecuteAction() (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x28ade04)
#22 0x00000a757c891c14 clang::FrontendAction::Execute() (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x22e1c14)
#23 0x00000a757c836fc0 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x2286fc0)
#24 0x00000a757c93fcb0 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x238fcb0)
#25 0x00000a757af5a95c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x9aa95c)
#26 0x00000a757af5ff14 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x9aff14)
#27 0x00000a757aead6fc main (/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15+0x8fd6fc)
#28 0x000074666d24a0b4 generic_start_main ./csu/../csu/libc-start.c:332:16
#29 0x000074666d24a2a0 __libc_start_main ./csu/../sysdeps/unix/sysv/linux/powerpc/libc-start.c:98:10
./fixdep-b209d4.sh: line 4: 3654250 Segmentation fault      (core dumped) PATH=/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/:$PATH "/mnt/sdb/pbuild/llvm/llvm-lto-latest-cleanbuild/bin/clang-15" "-cc1" "-triple" "powerpc64le-unknown-linux-gnu" "-emit-obj" "--mrelax-relocations" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "fixdep.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "ppc64le" "-mfloat-abi" "hard" "-target-abi" "elfv2" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=/mnt/sdb/pbuild/kernels-llvm/llvm-wip-llvm-latest-lto-full-cleanbuild" "-O2" "-Wall" "-Wmissing-prototypes" "-Wstrict-prototypes" "-Wdeclaration-after-statement" "-std=gnu11" "-fdebug-compilation-dir=/mnt/sdb/pbuild/kernels-llvm/llvm-wip-llvm-latest-lto-full-cleanbuild" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c" "fixdep-b209d4.c"
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWlt3m0gS_jXySx90AIEkHvwgy3LsXSfWsZRk9kmn6W6kHiNgG_Blfv1WNRfRWHE8s1Fm9uI4GKpvVV9duhoqTPnL-VVaJpykCVnefV3cT8lyOR97twvyOSyTonQd2xsO7MuBPauun7O8UILuye3tl49k4E7zHXWIcAPObDaOuHCBGBCmaL4TOXnaiYSwdJ_JWCZbciuT8pk8CJWImMiomkTmJCxlXJAnWezIljF4LAhPYXiSFtVU2LnTCcfVbM3rlWhBBmP7-m61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