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:
Родитель
696a13a2a8
Коммит
f0970beaf8
|
@ -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(
|
||||
|
|
Загрузка…
Ссылка в новой задаче