[pushed] c++, contracts: Only check contracts attributes [PR116607].

Message ID 20241030134606.55039-1-iain@sandoe.co.uk
State Committed
Commit 673d6b2cbf610508d315526f4963793a343a2070
Headers
Series [pushed] c++, contracts: Only check contracts attributes [PR116607]. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Iain Sandoe Oct. 30, 2024, 1:46 p.m. UTC
  Tested on x86_64-darwin, powerpc64-linux, pushed to trunk as 
trivial/obvious, thanks.
Iain

--- 8< ---

The ICE described in the PR is caused by not filtering out non-
contract attributes before making the has_active_contract_condition
test.  Fixed, as suggested by Andrew Pinski, by just using the
existing CONTRACT_CHAIN () macro to advance through the list.

	PR c++/116607

gcc/cp/ChangeLog:

	* contracts.cc (has_active_contract_condition): Use the
	CONTRACT_CHAIN macro to advance through the attribute list.

gcc/testsuite/ChangeLog:

	* g++.dg/contracts/pr116607.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
---
 gcc/cp/contracts.cc                       | 2 +-
 gcc/testsuite/g++.dg/contracts/pr116607.C | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/contracts/pr116607.C
  

Patch

diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index 2a55b87bd03..113469b49f7 100644
--- a/gcc/cp/contracts.cc
+++ b/gcc/cp/contracts.cc
@@ -1494,7 +1494,7 @@  contract_active_p (tree contract)
 static bool
 has_active_contract_condition (tree d, tree_code c)
 {
-  for (tree as = DECL_CONTRACTS (d) ; as != NULL_TREE; as = TREE_CHAIN (as))
+  for (tree as = DECL_CONTRACTS (d) ; as != NULL_TREE; as = CONTRACT_CHAIN (as))
     {
       tree contract = TREE_VALUE (TREE_VALUE (as));
       if (TREE_CODE (contract) == c && contract_active_p (contract))
diff --git a/gcc/testsuite/g++.dg/contracts/pr116607.C b/gcc/testsuite/g++.dg/contracts/pr116607.C
new file mode 100644
index 00000000000..726a5bcf646
--- /dev/null
+++ b/gcc/testsuite/g++.dg/contracts/pr116607.C
@@ -0,0 +1,6 @@ 
+// { dg-options "-std=c++20 -fcontracts " }
+struct a {
+  __attribute__((no_sanitize("")))
+  int f(int) [[pre:true]];
+};
+int a::f(int) { return 0; }
\ No newline at end of file