aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuliano Procida <gprocida@google.com>2023-12-01 14:40:16 +0000
committerGiuliano Procida <gprocida@google.com>2023-12-13 11:25:07 +0000
commit12254b5683084ee4dc448bc1634504cfffe7f323 (patch)
tree91294724a85d91f9e9f43e16d9512a1732e2abf3
parentd2f0adcb76772a94bf92b2dd6308c75b1b074074 (diff)
downloadstg-12254b5683084ee4dc448bc1634504cfffe7f323.tar.gz
type roots: ignore typedefs that would have been filtered out
When file-based type definition filtering (`--files`) is active, any type not matching the filter will not be considered a type root (`--types`). Previous to this change, such `typedef`s were still considered type roots. `typedef`, as a C and C++ language feature, does not permit forward declaration and STG does not model `typedef`s without a definition. STG only considers named types with definitions as type roots. Logically, if a `typedef` would have lost its definition, it should not be considered a type root. PiperOrigin-RevId: 586994877 Change-Id: I69c9a4069b7dca2d1e348e6690566ca843f4aba6
-rw-r--r--dwarf_processor.cc5
-rw-r--r--test_cases/info_tests/source_filter/expected/type_roots_cc.elf_stg15
2 files changed, 5 insertions, 15 deletions
diff --git a/dwarf_processor.cc b/dwarf_processor.cc
index a8e41bf..7f91653 100644
--- a/dwarf_processor.cc
+++ b/dwarf_processor.cc
@@ -424,6 +424,11 @@ class Processor {
const std::string type_name = scope_ + GetName(entry);
auto referred_type_id = GetIdForReferredType(MaybeGetReferredType(entry));
const Id id = AddProcessedNode<Typedef>(entry, type_name, referred_type_id);
+ if (!ShouldKeepDefinition(entry, type_name)) {
+ // We always model (and keep) typedef definitions. But we should exclude
+ // filtered out types from being type roots.
+ return;
+ }
AddNamedTypeNode(id);
}
diff --git a/test_cases/info_tests/source_filter/expected/type_roots_cc.elf_stg b/test_cases/info_tests/source_filter/expected/type_roots_cc.elf_stg
index 2b219ca..e91b30c 100644
--- a/test_cases/info_tests/source_filter/expected/type_roots_cc.elf_stg
+++ b/test_cases/info_tests/source_filter/expected/type_roots_cc.elf_stg
@@ -1,20 +1,5 @@
version: 0x00000002
root_id: 0x84ea5130
-special {
- id: 0x48b5725f
- kind: VOID
-}
-pointer_reference {
- id: 0x18bd6530
- kind: POINTER
- pointee_type_id: 0x48b5725f
-}
-typedef {
- id: 0x4f137329
- name: "Typedef"
- referred_type_id: 0x18bd6530
-}
interface {
id: 0x84ea5130
- type_id: 0x4f137329
}