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]

[PATCH] Register 3 builtins needed for -finstrument-functions in generic code (PR middle-end/49675)


Hi!

-finstrument-functions with any function written in Fortran, Go (and
presumably also Java and Ada, haven't tried) fails because
non-C/C++ FEs don't register __builtin_return_address (),
__cyg_profile_func_enter () and __cyg_profile_func_exit () builtins.
This worked until 4.5 because gimplification used
__builtin_profile_func_{enter,exit} () for
__cyg_profile_func_{enter,exit} (fn, __builtin_return_address ())
and expanded it that way only during expansion.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk/4.6?

2011-07-18  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/49675
	* tree.c (build_common_builtin_nodes): Register
	__builtin_return_address, __cyg_profile_func_enter
	and __cyg_profile_func_exit.

	* gfortran.dg/pr49675.f90: New test.

--- gcc/tree.c.jj	2011-07-13 17:31:18.000000000 +0200
+++ gcc/tree.c	2011-07-18 09:35:25.000000000 +0200
@@ -9546,6 +9546,31 @@ build_common_builtin_nodes (void)
 			 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
 			ECF_NORETURN);
 
+  if (built_in_decls[BUILT_IN_RETURN_ADDRESS] == NULL_TREE)
+    {
+      ftype = build_function_type_list (ptr_type_node, integer_type_node,
+					NULL_TREE);
+      local_define_builtin ("__builtin_return_address", ftype,
+			    BUILT_IN_RETURN_ADDRESS,
+			    "__builtin_return_address",
+			    ECF_NOTHROW);
+    }
+
+  if (built_in_decls[BUILT_IN_PROFILE_FUNC_ENTER] == NULL_TREE
+      || built_in_decls[BUILT_IN_PROFILE_FUNC_EXIT] == NULL_TREE)
+    {
+      ftype = build_function_type_list (void_type_node, ptr_type_node,
+					ptr_type_node, NULL_TREE);
+      if (built_in_decls[BUILT_IN_PROFILE_FUNC_ENTER] == NULL_TREE)
+	local_define_builtin ("__cyg_profile_func_enter", ftype,
+			      BUILT_IN_PROFILE_FUNC_ENTER,
+			      "__cyg_profile_func_enter", 0);
+      if (built_in_decls[BUILT_IN_PROFILE_FUNC_EXIT] == NULL_TREE)
+	local_define_builtin ("__cyg_profile_func_exit", ftype,
+			      BUILT_IN_PROFILE_FUNC_EXIT,
+			      "__cyg_profile_func_exit", 0);
+    }
+
   /* The exception object and filter values from the runtime.  The argument
      must be zero before exception lowering, i.e. from the front end.  After
      exception lowering, it will be the region number for the exception
--- gcc/testsuite/gfortran.dg/pr49675.f90.jj	2011-07-18 09:40:50.000000000 +0200
+++ gcc/testsuite/gfortran.dg/pr49675.f90	2011-07-18 09:39:55.000000000 +0200
@@ -0,0 +1,6 @@
+! PR middle-end/49675
+! { dg-do compile }
+! { dg-options "-finstrument-functions" }
+end
+! { dg-final { scan-assembler "__cyg_profile_func_enter" } }
+! { dg-final { scan-assembler "__cyg_profile_func_exit" } }

	Jakub


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