[clang] [Clang] Consider preferred_type in bitfield warnings (#116760) (PR #116785)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 25 09:12:26 PDT 2025
================
@@ -10488,7 +10488,14 @@ static bool AnalyzeBitFieldAssignment(Sema &S, FieldDecl *Bitfield, Expr *Init,
// The RHS is not constant. If the RHS has an enum type, make sure the
// bitfield is wide enough to hold all the values of the enum without
// truncation.
- if (const auto *EnumTy = OriginalInit->getType()->getAs<EnumType>()) {
+ const auto *EnumTy = OriginalInit->getType()->getAs<EnumType>();
+ const PreferredTypeAttr *PTAttr = nullptr;
+ if (!EnumTy) {
+ PTAttr = Bitfield->getAttr<PreferredTypeAttr>();
+ if (PTAttr)
+ EnumTy = PTAttr->getType()->getAs<EnumType>();
+ }
+ if (EnumTy) {
----------------
ojhunt wrote:
Nope, as we're conditionally setting EnumTy in the if(!EnumTy) branch (i.e. EnumTy may not be null afterwards)
https://github.com/llvm/llvm-project/pull/116785
More information about the cfe-commits
mailing list