Skip to content

Commit ac1012d

Browse files
authored
llvm-mc: Error on MCSubtargetInfo construction failure (llvm#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.
1 parent b3a1c77 commit ac1012d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/tools/llvm-mc/llvm-mc.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,10 @@ int main(int argc, char **argv) {
469469

470470
std::unique_ptr<MCSubtargetInfo> STI(
471471
TheTarget->createMCSubtargetInfo(TheTriple, MCPU, FeaturesStr));
472-
assert(STI && "Unable to create subtarget info!");
472+
if (!STI) {
473+
WithColor::error(errs(), ProgName) << "unable to create subtarget info\n";
474+
return 1;
475+
}
473476

474477
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
475478
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.

0 commit comments

Comments
 (0)