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

            Bug ID: 118831
           Summary: C function with variables arguments called from
                    fortran on ARM architecture
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jcldc13 at gmail dot com
  Target Milestone: ---

On ARM architecture (in my case mac mini M4), When a fortran program call a
language C function with variables arguments, variables arguments are not
decoded correctly. I have encountered this issue on gcc-14 (ARM), but some
colleague have same pb since gcc-10 (ARM).

Here is a sample of code, fortran an C, to reproduce the bug

Fortran77 style code  (main_va_arg.F) :
=======================================

       program test_va_arg_fortran_2_c
       implicit none
       character  sp*80
       integer test_va_arg_f3, val_i,i

       sp="hello world"//char(0)
       val_i = 666
       i=test_va_arg_f3(val_i,sp)
       end


C code (func_va_arg.c) :
========================

#include <stdio.h>
#include <stdarg.h>
int test_va_arg_f3_(int * s1, ...)
{
   va_list pa;
   char * myval;
   fprintf(stderr,"s1 [%d]\n",*s1);
   va_start(pa, s1);
   myval = (char *)  va_arg(pa, char *);
   fprintf(stderr,"myval [%s]\n",myval);
   return 1;
}


Compilation on mac mini M4 (gcc-14) :
======================================
gcc-14 -c func_va_arg.c
gfortran-14 -o test_va_arg main_va_arg.F func_va_arg.o


Execution :
./test_va_arg  
s1 [666]
myval [`k]

As we can see, myval variable does not get the right value, it should be "hello
world",

The same code executed on X86-64 architecture (Linux and mac) works perfectly.


Here is the complete description of the compilers:

gcc-14 :
========
 gcc-14 -v    
Using built-in specs.
COLLECT_GCC=gcc-14
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/14.2.0_1/bin/../libexec/gcc/aarch64-apple-darwin24/14/lto-wrapper
Target: aarch64-apple-darwin24
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc
--libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls
--enable-checking=release --with-gcc-major-version-only
--enable-languages=c,c++,objc,obj-c++,fortran,m2 --program-suffix=-14
--with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr
--with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl
--with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 14.2.0_1'
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--with-system-zlib --build=aarch64-apple-darwin24
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Homebrew GCC 14.2.0_1) 


gfortran-14 :
=============
gfortran-14 -v
Using built-in specs.
COLLECT_GCC=gfortran-14
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/14.2.0_1/bin/../libexec/gcc/aarch64-apple-darwin24/14/lto-wrapper
Target: aarch64-apple-darwin24
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc
--libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls
--enable-checking=release --with-gcc-major-version-only
--enable-languages=c,c++,objc,obj-c++,fortran,m2 --program-suffix=-14
--with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr
--with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl
--with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 14.2.0_1'
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--with-system-zlib --build=aarch64-apple-darwin24
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Homebrew GCC 14.2.0_1)

Reply via email to