aboutsummaryrefslogtreecommitdiffstats
path: root/dist
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2018-01-04 12:21:15 +0100
committerIvan Donchevskii <ivan.donchevskii@qt.io>2018-01-12 09:27:43 +0000
commit7a2e1e29cb38b339780938a3e582110e566b5631 (patch)
treedabc39ff39ccbbeb883c8b4b8904f130d1902350 /dist
parent8cecd73d2bf41f82d455bf3c2b19a8dd512ebcf3 (diff)
Clang: update clang patches
These patches should be applied on top of llvm/clang 5.0 List is taken from https://wiki.qt.io/Qt_Creator_Clang_Code_Model Change-Id: Icd927ae12fc1ef8181a45e2d800efe3007c616ae Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'dist')
-rw-r--r--dist/clang/patches/D35355_Fix-templated-type-alias-completion-when-using-global-completion-cache.patch2
-rw-r--r--dist/clang/patches/D38615_Only-mark-CXCursors-for-explicit-attributes-with-a-type.patch34
-rw-r--r--dist/clang/patches/D39957_Honor-TerseOutput-for-constructors.patch266
-rw-r--r--dist/clang/patches/D40027_Fix-cursors-for-in-class-initializer-of-field-declarations.patch33
-rw-r--r--dist/clang/patches/D40072_Support-querying-whether-a-declaration-is-invalid.patch153
-rw-r--r--dist/clang/patches/D40561_Fix-cursors-for-functions-with-trailing-return-type.patch79
-rw-r--r--dist/clang/patches/D40643_Add-function-to-get-the-buffer-for-a-file.patch64
-rw-r--r--dist/clang/patches/D40746_Correctly-handle-line-table-entries-without-filenames-during-AST-serialization.patch47
-rw-r--r--dist/clang/patches/D40841_Fix-a-crash-on-C++17-AST-for-non-trivial-construction-into-a-trivial-brace-initialize.patch117
-rw-r--r--dist/clang/patches/D41016_Fix-crash-in-unused-lambda-capture-warning-for-VLAs.patch37
-rw-r--r--dist/clang/patches/D41688_Fix-crash-on-code-completion-in-comment-in-included-file.patch47
-rw-r--r--dist/clang/patches/QTCREATORBUG-15157_Link-with-clazy_clang.patch6
-rw-r--r--dist/clang/patches/README.md78
-rw-r--r--dist/clang/patches/rL310905_Avoid-PointerIntPair-of-constexpr-EvalInfo-structs.patch88
14 files changed, 947 insertions, 104 deletions
diff --git a/dist/clang/patches/D35355_Fix-templated-type-alias-completion-when-using-global-completion-cache.patch b/dist/clang/patches/D35355_Fix-templated-type-alias-completion-when-using-global-completion-cache.patch
index a02e0da444..df57bedff8 100644
--- a/dist/clang/patches/D35355_Fix-templated-type-alias-completion-when-using-global-completion-cache.patch
+++ b/dist/clang/patches/D35355_Fix-templated-type-alias-completion-when-using-global-completion-cache.patch
@@ -25,7 +25,7 @@ index 944cd775d5..6aba10e5c7 100644
- return nullptr;
+ auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd,
+ prefixAttrs);
-+ if (!usingDeclPtr)
++ if (!usingDeclPtr || !usingDeclPtr.get().isSingleDecl())
+ return nullptr;
+ return usingDeclPtr.get().getSingleDecl();
}
diff --git a/dist/clang/patches/D38615_Only-mark-CXCursors-for-explicit-attributes-with-a-type.patch b/dist/clang/patches/D38615_Only-mark-CXCursors-for-explicit-attributes-with-a-type.patch
new file mode 100644
index 0000000000..3357f874aa
--- /dev/null
+++ b/dist/clang/patches/D38615_Only-mark-CXCursors-for-explicit-attributes-with-a-type.patch
@@ -0,0 +1,34 @@
+--- /dev/null
++++ b/tools/clang/test/Index/annotate-tokens-unexposed.cpp
+@@ -0,0 +1,20 @@
++// RUN: c-index-test -test-annotate-tokens=%s:1:1:16:1 %s -target x86_64-pc-windows-msvc | FileCheck %s
++class Foo
++{
++public:
++ void step(int v);
++ Foo();
++};
++
++void bar()
++{
++ // Introduce a MSInheritanceAttr node on the CXXRecordDecl for Foo. The
++ // existence of this attribute should not mark all cursors for tokens in
++ // Foo as UnexposedAttr.
++ &Foo::step;
++}
++
++Foo::Foo()
++{}
++
++// CHECK-NOT: UnexposedAttr=
+--- a/tools/clang/tools/libclang/CIndex.cpp
++++ b/tools/clang/tools/libclang/CIndex.cpp
+@@ -1772,7 +1772,7 @@
+
+ bool CursorVisitor::VisitAttributes(Decl *D) {
+ for (const auto *I : D->attrs())
+- if (Visit(MakeCXCursor(I, D, TU)))
++ if (!I->isImplicit() && Visit(MakeCXCursor(I, D, TU)))
+ return true;
+
+ return false;
diff --git a/dist/clang/patches/D39957_Honor-TerseOutput-for-constructors.patch b/dist/clang/patches/D39957_Honor-TerseOutput-for-constructors.patch
new file mode 100644
index 0000000000..a2d096cf16
--- /dev/null
+++ b/dist/clang/patches/D39957_Honor-TerseOutput-for-constructors.patch
@@ -0,0 +1,266 @@
+--- a/tools/clang/lib/AST/DeclPrinter.cpp
++++ b/tools/clang/lib/AST/DeclPrinter.cpp
+@@ -608,66 +608,69 @@
+ }
+
+ if (CDecl) {
+- bool HasInitializerList = false;
+- for (const auto *BMInitializer : CDecl->inits()) {
+- if (BMInitializer->isInClassMemberInitializer())
+- continue;
+-
+- if (!HasInitializerList) {
+- Proto += " : ";
+- Out << Proto;
+- Proto.clear();
+- HasInitializerList = true;
+- } else
+- Out << ", ";
++ if (!Policy.TerseOutput) {
++ bool HasInitializerList = false;
++ for (const auto *BMInitializer : CDecl->inits()) {
++ if (BMInitializer->isInClassMemberInitializer())
++ continue;
+
+- if (BMInitializer->isAnyMemberInitializer()) {
+- FieldDecl *FD = BMInitializer->getAnyMember();
+- Out << *FD;
+- } else {
+- Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
+- }
+-
+- Out << "(";
+- if (!BMInitializer->getInit()) {
+- // Nothing to print
+- } else {
+- Expr *Init = BMInitializer->getInit();
+- if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
+- Init = Tmp->getSubExpr();
+-
+- Init = Init->IgnoreParens();
+-
+- Expr *SimpleInit = nullptr;
+- Expr **Args = nullptr;
+- unsigned NumArgs = 0;
+- if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
+- Args = ParenList->getExprs();
+- NumArgs = ParenList->getNumExprs();
+- } else if (CXXConstructExpr *Construct
+- = dyn_cast<CXXConstructExpr>(Init)) {
+- Args = Construct->getArgs();
+- NumArgs = Construct->getNumArgs();
++ if (!HasInitializerList) {
++ Proto += " : ";
++ Out << Proto;
++ Proto.clear();
++ HasInitializerList = true;
+ } else
+- SimpleInit = Init;
+-
+- if (SimpleInit)
+- SimpleInit->printPretty(Out, nullptr, Policy, Indentation);
+- else {
+- for (unsigned I = 0; I != NumArgs; ++I) {
+- assert(Args[I] != nullptr && "Expected non-null Expr");
+- if (isa<CXXDefaultArgExpr>(Args[I]))
+- break;
+-
+- if (I)
+- Out << ", ";
+- Args[I]->printPretty(Out, nullptr, Policy, Indentation);
++ Out << ", ";
++
++ if (BMInitializer->isAnyMemberInitializer()) {
++ FieldDecl *FD = BMInitializer->getAnyMember();
++ Out << *FD;
++ } else {
++ Out << QualType(BMInitializer->getBaseClass(), 0)
++ .getAsString(Policy);
++ }
++
++ Out << "(";
++ if (!BMInitializer->getInit()) {
++ // Nothing to print
++ } else {
++ Expr *Init = BMInitializer->getInit();
++ if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
++ Init = Tmp->getSubExpr();
++
++ Init = Init->IgnoreParens();
++
++ Expr *SimpleInit = nullptr;
++ Expr **Args = nullptr;
++ unsigned NumArgs = 0;
++ if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
++ Args = ParenList->getExprs();
++ NumArgs = ParenList->getNumExprs();
++ } else if (CXXConstructExpr *Construct =
++ dyn_cast<CXXConstructExpr>(Init)) {
++ Args = Construct->getArgs();
++ NumArgs = Construct->getNumArgs();
++ } else
++ SimpleInit = Init;
++
++ if (SimpleInit)
++ SimpleInit->printPretty(Out, nullptr, Policy, Indentation);
++ else {
++ for (unsigned I = 0; I != NumArgs; ++I) {
++ assert(Args[I] != nullptr && "Expected non-null Expr");
++ if (isa<CXXDefaultArgExpr>(Args[I]))
++ break;
++
++ if (I)
++ Out << ", ";
++ Args[I]->printPretty(Out, nullptr, Policy, Indentation);
++ }
+ }
+ }
++ Out << ")";
++ if (BMInitializer->isPackExpansion())
++ Out << "...";
+ }
+- Out << ")";
+- if (BMInitializer->isPackExpansion())
+- Out << "...";
+ }
+ } else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
+ if (FT && FT->hasTrailingReturn()) {
+@@ -712,7 +715,7 @@
+ if (D->getBody())
+ D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation);
+ } else {
+- if (isa<CXXConstructorDecl>(*D))
++ if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
+ Out << " {}";
+ }
+ }
+--- a/tools/clang/test/Index/comment-cplus-decls.cpp
++++ b/tools/clang/test/Index/comment-cplus-decls.cpp
+@@ -46,7 +46,7 @@
+ data* reserved;
+ };
+ // CHECK: <Declaration>class Test {}</Declaration>
+-// CHECK: <Declaration>Test() : reserved(new Test::data()) {}</Declaration>
++// CHECK: <Declaration>Test()</Declaration>
+ // CHECK: <Declaration>unsigned int getID() const</Declaration>
+ // CHECK: <Declaration>~Test(){{( noexcept)?}}</Declaration>
+ // CHECK: <Declaration>Test::data *reserved</Declaration>
+--- a/tools/clang/unittests/AST/DeclPrinterTest.cpp
++++ b/tools/clang/unittests/AST/DeclPrinterTest.cpp
+@@ -31,18 +31,25 @@
+
+ namespace {
+
+-void PrintDecl(raw_ostream &Out, const ASTContext *Context, const Decl *D) {
++using PrintingPolicyModifier = void (*)(PrintingPolicy &policy);
++
++void PrintDecl(raw_ostream &Out, const ASTContext *Context, const Decl *D,
++ PrintingPolicyModifier PolicyModifier) {
+ PrintingPolicy Policy = Context->getPrintingPolicy();
+ Policy.TerseOutput = true;
++ if (PolicyModifier)
++ PolicyModifier(Policy);
+ D->print(Out, Policy, /*Indentation*/ 0, /*PrintInstantiation*/ false);
+ }
+
+ class PrintMatch : public MatchFinder::MatchCallback {
+ SmallString<1024> Printed;
+ unsigned NumFoundDecls;
++ PrintingPolicyModifier PolicyModifier;
+
+ public:
+- PrintMatch() : NumFoundDecls(0) {}
++ PrintMatch(PrintingPolicyModifier PolicyModifier)
++ : NumFoundDecls(0), PolicyModifier(PolicyModifier) {}
+
+ void run(const MatchFinder::MatchResult &Result) override {
+ const Decl *D = Result.Nodes.getNodeAs<Decl>("id");
+@@ -53,7 +60,7 @@
+ return;
+
+ llvm::raw_svector_ostream Out(Printed);
+- PrintDecl(Out, Result.Context, D);
++ PrintDecl(Out, Result.Context, D, PolicyModifier);
+ }
+
+ StringRef getPrinted() const {
+@@ -65,13 +72,12 @@
+ }
+ };
+
+-::testing::AssertionResult PrintedDeclMatches(
+- StringRef Code,
+- const std::vector<std::string> &Args,
+- const DeclarationMatcher &NodeMatch,
+- StringRef ExpectedPrinted,
+- StringRef FileName) {
+- PrintMatch Printer;
++::testing::AssertionResult
++PrintedDeclMatches(StringRef Code, const std::vector<std::string> &Args,
++ const DeclarationMatcher &NodeMatch,
++ StringRef ExpectedPrinted, StringRef FileName,
++ PrintingPolicyModifier PolicyModifier = nullptr) {
++ PrintMatch Printer(PolicyModifier);
+ MatchFinder Finder;
+ Finder.addMatcher(NodeMatch, &Printer);
+ std::unique_ptr<FrontendActionFactory> Factory(
+@@ -109,16 +115,17 @@
+ "input.cc");
+ }
+
+-::testing::AssertionResult PrintedDeclCXX98Matches(
+- StringRef Code,
+- const DeclarationMatcher &NodeMatch,
+- StringRef ExpectedPrinted) {
++::testing::AssertionResult
++PrintedDeclCXX98Matches(StringRef Code, const DeclarationMatcher &NodeMatch,
++ StringRef ExpectedPrinted,
++ PrintingPolicyModifier PolicyModifier = nullptr) {
+ std::vector<std::string> Args(1, "-std=c++98");
+ return PrintedDeclMatches(Code,
+ Args,
+ NodeMatch,
+ ExpectedPrinted,
+- "input.cc");
++ "input.cc",
++ PolicyModifier);
+ }
+
+ ::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code,
+@@ -478,6 +485,27 @@
+ "A(const A &a, int = 0)"));
+ }
+
++TEST(DeclPrinter, TestCXXConstructorDeclWithMemberInitializer) {
++ ASSERT_TRUE(PrintedDeclCXX98Matches(
++ "struct A {"
++ " int m;"
++ " A() : m(2) {}"
++ "};",
++ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
++ "A()"));
++}
++
++TEST(DeclPrinter, TestCXXConstructorDeclWithMemberInitializer_NoTerseOutput) {
++ ASSERT_TRUE(PrintedDeclCXX98Matches(
++ "struct A {"
++ " int m;"
++ " A() : m(2) {}"
++ "};",
++ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
++ "A() : m(2) {\n}\n",
++ [](PrintingPolicy &Policy){ Policy.TerseOutput = false; }));
++}
++
+ TEST(DeclPrinter, TestCXXConstructorDecl5) {
+ ASSERT_TRUE(PrintedDeclCXX11Matches(
+ "struct A {"
+@@ -540,7 +568,7 @@
+ " A(T&&... ts) : T(ts)... {}"
+ "};",
+ cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
+- "A<T...>(T &&...ts) : T(ts)... {}"));
++ "A<T...>(T &&...ts)"));
+ }
+
+ TEST(DeclPrinter, TestCXXDestructorDecl1) {
diff --git a/dist/clang/patches/D40027_Fix-cursors-for-in-class-initializer-of-field-declarations.patch b/dist/clang/patches/D40027_Fix-cursors-for-in-class-initializer-of-field-declarations.patch
new file mode 100644
index 0000000000..0e11237a5d
--- /dev/null
+++ b/dist/clang/patches/D40027_Fix-cursors-for-in-class-initializer-of-field-declarations.patch
@@ -0,0 +1,33 @@
+--- a/tools/clang/test/Index/get-cursor.cpp
++++ b/tools/clang/test/Index/get-cursor.cpp
+@@ -152,6 +152,11 @@
+ void f_dynamic_noexcept() throw(int);
+ void f_dynamic_noexcept_any() throw(...);
+
++enum EnumType { Enumerator };
++struct Z {
++ EnumType e = Enumerator;
++};
++
+ // RUN: c-index-test -cursor-at=%s:6:4 %s | FileCheck -check-prefix=CHECK-COMPLETION-1 %s
+ // CHECK-COMPLETION-1: CXXConstructor=X:6:3
+ // CHECK-COMPLETION-1-NEXT: Completion string: {TypedText X}{LeftParen (}{Placeholder int}{Comma , }{Placeholder int}{RightParen )}
+@@ -275,3 +280,6 @@
+ // CHECK-FORRANGE: 141:18 DeclRefExpr=coll:140:20 Extent=[141:18 - 141:22] Spelling=coll ([141:18 - 141:22])
+ // CHECK-FORRANGE: 142:11 DeclRefExpr=lv:141:13 Extent=[142:11 - 142:13] Spelling=lv ([142:11 - 142:13])
+
++// RUN: c-index-test -cursor-at=%s:157:18 -std=c++11 %s | FileCheck -check-prefix=CHECK-INCLASSINITIALIZER %s
++// CHECK-INCLASSINITIALIZER: 157:18 DeclRefExpr=Enumerator:155:17 Extent=[157:18 - 157:28] Spelling=Enumerator ([157:18 - 157:28])
++
+--- a/tools/clang/tools/libclang/CIndex.cpp
++++ b/tools/clang/tools/libclang/CIndex.cpp
+@@ -877,6 +877,9 @@
+ if (Expr *BitWidth = D->getBitWidth())
+ return Visit(MakeCXCursor(BitWidth, StmtParent, TU, RegionOfInterest));
+
++ if (Expr *Init = D->getInClassInitializer())
++ return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest));
++
+ return false;
+ }
+
diff --git a/dist/clang/patches/D40072_Support-querying-whether-a-declaration-is-invalid.patch b/dist/clang/patches/D40072_Support-querying-whether-a-declaration-is-invalid.patch
new file mode 100644
index 0000000000..62cb295454
--- /dev/null
+++ b/dist/clang/patches/D40072_Support-querying-whether-a-declaration-is-invalid.patch
@@ -0,0 +1,153 @@
+--- a/tools/clang/include/clang-c/Index.h
++++ b/tools/clang/include/clang-c/Index.h
+@@ -32,7 +32,7 @@
+ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
+ */
+ #define CINDEX_VERSION_MAJOR 0
+-#define CINDEX_VERSION_MINOR 43
++#define CINDEX_VERSION_MINOR 46
+
+ #define CINDEX_VERSION_ENCODE(major, minor) ( \
+ ((major) * 10000) \
+@@ -2641,6 +2641,16 @@ CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
+ */
+ CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
+
++/**
++ * \brief Determine whether the given declaration is invalid.
++ *
++ * A declaration is invalid if it could not be parsed successfully.
++ *
++ * \returns non-zero if the cursor represents a declaration and it is
++ * invalid, otherwise NULL.
++ */
++CINDEX_LINKAGE unsigned clang_isInvalidDeclaration(CXCursor);
++
+ /**
+ * \brief Determine whether the given cursor kind represents a simple
+ * reference.
+diff --git a/test/Index/opencl-types.cl b/test/Index/opencl-types.cl
+index fe0042aa20..d71893a220 100644
+--- a/tools/clang/test/Index/opencl-types.cl
++++ b/tools/clang/test/Index/opencl-types.cl
+@@ -16,11 +16,11 @@ void kernel testFloatTypes() {
+ double4 vectorDouble;
+ }
+
+-// CHECK: VarDecl=scalarHalf:11:8 (Definition) [type=half] [typekind=Half] [isPOD=1]
++// CHECK: VarDecl=scalarHalf:11:8 (Definition){{( \(invalid\))?}} [type=half] [typekind=Half] [isPOD=1]
+ // CHECK: VarDecl=vectorHalf:12:9 (Definition) [type=half4] [typekind=Typedef] [canonicaltype=half __attribute__((ext_vector_type(4)))] [canonicaltypekind=Unexposed] [isPOD=1]
+ // CHECK: VarDecl=scalarFloat:13:9 (Definition) [type=float] [typekind=Float] [isPOD=1]
+ // CHECK: VarDecl=vectorFloat:14:10 (Definition) [type=float4] [typekind=Typedef] [canonicaltype=float __attribute__((ext_vector_type(4)))] [canonicaltypekind=Unexposed] [isPOD=1]
+-// CHECK: VarDecl=scalarDouble:15:10 (Definition) [type=double] [typekind=Double] [isPOD=1]
++// CHECK: VarDecl=scalarDouble:15:10 (Definition){{( \(invalid\))?}} [type=double] [typekind=Double] [isPOD=1]
+ // CHECK: VarDecl=vectorDouble:16:11 (Definition) [type=double4] [typekind=Typedef] [canonicaltype=double __attribute__((ext_vector_type(4)))] [canonicaltypekind=Unexposed] [isPOD=1]
+
+ #pragma OPENCL EXTENSION cl_khr_gl_msaa_sharing : enable
+@@ -45,10 +45,10 @@ void kernel OCLImage3dROTest(read_only image3d_t scalarOCLImage3dRO);
+ // CHECK: ParmDecl=scalarOCLImage2dArrayRO:32:61 (Definition) [type=__read_only image2d_array_t] [typekind=OCLImage2dArrayRO] [isPOD=1]
+ // CHECK: ParmDecl=scalarOCLImage2dDepthRO:33:61 (Definition) [type=__read_only image2d_depth_t] [typekind=OCLImage2dDepthRO] [isPOD=1]
+ // CHECK: ParmDecl=scalarOCLImage2dArrayDepthRO:34:72 (Definition) [type=__read_only image2d_array_depth_t] [typekind=OCLImage2dArrayDepthRO] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dMSAARO:35:59 (Definition) [type=__read_only image2d_msaa_t] [typekind=OCLImage2dMSAARO] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dArrayMSAARO:36:70 (Definition) [type=__read_only image2d_array_msaa_t] [typekind=OCLImage2dArrayMSAARO] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dMSAADepthRO:37:70 (Definition) [type=__read_only image2d_msaa_depth_t] [typekind=OCLImage2dMSAADepthRO] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dArrayMSAADepthRO:38:81 (Definition) [type=__read_only image2d_array_msaa_depth_t] [typekind=OCLImage2dArrayMSAADepthRO] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dMSAARO:35:59 (Definition){{( \(invalid\))?}} [type=__read_only image2d_msaa_t] [typekind=OCLImage2dMSAARO] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dArrayMSAARO:36:70 (Definition){{( \(invalid\))?}} [type=__read_only image2d_array_msaa_t] [typekind=OCLImage2dArrayMSAARO] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dMSAADepthRO:37:70 (Definition){{( \(invalid\))?}} [type=__read_only image2d_msaa_depth_t] [typekind=OCLImage2dMSAADepthRO] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dArrayMSAADepthRO:38:81 (Definition){{( \(invalid\))?}} [type=__read_only image2d_array_msaa_depth_t] [typekind=OCLImage2dArrayMSAADepthRO] [isPOD=1]
+ // CHECK: ParmDecl=scalarOCLImage3dRO:39:50 (Definition) [type=__read_only image3d_t] [typekind=OCLImage3dRO] [isPOD=1]
+
+ void kernel OCLImage1dWOTest(write_only image1d_t scalarOCLImage1dWO);
+@@ -71,11 +71,11 @@ void kernel OCLImage3dWOTest(write_only image3d_t scalarOCLImage3dWO);
+ // CHECK: ParmDecl=scalarOCLImage2dArrayWO:58:62 (Definition) [type=__write_only image2d_array_t] [typekind=OCLImage2dArrayWO] [isPOD=1]
+ // CHECK: ParmDecl=scalarOCLImage2dDepthWO:59:62 (Definition) [type=__write_only image2d_depth_t] [typekind=OCLImage2dDepthWO] [isPOD=1]
+ // CHECK: ParmDecl=scalarOCLImage2dArrayDepthWO:60:73 (Definition) [type=__write_only image2d_array_depth_t] [typekind=OCLImage2dArrayDepthWO] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dMSAAWO:61:60 (Definition) [type=__write_only image2d_msaa_t] [typekind=OCLImage2dMSAAWO] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dArrayMSAAWO:62:71 (Definition) [type=__write_only image2d_array_msaa_t] [typekind=OCLImage2dArrayMSAAWO] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dMSAADepthWO:63:71 (Definition) [type=__write_only image2d_msaa_depth_t] [typekind=OCLImage2dMSAADepthWO] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dArrayMSAADepthWO:64:82 (Definition) [type=__write_only image2d_array_msaa_depth_t] [typekind=OCLImage2dArrayMSAADepthWO] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage3dWO:65:51 (Definition) [type=__write_only image3d_t] [typekind=OCLImage3dWO] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dMSAAWO:61:60 (Definition){{( \(invalid\))?}} [type=__write_only image2d_msaa_t] [typekind=OCLImage2dMSAAWO] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dArrayMSAAWO:62:71 (Definition){{( \(invalid\))?}} [type=__write_only image2d_array_msaa_t] [typekind=OCLImage2dArrayMSAAWO] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dMSAADepthWO:63:71 (Definition){{( \(invalid\))?}} [type=__write_only image2d_msaa_depth_t] [typekind=OCLImage2dMSAADepthWO] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dArrayMSAADepthWO:64:82 (Definition){{( \(invalid\))?}} [type=__write_only image2d_array_msaa_depth_t] [typekind=OCLImage2dArrayMSAADepthWO] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage3dWO:65:51 (Definition){{( \(invalid\))?}} [type=__write_only image3d_t] [typekind=OCLImage3dWO] [isPOD=1]
+
+ void kernel OCLImage1dRWTest(read_write image1d_t scalarOCLImage1dRW);
+ void kernel OCLImage1dArrayRWTest(read_write image1d_array_t scalarOCLImage1dArrayRW);
+@@ -97,10 +97,10 @@ void kernel OCLImage3dRWTest(read_write image3d_t scalarOCLImage3dRW);
+ // CHECK: ParmDecl=scalarOCLImage2dArrayRW:84:62 (Definition) [type=__read_write image2d_array_t] [typekind=OCLImage2dArrayRW] [isPOD=1]
+ // CHECK: ParmDecl=scalarOCLImage2dDepthRW:85:62 (Definition) [type=__read_write image2d_depth_t] [typekind=OCLImage2dDepthRW] [isPOD=1]
+ // CHECK: ParmDecl=scalarOCLImage2dArrayDepthRW:86:73 (Definition) [type=__read_write image2d_array_depth_t] [typekind=OCLImage2dArrayDepthRW] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dMSAARW:87:60 (Definition) [type=__read_write image2d_msaa_t] [typekind=OCLImage2dMSAARW] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dArrayMSAARW:88:71 (Definition) [type=__read_write image2d_array_msaa_t] [typekind=OCLImage2dArrayMSAARW] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dMSAADepthRW:89:71 (Definition) [type=__read_write image2d_msaa_depth_t] [typekind=OCLImage2dMSAADepthRW] [isPOD=1]
+-// CHECK: ParmDecl=scalarOCLImage2dArrayMSAADepthRW:90:82 (Definition) [type=__read_write image2d_array_msaa_depth_t] [typekind=OCLImage2dArrayMSAADepthRW] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dMSAARW:87:60 (Definition){{( \(invalid\))?}} [type=__read_write image2d_msaa_t] [typekind=OCLImage2dMSAARW] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dArrayMSAARW:88:71 (Definition){{( \(invalid\))?}} [type=__read_write image2d_array_msaa_t] [typekind=OCLImage2dArrayMSAARW] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dMSAADepthRW:89:71 (Definition){{( \(invalid\))?}} [type=__read_write image2d_msaa_depth_t] [typekind=OCLImage2dMSAADepthRW] [isPOD=1]
++// CHECK: ParmDecl=scalarOCLImage2dArrayMSAADepthRW:90:82 (Definition){{( \(invalid\))?}} [type=__read_write image2d_array_msaa_depth_t] [typekind=OCLImage2dArrayMSAADepthRW] [isPOD=1]
+ // CHECK: ParmDecl=scalarOCLImage3dRW:91:51 (Definition) [type=__read_write image3d_t] [typekind=OCLImage3dRW] [isPOD=1]
+
+ void kernel intPipeTestRO(read_only pipe int scalarPipe);
+diff --git a/test/Index/print-type-size.cpp b/test/Index/print-type-size.cpp
+index 45de93f308..1ea5346273 100644
+--- a/tools/clang/test/Index/print-type-size.cpp
++++ b/tools/clang/test/Index/print-type-size.cpp
+@@ -4,8 +4,8 @@
+
+ namespace basic {
+
+-// CHECK64: VarDecl=v:[[@LINE+2]]:6 (Definition) [type=void] [typekind=Void]
+-// CHECK32: VarDecl=v:[[@LINE+1]]:6 (Definition) [type=void] [typekind=Void]
++// CHECK64: VarDecl=v:[[@LINE+2]]:6 (Definition) (invalid) [type=void] [typekind=Void]
++// CHECK32: VarDecl=v:[[@LINE+1]]:6 (Definition) (invalid) [type=void] [typekind=Void]
+ void v;
+
+ // CHECK64: VarDecl=v1:[[@LINE+2]]:7 (Definition) [type=void *] [typekind=Pointer] [sizeof=8] [alignof=8]
+diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
+index 99f05669b6..c5e345ef6a 100644
+--- a/tools/clang/tools/c-index-test/c-index-test.c
++++ b/tools/clang/tools/c-index-test/c-index-test.c
+@@ -812,6 +812,8 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
+ printf(" (variadic)");
+ if (clang_Cursor_isObjCOptional(Cursor))
+ printf(" (@optional)");
++ if (clang_isInvalidDeclaration(Cursor))
++ printf(" (invalid)");
+
+ switch (clang_getCursorExceptionSpecificationType(Cursor))
+ {
+diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
+index 66b6edc8b1..429fca3474 100644
+--- a/tools/clang/tools/libclang/CIndex.cpp
++++ b/tools/clang/tools/libclang/CIndex.cpp
+@@ -5437,6 +5437,15 @@ unsigned clang_isDeclaration(enum CXCursorKind K) {
+ (K >= CXCursor_FirstExtraDecl && K <= CXCursor_LastExtraDecl);
+ }
+
++unsigned clang_isInvalidDeclaration(CXCursor C) {
++ if (clang_isDeclaration(C.kind)) {
++ if (const Decl *D = getCursorDecl(C))
++ return D->isInvalidDecl();
++ }
++
++ return 0;
++}
++
+ unsigned clang_isReference(enum CXCursorKind K) {
+ return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;
+ }
+diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
+index bf95b97073..5d1b0224ef 100644
+--- a/tools/clang/tools/libclang/libclang.exports
++++ b/tools/clang/tools/libclang/libclang.exports
+@@ -291,6 +291,7 @@ clang_isAttribute
+ clang_isConstQualifiedType
+ clang_isCursorDefinition
+ clang_isDeclaration
++clang_isInvalidDeclaration
+ clang_isExpression
+ clang_isFileMultipleIncludeGuarded
+ clang_isFunctionTypeVariadic
diff --git a/dist/clang/patches/D40561_Fix-cursors-for-functions-with-trailing-return-type.patch b/dist/clang/patches/D40561_Fix-cursors-for-functions-with-trailing-return-type.patch
new file mode 100644
index 0000000000..22084c5729
--- /dev/null
+++ b/dist/clang/patches/D40561_Fix-cursors-for-functions-with-trailing-return-type.patch
@@ -0,0 +1,79 @@
+--- a/tools/clang/test/Index/annotate-tokens.cpp
++++ b/tools/clang/test/Index/annotate-tokens.cpp
+@@ -37,7 +37,9 @@ class C {
+ ~C();
+ };
+
+-// RUN: c-index-test -test-annotate-tokens=%s:1:1:38:1 %s -fno-delayed-template-parsing | FileCheck %s
++auto test5(X) -> X;
++
++// RUN: c-index-test -test-annotate-tokens=%s:1:1:41:1 %s -std=c++14 -fno-delayed-template-parsing | FileCheck %s
+ // CHECK: Keyword: "struct" [1:1 - 1:7] StructDecl=bonk:1:8 (Definition)
+ // CHECK: Identifier: "bonk" [1:8 - 1:12] StructDecl=bonk:1:8 (Definition)
+ // CHECK: Punctuation: "{" [1:13 - 1:14] StructDecl=bonk:1:8 (Definition)
+@@ -184,6 +186,14 @@ class C {
+ // CHECK: Punctuation: "}" [29:22 - 29:23] CompoundStmt=
+ // CHECK: Punctuation: "~" [37:3 - 37:4] CXXDestructor=~C:37:3
+ // CHECK: Identifier: "C" [37:4 - 37:5] CXXDestructor=~C:37:3
++// CHECK: Keyword: "auto" [40:1 - 40:5] FunctionDecl=test5:40:6
++// CHECK: Identifier: "test5" [40:6 - 40:11] FunctionDecl=test5:40:6
++// CHECK: Punctuation: "(" [40:11 - 40:12] FunctionDecl=test5:40:6
++// CHECK: Identifier: "X" [40:12 - 40:13] TypeRef=struct X:7:8
++// CHECK: Punctuation: ")" [40:13 - 40:14] FunctionDecl=test5:40:6
++// CHECK: Punctuation: "->" [40:15 - 40:17] FunctionDecl=test5:40:6
++// CHECK: Identifier: "X" [40:18 - 40:19] TypeRef=struct X:7:8
++// CHECK: Punctuation: ";" [40:19 - 40:20]
+
+ // RUN: env LIBCLANG_DISABLE_CRASH_RECOVERY=1 c-index-test -test-annotate-tokens=%s:32:1:32:13 %s | FileCheck %s -check-prefix=CHECK2
+ // CHECK2: Keyword: "if" [32:3 - 32:5] IfStmt=
+--- a/tools/clang/tools/libclang/CIndex.cpp
++++ b/tools/clang/tools/libclang/CIndex.cpp
+@@ -783,6 +783,16 @@ bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) {
+ return false;
+ }
+
++static bool HasTrailingReturnType(FunctionDecl *ND) {
++ const QualType Ty = ND->getType();
++ if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
++ if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(AFT))
++ return FT->hasTrailingReturn();
++ }
++
++ return false;
++}
++
+ /// \brief Compare two base or member initializers based on their source order.
+ static int CompareCXXCtorInitializers(CXXCtorInitializer *const *X,
+ CXXCtorInitializer *const *Y) {
+@@ -802,14 +812,16 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
+ // written. This requires a bit of work.
+ TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
+ FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>();
++ const bool HasTrailingRT = HasTrailingReturnType(ND);
+
+ // If we have a function declared directly (without the use of a typedef),
+ // visit just the return type. Otherwise, just visit the function's type
+ // now.
+- if ((FTL && !isa<CXXConversionDecl>(ND) && Visit(FTL.getReturnLoc())) ||
++ if ((FTL && !isa<CXXConversionDecl>(ND) && !HasTrailingRT &&
++ Visit(FTL.getReturnLoc())) ||
+ (!FTL && Visit(TL)))
+ return true;
+-
++
+ // Visit the nested-name-specifier, if present.
+ if (NestedNameSpecifierLoc QualifierLoc = ND->getQualifierLoc())
+ if (VisitNestedNameSpecifierLoc(QualifierLoc))
+@@ -825,7 +837,11 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
+ // Visit the function parameters, if we have a function type.
+ if (FTL && VisitFunctionTypeLoc(FTL, true))
+ return true;
+-
++
++ // Visit the function's trailing return type.
++ if (FTL && HasTrailingRT && Visit(FTL.getReturnLoc()))
++ return true;
++
+ // FIXME: Attributes?
+ }
+
diff --git a/dist/clang/patches/D40643_Add-function-to-get-the-buffer-for-a-file.patch b/dist/clang/patches/D40643_Add-function-to-get-the-buffer-for-a-file.patch
new file mode 100644
index 0000000000..c0b3f861ec
--- /dev/null
+++ b/dist/clang/patches/D40643_Add-function-to-get-the-buffer-for-a-file.patch
@@ -0,0 +1,64 @@
+--- a/tools/clang/include/clang-c/Index.h
++++ a/tools/clang/include/clang-c/Index.h
+@@ -404,6 +404,21 @@
+ const char *file_name);
+
+ /**
++ * \brief Retrieve the buffer associated with the given file.
++ *
++ * \param tu the translation unit
++ *
++ * \param file the file for which to retrieve the buffer.
++ *
++ * \param size [out] if non-NULL, will be set to the size of the buffer.
++ *
++ * \returns a pointer to the buffer in memory that holds the contents of
++ * \p file, or a NULL pointer when the file is not loaded.
++ */
++CINDEX_LINKAGE const char *clang_getFileContents(CXTranslationUnit tu,
++ CXFile file, size_t *size);
++
++/**
+ * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
+ * or they are both NULL.
+ */
+--- a/tools/clang/tools/libclang/CIndex.cpp
++++ a/tools/clang/tools/libclang/CIndex.cpp
+@@ -4162,6 +4162,27 @@
+ return const_cast<FileEntry *>(FMgr.getFile(file_name));
+ }
+
++const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
++ size_t *size) {
++ if (isNotUsableTU(TU)) {
++ LOG_BAD_TU(TU);
++ return nullptr;
++ }
++
++ const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
++ FileID fid = SM.translateFile(static_cast<FileEntry *>(file));
++ bool Invalid = true;
++ llvm::MemoryBuffer *buf = SM.getBuffer(fid, &Invalid);
++ if (Invalid) {
++ if (size)
++ *size = 0;
++ return nullptr;
++ }
++ if (size)
++ *size = buf->getBufferSize();
++ return buf->getBufferStart();
++}
++
+ unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
+ CXFile file) {
+ if (isNotUsableTU(TU)) {
+--- a/tools/clang/tools/libclang/libclang.exports
++++ b/tools/clang/tools/libclang/libclang.exports
+@@ -216,6 +216,7 @@ clang_getExceptionSpecificationType
+ clang_getFieldDeclBitWidth
+ clang_getExpansionLocation
+ clang_getFile
++clang_getFileContents
+ clang_getFileLocation
+ clang_getFileName
+ clang_getFileTime
diff --git a/dist/clang/patches/D40746_Correctly-handle-line-table-entries-without-filenames-during-AST-serialization.patch b/dist/clang/patches/D40746_Correctly-handle-line-table-entries-without-filenames-during-AST-serialization.patch
new file mode 100644
index 0000000000..c165c69fe5
--- /dev/null
+++ b/dist/clang/patches/D40746_Correctly-handle-line-table-entries-without-filenames-during-AST-serialization.patch
@@ -0,0 +1,47 @@
+--- a/tools/clang/lib/Serialization/ASTReader.cpp
++++ b/tools/clang/lib/Serialization/ASTReader.cpp
+@@ -1220,6 +1220,7 @@
+
+ // Parse the file names
+ std::map<int, int> FileIDs;
++ FileIDs[-1] = -1; // For unspecified filenames.
+ for (unsigned I = 0; Record[Idx]; ++I) {
+ // Extract the file name
+ auto Filename = ReadPath(F, Record, Idx);
+--- a/tools/clang/lib/Serialization/ASTWriter.cpp
++++ b/tools/clang/lib/Serialization/ASTWriter.cpp
+@@ -2363,12 +2363,13 @@
+
+ // Emit the needed file names.
+ llvm::DenseMap<int, int> FilenameMap;
++ FilenameMap[-1] = -1; // For unspecified filenames.
+ for (const auto &L : LineTable) {
+ if (L.first.ID < 0)
+ continue;
+ for (auto &LE : L.second) {
+ if (FilenameMap.insert(std::make_pair(LE.FilenameID,
+- FilenameMap.size())).second)
++ FilenameMap.size() - 1)).second)
+ AddPath(LineTable.getFilename(LE.FilenameID), Record);
+ }
+ }
+--- a/tools/clang/test/PCH/line-directive-nofilename.h
++++ b/tools/clang/test/PCH/line-directive-nofilename.h
+@@ -0,0 +1,5 @@
++#line 42
++int foo; // This should appear as at line-directive-nofilename.h:42
++
++#line 100 "foobar.h"
++int bar; // This should appear as at foobar.h:100
+--- a/tools/clang/test/PCH/line-directive-nofilename.c
++++ b/tools/clang/test/PCH/line-directive-nofilename.c
+@@ -0,0 +1,9 @@
++// RUN: %clang_cc1 -emit-pch -o %t %S/line-directive-nofilename.h
++// RUN: not %clang_cc1 -include-pch %t -fsyntax-only %s 2>&1 | FileCheck %s
++
++// This causes an "error: redefinition" diagnostic. The notes will have the
++// locations of the declarations from the PCH file.
++double foo, bar;
++
++// CHECK: line-directive-nofilename.h:42:5: note: previous definition is here
++// CHECK: foobar.h:100:5: note: previous definition is here
diff --git a/dist/clang/patches/D40841_Fix-a-crash-on-C++17-AST-for-non-trivial-construction-into-a-trivial-brace-initialize.patch b/dist/clang/patches/D40841_Fix-a-crash-on-C++17-AST-for-non-trivial-construction-into-a-trivial-brace-initialize.patch
new file mode 100644
index 0000000000..e759e4a9f5
--- /dev/null
+++ b/dist/clang/patches/D40841_Fix-a-crash-on-C++17-AST-for-non-trivial-construction-into-a-trivial-brace-initialize.patch
@@ -0,0 +1,117 @@
+--- a/tools/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
++++ b/tools/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+@@ -22,6 +22,7 @@
+ //===----------------------------------------------------------------------===//
+
+ #include "ClangSACheckers.h"
++#include "clang/AST/ParentMap.h"
+ #include "clang/AST/RecursiveASTVisitor.h"
+ #include "clang/Basic/Builtins.h"
+ #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+@@ -262,8 +263,19 @@
+ if (const MemRegion *Target = Ctor->getCXXThisVal().getAsRegion()) {
+ // We just finished a base constructor. Now we can use the subclass's
+ // type when resolving virtual calls.
+- const Decl *D = C.getLocationContext()->getDecl();
+- recordFixedType(Target, cast<CXXConstructorDecl>(D), C);
++ const LocationContext *LCtx = C.getLocationContext();
++
++ // FIXME: In C++17 classes with non-virtual bases may be treated as
++ // aggregates, and in such case no top-frame constructor will be called.
++ // Figure out if we need to do anything in this case.
++ // FIXME: Instead of relying on the ParentMap, we should have the
++ // trigger-statement (InitListExpr in this case) available in this
++ // callback, ideally as part of CallEvent.
++ if (dyn_cast_or_null<InitListExpr>(
++ LCtx->getParentMap().getParent(Ctor->getOriginExpr())))
++ return;
++
++ recordFixedType(Target, cast<CXXConstructorDecl>(LCtx->getDecl()), C);
+ }
+ return;
+ }
+--- a/tools/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
++++ b/tools/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+@@ -14,6 +14,7 @@
+ #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+ #include "clang/AST/DeclCXX.h"
+ #include "clang/AST/StmtCXX.h"
++#include "clang/AST/ParentMap.h"
+ #include "clang/Basic/PrettyStackTrace.h"
+ #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+ #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
+@@ -267,6 +268,23 @@
+ }
+ // FALLTHROUGH
+ case CXXConstructExpr::CK_NonVirtualBase:
++ // In C++17, classes with non-virtual bases may be aggregates, so they would
++ // be initialized as aggregates without a constructor call, so we may have
++ // a base class constructed directly into an initializer list without
++ // having the derived-class constructor call on the previous stack frame.
++ // Initializer lists may be nested into more initializer lists that
++ // correspond to surrounding aggregate initializations.
++ // FIXME: For now this code essentially bails out. We need to find the
++ // correct target region and set it.
++ // FIXME: Instead of relying on the ParentMap, we should have the
++ // trigger-statement (InitListExpr in this case) passed down from CFG or
++ // otherwise always available during construction.
++ if (dyn_cast_or_null<InitListExpr>(LCtx->getParentMap().getParent(CE))) {
++ MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
++ Target = MRMgr.getCXXTempObjectRegion(CE, LCtx);
++ break;
++ }
++ // FALLTHROUGH
+ case CXXConstructExpr::CK_Delegating: {
+ const CXXMethodDecl *CurCtor = cast<CXXMethodDecl>(LCtx->getDecl());
+ Loc ThisPtr = getSValBuilder().getCXXThis(CurCtor,
+--- a/tools/clang/test/Analysis/initializer.cpp
++++ a/tools/clang/test/Analysis/initializer.cpp
+@@ -1,4 +1,5 @@
+ // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config c++-inlining=constructors -std=c++11 -verify %s
++// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,cplusplus.NewDeleteLeaks,debug.ExprInspection -analyzer-config c++-inlining=constructors -std=c++17 -DCPLUSPLUS17 -verify %s
+
+ void clang_analyzer_eval(bool);
+
+@@ -224,3 +225,42 @@
+ const char(&f)[2];
+ };
+ }
++
++namespace CXX17_aggregate_construction {
++struct A {
++ A();
++};
++
++struct B: public A {
++};
++
++struct C: public B {
++};
++
++struct D: public virtual A {
++};
++
++// In C++17, classes B and C are aggregates, so they will be constructed
++// without actually calling their trivial constructor. Used to crash.
++void foo() {
++ B b = {}; // no-crash
++ const B &bl = {}; // no-crash
++ B &&br = {}; // no-crash
++
++ C c = {}; // no-crash
++ const C &cl = {}; // no-crash
++ C &&cr = {}; // no-crash
++
++ D d = {}; // no-crash
++
++#ifdef CPLUSPLUS17
++ C cd = {{}}; // no-crash
++ const C &cdl = {{}}; // no-crash
++ C &&cdr = {{}}; // no-crash
++
++ const B &bll = {{}}; // no-crash
++ const B &bcl = C({{}}); // no-crash
++ B &&bcr = C({{}}); // no-crash
++#endif
++}
++}
diff --git a/dist/clang/patches/D41016_Fix-crash-in-unused-lambda-capture-warning-for-VLAs.patch b/dist/clang/patches/D41016_Fix-crash-in-unused-lambda-capture-warning-for-VLAs.patch
new file mode 100644
index 0000000000..f9743162ec
--- /dev/null
+++ b/dist/clang/patches/D41016_Fix-crash-in-unused-lambda-capture-warning-for-VLAs.patch
@@ -0,0 +1,37 @@
+--- a/tools/clang/include/clang/Sema/ScopeInfo.h
++++ b/tools/clang/include/clang/Sema/ScopeInfo.h
+@@ -560,6 +560,7 @@
+ void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
+
+ VarDecl *getVariable() const {
++ assert(isVariableCapture());
+ return VarAndNestedAndThis.getPointer();
+ }
+
+--- a/tools/clang/lib/Sema/SemaLambda.cpp
++++ b/tools/clang/lib/Sema/SemaLambda.cpp
+@@ -1481,6 +1481,9 @@
+ if (CaptureHasSideEffects(From))
+ return;
+
++ if (From.isVLATypeCapture())
++ return;
++
+ auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
+ if (From.isThisCapture())
+ diag << "'this'";
+--- a/tools/clang/test/SemaCXX/warn-unused-lambda-capture.cpp
++++ b/tools/clang/test/SemaCXX/warn-unused-lambda-capture.cpp
+@@ -191,3 +191,12 @@
+ void test_use_template() {
+ test_templated<int>(); // expected-note{{in instantiation of function template specialization 'test_templated<int>' requested here}}
+ }
++
++namespace pr35555 {
++int a;
++void b() {
++ int c[a];
++ auto vla_used = [&c] { return c[0]; };
++ auto vla_unused = [&c] {}; // expected-warning{{lambda capture 'c' is not used}}
++}
++} // namespace pr35555
diff --git a/dist/clang/patches/D41688_Fix-crash-on-code-completion-in-comment-in-included-file.patch b/dist/clang/patches/D41688_Fix-crash-on-code-completion-in-comment-in-included-file.patch
new file mode 100644
index 0000000000..14fe744798
--- /dev/null
+++ b/dist/clang/patches/D41688_Fix-crash-on-code-completion-in-comment-in-included-file.patch
@@ -0,0 +1,47 @@
+--- a/tools/clang/lib/Lex/PPCaching.cpp
++++ b/tools/clang/lib/Lex/PPCaching.cpp
+@@ -105,8 +105,10 @@
+ }
+
+ void Preprocessor::EnterCachingLexMode() {
+- if (InCachingLexMode())
++ if (InCachingLexMode()) {
++ assert(CurLexerKind == CLK_CachingLexer && "Unexpected lexer kind");
+ return;
++ }
+
+ PushIncludeMacroStack();
+ CurLexerKind = CLK_CachingLexer;
+--- a/tools/clang/lib/Lex/PPLexerChange.cpp
++++ b/tools/clang/lib/Lex/PPLexerChange.cpp
+@@ -444,6 +444,7 @@
+ }
+
+ CurPPLexer = nullptr;
++ recomputeCurLexerKind();
+ return true;
+ }
+
+--- /dev/null
++++ b/tools/clang/test/CodeCompletion/Inputs/comments.h
+@@ -0,0 +1,4 @@
++// PR32732
++struct B {
++ // <- code completion
++};
+--- /dev/null
++++ b/tools/clang/test/CodeCompletion/comments.cpp
+@@ -0,0 +1,13 @@
++// Note: the run lines follow their respective tests, since line/column
++// matter in this test.
++
++#include "comments.h"
++
++struct A {
++ // <- code completion
++ /* <- code completion */
++};
++
++// RUN: %clang_cc1 -I %S/Inputs -fsyntax-only -code-completion-at=%s:7:6 %s
++// RUN: %clang_cc1 -I %S/Inputs -fsyntax-only -code-completion-at=%s:8:6 %s
++// RUN: %clang_cc1 -I %S/Inputs -fsyntax-only -code-completion-at=%S/Inputs/comments.h:3:6 %s
diff --git a/dist/clang/patches/QTCREATORBUG-15157_Link-with-clazy_clang.patch b/dist/clang/patches/QTCREATORBUG-15157_Link-with-clazy_clang.patch
index 20c2d33e53..60acd6d9fa 100644
--- a/dist/clang/patches/QTCREATORBUG-15157_Link-with-clazy_clang.patch
+++ b/dist/clang/patches/QTCREATORBUG-15157_Link-with-clazy_clang.patch
@@ -20,6 +20,6 @@ index 4440637820..6798d2ee8b 100644
list(APPEND LIBS clangTidyPlugin)
list(APPEND LIBS clangIncludeFixerPlugin)
+ list(APPEND LIBS clazyPlugin)
- if(LLVM_ENABLE_MODULES)
- list(APPEND LLVM_COMPILE_FLAGS "-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
- endif()
+ endif ()
+
+ find_library(DL_LIBRARY_PATH dl)
diff --git a/dist/clang/patches/README.md b/dist/clang/patches/README.md
index ca03440631..ccf64a8a1d 100644
--- a/dist/clang/patches/README.md
+++ b/dist/clang/patches/README.md
@@ -9,26 +9,79 @@ The patches in this directory are applied to LLVM/Clang with:
Backported changes
------------------
+##### D41016_Fix-crash-in-unused-lambda-capture-warning-for-VLAs.patch
+
+* <https://reviews.llvm.org/D41016>
+
+[Sema] Fix crash in unused-lambda-capture warning for VLAs
+
##### D35355_Fix-templated-type-alias-completion-when-using-global-completion-cache.patch
* <https://reviews.llvm.org/D35355>
Fixes completion involving templated type alias.
-##### D37435_Dont-show-deleted-function-constructor-candidates-for-code-completion.patch
+##### D41688_Fix-crash-on-code-completion-in-comment-in-included-file.patch
+
+* <https://reviews.llvm.org/D41688>
+
+[Lex] Fix crash on code completion in comment in included file.
+
+##### D40841_Fix-a-crash-on-C++17-AST-for-non-trivial-construction-into-a-trivial-brace-initialize.patch
+
+* <https://reviews.llvm.org/D40841>
+
+[analyzer] Fix a crash on C++17 AST for non-trivial construction into a trivial brace initializer.
+
+##### D40746_Correctly-handle-line-table-entries-without-filenames-during-AST-serialization.patch
+
+* <https://reviews.llvm.org/D40746>
+
+Correctly handle line table entries without filenames during AST serialization
+Fixes crash during a reparse.
+
+##### D40027_Fix-cursors-for-in-class-initializer-of-field-declarations.patch
+
+* <https://reviews.llvm.org/D40027>
+* <https://bugs.llvm.org/show_bug.cgi?id=33745>
+
+[libclang] Fix cursors for in-class initializer of field declarations
+Fixes AST access to initializers of class members. Affects mostly semantic highlighting and highlighting of local uses.
+
+##### D40561_Fix-cursors-for-functions-with-trailing-return-type.patch
+
+* <https://reviews.llvm.org/D40561>
+
+[libclang] Fix cursors for functions with trailing return type
+
+##### D40072_Support-querying-whether-a-declaration-is-invalid.patch
+
+* <https://reviews.llvm.org/D40072>
+
+[libclang] Add support for checking abstractness of records
+Would need https://codereview.qt-project.org/#/c/211497/ on Qt Creator side.
+
+##### D39957_Honor-TerseOutput-for-constructors.patch
+
+* <https://reviews.llvm.org/D39957>
+
+[DeclPrinter] Honor TerseOutput for constructors
+Avoids printing member initialization list and body for constructor.
+
+##### D40643_Add-function-to-get-the-buffer-for-a-file.patch
-* <https://reviews.llvm.org/D37435>
-* <https://bugs.llvm.org/show_bug.cgi?id=34402>
+* <https://reviews.llvm.org/D40643>
+* <https://reviews.llvm.org/rL319881>
-Fixes completion involving implicitly deleted copy constructors.
+[libclang] Add function to get the buffer for a file
+Together with https://codereview.qt-project.org/#/c/212972/ fixes highlighting
-##### rL310905_Avoid-PointerIntPair-of-constexpr-EvalInfo-structs.patch
+##### D38615_Only-mark-CXCursors-for-explicit-attributes-with-a-type.patch
-* <https://reviews.llvm.org/rL310905>
-* <https://bugs.llvm.org/show_bug.cgi?id=32018>
+* <https://reviews.llvm.org/D38615>
-Fixes build/miscompilation of LLVM/Clang with MinGW, which enables generation
-of profile-guided-optimization builds for Windows.
+[libclang] Only mark CXCursors for explicit attributes with a type
+Some classes have totally broken highlighting (like classes inside texteditor.cpp)
Additional changes
------------------
@@ -40,10 +93,11 @@ Additional changes
Significantly reduces problems when saving a header file on Windows.
-##### QTCREATORBUG-15157_Link-with-clazy.patch
+##### QTCREATORBUG-15157_Link-with-clazy_llvm.patch
+##### QTCREATORBUG-15157_Link-with-clazy_clang.patch
+##### QTCREATORBUG-15157_Link-with-clazy_extra.patch
* <https://bugreports.qt.io/browse/QTCREATORBUG-15157>
-Introduces the flag CLANG_ENABLE_CLAZY to link libclang with Clazy and forces
-link for Clazy checks and plugin registry entry.
+Builds Clazy as an LLVM part and forces link for Clazy plugin registry entry.
diff --git a/dist/clang/patches/rL310905_Avoid-PointerIntPair-of-constexpr-EvalInfo-structs.patch b/dist/clang/patches/rL310905_Avoid-PointerIntPair-of-constexpr-EvalInfo-structs.patch
deleted file mode 100644
index e5c60b7f2f..0000000000
--- a/dist/clang/patches/rL310905_Avoid-PointerIntPair-of-constexpr-EvalInfo-structs.patch
+++ /dev/null
@@ -1,88 +0,0 @@
-diff --git a/tools/clang/lib/AST/ExprConstant.cpp b/tools/clang/lib/AST/ExprConstant.cpp
-index a26b608082..effd72c764 100644
---- a/tools/clang/lib/AST/ExprConstant.cpp
-+++ b/tools/clang/lib/AST/ExprConstant.cpp
-@@ -537,7 +537,11 @@ namespace {
- /// rules. For example, the RHS of (0 && foo()) is not evaluated. We can
- /// evaluate the expression regardless of what the RHS is, but C only allows
- /// certain things in certain situations.
-+#ifndef _WIN32
- struct LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) EvalInfo {
-+#else
-+ struct EvalInfo {
-+#endif
- ASTContext &Ctx;
-
- /// EvalStatus - Contains information about the evaluation.
-@@ -575,7 +579,21 @@ namespace {
-
- /// The current array initialization index, if we're performing array
- /// initialization.
-+#ifndef _WIN32
- uint64_t ArrayInitIndex = -1;
-+#else
-+ /// uint64_t value is split into two uint32_t values as a workaround
-+ /// to deal with mingw 32-bit miscompilation
-+ uint32_t ArrayInitIndex[2] = {static_cast<uint32_t>(-1), static_cast<uint32_t>(-1)};
-+ uint64_t GetArrayInitIndex() {
-+ return (static_cast<uint64_t>(ArrayInitIndex[0]) << 32)
-+ + static_cast<uint64_t>(ArrayInitIndex[1]);
-+ }
-+ void SetArrayInitIndex(uint64_t index) {
-+ ArrayInitIndex[0] = static_cast<uint32_t>(index >> 32);
-+ ArrayInitIndex[1] = static_cast<uint32_t>(index);
-+ }
-+#endif
-
- /// HasActiveDiagnostic - Was the previous diagnostic stored? If so, further
- /// notes attached to it will also be stored, otherwise they will not be.
-@@ -922,6 +940,7 @@ namespace {
- uint64_t OuterIndex;
-
- public:
-+#ifndef _WIN32
- ArrayInitLoopIndex(EvalInfo &Info)
- : Info(Info), OuterIndex(Info.ArrayInitIndex) {
- Info.ArrayInitIndex = 0;
-@@ -929,6 +948,19 @@ namespace {
- ~ArrayInitLoopIndex() { Info.ArrayInitIndex = OuterIndex; }
-
- operator uint64_t&() { return Info.ArrayInitIndex; }
-+#else
-+ ArrayInitLoopIndex(EvalInfo &Info)
-+ : Info(Info), OuterIndex(Info.GetArrayInitIndex()) {
-+ Info.SetArrayInitIndex(0);
-+ }
-+ ~ArrayInitLoopIndex() { Info.SetArrayInitIndex(OuterIndex); }
-+
-+ operator uint64_t() { return Info.GetArrayInitIndex(); }
-+ ArrayInitLoopIndex& operator++() {
-+ Info.SetArrayInitIndex(Info.GetArrayInitIndex() + 1);
-+ return *this;
-+ }
-+#endif
- };
- };
-
-@@ -6973,13 +7005,21 @@ public:
- }
-
- bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
-+#ifndef _WIN32
- if (Info.ArrayInitIndex == uint64_t(-1)) {
-+#else
-+ if (Info.GetArrayInitIndex() == uint64_t(-1)) {
-+#endif
- // We were asked to evaluate this subexpression independent of the
- // enclosing ArrayInitLoopExpr. We can't do that.
- Info.FFDiag(E);
- return false;
- }
-+#ifndef _WIN32
- return Success(Info.ArrayInitIndex, E);
-+#else
-+ return Success(Info.GetArrayInitIndex(), E);
-+#endif
- }
-
- // Note, GNU defines __null as an integer, not a pointer.