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

Pete Cooper peter_cooper at apple.com
Fri May 29 11:01:59 PDT 2015


> On May 29, 2015, at 10:59 AM, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> On Fri, May 29, 2015 at 10:19 AM, Pete Cooper <peter_cooper at apple.com <mailto:peter_cooper at apple.com>> wrote:
> Author: pete
> Date: Fri May 29 12:19:11 2015
> New Revision: 238579
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=238579&view=rev <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.
> 
> I think I missed a step - why wouldn't we have a test that does that? (llc --debug --filetype=obj)?
I guess we could, I just didn’t think we tended to have tests that do --debug.  I’ve got no problem adding it if you want.

Cheers,
Pete
>  
> 
> 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 <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
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits <http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150529/4c4876fb/attachment.html>


More information about the llvm-commits mailing list