[PATCH] D130303: Handle template parameter-dependent bit field widths in libclang

Igor Kushnir via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 6 03:02:38 PST 2023


vedgy added subscribers: aaron.ballman, vedgy.
vedgy added a comment.

I just verified that this patch fixes a KDevelop crash <https://bugs.kde.org/show_bug.cgi?id=438249> reported by several users. Thank you!

@aaron.ballman, could you please review this fix?



================
Comment at: clang/include/clang-c/Index.h:3554
+ */
+CINDEX_LINKAGE unsigned clang_isFieldDeclBitWidthDependent(CXCursor C);
+
----------------
New API has to be mentioned in the //libclang// section of //clang/docs/ReleaseNotes.rst// and in the //LLVM_17// block of //clang/tools/libclang/libclang.map//.


================
Comment at: clang/tools/libclang/CXType.cpp:404
+      if (FD->isBitField() && !FD->getBitWidth()->isValueDependent())
         return FD->getBitWidthValue(getCursorContext(C));
     }
----------------
I thought of the same fix while analyzing the assertion failure here: https://bugs.kde.org/show_bug.cgi?id=438249#c19

An alternative implementation is to place this same check in `clang::FieldDecl::getBitWidthValue()`. This looks like a general issue that could affect non-libclang users of `clang::FieldDecl::getBitWidthValue()`. But apparently no one else has stumbled upon it.

`clang::FieldDecl::getBitWidthValue()` returns `unsigned` and has no error-reporting mechanism yet. It could return `std::numeric_limits<unsigned>::max()` (or `0` if that's an invalid bit width value) in case of the value dependence.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130303/new/

https://reviews.llvm.org/D130303



More information about the cfe-commits mailing list