[PATCH] D153064: [-Wunsafe-buffer-usage] Do not emit fixits for C++ interfaces with C linkage
Rashmi Mudduluru via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 16 13:29:01 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd1ae844dc2cc: [-Wunsafe-buffer-usage] Do not emit fixits for C++ interfaces with C linkage (authored by t-rasmud).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153064/new/
https://reviews.llvm.org/D153064
Files:
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-c-linkage.cpp
Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-c-linkage.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-c-linkage.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions -verify %s
+
+extern "C" {
+void foo(int *ptr) {
+ ptr[5] = 10; // expected-warning{{unsafe buffer access}}
+}
+
+void bar(int *ptr);
+
+struct c_struct {
+ char *name;
+};
+}
+
+void bar(int *ptr) {
+ ptr[5] = 10; // expected-warning{{unsafe buffer access}}
+}
+
+void call_foo(int *p) {
+ foo(p);
+ struct c_struct str;
+ str.name[7] = 9; // expected-warning{{unsafe buffer access}}
+ bar(p);
+}
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===================================================================
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2139,6 +2139,18 @@
UnsafeBufferUsageHandler &Handler,
bool EmitSuggestions) {
assert(D && D->getBody());
+
+ // Do not emit fixit suggestions for functions declared in an
+ // extern "C" block.
+ if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
+ for (FunctionDecl *FReDecl : FD->redecls()) {
+ if (FReDecl->isExternC()) {
+ EmitSuggestions = false;
+ break;
+ }
+ }
+ }
+
WarningGadgetSets UnsafeOps;
FixableGadgetSets FixablesForAllVars;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153064.532280.patch
Type: text/x-patch
Size: 1493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230616/27e478d3/attachment.bin>
More information about the cfe-commits
mailing list