[PATCH] D131522: [ms] [llvm-ml] Add support for nested PROC/ENDP pairs

Eric Astor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 10 12:29:32 PDT 2022


epastor updated this revision to Diff 451601.
epastor added a comment.

Add tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131522/new/

https://reviews.llvm.org/D131522

Files:
  llvm/lib/MC/MCParser/COFFMasmParser.cpp
  llvm/test/tools/llvm-ml/nested_proc.asm
  llvm/test/tools/llvm-ml/nested_proc_errors.asm


Index: llvm/test/tools/llvm-ml/nested_proc_errors.asm
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ml/nested_proc_errors.asm
@@ -0,0 +1,13 @@
+; RUN: not llvm-ml -filetype=s %s /Fo - 2>&1 | FileCheck %s --implicit-check-not=error:
+
+.code
+
+t1 PROC
+  xor eax, eax
+t1_nested PROC
+  ret
+t1 ENDP
+t1_nested ENDP
+; CHECK: :[[# @LINE - 2]]:1: error: endp does not match current procedure 't1_nested'
+
+END
Index: llvm/test/tools/llvm-ml/nested_proc.asm
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ml/nested_proc.asm
@@ -0,0 +1,18 @@
+; RUN: llvm-ml -m32 -filetype=s %s /Fo - | FileCheck %s
+; RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s
+
+.code
+
+t1 PROC
+  xor eax, eax
+t1_nested PROC
+  ret
+t1_nested ENDP
+t1 ENDP
+
+; CHECK-LABEL: t1:
+; CHECK: xor eax, eax
+; CHECK: t1_nested:
+; CHECK: ret
+
+END
Index: llvm/lib/MC/MCParser/COFFMasmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/COFFMasmParser.cpp
+++ llvm/lib/MC/MCParser/COFFMasmParser.cpp
@@ -207,8 +207,9 @@
                               SectionKind::getBSS());
   }
 
-  StringRef CurrentProcedure;
-  bool CurrentProcedureFramed;
+  /// Stack of active procedure definitions.
+  SmallVector<StringRef, 1> CurrentProcedures;
+  SmallVector<bool, 1> CurrentProceduresFramed;
 
 public:
   COFFMasmParser() = default;
@@ -478,8 +479,8 @@
   }
   getStreamer().emitLabel(Sym, Loc);
 
-  CurrentProcedure = Label;
-  CurrentProcedureFramed = Framed;
+  CurrentProcedures.push_back(Label);
+  CurrentProceduresFramed.push_back(Framed);
   return false;
 }
 bool COFFMasmParser::ParseDirectiveEndProc(StringRef Directive, SMLoc Loc) {
@@ -488,17 +489,17 @@
   if (getParser().parseIdentifier(Label))
     return Error(LabelLoc, "expected identifier for procedure end");
 
-  if (CurrentProcedure.empty())
+  if (CurrentProcedures.empty())
     return Error(Loc, "endp outside of procedure block");
-  else if (CurrentProcedure != Label)
+  else if (CurrentProcedures.back() != Label)
     return Error(LabelLoc, "endp does not match current procedure '" +
-                               CurrentProcedure + "'");
+                               CurrentProcedures.back() + "'");
 
-  if (CurrentProcedureFramed) {
+  if (CurrentProceduresFramed.back()) {
     getStreamer().emitWinCFIEndProc(Loc);
   }
-  CurrentProcedure = "";
-  CurrentProcedureFramed = false;
+  CurrentProcedures.pop_back();
+  CurrentProceduresFramed.pop_back();
   return false;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131522.451601.patch
Type: text/x-patch
Size: 2614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220810/c8f52e36/attachment.bin>


More information about the llvm-commits mailing list