Skip to content

Commit

Permalink
XML writer: emit enclosing types of scoped declarations
Browse files Browse the repository at this point in the history
Bug 26591 - detect pathologically redundant types in abixml

One source of duplicated type ids in ABI XML is the writer emitting
scoped (nested) typed declarations before a later TU causes the
emission of the complete enclosing type declaration.

This commit causes the outermost enclosing type declaration to be
emitted immediately.

	* src/abg-writer.cc: (write_decl_in_scope): Emit the enclosing
	types of any nested type declaration.
	* tests/data/test-annotate/test15-pr18892.so.abi: Refresh.
	* tests/data/test-annotate/test17-pr19027.so.abi: Refresh.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Refresh.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Refresh.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Refresh.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Refresh.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Refresh.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Refresh.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Refresh.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Refresh.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Refresh.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Refresh.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Refresh.

Signed-off-by: Giuliano Procida <gprocida@google.com>
  • Loading branch information
myxoid committed Apr 6, 2021
1 parent bf8b339 commit e127d89
Show file tree
Hide file tree
Showing 14 changed files with 23,570 additions and 21,752 deletions.
35 changes: 12 additions & 23 deletions src/abg-writer.cc
Expand Up @@ -1941,6 +1941,8 @@ write_decl(const decl_base_sptr& decl, write_context& ctxt, unsigned indent)

/// Emit a declaration, along with its scope.
///
/// If the scope includes another type declaration, emit that instead.
///
/// This function is called at the end of emitting a translation unit,
/// to emit type declarations that were referenced by types that were
/// emitted in the TU already, but that were not emitted themselves.
Expand Down Expand Up @@ -1972,6 +1974,7 @@ write_decl_in_scope(const decl_base_sptr& decl,
stack<string> closing_tags;
stack<unsigned> closing_indents;
unsigned indent = initial_indent;
bool done = false;
for (list<scope_decl*>::const_iterator i = scopes.begin();
i != scopes.end();
++i)
Expand All @@ -1987,43 +1990,29 @@ write_decl_in_scope(const decl_base_sptr& decl,
<< "'>\n";
closing_tags.push("</namespace-decl>");
closing_indents.push(indent);
indent += c.get_xml_element_indent();
continue;
}
// ... or a class.
else if (class_decl* c = is_class_type(*i))
if (class_decl* c = is_class_type(*i))
{
class_decl_sptr class_type(c, noop_deleter());
write_class_decl_opening_tag(class_type, "", ctxt, indent,
/*prepare_to_handle_members=*/false);
closing_tags.push("</class-decl>");
closing_indents.push(indent);

unsigned nb_ws = get_indent_to_level(ctxt, indent, 1);
write_member_type_opening_tag(type, ctxt, nb_ws);
indent = nb_ws;
closing_tags.push("</member-type>");
closing_indents.push(nb_ws);
write_class_decl(class_type, ctxt, indent);
done = true;
}
else if (union_decl *u = is_union_type(*i))
{
union_decl_sptr union_type(u, noop_deleter());
write_union_decl_opening_tag(union_type, "", ctxt, indent,
/*prepare_to_handle_members=*/false);
closing_tags.push("</union-decl>");
closing_indents.push(indent);

unsigned nb_ws = get_indent_to_level(ctxt, indent, 1);
write_member_type_opening_tag(type, ctxt, nb_ws);
indent = nb_ws;
closing_tags.push("</member-type>");
closing_indents.push(nb_ws);
write_union_decl(union_type, ctxt, indent);
done = true;
}
else
// We should never reach this point.
abort();
indent += c.get_xml_element_indent();
}

write_decl(decl, ctxt, indent);
if (!done)
write_decl(decl, ctxt, indent);

while (!closing_tags.empty())
{
Expand Down
134 changes: 108 additions & 26 deletions tests/data/test-annotate/test15-pr18892.so.abi

Large diffs are not rendered by default.

2,754 changes: 1,357 additions & 1,397 deletions tests/data/test-annotate/test17-pr19027.so.abi

Large diffs are not rendered by default.

2,270 changes: 1,349 additions & 921 deletions tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi

Large diffs are not rendered by default.

3,764 changes: 2,192 additions & 1,572 deletions tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi

Large diffs are not rendered by default.

251 changes: 112 additions & 139 deletions tests/data/test-read-dwarf/test-libandroid.so.abi

Large diffs are not rendered by default.

1,833 changes: 951 additions & 882 deletions tests/data/test-read-dwarf/test12-pr18844.so.abi

Large diffs are not rendered by default.

105 changes: 82 additions & 23 deletions tests/data/test-read-dwarf/test15-pr18892.so.abi
Expand Up @@ -2633,6 +2633,39 @@
</data-member>
</class-decl>
</member-type>
<data-member access='private' static='yes'>
<var-decl name='kMinSizeLog' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='90' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='kMidSizeLog' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='91' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='kMinSize' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='92' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='kMidSize' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='93' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='kMidClass' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='94' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='S' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='95' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='M' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='96' column='1'/>
</data-member>
<data-member access='public' static='yes'>
<var-decl name='kMaxNumCached' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='99' column='1'/>
</data-member>
<data-member access='public' static='yes'>
<var-decl name='kMaxSize' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='109' column='1'/>
</data-member>
<data-member access='public' static='yes'>
<var-decl name='kNumClasses' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='110' column='1'/>
</data-member>
<data-member access='public' static='yes'>
<var-decl name='kNumClassesRounded' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='113' column='1'/>
</data-member>
</class-decl>
</namespace-decl>
<namespace-decl name='__sanitizer'>
Expand Down Expand Up @@ -3580,30 +3613,23 @@
<member-type access='public'>
<typedef-decl name='Type' type-id='type-id-284' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_atomic.h' line='39' column='1' id='type-id-287'/>
</member-type>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='val_dont_use' type-id='type-id-292' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_atomic.h' line='40' column='1'/>
</data-member>
</class-decl>
</namespace-decl>
<namespace-decl name='__sanitizer'>
<typedef-decl name='u32' type-id='type-id-211' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_internal_defs.h' line='68' column='1' id='type-id-284'/>
</namespace-decl>
<type-decl name='unsigned short int' size-in-bits='16' id='type-id-279'/>
<pointer-type-def type-id='type-id-292' size-in-bits='64' id='type-id-281'/>
<pointer-type-def type-id='type-id-293' size-in-bits='64' id='type-id-286'/>
<pointer-type-def type-id='type-id-293' size-in-bits='64' id='type-id-281'/>
<pointer-type-def type-id='type-id-294' size-in-bits='64' id='type-id-286'/>
<typedef-decl name='uint64_t' type-id='type-id-33' filepath='/usr/include/stdint.h' line='56' column='1' id='type-id-290'/>
<array-type-def dimensions='1' type-id='type-id-19' size-in-bits='64' id='type-id-289'>
<subrange length='8' type-id='type-id-50' id='type-id-294'/>
<subrange length='8' type-id='type-id-50' id='type-id-295'/>
</array-type-def>
<qualified-type-def type-id='type-id-291' volatile='yes' id='type-id-293'/>
<namespace-decl name='__sanitizer'>
<class-decl name='atomic_uint32_t' size-in-bits='32' is-struct='yes' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_atomic.h' line='38' column='1' id='type-id-291'>
<member-type access='public'>
<typedef-decl name='Type' type-id='type-id-284' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_atomic.h' line='39' column='1' id='type-id-287'/>
</member-type>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='val_dont_use' type-id='type-id-295' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_atomic.h' line='40' column='1'/>
</data-member>
</class-decl>
</namespace-decl>
<qualified-type-def type-id='type-id-287' volatile='yes' id='type-id-295'/>
<qualified-type-def type-id='type-id-291' volatile='yes' id='type-id-294'/>
<qualified-type-def type-id='type-id-287' volatile='yes' id='type-id-292'/>
</abi-instr>
<abi-instr address-size='64' path='../../.././libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc' comp-dir-path='/tmp/legendre/spack-stage/spack-stage-ImG4Cf/gcc-4.9.2/x86_64-unknown-linux-gnu/libsanitizer/sanitizer_common' language='LANG_C_plus_plus'>
<array-type-def dimensions='1' type-id='type-id-5' size-in-bits='448' id='type-id-296'>
Expand Down Expand Up @@ -5970,6 +5996,39 @@
</data-member>
</class-decl>
</member-type>
<data-member access='private' static='yes'>
<var-decl name='kMinSizeLog' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='90' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='kMidSizeLog' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='91' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='kMinSize' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='92' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='kMidSize' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='93' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='kMidClass' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='94' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='S' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='95' column='1'/>
</data-member>
<data-member access='private' static='yes'>
<var-decl name='M' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='96' column='1'/>
</data-member>
<data-member access='public' static='yes'>
<var-decl name='kMaxNumCached' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='99' column='1'/>
</data-member>
<data-member access='public' static='yes'>
<var-decl name='kMaxSize' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='109' column='1'/>
</data-member>
<data-member access='public' static='yes'>
<var-decl name='kNumClasses' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='110' column='1'/>
</data-member>
<data-member access='public' static='yes'>
<var-decl name='kNumClassesRounded' type-id='type-id-131' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_allocator.h' line='113' column='1'/>
</data-member>
</class-decl>
</namespace-decl>
<namespace-decl name='__tsan'>
Expand Down Expand Up @@ -7082,7 +7141,7 @@
<subrange length='6' type-id='type-id-50' id='type-id-164'/>
</array-type-def>
<array-type-def dimensions='1' type-id='type-id-19' size-in-bits='64' id='type-id-289'>
<subrange length='8' type-id='type-id-50' id='type-id-294'/>
<subrange length='8' type-id='type-id-50' id='type-id-295'/>
</array-type-def>
<array-type-def dimensions='1' type-id='type-id-33' size-in-bits='1024' id='type-id-595'>
<subrange length='16' type-id='type-id-50' id='type-id-503'/>
Expand Down Expand Up @@ -7752,7 +7811,7 @@
<qualified-type-def type-id='type-id-1253' const='yes' id='type-id-1254'/>
<qualified-type-def type-id='type-id-1255' id='type-id-1256'/>
<reference-type-def kind='lvalue' type-id='type-id-1254' size-in-bits='64' id='type-id-1255'/>
<qualified-type-def type-id='type-id-293' const='yes' id='type-id-1257'/>
<qualified-type-def type-id='type-id-294' const='yes' id='type-id-1257'/>
<pointer-type-def type-id='type-id-1257' size-in-bits='64' id='type-id-1258'/>
<qualified-type-def type-id='type-id-598' const='yes' id='type-id-1259'/>
<pointer-type-def type-id='type-id-1259' size-in-bits='64' id='type-id-1260'/>
Expand Down Expand Up @@ -7914,7 +7973,7 @@
<pointer-type-def type-id='type-id-1412' size-in-bits='64' id='type-id-661'/>
<pointer-type-def type-id='type-id-1413' size-in-bits='64' id='type-id-1103'/>
<pointer-type-def type-id='type-id-1414' size-in-bits='64' id='type-id-1105'/>
<pointer-type-def type-id='type-id-292' size-in-bits='64' id='type-id-281'/>
<pointer-type-def type-id='type-id-293' size-in-bits='64' id='type-id-281'/>
<pointer-type-def type-id='type-id-1415' size-in-bits='64' id='type-id-636'/>
<pointer-type-def type-id='type-id-1416' size-in-bits='64' id='type-id-1417'/>
<pointer-type-def type-id='type-id-1418' size-in-bits='64' id='type-id-1107'/>
Expand All @@ -7932,9 +7991,9 @@
<pointer-type-def type-id='type-id-1431' size-in-bits='64' id='type-id-702'/>
<pointer-type-def type-id='type-id-1432' size-in-bits='64' id='type-id-700'/>
<pointer-type-def type-id='type-id-1433' size-in-bits='64' id='type-id-680'/>
<qualified-type-def type-id='type-id-291' volatile='yes' id='type-id-293'/>
<pointer-type-def type-id='type-id-293' size-in-bits='64' id='type-id-286'/>
<qualified-type-def type-id='type-id-287' volatile='yes' id='type-id-295'/>
<qualified-type-def type-id='type-id-291' volatile='yes' id='type-id-294'/>
<pointer-type-def type-id='type-id-294' size-in-bits='64' id='type-id-286'/>
<qualified-type-def type-id='type-id-287' volatile='yes' id='type-id-292'/>
<pointer-type-def type-id='type-id-598' size-in-bits='64' id='type-id-1434'/>
<namespace-decl name='std'>
<class-decl name='nothrow_t' size-in-bits='8' is-struct='yes' visibility='default' filepath='../../.././libsanitizer/tsan/tsan_interceptors.cc' line='108' column='1' id='type-id-1253'/>
Expand Down Expand Up @@ -8077,7 +8136,7 @@
<typedef-decl name='Type' type-id='type-id-284' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_atomic.h' line='39' column='1' id='type-id-287'/>
</member-type>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='val_dont_use' type-id='type-id-295' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_atomic.h' line='40' column='1'/>
<var-decl name='val_dont_use' type-id='type-id-292' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_atomic.h' line='40' column='1'/>
</data-member>
</class-decl>
<class-decl name='SuppressionContext' size-in-bits='256' visibility='default' filepath='../../.././libsanitizer/sanitizer_common/sanitizer_suppressions.h' line='37' column='1' id='type-id-233'>
Expand Down Expand Up @@ -15575,7 +15634,7 @@
<parameter type-id='type-id-1271' name='cos'/>
<return type-id='type-id-4'/>
</function-type>
<function-type size-in-bits='64' id='type-id-292'>
<function-type size-in-bits='64' id='type-id-293'>
<parameter type-id='type-id-10'/>
<return type-id='type-id-4'/>
</function-type>
Expand Down

0 comments on commit e127d89

Please sign in to comment.