From f86c13921f6e2f586f4613ab3cb4a84c8693541f Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Mon, 12 Aug 2013 18:34:17 +0000 Subject: [PATCH] clang-cl: Expand warning about /TC and /TP override, and expand test git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188190 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 2 ++ lib/Driver/Driver.cpp | 30 +++++++++++--------- test/Driver/cl-inputs.c | 25 ++++++++++++---- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 866bb41dba..9222db8c33 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -153,6 +153,8 @@ def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">, def note_drv_command_failed_diag_msg : Note< "diagnostic msg: %0">; +def note_drv_t_option_is_global : + Note<"The last /TC or /TP option takes precedence over earlier instances">; def err_analyzer_config_no_value : Error< "analyzer-config option '%0' has a key but no value">; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 3fddc8fe6e..d6013f19ea 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1011,24 +1011,26 @@ void Driver::BuildInputs(const ToolChain &TC, const DerivedArgList &Args, types::ID InputType = types::TY_Nothing; Arg *InputTypeArg = 0; - // The /TC and /TP options set the input type to C or C++ globally. + // The last /TC or /TP option sets the input type to C or C++ globally. if (Arg *TCTP = Args.getLastArg(options::OPT__SLASH_TC, options::OPT__SLASH_TP)) { InputTypeArg = TCTP; - unsigned opposite; - - if (TCTP->getOption().matches(options::OPT__SLASH_TC)) { - InputType = types::TY_C; - opposite = options::OPT__SLASH_TP; - } else { - InputType = types::TY_CXX; - opposite = options::OPT__SLASH_TC; - } - - if (Arg *OppositeArg = Args.getLastArg(opposite)) { - Diag(clang::diag::warn_drv_overriding_t_option) - << OppositeArg->getSpelling() << InputTypeArg->getSpelling(); + InputType = TCTP->getOption().matches(options::OPT__SLASH_TC) + ? types::TY_C : types::TY_CXX; + + arg_iterator it = Args.filtered_begin(options::OPT__SLASH_TC, + options::OPT__SLASH_TP); + const arg_iterator ie = Args.filtered_end(); + Arg *Previous = *it++; + bool ShowNote = false; + while (it != ie) { + Diag(clang::diag::warn_drv_overriding_t_option) << Previous->getSpelling() + << (*it)->getSpelling(); + Previous = *it++; + ShowNote = true; } + if (ShowNote) + Diag(clang::diag::note_drv_t_option_is_global); // No driver mode exposes -x and /TC or /TP; we don't support mixing them. assert(!Args.hasArg(options::OPT_x) && "-x and /TC or /TP is not allowed"); diff --git a/test/Driver/cl-inputs.c b/test/Driver/cl-inputs.c index 1918e4cba9..79433edef7 100644 --- a/test/Driver/cl-inputs.c +++ b/test/Driver/cl-inputs.c @@ -6,17 +6,30 @@ // RUN: %clang_cl /TC -### -- %s 2>&1 | FileCheck -check-prefix=TC %s // TC: "-x" "c" +// TC-NOT: warning +// TC-NOT: note // RUN: %clang_cl /TP -### -- %s 2>&1 | FileCheck -check-prefix=TP %s // TP: "-x" "c++" +// TP-NOT: warning +// TP-NOT: note -// RUN: %clang_cl -### /Tc%s 2>&1 | FileCheck -check-prefix=Tc %s -// RUN: %clang_cl -### /TP /Tc%s 2>&1 | FileCheck -check-prefix=Tc %s +// RUN: %clang_cl -### /Tc%s /TP -- %s 2>&1 | FileCheck -check-prefix=Tc %s +// RUN: %clang_cl -### /TP /Tc%s -- %s 2>&1 | FileCheck -check-prefix=Tc %s // Tc: "-x" "c" +// Tc: "-x" "c++" +// Tc-NOT: warning +// Tc-NOT: note -// RUN: %clang_cl -### /Tp%s 2>&1 | FileCheck -check-prefix=Tp %s -// RUN: %clang_cl -### /TC /Tp%s 2>&1 | FileCheck -check-prefix=Tp %s +// RUN: %clang_cl -### /Tp%s /TC -- %s 2>&1 | FileCheck -check-prefix=Tp %s +// RUN: %clang_cl -### /TC /Tp%s -- %s 2>&1 | FileCheck -check-prefix=Tp %s // Tp: "-x" "c++" +// Tp: "-x" "c" +// Tp-NOT: warning +// Tp-NOT: note -// RUN: %clang_cl /TP /TC -### -- %s 2>&1 | FileCheck -check-prefix=WARN %s -// WARN: overriding '/TP' option with '/TC' +// RUN: %clang_cl /TP /TC /TP -### -- %s 2>&1 | FileCheck -check-prefix=WARN %s +// WARN: warning: overriding '/TP' option with '/TC' +// WARN: warning: overriding '/TC' option with '/TP' +// WARN: note: The last /TC or /TP option takes precedence over earlier instances +// WARN-NOT: note -- 2.50.1