timbunce / devel-nytprof

Devel::NYTProf is a powerful feature-rich source code profiler for Perl. (Mostly in maintenance mode, so PRs are much more likely to be acted upon than Issues.)
http://blog.timbunce.org/tag/nytprof/
67 stars 50 forks source link

Build-time warnings using g++ as compiler #191

Open jkeenan opened 3 years ago

jkeenan commented 3 years ago

With a perl-5.32.1 compiled on FreeBSD with g++, I got these build-time errors when running make for Devel-NYTProf:

"/usr/home/jkeenan/testing/perl-5.32.1/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- NYTProf.bs blib/arch/auto/Devel/NYTProf/NYTProf.bs 644
"/usr/home/jkeenan/testing/perl-5.32.1/bin/perl" "/home/jkeenan/testing/perl-5.32.1-gpp/lib/5.33.9/ExtUtils/xsubpp"  -typemap '/home/jkeenan/testing/perl-5.32.1/lib/5.33.9/ExtUtils/typemap' -typemap '/usr/home/jkeenan/gitwork/devel-nytprof/typemap'  FileHandle.xs > FileHandle.xsc
mv FileHandle.xsc FileHandle.c
g++ -c    -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_FORTIFY_SOURCE=2 -O2 -pipe -fstack-protector -fno-strict-aliasing    -DVERSION=\"6.09_001\"  -DXS_VERSION=\"6.09_001\" -DPIC -fPIC "-I/home/jkeenan/testing/perl-5.32.1/lib/5.33.9/amd64-freebsd-thread-multi/CORE"  -DHAS_CLOCK_GETTIME -DHAS_ZLIB -DUSE_HARD_ASSERT -W -Wall -Wpointer-arith -Wbad-function-cast -Wno-comment -Wno-sign-compare -Wno-cast-qual -Wmissing-noreturn -Wno-unused-parameter FileHandle.c
cc1plus: warning: command line option '-Wbad-function-cast' is valid for C/ObjC but not for C++
FileHandle.xs:972:60: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
  972 |     const size_t len = my_snprintf(buffer, sizeof(buffer), "%"NVgf, value);
      |                                                            ^
FileHandle.xs:992:60: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
  992 |     const size_t len = my_snprintf(buffer, sizeof(buffer), "%"IVdf, value);
      |                                                            ^
"/usr/home/jkeenan/testing/perl-5.32.1/bin/perl" "/home/jkeenan/testing/perl-5.32.1-gpp/lib/5.33.9/ExtUtils/xsubpp"  -typemap '/home/jkeenan/testing/perl-5.32.1/lib/5.33.9/ExtUtils/typemap' -typemap '/usr/home/jkeenan/gitwork/devel-nytprof/typemap'  NYTProf.xs > NYTProf.xsc
mv NYTProf.xsc NYTProf.c
g++ -c    -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_FORTIFY_SOURCE=2 -O2 -pipe -fstack-protector -fno-strict-aliasing    -DVERSION=\"6.09_001\"  -DXS_VERSION=\"6.09_001\" -DPIC -fPIC "-I/home/jkeenan/testing/perl-5.32.1/lib/5.33.9/amd64-freebsd-thread-multi/CORE"  -DHAS_CLOCK_GETTIME -DHAS_ZLIB -DUSE_HARD_ASSERT -W -Wall -Wpointer-arith -Wbad-function-cast -Wno-comment -Wno-sign-compare -Wno-cast-qual -Wmissing-noreturn -Wno-unused-parameter NYTProf.c
cc1plus: warning: command line option '-Wbad-function-cast' is valid for C/ObjC but not for C++
NYTProf.xs:1841:58: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 1841 |             sprintf(&filename_buf[strlen(filename_buf)], ".%.0"NVff"", gettimeofday_nv());
      |                                                          ^
NYTProf.xs:1860:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 1860 |         logwarn("~ opened %s at %.6"NVff"\n", filename, gettimeofday_nv());
      |                 ^
NYTProf.xs:1890:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 1890 |         logwarn("~ closed file at %.6"NVff"\n", timeofday);
      |                 ^
NYTProf.xs:1904:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 1904 |         logwarn("~ new pid %d (was %d) forkdepth %"IVdf"\n", getpid(), last_pid, profile_forkdepth);
      |                 ^
NYTProf.xs:2229:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2229 |         logwarn("%2u <-     %s %"NVgf" excl = %"NVgf"t incl - %"NVgf"t (%"NVgf"-%"NVgf"), oh %"NVff"-%"NVff"=%"NVff"t, d%d @%d:%d #%lu %p\n",
      |                 ^
NYTProf.xs:2229:38: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2229 |         logwarn("%2u <-     %s %"NVgf" excl = %"NVgf"t incl - %"NVgf"t (%"NVgf"-%"NVgf"), oh %"NVff"-%"NVff"=%"NVff"t, d%d @%d:%d #%lu %p\n",
      |                                      ^
NYTProf.xs:2229:53: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2229 |         logwarn("%2u <-     %s %"NVgf" excl = %"NVgf"t incl - %"NVgf"t (%"NVgf"-%"NVgf"), oh %"NVff"-%"NVff"=%"NVff"t, d%d @%d:%d #%lu %p\n",
      |                                                     ^
NYTProf.xs:2229:69: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2229 |         logwarn("%2u <-     %s %"NVgf" excl = %"NVgf"t incl - %"NVgf"t (%"NVgf"-%"NVgf"), oh %"NVff"-%"NVff"=%"NVff"t, d%d @%d:%d #%lu %p\n",
      |                                                                     ^
NYTProf.xs:2229:79: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2229 |         logwarn("%2u <-     %s %"NVgf" excl = %"NVgf"t incl - %"NVgf"t (%"NVgf"-%"NVgf"), oh %"NVff"-%"NVff"=%"NVff"t, d%d @%d:%d #%lu %p\n",
      |                                                                               ^
NYTProf.xs:2229:87: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2229 |         logwarn("%2u <-     %s %"NVgf" excl = %"NVgf"t incl - %"NVgf"t (%"NVgf"-%"NVgf"), oh %"NVff"-%"NVff"=%"NVff"t, d%d @%d:%d #%lu %p\n",
      |                                                                                       ^
NYTProf.xs:2229:100: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2229 |         logwarn("%2u <-     %s %"NVgf" excl = %"NVgf"t incl - %"NVgf"t (%"NVgf"-%"NVgf"), oh %"NVff"-%"NVff"=%"NVff"t, d%d @%d:%d #%lu %p\n",
      |                                                                                                    ^
NYTProf.xs:2229:108: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2229 |         logwarn("%2u <-     %s %"NVgf" excl = %"NVgf"t incl - %"NVgf"t (%"NVgf"-%"NVgf"), oh %"NVff"-%"NVff"=%"NVff"t, d%d @%d:%d #%lu %p\n",
      |                                                                                                            ^
NYTProf.xs:2405:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2405 |         logwarn("NYTProf panic: stack is confused, giving up! (Try running with subs=0) ix=%"IVdf" prev_ix=%"IVdf"\n", (IV)subr_entry_ix, (IV)prev_subr_entry_ix);
      |                 ^
NYTProf.xs:2405:98: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2405 |         logwarn("NYTProf panic: stack is confused, giving up! (Try running with subs=0) ix=%"IVdf" prev_ix=%"IVdf"\n", (IV)subr_entry_ix, (IV)prev_subr_entry_ix);
      |                                                                                                  ^
NYTProf.xs:2895:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2895 |         logwarn("%2u ->%4s %s::%s from %s::%s @%u:%u (d%d, oh %"NVff"t, sub %"NVff"s) #%lu\n",
      |                 ^
NYTProf.xs:2895:69: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 2895 |         logwarn("%2u ->%4s %s::%s from %s::%s @%u:%u (d%d, oh %"NVff"t, sub %"NVff"s) #%lu\n",
      |                                                                     ^
NYTProf.xs:3031:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 3031 |         logwarn("~ disable_profile (previously %s, pid %d, trace %"IVdf")\n",
      |                 ^
NYTProf.xs:3051:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 3051 |         logwarn("~ finish_profile (overhead %"NVgf"t, is_profiling %d)\n",
      |                 ^
NYTProf.xs:3679:29: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 3679 |                     logwarn("%s call has negative time: incl %"NVff"s, excl %"NVff"s:\n",
      |                             ^
NYTProf.xs:3679:68: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 3679 |                     logwarn("%s call has negative time: incl %"NVff"s, excl %"NVff"s:\n",
      |                                                                    ^
NYTProf.xs:3690:29: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 3690 |                     logwarn("%s called by %.*s at %u:%u: count %ld (i%"NVff"s e%"NVff"s, d%d ri%"NVff"s)\n",
      |                             ^
NYTProf.xs:3690:76: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 3690 |                     logwarn("%s called by %.*s at %u:%u: count %ld (i%"NVff"s e%"NVff"s, d%d ri%"NVff"s)\n",
      |                                                                            ^
NYTProf.xs:3690:86: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 3690 |                     logwarn("%s called by %.*s at %u:%u: count %ld (i%"NVff"s e%"NVff"s, d%d ri%"NVff"s)\n",
      |                                                                                      ^
NYTProf.xs:4279:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 4279 |         logwarn("Sub %s called by %s %u:%u: count %d, incl %"NVff", excl %"NVff"\n",
      |                 ^
NYTProf.xs:4279:66: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 4279 |         logwarn("Sub %s called by %s %u:%u: count %d, incl %"NVff", excl %"NVff"\n",
      |                                                                  ^
NYTProf.xs:4401:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 4401 |         logwarn("Start of profile data for pid %s (ppid %d, %"IVdf" pids live) at %"NVff"\n",
      |                 ^
NYTProf.xs:4401:67: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 4401 |         logwarn("Start of profile data for pid %s (ppid %d, %"IVdf" pids live) at %"NVff"\n",
      |                                                                   ^
NYTProf.xs:4433:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 4433 |         logwarn("End of profile data for pid %s (%"IVdf" remaining) at %"NVff"\n", text,
      |                 ^
NYTProf.xs:4433:56: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 4433 |         logwarn("End of profile data for pid %s (%"IVdf" remaining) at %"NVff"\n", text,
      |                                                        ^
NYTProf.xs:5004:17: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 5004 |         logwarn("Profile data incomplete, no terminator for %"IVdf" pids %s\n",
      |                 ^
NYTProf.xs:5046:21: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 5046 |             logwarn("The sum of the statement timings is %.1"NVff"%% of the total time profiling."
      |                     ^
NYTProf.xs:5054:21: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 5054 |             logwarn("Summary: statements profiled %lu (=%lu-%lu), sum of time %"NVff"s, profile spanned %"NVff"s\n",
      |                     ^
NYTProf.xs:5054:85: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
 5054 |             logwarn("Summary: statements profiled %lu (=%lu-%lu), sum of time %"NVff"s, profile spanned %"NVff"s\n",
      |                                                                                     ^
NYTProf.xs:226:37: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  226 | static Hash_table fidhash = { NULL, "fid", MAX_HASH_SIZE, sizeof(fid_hash_entry), NULL, NULL, NULL, 1 };
      |                                     ^~~~~
NYTProf.xs:231:37: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  231 | static Hash_table strhash = { NULL, "str", MAX_HASH_SIZE, sizeof(str_hash_entry), NULL, NULL, NULL, 1 };
      |                                     ^~~~~
NYTProf.xs:243:44: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  243 | static char *nytp_panic_overflow_msg_fmt = "panic: buffer overflow of %s on '%s' (see TROUBLESHOOTING section of the NYTProf documentation)";
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jkeenan commented 3 years ago

https://github.com/timbunce/devel-nytprof/pull/190 -- which is a cherry-pick of a patch from @rurban from 2 years ago -- appears to clear up most of these warnings. Here is my before/after comparison:

Effect of applying rurban patch 5599d1ab50 in branch gpp-build-time-warnings-20210505

[perlmonger: devel-nytprof] $ ~/bin/perl/report-build-warnings gpp.master.output.txt
File:  gpp.master.output.txt

  Wliteral-suffix                           35
  Wwrite-strings                             3

[perlmonger: devel-nytprof] $ ~/bin/perl/report-build-warnings gpp.branch.output.txt
File:  gpp.branch.output.txt

  Wwrite-strings                             3
jkeenan commented 3 years ago

With one more commit to the gpp-build-time-warnings-20210505 branch (https://github.com/timbunce/devel-nytprof/pull/190), we can reduce the remaining number of g++ build-time warnings from 3 to 2.

 ~/bin/perl/report-build-warnings gpp.branch.output.2nd.txt
File:  gpp.branch.output.2nd.txt

  Wwrite-strings                             2
jkeenan commented 3 years ago

With release of CPAN version 6.10, 2 -Wwrite-strings build-time warnings remain when compiling with g++.

jkeenan commented 2 years ago

With release of CPAN version 6.10, 2 -Wwrite-strings build-time warnings remain when compiling with g++.

$ parse-build-warnings 5c915c93d2.freebsd.g++9.make.output.txt.gz 
File:  5c915c93d2.freebsd.g++9.make.output.txt.gz

[
  {
    char   => 37,
    group  => "Wwrite-strings",
    line   => 226,
    source => "NYTProf.xs",
    text   => "ISO C++ forbids converting a string constant to 'char*'",
  },
  {
    char   => 37,
    group  => "Wwrite-strings",
    line   => 231,
    source => "NYTProf.xs",
    text   => "ISO C++ forbids converting a string constant to 'char*'",
  },
]
jkeenan commented 9 months ago

My local and remote machines have been upgraded. Here is a status update on warnings emitted during make when compiling Devel-NYTProf (master branch) with the default versions of g++.

Ubuntu Linux 22.04 LTS

$ g++ --version | head -n 1
g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

$ report-build-warnings 2a11e63e8d.linux.g++-11.make.output.txt.gz 
File:  2a11e63e8d.linux.g++-11.make.output.txt.gz

  Wregister                                  4
  Wwrite-strings                             2

$ parse-build-warnings 2a11e63e8d.linux.g++-11.make.output.txt.gz 
File:  2a11e63e8d.linux.g++-11.make.output.txt.gz

[
  {
    char   => 37,
    group  => "Wwrite-strings",
    line   => 226,
    source => "NYTProf.xs",
    text   => "ISO C++ forbids converting a string constant to \xE2\x80\x98char*\xE2\x80\x99",
  },
  {
    char   => 37,
    group  => "Wwrite-strings",
    line   => 231,
    source => "NYTProf.xs",
    text   => "ISO C++ forbids converting a string constant to \xE2\x80\x98char*\xE2\x80\x99",
  },
  {
    char   => 28,
    group  => "Wregister",
    line   => 1281,
    source => "NYTProf.xs",
    text   => "ISO C++17 does not allow \xE2\x80\x98register\xE2\x80\x99 storage class specifier",
  },
  {
    char   => 18,
    group  => "Wregister",
    line   => 1407,
    source => "NYTProf.xs",
    text   => "ISO C++17 does not allow \xE2\x80\x98register\xE2\x80\x99 storage class specifier",
  },
  {
    char   => 28,
    group  => "Wregister",
    line   => 1408,
    source => "NYTProf.xs",
    text   => "ISO C++17 does not allow \xE2\x80\x98register\xE2\x80\x99 storage class specifier",
  },
  {
    char   => 28,
    group  => "Wregister",
    line   => 1409,
    source => "NYTProf.xs",
    text   => "ISO C++17 does not allow \xE2\x80\x98register\xE2\x80\x99 storage class specifier",
  },
]

FreeBSD-13

$ g++ --version | head -n 1
g++ (FreeBSD Ports Collection) 12.2.0

$ report-build-warnings 2a11e63e8d.freebsd.threaded.gcc12.make.output.tx
t.gz
File:  2a11e63e8d.freebsd.threaded.gcc12.make.output.txt.gz

  Wregister                                  4
  Wwrite-strings                             2

$ parse-build-warnings 2a11e63e8d.freebsd.threaded.gcc12.make.output.txt.gz 
File:  2a11e63e8d.freebsd.threaded.gcc12.make.output.txt.gz

[
  {
    char   => 37,
    group  => "Wwrite-strings",
    line   => 226,
    source => "NYTProf.xs",
    text   => "ISO C++ forbids converting a string constant to 'char*'",
  },
  {
    char   => 37,
    group  => "Wwrite-strings",
    line   => 231,
    source => "NYTProf.xs",
    text   => "ISO C++ forbids converting a string constant to 'char*'",
  },
  {
    char   => 28,
    group  => "Wregister",
    line   => 1281,
    source => "NYTProf.xs",
    text   => "ISO C++17 does not allow 'register' storage class specifier",
  },
  {
    char   => 18,
    group  => "Wregister",
    line   => 1407,
    source => "NYTProf.xs",
    text   => "ISO C++17 does not allow 'register' storage class specifier",
  },
  {
    char   => 28,
    group  => "Wregister",
    line   => 1408,
    source => "NYTProf.xs",
    text   => "ISO C++17 does not allow 'register' storage class specifier",
  },
  {
    char   => 28,
    group  => "Wregister",
    line   => 1409,
    source => "NYTProf.xs",
    text   => "ISO C++17 does not allow 'register' storage class specifier",
  },
]

So on both platforms g++ is now emitting -Wregister warnings related to C++17. Context (from the FreeBSD run):

NYTProf.xs: In function ‘int dopopcx_at(PerlInterpreter*, PERL_CONTEXT*, I32, UV)’:
NYTProf.xs:1281:28: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 1281 |     register PERL_CONTEXT *cx;
      |                            ^~
NYTProf.xs: In function ‘PERL_CONTEXT* visit_contexts(PerlInterpreter*, UV, int (*)(PerlInterpreter*, PERL_CONTEXT*, UV*))’:
NYTProf.xs:1407:18: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 1407 |     register I32 cxix = cxstack_ix;
      |                  ^~~~
NYTProf.xs:1408:28: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 1408 |     register PERL_CONTEXT *cx = NULL;
      |                            ^~
NYTProf.xs:1409:28: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 1409 |     register PERL_CONTEXT *ccstack = cxstack;
      |                            ^~~~~~~

I don't follow C++ development. Is there anyone who could shed some light on this?

jkeenan commented 9 months ago

The 4 -Wregister warnings should be gone as of version 6.13 of Devel-NYTProf, uploaded just now to CPAN. That should leave the 2 -Wwrite-strings warnings.