From patchwork Wed Oct 30 13:46:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 99820 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 8A8CC385841E for ; Wed, 30 Oct 2024 13:46:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 62AC13858D28 for ; Wed, 30 Oct 2024 13:46:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 62AC13858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 62AC13858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730295978; cv=none; b=mvbeBxpEtF1RfbclJEek3qOfXqAAa70N9cxAoJAWkS/3XHBrdak0IutCbxSrwzTJzpWxIq+lN6erVGQdJI/oU1XBsSLXN9xCkWiopzBgLHH5sDFzBPdawHeZTa0wbh+BXwCzEJu4Nr45xv7XGMiOW16tnFjegveuL1Tfq477UmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730295978; c=relaxed/simple; bh=qZcf7flfmuY9BSy0LrDOQk1R6NKWPjTEgAlMrGSPRw4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ea3Z40B8zCsBWMRjefrU7ykHuqwDCdfFWaKE2gjhL/hiQ12KqrWck/CebiPeYz1C4gV7wD8oSitOI+EYP8L3IRx7Zq0wB++x7VL9Emf5ZmssGTkez/WVFMDtLhOJAAKV6dUqg6XklFMSW2xMCDbUzF9ucbuym1WmPt3T/NtGIcU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-37d473c4bb6so5666306f8f.3 for ; Wed, 30 Oct 2024 06:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730295968; x=1730900768; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=vzuztqw7N1mFtRtXY+gHYyf/4cCGyqarwEGaRy2Ku6s=; b=nj+VrSTwXLJRvZrz5lndNMjjiA9qjvOkdDuPvQ8zCobQhSt7SVdDlaeOST4Z4XyGKK rgB4yzGY9RfObBw0eCebt6amuzJctj70XheL4lKHb8EOvYsAIlT1VNWgronttv5RrMQt 7LyIZ6qoCG1Pa7Rn7eTVX4dxqjwMWSU1qkhYAZNBT15J1deuI75/dDD1iOx5Bcw5IjPO Bu2StyWExC+Av45yhsZkqx/x4HPTpjt+hlZGFWgBetUTqhzW5Pax4zg6EDpYTxhJ9whA sEat0duSv9O0n6NGz2g/lPvf6FVk81tin5hNzI5gvHkqXLphX6WY0f5sasmExRZgc62X uCwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730295968; x=1730900768; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vzuztqw7N1mFtRtXY+gHYyf/4cCGyqarwEGaRy2Ku6s=; b=G7D9ETRJmGJ+mEp8yMJ3y6TS5fk91bElgSDu7/bXSD/nFATQb60vKskByjXswzTF1o Qym6hMhO1LxIBKjidGAZcVfFo7G7FeBaPi2iIn3mqgub8DZRdnjEfeTFFHWQD3ksgv2S Y8FqChCX2pedxyv3FM8aSvAa9YOf71ShWRhD0wYFhW5qd1CRP1iNvv6+rEoBTKzoxj9k JHdwiY6JKwKJXWq8EujwNZA3ucSsdH3fHxRCuEc2tNnJc59CiT9PINBV+wBTHYXrDA/c X6A10vjJPxe7yB/X5bFBtRsQIDmfwUozQSWQ9f4MjNAnWwiEWYSia/bsQ3YonmwRVoO1 e2mQ== X-Gm-Message-State: AOJu0YzA4lrdZzUn9slmT9UC9uh7T1sycsvWiDBsEUw+8kbvOHqPYbeO HjOy0QtjlGywy0F+uW6kJhnUKEClJG2DHgf6PC9e+b71oRMb5XryK11u1A== X-Google-Smtp-Source: AGHT+IEBpCx73b123oRuV9B5hPzwFwQqNFIlKWUEQRKNhpiw7XPs0D1UD0FMtRNW7aPStUPq1RDAEg== X-Received: by 2002:adf:f10a:0:b0:37d:4b26:54ca with SMTP id ffacd0b85a97d-38061171f6bmr14643840f8f.14.1730295967664; Wed, 30 Oct 2024 06:46:07 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058bb1bc3sm15271175f8f.110.2024.10.30.06.46.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 30 Oct 2024 06:46:07 -0700 (PDT) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, dinka.ranns@googlemail.com Subject: [pushed] c++, contracts: Only check contracts attributes [PR116607]. Date: Wed, 30 Oct 2024 13:46:06 +0000 Message-Id: <20241030134606.55039-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: , Reply-To: iain@sandoe.co.uk Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org 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 --- 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 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