Skip to content

[NFC][analyzer] Remove Z3-as-constraint-manager hacks from lit test code #145731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions clang/docs/analyzer/developer-docs/DebugChecks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,10 @@ ExprInspection checks
The value can be represented either as a range set or as a concrete integer.
For the rest of the types function prints ``n/a`` (aka not available).

**Note:** This function will print nothing for clang built with Z3 constraint manager.
This may cause crashes of your tests. To manage this use one of the test constraining
techniques:

* llvm-lit commands ``REQUIRES no-z3`` or ``UNSUPPORTED z3`` `See for details. <https://llvm.org/docs/TestingGuide.html#constraining-test-execution>`_

* a preprocessor directive ``#ifndef ANALYZER_CM_Z3``

* a clang command argument ``-analyzer-constraints=range``
**Note:** This function will print nothing when clang uses Z3 as the
constraint manager (which is an unsupported and badly broken analysis mode
that's distinct from the supported and stable "Z3 refutation" aka "Z3
crosscheck" mode).

Example usage::

Expand Down
2 changes: 2 additions & 0 deletions clang/test/Analysis/PR37855.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// RUN: %clang_cc1 -analyze -analyzer-checker=core -w -analyzer-config crosscheck-with-z3=true -verify %s
// REQUIRES: z3

// XFAIL: *

typedef struct o p;
struct o {
struct {
Expand Down
53 changes: 0 additions & 53 deletions clang/test/Analysis/analyzer_test.py

This file was deleted.

4 changes: 0 additions & 4 deletions clang/test/Analysis/bool-assignment.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ void test_BOOL_initialization(int y) {
return;
}
if (y > 200 && y < 250) {
#ifdef ANALYZER_CM_Z3
BOOL x = y; // expected-warning {{Assignment of a non-Boolean value}}
#else
BOOL x = y; // no-warning
#endif
return;
}
if (y >= 127 && y < 150) {
Expand Down
3 changes: 1 addition & 2 deletions clang/test/Analysis/cstring-addrspace.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \
// RUN: -analyze -analyzer-checker=core,alpha.unix.cstring \
// RUN: -analyze -analyzer-checker=debug.ExprInspection \
// RUN: -analyzer-checker=core,alpha.unix.cstring,debug.ExprInspection \
// RUN: -analyzer-config crosscheck-with-z3=true -verify %s \
// RUN: -Wno-incompatible-library-redeclaration
// REQUIRES: z3
Expand Down
12 changes: 2 additions & 10 deletions clang/test/Analysis/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
from lit.llvm.subst import ToolSubst
import site
import lit.formats

# Load the custom analyzer test format, which runs the test again with Z3 if it
# is available.
site.addsitedir(os.path.dirname(__file__))
import analyzer_test

config.test_format = analyzer_test.AnalyzerTest(
config.test_format.execute_external, config.use_z3_solver
)
config.test_format = lit.formats.ShTest(config.test_format.execute_external)

# Filtering command used by Clang Analyzer tests (when comparing .plist files
# with reference output)
Expand Down
17 changes: 0 additions & 17 deletions clang/test/Analysis/ptr-arith.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,7 @@ void comparisons_imply_size(int *lhs, int *rhs) {
}

clang_analyzer_eval(lhs <= rhs); // expected-warning{{TRUE}}
// FIXME: In Z3ConstraintManager, ptrdiff_t is mapped to signed bitvector. However, this does not directly imply the unsigned comparison.
#ifdef ANALYZER_CM_Z3
clang_analyzer_eval((rhs - lhs) >= 0); // expected-warning{{UNKNOWN}}
#else
clang_analyzer_eval((rhs - lhs) >= 0); // expected-warning{{TRUE}}
#endif
clang_analyzer_eval((rhs - lhs) > 0); // expected-warning{{UNKNOWN}}

if (lhs >= rhs) {
Expand All @@ -236,11 +231,7 @@ void comparisons_imply_size(int *lhs, int *rhs) {

clang_analyzer_eval(lhs == rhs); // expected-warning{{FALSE}}
clang_analyzer_eval(lhs < rhs); // expected-warning{{TRUE}}
#ifdef ANALYZER_CM_Z3
clang_analyzer_eval((rhs - lhs) > 0); // expected-warning{{UNKNOWN}}
#else
clang_analyzer_eval((rhs - lhs) > 0); // expected-warning{{TRUE}}
#endif
}

void size_implies_comparison(int *lhs, int *rhs) {
Expand All @@ -251,11 +242,7 @@ void size_implies_comparison(int *lhs, int *rhs) {
return;
}

#ifdef ANALYZER_CM_Z3
clang_analyzer_eval(lhs <= rhs); // expected-warning{{UNKNOWN}}
#else
clang_analyzer_eval(lhs <= rhs); // expected-warning{{TRUE}}
#endif
clang_analyzer_eval((rhs - lhs) >= 0); // expected-warning{{TRUE}}
clang_analyzer_eval((rhs - lhs) > 0); // expected-warning{{UNKNOWN}}

Expand All @@ -265,11 +252,7 @@ void size_implies_comparison(int *lhs, int *rhs) {
}

clang_analyzer_eval(lhs == rhs); // expected-warning{{FALSE}}
#ifdef ANALYZER_CM_Z3
clang_analyzer_eval(lhs < rhs); // expected-warning{{UNKNOWN}}
#else
clang_analyzer_eval(lhs < rhs); // expected-warning{{TRUE}}
#endif
clang_analyzer_eval((rhs - lhs) > 0); // expected-warning{{TRUE}}
}

Expand Down
16 changes: 0 additions & 16 deletions clang/test/Analysis/reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,10 @@ S getS();
S *getSP();

void testReferenceAddress(int &x) {
// FIXME: Move non-zero reference assumption out of RangeConstraintManager.cpp:422
#ifdef ANALYZER_CM_Z3
clang_analyzer_eval(&x != 0); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(&ref() != 0); // expected-warning{{UNKNOWN}}
#else
clang_analyzer_eval(&x != 0); // expected-warning{{TRUE}}
clang_analyzer_eval(&ref() != 0); // expected-warning{{TRUE}}
#endif

#ifdef ANALYZER_CM_Z3
clang_analyzer_eval(&getS().x != 0); // expected-warning{{UNKNOWN}}
#else
clang_analyzer_eval(&getS().x != 0); // expected-warning{{TRUE}}
#endif

#ifdef ANALYZER_CM_Z3
clang_analyzer_eval(&getSP()->x != 0); // expected-warning{{UNKNOWN}}
#else
clang_analyzer_eval(&getSP()->x != 0); // expected-warning{{TRUE}}
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/unary-sym-expr-z3-refutation.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ void k(long L) {
int h = g + 1;
int j;
j += -h < 0; // should not crash
// expected-warning@-1{{garbage}}
// expected-warning@-1{{The left expression of the compound assignment uses uninitialized memory [core.uninitialized.Assign]}}
}
2 changes: 1 addition & 1 deletion clang/test/Analysis/z3-crosscheck-max-attempts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// CHECK: crosscheck-with-z3-max-attempts-per-query = 3

// RUN: rm -rf %t && mkdir %t
// RUN: %host_cxx -shared -fPIC \
// RUN: %host_cxx -shared -fPIC -I %z3_include_dir \
// RUN: %S/z3/Inputs/MockZ3_solver_check.cpp \
// RUN: -o %t/MockZ3_solver_check.so

Expand Down
6 changes: 4 additions & 2 deletions clang/test/Analysis/z3-crosscheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config crosscheck-with-z3=true -verify %s
// REQUIRES: z3

// XFAIL: *

void clang_analyzer_dump(float);

int foo(int x)
Expand Down Expand Up @@ -64,7 +66,7 @@ void floatUnaryNegInEq(int h, int l) {
clang_analyzer_dump((float)l); // expected-warning-re {{(float) (reg_${{[0-9]+}}<int l>)}}
if (-(float)h != (float)l) { // should not crash
j += 10;
// expected-warning@-1{{garbage}}
// expected-warning@-1{{The left expression of the compound assignment uses uninitialized memory [core.uninitialized.Assign]}}
}
}

Expand All @@ -74,7 +76,7 @@ void floatUnaryLNotInEq(int h, int l) {
clang_analyzer_dump((float)l); // expected-warning-re {{(float) (reg_${{[0-9]+}}<int l>)}}
if ((!(float)h) != (float)l) { // should not crash
j += 10;
// expected-warning@-1{{garbage}}
// expected-warning@-1{{The left expression of the compound assignment uses uninitialized memory [core.uninitialized.Assign]}}
}
}

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/z3/D83660.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: rm -rf %t && mkdir %t
// RUN: %host_cxx -shared -fPIC \
// RUN: %host_cxx -shared -fPIC -I %z3_include_dir \
// RUN: %S/Inputs/MockZ3_solver_check.cpp \
// RUN: -o %t/MockZ3_solver_check.so
//
Expand Down
2 changes: 0 additions & 2 deletions clang/test/Analysis/z3/crosscheck-statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

// REQUIRES: z3

// expected-error@1 {{Z3 refutation rate:1/2}}

int accepting(int n) {
if (n == 4) {
n = n / (n-4); // expected-warning {{Division by zero}}
Expand Down
3 changes: 0 additions & 3 deletions clang/test/Analysis/z3/enabled.c

This file was deleted.

6 changes: 0 additions & 6 deletions clang/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ if(LLVM_INCLUDE_SPIRV_TOOLS_TESTS)
)
endif()

set(CLANG_TEST_PARAMS
USE_Z3_SOLVER=0
)

if( NOT CLANG_BUILT_STANDALONE )
list(APPEND CLANG_TEST_DEPS
llvm-config
Expand Down Expand Up @@ -195,13 +191,11 @@ set_target_properties(clang-test-depends PROPERTIES FOLDER "Clang/Tests")
add_lit_testsuite(check-clang "Running the Clang regression tests"
${CMAKE_CURRENT_BINARY_DIR}
#LIT ${LLVM_LIT}
PARAMS ${CLANG_TEST_PARAMS}
DEPENDS ${CLANG_TEST_DEPS}
ARGS ${CLANG_TEST_EXTRA_ARGS}
)

add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR}
PARAMS ${CLANG_TEST_PARAMS}
DEPENDS ${CLANG_TEST_DEPS}
FOLDER "Clang tests/Suites"
)
Expand Down
3 changes: 3 additions & 0 deletions clang/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def have_host_clang_repl_cuda():

if config.clang_staticanalyzer_z3:
config.available_features.add("z3")
config.substitutions.append(
("%z3_include_dir", config.clang_staticanalyzer_z3_include_dir)
)
else:
config.available_features.add("no-z3")

Expand Down
2 changes: 1 addition & 1 deletion clang/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ config.clang_default_pie_on_linux = @CLANG_DEFAULT_PIE_ON_LINUX@
config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
config.clang_staticanalyzer_z3 = @LLVM_WITH_Z3@
config.clang_staticanalyzer_z3_include_dir = "@Z3_INCLUDE_DIR@"
config.clang_enable_cir = @CLANG_ENABLE_CIR@
config.clang_examples = @CLANG_BUILD_EXAMPLES@
config.enable_shared = @ENABLE_SHARED@
Expand All @@ -39,7 +40,6 @@ config.reverse_iteration = @LLVM_ENABLE_REVERSE_ITERATION@
config.host_arch = "@HOST_ARCH@"
config.perl_executable = "@PERL_EXECUTABLE@"
config.python_executable = "@Python3_EXECUTABLE@"
config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@")
config.has_plugins = @CLANG_PLUGIN_SUPPORT@
config.clang_vendor_uti = "@CLANG_VENDOR_UTI@"
config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
Expand Down
1 change: 0 additions & 1 deletion llvm/utils/gn/secondary/clang/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ write_lit_config("lit_site_cfg") {
"LLVM_USE_SANITIZER=",
"LLVM_VERSION_MAJOR=$llvm_version_major",
"Python3_EXECUTABLE=$python_path",
"USE_Z3_SOLVER=",
"PPC_LINUX_DEFAULT_IEEELONGDOUBLE=0",
]

Expand Down
3 changes: 2 additions & 1 deletion llvm/utils/lit/lit/llvm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@ def use_clang(
ToolSubst(
"%clang_analyze_cc1",
command="%clang_cc1",
extra_args=["-analyze", "%analyze", "-setup-static-analyzer"]
# -setup-static-analyzer ensures that __clang_analyzer__ is defined
extra_args=["-analyze", "-setup-static-analyzer"]
+ additional_flags,
),
ToolSubst(
Expand Down
Loading