From 7f73489c3f35814192c85c3919d5847a66c8e071 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 20 Dec 2010 22:45:09 +0000 Subject: [PATCH] Fix PR8639 by making the "argument unused during compilation" less agressive. Now we don't warn if an argument is not used because it is shadowed by a subsequent argument. llvm-svn: 122281 --- clang/lib/Driver/ArgList.cpp | 35 ++++++++++++++++------------------- clang/lib/Driver/Tools.cpp | 3 --- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/clang/lib/Driver/ArgList.cpp b/clang/lib/Driver/ArgList.cpp index e26318863db7..f52c25ac101b 100644 --- a/clang/lib/Driver/ArgList.cpp +++ b/clang/lib/Driver/ArgList.cpp @@ -55,62 +55,59 @@ Arg *ArgList::getLastArgNoClaim(OptSpecifier Id) const { } Arg *ArgList::getLastArg(OptSpecifier Id) const { - Arg *A = getLastArgNoClaim(Id); - if (A) - A->claim(); - return A; + Arg *Res = 0; + for (const_iterator it = begin(), ie = end(); it != ie; ++it) { + if ((*it)->getOption().matches(Id)) { + Res = *it; + Res->claim(); + } + } + + return Res; } Arg *ArgList::getLastArg(OptSpecifier Id0, OptSpecifier Id1) const { Arg *Res = 0; - for (const_reverse_iterator it = rbegin(), ie = rend(); it != ie; ++it) { + for (const_iterator it = begin(), ie = end(); it != ie; ++it) { if ((*it)->getOption().matches(Id0) || (*it)->getOption().matches(Id1)) { Res = *it; - break; + Res->claim(); + } } - if (Res) - Res->claim(); - return Res; } Arg *ArgList::getLastArg(OptSpecifier Id0, OptSpecifier Id1, OptSpecifier Id2) const { Arg *Res = 0; - for (const_reverse_iterator it = rbegin(), ie = rend(); it != ie; ++it) { + for (const_iterator it = begin(), ie = end(); it != ie; ++it) { if ((*it)->getOption().matches(Id0) || (*it)->getOption().matches(Id1) || (*it)->getOption().matches(Id2)) { Res = *it; - break; + Res->claim(); } } - if (Res) - Res->claim(); - return Res; } Arg *ArgList::getLastArg(OptSpecifier Id0, OptSpecifier Id1, OptSpecifier Id2, OptSpecifier Id3) const { Arg *Res = 0; - for (const_reverse_iterator it = rbegin(), ie = rend(); it != ie; ++it) { + for (const_iterator it = begin(), ie = end(); it != ie; ++it) { if ((*it)->getOption().matches(Id0) || (*it)->getOption().matches(Id1) || (*it)->getOption().matches(Id2) || (*it)->getOption().matches(Id3)) { Res = *it; - break; + Res->claim(); } } - if (Res) - Res->claim(); - return Res; } diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 4e23ed6dda43..9df276d9c24a 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -1147,9 +1147,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, A->render(Args, CmdArgs); } - // Silence warning for "clang -O2 -O0 -c foo.c -o foo.o" - Args.ClaimAllArgs(options::OPT_O_Group); - Args.AddAllArgs(CmdArgs, options::OPT_W_Group); Args.AddLastArg(CmdArgs, options::OPT_pedantic); Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors);