autoconf-patches
[Top][All Lists]
Advanced

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

Re: Overflow protection in _AC_COMPUTE_INT_COMPILE


From: Kaveh R. Ghazi
Subject: Re: Overflow protection in _AC_COMPUTE_INT_COMPILE
Date: Thu, 16 Nov 2000 15:26:16 -0500 (EST)

 > From: Akim Demaille <address@hidden>
 > 
 > Hi Kaveh,
 > 
 > We have a problem in CVS Autoconf: it uses the negative size array
 > trick to compute some compiler known values such as sizeof.  AFAIK you
 > are using a similar technique in GCC.
 > 
 > The problem we face is that the bundled cc under HP rejects the
 > computations of the array size.  Presumably while
 > 
 >         int foo[sizeof(int)]
 > 
 > would work, this doesn't
 > 
 >         int foo[4 == sizeof(int)]
 > 
 > (well, at least we know that the full formula is always rejected even
 > if it resolves to a valid size).
 > 
 > IIRC you are using the switch trick.  Did you face the same problem?
 > Are your macros *always* using this trick, or only when cross-compiling?

Hi Akim,

I haven't seen any problems using the switch trick in gcc, and we
always use it regardless of whether we are cross compiling or not.

IIRC, the array test does this:

int foo[1 - 2 * (sizeof (foo) == 4)];

so the expr is either -1 or 1.

The switch trick doesn't use any subtraction or multiplication, it
simply does "case (sizeof(foo) >= sizeof(bar)):", (at least my version
does.)  So the HP compiler might accept it more easily.

Note there is one design consideration which may have given gcc a
break.  The switch test is setup so that compilation failures based on
losing C compilers come out as a false result on the feature test.
Also gcc does a 3-stage bootstrap, we override the macro setting in
stage2 and stage3 when we know we have gcc so the test eventually gets
the "right" answer regardless of what answer it got in stage1 with
possible buggy C compilers.  I don't know if this was a factor or not.

I suggest trying the switch method on the hp compiler which reported
the problem.  Make sure to setup autoconf so that compilation failures
indicate a false feature test result.

                --Kaveh

PS: please update the AC_C_LONG_DOUBLE to use some sort of compile
time test.  That's the test we overrode in gcc in the first place.  I
looked in aclang.m4 in CVS and it's still using a RUN test.  You can
copy what's in gcc/aclocal.m4 if you want.
--
Kaveh R. Ghazi                  Engagement Manager / Project Services
address@hidden          Qwest Internet Solutions



reply via email to

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