Fix compiler crash in ObjC protocols

Stan Shebs shebs@apple.com
Tue May 1 16:09:00 GMT 2001


The following patch fixes the compiler crashes that have been
happening in Objective-C programs that use protocols (such as
testsuite/objc/execute/formal-protocol-*.m).  I'm not 100% sure
that this is the right fix, but the situation is that the ObjC
frontend keeps around some open function decls for some crufty
things it needs to do, and all the crashes come from synthesized
decls that accidently pick up those function decls as context,
even though they're really describing global data structures.
So clearing DECL_CONTEXT causes them to be handled as global data,
while leaving the tmp function decls alone.

Tested on powerpc-apple-darwin1.3, committed to trunk and
3.0 branch.

Stan

2001-05-01  Stan Shebs  <shebs@apple.com>

        * objc/objc-act.c (build_module_descriptor): Clear DECL_CONTEXT
        of UOBJC_MODULES_decl.
        (generate_strings): Clear DECL_CONTEXT of new decl nodes.
        (generate_descriptor_table): Ditto.
        (generate_protocols): Ditto.
        (generate_protocol_list): Ditto.
        (generate_classref_translation_entry): Ditto.

Index: objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.78
diff -c -3 -p -r1.78 objc-act.c
*** objc-act.c	2001/05/01 12:11:35	1.78
--- objc-act.c	2001/05/01 20:38:40
*************** build_module_descriptor ()
*** 1811,1816 ****
--- 1811,1818 ----
  
    DECL_ARTIFICIAL (UOBJC_MODULES_decl) = 1;
    DECL_IGNORED_P (UOBJC_MODULES_decl) = 1;
+   DECL_CONTEXT (UOBJC_MODULES_decl) = NULL_TREE;
+ 
    finish_decl (UOBJC_MODULES_decl,
  	       init_module_descriptor (TREE_TYPE (UOBJC_MODULES_decl)),
  	       NULL_TREE);
*************** generate_strings ()
*** 2022,2027 ****
--- 2024,2030 ----
        decl_specs = tree_cons (NULL_TREE, ridpointers[(int) RID_CHAR], sc_spec);
        expr_decl = build_nt (ARRAY_REF, DECL_NAME (decl), NULL_TREE);
        decl = start_decl (expr_decl, decl_specs, 1, NULL_TREE, NULL_TREE);
+       DECL_CONTEXT (decl) = NULL_TREE;
        string_expr = my_build_string (IDENTIFIER_LENGTH (string) + 1,
  				     IDENTIFIER_POINTER (string));
        finish_decl (decl, string_expr, NULL_TREE);
*************** generate_strings ()
*** 2036,2041 ****
--- 2039,2045 ----
        decl_specs = tree_cons (NULL_TREE, ridpointers[(int) RID_CHAR], sc_spec);
        expr_decl = build_nt (ARRAY_REF, DECL_NAME (decl), NULL_TREE);
        decl = start_decl (expr_decl, decl_specs, 1, NULL_TREE, NULL_TREE);
+       DECL_CONTEXT (decl) = NULL_TREE;
        string_expr = my_build_string (IDENTIFIER_LENGTH (string) + 1,
  				     IDENTIFIER_POINTER (string));
        finish_decl (decl, string_expr, NULL_TREE);
*************** generate_strings ()
*** 2050,2055 ****
--- 2054,2060 ----
        decl_specs = tree_cons (NULL_TREE, ridpointers[(int) RID_CHAR], sc_spec);
        expr_decl = build_nt (ARRAY_REF, DECL_NAME (decl), NULL_TREE);
        decl = start_decl (expr_decl, decl_specs, 1, NULL_TREE, NULL_TREE);
+       DECL_CONTEXT (decl) = NULL_TREE;
        string_expr = my_build_string (IDENTIFIER_LENGTH (string) + 1,
  				IDENTIFIER_POINTER (string));
        finish_decl (decl, string_expr, NULL_TREE);
*************** generate_descriptor_table (type, name, s
*** 2955,2961 ****
    decl_specs = tree_cons (NULL_TREE, type, sc_spec);
  
    decl = start_decl (synth_id_with_class_suffix (name, proto),
! 				decl_specs, 1, NULL_TREE, NULL_TREE);
  
    initlist = build_tree_list (NULL_TREE, build_int_2 (size, 0));
    initlist = tree_cons (NULL_TREE, list, initlist);
--- 2960,2967 ----
    decl_specs = tree_cons (NULL_TREE, type, sc_spec);
  
    decl = start_decl (synth_id_with_class_suffix (name, proto),
! 		     decl_specs, 1, NULL_TREE, NULL_TREE);
!   DECL_CONTEXT (decl) = NULL_TREE;
  
    initlist = build_tree_list (NULL_TREE, build_int_2 (size, 0));
    initlist = tree_cons (NULL_TREE, list, initlist);
*************** generate_protocols ()
*** 3212,3217 ****
--- 3218,3225 ----
        decl = start_decl (synth_id_with_class_suffix ("_OBJC_PROTOCOL", p),
  			 decl_specs, 1, NULL_TREE, NULL_TREE);
  
+       DECL_CONTEXT (decl) = NULL_TREE;
+ 
        protocol_name_expr = add_objc_string (PROTOCOL_NAME (p), class_names);
  
        if (refs_decl)
*************** generate_protocol_list (i_or_p)
*** 4238,4243 ****
--- 4246,4252 ----
    expr_decl = build1 (INDIRECT_REF, NULL_TREE, expr_decl);
  
    refs_decl = start_decl (expr_decl, decl_specs, 1, NULL_TREE, NULL_TREE);
+   DECL_CONTEXT (refs_decl) = NULL_TREE;
  
    finish_decl (refs_decl, build_constructor (TREE_TYPE (refs_decl),
  					     nreverse (initlist)),
*************** generate_classref_translation_entry (cha
*** 8346,8351 ****
--- 8355,8361 ----
    /* The decl that is returned from start_decl is the one that we
       forward declared in build_class_reference.  */
    decl = start_decl (name, decl_specs, 1, NULL_TREE, NULL_TREE);
+   DECL_CONTEXT (decl) = NULL_TREE;
    finish_decl (decl, expr, NULL_TREE);
    return;
  }



More information about the Gcc-patches mailing list