From patchwork Fri Sep 15 17:53:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 140587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1222527vqi; Fri, 15 Sep 2023 10:54:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdmE1/xYJ26Z6B0ZX1u5lqXd9SJFZATHUkJtS98Hj9p5PEgPrWBVX8dwUmRGolyORIk+ov X-Received: by 2002:a05:6402:1108:b0:52f:a5d4:1f5b with SMTP id u8-20020a056402110800b0052fa5d41f5bmr2114403edv.9.1694800446004; Fri, 15 Sep 2023 10:54:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694800445; cv=none; d=google.com; s=arc-20160816; b=ZT++1mAjN091AEF6XrhzslfdGDMSODDAPvS6Nq5G3k/L8ZHBU7lV5SXDmPa/L6pTEU 4b2mdSj/29ZnwzEMJXuMK5URPDzUVruAU0K0nmZG5NFFwpI0bhkiMQp9tfhIapniV9rN HKmiN95JoHkW9nAHjTSyYzFdbg2yml/QqVd42iv2p8ZnlylUVYSW4ntyAXLiElaCDPua i03Xz7/LnyWMXSF6U5dzg8kW4zdQhSpEscyesMLwPMPlY/Y7KEvcB1R+yVZ7cZ6KtDMd eTC8Zg8Kthz/LuZi0mSrUf+swHCqSufKZpZiV1/iqLUYGy+6jwyuaSW/h0uy/0vJzywd MCfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=bF0tTh9c5tMMGsob2CmwR//0JD93itxd6QmC+8otVQ0=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=xANCCxJX1yclyhMQgzbfAWMceCyIGi8eBOlZNKM5o/ayUaJaxoOgcQqD7xBH1J2rb8 qD6e3zBg/lnneRAqBMx41OA9UejdsvRV/xMWu3/H/h3iDFd24Rq4PzjTpI7ULvdJHAn0 L/A0R00TYqkKqkfx3fTucugMHuaAx2qDUOp3rih69DOzgkNqeyYtM8sTcpUkz42Svr4e 9vOwbqrj15UQ4MiEBBKX91NeFMQNTT9sfBkErjzrHDnP7IekezvhoOz4hPhF0UlwkS1k NJT1mPWvdoDE1VELp1RJWhEExLm5F3RFCUgaEdHsReRBoRzUcyNGSAgVl8yvZ2q57BJK lDgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pfVhgOPm; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j22-20020aa7ca56000000b0052c7734a9e9si3735321edt.603.2023.09.15.10.54.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:54:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pfVhgOPm; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 868BB3856DC7 for ; Fri, 15 Sep 2023 17:53:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 868BB3856DC7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694800437; bh=bF0tTh9c5tMMGsob2CmwR//0JD93itxd6QmC+8otVQ0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=pfVhgOPmpAJ/p8oZvZWgoQ2ro3SOsokcm2tFVKJxx15OFXXYAJMrTfdLCEKtonn9n WRlhor1bynBof4Wq0h7Ya1/LpAoF15qYhAs+1j8K0jJWxIS9spKuqJVu9Qjn69pI+8 +1u7reUEHam5GB1gz4eSaQFta6e+Gh21VyY/Zkok= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 3AB053858D35 for ; Fri, 15 Sep 2023 17:53:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3AB053858D35 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-693-IQ9lFp7bPpG7udBKJ0RLQQ-1; Fri, 15 Sep 2023 13:53:13 -0400 X-MC-Unique: IQ9lFp7bPpG7udBKJ0RLQQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 384C0945944 for ; Fri, 15 Sep 2023 17:53:13 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06BF510F1BE7; Fri, 15 Sep 2023 17:53:12 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: handle volatile ops Date: Fri, 15 Sep 2023 13:53:11 -0400 Message-Id: <20230915175311.1908421-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777127072575742894 X-GMAIL-MSGID: 1777127072575742894 Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-4040-g6319b5b2d46690. gcc/analyzer/ChangeLog: * region-model.cc (region_model::get_gassign_result): Handle volatile ops by using a conjured_svalue. gcc/testsuite/ChangeLog: * c-c++-common/analyzer/volatile-1.c: New test. --- gcc/analyzer/region-model.cc | 11 +++++++++++ .../c-c++-common/analyzer/volatile-1.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/analyzer/volatile-1.c diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 2e774c2824e..c4e68661ef1 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -729,6 +729,17 @@ region_model::get_gassign_result (const gassign *assign, region_model_context *ctxt) { tree lhs = gimple_assign_lhs (assign); + + if (gimple_has_volatile_ops (assign) + && !gimple_clobber_p (assign)) + { + conjured_purge p (this, ctxt); + return m_mgr->get_or_create_conjured_svalue (TREE_TYPE (lhs), + assign, + get_lvalue (lhs, ctxt), + p); + } + tree rhs1 = gimple_assign_rhs1 (assign); enum tree_code op = gimple_assign_rhs_code (assign); switch (op) diff --git a/gcc/testsuite/c-c++-common/analyzer/volatile-1.c b/gcc/testsuite/c-c++-common/analyzer/volatile-1.c new file mode 100644 index 00000000000..f8440d41220 --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/volatile-1.c @@ -0,0 +1,18 @@ +#include "../../gcc.dg/analyzer/analyzer-decls.h" + +volatile int g; + +void test_global (void) +{ + int v1 = g; + int v2 = g; + __analyzer_eval (v1 == v2); /* { dg-warning "UNKNOWN" } */ +} + +void test_local (void) +{ + volatile int x = 0; + int v1 = x; + int v2 = x; + __analyzer_eval (v1 == v2); /* { dg-warning "UNKNOWN" } */ +}