|
1 | 1 | #!/usr/bin/env bash |
2 | | -# macOS 27: why libc++ 22's std.cppm loses INFINITY/NAN. One READING per fact. |
| 2 | +# macOS 27: libc++ 22 std.cppm loses INFINITY/NAN. Round 2: mechanism and candidate fixes. |
3 | 3 | set +e |
4 | 4 | r() { echo "READING $*"; } |
5 | | -r "os $(sw_vers -productVersion) $(sw_vers -buildVersion) xcode=$(xcodebuild -version | tr '\n' ' ')" |
6 | | -r "xcrun sdk=$(xcrun --show-sdk-path) ver=$(xcrun --show-sdk-version)" |
7 | | -CLT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk |
8 | | -r "clt sdk link=$(readlink $CLT) exists=$([ -d $CLT ] && echo y || echo n) settings=$(plutil -extract Version raw $CLT/SDKSettings.plist 2>/dev/null)" |
9 | | -ls -la /Library/Developer/CommandLineTools/SDKs/ 2>&1 | sed 's/^/READING clt-sdks /' |
10 | | -XSDK=$(xcrun --show-sdk-path) |
11 | | -for s in $CLT $XSDK; do |
12 | | - r "math.h in $s: INFINITY defs: $(grep -rn 'define[[:space:]]*INFINITY' $s/usr/include/math.h $s/usr/include/_math.h $s/usr/include/math 2>/dev/null | head -3 | tr '\n' ' ')" |
13 | | - r "math.h head in $s: $(grep -n 'include\|__MATH' $s/usr/include/math.h 2>/dev/null | head -12 | tr '\n' ' ')" |
14 | | -done |
15 | | -# xlings llvm |
16 | | -curl -fsSL https://raw.githubusercontent.com/openxlings/xlings/main/tools/other/quick_install.sh | bash -s v2026.9.16.1 >/dev/null 2>&1 |
17 | | -export PATH="$HOME/.xlings/subos/current/bin:$PATH" |
18 | | -xlings install llvm@22.1.8 -y >/dev/null 2>&1 |
19 | | -L=$(ls -d $HOME/.xlings/data/xpkgs/xim-x-llvm/22.1.8) |
20 | | -r "llvm cfg: $(cat $L/bin/clang++.cfg | tr '\n' ' ')" |
21 | | -S=$L/share/libc++/v1/std.cppm |
| 5 | +L="$LLVM_ROOT"; SDK=$(xcrun --show-sdk-path); S=$L/share/libc++/v1/std.cppm |
| 6 | +r "llvm=$L cfg=$(tr '\n' ' ' < $L/bin/clang++.cfg)" |
| 7 | +r "math.h 55-95:"; sed -n 55,95p $SDK/usr/include/math.h | sed 's/^/READING math.h| /' |
| 8 | +FH=$($L/bin/clang -print-resource-dir)/include/float.h |
| 9 | +r "clang float.h INFINITY region:"; grep -n -B4 -A3 'define INFINITY' $FH | sed 's/^/READING float.h| /' |
| 10 | +AF=$(/usr/bin/clang -print-resource-dir)/include/float.h |
| 11 | +r "apple float.h INFINITY region:"; grep -n -B4 -A3 'define INFINITY' $AF | sed 's/^/READING apple-float.h| /' |
22 | 12 | W=$(mktemp -d); cd $W |
23 | | -try() { name=$1; shift; out=$("$@" 2>&1); rc=$?; r "$name rc=$rc $(printf '%s' "$out" | grep -m2 'error' | tr '\n' ' ')"; } |
24 | | -try cfg-clt $L/bin/clang++ -std=c++23 -Wno-reserved-module-identifier --precompile $S -o a.pcm |
25 | | -try isysroot-xc $L/bin/clang++ -std=c++23 -Wno-reserved-module-identifier --precompile $S -o b.pcm --sysroot=$XSDK |
26 | | -try no-cfg-xc $L/bin/clang++ --no-default-config -std=c++23 -nostdinc++ -isystem $L/include/c++/v1 -isysroot $XSDK -Wno-reserved-module-identifier --precompile $S -o c.pcm |
27 | | -printf '#include <cmath>\n#ifndef INFINITY\n#error no INFINITY after cmath\n#endif\n#include <complex>\nint main(){}\n' > t.cpp |
28 | | -try hdr-clt $L/bin/clang++ -std=c++23 -fsyntax-only t.cpp |
29 | | -try hdr-xc $L/bin/clang++ -std=c++23 -fsyntax-only t.cpp --sysroot=$XSDK |
30 | | -printf '#include <math.h>\n#ifndef INFINITY\n#error no INFINITY after math.h\n#endif\nint main(){}\n' > m.c |
31 | | -try c-math-clt $L/bin/clang -fsyntax-only m.c |
32 | | -try c-math-apple /usr/bin/clang -fsyntax-only m.c |
33 | | -try cxx-apple /usr/bin/clang++ -std=c++23 -fsyntax-only t.cpp |
34 | | -$L/bin/clang++ -std=c++23 -E -dD t.cpp 2>/dev/null | grep -n 'INFINITY\|# 1 ".*math' | head -10 | sed 's/^/READING pp-clt /' |
35 | | -$L/bin/clang++ -std=c++23 -H -fsyntax-only t.cpp 2>&1 | grep -i 'math' | head -12 | sed 's/^/READING includes-clt /' |
36 | | -# the released mcpp |
37 | | -xlings install mcpp@2026.9.16.2 -y >/dev/null 2>&1 |
38 | | -M=$(ls $HOME/.xlings/data/xpkgs/xim-x-mcpp/2026.9.16.2/bin/mcpp) |
39 | | -cd $(mktemp -d); "$M" new h >/dev/null 2>&1; cd h |
40 | | -out=$("$M" run 2>&1); rc=$? |
41 | | -r "mcpp-2026.9.16.2 new+run rc=$rc $(printf '%s' "$out" | grep -m3 -E 'error|Hello|sysroot' | tr '\n' ' ')" |
| 13 | +BASE=(--no-default-config -nostdinc++ -isystem $L/include/c++/v1 -isysroot $SDK -Wno-reserved-module-identifier) |
| 14 | +try() { name=$1; shift; out=$("$@" 2>&1); rc=$?; r "$name rc=$rc $(printf '%s' "$out" | grep -m1 'error' | cut -c1-200)"; } |
| 15 | +printf 'int main(){ return __has_feature(modules); }\n' > hf.cpp |
| 16 | +try hasfeature-modules-in-precompile-of-plain $L/bin/clang++ "${BASE[@]}" -std=c++23 -fsyntax-only hf.cpp |
| 17 | +printf 'export module m;\n#if __has_feature(modules)\n#error MODULES_ON\n#endif\n' > hf.cppm |
| 18 | +try hasfeature-modules-in-module-interface $L/bin/clang++ "${BASE[@]}" -std=c++23 --precompile hf.cppm -o hf.pcm |
| 19 | +try c++23 $L/bin/clang++ "${BASE[@]}" -std=c++23 --precompile $S -o a.pcm |
| 20 | +try gnu++23 $L/bin/clang++ "${BASE[@]}" -std=gnu++23 --precompile $S -o b.pcm |
| 21 | +try c++23-U-strict $L/bin/clang++ "${BASE[@]}" -std=c++23 -U__STRICT_ANSI__ --precompile $S -o c.pcm |
| 22 | +try c++23-inc-math $L/bin/clang++ "${BASE[@]}" -std=c++23 -include math.h --precompile $S -o d.pcm |
| 23 | +try c++23-fbuiltin-inf $L/bin/clang++ "${BASE[@]}" -std=c++23 "-DINFINITY=__builtin_inff()" "-DNAN=__builtin_nanf(\"\")" --precompile $S -o e.pcm |
| 24 | +try c++26 $L/bin/clang++ "${BASE[@]}" -std=c++26 --precompile $S -o f.pcm |
| 25 | +SDK26=/Library/Developer/CommandLineTools/SDKs/MacOSX26.5.sdk |
| 26 | +BASE26=(--no-default-config -nostdinc++ -isystem $L/include/c++/v1 -isysroot $SDK26 -Wno-reserved-module-identifier) |
| 27 | +try c++23-sdk26.5 $L/bin/clang++ "${BASE26[@]}" -std=c++23 --precompile $S -o g.pcm |
| 28 | +# a program importing std, end to end, with the variant that works |
| 29 | +for std in c++23 gnu++23; do |
| 30 | + rm -rf p; mkdir p; cd p |
| 31 | + $L/bin/clang++ "${BASE[@]}" -std=$std --precompile $S -o std.pcm >/dev/null 2>&1 |
| 32 | + $L/bin/clang++ "${BASE[@]}" -std=$std -c std.pcm -o std.o >/dev/null 2>&1 |
| 33 | + printf 'import std;\nint main(){ std::println("inf={} nan={}", std::numeric_limits<double>::infinity(), std::isnan(std::nan(""))); }\n' > m.cpp |
| 34 | + $L/bin/clang++ "${BASE[@]}" -std=$std -fmodule-file=std=std.pcm -c m.cpp -o m.o >/dev/null 2>&1 |
| 35 | + $L/bin/clang++ --no-default-config -isysroot $SDK -fuse-ld=lld -nostdlib++ m.o std.o $L/lib/libc++.a $L/lib/libc++abi.a -o m >/dev/null 2>&1 |
| 36 | + r "program $std: $(./m 2>&1)" |
| 37 | + cd .. |
| 38 | +done |
42 | 39 | exit 0 |
0 commit comments