Commit e78bede6 by Marek Polacek Committed by Marek Polacek

re PR c/68107 (Non-VLA type whose size is half or more of the address space…

re PR c/68107 (Non-VLA type whose size is half or more of the address space constructed via a pointer)

	PR c/68107
	PR c++/68266
	* c-common.c (valid_array_size_p): New function.
	* c-common.h (valid_array_size_p): Declare.

	* c-decl.c (grokdeclarator): Call valid_array_size_p.  Remove code
	checking the size of an array.

	* decl.c (grokdeclarator): Call valid_array_size_p.  Remove code
	checking the size of an array.

	* c-c++-common/pr68107.c: New test.
	* g++.dg/init/new38.C (large_array_char): Adjust dg-error.
	(large_array_char_template): Likewise.
	* g++.dg/init/new44.C: Adjust dg-error.

From-SVN: r230174
parent a5b50aa1
2015-11-11 Marek Polacek <polacek@redhat.com>
PR c/68107
PR c++/68266
* c-common.c (valid_array_size_p): New function.
* c-common.h (valid_array_size_p): Declare.
2015-11-11 Dominique d'Humieres <dominiq@lps.ens.fr>
PR bootstrap/68271
......
......@@ -13107,4 +13107,26 @@ warn_duplicated_cond_add_or_warn (location_t loc, tree cond, vec<tree> **chain)
(*chain)->safe_push (cond);
}
/* Check if array size calculations overflow or if the array covers more
than half of the address space. Return true if the size of the array
is valid, false otherwise. TYPE is the type of the array and NAME is
the name of the array, or NULL_TREE for unnamed arrays. */
bool
valid_array_size_p (location_t loc, tree type, tree name)
{
if (type != error_mark_node
&& COMPLETE_TYPE_P (type)
&& TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
&& !valid_constant_size_p (TYPE_SIZE_UNIT (type)))
{
if (name)
error_at (loc, "size of array %qE is too large", name);
else
error_at (loc, "size of unnamed array is too large");
return false;
}
return true;
}
#include "gt-c-family-c-common.h"
......@@ -1463,5 +1463,6 @@ extern bool check_no_cilk (tree, const char *, const char *,
location_t loc = UNKNOWN_LOCATION);
extern bool reject_gcc_builtin (const_tree, location_t = UNKNOWN_LOCATION);
extern void warn_duplicated_cond_add_or_warn (location_t, tree, vec<tree> **);
extern bool valid_array_size_p (location_t, tree, tree);
#endif /* ! GCC_C_COMMON_H */
2015-11-11 Marek Polacek <polacek@redhat.com>
PR c/68107
PR c++/68266
* c-decl.c (grokdeclarator): Call valid_array_size_p. Remove code
checking the size of an array.
2015-11-11 Andrew MacLeod <amacleod@redhat.com>
* c-array-notation.c: Remove unused header files.
......
......@@ -6000,6 +6000,9 @@ grokdeclarator (const struct c_declarator *declarator,
TYPE_SIZE_UNIT (type) = size_zero_node;
SET_TYPE_STRUCTURAL_EQUALITY (type);
}
if (!valid_array_size_p (loc, type, name))
type = error_mark_node;
}
if (decl_context != PARM
......@@ -6007,7 +6010,8 @@ grokdeclarator (const struct c_declarator *declarator,
|| array_ptr_attrs != NULL_TREE
|| array_parm_static))
{
error_at (loc, "static or type qualifiers in non-parameter array declarator");
error_at (loc, "static or type qualifiers in non-parameter "
"array declarator");
array_ptr_quals = TYPE_UNQUALIFIED;
array_ptr_attrs = NULL_TREE;
array_parm_static = 0;
......@@ -6286,22 +6290,6 @@ grokdeclarator (const struct c_declarator *declarator,
}
}
/* Did array size calculations overflow or does the array cover more
than half of the address-space? */
if (TREE_CODE (type) == ARRAY_TYPE
&& COMPLETE_TYPE_P (type)
&& TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
&& ! valid_constant_size_p (TYPE_SIZE_UNIT (type)))
{
if (name)
error_at (loc, "size of array %qE is too large", name);
else
error_at (loc, "size of unnamed array is too large");
/* If we proceed with the array type as it is, we'll eventually
crash in tree_to_[su]hwi(). */
type = error_mark_node;
}
/* If this is declaring a typedef name, return a TYPE_DECL. */
if (storage_class == csc_typedef)
......
2015-11-11 Marek Polacek <polacek@redhat.com>
PR c/68107
PR c++/68266
* decl.c (grokdeclarator): Call valid_array_size_p. Remove code
checking the size of an array.
2015-11-11 Dominique d'Humieres <dominiq@lps.ens.fr>
PR bootstrap/68271
......
......@@ -9939,6 +9939,9 @@ grokdeclarator (const cp_declarator *declarator,
case cdk_array:
type = create_array_type_for_decl (dname, type,
declarator->u.array.bounds);
if (!valid_array_size_p (input_location, type, dname))
type = error_mark_node;
if (declarator->std_attributes)
/* [dcl.array]/1:
......@@ -10502,19 +10505,6 @@ grokdeclarator (const cp_declarator *declarator,
error ("non-parameter %qs cannot be a parameter pack", name);
}
/* Did array size calculations overflow or does the array cover more
than half of the address-space? */
if (TREE_CODE (type) == ARRAY_TYPE
&& COMPLETE_TYPE_P (type)
&& TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
&& ! valid_constant_size_p (TYPE_SIZE_UNIT (type)))
{
error ("size of array %qs is too large", name);
/* If we proceed with the array type as it is, we'll eventually
crash in tree_to_[su]hwi(). */
type = error_mark_node;
}
if ((decl_context == FIELD || decl_context == PARM)
&& !processing_template_decl
&& variably_modified_type_p (type, NULL_TREE))
......
2015-11-11 Marek Polacek <polacek@redhat.com>
PR c/68107
PR c++/68266
* c-c++-common/pr68107.c: New test.
* g++.dg/init/new38.C (large_array_char): Adjust dg-error.
(large_array_char_template): Likewise.
* g++.dg/init/new44.C: Adjust dg-error.
2015-11-11 Nathan Sidwell <nathan@codesourcery.com>
* gfortran.dg/goacc/private-3.f95: Remove xfail.
......
/* PR c/68107 */
/* { dg-do compile } */
#define N ((__SIZE_MAX__ / sizeof (int)) / 2 + 1)
typedef int (*T1)[N]; /* { dg-error "too large" } */
typedef int (*T2)[N - 1];
typedef int (*T3)[N][N]; /* { dg-error "too large" } */
typedef int (*T4)[N - 1][N - 1]; /* { dg-error "too large" } */
typedef int (**T5)[N]; /* { dg-error "too large" } */
struct S {
int (*q1)[N]; /* { dg-error "too large" } */
int (*q2)[N - 1];
int (*q3)[N][N]; /* { dg-error "too large" } */
int (*q4)[N - 1][N - 1]; /* { dg-error "too large" } */
int (**q5)[N]; /* { dg-error "too large" } */
};
void fn1 (int (*p1)[N]); /* { dg-error "too large" } */
void fn2 (int (*p1)[N - 1]);
void fn3 (int (*p3)[N][N]); /* { dg-error "too large" } */
void fn4 (int (*p4)[N - 1][N - 1]); /* { dg-error "too large" } */
void fn5 (int (**p5)[N]); /* { dg-error "too large" } */
void
fn (void)
{
int (*n1)[N]; /* { dg-error "too large" } */
int (*n2)[N - 1];
int (*n3)[N][N]; /* { dg-error "too large" } */
int (*n4)[N - 1][N - 1]; /* { dg-error "too large" } */
int (**n5)[N]; /* { dg-error "too large" } */
sizeof (int (*)[N]); /* { dg-error "too large" } */
sizeof (int [N]); /* { dg-error "too large" } */
}
......@@ -5,7 +5,7 @@ large_array_char(int n)
{
new char[n]
[1ULL << (sizeof(void *) * 4)]
[1ULL << (sizeof(void *) * 4)]; // { dg-error "size of array" }
[1ULL << (sizeof(void *) * 4)]; // { dg-error "size of unnamed array" }
}
template <typename T>
......@@ -14,7 +14,7 @@ large_array_char_template(int n)
{
new char[n]
[1ULL << (sizeof(void *) * 4)]
[1ULL << (sizeof(void *) * 4)]; // { dg-error "size of array" }
[1ULL << (sizeof(void *) * 4)]; // { dg-error "size of unnamed array" }
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment