[PATCH] D64477: [ASTImporter] Using Lang_CXX11 in ASTImporterVisibilityTest.

2019-07-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Probably change to CXX14?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64477/new/

https://reviews.llvm.org/D64477



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64283: [PowerPC] Support -mabi=ieeelongdouble and -mabi=ibmlongdouble

2019-07-15 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366044: [PowerPC] Support -mabi=ieeelongdouble and 
-mabi=ibmlongdouble (authored by MaskRay, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64283/new/

https://reviews.llvm.org/D64283

Files:
  cfe/trunk/include/clang/Basic/LangOptions.def
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/lib/Basic/Targets/PPC.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/ppc64-long-double.cpp
  cfe/trunk/test/Driver/ppc-abi.c

Index: cfe/trunk/include/clang/Basic/LangOptions.def
===
--- cfe/trunk/include/clang/Basic/LangOptions.def
+++ cfe/trunk/include/clang/Basic/LangOptions.def
@@ -172,6 +172,7 @@
   "default maximum alignment for types")
 VALUE_LANGOPT(AlignDouble, 1, 0, "Controls if doubles should be aligned to 8 bytes (x86 only)")
 VALUE_LANGOPT(LongDoubleSize, 32, 0, "width of long double")
+LANGOPT(PPCIEEELongDouble, 1, 0, "use IEEE 754 quadruple-precision for long double")
 COMPATIBLE_VALUE_LANGOPT(PICLevel, 2, 0, "__PIC__ level")
 COMPATIBLE_VALUE_LANGOPT(PIE , 1, 0, "is pie")
 LANGOPT(ROPI , 1, 0, "Read-only position independence")
Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -298,6 +298,8 @@
"precision">;
 def mreassociate : Flag<["-"], "mreassociate">,
   HelpText<"Allow reassociation transformations for floating-point instructions">;
+def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">,
+  HelpText<"Use IEEE 754 quadruple-precision for long double">;
 def mfloat_abi : Separate<["-"], "mfloat-abi">,
   HelpText<"The float ABI to use">;
 def mtp : Separate<["-"], "mtp">,
Index: cfe/trunk/test/CodeGen/ppc64-long-double.cpp
===
--- cfe/trunk/test/CodeGen/ppc64-long-double.cpp
+++ cfe/trunk/test/CodeGen/ppc64-long-double.cpp
@@ -3,6 +3,14 @@
 // RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s -mlong-double-64 | \
 // RUN:   FileCheck --check-prefix=FP64 %s
 
+// musl defaults to -mlong-double-64, so -mlong-double-128 is needed to make
+// -mabi=ieeelongdouble effective.
+// RUN: %clang_cc1 -triple powerpc64-linux-musl -emit-llvm -o - %s -mlong-double-128 \
+// RUN:   -mabi=ieeelongdouble | FileCheck --check-prefix=FP128 %s
+// RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s \
+// RUN:   -mabi=ieeelongdouble | FileCheck --check-prefix=FP128 %s
+
+// IBM extended double is the default.
 // RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s | \
 // RUN:   FileCheck --check-prefix=IBM128 %s
 // RUN: %clang_cc1 -triple powerpc64-linux-musl -emit-llvm -o - -mlong-double-128 %s | \
@@ -13,10 +21,13 @@
 
 // FP64: @x = global double {{.*}}, align 8
 // FP64: @size = global i32 8
+// FP128: @x = global fp128 {{.*}}, align 16
+// FP128: @size = global i32 16
 // IBM128: @x = global ppc_fp128 {{.*}}, align 16
 // IBM128: @size = global i32 16
 
 long double foo(long double d) { return d; }
 
 // FP64: double @_Z3fooe(double %d)
+// FP128: fp128 @_Z3foou9__ieee128(fp128 %d)
 // IBM128: ppc_fp128 @_Z3foog(ppc_fp128 %d)
Index: cfe/trunk/test/Driver/ppc-abi.c
===
--- cfe/trunk/test/Driver/ppc-abi.c
+++ cfe/trunk/test/Driver/ppc-abi.c
@@ -66,4 +66,22 @@
 // CHECK-ELFv2-PIC: "-mrelocation-model" "pic" "-pic-level" "2"
 // CHECK-ELFv2-PIC: "-target-abi" "elfv2"
 
+// Check -mabi=ieeelongdouble is passed through but it does not change -target-abi.
+// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ieeelongdouble -mabi=elfv1 -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s
+// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=elfv1 -mabi=ieeelongdouble -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s
+// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=elfv2 -mabi=elfv1 -mabi=ibmlongdouble -mabi=ieeelongdouble -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s
+
+// CHECK-ELFv1-IEEE: "-mabi=ieeelongdouble"
+// CHECK-ELFv1-IEEE: "-target-abi" "elfv1"
+
+// Check -mabi=ibmlongdouble is the default.
+// RUN: %clang -target powerpc64le-linux-gnu %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s
+// RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ibmlongdouble -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s
 
+// CHECK-ELFv2-IBM128-NOT: "-mabi=ieeelongdouble"
+// CHECK-ELFv2-IBM128: "-target-abi" "elfv2"
Index: cfe/trunk/lib/Basic

r366044 - [PowerPC] Support -mabi=ieeelongdouble and -mabi=ibmlongdouble

2019-07-15 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Mon Jul 15 00:25:11 2019
New Revision: 366044

URL: http://llvm.org/viewvc/llvm-project?rev=366044&view=rev
Log:
[PowerPC] Support -mabi=ieeelongdouble and -mabi=ibmlongdouble

gcc PowerPC supports 3 representations of long double:

* -mlong-double-64

  long double has the same representation of double but is mangled as `e`.
  In clang, this is the default on AIX, FreeBSD and Linux musl.

* -mlong-double-128

  2 possible 128-bit floating point representations:

  + -mabi=ibmlongdouble
IBM extended double format. Mangled as `g`
In clang, this is the default on Linux glibc.
  + -mabi=ieeelongdouble
IEEE 754 quadruple-precision format. Mangled as `u9__ieee128` 
(`U10__float128` before gcc 8.2)
This is currently unavailable.

This patch adds -mabi=ibmlongdouble and -mabi=ieeelongdouble, and thus
makes the IEEE 754 quadruple-precision long double available for
languages supported by clang.

Reviewed By: hfinkel

Differential Revision: https://reviews.llvm.org/D64283

Modified:
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/Basic/Targets/PPC.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGen/ppc64-long-double.cpp
cfe/trunk/test/Driver/ppc-abi.c

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=366044&r1=366043&r2=366044&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Mon Jul 15 00:25:11 2019
@@ -172,6 +172,7 @@ VALUE_LANGOPT(MaxTypeAlign  , 32, 0,
   "default maximum alignment for types")
 VALUE_LANGOPT(AlignDouble, 1, 0, "Controls if doubles should be 
aligned to 8 bytes (x86 only)")
 VALUE_LANGOPT(LongDoubleSize, 32, 0, "width of long double")
+LANGOPT(PPCIEEELongDouble, 1, 0, "use IEEE 754 quadruple-precision 
for long double")
 COMPATIBLE_VALUE_LANGOPT(PICLevel, 2, 0, "__PIC__ level")
 COMPATIBLE_VALUE_LANGOPT(PIE , 1, 0, "is pie")
 LANGOPT(ROPI , 1, 0, "Read-only position independence")

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=366044&r1=366043&r2=366044&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Jul 15 00:25:11 2019
@@ -298,6 +298,8 @@ def menable_unsafe_fp_math : Flag<["-"],
"precision">;
 def mreassociate : Flag<["-"], "mreassociate">,
   HelpText<"Allow reassociation transformations for floating-point 
instructions">;
+def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">,
+  HelpText<"Use IEEE 754 quadruple-precision for long double">;
 def mfloat_abi : Separate<["-"], "mfloat-abi">,
   HelpText<"The float ABI to use">;
 def mtp : Separate<["-"], "mtp">,

Modified: cfe/trunk/lib/Basic/Targets/PPC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/PPC.cpp?rev=366044&r1=366043&r2=366044&view=diff
==
--- cfe/trunk/lib/Basic/Targets/PPC.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/PPC.cpp Mon Jul 15 00:25:11 2019
@@ -466,7 +466,9 @@ void PPCTargetInfo::adjust(LangOptions &
 Opts.AltiVec = 1;
   TargetInfo::adjust(Opts);
   if (LongDoubleFormat != &llvm::APFloat::IEEEdouble())
-LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble();
+LongDoubleFormat = Opts.PPCIEEELongDouble
+   ? &llvm::APFloat::IEEEquad()
+   : &llvm::APFloat::PPCDoubleDouble();
 }
 
 ArrayRef PPCTargetInfo::getTargetBuiltins() const {

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=366044&r1=366043&r2=366044&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Jul 15 00:25:11 2019
@@ -1803,12 +1803,21 @@ void Clang::AddPPCTargetArgs(const ArgLi
   break;
 }
 
-  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
-// The ppc64 linux abis are all "altivec" abis by default. Accept and 
ignore
-// the option if given as we don't have backend support for any targets
-// that don't use the altivec abi.
-if (StringRef(A->getValue()) != "altivec")
+  bool IEEELongDouble = false;
+  for (const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
+StringRef V = A->getValue();
+if (V == "ieeelongdouble")
+  IEEELongDouble = true;
+els

[PATCH] D64274: [analyzer] VirtualCallChecker overhaul.

2019-07-15 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

Hmm, I still fail to understand the problem with the current `VirtualCall` 
checker. Is it unstable? Does it report many false positives?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64274/new/

https://reviews.llvm.org/D64274



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64624: [clangd] Added highlighting to enum constants.

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom marked an inline comment as done.
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:257
+  case HighlightingKind::EnumConstant:
+return "constant.other.enum.cpp";
   case HighlightingKind::Namespace:

hokein wrote:
> hokein wrote:
> > could you check the tm scope on vscode? They seem to use 
> > `variable.other.enummember`.
> this comment is undone, vscode is using 
> https://github.com/microsoft/vscode/blob/master/extensions/cpp/syntaxes/cpp.tmLanguage.json#L10024
Oh yeah, I was going to write a comment about keeping it as 
`constant.other.enum` or something similar to it. Because it's not really a 
variable. But as we've stuck to the same TM scopes as vscode we should probably 
keep doing that so I'll change to `variable.other.enummember` and land.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64624/new/

https://reviews.llvm.org/D64624



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64477: [ASTImporter] Using Lang_CXX14 in ASTImporterVisibilityTest.

2019-07-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 209768.
balazske added a comment.

- Change to Lang_CXX14.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64477/new/

https://reviews.llvm.org/D64477

Files:
  unittests/AST/ASTImporterVisibilityTest.cpp


Index: unittests/AST/ASTImporterVisibilityTest.cpp
===
--- unittests/AST/ASTImporterVisibilityTest.cpp
+++ unittests/AST/ASTImporterVisibilityTest.cpp
@@ -80,13 +80,13 @@
 std::string Code = getCode() + getCode();
 auto Pattern = getPattern();
 
-TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX, "input0.cc");
+TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX14, "input0.cc");
 
 auto *FromD0 = FirstDeclMatcher().match(FromTu, Pattern);
 auto *FromD1 = LastDeclMatcher().match(FromTu, Pattern);
 
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD0 = Import(FromD0, Lang_CXX14);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 
 EXPECT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
@@ -157,13 +157,14 @@
   BindableMatcher getPattern() const { return PatternFactory()(); }
 
   void TypedTest_ImportAfter() {
-TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX);
-TranslationUnitDecl *FromTu = getTuDecl(getCode1(), Lang_CXX, "input1.cc");
+TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14);
+TranslationUnitDecl *FromTu =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 
 auto *ToD0 = FirstDeclMatcher().match(ToTu, getPattern());
 auto *FromD1 = FirstDeclMatcher().match(FromTu, getPattern());
 
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 
 ASSERT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
@@ -176,12 +177,14 @@
   }
 
   void TypedTest_ImportAfterImport() {
-TranslationUnitDecl *FromTu0 = getTuDecl(getCode0(), Lang_CXX, 
"input0.cc");
-TranslationUnitDecl *FromTu1 = getTuDecl(getCode1(), Lang_CXX, 
"input1.cc");
+TranslationUnitDecl *FromTu0 =
+getTuDecl(getCode0(), Lang_CXX14, "input0.cc");
+TranslationUnitDecl *FromTu1 =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 auto *FromD0 = FirstDeclMatcher().match(FromTu0, getPattern());
 auto *FromD1 = FirstDeclMatcher().match(FromTu1, getPattern());
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD0 = Import(FromD0, Lang_CXX14);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 ASSERT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
 EXPECT_NE(ToD0, ToD1);
@@ -192,13 +195,14 @@
   }
 
   void TypedTest_ImportAfterWithMerge() {
-TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX);
-TranslationUnitDecl *FromTu = getTuDecl(getCode1(), Lang_CXX, "input1.cc");
+TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14);
+TranslationUnitDecl *FromTu =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 
 auto *ToF0 = FirstDeclMatcher().match(ToTu, getPattern());
 auto *FromF1 = FirstDeclMatcher().match(FromTu, getPattern());
 
-auto *ToF1 = Import(FromF1, Lang_CXX);
+auto *ToF1 = Import(FromF1, Lang_CXX14);
 
 ASSERT_TRUE(ToF0);
 ASSERT_TRUE(ToF1);
@@ -213,12 +217,14 @@
   }
 
   void TypedTest_ImportAfterImportWithMerge() {
-TranslationUnitDecl *FromTu0 = getTuDecl(getCode0(), Lang_CXX, 
"input0.cc");
-TranslationUnitDecl *FromTu1 = getTuDecl(getCode1(), Lang_CXX, 
"input1.cc");
+TranslationUnitDecl *FromTu0 =
+getTuDecl(getCode0(), Lang_CXX14, "input0.cc");
+TranslationUnitDecl *FromTu1 =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 auto *FromF0 = FirstDeclMatcher().match(FromTu0, getPattern());
 auto *FromF1 = FirstDeclMatcher().match(FromTu1, getPattern());
-auto *ToF0 = Import(FromF0, Lang_CXX);
-auto *ToF1 = Import(FromF1, Lang_CXX);
+auto *ToF0 = Import(FromF0, Lang_CXX14);
+auto *ToF1 = Import(FromF1, Lang_CXX14);
 ASSERT_TRUE(ToF0);
 ASSERT_TRUE(ToF1);
 if (shouldBeLinked())


Index: unittests/AST/ASTImporterVisibilityTest.cpp
===
--- unittests/AST/ASTImporterVisibilityTest.cpp
+++ unittests/AST/ASTImporterVisibilityTest.cpp
@@ -80,13 +80,13 @@
 std::string Code = getCode() + getCode();
 auto Pattern = getPattern();
 
-TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX, "input0.cc");
+TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX14, "input0.cc");
 
 auto *FromD0 = FirstDeclMatcher().match(FromTu, Pattern);
 auto *FromD1 = LastDeclMatcher().match(FromTu, Pattern);
 
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD0 = Import(FromD0, Lang_CXX14);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 
 EXPECT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
@@ -157,13 +157,14 @@
   BindableMatcher getPatter

[clang-tools-extra] r366045 - [clangd] Added highlighting to enum constants.

2019-07-15 Thread Johan Vikstrom via cfe-commits
Author: jvikstrom
Date: Mon Jul 15 00:41:12 2019
New Revision: 366045

URL: http://llvm.org/viewvc/llvm-project?rev=366045&view=rev
Log:
[clangd] Added highlighting to enum constants.

Summary: VSCode does not have a scope for enum constants. So they were placed 
under "constant.other.enum" as that seems to be the most correct scope for enum 
constants. However, this makes theia color them blue (the same color it uses 
for keywords).

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64624

Modified:
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/SemanticHighlighting.h
clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=366045&r1=366044&r2=366045&view=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Mon Jul 15 00:41:12 
2019
@@ -119,6 +119,10 @@ private:
   addToken(Loc, HighlightingKind::Enum);
   return;
 }
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::EnumConstant);
+  return;
+}
 if (isa(D)) {
   addToken(Loc, HighlightingKind::Variable);
   return;
@@ -249,6 +253,8 @@ llvm::StringRef toTextMateScope(Highligh
 return "entity.name.type.class.cpp";
   case HighlightingKind::Enum:
 return "entity.name.type.enum.cpp";
+  case HighlightingKind::EnumConstant:
+return "variable.other.enummember.cpp";
   case HighlightingKind::Namespace:
 return "entity.name.namespace.cpp";
   case HighlightingKind::NumKinds:

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.h?rev=366045&r1=366044&r2=366045&view=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.h (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.h Mon Jul 15 00:41:12 
2019
@@ -28,6 +28,7 @@ enum class HighlightingKind {
   Function,
   Class,
   Enum,
+  EnumConstant,
   Namespace,
 
   NumKinds,

Modified: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/semantic-highlighting.test?rev=366045&r1=366044&r2=366045&view=diff
==
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test (original)
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test Mon Jul 15 
00:41:12 2019
@@ -17,6 +17,9 @@
 # CHECK-NEXT:"entity.name.type.enum.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
+# CHECK-NEXT:"variable.other.enummember.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.namespace.cpp"
 # CHECK-NEXT:  ]
 # CHECK-NEXT:]

Modified: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp?rev=366045&r1=366044&r2=366045&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Mon 
Jul 15 00:41:12 2019
@@ -37,7 +37,8 @@ void checkHighlightings(llvm::StringRef
   {HighlightingKind::Function, "Function"},
   {HighlightingKind::Class, "Class"},
   {HighlightingKind::Enum, "Enum"},
-  {HighlightingKind::Namespace, "Namespace"}};
+  {HighlightingKind::Namespace, "Namespace"},
+  {HighlightingKind::EnumConstant, "EnumConstant"}};
   std::vector ExpectedTokens;
   for (const auto &KindString : KindToString) {
 std::vector Toks = makeHighlightingTokens(
@@ -103,12 +104,19 @@ TEST(SemanticHighlighting, GetsCorrectTo
   }
 )cpp",
 R"cpp(
-  enum class $Enum[[E]] {};
-  enum $Enum[[EE]] {};
+  enum class $Enum[[E]] {
+$EnumConstant[[A]],
+$EnumConstant[[B]],
+  };
+  enum $Enum[[EE]] {
+$EnumConstant[[Hi]],
+  };
   struct $Class[[A]] {
 $Enum[[E]] EEE;
 $Enum[[EE]] ;
   };
+  int $Variable[[I]] = $EnumConstant[[Hi]];
+  $Enum[[E]] $Variable[[L]] = $Enum[[E]]::$EnumConstant[[B]];
 )cpp",
 R"cpp(
   namespace $Namespace[[abc]] {
@@ -118,7 +126,7 @@ TEST(SemanticHighlighting, GetsCorrectTo
   nam

[PATCH] D64624: [clangd] Added highlighting to enum constants.

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366045: [clangd] Added highlighting to enum constants. 
(authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64624?vs=209514&id=209769#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64624/new/

https://reviews.llvm.org/D64624

Files:
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
  clang-tools-extra/trunk/clangd/SemanticHighlighting.h
  clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
  clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -119,6 +119,10 @@
   addToken(Loc, HighlightingKind::Enum);
   return;
 }
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::EnumConstant);
+  return;
+}
 if (isa(D)) {
   addToken(Loc, HighlightingKind::Variable);
   return;
@@ -249,6 +253,8 @@
 return "entity.name.type.class.cpp";
   case HighlightingKind::Enum:
 return "entity.name.type.enum.cpp";
+  case HighlightingKind::EnumConstant:
+return "variable.other.enummember.cpp";
   case HighlightingKind::Namespace:
 return "entity.name.namespace.cpp";
   case HighlightingKind::NumKinds:
Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -37,7 +37,8 @@
   {HighlightingKind::Function, "Function"},
   {HighlightingKind::Class, "Class"},
   {HighlightingKind::Enum, "Enum"},
-  {HighlightingKind::Namespace, "Namespace"}};
+  {HighlightingKind::Namespace, "Namespace"},
+  {HighlightingKind::EnumConstant, "EnumConstant"}};
   std::vector ExpectedTokens;
   for (const auto &KindString : KindToString) {
 std::vector Toks = makeHighlightingTokens(
@@ -103,12 +104,19 @@
   }
 )cpp",
 R"cpp(
-  enum class $Enum[[E]] {};
-  enum $Enum[[EE]] {};
+  enum class $Enum[[E]] {
+$EnumConstant[[A]],
+$EnumConstant[[B]],
+  };
+  enum $Enum[[EE]] {
+$EnumConstant[[Hi]],
+  };
   struct $Class[[A]] {
 $Enum[[E]] EEE;
 $Enum[[EE]] ;
   };
+  int $Variable[[I]] = $EnumConstant[[Hi]];
+  $Enum[[E]] $Variable[[L]] = $Enum[[E]]::$EnumConstant[[B]];
 )cpp",
 R"cpp(
   namespace $Namespace[[abc]] {
@@ -118,7 +126,7 @@
   namespace $Namespace[[cde]] {
 struct $Class[[A]] {
   enum class $Enum[[B]] {
-Hi,
+$EnumConstant[[Hi]],
   };
 };
   }
@@ -129,7 +137,7 @@
 $Namespace[[abc]]::$Namespace[[bcd]]::$Namespace[[cde]];
   $Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable[[AA]];
   $Namespace[[vwz]]::$Class[[A]]::$Enum[[B]] $Variable[[AAA]] =
-$Namespace[[vwz]]::$Class[[A]]::$Enum[[B]]::Hi;
+$Namespace[[vwz]]::$Class[[A]]::$Enum[[B]]::$EnumConstant[[Hi]];
   ::$Namespace[[vwz]]::$Class[[A]] $Variable[[B]];
   ::$Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable[[BB]];
 )cpp"};
Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.h
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.h
@@ -28,6 +28,7 @@
   Function,
   Class,
   Enum,
+  EnumConstant,
   Namespace,
 
   NumKinds,
Index: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
===
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
@@ -17,6 +17,9 @@
 # CHECK-NEXT:"entity.name.type.enum.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
+# CHECK-NEXT:"variable.other.enummember.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.namespace.cpp"
 # CHECK-NEXT:  ]
 # CHECK-NEXT:]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r366047 - [clangd] Added highlighting for members and methods.

2019-07-15 Thread Johan Vikstrom via cfe-commits
Author: jvikstrom
Date: Mon Jul 15 01:12:21 2019
New Revision: 366047

URL: http://llvm.org/viewvc/llvm-project?rev=366047&view=rev
Log:
[clangd] Added highlighting for members and methods.

Summary: Added highlighting for members and methods.

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64617

Modified:
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/SemanticHighlighting.h
clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=366047&r1=366046&r2=366047&view=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Mon Jul 15 01:12:21 
2019
@@ -40,6 +40,16 @@ public:
 return true;
   }
 
+  bool VisitMemberExpr(MemberExpr *ME) {
+const auto *MD = ME->getMemberDecl();
+if (isa(MD))
+  // When calling the destructor manually like: AAA::~A(); The ~ is a
+  // MemberExpr. Other methods should still be highlighted though.
+  return true;
+addToken(ME->getMemberLoc(), MD);
+return true;
+  }
+
   bool VisitNamedDecl(NamedDecl *ND) {
 // UsingDirectiveDecl's namespaces do not show up anywhere else in the
 // Visit/Traverse mehods. But they should also be highlighted as a
@@ -115,6 +125,14 @@ private:
   addToken(Loc, HighlightingKind::Class);
   return;
 }
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Method);
+  return;
+}
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Field);
+  return;
+}
 if (isa(D)) {
   addToken(Loc, HighlightingKind::Enum);
   return;
@@ -247,8 +265,12 @@ llvm::StringRef toTextMateScope(Highligh
   switch (Kind) {
   case HighlightingKind::Function:
 return "entity.name.function.cpp";
+  case HighlightingKind::Method:
+return "entity.name.function.method.cpp";
   case HighlightingKind::Variable:
-return "variable.cpp";
+return "variable.other.cpp";
+  case HighlightingKind::Field:
+return "variable.other.field.cpp";
   case HighlightingKind::Class:
 return "entity.name.type.class.cpp";
   case HighlightingKind::Enum:

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.h?rev=366047&r1=366046&r2=366047&view=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.h (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.h Mon Jul 15 01:12:21 
2019
@@ -26,6 +26,8 @@ namespace clangd {
 enum class HighlightingKind {
   Variable = 0,
   Function,
+  Method,
+  Field,
   Class,
   Enum,
   EnumConstant,

Modified: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/semantic-highlighting.test?rev=366047&r1=366046&r2=366047&view=diff
==
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test (original)
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test Mon Jul 15 
01:12:21 2019
@@ -5,12 +5,18 @@
 # CHECK:  "semanticHighlighting": {
 # CHECK-NEXT:"scopes": [
 # CHECK-NEXT:  [
-# CHECK-NEXT:"variable.cpp"
+# CHECK-NEXT:"variable.other.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.function.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
+# CHECK-NEXT:"entity.name.function.method.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
+# CHECK-NEXT:"variable.other.field.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.type.class.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [

Modified: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp?rev=366047&r1=366046&r2=366047&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Mon 
Jul 15 01:12:21 2019
@@ -38,7 +38,9 @@ void checkHighlightings(llvm::StringRef
   {HighlightingKind::Class, "Class"},
   {HighlightingKind::Enum, "Enum"},
   {Highlighting

[PATCH] D64617: [clangd] Added highlighting for members and methods

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366047: [clangd] Added highlighting for members and methods. 
(authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64617?vs=209510&id=209770#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64617/new/

https://reviews.llvm.org/D64617

Files:
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
  clang-tools-extra/trunk/clangd/SemanticHighlighting.h
  clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
  clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
===
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
@@ -5,12 +5,18 @@
 # CHECK:  "semanticHighlighting": {
 # CHECK-NEXT:"scopes": [
 # CHECK-NEXT:  [
-# CHECK-NEXT:"variable.cpp"
+# CHECK-NEXT:"variable.other.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.function.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
+# CHECK-NEXT:"entity.name.function.method.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
+# CHECK-NEXT:"variable.other.field.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.type.class.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -38,7 +38,9 @@
   {HighlightingKind::Class, "Class"},
   {HighlightingKind::Enum, "Enum"},
   {HighlightingKind::Namespace, "Namespace"},
-  {HighlightingKind::EnumConstant, "EnumConstant"}};
+  {HighlightingKind::EnumConstant, "EnumConstant"},
+  {HighlightingKind::Field, "Field"},
+  {HighlightingKind::Method, "Method"}};
   std::vector ExpectedTokens;
   for (const auto &KindString : KindToString) {
 std::vector Toks = makeHighlightingTokens(
@@ -54,14 +56,14 @@
   const char *TestCases[] = {
 R"cpp(
   struct $Class[[AS]] {
-double SomeMember;
+double $Field[[SomeMember]];
   };
   struct {
   } $Variable[[S]];
   void $Function[[foo]](int $Variable[[A]], $Class[[AS]] $Variable[[As]]) {
 auto $Variable[[VeryLongVariableName]] = 12312;
 $Class[[AS]] $Variable[[AA]];
-auto $Variable[[L]] = $Variable[[AA]].SomeMember + $Variable[[A]];
+auto $Variable[[L]] = $Variable[[AA]].$Field[[SomeMember]] + $Variable[[A]];
 auto $Variable[[FN]] = [ $Variable[[AA]]](int $Variable[[A]]) -> void {};
 $Variable[[FN]](12312);
   }
@@ -73,19 +75,19 @@
 auto $Variable[[Bou]] = $Function[[Gah]];
   }
   struct $Class[[A]] {
-void $Function[[abc]]();
+void $Method[[abc]]();
   };
 )cpp",
 R"cpp(
   namespace $Namespace[[abc]] {
 template
 struct $Class[[A]] {
-  T t;
+  T $Field[[t]];
 };
   }
   template
   struct $Class[[C]] : $Namespace[[abc]]::A {
-typename T::A* D;
+typename T::A* $Field[[D]];
   };
   $Namespace[[abc]]::$Class[[A]] $Variable[[AA]];
   typedef $Namespace[[abc]]::$Class[[A]] AAA;
@@ -93,7 +95,7 @@
 $Class[[B]]();
 ~$Class[[B]]();
 void operator<<($Class[[B]]);
-$Class[[AAA]] AA;
+$Class[[AAA]] $Field[[AA]];
   };
   $Class[[B]]::$Class[[B]]() {}
   $Class[[B]]::~$Class[[B]]() {}
@@ -112,8 +114,8 @@
 $EnumConstant[[Hi]],
   };
   struct $Class[[A]] {
-$Enum[[E]] EEE;
-$Enum[[EE]] ;
+$Enum[[E]] $Field[[EEE]];
+$Enum[[EE]] $Field[[]];
   };
   int $Variable[[I]] = $EnumConstant[[Hi]];
   $Enum[[E]] $Variable[[L]] = $Enum[[E]]::$EnumConstant[[B]];
@@ -140,6 +142,30 @@
 $Namespace[[vwz]]::$Class[[A]]::$Enum[[B]]::$EnumConstant[[Hi]];
   ::$Namespace[[vwz]]::$Class[[A]] $Variable[[B]];
   ::$Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable[[BB]];
+)cpp",
+R"cpp(
+  struct $Class[[D]] {
+double $Field[[C]];
+  };
+  struct $Class[[A]] {
+double $Field[[B]];
+$Class[[D]] $Field[[E]];
+static double $Variable[[S]];
+void $Method[[foo]]() {
+  $Field[[B]] = 123;
+  this->$Field[[B]] = 156;
+  this->$Method[[foo]]();
+  $Method[[foo]]();
+  $Variable[[S]] = 90.1

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D64695#1584740 , @Manikishan wrote:

> In D64695#1584706 , @MyDeveloperDay 
> wrote:
>
> > There also seems like alot of duplication between the existing 
> > sortCppIncludes
> >
> > I think the only difference here is really just
> >
> > 
> >
> >   SmallVector Indices;
> > SmallVector Includes_p;
> > for (unsigned i = 0, e = Includes.size(); i != e; ++i) {
> >   unsigned pl = getNetBSDIncludePriority(Includes[i].Filename);
> >   Includes_p.push_back(pl);
> >   Indices.push_back(i);
> > }
> >
> >
> > vs the original
> >
> >   SmallVector Indices;
> >   for (unsigned i = 0, e = Includes.size(); i != e; ++i)
> > Indices.push_back(i);
> >   
> >
> > plus way the sorting is performed, are we sure we couldn't have just made 
> > the original sorting more powerful based on style settings?
>
>
> Does it mean that adding the priority to sort based on style? 
>  like this:
>
>   if (Style== NetBSD)
>  // set priority to netbsd's priority
>   else if(Style == X)
> // set X's priority
>
>
> I didn't want to mess up the original sorting and made up this patch, if we 
> have parameterise this solution, I will go for it.


We should be able to make changes without fear of breaking other code, if we 
can't then we don't have enough tests

I guess my comment was that you patche introduces a lot of code duplication, 
could the small amount of code you added be say put into a lambda and past in 
based on style?




Comment at: lib/Format/Format.cpp:1878
+  SmallVector Indices;
+  SmallVector Includes_p;
+  for (unsigned i = 0, e = Includes.size(); i != e; ++i) {

Manikishan wrote:
> MyDeveloperDay wrote:
> > _p? I don't understand what it stands for?
> > 
> > IncludesPriority?
> Yes , it means priority
I don't think Includes_p matches Clang naming conventions so I recommend 
changing it.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: unittests/Format/SortIncludesTest.cpp:709
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"  
+   "#include \n"  

should you add a test which has groups defined already, I'm unclear as to how 
your algorithm works across groups?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64634: [clangd] Fix duplicate highlighting tokens appearing in initializer lists

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom marked an inline comment as done.
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:36
+// must be deduplicated.
+std::sort(Tokens.begin(), Tokens.end());
+for (unsigned I = 1; I < Tokens.size(); ++I) {

hokein wrote:
> nit: we could write it like
> 
> ```
> llvm::sort(Tokens, [](const HighlightingToken &Lhs, const HighlightingToken 
> &Rhs) {
>return std::tie(Lhs.Kind, Lhs.R) < std::tie(Rhs.Kind, Rhs.R);
> });
> auto Last = std::unique(Tokens.begin(), Tokens.end());
> Tokens.erase(Last, Tokens.end());
> ```
About the comparator function though. I added an < operator because 
https://reviews.llvm.org/D64475 also sorts the tokens. However, could I just 
remove the sort in the main diffHighlightings method and just rely on the 
highlightings to be sorted in the first place from this patch?

Instead we'd do the sorting like:
```
llvm::sort(Tokens, [](const HighlightingToken &Lhs, const HighlightingToken 
&Rhs) {
   return std::tie(Lhs.R,Lhs.Kind) < std::tie(Rhs.R,Rhs.Kind);
});
```

so we get it sorted by their position first and Kind second.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64634/new/

https://reviews.llvm.org/D64634



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64634: [clangd] Fix duplicate highlighting tokens appearing in initializer lists

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 209773.
jvikstrom added a comment.

Remove operator< and use std::unique.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64634/new/

https://reviews.llvm.org/D64634

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,15 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(
+Tokens,
+[](const HighlightingToken &Lhs, const HighlightingToken &Rhs) -> bool 
{
+  return std::tie(Lhs.R, Lhs.Kind) < std::tie(Rhs.R, Rhs.Kind);
+});
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 
@@ -80,7 +89,6 @@
 DeclarationName::Identifier)
   // Only want to highlight identifiers.
   return true;
-
 addToken(Ref->getLocation(), Ref->getDecl());
 return true;
   }


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,15 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(
+Tokens,
+[](const HighlightingToken &Lhs, const HighlightingToken &Rhs) -> bool {
+  return std::tie(Lhs.R, Lhs.Kind) < std::tie(Rhs.R, Rhs.Kind);
+});
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 
@@ -80,7 +89,6 @@
 DeclarationName::Identifier)
   // Only want to highlight identifiers.
   return true;
-
 addToken(Ref->getLocation(), Ref->getDecl());
 return true;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64634: [clangd] Fix duplicate highlighting tokens appearing in initializer lists

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 209774.
jvikstrom added a comment.

Readded newline that was removed accidentaly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64634/new/

https://reviews.llvm.org/D64634

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,15 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(
+Tokens,
+[](const HighlightingToken &Lhs, const HighlightingToken &Rhs) -> bool 
{
+  return std::tie(Lhs.R, Lhs.Kind) < std::tie(Rhs.R, Rhs.Kind);
+});
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,15 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(
+Tokens,
+[](const HighlightingToken &Lhs, const HighlightingToken &Rhs) -> bool {
+  return std::tie(Lhs.R, Lhs.Kind) < std::tie(Rhs.R, Rhs.Kind);
+});
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64634: [clangd] Fix duplicate highlighting tokens appearing in initializer lists

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 209775.
jvikstrom added a comment.

Removed return type hint for lambda.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64634/new/

https://reviews.llvm.org/D64634

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,14 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(Tokens,
+   [](const HighlightingToken &Lhs, const HighlightingToken &Rhs) {
+ return std::tie(Lhs.R, Lhs.Kind) < std::tie(Rhs.R, Rhs.Kind);
+   });
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,14 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(Tokens,
+   [](const HighlightingToken &Lhs, const HighlightingToken &Rhs) {
+ return std::tie(Lhs.R, Lhs.Kind) < std::tie(Rhs.R, Rhs.Kind);
+   });
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added inline comments.



Comment at: unittests/Format/SortIncludesTest.cpp:709
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"  
+   "#include \n"  

MyDeveloperDay wrote:
> should you add a test which has groups defined already, I'm unclear as to how 
> your algorithm works across groups?
The include groups in NetBSD files are made depending on the use, for example 
Kernel headers, File systems headers, Network and protocol headers are grouped 
together. 
My algorithm is to detect the include type by regex and assign a priority to 
them to sort. And to regroup I used IncludeCategories.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 209776.
Manikishan marked an inline comment as done.

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1023,6 +1023,23 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1064,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -2083,6 +2083,10 @@
 /// http://www.gnu.org/prep/standards/standards.html
 FormatStyle getGNUStyle();
 
+/// Returns a format style complying with NetBSD Coding Standards:
+/// 
http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/style?rev=HEAD&content-type=text/x-cvsweb-markup
+FormatStyle getNetBSDStyle();
+
 /// Returns style indicating formatting should be not applied at all.
 FormatStyle getNoStyle();
 


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1023,6 +1023,23 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1064,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -2083,6 +2083,10 @@
 /// http://www.gnu.org/prep/standards/standards.html
 FormatStyle getGNUStyle();
 
+/// Returns a format style complying with NetBSD Coding Standards:
+/// http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/style?rev=HEAD&content-type=text/x-cvsweb-markup
+FormatStyle getNetBSDStyle();
+
 /// Returns style indicating formatting should be not applied at all.
 FormatStyle getNoStyle();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64632: [clang-format] Don't detect call to ObjC class method as C++11 attribute specifier

2019-07-15 Thread Robbie Gibson via Phabricator via cfe-commits
rkgibson2 updated this revision to Diff 209777.
rkgibson2 added a comment.

Add more tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64632/new/

https://reviews.llvm.org/D64632

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7027,6 +7027,12 @@
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
 
+  // Make sure that we do not mistake Objective-C method inside array literals
+  // as attributes, even if those method names are also keywords.
+  verifyFormat("@[ [foo bar] ];");
+  verifyFormat("@[ [NSArray class] ];");
+  verifyFormat("@[ [foo enum] ];");
+
   // Make sure we do not parse attributes as lambda introducers.
   FormatStyle MultiLineFunctions = getLLVMStyle();
   MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -388,6 +388,10 @@
   bool isCpp11AttributeSpecifier(const FormatToken &Tok) {
 if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
   return false;
+// The first square bracket is part of an ObjC array literal
+if (Tok.Previous && Tok.Previous->is(tok::at)) {
+  return false;
+}
 const FormatToken *AttrTok = Tok.Next->Next;
 if (!AttrTok)
   return false;
@@ -400,7 +404,7 @@
 while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
   // ObjC message send. We assume nobody will use : in a C++11 attribute
   // specifier parameter, although this is technically valid:
-  // [[foo(:)]]
+  // [[foo(:)]].
   if (AttrTok->is(tok::colon) ||
   AttrTok->startsSequence(tok::identifier, tok::identifier) ||
   AttrTok->startsSequence(tok::r_paren, tok::identifier))


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7027,6 +7027,12 @@
   // On the other hand, we still need to correctly find array subscripts.
   verifyFormat("int a = std::vector{1, 2, 3}[0];");
 
+  // Make sure that we do not mistake Objective-C method inside array literals
+  // as attributes, even if those method names are also keywords.
+  verifyFormat("@[ [foo bar] ];");
+  verifyFormat("@[ [NSArray class] ];");
+  verifyFormat("@[ [foo enum] ];");
+
   // Make sure we do not parse attributes as lambda introducers.
   FormatStyle MultiLineFunctions = getLLVMStyle();
   MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -388,6 +388,10 @@
   bool isCpp11AttributeSpecifier(const FormatToken &Tok) {
 if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
   return false;
+// The first square bracket is part of an ObjC array literal
+if (Tok.Previous && Tok.Previous->is(tok::at)) {
+  return false;
+}
 const FormatToken *AttrTok = Tok.Next->Next;
 if (!AttrTok)
   return false;
@@ -400,7 +404,7 @@
 while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
   // ObjC message send. We assume nobody will use : in a C++11 attribute
   // specifier parameter, although this is technically valid:
-  // [[foo(:)]]
+  // [[foo(:)]].
   if (AttrTok->is(tok::colon) ||
   AttrTok->startsSequence(tok::identifier, tok::identifier) ||
   AttrTok->startsSequence(tok::r_paren, tok::identifier))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64632: [clang-format] Don't detect call to ObjC class method as C++11 attribute specifier

2019-07-15 Thread Robbie Gibson via Phabricator via cfe-commits
rkgibson2 added a comment.

I don't think I have commit access. Could someone land this for me?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64632/new/

https://reviews.llvm.org/D64632



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64712: [clangd] Refactor background-index shard loading

2019-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, 
ilya-biryukov, mgorny.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64712

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/Background.h
  clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
  clang-tools-extra/clangd/index/BackgroundIndexLoader.h

Index: clang-tools-extra/clangd/index/BackgroundIndexLoader.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/BackgroundIndexLoader.h
@@ -0,0 +1,59 @@
+//===--- Background.h - Build an index in a background thread *- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_INDEX_LOADER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_INDEX_LOADER_H
+
+#include "Path.h"
+#include "index/Background.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+struct ShardInfo {
+  Path AbsolutePath;
+  FileDigest Digest = {};
+  bool CountReferences = false;
+  bool HadErrors = false;
+  std::unique_ptr Shard;
+};
+
+class BackgroundIndexLoader {
+public:
+  BackgroundIndexLoader(llvm::vfs::FileSystem *FS) : FS(FS) {}
+  /// Loads all shards for the TU \p MainFile from \p Storage. Returns false if
+  /// any shards that are first seen for this TU are stale.
+  bool load(PathRef MainFile, BackgroundIndexStorage *Storage);
+
+  /// Consumes the loader and returns all shards.
+  std::vector takeShards() &&;
+
+private:
+  struct CachedShard {
+ShardInfo SI;
+// Strings points to ShardInfo.
+std::vector Edges;
+bool IsStale = false;
+  };
+  std::pair
+  loadShard(PathRef ShardIdentifier, BackgroundIndexStorage *Storage);
+
+  // Cache for Storage lookups.
+  llvm::StringMap LoadedShards;
+
+  llvm::vfs::FileSystem *FS;
+};
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
@@ -0,0 +1,124 @@
+//===-- BackgroundIndexLoader.cpp - ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/BackgroundIndexLoader.h"
+#include "Logger.h"
+#include "Path.h"
+#include "index/Background.h"
+#include "llvm/ADT/DenseSet.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace {
+
+llvm::Optional uriToAbsolutePath(llvm::StringRef URI, PathRef HintPath) {
+  auto U = URI::parse(URI);
+  if (!U)
+return llvm::None;
+  auto AbsolutePath = URI::resolve(*U, HintPath);
+  if (!AbsolutePath)
+return llvm::None;
+  return *AbsolutePath;
+}
+
+bool hasChanged(llvm::vfs::FileSystem *FS, const ShardInfo &SI) {
+  auto Buf = FS->getBufferForFile(SI.AbsolutePath);
+  if (!Buf) {
+elog("Couldn't get buffer for file: {0}: {1}", SI.AbsolutePath,
+ Buf.getError().message());
+// There is no point in indexing an unreadable file.
+return false;
+  }
+  return digest(Buf->get()->getBuffer()) != SI.Digest;
+}
+
+} // namespace
+
+std::pair
+BackgroundIndexLoader::loadShard(PathRef ShardIdentifier,
+ BackgroundIndexStorage *Storage) {
+  auto It = LoadedShards.try_emplace(ShardIdentifier);
+  CachedShard &CS = It.first->getValue();
+  if (!It.second)
+return {CS, true};
+
+  ShardInfo &SI = CS.SI;
+  SI.AbsolutePath = ShardIdentifier;
+  auto Shard = Storage->loadShard(ShardIdentifier);
+  if (!Shard || !Shard->Sources) {
+vlog("Failed to load shard: {0}", ShardIdentifier);
+SI.HadErrors = true;
+CS.IsStale = true;
+return {CS, false};
+  }
+
+  SI.Shard = std::move(Shard);
+  SI.AbsolutePath = ShardIdentifier;
+  for (const auto &It : *SI.Shard->Sources) {
+auto AbsPath = uriToAbsolutePath(It.getKey(), ShardIdentifier);
+if (!AbsPath || *AbsPath != ShardIdentifier) {
+  CS.Edges.push_back(*AbsPath);
+  continue;
+}
+
+const IncludeGraphNode &IGN = It.getValue();
+SI.Digest = IGN.Digest;
+SI.CountReferences = IGN.Flags & IncludeGraphNode::SourceFlag::IsTU;
+SI.HadErrors = IGN.Flags & IncludeGraphNode::SourceFlag::HadErrors;
+ 

[PATCH] D64415: Consistent types and naming for AArch64 target features (NFC)

2019-07-15 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

FWIW I think this looks reasonable. The ARM equivalent uses bitfields such as

  unsigned CRC : 1;
  unsigned Crypto : 1;
  unsigned DSP : 1;
  unsigned Unaligned : 1;
  unsigned DotProd : 1;

Which would make more sense than using unsigned for each individual field. 
Several other targets that I looked at used bool and the Has 
convention so I think this brings AArch64 more in line with non ARM Targets at 
the cost of losing a little coherence with ARM where the name Crypto remains. I 
don't think that this is particularly important as the two have already started 
to diverge with HasDotProd.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64415/new/

https://reviews.llvm.org/D64415



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.



> I guess my comment was that you patche introduces a lot of code duplication, 
> could the small amount of code you added be say put into a lambda and past in 
> based on style?

Yes, I will add that and submit a patch soon.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64628: [CrossTU] Test change only: improve ctu-main.c

2019-07-15 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D64628#1584969 , @balazske wrote:

> The mentioned commit has a test that reproduces the same problem, so this 
> revision is not needed (abandon it?).


I think we should have this change, because it tests also if we can import the 
"extern implicit" function properly. Plus the bug visitor is exercised when the 
AST is merged.
So, even if the mentioned commit has a similar test I think with these changes 
we can achieve higher coverage and can prevent CTU related regression.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64628/new/

https://reviews.llvm.org/D64628



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64477: [ASTImporter] Using Lang_CXX14 in ASTImporterVisibilityTest.

2019-07-15 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.

Does it really matter if it is CXX11 or CXX14, in the child patch we use a 
CXX11 using directive. Anyway, CXX14 is more future proof.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64477/new/

https://reviews.llvm.org/D64477



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62584: [OpenCL][PR42033] Deducing addr space with template parameter types

2019-07-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D62584#1583340 , @rjmccall wrote:

> Oh, yes, it definitely can't be done to class types.  I suppose we should 
> just forget about it.


Ok, regarding address space qualifiers in template instantiation - is it still 
ok that we ignore them here in this patch?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62584/new/

https://reviews.llvm.org/D62584



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64677: [SemaTemplate] Fix uncorrected typos after pack expansion

2019-07-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang/lib/Sema/SemaTemplateVariadic.cpp:622
 << Pattern->getSourceRange();
+CorrectDelayedTyposInExpr(Pattern);
 return ExprError();

kadircet wrote:
> why not directly `return CorrectDelayedTyposInExpr(Pattern);` ?
Because the error isn't that `Pattern` is invalid per se (in a way that 
CorrectDelayedTyposInExpr can see), but rather that there's no pack to expand.

So even if CorrectDelayedTyposInExpr returns something valid, we still want to 
return ExprError(). We call it for its side-effects of flushing typos and 
emitting diagnostics.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64677/new/

https://reviews.llvm.org/D64677



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61989: [clang-tidy] enable modernize-concat-nested-namespaces on header files

2019-07-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h:1
+#pragma once
+

Please put the header under Inputs// directory to keep the tests 
directory a bit tidier. The header can then be renamed to something shorter, 
btw.



Comment at: 
clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h:1
+#pragma once
+

alexfh wrote:
> Please put the header under Inputs// directory to keep the tests 
> directory a bit tidier. The header can then be renamed to something shorter, 
> btw.
Is it important to use `#pragma once` in this file? Can we use regular include 
guards instead?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61989/new/

https://reviews.llvm.org/D61989



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64083: [OpenCL][Sema] Improve address space support for blocks

2019-07-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D64083#1583110 , @rjmccall wrote:

> In D64083#1583109 , @rjmccall wrote:
>
> > Okay, so it sounds like *from the language perspective* all block pointers 
> > are actually pointers into `__generic`, and the thing with literals is just 
> > an implementation detail that's been inappropriately expressed in the AST.  
> > The better implementation strategy is to make sure that (1) the AST uses 
> > the size/alignment of a `__generic` pointer for a block pointer and (2) 
> > IRGen implicitly converts block literals to `__generic` pointers when it 
> > emits them, and then there's no such thing as a block pointer to a 
> > qualified type.
>
>
> This is actually important to get right in C++ because of `auto` and 
> templates; you really don't want non-generic block pointer types to become an 
> expressible thing in the language.


Yes, I agree. Right now it fails but the diagnostic is wrong.

In D64083#1583110 , @rjmccall wrote:

> In D64083#1583109 , @rjmccall wrote:
>
> > Okay, so it sounds like *from the language perspective* all block pointers 
> > are actually pointers into `__generic`, and the thing with literals is just 
> > an implementation detail that's been inappropriately expressed in the AST.  
> > The better implementation strategy is to make sure that (1) the AST uses 
> > the size/alignment of a `__generic` pointer for a block pointer and (2) 
> > IRGen implicitly converts block literals to `__generic` pointers when it 
> > emits them, and then there's no such thing as a block pointer to a 
> > qualified type.
>
>
> This is actually important to get right in C++ because of `auto` and 
> templates; you really don't want non-generic block pointer types to become an 
> expressible thing in the language.


I agree. I have opened a bug to follow up on this: 
https://bugs.llvm.org/show_bug.cgi?id=42621. We can still simplify the code in 
this patch for now, although I expect in the future it won't be needed.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64083/new/

https://reviews.llvm.org/D64083



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59426: [PR41010][OpenCL] Allow OpenCL C style vector initialization in C++

2019-07-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

@rsmith, do you have any comments here? It would be quite useful to have this 
patch in Clang9.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59426/new/

https://reviews.llvm.org/D59426



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64418: [Docs][OpenCL] Documentation of C++ for OpenCL mode

2019-07-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia marked an inline comment as done.
Anastasia added inline comments.



Comment at: docs/LanguageExtensions.rst:1772
+``@_GLOBAL__sub_I_test.cl`` kernel to be enqueued.
+
+

I think I should add something about dtors too.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64418/new/

https://reviews.llvm.org/D64418



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r366059 - [OpenCL][PR41727] Prevent ICE on global dtors

2019-07-15 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Jul 15 04:58:10 2019
New Revision: 366059

URL: http://llvm.org/viewvc/llvm-project?rev=366059&view=rev
Log:
[OpenCL][PR41727] Prevent ICE on global dtors

Pass NULL to pointer arg of __cxa_atexit if addr space
is not matching with its param. This doesn't align yet
with how dtors are generated that should be changed too.

Differential Revision: https://reviews.llvm.org/D62413


Added:
cfe/trunk/test/CodeGenOpenCLCXX/atexit.cl
Modified:
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/TargetInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=366059&r1=366058&r2=366059&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Jul 15 04:58:10 2019
@@ -14,6 +14,7 @@
 #include "CGCXXABI.h"
 #include "CGObjCRuntime.h"
 #include "CGOpenMPRuntime.h"
+#include "TargetInfo.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Intrinsics.h"
@@ -118,9 +119,22 @@ static void EmitDeclDestroy(CodeGenFunct
 CXXDestructorDecl *Dtor = Record->getDestructor();
 
 Func = CGM.getAddrAndTypeOfCXXStructor(GlobalDecl(Dtor, Dtor_Complete));
-Argument = llvm::ConstantExpr::getBitCast(
-Addr.getPointer(), CGF.getTypes().ConvertType(Type)->getPointerTo());
-
+if (CGF.getContext().getLangOpts().OpenCL) {
+  auto DestAS =
+  CGM.getTargetCodeGenInfo().getAddrSpaceOfCxaAtexitPtrParam();
+  auto DestTy = CGF.getTypes().ConvertType(Type)->getPointerTo(
+  CGM.getContext().getTargetAddressSpace(DestAS));
+  auto SrcAS = D.getType().getQualifiers().getAddressSpace();
+  if (DestAS == SrcAS)
+Argument = llvm::ConstantExpr::getBitCast(Addr.getPointer(), DestTy);
+  else
+// FIXME: On addr space mismatch we are passing NULL. The generation
+// of the global destructor function should be adjusted accordingly.
+Argument = llvm::ConstantPointerNull::get(DestTy);
+} else {
+  Argument = llvm::ConstantExpr::getBitCast(
+  Addr.getPointer(), CGF.getTypes().ConvertType(Type)->getPointerTo());
+}
   // Otherwise, the standard logic requires a helper function.
   } else {
 Func = CodeGenFunction(CGM)

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=366059&r1=366058&r2=366059&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jul 15 04:58:10 2019
@@ -3577,8 +3577,12 @@ llvm::Constant *CodeGenModule::GetAddrOf
 llvm::Constant *
 CodeGenModule::CreateRuntimeVariable(llvm::Type *Ty,
  StringRef Name) {
-  auto *Ret =
-  GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty), nullptr);
+  auto PtrTy =
+  getContext().getLangOpts().OpenCL
+  ? llvm::PointerType::get(
+Ty, getContext().getTargetAddressSpace(LangAS::opencl_global))
+  : llvm::PointerType::getUnqual(Ty);
+  auto *Ret = GetOrCreateLLVMGlobal(Name, PtrTy, nullptr);
   setDSOLocal(cast(Ret->stripPointerCasts()));
   return Ret;
 }

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=366059&r1=366058&r2=366059&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon Jul 15 04:58:10 2019
@@ -2284,8 +2284,19 @@ static void emitGlobalDtorWithCXAAtExit(
   llvm::Type *dtorTy =
 llvm::FunctionType::get(CGF.VoidTy, CGF.Int8PtrTy, false)->getPointerTo();
 
+  // Preserve address space of addr.
+  auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0;
+  auto AddrInt8PtrTy =
+  AddrAS ? CGF.Int8Ty->getPointerTo(AddrAS) : CGF.Int8PtrTy;
+
+  // Create a variable that binds the atexit to this shared object.
+  llvm::Constant *handle =
+  CGF.CGM.CreateRuntimeVariable(CGF.Int8Ty, "__dso_handle");
+  auto *GV = cast(handle->stripPointerCasts());
+  GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+
   // extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d);
-  llvm::Type *paramTys[] = { dtorTy, CGF.Int8PtrTy, CGF.Int8PtrTy };
+  llvm::Type *paramTys[] = {dtorTy, AddrInt8PtrTy, handle->getType()};
   llvm::FunctionType *atexitTy =
 llvm::FunctionType::get(CGF.IntTy, paramTys, false);
 
@@ -2294,12 +2305,6 @@ static void emitGlobalDtorWithCXAAtExit(
   if (llvm::Function *fn = dyn_cast(atexit.getCallee()))
 fn->setDoesNotThrow();
 
-  // Create 

[PATCH] D62413: [OpenCL][PR41727] Prevent ICE on global dtors

2019-07-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366059: [OpenCL][PR41727] Prevent ICE on global dtors 
(authored by stulova, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62413?vs=209463&id=209804#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62413/new/

https://reviews.llvm.org/D62413

Files:
  cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/lib/CodeGen/TargetInfo.h
  cfe/trunk/test/CodeGenOpenCLCXX/atexit.cl

Index: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
===
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2284,8 +2284,19 @@
   llvm::Type *dtorTy =
 llvm::FunctionType::get(CGF.VoidTy, CGF.Int8PtrTy, false)->getPointerTo();
 
+  // Preserve address space of addr.
+  auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0;
+  auto AddrInt8PtrTy =
+  AddrAS ? CGF.Int8Ty->getPointerTo(AddrAS) : CGF.Int8PtrTy;
+
+  // Create a variable that binds the atexit to this shared object.
+  llvm::Constant *handle =
+  CGF.CGM.CreateRuntimeVariable(CGF.Int8Ty, "__dso_handle");
+  auto *GV = cast(handle->stripPointerCasts());
+  GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+
   // extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d);
-  llvm::Type *paramTys[] = { dtorTy, CGF.Int8PtrTy, CGF.Int8PtrTy };
+  llvm::Type *paramTys[] = {dtorTy, AddrInt8PtrTy, handle->getType()};
   llvm::FunctionType *atexitTy =
 llvm::FunctionType::get(CGF.IntTy, paramTys, false);
 
@@ -2294,12 +2305,6 @@
   if (llvm::Function *fn = dyn_cast(atexit.getCallee()))
 fn->setDoesNotThrow();
 
-  // Create a variable that binds the atexit to this shared object.
-  llvm::Constant *handle =
-  CGF.CGM.CreateRuntimeVariable(CGF.Int8Ty, "__dso_handle");
-  auto *GV = cast(handle->stripPointerCasts());
-  GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
-
   if (!addr)
 // addr is null when we are trying to register a dtor annotated with
 // __attribute__((destructor)) in a constructor function. Using null here is
@@ -2309,7 +2314,7 @@
 
   llvm::Value *args[] = {llvm::ConstantExpr::getBitCast(
  cast(dtor.getCallee()), dtorTy),
- llvm::ConstantExpr::getBitCast(addr, CGF.Int8PtrTy),
+ llvm::ConstantExpr::getBitCast(addr, AddrInt8PtrTy),
  handle};
   CGF.EmitNounwindRuntimeCall(atexit, args);
 }
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -3577,8 +3577,12 @@
 llvm::Constant *
 CodeGenModule::CreateRuntimeVariable(llvm::Type *Ty,
  StringRef Name) {
-  auto *Ret =
-  GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty), nullptr);
+  auto PtrTy =
+  getContext().getLangOpts().OpenCL
+  ? llvm::PointerType::get(
+Ty, getContext().getTargetAddressSpace(LangAS::opencl_global))
+  : llvm::PointerType::getUnqual(Ty);
+  auto *Ret = GetOrCreateLLVMGlobal(Name, PtrTy, nullptr);
   setDSOLocal(cast(Ret->stripPointerCasts()));
   return Ret;
 }
Index: cfe/trunk/lib/CodeGen/TargetInfo.h
===
--- cfe/trunk/lib/CodeGen/TargetInfo.h
+++ cfe/trunk/lib/CodeGen/TargetInfo.h
@@ -267,6 +267,11 @@
LangAS SrcAddr, LangAS DestAddr,
llvm::Type *DestTy) const;
 
+  /// Get address space of pointer parameter for __cxa_atexit.
+  virtual LangAS getAddrSpaceOfCxaAtexitPtrParam() const {
+return LangAS::Default;
+  }
+
   /// Get the syncscope used in LLVM IR.
   virtual llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts,
  SyncScope Scope,
Index: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
===
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
@@ -14,6 +14,7 @@
 #include "CGCXXABI.h"
 #include "CGObjCRuntime.h"
 #include "CGOpenMPRuntime.h"
+#include "TargetInfo.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Intrinsics.h"
@@ -118,9 +119,22 @@
 CXXDestructorDecl *Dtor = Record->getDestructor();
 
 Func = CGM.getAddrAndTypeOfCXXStructor(GlobalDecl(Dtor, Dtor_Complete));
-Argument = llvm::ConstantExpr::getBitCast(
-Addr.getPointer(), CGF.getTypes().ConvertType(Type)->getPointerTo());
-
+if (CGF.getContext().getLangOpts().OpenCL) 

[PATCH] D64477: [ASTImporter] Using Lang_CXX14 in ASTImporterVisibilityTest.

2019-07-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

In D64477#1585092 , @martong wrote:

> Does it really matter if it is CXX11 or CXX14, in the child patch we use a 
> CXX11 using directive. Anyway, CXX14 is more future proof.


Later there should follow the test with variable template that produces 
warnings again if not `Lang_CXX14` is used.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64477/new/

https://reviews.llvm.org/D64477



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64477: [ASTImporter] Using Lang_CXX14 in ASTImporterVisibilityTest.

2019-07-15 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D64477#1585218 , @balazske wrote:

> In D64477#1585092 , @martong wrote:
>
> > Does it really matter if it is CXX11 or CXX14, in the child patch we use a 
> > CXX11 using directive. Anyway, CXX14 is more future proof.
>
>
> Later there should follow the test with variable template that produces 
> warnings again if not `Lang_CXX14` is used.


Ok 👍


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64477/new/

https://reviews.llvm.org/D64477



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r366061 - [ASTImporter] Using Lang_CXX14 in ASTImporterVisibilityTest.

2019-07-15 Thread Balazs Keri via cfe-commits
Author: balazske
Date: Mon Jul 15 05:16:30 2019
New Revision: 366061

URL: http://llvm.org/viewvc/llvm-project?rev=366061&view=rev
Log:
[ASTImporter] Using Lang_CXX14 in ASTImporterVisibilityTest.

Summary:
These tests may work with C++14 language constructs in the future
(variable templates and others).
To avoid warnings about language version C++ version constants in the tests
are updated.

Reviewers: martong, a.sidorin

Reviewed By: martong

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64477

Modified:
cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp

Modified: cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp?rev=366061&r1=366060&r2=366061&view=diff
==
--- cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp Mon Jul 15 05:16:30 
2019
@@ -80,13 +80,13 @@ protected:
 std::string Code = getCode() + getCode();
 auto Pattern = getPattern();
 
-TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX, "input0.cc");
+TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX14, "input0.cc");
 
 auto *FromD0 = FirstDeclMatcher().match(FromTu, Pattern);
 auto *FromD1 = LastDeclMatcher().match(FromTu, Pattern);
 
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD0 = Import(FromD0, Lang_CXX14);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 
 EXPECT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
@@ -157,13 +157,14 @@ protected:
   BindableMatcher getPattern() const { return PatternFactory()(); }
 
   void TypedTest_ImportAfter() {
-TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX);
-TranslationUnitDecl *FromTu = getTuDecl(getCode1(), Lang_CXX, "input1.cc");
+TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14);
+TranslationUnitDecl *FromTu =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 
 auto *ToD0 = FirstDeclMatcher().match(ToTu, getPattern());
 auto *FromD1 = FirstDeclMatcher().match(FromTu, getPattern());
 
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 
 ASSERT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
@@ -176,12 +177,14 @@ protected:
   }
 
   void TypedTest_ImportAfterImport() {
-TranslationUnitDecl *FromTu0 = getTuDecl(getCode0(), Lang_CXX, 
"input0.cc");
-TranslationUnitDecl *FromTu1 = getTuDecl(getCode1(), Lang_CXX, 
"input1.cc");
+TranslationUnitDecl *FromTu0 =
+getTuDecl(getCode0(), Lang_CXX14, "input0.cc");
+TranslationUnitDecl *FromTu1 =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 auto *FromD0 = FirstDeclMatcher().match(FromTu0, getPattern());
 auto *FromD1 = FirstDeclMatcher().match(FromTu1, getPattern());
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD0 = Import(FromD0, Lang_CXX14);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 ASSERT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
 EXPECT_NE(ToD0, ToD1);
@@ -192,13 +195,14 @@ protected:
   }
 
   void TypedTest_ImportAfterWithMerge() {
-TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX);
-TranslationUnitDecl *FromTu = getTuDecl(getCode1(), Lang_CXX, "input1.cc");
+TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14);
+TranslationUnitDecl *FromTu =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 
 auto *ToF0 = FirstDeclMatcher().match(ToTu, getPattern());
 auto *FromF1 = FirstDeclMatcher().match(FromTu, getPattern());
 
-auto *ToF1 = Import(FromF1, Lang_CXX);
+auto *ToF1 = Import(FromF1, Lang_CXX14);
 
 ASSERT_TRUE(ToF0);
 ASSERT_TRUE(ToF1);
@@ -213,12 +217,14 @@ protected:
   }
 
   void TypedTest_ImportAfterImportWithMerge() {
-TranslationUnitDecl *FromTu0 = getTuDecl(getCode0(), Lang_CXX, 
"input0.cc");
-TranslationUnitDecl *FromTu1 = getTuDecl(getCode1(), Lang_CXX, 
"input1.cc");
+TranslationUnitDecl *FromTu0 =
+getTuDecl(getCode0(), Lang_CXX14, "input0.cc");
+TranslationUnitDecl *FromTu1 =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 auto *FromF0 = FirstDeclMatcher().match(FromTu0, getPattern());
 auto *FromF1 = FirstDeclMatcher().match(FromTu1, getPattern());
-auto *ToF0 = Import(FromF0, Lang_CXX);
-auto *ToF1 = Import(FromF1, Lang_CXX);
+auto *ToF0 = Import(FromF0, Lang_CXX14);
+auto *ToF1 = Import(FromF1, Lang_CXX14);
 ASSERT_TRUE(ToF0);
 ASSERT_TRUE(ToF1);
 if (shouldBeLinked())


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64477: [ASTImporter] Using Lang_CXX14 in ASTImporterVisibilityTest.

2019-07-15 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366061: [ASTImporter] Using Lang_CXX14 in 
ASTImporterVisibilityTest. (authored by balazske, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64477/new/

https://reviews.llvm.org/D64477

Files:
  cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp


Index: cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp
===
--- cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp
+++ cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp
@@ -80,13 +80,13 @@
 std::string Code = getCode() + getCode();
 auto Pattern = getPattern();
 
-TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX, "input0.cc");
+TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX14, "input0.cc");
 
 auto *FromD0 = FirstDeclMatcher().match(FromTu, Pattern);
 auto *FromD1 = LastDeclMatcher().match(FromTu, Pattern);
 
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD0 = Import(FromD0, Lang_CXX14);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 
 EXPECT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
@@ -157,13 +157,14 @@
   BindableMatcher getPattern() const { return PatternFactory()(); }
 
   void TypedTest_ImportAfter() {
-TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX);
-TranslationUnitDecl *FromTu = getTuDecl(getCode1(), Lang_CXX, "input1.cc");
+TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14);
+TranslationUnitDecl *FromTu =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 
 auto *ToD0 = FirstDeclMatcher().match(ToTu, getPattern());
 auto *FromD1 = FirstDeclMatcher().match(FromTu, getPattern());
 
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 
 ASSERT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
@@ -176,12 +177,14 @@
   }
 
   void TypedTest_ImportAfterImport() {
-TranslationUnitDecl *FromTu0 = getTuDecl(getCode0(), Lang_CXX, 
"input0.cc");
-TranslationUnitDecl *FromTu1 = getTuDecl(getCode1(), Lang_CXX, 
"input1.cc");
+TranslationUnitDecl *FromTu0 =
+getTuDecl(getCode0(), Lang_CXX14, "input0.cc");
+TranslationUnitDecl *FromTu1 =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 auto *FromD0 = FirstDeclMatcher().match(FromTu0, getPattern());
 auto *FromD1 = FirstDeclMatcher().match(FromTu1, getPattern());
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD0 = Import(FromD0, Lang_CXX14);
+auto *ToD1 = Import(FromD1, Lang_CXX14);
 ASSERT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
 EXPECT_NE(ToD0, ToD1);
@@ -192,13 +195,14 @@
   }
 
   void TypedTest_ImportAfterWithMerge() {
-TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX);
-TranslationUnitDecl *FromTu = getTuDecl(getCode1(), Lang_CXX, "input1.cc");
+TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX14);
+TranslationUnitDecl *FromTu =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 
 auto *ToF0 = FirstDeclMatcher().match(ToTu, getPattern());
 auto *FromF1 = FirstDeclMatcher().match(FromTu, getPattern());
 
-auto *ToF1 = Import(FromF1, Lang_CXX);
+auto *ToF1 = Import(FromF1, Lang_CXX14);
 
 ASSERT_TRUE(ToF0);
 ASSERT_TRUE(ToF1);
@@ -213,12 +217,14 @@
   }
 
   void TypedTest_ImportAfterImportWithMerge() {
-TranslationUnitDecl *FromTu0 = getTuDecl(getCode0(), Lang_CXX, 
"input0.cc");
-TranslationUnitDecl *FromTu1 = getTuDecl(getCode1(), Lang_CXX, 
"input1.cc");
+TranslationUnitDecl *FromTu0 =
+getTuDecl(getCode0(), Lang_CXX14, "input0.cc");
+TranslationUnitDecl *FromTu1 =
+getTuDecl(getCode1(), Lang_CXX14, "input1.cc");
 auto *FromF0 = FirstDeclMatcher().match(FromTu0, getPattern());
 auto *FromF1 = FirstDeclMatcher().match(FromTu1, getPattern());
-auto *ToF0 = Import(FromF0, Lang_CXX);
-auto *ToF1 = Import(FromF1, Lang_CXX);
+auto *ToF0 = Import(FromF0, Lang_CXX14);
+auto *ToF1 = Import(FromF1, Lang_CXX14);
 ASSERT_TRUE(ToF0);
 ASSERT_TRUE(ToF1);
 if (shouldBeLinked())


Index: cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp
===
--- cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp
+++ cfe/trunk/unittests/AST/ASTImporterVisibilityTest.cpp
@@ -80,13 +80,13 @@
 std::string Code = getCode() + getCode();
 auto Pattern = getPattern();
 
-TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX, "input0.cc");
+TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX14, "input0.cc");
 
 auto *FromD0 = FirstDeclMatcher().match(FromTu, Pattern);
 auto *FromD1 = LastDeclMatcher().match(FromTu, Pattern);
 
-auto *ToD0 = Import(FromD0, Lang

[PATCH] D64628: [CrossTU] Test change only: improve ctu-main.c

2019-07-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

I do not know how the AST import is relevant in this case, the 'implicit' 
function is not imported here. The test does something similar as the mentioned 
one, only the reported problem is after the imported function.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64628/new/

https://reviews.llvm.org/D64628



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah created this revision.
SureYeaah added reviewers: sammccall, kadircet.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

- Modified ExtractVariable to stop extraction for MemberExprs and

Assignment Expr

- Fixed unittests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64717

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -299,32 +299,32 @@
   return ^1;
 }
 void f() {
-  int a = 5 + [[4 ^* ^xyz^()]];
+  int a = 5 + [[4 * [[xyz();
   // multivariable initialization
   if(1)
-int x = ^1, y = ^a + 1, a = ^1, z = a + 1;
+int x = [[1]], y = [[a + 1]], a = [[1]], z = a + 1;
   // if without else
-  if(^1) {}
+  if([[1]]) {}
   // if with else
-  if(a < ^3)
-if(a == ^4)
-  a = ^5;
+  if(a < [[3]])
+if(a == [[4]])
+  a = [[5]];
 else
-  a = ^6;
-  else if (a < ^4)
-a = ^4;
+  a = [[6]];
+  else if (a < [[4]])
+a = [[4]];
   else
-a = ^5;
+a = [[5]];
   // for loop 
-  for(a = ^1; a > ^3^+^4; a++)
-a = ^2;
+  for(a = [[1]]; a > 3]]+4]]; a++)
+a = [[2]];
   // while 
-  while(a < ^1)
-^a++;
+  while(a < [[1]])
+[[a++]];
   // do while 
   do
-a = ^1;
-  while(a < ^3);
+a = [[1]];
+  while(a < [[3]]);
 }
   )cpp");
   // Should not crash.
@@ -340,8 +340,10 @@
   return 1;
   class T {
 T(int a = ^1) {};
+T f() { return T(); }
 int xyz = ^1;
   };
+  [[T.[[^t();
 }
 // function default argument
 void f(int b = ^1) {
@@ -359,6 +361,10 @@
 a = ^a ^+ 1;
   // lambda 
   auto lamb = [&^a, &^b](int r = ^1) {return 1;}
+  // assigment 
+  [[a ^= 5]];
+  // DeclRefExpr
+  a = [[b]], b = [[xyz]]();
 }
   )cpp");
   // vector of pairs of input and output strings
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -77,14 +77,20 @@
   return Visitor.ReferencedDecls;
 }
 
-// An expr is not extractable if it's null or an expression of type void
-// FIXME: Ignore assignment (a = 1) Expr since it is extracted as dummy = a =
+// An expr is not extractable if it's null, expression of type void, an
+// assignment expression, Member or a DeclRefExpr
 static bool isExtractableExpr(const clang::Expr *Expr) {
   if (Expr) {
-const Type *ExprType = Expr->getType().getTypePtrOrNull();
 // FIXME: check if we need to cover any other types
-if (ExprType)
-  return !ExprType->isVoidType();
+if(const Type *ExprType = Expr->getType().getTypePtrOrNull())
+  if(ExprType->isVoidType())
+return false;
+if(const BinaryOperator *BinOpExpr = llvm::dyn_cast_or_null(Expr))
+  if(BinOpExpr->getOpcode() == BinaryOperatorKind::BO_Assign)
+return false;
+if(llvm::isa(Expr) || llvm::isa(Expr))
+return false;
+return true;
   }
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64718: [clangd] Triggering indexing on each translation unit with an error

2019-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Background indexing triggers indexing only on the first TU that
includes a stale dependency.

This patch extends this behavior to also trigger indexing on TUs with errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64718

Files:
  clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp


Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -181,7 +181,6 @@
   void f_b();
   class A_CC {};
   )cpp";
-  std::string A_CC = "";
   FS.Files[testPath("root/A.cc")] = R"cpp(
   #include "A.h"
   void g() { (void)common; }
@@ -678,5 +677,61 @@
   EXPECT_EQ(LoRan, 0u);
 }
 
+TEST(BackgroundIndexLoaderTest, IndexAllTUsWithErrors) {
+  MockFSProvider FS;
+  FS.Files[testPath("root/A.h")] = "broken_header";
+  FS.Files[testPath("root/A.cc")] = R"cpp(#include "A.h")cpp";
+  FS.Files[testPath("root/B.cc")] = R"cpp(#include "A.h")cpp";
+
+  llvm::StringMap Storage;
+  size_t CacheHits = 0;
+  MemoryShardStorage MSS(Storage, CacheHits);
+
+  auto CmdForFile = [](PathRef RelativePath) {
+tooling::CompileCommand Cmd;
+Cmd.Filename = testPath(RelativePath);
+Cmd.Directory = testPath("root");
+Cmd.CommandLine = {"clang++", testPath(RelativePath)};
+return Cmd;
+  };
+  std::vector TUs = {"root/A.cc", "root/B.cc"};
+
+  {
+OverlayCDB CDB(/*Base=*/nullptr);
+for (PathRef RelPath : TUs)
+  CDB.setCompileCommand(RelPath, CmdForFile(RelPath));
+BackgroundIndex Idx(Context::empty(), FS, CDB,
+[&](llvm::StringRef) { return &MSS; });
+Idx.enqueue(TUs);
+ASSERT_TRUE(Idx.blockUntilIdleForTest());
+  }
+  EXPECT_EQ(CacheHits, 0U);
+  EXPECT_THAT(Storage.keys(),
+  UnorderedElementsAre(testPath("root/A.cc"), 
testPath("root/B.cc"),
+   testPath("root/A.h")));
+  for (PathRef RelPath : TUs) {
+EXPECT_THAT(MSS.loadShard(testPath(RelPath))
+->Sources->lookup(("unittest:///" + RelPath).str()),
+HadErrors());
+  }
+
+  FS.Files[testPath("root/A.h")] = "int broken_header;";
+  {
+OverlayCDB CDB(/*Base=*/nullptr);
+for (PathRef RelPath : TUs)
+  CDB.setCompileCommand(RelPath, CmdForFile(RelPath));
+
+BackgroundIndex Idx(Context::empty(), FS, CDB,
+[&](llvm::StringRef) { return &MSS; });
+Idx.enqueue(TUs);
+ASSERT_TRUE(Idx.blockUntilIdleForTest());
+  }
+  for (PathRef RelPath : TUs) {
+EXPECT_THAT(MSS.loadShard(testPath(RelPath))
+->Sources->lookup(("unittest:///" + RelPath).str()),
+Not(HadErrors()));
+  }
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
===
--- clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
+++ clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
@@ -100,8 +100,7 @@
 auto LoadResult = loadShard(ShardIdentifier, Storage);
 const CachedShard &CS = LoadResult.first;
 // Report the file as stale if it is the first time we see it.
-// FIXME: We should still update staleness for main file, if it had errors.
-if (!LoadResult.second && CS.IsStale)
+if ((!LoadResult.second || MainShard.SI.HadErrors) && CS.IsStale)
   IsStale = true;
 for (PathRef Edge : CS.Edges) {
   if (InQueue.insert(Edge).second)


Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -181,7 +181,6 @@
   void f_b();
   class A_CC {};
   )cpp";
-  std::string A_CC = "";
   FS.Files[testPath("root/A.cc")] = R"cpp(
   #include "A.h"
   void g() { (void)common; }
@@ -678,5 +677,61 @@
   EXPECT_EQ(LoRan, 0u);
 }
 
+TEST(BackgroundIndexLoaderTest, IndexAllTUsWithErrors) {
+  MockFSProvider FS;
+  FS.Files[testPath("root/A.h")] = "broken_header";
+  FS.Files[testPath("root/A.cc")] = R"cpp(#include "A.h")cpp";
+  FS.Files[testPath("root/B.cc")] = R"cpp(#include "A.h")cpp";
+
+  llvm::StringMap Storage;
+  size_t CacheHits = 0;
+  MemoryShardStorage MSS(Storage, CacheHits);
+
+  auto CmdForFile = [](PathRef RelativePath) {
+tooling::CompileCommand Cmd;
+Cmd.Filename = testPath(RelativePath);
+Cmd.Directory = testPath("root");
+Cmd.CommandLine = {"clang++", testPath(RelativePath)};
+return Cmd;
+  };
+  std::vector TUs = 

[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 209809.
SureYeaah added a comment.

Fixed comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -299,32 +299,32 @@
   return ^1;
 }
 void f() {
-  int a = 5 + [[4 ^* ^xyz^()]];
+  int a = 5 + [[4 * [[xyz();
   // multivariable initialization
   if(1)
-int x = ^1, y = ^a + 1, a = ^1, z = a + 1;
+int x = [[1]], y = [[a + 1]], a = [[1]], z = a + 1;
   // if without else
-  if(^1) {}
+  if([[1]]) {}
   // if with else
-  if(a < ^3)
-if(a == ^4)
-  a = ^5;
+  if(a < [[3]])
+if(a == [[4]])
+  a = [[5]];
 else
-  a = ^6;
-  else if (a < ^4)
-a = ^4;
+  a = [[6]];
+  else if (a < [[4]])
+a = [[4]];
   else
-a = ^5;
+a = [[5]];
   // for loop 
-  for(a = ^1; a > ^3^+^4; a++)
-a = ^2;
+  for(a = [[1]]; a > 3]]+4]]; a++)
+a = [[2]];
   // while 
-  while(a < ^1)
-^a++;
+  while(a < [[1]])
+[[a++]];
   // do while 
   do
-a = ^1;
-  while(a < ^3);
+a = [[1]];
+  while(a < [[3]]);
 }
   )cpp");
   // Should not crash.
@@ -340,8 +340,10 @@
   return 1;
   class T {
 T(int a = ^1) {};
+T f() { return T(); }
 int xyz = ^1;
   };
+  [[T.[[^t();
 }
 // function default argument
 void f(int b = ^1) {
@@ -359,6 +361,10 @@
 a = ^a ^+ 1;
   // lambda 
   auto lamb = [&^a, &^b](int r = ^1) {return 1;}
+  // assigment 
+  [[a ^= 5]];
+  // DeclRefExpr
+  a = [[b]], b = [[xyz]]();
 }
   )cpp");
   // vector of pairs of input and output strings
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -77,14 +77,21 @@
   return Visitor.ReferencedDecls;
 }
 
-// An expr is not extractable if it's null or an expression of type void
-// FIXME: Ignore assignment (a = 1) Expr since it is extracted as dummy = a =
+// An expr is not extractable if it's null, an expression of type void, an
+// assignment expression, MemberExpr or a DeclRefExpr
 static bool isExtractableExpr(const clang::Expr *Expr) {
   if (Expr) {
-const Type *ExprType = Expr->getType().getTypePtrOrNull();
 // FIXME: check if we need to cover any other types
-if (ExprType)
-  return !ExprType->isVoidType();
+if (const Type *ExprType = Expr->getType().getTypePtrOrNull())
+  if (ExprType->isVoidType())
+return false;
+if (const BinaryOperator *BinOpExpr =
+llvm::dyn_cast_or_null(Expr))
+  if (BinOpExpr->getOpcode() == BinaryOperatorKind::BO_Assign)
+return false;
+if (llvm::isa(Expr) || llvm::isa(Expr))
+  return false;
+return true;
   }
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 209814.

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -665,6 +665,67 @@
  "#include \"a.h\""));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n",
+			sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+	
+}
+
+TEST_F(SortIncludesTest, SortedIncludesInSingleBlockReGroupWithNetBSDSpecifications) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"		
+   "#include \n"		
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"	
+   "#include \n"
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"pathnames.h\"\n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -479,6 +479,7 @@
 IO.mapOptional("RawStringFormats", Style.RawStringFormats);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
+IO.mapOptional("SortNetBSDIncludes", Style.SortNetBSDIncludes);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
@@ -609,7 +610,7 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
+false, false, false, false, false, 
 false, false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
@@ -1023,6 +1024,29 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 2},
+  {"^\"\w.*\.h\"$", 1}, {".*", 0}};
+  NetBSDStyle.SortNetBSDIncludes = true;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1071,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
@@ -1763,7 +1789,163 @@
   }
   return std::make_pair(CursorIndex, OffsetToEOL);
 }
+enum CppIncludeHeadersKind {
+  IHK_KERNELHEADERS,
+  IHK_NETWORKHEADERS,
+  IHK_FILESYSHEADERS,
+  IHK_MACHINESHEADERS,
+  IHK_ARCHHEADERS,
+  IHK_USERHEADERS,
+  IHK_INCLUDESWITHQUOTES,
+};
+
+CppIncludeHeadersKind getHeadersKind(std::string Filename) {
+  SmallVector Matches;
+  const char KernelHeaderPattern[] = R"(^<(sys.*|uvm|dev)/)";
+  const char NetworkHeaderPattern[] = R"(^<(net.*|protocols)/)";
+  const char FilesSystemHeaderPattern[] =
+  R"(^<(fs|miscfs|msdosf

[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:83
 static bool isExtractableExpr(const clang::Expr *Expr) {
   if (Expr) {
 // FIXME: check if we need to cover any other types

nit: Could you reduce nesting by early returns and add braces to outer if 
statements if there are any nested statements left.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:299
   // return statement
   return ^1;
 }

left out this one ?



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:302
 void f() {
-  int a = 5 + [[4 ^* ^xyz^()]];
+  int a = 5 + [[4 * [[xyz();
   // multivariable initialization

how come these changes part of that patch?

is it possible that this tweak was changed to not trigger on empty selections, 
but tests were not updated? If that's the case could you please send these on a 
different patch and rebase this patch on that one?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:302
 void f() {
-  int a = 5 + [[4 ^* ^xyz^()]];
+  int a = 5 + [[4 * [[xyz();
   // multivariable initialization

kadircet wrote:
> how come these changes part of that patch?
> 
> is it possible that this tweak was changed to not trigger on empty 
> selections, but tests were not updated? If that's the case could you please 
> send these on a different patch and rebase this patch on that one?
> how come these changes part of that patch?

how come these changes *are* part of that patch?




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r366062 - Fix uninitialized variable analyzer warning. NFCI.

2019-07-15 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Mon Jul 15 06:00:43 2019
New Revision: 366062

URL: http://llvm.org/viewvc/llvm-project?rev=366062&view=rev
Log:
Fix uninitialized variable analyzer warning. NFCI.

Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=366062&r1=366061&r2=366062&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Jul 15 06:00:43 2019
@@ -8075,7 +8075,7 @@ ASTImporter::Import(NestedNameSpecifier
   if (!FromNNS)
 return nullptr;
 
-  NestedNameSpecifier *Prefix;
+  NestedNameSpecifier *Prefix = nullptr;
   if (Error Err = importInto(Prefix, FromNNS->getPrefix()))
 return std::move(Err);
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r366063 - [OpenCL] Deduce addr space for pointee of dependent types in instantiation.

2019-07-15 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Mon Jul 15 06:02:21 2019
New Revision: 366063

URL: http://llvm.org/viewvc/llvm-project?rev=366063&view=rev
Log:
[OpenCL] Deduce addr space for pointee of dependent types in instantiation.

Since pointee doesn't require context sensitive addr space deduction
it's easier to handle pointee of dependent types during templ
instantiation.

Differential Revision: https://reviews.llvm.org/D64400


Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=366063&r1=366062&r2=366063&view=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon Jul 15 06:02:21 2019
@@ -4536,6 +4536,14 @@ QualType TreeTransform::Transfo
   return Result;
 }
 
+/// Helper to deduce addr space of a pointee type in OpenCL mode.
+/// If the type is updated it will be overwritten in PointeeType param.
+static void deduceOpenCLPointeeAddrSpace(Sema &SemaRef, QualType &PointeeType) 
{
+  if (PointeeType.getAddressSpace() == LangAS::Default)
+PointeeType = SemaRef.Context.getAddrSpaceQualType(PointeeType,
+   LangAS::opencl_generic);
+}
+
 template
 QualType TreeTransform::TransformPointerType(TypeLocBuilder &TLB,
   PointerTypeLoc TL) {
@@ -4544,6 +4552,9 @@ QualType TreeTransform::Transfo
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (PointeeType->getAs()) {
 // A dependent pointer type 'T *' has is being transformed such
@@ -4582,6 +4593,9 @@ TreeTransform::TransformBlockPo
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
   PointeeType != TL.getPointeeLoc().getType()) {
@@ -4611,6 +4625,9 @@ TreeTransform::TransformReferen
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
   PointeeType != T->getPointeeTypeAsWritten()) {

Modified: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=366063&r1=366062&r2=366063&view=diff
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Mon Jul 15 06:02:21 
2019
@@ -24,3 +24,42 @@ struct c2 {
   alias_c1_ptr ptr = &y;
 };
 
+
+// Addr spaces for pointee of dependent types are not deduced
+// during parsing but during template instantiation instead.
+
+template 
+struct x1 {
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &) __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic 
x1 &) __generic'
+  x1& operator=(const x1& xx) {
+y = xx.y;
+return *this;
+  }
+  int y;
+};
+
+template 
+struct x2 {
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *) __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *) __generic'
+  void foo(x1* xx) {
+m[0] = *xx;
+  }
+//CHECK: -FieldDecl {{.*}}  m 'x1 [2]'
+  x1 m[2];
+};
+
+void bar(__global x1 *xx, __global x2 *bar) {
+  bar->foo(xx);
+}
+
+template 
+class x3 : public T {
+public:
+  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &) __generic'
+  x3(const x3 &t);
+};
+//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &) __generic'
+template 
+x3::x3(const x3 &t) {}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64400: [OpenCL][PR42390] Deduce addr space for templ specialization

2019-07-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366063: [OpenCL] Deduce addr space for pointee of dependent 
types in instantiation. (authored by stulova, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64400?vs=209205&id=209831#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64400/new/

https://reviews.llvm.org/D64400

Files:
  cfe/trunk/lib/Sema/TreeTransform.h
  cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl


Index: cfe/trunk/lib/Sema/TreeTransform.h
===
--- cfe/trunk/lib/Sema/TreeTransform.h
+++ cfe/trunk/lib/Sema/TreeTransform.h
@@ -4536,6 +4536,14 @@
   return Result;
 }
 
+/// Helper to deduce addr space of a pointee type in OpenCL mode.
+/// If the type is updated it will be overwritten in PointeeType param.
+static void deduceOpenCLPointeeAddrSpace(Sema &SemaRef, QualType &PointeeType) 
{
+  if (PointeeType.getAddressSpace() == LangAS::Default)
+PointeeType = SemaRef.Context.getAddrSpaceQualType(PointeeType,
+   LangAS::opencl_generic);
+}
+
 template
 QualType TreeTransform::TransformPointerType(TypeLocBuilder &TLB,
   PointerTypeLoc TL) {
@@ -4544,6 +4552,9 @@
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (PointeeType->getAs()) {
 // A dependent pointer type 'T *' has is being transformed such
@@ -4582,6 +4593,9 @@
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
   PointeeType != TL.getPointeeLoc().getType()) {
@@ -4611,6 +4625,9 @@
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
   PointeeType != T->getPointeeTypeAsWritten()) {
Index: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
===
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -24,3 +24,42 @@
   alias_c1_ptr ptr = &y;
 };
 
+
+// Addr spaces for pointee of dependent types are not deduced
+// during parsing but during template instantiation instead.
+
+template 
+struct x1 {
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &) __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic 
x1 &) __generic'
+  x1& operator=(const x1& xx) {
+y = xx.y;
+return *this;
+  }
+  int y;
+};
+
+template 
+struct x2 {
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *) __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *) __generic'
+  void foo(x1* xx) {
+m[0] = *xx;
+  }
+//CHECK: -FieldDecl {{.*}}  m 'x1 [2]'
+  x1 m[2];
+};
+
+void bar(__global x1 *xx, __global x2 *bar) {
+  bar->foo(xx);
+}
+
+template 
+class x3 : public T {
+public:
+  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &) __generic'
+  x3(const x3 &t);
+};
+//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &) __generic'
+template 
+x3::x3(const x3 &t) {}


Index: cfe/trunk/lib/Sema/TreeTransform.h
===
--- cfe/trunk/lib/Sema/TreeTransform.h
+++ cfe/trunk/lib/Sema/TreeTransform.h
@@ -4536,6 +4536,14 @@
   return Result;
 }
 
+/// Helper to deduce addr space of a pointee type in OpenCL mode.
+/// If the type is updated it will be overwritten in PointeeType param.
+static void deduceOpenCLPointeeAddrSpace(Sema &SemaRef, QualType &PointeeType) {
+  if (PointeeType.getAddressSpace() == LangAS::Default)
+PointeeType = SemaRef.Context.getAddrSpaceQualType(PointeeType,
+   LangAS::opencl_generic);
+}
+
 template
 QualType TreeTransform::TransformPointerType(TypeLocBuilder &TLB,
   PointerTypeLoc TL) {
@@ -4544,6 +4552,9 @@
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (PointeeType->getAs()) {
 // A dependent pointer type 'T *' has is being transformed such
@@ -4582,6 +4593,9 @@
   if (PointeeType.isNull())
 return QualType();
 
+  if (SemaRef.getLangOpts().OpenCL)
+deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
+
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
   PointeeTy

[PATCH] D61333: [ASTImporter] Fix LLDB lookup in transparent ctx and with ext src

2019-07-15 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 209832.
martong added a comment.

- Rebase to master


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61333/new/

https://reviews.llvm.org/D61333

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  lldb/packages/Python/lldbsuite/test/lang/c/ast/Makefile
  lldb/packages/Python/lldbsuite/test/lang/c/ast/TestAST.py
  lldb/packages/Python/lldbsuite/test/lang/c/ast/main.c
  lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -611,6 +611,8 @@
   if (!original_decl_context)
 return;
 
+  // Indicates whether we skipped any Decls of the original DeclContext.
+  bool SkippedDecls = false;
   for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
iter != original_decl_context->decls_end(); ++iter) {
 Decl *decl = *iter;
@@ -639,21 +641,22 @@
 
 m_ast_importer_sp->RequireCompleteType(copied_field_type);
   }
-
-  DeclContext *decl_context_non_const =
-  const_cast(decl_context);
-
-  if (copied_decl->getDeclContext() != decl_context) {
-if (copied_decl->getDeclContext()->containsDecl(copied_decl))
-  copied_decl->getDeclContext()->removeDecl(copied_decl);
-copied_decl->setDeclContext(decl_context_non_const);
-  }
-
-  if (!decl_context_non_const->containsDecl(copied_decl))
-decl_context_non_const->addDeclInternal(copied_decl);
+} else {
+  SkippedDecls = true;
 }
   }
 
+  // CopyDecl may build a lookup table which may set up ExternalLexicalStorage
+  // to false.  However, since we skipped some of the external Decls we must
+  // set it back!
+  if (SkippedDecls) {
+decl_context->setHasExternalLexicalStorage(true);
+// This sets HasLazyExternalLexicalLookups to true.  By setting this bit we
+// ensure that the lookup table is rebuilt, which means the external source
+// is consulted again when a clang::DeclContext::lookup is called.
+const_cast(decl_context)->setMustBuildLookupTable();
+  }
+
   return;
 }
 
Index: lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
===
--- lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
+++ lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
@@ -5,11 +5,11 @@
 typedef struct {
 int a;
 int b;
-} FILE;
+} MYFILE;
 
 int main()
 {
-FILE *myFile = malloc(sizeof(FILE));
+MYFILE *myFile = malloc(sizeof(MYFILE));
 
 myFile->a = 5;
 myFile->b = 9;
Index: lldb/packages/Python/lldbsuite/test/lang/c/ast/main.c
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/ast/main.c
@@ -0,0 +1,5 @@
+int main()
+{
+int a = 0; // Set breakpoint 0 here.
+return 0;
+}
Index: lldb/packages/Python/lldbsuite/test/lang/c/ast/TestAST.py
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/ast/TestAST.py
@@ -0,0 +1,77 @@
+"""Test that importing modules in C works as expected."""
+
+from __future__ import print_function
+
+
+from distutils.version import StrictVersion
+import os
+import time
+import platform
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class CModulesTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIfFreeBSD
+@skipIfLinux
+@skipIfWindows
+@skipIfNetBSD
+@skipIf(macos_version=["<", "10.12"])
+def test_expr(self):
+self.build()
+exe = self.getBuildArtifact("a.out")
+self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
+
+self.runCmd("run", RUN_SUCCEEDED)
+
+# The stop reason of the thread should be breakpoint.
+self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+substrs=['stopped',
+ 'stop reason = breakpoint'])
+
+# The breakpoint should have a hit count of 1.
+self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
+substrs=[' resolved, hit count = 1'])
+
+# Enable logging of the imported AST.
+log_file = os.path.join(self.getBuildDir(), "lldb-ast-log.txt")
+self.runCmd("log enable lldb ast -f '%s'" % log_file)
+
+self.expect(
+"expr -l objc++ -- @import Darwin; 3",
+VARIABLES_DISPLAYED_CORRECT

[PATCH] D61333: [ASTImporter] Fix LLDB lookup in transparent ctx and with ext src

2019-07-15 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D61333#1583173 , @teemperor wrote:

> @martong Sorry for the delay, feel free to ping me in the future about these 
> patches. I'll review them ASAP now that I'm back in office, so these delay's 
> hopefully won't happen again.
>
> I tried applying this patch and it seems it needs to be rebased. I would do 
> it myself, but I'm not entirely sure how to rebase the changes to 
> `ASTNodeImporter::ImportDefinition`. It seems we got rid of 
> `To->completeDefinition();`, so not sure if the code that this patch adds is 
> still in the right place.


Raphael,

Thank you for looking into this. I've rebased to master and updated the patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61333/new/

https://reviews.llvm.org/D61333



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64736: [clang-tidy] New bugprone-infinite-loop check for detecting obvious infinite loops

2019-07-15 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: aaron.ballman, lebedev.ri, alexfh.
baloghadamsoftware added a project: clang-tools-extra.
Herald added subscribers: gamesh411, whisperity, mgorny.
Herald added a project: clang.

Although detecting infinite loops in general is impossible (Halting-problem) 
there are some obvious cases where it is possible. Detecting such loops is 
beneficial since the tests will hang on programs containing infinite loops so 
testing-time detection may be costly in large systems. Obvious cases are where 
the programmer forgets to increment/decrement the counter or 
increments/decrements the wrong variable.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D64736

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tidy/bugprone/InfiniteLoopCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-infinite-loop.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-infinite-loop.cpp

Index: test/clang-tidy/bugprone-infinite-loop.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-infinite-loop.cpp
@@ -0,0 +1,226 @@
+// RUN: %check_clang_tidy %s bugprone-infinite-loop %t
+
+void simple_infinite_loop1() {
+  int i = 0;
+  int j = 0;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: None of the condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+j++;
+  }
+
+  do {
+j++;
+  } while (i < 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: None of the condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+
+  for (i = 0; i < 10; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: None of the condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+  }
+}
+
+void simple_infinite_loop2() {
+  int i = 0;
+  int j = 0;
+  int Limit = 10;
+  while (i < Limit) {
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: None of the condition variables (i, Limit) are updated in the loop body [bugprone-infinite-loop]
+j++;
+  }
+
+  do {
+j++;
+  } while (i < Limit);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: None of the condition variables (i, Limit) are updated in the loop body [bugprone-infinite-loop]
+
+  for (i = 0; i < Limit; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: None of the condition variables (i, Limit) are updated in the loop body [bugprone-infinite-loop]
+  }
+}
+
+void simple_not_infinite1() {
+  int i = 0;
+  int Limit = 100;
+  while (i < Limit) { // Not an error since 'Limit' is updated
+Limit--;
+  }
+  do {
+Limit--;
+  } while (i < Limit);
+
+  for (i = 0; i < Limit; Limit--) {
+  }
+}
+
+void simple_not_infinite2() {
+  for (int i = 10; i-- > 0;) // Not an error, since loop variable is modified in
+;// the condition part.
+}
+
+int any_function();
+
+void function_call() {
+  int i = 0;
+  while (i < any_function()) { // Not an error, since the function may return
+   // different values
+  }
+
+  do { // Not an error, since the function may return
+   // different values
+  } while (i < any_function());
+
+  for (i = 0; i < any_function();) { // Not an error, since the function may
+ // return different values
+  }
+}
+
+void escape_before1() {
+  int i = 0;
+  int Limit = 100;
+  int *p = &i;
+  while (i < Limit) { // Not an error, since *p is alias of i.
+(*p)++;
+  }
+
+  do {
+(*p)++;
+  } while (i < Limit);
+
+  for (i = 0; i < Limit; ++(*p)) {
+  }
+}
+
+void escape_before2() {
+  int i = 0;
+  int Limit = 100;
+  int &ii = i;
+  while (i < Limit) { // Not an error, since ii is alias of i.
+ii++;
+  }
+
+  do {
+ii++;
+  } while (i < Limit);
+
+  for (i = 0; i < Limit; ++ii) {
+  }
+}
+
+void escape_inside1() {
+  int i = 0;
+  int Limit = 100;
+  int *p = &i;
+  while (i < Limit) { // Not an error, since *p is alias of i.
+int *p = &i;
+(*p)++;
+  }
+
+  do {
+int *p = &i;
+(*p)++;
+  } while (i < Limit);
+}
+
+void escape_inside2() {
+  int i = 0;
+  int Limit = 100;
+  while (i < Limit) { // Not an error, since ii is alias of i.
+int &ii = i;
+ii++;
+  }
+
+  do {
+int &ii = i;
+ii++;
+  } while (i < Limit);
+}
+
+void escape_after1() {
+  int i = 0;
+  int j = 0;
+  int Limit = 10;
+
+  while (i < Limit) {
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: None of the condition variables (i, Limit) are updated in the loop body [bugprone-infinite-loop]
+  }
+  int *p = &i;
+}
+
+void escape_after2() {
+  int i = 0;
+  int j = 0;
+  int Limit = 10;
+
+  while (i < Limit) {
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: None of the condition variables (i, Limit) are updated in the loop body [bugprone-infinite-loop]
+  }
+  int &ii = i;
+}
+
+int glob;
+
+void global1(int &x) 

[PATCH] D64737: RISCV: Add support for floating point registers in inlineasm

2019-07-15 Thread Simon Cook via Phabricator via cfe-commits
simoncook created this revision.
simoncook added a reviewer: asb.
Herald added subscribers: cfe-commits, lenary, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, 
MaskRay, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, apazos, johnrusso, 
rbar.
Herald added a project: clang.
simoncook retitled this revision from "[PATCH] RISCV: Add support for floating 
point registers in inlineasm" to "RISCV: Add support for floating point 
registers in inlineasm".

This adds support for parsing/emitting in IR the floating-point RISC-V
registers in inline assembly clobber lists.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64737

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/Sema/riscv-asm.c


Index: clang/test/Sema/riscv-asm.c
===
--- /dev/null
+++ clang/test/Sema/riscv-asm.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 %s -triple riscv32 -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple riscv64 -verify -fsyntax-only
+
+// expected-no-diagnostics
+
+void i (void) {
+  asm volatile ("" ::: "x0",  "x1",  "x2",  "x3",  "x4",  "x5",  "x6",  "x7");
+  asm volatile ("" ::: "x8",  "x9",  "x10", "x11", "x12", "x13", "x14", "x15");
+  asm volatile ("" ::: "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23");
+  asm volatile ("" ::: "x24", "x25", "x26", "x27", "x28", "x29", "x30", "x31");
+
+  asm volatile ("" ::: "zero", "ra", "sp",  "gp",  "tp", "t0", "t1", "t2");
+  asm volatile ("" ::: "s0",   "s1", "a0",  "a1",  "a2", "a3", "a4", "a5");
+  asm volatile ("" ::: "a6",   "a7", "s2",  "s3",  "s4", "s5", "s6", "s7");
+  asm volatile ("" ::: "s8",   "s9", "s10", "s11", "t3", "t4", "t5", "t6");
+}
+
+void f (void) {
+  asm volatile ("" ::: "f0",  "f1",  "f2",  "f3",  "f4",  "f5",  "f6",  "f7");
+  asm volatile ("" ::: "f8",  "f9",  "f10", "f11", "f12", "f13", "f14", "f15");
+  asm volatile ("" ::: "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23");
+  asm volatile ("" ::: "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31");
+
+  asm volatile ("" ::: "ft0", "ft1", "ft2",  "ft3",  "ft4", "ft5", "ft6",  
"ft7");
+  asm volatile ("" ::: "fs0", "fs1", "fa0",  "fa1",  "fa2", "fa3", "fa4",  
"fa5");
+  asm volatile ("" ::: "fa6", "fa7", "fs2",  "fs3",  "fs4", "fs5", "fs6",  
"fs7");
+  asm volatile ("" ::: "fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", 
"ft11");
+}
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -19,23 +19,38 @@
 
 ArrayRef RISCVTargetInfo::getGCCRegNames() const {
   static const char *const GCCRegNames[] = {
+  // Integer registers
   "x0",  "x1",  "x2",  "x3",  "x4",  "x5",  "x6",  "x7",
   "x8",  "x9",  "x10", "x11", "x12", "x13", "x14", "x15",
   "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
-  "x24", "x25", "x26", "x27", "x28", "x29", "x30", "x31"};
+  "x24", "x25", "x26", "x27", "x28", "x29", "x30", "x31",
+
+  // Floating point registers
+  "f0",  "f1",  "f2",  "f3",  "f4",  "f5",  "f6",  "f7",
+  "f8",  "f9",  "f10", "f11", "f12", "f13", "f14", "f15",
+  "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
+  "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"};
   return llvm::makeArrayRef(GCCRegNames);
 }
 
 ArrayRef RISCVTargetInfo::getGCCRegAliases() const {
   static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
-  {{"zero"}, "x0"}, {{"ra"}, "x1"},  {{"sp"}, "x2"},   {{"gp"}, "x3"},
-  {{"tp"}, "x4"},   {{"t0"}, "x5"},  {{"t1"}, "x6"},   {{"t2"}, "x7"},
-  {{"s0"}, "x8"},   {{"s1"}, "x9"},  {{"a0"}, "x10"},  {{"a1"}, "x11"},
-  {{"a2"}, "x12"},  {{"a3"}, "x13"}, {{"a4"}, "x14"},  {{"a5"}, "x15"},
-  {{"a6"}, "x16"},  {{"a7"}, "x17"}, {{"s2"}, "x18"},  {{"s3"}, "x19"},
-  {{"s4"}, "x20"},  {{"s5"}, "x21"}, {{"s6"}, "x22"},  {{"s7"}, "x23"},
-  {{"s8"}, "x24"},  {{"s9"}, "x25"}, {{"s10"}, "x26"}, {{"s11"}, "x27"},
-  {{"t3"}, "x28"},  {{"t4"}, "x29"}, {{"t5"}, "x30"},  {{"t6"}, "x31"}};
+  {{"zero"}, "x0"}, {{"ra"}, "x1"},   {{"sp"}, "x2"},{{"gp"}, "x3"},
+  {{"tp"}, "x4"},   {{"t0"}, "x5"},   {{"t1"}, "x6"},{{"t2"}, "x7"},
+  {{"s0"}, "x8"},   {{"s1"}, "x9"},   {{"a0"}, "x10"},   {{"a1"}, "x11"},
+  {{"a2"}, "x12"},  {{"a3"}, "x13"},  {{"a4"}, "x14"},   {{"a5"}, "x15"},
+  {{"a6"}, "x16"},  {{"a7"}, "x17"},  {{"s2"}, "x18"},   {{"s3"}, "x19"},
+  {{"s4"}, "x20"},  {{"s5"}, "x21"},  {{"s6"}, "x22"},   {{"s7"}, "x23"},
+  {{"s8"}, "x24"},  {{"s9"}, "x25"},  {{"s10"}, "x26"},  {{"s11"}, "x27"},
+  {{"t3"}, "x28"},  {{"t4"}, "x29"},  {{"t5"}, "x30"},   {{"t6"}, "x31"},
+  {{"ft0"}, "f0"},  {{"ft1"}, "f1"},  {{"ft2"}, "f2"},   {{"ft3"}, "f3"},
+  {{"ft4"}, "f4"},  {{"ft5"}, "f5"},  {{"ft6"}, "f6"},   {{"ft7"}, "f7"},
+  {{"fs0"}, "f8"},  {{"fs1"}, "f9"},  {{"fa0"}, "f10"},

[PATCH] D64608: [OpenCL] Make TableGen'd builtin tables and helper functions static

2019-07-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64608/new/

https://reviews.llvm.org/D64608



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 209844.
SureYeaah marked 5 inline comments as done.
SureYeaah added a comment.

Removed unrelated changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -299,10 +299,10 @@
   return ^1;
 }
 void f() {
-  int a = 5 + [[4 ^* ^xyz^()]];
+  int a = 5 + [[4 ^* xyz^()]];
   // multivariable initialization
   if(1)
-int x = ^1, y = ^a + 1, a = ^1, z = a + 1;
+int x = ^1, y = [[a + 1]], a = ^1, z = a + 1;
   // if without else
   if(^1) {}
   // if with else
@@ -320,7 +320,7 @@
 a = ^2;
   // while 
   while(a < ^1)
-^a++;
+[[a++]];
   // do while 
   do
 a = ^1;
@@ -340,8 +340,10 @@
   return 1;
   class T {
 T(int a = ^1) {};
+T f() { return T(); }
 int xyz = ^1;
   };
+  [[T.[[^t();
 }
 // function default argument
 void f(int b = ^1) {
@@ -359,6 +361,10 @@
 a = ^a ^+ 1;
   // lambda 
   auto lamb = [&^a, &^b](int r = ^1) {return 1;}
+  // assigment 
+  [[a ^= 5]];
+  // DeclRefExpr
+  a = [[b]], b = [[xyz]]();
 }
   )cpp");
   // vector of pairs of input and output strings
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -77,16 +77,22 @@
   return Visitor.ReferencedDecls;
 }
 
-// An expr is not extractable if it's null or an expression of type void
-// FIXME: Ignore assignment (a = 1) Expr since it is extracted as dummy = a =
+// An expr is not extractable if it's null, an expression of type void, an
+// assignment expression, MemberExpr or a DeclRefExpr
 static bool isExtractableExpr(const clang::Expr *Expr) {
-  if (Expr) {
-const Type *ExprType = Expr->getType().getTypePtrOrNull();
-// FIXME: check if we need to cover any other types
-if (ExprType)
-  return !ExprType->isVoidType();
-  }
-  return false;
+  if (!Expr)
+return false;
+  // FIXME: check if we need to cover any other types
+  if (const Type *ExprType = Expr->getType().getTypePtrOrNull())
+if (ExprType->isVoidType())
+  return false;
+  if (const BinaryOperator *BinOpExpr =
+  llvm::dyn_cast_or_null(Expr))
+if (BinOpExpr->getOpcode() == BinaryOperatorKind::BO_Assign)
+  return false;
+  if (llvm::isa(Expr) || llvm::isa(Expr))
+return false;
+  return true;
 }
 
 ExtractionContext::ExtractionContext(const SelectionTree::Node *Node,


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -299,10 +299,10 @@
   return ^1;
 }
 void f() {
-  int a = 5 + [[4 ^* ^xyz^()]];
+  int a = 5 + [[4 ^* xyz^()]];
   // multivariable initialization
   if(1)
-int x = ^1, y = ^a + 1, a = ^1, z = a + 1;
+int x = ^1, y = [[a + 1]], a = ^1, z = a + 1;
   // if without else
   if(^1) {}
   // if with else
@@ -320,7 +320,7 @@
 a = ^2;
   // while 
   while(a < ^1)
-^a++;
+[[a++]];
   // do while 
   do
 a = ^1;
@@ -340,8 +340,10 @@
   return 1;
   class T {
 T(int a = ^1) {};
+T f() { return T(); }
 int xyz = ^1;
   };
+  [[T.[[^t();
 }
 // function default argument
 void f(int b = ^1) {
@@ -359,6 +361,10 @@
 a = ^a ^+ 1;
   // lambda 
   auto lamb = [&^a, &^b](int r = ^1) {return 1;}
+  // assigment 
+  [[a ^= 5]];
+  // DeclRefExpr
+  a = [[b]], b = [[xyz]]();
 }
   )cpp");
   // vector of pairs of input and output strings
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -77,16 +77,22 @@
   return Visitor.ReferencedDecls;
 }
 
-// An expr is not extractable if it's null or an expression of type void
-// FIXME: Ignore assignment (a = 1) Expr since it is extracted as dummy = a =
+// An expr is not extractable if it's null, an expression of type void, an
+// assignment expression, MemberExpr or a DeclRefExpr
 static bool isExtractableExpr(const

[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah added inline comments.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:299
   // return statement
   return ^1;
 }

kadircet wrote:
> left out this one ?
Since that's an IntegerLiteral, this patch doesn't apply to it?



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:302
 void f() {
-  int a = 5 + [[4 ^* ^xyz^()]];
+  int a = 5 + [[4 * [[xyz();
   // multivariable initialization

kadircet wrote:
> kadircet wrote:
> > how come these changes part of that patch?
> > 
> > is it possible that this tweak was changed to not trigger on empty 
> > selections, but tests were not updated? If that's the case could you please 
> > send these on a different patch and rebase this patch on that one?
> > how come these changes part of that patch?
> 
> how come these changes *are* part of that patch?
> 
> 
This patch doesn't involve empty selection triggers. Reverted these changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64736: [clang-tidy] New bugprone-infinite-loop check for detecting obvious infinite loops

2019-07-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

Thanks for working on this!
You want to use `clang/Analysis/Analyses/ExprMutationAnalyzer.h`.
See also: D51870 


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64736/new/

https://reviews.llvm.org/D64736



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64737: RISCV: Add support for floating point registers in inlineasm

2019-07-15 Thread Simon Cook via Phabricator via cfe-commits
simoncook added a comment.

As an aside, I've noticed a codegen issue when using floating point clobber 
lists, resulting in the implicit-defs not being added to INLINEASM 
instructions. I'm working on a fix for that now and will submit a second patch 
shortly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64737/new/

https://reviews.llvm.org/D64737



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64739: [SVE][Inline-Asm] Add support to clang for SVE inline assembly

2019-07-15 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin created this revision.
kmclaughlin added reviewers: erichkeane, sdesmalen, cfe-commits.
Herald added subscribers: psnobl, rkruppe, tschuett, javed.absar.
Herald added a reviewer: rengolin.
Herald added a project: clang.

Adds the SVE vector and predicate registers to the list of known registers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64739

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/test/CodeGen/aarch64-sve-inline-asm.c


Index: clang/test/CodeGen/aarch64-sve-inline-asm.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-inline-asm.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -target-feature 
+sve -o - %s | FileCheck %s
+
+long test_z0_p0()
+{
+  long t;
+
+  asm volatile(
+"ptrue p0.d\n"
+"dup z0.d, #3\n"
+"smaxv %d0, p0, z0.d\n"
+  : "=w" (t) : : "z0", "p0");
+// CHECK: call i64 asm sideeffect "ptrue p0.d\0Adup z0.d, #3\0Asmaxv ${0:d}, 
p0, z0.d\0A", "=w,~{z0},~{p0}"
+
+  return t;
+}
+
+long test_z31()
+{
+  long t;
+
+  asm volatile(
+"ptrue p0.d\n"
+"dup z31.d, #3\n"
+"uaddv %d0, p0, z31.d\n"
+  : "=w" (t) : : "z31", "p0");
+// CHECK: call i64 asm sideeffect "ptrue p0.d\0Adup z31.d, #3\0Auaddv ${0:d}, 
p0, z31.d\0A", "=w,~{z31},~{p0}"
+
+  return t;
+}
+
+long test_p15()
+{
+  long t = 0;
+
+  asm volatile(
+"ptrue p15.h\n"
+"incp %x0, p15.h\n"
+  : "=r" (t) : "0" (t) : "p15");
+// CHECK: call i64 asm sideeffect "ptrue p15.h\0Aincp ${0:x}, p15.h\0A", 
"=r,0,~{p15}"
+
+  return t;
+}
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -304,20 +304,29 @@
 "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", 
"x22",
 "x23", "x24", "x25", "x26", "x27", "x28", "fp", "lr", "sp",
 
-// 32-bit floating point regsisters
+// 32-bit floating point registers
 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11",
 "s12", "s13", "s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21", 
"s22",
 "s23", "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
 
-// 64-bit floating point regsisters
+// 64-bit floating point registers
 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10", "d11",
 "d12", "d13", "d14", "d15", "d16", "d17", "d18", "d19", "d20", "d21", 
"d22",
 "d23", "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
 
-// Vector registers
+// Neon vector registers
 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", 
"v22",
-"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
+"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
+
+// SVE vector registers
+"z0",  "z1",  "z2",  "z3",  "z4",  "z5",  "z6",  "z7",  "z8",  "z9",  
"z10",
+"z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", 
"z21",
+"z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
+
+// SVE predicate registers
+"p0",  "p1",  "p2",  "p3",  "p4",  "p5",  "p6",  "p7",  "p8",  "p9",  
"p10",
+"p11", "p12", "p13", "p14", "p15"
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {


Index: clang/test/CodeGen/aarch64-sve-inline-asm.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-inline-asm.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -target-feature +sve -o - %s | FileCheck %s
+
+long test_z0_p0()
+{
+  long t;
+
+  asm volatile(
+"ptrue p0.d\n"
+"dup z0.d, #3\n"
+"smaxv %d0, p0, z0.d\n"
+  : "=w" (t) : : "z0", "p0");
+// CHECK: call i64 asm sideeffect "ptrue p0.d\0Adup z0.d, #3\0Asmaxv ${0:d}, p0, z0.d\0A", "=w,~{z0},~{p0}"
+
+  return t;
+}
+
+long test_z31()
+{
+  long t;
+
+  asm volatile(
+"ptrue p0.d\n"
+"dup z31.d, #3\n"
+"uaddv %d0, p0, z31.d\n"
+  : "=w" (t) : : "z31", "p0");
+// CHECK: call i64 asm sideeffect "ptrue p0.d\0Adup z31.d, #3\0Auaddv ${0:d}, p0, z31.d\0A", "=w,~{z31},~{p0}"
+
+  return t;
+}
+
+long test_p15()
+{
+  long t = 0;
+
+  asm volatile(
+"ptrue p15.h\n"
+"incp %x0, p15.h\n"
+  : "=r" (t) : "0" (t) : "p15");
+// CHECK: call i64 asm sideeffect "ptrue p15.h\0Aincp ${0:x}, p15.h\0A", "=r,0,~{p15}"
+
+  return t;
+}
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -304,20 +304,29 @@
 "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22",
 "x23", "x24", "x25", "x26", "x27", "x28", "fp", "lr", "sp",
 
-// 32-bit floating point regsisters
+// 32-bit floating point registers
 "s0", "s

[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Are you sure we want to disable extraction here, rather than just do the 
extraction at a higher level?

E.g. if `bar(1,2,3, f[[o]]o(4,5));` seems like it should extract the call too 
`foo(4,5)`, not fail to trigger entirely.




Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:81
+// An expr is not extractable if it's null, an expression of type void, an
+// assignment expression, MemberExpr or a DeclRefExpr
 static bool isExtractableExpr(const clang::Expr *Expr) {

this comment repeats the implementation, but should explain why instead


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64671: [clang-tidy] New check: misc-init-local-variables

2019-07-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:21
+  Finder->addMatcher(
+  varDecl(unless(hasInitializer(anything(.bind("vardecl"), this);
+}

I believe, this should skip matches within template instantiations. Consider 
this code:
```
template
void f(T) { T t; }
void g() {
f(0);
f(0.0);
}
```

What will the fix  be?



Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:32
+  StringRef VarName = MatchedDecl->getName();
+  if (VarName.empty() || VarName.front() == '_') {
+// Some standard library methods such as "be64toh" are implemented

Should this just disallow all fixes within macros? Maybe warnings as well.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64671/new/

https://reviews.llvm.org/D64671



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64634: [clangd] Fix duplicate highlighting tokens appearing in initializer lists

2019-07-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Have we tried figuring out why `RecursiveASTVisitor` visits the argument lists 
twice? Is that an expected behavior?




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:37
+llvm::sort(Tokens,
+   [](const HighlightingToken &Lhs, const HighlightingToken &Rhs) {
+ return std::tie(Lhs.R, Lhs.Kind) < std::tie(Rhs.R, Rhs.Kind);

NIT: in LLVM style, these should be called `LHS` and `RHS` as they are 
abbreviations.
However, in clangd we typically use `L` and `R` for that in those cases, I 
would suggest sticking to that.

(One-letter names are harder to confuse with each other)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64634/new/

https://reviews.llvm.org/D64634



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:299
   // return statement
   return ^1;
 }

SureYeaah wrote:
> kadircet wrote:
> > left out this one ?
> Since that's an IntegerLiteral, this patch doesn't apply to it?
nvm this one, it was for "empyt selection triggering" case.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:323
   while(a < ^1)
-^a++;
+[[a++]];
   // do while 

I thought extractor didn't handle this case(missing braces).

What is the extraction in this case? Because if it is

```
auto dummy = a++;
while (a < 1)
   dummy++;
```

it is not going to be semantically same.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64736: [clang-tidy] New bugprone-infinite-loop check for detecting obvious infinite loops

2019-07-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/bugprone/InfiniteLoopCheck.cpp:164
+
+  std::string Result = "";
+  for (const Stmt *Child : Cond->children()) {

Unnecessary initialization. See readability-redundant-string-init.



Comment at: docs/ReleaseNotes.rst:114
 
+- New :doc:`bugprone-infinite-loop
+  ` check.

Wrong entry.



Comment at: docs/ReleaseNotes.rst:238
 
+- New :doc:`bugprone-infinite-loop `
+  check to detect obvious infinite loops (loops where the condition variable is

Please move into new checks list (in alphabetical order)



Comment at: docs/ReleaseNotes.rst:239
+- New :doc:`bugprone-infinite-loop `
+  check to detect obvious infinite loops (loops where the condition variable is
+  not changed at all).

Please separate with empty line and use first statement from documentation here.



Comment at: docs/clang-tidy/checks/bugprone-infinite-loop.rst:13
+detects such loops. A loop is considered as infinite if it does not have any
+loop exit statement (`break`, `continue`, `goto`, `return`, `throw`) and all of
+the following conditions hold for every variable in the condition:

Please use double back-ticks to highlight language constructs. Same below.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64736/new/

https://reviews.llvm.org/D64736



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah added a comment.

In D64717#1585512 , @sammccall wrote:

> Are you sure we want to disable extraction here, rather than just do the 
> extraction at a higher level?
>
> E.g. if `bar(1,2,3, f[[o]]o(4,5));` seems like it should extract the call too 
> `foo(4,5)`, not fail to trigger entirely.


Selecting `f[[o]]o(4,5)` will just extract the `foo` which would be a 
`DeclRefExpr`. We want to extract the `CallExpr` for which we would need to 
select the brackets as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah marked an inline comment as done.
SureYeaah added inline comments.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:323
   while(a < ^1)
-^a++;
+[[a++]];
   // do while 

kadircet wrote:
> I thought extractor didn't handle this case(missing braces).
> 
> What is the extraction in this case? Because if it is
> 
> ```
> auto dummy = a++;
> while (a < 1)
>dummy++;
> ```
> 
> it is not going to be semantically same.
We don't check for missing braces and continuing traversing up the AST until we 
find the CompoundStmt. 

Yes, it's not going to be semantically the same. We only check if after 
extraction, the extracted expression will reference a variable that hasn't been 
declared till that point.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64680: [analyzer] MallocChecker: Prevent Integer Set Library false positives

2019-07-15 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 209849.
Charusso added a comment.

- Remove unnecessary `DoNothing` kind.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64680/new/

https://reviews.llvm.org/D64680

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/retain-count-alloc.cpp

Index: clang/test/Analysis/retain-count-alloc.cpp
===
--- /dev/null
+++ clang/test/Analysis/retain-count-alloc.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix.Malloc \
+// RUN:  -verify %s
+
+// expected-no-diagnostics: We do not model Integer Set Library's retain-count
+//  based allocation.
+
+#define __isl_take
+#define __isl_keep
+
+struct Object { int Ref; };
+void free(void *);
+
+Object *copyObj(__isl_keep Object *O) {
+  O->Ref++;
+  return O;
+}
+
+void freeObj(__isl_take Object *O) {
+  if (--O->Ref > 0)
+return;
+
+  free(O);
+}
+
+void useAfterFree(__isl_take Object *A) {
+  if (!A)
+return;
+
+  Object *B = copyObj(A);
+  freeObj(B);
+
+  A->Ref = 13;
+  // no-warning: 'Use of memory after it is freed' was here.
+}
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/ParentMap.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -359,6 +360,9 @@
   /// Check if the memory associated with this symbol was released.
   bool isReleased(SymbolRef Sym, CheckerContext &C) const;
 
+  /// Check whether we do not model the memory allocation.
+  bool isNotModeled(const CallExpr *CE, CheckerContext &C) const;
+
   bool checkUseAfterFree(SymbolRef Sym, CheckerContext &C, const Stmt *S) const;
 
   void checkUseZeroAllocated(SymbolRef Sym, CheckerContext &C,
@@ -877,6 +881,9 @@
   State = ProcessZeroAllocation(C, CE, 0, State);
   State = ProcessZeroAllocation(C, CE, 1, State);
 } else if (FunI == II_free || FunI == II_g_free || FunI == II_kfree) {
+  if (isNotModeled(CE, C))
+return;
+
   State = FreeMemAux(C, CE, State, 0, false, ReleasedAllocatedMemory);
 } else if (FunI == II_strdup || FunI == II_win_strdup ||
FunI == II_wcsdup || FunI == II_win_wcsdup) {
@@ -2532,6 +2539,45 @@
   return (RS && RS->isReleased());
 }
 
+bool MallocChecker::isNotModeled(const CallExpr *CE, CheckerContext &C) const {
+  if (CE->getNumArgs() == 0)
+return false;
+
+  StringRef FunctionStr = "";
+  if (const Decl *D = C.getStackFrame()->getDecl())
+if (const FunctionDecl *FD = D->getAsFunction())
+  FunctionStr = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(
+  {FD->getBeginLoc(), FD->getBody()->getBeginLoc()}),
+  C.getSourceManager(), C.getLangOpts());
+
+  if (FunctionStr.equals(""))
+return false;
+
+  // We do not model the Integer Set Library's retain-count based allocation.
+  if (!FunctionStr.contains("__isl_"))
+return false;
+
+  ProgramStateRef State = C.getState();
+
+  for (const Expr *Arg : CE->arguments()) {
+if (const auto *DRE = dyn_cast(Arg->IgnoreImpCasts())) {
+  if (const auto *VD = dyn_cast(DRE->getDecl())) {
+SVal V = State->getSVal(State->getLValue(VD, C.getLocationContext()));
+if (SymbolRef Sym = V.getAsSymbol()) {
+  if (const RefState *RS = State->get(Sym)) {
+State = State->remove(Sym);
+State = State->set(Sym, RefState::getEscaped(RS));
+  }
+}
+  }
+}
+  }
+
+  C.addTransition(State);
+  return true;
+}
+
 bool MallocChecker::checkUseAfterFree(SymbolRef Sym, CheckerContext &C,
   const Stmt *S) const {
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:323
   while(a < ^1)
-^a++;
+[[a++]];
   // do while 

SureYeaah wrote:
> kadircet wrote:
> > I thought extractor didn't handle this case(missing braces).
> > 
> > What is the extraction in this case? Because if it is
> > 
> > ```
> > auto dummy = a++;
> > while (a < 1)
> >dummy++;
> > ```
> > 
> > it is not going to be semantically same.
> We don't check for missing braces and continuing traversing up the AST until 
> we find the CompoundStmt. 
> 
> Yes, it's not going to be semantically the same. We only check if after 
> extraction, the extracted expression will reference a variable that hasn't 
> been declared till that point.
I believe this behavior is not expected and we should address that as well, the 
expressions you extract might have weird side effects, therefore if some 
expression is within a loop body it should stay there.
No need to address in this patch though, could you (leave a fixme || create a 
bug) to make sure extraction of such expressions doesn't go to outer scope, but 
rather stays within the loop body?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64680: [analyzer] MallocChecker: Prevent Integer Set Library false positives

2019-07-15 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 4 inline comments as done.
Charusso added a comment.

In D64680#1584315 , @NoQ wrote:

> P.S. I think you should attach the report to Phabricator directly, as the 
> link will expire as soon as these reports get regenerated.


Luckily the stable scan-build namings are stable, so that is why I picked that 
handy option.




Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:56-58
+// If this checker does not model the allocation.
+DoNothing,
+// Reference to allocated memory.

NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > We already have `Escaped`, it's the same thing in practice.
> > It is more strict than `Escaped`, also it made for the purpose of 
> > `PSK_EscapeOther` to force out we lost the entire pointer and do not make 
> > false warnings of use-after-free.
> How exactly is it more strict? I.e., what warnings are getting suppressed by 
> you that aren't going to be suppressed if you use `Escaped` instead?
After some measurements the previously attached report has nothing to do with 
strictness, just we really miss some escaping. Reverted that.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64680/new/

https://reviews.llvm.org/D64680



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64741: [clangd] Added highlighting for tokens that are macro arguments.

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom created this revision.
jvikstrom added reviewers: hokein, sammccall, ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Adds semantic highlighting for tokens that are a macro argument.
Example:

  #define D_V(X) int X = 1230
  D_V(SomeVar);

The "SomeVar" inside the macro is highlighted as a variable now.

Tokens that are in a macro body expansion are ignored in this patch for three 
reasons.

- The spelling loc is inside the macro "definition" meaning it would highlight 
inside the macro definition (could probably easily be fixed by using 
getExpansionLoc instead of getSpellingLoc?)
- If wanting to highlight the macro definition this could create duplicate 
tokens. And if the tokens are of different types there would be conflicts 
(tokens in the same range but with different types). Say a macro defines some 
name and both a variable declaration and a function use this, there would be 
two tokens in the macro definition but one with Kind "Variable" and the other 
with Kind "Function".
- Thirdly, macro body expansions could come from a file that is not the main 
file (easily fixed, just check that the Loc is in the main file and not even a 
problem if we wanted to highlight the actual macro "invocation")


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64741

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,42 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  #define DEF_CLASS(T) class T {};
+  DEF_CLASS($Class[[A]])
+
+  #define MACRO_CONCAT(X, V, T) T foo##X = V
+  #define DEF_VAR(X, V) int X = V
+  #define DEF_VAR_T(T, X, V) T X = V
+  #define DEF_VAR_REV(V, X) DEF_VAR(X, V)
+  #define CPY(X) X
+  #define DEF_VAR_TYPE(X, Y) X Y
+  #define SOME_NAME variable
+  #define SOME_NAME_SET variable2 = 123
+  #define INC_VAR(X) X += 2
+  void $Function[[foo]]() {
+DEF_VAR($Variable[[X]],  123);
+DEF_VAR_REV(908, $Variable[[XY]]);
+int CPY( $Variable[[XX]] );
+DEF_VAR_TYPE($Class[[A]], $Variable[[AA]]);
+double SOME_NAME;
+int SOME_NAME_SET;
+$Variable[[variable]] = 20.1;
+MACRO_CONCAT(var, 2, float);
+DEF_VAR_T($Class[[A]], CPY(CPY($Variable[[Nested]])),
+  CPY($Class[[A]]()));
+INC_VAR($Variable[[variable]]);
+  }
+  void SOME_NAME();
+  DEF_VAR($Variable[[XYZ]], 567);
+  DEF_VAR_REV(756, $Variable[[AB]]);
+
+  #define CALL_FN(F) F();
+  #define DEF_FN(F) void F ()
+  DEF_FN($Function[[g]]) {
+CALL_FN($Function[[foo]]);
+  }
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -160,9 +160,15 @@
   }
 
   void addToken(SourceLocation Loc, HighlightingKind Kind) {
-if (Loc.isMacroID())
-  // FIXME: skip tokens inside macros for now.
-  return;
+if(Loc.isMacroID()) {
+  // If the location is not an argument it might be from a macro of the 
form
+  // "#define VAR var". In that case this would highlight "var" in the 
macro
+  // definition and if VAR is used for functions and variables there would
+  // be conflicts and duplicates. So skip those for now.
+  if (!SM.isMacroArgExpansion(Loc))
+return;
+  Loc = SM.getSpellingLoc(Loc);
+}
 
 auto R = getTokenRange(SM, Ctx.getLangOpts(), Loc);
 if (!R) {


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,42 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  #define DEF_CLASS(T) class T {};
+  DEF_CLASS($Class[[A]])
+
+  #define MACRO_CONCAT(X, V, T) T foo##X = V
+  #define DEF_VAR(X, V) int X = V
+  #define DEF_VAR_T(T, X, V) T X = V
+  #define DEF_VAR_REV(V, X) DEF_VAR(X, V)
+  #define CPY(X) X
+  #define DEF_VAR_TYPE(X, Y) X Y
+  #define SOME_NAME variable
+  #define SOME_NAME_SET variable2 = 123
+  #define INC_VAR(X) X += 2
+  void $Function[[foo]]() {

[PATCH] D64646: [OPENMP]Add support for analysis of if clauses.

2019-07-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev marked an inline comment as done.
ABataev added a comment.

Thanks for the review!




Comment at: test/Analysis/cfg-openmp.cpp:58-67
 #pragma omp distribute simd
   for (int i = 0; i < 10; ++i)
 argc = x;
-// CHECK-NEXT:  27: x
-// CHECK-NEXT:  28: [B1.27] (ImplicitCastExpr, LValueToRValue, int)
-// CHECK-NEXT:  29: argc
-// CHECK-NEXT:  30: [B1.29] = [B1.28]
-// CHECK-NEXT:  31: #pragma omp for
+// CHECK-NEXT:  [[#FOR:]]: x
+// CHECK-NEXT:  [[#FOR+1]]: [B1.[[#FOR]]] (ImplicitCastExpr, LValueToRValue, 
int)
+// CHECK-NEXT:  [[#FOR+2]]: argc
+// CHECK-NEXT:  [[#FOR+3]]: [B1.[[#FOR+2]]] = [B1.[[#FOR+1]]]

NoQ wrote:
> I'm slowly updating my mental model of these CFGs. Just to confirm my 
> understanding - tried the following example:
> 
> ```lang=c++
> int main(int argc, char **argv) {
>   int x = 0;
> #pragma omp for
>   for (int i = 0; i < 10; ++i)
> x += argv[i];
> }
> ```
> 
> The CFG was as follows:
> 
> ```
>1: 0
>2: int x = 0;
>3: x
>4: argv
>5: [B1.4] (ImplicitCastExpr, LValueToRValue, char **)
>6: i
>7: [B1.6] (ImplicitCastExpr, LValueToRValue, int)
>8: [B1.5][[B1.7]]
>9: [B1.8] (ImplicitCastExpr, LValueToRValue, char *)
>   10: [B1.3] += [B1.9]
>   11: #pragma omp for
> for (int i = 0; i < 10; ++i)
> [B1.10];
> ```
> 
> Do i understand correctly that `[B1.10]` aka `argv[0]` is going to act like 
> an "argument" to the "outlined function" and then it's going to be re-used 
> (as if it was a "local" "variable") on subsequent iterations of the loop 
> (i.e., assigned values `argv[1]`, ..., `argv[9]`)? I.e., the "function" is 
> going to be responsible for computing `argv[1]` and storing it in the 
> "parameter variable" (`OMPCapturedExprDecl` which is a sub-class of 
> `VarDecl`) that previously contained `argv[0]`, but it's not responsible for 
> computing `argv[0]` itself, right?
`argv` here is the shared variable, so it is passed by reference to the 
"outlined function". We do not create local copy of this variable here, we use 
the original `argv` in the "outlined function".
you can consider this code as something like this:
```
char **argv;
int x = 0;
outlined(x, argv);
...

void outlined(char **&argv, int &x) {
  for(int i =0; i < 10; ++i)
  x += argv[i];
}

```
This is very schematic but good enough to understand how it works.

`OMPCapturedExprDecl` is used only in some rare cases, when we need to pass the 
expression to the outlined region. For example:
```
#pragma omp target parallel if(a+b)

```
After codegen it must look like this:
```
 int .captured_expr. = a+b;
if (.captured_expr.) {
  offload target_outlined(.captured_expr.)
} else {
  call on host target_outlined(.captured_expr.)
}
...
void target_outlined(int .captured_expr.) {
  if (.captured_expr.)
parallel outlined();
  else
serialized outlined();
}
...
void outined() {
;
}
```
In this case `if` clause is applied to both, `target` and `parallel` 
constructs. We could capture variables `a` and `b` and calculate `a+b` inside 
of the target region but this is not effective. Instead, it is better to 
capture the result of `a+b` condition into the special variable and capture 
only this single variable by value (the value of clauses in most cases must be 
pre-evaluated before the real execution of the OpenMP construct). Does it make 
it a little bit clearer?
`OMPCapturedExprDecl` is used only in some rare cases, only for the complex 
combined constructs (which consists of several simple constructs) and only for 
the clauses, which require expression evaluation before entering the construct.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64646/new/

https://reviews.llvm.org/D64646



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64634: [clangd] Fix duplicate highlighting tokens appearing in initializer lists

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 209852.
jvikstrom marked an inline comment as done.
jvikstrom added a comment.

Address comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64634/new/

https://reviews.llvm.org/D64634

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,14 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(Tokens,
+   [](const HighlightingToken &L, const HighlightingToken &R) {
+ return std::tie(L.R, L.Kind) < std::tie(R.R, R.Kind);
+   });
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,14 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(Tokens,
+   [](const HighlightingToken &L, const HighlightingToken &R) {
+ return std::tie(L.R, L.Kind) < std::tie(R.R, R.Kind);
+   });
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64634: [clangd] Fix duplicate highlighting tokens appearing in initializer lists

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom added a comment.

In D64634#1585521 , @ilya-biryukov 
wrote:

> Have we tried figuring out why `RecursiveASTVisitor` visits the argument 
> lists twice? Is that an expected behavior?


The comment for the function that traverses initialization lists says this:

> // This method is called once for each pair of syntactic and semantic
>  // InitListExpr, and it traverses the subtrees defined by the two forms. This
>  // may cause some of the children to be visited twice, if they appear both in
>  // the syntactic and the semantic form.

So it seems to be expected. (and looking at the documentation for InitListExpr 
it seems to be difficult to change RecursiveASTVisitor to visit every sub expr 
once)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64634/new/

https://reviews.llvm.org/D64634



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 209853.
SureYeaah marked 2 inline comments as done.
SureYeaah added a comment.

Added comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -299,10 +299,10 @@
   return ^1;
 }
 void f() {
-  int a = 5 + [[4 ^* ^xyz^()]];
+  int a = 5 + [[4 ^* xyz^()]];
   // multivariable initialization
   if(1)
-int x = ^1, y = ^a + 1, a = ^1, z = a + 1;
+int x = ^1, y = [[a + 1]], a = ^1, z = a + 1;
   // if without else
   if(^1) {}
   // if with else
@@ -320,7 +320,7 @@
 a = ^2;
   // while 
   while(a < ^1)
-^a++;
+[[a++]];
   // do while 
   do
 a = ^1;
@@ -340,8 +340,10 @@
   return 1;
   class T {
 T(int a = ^1) {};
+T f() { return T(); }
 int xyz = ^1;
   };
+  [[T.[[^t();
 }
 // function default argument
 void f(int b = ^1) {
@@ -359,6 +361,10 @@
 a = ^a ^+ 1;
   // lambda 
   auto lamb = [&^a, &^b](int r = ^1) {return 1;}
+  // assigment 
+  [[a ^= 5]];
+  // DeclRefExpr
+  a = [[b]], b = [[xyz]]();
 }
   )cpp");
   // vector of pairs of input and output strings
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -77,16 +77,25 @@
   return Visitor.ReferencedDecls;
 }
 
-// An expr is not extractable if it's null or an expression of type void
-// FIXME: Ignore assignment (a = 1) Expr since it is extracted as dummy = a =
+// Decide which types of Exprs are allowed for extraction
 static bool isExtractableExpr(const clang::Expr *Expr) {
-  if (Expr) {
-const Type *ExprType = Expr->getType().getTypePtrOrNull();
-// FIXME: check if we need to cover any other types
-if (ExprType)
-  return !ExprType->isVoidType();
-  }
-  return false;
+  if (!Expr)
+return false;
+  // Expressions with type void can't be assigned.
+  // FIXME: check if we need to cover any other types
+  if (const Type *ExprType = Expr->getType().getTypePtrOrNull())
+if (ExprType->isVoidType())
+  return false;
+  // Extracting Exprs like a = 1 gives dummy = a = 1 which isn't useful.
+  if (const BinaryOperator *BinOpExpr =
+  llvm::dyn_cast_or_null(Expr))
+if (BinOpExpr->getOpcode() == BinaryOperatorKind::BO_Assign)
+  return false;
+  // Extracting just a = [[b]] or a = [[foo]]() isn't that useful.
+  // Extracting [[Foo.bar]]() is neither legal nor useful.
+  if (llvm::isa(Expr) || llvm::isa(Expr))
+return false;
+  return true;
 }
 
 ExtractionContext::ExtractionContext(const SelectionTree::Node *Node,
@@ -124,6 +133,7 @@
 
 // FIXME: Extraction from switch and case statements
 // FIXME: Doens't work for FoldExpr
+// FIXME: Ensure extraction from loops doesn't change semantics
 const clang::Stmt *ExtractionContext::computeInsertionPoint() const {
   // returns true if we can extract before InsertionPoint
   auto CanExtractOutside =


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -299,10 +299,10 @@
   return ^1;
 }
 void f() {
-  int a = 5 + [[4 ^* ^xyz^()]];
+  int a = 5 + [[4 ^* xyz^()]];
   // multivariable initialization
   if(1)
-int x = ^1, y = ^a + 1, a = ^1, z = a + 1;
+int x = ^1, y = [[a + 1]], a = ^1, z = a + 1;
   // if without else
   if(^1) {}
   // if with else
@@ -320,7 +320,7 @@
 a = ^2;
   // while 
   while(a < ^1)
-^a++;
+[[a++]];
   // do while 
   do
 a = ^1;
@@ -340,8 +340,10 @@
   return 1;
   class T {
 T(int a = ^1) {};
+T f() { return T(); }
 int xyz = ^1;
   };
+  [[T.[[^t();
 }
 // function default argument
 void f(int b = ^1) {
@@ -359,6 +361,10 @@
 a = ^a ^+ 1;
   // lambda 
   auto lamb = [&^a, &^b](int r = ^1) {return 1;}
+  // assigment 
+  [[a ^= 5]];
+  // DeclRefExpr
+  a = [[b]], b = [[xyz]]();
 }
   )cpp");
   // vector of pairs of input and output strings
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
---

[PATCH] D64742: Allow using -ftrivial-auto-var-init=zero in C mode without extra flags

2019-07-15 Thread Alexander Potapenko via Phabricator via cfe-commits
glider created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Initially concerns have been raised that -ftrivial-auto-var-init=zero
potentially defines a new dialect of C++, therefore this option was
guarded with
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang.

The guard flag name suggests that at some point
-ftrivial-auto-var-init=pattern will perform on par with
-ftrivial-auto-var-init=zero, thus making it possible to remove the
latter from Clang.
However this isn't going to happen in the nearest future, at least not
on X86, where `memset(object, 0, size)` is still lowered to a more
efficient code than `memset(object, 0xAA, size)`.
Therefore security-minded people may still need an easy way to
zero-initialize all the locals to keep the performance penalty low.

For Linux kernel, which already uses a non-standard dialect of C,
introducing yet another hardening feature doesn't radically change the
situation. Other C codebases also tend to use non-standard features more
often, so the mentioned guard flag only complicates the adoption of
auto-initialization for them, not actually protecting their purity.

As a compromise solution, let
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
remain mandatory for -ftrivial-auto-var-init=zero in C++ mode and make
it optional in the C mode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64742

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/clang_f_opts.c


Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -566,7 +566,10 @@
 // RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | 
FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck 
-check-prefix=CHECK-TRIVIAL-PATTERN %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=zero 
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang %s 
2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-GOOD %s
-// RUN: %clang -### -S -ftrivial-auto-var-init=zero %s 2>&1 | FileCheck 
-check-prefix=CHECK-TRIVIAL-ZERO-BAD %s
+// RUN: %clang -### -S -ftrivial-auto-var-init=zero %s 2>&1 | FileCheck 
-check-prefix=CHECK-TRIVIAL-ZERO-GOOD %s
+// RUN: %clangxx -### -S -ftrivial-auto-var-init=zero 
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang %s 
2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-ZERO-GOOD %s
+// RUN: %clangxx -### -S -ftrivial-auto-var-init=zero %s 2>&1 | FileCheck 
-check-prefix=CHECK-TRIVIAL-ZERO-BAD %s
+
 // CHECK-TRIVIAL-UNINIT-NOT: hasn't been enabled
 // CHECK-TRIVIAL-PATTERN-NOT: hasn't been enabled
 // CHECK-TRIVIAL-ZERO-GOOD-NOT: hasn't been enabled
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2544,7 +2544,8 @@
 static void RenderTrivialAutoVarInitOptions(const Driver &D,
 const ToolChain &TC,
 const ArgList &Args,
-ArgStringList &CmdArgs) {
+ArgStringList &CmdArgs,
+const InputInfo &Input) {
   auto DefaultTrivialAutoVarInit = TC.GetDefaultTrivialAutoVarInit();
   StringRef TrivialAutoVarInit = "";
 
@@ -2578,7 +2579,9 @@
 }
 
   if (!TrivialAutoVarInit.empty()) {
-if (TrivialAutoVarInit == "zero" && 
!Args.hasArg(options::OPT_enable_trivial_var_init_zero))
+if (TrivialAutoVarInit == "zero" &&
+!Args.hasArg(options::OPT_enable_trivial_var_init_zero) &&
+(Input.getType() != types::TY_C))
   D.Diag(diag::err_drv_trivial_auto_var_init_zero_disabled);
 CmdArgs.push_back(
 Args.MakeArgString("-ftrivial-auto-var-init=" + TrivialAutoVarInit));
@@ -4623,7 +4626,7 @@
 CmdArgs.push_back(Args.MakeArgString("-mspeculative-load-hardening"));
 
   RenderSSPOptions(TC, Args, CmdArgs, KernelOrKext);
-  RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
+  RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs, Input);
 
   // Translate -mstackrealign
   if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,


Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -566,7 +566,10 @@
 // RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck -check-prefix=CHECK-TRIVIAL-PATTERN %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=zero -enable-trivial-auto-var-i

[PATCH] D64744: Loop #pragma tail_predicate

2019-07-15 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer created this revision.

https://reviews.llvm.org/D64744

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CGLoopInfo.cpp
  clang/lib/CodeGen/CGLoopInfo.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/CodeGenCXX/pragma-tail-predicate.cpp
  clang/test/Parser/pragma-tail-predicate.cpp

Index: clang/test/Parser/pragma-tail-predicate.cpp
===
--- /dev/null
+++ clang/test/Parser/pragma-tail-predicate.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+// Note that this puts the expected lines before the directives to work around
+// limitations in the -verify mode.
+
+int foo(int *a, int N) {
+  int sum = 0;
+
+  #pragma tail_predicate
+  for (int i = 0; i < N; i++)
+sum += a[i];
+
+
+  #pragma tail_predicate
+  /* expected-error {{expected a for, while, or do-while loop to follow '#pragma tail_predicate'}} */ int b;
+
+  return sum;
+}
Index: clang/test/CodeGenCXX/pragma-tail-predicate.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pragma-tail-predicate.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple arm-none-eabi -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK:  !{!"llvm.loop.tailpredicate"}
+
+int foo(int *a, int N) {
+  int sum = 0;
+
+  #pragma tail_predicate
+  for (int i = 0; i < N; i++)
+sum += a[i];
+
+  return sum;
+}
Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -85,6 +85,7 @@
   StringRef PragmaName =
   llvm::StringSwitch(PragmaNameLoc->Ident->getName())
   .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam",
+ "tail_predicate",
  PragmaNameLoc->Ident->getName())
   .Default("clang loop");
 
@@ -118,6 +119,8 @@
   SetHints(LoopHintAttr::Unroll, LoopHintAttr::Enable);
   } else if (PragmaName == "nounroll_and_jam") {
 SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Disable);
+  } else if (PragmaName == "tail_predicate") {
+SetHints(LoopHintAttr::TailPredicate, LoopHintAttr::Enable);
   } else if (PragmaName == "unroll_and_jam") {
 // #pragma unroll_and_jam N
 if (ValueExpr)
@@ -189,7 +192,8 @@
 const LoopHintAttr *StateAttr;
 const LoopHintAttr *NumericAttr;
   } HintAttrs[] = {{nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr},
-   {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}};
+   {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr},
+   {nullptr, nullptr}};
 
   for (const auto *I : Attrs) {
 const LoopHintAttr *LH = dyn_cast(I);
@@ -205,7 +209,8 @@
   Unroll,
   UnrollAndJam,
   Distribute,
-  Pipeline
+  Pipeline,
+  TailPredicate
 } Category;
 switch (Option) {
 case LoopHintAttr::Vectorize:
@@ -232,6 +237,9 @@
 case LoopHintAttr::PipelineInitiationInterval:
   Category = Pipeline;
   break;
+case LoopHintAttr::TailPredicate:
+  Category = TailPredicate;
+  break;
 };
 
 assert(Category < sizeof(HintAttrs) / sizeof(HintAttrs[0]));
@@ -240,6 +248,7 @@
 if (Option == LoopHintAttr::Vectorize ||
 Option == LoopHintAttr::Interleave || Option == LoopHintAttr::Unroll ||
 Option == LoopHintAttr::UnrollAndJam ||
+Option == LoopHintAttr::TailPredicate ||
 Option == LoopHintAttr::PipelineDisabled ||
 Option == LoopHintAttr::Distribute) {
   // Enable|Disable|AssumeSafety hint.  For example, vectorize(enable).
Index: clang/lib/Parse/ParsePragma.cpp
===
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -372,6 +372,10 @@
   llvm::make_unique("unroll_and_jam");
   PP.AddPragmaHandler(UnrollAndJamHintHandler.get());
 
+  TailPredicateHintHandler =
+  llvm::make_unique("tail_predicate");
+  PP.AddPragmaHandler(TailPredicateHintHandler.get());
+
   NoUnrollAndJamHintHandler =
   llvm::make_unique("nounroll_and_jam");
   PP.AddPragmaHandler(NoUnrollAndJamHintHandler.get());
@@ -479,6 +483,9 @@
   PP.RemovePragmaHandler(UnrollAndJamHintHandler.get());
   UnrollAndJamHintHandler.reset();
 
+  PP.RemovePragmaHandler(TailPredicateHintHandler.get());
+  TailPredicateHintHandler.reset();
+
   PP.RemovePragmaHandler(NoUnrollAndJamHintHandler.get());
   NoUnrollAndJamHintHandler.reset();
 
@@ -1006,17 +1013,13 @@
 } // end anonymous namespace
 
 static std::string PragmaLoopHintString(Token PragmaName, Token Option) {
-  std::string PragmaString;
-  if (PragmaName.getIdentifierInfo()->getName() == "loop") {
-PragmaString = "clang loop ";
-PragmaString += Option.getIdentifierInfo()->getName();
-  } else if (PragmaName.getIdentifierInfo()->g

[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D64717#1585542 , @SureYeaah wrote:

> In D64717#1585512 , @sammccall wrote:
>
> > Are you sure we want to disable extraction here, rather than just do the 
> > extraction at a higher level?
> >
> > E.g. if `bar(1,2,3, f[[o]]o(4,5));` seems like it should extract the call 
> > too `foo(4,5)`, not fail to trigger entirely.
>
>
> Selecting `f[[o]]o(4,5)` will just extract the `foo` which would be a 
> `DeclRefExpr`. We want to extract the `CallExpr` for which we would need to 
> select the brackets as well.


I agree, but this patch doesn't do that. (I think?)
Instead it bans extraction entirely in this case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r366068 - [OPENMP]Add support for analysis of if clauses.

2019-07-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jul 15 07:46:23 2019
New Revision: 366068

URL: http://llvm.org/viewvc/llvm-project?rev=366068&view=rev
Log:
[OPENMP]Add support for analysis of if clauses.

Summary:
Added support for analysis of if clauses in the OpenMP directives to be
able to check for the use of uninitialized variables.

Reviewers: NoQ

Subscribers: guansong, jfb, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64646

Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/test/Analysis/cfg-openmp.cpp
cfe/trunk/test/OpenMP/cancel_if_messages.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_if_messages.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_if_messages.cpp
cfe/trunk/test/OpenMP/parallel_sections_if_messages.cpp
cfe/trunk/test/OpenMP/target_data_if_messages.cpp
cfe/trunk/test/OpenMP/target_enter_data_if_messages.cpp
cfe/trunk/test/OpenMP/target_exit_data_if_messages.cpp
cfe/trunk/test/OpenMP/target_if_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_if_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_if_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_if_messages.cpp
cfe/trunk/test/OpenMP/target_simd_if_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_if_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_if_messages.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_if_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_if_messages.cpp
cfe/trunk/test/OpenMP/target_teams_if_messages.cpp
cfe/trunk/test/OpenMP/target_update_if_messages.cpp
cfe/trunk/test/OpenMP/task_if_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_if_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_if_messages.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=366068&r1=366067&r2=366068&view=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Mon Jul 15 07:46:23 2019
@@ -501,11 +501,10 @@ public:
 return const_child_range(&Condition, &Condition + 1);
   }
 
-  child_range used_children() {
-return child_range(child_iterator(), child_iterator());
-  }
+  child_range used_children();
   const_child_range used_children() const {
-return const_child_range(const_child_iterator(), const_child_iterator());
+auto Children = const_cast(this)->used_children();
+return const_child_range(Children.begin(), Children.end());
   }
 
   static bool classof(const OMPClause *T) {

Modified: cfe/trunk/lib/AST/OpenMPClause.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OpenMPClause.cpp?rev=366068&r1=366067&r2=366068&view=diff
==
--- cfe/trunk/lib/AST/OpenMPClause.cpp (original)
+++ cfe/trunk/lib/AST/OpenMPClause.cpp Mon Jul 15 07:46:23 2019
@@ -209,6 +209,25 @@ const OMPClauseWithPostUpdate *OMPClause
   return nullptr;
 }
 
+/// Gets the address of the original, non-captured, expression used in the
+/// clause as the preinitializer.
+static Stmt **getAddrOfExprAsWritten(Stmt *S) {
+  if (!S)
+return nullptr;
+  if (auto *DS = dyn_cast(S)) {
+assert(DS->isSingleDecl() && "Only single expression must be captured.");
+if (auto *OED = dyn_cast(DS->getSingleDecl()))
+  return OED->getInitAddress();
+  }
+  return nullptr;
+}
+
+OMPClause::child_range OMPIfClause::used_children() {
+  if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
+return child_range(C, C + 1);
+  return child_range(&Condition, &Condition + 1);
+}
+
 OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
unsigned NumLoops,
SourceLocation StartLoc,

Modified: cfe/trunk/test/Analysis/cfg-openmp.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cfg-openmp.cpp?rev=366068&r1=366067&r2=366068&view=diff
==
--- cfe/trunk/test/Analysis/cfg-openmp.cpp (original)
+++ cfe/trunk/test/Analysis/cfg-openmp.cpp Mon Jul 15 07:46:23 2019
@@ -1,340 +1,402 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG %s 2>&1 -fopenmp | 
FileCheck %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG %s 2>&1 -fopenmp 
-fopenmp-version=45 | FileCheck %s
 
 // CHECK-LABEL:  void xxx(int argc)
 void xxx(int argc) {
 // CHECK:[B1]
 // CHECK-NEXT:   1: int x;

[PATCH] D64745: [clangd] BackgroundIndex stores shards to the closest project

2019-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Changes persistance logic to store shards at the directory of closest
CDB. Previously we were storing all shards to directory of the CDB that
triggered indexing, it had its downsides.

For example, if you had two TUs coming from a different CDB but depending on the
same header foo.h, we will store the foo.h only for the first CDB, and it would
be missing for the second and we would never persist it since it was actually
present in the memory and persisted before.

This patch still stores only a single copy of a shard, but makes the directory a
function of the file name. So that the shard place will be unique even with
multiple CDBs accessing the file. This directory is determined as the first
directory containing a CDB in the file's parent directories, if no such
directory exists we make use of the home directory.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64745

Files:
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/Background.h
  clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
  clang-tools-extra/clangd/index/BackgroundIndexLoader.h
  clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
  clang-tools-extra/clangd/test/Inputs/background-index/definition.jsonrpc
  clang-tools-extra/clangd/test/Inputs/background-index/foo.cpp
  clang-tools-extra/clangd/test/Inputs/background-index/foo.h
  
clang-tools-extra/clangd/test/Inputs/background-index/sub_dir/compile_flags.txt
  clang-tools-extra/clangd/test/Inputs/background-index/sub_dir/foo.h
  clang-tools-extra/clangd/test/background-index.test

Index: clang-tools-extra/clangd/test/background-index.test
===
--- clang-tools-extra/clangd/test/background-index.test
+++ clang-tools-extra/clangd/test/background-index.test
@@ -5,7 +5,8 @@
 # RUN: rm -rf %t
 # RUN: cp -r %S/Inputs/background-index %t
 # Need to embed the correct temp path in the actual JSON-RPC requests.
-# RUN: sed -i -e "s|DIRECTORY|%t|" %t/*
+# RUN: sed -i -e "s|DIRECTORY|%t|" %t/definition.jsonrpc
+# RUN: sed -i -e "s|DIRECTORY|%t|" %t/compile_commands.json
 
 # We're editing bar.cpp, which includes foo.h.
 # foo() is declared in foo.h and defined in foo.cpp.
@@ -14,6 +15,7 @@
 
 # Test that the index is writing files in the expected location.
 # RUN: ls %t/.clangd/index/foo.cpp.*.idx
+# RUN: ls %t/sub_dir/.clangd/index/foo.h.*.idx
 
 # Test the index is read from disk: delete code and restart clangd.
 # RUN: rm %t/foo.cpp
Index: clang-tools-extra/clangd/test/Inputs/background-index/foo.h
===
--- /dev/null
+++ clang-tools-extra/clangd/test/Inputs/background-index/foo.h
@@ -1,4 +0,0 @@
-#ifndef FOO_H
-#define FOO_H
-int foo();
-#endif
Index: clang-tools-extra/clangd/test/Inputs/background-index/foo.cpp
===
--- clang-tools-extra/clangd/test/Inputs/background-index/foo.cpp
+++ clang-tools-extra/clangd/test/Inputs/background-index/foo.cpp
@@ -1,2 +1,2 @@
-#include "foo.h"
+#include "sub_dir/foo.h"
 int foo() { return 42; }
Index: clang-tools-extra/clangd/test/Inputs/background-index/definition.jsonrpc
===
--- clang-tools-extra/clangd/test/Inputs/background-index/definition.jsonrpc
+++ clang-tools-extra/clangd/test/Inputs/background-index/definition.jsonrpc
@@ -18,7 +18,7 @@
   "uri": "file://DIRECTORY/bar.cpp",
   "languageId": "cpp",
   "version": 1,
-  "text": "#include \"foo.h\"\nint main(){\nreturn foo();\n}"
+  "text": "#include \"sub_dir/foo.h\"\nint main(){\nreturn foo();\n}"
 }
   }
 }
Index: clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
===
--- clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
+++ clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
@@ -6,9 +6,14 @@
 //
 //===--===//
 
+#include "GlobalCompilationDatabase.h"
 #include "Logger.h"
+#include "Path.h"
 #include "index/Background.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -119,11 +124,20 @@
 class DiskBackedIndexStorageManager {
 public:
   DiskBackedIndexStorageManager()
-  : IndexStorageMapMu(llvm::make_unique()) {}
+  : IndexStorageMapMu(llvm::make_unique()),
+CDB(llvm::make_unique(
+llvm::None)) {
+llvm::SmallString<128> HomeDir;
+llvm::sys::path::home_directory(HomeDir);
+this->HomeDir = HomeDir.str().

[PATCH] D64646: [OPENMP]Add support for analysis of if clauses.

2019-07-15 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366068: [OPENMP]Add support for analysis of if clauses. 
(authored by ABataev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64646/new/

https://reviews.llvm.org/D64646

Files:
  cfe/trunk/include/clang/AST/OpenMPClause.h
  cfe/trunk/lib/AST/OpenMPClause.cpp
  cfe/trunk/test/Analysis/cfg-openmp.cpp
  cfe/trunk/test/OpenMP/cancel_if_messages.cpp
  cfe/trunk/test/OpenMP/distribute_parallel_for_if_messages.cpp
  cfe/trunk/test/OpenMP/distribute_parallel_for_simd_if_messages.cpp
  cfe/trunk/test/OpenMP/parallel_for_if_messages.cpp
  cfe/trunk/test/OpenMP/parallel_for_simd_if_messages.cpp
  cfe/trunk/test/OpenMP/parallel_if_messages.cpp
  cfe/trunk/test/OpenMP/parallel_sections_if_messages.cpp
  cfe/trunk/test/OpenMP/target_data_if_messages.cpp
  cfe/trunk/test/OpenMP/target_enter_data_if_messages.cpp
  cfe/trunk/test/OpenMP/target_exit_data_if_messages.cpp
  cfe/trunk/test/OpenMP/target_if_messages.cpp
  cfe/trunk/test/OpenMP/target_parallel_for_if_messages.cpp
  cfe/trunk/test/OpenMP/target_parallel_for_simd_if_messages.cpp
  cfe/trunk/test/OpenMP/target_parallel_if_messages.cpp
  cfe/trunk/test/OpenMP/target_simd_if_messages.cpp
  cfe/trunk/test/OpenMP/target_teams_distribute_if_messages.cpp
  cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_if_messages.cpp
  
cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_if_messages.cpp
  cfe/trunk/test/OpenMP/target_teams_distribute_simd_if_messages.cpp
  cfe/trunk/test/OpenMP/target_teams_if_messages.cpp
  cfe/trunk/test/OpenMP/target_update_if_messages.cpp
  cfe/trunk/test/OpenMP/task_if_messages.cpp
  cfe/trunk/test/OpenMP/teams_distribute_parallel_for_if_messages.cpp
  cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_if_messages.cpp

Index: cfe/trunk/include/clang/AST/OpenMPClause.h
===
--- cfe/trunk/include/clang/AST/OpenMPClause.h
+++ cfe/trunk/include/clang/AST/OpenMPClause.h
@@ -501,11 +501,10 @@
 return const_child_range(&Condition, &Condition + 1);
   }
 
-  child_range used_children() {
-return child_range(child_iterator(), child_iterator());
-  }
+  child_range used_children();
   const_child_range used_children() const {
-return const_child_range(const_child_iterator(), const_child_iterator());
+auto Children = const_cast(this)->used_children();
+return const_child_range(Children.begin(), Children.end());
   }
 
   static bool classof(const OMPClause *T) {
Index: cfe/trunk/test/OpenMP/target_parallel_for_simd_if_messages.cpp
===
--- cfe/trunk/test/OpenMP/target_parallel_for_simd_if_messages.cpp
+++ cfe/trunk/test/OpenMP/target_parallel_for_simd_if_messages.cpp
@@ -9,6 +9,13 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int cond; // expected-note {{initialize the variable 'cond' to silence this warning}}
+#pragma omp target parallel for simd if(parallel: cond) // expected-warning {{variable 'cond' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note {{declared here}}
 
 template  // expected-note {{declared here}}
Index: cfe/trunk/test/OpenMP/target_teams_distribute_simd_if_messages.cpp
===
--- cfe/trunk/test/OpenMP/target_teams_distribute_simd_if_messages.cpp
+++ cfe/trunk/test/OpenMP/target_teams_distribute_simd_if_messages.cpp
@@ -9,6 +9,13 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int cond; // expected-note {{initialize the variable 'cond' to silence this warning}}
+#pragma omp target teams distribute simd if(cond) // expected-warning {{variable 'cond' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note {{declared here}}
 
 template  // expected-note {{declared here}}
Index: cfe/trunk/test/OpenMP/parallel_if_messages.cpp
===
--- cfe/trunk/test/OpenMP/parallel_if_messages.cpp
+++ cfe/trunk/test/OpenMP/parallel_if_messages.cpp
@@ -9,6 +9,13 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int cond; // expected-note {{initialize the variable 'cond' to silence this warning}}
+#pragma omp parallel if(cond) // expected-warning {{variable 'cond' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note {{declared here}}
 
 template  // expected-note {{declared here}}
Index: cfe/trunk/test/OpenMP/teams_distribute_parallel_for_if_messages.cpp
===
--- cfe/trunk/test/OpenMP/teams_distribute_parallel_for_if_messages.cpp
+++ cfe/trunk/test/OpenMP/teams_distribute_parallel_for_if_messages.cpp
@@ -9,6 +9,14 @@
   return argc;
 }
 

[PATCH] D64634: [clangd] Fix duplicate highlighting tokens appearing in initializer lists

2019-07-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM (I think @hokein 's comments were addressed too)

> So it seems to be expected. (and looking at the documentation for 
> InitListExpr it seems to be difficult to change RecursiveASTVisitor to visit 
> every sub expr once)

Ah, this particular piece of behavior seems really surprising to me.
We should definitely only traverse syntactic form if `shouldVisitImplicitCode() 
== true`, which should help us avoid this corner case here. But that's a topic 
for a separate patch, please land this to unbreak semantic highlighting.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64634/new/

https://reviews.llvm.org/D64634



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah added a comment.

In D64717#1585632 , @sammccall wrote:

> In D64717#1585542 , @SureYeaah wrote:
>
> > In D64717#1585512 , @sammccall 
> > wrote:
> >
> > > Are you sure we want to disable extraction here, rather than just do the 
> > > extraction at a higher level?
> > >
> > > E.g. if `bar(1,2,3, f[[o]]o(4,5));` seems like it should extract the call 
> > > too `foo(4,5)`, not fail to trigger entirely.
> >
> >
> > Selecting `f[[o]]o(4,5)` will just extract the `foo` which would be a 
> > `DeclRefExpr`. We want to extract the `CallExpr` for which we would need to 
> > select the brackets as well.
>
>
> I agree, but this patch doesn't do that. (I think?)
>  Instead it bans extraction entirely in this case.


Yes it doesn't. Our current model doesn't extend the user selection and as such 
we only check the commonAncestor of whatever the user has selected. Should this 
be changed then?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61479: Finish "Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO"

2019-07-15 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg updated this revision to Diff 209865.
sberg added a comment.

- Disallowed -fsanitize=function in combination with -fsanitize-minimal-runtime 
now.

- Left the ubsan test's RUN lines and \#include magic as-is, if there's no 
clearly better way to avoid this unfortunate complexity.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61479/new/

https://reviews.llvm.org/D61479

Files:
  clang/docs/UndefinedBehaviorSanitizer.rst
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/ubsan-function.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/lib/ubsan/ubsan_handlers_cxx.cc
  compiler-rt/lib/ubsan/ubsan_handlers_cxx.h
  compiler-rt/lib/ubsan/ubsan_interface.inc
  compiler-rt/test/ubsan/TestCases/TypeCheck/Function/function.cpp

Index: compiler-rt/test/ubsan/TestCases/TypeCheck/Function/function.cpp
===
--- compiler-rt/test/ubsan/TestCases/TypeCheck/Function/function.cpp
+++ compiler-rt/test/ubsan/TestCases/TypeCheck/Function/function.cpp
@@ -1,11 +1,53 @@
-// RUN: %clangxx -std=c++17 -fsanitize=function %s -O3 -g -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx -DDETERMINE_UNIQUE %s -o %t-unique
+// RUN: %clangxx -std=c++17 -fsanitize=function %s -O3 -g -DSHARED_LIB -fPIC -shared -o %t-so.so
+// RUN: %clangxx -std=c++17 -fsanitize=function %s -O3 -g -o %t %t-so.so
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK $(%run %t-unique UNIQUE)
 // Verify that we can disable symbolization if needed:
-// RUN: %env_ubsan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
+// RUN: %env_ubsan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM $(%run %t-unique NOSYM-UNIQUE)
 // XFAIL: windows-msvc
 // Unsupported function flag
 // UNSUPPORTED: openbsd
 
+#ifdef DETERMINE_UNIQUE
+
+#include 
+
+#include "../../../../../lib/sanitizer_common/sanitizer_platform.h"
+
+int main(int, char **argv) {
+  if (!SANITIZER_NON_UNIQUE_TYPEINFO)
+std::cout << "--check-prefix=" << argv[1];
+}
+
+#else
+
+struct Shared {};
+using FnShared = void (*)(Shared *);
+FnShared getShared();
+
+struct __attribute__((visibility("hidden"))) Hidden {};
+using FnHidden = void (*)(Hidden *);
+FnHidden getHidden();
+
+namespace {
+struct Private {};
+} // namespace
+using FnPrivate = void (*)(void *);
+FnPrivate getPrivate();
+
+#ifdef SHARED_LIB
+
+void fnShared(Shared *) {}
+FnShared getShared() { return fnShared; }
+
+void fnHidden(Hidden *) {}
+FnHidden getHidden() { return fnHidden; }
+
+void fnPrivate(Private *) {}
+FnPrivate getPrivate() { return reinterpret_cast(fnPrivate); }
+
+#else
+
 #include 
 
 void f() {}
@@ -64,12 +106,31 @@
   p2(0);
 }
 
+void check_cross_dso() {
+  getShared()(nullptr);
+
+  // UNIQUE: function.cpp:[[@LINE+2]]:3: runtime error: call to function fnHidden(Hidden*) through pointer to incorrect function type 'void (*)(Hidden *)'
+  // NOSYM-UNIQUE: function.cpp:[[@LINE+1]]:3: runtime error: call to function (unknown) through pointer to incorrect function type 'void (*)(Hidden *)'
+  getHidden()(nullptr);
+
+  // TODO: Unlike GCC, Clang fails to prefix the typeinfo name for the function
+  // type with "*", so this erroneously only fails for "*UNIQUE":
+  // UNIQUE: function.cpp:[[@LINE+2]]:3: runtime error: call to function fnPrivate((anonymous namespace)::Private*) through pointer to incorrect function type 'void (*)((anonymous namespace)::Private *)'
+  // NOSYM-UNIQUE: function.cpp:[[@LINE+1]]:3: runtime error: call to function (unknown) through pointer to incorrect function type 'void (*)((anonymous namespace)::Private *)'
+  reinterpret_cast(getPrivate())(nullptr);
+}
+
 int main(void) {
   make_valid_call();
   make_invalid_call();
   check_noexcept_calls();
+  check_cross_dso();
   // Check that no more errors will be printed.
   // CHECK-NOT: runtime error: call to function
   // NOSYM-NOT: runtime error: call to function
   make_invalid_call();
 }
+
+#endif
+
+#endif
Index: compiler-rt/lib/ubsan/ubsan_interface.inc
===
--- compiler-rt/lib/ubsan/ubsan_interface.inc
+++ compiler-rt/lib/ubsan/ubsan_interface.inc
@@ -21,8 +21,8 @@
 INTERFACE_FUNCTION(__ubsan_handle_dynamic_type_cache_miss_abort)
 INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow)
 INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow_abort)
-INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch)
-INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_abort)
+INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1)
+INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1_abort)
 INTERFACE_FUNCTION(__ubsan_handle_implicit_conversion)
 INTERFACE_FUNCTION(__ubsan_handle_implicit_conversion_abort)
 INTERFACE_FUNCTION(__ubsan_handle_invalid_builtin)
Index: compiler-rt/lib/ubsan/ubsan_handlers_cxx.h
===
--- compile

[PATCH] D58710: Added more detailed documentation for clangd

2019-07-15 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang-tools-extra/trunk/docs/clangd/Installation.rst:325
+
+  $ ln -s ~/myproject/compile_commands.json ~/myproject-build/
+

Isn't the order of the arguments the wrong way round here?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58710/new/

https://reviews.llvm.org/D58710



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64747: [clangd] Skip implicit nodes when traversing for highlightings

2019-07-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: jvikstrom, hokein.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Implicit code adds corner cases to handle and does not provide any value
as those nodes cannot be mapped back to source text.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64747

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -28,6 +28,10 @@
   HighlightingTokenCollector(ParsedAST &AST)
   : Ctx(AST.getASTContext()), SM(AST.getSourceManager()) {}
 
+  // Only highlight nodes that map to source code, skip implicitly generated
+  // code.
+  bool shouldVisitImplicitCode() const { return false; }
+
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -28,6 +28,10 @@
   HighlightingTokenCollector(ParsedAST &AST)
   : Ctx(AST.getASTContext()), SM(AST.getSourceManager()) {}
 
+  // Only highlight nodes that map to source code, skip implicitly generated
+  // code.
+  bool shouldVisitImplicitCode() const { return false; }
+
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64747: [clangd] Skip implicit nodes when traversing for highlightings

2019-07-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov abandoned this revision.
ilya-biryukov added a comment.

Ah, sorry, that's actually the default...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64747/new/

https://reviews.llvm.org/D64747



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64717: [Clangd] Fixed ExtractVariable for MemberExprs and Assignment Exprs

2019-07-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D64717#1585682 , @SureYeaah wrote:

> In D64717#1585632 , @sammccall wrote:
>
> > In D64717#1585542 , @SureYeaah 
> > wrote:
> >
> > > In D64717#1585512 , @sammccall 
> > > wrote:
> > >
> > > > Are you sure we want to disable extraction here, rather than just do 
> > > > the extraction at a higher level?
> > > >
> > > > E.g. if `bar(1,2,3, f[[o]]o(4,5));` seems like it should extract the 
> > > > call too `foo(4,5)`, not fail to trigger entirely.
> > >
> > >
> > > Selecting `f[[o]]o(4,5)` will just extract the `foo` which would be a 
> > > `DeclRefExpr`. We want to extract the `CallExpr` for which we would need 
> > > to select the brackets as well.
> >
> >
> > I agree, but this patch doesn't do that. (I think?)
> >  Instead it bans extraction entirely in this case.
>
>
> Yes it doesn't. Our current model doesn't extend the user selection and as 
> such we only check the commonAncestor of whatever the user has selected. 
> Should this be changed then?


Yes I think you want to walk up the tree like you do for finding the target 
stmt, giving up when you hit a non-expr.

This didn't matter prior to this patch as void subexprs are extremely rare. But 
declrefs are not!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64717/new/

https://reviews.llvm.org/D64717



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r366070 - [clangd] Fix duplicate highlighting tokens appearing in initializer lists.

2019-07-15 Thread Johan Vikstrom via cfe-commits
Author: jvikstrom
Date: Mon Jul 15 08:08:27 2019
New Revision: 366070

URL: http://llvm.org/viewvc/llvm-project?rev=366070&view=rev
Log:
[clangd] Fix duplicate highlighting tokens appearing in initializer lists.

Summary: The RecursiveASTVisitor sometimes visits exprs in initializer lists 
twice. Added deduplication to prevent duplicate highlighting tokens from 
appearing. Done by sorting and a linear search.

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64634

Modified:
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=366070&r1=366069&r2=366070&view=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Mon Jul 15 08:08:27 
2019
@@ -31,6 +31,14 @@ public:
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(Tokens,
+   [](const HighlightingToken &L, const HighlightingToken &R) {
+ return std::tie(L.R, L.Kind) < std::tie(R.R, R.Kind);
+   });
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 

Modified: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp?rev=366070&r1=366069&r2=366070&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Mon 
Jul 15 08:08:27 2019
@@ -166,6 +166,13 @@ TEST(SemanticHighlighting, GetsCorrectTo
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64634: [clangd] Fix duplicate highlighting tokens appearing in initializer lists

2019-07-15 Thread Johan Vikström via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366070: [clangd] Fix duplicate highlighting tokens appearing 
in initializer lists. (authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64634?vs=209852&id=209868#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64634/new/

https://reviews.llvm.org/D64634

Files:
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
  clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,14 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(Tokens,
+   [](const HighlightingToken &L, const HighlightingToken &R) {
+ return std::tie(L.R, L.Kind) < std::tie(R.R, R.Kind);
+   });
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 


Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -166,6 +166,13 @@
 $Variable[[AA]].$Field[[E]].$Field[[C]];
 $Class[[A]]::$Variable[[S]] = 90;
   }
+)cpp",
+R"cpp(
+  struct $Class[[AA]] {
+int $Field[[A]];
+  }
+  int $Variable[[B]];
+  $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -31,6 +31,14 @@
   std::vector collectTokens() {
 Tokens.clear();
 TraverseAST(Ctx);
+// Initializer lists can give duplicates of tokens, therefore all tokens
+// must be deduplicated.
+llvm::sort(Tokens,
+   [](const HighlightingToken &L, const HighlightingToken &R) {
+ return std::tie(L.R, L.Kind) < std::tie(R.R, R.Kind);
+   });
+auto Last = std::unique(Tokens.begin(), Tokens.end());
+Tokens.erase(Last, Tokens.end());
 return Tokens;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58710: Added more detailed documentation for clangd

2019-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/trunk/docs/clangd/Installation.rst:325
+
+  $ ln -s ~/myproject/compile_commands.json ~/myproject-build/
+

thakis wrote:
> Isn't the order of the arguments the wrong way round here?
yeah that seems to be the case it should rather be

`$ ln -s ~/myproject-build/compile_commands.json ~/myproject/`

sending out a patch, thanks for bringing it up!


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58710/new/

https://reviews.llvm.org/D58710



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r366073 - [clangd] Fix doc

2019-07-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Jul 15 08:16:57 2019
New Revision: 366073

URL: http://llvm.org/viewvc/llvm-project?rev=366073&view=rev
Log:
[clangd] Fix doc

Modified:
clang-tools-extra/trunk/docs/clangd/Installation.rst

Modified: clang-tools-extra/trunk/docs/clangd/Installation.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clangd/Installation.rst?rev=366073&r1=366072&r2=366073&view=diff
==
--- clang-tools-extra/trunk/docs/clangd/Installation.rst (original)
+++ clang-tools-extra/trunk/docs/clangd/Installation.rst Mon Jul 15 08:16:57 
2019
@@ -324,7 +324,7 @@ symlink it (or copy it) to the root of y
 
 ::
 
-  $ ln -s ~/myproject/compile_commands.json ~/myproject-build/
+  $ ln -s ~/myproject-build/compile_commands.json ~/myproject/
 
 :raw-html:``
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r366076 - fix unnamed fiefield issue and add tests for __builtin_preserve_access_index intrinsic

2019-07-15 Thread Yonghong Song via cfe-commits
Author: yhs
Date: Mon Jul 15 08:42:41 2019
New Revision: 366076

URL: http://llvm.org/viewvc/llvm-project?rev=366076&view=rev
Log:
fix unnamed fiefield issue and add tests for __builtin_preserve_access_index 
intrinsic

This is a followup patch for https://reviews.llvm.org/D61809.
Handle unnamed bitfield properly and add more test cases.

Fixed the unnamed bitfield issue. The unnamed bitfield is ignored
by debug info, so we need to ignore such a struct/union member
when we try to get the member index in the debug info.

D61809 contains two test cases but not enough as it does
not checking generated IRs in the fine grain level, and also
it does not have semantics checking tests.
This patch added unit tests for both code gen and semantics checking for
the new intrinsic.

Signed-off-by: Yonghong Song 

Added:
cfe/trunk/test/CodeGen/builtin-preserve-access-index.c
cfe/trunk/test/Sema/builtin-preserve-access-index.c
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=366076&r1=366075&r2=366076&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Jul 15 08:42:41 2019
@@ -3892,6 +3892,23 @@ LValue CodeGenFunction::EmitLValueForLam
   return EmitLValueForField(LambdaLV, Field);
 }
 
+/// Get the field index in the debug info. The debug info structure/union
+/// will ignore the unnamed bitfields.
+unsigned CodeGenFunction::getDebugInfoFIndex(const RecordDecl *Rec,
+ unsigned FieldIndex) {
+  unsigned I = 0, Skipped = 0;
+
+  for (auto F : Rec->getDefinition()->fields()) {
+if (I == FieldIndex)
+  break;
+if (F->isUnnamedBitfield())
+  Skipped++;
+I++;
+  }
+
+  return FieldIndex - Skipped;
+}
+
 /// Get the address of a zero-sized field within a record. The resulting
 /// address doesn't necessarily have the right type.
 static Address emitAddrOfZeroSizeField(CodeGenFunction &CGF, Address Base,
@@ -3931,7 +3948,7 @@ static Address emitPreserveStructAccess(
   CGF.CGM.getTypes().getCGRecordLayout(rec).getLLVMFieldNo(field);
 
   return CGF.Builder.CreatePreserveStructAccessIndex(
-  base, idx, field->getFieldIndex(), DbgInfo);
+  base, idx, CGF.getDebugInfoFIndex(rec, field->getFieldIndex()), DbgInfo);
 }
 
 static bool hasAnyVptr(const QualType Type, const ASTContext &Context) {
@@ -4048,7 +4065,7 @@ LValue CodeGenFunction::EmitLValueForFie
   getContext().getRecordType(rec), rec->getLocation());
   addr = Address(
   Builder.CreatePreserveUnionAccessIndex(
-  addr.getPointer(), field->getFieldIndex(), DbgInfo),
+  addr.getPointer(), getDebugInfoFIndex(rec, 
field->getFieldIndex()), DbgInfo),
   addr.getAlignment());
 }
   } else {

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=366076&r1=366075&r2=366076&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Jul 15 08:42:41 2019
@@ -2652,6 +2652,9 @@ public:
   /// Converts Location to a DebugLoc, if debug information is enabled.
   llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location);
 
+  /// Get the record field index as represented in debug info.
+  unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex);
+
 
   
//======//
   //Declaration Emission

Added: cfe/trunk/test/CodeGen/builtin-preserve-access-index.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-preserve-access-index.c?rev=366076&view=auto
==
--- cfe/trunk/test/CodeGen/builtin-preserve-access-index.c (added)
+++ cfe/trunk/test/CodeGen/builtin-preserve-access-index.c Mon Jul 15 08:42:41 
2019
@@ -0,0 +1,177 @@
+// RUN: %clang -target x86_64 -emit-llvm -S -g %s -o - | FileCheck %s
+
+#define _(x) (__builtin_preserve_access_index(x))
+
+const void *unit1(const void *arg) {
+  return _(arg);
+}
+// CHECK: define dso_local i8* @unit1(i8* %arg)
+// CHECK-NOT: llvm.preserve.array.access.index
+// CHECK-NOT: llvm.preserve.struct.access.index
+// CHECK-NOT: llvm.preserve.union.access.index
+
+const void *unit2(void) {
+  return _((const void *)0xULL);
+}
+// CHECK: define dso_local i8* @unit2()
+// CHECK-NOT: llvm.preserve.array.access.index
+// CHECK-NOT: llvm.preserve.struct.access.index
+// CHECK-NOT: llvm.preserve.union.access.index
+
+const void *unit3(const int *arg) {
+  return _(arg + 1);
+}
+// CHECK: define dso_local i8* @un

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 209873.
Manikishan added a comment.

Is this change that was meant?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -665,6 +665,67 @@
  "#include \"a.h\""));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n",
+			sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+	
+}
+
+TEST_F(SortIncludesTest, SortedIncludesInSingleBlockReGroupWithNetBSDSpecifications) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"		
+   "#include \n"		
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"	
+   "#include \n"
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"pathnames.h\"\n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -278,8 +278,15 @@
   }
 };
 
-template <>
-struct ScalarEnumerationTraits {
+template <> struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO,
+  FormatStyle::IncludeHeadersStyle &Value) {
+IO.enumCase(Value, "None", FormatStyle::SIS_None);
+IO.enumCase(Value, "NetBSD", FormatStyle::SIS_NetBSD);
+  }
+};
+
+template <> struct ScalarEnumerationTraits {
   static void enumeration(IO &IO,
   FormatStyle::SpaceBeforeParensOptions &Value) {
 IO.enumCase(Value, "Never", FormatStyle::SBPO_Never);
@@ -479,6 +486,7 @@
 IO.mapOptional("RawStringFormats", Style.RawStringFormats);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
+IO.mapOptional("SortIncludesStyle", Style.SortIncludesStyle);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
@@ -609,7 +617,7 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
+false, false, false, false, false, 
 false, false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
@@ -759,6 +767,7 @@
 
   LLVMStyle.DisableFormat = false;
   LLVMStyle.SortIncludes = true;
+  LLVMStyle.SortIncludesStyle = FormatStyle::SIS_None;
   LLVMStyle.SortUsingDeclarations = true;
   LLVMStyle.StatementMacros.push_back("Q_UNUSED");
   LLVMStyle.StatementMacros.push_back("QT_REQUIRE_VERSION");
@@ -919,6 +928,7 @@
 "javax",
 };
 ChromiumStyle.SortIncludes = true;
+ChromiumStyle.SortIncludesStyle = FormatStyle::SIS_None;
   } else if (Language == FormatStyle::LK_JavaScript) {
 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
 ChromiumStyle.AllowShortLoopsOnASingleLine = false;
@@ -1023,6 +1033,30 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Ronald Wampler via Phabricator via cfe-commits
rdwampler added a comment.

I am not quite sure why this change is required to sort the headers for NetBSD, 
you can set the priorities via `IncludeStyle.IncludeCategories`. Is that not 
sufficient?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64748: Refactor threshold checking

2019-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 created this revision.
Herald added subscribers: cfe-commits, Szelethus, dkrupp.
Herald added a reviewer: martong.
Herald added a project: clang.
Herald added a subscriber: rnkovacs.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64748

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -340,6 +340,14 @@
   }
 }
 
+bool CrossTranslationUnitContext::checkThresholdReached() const {
+  if (NumASTLoaded >= CTULoadThreshold) {
+++NumASTLoadThresholdReached;
+return true;
+  }
+  return false;
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -348,11 +356,10 @@
   //translation units contains decls with the same lookup name an
   //error will be returned.
 
-  if (NumASTLoaded >= CTULoadThreshold) {
-++NumASTLoadThresholdReached;
+  // If import threshold is reached, don't import anything.
+  if (checkThresholdReached())
 return llvm::make_error(
 index_error_code::load_threshold_reached);
-  }
 
   ASTUnit *Unit = nullptr;
   auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -163,6 +163,7 @@
   void emitCrossTUDiagnostics(const IndexError &IE);
 
 private:
+  bool checkThresholdReached() const;
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
   ASTImporter &getOrCreateASTImporter(ASTContext &From);
   template 


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -340,6 +340,14 @@
   }
 }
 
+bool CrossTranslationUnitContext::checkThresholdReached() const {
+  if (NumASTLoaded >= CTULoadThreshold) {
+++NumASTLoadThresholdReached;
+return true;
+  }
+  return false;
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -348,11 +356,10 @@
   //translation units contains decls with the same lookup name an
   //error will be returned.
 
-  if (NumASTLoaded >= CTULoadThreshold) {
-++NumASTLoadThresholdReached;
+  // If import threshold is reached, don't import anything.
+  if (checkThresholdReached())
 return llvm::make_error(
 index_error_code::load_threshold_reached);
-  }
 
   ASTUnit *Unit = nullptr;
   auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -163,6 +163,7 @@
   void emitCrossTUDiagnostics(const IndexError &IE);
 
 private:
+  bool checkThresholdReached() const;
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
   ASTImporter &getOrCreateASTImporter(ASTContext &From);
   template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64749: Refactor CTUIndex lazy initialization

2019-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 created this revision.
Herald added subscribers: cfe-commits, Szelethus, arphaman, dkrupp.
Herald added a reviewer: martong.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64749

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -348,6 +348,29 @@
   return false;
 }
 
+llvm::Error CrossTranslationUnitContext::lazyInitCTUIndex(StringRef CrossTUDir,
+  StringRef IndexName) 
{
+  // Dont initialize if the map is filled.
+  if (!NameFileMap.empty())
+return llvm::Error::success();
+
+  // Get the absolute path to the index file.
+  SmallString<256> IndexFile = CrossTUDir;
+  if (llvm::sys::path::is_absolute(IndexName))
+IndexFile = IndexName;
+  else
+llvm::sys::path::append(IndexFile, IndexName);
+
+  if (auto IndexMapping = parseCrossTUIndex(IndexFile, CrossTUDir)) {
+// Initialize member map.
+NameFileMap = *IndexMapping;
+return llvm::Error::success();
+  } else {
+// Error while parsing CrossTU index file.
+return IndexMapping.takeError();
+  };
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -364,19 +387,9 @@
   ASTUnit *Unit = nullptr;
   auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);
   if (NameUnitCacheEntry == NameASTUnitMap.end()) {
-if (NameFileMap.empty()) {
-  SmallString<256> IndexFile = CrossTUDir;
-  if (llvm::sys::path::is_absolute(IndexName))
-IndexFile = IndexName;
-  else
-llvm::sys::path::append(IndexFile, IndexName);
-  llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFile, CrossTUDir);
-  if (IndexOrErr)
-NameFileMap = *IndexOrErr;
-  else
-return IndexOrErr.takeError();
-}
+// Lazily initialize the mapping from function names to AST files.
+if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName))
+  return std::move(InitFailed);
 
 auto It = NameFileMap.find(LookupName);
 if (It == NameFileMap.end()) {
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -164,6 +164,7 @@
 
 private:
   bool checkThresholdReached() const;
+  llvm::Error lazyInitCTUIndex(StringRef CrossTUDir, StringRef IndexName);
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
   ASTImporter &getOrCreateASTImporter(ASTContext &From);
   template 


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -348,6 +348,29 @@
   return false;
 }
 
+llvm::Error CrossTranslationUnitContext::lazyInitCTUIndex(StringRef CrossTUDir,
+  StringRef IndexName) {
+  // Dont initialize if the map is filled.
+  if (!NameFileMap.empty())
+return llvm::Error::success();
+
+  // Get the absolute path to the index file.
+  SmallString<256> IndexFile = CrossTUDir;
+  if (llvm::sys::path::is_absolute(IndexName))
+IndexFile = IndexName;
+  else
+llvm::sys::path::append(IndexFile, IndexName);
+
+  if (auto IndexMapping = parseCrossTUIndex(IndexFile, CrossTUDir)) {
+// Initialize member map.
+NameFileMap = *IndexMapping;
+return llvm::Error::success();
+  } else {
+// Error while parsing CrossTU index file.
+return IndexMapping.takeError();
+  };
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -364,19 +387,9 @@
   ASTUnit *Unit = nullptr;
   auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);
   if (NameUnitCacheEntry == NameASTUnitMap.end()) {
-if (NameFileMap.empty()) {
-  SmallString<256> IndexFile = CrossTUDir;
-  if (llvm::sys::path::is_absolute(IndexName))
-IndexFile = IndexName;
-  else
-llvm::sys::path::append(IndexFile, IndexName);
-  llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFile, CrossTUDir);
-  if (IndexOrErr)
-NameFileMap = *IndexOrErr;
-  else
-return IndexOrErr.takeError();
-}
+// Lazily initialize the mapping from function names to AST files.
+if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName))
+  return std::move(InitFailed);
 
 auto It = NameFileMap.find(LookupName);
 if (It == NameFileMa

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1585754 , @rdwampler wrote:

> I am not quite sure why this change is required to sort the headers for 
> NetBSD, you can set the priorities via `IncludeStyle.IncludeCategories`. Is 
> that not sufficient?


It can be done by setting priorities in IncludeCategories, but here we have 
nearly 40+ cases and categories to hardcode due to complex interdependencies 
between their headers. So, I have added this style decreasing the cases using 
regex.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64695/new/

https://reviews.llvm.org/D64695



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64748: Refactor threshold checking

2019-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 209882.
gamesh411 added a comment.

Incremental change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64748/new/

https://reviews.llvm.org/D64748

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -395,6 +395,18 @@
   ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts());
 }
 
+llvm::Expected
+CrossTranslationUnitContext::getASTFileNameForLookup(
+StringRef LookupName) const {
+  auto NameFileMapEntry = NameFileMap.find(LookupName);
+  if (NameFileMapEntry != NameFileMap.end()) {
+return NameFileMapEntry->second;
+  } else {
+++NumNotInOtherTU;
+return llvm::make_error(index_error_code::missing_definition);
+  }
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -418,21 +430,19 @@
   if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName))
 return std::move(InitFailed);
 
-  auto It = NameFileMap.find(LookupName);
-  if (It == NameFileMap.end()) {
-++NumNotInOtherTU;
-return llvm::make_error(index_error_code::missing_definition);
-  }
-  StringRef ASTFileName = It->second;
-  auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName);
+  llvm::Expected ASTFileName = 
getASTFileNameForLookup(LookupName);
+  if (!ASTFileName)
+return ASTFileName.takeError();
+
+  auto ASTCacheEntry = FileASTUnitMap.find(*ASTFileName);
   if (ASTCacheEntry == FileASTUnitMap.end()) {
 // Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
-std::unique_ptr LoadedUnit = loadFromASTFile(ASTFileName);
+  std::unique_ptr LoadedUnit = loadFromASTFile(*ASTFileName);
 Unit = LoadedUnit.get();
-FileASTUnitMap[ASTFileName] = std::move(LoadedUnit);
+FileASTUnitMap[*ASTFileName] = std::move(LoadedUnit);
 ++NumASTLoaded;
 if (DisplayCTUProgress) {
-  llvm::errs() << "CTU loaded AST file: " << ASTFileName << "\n";
+  llvm::errs() << "CTU loaded AST file: " << *ASTFileName << "\n";
 }
   } else {
 Unit = ASTCacheEntry->second.get();
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -167,6 +167,9 @@
   llvm::Error lazyInitCTUIndex(StringRef CrossTUDir, StringRef IndexName);
   ASTUnit *getCachedASTUnitForName(StringRef LookupName) const;
   std::unique_ptr loadFromASTFile(StringRef ASTFileName) const;
+  llvm::Expected
+  getASTFileNameForLookup(StringRef LookupName) const;
+
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
   ASTImporter &getOrCreateASTImporter(ASTContext &From);
   template 


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -395,6 +395,18 @@
   ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts());
 }
 
+llvm::Expected
+CrossTranslationUnitContext::getASTFileNameForLookup(
+StringRef LookupName) const {
+  auto NameFileMapEntry = NameFileMap.find(LookupName);
+  if (NameFileMapEntry != NameFileMap.end()) {
+return NameFileMapEntry->second;
+  } else {
+++NumNotInOtherTU;
+return llvm::make_error(index_error_code::missing_definition);
+  }
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -418,21 +430,19 @@
   if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName))
 return std::move(InitFailed);
 
-  auto It = NameFileMap.find(LookupName);
-  if (It == NameFileMap.end()) {
-++NumNotInOtherTU;
-return llvm::make_error(index_error_code::missing_definition);
-  }
-  StringRef ASTFileName = It->second;
-  auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName);
+  llvm::Expected ASTFileName = getASTFileNameForLookup(LookupName);
+  if (!ASTFileName)
+return ASTFileName.takeError();
+
+  auto ASTCacheEntry = FileASTUnitMap.find(*ASTFileName);
   if (ASTCacheEntry == FileASTUnitMap.end()) {
 // Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
-std::unique_ptr LoadedUnit = loadFromASTFile(ASTFileName);
+  std::unique_ptr LoadedUnit = loadFromASTFile(*ASTFileName);
 Unit = LoadedUnit.get();
-FileASTUnitMap[ASTFileName] = std::move(LoadedUnit);
+FileASTUnitMap[*ASTFileName] = std::move(LoadedUnit);
 ++NumASTLoaded;
 if (DisplayCTUProgress) {
-  llvm::errs() << "CTU loade

[PATCH] D64748: Refactor threshold checking

2019-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 209880.
gamesh411 added a comment.

Incremental change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64748/new/

https://reviews.llvm.org/D64748

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp

Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -371,6 +371,15 @@
   };
 }
 
+ASTUnit *CrossTranslationUnitContext::getCachedASTUnitForName(
+StringRef LookupName) const {
+  auto CacheEntry = NameASTUnitMap.find(LookupName);
+  if (CacheEntry != NameASTUnitMap.end())
+return CacheEntry->second;
+  else
+return nullptr;
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -384,45 +393,45 @@
 return llvm::make_error(
 index_error_code::load_threshold_reached);
 
-  ASTUnit *Unit = nullptr;
-  auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);
-  if (NameUnitCacheEntry == NameASTUnitMap.end()) {
-// Lazily initialize the mapping from function names to AST files.
-if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName))
-  return std::move(InitFailed);
-
-auto It = NameFileMap.find(LookupName);
-if (It == NameFileMap.end()) {
-  ++NumNotInOtherTU;
-  return llvm::make_error(index_error_code::missing_definition);
-}
-StringRef ASTFileName = It->second;
-auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName);
-if (ASTCacheEntry == FileASTUnitMap.end()) {
-  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
-  TextDiagnosticPrinter *DiagClient =
-  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
-  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
-  IntrusiveRefCntPtr Diags(
-  new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
-
-  std::unique_ptr LoadedUnit(ASTUnit::LoadFromASTFile(
-  ASTFileName, CI.getPCHContainerOperations()->getRawReader(),
-  ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts()));
-  Unit = LoadedUnit.get();
-  FileASTUnitMap[ASTFileName] = std::move(LoadedUnit);
-  ++NumASTLoaded;
-  if (DisplayCTUProgress) {
-llvm::errs() << "CTU loaded AST file: "
- << ASTFileName << "\n";
-  }
-} else {
-  Unit = ASTCacheEntry->second.get();
+  // First try to access the cache to get the ASTUnit for the function name
+  // specified by LookupName.
+  ASTUnit *Unit = getCachedASTUnitForName(LookupName);
+  if (Unit)
+return Unit;
+
+  // Lazily initialize the mapping from function names to AST files.
+  if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName))
+return std::move(InitFailed);
+
+  auto It = NameFileMap.find(LookupName);
+  if (It == NameFileMap.end()) {
+++NumNotInOtherTU;
+return llvm::make_error(index_error_code::missing_definition);
+  }
+  StringRef ASTFileName = It->second;
+  auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName);
+  if (ASTCacheEntry == FileASTUnitMap.end()) {
+IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+TextDiagnosticPrinter *DiagClient =
+new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
+IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+IntrusiveRefCntPtr Diags(
+new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
+
+std::unique_ptr LoadedUnit(ASTUnit::LoadFromASTFile(
+ASTFileName, CI.getPCHContainerOperations()->getRawReader(),
+ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts()));
+Unit = LoadedUnit.get();
+FileASTUnitMap[ASTFileName] = std::move(LoadedUnit);
+++NumASTLoaded;
+if (DisplayCTUProgress) {
+  llvm::errs() << "CTU loaded AST file: " << ASTFileName << "\n";
 }
-NameASTUnitMap[LookupName] = Unit;
   } else {
-Unit = NameUnitCacheEntry->second;
+Unit = ASTCacheEntry->second.get();
   }
+  NameASTUnitMap[LookupName] = Unit;
+
   if (!Unit)
 return llvm::make_error(
 index_error_code::failed_to_get_external_ast);
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -165,6 +165,7 @@
 private:
   bool checkThresholdReached() const;
   llvm::Error lazyInitCTUIndex(StringRef CrossTUDir, StringRef IndexName);
+  ASTUnit *getCachedASTUnitForName(StringRef LookupName) const;
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
   ASTImporter &getOrCreateASTImporter(ASTContext &From);
   template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
htt

[PATCH] D64748: Refactor threshold checking

2019-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 209881.
gamesh411 added a comment.

Incremental change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64748/new/

https://reviews.llvm.org/D64748

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -380,6 +380,21 @@
 return nullptr;
 }
 
+std::unique_ptr
+CrossTranslationUnitContext::loadFromASTFile(StringRef ASTFileName) const {
+  // Load AST from ast-dump.
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  TextDiagnosticPrinter *DiagClient =
+  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  IntrusiveRefCntPtr Diags(
+  new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
+
+  return ASTUnit::LoadFromASTFile(
+  ASTFileName, CI.getPCHContainerOperations()->getRawReader(),
+  ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts());
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -411,16 +426,8 @@
   StringRef ASTFileName = It->second;
   auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName);
   if (ASTCacheEntry == FileASTUnitMap.end()) {
-IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
-TextDiagnosticPrinter *DiagClient =
-new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
-IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
-IntrusiveRefCntPtr Diags(
-new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
-
-std::unique_ptr LoadedUnit(ASTUnit::LoadFromASTFile(
-ASTFileName, CI.getPCHContainerOperations()->getRawReader(),
-ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts()));
+// Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
+std::unique_ptr LoadedUnit = loadFromASTFile(ASTFileName);
 Unit = LoadedUnit.get();
 FileASTUnitMap[ASTFileName] = std::move(LoadedUnit);
 ++NumASTLoaded;
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -166,6 +166,7 @@
   bool checkThresholdReached() const;
   llvm::Error lazyInitCTUIndex(StringRef CrossTUDir, StringRef IndexName);
   ASTUnit *getCachedASTUnitForName(StringRef LookupName) const;
+  std::unique_ptr loadFromASTFile(StringRef ASTFileName) const;
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
   ASTImporter &getOrCreateASTImporter(ASTContext &From);
   template 


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -380,6 +380,21 @@
 return nullptr;
 }
 
+std::unique_ptr
+CrossTranslationUnitContext::loadFromASTFile(StringRef ASTFileName) const {
+  // Load AST from ast-dump.
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  TextDiagnosticPrinter *DiagClient =
+  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  IntrusiveRefCntPtr Diags(
+  new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
+
+  return ASTUnit::LoadFromASTFile(
+  ASTFileName, CI.getPCHContainerOperations()->getRawReader(),
+  ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts());
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -411,16 +426,8 @@
   StringRef ASTFileName = It->second;
   auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName);
   if (ASTCacheEntry == FileASTUnitMap.end()) {
-IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
-TextDiagnosticPrinter *DiagClient =
-new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
-IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
-IntrusiveRefCntPtr Diags(
-new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
-
-std::unique_ptr LoadedUnit(ASTUnit::LoadFromASTFile(
-ASTFileName, CI.getPCHContainerOperations()->getRawReader(),
-ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts()));
+// Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
+std::unique_ptr LoadedUnit = loadFromASTFile(ASTFileName);
 Unit = LoadedUnit.get();
 FileASTUnitMap[ASTFileName] = std::move(LoadedUnit);
 ++NumASTLoaded;
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h

[PATCH] D64748: Refactor threshold checking

2019-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 209879.
gamesh411 added a comment.

Incremental change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64748/new/

https://reviews.llvm.org/D64748

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -348,6 +348,29 @@
   return false;
 }
 
+llvm::Error CrossTranslationUnitContext::lazyInitCTUIndex(StringRef CrossTUDir,
+  StringRef IndexName) 
{
+  // Dont initialize if the map is filled.
+  if (!NameFileMap.empty())
+return llvm::Error::success();
+
+  // Get the absolute path to the index file.
+  SmallString<256> IndexFile = CrossTUDir;
+  if (llvm::sys::path::is_absolute(IndexName))
+IndexFile = IndexName;
+  else
+llvm::sys::path::append(IndexFile, IndexName);
+
+  if (auto IndexMapping = parseCrossTUIndex(IndexFile, CrossTUDir)) {
+// Initialize member map.
+NameFileMap = *IndexMapping;
+return llvm::Error::success();
+  } else {
+// Error while parsing CrossTU index file.
+return IndexMapping.takeError();
+  };
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -364,19 +387,9 @@
   ASTUnit *Unit = nullptr;
   auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);
   if (NameUnitCacheEntry == NameASTUnitMap.end()) {
-if (NameFileMap.empty()) {
-  SmallString<256> IndexFile = CrossTUDir;
-  if (llvm::sys::path::is_absolute(IndexName))
-IndexFile = IndexName;
-  else
-llvm::sys::path::append(IndexFile, IndexName);
-  llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFile, CrossTUDir);
-  if (IndexOrErr)
-NameFileMap = *IndexOrErr;
-  else
-return IndexOrErr.takeError();
-}
+// Lazily initialize the mapping from function names to AST files.
+if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName))
+  return std::move(InitFailed);
 
 auto It = NameFileMap.find(LookupName);
 if (It == NameFileMap.end()) {
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -164,6 +164,7 @@
 
 private:
   bool checkThresholdReached() const;
+  llvm::Error lazyInitCTUIndex(StringRef CrossTUDir, StringRef IndexName);
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
   ASTImporter &getOrCreateASTImporter(ASTContext &From);
   template 


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -348,6 +348,29 @@
   return false;
 }
 
+llvm::Error CrossTranslationUnitContext::lazyInitCTUIndex(StringRef CrossTUDir,
+  StringRef IndexName) {
+  // Dont initialize if the map is filled.
+  if (!NameFileMap.empty())
+return llvm::Error::success();
+
+  // Get the absolute path to the index file.
+  SmallString<256> IndexFile = CrossTUDir;
+  if (llvm::sys::path::is_absolute(IndexName))
+IndexFile = IndexName;
+  else
+llvm::sys::path::append(IndexFile, IndexName);
+
+  if (auto IndexMapping = parseCrossTUIndex(IndexFile, CrossTUDir)) {
+// Initialize member map.
+NameFileMap = *IndexMapping;
+return llvm::Error::success();
+  } else {
+// Error while parsing CrossTU index file.
+return IndexMapping.takeError();
+  };
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -364,19 +387,9 @@
   ASTUnit *Unit = nullptr;
   auto NameUnitCacheEntry = NameASTUnitMap.find(LookupName);
   if (NameUnitCacheEntry == NameASTUnitMap.end()) {
-if (NameFileMap.empty()) {
-  SmallString<256> IndexFile = CrossTUDir;
-  if (llvm::sys::path::is_absolute(IndexName))
-IndexFile = IndexName;
-  else
-llvm::sys::path::append(IndexFile, IndexName);
-  llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFile, CrossTUDir);
-  if (IndexOrErr)
-NameFileMap = *IndexOrErr;
-  else
-return IndexOrErr.takeError();
-}
+// Lazily initialize the mapping from function names to AST files.
+if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName))
+  return std::move(InitFailed);
 
 auto It = NameFileMap.find(LookupName);
 if (It == NameFileMap.en

[PATCH] D64748: Refactor threshold checking

2019-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 209883.
gamesh411 added a comment.

Incremental change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64748/new/

https://reviews.llvm.org/D64748

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp

Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -18,8 +18,8 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Index/USRGeneration.h"
-#include "llvm/ADT/Triple.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
@@ -65,8 +65,7 @@
   Rhs.getVendor() != Triple::UnknownVendor &&
   Lhs.getVendor() != Rhs.getVendor())
 return false;
-  if (!Lhs.isOSUnknown() && !Rhs.isOSUnknown() &&
-  Lhs.getOS() != Rhs.getOS())
+  if (!Lhs.isOSUnknown() && !Rhs.isOSUnknown() && Lhs.getOS() != Rhs.getOS())
 return false;
   if (Lhs.getEnvironment() != Triple::UnknownEnvironment &&
   Rhs.getEnvironment() != Triple::UnknownEnvironment &&
@@ -237,8 +236,8 @@
   if (LookupName.empty())
 return llvm::make_error(
 index_error_code::failed_to_generate_usr);
-  llvm::Expected ASTUnitOrError = loadExternalAST(
-  LookupName, CrossTUDir, IndexName, DisplayCTUProgress);
+  llvm::Expected ASTUnitOrError =
+  loadExternalAST(LookupName, CrossTUDir, IndexName, DisplayCTUProgress);
   if (!ASTUnitOrError)
 return ASTUnitOrError.takeError();
   ASTUnit *Unit = *ASTUnitOrError;
@@ -407,6 +406,25 @@
   }
 }
 
+ASTUnit *
+CrossTranslationUnitContext::loadFromASTFileCached(StringRef LookupName,
+   StringRef ASTFileName) {
+  ASTUnit *Unit = nullptr;
+
+  auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName);
+  if (ASTCacheEntry == FileASTUnitMap.end()) {
+// Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
+std::unique_ptr LoadedUnit = loadFromASTFile(ASTFileName);
+Unit = LoadedUnit.get();
+FileASTUnitMap[ASTFileName] = std::move(LoadedUnit);
+  } else {
+Unit = ASTCacheEntry->second.get();
+  }
+  NameASTUnitMap[LookupName] = Unit;
+
+  return Unit;
+}
+
 llvm::Expected CrossTranslationUnitContext::loadExternalAST(
 StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
 bool DisplayCTUProgress) {
@@ -434,25 +452,19 @@
   if (!ASTFileName)
 return ASTFileName.takeError();
 
-  auto ASTCacheEntry = FileASTUnitMap.find(*ASTFileName);
-  if (ASTCacheEntry == FileASTUnitMap.end()) {
-// Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
-  std::unique_ptr LoadedUnit = loadFromASTFile(*ASTFileName);
-Unit = LoadedUnit.get();
-FileASTUnitMap[*ASTFileName] = std::move(LoadedUnit);
+  // Try to load from ASTFile but use cache for both file and function names.
+  Unit = loadFromASTFileCached(LookupName, *ASTFileName);
+
+  if (Unit) {
 ++NumASTLoaded;
 if (DisplayCTUProgress) {
   llvm::errs() << "CTU loaded AST file: " << *ASTFileName << "\n";
 }
+return Unit;
   } else {
-Unit = ASTCacheEntry->second.get();
-  }
-  NameASTUnitMap[LookupName] = Unit;
-
-  if (!Unit)
 return llvm::make_error(
 index_error_code::failed_to_get_external_ast);
-  return Unit;
+  }
 }
 
 template 
@@ -463,20 +475,19 @@
   ASTImporter &Importer = getOrCreateASTImporter(D->getASTContext());
   auto ToDeclOrError = Importer.Import(D);
   if (!ToDeclOrError) {
-handleAllErrors(ToDeclOrError.takeError(),
-[&](const ImportError &IE) {
-  switch (IE.Error) {
-  case ImportError::NameConflict:
-++NumNameConflicts;
- break;
-  case ImportError::UnsupportedConstruct:
-++NumUnsupportedNodeFound;
-break;
-  case ImportError::Unknown:
-llvm_unreachable("Unknown import error happened.");
-break;
-  }
-});
+handleAllErrors(ToDeclOrError.takeError(), [&](const ImportError &IE) {
+  switch (IE.Error) {
+  case ImportError::NameConflict:
+++NumNameConflicts;
+break;
+  case ImportError::UnsupportedConstruct:
+++NumUnsupportedNodeFound;
+break;
+  case ImportError::Unknown:
+llvm_unreachable("Unknown import error happened.");
+break;
+  }
+});
 return llvm::make_error(index_error_code::failed_import);
   }
   auto *ToDecl = cast(*ToDeclOrError);
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===

  1   2   3   >