[PATCH] D42254: Add optional DICompileUnit to DIBuilder and make outlined debug info use that CU

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 17:12:14 PST 2018


Agreed - if we're going to provide any debug info for this (line table,
etc) it's necessarily going to be confusing (in the case where we've
outlined from more than one place) but I think it's the right-est thing to
do, that I can think of right now, given the constraints, and we should
just follow through with it as far as possible in that direction (so, a
function with the same filename, same line entries, etc, from that one
instance we picked)

In theory, inline functions have the same issue, sort of - in one
translation unit you call inline function f1 which you may've written in
foo.cpp, and then in another translation unit you have another inline
definition of f1 in bar.cpp - so long as both definitions have the same
sequence/interpretation of tokens, you haven't violated the ODR, but in
theory the user might be confused by the fact that their code in foo.cpp
that clearly called f1 in foo.cpp actually jumps over to f1 in bar.cpp.
(yeah, admittedly that's not nearly as confusing as outlining - but that's
the nearest analogy I have & best idea I have for modelling this: as though
the user did the outlining and the linker picked a definition (except we
can be smart and intentionally pick a definition that has debug info, if
there is one))

On Thu, Jan 18, 2018 at 3:44 PM Paul Robinson via Phabricator <
reviews at reviews.llvm.org> wrote:

> probinson added inline comments.
>
>
> ================
> Comment at: lib/CodeGen/MachineOutliner.cpp:1283
> +    std::unique_ptr<DIBuilder> DB = llvm::make_unique<DIBuilder>(M, true,
> CU);
> +    DIFile *Unit = DB->createFile(CU->getName(), CU->getDirectory());
> +
> ----------------
> aprantl wrote:
> > paquette wrote:
> > > aprantl wrote:
> > > > aprantl wrote:
> > > > > Can you also grab the file from the DISubprogram that you got the
> CU from?
> > > > Looks like this one was accidentally marked as done?
> > > It's CU->getFile() on here now but in the e-mail thread, it appears to
> still be
> > >
> > > DIFile *Unit = DB->createFile(CU->getName(), CU->getDirectory())
> > >
> > > Maybe that got mixed up somehow? Or is that still incorrect? Is it
> possible for a DISubprogram to have a different DIFile than its CU?
> > > Is it possible for a DISubprogram to have a different DIFile than its
> CU?
> > Yes. For example, two functions defined in different header files have
> different files even if they belong to the same CU.
> >
> > My original suggestion was to use SP->getFile() here where SP is the
> DISubprogram attached to the function we got the CU from.
> >
> > That said, if we are outlining code from two function from two different
> files, this file will be wrong and I'm not sure how to handle this. Should
> we create a new "virtual" file "<outlined-code>"? What do others think?
> I think taking the DIFile from the same DISubprogram where we got the CU
> is fine.  It's more consistent than anything else we could do.
>
>
> https://reviews.llvm.org/D42254
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180119/351701cf/attachment.html>


More information about the llvm-commits mailing list