Make ReturnInst accept a value of type void as the return value. The
authorAlkis Evlogimenos <alkis@evlogimenos.com>
Wed, 17 Nov 2004 21:02:25 +0000 (21:02 +0000)
committerAlkis Evlogimenos <alkis@evlogimenos.com>
Wed, 17 Nov 2004 21:02:25 +0000 (21:02 +0000)
ReturnInst constructed is the same as if NULL was passed instead of
the void value.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17923 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Instructions.h
lib/VMCore/Instructions.cpp

index 714f7d7fb6e13c6e392a1c03defc815a04e06b2c..b52ebd9acaacf92ab90700763452669bb14e0188 100644 (file)
@@ -807,23 +807,20 @@ class ReturnInst : public TerminatorInst {
     }
   }
 
-  void init(Value *RetVal) {
-    if (RetVal) {
-      assert(!isa<BasicBlock>(RetVal) && 
-             "Cannot return basic block.  Probably using the incorrect ctor");
-      Operands.reserve(1);
-      Operands.push_back(Use(RetVal, this));
-    }
-  }
+  void init(Value *RetVal);
 
 public:
   // ReturnInst constructors:
   // ReturnInst()                  - 'ret void' instruction
+  // ReturnInst(    null)          - 'ret void' instruction
   // ReturnInst(Value* X)          - 'ret X'    instruction
   // ReturnInst(    null, Inst *)  - 'ret void' instruction, insert before I
   // ReturnInst(Value* X, Inst *I) - 'ret X'    instruction, insert before I
   // ReturnInst(    null, BB *B)   - 'ret void' instruction, insert @ end of BB
   // ReturnInst(Value* X, BB *B)   - 'ret X'    instruction, insert @ end of BB
+  //
+  // NOTE: If the Value* passed is of type void then the constructor behaves as
+  // if it was passed NULL.
   ReturnInst(Value *RetVal = 0, Instruction *InsertBefore = 0)
     : TerminatorInst(Instruction::Ret, InsertBefore) {
     init(RetVal);
index 029ee6a0f6b5c83de203207fbb45ea42861d7c9e..44167cbae714ce8e2e79dc48e9a181ab8fb51da5 100644 (file)
@@ -233,6 +233,15 @@ Function *CallSite::getCalledFunction() const {
 //                        ReturnInst Implementation
 //===----------------------------------------------------------------------===//
 
+void ReturnInst::init(Value* RetVal) {
+  if (RetVal && RetVal->getType() != Type::VoidTy) {
+    assert(!isa<BasicBlock>(RetVal) && 
+           "Cannot return basic block.  Probably using the incorrect ctor");
+    Operands.reserve(1);
+    Operands.push_back(Use(RetVal, this));
+  }
+}
+
 // Out-of-line ReturnInst method, put here so the C++ compiler can choose to
 // emit the vtable for the class in this translation unit.
 void ReturnInst::setSuccessor(unsigned idx, BasicBlock *NewSucc) {