This is an archive of the discontinued LLVM Phabricator instance.

[LLVM-C] Add Accessors For Global Variable Metadata Properties
ClosedPublic

Authored by CodaFi on Apr 15 2019, 10:36 AM.

Details

Summary

Metadata for a global variable is really a (GlobalVariable, Expression) tuple. Allow access to these, then allow retrieving the file, scope, and line for a DIVariable, whether global or local. This should be the last of the accessors required for uniform access to location and file information metadata.

Diff Detail

Event Timeline

CodaFi created this revision.Apr 15 2019, 10:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2019, 10:36 AM

@jberdine This patch handles the global variable side of things. You should be able to replace those accessors in Core with a call to LLVMGlobalCopyAllMetadata. You can filter for !dbg and dig out the global variable expression. From there, you locate from global variable expression to global variable with LLVMDIGlobalVariableExpressionGetVariable and from global variable to line with LLVMDIVariableGetLine.

In general, it isn't safe to assume that the first metadata attachment you find on a global variable is !dbg, so the existing bindings in Core will fail to retrieve information in some odd cases.

jberdine accepted this revision.Apr 16 2019, 1:31 PM

Thanks! These are working for me, though I needed to expose one more function, see D60795 (and feel free to incorporate it into this one).

One build-breaking typo noted inline.

llvm/lib/IR/DebugInfo.cpp
1257

s/getExpresssion/getExpression/

This revision is now accepted and ready to land.Apr 16 2019, 1:31 PM
CodaFi added inline comments.Apr 16 2019, 1:36 PM
llvm/lib/IR/DebugInfo.cpp
1257

Ugh, this New MacBook keyboard of mine... Thanks.

CodaFi updated this revision to Diff 195453.Apr 16 2019, 1:42 PM
CodaFi marked 2 inline comments as done.
CodaFi updated this revision to Diff 195463.Apr 16 2019, 2:30 PM

@whitequark Could I get your stamp of approval as well?

This revision was automatically updated to reflect the committed changes.