[llvm] r238579 - Fix crash in MCExpr::print.

Pete Cooper peter_cooper at apple.com
Fri May 29 10:19:11 PDT 2015


Author: pete
Date: Fri May 29 12:19:11 2015
New Revision: 238579

URL: http://llvm.org/viewvc/llvm-project?rev=238579&view=rev
Log:
Fix crash in MCExpr::print.

Symbols are no longer required to be named, but this leads to a crash here if an
unnamed symbol checks that its first character is '$'.

Change the code to first check for a name, then check its first character.

No test case i'm afraid as this is debugging code, but any test case with temp labels
and 'llc --debug --filetype=obj' would have crashed.

Modified:
    llvm/trunk/lib/MC/MCExpr.cpp

Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=238579&r1=238578&r2=238579&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Fri May 29 12:19:11 2015
@@ -43,7 +43,7 @@ void MCExpr::print(raw_ostream &OS) cons
     const MCSymbol &Sym = SRE.getSymbol();
     // Parenthesize names that start with $ so that they don't look like
     // absolute names.
-    bool UseParens = Sym.getName()[0] == '$';
+    bool UseParens = !Sym.getName().empty() && Sym.getName()[0] == '$';
     if (UseParens)
       OS << '(' << Sym << ')';
     else





More information about the llvm-commits mailing list