This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: patch: disallow initializing certain aggregates
- From: Aldy Hernandez <aldy at andrews dot edu>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 20 Feb 2003 09:43:37 -0800
- Subject: Re: patch: disallow initializing certain aggregates
Yesterday Richard briefly whined^Wmentioned that he didn't like yet
another target hook for this, that we could probably do all this
functionality with one hook.
This patch changes the previous TARGET_VECTOR_TYPES_COMPATIBLE and
calls it TARGET_VECTOR_OPAQUE_P. I changed the semantics a bit, so we
could use it both for auto-casted vectors, and for disallowing opaque
types to be initialized.
Now opaque types imply (a) they can be interconverted without a cast
(b) they cannot be initialized.
This is a much better approach because we delete code and get more
functionality
;-).
I also deleted the V2SI_type_node stuff Geoff didn't like. An upcoming
patch will change the nodes.
Is this OK?
2003-02-20 Aldy Hernandez <aldyh at redhat dot com>
* doc/tm.texi: Document Rename TARGET_VECTOR_TYPES_COMPATIBLE to
TARGET_VECTOR_OPAQUE_P. Document accordingly.
* testsuite/gcc.dg/20030218-1.c: Check that initialization of
opaque types fail.
* c-typeck.c (comptypes): Change call to vector_types_compatible
to vector_opaque_p.
(convert_for_assignment): Call vector_opaque_p instead of
vector_types_compatible.
(really_start_incremental_init): Disallow initialization of opaque
types.
* target-def.h: Remove TARGET_VECTOR_TYPES_COMPATIBLE.
Define TARGET_VECTOR_OPAQUE_P.
(TARGET_INITIALIZER): Same.
* target.h (struct gcc_target): Remove vector_types_compatible.
Add vector_opaque_p.
* config/rs6000/rs6000.c (rs6000_spe_vector_types_compatible):
Remove.
(is_ev64_opaque_type): Check for TARGET_SPE and make sure type is
a vector type. Change return type to bool.
(TARGET_VECTOR_TYPES_COMPATIBLE): Remove.
(TARGET_VECTOR_OPAQUE_P): Define.
* cp/parser.c (cp_parser_init_declarator): Call vector_opaque_p
target hook.
Include target.h.
(cp_parser_init_declarator): Fix typo in function comments.
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.203
diff -c -p -r1.203 tm.texi
*** doc/tm.texi 19 Feb 2003 21:55:22 -0000 1.203
--- doc/tm.texi 20 Feb 2003 17:16:25 -0000
*************** floating-point arithmetic.
*** 1452,1461 ****
The default definition of this macro returns false for all sizes.
@end table
! @deftypefn {Target Hook} bool TARGET_VECTOR_TYPES_COMPATIBLE (tree
@var{type1}, tree @var{type2})
! This target hook should return @code{true} if no cast is needed when
! copying a vector value of type @var{type1} into a vector lvalue of
! type @var{type2}. The default is that there are no such types.
@end deftypefn
@deftypefn {Target Hook} bool TARGET_MS_BITFIELD_LAYOUT_P (tree
@var{record_type})
--- 1452,1463 ----
The default definition of this macro returns false for all sizes.
@end table
! @deftypefn {Target Hook} bool TARGET_VECTOR_OPAQUE_P (tree @var{type})
! This target hook should return @code{true} a vector is opaque. That
! is, if no cast is needed when copying a vector value of type
! @var{type} into another vector lvalue of the same size. Vector opaque
! types cannot be initialized. The default is that there are no such
! types.
@end deftypefn
@deftypefn {Target Hook} bool TARGET_MS_BITFIELD_LAYOUT_P (tree
@var{record_type})
Index: testsuite/gcc.dg/20030218-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/20030218-1.c,v
retrieving revision 1.2
diff -c -p -r1.2 20030218-1.c
*** testsuite/gcc.dg/20030218-1.c 19 Feb 2003 04:32:44 -0000 1.2
--- testsuite/gcc.dg/20030218-1.c 20 Feb 2003 17:16:25 -0000
***************
*** 3,17 ****
/* Test vectors that can interconvert without a cast. */
! int vint __attribute__((mode(V2SI)));
int vshort __attribute__((mode(V4HI)));
int vfloat __attribute__((mode(V2SF)));
int
main (void)
{
! vint = vfloat;
! vshort = vint;
vfloat = vshort; /* { dg-error "incompatible types in assignment" }
*/
return 0;
}
--- 3,26 ----
/* Test vectors that can interconvert without a cast. */
! typedef int __attribute__((mode(V2SI))) __ev64_opaque__;
!
! __ev64_opaque__ opp;
! int vint __attribute__((mode(V2SI)));
int vshort __attribute__((mode(V4HI)));
int vfloat __attribute__((mode(V2SF)));
int
main (void)
{
! __ev64_opaque__ george = { 1, 2 }; /* { dg-error "opaque vector
types cannot be initialized" } */
!
! opp = vfloat;
! vshort = opp;
vfloat = vshort; /* { dg-error "incompatible types in assignment" }
*/
+
+ /* Just because this is a V2SI, it doesn't make it an opaque. */
+ vint = vshort; /* { dg-error "incompatible types in assignment" } */
+
return 0;
}
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.220
diff -c -p -r1.220 c-typeck.c
*** c-typeck.c 19 Feb 2003 00:51:16 -0000 1.220
--- c-typeck.c 20 Feb 2003 17:16:41 -0000
*************** comptypes (type1, type2)
*** 576,582 ****
case VECTOR_TYPE:
/* The target might allow certain vector types to be
compatible. */
! val = (*targetm.vector_types_compatible) (t1, t2);
break;
default:
--- 576,583 ----
case VECTOR_TYPE:
/* The target might allow certain vector types to be
compatible. */
! val = (*targetm.vector_opaque_p) (t1)
! || (*targetm.vector_opaque_p) (t2);
break;
default:
*************** convert_for_assignment (type, rhs, errty
*** 4071,4077 ****
}
/* Some types can interconvert without explicit casts. */
else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
! && (*targetm.vector_types_compatible) (type, rhstype))
return convert (type, rhs);
/* Arithmetic types all interconvert, and enum is treated like int.
*/
else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
--- 4072,4079 ----
}
/* Some types can interconvert without explicit casts. */
else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
! && ((*targetm.vector_opaque_p) (type)
! || (*targetm.vector_opaque_p) (rhstype)))
return convert (type, rhs);
/* Arithmetic types all interconvert, and enum is treated like int.
*/
else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
*************** really_start_incremental_init (type)
*** 5157,5162 ****
--- 5159,5167 ----
if (type == 0)
type = TREE_TYPE (constructor_decl);
+
+ if ((*targetm.vector_opaque_p) (type))
+ error ("opaque vector types cannot be initialized");
p->type = constructor_type;
p->fields = constructor_fields;
Index: target-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target-def.h,v
retrieving revision 1.45
diff -c -p -r1.45 target-def.h
*** target-def.h 19 Feb 2003 00:51:16 -0000 1.45
--- target-def.h 20 Feb 2003 17:16:41 -0000
*************** Foundation, 59 Temple Place - Suite 330,
*** 256,263 ****
#define TARGET_VALID_POINTER_MODE default_valid_pointer_mode
#endif
! #ifndef TARGET_VECTOR_TYPES_COMPATIBLE
! #define TARGET_VECTOR_TYPES_COMPATIBLE hook_bool_tree_tree_false
#endif
/* In hook.c. */
--- 256,263 ----
#define TARGET_VALID_POINTER_MODE default_valid_pointer_mode
#endif
! #ifndef TARGET_VECTOR_OPAQUE_P
! #define TARGET_VECTOR_OPAQUE_P hook_bool_tree_false
#endif
/* In hook.c. */
*************** Foundation, 59 Temple Place - Suite 330,
*** 307,313 ****
TARGET_ENCODE_SECTION_INFO, \
TARGET_STRIP_NAME_ENCODING, \
TARGET_VALID_POINTER_MODE, \
! TARGET_VECTOR_TYPES_COMPATIBLE, \
TARGET_RTX_COSTS, \
TARGET_ADDRESS_COST, \
TARGET_HAVE_NAMED_SECTIONS, \
--- 307,313 ----
TARGET_ENCODE_SECTION_INFO, \
TARGET_STRIP_NAME_ENCODING, \
TARGET_VALID_POINTER_MODE, \
! TARGET_VECTOR_OPAQUE_P, \
TARGET_RTX_COSTS, \
TARGET_ADDRESS_COST, \
TARGET_HAVE_NAMED_SECTIONS, \
Index: target.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target.h,v
retrieving revision 1.51
diff -c -p -r1.51 target.h
*** target.h 19 Feb 2003 00:51:16 -0000 1.51
--- target.h 20 Feb 2003 17:16:43 -0000
*************** struct gcc_target
*** 320,327 ****
/* True if MODE is valid for a pointer in
__attribute__((mode("MODE"))). */
bool (* valid_pointer_mode) PARAMS ((enum machine_mode mode));
! /* True if two vector types can be copied without an explicit cast.
*/
! bool (* vector_types_compatible) PARAMS ((tree, tree));
/* Compute a (partial) cost for rtx X. Return true if the complete
cost has been computed, and false if subexpressions should be
--- 320,327 ----
/* True if MODE is valid for a pointer in
__attribute__((mode("MODE"))). */
bool (* valid_pointer_mode) PARAMS ((enum machine_mode mode));
! /* True if a vector is opaque. */
! bool (* vector_opaque_p) PARAMS ((tree));
/* Compute a (partial) cost for rtx X. Return true if the complete
cost has been computed, and false if subexpressions should be
Index: config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.424
diff -c -p -r1.424 rs6000.c
*** config/rs6000/rs6000.c 19 Feb 2003 00:51:16 -0000 1.424
--- config/rs6000/rs6000.c 20 Feb 2003 17:17:12 -0000
*************** static void is_altivec_return_reg PARAMS
*** 268,275 ****
static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
static void altivec_frame_fixup PARAMS ((rtx, rtx, HOST_WIDE_INT));
static int easy_vector_constant PARAMS ((rtx));
! static int is_ev64_opaque_type PARAMS ((tree));
! static bool rs6000_spe_vector_types_compatible PARAMS ((tree, tree));
/* Hash table stuff for keeping track of TOC entries. */
--- 268,274 ----
static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
static void altivec_frame_fixup PARAMS ((rtx, rtx, HOST_WIDE_INT));
static int easy_vector_constant PARAMS ((rtx));
! static bool is_ev64_opaque_type PARAMS ((tree));
/* Hash table stuff for keeping track of TOC entries. */
*************** static const char alt_reg_names[][8] =
*** 422,429 ****
#undef TARGET_ADDRESS_COST
#define TARGET_ADDRESS_COST hook_int_rtx_0
! #undef TARGET_VECTOR_TYPES_COMPATIBLE
! #define TARGET_VECTOR_TYPES_COMPATIBLE
rs6000_spe_vector_types_compatible
struct gcc_target targetm = TARGET_INITIALIZER;
--- 421,428 ----
#undef TARGET_ADDRESS_COST
#define TARGET_ADDRESS_COST hook_int_rtx_0
! #undef TARGET_VECTOR_OPAQUE_P
! #define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
struct gcc_target targetm = TARGET_INITIALIZER;
*************** rs6000_memory_move_cost (mode, class, in
*** 13595,13629 ****
/* Return true if TYPE is of type __ev64_opaque__. */
! static int
is_ev64_opaque_type (type)
tree type;
{
! return (TYPE_NAME (type)
&& TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
&& DECL_NAME (TYPE_NAME (type))
&& strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))),
"__ev64_opaque__") == 0);
- }
-
- /* Return true if vector type1 can be converted into vector type2. */
-
- static bool
- rs6000_spe_vector_types_compatible (t1, t2)
- tree t1;
- tree t2;
- {
- if (!TARGET_SPE
- || TREE_CODE (t1) != VECTOR_TYPE || TREE_CODE (t2) !=
VECTOR_TYPE)
- return 0;
-
- if (TYPE_NAME (t1) || TYPE_NAME (t2))
- return is_ev64_opaque_type (t1) || is_ev64_opaque_type (t2);
-
- /* FIXME: We assume V2SI is the opaque type, so we accidentally
- allow inter conversion to and from V2SI modes. We could use
- V1D1, and rewrite <spe.h> accordingly. */
- return t1 == V2SI_type_node || t2 == V2SI_type_node;
}
#include "gt-rs6000.h"
--- 13594,13610 ----
/* Return true if TYPE is of type __ev64_opaque__. */
! static bool
is_ev64_opaque_type (type)
tree type;
{
! return (TARGET_SPE
! && TREE_CODE (type) == VECTOR_TYPE
! && TYPE_NAME (type)
&& TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
&& DECL_NAME (TYPE_NAME (type))
&& strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))),
"__ev64_opaque__") == 0);
}
#include "gt-rs6000.h"
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.43
diff -c -p -r1.43 parser.c
*** cp/parser.c 18 Feb 2003 18:16:19 -0000 1.43
--- cp/parser.c 20 Feb 2003 17:17:47 -0000
***************
*** 34,39 ****
--- 34,40 ----
#include "diagnostic.h"
#include "toplev.h"
#include "output.h"
+ #include "target.h"
/* The lexer. */
*************** cp_parser_asm_definition (cp_parser* par
*** 9506,9512 ****
declarator asm-specification [opt] attributes [opt] initializer
[opt]
The DECL_SPECIFIERS and PREFIX_ATTRIBUTES apply to this declarator.
! Returns a reprsentation of the entity declared. If MEMBER_P is
TRUE,
then this declarator appears in a class scope. The new DECL
created
by this declarator is returned.
--- 9507,9513 ----
declarator asm-specification [opt] attributes [opt] initializer
[opt]
The DECL_SPECIFIERS and PREFIX_ATTRIBUTES apply to this declarator.
! Returns a representation of the entity declared. If MEMBER_P is
TRUE,
then this declarator appears in a class scope. The new DECL
created
by this declarator is returned.
*************** cp_parser_init_declarator (cp_parser* pa
*** 9705,9712 ****
/* Parse the initializer. */
if (is_initialized)
! initializer = cp_parser_initializer (parser,
! &is_parenthesized_init);
else
{
initializer = NULL_TREE;
--- 9706,9718 ----
/* Parse the initializer. */
if (is_initialized)
! {
! if ((*targetm.vector_opaque_p) (TREE_TYPE (decl)))
! cp_parser_error (parser, "opaque vector types cannot be
initialized");
!
! initializer = cp_parser_initializer (parser,
! &is_parenthesized_init);
! }
else
{
initializer = NULL_TREE;