[llvm] ac1012d - llvm-mc: Error on MCSubtargetInfo construction failure (#159226)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 22:58:39 PDT 2025
Author: Matt Arsenault
Date: 2025-09-17T14:58:36+09:00
New Revision: ac1012d315fd4cac2a4ac535a00daed682481dc0
URL: https://github.com/llvm/llvm-project/commit/ac1012d315fd4cac2a4ac535a00daed682481dc0
DIFF: https://github.com/llvm/llvm-project/commit/ac1012d315fd4cac2a4ac535a00daed682481dc0.diff
LOG: llvm-mc: Error on MCSubtargetInfo construction failure (#159226)
We have inconsistent handling of null returns on target MC constructors.
Most tools report an error, but some assert. It's currently not possible
to test this with any in-tree targets. Make this a clean error so in the
future targets can fail the construction.
Added:
Modified:
llvm/tools/llvm-mc/llvm-mc.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index 136cd69526a3c..224fd80f6a6d3 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -469,7 +469,10 @@ int main(int argc, char **argv) {
std::unique_ptr<MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TheTriple, MCPU, FeaturesStr));
- assert(STI && "Unable to create subtarget info!");
+ if (!STI) {
+ WithColor::error(errs(), ProgName) << "unable to create subtarget info\n";
+ return 1;
+ }
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
More information about the llvm-commits
mailing list