Skip to content

Commit

Permalink
Merged master:24c74f5e8c2c into amd-gfx:6083d1110df4
Browse files Browse the repository at this point in the history
Local branch amd-gfx 6083d11 Merged master:24fc3177c176 into amd-gfx:ff3a17708b84
Remote branch master 24c74f5 [lldb] Don't delete orphaned shared modules in SBDebugger::DeleteTarget
  • Loading branch information
Sw authored and Sw committed Aug 17, 2020
2 parents 6083d11 + 24c74f5 commit 35fe0c3
Show file tree
Hide file tree
Showing 41 changed files with 1,141 additions and 637 deletions.
109 changes: 69 additions & 40 deletions clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,46 +1166,75 @@ TEST(SignatureHelpTest, ActiveArg) {
}

TEST(SignatureHelpTest, OpeningParen) {
llvm::StringLiteral Tests[] = {// Recursive function call.
R"cpp(
int foo(int a, int b, int c);
int main() {
foo(foo $p^( foo(10, 10, 10), ^ )));
})cpp",
// Functional type cast.
R"cpp(
struct Foo {
Foo(int a, int b, int c);
};
int main() {
Foo $p^( 10, ^ );
})cpp",
// New expression.
R"cpp(
struct Foo {
Foo(int a, int b, int c);
};
int main() {
new Foo $p^( 10, ^ );
})cpp",
// Macro expansion.
R"cpp(
int foo(int a, int b, int c);
#define FOO foo(
int main() {
// Macro expansions.
$p^FOO 10, ^ );
})cpp",
// Macro arguments.
R"cpp(
int foo(int a, int b, int c);
int main() {
#define ID(X) X
// FIXME: figure out why ID(foo (foo(10), )) doesn't work when preserving
// the recovery expression.
ID(foo $p^( 10, ^ ))
})cpp"};
llvm::StringLiteral Tests[] = {
// Recursive function call.
R"cpp(
int foo(int a, int b, int c);
int main() {
foo(foo $p^( foo(10, 10, 10), ^ )));
})cpp",
// Functional type cast.
R"cpp(
struct Foo {
Foo(int a, int b, int c);
};
int main() {
Foo $p^( 10, ^ );
})cpp",
// New expression.
R"cpp(
struct Foo {
Foo(int a, int b, int c);
};
int main() {
new Foo $p^( 10, ^ );
})cpp",
// Macro expansion.
R"cpp(
int foo(int a, int b, int c);
#define FOO foo(
int main() {
// Macro expansions.
$p^FOO 10, ^ );
})cpp",
// Macro arguments.
R"cpp(
int foo(int a, int b, int c);
int main() {
#define ID(X) X
// FIXME: figure out why ID(foo (foo(10), )) doesn't work when preserving
// the recovery expression.
ID(foo $p^( 10, ^ ))
})cpp",
// Dependent args.
R"cpp(
int foo(int a, int b);
template <typename T> void bar(T t) {
foo$p^(t, ^t);
})cpp",
// Dependent args on templated func.
R"cpp(
template <typename T>
int foo(T, T);
template <typename T> void bar(T t) {
foo$p^(t, ^t);
})cpp",
// Dependent args on member.
R"cpp(
struct Foo { int foo(int, int); };
template <typename T> void bar(T t) {
Foo f;
f.foo$p^(t, ^t);
})cpp",
// Dependent args on templated member.
R"cpp(
struct Foo { template <typename T> int foo(T, T); };
template <typename T> void bar(T t) {
Foo f;
f.foo$p^(t, ^t);
})cpp",
};

for (auto Test : Tests) {
Annotations Code(Test);
Expand Down
53 changes: 35 additions & 18 deletions clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5500,7 +5500,7 @@ typedef CodeCompleteConsumer::OverloadCandidate ResultCandidate;

static void mergeCandidatesWithResults(
Sema &SemaRef, SmallVectorImpl<ResultCandidate> &Results,
OverloadCandidateSet &CandidateSet, SourceLocation Loc) {
OverloadCandidateSet &CandidateSet, SourceLocation Loc, size_t ArgSize) {
// Sort the overload candidate set by placing the best overloads first.
llvm::stable_sort(CandidateSet, [&](const OverloadCandidate &X,
const OverloadCandidate &Y) {
Expand All @@ -5510,8 +5510,19 @@ static void mergeCandidatesWithResults(

// Add the remaining viable overload candidates as code-completion results.
for (OverloadCandidate &Candidate : CandidateSet) {
if (Candidate.Function && Candidate.Function->isDeleted())
continue;
if (Candidate.Function) {
if (Candidate.Function->isDeleted())
continue;
if (!Candidate.Function->isVariadic() &&
Candidate.Function->getNumParams() <= ArgSize &&
// Having zero args is annoying, normally we don't surface a function
// with 2 params, if you already have 2 params, because you are
// inserting the 3rd now. But with zero, it helps the user to figure
// out there are no overloads that take any arguments. Hence we are
// keeping the overload.
ArgSize > 0)
continue;
}
if (Candidate.Viable)
Results.push_back(ResultCandidate(Candidate.Function));
}
Expand Down Expand Up @@ -5562,22 +5573,25 @@ QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,

// FIXME: Provide support for variadic template functions.
// Ignore type-dependent call expressions entirely.
if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args) ||
Expr::hasAnyTypeDependentArguments(Args)) {
if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args))
return QualType();
}
// In presence of dependent args we surface all possible signatures using the
// non-dependent args in the prefix. Afterwards we do a post filtering to make
// sure provided candidates satisfy parameter count restrictions.
auto ArgsWithoutDependentTypes =
Args.take_while([](Expr *Arg) { return !Arg->isTypeDependent(); });

SmallVector<ResultCandidate, 8> Results;

Expr *NakedFn = Fn->IgnoreParenCasts();
// Build an overload candidate set based on the functions we find.
SourceLocation Loc = Fn->getExprLoc();
OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Normal);

SmallVector<ResultCandidate, 8> Results;

Expr *NakedFn = Fn->IgnoreParenCasts();
if (auto ULE = dyn_cast<UnresolvedLookupExpr>(NakedFn))
AddOverloadedCallCandidates(ULE, Args, CandidateSet,
if (auto ULE = dyn_cast<UnresolvedLookupExpr>(NakedFn)) {
AddOverloadedCallCandidates(ULE, ArgsWithoutDependentTypes, CandidateSet,
/*PartialOverloading=*/true);
else if (auto UME = dyn_cast<UnresolvedMemberExpr>(NakedFn)) {
} else if (auto UME = dyn_cast<UnresolvedMemberExpr>(NakedFn)) {
TemplateArgumentListInfo TemplateArgsBuffer, *TemplateArgs = nullptr;
if (UME->hasExplicitTemplateArgs()) {
UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
Expand All @@ -5587,7 +5601,8 @@ QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
// Add the base as first argument (use a nullptr if the base is implicit).
SmallVector<Expr *, 12> ArgExprs(
1, UME->isImplicitAccess() ? nullptr : UME->getBase());
ArgExprs.append(Args.begin(), Args.end());
ArgExprs.append(ArgsWithoutDependentTypes.begin(),
ArgsWithoutDependentTypes.end());
UnresolvedSet<8> Decls;
Decls.append(UME->decls_begin(), UME->decls_end());
const bool FirstArgumentIsBase = !UME->isImplicitAccess() && UME->getBase();
Expand All @@ -5606,7 +5621,7 @@ QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
Results.push_back(ResultCandidate(FD));
else
AddOverloadCandidate(FD, DeclAccessPair::make(FD, FD->getAccess()),
Args, CandidateSet,
ArgsWithoutDependentTypes, CandidateSet,
/*SuppressUserConversions=*/false,
/*PartialOverloading=*/true);

Expand All @@ -5621,7 +5636,8 @@ QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
LookupQualifiedName(R, DC);
R.suppressDiagnostics();
SmallVector<Expr *, 12> ArgExprs(1, NakedFn);
ArgExprs.append(Args.begin(), Args.end());
ArgExprs.append(ArgsWithoutDependentTypes.begin(),
ArgsWithoutDependentTypes.end());
AddFunctionCandidates(R.asUnresolvedSet(), ArgExprs, CandidateSet,
/*ExplicitArgs=*/nullptr,
/*SuppressUserConversions=*/false,
Expand All @@ -5635,7 +5651,8 @@ QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
T = T->getPointeeType();

if (auto FP = T->getAs<FunctionProtoType>()) {
if (!TooManyArguments(FP->getNumParams(), Args.size(),
if (!TooManyArguments(FP->getNumParams(),
ArgsWithoutDependentTypes.size(),
/*PartialOverloading=*/true) ||
FP->isVariadic())
Results.push_back(ResultCandidate(FP));
Expand All @@ -5644,7 +5661,7 @@ QualType Sema::ProduceCallSignatureHelp(Scope *S, Expr *Fn,
Results.push_back(ResultCandidate(FT));
}
}
mergeCandidatesWithResults(*this, Results, CandidateSet, Loc);
mergeCandidatesWithResults(*this, Results, CandidateSet, Loc, Args.size());
QualType ParamType =
ProduceSignatureHelp(*this, S, Results, Args.size(), OpenParLoc);
return !CandidateSet.empty() ? ParamType : QualType();
Expand Down Expand Up @@ -5685,7 +5702,7 @@ QualType Sema::ProduceConstructorSignatureHelp(Scope *S, QualType Type,
}

SmallVector<ResultCandidate, 8> Results;
mergeCandidatesWithResults(*this, Results, CandidateSet, Loc);
mergeCandidatesWithResults(*this, Results, CandidateSet, Loc, Args.size());
return ProduceSignatureHelp(*this, S, Results, Args.size(), OpenParLoc);
}

Expand Down
20 changes: 20 additions & 0 deletions clang/test/CodeCompletion/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,23 @@ void test() {
// CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
// CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
}

void f(int, int, int, int);
template <typename T>
void foo(T t) {
f(t, t, t);
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:39:5 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
// CHECK-CC4: f()
// CHECK-CC4-NEXT: f(<#X#>)
// CHECK-CC4-NEXT: f(<#int i#>, int j, int k)
// CHECK-CC4-NEXT: f(<#float x#>, float y)
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:39:8 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
// CHECK-CC5-NOT: f()
// CHECK-CC5: f(int i, <#int j#>, int k)
// CHECK-CC5-NEXT: f(float x, <#float y#>)
f(5, t, t);
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:49:11 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
// CHECK-CC6-NOT: f(float x, float y)
// CHECK-CC6: f(int, int, <#int#>, int)
// CHECK-CC6-NEXT: f(int i, int j, <#int k#>)
}
11 changes: 11 additions & 0 deletions lldb/bindings/interface/SBModule.i
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ public:
static uint32_t
GetNumberAllocatedModules();

%feature("docstring", "
Removes all modules which are no longer needed by any part of LLDB from
the module cache.
This is an implementation detail exposed for testing and should not be
relied upon. Use SBDebugger::MemoryPressureDetected instead to reduce
LLDB's memory consumption during execution.
") GarbageCollectAllocatedModules;
static void
GarbageCollectAllocatedModules();

STRING_EXTENSION(SBModule)

#ifdef SWIGPYTHON
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/API/SBModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ class LLDB_API SBModule {
/// Get the number of global modules.
static uint32_t GetNumberAllocatedModules();

/// Remove any global modules which are no longer needed.
static void GarbageCollectAllocatedModules();

private:
friend class SBAddress;
friend class SBFrame;
Expand Down
3 changes: 1 addition & 2 deletions lldb/include/lldb/Symbol/CompilerType.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ class CompilerType {

/// Creating related types.
/// \{
CompilerType GetArrayElementType(ExecutionContextScope *exe_scope,
uint64_t *stride = nullptr) const;
CompilerType GetArrayElementType(ExecutionContextScope *exe_scope) const;

CompilerType GetArrayType(uint64_t size) const;

Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Symbol/TypeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class TypeSystem : public PluginInterface {
// Creating related types

virtual CompilerType
GetArrayElementType(lldb::opaque_compiler_type_t type, uint64_t *stride,
GetArrayElementType(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) = 0;

virtual CompilerType GetArrayType(lldb::opaque_compiler_type_t type,
Expand Down
26 changes: 11 additions & 15 deletions lldb/include/lldb/Utility/Scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ class Scalar {
e_void = 0,
e_sint,
e_uint,
e_slong,
e_ulong,
e_slonglong,
e_ulonglong,
e_sint128,
e_uint128,
e_sint256,
e_uint256,
e_sint512,
e_uint512,
e_float,
e_double,
e_long_double
Expand All @@ -68,16 +58,16 @@ class Scalar {
: m_type(e_uint), m_integer(sizeof(v) * 8, uint64_t(v), false),
m_float(0.0f) {}
Scalar(long v)
: m_type(e_slong), m_integer(sizeof(v) * 8, uint64_t(v), true),
: m_type(e_sint), m_integer(sizeof(v) * 8, uint64_t(v), true),
m_float(0.0f) {}
Scalar(unsigned long v)
: m_type(e_ulong), m_integer(sizeof(v) * 8, uint64_t(v), false),
: m_type(e_uint), m_integer(sizeof(v) * 8, uint64_t(v), false),
m_float(0.0f) {}
Scalar(long long v)
: m_type(e_slonglong), m_integer(sizeof(v) * 8, uint64_t(v), true),
: m_type(e_sint), m_integer(sizeof(v) * 8, uint64_t(v), true),
m_float(0.0f) {}
Scalar(unsigned long long v)
: m_type(e_ulonglong), m_integer(sizeof(v) * 8, uint64_t(v), false),
: m_type(e_uint), m_integer(sizeof(v) * 8, uint64_t(v), false),
m_float(0.0f) {}
Scalar(float v) : m_type(e_float), m_float(v) {}
Scalar(double v) : m_type(e_double), m_float(v) {}
Expand Down Expand Up @@ -131,7 +121,8 @@ class Scalar {
/// Convert to an integer with \p bits and the given signedness.
void TruncOrExtendTo(uint16_t bits, bool sign);

bool Promote(Scalar::Type type);
bool IntegralPromote(uint16_t bits, bool sign);
bool FloatPromote(Scalar::Type type);

bool MakeSigned();

Expand Down Expand Up @@ -264,6 +255,11 @@ class Scalar {

template <typename T> T GetAs(T fail_value) const;

static Type PromoteToMaxType(Scalar &lhs, Scalar &rhs);

using IntPromotionKey = std::pair<unsigned, bool>;
IntPromotionKey GetIntKey() const;

private:
friend const Scalar operator+(const Scalar &lhs, const Scalar &rhs);
friend const Scalar operator-(Scalar lhs, Scalar rhs);
Expand Down
Loading

0 comments on commit 35fe0c3

Please sign in to comment.