Skip to content

[Clang][Driver] Skip empty strings in getAArch64MultilibFlags #97827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ static void getAArch64MultilibFlags(const Driver &D,
UnifiedFeatures.end());
std::vector<std::string> MArch;
for (const auto &Ext : AArch64::Extensions)
if (FeatureSet.contains(Ext.PosTargetFeature))
MArch.push_back(Ext.UserVisibleName.str());
if (!Ext.UserVisibleName.empty())
if (FeatureSet.contains(Ext.PosTargetFeature))
MArch.push_back(Ext.UserVisibleName.str());
for (const auto &Ext : AArch64::Extensions)
if (FeatureSet.contains(Ext.NegTargetFeature))
MArch.push_back(("no" + Ext.UserVisibleName).str());
if (!Ext.UserVisibleName.empty())
if (FeatureSet.contains(Ext.NegTargetFeature))
MArch.push_back(("no" + Ext.UserVisibleName).str());
StringRef ArchName;
for (const auto &ArchInfo : AArch64::ArchInfos)
if (FeatureSet.contains(ArchInfo->ArchFeature))
Expand All @@ -221,11 +223,13 @@ static void getARMMultilibFlags(const Driver &D,
UnifiedFeatures.end());
std::vector<std::string> MArch;
for (const auto &Ext : ARM::ARCHExtNames)
if (FeatureSet.contains(Ext.Feature))
MArch.push_back(Ext.Name.str());
if (!Ext.Name.empty())
if (FeatureSet.contains(Ext.Feature))
MArch.push_back(Ext.Name.str());
for (const auto &Ext : ARM::ARCHExtNames)
if (FeatureSet.contains(Ext.NegFeature))
MArch.push_back(("no" + Ext.Name).str());
if (!Ext.Name.empty())
if (FeatureSet.contains(Ext.NegFeature))
MArch.push_back(("no" + Ext.Name).str());
MArch.insert(MArch.begin(), ("-march=" + Triple.getArchName()).str());
Result.push_back(llvm::join(MArch, "+"));

Expand Down
17 changes: 17 additions & 0 deletions clang/test/Driver/aarch64-multilib-rcpc3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clang --target=aarch64-none-elf -march=armv8.9-a+rcpc3 -print-multi-flags-experimental -c %s 2>&1 | FileCheck %s

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be worth a comment here explaining what the test is checking for as it would likely need git blame to work it out otherwise. For example:

// rcpc3 implies rcpc-immo which does not have a user-visible name, check that an empty string is not produced.

// The purpose of this regression test is to make sure that when
// compile options are converted into multilib selection flags, no
// empty strings are accidentally included in the
// -march=armv8.9-a+foo+bar+baz string, leading to two consecutive +
// signs. With +rcpc3 in the input, this used to generate an empty
// string for the anonymous architecture extension corresponding to
// the SubtargetFeature 'rcpc-immo', which is a dependency of rcpc3
// but has no separate extension name for use on command lines. So we
// check that the two named rcpc options appear, and that no ++
// appears before or after.

// CHECK: -march=armv8.9-a
// CHECK-NOT: ++
// CHECK-SAME: +rcpc+rcpc3+
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if a CHECK-NOT ++ could be used as well. This test might unexpectedly pass if the ordering of the features were changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I wasn't sure whether it would need to come before or after the rcpc+rcpc3 check. The answer turns out to be both.

// CHECK-NOT: ++
Loading