From 464ba22f1e38d25402e5ec79a9b8d34a32df5a3f Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Wed, 18 Aug 2021 12:51:30 +1000 Subject: [PATCH] Check compiler for c99 declarations after code. The sntrup761 reference code contains c99-style declarations after code so don't try to build that if the compiler doesn't support it. --- configure.ac | 10 ++++++++++ defines.h | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index e728e3236..01e7d2a4f 100644 --- a/configure.ac +++ b/configure.ac @@ -307,6 +307,16 @@ AC_COMPILE_IFELSE( [ AC_MSG_RESULT([no]) ] ) +AC_MSG_CHECKING([if compiler accepts variable declarations after code]) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include ]], + [[ int a; a = 1; int b = 1; exit(a-b); ]])], + [ AC_MSG_RESULT([yes]) + AC_DEFINE(VARIABLE_DECLARATION_AFTER_CODE, [1], + [compiler variable declarations after code]) ], + [ AC_MSG_RESULT([no]) ] +) + if test "x$no_attrib_nonnull" != "x1" ; then AC_DEFINE([HAVE_ATTRIBUTE__NONNULL__], [1], [Have attribute nonnull]) fi diff --git a/defines.h b/defines.h index 7fff562c0..857abb8b1 100644 --- a/defines.h +++ b/defines.h @@ -901,10 +901,10 @@ struct winsize { #endif /* - * sntrup761 uses variable length arrays, only enable if the compiler - * supports them. + * sntrup761 uses variable length arrays and c99-style declarations after code, + * so only enable if the compiler supports them. */ -#ifdef VARIABLE_LENGTH_ARRAYS +#if defined(VARIABLE_LENGTH_ARRAYS) && defined(VARIABLE_DECLARATION_AFTER_CODE) # define USE_SNTRUP761X25519 1 #endif #endif /* _DEFINES_H */ -- 2.47.3