[clang] [Clang] Use ExtWarn for static local variable in extern inline function (fixes #39524) (PR #166332)
V S Susi Krishna via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 5 22:07:43 PST 2025
https://github.com/Susikrishna updated https://github.com/llvm/llvm-project/pull/166332
>From 16414b96e0ca5ee44b0332bc387ecbd0046eacd4 Mon Sep 17 00:00:00 2001
From: Susikrishna <krishnasusi323 at gmail.com>
Date: Tue, 4 Nov 2025 12:49:38 +0530
Subject: [PATCH 1/6] [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; }
>From ee314e1af7b74a02c31f38493262025912bc1d8e Mon Sep 17 00:00:00 2001
From: V S Susi Krishna <142647179+Susikrishna at users.noreply.github.com>
Date: Wed, 5 Nov 2025 21:42:38 +0530
Subject: [PATCH 2/6] Update clang/test/Sema/inline-static-var.c
Co-authored-by: Sirraide <aeternalmail at gmail.com>
---
clang/test/Sema/inline-static-var.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/clang/test/Sema/inline-static-var.c b/clang/test/Sema/inline-static-var.c
index f622a7f22e02c..641f952ac6da7 100644
--- a/clang/test/Sema/inline-static-var.c
+++ b/clang/test/Sema/inline-static-var.c
@@ -4,4 +4,3 @@ inline void f(void) { // expected-note {{use 'static' to give inline function 'f
static int x; // expected-error {{non-constant static local variable in inline function may be different in different files}}
}
-int main(void) { return 0; }
>From b4abe8eab1fc27e584da327c581260a93596f1d7 Mon Sep 17 00:00:00 2001
From: Susikrishna <krishnasusi323 at gmail.com>
Date: Wed, 5 Nov 2025 22:23:48 +0530
Subject: [PATCH 3/6] Update release notes and diagnostics for static local
variables in extern inline functions
---
clang/docs/ReleaseNotes.rst | 4 ++++
clang/include/clang/Basic/DiagnosticSemaKinds.td | 8 +++-----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f57ddc92d5e8..f4d1d379e5608 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -402,6 +402,10 @@ Improvements to Clang's diagnostics
- Clang now emits a diagnostic in case `vector_size` or `ext_vector_type`
attributes are used with a negative size (#GH165463).
+- Clang now emits an extension warning (`ExtWarn`) instead of a regular warning
+ for static local variables declared inside `extern inline` functions
+ (#GH39524).
+
Improvements to Clang's time-trace
----------------------------------
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 629a2b9493c66..7f10a0cd0a770 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6339,11 +6339,9 @@ 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
- : ExtWarn<"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">;
>From d5431b8a6ed0f8e0e01936d4c91377738bbe5c45 Mon Sep 17 00:00:00 2001
From: V S Susi Krishna <142647179+Susikrishna at users.noreply.github.com>
Date: Wed, 5 Nov 2025 23:01:27 +0530
Subject: [PATCH 4/6] Update clang/docs/ReleaseNotes.rst
Co-authored-by: Sirraide <aeternalmail at gmail.com>
---
clang/docs/ReleaseNotes.rst | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f4d1d379e5608..4503bccfd64c2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -402,9 +402,9 @@ Improvements to Clang's diagnostics
- Clang now emits a diagnostic in case `vector_size` or `ext_vector_type`
attributes are used with a negative size (#GH165463).
-- Clang now emits an extension warning (`ExtWarn`) instead of a regular warning
- for static local variables declared inside `extern inline` functions
- (#GH39524).
+- The warning about static local variables declared inside `extern inline`
+ functions is now correctly converted to an error if `-pedantic-errors` is
+ passed (#GH39524).
Improvements to Clang's time-trace
----------------------------------
>From 544b1bade2fd0bb7b4bf9548d74176f66a32e86c Mon Sep 17 00:00:00 2001
From: Susikrishna <krishnasusi323 at gmail.com>
Date: Wed, 5 Nov 2025 23:10:40 +0530
Subject: [PATCH 5/6] Update release note to refer to `inline` functions
instead of `extern inline`
---
clang/docs/ReleaseNotes.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4503bccfd64c2..c92bc0987f7ca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -402,7 +402,7 @@ Improvements to Clang's diagnostics
- Clang now emits a diagnostic in case `vector_size` or `ext_vector_type`
attributes are used with a negative size (#GH165463).
-- The warning about static local variables declared inside `extern inline`
+- The warning about static local variables declared inside `inline`
functions is now correctly converted to an error if `-pedantic-errors` is
passed (#GH39524).
>From 44c4a48da30b4176fadc673d0c772be628b8a0c7 Mon Sep 17 00:00:00 2001
From: V S Susi Krishna <142647179+Susikrishna at users.noreply.github.com>
Date: Thu, 6 Nov 2025 11:37:33 +0530
Subject: [PATCH 6/6] Update clang/test/Sema/inline-static-var.c
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
clang/test/Sema/inline-static-var.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Sema/inline-static-var.c b/clang/test/Sema/inline-static-var.c
index 641f952ac6da7..38b972305179b 100644
--- a/clang/test/Sema/inline-static-var.c
+++ b/clang/test/Sema/inline-static-var.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c11 -Wno-unused-variable -Wno-deprecated-non-prototype -Wno-inline -pedantic-errors -verify %s
+// RUN: %clang_cc1 -std=c11 -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}}
More information about the cfe-commits
mailing list