Skip to content

Add libclang based C++ header validation#23187

Merged
thewilsonator merged 3 commits into
dlang:masterfrom
dkorpel:cpp-header-fix
May 29, 2026
Merged

Add libclang based C++ header validation#23187
thewilsonator merged 3 commits into
dlang:masterfrom
dkorpel:cpp-header-fix

Conversation

@dkorpel
Copy link
Copy Markdown
Contributor

@dkorpel dkorpel commented May 28, 2026

Fix regressions from #23176, as well as many other mismatches found by a WIP new CI check that I hope to push soon(tm)

Update: adds a new CI check that verifies that the manually maintained C++ headers in
include/dmd/ stay in sync with the D extern(C++) declarations in the compiler source.
Checks enum constant values, field offsets and sizes, class instance sizes, vtable indices, and C++ mangled names.

A python script uses clang to walk over all .h files in the include directory, and generate D asserts for enums, fields, and functions with C++ mangling. It currently generates:

https://gist.github.com/dkorpel/f8de8ca519e8dcfc2adcd691af6203e1

Then it runs it with the D compiler and -version=IN_LLVM (to skip fields in version (MARS) blocks). Added to the C++ test targets in build.d so you can run it with: ./build.d cpp-layout-test

@dkorpel dkorpel requested a review from ibuclaw as a code owner May 28, 2026 12:46
@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#23187"

Copy link
Copy Markdown
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add to the tests to ensure that these specific changed do not regress in future?

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dkorpel dkorpel changed the title Fix C++ header mismatches Add libclang based C++ header validation May 28, 2026
@dkorpel
Copy link
Copy Markdown
Contributor Author

dkorpel commented May 28, 2026

I kinda meant to push this to another branch, but here we are. I pushed the new test target and updated the description.

@thewilsonator
Copy link
Copy Markdown
Contributor

This is far more comprehensive than I meant to suggest. Nice!

@dkorpel
Copy link
Copy Markdown
Contributor Author

dkorpel commented May 28, 2026

I know, this is a response to Iain's rightful complaining about the frequently broken headers (#23176 (comment)). I tried fixing frontend.h for a bit to compile, but it's a real hassle, so I figured maybe it's simpler to generate D tests from C code rather than C tests (or headers) from D code.

@thewilsonator thewilsonator merged commit 3b7cc35 into dlang:master May 29, 2026
42 of 43 checks passed
@dkorpel dkorpel deleted the cpp-header-fix branch May 29, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants