[llvm] r226470 - Produce errors when an assignment expression would use a common symbol.

Rafael Espindola rafael.espindola at gmail.com
Mon Jan 19 09:30:25 PST 2015


Author: rafael
Date: Mon Jan 19 11:30:24 2015
New Revision: 226470

URL: http://llvm.org/viewvc/llvm-project?rev=226470&view=rev
Log:
Produce errors when an assignment expression would use a common symbol.

An assignment will produce a symbol with a given section and offset. There is
no way to represent something like "1 byte after a common symbol".

This matches the behavior of GNU as.

Part of PR22217.

Added:
    llvm/trunk/test/MC/ELF/common-error1.s
    llvm/trunk/test/MC/ELF/common-error2.s
Modified:
    llvm/trunk/lib/MC/MCAssembler.cpp

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=226470&r1=226469&r2=226470&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Mon Jan 19 11:30:24 2015
@@ -201,7 +201,17 @@ const MCSymbol *MCAsmLayout::getBaseSymb
   if (!A)
     return nullptr;
 
-  return &A->getSymbol();
+  const MCSymbol &ASym = A->getSymbol();
+  const MCAssembler &Asm = getAssembler();
+  const MCSymbolData &ASD = Asm.getSymbolData(ASym);
+  if (ASD.isCommon()) {
+    // FIXME: we should probably add a SMLoc to MCExpr.
+    Asm.getContext().FatalError(SMLoc(),
+                                "Common symbol " + ASym.getName() +
+                                    " cannot be used in assignment expr");
+  }
+
+  return &ASym;
 }
 
 uint64_t MCAsmLayout::getSectionAddressSize(const MCSectionData *SD) const {

Added: llvm/trunk/test/MC/ELF/common-error1.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/common-error1.s?rev=226470&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/common-error1.s (added)
+++ llvm/trunk/test/MC/ELF/common-error1.s Mon Jan 19 11:30:24 2015
@@ -0,0 +1,6 @@
+// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux < %s 2>&1 | FileCheck %s
+
+        .comm   C,4,4
+        .set    A,C
+
+// CHECK: Common symbol C cannot be used in assignment expr

Added: llvm/trunk/test/MC/ELF/common-error2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/common-error2.s?rev=226470&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/common-error2.s (added)
+++ llvm/trunk/test/MC/ELF/common-error2.s Mon Jan 19 11:30:24 2015
@@ -0,0 +1,6 @@
+// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux < %s 2>&1 | FileCheck %s
+
+        .set    A,C
+        .comm   C,4,4
+
+// CHECK: Common symbol C cannot be used in assignment expr





More information about the llvm-commits mailing list