Issue 242596
Summary [X86] Debug CFI prevents merging stack-pointer adjustments
Labels new issue
Assignees
Reporter yqtian-se
    With `-m32 -Os`, compiling this function with `-g` emits two stack-pointer
adjustments where `-g0` emits one.

```c
typedef struct {
  void *stack;
  unsigned size;
  unsigned avail;
} compile_stack_type;

void foo(void *);
void bar(compile_stack_type, unsigned);

void test(void) {
  compile_stack_type stack;
  foo(&stack);
  bar(stack, 12);
}
```

```sh
clang --target=x86_64-linux-gnu -m32 -Os -fno-pic -ffreestanding \
  -fno-addrsig -g -S input.c -o with-g.s
clang --target=x86_64-linux-gnu -m32 -Os -fno-pic -ffreestanding \
  -fno-addrsig -g0 -S input.c -o without-g.s
diff -u without-g.s with-g.s
```

The relevant difference is:

```diff
-	subl $36, %esp
+	subl $24, %esp
+	subl $12, %esp
```

The first difference appears in `prolog-epilog`. With `-g`, two CFI
instructions follow the first stack adjustment. `mergeSPUpdates` steps back
over only one CFI instruction, so it does not find and merge the earlier
adjustment.

Consecutive CFI and debug instructions should not hide the earlier stack
adjustment. 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