Issue 242593
Summary [X86][LVI] Debug records can cause duplicate LFENCE insertion
Labels new issue
Assignees
Reporter yqtian-se
    With `-mlvi-hardening`, compiling this function with `-g` emits two
consecutive `lfence` instructions where `-g0` emits one.

```c
int *g(int);
int f(int **a, int **b, volatile int *n, int c) {
  int *p;
  do { p = *a; a++; } while (*n);
  int *q;
  if (c) { q = *b; } else { q = g(c); }
  return q[*p];
}
```

```sh
clang --target=x86_64-linux-gnu -O2 -mlvi-hardening -g  -S input.c -o with-g.s
clang --target=x86_64-linux-gnu -O2 -mlvi-hardening -g0 -S input.c -o without-g.s
grep -n lfence with-g.s without-g.s
```

The relevant difference is:

```diff
 	movq	(%rsi), %rax
+	lfence
 	lfence
```

The first difference appears in `x86-lvi-load`. `insertFences` checks the raw
previous machine instruction when deciding whether a fence is already present.
A `DBG_VALUE` between the existing `LFENCE` and the branch hides the fence, so
the pass inserts another one.

Debug records should not defeat the adjacent-fence check. This was reproduced
with clang `7517bcdb0b87`; the responsible code remains unchanged on LLVM main
`2451a1eadfa1`.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to