This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

patch: disallow initializing certain aggregates


The opaque types in my previous set of patches have another interesting quality: it is illegal to initialize them.

I've cleaned up the disgusting hack I had internally and genericized the concept as a target hook called at really_start_incremental_init() time. This allows a target hook to error() out if we are trying to initialize the opaque types.

First, I am unsure if I should extend this concept to initializers in general, not just the aggregate ones (caught at really_start_incremental_init). Right now I am only handling aggregate types because it's (a) simple (b) that's all that's needed at the moment.

Second, depending on my above comments, I'll have to come up with an equivalent patch to the C++ front end, because I just noticed it doesn't use really_start_incremental_init.

This is probably the remaining show stopper for current PPC-E500 ABI compliance.

Comments?

2003-02-18 Aldy Hernandez <aldyh@redhat.com>

* doc/tm.texi: Document TARGET_ALLOW_INITIALIZER.

* testsuite/gcc.dg/20030218-2.c: New.

* config/rs6000/rs6000.c (rs6000_allow_initializer): New.
(TARGET_ALLOW_INITIALIZER): Define.

* target.h (struct gcc_target): Add allow_initializer.

* target-def.h (TARGET_ALLOW_INITIALIZER): New macro.
(TARGET_INITIALIZER): Add TARGET_ALLOW_INITIALIZER.

* c-typeck.c (really_start_incremental_init): Call
allow_initializer target hook.

Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.201
diff -c -p -r1.201 tm.texi
*** doc/tm.texi 19 Feb 2003 00:51:16 -0000 1.201
--- doc/tm.texi 19 Feb 2003 05:06:52 -0000
*************** copying a vector value of type @var{type
*** 1458,1463 ****
--- 1458,1469 ----
type @var{type2}. The default is that there are no such types.
@end deftypefn

+ @deftypefn {Target Hook} void TARGET_ALLOW_INITIALIZER (tree @var{type})
+ This target hook should call @code{error} with an appropriate message
+ if it is invalid to initialize the given aggregate @code{type}. The
+ default is to do nothing.
+ @end deftypefn
+
@deftypefn {Target Hook} bool TARGET_MS_BITFIELD_LAYOUT_P (tree @var{record_type})
This target hook returns @code{true} if bit-fields in the given
@var{record_type} are to be laid out following the rules of Microsoft
Index: testsuite/gcc.dg/20030218-2.c
===================================================================
RCS file: testsuite/gcc.dg/20030218-2.c
diff -N testsuite/gcc.dg/20030218-2.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/20030218-2.c 19 Feb 2003 05:06:52 -0000
***************
*** 0 ****
--- 1,8 ----
+ /* { dg-do compile { target powerpc-*-eabi* } } */
+ /* { dg-options "-mcpu=8540" } */
+
+ /* Test that __ev64_opaque__ types cannot be initialized. */
+
+ typedef int __ev64_opaque__ __attribute__((mode(V2SI)));
+
+ __ev64_opaque__ george = {1, 2}; /* { dg-error "types cannot be initialized" } */
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 19 Feb 2003 05:07:20 -0000
*************** static void altivec_frame_fixup PARAMS (
*** 270,275 ****
--- 270,276 ----
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));
+ static void rs6000_allow_initializer PARAMS ((tree));

/* Hash table stuff for keeping track of TOC entries. */

*************** static const char alt_reg_names[][8] =
*** 425,430 ****
--- 426,434 ----
#undef TARGET_VECTOR_TYPES_COMPATIBLE
#define TARGET_VECTOR_TYPES_COMPATIBLE rs6000_spe_vector_types_compatible

+ #undef TARGET_ALLOW_INITIALIZER
+ #define TARGET_ALLOW_INITIALIZER rs6000_allow_initializer
+
struct gcc_target targetm = TARGET_INITIALIZER;

/* Override command line options. Mostly we process the processor
*************** rs6000_spe_vector_types_compatible (t1,
*** 13624,13629 ****
--- 13628,13647 ----
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;
+ }
+
+ /* Error out if we're trying to initialize an opaque type. */
+ static void
+ rs6000_allow_initializer (type)
+ tree type;
+ {
+ if (TARGET_SPE
+ && 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__"))
+ error ("__ev64_opaque__ types cannot be initialized");
}

#include "gt-rs6000.h"
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 19 Feb 2003 05:07:21 -0000
*************** struct gcc_target
*** 323,328 ****
--- 323,331 ----
/* True if two vector types can be copied without an explicit cast. */
bool (* vector_types_compatible) PARAMS ((tree, tree));

+ /* Error out if a type cannot be initialized. */
+ void (* allow_initializer) PARAMS ((tree));
+
/* Compute a (partial) cost for rtx X. Return true if the complete
cost has been computed, and false if subexpressions should be
scanned. In either case, *TOTAL contains the cost result. */
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 19 Feb 2003 05:07:22 -0000
*************** Foundation, 59 Temple Place - Suite 330,
*** 260,265 ****
--- 260,269 ----
#define TARGET_VECTOR_TYPES_COMPATIBLE hook_bool_tree_tree_false
#endif

+ #ifndef TARGET_ALLOW_INITIALIZER
+ #define TARGET_ALLOW_INITIALIZER hook_void_tree
+ #endif
+
/* In hook.c. */
#define TARGET_CANNOT_MODIFY_JUMPS_P hook_bool_void_false
#define TARGET_CANNOT_FORCE_CONST_MEM hook_bool_rtx_false
*************** Foundation, 59 Temple Place - Suite 330,
*** 308,313 ****
--- 312,318 ----
TARGET_STRIP_NAME_ENCODING, \
TARGET_VALID_POINTER_MODE, \
TARGET_VECTOR_TYPES_COMPATIBLE, \
+ TARGET_ALLOW_INITIALIZER, \
TARGET_RTX_COSTS, \
TARGET_ADDRESS_COST, \
TARGET_HAVE_NAMED_SECTIONS, \
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 19 Feb 2003 05:07:39 -0000
*************** really_start_incremental_init (type)
*** 5158,5163 ****
--- 5158,5166 ----
if (type == 0)
type = TREE_TYPE (constructor_decl);

+ /* Error out if type cannot be initiliazed. */
+ (*targetm.allow_initializer) (type);
+
p->type = constructor_type;
p->fields = constructor_fields;
p->index = constructor_index;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]