[clang] [analyzer] Fix [[clang::suppress]] for template instantiations (PR #168954)
Ziqing Luo via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 21 11:31:46 PST 2025
================
@@ -1,4 +1,27 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_warnIfReached();
+
+struct Clazz {
+ template <typename T>
+ static void templated_memfn();
+};
+
+// This must come before the 'templated_memfn' is defined!
+static void instantiate() {
+ Clazz::templated_memfn<int>();
+}
+
+template <typename T>
+void Clazz::templated_memfn() {
+ // When we report a bug in a function, we traverse the lexical decl context
+ // of it while looking for suppression attributes to record what source
----------------
ziqingluo-90 wrote:
I'm trying to understand how `BugSuppression` works:
The bug is at the `clang_analyzer_warnIfReached()` call so the decl context being visited is the instantiated definition of `Clazz::templated_memfn<int>() {...}`. During visiting, the analyzer will find that the call expression has the attribute.
What would happen if I move `[[clang::suppress]]` to line 12: `[[clang::suppress]] Clazz::templated_memfn<int>();`?
https://github.com/llvm/llvm-project/pull/168954
More information about the cfe-commits
mailing list