[clang] [Clang-CL][DXC] Expose -fdiagnostic-color= to clang-cl and clang-dxc (PR #120644)
Chris White via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 20 12:40:20 PST 2024
https://github.com/whiteio updated https://github.com/llvm/llvm-project/pull/120644
>From 770dec5aec1b879bafbc6c69b12a2e43c9497f7f Mon Sep 17 00:00:00 2001
From: Chris White <chriswhiteiodev at gmail.com>
Date: Thu, 19 Dec 2024 22:02:47 +0000
Subject: [PATCH 1/2] [Clang-CL][DXC] Expose -fdiagnostic-color= to clang-cl
and clang-dxc
---
clang/include/clang/Driver/Options.td | 2 +-
clang/test/Driver/cl-options.c | 9 +++++++++
clang/test/Driver/dxc_options.hlsl | 8 ++++++++
clang/test/Driver/unknown-arg-drivermodes.test | 4 ----
4 files changed, 18 insertions(+), 5 deletions(-)
create mode 100644 clang/test/Driver/dxc_options.hlsl
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 638f8c52053ec5..ad64626d960d43 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1990,7 +1990,7 @@ def : Flag<["-"], "fno-diagnostics-color">, Group<f_Group>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
Alias<fno_color_diagnostics>;
def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, Group<f_Group>,
- Visibility<[ClangOption, FlangOption]>,
+ Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
Values<"auto,always,never">,
HelpText<"When to use colors in diagnostics">;
def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group<f_Group>,
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 477e8489e74280..fe57a5232b2fdc 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -664,6 +664,15 @@
// RUN: not %clang_cl /guard:foo -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARDINVALID %s
// CFGUARDINVALID: invalid value 'foo' in '/guard:'
+// The test doesn't run in a PTY, so "auto" defaults to off.
+// RUN: %clang_cl -fdiagnostics-color=auto -### -- %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s
+
+// RUN: %clang_cl -fdiagnostics-color -### -- %s 2>&1 | FileCheck -check-prefix=COLOR %s
+// RUN: %clang_cl -fdiagnostics-color=always -### -- %s 2>&1 | FileCheck -check-prefix=COLOR %s
+// RUN: %clang_cl -fdiagnostics-color=never -### -- %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s
+// COLOR: "-fcolor-diagnostics"
+// NO_COLOR-NOT: "-fcolor-diagnostics"
+
// Accept "core" clang options.
// (/Zs is for syntax-only, -Werror makes it fail hard on unknown options)
// RUN: %clang_cl \
diff --git a/clang/test/Driver/dxc_options.hlsl b/clang/test/Driver/dxc_options.hlsl
new file mode 100644
index 00000000000000..9bd4b61cdcf19d
--- /dev/null
+++ b/clang/test/Driver/dxc_options.hlsl
@@ -0,0 +1,8 @@
+// The test doesn't run in a PTY, so "auto" defaults to off.
+// RUN: %clang_dxc -Tlib_6_7 -fdiagnostics-color=auto -### -- %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s
+
+// RUN: %clang_dxc -Tlib_6_7 -fdiagnostics-color -### %s 2>&1 | FileCheck -check-prefix=COLOR %s
+// RUN: %clang_dxc -Tlib_6_7 -fdiagnostics-color=always -### %s 2>&1 | FileCheck -check-prefix=COLOR %s
+// RUN: %clang_dxc -Tlib_6_7 -fdiagnostics-color=never -### %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s
+// COLOR: "-fcolor-diagnostics"
+// NO_COLOR-NOT: "-fcolor-diagnostics"
\ No newline at end of file
diff --git a/clang/test/Driver/unknown-arg-drivermodes.test b/clang/test/Driver/unknown-arg-drivermodes.test
index a7ea73af345e03..0125d79b47afa1 100644
--- a/clang/test/Driver/unknown-arg-drivermodes.test
+++ b/clang/test/Driver/unknown-arg-drivermodes.test
@@ -1,6 +1,5 @@
// RUN: %clang_cl \
// RUN: --config \
-// RUN: -fdiagnostics-color=auto \
// RUN: -fno-record-command-line \
// RUN: -frecord-command-line \
// RUN: -nodefaultlibs \
@@ -15,7 +14,6 @@
// RUN: not %clang_dxc \
// RUN: --config \
-// RUN: -fdiagnostics-color=auto \
// RUN: -fno-record-command-line \
// RUN: -frecord-command-line \
// RUN: -nodefaultlibs \
@@ -30,7 +28,6 @@
// RUN: | FileCheck %s --check-prefix=DXC --implicit-check-not="error:"
// CL: warning: unknown argument ignored in clang-cl: '--config'
-// CL: warning: unknown argument ignored in clang-cl: '-fdiagnostics-color=auto'
// CL: warning: unknown argument ignored in clang-cl: '-fno-record-command-line'
// CL: warning: unknown argument ignored in clang-cl: '-frecord-command-line'
// CL: warning: unknown argument ignored in clang-cl: '-nodefaultlibs'
@@ -42,7 +39,6 @@
// CL: warning: unknown argument ignored in clang-cl: '-Xoffload-linker'
// DXC: error: unknown argument: '--config'
-// DXC: error: unknown argument: '-fdiagnostics-color=auto'
// DXC: error: unknown argument: '-fno-record-command-line'
// DXC: error: unknown argument: '-frecord-command-line'
// DXC: error: unknown argument: '-nodefaultlibs'
>From bc06ddddd22ca5508b7e72437bfba4c874b43e0f Mon Sep 17 00:00:00 2001
From: Chris White <chriswhiteiodev at gmail.com>
Date: Fri, 20 Dec 2024 20:40:09 +0000
Subject: [PATCH 2/2] Address PR comments
---
clang/docs/ReleaseNotes.rst | 3 +++
clang/test/Driver/cl-options.c | 10 +---------
clang/test/Driver/dxc_options.hlsl | 14 +++++++-------
3 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5f91ff90634036..2909263d3484d2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -445,6 +445,9 @@ New Compiler Flags
- The ``-Warray-compare-cxx26`` warning has been added to warn about array comparison
starting from C++26, this warning is enabled as an error by default.
+- clang-cl and clang-dxc now support ``-fdiagnostics-color=[auto|never|always]``
+ in addition to ``-f[no-]color-diagnostics``.
+
Deprecated Compiler Flags
-------------------------
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index fe57a5232b2fdc..c975727839c0bf 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -664,15 +664,6 @@
// RUN: not %clang_cl /guard:foo -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARDINVALID %s
// CFGUARDINVALID: invalid value 'foo' in '/guard:'
-// The test doesn't run in a PTY, so "auto" defaults to off.
-// RUN: %clang_cl -fdiagnostics-color=auto -### -- %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s
-
-// RUN: %clang_cl -fdiagnostics-color -### -- %s 2>&1 | FileCheck -check-prefix=COLOR %s
-// RUN: %clang_cl -fdiagnostics-color=always -### -- %s 2>&1 | FileCheck -check-prefix=COLOR %s
-// RUN: %clang_cl -fdiagnostics-color=never -### -- %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s
-// COLOR: "-fcolor-diagnostics"
-// NO_COLOR-NOT: "-fcolor-diagnostics"
-
// Accept "core" clang options.
// (/Zs is for syntax-only, -Werror makes it fail hard on unknown options)
// RUN: %clang_cl \
@@ -689,6 +680,7 @@
// RUN: -fcoverage-mapping \
// RUN: -fno-coverage-mapping \
// RUN: -fdiagnostics-color \
+// RUN: -fdiagnostics-color=auto \
// RUN: -fno-diagnostics-color \
// RUN: -fdebug-compilation-dir . \
// RUN: -fdebug-compilation-dir=. \
diff --git a/clang/test/Driver/dxc_options.hlsl b/clang/test/Driver/dxc_options.hlsl
index 9bd4b61cdcf19d..09fdba1c3dd5f4 100644
--- a/clang/test/Driver/dxc_options.hlsl
+++ b/clang/test/Driver/dxc_options.hlsl
@@ -1,8 +1,8 @@
-// The test doesn't run in a PTY, so "auto" defaults to off.
-// RUN: %clang_dxc -Tlib_6_7 -fdiagnostics-color=auto -### -- %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s
+// RUN: %clang_dxc \
+// RUN: -fcolor-diagnostics \
+// RUN: -fno-color-diagnostics \
+// RUN: -fdiagnostics-color \
+// RUN: -fno-diagnostics-color \
+// RUN: -fdiagnostics-color=auto \
+// RUN: -Tlib_6_7 -Vd -fdriver-only -- %s 2>&1 |count 0
-// RUN: %clang_dxc -Tlib_6_7 -fdiagnostics-color -### %s 2>&1 | FileCheck -check-prefix=COLOR %s
-// RUN: %clang_dxc -Tlib_6_7 -fdiagnostics-color=always -### %s 2>&1 | FileCheck -check-prefix=COLOR %s
-// RUN: %clang_dxc -Tlib_6_7 -fdiagnostics-color=never -### %s 2>&1 | FileCheck -check-prefix=NO_COLOR %s
-// COLOR: "-fcolor-diagnostics"
-// NO_COLOR-NOT: "-fcolor-diagnostics"
\ No newline at end of file
More information about the cfe-commits
mailing list