[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

Hubert Tong via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 19:39:15 PDT 2024


================
@@ -14674,6 +14676,31 @@ static bool TryEvaluateBuiltinNaN(const ASTContext &Context,
 
   return true;
 }
+//  Checks that the value x is in the range (-1;-0.5], [0.5; 1)
+static bool isInFrexpResultRange(const llvm::APFloat &x) {
+  llvm::APFloat minusOne(x.getSemantics(), "-1.0");
+  llvm::APFloat minusHalf(x.getSemantics(), "-0.5");
+  llvm::APFloat half(x.getSemantics(), "0.5");
+  llvm::APFloat one(x.getSemantics(), "1.0");
+
+  return ((x.compare(minusOne) == llvm::APFloat::cmpGreaterThan &&
+           x.compare(minusHalf) != llvm::APFloat::cmpGreaterThan) ||
+          (x.compare(half) != llvm::APFloat::cmpLessThan &&
+           x.compare(one) == llvm::APFloat::cmpLessThan));
+}
+
+void FloatExprEvaluator::StoreExponent(LValue Pointer, int exp) {
+  const APValue::LValueBase Base = Pointer.getLValueBase();
+  auto *VD = const_cast<ValueDecl *>(Base.dyn_cast<const ValueDecl *>());
+  if (auto *VarD = dyn_cast<VarDecl>(VD)) {
+    clang::IntegerLiteral *IL =
+        clang::IntegerLiteral::Create(Info.Ctx, llvm::APSInt(32, exp),
+                                      Info.Ctx.IntTy, clang::SourceLocation());
+    VarD->setInit(IL);
----------------
hubert-reinterpretcast wrote:

See use of `handleAssignment` for `__builtin_add_overflow`:
https://github.com/llvm/llvm-project/blob/b2d7d72ff2408dcc27048e08d50ac719ff03a89e/clang/lib/AST/ExprConstant.cpp#L13071

https://github.com/llvm/llvm-project/pull/88978


More information about the llvm-commits mailing list