From: Rafael Espindola Date: Wed, 21 Aug 2013 17:34:32 +0000 (+0000) Subject: Move the logic for selecting the last feature in the command line to the driver. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc1e54587bf1ed18abadc566423777ddb3be78ac;p=clang Move the logic for selecting the last feature in the command line to the driver. This is a partial revert of r188817 now that the driver handles -target-feature in a single place. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188910 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index e2898cc86b..22a7bda1aa 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -5503,26 +5503,10 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, llvm::StringMap Features; Target->getDefaultFeatures(Features); - // Fist the last of each option; - llvm::StringMap LastOpt; - for (unsigned I = 0, N = Opts->FeaturesAsWritten.size(); - I < N; ++I) { - const char *Name = Opts->FeaturesAsWritten[I].c_str() + 1; - LastOpt[Name] = I; - } - // Apply the user specified deltas. for (unsigned I = 0, N = Opts->FeaturesAsWritten.size(); I < N; ++I) { const char *Name = Opts->FeaturesAsWritten[I].c_str(); - - // If this option was overridden, ignore it. - llvm::StringMap::iterator LastI = LastOpt.find(Name + 1); - assert(LastI != LastOpt.end()); - unsigned Last = LastI->second; - if (Last != I) - continue; - // Apply the feature via the target. bool Enabled = Name[0] == '+'; Target->setFeatureEnabled(Features, Name + 1, Enabled); diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 7e66caa6c3..746300000f 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1431,11 +1431,26 @@ static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple, getX86TargetFeatures(Args, Features); break; } - for (std::vector::iterator I = Features.begin(), - E = Features.end(); - I != E; ++I) { + + // Find the last of each feature. + llvm::StringMap LastOpt; + for (unsigned I = 0, N = Features.size(); I < N; ++I) { + const char *Name = Features[I]; + assert(Name[0] == '-' || Name[0] == '+'); + LastOpt[Name + 1] = I; + } + + for (unsigned I = 0, N = Features.size(); I < N; ++I) { + // If this feature was overridden, ignore it. + const char *Name = Features[I]; + llvm::StringMap::iterator LastI = LastOpt.find(Name + 1); + assert(LastI != LastOpt.end()); + unsigned Last = LastI->second; + if (Last != I) + continue; + CmdArgs.push_back("-target-feature"); - CmdArgs.push_back(*I); + CmdArgs.push_back(Name); } } diff --git a/test/Driver/x86_features.c b/test/Driver/x86_features.c index 5470bbcdea..6fbf5ca4ae 100644 --- a/test/Driver/x86_features.c +++ b/test/Driver/x86_features.c @@ -1,2 +1,3 @@ // RUN: %clang -target i386-unknown-unknown -### -S %s -msse -msse4 -mno-sse -mno-mmx -msse 2>&1 | FileCheck %s -// CHECK: "pentium4" "-target-feature" "+sse" "-target-feature" "+sse4" "-target-feature" "-sse" "-target-feature" "-mmx" "-target-feature" "+sse" +// CHECK: "pentium4" "-target-feature" "+sse4" "-target-feature" "-mmx" "-target-feature" "+sse" +// Note that we filter out all but the last -m(no)sse.