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: 1835101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=G8lvtfu8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RnMHh26BZz1ygG for ; Sat, 16 Sep 2023 03:53:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4006E3858C33 for ; Fri, 15 Sep 2023 17:53:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4006E3858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694800414; 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=G8lvtfu8I+Zs8tr+1yW+qXI3RphsH6QEme5G8T3n6IJxxnFUSx1eaDoJN4qEYIsSx rt03eT6hye2EwleikpUYWjZIRkvbfAr1T0wz87xJzOKemdbiu2xvK62gAMq5D3pb4s Hfhv/Z4HO/vxSIl7YkK5/5l3u99d069rGQ+tGjbY= 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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" } */ +}