[llvm] r208139 - Special case aliases in GlobalValue::getSection.

Rafael Espindola rafael.espindola at gmail.com
Tue May 6 15:44:30 PDT 2014


Author: rafael
Date: Tue May  6 17:44:30 2014
New Revision: 208139

URL: http://llvm.org/viewvc/llvm-project?rev=208139&view=rev
Log:
Special case aliases in GlobalValue::getSection.

This is similar to the getAlignment patch, but is done just for
completeness. It looks like we never call getSection on an alias. All the
tests still pass if the if is replaced with an assert.

Modified:
    llvm/trunk/include/llvm/IR/GlobalValue.h
    llvm/trunk/lib/IR/Globals.cpp
    llvm/trunk/lib/IR/Verifier.cpp

Modified: llvm/trunk/include/llvm/IR/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalValue.h?rev=208139&r1=208138&r2=208139&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalValue.h Tue May  6 17:44:30 2014
@@ -106,8 +106,8 @@ public:
   }
   void setDLLStorageClass(DLLStorageClassTypes C) { DllStorageClass = C; }
 
-  bool hasSection() const { return !Section.empty(); }
-  const std::string &getSection() const { return Section; }
+  bool hasSection() const { return !getSection().empty(); }
+  const std::string &getSection() const;
   void setSection(StringRef S);
 
   /// getType - Global values are always pointers.

Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=208139&r1=208138&r2=208139&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Tue May  6 17:44:30 2014
@@ -80,6 +80,12 @@ void GlobalValue::setAlignment(unsigned
   assert(getAlignment() == Align && "Alignment representation error!");
 }
 
+const std::string &GlobalValue::getSection() const {
+  if (auto *GA = dyn_cast<GlobalAlias>(this))
+    return GA->getAliasedGlobal()->getSection();
+  return Section;
+}
+
 void GlobalValue::setSection(StringRef S) {
   assert(!isa<GlobalAlias>(this) && "GlobalAlias should not have a section!");
   Section = S;

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=208139&r1=208138&r2=208139&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Tue May  6 17:44:30 2014
@@ -476,7 +476,6 @@ void Verifier::visitGlobalAlias(const Gl
   Assert1(GA.getType() == GA.getAliasee()->getType(),
           "Alias and aliasee types should match!", &GA);
   Assert1(!GA.hasUnnamedAddr(), "Alias cannot have unnamed_addr!", &GA);
-  Assert1(!GA.hasSection(), "Alias cannot have a section!", &GA);
 
   const Constant *Aliasee = GA.getAliasee();
   const GlobalValue *GV = dyn_cast<GlobalValue>(Aliasee);





More information about the llvm-commits mailing list