================
@@ -0,0 +1,130 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-but-set-variable -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-but-set-variable -I %S -verify 
%S/Inputs/warn-unused-but-set-static-global-header-test.c
+
+#define NULL (void*)0
+
+void *set(int size);
+void func_call(void *);
+
+static int set_unused; // expected-warning {{variable 'set_unused' set but not 
used}}
+static int set_and_used;
+static int only_used;
+static int addr_taken;
+extern int external_var;  // No warning (external linkage).
+extern int global_var;  // No warning (not static).
+
+void f1() {
+  set_unused = 1;
+  set_and_used = 2;
+
+  int x = set_and_used;
+  (void)x;
+
+  int y = only_used;
+  (void)y;
+
+  int *p = &addr_taken;
+  (void)p;
+
+  external_var = 3;
+  global_var = 4;
+}
+
+// Test across multiple functions.
+static int set_used1;
+static int set_used2;
+
+static int set1; // expected-warning {{variable 'set1' set but not used}}
+static int set2; // expected-warning {{variable 'set2' set but not used}}
+
+void f2() {
+  set1 = 1;
+  set_used1 = 1;
+
+  int x = set_used2;
+  (void)x;
+}
+
+void f3() {
+  set2 = 2;
+  set_used2 = 2;
+
+  int x = set_used1;
+  (void)x;
+}
+
+static volatile int vol_set; // expected-warning {{variable 'vol_set' set but 
not used}}
----------------
jpjepko wrote:

FWIW, I did some experimentation and both `-Wunused-but-set` and 
`-Wunused-variable` warn on volatiles when built from the main branch, so that 
might be behavior we want to match, unless there's good reason to diverge for 
file-scope statics.

https://github.com/llvm/llvm-project/pull/178342
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to