Skip to content

[Clang][NFC] Explicitly delete copy ctor and assignment for CGAtomicOptionsRAII #137275

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

Conversation

shafik
Copy link
Collaborator

@shafik shafik commented Apr 25, 2025

Static analysis flagged CGAtomicOptionsRAII as having an explicit destructor but not having explicit copy ctor and assignment. Rule of three says we should. We are just using this as an RAII object, no need for either so they will be specified as deleted.

…ptionsRAII

Static analysis flagged CGAtomicOptionsRAII as having an explicit destructor
but not having explict copy ctor and assignment. Rule of three says we should.
We are just using this as an RAII object, no need for either so they will be
specified as deleted.
@shafik shafik added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Apr 25, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Apr 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 25, 2025

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

Changes

Static analysis flagged CGAtomicOptionsRAII as having an explicit destructor but not having explicit copy ctor and assignment. Rule of three says we should. We are just using this as an RAII object, no need for either so they will be specified as deleted.


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

1 Files Affected:

  • (modified) clang/lib/CodeGen/CodeGenFunction.h (+3)
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 4c5e8a8a44926..561f8f6a2a2fb 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -869,6 +869,9 @@ class CodeGenFunction : public CodeGenTypeCache {
       }
       CGM.setAtomicOpts(AO);
     }
+
+    CGAtomicOptionsRAII(const CGAtomicOptionsRAII &) = delete;
+    CGAtomicOptionsRAII &operator=(const CGAtomicOptionsRAII &) = delete;
     ~CGAtomicOptionsRAII() { CGM.setAtomicOpts(SavedAtomicOpts); }
 
   private:

@llvmbot
Copy link
Member

llvmbot commented Apr 25, 2025

@llvm/pr-subscribers-clang-codegen

Author: Shafik Yaghmour (shafik)

Changes

Static analysis flagged CGAtomicOptionsRAII as having an explicit destructor but not having explicit copy ctor and assignment. Rule of three says we should. We are just using this as an RAII object, no need for either so they will be specified as deleted.


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

1 Files Affected:

  • (modified) clang/lib/CodeGen/CodeGenFunction.h (+3)
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 4c5e8a8a44926..561f8f6a2a2fb 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -869,6 +869,9 @@ class CodeGenFunction : public CodeGenTypeCache {
       }
       CGM.setAtomicOpts(AO);
     }
+
+    CGAtomicOptionsRAII(const CGAtomicOptionsRAII &) = delete;
+    CGAtomicOptionsRAII &operator=(const CGAtomicOptionsRAII &) = delete;
     ~CGAtomicOptionsRAII() { CGM.setAtomicOpts(SavedAtomicOpts); }
 
   private:

@shafik shafik requested a review from cor3ntin May 1, 2025 01:18
@shafik shafik merged commit 4768173 into llvm:main May 1, 2025
15 checks passed
@shafik shafik deleted the cgatomicoptionsraii_explicit_special_members_bc_dest branch May 2, 2025 04:36
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