]> granicus.if.org Git - clang/commitdiff
Add support for __builtin_unwind_init.
authorEli Friedman <eli.friedman@gmail.com>
Tue, 2 Jun 2009 09:37:50 +0000 (09:37 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 2 Jun 2009 09:37:50 +0000 (09:37 +0000)
Also, committing an #if 0'ed __builtin_setjmp and __builtin_longjmp
implementation I've had sitting in my tree for a while.  I haven't
enabled it because the LLVM backend support isn't complete yet.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72727 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtin-unwind-init.c [new file with mode: 0644]

index ec5738b28bd2e4355f64f5c2ddbed283c0dbbde9..d813bbae7f06e0330630439793548887f4f28e04 100644 (file)
@@ -320,6 +320,36 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
     // FIXME: There should be a target hook for this
     return RValue::get(EmitScalarExpr(E->getArg(0)));
   }
+  case Builtin::BI__builtin_unwind_init: {
+    Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init, 0, 0);
+    return RValue::get(Builder.CreateCall(F));
+  }
+#if 0
+  // FIXME: Finish/enable when LLVM backend support stabilizes
+  case Builtin::BI__builtin_setjmp: {
+    Value *Buf = EmitScalarExpr(E->getArg(0));
+    // Store the frame pointer to the buffer
+    Value *FrameAddrF = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0);
+    Value *FrameAddr =
+        Builder.CreateCall(FrameAddrF,
+                           Constant::getNullValue(llvm::Type::Int32Ty));
+    Builder.CreateStore(FrameAddr, Buf);
+    // Call the setjmp intrinsic
+    Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp, 0, 0);
+    const llvm::Type *DestType =
+      llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
+    Buf = Builder.CreateBitCast(Buf, DestType);
+    return RValue::get(Builder.CreateCall(F, Buf));
+  }
+  case Builtin::BI__builtin_longjmp: {
+    Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp, 0, 0);
+    Value *Buf = EmitScalarExpr(E->getArg(0));
+    const llvm::Type *DestType = 
+      llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
+    Buf = Builder.CreateBitCast(Buf, DestType);
+    return RValue::get(Builder.CreateCall(F, Buf));
+  }
+#endif
   case Builtin::BI__sync_fetch_and_add:
   case Builtin::BI__sync_fetch_and_sub:
   case Builtin::BI__sync_fetch_and_or:
diff --git a/test/CodeGen/builtin-unwind-init.c b/test/CodeGen/builtin-unwind-init.c
new file mode 100644 (file)
index 0000000..49a016a
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: clang-cc -emit-llvm < %s -o - | grep -F "llvm.eh.unwind.init"
+
+int a() { __builtin_unwind_init(); }
+