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

Re: [PATCH, libgfortran] PR 60324 Unbounded stack allocations in libgfortran


On 11/13/2014 02:32 AM, Janne Blomqvist wrote:

> in the spirit of PR 60324 and 61035, here's a patch that gets rid of
> the remaining potentially unbounded stack allocations in libgfortran.
> All uses of __builtin_alloca() and VLA's are replaced either straight
> with heap allocated memory, or with a fixed size stack buffer,
> potentially switching to heap storage for large sizes in places where
> performance might matter. In order to avoid reintroducing these kinds
> of issues, I also added -Werror=vla to AM_CFLAGS.
> 
> This might also help limited targets like nvptx that lack VLA's.
> 
> Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

I hit an error when building intrinsics/random.c:

  error: expression in static assertion is not constant

Joseph told me that static const variables cannot be used in constant
expressions in C, so I've replaced the _Static_assert with a regular
assert. Are you using g++ to build libgfortran?

I don't have a good baseline test this patch thoroughly, but at least I
can bootstrap gcc without it failing in libgfortran. Is this OK for
mainline and/or could someone see if it causes any regressions?

Thanks,
Cesar
2014-11-14  Cesar Philippidis  <cesar@codesourcery.com>

	libgfortran/
	* intrinsics/random.c (random_seed_i4): Replace _Static_assert
	with assert.


diff --git a/libgfortran/intrinsics/random.c b/libgfortran/intrinsics/random.c
index 5e91929..6b07a66d 100644
--- a/libgfortran/intrinsics/random.c
+++ b/libgfortran/intrinsics/random.c
@@ -25,6 +25,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
+#include <assert.h>
 #include <gthr.h>
 #include <string.h>
 
@@ -669,8 +670,8 @@ random_seed_i4 (GFC_INTEGER_4 *size, gfc_array_i4 *put, gfc_array_i4 *get)
 
 #define KISS_MAX_SIZE 12
   unsigned char seed[4 * KISS_MAX_SIZE];
-  _Static_assert (kiss_size <= KISS_MAX_SIZE,
-		  "kiss_size must <= KISS_MAX_SIZE");
+  assert (kiss_size <= KISS_MAX_SIZE
+	  && "kiss_size must <= KISS_MAX_SIZE");
 
   __gthread_mutex_lock (&random_lock);
 

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