Bug 97520 - ICE in calc_stmt, at gimple-range.cc:399 with "-O1 -fno-tree-fre -ftree-vrp"
Summary: ICE in calc_stmt, at gimple-range.cc:399 with "-O1 -fno-tree-fre -ftree-vrp"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 11.0
: P1 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-10-21 15:23 UTC by suochenyao@163.com
Modified: 2020-10-30 15:27 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.2.0
Known to fail: 11.0
Last reconfirmed: 2020-10-21 00:00:00


Attachments
handle a_2 = &a (600 bytes, patch)
2020-10-21 18:26 UTC, Andrew Macleod
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description suochenyao@163.com 2020-10-21 15:23:43 UTC
*******************************************************************************
OS and Platform:
CentOS Linux release 7.8.2003 (Core), x86_64 GNU/Linux
*******************************************************************************
Program:
char a;
void b() {
  char *c[5];
  char *d = &a;
  &d;
  *(c[4] = d);
}
int main() { return 0; }
*******************************************************************************
gcc version:
$ gcc -v
Using built-in specs.
COLLECT_GCC=/home/suocy/bin/gcc-dev/bin/gcc
COLLECT_LTO_WRAPPER=/home/suocy/bin/gcc-dev/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/home/suocy/bin/gcc-dev --disable-multilib --enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20201020 (experimental) (GCC)
*******************************************************************************
Command Lines:
$ gcc -Wall -Wextra -fno-strict-aliasing -fwrapv -O1 -fno-tree-fre -ftree-vrp a.c
a.c: In function ‘b’:
a.c:5:3: warning: statement with no effect [-Wunused-value]
    5 |   &d;
      |   ^~
a.c:6:3: warning: value computed is not used [-Wunused-value]
    6 |   *(c[4] = d);
      |   ^~~~~~~~~~~
during GIMPLE pass: evrp
a.c:8:1: internal compiler error: in calc_stmt, at gimple-range.cc:399
    8 | int main() { return 0; }
      | ^~~
0x7f6095 gimple_ranger::calc_stmt(irange&, gimple*, tree_node*)
        ../../gcc/gimple-range.cc:399
0x188dc5f gimple_ranger::range_of_stmt(irange&, gimple*, tree_node*)
        ../../gcc/gimple-range.cc:992
0x188a498 gimple_ranger::range_of_expr(irange&, tree_node*, gimple*)
        ../../gcc/gimple-range.cc:883
0x10a236d range_query::value_of_expr(tree_node*, gimple*)
        ../../gcc/value-query.cc:85
0x172bc71 hybrid_folder::value_of_expr(tree_node*, gimple*)
        ../../gcc/gimple-ssa-evrp.c:235
0xf5c73e substitute_and_fold_dom_walker::before_dom_children(basic_block_def*)
        ../../gcc/tree-ssa-propagate.c:1112
0x1703777 dom_walker::walk(basic_block_def*)
        ../../gcc/domwalk.c:309
0xf5b955 substitute_and_fold_engine::substitute_and_fold(basic_block_def*)
        ../../gcc/tree-ssa-propagate.c:1283
0x172b8e6 execute_early_vrp
        ../../gcc/gimple-ssa-evrp.c:349
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 1 Andrew Macleod 2020-10-21 18:26:24 UTC
Created attachment 49416 [details]
handle a_2 = &a

We handle more complex memory processing like &(x_2 +1), but the very simple
  a_2 = &a_1
was slipping thru and we were creating the range based on a_1, not &a_1.
Typically we never saw that since earlier passes were propagating this.  turning off FRE exposed this situatuion.

This patch should correct that... verifying now.
Comment 2 Martin Liška 2020-10-21 18:34:55 UTC
Just for the record, started with r11-4080-g6e02de946125c368.
Comment 3 GCC Commits 2020-10-22 00:16:54 UTC
The master branch has been updated by Andrew Macleod <amacleod@gcc.gnu.org>:

https://gcc.gnu.org/g:966fdb2e12c0347aa3f9efaf5f4e1cd8237fa024

commit r11-4200-g966fdb2e12c0347aa3f9efaf5f4e1cd8237fa024
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Wed Oct 21 20:11:16 2020 -0400

    Handle a_2= &b properly in range calculations.
    
    when processing assignments, we were using the type of b instead of type
    of &b when computing a range.  This was usually filtered out by FRE.
    turning it off exposed it.
    
            gcc/
            PR tree-optimization/97520
            * gimple-range.cc (range_of_non_trivial_assignment): Handle x = &a
            by returning a non-zero range.
            gcc/testsuite/
            * gcc.dg/pr97520.c: New.
Comment 4 Richard Biener 2020-10-22 07:03:27 UTC
Fixed.
Comment 5 suochenyao@163.com 2020-10-30 15:25:05 UTC
*******************************************************************************
I think this can be reproduced with "-fno-strict-aliasing"...
I am not sure whether it can be helpful...
*******************************************************************************
OS and Platform:
CentOS Linux release 7.8.2003 (Core), x86_64 GNU/Linux
*******************************************************************************
Program:
int printf(const char *, ...);
union {
  long a;
  int b;
} c;
int d=0;
long e=0;
long *f = &c.a;
short g=0;
int *h = &c.b;
short i(int j) {
  g = *h;
  *f = 3;
  for (;; e--) {
    if (*h)
      return d;
    *h = j;
  }
  return 0;
}
int main() {
  i(1);
  printf("%d\n", (int)e);
  return 0;
}
*******************************************************************************
gcc version:
$ gcc -v
Using built-in specs.
COLLECT_GCC=/home/suocy/bin/gcc-dev/bin/gcc
COLLECT_LTO_WRAPPER=/home/suocy/bin/gcc-dev/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/home/suocy/bin/gcc-dev/ --disable-multilib --enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20201029 (experimental) (GCC)
*******************************************************************************
Command Lines:
$ gcc a.c -o a.o1
$ gcc -Wall -Wextra -fno-strict-aliasing -fwrapv -Og -fgcse -fstrict-aliasing a.c -o a.o2
$ gcc -Og -fgcse -fstrict-aliasing a.c -o a.o3
$ ./a.o1
0
$ ./a.o2
-1
$ ./a.o3
-1
Comment 6 suochenyao@163.com 2020-10-30 15:27:18 UTC
(In reply to suochenyao@163.com from comment #5)
> *****************************************************************************
> **
> I think this can be reproduced with "-fno-strict-aliasing"...
> I am not sure whether it can be helpful...
> *****************************************************************************
> **
> OS and Platform:
> CentOS Linux release 7.8.2003 (Core), x86_64 GNU/Linux
> *****************************************************************************
> **
> Program:
> int printf(const char *, ...);
> union {
>   long a;
>   int b;
> } c;
> int d=0;
> long e=0;
> long *f = &c.a;
> short g=0;
> int *h = &c.b;
> short i(int j) {
>   g = *h;
>   *f = 3;
>   for (;; e--) {
>     if (*h)
>       return d;
>     *h = j;
>   }
>   return 0;
> }
> int main() {
>   i(1);
>   printf("%d\n", (int)e);
>   return 0;
> }
> *****************************************************************************
> **
> gcc version:
> $ gcc -v
> Using built-in specs.
> COLLECT_GCC=/home/suocy/bin/gcc-dev/bin/gcc
> COLLECT_LTO_WRAPPER=/home/suocy/bin/gcc-dev/libexec/gcc/x86_64-pc-linux-gnu/
> 11.0.0/lto-wrapper
> Target: x86_64-pc-linux-gnu
> Configured with: ../configure --prefix=/home/suocy/bin/gcc-dev/
> --disable-multilib --enable-languages=c,c++
> Thread model: posix
> Supported LTO compression algorithms: zlib
> gcc version 11.0.0 20201029 (experimental) (GCC)
> *****************************************************************************
> **
> Command Lines:
> $ gcc a.c -o a.o1
> $ gcc -Wall -Wextra -fno-strict-aliasing -fwrapv -Og -fgcse
> -fstrict-aliasing a.c -o a.o2
> $ gcc -Og -fgcse -fstrict-aliasing a.c -o a.o3
> $ ./a.o1
> 0
> $ ./a.o2
> -1
> $ ./a.o3
> -1

Sorry, comment to the wrong place...