diff mbox

[Ada] Spurious inlining error with function completed by an expression function

Message ID 20160418095230.GA117794@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 18, 2016, 9:52 a.m. UTC
This patch fixes a spurious error on a call to an expression function whose
expression is a call to a function whose full declaration is another expression
function, when compiling with optimization and inlining warnings enabled.

The following must compile quietly:

   gcc -c p.adb -gnatn -O -fdump-tree-optimized
   grep is_two p.adb.*.optimized

---
with Q; use Q;
procedure P is
begin
  if not Is_Two (2) then
    raise Program_Error;
  end if;
end;
---
with R; use R;
package Q is

  function Is_Two (I : Integer) return Boolean;

private
  function Is_Two (I : Integer) return Boolean is (Is_One (I - 1));
end Q;
---
package R is
  function Is_One (I : Integer) return Boolean is (I = 1);

  pragma Inline_Always (Is_One);
end R;

Tested on x86_64-pc-linux-gnu, committed on trunk

2016-04-18  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch6.adb (Analyze_Expression_Function): Set Inlined flag
	on the entity of a subprogram declaration that is completed by
	an expression function.
diff mbox

Patch

Index: sem_ch6.adb
===================================================================
--- sem_ch6.adb	(revision 235093)
+++ sem_ch6.adb	(working copy)
@@ -362,7 +362,7 @@ 
          Set_Is_Inlined (Prev);
 
       --  If the expression function is a completion, the previous declaration
-      --  must come from source. We know already that appears in the current
+      --  must come from source. We know already that it appears in the current
       --  scope. The entity itself may be internally created if within a body
       --  to be inlined.
 
@@ -371,6 +371,7 @@ 
         and then not Is_Formal_Subprogram (Prev)
       then
          Set_Has_Completion (Prev, False);
+         Set_Is_Inlined (Prev);
 
          --  An expression function that is a completion freezes the
          --  expression. This means freezing the return type, and if it is
@@ -411,7 +412,6 @@ 
          --  Not clear that the backend can inline it in this case ???
 
          if Has_Completion (Prev) then
-            Set_Is_Inlined (Prev);
 
             --  The formals of the expression function are body formals,
             --  and do not appear in the ali file, which will only contain