[llvm] [SystemZ] Implement .machine (push|pop) directives (PR #137302)

Ulrich Weigand via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 28 05:38:49 PDT 2025


================
@@ -1382,16 +1388,32 @@ bool SystemZAsmParser::parseDirectiveMachine(SMLoc L) {
       Parser.getTok().isNot(AsmToken::String))
     return TokError("unexpected token in '.machine' directive");
 
-  StringRef CPU = Parser.getTok().getIdentifier();
+  StringRef Id = Parser.getTok().getIdentifier();
+  // Do error check before lexing the next token so that TokError
+  // points at the correct token.
+  if ((Id == "pop") && (MachineStack.empty()))
+    return TokError("pop without corresponding push in '.machine' directive");
----------------
uweigand wrote:

Hmm.  I do think it would be better to have the syntax check before the semantics check.  E.g. if you do a `.machine pop z15` or something, you should preferably see the error that there's an unexpected token at the end, over the error that there was no corresponding push.

To get the location correct, I think it would be better to use an `Error` with an explicit location (e.g. by calling `Parser.getTok().getLoc()` at the place where you do the `getIdentifier` call, and then using that location with `Error` further down).


https://github.com/llvm/llvm-project/pull/137302


More information about the llvm-commits mailing list