Skip to content

Commit 65c0143

Browse files
committed
[clang][Interp] Fix rotate builtins with differently-typed arguments
We were assuming (and asserting) that both arguments have the same type, but at least for the ms versions, that's not always the case.
1 parent ea2cfcc commit 65c0143

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

clang/lib/AST/Interp/InterpBuiltin.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,12 @@ static bool interp__builtin_rotate(InterpState &S, CodePtr OpPC,
533533
const InterpFrame *Frame,
534534
const Function *Func, const CallExpr *Call,
535535
bool Right) {
536-
PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
537-
assert(ArgT == *S.getContext().classify(Call->getArg(1)->getType()));
536+
PrimType AmountT = *S.getContext().classify(Call->getArg(1)->getType());
537+
PrimType ValueT = *S.getContext().classify(Call->getArg(0)->getType());
538538

539-
APSInt Amount = peekToAPSInt(S.Stk, ArgT);
540-
APSInt Value = peekToAPSInt(S.Stk, ArgT, align(primSize(ArgT)) * 2);
539+
APSInt Amount = peekToAPSInt(S.Stk, AmountT);
540+
APSInt Value = peekToAPSInt(
541+
S.Stk, ValueT, align(primSize(AmountT)) + align(primSize(ValueT)));
541542

542543
APSInt Result;
543544
if (Right)

clang/test/AST/Interp/ms.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -verify=ref,both %s -fms-extensions
2+
// RUN: %clang_cc1 -verify=expected,both %s -fexperimental-new-constant-interpreter -fms-extensions
3+
4+
// ref-no-diagnostics
5+
// expected-no-diagnostics
6+
7+
/// Used to assert because the two parameters to _rotl do not have the same type.
8+
static_assert(_rotl(0x01, 5) == 32);

0 commit comments

Comments
 (0)