[clang] [clang][bytecode][NFC] Only get expr when checking for UB (PR #125397)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 2 03:02:07 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
The Expr and its Type were unused otherwise.
---
Full diff: https://github.com/llvm/llvm-project/pull/125397.diff
1 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.h (+9-13)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 2a39e3932077f57..9f029adc7083908 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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/125397
More information about the cfe-commits
mailing list