[llvm] r185766 - COFFDumper: Print uint64_t with the right format string.

Benjamin Kramer benny.kra at gmail.com
Sun Jul 7 00:51:56 PDT 2013


On Sun, Jul 7, 2013 at 1:40 AM, David Blaikie <dblaikie at gmail.com> wrote:
> On Sat, Jul 6, 2013 at 1:01 PM, Benjamin Kramer
> <benny.kra at googlemail.com> wrote:
>> Author: d0k
>> Date: Sat Jul  6 15:01:46 2013
>> New Revision: 185766
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=185766&view=rev
>> Log:
>> COFFDumper: Print uint64_t with the right format string.
>>
>> I wish we could typecheck llvm::format.
>
> Just rambling, but could it be done with constexpr & template magic? I
> thought that was one of the ideas that constexpr/variadic templates
> might allow (I suppose the easy way is for the format strings not to
> specify types at all & just use variadic templates to get the argument
> types, which doesn't help if we need to work in C++98 too - but I was
> thinking some kind of user defined type with sfinae'd typedefs based
> on constexprs of the format string to extract the parameter types,
> etc)

Maybe this would be the right thing to do in the long term. It sounds
like a lot of work and crazy metaprogramming though.

> Or can we not just annotate format with the printf formatter
> attributes? Or does it use some custom format specification?

It just forwards to snprintf, so the attribute would be fine. I tried
__attribute__((format)) but clang only accepts it on variadic
functions. I don't know why that limitation is there, it doesn't make
any sense to me.

- Ben

>
>>
>> Modified:
>>     llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
>>
>> Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=185766&r1=185765&r2=185766&view=diff
>> ==============================================================================
>> --- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
>> +++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Sat Jul  6 15:01:46 2013
>> @@ -479,15 +479,15 @@ static std::string formatSymbol(const st
>>
>>    StringRef Sym;
>>    if (resolveSymbolName(Rels, Offset, Sym)) {
>> -    Str << format(" (0x%X)", Offset);
>> +    Str << format(" (0x%" PRIX64 ")", Offset);
>>      return Str.str();
>>    }
>>
>>    Str << Sym;
>>    if (Disp > 0) {
>> -    Str << format(" +0x%X (0x%X)", Disp, Offset);
>> +    Str << format(" +0x%X (0x%" PRIX64 ")", Disp, Offset);
>>    } else {
>> -    Str << format(" (0x%X)", Offset);
>> +    Str << format(" (0x%" PRIX64 ")", Offset);
>>    }
>>
>>    return Str.str();
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list