gm2: Fix mc/mc.flex compilation on Solaris
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 |
success
|
Testing passed
|
Commit Message
The recent warning changes broke gm2 bootstrap on Solaris:
/vol/gcc/src/hg/master/local/gcc/m2/mc/mc.flex: In function 'handleFile':
/vol/gcc/src/hg/master/local/gcc/m2/mc/mc.flex:297:21: error: implicit declaration of function 'alloca' [-Wimplicit-function-declaration]
297 | char *s = (char *)alloca (strlen (filename) + 2 + 1);
| ^~~~~~
alloca needs <alloca.h> on Solaris, which isn't universally available.
Since mc.flex doesn't include any config header, I chose to switch to
__builtin_alloca instead.
/vol/gcc/src/hg/master/local/gcc/m2/mc/mc.flex:332:19: error: implicit declaration of function 'index' [-Wimplicit-function-declaration]
332 | char *p = index(sdate, '\n');
| ^~~~~
index is declared in <strings.h> on Solaris, again not a standard
header. I simply switched to using strchr to avoid that issue.
Bootstrapped without regressions on i386-pc-solaris2.11,
sparc-sun-solaris2.11, x86_64-pc-linux-gnu, and
x86_64-apple-darwin23.1.0.
Ok for trunk?
Rainer
Comments
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:
> The recent warning changes broke gm2 bootstrap on Solaris:
>
> /vol/gcc/src/hg/master/local/gcc/m2/mc/mc.flex: In function 'handleFile':
> /vol/gcc/src/hg/master/local/gcc/m2/mc/mc.flex:297:21: error: implicit declaration of function 'alloca' [-Wimplicit-function-declaration]
> 297 | char *s = (char *)alloca (strlen (filename) + 2 + 1);
> | ^~~~~~
>
> alloca needs <alloca.h> on Solaris, which isn't universally available.
> Since mc.flex doesn't include any config header, I chose to switch to
> __builtin_alloca instead.
>
> /vol/gcc/src/hg/master/local/gcc/m2/mc/mc.flex:332:19: error: implicit declaration of function 'index' [-Wimplicit-function-declaration]
> 332 | char *p = index(sdate, '\n');
> | ^~~~~
>
> index is declared in <strings.h> on Solaris, again not a standard
> header. I simply switched to using strchr to avoid that issue.
>
> Bootstrapped without regressions on i386-pc-solaris2.11,
> sparc-sun-solaris2.11, x86_64-pc-linux-gnu, and
> x86_64-apple-darwin23.1.0.
>
> Ok for trunk?
>
> Rainer
yes, lgtm, - thanks for fixing index as well,
regards,
Gaius
# HG changeset patch
# Parent 76246607bf26a4639355410e36af4cbf08c04f99
gm2: Fix mc/mc.flex compilation on Solaris
@@ -28,6 +28,10 @@ along with GNU Modula-2; see the file CO
#include <time.h>
#include <ctype.h>
+#ifdef __GNUC__
+#define alloca __builtin_alloca
+#endif
+
#if !defined(TRUE)
# define TRUE (1==1)
#endif
@@ -329,7 +333,7 @@ handleDate (void)
time_t clock = time ((long *)0);
char *sdate = ctime (&clock);
char *s = (char *)alloca (strlen (sdate)+2+1);
- char *p = index(sdate, '\n');
+ char *p = strchr(sdate, '\n');
if (p != NULL) {
*p = (char) 0;