[PATCH] D12776: [MC] Don't crash on division by zero

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 05:16:58 PDT 2015


On 10 September 2015 at 19:59, Davide Italiano <davide at freebsd.org> wrote:
> On Thu, Sep 10, 2015 at 3:00 PM, Rafael EspĂ­ndola
> <llvm-commits at lists.llvm.org> wrote:
>>> +// Check that llvm-mc doesn't crash on division by zero.
>>> +// RUN: llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1
>>> +
>>> +.int 1/0
>>
>> Does it work with -filetype=obj? What is output?
>>
>
> I forgot to mention in the original mail. It emits out an error, but
> probably not the most useful one :(
>
> % /exps/llvm2/build/bin/llvm-mc -filetype=obj test/MC/ELF/div-by-zero.s
> test/MC/ELF/div-by-zero.s:4:6: error: expected relocatable expression
> .int 1/0
>      ^
>
> We don't have a context in MCExpr so this should be probably handled
> by the parser to have something meaningful. MCExpr may return back an
> error code to the MCAssembler so that it can discriminate between
> 'relocatable expression' and 'division by zero' error.
> Maybe there's a better way of handling anyway.

OK. Just fixing a crash is an improvement.

What does gas produce is this case? Producing a good error is probably
OK. I am just curious in case we ever have to be bug by bug compatible
in this case.

Please add the object emission case to the test. The "not" utility
differentiates crashes and regular errors, so it will at least make
sure we don't crash.

Cheers,
Rafael


More information about the llvm-commits mailing list