Skip to content

Use trailing-zero builtin with older libc++ - #243

Closed
cristim wants to merge 1 commit into
OpenSwiftUIProject:mainfrom
cristim:fix/older-libcxx-count-trailing
Closed

cristim wants to merge 1 commit into
OpenSwiftUIProject:mainfrom
cristim:fix/older-libcxx-count-trailing

Conversation

@cristim

@cristim cristim commented Sep 23, 2026

Copy link
Copy Markdown

Summary

Use Clang's trailing-zero builtin when scanning a nonempty free-page map. This preserves the std::countr_zero result for the nonzero unsigned long long returned by to_ullong() and builds with older libc++ headers that lack the C++20 bit operation.

Why

The target-aware arm64 macOS OpenSwiftUI dependency build compiles OpenAttributeGraph against Darling's current libc++ and failed in table.cpp because std::countr_zero was unavailable.

Validation

  • Rebuilt the OpenSwiftUI target with local OpenAttributeGraph sources and Darling's libc++ headers. table.cpp now compiles and the build advances through the C++ sources to Swift errors in Graph.swift (NSDictionary bridging and optional string handling).
  • The loop calls the builtin only while free_pages_map.any() is true, so its zero input case is unreachable.

Contributing

Reproduce with a C++20 compile of table.cpp against the older libc++ in Darling and the local Swift runtime headers selected through OpenAttributeGraph PR #242. AI-assisted changes should check the nonzero precondition and verify allocation scans still choose the least significant free bit.

@Kyle-Ye

Kyle-Ye commented Nov 28, 2026

Copy link
Copy Markdown
Member

Have no plan to support older libc++ here.

@Kyle-Ye Kyle-Ye closed this Nov 28, 2026
@Kyle-Ye

Kyle-Ye commented Nov 28, 2026

Copy link
Copy Markdown
Member

Thanks for putting this together.

OpenAttributeGraphCxx builds in C++20 mode, where std::countr_zero (<bit>) is the standard, portable API across Apple Clang, Linux toolchains, and Windows MSVC (cl.exe does not provide __builtin_ctzll, and __builtin_ctzll(0) is also undefined at the builtin boundary). Replacing standard C++20 library facilities with GCC/Clang builtins to work around an outdated pre-C++20 libc++ in a custom SDK goes against our cross-platform portability direction, so I'm closing this PR.

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.

2 participants