[clang] [CodeGen] Remove an unnecessary cast (NFC) (PR #146380)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 30 09:15:47 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/146380
E is already of Expr * and shares the same declaration among all these
cases.
>From 3af2bd3b3743d16c45f759ecc38eaa0167e777d4 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 29 Jun 2025 12:15:46 -0700
Subject: [PATCH] [CodeGen] Remove an unnecessary cast (NFC)
E is already of Expr * and shares the same declaration among all these
cases.
---
clang/lib/CodeGen/CGExprScalar.cpp | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 193710bef2d16..fc441dd92d1ee 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2440,7 +2440,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
case CK_BlockPointerToObjCPointerCast:
case CK_AnyPointerToBlockPointerCast:
case CK_BitCast: {
- Value *Src = Visit(const_cast<Expr*>(E));
+ Value *Src = Visit(E);
llvm::Type *SrcTy = Src->getType();
llvm::Type *DstTy = ConvertType(DestTy);
@@ -2606,11 +2606,10 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
case CK_AtomicToNonAtomic:
case CK_NonAtomicToAtomic:
case CK_UserDefinedConversion:
- return Visit(const_cast<Expr*>(E));
+ return Visit(E);
case CK_NoOp: {
- return CE->changesVolatileQualification() ? EmitLoadOfLValue(CE)
- : Visit(const_cast<Expr *>(E));
+ return CE->changesVolatileQualification() ? EmitLoadOfLValue(CE) : Visit(E);
}
case CK_BaseToDerived: {
@@ -2712,10 +2711,10 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
case CK_LValueToRValue:
assert(CGF.getContext().hasSameUnqualifiedType(E->getType(), DestTy));
assert(E->isGLValue() && "lvalue-to-rvalue applied to r-value!");
- return Visit(const_cast<Expr*>(E));
+ return Visit(E);
case CK_IntegralToPointer: {
- Value *Src = Visit(const_cast<Expr*>(E));
+ Value *Src = Visit(E);
// First, convert to the correct width so that we control the kind of
// extension.
@@ -2768,7 +2767,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
case CK_HLSLAggregateSplatCast:
case CK_VectorSplat: {
llvm::Type *DstTy = ConvertType(DestTy);
- Value *Elt = Visit(const_cast<Expr *>(E));
+ Value *Elt = Visit(E);
// Splat the element across to all elements
llvm::ElementCount NumElements =
cast<llvm::VectorType>(DstTy)->getElementCount();
@@ -2906,7 +2905,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
case CK_HLSLVectorTruncation: {
assert((DestTy->isVectorType() || DestTy->isBuiltinType()) &&
"Destination type must be a vector or builtin type.");
- Value *Vec = Visit(const_cast<Expr *>(E));
+ Value *Vec = Visit(E);
if (auto *VecTy = DestTy->getAs<VectorType>()) {
SmallVector<int> Mask;
unsigned NumElts = VecTy->getNumElements();
More information about the cfe-commits
mailing list