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]

Function declaration compatibility with old noreturn syntax


This is intended to fix this sort of thing:

extern void xxx (int) __attribute__((noreturn));
__volatile extern void xxx (int);

... which at present doesn't work.  'volatile' was the only way to
specify noreturn semantics in GCC 2.5.1 and earlier, and it's hard to
transition if you have to do it all at once.

Of course, in ISO C, this is supposed to not work, so there's now a
testcase for that too.

Bootstrapped & tested on powerpc-darwin.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-volatileretval.patch==================
2003-04-29  Geoffrey Keating  <geoffk@apple.com>

	* c-typeck.c (function_types_compatible_p): Ignore incompatible
	'volatile' qualifiers on a function's return type in GNU mode.

Index: testsuite/ChangeLog
2003-04-29  Geoffrey Keating  <geoffk@apple.com>

	* gcc.dg/noreturn-5.c: New file.
	* gcc.dg/noreturn-6.c: New file.

Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.234
diff -u -p -u -p -r1.234 c-typeck.c
--- c-typeck.c	20 Apr 2003 22:43:59 -0000	1.234
+++ c-typeck.c	30 Apr 2003 01:19:49 -0000
@@ -630,9 +630,23 @@ function_types_compatible_p (f1, f2)
   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
   int val = 1;
   int val1;
+  tree ret1, ret2;
 
-  if (!(TREE_TYPE (f1) == TREE_TYPE (f2)
-	|| (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2)))))
+  ret1 = TREE_TYPE (f1);
+  ret2 = TREE_TYPE (f2);
+
+  /* 'volatile' qualifiers on a function's return type mean the function
+     is noreturn.  */
+  if (pedantic && TYPE_VOLATILE (ret1) != TYPE_VOLATILE (ret2))
+    pedwarn ("function return types not compatible due to `volatile'");
+  if (TYPE_VOLATILE (ret1))
+    ret1 = build_qualified_type (TYPE_MAIN_VARIANT (ret1),
+				 TYPE_QUALS (ret1) & ~TYPE_QUAL_VOLATILE);
+  if (TYPE_VOLATILE (ret2))
+    ret2 = build_qualified_type (TYPE_MAIN_VARIANT (ret2),
+				 TYPE_QUALS (ret2) & ~TYPE_QUAL_VOLATILE);
+  val = comptypes (ret1, ret2);
+  if (val == 0)
     return 0;
 
   args1 = TYPE_ARG_TYPES (f1);
Index: testsuite/gcc.dg/noreturn-5.c
===================================================================
RCS file: testsuite/gcc.dg/noreturn-5.c
diff -N testsuite/gcc.dg/noreturn-5.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/noreturn-5.c	30 Apr 2003 01:20:00 -0000
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+/* Check that 'noreturn' and 'volatile extern' are compatible.  
+   The testsuite uses -ansi -pedantic-errors by default, so this has
+   to override.  */
+extern void xxx (int) __attribute__((noreturn));
+__volatile extern void xxx (int);
Index: testsuite/gcc.dg/noreturn-6.c
===================================================================
RCS file: testsuite/gcc.dg/noreturn-6.c
diff -N testsuite/gcc.dg/noreturn-6.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/noreturn-6.c	30 Apr 2003 01:20:00 -0000
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* Check for volatile behaviour.  */
+extern int xxx (void);
+volatile extern int xxx (void);  /* { dg-error "not compatible" } */
============================================================


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