Skip to content
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

CI: Run crux-llvm test suite in macOS #1172

Merged
merged 6 commits into from
Feb 14, 2024
Merged

CI: Run crux-llvm test suite in macOS #1172

merged 6 commits into from
Feb 14, 2024

Conversation

RyanGlScott
Copy link
Contributor

Previously, we concocted a clang-withIncl script for running Clang on macOS CI runners, but this neglected to pass any arguments to Clang (among other issues). This patch replaces the clang-withIncl machinery with a much simpler, Homebrew-based setup for install Clang/LLVM. With this in place, we can finally run the crux-llvm test suite on macOS.

Fixes #999.


Running the test suite on macOS reveals several additional issues, among them #885 and #1013. This PR also applies a series of fixes for these issues.

RyanGlScott and others added 6 commits February 13, 2024 15:31
These packages do not require using an LLVM toolchain in order to run their
test suites, so they are relatively portable.
On the Darwin family of operating systems, which includes macOS, various
`libc` functions are defined in terms of aliases that contain various odd
prefixes and suffixes. For instance, the `write()` function is actually defined
in terms of a lower-level `\01_write()` function, and if you compile a C program
containing an occurrence of `write()` with Clang on Darwin, the resulting LLVM
bitcode will mention `\01_write()`, not `write()`. This poses an issue for
`crucible-llvm`'s override for `write()`, since it now mentions the wrong name
on Darwin. Moreover, it isn't feasible to make the LLVM bitcode mention
`write()` instead.

To compensate for this oddity, we introduce a new `DarwinAliasMatch` template
matcher and use it in `basic_llvm_override` when compiling on Darwin. This
matcher indicates that a function name is allowed to match the override name
after possibly removing some Darwin-related prefixes or suffixes. See
`Note [Darwin aliases]` for the full story.

Fixes #885.
The `crux-llvm` test suite had accumulated quite a bit of non-portable code
which causes various test cases to fail when compiled with macOS. This commit
attempts to bring some sanity to the test case:

* Several test cases use non-standard C functions that are not present on
  macOS. When appropriate, we section off any uses of non-portable functions
  with `#if !defined(__APPLE__)` CPP.
* Several test cases were missing `#include`s that were added behind the scenes
  on Linux, but not on macOS. These are simple enough to fix by just making the
  necessary `#include`s explicit.
* Some `math.h` functions compile down to low-level functions that are
  exclusive to macOS. For instance, `isnan(x)` compiles to `__isnand(x)` on
  macOS when `x` is a `double`, and we had neglected to add an override for
  `__isnand()`. This is easily fixed by adding the appropriate overrides.
* Clang on macOS is pickier about the placement of `__attribute__((noinline))`
  in a function declaration, so one occurrence of this attribute was moved to
  avoid macOS-specific warnings.
* We had special SV-COMP treatment for the `__assert_fail()` function on Linux,
  but not for the macOS counterpart `__assert_rtn()`. This seems inconsistent,
  causes some test cases to fail, and has caused us issues with debugging
  things previously (see #940 (comment)).
  For these reasons, we now treat `__assert_fail()` and `__assert_rtn()`
  uniformly.

Fixes #1013.
On Ubuntu, `isinf(x)` will return `1` if `x` is positive infinity and `-1` if
`x` is negative infinity. The C standard doesn't guarantee this, however, as it
only requires that `isinf(x)` return _some_ non-zero value if `x` is infinite.
More to the point, Apple Clang's version of `isinf` doesn't return the same
values that Ubuntu's Clang does, but the `isinf.c` test case in the `crux-llvm`
test suite specifically checks for these values, making the test fail on macOS.

This patch makes the checks in `isinf.c` more general so that they will pass
regardless of which non-zero value gets returned from `isinf(x)`.
Previous, we concocted a `clang-withIncl` script for running Clang on macOS CI
runners, but this neglected to pass any arguments to Clang (among other
issues). This patch replaces the `clang-withIncl` machinery with a much
simpler, Homebrew-based setup for install Clang/LLVM. With this in place, we
can finally run the `crux-llvm` test suite on macOS.

Fixes #999.
@RyanGlScott RyanGlScott marked this pull request as ready for review February 13, 2024 22:34
Copy link
Member

@kquick kquick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removal of all the special case for MacOS testing is nice.

I assume the generalization of zero v.s. non-zero in isinf and isnan tests is due to different return values from the different OS environments?

@RyanGlScott
Copy link
Contributor Author

I assume the generalization of zero v.s. non-zero in isinf and isnan tests is due to different return values from the different OS environments?

Yes. I added this to the commit message:

On Ubuntu, isinf(x) will return 1 if x is positive infinity and -1 if x is negative infinity. The C standard doesn't guarantee this, however, as it only requires that isinf(x) return some non-zero value if x is infinite. More to the point, Apple Clang's version of isinf doesn't return the same values that Ubuntu's Clang does, but the isinf.c test case in the crux-llvm test suite specifically checks for these values, making the test fail on macOS.

This patch makes the checks in isinf.c more general so that they will pass regardless of which non-zero value gets returned from isinf(x).

@RyanGlScott RyanGlScott merged commit 6d0af7c into master Feb 14, 2024
31 checks passed
@RyanGlScott RyanGlScott deleted the fix-macos-ci branch February 14, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI accidentally skips over crux-llvm tests on macOS
2 participants