[cfe-dev] Getting CXType_Int and data size == 4 for uint64_t

John McCall via cfe-dev cfe-dev at lists.llvm.org
Sat Sep 16 00:46:35 PDT 2017


> On Sep 16, 2017, at 3:27 AM, Hayden Livingston <halivingston at gmail.com> wrote:
> 
> I would have thought that precisely specifying bit width would be
> considered portable? Isn't that the whole point of it? vs long which
> is 8 or 4 bytes depending on the OS etc?

It is absolutely a high-requirement that uint64_t be a 64-bit type, but it's not the
compiler's responsibility to make that happen.  The compiler assigns sizes to the
fundamental types, like 'int' and 'long', based on the current target.  Types like
'uint64_t' are typedefs, and headers like stdint.h are supposed to define them to
be a type that's known to have the right size for the target.  So if stdint.h thinks
'unsigned long' is a 64-bit type and therefore reasonable to typedef 'uint64_t' to,
but the compiler thinks that 'unsigned long' is a 32-bit type, you can get problems
like this.

You should start by checking two things: what clang thinks the current target is and
where it's picking up the system headers.  I would guess that one or the other is not
what you expect.

Another possibility is that clang is supposed to be using its compiler-provided headers
on your target, but it can't find them because of how you've built it.

John.

> I'm not sure where to look or what to modify to get the right size.
> 
> On Fri, Sep 15, 2017 at 11:49 PM, John McCall <rjmccall at apple.com> wrote:
>>> On Sep 16, 2017, at 2:24 AM, Hayden Livingston via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>>> I'm writing a simple parser tool using libclang and I noticed
>>> something really odd.
>>> 
>>> For this simple file as I visit the cursors and call getType on them I
>>> see that A is detected as CXType_Int and 4 bytes of size, but C is
>>> also detected as CXType_Int and 4 bytes of size.
>>> 
>>> I did not expect this, am I doing something wrong?
>> 
>> Your <stdint.h> is probably not designed for your target.  They often aren't intended to be "portable".
>> 
>> John.
>> 
>>> 
>>> #include <stdint.h>
>>> 
>>> struct TestStruct
>>> {
>>> uint32_t A;
>>> const char *B;
>>> uint64_t C;
>>> };
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>> 




More information about the cfe-dev mailing list