This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Using `const int' values to size stack arrays


Nathan Sidwell wrote:

sorry, I missed this point of your email.  I don't think we can arbitrarily
remove the dynamic allocation of a VLA, because I think the following
is required to work

static const int SIZE = SOME_HUGE_VALUE_THAT_CAUSES_STACK_OVERFLOW;

void Foo ()
{
  if (SOME_EXPR_THAT_IS_FALSE_AT_RUNTIME)
    {
    char ary[SIZE];
    }
}

If ary was promoted to a regular array, and therefore stack-frame
allocated at compile time, this function would fail when called, rather
than fail when the if block is entered.  (A pathelogical example)

OK, so if this pathology is worrying you, limit the optimization to cases where the array is "small" (after all these are cases where the compiler does in fact know the size :-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]