This is the mail archive of the 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]

[objc] Fix PR18862

This PR is about a crash when trying to use -Wselector with the GNU runtime.

The -Wselector warnings are issued by build_selector_translation_table(). The code here used to be:

            /* Adjust line number for warning message.  */
            int save_lineno = input_line;
            if (flag_next_runtime && TREE_PURPOSE (chain))
              input_line = DECL_SOURCE_LINE (TREE_PURPOSE (chain));
            warning ("creating selector for non existant method %s",
                     IDENTIFIER_POINTER (TREE_VALUE (chain)));
            input_line = save_lineno;

... but this was changed by:

2004-09-24  Zack Weinberg  <>
        (build_selector_translation_table): Use %J in diagnostic
        instead of diddling input_line.  Fix spelling.

         warning ("%Jcreating selector for nonexistent method %qE",
                  TREE_PURPOSE (chain), TREE_VALUE (chain));

... which uses the location of TREE_PURPOSE (chain) unconditionally, hence the crash. (When using the GNU runtime, TREE_PURPOSE (chain) is used for the 'type' of the selector, and it's NULL if the type is unknown, which I believe is always the case for the selectors we'll warn about here; not sure if there's a sensible location on the type in other cases.)

Anyway, my patch fixes this by restoring the old check before using TREE_PURPOSE (chain), and using input_location otherwise.

(Using a more sensible location with the GNU runtime would be nice, but not, as far as I can tell, suitable for stage 3.)

Bootstrapped (c,objc) on i686-pc-linux-gnu. Tested with 'make check-objc', no new failures. I've verified that the new test fails with an unpatched compiler.

- Alexander Malmberg

2005-01-26  Alexander Malmberg  <>

	PR objc/18862
	* objc-act.c (build_selector_translation_table): Use
	input_location in the diagnostic for the GNU runtime or if
	TREE_PURPOSE (chain) is NULL.

2005-01-26  Alexander Malmberg  <>

	PR objc/18862
	* objc.dg/selector-2.m: New test.
Index: objc-act.c
RCS file: /cvsroot/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.262
diff -u -r1.262 objc-act.c
--- objc-act.c	16 Jan 2005 08:13:14 -0000	1.262
+++ objc-act.c	26 Jan 2005 00:28:24 -0000
@@ -2342,8 +2363,15 @@
         if (!found)
-	  warning ("%Jcreating selector for nonexistent method %qE",
-		   TREE_PURPOSE (chain), TREE_VALUE (chain));
+	  {
+	    location_t *loc;
+	    if (flag_next_runtime && TREE_PURPOSE (chain))
+	      loc = &DECL_SOURCE_LOCATION (TREE_PURPOSE (chain));
+	    else
+	      loc = &input_location;
+	    warning ("%Hcreating selector for nonexistent method %qE",
+		     loc, TREE_VALUE (chain));
+	  }
       expr = build_selector (TREE_VALUE (chain));
/* Test that we don't ICE when issuing a -Wselector warning.  */
/* { dg-options "-Wselector -fgnu-runtime" } */
/* { dg-do compile } */

#include <objc/Object.h>

@interface Foo
@implementation Foo
-(void) foo
  SEL a;
  a = @selector(b1ar);
@end /* { dg-warning "creating selector for nonexistent method .b1ar." } */

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