[clang] 6efa366 - [Clang][NFC] Avoid copies by using std::move (#146960)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 7 17:53:49 PDT 2025
Author: Shafik Yaghmour
Date: 2025-07-07T17:53:45-07:00
New Revision: 6efa366b43686bd8b1ec509e589752535507866e
URL: https://github.com/llvm/llvm-project/commit/6efa366b43686bd8b1ec509e589752535507866e
DIFF: https://github.com/llvm/llvm-project/commit/6efa366b43686bd8b1ec509e589752535507866e.diff
LOG: [Clang][NFC] Avoid copies by using std::move (#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.
Added:
Modified:
clang/include/clang/AST/Type.h
clang/lib/CodeGen/Targets/SPIR.cpp
Removed:
################################################################################
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