Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffi/record_meta.c:64:16: warning: returning 'struct _ffi_type **' from a function with incompatible return type 'ffi_type *' {aka 'struct _ffi_type *'} #153

Closed
ppisar opened this issue Jul 24, 2019 · 2 comments

Comments

@ppisar
Copy link
Contributor

commented Jul 24, 2019

When building FFI-Platypus-0.94 against libffi-3.1, gcc-9.1.1 emits these warnings:

gcc -fPIC -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FO
RTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -c ffi/record_meta.c -o ffi/_build/record_meta.c.o
ffi/record_meta.c: In function 'ffi_platypus_record_meta__new':
ffi/record_meta.c:32:20: warning: assignment to 'struct _ffi_type **' from incompatible pointer type 'ffi_type * (*)[]' [-Wincompatible-pointer-types]
   32 |   t->top.elements  = &t->elements;
      |                    ^
ffi/record_meta.c: In function 'ffi_platypus_record_meta__element_pointers':
ffi/record_meta.c:64:16: warning: returning 'struct _ffi_type **' from a function with incompatible return type 'ffi_type *' {aka 'struct _ffi_type *'} [-Wincompatible-pointer-types] 
   64 |   return t->top.elements;
      |          ~~~~~~^~~~~~~~~

The ffi_type is declared as:

typedef struct _ffi_type
{ 
  size_t size;
  unsigned short alignment;
  unsigned short type;
  struct _ffi_type **elements;
} ffi_type;

While the first warning looks like a deficiency in (or pedanticaly strict) compiler, the second warning is indeed a bug in the FFI-Platypus.

@plicease

This comment has been minimized.

Copy link
Member

commented Jul 24, 2019

I think this turns out to be harmless? It would be a problem if a C function were using ffi_platypus_record_meta__element_pointers and not expecting an array of pointers, but it gets called by a Perl level function that is expecting an array of opaque (essentially void*). Thanks for raising it though, I think #155 should address it.

@ppisar

This comment has been minimized.

Copy link
Contributor Author

commented Jul 24, 2019

If the pointers are processed as void*, then they are indeed harmless. (Although compilers are sometimes very smart when optimizing code and these kind of warnings are precursor for strict aliasing violations that are harmful).

And yes, #155 fixes the warnings. Thank you.

@plicease plicease closed this Jul 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.