Skip to content

Commit e2ed1e1

Browse files
committed
cenv_probe: cacheRoot before hostStripMacros; presents=none emits -fno-short-wchar
The previous parameter order put hostStripMacros before cacheRoot. That meant callers passing a custom cache directory (the test suite does this in every TEST) had to also pass an empty hostStripMacros, even though they did not care about the strip. Reordering puts cacheRoot first so the strip's default value (`{}`) is what callers that override cache actually mean, and tests that want to assert the strip's behaviour pass both. prepare.cppm's call passes both, in the reordered order. The "presents = none" wchar branch used to assert tokens.empty(). That is wrong under the new freestanding-wchar rule: -fno-short-wchar is emitted regardless of presents, because the wchar realisation is about width (the toolchain's host-contaminated default), not about identity (what macros the preprocessor states). Updated to assert the flag's presence and the absence of any identity macros.
1 parent f661260 commit e2ed1e1

4 files changed

Lines changed: 34 additions & 12 deletions

File tree

src/build/prepare.cppm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10927,6 +10927,7 @@ prepare_build(bool print_fingerprint,
1092710927
tc->binaryPath, probeArgv,
1092810928
tc->cEnvExpectWcharBits, tc->cEnvExpectLongBytes,
1092910929
tc->cEnvExpectDefined, tc->cEnvExpectUndefined,
10930+
mcpp::home::cache_root(),
1093010931
hostStripMacros);
1093110932
if (!probe) {
1093210933
refusal::record(refusal::Code::CEnvUnrealisable);

src/toolchain/cenv_probe.cppm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,20 @@ struct Result {
8585
// DIFFERENT failure from the declaration disagreeing with what compiled: the
8686
// caller reports it as a build error naming the command, not as a §3.2
8787
// verification mismatch.
88+
//
89+
// `hostStripMacros` is placed AFTER `cacheRoot` (the latter being the test
90+
// suite's frequent override) to keep the existing call sites — which pass
91+
// neither — source-compatible. New callers that DO need the strip supply
92+
// both arguments; tests that pin a temp cache directory pass the strip
93+
// empty by default.
8894
std::expected<Result, std::string> verify(
8995
const std::filesystem::path& compilerBin,
9096
const std::vector<std::string>& argv,
9197
int expectWcharBits, int expectLongBytes,
9298
const std::vector<std::string>& expectDefined,
9399
const std::vector<std::string>& expectUndefined,
94-
const std::vector<std::string>& hostStripMacros = {},
95-
const std::filesystem::path& cacheRoot = mcpp::home::cache_root());
100+
const std::filesystem::path& cacheRoot = mcpp::home::cache_root(),
101+
const std::vector<std::string>& hostStripMacros = {});
96102

97103
} // namespace mcpp::toolchain::cenv_probe
98104

@@ -141,8 +147,8 @@ std::expected<Result, std::string> verify(
141147
int expectWcharBits, int expectLongBytes,
142148
const std::vector<std::string>& expectDefined,
143149
const std::vector<std::string>& expectUndefined,
144-
const std::vector<std::string>& hostStripMacros,
145-
const std::filesystem::path& cacheRoot) {
150+
const std::filesystem::path& cacheRoot,
151+
const std::vector<std::string>& hostStripMacros) {
146152

147153
// The cache key is the compiler binary's own identity plus every argv
148154
// token, in order — exactly the inputs that can change what `-dM`

tests/unit/test_cenv.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,22 @@ TEST(CEnv, FreestandingAcceptsNone) {
166166
auto ok = decl(ts::CAbiPresents::None, ts::CAbiDataModel::ArchDefault, 32);
167167
auto r1 = cenv::realise(ok, "none", "riscv64", true);
168168
ASSERT_TRUE(r1.has_value()) << r1.error();
169-
EXPECT_TRUE(r1->tokens.empty());
169+
// The wchar branch ALWAYS emits on a freestanding target now (wave
170+
// 2026-09-18, openkal-llvm-runtime#24, Windows-host × riscv64-none-elf
171+
// measurement): the toolchain's host-contaminated default is not
172+
// something the engine can trust, so `wchar = 32` produces
173+
// `-fno-short-wchar` regardless of what `presents` says. Identity
174+
// macros stay absent (the `none` presents value's whole point),
175+
// but the wchar realisation still applies — and so does the
176+
// expectation, which the probe then measures.
177+
EXPECT_TRUE(has(r1->tokens, "-fno-short-wchar"));
178+
EXPECT_TRUE(r1->expectUndefined.empty())
179+
<< "presents = none declares NO environment-identity macros, "
180+
"neither defined nor undefined";
181+
EXPECT_TRUE(r1->expectDefined.empty());
182+
// Data-model is not checked on freestanding (no C library runtime to
183+
// present it), so `expectLongBytes` stays at 0.
184+
EXPECT_EQ(r1->expectLongBytes, 0);
170185
}
171186

172187
// A freestanding target ALSO realises `presents = "posix"` (design §3.3,

tests/unit/test_cenv_probe.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ TEST(CenvProbe, AHostStrippedMacroIsAbsentFromTheDump) {
245245
// First confirm the host's compiler would NOT define the macro absent
246246
// any help — a baseline so the strip's effect is unambiguous.
247247
auto baseline = cp::verify(cxx(), {}, 0, 0, {}, {kProbeStripUndefined},
248-
{}, cache.dir);
248+
cache.dir);
249249
ASSERT_TRUE(baseline.has_value()) << baseline.error();
250250
EXPECT_TRUE(baseline->mismatches.empty())
251251
<< "test-only macro " << kProbeStripUndefined
@@ -258,8 +258,9 @@ TEST(CenvProbe, AHostStrippedMacroIsAbsentFromTheDump) {
258258
{std::format("-D{}=", kProbeStripDefined)},
259259
0, 0,
260260
{}, {kProbeStripDefined}, // expected: undefined
261-
{std::format("-U{}", kProbeStripDefined)}, // host strip
262-
cache.dir);
261+
cache.dir,
262+
{std::format("-U{}", kProbeStripDefined)} // host strip
263+
);
263264
ASSERT_TRUE(stripped.has_value()) << stripped.error();
264265
EXPECT_TRUE(stripped->mismatches.empty())
265266
<< "a `-D…` followed by `-U…` must yield no mismatch: "
@@ -269,11 +270,10 @@ TEST(CenvProbe, AHostStrippedMacroIsAbsentFromTheDump) {
269270
TEST(CenvProbe, AStripListDoesNotShareACacheSlotWithAnEmptyStrip) {
270271
if (cxx().empty()) GTEST_SKIP() << "no C++ compiler found to probe";
271272
TmpCache cache;
272-
auto noStrip = cp::verify(cxx(), {}, 0, 0, {}, {}, {}, cache.dir);
273+
auto noStrip = cp::verify(cxx(), {}, 0, 0, {}, {}, cache.dir);
273274
ASSERT_TRUE(noStrip.has_value()) << noStrip.error();
274-
auto withStrip = cp::verify(cxx(), {}, 0, 0, {}, {},
275-
{"-U_MCPP_PROBE_TEST_NO_SUCH_MACRO"},
276-
cache.dir);
275+
auto withStrip = cp::verify(cxx(), {}, 0, 0, {}, {}, cache.dir,
276+
{"-U_MCPP_PROBE_TEST_NO_SUCH_MACRO"});
277277
ASSERT_TRUE(withStrip.has_value()) << withStrip.error();
278278
EXPECT_TRUE(noStrip->ran);
279279
EXPECT_TRUE(withStrip->ran)

0 commit comments

Comments
 (0)