[llvm-bugs] [Bug 29024] New: GNU statement expression in static initializer is miscompiled to all bytes zero

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 17 15:38:09 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=29024

            Bug ID: 29024
           Summary: GNU statement expression in static initializer is
                    miscompiled to all bytes zero
           Product: clang
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ju.orth at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Consider the following example:

------------
struct x {
    unsigned char i;
};

const struct x *f(void);
const struct x *f(void)
{
    static const struct x *x = __extension__ ({
        static const struct x z = { .i = 255 };
        &z;
    });
    return x;
}

const struct x *g(void);
const struct x *g(void)
{
    static const struct x z = { .i = 255 };
    static const struct x *x = &z;
    return x;
}
-----------

which miscompiles to

-----------
f:
    movl    $f.z, %eax
    retq
g:
    movl    $g.z, %eax
    retq
f.z:
    .zero    1
g.z:
    .byte    255
-----------

GCC rejects statement expressions in constant positions.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160817/3abac9ae/attachment.html>


More information about the llvm-bugs mailing list