public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-4040] analyzer: handle volatile ops
Date: Fri, 15 Sep 2023 17:48:54 +0000 (GMT) [thread overview]
Message-ID: <20230915174854.DD74D3858D35@sourceware.org> (raw)
https://gcc.gnu.org/g:6319b5b2d4669077e4ddf1e249eeb5602394693c
commit r14-4040-g6319b5b2d4669077e4ddf1e249eeb5602394693c
Author: David Malcolm <dmalcolm@redhat.com>
Date: Fri Sep 15 13:47:42 2023 -0400
analyzer: handle volatile ops
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.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/analyzer/region-model.cc | 11 +++++++++++
gcc/testsuite/c-c++-common/analyzer/volatile-1.c | 18 ++++++++++++++++++
2 files changed, 29 insertions(+)
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" } */
+}
reply other threads:[~2023-09-15 17:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230915174854.DD74D3858D35@sourceware.org \
--to=dmalcolm@gcc.gnu.org \
--cc=gcc-cvs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).