Skip to content

Inconsistent field sensitivity for array accesses #1779

@Yanhaoxi

Description

@Yanhaoxi

When using a union to overlay a named struct of function pointers with an array of function pointers, values written via the struct fields are stored correctly, but accessing them through the array results in only one function pointer being loaded/used.

#include <stdio.h>

void func1() { printf("func1 called\n"); }
void func2() { printf("func2 called\n"); }

typedef struct {
    union {
        struct {
            void (*func1)();
            void (*func2)();
        } named;
        void (*array[2])();
    };
} FuncArray;

int main() {
    FuncArray fa;
    
    fa.named.func1 = func1;
    fa.named.func2 = func2;
    
    for (int i = 0; i < 2; i++) {
        fa.array[i]();
    }
    
    return 0;
}
Image

It seems that all GEP-based accesses to the array have fldIdx = 0, which causes this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions