Author: Timm Baeder Date: 2025-02-02T12:25:08+01:00 New Revision: 642e84f0012b6e3a0e4f187bad5ee1775c3d623a
URL: https://github.com/llvm/llvm-project/commit/642e84f0012b6e3a0e4f187bad5ee1775c3d623a DIFF: https://github.com/llvm/llvm-project/commit/642e84f0012b6e3a0e4f187bad5ee1775c3d623a.diff LOG: [clang][bytecode][NFC] Only get expr when checking for UB (#125397) The Expr and its Type were unused otherwise. Added: Modified: clang/lib/AST/ByteCode/Interp.h Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 2a39e3932077f5..9f029adc708390 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -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(); } @@ -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; } @@ -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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits