[clang] ce8fa36 - [NFC][Driver] Change Multilib flag representation
Michael Platings via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 6 21:53:38 PDT 2023
Author: Michael Platings
Date: 2023-06-07T05:53:04+01:00
New Revision: ce8fa36e59e1995fde84730eeb460e06f42d7728
URL: https://github.com/llvm/llvm-project/commit/ce8fa36e59e1995fde84730eeb460e06f42d7728
DIFF: https://github.com/llvm/llvm-project/commit/ce8fa36e59e1995fde84730eeb460e06f42d7728.diff
LOG: [NFC][Driver] Change Multilib flag representation
This new representation means that a valid command line option may
potentially be used directly as a multilib flag without any translation.
To indicate that a flag is required not to be present, its first
character is replaced with '!', which is intended for consistency with
the logical not operator in many programming languages.
Reviewed By: simon_tatham
Differential Revision: https://reviews.llvm.org/D151438
Added:
Modified:
clang/include/clang/Driver/Multilib.h
clang/include/clang/Driver/MultilibBuilder.h
clang/lib/Driver/Multilib.cpp
clang/lib/Driver/MultilibBuilder.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/OHOS.cpp
clang/unittests/Driver/MultilibBuilderTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Multilib.h b/clang/include/clang/Driver/Multilib.h
index 9d6f1d23696b8..bf284e26f9dad 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -58,7 +58,7 @@ class Multilib {
const std::string &includeSuffix() const { return IncludeSuffix; }
/// Get the flags that indicate or contraindicate this multilib's use
- /// All elements begin with either '+' or '-'
+ /// All elements begin with either '-' or '!'
const flags_list &flags() const { return Flags; }
LLVM_DUMP_METHOD void dump() const;
diff --git a/clang/include/clang/Driver/MultilibBuilder.h b/clang/include/clang/Driver/MultilibBuilder.h
index 177c8104f917b..86f34592ba384 100644
--- a/clang/include/clang/Driver/MultilibBuilder.h
+++ b/clang/include/clang/Driver/MultilibBuilder.h
@@ -70,7 +70,7 @@ class MultilibBuilder {
MultilibBuilder &includeSuffix(StringRef S);
/// Get the flags that indicate or contraindicate this multilib's use
- /// All elements begin with either '+' or '-'
+ /// All elements begin with either '-' or '!'
const flags_list &flags() const { return Flags; }
flags_list &flags() { return Flags; }
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 06bab74898616..5336c9ec57ec9 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -49,7 +49,7 @@ void Multilib::print(raw_ostream &OS) const {
}
OS << ";";
for (StringRef Flag : Flags) {
- if (Flag.front() == '+')
+ if (Flag.front() == '-')
OS << "@" << Flag.substr(1);
}
}
diff --git a/clang/lib/Driver/MultilibBuilder.cpp b/clang/lib/Driver/MultilibBuilder.cpp
index 213f971f262f7..d2a3fcb3732f6 100644
--- a/clang/lib/Driver/MultilibBuilder.cpp
+++ b/clang/lib/Driver/MultilibBuilder.cpp
@@ -76,7 +76,7 @@ bool MultilibBuilder::isValid() const {
StringRef Flag(Flags[I]);
llvm::StringMap<int>::iterator SI = FlagSet.find(Flag.substr(1));
- assert(StringRef(Flag).front() == '+' || StringRef(Flag).front() == '-');
+ assert(StringRef(Flag).front() == '-' || StringRef(Flag).front() == '!');
if (SI == FlagSet.end())
FlagSet[Flag.substr(1)] = I;
@@ -97,10 +97,10 @@ Multilib MultilibBuilder::makeMultilib() const {
MultilibSetBuilder &MultilibSetBuilder::Maybe(const MultilibBuilder &M) {
MultilibBuilder Opposite;
- // Negate any '+' flags
+ // Negate positive flags
for (StringRef Flag : M.flags()) {
- if (Flag.front() == '+')
- Opposite.flags().push_back(("-" + Flag.substr(1)).str());
+ if (Flag.front() == '-')
+ Opposite.flags().push_back(("!" + Flag.substr(1)).str());
}
return Either(M, Opposite);
}
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 403b17d1b2d62..165b1f9ae1300 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1909,9 +1909,9 @@ void tools::addMultilibFlag(bool Enabled, const StringRef Flag,
Multilib::flags_list &Flags) {
assert(Flag.front() == '-');
if (Enabled) {
- Flags.push_back(("+" + Flag.substr(1)).str());
- } else {
Flags.push_back(Flag.str());
+ } else {
+ Flags.push_back(("!" + Flag.substr(1)).str());
}
}
diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp
index 833204e1dc535..0fdcafe898d70 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -40,15 +40,15 @@ static bool findOHOSMuslMultilibs(const Multilib::flags_list &Flags,
// -mfloat-abi=soft -mfloat-abi=softfp -mfloat-abi=hard
// -mfpu=neon-vfpv4
Multilibs.push_back(
- Multilib("/a7_soft", {}, {}, {"+mcpu=cortex-a7", "+mfloat-abi=soft"}));
+ Multilib("/a7_soft", {}, {}, {"-mcpu=cortex-a7", "-mfloat-abi=soft"}));
Multilibs.push_back(
Multilib("/a7_softfp_neon-vfpv4", {}, {},
- {"+mcpu=cortex-a7", "+mfloat-abi=softfp", "+mfpu=neon-vfpv4"}));
+ {"-mcpu=cortex-a7", "-mfloat-abi=softfp", "-mfpu=neon-vfpv4"}));
Multilibs.push_back(
Multilib("/a7_hard_neon-vfpv4", {}, {},
- {"+mcpu=cortex-a7", "+mfloat-abi=hard", "+mfpu=neon-vfpv4"}));
+ {"-mcpu=cortex-a7", "-mfloat-abi=hard", "-mfpu=neon-vfpv4"}));
if (Multilibs.select(Flags, Result.SelectedMultilib)) {
Result.Multilibs = Multilibs;
diff --git a/clang/unittests/Driver/MultilibBuilderTest.cpp b/clang/unittests/Driver/MultilibBuilderTest.cpp
index d88011cbb794e..ab3482870158e 100644
--- a/clang/unittests/Driver/MultilibBuilderTest.cpp
+++ b/clang/unittests/Driver/MultilibBuilderTest.cpp
@@ -58,7 +58,7 @@ TEST(MultilibBuilderTest, Construction3) {
MultilibBuilder().flag(true, "-f1").flag(true, "-f2").flag(false, "-f3");
for (const std::string &A : M.flags()) {
ASSERT_TRUE(llvm::StringSwitch<bool>(A)
- .Cases("+f1", "+f2", "-f3", true)
+ .Cases("-f1", "-f2", "!f3", true)
.Default(false));
}
}
@@ -71,9 +71,9 @@ TEST(MultilibBuilderTest, SetConstruction1) {
ASSERT_TRUE(MS.size() == 2);
for (MultilibSet::const_iterator I = MS.begin(), E = MS.end(); I != E; ++I) {
if (I->gccSuffix() == "/64")
- ASSERT_TRUE(*I->flags().begin() == "+m64");
- else if (I->gccSuffix() == "")
ASSERT_TRUE(*I->flags().begin() == "-m64");
+ else if (I->gccSuffix() == "")
+ ASSERT_TRUE(*I->flags().begin() == "!m64");
else
FAIL() << "Unrecognized gccSufix: " << I->gccSuffix();
}
@@ -92,19 +92,19 @@ TEST(MultilibBuilderTest, SetConstruction2) {
.Default(false))
<< "Multilib " << *I << " wasn't expected";
ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
- .Case("", is_contained(I->flags(), "-sof"))
- .Case("/sof", is_contained(I->flags(), "+sof"))
- .Case("/el", is_contained(I->flags(), "-sof"))
- .Case("/sof/el", is_contained(I->flags(), "+sof"))
+ .Case("", is_contained(I->flags(), "!sof"))
+ .Case("/sof", is_contained(I->flags(), "-sof"))
+ .Case("/el", is_contained(I->flags(), "!sof"))
+ .Case("/sof/el", is_contained(I->flags(), "-sof"))
.Default(false))
- << "Multilib " << *I << " didn't have the appropriate {+,-}sof flag";
+ << "Multilib " << *I << " didn't have the appropriate {-,!}sof flag";
ASSERT_TRUE(llvm::StringSwitch<bool>(I->gccSuffix())
- .Case("", is_contained(I->flags(), "-EL"))
- .Case("/sof", is_contained(I->flags(), "-EL"))
- .Case("/el", is_contained(I->flags(), "+EL"))
- .Case("/sof/el", is_contained(I->flags(), "+EL"))
+ .Case("", is_contained(I->flags(), "!EL"))
+ .Case("/sof", is_contained(I->flags(), "!EL"))
+ .Case("/el", is_contained(I->flags(), "-EL"))
+ .Case("/sof/el", is_contained(I->flags(), "-EL"))
.Default(false))
- << "Multilib " << *I << " didn't have the appropriate {+,-}EL flag";
+ << "Multilib " << *I << " didn't have the appropriate {-,!}EL flag";
}
}
@@ -160,17 +160,17 @@ TEST(MultilibBuilderTest, SetSelection1) {
.Maybe(MultilibBuilder("64").flag(true, "-m64"))
.makeMultilibSet();
- Multilib::flags_list FlagM64 = {"+m64"};
+ Multilib::flags_list FlagM64 = {"-m64"};
Multilib SelectionM64;
ASSERT_TRUE(MS1.select(FlagM64, SelectionM64))
- << "Flag set was {\"+m64\"}, but selection not found";
+ << "Flag set was {\"-m64\"}, but selection not found";
ASSERT_TRUE(SelectionM64.gccSuffix() == "/64")
<< "Selection picked " << SelectionM64 << " which was not expected";
- Multilib::flags_list FlagNoM64 = {"-m64"};
+ Multilib::flags_list FlagNoM64 = {"!m64"};
Multilib SelectionNoM64;
ASSERT_TRUE(MS1.select(FlagNoM64, SelectionNoM64))
- << "Flag set was {\"-m64\"}, but selection not found";
+ << "Flag set was {\"!m64\"}, but selection not found";
ASSERT_TRUE(SelectionNoM64.gccSuffix() == "")
<< "Selection picked " << SelectionNoM64 << " which was not expected";
}
@@ -186,19 +186,19 @@ TEST(MultilibBuilderTest, SetSelection2) {
bool IsSF = I & 0x2;
Multilib::flags_list Flags;
if (IsEL)
- Flags.push_back("+EL");
- else
Flags.push_back("-EL");
+ else
+ Flags.push_back("!EL");
if (IsSF)
- Flags.push_back("+SF");
- else
Flags.push_back("-SF");
+ else
+ Flags.push_back("!SF");
Multilib Selection;
ASSERT_TRUE(MS2.select(Flags, Selection))
- << "Selection failed for " << (IsEL ? "+EL" : "-EL") << " "
- << (IsSF ? "+SF" : "-SF");
+ << "Selection failed for " << (IsEL ? "-EL" : "!EL") << " "
+ << (IsSF ? "-SF" : "!SF");
std::string Suffix;
if (IsEL)
More information about the cfe-commits
mailing list