diff --git a/include/dxc/Support/HLSLOptions.h b/include/dxc/Support/HLSLOptions.h index 984e1accf..81d9899f6 100644 --- a/include/dxc/Support/HLSLOptions.h +++ b/include/dxc/Support/HLSLOptions.h @@ -121,6 +121,7 @@ public: bool DumpBin; // OPT_dumpbin bool WarningAsError; // OPT__SLASH_WX bool IEEEStrict; // OPT_Gis + bool IgnoreLineDirectives; // OPT_ignore_line_directives bool DefaultColMajor; // OPT_Zpc bool DefaultRowMajor; // OPT_Zpr bool DisableValidation; // OPT_VD diff --git a/include/dxc/Support/HLSLOptions.td b/include/dxc/Support/HLSLOptions.td index 602360ac4..22aa538d1 100644 --- a/include/dxc/Support/HLSLOptions.td +++ b/include/dxc/Support/HLSLOptions.td @@ -231,6 +231,8 @@ def rootsig_define : Separate<["-", "/"], "rootsig-define">, Group; def no_min_precision: Flag<["-", "/"], "no-min-precision">, Flags<[CoreOption, DriverOption, HelpHidden]>, HelpText<"Do not use min precision but use strict precision types.">; +def ignore_line_directives : Flag<["-", "/"], "ignore-line-directives">, HelpText<"Ignore line directives">, Flags<[CoreOption]>, Group; + ////////////////////////////////////////////////////////////////////////////// // fxc-based flags that don't match those previously defined. diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index e1e79f282..8a13dd701 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -300,6 +300,8 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude, opts.IEEEStrict = Args.hasFlag(OPT_Gis, OPT_INVALID, false); + opts.IgnoreLineDirectives = Args.hasFlag(OPT_ignore_line_directives, OPT_INVALID, false); + opts.FPDenormalMode = Args.getLastArgValue(OPT_denorm); // Check if a given denormalized value is valid if (!opts.FPDenormalMode.empty()) { diff --git a/tools/clang/include/clang/Lex/PreprocessorOptions.h b/tools/clang/include/clang/Lex/PreprocessorOptions.h index 963d95d7f..19957180e 100644 --- a/tools/clang/include/clang/Lex/PreprocessorOptions.h +++ b/tools/clang/include/clang/Lex/PreprocessorOptions.h @@ -55,6 +55,11 @@ public: /// definitions and expansions. unsigned DetailedRecord : 1; + // HLSL Change Begin - ignore line directives. + /// \brief Whether we should ignore #line directives. + unsigned IgnoreLineDirectives : 1; + // HLSL Change End + /// The implicit PCH included at the start of the translation unit, or empty. std::string ImplicitPCHInclude; @@ -141,6 +146,7 @@ public: public: PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), + IgnoreLineDirectives(false), // HLSL Change - ignore line directives. DisablePCHValidation(false), AllowPCHWithCompilerErrors(false), DumpDeserializedPCHDecls(false), diff --git a/tools/clang/lib/Lex/PPDirectives.cpp b/tools/clang/lib/Lex/PPDirectives.cpp index 8f0373653..08af04e9c 100644 --- a/tools/clang/lib/Lex/PPDirectives.cpp +++ b/tools/clang/lib/Lex/PPDirectives.cpp @@ -27,6 +27,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Path.h" #include "llvm/Support/SaveAndRestore.h" +#include "clang/Lex/PreprocessorOptions.h" // HLSL Change - ignore line directives. using namespace clang; //===----------------------------------------------------------------------===// @@ -1052,6 +1053,11 @@ void Preprocessor::HandleLineDirective(Token &Tok) { CheckEndOfDirective("line", true); } + // HLSL Change Begin - ignore line directives. + if (PPOpts->IgnoreLineDirectives) + return; + // HLSL Change End + SourceMgr.AddLineNote(DigitTok.getLocation(), LineNo, FilenameID); if (Callbacks) diff --git a/tools/clang/test/CodeGenHLSL/shader-compat-suite/ignore_line_directives.hlsl b/tools/clang/test/CodeGenHLSL/shader-compat-suite/ignore_line_directives.hlsl new file mode 100644 index 000000000..2da5054a8 --- /dev/null +++ b/tools/clang/test/CodeGenHLSL/shader-compat-suite/ignore_line_directives.hlsl @@ -0,0 +1,20 @@ +// RUN: %dxc -T lib_6_1 -Zi -ignore-line-directives %s | FileCheck %s + +// Make sure only 1 DIFile exist in debug info when NoLineDirectives is enabled. +// CHECK: !DIFile +// CHECK-NOT: !DIFile +// CHECK: ignore_line_directives.hlsl" +// CHECK: ignore_line_directives.hlsl"} +// CHECK-NOT: !DIFile + +#line 0 "test.h" + +RWStructuredBuffer buf0; +RWStructuredBuffer buf1; + +#line 0 "test2.h" + +void Store(bool bBufX, float2 v, uint idx) { + RWStructuredBuffer buf = bBufX ? buf0: buf1; + buf[idx] = v; +} \ No newline at end of file diff --git a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp index 1b0bbf4ed..15c81a2d5 100644 --- a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp +++ b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp @@ -752,6 +752,8 @@ public: PPOpts.addMacroDef(defines[i]); } + PPOpts.IgnoreLineDirectives = Opts.IgnoreLineDirectives; + // Pick additional arguments. clang::HeaderSearchOptions &HSOpts = compiler.getHeaderSearchOpts(); HSOpts.UseBuiltinIncludes = 0;