in reply to Re: Calling HePV - "warning: dereferencing type-punned pointer will break strict-aliasing rules"
in thread Calling HePV - "warning: dereferencing type-punned pointer will break strict-aliasing rules"

This is an external XS module that I am compiling.

Searching on that error gives me all sorts of doom and gloom about how this can lead to program malfunction, addressing memory by two different pointer types!

Not sure I believe it. Am tempted just to turn off strict-aliasing for that section. :)

  • Comment on Re^2: Calling HePV - "warning: dereferencing type-punned pointer will break strict-aliasing rules"

Replies are listed 'Best First'.
Re^3: Calling HePV - "warning: dereferencing type-punned pointer will break strict-aliasing rules"
by dave_the_m (Monsignor) on Jul 25, 2018 at 13:27 UTC
    This is an external XS module that I am compiling
    Yes, but XS modules are normally compiled using a similar set of compiler flags to that used to compile perl itself. Which is why I'm surprised that -fno-strict-aliasing isn't being passed. Compiling XS code without that flag while using perl macros which are intended to be used with that flag, is asking for subtle optimiser bugs to be introduced into your compiled code.

    Dave.

Re^3: Calling HePV - "warning: dereferencing type-punned pointer will break strict-aliasing rules"
by syphilis (Archbishop) on Jul 25, 2018 at 13:35 UTC
    This is an external XS module that I am compiling

    But if perl was built with -fno-strict-aliasing then one would expect that the compiler would not emit the warning when building an external XS module.
    If you provide us with the output of perl -V and tell us where we can view the entire source of the XS module, then we can perhaps shed some light on the matter.

    Cheers,
    Rob
      /usr/bin/perl /usr/share/perl5/vendor_perl/ExtUtils/xsubpp -typemap / +usr/share/perl5/ExtUtils/typemap -typemap typemap Utils.xs > Utils.x +sc && mv Utils.xsc Utils.c Please specify prototyping behavior for Utils.xs (see perlxs manual) gcc -c -I/DBA/lua/5.2.1/include -Wall -Wno-strict-aliasing -O2 -g -pi +pe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-stron +g --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic + -DVERSION=\"1.0\" -DXS_VERSION=\"1.0\" -fPIC "-I/usr/lib64/perl5/C +ORE" Utils.c Utils.xs: In function ‘perl_to_lua’: Utils.xs:263:13: warning: dereferencing type-punned pointer will break + strict-aliasing rules [-Wstrict-aliasing] char *key = HePV (he, key_len); ^ Utils.xs:263:13: warning: dereferencing type-punned pointer will break + strict-aliasing rules [-Wstrict-aliasing] Utils.xs:263:13: warning: dereferencing type-punned pointer will break + strict-aliasing rules [-Wstrict-aliasing] Utils.xs:263:13: warning: dereferencing type-punned pointer will break + strict-aliasing rules [-Wstrict-aliasing] Running Mkbootstrap for N2::Lua::Utils ()

      It's 1000 lines of XS code. I'd have to trim it down a bit.

      But in any case I think the answer is environmental, not in the code, as it compiles without warnings under Ubuntu 18.04, but WITH warnings under Oracle Linux Server 7.3.

      Here's the full build output. And I see that -Wno-strict-aliasing is actually present in the GCC options! So why on earth are we still getting that warning?

        And I see that -Wno-strict-aliasing is actually present in the GCC options! So why on earth are we still getting that warning?

        The "-Wall" enables the strict-aliasing warning.
        I think the "-Wno-strict-aliasing" would then disable that warning, but then there's a second "-Wall" switch which probably enables it again.

        You can edit the WriteMakefile() section of the module's Makefile.PL such that the flags are modified to give the behaviour you're after. (See the ExtUtils::MakeMaker documentation).
        I'm reluctant to be more specific because I'm not sure which flags are which. Output of perl -V should identify that for you.
        If both occurrences of "-Wall" are part of the same flagset, then I would remove the second occurrence. But if the second "-Wall" is in a different flagset (which is probably the case), then I would insert "-Wno-strict-aliasing" immediately after it.

        Cheers,
        Rob