tbaeder updated this revision to Diff 543321.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155568/new/

https://reviews.llvm.org/D155568

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpBuiltin.cpp

Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===================================================================
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -32,6 +32,30 @@
   return R;
 }
 
+/// Pushes \p Val to the stack, as a target-dependent 'int'.
+static void pushInt(InterpState &S, int32_t Val) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+    S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Val));
+  else if (IntWidth == 16)
+    S.Stk.push<Integral<16, true>>(Integral<16, true>::from(Val));
+  else
+    llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
+static bool retInt(InterpState &S, CodePtr OpPC, APValue &Result) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+    return Ret<PT_Sint32>(S, OpPC, Result);
+  else if (IntWidth == 16)
+    return Ret<PT_Sint16>(S, OpPC, Result);
+  llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
                                    const InterpFrame *Frame) {
   const Pointer &A = getParam<Pointer>(Frame, 0);
@@ -67,7 +91,7 @@
       break;
   }
 
-  S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
   return true;
 }
 
@@ -197,7 +221,7 @@
                                   const InterpFrame *Frame, const Function *F) {
   const Floating &Arg = S.Stk.peek<Floating>();
 
-  S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Arg.isNan()));
+  pushInt(S, Arg.isNan());
   return true;
 }
 
@@ -208,10 +232,9 @@
   bool IsInf = Arg.isInf();
 
   if (CheckSign)
-    S.Stk.push<Integral<32, true>>(
-        Integral<32, true>::from(IsInf ? (Arg.isNegative() ? -1 : 1) : 0));
+    pushInt(S, IsInf ? (Arg.isNegative() ? -1 : 1) : 0);
   else
-    S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Arg.isInf()));
+    pushInt(S, Arg.isInf());
   return true;
 }
 
@@ -220,7 +243,7 @@
                                      const Function *F) {
   const Floating &Arg = S.Stk.peek<Floating>();
 
-  S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Arg.isFinite()));
+  pushInt(S, Arg.isFinite());
   return true;
 }
 
@@ -229,7 +252,7 @@
                                      const Function *F) {
   const Floating &Arg = S.Stk.peek<Floating>();
 
-  S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Arg.isNormal()));
+  pushInt(S, Arg.isNormal());
   return true;
 }
 
@@ -246,12 +269,12 @@
 
   int32_t Result =
       static_cast<int32_t>((F.classify() & FPClassArg).getZExtValue());
-  S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
 
   return true;
 }
 
-/// Five int32 values followed by one floating value.
+/// Five int values followed by one floating value.
 static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC,
                                        const InterpFrame *Frame,
                                        const Function *Func) {
@@ -277,8 +300,9 @@
   unsigned Offset = align(primSize(PT_Float)) +
                     ((1 + (4 - Index)) * align(primSize(PT_Sint32)));
 
+  // FIXME: The size of the value we're peeking here is target-dependent.
   const Integral<32, true> &I = S.Stk.peek<Integral<32, true>>(Offset);
-  S.Stk.push<Integral<32, true>>(I);
+  pushInt(S, static_cast<int32_t>(I));
   return true;
 }
 
@@ -327,7 +351,7 @@
     return RetVoid(S, OpPC, Dummy);
   case Builtin::BI__builtin_strcmp:
     if (interp__builtin_strcmp(S, OpPC, Frame))
-      return Ret<PT_Sint32>(S, OpPC, Dummy);
+      return retInt(S, OpPC, Dummy);
     break;
   case Builtin::BI__builtin_nan:
   case Builtin::BI__builtin_nanf:
@@ -387,34 +411,34 @@
 
   case Builtin::BI__builtin_isnan:
     if (interp__builtin_isnan(S, OpPC, Frame, F))
-      return Ret<PT_Sint32>(S, OpPC, Dummy);
+      return retInt(S, OpPC, Dummy);
     break;
 
   case Builtin::BI__builtin_isinf:
     if (interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/false))
-      return Ret<PT_Sint32>(S, OpPC, Dummy);
+      return retInt(S, OpPC, Dummy);
     break;
 
   case Builtin::BI__builtin_isinf_sign:
     if (interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/true))
-      return Ret<PT_Sint32>(S, OpPC, Dummy);
+      return retInt(S, OpPC, Dummy);
     break;
 
   case Builtin::BI__builtin_isfinite:
     if (interp__builtin_isfinite(S, OpPC, Frame, F))
-      return Ret<PT_Sint32>(S, OpPC, Dummy);
+      return retInt(S, OpPC, Dummy);
     break;
   case Builtin::BI__builtin_isnormal:
     if (interp__builtin_isnormal(S, OpPC, Frame, F))
-      return Ret<PT_Sint32>(S, OpPC, Dummy);
+      return retInt(S, OpPC, Dummy);
     break;
   case Builtin::BI__builtin_isfpclass:
     if (interp__builtin_isfpclass(S, OpPC, Frame, F, Call))
-      return Ret<PT_Sint32>(S, OpPC, Dummy);
+      return retInt(S, OpPC, Dummy);
     break;
   case Builtin::BI__builtin_fpclassify:
     if (interp__builtin_fpclassify(S, OpPC, Frame, F))
-      return Ret<PT_Sint32>(S, OpPC, Dummy);
+      return retInt(S, OpPC, Dummy);
     break;
 
   case Builtin::BI__builtin_fabs:
Index: clang/lib/AST/Interp/Integral.h
===================================================================
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -95,6 +95,7 @@
   explicit operator unsigned() const { return V; }
   explicit operator int64_t() const { return V; }
   explicit operator uint64_t() const { return V; }
+  explicit operator int32_t() const { return V; }
 
   APSInt toAPSInt() const {
     return APSInt(APInt(Bits, static_cast<uint64_t>(V), Signed), !Signed);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to