llvm / llvm-project

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

Wrong line information at Og #45316

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

31fbadee-9e60-4c99-b908-8380e6a40c85 commented 4 years ago
Bugzilla Link 45971
Version trunk
OS Linux
Blocks llvm/llvm-project#38116
CC @dwblaikie,@JDevlieghere,@jmorse,@jdm,@walkerkd,@pogo59,@zygoloid

Extended Description

Line 8 should not be hit during debugging.

$ cat a.c char a, b; int g_37[] = {1}; int c; char(d)() { return a; } void e() { if (g_37[0]) return; --b &&d() || c; } int main() { e(); }

$ clang -v clang version 11.0.0 (https://github.com/llvm/llvm-project.git 709c52b9553f4ba83ab901a873392f8a7f2c56a5) 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 709c52b9553f4ba83ab901a873392f8a7f2c56a5 llvm revision 709c52b9553f4ba83ab901a873392f8a7f2c56a5

$ gdb -v GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git

$ 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 + 1 at a.c:10:14, address = 0x00000000004004b1 (lldb) r Process 231 launched: '/home/stepping/output/opt' (x86_64) Process 231 stopped

$ gdb opt (gdb) b main Breakpoint 1 at 0x4004b1: file a.c, line 10. (gdb) r Starting program: opt

Breakpoint 1, main () at a.c:10 10 int main() { e(); } (gdb) s e () at a.c:6 6 if (g_37[0]) (gdb) s e () at a.c:8 8 --b &&d() || c; (gdb) s 0x00007ffff7a05b97 in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6 (gdb)

llvmbot commented 4 years ago

Interesting, this calls BranchFolder, so it might be the same fix for llvm/llvm-bugzilla-archive#46009

// No tail merging opportunities if the block number is less than four. if (MF.size() > 3 && EnableTailMerge) { unsigned TailMergeSize = TailDupSize + 1; BranchFolder BF(/EnableTailMerge=/true, /CommonHoist=/false, MBFI, MBPI, PSI, TailMergeSize);

auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
if (BF.OptimizeFunction(MF, TII, MF.getSubtarget().getRegisterInfo(),
                        MMIWP ? &MMIWP->getMMI() : nullptr, MLI,
                        /*AfterPlacement=*/true)) {
  // Redo the layout if tail merging creates/removes/moves blocks.
  BlockToChain.clear();
  ComputedEdges.clear();
  // Must redo the post-dominator tree if blocks were changed.
  if (MPDT)
    MPDT->runOnMachineFunction(MF);
  ChainAllocator.DestroyAll();
  buildCFGChains();
}

}

llvmbot commented 4 years ago

So, I might be wrong, but my bisection points to:

BISECT: running pass (190) Stack Slot Coloring on function (e) BISECT: running pass (191) Machine Copy Propagation Pass on function (e) BISECT: running pass (192) Machine Loop Invariant Code Motion on function (e) BISECT: running pass (193) Fixup Statepoint Caller Saved on function (e) BISECT: running pass (194) PostRA Machine Sink on function (e) BISECT: running pass (195) Shrink Wrapping analysis on function (e) BISECT: running pass (196) Control Flow Optimizer on function (e) BISECT: running pass (197) Tail Duplication on function (e) BISECT: running pass (198) Machine Copy Propagation Pass on function (e) BISECT: running pass (199) Post RA top-down list latency scheduler on function (e) BISECT: running pass (200) Branch Probability Basic Block Placement on function (e)

^----

llvmbot commented 4 years ago

Process 3928 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 3928 stopped

jmorse commented 4 years ago

Neat; looks like it's this [0] folding of return blocks together. SimplifyCFG replaces identical return blocks with one of them; it should also be merging the DebugLocs too.

[0] https://github.com/llvm/llvm-project/blob/56079e1de1129837aa7569d8b3bb5e50afc0f1ea/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp#L131