This is the mail archive of the gcc-bugs@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]

[Bug ada/62117] [4.9 regression] wrong code for passing small array argument'Address, in generic


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62117

--- Comment #3 from yuta tomino <demoonlit at panathenaia dot halfmoon.jp> ---
I understood by trial and error that pragma Pure_Function is equivalent to
__attribute__((const)).
I'm sorry. The first case (in my first description) is not compiler's bug but
my mistake. The parameters Left and Right were erased by optimization because
compiler assumed that Pure_Function does not dereference, in my current
understanding.

Also, the case2 (in comment 2) is not reproduced by gcc-5.
However, the reason is that System.Fat_Flt.Unaligned_Valid is removed on gcc-5.


...By the way, I found an another point that I'm concerned.

In the document of pragma Pure_Function, a function having Address parameter is
not considered as Pure_Function.

https://gcc.gnu.org/onlinedocs/gnat_rm/Pragma-Pure_005fFunction.html

> One exception is any function that has at least one formal of type System.Address or a type derived from it. Such functions are not considered pure by default,

But,

with System;
package case3_p is
   pragma Pure;
   function F (X : System.Address) return System.Address;
end case3_p;

package body case3_p is
   function F (X : System.Address) return System.Address is
   begin
      return X;
   end F;
end case3_p;

with case3_p;
with System.Storage_Elements; use System.Storage_Elements;
with GNAT.IO;
procedure case3_m is
begin
   GNAT.IO.Put (Integer (To_Integer (case3_p.F (System'To_Address (10)))));
   GNAT.IO.Put (Integer (To_Integer (case3_p.F (System'To_Address (10)))));
   GNAT.IO.Put (Integer (To_Integer (case3_p.F (System'To_Address (10)))));
end case3_m;

Compile this case3_m.adb with optimization.

% gcc -S -O -gnatp case3_m.adb

    .text
    .globl __ada_case3_m
__ada_case3_m:
LFB1:
    pushq    %rbx
LCFI0:
    movl    $10, %edi
    call    _case3_p__f
    movq    %rax, %rbx
    movl    %eax, %edi
    call    _gnat__io__put__2
    movl    %ebx, %edi
    call    _gnat__io__put__2
    movl    %ebx, %edi
    call    _gnat__io__put__2
    popq    %rbx
LCFI1:
    ret

_case3_p__f is called once on the machine code against that case3_p.F is called
three times from case3_m.
Perhaps, case3_p.F is treated as Pure_Function.

Which of those is correct, the document or the behaviour of compiler?


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