Fix crash with GNAT minimal encodings

Running the AdaCore internal test suite with -fgnat-encodings=minimal
found a gdb crash.  The bug is that GDB ends up with a typedef in
ada_index_type, resulting in a NULL dereference.

This crash can be reproduced using GCC 11 with the included test case.

Tested on x86-64 Fedora 32.  Because this is Ada-specific, and was
already reviewed by Joel, I am going to check it in.

2021-04-30  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_index_type): Use ada_check_typedef.

gdb/testsuite/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/enum_idx_packed/pck.ads (My_Enum, My_Array_Type)
	(Confused_Array): New types.
	* gdb.ada/enum_idx_packed/foo.adb (Confused_Array): New variable.
	* gdb.ada/enum_idx_packed.exp: Add new tests.
This commit is contained in:
Tom Tromey
2021-04-15 08:54:06 -06:00
parent d1fbc3ba09
commit 2869ac4b59
6 changed files with 28 additions and 2 deletions

View File

@@ -2877,8 +2877,11 @@ ada_index_type (struct type *type, int n, const char *name)
int i;
for (i = 1; i < n; i += 1)
type = TYPE_TARGET_TYPE (type);
result_type = TYPE_TARGET_TYPE (type->index_type ());
{
type = ada_check_typedef (type);
type = TYPE_TARGET_TYPE (type);
}
result_type = TYPE_TARGET_TYPE (ada_check_typedef (type)->index_type ());
/* FIXME: The stabs type r(0,0);bound;bound in an array type
has a target type of TYPE_CODE_UNDEF. We compensate here, but
perhaps stabsread.c would make more sense. */