From patchwork Wed Oct 2 16:53:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1170824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105583-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="A7sW8i+j"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46k2K65KXkz9sPh for ; Thu, 3 Oct 2019 02:53:46 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=BPFHPJduW4ih8b1f708lRQMMBZ1Aq ix9D8qLRssmhmgUt1uKp/OLrphTFdriyTnq7HHQyCzoRw71kbZLGhKmF6h7XSgV6 HdkcNzJoFKJrRuapw+9mrl6kx3oV6OE2ZwE4esE4k3Ys50g6LEXMMMoQJZdVIU22 6sk7jseGXhCFQI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=RTS5S8XMfH5ySyuT1sQtpEnxzf8=; b=A7s W8i+jmhd5Qj7kk3CJ6Dn0km/KpHkhnGPZ4FC0b7Xd6k5YBm+vv2WTGTPT2hQ8MO6 ZqoqoTd3QRAroax4/vjnRDoK+h1rANxImW0QtJURC321M00HEFRk8KNBp+5GbnTh OPc/OfnuWFVdzOHtOz9ty6It4hVARZ0KjleHOZwQ= Received: (qmail 129608 invoked by alias); 2 Oct 2019 16:53:40 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 129599 invoked by uid 89); 2 Oct 2019 16:53:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy=4997 X-HELO: esa3.mentor.iphmx.com IronPort-SDR: 8ZBeTIZgY7/6pEBmGcXlQgKnHruMA8t13k1nqtpg9egx2Ae8+svVn0Ge5ykCfkP1cg+s8FxOgo pzYuL+hWrA8HxnkVrA+0jAypoo5JPCGnTNGfwfiekH7UspKoJQq0NiEyhb/AmOvtpF6639Rvnm GsBl4SvyFR7eIjEx9Q0EmCi2HZJvh2G0GB2QsSyP6PLQCqW2SuR9iXlomWQClOSh3rizqgDmZg 0STZiEHTACy8PL/NNPf+XVETWMgZ13WZhzmfVYBZdM2mwLnEfwnviRYGTRWRHtb6LDS6TgxtxC bhs= IronPort-SDR: S4tOpyH9qPDEUiRwFRQ6ArsxqngF53T9e0pgl/ArfDYfeh9InqN4BY1XUkBua2VlUzucpqZv2n C3X5wF2bn/UfiIACQCCGhamOCn+ITdzycGcQzvvMzld6iK1V69G/cLH33FvvTZAZv9YF2R7Wn6 5GoDv5aCQhN3+U1Sl/4qBAIiKO8Q2JUxVbQLxBGj2FaoSe8P6nUPIJqKgsrC0w+8GDB8MImrXg AlUd7w4tq4kKh3JKAxtYAaMg0W5trVMHltWrlGzbytLFF9Inwgk48VryIC91mkKdiMhkGFZQ21 iCE= Date: Wed, 2 Oct 2019 16:53:31 +0000 From: Joseph Myers To: Subject: Disable warnings in string/tester.c at top level Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 string/tester.c contains code that correctly triggers various GCC warnings about dubious uses of string functions (uses that are being deliberately tested there), and duly disables those warnings around the relevant code. A change in GCC mainline resulted in this code failing to compile with a -Warray-bounds error, despite the location with the error having -Warray-bounds already disabled. This has been reported as . This patch avoids that problem and possible future issues with these diagnostics by moving all the warning disabling in this file to top level, as suggested by Florian in , rather than only doing it locally around specific function calls. Tested with build-many-glibcs.py for aarch64-linux-gnu with GCC mainline (with only the conform/ failures noted in ). 2019-10-02 Joseph Myers * string/tester.c: Ignore -Warray-bounds and -Wmemset-transposed-args at top level. [__GNUC_PREREQ (7, 0)]: Ignore -Wrestrict and -Wstringop-overflow= at top level. [__GNUC_PREREQ (8, 0)]: Ignore -Wstringop-truncation at top level. (test_stpncpy): Do not ignore warnings here. (test_strncat): Likewise. (test_strncpy): Likewise. (test_memset): Likewise. diff --git a/string/tester.c b/string/tester.c index 24b0dad1cb..128d2c7731 100644 --- a/string/tester.c +++ b/string/tester.c @@ -34,6 +34,20 @@ #include #include +/* This file tests a range of corner cases of string functions, + including cases where truncation occurs or where sizes specified + are larger than the actual buffers, which result in various + warnings. */ +DIAG_IGNORE_NEEDS_COMMENT (8, "-Warray-bounds"); +DIAG_IGNORE_NEEDS_COMMENT (5.0, "-Wmemset-transposed-args"); +#if __GNUC_PREREQ (7, 0) +DIAG_IGNORE_NEEDS_COMMENT (9, "-Wrestrict"); +DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); +#endif +#if __GNUC_PREREQ (8, 0) +DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); +#endif + #define STREQ(a, b) (strcmp((a), (b)) == 0) @@ -264,15 +278,8 @@ test_stpncpy (void) { it = "stpncpy"; memset (one, 'x', sizeof (one)); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (8, 0) - /* GCC 8 warns about stpncpy truncating output; this is deliberately - tested here. */ - DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); -#endif check (stpncpy (one, "abc", 2) == one + 2, 1); check (stpncpy (one, "abc", 3) == one + 3, 2); - DIAG_POP_NEEDS_COMMENT; check (stpncpy (one, "abc", 4) == one + 3, 3); check (one[3] == '\0' && one[4] == 'x', 4); check (stpncpy (one, "abcd", 5) == one + 4, 5); @@ -360,106 +367,41 @@ test_strncat (void) mechanism. */ it = "strncat"; (void) strcpy (one, "ijk"); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 7 warns about the size passed to strncat being larger than - the size of the buffer; this is deliberately tested here.. */ - DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); -#endif check (strncat (one, "lmn", 99) == one, 1); /* Returned value. */ - DIAG_POP_NEEDS_COMMENT; equal (one, "ijklmn", 2); /* Basic test. */ (void) strcpy (one, "x"); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 7 warns about the size passed to strncat being larger than - the size of the buffer; this is deliberately tested here.. */ - DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); -#endif (void) strncat (one, "yz", 99); - DIAG_POP_NEEDS_COMMENT; equal (one, "xyz", 3); /* Writeover. */ equal (one+4, "mn", 4); /* Wrote too much? */ (void) strcpy (one, "gh"); (void) strcpy (two, "ef"); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 7 warns about the size passed to strncat being larger than - the size of the buffer; this is deliberately tested here; GCC 8 - gives a -Warray-bounds warning about this. */ - DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); -#endif - DIAG_IGNORE_NEEDS_COMMENT (8, "-Warray-bounds"); (void) strncat (one, two, 99); - DIAG_POP_NEEDS_COMMENT; equal (one, "ghef", 5); /* Basic test encore. */ equal (two, "ef", 6); /* Stomped on source? */ (void) strcpy (one, ""); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 7 warns about the size passed to strncat being larger than - the size of the buffer; this is deliberately tested here.. */ - DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); -#endif (void) strncat (one, "", 99); - DIAG_POP_NEEDS_COMMENT; equal (one, "", 7); /* Boundary conditions. */ (void) strcpy (one, "ab"); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 7 warns about the size passed to strncat being larger than - the size of the buffer; this is deliberately tested here.. */ - DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); -#endif (void) strncat (one, "", 99); - DIAG_POP_NEEDS_COMMENT; equal (one, "ab", 8); (void) strcpy (one, ""); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 7 warns about the size passed to strncat being larger than - the size of the buffer; this is deliberately tested here.. */ - DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); -#endif (void) strncat (one, "cd", 99); - DIAG_POP_NEEDS_COMMENT; equal (one, "cd", 9); (void) strcpy (one, "ab"); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (8, 0) - /* GCC 8 warns about strncat truncating output; this is deliberately - tested here. */ - DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); -#endif (void) strncat (one, "cdef", 2); - DIAG_POP_NEEDS_COMMENT; equal (one, "abcd", 10); /* Count-limited. */ (void) strncat (one, "gh", 0); equal (one, "abcd", 11); /* Zero count. */ - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 8 warns about strncat bound equal to source length; this is - deliberately tested here. */ - DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-overflow="); -#endif (void) strncat (one, "gh", 2); - DIAG_POP_NEEDS_COMMENT; equal (one, "abcdgh", 12); /* Count and length equal. */ - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 7 warns about the size passed to strncat being larger than - the size of the buffer; this is deliberately tested here.. */ - DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); -#endif (void) strncat (one, "ij", (size_t)-1); /* set sign bit in count */ - DIAG_POP_NEEDS_COMMENT; equal (one, "abcdghij", 13); int ntest = 14; @@ -478,22 +420,8 @@ test_strncat (void) buf1[n2 + n3] = '\0'; strcpy (buf2 + n1, "123"); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (7, 0) - /* GCC 7 warns about the size passed to strncat being - larger than the size of the buffer; this is - deliberately tested here; GCC 8 gives a -Warray-bounds - warning about this. */ - DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow="); - /* GCC 9 as of 2018-06-14 warns that the size passed is - large enough that, if it were the actual object size, - the objects would have to overlap. */ - DIAG_IGNORE_NEEDS_COMMENT (9, "-Wrestrict"); -#endif - DIAG_IGNORE_NEEDS_COMMENT (8, "-Warray-bounds"); check (strncat (buf1 + n2, buf2 + n1, ~((size_t) 0) - n4) == buf1 + n2, ntest); - DIAG_POP_NEEDS_COMMENT; if (errors == olderrors) for (size_t i = 0; i < sizeof (buf1); ++i) { @@ -552,25 +480,11 @@ test_strncpy (void) equal (one, "abc", 2); /* Did the copy go right? */ (void) strcpy (one, "abcdefgh"); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (8, 0) - /* GCC 8 warns about strncpy truncating output; this is deliberately - tested here. */ - DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); -#endif (void) strncpy (one, "xyz", 2); - DIAG_POP_NEEDS_COMMENT; equal (one, "xycdefgh", 3); /* Copy cut by count. */ (void) strcpy (one, "abcdefgh"); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (8, 0) - /* GCC 8 warns about strncpy truncating output; this is deliberately - tested here. */ - DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); -#endif (void) strncpy (one, "xyz", 3); /* Copy cut just before NUL. */ - DIAG_POP_NEEDS_COMMENT; equal (one, "xyzdefgh", 4); (void) strcpy (one, "abcdefgh"); @@ -585,14 +499,7 @@ test_strncpy (void) equal (one+5, "fgh", 9); (void) strcpy (one, "abc"); - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (8, 0) - /* GCC 8 warns about strncpy truncating output; this is deliberately - tested here. */ - DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); -#endif (void) strncpy (one, "xyz", 0); /* Zero-length copy. */ - DIAG_POP_NEEDS_COMMENT; equal (one, "abc", 10); (void) strncpy (one, "", 2); /* Zero-length source. */ @@ -1411,15 +1318,8 @@ test_memset (void) check(memset(one+1, 'x', 3) == one+1, 1); /* Return value. */ equal(one, "axxxefgh", 2); /* Basic test. */ - DIAG_PUSH_NEEDS_COMMENT; -#if __GNUC_PREREQ (5, 0) - /* GCC 5.0 warns about a zero-length memset because the arguments to memset - may be in the wrong order. But we really want to test this. */ - DIAG_IGNORE_NEEDS_COMMENT (5.0, "-Wmemset-transposed-args") -#endif (void) memset(one+2, 'y', 0); equal(one, "axxxefgh", 3); /* Zero-length set. */ - DIAG_POP_NEEDS_COMMENT; (void) memset(one+5, 0, 1); equal(one, "axxxe", 4); /* Zero fill. */