In order to have call_origin to an external function we need DISubprogram for the function.
Authors: @asowda, @NikolaPrica, @djtodoro, @ivanbaev
Differential D60713
[IR] Add DISuprogram and DIE for func decl of an external djtodoro on Apr 15 2019, 8:35 AM. Authored by
Details In order to have call_origin to an external function we need DISubprogram for the function. Authors: @asowda, @NikolaPrica, @djtodoro, @ivanbaev
Diff Detail
Event TimelineComment Actions Can you explain or (link to a review that explains) why this flag is necessary? What are we avoiding/gaining by having it? Comment Actions @aprantl Thanks again for your comments! The patch is needed to describe a call site to an external function. Currently, we do not have all necessary info for the debug call site (particular debug subprogram is missing for the external function). Since we can describe call site parameters for calls like that, we are producing additional subprogram for the declaration of the extern function by marking it with the DISPFlagDeclForCallSite flag. Please find the frontend part: D60714 Comment Actions
I'm sorry if the answer to that question is already in your reply and I just failed to parse it: Why do we need the DISPFlagDeclForCallSite *flag* to differentiate the a DISubprogram. Isn't the fact that it is attached to a forward-declaration enough? Secondly: since this is attached to a forward *declaration*, would it make sense to attach the unique (= not distinct) DISubprogram from the type hierarchy instead of creating another distinct node? What is the intended behavior when two LLVM modules containing the same forward declaration are llvm-linked during LTO? Comment Actions
We could avoid the flag, but since existing LLVM infrastructure does not allow debug info for function declarations itself, we wanted to emphasize that we are creating it only for the purpose of call site’s debug info. The verifier to distinguish that the declaration will be used in that purpose uses the flag.
Oh, the test case from this patch was artificial one. We are actually creating it that way. There is no distinct subprograms for the declarations. Please see the test case updated.
LLVM linked file will have just one debug info subprogram instance for the declaration. Comment Actions Prior to this patch Function declarations may not have a !dbg attachment, because there was no use-case for it. With call site debug info, I think it would make sense to revisit this rule. When I made my previous comment, I thought that the updated rule could be: (1) function definitions may have a distinct DISubprogram attached (as before) If I read the code in Verifier.cpp correctly, then it is legal for a unique DISubprogram to not have a unit, which would cause the declaration-DISubprograms to be uniqued during LTO. so the (2) should probably be: (2) function declarations may have a unique DISubprogram attached and it may not have a unit: field I've CC'ed Duncan in case he can catch a logic error with this reasoning. Comment Actions That rule seems reasonable. The critical piece is that declarations will show up in ~every TU, and to be uniqued properly they can't point at anything identifying which TU they're coming from. Comment Actions -Remove the SP flag Comment Actions @aprantl , @dexonsmith Thanks for your comments! Now, we avoid the sp flag and a unique sp is attached on to a declaration needed for call site debug info. For the test1.c: ` ... extern int fn1 (int a); int fn2(int arg) { ... arg = fn1(s); printf("\n"); ...` LLVM IR will look like: ... For the test2.c: ` ... extern int fn1 (int a); int fn3(int arg3) { ... arg3 = fn1(k); printf("\n"); ...` LLVM IR will look like: ... By linking the llvm files together we will have: ... Comment Actions
In addition, this will address only this.
Comment Actions Oh.. and could you please document this either in LangRef.rst or SourceLevelDebugging.rst? Comment Actions
Sure. Please find it in the latest patch. |