Be more strict about not calling setAlignment on global aliases.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 6 May 2014 14:51:36 +0000 (14:51 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 6 May 2014 14:51:36 +0000 (14:51 +0000)
The fact that GlobalAlias::setAlignment exists at all is a side effect of
how the classes are organized, it should never be used.

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

lib/IR/Globals.cpp
lib/Linker/LinkModules.cpp

index a6cd03e622a2bc488636ff7b8625313c668e9ce4..0b49350e5519db932c80044babda53d99636a9bf 100644 (file)
@@ -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 &&
index 581e8217deebd3ae6384e3be6598b303d75be758..55654ac25d693d9f56adea9eb7b7b8ea6b3f2273 100644 (file)
@@ -495,10 +495,16 @@ static void forceRenaming(GlobalValue *GV, StringRef Name) {
 /// 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());
 }