]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: skip constant pool in -fdump-analyzer-untracked [PR testsuite/105085]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 29 Mar 2022 21:50:48 +0000 (17:50 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 29 Mar 2022 21:50:48 +0000 (17:50 -0400)
In r12-7809-g5f6197d7c197f9 I added -fdump-analyzer-untracked as support
for DejaGnu testing of an optimization of -fanalyzer,
PR analyzer/104954.

PR testsuite/105085 notes testsuite failures of the form:
  FAIL: gcc.dg/analyzer/untracked-1.c (test for excess errors)
  Excess errors:
  cc1: warning: track '*.LC1': yes
where these warnings are emitted on some targets where the test
causes labelled constants to be created in the constant pool.

We probably ought not to be tracking the values of such decls in the
store, given that they're meant to be constant, and I attempted various
fixes to make the "should we track this decl" logic smarter, but given
that we're in stage 4, the simplest fix seems to be for
-fdump-analyzer-untracked to skip such decls in its output, to minimize
test output differences between targets.

gcc/analyzer/ChangeLog:
PR testsuite/105085
* region-model-manager.cc (dump_untracked_region): Skip decls in
the constant pool.

gcc/testsuite/ChangeLog:
PR testsuite/105085
* gcc.dg/analyzer/untracked-1.c: Add further test coverage.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/region-model-manager.cc
gcc/testsuite/gcc.dg/analyzer/untracked-1.c

index 5ca333a9ed6a03c4caaa072b50145638ce7e6a03..56d60768749ee99be631f904495d7daeeca6f665 100644 (file)
@@ -1770,6 +1770,13 @@ dump_untracked_region (const decl_region *decl_reg)
   tree decl = decl_reg->get_decl ();
   if (TREE_CODE (decl) != VAR_DECL)
     return;
+  /* For now, don't emit the status of decls in the constant pool, to avoid
+     differences in DejaGnu test results between targets that use these vs
+     those that don't.
+     (Eventually these decls should probably be untracked and we should test
+     for that, but that's not stage 4 material).  */
+  if (DECL_IN_CONSTANT_POOL (decl))
+    return;
   warning_at (DECL_SOURCE_LOCATION (decl), 0,
              "track %qD: %s",
              decl, (decl_reg->tracked_p () ? "yes" : "no"));
index d07c2975670932f0fc463e6eebbc1e9dd1553f96..9f3a639db5cdf0cec8c159f7815b9ad48f71be47 100644 (file)
@@ -1,5 +1,7 @@
 /* { dg-additional-options "-fdump-analyzer-untracked" } */
 
+#include "analyzer-decls.h"
+
 struct st
 {
   const char *m_filename;
@@ -39,6 +41,16 @@ void test_3 (void)
   extern_fn (&s3);
 }
 
+void test_3a (void)
+{
+  struct st s3a = { "foo.c", 42 }; /* { dg-warning "track 's3a': yes" } */
+  __analyzer_eval (s3a.m_filename[0] == 'f'); /* { dg-warning "TRUE" } */
+  __analyzer_eval (s3a.m_line == 42); /* { dg-warning "TRUE" } */
+  extern_fn (&s3a);
+  __analyzer_eval (s3a.m_filename[0] == 'f'); /* { dg-warning "UNKNOWN" } */
+  __analyzer_eval (s3a.m_line == 42); /* { dg-warning "UNKNOWN" } */
+}
+
 extern void called_by_test_4 (int *);
 
 int test_4 (void)
@@ -103,3 +115,17 @@ void test_13 (void)
 {
   extern_fn_char_ptr (__func__); /* { dg-warning "track '__func__': no" } */
 }
+
+char t14_global_unused[100]; /* { dg-warning "track 't14_global_unused': yes" } */
+static char t14_static_unused[100]; /* { dg-warning "track 't14_static_unused': yes" } */
+char t14_global_used[100]; /* { dg-warning "track 't14_global_used': yes" } */
+static char t14_static_used[100]; /* { dg-warning "track 't14_static_used': yes" } */
+void test_14 (void)
+{
+  extern_fn_char_ptr (t14_global_unused);
+  extern_fn_char_ptr (t14_static_unused);
+  extern_fn_char_ptr (t14_global_used);
+  __analyzer_eval (t14_global_used[0] == '\0'); /* { dg-warning "UNKNOWN" } */
+  extern_fn_char_ptr (t14_static_used);
+  __analyzer_eval (t14_static_used[0] == '\0'); /* { dg-warning "UNKNOWN" } */
+}