From 994fc9abdde826d0b843b48e8ef1627295c3ae25 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Fri, 20 Aug 2010 20:49:46 +0200
Subject: [PATCH] re PR middle-end/44974 (Function with attribute noreturn
 omits a call to another function with noreturn)

	PR middle-end/44974
	* builtins.c (expand_builtin): Don't optimize away
	calls to DECL_LOOPING_CONST_OR_PURE_P builtins.

	* gcc.dg/pr44974.c: New test.

From-SVN: r163415
---
 gcc/ChangeLog                  |  6 ++++++
 gcc/builtins.c                 |  3 ++-
 gcc/testsuite/ChangeLog        |  3 +++
 gcc/testsuite/gcc.dg/pr44974.c | 23 +++++++++++++++++++++++
 4 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr44974.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 367480517486..1cfd27ef8fd1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2010-08-20  Jakub Jelinek  <jakub@redhat.com>
+
+	PR middle-end/44974
+	* builtins.c (expand_builtin): Don't optimize away
+	calls to DECL_LOOPING_CONST_OR_PURE_P builtins.
+
 2010-08-20  Uros Bizjak  <ubizjak@gmail.com>
 
 	* config/i386/i386.md (ashift RSP splitter): Remove splitter.
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 9a79adbece27..e8974e1bbc22 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -5770,7 +5770,8 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode,
      none of its arguments are volatile, we can avoid expanding the
      built-in call and just evaluate the arguments for side-effects.  */
   if (target == const0_rtx
-      && (DECL_PURE_P (fndecl) || TREE_READONLY (fndecl)))
+      && (DECL_PURE_P (fndecl) || TREE_READONLY (fndecl))
+      && !DECL_LOOPING_CONST_OR_PURE_P (fndecl))
     {
       bool volatilep = false;
       tree arg;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0c1b613c7df1..358033100158 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2010-08-20  Jakub Jelinek  <jakub@redhat.com>
 
+	PR middle-end/44974
+	* gcc.dg/pr44974.c: New test.
+
 	PR rtl-optimization/45353
 	* gcc.dg/pr45353.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr44974.c b/gcc/testsuite/gcc.dg/pr44974.c
new file mode 100644
index 000000000000..14e43ece3c2d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr44974.c
@@ -0,0 +1,23 @@
+/* PR middle-end/44974 */
+/* { dg-do compile } */
+/* { dg-options "-O -fno-optimize-sibling-calls" } */
+
+extern void foo (int status) __attribute__ ((__noreturn__));
+extern void bar (int status) __attribute__ ((__noreturn__));
+extern void _Exit (int status) __attribute__ ((__noreturn__));
+
+void
+foo (int status)
+{
+  _Exit (status);
+}
+
+void
+_Exit (int status)
+{
+  bar (status);
+}
+
+/* { dg-final { scan-assembler "call\[^\n\]*_Exit" { target i?86-*-* x86_64-*-* ia64-*-* sparc*-*-* } } } */
+/* { dg-final { scan-assembler "bl\[^\n\]*_Exit" { target powerpc*-*-* } } } */
+/* { dg-final { scan-assembler "brasl\[^\n\]*_Exit" { target { s390*-*-* && lp64 } } } } */
-- 
GitLab