llvm-mc: When handling a .set, make sure to print subsequent references to the
authorDaniel Dunbar <daniel@zuster.org>
Fri, 14 Aug 2009 19:10:46 +0000 (19:10 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 14 Aug 2009 19:10:46 +0000 (19:10 +0000)
symbol as the symbol name itself, not the expression it was defined to. These
have different semantics due to the quirky .set behavior (which absolutizes an
expression that would otherwise be treated as a relocation).

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

lib/MC/MCAsmStreamer.cpp
test/MC/AsmParser/labels.s

index 43ce04ffdfd1c4c70184eeabdeae89b95dc6348e..41f88334e2b76440e4c4e3690f63a194a4780268 100644 (file)
@@ -136,11 +136,18 @@ void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value,
 
   if (MakeAbsolute) {
     OS << ".set " << Symbol << ", " << Value << '\n';
+
+    // HACK: If the value isn't already absolute, set the symbol value to
+    // itself, we want to use the .set absolute value, not the actual
+    // expression.
+    if (!Value.isAbsolute())
+      getContext().SetSymbolValue(Symbol, MCValue::get(Symbol));
+    else
+      getContext().SetSymbolValue(Symbol, Value);
   } else {
     OS << Symbol << " = " << Value << '\n';
+    getContext().SetSymbolValue(Symbol, Value);
   }
-
-  getContext().SetSymbolValue(Symbol, Value);
 }
 
 void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol, 
index c9cb44eaf0fcd44d982418608843f6bbc0b1ee27..f306685256858c8018bc42389d42f54605f25cce 100644 (file)
@@ -23,9 +23,9 @@ foo:
 // CHECK: addl $10, %eax
         addl "b$c", %eax
         
-        
 // CHECK: set "a 0", 11
-.set "a 0", 11
+        .set "a 0", 11
+        
 // CHECK: .long 11
         .long "a 0"
 
@@ -49,3 +49,9 @@ foo:
 
 // CHECK: .lsym "a 8",1
         .lsym "a 8", 1
+
+// CHECK: set "a 9", a - b
+        .set "a 9", a - b
+        
+// CHECK: .long "a 9"
+        .long "a 9"