llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.01k stars 11.95k forks source link

Wrong Line Information at Og #45419

Open 31fbadee-9e60-4c99-b908-8380e6a40c85 opened 4 years ago

31fbadee-9e60-4c99-b908-8380e6a40c85 commented 4 years ago
Bugzilla Link 46074
Version trunk
OS Linux
CC @adrian-prantl,@JDevlieghere,@walkerkd,@pogo59,@vedantk

Extended Description

Line 8 should not be hit.

$ cat a.c typedef int int32_t; int a, b, c; static int32_t d; static char e; char(f)(char g) { return g >> a; } int main() { for (; d < 9; ++d) { int32_t l_273[2][4][1]; c = 0; for (; c < 4; c++) l_273[0][c][0] = 0; b = f(e--); l_273[0][3][0] |= b; } }

$ clang -v clang version 11.0.0 (https://github.com/llvm/llvm-project.git 268fa40daa151d3b4bff1df12b62e5dae94685d7) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/local/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0 Candidate multilib: .;@m64 Selected multilib: .;@m64

$ lldb -v lldb version 11.0.0 clang revision 268fa40daa151d3b4bff1df12b62e5dae94685d7 llvm revision 268fa40daa151d3b4bff1df12b62e5dae94685d7

$ clang -Og -g -o opt a.c

$ lldb opt (lldb) target create "opt" Current executable set to 'opt' (x86_64). (lldb) b main Breakpoint 1: where = opt`main + 7 at a.c:7:3, address = 0x0000000000400497 (lldb) r Process 65 launched: 'opt' (x86_64) Process 65 stopped

llvmbot commented 4 years ago

@@ -32,35 +32,39 @@ 4: ; preds = %0 %5 = getelementptr inbounds [2 x [4 x [1 x i32]]], [2 x [4 x [1 x i32]]] %1, i64 0, i64 0, i64 3, i64 0, !dbg !​52 %6 = load i8, i8 @​e, align 1, !tbaa !​53

^ presumably when we create the zext that inherits the location of the branch & that causes the funny stepping.

llvmbot commented 4 years ago

It's LSR.

BISECT: running pass (107) Partially inline calls to library functions on function (f) BISECT: running pass (108) X86 Partial Reduction on function (f) BISECT: running pass (109) CodeGen Prepare on function (f) BISECT: running pass (110) Canonicalize Freeze Instructions in Loops on loop BISECT: running pass (111) Loop Strength Reduction on loop

llvmbot commented 4 years ago

Confirmed:

Process 24778 launched: '/Users/davide/work/build/bin/a.out' (x86_64) a.out was compiled with optimization - stepping may behave oddly; variables may not be available. Process 24778 stopped

I guess this is not a big deal but it's technically incorrect. We should stop on line 9 instead of the decl when we enter the loop. +Vedant/Adrian.