Issue 235299
Summary [lli] Interpreter asserts (APInt.h:127 isUIntN) when main returns a negative constant; JIT returns the wrapped value correctly
Labels new issue
Assignees
Reporter leidian977
    ## Summary

`lli --force-interpreter` aborts with an assertion failure in
`llvm::APInt::APInt` (`APInt.h:127`, `isUIntN`) when the module's `main`
returns a negative `i32` constant. The JIT path handles the same module
correctly (exit code 249 for `ret i32 -7`), so the interpreter and the
JIT disagree on semantics.

## Reduced test case (3 lines)

    define i32 @main() {
      ret i32 -7
    }

## Reproduction

    $ lli --force-interpreter f2.ll
    lli: .../llvm/include/llvm/ADT/APInt.h:127: llvm::APInt::APInt(unsigned int, uint64_t, bool, bool): Assertion `llvm::isUIntN(BitWidth, val) && "Value is not an N-bit unsigned value"' failed.
    PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ ...
    Aborted (core dumped)
 [exit code 134 / SIGABRT]

    $ lli f2.ll; echo $?
    249        ; JIT: correct (-7 mod 256)

## Root cause

Assertion site: `llvm/include/llvm/ADT/APInt.h:127` (the constructor
assert that the value fits in N bits unsigned). The Interpreter's RET
handling builds the exit value via `APInt(BitWidth, uint64_t)` without
sign-extending / modulo-reducing a negative int, so `-7` is fed as an
out-of-range unsigned literal. The JIT path converges correctly; the
two execution paths diverge. (Exact interpreter line left to upstream;
this report pins the behavioral divergence.)

## Impact

Any `main` returning a negative constant of width i1..i64 crashes under
`--force-interpreter`; lit tests that run `lli --force-interpreter` and
expect a negative exit code will abort. The bug is in the execution
substrate, not the transform layer.

## Suggested fix

Route the Interpreter RET/store exit-value construction through
`APInt(BitWidth, val, /*isSigned=*/true)` (or truncate first) so it
shares one converging function with the JIT path.

## Note on component status

Upstream is de-emphasizing the lli interpreter (#220130 / #220083 remove
interpreter RUN lines). If the component is retired, this path
disappears with it and poses no regression risk. Regardless, an assert
abort is not a silent miscompile and is reportable per LLVM issue
policy.

## Environment

- LLVM `24.0.0git`, built from git HEAD `cc2acc33a5b`
- Reproduced with `lli --force-interpreter` vs `lli` (JIT)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to