Author: Artem Dergachev Date: 2022-12-20T16:05:13-08:00 New Revision: 8fd62e70cde135943e54d80851984988cb00000a
URL: https://github.com/llvm/llvm-project/commit/8fd62e70cde135943e54d80851984988cb00000a DIFF: https://github.com/llvm/llvm-project/commit/8fd62e70cde135943e54d80851984988cb00000a.diff LOG: [-Wunsafe-buffer-usage] Suppress an assertion for visiting VarDecl twice. The assertion doesn't seem to hold due to ASTMatchers traversing code inside GNU StmtExpr twice. This can screw up our algorithm's invariants. We need a further investigation to properly fix this issue, but for now let's avoid the crash. Added: clang/test/SemaCXX/warn-unsafe-buffer-usage-crashes.c Modified: clang/lib/Analysis/UnsafeBufferUsage.cpp Removed: ################################################################################ diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index 85449c4c5b1c4..88d6ca3eaf0c5 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -245,7 +245,11 @@ class DeclUseTracker { void discoverDecl(const DeclStmt *DS) { for (const Decl *D : DS->decls()) { if (const auto *VD = dyn_cast<VarDecl>(D)) { - assert(Defs.count(VD) == 0 && "Definition already discovered!"); + // FIXME: Assertion temporarily disabled due to a bug in + // ASTMatcher internal behavior in presence of GNU + // statement-expressions. We need to properly investigate this + // because it can screw up our algorithm in other ways. + // assert(Defs.count(VD) == 0 && "Definition already discovered!"); Defs[VD] = DS; } } diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-crashes.c b/clang/test/SemaCXX/warn-unsafe-buffer-usage-crashes.c new file mode 100644 index 0000000000000..225e67f7ba1c4 --- /dev/null +++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-crashes.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -Wunsafe-buffer-usage %s -verify %s + +void gnu_stmtexpr_crash(void) { + struct A {}; + struct B { + struct A a; + }; + + struct B b = {{ + // This is a statement-expression (GNU extension). + ({ int x; }) // no-crash // expected-warning{{excess elements in struct initializer}} + }}; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits