| Issue |
181103
|
| Summary |
Miscompilation with LLVM Attributor
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
road2react
|
The following program is miscompiled using `clang -O3 -mllvm -attributor-enable=module`:
```c
#include <stdint.h>
#include <stdlib.h>
void ext(int64_t);
static int cond(int64_t** p) { return **p < 5; }
static void step(int64_t** p) { ext(**p); **p += 1; }
static void loop(int64_t** a, int64_t** b) {
while (cond(a)) step(b);
}
int main(void) {
int64_t* c = (int64_t*)malloc(8); *c = 0;
int64_t** e1 = (int64_t**)malloc(8); *e1 = c;
int64_t** e2 = (int64_t**)malloc(8); *e2 = c;
loop(e1, e2);
}
```
It is intended to print a counter from 0 to 5, but instead loops and prints 0 repeatedly.
Using `clang -O3` alone does not exhibit the issue.
I suspect this is because LLVM treats `e1` and `e2` as disjoint allocations, and applying this assumption transitively to the inner pointer `c`, while the inner allocation is shared between the double pointers.
System info:
```
# Arch linux
$ clang --version
clang version 21.1.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs