mirror of
https://github.com/Z3Prover/z3
synced 2026-11-09 19:50:59 +00:00
Fix segfault in mk_power_axiom caused by variable shadowing (#10594)
Asserting a fractional-exponent power expression (e.g. `(^ (fp.to_real
f) 0.5)`) segfaults under `sat.smt=true` / `sat.euf=true`.
**Root cause**
In `solver::mk_power_axiom` (`src/sat/smt/arith_axioms.cpp`), the axiom
for `x^(m/n)` with `n > 1` declares a local `expr_ref x(m)` that shadows
the function parameter `expr* x`. The shadowed variable defaults to a
null expression, so:
```cpp
if (denominator(r) > 1) {
expr_ref x_ge_0(a.mk_ge(x, a.mk_real(0)), m);
expr_ref x(m); // shadows parameter x, null-initialized
if (numerator(r) > 1)
x = a.mk_power(x, a.mk_real(numerator(r))); // uses the shadowed null x
expr_ref x_eq_pn(a.mk_eq(x, a.mk_power(p, a.mk_real(denominator(r)))), m); // null even when numerator(r) == 1
add_clause(~mk_literal(x_ge_0), mk_literal(x_eq_pn));
}
```
The resulting clause is built with a null expression, which crashes when
later dereferenced.
**Fix**
- Renamed the shadowing local to `xn` and initialized it from the
parameter `x`, so the axiom correctly references the base expression
(raised to `numerator(r)` when applicable).
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #10593
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
parent
64b1fba5f9
commit
c1c2f9498c
1 changed files with 3 additions and 3 deletions
|
|
@ -81,10 +81,10 @@ namespace arith {
|
|||
// r is m/n then x >= 0 => x^m = p^n
|
||||
if (denominator(r) > 1) {
|
||||
expr_ref x_ge_0(a.mk_ge(x, a.mk_real(0)), m);
|
||||
expr_ref x(m);
|
||||
expr_ref xn(x, m);
|
||||
if (numerator(r) > 1)
|
||||
x = a.mk_power(x, a.mk_real(numerator(r)));
|
||||
expr_ref x_eq_pn(a.mk_eq(x, a.mk_power(p, a.mk_real(denominator(r)))), m);
|
||||
xn = a.mk_power(x, a.mk_real(numerator(r)));
|
||||
expr_ref x_eq_pn(a.mk_eq(xn, a.mk_power(p, a.mk_real(denominator(r)))), m);
|
||||
add_clause(~mk_literal(x_ge_0), mk_literal(x_eq_pn));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue