Re: [PATCH] Fix compile error in configure script

2024-05-20 Thread Edgar Bonet
Hello!

On 2024-05-20, Sergey Kandaurov wrote:
> Concerning type compatibility, C11 gives a definition on what types
> are compatible. [...]

Thank-you for sharing these findings!

> I like the patch, but would like to adjust the commit log:
> there some styles issues and over-quoting.  Also, there is
> no mention of Clang behaviour.  Please see below.
>
> # HG changeset patch
> # User Edgar Bonet 
> # Date 1715850910 -7200
> #  Thu May 16 11:15:10 2024 +0200
> # Node ID 8d35d9cfef17f350f750049940e22d1d61d55a6a
> # Parent  5a5c01ec6f58d413e9867ace5d0065bb43484a11
> Configure: fixed building libatomic test.
>
> Using "long *" instead of "AO_t *" leads either to 
> -Wincompatible-pointer-types
> or -Wpointer-sign warnings, depending on whether long and size_t are 
> compatible
> types (e.g., ILP32 versus LP64 data models).  Notably, -Wpointer-sign warnings
> are enabled by default in Clang only, and -Wincompatible-pointer-types is an
> error starting from GCC 14.
>
> Signed-off-by: Edgar Bonet 

This all looks good to me.

Regards,

Edgar.
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Fix compile error in configure script

2024-05-20 Thread Sergey Kandaurov
On Sat, May 18, 2024 at 02:43:52PM +0200, Edgar Bonet wrote:
> Hello!
> 
> Yesterday, I wrote:
> > My understanding is that the compiler considers 'int' and 'long' to be
> > incompatible types [... On ILP32,] 'size_t' being an 'unsigned int',
> > it is incompatible with 'long'.
> >
> > On LP64 (your typical 64-bit Linux/Mac), 'size_t' is a 'unsigned
> > long', which is compatible with 'long' but for the signedness warning.
> 
> I just did a small experiment to confirm all this. It shows that this
> “incompatible pointer type” error is specific to GCC 14 compiling for
> 32-bit targets. I natively compiled the following C file:
> 
> #include 
> 
> void callee(size_t *);
> 
> void caller(void)
> {
> long n;
> callee();
> }
> 
> on three different systems:
> 
>  1. gcc 11.4 / Ubuntu 22.04 / x86_64 (desktop PC, 64 bits)
>  2. gcc 12.2 / Debian 12 / i686 (Acer Aspire One A110L, 32 bits)
>  3. gcc 10.2 / Raspbian 11 / armv6l (Raspberry Pi model B, 32 bits)
> 
> On the 64-bit PC, the compiler issues no warnings unless I explicitly
> request them (e.g., with -Wall). If I do so, I get the signedness
> warning:
> 
> warning: pointer targets in passing argument 1 of ‘callee’
> differ in signedness [-Wpointer-sign]
> note: expected ‘size_t *’ {aka ‘long unsigned int *’}
> but argument is of type ‘long int *’
> 
> On both 32-bit systems, I get the following warning even with no -W*
> option:
> 
> warning: passing argument 1 of ‘callee’
> from incompatible pointer type [-Wincompatible-pointer-types]
> note: expected ‘size_t *’ {aka ‘unsigned int *’}
> but argument is of type ‘long int *’
> 
> This shows that:
> 
>   * ‘size_t’ is ‘unsigned int’ on ILP32 and ‘long unsigned int’ on LP64
> 
>   * ‘int’ and ’long int’ are considered incompatible even on ILP32,
> where they have the same size.
> 
> What changes with GCC 14 is that the “incompatible pointer type” warning
> has been changed to an error. The GCC 14 porting guide states:[1]

Thanks for clarification and testing, this matches my observation.

Concerning type compatibility, C11 gives a definition on what types
are compatible.  From the n1548 draft, §6.2.7:

: Two types have compatible type if their types are the same.

Following "§6.2.5 Types", int and long belong to different types
(regardless of signedness).

An §6.7.8 example further clarifies compatible type definitions:

:typedef struct s1 { int x; } t1, *tp1;
:typedef struct s2 { int x; } t2, *tp2;
:
: type t1 and the type pointed to by tp1 are compatible. Type t1 is
: also compatible with type struct s1, but not compatible with the
: types struct s2, t2, the type pointed to by tp2, or int.

On Thu, May 16, 2024 at 11:25:33AM +0200, Edgar Bonet wrote:
> # HG changeset patch
> # User Edgar Bonet 
> # Date 1715850910 -7200
> #  Thu May 16 11:15:10 2024 +0200
> # Node ID c2c3b0d74b1a7d3f967421c72760b5c573afcd81
> # Parent  89093b003fcb54c7f8dc66042f17bc4dea4e7709
> Fix compile error in configure script
> 
> Building with GCC 14 fails at the configure step with:
> 
> ./configure: error: libatomic_ops library was not found.
> 
> The error is not caused by a missing library, but by an unrelated
> "incompatible pointer type" error in the test program:
> 
> ...
> checking for atomic_ops library
> objs/autotest.c: In function 'main':
> objs/autotest.c:9:48: error: passing argument 1 of 'AO_compare_and_swap' 
> from incompatible pointer type [-Wincompatible-pointer-types]
> 
> Fix the error by using the correct pointer types.
> 
> Signed-off-by: Edgar Bonet 
> 
> diff -r 89093b003fcb -r c2c3b0d74b1a auto/lib/libatomic/conf
> --- a/auto/lib/libatomic/conf Fri May 03 20:26:05 2024 +0400
> +++ b/auto/lib/libatomic/conf Thu May 16 11:15:10 2024 +0200
> @@ -19,7 +19,7 @@
>#include "
>  ngx_feature_path=
>  ngx_feature_libs="-latomic_ops"
> -ngx_feature_test="long  n = 0;
> +ngx_feature_test="AO_t  n = 0;
>if (!AO_compare_and_swap(, 0, 1))
>return 1;
>if (AO_fetch_and_add(, 1) != 1)

I like the patch, but would like to adjust the commit log:
there some styles issues and over-quoting.  Also, there is
no mention of Clang behaviour.  Please see below.

# HG changeset patch
# User Edgar Bonet 
# Date 1715850910 -7200
#  Thu May 16 11:15:10 2024 +0200
# Node ID 8d35d9cfef17f350f750049940e22d1d61d55a6a
# Parent  5a5c01ec6f58d413e9867ace5d0065bb43484a11
Configure: fixed building libatomic test.

Using "long *" instead of "AO_t *" leads either to -Wincompatible-pointer-types
or -Wpointer-sign warnings, depending on whether long and size_t are compatible
types (e.g., ILP32 versus LP64 data models).  Notably, -Wpointer-sign warnings
are enabled by default in Clang only, and -Wincompatible-pointer-types is an
error starting from GCC 14.

Signed-off-by: Edgar Bonet 
___

Re: [PATCH] Fix compile error in configure script

2024-05-18 Thread Edgar Bonet
Hello!

Yesterday, I wrote:
> My understanding is that the compiler considers 'int' and 'long' to be
> incompatible types [... On ILP32,] 'size_t' being an 'unsigned int',
> it is incompatible with 'long'.
>
> On LP64 (your typical 64-bit Linux/Mac), 'size_t' is a 'unsigned
> long', which is compatible with 'long' but for the signedness warning.

I just did a small experiment to confirm all this. It shows that this
“incompatible pointer type” error is specific to GCC 14 compiling for
32-bit targets. I natively compiled the following C file:

#include 

void callee(size_t *);

void caller(void)
{
long n;
callee();
}

on three different systems:

 1. gcc 11.4 / Ubuntu 22.04 / x86_64 (desktop PC, 64 bits)
 2. gcc 12.2 / Debian 12 / i686 (Acer Aspire One A110L, 32 bits)
 3. gcc 10.2 / Raspbian 11 / armv6l (Raspberry Pi model B, 32 bits)

On the 64-bit PC, the compiler issues no warnings unless I explicitly
request them (e.g., with -Wall). If I do so, I get the signedness
warning:

warning: pointer targets in passing argument 1 of ‘callee’
differ in signedness [-Wpointer-sign]
note: expected ‘size_t *’ {aka ‘long unsigned int *’}
but argument is of type ‘long int *’

On both 32-bit systems, I get the following warning even with no -W*
option:

warning: passing argument 1 of ‘callee’
from incompatible pointer type [-Wincompatible-pointer-types]
note: expected ‘size_t *’ {aka ‘unsigned int *’}
but argument is of type ‘long int *’

This shows that:

  * ‘size_t’ is ‘unsigned int’ on ILP32 and ‘long unsigned int’ on LP64

  * ‘int’ and ’long int’ are considered incompatible even on ILP32,
where they have the same size.

What changes with GCC 14 is that the “incompatible pointer type” warning
has been changed to an error. The GCC 14 porting guide states:[1]

Type checking on pointer types (-Werror=incompatible-pointer-types)

GCC no longer allows implicitly casting all pointer types to all
other pointer types.

This is confirmed by the documentation of the option
-Wno-incompatible-pointer-types, which contains this sentence:[2]

By default, in C99 and later dialects of C, GCC treats this issue as
an error.

The sentence is absent from the GCC 13 documentation of the same
option.[3]

Regards,

Edgar.

[1] https://gcc.gnu.org/gcc-14/porting_to.html#incompatible-pointer-types
[2] 
https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/Warning-Options.html#index-Wno-incompatible-pointer-types
[3] 
https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Warning-Options.html#index-Wno-incompatible-pointer-types
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Fix compile error in configure script

2024-05-17 Thread Edgar Bonet
Hello!

Sergey Kandaurov wrote:
> > objs/autotest.c:9:48: error: passing argument 1
> > of 'AO_compare_and_swap' from incompatible pointer type
> > [-Wincompatible-pointer-types]
> 
> Where did you try to build?

I experienced this when building for arm and i686, both cross-compiled
from x86_64. Building for x86_64 works fine.

> Usually, long and size_t (a "common default" for AO_t) have the same
> underlying type, unless you build with something like MSVC.

AO_t is a 'volatile size_t'. The volatile qualifier may not matter
though. The error message about incompatible types was followed by
this note:

expected 'volatile size_t *' {aka 'volatile unsigned int *'}
but argument is of type 'long int *'

My understanding is that the compiler considers 'int' and 'long' to be
incompatible types, even though they have the same underlying
representation on ILP32 environments. I'm not a language lawyer, so I
cannot tell _why_ they are considered incompatible. But then, 'size_t'
being an 'unsigned int', it is incompatible with 'long'.

On LP64 (your typical 64-bit Linux/Mac), 'size_t' is a 'unsigned long',
which is compatible with 'long' but for the signedness warning.

Regards,

Edgar.
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Fix compile error in configure script

2024-05-17 Thread Sergey Kandaurov

> On 16 May 2024, at 13:25, Edgar Bonet  wrote:
> 
> # HG changeset patch
> # User Edgar Bonet 
> # Date 1715850910 -7200
> #  Thu May 16 11:15:10 2024 +0200
> # Node ID c2c3b0d74b1a7d3f967421c72760b5c573afcd81
> # Parent  89093b003fcb54c7f8dc66042f17bc4dea4e7709
> Fix compile error in configure script
> 
> Building with GCC 14 fails at the configure step with:
> 
>./configure: error: libatomic_ops library was not found.
> 
> The error is not caused by a missing library, but by an unrelated
> "incompatible pointer type" error in the test program:
> 
>...
>checking for atomic_ops library
>objs/autotest.c: In function 'main':
>objs/autotest.c:9:48: error: passing argument 1 of 'AO_compare_and_swap' 
> from incompatible pointer type [-Wincompatible-pointer-types]
> 

Where did you try to build?
Usually, long and size_t (a "common default" for AO_t) have the same
underlying type, unless you build with something like MSVC.

So far I only get signedness warnings with -Wpointer-sign on both
Clang and GCC 14 prerelease, and it is disabled by default on GCC.
The patch addresses them.
This warning option is documented to enable warnings other than
-Wincompatible-pointer-types.  It might have been changed in the
released version though.

> Fix the error by using the correct pointer types.
> 
> Signed-off-by: Edgar Bonet 
> 
> diff -r 89093b003fcb -r c2c3b0d74b1a auto/lib/libatomic/conf
> --- a/auto/lib/libatomic/conf Fri May 03 20:26:05 2024 +0400
> +++ b/auto/lib/libatomic/conf Thu May 16 11:15:10 2024 +0200
> @@ -19,7 +19,7 @@
>   #include "
> ngx_feature_path=
> ngx_feature_libs="-latomic_ops"
> -ngx_feature_test="long  n = 0;
> +ngx_feature_test="AO_t  n = 0;
>   if (!AO_compare_and_swap(, 0, 1))
>   return 1;
>   if (AO_fetch_and_add(, 1) != 1)
> ___
> nginx-devel mailing list
> nginx-devel@nginx.org
> https://mailman.nginx.org/mailman/listinfo/nginx-devel

-- 
Sergey Kandaurov
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel