llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: V S Susi Krishna (Susikrishna) <details> <summary>Changes</summary> 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 --- Full diff: https://github.com/llvm/llvm-project/pull/166332.diff 2 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+5-3) - (added) clang/test/Sema/inline-static-var.c (+7) ``````````diff 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; } `````````` </details> https://github.com/llvm/llvm-project/pull/166332 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
