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?


Repository:
  rC Clang

https://reviews.llvm.org/D47097



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to