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(V), Signed), !Signed); Index: clang/lib/AST/Interp/InterpBuiltin.cpp =================================================================== --- clang/lib/AST/Interp/InterpBuiltin.cpp +++ clang/lib/AST/Interp/InterpBuiltin.cpp @@ -32,6 +32,19 @@ 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>::from(Val)); + else if (IntWidth == 16) + S.Stk.push>(Integral<16, true>::from(Val)); + else + 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(Frame, 0); @@ -67,7 +80,7 @@ break; } - S.Stk.push>(Integral<32, true>::from(Result)); + pushInt(S, Result); return true; } @@ -201,7 +214,7 @@ const InterpFrame *Frame, const Function *F) { const Floating &Arg = S.Stk.peek(); - S.Stk.push>(Integral<32, true>::from(Arg.isNan())); + pushInt(S, Arg.isNan()); return true; } @@ -212,10 +225,9 @@ bool IsInf = Arg.isInf(); if (CheckSign) - S.Stk.push>( - 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>::from(Arg.isInf())); + pushInt(S, Arg.isInf()); return true; } @@ -224,7 +236,7 @@ const Function *F) { const Floating &Arg = S.Stk.peek(); - S.Stk.push>(Integral<32, true>::from(Arg.isFinite())); + pushInt(S, Arg.isFinite()); return true; } @@ -233,7 +245,7 @@ const Function *F) { const Floating &Arg = S.Stk.peek(); - S.Stk.push>(Integral<32, true>::from(Arg.isNormal())); + pushInt(S, Arg.isNormal()); return true; } @@ -250,12 +262,12 @@ int32_t Result = static_cast((F.classify() & FPClassArg).getZExtValue()); - S.Stk.push>(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) { @@ -281,8 +293,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>(Offset); - S.Stk.push>(I); + pushInt(S, static_cast(I)); return true; }