[PATCH] D43456: [MC] - Don't crash on unclosed frame.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 19 03:33:13 PST 2018


grimar created this revision.
grimar added a reviewer: espindola.
grimar updated this revision to Diff 134883.
grimar added a comment.

- Add forgotten code change.


llvm-mc can crash when
there is `cfi_startproc` without `cfi_end_proc`:

  .text
  .globl foo
  foo:
   .cfi_startproc

Testcase shows the issue, patch fixes it.


https://reviews.llvm.org/D43456

Files:
  lib/MC/MCStreamer.cpp
  test/MC/X86/cfi-scope-unclosed.s


Index: test/MC/X86/cfi-scope-unclosed.s
===================================================================
--- test/MC/X86/cfi-scope-unclosed.s
+++ test/MC/X86/cfi-scope-unclosed.s
@@ -0,0 +1,10 @@
+# RUN: not llvm-mc %s -filetype=obj -triple=x86_64-unknown-linux \
+# RUN:   -o /dev/null 2>&1 | FileCheck %s
+
+## Check we don't crash on unclosed frame scope.
+# CHECK: error: Unfinished frame!
+
+.text
+.globl foo
+foo:
+ .cfi_startproc
Index: lib/MC/MCStreamer.cpp
===================================================================
--- lib/MC/MCStreamer.cpp
+++ lib/MC/MCStreamer.cpp
@@ -816,10 +816,11 @@
 }
 
 void MCStreamer::Finish() {
-  if (!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End)
-    getContext().reportError(SMLoc(), "Unfinished frame!");
-  if (!WinFrameInfos.empty() && !WinFrameInfos.back()->End)
+  if ((!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End) ||
+      (!WinFrameInfos.empty() && !WinFrameInfos.back()->End)) {
     getContext().reportError(SMLoc(), "Unfinished frame!");
+    return;
+  }
 
   MCTargetStreamer *TS = getTargetStreamer();
   if (TS)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43456.134883.patch
Type: text/x-patch
Size: 1104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180219/7cec5167/attachment.bin>


More information about the llvm-commits mailing list