[cfe-dev] static const function locals

Peter Cooper peter_cooper at apple.com
Mon Jun 18 10:59:30 PDT 2012


On Jun 18, 2012, at 10:55 AM, Eli Friedman wrote:

> On Mon, Jun 18, 2012 at 10:47 AM, Peter Cooper <peter_cooper at apple.com> wrote:
>> Hi all
>> 
>> I'm trying to write an optimization to create constant initializers for static const locals where they are structures, i.e., on this test
>> 
>> struct S {
>>        int i;
>>        S(int v) : i(v) { }
>> };
>> 
>> int foo(int i) {
>>        static const S arr[4] = {0,1,2,3};
>>        return arr[i].i;
>> }
>> 
>> i'm going to change the IR so that instead of a series of stores guarded by __cxa_guard functions, we just have
>> 
>> @_ZZ3fooiE3arr = constant global [4 x %struct.S] [%struct.S { i32 0}, %struct.S { i32 1}, %struct.S { i32 2}, %struct.S { i32 3}]
>> 
>> However, the global has been given a zero initializer which makes doing this change difficult without more analysis than I think is necessary.
>> 
>> So, finally, my question is, can we put an undef initializer on this variable instead of a zero initializer?  I don't know the C++ spec so i'm not sure if i'm missing something.
> 
> No; see [stmt.dcl]p4.
D'oh.  More involved analysis it is then.  Thanks Eli.

Pete
> 
> -Eli




More information about the cfe-dev mailing list