bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gawk 3.1.6: alignment problem in rand.awk test case


From: duncan . moore
Subject: gawk 3.1.6: alignment problem in rand.awk test case
Date: Wed, 2 Jan 2008 07:01:18 -0800 (PST)
User-agent: G2/1.0

Hi All,

I've compiled gawk 3.1.6 on RISC OS with gcc 4.1.1, having previously
used gcc 3.4.6 successfully. I'm now getting a different sequence of
numbers from the rand.awk test case supplied with gawk. I've
identified
the problem as a cast from char* to unsigned int*, which shows up with
-
Wcast-align:

gcc -c -Wall -Wcast-align -std=gnu99 -O2 -DHAVE_CONFIG_H -I. -MMD -MP
    -o random.o random.c
random.c: In function 'gawk_initstate':
random.c:401: warning: cast increases required alignment of target
type
random.c: In function 'gawk_setstate':
random.c:466: warning: cast increases required alignment of target
type

(I'm unable to run the configure scripts on RISC OS, but I don't think
I've missed any essential options in the compilation line above.)

Just to show that this is the problem, I made the following changes
(not a long term solution of course) and get the correct output from
rand.awk:

--- gawk-3.1.6.builtin.c        2007-09-30 19:57:05 +0000
+++ gawk-3.1.6.ro2/builtin.c    2008-01-02 13:00:53 +0000
@@ -2027,7 +2027,7 @@ do_cos(NODE *tree)
 /* do_rand --- do the rand function */

 static int firstrand = TRUE;
-static char state[256];
+static char state[256+16];

 /* ARGSUSED */
 NODE *

--- gawk-3.1.6/random.c         2006-09-15 12:15:45 +0000
+++ gawk-3.1.6.ro2/random.c     2008-01-02 13:01:16 +0000
@@ -397,6 +397,7 @@ initstate(seed, arg_state, n)
        char *arg_state;                /* pointer to state array */
        long n;                         /* # bytes of state info */
 {
+if ((int)arg_state%4) arg_state=(char*) (((int)arg_state/4)*4+4);
        char *ostate = (char *)(&state[-1]);
        uint32_t *int_arg_state = (uint32_t *)arg_state;

@@ -463,6 +464,7 @@ char *
 setstate(arg_state)
        char *arg_state;                /* pointer to state array */
 {
+if ((int)arg_state%4) arg_state=(char*) (((int)arg_state/4)*4+4);
        uint32_t *new_state = (uint32_t *)arg_state;
        uint32_t type = new_state[0] % MAX_TYPES;
        uint32_t rear = new_state[0] / MAX_TYPES;

It's a bit surprising that no one has raised this problem before, but
it could be due to the fact that the test case produces random
numbers,
so people tend to ignore the difference.


On a separate issue, -Wextra gives this warning (amongst others):

dfa.c: At top level:
dfa.c:762: warning: missing initializer
dfa.c:762: warning: (near initialization for 'prednames[12].pred')

I think the following change better reflects what the compiler
actually
produces, and what the programmer intended:

--- gawk-3.1.6/dfa.c            2007-09-03 03:30:12 +0000
+++ gawk-3.1.6.ro2/dfa.c        2008-01-02 14:22:54 +0000
@@ -759,7 +759,6 @@ static struct {
   { ":graph:]", is_graph },
   { ":cntrl:]", is_cntrl },
   { ":blank:]", is_blank },
-  { 0 }
 };

Regards

Duncan Moore


reply via email to

[Prev in Thread] Current Thread [Next in Thread]