[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
Thu Jul 11 05:59:05 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 01/12] 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 02/12] 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.
>From b553d87a675cac5d60df2b1fdc586d6b7af6b687 Mon Sep 17 00:00:00 2001
From: ccrownhill <ckronbichler at proton.me>
Date: Wed, 10 Jul 2024 19:04:17 +0200
Subject: [PATCH 03/12] add more tests for undefined internals
---
...undefined_internal.c => undefined-internal-basic.c} | 0
clang/test/Sema/undefined-internal-generic-selection.c | 10 ++++++++++
clang/test/Sema/undefined-internal-sizeof.c | 10 ++++++++++
clang/test/Sema/undefined-internal-typeof.c | 10 ++++++++++
4 files changed, 30 insertions(+)
rename clang/test/Sema/{undefined_internal.c => undefined-internal-basic.c} (100%)
create mode 100644 clang/test/Sema/undefined-internal-generic-selection.c
create mode 100644 clang/test/Sema/undefined-internal-sizeof.c
create mode 100644 clang/test/Sema/undefined-internal-typeof.c
diff --git a/clang/test/Sema/undefined_internal.c b/clang/test/Sema/undefined-internal-basic.c
similarity index 100%
rename from clang/test/Sema/undefined_internal.c
rename to clang/test/Sema/undefined-internal-basic.c
diff --git a/clang/test/Sema/undefined-internal-generic-selection.c b/clang/test/Sema/undefined-internal-generic-selection.c
new file mode 100644
index 0000000000000..0a2b4b61e68e7
--- /dev/null
+++ b/clang/test/Sema/undefined-internal-generic-selection.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+
+// expected-no-diagnostics
+
+static int f(void);
+
+int main(void)
+{
+ int x = _Generic(f(), int: 10, short: 20);
+}
diff --git a/clang/test/Sema/undefined-internal-sizeof.c b/clang/test/Sema/undefined-internal-sizeof.c
new file mode 100644
index 0000000000000..f609473b1341c
--- /dev/null
+++ b/clang/test/Sema/undefined-internal-sizeof.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+
+// expected-no-diagnostics
+
+static int f(void);
+
+int main(void)
+{
+ int x = sizeof f();
+}
diff --git a/clang/test/Sema/undefined-internal-typeof.c b/clang/test/Sema/undefined-internal-typeof.c
new file mode 100644
index 0000000000000..51c682ef7e942
--- /dev/null
+++ b/clang/test/Sema/undefined-internal-typeof.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c23 -pedantic-errors
+
+// expected-no-diagnostics
+
+static int f(void);
+
+int main(void)
+{
+ typeof(f()) x;
+}
>From 72a5f4084167b9c1930adbd3756450e5e908b674 Mon Sep 17 00:00:00 2001
From: ccrownhill <ckronbichler at proton.me>
Date: Thu, 11 Jul 2024 10:17:58 +0200
Subject: [PATCH 04/12] cover alignof as well as illegal _Generic case for
undefined_internal error test
---
clang/test/Sema/undefined-internal-alignof.c | 10 ++++++++++
clang/test/Sema/undefined-internal-generic-selection.c | 10 ++++++----
...ternal-typeof.c => undefined-internal-typeof-c23.c} | 0
3 files changed, 16 insertions(+), 4 deletions(-)
create mode 100644 clang/test/Sema/undefined-internal-alignof.c
rename clang/test/Sema/{undefined-internal-typeof.c => undefined-internal-typeof-c23.c} (100%)
diff --git a/clang/test/Sema/undefined-internal-alignof.c b/clang/test/Sema/undefined-internal-alignof.c
new file mode 100644
index 0000000000000..7083857b67cf9
--- /dev/null
+++ b/clang/test/Sema/undefined-internal-alignof.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+
+static void f(void); // expected-no-error
+
+int main(void)
+{
+ int i = _Alignof(f);
+ // expected-error at -1 {{'_Alignof' applied to an expression is a GNU extension}}
+ // expected-error at -2 {{invalid application of 'alignof' to a function type}}
+}
diff --git a/clang/test/Sema/undefined-internal-generic-selection.c b/clang/test/Sema/undefined-internal-generic-selection.c
index 0a2b4b61e68e7..db5e33fff769b 100644
--- a/clang/test/Sema/undefined-internal-generic-selection.c
+++ b/clang/test/Sema/undefined-internal-generic-selection.c
@@ -1,10 +1,12 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
-// expected-no-diagnostics
-
-static int f(void);
+static void *f(void); // expected-error {{function 'f' has internal linkage but is not defined}}
int main(void)
{
- int x = _Generic(f(), int: 10, short: 20);
+ int j = _Generic(&f, void *(*)(void): 10, default: 20);
+ // expected-no-diagnostic at -1
+
+ void *k = _Generic(&f, void *(*)(void): f(), default: 20);
+ // expected-note at -1 {{used here}}
}
diff --git a/clang/test/Sema/undefined-internal-typeof.c b/clang/test/Sema/undefined-internal-typeof-c23.c
similarity index 100%
rename from clang/test/Sema/undefined-internal-typeof.c
rename to clang/test/Sema/undefined-internal-typeof-c23.c
>From c2225c1060ccad70d616e5da6d6c83832ffd6a55 Mon Sep 17 00:00:00 2001
From: Constantin Kronbichler <56307024+ccrownhill at users.noreply.github.com>
Date: Thu, 11 Jul 2024 14:13:38 +0200
Subject: [PATCH 05/12] Update clang/docs/ReleaseNotes.rst
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
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 a4146aeee25de..5bfb059aa0acb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -554,7 +554,7 @@ Attribute Changes in Clang
Improvements to Clang's diagnostics
-----------------------------------
-- Clang now emits an error instead of a warning for `undefined_internal`
+- Clang now emits an error instead of a warning for ``-Wundefined-internal``
when compiling with `-pedantic-errors` to conform to the C standard
- Clang now applies syntax highlighting to the code snippets it
>From b47f7a19e89559c098a7adc06f9dfb7b3e1a6d00 Mon Sep 17 00:00:00 2001
From: Constantin Kronbichler <56307024+ccrownhill at users.noreply.github.com>
Date: Thu, 11 Jul 2024 14:14:33 +0200
Subject: [PATCH 06/12] Update clang/test/Sema/undefined-internal-basic.c
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
clang/test/Sema/undefined-internal-basic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Sema/undefined-internal-basic.c b/clang/test/Sema/undefined-internal-basic.c
index 1b6c3a4b76e05..e45bd05bdf1ba 100644
--- a/clang/test/Sema/undefined-internal-basic.c
+++ b/clang/test/Sema/undefined-internal-basic.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unused -pedantic-errors
static void f(void); // expected-error {{function 'f' has internal linkage but is not defined}}
>From a9615d196234ce94799749096d983db9cb3169ca Mon Sep 17 00:00:00 2001
From: Constantin Kronbichler <56307024+ccrownhill at users.noreply.github.com>
Date: Thu, 11 Jul 2024 14:14:59 +0200
Subject: [PATCH 07/12] Update clang/test/Sema/undefined-internal-alignof.c
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
clang/test/Sema/undefined-internal-alignof.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Sema/undefined-internal-alignof.c b/clang/test/Sema/undefined-internal-alignof.c
index 7083857b67cf9..5cf6f4647a7dd 100644
--- a/clang/test/Sema/undefined-internal-alignof.c
+++ b/clang/test/Sema/undefined-internal-alignof.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-pointer-arith -pedantic-errors
static void f(void); // expected-no-error
>From 5b685bbf771af33a610040e8e2ffefed662e4e8f Mon Sep 17 00:00:00 2001
From: Constantin Kronbichler <56307024+ccrownhill at users.noreply.github.com>
Date: Thu, 11 Jul 2024 14:15:10 +0200
Subject: [PATCH 08/12] Update
clang/test/Sema/undefined-internal-generic-selection.c
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
clang/test/Sema/undefined-internal-generic-selection.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/clang/test/Sema/undefined-internal-generic-selection.c b/clang/test/Sema/undefined-internal-generic-selection.c
index db5e33fff769b..55f81daf7b4b3 100644
--- a/clang/test/Sema/undefined-internal-generic-selection.c
+++ b/clang/test/Sema/undefined-internal-generic-selection.c
@@ -4,9 +4,7 @@ static void *f(void); // expected-error {{function 'f' has internal linkage but
int main(void)
{
- int j = _Generic(&f, void *(*)(void): 10, default: 20);
- // expected-no-diagnostic at -1
-
- void *k = _Generic(&f, void *(*)(void): f(), default: 20);
+ int j = _Generic(&f, void (*)(void): 0);
+ void *k = _Generic(&f, void (*)(void): f, default: 0); // expected-note {{used here}}
// expected-note at -1 {{used here}}
}
>From e1ad5396d8238904efecbe6173cbebd64022b3a6 Mon Sep 17 00:00:00 2001
From: Constantin Kronbichler <56307024+ccrownhill at users.noreply.github.com>
Date: Thu, 11 Jul 2024 14:15:22 +0200
Subject: [PATCH 09/12] Update clang/test/Sema/undefined-internal-sizeof.c
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
clang/test/Sema/undefined-internal-sizeof.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Sema/undefined-internal-sizeof.c b/clang/test/Sema/undefined-internal-sizeof.c
index f609473b1341c..f6cb31f7c7a2b 100644
--- a/clang/test/Sema/undefined-internal-sizeof.c
+++ b/clang/test/Sema/undefined-internal-sizeof.c
@@ -6,5 +6,5 @@ static int f(void);
int main(void)
{
- int x = sizeof f();
+ int x = sizeof(f);
}
>From 02d002011d285956bda4a4e23651c4eb730da4d1 Mon Sep 17 00:00:00 2001
From: Constantin Kronbichler <56307024+ccrownhill at users.noreply.github.com>
Date: Thu, 11 Jul 2024 14:15:33 +0200
Subject: [PATCH 10/12] Update clang/test/Sema/undefined-internal-typeof-c23.c
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
clang/test/Sema/undefined-internal-typeof-c23.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Sema/undefined-internal-typeof-c23.c b/clang/test/Sema/undefined-internal-typeof-c23.c
index 51c682ef7e942..837c36d4910a7 100644
--- a/clang/test/Sema/undefined-internal-typeof-c23.c
+++ b/clang/test/Sema/undefined-internal-typeof-c23.c
@@ -6,5 +6,5 @@ static int f(void);
int main(void)
{
- typeof(f()) x;
+ typeof(&f) x;
}
>From 275f22d87add7836ff273c3a9c4dab612bdfb80c Mon Sep 17 00:00:00 2001
From: Constantin Kronbichler <56307024+ccrownhill at users.noreply.github.com>
Date: Thu, 11 Jul 2024 14:17:45 +0200
Subject: [PATCH 11/12] Update clang/test/Sema/undefined-internal-sizeof.c
Co-authored-by: Aaron Ballman <aaron at aaronballman.com>
---
clang/test/Sema/undefined-internal-sizeof.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Sema/undefined-internal-sizeof.c b/clang/test/Sema/undefined-internal-sizeof.c
index f6cb31f7c7a2b..d395eb3bd0b20 100644
--- a/clang/test/Sema/undefined-internal-sizeof.c
+++ b/clang/test/Sema/undefined-internal-sizeof.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-pointer-arith -pedantic-errors
// expected-no-diagnostics
>From 8e50923830bb1a2234db46fb9f3640174180ca40 Mon Sep 17 00:00:00 2001
From: ccrownhill <ckronbichler at proton.me>
Date: Thu, 11 Jul 2024 14:58:37 +0200
Subject: [PATCH 12/12] group undefined-internal error tests into single file
---
clang/test/Sema/undefined-internal-alignof.c | 10 -------
clang/test/Sema/undefined-internal-basic.c | 30 +++++++++++++++----
.../undefined-internal-generic-selection.c | 10 -------
clang/test/Sema/undefined-internal-sizeof.c | 10 -------
4 files changed, 24 insertions(+), 36 deletions(-)
delete mode 100644 clang/test/Sema/undefined-internal-alignof.c
delete mode 100644 clang/test/Sema/undefined-internal-generic-selection.c
delete mode 100644 clang/test/Sema/undefined-internal-sizeof.c
diff --git a/clang/test/Sema/undefined-internal-alignof.c b/clang/test/Sema/undefined-internal-alignof.c
deleted file mode 100644
index 5cf6f4647a7dd..0000000000000
--- a/clang/test/Sema/undefined-internal-alignof.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-pointer-arith -pedantic-errors
-
-static void f(void); // expected-no-error
-
-int main(void)
-{
- int i = _Alignof(f);
- // expected-error at -1 {{'_Alignof' applied to an expression is a GNU extension}}
- // expected-error at -2 {{invalid application of 'alignof' to a function type}}
-}
diff --git a/clang/test/Sema/undefined-internal-basic.c b/clang/test/Sema/undefined-internal-basic.c
index e45bd05bdf1ba..baf05d474250e 100644
--- a/clang/test/Sema/undefined-internal-basic.c
+++ b/clang/test/Sema/undefined-internal-basic.c
@@ -1,11 +1,29 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unused -pedantic-errors
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-pointer-arith -Wno-gnu-alignof-expression -Wno-unused -pedantic-errors
-static void f(void); // expected-error {{function 'f' has internal linkage but is not defined}}
+static void *a(void); // expected-error {{function 'a' has internal linkage but is not defined}}
+static void *b(void); // expected-error {{function 'b' has internal linkage but is not defined}}
+static void *c(void); // expected-error {{function 'c' has internal linkage but is not defined}}
+static void *d(void); // expected-error {{function 'd' has internal linkage but is not defined}}
+static void *no_err(void);
int main(void)
{
- f;
- // expected-note at -1 {{used here}}
- // expected-warning at -2 {{expression result unused}}
-}
+ a; // expected-note {{used here}}
+
+ int i = _Alignof(no_err);
+
+ int j = _Generic(&no_err, void *(*)(void): 0);
+
+ void *k = _Generic(&no_err, void *(*)(void): b(), default: 0); // expected-note {{used here}}
+
+ // FIXME according to the C standard there should be no error if the undefined internal is
+ // "part of the expression in a generic association that is not the result expression of its generic selection;"
+ // but, currently, clang wrongly emits an error in this case
+ k = _Generic(&no_err, void *(*)(void): 0, default: c()); // expected-note {{used here}}
+ k = _Generic(&no_err, int (*)(void) : 0, default : d()); // expected-note {{used here}}
+
+ int l = sizeof(no_err);
+
+ __typeof__(&no_err) x;
+}
diff --git a/clang/test/Sema/undefined-internal-generic-selection.c b/clang/test/Sema/undefined-internal-generic-selection.c
deleted file mode 100644
index 55f81daf7b4b3..0000000000000
--- a/clang/test/Sema/undefined-internal-generic-selection.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// 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)
-{
- int j = _Generic(&f, void (*)(void): 0);
- void *k = _Generic(&f, void (*)(void): f, default: 0); // expected-note {{used here}}
- // expected-note at -1 {{used here}}
-}
diff --git a/clang/test/Sema/undefined-internal-sizeof.c b/clang/test/Sema/undefined-internal-sizeof.c
deleted file mode 100644
index d395eb3bd0b20..0000000000000
--- a/clang/test/Sema/undefined-internal-sizeof.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-pointer-arith -pedantic-errors
-
-// expected-no-diagnostics
-
-static int f(void);
-
-int main(void)
-{
- int x = sizeof(f);
-}
More information about the cfe-commits
mailing list