diff --git a/clang/include/clang/Driver/Types.h b/clang/include/clang/Driver/Types.h --- a/clang/include/clang/Driver/Types.h +++ b/clang/include/clang/Driver/Types.h @@ -95,6 +95,9 @@ /// isOpenCL - Is this an "OpenCL" input. bool isOpenCL(ID Id); + /// isHLSL - Is this an HLSL input. + bool isHLSL(ID Id); + /// isSrcFile - Is this a source file, i.e. something that still has to be /// preprocessed. The logic behind this is the same that decides if the first /// compilation phase is a preprocessing one. diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3529,12 +3529,14 @@ options::OPT_disable_llvm_passes, options::OPT_fnative_half_type, options::OPT_hlsl_entrypoint}; - + if (!types::isHLSL(InputType)) + return; for (const auto &Arg : ForwardedArguments) if (const auto *A = Args.getLastArg(Arg)) A->renderAsInput(Args, CmdArgs); // Add the default headers if dxc_no_stdinc is not set. - if (!Args.hasArg(options::OPT_dxc_no_stdinc)) + if (!Args.hasArg(options::OPT_dxc_no_stdinc) && + !Args.hasArg(options::OPT_nostdinc)) CmdArgs.push_back("-finclude-default-header"); } @@ -6389,8 +6391,7 @@ RenderOpenCLOptions(Args, CmdArgs, InputType); // Forward hlsl options to -cc1 - if (C.getDriver().IsDXCMode()) - RenderHLSLOptions(Args, CmdArgs, InputType); + RenderHLSLOptions(Args, CmdArgs, InputType); if (IsHIP) { if (Args.hasFlag(options::OPT_fhip_new_launch_api, diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp --- a/clang/lib/Driver/Types.cpp +++ b/clang/lib/Driver/Types.cpp @@ -286,6 +286,8 @@ } } +bool types::isHLSL(ID Id) { return Id == TY_HLSL; } + bool types::isSrcFile(ID Id) { return Id != TY_Object && getPreprocessedType(Id) != TY_INVALID; } diff --git a/clang/test/Driver/hlsl_no_stdinc.hlsl b/clang/test/Driver/hlsl_no_stdinc.hlsl --- a/clang/test/Driver/hlsl_no_stdinc.hlsl +++ b/clang/test/Driver/hlsl_no_stdinc.hlsl @@ -1,5 +1,7 @@ // RUN: %clang_dxc -Tlib_6_7 -fcgl -Fo - %s -### 2>&1 | FileCheck %s --check-prefix=STDINC +// RUN: %clang -target dxil-pc-shadermodel6.3-library -o - %s -### 2>&1 | FileCheck %s --check-prefix=STDINC // RUN: %clang_dxc -Tlib_6_7 -hlsl-no-stdinc -fcgl -Fo - %s -### 2>&1 | FileCheck %s --check-prefix=NOSTDINC +// RUN: %clang -target dxil-pc-shadermodel6.3-library -nostdinc -o - %s -### 2>&1 | FileCheck %s --check-prefix=NOSTDINC // RUN: %clang -cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s -verify