[PATCH] D103091: [SystemZ][z/OS] Validate symbol names for z/OS for printing without quotes

Anirudh Prasad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 25 08:41:56 PDT 2021


anirudhp created this revision.
Herald added a subscriber: hiraditya.
anirudhp requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

- 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103091

Files:
  llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
  llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h
  llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp


Index: llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
===================================================================
--- llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
+++ llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp
@@ -48,6 +48,7 @@
     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 @@
        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
Index: llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h
===================================================================
--- llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h
+++ llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.h
@@ -19,6 +19,7 @@
 class SystemZMCAsmInfo : public MCAsmInfoELF {
 public:
   explicit SystemZMCAsmInfo(const Triple &TT);
+  bool isAcceptableChar(char C) const override;
 };
 
 } // end namespace llvm
Index: llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
===================================================================
--- llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
+++ llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp
@@ -37,3 +37,10 @@
   SupportsDebugInformation = true;
   ExceptionsType = ExceptionHandling::DwarfCFI;
 }
+
+bool SystemZMCAsmInfo::isAcceptableChar(char C) const {
+  if (AssemblerDialect == AD_ATT)
+    return MCAsmInfo::isAcceptableChar(C);
+
+  return MCAsmInfo::isAcceptableChar(C) || C == '#';
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103091.347691.patch
Type: text/x-patch
Size: 2181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210525/5f8fef10/attachment.bin>


More information about the llvm-commits mailing list