Repository navigation
✨ Add libhal_add_compile_checks() for must-not-compile tests - #63
Merged
Merged
Conversation
Compiles each file with Clang's -verify mode, where the file marks the
diagnostics it must produce:
// expected-error@+1 {{is returned}}
return sensor(bus);
The build fails when an expected diagnostic is missing or an unexpected
one appears. This lets libraries test that misuse is rejected by the type
system or reported by Clang's lifetime safety analysis.
-verify is added by a compiler launcher (LibhalVerifyLauncher.cmake)
rather than a compile option: the launcher wraps only the compile step,
while a compile option would also reach the module dependency scanner,
which doesn't see the expected-* comments and fails.
Clang 23+ only; other compilers skip the checks.
kammce
force-pushed
the
add-compile-checks
branch
from
October 14, 2026 19:25
e6b0ec4 to
1565a31
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
libhal_add_compile_checks(), for testing code that must fail to compile: misuse rejected by the type system, and dangling references reported by Clang's lifetime safety analysis.Each file is compiled with Clang's
-verifymode and marks the diagnostics it must produce:The build fails if an expected diagnostic is missing or an unexpected one appears. Known gaps can stay in a file without annotations; once Clang starts catching them, the build fails and they become checked cases.
How
<target>_compile_checks, built withLIBHAL_CXX_FLAGS, linked to the target, with clang-tidy off.-verifyis added by a compiler launcher,LibhalVerifyLauncher.cmake(run withcmake -P), because a launcher wraps only the compile step. As a compile option it would also reach the module dependency scanner, which doesn't see theexpected-*comments and fails.Testing
macOS 27, LLVM 23.1.2: libhal v5's 36 compile-check cases, converted to four files (libhal#245), pass. Removing an expectation, or expecting an error on a known gap, fails the build with Clang's message. The launcher passes arguments through unchanged and returns the compiler's exit code. Incremental builds: no change rebuilds no checks; editing
fixtures.hpporlifetime.cppmrebuilds all four; editing one check file rebuilds only that one; a broken check fails again on the next build until fixed.