From patchwork Fri Dec 1 12:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 81110 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 DC883385841F for ; Fri, 1 Dec 2023 12:57:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 85DC33858CDB for ; Fri, 1 Dec 2023 12:57:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85DC33858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none 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 85DC33858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701435464; cv=none; b=fjViDq2HMaRxn/1VWR6f3DevXFMykrSENXgOzyT9sJJ4qwiA+r56v7+M7FVS4AitHKAvQains65I34oY406plXdXu4aZ4Mezudz9yMt/YKK/XJv2aRra6R65jlLn2gyGaw0UDYhLc8bZ6SouaGmgM3UkmHL0cqGCXpj/qZ6320s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701435464; c=relaxed/simple; bh=sznbUtgsFZW2qeYLp1TBK0jAYUBYMZkECZPP+Euk1+A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EbtuN+ApVqjw+foYwhGOoe9lsQDknlDB39D24OuPG1ISyRyHZTbmf72oIEv77iHFOxJNPbeXioNZ/dC6jfEbWBAuWQz7SgVrYPIYfCVr5U9cdv7946zqoiE4MOtX5dxl843J8+qOfKrBLEoiGrGcuCaGSuXYRx5y+4kyjhifaYU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1cfabcbda7bso3756415ad.0 for ; Fri, 01 Dec 2023 04:57:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1701435460; x=1702040260; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=xneq/QUtRzTXVV5Hs1klmILFgQTlZPoA3O04ONiitxI=; b=SyDYcECDW31sAYDdLL4wihMX9jwif/wPVLo0HXGONpYdDSWmPBW7+6SFnOYNbXNdvO oEq51r+tzhwal9IVXG6KgB4md9qxzSeQtYSTmyCcga2GOKI4jiW5+FPU1WFkl7Qoz9xJ O5v6+NS7o292XlDULnZFyF6Mt4xiukFChCNdeKr//1KIsgn3XQFZwX4AtvZojwJ4K88z 6q+zTJgT7APDVe7SmuDC+UQkw5WZXo1zDErCH8wj6INLLAVnkPSxP0S8aC4yy/0jfGNs OfuD4rfxf1bi97MgwQgzXsxZkVudPpW02u7GSr7fCHL82Q1qC3yfRr0PspRjn9RHykE+ /KJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701435460; x=1702040260; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xneq/QUtRzTXVV5Hs1klmILFgQTlZPoA3O04ONiitxI=; b=oqwEhLfOi/9e1dObIrp4HzBS30r+7dWz0z1kJE1I0wnVNbg0aFSKvfR7UWu6Zq4urP TtLMsxWcSrIJmB663a1FK3Uve5uVNUxNDB7H1aDgwLf/jeZj1V+pXRSZYfxkrrZpA6rx phJsC4tRVG+VX8CvwKKf7X6gF59GFRJ5TOvc+QTUS9GKReiJP3Y29mz+EYx38SHv6iNV 11uG9OPkvDCabbMR4KFNYWl6FcTLrrvDPsexS7WGNfw994HD+owHlRv/7ZDrJtNjo50Q Bo30vjckmRDdoYfgSdujU2O8OXfP9Lw93PeSb8hjL6bm4RaMJ3cl5MtLVVyXqQi4S6Ln WhvQ== X-Gm-Message-State: AOJu0Ywxgqvk4paWRshlfimgxYGRmHZWxwedX8oARYZlYP5/lYu5s8XM qg+6JJy9WrXEaaQtONbQMjKfV3x/fQW5PHsrB2sO/w== X-Google-Smtp-Source: AGHT+IExIfbvaITwtzSHcv37zTZOLbwoGhqTZRgEKtRxO9M4rwhybNoVGxGkBxTZ7iITPiVJCpdXww== X-Received: by 2002:a17:903:1108:b0:1bc:edd:e891 with SMTP id n8-20020a170903110800b001bc0edde891mr42661971plh.1.1701435460422; Fri, 01 Dec 2023 04:57:40 -0800 (PST) Received: from free.home ([2804:14c:4d1:44a5:f4d9:b7a4:4fb8:376f]) by smtp.gmail.com with ESMTPSA id g19-20020a632013000000b005c60ad6c4absm3005807pgg.4.2023.12.01.04.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 04:57:39 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3B1CvTSp095875 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 1 Dec 2023 09:57:30 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PATCH] hardcfr: make builtin_return tests more portable [PR112334] Organization: Free thinker, does not speak for AdaCore Date: Fri, 01 Dec 2023 09:57:29 -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.1 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, T_SCC_BODY_TEXT_LINE, 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 Rework __builtin_return tests to explicitly call __builtin_apply and use its return value rather than anything else. Also require untyped_assembly. Avoid the noise out of exceptions escaping the builtin-applied function, but add a test to cover their effects as well. Regstrapped on x86_64-linux-gnu. Also tested on arm-eabi, but it's *not* enough (or needed) to fix the PR, there's another bug lurking there, with a separate patch coming up. Regardless, is this ok to install? for gcc/testsuite/ChangeLog PR target/112334 * c-c++-common/torture/harden-cfr-bret.c: Rework for stricter untyped_return requirements. Require untyped_assembly. * c-c++-common/torture/harden-cfr-bret-except.c: New. * c-c++-common/torture/harden-cfr-bret-always.c: Require untyped_assembly. * c-c++-common/torture/harden-cfr-bret-never.c: Likewise. * c-c++-common/torture/harden-cfr-bret-noopt.c: Likewise. * c-c++-common/torture/harden-cfr-bret-noret.c: Likewise. * c-c++-common/torture/harden-cfr-bret-no-xthrow.c: Likewise. * c-c++-common/torture/harden-cfr-bret-nothrow.c: Likewise. * c-c++-common/torture/harden-cfr-bret-retcl.c: Likewise. --- .../c-c++-common/torture/harden-cfr-bret-always.c | 3 ++- .../c-c++-common/torture/harden-cfr-bret-except.c | 17 +++++++++++++++ .../c-c++-common/torture/harden-cfr-bret-never.c | 3 ++- .../torture/harden-cfr-bret-no-xthrow.c | 3 ++- .../c-c++-common/torture/harden-cfr-bret-noopt.c | 3 ++- .../c-c++-common/torture/harden-cfr-bret-noret.c | 3 ++- .../c-c++-common/torture/harden-cfr-bret-nothrow.c | 3 ++- .../c-c++-common/torture/harden-cfr-bret-retcl.c | 3 ++- .../c-c++-common/torture/harden-cfr-bret.c | 23 ++++++++++++++++---- .../c-c++-common/torture/harden-cfr-noret.c | 2 +- 10 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/torture/harden-cfr-bret-except.c diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c index 779896c60e846..3406c4e6ef9dc 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-require-effective-target untyped_assembly } */ /* Check that, even enabling all checks before noreturn calls (leaving returning calls enabled), we get checks before __builtin_return without diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-except.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-except.c new file mode 100644 index 0000000000000..3acb61cb75a77 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-except.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-fharden-control-flow-redundancy -fexceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-require-effective-target untyped_assembly } */ + +/* Check that, with exceptions enabled, even in C, the calls initiated by + builtin_apply are enclosed in cleanup handlers that add extra checks. + Unfortunately, declaring foobar as nothrow is not enough to avoid the + handler around the builtin_apply call, so the other bret tests all use + -fno-exceptions. */ + +#include "harden-cfr-bret.c" + +/* With exceptions, we get an extra check per function, to check before + propagating exceptions, so it's 3 in f and 2 in g. */ +/* { dg-final { scan-tree-dump-times "__hardcfr_check" 5 "hardcfr" } } */ +/* The extra check in g also removes the possibility of inlining the check. */ +/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */ diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c index 49ce17f5b937c..7f8fb64138df1 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-require-effective-target untyped_assembly } */ /* Check that, even enabling checks before never noreturn calls (leaving returning calls enabled), we get checks before __builtin_return without diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-no-xthrow.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-no-xthrow.c index 78e5bf4143927..07588e8d3c341 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-no-xthrow.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-no-xthrow.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=no-xthrow -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=no-xthrow -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-require-effective-target untyped_assembly } */ /* Check that, even enabling checks before no-xthrow-throwing noreturn calls (leaving returning calls enabled), we get checks before __builtin_return diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c index 1512614791ff2..716d9297c8d94 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-hardcfr-check-returning-calls -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-require-effective-target untyped_assembly } */ /* Check that, even disabling checks before both noreturn and returning calls, we still get checks before __builtin_return. */ diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c index fd95bb7e3e334..c6d2baa312031 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-require-effective-target untyped_assembly } */ /* Check that, even disabling checks before returning calls (leaving noreturn calls enabled), we still get checks before __builtin_return. */ diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c index c5c361234c499..2fd0d82c7ea3e 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=nothrow -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=nothrow -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-require-effective-target untyped_assembly } */ /* Check that, even enabling checks before nothrow noreturn calls (leaving returning calls enabled), we get checks before __builtin_return without diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c index 137dfbb95d6bb..b070294fde8ad 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-require-effective-target untyped_assembly } */ /* Check that, even disabling checks before noreturn calls (leaving returning calls enabled), we still get checks before __builtin_return. */ diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c index b459ff6b86491..b6630a6c86695 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c @@ -1,14 +1,27 @@ /* { dg-do compile } */ -/* { dg-options "-fharden-control-flow-redundancy -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-options "-fharden-control-flow-redundancy -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-require-effective-target untyped_assembly } */ -int f(int i) { +extern int foobar (void); + +#if __cplusplus +typedef void (*fnt)(...); +#else +typedef void (*fnt)(); +#endif + +int i; + +int f(void) { if (i) - __builtin_return (&i); + __builtin_return (__builtin_apply ((fnt)foobar, + __builtin_apply_args (), 0)); return i; } -int g(int i) { - __builtin_return (&i); +int g(void) { + __builtin_return (__builtin_apply ((fnt)foobar, + __builtin_apply_args (), 0)); } /* Out-of-line checking, before both builtin_return and return in f. */ diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-noret.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-noret.c index fdd803109a4ae..8c7cc01c0ce68 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-noret.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-noret.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fdump-tree-hardcfr -ffat-lto-objects" } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */ /* Check that we insert checking before all noreturn calls. */