[lld] r335848 - Fix warning on MSVC by using size_t arithmetic instead of casting after the fact. NFC

Aaron Ballman via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 28 05:54:58 PDT 2018


On Thu, Jun 28, 2018 at 8:49 AM, Filipe Cabecinhas <me at filcab.net> wrote:
> I did think about doing it that way, but went for doing something more
> inline with the code below.
> The code "wants" that value to be "something that after incrementing
> once yields 0". If it were "all bits set to 1", I'd use the one you
> mentioned, plus a cast to size_t.
> I probably should have mentioned the warning was:
> C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\lld\COFF\SymbolTable.cpp(192):
> warning C4309: 'initializing': truncation of constant value
>
> Your fix would work on the "unary minus applied to unsigned value"
> warning, but I don't think it would work on this one (after accounting
> for the fact that you might need ull suffix (at least a ul) on some
> platforms). But let me know if you want me to change.

I don't have that strong of an opinion and your rationale sounds
reasonable to me. I'd say leave it as-is.

Thanks!

~Aaron

>
> Thank you,
>  Filipe
>
> On Thu, Jun 28, 2018 at 1:45 PM, Aaron Ballman via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>> On Thu, Jun 28, 2018 at 8:38 AM, Filipe Cabecinhas via llvm-commits
>> <llvm-commits at lists.llvm.org> wrote:
>>> Author: filcab
>>> Date: Thu Jun 28 05:38:43 2018
>>> New Revision: 335848
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=335848&view=rev
>>> Log:
>>> Fix warning on MSVC by using size_t arithmetic instead of casting after the fact. NFC
>>>
>>> Modified:
>>>     lld/trunk/COFF/SymbolTable.cpp
>>>
>>> Modified: lld/trunk/COFF/SymbolTable.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=335848&r1=335847&r2=335848&view=diff
>>> ==============================================================================
>>> --- lld/trunk/COFF/SymbolTable.cpp (original)
>>> +++ lld/trunk/COFF/SymbolTable.cpp Thu Jun 28 05:38:43 2018
>>> @@ -189,7 +189,7 @@ void SymbolTable::reportRemainingUndefin
>>>    }
>>>
>>>    for (ObjFile *File : ObjFile::Instances) {
>>> -    size_t SymIndex = -1ull;
>>> +    size_t SymIndex = size_t{0} - 1;
>>
>> We usually write this as ~0U.
>>
>> ~Aaron
>>
>>>      for (Symbol *Sym : File->getSymbols()) {
>>>        ++SymIndex;
>>>        if (!Sym)
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list