[applied] abilint --show-type-use: Show results for global decls that have no symbols

Message ID 87o82qj9hb.fsf@redhat.com
State New
Headers
Series [applied] abilint --show-type-use: Show results for global decls that have no symbols |

Commit Message

Dodji Seketeli March 1, 2022, 9:41 a.m. UTC
  Hello,

In some abixml files, there can be global decls that don't have ELF
symbols.  We still want to see how those decls use the type that is
being used, as analyzed by abilint --show-type-use <type-id>.

	* include/abg-fwd.h (is_at_global_scope): Declare ...
	* src/abg-ir.cc (is_at_global_scope): ... new overload.
	* tools/abilint.cc (emit_artifact_use_trace): Emit the trace also
	when the decl is at global scope or has a linkage name.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 include/abg-fwd.h | 3 +++
 src/abg-ir.cc     | 9 +++++++++
 tools/abilint.cc  | 8 ++++++--
 3 files changed, 18 insertions(+), 2 deletions(-)
  

Patch

diff --git a/include/abg-fwd.h b/include/abg-fwd.h
index c5e98afe..6afaf7bc 100644
--- a/include/abg-fwd.h
+++ b/include/abg-fwd.h
@@ -349,6 +349,9 @@  is_at_global_scope(const decl_base&);
 bool
 is_at_global_scope(const decl_base_sptr);
 
+bool
+is_at_global_scope(const decl_base*);
+
 class_or_union*
 is_at_class_scope(const decl_base_sptr);
 
diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index 82971253..4afe2d61 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -9332,6 +9332,15 @@  bool
 is_at_global_scope(const decl_base_sptr decl)
 {return (decl && is_global_scope(decl->get_scope()));}
 
+/// Tests whether a given declaration is at global scope.
+///
+/// @param decl the decl to consider.
+///
+/// @return true iff decl is at global scope.
+bool
+is_at_global_scope(const decl_base* decl)
+{return is_at_global_scope(*decl);}
+
 /// Tests whether a given decl is at class scope.
 ///
 /// @param decl the decl to consider.
diff --git a/tools/abilint.cc b/tools/abilint.cc
index ba2de634..4883b557 100644
--- a/tools/abilint.cc
+++ b/tools/abilint.cc
@@ -398,10 +398,14 @@  emit_artifact_use_trace(const artifact_use_relation_tree& artifact_use_tree,
       if (is_decl(artifact))
 	{
 	  if (abigail::ir::var_decl* v = is_var_decl(artifact))
-	    if (v->get_symbol())
+	    if (v->get_symbol()
+		|| is_at_global_scope(v)
+		|| !v->get_linkage_name().empty())
 	      do_emit_trace = true;
 	  if (abigail::ir::function_decl* f = is_function_decl(artifact))
-	    if (f->get_symbol())
+	    if (f->get_symbol()
+		|| is_at_global_scope(f)
+		|| !f->get_linkage_name().empty())
 	      do_emit_trace = true;
 	}