[patch] Fix PR lto/50492

Eric Botcazou ebotcazou@adacore.com
Fri Oct 7 11:14:00 GMT 2011


this is another LTO bootstrap failure with Ada enabled.  There are 2 problems:

 1. dwarf2out.c thinks that it is processing pure C++ code for gnat1 so it is 
invoking some C++-specific code paths that aren't compatible with Ada.  Fixed 
by building TRANSLATION_UNIT_DECL nodes in Ada as well.

 2. the recent change:

	* gimple.c (canonicalize_cond_expr_cond): Handle cast from

breaks cross-language inlining.  More specifically, it removes a necessary cast 
between an Ada boolean type and a C boolean type (hence a GIMPLE verification 
failure later) when __gnat_is_absolute_path is inlined into Is_Absolute_Path:

   extern int __gnat_is_absolute_path (char *, int);

   function Is_Absolute_Path (Name : String) return Boolean is
      function Is_Absolute_Path
        (Name   : Address;
         Length : Integer) return Integer;
      pragma Import (C, Is_Absolute_Path, "__gnat_is_absolute_path");
      return Is_Absolute_Path (Name'Address, Name'Length) /= 0;
   end Is_Absolute_Path;

We start with:

  Ada_Boolean_Var = (Integer_Var != 0);

and forwprop figures out that (Integer_Var != 0) is equivalent to iftmp.xxx.
In combine_cond_expr_cond, the constant folder correctly turns this into:

  Ada_Boolean_Var = (Ada_Boolean_Type) iftmp.xxx;

but the call to canonicalize_cond_expr_cond wrongly removes the cast.

Note that changing Ada's boolean_type_node to a C-compatible type doesn't fix 
the problem as the boolean return type of Is_Absolute_Path has to be an Ada 
boolean type in any case, so a cast will be always necessary here.

Since reverting the canonicalize_cond_expr_cond change apparently has no effect 
(no regressions detected on x86 and x86-64), the proposed fix is just that.

Bootstrapped/regtested on x86_64-suse-linux, OK for mainline?

2011-10-07  Eric Botcazou  <ebotcazou@adacore.com>

	PR lto/50492
	* gimple.c (canonicalize_cond_expr_cond): Revert 2011-08-02 change.
	* gcc-interface/gigi.h (gnat_pushdecl): Adjust comment.
	* gcc-interface/utils.c (global_context): New variable.
	(gnat_pushdecl): Initialize it and set it as the DECL_CONTEXT of DECLs
	that are either public external or at top level.  Use "No" macro.
	(end_subprog_body): Call decl_function_context.
	(rest_of_subprog_body_compilation): Likewise.

Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr50492.diff
Type: text/x-diff
Size: 3943 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20111007/1c2af90b/attachment.bin>

More information about the Gcc-patches mailing list