[PATCH] D66862: Make lround builtin constexpr (and others)

Zoe Carver via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 27 21:03:23 PDT 2019


zoecarver created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66862

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/math-builtins.cpp


Index: clang/test/SemaCXX/math-builtins.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/math-builtins.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++11 %s
+
+int main()
+{
+  constexpr float f = 12345.6789;
+
+  static_assert(__builtin_llround(f) == 12346, "");
+  static_assert(__builtin_llroundf(f) == 12346, "");
+
+  static_assert(__builtin_llrint(f) == 12346, "");
+  static_assert(__builtin_llrintf(f) == 12346, "");
+
+  static_assert(__builtin_lrint(f) == 12346, "");
+  static_assert(__builtin_lrintf(f) == 12346, "");
+
+  static_assert(__builtin_lround(f) == 12346, "");
+  static_assert(__builtin_lroundf(f) == 12346, "");
+}
\ No newline at end of file
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9609,6 +9609,58 @@
     return Success(N == Val.getBitWidth() ? 0 : N + 1, E);
   }
 
+  case Builtin::BIlround:
+  case Builtin::BI__builtin_lround: {
+    APFloat Val(0.0);
+    return EvaluateFloat(E->getArg(0), Val, Info) &&
+           Success(lround(Val.convertToDouble()), E);
+  }
+  case Builtin::BIlroundf:
+  case Builtin::BI__builtin_lroundf: {
+    APFloat Val(0.0);
+    return EvaluateFloat(E->getArg(0), Val, Info) &&
+           Success(lround(Val.convertToFloat()), E);
+  }
+
+  case Builtin::BIllround:
+  case Builtin::BI__builtin_llround: {
+    APFloat Val(0.0);
+    return EvaluateFloat(E->getArg(0), Val, Info) &&
+           Success(lround(Val.convertToDouble()), E);
+  }
+  case Builtin::BIllroundf:
+  case Builtin::BI__builtin_llroundf: {
+    APFloat Val(0.0);
+    return EvaluateFloat(E->getArg(0), Val, Info) &&
+           Success(llround(Val.convertToFloat()), E);
+  }
+
+  case Builtin::BIlrint:
+  case Builtin::BI__builtin_lrint: {
+    APFloat Val(0.0);
+    return EvaluateFloat(E->getArg(0), Val, Info) &&
+           Success(lround(Val.convertToDouble()), E);
+  }
+  case Builtin::BIlrintf:
+  case Builtin::BI__builtin_lrintf: {
+    APFloat Val(0.0);
+    return EvaluateFloat(E->getArg(0), Val, Info) &&
+           Success(lrint(Val.convertToFloat()), E);
+  }
+
+  case Builtin::BIllrint:
+  case Builtin::BI__builtin_llrint: {
+    APFloat Val(0.0);
+    return EvaluateFloat(E->getArg(0), Val, Info) &&
+           Success(lround(Val.convertToDouble()), E);
+  }
+  case Builtin::BIllrintf:
+  case Builtin::BI__builtin_llrintf: {
+    APFloat Val(0.0);
+    return EvaluateFloat(E->getArg(0), Val, Info) &&
+           Success(llrint(Val.convertToFloat()), E);
+  }
+
   case Builtin::BI__builtin_fpclassify: {
     APFloat Val(0.0);
     if (!EvaluateFloat(E->getArg(5), Val, Info))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66862.217572.patch
Type: text/x-patch
Size: 2747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190828/d8264c05/attachment.bin>


More information about the cfe-commits mailing list