Skip to content

Commit 81d77bf

Browse files
committed
[Clang][Driver] Skip empty strings in getAArch64MultilibFlags
In a multilib setting, if you compile with a command line such as `clang --target=aarch64-none-elf -march=armv8.9-a+rcpc3`, `getAArch64MultilibFlags` returns an ill-formed string containing two consecutive `+` signs, of the form `...+rcpc++rcpc3+...`, causing later stages of multilib selection to get confused. The `++` arises from the entry in `AArch64::Extensions` for the SubtargetFeature `rcpc-immo`, which is a dependency of the `rcpc3` SubtargetFeature, but doesn't have an _extension_ name for the purposes of the `-march=foo+bar` option. So its `UserVisibleName` field is the empty string. To fix this, I've excluded extensions from consideration in `getAArch64MultilibFlags` if they have an empty `UserVisibleName`. Since the input to this function is not derived from a completely general set of SubtargetFeatures, but from a set that has only just been converted _from_ a clang driver command line, the only extensions skipped by this check should be cases like this one, where the anonymous extension was only included because it was a dependency of one mentioned explicitly. I've also made the analogous change in `getARMMultilibFlags`. I don't think it's necessary right now, because the architecture extensions for ARM (defined in `ARMTargetParser.def` rather than Tablegen) don't include any anonymous ones. But it seems sensible to add the check anyway, in case future refactoring introduces anonymous array elements in the same way that AArch64 did, and also in case someone writes a function for another platform by using either of these as example code.
1 parent 18b575d commit 81d77bf

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,13 @@ static void getAArch64MultilibFlags(const Driver &D,
195195
UnifiedFeatures.end());
196196
std::vector<std::string> MArch;
197197
for (const auto &Ext : AArch64::Extensions)
198-
if (FeatureSet.contains(Ext.PosTargetFeature))
199-
MArch.push_back(Ext.UserVisibleName.str());
198+
if (!Ext.UserVisibleName.empty())
199+
if (FeatureSet.contains(Ext.PosTargetFeature))
200+
MArch.push_back(Ext.UserVisibleName.str());
200201
for (const auto &Ext : AArch64::Extensions)
201-
if (FeatureSet.contains(Ext.NegTargetFeature))
202-
MArch.push_back(("no" + Ext.UserVisibleName).str());
202+
if (!Ext.UserVisibleName.empty())
203+
if (FeatureSet.contains(Ext.NegTargetFeature))
204+
MArch.push_back(("no" + Ext.UserVisibleName).str());
203205
StringRef ArchName;
204206
for (const auto &ArchInfo : AArch64::ArchInfos)
205207
if (FeatureSet.contains(ArchInfo->ArchFeature))
@@ -221,11 +223,13 @@ static void getARMMultilibFlags(const Driver &D,
221223
UnifiedFeatures.end());
222224
std::vector<std::string> MArch;
223225
for (const auto &Ext : ARM::ARCHExtNames)
224-
if (FeatureSet.contains(Ext.Feature))
225-
MArch.push_back(Ext.Name.str());
226+
if (!Ext.Name.empty())
227+
if (FeatureSet.contains(Ext.Feature))
228+
MArch.push_back(Ext.Name.str());
226229
for (const auto &Ext : ARM::ARCHExtNames)
227-
if (FeatureSet.contains(Ext.NegFeature))
228-
MArch.push_back(("no" + Ext.Name).str());
230+
if (!Ext.Name.empty())
231+
if (FeatureSet.contains(Ext.NegFeature))
232+
MArch.push_back(("no" + Ext.Name).str());
229233
MArch.insert(MArch.begin(), ("-march=" + Triple.getArchName()).str());
230234
Result.push_back(llvm::join(MArch, "+"));
231235

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clang --target=aarch64-none-elf -march=armv8.9-a+rcpc3 -print-multi-flags-experimental -c %s 2>&1 | FileCheck %s
2+
3+
// CHECK: -march=armv8.9-a
4+
// CHECK-SAME: +rcpc+rcpc3+

0 commit comments

Comments
 (0)