[llvm] 27d09e6 - [SandboxIR] Make some instruction constructors private (#119901)

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 10:19:21 PST 2024


Author: vporpo
Date: 2024-12-13T10:19:17-08:00
New Revision: 27d09e683f59707e82be0500930fbab1c82a29b4

URL: https://github.com/llvm/llvm-project/commit/27d09e683f59707e82be0500930fbab1c82a29b4
DIFF: https://github.com/llvm/llvm-project/commit/27d09e683f59707e82be0500930fbab1c82a29b4.diff

LOG: [SandboxIR] Make some instruction constructors private (#119901)

This patch changes the visibility of the constructors of CatchSwitchInst
ResumeInst and SwitchInst to private instead of public. This is similar
to all other Sandbox IR instructions. The constructor is private to
force the user go through the Context create* API.

The issue was exposed by:
https://github.com/llvm/llvm-project/pull/119824

Added: 
    

Modified: 
    llvm/include/llvm/SandboxIR/Instruction.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/SandboxIR/Instruction.h b/llvm/include/llvm/SandboxIR/Instruction.h
index d9b0e937258135..4d21c4d3da3556 100644
--- a/llvm/include/llvm/SandboxIR/Instruction.h
+++ b/llvm/include/llvm/SandboxIR/Instruction.h
@@ -1744,11 +1744,12 @@ class GetElementPtrInst final
 
 class CatchSwitchInst
     : public SingleLLVMInstructionImpl<llvm::CatchSwitchInst> {
-public:
   CatchSwitchInst(llvm::CatchSwitchInst *CSI, Context &Ctx)
       : SingleLLVMInstructionImpl(ClassID::CatchSwitch, Opcode::CatchSwitch,
                                   CSI, Ctx) {}
+  friend class Context; // For accessing the constructor in create*()
 
+public:
   static CatchSwitchInst *create(Value *ParentPad, BasicBlock *UnwindBB,
                                  unsigned NumHandlers, InsertPosition Pos,
                                  Context &Ctx, const Twine &Name = "");
@@ -1833,10 +1834,11 @@ class CatchSwitchInst
 };
 
 class ResumeInst : public SingleLLVMInstructionImpl<llvm::ResumeInst> {
-public:
   ResumeInst(llvm::ResumeInst *CSI, Context &Ctx)
       : SingleLLVMInstructionImpl(ClassID::Resume, Opcode::Resume, CSI, Ctx) {}
+  friend class Context; // For accessing the constructor in create*()
 
+public:
   static ResumeInst *create(Value *Exn, InsertPosition Pos, Context &Ctx);
   Value *getValue() const;
   unsigned getNumSuccessors() const {
@@ -1848,10 +1850,11 @@ class ResumeInst : public SingleLLVMInstructionImpl<llvm::ResumeInst> {
 };
 
 class SwitchInst : public SingleLLVMInstructionImpl<llvm::SwitchInst> {
-public:
   SwitchInst(llvm::SwitchInst *SI, Context &Ctx)
       : SingleLLVMInstructionImpl(ClassID::Switch, Opcode::Switch, SI, Ctx) {}
+  friend class Context; // For accessing the constructor in create*()
 
+public:
   static constexpr const unsigned DefaultPseudoIndex =
       llvm::SwitchInst::DefaultPseudoIndex;
 


        


More information about the llvm-commits mailing list