}
}
- const tree access_type = TREE_TYPE (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));
if (TREE_CODE (arg_type) == ARRAY_TYPE)
arg_type = TREE_TYPE (arg_type);
if (tree access_size = TYPE_SIZE_UNIT (access_type))
- {
- /* For naturally aligned accesses print the nonzero offset
- in units of the accessed type, in the form of an index.
- For unaligned accesses also print the residual byte offset. */
- offset_int asize = wi::to_offset (access_size);
- offset_int szlg2 = wi::floor_log2 (asize);
-
- elt_idx = byte_off >> szlg2;
- byte_off = byte_off - (elt_idx << szlg2);
- }
+ if (TREE_CODE (access_size) == INTEGER_CST)
+ {
+ /* For naturally aligned accesses print the nonzero offset
+ in units of the accessed type, in the form of an index.
+ For unaligned accesses also print the residual byte offset. */
+ offset_int asize = wi::to_offset (access_size);
+ offset_int szlg2 = wi::floor_log2 (asize);
+
+ elt_idx = byte_off >> szlg2;
+ byte_off = byte_off - (elt_idx << szlg2);
+ }
/* True to include a cast to the accessed type. */
const bool access_cast = VOID_TYPE_P (arg_type)
}
if (elt_idx != 0)
{
- if (byte_off == 0 && char_cast)
+ if (access_cast || char_cast)
pp_c_right_paren (pp);
- pp_c_right_paren (pp);
+
if (addr)
{
pp_space (pp);
--- /dev/null
+/* PR middle-end/98578 - ICE warning on uninitialized VLA access
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+void* malloc (__SIZE_TYPE__);
+
+void T (int, ...);
+
+void vla_n (int n, int i)
+{
+ int a1[n];
+
+ /* a1[I] should be formatted as as a1[I] (or, for I == 0, perhaps
+ as *a1), but definitely not as *a1[I]. This is a bug in VLA
+ formatting. */
+ T (a1[0]); // { dg-warning "'a1\\\[0]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "'\\*a1\\\[0]' is used uninitialized" "spurious star" { target *-*-* } .-1 }
+ T (a1[1]); // { dg-warning "a1\\\[1]' is used uninitialized" }
+ T (a1[i]); // { dg-warning "a1\\\[i]' is used uninitialized" }
+}
+
+void vla_n_2 (int n, int i)
+{
+ int a2[n][2];
+
+ T (a2[0][0]); // { dg-warning "a2\\\[0]\\\[0]' is used uninitialized" }
+ T (a2[2][1]); // { dg-warning "a2\\\[2]\\\[1]' is used uninitialized" }
+ T (a2[3][i]); // { dg-warning "a2\\\[3]\\\[i]' is used uninitialized" }
+ T (a2[i][0]); // { dg-warning "a2\\\[i]\\\[0]' is used uninitialized" }
+ T (a2[i][i]); // { dg-warning "a2\\\[i]\\\[i]' is used uninitialized" }
+}
+
+
+void vla_3_n (int n, int i)
+{
+ int a2[3][n];
+
+ T (a2[0][0]); // { dg-warning "a2\\\[0]\\\[0]' is used uninitialized" }
+ T (a2[1][2]); // { dg-warning "a2\\\[1]\\\[2]' is used uninitialized" }
+ T (a2[2][i]); // { dg-warning "a2\\\[2]\\\[i]' is used uninitialized" }
+ T (a2[i][3]); // { dg-warning "a2\\\[i]\\\[3]' is used uninitialized" }
+ T (a2[i][i]); // { dg-warning "a2\\\[i]\\\[i]' is used uninitialized" }
+}
+
+
+void vla_n_n (int n, int i)
+{
+ int a2[n][n];
+
+ T (a2[0][0]); // { dg-warning "a2\\\[0]\\\[0]' is used uninitialized" }
+ T (a2[4][5]); // { dg-warning "a2\\\[4]\\\[5]' is used uninitialized" }
+ T (a2[6][i]); // { dg-warning "a2\\\[6]\\\[i]' is used uninitialized" }
+ T (a2[i][7]); // { dg-warning "a2\\\[i]\\\[7]' is used uninitialized" }
+ T (a2[i][i]); // { dg-warning "a2\\\[i]\\\[i]' is used uninitialized" }
+}
+
+
+void char_ptr_n (int n, int i)
+{
+ char *p = malloc (n);
+
+ T (p[0]); // { dg-warning "'\\\*p' is used uninitialized" }
+ T (p[1]); // { dg-warning "'p\\\[1]' is used uninitialized" }
+ T (p[i]); // { dg-warning "'p\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "is used uninitialized" "POINTER_PLUS_EXPR" { target *-*-* } .-1 }
+}
+
+
+void int_ptr_n (int n, int i)
+{
+ int *p = malloc (n);
+
+ T (p[0]); // { dg-warning "'\\\*p' is used uninitialized" }
+ T (p[1]); // { dg-warning "'p\\\[1]' is used uninitialized" }
+ T (p[i]); // { dg-warning "'p\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "is used uninitialized" "POINTER_PLUS_EXPR" { target *-*-* } .-1 }
+}
+
+
+void int_arr_ptr_n (int n, int i)
+{
+ int (*p)[n] = malloc (n);
+
+ T ((*p)[0]); // { dg-warning "\\(\\*p\\)\\\[0]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[0]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[1]); // { dg-warning "\\(\\*p\\)\\\[1]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[1]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[i]); // { dg-warning "\\(\\*p\\)\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+}
+
+
+void int_arr_ptr_n_n (int n, int i)
+{
+ int (*p)[n][n] = malloc (n);
+
+ T ((*p)[0][0]); // { dg-warning "\\(\\*p\\)\\\[0]\\\[0]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[0]\\\[0]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[1][2]); // { dg-warning "\\(\\*p\\)\\\[1]\\\[2]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[1]\\\[2]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[0][i]); // { dg-warning "\\(\\*p\\)\\\[0]\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[0]\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[3][i]); // { dg-warning "\\(\\*p\\)\\\[3]\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[3]\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+ T ((*p)[i][i]); // { dg-warning "\\(\\*p\\)\\\[i]\\\[i]' is used uninitialized" "pr98587" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[i]\\\[i]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+
+ T ((*p)[i][i + 1]); // { dg-warning "\\(\\*p\\)\\\[i]\\\[i \\+ 1]' is used uninitialized" "pr98588" { xfail *-*-* } }
+ // { dg-warning "\\*p\\\[i]\\\[<unknown>]' is used uninitialized" "missing parens" { target *-*-* } .-1 }
+}