[clang] [analyzer] Adjust ExprEngine::VisitDeclStmt to ignore `T v=v;` idiom cases for C code (PR #187530)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 20 06:21:49 PDT 2026


================
@@ -0,0 +1,29 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -verify
----------------
NagyDonat wrote:

Please add a second `RUN:` configuration that demonstrates the difference between C and C++ by also analyzing this test in C++ mode (I hope that `std=c++whatever` works even if the file is named `something.c`).

You can use `-verify=expected,c` and `-verify=expected,cpp` on the two run lines to be able to say `c-warning` and `cpp-warning` for warnings that are only emitted in C or C++ (and `expected-warning` will denote a warning that appears in both C and C++). 

As the self-assignments would cause warnings in C++, you will probably need to move them into separate functions (`self_assign_int`, `self_assign_ptr` etc.).

You can also include the reference self-assignment in `#ifdef __cplusplus`.

https://github.com/llvm/llvm-project/pull/187530


More information about the cfe-commits mailing list