[clang] 13ea36d - Fix UPCAddressofArraySubscriptGadget::getClaimedVarUseSites() (#88406)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 16 12:43:04 PDT 2024
Author: juan.vazquez
Date: 2024-04-16T12:42:59-07:00
New Revision: 13ea36db166b7007f8b1e84e0827faaf24eb448e
URL: https://github.com/llvm/llvm-project/commit/13ea36db166b7007f8b1e84e0827faaf24eb448e
DIFF: https://github.com/llvm/llvm-project/commit/13ea36db166b7007f8b1e84e0827faaf24eb448e.diff
LOG: Fix UPCAddressofArraySubscriptGadget::getClaimedVarUseSites() (#88406)
UPCAddressofArraySubscriptGadget::getClaimedVarUseSites should skip
parentheses when accessing the DeclRefExpr, otherwise a crash happens
with parenthesized references.
Added:
clang/test/SemaCXX/warn-unsafe-buffer-usage-suggestions-crashes.cpp
Modified:
clang/lib/Analysis/UnsafeBufferUsage.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index e03fe1b6830043..c42e70d5b95ac1 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1114,7 +1114,7 @@ class UPCAddressofArraySubscriptGadget : public FixableGadget {
virtual DeclUseList getClaimedVarUseSites() const override {
const auto *ArraySubst = cast<ArraySubscriptExpr>(Node->getSubExpr());
const auto *DRE =
- cast<DeclRefExpr>(ArraySubst->getBase()->IgnoreImpCasts());
+ cast<DeclRefExpr>(ArraySubst->getBase()->IgnoreParenImpCasts());
return {DRE};
}
};
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-suggestions-crashes.cpp b/clang/test/SemaCXX/warn-unsafe-buffer-usage-suggestions-crashes.cpp
new file mode 100644
index 00000000000000..bf4faec184ee17
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-suggestions-crashes.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
+// RUN: -fsafe-buffer-usage-suggestions \
+// RUN: %s -verify %s
+
+char * unsafe_pointer; // expected-warning{{'unsafe_pointer' is an unsafe pointer used for buffer access}}
+
+void test(char * param) {
+}
+
+void dre_parenthesized() {
+ test(&(unsafe_pointer)[1]); // no-crash // expected-note{{used in buffer access here}}
+}
More information about the cfe-commits
mailing list