From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 4E3083858282; Sat, 1 Oct 2022 04:50:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E3083858282 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664599807; bh=oeqM3cDgawSE7FNrGeJuBg2kZE703pXepCq/7Nllq0I=; h=From:To:Subject:Date:From; b=PdT3i4iAm0siXWpwBA+bjghlTBxc+38qLiflgg3xCF7VfgVMJCNMbWonKyXADFb1Z TPlAwZeUbA0qKQoqOw5yF824SVdJMoDVGPhob5K812IMDFQRcvpFAtZbD0qQqCJGWz PBmink/rjV5lhN0ZgtenlemUas5NKL1Y3whA3K+M= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] hardcfr: fix builtin_return noreturn mishandling X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: d76a74ab71898f393606254ff17a72352f05e775 X-Git-Newrev: a162f8e5378c2dfeada2c38b5847c953e978c48e Message-Id: <20221001045007.4E3083858282@sourceware.org> Date: Sat, 1 Oct 2022 04:50:07 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a162f8e5378c2dfeada2c38b5847c953e978c48e commit a162f8e5378c2dfeada2c38b5847c953e978c48e Author: Alexandre Oliva Date: Fri Sep 30 23:20:33 2022 -0300 hardcfr: fix builtin_return noreturn mishandling Diff: --- gcc/gimple-harden-control-flow.cc | 18 ++++++++++-------- .../c-c++-common/torture/harden-cfr-bret-always.c | 13 +++++++++++++ .../c-c++-common/torture/harden-cfr-bret-never.c | 13 +++++++++++++ .../c-c++-common/torture/harden-cfr-bret-noopt.c | 12 ++++++++++++ .../c-c++-common/torture/harden-cfr-bret-noret.c | 12 ++++++++++++ .../c-c++-common/torture/harden-cfr-bret-nothrow.c | 13 +++++++++++++ .../c-c++-common/torture/harden-cfr-bret-retcl.c | 12 ++++++++++++ gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c | 8 +++++++- 8 files changed, 92 insertions(+), 9 deletions(-) diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc index 1c93bf622e8..cd5b3cf69b2 100644 --- a/gcc/gimple-harden-control-flow.cc +++ b/gcc/gimple-harden-control-flow.cc @@ -1294,12 +1294,15 @@ pass_harden_control_flow_redundancy::execute (function *fun) continue; } - /* If there are no exceptions, then any noreturn call must have - zero successor edges. Otherwise, check for blocks without - non-EH successors, but skip those with resx stmts and edges - (i.e., those other than that in bb_eh_cleanup), since those - will go through bb_eh_cleanup, that will have been counted as - noreturn above because it has no successors. */ + /* If there are no exceptions, it would seem like any noreturn + call must have zero successor edges, but __builtin_return + gets successor edges. We don't want to handle it here, it + will be dealt with in sibcall_search_preds. Otherwise, + check for blocks without non-EH successors, but skip those + with resx stmts and edges (i.e., those other than that in + bb_eh_cleanup), since those will go through bb_eh_cleanup, + that will have been counted as noreturn above because it + has no successors. */ gcc_checking_assert (bb != bb_eh_cleanup || !check_at_escaping_exceptions); if (flag_exceptions && is_a (stmt) @@ -1309,8 +1312,7 @@ pass_harden_control_flow_redundancy::execute (function *fun) ? false : (!flag_exceptions || gimple_call_nothrow_p (as_a (stmt))) - ? (/* Catch cases that should not have successors. */ - gcc_unreachable (), check_before_nothrow_noreturn_calls) + ? false /* rather than check_before_nothrow_noreturn_calls */ : always_throwing_noreturn_call_p (stmt) ? check_before_always_throwing_noreturn_calls : check_before_throwing_noreturn_calls) 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 new file mode 100644 index 00000000000..779896c60e8 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fdump-tree-hardcfr -ffat-lto-objects" } */ + +/* Check that, even enabling all checks before noreturn calls (leaving + returning calls enabled), we get checks before __builtin_return without + duplication (__builtin_return is both noreturn and a returning call). */ + +#include "harden-cfr-bret.c" + +/* Out-of-line checking, before both builtin_return and return in f. */ +/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */ +/* Inline checking before builtin_return in g. */ +/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "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 new file mode 100644 index 00000000000..49ce17f5b93 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */ + +/* Check that, even enabling checks before never noreturn calls (leaving + returning calls enabled), we get checks before __builtin_return without + duplication (__builtin_return is both noreturn and a returning call). */ + +#include "harden-cfr-bret.c" + +/* Out-of-line checking, before both builtin_return and return in f. */ +/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */ +/* Inline checking before builtin_return in g. */ +/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */ 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 new file mode 100644 index 00000000000..1512614791f --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c @@ -0,0 +1,12 @@ +/* { 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" } */ + +/* Check that, even disabling checks before both noreturn and returning + calls, we still get checks before __builtin_return. */ + +#include "harden-cfr-bret.c" + +/* Out-of-line checking, before both builtin_return and return in f. */ +/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */ +/* Inline checking before builtin_return in g. */ +/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */ 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 new file mode 100644 index 00000000000..fd95bb7e3e3 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */ + +/* Check that, even disabling checks before returning calls (leaving noreturn + calls enabled), we still get checks before __builtin_return. */ + +#include "harden-cfr-bret.c" + +/* Out-of-line checking, before both builtin_return and return in f. */ +/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */ +/* Inline checking before builtin_return in g. */ +/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */ 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 new file mode 100644 index 00000000000..c5c361234c4 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=nothrow -fdump-tree-hardcfr -ffat-lto-objects" } */ + +/* Check that, even enabling checks before nothrow noreturn calls (leaving + returning calls enabled), we get checks before __builtin_return without + duplication (__builtin_return is both noreturn and a returning call). */ + +#include "harden-cfr-bret.c" + +/* Out-of-line checking, before both builtin_return and return in f. */ +/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */ +/* Inline checking before builtin_return in g. */ +/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */ 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 new file mode 100644 index 00000000000..137dfbb95d6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */ + +/* Check that, even disabling checks before noreturn calls (leaving returning + calls enabled), we still get checks before __builtin_return. */ + +#include "harden-cfr-bret.c" + +/* Out-of-line checking, before both builtin_return and return in f. */ +/* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */ +/* Inline checking before builtin_return in g. */ +/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */ 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 70acdc95f25..b459ff6b864 100644 --- a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c +++ b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c @@ -7,5 +7,11 @@ int f(int i) { return i; } -/* Out-of-line checking, before both builtin_return and return. */ +int g(int i) { + __builtin_return (&i); +} + +/* Out-of-line checking, before both builtin_return and return in f. */ /* { dg-final { scan-tree-dump-times "__hardcfr_check" 2 "hardcfr" } } */ +/* Inline checking before builtin_return in g. */ +/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */