public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch c,c++,i386]:PR/15774 - Conflicting function decls not diagnosed
@ 2010-12-22 14:53 Kai Tietz
  2010-12-22 14:58 ` Dave Korn
  2010-12-22 17:21 ` Joseph S. Myers
  0 siblings, 2 replies; 19+ messages in thread
From: Kai Tietz @ 2010-12-22 14:53 UTC (permalink / raw)
  To: GCC Patches; +Cc: Joseph S. Myers, Jason Merrill, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 1000 bytes --]

Hi,  this patch fixes the bug described at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15774 in bugzilla.
It takes care that for function pointer types also the
calling-convention modifying attributes can be
displayed.  I added an implementation for the i386 architecture.

Tested for i686-pc-cygwin, i686-pc-mingw32, and x86_64-w64-mingw32.

ChangeLog

2010-12-22  Kai Tietz

	PR c++/15774
	* c-family/c-pretty-print.c: Add target.h include.
	(pp_c_specifier_qualifier_list): Call
	pp_c_attributes_calling_convention for (*).
	(pp_c_attributes_calling_convention): New.
	* c-family/c-pretty-print.h (pp_c_attributes_calling_convention):
	New prototype.
	* cp/error.c (dump_type_prefix): Call
	pp_c_attributes_calling_convention for (*).
	* config/i386/i386.c (ix86_attribute_affects_calling_convention):
	New hook.
	(TARGET_ATTRIBUTE_AFFECTS_CALLING_CONVENTION): Define.
	* doc/tm.texi.in (TARGET_ATTRIBUTE_AFFECTS_CALLING_CONVENTION): Add.
	* doc/tm.texi: Regenerated.

Ok for apply?

Regards,
Kai

[-- Attachment #2: dispcallcvt.txt --]
[-- Type: text/plain, Size: 6407 bytes --]

Index: gcc/gcc/c-family/c-pretty-print.c
===================================================================
--- gcc.orig/gcc/c-family/c-pretty-print.c	2010-12-22 13:43:53.651439000 +0100
+++ gcc/gcc/c-family/c-pretty-print.c	2010-12-22 14:04:32.807689000 +0100
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3.  
 #include "tree-pretty-print.h"
 #include "tree-iterator.h"
 #include "diagnostic.h"
+#include "target.h"
 
 /* Translate if being used for diagnostics, but not for dump files or
    __PRETTY_FUNCTION.  */
@@ -460,6 +461,7 @@ pp_c_specifier_qualifier_list (c_pretty_
 	  {
 	    pp_c_whitespace (pp);
 	    pp_c_left_paren (pp);
+	    pp_c_attributes_calling_convention (pp, TYPE_ATTRIBUTES (pointee));
 	  }
 	else if (!c_dialect_cxx ())
 	  pp_c_whitespace (pp);
@@ -790,6 +792,45 @@ pp_c_attributes (c_pretty_printer *pp, t
   pp_c_right_paren (pp);
 }
 
+/* Pretty-print ATTRIBUTES using GNU C extension syntax for calling
+   convention affecting attributes.  */
+
+void
+pp_c_attributes_calling_convention (c_pretty_printer *pp, tree a)
+{
+  int is_first = 1;
+
+  if (a == NULL_TREE)
+    return;
+
+  for (; a != NULL_TREE; a = TREE_CHAIN (a))
+    {
+      if (!targetm.attribute_affects_calling_convention (TREE_PURPOSE (a)))
+        continue;
+      if (is_first)
+	{
+	  pp_c_ws_string (pp, "__attribute__");
+	  pp_c_left_paren (pp);
+	  pp_c_left_paren (pp);
+	  is_first = 0;
+	}
+      else
+	{
+	  pp_separate_with (pp, ',');
+	}
+      pp_tree_identifier (pp, TREE_PURPOSE (a));
+      if (TREE_VALUE (a))
+	pp_c_call_argument_list (pp, TREE_VALUE (a));
+    }
+
+  if (!is_first)
+    {
+      pp_c_right_paren (pp);
+      pp_c_right_paren (pp);
+      pp_c_whitespace (pp);
+    }
+}
+
 /* function-definition:
       declaration-specifiers declarator compound-statement  */
 
Index: gcc/gcc/cp/error.c
===================================================================
--- gcc.orig/gcc/cp/error.c	2010-12-22 13:43:53.681439000 +0100
+++ gcc/gcc/cp/error.c	2010-12-22 14:05:38.526439000 +0100
@@ -661,6 +661,8 @@ dump_type_prefix (tree t, int flags)
 	  {
 	    pp_cxx_whitespace (cxx_pp);
 	    pp_cxx_left_paren (cxx_pp);
+	    pp_c_attributes_calling_convention (pp_c_base (cxx_pp),
+						TYPE_ATTRIBUTES (sub));
 	  }
 	if (TREE_CODE (t) == POINTER_TYPE)
 	  pp_character(cxx_pp, '*');
Index: gcc/gcc/c-family/c-pretty-print.h
===================================================================
--- gcc.orig/gcc/c-family/c-pretty-print.h	2010-12-22 13:43:53.676439000 +0100
+++ gcc/gcc/c-family/c-pretty-print.h	2010-12-22 13:45:49.479564000 +0100
@@ -176,6 +176,7 @@ void pp_c_space_for_pointer_operator (c_
 void pp_c_tree_decl_identifier (c_pretty_printer *, tree);
 void pp_c_function_definition (c_pretty_printer *, tree);
 void pp_c_attributes (c_pretty_printer *, tree);
+void pp_c_attributes_calling_convention (c_pretty_printer *, tree);
 void pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type);
 void pp_c_type_qualifier_list (c_pretty_printer *, tree);
 void pp_c_parameter_type_list (c_pretty_printer *, tree);
Index: gcc/gcc/config/i386/i386.c
===================================================================
--- gcc.orig/gcc/config/i386/i386.c	2010-12-22 13:43:53.679439000 +0100
+++ gcc/gcc/config/i386/i386.c	2010-12-22 14:19:21.091890600 +0100
@@ -5116,6 +5116,46 @@ ix86_function_ok_for_sibcall (tree decl,
   return true;
 }
 
+static bool
+ix86_attribute_affects_calling_convention (tree name)
+{
+  int ident_len;
+  const char *p;
+
+  gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+  p = IDENTIFIER_POINTER (name);
+  ident_len = IDENTIFIER_LENGTH (name);
+
+  if (ident_len > 4 && p[0] == '_' && p[1] == '_' && p[ident_len - 1] == '_'
+      && p[ident_len - 2] == '_')
+    {
+      ident_len -= 4;
+      p += 2;
+    }
+  switch (ident_len)
+    {
+    case 5:
+      if (!strncmp (p, "cdecl", 5))
+        return true;
+      break;
+    case 6:
+      if (!strncmp (p, "ms_abi", 6))
+        return true;
+      break;
+    case 7:
+      if (!strncmp (p, "regparm", 7) || !strncmp (p, "stdcall", 7))
+        return true;
+      break;
+    case 8:
+      if (!strncmp (p, "thiscall", 8) || !strncmp (p, "fastcall", 8)
+          || !strncmp (p, "sysv_abi", 8))
+        return true;
+      break;
+    }
+
+  return false;
+}
+
 /* Handle "cdecl", "stdcall", "fastcall", "regparm", "thiscall",
    and "sseregparm" calling convention attributes;
    arguments as in struct attribute_spec.handler.  */
@@ -34813,6 +34853,10 @@ ix86_autovectorize_vector_sizes (void)
 #undef TARGET_CONDITIONAL_REGISTER_USAGE
 #define TARGET_CONDITIONAL_REGISTER_USAGE ix86_conditional_register_usage
 
+#undef TARGET_ATTRIBUTE_AFFECTS_CALLING_CONVENTION
+#define TARGET_ATTRIBUTE_AFFECTS_CALLING_CONVENTION \
+  ix86_attribute_affects_calling_convention
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 #include "gt-i386.h"
Index: gcc/gcc/doc/tm.texi
===================================================================
--- gcc.orig/gcc/doc/tm.texi	2010-12-22 13:43:53.683439000 +0100
+++ gcc/gcc/doc/tm.texi	2010-12-22 14:18:28.230485800 +0100
@@ -9752,6 +9752,10 @@ when this is needed are when one attribu
 attribute is nullified by a subsequent definition.  This function may
 call @code{merge_attributes} to handle machine-independent merging.
 
+@deftypefn {Target Hook} bool TARGET_ATTRIBUTE_AFFECTS_CALLING_CONVENTION (const_tree @var{name})
+Returns @code{true} if given attribute by its @var{name} affects calling convention, otherwise @code{false}.
+@end deftypefn
+
 @findex TARGET_DLLIMPORT_DECL_ATTRIBUTES
 If the only target-specific handling you require is @samp{dllimport}
 for Microsoft Windows targets, you should define the macro
Index: gcc/gcc/doc/tm.texi.in
===================================================================
--- gcc.orig/gcc/doc/tm.texi.in	2010-12-22 13:43:53.000000000 +0100
+++ gcc/gcc/doc/tm.texi.in	2010-12-22 14:16:28.788399400 +0100
@@ -9716,6 +9716,8 @@ when this is needed are when one attribu
 attribute is nullified by a subsequent definition.  This function may
 call @code{merge_attributes} to handle machine-independent merging.
 
+@hook TARGET_ATTRIBUTE_AFFECTS_CALLING_CONVENTION
+
 @findex TARGET_DLLIMPORT_DECL_ATTRIBUTES
 If the only target-specific handling you require is @samp{dllimport}
 for Microsoft Windows targets, you should define the macro

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2010-12-23  2:26 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-22 14:53 [patch c,c++,i386]:PR/15774 - Conflicting function decls not diagnosed Kai Tietz
2010-12-22 14:58 ` Dave Korn
2010-12-22 15:11   ` Kai Tietz
2010-12-22 15:54     ` Gabriel Dos Reis
2010-12-22 16:21       ` Kai Tietz
2010-12-22 16:31         ` Gabriel Dos Reis
2010-12-22 16:38           ` Kai Tietz
2010-12-22 17:21 ` Joseph S. Myers
2010-12-22 17:38   ` Gabriel Dos Reis
2010-12-22 17:55   ` Kai Tietz
2010-12-22 17:57     ` Joseph S. Myers
2010-12-22 18:03       ` Kai Tietz
2010-12-22 18:10         ` Kai Tietz
2010-12-22 19:13         ` Joseph S. Myers
2010-12-22 18:24   ` Jason Merrill
2010-12-22 19:23     ` Kai Tietz
2010-12-22 19:25       ` Kai Tietz
2010-12-22 20:37         ` Kai Tietz
2010-12-23  8:19       ` Gabriel Dos Reis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).