[PATCH] D78085: [AST] Fix recovery-expr crash on invalid aligned attr.

2020-04-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.

crash stack:

  lang: tools/clang/include/clang/AST/AttrImpl.inc:1490: unsigned int 
clang::AlignedAttr::getAlignment(clang::ASTContext &) const: Assertion 
`!isAlignmentDependent()' failed.
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.  Program arguments: ./bin/clang -cc1 -std=c++1y -ast-dump 
-frecovery-ast -fcxx-exceptions /tmp/t4.cpp
  1.  /tmp/t4.cpp:3:31: current parser token ';'
   #0 0x02530cff llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
llvm-project/llvm/lib/Support/Unix/Signals.inc:564:13
   #1 0x0252ee30 llvm::sys::RunSignalHandlers() 
llvm-project/llvm/lib/Support/Signals.cpp:69:18
   #2 0x0253126c SignalHandler(int) 
llvm-project/llvm/lib/Support/Unix/Signals.inc:396:3
   #3 0x7f86964d0520 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x13520)
   #4 0x7f8695f9ff61 raise 
/build/glibc-oCLvUT/glibc-2.29/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
   #5 0x7f8695f8b535 abort 
/build/glibc-oCLvUT/glibc-2.29/stdlib/abort.c:81:7
   #6 0x7f8695f8b40f _nl_load_domain 
/build/glibc-oCLvUT/glibc-2.29/intl/loadmsgcat.c:1177:9
   #7 0x7f8695f98b92 (/lib/x86_64-linux-gnu/libc.so.6+0x32b92)
   #8 0x04503d9f llvm::APInt::getZExtValue() const 
llvm-project/llvm/include/llvm/ADT/APInt.h:1623:5
   #9 0x04503d9f clang::AlignedAttr::getAlignment(clang::ASTContext&) 
const llvm-project/build/tools/clang/include/clang/AST/AttrImpl.inc:1492:0


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78085

Files:
  clang/lib/AST/DeclBase.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaCXX/invalid-aligned-attr.cpp


Index: clang/test/SemaCXX/invalid-aligned-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-aligned-attr.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -frecovery-ast -verify %s
+// RUN: %clang_cc1 -verify %s
+
+struct alignas(invalid()) Foo {}; // expected-error {{use of undeclared 
identifier}}
+
+constexpr int k = alignof(Foo);
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -97,4 +97,9 @@
 void test(int x) {
   foo.abc;
   foo->func(x);
-}
\ No newline at end of file
+}
+
+// CHECK: |-AlignedAttr {{.*}} alignas
+// CHECK-NEXT:| `-RecoveryExpr {{.*}} contains-errors
+// CHECK-NEXT:|   `-UnresolvedLookupExpr {{.*}} 'invalid'
+struct alignas(invalid()) Aligned {};
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -396,8 +396,10 @@
   const AttrVec &V = getAttrs();
   ASTContext &Ctx = getASTContext();
   specific_attr_iterator I(V.begin()), E(V.end());
-  for (; I != E; ++I)
-Align = std::max(Align, I->getAlignment(Ctx));
+  for (; I != E; ++I) {
+if (!I->isAlignmentDependent())
+  Align = std::max(Align, I->getAlignment(Ctx));
+  }
   return Align;
 }
 


Index: clang/test/SemaCXX/invalid-aligned-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-aligned-attr.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -frecovery-ast -verify %s
+// RUN: %clang_cc1 -verify %s
+
+struct alignas(invalid()) Foo {}; // expected-error {{use of undeclared identifier}}
+
+constexpr int k = alignof(Foo);
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -97,4 +97,9 @@
 void test(int x) {
   foo.abc;
   foo->func(x);
-}
\ No newline at end of file
+}
+
+// CHECK: |-AlignedAttr {{.*}} alignas
+// CHECK-NEXT:| `-RecoveryExpr {{.*}} contains-errors
+// CHECK-NEXT:|   `-UnresolvedLookupExpr {{.*}} 'invalid'
+struct alignas(invalid()) Aligned {};
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -396,8 +396,10 @@
   const AttrVec &V = getAttrs();
   ASTContext &Ctx = getASTContext();
   specific_attr_iterator I(V.begin()), E(V.end());
-  for (; I != E; ++I)
-Align = std::max(Align, I->getAlignment(Ctx));
+  for (; I != E; ++I) {
+if (!I->isAlignmentDependent())
+  Align = std::max(Align, I->getAlignment(Ctx));
+  }
   return Align;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 37ac1c1 - [Analyzer][VLASize] Support multi-dimensional arrays.

2020-04-14 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2020-04-14T10:26:51+02:00
New Revision: 37ac1c19bed7b7d22e9312dfa61e7a4506ed4e49

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

LOG: [Analyzer][VLASize] Support multi-dimensional arrays.

Summary:
Check the size constraints for every (variable) dimension of the array.
Try to compute array size by multiplying size for every dimension.

Reviewers: Szelethus, martong, baloghadamsoftware, gamesh411

Reviewed By: Szelethus, martong

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

Tags: #clang

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
clang/test/Analysis/vla.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
index 21e8b9653039..0c7961a2a28b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -34,6 +34,9 @@ class VLASizeChecker : public Checker< 
check::PreStmt > {
   mutable std::unique_ptr BT;
   enum VLASize_Kind { VLA_Garbage, VLA_Zero, VLA_Tainted, VLA_Negative };
 
+  ProgramStateRef checkVLASize(CheckerContext &C, ProgramStateRef State,
+   const Expr *SizeE) const;
+
   void reportBug(VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State,
  CheckerContext &C,
  std::unique_ptr Visitor = nullptr) const;
@@ -43,6 +46,65 @@ class VLASizeChecker : public Checker< 
check::PreStmt > {
 };
 } // end anonymous namespace
 
+ProgramStateRef VLASizeChecker::checkVLASize(CheckerContext &C,
+ ProgramStateRef State,
+ const Expr *SizeE) const {
+  SVal SizeV = C.getSVal(SizeE);
+
+  if (SizeV.isUndef()) {
+reportBug(VLA_Garbage, SizeE, State, C);
+return nullptr;
+  }
+
+  // See if the size value is known. It can't be undefined because we would 
have
+  // warned about that already.
+  if (SizeV.isUnknown())
+return nullptr;
+
+  // Check if the size is tainted.
+  if (isTainted(State, SizeV)) {
+reportBug(VLA_Tainted, SizeE, nullptr, C,
+  std::make_unique(SizeV));
+return nullptr;
+  }
+
+  // Check if the size is zero.
+  DefinedSVal SizeD = SizeV.castAs();
+
+  ProgramStateRef StateNotZero, StateZero;
+  std::tie(StateNotZero, StateZero) = State->assume(SizeD);
+
+  if (StateZero && !StateNotZero) {
+reportBug(VLA_Zero, SizeE, StateZero, C);
+return nullptr;
+  }
+
+  // From this point on, assume that the size is not zero.
+  State = StateNotZero;
+
+  // Check if the size is negative.
+  SValBuilder &SVB = C.getSValBuilder();
+
+  QualType SizeTy = SizeE->getType();
+  DefinedOrUnknownSVal Zero = SVB.makeZeroVal(SizeTy);
+
+  SVal LessThanZeroVal = SVB.evalBinOp(State, BO_LT, SizeD, Zero, SizeTy);
+  if (Optional LessThanZeroDVal =
+  LessThanZeroVal.getAs()) {
+ConstraintManager &CM = C.getConstraintManager();
+ProgramStateRef StatePos, StateNeg;
+
+std::tie(StateNeg, StatePos) = CM.assumeDual(State, *LessThanZeroDVal);
+if (StateNeg && !StatePos) {
+  reportBug(VLA_Negative, SizeE, State, C); // FIXME: StateNeg ?
+  return nullptr;
+}
+State = StatePos;
+  }
+
+  return State;
+}
+
 void VLASizeChecker::reportBug(
 VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State,
 CheckerContext &C, std::unique_ptr Visitor) const {
@@ -89,98 +151,72 @@ void VLASizeChecker::checkPreStmt(const DeclStmt *DS, 
CheckerContext &C) const {
 return;
 
   ASTContext &Ctx = C.getASTContext();
+  SValBuilder &SVB = C.getSValBuilder();
+  ProgramStateRef State = C.getState();
+
   const VariableArrayType *VLA = Ctx.getAsVariableArrayType(VD->getType());
   if (!VLA)
 return;
 
-  // FIXME: Handle multi-dimensional VLAs.
-  const Expr *SE = VLA->getSizeExpr();
-  ProgramStateRef state = C.getState();
-  SVal sizeV = C.getSVal(SE);
-
-  if (sizeV.isUndef()) {
-reportBug(VLA_Garbage, SE, state, C);
-return;
-  }
-
-  // See if the size value is known. It can't be undefined because we would 
have
-  // warned about that already.
-  if (sizeV.isUnknown())
-return;
-
-  // Check if the size is tainted.
-  if (isTainted(state, sizeV)) {
-reportBug(VLA_Tainted, SE, nullptr, C,
-  std::make_unique(sizeV));
-return;
-  }
-
-  // Check if the size is zero.
-  DefinedSVal sizeD = sizeV.castAs();
-
-  ProgramStateRef stateNotZero, stateZero;
-  std::tie(stateNotZero, stateZero) = state->assume(sizeD);
-
-  if (stateZero &&

[PATCH] D78089: [dexp] NFC: Change positional argument format

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
kbobyrev updated this revision to Diff 257224.
kbobyrev added a comment.
kbobyrev edited the summary of this revision.

%s/PATH TO INDEX/INDEX FILE/g for clarity


Before:

  USAGE: dexp [options] --index-path Path to the index

After:

  USAGE: dexp [options] 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78089

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp


Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -26,8 +26,7 @@
 namespace clangd {
 namespace {
 
-llvm::cl::opt IndexPath("index-path",
- llvm::cl::desc("Path to the index"),
+llvm::cl::opt IndexPath(llvm::cl::desc(""),
  llvm::cl::Positional, llvm::cl::Required);
 
 llvm::cl::opt


Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -26,8 +26,7 @@
 namespace clangd {
 namespace {
 
-llvm::cl::opt IndexPath("index-path",
- llvm::cl::desc("Path to the index"),
+llvm::cl::opt IndexPath(llvm::cl::desc(""),
  llvm::cl::Positional, llvm::cl::Required);
 
 llvm::cl::opt
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

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

I looked at the graphical CFG dump and observed that the added code makes the 
same parts appear that are there in a VLA declaration but missing if a VLA 
typedef is used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809



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


[PATCH] D78089: [dexp] NFC: Change positional argument format

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 257224.
kbobyrev added a comment.

%s/PATH TO INDEX/INDEX FILE/g for clarity


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78089

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp


Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -26,8 +26,7 @@
 namespace clangd {
 namespace {
 
-llvm::cl::opt IndexPath("index-path",
- llvm::cl::desc("Path to the index"),
+llvm::cl::opt IndexPath(llvm::cl::desc(""),
  llvm::cl::Positional, llvm::cl::Required);
 
 llvm::cl::opt


Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -26,8 +26,7 @@
 namespace clangd {
 namespace {
 
-llvm::cl::opt IndexPath("index-path",
- llvm::cl::desc("Path to the index"),
+llvm::cl::opt IndexPath(llvm::cl::desc(""),
  llvm::cl::Positional, llvm::cl::Required);
 
 llvm::cl::opt
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77982: [Windows SEH] Fix the frame-ptr of a nested-filter within a _finally

2020-04-14 Thread Ten Tzen via Phabricator via cfe-commits
tentzen updated this revision to Diff 257227.
tentzen added a comment.

Do not use name comparison to locate parent's alloca of frame-pointer-addr. 
search parent's LocalDeclMap instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77982

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/windows-seh-filter-inFinally.c

Index: clang/test/CodeGen/windows-seh-filter-inFinally.c
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-filter-inFinally.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fms-extensions -Wno-implicit-function-declaration -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: %[[dst:[0-9-]+]] = call i8* @llvm.eh.recoverfp(i8* bitcast (void (i8, i8*)* @"?fin$0@0@main@@" to i8*), i8* %frame_pointer)
+// CHECK-NEXT: %[[dst1:[0-9-]+]] = call i8* @llvm.localrecover(i8* bitcast (void (i8, i8*)* @"?fin$0@0@main@@" to i8*), i8* %[[dst]], i32 0)
+// CHECK-NEXT: %[[dst2:[0-9-]+]] = bitcast i8* %[[dst1]] to i8**
+// CHECK-NEXT: = load i8*, i8** %[[dst2]], align 8
+
+int
+main(int argc, char *argv[])
+{
+int Counter = 0;
+//
+// Try/except within the finally clause of a try/finally.
+//
+__try {
+  Counter -= 1;
+}
+__finally {
+  __try {
+Counter += 2;
+// RtlRaiseStatus(STATUS_INTEGER_OVERFLOW);
+  } __except(Counter) {
+__try {
+  Counter += 3;
+}
+__finally {
+  if (abnormal_termination() == 1) {
+Counter += 5;
+  }
+}
+  }
+}
+// expect Counter == 9
+return 1;
+}
+
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -367,6 +367,9 @@
   CodeGenModule &CGM;  // Per-module state.
   const TargetInfo &Target;
 
+  // For EH/SEH outlined funclets, this field points to parent's CGF
+  CodeGenFunction *ParentCGF = nullptr;
+
   typedef std::pair ComplexPairTy;
   LoopInfoStack LoopStack;
   CGBuilderTy Builder;
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -1794,6 +1794,48 @@
 llvm::Constant *ParentI8Fn =
 llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
 ParentFP = Builder.CreateCall(RecoverFPIntrin, {ParentI8Fn, EntryFP});
+
+// if the parent is a _finally, the passed-in ParentFP is the FP
+// of parent _finally, not Establisher's FP (FP of outermost function).
+// Establkisher FP is 2nd paramenter passed into parent _finally.
+// Fortunately, it's always saved in parent's frame. The following
+// code retrieves it, and escapes it so that spill instruction won't be
+// optimized away.
+if (ParentCGF.ParentCGF != nullptr) {
+  // Locate and escape Parent's frame_pointer.addr alloca
+  // Depending on target, should be 1st/2nd one in LocalDeclMap.
+  // Let's just scan ImplicitParamDecl with VoidPtrTy.
+  llvm::AllocaInst *FramePtrAddrAlloca = nullptr;
+  for (auto &I : ParentCGF.LocalDeclMap) {
+const VarDecl *D = cast(I.first);
+if (isa(D) &&
+D->getType() == getContext().VoidPtrTy) {
+  assert(D->getName().startswith("frame_pointer"));
+  FramePtrAddrAlloca = cast(I.second.getPointer());
+  break;
+}
+  }
+  assert(FramePtrAddrAlloca);
+  auto InsertPair = ParentCGF.EscapedLocals.insert(
+  std::make_pair(FramePtrAddrAlloca, ParentCGF.EscapedLocals.size()));
+  int FrameEscapeIdx = InsertPair.first->second;
+
+  // an example of a filter's prolog::
+  // %0 = call i8* @llvm.eh.recoverfp(bitcast(@"?fin$0@0@main@@"),..)
+  // %1 = call i8* @llvm.localrecover(bitcast(@"?fin$0@0@main@@"),..)
+  // %2 = bitcast i8* %1 to i8**
+  // %3 = load i8*, i8* *%2, align 8
+  //   ==> %3 is the frame-pointer of outermost host function
+  llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration(
+  &CGM.getModule(), llvm::Intrinsic::localrecover);
+  llvm::Constant *ParentI8Fn =
+  llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
+  ParentFP = Builder.CreateCall(
+  FrameRecoverFn, {ParentI8Fn, ParentFP,
+   llvm::ConstantInt::get(Int32Ty, FrameEscapeIdx)});
+  ParentFP = Builder.CreateBitCast(ParentFP, CGM.VoidPtrPtrTy);
+  ParentFP = Builder.CreateLoad(Address(ParentFP, getPointerAlign()));
+}
   }
 
   // Create llvm.localrecover calls for all captures.
@@ -1992,6 +2034,7 @@
 
 void CodeGenFunction::EnterSEHTryStmt(const SEHTryStmt &S) {
   CodeGenFunction HelperCGF(CGM, /*suppressNewContext=*/true);
+  HelperCGF.Pare

[PATCH] D77982: [Windows SEH] Fix the frame-ptr of a nested-filter within a _finally

2020-04-14 Thread Ten Tzen via Phabricator via cfe-commits
tentzen added a comment.

In D77982#1978105 , @efriedma wrote:

> Again, using the name isn't reliable.  Among other things, in release builds, 
> IR values don't have names at all.


ok, will fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77982



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


[PATCH] D78048: [clangd] Add tests that no-op changes are cheap

2020-04-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks for doing this LGTM!




Comment at: clang-tools-extra/clangd/unittests/ClangdTests.cpp:501
+MATCHER_P4(Stats, Name, UsesMemory, PreambleBuilds, ASTBuilds, "") {
+  return arg.first() == Name && (arg.second.UsedBytes != 0) == UsesMemory &&
+ arg.second.PreambleBuilds == PreambleBuilds &&

nit:

```
std::make_tuple(arg.first(), arg.second.UsedBytes != 0, 
arg.second.PreambleBuilds, arg.second.ASTBuilds) == std::tie(Name, UsesMemory, 
PreambleBuilds, ASTBuilds);
```



Comment at: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp:762
+  ASSERT_TRUE(DoUpdate(SourceContents));
+  ASSERT_FALSE(DoUpdate(SourceContents));
+  ASSERT_EQ(S.fileStats().lookup(Source).ASTBuilds, 4u);

nit: maybe we drop these noop updates except the first one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78048



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


[PATCH] D77305: [Analyzer][VLASize] Support multi-dimensional arrays.

2020-04-14 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG37ac1c19bed7: [Analyzer][VLASize] Support multi-dimensional 
arrays. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77305

Files:
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/test/Analysis/vla.c

Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -1,4 +1,8 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-checker=debug.ExprInspection -verify %s
+
+typedef unsigned long size_t;
+size_t clang_analyzer_getExtent(void *);
+void clang_analyzer_eval(int);
 
 // Zero-sized VLAs.
 void check_zero_sized_VLA(int x) {
@@ -84,3 +88,41 @@
   if (x > 0)
 check_negative_sized_VLA_11_sub(x);
 }
+
+// Multi-dimensional arrays.
+
+void check_zero_sized_VLA_multi1(int x) {
+  if (x)
+return;
+
+  int vla[10][x]; // expected-warning{{Declared variable-length array (VLA) has zero size}}
+}
+
+void check_zero_sized_VLA_multi2(int x, int y) {
+  if (x)
+return;
+
+  int vla[y][x]; // expected-warning{{Declared variable-length array (VLA) has zero size}}
+}
+
+// Check the extent.
+
+void check_VLA_extent() {
+  int x = 3;
+
+  int vla1[x];
+  clang_analyzer_eval(clang_analyzer_getExtent(&vla1) == x * sizeof(int));
+  // expected-warning@-1{{TRUE}}
+
+  int vla2[x][2];
+  clang_analyzer_eval(clang_analyzer_getExtent(&vla2) == x * 2 * sizeof(int));
+  // expected-warning@-1{{TRUE}}
+
+  int vla2m[2][x];
+  clang_analyzer_eval(clang_analyzer_getExtent(&vla2m) == 2 * x * sizeof(int));
+  // expected-warning@-1{{TRUE}}
+
+  int vla3m[2][x][4];
+  clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * sizeof(int));
+  // expected-warning@-1{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -34,6 +34,9 @@
   mutable std::unique_ptr BT;
   enum VLASize_Kind { VLA_Garbage, VLA_Zero, VLA_Tainted, VLA_Negative };
 
+  ProgramStateRef checkVLASize(CheckerContext &C, ProgramStateRef State,
+   const Expr *SizeE) const;
+
   void reportBug(VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State,
  CheckerContext &C,
  std::unique_ptr Visitor = nullptr) const;
@@ -43,6 +46,65 @@
 };
 } // end anonymous namespace
 
+ProgramStateRef VLASizeChecker::checkVLASize(CheckerContext &C,
+ ProgramStateRef State,
+ const Expr *SizeE) const {
+  SVal SizeV = C.getSVal(SizeE);
+
+  if (SizeV.isUndef()) {
+reportBug(VLA_Garbage, SizeE, State, C);
+return nullptr;
+  }
+
+  // See if the size value is known. It can't be undefined because we would have
+  // warned about that already.
+  if (SizeV.isUnknown())
+return nullptr;
+
+  // Check if the size is tainted.
+  if (isTainted(State, SizeV)) {
+reportBug(VLA_Tainted, SizeE, nullptr, C,
+  std::make_unique(SizeV));
+return nullptr;
+  }
+
+  // Check if the size is zero.
+  DefinedSVal SizeD = SizeV.castAs();
+
+  ProgramStateRef StateNotZero, StateZero;
+  std::tie(StateNotZero, StateZero) = State->assume(SizeD);
+
+  if (StateZero && !StateNotZero) {
+reportBug(VLA_Zero, SizeE, StateZero, C);
+return nullptr;
+  }
+
+  // From this point on, assume that the size is not zero.
+  State = StateNotZero;
+
+  // Check if the size is negative.
+  SValBuilder &SVB = C.getSValBuilder();
+
+  QualType SizeTy = SizeE->getType();
+  DefinedOrUnknownSVal Zero = SVB.makeZeroVal(SizeTy);
+
+  SVal LessThanZeroVal = SVB.evalBinOp(State, BO_LT, SizeD, Zero, SizeTy);
+  if (Optional LessThanZeroDVal =
+  LessThanZeroVal.getAs()) {
+ConstraintManager &CM = C.getConstraintManager();
+ProgramStateRef StatePos, StateNeg;
+
+std::tie(StateNeg, StatePos) = CM.assumeDual(State, *LessThanZeroDVal);
+if (StateNeg && !StatePos) {
+  reportBug(VLA_Negative, SizeE, State, C); // FIXME: StateNeg ?
+  return nullptr;
+}
+State = StatePos;
+  }
+
+  return State;
+}
+
 void VLASizeChecker::reportBug(
 VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State,
 CheckerContext &C, std::unique_ptr Visitor) const {
@@ -89,98 +151,72 @@
 return;
 
   ASTContext &Ctx = C.getASTContext();
+  SValBuilder &SVB = C.getSValBuilder();
+  ProgramStateRef State = C.getState();
+
   const VariableArrayType *VLA = Ctx.getAsVariableArrayType(VD->getType());
   if (!VLA)
 return;
 
-  // FIXME: Handle multi-dimensional VLAs.
-  const Expr *SE = VLA->getSizeExpr();
-  ProgramStateR

[PATCH] D77875: [ARM] Armv8.6-a Matrix Mul cmd line support

2020-04-14 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a reviewer: DavidSpickett.
DavidSpickett added a comment.

> Note: +f32mm and +f64mm are optional and so have to be enabled by default

I think I know what you mean, but "and so are not enabled by default" would be 
clearer.

Also to double check, does f64mm imply f32mm? (not sure if there's an updated 
ARMARM yet that would tell me that)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77875



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


[PATCH] D77395: [AST] Dont invalidate VarDecl even the default initializaiton is failed.

2020-04-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 257231.
hokein marked 5 inline comments as done.
hokein added a comment.

rebase and address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77395

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-invalid-initialized.cpp
  clang/test/CXX/class.access/p4.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/special/class.ctor/p5-0x.cpp
  clang/test/CodeCompletion/invalid-initialized-class.cpp
  clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
  clang/test/SemaCXX/virtual-base-used.cpp
  clang/test/SemaObjCXX/arc-0x.mm

Index: clang/test/SemaObjCXX/arc-0x.mm
===
--- clang/test/SemaObjCXX/arc-0x.mm
+++ clang/test/SemaObjCXX/arc-0x.mm
@@ -116,13 +116,13 @@
   // Implicitly-declared special functions of a union are deleted by default if
   // ARC is enabled and the union has an ObjC pointer field.
   union U0 {
-id f0; // expected-note 6 {{'U0' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+id f0; // expected-note 7 {{'U0' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
   };
 
   union U1 {
-__weak id f0; // expected-note 12 {{'U1' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+__weak id f0; // expected-note 13 {{'U1' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 U1() = default; // expected-warning {{explicitly defaulted default constructor is implicitly deleted}} expected-note {{explicitly defaulted function was implicitly deleted here}}
-~U1() = default; // expected-warning {{explicitly defaulted destructor is implicitly deleted}} expected-note {{explicitly defaulted function was implicitly deleted here}}
+~U1() = default; // expected-warning {{explicitly defaulted destructor is implicitly deleted}} expected-note 2{{explicitly defaulted function was implicitly deleted here}}
 U1(const U1 &) = default; // expected-warning {{explicitly defaulted copy constructor is implicitly deleted}} expected-note 2 {{explicitly defaulted function was implicitly deleted here}}
 U1(U1 &&) = default; // expected-warning {{explicitly defaulted move constructor is implicitly deleted}}
 U1 & operator=(const U1 &) = default; // expected-warning {{explicitly defaulted copy assignment operator is implicitly deleted}} expected-note 2 {{explicitly defaulted function was implicitly deleted here}}
@@ -154,15 +154,15 @@
   // functions of the containing class.
   struct S0 {
 union {
-  id f0; // expected-note 6 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  id f0; // expected-note 7 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
   char f1;
 };
   };
 
   struct S1 {
 union {
-  union { // expected-note 2 {{'S1' is implicitly deleted because variant field '' has a non-trivial}} expected-note 4 {{'S1' is implicitly deleted because field '' has a deleted}}
-id f0; // expected-note 2 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  union { // expected-note 2 {{'S1' is implicitly deleted because variant field '' has a non-trivial}} expected-note 5 {{'S1' is implicitly deleted because field '' has a deleted}}
+id f0; // expected-note 3 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 char f1;
   };
   int f2;
@@ -172,7 +172,7 @@
   struct S2 {
 union {
   // FIXME: the note should say 'f0' is causing the special functions to be deleted.
-  struct { // expected-note 6 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
+  struct { // expected-note 7 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
 id f0;
 int f1;
   };
@@ -189,14 +189,18 @@
   S1 *x5;
   S2 *x6;
 
-  static union { // expected-error {{call to implicitly-deleted default constructor of}}
-id g0; // expected-note {{default constructor of '' is implicitly deleted because variant field 'g0' is an ObjC pointer}}
+  static union { // expected-error {{call to implicitly-deleted default constructor of}} expected-error {{attempt to use a deleted function}}
+id g0; // expected-note {{default constructor of '' is implicitly deleted because variant field 'g0' is an ObjC pointer}} \
+   // expected-note {{destructor of '' is implicitly deleted because}}
   };
 
-  static union { // expected-error {{call to implicitly-deleted default constructor of}}
-union { // expected-note {{default constructor of '' is implicitly deleted because field '' has a deleted default constructor}}
-  union { // expected-note {{default constructor of '' is implicitly deleted because field '' has a deleted default constructor}}
-__weak id g1; // expected-note {{default constructor

[PATCH] D77395: [AST] Dont invalidate VarDecl even the default initializaiton is failed.

2020-04-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D77395#1972666 , @sammccall wrote:

> the `attempt to use a deleted function` diagnostic is a bit spammy, because 
> the default-constructor and destructor are often deleted for similar reasons. 
> But I guess this is probably OK, unless you can see an easy way to suppress 
> it.


didn't see a trivial way to suppress this diagnostic, as we don't have enough 
information to distinguish the VarDecl (valid bit is true, no init-expr) has an 
ill-formed default initialization. I think we could build a recovery-expr and 
use it as the init-expr for the VarDecl, and suppress this diagnostic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77395



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


[PATCH] D77794: [clangd] Pull installed gRPC and introduce shared-index-(server|client)

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev planned changes to this revision.
kbobyrev added a comment.

Also




Comment at: clang-tools-extra/clangd/CMakeLists.txt:164
+
+  set(_GRPC_GRPCPP gRPC::grpc++)
+  set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)

sammccall wrote:
> Can we give these slightly less weird names :-)
Inlined everything except (newly) `GRPC_CPP_PLUGIN`.



Comment at: clang-tools-extra/clangd/CMakeLists.txt:169
+
+  add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1 -DCLANGD_SHARED_INDEX)
+  include_directories(${Protobuf_INCLUDE_DIRS})

sammccall wrote:
> CLANGD_SHARED_INDEX unused?
Yep, this one was used within Dexp when I was trying to extend it in this 
patch, but I realized I would need to either hide a bunch of commands or 
support some of them which would require the full Index interface 
implementation, Symbol deep copy and passing it through gRPC, etc. I guess we'd 
need to use it at some point anyway since there will be at least _some_ 
path-specific code if we don't build with gRPC by default (not rational for 
keeping it in this patch, just a bit of context in case you're interested).

Good catch, will remove!



Comment at: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp:262
 
 struct {
   const char *Name;

sammccall wrote:
> (unrelated formatting changes to this file)
This one is super weird, I even reset the file for the revision I was basing 
`arc diff` on, but it didn't work for some reason :(



Comment at: clang-tools-extra/clangd/index/shared/CMakeLists.txt:4
+
+set(SharedIndex_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/SharedIndex.pb.cc")
+set(SharedIndex_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/SharedIndex.pb.h")

sammccall wrote:
> generate a library wrapping those instead, for dependents to link against?
Great idea, thanks!



Comment at: clang-tools-extra/clangd/index/shared/CMakeLists.txt:5
+set(SharedIndex_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/SharedIndex.pb.cc")
+set(SharedIndex_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/SharedIndex.pb.h")
+set(SharedIndex_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/SharedIndex.grpc.pb.cc")

sammccall wrote:
> used once, inline? (and grpc_hdrs)
Why once? It's used at least 3 times at the moment - once in the generation 
command and in both targets. Maybe once I put all of it in the library that 
becomes twice? Let me see.



Comment at: clang-tools-extra/clangd/index/shared/CMakeLists.txt:13
+--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
+-I "${SharedIndexProtoPath}"
+--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"

sammccall wrote:
> Needed? it doesn't import anything
I'm afraid it's needed, I tried to get by without it but `protoc` fails with an 
error:

```
File does not reside within any path specified using --proto_path (or -I).  You 
must specify a --proto_path which encompasses this file.  Note that the 
proto_path must be an
 exact prefix of the .proto file names -- protoc is too dumb to figure out when 
two paths (e.g. absolute and relative) are equivalent (it's harder than you 
think).
```



Comment at: clang-tools-extra/clangd/index/shared/SharedIndex.proto:15
+
+message LookupRequestProto { string Name = 1; }
+

sammccall wrote:
> nit: LookupRequest, no Proto suffix. (If we need namespacing, we should use a 
> namespace)
Yep, thought this would be confusing :) We already have a bunch of `*Request` 
things but I didn't know `package <...>` would wrap it into the appropriate 
namespace. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794



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


[PATCH] D77732: [clangd] Shard preamble symbols in dynamic index

2020-04-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 257242.
kadircet marked 7 inline comments as done.
kadircet added a comment.

- Address comments
- Merge slab generations into a single member that returns an `IndexFileIn`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77732

Files:
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -116,9 +116,10 @@
 std::unique_ptr TestTU::index() const {
   auto AST = build();
   auto Idx = std::make_unique(/*UseDex=*/true);
-  Idx->updatePreamble(Filename, /*Version=*/"null", AST.getASTContext(),
-  AST.getPreprocessorPtr(), AST.getCanonicalIncludes());
-  Idx->updateMain(Filename, AST);
+  Idx->updatePreamble(testPath(Filename), /*Version=*/"null",
+  AST.getASTContext(), AST.getPreprocessorPtr(),
+  AST.getCanonicalIncludes());
+  Idx->updateMain(testPath(Filename), AST);
   return std::move(Idx);
 }
 
Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -151,8 +151,9 @@
   File.HeaderFilename = (Basename + ".h").str();
   File.HeaderCode = std::string(Code);
   auto AST = File.build();
-  M.updatePreamble(File.Filename, /*Version=*/"null", AST.getASTContext(),
-   AST.getPreprocessorPtr(), AST.getCanonicalIncludes());
+  M.updatePreamble(testPath(File.Filename), /*Version=*/"null",
+   AST.getASTContext(), AST.getPreprocessorPtr(),
+   AST.getCanonicalIncludes());
 }
 
 TEST(FileIndexTest, CustomizedURIScheme) {
@@ -393,8 +394,9 @@
   TU.HeaderCode = "class A {}; class B : public A {};";
   auto AST = TU.build();
   FileIndex Index;
-  Index.updatePreamble(TU.Filename, /*Version=*/"null", AST.getASTContext(),
-   AST.getPreprocessorPtr(), AST.getCanonicalIncludes());
+  Index.updatePreamble(testPath(TU.Filename), /*Version=*/"null",
+   AST.getASTContext(), AST.getPreprocessorPtr(),
+   AST.getCanonicalIncludes());
   SymbolID A = findSymbol(TU.headerSymbols(), "A").ID;
   uint32_t Results = 0;
   RelationsRequest Req;
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -283,6 +283,18 @@
   if (!ID)
 return true;
 
+  // ND is the canonical (i.e. first) declaration. If it's in the main file
+  // (which is not a header), then no public declaration was visible, so assume
+  // it's main-file only.
+  bool IsMainFileOnly =
+  SM.isWrittenInMainFile(SM.getExpansionLoc(ND->getBeginLoc())) &&
+  !isHeaderFile(SM.getFileEntryForID(SM.getMainFileID())->getName(),
+ASTCtx->getLangOpts());
+  // In C, printf is a redecl of an implicit builtin! So check OrigD instead.
+  if (ASTNode.OrigD->isImplicit() ||
+  !shouldCollectSymbol(*ND, *ASTCtx, Opts, IsMainFileOnly))
+return true;
+
   // Note: we need to process relations for all decl occurrences, including
   // refs, because the indexing code only populates relations for specific
   // occurrences. For example, RelationBaseOf is only populated for the
@@ -297,17 +309,6 @@
   if (IsOnlyRef && !CollectRef)
 return true;
 
-  // ND is the canonical (i.e. first) declaration. If it's in the main file
-  // (which is not a header), then no public declaration was visible, so assume
-  // it's main-file only.
-  bool IsMainFileOnly =
-  SM.isWrittenInMainFile(SM.getExpansionLoc(ND->getBeginLoc())) &&
-  !isHeaderFile(SM.getFileEntryForID(SM.getMainFileID())->getName(),
-ASTCtx->getLangOpts());
-  // In C, printf is a redecl of an implicit builtin! So check OrigD instead.
-  if (ASTNode.OrigD->isImplicit() ||
-  !shouldCollectSymbol(*ND, *ASTCtx, Opts, IsMainFileOnly))
-return true;
   // Do not store references to main-file symbols.
   // Unlike other fields, e.g. Symbols (which use spelling locations), we use
   // file locations for references (as it aligns the behavior of clangd's
Index: clang-tools-extra/clangd/index/FileIndex.h
===
--- clang-tools-extra/clangd/index/FileIndex.h
+++ clang-tools-extra/clangd/inde

[PATCH] D77794: [clangd] Pull installed gRPC and introduce shared-index-(server|client)

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 257240.
kbobyrev marked 19 inline comments as done.
kbobyrev added a comment.

Address a bunch of comments (still a couple left though).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/Server.cpp
  llvm/cmake/modules/LLVMProcessSources.cmake

Index: llvm/cmake/modules/LLVMProcessSources.cmake
===
--- llvm/cmake/modules/LLVMProcessSources.cmake
+++ llvm/cmake/modules/LLVMProcessSources.cmake
@@ -109,8 +109,8 @@
   else()
   set(fn_relative "${fn}")
   endif()
-  message(SEND_ERROR "Found unknown source file ${fn_relative}
-Please update ${CMAKE_CURRENT_LIST_FILE}\n")
+#   message(SEND_ERROR "Found unknown source file ${fn_relative}
+# Please update ${CMAKE_CURRENT_LIST_FILE}\n")
 endif()
   endif()
 endif()
Index: clang-tools-extra/clangd/index/remote/Server.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/Server.cpp
@@ -0,0 +1,125 @@
+//===--- Server.cpp - gRPC-based Remote Index Server  -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/Index.h"
+#include "index/Serialization.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+
+#include "grpcpp/grpcpp.h"
+#include "grpcpp/health_check_service_interface.h"
+
+#include "Index.grpc.pb.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+static const std::string Overview = R"(
+This is an experimental remote index implementation. The server opens Dex and
+awaits gRPC lookup requests from the client.
+)";
+
+llvm::cl::opt IndexPath(llvm::cl::desc("[PATH TO INDEX]"),
+ llvm::cl::Positional, llvm::cl::Required);
+
+llvm::cl::opt ServerAddress("server-address",
+ llvm::cl::init("0.0.0.0:50051"));
+
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*UseIndex=*/true);
+}
+
+// FIXME(kbobyrev): This is copied
+std::vector getSymbolIDsFromIndex(llvm::StringRef QualifiedName,
+const SymbolIndex *Index) {
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {std::string(Names.first)};
+  else
+// QualifiedName refers to a symbol in global scope (e.g. "GlobalSymbol"),
+// add the global scope to the request.
+Request.Scopes = {""};
+
+  Request.Query = std::string(Names.second);
+  std::vector SymIDs;
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
+class RemoteIndexServer final : public remote::Index::Service {
+public:
+  RemoteIndexServer(std::unique_ptr Index)
+  : Index(std::move(Index)) {}
+
+private:
+  grpc::Status
+  requestLookup(grpc::ServerContext *Context,
+const remote::LookupRequest *Request,
+grpc::ServerWriter *Reply) override {
+llvm::outs() << "Lookup of symbol with ID " << Request->name() << '\n';
+LookupRequest Req;
+for (const auto &ID : getSymbolIDsFromIndex(Request->name(), Index.get())) {
+  Req.IDs.insert(ID);
+}
+Index->lookup(Req, [&](const Symbol &Sym) {
+  remote::LookupReply NextSymbol;
+  NextSymbol.set_symbol_yaml(toYAML(Sym));
+  Reply->Write(NextSymbol);
+});
+return grpc::Status::OK;
+  }
+
+  std::unique_ptr Index;
+};
+
+void runServer(std::unique_ptr Index,
+   const std::string &ServerAddress) {
+  RemoteIndexServer Service(std::move(Index));
+
+  grpc::EnableDefaultHealthCheckService(true);
+  grpc::ServerBuilder Builder;
+  Builder.AddListeningPort(ServerAddress, grpc::InsecureServerCredentials());
+  Builder.RegisterService(&Service);
+  std::unique_ptr Server(Builder.BuildAndStart());

[PATCH] D77732: [clangd] Shard preamble symbols in dynamic index

2020-04-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/FileIndex.h:165
+  /// Returns absolute paths for all files that has a shard.
+  std::vector getAllFiles() const;
+

sammccall wrote:
> I do find it a little weird not to expose the map-structure of the vast 
> majority of the data here.
> 
> What steers you away from just making this a function
> `StringMap shardIndexToFile(IndexFileIn, PathRef)`
> where X could be `File` with a method to obtain the data, or the more 
> anonymous `unique_function`?
because the map structure is just pointers into the `IndexFileIn`, I wanted to 
make sure those pointers do not outlive the IndexFileIn.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:286
 
+  // ND is the canonical (i.e. first) declaration. If it's in the main file
+  // (which is not a header), then no public declaration was visible, so assume

sammccall wrote:
> kadircet wrote:
> > put this before `processRelations` to ensure `Subject` of a relation is a 
> > symbol we are going to collect.
> The code around this seems unchanged - how does this relate to the rest of 
> the patch?
> (Other than I guess you've been inspecting the data and finding bogus shards 
> :-)
> 
> This is bit subtle, and hard to reason about since we only have one example. 
> Indeed dangling relations are pointless. However:
>  - the direction of the relation is fairly arbitrary. Should we be checking 
> shouldCollectSymbol on the object of the relation too?
>  - shouldCollectSymbols depends somewhat on the file context, and also the 
> indexer options. In principle the subject could be indexable elsewhere but 
> not here. Or this index could see the relation and another could see the 
> symbol itself. Can't think of compelling examples though, just hypotheticals.
> 
> I think probably we should give this a comment (about not wanting relations 
> or refs either), add filtering on the relation objects, and add a test (I 
> think that should be pretty easy with inheriting from a main-file-only 
> class?).
> Maybe it's a separate patch?
> The code around this seems unchanged - how does this relate to the rest of 
> the patch?
> (Other than I guess you've been inspecting the data and finding bogus shards 
> :-)

Selection of file declaring the Subject seemed arbitrary, and turned out to be 
broken. We were not hitting this case before because background index was 
performing pre filtering and skipping any relation that mapped to a "non 
interesting" file, hence we didn't notice it was broken. Now it become obvious 
as we assert on the file containing the subject symbol.

> the direction of the relation is fairly arbitrary. Should we be checking 
> shouldCollectSymbol on the object of the relation too?
> shouldCollectSymbols depends somewhat on the file context, and also the 
> indexer options. In principle the subject could be indexable elsewhere but 
> not here. Or this index could see the relation and another could see the 
> symbol itself. Can't think of compelling examples though, just hypotheticals.
> I think probably we should give this a comment (about not wanting relations 
> or refs either), add filtering on the relation objects, and add a test (I 
> think that should be pretty easy with inheriting from a main-file-only 
> class?).
> Maybe it's a separate patch?

I also wanted to do this but it got hairy and as you also have suggested I 
decided to have a separate patch for this. Because there were other problematic 
stuff, for example `IndexerOpts::CollectMainFileSymbols` is always true.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77732



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


[PATCH] D76612: [Matrix] Add draft specification for matrix support in Clang.

2020-04-14 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added inline comments.



Comment at: clang/docs/MatrixTypes.rst:79
+  floating point type, convert the integer or floating point operand to the
+  underlying element type of the operand of matrix type.
+

rjmccall wrote:
> You should standardize on one term and then be clear what you mean by it.  
> Here you're saying "integer or floating point type", but elsewhere you use 
> "arithmetic type".  Unfortunately, the standard terms mean somewhat different 
> things in different standards: "integer" includes enums in C but not in C++, 
> "arithmetic" doesn't include complex types in C++ (although it does by 
> extension in Clang), etc.  I think for operands you probably want arithmetic 
> types in the real domain (which in Clang is `isRealType()`).  However, you'll 
> want to use a narrower term for the restriction on element types because 
> Clang does support fixed-point types, but you probably don't want to support 
> matrices of them quite yet (and you may not want to allow matrices of bools, 
> either).
> 
> Also, your description of the scalar conversions no longer promotes them to 
> matrix type.
> You should standardize on one term and then be clear what you mean by it. 
> Here you're saying "integer or floating point type", but elsewhere you use 
> "arithmetic type". Unfortunately, the standard terms mean somewhat different 
> things in different standards: "integer" includes enums in C but not in C++, 
> "arithmetic" doesn't include complex types in C++ (although it does by 
> extension in Clang), etc. I think for operands you probably want arithmetic 
> types in the real domain (which in Clang is isRealType()). However, you'll 
> want to use a narrower term for the restriction on element types because 
> Clang does support fixed-point types, but you probably don't want to support 
> matrices of them quite yet (and you may not want to allow matrices of bools, 
> either).

I've added the following to the Matrix Type section:
` A *matrix element type* must be a real type (as in C99 6.2.5p17) excluding 
enumeration types or an implementation-defined half-precision floating point 
type, otherwise the program is ill-formed.`

Other places are updated to use `a valid matrix element type` instead.

I think we explicitly want to allow half-precision types (like __fp16 and 
Float16 in Clang). I think by referring to real type as in the C99 spec, we 
naturally exclude Clang's fixed-point types and bool, right? 

> Also, your description of the scalar conversions no longer promotes them to 
> matrix type.

Right, I think we can just refer to the standard conversion rules here, as in

`If one operand is of matrix type and the other operand is of a valid matrix 
element type, convert the non-matrix type operand to the matrix type according 
to the standard conversion rules.`



Comment at: clang/docs/MatrixTypes.rst:123
+  M2 are of arithmetic type, they are broadcast to matrices here. — end note ]
+* The matrix types of M1 and M2 shall have the same number of rows and columns.
+* The result is equivalent to Res in the following where col is the number of

rjmccall wrote:
> They also have to have the same element types, right?  So they have to be the 
> same types?
Yes, for 2 operands of a matrix type, they should be the same types now. 
Changed to  `M1 and M2 shall be of the same matrix type.`



Comment at: clang/docs/MatrixTypes.rst:138
+* The type of ``M1`` shall have the same number of columns as the type of 
``M2`` has
+  rows.
+* The resulting type, ``MTy``, is the result of applying the usual arithmetic

rjmccall wrote:
> Same point about element types.
Added 
>The element types of ``M1`` and ``M2`` shall be the same type



Comment at: clang/docs/MatrixTypes.rst:141
+  conversions to ``M1`` and ``M2``, but with the same number of rows as M1’s 
matrix
+  type and the same number of columns as M2’s matrix type.
+* The result is equivalent to ``Res`` in the following where ``EltTy`` is the

rjmccall wrote:
> The easier way to put this now is that it's a matrix type whose element type 
> is the common element type, but with the number of rows of `M1` and the 
> number of columns of `M2`.
Replaced with 

> The resulting type, `MTy`, is a matrix type with the common element type, the 
> number of rows of `M1` and the number of columns of `M2`.




Comment at: clang/docs/MatrixTypes.rst:152
+  EltTy Elt = 0;
+  for (int K = 0; K < inner; ++K) {
+Elt += M1[R][K] * M2[K][C];

rjmccall wrote:
> `inner` is not defined.
Should be something like ` and ``inner`` is the number of columns of ``M1```



Comment at: clang/docs/MatrixTypes.rst:164
+Clang option to override this behavior and allow contraction of those
+operations (e.g. *-ffp-contract=matrix*).
+

rjmccall wrote:
> This is about rounding, not roun

[PATCH] D76612: [Matrix] Add draft specification for matrix support in Clang.

2020-04-14 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 257253.
fhahn marked 8 inline comments as done.
fhahn added a comment.

Address latest comments, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76612

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/MatrixTypes.rst

Index: clang/docs/MatrixTypes.rst
===
--- /dev/null
+++ clang/docs/MatrixTypes.rst
@@ -0,0 +1,323 @@
+==
+Matrix Types
+==
+
+.. contents::
+   :local:
+
+.. _matrixtypes:
+
+Clang provides a C/C++ language extension that allows users to directly express
+fixed-size matrices as language values and perform arithmetic on them.
+
+This feature is currently experimental, and both its design and its
+implementation are in flux.
+
+Draft Specification
+===
+
+Matrix Type
+---
+
+A matrix type is a scalar type with an underlying *element type*, a constant
+number of *rows*, and a constant number of *columns*. Matrix types with the same
+element type, rows, and columns are the same type. A value of a matrix type
+includes storage for ``rows * columns`` values of the *element ype*. The
+internal layout, overall size and alignment are implementation-defined.
+A *matrix element type* must be a real type (as in C99 6.2.5p17) excluding
+enumeration types or an implementation-defined half-precision floating point
+type, otherwise the program is ill-formed.
+
+The maximum of the product of the number of rows and columns is
+implementation-defined. If that implementation-defined limit is exceeded, the
+program is ill-formed.
+
+Matrix Type Attribute
+-
+
+Matrix types can be declared by adding the ``matrix_type`` attribute to the
+declaration of a *typedef* (or a C++ alias declaration). The underlying type
+of the *typedef* must be a valid matrix element type. The
+attribute takes two arguments, both of which must be integer constant
+expressions that evaluate to a value greater than zero. The first specifies the
+number of rows, and the second specifies the number of columns. The underlying
+type of the *typedef* becomes a matrix type with the given dimensions and an
+element type of the former underlying type.
+
+If a declaration of a *typedef-name* has a ``matrix_type`` attribute, then all
+declaration of that *typedef-name* shall have a matrix_type attribute with the
+same element type, number of rows, and number of columns.
+
+Standard Conversions
+
+
+The standard conversions are extended as follows. Note that these conversions
+are intentionally not listed as satisfying the constraints for assignment,
+which is to say, they are only permitted as explicit casts, not as implicit
+conversions.
+
+A value of matrix type can be converted to another matrix type if the number of
+rows and columns are the size and the value's elements can be converted to the
+element type of the result type. The result is a matrix where each element is
+the converted corresponding element.
+
+A value of non-matrix type can be converted to a matrix type if it can be
+converted to the element type of the matrix. The result is a matrix where
+all elements are the converted original value.
+
+If the number of rows or columns differ between the original and resulting
+type, the program is ill-formed.
+
+
+Arithmetic Conversions
+--
+
+The usual arithmetic conversions are extended as follows.
+
+Insert at the start:
+
+* If both operands are of matrix type, no arithmetic conversion is performed.
+* If one operand is of matrix type and the other operand is of a valid matrix
+  element type, convert the non-matrix type operand to the matrix type
+  according to the standard conversion rules.
+
+Matrix Type Element Access Operator
+---
+
+An expression of the form ``E1 [E2] [E3]``, where ``E1`` has matrix type ``cv
+M``, is a matrix element access expression.  Let ``T`` be the element type
+of ``M``, and let ``R`` and ``C`` be the number of rows and columns in ``M``
+respectively.  The index expressions shall have integral or unscoped
+enumeration type and shall not be uses of the comma operator unless
+parenthesized.  The first index expression shall evaluate to a
+non-negative value less than ``R``, and the second index expression shall
+evaluate to a non-negative value less than ``C``, or else the expression has
+undefined behavior.  If ``E1`` is a prvalue, the result is a prvalue with type
+``T`` and is the value of the element at the given row and column in the matrix.
+Otherwise, the result is a glvalue with type ``cv T`` and with the same value
+category as ``E1`` which refers to the element at the given row and column in
+the matrix.
+
+Programs containing a single subscript expression into a matrix are ill-formed.
+
+**Note**: We considered providing an expression of the form
+``postf

[PATCH] D76078: [AArch64][SVE] Add a pass for SVE intrinsic optimisations

2020-04-14 Thread Kerry McLaughlin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG36c76de6789c: [AArch64][SVE] Add a pass for SVE intrinsic 
optimisations (authored by kmclaughlin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76078

Files:
  llvm/lib/Target/AArch64/AArch64.h
  llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp
  llvm/test/CodeGen/AArch64/O3-pipeline.ll
  llvm/test/CodeGen/AArch64/sve-intrinsic-opts-ptest.ll
  llvm/test/CodeGen/AArch64/sve-intrinsic-opts-reinterpret.ll

Index: llvm/test/CodeGen/AArch64/sve-intrinsic-opts-reinterpret.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sve-intrinsic-opts-reinterpret.ll
@@ -0,0 +1,203 @@
+; RUN: opt -S -sve-intrinsic-opts -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck --check-prefix OPT %s
+
+define  @reinterpret_test_h( %a) {
+; OPT-LABEL: @reinterpret_test_h(
+; OPT-NOT: convert
+; OPT: ret  %a
+  %1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv8i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( %1)
+  ret  %2
+}
+
+; Reinterprets are not redundant because the second reinterpret zeros the
+; lanes that don't exist within its input.
+define  @reinterpret_test_h_rev( %a) {
+; OPT-LABEL: @reinterpret_test_h_rev(
+; OPT: %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( %a)
+; OPT-NEXT: %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv8i1( %1)
+; OPT-NEXT: ret  %2
+  %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv8i1( %1)
+  ret  %2
+}
+
+define  @reinterpret_test_w( %a) {
+; OPT-LABEL: @reinterpret_test_w(
+; OPT-NOT: convert
+; OPT: ret  %a
+  %1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( %1)
+  ret  %2
+}
+
+; Reinterprets are not redundant because the second reinterpret zeros the
+; lanes that don't exist within its input.
+define  @reinterpret_test_w_rev( %a) {
+; OPT-LABEL: @reinterpret_test_w_rev(
+; OPT: %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( %a)
+; OPT-NEXT: %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %1)
+; OPT-NEXT: ret  %2
+  %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %1)
+  ret  %2
+}
+
+define  @reinterpret_test_d( %a) {
+; OPT-LABEL: @reinterpret_test_d(
+; OPT-NOT: convert
+; OPT: ret  %a
+  %1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %1)
+  ret  %2
+}
+
+; Reinterprets are not redundant because the second reinterpret zeros the
+; lanes that don't exist within its input.
+define  @reinterpret_test_d_rev( %a) {
+; OPT-LABEL: @reinterpret_test_d_rev(
+; OPT: %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %a)
+; OPT-NEXT: %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %1)
+; OPT-NEXT: ret  %2
+  %1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %a)
+  %2 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %1)
+  ret  %2
+}
+
+define  @reinterpret_reductions(i32 %cond,  %a,  %b,  %c) {
+; OPT-LABEL: reinterpret_reductions
+; OPT-NOT: convert
+; OPT-NOT: phi 
+; OPT: phi  [ %a, %br_phi_a ], [ %b, %br_phi_b ], [ %c, %br_phi_c ]
+; OPT-NOT: convert
+; OPT: ret
+
+entry:
+  switch i32 %cond, label %br_phi_c [
+ i32 43, label %br_phi_a
+ i32 45, label %br_phi_b
+  ]
+
+br_phi_a:
+  %a1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %a)
+  br label %join
+
+br_phi_b:
+  %b1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %b)
+  br label %join
+
+br_phi_c:
+  %c1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %c)
+  br label %join
+
+join:
+  %pg = phi  [ %a1, %br_phi_a ], [ %b1, %br_phi_b ], [ %c1, %br_phi_c ]
+  %pg1 = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %pg)
+  ret  %pg1
+}
+
+; No transform as the reinterprets are converting from different types (nxv2i1 & nxv4i1)
+; As the incoming values to the phi must all be the same type, we cannot remove the reinterprets.
+define  @reinterpret_reductions_1(i32 %cond,  %a,  %b,  %c) {
+; OPT-LABEL: reinterpret_reductions_1
+; OPT: convert
+; OPT: phi  [ %a1, %br_phi_a ], [ %b1, %br_phi_b ], [ %c1, %br_phi_c ]
+; OPT-NOT: phi 
+; OPT: tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( %pg)
+; OPT: ret
+
+entry:
+  switch i32 %cond, label %br_phi_c [
+ i32 43, label %br_phi_a
+ i32 45, label %br_phi_b
+  ]
+
+br_phi_a:
+  %a1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv2i1( %a)
+  br label %join
+
+br_phi_b:
+  %b1 = tail call  @llvm.aarch64.sve.convert.to.svbool.nxv4i1( %b)
+  br label %join
+
+br_phi

[clang] f2b5e60 - [Analyzer][StreamChecker] Added evaluation of fseek.

2020-04-14 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2020-04-14T12:35:28+02:00
New Revision: f2b5e60dfd09f99d036197c078179c774f8b4582

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

LOG: [Analyzer][StreamChecker] Added evaluation of fseek.

Summary:
Function `fseek` is now evaluated with setting error return value
and error flags.

Reviewers: Szelethus, NoQ, xazax.hun, rnkovacs, dcoughlin, baloghadamsoftware, 
martong

Reviewed By: Szelethus

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

Tags: #clang

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
clang/test/Analysis/stream-error.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index b38a645432f4..76dd62d30ddf 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -25,8 +25,13 @@ using namespace ento;
 
 namespace {
 
+struct FnDescription;
+
 /// Full state information about a stream pointer.
 struct StreamState {
+  /// The last file operation called in the stream.
+  const FnDescription *LastOperation;
+
   /// State of a stream symbol.
   /// FIXME: We need maybe an "escaped" state later.
   enum KindTy {
@@ -45,6 +50,9 @@ struct StreamState {
 FEof,
 /// Other generic (non-EOF) error (`ferror` is true).
 FError,
+/// Unknown error flag is set (or none), the meaning depends on the last
+/// operation.
+Unknown
   } ErrorState = NoError;
 
   bool isOpened() const { return State == Opened; }
@@ -63,28 +71,47 @@ struct StreamState {
 assert(State == Opened && "Error undefined for closed stream.");
 return ErrorState == FError;
   }
+  bool isUnknown() const {
+assert(State == Opened && "Error undefined for closed stream.");
+return ErrorState == Unknown;
+  }
 
   bool operator==(const StreamState &X) const {
 // In not opened state error should always NoError.
-return State == X.State && ErrorState == X.ErrorState;
+return LastOperation == X.LastOperation && State == X.State &&
+   ErrorState == X.ErrorState;
   }
 
-  static StreamState getOpened() { return StreamState{Opened}; }
-  static StreamState getClosed() { return StreamState{Closed}; }
-  static StreamState getOpenFailed() { return StreamState{OpenFailed}; }
-  static StreamState getOpenedWithFEof() { return StreamState{Opened, FEof}; }
-  static StreamState getOpenedWithFError() {
-return StreamState{Opened, FError};
+  static StreamState getOpened(const FnDescription *L) {
+return StreamState{L, Opened};
+  }
+  static StreamState getOpened(const FnDescription *L, ErrorKindTy E) {
+return StreamState{L, Opened, E};
+  }
+  static StreamState getClosed(const FnDescription *L) {
+return StreamState{L, Closed};
   }
+  static StreamState getOpenFailed(const FnDescription *L) {
+return StreamState{L, OpenFailed};
+  }
+
+  /// Return if the specified error kind is possible on the stream in the
+  /// current state.
+  /// This depends on the stored `LastOperation` value.
+  /// If the error is not possible returns empty value.
+  /// If the error is possible returns the remaining possible error type
+  /// (after taking out `ErrorKind`). If a single error is possible it will
+  /// return that value, otherwise unknown error.
+  Optional getRemainingPossibleError(ErrorKindTy ErrorKind) const;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
+ID.AddPointer(LastOperation);
 ID.AddInteger(State);
 ID.AddInteger(ErrorState);
   }
 };
 
 class StreamChecker;
-struct FnDescription;
 using FnCheck = std::function;
 
@@ -95,8 +122,28 @@ struct FnDescription {
   FnCheck PreFn;
   FnCheck EvalFn;
   ArgNoTy StreamArgNo;
+  // What errors are possible after this operation.
+  // Used only if this operation resulted in Unknown state
+  // (otherwise there is a known single error).
+  // Must contain 2 or 3 elements, or zero.
+  llvm::SmallVector PossibleErrors = {};
 };
 
+Optional
+StreamState::getRemainingPossibleError(ErrorKindTy ErrorKind) const {
+  assert(ErrorState == Unknown &&
+ "Function to be used only if error is unknown.");
+  llvm::SmallVector NewPossibleErrors;
+  for (StreamState::ErrorKindTy E : LastOperation->PossibleErrors)
+if (E != ErrorKind)
+  NewPossibleErrors.push_back(E);
+  if (NewPossibleErrors.size() == LastOperation->PossibleErrors.size())
+return {};
+  if (NewPossibleErrors.size() == 1)
+return NewPossibleErrors.front();
+  return Unknown;
+}
+
 /// Get the value of the stream argument out

[PATCH] D76612: [Matrix] Add draft specification for matrix support in Clang.

2020-04-14 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 257259.
fhahn marked an inline comment as done.
fhahn added a comment.

Rename __builtin_matrix_columnwise_{load,store} => 
__builtin_matrix_column_major_{load,store}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76612

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/MatrixTypes.rst

Index: clang/docs/MatrixTypes.rst
===
--- /dev/null
+++ clang/docs/MatrixTypes.rst
@@ -0,0 +1,323 @@
+==
+Matrix Types
+==
+
+.. contents::
+   :local:
+
+.. _matrixtypes:
+
+Clang provides a C/C++ language extension that allows users to directly express
+fixed-size matrices as language values and perform arithmetic on them.
+
+This feature is currently experimental, and both its design and its
+implementation are in flux.
+
+Draft Specification
+===
+
+Matrix Type
+---
+
+A matrix type is a scalar type with an underlying *element type*, a constant
+number of *rows*, and a constant number of *columns*. Matrix types with the same
+element type, rows, and columns are the same type. A value of a matrix type
+includes storage for ``rows * columns`` values of the *element ype*. The
+internal layout, overall size and alignment are implementation-defined.
+A *matrix element type* must be a real type (as in C99 6.2.5p17) excluding
+enumeration types or an implementation-defined half-precision floating point
+type, otherwise the program is ill-formed.
+
+The maximum of the product of the number of rows and columns is
+implementation-defined. If that implementation-defined limit is exceeded, the
+program is ill-formed.
+
+Matrix Type Attribute
+-
+
+Matrix types can be declared by adding the ``matrix_type`` attribute to the
+declaration of a *typedef* (or a C++ alias declaration). The underlying type
+of the *typedef* must be a valid matrix element type. The
+attribute takes two arguments, both of which must be integer constant
+expressions that evaluate to a value greater than zero. The first specifies the
+number of rows, and the second specifies the number of columns. The underlying
+type of the *typedef* becomes a matrix type with the given dimensions and an
+element type of the former underlying type.
+
+If a declaration of a *typedef-name* has a ``matrix_type`` attribute, then all
+declaration of that *typedef-name* shall have a matrix_type attribute with the
+same element type, number of rows, and number of columns.
+
+Standard Conversions
+
+
+The standard conversions are extended as follows. Note that these conversions
+are intentionally not listed as satisfying the constraints for assignment,
+which is to say, they are only permitted as explicit casts, not as implicit
+conversions.
+
+A value of matrix type can be converted to another matrix type if the number of
+rows and columns are the size and the value's elements can be converted to the
+element type of the result type. The result is a matrix where each element is
+the converted corresponding element.
+
+A value of non-matrix type can be converted to a matrix type if it can be
+converted to the element type of the matrix. The result is a matrix where
+all elements are the converted original value.
+
+If the number of rows or columns differ between the original and resulting
+type, the program is ill-formed.
+
+
+Arithmetic Conversions
+--
+
+The usual arithmetic conversions are extended as follows.
+
+Insert at the start:
+
+* If both operands are of matrix type, no arithmetic conversion is performed.
+* If one operand is of matrix type and the other operand is of a valid matrix
+  element type, convert the non-matrix type operand to the matrix type
+  according to the standard conversion rules.
+
+Matrix Type Element Access Operator
+---
+
+An expression of the form ``E1 [E2] [E3]``, where ``E1`` has matrix type ``cv
+M``, is a matrix element access expression.  Let ``T`` be the element type
+of ``M``, and let ``R`` and ``C`` be the number of rows and columns in ``M``
+respectively.  The index expressions shall have integral or unscoped
+enumeration type and shall not be uses of the comma operator unless
+parenthesized.  The first index expression shall evaluate to a
+non-negative value less than ``R``, and the second index expression shall
+evaluate to a non-negative value less than ``C``, or else the expression has
+undefined behavior.  If ``E1`` is a prvalue, the result is a prvalue with type
+``T`` and is the value of the element at the given row and column in the matrix.
+Otherwise, the result is a glvalue with type ``cv T`` and with the same value
+category as ``E1`` which refers to the element at the given row and column in
+the matrix.
+
+Programs containing a single subscript expression into a matrix are ill-formed.
+
+**Note

[PATCH] D75851: [Analyzer][StreamChecker] Added evaluation of fseek.

2020-04-14 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2b5e60dfd09: [Analyzer][StreamChecker] Added evaluation of 
fseek. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75851

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-error.c

Index: clang/test/Analysis/stream-error.c
===
--- clang/test/Analysis/stream-error.c
+++ clang/test/Analysis/stream-error.c
@@ -52,3 +52,34 @@
   clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
   fclose(F);
 }
+
+void error_fseek() {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  int rc = fseek(F, 0, SEEK_SET);
+  if (rc) {
+int IsFEof = feof(F), IsFError = ferror(F);
+// Get feof or ferror or no error.
+clang_analyzer_eval(IsFEof || IsFError);
+// expected-warning@-1 {{FALSE}}
+// expected-warning@-2 {{TRUE}}
+clang_analyzer_eval(IsFEof && IsFError); // expected-warning {{FALSE}}
+// Error flags should not change.
+if (IsFEof)
+  clang_analyzer_eval(feof(F)); // expected-warning {{TRUE}}
+else
+  clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+if (IsFError)
+  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+else
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  } else {
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+// Error flags should not change.
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  }
+  fclose(F);
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -25,8 +25,13 @@
 
 namespace {
 
+struct FnDescription;
+
 /// Full state information about a stream pointer.
 struct StreamState {
+  /// The last file operation called in the stream.
+  const FnDescription *LastOperation;
+
   /// State of a stream symbol.
   /// FIXME: We need maybe an "escaped" state later.
   enum KindTy {
@@ -45,6 +50,9 @@
 FEof,
 /// Other generic (non-EOF) error (`ferror` is true).
 FError,
+/// Unknown error flag is set (or none), the meaning depends on the last
+/// operation.
+Unknown
   } ErrorState = NoError;
 
   bool isOpened() const { return State == Opened; }
@@ -63,28 +71,47 @@
 assert(State == Opened && "Error undefined for closed stream.");
 return ErrorState == FError;
   }
+  bool isUnknown() const {
+assert(State == Opened && "Error undefined for closed stream.");
+return ErrorState == Unknown;
+  }
 
   bool operator==(const StreamState &X) const {
 // In not opened state error should always NoError.
-return State == X.State && ErrorState == X.ErrorState;
+return LastOperation == X.LastOperation && State == X.State &&
+   ErrorState == X.ErrorState;
   }
 
-  static StreamState getOpened() { return StreamState{Opened}; }
-  static StreamState getClosed() { return StreamState{Closed}; }
-  static StreamState getOpenFailed() { return StreamState{OpenFailed}; }
-  static StreamState getOpenedWithFEof() { return StreamState{Opened, FEof}; }
-  static StreamState getOpenedWithFError() {
-return StreamState{Opened, FError};
+  static StreamState getOpened(const FnDescription *L) {
+return StreamState{L, Opened};
+  }
+  static StreamState getOpened(const FnDescription *L, ErrorKindTy E) {
+return StreamState{L, Opened, E};
+  }
+  static StreamState getClosed(const FnDescription *L) {
+return StreamState{L, Closed};
   }
+  static StreamState getOpenFailed(const FnDescription *L) {
+return StreamState{L, OpenFailed};
+  }
+
+  /// Return if the specified error kind is possible on the stream in the
+  /// current state.
+  /// This depends on the stored `LastOperation` value.
+  /// If the error is not possible returns empty value.
+  /// If the error is possible returns the remaining possible error type
+  /// (after taking out `ErrorKind`). If a single error is possible it will
+  /// return that value, otherwise unknown error.
+  Optional getRemainingPossibleError(ErrorKindTy ErrorKind) const;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
+ID.AddPointer(LastOperation);
 ID.AddInteger(State);
 ID.AddInteger(ErrorState);
   }
 };
 
 class StreamChecker;
-struct FnDescription;
 using FnCheck = std::function;
 
@@ -95,8 +122,28 @@
   FnCheck PreFn;
   FnCheck EvalFn;
   ArgNoTy StreamArgNo;
+  // What errors are possible after this operation.
+  // Used only if this operation resulted in Unknown state
+  // (otherwise there is a known single

[clang] 9657385 - [AST] Dont invalide VarDecl even the default initializaiton is failed.

2020-04-14 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-04-14T12:58:48+02:00
New Revision: 9657385960350150b77ed652175b4c3801abd7fa

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

LOG: [AST] Dont invalide VarDecl even the default initializaiton is failed.

Summary:
This patch would cause clang emit more diagnostics, but it is much better than 
https://reviews.llvm.org/D76831

```cpp
struct A {
  A(int);
  ~A() = delete;
};
void k() {
  A a;
}

```

before the patch:

/tmp/t3.cpp:24:5: error: no matching constructor for initialization of 'A'
  A a;
^
/tmp/t3.cpp:20:3: note: candidate constructor not viable: requires 1 argument, 
but 0 were provided
  A(int);
  ^
/tmp/t3.cpp:19:8: note: candidate constructor (the implicit copy constructor) 
not viable: requires 1 argument, but 0 were provided
struct A {

After the patch:

/tmp/t3.cpp:24:5: error: no matching constructor for initialization of 'A'
  A a;
^
/tmp/t3.cpp:20:3: note: candidate constructor not viable: requires 1 argument, 
but 0 were provided
  A(int);
  ^
/tmp/t3.cpp:19:8: note: candidate constructor (the implicit copy constructor) 
not viable: requires 1 argument, but 0 were provided
struct A {
   ^
/tmp/t3.cpp:24:5: error: attempt to use a deleted function
  A a;
^
/tmp/t3.cpp:21:3: note: '~A' has been explicitly marked deleted here
  ~A() = delete;

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

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

Added: 
clang/test/AST/ast-dump-invalid-initialized.cpp
clang/test/CodeCompletion/invalid-initialized-class.cpp

Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/CXX/class.access/p4.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/special/class.ctor/p5-0x.cpp
clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
clang/test/SemaCXX/virtual-base-used.cpp
clang/test/SemaObjCXX/arc-0x.mm

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 494a1cd1a685..9a93cb5d8ef2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12553,9 +12553,10 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
 
 InitializationSequence InitSeq(*this, Entity, Kind, None);
 ExprResult Init = InitSeq.Perform(*this, Entity, Kind, None);
-if (Init.isInvalid())
-  Var->setInvalidDecl();
-else if (Init.get()) {
+
+// If default-init fails, leave var uninitialized but valid, for recovery.
+
+if (Init.get()) {
   Var->setInit(MaybeCreateExprWithCleanups(Init.get()));
   // This is important for template substitution.
   Var->setInitStyle(VarDecl::CallInit);

diff  --git a/clang/test/AST/ast-dump-invalid-initialized.cpp 
b/clang/test/AST/ast-dump-invalid-initialized.cpp
new file mode 100644
index ..800a79cc831b
--- /dev/null
+++ b/clang/test/AST/ast-dump-invalid-initialized.cpp
@@ -0,0 +1,19 @@
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-fcxx-exceptions -std=gnu++17 -ast-dump %s | FileCheck -strict-whitespace %s
+
+struct A { A(int, int) {} };
+class ForwardDecl;
+
+void test() {
+  // CHECK: `-VarDecl {{.*}} a1 'A'
+  A a1;
+  // CHECK: `-VarDecl {{.*}} a2 'const A'
+  const A a2;
+  // CHECK: `-VarDecl {{.*}} a3 'A'
+  A a3 = garbage();
+
+
+  // CHECK: `-VarDecl {{.*}} invalid b1 'const A &'
+  const A& b1;
+  // CHECK: `-VarDecl {{.*}} invalid b2 'ForwardDecl'
+  ForwardDecl b2;
+}
\ No newline at end of file

diff  --git a/clang/test/CXX/class.access/p4.cpp 
b/clang/test/CXX/class.access/p4.cpp
index adc8bbe29583..b110683f0be8 100644
--- a/clang/test/CXX/class.access/p4.cpp
+++ b/clang/test/CXX/class.access/p4.cpp
@@ -220,14 +220,14 @@ namespace test3 {
   };
 
   class Derived3 :
-Base<0>, // expected-note {{deleted because base class 'Base<0>' has an 
inaccessible destructor}}
+Base<0>, // expected-note 2{{deleted because base class 'Base<0>' has an 
inaccessible destructor}}
 virtual Base<1>,
 Base2,
 virtual Base3
   {};
-  Derived3 d3; // expected-error {{implicitly-deleted default constructor}}
+  Derived3 d3; // expected-error {{implicitly-deleted default constructor}} 
expected-error {{attempt to use a deleted function}}
 #elif __cplusplus >= 201103L && defined(_MSC_VER)
-  template  class Base { ~Base(); }; // expected-note 6{{declared 
private here}}
+  template  class Base { ~Base(); }; // expected-note 9{{declared 
private here}}
   // expected-error@+1 {{inherited virtual base class 'Base<2>' has private 
destructor}}
   class Base2 : virtual Base<2> { ~Base2(); }; // expected-note 1{{declared 
private here}}
   // expected-error@+1 {{inherited virtual base class 'Base<3>' has private 
destructor}}
@@ -249,13 +249,15 @@ namespace test3 {
 ~Derived2() {}
   };
 
-

[clang] 1647ff6 - [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers.

2020-04-14 Thread Georgii Rymar via cfe-commits

Author: Georgii Rymar
Date: 2020-04-14T14:11:02+03:00
New Revision: 1647ff6e2753026f8a1e21c60d37b83602520b64

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

LOG: [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers.

It can be used to avoid passing the begin and end of a range.
This makes the code shorter and it is consistent with another
wrappers we already have.

Differential revision: https://reviews.llvm.org/D78016

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/SortJavaScriptImports.cpp
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
clang/lib/Tooling/Syntax/Tokens.cpp
lld/wasm/InputFiles.cpp
llvm/include/llvm/ADT/CoalescingBitVector.h
llvm/include/llvm/ADT/STLExtras.h
llvm/include/llvm/CodeGen/LiveInterval.h
llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp
llvm/lib/Analysis/LoopCacheAnalysis.cpp
llvm/lib/Analysis/TargetLibraryInfo.cpp
llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
llvm/lib/Frontend/OpenMP/OMPContext.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/Attributes.cpp
llvm/lib/MC/MCSubtargetInfo.cpp
llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
llvm/lib/Target/Mips/MipsCCState.cpp
llvm/lib/Target/X86/X86EvexToVex.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86InstrFMA3Info.cpp
llvm/lib/Target/X86/X86InstrFoldTables.cpp
llvm/lib/Target/X86/X86IntrinsicsInfo.h
llvm/lib/Transforms/IPO/CalledValuePropagation.cpp
llvm/tools/llvm-exegesis/lib/Target.cpp
llvm/tools/llvm-objcopy/ELF/Object.cpp
llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp
llvm/unittests/ADT/SimpleIListTest.cpp
llvm/unittests/Support/ParallelTest.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index ce16095e10c0..d2df24a6e21b 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -292,9 +292,7 @@ class AnalyzerOptions : public 
RefCountedBase {
   };
 
   bool isUnknownAnalyzerConfig(StringRef Name) const {
-
-assert(std::is_sorted(AnalyzerConfigCmdFlags.begin(),
-  AnalyzerConfigCmdFlags.end()));
+assert(llvm::is_sorted(AnalyzerConfigCmdFlags));
 
 return !std::binary_search(AnalyzerConfigCmdFlags.begin(),
AnalyzerConfigCmdFlags.end(), Name);

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index fb0c8b3aeaa3..812fdc61c25a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5352,7 +5352,7 @@ 
findARMVectorIntrinsicInMap(ArrayRef IntrinsicMap,
 
 #ifndef NDEBUG
   if (!MapProvenSorted) {
-assert(std::is_sorted(std::begin(IntrinsicMap), std::end(IntrinsicMap)));
+assert(llvm::is_sorted(IntrinsicMap));
 MapProvenSorted = true;
   }
 #endif

diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 31ab7977b7d2..1d0379afb4b5 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -5451,7 +5451,7 @@ llvm::Constant 
*IvarLayoutBuilder::buildBitmap(CGObjCCommonMac &CGObjC,
 // This isn't a stable sort, but our algorithm should handle it fine.
 llvm::array_pod_sort(IvarsInfo.begin(), IvarsInfo.end());
   } else {
-assert(std::is_sorted(IvarsInfo.begin(), IvarsInfo.end()));
+assert(llvm::is_sorted(IvarsInfo));
   }
   assert(IvarsInfo.back().Offset < InstanceEnd);
 

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 4a5626d42209..9b65c79b3526 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2049,8 +2049,7 @@ static void sortCppIncludes(const FormatStyle &Style,
   // enough as additional newlines might be added or removed across #include
   // blocks. This we handle below by generating the updated #imclude blocks and
   // comparing it to the original.
-  if (Indices.size() == Includes.size() &&
-  std::is_sorted(Indices.begin(), Indices.end()) &&
+  if (Indices.size() == Includes.size() && llvm::is_sorted(Indices) &&
   Style.IncludeStyle.IncludeBlocks == tooling::IncludeStyle::IBS_Preserve)
 return;
 

diff  --git a/clang/lib/Format/SortJavaScriptImports.cpp 
b/clang/lib/Format/SortJavaScriptImports.cpp
index 5be243f4c07a..db2b65b08898 100644
--- a/clang/lib/Format/SortJavaScriptImports.cpp
+++ b/cl

[PATCH] D77794: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 257270.
kbobyrev marked 6 inline comments as done.
kbobyrev added a comment.

Improve CMake infrastructure.

- Move client and server into separate directories and enable LLVM's error logic
- Address a bunch of comments regarding flags enabling gRPC & remote index build
- Simplify protobuf generation script


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/client/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/client/Client.cpp
  clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  llvm/CMakeLists.txt

Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -1107,3 +1107,8 @@
 if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)
   add_subdirectory(utils/llvm-locstats)
 endif()
+
+# FIXME(kirillbobyrev): Document this in the LLVM docs.
+option(LLVM_USE_GRPC "Use gRPC library to enable remote index support for Clangd" OFF)
+# FIXME(kbobyrev): Check if it works with optimized tablegen CMake option.
+set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library installation.")
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -0,0 +1,125 @@
+//===--- Server.cpp - gRPC-based Remote Index Server  -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/Index.h"
+#include "index/Serialization.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+
+#include "grpcpp/grpcpp.h"
+#include "grpcpp/health_check_service_interface.h"
+
+#include "Index.grpc.pb.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+static const std::string Overview = R"(
+This is an experimental remote index implementation. The server opens Dex and
+awaits gRPC lookup requests from the client.
+)";
+
+llvm::cl::opt IndexPath(llvm::cl::desc("[PATH TO INDEX]"),
+ llvm::cl::Positional, llvm::cl::Required);
+
+llvm::cl::opt ServerAddress("server-address",
+ llvm::cl::init("0.0.0.0:50051"));
+
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*UseIndex=*/true);
+}
+
+// FIXME(kbobyrev): This is copied
+std::vector getSymbolIDsFromIndex(llvm::StringRef QualifiedName,
+const SymbolIndex *Index) {
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {std::string(Names.first)};
+  else
+// QualifiedName refers to a symbol in global scope (e.g. "GlobalSymbol"),
+// add the global scope to the request.
+Request.Scopes = {""};
+
+  Request.Query = std::string(Names.second);
+  std::vector SymIDs;
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
+class RemoteIndexServer final : public remote::Index::Service {
+public:
+  RemoteIndexServer(std::unique_ptr Index)
+  : Index(std::move(Index)) {}
+
+private:
+  grpc::Status
+  requestLookup(grpc::ServerContext *Context,
+const remote::LookupRequest *Request,
+grpc::ServerWriter *Reply) override {
+llvm::outs() << "Lookup of symbol with ID " << Request->name() << '\n';
+LookupRequest Req;
+for (const auto &ID : getSymbolIDsFromIndex(Request->name(), Index.get())) {
+  Req.IDs.insert(ID);
+}
+Index->lookup(Req, [&](const Symbol &Sym) {
+  remote::LookupReply NextSymbol;
+  NextSymbol.set_symbol_yaml(toYAML(Sym));
+  Reply->Write(NextSymbol);
+});
+return grpc::Status::OK;
+  }
+
+  std::unique_ptr Index;
+};
+
+void runServer(std::unique_ptr Index,
+   const std::string &ServerAddress) {
+  RemoteIndexServer Service(std::m

[PATCH] D77794: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev planned changes to this revision.
kbobyrev added a comment.

Still need to do:

- Add documentation for enabling gRPC
- Simplify `clangd-index-(server|client)` as proposed
- Find out why lookup is working differently than in Dexp (debug a little bit, 
I'm pretty sure there is some minor bug)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794



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


[PATCH] D77794: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/CMakeLists.txt:156
+
+option(GRPC_INSTALL_PATH "Path to gRPC library installation." OFF)
+if (GRPC_INSTALL_PATH)

sammccall wrote:
> sammccall wrote:
> > sammccall wrote:
> > > We'll eventually want to move all this out of clangd I guess? Maybe add 
> > > FIXMEs for that?
> > this should be controlled by a top-level LLVM_ENABLE_GRPC or LLVM_USE_GRPC 
> > or so flag (not sure what the convention is).
> > Using GRPC_INSTALL_PATH is tempting now but there are multiple ways to 
> > configure it so it won't scale.
> > And at least in some cases we should be able to autodetect it, so we'll 
> > need a dedicated enable flag.
> GRPC_INSTALL_PATH should be set() instead of option().
Do you mean moving gRPC library setup logic to `llvm/CMakeLists.txt`?



Comment at: clang-tools-extra/clangd/index/shared/CMakeLists.txt:8
+set(SharedIndex_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/SharedIndex.grpc.pb.h")
+add_custom_command(
+  OUTPUT "${SharedIndex_proto_srcs}" "${SharedIndex_proto_hdrs}" 
"${SharedIndex_grpc_srcs}" "${SharedIndex_grpc_hdrs}"

sammccall wrote:
> can we wrap this in a function?
Are you proposing making a function (e.g. `generate_protos`) that would emit 
required source files? I'd have to do some manual dependency management in this 
case, that's why I did `add_custom_command` which seems to be the idiomatic way 
of generating targets with the right dependencies and properties (being 
generated files).

Could you please explain the benefit of wrapping this into a function?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794



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


[PATCH] D78016: [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers.

2020-04-14 Thread George Rimar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1647ff6e2753: [ADT/STLExtras.h] - Add llvm::is_sorted 
wrapper and update callers. (authored by grimar).
Herald added subscribers: cfe-commits, jrtc27.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78016

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/SortJavaScriptImports.cpp
  clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
  clang/lib/Tooling/Syntax/Tokens.cpp
  lld/wasm/InputFiles.cpp
  llvm/include/llvm/ADT/CoalescingBitVector.h
  llvm/include/llvm/ADT/STLExtras.h
  llvm/include/llvm/CodeGen/LiveInterval.h
  llvm/lib/Analysis/CFLAndersAliasAnalysis.cpp
  llvm/lib/Analysis/LoopCacheAnalysis.cpp
  llvm/lib/Analysis/TargetLibraryInfo.cpp
  llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
  llvm/lib/Frontend/OpenMP/OMPContext.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/MC/MCSubtargetInfo.cpp
  llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/lib/Target/Mips/MipsCCState.cpp
  llvm/lib/Target/X86/X86EvexToVex.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86InstrFMA3Info.cpp
  llvm/lib/Target/X86/X86InstrFoldTables.cpp
  llvm/lib/Target/X86/X86IntrinsicsInfo.h
  llvm/lib/Transforms/IPO/CalledValuePropagation.cpp
  llvm/tools/llvm-exegesis/lib/Target.cpp
  llvm/tools/llvm-objcopy/ELF/Object.cpp
  llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.cpp
  llvm/unittests/ADT/SimpleIListTest.cpp
  llvm/unittests/Support/ParallelTest.cpp

Index: llvm/unittests/Support/ParallelTest.cpp
===
--- llvm/unittests/Support/ParallelTest.cpp
+++ llvm/unittests/Support/ParallelTest.cpp
@@ -31,7 +31,7 @@
 i = dist(randEngine);
 
   sort(parallel::par, std::begin(array), std::end(array));
-  ASSERT_TRUE(std::is_sorted(std::begin(array), std::end(array)));
+  ASSERT_TRUE(llvm::is_sorted(array));
 }
 
 TEST(Parallel, parallel_for) {
Index: llvm/unittests/ADT/SimpleIListTest.cpp
===
--- llvm/unittests/ADT/SimpleIListTest.cpp
+++ llvm/unittests/ADT/SimpleIListTest.cpp
@@ -436,8 +436,8 @@
 // Check setup.
 EXPECT_EQ(4u, L1.size());
 EXPECT_EQ(6u, L2.size());
-EXPECT_TRUE(std::is_sorted(L1.begin(), L1.end()));
-EXPECT_TRUE(std::is_sorted(L2.begin(), L2.end()));
+EXPECT_TRUE(llvm::is_sorted(L1));
+EXPECT_TRUE(llvm::is_sorted(L2));
 
 // Merge.
 auto &LHS = IsL1LHS ? L1 : L2;
@@ -445,7 +445,7 @@
 LHS.merge(RHS);
 EXPECT_TRUE(RHS.empty());
 EXPECT_FALSE(LHS.empty());
-EXPECT_TRUE(std::is_sorted(LHS.begin(), LHS.end()));
+EXPECT_TRUE(llvm::is_sorted(LHS));
 auto I = LHS.begin();
 for (Node &N : Ns)
   EXPECT_EQ(&N, &*I++);
@@ -473,8 +473,8 @@
 // Check setup.
 EXPECT_EQ(3u, L1.size());
 EXPECT_EQ(2u, L2.size());
-EXPECT_TRUE(std::is_sorted(L1.begin(), L1.end(), makeFalse));
-EXPECT_TRUE(std::is_sorted(L2.begin(), L2.end(), makeFalse));
+EXPECT_TRUE(llvm::is_sorted(L1, makeFalse));
+EXPECT_TRUE(llvm::is_sorted(L2, makeFalse));
   };
 
   // Merge.  Should be stable.
@@ -482,7 +482,7 @@
   L1.merge(L2, makeFalse);
   EXPECT_TRUE(L2.empty());
   EXPECT_FALSE(L1.empty());
-  EXPECT_TRUE(std::is_sorted(L1.begin(), L1.end(), makeFalse));
+  EXPECT_TRUE(llvm::is_sorted(L1, makeFalse));
   auto I = L1.begin();
   EXPECT_EQ(&Ns[0], &*I++);
   EXPECT_EQ(&Ns[3], &*I++);
@@ -497,7 +497,7 @@
   L2.merge(L1, makeFalse);
   EXPECT_TRUE(L1.empty());
   EXPECT_FALSE(L2.empty());
-  EXPECT_TRUE(std::is_sorted(L2.begin(), L2.end(), makeFalse));
+  EXPECT_TRUE(llvm::is_sorted(L2, makeFalse));
   I = L2.begin();
   EXPECT_EQ(&Ns[1], &*I++);
   EXPECT_EQ(&Ns[2], &*I++);
@@ -521,7 +521,7 @@
 // Check setup.
 EXPECT_EQ(4u, L1.size());
 EXPECT_TRUE(L2.empty());
-EXPECT_TRUE(std::is_sorted(L1.begin(), L1.end()));
+EXPECT_TRUE(llvm::is_sorted(L1));
 
 // Merge.
 auto &LHS = IsL1LHS ? L1 : L2;
@@ -529,7 +529,7 @@
 LHS.merge(RHS);
 EXPECT_TRUE(RHS.empty());
 EXPECT_FALSE(LHS.empty());
-EXPECT_TRUE(std::is_sorted(LHS.begin(), LHS.end()));
+EXPECT_TRUE(llvm::is_sorted(LHS));
 auto I = LHS.begin();
 for (Node &N : Ns)
   EXPECT_EQ(&N, &*I++);
@@ -554,11 +554,11 @@
 
   // Check setup.
   EXPECT_EQ(10u, L.size());
-  EXPECT_FALSE(std::is_sorted(L.begin(), L.end()));
+  EXPECT_FALSE(llvm::is_sorted(L));
 
   // Sort.
   L.sort();
-  EXPECT_TRUE(std::is_sorted(L.begin(), L.end()));
+  EXPECT_TRUE(llvm::is_sorted(L));
   auto I = L.begin();
   for (Node &N

[PATCH] D77395: [AST] Dont invalidate VarDecl even the default initializaiton is failed.

2020-04-14 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG965738596035: [AST] Dont invalide VarDecl even the default 
initializaiton is failed. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D77395?vs=257231&id=257281#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77395

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-invalid-initialized.cpp
  clang/test/CXX/class.access/p4.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CXX/special/class.ctor/p5-0x.cpp
  clang/test/CodeCompletion/invalid-initialized-class.cpp
  clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
  clang/test/SemaCXX/virtual-base-used.cpp
  clang/test/SemaObjCXX/arc-0x.mm

Index: clang/test/SemaObjCXX/arc-0x.mm
===
--- clang/test/SemaObjCXX/arc-0x.mm
+++ clang/test/SemaObjCXX/arc-0x.mm
@@ -116,13 +116,13 @@
   // Implicitly-declared special functions of a union are deleted by default if
   // ARC is enabled and the union has an ObjC pointer field.
   union U0 {
-id f0; // expected-note 6 {{'U0' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+id f0; // expected-note 7 {{'U0' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
   };
 
   union U1 {
-__weak id f0; // expected-note 12 {{'U1' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+__weak id f0; // expected-note 13 {{'U1' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 U1() = default; // expected-warning {{explicitly defaulted default constructor is implicitly deleted}} expected-note {{explicitly defaulted function was implicitly deleted here}}
-~U1() = default; // expected-warning {{explicitly defaulted destructor is implicitly deleted}} expected-note {{explicitly defaulted function was implicitly deleted here}}
+~U1() = default; // expected-warning {{explicitly defaulted destructor is implicitly deleted}} expected-note 2{{explicitly defaulted function was implicitly deleted here}}
 U1(const U1 &) = default; // expected-warning {{explicitly defaulted copy constructor is implicitly deleted}} expected-note 2 {{explicitly defaulted function was implicitly deleted here}}
 U1(U1 &&) = default; // expected-warning {{explicitly defaulted move constructor is implicitly deleted}}
 U1 & operator=(const U1 &) = default; // expected-warning {{explicitly defaulted copy assignment operator is implicitly deleted}} expected-note 2 {{explicitly defaulted function was implicitly deleted here}}
@@ -154,15 +154,15 @@
   // functions of the containing class.
   struct S0 {
 union {
-  id f0; // expected-note 6 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  id f0; // expected-note 7 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
   char f1;
 };
   };
 
   struct S1 {
 union {
-  union { // expected-note 2 {{'S1' is implicitly deleted because variant field '' has a non-trivial}} expected-note 4 {{'S1' is implicitly deleted because field '' has a deleted}}
-id f0; // expected-note 2 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  union { // expected-note 2 {{'S1' is implicitly deleted because variant field '' has a non-trivial}} expected-note 5 {{'S1' is implicitly deleted because field '' has a deleted}}
+id f0; // expected-note 3 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 char f1;
   };
   int f2;
@@ -172,7 +172,7 @@
   struct S2 {
 union {
   // FIXME: the note should say 'f0' is causing the special functions to be deleted.
-  struct { // expected-note 6 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
+  struct { // expected-note 7 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
 id f0;
 int f1;
   };
@@ -189,14 +189,18 @@
   S1 *x5;
   S2 *x6;
 
-  static union { // expected-error {{call to implicitly-deleted default constructor of}}
-id g0; // expected-note {{default constructor of '' is implicitly deleted because variant field 'g0' is an ObjC pointer}}
+  static union { // expected-error {{call to implicitly-deleted default constructor of}} expected-error {{attempt to use a deleted function}}
+id g0; // expected-note {{default constructor of '' is implicitly deleted because variant field 'g0' is an ObjC pointer}} \
+   // expected-note {{destructor of '' is implicitly deleted because}}
   };
 
-  static union { // expected-error {{call to implicitly-deleted default constructor of}}
-union { // expected-note {{default constructor of '' is implicitly deleted because field '' has a deleted default constructor}}
-  union { // expected-note {{default constructor of '

[PATCH] D78098: [CGExprAgg] Fix infinite loop in `findPeephole`

2020-04-14 Thread Ehud Katz via Phabricator via cfe-commits
ekatz created this revision.
ekatz added reviewers: craig.topper, rjmccall, rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix PR45476


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78098

Files:
  clang/lib/CodeGen/CGExprAgg.cpp


Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -678,16 +678,16 @@
 /// Attempt to look through various unimportant expressions to find a
 /// cast of the given kind.
 static Expr *findPeephole(Expr *op, CastKind kind) {
-  while (true) {
-op = op->IgnoreParens();
-if (CastExpr *castE = dyn_cast(op)) {
-  if (castE->getCastKind() == kind)
-return castE->getSubExpr();
-  if (castE->getCastKind() == CK_NoOp)
-continue;
-}
-return nullptr;
+  while (CastExpr *castE = dyn_cast(op->IgnoreParens())) {
+if (castE->getCastKind() == kind)
+  return castE->getSubExpr();
+
+if (castE->getCastKind() != CK_NoOp || castE == op)
+  break;
+
+op = castE;
   }
+  return nullptr;
 }
 
 void AggExprEmitter::VisitCastExpr(CastExpr *E) {


Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -678,16 +678,16 @@
 /// Attempt to look through various unimportant expressions to find a
 /// cast of the given kind.
 static Expr *findPeephole(Expr *op, CastKind kind) {
-  while (true) {
-op = op->IgnoreParens();
-if (CastExpr *castE = dyn_cast(op)) {
-  if (castE->getCastKind() == kind)
-return castE->getSubExpr();
-  if (castE->getCastKind() == CK_NoOp)
-continue;
-}
-return nullptr;
+  while (CastExpr *castE = dyn_cast(op->IgnoreParens())) {
+if (castE->getCastKind() == kind)
+  return castE->getSubExpr();
+
+if (castE->getCastKind() != CK_NoOp || castE == op)
+  break;
+
+op = castE;
   }
+  return nullptr;
 }
 
 void AggExprEmitter::VisitCastExpr(CastExpr *E) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78097: [analyzer][RetainCount] Remove the CheckOSObject option

2020-04-14 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, vsavchenko, martong, baloghadamsoftware, 
xazax.hun, balazske, dcoughlin.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
whisperity.

As per http://lists.llvm.org/pipermail/cfe-dev/2019-August/063215.html, lets 
get rid of this option.

It presents 2 issues that have bugged me for years now:

- `OSObject` is NOT a `bool`ean option. It in fact has 3 states:
  - `osx.OSObjectRetainCount` is enabled but `OSObject` it set to false: 
RetainCount regards the option as disabled.
  - `osx.OSObjectRetainCount` is enabled and `OSObject` it set to true: 
RetainCount regards the option as enabled.
  - `osx.OSObjectRetainCount` is disabled: RetainCount regards the option as 
disabled.
- The hack involves directly modifying `AnalyzerOptions::ConfigTable`, which 
shouldn't even be public in the first place.

This still isn't really ideal, because it would be better to preserve the 
option and remove the checker (we want visible checkers to be associated with 
diagnostics, and hidden options like this one to be associated with changing 
how the modeling is done), but backwards compatibility is an issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78097

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/test-separate-retaincount.cpp


Index: clang/test/Analysis/test-separate-retaincount.cpp
===
--- clang/test/Analysis/test-separate-retaincount.cpp
+++ clang/test/Analysis/test-separate-retaincount.cpp
@@ -5,10 +5,6 @@
 // RUN: %clang_analyze_cc1 -std=c++14 -DNO_OS_OBJECT -verify %s \
 // RUN:   -analyzer-checker=core,osx \
 // RUN:   -analyzer-disable-checker osx.OSObjectRetainCount
-//
-// RUN: %clang_analyze_cc1 -std=c++14 -DNO_OS_OBJECT -verify %s \
-// RUN:   -analyzer-checker=core,osx \
-// RUN:   -analyzer-config "osx.cocoa.RetainCount:CheckOSObject=false"
 
 #include "os_object_base.h"
 
Index: clang/test/Analysis/analyzer-config.c
===
--- clang/test/Analysis/analyzer-config.c
+++ clang/test/Analysis/analyzer-config.c
@@ -89,7 +89,6 @@
 // CHECK-NEXT: 
optin.osx.cocoa.localizability.NonLocalizedStringChecker:AggressiveReport = 
false
 // CHECK-NEXT: optin.performance.Padding:AllowedPad = 24
 // CHECK-NEXT: osx.NumberObjectConversion:Pedantic = false
-// CHECK-NEXT: osx.cocoa.RetainCount:CheckOSObject = true
 // CHECK-NEXT: osx.cocoa.RetainCount:TrackNSCFStartParam = false
 // CHECK-NEXT: prune-paths = true
 // CHECK-NEXT: region-store-small-struct-limit = 2
@@ -106,4 +105,4 @@
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 103
+// CHECK-NEXT: num-entries = 102
Index: 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -1481,26 +1481,11 @@
   return true;
 }
 
-// FIXME: remove this, hack for backwards compatibility:
-// it should be possible to enable the NS/CF retain count checker as
-// osx.cocoa.RetainCount, and it should be possible to disable
-// osx.OSObjectRetainCount using osx.cocoa.RetainCount:CheckOSObject=false.
-static bool getOption(const AnalyzerOptions &Options,
-  StringRef Postfix,
-  StringRef Value) {
-  auto I = Options.Config.find(
-(StringRef("osx.cocoa.RetainCount:") + Postfix).str());
-  if (I != Options.Config.end())
-return I->getValue() == Value;
-  return false;
-}
-
 void ento::registerRetainCountChecker(CheckerManager &Mgr) {
   auto *Chk = Mgr.getChecker();
   Chk->TrackObjCAndCFObjects = true;
-  Chk->TrackNSCFStartParam = getOption(Mgr.getAnalyzerOptions(),
-   "TrackNSCFStartParam",
-   "true");
+  Chk->TrackNSCFStartParam = Mgr.getAnalyzerOptions().getCheckerBooleanOption(
+  Mgr.getCurrentCheckerName(), "TrackNSCFStartParam");
 }
 
 bool ento::shouldRegisterRetainCountChecker(const CheckerManager &mgr) {
@@ -1509,10 +1494,7 @@
 
 void ento::registerOSObjectRetainCountChecker(CheckerManager &Mgr) {
   auto *Chk = Mgr.getChecker();
-  if (!getOption(Mgr.getAnalyzerOptions(),
- "CheckOSObject",
- "false"))
-Chk->TrackOSObjects = true;
+  Chk->TrackOSObjects = true;
 }
 
 bool ento::shouldRegisterOSObjectRetainCountChecker(const CheckerManager &mgr) 
{
Index: clang/include/clang/StaticAnalyzer/Chec

[PATCH] D76612: [Matrix] Add draft specification for matrix support in Clang.

2020-04-14 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: clang/docs/MatrixTypes.rst:12
+fixed-size matrices as language values and perform arithmetic on them.
+
+This feature is currently experimental, and both its design and its

Would it be good to set expectations here or in the section below: define that 
we're talking about 2-dimensional m × n matrices?



Comment at: clang/docs/MatrixTypes.rst:25
+element type, rows, and columns are the same type. A value of a matrix type
+includes storage for ``rows * columns`` values of the *element ype*. The
+internal layout, overall size and alignment are implementation-defined.

typo: ype -> type



Comment at: clang/docs/MatrixTypes.rst:27
+internal layout, overall size and alignment are implementation-defined.
+A *matrix element type* must be a real type (as in C99 6.2.5p17) excluding
+enumeration types or an implementation-defined half-precision floating point

above you're using *element type* and here *matrix element type*. Since 
hopefully we're talking about the same things, "matrix *element type*" would be 
more consistent.

But this is just a nit, my main question is about the types:
why not e.g. define this to be the C11 types, that include _FloatN types, so 
that we can include N=16? Or is this intentionally omitted? I haven't even 
checked if this is supported in the architecture extension, but might make 
sense? And also, an element type cannot be an integer type? 

 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76612



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


[PATCH] D78068: [www] Turn 'Clang 10' boxes green in C++ status pages to reflect release

2020-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman 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/D78068/new/

https://reviews.llvm.org/D78068



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


[PATCH] D74669: [clang-tidy] New check: bugprone-suspicious-include

2020-04-14 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

Firefox uses a unified build model. For better performances in the binary, the 
C++ files are compiled as the same time from a single file (ex: 
Unified_cpp_netwerk_base3.cpp) which will include the .cpp files.

This isn't a common use case, so, don't hesitate to ignore me but checks 
triggers 4286 new issues. About 20 of them are legit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74669



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


[PATCH] D77461: [WIP][clang-tidy] Remove false positive in AvoidNonConstGlobalVariables

2020-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp:50
+// variables in a function.
+if (!Variable->isLocalVarDecl()) {
+  diag(Variable->getLocation(), "variable %0 is non-const and globally "

I think this should be handled in the matcher rather than here. I'd add a local 
matcher for `isLocalVarDecl()` and add it to the `unless()` matcher. WDYT?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp:234-236
+static int staticNonConstLoopVariable = 42;
 int nonConstLoopVariable = 42;
+nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;

I would like this example moved out of the section suggesting this is a false 
positive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77461



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


[PATCH] D57226: [Fixed Point] [AST] Add an AST serialization code for fixed-point literals.

2020-04-14 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thank you for the comments. Please do let me know when this patch is ready to 
land. Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57226



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


[PATCH] D57226: [Fixed Point] [AST] Add an AST serialization code for fixed-point literals.

2020-04-14 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 257287.
vabridgers added a comment.

update based on comments from rjmccall


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57226

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Expr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/PCH/Inputs/fixed-point-literal.h
  clang/test/PCH/fixed-point-literal.c

Index: clang/test/PCH/fixed-point-literal.c
===
--- /dev/null
+++ clang/test/PCH/fixed-point-literal.c
@@ -0,0 +1,15 @@
+
+// Test this without pch.
+// RUN: %clang_cc1 -ffixed-point -include %S/Inputs/fixed-point-literal.h -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -ffixed-point -emit-pch -o %t %S/Inputs/fixed-point-literal.h
+// RUN: %clang_cc1 -ffixed-point -include-pch %t -fsyntax-only -ast-print -o - %s | FileCheck %s
+
+// CHECK: const short _Fract sf = -0.25r;
+// CHECK: const _Fract f = 0.75r;
+// CHECK: const long _Accum la = 25.25lk;
+
+short _Fract sf2 = sf;
+_Fract f2 = f;
+long _Accum la2 = la;
Index: clang/test/PCH/Inputs/fixed-point-literal.h
===
--- /dev/null
+++ clang/test/PCH/Inputs/fixed-point-literal.h
@@ -0,0 +1,5 @@
+// Header for PCH test fixed-point-literal.c
+
+const short _Fract sf = -0.25r;
+const _Fract f = 0.75r;
+const long _Accum la = 25.25lk;
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -629,8 +629,9 @@
 void ASTStmtWriter::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   Record.AddSourceLocation(E->getLocation());
+  Record.push_back(E->getScale());
   Record.AddAPInt(E->getValue());
-  Code = serialization::EXPR_INTEGER_LITERAL;
+  Code = serialization::EXPR_FIXEDPOINT_LITERAL;
 }
 
 void ASTStmtWriter::VisitFloatingLiteral(FloatingLiteral *E) {
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -571,6 +571,7 @@
   RECORD(EXPR_PREDEFINED);
   RECORD(EXPR_DECL_REF);
   RECORD(EXPR_INTEGER_LITERAL);
+  RECORD(EXPR_FIXEDPOINT_LITERAL);
   RECORD(EXPR_FLOATING_LITERAL);
   RECORD(EXPR_IMAGINARY_LITERAL);
   RECORD(EXPR_STRING_LITERAL);
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -605,6 +605,7 @@
 void ASTStmtReader::VisitFixedPointLiteral(FixedPointLiteral *E) {
   VisitExpr(E);
   E->setLocation(readSourceLocation());
+  E->setScale(Record.readInt());
   E->setValue(Record.getContext(), Record.readAPInt());
 }
 
@@ -2857,6 +2858,10 @@
   S = IntegerLiteral::Create(Context, Empty);
   break;
 
+case EXPR_FIXEDPOINT_LITERAL:
+  S = FixedPointLiteral::Create(Context, Empty);
+  break;
+
 case EXPR_FLOATING_LITERAL:
   S = FloatingLiteral::Create(Context, Empty);
   break;
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -913,6 +913,11 @@
   return new (C) FixedPointLiteral(C, V, type, l, Scale);
 }
 
+FixedPointLiteral *FixedPointLiteral::Create(const ASTContext &C,
+ EmptyShell Empty) {
+  return new (C) FixedPointLiteral(Empty);
+}
+
 std::string FixedPointLiteral::getValueAsString(unsigned Radix) const {
   // Currently the longest decimal number that can be printed is the max for an
   // unsigned long _Accum: 4294967295.976716935634613037109375
Index: clang/include/clang/Serialization/ASTBitCodes.h
===
--- clang/include/clang/Serialization/ASTBitCodes.h
+++ clang/include/clang/Serialization/ASTBitCodes.h
@@ -1887,6 +1887,9 @@
   EXPR_COAWAIT,
   EXPR_COYIELD,
   EXPR_DEPENDENT_COAWAIT,
+
+  // FixedPointLiteral
+  EXPR_FIXEDPOINT_LITERAL,
 };
 
 /// The kinds of designators that can occur in a
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1484,7 +1484,7 @@
   SourceLocation Loc;
   unsigned Scale;
 
-  /// \brief Construct an empty integer literal.
+  /// \brief Construct an empty fixed-point literal.
   explicit FixedPointLiteral(EmptyShell Empty)
   : Expr(FixedPointLiteralClass, Empty) {}
 
@@ -1498,6 +1498,9 @@
 

[PATCH] D78100: [AST] Suppress the spammy "attempt to use a deleted fucntion" diagnostic.

2020-04-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: clang.

This patch fixes the regression diagnostic, which was introduced in
https://reviews.llvm.org/D77395.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78100

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class.access/p4.cpp
  clang/test/CXX/special/class.ctor/p5-0x.cpp
  clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
  clang/test/SemaCXX/virtual-base-used.cpp
  clang/test/SemaObjCXX/arc-0x.mm

Index: clang/test/SemaObjCXX/arc-0x.mm
===
--- clang/test/SemaObjCXX/arc-0x.mm
+++ clang/test/SemaObjCXX/arc-0x.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -fobjc-weak -verify -fblocks -fobjc-exceptions %s
+// RUN: %clang_cc1 -frecovery-ast -std=c++11 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -fobjc-weak -verify -fblocks -fobjc-exceptions %s
 
 // "Move" semantics, trivial version.
 void move_it(__strong id &&from) {
@@ -116,13 +116,13 @@
   // Implicitly-declared special functions of a union are deleted by default if
   // ARC is enabled and the union has an ObjC pointer field.
   union U0 {
-id f0; // expected-note 7 {{'U0' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+id f0; // expected-note 6 {{'U0' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
   };
 
   union U1 {
-__weak id f0; // expected-note 13 {{'U1' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+__weak id f0; // expected-note 12 {{'U1' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 U1() = default; // expected-warning {{explicitly defaulted default constructor is implicitly deleted}} expected-note {{explicitly defaulted function was implicitly deleted here}}
-~U1() = default; // expected-warning {{explicitly defaulted destructor is implicitly deleted}} expected-note 2{{explicitly defaulted function was implicitly deleted here}}
+~U1() = default; // expected-warning {{explicitly defaulted destructor is implicitly deleted}} expected-note {{explicitly defaulted function was implicitly deleted here}}
 U1(const U1 &) = default; // expected-warning {{explicitly defaulted copy constructor is implicitly deleted}} expected-note 2 {{explicitly defaulted function was implicitly deleted here}}
 U1(U1 &&) = default; // expected-warning {{explicitly defaulted move constructor is implicitly deleted}}
 U1 & operator=(const U1 &) = default; // expected-warning {{explicitly defaulted copy assignment operator is implicitly deleted}} expected-note 2 {{explicitly defaulted function was implicitly deleted here}}
@@ -154,15 +154,15 @@
   // functions of the containing class.
   struct S0 {
 union {
-  id f0; // expected-note 7 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  id f0; // expected-note 6 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
   char f1;
 };
   };
 
   struct S1 {
 union {
-  union { // expected-note 2 {{'S1' is implicitly deleted because variant field '' has a non-trivial}} expected-note 5 {{'S1' is implicitly deleted because field '' has a deleted}}
-id f0; // expected-note 3 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  union { // expected-note 2 {{'S1' is implicitly deleted because variant field '' has a non-trivial}} expected-note 4 {{'S1' is implicitly deleted because field '' has a deleted}}
+id f0; // expected-note 2 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 char f1;
   };
   int f2;
@@ -172,7 +172,7 @@
   struct S2 {
 union {
   // FIXME: the note should say 'f0' is causing the special functions to be deleted.
-  struct { // expected-note 7 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
+  struct { // expected-note 6 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
 id f0;
 int f1;
   };
@@ -189,18 +189,14 @@
   S1 *x5;
   S2 *x6;
 
-  static union { // expected-error {{call to implicitly-deleted default constructor of}} expected-error {{attempt to use a deleted function}}
-id g0; // expected-note {{default constructor of '' is implicitly deleted because variant field 'g0' is an ObjC pointer}} \
-   // expected-note {{destructor of '' is implicitly deleted because}}
+  static union { // expected-error {{call to implicitly-deleted default constructor of}}
+id g0; // expected-note {{default constructor of '' is implicitly deleted because variant field 'g0' is an ObjC pointer}}
   };
 
-  static union { // expected-error {{call to implicitly-deleted default constructor of}} expected-error {{attempt to use a deleted function}}
-union { // expected-no

[PATCH] D78098: [CGExprAgg] Fix infinite loop in `findPeephole`

2020-04-14 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Can test be added here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78098



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


[PATCH] D76594: [clang][AST] Support AST files larger than 512M

2020-04-14 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.

We're starting to see quite a lot of production crashes with this and would 
very much like a fix.
At this point it seems like we're best moving ahead and if someone comes up 
with a better idea, we can improve it later.




Comment at: clang/include/clang/Serialization/ASTBitCodes.h:220
 /// Source range/offset of a preprocessed entity.
 struct DeclOffset {
+  /// Raw source location. The unsigned i.e. 32-bit integer is enough for

DmitryPolukhin wrote:
> sammccall wrote:
> > Is there one of these for every decl in the module? It seems like we're 
> > probably giving up a good fraction of the 4% increase for just using 
> > absolute 64 bit offsets everywhere :-( Is there still a significant gain 
> > from using section-relative elsewhere?
> > 
> > If there are indeed lots of these, giving up 4 bytes to padding (in 
> > addition to the wide offset) seems unfortunate and because we memcpy the 
> > structs into the AST file seems like a sad reason :-)
> > Can we align this to 4 bytes instead?
> > (e.g. by splitting into two fields and encapsulating the few direct 
> > accesses, though there's probably a neater way)
> Yes, it seems that all referenced decls should have an entry in this table. 
> 4% increase was counted on previous diff before I discovered DeclOffsets and 
> TypeOffsets. This diff uses relative offsets for previous cases and increase 
> is only 2 additional 64-bit integers per file. DeclOffsets are about 4.7% and 
> TypeOffsets are about 2.5% of the whole file. With this diff both number will 
> be 2x, splitting DeclOffset in two separate arrays could make the increase 
> only 1.5x for DeclOffsets. If approach from this diff looks fine, I can split 
> array of DeclOffset into 2 separate arrays. It could be a bit less efficient 
> because of worse memory locality but will save some space.
Or even just 32-bit BitOffsetLow and BitOffsetHigh fields so the overall struct 
is 32-bit aligned... then you'd still be local?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76594



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


[PATCH] D76083: [clang-tidy] Expand the list of functions in bugprone-unused-return-value

2020-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp:98
+   "::access;"
+   "::bind;"
+   "::connect;"

sammccall wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > sammccall wrote:
> > > > aaron.ballman wrote:
> > > > > sammccall wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > jranieri-grammatech wrote:
> > > > > > > > alexfh wrote:
> > > > > > > > > bind has a side effect and returns a success status. Thus, 
> > > > > > > > > the result being unused isn't necessarily a bug. Same for 
> > > > > > > > > `connect`. And probably for `setjmp` as well.
> > > > > > > > In terms of bind, connect, and setjmp: while I personally would 
> > > > > > > > say that code not using the return value is bugprone, the data 
> > > > > > > > suggests that the vast majority of developers are using these 
> > > > > > > > functions in the intended manner and the false-positive rate 
> > > > > > > > should be low.
> > > > > > > I think we have sufficient statistical data to suggest that these 
> > > > > > > APIs should be on the list because the majority of programmers 
> > > > > > > *do not* use them solely for side effects without using the 
> > > > > > > return value, so my preference is to keep them in the list.
> > > > > > I stumbled upon this review as we're considering turning this check 
> > > > > > on by default in clangd.
> > > > > > 
> > > > > > There's a significant difference between unused std::async() 
> > > > > > (programmer misunderstood contract) and unused ::connect() 
> > > > > > (ignoring error conditions). The former is ~never noise, and the 
> > > > > > latter may be (e.g. in experimental or incomplete code).
> > > > > > 
> > > > > > So there's some value in separating these two lists out either as 
> > > > > > an option or a separate named check (bugprone-unhandled-error?) I 
> > > > > > think we probably wouldn't enable this check by default if it 
> > > > > > includes the error-code functions.
> > > > > > 
> > > > > > > the majority of programmers *do not* use them solely for side 
> > > > > > > effects
> > > > > > ...in popular, distributed software :-)
> > > > > > So there's some value in separating these two lists out either as 
> > > > > > an option or a separate named check (bugprone-unhandled-error?) I 
> > > > > > think we probably wouldn't enable this check by default if it 
> > > > > > includes the error-code functions.
> > > > > 
> > > > > I think that adds complexity to this check when the complexity isn't 
> > > > > necessary. clang-tidy has traditionally been a place for checks that 
> > > > > are chattier than what the compiler should provide, and this check 
> > > > > has a trivial, well-understood mechanism to silence the diagnostics 
> > > > > (cast to void) which also expresses intent properly to the toolchain.
> > > > > 
> > > > > >>the majority of programmers *do not* use them solely for side 
> > > > > >>effects
> > > > > > ...in popular, distributed software :-)
> > > > > 
> > > > > I have not seen anyone provide data to suggest that the functions in 
> > > > > question appear in any statistically significant amount in practice 
> > > > > without checking the return value, just worries that they *could*. I 
> > > > > don't think that's compelling in the face of data. Remember, this is 
> > > > > for bugprone patterns, not bugknown patterns.
> > > > I think we're talking past each other here. I'm not saying clang-tidy 
> > > > shouldn't have the check, or that it's not a bugprone pattern, or that 
> > > > the clang-tidy default should be different.
> > > > 
> > > > But there are scenarios where you want one but not the other. 
> > > > Concretely, warnings shown in an IDE **as you type and by default**. If 
> > > > you're misusing an API rendering it completely useless, you should see 
> > > > that ASAP. If you fail to check an error code, some users won't want to 
> > > > be warned about that until later.
> > > > 
> > > > By bundling them into a single check without options (other than 
> > > > duplicating the whole list), it's hard to create that useful but 
> > > > inoffensive default setup. That's OK, clangd can remove the check from 
> > > > the whitelist, but I think we'd get a lot of value out of it.
> > > > 
> > > > > I have not seen anyone provide data to suggest that the functions in 
> > > > > question appear in any statistically significant amount in practice
> > > > Right, we don't have data either way on incomplete code. Based on 
> > > > experience of writing code and watching others write code, I believe 
> > > > people write sloppy code they'd never check in, and appreciate being 
> > > > told early when it doesn't do what they intend, but some don't 
> > > > appreciate being told to be less sloppy. Is your intuition different? 
> > > > Do you think the data provi

[PATCH] D78101: [analyzer][StackAddressEscape] Tie warnings to the diagnostic checkers rather then core.StackAddrEscapeBase

2020-04-14 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, dcoughlin, baloghadamsoftware, 
balazske, martong.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
whisperity.

Exactly what it says on the tin!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78101

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
  clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  clang/test/Analysis/incorrect-checker-names.cpp
  clang/test/Analysis/incorrect-checker-names.mm

Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- clang/test/Analysis/incorrect-checker-names.mm
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -1,5 +1,6 @@
-// RUN: %clang_analyze_cc1 -fblocks -verify %s -Wno-objc-root-class \
+// RUN: %clang_analyze_cc1 -fblocks -fobjc-arc -verify %s -Wno-objc-root-class \
 // RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=alpha.core.StackAddressAsyncEscape \
 // RUN:   -analyzer-checker=nullability \
 // RUN:   -analyzer-checker=osx
 
@@ -114,3 +115,32 @@
   // FIXME: This shouldn't be tied to a modeling checker.
   write_into_out_param_on_success(&obj); // expected-warning{{Potential leak of an object stored into 'obj' [osx.cocoa.RetainCountBase]}}
 }
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+typedef long dispatch_once_t;
+void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);
+typedef long dispatch_time_t;
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_barrier_sync(dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+extern dispatch_once_t *predicate;
+extern dispatch_time_t when;
+
+dispatch_block_t get_leaking_block() {
+  int leaked_x = 791;
+  int *p = &leaked_x;
+  return ^void(void) {
+*p = 1;
+  };
+  // expected-warning@-3 {{Address of stack memory associated with local variable 'leaked_x' \
+is captured by a returned block [core.StackAddressEscape]}}
+}
+
+void test_returned_from_func_block_async() {
+  dispatch_async(queue, get_leaking_block());
+  // expected-warning@-1 {{Address of stack memory associated with local variable 'leaked_x' \
+is captured by an asynchronously-executed block [alpha.core.StackAddressAsyncEscape]}}
+}
Index: clang/test/Analysis/incorrect-checker-names.cpp
===
--- clang/test/Analysis/incorrect-checker-names.cpp
+++ clang/test/Analysis/incorrect-checker-names.cpp
@@ -5,9 +5,16 @@
 int* stack_addr_escape_base() {
   int x = 0;
   // FIXME: This shouldn't be tied to a modeling checker.
-  return &x; // expected-warning{{Address of stack memory associated with local variable 'x' returned to caller [core.StackAddrEscapeBase]}}
+  return &x; // expected-warning{{Address of stack memory associated with local variable 'x' returned to caller [core.StackAddressEscape]}}
   // expected-note-re@-1^Address of stack memory associated with local variable 'x' returned to caller$
   // Just a regular compiler warning.
   // expected-warning@-3{{address of stack memory associated with local variable 'x' returned}}
 }
 
+char const *p;
+
+void f0() {
+  char const str[] = "This will change";
+  p = str;
+} // expected-warning{{Address of stack memory associated with local variable 'str' is still referred to by the global variable 'p' upon returning to the caller.  This will be a dangling reference [core.StackAddressEscape]}}
+// expected-note@-1{{Address of stack memory associated with local variable 'str' is still referred to by the global variable 'p' upon returning to the caller.  This will be a dangling reference}}
Index: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -43,6 +43,7 @@
   };
 
   DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  CheckerNameRef CheckNames[CK_NumCheckKinds];
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPreStmt(const ReturnStmt *RS, CheckerContext &C) const;
@@ -156,7 +157,8 @@
 return;
   if (!BT_returnstack)
 BT_returnstack = std::make_unique(
-this, "Return of address to stack-allocated memory");
+CheckNames[CK_StackAddrEscapeChecker],
+"Return of address to stack-allocated memory");
   // Generate a report for this bug.
   SmallString<128> buf;
   llvm::raw_svector_ostream os(buf);
@@ -195,7 +197,8 @@
   continue;
 if (!BT_capturedstackasync)
   BT_capturedstackasync = st

Re: [PATCH] D63194: [clangd] Link and initialize target infos

2020-04-14 Thread Filipe Cabecinhas via cfe-commits
Hi Kadir,

Thank you for looking into this.
Unfortunately, I can't repro this anymore. I wonder if I had a weird stale
clangd or something. Current test (now changed to armv7) does set the
target properly. When I tried last time, it wasn't setting it, and was
defaulting to my system's (darwin).

Thank you,
  Filipe


On Sat, Apr 11, 2020 at 5:20 PM Kadir Çetinkaya  wrote:

> Hi Filipe! Thanks for letting me know, I've sent
> https://reviews.llvm.org/D77944 to enable this in clangd lit config.
>
> Regarding the failure, I can't seem to repro on machines I have access to.
> The premerge-tests also seems to be succeeding, please see
> https://results.llvm-merge-guard.org/BETA_amd64_debian_testing_clang8-626/console-log.txt
> .
>
> Can you provide more info about how you've ran the test?
>
> On Fri, Apr 10, 2020 at 4:23 PM Filipe Cabecinhas 
> wrote:
>
>> Hi Kadir,
>>
>> Can you fix the target_info.test clangd test you committed in this
>> revision, please?
>> I see you've tried fixing it later by adding `REQUIRES:
>> x86-registered-target`, but now it's never running because that feature
>> isn't (ever) set.
>> Here's a buildbot run showing it as unsupported (x86 target is built):
>> http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/26746/steps/test-check-all/logs/stdio
>>
>> I saw you tried to fix the test in r364413 ([clangd] Disable failing
>> unittest on non-x86 platforms) because it was always failing. The problem
>> is that, even though the feature check is needed, the test still isn't
>> working well. I just ran it manually and didn't get the target changed from
>> my host one.
>>
>> Here's a diff for the feature check that you can apply to propagate the
>> feature. But we still need to get the clangd code fixed so it picks up the
>> target:
>>
>> ```
>> diff --git a/clang-tools-extra/clangd/test/lit.cfg.py
>> b/clang-tools-extra/clangd/test/lit.cfg.py
>> index 5030ca356ef..54406498af0 100644
>> --- a/clang-tools-extra/clangd/test/lit.cfg.py
>> +++ b/clang-tools-extra/clangd/test/lit.cfg.py
>> @@ -3,6 +3,19 @@ import lit.llvm
>>  lit.llvm.initialize(lit_config, config)
>>  lit.llvm.llvm_config.use_clang()
>>
>> +# required for target_info.test
>> +def calculate_arch_features(arch_string):
>> +features = []
>> +for arch in arch_string.split():
>> +features.append(arch.lower() + '-registered-target')
>> +return features
>> +
>> +lit.llvm.llvm_config.feature_config(
>> +[('--assertion-mode', {'ON': 'asserts'}),
>> + ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}),
>> + ('--targets-built', calculate_arch_features)
>> + ])
>> +
>>  config.name = 'Clangd'
>>  config.suffixes = ['.test']
>>  config.excludes = ['Inputs']
>> ```
>>
>> Thank you,
>>
>>   Filipe
>>
>>   Filipe
>>
>>
>> On Wed, Jun 26, 2019 at 8:48 AM Kadir Cetinkaya via Phabricator via
>> cfe-commits  wrote:
>>
>>> kadircet closed this revision.
>>> kadircet added a comment.
>>>
>>> Landed as rL364387 
>>>
>>>
>>> Repository:
>>>   rG LLVM Github Monorepo
>>>
>>> CHANGES SINCE LAST ACTION
>>>   https://reviews.llvm.org/D63194/new/
>>>
>>> https://reviews.llvm.org/D63194
>>>
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 440b445 - [clang-objc-fuzzer] Add LLVMFuzzerInitialize to fix msvc builds (PR44414)

2020-04-14 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-04-14T13:37:27+01:00
New Revision: 440b445fff848aded09fe5f7d69ff690113e44e2

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

LOG: [clang-objc-fuzzer] Add LLVMFuzzerInitialize to fix msvc builds (PR44414)

The (supposedly superfluous) LLVMFuzzerInitialize function was removed when 
this file was copied from clang-fuzzer, but this is causing link errors on some 
targets. @morehouse confirmed on D69171 that it was OK to add back.

Added: 


Modified: 
clang/tools/clang-fuzzer/ClangObjectiveCFuzzer.cpp

Removed: 




diff  --git a/clang/tools/clang-fuzzer/ClangObjectiveCFuzzer.cpp 
b/clang/tools/clang-fuzzer/ClangObjectiveCFuzzer.cpp
index 908778f3d765..40fb07d3332f 100644
--- a/clang/tools/clang-fuzzer/ClangObjectiveCFuzzer.cpp
+++ b/clang/tools/clang-fuzzer/ClangObjectiveCFuzzer.cpp
@@ -16,6 +16,8 @@
 
 using namespace clang_fuzzer;
 
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { return 0; }
+
 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
   std::string s(reinterpret_cast(data), size);
   HandleCXX(s, "./test.m", {"-O2"});



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


[PATCH] D78098: [CGExprAgg] Fix infinite loop in `findPeephole`

2020-04-14 Thread Ehud Katz via Phabricator via cfe-commits
ekatz updated this revision to Diff 257299.
ekatz added a comment.
Herald added a subscriber: jfb.

Added test.


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

https://reviews.llvm.org/D78098

Files:
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/CodeGen/atomic-struct-bug.cpp


Index: clang/test/CodeGen/atomic-struct-bug.cpp
===
--- /dev/null
+++ clang/test/CodeGen/atomic-struct-bug.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// PR45476
+
+// This test used to get into an infinite loop,
+// which, in turn, caused clang to never finish execution.
+
+struct s3 {
+  char a, b, c;
+};
+
+_Atomic struct s3 a;
+
+extern "C" void foo() {
+  // CHECK-LABEL: @foo
+  // CHECK: store atomic i32
+
+  a = s3{1, 2, 3};
+}
+
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -678,16 +678,16 @@
 /// Attempt to look through various unimportant expressions to find a
 /// cast of the given kind.
 static Expr *findPeephole(Expr *op, CastKind kind) {
-  while (true) {
-op = op->IgnoreParens();
-if (CastExpr *castE = dyn_cast(op)) {
-  if (castE->getCastKind() == kind)
-return castE->getSubExpr();
-  if (castE->getCastKind() == CK_NoOp)
-continue;
-}
-return nullptr;
+  while (CastExpr *castE = dyn_cast(op->IgnoreParens())) {
+if (castE->getCastKind() == kind)
+  return castE->getSubExpr();
+
+if (castE->getCastKind() != CK_NoOp || castE == op)
+  break;
+
+op = castE;
   }
+  return nullptr;
 }
 
 void AggExprEmitter::VisitCastExpr(CastExpr *E) {


Index: clang/test/CodeGen/atomic-struct-bug.cpp
===
--- /dev/null
+++ clang/test/CodeGen/atomic-struct-bug.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// PR45476
+
+// This test used to get into an infinite loop,
+// which, in turn, caused clang to never finish execution.
+
+struct s3 {
+  char a, b, c;
+};
+
+_Atomic struct s3 a;
+
+extern "C" void foo() {
+  // CHECK-LABEL: @foo
+  // CHECK: store atomic i32
+
+  a = s3{1, 2, 3};
+}
+
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -678,16 +678,16 @@
 /// Attempt to look through various unimportant expressions to find a
 /// cast of the given kind.
 static Expr *findPeephole(Expr *op, CastKind kind) {
-  while (true) {
-op = op->IgnoreParens();
-if (CastExpr *castE = dyn_cast(op)) {
-  if (castE->getCastKind() == kind)
-return castE->getSubExpr();
-  if (castE->getCastKind() == CK_NoOp)
-continue;
-}
-return nullptr;
+  while (CastExpr *castE = dyn_cast(op->IgnoreParens())) {
+if (castE->getCastKind() == kind)
+  return castE->getSubExpr();
+
+if (castE->getCastKind() != CK_NoOp || castE == op)
+  break;
+
+op = castE;
   }
+  return nullptr;
 }
 
 void AggExprEmitter::VisitCastExpr(CastExpr *E) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

2020-04-14 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D77809#1979911 , @balazske wrote:

> I looked at the graphical CFG dump and observed that the added code makes the 
> same parts appear that are there in a VLA declaration but missing if a VLA 
> typedef is used.


Could add a test case those with the CFG dumper debug checker? 
`clang/test/Analysis/cfg.cpp` is a great example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809



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


[PATCH] D77875: [ARM] Armv8.6-a Matrix Mul cmd line support

2020-04-14 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

Or in other words, does amrv8.6-a+sve imply +f32mm *and* +f64mm?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77875



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


[PATCH] D77233: [NFC] Refactoring PropertyAttributeKind for ObjCPropertyDecl and ObjCDeclSpec.

2020-04-14 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/include/clang-c/Index.h:4503
   CXObjCPropertyAttr_unsafe_unretained = 0x800,
-  CXObjCPropertyAttr_class = 0x1000
+  CXObjCPropertyAttr_classattr = 0x1000
 } CXObjCPropertyAttrKind;

plotfi wrote:
> erik.pilkington wrote:
> > plotfi wrote:
> > > @erik.pilkington  Do you think we should be adding the C-API analogs of 
> > > nullability / null_resettable (and direct) to 
> > > clang/include/clang-c/Index.h? 
> > > 
> > > I noticed those are missing.
> > > 
> > > 
> > Oh, sorry, I missed this. The C API is supposed to be stable, so I don't 
> > think we should change the name of this enumerator (@arphaman can you 
> > confirm?). Adding the missing attributes seem fine though. 
> @erik.pilkington  @arphaman Any chance I can land the C API changes in a 
> follow up commit? That's what I was thinking. 
I think this enumerator should stay named `CXObjCPropertyAttr_class`, changing 
the name to `CXObjCPropertyAttr_classattr` is API breaking, and the C API 
should be stable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77233



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


[PATCH] D78100: [AST] Suppress the spammy "attempt to use a deleted fucntion" diagnostic.

2020-04-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 257302.
hokein added a comment.

fix the broken tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78100

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class.access/p4.cpp
  clang/test/CXX/special/class.ctor/p5-0x.cpp
  clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
  clang/test/SemaCXX/virtual-base-used.cpp
  clang/test/SemaObjCXX/arc-0x.mm

Index: clang/test/SemaObjCXX/arc-0x.mm
===
--- clang/test/SemaObjCXX/arc-0x.mm
+++ clang/test/SemaObjCXX/arc-0x.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -fobjc-weak -verify -fblocks -fobjc-exceptions %s
+// RUN: %clang_cc1 -frecovery-ast -std=c++11 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -fobjc-weak -verify -fblocks -fobjc-exceptions %s
 
 // "Move" semantics, trivial version.
 void move_it(__strong id &&from) {
@@ -116,13 +116,13 @@
   // Implicitly-declared special functions of a union are deleted by default if
   // ARC is enabled and the union has an ObjC pointer field.
   union U0 {
-id f0; // expected-note 7 {{'U0' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+id f0; // expected-note 6 {{'U0' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
   };
 
   union U1 {
-__weak id f0; // expected-note 13 {{'U1' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+__weak id f0; // expected-note 12 {{'U1' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 U1() = default; // expected-warning {{explicitly defaulted default constructor is implicitly deleted}} expected-note {{explicitly defaulted function was implicitly deleted here}}
-~U1() = default; // expected-warning {{explicitly defaulted destructor is implicitly deleted}} expected-note 2{{explicitly defaulted function was implicitly deleted here}}
+~U1() = default; // expected-warning {{explicitly defaulted destructor is implicitly deleted}} expected-note {{explicitly defaulted function was implicitly deleted here}}
 U1(const U1 &) = default; // expected-warning {{explicitly defaulted copy constructor is implicitly deleted}} expected-note 2 {{explicitly defaulted function was implicitly deleted here}}
 U1(U1 &&) = default; // expected-warning {{explicitly defaulted move constructor is implicitly deleted}}
 U1 & operator=(const U1 &) = default; // expected-warning {{explicitly defaulted copy assignment operator is implicitly deleted}} expected-note 2 {{explicitly defaulted function was implicitly deleted here}}
@@ -154,15 +154,15 @@
   // functions of the containing class.
   struct S0 {
 union {
-  id f0; // expected-note 7 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  id f0; // expected-note 6 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
   char f1;
 };
   };
 
   struct S1 {
 union {
-  union { // expected-note 2 {{'S1' is implicitly deleted because variant field '' has a non-trivial}} expected-note 5 {{'S1' is implicitly deleted because field '' has a deleted}}
-id f0; // expected-note 3 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
+  union { // expected-note 2 {{'S1' is implicitly deleted because variant field '' has a non-trivial}} expected-note 4 {{'S1' is implicitly deleted because field '' has a deleted}}
+id f0; // expected-note 2 {{'' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 char f1;
   };
   int f2;
@@ -172,7 +172,7 @@
   struct S2 {
 union {
   // FIXME: the note should say 'f0' is causing the special functions to be deleted.
-  struct { // expected-note 7 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
+  struct { // expected-note 6 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
 id f0;
 int f1;
   };
@@ -189,18 +189,14 @@
   S1 *x5;
   S2 *x6;
 
-  static union { // expected-error {{call to implicitly-deleted default constructor of}} expected-error {{attempt to use a deleted function}}
-id g0; // expected-note {{default constructor of '' is implicitly deleted because variant field 'g0' is an ObjC pointer}} \
-   // expected-note {{destructor of '' is implicitly deleted because}}
+  static union { // expected-error {{call to implicitly-deleted default constructor of}}
+id g0; // expected-note {{default constructor of '' is implicitly deleted because variant field 'g0' is an ObjC pointer}}
   };
 
-  static union { // expected-error {{call to implicitly-deleted default constructor of}} expected-error {{attempt to use a deleted function}}
-union { // expected-note {{default constructor of '' is implici

[PATCH] D76612: [Matrix] Add draft specification for matrix support in Clang.

2020-04-14 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 257304.
fhahn added a comment.

Fix typo, remove a 2 places where `underlying` element type was used, move C 
portion of the example to LanguageExtensions.rst, drop the rest of the example.
:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76612

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/MatrixTypes.rst

Index: clang/docs/MatrixTypes.rst
===
--- /dev/null
+++ clang/docs/MatrixTypes.rst
@@ -0,0 +1,271 @@
+==
+Matrix Types
+==
+
+.. contents::
+   :local:
+
+.. _matrixtypes:
+
+Clang provides a C/C++ language extension that allows users to directly express
+fixed-size 2-dimensional matrices as language values and perform arithmetic on
+them.
+
+This feature is currently experimental, and both its design and its
+implementation are in flux.
+
+Draft Specification
+===
+
+Matrix Type
+---
+
+A matrix type is a scalar type with an underlying *element type*, a constant
+number of *rows*, and a constant number of *columns*. Matrix types with the same
+element type, rows, and columns are the same type. A value of a matrix type
+includes storage for ``rows * columns`` values of the *element type*. The
+internal layout, overall size and alignment are implementation-defined.
+A *matrix element type* must be a real type (as in C99 6.2.5p17) excluding
+enumeration types or an implementation-defined half-precision floating point
+type, otherwise the program is ill-formed.
+
+The maximum of the product of the number of rows and columns is
+implementation-defined. If that implementation-defined limit is exceeded, the
+program is ill-formed.
+
+Matrix Type Attribute
+-
+
+Matrix types can be declared by adding the ``matrix_type`` attribute to the
+declaration of a *typedef* (or a C++ alias declaration). The underlying type
+of the *typedef* must be a valid matrix element type. The
+attribute takes two arguments, both of which must be integer constant
+expressions that evaluate to a value greater than zero. The first specifies the
+number of rows, and the second specifies the number of columns. The underlying
+type of the *typedef* becomes a matrix type with the given dimensions and an
+element type of the former underlying type.
+
+If a declaration of a *typedef-name* has a ``matrix_type`` attribute, then all
+declaration of that *typedef-name* shall have a matrix_type attribute with the
+same element type, number of rows, and number of columns.
+
+Standard Conversions
+
+
+The standard conversions are extended as follows. Note that these conversions
+are intentionally not listed as satisfying the constraints for assignment,
+which is to say, they are only permitted as explicit casts, not as implicit
+conversions.
+
+A value of matrix type can be converted to another matrix type if the number of
+rows and columns are the size and the value's elements can be converted to the
+element type of the result type. The result is a matrix where each element is
+the converted corresponding element.
+
+A value of non-matrix type can be converted to a matrix type if it can be
+converted to the element type of the matrix. The result is a matrix where
+all elements are the converted original value.
+
+If the number of rows or columns differ between the original and resulting
+type, the program is ill-formed.
+
+
+Arithmetic Conversions
+--
+
+The usual arithmetic conversions are extended as follows.
+
+Insert at the start:
+
+* If both operands are of matrix type, no arithmetic conversion is performed.
+* If one operand is of matrix type and the other operand is of a valid matrix
+  element type, convert the non-matrix type operand to the matrix type
+  according to the standard conversion rules.
+
+Matrix Type Element Access Operator
+---
+
+An expression of the form ``E1 [E2] [E3]``, where ``E1`` has matrix type ``cv
+M``, is a matrix element access expression.  Let ``T`` be the element type
+of ``M``, and let ``R`` and ``C`` be the number of rows and columns in ``M``
+respectively.  The index expressions shall have integral or unscoped
+enumeration type and shall not be uses of the comma operator unless
+parenthesized.  The first index expression shall evaluate to a
+non-negative value less than ``R``, and the second index expression shall
+evaluate to a non-negative value less than ``C``, or else the expression has
+undefined behavior.  If ``E1`` is a prvalue, the result is a prvalue with type
+``T`` and is the value of the element at the given row and column in the matrix.
+Otherwise, the result is a glvalue with type ``cv T`` and with the same value
+category as ``E1`` which refers to the element at the given row and column in
+the matrix.
+
+Programs containing a single subscript expressio

[PATCH] D77229: [Analyzer][WIP] Avoid handling of LazyCompundVals in IteratorModeling

2020-04-14 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

OK, I made some experiments. In function `vector_insert_begin()` of test file 
`iterator-modeling.cpp`, line `960` we pass `i0` to `std::vector::insert()`. 
This function has no body at all so regardless of inlining of STL functions is 
enabled, this function is never inlined. Probably for this reason, because it 
does not have its `StackFrame` function `handleConstructionContext()` returns a 
C++ temporary at the end of the function. This temporary is not added to the 
construction context of the function thus it is not marked as live before 
removing dead symbols.

I see two ways now to resolve this. The first is to add these temporaries into 
the construction context. This requires the assertion in 
`ExprEngine::finishArgumentConstruction()` (around line 544, but I have some 
debug printouts there, at the moment so the line number may not be accurate) to 
be changed because it assumes that the region is a `VarRegion`. The second is 
somehow to recognize these temporary regions and mark them as alive based on 
the `CallEvent` by somehow checking the regions bound to its arguments but I 
wonder how exactly to do this.

@NoQ, I need you comments about the right direction about proceeding further.


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

https://reviews.llvm.org/D77229



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


[PATCH] D77732: [clangd] Shard preamble symbols in dynamic index

2020-04-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

Still LG




Comment at: clang-tools-extra/clangd/index/FileIndex.h:165
+  /// Returns absolute paths for all files that has a shard.
+  std::vector getAllFiles() const;
+

kadircet wrote:
> sammccall wrote:
> > I do find it a little weird not to expose the map-structure of the vast 
> > majority of the data here.
> > 
> > What steers you away from just making this a function
> > `StringMap shardIndexToFile(IndexFileIn, PathRef)`
> > where X could be `File` with a method to obtain the data, or the more 
> > anonymous `unique_function`?
> because the map structure is just pointers into the `IndexFileIn`, I wanted 
> to make sure those pointers do not outlive the IndexFileIn.
I don't think it's unreasonable to have a non-owning data structure with a 
comment, but up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77732



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


[PATCH] D76612: [Matrix] Add draft specification for matrix support in Clang.

2020-04-14 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 257309.
fhahn added a comment.

Drop another instance of underlying element type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76612

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/MatrixTypes.rst

Index: clang/docs/MatrixTypes.rst
===
--- /dev/null
+++ clang/docs/MatrixTypes.rst
@@ -0,0 +1,271 @@
+==
+Matrix Types
+==
+
+.. contents::
+   :local:
+
+.. _matrixtypes:
+
+Clang provides a C/C++ language extension that allows users to directly express
+fixed-size 2-dimensional matrices as language values and perform arithmetic on
+them.
+
+This feature is currently experimental, and both its design and its
+implementation are in flux.
+
+Draft Specification
+===
+
+Matrix Type
+---
+
+A matrix type is a scalar type with an underlying *element type*, a constant
+number of *rows*, and a constant number of *columns*. Matrix types with the same
+element type, rows, and columns are the same type. A value of a matrix type
+includes storage for ``rows * columns`` values of the *element type*. The
+internal layout, overall size and alignment are implementation-defined.
+A *matrix element type* must be a real type (as in C99 6.2.5p17) excluding
+enumeration types or an implementation-defined half-precision floating point
+type, otherwise the program is ill-formed.
+
+The maximum of the product of the number of rows and columns is
+implementation-defined. If that implementation-defined limit is exceeded, the
+program is ill-formed.
+
+Matrix Type Attribute
+-
+
+Matrix types can be declared by adding the ``matrix_type`` attribute to the
+declaration of a *typedef* (or a C++ alias declaration). The underlying type
+of the *typedef* must be a valid matrix element type. The
+attribute takes two arguments, both of which must be integer constant
+expressions that evaluate to a value greater than zero. The first specifies the
+number of rows, and the second specifies the number of columns. The underlying
+type of the *typedef* becomes a matrix type with the given dimensions and an
+element type of the former underlying type.
+
+If a declaration of a *typedef-name* has a ``matrix_type`` attribute, then all
+declaration of that *typedef-name* shall have a matrix_type attribute with the
+same element type, number of rows, and number of columns.
+
+Standard Conversions
+
+
+The standard conversions are extended as follows. Note that these conversions
+are intentionally not listed as satisfying the constraints for assignment,
+which is to say, they are only permitted as explicit casts, not as implicit
+conversions.
+
+A value of matrix type can be converted to another matrix type if the number of
+rows and columns are the size and the value's elements can be converted to the
+element type of the result type. The result is a matrix where each element is
+the converted corresponding element.
+
+A value of non-matrix type can be converted to a matrix type if it can be
+converted to the element type of the matrix. The result is a matrix where
+all elements are the converted original value.
+
+If the number of rows or columns differ between the original and resulting
+type, the program is ill-formed.
+
+
+Arithmetic Conversions
+--
+
+The usual arithmetic conversions are extended as follows.
+
+Insert at the start:
+
+* If both operands are of matrix type, no arithmetic conversion is performed.
+* If one operand is of matrix type and the other operand is of a valid matrix
+  element type, convert the non-matrix type operand to the matrix type
+  according to the standard conversion rules.
+
+Matrix Type Element Access Operator
+---
+
+An expression of the form ``E1 [E2] [E3]``, where ``E1`` has matrix type ``cv
+M``, is a matrix element access expression.  Let ``T`` be the element type
+of ``M``, and let ``R`` and ``C`` be the number of rows and columns in ``M``
+respectively.  The index expressions shall have integral or unscoped
+enumeration type and shall not be uses of the comma operator unless
+parenthesized.  The first index expression shall evaluate to a
+non-negative value less than ``R``, and the second index expression shall
+evaluate to a non-negative value less than ``C``, or else the expression has
+undefined behavior.  If ``E1`` is a prvalue, the result is a prvalue with type
+``T`` and is the value of the element at the given row and column in the matrix.
+Otherwise, the result is a glvalue with type ``cv T`` and with the same value
+category as ``E1`` which refers to the element at the given row and column in
+the matrix.
+
+Programs containing a single subscript expression into a matrix are ill-formed.
+
+**Note**: We considered providing an expression of the form
+``postfix-expr

[PATCH] D76612: [Matrix] Add draft specification for matrix support in Clang.

2020-04-14 Thread Florian Hahn via Phabricator via cfe-commits
fhahn marked 3 inline comments as done.
fhahn added inline comments.



Comment at: clang/docs/MatrixTypes.rst:12
+fixed-size matrices as language values and perform arithmetic on them.
+
+This feature is currently experimental, and both its design and its

SjoerdMeijer wrote:
> Would it be good to set expectations here or in the section below: define 
> that we're talking about 2-dimensional m × n matrices?
I've changed it to `fixed-size 2-dimensional matrices`. I think the type 
definition below should be already clear enough about being 2 dimensional.



Comment at: clang/docs/MatrixTypes.rst:27
+internal layout, overall size and alignment are implementation-defined.
+A *matrix element type* must be a real type (as in C99 6.2.5p17) excluding
+enumeration types or an implementation-defined half-precision floating point

SjoerdMeijer wrote:
> above you're using *element type* and here *matrix element type*. Since 
> hopefully we're talking about the same things, "matrix *element type*" would 
> be more consistent.
> 
> But this is just a nit, my main question is about the types:
> why not e.g. define this to be the C11 types, that include _FloatN types, so 
> that we can include N=16? Or is this intentionally omitted? I haven't even 
> checked if this is supported in the architecture extension, but might make 
> sense? And also, an element type cannot be an integer type? 
> 
>  
> above you're using *element type* and here *matrix element type*. Since 
> hopefully we're talking about the same things, "matrix *element type*" would 
> be more consistent.

Yes it is referring to the same thing. I had a look at most uses, and in most 
cases `element type` is used to refer to the element type of a given matrix 
type. In that context it seems a bit verbose to use `matrix element type`, 
although I am more than happy to change that if it helps with clarifying things.

I intentionally used `matrix element type` in `Arithmetic Conversions`, because 
there it is standing on its own and refers exactly to the set of types defined 
as valid matrix element types here.

> why not e.g. define this to be the C11 types, that include _FloatN types, so 
> that we can include N=16? Or is this intentionally omitted? I haven't even 
> checked if this is supported in the architecture extension, but might make 
> sense?

I couldn't find any reference to _FloatN types in the C11 draft version I 
checked. Do you by any chance have a reference to the _FloatN types?

> And also, an element type cannot be an integer type?

The current definition should include it (real types include integer and real 
floating point types according to  C99 6.2.5p17). I don't think there is any 
reason to exclude them I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76612



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


[PATCH] D77802: [analyzer] Improved RangeSet::Negate support of unsigned ranges

2020-04-14 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

Thank you for fixing this issue!

Please add a bit more tests where we can see that the negated of unsigned range 
of `[n..m]` is `UINT_MAX-m+1..UINT_MAX-n+1]`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77802



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


[PATCH] D76612: [Matrix] Add draft specification for matrix support in Clang.

2020-04-14 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: clang/docs/MatrixTypes.rst:27
+internal layout, overall size and alignment are implementation-defined.
+A *matrix element type* must be a real type (as in C99 6.2.5p17) excluding
+enumeration types or an implementation-defined half-precision floating point

fhahn wrote:
> SjoerdMeijer wrote:
> > above you're using *element type* and here *matrix element type*. Since 
> > hopefully we're talking about the same things, "matrix *element type*" 
> > would be more consistent.
> > 
> > But this is just a nit, my main question is about the types:
> > why not e.g. define this to be the C11 types, that include _FloatN types, 
> > so that we can include N=16? Or is this intentionally omitted? I haven't 
> > even checked if this is supported in the architecture extension, but might 
> > make sense? And also, an element type cannot be an integer type? 
> > 
> >  
> > above you're using *element type* and here *matrix element type*. Since 
> > hopefully we're talking about the same things, "matrix *element type*" 
> > would be more consistent.
> 
> Yes it is referring to the same thing. I had a look at most uses, and in most 
> cases `element type` is used to refer to the element type of a given matrix 
> type. In that context it seems a bit verbose to use `matrix element type`, 
> although I am more than happy to change that if it helps with clarifying 
> things.
> 
> I intentionally used `matrix element type` in `Arithmetic Conversions`, 
> because there it is standing on its own and refers exactly to the set of 
> types defined as valid matrix element types here.
> 
> > why not e.g. define this to be the C11 types, that include _FloatN types, 
> > so that we can include N=16? Or is this intentionally omitted? I haven't 
> > even checked if this is supported in the architecture extension, but might 
> > make sense?
> 
> I couldn't find any reference to _FloatN types in the C11 draft version I 
> checked. Do you by any chance have a reference to the _FloatN types?
> 
> > And also, an element type cannot be an integer type?
> 
> The current definition should include it (real types include integer and real 
> floating point types according to  C99 6.2.5p17). I don't think there is any 
> reason to exclude them I think.
>>why not e.g. define this to be the C11 types, that include _FloatN types, 
>> so that we can include N=16? Or is this intentionally omitted? I haven't 
>> even checked if this is supported in the architecture extension, but might 
>> make sense?
>>
> I couldn't find any reference to _FloatN types in the C11 draft version I 
> checked. Do you by any chance have a reference to the _FloatN types?

Sorry, I was a bit imprecise here, it's an extension of C11: ISO/IEC TS 
18661-3:2015.
My thinking was it would be cool to support the "proper" half-precision type. I 
thought about this, because of "or an implementation-defined half-precision" 
mentioned just below here, of which probably __fp16 is an example.  If you 
refer to the C99 types, you probably don't even need to mention this (although 
it won't do any harm)?

>>  And also, an element type cannot be an integer type?
>
> The current definition should include it (real types include integer and real 
> floating point types according to C99 6.2.5p17). I don't think there is any 
> reason to exclude them I think.

Ok, cheers, wrote this from memory (forgot this), and didn't check the standard.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76612



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


[PATCH] D77794: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/CMakeLists.txt:19
+add_library(gRPCProtos ${Index_proto_source} ${Index_grpc_header} 
${Index_grpc_source} ${Index_grpc_header})
+target_link_libraries(gRPCProtos gRPC::grpc++ protobuf::libprotobuf)
+

sorry, what I meant by "less weird names" was can we call these libraries 
`grpc++` instead of `gRPC::grpc++` and `protobuf` instead of 
`protobuf::libprotobuf`?
Those thare the names that the libraries are installed as on my system at 
least...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794



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


[PATCH] D78101: [analyzer][StackAddressEscape] Tie warnings to the diagnostic checkers rather then core.StackAddrEscapeBase

2020-04-14 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware accepted this revision.
baloghadamsoftware added a comment.
This revision is now accepted and ready to land.

This seems to be an obvious fix. Thank you for working on this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78101



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


[libclc] cccdd05 - libclc: Don't pass linker flags to CLC/LLAsm

2020-04-14 Thread Jan Vesely via cfe-commits

Author: Daniel Stone
Date: 2020-04-14T10:03:27-04:00
New Revision: cccdd0579b5027d0a21fd2dbc0a6a50330134976

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

LOG: libclc: Don't pass linker flags to CLC/LLAsm

We don't want the regular linker flags for these invocations, since
we're not compiling to the target machine anyway. This fixes things like
'/machine:x64' being unknown when invoked under Windows.

reviewer: jvesely
Differential Revision: https://reviews.llvm.org/D77164

Added: 


Modified: 
libclc/cmake/CMakeCLCInformation.cmake
libclc/cmake/CMakeLLAsmInformation.cmake

Removed: 




diff  --git a/libclc/cmake/CMakeCLCInformation.cmake 
b/libclc/cmake/CMakeCLCInformation.cmake
index dfbdda9941a7..6eecf4edf0e7 100644
--- a/libclc/cmake/CMakeCLCInformation.cmake
+++ b/libclc/cmake/CMakeCLCInformation.cmake
@@ -5,7 +5,7 @@ endif()
 
 if(NOT CMAKE_CLC_CREATE_STATIC_LIBRARY)
   set(CMAKE_CLC_CREATE_STATIC_LIBRARY
-"  -o  ")
+" -o  ")
 endif()
 
 set(CMAKE_INCLUDE_FLAG_CLC "-I")

diff  --git a/libclc/cmake/CMakeLLAsmInformation.cmake 
b/libclc/cmake/CMakeLLAsmInformation.cmake
index f1d013b02887..73fb28e13135 100644
--- a/libclc/cmake/CMakeLLAsmInformation.cmake
+++ b/libclc/cmake/CMakeLLAsmInformation.cmake
@@ -5,7 +5,7 @@ endif()
 
 if(NOT CMAKE_LLAsm_CREATE_STATIC_LIBRARY)
   set(CMAKE_LLAsm_CREATE_STATIC_LIBRARY
-"  -o  ")
+" -o  ")
 endif()
 
 set(CMAKE_INCLUDE_FLAG_LLAsm "-I")



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


[libclc] 24fad72 - libclc: Use temporary files rather than a pipe

2020-04-14 Thread Jan Vesely via cfe-commits

Author: Daniel Stone
Date: 2020-04-14T10:03:27-04:00
New Revision: 24fad7278a391c6f8af664f4ac691c1719008a09

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

LOG: libclc: Use temporary files rather than a pipe

This is required for using the Ninja backend on Windows, as it passes
commands directly to CreateProcess, and does not allow the shell to
interpret them: https://ninja-build.org/manual.html#ref_rule_command

Using the Visual Studio backend is not possible as attempting to create
a static library target comprised entirely of novel languages not known
to the Visual Studio backend built in to CMake's C++ source will
generate nothing at all.

reviewer: jvesely
Differential Revision: https://reviews.llvm.org/D77165

Added: 


Modified: 
libclc/cmake/CMakeLLAsmInformation.cmake

Removed: 




diff  --git a/libclc/cmake/CMakeLLAsmInformation.cmake 
b/libclc/cmake/CMakeLLAsmInformation.cmake
index 73fb28e13135..218e20a52fe8 100644
--- a/libclc/cmake/CMakeLLAsmInformation.cmake
+++ b/libclc/cmake/CMakeLLAsmInformation.cmake
@@ -1,6 +1,7 @@
 if(NOT CMAKE_LLAsm_COMPILE_OBJECT)
   set(CMAKE_LLAsm_COMPILE_OBJECT
- "${CMAKE_LLAsm_PREPROCESSOR} -E -P -x 
cl   -o - |  -o  ")
+ "${CMAKE_LLAsm_PREPROCESSOR} -E -P -x 
cl  -o .temp"
+ " -o  .temp")
 endif()
 
 if(NOT CMAKE_LLAsm_CREATE_STATIC_LIBRARY)



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


[libclc] acf0790 - libclc: Use echo rather than true for try_compile

2020-04-14 Thread Jan Vesely via cfe-commits

Author: Daniel Stone
Date: 2020-04-14T10:03:27-04:00
New Revision: acf079006e6dbdd23300e9289cc8d8197aab5fb5

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

LOG: libclc: Use echo rather than true for try_compile

When providing a fake compiler, libclc currently uses 'true' which does
not exist on Windows. Use echo instead as the no-op.

reviewer: jvesely
Differential Revision: https://reviews.llvm.org/D77163

Added: 


Modified: 
libclc/cmake/CMakeTestCLCCompiler.cmake
libclc/cmake/CMakeTestLLAsmCompiler.cmake

Removed: 




diff  --git a/libclc/cmake/CMakeTestCLCCompiler.cmake 
b/libclc/cmake/CMakeTestCLCCompiler.cmake
index fae660fbcadc..869fcc3d01ab 100644
--- a/libclc/cmake/CMakeTestCLCCompiler.cmake
+++ b/libclc/cmake/CMakeTestCLCCompiler.cmake
@@ -24,7 +24,7 @@ if(NOT CMAKE_CLC_COMPILER_WORKS)
   try_compile(CMAKE_CLC_COMPILER_WORKS ${CMAKE_BINARY_DIR}
 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCLCCompiler.cl
 # We never generate executable so bypass the link step
-CMAKE_FLAGS -DCMAKE_CLC_LINK_EXECUTABLE='true'
+CMAKE_FLAGS -DCMAKE_CLC_LINK_EXECUTABLE='echo'
 OUTPUT_VARIABLE __CMAKE_CLC_COMPILER_OUTPUT)
   # Move result from cache to normal variable.
   set(CMAKE_CLC_COMPILER_WORKS ${CMAKE_CLC_COMPILER_WORKS})

diff  --git a/libclc/cmake/CMakeTestLLAsmCompiler.cmake 
b/libclc/cmake/CMakeTestLLAsmCompiler.cmake
index 1a87457c2cde..35948ee07a94 100644
--- a/libclc/cmake/CMakeTestLLAsmCompiler.cmake
+++ b/libclc/cmake/CMakeTestLLAsmCompiler.cmake
@@ -24,7 +24,7 @@ if(NOT CMAKE_LLAsm_COMPILER_WORKS)
   try_compile(CMAKE_LLAsm_COMPILER_WORKS ${CMAKE_BINARY_DIR}
 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testLLAsmCompiler.ll
 # We never generate executable so bypass the link step
-CMAKE_FLAGS -DCMAKE_LLAsm_LINK_EXECUTABLE='true'
+CMAKE_FLAGS -DCMAKE_LLAsm_LINK_EXECUTABLE='echo'
 OUTPUT_VARIABLE __CMAKE_LLAsm_COMPILER_OUTPUT)
   # Move result from cache to normal variable.
   set(CMAKE_LLAsm_COMPILER_WORKS ${CMAKE_LLAsm_COMPILER_WORKS})



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


[libclc] e6bb1d6 - libclc: Fix LLVM library linking on Windows

2020-04-14 Thread Jan Vesely via cfe-commits

Author: Daniel Stone
Date: 2020-04-14T10:03:27-04:00
New Revision: e6bb1d69eccc612e54fd1a0b63ca3dcc84c3a6fa

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

LOG: libclc: Fix LLVM library linking on Windows

CMake requires library lists on Windows to be split by semi-colons,
rather than the spaces we get from llvm-config. Fix this by a
substitution on Windows.

reviewer: jvesely
Differential Revision: https://reviews.llvm.org/D77162

Added: 


Modified: 
libclc/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 4afed0d8f994..7274f02f666b 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -58,9 +58,11 @@ list( SORT LIBCLC_TARGETS_TO_BUILD )
 execute_process( COMMAND ${LLVM_CONFIG} "--system-libs"
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE )
+separate_arguments( LLVM_SYSTEM_LIBS )
 execute_process( COMMAND ${LLVM_CONFIG} "--libs" "core" "bitreader" "bitwriter"
OUTPUT_VARIABLE LLVM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE )
+separate_arguments( LLVM_LIBS )
 execute_process( COMMAND ${LLVM_CONFIG} "--libdir"
OUTPUT_VARIABLE LLVM_LIBDIR
OUTPUT_STRIP_TRAILING_WHITESPACE )
@@ -76,7 +78,7 @@ execute_process( COMMAND ${LLVM_CONFIG} "--bindir"
OUTPUT_STRIP_TRAILING_WHITESPACE )
 
 # These were not properly reported in early LLVM and we don't need them
-set( LLVM_CXX_FLAGS ${LLVM_CXX_FLAGS} -fno-rtti -fno-exceptions )
+list( APPEND LLVM_CXX_FLAGS -fno-rtti -fno-exceptions )
 
 # Print LLVM variables
 message( "LLVM system libs: ${LLVM_SYSTEM_LIBS}" )



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


[clang-tools-extra] 808c285 - [clangd] Add tests that no-op changes are cheap

2020-04-14 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-04-14T16:15:23+02:00
New Revision: 808c2855e11615a384df9667338aa52854a92fd5

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

LOG: [clangd] Add tests that no-op changes are cheap

Summary:
We want to be sure they don't cause AST rebuilds or evict items from the cache.
D77847 is going to start sending spurious no-op changes (in case the preamble
was invalidated), this is cheap enough but we shouldn't regress that in future.

Reviewers: kadircet

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h
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 766cf7642155..f82bfa4f2682 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -703,9 +703,8 @@ void ClangdServer::semanticHighlights(
TUScheduler::InvalidateOnUpdate);
 }
 
-std::vector>
-ClangdServer::getUsedBytesPerFile() const {
-  return WorkScheduler.getUsedBytesPerFile();
+llvm::StringMap ClangdServer::fileStats() const {
+  return WorkScheduler.fileStats();
 }
 
 LLVM_NODISCARD bool

diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index ae3da84c42c8..f6e7e0799d83 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -304,14 +304,14 @@ class ClangdServer {
   void semanticHighlights(PathRef File,
   Callback>);
 
-  /// Returns estimated memory usage for each of the currently open files.
-  /// The order of results is unspecified.
+  /// Returns estimated memory usage and other statistics for each of the
+  /// currently open files.
   /// Overall memory usage of clangd may be significantly more than reported
   /// here, as this metric does not account (at least) for:
   ///   - memory occupied by static and dynamic index,
   ///   - memory required for in-flight requests,
   /// FIXME: those metrics might be useful too, we should add them.
-  std::vector> getUsedBytesPerFile() const;
+  llvm::StringMap fileStats() const;
 
   // Blocks the main thread until the server is idle. Only for use in tests.
   // Returns false if the timeout expires.

diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index 382cfe38239f..26adcfd2b8f2 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -397,7 +397,7 @@ class ASTWorker {
   /// getPossiblyStalePreamble() can be null even after this function returns.
   void waitForFirstPreamble() const;
 
-  std::size_t getUsedBytes() const;
+  TUScheduler::FileStats stats() const;
   bool isASTCached() const;
 
 private:
@@ -478,6 +478,8 @@ class ASTWorker {
   // don't. When the old handle is destroyed, the old worker will stop 
reporting
   // any results to the user.
   bool CanPublishResults = true; /* GUARDED_BY(PublishMu) */
+  std::atomic ASTBuildCount = {0};
+  std::atomic PreambleBuildCount = {0};
 
   SynchronizedTUStatus Status;
   PreambleThread PreamblePeer;
@@ -661,11 +663,13 @@ void ASTWorker::runWithAST(
   // FIXME: We might need to build a patched ast once preamble thread 
starts
   // running async. Currently getPossiblyStalePreamble below will always
   // return a compatible preamble as ASTWorker::update blocks.
-  llvm::Optional NewAST =
-  Invocation ? buildAST(FileName, std::move(Invocation),
-CompilerInvocationDiagConsumer.take(),
-FileInputs, getPossiblyStalePreamble())
- : None;
+  llvm::Optional NewAST;
+  if (Invocation) {
+NewAST = buildAST(FileName, std::move(Invocation),
+  CompilerInvocationDiagConsumer.take(), FileInputs,
+  getPossiblyStalePreamble());
+++ASTBuildCount;
+  }
   AST = NewAST ? std::make_unique(std::move(*NewAST)) : nullptr;
 }
 // Make sure we put the AST back into the LRU cache.
@@ -732,6 +736,7 @@ void 
ASTWorker::updatePreamble(std::unique_ptr CI,
 // running inside ASTWorker assumes internals won't change until it
 // finishes.
 if (Preamble != LatestPreamble) {
+  ++PreambleBuildCount;
   // Cached AST is no longer valid.

[PATCH] D78048: [clangd] Add tests that no-op changes are cheap

2020-04-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 3 inline comments as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/unittests/ClangdTests.cpp:501
+MATCHER_P4(Stats, Name, UsesMemory, PreambleBuilds, ASTBuilds, "") {
+  return arg.first() == Name && (arg.second.UsedBytes != 0) == UsesMemory &&
+ arg.second.PreambleBuilds == PreambleBuilds &&

kadircet wrote:
> nit:
> 
> ```
> std::make_tuple(arg.first(), arg.second.UsedBytes != 0, 
> arg.second.PreambleBuilds, arg.second.ASTBuilds) == std::tie(Name, 
> UsesMemory, PreambleBuilds, ASTBuilds);
> ```
Switched to tie for the trivial fields, but I don't like separating out the 
unnamed (first()) or nonobvious (UsedBytes!=0) things from what they're 
compared to.



Comment at: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp:762
+  ASSERT_TRUE(DoUpdate(SourceContents));
+  ASSERT_FALSE(DoUpdate(SourceContents));
+  ASSERT_EQ(S.fileStats().lookup(Source).ASTBuilds, 4u);

kadircet wrote:
> nit: maybe we drop these noop updates except the first one.
I think that allows an implementation that always compares the compile command 
to the first-ever (i.e. changes to the compile command don't "stick")
This is the primary test that verifies that no-op changes are recognized, so I 
think we should keep testing that (it's pretty cheap)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78048



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


[PATCH] D77229: [Analyzer][WIP] Avoid handling of LazyCompundVals in IteratorModeling

2020-04-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Aha, ok, sounds like i thought that it's not worth it to inline the constructor 
for an argument when the call itself is not inlined, therefore i didn't model 
the construction context for this call. See also D49443#1193290 
. Your example shows that i was wrong 
to give up and this is something we should totally implement.

The proper solution is to model the target region in `ExprEngine` as a 
parameter region based on the `ParmVarDecl` that //would have been used if the 
function was inlined//, instead of the dummy temporary. Then it'll be kept 
alive as an object under construction.

The most annoying part is to make sure that you're using the same 
`FunctionDecl` consistently everywhere. If this turns out to be too annoying, 
we could also replace `VarRegion{ParmVarDecl}` with a new sort of region that 
doesn't include a specific `ParmVarDecl` but merely a parameter index (and 
maybe a type or a call site expr), so that not to bother with redeclarations; 
this is the right thing to do anyway.


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

https://reviews.llvm.org/D77229



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


[PATCH] D78027: [TimeProfiler] Emit real process ID and thread names

2020-04-14 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop accepted this revision.
russell.gallop added a comment.
This revision is now accepted and ready to land.

Would be nice if the test could check that the pid was being set to something 
but not sure how you could do that (beyond checking that it's a number).

Apart from that, LGTM.


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

https://reviews.llvm.org/D78027



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


[PATCH] D76360: [PPC][AIX] Emit correct Vaarg for 32BIT-AIX in clang

2020-04-14 Thread Sean Fertile via Phabricator via cfe-commits
sfertile added inline comments.



Comment at: clang/test/CodeGen/ppc32-struct-return.c:53
+
+// AIX-SVR4: fatal error: error in backend: -msvr4-struct-return not supported 
on AIX
+ 

jasonliu wrote:
> If certain front end option is not supported on certain target, I think it 
> makes more sense to have a standard diagnostic in the driver component, 
> instead of "crash" in the backend. 
> i.e. What if we specify this option on a Windows machine? Maybe we should 
> pursue the same behavior. 
Its not that we don't intend to support the option on AIX, but that support for 
the option takes further verification on AIX.  Since there is a difference how  
AIX justifies subregister sized values in its argument passing, we can't just 
assume that this option will pack the return values the same way on AIX and 
Linux. 

The focus of this patch was originally to enable and verify the proper IR 
generation of va-arg/va-lis/va-start, however the scope of the patch has kept 
growing. If there are codegen differences in packing the return register with 
the svr4-return option enabled it will grow this patch once again. The fatal 
error lets us limit the scope of this patch, while not silently emiting bad 
codegen if there is a difference in how gcc initializes the return  registers. 
If during verification we decide we don't want to support the option on AIX, 
then adopting  a standard diagnostic in the driver component becomes the 
appropriate behavior. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76360



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


[PATCH] D77806: [analyzer] Do not report CFError null dereference for nonnull params

2020-04-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Looks great. I'll commit this one as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77806



___
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-04-14 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 257317.
martong marked an inline comment as done.
martong added a comment.

- Rebase to master
- Use BinaryOperator::negateComparisonOp
- getBufferDynamicSize -> getDynamicSizeWithOffset


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) {
+  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()

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

2020-04-14 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D77066#1953280 , @Charusso wrote:

> Please avoid to stuff in `CheckerContext` because this facility should be 
> used by ExprEngine/Store as well.
>  Let us reword your API: `getDynamicSizeWithOffset(ProgramStateRef, SVal, 
> SValBuilder &)`. Of course we are trying to obtain some buffer-ish size, that 
> is the purpose of the entire API.
>  I also could imagine something like `getDynamicSizeMul(ProgramStateRef, 
> const MemRegion &, const MemRegion &, SValBuilder &)`, as it is very common.
>
> May it would make sense to use the API like:
>
>   getDynamicSizeWithOffset(State, MR, SVB) {
> Offset = State->getStoreManager().getStaticOffset(MR, SVB);
> ...
>   }
>
>
> This idea is similar to `MemRegionManager::getStaticSize(MR, SVB)`. Hopefully 
> no-one needs dynamic offsets.


Thanks for the review! I've update the API as you suggested.


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] D78020: clang/AMDGPU: Assume denormals are enabled for the default target.

2020-04-14 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D78020#1978034 , @yaxunl wrote:

> I think https://reviews.llvm.org/D78019 should fix the issue about HIP not 
> using correct default denormal value if no arch is specified.
>
> In that case, driver actually sets offloading arch to gfx803 and clang should 
> be able to see it in JobAction.


I just tried again and you're right, the function does see the explicit 
GK_GFX803


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

https://reviews.llvm.org/D78020



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


[PATCH] D78020: clang/AMDGPU: Assume denormals are enabled for the default target.

2020-04-14 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 257318.
arsenm added a comment.

Fix test


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

https://reviews.llvm.org/D78020

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/test/Driver/cl-denorms-are-zero.cl
  clang/test/Driver/cuda-flush-denormals-to-zero.cu


Index: clang/test/Driver/cuda-flush-denormals-to-zero.cu
===
--- clang/test/Driver/cuda-flush-denormals-to-zero.cu
+++ clang/test/Driver/cuda-flush-denormals-to-zero.cu
@@ -22,6 +22,10 @@
 // RUN: %clang -x hip -no-canonical-prefixes -### -target x86_64-linux-gnu -c 
-march=haswell --cuda-gpu-arch=gfx803 -nocudainc -nogpulib %s 2>&1 | FileCheck 
-check-prefix=FTZ %s
 // RUN: %clang -x hip -no-canonical-prefixes -### -target x86_64-linux-gnu -c 
-march=haswell --cuda-gpu-arch=gfx900 -nocudainc -nogpulib %s 2>&1 | FileCheck 
-check-prefix=NOFTZ %s
 
+// Test no subtarget
+// FIXME: This defaults to gfx803, but gets a different denormal mode than 
explicitly specifying it.
+// RUN: %clang -x hip -no-canonical-prefixes -### -target x86_64-linux-gnu -c 
-march=haswell -nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=FTZ %s
+
 
 // Test multiple offload archs with different defaults.
 // RUN: %clang -x hip -no-canonical-prefixes -### -target x86_64-linux-gnu -c 
-march=haswell --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 -nocudainc 
-nogpulib %s 2>&1 | FileCheck -check-prefix=MIXED-DEFAULT-MODE %s
Index: clang/test/Driver/cl-denorms-are-zero.cl
===
--- clang/test/Driver/cl-denorms-are-zero.cl
+++ clang/test/Driver/cl-denorms-are-zero.cl
@@ -1,20 +1,24 @@
 // Slow FMAF and slow f32 denormals
-// RUN: %clang -### -target amdgcn--amdhsa -c -mcpu=pitcairn %s 2>&1 | 
FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
+// RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c -mcpu=pitcairn %s 2>&1 
| FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
 // RUN: %clang -### -cl-denorms-are-zero -o - -target amdgcn--amdhsa -c 
-mcpu=pitcairn %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
 
 // Fast FMAF, but slow f32 denormals
-// RUN: %clang -### -target amdgcn--amdhsa -c -mcpu=tahiti %s 2>&1 | FileCheck 
-check-prefixes=AMDGCN,AMDGCN-FLUSH %s
+// RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c -mcpu=tahiti %s 2>&1 | 
FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
 // RUN: %clang -### -cl-denorms-are-zero -o - -target amdgcn--amdhsa -c 
-mcpu=tahiti %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
 
 // Fast F32 denormals, but slow FMAF
-// RUN: %clang -### -target amdgcn--amdhsa -c -mcpu=fiji %s 2>&1 | FileCheck 
-check-prefixes=AMDGCN,AMDGCN-FLUSH %s
+// RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c -mcpu=fiji %s 2>&1 | 
FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
 // RUN: %clang -### -cl-denorms-are-zero -o - -target amdgcn--amdhsa -c 
-mcpu=fiji %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
 
 // Fast F32 denormals and fast FMAF
-// RUN: %clang -### -target amdgcn--amdhsa -c -mcpu=gfx900 %s 2>&1 | FileCheck 
-check-prefixes=AMDGCN,AMDGCN-DENORM %s
-// RUN: %clang -### -cl-denorms-are-zero -o - -target amdgcn--amdhsa -c 
-mcpu=gfx900 %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
+// RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c -mcpu=gfx900 %s 2>&1 | 
FileCheck -check-prefixes=AMDGCN,AMDGCN-DENORM %s
+// RUN: %clang -### -cl-denorms-are-zero -o - -target amdgcn--amdhsa -nogpulib 
-c -mcpu=gfx900 %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
+
+// Default target is artificial, but should assume a conservative default.
+// RUN: %clang -### -target amdgcn--amdhsa -nogpulib -c %s 2>&1 | FileCheck 
-check-prefixes=AMDGCN,AMDGCN-DENORM %s
+// RUN: %clang -### -cl-denorms-are-zero -o - -target amdgcn--amdhsa -nogpulib 
-c %s 2>&1 | FileCheck -check-prefixes=AMDGCN,AMDGCN-FLUSH %s
 
 // AMDGCN-FLUSH: "-fdenormal-fp-math-f32=preserve-sign,preserve-sign"
 
 // This should be omitted and default to ieee
-// AMDGCN-DENORM-NOT: "-fdenormal-fp-math-f32"
+// AMDGCN-DENORM-NOT: denormal-fp-math
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -262,6 +262,11 @@
 
 bool AMDGPUToolChain::getDefaultDenormsAreZeroForTarget(
 llvm::AMDGPU::GPUKind Kind) {
+
+  // Assume nothing without a specific target.
+  if (Kind == llvm::AMDGPU::GK_NONE)
+return false;
+
   const unsigned ArchAttr = llvm::AMDGPU::getArchAttrAMDGCN(Kind);
 
   // Default to enabling f32 denormals by default on subtargets where fma is


Index: clang/test/Driver/cuda-flush-denormals-to-zero.cu
===
--- clang/test/Driver/cuda-flush-denormals-to-zero.cu
+++ clang/test/Driver/cuda-flush-denormals-to-zero.cu
@@ -22,6 +22,10

[PATCH] D77989: Allow disabling of vectorization using internal options

2020-04-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D77989#1979772 , @wmi wrote:

> In D77989#1979725 , @wmi wrote:
>
> > The patch makes the reasoning about when the internal flags will take 
> > effect much easier.
> >
> > One question is, with the change, the internal flags can only be used to 
> > disable loop vectorization/slp vectorization/loop interleaving, but not to 
> > enable them. Can we treat them in the way that the flags in 
> > PipelineTuningOptions contain the default values set by Opt Level, and the 
> > internal flags can override them, which can either enable or disable the 
> > vectorizations/interleaving.
>
>
> I realize it is not easy to do since the internal flags are bool type, and 
> there is no easy way to specify unspecified values for the internal flags 
> which could allow us to use the default values set by Opt Level.  Ideally, we 
> want -slp-vectorize=true to enable slp, -slp-vectorize=false to disable slp, 
> no -slp-vectorize flag to keep the default value, but that is not easy to 
> achieve with current commandline library.


Right. The reason I went with the strategy of using the false value to disable 
is that they are all on by default (at least >O0), and it seemed more useful to 
have a way to disable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77989



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


[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-04-14 Thread Digger via Phabricator via cfe-commits
DiggerLin updated this revision to Diff 257319.
DiggerLin marked 2 inline comments as done.
DiggerLin added a comment.

address comment and add a new test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/test/Driver/aix-as.c
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/include/llvm/MC/MCDirectives.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/MC/MCAsmInfoXCOFF.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCXCOFFStreamer.cpp
  llvm/lib/MC/XCOFFObjectWriter.cpp
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/test/CodeGen/PowerPC/aix-LinkOnceAnyLinkage.ll
  llvm/test/CodeGen/PowerPC/aix-LinkOnceODRLinkage.ll
  llvm/test/CodeGen/PowerPC/aix-WeakODRLinkage.ll
  llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
  llvm/test/CodeGen/PowerPC/aix-extern.ll
  llvm/test/CodeGen/PowerPC/aix-linkage.ll
  llvm/test/CodeGen/PowerPC/aix-reference-func-addr-const.ll
  llvm/test/CodeGen/PowerPC/aix-weak.ll

Index: llvm/test/CodeGen/PowerPC/aix-weak.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-weak.ll
@@ -0,0 +1,358 @@
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec < %s | FileCheck --check-prefixes=COMMON,BIT32 %s
+
+; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec < %s | FileCheck --check-prefixes=COMMON,BIT64 %s
+
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN: -mattr=-altivec -filetype=obj -o %t.o < %s
+; RUN: llvm-readobj  --symbols %t.o | FileCheck --check-prefix=CHECKSYM %s
+
+@foo_weak_p = global void (...)* bitcast (void ()* @foo_ref_weak to void (...)*), align 4
+@b = weak global i32 0, align 4
+
+define weak void @foo_weak(i32* %p)  {
+entry:
+  %p.addr = alloca i32*, align 4
+  store i32* %p, i32** %p.addr, align 4
+  %0 = load i32*, i32** %p.addr, align 4
+  %1 = load i32, i32* %0, align 4
+  %inc = add nsw i32 %1, 1
+  store i32 %inc, i32* %0, align 4
+  ret void
+}
+
+define weak void @foo_ref_weak()  {
+entry:
+  ret void
+}
+
+define i32 @main()  {
+entry:
+  %0 = load void (...)*, void (...)** @foo_weak_p, align 4
+  %callee.knr.cast = bitcast void (...)* %0 to void ()*
+  call void %callee.knr.cast()
+  call void @foo_weak(i32* @b)
+  call void @foo_ref_weak()
+  ret i32 0
+}
+
+; COMMON:  	.weak	foo_weak[DS]# -- Begin function foo_weak
+; COMMON-NEXT:  .weak	.foo_weak
+; COMMON-NEXT:  .align	4
+; COMMON-NEXT:  .csect foo_weak[DS]
+; BIT32-NEXT:   .long	.foo_weak   # @foo_weak
+; BIT32-NEXT:   .long	TOC[TC0]
+; BIT32-NEXT:   .long	0
+; BIT64-NEXT:   .llong	.foo_weak   # @foo_weak
+; BIT64-NEXT:   .llong	TOC[TC0]
+; BIT64-NEXT:   .llong	0
+; COMMON-NEXT:  .csect .text[PR]
+; COMMON-NEXT:  .foo_weak:
+
+; COMMON:	.weak	foo_ref_weak[DS]# -- Begin function foo_ref_weak
+; COMMON-NEXT:  .weak	.foo_ref_weak
+; COMMON-NEXT:  .align	4
+; COMMON-NEXT:  .csect foo_ref_weak[DS]
+; BIT32-NEXT:   .long	.foo_ref_weak   # @foo_ref_weak
+; BIT32-NEXT:   .long	TOC[TC0]
+; BIT32-NEXT:   .long	0
+; BIT64-NEXT:   .llong	.foo_ref_weak   # @foo_ref_weak
+; BIT64-NEXT:   .llong	TOC[TC0]
+; BIT64-NEXT:   .llong	0
+; COMMON-NEXT:  .csect .text[PR]
+; COMMON-NEXT:  .foo_ref_weak:
+
+; COMMON:  	.globl	main[DS]# -- Begin function main
+; COMMON-NEXT:  .globl	.main
+; COMMON-NEXT:  .align	4
+; COMMON-NEXT:  .csect main[DS]
+; BIT32-NEXT:   .long	.main   # @main
+; BIT32-NEXT:   .long	TOC[TC0]
+; BIT32-NEXT:   .long	0
+; BIT64-NEXT:   .llong	.main   # @main
+; BIT64-NEXT:   .llong	TOC[TC0]
+; BIT64-NEXT:   .llong	0
+; COMMON-NEXT:  .csect .text[PR]
+; COMMON-NEXT:  .main:
+
+; COMMON: 	.csect .data[RW]
+; COMMON-NEXT:  .globl	foo_weak_p
+; BIT32-NEXT:   .align	2
+; BIT64-NEXT:   .align	3
+; COMMON-NEXT:  foo_weak_p:
+; BIT32-NEXT:   .long	foo_ref_weak[DS]
+; BIT64-NEXT:   .llong	foo_ref_weak[DS]
+; COMMON-NEXT:  .weak	b
+; COMMON-NEXT:  .align	2
+; COMMON-NEXT:  b:
+; COMMON-NEXT:  .long	0   # 0x0
+; COMMON-NEXT:  .toc
+; COMMON-NEXT:  LC0:
+; COMMON-NEXT:  .tc foo_weak_p[TC],foo_weak_p
+; COMMON-NEXT:  LC1:
+; COMMON-NEXT:  .tc b[TC],b
+
+
+; CHECKSYM:  Symbols [
+; CHECKSYM-NEXT:   Symbol {
+; CHECKSYM-NEXT: Index: [[#Index:]]
+; CHECKSYM-NEXT: Name: .text
+; CHECKSYM-NEXT: Value (RelocatableAddress

[PATCH] D78048: [clangd] Add tests that no-op changes are cheap

2020-04-14 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG808c2855e116: [clangd] Add tests that no-op changes are 
cheap (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D78048?vs=257083&id=257325#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78048

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  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
@@ -608,6 +608,37 @@
   UnorderedElementsAre(Foo, AnyOf(Bar, Baz)));
 }
 
+// We send "empty" changes to TUScheduler when we think some external event
+// *might* have invalidated current state (e.g. a header was edited).
+// Verify that this doesn't evict our cache entries.
+TEST_F(TUSchedulerTests, NoopChangesDontThrashCache) {
+  auto Opts = optsForTest();
+  Opts.RetentionPolicy.MaxRetainedASTs = 1;
+  TUScheduler S(CDB, Opts);
+
+  auto Foo = testPath("foo.cpp");
+  auto FooInputs = getInputs(Foo, "int x=1;");
+  auto Bar = testPath("bar.cpp");
+  auto BarInputs = getInputs(Bar, "int x=2;");
+
+  // After opening Foo then Bar, AST cache contains Bar.
+  S.update(Foo, FooInputs, WantDiagnostics::Auto);
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  S.update(Bar, BarInputs, WantDiagnostics::Auto);
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_THAT(S.getFilesWithCachedAST(), ElementsAre(Bar));
+
+  // Any number of no-op updates to Foo don't dislodge Bar from the cache.
+  S.update(Foo, FooInputs, WantDiagnostics::Auto);
+  S.update(Foo, FooInputs, WantDiagnostics::Auto);
+  S.update(Foo, FooInputs, WantDiagnostics::Auto);
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+  ASSERT_THAT(S.getFilesWithCachedAST(), ElementsAre(Bar));
+  // In fact each file has been built only once.
+  ASSERT_EQ(S.fileStats().lookup(Foo).ASTBuilds, 1u);
+  ASSERT_EQ(S.fileStats().lookup(Bar).ASTBuilds, 1u);
+}
+
 TEST_F(TUSchedulerTests, EmptyPreamble) {
   TUScheduler S(CDB, optsForTest());
 
@@ -686,7 +717,7 @@
   Files[Header] = "int a;";
   Timestamps[Header] = time_t(0);
 
-  auto SourceContents = R"cpp(
+  std::string SourceContents = R"cpp(
   #include "foo.h"
   int b = a;
 )cpp";
@@ -705,25 +736,32 @@
 
   // Test that subsequent updates with the same inputs do not cause rebuilds.
   ASSERT_TRUE(DoUpdate(SourceContents));
+  ASSERT_EQ(S.fileStats().lookup(Source).ASTBuilds, 1u);
+  ASSERT_EQ(S.fileStats().lookup(Source).PreambleBuilds, 1u);
   ASSERT_FALSE(DoUpdate(SourceContents));
+  ASSERT_EQ(S.fileStats().lookup(Source).ASTBuilds, 1u);
+  ASSERT_EQ(S.fileStats().lookup(Source).PreambleBuilds, 1u);
 
   // Update to a header should cause a rebuild, though.
   Timestamps[Header] = time_t(1);
   ASSERT_TRUE(DoUpdate(SourceContents));
   ASSERT_FALSE(DoUpdate(SourceContents));
+  ASSERT_EQ(S.fileStats().lookup(Source).ASTBuilds, 2u);
+  ASSERT_EQ(S.fileStats().lookup(Source).PreambleBuilds, 2u);
 
   // Update to the contents should cause a rebuild.
-  auto OtherSourceContents = R"cpp(
-  #include "foo.h"
-  int c = d;
-)cpp";
-  ASSERT_TRUE(DoUpdate(OtherSourceContents));
-  ASSERT_FALSE(DoUpdate(OtherSourceContents));
+  SourceContents += "\nint c = b;";
+  ASSERT_TRUE(DoUpdate(SourceContents));
+  ASSERT_FALSE(DoUpdate(SourceContents));
+  ASSERT_EQ(S.fileStats().lookup(Source).ASTBuilds, 3u);
+  ASSERT_EQ(S.fileStats().lookup(Source).PreambleBuilds, 2u);
 
   // Update to the compile commands should also cause a rebuild.
   CDB.ExtraClangFlags.push_back("-DSOMETHING");
-  ASSERT_TRUE(DoUpdate(OtherSourceContents));
-  ASSERT_FALSE(DoUpdate(OtherSourceContents));
+  ASSERT_TRUE(DoUpdate(SourceContents));
+  ASSERT_FALSE(DoUpdate(SourceContents));
+  ASSERT_EQ(S.fileStats().lookup(Source).ASTBuilds, 4u);
+  ASSERT_EQ(S.fileStats().lookup(Source).PreambleBuilds, 3u);
 }
 
 TEST_F(TUSchedulerTests, ForceRebuild) {
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -38,6 +38,7 @@
 
 namespace {
 
+using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::Field;
 using ::testing::Gt;
@@ -496,7 +497,13 @@
   EXPECT_THAT(*Locations, ElementsAre(DeclAt(FooCpp, FooSource.range("two";
 }
 
-TEST_F(ClangdVFSTest, MemoryUsage) {
+MATCHER_P4(Stats, Name, UsesMemory, PreambleBuilds, AST

[clang] f6ea026 - [SveEmitter] Fix encoding/decoding of SVETypeFlags

2020-04-14 Thread Sander de Smalen via cfe-commits

Author: Sander de Smalen
Date: 2020-04-14T15:48:28+01:00
New Revision: f6ea026f179a02cd335d71e4800b4d67c25c006b

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

LOG: [SveEmitter] Fix encoding/decoding of SVETypeFlags

Summary:
This issue was introduced when reworking D75861. The bug isn't
actually hit with current unit tests because the contiguous loads/stores
infer the EltType and the MemEltType from the pointer and result, rather
than using the flags. But it will be needed for other intrinsics, such as
gather/scatter.

Reviewers: SjoerdMeijer, Andrzej

Reviewed By: SjoerdMeijer

Subscribers: andwar, tschuett, cfe-commits, llvm-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/TargetBuiltins.h
clang/include/clang/Basic/arm_sve.td
clang/utils/TableGen/SveEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetBuiltins.h 
b/clang/include/clang/Basic/TargetBuiltins.h
index 99af2412426f..468167957974 100644
--- a/clang/include/clang/Basic/TargetBuiltins.h
+++ b/clang/include/clang/Basic/TargetBuiltins.h
@@ -17,6 +17,7 @@
 
 #include 
 #include "clang/Basic/Builtins.h"
+#include "llvm/Support/MathExtras.h"
 #undef PPC
 
 namespace clang {
@@ -163,6 +164,9 @@ namespace clang {
   /// Flags to identify the types for overloaded SVE builtins.
   class SVETypeFlags {
 uint64_t Flags;
+unsigned EltTypeShift;
+unsigned MemEltTypeShift;
+unsigned MergeTypeShift;
 
   public:
 #define LLVM_GET_SVE_TYPEFLAGS
@@ -181,15 +185,27 @@ namespace clang {
 #undef LLVM_GET_SVE_MEMELTTYPES
 };
 
-SVETypeFlags(uint64_t F) : Flags(F) {}
-SVETypeFlags(EltType ET, bool IsUnsigned) : Flags(ET) {}
+enum MergeType {
+#define LLVM_GET_SVE_MERGETYPES
+#include "clang/Basic/arm_sve_typeflags.inc"
+#undef LLVM_GET_SVE_MERGETYPES
+};
+SVETypeFlags(uint64_t F) : Flags(F) {
+  EltTypeShift = llvm::countTrailingZeros(EltTypeMask);
+  MemEltTypeShift = llvm::countTrailingZeros(MemEltTypeMask);
+  MergeTypeShift = llvm::countTrailingZeros(MergeTypeMask);
+}
 
 EltType getEltType() const {
-  return (EltType)((Flags & EltTypeMask) - FirstEltType);
+  return (EltType)((Flags & EltTypeMask) >> EltTypeShift);
 }
 
 MemEltType getMemEltType() const {
-  return (MemEltType)((Flags & MemEltTypeMask) - FirstMemEltType);
+  return (MemEltType)((Flags & MemEltTypeMask) >> MemEltTypeShift);
+}
+
+MergeType getMergeType() const {
+  return (MergeType)((Flags & MergeTypeMask) >> MergeTypeShift);
 }
 
 bool isLoad() const { return Flags & IsLoad; }

diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 4e75d0339b5c..9ed4ae86e1b7 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -84,15 +84,16 @@
 // Y: const pointer to uint32_t
 // Z: const pointer to uint64_t
 
-class MergeType {
+class MergeType {
   int Value = val;
+  string Suffix = suffix;
 }
 def MergeNone: MergeType<0>;
-def MergeAny : MergeType<1>;
-def MergeOp1 : MergeType<2>;
-def MergeZero: MergeType<3>;
-def MergeAnyExp  : MergeType<4>; // Use merged builtin with explicit
-def MergeZeroExp : MergeType<5>; // generation of its inactive argument.
+def MergeAny : MergeType<1, "_x">;
+def MergeOp1 : MergeType<2, "_m">;
+def MergeZero: MergeType<3, "_z">;
+def MergeAnyExp  : MergeType<4, "_x">; // Use merged builtin with explicit
+def MergeZeroExp : MergeType<5, "_z">; // generation of its inactive argument.
 
 class EltType {
   int Value = val;
@@ -134,13 +135,17 @@ def FirstMemEltType   : FlagType<0x0010>;
 //  : :
 //  : :
 def MemEltTypeMask: FlagType<0x0070>;
-def IsLoad: FlagType<0x0080>;
-def IsStore   : FlagType<0x0100>;
-def IsGatherLoad  : FlagType<0x0200>;
-def IsScatterStore: FlagType<0x0400>;
-def IsStructLoad  : FlagType<0x0800>;
-def IsStructStore : FlagType<0x1000>;
-def IsZExtReturn  : FlagType<0x2000>; // Return value is 
sign-extend by default
+def FirstMergeTypeMask: FlagType<0x0080>;
+//  : :
+//  : :
+def MergeTypeMask : FlagType<0x0380>;
+def IsLoad: FlagType<0x2000>;
+def IsStore   : FlagType<0x4000>;
+def IsGatherLoad  : FlagType<0x8000>;
+def IsScatterStore: FlagType<0x0001>;
+def IsStructLoad  : FlagType<0x0002

[PATCH] D78020: clang/AMDGPU: Assume denormals are enabled for the default target.

2020-04-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/Driver/cuda-flush-denormals-to-zero.cu:26
+// Test no subtarget
+// FIXME: This defaults to gfx803, but gets a different denormal mode than 
explicitly specifying it.
+// RUN: %clang -x hip -no-canonical-prefixes -### -target x86_64-linux-gnu -c 
-march=haswell -nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=FTZ %s

this comment can be removed or modified 


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

https://reviews.llvm.org/D78020



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


[PATCH] D76238: [SveEmitter] Implement builtins for contiguous loads/stores

2020-04-14 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/include/clang/Basic/arm_sve.td:186
+def SVLDFF1   : MInst<"svldff1[_{2}]", "dPc", "csilUcUsUiUlhfd", [IsLoad], 
  MemEltTyDefault, "aarch64_sve_ldff1">;
+def SVLDFF1SB : MInst<"svldff1sb_{d}", "dPS", "silUsUiUl",   [IsLoad], 
  MemEltTyInt8,"aarch64_sve_ldff1">;
+def SVLDFF1UB : MInst<"svldff1ub_{d}", "dPW", "silUsUiUl",   [IsLoad, 
IsZExtReturn], MemEltTyInt8,"aarch64_sve_ldff1">;

Andrzej wrote:
> Tests for `ldff1sb` seem to be missing.
Good spot, I've added this test before committing the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76238



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


[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

2020-04-14 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 257330.
balazske added a comment.

- Added tests.
- Updated a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/cfg.cpp


Index: clang/test/Analysis/cfg.cpp
===
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -568,6 +568,25 @@
   return 2;
 }
 
+// CHECK-LABEL: void vla_simple(int x)
+// CHECK: [B1]
+// CHECK-NEXT:   1: x
+// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: int vla[x];
+void vla_simple(int x) {
+  int vla[x];
+}
+
+// CHECK-LABEL: void vla_typedef(int x)
+// CHECK: [B1]
+// CHECK-NEXT:   1: x
+// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: VLA vla;
+void vla_typedef(int x) {
+  typedef int VLA[x];
+  VLA vla;
+}
+
 // CHECK-LABEL: template<> int *PR18472()
 // CHECK: [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2839,11 +2839,24 @@
 /// DeclStmts and initializers in them.
 CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) {
   assert(DS->isSingleDecl() && "Can handle single declarations only.");
+
+  if (const auto *TDD = dyn_cast(DS->getSingleDecl())) {
+// If we encounter a VLA in typedef, then process its size expressions.
+CFGBlock *LastBlock = Block;
+for (const VariableArrayType *VA =
+ FindVA(TDD->getUnderlyingType().getTypePtr());
+ VA != nullptr; VA = FindVA(VA->getElementType().getTypePtr())) {
+  if (CFGBlock *newBlock = addStmt(VA->getSizeExpr()))
+LastBlock = newBlock;
+}
+return LastBlock;
+  }
+
   VarDecl *VD = dyn_cast(DS->getSingleDecl());
 
   if (!VD) {
-// Of everything that can be declared in a DeclStmt, only VarDecls impact
-// runtime semantics.
+// Of everything that can be declared in a DeclStmt, only VarDecls and the
+// exceptions above impact runtime semantics.
 return Block;
   }
 


Index: clang/test/Analysis/cfg.cpp
===
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -568,6 +568,25 @@
   return 2;
 }
 
+// CHECK-LABEL: void vla_simple(int x)
+// CHECK: [B1]
+// CHECK-NEXT:   1: x
+// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: int vla[x];
+void vla_simple(int x) {
+  int vla[x];
+}
+
+// CHECK-LABEL: void vla_typedef(int x)
+// CHECK: [B1]
+// CHECK-NEXT:   1: x
+// CHECK-NEXT:   2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: VLA vla;
+void vla_typedef(int x) {
+  typedef int VLA[x];
+  VLA vla;
+}
+
 // CHECK-LABEL: template<> int *PR18472()
 // CHECK: [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2839,11 +2839,24 @@
 /// DeclStmts and initializers in them.
 CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) {
   assert(DS->isSingleDecl() && "Can handle single declarations only.");
+
+  if (const auto *TDD = dyn_cast(DS->getSingleDecl())) {
+// If we encounter a VLA in typedef, then process its size expressions.
+CFGBlock *LastBlock = Block;
+for (const VariableArrayType *VA =
+ FindVA(TDD->getUnderlyingType().getTypePtr());
+ VA != nullptr; VA = FindVA(VA->getElementType().getTypePtr())) {
+  if (CFGBlock *newBlock = addStmt(VA->getSizeExpr()))
+LastBlock = newBlock;
+}
+return LastBlock;
+  }
+
   VarDecl *VD = dyn_cast(DS->getSingleDecl());
 
   if (!VD) {
-// Of everything that can be declared in a DeclStmt, only VarDecls impact
-// runtime semantics.
+// Of everything that can be declared in a DeclStmt, only VarDecls and the
+// exceptions above impact runtime semantics.
 return Block;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

2020-04-14 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added a comment.

Without the new code the CFG dump for `vla_typedef` contains:

  [B1]
 1: VLA vla;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809



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


[PATCH] D76389: [NewPM] Run the Speculative Execution Pass only if the target has divergent branches

2020-04-14 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/include/llvm/Transforms/Scalar/SpeculativeExecution.h:97
+
+class SpeculativeExecutionIfHasBranchDivergencePass
+: public SpeculativeExecutionPassImpl,

Still define a second pass



Comment at: llvm/lib/Passes/PassBuilder.cpp:435
   if (Level.getSpeedupLevel() > 1) {
-FPM.addPass(SpeculativeExecutionPass());
+FPM.addPass(SpeculativeExecutionIfHasBranchDivergencePass());
 

leonardchan wrote:
> arsenm wrote:
> > I don't expect this to be a separate pass, just added based on a divergent 
> > target
> Updated such that the current pass is used, although it's a bit more 
> difficult to test since the same pass name will appear when dumping the 
> passes.
There's a check for divergent branches in the builder so you don't need to run 
the pass at all


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76389



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


[PATCH] D78075: [Clang][OpenMP] Added support for nowait target in CodeGen

2020-04-14 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

You need to update the tests too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075



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


[PATCH] D77875: [ARM] Armv8.6-a Matrix Mul cmd line support

2020-04-14 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson added a comment.

In D77875#1979980 , @DavidSpickett 
wrote:

> > Note: +f32mm and +f64mm are optional and so have to be enabled by default
>
> I think I know what you mean, but "and so are not enabled by default" would 
> be clearer.
>
> Also to double check, does f64mm imply f32mm? (not sure if there's an updated 
> ARMARM yet that would tell me that)


Since these options can be enabled independently pre-8.6a in general the answer 
is no. I'll add a comment noting why we only only imply f32mm in AArch64.cpp

In D77875#1980488 , @DavidSpickett 
wrote:

> Or in other words, does amrv8.6-a+sve imply +f32mm *and* +f64mm?


Also no here, as an example the xml has different checks for fmmla 
https://developer.arm.com/docs/ddi0596/latest/a64-sve-instructions-alphabetic-order/fmmla-floating-point-matrix-multiply-accumulate


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77875



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


[PATCH] D76360: [PPC][AIX] Emit correct Vaarg for 32BIT-AIX in clang

2020-04-14 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: clang/test/CodeGen/ppc32-struct-return.c:53
+
+// AIX-SVR4: fatal error: error in backend: -msvr4-struct-return not supported 
on AIX
+ 

jasonliu wrote:
> sfertile wrote:
> > jasonliu wrote:
> > > If certain front end option is not supported on certain target, I think 
> > > it makes more sense to have a standard diagnostic in the driver 
> > > component, instead of "crash" in the backend. 
> > > i.e. What if we specify this option on a Windows machine? Maybe we should 
> > > pursue the same behavior. 
> > Its not that we don't intend to support the option on AIX, but that support 
> > for the option takes further verification on AIX.  Since there is a 
> > difference how  AIX justifies subregister sized values in its argument 
> > passing, we can't just assume that this option will pack the return values 
> > the same way on AIX and Linux. 
> > 
> > The focus of this patch was originally to enable and verify the proper IR 
> > generation of va-arg/va-lis/va-start, however the scope of the patch has 
> > kept growing. If there are codegen differences in packing the return 
> > register with the svr4-return option enabled it will grow this patch once 
> > again. The fatal error lets us limit the scope of this patch, while not 
> > silently emiting bad codegen if there is a difference in how gcc 
> > initializes the return  registers. If during verification we decide we 
> > don't want to support the option on AIX, then adopting  a standard 
> > diagnostic in the driver component becomes the appropriate behavior. 
> It wasn't clear for me from the code that this is not a permanent thing.  In 
> that case, does it make sense to leave a TODO here and say we need to 
> re-evaluate this in the future to decide if we want to support it or not on 
> AIX?
> On another note, I'm not sure if this is really needed on AIX target though. 
> But I guess we could discuss it down the road. 
Just to avoid ambiguity, I meant I'm not sure if we really need this *option* 
on AIX.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76360



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


[PATCH] D76360: [PPC][AIX] Emit correct Vaarg for 32BIT-AIX in clang

2020-04-14 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: clang/test/CodeGen/ppc32-struct-return.c:53
+
+// AIX-SVR4: fatal error: error in backend: -msvr4-struct-return not supported 
on AIX
+ 

sfertile wrote:
> jasonliu wrote:
> > If certain front end option is not supported on certain target, I think it 
> > makes more sense to have a standard diagnostic in the driver component, 
> > instead of "crash" in the backend. 
> > i.e. What if we specify this option on a Windows machine? Maybe we should 
> > pursue the same behavior. 
> Its not that we don't intend to support the option on AIX, but that support 
> for the option takes further verification on AIX.  Since there is a 
> difference how  AIX justifies subregister sized values in its argument 
> passing, we can't just assume that this option will pack the return values 
> the same way on AIX and Linux. 
> 
> The focus of this patch was originally to enable and verify the proper IR 
> generation of va-arg/va-lis/va-start, however the scope of the patch has kept 
> growing. If there are codegen differences in packing the return register with 
> the svr4-return option enabled it will grow this patch once again. The fatal 
> error lets us limit the scope of this patch, while not silently emiting bad 
> codegen if there is a difference in how gcc initializes the return  
> registers. If during verification we decide we don't want to support the 
> option on AIX, then adopting  a standard diagnostic in the driver component 
> becomes the appropriate behavior. 
It wasn't clear for me from the code that this is not a permanent thing.  In 
that case, does it make sense to leave a TODO here and say we need to 
re-evaluate this in the future to decide if we want to support it or not on AIX?
On another note, I'm not sure if this is really needed on AIX target though. 
But I guess we could discuss it down the road. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76360



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


[PATCH] D77461: [WIP][clang-tidy] Remove false positive in AvoidNonConstGlobalVariables

2020-04-14 Thread Kim Viggedal via Phabricator via cfe-commits
vingeldal added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp:234-236
+static int staticNonConstLoopVariable = 42;
 int nonConstLoopVariable = 42;
+nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;

aaron.ballman wrote:
> I would like this example moved out of the section suggesting this is a false 
> positive.
I don't follow I thought you said this was a false positive and that's why I'm 
now making the check not catch this piece of code?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77461



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


[PATCH] D77794: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 257334.
kbobyrev marked 3 inline comments as done.
kbobyrev added a comment.

Improve CMake machinery and cleanup code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/client/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/client/Client.cpp
  clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  llvm/CMakeLists.txt

Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -1107,3 +1107,8 @@
 if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)
   add_subdirectory(utils/llvm-locstats)
 endif()
+
+# FIXME(kirillbobyrev): Document this in the LLVM docs.
+option(LLVM_USE_GRPC "Use gRPC library to enable remote index support for Clangd" OFF)
+# FIXME(kirillbobyrev): Check if it works with optimized tablegen CMake option.
+set(GRPC_INSTALL_PATH "/usr" CACHE PATH "Path to gRPC library installation.")
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -0,0 +1,103 @@
+//===--- Server.cpp - gRPC-based Remote Index Server  -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/Index.h"
+#include "index/Serialization.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+
+#include "grpcpp/grpcpp.h"
+#include "grpcpp/health_check_service_interface.h"
+
+#include "Index.grpc.pb.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+static const std::string Overview = R"(
+This is an experimental remote index implementation. The server opens Dex and
+awaits gRPC lookup requests from the client.
+)";
+
+llvm::cl::opt IndexPath(llvm::cl::desc("[PATH TO INDEX]"),
+ llvm::cl::Positional, llvm::cl::Required);
+
+llvm::cl::opt ServerAddress("server-address",
+ llvm::cl::init("0.0.0.0:50051"));
+
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*UseIndex=*/true);
+}
+
+class RemoteIndexServer final : public remote::Index::Service {
+public:
+  RemoteIndexServer(std::unique_ptr Index)
+  : Index(std::move(Index)) {}
+
+private:
+  grpc::Status
+  requestLookup(grpc::ServerContext *Context,
+const remote::LookupRequest *Request,
+grpc::ServerWriter *Reply) override {
+llvm::outs() << "Lookup of symbol with ID " << Request->id() << '\n';
+LookupRequest Req;
+auto SID = SymbolID::fromStr(Request->id());
+if (!SID) {
+  llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+  return grpc::Status::CANCELLED;
+}
+Req.IDs.insert(*SID);
+Index->lookup(Req, [&](const Symbol &Sym) {
+  remote::LookupReply NextSymbol;
+  NextSymbol.set_symbol_yaml(toYAML(Sym));
+  Reply->Write(NextSymbol);
+});
+return grpc::Status::OK;
+  }
+
+  std::unique_ptr Index;
+};
+
+void runServer(std::unique_ptr Index,
+   const std::string &ServerAddress) {
+  RemoteIndexServer Service(std::move(Index));
+
+  grpc::EnableDefaultHealthCheckService(true);
+  grpc::ServerBuilder Builder;
+  Builder.AddListeningPort(ServerAddress, grpc::InsecureServerCredentials());
+  Builder.RegisterService(&Service);
+  std::unique_ptr Server(Builder.BuildAndStart());
+  llvm::outs() << "Server listening on " << ServerAddress << '\n';
+
+  Server->Wait();
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
+
+int main(int argc, char *argv[]) {
+  using namespace clang::clangd;
+  llvm::cl::ParseCommandLineOptions(argc, argv, clang::clangd::Overview);
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  std::unique_ptr Index = openIndex(IndexPath);
+
+  if (!Index) {
+llvm::outs() << "Failed to open the index.\n";
+return -1;
+  }
+
+  runServer(std::move(Index), ServerAddress);
+}
Index: clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
===
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_clang_executable(clangd-

[PATCH] D77461: [WIP][clang-tidy] Remove false positive in AvoidNonConstGlobalVariables

2020-04-14 Thread Kim Viggedal via Phabricator via cfe-commits
vingeldal updated this revision to Diff 257335.
vingeldal marked 3 inline comments as done.
vingeldal added a comment.

Moved previously added condition into the actual matcher.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77461

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
@@ -231,7 +231,8 @@
 // CHECKING AGAINST FALSE POSITIVES INSIDE FUNCTION SCOPE /
 int main() {
   for (int i = 0; i < 3; ++i) {
+static int staticNonConstLoopVariable = 42;
 int nonConstLoopVariable = 42;
-nonConstInt = nonConstLoopVariable + i;
+nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
   }
 }
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
@@ -17,11 +17,15 @@
 namespace tidy {
 namespace cppcoreguidelines {
 
+namespace {
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+} // namespace
+
 void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
   auto GlobalVariable = varDecl(
   hasGlobalStorage(),
   unless(anyOf(
-  isConstexpr(), hasType(isConstQualified()),
+  isLocalVarDecl(), isConstexpr(), hasType(isConstQualified()),
   hasType(referenceType(); // References can't be changed, only the
// data they reference can be changed.
 
@@ -45,11 +49,15 @@
 
   if (const auto *Variable =
   Result.Nodes.getNodeAs("non-const_variable")) {
-diag(Variable->getLocation(), "variable %0 is non-const and globally "
-  "accessible, consider making it const")
-<< Variable; // FIXME: Add fix-it hint to Variable
-// Don't return early, a non-const variable may also be a pointer or
-// reference to non-const data.
+// To avoid warning about local variables with global storage, like static
+// variables in a function.
+if (!Variable->isLocalVarDecl()) {
+  diag(Variable->getLocation(), "variable %0 is non-const and globally "
+"accessible, consider making it const")
+  << Variable; // FIXME: Add fix-it hint to Variable
+  // Don't return early, a non-const variable may also be a pointer or
+  // reference to non-const data.
+}
   }
 
   if (const auto *VD =


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
@@ -231,7 +231,8 @@
 // CHECKING AGAINST FALSE POSITIVES INSIDE FUNCTION SCOPE /
 int main() {
   for (int i = 0; i < 3; ++i) {
+static int staticNonConstLoopVariable = 42;
 int nonConstLoopVariable = 42;
-nonConstInt = nonConstLoopVariable + i;
+nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
   }
 }
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
@@ -17,11 +17,15 @@
 namespace tidy {
 namespace cppcoreguidelines {
 
+namespace {
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+} // namespace
+
 void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
   auto GlobalVariable = varDecl(
   hasGlobalStorage(),
   unless(anyOf(
-  isConstexpr(), hasType(isConstQualified()),
+  isLocalVarDecl(), isConstexpr(), hasType(isConstQualified()),
   hasType(referenceType(); // References can't be changed, only the
// data they reference can be changed.
 
@@ -45,11 +49,15 @@
 
   if (const auto *Variable =
   Result.Nodes.getNodeAs("non-const_variable")) {
-   

[PATCH] D75184: [clang-tidy] Optional inheritance of file configs from parent directories 

2020-04-14 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin added a comment.

@alexfh thank you for review!




Comment at: clang-tools-extra/clang-tidy/ClangTidyOptions.h:101-104
+ClangTidyValue(const char *Value) : Value(Value), Priority(0) {}
+ClangTidyValue(const std::string &Value) : Value(Value), Priority(0) {}
+ClangTidyValue(const std::string &Value, unsigned Priority)
+: Value(Value), Priority(Priority) {}

alexfh wrote:
> Maybe just `ClangTidyValue(StringRef Value, unsigned Priority = 0)`?
Reduced number of c-tors to 2 with default value. We need `ClangTidyValue(const 
char *Value)` for supporting lots of constructs like 
`Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";` without changing lots of 
code without good reason.



Comment at: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:41
+  in the parent directory (if any exists) will be taken and current config file
+  will be applied on top of the parent one. If any configuration options have
+  a corresponding command-line option, command-line option takes precedence.

alexfh wrote:
> Does the new logic related to local and global options deserve a separate 
> mention here?
I think adding global vs local here will only add more confusion and general 
statement about precedence still true. As far as I can see there are no 
оreferences to global options in user documentation. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75184



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


[PATCH] D76617: [SveEmitter] Fix encoding/decoding of SVETypeFlags

2020-04-14 Thread Sander de Smalen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf6ea026f179a: [SveEmitter] Fix encoding/decoding of 
SVETypeFlags (authored by sdesmalen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76617

Files:
  clang/include/clang/Basic/TargetBuiltins.h
  clang/include/clang/Basic/arm_sve.td
  clang/utils/TableGen/SveEmitter.cpp

Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -65,9 +65,6 @@
 applyModifier(CharMod);
   }
 
-  /// Return the value in SVETypeFlags for this type.
-  unsigned getTypeFlags() const;
-
   bool isPointer() const { return Pointer; }
   bool isVoidPointer() const { return Pointer && Void; }
   bool isSigned() const { return Signed; }
@@ -138,36 +135,22 @@
   /// The architectural #ifdef guard.
   std::string Guard;
 
+  // The merge suffix such as _m, _x or _z.
+  std::string MergeSuffix;
+
   /// The types of return value [0] and parameters [1..].
   std::vector Types;
 
   /// The "base type", which is VarType('d', BaseTypeSpec).
   SVEType BaseType;
 
-  unsigned Flags;
+  uint64_t Flags;
 
 public:
-  /// The type of predication.
-  enum MergeType {
-MergeNone,
-MergeAny,
-MergeOp1,
-MergeZero,
-MergeAnyExp,
-MergeZeroExp,
-MergeInvalid
-  } Merge;
-
-  Intrinsic(StringRef Name, StringRef Proto, int64_t MT, StringRef LLVMName,
-unsigned Flags, TypeSpec BT, ClassKind Class, SVEEmitter &Emitter,
-StringRef Guard)
-  : Name(Name.str()), LLVMName(LLVMName), Proto(Proto.str()),
-BaseTypeSpec(BT), Class(Class), Guard(Guard.str()), BaseType(BT, 'd'),
-Flags(Flags), Merge(MergeType(MT)) {
-// Types[0] is the return value.
-for (unsigned I = 0; I < Proto.size(); ++I)
-  Types.emplace_back(BaseTypeSpec, Proto[I]);
-  }
+  Intrinsic(StringRef Name, StringRef Proto, uint64_t MergeTy,
+StringRef MergeSuffix, uint64_t MemoryElementTy, StringRef LLVMName,
+uint64_t Flags, TypeSpec BT, ClassKind Class, SVEEmitter &Emitter,
+StringRef Guard);
 
   ~Intrinsic()=default;
 
@@ -179,14 +162,13 @@
 
   StringRef getGuard() const { return Guard; }
   ClassKind getClassKind() const { return Class; }
-  MergeType getMergeType() const { return Merge; }
 
   SVEType getReturnType() const { return Types[0]; }
   ArrayRef getTypes() const { return Types; }
   SVEType getParamType(unsigned I) const { return Types[I + 1]; }
   unsigned getNumParams() const { return Proto.size() - 1; }
 
-  unsigned getFlags() const { return Flags; }
+  uint64_t getFlags() const { return Flags; }
   bool isFlagSet(uint64_t Flag) const { return Flags & Flag;}
 
   /// Return the type string for a BUILTIN() macro in Builtins.def.
@@ -209,7 +191,7 @@
   void emitIntrinsic(raw_ostream &OS) const;
 
 private:
-  std::string getMergeSuffix() const;
+  std::string getMergeSuffix() const { return MergeSuffix; }
   std::string mangleName(ClassKind LocalCK) const;
   std::string replaceTemplatedArgs(std::string Name, TypeSpec TS,
std::string Proto) const;
@@ -221,8 +203,8 @@
   llvm::StringMap EltTypes;
   llvm::StringMap MemEltTypes;
   llvm::StringMap FlagTypes;
+  llvm::StringMap MergeTypes;
 
-  unsigned getTypeFlags(const SVEType &T);
 public:
   SVEEmitter(RecordKeeper &R) : Records(R) {
 for (auto *RV : Records.getAllDerivedDefinitions("EltType"))
@@ -231,8 +213,42 @@
   MemEltTypes[RV->getNameInitAsString()] = RV->getValueAsInt("Value");
 for (auto *RV : Records.getAllDerivedDefinitions("FlagType"))
   FlagTypes[RV->getNameInitAsString()] = RV->getValueAsInt("Value");
+for (auto *RV : Records.getAllDerivedDefinitions("MergeType"))
+  MergeTypes[RV->getNameInitAsString()] = RV->getValueAsInt("Value");
+  }
+
+  // Returns the SVETypeFlags for a given value and mask.
+  uint64_t encodeFlag(uint64_t V, StringRef MaskName) const {
+auto It = FlagTypes.find(MaskName);
+if (It != FlagTypes.end()) {
+  uint64_t Mask = It->getValue();
+  unsigned Shift = llvm::countTrailingZeros(Mask);
+  return (V << Shift) & Mask;
+}
+llvm_unreachable("Unsupported flag");
+  }
+
+  // Returns the SVETypeFlags for the given element type.
+  uint64_t encodeEltType(StringRef EltName) {
+auto It = EltTypes.find(EltName);
+if (It != EltTypes.end())
+  return encodeFlag(It->getValue(), "EltTypeMask");
+llvm_unreachable("Unsupported EltType");
+  }
+
+  // Returns the SVETypeFlags for the given memory element type.
+  uint64_t encodeMemoryElementType(uint64_t MT) {
+return encodeFlag(MT, "MemEltTypeMask");
   }
 
+  // Returns the SVETypeFlags for the given merge type.
+  uint64_t encodeMergeType(uint64_t MT) {
+return encodeFlag(MT, "MergeTypeMask");
+  }
+
+  // 

[PATCH] D75184: [clang-tidy] Optional inheritance of file configs from parent directories 

2020-04-14 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 257336.
DmitryPolukhin marked 6 inline comments as done.
DmitryPolukhin added a comment.

Comments resolved + rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75184

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/docs/clang-tidy/index.rst
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy
  clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -87,7 +87,7 @@
   ExtraArgsBefore: ['arg-before3', 'arg-before4']
   )");
   ASSERT_TRUE(!!Options2);
-  ClangTidyOptions Options = Options1->mergeWith(*Options2);
+  ClangTidyOptions Options = Options1->mergeWith(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ("user2", *Options.User);
Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -7,6 +7,26 @@
 // RUN: clang-tidy -dump-config %S/Inputs/config-files/2/- -- | FileCheck %s -check-prefix=CHECK-CHILD2
 // CHECK-CHILD2: Checks: {{.*}}from-parent
 // CHECK-CHILD2: HeaderFilterRegex: parent
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/3/- -- | FileCheck %s -check-prefix=CHECK-CHILD3
+// CHECK-CHILD3: Checks: {{.*}}from-parent,from-child3
+// CHECK-CHILD3: HeaderFilterRegex: child3
 // RUN: clang-tidy -dump-config -checks='from-command-line' -header-filter='from command line' %S/Inputs/config-files/- -- | FileCheck %s -check-prefix=CHECK-COMMAND-LINE
 // CHECK-COMMAND-LINE: Checks: {{.*}}from-parent,from-command-line
 // CHECK-COMMAND-LINE: HeaderFilterRegex: from command line
+
+// For this test we have to use names of the real checks because otherwise values are ignored.
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-CHILD4
+// CHECK-CHILD4: Checks: {{.*}}modernize-loop-convert,modernize-use-using,llvm-qualified-auto
+// CHECK-CHILD4: - key: llvm-qualified-auto.AddConstToQualified
+// CHECK-CHILD4-NEXT: value: '1
+// CHECK-CHILD4: - key: modernize-loop-convert.MaxCopySize
+// CHECK-CHILD4-NEXT: value: '20'
+// CHECK-CHILD4: - key: modernize-loop-convert.MinConfidence
+// CHECK-CHILD4-NEXT: value: reasonable
+// CHECK-CHILD4: - key: modernize-use-using.IgnoreMacros
+// CHECK-CHILD4-NEXT: value: '0'
+
+// RUN: clang-tidy --explain-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-EXPLAIN
+// CHECK-EXPLAIN: 'llvm-qualified-auto' is enabled in the {{.*}}/Inputs/config-files/4/44/.clang-tidy.
+// CHECK-EXPLAIN: 'modernize-loop-convert' is enabled in the {{.*}}/Inputs/config-files/4/.clang-tidy.
+// CHECK-EXPLAIN: 'modernize-use-using' is enabled in the {{.*}}/Inputs/config-files/4/.clang-tidy.
Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy
@@ -0,0 +1,9 @@
+InheritParentConfig: true
+Checks: 'llvm-qualified-auto'
+CheckOptions:
+  - key: modernize-loop-convert.MaxCopySize
+value:   '20'
+  - key: llvm-qualified-auto.AddConstToQualified
+value:   '1'
+  - key: IgnoreMacros
+value:   '0'
Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy
@@ -0,0 +1,8 @@
+Checks: '-*,modernize-loop-convert,modernize-use-using'
+CheckOptions:
+  - key: modernize-loop-convert.MaxCopySize
+value:   '10'
+  - key: modernize-loop-convert.MinConfidence
+value:   reasonable
+  - key: modernize-use-using.IgnoreMa

[PATCH] D75184: [clang-tidy] Optional inheritance of file configs from parent directories 

2020-04-14 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 257338.
DmitryPolukhin added a comment.

Remove clang-format errors in diff


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75184

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/docs/clang-tidy/index.rst
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy
  clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -87,7 +87,7 @@
   ExtraArgsBefore: ['arg-before3', 'arg-before4']
   )");
   ASSERT_TRUE(!!Options2);
-  ClangTidyOptions Options = Options1->mergeWith(*Options2);
+  ClangTidyOptions Options = Options1->mergeWith(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ("user2", *Options.User);
Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -7,6 +7,26 @@
 // RUN: clang-tidy -dump-config %S/Inputs/config-files/2/- -- | FileCheck %s -check-prefix=CHECK-CHILD2
 // CHECK-CHILD2: Checks: {{.*}}from-parent
 // CHECK-CHILD2: HeaderFilterRegex: parent
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/3/- -- | FileCheck %s -check-prefix=CHECK-CHILD3
+// CHECK-CHILD3: Checks: {{.*}}from-parent,from-child3
+// CHECK-CHILD3: HeaderFilterRegex: child3
 // RUN: clang-tidy -dump-config -checks='from-command-line' -header-filter='from command line' %S/Inputs/config-files/- -- | FileCheck %s -check-prefix=CHECK-COMMAND-LINE
 // CHECK-COMMAND-LINE: Checks: {{.*}}from-parent,from-command-line
 // CHECK-COMMAND-LINE: HeaderFilterRegex: from command line
+
+// For this test we have to use names of the real checks because otherwise values are ignored.
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-CHILD4
+// CHECK-CHILD4: Checks: {{.*}}modernize-loop-convert,modernize-use-using,llvm-qualified-auto
+// CHECK-CHILD4: - key: llvm-qualified-auto.AddConstToQualified
+// CHECK-CHILD4-NEXT: value: '1
+// CHECK-CHILD4: - key: modernize-loop-convert.MaxCopySize
+// CHECK-CHILD4-NEXT: value: '20'
+// CHECK-CHILD4: - key: modernize-loop-convert.MinConfidence
+// CHECK-CHILD4-NEXT: value: reasonable
+// CHECK-CHILD4: - key: modernize-use-using.IgnoreMacros
+// CHECK-CHILD4-NEXT: value: '0'
+
+// RUN: clang-tidy --explain-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-EXPLAIN
+// CHECK-EXPLAIN: 'llvm-qualified-auto' is enabled in the {{.*}}/Inputs/config-files/4/44/.clang-tidy.
+// CHECK-EXPLAIN: 'modernize-loop-convert' is enabled in the {{.*}}/Inputs/config-files/4/.clang-tidy.
+// CHECK-EXPLAIN: 'modernize-use-using' is enabled in the {{.*}}/Inputs/config-files/4/.clang-tidy.
Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy
@@ -0,0 +1,9 @@
+InheritParentConfig: true
+Checks: 'llvm-qualified-auto'
+CheckOptions:
+  - key: modernize-loop-convert.MaxCopySize
+value:   '20'
+  - key: llvm-qualified-auto.AddConstToQualified
+value:   '1'
+  - key: IgnoreMacros
+value:   '0'
Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy
@@ -0,0 +1,8 @@
+Checks: '-*,modernize-loop-convert,modernize-use-using'
+CheckOptions:
+  - key: modernize-loop-convert.MaxCopySize
+value:   '10'
+  - key: modernize-loop-convert.MinConfidence
+value:   reasonable
+  - key: modernize-use-using.IgnoreMacros
+value:   1
Index: clang

[PATCH] D78030: [TimeProfiler] Emit clock synchronization point

2020-04-14 Thread Sergej Jaskiewicz via Phabricator via cfe-commits
broadwaylamb updated this revision to Diff 257340.
broadwaylamb added a comment.

Indent patterns in tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78030

Files:
  clang/test/Driver/check-time-trace-sections.py
  clang/test/Driver/check-time-trace.cpp
  lld/test/ELF/time-trace.s
  llvm/lib/Support/TimeProfiler.cpp

Index: llvm/lib/Support/TimeProfiler.cpp
===
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -252,6 +252,21 @@
 
 J.arrayEnd();
 J.attributeEnd();
+
+// Emit synchronization point, i. e. the absolute time of StartTime.
+// When combining time profiler logs from different processes,
+// this attribute helps preserve relative timing.
+{
+  const auto SystemTime =
+  time_point_cast(system_clock::now());
+  const microseconds ProcessLocalTime =
+  time_point_cast(steady_clock::now()) -
+  time_point_cast(StartTime);
+  const auto BeginningOfTimeUs = SystemTime - ProcessLocalTime;
+  J.attribute("beginningOfTime",
+  BeginningOfTimeUs.time_since_epoch().count());
+}
+
 J.objectEnd();
   }
 
Index: lld/test/ELF/time-trace.s
===
--- lld/test/ELF/time-trace.s
+++ lld/test/ELF/time-trace.s
@@ -18,7 +18,8 @@
 # RUN:   | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 # RUN:   | FileCheck %s
 
-# CHECK: "traceEvents": [
+# CHECK:  "beginningOfTime": {{[0-9]{16},}}
+# CHECK-NEXT: "traceEvents": [
 
 # Check one event has correct fields
 # CHECK:  "dur":
Index: clang/test/Driver/check-time-trace.cpp
===
--- clang/test/Driver/check-time-trace.cpp
+++ clang/test/Driver/check-time-trace.cpp
@@ -3,18 +3,19 @@
 // RUN:   | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
 
-// CHECK: "traceEvents": [
-// CHECK: "args":
-// CHECK: "detail":
-// CHECK: "dur":
-// CHECK: "name":
+// CHECK:  "beginningOfTime": {{[0-9]{16},}}
+// CHECK-NEXT: "traceEvents": [
+// CHECK:  "args":
+// CHECK:  "detail":
+// CHECK:  "dur":
+// CHECK:  "name":
 // CHECK-NEXT: "ph":
 // CHECK-NEXT: "pid":
 // CHECK-NEXT: "tid":
 // CHECK-NEXT: "ts":
-// CHECK: "name": "clang{{.*}}"
-// CHECK: "name": "process_name"
-// CHECK: "name": "thread_name"
+// CHECK:  "name": "clang{{.*}}"
+// CHECK:  "name": "process_name"
+// CHECK:  "name": "thread_name"
 
 template 
 struct Struct {
Index: clang/test/Driver/check-time-trace-sections.py
===
--- clang/test/Driver/check-time-trace-sections.py
+++ clang/test/Driver/check-time-trace-sections.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import json, sys
+import json, sys, time
 
 def is_inside(range1, range2):
 a = range1["ts"]; b = a + range1["dur"]
@@ -11,11 +11,20 @@
 b = range1["ts"] + range1["dur"]; c = range2["ts"]
 return b <= c
 
-events = json.loads(sys.stdin.read())["traceEvents"]
+log_contents = json.loads(sys.stdin.read())
+events = log_contents["traceEvents"]
 codegens = [event for event in events if event["name"] == "CodeGen Function"]
 frontends = [event for event in events if event["name"] == "Frontend"]
 backends = [event for event in events if event["name"] == "Backend"]
 
+beginning_of_time = log_contents["beginningOfTime"] / 100
+seconds_since_epoch = time.time()
+
+# Make sure that the 'beginningOfTime' is not earlier than 10 seconds ago.
+if seconds_since_epoch - beginning_of_time > 10:
+sys.exit("'beginningOfTime' should represent the absolute time when the "
+ "process has started")
+
 if not all([any([is_inside(codegen, frontend) for frontend in frontends])
 for codegen in codegens]):
 sys.exit("Not all CodeGen sections are inside any Frontend section!")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78030: [TimeProfiler] Emit clock synchronization point

2020-04-14 Thread Sergej Jaskiewicz via Phabricator via cfe-commits
broadwaylamb marked an inline comment as done.
broadwaylamb added a comment.

It'd be good if I had one more LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78030



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


[PATCH] D77794: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 257341.
kbobyrev marked 2 inline comments as done.
kbobyrev added a comment.

Give gRPC and Protobuf libraries better names in CMake.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/client/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/client/Client.cpp
  clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  llvm/CMakeLists.txt

Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -1107,3 +1107,8 @@
 if (LLVM_INCLUDE_UTILS AND LLVM_INCLUDE_TOOLS)
   add_subdirectory(utils/llvm-locstats)
 endif()
+
+# FIXME(kirillbobyrev): Document this in the LLVM docs.
+option(LLVM_USE_GRPC "Use gRPC library to enable remote index support for Clangd" OFF)
+# FIXME(kirillbobyrev): Check if it works with optimized tablegen CMake option.
+set(GRPC_INSTALL_PATH "/usr" CACHE PATH "Path to gRPC library installation.")
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -0,0 +1,103 @@
+//===--- Server.cpp - gRPC-based Remote Index Server  -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/Index.h"
+#include "index/Serialization.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+
+#include "grpcpp/grpcpp.h"
+#include "grpcpp/health_check_service_interface.h"
+
+#include "Index.grpc.pb.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+static const std::string Overview = R"(
+This is an experimental remote index implementation. The server opens Dex and
+awaits gRPC lookup requests from the client.
+)";
+
+llvm::cl::opt IndexPath(llvm::cl::desc(""),
+ llvm::cl::Positional, llvm::cl::Required);
+
+llvm::cl::opt ServerAddress("server-address",
+ llvm::cl::init("0.0.0.0:50051"));
+
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*UseIndex=*/true);
+}
+
+class RemoteIndexServer final : public remote::Index::Service {
+public:
+  RemoteIndexServer(std::unique_ptr Index)
+  : Index(std::move(Index)) {}
+
+private:
+  grpc::Status
+  requestLookup(grpc::ServerContext *Context,
+const remote::LookupRequest *Request,
+grpc::ServerWriter *Reply) override {
+llvm::outs() << "Lookup of symbol with ID " << Request->id() << '\n';
+LookupRequest Req;
+auto SID = SymbolID::fromStr(Request->id());
+if (!SID) {
+  llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+  return grpc::Status::CANCELLED;
+}
+Req.IDs.insert(*SID);
+Index->lookup(Req, [&](const Symbol &Sym) {
+  remote::LookupReply NextSymbol;
+  NextSymbol.set_symbol_yaml(toYAML(Sym));
+  Reply->Write(NextSymbol);
+});
+return grpc::Status::OK;
+  }
+
+  std::unique_ptr Index;
+};
+
+void runServer(std::unique_ptr Index,
+   const std::string &ServerAddress) {
+  RemoteIndexServer Service(std::move(Index));
+
+  grpc::EnableDefaultHealthCheckService(true);
+  grpc::ServerBuilder Builder;
+  Builder.AddListeningPort(ServerAddress, grpc::InsecureServerCredentials());
+  Builder.RegisterService(&Service);
+  std::unique_ptr Server(Builder.BuildAndStart());
+  llvm::outs() << "Server listening on " << ServerAddress << '\n';
+
+  Server->Wait();
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
+
+int main(int argc, char *argv[]) {
+  using namespace clang::clangd;
+  llvm::cl::ParseCommandLineOptions(argc, argv, clang::clangd::Overview);
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  std::unique_ptr Index = openIndex(IndexPath);
+
+  if (!Index) {
+llvm::outs() << "Failed to open the index.\n";
+return -1;
+  }
+
+  runServer(std::move(Index), ServerAddress);
+}
Index: clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
===
--- /dev/null
+++ clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_clang_executable(clangd-

[PATCH] D77923: OpenCL: Fix some missing predefined macros

2020-04-14 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

As for OpenCL C spec we should ideally add `__OPENCL_VERSION__` but I feel it 
should be taken from architecture or OS type... I think there were other cases 
where we needed something like an OpenCL runtime version in the triple too but 
I can't remember this now.

I can't think of any use case where this macro would be useful in the kernel 
code though.


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

https://reviews.llvm.org/D77923



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


[PATCH] D77794: [clangd] Pull installed gRPC and introduce clangd-remote-(server|client)

2020-04-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/CMakeLists.txt:19
+add_library(gRPCProtos ${Index_proto_source} ${Index_grpc_header} 
${Index_grpc_source} ${Index_grpc_header})
+target_link_libraries(gRPCProtos gRPC::grpc++ protobuf::libprotobuf)
+

sammccall wrote:
> sorry, what I meant by "less weird names" was can we call these libraries 
> `grpc++` instead of `gRPC::grpc++` and `protobuf` instead of 
> `protobuf::libprotobuf`?
> Those thare the names that the libraries are installed as on my system at 
> least...
I'm afraid those are going to be called differently depending on how they are 
imported. I've changed it to `PROTOBUF_LIBRARY` and `GRPC_LIBRARY`, is that OK?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794



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


[PATCH] D75184: [clang-tidy] Optional inheritance of file configs from parent directories 

2020-04-14 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 257344.
DmitryPolukhin added a comment.

One more try to remove useless lint issues


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75184

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/docs/clang-tidy/index.rst
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy
  clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -87,7 +87,7 @@
   ExtraArgsBefore: ['arg-before3', 'arg-before4']
   )");
   ASSERT_TRUE(!!Options2);
-  ClangTidyOptions Options = Options1->mergeWith(*Options2);
+  ClangTidyOptions Options = Options1->mergeWith(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ("user2", *Options.User);
Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
@@ -7,6 +7,26 @@
 // RUN: clang-tidy -dump-config %S/Inputs/config-files/2/- -- | FileCheck %s -check-prefix=CHECK-CHILD2
 // CHECK-CHILD2: Checks: {{.*}}from-parent
 // CHECK-CHILD2: HeaderFilterRegex: parent
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/3/- -- | FileCheck %s -check-prefix=CHECK-CHILD3
+// CHECK-CHILD3: Checks: {{.*}}from-parent,from-child3
+// CHECK-CHILD3: HeaderFilterRegex: child3
 // RUN: clang-tidy -dump-config -checks='from-command-line' -header-filter='from command line' %S/Inputs/config-files/- -- | FileCheck %s -check-prefix=CHECK-COMMAND-LINE
 // CHECK-COMMAND-LINE: Checks: {{.*}}from-parent,from-command-line
 // CHECK-COMMAND-LINE: HeaderFilterRegex: from command line
+
+// For this test we have to use names of the real checks because otherwise values are ignored.
+// RUN: clang-tidy -dump-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-CHILD4
+// CHECK-CHILD4: Checks: {{.*}}modernize-loop-convert,modernize-use-using,llvm-qualified-auto
+// CHECK-CHILD4: - key: llvm-qualified-auto.AddConstToQualified
+// CHECK-CHILD4-NEXT: value: '1
+// CHECK-CHILD4: - key: modernize-loop-convert.MaxCopySize
+// CHECK-CHILD4-NEXT: value: '20'
+// CHECK-CHILD4: - key: modernize-loop-convert.MinConfidence
+// CHECK-CHILD4-NEXT: value: reasonable
+// CHECK-CHILD4: - key: modernize-use-using.IgnoreMacros
+// CHECK-CHILD4-NEXT: value: '0'
+
+// RUN: clang-tidy --explain-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-EXPLAIN
+// CHECK-EXPLAIN: 'llvm-qualified-auto' is enabled in the {{.*}}/Inputs/config-files/4/44/.clang-tidy.
+// CHECK-EXPLAIN: 'modernize-loop-convert' is enabled in the {{.*}}/Inputs/config-files/4/.clang-tidy.
+// CHECK-EXPLAIN: 'modernize-use-using' is enabled in the {{.*}}/Inputs/config-files/4/.clang-tidy.
Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy
@@ -0,0 +1,9 @@
+InheritParentConfig: true
+Checks: 'llvm-qualified-auto'
+CheckOptions:
+  - key: modernize-loop-convert.MaxCopySize
+value:   '20'
+  - key: llvm-qualified-auto.AddConstToQualified
+value:   '1'
+  - key: IgnoreMacros
+value:   '0'
Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy
@@ -0,0 +1,8 @@
+Checks: '-*,modernize-loop-convert,modernize-use-using'
+CheckOptions:
+  - key: modernize-loop-convert.MaxCopySize
+value:   '10'
+  - key: modernize-loop-convert.MinConfidence
+value:   reasonable
+  - key: modernize-use-using.IgnoreMacros
+value:   1
Inde

[PATCH] D71227: [cuda][hip] Fix function overload resolution in the global initiailizer.

2020-04-14 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 257347.
hliao added a comment.

Rebase to trunk.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71227

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCUDA/function-overload.cu
  clang/test/SemaCUDA/global-initializers-host.cu

Index: clang/test/SemaCUDA/global-initializers-host.cu
===
--- clang/test/SemaCUDA/global-initializers-host.cu
+++ clang/test/SemaCUDA/global-initializers-host.cu
@@ -6,12 +6,14 @@
 // module initializer.
 
 struct S {
+  // expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided}}
+  // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided}}
   __device__ S() {}
-  // expected-note@-1 {{'S' declared here}}
+  // expected-note@-1 {{candidate constructor not viable: call to __device__ function from __host__ function}}
 };
 
 S s;
-// expected-error@-1 {{reference to __device__ function 'S' in global initializer}}
+// expected-error@-1 {{no matching constructor for initialization of 'S'}}
 
 struct T {
   __host__ __device__ T() {}
@@ -19,14 +21,17 @@
 T t;  // No error, this is OK.
 
 struct U {
+  // expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const U' for 1st argument}}
+  // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'U' for 1st argument}}
   __host__ U() {}
+  // expected-note@-1 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
   __device__ U(int) {}
-  // expected-note@-1 {{'U' declared here}}
+  // expected-note@-1 {{candidate constructor not viable: call to __device__ function from __host__ function}}
 };
 U u(42);
-// expected-error@-1 {{reference to __device__ function 'U' in global initializer}}
+// expected-error@-1 {{no matching constructor for initialization of 'U'}}
 
 __device__ int device_fn() { return 42; }
-// expected-note@-1 {{'device_fn' declared here}}
+// expected-note@-1 {{candidate function not viable: call to __device__ function from __host__ function}}
 int n = device_fn();
-// expected-error@-1 {{reference to __device__ function 'device_fn' in global initializer}}
+// expected-error@-1 {{no matching function for call to 'device_fn'}}
Index: clang/test/SemaCUDA/function-overload.cu
===
--- clang/test/SemaCUDA/function-overload.cu
+++ clang/test/SemaCUDA/function-overload.cu
@@ -214,8 +214,10 @@
 // Test for address of overloaded function resolution in the global context.
 HostFnPtr fp_h = h;
 HostFnPtr fp_ch = ch;
+#if !defined(__CUDA_ARCH__)
 CurrentFnPtr fp_dh = dh;
 CurrentFnPtr fp_cdh = cdh;
+#endif
 GlobalFnPtr fp_g = g;
 
 
@@ -419,3 +421,28 @@
 int test_constexpr_overload(C2 &x, C2 &y) {
   return constexpr_overload(x, y);
 }
+
+__device__ float fn(int);
+__host__ float fn(float);
+
+// Overload resolution in the global initialization should follow the same rule
+// as the one in other places. That is, we prefer a callable function over a
+// non-callable function with a better signature match. In this test case, even
+// though the device function has exactly matching with the integer argument,
+// it can't be executed.
+float gvar1 = fn(1);
+
+__device__ float dev_only_fn(int);
+// expected-note@-1 {{candidate function not viable: call to __device__ function from __host__ function}}
+
+float gvar2 = dev_only_fn(1); // expected-error {{no matching function for call to 'dev_only_fn'}}
+
+#ifdef __CUDA_ARCH__
+__device__ DeviceReturnTy gvar3 = template_vs_function(1.f);
+// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
+__device__ int gvar4 = template_overload(1);
+// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, and __shared__ variables.}}
+#else
+TemplateReturnTy gvar3 = template_vs_function(2.f);
+int gvar4 = template_overload(1);
+#endif
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -6302,17 +6302,12 @@
   }
 
   // (CUDA B.1): Check for invalid calls between targets.
-  if (getLangOpts().CUDA)
-if (const FunctionDecl *Caller = dyn_cast(CurContext))
-  // Skip the check for callers that are implicit members, because in this
-  // case we may not yet know what the member's target is; the target is
-  // inferred for the member automatically, based on th

[PATCH] D77461: [WIP][clang-tidy] Remove false positive in AvoidNonConstGlobalVariables

2020-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp:50
+// variables in a function.
+if (!Variable->isLocalVarDecl()) {
+  diag(Variable->getLocation(), "variable %0 is non-const and globally "

aaron.ballman wrote:
> I think this should be handled in the matcher rather than here. I'd add a 
> local matcher for `isLocalVarDecl()` and add it to the `unless()` matcher. 
> WDYT?
You should be able to remove this change now.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp:234-236
+static int staticNonConstLoopVariable = 42;
 int nonConstLoopVariable = 42;
+nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;

vingeldal wrote:
> aaron.ballman wrote:
> > I would like this example moved out of the section suggesting this is a 
> > false positive.
> I don't follow I thought you said this was a false positive and that's why 
> I'm now making the check not catch this piece of code?
I think I just misread the comment as the opposite (false negatives), sorry for 
the noise!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77461



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


  1   2   3   >