Index: clang/lib/AST/Interp/InterpBuiltin.cpp =================================================================== --- clang/lib/AST/Interp/InterpBuiltin.cpp +++ clang/lib/AST/Interp/InterpBuiltin.cpp @@ -139,6 +139,25 @@ return true; } +static bool interp__builtin_fmin(InterpState &S, CodePtr OpPC, + const InterpFrame *Frame, const Function *F) { + const Floating &LHS = getParam(Frame, 0); + const Floating &RHS = getParam(Frame, 1); + + Floating Result; + + // When comparing zeroes, return -0.0 if one of the zeroes is negative. + if (LHS.isZero() && RHS.isZero() && RHS.isNegative()) + Result = RHS; + else if (LHS.isNan() || RHS < LHS) + Result = RHS; + else + Result = LHS; + + S.Stk.push(Result); + return true; +} + bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) { InterpFrame *Frame = S.Current; APValue Dummy; @@ -191,6 +210,14 @@ return Ret(S, OpPC, Dummy); break; + case Builtin::BI__builtin_fmin: + case Builtin::BI__builtin_fminf: + case Builtin::BI__builtin_fminl: + case Builtin::BI__builtin_fminf16: + case Builtin::BI__builtin_fminf128: + if (interp__builtin_fmin(S, OpPC, Frame, F)) + return Ret(S, OpPC, Dummy); + break; default: return false;