From 55b3d665057ac473e8a40cd35614fd7896c5c08c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 1 Oct 2001 09:18:49 -0400 Subject: [PATCH] decl.c (grokdeclarator): Copy array typedef handling from C frontend. * decl.c (grokdeclarator): Copy array typedef handling from C frontend. * decl.c (grokdeclarator): Copy too-large array handling from C frontend. * stor-layout.c (layout_type): Don't complain about too-large array here. From-SVN: r45923 --- gcc/ChangeLog | 5 +++++ gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/decl.c | 17 +++++++++++++++-- gcc/stor-layout.c | 20 -------------------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8993b5ac05b..a2247bd4778 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2001-10-01 Jason Merrill + + * stor-layout.c (layout_type): Don't complain about too-large + array here. + Mon Oct 1 06:43:41 2001 Richard Kenner * function.c (keep_stack_depressed): Don't use delete_insn. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 44cfc47daf1..b65644ad058 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2001-10-01 Jason Merrill + + * decl.c (grokdeclarator): Copy array typedef handling from C + frontend. + + * decl.c (grokdeclarator): Copy too-large array handling from C + frontend. + 2001-09-29 Alexandre Oliva * config-lang.in (target_libs): Added target-gperf, so that we diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 0402d77edd4..dc4eb8116e9 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10888,6 +10888,18 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* Now TYPE has the actual type. */ + /* Did array size calculations overflow? */ + + if (TREE_CODE (type) == ARRAY_TYPE + && COMPLETE_TYPE_P (type) + && TREE_OVERFLOW (TYPE_SIZE (type))) + { + error ("size of array `%s' is too large", name); + /* If we proceed with the array type as it is, we'll eventully + crash in tree_low_cst(). */ + type = error_mark_node; + } + if (explicitp == 1 || (explicitp && friendp)) { /* [dcl.fct.spec] The explicit specifier shall only be used in @@ -11037,8 +11049,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) a distinct type, so that each identifier's size can be controlled separately by its own initializer. */ - if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE - && TYPE_DOMAIN (type) == NULL_TREE) + if (type != 0 && typedef_type != 0 + && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0 + && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)) { type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); } diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 57b839f7724..3ff8726b1a3 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -1443,26 +1443,6 @@ layout_type (type) if (TYPE_SIZE_UNIT (element) != 0 && ! integer_onep (element_size)) TYPE_SIZE_UNIT (type) = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (element), length); - - /* Complain if the user has requested an array too large to - fit in size_t. - - ??? Disable this test for signed sizetypes. This has the effect - of disabling it for Ada, where it will cause trouble. However, - this test doesn't make sense for C either since there should - be no problem with a type whose size overflows, only an - object whose size overflows. */ - if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST - && TREE_OVERFLOW (TYPE_SIZE (type)) - && TREE_UNSIGNED (TREE_TYPE (TYPE_SIZE (type)))) - { - error ("requested array too large for target"); - - /* Avoid crashing later. */ - TYPE_SIZE (type) = element_size; - if (TYPE_SIZE_UNIT (type)) - TYPE_SIZE_UNIT (type) = TYPE_SIZE_UNIT (element); - } } /* Now round the alignment and size,