[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
Mon Jul 8 04:51:45 PDT 2024
https://github.com/ccrownhill created https://github.com/llvm/llvm-project/pull/98016
This fixes issue #39558 which mentions the problem when compiling the following code with `-pedantic-errors` flag (it also mentions `-Wall -Wextra` but those shouldn't change the output, which is also the case in GCC):
```c
static void f();
int main()
{
f;
}
```
Clang only outputs an `undefined-internal` warning on the first line, but according to 6.9/3
```
"... Moreover, if an identifier declared with internal linkage is used in an
expression (other than as a part of the operand of a sizeof or _Alignof
operator whose result is an integer constant), there shall be exactly one
external definition for the identifier in the translation unit."
```
this should be illegal and hence an error.
I fixed this by changing the warning type from `Warning` to `ExtWarn` and by adding a suitable test.
>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] 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}}
+}
+
More information about the cfe-commits
mailing list