This is an archive of the discontinued LLVM Phabricator instance.

[libclang] Expose AtomicType
ClosedPublic

Authored by slowhog on May 8 2019, 10:12 PM.

Details

Reviewers
aaron.ballman
Summary

Expose atomic type through the C API.

Diff Detail

Event Timeline

slowhog created this revision.May 8 2019, 10:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2019, 10:12 PM
slowhog retitled this revision from Expose AtomicType to [libclang] Expose AtomicType.May 8 2019, 10:17 PM
slowhog edited projects, added Restricted Project; removed Restricted Project.May 23 2019, 11:10 AM
slowhog removed reviewers: yvvan, jbcoe.

Hi,

We use libclang in OpenJDK project Panama for a tool, jextract, to read C header files and generate Java bindings. It's critical for us to be able get the "real" underlying type.

Currently type like _Atomic(int) are not exposed, and libclang will give us a type kind of CXType_Unexposed, and we need a way to get the value type of CXType_Int .

Is there an existing way to do that? I have tried to call clang_getCanonicalType on the unexposed type, but that return the same unexposed type.

Please let me know if the proposed patch is on the right track or not, I would appreciate guidance to get this issue solved.

Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2019, 11:10 AM
slowhog updated this revision to Diff 241747.Jan 31 2020, 9:05 AM
slowhog added a reviewer: aaron.ballman.

Updated to latest

Would like to try to draw attention to this patch again, since it seems to have gone under the radar. Can someone review this/help get it integrated? We are still having to work around _Atomic types because we can't get to the underlying value type. Thanks

I'm sorry about the delay in review, this did fall off my radar. Thank you for bringing it to my attention!

Looks mostly good to me, just a few small nits.

clang/include/clang-c/Index.h
3953

Missing a full stop at the end of the comment.

clang/tools/c-index-test/c-index-test.c
1585

Should elide braces here.

clang/tools/libclang/CXType.cpp
1326–1329

I would probably rewrite this function to:

QualType T = GetQualType(CT);
if (T.isNull() || !T->isAtomicType())
  return MakeCXType(QualType(), GetTU(CT));
const auto *AT = T->castAs<AtomicType>();
return MakeCXType(AT->getValueType(), GetTU(CT));
slowhog updated this revision to Diff 257754.Apr 15 2020, 9:39 AM
slowhog marked 3 inline comments as done.

Thanks for reviewing, I applied the recommended changes.

aaron.ballman accepted this revision.Apr 15 2020, 12:07 PM

LGTM! Do you need me to commit on your behalf?

This revision is now accepted and ready to land.Apr 15 2020, 12:07 PM

Yes, please help to commit the patch. Thank you for looking after this.

aaron.ballman closed this revision.Apr 16 2020, 5:08 AM

I've commit on your behalf in 38ca7b11db2d22e0fdfbff3f19276f9796f747d3, thank you for the patch!