[clang] [NFC][BoundsSafety] Re-order some checks in `Sema::CheckCountedByAttrOnField` (PR #209713)
Dan Liew via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 15 03:00:07 PDT 2026
https://github.com/delcypher created https://github.com/llvm/llvm-project/pull/209713
This is post-merge feedback for #209603
(4b455a91141d59ace3a29870c885f5f5e4ff0506).
>From fd4c3bc30d58be885607ed20f223b123d7dd0d5a Mon Sep 17 00:00:00 2001
From: Dan Liew <dliew at apple.com>
Date: Wed, 15 Jul 2026 10:56:10 +0100
Subject: [PATCH] [NFC][BoundsSafety] Re-order some checks in
`Sema::CheckCountedByAttrOnField`
This is post-merge feedback for #209603
(4b455a91141d59ace3a29870c885f5f5e4ff0506).
---
clang/lib/Sema/SemaBoundsSafety.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
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
More information about the cfe-commits
mailing list