[Bug analyzer/94365] false positive leak when using container_of-like constructs

2021-06-12 Thread dimitri at ouroboros dot rocks via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94365

dimitri at ouroboros dot rocks changed:

   What|Removed |Added

 CC||dimitri at ouroboros dot rocks

--- Comment #1 from dimitri at ouroboros dot rocks ---
Thanks for filing this one. 

We're using a double-linked-list implementation which also has this construct
using offsetof and are also seeing false positives in these parts of the code.
I thought the analyzer may have trouble with the list pointers, but I think it
will actually be the offsetof that is causing it.

[Bug tree-optimization/101039] New: Some simple fold_cond_expr_with_comparison with CMP 0 is not simplified

2021-06-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101039

Bug ID: 101039
   Summary: Some simple fold_cond_expr_with_comparison with CMP 0
is not simplified
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Keywords: missed-optimization
  Severity: enhancement
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take at -O2:
int f0(int A)
{
// A == 0? A : -Asame as -A
  if (A == 0)  return A;
  return -A;
}

int f1(int A)
{
// A != 0? A : -Asame as A
  if (A != 0)  return A;
  return -A;
}
int f2(int A)
{
// A >= 0? A : -Asame as abs (A)
  if (A >= 0)  return A;
  return -A;
}
int f3(int A)
{
// A > 0?  A : -Asame as abs (A)
  if (A > 0)  return A;
  return -A;
}
int f4(int A)
{
// A <= 0? A : -Asame as -abs (A)
  if (A <= 0)  return A;
  return -A;
}
int f5(int A)
{
// A < 0?  A : -Asame as -abs (A)
  if (A < 0)  return A;
  return -A;
}

-- CUT ---
Only f1-f3 are optimized at the gimple level.  f0, f4, f5 are not.
With -Dint=float -Ofast, only f0 is not optimized but note f1 takes until
*.phiopt3 be optimized; and unlike int, f4 and f5 are optimized in phiopt2.

Note phiopt1 is still confused by predictor but I think there might be another
bug for that.

[Bug c++/101040] New: [11 Regression] Internal compiler error: in get_or_insert_ctor_field, at cp/constexpr.c:3571

2021-06-12 Thread git at foonathan dot net via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101040

Bug ID: 101040
   Summary: [11 Regression] Internal compiler error: in
get_or_insert_ctor_field, at cp/constexpr.c:3571
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: git at foonathan dot net
  Target Milestone: ---

Minimal repro: https://godbolt.org/z/n71dhjPox

```
// This class has to be empty.
struct empty
{};

// This class has to be empty.
struct single
{
// This member has to be no_unique_address.
[[no_unique_address]] empty obj;
};

// This class has to be empty and derived from single.
struct derived : single
{
// This constructor has to be constexpr and take a forwarding reference.
template 
constexpr derived(Arg&& arg) : single{arg}
{}
};

auto obj = derived{empty{}};
```

Fails on GCC 11.1 and trunk:

```
source>:21:27:   in 'constexpr' expansion of 'derived(empty())'
:21:27: internal compiler error: in get_or_insert_ctor_field, at
cp/constexpr.c:3571
   21 | auto obj = derived{empty{}};
  |   ^
0x1d322a9 internal_error(char const*, ...)
???:0
0x71fc09 fancy_abort(char const*, int, char const*)
???:0
0xa58de0 store_init_value(tree_node*, tree_node*, vec**, int)
???:0
0x818a14 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
???:0
0x94812d c_parse_file()
???:0
0xacb002 c_common_parse_file()
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.
Compiler returned: 1
```

Works with GCC 10.3.

[Bug middle-end/67809] Empty pointer-chasing loops aren't optimized out

2021-06-12 Thread gareth--- via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67809

Gareth Lloyd  changed:

   What|Removed |Added

 CC||gar...@ignition-web.co.uk

--- Comment #11 from Gareth Lloyd  ---
Looks like as of GCC 10.1 this optimisation exists

This bug can be closed?

[Bug target/101041] New: z13: Inefficient handling of vector register passed to function

2021-06-12 Thread jens.seifert at de dot ibm.com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101041

Bug ID: 101041
   Summary: z13: Inefficient handling of vector register passed to
function
   Product: gcc
   Version: 8.3.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: jens.seifert at de dot ibm.com
  Target Milestone: ---

#include 
vector unsigned long long mul64(vector unsigned long long a, vector unsigned
long long b)
{
   return a * b;
}

creates:
_Z5mul64Dv2_yS_:
.LFB9:
.cfi_startproc
ldgr%f4,%r15
.cfi_register 15, 18
lay %r15,-192(%r15)
.cfi_def_cfa_offset 352
vst %v24,160(%r15),3
vst %v26,176(%r15),3
lg  %r2,160(%r15)
lg  %r1,176(%r15)
lgr %r4,%r2
lg  %r0,168(%r15)
lgr %r2,%r1
lg  %r1,184(%r15)
lgr %r5,%r0
lgr %r3,%r1
vlvgp   %v2,%r4,%r5
vlvgp   %v0,%r2,%r3
vlgvg   %r4,%v2,0
vlgvg   %r1,%v2,1
vlgvg   %r2,%v0,0
vlgvg   %r3,%v0,1
msgr%r2,%r4
msgr%r1,%r3
lgdr%r15,%f4
.cfi_restore 15
.cfi_def_cfa_offset 160
vlvgp   %v24,%r2,%r1
br  %r14

Store to stack of v24,v26, then lg+lgr for all 4 parts, then constructing new
vector register v0 and v2 and then extract the 4 elements again using vlgvg.

Expected 4 * vlgvg + 2 * msgr + vlvgp

[Bug c/101042] New: Bogus -Wstringop-overread with 11.1.0 and -O1 because of a call to printf _after_ assertions

2021-06-12 Thread ypsah+6a11ea7d-369c-4db1-b3f4-60ced987a559 at devyard dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101042

Bug ID: 101042
   Summary: Bogus -Wstringop-overread with 11.1.0 and -O1 because
of a call to printf _after_ assertions
   Product: gcc
   Version: 11.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ypsah+6a11ea7d-369c-4db1-b3f4-60ced987a559 at devyard dot 
org
  Target Milestone: ---

Created attachment 50989
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50989&action=edit
reproducer.c

Hi,

It looks like printf-ing a pointer after running assertions on it throws gcc 11
off:

#include 
#include 
#include 
#include 

enum field_type {
INTEGER,
STRING,
};

struct field {
enum field_type type;

union {
int integer;
const char *string;
};
};

int
main()
{
const struct field FIELD = {
.type = INTEGER,
.integer = 1,
};
struct field *field = calloc(1, sizeof(struct field));
assert(field);

assert(field->type == FIELD.type);
printf("field = %p\n", field);
switch (field->type) {
case STRING:
assert(strcmp(field->string, FIELD.string) == 0);
break;
default:
break;
}

free(field);
return 0;
}

$ gcc -Werror -O0 reproducer.c # <== Runs fine
$ gcc -Werror -O1 reproducer.c
In file included from reproducer.c:1:
reproducer.c: In function ‘main’:
reproducer.c:34:16: error: ‘strcmp’ reading 1 or more bytes from a region of
size 0 [-Werror=stringop-overread]
   34 | assert(strcmp(field->string, FIELD.string) == 0);
  |^~~
cc1: all warnings being treated as errors

Any optimization level above 0 yields the warning.

If you remove the printf() statement, or place it before one of the two
assert(), the warning goes away.
Downgrading to 10.2.0 also fixes the issue.

[Bug c++/101029] [10/11/12 regression] unexpected error: non-constant condition for static assertion in gcc 10/11, but not 9 (clang also fine)

2021-06-12 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101029

--- Comment #6 from CVS Commits  ---
The master branch has been updated by Jason Merrill :

https://gcc.gnu.org/g:08e1ff9d6e5a419d5b4a60c077df549e81601d9b

commit r12-1404-g08e1ff9d6e5a419d5b4a60c077df549e81601d9b
Author: Jason Merrill 
Date:   Fri Jun 11 16:55:30 2021 -0400

c++: constexpr and array[0] [PR101029]

build_vec_init_elt exits early if we're initializing a zero-element array,
so build_vec_init needs to do the same to avoid trying to instantiate
things
after we've already started throwing important bits away.

PR c++/101029

gcc/cp/ChangeLog:

* init.c (build_vec_init): Shortcut [0] case.

gcc/testsuite/ChangeLog:

* g++.dg/ext/array4.C: New test.

[Bug tree-optimization/101042] Bogus -Wstringop-overread with 11.1.0 and -O1 because of a call to printf _after_ assertions

2021-06-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101042

Andrew Pinski  changed:

   What|Removed |Added

  Component|c   |tree-optimization

--- Comment #1 from Andrew Pinski  ---
The probelm is GCC does not know that printf cannot change field->type.

[Bug c/39985] Type qualifiers not actually ignored on function return type

2021-06-12 Thread muecker at gwdg dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39985

Martin Uecker  changed:

   What|Removed |Added

 CC||muecker at gwdg dot de

--- Comment #10 from Martin Uecker  ---

It seems this is fixed in 11.1:

https://gcc.godbolt.org/z/nMqz8sG1v

[Bug c++/101043] New: ICE in check_noexcept_r for lambda conditional noexcept via requires expression

2021-06-12 Thread jbassett271 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101043

Bug ID: 101043
   Summary: ICE in check_noexcept_r for lambda conditional
noexcept via requires expression
   Product: gcc
   Version: 10.3.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: jbassett271 at gmail dot com
  Target Milestone: ---

GCC has an internal compiler error for requires expressions inside the noexcept
clause of a lambda inside a templated function:

https://godbolt.org/z/oWhq9sf8M


template 
struct set {
  bool contains(T const&) const { return true; }
};

template 
void intersect(set const& lhs, set const& rhs) {
  auto f = [&](T1&& _1) noexcept(requires {
{ rhs.contains(_1) } noexcept;
  }) {
  return rhs.contains(_1);
  };
}

int main() {
  set lhs;
  set rhs;
  intersect(lhs, rhs);
}


Error message:

: In instantiation of 'void intersect(const set&, const set&)
[with T = int]':
:18:21:   required from here
:9:7: internal compiler error: in check_noexcept_r, at cp/except.c:1123
9 | { rhs.contains(_1) } noexcept;
  | ~~^~~
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.


The commandline arguments, according to the Compiler Explorer link (cleaned a
little):

-g -o output.s -masm=intel -S -fdiagnostics-color=always -std=c++20 example.cpp

Clang compiles this fine.

I was able to replicate this bug in GCC versions 10.1, 10.2, 10.3, and 11.1.

[Bug fortran/100683] Array initialization refuses valid

2021-06-12 Thread jrfsousa at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100683

--- Comment #5 from José Rui Faustino de Sousa  ---
I am having trouble reproducing this.

Can you provide some more detail on your setup?

Best regards,
José Rui

[Bug rtl-optimization/101044] New: -ABS(A) produces two neg instructions

2021-06-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101044

Bug ID: 101044
   Summary: -ABS(A) produces two neg instructions
   Product: gcc
   Version: 12.0
Status: UNCONFIRMED
  Keywords: missed-optimization
  Severity: normal
  Priority: P3
 Component: rtl-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---
Target: x86_64-linux-gnu

Take:
int f4(int A)
{
  return A <= 0? A : -A;
}
int f5(int A)
{
return A < 0?  A : -A;
}
int f2(int A)
{
  A = A < 0 ? -A : A;
  return -A;
}
 CUT ---
On x86_64 we get two neg for each of these functions now, we used to get none
sometime ago.
Right now we get for each of them:
movl%edi, %eax
negl%eax
cmovs   %edi, %eax
negl%eax
- CUT ---
Note aarch64 seems to be fine:
cmp w0, 0
csneg   w0, w0, w0, lt