From 087eeaf33c7cd335449017ab06a7ad3f02080639 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Jul 2026 20:32:02 -0700 Subject: [PATCH] Fix api_datalog test: reuse of Z3_context across set-logic calls (#10101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `api_datalog` unit test was failing in CI with `"the logic has already been set"`. Two consecutive regression tests shared a single `Z3_context`, but both called `Z3_eval_smtlib2_string` with `(set-logic HORN)` — the second call always fails because context logic state is permanent. ## Changes - **`src/test/api_datalog.cpp`**: Give each `Z3_eval_smtlib2_string`-based regression test its own `Z3_config`/`Z3_context`, destroyed immediately after the test block. The outer context is retained only for the two tests that don't invoke the SMT-LIB evaluator. ```cpp // Before: both blocks shared `ctx`, second (set-logic HORN) always errored Z3_string response = Z3_eval_smtlib2_string(ctx, chc1); // sets HORN logic Z3_string response = Z3_eval_smtlib2_string(ctx, chc2); // ERROR: logic already set // After: each block owns its context Z3_config cfg2 = Z3_mk_config(); Z3_context ctx2 = Z3_mk_context(cfg2); Z3_del_config(cfg2); Z3_string response = Z3_eval_smtlib2_string(ctx2, chc2); Z3_del_context(ctx2); ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- src/test/api_datalog.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/test/api_datalog.cpp b/src/test/api_datalog.cpp index 3b0011a4b3..f57e0c0419 100644 --- a/src/test/api_datalog.cpp +++ b/src/test/api_datalog.cpp @@ -66,6 +66,10 @@ void tst_api_datalog() { // Regression test for Spacer model construction on ADT CHCs { + Z3_config cfg2 = Z3_mk_config(); + Z3_context ctx2 = Z3_mk_context(cfg2); + Z3_del_config(cfg2); + char const* chc = "(set-logic HORN)\n" "(set-option :fp.engine spacer)\n" @@ -85,13 +89,18 @@ void tst_api_datalog() { " false)))\n" "(check-sat)\n"; - Z3_string response = Z3_eval_smtlib2_string(ctx, chc); + Z3_string response = Z3_eval_smtlib2_string(ctx2, chc); ENSURE(response != nullptr); - ENSURE(Z3_get_error_code(ctx) == Z3_OK); + ENSURE(Z3_get_error_code(ctx2) == Z3_OK); + Z3_del_context(ctx2); } // Regression test for assertion violation in Spacer QE projection (#3845) { + Z3_config cfg3 = Z3_mk_config(); + Z3_context ctx3 = Z3_mk_context(cfg3); + Z3_del_config(cfg3); + char const* chc = R"( (set-logic HORN) (set-option :fp.xform.inline_eager false) @@ -224,9 +233,10 @@ void tst_api_datalog() { (check-sat) )"; - Z3_string response = Z3_eval_smtlib2_string(ctx, chc); + Z3_string response = Z3_eval_smtlib2_string(ctx3, chc); ENSURE(response != nullptr); - ENSURE(Z3_get_error_code(ctx) == Z3_OK); + ENSURE(Z3_get_error_code(ctx3) == Z3_OK); + Z3_del_context(ctx3); } Z3_del_context(ctx);