Skip to content
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

Failure to compile std::u16string from libstdc++ 12.1 in c++20 mode #55560

Closed
patstew opened this issue May 18, 2022 · 17 comments
Closed

Failure to compile std::u16string from libstdc++ 12.1 in c++20 mode #55560

patstew opened this issue May 18, 2022 · 17 comments
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" libstdc++ GNU libstdc++ C++ standard library rejects-valid release:backport release:merged

Comments

@patstew
Copy link

patstew commented May 18, 2022

I'm getting:

error: undefined symbol: void std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >::_M_construct<char16_t const*>(char16_t const*, char16_t const*, std::forward_iterator_tag)

compiling the following simple test case:

#include <string>
#include <string_view>

// static std::u16string clang_string_workaround(const char16_t* a, const char16_t* b) { return {a, b}; }

std::u16string_view sv{u"test"};

std::u16string print() { return std::u16string(sv); }

int main(int, char**) { std::u16string s = print(); }

on clang 13 and 14.0.0, with clang++ -std=c++20 -o test test.cpp. It works fine with -std=c++17. Bizarrely, it also works if you simply uncomment the clang_string_workaround line which isn't even called. It looks like libstdc++ moved that _M_construct function into a separate file recently, which might be related.

@jwakely
Copy link
Contributor

jwakely commented May 19, 2022

It looks like libstdc++ moved that _M_construct function into a separate file recently

No we didn't. The relevant change is probably jwakely/gcc@5a9572e but I don't know why that would make clang not instantiate the function it calls.

@jwakely
Copy link
Contributor

jwakely commented May 19, 2022

Very odd. If I remove this function from the <string> code then clang links in C++20 mode:

    __attribute ((__abi_tag__ ("cxx11")))
    inline basic_string<char16_t>
    operator""s(const char16_t* __str, size_t __len)
    { return basic_string<char16_t>{__str, __len}; }

@jwakely
Copy link
Contributor

jwakely commented May 19, 2022

And if I remove the constexpr specifier from the declaration and definition of the undefined function, it links:

      template<typename _FwdIterator>
        constexpr
        void
        _M_construct(_FwdIterator __beg, _FwdIterator __end,
       std::forward_iterator_tag);

@tstellar tstellar added this to the LLVM 14.0.5 Release milestone May 26, 2022
@tstellar tstellar moved this to Needs Triage in LLVM Release Status May 26, 2022
@tbaederr tbaederr added c++20 rejects-valid libstdc++ GNU libstdc++ C++ standard library and removed new issue labels May 27, 2022
@llvmbot
Copy link
Member

llvmbot commented May 27, 2022

@llvm/issue-subscribers-c-20

@tbaederr
Copy link
Contributor

I think this is a small reproducer of the problem:

#define INLINE constexpr

template<typename T>
INLINE
T foo(T a);

int main() {
  int k = foo<int>(5);
}

template<typename T>
INLINE
T foo(T a) {
  return a;
}

Godbolt: https://godbolt.org/z/xoYvvbPKv

The example can be fixed by defining INLINE to nothing (which Jonathan already pointed out), defining it to inline or by just moving the definition of foo() before the point of use: https://godbolt.org/z/qfe38bsnE

@tbaederr
Copy link
Contributor

tbaederr commented Jun 2, 2022

The problematic code in clang is:

else if (Func->isConstexpr())
// Do not defer instantiations of constexpr functions, to avoid the
// expression evaluator needing to call back into Sema if it sees a
// call to such a function.
InstantiateFunctionDefinition(PointOfInstantiation, Func);

Replacing that else if with else if (false) makes the reproducer from above work (but breaks a ton of test cases of course). As far as I understand, delayed constexpr instantiation is simply not implemented in clang. I wonder what a good way to address this would be. @zygoloid, do you maybe have some pointers on the matter?

@tbaederr
Copy link
Contributor

tbaederr commented Jun 2, 2022

#55315, #37522 and #16992 are probably the same problem, or at least closely related.

@tstellar tstellar moved this from Needs Triage to Needs Fix in LLVM Release Status Jun 3, 2022
@serge-sans-paille
Copy link
Collaborator

https://reviews.llvm.org/D128119 seems to fix the issue

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jul 10, 2022
@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2022

@llvm/issue-subscribers-clang-frontend

@tru
Copy link
Collaborator

tru commented Aug 3, 2022

Should this be backported to the release branch?

@tbaederr
Copy link
Contributor

tbaederr commented Aug 3, 2022

@tstellar any opinion? Serge isn't available right now as far as I know.

@tstellar tstellar moved this from Needs Fix to Needs Pull Request in LLVM Release Status Aug 3, 2022
@tstellar
Copy link
Collaborator

tstellar commented Aug 3, 2022

/cherry-pick da6a14b

@llvmbot
Copy link
Member

llvmbot commented Aug 3, 2022

Failed to cherry-pick: da6a14b

https://github.com/llvm/llvm-project/actions/runs/2790868798

Please manually backport the fix and push it to your github fork. Once this is done, please add a comment like this:

/branch <user>/<repo>/<branch>

@tstellar
Copy link
Collaborator

tstellar commented Aug 8, 2022

This patch is already in the branch.

@tru tru moved this from Needs Pull Request to Done in LLVM Release Status Aug 9, 2022
paulhuggett added a commit to paulhuggett/peejay that referenced this issue Nov 15, 2022
@kwizart
Copy link

kwizart commented Dec 1, 2022

Cherry-pick seems to fail in 14.x locally because of the ReleaseNotes.rst

Is there a mean to backport in 14.x ? ( we need this in fedora 36 in order to build chromium 108).
Thanks in advance.

@tbaederr
Copy link
Contributor

tbaederr commented Dec 1, 2022

There won't be any 14.x releases anymore, so you'll have to do the backport downstream

@leigh123linux
Copy link

chromium 108 error on fedora-36

[54374/54383] rm -f obj/chrome/browser/libbrowser.a && "llvm-ar" -T -r -c -s -D obj/chrome/browser/libbrowser.a @"obj/chrome/browser/libbrowser.a.rsp"
[54375/54383] /usr/bin/python3 "../../build/toolchain/gcc_link_wrapper.py" --output="./v8_context_snapshot_generator" -- clang++ -fuse-ld=lld -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--color-diagnostics -Wl,-mllvm,-instcombine-lower-dbg-declare=0 -flto=thin -Wl,--thinlto-jobs=all -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy=cache_size=10\%:cache_size_bytes=40g:cache_size_files=100000 -Wl,-mllvm,-import-instr-limit=30 -fwhole-program-vtables -Wl,--no-call-graph-profile-sort -m64 -Wl,-O2 -Wl,--gc-sections -rdynamic -Wl,-z,defs -Wl,--as-needed -Wl,--lto-O0 -pie -Wl,--disable-new-dtags -Wl,--icf=none -L/usr/lib64 -o "./v8_context_snapshot_generator" -Wl,--start-group @"./v8_context_snapshot_generator.rsp"  -Wl,--end-group  -latomic -ldl -lpthread -lrt -lgmodule-2.0 -lglib-2.0 -lgobject-2.0 -lgthread-2.0 -lsmime3 -lnss3 -lnssutil3 -lplds4 -lplc4 -lnspr4 -lresolv -lgio-2.0 -lexpat -luuid -lm -lz -lX11 -lXcomposite -lXdamage -lXext -lXfixes -lXrender -lXrandr -lXtst -lpipewire-0.3 -lgbm -lEGL -ldrm -lxcb -lxkbcommon -lXi -lpci -lffi -ldbus-1 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lcairo -latk-1.0 -latk-bridge-2.0 -lasound -lpulse -latspi
FAILED: v8_context_snapshot_generator 
/usr/bin/python3 "../../build/toolchain/gcc_link_wrapper.py" --output="./v8_context_snapshot_generator" -- clang++ -fuse-ld=lld -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--color-diagnostics -Wl,-mllvm,-instcombine-lower-dbg-declare=0 -flto=thin -Wl,--thinlto-jobs=all -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy=cache_size=10\%:cache_size_bytes=40g:cache_size_files=100000 -Wl,-mllvm,-import-instr-limit=30 -fwhole-program-vtables -Wl,--no-call-graph-profile-sort -m64 -Wl,-O2 -Wl,--gc-sections -rdynamic -Wl,-z,defs -Wl,--as-needed -Wl,--lto-O0 -pie -Wl,--disable-new-dtags -Wl,--icf=none -L/usr/lib64 -o "./v8_context_snapshot_generator" -Wl,--start-group @"./v8_context_snapshot_generator.rsp"  -Wl,--end-group  -latomic -ldl -lpthread -lrt -lgmodule-2.0 -lglib-2.0 -lgobject-2.0 -lgthread-2.0 -lsmime3 -lnss3 -lnssutil3 -lplds4 -lplc4 -lnspr4 -lresolv -lgio-2.0 -lexpat -luuid -lm -lz -lX11 -lXcomposite -lXdamage -lXext -lXfixes -lXrender -lXrandr -lXtst -lpipewire-0.3 -lgbm -lEGL -ldrm -lxcb -lxkbcommon -lXi -lpci -lffi -ldbus-1 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lcairo -latk-1.0 -latk-bridge-2.0 -lasound -lpulse -latspi
ld.lld: error: undefined symbol: void std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >::_M_construct<char16_t const*>(char16_t const*, char16_t const*, std::forward_iterator_tag)
>>> referenced by skeleton_generator.cc
>>>               thinlto-cache/llvmcache-74F39D4271E61E212B9DE8AF2A31A2A8E125F721:(SkeletonGenerator::MaybeRemoveDiacritics[abi:cxx11](base::BasicStringPiece<char16_t, std::char_traits<char16_t> >))
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
RPM build errors:

kwizart pushed a commit to kwizart/llvm-project that referenced this issue Dec 1, 2022
…non-constexpr evaluation

Otherwise these functions are not instantiated and we end up with an undefined
symbol.

Fix llvm#55560

Differential Revision: https://reviews.llvm.org/D128119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" libstdc++ GNU libstdc++ C++ standard library rejects-valid release:backport release:merged
Projects
Archived in project
Development

No branches or pull requests

10 participants