bug 122:
authorReid Spencer <rspencer@reidspencer.com>
Sun, 18 Jul 2004 00:01:50 +0000 (00:01 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Sun, 18 Jul 2004 00:01:50 +0000 (00:01 +0000)
- Correct isa<Constant> for GlobalValue subclass

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

lib/VMCore/Value.cpp

index a4f2669de0126be24aa08d7d7fb123d6a3069f74..d14d1656a473c378ec9c2752bbfee95ed3185d26 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constant.h"
+#include "llvm/GlobalValue.h"
 #include "Support/LeakDetector.h"
 #include <algorithm>
 #include <iostream>
@@ -71,7 +72,10 @@ void Value::uncheckedReplaceAllUsesWith(Value *New) {
     // Must handle Constants specially, we cannot call replaceUsesOfWith on a
     // constant!
     if (Constant *C = dyn_cast<Constant>(U.getUser())) {
-      C->replaceUsesOfWithOnConstant(this, New, true);
+      if (!isa<GlobalValue>(C))
+        C->replaceUsesOfWithOnConstant(this, New, true);
+      else 
+        U.set(New);
     } else {
       U.set(New);
     }
@@ -97,7 +101,7 @@ void Value::replaceAllUsesWith(Value *New) {
 void User::replaceUsesOfWith(Value *From, Value *To) {
   if (From == To) return;   // Duh what?
 
-  assert(!isa<Constant>(this) &&
+  assert(!isa<Constant>(this) || isa<GlobalValue>(this) &&
          "Cannot call User::replaceUsesofWith on a constant!");
 
   for (unsigned i = 0, E = getNumOperands(); i != E; ++i)
@@ -108,3 +112,4 @@ void User::replaceUsesOfWith(Value *From, Value *To) {
       setOperand(i, To); // Fix it now...
     }
 }
+