Ticket #10: emx-cconv-on-var-crash.diff
File emx-cconv-on-var-crash.diff, 11.2 KB (added by , 14 years ago) |
---|
-
i386/emx.c
diff -ur config.orig-patch/i386/emx.c config/i386/emx.c
old new 67 67 case POINTER_TYPE: return "POINTER_TYPE "; 68 68 case VOID_TYPE: return "VOID_TYPE "; 69 69 case INTEGER_TYPE: return "INTEGER_TYPE "; 70 case CHAR_TYPE: return "CHAR_TYPE ";71 70 case BOOLEAN_TYPE: return "BOOLEAN_TYPE "; 72 case SET_TYPE: return "SET_TYPE ";73 71 case ARRAY_TYPE: return "ARRAY_TYPE "; 74 72 case RECORD_TYPE: return "RECORD_TYPE "; 75 73 case QUAL_UNION_TYPE: return "QUAL_UNION_TYPE"; … … 137 135 138 136 fprintf(stderr, "dbg: node=%d %s %p %s '%s' type=%d %s %p %s '%s' type_type=%d %s %p %s '%s' context=%d %s %p %s '%s' (%s)\n", 139 137 TREE_CODE(node), code(node), (void*)node, birddump_callingconv(node), birddump_name(node), 140 gtype ? (int)TREE_CODE(type) : -1, code(type), (void*)type, birddump_callingconv(type), birddump_name (type),138 type ? (int)TREE_CODE(type) : -1, code(type), (void*)type, birddump_callingconv(type), birddump_name (type), 141 139 type2 ? (int)TREE_CODE(type2) : -1, code(type2), (void*)type2, birddump_callingconv(type2), birddump_name (type2), 142 140 context ? (int)TREE_CODE(context) : -1, code(context), (void*)context, birddump_callingconv(context), birddump_name (context), 143 141 pszFunction); … … 299 297 return rc; 300 298 } 301 299 302 #if 0 /* choose between the smaller non working version, and the303 large ugly one which is working. */304 305 tree emx_handle_vacpp_attribute (tree *node, tree name, tree args,306 int flags, _Bool *no_add_attrs)307 {308 tree *type;309 (void) args;310 (void) flags;311 312 dfprintf((stderr, "emx_handle_vacpp_attribute\n"));313 DUMP (*node);314 315 if (TREE_CODE (*node) != FUNCTION_TYPE316 && TREE_CODE (*node) != METHOD_TYPE317 && TREE_CODE (*node) != FIELD_DECL318 && TREE_CODE (*node) != TYPE_DECL)319 {320 warning ("`%s' attribute only applies to functions",321 IDENTIFIER_POINTER (name));322 *no_add_attrs = true;323 }324 325 if (TARGET_64BIT)326 {327 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));328 *no_add_attrs = true;329 }330 331 /* Check if the attributes are compatible */332 if (ix86_check_append_attr (*node, name, no_add_attrs))333 return NULL_TREE;334 335 /* Now, a new type with our attribute please!336 If the FUNCTION_TYPE/METHOD_TYPE already have the attribute associated,337 there is no need to duplicate the type.338 @todo: I'm unsure wether or not we should do this from node and down... */339 for (type = node;340 TREE_CODE (*type) != FUNCTION_TYPE && TREE_CODE (*type) != METHOD_TYPE;341 type = &TREE_TYPE (*type))342 /* do nothing */;343 344 if (lookup_attribute (IDENTIFIER_POINTER (name), TYPE_ATTRIBUTES (*type)))345 return NULL_TREE;346 347 *type = build_type_copy (*type);348 *type = build_type_attribute_variant (*type, tree_cons (name, args, TYPE_ATTRIBUTES (*type)) );349 /**no_add_attrs = true; ?? */350 351 dfprintf((stderr, "emx_handle_vacpp_attribute: new type (%p)\n", (void*)type));352 DUMP (*node);353 return NULL_TREE;354 }355 356 #else357 358 /* This is the working version which we belive duplicate some which could be359 done by the generic attribute stuff in GCC... */360 tree emx_handle_vacpp_attribute (tree *node, tree name, tree args, int flags, _Bool *no_add_attrs)361 {362 tree type;363 364 dfprintf((stderr, "emx_handle_vacpp_attribute: node=%p\n", (void *)node));365 DUMP (*node);366 367 switch (TREE_CODE (*node))368 {369 /* Declarations!370 We need to attach the attribute to the type of the declaration.371 (Name mangling is done by emx_c_set_decl_assembler_name().) */372 case FUNCTION_DECL:/* Function declaration. */373 case TYPE_DECL: /* Function or function pointer type. */374 case FIELD_DECL: /* Function pointer (or function?) as a struct, union or class member. */375 case PARM_DECL: /* Function pointer as a parameter. */376 case VAR_DECL: /* Function pointer variable. */377 /* If this is a type declaration with our attribute, we allow it378 only if it is a pointer-to-a-function type or a function type. */379 type = TREE_TYPE (*node);380 if (TREE_CODE (type) == POINTER_TYPE)381 type = TREE_TYPE(type);382 if ( TREE_CODE (type) != FUNCTION_TYPE383 && TREE_CODE (type) != METHOD_TYPE)384 {385 warning ("`%s' attribute only applies to functions and function types, not to '%T'.",386 IDENTIFIER_POINTER (name), type);387 *no_add_attrs = true;388 break;389 }390 391 if (ix86_check_append_attr (type, name, no_add_attrs))392 break;393 394 /* If required we'll make a variant of the type for this attribute. */395 if (!lookup_attribute (IDENTIFIER_POINTER (name),396 TYPE_ATTRIBUTES (type)))397 {398 tree *ptype = node;399 while (*ptype != type)400 ptype = &TREE_TYPE (*ptype);401 *ptype = build_variant_type_copy (*ptype);402 *ptype = build_type_attribute_variant (403 *ptype, tree_cons (name, args, TYPE_ATTRIBUTES (*ptype)) );404 dfprintf((stderr, "emx_handle_vacpp_attribute: new type\n"));405 DUMP(*node);406 }407 else408 dfprintf((stderr, "emx_handle_vacpp_attribute: use old type\n"));409 *no_add_attrs = true;410 break;411 412 /* Types!413 For types involving functions we need to convince decl_attributes()414 (and its callers) to supply a declaration so we safely can change415 the type. */416 case POINTER_TYPE:417 /* We allow:418 This being the return type of a function which is coming soon.419 This being a function pointer which declaration is coming next.420 Everything else is considered inappropriate use of the attribute. */421 if ( !(flags & ATTR_FLAG_FUNCTION_NEXT)422 && ( !(flags & ATTR_FLAG_DECL_NEXT)423 || !(type = TREE_TYPE (*node))424 || ( TREE_CODE (type) != FUNCTION_TYPE425 && TREE_CODE (type) != METHOD_TYPE)))426 {427 warning ("`%s' attribute only applies to functions and function types",428 IDENTIFIER_POINTER (name));429 *no_add_attrs = true;430 break;431 }432 /* fall thru */433 case FUNCTION_TYPE:434 case METHOD_TYPE:435 #if 0 /* bird: This fixes optlink/tst4.c and doesn't seem to break anything.436 If set to true we are in some cases imposing _Optlink onto following437 declarations. This is weird stuff!438 !! This problem is actually what we see with the other implementation!! */439 *no_add_attrs = true;440 #endif441 return tree_cons (name, args, NULL_TREE);442 443 default:444 warning ("`%s' attribute only applies to functions and function types (code=%d)",445 IDENTIFIER_POINTER (name), TREE_CODE (*node));446 *no_add_attrs = true;447 break;448 }449 450 return NULL_TREE;451 }452 #endif453 454 300 void 455 301 emx_eh_frame_section () 456 302 { -
i386/emx.h
diff -ur config.orig-patch/i386/emx.h config/i386/emx.h
old new 119 119 120 120 /* We want the _System attribute */ 121 121 #define TARGET_SYSTEM_DECL_ATTRIBUTES 122 #define ix86_handle_system_attribute emx_handle_vacpp_attribute123 122 124 123 /* We want the _Optlink attribute */ 125 124 #define TARGET_OPTLINK_DECL_ATTRIBUTES 126 #define ix86_handle_optlink_attribute emx_handle_vacpp_attribute127 125 128 126 /* Do our own mangling on some kinds of decls */ 129 127 #define TARGET_C_SET_DECL_ASSEMBLER_NAME(decl) \ … … 310 308 extern void emx_eh_frame_section (void); 311 309 extern void emx_output_function_begin_epilogue (FILE *); 312 310 313 /* This function handles both _System and _Optlink attributes. */314 extern tree emx_handle_vacpp_attribute PARAMS ((tree *, tree, tree, int, _Bool *));315 316 311 /* These functions are for handling dllexport and dllimport. */ 317 312 extern void i386_emx_record_exported_symbol (const char *, int); 318 313 extern void i386_emx_file_end (void); -
i386/i386.c
diff -ur config.orig-patch/i386/i386.c config/i386/i386.c
old new 29685 29685 static const struct attribute_spec ix86_attribute_table[] = 29686 29686 { 29687 29687 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ 29688 #ifdef EMX /** @todo: ugly stuff, cleanup later. */29689 /* Stdcall attribute says callee is responsible for popping arguments29690 if they are not variable. */29691 { "stdcall", 0, 0, false, false, false, ix86_handle_system_attribute },29692 /* Fastcall attribute says callee is responsible for popping arguments29693 if they are not variable. */29694 { "fastcall", 0, 0, false, false, false, ix86_handle_system_attribute },29695 /* Cdecl attribute says the callee is a normal C declaration */29696 { "cdecl", 0, 0, false, false, false, ix86_handle_system_attribute },29697 #else29698 29688 /* Stdcall attribute says callee is responsible for popping arguments 29699 29689 if they are not variable. */ 29700 29690 { "stdcall", 0, 0, false, true, true, ix86_handle_cconv_attribute }, … … 29703 29693 { "fastcall", 0, 0, false, true, true, ix86_handle_cconv_attribute }, 29704 29694 /* Cdecl attribute says the callee is a normal C declaration */ 29705 29695 { "cdecl", 0, 0, false, true, true, ix86_handle_cconv_attribute }, 29706 #endif29707 29696 /* Regparm attribute specifies how many integer arguments are to be 29708 29697 passed in registers. */ 29709 29698 { "regparm", 1, 1, false, true, true, ix86_handle_cconv_attribute }, … … 29728 29717 { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute }, 29729 29718 { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute }, 29730 29719 /* End element. */ 29731 #ifdef EMX /** @todo: ugly stuff, cleanup later. */29732 29720 #ifdef TARGET_SYSTEM_DECL_ATTRIBUTES 29733 29721 /* System says the function is extern "C" and is not underscored. */ 29734 { "system", 0, 0, false, false, false, ix86_handle_system_attribute },29722 { "system", 0, 0, false, true, true, ix86_handle_cconv_attribute }, 29735 29723 #endif 29736 29724 #ifdef TARGET_OPTLINK_DECL_ATTRIBUTES 29737 29725 /* Optlink is like regparm with a few differences */ 29738 { "optlink", 0, 0, false, false, false, ix86_handle_optlink_attribute }, 29739 #endif 29740 #else 29741 #ifdef TARGET_SYSTEM_DECL_ATTRIBUTES 29742 /* System says the function is extern "C" and is not underscored. */ 29743 { "system", 0, 0, false, true, true, ix86_handle_system_attribute }, 29744 #endif 29745 #ifdef TARGET_OPTLINK_DECL_ATTRIBUTES 29746 /* Optlink is like regparm with a few differences */ 29747 { "optlink", 0, 0, false, true, true, ix86_handle_optlink_attribute }, 29748 #endif 29726 { "optlink", 0, 0, false, true, true, ix86_handle_cconv_attribute }, 29749 29727 #endif 29750 29728 { NULL, 0, 0, false, false, false, NULL } 29751 29729 };