This is an archive of the discontinued LLVM Phabricator instance.

[libclang] No longer attempt to get a dependent bit-width
ClosedPublic

Authored by aaron.ballman on Mar 14 2023, 6:09 AM.

Details

Summary

Handle template parameter-dependent bit field widths in libclang

In a class template, a bit field's width may depend on a template parameter. In this case the width expression cannot be evaluated.

Previously clang_getFieldDeclBitWidth() would assert, or cause memory unsafety and return an invalid result if assertions are disabled.

This adds a check for this case which returns an error code.

This work was largely taken from an earlier patch which was reverted due to an accidental API duplication (https://reviews.llvm.org/D130303).

Fixes: https://github.com/llvm/llvm-project/issues/56644

Diff Detail

Event Timeline

aaron.ballman created this revision.Mar 14 2023, 6:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2023, 6:09 AM
Herald added a subscriber: arphaman. · View Herald Transcript
aaron.ballman requested review of this revision.Mar 14 2023, 6:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2023, 6:09 AM
vedgy added inline comments.Mar 14 2023, 6:27 AM
clang/include/clang-c/Index.h
3043

Surround the example with \code and \endcode commands.

3046

"non-dependent" is unclear to me. How about rewording to:

*   int Width = clang_getFieldDeclBitWidth(Cursor);
*   if (Width == -1) {
*     // The bit-field width depends on a template parameter.

or alternatively more specific standardese:

*     // The bit-field width is [not] value-dependent.
aaron.ballman marked 2 inline comments as done.

Added \code and \endcode markers, reworded a comment slightly.

vedgy accepted this revision.Mar 14 2023, 6:56 AM

LGTM!

This revision is now accepted and ready to land.Mar 14 2023, 6:56 AM
This revision was landed with ongoing or failed builds.Mar 14 2023, 6:59 AM
This revision was automatically updated to reflect the committed changes.

LGTM!

Thank you for the quick reviews! I've landed in 48fb6659610a3177e8606681046dfa0d19f67203