Check that GlobalAliases don't have section or alignment.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 13 Feb 2014 18:26:41 +0000 (18:26 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 13 Feb 2014 18:26:41 +0000 (18:26 +0000)
An alias is always in the section of its aliasee and has the same alignment
(since it has the same address).

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

include/llvm/IR/GlobalValue.h
lib/IR/Globals.cpp
lib/IR/Verifier.cpp

index 5fdf6611e9a23601ef7a0b13e14f6a6480040aa7..f0c80673be167f4cd0a993ff34493f435455465e 100644 (file)
@@ -112,8 +112,12 @@ public:
 
   bool hasSection() const { return !Section.empty(); }
   const std::string &getSection() const { return Section; }
-  void setSection(StringRef S) { Section = S; }
-  
+  void setSection(StringRef S) {
+    assert((getValueID() != Value::GlobalAliasVal || S.empty()) &&
+           "GlobalAlias should not have a section!");
+    Section = S;
+  }
+
   /// If the usage is empty (except transitively dead constants), then this
   /// global value can be safely deleted since the destructor will
   /// delete the dead constants as well.
index a70ea0f37b904a22e861d7c5f0a74ecc2736e515..5ad96b2ce3af93db7f2dae20da0d5fed477e8fe8 100644 (file)
@@ -57,6 +57,8 @@ void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
 }
 
 void GlobalValue::setAlignment(unsigned Align) {
+  assert((!isa<GlobalAlias>(this) || !Align) &&
+         "GlobalAlias should not have an alignment!");
   assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
   assert(Align <= MaximumAlignment &&
          "Alignment is greater than MaximumAlignment!");
index f81260960e8ebb006b688d73ba3e54319361374e..73496b4f55d70a150d192d8bf747b4e64649685b 100644 (file)
@@ -475,6 +475,8 @@ void Verifier::visitGlobalAlias(const GlobalAlias &GA) {
   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);
+  Assert1(!GA.getAlignment(), "Alias connot have an alignment", &GA);
 
   const Constant *Aliasee = GA.getAliasee();