-
Notifications
You must be signed in to change notification settings - Fork 482
Open
Description
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;
}
It seems that all GEP-based accesses to the array have fldIdx = 0, which causes this problem.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels