Skip to content

[clang] Debugging Error: Non-null pointer (Instruction *)I shows as null #77921

Open
@sunshaoce

Description

@sunshaoce

When debugging with gdb/lldb for build/bin/clang, encountered a situation where (Instrcution *)I appears to be null, but in reality, it is not.

This is the clang I installed (commit 35c19fd). The results are the same whether using Release/17.x or -DCMAKE_BUILD_TYPE=Debug. Subsequently, I refer to it as $HOME/usr/clang.

cmake -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_TARGETS_TO_BUILD="X86" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$HOME/usr" -GNinja ../llvm
ninja install

Then I used the aforementioned $HOME/usr/clang to compile build/bin/clang, using the parameters based on the same commit (35c19fd). This issue does not occur when using gcc 11.4.0.

cmake -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_TARGETS_TO_BUILD="X86;RISCV" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=$HOME/usr/bin/clang -DCMAKE_CXX_COMPILER=$HOME/usr/bin/clang++ -GNinja ../llvm
ninja clang

Then, run gdb to debug build/bin/clang for compiling foo.c (lldb has the same issue):

foo.c:

void foo(int *restrict A, int *restrict B, int *restrict C) {
  for (int i = 0; i < 64; ++i)
    A[i] = B[C[i]];
}
gdb --args build/bin/clang foo.c --target=riscv64 -march=rv64gc -O3 -mllvm -debug-only=instcombine -S
b llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:4416

After 2 (gdb) c ...

IC: Visiting:   %idxprom1 = sext i32 %0 to i64
IC: Visiting:   %arrayidx2 = getelementptr inbounds i32, ptr %B, i64 %idxprom1
IC: Visiting:   %1 = load i32, ptr %arrayidx2, align 4, !tbaa !4
IC: Visiting:   %arrayidx4 = getelementptr inbounds i32, ptr %A, i64 %idxprom
IC: Visiting:   store i32 %1, ptr %arrayidx4, align 4, !tbaa !4
IC: Visiting:   %inc = add nsw i32 %i.0, 1

Breakpoint 1, llvm::InstCombinerImpl::run (this=0x7fffffff6e10) at llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:4416
4416          if (Result != I) {
(gdb) p I
$1 = (llvm::Instruction *) 0x0
(gdb) n
4449            LLVM_DEBUG(dbgs() << "IC: Mod = " << OrigI << '\n'
(gdb) p I
$2 = (llvm::Instruction *) 0x0
(gdb) p Result
$3 = (llvm::Instruction *) 0x5555649ffa00
(gdb) p Result!=I
$4 = true
(gdb) 

Here, I is not actually a null pointer; otherwise, the code within the else branch (line 4449) would not be executed.

Related Codes:

Metadata

Metadata

Assignees

No one assigned

    Labels

    clangClang issues not falling into any other categorywrong-debug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions