https://github.com/Susikrishna created 
https://github.com/llvm/llvm-project/pull/166332

This patch fixes incorrect behavior when compiling an inline function
definition containing a static local variable with external linkage.
Previously, Clang emitted a warning instead of an error under
`-pedantic-errors`, violating C11 6.7.4/3.

The diagnostic definition for `warn_static_local_in_extern_inline`
was changed from `Warning` to `ExtWarn`.

A new test was added under `clang/test/Sema/inline-static-var.c`
to verify that the behavior now matches the C standard and GCC’s output.

Fixes: #39524


>From 16414b96e0ca5ee44b0332bc387ecbd0046eacd4 Mon Sep 17 00:00:00 2001
From: Susikrishna <[email protected]>
Date: Tue, 4 Nov 2025 12:49:38 +0530
Subject: [PATCH] [Clang] Use ExtWarn for static local variable in extern
 inline function (fixes #39524)

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 8 +++++---
 clang/test/Sema/inline-static-var.c              | 7 +++++++
 2 files changed, 12 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/inline-static-var.c

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4e369be0bbb92..80272e24eced8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6337,9 +6337,11 @@ def warn_c2y_compat_internal_in_extern_inline : Warning<
   "using static %select{function|variable}0 %1 in an inline function with "
   "external linkage is incompatible with standards before C2y">,
   InGroup<CPre2yCompat>, DefaultIgnore;
-def warn_static_local_in_extern_inline : Warning<
-  "non-constant static local variable in inline function may be different "
-  "in different files">, InGroup<StaticLocalInInline>;
+def warn_static_local_in_extern_inline
+    : ExtWarn<"non-constant static local variable in inline function may be "
+              "different "
+              "in different files">,
+      InGroup<StaticLocalInInline>;
 def note_convert_inline_to_static : Note<
   "use 'static' to give inline function %0 internal linkage">;
 
diff --git a/clang/test/Sema/inline-static-var.c 
b/clang/test/Sema/inline-static-var.c
new file mode 100644
index 0000000000000..f622a7f22e02c
--- /dev/null
+++ b/clang/test/Sema/inline-static-var.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c11 -Wno-unused-variable -Wno-deprecated-non-prototype 
-Wno-inline -pedantic-errors -verify %s
+
+inline void f(void) { // expected-note {{use 'static' to give inline function 
'f' internal linkage}}
+  static int x; // expected-error {{non-constant static local variable in 
inline function may be different in different files}}
+}
+
+int main(void) { return 0; }

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

Reply via email to