diff --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp --- a/clang-tools-extra/clangd/CompileCommands.cpp +++ b/clang-tools-extra/clangd/CompileCommands.cpp @@ -423,6 +423,8 @@ if (!Opt.hasFlag(driver::options::NoDriverOption)) { if (Opt.hasFlag(driver::options::CLOption)) { Result |= DM_CL; + } else if (Opt.hasFlag(driver::options::CLDXCOption)) { + Result |= DM_CL; } else { Result |= DM_GCC; if (Opt.hasFlag(driver::options::CoreOption)) { diff --git a/clang/include/clang/Driver/Options.h b/clang/include/clang/Driver/Options.h --- a/clang/include/clang/Driver/Options.h +++ b/clang/include/clang/Driver/Options.h @@ -36,7 +36,8 @@ FC1Option = (1 << 15), FlangOnlyOption = (1 << 16), DXCOption = (1 << 17), - Ignored = (1 << 18), + CLDXCOption = (1 << 18), + Ignored = (1 << 19), }; enum ID { diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -53,6 +53,10 @@ // are made available when the driver is running in DXC compatibility mode. def DXCOption : OptionFlag; +// CLDXCOption - This is a cl.exe/dxc.exe compatibility option. Options with this flag +// are made available when the driver is running in CL/DXC compatibility mode. +def CLDXCOption : OptionFlag; + // NoDriverOption - This option should not be accepted by the driver. def NoDriverOption : OptionFlag; @@ -6355,7 +6359,7 @@ // clang-cl Options //===----------------------------------------------------------------------===// -def cl_Group : OptionGroup<"">, Flags<[CLOption]>, +def cl_Group : OptionGroup<"">, Flags<[CLDXCOption]>, HelpText<"CL.EXE COMPATIBILITY OPTIONS">; def cl_compile_Group : OptionGroup<"">, @@ -6385,6 +6389,9 @@ class CLJoinedOrSeparate : Option<["/", "-"], name, KIND_JOINED_OR_SEPARATE>, Group, Flags<[CLOption, NoXarchOption]>; +class CLDXCJoinedOrSeparate : Option<["/", "-"], name, + KIND_JOINED_OR_SEPARATE>, Group, Flags<[CLDXCOption, NoXarchOption]>; + class CLCompileJoinedOrSeparate : Option<["/", "-"], name, KIND_JOINED_OR_SEPARATE>, Group, Flags<[CLOption, NoXarchOption]>; @@ -6462,7 +6469,7 @@ def _SLASH_HELP : CLFlag<"HELP">, Alias; def _SLASH_hotpatch : CLFlag<"hotpatch">, Alias, HelpText<"Create hotpatchable image">; -def _SLASH_I : CLJoinedOrSeparate<"I">, +def _SLASH_I : CLDXCJoinedOrSeparate<"I">, HelpText<"Add directory to include search path">, MetaVarName<"">, Alias; def _SLASH_J : CLFlag<"J">, HelpText<"Make char type unsigned">, diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -6262,6 +6262,7 @@ if (IsClCompatMode) { // Include CL and Core options. IncludedFlagsBitmask |= options::CLOption; + IncludedFlagsBitmask |= options::CLDXCOption; IncludedFlagsBitmask |= options::CoreOption; } else { ExcludedFlagsBitmask |= options::CLOption; @@ -6269,10 +6270,14 @@ if (IsDXCMode()) { // Include DXC and Core options. IncludedFlagsBitmask |= options::DXCOption; + IncludedFlagsBitmask |= options::CLDXCOption; IncludedFlagsBitmask |= options::CoreOption; } else { ExcludedFlagsBitmask |= options::DXCOption; } + if (!IsClCompatMode && !IsDXCMode()) + ExcludedFlagsBitmask |= options::CLDXCOption; + return std::make_pair(IncludedFlagsBitmask, ExcludedFlagsBitmask); } 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 @@ -3511,6 +3511,7 @@ types::ID InputType) { const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version, options::OPT_D, + options::OPT_I, options::OPT_S, options::OPT_emit_llvm, options::OPT_disable_llvm_passes, diff --git a/clang/test/Driver/dxc_I.hlsl b/clang/test/Driver/dxc_I.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/Driver/dxc_I.hlsl @@ -0,0 +1,4 @@ +// RUN: %clang_dxc -I test -### %s 2>&1 | FileCheck %s + +// Make sure -I send to cc1. +// CHECK:"-I" "test"