tbaeder created this revision. tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Integers might not be 32 bits wide, so check the TargetInfo for their size. Repository: rG LLVM Github Monorepo 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,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>>(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 interp__builtin_strcmp(InterpState &S, CodePtr OpPC, const InterpFrame *Frame) { const Pointer &A = getParam<Pointer>(Frame, 0); @@ -67,7 +80,7 @@ break; } - S.Stk.push<Integral<32, true>>(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<Floating>(); - S.Stk.push<Integral<32, true>>(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>>( - 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; } @@ -224,7 +236,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; } @@ -233,7 +245,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; } @@ -250,12 +262,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) { @@ -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<Integral<32, true>>(Offset); - S.Stk.push<Integral<32, true>>(I); + pushInt(S, static_cast<int32_t>(I)); return true; } 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