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

This commit is contained in:
Xiang Li 2017-08-11 14:55:45 -07:00 коммит произвёл GitHub
Родитель 2cf2a5cc39
Коммит 8c4f2db67e
7 изменённых файлов: 39 добавлений и 0 удалений

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

@ -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

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

@ -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.

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

@ -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()) {

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

@ -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),

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

@ -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)

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

@ -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;
}

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

@ -752,6 +752,8 @@ public:
PPOpts.addMacroDef(defines[i]);
}
PPOpts.IgnoreLineDirectives = Opts.IgnoreLineDirectives;
// Pick additional arguments.
clang::HeaderSearchOptions &HSOpts = compiler.getHeaderSearchOpts();
HSOpts.UseBuiltinIncludes = 0;