[llvm] b37a2fc - [SystemZ][z/OS] Validate symbol names for z/OS for printing without quotes
Anirudh Prasad via llvm-commits
llvm-commits at lists.llvm.org
Wed May 26 07:37:15 PDT 2021
Author: Anirudh Prasad
Date: 2021-05-26T10:37:09-04:00
New Revision: b37a2fcd8d7c59c3db4b1c64bbdba6d1bbea9e99
URL: https://github.com/llvm/llvm-project/commit/b37a2fcd8d7c59c3db4b1c64bbdba6d1bbea9e99
DIFF: https://github.com/llvm/llvm-project/commit/b37a2fcd8d7c59c3db4b1c64bbdba6d1bbea9e99.diff
LOG: [SystemZ][z/OS] Validate symbol names for z/OS for printing without quotes
- Currently, before printing a label in MCSymbol.cpp (MCSymbol::print), the current code "validates" the label that is to be printed.
- If it fails the validation step, then it prints the label within double quotes.
- However, the validation is provided as a virtual function in MCAsmInfo.h (i.e. isAcceptableChar() function). So we can override this for the AD_HLASM dialect in SystemZMCAsmInfo.cpp.
Reviewed By: uweigand
Differential Revision: https://reviews.llvm.org/D103091
Added:
Modified:
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h
llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
index 221b6fdd59c8b..61fe2f4a5fdba 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
@@ -37,3 +37,10 @@ SystemZMCAsmInfo::SystemZMCAsmInfo(const Triple &TT) {
SupportsDebugInformation = true;
ExceptionsType = ExceptionHandling::DwarfCFI;
}
+
+bool SystemZMCAsmInfo::isAcceptableChar(char C) const {
+ if (AssemblerDialect == AD_ATT)
+ return MCAsmInfo::isAcceptableChar(C);
+
+ return MCAsmInfo::isAcceptableChar(C) || C == '#';
+}
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h
index 8b42dea1303d7..389575d146790 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h
@@ -19,6 +19,7 @@ enum SystemZAsmDialect { AD_ATT = 0, AD_HLASM = 1 };
class SystemZMCAsmInfo : public MCAsmInfoELF {
public:
explicit SystemZMCAsmInfo(const Triple &TT);
+ bool isAcceptableChar(char C) const override;
};
} // end namespace llvm
diff --git a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
index b90e051b6f2b3..caf1dccb06577 100644
--- a/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
+++ b/llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
@@ -48,6 +48,7 @@ class MockedUpMCAsmInfo : public MCAsmInfo {
AllowHashAtStartOfIdentifier = Value;
}
void setAllowDotIsPC(bool Value) { DotIsPC = Value; }
+ void setAssemblerDialect(unsigned Value) { AssemblerDialect = Value; }
};
// Setup a testing class that the GTest framework can call.
@@ -734,4 +735,19 @@ TEST_F(SystemZAsmLexerTest, CheckRejectStringLiterals) {
AsmToken::Error, AsmToken::EndOfStatement, AsmToken::Eof});
lexAndCheckTokens(AsmStr, ExpectedTokens);
}
+
+TEST_F(SystemZAsmLexerTest, CheckPrintAcceptableSymbol) {
+ std::string AsmStr = "ab13_$.@";
+ EXPECT_EQ(true, MUPMAI->isValidUnquotedName(AsmStr));
+ AsmStr += "#";
+ EXPECT_EQ(false, MUPMAI->isValidUnquotedName(AsmStr));
+}
+
+TEST_F(SystemZAsmLexerTest, CheckPrintAcceptableSymbol2) {
+ MUPMAI->setAssemblerDialect(1);
+ std::string AsmStr = "ab13_$.@";
+ EXPECT_EQ(true, MUPMAI->isValidUnquotedName(AsmStr));
+ AsmStr += "#";
+ EXPECT_EQ(true, MUPMAI->isValidUnquotedName(AsmStr));
+}
} // end anonymous namespace
More information about the llvm-commits
mailing list