[llvm] r208094 - Be more strict about not calling setAlignment on global aliases.

Rafael Espindola rafael.espindola at gmail.com
Tue May 6 07:51:36 PDT 2014


Author: rafael
Date: Tue May  6 09:51:36 2014
New Revision: 208094

URL: http://llvm.org/viewvc/llvm-project?rev=208094&view=rev
Log:
Be more strict about not calling setAlignment on global aliases.

The fact that GlobalAlias::setAlignment exists at all is a side effect of
how the classes are organized, it should never be used.

Modified:
    llvm/trunk/lib/IR/Globals.cpp
    llvm/trunk/lib/Linker/LinkModules.cpp

Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=208094&r1=208093&r2=208094&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Tue May  6 09:51:36 2014
@@ -53,15 +53,18 @@ void GlobalValue::destroyConstant() {
 /// copyAttributesFrom - copy all additional attributes (those not needed to
 /// create a GlobalValue) from the GlobalValue Src to this one.
 void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
-  setAlignment(Src->getAlignment());
-  setSection(Src->getSection());
+  if (!isa<GlobalAlias>(this)) {
+    setAlignment(Src->getAlignment());
+    setSection(Src->getSection());
+  }
+
   setVisibility(Src->getVisibility());
   setUnnamedAddr(Src->hasUnnamedAddr());
   setDLLStorageClass(Src->getDLLStorageClass());
 }
 
 void GlobalValue::setAlignment(unsigned Align) {
-  assert((!isa<GlobalAlias>(this) || !Align) &&
+  assert((!isa<GlobalAlias>(this)) &&
          "GlobalAlias should not have an alignment!");
   assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
   assert(Align <= MaximumAlignment &&

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=208094&r1=208093&r2=208094&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Tue May  6 09:51:36 2014
@@ -495,10 +495,16 @@ static void forceRenaming(GlobalValue *G
 /// a GlobalValue) from the SrcGV to the DestGV.
 static void copyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
   // Use the maximum alignment, rather than just copying the alignment of SrcGV.
-  unsigned Alignment = std::max(DestGV->getAlignment(), SrcGV->getAlignment());
+  unsigned Alignment;
+  bool IsAlias = isa<GlobalAlias>(DestGV);
+  if (!IsAlias)
+    Alignment = std::max(DestGV->getAlignment(), SrcGV->getAlignment());
+
   DestGV->copyAttributesFrom(SrcGV);
-  DestGV->setAlignment(Alignment);
-  
+
+  if (!IsAlias)
+    DestGV->setAlignment(Alignment);
+
   forceRenaming(DestGV, SrcGV->getName());
 }
 





More information about the llvm-commits mailing list