diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def --- a/clang/include/clang/Basic/Builtins.def +++ b/clang/include/clang/Basic/Builtins.def @@ -392,6 +392,7 @@ // Access to floating point environment BUILTIN(__builtin_flt_rounds, "i", "n") +BUILTIN(__builtin_fesetround, "vi", "n") // C99 complex builtins BUILTIN(__builtin_cabs, "dXd", "Fne") diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -3361,6 +3361,14 @@ return RValue::get(Result); } + case Builtin::BI__builtin_fesetround: { + Function *F = CGM.getIntrinsic(Intrinsic::set_rounding); + + Value *V = EmitScalarExpr(E->getArg(0)); + Builder.CreateCall(F, V); + return RValue::get(nullptr); + } + case Builtin::BI__builtin_fpclassify: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); // FIXME: for strictfp/IEEE-754 we need to not trap on SNaN here. diff --git a/clang/test/CodeGen/builtins.c b/clang/test/CodeGen/builtins.c --- a/clang/test/CodeGen/builtins.c +++ b/clang/test/CodeGen/builtins.c @@ -278,6 +278,9 @@ res = __builtin_flt_rounds(); // CHECK: call i32 @llvm.get.rounding( + + __builtin_fesetround(1); + // CHECK: call void @llvm.set.rounding(i32 1) } // CHECK-LABEL: define{{.*}} void @test_float_builtin_ops