-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[C++20] [Modules] False Positive ODR violation diagnostic due to using inconsistent qualified but the same type #78850
Comments
@llvm/issue-subscribers-clang-modules Author: None (ashley-hawkins)
Clang versions I tested with, from <https://apt.llvm.org/> (taken from `--version`):
- `Debian clang version 18.0.0 (++20240119100743+cd05ade13a66-1~exp1~20240119220916.1830)` cd05ade
- `Debian clang version 17.0.6 (5)`
Current clang version on compiler explorer: clang version 18.0.0git (https://github.com/llvm/llvm-project.git 4684507) I'm still not sure whether this is a problem with libstdc++ or a problem with clang so I apologise if this is the wrong place to report, but I get this error when including just <chrono> in one module partition and <memory> in another, here is an example on Compiler Explorer: https://godbolt.org/z/Wvv1h5aYa module;
#include <chrono>
export module repro;
export import :part; </details> module;
#include <memory>
export module repro:part; </details> In this example I am getting the error
</details> I looked at the preprocessed source and saw that the problem causing the function definitions to be considered different was one of them was getting I could reproduce the same situation without those included headers to demonstrate the problem: module;
typedef long T;
namespace ns {
using ::T;
}
namespace ns {
inline void fun() {
(void)(T)0;
}
}
export module repro;
export import :part; </details> module;
typedef long T;
namespace ns {
inline void fun() {
(void)(T)0;
}
}
export module repro:part; </details> cmake_minimum_required(VERSION 3.28)
project(repro)
set(CMAKE_CXX_STANDARD 20)
add_library(repro)
target_sources(repro PUBLIC FILE_SET CXX_MODULES FILES module.cc part.cc) </details> And here is the above on compiler explorer: https://godbolt.org/z/Ke6eoGnan and the compiler output from that compiler explorer example:
</details> |
Hmm, seems like the same as #76638, which claims to be fixed - but this repro shows the failure on godbolt at ToT... so, not sure. |
#76638 is a simple workaround for the enum type only. And this issue has the same fundamental reason with |
error: 'std::align' has different definitions in different modules
when just including standard headers in two module partitions
First thing would be to establish whether the example is conforming, I guess? If the alias had a different name it'd obviously be non-conforming/ODR violation, right? (because definitions must have the same sequence of tokens) The (however it's phrased in the spec) "lookups must find the same names" - if that applies to aliases (like you must find the same alias) - then the code is non-conforming, I think? If it applies to the underlying entity (making the alias transparent) then perhaps the code is conforming and we need to canonicalize earlier in some way. |
Yes.
It should be the later case according to the comment of https://reviews.llvm.org/D156210#4540980 |
The reproducer can be workaround by #79240. However, I suspect the same issue exist with the declarations in the module purview. But given there is almost no legacy code in module purview, it won't be so hurting any more. |
@ashley-hawkins I've landed #79240. Could you try to test your original workload? |
@ChuanqiXu9 I have tested with the development build, and the issue no longer occurs. Many thanks. |
Thanks for your high quality reporting too. It is important for us to keep forward. BTW, if you're making a toy and want to get a feeling about modules, it is suggested to use std modules from https://libcxx.llvm.org/Modules.html. Or if you still want to use libstdc++, it is suggested to mock a std module for that by yourself. |
@ashley-hawkins There is some chance the underlying failure will be fixed in #80245 Just based on the fact your own reduction zeroed in on a using declaration, and the above patch fixes an issue with modules which export using declarations that shadow other declarations. I think it's possible the non-reduced repro exposes a false-positive ODR violation, but the reduction went south somewhere and introduced a different problem. If you agree that's possible, would you mind giving it a try with the above patch? Now that the ODR checker is disabled by default in the driver, you can either pass |
I am also reopening because it has to be decided if the reduced repro is a real ODR violation or not.
|
I just got reply from Gaby from WG21, who is the one of original designer of modules. He confirmed this is not an ODR violation. Here is his reply:
|
@mizvekov I have tested the patch, and on libstdc++ 13.2.0 on my original workload, and the non-reduced reproducer with |
@ashley-hawkins Thanks for confirming! So we will fix the ODR checker then. |
bump. |
Is...solved? |
Clang versions I tested with, from https://apt.llvm.org/ (taken from
--version
):Debian clang version 18.0.0 (++20240119100743+cd05ade13a66-1~exp1~20240119220916.1830)
cd05adeDebian clang version 17.0.6 (5)
Current clang version on compiler explorer: clang version 18.0.0git (https://github.com/llvm/llvm-project.git 4684507)
I'm still not sure whether this is a problem with libstdc++ or a problem with clang so I apologise if this is the wrong place to report, but I get this error when including just
<chrono>
in one module partition and<memory>
in another, here is an example on Compiler Explorer: https://godbolt.org/z/Wvv1h5aYamodule.cc
part.cc
In this example I am getting the error
'std::align' has different definitions in different modules
full compiler output
I looked at the preprocessed source and saw that the problem causing the function definitions to be considered different was one of them was getting
uintptr_t
from the global namespace, the other was gettinguintptr_t
from ausing
in the std namespace.I could reproduce the same situation without those included headers to demonstrate the problem:
module.cc
part.cc
CMakeLists.txt
And here is the above on compiler explorer: https://godbolt.org/z/Ke6eoGnan and the compiler output from that compiler explorer example:
full compiler output
The text was updated successfully, but these errors were encountered: