@@ -557,30 +557,33 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
557
557
else
558
558
return RValue::get (Builder.CreateZExt (Result, Int64Ty, " extend.zext" ));
559
559
}
560
- #if 0
561
- // FIXME: Finish/enable when LLVM backend support stabilizes
562
560
case Builtin::BI__builtin_setjmp: {
561
+ // Buffer is a void**.
563
562
Value *Buf = EmitScalarExpr (E->getArg (0 ));
564
- // Store the frame pointer to the buffer
565
- Value *FrameAddrF = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0);
563
+
564
+ // Store the frame pointer to the setjmp buffer.
566
565
Value *FrameAddr =
567
- Builder.CreateCall(FrameAddrF ,
568
- Constant::getNullValue (llvm::Type::getInt32Ty(VMContext)));
566
+ Builder.CreateCall (CGM. getIntrinsic (Intrinsic::frameaddress) ,
567
+ ConstantInt::get (llvm::Type::getInt32Ty (VMContext), 0 ));
569
568
Builder.CreateStore (FrameAddr, Buf);
570
- // Call the setjmp intrinsic
571
- Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp, 0, 0);
572
- const llvm::Type *DestType = llvm::Type::getInt8PtrTy(VMContext );
573
- Buf = Builder.CreateBitCast(Buf, DestType );
569
+
570
+ // Call LLVM's EH setjmp, which is lightweight.
571
+ Value *F = CGM. getIntrinsic (Intrinsic::eh_sjlj_setjmp );
572
+ Buf = Builder.CreateBitCast (Buf, llvm::Type::getInt8PtrTy (VMContext) );
574
573
return RValue::get (Builder.CreateCall (F, Buf));
575
574
}
576
575
case Builtin::BI__builtin_longjmp: {
577
- Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp, 0, 0);
578
576
Value *Buf = EmitScalarExpr (E->getArg (0 ));
579
- const llvm::Type *DestType = llvm::Type::getInt8PtrTy(VMContext);
580
- Buf = Builder.CreateBitCast(Buf, DestType);
581
- return RValue::get(Builder.CreateCall(F, Buf));
577
+ Buf = Builder.CreateBitCast (Buf, llvm::Type::getInt8PtrTy (VMContext));
578
+
579
+ // Call LLVM's EH longjmp, which is lightweight.
580
+ Builder.CreateCall (CGM.getIntrinsic (Intrinsic::eh_sjlj_longjmp), Buf);
581
+
582
+ // longjmp doesn't return; mark this as unreachable
583
+ Value *V = Builder.CreateUnreachable ();
584
+ Builder.ClearInsertionPoint ();
585
+ return RValue::get (V);
582
586
}
583
- #endif
584
587
case Builtin::BI__sync_fetch_and_add:
585
588
case Builtin::BI__sync_fetch_and_sub:
586
589
case Builtin::BI__sync_fetch_and_or:
0 commit comments