[llvm] [llc] Change `TargetMachine` allocation assert to error (PR #189541)
Tomer Shafir via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 31 01:15:33 PDT 2026
https://github.com/tomershafir updated https://github.com/llvm/llvm-project/pull/189541
>From d20da7a770c02b21e25c92b11762991e5d890969 Mon Sep 17 00:00:00 2001
From: tomershafir <tomer.shafir8 at gmail.com>
Date: Tue, 31 Mar 2026 09:09:22 +0300
Subject: [PATCH 1/2] [llc] Change `TargetMachine` allocation assert to error
As we shouldn't assert an allocation (which can fail).
---
llvm/tools/llc/llc.cpp | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 74d39991f6d52..3e2065536a665 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -617,7 +617,11 @@ static int compileModule(char **argv, SmallVectorImpl<PassPlugin> &PluginList,
// to avoid a memory leak.
Target = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
TheTriple, SkipModuleCPU, FeaturesStr, Options, RM, CM, OLvl));
- assert(Target && "Could not allocate target machine!");
+ if (!Target) {
+ WithColor::error(errs(), argv[0])
+ << "Could not allocate target machine!\n";
+ return 1;
+ }
// If we don't have a module then just exit now. We do this down
// here since the CPU/Feature help is underneath the target machine
@@ -646,7 +650,11 @@ static int compileModule(char **argv, SmallVectorImpl<PassPlugin> &PluginList,
InitializeOptions(TheTriple);
Target = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
TheTriple, CPUStr, FeaturesStr, Options, RM, CM, OLvl));
- assert(Target && "Could not allocate target machine!");
+ if (!Target) {
+ WithColor::error(errs(), argv[0])
+ << "Could not allocate target machine!\n";
+ exit(1);
+ }
// Set PGO options based on command line flags
setPGOOptions(*Target);
>From 961460bd4205a3ba7c810930124311e1d2ed1b66 Mon Sep 17 00:00:00 2001
From: Tomer Shafir <tomer.shafir8 at gmail.com>
Date: Tue, 31 Mar 2026 11:15:24 +0300
Subject: [PATCH 2/2] lower case err message 1
Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
---
llvm/tools/llc/llc.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 3e2065536a665..f1f816583e496 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -619,7 +619,7 @@ static int compileModule(char **argv, SmallVectorImpl<PassPlugin> &PluginList,
TheTriple, SkipModuleCPU, FeaturesStr, Options, RM, CM, OLvl));
if (!Target) {
WithColor::error(errs(), argv[0])
- << "Could not allocate target machine!\n";
+ << "could not allocate target machine\n";
return 1;
}
More information about the llvm-commits
mailing list