@@ -540,12 +540,20 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
540540 }
541541
542542 // Now see if we can emit a target-specific builtin.
543- if (mlir::Value v = emitTargetBuiltinExpr (builtinID, e, returnValue)) {
543+ std::optional<mlir::Value> valueOpt =
544+ emitTargetBuiltinExpr (builtinID, e, returnValue);
545+ if (valueOpt) {
546+ // A builtin was emitted but had no return value.
547+ if (*valueOpt == nullptr ) {
548+ return RValue::get (nullptr );
549+ }
550+
544551 switch (evalKind) {
545552 case cir::TEK_Scalar:
546- if (mlir::isa<cir::VoidType>(v. getType ()))
553+ if (mlir::isa<cir::VoidType>(valueOpt-> getType ())) {
547554 return RValue::get (nullptr );
548- return RValue::get (v);
555+ }
556+ return RValue::get (*valueOpt);
549557 case cir::TEK_Aggregate:
550558 cgm.errorNYI (e->getSourceRange (), " aggregate return value from builtin" );
551559 return getUndefRValue (e->getType ());
@@ -561,7 +569,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
561569 return getUndefRValue (e->getType ());
562570}
563571
564- static mlir::Value emitTargetArchBuiltinExpr (CIRGenFunction *cgf,
572+ static std::optional< mlir::Value> emitTargetArchBuiltinExpr (CIRGenFunction *cgf,
565573 unsigned builtinID,
566574 const CallExpr *e,
567575 ReturnValueSlot &returnValue,
@@ -616,7 +624,7 @@ static mlir::Value emitTargetArchBuiltinExpr(CIRGenFunction *cgf,
616624 }
617625}
618626
619- mlir::Value
627+ std::optional< mlir::Value>
620628CIRGenFunction::emitTargetBuiltinExpr (unsigned builtinID, const CallExpr *e,
621629 ReturnValueSlot &returnValue) {
622630 if (getContext ().BuiltinInfo .isAuxBuiltinID (builtinID)) {
0 commit comments