Skip to content

Commit 617437c

Browse files
committed
Use ArrayRef instead of raw pointers
1 parent 3392c6e commit 617437c

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,22 +1896,29 @@ def LifetimeCaptureBy : DeclOrTypeAttr {
18961896
let Documentation = [LifetimeCaptureByDocs];
18971897
let AdditionalMembers = [{
18981898
private:
1899-
IdentifierInfo** ArgIdents;
1900-
SourceLocation* ArgLocs;
1899+
MutableArrayRef<IdentifierInfo*> ArgIdents;
1900+
MutableArrayRef<SourceLocation> ArgLocs;
19011901

19021902
public:
19031903
static constexpr int THIS = 0;
19041904
static constexpr int INVALID = -1;
19051905
static constexpr int UNKNOWN = -2;
19061906
static constexpr int GLOBAL = -3;
19071907

1908-
void setArgs(IdentifierInfo **Idents, SourceLocation *Locs) {
1909-
ArgIdents = Idents;
1910-
ArgLocs = Locs;
1908+
void CreateArgs(ASTContext &Ctx) {
1909+
ArgIdents =
1910+
MutableArrayRef<IdentifierInfo *>(new (Ctx) IdentifierInfo *[params_Size], params_Size);
1911+
ArgLocs =
1912+
MutableArrayRef<SourceLocation>(new (Ctx) SourceLocation[params_Size], params_Size);
1913+
}
1914+
auto getArgIdents() const {
1915+
assert(ArgIdents.size() == params_Size);
1916+
return ArgIdents;
1917+
}
1918+
auto getArgLocs() const {
1919+
assert(ArgLocs.size() == params_Size);
1920+
return ArgLocs;
19111921
}
1912-
1913-
auto getArgIdents() const { return ArrayRef<IdentifierInfo*>(ArgIdents, params_Size); }
1914-
auto getArgLocs() const { return ArrayRef<SourceLocation>(ArgLocs, params_Size); }
19151922
void setParamIdx(size_t Idx, int Val) {
19161923
assert(Idx < params_Size);
19171924
params_[Idx] = Val;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,8 +3878,12 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
38783878
return nullptr;
38793879
}
38803880
unsigned N = AL.getNumArgs();
3881-
IdentifierInfo **ParamIdents = new (Context) IdentifierInfo *[N];
3882-
SourceLocation *ParamLocs = new (Context) SourceLocation[N];
3881+
SmallVector<int> FakeParamIndices(N, LifetimeCaptureByAttr::INVALID);
3882+
auto *CapturedBy = ::new (Context)
3883+
LifetimeCaptureByAttr(Context, AL, FakeParamIndices.data(), N);
3884+
CapturedBy->CreateArgs(Context);
3885+
MutableArrayRef<SourceLocation> ParamLocs = CapturedBy->getArgLocs();
3886+
MutableArrayRef<IdentifierInfo *> ParamIdents = CapturedBy->getArgIdents();
38833887
bool IsValid = true;
38843888
for (unsigned I = 0; I < N; ++I) {
38853889
if (AL.isArgExpr(I)) {
@@ -3899,13 +3903,7 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
38993903
ParamIdents[I] = IdLoc->Ident;
39003904
ParamLocs[I] = IdLoc->Loc;
39013905
}
3902-
if (!IsValid)
3903-
return nullptr;
3904-
SmallVector<int> FakeParamIndices(N, LifetimeCaptureByAttr::INVALID);
3905-
LifetimeCaptureByAttr *CapturedBy = ::new (Context) LifetimeCaptureByAttr(
3906-
Context, AL, FakeParamIndices.data(), FakeParamIndices.size());
3907-
CapturedBy->setArgs(ParamIdents, ParamLocs);
3908-
return CapturedBy;
3906+
return IsValid ? CapturedBy : nullptr;
39093907
}
39103908

39113909
static void handleLifetimeCaptureByAttr(Sema &S, Decl *D,

0 commit comments

Comments
 (0)