Re: [pcre-dev] Compiler warnings in JIT with NEON instructio…

Páxina inicial
Borrar esta mensaxe
Autor: Petr Pisar
Data:  
Para: pcre-dev
Asunto: Re: [pcre-dev] Compiler warnings in JIT with NEON instructions
On Fri, Nov 08, 2019 at 04:25:07PM +0000, ph10@??? wrote:
> On Thu, 7 Nov 2019, Petr Pisar via Pcre-dev wrote:
>
> > I can see GCC 4.8.5 prints these warnings on 32-bit PowerPC:
> >
> > gcc -DHAVE_CONFIG_H -I. -I./src  "-I./src"     -pthread -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m32 -mcpu=power7 -mtune=power7 -c -o src/pcre2test-pcre2test.o `test -f 'src/pcre2test.c' || echo './'`src/pcre2test.c
> > [...]
> > src/pcre2test.c: In function 'process_pattern':
> > src/pcre2test.c:5212:13: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'int' [-Wformat=]
> >              "opening quote is at offset %" PTR_FORM ".\n", pq - buffer - 2);

>
> I am going to need some help here. The PTR_FORM macro is set to the
> appropriate print format for pointers. It is currently defined like
> this:
>
> /* VC and older compilers don't support %td or %zu, and even some that claim to
> be C99 don't support it (hence DISABLE_PERCENT_ZT). */
>
> #if defined(_MSC_VER) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L || defined(DISABLE_PERCENT_ZT)
> #define PTR_FORM "lu"
> #define SIZ_FORM "lu"
> #define SIZ_CAST (unsigned long int)
> #else
> #define PTR_FORM "td"
> #define SIZ_FORM "zu"
> #define SIZ_CAST
> #endif
>
> I presume you are seeing %lu because gcc 4.8.5 triggers the
> __STDC_VERSION__ test.


Yes. GCC 4.8.5 defaults to -std=gnu90 and __STDC_VERSION__ is not defined
there. Recent GCC defaults to gnu17 and __STDC_VERSION__ is "201710L".

> What is the best way (compatible with 4.8.5) to
> test for being in a 32-bit system at preprocessor time? Is
>

The issue is that 32-bit integers do not mean 32-bit pointers. E.g. MIPS64
n32 ABI and AMD64 x32 ABI have 64-bit integers but 32-bit pointers.

GCC provides __SIZEOF_POINTER__ macro, but I don't think there is any
standard for that.

A portable way requires testing a sizeof() operator output in ./configure
script. But that needs executing the compiled code and that would be problem
when crosscompiling.

> #if LONG_MAX == 2147483647
>
> the right way to do it? If so, then PTR_FORM and SIZ_FORM can be defined
> as "u" when that test is true. Presumably the cast is OK.
>

Accordig to my tests with GCC and glibc for Linux, LONG_MAX indicates size of
integers correctly. But I don't have any other compilers or platforms
available. Web search reveals that some Windows systems (LLP64 model) have
long int shorter than a pointer
<http://infocenter.arm.com/help/topic/com.arm.doc.dai0490a/ar01s01.html>.

Frankly I don't believe there is a way of solving it and I'd just keep the
warning there. Using C99 conformant compilers is the correct way. E.g. passing
-std=c99 to GCC with glibc fixes the warning. I'd just document it somwehere
in README or in source code near the PTR_FORM macro definition.

-- Petr