2
0
Эх сурвалжийг харах

Add -NoLineDirectives to ignore #line. (#550)

Xiang Li 8 жил өмнө
parent
commit
8c4f2db67e

+ 1 - 0
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

+ 2 - 0
include/dxc/Support/HLSLOptions.td

@@ -231,6 +231,8 @@ def rootsig_define : Separate<["-", "/"], "rootsig-define">, Group<hlslcomp_Grou
   HelpText<"Read root signature from a #define">;
 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<hlslcomp_Group>;
+
 //////////////////////////////////////////////////////////////////////////////
 // fxc-based flags that don't match those previously defined.
 

+ 2 - 0
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()) {

+ 6 - 0
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),

+ 6 - 0
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)

+ 20 - 0
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<float2> buf0;
+RWStructuredBuffer<float2> buf1;
+
+#line 0 "test2.h"
+
+void Store(bool bBufX, float2 v, uint idx) {
+  RWStructuredBuffer<float2> buf = bBufX ? buf0: buf1;
+  buf[idx] = v;
+}

+ 2 - 0
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;