[clang] [Clang] Consider preferred_type in bitfield warnings (#116760) (PR #116785)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 26 05:17:18 PST 2024


================
@@ -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) {
----------------
tbaederr wrote:

```suggestion
    else {
```
I guess? :thinking: 

https://github.com/llvm/llvm-project/pull/116785


More information about the cfe-commits mailing list