llvm / llvm-project

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

inconsistent behaviors at -O2 #45394

Open llvmbot opened 4 years ago

llvmbot commented 4 years ago
Bugzilla Link 46049
Version unspecified
OS Linux
Attachments the binary
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@JDevlieghere

Extended Description

$ clang --version clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project 871beba234a83a2a02da9dedbd59b91a1bfbd7af) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin

$ lldb --version lldb version 11.0.0 clang revision 871beba234a83a2a02da9dedbd59b91a1bfbd7af llvm revision 871beba234a83a2a02da9dedbd59b91a1bfbd7af

$ clang -g -O2 small.c

$ lldb a.out (lldb) target create "a.out" Current executable set to '/home/yibiao/Debugger/a.out' (x86_64). (lldb) b 6 Breakpoint 1: where = a.out`main + 29 at small.c:6:7, address = 0x000000000040112d (lldb) r Process 578366 launched: '/home/yibiao/Debugger/a.out' (x86_64) Process 578366 exited with status = 0 (0x00000000) (lldb)

/**** As showed above, Line 6 is not hit by lldb when setting breakpoint. However, it was hit by lldb when using step-i *****/

$ lldb a.out (lldb) target create "a.out" Current executable set to '/home/yibiao/Debugger/a.out' (x86_64). (lldb) b main Breakpoint 1: where = a.out`main at small.c:4:7, address = 0x0000000000401110 (lldb) r Process 578410 launched: '/home/yibiao/Debugger/a.out' (x86_64) Process 578410 stopped

$ cat small.c int a, b, d=1;

int main() { if (d) a = b==0; if (a!=1) return 1; return 0; }

dwblaikie commented 4 years ago

another case of jumping into the middle of a line:

.LBB0_1: .loc 1 6 7 is_stmt 1 # ./example.c:6:7 mov ecx, dword ptr [rip + .La$local] .LBB0_3: .loc 1 6 8 is_stmt 0 # ./example.c:6:8 xor eax, eax cmp ecx, 1 setne al .loc 1 9 1 is_stmt 1 # ./example.c:9:1 ret

The first reference to line 6 is the load from 'a', but that's conditional - if the code came from the 'if (d)' block, then 'a's value is known without the need to load it, so the code skips over the load (missing the "start" of line 6 in the process).