Bug 27267 - Better support for opaque enum types

Upon a request to build the IR for a opaque enum type,
get_opaque_version_of_type wrongly returns a nil type even though the
code is in there to construct an opaque variant of the enum.

This patch cleans up that code to let it build an opaque enum type.
It also ensures the opaque enum type is properly added to its lexical
scope to ensure proper life cycle management.

	* src/abg-dwarf-reader.cc (get_opaque_version_of_type): Do not
	quit early for enum types, because the code that comes a bit later
	can handle enums.  Add the newly built enum to its scope for
	proper life cycle management.
	* tests/data/test-diff-suppr/PR27267/include-dir-v{0,1}/include.h: New
	include files for the input test library.
	* tests/data/test-diff-suppr/PR27267/libtestpr27267-v{0,1}.so: New
	input test library.
	* tests/data/test-diff-suppr/PR27267/report-1.txt: New reference
	output for the comparison.
	* tests/data/test-diff-suppr/PR27267/v{0,1}.c: Source code for the
	new input test library.
	* tests/data/Makefile.am: Add the new test material above to
	source distribution.
	* tests/test-diff-suppr.cc (in_out_specs): Add the new test input
	above to the test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2021-02-04 09:26:05 +01:00
parent 013a19c5fe
commit e5c7fd3400
10 changed files with 87 additions and 6 deletions

View File

@ -15906,12 +15906,6 @@ get_opaque_version_of_type(read_context &ctxt,
&& tag != DW_TAG_enumeration_type)
return result;
if (tag == DW_TAG_union_type)
// TODO: also handle declaration-only unions. To do that, we mostly
// need to adapt add_or_update_union_type to make it schedule
// declaration-only unions for resolution too.
return result;
string type_name, linkage_name;
location type_location;
die_loc_and_name(ctxt, type_die, type_location, type_name, linkage_name);
@ -15973,6 +15967,7 @@ get_opaque_version_of_type(read_context &ctxt,
underlying_type,
enumeratorz,
linkage_name));
add_decl_to_scope(enum_type, scope);
result = enum_type;
}
}

View File

@ -1482,6 +1482,13 @@ test-diff-suppr/libtest48-soname-abixml-suppr.txt \
test-diff-suppr/libtest48-soname-abixml-suppr-2.txt \
test-diff-suppr/libtest48-soname-abixml-suppr-3.txt \
test-diff-suppr/libtest48-soname-abixml-suppr-4.txt \
test-diff-suppr/PR27267/include-dir-v0/include.h \
test-diff-suppr/PR27267/include-dir-v1/include.h \
test-diff-suppr/PR27267/v0.c \
test-diff-suppr/PR27267/v1.c \
test-diff-suppr/PR27267/libtestpr27267-v0.so \
test-diff-suppr/PR27267/libtestpr27267-v1.so \
test-diff-suppr/PR27267/report-1.txt \
\
test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1 \
test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi \

View File

@ -0,0 +1,8 @@
enum opaque_enum;
struct opaque_struct;
typedef enum opaque_enum opaque_enum;
typedef struct opaque_struct opaque_struct;
void
fn(opaque_struct *, opaque_enum *e);

View File

@ -0,0 +1,8 @@
enum opaque_enum;
struct opaque_struct;
typedef enum opaque_enum opaque_enum;
typedef struct opaque_struct opaque_struct;
void
fn(opaque_struct *, opaque_enum *e);

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,25 @@
/**
*
* Compile with:
* gcc -shared -g -Wall -o libtestpr27267-v0.so v0.c
*
*/
#include "include-dir-v0/include.h"
enum opaque_enum
{
e0,
e1
};
struct opaque_struct
{
opaque_enum m0;
};
void
fn(opaque_struct * s, opaque_enum *e)
{
s->m0 = *e;
}

View File

@ -0,0 +1,28 @@
/**
*
* Compile with:
* gcc -shared -g -Wall -o libtestpr27267-v1.so v1.c
*
*/
#include "include-dir-v1/include.h"
enum opaque_enum
{
e0,
e1,
e2
};
struct opaque_struct
{
opaque_enum m0;
opaque_enum m1;
};
void
fn(opaque_struct * s, opaque_enum *e)
{
s->m0 = *e;
s->m1 = s->m0;
}

View File

@ -2026,6 +2026,16 @@ InOutSpec in_out_specs[] =
"data/test-diff-suppr/libtest48-soname-abixml-report-1.txt",
"output/test-diff-suppr/libtest48-soname-abixml-report-1_suppr4.txt"
},
{
"data/test-diff-suppr/PR27267/libtestpr27267-v0.so",
"data/test-diff-suppr/PR27267/libtestpr27267-v1.so",
"data/test-diff-suppr/PR27267/include-dir-v0",
"data/test-diff-suppr/PR27267/include-dir-v1",
"",
"--drop-private-types --no-default-suppression",
"data/test-diff-suppr/PR27267/report-1.txt",
"output/test-diff-suppr/PR27267/report-1.txt"
},
// This should be the last entry
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
};