[llvm] r250557 - MC: Don't crash after issuing a diagnostic.

Jim Grosbach via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 15:07:59 PDT 2015


Author: grosbach
Date: Fri Oct 16 17:07:59 2015
New Revision: 250557

URL: http://llvm.org/viewvc/llvm-project?rev=250557&view=rev
Log:
MC: Don't crash after issuing a diagnostic.

Crashing is bad, m'kay? Fixing a 4 year old bug of my own creation.
Adding the testcase now which I should have added then which would have
long since caught this.

The problem is that printMessage() will display the diagnostic but not
set HadError to true, resulting in the assembler continuing on its way
and trying to create relocations for things that may not allow them or
otherwise get itself into trouble. Using the Error() helper function
here rather than calling printMessage() directly resolves this.

rdar://23133240

Added:
    llvm/trunk/test/MC/AsmParser/undefined-local-symbol.s
Modified:
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=250557&r1=250556&r2=250557&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Fri Oct 16 17:07:59 2015
@@ -690,9 +690,8 @@ bool AsmParser::Run(bool NoInitialTextSe
         // FIXME: We would really like to refer back to where the symbol was
         // first referenced for a source location. We need to add something
         // to track that. Currently, we just point to the end of the file.
-        printMessage(getLexer().getLoc(), SourceMgr::DK_Error,
-                     "assembler local symbol '" + Sym->getName() +
-                         "' not defined");
+        return Error(getLexer().getLoc(), "assembler local symbol '" +
+                                              Sym->getName() + "' not defined");
     }
   }
 

Added: llvm/trunk/test/MC/AsmParser/undefined-local-symbol.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/undefined-local-symbol.s?rev=250557&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/undefined-local-symbol.s (added)
+++ llvm/trunk/test/MC/AsmParser/undefined-local-symbol.s Fri Oct 16 17:07:59 2015
@@ -0,0 +1,8 @@
+# RUN: not llvm-mc -triple i386-apple-darwin -filetype=obj -o /dev/null %s 2>&1 | FileCheck %s
+
+# NOTE: apple-darwin portion of the triple is to enforce the convention choice
+#       of what an assembler local symbol looks like (i.e., 'L' prefix.)
+
+# CHECK: error: assembler local symbol 'Lbar' not defined
+foo:
+  jmp Lbar




More information about the llvm-commits mailing list