Skip to content

[Clang][Driver] Valid -march value is not mandatory in AArch64 multilib #151103

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 29, 2025

Conversation

vhscampos
Copy link
Member

If a user passed an invalid value to -march, an assertion failure happened in the AArch64 multilib logic.

But an invalid -march value is an expected case that should be handled via error messages.

This patch removes the requirement that the -march value must be valid.

…ilib

If a user passed an invalid value to `-march`, an assertion failure
happened in the AArch64 multilib logic.

But an invalid `-march` value is an expected case that should be handled
via error messages.

This patch removes the requirement that the `-march` value must be
valid.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Jul 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Victor Campos (vhscampos)

Changes

If a user passed an invalid value to -march, an assertion failure happened in the AArch64 multilib logic.

But an invalid -march value is an expected case that should be handled via error messages.

This patch removes the requirement that the -march value must be valid.


Full diff: https://github.com/llvm/llvm-project/pull/151103.diff

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChain.cpp (+4-3)
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 1d7dad0d7d12b..496c0dc1780e4 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -191,9 +191,10 @@ static void getAArch64MultilibFlags(const Driver &D,
   for (const auto &ArchInfo : AArch64::ArchInfos)
     if (FeatureSet.contains(ArchInfo->ArchFeature))
       ArchName = ArchInfo->Name;
-  assert(!ArchName.empty() && "at least one architecture should be found");
-  MArch.insert(MArch.begin(), ("-march=" + ArchName).str());
-  Result.push_back(llvm::join(MArch, "+"));
+  if (!ArchName.empty()) {
+    MArch.insert(MArch.begin(), ("-march=" + ArchName).str());
+    Result.push_back(llvm::join(MArch, "+"));
+  }
 
   const Arg *BranchProtectionArg =
       Args.getLastArgNoClaim(options::OPT_mbranch_protection_EQ);

Copy link
Contributor

@MarkMurrayARM MarkMurrayARM left a comment

Choose a reason for hiding this comment

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

Shouldn't we have tests for this? Particularly given it can cause untidy crashes from CL errors. No objection if the answer is "no".

@vhscampos
Copy link
Member Author

Added tests. Thank you for pointing that out

Copy link
Contributor

@MarkMurrayARM MarkMurrayARM left a comment

Choose a reason for hiding this comment

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

LGTM

@vhscampos vhscampos merged commit 910f6ad into llvm:main Jul 29, 2025
9 checks passed
@vhscampos vhscampos deleted the multilib-arm-aarch64-invalid-march branch July 29, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants