From patchwork Wed Oct 27 16:56:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1547014 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HfZdf5Jfgz9sX3 for ; Thu, 28 Oct 2021 03:58:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 051073858404 for ; Wed, 27 Oct 2021 16:58:28 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 42D05385842B for ; Wed, 27 Oct 2021 16:56:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 42D05385842B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: Okv0RbVgJ9Hz9Fz5MiMjLAbA2Yo0mCywx5hWhVVfcwKLyWGxxAWXfYhwGGZgKXAex4kKGIcsjN 0agrZ4sFaj53JaLOlk/iW+7IlhgzpX0sRf0Q3TRxA0Bf077+1yvUsgkEwwIls8O/sieEzXp0AA xyRg6SSKlcbTEXP+0Td1ee7vBtLoZudv2zn84nB8I22nrcbBWSYfrmLe8zKWD+wOIxky0quamD 4j2kb7JWycFc69AVDd1gWTCH8IhlP231LRZgV/CwVrQvdn+i1M5NXuCdHaivhV6cDTKeYkeI17 6OYi9rk0GflLNAxlZxEuPIpC X-IronPort-AV: E=Sophos;i="5.87,187,1631606400"; d="scan'208";a="67705693" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 27 Oct 2021 08:56:40 -0800 IronPort-SDR: L8ZVXPwBx0ltJUjmuvkzbw7WFOJ68J7rNM4bH0TDMKQXFAdScWQS8C0u6buTMgQRrHm2MqgsuN GWiCPiGS9nY7GdeZEVrYkqCRhD4zzcIQrNuSk3RtGI70Ud2xcp3FDGoih18I2t+CgVB9FeVLOF 97bYCsnLPDweADBQSKUQKaW7SZ2kFRztnxCQnnV+CCLtyooyeVyAXriEDJaypyJX/PY1gXlze9 M4NEoEeO3XrnmbOx5YEDBNrQJO6X+F+FMPKh90hoKe3LKnMgvqWE4rH4pq70POpADaEk0mqzxL yss= Date: Wed, 27 Oct 2021 16:56:34 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: Disable -Waggressive-loop-optimizations warnings in tst-dynarray.c Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-05.mgc.mentorg.com (139.181.222.5) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3123.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" My build-many-glibcs.py bot shows -Waggressive-loop-optimizations errors building the glibc testsuite for 32-bit architectures with GCC mainline, which seem to have appeared between GCC commits 4abc0c196b10251dc80d0743ba9e8ab3e56c61ed and d8edfadfc7a9795b65177a50ce44fd348858e844: In function 'dynarray_long_noscratch_resize', inlined from 'test_long_overflow' at tst-dynarray.c:489:5, inlined from 'do_test' at tst-dynarray.c:571:3: ../malloc/dynarray-skeleton.c:391:36: error: iteration 1073741823 invokes undefined behavior [-Werror=aggressive-loop-optimizations] 391 | DYNARRAY_ELEMENT_INIT (&list->u.dynarray_header.array[i]); tst-dynarray.c:39:37: note: in definition of macro 'DYNARRAY_ELEMENT_INIT' 39 | #define DYNARRAY_ELEMENT_INIT(e) (*(e) = 23) | ^ In file included from tst-dynarray.c:42: ../malloc/dynarray-skeleton.c:389:37: note: within this loop 389 | for (size_t i = old_size; i < size; ++i) | ~~^~~~~~ In function 'dynarray_long_resize', inlined from 'test_long_overflow' at tst-dynarray.c:479:5, inlined from 'do_test' at tst-dynarray.c:571:3: ../malloc/dynarray-skeleton.c:391:36: error: iteration 1073741823 invokes undefined behavior [-Werror=aggressive-loop-optimizations] 391 | DYNARRAY_ELEMENT_INIT (&list->u.dynarray_header.array[i]); tst-dynarray.c:27:37: note: in definition of macro 'DYNARRAY_ELEMENT_INIT' 27 | #define DYNARRAY_ELEMENT_INIT(e) (*(e) = 17) | ^ In file included from tst-dynarray.c:28: ../malloc/dynarray-skeleton.c:389:37: note: within this loop 389 | for (size_t i = old_size; i < size; ++i) | ~~^~~~~~ I don't know what GCC change made these errors appear, or why they only appear for 32-bit architectures. However, the warnings appear to be both true (that iteration would indeed involve undefined behavior if executed) and useless in this particular case (that iteration is never executed, because the allocation size overflows and so the allocation fails - but the check for allocation size overflow is in a separate source file and so can't be seen by the compiler when compiling this test). So use the DIAG_* macros to disable -Waggressive-loop-optimizations around the calls in question to dynarray_long_resize and dynarray_long_noscratch_resize in this test. Tested with build-many-glibcs.py (GCC mainline) for arm-linux-gnueabi, where it restores a clean testsuite build. diff --git a/malloc/tst-dynarray.c b/malloc/tst-dynarray.c index c33505711f..955fab696c 100644 --- a/malloc/tst-dynarray.c +++ b/malloc/tst-dynarray.c @@ -20,6 +20,7 @@ #include #include +#include #define DYNARRAY_STRUCT dynarray_long #define DYNARRAY_ELEMENT long @@ -476,8 +477,15 @@ test_long_overflow (void) struct dynarray_long dyn; dynarray_long_init (&dyn); errno = EINVAL; + DIAG_PUSH_NEEDS_COMMENT; + /* GCC 12 (on 32-bit platforms) warns that after inlining, a loop + iteration would invoke undefined behavior. That loop iteration + can never be executed because an allocation of this size must + fail. */ + DIAG_IGNORE_NEEDS_COMMENT (12, "-Waggressive-loop-optimizations"); TEST_VERIFY (!dynarray_long_resize (&dyn, (SIZE_MAX / sizeof (long)) + 1)); + DIAG_POP_NEEDS_COMMENT; TEST_VERIFY (errno == ENOMEM); TEST_VERIFY (dynarray_long_has_failed (&dyn)); } @@ -486,8 +494,15 @@ test_long_overflow (void) struct dynarray_long_noscratch dyn; dynarray_long_noscratch_init (&dyn); errno = EINVAL; + DIAG_PUSH_NEEDS_COMMENT; + /* GCC 12 (on 32-bit platforms) warns that after inlining, a loop + iteration would invoke undefined behavior. That loop iteration + can never be executed because an allocation of this size must + fail. */ + DIAG_IGNORE_NEEDS_COMMENT (12, "-Waggressive-loop-optimizations"); TEST_VERIFY (!dynarray_long_noscratch_resize (&dyn, (SIZE_MAX / sizeof (long)) + 1)); + DIAG_POP_NEEDS_COMMENT; TEST_VERIFY (errno == ENOMEM); TEST_VERIFY (dynarray_long_noscratch_has_failed (&dyn)); }