1 //===- llvm/unittests/MC/SystemZ/SystemZAsmLexerTest.cpp ----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===--------------------------------------------------------------------===//
8 #include "llvm/MC/MCAsmInfo.h"
9 #include "llvm/MC/MCContext.h"
10 #include "llvm/MC/MCObjectFileInfo.h"
11 #include "llvm/MC/MCParser/MCTargetAsmParser.h"
12 #include "llvm/MC/MCRegisterInfo.h"
13 #include "llvm/MC/MCStreamer.h"
14 #include "llvm/MC/TargetRegistry.h"
15 #include "llvm/Support/MemoryBuffer.h"
16 #include "llvm/Support/SourceMgr.h"
17 #include "llvm/Support/TargetSelect.h"
18 
19 #include "gtest/gtest.h"
20 
21 using namespace llvm;
22 
23 namespace {
24 
25 // Setup a testing class that the GTest framework can call.
26 class SystemZAsmLexerTest : public ::testing::Test {
27 protected:
28   static void SetUpTestCase() {
29     LLVMInitializeSystemZTargetInfo();
30     LLVMInitializeSystemZTargetMC();
31     LLVMInitializeSystemZAsmParser();
32   }
33 
34   std::unique_ptr<MCRegisterInfo> MRI;
35   std::unique_ptr<MCAsmInfo> MAI;
36   std::unique_ptr<const MCInstrInfo> MII;
37   std::unique_ptr<MCObjectFileInfo> MOFI;
38   std::unique_ptr<MCStreamer> Str;
39   std::unique_ptr<MCAsmParser> Parser;
40   std::unique_ptr<MCContext> Ctx;
41   std::unique_ptr<MCSubtargetInfo> STI;
42   std::unique_ptr<MCTargetAsmParser> TargetAsmParser;
43 
44   SourceMgr SrcMgr;
45   std::string TripleName;
46   llvm::Triple Triple;
47   const Target *TheTarget;
48 
49   const MCTargetOptions MCOptions;
50 
51   SystemZAsmLexerTest() = delete;
52 
53   SystemZAsmLexerTest(std::string SystemZTriple) {
54     // We will use the SystemZ triple, because of missing
55     // Object File and Streamer support for the z/OS target.
56     TripleName = SystemZTriple;
57     Triple = llvm::Triple(TripleName);
58 
59     std::string Error;
60     TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
61     EXPECT_NE(TheTarget, nullptr);
62 
63     MRI.reset(TheTarget->createMCRegInfo(TripleName));
64     EXPECT_NE(MRI, nullptr);
65 
66     MII.reset(TheTarget->createMCInstrInfo());
67     EXPECT_NE(MII, nullptr);
68 
69     STI.reset(TheTarget->createMCSubtargetInfo(TripleName, "z10", ""));
70     EXPECT_NE(STI, nullptr);
71 
72     MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
73     EXPECT_NE(MAI, nullptr);
74   }
75 
76   void setupCallToAsmParser(StringRef AsmStr) {
77     std::unique_ptr<MemoryBuffer> Buffer(MemoryBuffer::getMemBuffer(AsmStr));
78     SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
79     EXPECT_EQ(Buffer, nullptr);
80 
81     Ctx.reset(new MCContext(Triple, MAI.get(), MRI.get(), STI.get(), &SrcMgr,
82                             &MCOptions));
83     MOFI.reset(TheTarget->createMCObjectFileInfo(*Ctx, /*PIC=*/false,
84                                                  /*LargeCodeModel=*/false));
85     Ctx->setObjectFileInfo(MOFI.get());
86 
87     Str.reset(TheTarget->createNullStreamer(*Ctx));
88 
89     Parser.reset(createMCAsmParser(SrcMgr, *Ctx, *Str, *MAI));
90 
91     TargetAsmParser.reset(
92         TheTarget->createMCAsmParser(*STI, *Parser, *MII, MCOptions));
93     Parser->setTargetParser(*TargetAsmParser);
94   }
95 
96   void lexAndCheckTokens(StringRef AsmStr,
97                          SmallVector<AsmToken::TokenKind> ExpectedTokens) {
98     // Get reference to AsmLexer.
99     MCAsmLexer &Lexer = Parser->getLexer();
100     // Loop through all expected tokens checking one by one.
101     for (size_t I = 0; I < ExpectedTokens.size(); ++I) {
102       EXPECT_EQ(Lexer.getTok().getKind(), ExpectedTokens[I]);
103       Lexer.Lex();
104     }
105   }
106 
107   void lexAndCheckIntegerTokensAndValues(StringRef AsmStr,
108                                          SmallVector<int64_t> ExpectedValues) {
109     // Get reference to AsmLexer.
110     MCAsmLexer &Lexer = Parser->getLexer();
111     // Loop through all expected tokens and expected values.
112     for (size_t I = 0; I < ExpectedValues.size(); ++I) {
113       // Skip any EndOfStatement tokens, we're not concerned with them.
114       if (Lexer.getTok().getKind() == AsmToken::EndOfStatement)
115         continue;
116       EXPECT_EQ(Lexer.getTok().getKind(), AsmToken::Integer);
117       EXPECT_EQ(Lexer.getTok().getIntVal(), ExpectedValues[I]);
118       Lexer.Lex();
119     }
120   }
121 };
122 
123 class SystemZAsmLexerLinux : public SystemZAsmLexerTest {
124 protected:
125   SystemZAsmLexerLinux() : SystemZAsmLexerTest("s390x-ibm-linux") {}
126 };
127 
128 class SystemZAsmLexerZOS : public SystemZAsmLexerTest {
129 protected:
130   SystemZAsmLexerZOS() : SystemZAsmLexerTest("s390x-ibm-zos") {}
131 };
132 
133 TEST_F(SystemZAsmLexerLinux, CheckDontRestrictCommentStringToStartOfStatement) {
134   StringRef AsmStr = "jne #-4";
135 
136   // Setup.
137   setupCallToAsmParser(AsmStr);
138 
139   // Lex initially to get the string.
140   Parser->getLexer().Lex();
141 
142   SmallVector<AsmToken::TokenKind> ExpectedTokens(
143       {AsmToken::Identifier, AsmToken::EndOfStatement});
144   lexAndCheckTokens(AsmStr /* "jne #-4" */, ExpectedTokens);
145 }
146 
147 TEST_F(SystemZAsmLexerZOS, CheckRestrictCommentStringToStartOfStatement) {
148   StringRef AsmStr = "jne #-4";
149 
150   // Setup.
151   setupCallToAsmParser(AsmStr);
152 
153   // Lex initially to get the string.
154   Parser->getLexer().Lex();
155 
156   // When we are restricting the comment string to only the start of the
157   // statement, The sequence of tokens we are expecting are: Identifier - "jne"
158   // Hash - '#'
159   // Minus - '-'
160   // Integer - '4'
161   SmallVector<AsmToken::TokenKind> ExpectedTokens(
162       {AsmToken::Identifier, AsmToken::Space, AsmToken::Identifier});
163   lexAndCheckTokens(AsmStr /* "jne #-4" */, ExpectedTokens);
164 }
165 
166 // Test HLASM Comment Syntax ('*')
167 TEST_F(SystemZAsmLexerZOS, CheckHLASMComment) {
168   StringRef AsmStr = "* lhi 1,10";
169 
170   // Setup.
171   setupCallToAsmParser(AsmStr);
172 
173   // Lex initially to get the string.
174   Parser->getLexer().Lex();
175 
176   SmallVector<AsmToken::TokenKind> ExpectedTokens(
177       {AsmToken::EndOfStatement, AsmToken::Eof});
178   lexAndCheckTokens(AsmStr /* "* lhi 1,10" */, ExpectedTokens);
179 }
180 
181 TEST_F(SystemZAsmLexerLinux, CheckHashDefault) {
182   StringRef AsmStr = "lh#123";
183 
184   // Setup.
185   setupCallToAsmParser(AsmStr);
186 
187   // Lex initially to get the string.
188   Parser->getLexer().Lex();
189 
190   // "lh" -> Identifier
191   // "#123" -> EndOfStatement (Lexed as a comment since CommentString is "#")
192   SmallVector<AsmToken::TokenKind> ExpectedTokens(
193       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
194   lexAndCheckTokens(AsmStr, ExpectedTokens);
195 }
196 
197 // Test if "#" is accepted as an Identifier
198 TEST_F(SystemZAsmLexerZOS, CheckAllowHashInIdentifier) {
199   StringRef AsmStr = "lh#123";
200 
201   // Setup.
202   setupCallToAsmParser(AsmStr);
203 
204   // Lex initially to get the string.
205   Parser->getLexer().Lex();
206 
207   // "lh123" -> Identifier
208   SmallVector<AsmToken::TokenKind> ExpectedTokens(
209       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
210   lexAndCheckTokens(AsmStr, ExpectedTokens);
211 }
212 
213 TEST_F(SystemZAsmLexerZOS, CheckAllowHashInIdentifier2) {
214   StringRef AsmStr = "lh#12*3";
215 
216   // Setup.
217   setupCallToAsmParser(AsmStr);
218 
219   // Lex initially to get the string.
220   Parser->getLexer().Lex();
221 
222   // "lh#12" -> Identifier
223   // "*" -> Star
224   // "3" -> Integer
225   SmallVector<AsmToken::TokenKind> ExpectedTokens(
226       {AsmToken::Identifier, AsmToken::Star, AsmToken::Integer,
227        AsmToken::EndOfStatement, AsmToken::Eof});
228   lexAndCheckTokens(AsmStr, ExpectedTokens);
229 }
230 
231 TEST_F(SystemZAsmLexerLinux, DontCheckStrictCommentString) {
232   StringRef AsmStr = "# abc\n/* def *///  xyz";
233 
234   // Setup.
235   setupCallToAsmParser(AsmStr);
236 
237   // Lex initially to get the string.
238   Parser->getLexer().Lex();
239 
240   SmallVector<AsmToken::TokenKind> ExpectedTokens(
241       {AsmToken::EndOfStatement, AsmToken::Comment, AsmToken::EndOfStatement,
242        AsmToken::Eof});
243   lexAndCheckTokens(AsmStr, ExpectedTokens);
244 }
245 
246 TEST_F(SystemZAsmLexerZOS, CheckStrictCommentString) {
247   StringRef AsmStr = "# abc\n/* def *///  xyz";
248 
249   // Setup.
250   setupCallToAsmParser(AsmStr);
251 
252   // Lex initially to get the string.
253   Parser->getLexer().Lex();
254 
255   SmallVector<AsmToken::TokenKind> ExpectedTokens;
256   ExpectedTokens.push_back(AsmToken::Identifier);     // "#"
257   ExpectedTokens.push_back(AsmToken::Space);          // " "
258   ExpectedTokens.push_back(AsmToken::Identifier);     // "abc"
259   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
260   ExpectedTokens.push_back(AsmToken::Slash);          // "/"
261   ExpectedTokens.push_back(AsmToken::Star);           // "*"
262   ExpectedTokens.push_back(AsmToken::Space);          // " "
263   ExpectedTokens.push_back(AsmToken::Identifier);     // "def"
264   ExpectedTokens.push_back(AsmToken::Space);          // " "
265   ExpectedTokens.push_back(AsmToken::Star);           // "*"
266   ExpectedTokens.push_back(AsmToken::Slash);          // "/"
267   ExpectedTokens.push_back(AsmToken::Slash);          // "/"
268   ExpectedTokens.push_back(AsmToken::Slash);          // "/"
269   ExpectedTokens.push_back(AsmToken::Space);          // " "
270   ExpectedTokens.push_back(AsmToken::Identifier);     // "xyz"
271   ExpectedTokens.push_back(AsmToken::EndOfStatement);
272   ExpectedTokens.push_back(AsmToken::Eof);
273 
274   lexAndCheckTokens(AsmStr, ExpectedTokens);
275 }
276 
277 TEST_F(SystemZAsmLexerZOS, CheckValidHLASMIntegers) {
278   StringRef AsmStr = "123\n000123\n1999\n007\n12300\n12021\n";
279   // StringRef AsmStr = "123";
280   // Setup.
281   setupCallToAsmParser(AsmStr);
282 
283   // Lex initially to get the string.
284   Parser->getLexer().Lex();
285 
286   // SmallVector<int64_t> ExpectedValues({123});
287   SmallVector<int64_t> ExpectedValues({123, 123, 1999, 7, 12300, 12021});
288   lexAndCheckIntegerTokensAndValues(AsmStr, ExpectedValues);
289 }
290 
291 TEST_F(SystemZAsmLexerZOS, CheckInvalidHLASMIntegers) {
292   StringRef AsmStr = "0b0101\n0xDEADBEEF\nfffh\n.133\n";
293 
294   // Setup.
295   setupCallToAsmParser(AsmStr);
296 
297   // Lex initially to get the string.
298   Parser->getLexer().Lex();
299 
300   SmallVector<AsmToken::TokenKind> ExpectedTokens;
301   ExpectedTokens.push_back(AsmToken::Integer);        // "0"
302   ExpectedTokens.push_back(AsmToken::Identifier);     // "b0101"
303   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
304   ExpectedTokens.push_back(AsmToken::Integer);        // "0"
305   ExpectedTokens.push_back(AsmToken::Identifier);     // "xDEADBEEF"
306   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
307   ExpectedTokens.push_back(AsmToken::Identifier);     // "fffh"
308   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
309   ExpectedTokens.push_back(AsmToken::Real);           // ".133"
310   ExpectedTokens.push_back(AsmToken::EndOfStatement); // "\n"
311   ExpectedTokens.push_back(AsmToken::Eof);
312   lexAndCheckTokens(AsmStr, ExpectedTokens);
313 }
314 
315 TEST_F(SystemZAsmLexerLinux, CheckDefaultIntegers) {
316   StringRef AsmStr = "0b0101\n0xDEADBEEF\nfffh\n";
317 
318   // Setup.
319   setupCallToAsmParser(AsmStr);
320 
321   // Lex initially to get the string.
322   Parser->getLexer().Lex();
323 
324   SmallVector<int64_t> ExpectedValues({5, 0xDEADBEEF, 0xFFF});
325   lexAndCheckIntegerTokensAndValues(AsmStr, ExpectedValues);
326 }
327 
328 TEST_F(SystemZAsmLexerLinux, CheckDefaultFloats) {
329   StringRef AsmStr = "0.333\n1.3\n2.5\n3.0\n";
330 
331   // Setup.
332   setupCallToAsmParser(AsmStr);
333 
334   // Lex initially to get the string.
335   Parser->getLexer().Lex();
336 
337   SmallVector<AsmToken::TokenKind> ExpectedTokens;
338 
339   for (int I = 0; I < 4; ++I)
340     ExpectedTokens.insert(ExpectedTokens.begin(),
341                           {AsmToken::Real, AsmToken::EndOfStatement});
342 
343   ExpectedTokens.push_back(AsmToken::Eof);
344   lexAndCheckTokens(AsmStr, ExpectedTokens);
345 }
346 
347 TEST_F(SystemZAsmLexerLinux, CheckDefaultQuestionAtStartOfIdentifier) {
348   StringRef AsmStr = "?lh1?23";
349 
350   // Setup.
351   setupCallToAsmParser(AsmStr);
352 
353   // Lex initially to get the string.
354   Parser->getLexer().Lex();
355 
356   SmallVector<AsmToken::TokenKind> ExpectedTokens(
357       {AsmToken::Error, AsmToken::Identifier, AsmToken::EndOfStatement,
358        AsmToken::Eof});
359   lexAndCheckTokens(AsmStr, ExpectedTokens);
360 }
361 
362 TEST_F(SystemZAsmLexerLinux, CheckDefaultAtAtStartOfIdentifier) {
363   StringRef AsmStr = "@@lh1?23";
364 
365   // Setup.
366   setupCallToAsmParser(AsmStr);
367 
368   // Lex initially to get the string.
369   Parser->getLexer().Lex();
370 
371   SmallVector<AsmToken::TokenKind> ExpectedTokens(
372       {AsmToken::At, AsmToken::At, AsmToken::Identifier,
373        AsmToken::EndOfStatement, AsmToken::Eof});
374   lexAndCheckTokens(AsmStr, ExpectedTokens);
375 }
376 
377 TEST_F(SystemZAsmLexerZOS, CheckAcceptAtAtStartOfIdentifier) {
378   StringRef AsmStr = "@@lh1?23";
379 
380   // Setup.
381   setupCallToAsmParser(AsmStr);
382 
383   // Lex initially to get the string.
384   Parser->getLexer().Lex();
385 
386   SmallVector<AsmToken::TokenKind> ExpectedTokens(
387       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
388   lexAndCheckTokens(AsmStr, ExpectedTokens);
389 }
390 
391 TEST_F(SystemZAsmLexerLinux, CheckDefaultDollarAtStartOfIdentifier) {
392   StringRef AsmStr = "$$ac$c";
393 
394   // Setup.
395   setupCallToAsmParser(AsmStr);
396 
397   // Lex initially to get the string.
398   Parser->getLexer().Lex();
399 
400   SmallVector<AsmToken::TokenKind> ExpectedTokens(
401       {AsmToken::Dollar, AsmToken::Dollar, AsmToken::Identifier,
402        AsmToken::EndOfStatement, AsmToken::Eof});
403   lexAndCheckTokens(AsmStr, ExpectedTokens);
404 }
405 
406 TEST_F(SystemZAsmLexerZOS, CheckAcceptDollarAtStartOfIdentifier) {
407   StringRef AsmStr = "$$ab$c";
408 
409   // Setup.
410   setupCallToAsmParser(AsmStr);
411 
412   // Lex initially to get the string.
413   Parser->getLexer().Lex();
414 
415   SmallVector<AsmToken::TokenKind> ExpectedTokens(
416       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
417   lexAndCheckTokens(AsmStr, ExpectedTokens);
418 }
419 
420 TEST_F(SystemZAsmLexerZOS, CheckAcceptHashAtStartOfIdentifier) {
421   StringRef AsmStr = "##a#b$c";
422 
423   // Setup.
424   setupCallToAsmParser(AsmStr);
425 
426   // Lex initially to get the string.
427   Parser->getLexer().Lex();
428 
429   SmallVector<AsmToken::TokenKind> ExpectedTokens(
430       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
431   lexAndCheckTokens(AsmStr, ExpectedTokens);
432 }
433 
434 TEST_F(SystemZAsmLexerLinux, CheckAcceptHashAtStartOfIdentifier2) {
435   StringRef AsmStr = "##a#b$c";
436 
437   // Setup.
438   setupCallToAsmParser(AsmStr);
439 
440   // Lex initially to get the string.
441   Parser->getLexer().Lex();
442 
443   // By default, the CommentString attribute is set to "#".
444   // Hence, "##a#b$c" is lexed as a line comment irrespective
445   // of whether the AllowHashAtStartOfIdentifier attribute is set to true.
446   SmallVector<AsmToken::TokenKind> ExpectedTokens(
447       {AsmToken::EndOfStatement, AsmToken::Eof});
448   lexAndCheckTokens(AsmStr, ExpectedTokens);
449 }
450 
451 TEST_F(SystemZAsmLexerZOS, CheckAcceptHashAtStartOfIdentifier3) {
452   StringRef AsmStr = "##a#b$c";
453 
454   // Setup.
455   setupCallToAsmParser(AsmStr);
456 
457   // Lex initially to get the string.
458   Parser->getLexer().Lex();
459 
460   SmallVector<AsmToken::TokenKind> ExpectedTokens(
461       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
462   lexAndCheckTokens(AsmStr, ExpectedTokens);
463 }
464 
465 TEST_F(SystemZAsmLexerZOS, CheckAcceptHashAtStartOfIdentifier4) {
466   StringRef AsmStr = "##a#b$c";
467 
468   // Setup.
469   setupCallToAsmParser(AsmStr);
470 
471   // Lex initially to get the string.
472   Parser->getLexer().Lex();
473 
474   // Since, the AllowAdditionalComments attribute is set to false,
475   // only strings starting with the CommentString attribute are
476   // lexed as possible comments.
477   // Hence, "##a$b$c" is lexed as an Identifier because the
478   // AllowHashAtStartOfIdentifier attribute is set to true.
479   SmallVector<AsmToken::TokenKind> ExpectedTokens(
480       {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
481   lexAndCheckTokens(AsmStr, ExpectedTokens);
482 }
483 
484 TEST_F(SystemZAsmLexerZOS, CheckRejectDotAsCurrentPC) {
485   StringRef AsmStr = ".-4";
486 
487   // Setup.
488   setupCallToAsmParser(AsmStr);
489 
490   // Lex initially to get the string.
491   Parser->getLexer().Lex();
492 
493   const MCExpr *Expr;
494   bool ParsePrimaryExpr = Parser->parseExpression(Expr);
495   EXPECT_EQ(ParsePrimaryExpr, true);
496   EXPECT_EQ(Parser->hasPendingError(), true);
497 }
498 
499 TEST_F(SystemZAsmLexerLinux, CheckRejectStarAsCurrentPC) {
500   StringRef AsmStr = "*-4";
501 
502   // Setup.
503   setupCallToAsmParser(AsmStr);
504 
505   // Lex initially to get the string.
506   Parser->getLexer().Lex();
507 
508   const MCExpr *Expr;
509   bool ParsePrimaryExpr = Parser->parseExpression(Expr);
510   EXPECT_EQ(ParsePrimaryExpr, true);
511   EXPECT_EQ(Parser->hasPendingError(), true);
512 }
513 
514 TEST_F(SystemZAsmLexerZOS, CheckRejectCharLiterals) {
515   StringRef AsmStr = "abc 'd'";
516 
517   // Setup.
518   setupCallToAsmParser(AsmStr);
519 
520   // Lex initially to get the string.
521   Parser->getLexer().Lex();
522 
523   SmallVector<AsmToken::TokenKind> ExpectedTokens(
524       {AsmToken::Identifier, AsmToken::Space, AsmToken::Error, AsmToken::Error,
525        AsmToken::EndOfStatement, AsmToken::Eof});
526   lexAndCheckTokens(AsmStr, ExpectedTokens);
527 }
528 
529 TEST_F(SystemZAsmLexerZOS, CheckRejectStringLiterals) {
530   StringRef AsmStr = "abc \"ef\"";
531 
532   // Setup.
533   setupCallToAsmParser(AsmStr);
534 
535   // Lex initially to get the string.
536   Parser->getLexer().Lex();
537 
538   SmallVector<AsmToken::TokenKind> ExpectedTokens(
539       {AsmToken::Identifier, AsmToken::Space, AsmToken::Error,
540        AsmToken::Identifier, AsmToken::Error, AsmToken::EndOfStatement,
541        AsmToken::Eof});
542   lexAndCheckTokens(AsmStr, ExpectedTokens);
543 }
544 
545 TEST_F(SystemZAsmLexerZOS, CheckPrintAcceptableSymbol) {
546   std::string AsmStr = "ab13_$.@";
547   EXPECT_EQ(true, MAI->isValidUnquotedName(AsmStr));
548   AsmStr += "#";
549   EXPECT_EQ(true, MAI->isValidUnquotedName(AsmStr));
550 }
551 
552 TEST_F(SystemZAsmLexerLinux, CheckPrintAcceptableSymbol) {
553   std::string AsmStr = "ab13_$.@";
554   EXPECT_EQ(true, MAI->isValidUnquotedName(AsmStr));
555   AsmStr += "#";
556   EXPECT_EQ(false, MAI->isValidUnquotedName(AsmStr));
557 }
558 
559 TEST_F(SystemZAsmLexerZOS, CheckLabelCaseUpperCase) {
560   StringRef AsmStr = "label";
561 
562   // Setup.
563   setupCallToAsmParser(AsmStr);
564 
565   // Lex initially to get the string.
566   Parser->getLexer().Lex();
567 
568   const MCExpr *Expr;
569   bool ParsePrimaryExpr = Parser->parseExpression(Expr);
570   EXPECT_EQ(ParsePrimaryExpr, false);
571 
572   const MCSymbolRefExpr *SymbolExpr = dyn_cast<MCSymbolRefExpr>(Expr);
573   EXPECT_NE(SymbolExpr, nullptr);
574   EXPECT_NE(&SymbolExpr->getSymbol(), nullptr);
575   EXPECT_EQ((&SymbolExpr->getSymbol())->getName(), StringRef("LABEL"));
576 }
577 
578 TEST_F(SystemZAsmLexerLinux, CheckLabelUpperCase2) {
579   StringRef AsmStr = "label";
580 
581   // Setup.
582   setupCallToAsmParser(AsmStr);
583 
584   // Lex initially to get the string.
585   Parser->getLexer().Lex();
586 
587   const MCExpr *Expr;
588   bool ParsePrimaryExpr = Parser->parseExpression(Expr);
589   EXPECT_EQ(ParsePrimaryExpr, false);
590 
591   const MCSymbolRefExpr *SymbolExpr = dyn_cast<MCSymbolRefExpr>(Expr);
592   EXPECT_NE(SymbolExpr, nullptr);
593   EXPECT_NE(&SymbolExpr->getSymbol(), nullptr);
594   EXPECT_EQ((&SymbolExpr->getSymbol())->getName(), StringRef("label"));
595 }
596 } // end anonymous namespace
597