[Bug tree-optimization/96963] [10 Regression] -Wstringop-overflow false positive on -O3 or -O2 -ftree-vectorize when assigning consecutive char struct members

2023-02-03 Thread pokechu022+gccbugzilla at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96963

Pokechu22  changed:

   What|Removed |Added

 CC||pokechu022+gccbugzilla@gmai
   ||l.com

--- Comment #16 from Pokechu22  ---
I ran into this with Dolphin Emulator (see
https://github.com/dolphin-emu/dolphin/pull/11534), but ran into trouble trying
to simplify it. Here's what I ended up with:

```
struct Foo {
char pad[40];
char a, b;
};
struct Bar {
  void Baz();
  // One of these needs to be uncommented for the issue to occur
  // virtual void Qux();
  // int x;
  Foo foo;
};
void heh(char *);
void Bar::Baz() {
  heh();
  foo.a = 1;
  foo.b = 1;
}
```

Based on Godbolt (https://godbolt.org/z/46aTrP3vj) I can confirm that this
doesn't happen in 11.0 or 9.3/9.5, and does happen on 10.1/10.2/10.3/10.4.

[Bug c++/108670] New: Bogus narrowing conversion warning with designated initializers for bitfield in union

2023-02-03 Thread pokechu022+gccbugzilla at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108670

Bug ID: 108670
   Summary: Bogus narrowing conversion warning with designated
initializers for bitfield in union
   Product: gcc
   Version: 12.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: pokechu022+gccbugzilla at gmail dot com
  Target Milestone: ---

This code (https://godbolt.org/z/4YGTfPoY9):

```
union Foo {
int x : 4;
};
union Bar {
int y : 4;
};
int foo() {
Foo foo{.x = 5};
Bar bar{.y = foo.x};
return bar.y;
}
```

Yields the following warning:

```
:9:22: warning: narrowing conversion of '(int)foo.Foo::x' from 'int' to
'signed char:4' [-Wnarrowing].
9 | Bar bar{.y = foo.x};
  |  ^
```

This warning does not make sense since both fields are the same size, and the
field is not a signed char. (A size of 31 will still show a warning with
int:31,  while int:32 gives no warning).

Foo can be either a struct or union. Weirdly, Bar must be a union (and I
couldn't get *any* narrowing conversion warnings to occur with it as a struct,
even if the sizes don't match).

I'm pretty sure this is different from bug 106371 and bug 87292 (though the
latter seems somewhat close). Nor does it match bug 102538. Based on
godbolt.org, this bug exists in the 4.7.1, the first version to support
designated initializers (though they weren't called that then).

This was originally encountered in Dolphin Emulator (see
https://github.com/dolphin-emu/dolphin/pull/11534).

[Bug c++/107755] ICE: in fold_convert_loc, at fold-const.c:2435, with -Wlogical-op, implicit user-defined conversion operator, template function, logical operator, and conditional operator

2022-11-18 Thread pokechu022+gccbugzilla at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107755

Pokechu22  changed:

   What|Removed |Added

  Known to fail||10.3.0, 12.2.0, 4.8.1,
   ||9.4.0
  Known to work||4.7.4

--- Comment #1 from Pokechu22  ---
Here are a few cases that would be useful to include in a test:

```
return (!false && (false ? a : b));
return (!true && (false ? a : b));
return (!false || (false ? a : b));
return (!true || (false ? a : b));
return (x && (y ? a : b));
return (x || (y ? a : b));
```

As an aside, `(false | (false ? a : b))` (where a is bool and b is Foo) used to
cause an ICE (confirmed in 4.7.4, 4.8.1, and 5.5). This was fixed in or before
6.1. I can't find a bug report corresponding to that issue either, but it
probably should be verified that that doesn't regress either.

[Bug c++/107755] New: ICE: in fold_convert_loc, at fold-const.c:2435, with -Wlogical-op, implicit user-defined conversion operator, template function, logical operator, and conditional operator

2022-11-18 Thread pokechu022+gccbugzilla at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107755

Bug ID: 107755
   Summary: ICE: in fold_convert_loc, at fold-const.c:2435, with
-Wlogical-op, implicit user-defined conversion
operator, template function, logical operator, and
conditional operator
   Product: gcc
   Version: 10.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: pokechu022+gccbugzilla at gmail dot com
  Target Milestone: ---

Created attachment 53928
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53928=edit
failing code using (!false && (false ? a : b))

A combination of -Wlogical-op, a template function, an implicit user-defined
conversion operator, a logical AND or OR operator, and a ternary conditional
operator results in an ICE.

```
$ gcc-10 -Wlogical-op -save-temps test.cpp
test.cpp: In function ‘bool Bar()’:
test.cpp:12:35: internal compiler error: in fold_convert_loc, at
fold-const.c:2435
   12 |   return (!false && (false ? a : b));
  |   ^
0x7f08a2bf4082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.
$ gcc-10 -v
Using built-in specs.
COLLECT_GCC=gcc-10
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
10.3.0-1ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-10
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-10-S4I5Pr/gcc-10-10.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-S4I5Pr/gcc-10-10.3.0/debian/tmp-gcn/usr,hsa
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-mutex
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
```

I tested at https://godbolt.org/z/574Wq1Ws5 and found that this issue was not
present in 4.7.4 and is present in 4.8.1, 12.2, and trunk. Here's the output on
trunk from compiler explorer, for convenience:

```
Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/gcc-snapshot/bin/g++
Target: x86_64-linux-gnu
Configured with: ../gcc-trunk-20221118/configure
--prefix=/opt/compiler-explorer/gcc-build/staging --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-bootstrap
--enable-multiarch --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --enable-clocale=gnu
--enable-languages=c,c++,fortran,ada,objc,obj-c++,d --enable-ld=yes
--enable-gold=yes --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-linker-build-id --enable-lto --enable-plugins --enable-threads=posix
--with-pkgversion=Compiler-Explorer-Build-gcc-7b3b2f50953c5143d4b14b59d322d8a793f411dd-binutils-2.38
--enable-libstdcxx-backtrace=yes
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20221117 (experimental)
(Compiler-Explorer-Build-gcc-7b3b2f50953c5143d4b14b59d322d8a793f411dd-binutils-2.38)
 
COLLECT_GCC_OPTIONS='-fdiagnostics-color=always' '-g' '-o' '/app/output.s'
'-masm=intel' '-S' '-Wlogical-op' '-v' '-shared-libgcc' '-mtune=generic'
'-march=x86-64' '-dumpdir' '/app/'

/opt/compiler-explorer/gcc-trunk-20221118/bin/../libexec/gcc/x86_64-linux-gnu/13.0.0/cc1plus
-quiet -v -imultiarch x86_64-linux-gnu -iprefix
/opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/x86_64-linux-gnu/13.0.0/
-D_GNU_SOURCE  -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase-ext
.cpp -masm=intel -mtune=generic -march=x86-64 -g -Wlogical-op -version
-fdiagnostics-color=always -o /app/output.s
GNU C++17
(Compiler-Explorer-Build-gcc-7b3b2f50953c5143d4b14b59d322d8a793f411dd-binutils-2.38)
version 13.0.0 20221117 (experimental) (x86_64-linux-gnu)
compiled by GNU C version 9.4.0, GMP version 6.2.1, MPFR version 

[Bug c++/80351] Inconsistent warning for constexpr auto constant when using initializer list (-Wunused-variable)

2022-03-21 Thread pokechu022+gccbugzilla at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80351

--- Comment #4 from Pokechu22  ---
This also affects const variables, not just constexpr ones.  See
https://godbolt.org/z/5coadhr8a.

The source of the issue is that the type is not complete the first time when
cp_apply_type_quals_to_decl (in cp/typeck.cc) is called by cp_finish_decl (in
cp/decl.cc); since it is not complete, cp_apply_type_quals_to_decl removes the
const qualifier on the assumption that cp_finish_decl will later add it, but
it's too late for that.  (cp_apply_type_quals_to_decl is also called earlier on
by grokdeclarator (cp/decl.cc) where that assumption is valid).  The type is
already complete when a second variable is declared, which is why the warning
only appears once.  Presumably, initializer lists are the only type where auto
can deduce to something that hasn't been completed yet (though I'm not 100%
sure of this).

This change fixes the issue:

```
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@@ -8098,7 -8098,7 +8098,7 @@@ cp_finish_decl (tree decl, tree init, b
 TREE_TYPE (decl) = error_mark_node;
 return;
   }
-  cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
+  cp_apply_type_quals_to_decl (cp_type_quals (complete_type (type)),
decl);
 }

   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
```

I am working on sending in a proper patch with testcases.  (I assume I will not
need to fill out the contributing agreement for a change this small.)

[Bug c++/80351] Inconsistent warning for constexpr auto constant when using initializer list (-Wunused-variable)

2022-01-17 Thread pokechu022+gccbugzilla at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80351

Pokechu22  changed:

   What|Removed |Added

 CC||pokechu022+gccbugzilla@gmai
   ||l.com

--- Comment #3 from Pokechu22  ---
Still an issue in GCC 11.2.

Here are some additional examples: https://godbolt.org/z/hvEs6bb95
https://godbolt.org/z/674seG3bn https://godbolt.org/z/6esEs1fsr
https://godbolt.org/z/s8eqsnzP9 https://godbolt.org/z/1TjnP6GeG
https://godbolt.org/z/czefeKWsf

The use of an enum class isn't needed; the issue also happens with int.

In GCC 7.1+, marking warn as [[maybe_unused]] removes the warning (it doesn't
get shifted to no_warn); GCC 6.4- give an additional warning that
"'maybe_unused' attribute directive ignored" (it may not have been implemented
then).

Explicitly using std::initializer_list instead of auto resolves the issue.
 In GCC 9.2+, only warn needs to be changed to have an explicit type (no_warn
can remain as auto without a warning being generated), but in GCC 9.1-, the
first use of auto will generate the warning (meaning no_warn will generate a
warning unless it too is changed).

If different types are used, then one warning is generated for each type (e.g.
{1, 2} and {1u, 2u} each generate one warning).

The behavior of only one warning being generated started in GCC 4.8.1+;
multiple warnings were generated in 4.7.4-.