Make these methods const correct.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 25 Jul 2013 02:50:08 +0000 (02:50 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 25 Jul 2013 02:50:08 +0000 (02:50 +0000)
Thanks to Nick Lewycky for noticing it.

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

include/llvm/IR/Module.h
lib/IR/Module.cpp
lib/Transforms/IPO/GlobalOpt.cpp

index 2514be4faa333d86cb41928c434bc023b8a88185..3dbc5ffde743c6f077c2edf1dcc148dab964d227 100644 (file)
@@ -352,15 +352,22 @@ public:
   /// symbol table.  If it does not exist, return null. If AllowInternal is set
   /// to true, this function will return types that have InternalLinkage. By
   /// default, these types are not returned.
-  GlobalVariable *getGlobalVariable(StringRef Name,
-                                    bool AllowInternal = false) const;
+  const GlobalVariable *getGlobalVariable(StringRef Name,
+                                          bool AllowInternal = false) const {
+    return const_cast<Module *>(this)->getGlobalVariable(Name, AllowInternal);
+  }
+
+  GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal = false);
 
   /// getNamedGlobal - Return the global variable in the module with the
   /// specified name, of arbitrary type.  This method returns null if a global
   /// with the specified name is not found.
-  GlobalVariable *getNamedGlobal(StringRef Name) const {
+  GlobalVariable *getNamedGlobal(StringRef Name) {
     return getGlobalVariable(Name, true);
   }
+  const GlobalVariable *getNamedGlobal(StringRef Name) const {
+    return const_cast<Module *>(this)->getNamedGlobal(Name);
+  }
 
   /// getOrInsertGlobal - Look up the specified global in the module symbol
   /// table.
index 3d3dc737a1b5c50d427693227fe68d7845b62244..968b8f4b904ddc9835a1f251716af8fe2adf4706 100644 (file)
@@ -233,8 +233,7 @@ Function *Module::getFunction(StringRef Name) const {
 /// If AllowLocal is set to true, this function will return types that
 /// have an local. By default, these types are not returned.
 ///
-GlobalVariable *Module::getGlobalVariable(StringRef Name,
-                                          bool AllowLocal) const {
+GlobalVariable *Module::getGlobalVariable(StringRef Name, bool AllowLocal) {
   if (GlobalVariable *Result =
       dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
     if (AllowLocal || !Result->hasLocalLinkage())
index 183a599bc1226d476101d741efda8aa12f51b438..6250cc5ec45e11ceeb093aa67431fd725832b64a 100644 (file)
@@ -3043,7 +3043,7 @@ bool GlobalOpt::OptimizeGlobalCtorsList(GlobalVariable *&GCL) {
 /// \brief Given "llvm.used" or "llvm.compiler.used" as a global name, collect
 /// the initializer elements of that global in Set and return the global itself.
 static GlobalVariable *
-collectUsedGlobalVariables(const Module &M, const char *Name,
+collectUsedGlobalVariables(Module &M, const char *Name,
                            SmallPtrSet<GlobalValue *, 8> &Set) {
   GlobalVariable *GV = M.getGlobalVariable(Name);
   if (!GV || !GV->hasInitializer())
@@ -3106,7 +3106,7 @@ class LLVMUsed {
   GlobalVariable *CompilerUsedV;
 
 public:
-  LLVMUsed(const Module &M) {
+  LLVMUsed(Module &M) {
     UsedV = collectUsedGlobalVariables(M, "llvm.used", Used);
     CompilerUsedV =
         collectUsedGlobalVariables(M, "llvm.compiler.used", CompilerUsed);