From 374d8bddacbffce7c82ce81103d30b5ee42032df Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 30 Jun 2009 22:49:27 +0000 Subject: [PATCH] llvm-mc: Symbols in a relocatable expression of the (a - b + cst) form are allowed to be undefined when the expression is seen, we cannot enforce the same-section requirement until the entire assembly file has been seen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74565 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCValue.h | 7 +++---- test/MC/AsmParser/exprs.s | 7 +++++++ tools/llvm-mc/AsmExpr.cpp | 9 ++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/llvm/MC/MCValue.h b/include/llvm/MC/MCValue.h index df834c7de52..174992ebe0f 100644 --- a/include/llvm/MC/MCValue.h +++ b/include/llvm/MC/MCValue.h @@ -26,7 +26,8 @@ class MCSymbol; /// relocations of this general form, but we need to represent this anyway. /// /// In the general form, SymbolB can only be defined if SymbolA is, and both -/// must be in the same (non-external) section. +/// must be in the same (non-external) section. The latter constraint is not +/// enforced, since a symbol's section may not be known at construction. /// /// Note that this class must remain a simple POD value class, because we need /// it to live in unions etc. @@ -52,9 +53,7 @@ public: static MCValue get(MCSymbol *SymA, MCSymbol *SymB = 0, int64_t Val = 0) { MCValue R; - assert((!SymB || (SymA && SymA->getSection() && - SymA->getSection() == SymB->getSection())) && - "Invalid relocatable MCValue!"); + assert((!SymB || SymA) && "Invalid relocatable MCValue!"); R.Cst = Val; R.SymA = SymA; R.SymB = SymB; diff --git a/test/MC/AsmParser/exprs.s b/test/MC/AsmParser/exprs.s index 14bafd5e28a..20de3a5e0ba 100644 --- a/test/MC/AsmParser/exprs.s +++ b/test/MC/AsmParser/exprs.s @@ -52,4 +52,11 @@ k: i = (j + 10) - (k + 2) .long i + l = m - n + 4 + + .text +m: +n: + nop + \ No newline at end of file diff --git a/tools/llvm-mc/AsmExpr.cpp b/tools/llvm-mc/AsmExpr.cpp index 3c19be308b6..4b32b922935 100644 --- a/tools/llvm-mc/AsmExpr.cpp +++ b/tools/llvm-mc/AsmExpr.cpp @@ -37,12 +37,11 @@ static bool EvaluateSymbolicAdd(const MCValue &LHS, MCSymbol *RHS_A, MCSymbol *A = LHS.getSymA() ? LHS.getSymA() : RHS_A; MCSymbol *B = LHS.getSymB() ? LHS.getSymB() : RHS_B; if (B) { - // If we have a negated symbol, then we must have also have a - // non-negated symbol, and both symbols must be in the same - // non-external section. We can do this check later to permit - // expressions which eventually fold to a representable form -- such + // If we have a negated symbol, then we must have also have a non-negated + // symbol in order to encode the expression. We can do this check later to + // permit expressions which eventually fold to a representable form -- such // as (a + (0 - b)) -- if necessary. - if (!A || !A->getSection() || A->getSection() != B->getSection()) + if (!A) return false; } Res = MCValue::get(A, B, LHS.getConstant() + RHS_Cst); -- 2.34.1