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]

Testcase: missing noreturn attribute on std::abort & std::exit


G++ doesn't know that std::abort and std::exit are noreturn functions.
If we can assume that they are, this fact results in missed
optimization opportunities and spurious warnings as demonstrated by
the attached testcase.  I should get zero warnings but instead I get:

 > g++.dg/warn/noreturn1.C: In function `int foo2(int)':
 > g++.dg/warn/noreturn1.C:28: warning: control reaches end of non-void function
 > g++.dg/warn/noreturn1.C: In function `int foo4(int)':
 > g++.dg/warn/noreturn1.C:50: warning: control reaches end of non-void function
 > g++.dg/warn/noreturn1.C: In function `void foo6()':
 > g++.dg/warn/noreturn1.C:60: warning: `noreturn' function does return
 > g++.dg/warn/noreturn1.C: In function `void foo8()':
 > g++.dg/warn/noreturn1.C:70: warning: `noreturn' function does return


Note we probably have the same problem with other attributes on system
functions like attribute malloc on std::malloc, etc.  (I haven't
verified that however.)

I don't know how to fix this, but in the mean time ok to install the
test?

		Thanks,
		--Kaveh


2002-06-18  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* g++.dg/warn/noreturn1.C: New test.

diff -rup orig/egcc-CVS20020617/gcc/testsuite/g++.dg/warn/noreturn1.C egcc-CVS20020617/gcc/testsuite/g++.dg/warn/noreturn1.C
--- orig/egcc-CVS20020617/gcc/testsuite/g++.dg/warn/noreturn1.C	2002-06-18 11:18:42.351544533 -0400
+++ egcc-CVS20020617/gcc/testsuite/g++.dg/warn/noreturn1.C	2002-06-18 11:17:22.456971774 -0400
@@ -0,0 +1,70 @@
+// Test that noreturn attributes are properly set.
+// Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> 2002-06-18.
+// { dg-do compile }
+// { dg-options "-Wall -O2" }
+
+#include <cstdlib>
+
+int foo1 (int i)
+{
+  switch (i)
+    {
+    case 1:
+    case 2:
+      return i;
+    }
+  abort();
+}
+
+int foo2 (int i)
+{
+  switch (i)
+    {
+    case 1:
+    case 2:
+      return i;
+    }
+  std::abort();
+}
+
+int foo3 (int i)
+{
+  switch (i)
+    {
+    case 1:
+    case 2:
+      return i;
+    }
+  exit(1);
+}
+
+int foo4 (int i)
+{
+  switch (i)
+    {
+    case 1:
+    case 2:
+      return i;
+    }
+  std::exit(1);
+}
+
+void __attribute__ ((__noreturn__)) foo5 ()
+{
+  abort();
+}
+
+void __attribute__ ((__noreturn__)) foo6 ()
+{
+  std::abort();
+}
+
+void __attribute__ ((__noreturn__)) foo7 ()
+{
+  exit(1);
+}
+
+void __attribute__ ((__noreturn__)) foo8 ()
+{
+  std::exit(1);
+}


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