Skip to content

[Clang][NFC] Avoid copies by using std::move #146960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shafik
Copy link
Collaborator

@shafik shafik commented Jul 3, 2025

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.

Static analysis flagged this code as using copies when we could use move
instead.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. labels Jul 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2025

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/146960.diff

2 Files Affected:

  • (modified) clang/include/clang/AST/Type.h (+3-3)
  • (modified) clang/lib/CodeGen/Targets/SPIR.cpp (+2-4)
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: {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants