Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,14 @@ bool AddSubMulHelper(InterpState &S, CodePtr OpPC, unsigned Bits, const T &LHS,
APSInt Value = OpAP<APSInt>()(LHS.toAPSInt(Bits), RHS.toAPSInt(Bits));

// Report undefined behaviour, stopping if required.
const Expr *E = S.Current->getExpr(OpPC);
QualType Type = E->getType();
if (S.checkingForUndefinedBehavior()) {
const Expr *E = S.Current->getExpr(OpPC);
QualType Type = E->getType();
SmallString<32> Trunc;
Value.trunc(Result.bitWidth())
.toString(Trunc, 10, Result.isSigned(), /*formatAsCLiteral=*/false,
/*UpperCase=*/true, /*InsertSeparators=*/true);
auto Loc = E->getExprLoc();
S.report(Loc, diag::warn_integer_constant_overflow)
S.report(E->getExprLoc(), diag::warn_integer_constant_overflow)
<< Trunc << Type << E->getSourceRange();
}

Expand Down Expand Up @@ -737,16 +736,14 @@ bool Neg(InterpState &S, CodePtr OpPC) {
S.Stk.push<T>(Result);

APSInt NegatedValue = -Value.toAPSInt(Value.bitWidth() + 1);
const Expr *E = S.Current->getExpr(OpPC);
QualType Type = E->getType();

if (S.checkingForUndefinedBehavior()) {
const Expr *E = S.Current->getExpr(OpPC);
QualType Type = E->getType();
SmallString<32> Trunc;
NegatedValue.trunc(Result.bitWidth())
.toString(Trunc, 10, Result.isSigned(), /*formatAsCLiteral=*/false,
/*UpperCase=*/true, /*InsertSeparators=*/true);
auto Loc = E->getExprLoc();
S.report(Loc, diag::warn_integer_constant_overflow)
S.report(E->getExprLoc(), diag::warn_integer_constant_overflow)
<< Trunc << Type << E->getSourceRange();
return true;
}
Expand Down Expand Up @@ -800,15 +797,14 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
APResult = --Value.toAPSInt(Bits);

// Report undefined behaviour, stopping if required.
const Expr *E = S.Current->getExpr(OpPC);
QualType Type = E->getType();
if (S.checkingForUndefinedBehavior()) {
const Expr *E = S.Current->getExpr(OpPC);
QualType Type = E->getType();
SmallString<32> Trunc;
APResult.trunc(Result.bitWidth())
.toString(Trunc, 10, Result.isSigned(), /*formatAsCLiteral=*/false,
/*UpperCase=*/true, /*InsertSeparators=*/true);
auto Loc = E->getExprLoc();
S.report(Loc, diag::warn_integer_constant_overflow)
S.report(E->getExprLoc(), diag::warn_integer_constant_overflow)
<< Trunc << Type << E->getSourceRange();
return true;
}
Expand Down