From patchwork Tue Apr 16 03:22:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 88519 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 54F7A3858C53 for ; Tue, 16 Apr 2024 03:23:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 281523858D32 for ; Tue, 16 Apr 2024 03:23:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 281523858D32 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 281523858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::536 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713237794; cv=none; b=AGUzUGqIDHJXVdY5zpRG3Uk8mgrAafjRzfsQyLFRV1diQilNK8UhCFI87xA5joFLhmCA+RP5EtW9w9uyCoeoADWWz0o9FNrEV6bEGOzW0/DX4MlNSuSXyTfsmA0fxOl8jbSjCSi270Is/mWA4YR6OiXjOdj5t+h7VP0t9/czI3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713237794; c=relaxed/simple; bh=UL/EtePz1h5UM9hXH7rViMAX/VaFgF4tCXSiJgCxlgE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=h1PoEt53n9iVAoqj2Bf9h9OjWGXRqCdM922tQEeSfYa+nqF88k23Z1ppRXs6S5Ga1boF8ZtzAhfNnXy8KPcCKuju2y5om4FEjjOdsAsZWDKu2roQSyyxPpQG04+hgFfhdS7KiY1WrZGQWbFi7boUnV1FyoQAhlmNGMLuyVMkL+4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5dca1efad59so2664546a12.2 for ; Mon, 15 Apr 2024 20:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1713237788; x=1713842588; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=UCeRgff7H3WqvVUYNxtx71vB3g9uiCjLIsrVr/wmmEE=; b=QzVIgdLtMypTs7OLN+K4/azEVeJZqzpmOsY0bh93VHiwUJYEP8mqmT2C3ztS9BD/1c l9mHugyIme93QNloLJbiZFeqPxqvMnOcDczHGYz9oSOR8yI7nJpgCccQ7Ajt6Y5X77+v cPbxi3kQMfzXHMDnYBSAvfjQIC/oIqPDbo4+NPr3W/taIYeILUafUsaHOc+6fV1AkiRb LnckAqvNW8xvYnxFVtp1uj/uEtV7klfXoGvH4tZ8YAaSt9fHciE1vJXMxFut1R6jB0sg 3CL3uvu2V/T/6bbpb7G7lOLX8sFdPq9JAAcJ2XWAi3Cq5RGysnVPPP3Ss6O/C900PQQX t6AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713237788; x=1713842588; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UCeRgff7H3WqvVUYNxtx71vB3g9uiCjLIsrVr/wmmEE=; b=stCTa2GJe/1UfvZBM48dcFcD4pKOfHED/R1LrI7FuFXR+E9y3VMjEdFix1LELMQW6n YN2m7HuFe05CLMggiAARi7DLFT+t47/EAYmrXHr2IZN8HrEcnu77m5wVY9Xua82AW5m9 oq1dzsfMt4Rx8ZKNGKJDR11DV419ijAJVSMU1qCIgiEENngOp4cEB2D1Xl+z5v6O3u2F JJhHtZwFi1RfMJS6JPUZm8em+3Dw6ZiDuU4AQh6ilhxfbBez04yOPfqDGwJoT2NZdraM q7RVwywBjx9Ud2nKhOW40xrl3IhdG4SzV7ShOOSYC0GELu3sDfBpiMTg/jsogb53XHNB 5gOg== X-Gm-Message-State: AOJu0Yz6edCWsVUi7yffgOfs7x7UDR0nH6W1CZodXti2BM+c2JFPSRR6 HIuLi1C6AUK9X1dWqNJmhCNMrs6Uv1AdbVeJjhuEybDwy3Nqj8YyVUrxFe23Tfgg4zvhuF3x9j6 hYw== X-Google-Smtp-Source: AGHT+IEqfuZG6UAHNhc88s+5liyFnRIaTDvffZPpHs84JSnq+VfT1X2zI0tF986b9oad13rq6wQiJg== X-Received: by 2002:a17:90a:db01:b0:29b:ad3a:7b01 with SMTP id g1-20020a17090adb0100b0029bad3a7b01mr8701340pjv.46.1713237787817; Mon, 15 Apr 2024 20:23:07 -0700 (PDT) Received: from free.home ([2804:7f1:218b:5e2:c43b:e0c4:71a:241b]) by smtp.gmail.com with ESMTPSA id z2-20020a17090a6d0200b002a5290ad3d4sm8714544pjj.3.2024.04.15.20.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 20:23:07 -0700 (PDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 43G3MkEe2387283 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 16 Apr 2024 00:22:46 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: Rainer Orth , Mike Stump Subject: [PATCH] [testsuite] introduce strndup effective target Organization: Free thinker, does not speak for AdaCore Date: Tue, 16 Apr 2024 00:22:46 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org A number of tests that call strndup fail on vxworks, where there's no strndup. Some of them already had workarounds to skip the strndup parts of the tests on platforms that don't offer it. I've changed them to rely on a strndup effective target instead, and extended the logic to other tests that were otherwise skipped entirely. Regstrapped on x86_64-linux-gnu. Also tested with gcc-13 on arm-, aarch64-, x86- and x86_64-vxworks7r2. Ok to install? for gcc/ChangeLog * doc/sourcebuild.texi (strndup): Add effective target. for gcc/testsuite/ChangeLog * lib/target-supports.exp (check_effective_target_strndup): New. * gcc.dg/builtin-dynamic-object-size-0.c: Skip strndup tests when the function is not available. * gcc.dg/builtin-dynamic-object-size-1.c: Likewise. * gcc.dg/builtin-dynamic-object-size-2.c: Likewise. * gcc.dg/builtin-dynamic-object-size-3.c: Likewise. * gcc.dg/builtin-dynamic-object-size-4.c: Likewise. * gcc.dg/builtin-object-size-1.c: Likewise. * gcc.dg/builtin-object-size-2.c: Likewise. * gcc.dg/builtin-object-size-3.c: Likewise. * gcc.dg/builtin-object-size-4.c: Likewise. --- gcc/doc/sourcebuild.texi | 3 +++ .../gcc.dg/builtin-dynamic-object-size-0.c | 10 +++++++++- gcc/testsuite/gcc.dg/builtin-object-size-1.c | 7 ++++--- gcc/testsuite/gcc.dg/builtin-object-size-2.c | 7 ++++--- gcc/testsuite/gcc.dg/builtin-object-size-3.c | 7 ++++--- gcc/testsuite/gcc.dg/builtin-object-size-4.c | 7 ++++--- gcc/testsuite/lib/target-supports.exp | 11 +++++++++++ 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index 7c0df90e82236..8e4e59ac44c74 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -2837,6 +2837,9 @@ can be included without error when @option{-mbig-endian} is passed. @item stpcpy Target provides @code{stpcpy} function. +@item strndup +Target provides @code{strndup} function. + @item sysconf Target supports @code{sysconf}. diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c index 173e7c755f4c9..d02e37f79d95f 100644 --- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c +++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c @@ -1,7 +1,7 @@ /* { dg-do run } */ /* { dg-options "-O2" } */ /* { dg-require-effective-target size20plus } */ -/* { dg-skip-if "no strndup" { hppa*-*-hpux* } } */ +/* { dg-additional-options "-DSKIP_STRNDUP" { target { ! strndup } } } */ #include "builtin-object-size-common.h" @@ -567,6 +567,7 @@ test_strdup (const char *in) return sz; } +#ifndef SKIP_STRNDUP size_t __attribute__ ((noinline)) test_strndup (const char *in, size_t bound) @@ -577,6 +578,7 @@ test_strndup (const char *in, size_t bound) __builtin_free (res); return sz; } +#endif size_t __attribute__ ((noinline)) @@ -589,6 +591,7 @@ test_strdup_min (const char *in) return sz; } +#ifndef SKIP_STRNDUP size_t __attribute__ ((noinline)) test_strndup_min (const char *in, size_t bound) @@ -599,6 +602,7 @@ test_strndup_min (const char *in, size_t bound) __builtin_free (res); return sz; } +#endif /* Other tests. */ @@ -788,12 +792,16 @@ main (int argc, char **argv) const char *str = "hello world"; if (test_strdup (str) != __builtin_strlen (str) + 1) FAIL (); +#ifndef SKIP_STRNDUP if (test_strndup (str, 4) != 5) FAIL (); +#endif if (test_strdup_min (str) != __builtin_strlen (str) + 1) FAIL (); +#ifndef SKIP_STRNDUP if (test_strndup_min (str, 4) != 1) FAIL (); +#endif DONE (); } diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-1.c b/gcc/testsuite/gcc.dg/builtin-object-size-1.c index 4f7d4c0b370f5..d6d13c5ef7a29 100644 --- a/gcc/testsuite/gcc.dg/builtin-object-size-1.c +++ b/gcc/testsuite/gcc.dg/builtin-object-size-1.c @@ -1,6 +1,7 @@ /* { dg-do run } */ /* { dg-options "-O2 -Wno-stringop-overread" } */ /* { dg-require-effective-target alloca } */ +/* { dg-additional-options "-DSKIP_STRNDUP" { target { ! strndup } } } */ #include "builtin-object-size-common.h" @@ -621,7 +622,7 @@ test10 (void) } } -#if !defined(__AVR__) && !defined(__hpux__) /* avr and hpux have no strndup */ +#ifndef SKIP_STRNDUP /* Tests for strdup/strndup. */ size_t __attribute__ ((noinline)) @@ -709,7 +710,7 @@ test11 (void) FAIL (); free (res); } -#endif /* avr */ +#endif int main (void) @@ -726,7 +727,7 @@ main (void) test8 (); test9 (1); test10 (); -#if !defined(__AVR__) && !defined(__hpux__) /* avr and hpux have no strndup */ +#ifndef SKIP_STRNDUP test11 (); #endif DONE (); diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-2.c b/gcc/testsuite/gcc.dg/builtin-object-size-2.c index 37d3dcc6f5689..c28d72eee9bfe 100644 --- a/gcc/testsuite/gcc.dg/builtin-object-size-2.c +++ b/gcc/testsuite/gcc.dg/builtin-object-size-2.c @@ -1,6 +1,7 @@ /* { dg-do run } */ /* { dg-options "-O2 -Wno-stringop-overread" } */ /* { dg-require-effective-target alloca } */ +/* { dg-additional-options "-DSKIP_STRNDUP" { target { ! strndup } } } */ #include "builtin-object-size-common.h" @@ -536,7 +537,7 @@ test8 (unsigned cond) #endif } -#if !defined(__AVR__) && !defined(__hpux__) /* avr and hpux have no strndup */ +#ifndef SKIP_STRNDUP /* Tests for strdup/strndup. */ size_t __attribute__ ((noinline)) @@ -624,7 +625,7 @@ test9 (void) FAIL (); free (res); } -#endif /* avr */ +#endif int main (void) @@ -639,7 +640,7 @@ main (void) test6 (); test7 (); test8 (1); -#if !defined(__AVR__) && !defined(__hpux__) /* avr and hpux have no strndup */ +#ifndef SKIP_STRNDUP test9 (); #endif DONE (); diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-3.c b/gcc/testsuite/gcc.dg/builtin-object-size-3.c index f4d1ebf7027bf..3f58da3d500cd 100644 --- a/gcc/testsuite/gcc.dg/builtin-object-size-3.c +++ b/gcc/testsuite/gcc.dg/builtin-object-size-3.c @@ -1,6 +1,7 @@ /* { dg-do run } */ /* { dg-options "-O2 -Wno-stringop-overread" } */ /* { dg-require-effective-target alloca } */ +/* { dg-additional-options "-DSKIP_STRNDUP" { target { ! strndup } } } */ #include "builtin-object-size-common.h" @@ -628,7 +629,7 @@ test10 (void) } } -#if !defined(__AVR__) && !defined(__hpux__) /* avr and hpux have no strndup */ +#ifndef SKIP_STRNDUP /* Tests for strdup/strndup. */ size_t __attribute__ ((noinline)) @@ -717,7 +718,7 @@ test11 (void) FAIL (); free (res); } -#endif /* avr */ +#endif int main (void) @@ -734,7 +735,7 @@ main (void) test8 (); test9 (1); test10 (); -#if !defined(__AVR__) && !defined(__hpux__) /* avr and hpux have no strndup */ +#ifndef SKIP_STRNDUP test11 (); #endif DONE (); diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-4.c b/gcc/testsuite/gcc.dg/builtin-object-size-4.c index 2887dd150423b..b3eb36efb744d 100644 --- a/gcc/testsuite/gcc.dg/builtin-object-size-4.c +++ b/gcc/testsuite/gcc.dg/builtin-object-size-4.c @@ -1,6 +1,7 @@ /* { dg-do run } */ /* { dg-options "-O2 -Wno-stringop-overread" } */ /* { dg-require-effective-target alloca } */ +/* { dg-additional-options "-DSKIP_STRNDUP" { target { ! strndup } } } */ #include "builtin-object-size-common.h" @@ -509,7 +510,7 @@ test8 (unsigned cond) #endif } -#if !defined(__AVR__) && !defined(__hpux__) /* avr and hpux have no strndup */ +#ifndef SKIP_STRNDUP /* Tests for strdup/strndup. */ size_t __attribute__ ((noinline)) @@ -597,7 +598,7 @@ test9 (void) FAIL (); free (res); } -#endif /* avr */ +#endif int main (void) @@ -612,7 +613,7 @@ main (void) test6 (); test7 (); test8 (1); -#if !defined(__AVR__) && !defined(__hpux__) /* avr and hpux have no strndup */ +#ifndef SKIP_STRNDUP test9 (); #endif DONE (); diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index edce672c0e21a..17c8382adf143 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -11580,6 +11580,17 @@ proc check_effective_target_stpcpy {} { return [check_function_available "stpcpy"] } +# Returns 1 if "strndup" is available on the target system. + +proc check_effective_target_strndup {} { + if { [istarget *-*-vxworks*] } { + # VxWorks doesn't have strndup but our way to test fails + # to detect as we're doing partial links for kernel modules. + return 0 + } + return [check_function_available "strndup"] +} + # Returns 1 if "sigsetjmp" is available on the target system. # Also check if "__sigsetjmp" is defined since that's what glibc # uses.