On Tue, 22 Jun 2021, Jakub Jelinek wrote: > Hi! > > Andrew's recent r12-1608-g2f1686ff70b25fceb04ca2ffc0a450fb682913ef change > to fail verification on various unary and binary operations with OFFSET_TYPE > revealed that e.g. switchconf happily performs multiplications and additions > in OFFSET_TYPE. > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for > trunk?
OK. > 2021-06-22 Jakub Jelinek <ja...@redhat.com> > Andrew Pinski <apin...@marvell.com> > > PR tree-optimization/101162 > * fold-const.c (range_check_type): Handle OFFSET_TYPE like pointer > types. > > * g++.dg/opt/pr101162.C: New test. > > --- gcc/fold-const.c.jj 2021-06-14 12:27:18.572411152 +0200 > +++ gcc/fold-const.c 2021-06-22 11:06:49.718462451 +0200 > @@ -5360,7 +5360,7 @@ range_check_type (tree etype) > else > return NULL_TREE; > } > - else if (POINTER_TYPE_P (etype)) > + else if (POINTER_TYPE_P (etype) || TREE_CODE (etype) == OFFSET_TYPE) > etype = unsigned_type_for (etype); > return etype; > } > --- gcc/testsuite/g++.dg/opt/pr101162.C.jj 2021-06-22 11:08:11.754359910 > +0200 > +++ gcc/testsuite/g++.dg/opt/pr101162.C 2021-06-22 11:07:54.318594243 > +0200 > @@ -0,0 +1,21 @@ > +// PR tree-optimization/101162 > +// { dg-do compile } > +// { dg-options "-O2" } > + > +struct A { int i1, i2, i3, i4, i5, i6; }; > + > +int A::* > +foo (int i) > +{ > + switch (i) > + { > + case 1: return &A::i1; > + case 2: return &A::i2; > + case 3: return &A::i3; > + case 4: return &A::i4; > + case 5: return &A::i5; > + case 6: return &A::i6; > + } > + > + return 0; > +} > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)