[clang] 028c103 - [Driver][BareMetal] Error if no matching multilib
Michael Platings via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 22 00:10:56 PDT 2023
Author: Michael Platings
Date: 2023-06-22T08:10:43+01:00
New Revision: 028c1033b1ed7b35beab736dd50053f80df02fa3
URL: https://github.com/llvm/llvm-project/commit/028c1033b1ed7b35beab736dd50053f80df02fa3
DIFF: https://github.com/llvm/llvm-project/commit/028c1033b1ed7b35beab736dd50053f80df02fa3.diff
LOG: [Driver][BareMetal] Error if no matching multilib
Previously if no matching multilib was found then the user would
typically see an error like "fatal error: 'stdio.h' file not found"
which gives no indication as to the underlying problem.
With this change the user will instead see an error like
clang: error: no multilib found matching flags: --target=thumbv7em-none-unknown-eabi -march=...
clang: note: available multilibs are:
--target=armv4t-none-unknown-eabi
--target=thumbv6m-none-unknown-eabi -mfpu=none
...
Differential Revision: https://reviews.llvm.org/D153292
Added:
Modified:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/test/Driver/baremetal-multilib.yaml
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index ff0f693061a39..635f6e755cdcb 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -733,4 +733,9 @@ def err_drv_loongarch_invalid_mfpu_EQ : Error<
def err_drv_expand_response_file : Error<
"failed to expand response file: %0">;
+
+def err_drv_no_matching_multilib : Error<
+ "no multilib found matching flags: %0">;
+def note_drv_available_multilibs : Note<
+ "available multilibs are:%0">;
}
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 17fd1f88975b9..09cc72f03363d 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -23,6 +23,8 @@
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
+#include <sstream>
+
using namespace llvm::opt;
using namespace clang;
using namespace clang::driver;
@@ -158,20 +160,26 @@ static bool isRISCVBareMetal(const llvm::Triple &Triple) {
return Triple.getEnvironmentName() == "elf";
}
-static bool findMultilibsFromYAML(const ToolChain &TC, const Driver &D,
+static void findMultilibsFromYAML(const ToolChain &TC, const Driver &D,
StringRef MultilibPath, const ArgList &Args,
DetectedMultilibs &Result) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB =
D.getVFS().getBufferForFile(MultilibPath);
if (!MB)
- return false;
+ return;
Multilib::flags_list Flags = TC.getMultilibFlags(Args);
llvm::ErrorOr<MultilibSet> ErrorOrMultilibSet =
MultilibSet::parseYaml(*MB.get());
if (ErrorOrMultilibSet.getError())
- return false;
+ return;
Result.Multilibs = ErrorOrMultilibSet.get();
- return Result.Multilibs.select(Flags, Result.SelectedMultilibs);
+ if (Result.Multilibs.select(Flags, Result.SelectedMultilibs))
+ return;
+ D.Diag(clang::diag::err_drv_no_matching_multilib) << llvm::join(Flags, " ");
+ std::stringstream ss;
+ for (const Multilib &Multilib : Result.Multilibs)
+ ss << "\n" << llvm::join(Multilib.flags(), " ");
+ D.Diag(clang::diag::note_drv_available_multilibs) << ss.str();
}
static constexpr llvm::StringLiteral MultilibFilename = "multilib.yaml";
diff --git a/clang/test/Driver/baremetal-multilib.yaml b/clang/test/Driver/baremetal-multilib.yaml
index 93fa61ce6adf0..e3281fa3b04b6 100644
--- a/clang/test/Driver/baremetal-multilib.yaml
+++ b/clang/test/Driver/baremetal-multilib.yaml
@@ -20,6 +20,16 @@
# CHECK-SAME: "-lc" "-lm" "-lclang_rt.builtins"
# CHECK-SAME: "-o" "{{.*}}.tmp.out"
+# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -x c++ %s -### -o %t.out 2>&1 \
+# RUN: --target=thumbv7em-none-eabi -mfpu=fpv4-sp-d16 --sysroot= \
+# RUN: | FileCheck --check-prefix=CHECK-NO-MATCH %s
+# CHECK-NO-MATCH: error: no multilib found matching flags:
+# CHECK-NO-MATCH-SAME: --target=thumbv7em-none-unknown-eabi
+# CHECK-NO-MATCH: note: available multilibs are:
+# CHECK-NO-MATCH: --target=thumbv6m-none-unknown-eabi -mfpu=none
+# CHECK-NO-MATCH: --target=thumbv7m-none-unknown-eabi -mfpu=none
+# CHECK-NO-MATCH: --target=thumbv7em-none-unknown-eabi -mfpu=none
+
# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -print-multi-directory 2>&1 \
# RUN: --target=thumbv8m.main-none-eabihf --sysroot= \
# RUN: | FileCheck --check-prefix=CHECK-PRINT-MULTI-DIRECTORY %s
@@ -75,6 +85,9 @@ MultilibVersion: 1.0
# multilib, layered on top of each other.
Variants:
+- Dir: arm-none-eabi/arm/v4t
+ Flags: [--target=armv4t-none-unknown-eabi]
+
- Dir: arm-none-eabi/thumb/v6-m/nofp
Flags: [--target=thumbv6m-none-unknown-eabi, -mfpu=none]
More information about the cfe-commits
mailing list