Repository navigation
A program that checks builds when a C++ compiler calls a self-assignment, a self-comparison or an unsigned comparison with zero pointless - #187
Open
SamMausberg wants to merge 2 commits into
Open
SamMausberg wants to merge 2 commits into
SamMausberg wants to merge 2 commits into
Conversation
…ent, a self-comparison or an unsigned comparison with zero pointless
SamMausberg
enabled auto-merge (squash)
September 28, 2026 19:36
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This branch has not been deployed
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.
Summary
A program that checks now builds when a C++ compiler calls part of it pointless. The default build makes every C++ warning an error, and before this change it refused
which
cairn checkaccepts: clang++ onseen = seen(-Wself-assign), both compilers onok != ok(-Wtautological-compare), and g++ onw < 0,w >= 0and theu64instance ofnegative(-Wtype-limits).cairn runsaid it was "a fault of the CAIRN compiler, never of the program", which was right.Motivation
Part of #36. The typed fuzzer I am building for #36 found this in its first batch: 23 of the first 96 programs it built under the default flags, seed 2, failed this way, and every one cut down to one of three statements, a self-assignment, a self-comparison or an unsigned comparison with zero. The generic
negativeis the form an agent is likely to meet: a bound ofintegercovers signed and unsigned types, each instance is its own C++ function, and g++ judges the unsigned one on its own.Each of the three means in C++ what it means in CAIRN: a self-assignment does nothing, an integer compared with itself is equal, and an unsigned value is never below zero. The warnings are advice about the source, and CAIRN's source already has one meaning for them, so the build stops treating them as errors, as it already does for a local that is never read (
-Wno-unused-variable). The alternative was to refuse these forms in the checker, which would be a language change that refuses correct programs, or to have the emitter rewrite them, which would hide what the program says. nvcc's own front end refuses the unsigned comparison with zero too (#186), in device code and in the host code of a device program, so it is suppressed there beside 177 and 550.Changes
projects/toolchain.py):WARNINGSadds-Wno-self-assign,-Wno-tautological-compareand-Wno-type-limits;DEVICE_WARNINGSsuppresses 186. GCC ignores-Wno-self-assign, which it does not know.tests/soundness/test_fuzz_findings.py, new): the program above built ascairn buildbuilds it and run under clang++ and g++, and the same forms in a device lane and beside it compiled by nvcc for sm_120. The file is where the fuzzer's regression programs will go. The Makefile'sDEVICE_TESTSnames the nvcc test, so the device job compiles it.Behaviour and compatibility
Every host build, sanitized build, freestanding image, nvcc host pass and incremental unit gets the three flags, and every device build suppresses one more nvcc diagnostic. A program that built before builds the same, since a flag that turns a warning off changes no code. Programs with these forms, refused by the native build until now, build. No diagnostic code, emitted C++ or CUDA changes.
Testing
Six of the seven failures are the g++ ThreadSanitizer tests
mainfails on this machine (GCC 11's libtsan on this aarch64 kernel). The seventh wastest_workflow.pyasking for the new nvcc test in the Makefile'sDEVICE_TESTS, which it now is; the second command ran after that. Without the change the three new tests fail: clang++ on-Wself-assignand-Wtautological-compare, g++ on-Wtautological-compareand-Wtype-limits, and nvcc 13.0 on #186 twice. Clang 14 and GCC 11.4 are what this machine has; the floor README names is Clang 13 and GCC 11, and each of the three flags is older than both. Nothing ran on a device: the nvcc test compiles only.Evidence and claims
The native-built claim now holds for accepted programs with these three forms, which it did not. No other claim changes.
Performance
none: the flags silence diagnostics and change no generated code.
Checklist
make editors,make docs): nothing they generate from changed