Skip to content

Commit 93673b4

Browse files
committed
address PR comments
1 parent 56dfef9 commit 93673b4

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6161,36 +6161,36 @@ getBoundsAttrKind(AttributeCommonInfo::Kind Kind) {
61616161
}
61626162

61636163
class EarlyLifetimeAndScopeCheck
6164-
: public StmtVisitor<EarlyLifetimeAndScopeCheck, bool> {
6164+
: public ConstStmtVisitor<EarlyLifetimeAndScopeCheck, bool> {
61656165
Sema &SemaRef;
61666166
bool ScopeCheck;
61676167
Sema::LifetimeCheckKind LifetimeCheck;
61686168
BoundsAttributedType::BoundsAttrKind AttrKind;
61696169
bool IsArrayType;
6170-
llvm::SmallPtrSet<Decl *, 16> Visited;
6170+
llvm::SmallPtrSet<const ValueDecl *, 16> Visited;
61716171

61726172
public:
61736173
EarlyLifetimeAndScopeCheck(Sema &S, bool SC, Sema::LifetimeCheckKind LC,
61746174
AttributeCommonInfo::Kind AK, bool IsArray)
61756175
: SemaRef(S), ScopeCheck(SC), LifetimeCheck(LC),
61766176
AttrKind(getBoundsAttrKind(AK)), IsArrayType(IsArray) {}
61776177

6178-
bool VisitStmt(Stmt *S) {
6178+
bool VisitStmt(const Stmt *S) {
61796179
bool HadError = false;
6180-
for (auto Child : S->children())
6180+
for (const auto *Child : S->children())
61816181
HadError |= Visit(Child);
61826182
return HadError;
61836183
}
61846184

6185-
bool VisitDeclRefExpr(DeclRefExpr *E) {
6186-
ValueDecl *VD = E->getDecl();
6185+
bool VisitDeclRefExpr(const DeclRefExpr *E) {
6186+
const ValueDecl *VD = E->getDecl();
61876187
bool IsNewVD = Visited.insert(VD).second;
61886188
return IsNewVD &&
61896189
CheckArgLifetimeAndScope(SemaRef, VD, E->getExprLoc(), ScopeCheck,
61906190
LifetimeCheck, AttrKind, IsArrayType);
61916191
}
61926192

6193-
bool VisitMemberExpr(MemberExpr *E) {
6193+
bool VisitMemberExpr(const MemberExpr *E) {
61946194
bool HadError = Visit(E->getBase());
61956195
ValueDecl *VD = E->getMemberDecl();
61966196
bool IsNewVD = Visited.insert(VD).second;

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,30 +651,32 @@ instantiateBoundsSafetyAttr(Sema &S,
651651
int Level;
652652
Expr *ArgExpr;
653653
std::string Spelling;
654-
if (auto A = dyn_cast<SizedByAttr>(AL)) {
654+
if (const auto *A = dyn_cast<SizedByAttr>(AL)) {
655655
Level = A->getNestedLevel();
656656
ArgExpr = A->getSize();
657657
Spelling = A->getSpelling();
658-
} else if (auto A = dyn_cast<SizedByOrNullAttr>(AL)) {
658+
} else if (const auto *A = dyn_cast<SizedByOrNullAttr>(AL)) {
659659
Level = A->getNestedLevel();
660660
ArgExpr = A->getSize();
661661
Spelling = A->getSpelling();
662-
} else if (auto A = dyn_cast<CountedByAttr>(AL)) {
662+
} else if (const auto *A = dyn_cast<CountedByAttr>(AL)) {
663663
Level = A->getNestedLevel();
664664
ArgExpr = A->getCount();
665665
Spelling = A->getSpelling();
666-
} else if (auto A = dyn_cast<CountedByOrNullAttr>(AL)) {
666+
} else if (const auto *A = dyn_cast<CountedByOrNullAttr>(AL)) {
667667
Level = A->getNestedLevel();
668668
ArgExpr = A->getCount();
669669
Spelling = A->getSpelling();
670-
} else if (auto A = dyn_cast<PtrEndedByAttr>(AL)) {
670+
} else if (const auto *A = dyn_cast<PtrEndedByAttr>(AL)) {
671671
Level = A->getNestedLevel();
672672
ArgExpr = A->getEndPtr();
673673
Spelling = A->getSpelling();
674674
} else
675675
llvm_unreachable("unexpected late instantiated bounds safety attribute");
676676

677677
ExprResult InstantiatedArgExpr = S.SubstExpr(ArgExpr, TemplateArgs);
678+
if (InstantiatedArgExpr.isInvalid())
679+
return;
678680
S.applyPtrCountedByEndedByAttr(
679681
New, Level, AL->getParsedKind(), InstantiatedArgExpr.get(), AL->getLoc(),
680682
AL->getRange(), "\'" + Spelling + "\'", /*from API notes*/ false,

0 commit comments

Comments
 (0)