Skip to content

Commit 8f8317f

Browse files
committed
add TO_UPSTREAM comments
1 parent 848d9d4 commit 8f8317f

File tree

9 files changed

+55
-2
lines changed

9 files changed

+55
-2
lines changed

clang/include/clang/APINotes/Types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ inline bool operator!=(const ContextInfo &LHS, const ContextInfo &RHS) {
300300
return !(LHS == RHS);
301301
}
302302

303+
/* TO_UPSTREAM(BoundsSafety) ON */
303304
class BoundsSafetyInfo {
304305
public:
305306
enum class BoundsSafetyKind {
@@ -361,6 +362,7 @@ inline bool operator==(const BoundsSafetyInfo &LHS,
361362
LHS.LevelAudited == RHS.LevelAudited && LHS.Level == RHS.Level &&
362363
LHS.ExternalBounds == RHS.ExternalBounds;
363364
}
365+
/* TO_UPSTREAM(BoundsSafety) OFF */
364366

365367
/// API notes for a variable/property.
366368
class VariableInfo : public CommonEntityInfo {
@@ -501,7 +503,9 @@ class ParamInfo : public VariableInfo {
501503
unsigned RawRetainCountConvention : 3;
502504

503505
public:
506+
/* TO_UPSTREAM(BoundsSafety) ON */
504507
std::optional<BoundsSafetyInfo> BoundsSafety;
508+
/* TO_UPSTREAM(BoundsSafety) OFF */
505509

506510
ParamInfo()
507511
: NoEscapeSpecified(false), NoEscape(false),
@@ -552,8 +556,10 @@ class ParamInfo : public VariableInfo {
552556
if (!RawRetainCountConvention)
553557
RawRetainCountConvention = RHS.RawRetainCountConvention;
554558

559+
/* TO_UPSTREAM(BoundsSafety) ON */
555560
if (!BoundsSafety)
556561
BoundsSafety = RHS.BoundsSafety;
562+
/* TO_UPSTREAM(BoundsSafety) OFF */
557563

558564
return *this;
559565
}
@@ -570,7 +576,9 @@ inline bool operator==(const ParamInfo &LHS, const ParamInfo &RHS) {
570576
LHS.LifetimeboundSpecified == RHS.LifetimeboundSpecified &&
571577
LHS.Lifetimebound == RHS.Lifetimebound &&
572578
LHS.RawRetainCountConvention == RHS.RawRetainCountConvention &&
579+
/* TO_UPSTREAM(BoundsSafety) ON */
573580
LHS.BoundsSafety == RHS.BoundsSafety;
581+
/* TO_UPSTREAM(BoundsSafety) OFF */
574582
}
575583

576584
inline bool operator!=(const ParamInfo &LHS, const ParamInfo &RHS) {

clang/include/clang/Parse/Parser.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ class Parser : public CodeCompletionHandler {
20212021
/// Parse a __builtin_bit_cast(T, E), used to implement C++2a std::bit_cast.
20222022
ExprResult ParseBuiltinBitCast();
20232023

2024-
/* TO_UPSTREAM(BoundsSafety) ON*/
2024+
/* TO_UPSTREAM(BoundsSafety) ON */
20252025
//===--------------------------------------------------------------------===//
20262026
/// BoundsSafety: __builtin_unsafe_forge_bidi_indexable(expr, size)
20272027
ExprResult ParseUnsafeForgeBidiIndexable();
@@ -3924,10 +3924,25 @@ class Parser : public CodeCompletionHandler {
39243924
/// \param IncludeLoc The location at which this parse was triggered.
39253925
TypeResult ParseTypeFromString(StringRef TypeStr, StringRef Context,
39263926
SourceLocation IncludeLoc);
3927+
/* TO_UPSTREAM(BoundsSafety) ON */
3928+
/// Parse the given string as an expression in the argument position for a
3929+
/// bounds safety attribute.
3930+
///
3931+
/// This is a dangerous utility function currently employed only by API notes.
3932+
/// It is not a general entry-point for safely parsing expressions from
3933+
/// strings.
3934+
///
3935+
/// \param ExprStr The string to be parsed as an expression.
3936+
/// \param Context The name of the context in which this string is being
3937+
/// parsed, which will be used in diagnostics.
3938+
/// \param ParentDecl If a function or method is provided, the parameters are
3939+
/// added to the current parsing context.
3940+
/// \param IncludeLoc The location at which this parse was triggered.
39273941
ExprResult ParseBoundsAttributeArgFromString(StringRef ExprStr,
39283942
StringRef Context,
39293943
Decl *ParentDecl,
39303944
SourceLocation IncludeLoc);
3945+
/* TO_UPSTREAM(BoundsSafety) OFF */
39313946

39323947
//===--------------------------------------------------------------------===//
39333948
// Modules

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,9 +1131,11 @@ class Sema final : public SemaBase {
11311131
std::function<TypeResult(StringRef, StringRef, SourceLocation)>
11321132
ParseTypeFromStringCallback;
11331133

1134+
/* TO_UPSTREAM(BoundsSafety) ON */
11341135
/// Callback to the parser to parse a type expressed as a string.
11351136
std::function<ExprResult(StringRef, StringRef, Decl *, SourceLocation)>
11361137
ParseBoundsAttributeArgFromStringCallback;
1138+
/* TO_UPSTREAM(BoundsSafety) OFF */
11371139

11381140
/// VAListTagName - The declaration name corresponding to __va_list_tag.
11391141
/// This is used as part of a hack to omit that class from ADL results.
@@ -15508,12 +15510,12 @@ class Sema final : public SemaBase {
1550815510
llvm::SmallVectorImpl<TypeCoupledDeclRefInfo> &Decls, bool CountInBytes,
1550915511
bool OrNull);
1551015512

15513+
/* TO_UPSTREAM(BoundsSafety) ON */
1551115514
void applyPtrCountedByEndedByAttr(Decl *D, unsigned Level,
1551215515
AttributeCommonInfo::Kind Kind,
1551315516
Expr *AttrArg, SourceLocation Loc,
1551415517
SourceRange Range, StringRef DiagName);
1551515518

15516-
/* TO_UPSTREAM(BoundsSafety) ON*/
1551715519
/// Perform Bounds Safety Semantic checks for assigning to a `__counted_by` or
1551815520
/// `__counted_by_or_null` pointer type \param LHSTy.
1551915521
///

clang/lib/APINotes/APINotesReader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ class FieldTableInfo
322322
}
323323
};
324324

325+
/* TO_UPSTREAM(BoundsSafety) ON */
325326
BoundsSafetyInfo::BoundsSafetyKind readKindFlag(uint8_t kind) {
326327
switch (kind) {
327328
case 0x00:
@@ -359,6 +360,7 @@ void ReadBoundsSafetyInfo(const uint8_t *&Data, BoundsSafetyInfo &Info) {
359360
Info.ExternalBounds = std::string(Data, Data + ExternalBoundsLen);
360361
Data += ExternalBoundsLen;
361362
}
363+
/* TO_UPSTREAM(BoundsSafety) OFF */
362364

363365
/// Read serialized ParamInfo.
364366
void ReadParamInfo(const uint8_t *&Data, ParamInfo &Info) {
@@ -376,11 +378,13 @@ void ReadParamInfo(const uint8_t *&Data, ParamInfo &Info) {
376378
if (Payload & 0x01)
377379
Info.setNoEscape(Payload & 0x02);
378380
Payload >>= 2;
381+
/* TO_UPSTREAM(BoundsSafety) ON */
379382
if (Payload & 0x01) {
380383
BoundsSafetyInfo BSI;
381384
ReadBoundsSafetyInfo(Data, BSI);
382385
Info.BoundsSafety = BSI;
383386
}
387+
/* TO_UPSTREAM(BoundsSafety) OFF */
384388
}
385389

386390
/// Read serialized FunctionInfo.

clang/lib/APINotes/APINotesWriter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ void APINotesWriter::Implementation::writeGlobalVariableBlock(
10741074
}
10751075
}
10761076

1077+
/* TO_UPSTREAM(BoundsSafety) ON */
10771078
namespace {
10781079
uint8_t getKindFlag(BoundsSafetyInfo::BoundsSafetyKind kind) {
10791080
switch (kind) {
@@ -1112,11 +1113,14 @@ void emitBoundsSafetyInfo(raw_ostream &OS, const BoundsSafetyInfo &BSI) {
11121113
unsigned getBoundsSafetyInfoSize(const BoundsSafetyInfo &BSI) {
11131114
return 1 + sizeof(uint16_t) + BSI.ExternalBounds.size();
11141115
}
1116+
/* TO_UPSTREAM(BoundsSafety) OFF */
11151117

11161118
unsigned getParamInfoSize(const ParamInfo &PI) {
11171119
unsigned BSISize = 0;
1120+
/* TO_UPSTREAM(BoundsSafety) ON */
11181121
if (auto BSI = PI.BoundsSafety)
11191122
BSISize = getBoundsSafetyInfoSize(*BSI);
1123+
/* TO_UPSTREAM(BoundsSafety) OFF */
11201124
return getVariableInfoSize(PI) + 1 + BSISize;
11211125
}
11221126

@@ -1144,8 +1148,10 @@ void emitParamInfo(raw_ostream &OS, const ParamInfo &PI) {
11441148

11451149
llvm::support::endian::Writer writer(OS, llvm::endianness::little);
11461150
writer.write<uint8_t>(flags);
1151+
/* TO_UPSTREAM(BoundsSafety) ON */
11471152
if (auto BSI = PI.BoundsSafety)
11481153
emitBoundsSafetyInfo(OS, *PI.BoundsSafety);
1154+
/* TO_UPSTREAM(BoundsSafety) OFF */
11491155
}
11501156

11511157
/// Retrieve the serialized size of the given FunctionInfo, for use in on-disk

clang/lib/APINotes/APINotesYAMLCompiler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ enum class APIAvailability {
150150
};
151151
} // namespace
152152

153+
/* TO_UPSTREAM(BoundsSafety) ON */
153154
namespace {
154155
struct BoundsSafety {
155156
BoundsSafetyInfo::BoundsSafetyKind Kind;
@@ -174,6 +175,7 @@ template <> struct ScalarEnumerationTraits<BoundsSafetyInfo::BoundsSafetyKind> {
174175
};
175176
} // namespace yaml
176177
} // namespace llvm
178+
/* TO_UPSTREAM(BoundsSafety) OFF */
177179

178180
namespace llvm {
179181
namespace yaml {
@@ -213,7 +215,9 @@ struct Param {
213215
std::optional<NullabilityKind> Nullability;
214216
std::optional<RetainCountConventionKind> RetainCountConvention;
215217
StringRef Type;
218+
/* TO_UPSTREAM(BoundsSafety) ON */
216219
BoundsSafety BoundsSafety;
220+
/* TO_UPSTREAM(BoundsSafety) OFF */
217221
};
218222

219223
typedef std::vector<Param> ParamsSeq;
@@ -264,17 +268,21 @@ template <> struct MappingTraits<Param> {
264268
IO.mapOptional("NoEscape", P.NoEscape);
265269
IO.mapOptional("Lifetimebound", P.Lifetimebound);
266270
IO.mapOptional("Type", P.Type, StringRef(""));
271+
/* TO_UPSTREAM(BoundsSafety) ON */
267272
IO.mapOptional("BoundsSafety", P.BoundsSafety);
273+
/* TO_UPSTREAM(BoundsSafety) OFF */
268274
}
269275
};
270276

277+
/* TO_UPSTREAM(BoundsSafety) ON */
271278
template <> struct MappingTraits<BoundsSafety> {
272279
static void mapping(IO &IO, BoundsSafety &BS) {
273280
IO.mapRequired("Kind", BS.Kind);
274281
IO.mapRequired("BoundedBy", BS.BoundsExpr);
275282
IO.mapOptional("Level", BS.Level, 0);
276283
}
277284
};
285+
/* TO_UPSTREAM(BoundsSafety) OFF */
278286
} // namespace yaml
279287
} // namespace llvm
280288

@@ -898,10 +906,12 @@ class YAMLConverter {
898906
PI.setType(std::string(P.Type));
899907
PI.setRetainCountConvention(P.RetainCountConvention);
900908
BoundsSafetyInfo BSI;
909+
/* TO_UPSTREAM(BoundsSafety) ON */
901910
BSI.setKindAudited(P.BoundsSafety.Kind);
902911
BSI.setLevelAudited(P.BoundsSafety.Level);
903912
BSI.ExternalBounds = P.BoundsSafety.BoundsExpr.str();
904913
PI.BoundsSafety = BSI;
914+
/* TO_UPSTREAM(BoundsSafety) OFF */
905915
if (static_cast<int>(OutInfo.Params.size()) <= P.Position)
906916
OutInfo.Params.resize(P.Position + 1);
907917
if (P.Position == -1)

clang/lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8941,6 +8941,7 @@ TypeResult Parser::ParseTypeFromString(StringRef TypeStr, StringRef Context,
89418941
return Result;
89428942
}
89438943

8944+
/* TO_UPSTREAM(BoundsSafety) ON */
89448945
ExprResult
89458946
Parser::ParseBoundsAttributeArgFromString(StringRef ExprStr, StringRef Context,
89468947
Decl *ParentDecl,
@@ -9022,6 +9023,7 @@ Parser::ParseBoundsAttributeArgFromString(StringRef ExprStr, StringRef Context,
90229023
Actions.ActOnExitFunctionContext();
90239024
return Result;
90249025
}
9026+
/* TO_UPSTREAM(BoundsSafety) OFF */
90259027

90269028
void Parser::DiagnoseBitIntUse(const Token &Tok) {
90279029
// If the token is for _ExtInt, diagnose it as being deprecated. Otherwise,

clang/lib/Parse/Parser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies)
7676
[this](StringRef TypeStr, StringRef Context, SourceLocation IncludeLoc) {
7777
return this->ParseTypeFromString(TypeStr, Context, IncludeLoc);
7878
};
79+
/* TO_UPSTREAM(BoundsSafety) ON */
7980
Actions.ParseBoundsAttributeArgFromStringCallback =
8081
[this](StringRef ExprStr, StringRef Context, Decl *Parent,
8182
SourceLocation IncludeLoc) {
8283
return this->ParseBoundsAttributeArgFromString(ExprStr, Context, Parent,
8384
IncludeLoc);
8485
};
86+
/* TO_UPSTREAM(BoundsSafety) OFF */
8587
}
8688

8789
DiagnosticBuilder Parser::Diag(SourceLocation Loc, unsigned DiagID) {

clang/lib/Sema/SemaAPINotes.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ static void ProcessAPINotes(Sema &S, Decl *D,
409409
Metadata);
410410
}
411411

412+
/* TO_UPSTREAM(BoundsSafety) ON */
412413
static void applyBoundsSafety(Sema &S, ValueDecl *D,
413414
const api_notes::BoundsSafetyInfo &Info,
414415
VersionedInfoMetadata Metadata) {
@@ -453,6 +454,7 @@ static void applyBoundsSafety(Sema &S, ValueDecl *D,
453454
SourceLocation(), SourceRange(), AttrName);
454455
}
455456
}
457+
/* TO_UPSTREAM(BoundsSafety) OFF */
456458

457459
/// Process API notes for a parameter.
458460
static void ProcessAPINotes(Sema &S, ParmVarDecl *D,
@@ -471,8 +473,10 @@ static void ProcessAPINotes(Sema &S, ParmVarDecl *D,
471473
LifetimeBoundAttr(S.Context, getPlaceholderAttrInfo());
472474
});
473475

476+
/* TO_UPSTREAM(BoundsSafety) ON */
474477
if (Info.BoundsSafety.has_value())
475478
applyBoundsSafety(S, D, *Info.BoundsSafety, Metadata);
479+
/* TO_UPSTREAM(BoundsSafety) OFF */
476480

477481
// Retain count convention
478482
handleAPINotedRetainCountConvention(S, D, Metadata,

0 commit comments

Comments
 (0)