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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits