diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 33dad2726445b21bcc993adb4ab9b2a56e183244..b748e75827697682835fea412cbfb737ff628af7 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -497,18 +497,22 @@ void CodeGenFunction::EmitPlatinaIntrinsic(const ArrayRef<const Attr*> &Attrs) { // Skip non PlatinaGuard attributes if (!PA) continue; - Function *Callee = - CGM.getIntrinsic(Intrinsic::platina); - CallInst *callsite = Builder.CreateCall(Callee); - // Attach the guardexpr to the instruction-metadata // We have to store our string in the LLVMContext - LLVMContext& C = callsite->getContext(); - StringRef name = PA->getType()->getName(); - MDNode *type = MDNode::get(C, MDString::get(C, name)); - callsite->setMetadata("platina.type", type); - MDNode *expr = MDNode::get(C, MDString::get(C, PA->getPlatinaExpr())); - callsite->setMetadata("platina.expr", expr); + LLVMContext& C = Builder.getContext(); + + // In theory, we could wrap a plain MDString into a MetadataAsValue + // However, we need MDNodes as MachnineInstrunctions anyways, so, + // for consistencies sake, we marshal MDNodes the whole way + StringRef name = PA->getType()->getName(); + MDNode *type = MDNode::get(C, MDString::get(C, name)); + MetadataAsValue *vtype = MetadataAsValue::get(C, type); + MDNode *expr = MDNode::get(C, MDString::get(C, PA->getPlatinaExpr())); + MetadataAsValue *vexpr = MetadataAsValue::get(C, expr); + + Function *Callee = + CGM.getIntrinsic(Intrinsic::platina); + Builder.CreateCall(Callee, {vtype, vexpr}); } }