From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E337E38708D8; Thu, 14 May 2020 19:19:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E337E38708D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589483954; bh=whQeV9wJWofZpprkeqqd4riDRJHr/T41/3LRLA7xv1o=; h=From:To:Subject:Date:From; b=EcE/e9yrfchbTjlyHs5H54dijN/Obn7vnuZSu197UzSo/rZr3zileWQnpY5S6r6E7 ptoS3nS9q4/Yew8A3YNHJcxRMDlmqiXKniMYHFOv2zmUD/Y85aGieZv4dXBtTKMnZm 3jaLkKkmAKFrVNyq6XvH8HeAMfmc+Y0vPezBKMhY= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/95140] New: [10/11 Regression] bogus -Wstringop-overflow for a loop unrolled past the end of a trailing array Date: Thu, 14 May 2020 19:19:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 May 2020 19:19:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95140 Bug ID: 95140 Summary: [10/11 Regression] bogus -Wstringop-overflow for a loop unrolled past the end of a trailing array Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- As reported in https://bugzilla.redhat.com/show_bug.cgi?id=3D1835906, compi= ling loops that copy a variable number of elements to a trailing character array member results in many spurious instances of -Wstringop-overflow (below). The reporter expects "No warnings about an overflow, and little or no code = to handle c > 8, as that would be undefined behaviour" and adds "It would be n= ice if GCC still warned if a function like f was called with a value of c that = was a compile time constant > 8 however." $ cat rhbz1835906.c && gcc -O3 -S -Wall -fdump-tree-strlen=3D/dev/stdout rhbz1835906.c struct A { char v[8]; }; void f (struct A *p, char * s, int c) { for (int i =3D 0; i < c; ++i) p->v[i] =3D s[i]; } ;; Function f (f, funcdef_no=3D0, decl_uid=3D1934, cgraph_uid=3D1, symbol_o= rder=3D0) Created preheader block for loop 2 Created preheader block for loop 1 ;; 4 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 3 4 28 5 30 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22= 27 23 29 24 25 26 ;; ;; Loop 2 ;; header 23, latch 29 ;; depth 1, outer 0 ;; nodes: 23 29 ;; ;; Loop 1 ;; header 5, latch 30 ;; depth 1, outer 0 ;; nodes: 5 30 ;; 2 succs { 3 26 } ;; 3 succs { 14 4 } ;; 4 succs { 28 6 } ;; 28 succs { 5 } ;; 5 succs { 30 6 } ;; 30 succs { 5 } ;; 6 succs { 7 24 } ;; 7 succs { 8 24 } ;; 8 succs { 9 24 } ;; 9 succs { 10 24 } ;; 10 succs { 11 24 } ;; 11 succs { 12 24 } ;; 12 succs { 13 24 } ;; 13 succs { 24 } ;; 14 succs { 15 25 } ;; 15 succs { 16 25 } ;; 16 succs { 17 25 } ;; 17 succs { 18 25 } ;; 18 succs { 19 25 } ;; 19 succs { 20 25 } ;; 20 succs { 21 25 } ;; 21 succs { 22 25 } ;; 22 succs { 27 25 } ;; 27 succs { 23 } ;; 23 succs { 29 25 } ;; 29 succs { 23 } ;; 24 succs { 25 } ;; 25 succs { 26 } ;; 26 succs { 1 } rhbz1835906.c: In function =E2=80=98f=E2=80=99: rhbz1835906.c:9:13: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 9 | p->v[i] =3D s[i]; | ~~~~~~~~^~~~~~ rhbz1835906.c:3:8: note: at offset [8, 2147483640] to object =E2=80=98v=E2= =80=99 with size 8 declared here 3 | char v[8]; | ^ rhbz1835906.c:9:13: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 9 | p->v[i] =3D s[i]; | ~~~~~~~~^~~~~~ rhbz1835906.c:3:8: note: at offset [9, 2147483641] to object =E2=80=98v=E2= =80=99 with size 8 declared here 3 | char v[8]; | ^ rhbz1835906.c:9:13: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 9 | p->v[i] =3D s[i]; | ~~~~~~~~^~~~~~ rhbz1835906.c:3:8: note: at offset [10, 2147483642] to object =E2=80=98v=E2= =80=99 with size 8 declared here 3 | char v[8]; | ^ rhbz1835906.c:9:13: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 9 | p->v[i] =3D s[i]; | ~~~~~~~~^~~~~~ rhbz1835906.c:3:8: note: at offset [11, 2147483643] to object =E2=80=98v=E2= =80=99 with size 8 declared here 3 | char v[8]; | ^ rhbz1835906.c:9:13: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 9 | p->v[i] =3D s[i]; | ~~~~~~~~^~~~~~ rhbz1835906.c:3:8: note: at offset [12, 2147483644] to object =E2=80=98v=E2= =80=99 with size 8 declared here 3 | char v[8]; | ^ rhbz1835906.c:9:13: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 9 | p->v[i] =3D s[i]; | ~~~~~~~~^~~~~~ rhbz1835906.c:3:8: note: at offset [13, 2147483645] to object =E2=80=98v=E2= =80=99 with size 8 declared here 3 | char v[8]; | ^ rhbz1835906.c:9:13: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 9 | p->v[i] =3D s[i]; | ~~~~~~~~^~~~~~ rhbz1835906.c:3:8: note: at offset [14, 2147483646] to object =E2=80=98v=E2= =80=99 with size 8 declared here 3 | char v[8]; | ^ rhbz1835906.c:9:13: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 9 | p->v[i] =3D s[i]; | ~~~~~~~~^~~~~~ rhbz1835906.c:3:8: note: at offset 8 to object =E2=80=98v=E2=80=99 with siz= e 8 declared here 3 | char v[8]; | ^ f (struct A * p, char * s, int c) { unsigned long ivtmp.24; sizetype ivtmp.15; vector(8) char * vectp_p.12; vector(8) char * vectp_p.11; vector(8) char vect__3.10; vector(8) char * vectp_s.9; vector(8) char * vectp_s.8; int tmp.7; unsigned int niters_vector_mult_vf.6; unsigned int bnd.5; unsigned int niters.4; int i; unsigned int _4; unsigned int _5; char _11; ssizetype _12; char * _13; _Bool _17; sizetype _19; _Bool _20; _Bool _21; char _26; sizetype _33; char * _34; char _35; char _54; char * _60; char _61; char * _67; char _68; char * _74; char _75; char * _81; char _82; char * _88; char _89; char * _95; char _96; char * _102; char _103; sizetype _108; char * _109; char _110; sizetype _115; char * _116; char _117; sizetype _122; char * _123; char _124; sizetype _129; char * _130; char _131; sizetype _136; char * _137; char _138; sizetype _143; char * _144; char _145; unsigned int _159; unsigned int _160; [local count: 118111600]: if (c_7(D) > 0) goto ; [89.00%] else goto ; [11.00%] [local count: 105119324]: _5 =3D (unsigned int) c_7(D); _4 =3D _5 + 4294967295; _17 =3D _4 > 6; _13 =3D s_8(D) + 1; _12 =3D p_9(D) - _13; _19 =3D (sizetype) _12; _20 =3D _19 > 6; _21 =3D _20 & _17; if (_21 !=3D 0) goto ; [80.00%] else goto ; [20.00%] [local count: 84095460]: bnd.5_39 =3D _5 >> 3; vect__3.10_152 =3D MEM [(char *)s_8(D)]; MEM [(char *)p_9(D)] =3D vect__3.10_152; vectp_s.8_154 =3D s_8(D) + 8; vectp_p.11_155 =3D p_9(D) + 8; if (bnd.5_39 > 1) goto ; [83.33%] else goto ; [16.67%] [local count: 70079550]: [local count: 70079549]: # ivtmp.24_148 =3D PHI <0(28), ivtmp.24_158(30)> vect__3.10_45 =3D MEM[base: s_8(D), index: ivtmp.24_148, step: 8, offset:= 8B]; MEM[base: p_9(D), index: ivtmp.24_148, step: 8, offset: 8B] =3D vect__3.1= 0_45; ivtmp.24_158 =3D ivtmp.24_148 + 1; _159 =3D (unsigned int) ivtmp.24_158; _160 =3D _159 + 1; if (_160 < bnd.5_39) goto ; [83.33%] else goto ; [16.67%] [local count: 58399624]: goto ; [100.00%] [local count: 84095460]: niters_vector_mult_vf.6_40 =3D bnd.5_39 << 3; tmp.7_41 =3D (int) niters_vector_mult_vf.6_40; if (_5 =3D=3D niters_vector_mult_vf.6_40) goto ; [12.50%] else goto ; [87.50%] [local count: 73583527]: _108 =3D (sizetype) tmp.7_41; _109 =3D s_8(D) + _108; _110 =3D *_109; p_9(D)->v[tmp.7_41] =3D _110; i_112 =3D tmp.7_41 + 1; if (c_7(D) > i_112) goto ; [89.00%] else goto ; [11.00%] [local count: 65489342]: _115 =3D (sizetype) i_112; _116 =3D s_8(D) + _115; _117 =3D *_116; p_9(D)->v[i_112] =3D _117; i_119 =3D i_112 + 1; if (c_7(D) > i_119) goto ; [89.00%] else goto ; [11.00%] [local count: 58285513]: _122 =3D (sizetype) i_119; _123 =3D s_8(D) + _122; _124 =3D *_123; p_9(D)->v[i_119] =3D _124; i_126 =3D i_119 + 1; if (c_7(D) > i_126) goto ; [89.00%] else goto ; [11.00%] [local count: 51874105]: _129 =3D (sizetype) i_126; _130 =3D s_8(D) + _129; _131 =3D *_130; p_9(D)->v[i_126] =3D _131; i_133 =3D i_126 + 1; if (c_7(D) > i_133) goto ; [89.00%] else goto ; [11.00%] [local count: 46167954]: _136 =3D (sizetype) i_133; _137 =3D s_8(D) + _136; _138 =3D *_137; p_9(D)->v[i_133] =3D _138; i_140 =3D i_133 + 1; if (c_7(D) > i_140) goto ; [89.00%] else goto ; [11.00%] [local count: 41089477]: _143 =3D (sizetype) i_140; _144 =3D s_8(D) + _143; _145 =3D *_144; p_9(D)->v[i_140] =3D _145; i_147 =3D i_140 + 1; if (c_7(D) > i_147) goto ; [89.00%] else goto ; [11.00%] [local count: 36569637]: _33 =3D (sizetype) i_147; _34 =3D s_8(D) + _33; _35 =3D *_34; p_9(D)->v[i_147] =3D _35; i_37 =3D i_147 + 1; goto ; [100.00%] [local count: 21023864]: _11 =3D *s_8(D); p_9(D)->v[0] =3D _11; if (c_7(D) > 1) goto ; [89.00%] else goto ; [11.00%] [local count: 18711240]: _54 =3D *_13; p_9(D)->v[1] =3D _54; if (c_7(D) > 2) goto ; [89.00%] else goto ; [11.00%] [local count: 16653003]: _60 =3D s_8(D) + 2; _61 =3D *_60; p_9(D)->v[2] =3D _61; if (c_7(D) > 3) goto ; [89.00%] else goto ; [11.00%] [local count: 14821173]: _67 =3D s_8(D) + 3; _68 =3D *_67; p_9(D)->v[3] =3D _68; if (c_7(D) > 4) goto ; [89.00%] else goto ; [11.00%] [local count: 13190844]: _74 =3D s_8(D) + 4; _75 =3D *_74; p_9(D)->v[4] =3D _75; if (c_7(D) > 5) goto ; [89.00%] else goto ; [11.00%] [local count: 11739850]: _81 =3D s_8(D) + 5; _82 =3D *_81; p_9(D)->v[5] =3D _82; if (c_7(D) > 6) goto ; [89.00%] else goto ; [11.00%] [local count: 10448467]: _88 =3D s_8(D) + 6; _89 =3D *_88; p_9(D)->v[6] =3D _89; if (c_7(D) > 7) goto ; [89.00%] else goto ; [11.00%] [local count: 9299136]: _95 =3D s_8(D) + 7; _96 =3D *_95; p_9(D)->v[7] =3D _96; if (c_7(D) > 8) goto ; [89.00%] else goto ; [11.00%] [local count: 8276231]: _102 =3D s_8(D) + 8; _103 =3D *_102; p_9(D)->v[8] =3D _103; if (c_7(D) > 9) goto ; [89.00%] else goto ; [11.00%] [local count: 7365846]: [local count: 7365845]: # ivtmp.15_151 =3D PHI <9(27), ivtmp.15_150(29)> _26 =3D MEM[base: s_8(D), index: ivtmp.15_151, offset: 0B]; MEM[base: p_9(D), index: ivtmp.15_151, offset: 0B] =3D _26; ivtmp.15_150 =3D ivtmp.15_151 + 1; i_149 =3D (int) ivtmp.15_150; if (c_7(D) > i_149) goto ; [89.00%] else goto ; [11.00%] [local count: 6555602]: goto ; [100.00%] [local count: 84095460]: [local count: 105119324]: [local count: 118111600]: return; }=