Skip to content

Commit ed9007d

Browse files
committed
Revert "[Bounds-Safety] Temporarily relax a counted_by attribute restriction on flexible array members"
Together with 0ec3b97 breaks https://lab.llvm.org/buildbot/#/builders/5/builds/43403 Issue #92687 This reverts commit cef6387.
1 parent 7273ad1 commit ed9007d

File tree

4 files changed

+6
-32
lines changed

4 files changed

+6
-32
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,10 +1447,6 @@ def FunctionMultiVersioning
14471447

14481448
def NoDeref : DiagGroup<"noderef">;
14491449

1450-
// -fbounds-safety and bounds annotation related warnings
1451-
def BoundsSafetyCountedByEltTyUnknownSize :
1452-
DiagGroup<"bounds-safety-counted-by-elt-type-unknown-size">;
1453-
14541450
// A group for cross translation unit static analysis related warnings.
14551451
def CrossTU : DiagGroup<"ctu">;
14561452

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6552,7 +6552,7 @@ def err_counted_by_attr_refer_to_union : Error<
65526552
def note_flexible_array_counted_by_attr_field : Note<
65536553
"field %0 declared here">;
65546554
def err_counted_by_attr_pointee_unknown_size : Error<
6555-
"'counted_by' %select{cannot|should not}3 be applied to %select{"
6555+
"'counted_by' cannot be applied to %select{"
65566556
"a pointer with pointee|" // pointer
65576557
"an array with element}0" // array
65586558
" of unknown size because %1 is %select{"
@@ -6561,14 +6561,8 @@ def err_counted_by_attr_pointee_unknown_size : Error<
65616561
"a function type|" // CountedByInvalidPointeeTypeKind::FUNCTION
65626562
// CountedByInvalidPointeeTypeKind::FLEXIBLE_ARRAY_MEMBER
65636563
"a struct type with a flexible array member"
6564-
"%select{|. This will be an error in a future compiler version}3"
6565-
""
65666564
"}2">;
65676565

6568-
def warn_counted_by_attr_elt_type_unknown_size :
6569-
Warning<err_counted_by_attr_pointee_unknown_size.Summary>,
6570-
InGroup<BoundsSafetyCountedByEltTyUnknownSize>;
6571-
65726566
let CategoryName = "ARC Semantic Issue" in {
65736567

65746568
// ARC-mode diagnostics.

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8687,33 +8687,20 @@ static bool CheckCountedByAttrOnField(
86878687
// Note: The `Decl::isFlexibleArrayMemberLike` check earlier on means
86888688
// only `PointeeTy->isStructureTypeWithFlexibleArrayMember()` is reachable
86898689
// when `FieldTy->isArrayType()`.
8690-
bool ShouldWarn = false;
86918690
if (PointeeTy->isIncompleteType()) {
86928691
InvalidTypeKind = CountedByInvalidPointeeTypeKind::INCOMPLETE;
86938692
} else if (PointeeTy->isSizelessType()) {
86948693
InvalidTypeKind = CountedByInvalidPointeeTypeKind::SIZELESS;
86958694
} else if (PointeeTy->isFunctionType()) {
86968695
InvalidTypeKind = CountedByInvalidPointeeTypeKind::FUNCTION;
86978696
} else if (PointeeTy->isStructureTypeWithFlexibleArrayMember()) {
8698-
if (FieldTy->isArrayType()) {
8699-
// This is a workaround for the Linux kernel that has already adopted
8700-
// `counted_by` on a FAM where the pointee is a struct with a FAM. This
8701-
// should be an error because computing the bounds of the array cannot be
8702-
// done correctly without manually traversing every struct object in the
8703-
// array at runtime. To allow the code to be built this error is
8704-
// downgraded to a warning.
8705-
ShouldWarn = true;
8706-
}
87078697
InvalidTypeKind = CountedByInvalidPointeeTypeKind::FLEXIBLE_ARRAY_MEMBER;
87088698
}
87098699

87108700
if (InvalidTypeKind != CountedByInvalidPointeeTypeKind::VALID) {
8711-
unsigned DiagID = ShouldWarn
8712-
? diag::warn_counted_by_attr_elt_type_unknown_size
8713-
: diag::err_counted_by_attr_pointee_unknown_size;
8714-
S.Diag(FD->getBeginLoc(), DiagID)
8701+
S.Diag(FD->getBeginLoc(), diag::err_counted_by_attr_pointee_unknown_size)
87158702
<< SelectPtrOrArr << PointeeTy << (int)InvalidTypeKind
8716-
<< (ShouldWarn ? 1 : 0) << FD->getSourceRange();
8703+
<< FD->getSourceRange();
87178704
return true;
87188705
}
87198706

clang/test/Sema/attr-counted-by-vla.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,24 +173,21 @@ struct has_annotated_VLA {
173173

174174
struct buffer_of_structs_with_unnannotated_vla {
175175
int count;
176-
// Treating this as a warning is a temporary fix for existing attribute adopters. It **SHOULD BE AN ERROR**.
177-
// expected-warning@+1{{'counted_by' should not be applied to an array with element of unknown size because 'struct has_unannotated_VLA' is a struct type with a flexible array member. This will be an error in a future compiler version}}
176+
// expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_unannotated_VLA' is a struct type with a flexible array member}}
178177
struct has_unannotated_VLA Arr[] __counted_by(count);
179178
};
180179

181180

182181
struct buffer_of_structs_with_annotated_vla {
183182
int count;
184-
// Treating this as a warning is a temporary fix for existing attribute adopters. It **SHOULD BE AN ERROR**.
185-
// expected-warning@+1{{'counted_by' should not be applied to an array with element of unknown size because 'struct has_annotated_VLA' is a struct type with a flexible array member. This will be an error in a future compiler version}}
183+
// expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_annotated_VLA' is a struct type with a flexible array member}}
186184
struct has_annotated_VLA Arr[] __counted_by(count);
187185
};
188186

189187
struct buffer_of_const_structs_with_annotated_vla {
190188
int count;
191-
// Treating this as a warning is a temporary fix for existing attribute adopters. It **SHOULD BE AN ERROR**.
192189
// Make sure the `const` qualifier is printed when printing the element type.
193-
// expected-warning@+1{{'counted_by' should not be applied to an array with element of unknown size because 'const struct has_annotated_VLA' is a struct type with a flexible array member. This will be an error in a future compiler version}}
190+
// expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'const struct has_annotated_VLA' is a struct type with a flexible array member}}
194191
const struct has_annotated_VLA Arr[] __counted_by(count);
195192
};
196193

0 commit comments

Comments
 (0)