[clang] [Clang][NFC] Avoid copies by using std::move (PR #146960)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 3 13:32:31 PDT 2025
https://github.com/shafik created https://github.com/llvm/llvm-project/pull/146960
Static analysis flagged this code as using copies when we could use move instead. I used a temporary in some cases instead of an explicit move.
>From 672514ff2ab201ea9d3098f4a94251155533ce55 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <shafik.yaghmour at intel.com>
Date: Thu, 3 Jul 2025 13:27:35 -0700
Subject: [PATCH] [Clang][NFC] Avoid copies by using std::move
Static analysis flagged this code as using copies when we could use move
instead.
---
clang/include/clang/AST/Type.h | 6 +++---
clang/lib/CodeGen/Targets/SPIR.cpp | 6 ++----
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1a87608e5be34..21b97102db95a 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -6404,7 +6404,7 @@ class SpirvOperand {
SpirvOperand() : Kind(Invalid), ResultType(), Value() {}
SpirvOperand(SpirvOperandKind Kind, QualType ResultType, llvm::APInt Value)
- : Kind(Kind), ResultType(ResultType), Value(Value) {}
+ : Kind(Kind), ResultType(ResultType), Value(std::move(Value)) {}
SpirvOperand(const SpirvOperand &Other) { *this = Other; }
~SpirvOperand() {}
@@ -6438,11 +6438,11 @@ class SpirvOperand {
}
static SpirvOperand createConstant(QualType ResultType, llvm::APInt Val) {
- return SpirvOperand(ConstantId, ResultType, Val);
+ return SpirvOperand(ConstantId, ResultType, std::move(Val));
}
static SpirvOperand createLiteral(llvm::APInt Val) {
- return SpirvOperand(Literal, QualType(), Val);
+ return SpirvOperand(Literal, QualType(), std::move(Val));
}
static SpirvOperand createType(QualType T) {
diff --git a/clang/lib/CodeGen/Targets/SPIR.cpp b/clang/lib/CodeGen/Targets/SPIR.cpp
index 845b0f4b58461..a66de79ed7cd1 100644
--- a/clang/lib/CodeGen/Targets/SPIR.cpp
+++ b/clang/lib/CodeGen/Targets/SPIR.cpp
@@ -421,14 +421,12 @@ static llvm::Type *getInlineSpirvType(CodeGenModule &CGM,
case SpirvOperandKind::ConstantId: {
llvm::Type *IntegralType =
CGM.getTypes().ConvertType(Operand.getResultType());
- llvm::APInt Value = Operand.getValue();
- Result = getInlineSpirvConstant(CGM, IntegralType, Value);
+ Result = getInlineSpirvConstant(CGM, IntegralType, Operand.getValue());
break;
}
case SpirvOperandKind::Literal: {
- llvm::APInt Value = Operand.getValue();
- Result = getInlineSpirvConstant(CGM, nullptr, Value);
+ Result = getInlineSpirvConstant(CGM, nullptr, Operand.getValue());
break;
}
case SpirvOperandKind::TypeId: {
More information about the cfe-commits
mailing list