[Bug c/80528] reimplement gnulib's "useless-if-before-free" script as a compiler warning

2024-06-26 Thread collin.funk1 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80528

--- Comment #8 from Collin Funk  ---
Thanks for the add. My change was just adding nullptr since it can be used in C
code (per C23). I agree with most of the other comments. Probably excessive for
-Wall and -Wextra since the idiom exists in old code still. But a warning that
is explicitly enabled would be nice.

[Bug bootstrap/115453] [15 regression] Noise from new dlopen, pthread configure checks since r15-1177-g75299e4fe50aa8

2024-06-19 Thread collin.funk1 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115453

--- Comment #16 from Collin Funk  ---
(In reply to Mark Wielaard from comment #15)
> -Copyright (C)  Free Software Foundation, Inc.
> +Copyright (C) 2012 Free Software Foundation, Inc.

I thought I used the correct Autoconf version, but I guess not. I think this
should go away if you regenerate with Autoconf 2.69 (released in 2012).

> -if test "x$gcc_cv_as_mips_explicit_relocs_pcrel" = "xyes"; then
> +if test $gcc_cv_as_mips_explicit_relocs_pcrel = yes; then

I think my commit was amended to include this. Therefore the configure script
must be generated again.

Sorry for the confusion.

[Bug bootstrap/115453] [15 regression] Noise from new dlopen, pthread configure checks since r15-1177-g75299e4fe50aa8

2024-06-19 Thread collin.funk1 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115453

--- Comment #14 from Collin Funk  ---
(In reply to Sam James from comment #11)
> But the crate vs create needs fixing still.

Oops. Sorry, I thought a correct patch here was being used not mine. If I had
known I would have submitted a fixed patch.

(In reply to YunQiang Su from comment #13)
> It has been fixed.

Thanks!

[Bug target/115409] avx512 intrinsics trigger -Wshift-overflow

2024-06-09 Thread collin.funk1 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115409

--- Comment #3 from Collin Funk  ---
Oops, Sorry about that. Here is the compile command:

gcc15.0  -I. -I./lib  -Ilib -I./lib -Isrc -I./src   -fstrict-flex-arrays -Wall
-Warith-conversion -Wbad-function-cast -Wcast-align=strict -Wdate-time
-Wdisabled-optimization -Wduplicated-cond -Wextra -Wformat-signedness
-Wflex-array-member-not-at-end -Winit-self -Winvalid-pch -Wlogical-op
-Wmissing-declarations -Wmissing-include-dirs -Wnull-dereference -Wopenmp-simd
-Woverlength-strings -Wpacked -Wpointer-arith -Wshadow -Wstrict-flex-arrays
-Wstrict-prototypes -Wsuggest-attribute=cold -Wsuggest-attribute=const
-Wsuggest-attribute=format -Wsuggest-attribute=malloc
-Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods
-Wsuggest-final-types -Wsync-nand -Wtrampolines -Wunknown-pragmas
-Wvariadic-macros -Wvla -Wwrite-strings -Warray-bounds=2 -Wattribute-alias=2
-Wbidi-chars=any,ucn -Wformat=2 -Wimplicit-fallthrough=5 -Wshift-overflow=2
-Wuse-after-free=3 -Wunused-const-variable=2 -Wvla-larger-than=4031
-Wno-sign-compare -Wno-unused-parameter -Wno-format-nonliteral
-fdiagnostics-show-option -funit-at-a-time -Wno-return-local-addr
-Wno-stringop-overflow -Wno-cast-qual -Wno-conversion -Wno-float-equal
-Wno-sign-compare -Wno-undef -Wno-unused-function -Wno-unused-parameter
-Wno-float-conversion -Wimplicit-fallthrough -Wno-pedantic -Wno-sign-conversion
-Wno-type-limits -Wno-unsuffixed-float-constants -g -O2 -MT
lib/libcoreutils_a-sm3.o -MD -MP -MF lib/.deps/libcoreutils_a-sm3.Tpo -c -o
lib/libcoreutils_a-sm3.o `test -f 'lib/sm3.c' || echo './'`lib/sm3.c
In file included from
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/immintrin.h:99:
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16vlintrin.h:
In function '_mm256_conj_pch':
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16vlintrin.h:184:80:
warning: result of '1 << 31' requires 33 bits to represent, but 'int' only has
32 bits [-Wshift-overflow=]
  184 |   return (__m256h) _mm256_xor_epi32 ((__m256i) __A,
_mm256_avx512_set1_epi32 (1<<31));
  |
   ^~
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16vlintrin.h:
In function '_mm_conj_pch':
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16vlintrin.h:212:74:
warning: result of '1 << 31' requires 33 bits to represent, but 'int' only has
32 bits [-Wshift-overflow=]
  212 |   return (__m128h) _mm_xor_epi32 ((__m128i) __A, _mm_avx512_set1_epi32
(1<<31));
  |
 ^~

I'll read the page you sent and send a patch to gcc-patches referencing this
bug report.

[Bug c/115409] New: avx512 intrinsics trigger -Wshift-overflow

2024-06-09 Thread collin.funk1 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115409

Bug ID: 115409
   Summary: avx512 intrinsics trigger -Wshift-overflow
   Product: gcc
   Version: 15.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: collin.funk1 at gmail dot com
  Target Milestone: ---

Created attachment 58396
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58396&action=edit
Patch with proposed fix.

When building GNU Coreutils from master:

In file included from
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/immintrin.h:97,
 from
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/x86intrin.h:32,
 from src/cksum_pclmul.c:22:
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16intrin.h:
In function '_mm512_conj_pch':
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16intrin.h:3358:73:
error: result of '1 << 31' requires 33 bits to represent, but 'int' only has 32
bits [-Werror=shift-overflow=]
 3358 |   return (__m512h) _mm512_xor_epi32 ((__m512i) __A, _mm512_set1_epi32
(1<<31));
  |
^~
In file included from
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/immintrin.h:99:
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16vlintrin.h:
In function '_mm256_conj_pch':
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16vlintrin.h:184:80:
error: result of '1 << 31' requires 33 bits to represent, but 'int' only has 32
bits [-Werror=shift-overflow=]
  184 |   return (__m256h) _mm256_xor_epi32 ((__m256i) __A,
_mm256_avx512_set1_epi32 (1<<31));
  |
   ^~
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16vlintrin.h:
In function '_mm_conj_pch':
/home/collin/.local/lib/gcc/x86_64-pc-linux-gnu/15.0.0/include/avx512fp16vlintrin.h:212:74:
error: result of '1 << 31' requires 33 bits to represent, but 'int' only has 32
bits [-Werror=shift-overflow=]
  212 |   return (__m128h) _mm_xor_epi32 ((__m128i) __A, _mm_avx512_set1_epi32
(1<<31));
  |
 ^~

This warning seems correct to me. I'm not very familiar with these functions
but I believe making the 1 unsigned before shifting should fix the issue. I
have attached a patch if you would like to double check it.

[Bug tree-optimization/114876] New: -fprintf-return-value mishandles %lc with a '\0' argument.

2024-04-28 Thread collin.funk1 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114876

Bug ID: 114876
   Summary: -fprintf-return-value  mishandles %lc with a '\0'
argument.
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: collin.funk1 at gmail dot com
  Target Milestone: ---

I noticed some test failures in some Gnulib test cases earlier [1].

I'm using Fedora 40's GCC 14.0 package.

$ uname -a
Linux fedora 6.8.7-300.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 17 19:21:08
UTC 2024 x86_64 GNU/Linux

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-14.0.1-20240411/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted
--without-cuda-driver --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
--with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240411 (Red Hat 14.0.1-0) (GCC) 

$ ldd --version
ldd (GNU libc) 2.39

Here is a test program:

===
int
main (void)
{
  char buffer[5000];
  wint_t ch = (wint_t) '\0';
  int result = sprintf (buffer, "%lc%lc%lc%lc", ch, ch, ch, ch);
  printf ("%d\n", result);
  return 0;
}
===

I believe that this program should print 4. POSIX states "Upon successful
completion, the sprintf() function shall return the number of bytes written to
s, excluding the terminating null byte." So in total 5 '\0' characters written
to the buffer and 4 returned because the extra terminating one is excluded.

Here is some runs with different optimization settings:

# -O0 passes.
$ make
gcc -Wall -Wextra -g -O0  -o a.out main.c
./a.out
4

# -01 fails, likewise for -O2 and -O3.
$ make
gcc -Wall -Wextra -g -O1  -o a.out main.c
./a.out
0

# -O0 -fprintf-return-value passes.
$ make
gcc -Wall -Wextra -g -O0 -fprintf-return-value -o a.out main.c
./a.out
4

# -01 -fprintf-return-value fails.
$ make
gcc -Wall -Wextra -g -O1 -fprintf-return-value -o a.out main.c
./a.out
0

# -O1 -fno-printf-return-value passes, likewise for -O2 and -O3 with
-fno-printf-return-value.
$ make
gcc -Wall -Wextra -g -O1 -fno-printf-return-value -o a.out main.c
./a.out
4

I also built a barebones gcc-13.2 compiler from the tarball on the GNU FTP
server. It seems to behave in the same way.

$ gcc-13.2 -v
Using built-in specs.
COLLECT_GCC=gcc-13.2
COLLECT_LTO_WRAPPER=/home/collin/.local/libexec/gcc/x86_64-pc-linux-gnu/13.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/collin/.local
--program-suffix=-13.2 --enable-languages=c,c++ --enable-threads=posix
--enable-linker-build-id --disable-multilib --disable-multiarch
--with-tune=generic --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (GCC) 

I've never submitted a GCC bug, so please let me know if you need any more
information. Thanks!

[1] https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00453.html