[llvm] [llc] Change `TargetMachine` allocation assert to error (PR #189541)
Tomer Shafir via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 30 23:56:42 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] [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);
More information about the llvm-commits
mailing list