From 8f6e6bf375959dc0c4aad0df8374af715dd2e440 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Mon, 4 Dec 2006 07:47:32 +0000 Subject: [PATCH] tree.c (walk_type_fields): Do not handle TYPE_MIN_VALUE and TYPE_MAX_VALUE for scalar types here but... * tree.c (walk_type_fields): Do not handle TYPE_MIN_VALUE and TYPE_MAX_VALUE for scalar types here but... (walk_tree): ...there instead. Return NULL_TREE if the TYPE_DECL is attached an error mark, and the return value of the callback if it is not NULL_TREE. cp/ * pt.c (for_each_template_parm_r) : New case. Call for_each_template_parm on TYPE_MIN_VALUE and TYPE_MAX_VALUE. testsuite/ * gnat.dg/pointer_variable_bounds.adb: New test. * gnat.dg/pointer_variable_bounds.ads: Likewise. * gnat.dg/pointer_variable_bounds_q.ads: Likewise. From-SVN: r119481 --- gcc/ChangeLog | 8 ++++ gcc/cp/ChangeLog | 5 +++ gcc/cp/pt.c | 8 ++++ gcc/testsuite/ChangeLog | 6 +++ .../gnat.dg/pointer_variable_bounds.adb | 26 ++++++++++++ .../gnat.dg/pointer_variable_bounds.ads | 16 +++++++ .../gnat.dg/pointer_variable_bounds_q.ads | 6 +++ gcc/tree.c | 42 +++++++++++-------- 8 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/pointer_variable_bounds.adb create mode 100644 gcc/testsuite/gnat.dg/pointer_variable_bounds.ads create mode 100644 gcc/testsuite/gnat.dg/pointer_variable_bounds_q.ads diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e0b7813136c..0a0984d96da 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2006-12-04 Eric Botcazou + + * tree.c (walk_type_fields): Do not handle TYPE_MIN_VALUE and + TYPE_MAX_VALUE for scalar types here but... + (walk_tree): ...there instead. Return NULL_TREE if the TYPE_DECL + is attached an error mark, and the return value of the callback + if it is not NULL_TREE. + 2006-12-04 Ben Elliston * config/spu/spu.md (_mulv4si3): Remove unused local variables. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7e482c01e1d..cf577f0d9f8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2006-12-04 Eric Botcazou + + * pt.c (for_each_template_parm_r) : New case. + Call for_each_template_parm on TYPE_MIN_VALUE and TYPE_MAX_VALUE. + 2006-12-03 Richard Henderson Andrew Pinski diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2f4e8996839..0b8eecac3ff 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4958,6 +4958,14 @@ for_each_template_parm_r (tree *tp, int *walk_subtrees, void *d) return error_mark_node; break; + case INTEGER_TYPE: + if (for_each_template_parm (TYPE_MIN_VALUE (t), + fn, data, pfd->visited) + || for_each_template_parm (TYPE_MAX_VALUE (t), + fn, data, pfd->visited)) + return error_mark_node; + break; + case METHOD_TYPE: /* Since we're not going to walk subtrees, we have to do this explicitly here. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index db198ec418a..c4608158535 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-12-04 Eric Botcazou + + * gnat.dg/pointer_variable_bounds.adb: New test. + * gnat.dg/pointer_variable_bounds.ads: Likewise. + * gnat.dg/pointer_variable_bounds_q.ads: Likewise. + 2006-12-03 Eric Christopher * gcc.target/i386/stack-prot-kernel.c: Skip for x86_64-*-darwin. diff --git a/gcc/testsuite/gnat.dg/pointer_variable_bounds.adb b/gcc/testsuite/gnat.dg/pointer_variable_bounds.adb new file mode 100644 index 00000000000..5cc838a383e --- /dev/null +++ b/gcc/testsuite/gnat.dg/pointer_variable_bounds.adb @@ -0,0 +1,26 @@ +-- { dg-do compile } +-- { dg-options "-gnatws" } + +package body pointer_variable_bounds is + + function COMPONENT_DAT(BP : in BUNDLE_POINTER_TYPE; CP : in COMP_POINTER_TYPE) return HALF_INTEGER is + type CP_TYPE is access COMP_POINTER_TYPE; + type CD_TYPE is access HALF_INTEGER; + CD : CD_TYPE; + begin + return CD.all; + end; + + procedure BUNDLE_DAT(BP : in BUNDLE_POINTER_TYPE) is + N0 : C_POINTER_TYPE := COMPONENT_DAT(BP, 4); + begin + null; + end; + + procedure SEQUENCE_DAT(BP : in BUNDLE_POINTER_TYPE) is + N0 : C_POINTER_TYPE := COMPONENT_DAT(BP, 4); + begin + null; + end; + +end pointer_variable_bounds; diff --git a/gcc/testsuite/gnat.dg/pointer_variable_bounds.ads b/gcc/testsuite/gnat.dg/pointer_variable_bounds.ads new file mode 100644 index 00000000000..b18c354077d --- /dev/null +++ b/gcc/testsuite/gnat.dg/pointer_variable_bounds.ads @@ -0,0 +1,16 @@ +with pointer_variable_bounds_q; use pointer_variable_bounds_q; + +package pointer_variable_bounds is + + type HALF_INTEGER is range -32768 .. 32767; + subtype HALF_NATURAL is HALF_INTEGER range 0 .. 32767; + + MAX_COMPS : constant HALF_NATURAL := HALF_NATURAL(A_MAX_COMPS); + subtype COMP_POINTER_TYPE is HALF_NATURAL range 0 .. MAX_COMPS; + subtype BUNDLE_POINTER_TYPE is HALF_NATURAL range 0 .. 1; + subtype C_POINTER_TYPE is HALF_NATURAL range 0 .. 1; + + procedure BUNDLE_DAT(BP : in BUNDLE_POINTER_TYPE); + procedure SEQUENCE_DAT(BP : in BUNDLE_POINTER_TYPE); + +end pointer_variable_bounds; diff --git a/gcc/testsuite/gnat.dg/pointer_variable_bounds_q.ads b/gcc/testsuite/gnat.dg/pointer_variable_bounds_q.ads new file mode 100644 index 00000000000..03997f77e63 --- /dev/null +++ b/gcc/testsuite/gnat.dg/pointer_variable_bounds_q.ads @@ -0,0 +1,6 @@ +package pointer_variable_bounds_q is + + type A_SIZE_TYPE is new INTEGER range 0 .. 65536; + function A_MAX_COMPS return A_SIZE_TYPE; + +end pointer_variable_bounds_q; diff --git a/gcc/tree.c b/gcc/tree.c index 6e3d13b8792..2d2ef08e5f7 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -7442,14 +7442,6 @@ walk_type_fields (tree type, walk_tree_fn func, void *data, WALK_SUBTREE (TYPE_DOMAIN (type)); break; - case BOOLEAN_TYPE: - case ENUMERAL_TYPE: - case INTEGER_TYPE: - case REAL_TYPE: - WALK_SUBTREE (TYPE_MIN_VALUE (type)); - WALK_SUBTREE (TYPE_MAX_VALUE (type)); - break; - case OFFSET_TYPE: WALK_SUBTREE (TREE_TYPE (type)); WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type)); @@ -7518,7 +7510,7 @@ walk_tree (tree *tp, walk_tree_fn func, void *data, struct pointer_set_t *pset) result = lang_hooks.tree_inlining.walk_subtrees (tp, &walk_subtrees, func, data, pset); - if (result || ! walk_subtrees) + if (result || !walk_subtrees) return result; switch (code) @@ -7648,23 +7640,29 @@ walk_tree (tree *tp, walk_tree_fn func, void *data, struct pointer_set_t *pset) } case DECL_EXPR: - /* Walk into various fields of the type that it's defining. We only - want to walk into these fields of a type in this case. Note that - decls get walked as part of the processing of a BIND_EXPR. + /* If this is a TYPE_DECL, walk into the fields of the type that it's + defining. We only want to walk into these fields of a type in this + case and not in the general case of a mere reference to the type. - ??? Precisely which fields of types that we are supposed to walk in - this case vs. the normal case aren't well defined. */ - if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL - && TREE_CODE (TREE_TYPE (DECL_EXPR_DECL (*tp))) != ERROR_MARK) + The criterion is as follows: if the field can be an expression, it + must be walked only here. This should be in keeping with the fields + that are directly gimplified in gimplify_type_sizes in order for the + mark/copy-if-shared/unmark machinery of the gimplifier to work with + variable-sized types. + + Note that DECLs get walked as part of processing the BIND_EXPR. */ + if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL) { tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp)); + if (TREE_CODE (*type_p) == ERROR_MARK) + return NULL_TREE; /* Call the function for the type. See if it returns anything or doesn't want us to continue. If we are to continue, walk both the normal fields and those for the declaration case. */ result = (*func) (type_p, &walk_subtrees, data); if (result || !walk_subtrees) - return NULL_TREE; + return result; result = walk_type_fields (*type_p, func, data, pset); if (result) @@ -7695,6 +7693,16 @@ walk_tree (tree *tp, walk_tree_fn func, void *data, struct pointer_set_t *pset) } } + /* Same for scalar types. */ + else if (TREE_CODE (*type_p) == BOOLEAN_TYPE + || TREE_CODE (*type_p) == ENUMERAL_TYPE + || TREE_CODE (*type_p) == INTEGER_TYPE + || TREE_CODE (*type_p) == REAL_TYPE) + { + WALK_SUBTREE (TYPE_MIN_VALUE (*type_p)); + WALK_SUBTREE (TYPE_MAX_VALUE (*type_p)); + } + WALK_SUBTREE (TYPE_SIZE (*type_p)); WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p)); }