Skip to content

Commit

Permalink
[clang][Interp] Fix rotate builtins with differently-typed arguments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tbaederr committed Mar 14, 2024
1 parent ea2cfcc commit 65c0143
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions clang/lib/AST/Interp/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,12 @@ static bool interp__builtin_rotate(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func, const CallExpr *Call,
bool Right) {
PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
assert(ArgT == *S.getContext().classify(Call->getArg(1)->getType()));
PrimType AmountT = *S.getContext().classify(Call->getArg(1)->getType());
PrimType ValueT = *S.getContext().classify(Call->getArg(0)->getType());

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

APSInt Result;
if (Right)
Expand Down
8 changes: 8 additions & 0 deletions clang/test/AST/Interp/ms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -verify=ref,both %s -fms-extensions
// RUN: %clang_cc1 -verify=expected,both %s -fexperimental-new-constant-interpreter -fms-extensions

// ref-no-diagnostics
// expected-no-diagnostics

/// Used to assert because the two parameters to _rotl do not have the same type.
static_assert(_rotl(0x01, 5) == 32);

0 comments on commit 65c0143

Please sign in to comment.