Skip to content

Commit e34e021

Browse files
authored
[clang] Fix tests requiring Z3 headers in standalone builds (#146200)
Fix running tests that require Z3 headers in standalone build. They were wrongly relying on `Z3_INCLUDE_DIR` being passed through from LLVM, which is not the case for a standalone build. Instead, perform `find_package(Z3)` again to find Z3 development files and set `Z3_INCLUDE_DIR`. While at it, handle the possibility that Z3 development package is no longer installed -- run the tests only if both LLVM has been built against Z3, and the headers are still available. #145731 (comment) Signed-off-by: Michał Górny <[email protected]>
1 parent 3c4e730 commit e34e021

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

clang/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ if(CLANG_BUILT_STANDALONE)
150150
endif()
151151

152152
umbrella_lit_testsuite_begin(check-all)
153+
154+
# If LLVM was built with Z3, check if we still have the headers around.
155+
# They are used by a few tests.
156+
if (LLVM_WITH_Z3)
157+
find_package(Z3 4.8.9)
158+
endif()
153159
endif() # LLVM_INCLUDE_TESTS
154160
endif() # standalone
155161

clang/test/Analysis/z3-crosscheck-max-attempts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// RUN: Z3_SOLVER_RESULTS="UNDEF,UNDEF,SAT" %{mocked_clang} %{attempts}=3 -verify=accepted
3333

3434

35-
// REQUIRES: z3, asserts, shell, system-linux
35+
// REQUIRES: z3, z3-devel, asserts, shell, system-linux
3636

3737
// refuted-no-diagnostics
3838

clang/test/Analysis/z3/D83660.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// RUN: %clang_cc1 -analyze -analyzer-constraints=z3 -setup-static-analyzer \
99
// RUN: -analyzer-checker=core %s -verify
1010
//
11-
// REQUIRES: z3, asserts, shell, system-linux
11+
// REQUIRES: z3, z3-devel, asserts, shell, system-linux
1212
//
1313
// Works only with the z3 constraint manager.
1414
// expected-no-diagnostics

clang/test/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ llvm_canonicalize_cmake_booleans(
2929
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS
3030
)
3131

32+
# Run tests requiring Z3 headers only if LLVM was built with Z3
33+
# and the headers are available while building Clang -- the latter may
34+
# not be the case when building standalone against installed LLVM.
35+
set(TEST_WITH_Z3_DEVEL 0)
36+
if(LLVM_WITH_Z3 AND Z3_FOUND)
37+
set(TEST_WITH_Z3_DEVEL 1)
38+
endif()
39+
3240
configure_lit_site_cfg(
3341
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
3442
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py

clang/test/lit.cfg.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,11 @@ def have_host_clang_repl_cuda():
201201

202202
if config.clang_staticanalyzer_z3:
203203
config.available_features.add("z3")
204-
config.substitutions.append(
205-
("%z3_include_dir", config.clang_staticanalyzer_z3_include_dir)
206-
)
204+
if config.clang_staticanalyzer_z3_devel:
205+
config.available_features.add("z3-devel")
206+
config.substitutions.append(
207+
("%z3_include_dir", config.clang_staticanalyzer_z3_include_dir)
208+
)
207209
else:
208210
config.available_features.add("no-z3")
209211

clang/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ config.clang_default_pie_on_linux = @CLANG_DEFAULT_PIE_ON_LINUX@
2727
config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
2828
config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
2929
config.clang_staticanalyzer_z3 = @LLVM_WITH_Z3@
30+
config.clang_staticanalyzer_z3_devel = @TEST_WITH_Z3_DEVEL@
3031
config.clang_staticanalyzer_z3_include_dir = "@Z3_INCLUDE_DIR@"
3132
config.clang_enable_cir = @CLANG_ENABLE_CIR@
3233
config.clang_examples = @CLANG_BUILD_EXAMPLES@

0 commit comments

Comments
 (0)