Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Wrong line information at Og #44941

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR45971
Status CONFIRMED
Importance P enhancement
Reported by Luca Massarelli (massarelli@diag.uniroma1.it)
Reported on 2020-05-18 03:18:11 -0700
Last modified on 2020-06-17 14:54:38 -0700
Version trunk
Hardware PC Linux
CC dblaikie@gmail.com, ditaliano@apple.com, htmldeveloper@gmail.com, jdevlieghere@apple.com, jeremy.morse.llvm@gmail.com, josh@joshmatthews.net, keith.walker@arm.com, llvm-bugs@lists.llvm.org, neeilans@live.com, paul_robinson@playstation.sony.com, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks PR38768
Blocked by
See also
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
* thread #1, name = 'opt', stop reason = breakpoint 1.1
    frame #0: 0x00000000004004b1 opt`main at a.c:10:14
   7        return;
   8      --b &&d() || c;
   9    }
-> 10   int main() { e(); }
(lldb) s
Process 231 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x0000000000400490 opt`e at a.c:6:7
   3    int c;
   4    char(d)() { return a; }
   5    void e() {
-> 6      if (g_37[0])
   7        return;
   8      --b &&d() || c;
   9    }
(lldb) s
Process 231 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x0000000000400499 opt`e at a.c:8:13
   5    void e() {
   6      if (g_37[0])
   7        return;
-> 8      --b &&d() || c;
   9    }
   10   int main() { e(); }
(lldb) di
opt`e:
    0x400490 <+0>:  cmpl   $0x0, 0x200b91(%rip)      ; __dso_handle + 7
    0x400497 <+7>:  je     0x40049a                  ; <+10> at a.c:8:3
->  0x400499 <+9>:  retq
    0x40049a <+10>: addb   $-0x1, 0x200b90(%rip)     ; opt.PT_LOAD[1]..bss + 4
    0x4004a1 <+17>: retq

$  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)
Quuxplusone 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

Quuxplusone 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
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000f8d a.out`e at a.c:8:13 [opt]
   5    void e() {
   6      if (g_37[0])
   7        return;
-> 8      --b &&d() || c;
   9    }
   10   int main() { e(); }
(lldb) frame var g_37
(int [1]) g_37 = ([0] = 1)
Quuxplusone 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)

^----
Quuxplusone commented 4 years ago
Interesting, this calls BranchFolder, so it might be the same fix for
https://bugs.llvm.org/show_bug.cgi?id=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();
    }
  }