3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-08-02 12:13:25 +00:00

Fix reversed precondition assertion in grobner::pop_scope (#10318)

### What it does

Fixes an inverted precondition assertion in `grobner::pop_scope`
(`src/math/grobner/grobner.cpp`).

```cpp
void grobner::pop_scope(unsigned num_scopes) {
    SASSERT(num_scopes >= get_scope_level());          // was reversed
    unsigned new_lvl = get_scope_level() - num_scopes; // requires num_scopes <= level
    ...
    m_scopes.shrink(new_lvl);
}
```

`get_scope_level()` returns `m_scopes.size()` (grobner.h). The body
computes
`new_lvl = get_scope_level() - num_scopes` and calls
`m_scopes.shrink(new_lvl)`,
which is only well-defined when `num_scopes <= get_scope_level()`. The
assertion
stated the opposite (`>=`), so in debug builds it would fire on any
valid partial
pop (e.g. popping one of several scopes) while failing to catch the
unsigned
underflow it was meant to guard against. Changed to `<=`.

### Evidence

- `get_scope_level() const { return m_scopes.size(); }`
(`src/math/grobner/grobner.h`).
- Compiled the translation unit with MSVC and `Z3DEBUG` defined (so the
`SASSERT`
  is active): builds cleanly.

### What we did not verify

This is a debug-only (`SASSERT`) correctness fix and has no effect on
release
builds. No behavioral test was added.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ad2c295d-7523-48cf-b786-b435b833e3af
This commit is contained in:
Nikolaj Bjorner 2026-07-30 20:04:53 -07:00 committed by GitHub
parent 3c3fdb81b1
commit bffbe2475f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -98,7 +98,7 @@ void grobner::push_scope() {
}
void grobner::pop_scope(unsigned num_scopes) {
SASSERT(num_scopes >= get_scope_level());
SASSERT(num_scopes <= get_scope_level());
unsigned new_lvl = get_scope_level() - num_scopes;
scope & s = m_scopes[new_lvl];
unfreeze_equations(s.m_equations_to_unfreeze_lim);