[PATCH] D47097: [DebugInfo] Preserve scope in auto generated StoreInst

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 24 11:00:51 PDT 2018

vsk added a comment.

In https://reviews.llvm.org/D47097#1111248, @aprantl wrote:

> In https://reviews.llvm.org/D47097#1111223, @gramanas wrote:
> > In https://reviews.llvm.org/D47097#1111149, @probinson wrote:
> >
> > > Can we step back a second and better explain what the problem is? With current Clang the debug info for this function looks okay to me.
> > >  The store that is "missing" a debug location is homing the formal parameter to its local stack location; this is part of prolog setup, not "real" code.
> >

The problem @gramanas is trying to address appears after SROA. SROA invokes mem2reg, which tries to assign scope information to the phis it creates (see https://reviews.llvm.org/D45397). Subsequent passes which touch these phis can use these debug locations. This makes it easier for the debugger to find the right scope when handling a machine exception.

Store instructions in the prolog without scope information cause mem2reg to create phis without scope info. E.g:

  // foo.c
  extern int map[];
  void f(int a, int n) {
    for (int i = 0; i < n; ++i)
      a = map[a];
  $ clang foo.c -S -emit-llvm -o - -g -O1 -mllvm -opt-bisect-limit=2
      %a.addr.0 = phi i32 [ %a, %entry ], [ %0, %for.body ]

(Side note: @gramanas, it would help to have the full context/motivation for changes in the patch summary.)

>> Isn't this the reason the artificial debug loc exists? The store in the prolog might not be real code but it should still have the scope that the rest of the function has.
> Instructions that are part of the function prologue are supposed to have no debug location, not an artificial one. The funciton prologue ends at the first instruction with a nonempty location.

I've been reading through PEI but I'm having a hard time verifying this. How does llvm determine where the function prologue ends when there isn't any debug info? What would go wrong if llvm started to behave as if the prologue ended sooner than it should? Also, why isn't this a problem for the swift compiler, which appears to always assign debug locations to each instruction?

  rC Clang


More information about the cfe-commits mailing list