[PATCH] D43934: [ELF] - Report location for div/mod by zero.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 1 09:20:07 PST 2018


George Rimar <grimar at accesssoftek.com> writes:

>>> +Expr ScriptParser::combine(StringRef Op, Expr L, Expr R) {
>>>    if (Op == "+")
>>>      return [=] { return add(L(), R()); };
>>>    if (Op == "-")
>>>      return [=] { return sub(L(), R()); };
>>>    if (Op == "*")
>>>      return [=] { return L().getValue() * R().getValue(); };
>>> -  if (Op == "/")
>>> -    return [=] { return div(L(), R()); };
>>> -  if (Op == "%")
>>> -    return [=] { return mod(L(), R()); };
>>> +  if (Op == "/") {
>>> +    std::string Loc = getCurrentLocation();
>>
>>getCurrentLocation is pretty expensive. It probably is not critical in
>>here, but we should probably keep the style of only calling
>>getCurrentLocation() when there is an error.
>>
>>Cheers,
>>Rafael
>
> At the moment when there is a error (calculation of expression)
> it is too late to call getCurrentLocation.
> (getCurrentLocation returns location in linker script, so we have to call it
> during parsing)
>
> Actually we call it often, see ScriptParser.cpp, I believe you are talking about
> getLocation probably.

The part I thought was expensive was getLineNumber. Since what the patch
does is common practice, LGTM.

Wait to see if Rui is OK with it too.

Cheers,
Rafael


More information about the llvm-commits mailing list