aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorHenrik G. Olsson <hnrklssn@gmail.com>2024-07-09 13:58:01 -0700
committerGitHub <noreply@github.com>2024-07-09 13:58:01 -0700
commite22ebee5a3bb56cb7f9a9513f01fb7ed24b23f48 (patch)
tree543aafea0fcbb569c50f37977ecdb4e2b3f89bc7 /clang/lib/Parse/ParseDecl.cpp
parent9e1f1cfa59c4513798de5c326d77e1e5912b1634 (diff)
downloadllvm-e22ebee5a3bb56cb7f9a9513f01fb7ed24b23f48.zip
llvm-e22ebee5a3bb56cb7f9a9513f01fb7ed24b23f48.tar.gz
llvm-e22ebee5a3bb56cb7f9a9513f01fb7ed24b23f48.tar.bz2
[Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (#93231)
The attributes `sized_by`, `counted_by_or_null` and `sized_by_or_null` have been added as variants on `counted_by`, each with slightly different semantics. `sized_by` takes a byte size parameter instead of an element count, allowing pointees with unknown size. The `counted_by_or_null` and `sized_by_or_null` variants are equivalent to their base variants, except the pointer can be null regardless of count/size value. If the pointer is null the size is effectively 0. rdar://125400354
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 0aae5f3..7ce9a9c 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -700,7 +700,10 @@ void Parser::ParseGNUAttributeArgs(
ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, ScopeName,
ScopeLoc, Form);
return;
- } else if (AttrKind == ParsedAttr::AT_CountedBy) {
+ } else if (AttrKind == ParsedAttr::AT_CountedBy ||
+ AttrKind == ParsedAttr::AT_CountedByOrNull ||
+ AttrKind == ParsedAttr::AT_SizedBy ||
+ AttrKind == ParsedAttr::AT_SizedByOrNull) {
ParseBoundsAttribute(*AttrName, AttrNameLoc, Attrs, ScopeName, ScopeLoc,
Form);
return;
@@ -4866,9 +4869,8 @@ static void DiagnoseCountAttributedTypeInUnnamedAnon(ParsingDeclSpec &DS,
for (const auto &DD : CAT->dependent_decls()) {
if (!RD->containsDecl(DD.getDecl())) {
- P.Diag(VD->getBeginLoc(),
- diag::err_flexible_array_count_not_in_same_struct)
- << DD.getDecl();
+ P.Diag(VD->getBeginLoc(), diag::err_count_attr_param_not_in_same_struct)
+ << DD.getDecl() << CAT->getKind() << CAT->isArrayType();
P.Diag(DD.getDecl()->getBeginLoc(),
diag::note_flexible_array_counted_by_attr_field)
<< DD.getDecl();