[PATCH] MC: do not try to parse invalid handled directives

Saleem Abdulrasool compnerd at compnerd.org
Sun Dec 15 20:20:10 PST 2013


  Fix floating-literals test that was accidentally broken.

Hi t.p.northover, dblaikie,

http://llvm-reviews.chandlerc.com/D2410

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2410?vs=6110&id=6113#toc

Files:
  lib/MC/MCParser/AsmParser.cpp
  test/MC/AsmParser/target-directives.s

Index: lib/MC/MCParser/AsmParser.cpp
===================================================================
--- lib/MC/MCParser/AsmParser.cpp
+++ lib/MC/MCParser/AsmParser.cpp
@@ -628,13 +628,18 @@
 
   // While we have input, parse each statement.
   while (Lexer.isNot(AsmToken::Eof)) {
+    const bool HadErrorPreviously = HadError;
+    HadError = false;
     ParseStatementInfo Info;
-    if (!parseStatement(Info))
+    if (!parseStatement(Info)) {
+      HadError = HadError || HadErrorPreviously;
       continue;
+    }
 
     // We had an error, validate that one was emitted and recover by skipping to
     // the next line.
     assert(HadError && "Parse statement returned an error, but none emitted!");
+    HadError = HadError || HadErrorPreviously;
     eatToEndOfStatement();
   }
 
@@ -1324,8 +1329,17 @@
 
     // First query the target-specific parser. It will return 'true' if it
     // isn't interested in this directive.
-    if (!getTargetParser().ParseDirective(ID))
+    const bool HadErrorPreviously = HadError;
+    HadError = false;
+    if (!getTargetParser().ParseDirective(ID)) {
+      HadError = HadError || HadErrorPreviously;
       return false;
+    }
+
+    if (HadError)
+      return false;
+
+    HadError = HadErrorPreviously;
 
     // Next, check the extention directive map to see if any extension has
     // registered itself to parse this directive.
Index: test/MC/AsmParser/target-directives.s
===================================================================
--- /dev/null
+++ test/MC/AsmParser/target-directives.s
@@ -0,0 +1,8 @@
+# RUN: not llvm-mc -triple i386-unknown-unknown -filetype obj 2>&1 -o /dev/null %s \
+# RUN:   | FileCheck %s
+
+	.code42
+
+# CHECK: unexpected directive .code42
+# CHECK-NOT: unknown directive
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2410.3.patch
Type: text/x-patch
Size: 1780 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131215/af126486/attachment.bin>


More information about the llvm-commits mailing list