More Objective C @"string" bugs...

Zack Weinberg zackw@Stanford.EDU
Mon Mar 5 15:42:00 GMT 2001


On Mon, Mar 05, 2001 at 01:14:36PM -0800, Zack Weinberg wrote:
> This program will return exit status 2:

It looks like no one updated the ObjC front end for this change:

2001-02-26  Jason Merrill  <jason@redhat.com>

        * c-decl.c (finish_decl): Set DECL_DEFER_OUTPUT on tentative file-scope
        definitions.
        * toplev.c (rest_of_decl_compilation): Check DECL_DEFER_OUTPUT to
        recognize a tentative definition.  Lose obsolete code.

        * toplev.c (wrapup_global_declarations): Don't emit DECL_COMDAT
        variables unless necessary, either.

objc-act.c is assuming it's safe to call rest_of_decl_compilation on a
half-initialized decl and then set its constructor, which is no longer
true.  The appended patch makes my test program compile and run
successfully.  I've also changed the existing string[12].m so that
they don't mask the bug anymore.

zw

	* objc/objc-act.c (objc_add_static_instance): Set DECL_INITIAL
	and DECL_DEFER_OUTPUT on the decl we create, before calling
	rest_of_decl_compilation.

	* objc/execute/string1.m, objc/execute/string2.m: Compare the
	result of -cString against what we expect it to be; don't just
	print it out for no one to read.

===================================================================
Index: objc/objc-act.c
--- objc/objc-act.c	2001/03/02 00:40:00	1.68
+++ objc/objc-act.c	2001/03/05 23:38:46
@@ -1474,12 +1474,13 @@ objc_add_static_instance (constructor, c
   DECL_COMMON (decl) = 1;
   TREE_STATIC (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
+  DECL_INITIAL (decl) = constructor;
+
+  /* We may be writing something else just now.
+     Postpone till end of input.  */
+  DECL_DEFER_OUTPUT (decl) = 1;
   pushdecl_top_level (decl);
   rest_of_decl_compilation (decl, 0, 1, 0);
-
-  /* Do this here so it gets output later instead of possibly
-     inside something else we are writing.  */
-  DECL_INITIAL (decl) = constructor;
 
   /* Add the DECL to the head of this CLASS' list.  */
   TREE_PURPOSE (*chain) = tree_cons (NULL_TREE, decl, TREE_PURPOSE (*chain));
===================================================================
Index: testsuite/objc/execute/string1.m
--- testsuite/objc/execute/string1.m	2000/07/30 05:45:10	1.1
+++ testsuite/objc/execute/string1.m	2001/03/05 23:38:46
@@ -1,8 +1,10 @@
-#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
 #include <objc/NXConstStr.h>
 
 int main(int argc, void **args)
 {
-  printf ([@"this is a string\n" cString]);
+  if (strcmp ([@"this is a string" cString], "this is a string"))
+    abort ();
   return 0;
 }
===================================================================
Index: testsuite/objc/execute/string2.m
--- testsuite/objc/execute/string2.m	2000/07/30 05:45:10	1.1
+++ testsuite/objc/execute/string2.m	2001/03/05 23:38:46
@@ -1,8 +1,11 @@
-#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
 #include <objc/NXConstStr.h>
 
 int main(int argc, void **args)
 {
-  printf ([@"this " @"is " @"a " @"string\n" cString]);
+  if (strcmp ([@"this " @"is " @"a " @"string" cString],
+              "this " "is " "a " "string"))
+    abort ();
   return 0;
 }



More information about the Gcc-bugs mailing list