[clang] [clang] constexpr built-in abs function. (PR #112539)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 17 00:15:23 PDT 2024


================
@@ -563,6 +563,19 @@ static bool interp__builtin_fabs(InterpState &S, CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_abs(InterpState &S, CodePtr OpPC,
+                                const InterpFrame *Frame, const Function *Func,
+                                const CallExpr *Call) {
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  APSInt Val = peekToAPSInt(S.Stk, ArgT);
+  if (Val == APSInt(APSInt::getSignedMinValue(Val.getBitWidth()), false))
----------------
tbaederr wrote:

```suggestion
  if (Val == APSInt(APInt::getSignedMinValue(Val.getBitWidth()), /*IsUnsigned=*/false))
```

Same with the other implementation

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


More information about the cfe-commits mailing list