773ec47fe6
PR c/6940 * doc/invoke.texi: Document -Wsizeof-array-argument. c-family/ * c.opt (Wsizeof-array-argument): New option. c/ * c-decl.c (grokdeclarator): Set C_ARRAY_PARAMETER. * c-tree.h (C_ARRAY_PARAMETER): Define. * c-typeck.c (c_expr_sizeof_expr): Warn when using sizeof on an array function parameter. cp/ * cp-tree.h (DECL_ARRAY_PARAMETER_P): Define. * decl.c (grokdeclarator): Set DECL_ARRAY_PARAMETER_P. * typeck.c (cxx_sizeof_expr): Warn when using sizeof on an array function parameter. testsuite/ * c-c++-common/Wsizeof-pointer-memaccess1.c: Use -Wno-sizeof-array-argument. * c-c++-common/Wsizeof-pointer-memaccess2.c: Likewise. * g++.dg/warn/Wsizeof-pointer-memaccess-1.C: Likewise. * gcc.dg/Wsizeof-pointer-memaccess1.c: Likewise. * g++.dg/torture/Wsizeof-pointer-memaccess1.C: Likewise. * g++.dg/torture/Wsizeof-pointer-memaccess2.C: Likewise. * gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Likewise. * c-c++-common/sizeof-array-argument.c: New test. * gcc.dg/vla-5.c: Add dg-warnings. ../libgomp/ * testsuite/libgomp.c/appendix-a/a.29.1.c (f): Add dg-warnings. From-SVN: r212312
31 lines
760 B
C
31 lines
760 B
C
/* { dg-do run } */
|
|
|
|
#include <assert.h>
|
|
int A[2][2] = { 1, 2, 3, 4 };
|
|
void
|
|
f (int n, int B[n][n], int C[])
|
|
{
|
|
int D[2][2] = { 1, 2, 3, 4 };
|
|
int E[n][n];
|
|
assert (n >= 2);
|
|
E[1][1] = 4;
|
|
#pragma omp parallel firstprivate(B, C, D, E)
|
|
{
|
|
assert (sizeof (B) == sizeof (int (*)[n])); /* { dg-warning "on array function parameter" } */
|
|
assert (sizeof (C) == sizeof (int *)); /* { dg-warning "on array function parameter" } */
|
|
assert (sizeof (D) == 4 * sizeof (int));
|
|
assert (sizeof (E) == n * n * sizeof (int));
|
|
/* Private B and C have values of original B and C. */
|
|
assert (&B[1][1] == &A[1][1]);
|
|
assert (&C[3] == &A[1][1]);
|
|
assert (D[1][1] == 4);
|
|
assert (E[1][1] == 4);
|
|
}
|
|
}
|
|
int
|
|
main ()
|
|
{
|
|
f (2, A, A[0]);
|
|
return 0;
|
|
}
|