]> granicus.if.org Git - clang/commitdiff
[WebAssembly] Add throw/rethrow builtins for exception handling
authorHeejin Ahn <aheejin@gmail.com>
Fri, 30 Jun 2017 00:44:01 +0000 (00:44 +0000)
committerHeejin Ahn <aheejin@gmail.com>
Fri, 30 Jun 2017 00:44:01 +0000 (00:44 +0000)
Summary:
Add new builtins for throw/rethrow instructions. This follows exception handling
handling proposal in
https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md

Reviewers: sunfish, dschuff

Reviewed By: dschuff

Subscribers: jfb, dschuff, sbc100, jgravelle-google

Differential Revision: https://reviews.llvm.org/D34783

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

include/clang/Basic/BuiltinsWebAssembly.def
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtins-wasm.c

index de56908be83c628d0617613edd3bfc2d6e1b9d5c..19318dcebb9ec2f6f76436da021ee215c6882892 100644 (file)
@@ -21,4 +21,8 @@
 BUILTIN(__builtin_wasm_current_memory, "z", "n")
 BUILTIN(__builtin_wasm_grow_memory, "zz", "n")
 
+// Exception handling builtins.
+BUILTIN(__builtin_wasm_throw, "vUiv*", "r")
+BUILTIN(__builtin_wasm_rethrow, "v", "r")
+
 #undef BUILTIN
index a6451b7fc3c135f5b964f729a4f13421ef7a3eef..2a6e92e7f3ce99035c637867e82c01de752bf4f8 100644 (file)
@@ -9372,6 +9372,16 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
     Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_grow_memory, X->getType());
     return Builder.CreateCall(Callee, X);
   }
+  case WebAssembly::BI__builtin_wasm_throw: {
+    Value *Tag = EmitScalarExpr(E->getArg(0));
+    Value *Obj = EmitScalarExpr(E->getArg(1));
+    Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_throw);
+    return Builder.CreateCall(Callee, {Tag, Obj});
+  }
+  case WebAssembly::BI__builtin_wasm_rethrow: {
+    Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_rethrow);
+    return Builder.CreateCall(Callee);
+  }
 
   default:
     return nullptr;
index 0c0b87945d4267770a08aba519608a5e658e2edc..e0f72d2e503417517fec56432486aa276cfd0912 100644 (file)
@@ -14,3 +14,15 @@ __SIZE_TYPE__ f2(__SIZE_TYPE__ delta) {
 // WEBASSEMBLY32: call i32 @llvm.wasm.grow.memory.i32(i32 %{{.*}})
 // WEBASSEMBLY64: call i64 @llvm.wasm.grow.memory.i64(i64 %{{.*}})
 }
+
+void f3(unsigned int tag, void *obj) {
+  return __builtin_wasm_throw(tag, obj);
+// WEBASSEMBLY32: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}})
+// WEBASSEMBLY64: call void @llvm.wasm.throw(i32 %{{.*}}, i8* %{{.*}})
+}
+
+void f4() {
+  return __builtin_wasm_rethrow();
+// WEBASSEMBLY32: call void @llvm.wasm.rethrow()
+// WEBASSEMBLY64: call void @llvm.wasm.rethrow()
+}