Expose clang option `-fdiagnostics-format=` in dxc (#6357)

This change exposes the clang 3.7 `-fdiagnostics-format=` flag in DXC with supported values `clang`, `msvc`, `mdvc-fallback`, and `vi`.

This option allows having DXC output diagnostic messages in string formats that are recognized natively by Visual Studio.

Resolves #6160 & #1811, both of which had been closed as not planned.
This commit is contained in:
Jonas Meyer 2024-02-27 19:18:42 +01:00 коммит произвёл GitHub
Родитель 696a13a2a8
Коммит f0970beaf8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 32 добавлений и 0 удалений

Просмотреть файл

@ -156,6 +156,7 @@ public:
llvm::StringRef DefaultLinkage; // OPT_default_linkage
llvm::StringRef ImportBindingTable; // OPT_import_binding_table
llvm::StringRef BindingTableDefine; // OPT_binding_table_define
llvm::StringRef DiagnosticsFormat; // OPT_fdiagnostics_format
unsigned DefaultTextCodePage = DXC_CP_UTF8; // OPT_encoding
bool AllResourcesBound = false; // OPT_all_resources_bound

Просмотреть файл

@ -121,6 +121,9 @@ def fconstexpr_depth_EQ : Joined<["-"], "fconstexpr-depth=">, Group<f_Group>;
def fconstexpr_steps_EQ : Joined<["-"], "fconstexpr-steps=">, Group<f_Group>;
def fconstexpr_backtrace_limit_EQ : Joined<["-"], "fconstexpr-backtrace-limit=">,
Group<f_Group>;
def fdiagnostics_format_EQ : Joined<["-"], "fdiagnostics-format=">, Group<hlslcomp_Group>,
Flags<[CoreOption]>,
HelpText<"Select diagnostic message format. Supported values: clang, msvc, mdvc-fallback, vi">;
def fdiagnostics_show_option : Flag<["-"], "fdiagnostics-show-option">, Group<hlslcomp_Group>,
Flags<[CoreOption]>, HelpText<"Print option name with mappable diagnostics">;
def fno_diagnostics_show_option : Flag<["-"], "fno-diagnostics-show-option">, Group<hlslcomp_Group>,

Просмотреть файл

@ -538,6 +538,8 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
opts.OutputReflectionFile = Args.getLastArgValue(OPT_Fre);
opts.OutputRootSigFile = Args.getLastArgValue(OPT_Frs);
opts.OutputShaderHashFile = Args.getLastArgValue(OPT_Fsh);
opts.DiagnosticsFormat =
Args.getLastArgValue(OPT_fdiagnostics_format_EQ, "clang");
opts.ShowOptionNames = Args.hasFlag(OPT_fdiagnostics_show_option,
OPT_fno_diagnostics_show_option, true);
opts.UseColor = Args.hasFlag(OPT_Cc, OPT_INVALID, false);

Просмотреть файл

@ -0,0 +1,14 @@
// RUN: %dxc -T ps_6_0 %s -verify
// RUN: not %dxc -T ps_6_0 %s 2>&1 | FileCheck %s --check-prefix=CLANG
// RUN: not %dxc -T ps_6_0 %s -fdiagnostics-format=clang 2>&1 | FileCheck %s --check-prefix=CLANG
// RUN: not %dxc -T ps_6_0 %s -fdiagnostics-format=msvc 2>&1 | FileCheck %s --check-prefix=MSVC
// RUN: not %dxc -T ps_6_0 %s -fdiagnostics-format=msvc-fallback 2>&1 | FileCheck %s --check-prefix=MSVC
// RUN: not %dxc -T ps_6_0 %s -fdiagnostics-format=vi 2>&1 | FileCheck %s --check-prefix=VI
// RUN: not %dxc -T ps_6_0 %s -fdiagnostics-format=nonsense 2>&1 | FileCheck %s --check-prefixes=NONSENSE,CLANG
main() {} // expected-error{{HLSL requires a type specifier for all declarations}}
// NONSENSE: warning: invalid option nonsense to -fdiagnostics-format: supported values are clang, msvc, msvc-fallback, and vi
// VI: +9:1: error: HLSL requires a type specifier for all declarations
// MSVC: (9,1) : error: HLSL requires a type specifier for all declarations
// CLANG: :9:1: error: HLSL requires a type specifier for all declarations

Просмотреть файл

@ -1359,6 +1359,18 @@ public:
compiler.createDiagnostics(diagPrinter, false);
// don't output warning to stderr/file if "/no-warnings" is present.
compiler.getDiagnostics().setIgnoreAllWarnings(!Opts.OutputWarnings);
if (Opts.DiagnosticsFormat.equals_lower("msvc") ||
Opts.DiagnosticsFormat.equals_lower("msvc-fallback"))
compiler.getDiagnosticOpts().setFormat(DiagnosticOptions::MSVC);
else if (Opts.DiagnosticsFormat.equals_lower("vi"))
compiler.getDiagnosticOpts().setFormat(DiagnosticOptions::Vi);
else if (!Opts.DiagnosticsFormat.equals_lower("clang")) {
auto const ID = compiler.getDiagnostics().getCustomDiagID(
clang::DiagnosticsEngine::Warning,
"invalid option %0 to -fdiagnostics-format: supported values are "
"clang, msvc, msvc-fallback, and vi");
compiler.getDiagnostics().Report(ID) << Opts.DiagnosticsFormat;
}
compiler.createFileManager();
compiler.createSourceManager(compiler.getFileManager());
compiler.setTarget(