Skip to content

Fix #23332 and add test case.#23334

Merged
thewilsonator merged 2 commits into
dlang:masterfrom
LightBender:fix23332
Jun 29, 2026
Merged

Fix #23332 and add test case.#23334
thewilsonator merged 2 commits into
dlang:masterfrom
LightBender:fix23332

Conversation

@LightBender

Copy link
Copy Markdown
Contributor

Fixed with LLM.

LLM Model : Opus 4.8
Prompt:

Instead of reverting the change to tocsym.d, can you fix it to not cause the access violation? Then create a test case using issue number 23332 (#23332).

@thewilsonator thewilsonator added the AI Generated Code that is generated by an LLM AI. label Jun 29, 2026
@LightBender LightBender added the Compiler:Backend glue code, optimizer, code generation label Jun 29, 2026
@thewilsonator thewilsonator merged commit 99c96ea into dlang:master Jun 29, 2026
39 of 41 checks passed
@LightBender

Copy link
Copy Markdown
Contributor Author

@WalterBright This failure occurred on Windows 11 (latest build). The LLM was able to find it and fix it.

This is what Opus had to say:
The crash was the %zd in buf.printf("%zd%s%s", ...) — the host C runtime mishandles %zd, so snprintf returns −1 and the OutBuffer length corrupted, overflowing symbol_calloc. Kept the simplification, switched to %d with cast(int).

It looks like this possibly a Windows CRT failure?

@LightBender LightBender deleted the fix23332 branch June 29, 2026 04:45
@rainers

rainers commented Jun 29, 2026

Copy link
Copy Markdown
Member

"%zd" is used throughout the compiler, so patching it in one place won't get you very far. What runtime are you linking the compiler against? The MS runtime supports %z since VS 2015 IIRC.

@LightBender

LightBender commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@rainers I was using build.d, and I have VS2022/2026 installed on my machine, but for some reason it picked MSVCR120.dll which is the 2013 runtime. I happy to revert this change. But we have a bigger problem with how we're doing CRT library selection. Everybody using anything modern will hit this problem.

@LightBender

Copy link
Copy Markdown
Contributor Author

@rainers On further investigation, it looks like we ship msvcr120.dll in the bin64 folder of the windows installation, and it appears that this is what is used when it cannot find an appropriate newer CRT. Unfortunately, if we're going to stick with MSVCR120.dll, then we cannot use %z formatters in printf since we will be breaking builds. It is well known that %z specifiers are not supported in MSVCR120.dll.

@@ -0,0 +1,5 @@
// https://github.com/dlang/dmd/issues/23332
// Segfault generating a struct's static initializer symbol when it has a float member.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a misleading test case. Surely structs with float members are already covered by the test suite. And if it's about float members, why is there an unused f() function? From the discussion, it looks like this has nothing to do with the test case and everything to do with the Windows CRT version of the host compiler, which such a snippet doesn't control at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I know. That was discovered after merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Code that is generated by an LLM AI. Compiler:Backend glue code, optimizer, code generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants