From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E39C43858C39 for ; Fri, 29 Oct 2021 09:04:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E39C43858C39 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-141-f__aEW9yO3OFdYHH9dQVGA-1; Fri, 29 Oct 2021 05:04:14 -0400 X-MC-Unique: f__aEW9yO3OFdYHH9dQVGA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFEC510168D3; Fri, 29 Oct 2021 09:04:12 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.194.250]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0DEA510016F4; Fri, 29 Oct 2021 09:04:11 +0000 (UTC) From: Florian Weimer To: Joseph Myers Cc: Subject: Re: Disable -Waggressive-loop-optimizations warnings in tst-dynarray.c References: Date: Fri, 29 Oct 2021 11:04:10 +0200 In-Reply-To: (Joseph Myers's message of "Wed, 27 Oct 2021 16:56:34 +0000") Message-ID: <87zgqsjj79.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: , X-List-Received-Date: Fri, 29 Oct 2021 09:04:20 -0000 * Joseph Myers: > 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. The glibc patch is okay, but I think this case is fairly common: A failed allocation ensuring that loops do not wrap around the address space. So this could hint to a defect in the GCC warning. Thanks, Florian