Author: Dan Liew
Date: 2026-07-15T11:48:37+01:00
New Revision: edbf9e3096c027b61d72df6397c2963be56b2b7b

URL: 
https://github.com/llvm/llvm-project/commit/edbf9e3096c027b61d72df6397c2963be56b2b7b
DIFF: 
https://github.com/llvm/llvm-project/commit/edbf9e3096c027b61d72df6397c2963be56b2b7b.diff

LOG: [NFC][BoundsSafety] Re-order some checks in 
`Sema::CheckCountedByAttrOnField` (#209713)

This is post-merge feedback for #209603
(4b455a91141d59ace3a29870c885f5f5e4ff0506).

Added: 
    

Modified: 
    clang/lib/Sema/SemaBoundsSafety.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaBoundsSafety.cpp 
b/clang/lib/Sema/SemaBoundsSafety.cpp
index 6cfa505d3dc77..066dab2f0bef2 100644
--- a/clang/lib/Sema/SemaBoundsSafety.cpp
+++ b/clang/lib/Sema/SemaBoundsSafety.cpp
@@ -103,7 +103,7 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   // only `PointeeTy->isStructureTypeWithFlexibleArrayMember()` is reachable
   // when `FieldTy->isArrayType()`.
   bool ShouldWarn = false;
-  if (PointeeTy->isAlwaysIncompleteType() && !CountInBytes) {
+  if (!CountInBytes && PointeeTy->isAlwaysIncompleteType()) {
     // In general using `counted_by` or `counted_by_or_null` on
     // pointers where the pointee is an incomplete type are problematic. This 
is
     // because it isn't possible to compute the pointer's bounds without 
knowing
@@ -152,8 +152,8 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
     InvalidTypeKind = CountedByInvalidPointeeTypeKind::SIZELESS;
   } else if (PointeeTy->isFunctionType()) {
     InvalidTypeKind = CountedByInvalidPointeeTypeKind::FUNCTION;
-  } else if (PointeeTy->isStructureTypeWithFlexibleArrayMember() &&
-             !CountInBytes) {
+  } else if (!CountInBytes &&
+             PointeeTy->isStructureTypeWithFlexibleArrayMember()) {
     if (FieldTy->isArrayType() && !getLangOpts().BoundsSafety) {
       // This is a workaround for the Linux kernel that has already adopted
       // `counted_by` on a FAM where the pointee is a struct with a FAM. This


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to