[llvm] ded0a70 - [AsmParser][SystemZ][z/OS] Reject "Dot" as current PC on z/OS
Anirudh Prasad via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 29 08:59:00 PDT 2021
Author: Anirudh Prasad
Date: 2021-04-29T11:58:54-04:00
New Revision: ded0a70aeb08919922cdba5f4fcc7d7646e2ffe2
URL: https://github.com/llvm/llvm-project/commit/ded0a70aeb08919922cdba5f4fcc7d7646e2ffe2
DIFF: https://github.com/llvm/llvm-project/commit/ded0a70aeb08919922cdba5f4fcc7d7646e2ffe2.diff
LOG: [AsmParser][SystemZ][z/OS] Reject "Dot" as current PC on z/OS
- Currently, the "." (Dot) character, when not identifying an Identifier or a Constant, refers to the current PC (Program Counter)
- However, in z/OS, for the HLASM dialect, it strictly accepts only the "*" as the current PC (Support for this will be put up in a follow-up patch)
- The changes in this patch allow individual platforms to choose whether they would like to use the "." (Dot) character as a marker for the current PC or not.
- It is achieved by introducing a new field in MCAsmInfo.h called `DotIsPC` (similar to `DollarIsPC`)
Reviewed By: abhina.sreeskantharajan
Differential Revision: https://reviews.llvm.org/D100975
Added:
Modified:
llvm/include/llvm/MC/MCAsmInfo.h
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index f72cc709389d4..a0e7ba6e2a5aa 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -118,6 +118,10 @@ class MCAsmInfo {
/// the current PC. Defaults to false.
bool DollarIsPC = false;
+ /// Allow '.' token, when not referencing an identifier or constant, to refer
+ /// to the current PC. Defaults to true.
+ bool DotIsPC = true;
+
/// This string, if specified, is used to separate instructions from each
/// other when on the same line. Defaults to ';'
const char *SeparatorString;
@@ -593,6 +597,7 @@ class MCAsmInfo {
unsigned getMinInstAlignment() const { return MinInstAlignment; }
bool getDollarIsPC() const { return DollarIsPC; }
+ bool getDotIsPC() const { return DotIsPC; }
const char *getSeparatorString() const { return SeparatorString; }
/// This indicates the column (zero-based) at which asm comments should be
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index f2fb5714a6bc4..5d037931bb0f5 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -1245,6 +1245,9 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
return false;
}
case AsmToken::Dot: {
+ if (!MAI.getDotIsPC())
+ return TokError("cannot use . as current PC");
+
// This is a '.' reference, which references the current PC. Emit a
// temporary label to the streamer and refer to it.
MCSymbol *Sym = Ctx.createTempSymbol();
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
index 4bb9e15d4c4ad..6422ca93b6d77 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
@@ -27,6 +27,7 @@ SystemZMCAsmInfo::SystemZMCAsmInfo(const Triple &TT) {
AllowAtAtStartOfIdentifier = (AssemblerDialect == AD_HLASM);
AllowDollarAtStartOfIdentifier = (AssemblerDialect == AD_HLASM);
AllowHashAtStartOfIdentifier = (AssemblerDialect == AD_HLASM);
+ DotIsPC = (AssemblerDialect == AD_ATT);
ZeroDirective = "\t.space\t";
Data64bitsDirective = "\t.quad\t";
diff --git a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
index 81180966708e6..6c868ce861674 100644
--- a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
+++ b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
@@ -47,6 +47,7 @@ class MockedUpMCAsmInfo : public MCAsmInfo {
void setAllowHashAtStartOfIdentifier(bool Value) {
AllowHashAtStartOfIdentifier = Value;
}
+ void setAllowDotIsPC(bool Value) { DotIsPC = Value; }
};
// Setup a testing class that the GTest framework can call.
@@ -55,6 +56,7 @@ class SystemZAsmLexerTest : public ::testing::Test {
static void SetUpTestCase() {
LLVMInitializeSystemZTargetInfo();
LLVMInitializeSystemZTargetMC();
+ LLVMInitializeSystemZAsmParser();
}
std::unique_ptr<MCRegisterInfo> MRI;
@@ -63,6 +65,8 @@ class SystemZAsmLexerTest : public ::testing::Test {
std::unique_ptr<MCStreamer> Str;
std::unique_ptr<MCAsmParser> Parser;
std::unique_ptr<MCContext> Ctx;
+ std::unique_ptr<MCSubtargetInfo> STI;
+ std::unique_ptr<MCTargetAsmParser> TargetAsmParser;
SourceMgr SrcMgr;
std::string TripleName;
@@ -85,6 +89,12 @@ class SystemZAsmLexerTest : public ::testing::Test {
MRI.reset(TheTarget->createMCRegInfo(TripleName));
EXPECT_NE(MRI, nullptr);
+ MII.reset(TheTarget->createMCInstrInfo());
+ EXPECT_NE(MII, nullptr);
+
+ STI.reset(TheTarget->createMCSubtargetInfo(TripleName, "z10", ""));
+ EXPECT_NE(STI, nullptr);
+
std::unique_ptr<MCAsmInfo> MAI;
MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
EXPECT_NE(MAI, nullptr);
@@ -109,6 +119,10 @@ class SystemZAsmLexerTest : public ::testing::Test {
Str.reset(TheTarget->createNullStreamer(*Ctx));
Parser.reset(createMCAsmParser(SrcMgr, *Ctx, *Str, *MUPMAI));
+
+ TargetAsmParser.reset(
+ TheTarget->createMCAsmParser(*STI, *Parser, *MII, MCOptions));
+ Parser->setTargetParser(*TargetAsmParser);
}
void lexAndCheckTokens(StringRef AsmStr,
@@ -655,4 +669,20 @@ TEST_F(SystemZAsmLexerTest, CheckAcceptHashAtStartOfIdentifier4) {
{AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
lexAndCheckTokens(AsmStr, ExpectedTokens);
}
+
+TEST_F(SystemZAsmLexerTest, CheckRejectDotAsCurrentPC) {
+ StringRef AsmStr = ".-4";
+
+ // Setup.
+ MUPMAI->setAllowDotIsPC(false);
+ setupCallToAsmParser(AsmStr);
+
+ // Lex initially to get the string.
+ Parser->getLexer().Lex();
+
+ const MCExpr *Expr;
+ bool ParsePrimaryExpr = Parser->parseExpression(Expr);
+ EXPECT_EQ(ParsePrimaryExpr, true);
+ EXPECT_EQ(Parser->hasPendingError(), true);
+}
} // end anonymous namespace
More information about the llvm-commits
mailing list