tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Fwd: Segfault compiling bash?


From: Dave Dodge
Subject: Re: [Tinycc-devel] Fwd: Segfault compiling bash?
Date: Thu, 21 Jul 2005 01:36:16 -0400
User-agent: Mutt/1.4.2i

On Sat, Jul 16, 2005 at 07:14:43AM -0700, address@hidden wrote:
> Still see this with the latest release. Anyone else
> have the same problem?

I can at least explain the "constant expression expected" bug: tcc
does not properly compile code when a long long value is used to
specify an array size.

This partly comes from the fact that the expr_const() function in tcc,
which is used to obtain the array size, assumes constant values have
type int.  Demonstration code:

  void foo(void){
    /* this works, but only by accident */
    char a1[1LL];

    /*
     * "invalid array size".  It pulls the value out of the CType int
     * field, which produces a bit pattern that looks like -1.
     */
    char a2[0x80000000LL];

    /*
     * "constant expression expected".  When an operator is put into
     * the long long expression, I think it ends up trying to actually
     * generate code to evaluate the expression at runtime, rather than
     * realizing that it's a constant.
     */
    char a3[1LL + 1LL];
  }


The code in bash is doing this:

  char ibuf[INT_STRLEN_BOUND (intmax_t) + 1], *p;

which expands to an expression with some intmax_t casts in it.  On
i386 intmax_t is long long.

Sorry, I don't have a patch to fix it.  At the very least someone should
probably fix expr_const() and everything that calls it.  But that probably
still won't fix the a3 case.

As far as the segfault, I don't know.  It might be related to the constant
handling as well.

                                                  -Dave Dodge




reply via email to

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