This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][NativePDB] Add MSInheritanceAttr when creating pointer type that is a pointer to member.
ClosedPublic

Authored by zequanwu on Jul 14 2022, 3:12 PM.

Diff Detail

Event Timeline

zequanwu created this revision.Jul 14 2022, 3:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2022, 3:12 PM
zequanwu requested review of this revision.Jul 14 2022, 3:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2022, 3:12 PM

Is this fixing a specific situation and if so, can a test be written for it? I'm sure we have existing tests you can adapt.

zequanwu updated this revision to Diff 445081.Jul 15 2022, 11:42 AM
zequanwu added a reviewer: rnk.

add testscase.

Is this fixing a specific situation and if so, can a test be written for it? I'm sure we have existing tests you can adapt.

It fixed the issue. Testcase added.

zequanwu edited the summary of this revision. (Show Details)Jul 15 2022, 11:49 AM
rnk added inline comments.Jul 18 2022, 9:22 AM
lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
492 ↗(On Diff #445081)

I think you want to make code changes here to look at mpi.Representation.

762 ↗(On Diff #445081)

This codepath seems specific to global variable creation. Are there other ways to hit this issue through other codepaths, such as local variables or non-type template parameters?

I would consider moving this logic closer to the logic which creates the AST member pointer type. Any time LLDB loads a member pointer type, it should check the inheritance kind, and then check if the class already has an MSInheritanceAttr, and add one if it is missing.

If the existing attribute doesn't match the attribute you want to add, that represents an ODR violation in the user program. I'm not sure what LLDB should do in that case.

lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
319

We shouldn't try to reimplement the frontend calculation logic, we should just trust the debug info. Users can use the pointers_to_members pragma to force the compiler to use different representations, so this calculation won't always be right.

Also, I don't think this case handles multiple inheritance via indirect bases. Consider:

struct A { int a; };
struct B { int b; };
struct C : A, B { int c; };
struct D : C { int d; };

If we need this logic in LLDB, try calling CXXRecordDecl::calculateInheritanceModel.

zequanwu updated this revision to Diff 445942.Jul 19 2022, 2:11 PM
zequanwu marked 3 inline comments as done.
zequanwu edited the summary of this revision. (Show Details)

Use PointerToMemberRepresentation in pdb to get inheritance attribute.

zequanwu retitled this revision from [LLDB][NativePDB] Add MSInheritanceAttr when completing CXXRecordDecl to [LLDB][NativePDB] Add MSInheritanceAttr when creating pointer type that is a pointer to member..Jul 19 2022, 2:13 PM
zequanwu edited the summary of this revision. (Show Details)
rnk accepted this revision.Jul 19 2022, 3:15 PM

Thanks!

lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
840 ↗(On Diff #445942)

This should be virtual, not multiple, right?

lldb/test/Shell/SymbolFile/NativePDB/ast-types.cpp
111 ↗(On Diff #445942)

It's worth adding tests for data member pointers as well as function member pointers, in particular ones that use -1 as the null representation. Try this:

int SI::*mp9 = nullptr;

Because offset zero is a valid offset, -1 is used to represent null in this case.

This revision is now accepted and ready to land.Jul 19 2022, 3:15 PM