[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)

Constantin Kronbichler via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 10 05:06:55 PDT 2024


https://github.com/ccrownhill updated https://github.com/llvm/llvm-project/pull/98016

>From 5dd2bb12dee26ba93d927ad1cd99fa610f9ace97 Mon Sep 17 00:00:00 2001
From: ccrownhill <ckronbichler at proton.me>
Date: Mon, 8 Jul 2024 11:42:37 +0100
Subject: [PATCH 1/2] fix bug that undefined internal is a warning only for
 -pedantic-errors

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 +-
 clang/test/Sema/undefined_internal.c             | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Sema/undefined_internal.c

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44fd51ec9abc9..ae3dbedd01693 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6013,7 +6013,7 @@ def note_deleted_assign_field : Note<
   "because field %2 is of %select{reference|const-qualified}4 type %3">;
 
 // These should be errors.
-def warn_undefined_internal : Warning<
+def warn_undefined_internal : ExtWarn<
   "%select{function|variable}0 %q1 has internal linkage but is not defined">,
   InGroup<DiagGroup<"undefined-internal">>;
 def err_undefined_internal_type : Error<
diff --git a/clang/test/Sema/undefined_internal.c b/clang/test/Sema/undefined_internal.c
new file mode 100644
index 0000000000000..1b6c3a4b76e05
--- /dev/null
+++ b/clang/test/Sema/undefined_internal.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+
+static void f(void); // expected-error {{function 'f' has internal linkage but is not defined}}
+
+int main(void)
+{
+    f;
+    // expected-note at -1 {{used here}}
+    // expected-warning at -2 {{expression result unused}}
+}
+

>From 9e679ac9c2c669b595d361516b7e499e0b0457ba Mon Sep 17 00:00:00 2001
From: ccrownhill <ckronbichler at proton.me>
Date: Wed, 10 Jul 2024 12:06:28 +0100
Subject: [PATCH 2/2] add to change of undefined_internal to error for
 -pedantic-errors to release notes

---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 838cb69f647ee..a4146aeee25de 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -554,6 +554,9 @@ Attribute Changes in Clang
 
 Improvements to Clang's diagnostics
 -----------------------------------
+- Clang now emits an error instead of a warning for `undefined_internal`
+  when compiling with `-pedantic-errors` to conform to the C standard
+
 - Clang now applies syntax highlighting to the code snippets it
   prints.
 



More information about the cfe-commits mailing list