[Fortran] Fix broken use of alloca in C interoperability testcase

Message ID 242ab49c-5047-c7fe-ee06-23210f3bbe18@codesourcery.com
State New
Headers
Series [Fortran] Fix broken use of alloca in C interoperability testcase |

Commit Message

Sandra Loosemore Oct. 25, 2021, 6:27 p.m. UTC
  This patch is for PR102910.  There's no reason why the testcase in 
question needs to use alloca, but I wasn't aware there were portability 
issues with it until I saw this issue.

I think this fix is probably obvious and will commit it tomorrow unless 
I get some feedback on it meanwhile.

-Sandra
  

Patch

commit 75b603334401d079391ca950dd2e22663cdb3080
Author: Sandra Loosemore <sandra@codesourcery.com>
Date:   Mon Oct 25 11:08:28 2021 -0700

    [Fortran] Fix broken use of alloca in C interoperability testcase
    
    2021-10-25  Sandra Loosemore  <sandra@codesourcery.com>
    
    	gcc/testsuite/
    
    	PR testsuite/102910
    	* gfortran.dg/c-interop/cf-descriptor-5-c.c: Use a static buffer
    	instead of alloca.

diff --git a/gcc/testsuite/gfortran.dg/c-interop/cf-descriptor-5-c.c b/gcc/testsuite/gfortran.dg/c-interop/cf-descriptor-5-c.c
index 12464b5..320a354 100644
--- a/gcc/testsuite/gfortran.dg/c-interop/cf-descriptor-5-c.c
+++ b/gcc/testsuite/gfortran.dg/c-interop/cf-descriptor-5-c.c
@@ -1,6 +1,5 @@ 
 #include <stdlib.h>
 #include <stdio.h>
-#include <alloca.h>
 
 #include <ISO_Fortran_binding.h>
 #include "dump-descriptors.h"
@@ -8,12 +7,18 @@ 
 extern void ctest (int n);
 extern void ftest (CFI_cdesc_t *a, int n);
 
+#define BUFSIZE 512
+static char adata[BUFSIZE];
+
 void
 ctest (int n)
 {
   CFI_CDESC_T(0) adesc;
   CFI_cdesc_t *a = (CFI_cdesc_t *) &adesc;
-  char *adata = (char *) alloca (n);
+
+  /* Use a fixed-size static buffer instead of allocating one dynamically.  */
+  if (n > BUFSIZE)
+    abort ();
 
   /* Fill in adesc.  */
   check_CFI_status ("CFI_establish",