Skip to content

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Jul 17, 2025

This patch makes the __failed lambda a member function on fstream. This fixes two LLDB expression evaluation test failures that got introduced with #147389:

16:22:51  ********************
16:22:51  Unresolved Tests (2):
16:22:51    lldb-api :: commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
16:22:51    lldb-api :: commands/expression/import-std-module/list/TestListFromStdModule.py

The expression evaluator is asserting in the Clang parser:

Assertion failed: (capture_size() == Class->capture_size() && "Wrong number of captures"), function LambdaExpr, file ExprCXX.cpp, line 1277.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.

Ideally we'd figure out why LLDB is falling over on this lambda. But to unblock CI for now, make this a member function.

In the long run we should figure out the LLDB bug here so libc++ doesn't need to care about whether it uses lambdas like this or not.

@Michael137 Michael137 requested a review from ldionne July 17, 2025 19:39
@Michael137 Michael137 requested a review from a team as a code owner July 17, 2025 19:39
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 17, 2025

@llvm/pr-subscribers-libcxx

Author: Michael Buch (Michael137)

Changes

This patch makes the __failed lambda a member function on fstream. This fixes two LLDB expression evaluation test failures that got introduced with #147389:

16:22:51  ********************
16:22:51  Unresolved Tests (2):
16:22:51    lldb-api :: commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
16:22:51    lldb-api :: commands/expression/import-std-module/list/TestListFromStdModule.py

The expression evaluator is asserting in the Clang parser:

Assertion failed: (capture_size() == Class->capture_size() && "Wrong number of captures"), function LambdaExpr, file ExprCXX.cpp, line 1277.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.

Ideally we'd figure out why LLDB is falling over on this lambda. But to unblock CI for now, make this a member function.

In the long run we should figure out the LLDB bug here so libc++ doesn't need to care about whether it uses lambdas like this or not.


Full diff: https://github.com/llvm/llvm-project/pull/149390.diff

1 Files Affected:

  • (modified) libcxx/include/fstream (+14-14)
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index dc5c47304f014..cf6d5779d1de5 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -401,6 +401,14 @@ private:
       }
     }
   }
+
+  typename traits_type::int_type __overflow_failed() {
+    if (this->pptr() == this->epptr() + 1) {
+      this->pbump(-1); // lose the character we overflowed above -- we don't really have a
+                       // choice since we couldn't commit the contents of the put area
+    }
+    return traits_type::eof();
+  }
 };
 
 template <class _CharT, class _Traits>
@@ -821,14 +829,6 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
 
 template <class _CharT, class _Traits>
 typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::overflow(int_type __c) {
-  auto __failed = [this]() {
-    if (this->pptr() == this->epptr() + 1) {
-      this->pbump(-1); // lose the character we overflowed above -- we don't really have a
-                       // choice since we couldn't commit the contents of the put area
-    }
-    return traits_type::eof();
-  };
-
   if (__file_ == nullptr)
     return traits_type::eof();
   __write_mode();
@@ -850,7 +850,7 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
   if (__always_noconv_) {
     size_t __n = static_cast<size_t>(this->pptr() - this->pbase());
     if (std::fwrite(this->pbase(), sizeof(char_type), __n, __file_) != __n) {
-      return __failed();
+      return __overflow_failed();
     }
   } else {
     if (!__cv_)
@@ -864,14 +864,14 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
     do {
       codecvt_base::result __r = __cv_->out(__st_, __b, __p, __end, __extbuf_, __extbuf_ + __ebs_, __extbuf_end);
       if (__end == __b) {
-        return __failed();
+        return __overflow_failed();
       }
 
       // No conversion needed: output characters directly to the file, done.
       if (__r == codecvt_base::noconv) {
         size_t __n = static_cast<size_t>(__p - __b);
         if (std::fwrite(__b, 1, __n, __file_) != __n) {
-          return __failed();
+          return __overflow_failed();
         }
         break;
 
@@ -879,7 +879,7 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
       } else if (__r == codecvt_base::ok) {
         size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_);
         if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) {
-          return __failed();
+          return __overflow_failed();
         }
         break;
 
@@ -888,13 +888,13 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
       } else if (__r == codecvt_base::partial) {
         size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_);
         if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) {
-          return __failed();
+          return __overflow_failed();
         }
         __b = const_cast<char_type*>(__end);
         continue;
 
       } else {
-        return __failed();
+        return __overflow_failed();
       }
     } while (true);
   }

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

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

LGTM with green CI. Can you file a Github issue to figure out the issue and we can add it in a comment here. That way we can go back to the much more readable variant once the bug is fixed.

But in the meantime, we should make sure that LLDB works properly with the version of libc++ we'll include in LLVM 21, so I think it makes sense to land this change and cherry-pick it.

@Michael137 Michael137 self-assigned this Jul 17, 2025
@Michael137
Copy link
Member Author

Michael137 commented Jul 17, 2025

Tests pass. Code formatter github action keeps failing with:

Traceback (most recent call last):
  File "/home/runner/work/llvm-project/llvm-project/./code-format-tools/llvm/utils/git/code-format-helper.py", line 525, in <module>
    if not fmt.run(changed_files, args):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/llvm-project/llvm-project/./code-format-tools/llvm/utils/git/code-format-helper.py", line 151, in run
    self.update_pr(comment_text, args, create_new=False)
  File "/home/runner/work/llvm-project/llvm-project/./code-format-tools/llvm/utils/git/code-format-helper.py", line 121, in update_pr
    repo = github.Github(args.token).get_repo(args.repo)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/github/MainClass.py", line 363, in get_repo
    headers, data = self.__requester.requestJsonAndCheck("GET", url)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/github/Requester.py", line 442, in requestJsonAndCheck
    return self.__check(
           ^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/github/Requester.py", line 487, in __check
    raise self.__createException(status, responseHeaders, data)
github.GithubException.RateLimitExceededException: 403 {"message": "API rate limit exceeded for installation. If you reach out to GitHub Support for help, please include the request ID 5800:166FBA:3860649:7137236:687958E8 and timestamp 2025-07-17 20:11:20 UTC.", "documentation_url": "https://docs.github.com/rest/overview/rate-limits-for-the-rest-api", "status": "403"}

Seems unrelated so going to merge this. I ran git clang-format prior to comitting

@Michael137 Michael137 merged commit 8f4deff into llvm:main Jul 17, 2025
76 of 79 checks passed
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in LLVM Release Status Jul 17, 2025
@Michael137 Michael137 deleted the libcxx/fstream-lambda branch July 17, 2025 22:50
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 17, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-aarch64-linux-bootstrap-hwasan running on sanitizer-buildbot12 while building libcxx at step 2 "annotate".

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

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-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:73: 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: 89181 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 
FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s (54027 of 89181)
******************** TEST 'LLVM :: ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-mc -filetype=obj -triple=x86_64-windows-msvc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s -o /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp # RUN: at line 1
+ /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-mc -filetype=obj -triple=x86_64-windows-msvc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s -o /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
not /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-jitlink -noexec /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp 2>&1 | /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/FileCheck /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s # RUN: at line 2
+ not /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-jitlink -noexec /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
+ /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/FileCheck /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
56.10s: Clang :: Driver/fsanitize.c
36.44s: Clang :: Preprocessor/riscv-target-features.c
35.70s: LLVM :: CodeGen/AMDGPU/sched-group-barrier-pipeline-solver.mir
35.26s: Clang :: Driver/arm-cortex-cpus-2.c
34.93s: Clang :: Driver/arm-cortex-cpus-1.c
29.08s: LLVM :: CodeGen/AMDGPU/amdgcn.bitcast.1024bit.ll
28.36s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
27.62s: Clang :: OpenMP/target_update_codegen.cpp
26.56s: LLVM :: CodeGen/RISCV/attributes.ll
26.32s: Clang :: Preprocessor/aarch64-target-features.c
26.02s: Clang :: Preprocessor/arm-target-features.c
23.75s: LLVM :: tools/llvm-reduce/parallel-workitem-kill.ll
22.55s: Clang :: CodeGen/AArch64/sve-intrinsics/acle_sve_reinterpret.c
22.50s: Clang :: Driver/linux-ld.c
21.98s: Clang :: Driver/clang_f_opts.c
21.29s: Clang :: Headers/arm-neon-header.c
20.96s: Clang :: Driver/cl-options.c
20.90s: Clang :: Preprocessor/predefined-arch-macros.c
20.26s: Clang :: Driver/x86-target-features.c
19.91s: Clang :: Analysis/a_flaky_crash.cpp

Step 11 (stage2/hwasan check) failure: stage2/hwasan check (failure)
...
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:73: 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: 89181 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 
FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s (54027 of 89181)
******************** TEST 'LLVM :: ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-mc -filetype=obj -triple=x86_64-windows-msvc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s -o /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp # RUN: at line 1
+ /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-mc -filetype=obj -triple=x86_64-windows-msvc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s -o /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
not /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-jitlink -noexec /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp 2>&1 | /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/FileCheck /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s # RUN: at line 2
+ not /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-jitlink -noexec /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
+ /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/FileCheck /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
56.10s: Clang :: Driver/fsanitize.c
36.44s: Clang :: Preprocessor/riscv-target-features.c
35.70s: LLVM :: CodeGen/AMDGPU/sched-group-barrier-pipeline-solver.mir
35.26s: Clang :: Driver/arm-cortex-cpus-2.c
34.93s: Clang :: Driver/arm-cortex-cpus-1.c
29.08s: LLVM :: CodeGen/AMDGPU/amdgcn.bitcast.1024bit.ll
28.36s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
27.62s: Clang :: OpenMP/target_update_codegen.cpp
26.56s: LLVM :: CodeGen/RISCV/attributes.ll
26.32s: Clang :: Preprocessor/aarch64-target-features.c
26.02s: Clang :: Preprocessor/arm-target-features.c
23.75s: LLVM :: tools/llvm-reduce/parallel-workitem-kill.ll
22.55s: Clang :: CodeGen/AArch64/sve-intrinsics/acle_sve_reinterpret.c
22.50s: Clang :: Driver/linux-ld.c
21.98s: Clang :: Driver/clang_f_opts.c
21.29s: Clang :: Headers/arm-neon-header.c
20.96s: Clang :: Driver/cl-options.c
20.90s: Clang :: Preprocessor/predefined-arch-macros.c
20.26s: Clang :: Driver/x86-target-features.c
19.91s: Clang :: Analysis/a_flaky_crash.cpp


@var-const
Copy link
Member

/cherry-pick 8f4deff

@llvmbot
Copy link
Member

llvmbot commented Aug 28, 2025

Failed to cherry-pick: 8f4deff

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

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. release:cherry-pick-failed
Projects
Development

Successfully merging this pull request may close these issues.

5 participants