[llvm] [mlir] Fix LLVM_ENABLE_ABI_BREAKING_CHECKS macro check: use #if instead of #ifdef (PR #110185)

Dimitry Andric via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 23 15:47:47 PDT 2024


DimitryAndric wrote:

After 1905cdbf4ef15565504036c52725cb0622ee64ef, I'm running into segfaults when assertions are disabled (`NDEBUG` is defined) and `LLVM_ENABLE_ABI_BREAKING_CHECKS=1`. The problem is that `llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp` has in `SelectionDAGISel::initializeAnalysisResults`:

```c++
#if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS
  TTI = &FAM.getResult<TargetIRAnalysis>(Fn);
#endif
```

but all the calls to `VerifyDAGDivergence` in `SelectionDAGISel::CodeGenAndEmitDAG` are first checked by accessing `TTI`:

```c++
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
  if (TTI->hasBranchDivergence())
    CurDAG->VerifyDAGDivergence();
#endif
```

Since `TTI` is initialized with `nullptr` in the `SelectionDAGISel` class declaration, this access segfaults.


https://github.com/llvm/llvm-project/pull/110185


More information about the llvm-commits mailing list