Avoid a couple more ICEs in print_mem_ref (PR c/98597).
Resolves: PR c/98597 - ICE in -Wuninitialized printing a MEM_REF PR c/98592 - ICE in gimple_canonical_types_compatible_p while formatting gcc/c-family/ChangeLog: PR c/98597 PR c/98592 * c-pretty-print.c (print_mem_ref): Avoid assuming MEM_REF operand has pointer type. Remove redundant code. Avoid calling gimple_canonical_types_compatible_p. gcc/testsuite/ChangeLog: PR c/98597 PR c/98592 * g++.dg/warn/Wuninitialized-13.C: New test. gcc.dg/uninit-39.c: New test. #
This commit is contained in:
parent
728fee7a79
commit
5a9cfad2de
3 changed files with 79 additions and 6 deletions
|
@ -1847,10 +1847,11 @@ print_mem_ref (c_pretty_printer *pp, tree e)
|
|||
tree access_type = TREE_TYPE (e);
|
||||
if (TREE_CODE (access_type) == ARRAY_TYPE)
|
||||
access_type = TREE_TYPE (access_type);
|
||||
tree arg_type = TREE_TYPE (TREE_TYPE (arg));
|
||||
tree arg_type = TREE_TYPE (arg);
|
||||
if (POINTER_TYPE_P (arg_type))
|
||||
arg_type = TREE_TYPE (arg_type);
|
||||
if (TREE_CODE (arg_type) == ARRAY_TYPE)
|
||||
arg_type = TREE_TYPE (arg_type);
|
||||
|
||||
if (tree access_size = TYPE_SIZE_UNIT (access_type))
|
||||
if (TREE_CODE (access_size) == INTEGER_CST)
|
||||
{
|
||||
|
@ -1866,16 +1867,13 @@ print_mem_ref (c_pretty_printer *pp, tree e)
|
|||
|
||||
/* True to include a cast to the accessed type. */
|
||||
const bool access_cast = VOID_TYPE_P (arg_type)
|
||||
|| !gimple_canonical_types_compatible_p (access_type, arg_type);
|
||||
|| TYPE_MAIN_VARIANT (access_type) != TYPE_MAIN_VARIANT (arg_type);
|
||||
|
||||
if (byte_off != 0)
|
||||
{
|
||||
/* When printing the byte offset for a pointer to a type of
|
||||
a different size than char, include a cast to char* first,
|
||||
before printing the cast to a pointer to the accessed type. */
|
||||
tree arg_type = TREE_TYPE (TREE_TYPE (arg));
|
||||
if (TREE_CODE (arg_type) == ARRAY_TYPE)
|
||||
arg_type = TREE_TYPE (arg_type);
|
||||
offset_int arg_size = 0;
|
||||
if (tree size = TYPE_SIZE (arg_type))
|
||||
arg_size = wi::to_offset (size);
|
||||
|
|
28
gcc/testsuite/g++.dg/warn/Wuninitialized-13.C
Normal file
28
gcc/testsuite/g++.dg/warn/Wuninitialized-13.C
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* PR c/98597 - ICE in -Wuninitialized printing a MEM_REF
|
||||
{ dg-do compile }
|
||||
{ dg-options "-O2 -Wall" } */
|
||||
|
||||
struct shared_count {
|
||||
shared_count () { }
|
||||
shared_count (shared_count &r)
|
||||
: pi (r.pi) { } // { dg-warning "\\\[-Wuninitialized" }
|
||||
int pi;
|
||||
};
|
||||
|
||||
// There's another (redundant) -Wuninitialized on the line below.
|
||||
struct shared_ptr {
|
||||
int ptr;
|
||||
shared_count refcount;
|
||||
};
|
||||
|
||||
struct Bar {
|
||||
Bar (int, shared_ptr);
|
||||
};
|
||||
|
||||
void g () {
|
||||
shared_ptr foo;
|
||||
Bar (0, foo);
|
||||
}
|
||||
|
||||
// Prune out duplicates.
|
||||
// { dg-prune-output "-Wuninitialized" }
|
47
gcc/testsuite/gcc.dg/uninit-39.c
Normal file
47
gcc/testsuite/gcc.dg/uninit-39.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* PR c/98592 - ICE in gimple_canonical_types_compatible_p while formatting
|
||||
a MEM_REF
|
||||
{ dg-do compile }
|
||||
{ dg-options "-O2 -Wall" } */
|
||||
|
||||
void f (int);
|
||||
|
||||
void vlaNx3_to_pia1 (int n)
|
||||
{
|
||||
int a[n][3];
|
||||
|
||||
/* The VLA isn't formatted correctly due to PR 98587. Just verify
|
||||
there is no ICE and a warning is issued. */
|
||||
f (((*(int(*)[4])&a[1][2]))[3]); // { dg-warning "\\\[-Wuninitialized" }
|
||||
}
|
||||
|
||||
void vlaNxN_to_pia1 (int n)
|
||||
{
|
||||
int a[n][n];
|
||||
|
||||
/* Same as above. */
|
||||
f (((*(int(*)[4])&a[1][2]))[3]); // { dg-warning "\\\[-Wuninitialized" }
|
||||
}
|
||||
|
||||
void vlaNxN_to_pvla4xN (int n)
|
||||
{
|
||||
int a[n][n];
|
||||
|
||||
/* Same as above. */
|
||||
f (((*(int(*)[4][n])&a[1][2]))[3][4]); // { dg-warning "\\\[-Wuninitialized" }
|
||||
}
|
||||
|
||||
void vlaN_to_pia2 (int n)
|
||||
{
|
||||
int a[n];
|
||||
|
||||
/* Same as above. */
|
||||
f (((*(int(*)[3][4])&a[1]))[2][3]); // { dg-warning "\\\[-Wuninitialized" }
|
||||
}
|
||||
|
||||
void vlaN_to_pvlaNx4 (int n)
|
||||
{
|
||||
int a[n];
|
||||
|
||||
/* Same as above. */
|
||||
f (((*(int(*)[n][4])&a[1]))[1][3]); // { dg-warning "\\\[-Wuninitialized" }
|
||||
}
|
Loading…
Add table
Reference in a new issue