Skip to content

Commit 13ea36d

Browse files
authored
Fix UPCAddressofArraySubscriptGadget::getClaimedVarUseSites() (#88406)
UPCAddressofArraySubscriptGadget::getClaimedVarUseSites should skip parentheses when accessing the DeclRefExpr, otherwise a crash happens with parenthesized references.
1 parent ed7038e commit 13ea36d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ class UPCAddressofArraySubscriptGadget : public FixableGadget {
11141114
virtual DeclUseList getClaimedVarUseSites() const override {
11151115
const auto *ArraySubst = cast<ArraySubscriptExpr>(Node->getSubExpr());
11161116
const auto *DRE =
1117-
cast<DeclRefExpr>(ArraySubst->getBase()->IgnoreImpCasts());
1117+
cast<DeclRefExpr>(ArraySubst->getBase()->IgnoreParenImpCasts());
11181118
return {DRE};
11191119
}
11201120
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
2+
// RUN: -fsafe-buffer-usage-suggestions \
3+
// RUN: %s -verify %s
4+
5+
char * unsafe_pointer; // expected-warning{{'unsafe_pointer' is an unsafe pointer used for buffer access}}
6+
7+
void test(char * param) {
8+
}
9+
10+
void dre_parenthesized() {
11+
test(&(unsafe_pointer)[1]); // no-crash // expected-note{{used in buffer access here}}
12+
}

0 commit comments

Comments
 (0)