This is an archive of the discontinued LLVM Phabricator instance.

Fixed debug info generation for function static variables, typedef, and records
ClosedPublic

Authored by aaboud on May 13 2015, 12:07 PM.

Details

Summary

A Fix for Bug 19238.
Function static variable defined inside a lexical scope, same as typedef and record (class, struct or union), which are declared inside a lexical scope, were all associated to the function as its parent scope, rather than to the lexical scope they are defined or declared inside.

This patch provides a fix for all these three cases in the Clang debug info generation.

This patch is related to "D9758"

Diff Detail

Repository
rL LLVM

Event Timeline

aaboud updated this revision to Diff 25722.May 13 2015, 12:07 PM
aaboud retitled this revision from to Fixed debug info generation for function static variables, typedef, and records.
aaboud updated this object.
aaboud edited the test plan for this revision. (Show Details)
aaboud added reviewers: echristo, dblaikie, ABataev.
aaboud added a subscriber: Unknown Object (MLST).

The original bug had an example where the inner block has a second static variable, with the same name as the static variable in the outer block. With a different type, to make it more interesting.
It would be nice to have a test like that here.

I did not get feedback on the fix, yet.
Can you please approve or comment if you disagree on this code change?

probinson added inline comments.May 21 2015, 2:40 PM
lib/CodeGen/CGDebugInfo.cpp
782 ↗(On Diff #25722)

This could be refactored into a 'getDeclarationLexicalScope' method, as the companion to 'recordDeclarationLexicalScope'.

2228 ↗(On Diff #25722)

This would become a call to 'getDeclarationLexicalScope'.

I did not get feedback on the fix, yet.

Actually I had a previous comment on testing.

aaboud updated this revision to Diff 26383.May 24 2015, 9:06 AM

Made some changes to follow Paul's review:
Added another test for static variables, based on the example from Bug 19238.
Moved some common code to a new helper function.

aaboud updated this revision to Diff 26675.May 28 2015, 5:59 AM

Applied changes according to David Blaikie commits.
Now, records and typedef entries that are defined inside a lexical block are added to the retained types list.

aaboud updated this revision to Diff 28644.Jun 29 2015, 12:17 AM

Updated the LLVM version to 240902 (close to top of trunk preparing for commit).

dblaikie edited edge metadata.Jun 29 2015, 9:45 AM

Do you need to resolve the Context in the retained types iteration? If it's
a lexical block it shouldn't ever be a scope ref, I think? Not sure.

(mostly I'm just concerned aobut the inconsistency between that case and
the global variable case above)

In DwarfCompileUnit - perhaps:

auto LocalDeclNodeRangeForScope = DD->findLocalDeclNodesForScope(DS);

could be changed to:

iterator_range<LocalDeclMap::const_iterator> LocalDeclNodeRangeForScope;
if (!includeMinimalInlineScopes())
  LocalDeclNodeRangeForScope = DD->findLocalDeclNodesForScope(DS);

Then you can drop the includeMinimalInlineScopes() condition from the
following if and the if around the for loop furtehr down, I think? (with
the caveat that I'm not sure if iterator_range is guaranteed (or can be
guaranteed) to produce an empty range - not sure if two default constructed
iterators are guaranteed/meant to be equal to each other - could check the
spec, etc)

  • David

Hi David,

The reason I resolve the context for the retained type while I do not for the global variable, is because the “getScope” of the DIType returns a DIScopeRef, while the “getScope” of the DIGlobalVariable returns a DIScope.
I have no idea what are the reasons for this difference, but if we decide to unify the return value of the getScope, it is a change for another patch.

I will do the changes you suggested in DwarfCompileUnit and upload a new version.

Regards,
Amjad

From: David Blaikie [mailto:dblaikie@gmail.com]
Sent: Monday, June 29, 2015 19:45
To: reviews+D9760+public+57feba0fe3280700@reviews.llvm.org
Cc: Aboud, Amjad; Eric Christopher; Alexey Bataev; Robinson, Paul; llvm cfe
Subject: Re: [PATCH] Fixed debug info generation for function static variables, typedef, and records

Do you need to resolve the Context in the retained types iteration? If it's a lexical block it shouldn't ever be a scope ref, I think? Not sure.

(mostly I'm just concerned aobut the inconsistency between that case and the global variable case above)

In DwarfCompileUnit - perhaps:

auto LocalDeclNodeRangeForScope = DD->findLocalDeclNodesForScope(DS);

could be changed to:

iterator_range<LocalDeclMap::const_iterator> LocalDeclNodeRangeForScope;
if (!includeMinimalInlineScopes())
  LocalDeclNodeRangeForScope = DD->findLocalDeclNodesForScope(DS);

Then you can drop the includeMinimalInlineScopes() condition from the following if and the if around the for loop furtehr down, I think? (with the caveat that I'm not sure if iterator_range is guaranteed (or can be guaranteed) to produce an empty range - not sure if two default constructed iterators are guaranteed/meant to be equal to each other - could check the spec, etc)

  • David
This revision was automatically updated to reflect the committed changes.