Skip to content

"Definition with same mangled name as another definition" error when compiling C++20 Modules #118137

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

Open
MikailBag opened this issue Nov 29, 2024 · 5 comments
Labels
clang:modules C++20 modules and Clang Header Modules

Comments

@MikailBag
Copy link

MikailBag commented Nov 29, 2024

My code: https://gist.github.com/MikailBag/5803041040c052deda1d06893eae67e1
(Please note that is requires stdexec, which is AFAIK reference implementation of the C++26 std::execution)

When running build.sh, I get following error:

/tmp/build/vcpkg_installed/x64-linux-clang/include/exec/../stdexec/__detail/__transform_sender.hpp:103:9: error: definition with same mangled name '_ZNK7stdexec8__domain18__transform_senderclIS1_NS_14default_domainENS_7__sexprIXtlNS_12_GLOBAL__N_1UlvE8_EEENS5_6__anonEEEJNS_5__env9empty_envEEEEDcT0_OT1_DpRKT2_' as another definition
  103 |         operator()(_Domain __dom, _Sender&& __sndr, const _Env&... __env) const
      |         ^
/tmp/build/vcpkg_installed/x64-linux-clang/include/exec/../stdexec/__detail/__transform_sender.hpp:103:9: note: previous definition is here

I'm not an experienced modules user, so I can easily be wrong, but I don't see anything wrong in terms of linkage/ODR/etc. And based on #53232 it seems, that this error is in fact internal to compiler.

Here is compiler version (it was installed from the LLVM APT repository):

$ clang++-19 --version
Ubuntu clang version 19.1.5 (++20241125105251+086d8e6bb5da-1~exp1~20241125105305.67)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules and removed new issue labels Nov 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 30, 2024

@llvm/issue-subscribers-clang-modules

Author: Mikail Bagishov (MikailBag)

My code: https://gist.github.com/MikailBag/5803041040c052deda1d06893eae67e1 (Please note that is requires stdexec, which is AFAIK reference implementation of the C++26 `std::execution`)

When running build.sh, I get following error:

/tmp/build/vcpkg_installed/x64-linux-clang/include/exec/../stdexec/__detail/__transform_sender.hpp:103:9: error: definition with same mangled name '_ZNK7stdexec8__domain18__transform_senderclIS1_NS_14default_domainENS_7__sexprIXtlNS_12_GLOBAL__N_1UlvE8_EEENS5_6__anonEEEJNS_5__env9empty_envEEEEDcT0_OT1_DpRKT2_' as another definition
  103 |         operator()(_Domain __dom, _Sender&& __sndr, const _Env&... __env) const
      |         ^
/tmp/build/vcpkg_installed/x64-linux-clang/include/exec/../stdexec/__detail/__transform_sender.hpp:103:9: note: previous definition is here

I'm not an experienced modules user, so I can easily be wrong, but I don't see anything wrong in terms of linkage/ODR/etc. And based on #53232 it seems, that this error is in fact internal to compiler.

Here is compiler version (it was installed from the LLVM APT repository):

$ clang++-19 --version
Ubuntu clang version 19.1.5 (++20241125105251+086d8e6bb5da-1~exp1~20241125105305.67)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin

@MikailBag
Copy link
Author

MikailBag commented Jan 7, 2025

Well, I've tried to investigate this problem a bit more, and situation got more interesting.

I've compiled clang from sources, here is version info (some fresh commit + release build + assertions):

clang version 20.0.0git (https://github.com/llvm/llvm-project.git 17c8c1c5098bd1fa68809d686867d01d56d5e564)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/mb/projects/llvm-project/build/bin
Build config: +assertions

According to git status & git diff, this is a clean build.

With that, I get following results:

  1. My original project fails to compile with the same error as before (modulo additional output I added)
  2. Reproducer I've attached above now fails with assertion error
clang-20: /home/mb/projects/llvm-project/clang/lib/AST/DeclCXX.cpp:1650: NamedDecl *getLambdaCallOperatorHelper(const CXXRecordDecl &): Assertion `allLookupResultsAreTheSame(Calls) && "More than one lambda call operator!"' failed.

Full error message https://gist.github.com/MikailBag/d2f109fc923a72e15c3568aa6faed917

I can attach generated reproducer script and preprocessed source, but they depent upon BMIs, so it feels useless.

To be clear: I have no idea whether or how this assertion failure relates to the ODR/mangling issue above.

@ChuanqiXu9
Copy link
Member

I suspect this is duplicated with #119947

Can you try to verify?

@MikailBag
Copy link
Author

I suspect this is duplicated

Error messages are similar, anonymous namespaced are involved too, so this may easily be the case.

Can you try to verify?

Could you, please, clarify how can I do it?
I tried to use cvise (with a predicate like "compiler output contains 'error: definition with same mangled name'"), but it reduced input to a file which actually contains ODR violation :(

If you want to postpone this issue until 119947 is resolved, then I think I have no objections (since there is no evidence that these two issues are different). With that said, I have two somewhat related questions:

  1. Depending on compiler version (and assertions being enabled or disabled) I've met two different confusing behaviors: mangling-related diagnostic (with clang-19) and assertion error (with clang built from fresh Git main). I don't know whether these problems are connected. Should I move "Definition with same mangled name as another definition" error when compiling C++20 Modules #118137 (comment) to another issue?
  2. As far as I understood relevant code, this diagnostic means something like "There are two definitions for item D and they are not equivalent". Error message currently contains mangled name (and hence item in question), but it does not tell how definitions are different. I think that this information would be useful to add. Is this a valid feature request?

@ChuanqiXu9
Copy link
Member

I suspect this is duplicated

Error messages are similar, anonymous namespaced are involved too, so this may easily be the case.

Can you try to verify?

Could you, please, clarify how can I do it? I tried to use cvise (with a predicate like "compiler output contains 'error: definition with same mangled name'"), but it reduced input to a file which actually contains ODR violation :(

If you want to postpone this issue until 119947 is resolved, then I think I have no objections (since there is no evidence that these two issues are different). With that said, I have two somewhat related questions:

  1. Depending on compiler version (and assertions being enabled or disabled) I've met two different confusing behaviors: mangling-related diagnostic (with clang-19) and assertion error (with clang built from fresh Git main). I don't know whether these problems are connected. Should I move "Definition with same mangled name as another definition" error when compiling C++20 Modules #118137 (comment) to another issue?
  2. As far as I understood relevant code, this diagnostic means something like "There are two definitions for item D and they are not equivalent". Error message currently contains mangled name (and hence item in question), but it does not tell how definitions are different. I think that this information would be useful to add. Is this a valid feature request?

If we can't reduce it, maybe we don't have good method to judge if it is the same issue precisely. So I prefer to postpone this until #119947 is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules
Projects
None yet
Development

No branches or pull requests

4 participants