Skip to content

Commit 53330a9

Browse files
committed
Add clarifying comments; Fix empty diagostic text; Use ArrayRef for parameter
1 parent f0ec140 commit 53330a9

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,8 @@ class Parser : public CodeCompletionHandler {
11641164
unsigned NestedTypeLevel;
11651165

11661166
explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name,
1167-
SourceLocation Loc, unsigned Level = 0)
1168-
: Self(P), AttrName(Name), AttrNameLoc(Loc), NestedTypeLevel(Level) {}
1167+
SourceLocation Loc, unsigned NestedTypeLevel = 0)
1168+
: Self(P), AttrName(Name), AttrNameLoc(Loc), NestedTypeLevel(NestedTypeLevel) {}
11691169

11701170
void ParseLexedAttributes() override;
11711171

clang/include/clang/Sema/DeclSpec.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,11 @@ struct DeclaratorChunk {
12381238

12391239
ParsedAttributesView AttrList;
12401240

1241-
using LateAttrListTy = SmallVector<void *, 1>;
1241+
/// Stores pointers to `Parser::LateParsedAttribute`. We use `void*` here
1242+
/// because `LateParsedAttribute` is a nested struct of `class Parser` and
1243+
/// cannot be forward-declared.
1244+
using LateAttrOpaquePtr = void *;
1245+
using LateAttrListTy = SmallVector<LateAttrOpaquePtr, 1>;
12421246
LateAttrListTy LateAttrList;
12431247

12441248
struct PointerTypeInfo {
@@ -2329,7 +2333,7 @@ class Declarator {
23292333
/// of those attributes from the parameter.
23302334
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs,
23312335
SourceLocation EndLoc,
2332-
const DeclaratorChunk::LateAttrListTy &LateAttrs = {}) {
2336+
ArrayRef<DeclaratorChunk::LateAttrOpaquePtr> LateAttrs = {}) {
23332337
DeclTypeInfo.push_back(TI);
23342338
DeclTypeInfo.back().getAttrs().prepend(attrs.begin(), attrs.end());
23352339
getAttributePool().takeAllFrom(attrs.getPool());

clang/lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,7 +3145,7 @@ void Parser::DistributeCLateParsedAttrs(Declarator &D, Decl *Dcl,
31453145
if (!LateAttrs)
31463146
return;
31473147

3148-
unsigned NestedLevel = 0;
3148+
unsigned NestedTypeLevel = 0;
31493149
for (unsigned i = 0; i < D.getNumTypeObjects(); ++i) {
31503150
DeclaratorChunk &DC = D.getTypeObject(i);
31513151

@@ -3160,10 +3160,10 @@ void Parser::DistributeCLateParsedAttrs(Declarator &D, Decl *Dcl,
31603160
// Extract `LateParsedAttribute *` from `DeclaratorChunk`.
31613161
for (auto *OpaqueLA : DC.LateAttrList) {
31623162
auto *LA = static_cast<LateParsedAttribute *>(OpaqueLA);
3163-
LA->NestedTypeLevel = NestedLevel;
3163+
LA->NestedTypeLevel = NestedTypeLevel;
31643164
LateAttrs->push_back(LA);
31653165
}
3166-
NestedLevel++;
3166+
NestedTypeLevel++;
31673167
}
31683168

31693169
// Attach `Decl *` to each `LateParsedAttribute *`.
@@ -6484,8 +6484,10 @@ void Parser::ParseDeclaratorInternal(Declarator &D,
64846484
if (Kind == tok::star) {
64856485
DeclaratorChunk::LateAttrListTy OpaqueLateAttrList;
64866486
if (getLangOpts().ExperimentalLateParseAttributes && !LateAttrs.empty()) {
6487+
// TODO: Support `counted_by` in function parameters, return types, and
6488+
// other contexts (Issue #167365).
64876489
if (!D.isFunctionDeclarator()) {
6488-
for (auto LA : LateAttrs) {
6490+
for (LateParsedAttribute *LA : LateAttrs) {
64896491
OpaqueLateAttrList.push_back(LA);
64906492
}
64916493
}

clang/test/Sema/attr-sized-by-late-parsed-struct-ptrs.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ struct on_pointer_anon_count {
102102
//==============================================================================
103103
// __sized_by on struct member pointer in type attribute position
104104
//==============================================================================
105-
// TODO: Correctly parse sized_by as a type attribute. Currently it is parsed
106-
// as a declaration attribute and is **not** late parsed resulting in the `size`
107-
// field being unavailable.
108105

109106
struct on_member_pointer_complete_ty_ty_pos {
110107
struct size_known *__sized_by(size) buf;
@@ -156,7 +153,7 @@ struct on_member_pointer_fn_ptr_ty_typedef_ty_pos {
156153
};
157154

158155
struct on_member_pointer_fn_ptr_ty_ty_pos_inner {
159-
// expected-error@+1{{}}
156+
// expected-error@+1{{'sized_by' attribute on nested pointer type is not allowed}}
160157
void (* __sized_by(size) * fn_ptr)(void);
161158
int size;
162159
};
@@ -174,9 +171,7 @@ struct on_member_pointer_struct_with_annotated_vla_ty_pos {
174171
};
175172

176173
struct on_nested_pointer_inner {
177-
// TODO: This should be disallowed because in the `-fbounds-safety` model
178-
// `__sized_by` can only be nested when used in function parameters.
179-
// expected-error@+1{{}}
174+
// expected-error@+1{{'sized_by' attribute on nested pointer type is not allowed}}
180175
struct size_known *__sized_by(size) *buf;
181176
int size;
182177
};

clang/test/Sema/attr-sized-by-or-null-late-parsed-struct-ptrs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct on_member_pointer_fn_ptr_ty_ptr_ty_pos {
136136
};
137137

138138
struct on_member_pointer_fn_ty_ty_pos {
139+
// TODO: Improve diagnostics (Issue #167368).
139140
// expected-error@+1{{'sized_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
140141
void (* __sized_by_or_null(size) fn_ptr)(void);
141142
int size;

0 commit comments

Comments
 (0)