llvm / llvm/llvm-project

[BUG] ICE in llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&)

Open
#204,773 1 comment 0 reactions 0 assignees View on GitHub
backend:X86 confirmed crash-on-invalid crash-on-valid generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Bug Report: ICE in llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&)

Clang crashes when compiling the following C code.

**Compiler**: clang-22 (LLVM 22.1.5, commit 5ea218a153f4d2f815b8244eab3e4b4ba5e00e6c)
**Compilation flags**: -O0
**Platform**: x86_64-linux-gnu
**Component**: backend

This is a **backend** crash (does not reproduce with `-emit-llvm`).

## Reduced Test Case

> Minimized from the original fuzzer-generated input using `creduce`.

```sh
clang -O0 test.c -o /dev/null
```

```c
short *f(short *a, int b, int *d) __attribute__((noinline,noclone));
short *f(short *a, int b, int *d)
{
short c = *a;
if (b!= 1)
__builtin_abort ();
__asm__ ("{cmpl{l}\t$d,%c1;je\t1f;addw{l}\t$d,%c2;jmp\t2f;1:decl\t%c2;2:}" : "=r&"(c) : "g"(c), "g"(b), "0"(c) : "cc");
*d = c;
return a;
}
int main(void)
{
int d;
short a[2];
a[0] = 0;
if (f(a, 1, &d) != &a[1])
__builtin_abort ();
if (d != 1)
__builtin_abort ();
return 0;
}
```

## Crash Output

```
/root/outputs/experiments-on-metamut/surfuzz,gcc,1/bhnMHGEFPWQx_surfuzz_28.c:1:59: warning: unknown attribute 'noclone' ignored; did you mean 'noinline'? [-Wunknown-attributes]
1 | short *f(short *a, int b, int *d) __attribute__((noinline,noclone));
| ^\~\~\~\~\~\~
| noinline
fatal error: error in backend: Nested variants found in inline asm string: '$(cmpl$(l$) $$d,${1:c};je 1f;addw$(l$) $$d,${2:c};jmp 2f;1:decl ${2:c};2:$)'
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 22.1.5 (https://github.com/llvm/llvm-project.git 5ea218a153f4d2f815b8244eab3e4b4ba5e00e6c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /root/objects/llvm-project-release.obj/bin
Build config: \+assertions
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/bhnMHGEFPWQx_surfuzz_28-d5a56d.c
clang: note: diagnostic msg: /tmp/bhnMHGEFPWQx_surfuzz_28-d5a56d.sh
clang: note: diagnostic msg:
********************
EXIT_CODE: 1
```

## Preprocessed Source & Run Script

**Preprocessed source** (`/tmp/bhnMHGEFPWQx_surfuzz_28-d5a56d.c`):

```c
# 1 ""
# 1 "/root/outputs/experiments-on-metamut/surfuzz,gcc,1/bhnMHGEFPWQx_surfuzz_28.c"
short *f(short *a, int b, int *d) __attribute__((noinline,noclone));
short *f(short *a, int b, int *d)
{
short c = *a;
if (b!= 1)
__builtin_abort ();
__asm__ ("{cmpl{l}\t$d,%c1;je\t1f;addw{l}\t$d,%c2;jmp\t2f;1:decl\t%c2;2:}" : "=r&"(c) : "g"(c), "g"(b), "0"(c) : "cc");
*d = c;
return a;
}
int main(void)
{
int d;
short a[2];
a[0] = 0;
if (f(a, 1, &d) != &a[1])
__builtin_abort ();
if (d != 1)
__builtin_abort ();
return 0;
}

```

**Run script** (`/tmp/bhnMHGEFPWQx_surfuzz_28-d5a56d.sh`):

```sh
# Crash reproducer for clang version 22.1.5 (https://github.com/llvm/llvm-project.git 5ea218a153f4d2f815b8244eab3e4b4ba5e00e6c)
# Driver args: "-O0" "/root/outputs/experiments-on-metamut/surfuzz,gcc,1/bhnMHGEFPWQx_surfuzz_28.c" "-o" "/dev/null"
# Original command: "/root/objects/llvm-project-release.obj/bin/clang-22" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-O0" "-emit-obj" "-dumpdir" "/dev/null-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "bhnMHGEFPWQx_surfuzz_28.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/root/data" "-fcoverage-compilation-dir=/root/data" "-resource-dir" "/root/objects/llvm-project-release.obj/lib/clang/22" "-internal-isystem" "/root/objects/llvm-project-release.obj/lib/clang/22/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-faddrsig" "-fdwarf2-cfi-asm" "-o" "/tmp/bhnMHGEFPWQx_surfuzz_28-5dd735.o" "-x" "c" "/root/outputs/experiments-on-metamut/surfuzz,gcc,1/bhnMHGEFPWQx_surfuzz_28.c"
"/root/objects/llvm-project-release.obj/bin/clang-22" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-O0" "-emit-obj" "-dumpdir" "/dev/null-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "bhnMHGEFPWQx_surfuzz_28.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/root/data" "-fcoverage-compilation-dir=/root/data" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-faddrsig" "-fdwarf2-cfi-asm" "-x" "c" "bhnMHGEFPWQx_surfuzz_28-d5a56d.c"

```

* found via a fuzzer

[bhnMHGEFPWQx_surfuzz_28-d5a56d.c](https://github.com/user-attachments/files/29128497/bhnMHGEFPWQx_surfuzz_28-d5a56d.c)
[bhnMHGEFPWQx_surfuzz_28-d5a56d.sh](https://github.com/user-attachments/files/29128498/bhnMHGEFPWQx_surfuzz_28-d5a56d.sh)

Contributor guide

Open the contributing guide

Research direction

Start with the attached preprocessed C source and run script, reproducing the crash with clang -O0 on x86_64. Trace the backend handling of the inline assembly string in the reported X86AsmPrinter path; done means the reduced test no longer produces the Nested variants backend fatal error.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.