aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2024-01-21 13:18:51 -0500
committerAaron Ballman <aaron@aaronballman.com>2024-01-21 13:20:56 -0500
commit997ffce43c6d2d3f647eb091c732665049b1f47f (patch)
treef1029f75b98a5d3c07bd134295c9137008a53f6d
parentbc82cfb38d83f1afeb2c290aa472c2e2e88919cb (diff)
downloadllvm-997ffce43c6d2d3f647eb091c732665049b1f47f.zip
llvm-997ffce43c6d2d3f647eb091c732665049b1f47f.tar.gz
llvm-997ffce43c6d2d3f647eb091c732665049b1f47f.tar.bz2
[C23] Implement N2490, Remove trigraphs??!
This follows the same implementation logic as with C++ and is compatible with the GCC behavior in C. Trigraphs are enabled by default in -std=c* conformance modes before C23, but are disabled in GNU and Microsoft modes as well as in C23 or later.
-rw-r--r--clang/docs/ReleaseNotes.rst7
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp8
-rw-r--r--clang/test/C/C2x/n2940.c26
-rw-r--r--clang/test/C/drs/dr3xx.c31
-rw-r--r--clang/test/Preprocessor/ucn-pp-identifier.c2
-rw-r--r--clang/www/c_status.html2
6 files changed, 59 insertions, 17 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bb26fc..28fd79a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -271,6 +271,13 @@ C23 Feature Support
previously implemented allowing a label at the end of a compound statement,
and now we've implemented allowing a label to be followed by a declaration
instead of a statement.
+- Implemented
+ `N2940 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2940.pdf>`_ which
+ removes support for trigraphs in C23 and later. In earlier language modes,
+ trigraphs remain enabled by default in conforming modes (e.g. ``-std=c17``)
+ and disabled by default in GNU and Microsoft modes (e.g., ``-std=gnu17`` or
+ ``-fms-compatibility``). If needed, you can enable trigraphs by passing
+ ``-ftrigraphs``.
Non-comprehensive list of changes in this release
-------------------------------------------------
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index ed9cd12..7edea77 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3480,7 +3480,8 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
Twine(Major) + "." + Twine(Minor) + "." + Twine(Subminor));
}
- if ((!Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus17) || T.isOSzOS()) {
+ if ((!Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus17 && !Opts.C23) ||
+ T.isOSzOS()) {
if (!Opts.Trigraphs)
GenerateArg(Consumer, OPT_fno_trigraphs);
} else {
@@ -3876,10 +3877,11 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
// Mimicking gcc's behavior, trigraphs are only enabled if -trigraphs
// is specified, or -std is set to a conforming mode.
- // Trigraphs are disabled by default in c++1z onwards.
+ // Trigraphs are disabled by default in C++17 and C23 onwards.
// For z/OS, trigraphs are enabled by default (without regard to the above).
Opts.Trigraphs =
- (!Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus17) || T.isOSzOS();
+ (!Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus17 && !Opts.C23) ||
+ T.isOSzOS();
Opts.Trigraphs =
Args.hasFlag(OPT_ftrigraphs, OPT_fno_trigraphs, Opts.Trigraphs);
diff --git a/clang/test/C/C2x/n2940.c b/clang/test/C/C2x/n2940.c
new file mode 100644
index 0000000..ee92b6e
--- /dev/null
+++ b/clang/test/C/C2x/n2940.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -verify=no-trigraphs -std=c23 %s
+// RUN: %clang_cc1 -verify=no-trigraphs -std=gnu23 %s
+// RUN: %clang_cc1 -verify=no-trigraphs -std=gnu17 %s
+// RUN: %clang_cc1 -verify=no-trigraphs -std=gnu11 %s
+// RUN: %clang_cc1 -verify=no-trigraphs -std=gnu99 %s
+// RUN: %clang_cc1 -verify=no-trigraphs -std=gnu89 %s
+// RUN: %clang_cc1 -verify=trigraphs -std=c17 %s
+// RUN: %clang_cc1 -verify=trigraphs -std=c11 %s
+// RUN: %clang_cc1 -verify=trigraphs -std=c99 %s
+// RUN: %clang_cc1 -verify=trigraphs -std=c89 %s
+// RUN: %clang_cc1 -verify=trigraphs -std=c23 -ftrigraphs %s
+
+/* WG14 N2940: Clang 18
+ * Removing trigraphs??!
+ */
+
+// Trigraphs are enabled by default in any conforming C mode before C23, but
+// are otherwise disabled (in all GNU modes, and in C23 or later).
+// The ??= trigraph, if supported, will become the # character, which is a null
+// preprocessor directive that does nothing.
+
+??=
+// no-trigraphs-warning@-1 {{trigraph ignored}} \
+ no-trigraphs-error@-1 {{expected identifier or '('}} \
+ trigraphs-warning@-1 {{trigraph converted to '#' character}}
+
diff --git a/clang/test/C/drs/dr3xx.c b/clang/test/C/drs/dr3xx.c
index 4d66171..0f67470 100644
--- a/clang/test/C/drs/dr3xx.c
+++ b/clang/test/C/drs/dr3xx.c
@@ -1,8 +1,8 @@
-/* RUN: %clang_cc1 -std=c89 -fsyntax-only -Wvla -verify=expected,c89only -pedantic -Wno-c11-extensions %s
- RUN: %clang_cc1 -std=c99 -fsyntax-only -Wvla -verify=expected,c99andup -pedantic -Wno-c11-extensions %s
- RUN: %clang_cc1 -std=c11 -fsyntax-only -Wvla -verify=expected,c99andup -pedantic %s
- RUN: %clang_cc1 -std=c17 -fsyntax-only -Wvla -verify=expected,c99andup -pedantic %s
- RUN: %clang_cc1 -std=c2x -fsyntax-only -Wvla -verify=expected,c99andup -pedantic %s
+/* RUN: %clang_cc1 -std=c89 -fsyntax-only -Wvla -verify=expected,c89only,c17andearlier -pedantic -Wno-c11-extensions %s
+ RUN: %clang_cc1 -std=c99 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic -Wno-c11-extensions %s
+ RUN: %clang_cc1 -std=c11 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic %s
+ RUN: %clang_cc1 -std=c17 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic %s
+ RUN: %clang_cc1 -std=c2x -fsyntax-only -Wvla -verify=expected,c99andup,c23andup -pedantic %s
*/
/* The following are DRs which do not require tests to demonstrate
@@ -70,13 +70,6 @@
#error "We definitely should not have gotten here"
#endif
-/* WG14 DR309: yes
- * Clarifying trigraph substitution
- */
-int dr309??(1??) = { 1 }; /* expected-warning {{trigraph converted to '[' character}}
- expected-warning {{trigraph converted to ']' character}}
- */
-
/* WG14 DR311: yes
* Definition of variably modified types
*/
@@ -292,3 +285,17 @@ void f(long double f,
char (**a)[10 * sizeof f]) {
_Static_assert(sizeof **a == sizeof(long double) * 10, "");
}
+
+/* WG14 DR309: yes
+ * Clarifying trigraph substitution
+ */
+int dr309??(1??) = { 1 }; /* c17andearlier-warning {{trigraph converted to '[' character}}
+ c17andearlier-warning {{trigraph converted to ']' character}}
+ c23andup-warning 2 {{trigraph ignored}}
+ c23andup-error {{expected ';' after top level declarator}}
+ */
+
+/* NOTE: Due to interactions with the diagnostic system, dr309 should be the
+ * last test case in this file because subsequent diagnostics may not be
+ * generated as expected.
+ */
diff --git a/clang/test/Preprocessor/ucn-pp-identifier.c b/clang/test/Preprocessor/ucn-pp-identifier.c
index 19cfc25..5efcfe4 100644
--- a/clang/test/Preprocessor/ucn-pp-identifier.c
+++ b/clang/test/Preprocessor/ucn-pp-identifier.c
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef -DTRIGRAPHS=1
-// RUN: %clang_cc1 %s -fsyntax-only -std=c2x -pedantic -verify=expected,ext -Wundef -DTRIGRAPHS=1
+// RUN: %clang_cc1 %s -fsyntax-only -std=c23 -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=1
// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -fno-trigraphs
// RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++23 -pedantic -ftrigraphs -DTRIGRAPHS=1 -verify=expected,cxx23 -Wundef -Wpre-c++23-compat
// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=1
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index b9e0650..3955a1d 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -1156,7 +1156,7 @@ conformance.</p>
<tr>
<td>Remove trigraphs??!</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2940.pdf">N2940</a></td>
- <td class="full" align="center">Yes</td>
+ <td class="unreleased" align="center">Clang 18</td>
</tr>
<tr>
<td>Improved normal enumerations</td>