From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4B35C385702E; Wed, 23 Sep 2020 20:18:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B35C385702E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600892332; bh=d6UklM79hRQFvTIcCA20NIn7kVDOgyKgHwJTQSKAB2U=; h=From:To:Subject:Date:From; b=DiMpgyGfRjINCgGmy1AYb1x5au+/mixw8K7Si+naAOQcU27jTJ9DiH9s689BOXAgl Y738u5B29PZxoWGVA9LnXBZ+jFrHgGZuNlhFF1sgmGEGS7l7OuKtl4EZBUmdMcsqfg kypayNERT9lsTZrm6kRUl7WDQb3hlm6q3gy/BXoE= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/97185] New: inconsistent builtin elimination for impossible range Date: Wed, 23 Sep 2020 20:18:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 11.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: Wed, 23 Sep 2020 20:18:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97185 Bug ID: 97185 Summary: inconsistent builtin elimination for impossible range Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- In the test case below GCC eliminates the memcpy and memmove calls because = the only valid bound they are called with is zero. But the same optimization i= sn't done for the any of the remaining calls, including memset, resulting in warnings noting that the range is (most likely) invalid. GCC should be consistent and either eliminate all the calls (preferably), or none of them. $ cat z.c && gcc -O2 -S -fdump-tree-optimized=3D/dev/stdout z.c void f0 (void *p, const void *q, int n) {=20 if (n > 0) return; __builtin_memcpy (p, q, n); } void f1 (void *p, const void *q, int n) { if (n > 0) return; __builtin_memmove (p, q, n); } void f2 (char *p, const char *q, int n) { if (n > 0) return; __builtin_strncpy (p, q, n); } void f3 (void *p, int n) {=20 if (n > 0) return; __builtin_memset (p, 0, n); } void* f4 (const void *p, int n) { if (n > 0) return 0; return __builtin_memchr (p, 0, n); } int f5 (const void *p, const void *q, int n) { if (n > 0) return 0; return __builtin_memcmp (p, q, n); } ;; Function f0 (f0, funcdef_no=3D0, decl_uid=3D1933, cgraph_uid=3D1, symbol= _order=3D0) f0 (void * p, const void * q, int n) { [local count: 1073741824]: return; } ;; Function f1 (f1, funcdef_no=3D1, decl_uid=3D1938, cgraph_uid=3D2, symbol= _order=3D1) f1 (void * p, const void * q, int n) { [local count: 1073741824]: return; } ;; Function f2 (f2, funcdef_no=3D2, decl_uid=3D1943, cgraph_uid=3D3, symbol= _order=3D2) Removing basic block 5 f2 (char * p, const char * q, int n) { long unsigned int _1; [local count: 1073741824]: if (n_3(D) > 0) goto ; [60.08%] else goto ; [39.92%] [local count: 428637736]: _1 =3D (long unsigned int) n_3(D); __builtin_strncpy (p_5(D), q_6(D), _1); [tail call] [local count: 1073741824]: return; } z.c: In function =E2=80=98f2=E2=80=99: z.c:16:3: warning: =E2=80=98__builtin_strncpy=E2=80=99 specified size betwe= en 18446744071562067968 and 0 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=3D] 16 | __builtin_strncpy (p, q, n); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; Function f3 (f3, funcdef_no=3D3, decl_uid=3D1947, cgraph_uid=3D4, symbol= _order=3D3) Removing basic block 5 f3 (void * p, int n) { long unsigned int _1; [local count: 1073741824]: if (n_3(D) > 0) goto ; [60.08%] else goto ; [39.92%] [local count: 428637736]: _1 =3D (long unsigned int) n_3(D); __builtin_memset (p_5(D), 0, _1); [tail call] [local count: 1073741824]: return; } z.c: In function =E2=80=98f3=E2=80=99: z.c:22:3: warning: =E2=80=98__builtin_memset=E2=80=99 specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=3D] 22 | __builtin_memset (p, 0, n); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ ;; Function f4 (f4, funcdef_no=3D4, decl_uid=3D1951, cgraph_uid=3D5, symbol= _order=3D4) Removing basic block 5 f4 (const void * p, int n) { long unsigned int _1; void * _2; void * _6; [local count: 1073741824]: if (n_3(D) > 0) goto ; [23.24%] else goto ; [76.76%] [local count: 824204225]: _1 =3D (long unsigned int) n_3(D); _6 =3D __builtin_memchr (p_5(D), 0, _1); [tail call] [local count: 1073741824]: # _2 =3D PHI <_6(3), 0B(2)> return _2; } z.c: In function =E2=80=98f4=E2=80=99: z.c:28:10: warning: =E2=80=98__builtin_memchr=E2=80=99 specified bound [184= 46744071562067968, 0] exceeds maximum object size 9223372036854775807 [-Wstringop-overread] 28 | return __builtin_memchr (p, 0, n); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ ;; Function f5 (f5, funcdef_no=3D5, decl_uid=3D1956, cgraph_uid=3D6, symbol= _order=3D5) Removing basic block 5 f5 (const void * p, const void * q, int n) { long unsigned int _1; int _2; int _7; [local count: 1073741824]: if (n_3(D) > 0) goto ; [42.57%] else goto ; [57.43%] [local count: 616649929]: _1 =3D (long unsigned int) n_3(D); _7 =3D __builtin_memcmp (p_5(D), q_6(D), _1); [tail call] [local count: 1073741824]: # _2 =3D PHI <_7(3), 0(2)> return _2; } z.c: In function =E2=80=98f5=E2=80=99: z.c:34:10: warning: =E2=80=98__builtin_memcmp=E2=80=99 specified bound [184= 46744071562067968, 0] exceeds maximum object size 9223372036854775807 [-Wstringop-overread] 34 | return __builtin_memcmp (p, q, n); | ^~~~~~~~~~~~~~~~~~~~~~~~~~=