qqiangwu / cppsafe

Cpp lifetime safety profile static analyzer
MIT License
48 stars 1 forks source link

error: cast from pointer to smaller type #52

Open SteveLee123 opened 6 months ago

SteveLee123 commented 6 months ago

I use x86_64 gcc and I encounter this error. how can I fix that ? seems that is because my pointer is 64bits.

In file included from /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.4.0/../../../../include/c++/11.4.0/memory:72:
/usr/local/lib/gcc/x86_64-pc-linux-gnu/11.4.0/../../../../include/c++/11.4.0/bits/align.h:66:25: error: cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information
   66 |   const auto __intptr = reinterpret_cast<uintptr_t>(__ptr);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qqiangwu commented 6 months ago

still, it's the problem of headers. uintptr_t are the same length of pointers by design.

Please provide the concrete os versions and how to re-produce it, otherwise I cannot handle it.

SteveLee123 commented 6 months ago

still, it's the problem of headers. uintptr_t are the same length of pointers by design.

Please provide the concrete os versions and how to re-produce it, otherwise I cannot handle it.

I got them from google:

'uintptr_t' (aka 'unsigned int') is alwasys 4bytes. but pointer is 4bytes at 32bit system and 8bytes at 64bit system.

seems that is not about headers.

qqiangwu commented 6 months ago

NO. see https://en.cppreference.com/w/cpp/types/integer

uintptr_t(optional) | unsigned integer type capable of holding a pointer to void(typedef)

qqiangwu commented 6 months ago

I somehow knowns the problem, but I need an environment to reproduce it. Please wait.

A potential solution is to not rely on auto-detection, specify includes by your self. For example:

cppsafe a.cpp -- -isystem/usr/include -isystem/usr/local/include

Remember to replace these -isystem to your local c/c++ includes.

SteveLee123 commented 6 months ago

I somehow knowns the problem, but I need an environment to reproduce it. Please wait.

A potential solution is to not rely on auto-detection, specify includes by your self. For example:

cppsafe a.cpp -- -isystem/usr/include -isystem/usr/local/include

Remember to replace these -isystem to your local c/c++ includes.

seems that I can't use compile_commands.json if I use --

qqiangwu commented 6 months ago

seems that I can't use compile_commands.json if I use --

Can you show me your compile_commands.json?

SteveLee123 commented 6 months ago

I will show you part of it tomorrow.

SteveLee123 commented 6 months ago

I somehow knowns the problem, but I need an environment to reproduce it. Please wait.

A potential solution is to not rely on auto-detection, specify includes by your self. For example:

cppsafe a.cpp -- -isystem/usr/include -isystem/usr/local/include

Remember to replace these -isystem to your local c/c++ includes.

so you still think is because the headers ? how can I make sure I got the right header by auto-detection?

my header directory search way is like this: https://github.com/qqiangwu/cppsafe/issues/42#issuecomment-2003065472

SteveLee123 commented 6 months ago

fix by: cppsafe -p xxxx a.cpp --extra-arg=-m32

because cppsafe cannot detect my cpu.

SteveLee123 commented 6 months ago

Can you show me your compile_commands.json?

I somehow know the reason of why I got so many headers error.

Firstly, I compile my project with gcc7.3.0, so My compile_commands.json is generated by gcc 7.3.0; Secondly, I upgrate my gcc to 11.4.0, and compile cppsafe . Lastly, I use cppsafe -p compile_commands.json xxx.cpp.

Are these error all about I use a wrong version of gcc in my compile_commands.json? And I need to downgrade my gcc to 7.3.0?
Is it right ?

Thanks for helping.