From ffbe9ff668976c7bc916b9e462ef5578452f205b Mon Sep 17 00:00:00 2001 From: Eric Astor Date: Mon, 7 Sep 2020 14:00:05 -0400 Subject: [PATCH] [ms] [llvm-ml] Allow use of locally-defined variables in expressions MASM allows variables defined by equate statements to be used in expressions. Reviewed By: thakis Differential Revision: https://reviews.llvm.org/D86946 --- lib/MC/MCParser/MasmParser.cpp | 5 +++++ test/tools/llvm-ml/variable.test | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/tools/llvm-ml/variable.test diff --git a/lib/MC/MCParser/MasmParser.cpp b/lib/MC/MCParser/MasmParser.cpp index 333eef2f698..4d62174f7e5 100644 --- a/lib/MC/MCParser/MasmParser.cpp +++ b/lib/MC/MCParser/MasmParser.cpp @@ -3076,6 +3076,11 @@ bool MasmParser::parseDirectiveEquate(StringRef IDVal, StringRef Name, SMLoc EndLoc, StartLoc = Lexer.getLoc(); if (parseExpression(Expr, EndLoc)) return addErrorSuffix(" in '" + Twine(IDVal) + "' directive"); + MCSymbol *Sym = getContext().getOrCreateSymbol(Var.Name); + Sym->setRedefinable(Var.Redefinable); + Sym->setVariableValue(Expr); + Sym->setExternal(false); + if (Expr->evaluateAsAbsolute(Var.NumericValue, getStreamer().getAssemblerPtr())) return false; diff --git a/test/tools/llvm-ml/variable.test b/test/tools/llvm-ml/variable.test new file mode 100644 index 00000000000..4e89d67bd59 --- /dev/null +++ b/test/tools/llvm-ml/variable.test @@ -0,0 +1,13 @@ +# RUN: llvm-ml -filetype=asm %s | FileCheck %s + +.data +t1_value equ 1 or 2 + +t1 BYTE t1_value DUP (0) +; CHECK: t1: +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .byte 0 +; CHECK-NOT: .byte 0 + +END