[clang] ca46754 - [CMake] Pass CLANG_VENDOR variables into later stages

2020-05-29 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2020-05-29T09:13:08+02:00
New Revision: ca467542eecfc621eea7fefb3c7e3849c6b43ac7

URL: 
https://github.com/llvm/llvm-project/commit/ca467542eecfc621eea7fefb3c7e3849c6b43ac7
DIFF: 
https://github.com/llvm/llvm-project/commit/ca467542eecfc621eea7fefb3c7e3849c6b43ac7.diff

LOG: [CMake] Pass CLANG_VENDOR variables into later stages

We are already passing CLANG_VERSION_* & PACKAGE_VENDOR

Added: 


Modified: 
clang/CMakeLists.txt

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 7dadc5f6e917..5a5e34aacbeb 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -711,6 +711,7 @@ if (CLANG_ENABLE_BOOTSTRAP)
 CLANG_VERSION_MAJOR
 CLANG_VERSION_MINOR
 CLANG_VERSION_PATCHLEVEL
+CLANG_VENDOR
 LLVM_VERSION_SUFFIX
 LLVM_BINUTILS_INCDIR
 CLANG_REPOSITORY_STRING



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


[libclc] a341863 - libclc: update website url

2020-05-29 Thread Sylvestre Ledru via cfe-commits

Author: davidak
Date: 2020-05-29T09:18:37+02:00
New Revision: a3418631e8aa0941b8b57ec2fc3b8d0c7db493be

URL: 
https://github.com/llvm/llvm-project/commit/a3418631e8aa0941b8b57ec2fc3b8d0c7db493be
DIFF: 
https://github.com/llvm/llvm-project/commit/a3418631e8aa0941b8b57ec2fc3b8d0c7db493be.diff

LOG: libclc: update website url

old link is dead

Added: 


Modified: 
libclc/README.TXT

Removed: 




diff  --git a/libclc/README.TXT b/libclc/README.TXT
index 00ae6bfa40a1..57b5242b9bbe 100644
--- a/libclc/README.TXT
+++ b/libclc/README.TXT
@@ -49,4 +49,4 @@ $ DESTDIR=/path/for/staged/install ninja install
 Website
 ---
 
-http://www.pcc.me.uk/~peter/libclc/
+https://libclc.llvm.org/



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


[PATCH] D80712: [SVE] Add checks for no warnings in SVE tests

2020-05-29 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

Hi @efriedma, at least amongst all the tests in llvm/test/CodeGen/AArch64/sve-* 
there are still 66 with warnings. @sdesmalen and I discussed this and our 
reason for adding checks for warnings is mainly to do with the fact we are 
still fixing up cases and implementing SVE codgen support, so there is a chance 
that somewhere we'll introduce a regression without realising it. That's the 
main rationale for this, but I do realise that ultimately 
getVectorNumElements() will be deprecated. I also realised that the warnings 
I've added to the clang tests aren't that useful unless we're compiling them to 
real assembly so I may add some new RUN lines for those.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80712



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


[clang] 82bb57c - [AST][RecoveryExpr] Make DeduceAutoType fail if the auto is deduced from recovery exprs.

2020-05-29 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-05-29T09:54:28+02:00
New Revision: 82bb57c11d8ccb4e1b0f420f4388dd6553bbc57a

URL: 
https://github.com/llvm/llvm-project/commit/82bb57c11d8ccb4e1b0f420f4388dd6553bbc57a
DIFF: 
https://github.com/llvm/llvm-project/commit/82bb57c11d8ccb4e1b0f420f4388dd6553bbc57a.diff

LOG: [AST][RecoveryExpr] Make DeduceAutoType fail if the auto is deduced from 
recovery exprs.

Summary:
With recovery-ast, we will get an undeduced `auto` return type for
"auto foo()->undef()" function declaration, the function decl still keeps
valid, it is dangerous, and breaks assumptions in clang, and leads crashes.

This patch invalidates these functions, if we deduce autos from the
return rexpression, which is similar to auto VarDecl.

Subscribers: cfe-commits

Tags: #clang

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

Added: 
clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp

Modified: 
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/Sema/invalid-bitwidth-expr.mm

Removed: 




diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 0cb600fb46d1..dda0d3486e0e 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3309,6 +3309,7 @@ Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, 
Expr *RetValExp) {
 assert(AT && "lost auto type from lambda return type");
 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
   FD->setInvalidDecl();
+  // FIXME: preserve the ill-formed return expression.
   return StmtError();
 }
 CurCap->ReturnType = FnRetType = FD->getReturnType();

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 19f8248db6bf..877020ed4dcf 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4655,6 +4655,8 @@ Sema::DeduceAutoResult
 Sema::DeduceAutoType(TypeLoc Type, Expr *&Init, QualType &Result,
  Optional DependentDeductionDepth,
  bool IgnoreConstraints) {
+  if (Init->containsErrors())
+return DAR_FailedAlreadyDiagnosed;
   if (Init->getType()->isNonOverloadPlaceholderType()) {
 ExprResult NonPlaceholder = CheckPlaceholderExpr(Init);
 if (NonPlaceholder.isInvalid())

diff  --git a/clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp 
b/clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp
new file mode 100644
index ..b77d5335c661
--- /dev/null
+++ b/clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp
@@ -0,0 +1,28 @@
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-fcxx-exceptions -frecovery-ast -std=gnu++17 -ast-dump %s | FileCheck 
-strict-whitespace %s
+
+// CHECK: FunctionDecl {{.*}} s1 'auto ()'
+auto s1(); // valid
+// FIXME: why we're finding int as the return type. int is used as a fallback 
type?
+// CHECK: FunctionDecl {{.*}} invalid s2 'auto () -> int'
+auto s2() -> undef();
+// CHECK: FunctionDecl {{.*}} invalid s3 'auto () -> int'
+auto s3() -> decltype(undef());
+// CHECK: FunctionDecl {{.*}} invalid s4 'auto ()'
+auto s4() {
+  return undef();
+}
+// CHECK: FunctionDecl {{.*}} s5 'void ()'
+auto s5() {} // valid, no return stmt, fallback to void
+
+class Foo {
+  // CHECK: CXXMethodDecl {{.*}} foo1 'auto ()'
+  auto foo1(); // valid
+  // CHECK: CXXMethodDecl {{.*}} invalid foo2 'auto () -> int'
+  auto foo2() -> undef();
+  // CHECK: CXXMethodDecl {{.*}} invalid foo3 'auto () -> int'
+  auto foo3() -> decltype(undef());
+  // CHECK: CXXMethodDecl {{.*}} invalid foo4 'auto ()'
+  auto foo4() { return undef(); }
+  // CHECK: CXXMethodDecl {{.*}} foo5 'void ()'
+  auto foo5() {} // valid, no return stmt, fallback to void.
+};

diff  --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index b63483fba416..9b13f4d3e06b 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -178,10 +178,6 @@ void InitializerForAuto() {
   auto unresolved_typo = gned.*[] {};
 }
 
-// CHECK:  `-TypeAliasDecl {{.*}} Escape 'decltype([] {
-// CHECK-NEXT:   return (undef);
-// CHECK-NEXT: }())'
-// CHECK-NEXT:   `-DecltypeType {{.*}} 'decltype([] {
-// CHECK-NEXT: return (undef);
-// CHECK-NEXT:   }())' dependent
+// Verified that the generated call operator is invalid.
+// CHECK: |-CXXMethodDecl {{.*}} invalid operator() 'auto () const -> auto'
 using Escape = decltype([] { return undef(); }());

diff  --git a/clang/test/Sema/invalid-bitwidth-expr.mm 
b/clang/test/Sema/invalid-bitwidth-expr.mm
index fe93cac683ae..63aced1a3bf4 100644
--- a/clang/test/Sema/invalid-bitwidth-expr.mm
+++ b/clang/test/Sema/invalid-bitwidth-expr.mm
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fobjc-runtime=gcc -frecovery-ast -verify %s
-// RUN: %clang_cc1 -fobjc-runtime=gcc -fno-recover

[PATCH] D80279: [libclang] Extend clang_Cursor_Evaluate().

2020-05-29 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added a comment.

@jkorous: Please submit. I can't as my svn account is still not ported to 
github... :/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80279



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


[PATCH] D80221: [AST][RecoveryExpr] Make DeduceAutoType fail if the auto is deduced from recovery exprs.

2020-05-29 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG82bb57c11d8c: [AST][RecoveryExpr] Make DeduceAutoType fail 
if the auto is deduced from… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80221

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/Sema/invalid-bitwidth-expr.mm


Index: clang/test/Sema/invalid-bitwidth-expr.mm
===
--- clang/test/Sema/invalid-bitwidth-expr.mm
+++ clang/test/Sema/invalid-bitwidth-expr.mm
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fobjc-runtime=gcc -frecovery-ast -verify %s
-// RUN: %clang_cc1 -fobjc-runtime=gcc -fno-recovery-ast -verify %s
 
 @interface Ivar
 {
@@ -11,3 +10,11 @@
 
 constexpr int s = sizeof(Ivar);
 constexpr int ss = sizeof(X);
+
+auto func() {
+  return undef(); // expected-error {{use of undeclared identifier}}
+}
+struct Y {
+  int X : func();
+};
+constexpr int sss = sizeof(Y);
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -178,10 +178,6 @@
   auto unresolved_typo = gned.*[] {};
 }
 
-// CHECK:  `-TypeAliasDecl {{.*}} Escape 'decltype([] {
-// CHECK-NEXT:   return (undef);
-// CHECK-NEXT: }())'
-// CHECK-NEXT:   `-DecltypeType {{.*}} 'decltype([] {
-// CHECK-NEXT: return (undef);
-// CHECK-NEXT:   }())' dependent
+// Verified that the generated call operator is invalid.
+// CHECK: |-CXXMethodDecl {{.*}} invalid operator() 'auto () const -> auto'
 using Escape = decltype([] { return undef(); }());
Index: clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp
@@ -0,0 +1,28 @@
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-fcxx-exceptions -frecovery-ast -std=gnu++17 -ast-dump %s | FileCheck 
-strict-whitespace %s
+
+// CHECK: FunctionDecl {{.*}} s1 'auto ()'
+auto s1(); // valid
+// FIXME: why we're finding int as the return type. int is used as a fallback 
type?
+// CHECK: FunctionDecl {{.*}} invalid s2 'auto () -> int'
+auto s2() -> undef();
+// CHECK: FunctionDecl {{.*}} invalid s3 'auto () -> int'
+auto s3() -> decltype(undef());
+// CHECK: FunctionDecl {{.*}} invalid s4 'auto ()'
+auto s4() {
+  return undef();
+}
+// CHECK: FunctionDecl {{.*}} s5 'void ()'
+auto s5() {} // valid, no return stmt, fallback to void
+
+class Foo {
+  // CHECK: CXXMethodDecl {{.*}} foo1 'auto ()'
+  auto foo1(); // valid
+  // CHECK: CXXMethodDecl {{.*}} invalid foo2 'auto () -> int'
+  auto foo2() -> undef();
+  // CHECK: CXXMethodDecl {{.*}} invalid foo3 'auto () -> int'
+  auto foo3() -> decltype(undef());
+  // CHECK: CXXMethodDecl {{.*}} invalid foo4 'auto ()'
+  auto foo4() { return undef(); }
+  // CHECK: CXXMethodDecl {{.*}} foo5 'void ()'
+  auto foo5() {} // valid, no return stmt, fallback to void.
+};
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4655,6 +4655,8 @@
 Sema::DeduceAutoType(TypeLoc Type, Expr *&Init, QualType &Result,
  Optional DependentDeductionDepth,
  bool IgnoreConstraints) {
+  if (Init->containsErrors())
+return DAR_FailedAlreadyDiagnosed;
   if (Init->getType()->isNonOverloadPlaceholderType()) {
 ExprResult NonPlaceholder = CheckPlaceholderExpr(Init);
 if (NonPlaceholder.isInvalid())
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3309,6 +3309,7 @@
 assert(AT && "lost auto type from lambda return type");
 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
   FD->setInvalidDecl();
+  // FIXME: preserve the ill-formed return expression.
   return StmtError();
 }
 CurCap->ReturnType = FnRetType = FD->getReturnType();


Index: clang/test/Sema/invalid-bitwidth-expr.mm
===
--- clang/test/Sema/invalid-bitwidth-expr.mm
+++ clang/test/Sema/invalid-bitwidth-expr.mm
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fobjc-runtime=gcc -frecovery-ast -verify %s
-// RUN: %clang_cc1 -fobjc-runtime=gcc -fno-recovery-ast -verify %s
 
 @interface Ivar
 {
@@ -11,3 +10,11 @@
 
 constexpr int s = sizeof(Ivar);
 constexpr int ss = sizeof(X);
+
+auto func() {
+  return undef(); // expected-error {{use of undeclared identifier}}
+}
+struct Y {
+  int X : func();
+};
+constexpr int sss 

[PATCH] D80369: [DebugInfo][CallSites] Remove decl subprograms from 'retainedTypes:'

2020-05-29 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro marked an inline comment as done.
djtodoro added inline comments.



Comment at: clang/test/Modules/ModuleDebugInfo.m:46-47
 
-// The forward declaration should not be in the module scope.
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "OpaqueData", file
-

dblaikie wrote:
> Did this type go missing with this change? (ie: was this type /only/ 
> accessible via a subprogram in the retained types list?)
Yes, it was **only** accessible via that subprogram we removed.


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

https://reviews.llvm.org/D80369



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


[PATCH] D80221: [AST][RecoveryExpr] Make DeduceAutoType fail if the auto is deduced from recovery exprs.

2020-05-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 267137.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80221

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/Sema/invalid-bitwidth-expr.mm


Index: clang/test/Sema/invalid-bitwidth-expr.mm
===
--- clang/test/Sema/invalid-bitwidth-expr.mm
+++ clang/test/Sema/invalid-bitwidth-expr.mm
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fobjc-runtime=gcc -frecovery-ast -verify %s
-// RUN: %clang_cc1 -fobjc-runtime=gcc -fno-recovery-ast -verify %s
 
 @interface Ivar
 {
@@ -11,3 +10,11 @@
 
 constexpr int s = sizeof(Ivar);
 constexpr int ss = sizeof(X);
+
+auto func() {
+  return undef(); // expected-error {{use of undeclared identifier}}
+}
+struct Y {
+  int X : func();
+};
+constexpr int sss = sizeof(Y);
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -178,10 +178,6 @@
   auto unresolved_typo = gned.*[] {};
 }
 
-// CHECK:  `-TypeAliasDecl {{.*}} Escape 'decltype([] {
-// CHECK-NEXT:   return (undef);
-// CHECK-NEXT: }())'
-// CHECK-NEXT:   `-DecltypeType {{.*}} 'decltype([] {
-// CHECK-NEXT: return (undef);
-// CHECK-NEXT:   }())' dependent
+// Verified that the generated call operator is invalid.
+// CHECK: |-CXXMethodDecl {{.*}} invalid operator() 'auto () const -> auto'
 using Escape = decltype([] { return undef(); }());
Index: clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-invalid-auto-return-funcs.cpp
@@ -0,0 +1,28 @@
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-fcxx-exceptions -frecovery-ast -std=gnu++17 -ast-dump %s | FileCheck 
-strict-whitespace %s
+
+// CHECK: FunctionDecl {{.*}} s1 'auto ()'
+auto s1(); // valid
+// FIXME: why we're finding int as the return type. int is used as a fallback 
type?
+// CHECK: FunctionDecl {{.*}} invalid s2 'auto () -> int'
+auto s2() -> undef();
+// CHECK: FunctionDecl {{.*}} invalid s3 'auto () -> int'
+auto s3() -> decltype(undef());
+// CHECK: FunctionDecl {{.*}} invalid s4 'auto ()'
+auto s4() {
+  return undef();
+}
+// CHECK: FunctionDecl {{.*}} s5 'void ()'
+auto s5() {} // valid, no return stmt, fallback to void
+
+class Foo {
+  // CHECK: CXXMethodDecl {{.*}} foo1 'auto ()'
+  auto foo1(); // valid
+  // CHECK: CXXMethodDecl {{.*}} invalid foo2 'auto () -> int'
+  auto foo2() -> undef();
+  // CHECK: CXXMethodDecl {{.*}} invalid foo3 'auto () -> int'
+  auto foo3() -> decltype(undef());
+  // CHECK: CXXMethodDecl {{.*}} invalid foo4 'auto ()'
+  auto foo4() { return undef(); }
+  // CHECK: CXXMethodDecl {{.*}} foo5 'void ()'
+  auto foo5() {} // valid, no return stmt, fallback to void.
+};
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4655,6 +4655,8 @@
 Sema::DeduceAutoType(TypeLoc Type, Expr *&Init, QualType &Result,
  Optional DependentDeductionDepth,
  bool IgnoreConstraints) {
+  if (Init->containsErrors())
+return DAR_FailedAlreadyDiagnosed;
   if (Init->getType()->isNonOverloadPlaceholderType()) {
 ExprResult NonPlaceholder = CheckPlaceholderExpr(Init);
 if (NonPlaceholder.isInvalid())
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3309,6 +3309,7 @@
 assert(AT && "lost auto type from lambda return type");
 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
   FD->setInvalidDecl();
+  // FIXME: preserve the ill-formed return expression.
   return StmtError();
 }
 CurCap->ReturnType = FnRetType = FD->getReturnType();


Index: clang/test/Sema/invalid-bitwidth-expr.mm
===
--- clang/test/Sema/invalid-bitwidth-expr.mm
+++ clang/test/Sema/invalid-bitwidth-expr.mm
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fobjc-runtime=gcc -frecovery-ast -verify %s
-// RUN: %clang_cc1 -fobjc-runtime=gcc -fno-recovery-ast -verify %s
 
 @interface Ivar
 {
@@ -11,3 +10,11 @@
 
 constexpr int s = sizeof(Ivar);
 constexpr int ss = sizeof(X);
+
+auto func() {
+  return undef(); // expected-error {{use of undeclared identifier}}
+}
+struct Y {
+  int X : func();
+};
+constexpr int sss = sizeof(Y);
Index: clang/test/AST/ast-dump-recovery.cpp
=

[PATCH] D79710: [clang][BFloat] add create/set/get/dup intrinsics

2020-05-29 Thread Dave Green via Phabricator via cfe-commits
dmgreen added inline comments.



Comment at: clang/include/clang/Basic/arm_neon.td:1860
+
+  def VGET_HIGH_BF : NoTestOpInst<"vget_high", ".Q", "b", OP_HI>;
+  def VGET_LOW_BF  : NoTestOpInst<"vget_low", ".Q", "b", OP_LO>;

Do you know what InstName = "vmov" does, and is it needed here?

I'm pretty sure it's a vestige of an earlier implementation of the neon emitter.



Comment at: clang/include/clang/Basic/arm_neon.td:1867
+  def SCALAR_VDUP_LANE_BF : IInst<"vdup_lane", "1.I", "Sb">;
+  def SCALAR_VDUP_LANEQ_BF : IInst<"vdup_laneq", "1QI", "Sb">;
+}

Does this need let isLaneQ = 1, like the other vdup_laneq's?



Comment at: clang/include/clang/Basic/arm_neon_incl.td:293
+
+  string CartesianProductWith = "";
 }

Is this needed in this patch?



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:6309
+  case NEON::BI__builtin_neon_vget_lane_bf16:
+  case NEON::BI__builtin_neon_vduph_lane_bf16:
   case NEON::BI__builtin_neon_vgetq_lane_i8:

How come these are needed for vduph_lane_bf16 if they were not needed for 
vduph_lane_f16?



Comment at: clang/test/CodeGen/aarch64-bf16-getset-intrinsics.c:2
+// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -target-feature +neon 
-target-feature +bf16 \
+// RUN:  -O2 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK64
+// RUN: %clang_cc1 -triple armv8.6a-arm-none-eabi -target-feature +neon 
-target-feature +bf16 -mfloat-abi hard \

It's best to have auto generated tests if we can, and ideally not rely on 
running the entire -O2 pipeline. I think a lot of the other tests use clang ... 
-disable-O0-optnone | opt -S -mem2reg | Filecheck ...

Also this aarch64 tests is running arm codegen too? Not sure if that matters, 
but I don't immediately see it being done elsewhere.



Comment at: clang/test/CodeGen/aarch64-bf16-getset-intrinsics.c:19-20
+// CHECK-LABEL: test_vdup_n_bf16
+// CHECK64: %vecinit.i = insertelement <4 x bfloat> undef, bfloat %v, i32 0
+// CHECK32: %vecinit.i = insertelement <4 x bfloat> undef, bfloat %v, i32 0
+// CHECK: %vecinit{{.*}} = shufflevector <4 x bfloat> %vecinit.i, <4 x bfloat> 
undef, <4 x i32> zeroinitializer

A lot of these 32 and 64 bit lines look the same.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79710



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


[PATCH] D69764: [clang-format] Add East/West Const fixer capability

2020-05-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Random thoughts from the peanut gallery:

- `clang-format` *is* the place I'd expect/want this feature, as a user. It's 
way more similar to `int *x` -> `int* x` than it is to e.g. typical clang-tidy 
rewrites. My only concern is whether we can give it the safety users expect.
- `clang-tidy` has a much higher barrier to entry: slow runtime, complex 
configuration, build-system integration, more false-positives in common 
scenarios.  e.g. Google has a pretty sophisticated CI system that integrates 
both: clang-format is typically blocking and clang-tidy is typically not. It 
would be less useful in clang-tidy.
- AIUI there are two identified sources of unsafety. They're real costs for 
sure, we should mitigate them as much as possible.
  - bugs: it seems reasonably likely these can be identified and fixed, based 
on what we've seen in this patch. I'd be more worried about maintenance if this 
was a drive-by contribution, but it's the opposite of that.
  - macros: there is some precedent for clang-format being bad or even unsafe 
in the presence of unknown macros. We could include a list of "don't touch 
qualifiers around" macro names in config. @klimek has a general-purpose 
mechanism nearly ready where you can provide actual macro definitions in 
config. It's also unclear if there's a common pattern where we'd see this.
  - typedefs don't introduce any such issues, right?
- one general mitigation is not including this in any default styles. We could 
go further and not support setting it in a style file (only as a flag) for 
clang-format 11, to shake out bugs.
- I think `const` is by far the most important qualifier to handle: volatile is 
rare, others cause less semantic confusion and are generally less 
controversial. IMO it's fine for this patch to only handle const as long as we 
know how the configuration could be expanded in future. Shipping is a feature.
- To bikeshed the configuration once more: what about `QualifierOrder: [Const, 
Type]`? This seems fairly self-explanatory, sidesteps "left" vs "west", and 
expands naturally to `[Static, Const, Type]` in future. It requires some 
nontrivial validation though.


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

https://reviews.llvm.org/D69764



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


[PATCH] D77148: [analyzer] ApiModeling: Add buffer size arg constraint with multiplier involved

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 267141.
martong marked an inline comment as done.
martong added a comment.

- Rebase to D77066 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77148

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -149,3 +149,27 @@
   // bugpath-note{{TRUE}} \
   // bugpath-note{{'s' is <= 2}}
 }
+int __buf_size_arg_constraint_mul(const void *, size_t, size_t);
+void test_buf_size_concrete_with_multiplication() {
+  short buf[3]; // bugpath-note{{'buf' initialized here}}
+  __buf_size_arg_constraint_mul(buf, 4, sizeof(short)); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+}
+void test_buf_size_symbolic_with_multiplication(size_t s) {
+  short buf[3];
+  __buf_size_arg_constraint_mul(buf, s, sizeof(short));
+  clang_analyzer_eval(s * sizeof(short) <= 6); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}}
+}
+void test_buf_size_symbolic_and_offset_with_multiplication(size_t s) {
+  short buf[3];
+  __buf_size_arg_constraint_mul(buf + 1, s, sizeof(short));
+  clang_analyzer_eval(s * sizeof(short) <= 4); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -215,9 +215,16 @@
   // Represents a buffer argument with an additional size argument.
   // E.g. the first two arguments here:
   //   ctime_s(char *buffer, rsize_t bufsz, const time_t *time);
+  // Another example:
+  //   size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
+  //   // Here, ptr is the buffer, and its minimum size is `size * nmemb`.
   class BufferSizeConstraint : public ValueConstraint {
 // The argument which holds the size of the buffer.
 ArgNo SizeArgN;
+// The argument which is a multiplier to size. This is set in case of
+// `fread` like functions where the size is computed as a multiplication of
+// two arguments.
+llvm::Optional SizeMultiplierArgN;
 // The operator we use in apply. This is negated in negate().
 BinaryOperator::Opcode Op = BO_LE;
 
@@ -225,18 +232,28 @@
 BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize)
 : ValueConstraint(Buffer), SizeArgN(BufSize) {}
 
+BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize, ArgNo BufSizeMultiplier)
+: ValueConstraint(Buffer), SizeArgN(BufSize),
+  SizeMultiplierArgN(BufSizeMultiplier) {}
+
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
   const Summary &Summary,
   CheckerContext &C) const override {
+  SValBuilder &SvalBuilder = C.getSValBuilder();
   // The buffer argument.
   SVal BufV = getArgSVal(Call, getArgNo());
   // The size argument.
   SVal SizeV = getArgSVal(Call, SizeArgN);
+  // Multiply with another argument if given.
+  if (SizeMultiplierArgN) {
+SVal SizeMulV = getArgSVal(Call, *SizeMultiplierArgN);
+SizeV = SvalBuilder.evalBinOp(State, BO_Mul, SizeV, SizeMulV,
+  Summary.getArgType(SizeArgN));
+  }
   // The dynamic size of the buffer argument, got from the analyzer engine.
   SVal BufDynSize =
   getDynamicSizeWithOffset(State, BufV, C.getSValBuilder());
 
-  SValBuilder &SvalBuilder = C.getSValBuilder();
   SVal Feasible = SvalBuilder.evalBinOp(State, Op, SizeV, BufDynSize,
 SvalBuilder.getContext().BoolTy);
   if (auto F = Feasible.getAs())
@@ -745,8 +762,8 @@
   IntRangeVector Ranges) {
 return std::make_shared(ArgN, Kind, Ranges);
   };
-  auto BufferSize = [](ArgNo BufArgN, ArgNo SizeArgN) {
-return std::make_shared(BufArgN, SizeArgN);
+  auto BufferSize = [](auto... Args) {
+return std::make_shared(Args...);
   };
   struct {
 auto operator()(RangeKind Kind, IntRangeVector Ranges) {
@@ -989,6 +1006,12 @@
 EvalCallAsPure)
 .ArgConstraint(
 BufferSize(/*Buffer=*/ArgNo(0), /*BufSize=*/ArgNo(1;
+addToFunctionSummaryMap(
+"__buf

[PATCH] D75665: [analyzer] On-demand parsing capability for CTU

2020-05-29 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 267143.
gamesh411 marked 6 inline comments as done.
gamesh411 added a comment.

Fix documentation and commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75665

Files:
  clang/docs/analyzer/user-docs/CrossTranslationUnit.rst
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Analysis/Inputs/ctu-other.c
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/ctu-different-triples.cpp
  clang/test/Analysis/ctu-main.c
  clang/test/Analysis/ctu-main.cpp
  clang/test/Analysis/ctu-on-demand-parsing.c
  clang/test/Analysis/ctu-on-demand-parsing.cpp
  clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
  clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -7,10 +7,11 @@
 //===--===//
 
 #include "clang/CrossTU/CrossTranslationUnit.h"
-#include "clang/Frontend/CompilerInstance.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ToolOutputFile.h"
@@ -162,7 +163,7 @@
   IndexFile.os().flush();
   EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
   llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFileName, "");
+  parseCrossTUIndex(IndexFileName);
   EXPECT_TRUE((bool)IndexOrErr);
   llvm::StringMap ParsedIndex = IndexOrErr.get();
   for (const auto &E : Index) {
@@ -173,25 +174,5 @@
 EXPECT_TRUE(Index.count(E.getKey()));
 }
 
-TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) {
-  llvm::StringMap Index;
-  Index["a"] = "/b/c/d";
-  std::string IndexText = createCrossTUIndexString(Index);
-
-  int IndexFD;
-  llvm::SmallString<256> IndexFileName;
-  ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
-  IndexFileName));
-  llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
-  IndexFile.os() << IndexText;
-  IndexFile.os().flush();
-  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
-  llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFileName, "/ctudir");
-  EXPECT_TRUE((bool)IndexOrErr);
-  llvm::StringMap ParsedIndex = IndexOrErr.get();
-  EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d");
-}
-
 } // end namespace cross_tu
 } // end namespace clang
Index: clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
===
--- clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
+++ clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
@@ -5,7 +5,7 @@
 // RUN: mkdir -p %t/ctudir
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
 // RUN:   -emit-pch -o %t/ctudir/ctu-other.cpp.ast %S/Inputs/ctu-other.cpp
-// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.txt %t/ctudir/externalDefMap.txt
+// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
 // RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-linux-gnu \
 // RUN:   -analyzer-checker=core,debug.ExprInspection \
 // RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
Index: clang/test/Analysis/ctu-on-demand-parsing.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-on-demand-parsing.cpp
@@ -0,0 +1,110 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/Inputs
+// RUN: cp %s %t/ctu-on-demand-parsing.cpp
+// RUN: cp %S/ctu-hdr.h %t/ctu-hdr.h
+// RUN: cp %S/Inputs/ctu-chain.cpp %t/Inputs/ctu-chain.cpp
+// RUN: cp %S/Inputs/ctu-other.cpp %t/Inputs/ctu-other.cpp
+//
+// Path substitutions on Windows platform could contain backslashes. These are escaped in the json file.
+// compile_commands.json is only needed for the extdef_mapping, not for the analysis itself.
+// RUN: echo '[{"directory":"%t/Inputs","command":"clang++ ctu-chain.cpp","file":"ctu-chain.cpp"},{"directory":"%t/Inputs","command":"clang++ ctu-other.cpp","file":"ctu-other.cpp"}]' | sed -e 's/\\//g' > %t/compile_commands.json
+//
+// RUN: echo '{"%t/Inputs/ctu-chain.cpp": ["g++", "%t/Inputs/ctu-chain.cpp"], "%t/Inputs/ctu-other

[PATCH] D80740: [SveEmitter] Add SVE ACLE for svld1ro.

2020-05-29 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen accepted this revision.
sdesmalen added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80740



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


[PATCH] D80781: [clang] Always allow including builtin headers in [no_undeclared_headers] modules.

2020-05-29 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
mboehme added a project: clang.
Herald added a subscriber: cfe-commits.
mboehme added a reviewer: rsmith.

Previously, this would fail if the builtin headers had been "claimed" by a 
different module that wraps these builtin headers. libc++ does this, for 
example.

This change adds a test demonstrating this situation; the test fails without 
the fix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80781

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  
clang/test/Modules/Inputs/no-undeclared-includes-builtins/system_module/module.modulemap
  
clang/test/Modules/Inputs/no-undeclared-includes-builtins/system_module/stddef.h
  
clang/test/Modules/Inputs/no-undeclared-includes-builtins/user_module/module.modulemap
  
clang/test/Modules/Inputs/no-undeclared-includes-builtins/user_module/user_module.h
  clang/test/Modules/no-undeclared-includes-builtins.cpp

Index: clang/test/Modules/no-undeclared-includes-builtins.cpp
===
--- /dev/null
+++ clang/test/Modules/no-undeclared-includes-builtins.cpp
@@ -0,0 +1,9 @@
+// Test that a [no_undeclared_headers] module can include builtin headers, even
+// if these have been "claimed" by a different module that wraps these builtin
+// headers. libc++ does this, for example.
+
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/no-undeclared-includes-builtins/user_module -I %S/Inputs/no-undeclared-includes-builtins/system_module %s
+// expected-no-diagnostics
+
+#include 
Index: clang/test/Modules/Inputs/no-undeclared-includes-builtins/user_module/user_module.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/no-undeclared-includes-builtins/user_module/user_module.h
@@ -0,0 +1 @@
+#include 
Index: clang/test/Modules/Inputs/no-undeclared-includes-builtins/user_module/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/no-undeclared-includes-builtins/user_module/module.modulemap
@@ -0,0 +1,4 @@
+module UserModule [no_undeclared_includes] {
+  header "user_module.h"
+  export *
+}
Index: clang/test/Modules/Inputs/no-undeclared-includes-builtins/system_module/stddef.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/no-undeclared-includes-builtins/system_module/stddef.h
@@ -0,0 +1 @@
+#include_next 
Index: clang/test/Modules/Inputs/no-undeclared-includes-builtins/system_module/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/no-undeclared-includes-builtins/system_module/module.modulemap
@@ -0,0 +1,4 @@
+module stddef [system] {
+  header "stddef.h"
+  export *
+}
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -387,13 +387,17 @@
.Default(false);
 }
 
+bool ModuleMap::isBuiltinHeader(const FileEntry *File) {
+  return File->getDir() == BuiltinIncludeDir &&
+ ModuleMap::isBuiltinHeader(llvm::sys::path::filename(File->getName()));
+}
+
 ModuleMap::HeadersMap::iterator
 ModuleMap::findKnownHeader(const FileEntry *File) {
   resolveHeaderDirectives(File);
   HeadersMap::iterator Known = Headers.find(File);
   if (HeaderInfo.getHeaderSearchOpts().ImplicitModuleMaps &&
-  Known == Headers.end() && File->getDir() == BuiltinIncludeDir &&
-  ModuleMap::isBuiltinHeader(llvm::sys::path::filename(File->getName( {
+  Known == Headers.end() && ModuleMap::isBuiltinHeader(File)) {
 HeaderInfo.loadTopLevelSystemModules();
 return Headers.find(File);
   }
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1276,14 +1276,12 @@
 //
 // It's common that libc++ and system modules will both define such
 // submodules. Make sure cached results for a builtin header won't
-// prevent other builtin modules to potentially enter the builtin header.
-// Note that builtins are header guarded and the decision to actually
-// enter them is postponed to the controlling macros logic below.
+// prevent other builtin modules from potentially entering the builtin
+// header. Note that builtins are header guarded and the decision to
+// actually enter them is postponed to the controlling macros logic below.
 bool TryEnterHdr = false;
 if (FileInfo.isCompilingModuleHeader && FileInfo.isModuleHeader)
-  TryEnterHdr = File->getDir() == ModMap.getBuiltinDir() &&
-ModuleMap::isBuiltinHeader(
-llvm::sys::path::filename(File->getName()));
+

[PATCH] D80627: [clang-format] Create a python documentation tool to generate a summary of the clang-format status for the whole of the LLVM project

2020-05-29 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

@MyDeveloperDay , I know it's a strange request, but could you change (or 
remove) the background color for 100% case.
I'm partially color-blind and having red and green background in the same table 
is really hard to distinguish. I guess I'm not alone.
I'd suggest using something like light blue, it doesn't need to stand out 
anyway.




Comment at: clang/docs/tools/generate_formatted_state.py:50
+totalFilesFail = 0
+for root, subdirs, files in os.walk(rootdir):
+path = os.path.relpath(root, LLVM_DIR)

Unused `subdirs` variable: change to `_`.



Comment at: clang/docs/tools/generate_formatted_state.py:52
+path = os.path.relpath(root, LLVM_DIR)
+if "/test/" in path:
+continue

That doesn't work on Windows because of slashes. You doesn't skip `unittests` 
(present at least in clang and llvm).



Comment at: clang/docs/tools/generate_formatted_state.py:56
+while head:
+fileCount = 0
+filePass = 0

curdeius wrote:
> You can move it outside the loop.
Here you use camelCase, but in other places you use snake_case (e.g. 
`file_path`). Please make that consistent.



Comment at: clang/docs/tools/generate_formatted_state.py:56-58
+fileCount = 0
+filePass = 0
+fileFail = 0

You can move it outside the loop.



Comment at: clang/docs/tools/generate_formatted_state.py:80
+if (fileCount > 0):
+output.write("   * - " + path + "\n")
+output.write(" - " + str(fileCount) + "\n")

Writing `path` directly on Windows will put backslashes that are not rendered 
in rst, so you should either change backslashes to forward slashes (that's what 
I'd suggest) or double the backslashes. You can just `path.replace('\\', '/')`.


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

https://reviews.llvm.org/D80627



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


[PATCH] D80627: [clang-format] Create a python documentation tool to generate a summary of the clang-format status for the whole of the LLVM project

2020-05-29 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D80627#2062332 , @curdeius wrote:

> @MyDeveloperDay , I know it's a strange request, but could you change (or 
> remove) the background color for 100% case.
>  I'm partially color-blind and having red and green background in the same 
> table is really hard to distinguish. I guess I'm not alone.
>  I'd suggest using something like light blue, it doesn't need to stand out 
> anyway.


Absolutely..


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

https://reviews.llvm.org/D80627



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


[PATCH] D80293: [clangd] Run PreambleThread in async mode behind a flag

2020-05-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:724
std::move(Req.WantDiags));
+// Set it after notifying ASTPeer about the preamble to prevent any races.
+BuiltFirst.notify();

kadircet wrote:
> sammccall wrote:
> > hmm, we're notifying the ASTPeer, and then setting builtfirst which is 
> > being waited on... by astpeer.
> > This suggests to me the AST thread should own the notification, not the 
> > preamble thread.
> > And in fact it already has a notification for the first preamble being 
> > built! why can't we use that one?
> umm, it is a little bit more complicated.
> 
> The above call only inserts the "update request" onto ASTPeer's queue and 
> doesn't update the preamble inside ASTPeer. This enables ASTPeer to access 
> `LatestPreamble` without holding the lock, as it is the only writer. We can 
> change that, update the `LatestPreamble` while queueing the request.
As discussed, the relationship between the two is complicated.
At least we should move the second into ASTPeer to reduce the surface area 
between the two.

As a followup, we can "explode" the existing notification into CV + Mutex + 
bool.
The bool can naturally become the "present" bit on LatestPreamble if it turns 
into an Optional> - we must document none vs null!
The Mutex already exists.

Then we don't need the second notification: we just wait on 
`!preambletasks.empty() || LatestPreamble.hasValue()`





Comment at: clang-tools-extra/clangd/TUScheduler.cpp:658
 std::move(CompilerInvocationDiags), WantDiags);
+// Block until first preamble is ready, as patching an empty preamble would
+// imply rebuilding it from scratch.

This isn't the natural place to block, rather where the preamble would be 
consumed.
But that's too late, we'd be running on the worker thread with the PreambleTask 
scheduled and so we'd deadlock.
This needs a comment :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80293



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


[PATCH] D79835: [Fuchsia] Rely on linker switch rather than dead code ref for profile runtime

2020-05-29 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp:1037
 bool InstrProfiling::emitRuntimeHook() {
   // We expect the linker to be invoked with -u flag for linux,
   // for which case there is no need to emit the user function.

Nit: s/for linux/for Linux or Fuchsia/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79835



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


[PATCH] D80627: [clang-format] Create a python documentation tool to generate a summary of the clang-format status for the whole of the LLVM project

2020-05-29 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

@MyDeveloperDay, I've played around with the script, you can take as much as 
you judge useful from here: 
https://github.com/mkurdej/llvm-project/tree/arcpatch-D80627.


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

https://reviews.llvm.org/D80627



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


[PATCH] D79400: [CMAKE] Fix build failure when source directory is read only

2020-05-29 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal updated this revision to Diff 267153.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79400

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/include/llvm/Support/CMakeLists.txt


Index: llvm/include/llvm/Support/CMakeLists.txt
===
--- llvm/include/llvm/Support/CMakeLists.txt
+++ llvm/include/llvm/Support/CMakeLists.txt
@@ -5,12 +5,19 @@
 
 set(generate_vcs_version_script 
"${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
 
-if(llvm_vc AND LLVM_APPEND_VC_REV)
+if(LLVM_APPEND_VC_REV)
   set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
+
+  # A fake version file and is not expected to exist. It is being used to
+  # force regeneration of VCSRevision.h for source directory with no write
+  # permission available.
+  if (NOT llvm_vc)
+set(fake_version_inc "${CMAKE_CURRENT_BINARY_DIR}/__FakeVCSRevision.h")
+  endif()
 endif()
 
 # Create custom target to generate the VC revision include.
-add_custom_command(OUTPUT "${version_inc}"
+add_custom_command(OUTPUT "${version_inc}" "${fake_version_inc}"
   DEPENDS "${llvm_vc}" "${generate_vcs_version_script}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
@@ -22,5 +29,5 @@
   PROPERTIES GENERATED TRUE
  HEADER_FILE_ONLY TRUE)
 
-add_custom_target(llvm_vcsrevision_h DEPENDS "${version_inc}")
+add_custom_target(llvm_vcsrevision_h ALL DEPENDS "${version_inc}" 
"${fake_version_inc}")
 set_target_properties(llvm_vcsrevision_h PROPERTIES FOLDER "Misc")
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -2118,7 +2118,13 @@
 get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
 # Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
 if (NOT EXISTS "${git_dir}/logs/HEAD")
-  file(WRITE "${git_dir}/logs/HEAD" "")
+  execute_process(COMMAND ${CMAKE_COMMAND} -E touch HEAD
+WORKING_DIRECTORY "${git_dir}/logs"
+RESULT_VARIABLE touch_head_result
+ERROR_QUIET)
+  if (NOT touch_head_result EQUAL 0)
+return()
+  endif()
 endif()
 set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
   endif()


Index: llvm/include/llvm/Support/CMakeLists.txt
===
--- llvm/include/llvm/Support/CMakeLists.txt
+++ llvm/include/llvm/Support/CMakeLists.txt
@@ -5,12 +5,19 @@
 
 set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
 
-if(llvm_vc AND LLVM_APPEND_VC_REV)
+if(LLVM_APPEND_VC_REV)
   set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
+
+  # A fake version file and is not expected to exist. It is being used to
+  # force regeneration of VCSRevision.h for source directory with no write
+  # permission available.
+  if (NOT llvm_vc)
+set(fake_version_inc "${CMAKE_CURRENT_BINARY_DIR}/__FakeVCSRevision.h")
+  endif()
 endif()
 
 # Create custom target to generate the VC revision include.
-add_custom_command(OUTPUT "${version_inc}"
+add_custom_command(OUTPUT "${version_inc}" "${fake_version_inc}"
   DEPENDS "${llvm_vc}" "${generate_vcs_version_script}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
@@ -22,5 +29,5 @@
   PROPERTIES GENERATED TRUE
  HEADER_FILE_ONLY TRUE)
 
-add_custom_target(llvm_vcsrevision_h DEPENDS "${version_inc}")
+add_custom_target(llvm_vcsrevision_h ALL DEPENDS "${version_inc}" "${fake_version_inc}")
 set_target_properties(llvm_vcsrevision_h PROPERTIES FOLDER "Misc")
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -2118,7 +2118,13 @@
 get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
 # Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
 if (NOT EXISTS "${git_dir}/logs/HEAD")
-  file(WRITE "${git_dir}/logs/HEAD" "")
+  execute_process(COMMAND ${CMAKE_COMMAND} -E touch HEAD
+WORKING_DIRECTORY "${git_dir}/logs"
+RESULT_VARIABLE touch_head_result
+ERROR_QUIET)
+  if (NOT touch_head_result EQUAL 0)
+return()
+  endif()
 endif()
 set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
   endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80293: [clangd] Run PreambleThread in async mode behind a flag

2020-05-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 267156.
kadircet added a comment.

- Move notification from PreambleThread to ASTWorker


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80293

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -21,14 +21,20 @@
 #include "support/Threading.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 namespace clang {
@@ -407,6 +413,7 @@
   int TotalASTReads = 0;
   int TotalPreambleReads = 0;
   int TotalUpdates = 0;
+  llvm::StringMap LatestDiagVersion;
 
   // Run TUScheduler and collect some stats.
   {
@@ -441,15 +448,23 @@
 auto Inputs = getInputs(File, Contents.str());
 {
   WithContextValue WithNonce(NonceKey, ++Nonce);
-  Inputs.Version = std::to_string(Nonce);
+  Inputs.Version = std::to_string(UpdateI);
   updateWithDiags(
   S, File, Inputs, WantDiagnostics::Auto,
-  [File, Nonce, &Mut, &TotalUpdates](std::vector) {
+  [File, Nonce, Version(Inputs.Version), &Mut, &TotalUpdates,
+   &LatestDiagVersion](std::vector) {
 EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce));
 
 std::lock_guard Lock(Mut);
 ++TotalUpdates;
 EXPECT_EQ(File, *TUScheduler::getFileBeingProcessedInContext());
+// Make sure Diags are for a newer version.
+auto It = LatestDiagVersion.try_emplace(File, -1);
+const int PrevVersion = It.first->second;
+int CurVersion;
+ASSERT_TRUE(llvm::to_integer(Version, CurVersion, 10));
+EXPECT_LT(PrevVersion, CurVersion);
+It.first->getValue() = CurVersion;
   });
 }
 {
@@ -494,7 +509,13 @@
   } // TUScheduler destructor waits for all operations to finish.
 
   std::lock_guard Lock(Mut);
-  EXPECT_EQ(TotalUpdates, FilesCount * UpdatesPerFile);
+  // Updates might get coalesced in preamble thread and result in dropping
+  // diagnostics for intermediate snapshots.
+  EXPECT_GE(TotalUpdates, FilesCount);
+  EXPECT_LE(TotalUpdates, FilesCount * UpdatesPerFile);
+  // We should receive diags for last update.
+  for (const auto &Entry : LatestDiagVersion)
+EXPECT_EQ(Entry.second, UpdatesPerFile - 1);
   EXPECT_EQ(TotalASTReads, FilesCount * UpdatesPerFile);
   EXPECT_EQ(TotalPreambleReads, FilesCount * UpdatesPerFile);
 }
@@ -972,6 +993,57 @@
   EXPECT_NEAR(25, Compute({}), 0.01) << "no history -> max";
 }
 
+TEST_F(TUSchedulerTests, AsyncPreambleThread) {
+  // Blocks preamble thread while building preamble with \p BlockVersion until
+  // \p N is notified.
+  class BlockPreambleThread : public ParsingCallbacks {
+  public:
+BlockPreambleThread(llvm::StringRef BlockVersion, Notification &N)
+: BlockVersion(BlockVersion), N(N) {}
+void onPreambleAST(PathRef Path, llvm::StringRef Version, ASTContext &Ctx,
+   std::shared_ptr PP,
+   const CanonicalIncludes &) override {
+  if (Version == BlockVersion)
+N.wait();
+}
+
+  private:
+llvm::StringRef BlockVersion;
+Notification &N;
+  };
+
+  static constexpr llvm::StringLiteral InputsV0 = "v0";
+  static constexpr llvm::StringLiteral InputsV1 = "v1";
+  Notification Ready;
+  TUScheduler S(CDB, optsForTest(),
+std::make_unique(InputsV1, Ready));
+
+  Path File = testPath("foo.cpp");
+  auto PI = getInputs(File, "");
+  PI.Version = InputsV0.str();
+  S.update(File, PI, WantDiagnostics::Auto);
+  S.blockUntilIdle(timeoutSeconds(10));
+
+  // Block preamble builds.
+  PI.Version = InputsV1.str();
+  // Issue second update which will block preamble thread.
+  S.update(File, PI, WantDiagnostics::Auto);
+
+  Notification RunASTAction;
+  // Issue an AST read, which shouldn't be blocked and see latest version of the
+  // file.
+  S.runWithAST("test", File, [&](Expected AST) {
+

[PATCH] D77658: [analyzer] StdLibraryFunctionsChecker: Add sanity checks for constraints

2020-05-29 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

The code looks basically good to me, some documentations can be improved.




Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:697
 if (auto *FD = dyn_cast(D)) {
-  if (S.matchesSignature(FD)) {
+  if (S.Sign.matches(FD) && S.validate(FD)) {
 auto Res = Map.insert({FD->getCanonicalDecl(), S});

martong wrote:
> balazske wrote:
> > martong wrote:
> > > Szelethus wrote:
> > > > This looks a bit odd, we're checking whether the function matches, and 
> > > > than we validate right after? Shouldn't we just not match the `FD` if 
> > > > it isn't valid?
> > > Yeah, ok, I moved the validation back into `matchesSignature`.
> > I think these are not related, there should be signature match and 
> > validness check, but it is natural to check first the signature, then the 
> > validness.
> @Szelethus, @balazske : I agree with both of you so I renamed 
> `matchesSignature` to `matches`, which is a shorthand to the the signature 
> match and then the validity check (and added a comment):
> ```
> // Returns true if the summary should be applied to the given function.
> bool matches(const FunctionDecl *FD) const {
>   return Sign.matches(FD) && validateByConstraints(FD);
> }
> ```
Suggestion: Maybe we can have one function for `matches` and `setFunctionDecl` 
(set it if matches). We do not want to change the function decl later anyway, 
and not to something that does not match.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:68
   /// We avoid nesting types here because each additional qualifier
   /// would need to be repeated in every function spec.
+  class Summary;

This text above is not the documentation of `Summary` (is it attached to 
`Summary` by doxygen?). Probably not `///` is needed, only `//`. And it is 
probably out of date now, at least I can not understand immediately what is it 
about (what typedef's are these, what kind of "nesting types"). 



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:116
+
+/// Do sanity check on the constraint.
+bool checkValidity(const FunctionDecl *FD) const {

We check here that a function is a suitable candidate to be used with the 
constraint? (We select a function for the constraint, not a constraint for a 
function.) Maybe a better description would help to clarify this.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:571
   // Apply case/branch specifications.
-  for (const auto &VRS : Summary.CaseConstraints) {
+  for (const auto &VRS : Summary.getCaseConstraints()) {
 ProgramStateRef NewState = State;

It may be better to see type of `VRS` instead of `auto` (and know what the 
`VRS` abbrevation means, why not `CC` for case constraint and not `VC` for 
`ValueConstraint`). Same for `VR` below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77658



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


[PATCH] D80784: [clangd][NFC] Explode ReceivedPreamble into a CV

2020-05-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
javed.absar, ilya-biryukov.
Herald added a project: clang.

Instead of a notification, we make use of a CV and store the boolean on
LatestPreamble by converting it into an optional.

Depends on D80293 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80784

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

Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Support/Threading.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -458,9 +459,6 @@
   const GlobalCompilationDatabase &CDB;
   /// Callback invoked when preamble or main file AST is built.
   ParsingCallbacks &Callbacks;
-  /// Latest build preamble for current TU.
-  std::shared_ptr LatestPreamble;
-  Notification BuiltFirstPreamble;
 
   Semaphore &Barrier;
   /// Whether the 'onMainAST' callback ran for the current FileInputs.
@@ -480,7 +478,12 @@
   std::queue PreambleRequests;   /* GUARDED_BY(Mutex) */
   llvm::Optional CurrentRequest; /* GUARDED_BY(Mutex) */
   mutable std::condition_variable RequestsCV;
-  Notification ReceivedPreamble;
+  /// Latest build preamble for current TU.
+  /// None means no builds yet, null means there was an error while building.
+  /// Only written by ASTWorker's thread.
+  llvm::Optional> LatestPreamble;
+  /// Signaled whenever LatestPreamble changes state.
+  mutable std::condition_variable PreambleCV;
   /// Guards the callback that publishes results of AST-related computations
   /// (diagnostics, highlightings) and file statuses.
   std::mutex PublishMu;
@@ -643,20 +646,26 @@
   if (CanPublishResults)
 Publish();
 });
+  // Note that this might throw away a stale preamble that might still be
+  // useful, but this is how we communicate a build error.
+  LatestPreamble.emplace();
   // Make sure anyone waiting for the preamble gets notified it could not be
   // built.
-  BuiltFirstPreamble.notify();
+  PreambleCV.notify_all();
   return;
 }
 
 PreamblePeer.update(std::move(Invocation), std::move(Inputs),
 std::move(CompilerInvocationDiags), WantDiags);
-// Block until first preamble is ready, as patching an empty preamble would
-// imply rebuilding it from scratch.
-// This isn't the natural place to block, rather where the preamble would be
-// consumed. But that's too late, we'd be running on the worker thread with
-// the PreambleTask scheduled and so we'd deadlock.
-ReceivedPreamble.wait();
+std::unique_lock Lock(Mutex);
+RequestsCV.wait(Lock, [this] {
+  // Block until we reiceve a preamble request, unless a preamble already
+  // exists, as patching an empty preamble would imply rebuilding it from
+  // scratch.
+  // We block here instead of the consumer to prevent any deadlocks. Since
+  // LatestPreamble is only populated by ASTWorker thread.
+  return LatestPreamble || !PreambleRequests.empty() || Done;
+});
 return;
   };
   startTask(TaskName, std::move(Task), WantDiags, TUScheduler::NoInvalidation);
@@ -756,7 +765,7 @@
 // Update the preamble inside ASTWorker queue to ensure atomicity. As a task
 // running inside ASTWorker assumes internals won't change until it
 // finishes.
-if (Preamble != LatestPreamble) {
+if (!LatestPreamble || Preamble != *LatestPreamble) {
   ++PreambleBuildCount;
   // Cached AST is no longer valid.
   IdleASTs.take(this);
@@ -764,12 +773,16 @@
   std::lock_guard Lock(Mutex);
   // LatestPreamble might be the last reference to old preamble, do not
   // trigger destructor while holding the lock.
-  std::swap(LatestPreamble, Preamble);
+  if (LatestPreamble)
+std::swap(*LatestPreamble, Preamble);
+  else
+LatestPreamble = std::move(Preamble);
 }
+// Notify anyone waiting for a preamble.
+PreambleCV.notify_all();
 // Give up our ownership to old preamble before starting expensive AST
 // build.
 Preamble.reset();
-BuiltFirstPreamble.notify();
 // We only need to build the AST if diagnostics were requested.
 if (WantDiags == WantDiagnostics::No)
   return;
@@ -780,7 +793,6 @@
   };
   if (RunSync) {
 Task();
-ReceivedPreamble.notify();
 return;
   }
   {
@@ -789,7 +801,6 @@
steady_clock::now(), Context::current().clone(),
llvm::None, TUScheduler::NoInvalidation, nullptr});
   }
-  ReceivedPreamble.notify();
   RequestsCV.notify_all();
 }
 
@@ -800,6 +811,7 @@
   static constexpr t

[PATCH] D80293: [clangd] Run PreambleThread in async mode behind a flag

2020-05-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 267157.
kadircet marked 3 inline comments as done.
kadircet added a comment.

- Add comment explaining why we block on ASTWorker::update rather than 
consumers of a preamble


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80293

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -21,14 +21,20 @@
 #include "support/Threading.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 namespace clang {
@@ -407,6 +413,7 @@
   int TotalASTReads = 0;
   int TotalPreambleReads = 0;
   int TotalUpdates = 0;
+  llvm::StringMap LatestDiagVersion;
 
   // Run TUScheduler and collect some stats.
   {
@@ -441,15 +448,23 @@
 auto Inputs = getInputs(File, Contents.str());
 {
   WithContextValue WithNonce(NonceKey, ++Nonce);
-  Inputs.Version = std::to_string(Nonce);
+  Inputs.Version = std::to_string(UpdateI);
   updateWithDiags(
   S, File, Inputs, WantDiagnostics::Auto,
-  [File, Nonce, &Mut, &TotalUpdates](std::vector) {
+  [File, Nonce, Version(Inputs.Version), &Mut, &TotalUpdates,
+   &LatestDiagVersion](std::vector) {
 EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce));
 
 std::lock_guard Lock(Mut);
 ++TotalUpdates;
 EXPECT_EQ(File, *TUScheduler::getFileBeingProcessedInContext());
+// Make sure Diags are for a newer version.
+auto It = LatestDiagVersion.try_emplace(File, -1);
+const int PrevVersion = It.first->second;
+int CurVersion;
+ASSERT_TRUE(llvm::to_integer(Version, CurVersion, 10));
+EXPECT_LT(PrevVersion, CurVersion);
+It.first->getValue() = CurVersion;
   });
 }
 {
@@ -494,7 +509,13 @@
   } // TUScheduler destructor waits for all operations to finish.
 
   std::lock_guard Lock(Mut);
-  EXPECT_EQ(TotalUpdates, FilesCount * UpdatesPerFile);
+  // Updates might get coalesced in preamble thread and result in dropping
+  // diagnostics for intermediate snapshots.
+  EXPECT_GE(TotalUpdates, FilesCount);
+  EXPECT_LE(TotalUpdates, FilesCount * UpdatesPerFile);
+  // We should receive diags for last update.
+  for (const auto &Entry : LatestDiagVersion)
+EXPECT_EQ(Entry.second, UpdatesPerFile - 1);
   EXPECT_EQ(TotalASTReads, FilesCount * UpdatesPerFile);
   EXPECT_EQ(TotalPreambleReads, FilesCount * UpdatesPerFile);
 }
@@ -972,6 +993,57 @@
   EXPECT_NEAR(25, Compute({}), 0.01) << "no history -> max";
 }
 
+TEST_F(TUSchedulerTests, AsyncPreambleThread) {
+  // Blocks preamble thread while building preamble with \p BlockVersion until
+  // \p N is notified.
+  class BlockPreambleThread : public ParsingCallbacks {
+  public:
+BlockPreambleThread(llvm::StringRef BlockVersion, Notification &N)
+: BlockVersion(BlockVersion), N(N) {}
+void onPreambleAST(PathRef Path, llvm::StringRef Version, ASTContext &Ctx,
+   std::shared_ptr PP,
+   const CanonicalIncludes &) override {
+  if (Version == BlockVersion)
+N.wait();
+}
+
+  private:
+llvm::StringRef BlockVersion;
+Notification &N;
+  };
+
+  static constexpr llvm::StringLiteral InputsV0 = "v0";
+  static constexpr llvm::StringLiteral InputsV1 = "v1";
+  Notification Ready;
+  TUScheduler S(CDB, optsForTest(),
+std::make_unique(InputsV1, Ready));
+
+  Path File = testPath("foo.cpp");
+  auto PI = getInputs(File, "");
+  PI.Version = InputsV0.str();
+  S.update(File, PI, WantDiagnostics::Auto);
+  S.blockUntilIdle(timeoutSeconds(10));
+
+  // Block preamble builds.
+  PI.Version = InputsV1.str();
+  // Issue second update which will block preamble thread.
+  S.update(File, PI, WantDiagnostics::Auto);
+
+  Notification RunASTAction;
+  // Issue an AST read, which shouldn't be blocked and see

[PATCH] D75665: [analyzer] On-demand parsing capability for CTU

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75665



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


[clang-tools-extra] 478f6fb - [clangd] Add buildPreamble to TestTU

2020-05-29 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-05-29T12:20:23+02:00
New Revision: 478f6fb2001698eb102ddce9500ff0885eaaeaab

URL: 
https://github.com/llvm/llvm-project/commit/478f6fb2001698eb102ddce9500ff0885eaaeaab
DIFF: 
https://github.com/llvm/llvm-project/commit/478f6fb2001698eb102ddce9500ff0885eaaeaab.diff

LOG: [clangd] Add buildPreamble to TestTU

Summary: Depends on D77644.

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/PreambleTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
clang-tools-extra/clangd/unittests/TestTU.h

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp 
b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
index bb471ab30175..75aad728280a 100644
--- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -36,37 +36,19 @@ MATCHER_P2(Distance, File, D, "") {
   return arg.first() == File && arg.second == D;
 }
 
-std::shared_ptr
-createPreamble(llvm::StringRef Contents = "") {
-  auto TU = TestTU::withCode(Contents);
-  // ms-compatibility changes meaning of #import, make sure it is turned off.
-  TU.ExtraArgs = {"-fno-ms-compatibility"};
-  TU.Filename = "preamble.cpp";
-  auto PI = TU.inputs();
-  IgnoreDiagnostics Diags;
-  auto CI = buildCompilerInvocation(PI, Diags);
-  if (!CI) {
-ADD_FAILURE() << "failed to build compiler invocation";
-return nullptr;
-  }
-  if (auto Preamble = buildPreamble(TU.Filename, *CI, PI, true, nullptr))
-return Preamble;
-  ADD_FAILURE() << "failed to build preamble";
-  return nullptr;
-}
-
 // Builds a preamble for BaselineContents, patches it for ModifiedContents and
 // returns the includes in the patch.
 IncludeStructure
 collectPatchedIncludes(llvm::StringRef ModifiedContents,
llvm::StringRef BaselineContents,
llvm::StringRef MainFileName = "main.cpp") {
-  auto BaselinePreamble = createPreamble(BaselineContents);
-  // Create the patch.
-  auto TU = TestTU::withCode(ModifiedContents);
+  auto TU = TestTU::withCode(BaselineContents);
   TU.Filename = MainFileName.str();
   // ms-compatibility changes meaning of #import, make sure it is turned off.
   TU.ExtraArgs = {"-fno-ms-compatibility"};
+  auto BaselinePreamble = TU.preamble();
+  // Create the patch.
+  TU = TestTU::withCode(ModifiedContents);
   auto PI = TU.inputs();
   auto PP = PreamblePatch::create(testPath(TU.Filename), PI, 
*BaselinePreamble);
   // Collect patch contents.

diff  --git a/clang-tools-extra/clangd/unittests/TestTU.cpp 
b/clang-tools-extra/clangd/unittests/TestTU.cpp
index 824c4cc8ff14..b4781425943c 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -66,14 +66,24 @@ ParseInputs TestTU::inputs() const {
   return Inputs;
 }
 
+std::shared_ptr TestTU::preamble() const {
+  auto Inputs = inputs();
+  IgnoreDiagnostics Diags;
+  auto CI = buildCompilerInvocation(Inputs, Diags);
+  assert(CI && "Failed to build compilation invocation.");
+  return clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+  /*StoreInMemory=*/true,
+  /*PreambleCallback=*/nullptr);
+}
+
 ParsedAST TestTU::build() const {
   auto Inputs = inputs();
   StoreDiags Diags;
   auto CI = buildCompilerInvocation(Inputs, Diags);
   assert(CI && "Failed to build compilation invocation.");
-  auto Preamble =
-  buildPreamble(testPath(Filename), *CI, Inputs,
-/*StoreInMemory=*/true, /*PreambleCallback=*/nullptr);
+  auto Preamble = clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+   /*StoreInMemory=*/true,
+   /*PreambleCallback=*/nullptr);
   auto AST = ParsedAST::build(testPath(Filename), Inputs, std::move(CI),
   Diags.take(), Preamble);
   if (!AST.hasValue()) {

diff  --git a/clang-tools-extra/clangd/unittests/TestTU.h 
b/clang-tools-extra/clangd/unittests/TestTU.h
index 2be294f78e7e..57017f4a9175 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.h
+++ b/clang-tools-extra/clangd/unittests/TestTU.h
@@ -68,6 +68,7 @@ struct TestTU {
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   ParsedAST build() const;
+  std::shared_ptr preamble() const;
   ParseInputs inputs() const;
   SymbolSlab headerSymbols() const;
   RefSlab headerRefs() const;



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


[clang-tools-extra] b742eaa - [clangd] Handle additional includes while parsing ASTs

2020-05-29 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-05-29T12:20:23+02:00
New Revision: b742eaa321219fa3444e3bcd33eda441bea6b73a

URL: 
https://github.com/llvm/llvm-project/commit/b742eaa321219fa3444e3bcd33eda441bea6b73a
DIFF: 
https://github.com/llvm/llvm-project/commit/b742eaa321219fa3444e3bcd33eda441bea6b73a.diff

LOG: [clangd] Handle additional includes while parsing ASTs

Summary:
Enables building ASTs with stale preambles by handling additional preamble
includes. Sets the correct location information for those imaginary includes so
that features like gotodef/documentlink keeps functioning propoerly.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, usaxena95, 
cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/Preamble.h
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
clang-tools-extra/clangd/unittests/PreambleTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index f2bdadb0ad9d..d2ee41f36cf4 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1031,7 +1031,7 @@ struct SemaCompleteInput {
   PathRef FileName;
   const tooling::CompileCommand &Command;
   const PreambleData &Preamble;
-  const PreamblePatch &Patch;
+  llvm::Optional Patch;
   llvm::StringRef Contents;
   size_t Offset;
   llvm::IntrusiveRefCntPtr VFS;
@@ -1105,7 +1105,8 @@ bool 
semaCodeComplete(std::unique_ptr Consumer,
   PreambleBounds PreambleRegion =
   ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
   bool CompletingInPreamble = PreambleRegion.Size > Input.Offset;
-  Input.Patch.apply(*CI);
+  if (Input.Patch)
+Input.Patch->apply(*CI);
   // NOTE: we must call BeginSourceFile after prepareCompilerInstance. 
Otherwise
   // the remapped buffers do not get freed.
   auto Clang = prepareCompilerInstance(
@@ -1767,7 +1768,8 @@ codeComplete(PathRef FileName, const 
tooling::CompileCommand &Command,
  : std::move(Flow).run({FileName, Command, *Preamble,
 // We want to serve code completions with
 // low latency, so don't bother patching.
-PreamblePatch(), Contents, *Offset, VFS});
+/*PreamblePatch=*/llvm::None, Contents,
+*Offset, VFS});
 }
 
 SignatureHelp signatureHelp(PathRef FileName,
@@ -1792,10 +1794,11 @@ SignatureHelp signatureHelp(PathRef FileName,
   PI.CompileCommand = Command;
   PI.Contents = Contents.str();
   PI.FS = std::move(VFS);
-  auto PP = PreamblePatch::create(FileName, PI, Preamble);
   semaCodeComplete(
   std::make_unique(Options, Index, Result), 
Options,
-  {FileName, Command, Preamble, PP, Contents, *Offset, std::move(PI.FS)});
+  {FileName, Command, Preamble,
+   PreamblePatch::create(FileName, PI, Preamble), Contents, *Offset,
+   std::move(PI.FS)});
   return Result;
 }
 

diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index e7678f3d69e9..660932a7b259 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -14,6 +14,7 @@
 #include "Diagnostics.h"
 #include "Headers.h"
 #include "IncludeFixer.h"
+#include "Preamble.h"
 #include "SourceCode.h"
 #include "index/CanonicalIncludes.h"
 #include "index/Index.h"
@@ -48,6 +49,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
+#include 
 
 // Force the linker to link in Clang-tidy modules.
 // clangd doesn't support the static analyzer.
@@ -268,6 +270,11 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
 
   StoreDiags ASTDiags;
 
+  llvm::Optional Patch;
+  if (Preamble) {
+Patch = PreamblePatch::create(Filename, Inputs, *Preamble);
+Patch->apply(*CI);
+  }
   auto Clang = prepareCompilerInstance(
   std::move(CI), PreamblePCH,
   llvm::MemoryBuffer::getMemBufferCopy(Inputs.Contents, Filename), VFS,
@@ -369,12 +376,14 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
 Clang->setExternalSemaSource(FixIncludes->unresolvedNameRecorder());
   }
 
-  // Copy over the includes from the preamble, then combine with the
-  // non-preamble includes below.
-  auto Includes = Preamble ? Preamble->Includes : IncludeStructure{};
-  // Replay the preamble includes so that clang-tidy checks can see them.
-  if (Preamble)
+  IncludeStructure Includes;
+  // If we are using a preamble, copy existing includes.
+  if (Preamble) {
+Includes = Preamble->Incl

[clang-tools-extra] 1772adb - [clangd] Preserve extra args in PreambleTests::IncludeParsing to fix windows build bots

2020-05-29 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-05-29T12:35:25+02:00
New Revision: 1772adb0594bf0d8684fe8b63609352ad4a1ccf0

URL: 
https://github.com/llvm/llvm-project/commit/1772adb0594bf0d8684fe8b63609352ad4a1ccf0
DIFF: 
https://github.com/llvm/llvm-project/commit/1772adb0594bf0d8684fe8b63609352ad4a1ccf0.diff

LOG: [clangd] Preserve extra args in PreambleTests::IncludeParsing to fix 
windows build bots

Added: 


Modified: 
clang-tools-extra/clangd/unittests/PreambleTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp 
b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
index 75aad728280a..b1548ef4732b 100644
--- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -48,7 +48,7 @@ collectPatchedIncludes(llvm::StringRef ModifiedContents,
   TU.ExtraArgs = {"-fno-ms-compatibility"};
   auto BaselinePreamble = TU.preamble();
   // Create the patch.
-  TU = TestTU::withCode(ModifiedContents);
+  TU.Code = ModifiedContents.str();
   auto PI = TU.inputs();
   auto PP = PreamblePatch::create(testPath(TU.Filename), PI, 
*BaselinePreamble);
   // Collect patch contents.



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


[PATCH] D80697: [clang-tidy] Reworked TransformerClangTidyCheck to simplify usage of Options

2020-05-29 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

There are a few reasons for using the virtual method:

- It keeps everything contained in the one class.
- In the case where options are needed it avoid extra work in the derived class.
- It's consistent with how all base class checks handle the specifics of 
derived checks.




Comment at: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h:62
-  // of the language or clang-tidy options.
-  TransformerClangTidyCheck(transformer::RewriteRule R, StringRef Name,
-ClangTidyContext *Context);

ymandel wrote:
> Why delete this? It is the most commonly used constructor and cleaner than 
> the OOP goop of the virtual method.
I'll add that back in, but I feel this constructor is no different in most 
cases to just placing the rule builder in the virtual method


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80697



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


[PATCH] D80697: [clang-tidy] Reworked TransformerClangTidyCheck to simplify usage of Options

2020-05-29 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 267161.
njames93 marked 3 inline comments as done.
njames93 added a comment.

- Add back old constructors, one being deprecated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80697

Files:
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.h
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
@@ -10,6 +10,7 @@
 #include "ClangTidyTest.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/Transformer/RangeSelector.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
 #include "clang/Tooling/Transformer/Stencil.h"
 #include "clang/Tooling/Transformer/Transformer.h"
 #include "gtest/gtest.h"
@@ -28,23 +29,23 @@
 using transformer::statement;
 
 // Invert the code of an if-statement, while maintaining its semantics.
-RewriteRule invertIf() {
-  StringRef C = "C", T = "T", E = "E";
-  RewriteRule Rule = tooling::makeRule(
-  ifStmt(hasCondition(expr().bind(C)), hasThen(stmt().bind(T)),
- hasElse(stmt().bind(E))),
-  change(statement(std::string(RewriteRule::RootID)),
- cat("if(!(", node(std::string(C)), ")) ",
- statement(std::string(E)), " else ",
- statement(std::string(T,
-  cat("negate condition and reverse `then` and `else` branches"));
-  return Rule;
-}
-
 class IfInverterCheck : public TransformerClangTidyCheck {
 public:
   IfInverterCheck(StringRef Name, ClangTidyContext *Context)
-  : TransformerClangTidyCheck(invertIf(), Name, Context) {}
+  : TransformerClangTidyCheck(Name, Context) {}
+
+  Optional buildRule() const override {
+StringRef C = "C", T = "T", E = "E";
+RewriteRule Rule = tooling::makeRule(
+ifStmt(hasCondition(expr().bind(C)), hasThen(stmt().bind(T)),
+   hasElse(stmt().bind(E))),
+change(statement(std::string(RewriteRule::RootID)),
+   cat("if(!(", node(std::string(C)), ")) ",
+   statement(std::string(E)), " else ",
+   statement(std::string(T,
+cat("negate condition and reverse `then` and `else` branches"));
+return Rule;
+  }
 };
 
 // Basic test of using a rewrite rule as a ClangTidy.
@@ -70,10 +71,12 @@
 class IntLitCheck : public TransformerClangTidyCheck {
 public:
   IntLitCheck(StringRef Name, ClangTidyContext *Context)
-  : TransformerClangTidyCheck(tooling::makeRule(integerLiteral(),
-change(cat("LIT")),
-cat("no message")),
-  Name, Context) {}
+  : TransformerClangTidyCheck(Name, Context) {}
+
+  Optional buildRule() const override {
+return tooling::makeRule(integerLiteral(), change(cat("LIT")),
+ cat("no message"));
+  }
 };
 
 // Tests that two changes in a single macro expansion do not lead to conflicts
@@ -94,11 +97,13 @@
 class BinOpCheck : public TransformerClangTidyCheck {
 public:
   BinOpCheck(StringRef Name, ClangTidyContext *Context)
-  : TransformerClangTidyCheck(
-tooling::makeRule(
-binaryOperator(hasOperatorName("+"), hasRHS(expr().bind("r"))),
-change(node("r"), cat("RIGHT")), cat("no message")),
-Name, Context) {}
+  : TransformerClangTidyCheck(Name, Context) {}
+
+  Optional buildRule() const override {
+return tooling::makeRule(
+binaryOperator(hasOperatorName("+"), hasRHS(expr().bind("r"))),
+change(node("r"), cat("RIGHT")), cat("no message"));
+  }
 };
 
 // Tests case where the rule's match spans both source from the macro and its
@@ -118,18 +123,20 @@
 }
 
 // A trivial rewrite-rule generator that requires Objective-C code.
-Optional needsObjC(const LangOptions &LangOpts,
-const ClangTidyCheck::OptionsView &Options) {
-  if (!LangOpts.ObjC)
-return None;
-  return tooling::makeRule(clang::ast_matchers::functionDecl(),
-   change(cat("void changed() {}")), cat("no message"));
-}
-
 class NeedsObjCCheck : public TransformerClangTidyCheck {
 public:
   NeedsObjCCheck(StringRef Name, ClangTidyContext *Context)
-  : TransformerClangTidyCheck(needsObjC, Name, Context) {}
+  : TransformerClangTidyCheck(Name, Context) {}
+
+  bool isLanguageVersio

[PATCH] D79930: [clangd] Add buildPreamble to TestTU

2020-05-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG478f6fb20016: [clangd] Add buildPreamble to TestTU (authored 
by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79930

Files:
  clang-tools-extra/clangd/unittests/PreambleTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h


Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -68,6 +68,7 @@
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   ParsedAST build() const;
+  std::shared_ptr preamble() const;
   ParseInputs inputs() const;
   SymbolSlab headerSymbols() const;
   RefSlab headerRefs() const;
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -66,14 +66,24 @@
   return Inputs;
 }
 
+std::shared_ptr TestTU::preamble() const {
+  auto Inputs = inputs();
+  IgnoreDiagnostics Diags;
+  auto CI = buildCompilerInvocation(Inputs, Diags);
+  assert(CI && "Failed to build compilation invocation.");
+  return clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+  /*StoreInMemory=*/true,
+  /*PreambleCallback=*/nullptr);
+}
+
 ParsedAST TestTU::build() const {
   auto Inputs = inputs();
   StoreDiags Diags;
   auto CI = buildCompilerInvocation(Inputs, Diags);
   assert(CI && "Failed to build compilation invocation.");
-  auto Preamble =
-  buildPreamble(testPath(Filename), *CI, Inputs,
-/*StoreInMemory=*/true, /*PreambleCallback=*/nullptr);
+  auto Preamble = clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+   /*StoreInMemory=*/true,
+   /*PreambleCallback=*/nullptr);
   auto AST = ParsedAST::build(testPath(Filename), Inputs, std::move(CI),
   Diags.take(), Preamble);
   if (!AST.hasValue()) {
Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -36,37 +36,19 @@
   return arg.first() == File && arg.second == D;
 }
 
-std::shared_ptr
-createPreamble(llvm::StringRef Contents = "") {
-  auto TU = TestTU::withCode(Contents);
-  // ms-compatibility changes meaning of #import, make sure it is turned off.
-  TU.ExtraArgs = {"-fno-ms-compatibility"};
-  TU.Filename = "preamble.cpp";
-  auto PI = TU.inputs();
-  IgnoreDiagnostics Diags;
-  auto CI = buildCompilerInvocation(PI, Diags);
-  if (!CI) {
-ADD_FAILURE() << "failed to build compiler invocation";
-return nullptr;
-  }
-  if (auto Preamble = buildPreamble(TU.Filename, *CI, PI, true, nullptr))
-return Preamble;
-  ADD_FAILURE() << "failed to build preamble";
-  return nullptr;
-}
-
 // Builds a preamble for BaselineContents, patches it for ModifiedContents and
 // returns the includes in the patch.
 IncludeStructure
 collectPatchedIncludes(llvm::StringRef ModifiedContents,
llvm::StringRef BaselineContents,
llvm::StringRef MainFileName = "main.cpp") {
-  auto BaselinePreamble = createPreamble(BaselineContents);
-  // Create the patch.
-  auto TU = TestTU::withCode(ModifiedContents);
+  auto TU = TestTU::withCode(BaselineContents);
   TU.Filename = MainFileName.str();
   // ms-compatibility changes meaning of #import, make sure it is turned off.
   TU.ExtraArgs = {"-fno-ms-compatibility"};
+  auto BaselinePreamble = TU.preamble();
+  // Create the patch.
+  TU = TestTU::withCode(ModifiedContents);
   auto PI = TU.inputs();
   auto PP = PreamblePatch::create(testPath(TU.Filename), PI, 
*BaselinePreamble);
   // Collect patch contents.


Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -68,6 +68,7 @@
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   ParsedAST build() const;
+  std::shared_ptr preamble() const;
   ParseInputs inputs() const;
   SymbolSlab headerSymbols() const;
   RefSlab headerRefs() const;
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unitt

[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: cfe-commits, martong.
Herald added a reviewer: shafik.
Herald added a reviewer: rengolin.
Herald added a project: clang.

Declaring these helpers in the ast_matcher namespace in the clangAST
library seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.

Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I renamed it
to "UnittestClangArgs" to emphasize semantics and de-emphasize
vector-ness.

Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"UnittestLanguage".

Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80786

Files:
  clang/unittests/AST/ASTImporterFixtures.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterODRStrategiesTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/ASTImporterVisibilityTest.cpp
  clang/unittests/AST/Language.cpp
  clang/unittests/AST/Language.h
  clang/unittests/AST/MatchVerifier.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -23,12 +23,13 @@
   // snippets. To determine the returned node, a separate matcher is specified
   // for both snippets. The first matching node is returned.
   template 
-  std::tuple makeDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang,
-  const MatcherType &Matcher0, const MatcherType &Matcher1) {
+  std::tuple
+  makeDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+UnittestLanguage Lang, const MatcherType &Matcher0,
+const MatcherType &Matcher1) {
 this->Code0 = SrcCode0;
 this->Code1 = SrcCode1;
-ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+UnittestClangArgs Args = getCommandLineArgsForTesting(Lang);
 
 const char *const InputFileName = "input.cc";
 
@@ -43,11 +44,12 @@
 return std::make_tuple(D0, D1);
   }
 
-  std::tuple makeTuDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang) {
+  std::tuple
+  makeTuDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+  UnittestLanguage Lang) {
 this->Code0 = SrcCode0;
 this->Code1 = SrcCode1;
-ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+UnittestClangArgs Args = getCommandLineArgsForTesting(Lang);
 
 const char *const InputFileName = "input.cc";
 
@@ -61,9 +63,9 @@
   // Get a pair of node pointers into the synthesized AST from the given code
   // snippets. The same matcher is used for both snippets.
   template 
-  std::tuple makeDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang,
-  const MatcherType &AMatcher) {
+  std::tuple
+  makeDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+UnittestLanguage Lang, const MatcherType &AMatcher) {
 return makeDecls(
   SrcCode0, SrcCode1, Lang, AMatcher, AMatcher);
   }
@@ -71,9 +73,9 @@
   // Get a pair of Decl pointers to the synthesized declarations from the given
   // code snippets. We search for the first NamedDecl with given name in both
   // snippets.
-  std::tuple makeNamedDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1,
-  Language Lang, const char *const Identifier = "foo") {
+  std::tuple
+  makeNamedDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+ UnittestLanguage Lang, const char *const Identifier = "foo") {
 auto Matcher = namedDecl(hasName(Identifier));
 return makeDecls(SrcCode0, SrcCode1, Lang, Matcher);
   }
Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -42,16 +42,15 @@
   template 
   testing::AssertionResult match(const std::string &Code,
  const MatcherType &AMatcher,
- Language L) {
+ UnittestLanguage L) {
 std::vector Args;
 return match(Code, AMatcher, Args, L);
   }
 
   template 
-  testing::AssertionResult match(const std::string &Code,
- const MatcherType &AMatcher,
- std::vector& Args,
- Language L);
+  testing::AssertionResult
+  match

[PATCH] D77644: [clangd] Handle additional includes while parsing ASTs

2020-05-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb742eaa32121: [clangd] Handle additional includes while 
parsing ASTs (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77644

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -8,6 +8,7 @@
 
 #include "Annotations.h"
 #include "Compiler.h"
+#include "Headers.h"
 #include "Preamble.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -21,6 +22,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -30,51 +32,58 @@
 namespace clangd {
 namespace {
 
+MATCHER_P2(Distance, File, D, "") {
+  return arg.first() == File && arg.second == D;
+}
+
+std::shared_ptr
+createPreamble(llvm::StringRef Contents = "") {
+  auto TU = TestTU::withCode(Contents);
+  // ms-compatibility changes meaning of #import, make sure it is turned off.
+  TU.ExtraArgs = {"-fno-ms-compatibility"};
+  TU.Filename = "preamble.cpp";
+  auto PI = TU.inputs();
+  IgnoreDiagnostics Diags;
+  auto CI = buildCompilerInvocation(PI, Diags);
+  if (!CI) {
+ADD_FAILURE() << "failed to build compiler invocation";
+return nullptr;
+  }
+  if (auto Preamble = buildPreamble(TU.Filename, *CI, PI, true, nullptr))
+return Preamble;
+  ADD_FAILURE() << "failed to build preamble";
+  return nullptr;
+}
+
 // Builds a preamble for BaselineContents, patches it for ModifiedContents and
 // returns the includes in the patch.
 IncludeStructure
 collectPatchedIncludes(llvm::StringRef ModifiedContents,
llvm::StringRef BaselineContents,
llvm::StringRef MainFileName = "main.cpp") {
-  std::string MainFile = testPath(MainFileName);
-  ParseInputs PI;
-  PI.FS = new llvm::vfs::InMemoryFileSystem;
-  MockCompilationDatabase CDB;
+  auto BaselinePreamble = createPreamble(BaselineContents);
+  // Create the patch.
+  auto TU = TestTU::withCode(ModifiedContents);
+  TU.Filename = MainFileName.str();
   // ms-compatibility changes meaning of #import, make sure it is turned off.
-  CDB.ExtraClangFlags.push_back("-fno-ms-compatibility");
-  PI.CompileCommand = CDB.getCompileCommand(MainFile).getValue();
-  // Create invocation
+  TU.ExtraArgs = {"-fno-ms-compatibility"};
+  auto PI = TU.inputs();
+  auto PP = PreamblePatch::create(testPath(TU.Filename), PI, *BaselinePreamble);
+  // Collect patch contents.
   IgnoreDiagnostics Diags;
   auto CI = buildCompilerInvocation(PI, Diags);
-  assert(CI && "failed to create compiler invocation");
-  // Build baseline preamble.
-  PI.Contents = BaselineContents.str();
-  PI.Version = "baseline preamble";
-  auto BaselinePreamble = buildPreamble(MainFile, *CI, PI, true, nullptr);
-  assert(BaselinePreamble && "failed to build baseline preamble");
-  // Create the patch.
-  PI.Contents = ModifiedContents.str();
-  PI.Version = "modified contents";
-  auto PP = PreamblePatch::create(MainFile, PI, *BaselinePreamble);
-  // Collect patch contents.
   PP.apply(*CI);
-  llvm::StringRef PatchContents;
-  for (const auto &Rempaped : CI->getPreprocessorOpts().RemappedFileBuffers) {
-if (Rempaped.first == testPath("__preamble_patch__.h")) {
-  PatchContents = Rempaped.second->getBuffer();
-  break;
-}
-  }
-  // Run preprocessor over the modified contents with patched Invocation to and
-  // BaselinePreamble to collect includes in the patch. We trim the input to
-  // only preamble section to not collect includes in the mainfile.
+  // Run preprocessor over the modified contents with patched Invocation. We
+  // provide a preamble and trim contents to ensure only the implicit header
+  // introduced by the patch is parsed and nothing else.
+  // We don't run PP directly over the patch cotents to test production
+  // behaviour.
   auto Bounds = Lexer::ComputePreamble(ModifiedContents, *CI->getLangOpts());
   auto Clang =
   prepareCompilerInstance(std::move(CI), &BaselinePreamble->Preamble,
   llvm::MemoryBuffer::getMemBufferCopy(
   ModifiedContents.slice(0, Bounds.Size).str()),
   PI.FS, Diags);
-  Clang->getPreprocessorOpts().ImplicitPCHInclude.clear();
   PreprocessOnlyAction Action;
   if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
 ADD_FAILURE() << "failed begin source file";
@@ -

[clang-tools-extra] fcde3d5 - [clangd] Patch PP directives to use stale preambles while building ASTs

2020-05-29 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-05-29T12:46:53+02:00
New Revision: fcde3d5b04b612ebc4164fe8f3e83f93cd1fce53

URL: 
https://github.com/llvm/llvm-project/commit/fcde3d5b04b612ebc4164fe8f3e83f93cd1fce53
DIFF: 
https://github.com/llvm/llvm-project/commit/fcde3d5b04b612ebc4164fe8f3e83f93cd1fce53.diff

LOG: [clangd] Patch PP directives to use stale preambles while building ASTs

Summary:
Depends on D79930.

This enables more accurate parsing of the AST, by making new macro
definitions in preamble section visible. This is handled by injecting
define directives into preamble patch.

This patch doesn't handle any location mappings yet, so features like go-to-def,
go-to-refs and hover might not work as expected. These will be addressed in a
follow-up patch.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/Preamble.h
clang-tools-extra/clangd/unittests/PreambleTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index 959b241dac12..dcfafc914d10 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -106,14 +107,70 @@ class CppFilePreambleCallbacks : public PreambleCallbacks 
{
   const SourceManager *SourceMgr = nullptr;
 };
 
-/// Gets the includes in the preamble section of the file by running
-/// preprocessor over \p Contents. Returned includes do not contain resolved
-/// paths. \p VFS and \p Cmd is used to build the compiler invocation, which
-/// might stat/read files.
-llvm::Expected>
-scanPreambleIncludes(llvm::StringRef Contents,
- llvm::IntrusiveRefCntPtr VFS,
- const tooling::CompileCommand &Cmd) {
+// Represents directives other than includes, where basic textual information 
is
+// enough.
+struct TextualPPDirective {
+  unsigned DirectiveLine;
+  // Full text that's representing the directive, including the `#`.
+  std::string Text;
+
+  bool operator==(const TextualPPDirective &RHS) const {
+return std::tie(DirectiveLine, Text) ==
+   std::tie(RHS.DirectiveLine, RHS.Text);
+  }
+};
+
+// Collects #define directives inside the main file.
+struct DirectiveCollector : public PPCallbacks {
+  DirectiveCollector(const Preprocessor &PP,
+ std::vector &TextualDirectives)
+  : LangOpts(PP.getLangOpts()), SM(PP.getSourceManager()),
+TextualDirectives(TextualDirectives) {}
+
+  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
+   SrcMgr::CharacteristicKind FileType,
+   FileID PrevFID) override {
+InMainFile = SM.isWrittenInMainFile(Loc);
+  }
+
+  void MacroDefined(const Token &MacroNameTok,
+const MacroDirective *MD) override {
+if (!InMainFile)
+  return;
+TextualDirectives.emplace_back();
+TextualPPDirective &TD = TextualDirectives.back();
+
+auto DecompLoc = SM.getDecomposedLoc(MacroNameTok.getLocation());
+TD.DirectiveLine = SM.getLineNumber(DecompLoc.first, DecompLoc.second);
+
+SourceRange DefRange(
+MD->getMacroInfo()->getDefinitionLoc(),
+Lexer::getLocForEndOfToken(MD->getMacroInfo()->getDefinitionEndLoc(), 
0,
+   SM, LangOpts));
+llvm::raw_string_ostream OS(TD.Text);
+OS << "#define " << toSourceCode(SM, DefRange);
+  }
+
+private:
+  bool InMainFile = true;
+  const LangOptions &LangOpts;
+  const SourceManager &SM;
+  std::vector &TextualDirectives;
+};
+
+struct ScannedPreamble {
+  std::vector Includes;
+  std::vector TextualDirectives;
+};
+
+/// Scans the preprocessor directives in the preamble section of the file by
+/// running preprocessor over \p Contents. Returned includes do not contain
+/// resolved paths. \p VFS and \p Cmd is used to build the compiler invocation,
+/// which might stat/read files.
+llvm::Expected
+scanPreamble(llvm::StringRef Contents,
+ llvm::IntrusiveRefCntPtr VFS,
+ const tooling::CompileCommand &Cmd) {
   // Build and run Preprocessor over the preamble.
   ParseInputs PI;
   PI.Contents = Contents.str();
@@ -147,14 +204,18 @@ scanPreambleIncludes(llvm::StringRef Contents,
   if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]))
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"failed BeginSourceFile");
+  const auto &SM = Clang

[clang-tools-extra] 538c275 - [clangd] locateMacroAt handles patched macros

2020-05-29 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-05-29T12:46:54+02:00
New Revision: 538c2753f3ec818eae57a5c5dfbe1f05af57ee37

URL: 
https://github.com/llvm/llvm-project/commit/538c2753f3ec818eae57a5c5dfbe1f05af57ee37
DIFF: 
https://github.com/llvm/llvm-project/commit/538c2753f3ec818eae57a5c5dfbe1f05af57ee37.diff

LOG: [clangd] locateMacroAt handles patched macros

Summary: Depends on D79992.

This patch changes locateMacroAt to perform #line directive substitution
for macro identifier locations.

We first check whether a location is inside a file included through
built-in header. If so we check whether line directive maps it back to
the main file, and afterwards use TokenBuffers to find exact location of
the identifier on the line.

Instead of performing the mapping in locateMacroAt, we could also store
a mapping inside the ParsedAST whenever we use a patched preamble. But
that would imply adding more responsibility to ParsedAST and paying for
the mapping even when it is not going to be used.



Go-To-Definition:

Later on these locations are used for serving go-to-definition requests,
this enables jumping to definition inside the preamble section in
presence of patched macros.

=

Go-To-Refs:

Macro references in main file are collected separetely and stored as a
map from macro's symbol id to reference ranges. Those ranges are
computed inside PPCallbacks, hence we don't have access to TokenBuffer.

In presence of preamble patch, any reference to a macro inside the
preamble section will unfortunately have the wrong range. They'll point
into the patch rather than the main file. Hence during findReferences,
we won't get any ranges reported for those.

Fixing those requires:
- Lexing the preamble section to figure out "real range" of a patched
  macro definition
- Postponing range/location calculations until a later step in which we
  have access to tokenbuffers.

This patch trades some accuracy in favor of code complexity. We don't do
any patching for references inside the preamble patch but get any
reference inside the main file for free.

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/Preamble.h
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/SourceCode.h
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/HeadersTests.cpp
clang-tools-extra/clangd/unittests/PreambleTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Headers.cpp 
b/clang-tools-extra/clangd/Headers.cpp
index 2b9f8feb7db8..876645cd6a50 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -8,6 +8,7 @@
 
 #include "Headers.h"
 #include "Compiler.h"
+#include "Preamble.h"
 #include "SourceCode.h"
 #include "support/Logger.h"
 #include "clang/Basic/SourceLocation.h"
@@ -23,11 +24,6 @@ namespace clang {
 namespace clangd {
 namespace {
 
-bool isMainFile(llvm::StringRef FileName, const SourceManager &SM) {
-  auto FE = SM.getFileManager().getFile(FileName);
-  return FE && *FE == SM.getFileEntryForID(SM.getMainFileID());
-}
-
 class RecordHeaders : public PPCallbacks {
 public:
   RecordHeaders(const SourceManager &SM, IncludeStructure *Out)
@@ -44,17 +40,8 @@ class RecordHeaders : public PPCallbacks {
   SrcMgr::CharacteristicKind FileKind) override {
 auto MainFID = SM.getMainFileID();
 // If an include is part of the preamble patch, translate #line directives.
-if (InBuiltinFile) {
-  auto Presumed = SM.getPresumedLoc(HashLoc);
-  // Presumed locations will have an invalid file id when #line directive
-  // changes the filename.
-  if (Presumed.getFileID().isInvalid() &&
-  isMainFile(Presumed.getFilename(), SM)) {
-// Now we'll hit the case below.
-HashLoc = SM.translateLineCol(MainFID, Presumed.getLine(),
-  Presumed.getColumn());
-  }
-}
+if (InBuiltinFile)
+  HashLoc = translatePreamblePatchLocation(HashLoc, SM);
 
 // Record main-file inclusions (including those mapped from the preamble
 // patch).

diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index e2a3a0dd62f5..1cc564be5cf5 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -376,8 +376,7 @@ llvm::Optional fieldName(const Expr *E) {
   const auto *ME = llvm::dyn_cast(E->IgnoreCasts());
   if (!ME || !llvm::isa(ME->getBase()->IgnoreCasts()))
 return llvm::None;
-  const auto *Field =
-  llvm::dyn_cast(ME->getMemberDecl());
+  const auto *Field = llvm::dyn_cast(ME->getMemberDecl());
   if (!Field || !Field->g

[PATCH] D43002: Emit S_OBJNAME symbol in CodeView

2020-05-29 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

In D43002#2061162 , @echristo wrote:

> First question:
>
> Since split dwarf has to do some similar things can we not use the same 
> support? This seems to be a lot of changes for this.
>
> Second question:
>
> and if we can't use the same support can we make split dwarf use this? Having 
> two separate methods for passing everything around is a bit painful.


To answer both questions, I tried to converge but the uses are slightly 
different. In one case (DWARF) the `-split-dwarf-file/-split-dwarf-output` 
flags are passed down almost blindly to the back-end, whereas for COFF there's 
more logic to determine where the file should be emitted (see 
`CompilerInstance::createOutputFile`). We always need full path names in 
`S_OBJNAME`, whereas (it seems) split DWARF can handle relative paths (for 
example see `llvm-mc -split-dwarf-file`). I think the purpose is also 
different: the .dwo is for immediate debugger consumption, whereas the path in 
`S_OBJNAME` seems to be used more like a global identifier.

Please let me know if you feel this could be done differently.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D43002



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


[PATCH] D43002: Emit S_OBJNAME symbol in CodeView

2020-05-29 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea updated this revision to Diff 267111.
aganea added a comment.

Simplified. Now using `CodeGenOptions` to pass the object filename around.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D43002

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  lld/COFF/LTO.cpp
  lld/COFF/LTO.h
  lld/ELF/LTO.cpp
  lld/wasm/LTO.cpp
  llvm/include/llvm/LTO/LTO.h
  llvm/include/llvm/MC/MCTargetOptions.h
  llvm/include/llvm/Support/ToolOutputFile.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/LTO/Caching.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/test/DebugInfo/COFF/globals.ll
  llvm/test/DebugInfo/COFF/multifunction.ll
  llvm/test/DebugInfo/COFF/pr28747.ll
  llvm/test/DebugInfo/COFF/simple.ll
  llvm/test/DebugInfo/COFF/vframe-fpo.ll
  llvm/test/MC/AArch64/coff-debug.ll
  llvm/test/MC/ARM/coff-debugging-secrel.ll
  llvm/test/MC/COFF/cv-compiler-info.ll
  llvm/tools/llc/llc.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -352,7 +352,7 @@
 std::error_code EC;
 auto S = std::make_unique(Path, EC, sys::fs::OF_None);
 check(EC, Path);
-return std::make_unique(std::move(S));
+return std::make_unique(std::move(S), Path);
   };
 
   auto AddBuffer = [&](size_t Task, std::unique_ptr MB) {
Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -530,6 +530,9 @@
   GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]);
   if (!Out) return 1;
 
+  // Ensure the filename is passed down to CodeViewDebug.
+  Target->Options.MCOptions.COFFOutputFilename = Out->outputFilename();
+
   std::unique_ptr DwoOut;
   if (!SplitDwarfOutputFile.empty()) {
 std::error_code EC;
Index: llvm/test/MC/COFF/cv-compiler-info.ll
===
--- llvm/test/MC/COFF/cv-compiler-info.ll
+++ llvm/test/MC/COFF/cv-compiler-info.ll
@@ -1,4 +1,6 @@
-; RUN: llc -mtriple i686-pc-windows-msvc < %s | FileCheck %s
+; RUN: llc -mtriple i686-pc-windows-msvc < %s | FileCheck %s --check-prefixes=CHECK,STDOUT
+; RUN: llc -mtriple i686-pc-windows-msvc < %s -o %t
+; RUN: FileCheck %s --input-file=%t --check-prefixes=CHECK,FILE
 ; ModuleID = 'D:\src\scopes\foo.cpp'
 source_filename = "D:\5Csrc\5Cscopes\5Cfoo.cpp"
 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
@@ -20,19 +22,23 @@
 ; One .debug$S section should contain an S_COMPILE3 record that identifies the
 ; source language and the version of the compiler based on the DICompileUnit.
 ; CHECK: 	.section	.debug$S,"dr"
+; CHECK:.short  4353# Record kind: S_OBJNAME
+; CHECK-NEXT:   .long   0   # Signature
+; STDOUT-NEXT:  .byte   0   # Object name
+; FILE-NEXT:.asciz	"{{.*}}{{|/}}cv-compiler-info.ll.tmp" # Object name
 ; CHECK: 		.short	4412  # Record kind: S_COMPILE3
-; CHECK: 		.long	1   # Flags and language
-; CHECK: 		.short	7 # CPUType
-; CHECK: 		.short	4 # Frontend version
-; CHECK: 		.short	0
-; CHECK: 		.short	0
-; CHECK: 		.short	0
-; CHECK: 		.short	[[BACKEND_VERSION:[0-9]+]]  # Backend version
-; CHECK: 		.short	0
-; CHECK: 		.short	0
-; CHECK: 		.short	0
-; CHECK: 		.asciz	"clang version 4.0.0 "  # Null-terminated compiler version string
-; CHECK-NOT: .short	4412  # Record kind: S_COMPILE3
+; CHECK-NEXT:   .long	1   # Flags and language
+; CHECK-NEXT: 	.short	7 # CPUType
+; CHECK-NEXT: 	.short	4 # Frontend version
+; CHECK-NEXT: 	.short	0
+; CHECK-NEXT: 	.short	0
+; CHECK-NEXT: 	.short	0
+; CHECK-NEXT: 	.short	[[BACKEND_VERSION:[0-9]+]]  # Backend version
+; CHECK-NEXT: 	.short	0
+; CHECK-NEXT: 	.short	0
+; CHECK-NEXT: 	.short	0
+; CHECK-NEXT: 	.asciz	"clang version 4.0.0 "  # Null-terminated compiler version string
+; CHECK-NOT:.short	4412  # Record kind: S_COMPILE3
 !1 = !DIFile(filename: "D:\5Csrc\5Cscopes\5Cfoo.cpp", directory: "D:\5Csrc\5Cscopes\5Cclang")
 !2 = !{}
 !7 = !{i32 2, !"CodeView", i32 1}
Index: llvm/test/MC/ARM/coff-debugging-secrel.ll
===
--- llvm/test/MC/ARM/coff-debugging-secrel.ll
+++ llvm/test/MC/ARM/coff-debugging-secrel.ll
@@ -42,10 +42,10 @@
 
 ; CHECK-MSVC: Relocations [
 ; CHECK-MSVC:   Section {{.*}} .debug$S {
-; CHECK-MSVC: 0x64 IMAGE_REL_ARM_SECREL function
-; CHECK-MSVC: 0x68 IMAGE_REL_ARM_SECTION function
-; CHECK-MSVC: 0xA0 IMAGE_REL_ARM_SECREL funct

[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Agree with the rationale about moving the names out of `clang::ast_matchers`, 
and the names not being safe to put into `clang::` as-is.

The names are a bit unwieldy though, and I wonder if all of them are patterns 
we want to encourage using widely (at least if so, the names become more 
important).

I'd consider:

- Unittest -> Test (shorter, and unit test is two words, and llvm naming 
conventions notwithstanding many gtests are not unit tests)
- moving into a clang::test namespace instead of prefixing the names
- UnitTestClangArgs --> `std::vector` it's harder to parse but 
much more widely understood

Anyway, don't want to block this, this is an important step to sharing which is 
worthwhile whether the names are my favourite or not :-)




Comment at: clang/unittests/AST/Language.h:23
+
+enum UnittestLanguage {
+  Lang_C,

this enum doesn't seem great: why is the default CXX (presumably) 98? How do 
you get objc++ with 14 features?

(No need to address this now, but it's not clear this is a great API to spread 
more widely. Vs e.g.
```
struct TestLanguage {
  static TestLanguage CXX; // some arbitrary version
  static TestLanguage C;
  
  enum {
CXX98,
CXX11,
  } CXXVersion;

  vector getCommandLineArgs();
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80786



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


[PATCH] D80753: [clang-tidy] remove duplicate fixes of alias checkers

2020-05-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D80753#2061565 , @njames93 wrote:

> It may be worth verifying that the fix-its are identical too, multiple 
> versions of a check could be running with differing options resulting in 
> different fix-its generated, in that case we should let clang-tidy disable 
> any conflicting fixes for us.
>  Side note would it not be nicer to just group the diagnostics into one, 
> thinking either of these ways
>
>   CHECK-MESSAGES: warning: use emplace_back instead of push_back 
> [hicpp-use-emplace, modernize-use-emplace]
>   CHECK-MESSAGES: warning: use emplace_back instead of push_back 
> [hicpp-use-emplace] [modernize-use-emplace]
>
> This would result in cleaner diagnostics emitted and remove the need for that 
> note.


I think this is a nice approach. It also helps the case where a user sees a 
false positive diagnostic and tries to disable it in their config file. Under 
the removing duplicates behavior, the user would have a harder time discovering 
what tests to disable, but under the above approach, they'd have all the 
information they need up front.




Comment at: 
clang-tools-extra/test/clang-tidy/infrastructure/duplicate-fixes-of-alias-checkers.cpp:3
+
+#include 
+namespace std {

Daniel599 wrote:
> Eugene.Zelenko wrote:
> > cstdio. Please also separate with newline.
> I wanted to use cstdio but the test fails with 'file not found', don't know 
> if it's specific on my host, anyway I`ll remove this include (and the printf)
 would have been wrong anyway -- clang-tidy (like clang) tests should 
not include system headers (unless they're faked system header so they're 
consistent across build bots).


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

https://reviews.llvm.org/D80753



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


[PATCH] D80627: [clang-format] Create a python documentation tool to generate a summary of the clang-format status for the whole of the LLVM project

2020-05-29 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked an inline comment as done.
MyDeveloperDay added a comment.

Would something like this be easier to read?

F12027905: image.png 




Comment at: clang/docs/tools/generate_formatted_state.py:52
+path = os.path.relpath(root, LLVM_DIR)
+if "/test/" in path:
+continue

curdeius wrote:
> That doesn't work on Windows because of slashes. You doesn't skip `unittests` 
> (present at least in clang and llvm).
So unit tests is something that I I think needs to be clang-formatted, this is 
because often we are actively editing in there, (I use format on save) and so 
having clean tests is super important

The tests directories normally have 100's of small snippets of code and some 
may even be testing unformatted code deliberately, these files are often made 
once and not continuously edited, (whilst it would be good to have them clean, 
I wanted to give ourselves a fighting chance!)

Point taken about Windows, whilst I develop myself on Windows I use cygwin 
which is why it probably worked.


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

https://reviews.llvm.org/D80627



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


[PATCH] D80198: [clangd] locateMacroAt handles patched macros

2020-05-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG538c2753f3ec: [clangd] locateMacroAt handles patched macros 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80198

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -9,14 +9,19 @@
 #include "Annotations.h"
 #include "Compiler.h"
 #include "Headers.h"
+#include "Hover.h"
 #include "Preamble.h"
+#include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "XRefs.h"
+#include "clang/Format/Format.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "gmock/gmock.h"
@@ -28,6 +33,7 @@
 
 using testing::Contains;
 using testing::Field;
+using testing::Matcher;
 using testing::MatchesRegex;
 
 namespace clang {
@@ -199,7 +205,7 @@
 ADD_FAILURE() << "Failed to build compiler invocation";
 return llvm::None;
   }
-  return ParsedAST::build(testPath("main.cpp"), TU.inputs(), std::move(CI), {},
+  return ParsedAST::build(testPath(TU.Filename), TU.inputs(), std::move(CI), {},
   BaselinePreamble);
 }
 
@@ -228,7 +234,8 @@
 #define BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 2
+#define BAR
 )cpp",
   },
   // multiline macro
@@ -238,7 +245,8 @@
 
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 2
+#define BAR
 )cpp",
   },
   // multiline macro
@@ -248,7 +256,8 @@
 BAR
 [[BAR]])cpp",
   R"cpp(#line 0 ".*main.cpp"
-#define BAR
+#line 3
+#define BAR
 )cpp",
   },
   };
@@ -275,8 +284,10 @@
   )cpp");
 
   llvm::StringLiteral ExpectedPatch(R"cpp(#line 0 ".*main.cpp"
-#define BAR\(X, Y\) X Y
-#define BAR\(X\) X
+#line 2
+#define BAR\(X, Y\) X Y
+#line 3
+#define BAR\(X\) X
 )cpp");
   EXPECT_THAT(getPreamblePatch(Baseline, Modified.code()),
   MatchesRegex(ExpectedPatch.str()));
@@ -286,6 +297,193 @@
   EXPECT_THAT(AST->getDiagnostics(),
   Not(Contains(Field(&Diag::Range, Modified.range();
 }
+
+TEST(PreamblePatchTest, LocateMacroAtWorks) {
+  struct {
+llvm::StringLiteral Baseline;
+llvm::StringLiteral Modified;
+  } Cases[] = {
+  // Addition of new directive
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  // Available inside preamble section
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef $use^FOO)cpp",
+  },
+  // Available after undef, as we don't patch those
+  {
+  "",
+  R"cpp(
+#define $def^FOO
+#undef FOO
+$use^FOO)cpp",
+  },
+  // Identifier on a different line
+  {
+  "",
+  R"cpp(
+#define \
+  $def^FOO
+$use^FOO)cpp",
+  },
+  // In presence of comment tokens
+  {
+  "",
+  R"cpp(
+#\
+  define /* FOO */\
+  /* FOO */ $def^FOO
+$use^FOO)cpp",
+  },
+  // Moved around
+  {
+  "#define FOO",
+  R"cpp(
+#define BAR
+#define $def^FOO
+$use^FOO)cpp",
+  },
+  };
+  for (const auto &Case : Cases) {
+SCOPED_TRACE(Case.Modified);
+llvm::Annotations Modified(Case.Modified);
+auto AST = createPatchedAST(Case.Baseline, Modified.code());
+ASSERT_TRUE(AST);
+
+const auto &SM = AST->getSourceManager();
+auto *MacroTok = AST->getTokens().spelledTokenAt(
+SM.getComposedLoc(SM.getMainFileID(), Modified.point("use")));
+ASSERT_TRUE(MacroTok);
+
+auto FoundMacro = locateMacroAt(*MacroTok, AST->getPreprocessor());
+ASSERT_TRUE(FoundMacro);
+EXPECT_THAT(FoundMacro->Name, "FOO");
+
+auto MacroLoc = FoundMacro->NameLoc;
+EXPECT_EQ(SM.getFileID(MacroLoc), SM.getMainFileID());
+EXPECT_EQ(SM.getFileOffset(MacroLoc), Modified.point("def"));
+  }
+}
+
+TEST(PreamblePatchTest, LocateMacroAtDeletion) {
+  {
+//

[PATCH] D79992: [clangd] Patch PP directives to use stale preambles while building ASTs

2020-05-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfcde3d5b04b6: [clangd] Patch PP directives to use stale 
preambles while building ASTs (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79992

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -26,7 +26,9 @@
 #include 
 #include 
 
+using testing::Contains;
 using testing::Field;
+using testing::MatchesRegex;
 
 namespace clang {
 namespace clangd {
@@ -181,6 +183,109 @@
   ElementsAre(AllOf(Field(&Inclusion::Written, "\"a.h\""),
 Field(&Inclusion::Resolved, testPath("a.h");
 }
+
+llvm::Optional createPatchedAST(llvm::StringRef Baseline,
+   llvm::StringRef Modified) {
+  auto BaselinePreamble = TestTU::withCode(Baseline).preamble();
+  if (!BaselinePreamble) {
+ADD_FAILURE() << "Failed to build baseline preamble";
+return llvm::None;
+  }
+
+  IgnoreDiagnostics Diags;
+  auto TU = TestTU::withCode(Modified);
+  auto CI = buildCompilerInvocation(TU.inputs(), Diags);
+  if (!CI) {
+ADD_FAILURE() << "Failed to build compiler invocation";
+return llvm::None;
+  }
+  return ParsedAST::build(testPath("main.cpp"), TU.inputs(), std::move(CI), {},
+  BaselinePreamble);
+}
+
+std::string getPreamblePatch(llvm::StringRef Baseline,
+ llvm::StringRef Modified) {
+  auto BaselinePreamble = TestTU::withCode(Baseline).preamble();
+  if (!BaselinePreamble) {
+ADD_FAILURE() << "Failed to build baseline preamble";
+return "";
+  }
+  auto TU = TestTU::withCode(Modified);
+  return PreamblePatch::create(testPath("main.cpp"), TU.inputs(),
+   *BaselinePreamble)
+  .text()
+  .str();
+}
+
+TEST(PreamblePatchTest, Define) {
+  // BAR should be defined while parsing the AST.
+  struct {
+llvm::StringLiteral Contents;
+llvm::StringLiteral ExpectedPatch;
+  } Cases[] = {
+  {
+  R"cpp(
+#define BAR
+[[BAR]])cpp",
+  R"cpp(#line 0 ".*main.cpp"
+#define BAR
+)cpp",
+  },
+  // multiline macro
+  {
+  R"cpp(
+#define BAR \
+
+[[BAR]])cpp",
+  R"cpp(#line 0 ".*main.cpp"
+#define BAR
+)cpp",
+  },
+  // multiline macro
+  {
+  R"cpp(
+#define \
+BAR
+[[BAR]])cpp",
+  R"cpp(#line 0 ".*main.cpp"
+#define BAR
+)cpp",
+  },
+  };
+
+  for (const auto &Case : Cases) {
+SCOPED_TRACE(Case.Contents);
+Annotations Modified(Case.Contents);
+EXPECT_THAT(getPreamblePatch("", Modified.code()),
+MatchesRegex(Case.ExpectedPatch.str()));
+
+auto AST = createPatchedAST("", Modified.code());
+ASSERT_TRUE(AST);
+EXPECT_THAT(AST->getDiagnostics(),
+Not(Contains(Field(&Diag::Range, Modified.range();
+  }
+}
+
+TEST(PreamblePatchTest, OrderingPreserved) {
+  llvm::StringLiteral Baseline = "#define BAR(X) X";
+  Annotations Modified(R"cpp(
+#define BAR(X, Y) X Y
+#define BAR(X) X
+[[BAR]](int y);
+  )cpp");
+
+  llvm::StringLiteral ExpectedPatch(R"cpp(#line 0 ".*main.cpp"
+#define BAR\(X, Y\) X Y
+#define BAR\(X\) X
+)cpp");
+  EXPECT_THAT(getPreamblePatch(Baseline, Modified.code()),
+  MatchesRegex(ExpectedPatch.str()));
+
+  auto AST = createPatchedAST(Baseline, Modified.code());
+  ASSERT_TRUE(AST);
+  EXPECT_THAT(AST->getDiagnostics(),
+  Not(Contains(Field(&Diag::Range, Modified.range();
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Preamble.h
===
--- clang-tools-extra/clangd/Preamble.h
+++ clang-tools-extra/clangd/Preamble.h
@@ -119,6 +119,9 @@
   /// using the presumed-location mechanism.
   std::vector preambleIncludes() const;
 
+  /// Returns textual patch contents.
+  llvm::StringRef text() const { return PatchContents; }
+
 private:
   PreamblePatch() = default;
   std::string PatchContents;
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -15,6 +15,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/F

[clang-tools-extra] 1f4ba66 - [clangd] Run PreambleThread in async mode behind a flag

2020-05-29 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-05-29T13:20:46+02:00
New Revision: 1f4ba66ecc877562e75059e32d4c95a67e1fd483

URL: 
https://github.com/llvm/llvm-project/commit/1f4ba66ecc877562e75059e32d4c95a67e1fd483
DIFF: 
https://github.com/llvm/llvm-project/commit/1f4ba66ecc877562e75059e32d4c95a67e1fd483.diff

LOG: [clangd] Run PreambleThread in async mode behind a flag

Summary: Depends on D80198.

This patch implies ASTs might be built with stale preambles without
blocking for a fresh one. It also drops any guarantees on every preamble
version being built. In case of multiple preamble build requests, in
addition to being debounced.

Any preamble requested with a WantDiags::Yes will always be built, this
is ensured by blocking enqueueing of any subsequent reqest.

AST worker will still block for initial preamble to reduce duplicate
work.

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, jfb, 
usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/ParsedAST.h
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/ClangdTests.cpp
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 910c591c1f1e..044b37944b6c 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -114,6 +114,7 @@ ClangdServer::Options ClangdServer::optsForTest() {
   Opts.StorePreamblesInMemory = true;
   Opts.AsyncThreadsCount = 4; // Consistent!
   Opts.TheiaSemanticHighlighting = true;
+  Opts.AsyncPreambleBuilds = true;
   return Opts;
 }
 
@@ -123,6 +124,7 @@ ClangdServer::Options::operator TUScheduler::Options() 
const {
   Opts.RetentionPolicy = RetentionPolicy;
   Opts.StorePreamblesInMemory = StorePreamblesInMemory;
   Opts.UpdateDebounce = UpdateDebounce;
+  Opts.AsyncPreambleBuilds = AsyncPreambleBuilds;
   return Opts;
 }
 

diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index 68344eb8f51e..2c477faecedd 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -97,6 +97,9 @@ class ClangdServer {
 
 /// Cached preambles are potentially large. If false, store them on disk.
 bool StorePreamblesInMemory = true;
+/// Reuse even stale preambles, and rebuild them in the background.
+/// This improves latency at the cost of accuracy.
+bool AsyncPreambleBuilds = false;
 
 /// If true, ClangdServer builds a dynamic in-memory index for symbols in
 /// opened files and uses the index to augment code completion results.

diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 660932a7b259..082c7cae0021 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -551,5 +551,10 @@ ParsedAST::ParsedAST(llvm::StringRef Version,
   assert(this->Action);
 }
 
+llvm::Optional ParsedAST::preambleVersion() const {
+  if (!Preamble)
+return llvm::None;
+  return llvm::StringRef(Preamble->Version);
+}
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/ParsedAST.h 
b/clang-tools-extra/clangd/ParsedAST.h
index d90f77f9263b..c01f1fa0e6d8 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-tools-extra/clangd/ParsedAST.h
@@ -33,6 +33,9 @@
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
 #include 
 #include 
 #include 
@@ -102,6 +105,10 @@ class ParsedAST {
   /// Returns the version of the ParseInputs this AST was built from.
   llvm::StringRef version() const { return Version; }
 
+  /// Returns the version of the ParseInputs used to build Preamble part of 
this
+  /// AST. Might be None if no Preamble is used.
+  llvm::Optional preambleVersion() const;
+
 private:
   ParsedAST(llvm::StringRef Version,
 std::shared_ptr Preamble,

diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index ee6d52188934..b53daa251b03 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -239,10 +239,14 @@ class PreambleThread {
   return;
 }
 {
-  std::lock_guard Lock(Mutex);
-  // If shutdown is issued, don't bother building.
-  if (Done)
-return;
+  std::unique_lock Lock(Mutex);
+  // If NextReq was request

[PATCH] D77658: [analyzer] StdLibraryFunctionsChecker: Add sanity checks for constraints

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 267177.
martong marked 8 inline comments as done.
martong added a comment.

- Add comments, remove auto from 'for' loops, matches -> matchesAndSet


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77658

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -63,10 +63,8 @@
 namespace {
 class StdLibraryFunctionsChecker
 : public Checker {
-  /// Below is a series of typedefs necessary to define function specs.
-  /// We avoid nesting types here because each additional qualifier
-  /// would need to be repeated in every function spec.
-  struct Summary;
+
+  class Summary;
 
   /// Specify how much the analyzer engine should entrust modeling this function
   /// to us. If he doesn't, he performs additional invalidations.
@@ -112,10 +110,27 @@
 virtual ValueConstraintPtr negate() const {
   llvm_unreachable("Not implemented");
 };
+
+// Check whether the constraint is malformed or not. It is malformed if the
+// specified argument has a mismatch with the given FunctionDecl (e.g. the
+// arg number is out-of-range of the function's argument list).
+bool checkValidity(const FunctionDecl *FD) const {
+  const bool ValidArg = ArgN == Ret || ArgN < FD->getNumParams();
+  assert(ValidArg && "Arg out of range!");
+  if (!ValidArg)
+return false;
+  // Subclasses may further refine the validation.
+  return checkSpecificValidity(FD);
+}
 ArgNo getArgNo() const { return ArgN; }
 
   protected:
 ArgNo ArgN; // Argument to which we apply the constraint.
+
+/// Do polymorphic sanity check on the constraint.
+virtual bool checkSpecificValidity(const FunctionDecl *FD) const {
+  return true;
+}
   };
 
   /// Given a range, should the argument stay inside or outside this range?
@@ -165,6 +180,14 @@
   }
   return std::make_shared(Tmp);
 }
+
+bool checkSpecificValidity(const FunctionDecl *FD) const override {
+  const bool ValidArg =
+  getArgType(FD, ArgN)->isIntegralType(FD->getASTContext());
+  assert(ValidArg &&
+ "This constraint should be applied on an integral type");
+  return ValidArg;
+}
   };
 
   class ComparisonConstraint : public ValueConstraint {
@@ -205,17 +228,65 @@
   Tmp.CannotBeNull = !this->CannotBeNull;
   return std::make_shared(Tmp);
 }
+
+bool checkSpecificValidity(const FunctionDecl *FD) const override {
+  const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
+  assert(ValidArg &&
+ "This constraint should be applied only on a pointer type");
+  return ValidArg;
+}
   };
 
   /// The complete list of constraints that defines a single branch.
   typedef std::vector ConstraintSet;
 
   using ArgTypes = std::vector;
+
+  // A placeholder type, we use it whenever we do not care about the concrete
+  // type in a Signature.
+  const QualType Irrelevant{};
+  bool static isIrrelevant(QualType T) { return T.isNull(); }
+
+  // The signature of a function we want to describe with a summary. This is a
+  // concessive signature, meaning there may be irrelevant types in the
+  // signature which we do not check against a function with concrete types.
+  struct Signature {
+const ArgTypes ArgTys;
+const QualType RetTy;
+Signature(ArgTypes ArgTys, QualType RetTy) : ArgTys(ArgTys), RetTy(RetTy) {
+  assertRetTypeSuitableForSignature(RetTy);
+  for (size_t I = 0, E = ArgTys.size(); I != E; ++I) {
+QualType ArgTy = ArgTys[I];
+assertArgTypeSuitableForSignature(ArgTy);
+  }
+}
+bool matches(const FunctionDecl *FD) const;
+
+  private:
+static void assertArgTypeSuitableForSignature(QualType T) {
+  assert((T.isNull() || !T->isVoidType()) &&
+ "We should have no void types in the spec");
+  assert((T.isNull() || T.isCanonical()) &&
+ "We should only have canonical types in the spec");
+}
+static void assertRetTypeSuitableForSignature(QualType T) {
+  assert((T.isNull() || T.isCanonical()) &&
+ "We should only have canonical types in the spec");
+}
+  };
+
+  static QualType getArgType(const FunctionDecl *FD, ArgNo ArgN) {
+assert(FD && "Function must be set");
+QualType T = (ArgN == Ret)
+ ? FD->getReturnType().getCanonicalType()
+ : FD->getParamDecl(ArgN)->getType().getCanonicalType();
+return T;
+  }
+
   using Cases = std::vector;
 
-  /// Includes information about
-  ///   * function prototype (which is necessary to
-  /// ensure we're modeli

[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thank you for working on this.

> moving into a clang::test namespace instead of prefixing the names

+1 for this. We could go even further: `clang::test::ast` or 
`clang::unittest::ast`.




Comment at: clang/unittests/AST/Language.h:23
+
+enum UnittestLanguage {
+  Lang_C,

sammccall wrote:
> this enum doesn't seem great: why is the default CXX (presumably) 98? How do 
> you get objc++ with 14 features?
> 
> (No need to address this now, but it's not clear this is a great API to 
> spread more widely. Vs e.g.
> ```
> struct TestLanguage {
>   static TestLanguage CXX; // some arbitrary version
>   static TestLanguage C;
>   
>   enum {
> CXX98,
> CXX11,
>   } CXXVersion;
> 
>   vector getCommandLineArgs();
> }
> ```
Yes I agree. However, in the ASTImporter tests we didn't need to select 
multiple languages for one test case (yet). I think later if we need that case 
then we can address this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80786



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


[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Just out of curiosity. In what way do you prepare to share these test? For 
which component are you planning to reuse this test infrastructure?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80786



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


[PATCH] D80293: [clangd] Run PreambleThread in async mode behind a flag

2020-05-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1f4ba66ecc87: [clangd] Run PreambleThread in async mode 
behind a flag (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80293

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -21,14 +21,20 @@
 #include "support/Threading.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 namespace clang {
@@ -407,6 +413,7 @@
   int TotalASTReads = 0;
   int TotalPreambleReads = 0;
   int TotalUpdates = 0;
+  llvm::StringMap LatestDiagVersion;
 
   // Run TUScheduler and collect some stats.
   {
@@ -441,15 +448,23 @@
 auto Inputs = getInputs(File, Contents.str());
 {
   WithContextValue WithNonce(NonceKey, ++Nonce);
-  Inputs.Version = std::to_string(Nonce);
+  Inputs.Version = std::to_string(UpdateI);
   updateWithDiags(
   S, File, Inputs, WantDiagnostics::Auto,
-  [File, Nonce, &Mut, &TotalUpdates](std::vector) {
+  [File, Nonce, Version(Inputs.Version), &Mut, &TotalUpdates,
+   &LatestDiagVersion](std::vector) {
 EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce));
 
 std::lock_guard Lock(Mut);
 ++TotalUpdates;
 EXPECT_EQ(File, *TUScheduler::getFileBeingProcessedInContext());
+// Make sure Diags are for a newer version.
+auto It = LatestDiagVersion.try_emplace(File, -1);
+const int PrevVersion = It.first->second;
+int CurVersion;
+ASSERT_TRUE(llvm::to_integer(Version, CurVersion, 10));
+EXPECT_LT(PrevVersion, CurVersion);
+It.first->getValue() = CurVersion;
   });
 }
 {
@@ -494,7 +509,13 @@
   } // TUScheduler destructor waits for all operations to finish.
 
   std::lock_guard Lock(Mut);
-  EXPECT_EQ(TotalUpdates, FilesCount * UpdatesPerFile);
+  // Updates might get coalesced in preamble thread and result in dropping
+  // diagnostics for intermediate snapshots.
+  EXPECT_GE(TotalUpdates, FilesCount);
+  EXPECT_LE(TotalUpdates, FilesCount * UpdatesPerFile);
+  // We should receive diags for last update.
+  for (const auto &Entry : LatestDiagVersion)
+EXPECT_EQ(Entry.second, UpdatesPerFile - 1);
   EXPECT_EQ(TotalASTReads, FilesCount * UpdatesPerFile);
   EXPECT_EQ(TotalPreambleReads, FilesCount * UpdatesPerFile);
 }
@@ -972,6 +993,57 @@
   EXPECT_NEAR(25, Compute({}), 0.01) << "no history -> max";
 }
 
+TEST_F(TUSchedulerTests, AsyncPreambleThread) {
+  // Blocks preamble thread while building preamble with \p BlockVersion until
+  // \p N is notified.
+  class BlockPreambleThread : public ParsingCallbacks {
+  public:
+BlockPreambleThread(llvm::StringRef BlockVersion, Notification &N)
+: BlockVersion(BlockVersion), N(N) {}
+void onPreambleAST(PathRef Path, llvm::StringRef Version, ASTContext &Ctx,
+   std::shared_ptr PP,
+   const CanonicalIncludes &) override {
+  if (Version == BlockVersion)
+N.wait();
+}
+
+  private:
+llvm::StringRef BlockVersion;
+Notification &N;
+  };
+
+  static constexpr llvm::StringLiteral InputsV0 = "v0";
+  static constexpr llvm::StringLiteral InputsV1 = "v1";
+  Notification Ready;
+  TUScheduler S(CDB, optsForTest(),
+std::make_unique(InputsV1, Ready));
+
+  Path File = testPath("foo.cpp");
+  auto PI = getInputs(File, "");
+  PI.Version = InputsV0.str();
+  S.update(File, PI, WantDiagnostics::Auto);
+  S.blockUntilIdle(timeoutSeconds(10));
+
+  // Block preamble builds.
+  PI.Version = InputsV1.str();
+  // Issue second update which will block preamble thread.
+  S.update(File, PI, WantDiagnostics::Auto);
+
+  Notification RunASTAction;
+  // Issue an AST read, which shouldn't be blocked and see latest version of the
+  

[clang-tools-extra] 20b2af3 - [clangd][NFC] Add traces for PreamblePatch::create

2020-05-29 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-05-29T14:00:08+02:00
New Revision: 20b2af3e5559e50d1b5279311c6e5034a2d1928d

URL: 
https://github.com/llvm/llvm-project/commit/20b2af3e5559e50d1b5279311c6e5034a2d1928d
DIFF: 
https://github.com/llvm/llvm-project/commit/20b2af3e5559e50d1b5279311c6e5034a2d1928d.diff

LOG: [clangd][NFC] Add traces for PreamblePatch::create

Added: 


Modified: 
clang-tools-extra/clangd/Preamble.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index 667fa04ff345..d02685f4bf46 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -385,6 +385,8 @@ void escapeBackslashAndQuotes(llvm::StringRef Text, 
llvm::raw_ostream &OS) {
 PreamblePatch PreamblePatch::create(llvm::StringRef FileName,
 const ParseInputs &Modified,
 const PreambleData &Baseline) {
+  trace::Span Tracer("CreatePreamblePatch");
+  SPAN_ATTACH(Tracer, "File", FileName);
   assert(llvm::sys::path::is_absolute(FileName) && "relative FileName!");
   // First scan preprocessor directives in Baseline and Modified. These will be
   // used to figure out newly added directives in Modified. Scanning can fail,



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


[clang] ac1f7ab - [clang] [Darwin] Add reverse mappings for aarch64/aarch64_32 to darwin arch names

2020-05-29 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2020-05-29T15:23:14+03:00
New Revision: ac1f7ab007e347dc4a542aa3415e6378289480f4

URL: 
https://github.com/llvm/llvm-project/commit/ac1f7ab007e347dc4a542aa3415e6378289480f4
DIFF: 
https://github.com/llvm/llvm-project/commit/ac1f7ab007e347dc4a542aa3415e6378289480f4.diff

LOG: [clang] [Darwin] Add reverse mappings for aarch64/aarch64_32 to darwin 
arch names

These are mapped in MachO::getMachOArchName already, but were missing
in ToolChain::getDefaultUniversalArchName.

Having these reverse mapped here fixes weird inconsistencies like
-dumpmachine showing a target triple like "aarch64-apple-darwin",
while "clang -target aarch64-apple-darwin" didn't use to work (ended
up mapped as unknown-apple-ios).

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

Added: 
clang/test/Driver/darwin-arm64-target.c

Modified: 
clang/lib/Driver/ToolChain.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ad66e8e6b5d3..cf04fd07e2a0 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -230,9 +230,12 @@ ToolChain::getTargetAndModeFromProgramName(StringRef PN) {
 StringRef ToolChain::getDefaultUniversalArchName() const {
   // In universal driver terms, the arch name accepted by -arch isn't exactly
   // the same as the ones that appear in the triple. Roughly speaking, this is
-  // an inverse of the darwin::getArchTypeForDarwinArchName() function, but the
-  // only interesting special case is powerpc.
+  // an inverse of the darwin::getArchTypeForDarwinArchName() function.
   switch (Triple.getArch()) {
+  case llvm::Triple::aarch64:
+return "arm64";
+  case llvm::Triple::aarch64_32:
+return "arm64_32";
   case llvm::Triple::ppc:
 return "ppc";
   case llvm::Triple::ppc64:

diff  --git a/clang/test/Driver/darwin-arm64-target.c 
b/clang/test/Driver/darwin-arm64-target.c
new file mode 100644
index ..397afa288360
--- /dev/null
+++ b/clang/test/Driver/darwin-arm64-target.c
@@ -0,0 +1,3 @@
+// RUN: %clang -target aarch64-apple-darwin %s -miphoneos-version-min=8.0 -### 
2>&1 | FileCheck %s
+
+// CHECK: "-cc1"{{.*}} "-triple" "arm64-apple-ios8.0.0"



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


[clang] ab4d02c - [clang] [MinGW] Fix libunwind extension

2020-05-29 Thread Martin Storsjö via cfe-commits

Author: Mateusz Mikuła
Date: 2020-05-29T15:23:14+03:00
New Revision: ab4d02cf265982d4c03123d2f52b9d5ee8df575d

URL: 
https://github.com/llvm/llvm-project/commit/ab4d02cf265982d4c03123d2f52b9d5ee8df575d
DIFF: 
https://github.com/llvm/llvm-project/commit/ab4d02cf265982d4c03123d2f52b9d5ee8df575d.diff

LOG: [clang] [MinGW] Fix libunwind extension

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/compiler-rt-unwind.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 33c43222b5f9..b2c984912154 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1235,7 +1235,14 @@ static void AddUnwindLibrary(const ToolChain &TC, const 
Driver &D,
   case ToolChain::UNW_CompilerRT:
 if (LGT == LibGccType::StaticLibGcc)
   CmdArgs.push_back("-l:libunwind.a");
-else
+else if (TC.getTriple().isOSCygMing()) {
+  if (LGT == LibGccType::SharedLibGcc)
+CmdArgs.push_back("-l:libunwind.dll.a");
+  else
+// Let the linker choose between libunwind.dll.a and libunwind.a
+// depending on what's available, and depending on the -static flag
+CmdArgs.push_back("-lunwind");
+} else
   CmdArgs.push_back("-l:libunwind.so");
 break;
   }

diff  --git a/clang/test/Driver/compiler-rt-unwind.c 
b/clang/test/Driver/compiler-rt-unwind.c
index 652a48c6ad78..e21916d41f93 100644
--- a/clang/test/Driver/compiler-rt-unwind.c
+++ b/clang/test/Driver/compiler-rt-unwind.c
@@ -48,3 +48,26 @@
 // RUN: --gcc-toolchain="" \
 // RUN: FileCheck --input-file=%t.err 
--check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER_RT %s
 // RTLIB-GCC-UNWINDLIB-COMPILER_RT: "{{[.|\\\n]*}}--rtlib=libgcc requires 
--unwindlib=libgcc"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt 
--unwindlib=libunwind \
+// RUN: -shared-libgcc \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck 
--check-prefix=MINGW-RTLIB-COMPILER-RT-SHARED-UNWINDLIB-COMPILER-RT %s
+// MINGW-RTLIB-COMPILER-RT-SHARED-UNWINDLIB-COMPILER-RT: 
"{{.*}}libclang_rt.builtins-x86_64.a"
+// MINGW-RTLIB-COMPILER-RT-SHARED-UNWINDLIB-COMPILER-RT: 
"{{.*}}l:libunwind.dll.a"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt 
--unwindlib=libunwind \
+// RUN: -static-libgcc \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck 
--check-prefix=MINGW-RTLIB-COMPILER-RT-STATIC-UNWINDLIB-COMPILER-RT %s
+// MINGW-RTLIB-COMPILER-RT-STATIC-UNWINDLIB-COMPILER-RT: 
"{{.*}}libclang_rt.builtins-x86_64.a"
+// MINGW-RTLIB-COMPILER-RT-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.a"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt 
--unwindlib=libunwind \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck 
--check-prefix=MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT %s
+// MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: 
"{{.*}}libclang_rt.builtins-x86_64.a"
+// MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind"



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


[PATCH] D77066: [analyzer] ApiModeling: Add buffer size arg constraint

2020-05-29 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a subscriber: balazske.
Szelethus added a comment.
This revision is now accepted and ready to land.

LGTM! I think you could remove the extra parameter, but I don't think this 
warrants another round of review on my end. However, the dynamic size change 
seems very unfamiliar to me. @baloghadamsoftware, @balazske, could you take a 
peek?




Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:237
+  SVal BufDynSize =
+  getDynamicSizeWithOffset(State, BufV, C.getSValBuilder());
+

You can retrieve `SValBuilder` from `ProgramState`: 
`State->getStateManager().getSValBuilder()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77066



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


[PATCH] D78933: [analyzer] RangeConstraintManager optimizations in comparison expressions

2020-05-29 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 267185.
ASDenysPetrov added a comment.

Updated. Rebased with D79232 .
@vsavchenko, @NoQ, @xazax.hun  please look.


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

https://reviews.llvm.org/D78933

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constraint_manager_conditions.cpp

Index: clang/test/Analysis/constraint_manager_conditions.cpp
===
--- /dev/null
+++ clang/test/Analysis/constraint_manager_conditions.cpp
@@ -0,0 +1,213 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(int);
+
+void comparison_lt(int x, int y) {
+  if (x < y) {
+clang_analyzer_eval(x < y);  // expected-warning{{TRUE}}
+clang_analyzer_eval(y > x);  // expected-warning{{TRUE}}
+clang_analyzer_eval(x > y);  // expected-warning{{FALSE}}
+clang_analyzer_eval(y < x);  // expected-warning{{FALSE}}
+clang_analyzer_eval(x <= y); // expected-warning{{TRUE}}
+clang_analyzer_eval(y >= x); // expected-warning{{TRUE}}
+clang_analyzer_eval(x >= y); // expected-warning{{FALSE}}
+clang_analyzer_eval(y <= x); // expected-warning{{FALSE}}
+clang_analyzer_eval(x == y); // expected-warning{{FALSE}}
+clang_analyzer_eval(y == x); // expected-warning{{FALSE}}
+clang_analyzer_eval(x != y); // expected-warning{{TRUE}}
+clang_analyzer_eval(y != x); // expected-warning{{TRUE}}
+  } else {
+clang_analyzer_eval(x < y);  // expected-warning{{FALSE}}
+clang_analyzer_eval(y > x);  // expected-warning{{FALSE}}
+clang_analyzer_eval(x > y);  // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y < x);  // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(x <= y); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y >= x); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(x >= y); // expected-warning{{TRUE}}
+clang_analyzer_eval(y <= x); // expected-warning{{TRUE}}
+clang_analyzer_eval(x == y); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y == x); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(x != y); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y != x); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+  }
+}
+
+void comparison_gt(int x, int y) {
+  if (x > y) {
+clang_analyzer_eval(x < y);  // expected-warning{{FALSE}}
+clang_analyzer_eval(y > x);  // expected-warning{{FALSE}}
+clang_analyzer_eval(x > y);  // expected-warning{{TRUE}}
+clang_analyzer_eval(y < x);  // expected-warning{{TRUE}}
+clang_analyzer_eval(x <= y); // expected-warning{{FALSE}}
+clang_analyzer_eval(y >= x); // expected-warning{{FALSE}}
+clang_analyzer_eval(x >= y); // expected-warning{{TRUE}}
+clang_analyzer_eval(y <= x); // expected-warning{{TRUE}}
+clang_analyzer_eval(x == y); // expected-warning{{FALSE}}
+clang_analyzer_eval(y == x); // expected-warning{{FALSE}}
+clang_analyzer_eval(x != y); // expected-warning{{TRUE}}
+clang_analyzer_eval(y != x); // expected-warning{{TRUE}}
+  } else {
+clang_analyzer_eval(x < y);  // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y > x);  // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(x > y);  // expected-warning{{FALSE}}
+clang_analyzer_eval(y < x);  // expected-warning{{FALSE}}
+clang_analyzer_eval(x <= y); // expected-warning{{TRUE}}
+clang_analyzer_eval(y >= x); // expected-warning{{TRUE}}
+clang_analyzer_eval(x >= y); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y <= x); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(x == y); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y == x); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(x != y); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y != x); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+  }
+}
+
+void comparison_le(int x, int y) {
+  if (x <= y) {
+clang_analyzer_eval(x < y);  // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y > x);  // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(x > y);  // expected-warning{{FALSE}}
+clang_analyzer_eval(y < x);  // expected-warning{{FALSE}}
+clang_analyzer_eval(x <= y); // expected-warning{{TRUE}}
+clang_analyzer_eval(y >= x); // expected-warning{{TRUE}}
+clang_analyzer_eval(x >= y); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(y <= x); // expected-warning{{TRUE}} expected-warning{{FALSE}}
+clang_analyzer_eval(x == y); // ex

[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 267187.
gribozavr added a comment.

Addressed review feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80786

Files:
  clang/unittests/AST/ASTImporterFixtures.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterODRStrategiesTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/ASTImporterVisibilityTest.cpp
  clang/unittests/AST/Language.cpp
  clang/unittests/AST/Language.h
  clang/unittests/AST/MatchVerifier.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -23,12 +23,13 @@
   // snippets. To determine the returned node, a separate matcher is specified
   // for both snippets. The first matching node is returned.
   template 
-  std::tuple makeDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang,
-  const MatcherType &Matcher0, const MatcherType &Matcher1) {
+  std::tuple
+  makeDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+TestLanguage Lang, const MatcherType &Matcher0,
+const MatcherType &Matcher1) {
 this->Code0 = SrcCode0;
 this->Code1 = SrcCode1;
-ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+std::vector Args = getCommandLineArgsForTesting(Lang);
 
 const char *const InputFileName = "input.cc";
 
@@ -43,11 +44,12 @@
 return std::make_tuple(D0, D1);
   }
 
-  std::tuple makeTuDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang) {
+  std::tuple
+  makeTuDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+  TestLanguage Lang) {
 this->Code0 = SrcCode0;
 this->Code1 = SrcCode1;
-ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+std::vector Args = getCommandLineArgsForTesting(Lang);
 
 const char *const InputFileName = "input.cc";
 
@@ -61,9 +63,9 @@
   // Get a pair of node pointers into the synthesized AST from the given code
   // snippets. The same matcher is used for both snippets.
   template 
-  std::tuple makeDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang,
-  const MatcherType &AMatcher) {
+  std::tuple
+  makeDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+TestLanguage Lang, const MatcherType &AMatcher) {
 return makeDecls(
   SrcCode0, SrcCode1, Lang, AMatcher, AMatcher);
   }
@@ -71,9 +73,9 @@
   // Get a pair of Decl pointers to the synthesized declarations from the given
   // code snippets. We search for the first NamedDecl with given name in both
   // snippets.
-  std::tuple makeNamedDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1,
-  Language Lang, const char *const Identifier = "foo") {
+  std::tuple
+  makeNamedDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+ TestLanguage Lang, const char *const Identifier = "foo") {
 auto Matcher = namedDecl(hasName(Identifier));
 return makeDecls(SrcCode0, SrcCode1, Lang, Matcher);
   }
Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -41,17 +41,15 @@
 
   template 
   testing::AssertionResult match(const std::string &Code,
- const MatcherType &AMatcher,
- Language L) {
+ const MatcherType &AMatcher, TestLanguage L) {
 std::vector Args;
 return match(Code, AMatcher, Args, L);
   }
 
   template 
-  testing::AssertionResult match(const std::string &Code,
- const MatcherType &AMatcher,
- std::vector& Args,
- Language L);
+  testing::AssertionResult
+  match(const std::string &Code, const MatcherType &AMatcher,
+std::vector &Args, TestLanguage L);
 
   template 
   testing::AssertionResult match(const Decl *D, const MatcherType &AMatcher);
@@ -77,10 +75,12 @@
 
 /// \brief Runs a matcher over some code, and returns the result of the
 /// verifier for the matched node.
-template  template 
-testing::AssertionResult MatchVerifier::match(
-const std::string &Code, const MatcherType &AMatcher,
-std::vector& Args, Language L) {
+template 
+template 
+testing::AssertionResult
+MatchVerifier::match(const std::string &Code,
+   const MatcherType &AMatcher,
+   std::vector &Args, TestLanguage L) {
   MatchFinder Finder;
   Finder.addMatcher(AMatcher.bind(""), this);
   std::unique_ptr Factory(
Index

[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

In D80786#2062557 , @sammccall wrote:

> - Unittest -> Test (shorter, and unit test is two words, and llvm naming 
> conventions notwithstanding many gtests are not unit tests)


Done.

> - UnitTestClangArgs --> `std::vector` it's harder to parse but 
> much more widely understood

Done. I also wanted to expand the typedef, but didn't do it because I didn't 
want to make this change controversial.

> - moving into a clang::test namespace instead of prefixing the names

Nested namespaces with names that can appear in other namespaces ("test") are a 
trap in C++: https://abseil.io/tips/130. This might not be a problem within the 
llvm-project.git code itself, but Clang is used as a library in a lot of other 
software.




Comment at: clang/unittests/AST/Language.h:23
+
+enum UnittestLanguage {
+  Lang_C,

martong wrote:
> sammccall wrote:
> > this enum doesn't seem great: why is the default CXX (presumably) 98? How 
> > do you get objc++ with 14 features?
> > 
> > (No need to address this now, but it's not clear this is a great API to 
> > spread more widely. Vs e.g.
> > ```
> > struct TestLanguage {
> >   static TestLanguage CXX; // some arbitrary version
> >   static TestLanguage C;
> >   
> >   enum {
> > CXX98,
> > CXX11,
> >   } CXXVersion;
> > 
> >   vector getCommandLineArgs();
> > }
> > ```
> Yes I agree. However, in the ASTImporter tests we didn't need to select 
> multiple languages for one test case (yet). I think later if we need that 
> case then we can address this.
Oh I absolutely agree -- I think we need a way to describe a lot more than just 
the language standard. Feature flags (like Objective-C, delayed template 
parsing etc.) should compose with each other.

I'm thinking it should be somewhat similar to the LangOptions struct, but be 
much friendlier for unit tests, the testing library should provide a bunch of 
presets that imitate important platforms (for example, 32-bit Linux, 64-bit 
Linux, macOS, iOS, Windows with delayed template parsing etc.)

However, we have to take this one step at a time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80786



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


[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 267188.
gribozavr added a comment.

Changed description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80786

Files:
  clang/unittests/AST/ASTImporterFixtures.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterODRStrategiesTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/ASTImporterVisibilityTest.cpp
  clang/unittests/AST/Language.cpp
  clang/unittests/AST/Language.h
  clang/unittests/AST/MatchVerifier.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -23,12 +23,13 @@
   // snippets. To determine the returned node, a separate matcher is specified
   // for both snippets. The first matching node is returned.
   template 
-  std::tuple makeDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang,
-  const MatcherType &Matcher0, const MatcherType &Matcher1) {
+  std::tuple
+  makeDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+TestLanguage Lang, const MatcherType &Matcher0,
+const MatcherType &Matcher1) {
 this->Code0 = SrcCode0;
 this->Code1 = SrcCode1;
-ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+std::vector Args = getCommandLineArgsForTesting(Lang);
 
 const char *const InputFileName = "input.cc";
 
@@ -43,11 +44,12 @@
 return std::make_tuple(D0, D1);
   }
 
-  std::tuple makeTuDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang) {
+  std::tuple
+  makeTuDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+  TestLanguage Lang) {
 this->Code0 = SrcCode0;
 this->Code1 = SrcCode1;
-ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+std::vector Args = getCommandLineArgsForTesting(Lang);
 
 const char *const InputFileName = "input.cc";
 
@@ -61,9 +63,9 @@
   // Get a pair of node pointers into the synthesized AST from the given code
   // snippets. The same matcher is used for both snippets.
   template 
-  std::tuple makeDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang,
-  const MatcherType &AMatcher) {
+  std::tuple
+  makeDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+TestLanguage Lang, const MatcherType &AMatcher) {
 return makeDecls(
   SrcCode0, SrcCode1, Lang, AMatcher, AMatcher);
   }
@@ -71,9 +73,9 @@
   // Get a pair of Decl pointers to the synthesized declarations from the given
   // code snippets. We search for the first NamedDecl with given name in both
   // snippets.
-  std::tuple makeNamedDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1,
-  Language Lang, const char *const Identifier = "foo") {
+  std::tuple
+  makeNamedDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+ TestLanguage Lang, const char *const Identifier = "foo") {
 auto Matcher = namedDecl(hasName(Identifier));
 return makeDecls(SrcCode0, SrcCode1, Lang, Matcher);
   }
Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -41,17 +41,15 @@
 
   template 
   testing::AssertionResult match(const std::string &Code,
- const MatcherType &AMatcher,
- Language L) {
+ const MatcherType &AMatcher, TestLanguage L) {
 std::vector Args;
 return match(Code, AMatcher, Args, L);
   }
 
   template 
-  testing::AssertionResult match(const std::string &Code,
- const MatcherType &AMatcher,
- std::vector& Args,
- Language L);
+  testing::AssertionResult
+  match(const std::string &Code, const MatcherType &AMatcher,
+std::vector &Args, TestLanguage L);
 
   template 
   testing::AssertionResult match(const Decl *D, const MatcherType &AMatcher);
@@ -77,10 +75,12 @@
 
 /// \brief Runs a matcher over some code, and returns the result of the
 /// verifier for the matched node.
-template  template 
-testing::AssertionResult MatchVerifier::match(
-const std::string &Code, const MatcherType &AMatcher,
-std::vector& Args, Language L) {
+template 
+template 
+testing::AssertionResult
+MatchVerifier::match(const std::string &Code,
+   const MatcherType &AMatcher,
+   std::vector &Args, TestLanguage L) {
   MatchFinder Finder;
   Finder.addMatcher(AMatcher.bind(""), this);
   std::unique_ptr Factory(
Index: clan

[PATCH] D79995: [clang] [MinGW] Fix libunwind extension

2020-05-29 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGab4d02cf2659: [clang] [MinGW] Fix libunwind extension 
(authored by mati865, committed by mstorsjo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79995

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/compiler-rt-unwind.c


Index: clang/test/Driver/compiler-rt-unwind.c
===
--- clang/test/Driver/compiler-rt-unwind.c
+++ clang/test/Driver/compiler-rt-unwind.c
@@ -48,3 +48,26 @@
 // RUN: --gcc-toolchain="" \
 // RUN: FileCheck --input-file=%t.err 
--check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER_RT %s
 // RTLIB-GCC-UNWINDLIB-COMPILER_RT: "{{[.|\\\n]*}}--rtlib=libgcc requires 
--unwindlib=libgcc"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt 
--unwindlib=libunwind \
+// RUN: -shared-libgcc \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck 
--check-prefix=MINGW-RTLIB-COMPILER-RT-SHARED-UNWINDLIB-COMPILER-RT %s
+// MINGW-RTLIB-COMPILER-RT-SHARED-UNWINDLIB-COMPILER-RT: 
"{{.*}}libclang_rt.builtins-x86_64.a"
+// MINGW-RTLIB-COMPILER-RT-SHARED-UNWINDLIB-COMPILER-RT: 
"{{.*}}l:libunwind.dll.a"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt 
--unwindlib=libunwind \
+// RUN: -static-libgcc \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck 
--check-prefix=MINGW-RTLIB-COMPILER-RT-STATIC-UNWINDLIB-COMPILER-RT %s
+// MINGW-RTLIB-COMPILER-RT-STATIC-UNWINDLIB-COMPILER-RT: 
"{{.*}}libclang_rt.builtins-x86_64.a"
+// MINGW-RTLIB-COMPILER-RT-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.a"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt 
--unwindlib=libunwind \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck 
--check-prefix=MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT %s
+// MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: 
"{{.*}}libclang_rt.builtins-x86_64.a"
+// MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1235,7 +1235,14 @@
   case ToolChain::UNW_CompilerRT:
 if (LGT == LibGccType::StaticLibGcc)
   CmdArgs.push_back("-l:libunwind.a");
-else
+else if (TC.getTriple().isOSCygMing()) {
+  if (LGT == LibGccType::SharedLibGcc)
+CmdArgs.push_back("-l:libunwind.dll.a");
+  else
+// Let the linker choose between libunwind.dll.a and libunwind.a
+// depending on what's available, and depending on the -static flag
+CmdArgs.push_back("-lunwind");
+} else
   CmdArgs.push_back("-l:libunwind.so");
 break;
   }


Index: clang/test/Driver/compiler-rt-unwind.c
===
--- clang/test/Driver/compiler-rt-unwind.c
+++ clang/test/Driver/compiler-rt-unwind.c
@@ -48,3 +48,26 @@
 // RUN: --gcc-toolchain="" \
 // RUN: FileCheck --input-file=%t.err --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER_RT %s
 // RTLIB-GCC-UNWINDLIB-COMPILER_RT: "{{[.|\\\n]*}}--rtlib=libgcc requires --unwindlib=libgcc"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt --unwindlib=libunwind \
+// RUN: -shared-libgcc \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=MINGW-RTLIB-COMPILER-RT-SHARED-UNWINDLIB-COMPILER-RT %s
+// MINGW-RTLIB-COMPILER-RT-SHARED-UNWINDLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a"
+// MINGW-RTLIB-COMPILER-RT-SHARED-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.dll.a"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt --unwindlib=libunwind \
+// RUN: -static-libgcc \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=MINGW-RTLIB-COMPILER-RT-STATIC-UNWINDLIB-COMPILER-RT %s
+// MINGW-RTLIB-COMPILER-RT-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a"
+// MINGW-RTLIB-COMPILER-RT-STATIC-UNWINDLIB-COMPILER-RT: "{{.*}}l:libunwind.a"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-w64-mingw32 -rtlib=compiler-rt --unwindlib=libunwind \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT %s
+// MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a"
+// MINGW-RTLIB-COMPILER-RT-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp

[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

In D80786#2062634 , @martong wrote:

> Just out of curiosity. In what way do you prepare to share these test? For 
> which component are you planning to reuse this test infrastructure?


Tests in clang/unittests/Tooling/Syntax/TreeTest.cpp have similar needs. In 
fact, I think pretty much all Clang unittests that start by parsing a string of 
source code into a translation unit need such infrastructure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80786



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


[PATCH] D79117: [clang] [Darwin] Add reverse mappings for aarch64/aarch64_32 to darwin arch names

2020-05-29 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac1f7ab007e3: [clang] [Darwin] Add reverse mappings for 
aarch64/aarch64_32 to darwin arch… (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79117

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/darwin-arm64-target.c


Index: clang/test/Driver/darwin-arm64-target.c
===
--- /dev/null
+++ clang/test/Driver/darwin-arm64-target.c
@@ -0,0 +1,3 @@
+// RUN: %clang -target aarch64-apple-darwin %s -miphoneos-version-min=8.0 -### 
2>&1 | FileCheck %s
+
+// CHECK: "-cc1"{{.*}} "-triple" "arm64-apple-ios8.0.0"
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -230,9 +230,12 @@
 StringRef ToolChain::getDefaultUniversalArchName() const {
   // In universal driver terms, the arch name accepted by -arch isn't exactly
   // the same as the ones that appear in the triple. Roughly speaking, this is
-  // an inverse of the darwin::getArchTypeForDarwinArchName() function, but the
-  // only interesting special case is powerpc.
+  // an inverse of the darwin::getArchTypeForDarwinArchName() function.
   switch (Triple.getArch()) {
+  case llvm::Triple::aarch64:
+return "arm64";
+  case llvm::Triple::aarch64_32:
+return "arm64_32";
   case llvm::Triple::ppc:
 return "ppc";
   case llvm::Triple::ppc64:


Index: clang/test/Driver/darwin-arm64-target.c
===
--- /dev/null
+++ clang/test/Driver/darwin-arm64-target.c
@@ -0,0 +1,3 @@
+// RUN: %clang -target aarch64-apple-darwin %s -miphoneos-version-min=8.0 -### 2>&1 | FileCheck %s
+
+// CHECK: "-cc1"{{.*}} "-triple" "arm64-apple-ios8.0.0"
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -230,9 +230,12 @@
 StringRef ToolChain::getDefaultUniversalArchName() const {
   // In universal driver terms, the arch name accepted by -arch isn't exactly
   // the same as the ones that appear in the triple. Roughly speaking, this is
-  // an inverse of the darwin::getArchTypeForDarwinArchName() function, but the
-  // only interesting special case is powerpc.
+  // an inverse of the darwin::getArchTypeForDarwinArchName() function.
   switch (Triple.getArch()) {
+  case llvm::Triple::aarch64:
+return "arm64";
+  case llvm::Triple::aarch64_32:
+return "arm64_32";
   case llvm::Triple::ppc:
 return "ppc";
   case llvm::Triple::ppc64:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d4ef654 - Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-05-29T14:25:20+02:00
New Revision: d4ef654673a921878ba5aedb9725b2ac32681f01

URL: 
https://github.com/llvm/llvm-project/commit/d4ef654673a921878ba5aedb9725b2ac32681f01
DIFF: 
https://github.com/llvm/llvm-project/commit/d4ef654673a921878ba5aedb9725b2ac32681f01.diff

LOG: Rename APIs in unittests/AST/Language.h in preparation to share them

Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.

Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.

Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".

Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").

Reviewers: shafik, rengolin, sammccall

Reviewed By: sammccall

Subscribers: gribozavr2, sammccall, martong, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/AST/ASTImporterFixtures.cpp
clang/unittests/AST/ASTImporterFixtures.h
clang/unittests/AST/ASTImporterODRStrategiesTest.cpp
clang/unittests/AST/ASTImporterTest.cpp
clang/unittests/AST/ASTImporterVisibilityTest.cpp
clang/unittests/AST/Language.cpp
clang/unittests/AST/Language.h
clang/unittests/AST/MatchVerifier.h
clang/unittests/AST/StructuralEquivalenceTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/ASTImporterFixtures.cpp 
b/clang/unittests/AST/ASTImporterFixtures.cpp
index 36732ee712f3..897b370dd3cd 100644
--- a/clang/unittests/AST/ASTImporterFixtures.cpp
+++ b/clang/unittests/AST/ASTImporterFixtures.cpp
@@ -38,7 +38,8 @@ void createVirtualFileIfNeeded(ASTUnit *ToAST, StringRef 
FileName,
llvm::MemoryBuffer::getMemBuffer(Code));
 }
 
-ASTImporterTestBase::TU::TU(StringRef Code, StringRef FileName, ArgVector Args,
+ASTImporterTestBase::TU::TU(StringRef Code, StringRef FileName,
+std::vector Args,
 ImporterConstructor C,
 ASTImporter::ODRHandlingType ODRHandling)
 : Code(std::string(Code)), FileName(std::string(FileName)),
@@ -112,11 +113,12 @@ void 
ASTImporterTestBase::lazyInitSharedState(TranslationUnitDecl *ToTU) {
 SharedStatePtr = std::make_shared(*ToTU);
 }
 
-void ASTImporterTestBase::lazyInitToAST(Language ToLang, StringRef ToSrcCode,
+void ASTImporterTestBase::lazyInitToAST(TestLanguage ToLang,
+StringRef ToSrcCode,
 StringRef FileName) {
   if (ToAST)
 return;
-  ArgVector ToArgs = getArgVectorForLanguage(ToLang);
+  std::vector ToArgs = getCommandLineArgsForLanguage(ToLang);
   // Source code must be a valid live buffer through the tests lifetime.
   ToCode = std::string(ToSrcCode);
   // Build the AST from an empty file.
@@ -136,12 +138,11 @@ ASTImporterTestBase::TU 
*ASTImporterTestBase::findFromTU(Decl *From) {
   return &*It;
 }
 
-std::tuple
-ASTImporterTestBase::getImportedDecl(StringRef FromSrcCode, Language FromLang,
- StringRef ToSrcCode, Language ToLang,
- StringRef Identifier) {
-  ArgVector FromArgs = getArgVectorForLanguage(FromLang),
-ToArgs = getArgVectorForLanguage(ToLang);
+std::tuple ASTImporterTestBase::getImportedDecl(
+StringRef FromSrcCode, TestLanguage FromLang, StringRef ToSrcCode,
+TestLanguage ToLang, StringRef Identifier) {
+  std::vector FromArgs = getCommandLineArgsForLanguage(FromLang);
+  std::vector ToArgs = getCommandLineArgsForLanguage(ToLang);
 
   FromTUs.emplace_back(FromSrcCode, InputFileName, FromArgs, Creator,
ODRHandling);
@@ -170,13 +171,13 @@ ASTImporterTestBase::getImportedDecl(StringRef 
FromSrcCode, Language FromLang,
 }
 
 TranslationUnitDecl *ASTImporterTestBase::getTuDecl(StringRef SrcCode,
-Language Lang,
+TestLanguage Lang,
 StringRef FileName) {
   assert(llvm::find_if(FromTUs, [FileName](const TU &E) {
return E.FileName == FileName;
  }) == FromTUs.end());
 
-  ArgVector Args = getArgVectorForLanguage(Lang);
+  std::vector Args = getCommandLineArgsForLanguage(Lang);
   FromTUs.emplace_back(SrcCode, FileName, Args, Creator, ODRHandling);
   TU &Tu = FromTUs.back();
 
@@ -184

[PATCH] D80781: [clang] Always allow including builtin headers in [no_undeclared_headers] modules.

2020-05-29 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

Temporarily retracting from review as I've realized there's another case I need 
to take care of.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80781



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


[PATCH] D80366: [Analyzer] Add `getReturnValueUnderConstruction()` to `CallEvent`

2020-05-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:112
 
+Optional ExprEngine::retrieveFromConstructionContext(
+ProgramStateRef State, const LocationContext *LCtx,

baloghadamsoftware wrote:
> martong wrote:
> > baloghadamsoftware wrote:
> > > NoQ wrote:
> > > > balazske wrote:
> > > > > baloghadamsoftware wrote:
> > > > > > baloghadamsoftware wrote:
> > > > > > > baloghadamsoftware wrote:
> > > > > > > > baloghadamsoftware wrote:
> > > > > > > > > NoQ wrote:
> > > > > > > > > > baloghadamsoftware wrote:
> > > > > > > > > > > NoQ wrote:
> > > > > > > > > > > > Please instead re-use the code that computes the object 
> > > > > > > > > > > > under construction. That'll save you ~50 lines of code 
> > > > > > > > > > > > and will be more future-proof (eg., standalone 
> > > > > > > > > > > > temporaries without destructor technically have a 
> > > > > > > > > > > > construction context with 0 items so when we implement 
> > > > > > > > > > > > them correctly your procedure will stop working).
> > > > > > > > > > > That was so my first thought. However, 
> > > > > > > > > > > `handleConstructionContext()` is private and non-static. 
> > > > > > > > > > > Now I tried to merge the two methods: if the value is 
> > > > > > > > > > > already in the construction context, we return it, if not 
> > > > > > > > > > > then we add it. Is this what you suggest? Or did I 
> > > > > > > > > > > misunderstand you? At the very beginning I tried to 
> > > > > > > > > > > simply use `handleConstructionContext()`, but it asserted 
> > > > > > > > > > > because the value was already in the map.
> > > > > > > > > > I'd like to preserve the assertion that 
> > > > > > > > > > objects-under-construction are never filled twice; it's a 
> > > > > > > > > > very useful sanity check. What you need in your checker is 
> > > > > > > > > > a function that computes object-under-construction but 
> > > > > > > > > > doesn't put it into the objects-under-construction map. So 
> > > > > > > > > > you have to separate the computation from filling in the 
> > > > > > > > > > state.
> > > > > > > > > OK, so I (fortunately) misundertood you. Thus I should 
> > > > > > > > > refactor this function to a calculation and a storing part?
> > > > > > > > OK, I see what you are speaking about, but I have no idea how 
> > > > > > > > to do it properly. The problem is that the control logic of 
> > > > > > > > filling in the state also depends on the kind of the 
> > > > > > > > construction context. For some kinds we do not fill at all. 
> > > > > > > > Every way I try it becomes more complex and less correct:
> > > > > > > > 
> > > > > > > > 1) `NewAllocatedObjectKind`: we do not add this to the state, 
> > > > > > > > we only retrieve the original.
> > > > > > > > 2) `SimpleReturnedValueKind` and 
> > > > > > > > `CXX17ElidedCopyReturnedValueKind`: depending on whether we are 
> > > > > > > > in top frame we handle this case recursively or we do not fill 
> > > > > > > > at all, just return the value. What is the construction context 
> > > > > > > > item here? Maybe the `ReturnStmt`?
> > > > > > > > 3) `ElidedTemporaryObjectKind`: this is the most problematic: 
> > > > > > > > we first handle it recursively for the construction context 
> > > > > > > > after elision, then we also fill it for the elided temporary 
> > > > > > > > object construction context as well.
> > > > > > > > 
> > > > > > > > The only thing I can (maybe) do is to retrieve the construction 
> > > > > > > > context item. But then the switch is still duplicated for 
> > > > > > > > filling, because of the different control logic for different 
> > > > > > > > construction context kinds.
> > > > > > > > The only thing I can (maybe) do is to retrieve the construction 
> > > > > > > > context item.
> > > > > > > 
> > > > > > > This does not help even for retrieving the value, because its 
> > > > > > > control logic also depends on the construction context kind. If I 
> > > > > > > do it, it will be code triplication instead of duplication and 
> > > > > > > results in a code that is worse to understand than the current 
> > > > > > > one.
> > > > > > > 
> > > > > > > 
> > > > > > > Please instead re-use the code that computes the object under 
> > > > > > > construction. That'll save you ~50 lines of code and will be more 
> > > > > > > future-proof (eg., standalone temporaries without destructor 
> > > > > > > technically have a construction context with 0 items so when we 
> > > > > > > implement them correctly your procedure will stop working).
> > > > > > 
> > > > > > Any solution I can come up with rather adds 100 to 150 lines to the 
> > > > > > code instead of saving 50. For retrieving we only have to determine 
> > > > > > the construction context item (the key). For storing we also have 
> > > > > > to calculate the value. It sounds good to calculate these things in 
> > > > > > separate functions and

[PATCH] D80791: [AArch64] Generate .note.gnu.property based on module flags.

2020-05-29 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss created this revision.
danielkiss added reviewers: tamas.petz, chill.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, kristof.beyls.
Herald added projects: clang, LLVM.

Generate .note.gnu.property for PAC and BTI if the compile unit is
compiled with -mbranch-protection. 
It is valid use case to have a non-bti protected function therefore the note 
shouldn't be
removed in that case. In this case only the direct call is valid to the 
function.
This behaviour matches with gcc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80791

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
  llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-0.ll
  llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-1.ll
  llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-2.ll
  llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-3.ll
  llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-4.ll
  llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-5.ll
  llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-6.ll
  llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-7.ll
  llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-8.ll

Index: llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-8.ll
===
--- llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-8.ll
+++ /dev/null
@@ -1,21 +0,0 @@
-; RUN: llc -mtriple=aarch64-linux %s   -o - | \
-; RUN:   FileCheck %s --check-prefix=ASM
-; RUN: llc -mtriple=aarch64-linux %s -filetype=obj -o - | \
-; RUN:   llvm-readelf --notes | FileCheck %s --check-prefix=OBJ
-
-define dso_local i32 @f() #0 {
-entry:
-  %r = tail call i32 @g()
-  ret i32 %r
-}
-
-declare dso_local i32 @g()
-
-attributes #0 = { "branch-target-enforcement" }
-
-; Declarations don't prevent setting BTI
-; ASM:	.word	3221225472
-; ASM-NEXT:	.word	4
-; ASM-NEXT:	.word	1
-
-; OBJ: Properties: aarch64 feature: BTI
Index: llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-7.ll
===
--- llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-7.ll
+++ /dev/null
@@ -1,23 +0,0 @@
-; RUN: llc -mtriple=aarch64-linux %s   -o - 2>&1 | \
-; RUN:   FileCheck %s --check-prefix=ASM
-; RUN: llc -mtriple=aarch64-linux %s -filetype=obj -o -  |  \
-; RUN:   llvm-readelf -S | FileCheck %s --check-prefix=OBJ
-
-define dso_local i32 @f() #0 {
-entry:
-  ret i32 0
-}
-
-define dso_local i32 @g() #1 {
-entry:
-  ret i32 0
-}
-
-attributes #0 = { "sign-return-address"="non-leaf" }
-
-attributes #1 = { "branch-target-enforcement" }
-
-; No common attribute, no note section
-; ASM: warning: not setting BTI in feature flags
-; ASM-NOT: .note.gnu.property
-; OBJ-NOT: .note.gnu.property
Index: llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-6.ll
===
--- llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-6.ll
+++ /dev/null
@@ -1,22 +0,0 @@
-; RUN: llc -mtriple=aarch64-linux %s   -o - | \
-; RUN:   FileCheck %s --check-prefix=ASM
-; RUN: llc -mtriple=aarch64-linux %s -filetype=obj -o - |  \
-; RUN:   llvm-readelf -S | FileCheck %s --check-prefix=OBJ
-
-define dso_local i32 @f() #0 {
-entry:
-  ret i32 0
-}
-
-define dso_local i32 @g() #1 {
-entry:
-  ret i32 0
-}
-
-attributes #0 = { "sign-return-address"="non-leaf" }
-
-attributes #1 = { "sign-return-address"="none" }
-
-; No common attribute, no note section
-; ASM-NOT: .note.gnu.property
-; OBJ-NOT: .note.gnu.property
Index: llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-5.ll
===
--- llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-5.ll
+++ /dev/null
@@ -1,26 +0,0 @@
-; RUN: llc -mtriple=aarch64-linux %s   -o - 2>&1 | \
-; RUN:   FileCheck %s --check-prefix=ASM
-; RUN: llc -mtriple=aarch64-linux %s -filetype=obj -o -  |  \
-; RUN:   llvm-readelf --notes | FileCheck %s --check-prefix=OBJ
-
-define dso_local i32 @f() #0 {
-entry:
-  ret i32 0
-}
-
-define dso_local i32 @g() #1 {
-entry:
-  ret i32 0
-}
-
-attributes #0 = { "branch-target-enforcement" "sign-return-address"="non-leaf" }
-
-attributes #1 = { "sign-return-address"="all" }
-
-; Only the common atttribute (PAC)
-; ASM: warning: not setting BTI in feature flags
-; ASM:	.word	3221225472
-; ASM-NEXT:	.word	4
-; ASM-NEXT:	.word	2
-
-; OBJ: Properties: aarch64 feature: PAC
Index: llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-4.ll
===
--- llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-4.ll
+++ llvm/test/CodeGen/AArch64/note-gnu-property-pac-bti-4.ll
@@ -1,25 +1,12 @@
 ; RUN: llc -mtriple=aarch64-linux %s   -o - | \
 ; RUN:   FileCheck %s --check-prefix=ASM
-; RUN: llc -mtriple=aarch64-linux %s -filetype=obj -o - |  \
-; RUN:   llvm-readelf --notes | FileCheck %s --

[PATCH] D80792: Move unittest helpers to a shared location

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 267204.
gribozavr added a comment.

Removed some refactoring leftovers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80792

Files:
  clang/include/clang/Testing/CommandLineArgs.h
  clang/lib/CMakeLists.txt
  clang/lib/Testing/CMakeLists.txt
  clang/lib/Testing/CommandLineArgs.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/Language.cpp
  clang/unittests/AST/Language.h
  clang/unittests/AST/MatchVerifier.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -2,10 +2,10 @@
 #include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Host.h"
 
-#include "Language.h"
 #include "DeclMatcher.h"
 
 #include "gtest/gtest.h"
Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -21,8 +21,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "clang/Tooling/Tooling.h"
-#include "Language.h"
 #include "gtest/gtest.h"
 
 namespace clang {
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -26,7 +26,6 @@
   DeclTest.cpp
   EvaluateAsRValueTest.cpp
   ExternalASTSourceTest.cpp
-  Language.cpp
   NamedDeclPrinterTest.cpp
   RecursiveASTVisitorTest.cpp
   SizelessTypesTest.cpp
@@ -42,6 +41,7 @@
   clangBasic
   clangFrontend
   clangSerialization
+  clangTesting
   clangTooling
   )
 
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -19,11 +19,11 @@
 #include "clang/AST/ASTImporter.h"
 #include "clang/AST/ASTImporterSharedState.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 
 #include "DeclMatcher.h"
-#include "Language.h"
 
 #include 
 
Index: clang/lib/Testing/CommandLineArgs.cpp
===
--- clang/lib/Testing/CommandLineArgs.cpp
+++ clang/lib/Testing/CommandLineArgs.cpp
@@ -1,16 +1,12 @@
-//===-- unittest/AST/Language.cpp - AST unit test support -===//
+//===--- CommandLineArgs.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
 //
 //===--===//
-//
-//  This file defines language options for AST unittests.
-//
-//===--===//
 
-#include "Language.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace clang {
Index: clang/lib/Testing/CMakeLists.txt
===
--- /dev/null
+++ clang/lib/Testing/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_library(clangTesting
+  CommandLineArgs.cpp
+  )
Index: clang/lib/CMakeLists.txt
===
--- clang/lib/CMakeLists.txt
+++ clang/lib/CMakeLists.txt
@@ -24,3 +24,4 @@
   add_subdirectory(StaticAnalyzer)
 endif()
 add_subdirectory(Format)
+add_subdirectory(Testing)
Index: clang/include/clang/Testing/CommandLineArgs.h
===
--- clang/include/clang/Testing/CommandLineArgs.h
+++ clang/include/clang/Testing/CommandLineArgs.h
@@ -1,4 +1,4 @@
-//===-- unittest/AST/Language.h - AST unit test support ---===//
+//===--- CommandLineArgs.h ===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,15 @@
 //
 //===--===//
 //
-//  This file defines language options for AST unittests.
+//  This file defines language options for Clang

[PATCH] D78933: [analyzer] RangeConstraintManager optimizations in comparison expressions

2020-05-29 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D78933#2054195 , @ASDenysPetrov 
wrote:

> @xazax.hun, any thoughts?


I think we should check it on some more projects. We saw vastly different 
analyzer behavior on other projects in the past. I think you should be able to 
run it on any cmake project that supports windows by generating compilation 
database and using scan-build-py (in case other methods did not work).

Overall, the performance penalty does not look that bad. But I wonder how would 
this compare to a solution that also handles transitivity. We did not really 
look into the alternatives yet.

I'd like to know what @vsavchenko thinks as Valeriy is more into this kind of 
stuff lately.


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

https://reviews.llvm.org/D78933



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


[PATCH] D79330: [Analyzer][VLASizeChecker] Check for VLA size overflow.

2020-05-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

https://bugs.llvm.org/show_bug.cgi?id=46128 looks like a crash caused by this 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79330



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


[PATCH] D80792: Move unittest helpers to a shared location

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: cfe-commits, martong, mgorny.
Herald added a project: clang.
gribozavr updated this revision to Diff 267204.
gribozavr added a comment.

Removed some refactoring leftovers.


unittests/AST/Language.h defines some helpers that we would like to
reuse in other tests, for example, in tests for syntax trees.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80792

Files:
  clang/include/clang/Testing/CommandLineArgs.h
  clang/lib/CMakeLists.txt
  clang/lib/Testing/CMakeLists.txt
  clang/lib/Testing/CommandLineArgs.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/Language.cpp
  clang/unittests/AST/Language.h
  clang/unittests/AST/MatchVerifier.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -2,10 +2,10 @@
 #include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Host.h"
 
-#include "Language.h"
 #include "DeclMatcher.h"
 
 #include "gtest/gtest.h"
Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -21,8 +21,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "clang/Tooling/Tooling.h"
-#include "Language.h"
 #include "gtest/gtest.h"
 
 namespace clang {
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -26,7 +26,6 @@
   DeclTest.cpp
   EvaluateAsRValueTest.cpp
   ExternalASTSourceTest.cpp
-  Language.cpp
   NamedDeclPrinterTest.cpp
   RecursiveASTVisitorTest.cpp
   SizelessTypesTest.cpp
@@ -42,6 +41,7 @@
   clangBasic
   clangFrontend
   clangSerialization
+  clangTesting
   clangTooling
   )
 
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -19,11 +19,11 @@
 #include "clang/AST/ASTImporter.h"
 #include "clang/AST/ASTImporterSharedState.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 
 #include "DeclMatcher.h"
-#include "Language.h"
 
 #include 
 
Index: clang/lib/Testing/CommandLineArgs.cpp
===
--- clang/lib/Testing/CommandLineArgs.cpp
+++ clang/lib/Testing/CommandLineArgs.cpp
@@ -1,16 +1,12 @@
-//===-- unittest/AST/Language.cpp - AST unit test support -===//
+//===--- CommandLineArgs.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
 //
 //===--===//
-//
-//  This file defines language options for AST unittests.
-//
-//===--===//
 
-#include "Language.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace clang {
Index: clang/lib/Testing/CMakeLists.txt
===
--- /dev/null
+++ clang/lib/Testing/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_library(clangTesting
+  CommandLineArgs.cpp
+  )
Index: clang/lib/CMakeLists.txt
===
--- clang/lib/CMakeLists.txt
+++ clang/lib/CMakeLists.txt
@@ -24,3 +24,4 @@
   add_subdirectory(StaticAnalyzer)
 endif()
 add_subdirectory(Format)
+add_subdirectory(Testing)
Index: clang/include/clang/Testing/CommandLineArgs.h
===
--- clang/include/clang/Testing/CommandLineArgs.h
+++ clang/include/clang/Testing/CommandLineArgs.h
@@ -1,4 +1,4 @@
-//===-- unittest/AST/Language.h - AST unit test support ---===//
+//===--- CommandLineArgs.h ===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,15 @@
 //
 //===--

[PATCH] D80757: [PowerPC] Add clang option -m[no-]pcrel

2020-05-29 Thread Lei Huang via Phabricator via cfe-commits
lei marked an inline comment as done.
lei added inline comments.



Comment at: clang/test/Driver/ppc-pcrel.cpp:1
+// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -mcpu=pwr10 -mpcrel 
-o %t.o 2>&1 | FileCheck -check-prefix=CHECK-PCREL %s
+// RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -mcpu=pwr10 
-mno-pcrel -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOPCREL %s

saghir wrote:
> nit: would the first two checks be better off in 
> `clang/test/Driver/ppc-features.cpp`?
I think it's better to keep all tests for pcrel within this specific pcrel test 
file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80757



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


[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd4ef654673a9: Rename APIs in unittests/AST/Language.h in 
preparation to share them (authored by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80786

Files:
  clang/unittests/AST/ASTImporterFixtures.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterODRStrategiesTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/ASTImporterVisibilityTest.cpp
  clang/unittests/AST/Language.cpp
  clang/unittests/AST/Language.h
  clang/unittests/AST/MatchVerifier.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -23,12 +23,13 @@
   // snippets. To determine the returned node, a separate matcher is specified
   // for both snippets. The first matching node is returned.
   template 
-  std::tuple makeDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang,
-  const MatcherType &Matcher0, const MatcherType &Matcher1) {
+  std::tuple
+  makeDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+TestLanguage Lang, const MatcherType &Matcher0,
+const MatcherType &Matcher1) {
 this->Code0 = SrcCode0;
 this->Code1 = SrcCode1;
-ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+std::vector Args = getCommandLineArgsForTesting(Lang);
 
 const char *const InputFileName = "input.cc";
 
@@ -43,11 +44,12 @@
 return std::make_tuple(D0, D1);
   }
 
-  std::tuple makeTuDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang) {
+  std::tuple
+  makeTuDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+  TestLanguage Lang) {
 this->Code0 = SrcCode0;
 this->Code1 = SrcCode1;
-ArgVector Args = getBasicRunOptionsForLanguage(Lang);
+std::vector Args = getCommandLineArgsForTesting(Lang);
 
 const char *const InputFileName = "input.cc";
 
@@ -61,9 +63,9 @@
   // Get a pair of node pointers into the synthesized AST from the given code
   // snippets. The same matcher is used for both snippets.
   template 
-  std::tuple makeDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1, Language Lang,
-  const MatcherType &AMatcher) {
+  std::tuple
+  makeDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+TestLanguage Lang, const MatcherType &AMatcher) {
 return makeDecls(
   SrcCode0, SrcCode1, Lang, AMatcher, AMatcher);
   }
@@ -71,9 +73,9 @@
   // Get a pair of Decl pointers to the synthesized declarations from the given
   // code snippets. We search for the first NamedDecl with given name in both
   // snippets.
-  std::tuple makeNamedDecls(
-  const std::string &SrcCode0, const std::string &SrcCode1,
-  Language Lang, const char *const Identifier = "foo") {
+  std::tuple
+  makeNamedDecls(const std::string &SrcCode0, const std::string &SrcCode1,
+ TestLanguage Lang, const char *const Identifier = "foo") {
 auto Matcher = namedDecl(hasName(Identifier));
 return makeDecls(SrcCode0, SrcCode1, Lang, Matcher);
   }
Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -41,17 +41,15 @@
 
   template 
   testing::AssertionResult match(const std::string &Code,
- const MatcherType &AMatcher,
- Language L) {
+ const MatcherType &AMatcher, TestLanguage L) {
 std::vector Args;
 return match(Code, AMatcher, Args, L);
   }
 
   template 
-  testing::AssertionResult match(const std::string &Code,
- const MatcherType &AMatcher,
- std::vector& Args,
- Language L);
+  testing::AssertionResult
+  match(const std::string &Code, const MatcherType &AMatcher,
+std::vector &Args, TestLanguage L);
 
   template 
   testing::AssertionResult match(const Decl *D, const MatcherType &AMatcher);
@@ -77,10 +75,12 @@
 
 /// \brief Runs a matcher over some code, and returns the result of the
 /// verifier for the matched node.
-template  template 
-testing::AssertionResult MatchVerifier::match(
-const std::string &Code, const MatcherType &AMatcher,
-std::vector& Args, Language L) {
+template 
+template 
+testing::AssertionResult
+MatchVerifier::match(const std::string &Code,
+   const MatcherType &AMatcher,
+   std::vector &Args, TestLanguage L) {
   Ma

[PATCH] D79587: [CodeGen][SVE] Legalisation of extends with scalable types

2020-05-29 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin updated this revision to Diff 267183.
kmclaughlin edited the summary of this revision.
kmclaughlin added a comment.

- Removed ReplaceExtensionResults and instead try to use extract_subvector as 
much as possible to legalise the result
- Added ReplaceExtractSubVectorResults, which replaces extract_subvector with 
unpack operations
- Changed performSignExtendInRegCombine to replace a sign extend of an unsigned 
unpack with a signed unpack
- Removed changes to unrelated test files


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

https://reviews.llvm.org/D79587

Files:
  llvm/include/llvm/CodeGen/ValueTypes.h
  llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/test/CodeGen/AArch64/sve-ext.ll

Index: llvm/test/CodeGen/AArch64/sve-ext.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sve-ext.ll
@@ -0,0 +1,171 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+
+;
+; SEXT
+;
+
+define  @sext_b_to_h( %a) {
+; CHECK-LABEL: sext_b_to_h:
+; CHECK-DAG: sunpklo z2.h, z0.b
+; CHECK-DAG: sunpkhi z1.h, z0.b
+; CHECK-DAG: mov z0.d, z2.d
+; CHECK-NEXT: ret
+  %ext = sext  %a to 
+  ret  %ext
+}
+
+define  @sext_h_to_s( %a) {
+; CHECK-LABEL: sext_h_to_s:
+; CHECK-DAG: sunpklo z2.s, z0.h
+; CHECK-DAG: sunpkhi z1.s, z0.h
+; CHECK-DAG: mov z0.d, z2.d
+; CHECK-NEXT: ret
+  %ext = sext  %a to 
+  ret  %ext
+}
+
+define  @sext_s_to_d( %a) {
+; CHECK-LABEL: sext_s_to_d:
+; CHECK-DAG: sunpklo z2.d, z0.s
+; CHECK-DAG: sunpkhi z1.d, z0.s
+; CHECK-DAG: mov z0.d, z2.d
+; CHECK-NEXT: ret
+  %ext = sext  %a to 
+  ret  %ext
+}
+
+define  @sext_b_to_s( %a) {
+; CHECK-LABEL: sext_b_to_s:
+; CHECK-DAG: sunpklo [[LO:z[0-9]+]].h, z0.b
+; CHECK-DAG: sunpkhi [[HI:z[0-9]+]].h, z0.b
+; CHECK-DAG: sunpklo [[LOLO:z[0-9]+]].s, [[LO]].h
+; CHECK-DAG: sunpkhi {{z[0-9]+}}.s, [[LO]].h
+; CHECK-DAG: sunpklo {{z[0-9]+}}.s, [[HI]].h
+; CHECK-DAG: sunpkhi {{z[0-9]+}}.s, [[HI]].h
+; CHECK-NOT: sxt
+; CHECK: ret
+  %ext = sext  %a to 
+  ret  %ext
+}
+
+define  @sext_b_to_d( %a) {
+; CHECK-DAG: sunpklo [[LO1:z[0-9]+]].h, z0.b
+; CHECK-DAG: sunpkhi [[HI1:z[0-9]+]].h, z0.b
+; CHECK-DAG: sunpklo [[LO2:z[0-9]+]].s, z1.h
+; CHECK-DAG: sunpkhi [[HI2:z[0-9]+]].s, z1.h
+; CHECK-DAG: sunpklo [[LO3:z[0-9]+]].s, z0.h
+; CHECK-DAG: sunpkhi [[HI3:z[0-9]+]].s, z0.h
+; CHECK-DAG: sunpklo z0.d, [[LO2]].s
+; CHECK-DAG: sunpkhi z1.d, [[LO2]].s
+; CHECK-DAG: sunpklo z2.d, [[HI2]].s
+; CHECK-DAG: sunpkhi z3.d, [[HI2]].s
+; CHECK-DAG: sunpklo z4.d, [[LO3]].s
+; CHECK-DAG: sunpkhi z5.d, [[LO3]].s
+; CHECK-DAG: sunpklo z6.d, [[HI3]].s
+; CHECK-DAG: sunpkhi z7.d, [[HI3]].s
+; CHECK-NOT: sxt
+; CHECK-NEXT: ret
+  %ext = sext  %a to 
+  ret  %ext
+}
+
+define  @sext_promote_b_to_s( %in) {
+; CHECK-LABEL: @sext_promote
+; CHECK-DAG: ptrue p0.s
+; CHECK-DAG: sxtb z0.s, p0/m, z0.s
+; CHECK-NEXT: ret
+  %out = sext  %in to 
+  ret  %out
+}
+
+define  @sext_promote_h_to_d( %in) {
+; CHECK-LABEL: @sext_promote_h_to_d
+; CHECK-DAG: ptrue p0.d
+; CHECK-DAG: sxth z0.d, p0/m, z0.d
+; CHECK-NEXT: ret
+  %out = sext  %in to 
+  ret  %out
+}
+
+; ZEXT
+
+define  @zext_b_to_h( %a) {
+; CHECK-LABEL: zext_b_to_h:
+; CHECK-DAG: uunpklo z2.h, z0.b
+; CHECK-DAG: uunpkhi z1.h, z0.b
+; CHECK-DAG: mov z0.d, z2.d
+; CHECK-NEXT: ret
+  %ext = zext  %a to 
+  ret  %ext
+}
+
+define  @zext_h_to_s( %a) {
+; CHECK-LABEL: zext_h_to_s:
+; CHECK-DAG: uunpklo z2.s, z0.h
+; CHECK-DAG: uunpkhi z1.s, z0.h
+; CHECK-DAG: mov z0.d, z2.d
+; CHECK-NEXT: ret
+  %ext = zext  %a to 
+  ret  %ext
+}
+
+define  @zext_s_to_d( %a) {
+; CHECK-LABEL: zext_s_to_d:
+; CHECK-DAG: uunpklo z2.d, z0.s
+; CHECK-DAG: uunpkhi z1.d, z0.s
+; CHECK-DAG: mov z0.d, z2.d
+; CHECK-NEXT: ret
+  %ext = zext  %a to 
+  ret  %ext
+}
+
+define  @zext_b_to_s( %a) {
+; CHECK-LABEL: zext_b_to_s:
+; CHECK-DAG: uunpklo [[LO:z[0-9]+]].h, z0.b
+; CHECK-DAG: uunpkhi [[HI:z[0-9]+]].h, z0.b
+; CHECK-DAG: uunpklo z0.s, [[LO]].h
+; CHECK-DAG: uunpkhi z1.s, [[LO]].h
+; CHECK-DAG: uunpklo z2.s, [[HI]].h
+; CHECK-DAG: uunpkhi z3.s, [[HI]].h
+; CHECK-NOT: and
+; CHECK: ret
+  %ext = zext  %a to 
+  ret  %ext
+}
+
+define  @zext_b_to_d( %a) {
+; CHECK-DAG: uunpklo [[LO1:z[0-9]+]].h, z0.b
+; CHECK-DAG: uunpkhi [[HI1:z[0-9]+]].h, z0.b
+; CHECK-DAG: uunpklo [[LO2:z[0-9]+]].s, z1.h
+; CHECK-DAG: uunpkhi [[HI2:z[0-9]+]].s, z1.h
+; CHECK-DAG: uunpklo [[LO3:z[0-9]+]].s, z0.h
+; CHECK-DAG: uunpkhi [[HI3:z[0-9]+]].s, z0.h
+; CHECK-DAG: uunpklo z0.d, [[LO2]].s
+; CHECK-DAG: uunpkhi z1.d, [[LO2]].s
+; CHECK-DAG: uunpklo z2.d, [[HI2]].s
+; CHECK-DAG: uunpkhi z3.d, [[HI2]].s
+; CHECK-DAG: uunpklo z4.d, [[LO3]].s
+; CHECK-DAG: uunpkhi z5.d, [[LO3]].s
+; CHECK-DAG: uunpklo z6.d, [[HI3]].s
+; CHECK-DAG: uunpkhi z7.d, [[HI3]].s
+; CHECK-NOT: and
+; CHECK-NEXT: ret
+  %ext = zext  %a to 
+  ret  %ext
+}
+
+define  @zext_promote_

[PATCH] D80786: Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks! LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80786



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


[PATCH] D80781: [clang] Always allow including builtin headers in [no_undeclared_headers] modules.

2020-05-29 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 267210.
mboehme added a comment.

When testing with the real libc++ and glibc, I realized that I was still 
getting a cyclic dependency between the two modules because the builtin 
stddef.h that glibc was including was still being ascribed to libc++.

This modified version fixes this and also updates the test to more closely 
reflect the real libc++ and glibc so that my previous version of the fix also 
fails with a cyclic dependency.


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

https://reviews.llvm.org/D80781

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  
clang/test/Modules/Inputs/no-undeclared-includes-builtins/glibc/module.modulemap
  clang/test/Modules/Inputs/no-undeclared-includes-builtins/glibc/stdio.h
  
clang/test/Modules/Inputs/no-undeclared-includes-builtins/libcxx/module.modulemap
  clang/test/Modules/Inputs/no-undeclared-includes-builtins/libcxx/stddef.h
  clang/test/Modules/Inputs/no-undeclared-includes-builtins/libcxx/stdio.h
  clang/test/Modules/no-undeclared-includes-builtins.cpp

Index: clang/test/Modules/no-undeclared-includes-builtins.cpp
===
--- /dev/null
+++ clang/test/Modules/no-undeclared-includes-builtins.cpp
@@ -0,0 +1,14 @@
+// Test that a [no_undeclared_headers] module can include builtin headers, even
+// if these have been "claimed" by a different module that wraps these builtin
+// headers. libc++ does this, for example.
+//
+// The test inputs used here replicates the relationship between libc++ and
+// glibc. When modularizing glibc, [no_undeclared_headers] must be used to
+// prevent glibc from including the libc++ versions of the C standard library
+// headers.
+
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/no-undeclared-includes-builtins/libcxx -I %S/Inputs/no-undeclared-includes-builtins/glibc %s
+// expected-no-diagnostics
+
+#include 
Index: clang/test/Modules/Inputs/no-undeclared-includes-builtins/libcxx/stdio.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/no-undeclared-includes-builtins/libcxx/stdio.h
@@ -0,0 +1 @@
+#include_next 
Index: clang/test/Modules/Inputs/no-undeclared-includes-builtins/libcxx/stddef.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/no-undeclared-includes-builtins/libcxx/stddef.h
@@ -0,0 +1 @@
+#include_next 
Index: clang/test/Modules/Inputs/no-undeclared-includes-builtins/libcxx/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/no-undeclared-includes-builtins/libcxx/module.modulemap
@@ -0,0 +1,5 @@
+module libcxx [system] {
+  header "stddef.h"
+  header "stdio.h"
+  export *
+}
Index: clang/test/Modules/Inputs/no-undeclared-includes-builtins/glibc/stdio.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/no-undeclared-includes-builtins/glibc/stdio.h
@@ -0,0 +1 @@
+#include 
Index: clang/test/Modules/Inputs/no-undeclared-includes-builtins/glibc/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/no-undeclared-includes-builtins/glibc/module.modulemap
@@ -0,0 +1,5 @@
+module glibc [system] [no_undeclared_includes] {
+  // glibc relies on the builtin stddef.h, so it has no stddef.h of its own.
+  header "stdio.h"
+  export *
+}
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -387,13 +387,17 @@
.Default(false);
 }
 
+bool ModuleMap::isBuiltinHeader(const FileEntry *File) {
+  return File->getDir() == BuiltinIncludeDir &&
+ ModuleMap::isBuiltinHeader(llvm::sys::path::filename(File->getName()));
+}
+
 ModuleMap::HeadersMap::iterator
 ModuleMap::findKnownHeader(const FileEntry *File) {
   resolveHeaderDirectives(File);
   HeadersMap::iterator Known = Headers.find(File);
   if (HeaderInfo.getHeaderSearchOpts().ImplicitModuleMaps &&
-  Known == Headers.end() && File->getDir() == BuiltinIncludeDir &&
-  ModuleMap::isBuiltinHeader(llvm::sys::path::filename(File->getName( {
+  Known == Headers.end() && ModuleMap::isBuiltinHeader(File)) {
 HeaderInfo.loadTopLevelSystemModules();
 return Headers.find(File);
   }
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1276,14 +1276,12 @@
 //
 // It's common that libc++ and system modules will both define such
 // submodules. Make sure cached results for a builtin header won't
-// prevent other builtin modules to po

[PATCH] D78933: [analyzer] RangeConstraintManager optimizations in comparison expressions

2020-05-29 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Sorry for postponing this review.
I'll get to it right away!


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

https://reviews.llvm.org/D78933



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


[PATCH] D77066: [analyzer] ApiModeling: Add buffer size arg constraint

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 267216.
martong marked 2 inline comments as done.
martong added a comment.

- Remove SValBuilder param


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77066

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
  clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -122,3 +122,30 @@
   // bugpath-warning{{Function argument constraint is not satisfied}} \
   // bugpath-note{{Function argument constraint is not satisfied}}
 }
+
+int __buf_size_arg_constraint(const void *, size_t);
+void test_buf_size_concrete() {
+  char buf[3];   // bugpath-note{{'buf' initialized here}}
+  __buf_size_arg_constraint(buf, 4); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+}
+void test_buf_size_symbolic(int s) {
+  char buf[3];
+  __buf_size_arg_constraint(buf, s);
+  clang_analyzer_eval(s <= 3); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{'s' is <= 3}}
+}
+void test_buf_size_symbolic_and_offset(int s) {
+  char buf[3];
+  __buf_size_arg_constraint(buf + 1, s);
+  clang_analyzer_eval(s <= 2); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{'s' is <= 2}}
+}
Index: clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
===
--- clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
+++ clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
@@ -44,5 +44,28 @@
   return DivisionV.castAs();
 }
 
+SVal getDynamicSizeWithOffset(ProgramStateRef State, const SVal &BufV) {
+  SValBuilder &SvalBuilder = State->getStateManager().getSValBuilder();
+  const MemRegion *MRegion = BufV.getAsRegion();
+  if (!MRegion)
+return UnknownVal();
+  RegionOffset Offset = MRegion->getAsOffset();
+  if (Offset.hasSymbolicOffset())
+return UnknownVal();
+  const MemRegion *BaseRegion = MRegion->getBaseRegion();
+  if (!BaseRegion)
+return UnknownVal();
+
+  NonLoc OffsetInBytes = SvalBuilder.makeArrayIndex(
+  Offset.getOffset() /
+  MRegion->getMemRegionManager().getContext().getCharWidth());
+  DefinedOrUnknownSVal ExtentInBytes =
+  getDynamicSize(State, BaseRegion, SvalBuilder);
+
+  return SvalBuilder.evalBinOp(State, BinaryOperator::Opcode::BO_Sub,
+   ExtentInBytes, OffsetInBytes,
+   SvalBuilder.getArrayIndexType());
+}
+
 } // namespace ento
 } // namespace clang
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -56,6 +56,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
 
 using namespace clang;
 using namespace clang::ento;
@@ -108,7 +109,8 @@
 /// Apply the effects of the constraint on the given program state. If null
 /// is returned then the constraint is not feasible.
 virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
-  const Summary &Summary) const = 0;
+  const Summary &Summary,
+  CheckerContext &C) const = 0;
 virtual ValueConstraintPtr negate() const {
   llvm_unreachable("Not implemented");
 };
@@ -143,7 +145,8 @@
const Summary &Summary) const;
   public:
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
-  const Summary &Summary) const override {
+  const Summary &Summary,
+  CheckerContext &C) const override {
   switch (Kind) {
   case OutOfRange:
 return applyAsOutOfRange(State, Call, Summary);
@@ -178,7 +181,8 @@
 ArgNo getOtherArgNo() const { return OtherArgN; }
 BinaryOperator::Opcode getOpcode() const { return Opcode; }
 ProgramStateRef apply(P

[PATCH] D78933: [analyzer] RangeConstraintManager optimizations in comparison expressions

2020-05-29 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@xazax.hun

> I think we should check it on some more projects. We saw vastly different 
> analyzer behavior on other projects in the past.

I completely agree with you. But, unfortunately, vim-proj is the only I could 
squeeze from that bunch.

> I think you should be able to run it on any cmake project that supports 
> windows by generating compilation database and using scan-build-py (in case 
> other methods did not work).

I'll appreciate if you'd give some of such projects. Another point is that I 
don't know how to get printed stats from the //scan-build//.

> But I wonder how would this compare to a solution that also handles 
> transitivity. We did not really look into the alternatives yet.

I've read an article about Octagons you gave me. The article covers much bigger 
and more complicated scope, then mine solution. For now I'm not really ready to 
enlarge it, as it needs a deep investigation. I think for now it can be 
accepted as an intermadiate proposal.


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

https://reviews.llvm.org/D78933



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


[PATCH] D80792: Move unittest helpers to a shared location

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 267214.
gribozavr added a comment.

Added a modulemap entry for the new Clang library.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80792

Files:
  clang/include/clang/Testing/CommandLineArgs.h
  clang/include/clang/module.modulemap
  clang/lib/CMakeLists.txt
  clang/lib/Testing/CMakeLists.txt
  clang/lib/Testing/CommandLineArgs.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/Language.cpp
  clang/unittests/AST/Language.h
  clang/unittests/AST/MatchVerifier.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -2,10 +2,10 @@
 #include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Host.h"
 
-#include "Language.h"
 #include "DeclMatcher.h"
 
 #include "gtest/gtest.h"
Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -21,8 +21,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "clang/Tooling/Tooling.h"
-#include "Language.h"
 #include "gtest/gtest.h"
 
 namespace clang {
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -26,7 +26,6 @@
   DeclTest.cpp
   EvaluateAsRValueTest.cpp
   ExternalASTSourceTest.cpp
-  Language.cpp
   NamedDeclPrinterTest.cpp
   RecursiveASTVisitorTest.cpp
   SizelessTypesTest.cpp
@@ -42,6 +41,7 @@
   clangBasic
   clangFrontend
   clangSerialization
+  clangTesting
   clangTooling
   )
 
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -19,11 +19,11 @@
 #include "clang/AST/ASTImporter.h"
 #include "clang/AST/ASTImporterSharedState.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 
 #include "DeclMatcher.h"
-#include "Language.h"
 
 #include 
 
Index: clang/lib/Testing/CommandLineArgs.cpp
===
--- clang/lib/Testing/CommandLineArgs.cpp
+++ clang/lib/Testing/CommandLineArgs.cpp
@@ -1,16 +1,12 @@
-//===-- unittest/AST/Language.cpp - AST unit test support -===//
+//===--- CommandLineArgs.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
 //
 //===--===//
-//
-//  This file defines language options for AST unittests.
-//
-//===--===//
 
-#include "Language.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace clang {
Index: clang/lib/Testing/CMakeLists.txt
===
--- /dev/null
+++ clang/lib/Testing/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_library(clangTesting
+  CommandLineArgs.cpp
+  )
Index: clang/lib/CMakeLists.txt
===
--- clang/lib/CMakeLists.txt
+++ clang/lib/CMakeLists.txt
@@ -24,3 +24,4 @@
   add_subdirectory(StaticAnalyzer)
 endif()
 add_subdirectory(Format)
+add_subdirectory(Testing)
Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -152,6 +152,12 @@
   module * { export * }
 }
 
+module Clang_Testing {
+  requires cplusplus
+  umbrella "Testing"
+  module * { export * }
+}
+
 module Clang_Tooling {
   requires cplusplus umbrella "Tooling" module * { export * }
   // FIXME: Exclude these headers to avoid pulling all of the AST matchers
Index: clang/include/clang/Testing/CommandLineArgs.h
===
--- clang/include/clang/Testing/CommandLineArgs.h
+++ clang/include/clang/Testing/Co

[PATCH] D77066: [analyzer] ApiModeling: Add buffer size arg constraint

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:237
+  SVal BufDynSize =
+  getDynamicSizeWithOffset(State, BufV, C.getSValBuilder());
+

Szelethus wrote:
> You can retrieve `SValBuilder` from `ProgramState`: 
> `State->getStateManager().getSValBuilder()`.
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77066



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


[PATCH] D79587: [CodeGen][SVE] Legalisation of extends with scalable types

2020-05-29 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

Hi Kerry, just a couple of comments about the use of getVectorNumElements() - 
we're trying to remove calls to this function so it would be good if you could 
use  getVectorElementCount() instead. Thanks!




Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:13837
+
+  if (InVT.getVectorNumElements() != (VT.getVectorNumElements()*2))
+return;

I think we want to move away from calling getVectorNumElements(), so might need 
to change this to something like

ElementCount ResEC = VT.getVectorElementCount();
if (InVT.getVectorElementCount() != (ResEC * 2))



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:13845
+  unsigned Index = CIndex->getZExtValue();
+  if ((Index != 0) && (Index != VT.getVectorNumElements()))
+return;

And here you could then change this to:

if ((Index != 0) && (Index != ResEC.Min))



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

https://reviews.llvm.org/D79587



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


Re: Bug in QualTypeNames.cpp and adding an option to prepend "::" to fully qualified names.

2020-05-29 Thread Sam McCall via cfe-commits
Sorry about ignoring this, I didn't really have an opinion - clang is
fairly full of helper functions that don't quite do what you expect.
This does look like a bug though.

Generally for printing types, PrettyPrinter is the way to go. So I'm
supportive of any of:
 - adding the option to explicitly root names at the global namespace
 - modifying CLIF to use a PrintingPolicy directly
 - modifying getFullyQualifiedName() to do something roughly equivalent but
less buggy using the pretty-printer
 - deprecating getFullyQualifiedName()

> The presence of inline namespaces is about the only bit I'd find a touch
questionable
Does SuppressUnwrittenScope do what you want?

I did miss the patch attached to this, we do apparently have docs
 that say
mailing patch files to the *-commits@ mailing lists is a good way to get
them reviewed, but IMO those docs are out of date - Phabricator is the way
to go. Feel free to send it to me.
It will need a test, I think
llvm-project/clang/unittests/AST/DeclPrinterTest.cpp is probably the best
place to add one.

On Sat, May 23, 2020 at 10:22 PM Jean-Baptiste Lespiau 
wrote:

> Hi,
>
> should we submit this CL, adding the option to prepend classes and struct
> fully qualified names with "::"?
>
> This can then allow people to slowly switch to the new function, and I can
> close my fix/close my bug in CLIF. I can do more on this CL if it is
> needed, but I would like to be sure this will get submitted and I will not
> waste my time, and know exactly what you want me to do.
>
> Possible options include:
> - adding the full context, with the bug, in the CL description
> - adding documentation on `getFullyQualifiedName` expliciting in which
> context the bug can occur
> - adding a FullyQualifiedTypePrinter() that will take an AST or a
> TypePolicy, and set the correct fields, so one can do
> QualType.getAsString(FullyQualifiedTypePrinter(ast)) to replace the
> hereabove one.
> - add some tests, but I do not know where and how.
>
> When this few lines are submitted, I can update google3 for clang, and I
> can start changing some internal occurrences, and finally fix the CLIF bug.
>
> Thanks!
>
> On Tue, May 12, 2020 at 11:19 PM Jean-Baptiste Lespiau <
> jblesp...@google.com> wrote:
>
>>
>>
>> On Tue, May 12, 2020 at 11:11 PM David Blaikie 
>> wrote:
>>
>>> On Tue, May 12, 2020 at 12:40 PM Jean-Baptiste Lespiau <
>>> jblesp...@google.com> wrote:
>>>
 Hi,

 thanks for your answer.

 Just a few remarks:

 1. I imagine that we cannot know if people are using
 getFullyQualifiedName. In particular, people could have developed their own
 internal tools, thus we cannot be aware of all callers. I do not know
 Clang's policy, but can we delete or completely change a function without
 deprecating it first?

>>>
>>> The LLVM project offers little/no API guarantees -
>>> potentially/especially for a function with no use in-tree. But, yes, as
>>> Googlers we'd be encouraged not to commit an API change knowing this might
>>> cause widespread internal breakage without a plan/pre-emptively fixing
>>> things.
>>>
>>>
 I was imagining that the process was to deprecate it, document the case
 where it can be incorrect, and that in a next release it gets
 deleted/replaced (or someone steps up to fix it).

>>>
>>> Sometimes deprecation is used - certain APIs have a lot of out of tree
>>> surface area
>>>
>>>
 2. As example of different behaviors:
 (a) the qual_type.getAsString() will print implementation namespace
 details (e.g. ::std*::__u*::variant instead of std::variant).

>>>
>>> Yep, that's probably not ideal for most source generating use cases.
>>>
>>>
 (b) It will also display default template arguments, e.g.
 template 
 class MyClass
 is printed as MyClass (I think) in getFullyQualifiedName, while
 getAsString() will use MyClass.

>>>
>>> That seems better/correct - did CLIF actually want/rely on/benefit from
>>> the old behavior of only printing the template name?
>>>
>>
>> I did check to replace all of the getFullyQualifiedName in CLIF with the
>> new version: it worked like a charm. The error messages are just changed
>> accordingly (so they will have longer types).
>> And the generated code was also less verbose.
>>
>>>
>>>
 (c) the example of the nested template argument above.

>>>
>>> Which seems just wrong/inconsistent/not-behaving-to-spec to me - I don't
>>> imagine any caller actually wanted that behavior?
>>>
>>
>> I agree.
>>
>>>
>>>

 At the end,what matters is that getAsString() is semantically always
 correct, even if it can be overly verbose.

>>>
>>> The presence of inline namespaces is about the only bit I'd find a touch
>>> questionable. (Hopefully Sam can chime in on some of that)
>>>
>>
>> Me too, I would be curious if it is easy to remove.
>>
>>>
>>>
 I tried to fix getFullyQualifiedNam

[clang] bd03ef1 - [analyzer] ApiModeling: Add buffer size arg constraint

2020-05-29 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-05-29T16:13:57+02:00
New Revision: bd03ef19beb8a3476d5cd9f744c5fba5ca287c51

URL: 
https://github.com/llvm/llvm-project/commit/bd03ef19beb8a3476d5cd9f744c5fba5ca287c51
DIFF: 
https://github.com/llvm/llvm-project/commit/bd03ef19beb8a3476d5cd9f744c5fba5ca287c51.diff

LOG: [analyzer] ApiModeling: Add buffer size arg constraint

Summary:
Introducing a new argument constraint to confine buffer sizes. It is typical in
C APIs that a parameter represents a buffer and another param holds the size of
the buffer (or the size of the data we want to handle from the buffer).

Reviewers: NoQ, Szelethus, Charusso, steakhal

Subscribers: whisperity, xazax.hun, baloghadamsoftware, szepet, rnkovacs, 
a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, gamesh411, ASDenysPetrov, 
cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints.c

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
index b48914c53d82..398f9b6ac33a 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
@@ -32,6 +32,21 @@ DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef 
State,
 SValBuilder &SVB,
 QualType ElementTy);
 
+/// Get the dynamic size for a symbolic value that represents a buffer. If
+/// there is an offsetting to the underlying buffer we consider that too.
+/// Returns with an SVal that represents the size, this is Unknown if the
+/// engine cannot deduce the size.
+/// E.g.
+///   char buf[3];
+///   (buf); // size is 3
+///   (buf + 1); // size is 2
+///   (buf + 3); // size is 0
+///   (buf + 4); // size is -1
+///
+///   char *bufptr;
+///   (bufptr) // size is unknown
+SVal getDynamicSizeWithOffset(ProgramStateRef State, const SVal &BufV);
+
 } // namespace ento
 } // namespace clang
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
index fec9fb59b2eb..dc9cd717be9e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
@@ -63,28 +63,8 @@ class PlacementNewChecker : public 
Checker> {
 
 SVal PlacementNewChecker::getExtentSizeOfPlace(const CXXNewExpr *NE,
CheckerContext &C) const {
-  ProgramStateRef State = C.getState();
   const Expr *Place = NE->getPlacementArg(0);
-
-  const MemRegion *MRegion = C.getSVal(Place).getAsRegion();
-  if (!MRegion)
-return UnknownVal();
-  RegionOffset Offset = MRegion->getAsOffset();
-  if (Offset.hasSymbolicOffset())
-return UnknownVal();
-  const MemRegion *BaseRegion = MRegion->getBaseRegion();
-  if (!BaseRegion)
-return UnknownVal();
-
-  SValBuilder &SvalBuilder = C.getSValBuilder();
-  NonLoc OffsetInBytes = SvalBuilder.makeArrayIndex(
-  Offset.getOffset() / C.getASTContext().getCharWidth());
-  DefinedOrUnknownSVal ExtentInBytes =
-  getDynamicSize(State, BaseRegion, SvalBuilder);
-
-  return SvalBuilder.evalBinOp(State, BinaryOperator::Opcode::BO_Sub,
-   ExtentInBytes, OffsetInBytes,
-   SvalBuilder.getArrayIndexType());
+  return getDynamicSizeWithOffset(C.getState(), C.getSVal(Place));
 }
 
 SVal PlacementNewChecker::getExtentSizeOfNewTarget(const CXXNewExpr *NE,

diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index aefcad374596..f661f29948b6 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -56,6 +56,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
 
 using namespace clang;
 using namespace clang::ento;
@@ -108,7 +109,8 @@ class StdLibraryFunctionsChecker
 /// Apply the effects of the constraint on the given program state. If null
 /// is returned then the constraint is not feasible.
 virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
-  const Summary

[clang] 41928c9 - [analyzer] ApiModeling: Add buffer size arg constraint with multiplier involved

2020-05-29 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-05-29T16:24:26+02:00
New Revision: 41928c97b6a17264938fc765a6a0656d8b6e86ed

URL: 
https://github.com/llvm/llvm-project/commit/41928c97b6a17264938fc765a6a0656d8b6e86ed
DIFF: 
https://github.com/llvm/llvm-project/commit/41928c97b6a17264938fc765a6a0656d8b6e86ed.diff

LOG: [analyzer] ApiModeling: Add buffer size arg constraint with multiplier 
involved

Summary:
Further develop the buffer size argumentum constraint so it can handle sizes
that we can get by multiplying two variables.

Reviewers: Szelethus, NoQ, steakhal

Subscribers: whisperity, xazax.hun, baloghadamsoftware, szepet, rnkovacs, 
a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, gamesh411, Charusso, 
ASDenysPetrov, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index f661f29948b6..bd2f505849af 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -215,9 +215,16 @@ class StdLibraryFunctionsChecker
   // Represents a buffer argument with an additional size argument.
   // E.g. the first two arguments here:
   //   ctime_s(char *buffer, rsize_t bufsz, const time_t *time);
+  // Another example:
+  //   size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
+  //   // Here, ptr is the buffer, and its minimum size is `size * nmemb`.
   class BufferSizeConstraint : public ValueConstraint {
 // The argument which holds the size of the buffer.
 ArgNo SizeArgN;
+// The argument which is a multiplier to size. This is set in case of
+// `fread` like functions where the size is computed as a multiplication of
+// two arguments.
+llvm::Optional SizeMultiplierArgN;
 // The operator we use in apply. This is negated in negate().
 BinaryOperator::Opcode Op = BO_LE;
 
@@ -225,17 +232,27 @@ class StdLibraryFunctionsChecker
 BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize)
 : ValueConstraint(Buffer), SizeArgN(BufSize) {}
 
+BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize, ArgNo BufSizeMultiplier)
+: ValueConstraint(Buffer), SizeArgN(BufSize),
+  SizeMultiplierArgN(BufSizeMultiplier) {}
+
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
   const Summary &Summary,
   CheckerContext &C) const override {
+  SValBuilder &SvalBuilder = C.getSValBuilder();
   // The buffer argument.
   SVal BufV = getArgSVal(Call, getArgNo());
   // The size argument.
   SVal SizeV = getArgSVal(Call, SizeArgN);
+  // Multiply with another argument if given.
+  if (SizeMultiplierArgN) {
+SVal SizeMulV = getArgSVal(Call, *SizeMultiplierArgN);
+SizeV = SvalBuilder.evalBinOp(State, BO_Mul, SizeV, SizeMulV,
+  Summary.getArgType(SizeArgN));
+  }
   // The dynamic size of the buffer argument, got from the analyzer engine.
   SVal BufDynSize = getDynamicSizeWithOffset(State, BufV);
 
-  SValBuilder &SvalBuilder = C.getSValBuilder();
   SVal Feasible = SvalBuilder.evalBinOp(State, Op, SizeV, BufDynSize,
 SvalBuilder.getContext().BoolTy);
   if (auto F = Feasible.getAs())
@@ -744,8 +761,8 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   IntRangeVector Ranges) {
 return std::make_shared(ArgN, Kind, Ranges);
   };
-  auto BufferSize = [](ArgNo BufArgN, ArgNo SizeArgN) {
-return std::make_shared(BufArgN, SizeArgN);
+  auto BufferSize = [](auto... Args) {
+return std::make_shared(Args...);
   };
   struct {
 auto operator()(RangeKind Kind, IntRangeVector Ranges) {
@@ -988,6 +1005,12 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 EvalCallAsPure)
 .ArgConstraint(
 BufferSize(/*Buffer=*/ArgNo(0), /*BufSize=*/ArgNo(1;
+addToFunctionSummaryMap(
+"__buf_size_arg_constraint_mul",
+Summary(ArgTypes{ConstVoidPtrTy, SizeTy, SizeTy}, RetType{IntTy},
+EvalCallAsPure)
+.ArgConstraint(BufferSize(/*Buffer=*/ArgNo(0), 
/*BufSize=*/ArgNo(1),
+  /*BufSizeMultiplier=*/ArgNo(2;
   }
 }
 

diff  --git a/clang/test/Analysis/std-c-library-functions-arg-constraints.c 
b/clang/test/Analysis/std-c-library-functions-arg-constraints.c
index c59e4429f419..60338128ec89 100644
--- a/clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ b/clang/test/Analysis/std-c-lib

[PATCH] D80800: Add an option to fully qualify classes and structs.

2020-05-29 Thread Jean-Baptiste Lespiau via Phabricator via cfe-commits
jblespiau created this revision.
jblespiau added a reviewer: sammccall.
jblespiau edited the summary of this revision.
sammccall added a comment.

This should really have a test - NamedDeclPrinterTest.cpp seems like the right 
place.




Comment at: clang/lib/AST/TypePrinter.cpp:326
+  if (Policy.FullyQualifiedName && Policy.GlobalScopeQualifiedName &&
+  T->isStructureOrClassType()) {
+OS << "::";

structure-or-class-type isn't quite the right check:
 - enums and typedefs for instance should also be qualified.
 - you're looking through sugar to the underlying type, which may not be what 
you want
 
It's going to be hard to get this right from here... I suspect it's better to 
fix where `FullyQualifiedName` is checked in DeclPrinter.
This ultimately calls through to NamedDecl::printNestedNameSpecifier, which is 
probably the right place to respect this option.
(I don't totally understand what's meant to happen if SuppressScope is false 
but FullyQualiifedName is also false, that calls through to 
NestedNameSpecifier::print which you may want to also fix, or not)


Generally speaking, using TypePrinter is the most flexible mechanism for
printing types. It makes sense to have this feature just for this
reason.

However, this is also done in another context:
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20200518/321225.html

In a nutshell, `getFullyQualifiedName` is bugged and prints
`::tensorfn::Nested< ::std::variant >`
instead of:
`::tensorfn::Nested< 
::std::variant<::tensorflow::Tensor,::tensorfn::DeviceTensor> >`

I was not able to fix this function, and intend to add this feature and
then start to remove the use of the other function (in CLIF first).

Longer term, we should delete `QualTypeNames.cpp`, and prefer
TypePrinter.

Things that are not that clear:

- should more types than classes and struct be globally qualified?


https://reviews.llvm.org/D80800

Files:
  clang/include/clang/AST/PrettyPrinter.h
  clang/lib/AST/TypePrinter.cpp


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -40,6 +41,7 @@
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -320,6 +322,10 @@
   HasEmptyPlaceHolder = false;
   }
 
+  if (Policy.FullyQualifiedName && Policy.GlobalScopeQualifiedName &&
+  T->isStructureOrClassType()) {
+OS << "::";
+  }
   switch (T->getTypeClass()) {
 #define ABSTRACT_TYPE(CLASS, PARENT)
 #define TYPE(CLASS, PARENT) case Type::CLASS: \
Index: clang/include/clang/AST/PrettyPrinter.h
===
--- clang/include/clang/AST/PrettyPrinter.h
+++ clang/include/clang/AST/PrettyPrinter.h
@@ -63,7 +63,8 @@
 MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true),
 MSVCFormatting(false), ConstantsAsWritten(false),
 SuppressImplicitBase(false), FullyQualifiedName(false),
-PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true) 
{}
+GlobalScopeQualifiedName(false), PrintCanonicalTypes(false),
+PrintInjectedClassNameWithArguments(true) {}
 
   /// Adjust this printing policy for cases where it's known that we're
   /// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -241,6 +242,13 @@
   /// This is the opposite of SuppressScope and thus overrules it.
   unsigned FullyQualifiedName : 1;
 
+  // When true, class and struct types (to be expanded if needed) will be
+  // prepended with "::"
+  // Note it also requires `FullyQualifiedName` to also be set to true, as it
+  // does not make sense to prepend "::" to a non fully-qualified name.
+  // This targets generated code.
+  unsigned GlobalScopeQualifiedName : 1;
+
   /// Whether to print types as written or canonically.
   unsigned PrintCanonicalTypes : 1;
 


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -40,6 +41,7 @@
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -320,6 +322,10 @@
   HasEmptyPlaceHolder = false;
   }
 
+  if (Policy.FullyQualifiedName && Policy.GlobalScopeQualifiedN

[PATCH] D79587: [CodeGen][SVE] Legalisation of extends with scalable types

2020-05-29 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

Sorry I forgot to mention I think we have an existing test file for extends:

llvm/test/CodeGen/AArch64/sve-sext-zext.ll

It might be worth adding these cases to that file instead of creating a new one?


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

https://reviews.llvm.org/D79587



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


[PATCH] D80237: [hip] Ensure pointer in struct argument has proper `addrspacecast`.

2020-05-29 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D80237#2058108 , @rjmccall wrote:

> In D80237#2055902 , @arsenm wrote:
>
> > In D80237#2051933 , @rjmccall 
> > wrote:
> >
> > > Okay.  Can you explain why we need to coerce in the first place, though?  
> > > Especially if the representation is the same, why is your target-lowering 
> > > requiring parameters to be coerced to involve pointers in a different 
> > > address space?
> >
> >
> > It's not a requirement, but an optimization. The pointer representation is 
> > the same, but there's a penalty to using the generic pointer. From the 
> > language context here, we know the flat pointer can never alias the 
> > non-global address spaces.
>
>
> Is that because it's a kernel argument?  I don't understand how the coercion 
> can work in general for structs that just contain pointers.


Yes, there's no valid way to pass a non-global address space pointer through a 
flat pointer into a kernel. This doesn't apply in other contexts


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80237



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


[PATCH] D80800: Add an option to fully qualify classes and structs.

2020-05-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This should really have a test - NamedDeclPrinterTest.cpp seems like the right 
place.




Comment at: clang/lib/AST/TypePrinter.cpp:326
+  if (Policy.FullyQualifiedName && Policy.GlobalScopeQualifiedName &&
+  T->isStructureOrClassType()) {
+OS << "::";

structure-or-class-type isn't quite the right check:
 - enums and typedefs for instance should also be qualified.
 - you're looking through sugar to the underlying type, which may not be what 
you want
 
It's going to be hard to get this right from here... I suspect it's better to 
fix where `FullyQualifiedName` is checked in DeclPrinter.
This ultimately calls through to NamedDecl::printNestedNameSpecifier, which is 
probably the right place to respect this option.
(I don't totally understand what's meant to happen if SuppressScope is false 
but FullyQualiifedName is also false, that calls through to 
NestedNameSpecifier::print which you may want to also fix, or not)


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

https://reviews.llvm.org/D80800



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


[PATCH] D77066: [analyzer] ApiModeling: Add buffer size arg constraint

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbd03ef19beb8: [analyzer] ApiModeling: Add buffer size arg 
constraint (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77066

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
  clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -122,3 +122,30 @@
   // bugpath-warning{{Function argument constraint is not satisfied}} \
   // bugpath-note{{Function argument constraint is not satisfied}}
 }
+
+int __buf_size_arg_constraint(const void *, size_t);
+void test_buf_size_concrete() {
+  char buf[3];   // bugpath-note{{'buf' initialized here}}
+  __buf_size_arg_constraint(buf, 4); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+}
+void test_buf_size_symbolic(int s) {
+  char buf[3];
+  __buf_size_arg_constraint(buf, s);
+  clang_analyzer_eval(s <= 3); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{'s' is <= 3}}
+}
+void test_buf_size_symbolic_and_offset(int s) {
+  char buf[3];
+  __buf_size_arg_constraint(buf + 1, s);
+  clang_analyzer_eval(s <= 2); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{'s' is <= 2}}
+}
Index: clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
===
--- clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
+++ clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
@@ -44,5 +44,28 @@
   return DivisionV.castAs();
 }
 
+SVal getDynamicSizeWithOffset(ProgramStateRef State, const SVal &BufV) {
+  SValBuilder &SvalBuilder = State->getStateManager().getSValBuilder();
+  const MemRegion *MRegion = BufV.getAsRegion();
+  if (!MRegion)
+return UnknownVal();
+  RegionOffset Offset = MRegion->getAsOffset();
+  if (Offset.hasSymbolicOffset())
+return UnknownVal();
+  const MemRegion *BaseRegion = MRegion->getBaseRegion();
+  if (!BaseRegion)
+return UnknownVal();
+
+  NonLoc OffsetInBytes = SvalBuilder.makeArrayIndex(
+  Offset.getOffset() /
+  MRegion->getMemRegionManager().getContext().getCharWidth());
+  DefinedOrUnknownSVal ExtentInBytes =
+  getDynamicSize(State, BaseRegion, SvalBuilder);
+
+  return SvalBuilder.evalBinOp(State, BinaryOperator::Opcode::BO_Sub,
+   ExtentInBytes, OffsetInBytes,
+   SvalBuilder.getArrayIndexType());
+}
+
 } // namespace ento
 } // namespace clang
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -56,6 +56,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
 
 using namespace clang;
 using namespace clang::ento;
@@ -108,7 +109,8 @@
 /// Apply the effects of the constraint on the given program state. If null
 /// is returned then the constraint is not feasible.
 virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
-  const Summary &Summary) const = 0;
+  const Summary &Summary,
+  CheckerContext &C) const = 0;
 virtual ValueConstraintPtr negate() const {
   llvm_unreachable("Not implemented");
 };
@@ -143,7 +145,8 @@
const Summary &Summary) const;
   public:
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
-  const Summary &Summary) const override {
+  const Summary &Summary,
+  CheckerContext &C) const override {
   switch (Kind) {
   case OutOfRange:
 return applyAsOutOfRange(State, Call, Summary);
@@ -178,7 +181,8 @@
 ArgNo getOtherArgNo() const { return OtherArgN; }
 BinaryOperator::Opcode getOpcode() const { r

[PATCH] D80784: [clangd][NFC] Explode ReceivedPreamble into a CV

2020-05-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:661
+std::unique_lock Lock(Mutex);
+RequestsCV.wait(Lock, [this] {
+  // Block until we reiceve a preamble request, unless a preamble already

Does LatestPreamble signal RequestsCV or just PreambleCV?

Seems like it might be less error-prone to have just one CV, signalled when 
preamble requests are scheduled, latest preamble becomes available, and on 
shutdown. The spurious wakeups shouldn't be a real problem, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80784



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


[PATCH] D77148: [analyzer] ApiModeling: Add buffer size arg constraint with multiplier involved

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41928c97b6a1: [analyzer] ApiModeling: Add buffer size arg 
constraint with multiplier involved (authored by martong).

Changed prior to commit:
  https://reviews.llvm.org/D77148?vs=267141&id=267232#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77148

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -149,3 +149,27 @@
   // bugpath-note{{TRUE}} \
   // bugpath-note{{'s' is <= 2}}
 }
+int __buf_size_arg_constraint_mul(const void *, size_t, size_t);
+void test_buf_size_concrete_with_multiplication() {
+  short buf[3]; // bugpath-note{{'buf' initialized here}}
+  __buf_size_arg_constraint_mul(buf, 4, sizeof(short)); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+}
+void test_buf_size_symbolic_with_multiplication(size_t s) {
+  short buf[3];
+  __buf_size_arg_constraint_mul(buf, s, sizeof(short));
+  clang_analyzer_eval(s * sizeof(short) <= 6); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}}
+}
+void test_buf_size_symbolic_and_offset_with_multiplication(size_t s) {
+  short buf[3];
+  __buf_size_arg_constraint_mul(buf + 1, s, sizeof(short));
+  clang_analyzer_eval(s * sizeof(short) <= 4); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -215,9 +215,16 @@
   // Represents a buffer argument with an additional size argument.
   // E.g. the first two arguments here:
   //   ctime_s(char *buffer, rsize_t bufsz, const time_t *time);
+  // Another example:
+  //   size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
+  //   // Here, ptr is the buffer, and its minimum size is `size * nmemb`.
   class BufferSizeConstraint : public ValueConstraint {
 // The argument which holds the size of the buffer.
 ArgNo SizeArgN;
+// The argument which is a multiplier to size. This is set in case of
+// `fread` like functions where the size is computed as a multiplication of
+// two arguments.
+llvm::Optional SizeMultiplierArgN;
 // The operator we use in apply. This is negated in negate().
 BinaryOperator::Opcode Op = BO_LE;
 
@@ -225,17 +232,27 @@
 BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize)
 : ValueConstraint(Buffer), SizeArgN(BufSize) {}
 
+BufferSizeConstraint(ArgNo Buffer, ArgNo BufSize, ArgNo BufSizeMultiplier)
+: ValueConstraint(Buffer), SizeArgN(BufSize),
+  SizeMultiplierArgN(BufSizeMultiplier) {}
+
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
   const Summary &Summary,
   CheckerContext &C) const override {
+  SValBuilder &SvalBuilder = C.getSValBuilder();
   // The buffer argument.
   SVal BufV = getArgSVal(Call, getArgNo());
   // The size argument.
   SVal SizeV = getArgSVal(Call, SizeArgN);
+  // Multiply with another argument if given.
+  if (SizeMultiplierArgN) {
+SVal SizeMulV = getArgSVal(Call, *SizeMultiplierArgN);
+SizeV = SvalBuilder.evalBinOp(State, BO_Mul, SizeV, SizeMulV,
+  Summary.getArgType(SizeArgN));
+  }
   // The dynamic size of the buffer argument, got from the analyzer engine.
   SVal BufDynSize = getDynamicSizeWithOffset(State, BufV);
 
-  SValBuilder &SvalBuilder = C.getSValBuilder();
   SVal Feasible = SvalBuilder.evalBinOp(State, Op, SizeV, BufDynSize,
 SvalBuilder.getContext().BoolTy);
   if (auto F = Feasible.getAs())
@@ -744,8 +761,8 @@
   IntRangeVector Ranges) {
 return std::make_shared(ArgN, Kind, Ranges);
   };
-  auto BufferSize = [](ArgNo BufArgN, ArgNo SizeArgN) {
-return std::make_shared(BufArgN, SizeArgN);
+  auto BufferSize = [](auto... Args) {
+return std::make_shared(Args...);
   };
   struct {
 auto operator()(RangeKind Kind, IntRangeVector Ranges) {
@@ -988,6 +1005,12 @@
 EvalCallAsPure)
 .ArgConstraint(
 Buffer

[PATCH] D79400: [CMAKE] Fix build failure when source directory is read only

2020-05-29 Thread Sameer Sahasrabuddhe via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG16fef6d0b46f: Fix build failure when source is read only 
(authored by pdhaliwal, committed by sameerds).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79400

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/include/llvm/Support/CMakeLists.txt


Index: llvm/include/llvm/Support/CMakeLists.txt
===
--- llvm/include/llvm/Support/CMakeLists.txt
+++ llvm/include/llvm/Support/CMakeLists.txt
@@ -5,12 +5,19 @@
 
 set(generate_vcs_version_script 
"${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
 
-if(llvm_vc AND LLVM_APPEND_VC_REV)
+if(LLVM_APPEND_VC_REV)
   set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
+
+  # A fake version file and is not expected to exist. It is being used to
+  # force regeneration of VCSRevision.h for source directory with no write
+  # permission available.
+  if (NOT llvm_vc)
+set(fake_version_inc "${CMAKE_CURRENT_BINARY_DIR}/__FakeVCSRevision.h")
+  endif()
 endif()
 
 # Create custom target to generate the VC revision include.
-add_custom_command(OUTPUT "${version_inc}"
+add_custom_command(OUTPUT "${version_inc}" "${fake_version_inc}"
   DEPENDS "${llvm_vc}" "${generate_vcs_version_script}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
@@ -22,5 +29,5 @@
   PROPERTIES GENERATED TRUE
  HEADER_FILE_ONLY TRUE)
 
-add_custom_target(llvm_vcsrevision_h DEPENDS "${version_inc}")
+add_custom_target(llvm_vcsrevision_h ALL DEPENDS "${version_inc}" 
"${fake_version_inc}")
 set_target_properties(llvm_vcsrevision_h PROPERTIES FOLDER "Misc")
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -2118,7 +2118,13 @@
 get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
 # Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
 if (NOT EXISTS "${git_dir}/logs/HEAD")
-  file(WRITE "${git_dir}/logs/HEAD" "")
+  execute_process(COMMAND ${CMAKE_COMMAND} -E touch HEAD
+WORKING_DIRECTORY "${git_dir}/logs"
+RESULT_VARIABLE touch_head_result
+ERROR_QUIET)
+  if (NOT touch_head_result EQUAL 0)
+return()
+  endif()
 endif()
 set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
   endif()


Index: llvm/include/llvm/Support/CMakeLists.txt
===
--- llvm/include/llvm/Support/CMakeLists.txt
+++ llvm/include/llvm/Support/CMakeLists.txt
@@ -5,12 +5,19 @@
 
 set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
 
-if(llvm_vc AND LLVM_APPEND_VC_REV)
+if(LLVM_APPEND_VC_REV)
   set(llvm_source_dir ${LLVM_MAIN_SRC_DIR})
+
+  # A fake version file and is not expected to exist. It is being used to
+  # force regeneration of VCSRevision.h for source directory with no write
+  # permission available.
+  if (NOT llvm_vc)
+set(fake_version_inc "${CMAKE_CURRENT_BINARY_DIR}/__FakeVCSRevision.h")
+  endif()
 endif()
 
 # Create custom target to generate the VC revision include.
-add_custom_command(OUTPUT "${version_inc}"
+add_custom_command(OUTPUT "${version_inc}" "${fake_version_inc}"
   DEPENDS "${llvm_vc}" "${generate_vcs_version_script}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
@@ -22,5 +29,5 @@
   PROPERTIES GENERATED TRUE
  HEADER_FILE_ONLY TRUE)
 
-add_custom_target(llvm_vcsrevision_h DEPENDS "${version_inc}")
+add_custom_target(llvm_vcsrevision_h ALL DEPENDS "${version_inc}" "${fake_version_inc}")
 set_target_properties(llvm_vcsrevision_h PROPERTIES FOLDER "Misc")
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -2118,7 +2118,13 @@
 get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
 # Some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD
 if (NOT EXISTS "${git_dir}/logs/HEAD")
-  file(WRITE "${git_dir}/logs/HEAD" "")
+  execute_process(COMMAND ${CMAKE_COMMAND} -E touch HEAD
+WORKING_DIRECTORY "${git_dir}/logs"
+RESULT_VARIABLE touch_head_result
+ERROR_QUIET)
+  if (NOT touch_head_result EQUAL 0)
+return()
+  endif()
 endif()
 set(${out_var} "${git_dir}/logs/HEAD" PARENT_SCOPE)
   endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 16506d7 - [analyzer] StdLibraryFunctionsChecker: Add sanity checks for constraints

2020-05-29 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-05-29T16:38:45+02:00
New Revision: 16506d789084fd037fc61d442da43dd5242872b7

URL: 
https://github.com/llvm/llvm-project/commit/16506d789084fd037fc61d442da43dd5242872b7
DIFF: 
https://github.com/llvm/llvm-project/commit/16506d789084fd037fc61d442da43dd5242872b7.diff

LOG: [analyzer] StdLibraryFunctionsChecker: Add sanity checks for constraints

Summary:
Once we found a matching FunctionDecl for the given summary then we
validate the given constraints against that FunctionDecl. E.g. we
validate that a NotNull constraint is applied only on arguments that
have pointer types.

This is needed because when we matched the signature of the summary we
were working with incomplete function types, i.e. some intricate type
could have been marked as `Irrelevant` in the signature.

Reviewers: NoQ, Szelethus, balazske

Subscribers: whisperity, xazax.hun, baloghadamsoftware, szepet, rnkovacs, 
a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, gamesh411, Charusso, steakhal, 
ASDenysPetrov, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index bd2f505849af..578f6ad46b84 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -64,10 +64,8 @@ using namespace clang::ento;
 namespace {
 class StdLibraryFunctionsChecker
 : public Checker {
-  /// Below is a series of typedefs necessary to define function specs.
-  /// We avoid nesting types here because each additional qualifier
-  /// would need to be repeated in every function spec.
-  struct Summary;
+
+  class Summary;
 
   /// Specify how much the analyzer engine should entrust modeling this 
function
   /// to us. If he doesn't, he performs additional invalidations.
@@ -114,10 +112,27 @@ class StdLibraryFunctionsChecker
 virtual ValueConstraintPtr negate() const {
   llvm_unreachable("Not implemented");
 };
+
+// Check whether the constraint is malformed or not. It is malformed if the
+// specified argument has a mismatch with the given FunctionDecl (e.g. the
+// arg number is out-of-range of the function's argument list).
+bool checkValidity(const FunctionDecl *FD) const {
+  const bool ValidArg = ArgN == Ret || ArgN < FD->getNumParams();
+  assert(ValidArg && "Arg out of range!");
+  if (!ValidArg)
+return false;
+  // Subclasses may further refine the validation.
+  return checkSpecificValidity(FD);
+}
 ArgNo getArgNo() const { return ArgN; }
 
   protected:
 ArgNo ArgN; // Argument to which we apply the constraint.
+
+/// Do polymorphic sanity check on the constraint.
+virtual bool checkSpecificValidity(const FunctionDecl *FD) const {
+  return true;
+}
   };
 
   /// Given a range, should the argument stay inside or outside this range?
@@ -168,6 +183,14 @@ class StdLibraryFunctionsChecker
   }
   return std::make_shared(Tmp);
 }
+
+bool checkSpecificValidity(const FunctionDecl *FD) const override {
+  const bool ValidArg =
+  getArgType(FD, ArgN)->isIntegralType(FD->getASTContext());
+  assert(ValidArg &&
+ "This constraint should be applied on an integral type");
+  return ValidArg;
+}
   };
 
   class ComparisonConstraint : public ValueConstraint {
@@ -210,6 +233,13 @@ class StdLibraryFunctionsChecker
   Tmp.CannotBeNull = !this->CannotBeNull;
   return std::make_shared(Tmp);
 }
+
+bool checkSpecificValidity(const FunctionDecl *FD) const override {
+  const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
+  assert(ValidArg &&
+ "This constraint should be applied only on a pointer type");
+  return ValidArg;
+}
   };
 
   // Represents a buffer argument with an additional size argument.
@@ -278,11 +308,52 @@ class StdLibraryFunctionsChecker
   typedef std::vector ConstraintSet;
 
   using ArgTypes = std::vector;
+
+  // A placeholder type, we use it whenever we do not care about the concrete
+  // type in a Signature.
+  const QualType Irrelevant{};
+  bool static isIrrelevant(QualType T) { return T.isNull(); }
+
+  // The signature of a function we want to describe with a summary. This is a
+  // concessive signature, meaning there may be irrelevant types in the
+  // signature which we do not check against a function with concrete types.
+  struct Signature {
+const ArgTypes ArgTys;
+const QualType RetTy;
+Signature(ArgTypes ArgTys, QualType RetTy) : ArgTys(ArgTys), RetTy(RetTy) {
+  assertRetTypeSuitableForSignature(RetTy);
+  for (size_t I = 0, E = ArgTys.size(); I 

[clang] 0e265e3 - Move unittest helpers to a shared location

2020-05-29 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-05-29T16:47:33+02:00
New Revision: 0e265e315784b4e47f984f8ed9fb7586130bacdc

URL: 
https://github.com/llvm/llvm-project/commit/0e265e315784b4e47f984f8ed9fb7586130bacdc
DIFF: 
https://github.com/llvm/llvm-project/commit/0e265e315784b4e47f984f8ed9fb7586130bacdc.diff

LOG: Move unittest helpers to a shared location

Summary:
unittests/AST/Language.h defines some helpers that we would like to
reuse in other tests, for example, in tests for syntax trees.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: mgorny, martong, cfe-commits

Tags: #clang

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

Added: 
clang/include/clang/Testing/CommandLineArgs.h
clang/lib/Testing/CMakeLists.txt
clang/lib/Testing/CommandLineArgs.cpp

Modified: 
clang/include/clang/module.modulemap
clang/lib/CMakeLists.txt
clang/unittests/AST/ASTImporterFixtures.h
clang/unittests/AST/CMakeLists.txt
clang/unittests/AST/MatchVerifier.h
clang/unittests/AST/StructuralEquivalenceTest.cpp

Removed: 
clang/unittests/AST/Language.cpp
clang/unittests/AST/Language.h



diff  --git a/clang/unittests/AST/Language.h 
b/clang/include/clang/Testing/CommandLineArgs.h
similarity index 76%
rename from clang/unittests/AST/Language.h
rename to clang/include/clang/Testing/CommandLineArgs.h
index da200ec8719f..0d2267f63ac5 100644
--- a/clang/unittests/AST/Language.h
+++ b/clang/include/clang/Testing/CommandLineArgs.h
@@ -1,4 +1,4 @@
-//===-- unittest/AST/Language.h - AST unit test support 
---===//
+//===--- CommandLineArgs.h 
===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,15 @@
 //
 
//===--===//
 //
-//  This file defines language options for AST unittests.
+//  This file defines language options for Clang unittests.
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_UNITTESTS_AST_LANGUAGE_H
-#define LLVM_CLANG_UNITTESTS_AST_LANGUAGE_H
+#ifndef LLVM_CLANG_TESTING_COMMANDLINEARGS_H
+#define LLVM_CLANG_TESTING_COMMANDLINEARGS_H
 
-#include 
 #include 
+#include 
 
 namespace clang {
 

diff  --git a/clang/include/clang/module.modulemap 
b/clang/include/clang/module.modulemap
index 15f891c15340..7549ff2e3bcd 100644
--- a/clang/include/clang/module.modulemap
+++ b/clang/include/clang/module.modulemap
@@ -152,6 +152,12 @@ module Clang_StaticAnalyzer_Frontend {
   module * { export * }
 }
 
+module Clang_Testing {
+  requires cplusplus
+  umbrella "Testing"
+  module * { export * }
+}
+
 module Clang_Tooling {
   requires cplusplus umbrella "Tooling" module * { export * }
   // FIXME: Exclude these headers to avoid pulling all of the AST matchers

diff  --git a/clang/lib/CMakeLists.txt b/clang/lib/CMakeLists.txt
index 0c03f5972b09..c2b6a5a4d5d4 100644
--- a/clang/lib/CMakeLists.txt
+++ b/clang/lib/CMakeLists.txt
@@ -24,3 +24,4 @@ if(CLANG_ENABLE_STATIC_ANALYZER)
   add_subdirectory(StaticAnalyzer)
 endif()
 add_subdirectory(Format)
+add_subdirectory(Testing)

diff  --git a/clang/lib/Testing/CMakeLists.txt 
b/clang/lib/Testing/CMakeLists.txt
new file mode 100644
index ..4a8d436aab66
--- /dev/null
+++ b/clang/lib/Testing/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_library(clangTesting
+  CommandLineArgs.cpp
+  )

diff  --git a/clang/unittests/AST/Language.cpp 
b/clang/lib/Testing/CommandLineArgs.cpp
similarity index 83%
rename from clang/unittests/AST/Language.cpp
rename to clang/lib/Testing/CommandLineArgs.cpp
index 3dd9659fc00e..58a61dade2ea 100644
--- a/clang/unittests/AST/Language.cpp
+++ b/clang/lib/Testing/CommandLineArgs.cpp
@@ -1,16 +1,12 @@
-//===-- unittest/AST/Language.cpp - AST unit test support 
-===//
+//===--- CommandLineArgs.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
 //
 
//===--===//
-//
-//  This file defines language options for AST unittests.
-//
-//===--===//
 
-#include "Language.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace clang {

diff  --git a/clang/unittests/AST/ASTImporterFixtures.h 
b/clang/unittests/AST/ASTImporterFixtures.h
index 619c3f590be4..4fbceef39384 100644
--- a/clang/unittests/AST/ASTImporterFixtures.h
+++ b/clang/unittests/AST/ASTImporterFixtures.h
@@ -19,11 +19,11 @@
 #include "

[clang] cf6cc66 - [OpenMP][SYCL] Improve diagnosing of unsupported types usage

2020-05-29 Thread Alexey Bader via cfe-commits

Author: Mariya Podchishchaeva
Date: 2020-05-29T18:00:48+03:00
New Revision: cf6cc6622b1416430f517850be9032788e39

URL: 
https://github.com/llvm/llvm-project/commit/cf6cc6622b1416430f517850be9032788e39
DIFF: 
https://github.com/llvm/llvm-project/commit/cf6cc6622b1416430f517850be9032788e39.diff

LOG: [OpenMP][SYCL] Improve diagnosing of unsupported types usage

Summary:
Diagnostic is emitted if some declaration of unsupported type
declaration is used inside device code.
Memcpy operations for structs containing member with unsupported type
are allowed. Fixed crash on attempt to emit diagnostic outside of the
functions.

The approach is generalized between SYCL and OpenMP.
CUDA/OMP deferred diagnostic interface is going to be used for SYCL device.

Reviewers: rsmith, rjmccall, ABataev, erichkeane, bader, jdoerfert, 
aaron.ballman

Reviewed By: jdoerfert

Subscribers: guansong, sstefan1, yaxunl, mgorny, bader, ebevhan, Anastasia, 
cfe-commits

Tags: #clang

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

Added: 
clang/lib/Sema/SemaSYCL.cpp
clang/test/SemaSYCL/float128.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/CMakeLists.txt
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Headers/nvptx_device_math_sin.c
clang/test/Headers/nvptx_device_math_sin.cpp
clang/test/OpenMP/nvptx_unsupported_type_codegen.cpp
clang/test/OpenMP/nvptx_unsupported_type_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 845e329033c3..63af9f42dfd3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10204,8 +10204,8 @@ def err_omp_invariant_or_linear_dependency : Error<
   "expected loop invariant expression or ' * %0 + ' 
kind of expression">;
 def err_omp_wrong_dependency_iterator_type : Error<
   "expected an integer or a pointer type of the outer loop counter '%0' for 
non-rectangular nests">;
-def err_omp_unsupported_type : Error <
-  "host requires %0 bit size %1 type support, but device '%2' does not support 
it">;
+def err_device_unsupported_type : Error <
+  "%0 requires %1 bit size %2 type support, but device '%3' does not support 
it">;
 def err_omp_lambda_capture_in_declare_target_not_to : Error<
   "variable captured in declare target region must appear in a to clause">;
 def err_omp_device_type_mismatch : Error<

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index dc7ee2ddd0b8..594c6e03aa38 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9868,10 +9868,6 @@ class Sema final {
   /// Pop OpenMP function region for non-capturing function.
   void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI);
 
-  /// Check if the expression is allowed to be used in expressions for the
-  /// OpenMP devices.
-  void checkOpenMPDeviceExpr(const Expr *E);
-
   /// Checks if a type or a declaration is disabled due to the owning extension
   /// being disabled, and emits diagnostic messages if it is disabled.
   /// \param D type or declaration to be checked.
@@ -11654,6 +11650,10 @@ class Sema final {
 
   DeviceDiagBuilder targetDiag(SourceLocation Loc, unsigned DiagID);
 
+  /// Check if the expression is allowed to be used in expressions for the
+  /// offloading devices.
+  void checkDeviceDecl(const ValueDecl *D, SourceLocation Loc);
+
   enum CUDAFunctionTarget {
 CFT_Device,
 CFT_Global,
@@ -12396,6 +12396,40 @@ class Sema final {
 ConstructorDestructor,
 BuiltinFunction
   };
+  /// Creates a DeviceDiagBuilder that emits the diagnostic if the current
+  /// context is "used as device code".
+  ///
+  /// - If CurLexicalContext is a kernel function or it is known that the
+  ///   function will be emitted for the device, emits the diagnostics
+  ///   immediately.
+  /// - If CurLexicalContext is a function and we are compiling
+  ///   for the device, but we don't know that this function will be codegen'ed
+  ///   for devive yet, creates a diagnostic which is emitted if and when we
+  ///   realize that the function will be codegen'ed.
+  ///
+  /// Example usage:
+  ///
+  /// Diagnose __float128 type usage only from SYCL device code if the current
+  /// target doesn't support it
+  /// if (!S.Context.getTargetInfo().hasFloat128Type() &&
+  /// S.getLangOpts().SYCLIsDevice)
+  ///   SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128";
+  DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
+
+  /// Check whether we're allowed to call Callee from the current context.
+  

[PATCH] D78933: [analyzer] RangeConstraintManager optimizations in comparison expressions

2020-05-29 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:32
+BO_GE < BO_EQ && BO_EQ < BO_NE,
+"This class relies on operators order. Rework it otherwise.");
+

+1 for this static assert!
It's good to ensure such assumptions, even if those are very unlikely to change



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:80
+
+  static size_t IndexFromOp(BinaryOperatorKind OP) {
+return static_cast(OP - BO_LT);

I would prefer function names to comply with LLVM coding standards (start with 
a verb and a lowercase letter
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:665
+
+auto SSE = dyn_cast(Sym);
+if (!SSE)

I believe that when we use auto we still try to be more verbose with it, so in 
this case it should be smth like `const auto *SSE`



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:689
+
+// Loop goes through the all columns except the last `UnknownX2`
+// We treat `UnknownX2` column separately at the end of the loop body.

Sorry for nitpicking, but it seems like the grammar is a bit off in the **the 
all columns except the last** part



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:690
+// Loop goes through the all columns except the last `UnknownX2`
+// We treat `UnknownX2` column separately at the end of the loop body.
+for (size_t i = 0; i < CmpOpTable.GetCmpOpCount(); ++i) {

I think that **treat** is not the best option here. Maybe smith like 
**process** will do?



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:696
+  const SymSymExpr *SymSym = SymMgr.getSymSymExpr(LHS, QueriedOP, RHS, T);
+  const RangeSet *RangeSet = State->get(SymSym);
+

Maybe we can name this constant somehow differently to be more verbose? 



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:700-705
+  if (!RangeSet) {
+const BinaryOperatorKind ROP =
+BinaryOperator::reverseComparisonOp(QueriedOP);
+SymSym = SymMgr.getSymSymExpr(RHS, ROP, LHS, T);
+RangeSet = State->get(SymSym);
+  }

Please, correct me if I'm wrong, but I thought that we are iterating over 
//all// comparison operators (excluding `<=>`), which means that if we don't 
find it on this iteration for let's say `x < y` then we'll find it (or already 
did) for `x > y`.  So, my question is - why do we have this clause then?

And it confuses me that `RangeSet` now corresponds to a //reversed// operator, 
while `QueriedOP` remains the same.

Maybe a good commentary explaining why we need it could help!


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

https://reviews.llvm.org/D78933



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


[PATCH] D80792: Move unittest helpers to a shared location

2020-05-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 267237.
gribozavr added a comment.

Fixed a clang-tidy warning about header guard format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80792

Files:
  clang/include/clang/Testing/CommandLineArgs.h
  clang/include/clang/module.modulemap
  clang/lib/CMakeLists.txt
  clang/lib/Testing/CMakeLists.txt
  clang/lib/Testing/CommandLineArgs.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/Language.cpp
  clang/unittests/AST/Language.h
  clang/unittests/AST/MatchVerifier.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -2,10 +2,10 @@
 #include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Host.h"
 
-#include "Language.h"
 #include "DeclMatcher.h"
 
 #include "gtest/gtest.h"
Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -21,8 +21,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "clang/Tooling/Tooling.h"
-#include "Language.h"
 #include "gtest/gtest.h"
 
 namespace clang {
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -26,7 +26,6 @@
   DeclTest.cpp
   EvaluateAsRValueTest.cpp
   ExternalASTSourceTest.cpp
-  Language.cpp
   NamedDeclPrinterTest.cpp
   RecursiveASTVisitorTest.cpp
   SizelessTypesTest.cpp
@@ -42,6 +41,7 @@
   clangBasic
   clangFrontend
   clangSerialization
+  clangTesting
   clangTooling
   )
 
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -19,11 +19,11 @@
 #include "clang/AST/ASTImporter.h"
 #include "clang/AST/ASTImporterSharedState.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 
 #include "DeclMatcher.h"
-#include "Language.h"
 
 #include 
 
Index: clang/lib/Testing/CommandLineArgs.cpp
===
--- clang/lib/Testing/CommandLineArgs.cpp
+++ clang/lib/Testing/CommandLineArgs.cpp
@@ -1,16 +1,12 @@
-//===-- unittest/AST/Language.cpp - AST unit test support -===//
+//===--- CommandLineArgs.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
 //
 //===--===//
-//
-//  This file defines language options for AST unittests.
-//
-//===--===//
 
-#include "Language.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace clang {
Index: clang/lib/Testing/CMakeLists.txt
===
--- /dev/null
+++ clang/lib/Testing/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_library(clangTesting
+  CommandLineArgs.cpp
+  )
Index: clang/lib/CMakeLists.txt
===
--- clang/lib/CMakeLists.txt
+++ clang/lib/CMakeLists.txt
@@ -24,3 +24,4 @@
   add_subdirectory(StaticAnalyzer)
 endif()
 add_subdirectory(Format)
+add_subdirectory(Testing)
Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -152,6 +152,12 @@
   module * { export * }
 }
 
+module Clang_Testing {
+  requires cplusplus
+  umbrella "Testing"
+  module * { export * }
+}
+
 module Clang_Tooling {
   requires cplusplus umbrella "Tooling" module * { export * }
   // FIXME: Exclude these headers to avoid pulling all of the AST matchers
Index: clang/include/clang/Testing/CommandLineArgs.h
===
--- clang/include/clang/Testing/CommandLineArgs.h
+++ clang/include/clang/Testing

[PATCH] D76077: [ARM] Add __bf16 as new Bfloat16 C Type

2020-05-29 Thread Ties Stuij via Phabricator via cfe-commits
stuij marked 9 inline comments as done.
stuij added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:74
+  BFloat16Width = BFloat16Align = 16;
+  BFloat16Format = &llvm::APFloat::BFloat();
+

SjoerdMeijer wrote:
> stuij wrote:
> > SjoerdMeijer wrote:
> > > Nit: we use bfloat16 everywhere, would `llvm::APFloat::BFloat16()` be 
> > > better for consistency?
> > In the IR world bfloat is consistently called bfloat, without the 16. I 
> > think this might turn into bikeshedding to justify if either one or both 
> > sides of the divide should or should not include the '16'. I can think of 
> > arguments to support the various options.
> > 
> > As I think there's no clear winner, I'd like to take the route of less 
> > effort and keep things as is.
> ah, I couldn't remember on which patch I commented on the bfloat16 vs bfloat 
> naming.
> Since everything is called bfloat16, from the architecture extension to the 
> source language type, I find this a bit of a missed opportunity to get the 
> names consistent. And I wouldn't say that naming of types is bikeshedding. 
> But maybe that's just me...
In general naming isn't bikeshedding. And I appreciate discussions on naming. 
I'm just afraid it might turn into bikeshedding. I do agree that such a remark 
isn't a very constructive to a conversation. Sorry.



Comment at: clang/test/CodeGen/arm-bf16-params-returns.c:5
+// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -target-abi aapcs -mfloat-abi 
softfp -target-feature +bf16 -target-feature +neon -emit-llvm -O2 -o - %s | opt 
-S -mem2reg -sroa | FileCheck %s --check-prefix=CHECK64-SOFTFP
+
+// function return types

SjoerdMeijer wrote:
> what happens with `-mfloat-abi=soft`. Does that deserve a test?
Yes, this one is interesting. I think we shouldn't support bfloat at all in 
combination with -mfloat-abi=soft. We don't support software emulation of 
bfloat instructions and all operations on bfloat are simd instructions.

It turns out cc1 will accept -mfloat-abi=soft with neon intrinsics, which will 
happily churn out neon instructions. This doesn't sound very soft. The driver 
will ignore -mfloat-abi=soft in certain combinations of cmdline instructions, 
but I haven't delved deep enough to know what's what.

GCC doesn't allow soft+neon combination. Unfortunately it will actually crash 
for just a bfloat type by itself, which is quite useless without intrinsics. 
The Arm GCC folks will raise a ticket on this with as proposed solution to not 
allow this combination.

As this issue seems bigger than just bfloat, and potentially there's driver 
code involved as well I thought it'd make sense to handle this in a separate 
patch.



Comment at: clang/test/CodeGen/arm-mangle-16bit-float.cpp:4
+
+// CHECK64: define {{.*}}void @_Z3foou6__bf16(half %b)
+// CHECK32: define {{.*}}void @_Z3foou6__bf16(i32 %b.coerce)

SjoerdMeijer wrote:
> LukeGeeson wrote:
> > SjoerdMeijer wrote:
> > > LukeGeeson wrote:
> > > > craig.topper wrote:
> > > > > How can bfloat16 be passed as half? Don't they have a different 
> > > > > format?
> > > > see the above comment about soft-abis
> > > Probably I am bit confused too now... are the three possible types that 
> > > we are expecing not bfloat, i32, or i16? 
> > Hi Sjoerd, Good spot here I forgot to add a default case somewhere, which 
> > means AArch32 didn't observe `-mfloat-abi softfp` by default - and hence 
> > used bfloat where i32 was expected. 
> > 
> > I have a local patch for this and will send to Ties to merge into this one 
> > :) 
> > 
> > 
> > We're not sure what you mean by i16 however?
> Ah, as I said, got confused. Now I see we use i16 for targets that don't 
> support bfloat16. So we probably need a test for that.
As I wrote above, I think we currently should not allow it as long as there are 
no targets that support bfloat and have use for this combination.



Comment at: clang/test/CodeGen/arm-mangle-bf16.cpp:3
+// RUN: %clang_cc1 -triple arm-arm-none-eabi -target-feature +bf16 -mfloat-abi 
hard -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK32-HARD
+// RUN: %clang_cc1 -triple arm-arm-none-eabi -target-feature +bf16 -mfloat-abi 
softfp -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK32-SOFTFP
+

SjoerdMeijer wrote:
> SjoerdMeijer wrote:
> > nit: if the name mangling is Independent of the float ABI, then you might 
> > as well one runline and the abi option.
> -> ...  then you might as well have only one runline and remove the abi 
> option.
yes, I thought it's better to be defensive here, in case the implementation 
changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76077



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

[PATCH] D80802: [RISCV] Upgrade RVV MC to v0.9.

2020-05-29 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai updated this revision to Diff 267239.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80802

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
  llvm/lib/Target/RISCV/RISCVInstrFormatsV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoV.td
  llvm/test/MC/RISCV/rvv/convert.s
  llvm/test/MC/RISCV/rvv/ext.s
  llvm/test/MC/RISCV/rvv/fothers.s
  llvm/test/MC/RISCV/rvv/invalid.s
  llvm/test/MC/RISCV/rvv/load.s
  llvm/test/MC/RISCV/rvv/mask.s
  llvm/test/MC/RISCV/rvv/snippet.s
  llvm/test/MC/RISCV/rvv/store.s
  llvm/test/MC/RISCV/rvv/vsetvl.s

Index: llvm/test/MC/RISCV/rvv/vsetvl.s
===
--- llvm/test/MC/RISCV/rvv/vsetvl.s
+++ llvm/test/MC/RISCV/rvv/vsetvl.s
@@ -8,12 +8,72 @@
 # RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-v < %s \
 # RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
 
+vsetvli a2, a0, e32,m1
+# CHECK-INST: vsetvli a2, a0, e32,m1
+# CHECK-ENCODING: [0x57,0x76,0x85,0x00]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 85 00 
+
+vsetvli a2, a0, e32,m2
+# CHECK-INST: vsetvli a2, a0, e32,m2
+# CHECK-ENCODING: [0x57,0x76,0x95,0x00]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 95 00 
+
 vsetvli a2, a0, e32,m4
 # CHECK-INST: vsetvli a2, a0, e32,m4
 # CHECK-ENCODING: [0x57,0x76,0xa5,0x00]
 # CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
 # CHECK-UNKNOWN: 57 76 a5 00 
 
+vsetvli a2, a0, e32,m8
+# CHECK-INST: vsetvli a2, a0, e32,m8
+# CHECK-ENCODING: [0x57,0x76,0xb5,0x00]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 b5 00 
+
+vsetvli a2, a0, e32,mf2
+# CHECK-INST: vsetvli a2, a0, e32,mf2
+# CHECK-ENCODING: [0x57,0x76,0xb5,0x02]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 b5 02 
+
+vsetvli a2, a0, e32,mf4
+# CHECK-INST: vsetvli a2, a0, e32,mf4
+# CHECK-ENCODING: [0x57,0x76,0xa5,0x02]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 a5 02 
+
+vsetvli a2, a0, e32,mf8
+# CHECK-INST: vsetvli a2, a0, e32,mf8
+# CHECK-ENCODING: [0x57,0x76,0x95,0x02]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 95 02 
+
+vsetvli a2, a0, e32,m1,ta,ma
+# CHECK-INST: vsetvli a2, a0, e32,m1,ta,ma
+# CHECK-ENCODING: [0x57,0x76,0x85,0x0c]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 85 0c 
+
+vsetvli a2, a0, e32,m1,tu,ma
+# CHECK-INST: vsetvli a2, a0, e32,m1,tu,ma
+# CHECK-ENCODING: [0x57,0x76,0x85,0x08]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 85 08 
+
+vsetvli a2, a0, e32,m1,ta,mu
+# CHECK-INST: vsetvli a2, a0, e32,m1,ta,mu
+# CHECK-ENCODING: [0x57,0x76,0x85,0x04]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 85 04 
+
+vsetvli a2, a0, e32,m1,tu,mu
+# CHECK-INST: vsetvli a2, a0, e32,m1
+# CHECK-ENCODING: [0x57,0x76,0x85,0x00]
+# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
+# CHECK-UNKNOWN: 57 76 85 00 
+
 vsetvl a2, a0, a1
 # CHECK-INST: vsetvl a2, a0, a1
 # CHECK-ENCODING: [0x57,0x76,0xb5,0x80]
Index: llvm/test/MC/RISCV/rvv/store.s
===
--- llvm/test/MC/RISCV/rvv/store.s
+++ llvm/test/MC/RISCV/rvv/store.s
@@ -8,200 +8,296 @@
 # RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-v < %s \
 # RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
 
-vsb.v v24, (a0), v0.t
-# CHECK-INST: vsb.v v24, (a0), v0.t
+vse8.v v24, (a0), v0.t
+# CHECK-INST: vse8.v v24, (a0), v0.t
 # CHECK-ENCODING: [0x27,0x0c,0x05,0x00]
 # CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
 # CHECK-UNKNOWN: 27 0c 05 00 
 
-vsb.v v24, (a0)
-# CHECK-INST: vsb.v v24, (a0)
+vse8.v v24, (a0)
+# CHECK-INST: vse8.v v24, (a0)
 # CHECK-ENCODING: [0x27,0x0c,0x05,0x02]
 # CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
 # CHECK-UNKNOWN: 27 0c 05 02 
 
-vsh.v v24, (a0), v0.t
-# CHECK-INST: vsh.v v24, (a0), v0.t
+vse16.v v24, (a0), v0.t
+# CHECK-INST: vse16.v v24, (a0), v0.t
 # CHECK-ENCODING: [0x27,0x5c,0x05,0x00]
 # CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions)
 # CHECK-UNKNOWN: 27 5c 05 00 
 
-vsh.v v24, (a0)
-# CHECK-INST: vsh.v v24, (a0)
+vse16.v v24, (a0)
+# CHECK-INST: vse16.v v24, (a0)
 # CHECK-ENCODING: [0x27,0x5c,0x05,0x02]
 # CHECK

[PATCH] D80627: [clang-format] Create a python documentation tool to generate a summary of the clang-format status for the whole of the LLVM project

2020-05-29 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

That looks nicer indeed. Thanks.
Just some minor nitty-gritty comments.




Comment at: clang/docs/tools/generate_formatted_state.py:52
+path = os.path.relpath(root, LLVM_DIR)
+if "/test/" in path:
+continue

MyDeveloperDay wrote:
> curdeius wrote:
> > That doesn't work on Windows because of slashes. You doesn't skip 
> > `unittests` (present at least in clang and llvm).
> So unit tests is something that I I think needs to be clang-formatted, this 
> is because often we are actively editing in there, (I use format on save) and 
> so having clean tests is super important
> 
> The tests directories normally have 100's of small snippets of code and some 
> may even be testing unformatted code deliberately, these files are often made 
> once and not continuously edited, (whilst it would be good to have them 
> clean, I wanted to give ourselves a fighting chance!)
> 
> Point taken about Windows, whilst I develop myself on Windows I use cygwin 
> which is why it probably worked.
OK, I agree for unittests. But then one could argue that the same should apply 
for test, nope?



Comment at: clang/docs/tools/generate_formatted_state.py:30
+.good {{ background-color: #2CCCFF }}
+
+

Nit: wrong indentation.



Comment at: clang/docs/tools/generate_formatted_state.py:74
+continue
+head, tail = os.path.split(root)
+while head:

Both `tail` and `_tail` seem unused. You can change to `_`.


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

https://reviews.llvm.org/D80627



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


[PATCH] D80016: [analyzer] StdLibraryFunctionsChecker: Add support to lookup types

2020-05-29 Thread Balázs Kéri via Phabricator via cfe-commits
balazske accepted this revision.
balazske added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:739
 
+  Optional FileTy = lookupType("FILE", ACtx);
+  Optional FilePtrTy, FilePtrRestrictTy;

There is a `ASTContext::getFILEType` that can be used for this. (But if more 
types are needed the `lookupType` must be used again.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80016



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


[PATCH] D80804: [AMDGPU] Expose llvm atomic inc/dec instructions as clang builtins for AMDGPU target

2020-05-29 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam created this revision.
saiislam added reviewers: arsenm, sameerds, JonChesterfield, jdoerfert.
Herald added subscribers: cfe-commits, kerbowa, jfb, t-tye, tpr, dstuttard, 
yaxunl, nhaehnle, wdng, jvesely, kzhuravl.
Herald added a project: clang.
saiislam added parent revisions: D75917: Expose llvm fence instruction as clang 
intrinsic, D73076: [libomptarget] Implement most hip atomic functions in terms 
of intrinsics.

__builtin_amdgcn_atomic_inc(int *Ptr, int Val, unsigned MemoryOrdering,

const char *SyncScope, bool IsVolatile)

__builtin_amdgcn_atomic_dec(int *Ptr, int Val, unsigned MemoryOrdering,

  const char *SyncScope, bool IsVolatile)

First, second, and fifth argument gets transparently passed to the llvm
intruction. The third argument of this builtin is one of the memory-ordering
specifiers ATOMIC_ACQUIRE, ATOMIC_RELEASE, ATOMIC_ACQ_REL, or ATOMIC_SEQ_CST
following C++11 memory model semantics. This is mapped to corresponding
LLVM atomic memory ordering for the atomic inc/dec instruction using LLVM
atomic C ABI. The fourth argument is an AMDGPU-specific synchronization scope
defined as string.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80804

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
  clang/test/Sema/builtin-amdgcn-atomic-inc-dec-failure.cpp
  clang/test/SemaOpenCL/builtins-amdgcn-error.cl

Index: clang/test/SemaOpenCL/builtins-amdgcn-error.cl
===
--- clang/test/SemaOpenCL/builtins-amdgcn-error.cl
+++ clang/test/SemaOpenCL/builtins-amdgcn-error.cl
@@ -144,3 +144,27 @@
   __builtin_amdgcn_s_setreg(x, 0); // expected-error {{argument to '__builtin_amdgcn_s_setreg' must be a constant integer}}
   __builtin_amdgcn_s_setreg(x, y); // expected-error {{argument to '__builtin_amdgcn_s_setreg' must be a constant integer}}
 }
+
+void test_atomic_inc() {
+  int val = 17;
+  val = __builtin_amdgcn_atomic_inc(&val, val, __ATOMIC_SEQ_CST + 1, "workgroup", true); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_inc(&val, val, __ATOMIC_ACQUIRE - 1, "workgroup", true); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_inc(4); // expected-error {{too few arguments to function call, expected 5}}
+  val = __builtin_amdgcn_atomic_inc(&val, val, 4, 4, 4, 4); // expected-error {{too many arguments to function call, expected 5}}
+  val = __builtin_amdgcn_atomic_inc(&val, val, 3.14, "", true); // expected-warning {{implicit conversion from 'double' to 'unsigned int' changes value from 3.14 to 3}}
+  val = __builtin_amdgcn_atomic_inc(&val, val, __ATOMIC_ACQUIRE, 5, true); // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'}}
+  const char ptr[] = "workgroup";
+  val = __builtin_amdgcn_atomic_inc(&val, val, __ATOMIC_ACQUIRE, ptr, true); // expected-error {{expression is not a string literal}}
+}
+
+void test_atomic_dec() {
+  int val = 17;
+  val = __builtin_amdgcn_atomic_dec(&val, val, __ATOMIC_SEQ_CST + 1, "workgroup", true); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_dec(&val, val, __ATOMIC_ACQUIRE - 1, "workgroup", true); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_dec(4); // expected-error {{too few arguments to function call, expected 5}}
+  val = __builtin_amdgcn_atomic_dec(&val, val, 4, 4, 4, 4); // expected-error {{too many arguments to function call, expected 5}}
+  val = __builtin_amdgcn_atomic_dec(&val, val, 3.14, "", true); // expected-warning {{implicit conversion from 'double' to 'unsigned int' changes value from 3.14 to 3}}
+  val = __builtin_amdgcn_atomic_dec(&val, val, __ATOMIC_ACQUIRE, 5, true); // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'}}
+  const char ptr[] = "workgroup";
+  val = __builtin_amdgcn_atomic_dec(&val, val, __ATOMIC_ACQUIRE, ptr, true); // expected-error {{expression is not a string literal}}
+}
Index: clang/test/Sema/builtin-amdgcn-atomic-inc-dec-failure.cpp
===
--- /dev/null
+++ clang/test/Sema/builtin-amdgcn-atomic-inc-dec-failure.cpp
@@ -0,0 +1,12 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: not %clang_cc1 %s -x hip -fcuda-is-device -o - -emit-llvm -triple=amdgcn-amd-amdhsa 2>&1 | FileCheck %s
+
+void test_host() {
+  int val;
+
+  // CHECK: error: reference to __device__ function '__builtin_amdgcn_atomic_inc' in __host__ function
+  val = __builtin_amdgcn_atomic_inc(&val, val, __ATOMIC_SEQ_CST, "", true);
+
+  // CHECK: error: referen

[PATCH] D80627: [clang-format] Create a python documentation tool to generate a summary of the clang-format status for the whole of the LLVM project

2020-05-29 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/docs/tools/generate_formatted_state.py:54
+
+table_row = """   * - {path}
+ - {count}

Another nit: I prefer writing `"""\` as it nicely aligns with subsequent lines.


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

https://reviews.llvm.org/D80627



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


[PATCH] D77658: [analyzer] StdLibraryFunctionsChecker: Add sanity checks for constraints

2020-05-29 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG16506d789084: [analyzer] StdLibraryFunctionsChecker: Add 
sanity checks for constraints (authored by martong).

Changed prior to commit:
  https://reviews.llvm.org/D77658?vs=267177&id=267243#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77658

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -64,10 +64,8 @@
 namespace {
 class StdLibraryFunctionsChecker
 : public Checker {
-  /// Below is a series of typedefs necessary to define function specs.
-  /// We avoid nesting types here because each additional qualifier
-  /// would need to be repeated in every function spec.
-  struct Summary;
+
+  class Summary;
 
   /// Specify how much the analyzer engine should entrust modeling this function
   /// to us. If he doesn't, he performs additional invalidations.
@@ -114,10 +112,27 @@
 virtual ValueConstraintPtr negate() const {
   llvm_unreachable("Not implemented");
 };
+
+// Check whether the constraint is malformed or not. It is malformed if the
+// specified argument has a mismatch with the given FunctionDecl (e.g. the
+// arg number is out-of-range of the function's argument list).
+bool checkValidity(const FunctionDecl *FD) const {
+  const bool ValidArg = ArgN == Ret || ArgN < FD->getNumParams();
+  assert(ValidArg && "Arg out of range!");
+  if (!ValidArg)
+return false;
+  // Subclasses may further refine the validation.
+  return checkSpecificValidity(FD);
+}
 ArgNo getArgNo() const { return ArgN; }
 
   protected:
 ArgNo ArgN; // Argument to which we apply the constraint.
+
+/// Do polymorphic sanity check on the constraint.
+virtual bool checkSpecificValidity(const FunctionDecl *FD) const {
+  return true;
+}
   };
 
   /// Given a range, should the argument stay inside or outside this range?
@@ -168,6 +183,14 @@
   }
   return std::make_shared(Tmp);
 }
+
+bool checkSpecificValidity(const FunctionDecl *FD) const override {
+  const bool ValidArg =
+  getArgType(FD, ArgN)->isIntegralType(FD->getASTContext());
+  assert(ValidArg &&
+ "This constraint should be applied on an integral type");
+  return ValidArg;
+}
   };
 
   class ComparisonConstraint : public ValueConstraint {
@@ -210,6 +233,13 @@
   Tmp.CannotBeNull = !this->CannotBeNull;
   return std::make_shared(Tmp);
 }
+
+bool checkSpecificValidity(const FunctionDecl *FD) const override {
+  const bool ValidArg = getArgType(FD, ArgN)->isPointerType();
+  assert(ValidArg &&
+ "This constraint should be applied only on a pointer type");
+  return ValidArg;
+}
   };
 
   // Represents a buffer argument with an additional size argument.
@@ -278,11 +308,52 @@
   typedef std::vector ConstraintSet;
 
   using ArgTypes = std::vector;
+
+  // A placeholder type, we use it whenever we do not care about the concrete
+  // type in a Signature.
+  const QualType Irrelevant{};
+  bool static isIrrelevant(QualType T) { return T.isNull(); }
+
+  // The signature of a function we want to describe with a summary. This is a
+  // concessive signature, meaning there may be irrelevant types in the
+  // signature which we do not check against a function with concrete types.
+  struct Signature {
+const ArgTypes ArgTys;
+const QualType RetTy;
+Signature(ArgTypes ArgTys, QualType RetTy) : ArgTys(ArgTys), RetTy(RetTy) {
+  assertRetTypeSuitableForSignature(RetTy);
+  for (size_t I = 0, E = ArgTys.size(); I != E; ++I) {
+QualType ArgTy = ArgTys[I];
+assertArgTypeSuitableForSignature(ArgTy);
+  }
+}
+bool matches(const FunctionDecl *FD) const;
+
+  private:
+static void assertArgTypeSuitableForSignature(QualType T) {
+  assert((T.isNull() || !T->isVoidType()) &&
+ "We should have no void types in the spec");
+  assert((T.isNull() || T.isCanonical()) &&
+ "We should only have canonical types in the spec");
+}
+static void assertRetTypeSuitableForSignature(QualType T) {
+  assert((T.isNull() || T.isCanonical()) &&
+ "We should only have canonical types in the spec");
+}
+  };
+
+  static QualType getArgType(const FunctionDecl *FD, ArgNo ArgN) {
+assert(FD && "Function must be set");
+QualType T = (ArgN == Ret)
+ ? FD->getReturnType().getCanonicalType()
+ : FD->getParamDecl(ArgN)->getType().getCanonicalType();
+return T;
+  }
+
   using Cases = std::vecto

  1   2   3   >