Skip to content

Commit ab07d73

Browse files
committed
rebase
Created using spr 1.3.4
2 parents c00fee8 + 24171f4 commit ab07d73

File tree

21 files changed

+830
-465
lines changed

21 files changed

+830
-465
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,17 @@ static void appendParameterTypes(const CodeGenTypes &CGT,
199199
prefix.size());
200200
}
201201

202+
using ExtParameterInfoList =
203+
SmallVector<FunctionProtoType::ExtParameterInfo, 16>;
204+
202205
/// Arrange the LLVM function layout for a value of the given function
203206
/// type, on top of any implicit parameters already stored.
204207
static const CGFunctionInfo &
205208
arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod,
206209
SmallVectorImpl<CanQualType> &prefix,
207210
CanQual<FunctionProtoType> FTP) {
208-
SmallVector<FunctionProtoType::ExtParameterInfo, 16> paramInfos;
211+
ExtParameterInfoList paramInfos;
209212
RequiredArgs Required = RequiredArgs::forPrototypePlus(FTP, prefix.size());
210-
// FIXME: Kill copy.
211213
appendParameterTypes(CGT, prefix, paramInfos, FTP);
212214
CanQualType resultType = FTP->getReturnType().getUnqualifiedType();
213215

@@ -217,11 +219,13 @@ arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod,
217219
FTP->getExtInfo(), paramInfos, Required);
218220
}
219221

222+
using CanQualTypeList = SmallVector<CanQualType, 16>;
223+
220224
/// Arrange the argument and result information for a value of the
221225
/// given freestanding function type.
222226
const CGFunctionInfo &
223227
CodeGenTypes::arrangeFreeFunctionType(CanQual<FunctionProtoType> FTP) {
224-
SmallVector<CanQualType, 16> argTypes;
228+
CanQualTypeList argTypes;
225229
return ::arrangeLLVMFunctionInfo(*this, /*instanceMethod=*/false, argTypes,
226230
FTP);
227231
}
@@ -319,7 +323,7 @@ const CGFunctionInfo &
319323
CodeGenTypes::arrangeCXXMethodType(const CXXRecordDecl *RD,
320324
const FunctionProtoType *FTP,
321325
const CXXMethodDecl *MD) {
322-
SmallVector<CanQualType, 16> argTypes;
326+
CanQualTypeList argTypes;
323327

324328
// Add the 'this' pointer.
325329
argTypes.push_back(DeriveThisType(RD, MD));
@@ -375,8 +379,8 @@ const CGFunctionInfo &
375379
CodeGenTypes::arrangeCXXStructorDeclaration(GlobalDecl GD) {
376380
auto *MD = cast<CXXMethodDecl>(GD.getDecl());
377381

378-
SmallVector<CanQualType, 16> argTypes;
379-
SmallVector<FunctionProtoType::ExtParameterInfo, 16> paramInfos;
382+
CanQualTypeList argTypes;
383+
ExtParameterInfoList paramInfos;
380384

381385
const CXXRecordDecl *ThisType = getCXXABI().getThisArgumentTypeForMethod(GD);
382386
argTypes.push_back(DeriveThisType(ThisType, MD));
@@ -421,26 +425,26 @@ CodeGenTypes::arrangeCXXStructorDeclaration(GlobalDecl GD) {
421425
argTypes, extInfo, paramInfos, required);
422426
}
423427

424-
static SmallVector<CanQualType, 16>
425-
getArgTypesForCall(ASTContext &ctx, const CallArgList &args) {
426-
SmallVector<CanQualType, 16> argTypes;
428+
static CanQualTypeList getArgTypesForCall(ASTContext &ctx,
429+
const CallArgList &args) {
430+
CanQualTypeList argTypes;
427431
for (auto &arg : args)
428432
argTypes.push_back(ctx.getCanonicalParamType(arg.Ty));
429433
return argTypes;
430434
}
431435

432-
static SmallVector<CanQualType, 16>
433-
getArgTypesForDeclaration(ASTContext &ctx, const FunctionArgList &args) {
434-
SmallVector<CanQualType, 16> argTypes;
436+
static CanQualTypeList getArgTypesForDeclaration(ASTContext &ctx,
437+
const FunctionArgList &args) {
438+
CanQualTypeList argTypes;
435439
for (auto &arg : args)
436440
argTypes.push_back(ctx.getCanonicalParamType(arg->getType()));
437441
return argTypes;
438442
}
439443

440-
static llvm::SmallVector<FunctionProtoType::ExtParameterInfo, 16>
441-
getExtParameterInfosForCall(const FunctionProtoType *proto,
442-
unsigned prefixArgs, unsigned totalArgs) {
443-
llvm::SmallVector<FunctionProtoType::ExtParameterInfo, 16> result;
444+
static ExtParameterInfoList
445+
getExtParameterInfosForCall(const FunctionProtoType *proto, unsigned prefixArgs,
446+
unsigned totalArgs) {
447+
ExtParameterInfoList result;
444448
if (proto->hasExtParameterInfos()) {
445449
addExtParameterInfosForCall(result, proto, prefixArgs, totalArgs);
446450
}
@@ -462,8 +466,7 @@ CodeGenTypes::arrangeCXXConstructorCall(const CallArgList &args,
462466
unsigned ExtraPrefixArgs,
463467
unsigned ExtraSuffixArgs,
464468
bool PassProtoArgs) {
465-
// FIXME: Kill copy.
466-
SmallVector<CanQualType, 16> ArgTypes;
469+
CanQualTypeList ArgTypes;
467470
for (const auto &Arg : args)
468471
ArgTypes.push_back(Context.getCanonicalParamType(Arg.Ty));
469472

@@ -483,7 +486,7 @@ CodeGenTypes::arrangeCXXConstructorCall(const CallArgList &args,
483486
: Context.VoidTy;
484487

485488
FunctionType::ExtInfo Info = FPT->getExtInfo();
486-
llvm::SmallVector<FunctionProtoType::ExtParameterInfo, 16> ParamInfos;
489+
ExtParameterInfoList ParamInfos;
487490
// If the prototype args are elided, we should only have ABI-specific args,
488491
// which never have param info.
489492
if (PassProtoArgs && FPT->hasExtParameterInfos()) {
@@ -546,13 +549,11 @@ CodeGenTypes::arrangeObjCMethodDeclaration(const ObjCMethodDecl *MD) {
546549
const CGFunctionInfo &
547550
CodeGenTypes::arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD,
548551
QualType receiverType) {
549-
SmallVector<CanQualType, 16> argTys;
550-
SmallVector<FunctionProtoType::ExtParameterInfo, 4> extParamInfos(
551-
MD->isDirectMethod() ? 1 : 2);
552+
CanQualTypeList argTys;
553+
ExtParameterInfoList extParamInfos(MD->isDirectMethod() ? 1 : 2);
552554
argTys.push_back(Context.getCanonicalParamType(receiverType));
553555
if (!MD->isDirectMethod())
554556
argTys.push_back(Context.getCanonicalParamType(Context.getObjCSelType()));
555-
// FIXME: Kill copy?
556557
for (const auto *I : MD->parameters()) {
557558
argTys.push_back(Context.getCanonicalParamType(I->getType()));
558559
auto extParamInfo = FunctionProtoType::ExtParameterInfo().withIsNoEscape(
@@ -579,7 +580,7 @@ CodeGenTypes::arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD,
579580
const CGFunctionInfo &
580581
CodeGenTypes::arrangeUnprototypedObjCMessageSend(QualType returnType,
581582
const CallArgList &args) {
582-
auto argTypes = getArgTypesForCall(Context, args);
583+
CanQualTypeList argTypes = getArgTypesForCall(Context, args);
583584
FunctionType::ExtInfo einfo;
584585

585586
return arrangeLLVMFunctionInfo(GetReturnType(returnType), FnInfoOpts::None,
@@ -641,7 +642,7 @@ arrangeFreeFunctionLikeCall(CodeGenTypes &CGT,
641642
bool chainCall) {
642643
assert(args.size() >= numExtraRequiredArgs);
643644

644-
llvm::SmallVector<FunctionProtoType::ExtParameterInfo, 16> paramInfos;
645+
ExtParameterInfoList paramInfos;
645646

646647
// In most cases, there are no optional arguments.
647648
RequiredArgs required = RequiredArgs::All;
@@ -666,8 +667,7 @@ arrangeFreeFunctionLikeCall(CodeGenTypes &CGT,
666667
required = RequiredArgs(args.size());
667668
}
668669

669-
// FIXME: Kill copy.
670-
SmallVector<CanQualType, 16> argTypes;
670+
CanQualTypeList argTypes;
671671
for (const auto &arg : args)
672672
argTypes.push_back(CGT.getContext().getCanonicalParamType(arg.Ty));
673673
FnInfoOpts opts = chainCall ? FnInfoOpts::IsChainCall : FnInfoOpts::None;
@@ -700,8 +700,9 @@ CodeGenTypes::arrangeBlockFunctionCall(const CallArgList &args,
700700
const CGFunctionInfo &
701701
CodeGenTypes::arrangeBlockFunctionDeclaration(const FunctionProtoType *proto,
702702
const FunctionArgList &params) {
703-
auto paramInfos = getExtParameterInfosForCall(proto, 1, params.size());
704-
auto argTypes = getArgTypesForDeclaration(Context, params);
703+
ExtParameterInfoList paramInfos =
704+
getExtParameterInfosForCall(proto, 1, params.size());
705+
CanQualTypeList argTypes = getArgTypesForDeclaration(Context, params);
705706

706707
return arrangeLLVMFunctionInfo(GetReturnType(proto->getReturnType()),
707708
FnInfoOpts::None, argTypes,
@@ -712,8 +713,7 @@ CodeGenTypes::arrangeBlockFunctionDeclaration(const FunctionProtoType *proto,
712713
const CGFunctionInfo &
713714
CodeGenTypes::arrangeBuiltinFunctionCall(QualType resultType,
714715
const CallArgList &args) {
715-
// FIXME: Kill copy.
716-
SmallVector<CanQualType, 16> argTypes;
716+
CanQualTypeList argTypes;
717717
for (const auto &Arg : args)
718718
argTypes.push_back(Context.getCanonicalParamType(Arg.Ty));
719719
return arrangeLLVMFunctionInfo(GetReturnType(resultType), FnInfoOpts::None,
@@ -724,7 +724,7 @@ CodeGenTypes::arrangeBuiltinFunctionCall(QualType resultType,
724724
const CGFunctionInfo &
725725
CodeGenTypes::arrangeBuiltinFunctionDeclaration(QualType resultType,
726726
const FunctionArgList &args) {
727-
auto argTypes = getArgTypesForDeclaration(Context, args);
727+
CanQualTypeList argTypes = getArgTypesForDeclaration(Context, args);
728728

729729
return arrangeLLVMFunctionInfo(GetReturnType(resultType), FnInfoOpts::None,
730730
argTypes, FunctionType::ExtInfo(), {},
@@ -752,11 +752,10 @@ CodeGenTypes::arrangeCXXMethodCall(const CallArgList &args,
752752
"Emitting a call with less args than the required prefix?");
753753
// Add one to account for `this`. It's a bit awkward here, but we don't count
754754
// `this` in similar places elsewhere.
755-
auto paramInfos =
756-
getExtParameterInfosForCall(proto, numPrefixArgs + 1, args.size());
755+
ExtParameterInfoList paramInfos =
756+
getExtParameterInfosForCall(proto, numPrefixArgs + 1, args.size());
757757

758-
// FIXME: Kill copy.
759-
auto argTypes = getArgTypesForCall(Context, args);
758+
CanQualTypeList argTypes = getArgTypesForCall(Context, args);
760759

761760
FunctionType::ExtInfo info = proto->getExtInfo();
762761
return arrangeLLVMFunctionInfo(GetReturnType(proto->getReturnType()),
@@ -777,14 +776,14 @@ CodeGenTypes::arrangeCall(const CGFunctionInfo &signature,
777776
if (signature.arg_size() == args.size())
778777
return signature;
779778

780-
SmallVector<FunctionProtoType::ExtParameterInfo, 16> paramInfos;
779+
ExtParameterInfoList paramInfos;
781780
auto sigParamInfos = signature.getExtParameterInfos();
782781
if (!sigParamInfos.empty()) {
783782
paramInfos.append(sigParamInfos.begin(), sigParamInfos.end());
784783
paramInfos.resize(args.size());
785784
}
786785

787-
auto argTypes = getArgTypesForCall(Context, args);
786+
CanQualTypeList argTypes = getArgTypesForCall(Context, args);
788787

789788
assert(signature.getRequiredArgs().allowsOptionalArgs());
790789
FnInfoOpts opts = FnInfoOpts::None;

lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,30 @@ lldb_private::formatters::LibcxxStdVectorSyntheticFrontEnd::
8383
llvm::Expected<uint32_t> lldb_private::formatters::
8484
LibcxxStdVectorSyntheticFrontEnd::CalculateNumChildren() {
8585
if (!m_start || !m_finish)
86-
return 0;
86+
return llvm::createStringError(
87+
"Failed to determine start/end of vector data.");
88+
8789
uint64_t start_val = m_start->GetValueAsUnsigned(0);
8890
uint64_t finish_val = m_finish->GetValueAsUnsigned(0);
8991

90-
if (start_val == 0 || finish_val == 0)
92+
// A default-initialized empty vector.
93+
if (start_val == 0 && finish_val == 0)
9194
return 0;
9295

93-
if (start_val >= finish_val)
94-
return 0;
96+
if (start_val == 0)
97+
return llvm::createStringError("Invalid value for start of vector.");
98+
99+
if (finish_val == 0)
100+
return llvm::createStringError("Invalid value for end of vector.");
101+
102+
if (start_val > finish_val)
103+
return llvm::createStringError(
104+
"Start of vector data begins after end pointer.");
95105

96106
size_t num_children = (finish_val - start_val);
97107
if (num_children % m_element_size)
98-
return 0;
108+
return llvm::createStringError("Size not multiple of element size.");
109+
99110
return num_children / m_element_size;
100111
}
101112

lldb/source/ValueObject/ValueObject.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,10 +1521,16 @@ bool ValueObject::DumpPrintableRepresentation(
15211521
str = GetLocationAsCString();
15221522
break;
15231523

1524-
case eValueObjectRepresentationStyleChildrenCount:
1525-
strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildrenIgnoringErrors());
1526-
str = strm.GetString();
1524+
case eValueObjectRepresentationStyleChildrenCount: {
1525+
if (auto err = GetNumChildren()) {
1526+
strm.Printf("%" PRIu32, *err);
1527+
str = strm.GetString();
1528+
} else {
1529+
strm << "error: " << toString(err.takeError());
1530+
str = strm.GetString();
1531+
}
15271532
break;
1533+
}
15281534

15291535
case eValueObjectRepresentationStyleType:
15301536
str = GetTypeName().GetStringRef();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
override CXXFLAGS_EXTRAS += -std=c++14
3+
include Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Test we can understand various layouts of the libc++'s std::string
3+
"""
4+
5+
6+
import lldb
7+
from lldbsuite.test.decorators import *
8+
from lldbsuite.test.lldbtest import *
9+
from lldbsuite.test import lldbutil
10+
import functools
11+
12+
13+
class LibcxxInvalidVectorDataFormatterSimulatorTestCase(TestBase):
14+
NO_DEBUG_INFO_TESTCASE = True
15+
16+
def test(self):
17+
self.build()
18+
lldbutil.run_to_source_breakpoint(self, "return 0", lldb.SBFileSpec("main.cpp"))
19+
20+
self.expect(
21+
"frame variable v1",
22+
substrs=["size=error: Invalid value for end of vector."],
23+
)
24+
self.expect(
25+
"frame variable v2",
26+
substrs=["size=error: Invalid value for start of vector."],
27+
)
28+
self.expect(
29+
"frame variable v3",
30+
substrs=["size=error: Start of vector data begins after end pointer."],
31+
)
32+
self.expect(
33+
"frame variable v4",
34+
substrs=["size=error: Failed to determine start/end of vector data."],
35+
)
36+
self.expect(
37+
"frame variable v5",
38+
substrs=["size=error: Size not multiple of element size."],
39+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#define COMPRESSED_PAIR_REV 2
2+
#include <libcxx-simulators-common/compressed_pair.h>
3+
4+
namespace std {
5+
namespace __1 {
6+
template <typename T> struct vector {
7+
T *__begin_;
8+
T *__end_;
9+
_LLDB_COMPRESSED_PAIR(T *, __cap_ = nullptr, void *, __alloc_);
10+
};
11+
} // namespace __1
12+
13+
namespace __2 {
14+
template <typename T> struct vector {};
15+
} // namespace __2
16+
17+
namespace __3 {
18+
template <typename T> struct vector {
19+
T *__begin_;
20+
T *__end_;
21+
_LLDB_COMPRESSED_PAIR(short *, __cap_ = nullptr, void *, __alloc_);
22+
};
23+
} // namespace __3
24+
} // namespace std
25+
26+
int main() {
27+
int arr[] = {1, 2, 3};
28+
std::__1::vector<int> v1{.__begin_ = arr, .__end_ = nullptr};
29+
std::__1::vector<int> v2{.__begin_ = nullptr, .__end_ = arr};
30+
std::__1::vector<int> v3{.__begin_ = &arr[2], .__end_ = arr};
31+
std::__2::vector<int> v4;
32+
33+
char carr[] = {'a'};
34+
std::__3::vector<char> v5{.__begin_ = carr, .__end_ = carr + 1};
35+
36+
return 0;
37+
}

llvm/include/llvm/Demangle/ItaniumDemangle.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
DEMANGLE_NAMESPACE_BEGIN
3939

4040
template <class T, size_t N> class PODSmallVector {
41-
static_assert(std::is_trivial<T>::value,
42-
"T is required to be a trivial type");
41+
static_assert(std::is_trivially_copyable<T>::value,
42+
"T is required to be a trivially copyable type");
43+
static_assert(std::is_trivially_default_constructible<T>::value,
44+
"T is required to be trivially default constructible");
4345
T *First = nullptr;
4446
T *Last = nullptr;
4547
T *Cap = nullptr;
@@ -5739,14 +5741,16 @@ struct FloatData<double>
57395741
template <>
57405742
struct FloatData<long double>
57415743
{
5742-
#if defined(__mips__) && defined(__mips_n64) || defined(__aarch64__) || \
5743-
defined(__wasm__) || defined(__riscv) || defined(__loongarch__) || \
5744-
defined(__ve__)
5745-
static const size_t mangled_size = 32;
5746-
#elif defined(__arm__) || defined(__mips__) || defined(__hexagon__)
5747-
static const size_t mangled_size = 16;
5744+
#if __LDBL_MANT_DIG__ == 113 || __LDBL_MANT_DIG__ == 106
5745+
static const size_t mangled_size = 32;
5746+
#elif __LDBL_MANT_DIG__ == 53 || defined(_MSC_VER)
5747+
// MSVC doesn't define __LDBL_MANT_DIG__, but it has long double equal to
5748+
// regular double on all current architectures.
5749+
static const size_t mangled_size = 16;
5750+
#elif __LDBL_MANT_DIG__ == 64
5751+
static const size_t mangled_size = 20;
57485752
#else
5749-
static const size_t mangled_size = 20; // May need to be adjusted to 16 or 24 on other platforms
5753+
#error Unknown size for __LDBL_MANT_DIG__
57505754
#endif
57515755
// `-0x1.ffffffffffffffffffffffffffffp+16383` + 'L' + '\0' == 42 bytes.
57525756
// 28 'f's * 4 bits == 112 bits, which is the number of mantissa bits.

0 commit comments

Comments
 (0)