From 11899b5cb151a606eb0d73db389e7a69a1b4af8d Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 23 Oct 2023 10:03:50 +1100 Subject: [PATCH] remove C++20 deprecated volatile argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This produced warnings like: g++ -c -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing \ -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 \ -xc++ -I/usr/lib/llvm-18/include -std=c++17 -fno-exceptions \ -funwind-tables -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS \ -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fexceptions \ -I/usr/lib/x86_64-linux-gnu/perl5/5.36/Imager/include -std=c++23 \ -O2 -g -DVERSION=\"1.000\" -DXS_VERSION=\"1.000\" -fPIC \ "-I/usr/lib/x86_64-linux-gnu/perl/5.36/CORE" LLVM.c In file included from /usr/lib/x86_64-linux-gnu/perl/5.36/CORE/perl.h:5798, from LLVM.xs:15: /usr/lib/x86_64-linux-gnu/perl/5.36/CORE/proto.h:392:65: warning: ‘volatile’-qualified parameter is deprecated [-Wvolatile] 392 | PERL_CALLCONV I32 Perl_call_sv(pTHX_ SV* sv, volatile I32 flags); | ~~~~~~~~~~~~~^~~~~ I haven't been able to produce this when building perl itself as C++ since it requires a modern -std argument to reproduce, and that breaks the build in other ways. It is reproducible when building a C++ XS module with gcc and -std=c++20 or later. In a strict standard sense flags does not need to be volatile since flags is not modified between setjmp() and longjmp(), but due to a bug in gcc, gcc complains flags could be clobbered. GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21161 --- embed.fnc | 2 +- perl.c | 6 +++++- proto.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/embed.fnc b/embed.fnc index ef9d34f84be0..97aac7afc649 100644 --- a/embed.fnc +++ b/embed.fnc @@ -772,7 +772,7 @@ CTadop |Malloc_t|calloc |MEM_SIZE elements \ AOdp |SSize_t|call_pv |NN const char *sub_name \ |I32 flags AOdp |SSize_t|call_sv |NN SV *sv \ - |volatile I32 flags + |I32 flags : Used in several source files Rp |bool |cando |Mode_t mode \ |bool effective \ diff --git a/perl.c b/perl.c index ec4492355206..6d1752203d14 100644 --- a/perl.c +++ b/perl.c @@ -3060,7 +3060,7 @@ See L. */ SSize_t -Perl_call_sv(pTHX_ SV *sv, volatile I32 flags) +Perl_call_sv(pTHX_ SV *sv, I32 arg_flags) /* See G_* flags in cop.h */ { LOGOP myop; /* fake syntax tree node */ @@ -3070,6 +3070,10 @@ Perl_call_sv(pTHX_ SV *sv, volatile I32 flags) bool oldcatch = CATCH_GET; int ret; OP* const oldop = PL_op; + /* Since we don't modify flags after setjmp() we don't really need to make + flags volatile, but gcc complains that it could be clobbered anyway. + */ + volatile I32 flags = arg_flags; dJMPENV; PERL_ARGS_ASSERT_CALL_SV; diff --git a/proto.h b/proto.h index cbb5b179a951..52fac1cfd1f2 100644 --- a/proto.h +++ b/proto.h @@ -444,7 +444,7 @@ Perl_call_pv(pTHX_ const char *sub_name, I32 flags); assert(sub_name) PERL_CALLCONV SSize_t -Perl_call_sv(pTHX_ SV *sv, volatile I32 flags); +Perl_call_sv(pTHX_ SV *sv, I32 flags); #define PERL_ARGS_ASSERT_CALL_SV \ assert(sv)