Skip to content

[LoopInterchange] Interchange breaks program correctness #46867

Closed
@cmd120

Description

@cmd120
Bugzilla Link 47523
Version trunk
OS Linux
Attachments reproducer, reproducer.ll
CC @fhahn

Extended Description

$ clang -mllvm -enable-loopinterchange -O2 reproducer.c -w && ./a.out
11
$ clang -O0 reproducer.c -w && ./a.out
9

LoopInterchange wrongly interchanges loops in the following function "h()", in which the order of *s=3 matters:

struct a {
unsigned char b
} c[];
d, e, g;
f[4][9] = {5, 3};
h() {
for (; d <= 2; d++) {
for (e = 0; e <= 2; e++) {
short *s = &g;
if ((long)(f[e][d] && (*s = 3), c) % 4073709551606)
++*s;
}
}
}
main() {
h();
printf("%d\n", g);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions