You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LLVM verify error: comparing a &str parameter to a string literal emits icmp between ptr and str #293
Comparing a value bound as &str against a string literal mis-codegens: LLVM rejects an icmp eq whose operands are ptr (the &str) and str (the literal value). with check passes; the failure is at codegen. Comparing an owned str works fine.
Environment
with v0.14.5, macOS arm64
Minimal repro
fn is_x(k: &str) -> bool:
k == "x"
fn main:
let r = is_x("x")
print(f"r={r}")
Observed
with run:
LLVM verify error
Both operands to ICmp instruction are not of the same type!
%9 = icmp eq ptr %4, %str %8
error: code generation failed
with check → ok.
Workaround
Compare an owned str instead of a &str: take the parameter by value (k: str), or compare a str field/local. str == "literal" codegens correctly.
Notes
The &str operand lowers to a bare ptr while the string literal lowers to the str aggregate value; equality should deref the &str (or otherwise compare consistently) before the icmp.
Fixed in 6bf8849. Sema now treats a &str as the str it points at for comparison (cmp_normalize_str_ref — only str refs; &i32 keeps pointer semantics), and codegen classifies a &str as a str and loads the str aggregate from the ref before compare_str_eq. &str == "lit", &str == &str, and &str != "lit" now compare by value. Regression test test/behavior/ref_str_compare.w; full build + fixpoint + test green. (Note: the symptom had evolved from the original LLVM verify error to a Sema rejection; both are fixed.)
Activity
ehartford commentedon May 31, 2026
Fixed in 6bf8849. Sema now treats a
&stras the str it points at for comparison (cmp_normalize_str_ref — only str refs;&i32keeps pointer semantics), and codegen classifies a&stras a str and loads the str aggregate from the ref before compare_str_eq.&str == "lit",&str == &str, and&str != "lit"now compare by value. Regression test test/behavior/ref_str_compare.w; full build + fixpoint + test green. (Note: the symptom had evolved from the original LLVM verify error to a Sema rejection; both are fixed.)Compare &str as the str it points at, not as a pointer (#293)
Compare &str as the str it points at, not as a pointer (#293)
WIP withlang-dev#747: codegen — a &str operand concatenates as its po…
codegen: sema-routed str ORDERING compares; regex literals pass &str …
emit-c: == / != and the orderings on &str views compare the text (#1560)
C backend and modeled-C fixes: map loops, generic structs, view compa…