diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index 2bda8e51d9c5d6..c9d255c4aa8af5 100644 --- a/clang/include/clang/Basic/BuiltinsWebAssembly.def +++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def @@ -40,6 +40,8 @@ BUILTIN(__builtin_wasm_max_f64, "ddd", "nc") BUILTIN(__builtin_wasm_segment_new, "v*v*z", "n") BUILTIN(__builtin_wasm_segment_free, "vv*z", "n") +BUILTIN(__builtin_wasm_segment_set_tag, "vv*v*z", "n") +BUILTIN(__builtin_wasm_untag_ptr, "v*v*", "n") // Exception handling builtins. TARGET_BUILTIN(__builtin_wasm_throw, "vIUiv*", "r", "exception-handling") diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 8fff2b7dc7b321..b433effa14eff2 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -19851,6 +19851,21 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Value *Size = EmitScalarExpr(E->getArg(1)); return Builder.CreateCall(Callee, {Ptr, Size}); } + case WebAssembly::BI__builtin_wasm_untag_ptr: { + llvm::Type *IntTy = llvm::Type::getInt64Ty(Builder.getContext()); + Value *Ptr = EmitScalarExpr(E->getArg(0)); + Value *IntPtr = Builder.CreateIntToPtr(Ptr, IntTy); + Value *BitMask = llvm::ConstantInt::get(IntTy, 0x0000'FFFF'FFFF'FFFF, false); + Value *StrippedPtr = Builder.CreateBinOp(llvm::Instruction::BinaryOps::And, IntPtr, BitMask); + return Builder.CreateIntToPtr(StrippedPtr, ConvertType(E->getType())); + } + case WebAssembly::BI__builtin_wasm_segment_set_tag: { + Value *Ptr = EmitScalarExpr(E->getArg(0)); + Value *Tag = EmitScalarExpr(E->getArg(1)); + Value *Size = EmitScalarExpr(E->getArg(2)); + Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_segment_set_tag); + return Builder.CreateCall(Callee, {Ptr, Tag, Size}); + } case WebAssembly::BI__builtin_wasm_throw: { Value *Tag = EmitScalarExpr(E->getArg(0)); Value *Obj = EmitScalarExpr(E->getArg(1));