Skip to content

Improve C++ layout test error messages#23190

Merged
thewilsonator merged 2 commits into
dlang:masterfrom
dkorpel:cpp-layout-test-msg
May 29, 2026
Merged

Improve C++ layout test error messages#23190
thewilsonator merged 2 commits into
dlang:masterfrom
dkorpel:cpp-layout-test-msg

Conversation

@dkorpel
Copy link
Copy Markdown
Contributor

@dkorpel dkorpel commented May 29, 2026

Instead of a default static assert message, give the values and locations
of the mismatches symbols.

cpp-layout-test failed:
/home/dennis/repos/dmd/generated/linux/release/64/cpp_layout_asserts.d(4782): Error: static assert:  "

Mangled name mismatch for `dmd.cxxfrontend.cppThunkMangleItanium`:
  D:   _ZN3dmd21cppThunkMangleItaniumEP15FuncDeclarationif at /home/dennis/repos/dmd/compiler/src/dmd/../dmd/cxxfrontend.d:68
  C++: _ZN3dmd21cppThunkMangleItaniumEP15FuncDeclarationi at mangle.h:25
Changes to dmd's extern(C++) types/functions must be reflected in compiler/include/*.h

Also important: pass -unittest in the build step so those checks are actually performed.

@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#23190"

Instead of a default static assert message, give the values and locations
of the mismatches symbols.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dkorpel dkorpel force-pushed the cpp-layout-test-msg branch from 4d7db1f to b989ce3 Compare May 29, 2026 10:53
@dkorpel
Copy link
Copy Markdown
Contributor Author

dkorpel commented May 29, 2026

Verified that the CI runs:

+ python3 -m pip install libclang
Defaulting to user installation because normal site-packages is not writeable
Collecting libclang
  Downloading libclang-18.1.1-py2.py3-none-manylinux2010_x86_64.whl (24.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 24.5/24.5 MB 56.2 MB/s eta 0:00:00
Installing collected packages: libclang
Successfully installed libclang-18.1.1
+ ./dmd/generated/build cpp-layout-test
(TEST) CPP-LAYOUT

The following operation failed:
Name: cpp-layout-test
Description: Check that compiler/include/dmd/*.h matches the D extern(C++) declarations
CommandFunction: Yes

-----------------------------------------------------------
cpp-layout-test failed:
/home/runner/work/dmd/dmd/dmd/generated/linux/release/64/cpp_layout_asserts.d(44): Error: static assert:  "

Offset mismatch for `Param.objfiles`:
  D field at offset 992 at /home/runner/work/dmd/dmd/dmd/compiler/src/dmd/../dmd/globals.d:261
  C++ field at offset 984 at globals.h:281
Changes to dmd's extern(C++) types/functions must be reflected in compiler/include/*.h
"
        static assert(actualOffset == expectedOffset,
        ^
/home/runner/work/dmd/dmd/dmd/generated/linux/release/64/cpp_layout_asserts.d(296):        instantiated from here: `checkField!(Param, "objfiles", 984, 32, "globals.h:281")`
    checkField!(Param, "objfiles", 984, 32, "globals.h:281");
    ^

DETAILS:


Error: Process completed with exit code 1.

@thewilsonator
Copy link
Copy Markdown
Contributor

Mangled name mismatch for `dmd.cxxfrontend.cppThunkMangleItanium`:
  D:   _ZN3dmd21cppThunkMangleItaniumEP15FuncDeclarationif at /home/dennis/repos/dmd/compiler/src/dmd/../dmd/cxxfrontend.d:68
  C++: _ZN3dmd21cppThunkMangleItaniumEP15FuncDeclarationi at mangle.h:25

can you demangle those symbols with druntime and c++filt (if available)? would make it a lot easier for those who don't spend a lot of time looking at mangled symbols.

@dkorpel
Copy link
Copy Markdown
Contributor Author

dkorpel commented May 29, 2026

The problem is that it's currently a compile time only test using static assert, and druntime's demangler only implements extern(D) demangling (it hooks to __cxa_demangle for C++). In theory, just visiting both source locations should give you the demangled signatures.

@thewilsonator
Copy link
Copy Markdown
Contributor

test using static assert

if that fails surely it will print on stderr, which you can pipe to c++filt? Anyway, it can be done later.

@thewilsonator thewilsonator merged commit ac4f8dc into dlang:master May 29, 2026
42 of 43 checks passed
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