/* File-scope initializers for a pointer from a cast-wrapped compound
 * literal, as generated by macro libraries like Cello's CelloObject():
 *
 *   (var)((char*)((var[]){ NULL, (var)sizeof(struct T), ... }) + sizeof(struct Header))
 *
 * Three rcc bugs were found here:
 *  1. "(T)((T2){...})" — a cast wrapping a compound literal — was not
 *     recognised as a compound literal at all ("unsupported global
 *     initializer"); the anonymous object also got the cast target type
 *     instead of the literal's type.
 *  2. A trailing constant addend ("+ sizeof(...)") after the literal was
 *     not folded into the relocation.
 *  3. `sizeof` inside such an initializer was treated as a label name
 *     ("reloc to symbol 'sizeof'"), and the two anonymous objects emitted
 *     for the outer array and a nested "&(compound literal)" collided
 *     under one ".Lanon.0" name, coalescing into one corrupt object.
 */
#include <stdio.h>

typedef void *var;

struct Header { int h; };          /* sizeof == 4 */
struct Doc   { var a; var b; };    /* sizeof == 16 */

/* g points 4 bytes past the anonymous array; the array's elements are
 * [0]=NULL, [1]=sizeof(struct Doc)=16, [2]=&(struct Doc){11,22}. */
static var g = (var)((char*)((var[]){
    NULL,
    (var)sizeof(struct Doc),
    &((struct Doc){ (var)11, (var)22 }),
    NULL
}) + sizeof(struct Header));

int main(void)
{
    var *v = (var *)((char *)g - sizeof(struct Header));
    if (v[0] != NULL) return 1;
    if (v[1] != (var)16) return 2;                    /* sizeof folded */
    struct Doc *d = (struct Doc *)v[2];
    if (d->a != (var)11 || d->b != (var)22) return 3; /* &(literal) reloc */
    if (v[3] != NULL) return 4;
    printf("OK\n");
    return 0;
}
