Skip to content

Commit ce1ce2a

Browse files
committed
Merge remote-tracking branch 'upstream/release/10.x' into rustc/10.0-2020-05-05
2 parents 99580e0 + f79cd71 commit ce1ce2a

File tree

52 files changed

+1898
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1898
-196
lines changed

clang/include/clang/AST/DeclBase.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,14 +856,15 @@ class alignas(8) Decl {
856856
return getParentFunctionOrMethod() == nullptr;
857857
}
858858

859-
/// Returns true if this declaration lexically is inside a function.
860-
/// It recognizes non-defining declarations as well as members of local
861-
/// classes:
859+
/// Returns true if this declaration is lexically inside a function or inside
860+
/// a variable initializer. It recognizes non-defining declarations as well
861+
/// as members of local classes:
862862
/// \code
863863
/// void foo() { void bar(); }
864864
/// void foo2() { class ABC { void bar(); }; }
865+
/// inline int x = [](){ return 0; };
865866
/// \endcode
866-
bool isLexicallyWithinFunctionOrMethod() const;
867+
bool isInLocalScope() const;
867868

868869
/// If this decl is defined inside a function/method/block it returns
869870
/// the corresponding DeclContext, otherwise it returns null.

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def XRayLogArgs : InheritableAttr {
685685

686686
def PatchableFunctionEntry
687687
: InheritableAttr,
688-
TargetSpecificAttr<TargetArch<["aarch64", "x86", "x86_64"]>> {
688+
TargetSpecificAttr<TargetArch<["aarch64", "aarch64_be", "x86", "x86_64"]>> {
689689
let Spellings = [GCC<"patchable_function_entry">];
690690
let Subjects = SubjectList<[Function, ObjCMethod]>;
691691
let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>];

clang/lib/AST/DeclBase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,16 @@ void Decl::setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
332332
}
333333
}
334334

335-
bool Decl::isLexicallyWithinFunctionOrMethod() const {
335+
bool Decl::isInLocalScope() const {
336336
const DeclContext *LDC = getLexicalDeclContext();
337337
while (true) {
338338
if (LDC->isFunctionOrMethod())
339339
return true;
340340
if (!isa<TagDecl>(LDC))
341341
return false;
342+
if (const auto *CRD = dyn_cast<CXXRecordDecl>(LDC))
343+
if (CRD->isLambda())
344+
return true;
342345
LDC = LDC->getLexicalParent();
343346
}
344347
return false;

clang/lib/AST/ExprConstant.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8593,6 +8593,10 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
85938593
static bool EvaluateArrayNewInitList(EvalInfo &Info, LValue &This,
85948594
APValue &Result, const InitListExpr *ILE,
85958595
QualType AllocType);
8596+
static bool EvaluateArrayNewConstructExpr(EvalInfo &Info, LValue &This,
8597+
APValue &Result,
8598+
const CXXConstructExpr *CCE,
8599+
QualType AllocType);
85968600

85978601
bool PointerExprEvaluator::VisitCXXNewExpr(const CXXNewExpr *E) {
85988602
if (!Info.getLangOpts().CPlusPlus2a)
@@ -8642,6 +8646,7 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const CXXNewExpr *E) {
86428646

86438647
const Expr *Init = E->getInitializer();
86448648
const InitListExpr *ResizedArrayILE = nullptr;
8649+
const CXXConstructExpr *ResizedArrayCCE = nullptr;
86458650

86468651
QualType AllocType = E->getAllocatedType();
86478652
if (Optional<const Expr*> ArraySize = E->getArraySize()) {
@@ -8685,7 +8690,7 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const CXXNewExpr *E) {
86858690
// -- the new-initializer is a braced-init-list and the number of
86868691
// array elements for which initializers are provided [...]
86878692
// exceeds the number of elements to initialize
8688-
if (Init) {
8693+
if (Init && !isa<CXXConstructExpr>(Init)) {
86898694
auto *CAT = Info.Ctx.getAsConstantArrayType(Init->getType());
86908695
assert(CAT && "unexpected type for array initializer");
86918696

@@ -8708,6 +8713,8 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const CXXNewExpr *E) {
87088713
// special handling for this case when we initialize.
87098714
if (InitBound != AllocBound)
87108715
ResizedArrayILE = cast<InitListExpr>(Init);
8716+
} else if (Init) {
8717+
ResizedArrayCCE = cast<CXXConstructExpr>(Init);
87118718
}
87128719

87138720
AllocType = Info.Ctx.getConstantArrayType(AllocType, ArrayBound, nullptr,
@@ -8772,6 +8779,10 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const CXXNewExpr *E) {
87728779
if (!EvaluateArrayNewInitList(Info, Result, *Val, ResizedArrayILE,
87738780
AllocType))
87748781
return false;
8782+
} else if (ResizedArrayCCE) {
8783+
if (!EvaluateArrayNewConstructExpr(Info, Result, *Val, ResizedArrayCCE,
8784+
AllocType))
8785+
return false;
87758786
} else if (Init) {
87768787
if (!EvaluateInPlace(*Val, Info, Result, Init))
87778788
return false;
@@ -9597,6 +9608,16 @@ static bool EvaluateArrayNewInitList(EvalInfo &Info, LValue &This,
95979608
.VisitInitListExpr(ILE, AllocType);
95989609
}
95999610

9611+
static bool EvaluateArrayNewConstructExpr(EvalInfo &Info, LValue &This,
9612+
APValue &Result,
9613+
const CXXConstructExpr *CCE,
9614+
QualType AllocType) {
9615+
assert(CCE->isRValue() && CCE->getType()->isArrayType() &&
9616+
"not an array rvalue");
9617+
return ArrayExprEvaluator(Info, This, Result)
9618+
.VisitCXXConstructExpr(CCE, This, &Result, AllocType);
9619+
}
9620+
96009621
// Return true iff the given array filler may depend on the element index.
96019622
static bool MaybeElementDependentArrayFiller(const Expr *FillerExpr) {
96029623
// For now, just whitelist non-class value-initialization and initialization

clang/lib/AST/RawCommentList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ std::string RawComment::getFormattedText(const SourceManager &SourceMgr,
430430
};
431431

432432
auto DropTrailingNewLines = [](std::string &Str) {
433-
while (Str.back() == '\n')
433+
while (!Str.empty() && Str.back() == '\n')
434434
Str.pop_back();
435435
};
436436

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,9 +1847,16 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
18471847
else if (const auto *SA = FD->getAttr<SectionAttr>())
18481848
F->setSection(SA->getName());
18491849

1850+
// If we plan on emitting this inline builtin, we can't treat it as a builtin.
18501851
if (FD->isInlineBuiltinDeclaration()) {
1851-
F->addAttribute(llvm::AttributeList::FunctionIndex,
1852-
llvm::Attribute::NoBuiltin);
1852+
const FunctionDecl *FDBody;
1853+
bool HasBody = FD->hasBody(FDBody);
1854+
(void)HasBody;
1855+
assert(HasBody && "Inline builtin declarations should always have an "
1856+
"available body!");
1857+
if (shouldEmitFunction(FDBody))
1858+
F->addAttribute(llvm::AttributeList::FunctionIndex,
1859+
llvm::Attribute::NoBuiltin);
18531860
}
18541861

18551862
if (FD->isReplaceableGlobalAllocationFunction()) {

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
11461146
addExportedSymbol(CmdArgs, "___gcov_flush");
11471147
addExportedSymbol(CmdArgs, "_flush_fn_list");
11481148
addExportedSymbol(CmdArgs, "_writeout_fn_list");
1149+
addExportedSymbol(CmdArgs, "_reset_fn_list");
11491150
} else {
11501151
addExportedSymbol(CmdArgs, "___llvm_profile_filename");
11511152
addExportedSymbol(CmdArgs, "___llvm_profile_raw_version");

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,10 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
21762176
Next = Next->Next;
21772177
continue;
21782178
}
2179+
if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
2180+
Next = Next->MatchingParen;
2181+
continue;
2182+
}
21792183

21802184
break;
21812185
}
@@ -2705,20 +2709,40 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
27052709
tok::l_square));
27062710
if (Right.is(tok::star) && Left.is(tok::l_paren))
27072711
return false;
2708-
if (Right.isOneOf(tok::star, tok::amp, tok::ampamp) &&
2709-
(Left.is(tok::identifier) || Left.isSimpleTypeSpecifier()) &&
2710-
// Space between the type and the * in:
2711-
// operator void*()
2712-
// operator char*()
2713-
// operator /*comment*/ const char*()
2714-
// operator volatile /*comment*/ char*()
2715-
// operator Foo*()
2716-
// dependent on PointerAlignment style.
2717-
Left.Previous &&
2718-
(Left.Previous->endsSequence(tok::kw_operator) ||
2719-
Left.Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
2720-
Left.Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
2721-
return (Style.PointerAlignment != FormatStyle::PAS_Left);
2712+
if (Right.is(tok::star) && Left.is(tok::star))
2713+
return false;
2714+
if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) {
2715+
const FormatToken *Previous = &Left;
2716+
while (Previous && !Previous->is(tok::kw_operator)) {
2717+
if (Previous->is(tok::identifier) || Previous->isSimpleTypeSpecifier()) {
2718+
Previous = Previous->getPreviousNonComment();
2719+
continue;
2720+
}
2721+
if (Previous->is(TT_TemplateCloser) && Previous->MatchingParen) {
2722+
Previous = Previous->MatchingParen->getPreviousNonComment();
2723+
continue;
2724+
}
2725+
if (Previous->is(tok::coloncolon)) {
2726+
Previous = Previous->getPreviousNonComment();
2727+
continue;
2728+
}
2729+
break;
2730+
}
2731+
// Space between the type and the * in:
2732+
// operator void*()
2733+
// operator char*()
2734+
// operator /*comment*/ const char*()
2735+
// operator volatile /*comment*/ char*()
2736+
// operator Foo*()
2737+
// operator C<T>*()
2738+
// operator std::Foo*()
2739+
// operator C<T>::D<U>*()
2740+
// dependent on PointerAlignment style.
2741+
if (Previous && (Previous->endsSequence(tok::kw_operator) ||
2742+
Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
2743+
Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
2744+
return (Style.PointerAlignment != FormatStyle::PAS_Left);
2745+
}
27222746
const auto SpaceRequiredForArrayInitializerLSquare =
27232747
[](const FormatToken &LSquareTok, const FormatStyle &Style) {
27242748
return Style.SpacesInContainerLiterals ||

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
23432343
UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
23442344
} else if (Expr *Arg = OldParm->getDefaultArg()) {
23452345
FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext());
2346-
if (OwningFunc->isLexicallyWithinFunctionOrMethod()) {
2346+
if (OwningFunc->isInLocalScope()) {
23472347
// Instantiate default arguments for methods of local classes (DR1484)
23482348
// and non-defining declarations.
23492349
Sema::ContextRAII SavedContext(*this, OwningFunc);

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4367,7 +4367,7 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New,
43674367
EPI.ExceptionSpec.Type != EST_None &&
43684368
EPI.ExceptionSpec.Type != EST_DynamicNone &&
43694369
EPI.ExceptionSpec.Type != EST_BasicNoexcept &&
4370-
!Tmpl->isLexicallyWithinFunctionOrMethod()) {
4370+
!Tmpl->isInLocalScope()) {
43714371
FunctionDecl *ExceptionSpecTemplate = Tmpl;
43724372
if (EPI.ExceptionSpec.Type == EST_Uninstantiated)
43734373
ExceptionSpecTemplate = EPI.ExceptionSpec.SourceTemplate;

clang/lib/Sema/TreeTransform.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11828,19 +11828,6 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
1182811828

1182911829
LSI->CallOperator = NewCallOperator;
1183011830

11831-
for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11832-
I != NumParams; ++I) {
11833-
auto *P = NewCallOperator->getParamDecl(I);
11834-
if (P->hasUninstantiatedDefaultArg()) {
11835-
EnterExpressionEvaluationContext Eval(
11836-
getSema(),
11837-
Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
11838-
ExprResult R = getDerived().TransformExpr(
11839-
E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11840-
P->setDefaultArg(R.get());
11841-
}
11842-
}
11843-
1184411831
getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
1184511832
getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
1184611833

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - %s | FileCheck %s
2+
//
3+
// Verifies that clang doesn't mark an inline builtin definition as `nobuiltin`
4+
// if the builtin isn't emittable.
5+
6+
typedef unsigned long size_t;
7+
8+
// always_inline is used so clang will emit this body. Otherwise, we need >=
9+
// -O1.
10+
#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) \
11+
__attribute__((gnu_inline))
12+
13+
AVAILABLE_EXTERNALLY void *memcpy(void *a, const void *b, size_t c) {
14+
return __builtin_memcpy(a, b, c);
15+
}
16+
17+
// CHECK-LABEL: define void @foo
18+
void foo(void *a, const void *b, size_t c) {
19+
// Clang will always _emit_ this as memcpy. LLVM turns it into @llvm.memcpy
20+
// later on if optimizations are enabled.
21+
// CHECK: call i8* @memcpy
22+
memcpy(a, b, c);
23+
}
24+
25+
// CHECK-NOT: nobuiltin
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++11 -S -emit-llvm -o - %s | FileCheck %s
2+
//
3+
// Regression test for the issue reported at
4+
// https://reviews.llvm.org/D78162#1986104
5+
6+
typedef unsigned long size_t;
7+
8+
extern "C" __inline__ __attribute__((__gnu_inline__)) void *memcpy(void *a, const void *b, unsigned c) {
9+
return __builtin_memcpy(a, b, c);
10+
}
11+
void *memcpy(void *, const void *, unsigned);
12+
13+
// CHECK-LABEL: define void @_Z1av
14+
void a() { (void)memcpy; }
15+
16+
// CHECK-NOT: nobuiltin

clang/test/Sema/patchable-function-entry-attr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -verify=silence %s
2+
// RUN: %clang_cc1 -triple aarch64_be -fsyntax-only -verify=silence %s
23
// RUN: %clang_cc1 -triple i386 -fsyntax-only -verify=silence %s
34
// RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify=silence %s
45
// RUN: %clang_cc1 -triple ppc64le -fsyntax-only -verify %s

clang/test/SemaCXX/constant-expression-cxx2a.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,3 +1279,23 @@ namespace value_dependent_init {
12791279
A a = T();
12801280
}
12811281
}
1282+
1283+
namespace PR45350 {
1284+
int q;
1285+
struct V { int n; int *p = &n; constexpr ~V() { *p = *p * 10 + n; }};
1286+
constexpr int f(int n) {
1287+
int k = 0;
1288+
V *p = new V[n];
1289+
for (int i = 0; i != n; ++i) {
1290+
if (p[i].p != &p[i].n) return -1;
1291+
p[i].n = i;
1292+
p[i].p = &k;
1293+
}
1294+
delete[] p;
1295+
return k;
1296+
}
1297+
// [expr.delete]p6:
1298+
// In the case of an array, the elements will be destroyed in order of
1299+
// decreasing address
1300+
static_assert(f(6) == 543210);
1301+
}

clang/test/SemaCXX/vartemplate-lambda.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ template <class> auto fn0 = [] {};
44
template <typename> void foo0() { fn0<char>(); }
55

66
template<typename T> auto fn1 = [](auto a) { return a + T(1); };
7-
template<typename T> auto v1 = [](int a = T(1)) { return a; }();
7+
template<typename T> auto v1 = [](int a = T()) { return a; }();
8+
// expected-error@-1{{cannot initialize a parameter of type 'int' with an rvalue of type 'int *'}}
9+
// expected-error@-2{{no matching function for call}}
10+
// expected-note@-3{{passing argument to parameter 'a' here}}
11+
// expected-note@-4{{candidate function not viable}}
12+
// expected-note@-5{{conversion candidate of type 'int (*)(int)'}}
813

914
struct S {
1015
template<class T>
@@ -16,6 +21,7 @@ int foo2() {
1621
X a = 0x61;
1722
fn1<char>(a);
1823
(void)v1<int>;
24+
(void)v1<int *>; // expected-note{{in instantiation of variable template specialization 'v1' requested here}}
1925
(void)S::t<int>; // expected-note{{in instantiation of static data member 'S::t<int>' requested here}}
2026
return 0;
2127
}

clang/test/SemaTemplate/instantiate-local-class.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,16 @@ namespace anon_union_default_member_init {
486486
}
487487
void g() { f<int>(); }
488488
}
489+
490+
namespace PR45000 {
491+
template <typename T>
492+
void f(int x = [](T x = nullptr) -> int { return x; }());
493+
// expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'}}
494+
// expected-note@-2 {{passing argument to parameter 'x' here}}
495+
// expected-error@-3 {{no matching function for call}}
496+
// expected-note@-4 {{candidate function not viable: requires single argument 'x', but no arguments were provided}}
497+
// expected-note@-5 {{conversion candidate of type 'auto (*)(int) -> int'}}
498+
499+
void g() { f<int>(); }
500+
// expected-note@-1 {{in instantiation of default function argument expression for 'f<int>' required here}}
501+
}

clang/tools/libclang/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ set(LIBS
4444
clangSema
4545
clangSerialization
4646
clangTooling
47-
LLVMSupport
4847
)
4948

5049
if (CLANG_ENABLE_ARCMT)

0 commit comments

Comments
 (0)