This is another PR towards the goal of getting Z3 to compile cleanly
when included via FetchContents into clang-tidy, which uses a pretty
strict set of warnings.
This one concerns "-Wzero-length-array". Many classes in Z3 use the
"trailing array" idiom: the last field of the class C is a zero-length
array of some type T, and the allocation of an instance adds extra space
for some number of T's (usually the number is held in some other field
of C).
When the flag -Wzero-length-array is used, this gives warnings like:
```
warning: zero size arrays are an extension [-Wzero-length-array]
```
This PR first adds -Wzero-length-array to the CLANG_ONLY_WARNINGS
defined in compiler_warnings.cmake. This causes the warnings to occur in
a normal clang Z3 build. We then make a trailing_array.h, that defines a
TRAILING_ARRAY(type, field) macro. This is defined, on per-comnpiler
basis, to disable such warnings if they're enabled. I chose this route
because the use of the idiom is baked deeply into Z3, so it didn't seem
feasable to consider alternative patterns (like, for example, having the
trailing field be a pointer to a separately allocated array).
The rest of the changes in the PR are uses of this include file and
macro in place of "raw" zero-length arrays.
With these changes, all instances of this warning are removed.
* Initial plan
* Disable C++98 compatibility warnings for Clang to fix vcpkg build freeze
Add -Wno-c++98-compat and -Wno-c++98-compat-pedantic flags to prevent
excessive warning output when building with clang-cl or when -Weverything
is enabled. These warnings are not useful for Z3 since it requires C++20.
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
* Update doc for `mk_context`.
* Migrating to cmake.
* Migrating to cmake. It builds both internal or external libz3.
* Start to work on platform-specific problem.
* Messy notes.
* debug.
* Cleanup a bit.
* Fixing shared lib extension.
* Minor.
* Resume working on this PR.
* Remove including `AddOCaml`.
* Keep `z3.ml` and `z3.mli` in the src but specify the generated file in the bin.
* Keep `ml_example.ml` in the src.
* Try github action for ocaml.
* Add workflow using matrix.
* Fix mac linking once more.
* Bypass @rpath in building sanity check.
* sat_literal: make constants constexpr
* dlist: rename elem -> list
* tbv: use get_bit
* additional pdd and rational tests
* egraph: callback setters take functions by value
This allows to set callbacks without defining a separate variable for
the callback lambda.
(previous usage does one copy of the function, exactly as before)
* cmake: enable compiler error when non-void function does not return value
`FindPythonInterp` has been deprecated for a long time and is more
verbal about that deprecation now.
The build system no longer uses `PYTHON_EXECUTABLE` but instead uses
`Python3_EXECUTABLE`.
* CMake: simplify FindGMP.cmake
Remove printing of all the different variables, and let FPHSA output the library
name. Add an imported target, which bundles the library and the include
directories for easier usage.
* fix build: vector::c_ptr() now is vector::data()
* CMake: use Threads::Threads imported module
Otherwise the setting of THREADS_PREFER_PTHREAD_FLAG has no effect.
* CMake: remove needless policy setting
The minimum required version is CMake 3.4, where these policies are already set
to new because they were introduced earlier.
* CMake: remove needless variable expansion
This removes an incomplete check in cmake git-submodule detection
logic, directly using filepath probing instead. As a direct usecase,
it fixes submodule building for https://github.com/prove-rs/z3.rs.
The code should refrain from using global parameters such as CMAKE_SOURCE_DIR/CMAKE_BINARY_DIR, especially here which is handling the case of Z3 being a submodule. Instead, use project specific variables like Z3_SOURCE_DIR so that people can incorporate z3 build as part of their build-system.
reported by @nbraud reported in #1227.
Previously the CMake build system assumed that the `.git` file must
be a directory. This is not the case when the working directory
is a "git worktree". In this case the `.git` file is just a plain
file that points to a directory within the true `.git` directory.
This commit essentially implements the logic to traverse this extra
level of indirection and removes some assumptions that the `.git`
file is a directory.