forked from OSchip/llvm-project
[MSVC Compat] Only warn for unknown clang-cl arguments
Summary: MSVC's driver accepts all unknown arguments but warns about them. clang by default rejects all unknown arguments. This causes issues specifically with build systems such as autoconf which liberally pass things such as $LDFLAGS to the compiler and expect everything to work. This patch teaches clang-cl to ignore unknown driver arguments. Reviewers: rnk Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D16511 llvm-svn: 258720
This commit is contained in:
parent
580ccca192
commit
d851833c9a
|
@ -2024,8 +2024,9 @@ with a warning. For example:
|
|||
|
||||
To suppress warnings about unused arguments, use the ``-Qunused-arguments`` option.
|
||||
|
||||
Options that are not known to clang-cl will cause errors. If they are spelled with a
|
||||
leading ``/``, they will be mistaken for a filename:
|
||||
Options that are not known to clang-cl will be ignored by default. Use the
|
||||
``-Werror=unknown-argument`` option in order to treat them as errors. If these
|
||||
options are spelled with a leading ``/``, they will be mistaken for a filename:
|
||||
|
||||
::
|
||||
|
||||
|
|
|
@ -93,6 +93,9 @@ def err_target_unsupported_arch
|
|||
def err_drv_I_dash_not_supported : Error<
|
||||
"'%0' not supported, please use -iquote instead">;
|
||||
def err_drv_unknown_argument : Error<"unknown argument: '%0'">;
|
||||
def warn_drv_unknown_argument_clang_cl : Warning<
|
||||
"unknown argument ignored in clang-cl: '%0'">,
|
||||
InGroup<UnknownArgument>;
|
||||
def err_drv_invalid_value : Error<"invalid value '%1' in '%0'">;
|
||||
def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
|
||||
def err_drv_invalid_remap_file : Error<
|
||||
|
|
|
@ -848,3 +848,5 @@ def FutureCompat : DiagGroup<"future-compat">;
|
|||
def InvalidOrNonExistentDirectory : DiagGroup<"invalid-or-nonexistent-directory">;
|
||||
|
||||
def OptionIgnored : DiagGroup<"option-ignored">;
|
||||
|
||||
def UnknownArgument : DiagGroup<"unknown-argument">;
|
||||
|
|
|
@ -146,7 +146,9 @@ InputArgList Driver::ParseArgStrings(ArrayRef<const char *> ArgStrings) {
|
|||
}
|
||||
|
||||
for (const Arg *A : Args.filtered(options::OPT_UNKNOWN))
|
||||
Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
|
||||
Diags.Report(IsCLMode() ? diag::warn_drv_unknown_argument_clang_cl :
|
||||
diag::err_drv_unknown_argument)
|
||||
<< A->getAsString(Args);
|
||||
|
||||
return Args;
|
||||
}
|
||||
|
@ -1710,8 +1712,11 @@ void Driver::BuildJobs(Compilation &C) const {
|
|||
continue;
|
||||
}
|
||||
|
||||
Diag(clang::diag::warn_drv_unused_argument)
|
||||
<< A->getAsString(C.getArgs());
|
||||
// In clang-cl, don't mention unknown arguments here since they have
|
||||
// already been warned about.
|
||||
if (!IsCLMode() || !A->getOption().matches(options::OPT_UNKNOWN))
|
||||
Diag(clang::diag::warn_drv_unused_argument)
|
||||
<< A->getAsString(C.getArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9708,6 +9708,10 @@ std::unique_ptr<Command> visualstudio::Compiler::GetCommand(
|
|||
options::OPT__SLASH_MT, options::OPT__SLASH_MTd))
|
||||
A->render(Args, CmdArgs);
|
||||
|
||||
// Pass through all unknown arguments so that the fallback command can see
|
||||
// them too.
|
||||
Args.AddAllArgs(CmdArgs, options::OPT_UNKNOWN);
|
||||
|
||||
// Input filename.
|
||||
assert(Inputs.size() == 1);
|
||||
const InputInfo &II = Inputs[0];
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
// RUN: %clang_cl --target=i686-pc-win32 /fallback /Dfoo=bar /Ubaz /Ifoo /O0 /Ox /GR /GR- /Gy /Gy- \
|
||||
// RUN: /Gw /Gw- /LD /LDd /EHs /EHs- /Zl /MD /MDd /MTd /MT /FImyheader.h /Zi \
|
||||
// RUN: -garbage -moregarbage \
|
||||
// RUN: -### -- %s 2>&1 \
|
||||
// RUN: | FileCheck %s
|
||||
// CHECK: "-fdiagnostics-format" "msvc-fallback"
|
||||
|
@ -31,6 +32,8 @@
|
|||
// CHECK: "/EHs-"
|
||||
// CHECK: "/Zl"
|
||||
// CHECK: "/MT"
|
||||
// CHECK: "-garbage"
|
||||
// CHECK: "-moregarbage"
|
||||
// CHECK: "/Tc" "{{.*cl-fallback.c}}"
|
||||
// CHECK: "/Fo{{.*cl-fallback.*.obj}}"
|
||||
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
// RUN: not %clang %s -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option 2>&1 | \
|
||||
// RUN: FileCheck %s
|
||||
// RUN: %clang_cl -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -- %s 2>&1 | \
|
||||
// RUN: FileCheck %s --check-prefix=CL
|
||||
// RUN: not %clang_cl -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Werror=unknown-argument -- %s 2>&1 | \
|
||||
// RUN: FileCheck %s --check-prefix=CL
|
||||
// RUN: %clang_cl -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Wno-unknown-argument -- %s 2>&1 | \
|
||||
// RUN: FileCheck %s --check-prefix=SILENT --allow-empty
|
||||
|
||||
// CHECK: unknown argument: '-cake-is-lie'
|
||||
// CHECK: unknown argument: '-%0'
|
||||
|
@ -8,6 +14,15 @@
|
|||
// CHECK: unknown argument: '-munknown-to-clang-option'
|
||||
// CHECK: unknown argument: '-print-stats'
|
||||
// CHECK: unknown argument: '-funknown-to-clang-option'
|
||||
// CL: unknown argument ignored in clang-cl: '-cake-is-lie'
|
||||
// CL: unknown argument ignored in clang-cl: '-%0'
|
||||
// CL: unknown argument ignored in clang-cl: '-%d'
|
||||
// CL: unknown argument ignored in clang-cl: '-HHHH'
|
||||
// CL: unknown argument ignored in clang-cl: '-munknown-to-clang-option'
|
||||
// CL: unknown argument ignored in clang-cl: '-print-stats'
|
||||
// CL: unknown argument ignored in clang-cl: '-funknown-to-clang-option'
|
||||
// SILENT-NOT: error
|
||||
// SILENT-NOT: warning
|
||||
|
||||
|
||||
// RUN: %clang -S %s -o %t.s -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
// doesn't litter the user's system with preprocessed output.
|
||||
|
||||
// RUN: rm -f %t
|
||||
// RUN: %clang -Wx-unknown-warning -Wall -fsyntax-only --serialize-diagnostics %t.diag %s
|
||||
// RUN: %clang -Wx-typoed-warning -Wall -fsyntax-only --serialize-diagnostics %t.diag %s
|
||||
// RUN: c-index-test -read-diagnostics %t.diag 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: warning: unknown warning option '-Wx-unknown-warning' [-Wunknown-warning-option] []
|
||||
// CHECK: warning: unknown warning option '-Wx-typoed-warning' [-Wunknown-warning-option] []
|
||||
|
||||
// CHECK: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized]
|
||||
// CHECK: note: initialize the variable 'voodoo' to silence this warning []
|
||||
|
|
Loading…
Reference in New Issue