-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] c++20 modules | using template function imported from other translation unit causes crash #59999
Comments
@llvm/issue-subscribers-c-20 |
@llvm/issue-subscribers-clang-modules |
One more example of this issue. |
for me crash it's caused by |
I can't reproduce this locally. I am not sure if this is Windows related or you use the incorrect command line. Would you like to provide the full command line reproducer? |
In your crash stack trace, it looks like you're compiling WorldObject.cppm instead of Consumer.cppm. |
@ChuanqiXu9 I attached files of my project in .zip archive. Yes, i misunderstood what causes this issue at first, it's reason is more, than just a templated function export, it turned out. In archieve i sent all files that should be compiled, i guess they should be enough. If they're not enough, contact me, i will make minimal reproducer based on my actual code and will send it to you with more details. Also i edited original comment, maybe it would be helpful. |
I downloaded the codes in the zip and it is a VS project. I can't run it. It would be best to have a minimal reproducer and the corresponding set of flags. |
Sorry for inconvenience! Here is my minimal reproducer. It's the most isolated i was able to actually make. Be aware, that LLVM linker driver i used in make file is window-only. Also, it crashes at 3rd line from the end in make file, and if it doesn't crash after you execute all commands, than it doesn't crash on your PC/Platform/Architecture. It crashes for me on Window 10 & 11, tested on 3 PCs. |
Sorry, it has too many files that I can't run it. Could you try to reproduce them further? A pretty good example could be found at #60036 |
Sorry, you see, i can't minimize it much further without it starting to compile successfully.
Sorry that i added a lot of useless files tho, i removed them. But i can't remove anything else, because then crash won't happen. I included file with all commands, that i use to compile. On my PC and few other PCs, these commands cause crash. |
@ChuanqiXu9 Hello, sorry for ping, how's this issue going? Do you need anything else maybe? Was you able to run reproducer? |
I didn't have progress on this. It'll still be helpful to reduce it further. BTW, I guess you can try to remove the |
@SasisaDev I think your example can be much simpler if squashed it into two files and remove extra stuff: export module Module;
export template <class ObjectType> bool ModuleRegister() { return true; };
export struct ModuleEntry {
static const bool bRegistered;
};
const bool ModuleEntry::bRegistered = ModuleRegister<ModuleEntry>(); export module Object;
import Module;
export template <class ObjectType> bool ObjectRegister() { return true; }
export struct NObject {
static const bool bRegistered;
};
export struct ObjectModuleEntry {
static const bool bRegistered;
};
// This function is also required for crash
const bool NObject::bRegistered = ObjectRegister<NObject>();
// One another function, that helps clang crash
const bool ObjectModuleEntry::bRegistered = ModuleRegister<ObjectModuleEntry>(); Does that still fail if you compile in your machine? Or does it only fail if split into multiple parts per module and/or including the "world" module? We might be able to reduce it further: does it need both I have a similar issue (same exception code and stack dump), but it is harder for me to reproduce it because it only fails running the build in a GitHub workflow (my code works fine in my PC). It would be helpful if we can tweak your example to reproduce with minimal effort for devs. Bonus points if it can eventually become a unit test in llvm, I guess. |
The reproducer works fine for me. |
Add a test from #59999. It is always good to have more tests.
Your minimal reproducer doesn't crash for me, yet that one example that i sent before still does crash. I have no idea how and why this happens, but i really tried tweaking it further and further, yet latest my reproducer is the minimal i could achieve, if i do anything else to it, it stops from crashing. I'm really sorry, if my reproducer is really hard to work with, but i was not able to reduce it further and still get crashes. |
Somehow I got a crash in my Windows machine in my own project and I decided to try yours again. I noticed I get a crash only once every ~10 times. After a lot of trial-and-error, I was able to import the project into this repo and shrink its size further. I stopped at this tag because it now fails in two different ways (at random, around 50~50 chance). One is the same crash. Other is this message:
This is at random. I run As @SasisaDev mentions, this bug is really hard to reproduce in a smaller setup. Removing code often "fixes" the issue. I was able to remove a bunch of custom types, leaving only the From what I noticed in my attempts and the error message I may get when building, I suspect there's something off about symbol exposure. Removing somewhat unrelated symbols, like the |
This is a extension for llvm#59999 tests in order to make them reproduce the issue reported. From local tests, I found out the definition in a "part unit" being instantiated in a deeper dependency tree is fundamental to the failure. So, in the case of this issue, splitting the code with its parts and the `World` module are important. Also, I noticed more symbols are also important to reproduce the issue.
@ChuanqiXu9 - I saw your test case, but it was using my first attempt with only two modules. I'm trying to change it to reflect what I was able to reproduce in my machine. Unfortunately, I'm not able to build LLVM in that Windows PC, but I was able to write a patch: https://reviews.llvm.org/D154801 - the I hope that helps. |
Now, THIS is something I hope can help. I was able to build clang with debug symbols. Running the Nonetheless, I noticed this time it fails when compiling
|
Also, in my personal endeavours, I found #61065 which has a root cause very similar to what I see in this one:
But, #61065 failure is related to ctors, while this one looks more like function instantiation. |
Original reproduction code:
Causes this:
This is archive with code dependencies, generated by Clang on crash:
WorldObject-669c29.zip
The text was updated successfully, but these errors were encountered: