Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions libcxx/include/fstream
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,14 @@ private:
}
}
}

_LIBCPP_HIDE_FROM_ABI 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>
Expand Down Expand Up @@ -841,8 +849,9 @@ 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 traits_type::eof();
if (std::fwrite(this->pbase(), sizeof(char_type), __n, __file_) != __n) {
return __overflow_failed();
}
} else {
if (!__cv_)
std::__throw_bad_cast();
Expand All @@ -854,34 +863,38 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
char* __extbuf_end = __extbuf_;
do {
codecvt_base::result __r = __cv_->out(__st_, __b, __p, __end, __extbuf_, __extbuf_ + __ebs_, __extbuf_end);
if (__end == __b)
return traits_type::eof();
if (__end == __b) {
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 traits_type::eof();
if (std::fwrite(__b, 1, __n, __file_) != __n) {
return __overflow_failed();
}
break;

// Conversion successful: output the converted characters to the file, done.
} 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 traits_type::eof();
if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) {
return __overflow_failed();
}
break;

// Conversion partially successful: output converted characters to the file and repeat with the
// remaining characters.
} 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 traits_type::eof();
if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) {
return __overflow_failed();
}
__b = const_cast<char_type*>(__end);
continue;

} else {
return traits_type::eof();
return __overflow_failed();
}
} while (true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: no-filesystem

// setrlimit(RLIMIT_FSIZE) seems to only work as intended on Apple platforms
// REQUIRES: target={{.+}}-apple-{{.+}}

// <fstream>

// Make sure that we properly handle the case where we try to write content to a file
// but we fail to do so because std::fwrite fails.

#include <cassert>
#include <csignal>
#include <cstddef>
#include <fstream>
#include <string>

#include "platform_support.h"
#include "test_macros.h"

#if __has_include(<sys/resource.h>)
# include <sys/resource.h>
void limit_file_size_to(std::size_t bytes) {
rlimit lim = {bytes, bytes};
assert(setrlimit(RLIMIT_FSIZE, &lim) == 0);

std::signal(SIGXFSZ, [](int) {}); // ignore SIGXFSZ to ensure std::fwrite fails
}
#else
# error No known way to limit the amount of filesystem space available
#endif

template <class CharT>
void test() {
std::string temp = get_temp_file_name();
std::basic_filebuf<CharT> fbuf;
assert(fbuf.open(temp, std::ios::out | std::ios::trunc));

std::size_t const limit = 100000;
limit_file_size_to(limit);

std::basic_string<CharT> large_block(limit / 10, CharT(42));

std::streamsize ret;
std::size_t bytes_written = 0;
while ((ret = fbuf.sputn(large_block.data(), large_block.size())) != 0) {
bytes_written += ret;

// In theory, it's possible for an implementation to allow writing arbitrarily more bytes than
// set by setrlimit, but in practice if we bust 100x our limit, something else is wrong with the
// test and we'd end up looping forever.
assert(bytes_written < 100 * limit);
}

fbuf.close();
}

int main(int, char**) {
test<char>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test<wchar_t>();
#endif

return 0;
}
10 changes: 10 additions & 0 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,16 @@ ClangASTImporter::MapCompleter::~MapCompleter() = default;

llvm::Expected<Decl *>
ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
// FIXME: The Minimal import mode of clang::ASTImporter does not correctly
// import Lambda definitions. Work around this for now by not importing
// lambdas at all. This is most likely encountered when importing decls from
// the `std` module (not from debug-info), where lambdas can be defined in
// inline function bodies. Those will be imported by LLDB.
if (const auto *CXX = llvm::dyn_cast<clang::CXXRecordDecl>(From))
if (CXX->isLambda())
return llvm::make_error<ASTImportError>(
ASTImportError::UnsupportedConstruct);

if (m_std_handler) {
std::optional<Decl *> D = m_std_handler->Import(From);
if (D) {
Expand Down
10 changes: 9 additions & 1 deletion lldb/test/API/lang/cpp/lambdas/TestLambdas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from lldbsuite.test import lldbinline
from lldbsuite.test import decorators

lldbinline.MakeInlineTest(__file__, globals())
lldbinline.MakeInlineTest(
__file__,
globals(),
[
decorators.expectedFailureAll(
bugnumber="https://github.com/llvm/llvm-project/issues/149477"
)
],
)
26 changes: 26 additions & 0 deletions lldb/test/Shell/Expr/TestLambdaExprImport.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Test that we can successfully ASTImport clang::LambdaExpr nodes.
# Currently this is not supported in MinimalImport mode (which LLDB
# uses always).

# RUN: split-file %s %t
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
# RUN: %lldb -o "settings set interpreter.stop-command-source-on-error false" \
# RUN: -x -b -s %t/commands.input %t.out 2>&1 \
# RUN: | FileCheck %s

#--- main.cpp

int main() {
__builtin_debugtrap();
}

#--- commands.input

run
expression --top-level -- void method(int x) { [x=x] { ; }; }
target dump typesystem

# CHECK: expression
# CHECK: target dump typesystem
# CHECK-NOT: FunctionDecl
# CHECK-NOT: LambdaExpr
Loading