[clang] Fix UPCAddressofArraySubscriptGadget::getClaimedVarUseSites() (PR #88406)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 11 09:15:09 PDT 2024
https://github.com/juanvazquez created https://github.com/llvm/llvm-project/pull/88406
UPCAddressofArraySubscriptGadget::getClaimedVarUseSites should skip parentheses when accessing the DeclRefExpr, otherwise a crash happens with parenthesized references.
>From f083f7f7e697b9753668e514f38af50898d571f8 Mon Sep 17 00:00:00 2001
From: Juan Vazquez <juvazq at google.com>
Date: Thu, 11 Apr 2024 18:01:30 +0200
Subject: [PATCH] Fix UPCAddressofArraySubscriptGadget::getClaimedVarUseSites()
UPCAddressofArraySubscriptGadget::getClaimedVarUseSites should skip
parentheses when accessing the DeclRefExpr, otherwise a crash happens
with parenthesized references.
---
clang/lib/Analysis/UnsafeBufferUsage.cpp | 2 +-
.../warn-unsafe-buffer-usage-suggestions-crashes.cpp | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-suggestions-crashes.cpp
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