This is an archive of the discontinued LLVM Phabricator instance.

clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled
ClosedPublic

Authored by michaelwu on Sep 30 2015, 4:39 PM.

Details

Reviewers
rsmith
Summary

Right now clang_Cursor_getMangling will attempt to mangle any declaration, even if the declaration isn't mangled (extern "C"). This results in a partially mangled name which isn't useful for much. This patch makes clang_Cursor_getMangling return an empty string if the declaration isn't mangled.

Diff Detail

Event Timeline

michaelwu updated this revision to Diff 36161.Sep 30 2015, 4:39 PM
michaelwu retitled this revision from to clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled.
michaelwu updated this object.
michaelwu added a subscriber: cfe-commits.
rsmith added a subscriber: rsmith.Sep 30 2015, 5:41 PM
rsmith added inline comments.
tools/libclang/CIndex.cpp
3892

You should use shouldMangleDeclName here instead; this will do the wrong thing if there's an asm label on the declaration (where presumably we do want to list a "mangling").

3893

In this case, we should presumably use the decl's identifier as the "mangled name" rather than just giving up; there could still be backend mangling that applies here, and we should be producing the final symbol name here. In fact, MangleContext::mangleName should probably be changed to produce the identifier name in this case, rather than handling it here.

michaelwu updated this revision to Diff 36330.Oct 1 2015, 8:47 PM

Thanks for the review. I switched to shouldMangleDeclName instead of shouldMangleCXXName, and made it skip the frontend mangling instead of returning an empty string. I tried making mangleName do that instead, but it seemed to cause a bunch of test failures..

The nice thing about returning a valid symbol name instead of an empty string is that I discovered my new test was incomplete. This diff also adds a change to properly handle declarations inside an extern "C".

michaelwu marked 2 inline comments as done.Oct 5 2015, 7:19 AM
michaelwu updated this revision to Diff 36518.Oct 5 2015, 7:29 AM

This uses clang_isInvalid in PrintMangledName instead of checking for CXCursor_UnexposedDecl.

rsmith accepted this revision.Oct 5 2015, 5:58 PM
rsmith added a reviewer: rsmith.
This revision is now accepted and ready to land.Oct 5 2015, 5:58 PM
ehsan closed this revision.Oct 6 2015, 11:26 AM

Landed in r249437.

michaelwu updated this revision to Diff 36645.Oct 6 2015, 12:31 PM
michaelwu edited edge metadata.

Turns out clang_isUnexposed is what I wanted, rather than clang_isInvalid. I remember seeing clang_isInvalid work though..