analyzer: use DECL_DEBUG_EXPR on SSA names for artificial vars
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 15 Jul 2021 19:02:42 +0000 (15:02 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 15 Jul 2021 19:02:42 +0000 (15:02 -0400)
gcc/analyzer/ChangeLog:
* analyzer.cc (fixup_tree_for_diagnostic_1): Use DECL_DEBUG_EXPR
if it's available.
* engine.cc (readability): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/analyzer.cc
gcc/analyzer/engine.cc

index 12c03f6..a8ee1a1 100644 (file)
@@ -165,8 +165,13 @@ fixup_tree_for_diagnostic_1 (tree expr, hash_set<tree> *visited)
       && TREE_CODE (expr) == SSA_NAME
       && (SSA_NAME_VAR (expr) == NULL_TREE
          || DECL_ARTIFICIAL (SSA_NAME_VAR (expr))))
-    if (tree expr2 = maybe_reconstruct_from_def_stmt (expr, visited))
-      return expr2;
+    {
+      if (tree var = SSA_NAME_VAR (expr))
+       if (VAR_P (var) && DECL_HAS_DEBUG_EXPR_P (var))
+         return DECL_DEBUG_EXPR (var);
+      if (tree expr2 = maybe_reconstruct_from_def_stmt (expr, visited))
+       return expr2;
+    }
   return expr;
 }
 
index 01b83a4..8f3e7f7 100644 (file)
@@ -527,9 +527,22 @@ readability (const_tree expr)
     case SSA_NAME:
       {
        if (tree var = SSA_NAME_VAR (expr))
-         /* Slightly favor the underlying var over the SSA name to
-            avoid having them compare equal.  */
-         return readability (var) - 1;
+         {
+           if (DECL_ARTIFICIAL (var))
+             {
+               /* If we have an SSA name for an artificial var,
+                  only use it if it has a debug expr associated with
+                  it that fixup_tree_for_diagnostic can use.  */
+               if (VAR_P (var) && DECL_HAS_DEBUG_EXPR_P (var))
+                 return readability (DECL_DEBUG_EXPR (var)) - 1;
+             }
+           else
+             {
+               /* Slightly favor the underlying var over the SSA name to
+                  avoid having them compare equal.  */
+               return readability (var) - 1;
+             }
+         }
        /* Avoid printing '<unknown>' for SSA names for temporaries.  */
        return -1;
       }