@@ -1634,16 +1634,19 @@ class AbortRewriter: public mlir::OpConversionPattern<mlir::rlc::AbortOp>
16341634 mlir::TypeConverter& converter,
16351635 mlir::MLIRContext* ctx,
16361636 mlir::LLVM::LLVMFuncOp puts,
1637+ mlir::LLVM::LLVMFuncOp libcAbort,
16371638 llvm::StringMap<mlir::LLVM::GlobalOp>& stringsCache,
16381639 mlir::StringRef abort = " " )
16391640 : mlir::OpConversionPattern<mlir::rlc::AbortOp>::OpConversionPattern(
16401641 converter, ctx),
16411642 puts (puts),
1643+ libCAbort(libcAbort),
16421644 stringsCache(&stringsCache),
16431645 abort(abort)
16441646 {
16451647 }
16461648 mutable mlir::LLVM::LLVMFuncOp puts;
1649+ mutable mlir::LLVM::LLVMFuncOp libCAbort;
16471650 llvm::StringMap<mlir::LLVM::GlobalOp>* stringsCache;
16481651 llvm::StringRef abort;
16491652
@@ -1656,7 +1659,7 @@ class AbortRewriter: public mlir::OpConversionPattern<mlir::rlc::AbortOp>
16561659 op.getLoc (),
16571660 rewriter,
16581661 " " ,
1659- op.getMessage (),
1662+ ( op.getMessage () + llvm::Twine ( ' \0 ' )). str (),
16601663 op->getParentOfType <mlir::ModuleOp>(),
16611664 *stringsCache);
16621665
@@ -1677,7 +1680,11 @@ class AbortRewriter: public mlir::OpConversionPattern<mlir::rlc::AbortOp>
16771680 puts.getSymName (),
16781681 mlir::ValueRange ({ global }));
16791682 }
1680- rewriter.create <mlir::LLVM::Trap>(op.getLoc ());
1683+ rewriter.create <mlir::LLVM::CallOp>(
1684+ op.getLoc (),
1685+ mlir::TypeRange (),
1686+ libCAbort.getSymName (),
1687+ mlir::ValueRange ({}));
16811688 }
16821689
16831690 rewriter.create <mlir::LLVM::ReturnOp>(op.getLoc (), mlir::ValueRange ());
@@ -2278,6 +2285,15 @@ namespace mlir::rlc
22782285 mlir::LLVM::LLVMVoidType::get (&getContext ()),
22792286 { mlir::LLVM::LLVMPointerType::get (&getContext ()) }));
22802287
2288+ auto libcAbort = rewriter.create <mlir::LLVM::LLVMFuncOp>(
2289+ getOperation ().getLoc (),
2290+ " abort" ,
2291+ mlir::LLVM::LLVMFunctionType::get (
2292+ mlir::LLVM::LLVMVoidType::get (&getContext ()), {}));
2293+ libcAbort.setNoUnwind (true );
2294+ auto arr = rewriter.getArrayAttr ({ rewriter.getStringAttr (" noreturn" ) });
2295+ libcAbort.setPassthroughAttr (arr);
2296+
22812297 auto malloc = rewriter.create <mlir::LLVM::LLVMFuncOp>(
22822298 getOperation ().getLoc (),
22832299 " malloc" ,
@@ -2385,7 +2401,12 @@ namespace mlir::rlc
23852401 .add <ClassDeclarationRewriter>(converter, &getContext ())
23862402 .add <ExplicitConstructRewriter>(converter, &getContext ())
23872403 .add <AbortRewriter>(
2388- converter, &getContext (), puts, stringsCache, abort_symbol);
2404+ converter,
2405+ &getContext (),
2406+ puts,
2407+ libcAbort,
2408+ stringsCache,
2409+ abort_symbol);
23892410
23902411 if (failed (
23912412 applyFullConversion (getOperation (), target, std::move (patterns))))
0 commit comments