]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: handle volatile ops
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 15 Sep 2023 17:47:42 +0000 (13:47 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Fri, 15 Sep 2023 17:47:42 +0000 (13:47 -0400)
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>
gcc/analyzer/region-model.cc
gcc/testsuite/c-c++-common/analyzer/volatile-1.c [new file with mode: 0644]

index 2e774c2824e78885fbe05818808a823078334c9b..c4e68661ef1eba2b0f193b26b315566d59b43495 100644 (file)
@@ -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 (file)
index 0000000..f8440d4
--- /dev/null
@@ -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" } */
+}