Skip to content

[Clang] Implement CWG2369 "Ordering between constraints and substitution" #102857

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

Merged
merged 36 commits into from
Jan 5, 2025

Conversation

zyn0217
Copy link
Contributor

@zyn0217 zyn0217 commented Aug 12, 2024

This patch partially implements CWG 2369 for non-lambda-constrained functions.

Lambdas are left intact at this point because we need extra work to correctly instantiate captures before the function instantiation.

As a premise of CWG2369, this patch also implements CWG2770 to ensure the function parameters are instantiated on demand.

Closes #54440

@zyn0217 zyn0217 requested a review from cor3ntin August 12, 2024 07:35
Copy link

github-actions bot commented Aug 18, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

mordante added a commit to mordante/llvm-project that referenced this pull request Aug 18, 2024
The function

    template<class Duration>
      requires three_way_comparable_with<sys_seconds, sys_time<Duration>>
      constexpr auto operator<=>(const leap_second& x, const sys_time<Duration>& y) noexcept;

Has a recursive constrained. This caused an infinite loop in GCC and is
now hit by llvm#102857.

A fix would be to make this function a hidden friend, this solution is
propsed in LWG4139.

For consistency all comparisons are made hidden friends.
Since the issue causes compilation failures no additional test are
needed.

Fixes: llvm#104700
mordante and others added 2 commits August 19, 2024 09:51
The function

    template<class Duration>
      requires three_way_comparable_with<sys_seconds, sys_time<Duration>>
      constexpr auto operator<=>(const leap_second& x, const sys_time<Duration>& y) noexcept;

Has a recursive constrained. This caused an infinite loop in GCC and is
now hit by llvm#102857.

A fix would be to make this function a hidden friend, this solution is
propsed in LWG4139.

For consistency all comparisons are made hidden friends.
Since the issue causes compilation failures no additional test are
needed.
@zyn0217
Copy link
Contributor Author

zyn0217 commented Aug 19, 2024

@mordante
I saw some tests are "unexpectedly passed" on ARM platforms: https://buildkite.com/llvm-project/libcxx-ci/builds/37165#0191685f-c770-41d1-a8a4-8819da1b1802
Is that something undesired / why did we mark them XFAIL previously?

mordante added a commit that referenced this pull request Aug 20, 2024
The function

    template<class Duration>
requires three_way_comparable_with<sys_seconds, sys_time<Duration>>
constexpr auto operator<=>(const leap_second& x, const
sys_time<Duration>& y) noexcept;

Has a recursive constrained. This caused an infinite loop in GCC and is
now hit by #102857.

A fix would be to make this function a hidden friend, this solution is
propsed in LWG4139.

For consistency all comparisons are made hidden friends. Since the issue
causes compilation failures no additional test are needed.

Fixes: #104700
@zyn0217 zyn0217 marked this pull request as ready for review August 28, 2024 10:40
@zyn0217 zyn0217 requested a review from Endilll as a code owner August 28, 2024 10:40
@zyn0217 zyn0217 requested a review from mizvekov August 28, 2024 10:40
@zyn0217 zyn0217 deleted the cwg-2369 branch January 5, 2025 02:51
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 5, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux-fast running on sanitizer-buildbot4 while building clang at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/169/builds/7054

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 88095 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 
FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/MachO_weak_references.s (50787 of 88095)
******************** TEST 'LLVM :: ExecutionEngine/JITLink/x86-64/MachO_weak_references.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: rm -rf /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp && mkdir -p /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
+ rm -rf /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
+ mkdir -p /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
RUN: at line 2: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
RUN: at line 3: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 -check=/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 -check=/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
RUN: at line 4: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-absent -check=/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-absent -check=/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o

=================================================================
==765590==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x5aad1003710f in malloc /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0x73591309cf8b  (/lib/x86_64-linux-gnu/libc.so.6+0x9cf8b) (BuildId: 5f3f024b472f38389da3a2f567b3d0eaa8835ca2)
    #2 0x73591309d613 in dlsym (/lib/x86_64-linux-gnu/libc.so.6+0x9d613) (BuildId: 5f3f024b472f38389da3a2f567b3d0eaa8835ca2)
    #3 0x5aad111a0bf6 in llvm::orc::SelfExecutorProcessControl::lookupSymbolsAsync(llvm::ArrayRef<llvm::orc::DylibManager::LookupRequest>, llvm::unique_function<void (llvm::Expected<std::__1::vector<std::__1::vector<llvm::orc::ExecutorSymbolDef, std::__1::allocator<llvm::orc::ExecutorSymbolDef>>, std::__1::allocator<std::__1::vector<llvm::orc::ExecutorSymbolDef, std::__1::allocator<llvm::orc::ExecutorSymbolDef>>>>>)>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp:101:26
    #4 0x5aad10fd05c9 in llvm::orc::EPCDynamicLibrarySearchGenerator::tryToGenerate(llvm::orc::LookupState&, llvm::orc::LookupKind, llvm::orc::JITDylib&, llvm::orc::JITDylibLookupFlags, llvm::orc::SymbolLookupSet const&) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.cpp:56:21
    #5 0x5aad10ed15ef in llvm::orc::ExecutionSession::OL_applyQueryPhase1(std::__1::unique_ptr<llvm::orc::InProgressLookupState, std::__1::default_delete<llvm::orc::InProgressLookupState>>, llvm::Error) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp:2473:19
    #6 0x5aad10ec23fc in llvm::orc::ExecutionSession::lookup(llvm::orc::LookupKind, std::__1::vector<std::__1::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>, std::__1::allocator<std::__1::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>>> const&, llvm::orc::SymbolLookupSet, llvm::orc::SymbolState, llvm::unique_function<void (llvm::Expected<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef>>>)>, std::__1::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>>> const&)>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp:1814:3
    #7 0x5aad11091eb2 in llvm::orc::LinkGraphLinkingLayer::JITLinkCtx::lookup(llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::jitlink::SymbolLookupFlags, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, llvm::jitlink::SymbolLookupFlags>> const&, std::__1::unique_ptr<llvm::jitlink::JITLinkAsyncLookupContinuation, std::__1::default_delete<llvm::jitlink::JITLinkAsyncLookupContinuation>>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/LinkGraphLinkingLayer.cpp:117:8
    #8 0x5aad107a8c87 in llvm::jitlink::JITLinkerBase::linkPhase2(std::__1::unique_ptr<llvm::jitlink::JITLinkerBase, std::__1::default_delete<llvm::jitlink::JITLinkerBase>>, llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp:122:8
    #9 0x5aad107af535 in operator() /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp:63:18
    #10 0x5aad107af535 in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>>::CallImpl<llvm::jitlink::JITLinkerBase::linkPhase1(std::__1::unique_ptr<llvm::jitlink::JITLinkerBase, std::__1::default_delete<llvm::jitlink::JITLinkerBase>>)::$_1>(void*, llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>&) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222:12
    #11 0x5aad110fab31 in operator() /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387:12
    #12 0x5aad110fab31 in llvm::orc::MapperJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>)>)::$_0::operator()(llvm::Expected<llvm::orc::ExecutorAddrRange>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp:120:5
    #13 0x5aad1110be58 in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<llvm::orc::ExecutorAddrRange>>::CallImpl<llvm::orc::MapperJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>)>)::$_0>(void*, llvm::Expected<llvm::orc::ExecutorAddrRange>&) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222:12
    #14 0x5aad100b749b in operator() /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387:12
    #15 0x5aad100b749b in llvm::InProcessDeltaMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>)::'lambda'(llvm::Expected<llvm::orc::ExecutorAddrRange>)::operator()(llvm::Expected<llvm::orc::ExecutorAddrRange>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/llvm-jitlink/llvm-jitlink.cpp:566:11
    #16 0x5aad100b6d68 in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<llvm::orc::ExecutorAddrRange>>::CallImpl<llvm::InProcessDeltaMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>)::'lambda'(llvm::Expected<llvm::orc::ExecutorAddrRange>)>(void*, llvm::Expected<llvm::orc::ExecutorAddrRange>&) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222:12
    #17 0x5aad1110da2f in operator() /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387:12
    #18 0x5aad1110da2f in llvm::orc::InProcessMemoryMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:57:3
Step 10 (stage2/asan_ubsan check) failure: stage2/asan_ubsan check (failure)
...
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 88095 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 
FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/MachO_weak_references.s (50787 of 88095)
******************** TEST 'LLVM :: ExecutionEngine/JITLink/x86-64/MachO_weak_references.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: rm -rf /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp && mkdir -p /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
+ rm -rf /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
+ mkdir -p /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
RUN: at line 2: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
RUN: at line 3: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 -check=/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 -check=/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
RUN: at line 4: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-absent -check=/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec -check-name=jitlink-check-bar-absent -check=/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o

=================================================================
==765590==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x5aad1003710f in malloc /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0x73591309cf8b  (/lib/x86_64-linux-gnu/libc.so.6+0x9cf8b) (BuildId: 5f3f024b472f38389da3a2f567b3d0eaa8835ca2)
    #2 0x73591309d613 in dlsym (/lib/x86_64-linux-gnu/libc.so.6+0x9d613) (BuildId: 5f3f024b472f38389da3a2f567b3d0eaa8835ca2)
    #3 0x5aad111a0bf6 in llvm::orc::SelfExecutorProcessControl::lookupSymbolsAsync(llvm::ArrayRef<llvm::orc::DylibManager::LookupRequest>, llvm::unique_function<void (llvm::Expected<std::__1::vector<std::__1::vector<llvm::orc::ExecutorSymbolDef, std::__1::allocator<llvm::orc::ExecutorSymbolDef>>, std::__1::allocator<std::__1::vector<llvm::orc::ExecutorSymbolDef, std::__1::allocator<llvm::orc::ExecutorSymbolDef>>>>>)>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp:101:26
    #4 0x5aad10fd05c9 in llvm::orc::EPCDynamicLibrarySearchGenerator::tryToGenerate(llvm::orc::LookupState&, llvm::orc::LookupKind, llvm::orc::JITDylib&, llvm::orc::JITDylibLookupFlags, llvm::orc::SymbolLookupSet const&) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.cpp:56:21
    #5 0x5aad10ed15ef in llvm::orc::ExecutionSession::OL_applyQueryPhase1(std::__1::unique_ptr<llvm::orc::InProgressLookupState, std::__1::default_delete<llvm::orc::InProgressLookupState>>, llvm::Error) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp:2473:19
    #6 0x5aad10ec23fc in llvm::orc::ExecutionSession::lookup(llvm::orc::LookupKind, std::__1::vector<std::__1::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>, std::__1::allocator<std::__1::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>>> const&, llvm::orc::SymbolLookupSet, llvm::orc::SymbolState, llvm::unique_function<void (llvm::Expected<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef>>>)>, std::__1::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>>> const&)>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/Core.cpp:1814:3
    #7 0x5aad11091eb2 in llvm::orc::LinkGraphLinkingLayer::JITLinkCtx::lookup(llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::jitlink::SymbolLookupFlags, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, llvm::jitlink::SymbolLookupFlags>> const&, std::__1::unique_ptr<llvm::jitlink::JITLinkAsyncLookupContinuation, std::__1::default_delete<llvm::jitlink::JITLinkAsyncLookupContinuation>>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/LinkGraphLinkingLayer.cpp:117:8
    #8 0x5aad107a8c87 in llvm::jitlink::JITLinkerBase::linkPhase2(std::__1::unique_ptr<llvm::jitlink::JITLinkerBase, std::__1::default_delete<llvm::jitlink::JITLinkerBase>>, llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp:122:8
    #9 0x5aad107af535 in operator() /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp:63:18
    #10 0x5aad107af535 in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>>::CallImpl<llvm::jitlink::JITLinkerBase::linkPhase1(std::__1::unique_ptr<llvm::jitlink::JITLinkerBase, std::__1::default_delete<llvm::jitlink::JITLinkerBase>>)::$_1>(void*, llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>&) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222:12
    #11 0x5aad110fab31 in operator() /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387:12
    #12 0x5aad110fab31 in llvm::orc::MapperJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>)>)::$_0::operator()(llvm::Expected<llvm::orc::ExecutorAddrRange>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/MapperJITLinkMemoryManager.cpp:120:5
    #13 0x5aad1110be58 in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<llvm::orc::ExecutorAddrRange>>::CallImpl<llvm::orc::MapperJITLinkMemoryManager::allocate(llvm::jitlink::JITLinkDylib const*, llvm::jitlink::LinkGraph&, llvm::unique_function<void (llvm::Expected<std::__1::unique_ptr<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc, std::__1::default_delete<llvm::jitlink::JITLinkMemoryManager::InFlightAlloc>>>)>)::$_0>(void*, llvm::Expected<llvm::orc::ExecutorAddrRange>&) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222:12
    #14 0x5aad100b749b in operator() /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387:12
    #15 0x5aad100b749b in llvm::InProcessDeltaMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>)::'lambda'(llvm::Expected<llvm::orc::ExecutorAddrRange>)::operator()(llvm::Expected<llvm::orc::ExecutorAddrRange>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/llvm-jitlink/llvm-jitlink.cpp:566:11
    #16 0x5aad100b6d68 in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<llvm::orc::ExecutorAddrRange>>::CallImpl<llvm::InProcessDeltaMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>)::'lambda'(llvm::Expected<llvm::orc::ExecutorAddrRange>)>(void*, llvm::Expected<llvm::orc::ExecutorAddrRange>&) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222:12
    #17 0x5aad1110da2f in operator() /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387:12
    #18 0x5aad1110da2f in llvm::orc::InProcessMemoryMapper::reserve(unsigned long, llvm::unique_function<void (llvm::Expected<llvm::orc::ExecutorAddrRange>)>) /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp:57:3

@mysterymath
Copy link
Contributor

We've started seeing libc++ test failures in the Fuchsia toolchain buildbots for Windows: https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-windows-x64/b8726615170786362641/overview

This may be related to the discussion in #121881, but the error looks slightly different.

This is definitely the only plausible PR in the blamelist: https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-windows-x64/b8726615170786362641/blamelist

llvm-libc++-static-clangcl.cfg.in :: std/utilities/optional/optional.relops/less_than.pass.cpp
==============
# | In file included from C:\b\s\w\ir\x\w\llvm-llvm-project\libcxx\test\std\utilities\optional\optional.relops\less_than.pass.cpp:14:
# | C:/b/s/w/ir/x/w/llvm_build/runtimes/runtimes-x86_64-pc-windows-msvc-bins/libcxx/test-suite-install/include/c++/v1\optional:1247:1: error: cannot mangle this dependent name type yet
# |  1247 | _LIBCPP_HIDE_FROM_ABI constexpr compare_three_way_result_t<_Tp, _Up>
# |       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |  1248 | operator<=>(const optional<_Tp>& __x, const _Up& __v) {
# |       | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |  1249 |   return __x.has_value() ? *__x <=> __v : strong_ordering::less;
# |       |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |  1250 | }
# |       | ~

@zmodem
Copy link
Collaborator

zmodem commented Jan 8, 2025

We've started seeing libc++ test failures in the Fuchsia toolchain buildbots for Windows

We're hitting the same error in Chromium builds. Here is a stand-alone reproducer: https://crbug.com/388428503#comment4

@cor3ntin
Copy link
Contributor

cor3ntin commented Jan 8, 2025

We've started seeing libc++ test failures in the Fuchsia toolchain buildbots for Windows

We're hitting the same error in Chromium builds. Here is a stand-alone reproducer: https://crbug.com/388428503#comment4

Thanks. @Endilll is working on a reduction, so that we get a better sense of what the issue is

@zyn0217
Copy link
Contributor Author

zyn0217 commented Jan 8, 2025

@cor3ntin Do we need to revert it for now?

@cor3ntin
Copy link
Contributor

cor3ntin commented Jan 8, 2025

@cor3ntin Do we need to revert it for now?

I'd like us to figure out if it's a conformance issue first - but bearing resolution we should revert before end of week imo

@zmodem
Copy link
Collaborator

zmodem commented Jan 8, 2025

Here's what I got from creduce:

$ cat /tmp/a.ii
template <class, class _Up>
using compare_three_way_result_t = _Up ::type;

struct __sfinae_assign_base {};

template <class _Tp>
concept __is_derived_from_optional =
    requires(_Tp __t) { []<class _Up>(_Up) {}(__t); };

template <class _Tp, class _Up>
  requires(__is_derived_from_optional<_Up>)
compare_three_way_result_t<_Tp, _Up> operator<=>(_Tp, _Up);

struct RuntimeModeArgs {
  auto operator<=>(const RuntimeModeArgs &) const = default;
  __sfinae_assign_base needs_admin;
};

$ build/bin/clang.bad -cc1 -triple x86_64-pc-windows-msvc19.34.0 -emit-obj -fms-extensions -fms-compatibility -std=c++20 -w /tmp/a.ii
/tmp/a.ii:12:1: error: cannot mangle this dependent name type yet
   12 | compare_three_way_result_t<_Tp, _Up> operator<=>(_Tp, _Up);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

@zyn0217
Copy link
Contributor Author

zyn0217 commented Jan 8, 2025

I see the problem here:

When substituting into the constraint __is_derived_from_optional with [_Tp = __sfinae_assign_base] prior to substituting the three-way operator, we must also substitute into the lambda call expression. This requires instantiating the lambda body to deduce its return type, and instantiating the lambda body necessitates mangling its parent for Microsoft mangling. In this case, the lambda resides within the function declaration compare_three_way_result_t<_Tp, _Up> operator<=>(_Tp, _Up), which remains uninstantiated at this point!

@cor3ntin

@cor3ntin
Copy link
Contributor

cor3ntin commented Jan 8, 2025

@zyn0217 Ouch. Lets revert and try to figure that out... @erichkeane

zyn0217 added a commit to zyn0217/llvm-project that referenced this pull request Jan 8, 2025
…ubstitution""

Unfortunately that breaks some code on Windows when lambdas come into
play, as reported in llvm#102857 (comment)

This reverts commit 96eced6.
@zyn0217
Copy link
Contributor Author

zyn0217 commented Jan 8, 2025

Reverted in #122130

@erichkeane
Copy link
Collaborator

Oof, hrmph. It seems to me that we just have to be slightly more aggressive at making sure we instantiate stuff I think.

This sentence:
In this case, the lambda resides within the function declaration compare_three_way_result_t<_Tp, _Up> operator<=>(_Tp, _Up), which remains uninstantiated at this point!

Is kinda wrong, it should be in the instantiation of that function...

cor3ntin pushed a commit that referenced this pull request Jan 8, 2025
…ubstitution"" (#122130)

Unfortunately that breaks some code on Windows when lambdas come into
play, as reported in
#102857 (comment)

This reverts commit 96eced6.
@zyn0217
Copy link
Contributor Author

zyn0217 commented Jan 9, 2025

Is kinda wrong, it should be in the instantiation of that function...

@erichkeane I don’t quite understand: the CWG issue itself requires us to check the constraint before substituting into the function during template argument deduction. So it shouldn’t live in a specialization because we don’t really have one. This situation feels more like a chicken-and-egg problem.

GCC doesn’t encounter this issue because it doesn’t need to support the MSVC ABI. The problem only arises with the MSVC ABI because it requires parent mangling when instantiating the lambda body.

@frederick-vs-ja
Copy link
Contributor

Do we want to add some workaround to libc++'s <optional>?

@cor3ntin
Copy link
Contributor

cor3ntin commented Jan 9, 2025

@mizvekov can you investigate whether #107942 helps with this? Thanks

/*Final=*/false, /*Innermost=*/std::nullopt, /*RelativeToPrimary=*/true,
/*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true);
MLTAL.replaceInnermostTemplateArguments(Template, TemplateArgs);

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to enter an Unevaluated ExpressionEvaluationContext
Given the windows bug, I think the SavedContext might not be correct. Can you play with that?

@erichkeane
Copy link
Collaborator

Is kinda wrong, it should be in the instantiation of that function...

@erichkeane I don’t quite understand: the CWG issue itself requires us to check the constraint before substituting into the function during template argument deduction. So it shouldn’t live in a specialization because we don’t really have one. This situation feels more like a chicken-and-egg problem.

GCC doesn’t encounter this issue because it doesn’t need to support the MSVC ABI. The problem only arises with the MSVC ABI because it requires parent mangling when instantiating the lambda body.

Actually, I perhaps misread the example (I think I inserted extra curleys there). It isn't clear to me why we are mangling the name of the lambda. It isn't in a context where it should be emitted? Corentin might be right about the starting an unevaluated context.

It also isn't clear to me why compare_three_way_result_t is being instantiated with a lambda in it, but the example is one that perhaps needs more contemplating.

@cor3ntin
Copy link
Contributor

cor3ntin commented Jan 9, 2025

I spent some time on this with @zyn0217

template <class, class _Up>
using compare_three_way_result_t = _Up ::type;

struct __sfinae_assign_base {};

template <class _Tp, class _Up>
  requires ([]<class W>(W) { return true; }(_Up())) // #1
compare_three_way_result_t<_Tp, _Up> operator<=>(_Tp, _Up); //#2

struct RuntimeModeArgs {
  auto operator<=>(const RuntimeModeArgs &) const = default;
  __sfinae_assign_base needs_admin;
};

In #1, the lambda has an auto return type. During constraint satisfaction checking (before #2 gets specialized), we need to call DeduceReturnType which calls InstantiateFunctionDefinition.

In turn InstantiateFunctionDefinition ends up calling EmitGlobalDecl through:

Consumer.HandleTopLevelDecl(DG);

This in turns requires the lambda to have a mangled name, causing its enclosing, dependent function template type to get mangled on the windows abi, which obviously isn't going to work.

Fortunately, we do not need to mangle constraints, so we just need to find a reasonable way to skip the codegen.
It's weird that we try to emit anything from an unevaluated context to begin with.

This patch does the trick by skipping EmitGlobalDecl from unevaluated and immediate contexts

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 18fd95f77ec2..0e30f21ab68b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13721,7 +13721,8 @@ public:
                                      FunctionDecl *Function,
                                      bool Recursive = false,
                                      bool DefinitionRequired = false,
-                                     bool AtEndOfTU = false);
+                                     bool AtEndOfTU = false,
+                                     bool DeducingReturnType = false);
   VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
       VarTemplateDecl *VarTemplate, VarDecl *FromVar,
       const TemplateArgumentList *PartialSpecArgs,
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index acd1151184e4..b9918c556443 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5459,7 +5459,7 @@ bool Sema::DeduceReturnType(FunctionDecl *FD, SourceLocation Loc,
 
   if (FD->getTemplateInstantiationPattern()) {
     runWithSufficientStackSpace(Loc, [&] {
-      InstantiateFunctionDefinition(Loc, FD);
+      InstantiateFunctionDefinition(Loc, FD, false, false, false, /*DeducingReturnType=*/true);
     });
   }
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index e058afe81da5..e3d34c305429 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4955,7 +4955,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
                                          FunctionDecl *Function,
                                          bool Recursive,
                                          bool DefinitionRequired,
-                                         bool AtEndOfTU) {
+                                         bool AtEndOfTU,
+                                         bool DeducingReturnType) {
   if (Function->isInvalidDecl() || isa<CXXDeductionGuideDecl>(Function))
     return;
 
@@ -5284,8 +5285,11 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
     savedContext.pop();
   }
 
-  DeclGroupRef DG(Function);
-  Consumer.HandleTopLevelDecl(DG);
+  if(!DeducingReturnType || !(parentEvaluationContext().isUnevaluated()
+       || parentEvaluationContext().isImmediateFunctionContext())) {
+     DeclGroupRef DG(Function);
+     Consumer.HandleTopLevelDecl(DG);
+  }
 
   // This class may have local implicit instantiations that need to be
   // instantiation within this scope.

The DeducingReturnType boolean is only useful not to break
CodeGenCXX/template-param-objects-address-space.cpp so maybe we'd need to investigate that test further

@erichkeane @zygoloid @AaronBallman

@erichkeane
Copy link
Collaborator

That seems like a heavy hand. Should we instead be checking the 'unevaluated context' state to see whether we should be emitting stuff? I can't imagine that anything from an unevaluated context should ever be emitted.

github-actions bot pushed a commit to arm/arm-toolchain that referenced this pull request Jan 10, 2025
…aints and substitution"" (#122130)

Unfortunately that breaks some code on Windows when lambdas come into
play, as reported in
llvm/llvm-project#102857 (comment)

This reverts commit 96eced6.
zyn0217 added a commit that referenced this pull request Jun 2, 2025
…n" (#122423)

The previous approach broke code generation for the MS ABI due to an
unintended code path during constraint substitution. This time we
address the issue by inspecting the evaluation contexts and thereby
avoiding that code path.

This reapplies 96eced6 (#102857).
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
…n" (llvm#122423)

The previous approach broke code generation for the MS ABI due to an
unintended code path during constraint substitution. This time we
address the issue by inspecting the evaluation contexts and thereby
avoiding that code path.

This reapplies 96eced6 (llvm#102857).
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" concepts C++20 concepts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement CWG2369