Skip to content

Commit 9b72e2c

Browse files
committed
make BoundsSafety std::optional, add test w/o optional level field
1 parent 97e519f commit 9b72e2c

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

clang/lib/APINotes/APINotesYAMLCompiler.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ struct Param {
214214
std::optional<bool> Lifetimebound = false;
215215
std::optional<NullabilityKind> Nullability;
216216
std::optional<RetainCountConventionKind> RetainCountConvention;
217-
StringRef Type;
218217
/* TO_UPSTREAM(BoundsSafety) ON */
219-
BoundsSafety BoundsSafety;
218+
std::optional<BoundsSafety> BoundsSafety;
220219
/* TO_UPSTREAM(BoundsSafety) OFF */
220+
StringRef Type;
221221
};
222222

223223
typedef std::vector<Param> ParamsSeq;
@@ -907,9 +907,11 @@ class YAMLConverter {
907907
PI.setRetainCountConvention(P.RetainCountConvention);
908908
BoundsSafetyInfo BSI;
909909
/* TO_UPSTREAM(BoundsSafety) ON */
910-
BSI.setKindAudited(P.BoundsSafety.Kind);
911-
BSI.setLevelAudited(P.BoundsSafety.Level);
912-
BSI.ExternalBounds = P.BoundsSafety.BoundsExpr.str();
910+
if (P.BoundsSafety) {
911+
BSI.setKindAudited(P.BoundsSafety->Kind);
912+
BSI.setLevelAudited(P.BoundsSafety->Level);
913+
BSI.ExternalBounds = P.BoundsSafety->BoundsExpr.str();
914+
}
913915
PI.BoundsSafety = BSI;
914916
/* TO_UPSTREAM(BoundsSafety) OFF */
915917
if (static_cast<int>(OutInfo.Params.size()) <= P.Position)

clang/test/APINotes/Inputs/Headers/BoundsUnsafe.apinotes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ Functions:
7272
Kind: counted_by
7373
Level: 0
7474
BoundedBy: len
75+
- Name: asdf_counted_default_level
76+
Parameters:
77+
- Position: 0
78+
BoundsSafety:
79+
Kind: counted_by
80+
BoundedBy: len
7581
- Name: asdf_nterm
7682
Parameters:
7783
- Position: 0

clang/test/APINotes/Inputs/Headers/BoundsUnsafe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ void asdf_counted_out(int ** buf, int * len);
99
void asdf_counted_const(int * buf);
1010
void asdf_counted_nullable(int len, int * _Nullable buf);
1111
void asdf_counted_noescape(int * buf, int len);
12+
void asdf_counted_default_level(int * buf, int len);
1213

1314
void asdf_nterm(char * buf);

clang/test/APINotes/boundssafety.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
// CHECK: buf 'int * __counted_by(len)':'int *'
3636
// CHECK-NEXT: NoEscapeAttr
3737

38+
// CHECK: asdf_counted_default_level 'void (int * __counted_by(len), int)'
39+
// CHECK: buf 'int * __counted_by(len)':'int *'
40+
3841
// CHECK: asdf_nterm 'void (int * __terminated_by(0))'
3942
// CHECK: buf 'int * __terminated_by(0)':'int *'
4043

0 commit comments

Comments
 (0)