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]

Re: Update pass manager to handle generate_summary/transform functions


> With mapped locations, system-header-ness is encoded into a
> location_t.  So, I think it should be possible to remove the global
> in_system_header, and then change DECL_IN_SYSTEM_HEADER to simply
> check the decl's location.  Uses of in_system_header in a front end
> can simply look at the appropriate location -- the current token's
> location for the parser, the location of some expression, or
> input_location as a last resort.
>
> I think this not should be much more work than what you have done, and
> IMO it would be preferable because it would remove a global.

I liked the idea and decided to give it a try. Two problems that I found:
*) In some places we use in_system_header just to avoid warnings.
*) in_system_headers and location are not kept in perfect sync. In
particular, the function "warning" should probably take a location_t
argument informing where the warning happened.

I was able to create a patch that avoids these problems. It is not
very clean, but it does removes a global variable and a field from the
trees :-)

With this change it is no longer possible to change just the in_system_header
of a decl. We could create a global dummy_system_header_location and set
the location to that, but I don't think we need to.

OK for trunk if bootstraps and tests are OK?

2007-07-09  Rafael Avila de Espindola  <espindola@google.com>

	* c-decl.c (diagnose_mismatched_decls): Don't warn if TREE_NO_WARNING is
	set.
	(merge_decls): Port to new in_system_header API.
	* c-lex.c (fe_file_change): Port to new in_system_header API.
	* c-parser.c (c_token): Rename in_system_header to is_in_system_header.
	(c_lex_one_token): Rename in_system_header to is_in_system_header.
	(c_parser_set_source_position_from_token): Port to new
	in_system_header API.
	* flags.h (in_system_header): Remove.
	* function.c (saved_in_system_header): Remove.
	(push_cfun): Port to new in_system_header API.
	(pop_cfun): Port to new in_system_header API.
	(push_struct_function): Port to new in_system_header API.
	* input.h (expanded_location): Add sysp.
	(LOCATION_SYSP): New.
	* toplev.c (in_system_header): Remove.
	* tree-cfg.c (execute_warn_function_return): Port to new
	in_system_header API.
	* tree-ssa.c (warn_uninit): Port to new in_system_header API.
	* tree.c (make_node_stat): Port to new in_system_header API.
	(expand_location): Initialize xloc.sysp.
	* tree.h (DECL_IN_SYSTEM_HEADER): Port to new in_system_header API.
	(tree_decl_with_vis): Remove in_system_header_flag.

2007-07-09  Rafael Avila de Espindola  <espindola@google.com>

	* objc/objc-act.c (synth_module_prologue): Use TREE_NO_WARNING instead
	of DECL_IN_SYSTEM_HEADER.

2007-07-09  Rafael Avila de Espindola  <espindola@google.com>

	* cp/parser.c (cp_token): Rename in_system_header to
	is_in_system_header.
	(cp_lexer_get_preprocessor_token): Rename in_system_header to
	is_in_system_header.
	(cp_lexer_set_source_position_from_token): Port to new in_system_header
	API.
	(cp_parser_member_declaration): Port to new in_system_header API.
	* cp/pt.c (lookup_template_class): Port to new in_system_header API.
	(pop_tinst_level): Port to new in_system_header API.
	(instantiate_class_template): Port to new in_system_header API.
	(instantiate_decl): Port to new in_system_header API.
	(instantiate_pending_templates): Port to new in_system_header API.


> Tom
>

Cheers,
--
Rafael Avila de Espindola

Google Ireland Ltd.
Gordon House
Barrow Street
Dublin 4
Ireland

Registered in Dublin, Ireland
Registration Number: 368047
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 18ad119..ed5cbb0 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -1258,7 +1258,10 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
      header.  (Conflicting redeclarations were handled above.)  */
   if (TREE_CODE (newdecl) == TYPE_DECL)
     {
-      if (DECL_IN_SYSTEM_HEADER (newdecl) || DECL_IN_SYSTEM_HEADER (olddecl))
+      if (DECL_IN_SYSTEM_HEADER (newdecl)
+	  || DECL_IN_SYSTEM_HEADER (olddecl)
+	  || TREE_NO_WARNING (newdecl)
+	  || TREE_NO_WARNING (olddecl))
 	return true;  /* Allow OLDDECL to continue in use.  */
 
       error ("redefinition of typedef %q+D", newdecl);
@@ -1697,12 +1700,6 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
 
   if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS))
     {
-      /* Merge the unused-warning information.  */
-      if (DECL_IN_SYSTEM_HEADER (olddecl))
-	DECL_IN_SYSTEM_HEADER (newdecl) = 1;
-      else if (DECL_IN_SYSTEM_HEADER (newdecl))
-	DECL_IN_SYSTEM_HEADER (olddecl) = 1;
-
       /* Merge the section attribute.
 	 We want to issue an error if the sections conflict but that
 	 must be done later in decl_attributes since we are called
diff --git a/gcc/c-lex.c b/gcc/c-lex.c
index 3c2c225..9446916 100644
--- a/gcc/c-lex.c
+++ b/gcc/c-lex.c
@@ -239,7 +239,6 @@ fe_file_change (const struct line_map *new_map)
     }
 
   update_header_times (new_map->to_file);
-  in_system_header = new_map->sysp != 0;
   input_location = new_map->start_location;
 }
 
diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index 45aff80..185df29 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -258,7 +258,7 @@ typedef struct c_token GTY (())
      was seen.  Otherwise it is PRAGMA_NONE.  */
   ENUM_BITFIELD (pragma_kind) pragma_kind : 7;
   /* True if this token is from a system header.  */
-  BOOL_BITFIELD in_system_header : 1;
+  BOOL_BITFIELD is_in_system_header : 1;
   /* The value associated with this token, if any.  */
   tree value;
   /* The location at which this token was found.  */
@@ -314,7 +314,7 @@ c_lex_one_token (c_parser *parser, c_token *token)
   token->id_kind = C_ID_NONE;
   token->keyword = RID_MAX;
   token->pragma_kind = PRAGMA_NONE;
-  token->in_system_header = in_system_header;
+  token->is_in_system_header = in_system_header;
 
   switch (token->type)
     {
@@ -646,7 +646,6 @@ c_parser_set_source_position_from_token (c_token *token)
   if (token->type != CPP_EOF)
     {
       input_location = token->location;
-      in_system_header = token->in_system_header;
     }
 }
 
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 2323c67..45a27ea 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -72,7 +72,7 @@ typedef struct cp_token GTY (())
   /* Identifier for the pragma.  */
   ENUM_BITFIELD (pragma_kind) pragma_kind : 6;
   /* True if this token is from a system header.  */
-  BOOL_BITFIELD in_system_header : 1;
+  BOOL_BITFIELD is_in_system_header : 1;
   /* True if this token is from a context where it is implicitly extern "C" */
   BOOL_BITFIELD implicit_extern_c : 1;
   /* True for a CPP_NAME token that is not a keyword (i.e., for which
@@ -408,7 +408,7 @@ cp_lexer_get_preprocessor_token (cp_lexer *lexer, cp_token *token)
 			lexer == NULL ? 0 : C_LEX_RAW_STRINGS);
   token->keyword = RID_MAX;
   token->pragma_kind = PRAGMA_NONE;
-  token->in_system_header = in_system_header;
+  token->is_in_system_header = in_system_header;
 
   /* On some systems, some header files are surrounded by an
      implicit extern "C" block.  Set a flag in the token if it
@@ -478,15 +478,13 @@ cp_lexer_get_preprocessor_token (cp_lexer *lexer, cp_token *token)
     }
 }
 
-/* Update the globals input_location and in_system_header and the
-   input file stack from TOKEN.  */
+/* Update the globals input_location and the input file stack from TOKEN.  */
 static inline void
 cp_lexer_set_source_position_from_token (cp_token *token)
 {
   if (token->type != CPP_EOF)
     {
       input_location = token->location;
-      in_system_header = token->in_system_header;
     }
 }
 
@@ -15218,7 +15216,7 @@ cp_parser_member_declaration (cp_parser* parser)
       if (!decl_specifiers.any_specifiers_p)
 	{
 	  cp_token *token = cp_lexer_peek_token (parser->lexer);
-	  if (pedantic && !token->in_system_header)
+	  if (pedantic && !token->is_in_system_header)
 	    pedwarn ("%Hextra %<;%>", &token->location);
 	}
       else
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index cce706f..19ba10b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5888,8 +5888,6 @@ lookup_template_class (tree d1,
 	= TREE_PRIVATE (TYPE_STUB_DECL (template_type));
       TREE_PROTECTED (type_decl)
 	= TREE_PROTECTED (TYPE_STUB_DECL (template_type));
-      DECL_IN_SYSTEM_HEADER (type_decl)
-	= DECL_IN_SYSTEM_HEADER (template);
       if (CLASSTYPE_VISIBILITY_SPECIFIED (template_type))
 	{
 	  DECL_VISIBILITY_SPECIFIED (type_decl) = 1;
@@ -6338,7 +6336,6 @@ pop_tinst_level (void)
   /* Restore the filename and line number stashed away when we started
      this instantiation.  */
   input_location = current_tinst_level->locus;
-  in_system_header = current_tinst_level->in_system_header_p;
   current_tinst_level = current_tinst_level->next;
   --tinst_depth;
   ++tinst_level_tick;
@@ -6910,7 +6907,6 @@ instantiate_class_template (tree type)
      if tsubsting causes an error.  */
   typedecl = TYPE_MAIN_DECL (type);
   input_location = DECL_SOURCE_LOCATION (typedecl);
-  in_system_header = DECL_IN_SYSTEM_HEADER (typedecl);
 
   TYPE_HAS_USER_CONSTRUCTOR (type) = TYPE_HAS_USER_CONSTRUCTOR (pattern);
   TYPE_HAS_NEW_OPERATOR (type) = TYPE_HAS_NEW_OPERATOR (pattern);
@@ -15021,7 +15017,6 @@ instantiate_decl (tree d, int defer_ok,
   bool pattern_defined;
   int need_push;
   location_t saved_loc = input_location;
-  int saved_in_system_header = in_system_header;
   bool external_p;
 
   /* This function should only be used to instantiate templates for
@@ -15104,7 +15099,6 @@ instantiate_decl (tree d, int defer_ok,
     mark_definable (d);
 
   input_location = DECL_SOURCE_LOCATION (d);
-  in_system_header = DECL_IN_SYSTEM_HEADER (d);
 
   /* If D is a member of an explicitly instantiated class template,
      and no definition is available, treat it like an implicit
@@ -15376,7 +15370,6 @@ instantiate_decl (tree d, int defer_ok,
 
 out:
   input_location = saved_loc;
-  in_system_header = saved_in_system_header;
   pop_deferring_access_checks ();
   pop_tinst_level ();
 
@@ -15394,7 +15387,6 @@ instantiate_pending_templates (int retries)
 {
   int reconsider;
   location_t saved_loc = input_location;
-  int saved_in_system_header = in_system_header;
 
   /* Instantiating templates may trigger vtable generation.  This in turn
      may require further template instantiations.  We place a limit here
@@ -15478,7 +15470,6 @@ instantiate_pending_templates (int retries)
   while (reconsider);
 
   input_location = saved_loc;
-  in_system_header = saved_in_system_header;
 }
 
 /* Substitute ARGVEC into T, which is a list of initializers for
diff --git a/gcc/flags.h b/gcc/flags.h
index 1818a42..9fcc374 100644
--- a/gcc/flags.h
+++ b/gcc/flags.h
@@ -143,11 +143,6 @@ extern HOST_WIDE_INT larger_than_size;
 extern bool warn_frame_larger_than;
 extern HOST_WIDE_INT frame_larger_than_size;
 
-/* Temporarily suppress certain warnings.
-   This is set while reading code from a system header file.  */
-
-extern int in_system_header;
-
 /* Nonzero for -dp: annotate the assembly with a comment describing the
    pattern and alternative used.  */
 
diff --git a/gcc/function.c b/gcc/function.c
index d8234da..60099d7 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -3762,22 +3762,12 @@ DEF_VEC_ALLOC_P(function_p,heap);
 
 static VEC(function_p,heap) *cfun_stack;
 
-/* We save the value of in_system_header here when pushing the first
-   function on the cfun stack, and we restore it from here when
-   popping the last function.  */
-
-static bool saved_in_system_header;
-
 /* Push the current cfun onto the stack, and set cfun to new_cfun.  */
 
 void
 push_cfun (struct function *new_cfun)
 {
-  if (cfun == NULL)
-    saved_in_system_header = in_system_header;
   VEC_safe_push (function_p, heap, cfun_stack, cfun);
-  if (new_cfun)
-    in_system_header = DECL_IN_SYSTEM_HEADER (new_cfun->decl);
   set_cfun (new_cfun);
 }
 
@@ -3787,8 +3777,6 @@ void
 pop_cfun (void)
 {
   struct function *new_cfun = VEC_pop (function_p, cfun_stack);
-  in_system_header = ((new_cfun == NULL) ? saved_in_system_header
-		      : DECL_IN_SYSTEM_HEADER (new_cfun->decl));
   set_cfun (new_cfun);
 }
 
@@ -3866,11 +3854,7 @@ allocate_struct_function (tree fndecl, bool abstract_p)
 void
 push_struct_function (tree fndecl)
 {
-  if (cfun == NULL)
-    saved_in_system_header = in_system_header;
   VEC_safe_push (function_p, heap, cfun_stack, cfun);
-  if (fndecl)
-    in_system_header = DECL_IN_SYSTEM_HEADER (fndecl);
   allocate_struct_function (fndecl, false);
 }
 
diff --git a/gcc/input.h b/gcc/input.h
index 5d43259..76ec19d 100644
--- a/gcc/input.h
+++ b/gcc/input.h
@@ -41,6 +41,9 @@ typedef struct GTY (())
   int line;
 
   int column;
+
+  /* In a system header?. */
+  unsigned char sysp;
 } expanded_location;
 
 extern expanded_location expand_location (source_location);
@@ -56,8 +59,10 @@ extern location_t input_location;
 
 #define LOCATION_FILE(LOC) ((expand_location (LOC)).file)
 #define LOCATION_LINE(LOC) ((expand_location (LOC)).line)
+#define LOCATION_SYSP(LOC) ((expand_location (LOC)).sysp)
 
 #define input_line LOCATION_LINE (input_location)
 #define input_filename LOCATION_FILE (input_location)
+#define in_system_header (LOCATION_SYSP (input_location) != 0)
 
 #endif
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 4aef9a0..efc6766 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -1555,11 +1555,11 @@ synth_module_prologue (void)
   type = lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
 						objc_object_name,
 						objc_object_type));
-  DECL_IN_SYSTEM_HEADER (type) = 1;
+  TREE_NO_WARNING (type) = 1;
   type = lang_hooks.decls.pushdecl (build_decl (TYPE_DECL,
 						objc_class_name,
 						objc_class_type));
-  DECL_IN_SYSTEM_HEADER (type) = 1;
+  TREE_NO_WARNING (type) = 1;
 
   /* Forward-declare '@interface Protocol'.  */
 
diff --git a/gcc/toplev.c b/gcc/toplev.c
index a35c105..827b8f5 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -202,11 +202,6 @@ tree current_function_decl;
    if none.  */
 const char * current_function_func_begin_label;
 
-/* Temporarily suppress certain warnings.
-   This is set while reading code from a system header file.  */
-
-int in_system_header = 0;
-
 /* Nonzero means to collect statistics which might be expensive
    and to print them when we are done.  */
 int flag_detailed_statistics = 0;
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 341a1de..65ef8c2 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -7197,10 +7197,13 @@ execute_warn_function_return (void)
 	      && TREE_OPERAND (last, 0) == NULL
 	      && !TREE_NO_WARNING (last))
 	    {
+	      location_t saved_input_location = input_location;
 	      location = EXPR_LOCATION (last);
 	      if (location == UNKNOWN_LOCATION)
 		  location = cfun->function_end_locus;
+	      input_location = location;
 	      warning (OPT_Wreturn_type, "%Hcontrol reaches end of non-void function", &location);
+	      input_location = saved_input_location;
 	      TREE_NO_WARNING (cfun->decl) = 1;
 	      break;
 	    }
diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
index 7f567b5..7e049ef 100644
--- a/gcc/tree-ssa.c
+++ b/gcc/tree-ssa.c
@@ -1373,6 +1373,7 @@ warn_uninit (tree t, const char *gmsgid, void *data)
   tree context = (tree) data;
   location_t *locus;
   expanded_location xloc, floc;
+  location_t saved_input_location;
 
   if (!ssa_undefined_value_p (t))
     return;
@@ -1385,7 +1386,10 @@ warn_uninit (tree t, const char *gmsgid, void *data)
   locus = (context != NULL && EXPR_HAS_LOCATION (context)
 	   ? EXPR_LOCUS (context)
 	   : &DECL_SOURCE_LOCATION (var));
+  saved_input_location = input_location;
+  input_location = DECL_SOURCE_LOCATION (cfun->decl);
   warning (OPT_Wuninitialized, gmsgid, locus, var);
+  input_location = saved_input_location;
   xloc = expand_location (*locus);
   floc = expand_location (DECL_SOURCE_LOCATION (cfun->decl));
   if (xloc.file != floc.file
diff --git a/gcc/tree.c b/gcc/tree.c
index 97b53bd..31e0715 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -622,8 +622,6 @@ make_node_stat (enum tree_code code MEM_STAT_DECL)
       break;
 
     case tcc_declaration:
-      if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
-	DECL_IN_SYSTEM_HEADER (t) = in_system_header;
       if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
 	{
 	  if (code == FUNCTION_DECL)
@@ -3524,6 +3522,7 @@ expand_location (source_location loc)
       xloc.file = NULL;
       xloc.line = 0;
       xloc.column = 0;
+      xloc.sysp = 0;
     }
   else
     {
@@ -3531,6 +3530,7 @@ expand_location (source_location loc)
       xloc.file = map->to_file;
       xloc.line = SOURCE_LINE (map, loc);
       xloc.column = SOURCE_COLUMN (map, loc);
+      xloc.sysp = map->sysp;
     };
   return xloc;
 }
diff --git a/gcc/tree.h b/gcc/tree.h
index e6b9f9c..f5c72b8 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3051,7 +3051,7 @@ struct tree_parm_decl GTY(())
 /* Nonzero for a given ..._DECL node means that no warnings should be
    generated just because this node is unused.  */
 #define DECL_IN_SYSTEM_HEADER(NODE) \
-  (DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.in_system_header_flag)
+  (LOCATION_SYSP(DECL_SOURCE_LOCATION (NODE)) != 0)
 
   /* Used to indicate that this DECL has weak linkage.  */
 #define DECL_WEAK(NODE) (DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.weak_flag)
@@ -3179,7 +3179,6 @@ struct tree_decl_with_vis GTY(())
  unsigned shadowed_for_var_p : 1;
 
  /* Don't belong to VAR_DECL exclusively.  */
- unsigned in_system_header_flag : 1;
  unsigned weak_flag:1;
  unsigned seen_in_bind_expr : 1;
  unsigned comdat_flag : 1;

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