[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-19 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!




Comment at: clang/lib/Driver/Types.cpp:303
+  //   Types.def is correct. Everything above this comment will be removed
+  //   in a subsequent NFC commit.a
+  P = Phases;

Spurious `a` at the end of the comment should be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64098



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


[PATCH] D64914: Implement P1771

2019-07-19 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 210753.
erichkeane marked an inline comment as done.
erichkeane added a comment.

Removes pure/const, limits change to just CXX11 spelling, and changes 
docs/FeatureTestMacro.


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

https://reviews.llvm.org/D64914

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
  clang/test/Preprocessor/has_attribute.cpp

Index: clang/test/Preprocessor/has_attribute.cpp
===
--- clang/test/Preprocessor/has_attribute.cpp
+++ clang/test/Preprocessor/has_attribute.cpp
@@ -63,7 +63,7 @@
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
 // WINDOWS: no_unique_address: 0
-// CHECK: nodiscard: 201603L
+// CHECK: nodiscard: 201907L
 // CHECK: noreturn: 200809L
 // FIXME(201803L) CHECK: unlikely: 0
 
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
@@ -61,10 +61,29 @@
 }
 } // namespace PR31526
 
+namespace p1771 {
+  struct S {
+[[nodiscard]] S();
+S(int);
+[[gnu::warn_unused_result]] S(double);
+  };
+
+  struct[[nodiscard]] Y{};
+
+  void usage() {
+S(); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+S(1);
+S(2.2);
+Y(); // expected-warning {{expression result unused}}
+  }
+}; // namespace p1771
+
 #ifdef EXT
 // expected-warning@4 {{use of the 'nodiscard' attribute is a C++17 extension}}
 // expected-warning@8 {{use of the 'nodiscard' attribute is a C++17 extension}}
 // expected-warning@11 {{use of the 'nodiscard' attribute is a C++17 extension}}
 // expected-warning@12 {{use of the 'nodiscard' attribute is a C++17 extension}}
 // expected-warning@28 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@66 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@71 {{use of the 'nodiscard' attribute is a C++17 extension}}
 #endif
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -279,6 +279,13 @@
 return;
   }
 }
+  } else if (const auto *CE = dyn_cast(E)) {
+if (const CXXConstructorDecl *Ctor = CE->getConstructor()) {
+  if (const auto *A = Ctor->getAttr()) {
+Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
+return;
+  }
+}
   } else if (ShouldSuppress)
 return;
 
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2831,7 +2831,8 @@
 
 static void handleWarnUnusedResult(Sema &S, Decl *D, const ParsedAttr &AL) {
   if (D->getFunctionType() &&
-  D->getFunctionType()->getReturnType()->isVoidType()) {
+  D->getFunctionType()->getReturnType()->isVoidType() &&
+  !isa(D)) {
 S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
 return;
   }
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2563,13 +2563,31 @@
   case CXXTemporaryObjectExprClass:
   case CXXConstructExprClass: {
 if (const CXXRecordDecl *Type = getType()->getAsCXXRecordDecl()) {
-  if (Type->hasAttr()) {
+  const auto *WarnURAttr = Type->getAttr();
+  if (Type->hasAttr() ||
+  (WarnURAttr && WarnURAttr->IsCXX11NoDiscard())) {
 WarnE = this;
 Loc = getBeginLoc();
 R1 = getSourceRange();
 return true;
   }
 }
+
+const auto *CE = cast(this);
+if (const CXXConstructorDecl *Ctor = CE->getConstructor()) {
+  const auto *WarnURAttr = Ctor->getAttr();
+  if (WarnURAttr && WarnURAttr->IsCXX11NoDiscard()) {
+WarnE = this;
+Loc = getBeginLoc();
+R1 = getSourceRange();
+
+if (unsigned NumArgs = CE->getNumArgs())
+  R2 = SourceRange(CE->getArg(0)->getBeginLoc(),
+   CE->getArg(NumArgs - 1)->getEndLoc());
+return true;
+  }
+}
+
 return false;
   }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7426,6 +7426,9 @@
 def warn_unused_call : Warning<
   "ignoring return value of function declared with %0 attribute">,
   InGroup;
+def

[clang-tools-extra] r366541 - [clangd] cleanup: unify the implemenation of checking a location is inside main file.

2019-07-19 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Jul 19 01:33:39 2019
New Revision: 366541

URL: http://llvm.org/viewvc/llvm-project?rev=366541&view=rev
Log:
[clangd] cleanup: unify the implemenation of checking a location is inside main 
file.

Summary: We have variant implementations in the codebase, this patch unifies 
them.

Reviewers: ilya-biryukov, kadircet

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/clangd/Headers.cpp
clang-tools-extra/trunk/clangd/IncludeFixer.cpp
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/refactor/Rename.cpp
clang-tools-extra/trunk/clangd/unittests/SourceCodeTests.cpp
clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=366541&r1=366540&r2=366541&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Fri Jul 19 01:33:39 2019
@@ -68,7 +68,7 @@ public:
   bool HandleTopLevelDecl(DeclGroupRef DG) override {
 for (Decl *D : DG) {
   auto &SM = D->getASTContext().getSourceManager();
-  if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation(
+  if (!isInsideMainFile(D->getLocation(), SM))
 continue;
 
   // ObjCMethodDecl are not actually top-level decls.
@@ -355,8 +355,7 @@ ParsedAST::build(std::unique_ptrhttp://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=366541&r1=366540&r2=366541&view=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Fri Jul 19 01:33:39 2019
@@ -140,15 +140,11 @@ void adjustDiagFromHeader(Diag &D, const
   D.Message = llvm::Twine("in included file: ", D.Message).str();
 }
 
-bool isInsideMainFile(const SourceLocation Loc, const SourceManager &M) {
-  return Loc.isValid() && M.isWrittenInMainFile(M.getFileLoc(Loc));
-}
-
 bool isInsideMainFile(const clang::Diagnostic &D) {
   if (!D.hasSourceManager())
 return false;
 
-  return isInsideMainFile(D.getLocation(), D.getSourceManager());
+  return clangd::isInsideMainFile(D.getLocation(), D.getSourceManager());
 }
 
 bool isNote(DiagnosticsEngine::Level L) {

Modified: clang-tools-extra/trunk/clangd/Headers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.cpp?rev=366541&r1=366540&r2=366541&view=diff
==
--- clang-tools-extra/trunk/clangd/Headers.cpp (original)
+++ clang-tools-extra/trunk/clangd/Headers.cpp Fri Jul 19 01:33:39 2019
@@ -35,7 +35,7 @@ public:
   llvm::StringRef /*RelativePath*/,
   const Module * /*Imported*/,
   SrcMgr::CharacteristicKind FileKind) override {
-if (SM.isWrittenInMainFile(HashLoc)) {
+if (isInsideMainFile(HashLoc, SM)) {
   Out->MainFileIncludes.emplace_back();
   auto &Inc = Out->MainFileIncludes.back();
   Inc.R = halfOpenToRange(SM, FilenameRange);

Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=366541&r1=366540&r2=366541&view=diff
==
--- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Fri Jul 19 01:33:39 2019
@@ -318,7 +318,7 @@ public:
 assert(SemaPtr && "Sema must have been set.");
 if (SemaPtr->isSFINAEContext())
   return TypoCorrection();
-if (!SemaPtr->SourceMgr.isWrittenInMainFile(Typo.getLoc()))
+if (!isInsideMainFile(Typo.getLoc(), SemaPtr->SourceMgr))
   return clang::TypoCorrection();
 
 // This is not done lazily because `SS` can get out of scope and it's

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=366541&r1=366540&r2=366541&view=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Fri Jul 19 01:33:39 2019
@@ -9,6 +9,7 @@
 #include "Quality.h"
 #include "AST.h"
 #include "FileDistance.h"
+#include "SourceCode.h"
 #

[PATCH] D64915: [clangd] cleanup: unify the implemenation of checking a location is inside main file.

2019-07-19 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366541: [clangd] cleanup: unify the implemenation of 
checking a location is inside main… (authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64915?vs=210569&id=210769#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64915

Files:
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/clangd/Diagnostics.cpp
  clang-tools-extra/trunk/clangd/Headers.cpp
  clang-tools-extra/trunk/clangd/IncludeFixer.cpp
  clang-tools-extra/trunk/clangd/Quality.cpp
  clang-tools-extra/trunk/clangd/SourceCode.cpp
  clang-tools-extra/trunk/clangd/SourceCode.h
  clang-tools-extra/trunk/clangd/XRefs.cpp
  clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
  clang-tools-extra/trunk/clangd/refactor/Rename.cpp
  clang-tools-extra/trunk/clangd/unittests/SourceCodeTests.cpp
  clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp

Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -68,7 +68,7 @@
   bool HandleTopLevelDecl(DeclGroupRef DG) override {
 for (Decl *D : DG) {
   auto &SM = D->getASTContext().getSourceManager();
-  if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation(
+  if (!isInsideMainFile(D->getLocation(), SM))
 continue;
 
   // ObjCMethodDecl are not actually top-level decls.
@@ -355,8 +355,7 @@
   // those might take us into a preamble file as well.
   bool IsInsideMainFile =
   Info.hasSourceManager() &&
-  Info.getSourceManager().isWrittenInMainFile(
-  Info.getSourceManager().getFileLoc(Info.getLocation()));
+  isInsideMainFile(Info.getLocation(), Info.getSourceManager());
   if (IsInsideMainFile && tidy::ShouldSuppressDiagnostic(
   DiagLevel, Info, *CTContext,
   /* CheckMacroExpansion = */ false)) {
Index: clang-tools-extra/trunk/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/trunk/clangd/IncludeFixer.cpp
+++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp
@@ -318,7 +318,7 @@
 assert(SemaPtr && "Sema must have been set.");
 if (SemaPtr->isSFINAEContext())
   return TypoCorrection();
-if (!SemaPtr->SourceMgr.isWrittenInMainFile(Typo.getLoc()))
+if (!isInsideMainFile(Typo.getLoc(), SemaPtr->SourceMgr))
   return clang::TypoCorrection();
 
 // This is not done lazily because `SS` can get out of scope and it's
Index: clang-tools-extra/trunk/clangd/Diagnostics.cpp
===
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp
@@ -140,15 +140,11 @@
   D.Message = llvm::Twine("in included file: ", D.Message).str();
 }
 
-bool isInsideMainFile(const SourceLocation Loc, const SourceManager &M) {
-  return Loc.isValid() && M.isWrittenInMainFile(M.getFileLoc(Loc));
-}
-
 bool isInsideMainFile(const clang::Diagnostic &D) {
   if (!D.hasSourceManager())
 return false;
 
-  return isInsideMainFile(D.getLocation(), D.getSourceManager());
+  return clangd::isInsideMainFile(D.getLocation(), D.getSourceManager());
 }
 
 bool isNote(DiagnosticsEngine::Level L) {
Index: clang-tools-extra/trunk/clangd/SourceCode.cpp
===
--- clang-tools-extra/trunk/clangd/SourceCode.cpp
+++ clang-tools-extra/trunk/clangd/SourceCode.cpp
@@ -328,6 +328,10 @@
   return FileRange;
 }
 
+bool isInsideMainFile(SourceLocation Loc, const SourceManager &SM) {
+  return Loc.isValid() && SM.isWrittenInMainFile(SM.getExpansionLoc(Loc));
+}
+
 llvm::Optional toHalfOpenFileRange(const SourceManager &SM,
 const LangOptions &LangOpts,
 SourceRange R) {
Index: clang-tools-extra/trunk/clangd/XRefs.cpp
===
--- clang-tools-extra/trunk/clangd/XRefs.cpp
+++ clang-tools-extra/trunk/clangd/XRefs.cpp
@@ -406,7 +406,7 @@
 assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
 const SourceManager &SM = AST.getSourceManager();
 Loc = SM.getFileLoc(Loc);
-if (SM.isWrittenInMainFile(Loc) && CanonicalTargets.count(D))
+if (isInsideMainFile(Loc, SM) && CanonicalTargets.count(D))
   References.push_back({D, Loc, Roles});
 return true;
   }
Index: clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp

[PATCH] D64416: [AArch64] Add support for Transactional Memory Extension (TME)

2019-07-19 Thread Momchil Velikov via Phabricator via cfe-commits
chill updated this revision to Diff 210768.
chill added a comment.
This revision is now accepted and ready to land.

Changed `tcancel` implementation.


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

https://reviews.llvm.org/D64416

Files:
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Headers/arm_acle.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/aarch64-tme-tcancel-arg.cpp
  clang/test/CodeGen/aarch64-tme.c
  clang/test/Sema/aarch64-tme-errors.c
  clang/test/Sema/aarch64-tme-tcancel-const-error.c
  clang/test/Sema/aarch64-tme-tcancel-range-error.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/test/CodeGen/AArch64/tme-tcancel.ll
  llvm/test/CodeGen/AArch64/tme-tcommit.ll
  llvm/test/CodeGen/AArch64/tme-tstart.ll
  llvm/test/CodeGen/AArch64/tme-ttest.ll
  llvm/test/MC/AArch64/tme-error.s
  llvm/test/MC/AArch64/tme.s
  llvm/test/MC/Disassembler/AArch64/tme.txt
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1119,6 +1119,7 @@
   {"rcpc", "norcpc", "+rcpc", "-rcpc" },
   {"rng", "norng", "+rand", "-rand"},
   {"memtag", "nomemtag", "+mte", "-mte"},
+  {"tme", "notme", "+tme", "-tme"},
   {"ssbs", "nossbs", "+ssbs", "-ssbs"},
   {"sb", "nosb", "+sb", "-sb"},
   {"predres", "nopredres", "+predres", "-predres"}
Index: llvm/test/MC/Disassembler/AArch64/tme.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/AArch64/tme.txt
@@ -0,0 +1,19 @@
+# Tests for transaction memory extension instructions
+# RUN: llvm-mc -triple=aarch64 -mattr=+tme   -disassemble < %s  | FileCheck %s
+# RUN: not llvm-mc -triple=aarch64 -mattr=-tme   -disassemble < %s 2>&1 | FileCheck %s --check-prefix=NOTME
+
+[0x63,0x30,0x23,0xd5]
+[0x64,0x31,0x23,0xd5]
+[0x7f,0x30,0x03,0xd5]
+[0x80,0x46,0x62,0xd4]
+
+# CHECK: tstart x3
+# CHECK: ttest  x4
+# CHECK: tcommit
+# CHECK: tcancel #0x1234
+
+# NOTEME: mrs
+# NOTEME-NEXT: mrs
+# NOTEME-NEXT: msr
+# NOTME:  warning: invalid instruction encoding
+# NOTME-NEXT: [0x80,0x46,0x62,0xd4]
Index: llvm/test/MC/AArch64/tme.s
===
--- /dev/null
+++ llvm/test/MC/AArch64/tme.s
@@ -0,0 +1,24 @@
+// Tests for transaction memory extension instructions
+//
+// RUN: llvm-mc -triple aarch64 -show-encoding -mattr=+tme   < %s  | FileCheck %s
+// RUN: not llvm-mc -triple aarch64 -show-encoding -mattr=-tme   < %s 2>&1 | FileCheck %s --check-prefix=NOTME
+
+tstart x3
+ttest  x4
+tcommit
+tcancel #0x1234
+
+// CHECK: tstart x3 // encoding: [0x63,0x30,0x23,0xd5]
+// CHECK: ttest x4  // encoding: [0x64,0x31,0x23,0xd5]
+// CHECK: tcommit   // encoding: [0x7f,0x30,0x03,0xd5]
+// CHECK: tcancel #0x1234   // encoding: [0x80,0x46,0x62,0xd4]
+
+
+// NOTME: instruction requires: tme
+// NOTME-NEXT: tstart x3
+// NOTME: instruction requires: tme
+// NOTME-NEXT: ttest  x4
+// NOTME: instruction requires: tme
+// NOTME-NEXT: tcommit
+// NOTME: instruction requires: tme
+// NOTME-NEXT: tcancel #0x1234
Index: llvm/test/MC/AArch64/tme-error.s
===
--- /dev/null
+++ llvm/test/MC/AArch64/tme-error.s
@@ -0,0 +1,47 @@
+// Tests for transactional memory extension instructions
+// RUN: not llvm-mc -triple aarch64 -show-encoding -mattr=+tme < %s 2>&1   | FileCheck %s
+
+tstart
+// CHECK: error: too few operands for instruction
+// CHECK-NEXT: tstart
+tstart  x4, x5
+// CHECK: error: invalid operand for instruction
+// CHECK-NEXT: tstart x4, x5
+tstart  x4, #1
+// CHECK: error: invalid operand for instruction
+// CHECK-NEXT: tstart x4, #1
+tstart  sp
+// CHECK: error: invalid operand for instruction
+// CHECK-NEXT: tstart sp
+
+ttest
+// CHECK: error: too few operands for instruction
+// CHECK-NEXT: ttest
+ttest  x4, x5
+// CHECK: error: invalid operand for instruction
+// CHECK-NEXT: ttest x4, x5
+ttest  x4, #1
+// CHECK: error: invalid operand for instruction
+// CHECK-NEXT: ttest x4, #1
+ttest  sp
+// CHECK: error: invalid operand for instruction
+// CHECK-NEXT: ttest sp
+
+tcommit  x4
+// CHECK: error: invalid operand for instruction
+// CHECK-NEXT: tcommit x4
+tcommit  sp
+// CHECK: error: invalid operand for ins

[PATCH] D64222: [sanitizers] Use covering ObjectFormatType switches

2019-07-19 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366544: [sanitizers] Use covering ObjectFormatType switches 
(authored by hubert.reinterpretcast, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D64222?vs=208085&id=210772#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64222

Files:
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp


Index: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1919,7 +1919,12 @@
   case Triple::COFF:  return ".ASAN$GL";
   case Triple::ELF:   return "asan_globals";
   case Triple::MachO: return "__DATA,__asan_globals,regular";
-  default: break;
+  case Triple::Wasm:
+  case Triple::XCOFF:
+report_fatal_error(
+"ModuleAddressSanitizer not implemented for object file format.");
+  case Triple::UnknownObjectFormat:
+break;
   }
   llvm_unreachable("unsupported object format");
 }
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -231,9 +231,13 @@
 return true;
   case Triple::ELF:
 return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
-  default:
-return false;
+  case Triple::XCOFF:
+llvm::report_fatal_error("ASan not implemented for XCOFF.");
+  case Triple::Wasm:
+  case Triple::UnknownObjectFormat:
+break;
   }
+  return false;
 }
 
 static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,


Index: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1919,7 +1919,12 @@
   case Triple::COFF:  return ".ASAN$GL";
   case Triple::ELF:   return "asan_globals";
   case Triple::MachO: return "__DATA,__asan_globals,regular";
-  default: break;
+  case Triple::Wasm:
+  case Triple::XCOFF:
+report_fatal_error(
+"ModuleAddressSanitizer not implemented for object file format.");
+  case Triple::UnknownObjectFormat:
+break;
   }
   llvm_unreachable("unsupported object format");
 }
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -231,9 +231,13 @@
 return true;
   case Triple::ELF:
 return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
-  default:
-return false;
+  case Triple::XCOFF:
+llvm::report_fatal_error("ASan not implemented for XCOFF.");
+  case Triple::Wasm:
+  case Triple::UnknownObjectFormat:
+break;
   }
+  return false;
 }
 
 static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r366544 - [sanitizers] Use covering ObjectFormatType switches

2019-07-19 Thread Hubert Tong via cfe-commits
Author: hubert.reinterpretcast
Date: Fri Jul 19 01:46:18 2019
New Revision: 366544

URL: http://llvm.org/viewvc/llvm-project?rev=366544&view=rev
Log:
[sanitizers] Use covering ObjectFormatType switches

Summary:
This patch removes the `default` case from some switches on
`llvm::Triple::ObjectFormatType`, and cases for the missing enumerators
(`UnknownObjectFormat`, `Wasm`, and `XCOFF`) are then added.

For `UnknownObjectFormat`, the effect of the action for the `default`
case is maintained; otherwise, where `llvm_unreachable` is called,
`report_fatal_error` is used instead.

Where the `default` case returns a default value, `report_fatal_error`
is used for XCOFF as a placeholder. For `Wasm`, the effect of the action
for the `default` case in maintained.

The code is structured to avoid strongly implying that the `Wasm` case
is present for any reason other than to make the switch cover all
`ObjectFormatType` enumerator values.

Reviewers: sfertile, jasonliu, daltenty

Reviewed By: sfertile

Subscribers: hiraditya, aheejin, sunfish, llvm-commits, cfe-commits

Tags: #clang, #llvm

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

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=366544&r1=366543&r2=366544&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Fri Jul 19 01:46:18 2019
@@ -231,9 +231,13 @@ static bool asanUseGlobalsGC(const Tripl
 return true;
   case Triple::ELF:
 return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
-  default:
-return false;
+  case Triple::XCOFF:
+llvm::report_fatal_error("ASan not implemented for XCOFF.");
+  case Triple::Wasm:
+  case Triple::UnknownObjectFormat:
+break;
   }
+  return false;
 }
 
 static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,


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


[PATCH] D64329: [Clangd] Fixed SelectionTree bug for macros

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

Just doc nits I think.

This eliminates a semi-fast path (that uses approximate token matching to avoid 
running the lexer in claimRange sometimes) but I think we can live without it.




Comment at: clang-tools-extra/clangd/Selection.cpp:242
   // This is usually called from pop(), so we can take children into account.
+  // FIXME: Doesn't select the binary operator node in
+  //  #define FOO(X) X + 1

I'm not sure why the FIXME is on this function, it can't be fixed here.

If you're not sure where to put it, I'd suggest putting the FIXME on the unit 
test that shows the wrong behavior.



Comment at: clang-tools-extra/clangd/Selection.cpp:261
   return SelectionTree::Unselected;
 // Cheap test: is there any overlap at all between the selection and range?
+if (B.second >= SelEnd || E.second < SelBegin)

The rest of this function talks about cheap vs precise checks etc - you've 
removed the cheap path (which is OK to improve correctness, I think), so the 
comments need to be rewritten


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64329



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


[PATCH] D64980: [clangd][BackgroundIndexLoader] Directly store DependentTU while loading shard

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

We were deferring the population of DependentTU field in LoadedShard
until BackgroundIndexLoader was consumed. This actually triggers a use after
free since the shards FileToTU was pointing at could've been moved while
consuming the Loader.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64980

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


Index: clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
===
--- clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
+++ clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
@@ -51,19 +51,16 @@
   /// Storage. Also returns paths for dependencies of \p StartSourceFile if it
   /// wasn't cached yet.
   std::pair>
-  loadShard(PathRef StartSourceFile);
+  loadShard(PathRef StartSourceFile, PathRef DependentTU);
 
   /// Cache for Storage lookups.
   llvm::StringMap LoadedShards;
 
-  /// References are into the AbsolutePaths in LoadedShards.
-  llvm::DenseMap FileToTU;
-
   BackgroundIndexStorage::Factory &IndexStorageFactory;
 };
 
 std::pair>
-BackgroundIndexLoader::loadShard(PathRef StartSourceFile) {
+BackgroundIndexLoader::loadShard(PathRef StartSourceFile, PathRef DependentTU) 
{
   auto It = LoadedShards.try_emplace(StartSourceFile);
   LoadedShard &LS = It.first->getValue();
   std::vector Edges = {};
@@ -72,6 +69,7 @@
 return {LS, Edges};
 
   LS.AbsolutePath = StartSourceFile.str();
+  LS.DependentTU = DependentTU;
   BackgroundIndexStorage *Storage = IndexStorageFactory(LS.AbsolutePath);
   auto Shard = Storage->loadShard(StartSourceFile);
   if (!Shard || !Shard->Sources) {
@@ -111,8 +109,7 @@
 PathRef SourceFile = ToVisit.front();
 ToVisit.pop();
 
-auto ShardAndEdges = loadShard(SourceFile);
-FileToTU[ShardAndEdges.first.AbsolutePath] = MainFile;
+auto ShardAndEdges = loadShard(SourceFile, MainFile);
 for (PathRef Edge : ShardAndEdges.second) {
   auto It = InQueue.insert(Edge);
   if (It.second)
@@ -124,13 +121,8 @@
 std::vector BackgroundIndexLoader::takeResult() && {
   std::vector Result;
   Result.reserve(LoadedShards.size());
-  for (auto &It : LoadedShards) {
+  for (auto &It : LoadedShards)
 Result.push_back(std::move(It.getValue()));
-LoadedShard &LS = Result.back();
-auto TUsIt = FileToTU.find(LS.AbsolutePath);
-assert(TUsIt != FileToTU.end() && "No TU registered for the shard");
-Result.back().DependentTU = TUsIt->second;
-  }
   return Result;
 }
 } // namespace


Index: clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
===
--- clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
+++ clang-tools-extra/clangd/index/BackgroundIndexLoader.cpp
@@ -51,19 +51,16 @@
   /// Storage. Also returns paths for dependencies of \p StartSourceFile if it
   /// wasn't cached yet.
   std::pair>
-  loadShard(PathRef StartSourceFile);
+  loadShard(PathRef StartSourceFile, PathRef DependentTU);
 
   /// Cache for Storage lookups.
   llvm::StringMap LoadedShards;
 
-  /// References are into the AbsolutePaths in LoadedShards.
-  llvm::DenseMap FileToTU;
-
   BackgroundIndexStorage::Factory &IndexStorageFactory;
 };
 
 std::pair>
-BackgroundIndexLoader::loadShard(PathRef StartSourceFile) {
+BackgroundIndexLoader::loadShard(PathRef StartSourceFile, PathRef DependentTU) {
   auto It = LoadedShards.try_emplace(StartSourceFile);
   LoadedShard &LS = It.first->getValue();
   std::vector Edges = {};
@@ -72,6 +69,7 @@
 return {LS, Edges};
 
   LS.AbsolutePath = StartSourceFile.str();
+  LS.DependentTU = DependentTU;
   BackgroundIndexStorage *Storage = IndexStorageFactory(LS.AbsolutePath);
   auto Shard = Storage->loadShard(StartSourceFile);
   if (!Shard || !Shard->Sources) {
@@ -111,8 +109,7 @@
 PathRef SourceFile = ToVisit.front();
 ToVisit.pop();
 
-auto ShardAndEdges = loadShard(SourceFile);
-FileToTU[ShardAndEdges.first.AbsolutePath] = MainFile;
+auto ShardAndEdges = loadShard(SourceFile, MainFile);
 for (PathRef Edge : ShardAndEdges.second) {
   auto It = InQueue.insert(Edge);
   if (It.second)
@@ -124,13 +121,8 @@
 std::vector BackgroundIndexLoader::takeResult() && {
   std::vector Result;
   Result.reserve(LoadedShards.size());
-  for (auto &It : LoadedShards) {
+  for (auto &It : LoadedShards)
 Result.push_back(std::move(It.getValue()));
-LoadedShard &LS = Result.back();
-auto TUsIt = FileToTU.find(LS.AbsolutePath);
-assert(TUsIt != FileToTU.end() && "No TU registered for the shard");
-Result.back().DependentTU = TUsIt->second;
-  }
   return Result;
 }
 } // namespace
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.ll

[PATCH] D64744: #pragma clang loop vectorize_predicate(enable|disable)

2019-07-19 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer updated this revision to Diff 210774.
SjoerdMeijer retitled this revision from " #pragma clang loop 
predicate(enable|disable)" to " #pragma clang loop 
vectorize_predicate(enable|disable)".
SjoerdMeijer edited the summary of this revision.
SjoerdMeijer added a comment.

Hi Michael, thanks for taking a look again!

Completely agree what you suggested, so I've change the pragma to 
`vectorize_predicate(enable) ` and the metadata to 
`llvm.loop.vectorize.predicate`.

My little plan is as follows:

- Finish D64916 : thanks for reviewing that 
too!
- I will follow up on that. I have a local patch that I need to finish that 
shows how all moving parts work together. I.e., it picks up the metadata, and 
enables the folding.
- Finally, I was thinking to follow up with a doc patch. I don't want to 
advertise this just yet, but want to get everything in, and then add it to the 
docs.

Does that sound like an idea?


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

https://reviews.llvm.org/D64744

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/CodeGen/CGLoopInfo.cpp
  clang/lib/CodeGen/CGLoopInfo.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/AST/ast-print-pragmas.cpp
  clang/test/CodeGenCXX/pragma-loop.cpp
  clang/test/Parser/pragma-loop.cpp
  clang/test/Parser/pragma-unroll-and-jam.cpp

Index: clang/test/Parser/pragma-unroll-and-jam.cpp
===
--- clang/test/Parser/pragma-unroll-and-jam.cpp
+++ clang/test/Parser/pragma-unroll-and-jam.cpp
@@ -67,7 +67,7 @@
   }
 
 // pragma clang unroll_and_jam is disabled for the moment
-/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, or distribute}} */ #pragma clang loop unroll_and_jam(4)
+/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, or distribute}} */ #pragma clang loop unroll_and_jam(4)
   for (int i = 0; i < Length; i++) {
 for (int j = 0; j < Length; j++) {
   List[i * Length + j] = Value;
Index: clang/test/Parser/pragma-loop.cpp
===
--- clang/test/Parser/pragma-loop.cpp
+++ clang/test/Parser/pragma-loop.cpp
@@ -81,6 +81,7 @@
 
 #pragma clang loop vectorize(enable)
 #pragma clang loop interleave(enable)
+#pragma clang loop vectorize_predicate(enable)
 #pragma clang loop unroll(full)
   while (i + 1 < Length) {
 List[i] = i;
@@ -95,6 +96,7 @@
 
 #pragma clang loop vectorize(disable)
 #pragma clang loop interleave(disable)
+#pragma clang loop vectorize_predicate(disable)
 #pragma clang loop unroll(disable)
   while (i - 1 < Length) {
 List[i] = i;
@@ -111,7 +113,7 @@
   }
 
   int VList[Length];
-#pragma clang loop vectorize(disable) interleave(disable) unroll(disable)
+#pragma clang loop vectorize(disable) interleave(disable) unroll(disable) vectorize_predicate(disable)
   for (int j : VList) {
 VList[j] = List[j];
   }
@@ -130,11 +132,13 @@
 
 /* expected-error {{expected '('}} */ #pragma clang loop vectorize
 /* expected-error {{expected '('}} */ #pragma clang loop interleave
+/* expected-error {{expected '('}} */ #pragma clang loop vectorize_predicate
 /* expected-error {{expected '('}} */ #pragma clang loop unroll
 /* expected-error {{expected '('}} */ #pragma clang loop distribute
 
 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(enable
 /* expected-error {{expected ')'}} */ #pragma clang loop interleave(enable
+/* expected-error {{expected ')'}} */ #pragma clang loop vectorize_predicate(enable
 /* expected-error {{expected ')'}} */ #pragma clang loop unroll(full
 /* expected-error {{expected ')'}} */ #pragma clang loop distribute(enable
 
@@ -147,7 +151,7 @@
 /* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll()
 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute()
 
-/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, or distribute}} */ #pragma clang loop
+/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, or distribute}} */ #pragma clang loop
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable)
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword

[clang-tools-extra] r366545 - [clangd] Handle windows line endings in QueryDriver

2019-07-19 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Jul 19 02:08:22 2019
New Revision: 366545

URL: http://llvm.org/viewvc/llvm-project?rev=366545&view=rev
Log:
[clangd] Handle windows line endings in QueryDriver

Summary:
The previous patch did not fix the end mark. D64789
fixes second case of https://github.com/clangd/clangd/issues/93

Patch by @lh123 !

Reviewers: sammccall, kadircet

Reviewed By: kadircet

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

Tags: #clang-tools-extra, #clang

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

Modified:
clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
clang-tools-extra/trunk/clangd/test/system-include-extractor.test

Modified: clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp?rev=366545&r1=366544&r2=366545&view=diff
==
--- clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp Fri Jul 19 02:08:22 
2019
@@ -59,7 +59,7 @@ namespace {
 std::vector parseDriverOutput(llvm::StringRef Output) {
   std::vector SystemIncludes;
   const char SIS[] = "#include <...> search starts here:";
-  constexpr char const *SIE = "End of search list.";
+  const char SIE[] = "End of search list.";
   llvm::SmallVector Lines;
   Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
@@ -70,7 +70,9 @@ std::vector parseDriverOutp
 return {};
   }
   ++StartIt;
-  const auto EndIt = std::find(StartIt, Lines.end(), SIE);
+  const auto EndIt =
+  llvm::find_if(llvm::make_range(StartIt, Lines.end()),
+[SIE](llvm::StringRef Line) { return Line.trim() == SIE; 
});
   if (EndIt == Lines.end()) {
 elog("System include extraction: end marker missing: {0}", Output);
 return {};

Modified: clang-tools-extra/trunk/clangd/test/system-include-extractor.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/system-include-extractor.test?rev=366545&r1=366544&r2=366545&view=diff
==
--- clang-tools-extra/trunk/clangd/test/system-include-extractor.test (original)
+++ clang-tools-extra/trunk/clangd/test/system-include-extractor.test Fri Jul 
19 02:08:22 2019
@@ -8,7 +8,7 @@
 # RUN: echo 'echo -e "#include <...> search starts here:\r" >&2' >> 
%t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo -e "End of search list.\r" >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h


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


r366546 - [OpenCL] Define CLK_NULL_EVENT without cast

2019-07-19 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Fri Jul 19 02:11:48 2019
New Revision: 366546

URL: http://llvm.org/viewvc/llvm-project?rev=366546&view=rev
Log:
[OpenCL] Define CLK_NULL_EVENT without cast

Defining CLK_NULL_EVENT with a `(void*)` cast has the (unintended?)
side-effect that the address space will be fixed (as generic in OpenCL
2.0 mode).  The consequence is that any target specific address space
for the clk_event_t type will not be applied.

It is not clear why the void pointer cast was needed in the first
place, and it seems we can do without it.

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

Modified:
cfe/trunk/lib/Headers/opencl-c-base.h
cfe/trunk/test/SemaOpenCL/clk_event_t.cl

Modified: cfe/trunk/lib/Headers/opencl-c-base.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c-base.h?rev=366546&r1=366545&r2=366546&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c-base.h (original)
+++ cfe/trunk/lib/Headers/opencl-c-base.h Fri Jul 19 02:11:48 2019
@@ -413,7 +413,7 @@ typedef enum memory_order
 #define CLK_OUT_OF_RESOURCES-5
 
 #define CLK_NULL_QUEUE  0
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 // execution model related definitions
 #define CLK_ENQUEUE_FLAGS_NO_WAIT   0x0

Modified: cfe/trunk/test/SemaOpenCL/clk_event_t.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/clk_event_t.cl?rev=366546&r1=366545&r2=366546&view=diff
==
--- cfe/trunk/test/SemaOpenCL/clk_event_t.cl (original)
+++ cfe/trunk/test/SemaOpenCL/clk_event_t.cl Fri Jul 19 02:11:48 2019
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 global clk_event_t ce; // expected-error {{the '__global clk_event_t' type 
cannot be used to declare a program scope variable}}
 
@@ -10,6 +10,7 @@ int clk_event_tests() {
   event_t e;
   clk_event_t ce1;
   clk_event_t ce2;
+  clk_event_t ce3 = CLK_NULL_EVENT;
 
   if (e == ce1) { // expected-error {{invalid operands to binary expression 
('event_t' and 'clk_event_t')}}
 return 9;


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


[PATCH] D64970: [clangd] Handle windows line endings in QueryDriver

2019-07-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366545: [clangd] Handle windows line endings in QueryDriver 
(authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64970?vs=210737&id=210777#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64970

Files:
  clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/trunk/clangd/test/system-include-extractor.test


Index: clang-tools-extra/trunk/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/trunk/clangd/test/system-include-extractor.test
+++ clang-tools-extra/trunk/clangd/test/system-include-extractor.test
@@ -8,7 +8,7 @@
 # RUN: echo 'echo -e "#include <...> search starts here:\r" >&2' >> 
%t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo -e "End of search list.\r" >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h
Index: clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
@@ -59,7 +59,7 @@
 std::vector parseDriverOutput(llvm::StringRef Output) {
   std::vector SystemIncludes;
   const char SIS[] = "#include <...> search starts here:";
-  constexpr char const *SIE = "End of search list.";
+  const char SIE[] = "End of search list.";
   llvm::SmallVector Lines;
   Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
@@ -70,7 +70,9 @@
 return {};
   }
   ++StartIt;
-  const auto EndIt = std::find(StartIt, Lines.end(), SIE);
+  const auto EndIt =
+  llvm::find_if(llvm::make_range(StartIt, Lines.end()),
+[SIE](llvm::StringRef Line) { return Line.trim() == SIE; 
});
   if (EndIt == Lines.end()) {
 elog("System include extraction: end marker missing: {0}", Output);
 return {};


Index: clang-tools-extra/trunk/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/trunk/clangd/test/system-include-extractor.test
+++ clang-tools-extra/trunk/clangd/test/system-include-extractor.test
@@ -8,7 +8,7 @@
 # RUN: echo 'echo -e "#include <...> search starts here:\r" >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo -e "End of search list.\r" >&2' >> %t.dir/my_driver.sh
 # RUN: chmod +x %t.dir/my_driver.sh
 
 # Create header files my/dir/a.h and my/dir2/b.h
Index: clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
===
--- clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
@@ -59,7 +59,7 @@
 std::vector parseDriverOutput(llvm::StringRef Output) {
   std::vector SystemIncludes;
   const char SIS[] = "#include <...> search starts here:";
-  constexpr char const *SIE = "End of search list.";
+  const char SIE[] = "End of search list.";
   llvm::SmallVector Lines;
   Output.split(Lines, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
@@ -70,7 +70,9 @@
 return {};
   }
   ++StartIt;
-  const auto EndIt = std::find(StartIt, Lines.end(), SIE);
+  const auto EndIt =
+  llvm::find_if(llvm::make_range(StartIt, Lines.end()),
+[SIE](llvm::StringRef Line) { return Line.trim() == SIE; });
   if (EndIt == Lines.end()) {
 elog("System include extraction: end marker missing: {0}", Output);
 return {};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63876: [OpenCL] Define CLK_NULL_EVENT without cast

2019-07-19 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366546: [OpenCL] Define CLK_NULL_EVENT without cast 
(authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63876?vs=206850&id=210778#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63876

Files:
  cfe/trunk/lib/Headers/opencl-c-base.h
  cfe/trunk/test/SemaOpenCL/clk_event_t.cl


Index: cfe/trunk/test/SemaOpenCL/clk_event_t.cl
===
--- cfe/trunk/test/SemaOpenCL/clk_event_t.cl
+++ cfe/trunk/test/SemaOpenCL/clk_event_t.cl
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 global clk_event_t ce; // expected-error {{the '__global clk_event_t' type 
cannot be used to declare a program scope variable}}
 
@@ -10,6 +10,7 @@
   event_t e;
   clk_event_t ce1;
   clk_event_t ce2;
+  clk_event_t ce3 = CLK_NULL_EVENT;
 
   if (e == ce1) { // expected-error {{invalid operands to binary expression 
('event_t' and 'clk_event_t')}}
 return 9;
Index: cfe/trunk/lib/Headers/opencl-c-base.h
===
--- cfe/trunk/lib/Headers/opencl-c-base.h
+++ cfe/trunk/lib/Headers/opencl-c-base.h
@@ -413,7 +413,7 @@
 #define CLK_OUT_OF_RESOURCES-5
 
 #define CLK_NULL_QUEUE  0
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 // execution model related definitions
 #define CLK_ENQUEUE_FLAGS_NO_WAIT   0x0


Index: cfe/trunk/test/SemaOpenCL/clk_event_t.cl
===
--- cfe/trunk/test/SemaOpenCL/clk_event_t.cl
+++ cfe/trunk/test/SemaOpenCL/clk_event_t.cl
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
 
 // Taken from opencl-c.h
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 global clk_event_t ce; // expected-error {{the '__global clk_event_t' type cannot be used to declare a program scope variable}}
 
@@ -10,6 +10,7 @@
   event_t e;
   clk_event_t ce1;
   clk_event_t ce2;
+  clk_event_t ce3 = CLK_NULL_EVENT;
 
   if (e == ce1) { // expected-error {{invalid operands to binary expression ('event_t' and 'clk_event_t')}}
 return 9;
Index: cfe/trunk/lib/Headers/opencl-c-base.h
===
--- cfe/trunk/lib/Headers/opencl-c-base.h
+++ cfe/trunk/lib/Headers/opencl-c-base.h
@@ -413,7 +413,7 @@
 #define CLK_OUT_OF_RESOURCES-5
 
 #define CLK_NULL_QUEUE  0
-#define CLK_NULL_EVENT (__builtin_astype(((void*)(__SIZE_MAX__)), clk_event_t))
+#define CLK_NULL_EVENT (__builtin_astype(((__SIZE_MAX__)), clk_event_t))
 
 // execution model related definitions
 #define CLK_ENQUEUE_FLAGS_NO_WAIT   0x0
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] r366549 - Drop svn version suffix.

2019-07-19 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Jul 19 02:22:57 2019
New Revision: 366549

URL: http://llvm.org/viewvc/llvm-project?rev=366549&view=rev
Log:
Drop svn version suffix.

Modified:
libunwind/branches/release_90/CMakeLists.txt

Modified: libunwind/branches/release_90/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/branches/release_90/CMakeLists.txt?rev=366549&r1=366548&r2=366549&view=diff
==
--- libunwind/branches/release_90/CMakeLists.txt (original)
+++ libunwind/branches/release_90/CMakeLists.txt Fri Jul 19 02:22:57 2019
@@ -83,7 +83,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
   endif()
 
   set(PACKAGE_NAME libunwind)
-  set(PACKAGE_VERSION 9.0.0svn)
+  set(PACKAGE_VERSION 9.0.0)
   set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
   set(PACKAGE_BUGREPORT "llvm-b...@lists.llvm.org")
 


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


[clang-tools-extra] r366551 - Revert r366458, r366467 and r366468

2019-07-19 Thread Azharuddin Mohammed via cfe-commits
Author: azhar
Date: Fri Jul 19 02:26:33 2019
New Revision: 366551

URL: http://llvm.org/viewvc/llvm-project?rev=366551&view=rev
Log:
Revert r366458, r366467 and r366468

r366458 is causing test failures. r366467 and r366468 had to be reverted as
they were casuing conflict while reverting r366458.

r366468 [clangd] Remove dead code from BackgroundIndex
r366467 [clangd] BackgroundIndex stores shards to the closest project
r366458 [clangd] Refactor background-index shard loading

Added:
clang-tools-extra/trunk/clangd/test/Inputs/background-index/foo.h
Removed:
clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.cpp
clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.h
clang-tools-extra/trunk/clangd/test/Inputs/background-index/sub_dir/
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/clangd/index/BackgroundIndexStorage.cpp
clang-tools-extra/trunk/clangd/index/BackgroundRebuild.cpp
clang-tools-extra/trunk/clangd/index/BackgroundRebuild.h

clang-tools-extra/trunk/clangd/test/Inputs/background-index/definition.jsonrpc
clang-tools-extra/trunk/clangd/test/Inputs/background-index/foo.cpp
clang-tools-extra/trunk/clangd/test/background-index.test
clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=366551&r1=366550&r2=366551&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri Jul 19 02:26:33 2019
@@ -73,7 +73,6 @@ add_clang_library(clangDaemon
   XRefs.cpp
 
   index/Background.cpp
-  index/BackgroundIndexLoader.cpp
   index/BackgroundIndexStorage.cpp
   index/BackgroundQueue.cpp
   index/BackgroundRebuild.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=366551&r1=366550&r2=366551&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Fri Jul 19 02:26:33 2019
@@ -127,8 +127,7 @@ ClangdServer::ClangdServer(const GlobalC
   if (Opts.BackgroundIndex) {
 BackgroundIdx = llvm::make_unique(
 Context::current().clone(), FSProvider, CDB,
-BackgroundIndexStorage::createDiskBackedStorageFactory(
-[&CDB](llvm::StringRef File) { return CDB.getProjectInfo(File); 
}));
+BackgroundIndexStorage::createDiskBackedStorageFactory());
 AddIndex(BackgroundIdx.get());
   }
   if (DynamicIdx)

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=366551&r1=366550&r2=366551&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Fri Jul 19 02:26:33 2019
@@ -10,7 +10,6 @@
 #include "ClangdUnit.h"
 #include "Compiler.h"
 #include "Context.h"
-#include "FSProvider.h"
 #include "Headers.h"
 #include "Logger.h"
 #include "Path.h"
@@ -19,7 +18,6 @@
 #include "Threading.h"
 #include "Trace.h"
 #include "URI.h"
-#include "index/BackgroundIndexLoader.h"
 #include "index/FileIndex.h"
 #include "index/IndexAction.h"
 #include "index/MemIndex.h"
@@ -30,8 +28,6 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Driver/Types.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
@@ -46,7 +42,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -54,8 +49,6 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 
 namespace clang {
 namespace clangd {
@@ -126,18 +119,6 @@ llvm::SmallString<128> getAbsolutePath(c
   }
   return AbsolutePath;
 }
-
-bool shardIsStale(const LoadedShard &LS, llvm::vfs::FileSystem *FS) {
-  auto Buf = FS->getBufferForFile(LS.AbsolutePath);
-  if (!Buf) {
-elog("Background-index: Couldn't read {0} to validate stored index: {1}",
- LS.AbsolutePath, Buf.getError().message());
-// There is no point in indexing an unreadable file.
-return false;
-  }
-  return digest(Buf->get()->getBuffer()) != LS.Digest;
-}
-
 } // namespace
 
 BackgroundIndex::BackgroundIndex(
@@ -175,14 +156,14 @@ BackgroundQueue::Task BackgroundIndex::c
 log("Enqueueing {0} commands for indexing", ChangedFiles.size());
 SPAN_ATTACH(Trac

[PATCH] D64475: [clangd] Duplicate lines of semantic highlightings sent removed.

2019-07-19 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:458
+// edit there are stale previous highlightings.
+std::lock_guard Lock(HighlightingsMutex);
+FileToHighlightings.erase(File);

ilya-biryukov wrote:
> jvikstrom wrote:
> > ilya-biryukov wrote:
> > > Should can't we handle this on `didClose` instead?
> > We are removing in didClose but the problem is that there is a race 
> > condition (I think).
> > 
> > If someone does some edits and closes the document right after, the 
> > highlightings for the final edit might finish being generated after the 
> > FileToHighlightings have earsed the highlightings for the file. So next 
> > time when opening the file we will have those final highlightings that were 
> > generated for the last edit in the map. 
> > I don't really know how we could handle this in didClose without having 
> > another map and with an open/closed bit and checking that every time we 
> > generate new highlightings. But we'd still have to set the bit to be open 
> > every didOpen so I don't really see the benefit.
> > 
> > However I've head that ASTWorked is synchronous for a single file, is that 
> > the case for the didClose call as well? Because in that case there is no 
> > race condition.
> You are correct, there is actually a race condition. We worked hard to 
> eliminate it for diagnostics, but highlightings are going through a different 
> code path in `ASTWorker`, not guarded by `DiagsMu` and `ReportDiagnostics`.
> 
> And, unfortunately, I don't think this guard here prevents it in all cases. 
> In particular, there is still a possibility (albeit very low, I guess) that 
> the old highlightings you are trying to remove here are still being computed. 
> If they are reported **after** this `erase()` runs, we will end up with 
> inconsistent highlightings.
> 
> Ideally, we would guard the diagnostics callback with the same mutex, but 
> given our current layering it seems like a hard problem, will need to think 
> what's the simplest way to fix this.
The race condition of highlighting sounds bad (especially when a user opens a 
large file and closes it immediately, then the highlighting is finished and we 
emit it to the client). No need to fix it in this patch, just add a FIXME.


Can we use the same mechanism for Diagnostic to guard the highlighting here? or 
use the `DiagsMu` and `ReportDiagnostics` to guard the `callback.onMainAST()` 
as well (which is probably not a good idea)...



Comment at: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp:307
 
+TEST(SemanticHighlighting, HighlightingDiffer) {
+  struct {

jvikstrom wrote:
> ilya-biryukov wrote:
> > Can we test this in a more direct manner by specifying:
> > 1. annotated input for old highlightings,
> > 2. annotated input for new highlightings,
> > 3. the expected diff?
> > 
> > The resulting tests don't have to be real C++ then, allowing to express 
> > what we're testing in a more direct manner.
> > ```
> > {/*Old*/ "$Variable[[a]]", /*New*/ "$Class[[a]]", /*Diff*/ "{{/*line */0, 
> > "$Class[[a]]"}}
> > ```
> > 
> > It also seems that the contents of the lines could even be checked 
> > automatically (they should be equal to the corresponding line from 
> > `/*New*/`, right?), that leaves us with even simpler inputs:
> > ```
> > {/*Old*/ "$Variable[[a]]", /*New*/ "$Class[[a]]", /*DiffLines*/ "{0}}
> > ```
> That's a great idea on how to write these tests.
hmm, I have a different opinion here (I'd prefer the previous one), let's chat.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64475



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


Re: [clang-tools-extra] r366458 - [clangd] Refactor background-index shard loading

2019-07-19 Thread Azhar Mohammed via cfe-commits
Reverted in r366551. 


Revert r366458, r366467 and r366468

r366458 is causing test failures. r366467 and r366468 had to be reverted as
they were casuing conflict while reverting r366458.

r366468 [clangd] Remove dead code from BackgroundIndex
r366467 [clangd] BackgroundIndex stores shards to the closest project
r366458 [clangd] Refactor background-index shard loading

> On Jul 18, 2019, at 6:21 PM, Azhar Mohammed  wrote:
> 
> Hi Kadir
> 
> This change is causing test failures, can you please look into it. Refer to 
> http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/58104/testReport/
>  
> .
>  
> 
> Assertion failed: (TUsIt != FileToTU.end() && "No TU registered for the 
> shard"), function takeResult, file 
> /Users/buildslave/jenkins/workspace/clang-stage1-configure-RA/llvm/tools/clang/tools/extra/clangd/index/BackgroundIndexLoader.cpp,
>  line 131.
> 
> 
> Failing Tests (10):
> Clangd :: did-change-configuration-params.test
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.CmdLineHash
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.DirectIncludesTest
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.IndexTwoFiles
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.NoCrashOnErrorFile
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.NoDotsInAbsPath
> Clangd Unit Tests :: 
> ./ClangdTests/BackgroundIndexTest.ShardStorageEmptyFile
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.ShardStorageLoad
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.ShardStorageTest
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.UncompilableFiles
> 
> 
>> On Jul 18, 2019, at 9:25 AM, Kadir Cetinkaya via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> 
>> Author: kadircet
>> Date: Thu Jul 18 09:25:36 2019
>> New Revision: 366458
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=366458&view=rev 
>> 
>> Log:
>> [clangd] Refactor background-index shard loading
>> 
>> Reviewers: sammccall
>> 
>> Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
>> 
>> Tags: #clang
>> 
>> Differential Revision: https://reviews.llvm.org/D64712 
>> 
>> 
>> Added:
>>clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.cpp
>>clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.h
>> Modified:
>>clang-tools-extra/trunk/clangd/CMakeLists.txt
>>clang-tools-extra/trunk/clangd/index/Background.cpp
>>clang-tools-extra/trunk/clangd/index/Background.h
>>clang-tools-extra/trunk/clangd/index/BackgroundRebuild.cpp
>>clang-tools-extra/trunk/clangd/index/BackgroundRebuild.h
>>clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
>> 
>> Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
>> URL: 
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=366458&r1=366457&r2=366458&view=diff
>>  
>> 
>> ==
>> --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
>> +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Jul 18 09:25:36 2019
>> @@ -73,6 +73,7 @@ add_clang_library(clangDaemon
>>   XRefs.cpp
>> 
>>   index/Background.cpp
>> +  index/BackgroundIndexLoader.cpp
>>   index/BackgroundIndexStorage.cpp
>>   index/BackgroundQueue.cpp
>>   index/BackgroundRebuild.cpp
>> 
>> Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=366458&r1=366457&r2=366458&view=diff
>>  
>> 
>> ==
>> --- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Jul 18 09:25:36 
>> 2019
>> @@ -10,6 +10,7 @@
>> #include "ClangdUnit.h"
>> #include "Compiler.h"
>> #include "Context.h"
>> +#include "FSProvider.h"
>> #include "Headers.h"
>> #include "Logger.h"
>> #include "Path.h"
>> @@ -18,6 +19,7 @@
>> #include "Threading.h"
>> #include "Trace.h"
>> #include "URI.h"
>> +#include "index/BackgroundIndexLoader.h"
>> #include "index/FileIndex.h"
>> #include "index/IndexAction.h"
>> #include "index/MemIndex.h"
>> @@ -28,6 +30,8 @@
>> #include "clang/Basic/SourceLocation.h"
>> #include "clang/Basic/SourceManager.h"
>> #include "clang/Driver/Types.h"
>> +#include "llvm/ADT/ArrayRef.h"
>> +#include "llvm/ADT/DenseSet.h"
>> #include "llvm/ADT/Hashing.h"
>> #include "llvm/ADT/STLExtras

[PATCH] D64329: [Clangd] Fixed SelectionTree bug for macros

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

Updated comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64329

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -395,12 +395,23 @@
}
  })cpp"},*/
   // ensure InsertionPoint isn't inside a macro
-  {R"cpp(#define LOOP(x) {int a = x + 1;}
+  // FIXME: SelectionTree needs to be fixed for macros
+  /*{R"cpp(#define LOOP(x) while (1) {a = x;}
  void f(int a) {
if(1)
 LOOP(5 + ^3)
  })cpp",
-   R"cpp(#define LOOP(x) {int a = x + 1;}
+ R"cpp(#define LOOP(x) while (1) {a = x;}
+ void f(int a) {
+   auto dummy = 3; if(1)
+LOOP(5 + dummy)
+ })cpp"},*/
+  {R"cpp(#define LOOP(x) do {x;} while(1);
+ void f(int a) {
+   if(1)
+LOOP(5 + ^3)
+ })cpp",
+   R"cpp(#define LOOP(x) do {x;} while(1);
  void f(int a) {
auto dummy = 3; if(1)
 LOOP(5 + dummy)
@@ -421,9 +432,9 @@
  void f(int a) {
auto dummy = a; PLUS(dummy);
  })cpp"},*/
-  // FIXME: Doesn't work correctly for \[\[clang::uninitialized\]\] int b
-  // = 1; since the attr is inside the DeclStmt and the bounds of
-  // DeclStmt don't cover the attribute
+  // FIXME: Doesn't work correctly for this code since the attr is
+  // inside the DeclStmt and the bounds of DeclStmt don't cover the attr
+  // \[\[clang::uninitialized\]\] int b = 1;
   };
   for (const auto &IO : InputOutputs) {
 checkTransform(ID, IO.first, IO.second);
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -37,15 +37,15 @@
 Range nodeRange(const SelectionTree::Node *N, ParsedAST &AST) {
   if (!N)
 return Range{};
-  SourceManager &SM = AST.getSourceManager();
+  const SourceManager &SM = AST.getSourceManager();
+  const LangOptions &LangOpts = AST.getASTContext().getLangOpts();
   StringRef Buffer = SM.getBufferData(SM.getMainFileID());
-  SourceRange SR = N->ASTNode.getSourceRange();
-  SR.setBegin(SM.getFileLoc(SR.getBegin()));
-  SR.setEnd(SM.getFileLoc(SR.getEnd()));
-  CharSourceRange R =
-  Lexer::getAsCharRange(SR, SM, AST.getASTContext().getLangOpts());
-  return Range{offsetToPosition(Buffer, SM.getFileOffset(R.getBegin())),
-   offsetToPosition(Buffer, SM.getFileOffset(R.getEnd()))};
+  auto FileRange =
+  toHalfOpenFileRange(SM, LangOpts, N->ASTNode.getSourceRange());
+  assert(FileRange && "We should be able to get the File Range");
+  return Range{
+  offsetToPosition(Buffer, SM.getFileOffset(FileRange->getBegin())),
+  offsetToPosition(Buffer, SM.getFileOffset(FileRange->getEnd()))};
 }
 
 std::string nodeKind(const SelectionTree::Node *N) {
@@ -144,17 +144,17 @@
   R"cpp(
 void foo();
 #define CALL_FUNCTION(X) X()
-void bar() [[{ CALL_FUNC^TION(fo^o); }]]
+void bar() { [[CALL_FUNC^TION(fo^o)]]; }
   )cpp",
-  "CompoundStmt",
+  "CallExpr",
   },
   {
   R"cpp(
 void foo();
 #define CALL_FUNCTION(X) X()
-void bar() [[{ C^ALL_FUNC^TION(foo); }]]
+void bar() { [[C^ALL_FUNC^TION(foo)]]; }
   )cpp",
-  "CompoundStmt",
+  "CallExpr",
   },
   {
   R"cpp(
@@ -289,6 +289,9 @@
   EXPECT_FALSE(D->isInjectedClassName());
 }
 
+// FIXME: Doesn't select the binary operator node in
+//  #define FOO(X) X + 1
+//  int a, b = [[FOO(a)]];
 TEST(SelectionTest, Selected) {
   // Selection with ^marks^.
   // Partially selected nodes marked with a [[range]].
@@ -308,7 +311,12 @@
   R"cpp(
   template 
   struct unique_ptr {};
-  void foo(^$C[[unique_ptr>]]^ a) {}
+  void foo(^$C[[unique_ptr<$C[[unique_ptr<$C[[int]]>]]>]]^ a) {}
+  )cpp",
+  R"cpp(int a = [[5 >^> 1]];)cpp",
+  R"cpp(
+#define ECHO(X) X
+ECHO(EC^HO([[$C[[int]]) EC^HO(a]]));
   )cpp",
   };
   for (const char *C : Cases) {
Index: cla

[PATCH] D41412: [libcxx] implement concat() and split()

2019-07-19 Thread Tobias Grosser via Phabricator via cfe-commits
grosser added a comment.

In D41412#1592152 , @timshen wrote:

> Tobias,
>
> I spoke to @EricWF who is willing to take a look at all these patches. 
> However, I don't know when exactly will the review starts.


Amazing. I am super interested in seeing this moving but am happy to give you 
some time to get started. ;-) Thanks a lot for picking this up!


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

https://reviews.llvm.org/D41412



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


[PATCH] D62960: Add SVE opaque built-in types

2019-07-19 Thread Diana Picus via Phabricator via cfe-commits
rovka added a comment.

FWIW, I think the tests look great. Would be nice if someone more experienced 
with clang could also have a look though.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62960



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


Re: r366480 - [RISCV] Hard float ABI support

2019-07-19 Thread Hans Wennborg via cfe-commits
Merged to the 9.0 branch in r366554.

On Thu, Jul 18, 2019 at 8:29 PM Alex Bradbury via cfe-commits
 wrote:
>
> Author: asb
> Date: Thu Jul 18 11:29:59 2019
> New Revision: 366480
>
> URL: http://llvm.org/viewvc/llvm-project?rev=366480&view=rev
> Log:
> [RISCV] Hard float ABI support
>
> The RISC-V hard float calling convention requires the frontend to:
>
> * Detect cases where, once "flattened", a struct can be passed using
> int+fp or fp+fp registers under the hard float ABI and coerce to the
> appropriate type(s)
> * Track usage of GPRs and FPRs in order to gate the above, and to
> determine when signext/zeroext attributes must be added to integer
> scalars
>
> This patch attempts to do this in compliance with the documented ABI,
> and uses ABIArgInfo::CoerceAndExpand in order to do this. @rjmccall, as
> author of that code I've tagged you as reviewer for initial feedback on
> my usage.
>
> Note that a previous version of the ABI indicated that when passing an
> int+fp struct using a GPR+FPR, the int would need to be sign or
> zero-extended appropriately. GCC never did this and the ABI was changed,
> which makes life easier as ABIArgInfo::CoerceAndExpand can't currently
> handle sign/zero-extension attributes.
>
> Re-landed after backing out 366450 due to missed hunks.
>
> Differential Revision: https://reviews.llvm.org/D60456
>
> Added:
> cfe/trunk/test/CodeGen/riscv32-ilp32d-abi.c
> cfe/trunk/test/CodeGen/riscv32-ilp32f-abi.c
> cfe/trunk/test/CodeGen/riscv32-ilp32f-ilp32d-abi.c
> cfe/trunk/test/CodeGen/riscv64-lp64d-abi.c
> cfe/trunk/test/CodeGen/riscv64-lp64f-lp64d-abi.c
> Modified:
> cfe/trunk/lib/Basic/Targets/RISCV.cpp
> cfe/trunk/lib/Basic/Targets/RISCV.h
> cfe/trunk/lib/CodeGen/TargetInfo.cpp
> cfe/trunk/test/CodeGen/riscv32-ilp32-ilp32f-abi.c
> cfe/trunk/test/CodeGen/riscv32-ilp32-ilp32f-ilp32d-abi.c
> cfe/trunk/test/CodeGen/riscv64-lp64-lp64f-abi.c
> cfe/trunk/test/CodeGen/riscv64-lp64-lp64f-lp64d-abi.c
> cfe/trunk/test/Driver/riscv-abi.c
> cfe/trunk/test/Preprocessor/riscv-target-features.c
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64863: [clangd] Ignore diags from builtin files

2019-07-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 210786.
kadircet added a comment.

- Add tests.
- Change the layer we ignore the diags:
  - Mark diags from headers as insidemainfile when we decide to surface them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64863

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -907,7 +907,6 @@
 int x = 5/0;)cpp");
   TestTU TU = TestTU::withCode(Main.code());
   TU.AdditionalFiles = {{"a.h", Header.code()}};
-  auto diags = TU.build().getDiagnostics();
   EXPECT_THAT(TU.build().getDiagnostics(),
   UnorderedElementsAre(AllOf(
   Diag(Main.range(), "in included file: C++ requires "
@@ -915,6 +914,19 @@
   WithNote(Diag(Header.range(), "error occurred here");
 }
 
+TEST(IgnoreDiags, FromNonWrittenSources) {
+  Annotations Main(R"cpp(
+#include [["a.h"]]
+void foo() {})cpp");
+  Annotations Header(R"cpp(
+int x = 5/0;
+int b = [[FOO]];)cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.AdditionalFiles = {{"a.h", Header.code()}};
+  TU.ExtraArgs = {"-DFOO=NOOO"};
+  EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
+}
+
 } // namespace
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -20,6 +20,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Capacity.h"
@@ -108,7 +109,12 @@
 }
 
 void adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info,
-  const LangOptions &LangOpts) {
+  const LangOptions &LangOpts,
+  llvm::DenseSet &IncludeLinesWithErrors) {
+  // We only report diagnostics with at least error severity from headers.
+  if (D.Severity < DiagnosticsEngine::Level::Error)
+return;
+
   const SourceLocation &DiagLoc = Info.getLocation();
   const SourceManager &SM = Info.getSourceManager();
   SourceLocation IncludeInMainFile;
@@ -120,12 +126,17 @@
 IncludeInMainFile = IncludeLocation;
   if (IncludeInMainFile.isInvalid())
 return;
+  Position StartPos = sourceLocToPosition(SM, IncludeInMainFile);
+  // Only report the first diagnostic coming from a header.
+  if (!IncludeLinesWithErrors.insert(StartPos.line).second)
+return;
 
   // Update diag to point at include inside main file.
   D.File = SM.getFileEntryForID(SM.getMainFileID())->getName().str();
-  D.Range.start = sourceLocToPosition(SM, IncludeInMainFile);
+  D.Range.start = std::move(StartPos);
   D.Range.end = sourceLocToPosition(
   SM, Lexer::getLocForEndOfToken(IncludeInMainFile, 0, SM, LangOpts));
+  D.InsideMainFile = true;
 
   // Add a note that will point to real diagnostic.
   const auto *FE = SM.getFileEntryForID(SM.getFileID(DiagLoc));
@@ -465,6 +476,7 @@
   }
 
   bool InsideMainFile = isInsideMainFile(Info);
+  SourceManager &SM = Info.getSourceManager();
 
   auto FillDiagBase = [&](DiagBase &D) {
 D.Range = diagnosticRange(Info, *LangOpts);
@@ -472,8 +484,7 @@
 Info.FormatDiagnostic(Message);
 D.Message = Message.str();
 D.InsideMainFile = InsideMainFile;
-D.File = Info.getSourceManager().getFilename(Info.getLocation());
-auto &SM = Info.getSourceManager();
+D.File = SM.getFilename(Info.getLocation());
 D.AbsFile = getCanonicalPath(
 SM.getFileEntryForID(SM.getFileID(Info.getLocation())), SM);
 D.Severity = DiagLevel;
@@ -496,10 +507,9 @@
   if (FixIt.RemoveRange.getBegin().isMacroID() ||
   FixIt.RemoveRange.getEnd().isMacroID())
 return false;
-  if (!isInsideMainFile(FixIt.RemoveRange.getBegin(),
-Info.getSourceManager()))
+  if (!isInsideMainFile(FixIt.RemoveRange.getBegin(), SM))
 return false;
-  Edits.push_back(toTextEdit(FixIt, Info.getSourceManager(), *LangOpts));
+  Edits.push_back(toTextEdit(FixIt, SM, *LangOpts));
 }
 
 llvm::SmallString<64> Message;
@@ -507,8 +517,8 @@
 if (SyntheticMessage && Info.getNumFixItHints() == 1) {
   const auto &FixIt = Info.getFixItHint(0);
   bool Invalid = false;
-  llvm::StringRef Remove = Lexer::getSourceText(
-  FixIt.RemoveRange, Info.getSourceManager(), *LangOpts, &Invalid);
+  llvm::StringRef Remove =
+  Lexer::getSourceText(FixIt.RemoveRange, SM, *LangOpts, &Invalid);
   

[PATCH] D64863: [clangd] Ignore diags from builtin files

2019-07-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 2 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:473
+  SourceManager &SM = Info.getSourceManager();
+  if (!InsideMainFile && SM.isWrittenInBuiltinFile(Info.getLocation())) {
+IgnoreDiagnostics::log(DiagLevel, Info);

ilya-biryukov wrote:
> hokein wrote:
> > ilya-biryukov wrote:
> > > There is also at least `isWrittenInCommandLineFile` and 
> > > `isWrittenInScratchSpace`.
> > > We should probably handle both of them here too.
> > > 
> > > What are we actually checking here? That we can later create a URI for 
> > > this file? Is there a good way to check exactly that without breaking 
> > > layering?
> > shall we put this into the `isInsideMainFile`? I think the location written 
> > in CommandLineFile/ScratchSpace is not inside main file logically.
> > 
> Very good point.
> @kadircet does `isInsideMainFile` returns true for locations from command 
> line or scratch-pad?
yes it does


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64863



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


Re: r366511 - Update the SimpleJIT class in the clang-interpreter example to use ORCv2.

2019-07-19 Thread Hans Wennborg via cfe-commits
Merged to 9.0 in r366556.

On Fri, Jul 19, 2019 at 12:46 AM Lang Hames via cfe-commits
 wrote:
>
> Author: lhames
> Date: Thu Jul 18 15:47:18 2019
> New Revision: 366511
>
> URL: http://llvm.org/viewvc/llvm-project?rev=366511&view=rev
> Log:
> Update the SimpleJIT class in the clang-interpreter example to use ORCv2.
>
> This will remove the ORCv1 deprecation warnings.
>
> Modified:
> cfe/trunk/examples/clang-interpreter/main.cpp
>
> Modified: cfe/trunk/examples/clang-interpreter/main.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/clang-interpreter/main.cpp?rev=366511&r1=366510&r2=366511&view=diff
> ==
> --- cfe/trunk/examples/clang-interpreter/main.cpp (original)
> +++ cfe/trunk/examples/clang-interpreter/main.cpp Thu Jul 18 15:47:18 2019
> @@ -18,6 +18,7 @@
>  #include "llvm/ADT/SmallString.h"
>  #include "llvm/ExecutionEngine/ExecutionEngine.h"
>  #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
> +#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
>  #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
>  #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
>  #include "llvm/ExecutionEngine/SectionMemoryManager.h"
> @@ -50,65 +51,69 @@ namespace orc {
>  class SimpleJIT {
>  private:
>ExecutionSession ES;
> -  std::shared_ptr Resolver;
>std::unique_ptr TM;
>const DataLayout DL;
> -  LegacyRTDyldObjectLinkingLayer ObjectLayer;
> -  LegacyIRCompileLayer CompileLayer;
> +  MangleAndInterner Mangle{ES, DL};
> +  RTDyldObjectLinkingLayer ObjectLayer{ES, createMemMgr};
> +  IRCompileLayer CompileLayer{ES, ObjectLayer, SimpleCompiler(*TM)};
>
> -public:
> -  SimpleJIT()
> -  : Resolver(createLegacyLookupResolver(
> -ES,
> -[this](const std::string &Name) -> JITSymbol {
> -  if (auto Sym = CompileLayer.findSymbol(Name, false))
> -return Sym;
> -  else if (auto Err = Sym.takeError())
> -return std::move(Err);
> -  if (auto SymAddr =
> -  RTDyldMemoryManager::getSymbolAddressInProcess(Name))
> -return JITSymbol(SymAddr, JITSymbolFlags::Exported);
> -  return nullptr;
> -},
> -[](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); 
> })),
> -TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
> -ObjectLayer(ES,
> -[this](VModuleKey) {
> -  return LegacyRTDyldObjectLinkingLayer::Resources{
> -  std::make_shared(), 
> Resolver};
> -}),
> -CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {
> +  static std::unique_ptr createMemMgr() {
> +return llvm::make_unique();
> +  }
> +
> +  SimpleJIT(std::unique_ptr TM, DataLayout DL,
> +DynamicLibrarySearchGenerator ProcessSymbolsGenerator)
> +  : TM(std::move(TM)), DL(std::move(DL)) {
>  llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
> +ES.getMainJITDylib().setGenerator(std::move(ProcessSymbolsGenerator));
>}
>
> -  const TargetMachine &getTargetMachine() const { return *TM; }
> +public:
> +  static Expected> Create() {
> +auto JTMB = JITTargetMachineBuilder::detectHost();
> +if (!JTMB)
> +  return JTMB.takeError();
> +
> +auto TM = JTMB->createTargetMachine();
> +if (!TM)
> +  return TM.takeError();
> +
> +auto DL = (*TM)->createDataLayout();
> +
> +auto ProcessSymbolsGenerator =
> +DynamicLibrarySearchGenerator::GetForCurrentProcess(
> +DL.getGlobalPrefix());
> +
> +if (!ProcessSymbolsGenerator)
> +  return ProcessSymbolsGenerator.takeError();
>
> -  VModuleKey addModule(std::unique_ptr M) {
> -// Add the module to the JIT with a new VModuleKey.
> -auto K = ES.allocateVModule();
> -cantFail(CompileLayer.addModule(K, std::move(M)));
> -return K;
> +return std::unique_ptr(new SimpleJIT(
> +std::move(*TM), std::move(DL), std::move(*ProcessSymbolsGenerator)));
>}
>
> -  JITSymbol findSymbol(const StringRef &Name) {
> -std::string MangledName;
> -raw_string_ostream MangledNameStream(MangledName);
> -Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
> -return CompileLayer.findSymbol(MangledNameStream.str(), true);
> +  const TargetMachine &getTargetMachine() const { return *TM; }
> +
> +  Error addModule(ThreadSafeModule M) {
> +return CompileLayer.add(ES.getMainJITDylib(), std::move(M));
>}
>
> -  JITTargetAddress getSymbolAddress(const StringRef &Name) {
> -return cantFail(findSymbol(Name).getAddress());
> +  Expected findSymbol(const StringRef &Name) {
> +return ES.lookup({&ES.getMainJITDylib()}, Mangle(Name));
>}
>
> -  void removeModule(VModuleKey K) {
> -cantFail(CompileLayer.removeModule(K));
> +  Expected getSymbolAddress(const StringRef &Name) {
> +auto Sym = findSymbol(N

[PATCH] D64985: [clangd] Provide a way to publish highlightings in non-racy manner

2019-07-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, javed.absar.
Herald added a project: clang.

By exposing a callback that can guard code publishing results of
'onMainAST' callback in the same manner we guard diagnostics.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64985

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

Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -15,6 +15,7 @@
 #include "Threading.h"
 #include "index/CanonicalIncludes.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -88,6 +89,7 @@
   BuildDetails Details;
 };
 
+
 class ParsingCallbacks {
 public:
   virtual ~ParsingCallbacks() = default;
@@ -98,6 +100,10 @@
   virtual void onPreambleAST(PathRef Path, ASTContext &Ctx,
  std::shared_ptr PP,
  const CanonicalIncludes &) {}
+  /// A function that is run under the critical section guarding against races
+  /// when closing the files.
+  using PublishResults = llvm::function_ref;
+
   /// Called on the AST built for the file itself. Note that preamble AST nodes
   /// are not deserialized and should be processed in the onPreambleAST call
   /// instead.
@@ -108,7 +114,14 @@
   /// etc. Clients are expected to process only the AST nodes from the main file
   /// in this callback (obtained via ParsedAST::getLocalTopLevelDecls) to obtain
   /// optimal performance.
-  virtual void onMainAST(PathRef Path, ParsedAST &AST) {}
+  ///
+  /// This callback is run on a worker thread and if we need to send results of
+  /// processing AST to the users, we might run into a race condition with file
+  /// removal. To avoid the race condition, send the results by running \p
+  /// Publish. That would ensure publishing the results is either sequenced
+  /// before removing the file or does not happen at all.
+  virtual void onMainAST(PathRef Path, ParsedAST &AST,
+ llvm::function_ref Publish) {}
 
   /// Called whenever the diagnostics for \p File are produced.
   virtual void onDiagnostics(PathRef File, std::vector Diags) {}
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -486,13 +486,22 @@
 // spam us with updates.
 // Note *AST can still be null if buildAST fails.
 if (*AST) {
-  {
+  // Results from the worker thread should only be published if the file was
+  // not removed. This callback ensures the passed operation is not racing
+  // with file removal.
+  auto Publish = [&](ParsingCallbacks::PublishResults Action) {
 std::lock_guard Lock(DiagsMu);
 if (ReportDiagnostics)
-  Callbacks.onDiagnostics(FileName, (*AST)->getDiagnostics());
-  }
+  Action();
+  };
+
+  // Publish diagnostics.
+  Publish([&]() {
+Callbacks.onDiagnostics(FileName, (*AST)->getDiagnostics());
+  });
+
   trace::Span Span("Running main AST callback");
-  Callbacks.onMainAST(FileName, **AST);
+  Callbacks.onMainAST(FileName, **AST, Publish);
   DiagsWereReported = true;
 }
 // Stash the AST in the cache for further use.
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -31,6 +31,7 @@
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
@@ -60,11 +61,17 @@
   FIndex->updatePreamble(Path, Ctx, std::move(PP), CanonIncludes);
   }
 
-  void onMainAST(PathRef Path, ParsedAST &AST) override {
+  void onMainAST(PathRef Path, ParsedAST &AST,
+ llvm::function_ref Publish) override {
 if (FIndex)
   FIndex->updateMain(Path, AST);
-if (SemanticHighlighting)
-  DiagConsumer.onHighlightingsReady(Path, getSemanticHighlightings(AST));
+
+if (!SemanticHighlighting)
+  return;
+auto Highlightings = getSemanticHighlightings(AST);
+Publish([&]() {
+  DiagConsumer.onHighlightingsReady(Path, std::move(Highlightings));
+});
   }
 
   void onDiagnostics(PathRef File, std::vector Diags) override {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-co

[PATCH] D64416: [AArch64] Add support for Transactional Memory Extension (TME)

2019-07-19 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard accepted this revision.
ostannard added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D64416



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


[clang-tools-extra] r366559 - Revert "Revert r366458, r366467 and r366468"

2019-07-19 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Jul 19 03:18:52 2019
New Revision: 366559

URL: http://llvm.org/viewvc/llvm-project?rev=366559&view=rev
Log:
Revert "Revert r366458, r366467 and r366468"

This reverts commit 9c377105da0be7c2c9a3c70035ce674c71b846af.

[clangd][BackgroundIndexLoader] Directly store DependentTU while loading shard

Summary:
We were deferring the population of DependentTU field in LoadedShard
until BackgroundIndexLoader was consumed. This actually triggers a use after
free since the shards FileToTU was pointing at could've been moved while
consuming the Loader.

Reviewers: sammccall

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

Tags: #clang

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

Added:
clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.cpp
clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.h
clang-tools-extra/trunk/clangd/test/Inputs/background-index/sub_dir/

clang-tools-extra/trunk/clangd/test/Inputs/background-index/sub_dir/compile_flags.txt
clang-tools-extra/trunk/clangd/test/Inputs/background-index/sub_dir/foo.h
Removed:
clang-tools-extra/trunk/clangd/test/Inputs/background-index/foo.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/clangd/index/BackgroundIndexStorage.cpp
clang-tools-extra/trunk/clangd/index/BackgroundRebuild.cpp
clang-tools-extra/trunk/clangd/index/BackgroundRebuild.h

clang-tools-extra/trunk/clangd/test/Inputs/background-index/definition.jsonrpc
clang-tools-extra/trunk/clangd/test/Inputs/background-index/foo.cpp
clang-tools-extra/trunk/clangd/test/background-index.test
clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=366559&r1=366558&r2=366559&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri Jul 19 03:18:52 2019
@@ -73,6 +73,7 @@ add_clang_library(clangDaemon
   XRefs.cpp
 
   index/Background.cpp
+  index/BackgroundIndexLoader.cpp
   index/BackgroundIndexStorage.cpp
   index/BackgroundQueue.cpp
   index/BackgroundRebuild.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=366559&r1=366558&r2=366559&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Fri Jul 19 03:18:52 2019
@@ -127,7 +127,8 @@ ClangdServer::ClangdServer(const GlobalC
   if (Opts.BackgroundIndex) {
 BackgroundIdx = llvm::make_unique(
 Context::current().clone(), FSProvider, CDB,
-BackgroundIndexStorage::createDiskBackedStorageFactory());
+BackgroundIndexStorage::createDiskBackedStorageFactory(
+[&CDB](llvm::StringRef File) { return CDB.getProjectInfo(File); 
}));
 AddIndex(BackgroundIdx.get());
   }
   if (DynamicIdx)

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=366559&r1=366558&r2=366559&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Fri Jul 19 03:18:52 2019
@@ -10,6 +10,7 @@
 #include "ClangdUnit.h"
 #include "Compiler.h"
 #include "Context.h"
+#include "FSProvider.h"
 #include "Headers.h"
 #include "Logger.h"
 #include "Path.h"
@@ -18,6 +19,7 @@
 #include "Threading.h"
 #include "Trace.h"
 #include "URI.h"
+#include "index/BackgroundIndexLoader.h"
 #include "index/FileIndex.h"
 #include "index/IndexAction.h"
 #include "index/MemIndex.h"
@@ -28,6 +30,8 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Driver/Types.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
@@ -42,6 +46,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -49,6 +54,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -119,6 +126,18 @@ llvm::SmallString<128> getAbsolutePath(c
   }
   return AbsolutePath;
 }
+
+bool shardIsStale(const LoadedShard &LS, llvm::vfs::FileSystem *FS) {
+  auto Buf = FS->getBufferForFile(LS.AbsolutePath);
+  if (!Buf) {
+elog("Background-index: Couldn't read {0} to validate s

[PATCH] D64980: [clangd][BackgroundIndexLoader] Directly store DependentTU while loading shard

2019-07-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366559: Revert "Revert r366458, r366467 and 
r366468" (authored by kadircet, committed by ).
Herald added subscribers: llvm-commits, mgorny.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D64980?vs=210775&id=210791#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64980

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

Index: clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.h
===
--- clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.h
+++ clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.h
@@ -0,0 +1,54 @@
+//===--- BackgroundIndexLoader.h - Load shards from index storage-*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_INDEX_LOADER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_INDEX_LOADER_H
+
+#include "Path.h"
+#include "index/Background.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// Represents a shard loaded from storage, stores contents in \p Shard and
+/// metadata about the source file that generated this shard.
+struct LoadedShard {
+  /// Path of the source file that produced this shard.
+  Path AbsolutePath;
+  /// Digest of the source file contents that produced this shard.
+  FileDigest Digest = {};
+  /// Whether the RefSlab in Shard should be used for updating symbol reference
+  /// counts when building an index.
+  bool CountReferences = false;
+  /// Whether the indexing action producing that shard had errors.
+  bool HadErrors = false;
+  /// Path to a TU that is depending on this shard.
+  Path DependentTU;
+  /// Will be nullptr when index storage couldn't provide a valid shard for
+  /// AbsolutePath.
+  std::unique_ptr Shard;
+};
+
+/// Loads all shards for the TU \p MainFile from \p Storage.
+std::vector
+loadIndexShards(llvm::ArrayRef MainFiles,
+BackgroundIndexStorage::Factory &IndexStorageFactory,
+const GlobalCompilationDatabase &CDB);
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/trunk/clangd/index/BackgroundRebuild.cpp
===
--- clang-tools-extra/trunk/clangd/index/BackgroundRebuild.cpp
+++ clang-tools-extra/trunk/clangd/index/BackgroundRebuild.cpp
@@ -78,13 +78,13 @@
 void BackgroundIndexRebuilder::startLoading() {
   std::lock_guard Lock(Mu);
   if (!Loading)
-LoadedTUs = 0;
+LoadedShards = 0;
   ++Loading;
 }
-void BackgroundIndexRebuilder::loadedTU() {
+void BackgroundIndexRebuilder::loadedShard(size_t ShardCount) {
   std::lock_guard Lock(Mu);
   assert(Loading);
-  ++LoadedTUs;
+  LoadedShards += ShardCount;
 }
 void BackgroundIndexRebuilder::doneLoading() {
   maybeRebuild("after loading index from disk", [this] {
@@ -93,7 +93,7 @@
 if (Loading)// was loading multiple batches concurrently
   return false; // rebuild once the last batch is done.
 // Rebuild if we loaded any shards, or if we stopped an indexedTU rebuild.
-return LoadedTUs > 0 || enoughTUsToRebuild();
+return LoadedShards > 0 || enoughTUsToRebuild();
   });
 }
 
Index: clang-tools-extra/trunk/clangd/index/Background.h
===
--- clang-tools-extra/trunk/clangd/index/Background.h
+++

Re: [clang-tools-extra] r366458 - [clangd] Refactor background-index shard loading

2019-07-19 Thread Kadir Çetinkaya via cfe-commits
Hi Azhar, D64980 should fix the problem. I am reverting your revert while
adding the fix in r366559.

On Fri, Jul 19, 2019 at 11:29 AM Azhar Mohammed  wrote:

> Reverted in r366551.
>
>
> Revert r366458, r366467 and r366468
>
> r366458 is causing test failures. r366467 and r366468 had to be
> reverted as
> they were casuing conflict while reverting r366458.
>
> r366468 [clangd] Remove dead code from BackgroundIndex
> r366467 [clangd] BackgroundIndex stores shards to the closest project
> r366458 [clangd] Refactor background-index shard loading
>
> On Jul 18, 2019, at 6:21 PM, Azhar Mohammed  wrote:
>
> Hi Kadir
>
> This change is causing test failures, can you please look into it. Refer
> to
> http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/58104/testReport/
> .
>
> Assertion failed: (TUsIt != FileToTU.end() && "No TU registered for the 
> shard"), function takeResult, file 
> /Users/buildslave/jenkins/workspace/clang-stage1-configure-RA/llvm/tools/clang/tools/extra/clangd/index/BackgroundIndexLoader.cpp,
>  line 131.
>
>
>
> Failing Tests (10):
> Clangd :: did-change-configuration-params.test
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.CmdLineHash
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.DirectIncludesTest
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.IndexTwoFiles
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.NoCrashOnErrorFile
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.NoDotsInAbsPath
> Clangd Unit Tests :: 
> ./ClangdTests/BackgroundIndexTest.ShardStorageEmptyFile
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.ShardStorageLoad
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.ShardStorageTest
> Clangd Unit Tests :: ./ClangdTests/BackgroundIndexTest.UncompilableFiles
>
>
>
> On Jul 18, 2019, at 9:25 AM, Kadir Cetinkaya via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: kadircet
> Date: Thu Jul 18 09:25:36 2019
> New Revision: 366458
>
> URL: http://llvm.org/viewvc/llvm-project?rev=366458&view=rev
> Log:
> [clangd] Refactor background-index shard loading
>
> Reviewers: sammccall
>
> Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D64712
>
> Added:
>clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.cpp
>clang-tools-extra/trunk/clangd/index/BackgroundIndexLoader.h
> Modified:
>clang-tools-extra/trunk/clangd/CMakeLists.txt
>clang-tools-extra/trunk/clangd/index/Background.cpp
>clang-tools-extra/trunk/clangd/index/Background.h
>clang-tools-extra/trunk/clangd/index/BackgroundRebuild.cpp
>clang-tools-extra/trunk/clangd/index/BackgroundRebuild.h
>clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
>
> Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=366458&r1=366457&r2=366458&view=diff
>
> ==
> --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
> +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Jul 18 09:25:36 2019
> @@ -73,6 +73,7 @@ add_clang_library(clangDaemon
>   XRefs.cpp
>
>   index/Background.cpp
> +  index/BackgroundIndexLoader.cpp
>   index/BackgroundIndexStorage.cpp
>   index/BackgroundQueue.cpp
>   index/BackgroundRebuild.cpp
>
> Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=366458&r1=366457&r2=366458&view=diff
>
> ==
> --- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
> +++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Jul 18
> 09:25:36 2019
> @@ -10,6 +10,7 @@
> #include "ClangdUnit.h"
> #include "Compiler.h"
> #include "Context.h"
> +#include "FSProvider.h"
> #include "Headers.h"
> #include "Logger.h"
> #include "Path.h"
> @@ -18,6 +19,7 @@
> #include "Threading.h"
> #include "Trace.h"
> #include "URI.h"
> +#include "index/BackgroundIndexLoader.h"
> #include "index/FileIndex.h"
> #include "index/IndexAction.h"
> #include "index/MemIndex.h"
> @@ -28,6 +30,8 @@
> #include "clang/Basic/SourceLocation.h"
> #include "clang/Basic/SourceManager.h"
> #include "clang/Driver/Types.h"
> +#include "llvm/ADT/ArrayRef.h"
> +#include "llvm/ADT/DenseSet.h"
> #include "llvm/ADT/Hashing.h"
> #include "llvm/ADT/STLExtras.h"
> #include "llvm/ADT/ScopeExit.h"
> @@ -42,6 +46,7 @@
> #include 
> #include 
> #include 
> +#include 
> #include 
> #include 
> #include 
> @@ -49,6 +54,8 @@
> #include 
> #include 
> #include 
> +#include 
> +#include 
>
> namespace clang {
> namespace clangd {
> @@ -119,6 +126,18 @@ llvm::SmallString<128> getAbsolutePath(c
>   }
>   return AbsolutePath;
> }
> +
> +bo

[PATCH] D64638: [CrossTU] Fix plist macro expansion if macro in other file.

2019-07-19 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a reviewer: ilya-biryukov.
balazske added a subscriber: ilya-biryukov.
balazske added a comment.

@ilya-biryukov Please check if it is acceptable to use `ASTUnit` in 
PlistDiagnostic.cpp.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64638



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


[PATCH] D64329: [Clangd] Fixed SelectionTree bug for macros

2019-07-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:399
+  // FIXME: SelectionTree needs to be fixed for macros
+  /*{R"cpp(#define LOOP(x) while (1) {a = x;}
  void f(int a) {

can you uncomment this case, and assert the actual behavior? The FIXME should 
say what it should be instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64329



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


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

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



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:208
   const SelectionTree::Node *N = Inputs.ASTSelection.commonAncestor();
-  if (!N)
-return false;
-  Target = llvm::make_unique(N, SM, Ctx);
-  return Target->isExtractable();
+  computeExtractionContext(N, SM, Ctx);
+  return Target && Target->InsertionPoint;

kadircet wrote:
> SureYeaah wrote:
> > kadircet wrote:
> > > maybe instead of checking internals like `Target` just make 
> > > `computeExtractionContext` return an `llvm::Error` and check for success?
> > Should it instead return a bool since there's actually no error?
> Yes that's also plausible
i was trying to say:

having a function named `computeExtractionContext` that will require you to 
check some other state even when it returns true sounds like a bad idea.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:292
+  Target = llvm::make_unique(TargetNode, SM, Ctx);
+  return true;
+}

SureYeaah wrote:
> kadircet wrote:
> > `return Target->InsertionPoint`?
> Changed to checking if target is extractable.
any reasons for not returning `Target->isExtractable()` ?



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:304
   // return statement
-  return ^1;
+  return t.bar]](t.z)]];
 }

kadircet wrote:
> another case on bar ?
> 
> ```
> t.b[[a]]r]](t.z)]]
> ```
i suppose this is done



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:427
R"cpp(void f(int a) {
 auto dummy = 1; label: [ [gsl::suppress("type")] ] for 
(;;) a = dummy;
  })cpp"},

I think `auto dummy = 1;` should be within the label. otherwise we might break 
codes like(which is basically anything with labels):
```
void foo() {
goto label;
label:
 a = 1;
}
```

I don't think it is that important though, and have no idea about the effort 
necessary feel free to just add a FIXME if it turns out hard.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64717



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


[PATCH] D64985: [clangd] Provide a way to publish highlightings in non-racy manner

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

I think this is the right design. As mentioned offline, I think we can now move 
the onDiagnostics call out from TUScheduler into ClangdServer (and remove 
onDiagnostics from the callbacks interface).
This is a better layer because the diagnostics callback model is really about 
how LSP treats diagnostics, and TUScheduler shouldn't have to care much (maybe 
one day this will even live in ClangdLSPServer).




Comment at: clang-tools-extra/clangd/TUScheduler.h:105
+  /// when closing the files.
+  using PublishResults = llvm::function_ref;
+

I'd consider having the typedef be the full `using PublishFn = 
llvm::function_ref)>`

That way the signature of `onMainAST` is simpler, and realistically people are 
going to understand how to call Publish by example.



Comment at: clang-tools-extra/clangd/TUScheduler.h:118
+  ///
+  /// This callback is run on a worker thread and if we need to send results of
+  /// processing AST to the users, we might run into a race condition with file

I think we need to explain the API before apologising for it (explaining why 
it's this shape etc). And I think this is weird enough that an example would 
help.

Something like:
```
When information about the file (diagnostics, syntax highlighting) is published 
to clients,
this should be wrapped in Publish, e.g.
  void onMainAST(...) {
Highlights = computeHighlights();
Publish([&] { notifyHighlights(Path, Highlights); });
  }
This guarantees that clients will see results in the correct sequence if the 
file is concurrently closed
and/or reopened. (The lambda passed to Publish() may never run in this case).
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64985



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


[clang-tools-extra] r366566 - [Clangd] Fixed SelectionTree bug for macros

2019-07-19 Thread Shaurya Gupta via cfe-commits
Author: sureyeaah
Date: Fri Jul 19 04:41:02 2019
New Revision: 366566

URL: http://llvm.org/viewvc/llvm-project?rev=366566&view=rev
Log:
[Clangd] Fixed SelectionTree bug for macros

Summary:
Fixed SelectionTree bug for macros
- Fixed SelectionTree claimRange for macros and template instantiations
- Fixed SelectionTree unit tests
- Changed a breaking test in TweakTests

Reviewers: sammccall, kadircet

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/Selection.cpp
clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp

Modified: clang-tools-extra/trunk/clangd/Selection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Selection.cpp?rev=366566&r1=366565&r2=366566&view=diff
==
--- clang-tools-extra/trunk/clangd/Selection.cpp (original)
+++ clang-tools-extra/trunk/clangd/Selection.cpp Fri Jul 19 04:41:02 2019
@@ -8,10 +8,13 @@
 
 #include "Selection.h"
 #include "ClangdUnit.h"
+#include "SourceCode.h"
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/STLExtras.h"
 #include 
 
@@ -239,26 +242,23 @@ private:
   SelectionTree::Selection claimRange(SourceRange S) {
 if (!S.isValid())
   return SelectionTree::Unselected;
-// getTopMacroCallerLoc() allows selection of constructs in macro args. 
e.g:
+// toHalfOpenFileRange() allows selection of constructs in macro args. e.g:
 //   #define LOOP_FOREVER(Body) for(;;) { Body }
 //   void IncrementLots(int &x) {
 // LOOP_FOREVER( ++x; )
 //   }
 // Selecting "++x" or "x" will do the right thing.
-auto B = SM.getDecomposedLoc(SM.getTopMacroCallerLoc(S.getBegin()));
-auto E = SM.getDecomposedLoc(SM.getTopMacroCallerLoc(S.getEnd()));
+auto Range = toHalfOpenFileRange(SM, LangOpts, S);
+assert(Range && "We should be able to get the File Range");
+auto B = SM.getDecomposedLoc(Range->getBegin());
+auto E = SM.getDecomposedLoc(Range->getEnd());
 // Otherwise, nodes in macro expansions can't be selected.
 if (B.first != SelFile || E.first != SelFile)
   return SelectionTree::Unselected;
-// Cheap test: is there any overlap at all between the selection and range?
-// Note that E.second is the *start* of the last token, which is why we
-// compare against the "rounded-down" SelBegin.
-if (B.second >= SelEnd || E.second < SelBeginTokenStart)
+// Is there any overlap at all between the selection and range?
+if (B.second >= SelEnd || E.second < SelBegin)
   return SelectionTree::Unselected;
-
-// We may have hit something, need some more precise checks.
-// Adjust [B, E) to be a half-open character range.
-E.second += Lexer::MeasureTokenLength(S.getEnd(), SM, LangOpts);
+// We may have hit something.
 auto PreciseBounds = std::make_pair(B.second, E.second);
 // Trim range using the selection, drop it if empty.
 B.second = std::max(B.second, SelBegin);

Modified: clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp?rev=366566&r1=366565&r2=366566&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp Fri Jul 19 
04:41:02 2019
@@ -37,15 +37,15 @@ SelectionTree makeSelectionTree(const St
 Range nodeRange(const SelectionTree::Node *N, ParsedAST &AST) {
   if (!N)
 return Range{};
-  SourceManager &SM = AST.getSourceManager();
+  const SourceManager &SM = AST.getSourceManager();
+  const LangOptions &LangOpts = AST.getASTContext().getLangOpts();
   StringRef Buffer = SM.getBufferData(SM.getMainFileID());
-  SourceRange SR = N->ASTNode.getSourceRange();
-  SR.setBegin(SM.getFileLoc(SR.getBegin()));
-  SR.setEnd(SM.getFileLoc(SR.getEnd()));
-  CharSourceRange R =
-  Lexer::getAsCharRange(SR, SM, AST.getASTContext().getLangOpts());
-  return Range{offsetToPosition(Buffer, SM.getFileOffset(R.getBegin())),
-   offsetToPosition(Buffer, SM.getFileOffset(R.getEnd()))};
+  auto FileRange =
+  toHalfOpenFileRange(SM, LangOpts, N->ASTNode.getSourceRange());
+  assert(FileRange && "We should be able to get the File Range");
+  return Range{
+  offsetToPosition(Buffer, SM.getFileOffset(FileRange->getBegin())),
+  offsetToPosition(Buffer, SM.getFileOffset(FileRange->getEnd()))};
 }
 
 std::string nodeKind(const SelectionTree::Node *N) {
@@ -144,17 +144,17 @@ TEST(Select

[PATCH] D64329: [Clangd] Fixed SelectionTree bug for macros

2019-07-19 Thread Shaurya Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366566: [Clangd] Fixed SelectionTree bug for macros 
(authored by SureYeaah, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64329?vs=210783&id=210799#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64329

Files:
  clang-tools-extra/trunk/clangd/Selection.cpp
  clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
  clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/trunk/clangd/Selection.cpp
===
--- clang-tools-extra/trunk/clangd/Selection.cpp
+++ clang-tools-extra/trunk/clangd/Selection.cpp
@@ -8,10 +8,13 @@
 
 #include "Selection.h"
 #include "ClangdUnit.h"
+#include "SourceCode.h"
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/STLExtras.h"
 #include 
 
@@ -239,26 +242,23 @@
   SelectionTree::Selection claimRange(SourceRange S) {
 if (!S.isValid())
   return SelectionTree::Unselected;
-// getTopMacroCallerLoc() allows selection of constructs in macro args. e.g:
+// toHalfOpenFileRange() allows selection of constructs in macro args. e.g:
 //   #define LOOP_FOREVER(Body) for(;;) { Body }
 //   void IncrementLots(int &x) {
 // LOOP_FOREVER( ++x; )
 //   }
 // Selecting "++x" or "x" will do the right thing.
-auto B = SM.getDecomposedLoc(SM.getTopMacroCallerLoc(S.getBegin()));
-auto E = SM.getDecomposedLoc(SM.getTopMacroCallerLoc(S.getEnd()));
+auto Range = toHalfOpenFileRange(SM, LangOpts, S);
+assert(Range && "We should be able to get the File Range");
+auto B = SM.getDecomposedLoc(Range->getBegin());
+auto E = SM.getDecomposedLoc(Range->getEnd());
 // Otherwise, nodes in macro expansions can't be selected.
 if (B.first != SelFile || E.first != SelFile)
   return SelectionTree::Unselected;
-// Cheap test: is there any overlap at all between the selection and range?
-// Note that E.second is the *start* of the last token, which is why we
-// compare against the "rounded-down" SelBegin.
-if (B.second >= SelEnd || E.second < SelBeginTokenStart)
+// Is there any overlap at all between the selection and range?
+if (B.second >= SelEnd || E.second < SelBegin)
   return SelectionTree::Unselected;
-
-// We may have hit something, need some more precise checks.
-// Adjust [B, E) to be a half-open character range.
-E.second += Lexer::MeasureTokenLength(S.getEnd(), SM, LangOpts);
+// We may have hit something.
 auto PreciseBounds = std::make_pair(B.second, E.second);
 // Trim range using the selection, drop it if empty.
 B.second = std::max(B.second, SelBegin);
Index: clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
@@ -37,15 +37,15 @@
 Range nodeRange(const SelectionTree::Node *N, ParsedAST &AST) {
   if (!N)
 return Range{};
-  SourceManager &SM = AST.getSourceManager();
+  const SourceManager &SM = AST.getSourceManager();
+  const LangOptions &LangOpts = AST.getASTContext().getLangOpts();
   StringRef Buffer = SM.getBufferData(SM.getMainFileID());
-  SourceRange SR = N->ASTNode.getSourceRange();
-  SR.setBegin(SM.getFileLoc(SR.getBegin()));
-  SR.setEnd(SM.getFileLoc(SR.getEnd()));
-  CharSourceRange R =
-  Lexer::getAsCharRange(SR, SM, AST.getASTContext().getLangOpts());
-  return Range{offsetToPosition(Buffer, SM.getFileOffset(R.getBegin())),
-   offsetToPosition(Buffer, SM.getFileOffset(R.getEnd()))};
+  auto FileRange =
+  toHalfOpenFileRange(SM, LangOpts, N->ASTNode.getSourceRange());
+  assert(FileRange && "We should be able to get the File Range");
+  return Range{
+  offsetToPosition(Buffer, SM.getFileOffset(FileRange->getBegin())),
+  offsetToPosition(Buffer, SM.getFileOffset(FileRange->getEnd()))};
 }
 
 std::string nodeKind(const SelectionTree::Node *N) {
@@ -144,17 +144,17 @@
   R"cpp(
 void foo();
 #define CALL_FUNCTION(X) X()
-void bar() [[{ CALL_FUNC^TION(fo^o); }]]
+void bar() { [[CALL_FUNC^TION(fo^o)]]; }
   )cpp",
-  "CompoundStmt",
+  "CallExpr",
   },
   {
   R"cpp(
 void foo();
 #define CALL_FUNCTION(X) X()
-void bar() [[{ C^ALL_FUNC^TION(foo); }]]
+void bar() { [[C^ALL_FUNC^TION(foo)]]; }
   )cpp",
-  "CompoundStmt",
+

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

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

Minor changes and disabled extraction from label statement


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64717

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

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -291,18 +291,23 @@
   const char *Input = "struct ^X { int x; int y; }";
   EXPECT_THAT(getMessage(ID, Input), ::testing::HasSubstr("0 |   int x"));
 }
+
 TEST(TweakTest, ExtractVariable) {
   llvm::StringLiteral ID = "ExtractVariable";
   checkAvailable(ID, R"cpp(
-int xyz() {
+int xyz(int a = 1) {
+  struct T {
+int bar(int a = 1);
+int z;
+  } t;
   // return statement
-  return [[1]];
+  return t.b[[a]]r]](t.z)]];
 }
 void f() {
   int a = [[5 +]] [[4 * xyz]]();
   // multivariable initialization
   if(1)
-int x = [[1]], y = [[a]] + 1, a = [[1]], z = a + 1;
+int x = [[1]], y = [[a + 1]], a = [[1]], z = a + 1;
   // if without else
   if([[1]])
 a = [[1]];
@@ -316,13 +321,13 @@
 a = [[4]];
   else
 a = [[5]];
-  // for loop 
+  // for loop
   for(a = [[1]]; a > 3]] + [[4; a++)
 a = [[2]];
-  // while 
+  // while
   while(a < [[1]])
-[[a]]++;
-  // do while 
+[[a++]];
+  // do while
   do
 a = [[1]];
   while(a < [[3]]);
@@ -332,18 +337,19 @@
   checkNotAvailable(ID, R"cpp(
 template
 struct Test {
-Test(const T &v) :val(^) {}
+Test(const T &v) :val[[(^]]) {}
   T val;
 };
   )cpp");
   checkNotAvailable(ID, R"cpp(
 int xyz(int a = [[1]]) {
-  return 1;
-  class T {
-T(int a = [[1]]) {};
-int xyz = [[1]];
-  };
+  struct T {
+int bar(int a = [[1]]);
+int z = [[1]];
+  } t;
+  return [[t]].bar(t]].z]]);
 }
+void v() { return; }
 // function default argument
 void f(int b = [[1]]) {
   // empty selection
@@ -351,17 +357,22 @@
   // void expressions
   auto i = new int, j = new int;
   delete i]], delete j]];
+  [[v]]();
   // if
   if(1)
 int x = 1, y = a + 1, a = 1, z = [[a + 1]];
   if(int a = 1)
-if([[a]] == 4)
+if([[a + 1]] == 4)
   a = a]] +]] 1;
-  // for loop 
-  for(int a = 1, b = 2, c = 3; [[a]] > [[b + c]]; [[a]]++)
+  // for loop
+  for(int a = 1, b = 2, c = 3; a > [[b + c]]; [[a++]])
 a = [[a + 1]];
-  // lambda 
+  // lambda
   auto lamb = [&[[a]], &[[b]]](int r = [[1]]) {return 1;}
+  // assigment
+  [[a = 5]];
+  // Variable DeclRefExpr
+  a = [[b]];
 }
   )cpp");
   // vector of pairs of input and output strings
@@ -408,12 +419,30 @@
auto dummy = 3; if(1)
 LOOP(5 + dummy)
  })cpp"},
-  // label and attribute testing
+  // attribute testing
   {R"cpp(void f(int a) {
-label: [ [gsl::suppress("type")] ] for (;;) a = [[1]];
+[ [gsl::suppress("type")] ] for (;;) a = [[1]];
  })cpp",
R"cpp(void f(int a) {
-auto dummy = 1; label: [ [gsl::suppress("type")] ] for (;;) a = dummy;
+auto dummy = 1; [ [gsl::suppress("type")] ] for (;;) a = dummy;
+ })cpp"},
+  // MemberExpr
+  {R"cpp(class T {
+   T f() {
+ return [[T().f()]].f();
+   }
+ };)cpp",
+   R"cpp(class T {
+   T f() {
+ auto dummy = T().f(); return dummy.f();
+   }
+ };)cpp"},
+  // Function DeclRefExpr
+  {R"cpp(int f() {
+   return [[f]]();
+ })cpp",
+   R"cpp(int f() {
+   auto dummy = f(); return dummy;
  })cpp"},
   // FIXME: Doesn't work because bug in selection tree
   /*{R"cpp(#define PLUS(x) x++
@@ -424,9 +453,9 @@
  void f(int a) {
auto dummy = a; PLUS(dummy);
  })cpp"},*/
-  // FIXME: Doesn't work correctly for \[\[clang::uninitialized\]\] int
-  // b = [[1]]; since the attr is inside the DeclStmt and the bounds of
-  // DeclStmt don't cover the attribute
+  // FIXME: Wrong result for \[\[clang::uninitialized\]\] int b = [[1]];
+  // since the attr is inside the DeclStmt and the bounds

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

2019-07-19 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, LGTM from my side. Do you have any concerns @sammccall ?




Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:427
R"cpp(void f(int a) {
 auto dummy = 1; label: [ [gsl::suppress("type")] ] for 
(;;) a = dummy;
  })cpp"},

kadircet wrote:
> I think `auto dummy = 1;` should be within the label. otherwise we might 
> break codes like(which is basically anything with labels):
> ```
> void foo() {
> goto label;
> label:
>  a = 1;
> }
> ```
> 
> I don't think it is that important though, and have no idea about the effort 
> necessary feel free to just add a FIXME if it turns out hard.
could you keep the previous test case within a `checkNotAvailable` block ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64717



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


[PATCH] D64775: [Format/ObjC] Avoid breaking between unary operators and ObjC method invocations

2019-07-19 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.

Yeah, worst case we'll need to roll this back and go with the targeted fix, but 
I don't see a problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64775



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


[PATCH] D64416: [AArch64] Add support for Transactional Memory Extension (TME)

2019-07-19 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover added inline comments.



Comment at: clang/test/Sema/aarch64-tme-errors.c:1
+// RUN: %clang_cc1 -triple aarch64-eabi -verify %s
+

I don't think the Sema checks need to be split over so many files. One for the 
whole of transactional seems enough. Similarly for CodeGen really.



Comment at: llvm/test/CodeGen/AArch64/tme-tcancel.ll:6
+define void @test_tcancel() #0 {
+  tail call void @llvm.aarch64.tcancel(i64 0) #1
+  ret void

Testing more values than 0 would be a good idea.


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

https://reviews.llvm.org/D64416



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


[PATCH] D64914: Implement P1771

2019-07-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2346
+// spellings.
+bool IsCXX11NoDiscard() const {
+  return this->getSemanticSpelling() == CXX11_nodiscard;

I don't think this is strictly required, but perhaps it's not a bad idea.



Comment at: clang/include/clang/Basic/AttrDocs.td:1499
+marked with ``[[nodiscard]]`` or a constructor of a type marked
+``[[nodiscard]]`` will also diagnose.
+

We should probably also talk about type conversions as well.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:2833-2835
   if (D->getFunctionType() &&
-  D->getFunctionType()->getReturnType()->isVoidType()) {
+  D->getFunctionType()->getReturnType()->isVoidType() &&
+  !isa(D)) {

erichkeane wrote:
> aaron.ballman wrote:
> > I'm not certain about this -- we do not allow you to put 
> > `__attribute__((warn_unused_result))` on a constructor declaration, and 
> > neither does GCC. Do you know if they're planning to change their behavior 
> > as well? https://godbolt.org/z/kDZu3Q
> I'm unsure about GCC's intent, though they will likely be changing the 
> [[nodiscard]] behavior due to the vote (and I doubt they will have an "if 
> C++20" test either.  
> 
> Do we have a good way to exclude the alternate spellings?  isCXX11Attribute 
> only checks syntax, not the actual spelling.  ParsedAttr doesn't seem to even 
> contain a way to get which namespace it is associated with either.  Is 
> something like that valuable to add?
The way we currently do this is `(isCXX11Attribute() || isC2xAttribute()) && 
!getScopeName()`, but I am not opposed to going with an additional member. Do 
you have a preference either way?



Comment at: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp:69
+[[gnu::warn_unused_result]] S(double);
+  };
+

I think this also needs tests for type conversions, from d1771r1.



Comment at: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp:87-88
 // expected-warning@28 {{use of the 'nodiscard' attribute is a C++17 
extension}}
+// expected-warning@66 {{use of the 'nodiscard' attribute is a C++17 
extension}}
+// expected-warning@71 {{use of the 'nodiscard' attribute is a C++17 
extension}}
 #endif

Is Core treating this paper as a DR? I don't have a strong opinion here, but 
for the nodiscard with a message version, I made it a C++2a extension. I don't 
have a strong opinion, but I sort of prefer doing whatever Core decides.


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

https://reviews.llvm.org/D64914



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


[clang-tools-extra] r366568 - [Clangd] Fixed ExtractVariable test

2019-07-19 Thread Shaurya Gupta via cfe-commits
Author: sureyeaah
Date: Fri Jul 19 05:11:04 2019
New Revision: 366568

URL: http://llvm.org/viewvc/llvm-project?rev=366568&view=rev
Log:
[Clangd] Fixed ExtractVariable test

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

Modified: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp?rev=366568&r1=366567&r2=366568&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp Fri Jul 19 05:11:04 
2019
@@ -398,17 +398,23 @@ TEST(TweakTest, ExtractVariable) {
}
  })cpp"},*/
   // ensure InsertionPoint isn't inside a macro
-  // FIXME: SelectionTree needs to be fixed for macros
-  /*{R"cpp(#define LOOP(x) while (1) {a = x;}
+  {R"cpp(#define LOOP(x) while (1) {a = x;}
  void f(int a) {
if(1)
 LOOP(5 + [[3]])
  })cpp",
- R"cpp(#define LOOP(x) while (1) {a = x;}
+   /*FIXME: It should be extracted like this. SelectionTree needs to be
+* fixed for macros.
+ R"cpp(#define LOOP(x) while (1) {a = x;}
+   void f(int a) {
+ auto dummy = 3; if(1)
+  LOOP(5 + dummy)
+   })cpp"},*/
+   R"cpp(#define LOOP(x) while (1) {a = x;}
  void f(int a) {
-   auto dummy = 3; if(1)
-LOOP(5 + dummy)
- })cpp"},*/
+   auto dummy = LOOP(5 + 3); if(1)
+dummy
+ })cpp"},
   {R"cpp(#define LOOP(x) do {x;} while(1);
  void f(int a) {
if(1)
@@ -426,15 +432,15 @@ TEST(TweakTest, ExtractVariable) {
R"cpp(void f(int a) {
 auto dummy = 1; label: [ [gsl::suppress("type")] ] for 
(;;) a = dummy;
  })cpp"},
-  // FIXME: Doesn't work because bug in selection tree
-  /*{R"cpp(#define PLUS(x) x++
+  // macro testing
+  {R"cpp(#define PLUS(x) x++
  void f(int a) {
PLUS([[a]]);
  })cpp",
R"cpp(#define PLUS(x) x++
  void f(int a) {
auto dummy = a; PLUS(dummy);
- })cpp"},*/
+ })cpp"},
   // FIXME: Doesn't work correctly for \[\[clang::uninitialized\]\] int
   // b = [[1]]; since the attr is inside the DeclStmt and the bounds of
   // DeclStmt don't cover the attribute


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


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

2019-07-19 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 210803.
SureYeaah marked an inline comment as done.
SureYeaah added a comment.

Added test for label


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64717

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

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -291,18 +291,23 @@
   const char *Input = "struct ^X { int x; int y; }";
   EXPECT_THAT(getMessage(ID, Input), ::testing::HasSubstr("0 |   int x"));
 }
+
 TEST(TweakTest, ExtractVariable) {
   llvm::StringLiteral ID = "ExtractVariable";
   checkAvailable(ID, R"cpp(
-int xyz() {
+int xyz(int a = 1) {
+  struct T {
+int bar(int a = 1);
+int z;
+  } t;
   // return statement
-  return [[1]];
+  return t.b[[a]]r]](t.z)]];
 }
 void f() {
   int a = [[5 +]] [[4 * xyz]]();
   // multivariable initialization
   if(1)
-int x = [[1]], y = [[a]] + 1, a = [[1]], z = a + 1;
+int x = [[1]], y = [[a + 1]], a = [[1]], z = a + 1;
   // if without else
   if([[1]])
 a = [[1]];
@@ -316,13 +321,13 @@
 a = [[4]];
   else
 a = [[5]];
-  // for loop 
+  // for loop
   for(a = [[1]]; a > 3]] + [[4; a++)
 a = [[2]];
-  // while 
+  // while
   while(a < [[1]])
-[[a]]++;
-  // do while 
+[[a++]];
+  // do while
   do
 a = [[1]];
   while(a < [[3]]);
@@ -332,18 +337,19 @@
   checkNotAvailable(ID, R"cpp(
 template
 struct Test {
-Test(const T &v) :val(^) {}
+Test(const T &v) :val[[(^]]) {}
   T val;
 };
   )cpp");
   checkNotAvailable(ID, R"cpp(
 int xyz(int a = [[1]]) {
-  return 1;
-  class T {
-T(int a = [[1]]) {};
-int xyz = [[1]];
-  };
+  struct T {
+int bar(int a = [[1]]);
+int z = [[1]];
+  } t;
+  return [[t]].bar(t]].z]]);
 }
+void v() { return; }
 // function default argument
 void f(int b = [[1]]) {
   // empty selection
@@ -351,17 +357,26 @@
   // void expressions
   auto i = new int, j = new int;
   delete i]], delete j]];
+  [[v]]();
   // if
   if(1)
 int x = 1, y = a + 1, a = 1, z = [[a + 1]];
   if(int a = 1)
-if([[a]] == 4)
+if([[a + 1]] == 4)
   a = a]] +]] 1;
-  // for loop 
-  for(int a = 1, b = 2, c = 3; [[a]] > [[b + c]]; [[a]]++)
+  // for loop
+  for(int a = 1, b = 2, c = 3; a > [[b + c]]; [[a++]])
 a = [[a + 1]];
-  // lambda 
+  // lambda
   auto lamb = [&[[a]], &[[b]]](int r = [[1]]) {return 1;}
+  // assigment
+  [[a = 5]];
+  // Variable DeclRefExpr
+  a = [[b]];
+  // label statement
+  goto label;
+  label:
+a = [[1]];
 }
   )cpp");
   // vector of pairs of input and output strings
@@ -408,12 +423,30 @@
auto dummy = 3; if(1)
 LOOP(5 + dummy)
  })cpp"},
-  // label and attribute testing
+  // attribute testing
   {R"cpp(void f(int a) {
-label: [ [gsl::suppress("type")] ] for (;;) a = [[1]];
+[ [gsl::suppress("type")] ] for (;;) a = [[1]];
  })cpp",
R"cpp(void f(int a) {
-auto dummy = 1; label: [ [gsl::suppress("type")] ] for (;;) a = dummy;
+auto dummy = 1; [ [gsl::suppress("type")] ] for (;;) a = dummy;
+ })cpp"},
+  // MemberExpr
+  {R"cpp(class T {
+   T f() {
+ return [[T().f()]].f();
+   }
+ };)cpp",
+   R"cpp(class T {
+   T f() {
+ auto dummy = T().f(); return dummy.f();
+   }
+ };)cpp"},
+  // Function DeclRefExpr
+  {R"cpp(int f() {
+   return [[f]]();
+ })cpp",
+   R"cpp(int f() {
+   auto dummy = f(); return dummy;
  })cpp"},
   // FIXME: Doesn't work because bug in selection tree
   /*{R"cpp(#define PLUS(x) x++
@@ -424,9 +457,9 @@
  void f(int a) {
auto dummy = a; PLUS(dummy);
  })cpp"},*/
-  // FIXME: Doesn't work correctly for \[\[clang::uninitialized\]\] int
-  // b = [[1]]; since the attr is inside the DeclStmt and the bounds of
-  // DeclStmt don't cover the attribute
+  // FIXME: Wrong result for \[\[clang::uninitialized\]\] int b = [[1]];
+  // since the a

[PATCH] D64914: Implement P1771

2019-07-19 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 2 inline comments as done.
erichkeane added a comment.

I'll need to rebase this on another patch soon anyway, so I'll hold off until 
next week to update this particularly since we have some open questions.  The 
additional TableGen work is tempting to do, though I'm not completely sure 
it'll get more than just this use.

I'd also like to see how this paper goes through CWG and see what the general 
attitude is there.




Comment at: clang/lib/Sema/SemaDeclAttr.cpp:2833-2835
   if (D->getFunctionType() &&
-  D->getFunctionType()->getReturnType()->isVoidType()) {
+  D->getFunctionType()->getReturnType()->isVoidType() &&
+  !isa(D)) {

aaron.ballman wrote:
> erichkeane wrote:
> > aaron.ballman wrote:
> > > I'm not certain about this -- we do not allow you to put 
> > > `__attribute__((warn_unused_result))` on a constructor declaration, and 
> > > neither does GCC. Do you know if they're planning to change their 
> > > behavior as well? https://godbolt.org/z/kDZu3Q
> > I'm unsure about GCC's intent, though they will likely be changing the 
> > [[nodiscard]] behavior due to the vote (and I doubt they will have an "if 
> > C++20" test either.  
> > 
> > Do we have a good way to exclude the alternate spellings?  isCXX11Attribute 
> > only checks syntax, not the actual spelling.  ParsedAttr doesn't seem to 
> > even contain a way to get which namespace it is associated with either.  Is 
> > something like that valuable to add?
> The way we currently do this is `(isCXX11Attribute() || isC2xAttribute()) && 
> !getScopeName()`, but I am not opposed to going with an additional member. Do 
> you have a preference either way?
An additional member of Spelling-Kind (vs Syntax kind) seems very valuable 
here, though I wonder if it is valuable enough of a change for TableGen.  The 
isCXX11Attribute && !getScopeName seems a little obtuse from a readers 
perspective.



Comment at: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp:87-88
 // expected-warning@28 {{use of the 'nodiscard' attribute is a C++17 
extension}}
+// expected-warning@66 {{use of the 'nodiscard' attribute is a C++17 
extension}}
+// expected-warning@71 {{use of the 'nodiscard' attribute is a C++17 
extension}}
 #endif

aaron.ballman wrote:
> Is Core treating this paper as a DR? I don't have a strong opinion here, but 
> for the nodiscard with a message version, I made it a C++2a extension. I 
> don't have a strong opinion, but I sort of prefer doing whatever Core decides.
I am unfamiliar with what Core is treating it as, but my understanding is that 
EWG encouraged implementers to treat it as such.  


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

https://reviews.llvm.org/D64914



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


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

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



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:427
R"cpp(void f(int a) {
 auto dummy = 1; label: [ [gsl::suppress("type")] ] for 
(;;) a = dummy;
  })cpp"},

kadircet wrote:
> I think `auto dummy = 1;` should be within the label. otherwise we might 
> break codes like(which is basically anything with labels):
> ```
> void foo() {
> goto label;
> label:
>  a = 1;
> }
> ```
> 
> I don't think it is that important though, and have no idea about the effort 
> necessary feel free to just add a FIXME if it turns out hard.
I've disabled extraction from label statements and added a fixme because the 
fix for all kinds of loops as well as if statement needs another patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64717



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


[PATCH] D64985: [clangd] Provide a way to publish highlightings in non-racy manner

2019-07-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 210805.
ilya-biryukov added a comment.

- Use the same mechanism for diagnostics
- Change typedef to function)>
- Update a comment
- s/PublishResults/PublishFn
- Reformat


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64985

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  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
@@ -7,10 +7,14 @@
 //===--===//
 
 #include "Annotations.h"
+#include "ClangdUnit.h"
 #include "Context.h"
+#include "Diagnostics.h"
 #include "Matchers.h"
+#include "Path.h"
 #include "TUScheduler.h"
 #include "TestFS.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -56,12 +60,17 @@
   /// in updateWithDiags.
   static std::unique_ptr captureDiags() {
 class CaptureDiags : public ParsingCallbacks {
-  void onDiagnostics(PathRef File, std::vector Diags) override {
+  void onMainAST(PathRef File, ParsedAST &AST, PublishFn Publish) override {
+auto Diags = AST.getDiagnostics();
 auto D = Context::current().get(DiagsCallbackKey);
 if (!D)
   return;
-const_cast)> &> (
-*D)(File, Diags);
+
+Publish([&]() {
+  const_cast<
+  llvm::unique_function)> &> (*D)(
+  File, std::move(Diags));
+});
   }
 };
 return llvm::make_unique();
@@ -116,8 +125,8 @@
   S.update(Added, getInputs(Added, "x"), WantDiagnostics::No);
   EXPECT_EQ(S.getContents(Added), "x");
 
-  // Assert each operation for missing file is an error (even if it's available
-  // in VFS).
+  // Assert each operation for missing file is an error (even if it's
+  // available in VFS).
   S.runWithAST("", Missing,
[&](Expected AST) { EXPECT_ERROR(AST); });
   S.runWithPreamble(
@@ -367,8 +376,8 @@
 StringRef AllContents[] = {Contents1, Contents2, Contents3};
 const int AllContentsSize = 3;
 
-// Scheduler may run tasks asynchronously, but should propagate the context.
-// We stash a nonce in the context, and verify it in the task.
+// Scheduler may run tasks asynchronously, but should propagate the
+// context. We stash a nonce in the context, and verify it in the task.
 static Key NonceKey;
 int Nonce = 0;
 
@@ -465,8 +474,8 @@
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   ASSERT_EQ(BuiltASTCounter.load(), 1);
 
-  // Build two more files. Since we can retain only 2 ASTs, these should be the
-  // ones we see in the cache later.
+  // Build two more files. Since we can retain only 2 ASTs, these should be
+  // the ones we see in the cache later.
   updateWithCallback(S, Bar, SourceContents, WantDiagnostics::Yes,
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
   updateWithCallback(S, Baz, SourceContents, WantDiagnostics::Yes,
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -15,6 +15,7 @@
 #include "Threading.h"
 #include "index/CanonicalIncludes.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -98,6 +99,10 @@
   virtual void onPreambleAST(PathRef Path, ASTContext &Ctx,
  std::shared_ptr PP,
  const CanonicalIncludes &) {}
+  /// The argument function is run under the critical section guarding against
+  /// races when closing the files.
+  using PublishFn = llvm::function_ref)>;
+
   /// Called on the AST built for the file itself. Note that preamble AST nodes
   /// are not deserialized and should be processed in the onPreambleAST call
   /// instead.
@@ -108,10 +113,17 @@
   /// etc. Clients are expected to process only the AST nodes from the main file
   /// in this callback (obtained via ParsedAST::getLocalTopLevelDecls) to obtain
   /// optimal performance.
-  virtual void onMainAST(PathRef Path, ParsedAST &AST) {}
-
-  /// Called whenever the diagnostics for \p File are produced.
-  virtual void onDiagnostics(PathRef File, std::vector Diags) {}
+  ///
+  /// When information about the file (diagnostics, syntax highlighting) is
+  /// published to clients, this should be wrapped in Publish, e.g.
+  ///   void onMainAST(...) {
+  /// Highlights = computeHighlights();
+  /// Publish([&] { notifyHighlights(Path, Highli

[PATCH] D64914: Implement P1771

2019-07-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:2833-2835
   if (D->getFunctionType() &&
-  D->getFunctionType()->getReturnType()->isVoidType()) {
+  D->getFunctionType()->getReturnType()->isVoidType() &&
+  !isa(D)) {

erichkeane wrote:
> aaron.ballman wrote:
> > erichkeane wrote:
> > > aaron.ballman wrote:
> > > > I'm not certain about this -- we do not allow you to put 
> > > > `__attribute__((warn_unused_result))` on a constructor declaration, and 
> > > > neither does GCC. Do you know if they're planning to change their 
> > > > behavior as well? https://godbolt.org/z/kDZu3Q
> > > I'm unsure about GCC's intent, though they will likely be changing the 
> > > [[nodiscard]] behavior due to the vote (and I doubt they will have an "if 
> > > C++20" test either.  
> > > 
> > > Do we have a good way to exclude the alternate spellings?  
> > > isCXX11Attribute only checks syntax, not the actual spelling.  ParsedAttr 
> > > doesn't seem to even contain a way to get which namespace it is 
> > > associated with either.  Is something like that valuable to add?
> > The way we currently do this is `(isCXX11Attribute() || isC2xAttribute()) 
> > && !getScopeName()`, but I am not opposed to going with an additional 
> > member. Do you have a preference either way?
> An additional member of Spelling-Kind (vs Syntax kind) seems very valuable 
> here, though I wonder if it is valuable enough of a change for TableGen.  The 
> isCXX11Attribute && !getScopeName seems a little obtuse from a readers 
> perspective.
Yeah, I would love to solve this through the tablegen interface at some point, 
as that solves other problems we have (like the fact that we don't AST dump 
with the syntax the user wrote). Let's hold off on that for now and use the 
obtuse approach, but with a FIXME for us to come back and touch it again once 
we get tablegen to track more syntactic information along with the semantic 
attribute object.



Comment at: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp:87-88
 // expected-warning@28 {{use of the 'nodiscard' attribute is a C++17 
extension}}
+// expected-warning@66 {{use of the 'nodiscard' attribute is a C++17 
extension}}
+// expected-warning@71 {{use of the 'nodiscard' attribute is a C++17 
extension}}
 #endif

erichkeane wrote:
> aaron.ballman wrote:
> > Is Core treating this paper as a DR? I don't have a strong opinion here, 
> > but for the nodiscard with a message version, I made it a C++2a extension. 
> > I don't have a strong opinion, but I sort of prefer doing whatever Core 
> > decides.
> I am unfamiliar with what Core is treating it as, but my understanding is 
> that EWG encouraged implementers to treat it as such.  
We expose the attribute in all its glory in all language modes, so these 
changes already do what we want in effect. The only real question is whether we 
want to claim it's a C++17 extension or a C++2a extension. If a user turns on 
extension warnings, we should probably tell them when the feature was added, 
which is C++2a. It would be a bit weird to claim this is a C++17 when the 
feature test for it is `__has_attribute(nodiscard) == 201907L` (due to the 
normative wording changes).

But if Core moves it as a DR, then C++17 is fine, though I suppose SD-6 would 
need to make clear what is required for each given attribute feature test value 
to give us the answer.


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

https://reviews.llvm.org/D64914



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


[PATCH] D60456: [RISCV] Hard float ABI support

2019-07-19 Thread Alex Bradbury via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366450: [RISCV] Hard float ABI support (authored by asb, 
committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60456?vs=208477&id=210586#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60456

Files:
  cfe/trunk/lib/Basic/Targets/RISCV.cpp
  cfe/trunk/lib/Basic/Targets/RISCV.h
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/test/CodeGen/riscv32-ilp32-ilp32f-abi.c
  cfe/trunk/test/CodeGen/riscv32-ilp32-ilp32f-ilp32d-abi.c
  cfe/trunk/test/CodeGen/riscv32-ilp32d-abi.c
  cfe/trunk/test/CodeGen/riscv32-ilp32f-abi.c
  cfe/trunk/test/CodeGen/riscv32-ilp32f-ilp32d-abi.c
  cfe/trunk/test/CodeGen/riscv64-lp64-lp64f-abi.c
  cfe/trunk/test/CodeGen/riscv64-lp64-lp64f-lp64d-abi.c
  cfe/trunk/test/CodeGen/riscv64-lp64d-abi.c
  cfe/trunk/test/CodeGen/riscv64-lp64f-lp64d-abi.c
  cfe/trunk/test/Preprocessor/riscv-target-features.c

Index: cfe/trunk/lib/CodeGen/TargetInfo.cpp
===
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp
@@ -9188,25 +9188,44 @@
 namespace {
 class RISCVABIInfo : public DefaultABIInfo {
 private:
-  unsigned XLen; // Size of the integer ('x') registers in bits.
+  // Size of the integer ('x') registers in bits.
+  unsigned XLen;
+  // Size of the floating point ('f') registers in bits. Note that the target
+  // ISA might have a wider FLen than the selected ABI (e.g. an RV32IF target
+  // with soft float ABI has FLen==0).
+  unsigned FLen;
   static const int NumArgGPRs = 8;
+  static const int NumArgFPRs = 8;
+  bool detectFPCCEligibleStructHelper(QualType Ty, CharUnits CurOff,
+  llvm::Type *&Field1Ty,
+  CharUnits &Field1Off,
+  llvm::Type *&Field2Ty,
+  CharUnits &Field2Off) const;
 
 public:
-  RISCVABIInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen)
-  : DefaultABIInfo(CGT), XLen(XLen) {}
+  RISCVABIInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen, unsigned FLen)
+  : DefaultABIInfo(CGT), XLen(XLen), FLen(FLen) {}
 
   // DefaultABIInfo's classifyReturnType and classifyArgumentType are
   // non-virtual, but computeInfo is virtual, so we overload it.
   void computeInfo(CGFunctionInfo &FI) const override;
 
-  ABIArgInfo classifyArgumentType(QualType Ty, bool IsFixed,
-  int &ArgGPRsLeft) const;
+  ABIArgInfo classifyArgumentType(QualType Ty, bool IsFixed, int &ArgGPRsLeft,
+  int &ArgFPRsLeft) const;
   ABIArgInfo classifyReturnType(QualType RetTy) const;
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override;
 
   ABIArgInfo extendType(QualType Ty) const;
+
+  bool detectFPCCEligibleStruct(QualType Ty, llvm::Type *&Field1Ty, CharUnits &Field1Off,
+llvm::Type *&Field2Ty, CharUnits &Field2Off,
+int &NeededArgGPRs, int &NeededArgFPRs) const;
+  ABIArgInfo coerceAndExpandFPCCEligibleStruct(llvm::Type *Field1Ty,
+   CharUnits Field1Off,
+   llvm::Type *Field2Ty,
+   CharUnits Field2Off) const;
 };
 } // end anonymous namespace
 
@@ -9228,18 +9247,214 @@
   // different for variadic arguments, we must also track whether we are
   // examining a vararg or not.
   int ArgGPRsLeft = IsRetIndirect ? NumArgGPRs - 1 : NumArgGPRs;
+  int ArgFPRsLeft = FLen ? NumArgFPRs : 0;
   int NumFixedArgs = FI.getNumRequiredArgs();
 
   int ArgNum = 0;
   for (auto &ArgInfo : FI.arguments()) {
 bool IsFixed = ArgNum < NumFixedArgs;
-ArgInfo.info = classifyArgumentType(ArgInfo.type, IsFixed, ArgGPRsLeft);
+ArgInfo.info =
+classifyArgumentType(ArgInfo.type, IsFixed, ArgGPRsLeft, ArgFPRsLeft);
 ArgNum++;
   }
 }
 
+// Returns true if the struct is a potential candidate for the floating point
+// calling convention. If this function returns true, the caller is
+// responsible for checking that if there is only a single field then that
+// field is a float.
+bool RISCVABIInfo::detectFPCCEligibleStructHelper(QualType Ty, CharUnits CurOff,
+  llvm::Type *&Field1Ty,
+  CharUnits &Field1Off,
+  llvm::Type *&Field2Ty,
+  CharUnits &Field2Off) const {
+  bool IsInt = Ty->isIntegralOrEnumerationType();
+  bool IsFloat = Ty->isRealFloatingType();
+
+  if (IsInt || IsFloat) {
+uint64_t Size = getContext().getTy

[PATCH] D64985: [clangd] Provide a way to publish highlightings in non-racy manner

2019-07-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 210807.
ilya-biryukov added a comment.

- Update usage of DiagsMu in a comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64985

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  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
@@ -7,10 +7,14 @@
 //===--===//
 
 #include "Annotations.h"
+#include "ClangdUnit.h"
 #include "Context.h"
+#include "Diagnostics.h"
 #include "Matchers.h"
+#include "Path.h"
 #include "TUScheduler.h"
 #include "TestFS.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -56,12 +60,17 @@
   /// in updateWithDiags.
   static std::unique_ptr captureDiags() {
 class CaptureDiags : public ParsingCallbacks {
-  void onDiagnostics(PathRef File, std::vector Diags) override {
+  void onMainAST(PathRef File, ParsedAST &AST, PublishFn Publish) override {
+auto Diags = AST.getDiagnostics();
 auto D = Context::current().get(DiagsCallbackKey);
 if (!D)
   return;
-const_cast)> &> (
-*D)(File, Diags);
+
+Publish([&]() {
+  const_cast<
+  llvm::unique_function)> &> (*D)(
+  File, std::move(Diags));
+});
   }
 };
 return llvm::make_unique();
@@ -116,8 +125,8 @@
   S.update(Added, getInputs(Added, "x"), WantDiagnostics::No);
   EXPECT_EQ(S.getContents(Added), "x");
 
-  // Assert each operation for missing file is an error (even if it's available
-  // in VFS).
+  // Assert each operation for missing file is an error (even if it's
+  // available in VFS).
   S.runWithAST("", Missing,
[&](Expected AST) { EXPECT_ERROR(AST); });
   S.runWithPreamble(
@@ -367,8 +376,8 @@
 StringRef AllContents[] = {Contents1, Contents2, Contents3};
 const int AllContentsSize = 3;
 
-// Scheduler may run tasks asynchronously, but should propagate the context.
-// We stash a nonce in the context, and verify it in the task.
+// Scheduler may run tasks asynchronously, but should propagate the
+// context. We stash a nonce in the context, and verify it in the task.
 static Key NonceKey;
 int Nonce = 0;
 
@@ -465,8 +474,8 @@
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   ASSERT_EQ(BuiltASTCounter.load(), 1);
 
-  // Build two more files. Since we can retain only 2 ASTs, these should be the
-  // ones we see in the cache later.
+  // Build two more files. Since we can retain only 2 ASTs, these should be
+  // the ones we see in the cache later.
   updateWithCallback(S, Bar, SourceContents, WantDiagnostics::Yes,
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
   updateWithCallback(S, Baz, SourceContents, WantDiagnostics::Yes,
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -15,6 +15,7 @@
 #include "Threading.h"
 #include "index/CanonicalIncludes.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -98,6 +99,10 @@
   virtual void onPreambleAST(PathRef Path, ASTContext &Ctx,
  std::shared_ptr PP,
  const CanonicalIncludes &) {}
+  /// The argument function is run under the critical section guarding against
+  /// races when closing the files.
+  using PublishFn = llvm::function_ref)>;
+
   /// Called on the AST built for the file itself. Note that preamble AST nodes
   /// are not deserialized and should be processed in the onPreambleAST call
   /// instead.
@@ -108,10 +113,17 @@
   /// etc. Clients are expected to process only the AST nodes from the main file
   /// in this callback (obtained via ParsedAST::getLocalTopLevelDecls) to obtain
   /// optimal performance.
-  virtual void onMainAST(PathRef Path, ParsedAST &AST) {}
-
-  /// Called whenever the diagnostics for \p File are produced.
-  virtual void onDiagnostics(PathRef File, std::vector Diags) {}
+  ///
+  /// When information about the file (diagnostics, syntax highlighting) is
+  /// published to clients, this should be wrapped in Publish, e.g.
+  ///   void onMainAST(...) {
+  /// Highlights = computeHighlights();
+  /// Publish([&] { notifyHighlights(Path, Highlights); });
+  ///   }
+  /// This guarantees that clients will see results in the correct se

[PATCH] D64985: [clangd] Provide a way to publish highlightings in non-racy manner

2019-07-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 210808.
ilya-biryukov added a comment.

- Remove a leftover comment from the previous version


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64985

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  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
@@ -7,10 +7,14 @@
 //===--===//
 
 #include "Annotations.h"
+#include "ClangdUnit.h"
 #include "Context.h"
+#include "Diagnostics.h"
 #include "Matchers.h"
+#include "Path.h"
 #include "TUScheduler.h"
 #include "TestFS.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -56,12 +60,17 @@
   /// in updateWithDiags.
   static std::unique_ptr captureDiags() {
 class CaptureDiags : public ParsingCallbacks {
-  void onDiagnostics(PathRef File, std::vector Diags) override {
+  void onMainAST(PathRef File, ParsedAST &AST, PublishFn Publish) override {
+auto Diags = AST.getDiagnostics();
 auto D = Context::current().get(DiagsCallbackKey);
 if (!D)
   return;
-const_cast)> &> (
-*D)(File, Diags);
+
+Publish([&]() {
+  const_cast<
+  llvm::unique_function)> &> (*D)(
+  File, std::move(Diags));
+});
   }
 };
 return llvm::make_unique();
@@ -116,8 +125,8 @@
   S.update(Added, getInputs(Added, "x"), WantDiagnostics::No);
   EXPECT_EQ(S.getContents(Added), "x");
 
-  // Assert each operation for missing file is an error (even if it's available
-  // in VFS).
+  // Assert each operation for missing file is an error (even if it's
+  // available in VFS).
   S.runWithAST("", Missing,
[&](Expected AST) { EXPECT_ERROR(AST); });
   S.runWithPreamble(
@@ -367,8 +376,8 @@
 StringRef AllContents[] = {Contents1, Contents2, Contents3};
 const int AllContentsSize = 3;
 
-// Scheduler may run tasks asynchronously, but should propagate the context.
-// We stash a nonce in the context, and verify it in the task.
+// Scheduler may run tasks asynchronously, but should propagate the
+// context. We stash a nonce in the context, and verify it in the task.
 static Key NonceKey;
 int Nonce = 0;
 
@@ -465,8 +474,8 @@
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   ASSERT_EQ(BuiltASTCounter.load(), 1);
 
-  // Build two more files. Since we can retain only 2 ASTs, these should be the
-  // ones we see in the cache later.
+  // Build two more files. Since we can retain only 2 ASTs, these should be
+  // the ones we see in the cache later.
   updateWithCallback(S, Bar, SourceContents, WantDiagnostics::Yes,
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
   updateWithCallback(S, Baz, SourceContents, WantDiagnostics::Yes,
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -15,6 +15,7 @@
 #include "Threading.h"
 #include "index/CanonicalIncludes.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -98,6 +99,10 @@
   virtual void onPreambleAST(PathRef Path, ASTContext &Ctx,
  std::shared_ptr PP,
  const CanonicalIncludes &) {}
+  /// The argument function is run under the critical section guarding against
+  /// races when closing the files.
+  using PublishFn = llvm::function_ref)>;
+
   /// Called on the AST built for the file itself. Note that preamble AST nodes
   /// are not deserialized and should be processed in the onPreambleAST call
   /// instead.
@@ -108,10 +113,17 @@
   /// etc. Clients are expected to process only the AST nodes from the main file
   /// in this callback (obtained via ParsedAST::getLocalTopLevelDecls) to obtain
   /// optimal performance.
-  virtual void onMainAST(PathRef Path, ParsedAST &AST) {}
-
-  /// Called whenever the diagnostics for \p File are produced.
-  virtual void onDiagnostics(PathRef File, std::vector Diags) {}
+  ///
+  /// When information about the file (diagnostics, syntax highlighting) is
+  /// published to clients, this should be wrapped in Publish, e.g.
+  ///   void onMainAST(...) {
+  /// Highlights = computeHighlights();
+  /// Publish([&] { notifyHighlights(Path, Highlights); });
+  ///   }
+  /// This guarantees that clients will see results in

[PATCH] D64985: [clangd] Provide a way to publish highlightings in non-racy manner

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

Thanks for all the suggestions. This is ready for the next round now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64985



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


[PATCH] D64985: [clangd] Provide a way to publish highlightings in non-racy manner

2019-07-19 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.

Awesome, I think this is in better shape than before highlighting was added.




Comment at: clang-tools-extra/clangd/TUScheduler.h:102
  const CanonicalIncludes &) {}
+  /// The argument function is run under the critical section guarding against
+  /// races when closing the files.

uber-nit: newline before this, as currently it's grouped with onPreambleAST 
rather than onMainAST


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64985



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


[PATCH] D64638: [CrossTU] Fix plist macro expansion if macro in other file.

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

`StaticAnalyzer/Core` does not depend on `clangFrontend` now, you can see this 
by looking at `lib/StaticAnalyzer/Core/CMakeLists.txt`:

  add_clang_library(clangStaticAnalyzerCore
  ...
LINK_LIBS
clangAST
clangASTMatchers
clangAnalysis
clangBasic
clangCrossTU
clangLex
clangRewrite
)

Not a `StaticAnalyzer` expert, so I don't know whether it's acceptable to add 
this dependency to `clangStaticAnalyzerCore`, you'll have to find someone who 
owns the code to know whether this dependency is justified.
(My wild guess from looking at the names of the libraries would be that this 
dependency is not ok and the code should go into `clangStaticAnalyzerFrontend` 
instead. But again, not an expert here, just a guess).

But please add a dependency into `LINK_LIBS` inside `CMakeLists.txt` if you 
start depending on `clangFrontend`.
Most of these violations are found if you build in a `cmake 
-DBUILD_SHARED_LIBS=On` configuration.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64638



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


[PATCH] D44100: [ASTImporter] Reorder fields after structure import is finished

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

- Rebase to master
- Some refactor is done mostly because since D63603 
 ([ASTImporter] Propagate

error from ImportDeclContext) we may not imported successfully all decls of a
DC.

- Made the code simpler and shorter by adding a local vector to hold the decls

of the "from" DC in the original order.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D44100

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1472,7 +1472,7 @@
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
-   DISABLED_CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) {
+   CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
   // The original recursive algorithm of ASTImporter first imports 'c' then
@@ -5232,5 +5232,16 @@
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, LLDBLookupTest,
 DefaultTestValuesForRunOptions, );
 
+TEST_P(ImportDecl, ImportFieldOrder) {
+  MatchVerifier Verifier;
+  testImport("struct declToImport {"
+ "  int b = a + 2;"
+ "  int a = 5;"
+ "};",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ recordDecl(hasFieldOrder({"b", "a"})));
+}
+
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1645,7 +1645,6 @@
   bool AccumulateChildErrors = isa(FromDC);
 
   Error ChildErrors = Error::success();
-  llvm::SmallVector ImportedDecls;
   for (auto *From : FromDC->decls()) {
 ExpectedDecl ImportedOrErr = import(From);
 if (!ImportedOrErr) {
@@ -1657,6 +1656,63 @@
 }
   }
 
+  // We reorder declarations in RecordDecls because they may have another order
+  // in the "to" context than they have in the "from" context. This may happen
+  // e.g when we import a class like this:
+  //struct declToImport {
+  //int a = c + b;
+  //int b = 1;
+  //int c = 2;
+  //};
+  // During the import of `a` we import first the dependencies in sequence,
+  // thus the order would be `c`, `b`, `a`. We will get the normal order by
+  // first removing the already imported members and then adding them in the
+  // order as they apper in the "from" context.
+  //
+  // Keeping field order is vital because it determines structure layout.
+  //
+  // Here and below, we cannot call field_begin() method and its callers on
+  // ToDC if it has an external storage. Calling field_begin() will
+  // automatically load all the fields by calling
+  // LoadFieldsFromExternalStorage().  LoadFieldsFromExternalStorage() would
+  // call ASTImporter::Import(). This is because the ExternalASTSource
+  // interface in LLDB is implemented by the means of the ASTImporter. However,
+  // calling an import at this point would result in an uncontrolled import, we
+  // must avoid that.
+  const auto *FromRD = dyn_cast(FromDC);
+  if (!FromRD)
+return ChildErrors;
+  auto ToDCOrErr = Importer.ImportContext(FromDC);
+  if (!ToDCOrErr) {
+consumeError(std::move(ChildErrors));
+return ToDCOrErr.takeError();
+  }
+
+  DeclContext *ToDC = *ToDCOrErr;
+  // Remove all declarations, which may be in wrong order in the
+  // lexical DeclContext.
+  llvm::SmallVector ImportedDeclsInOriginalOrder;
+  for (auto *D : FromRD->decls()) {
+if (isa(D) || isa(D)) {
+  assert(D && "DC has a contained decl which is null?");
+  Decl *ToD = Importer.GetAlreadyImportedOrNull(D);
+  // Remove only the decls which we successfully imported.
+  if (ToD) {
+assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
+ToDC->removeDecl(ToD);
+ImportedDeclsInOriginalOrder.push_back(ToD);
+  }
+}
+  }
+  // At this point we removed only those decls which we have imported from the
+  // FromDC. We  did not remove all the decls of ToDC. And we don't want to
+  // remove any decls which may be loaded from the external storage of ToDC
+  // (these decls are not imported btw).
+
+  // Add the declarations, but this time in the correct order.
+  for (Decl *ToD : ImportedDeclsInOriginalOrder)
+ToDC->addDeclInternal(ToD);
+
   return ChildErrors;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64990: [clangd] Disable background-index on lit-tests by default

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

Since background-index can perform disk writes, we don't want to turn
it on tests that won't clear it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64990

Files:
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -355,6 +355,9 @@
 InputStyle = JSONStreamStyle::Delimited;
 LogLevel = Logger::Verbose;
 PrettyPrint = true;
+// Disable background index on lit tests by default to prevent disk writes.
+if (!EnableBackgroundIndex.getNumOccurrences())
+  EnableBackgroundIndex = false;
 // Ensure background index makes progress.
 BackgroundQueue::preventThreadStarvationInTests();
   }


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -355,6 +355,9 @@
 InputStyle = JSONStreamStyle::Delimited;
 LogLevel = Logger::Verbose;
 PrettyPrint = true;
+// Disable background index on lit tests by default to prevent disk writes.
+if (!EnableBackgroundIndex.getNumOccurrences())
+  EnableBackgroundIndex = false;
 // Ensure background index makes progress.
 BackgroundQueue::preventThreadStarvationInTests();
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64991: [analyzer][WIP] Implement a primitive reaching definitions analysis

2019-07-19 Thread KristĂłf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, baloghadamsoftware, Charusso, 
rnkovacs, a_sidorin, dcoughlin.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, whisperity, mgorny.

When I say WIP, I really mean it. This has no comments, no nothing, but follows 
this  algorithm pretty 
literally.

This analysis isn't conservative enough yet, I really should include function 
calls with non-const references into the gen set, but hey, at this point I'm 
optimistic that it can be done.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64991

Files:
  clang/include/clang/Analysis/Analyses/ReachingDefinitions.h
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Analysis/ReachingDefinitions.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
  clang/test/Analysis/dump-definitions.cpp

Index: clang/test/Analysis/dump-definitions.cpp
===
--- /dev/null
+++ clang/test/Analysis/dump-definitions.cpp
@@ -0,0 +1,176 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=debug.DumpGenSets \
+// RUN:   -analyzer-checker=debug.DumpKillSets \
+// RUN:   -analyzer-checker=debug.DumpReachingDefinitions \
+// RUN:   2>&1 | FileCheck %s
+
+
+
+int getInt();
+int *getIntPtr();
+bool coin();
+
+void single_vardecl_in_declstmt() {
+  int *ptr = getIntPtr();
+}
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 1 (ptr, [1, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (ptr, [1, 3])
+// CHECK-NEXT: 1 OUT (ptr, [1, 3])
+
+void multiple_vardecl_in_declstmt() {
+  int *ptr = getIntPtr(), i;
+}
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 1 (i, [1, 4])
+// CHECK-NEXT: 1 (ptr, [1, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (i, [1, 4])
+// CHECK-NEXT: 0 IN (ptr, [1, 3])
+// CHECK-NEXT: 1 OUT (i, [1, 4])
+// CHECK-NEXT: 1 OUT (ptr, [1, 3])
+
+void function_and_vardecl_in_declstmt() {
+  int *ptr = getIntPtr(), a();
+}
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 1 (ptr, [1, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (ptr, [1, 3])
+// CHECK-NEXT: 1 OUT (ptr, [1, 3])
+
+void single_def_in_same_block() {
+  int *ptr = getIntPtr();
+
+  if (coin())
+ptr = 0;
+
+  if (!ptr)
+*ptr = 5;
+}
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 3 (ptr, [3, 3])
+// CHECK-NEXT: 4 (ptr, [4, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 3 (ptr, [4, 3])
+// CHECK-NEXT: 4 (ptr, [3, 3])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 2 IN (ptr, [3, 3])
+// CHECK-NEXT: 2 IN (ptr, [4, 3])
+// CHECK-NEXT: 3 IN (ptr, [4, 3])
+// CHECK-NEXT: 3 OUT (ptr, [3, 3])
+// CHECK-NEXT: 4 OUT (ptr, [4, 3])
+
+void different_assignments() {
+  int i = getInt();
+
+  if (coin())
+i = 0;
+
+  i += 3;
+
+  if (!coin())
+i -= 2;
+
+  i *= 9;
+
+  if (i = 0)
+;
+}
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 2 (i, [2, 5])
+// CHECK-NEXT: 3 (i, [3, 2])
+// CHECK-NEXT: 4 (i, [4, 2])
+// CHECK-NEXT: 5 (i, [5, 2])
+// CHECK-NEXT: 6 (i, [6, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 2 (i, [3, 2])
+// CHECK-NEXT: 2 (i, [4, 2])
+// CHECK-NEXT: 2 (i, [5, 2])
+// CHECK-NEXT: 2 (i, [6, 3])
+// CHECK-NEXT: 3 (i, [2, 5])
+// CHECK-NEXT: 3 (i, [4, 2])
+// CHECK-NEXT: 3 (i, [5, 2])
+// CHECK-NEXT: 3 (i, [6, 3])
+// CHECK-NEXT: 4 (i, [2, 5])
+// CHECK-NEXT: 4 (i, [3, 2])
+// CHECK-NEXT: 4 (i, [5, 2])
+// CHECK-NEXT: 4 (i, [6, 3])
+// CHECK-NEXT: 5 (i, [2, 5])
+// CHECK-NEXT: 5 (i, [3, 2])
+// CHECK-NEXT: 5 (i, [4, 2])
+// CHECK-NEXT: 5 (i, [6, 3])
+// CHECK-NEXT: 6 (i, [2, 5])
+// CHECK-NEXT: 6 (i, [3, 2])
+// CHECK-NEXT: 6 (i, [4, 2])
+// CHECK-NEXT: 6 (i, [5, 2])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (i, [2, 5])
+// CHECK-NEXT: 1 IN (i, [2, 5])
+// CHECK-NEXT: 2 IN (i, [3, 2])
+// CHECK-NEXT: 2 IN (i, [4, 2])
+// CHECK-NEXT: 2 OUT (i, [2, 5])
+// CHECK-NEXT: 3 IN (i, [4, 2])
+// CHECK-NEXT: 3 OUT (i, [3, 2])
+// CHECK-NEXT: 4 IN (i, [5, 2])
+// CHECK-NEXT: 4 IN (i, [6, 3])
+// CHECK-NEXT: 4 OUT (i, [4, 2])
+// CHECK-NEXT: 5 IN (i, [6, 3])
+// CHECK-NEXT: 5 OUT (i, [5, 2])
+// CH

[PATCH] D64990: [clangd] Disable background-index on lit-tests by default

2019-07-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:361
+  EnableBackgroundIndex = false;
 // Ensure background index makes progress.
 BackgroundQueue::preventThreadStarvationInTests();

maybe add "if enabled" here, this reads a little funny otherwise!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64990



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


[clang-tools-extra] r366575 - [clangd] Disable background-index on lit-tests by default

2019-07-19 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Jul 19 06:40:30 2019
New Revision: 366575

URL: http://llvm.org/viewvc/llvm-project?rev=366575&view=rev
Log:
[clangd] Disable background-index on lit-tests by default

Summary:
Since background-index can perform disk writes, we don't want to turn
it on tests that won't clear it.

Reviewers: sammccall

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=366575&r1=366574&r2=366575&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Fri Jul 19 06:40:30 2019
@@ -355,8 +355,12 @@ int main(int argc, char *argv[]) {
 InputStyle = JSONStreamStyle::Delimited;
 LogLevel = Logger::Verbose;
 PrettyPrint = true;
+// Disable background index on lit tests by default to prevent disk writes.
+if (!EnableBackgroundIndex.getNumOccurrences())
+  EnableBackgroundIndex = false;
 // Ensure background index makes progress.
-BackgroundQueue::preventThreadStarvationInTests();
+else if (EnableBackgroundIndex)
+  BackgroundQueue::preventThreadStarvationInTests();
   }
   if (Test || EnableTestScheme) {
 static URISchemeRegistry::Add X(


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


[PATCH] D64475: [clangd] Duplicate lines of semantic highlightings sent removed.

2019-07-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp:307
+llvm::StringRef NewCode;
+std::vector DiffedLines;
+  } TestCases[]{

@hokein rightfully pointed out that mentioning all changed lines makes the 
tests unreadable.
An alternative idea we all came up with is to force people to put `^` on each 
of the changed lines inside the `NewCode`, i.e.

```
{/*Before*/ R"(
  $Var[[a]]
  $Func[[b]]
"),
 /*After*/ R"(
  $Var[[a]]
 ^$Func[[b]]
)"} // and no list of lines is needed!
```

Could we do that here?

One interesting case that we can't test this way to removing lines from the end 
of the file. But for that particular case, could we just write a separate test 
case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64475



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


[PATCH] D64990: [clangd] Disable background-index on lit-tests by default

2019-07-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366575: [clangd] Disable background-index on lit-tests by 
default (authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64990?vs=210820&id=210822#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64990

Files:
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -355,8 +355,12 @@
 InputStyle = JSONStreamStyle::Delimited;
 LogLevel = Logger::Verbose;
 PrettyPrint = true;
+// Disable background index on lit tests by default to prevent disk writes.
+if (!EnableBackgroundIndex.getNumOccurrences())
+  EnableBackgroundIndex = false;
 // Ensure background index makes progress.
-BackgroundQueue::preventThreadStarvationInTests();
+else if (EnableBackgroundIndex)
+  BackgroundQueue::preventThreadStarvationInTests();
   }
   if (Test || EnableTestScheme) {
 static URISchemeRegistry::Add X(


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -355,8 +355,12 @@
 InputStyle = JSONStreamStyle::Delimited;
 LogLevel = Logger::Verbose;
 PrettyPrint = true;
+// Disable background index on lit tests by default to prevent disk writes.
+if (!EnableBackgroundIndex.getNumOccurrences())
+  EnableBackgroundIndex = false;
 // Ensure background index makes progress.
-BackgroundQueue::preventThreadStarvationInTests();
+else if (EnableBackgroundIndex)
+  BackgroundQueue::preventThreadStarvationInTests();
   }
   if (Test || EnableTestScheme) {
 static URISchemeRegistry::Add X(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64985: [clangd] Provide a way to publish highlightings in non-racy manner

2019-07-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 210823.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

- Group PublishFn with onMainAST


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64985

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  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
@@ -7,10 +7,14 @@
 //===--===//
 
 #include "Annotations.h"
+#include "ClangdUnit.h"
 #include "Context.h"
+#include "Diagnostics.h"
 #include "Matchers.h"
+#include "Path.h"
 #include "TUScheduler.h"
 #include "TestFS.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -56,12 +60,17 @@
   /// in updateWithDiags.
   static std::unique_ptr captureDiags() {
 class CaptureDiags : public ParsingCallbacks {
-  void onDiagnostics(PathRef File, std::vector Diags) override {
+  void onMainAST(PathRef File, ParsedAST &AST, PublishFn Publish) override {
+auto Diags = AST.getDiagnostics();
 auto D = Context::current().get(DiagsCallbackKey);
 if (!D)
   return;
-const_cast)> &> (
-*D)(File, Diags);
+
+Publish([&]() {
+  const_cast<
+  llvm::unique_function)> &> (*D)(
+  File, std::move(Diags));
+});
   }
 };
 return llvm::make_unique();
@@ -116,8 +125,8 @@
   S.update(Added, getInputs(Added, "x"), WantDiagnostics::No);
   EXPECT_EQ(S.getContents(Added), "x");
 
-  // Assert each operation for missing file is an error (even if it's available
-  // in VFS).
+  // Assert each operation for missing file is an error (even if it's
+  // available in VFS).
   S.runWithAST("", Missing,
[&](Expected AST) { EXPECT_ERROR(AST); });
   S.runWithPreamble(
@@ -367,8 +376,8 @@
 StringRef AllContents[] = {Contents1, Contents2, Contents3};
 const int AllContentsSize = 3;
 
-// Scheduler may run tasks asynchronously, but should propagate the context.
-// We stash a nonce in the context, and verify it in the task.
+// Scheduler may run tasks asynchronously, but should propagate the
+// context. We stash a nonce in the context, and verify it in the task.
 static Key NonceKey;
 int Nonce = 0;
 
@@ -465,8 +474,8 @@
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   ASSERT_EQ(BuiltASTCounter.load(), 1);
 
-  // Build two more files. Since we can retain only 2 ASTs, these should be the
-  // ones we see in the cache later.
+  // Build two more files. Since we can retain only 2 ASTs, these should be
+  // the ones we see in the cache later.
   updateWithCallback(S, Bar, SourceContents, WantDiagnostics::Yes,
  [&BuiltASTCounter]() { ++BuiltASTCounter; });
   updateWithCallback(S, Baz, SourceContents, WantDiagnostics::Yes,
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -15,6 +15,7 @@
 #include "Threading.h"
 #include "index/CanonicalIncludes.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -98,6 +99,10 @@
   virtual void onPreambleAST(PathRef Path, ASTContext &Ctx,
  std::shared_ptr PP,
  const CanonicalIncludes &) {}
+
+  /// The argument function is run under the critical section guarding against
+  /// races when closing the files.
+  using PublishFn = llvm::function_ref)>;
   /// Called on the AST built for the file itself. Note that preamble AST nodes
   /// are not deserialized and should be processed in the onPreambleAST call
   /// instead.
@@ -108,10 +113,17 @@
   /// etc. Clients are expected to process only the AST nodes from the main file
   /// in this callback (obtained via ParsedAST::getLocalTopLevelDecls) to obtain
   /// optimal performance.
-  virtual void onMainAST(PathRef Path, ParsedAST &AST) {}
-
-  /// Called whenever the diagnostics for \p File are produced.
-  virtual void onDiagnostics(PathRef File, std::vector Diags) {}
+  ///
+  /// When information about the file (diagnostics, syntax highlighting) is
+  /// published to clients, this should be wrapped in Publish, e.g.
+  ///   void onMainAST(...) {
+  /// Highlights = computeHighlights();
+  /// Publish([&] { notifyHighlights(Path, Highlights); });
+  ///   }
+  /// This guarantees that 

[PATCH] D64739: [SVE][Inline-Asm] Add support to specify SVE registers in the clobber list

2019-07-19 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin updated this revision to Diff 210821.
kmclaughlin retitled this revision from "[SVE][Inline-Asm] Add support to clang 
for SVE inline assembly" to "[SVE][Inline-Asm] Add support to specify SVE 
registers in the clobber list".
kmclaughlin added a comment.

- Removed typo fixes from this patch
- Consolidated the tests in aarch64-sve-inline-asm.c into one test & fixed 
formatting
- Added a test without +sve to ensure we get the correct diagnostic


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

https://reviews.llvm.org/D64739

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


Index: clang/test/CodeGen/aarch64-sve-inline-asm.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-inline-asm.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -target-feature 
+sve -o - %s | FileCheck %s -check-prefix=CHECK-SVE
+// RUN: not %clang_cc1 -triple aarch64-none-linux-gnu -S %s -o - 2>&1 | 
FileCheck %s -check-prefix=CHECK-ERROR
+
+long test_sve_asm() {
+  long t;
+
+  asm volatile(
+  "ptrue p0.d\n"
+  "ptrue p15.d\n"
+  "add z0.d, p0/m, z0.d, z0.d\n"
+  "add z31.d, p0/m, z31.d, z31.d\n"
+  : "=w"(t)
+  :
+  : "z0", "z31", "p0", "p15");
+  // CHECK-SVE: "=w,~{z0},~{z31},~{p0},~{p15}"
+  // CHECK-ERROR: error: instruction requires: sve
+
+  return t;
+}
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -351,10 +351,19 @@
 "d12", "d13", "d14", "d15", "d16", "d17", "d18", "d19", "d20", "d21", 
"d22",
 "d23", "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
 
-// Vector registers
+// Neon vector registers
 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", 
"v22",
-"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
+"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
+
+// SVE vector registers
+"z0",  "z1",  "z2",  "z3",  "z4",  "z5",  "z6",  "z7",  "z8",  "z9",  
"z10",
+"z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", 
"z21",
+"z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
+
+// SVE predicate registers
+"p0",  "p1",  "p2",  "p3",  "p4",  "p5",  "p6",  "p7",  "p8",  "p9",  
"p10",
+"p11", "p12", "p13", "p14", "p15"
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {


Index: clang/test/CodeGen/aarch64-sve-inline-asm.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-inline-asm.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -target-feature +sve -o - %s | FileCheck %s -check-prefix=CHECK-SVE
+// RUN: not %clang_cc1 -triple aarch64-none-linux-gnu -S %s -o - 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR
+
+long test_sve_asm() {
+  long t;
+
+  asm volatile(
+  "ptrue p0.d\n"
+  "ptrue p15.d\n"
+  "add z0.d, p0/m, z0.d, z0.d\n"
+  "add z31.d, p0/m, z31.d, z31.d\n"
+  : "=w"(t)
+  :
+  : "z0", "z31", "p0", "p15");
+  // CHECK-SVE: "=w,~{z0},~{z31},~{p0},~{p15}"
+  // CHECK-ERROR: error: instruction requires: sve
+
+  return t;
+}
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -351,10 +351,19 @@
 "d12", "d13", "d14", "d15", "d16", "d17", "d18", "d19", "d20", "d21", "d22",
 "d23", "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
 
-// Vector registers
+// Neon vector registers
 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22",
-"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
+"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
+
+// SVE vector registers
+"z0",  "z1",  "z2",  "z3",  "z4",  "z5",  "z6",  "z7",  "z8",  "z9",  "z10",
+"z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21",
+"z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
+
+// SVE predicate registers
+"p0",  "p1",  "p2",  "p3",  "p4",  "p5",  "p6",  "p7",  "p8",  "p9",  "p10",
+"p11", "p12", "p13", "p14", "p15"
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64416: [AArch64] Add support for Transactional Memory Extension (TME)

2019-07-19 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/test/CodeGen/AArch64/tme-tcancel.ll:1
+; RUN: llc %s -o - | FileCheck %s
+

Would it make sense to add -verify-machineinstrs to all these 
Codegen/AArch64/tme-*.ll tests?


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

https://reviews.llvm.org/D64416



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


[clang-tools-extra] r366577 - [clangd] Provide a way to publish highlightings in non-racy manner

2019-07-19 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Jul 19 06:51:01 2019
New Revision: 366577

URL: http://llvm.org/viewvc/llvm-project?rev=366577&view=rev
Log:
[clangd] Provide a way to publish highlightings in non-racy manner

Summary:
By exposing a callback that can guard code publishing results of
'onMainAST' callback in the same manner we guard diagnostics.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: javed.absar, MaskRay, jkorous, arphaman, kadircet, hokein, 
jvikstrom, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/TUScheduler.h
clang-tools-extra/trunk/clangd/unittests/TUSchedulerTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=366577&r1=366576&r2=366577&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Fri Jul 19 06:51:01 2019
@@ -14,6 +14,7 @@
 #include "FormattedString.h"
 #include "Headers.h"
 #include "Protocol.h"
+#include "SemanticHighlighting.h"
 #include "SourceCode.h"
 #include "TUScheduler.h"
 #include "Trace.h"
@@ -31,6 +32,7 @@
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
@@ -60,15 +62,20 @@ struct UpdateIndexCallbacks : public Par
   FIndex->updatePreamble(Path, Ctx, std::move(PP), CanonIncludes);
   }
 
-  void onMainAST(PathRef Path, ParsedAST &AST) override {
+  void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override {
 if (FIndex)
   FIndex->updateMain(Path, AST);
+
+std::vector Diagnostics = AST.getDiagnostics();
+std::vector Highlightings;
 if (SemanticHighlighting)
-  DiagConsumer.onHighlightingsReady(Path, getSemanticHighlightings(AST));
-  }
+  Highlightings = getSemanticHighlightings(AST);
 
-  void onDiagnostics(PathRef File, std::vector Diags) override {
-DiagConsumer.onDiagnosticsReady(File, std::move(Diags));
+Publish([&]() {
+  DiagConsumer.onDiagnosticsReady(Path, std::move(Diagnostics));
+  if (SemanticHighlighting)
+DiagConsumer.onHighlightingsReady(Path, std::move(Highlightings));
+});
   }
 
   void onFileUpdated(PathRef File, const TUStatus &Status) override {

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=366577&r1=366576&r2=366577&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Fri Jul 19 06:51:01 2019
@@ -249,9 +249,8 @@ private:
   TUStatus Status;
 
   Semaphore &Barrier;
-  /// Whether the diagnostics for the current FileInputs were reported to the
-  /// users before.
-  bool DiagsWereReported = false;
+  /// Whether the 'onMainAST' callback ran for the current FileInputs.
+  bool RanASTCallback = false;
   /// Guards members used by both TUScheduler and the worker thread.
   mutable std::mutex Mutex;
   /// File inputs, currently being used by the worker.
@@ -265,15 +264,16 @@ private:
   bool Done;/* GUARDED_BY(Mutex) */
   std::deque Requests; /* GUARDED_BY(Mutex) */
   mutable std::condition_variable RequestsCV;
-  // FIXME: rename it to better fix the current usage, we also use it to guard
-  // emitting TUStatus.
-  /// Guards a critical section for running the diagnostics callbacks.
-  std::mutex DiagsMu;
-  // Used to prevent remove document + leading to out-of-order diagnostics:
+  /// Guards the callback that publishes results of AST-related computations
+  /// (diagnostics, highlightings) and file statuses.
+  std::mutex PublishMu;
+  // Used to prevent remove document + add document races that lead to
+  // out-of-order callbacks for publishing results of onMainAST callback.
+  //
   // The lifetime of the old/new ASTWorkers will overlap, but their handles
   // don't. When the old handle is destroyed, the old worker will stop 
reporting
-  // diagnostics.
-  bool ReportDiagnostics = true; /* GUARDED_BY(DiagsMu) */
+  // any results to the user.
+  bool CanPublishResults = true; /* GUARDED_BY(PublishMu) */
 };
 
 /// A smart-pointer-like class that points to an active ASTWorker.
@@ -381,12 +381,12 @@ void ASTWorker::update(ParseInputs Input
 std::tie(Inputs.CompileCommand, Inputs.Contents);
 
 tooling::CompileCommand OldCommand = PrevInputs->CompileCommand;
-bool PrevDiagsWereReported = DiagsWereReported;
+bool RanCallbackForPrevInputs = RanASTCallb

[PATCH] D64985: [clangd] Provide a way to publish highlightings in non-racy manner

2019-07-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366577: [clangd] Provide a way to publish highlightings in 
non-racy manner (authored by ibiryukov, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64985?vs=210823&id=210824#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64985

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/TUScheduler.cpp
  clang-tools-extra/trunk/clangd/TUScheduler.h
  clang-tools-extra/trunk/clangd/unittests/TUSchedulerTests.cpp

Index: clang-tools-extra/trunk/clangd/TUScheduler.h
===
--- clang-tools-extra/trunk/clangd/TUScheduler.h
+++ clang-tools-extra/trunk/clangd/TUScheduler.h
@@ -15,6 +15,7 @@
 #include "Threading.h"
 #include "index/CanonicalIncludes.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -98,6 +99,10 @@
   virtual void onPreambleAST(PathRef Path, ASTContext &Ctx,
  std::shared_ptr PP,
  const CanonicalIncludes &) {}
+
+  /// The argument function is run under the critical section guarding against
+  /// races when closing the files.
+  using PublishFn = llvm::function_ref)>;
   /// Called on the AST built for the file itself. Note that preamble AST nodes
   /// are not deserialized and should be processed in the onPreambleAST call
   /// instead.
@@ -108,10 +113,17 @@
   /// etc. Clients are expected to process only the AST nodes from the main file
   /// in this callback (obtained via ParsedAST::getLocalTopLevelDecls) to obtain
   /// optimal performance.
-  virtual void onMainAST(PathRef Path, ParsedAST &AST) {}
-
-  /// Called whenever the diagnostics for \p File are produced.
-  virtual void onDiagnostics(PathRef File, std::vector Diags) {}
+  ///
+  /// When information about the file (diagnostics, syntax highlighting) is
+  /// published to clients, this should be wrapped in Publish, e.g.
+  ///   void onMainAST(...) {
+  /// Highlights = computeHighlights();
+  /// Publish([&] { notifyHighlights(Path, Highlights); });
+  ///   }
+  /// This guarantees that clients will see results in the correct sequence if
+  /// the file is concurrently closed and/or reopened. (The lambda passed to
+  /// Publish() may never run in this case).
+  virtual void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) {}
 
   /// Called whenever the TU status is updated.
   virtual void onFileUpdated(PathRef File, const TUStatus &Status) {}
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -14,6 +14,7 @@
 #include "FormattedString.h"
 #include "Headers.h"
 #include "Protocol.h"
+#include "SemanticHighlighting.h"
 #include "SourceCode.h"
 #include "TUScheduler.h"
 #include "Trace.h"
@@ -31,6 +32,7 @@
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
@@ -60,15 +62,20 @@
   FIndex->updatePreamble(Path, Ctx, std::move(PP), CanonIncludes);
   }
 
-  void onMainAST(PathRef Path, ParsedAST &AST) override {
+  void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override {
 if (FIndex)
   FIndex->updateMain(Path, AST);
+
+std::vector Diagnostics = AST.getDiagnostics();
+std::vector Highlightings;
 if (SemanticHighlighting)
-  DiagConsumer.onHighlightingsReady(Path, getSemanticHighlightings(AST));
-  }
+  Highlightings = getSemanticHighlightings(AST);
 
-  void onDiagnostics(PathRef File, std::vector Diags) override {
-DiagConsumer.onDiagnosticsReady(File, std::move(Diags));
+Publish([&]() {
+  DiagConsumer.onDiagnosticsReady(Path, std::move(Diagnostics));
+  if (SemanticHighlighting)
+DiagConsumer.onHighlightingsReady(Path, std::move(Highlightings));
+});
   }
 
   void onFileUpdated(PathRef File, const TUStatus &Status) override {
Index: clang-tools-extra/trunk/clangd/TUScheduler.cpp
===
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp
@@ -249,9 +249,8 @@
   TUStatus Status;
 
   Semaphore &Barrier;
-  /// Whether the diagnostics for the current FileInputs were reported to the
-  /// users before.
-  bool DiagsWereReported = false;
+  /// Whether the 'onMainAST' callback ran for the current FileInputs.
+  bool RanASTCallback = false;
   /// Guards members used by both T

[PATCH] D64475: [clangd] Duplicate lines of semantic highlightings sent removed.

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

The fix for a race condition on remove has landed in rL366577 
, this revision would need a small update 
after it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64475



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


[PATCH] D64863: [clangd] Ignore diags from builtin files

2019-07-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:601
-  if (mentionsMainFile(*LastDiag) ||
-  (LastDiag->Severity >= DiagnosticsEngine::Level::Error &&
-   IncludeLinesWithErrors.insert(LastDiag->Range.start.line).second)) {

It's not clear why we these conditions should be checked somewhere else.
Could you explain in more detail?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64863



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


[PATCH] D64592: [OpenMP] Fix declare target link implementation

2019-07-19 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:2592-2593
   llvm::raw_svector_ostream OS(PtrName);
-  OS << CGM.getMangledName(GlobalDecl(VD)) << "_decl_tgt_ref_ptr";
+  unsigned DeviceID, Line;
+  unsigned FileID = 0;
+  OS << CGM.getMangledName(GlobalDecl(VD));

Move those 3 vars to `if` statement, they are not needed here.



Comment at: test/OpenMP/declare_target_link_codegen.cpp:22-23
+// HOST-DAG: @c_decl_tgt_ref_ptr = weak global i32* @c
+// HOST-DAG: @_{{.*}}d = internal global i32 2
+// HOST-DAG: @_{{.*}}d_{{.*}}_decl_tgt_ref_ptr = weak global i32* @_{{.*}}d
 // DEVICE-NOT: @c =

Better to define the variable with the name of the original `d` variable for 
better and stable check


Repository:
  rC Clang

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

https://reviews.llvm.org/D64592



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


[libclc] r366581 - Creating release candidate final from release_801 branch

2019-07-19 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Fri Jul 19 07:14:12 2019
New Revision: 366581

URL: http://llvm.org/viewvc/llvm-project?rev=366581&view=rev
Log:
Creating release candidate final from release_801 branch

Added:
libclc/tags/RELEASE_801/final/
  - copied from r366580, libclc/branches/release_80/

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


[libunwind] r366581 - Creating release candidate final from release_801 branch

2019-07-19 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Fri Jul 19 07:14:12 2019
New Revision: 366581

URL: http://llvm.org/viewvc/llvm-project?rev=366581&view=rev
Log:
Creating release candidate final from release_801 branch

Added:
libunwind/tags/RELEASE_801/final/
  - copied from r366580, libunwind/branches/release_80/

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


[PATCH] D64838: [Attr] Support _attribute__ ((fallthrough))

2019-07-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D64838#1592520 , 
@Nathan-Huckleberry wrote:

>   void foo() {
> __attribute__((address_space(0))) *x;
> *y;
>   }
>
>
> If the attributes are parsed then function body looks like this to the parser:
>
>   {
> *x; //this one has attributes now
> *y;
>   {
>
>
> The first line should be a valid declaration and the second like should be a 
> dereference of an uninitialized variable. If the attributes token is 
> discarded before parsing the rest of the line the only way to differentiate 
> these is by looking at the attributes added to them.
>
> An alternative may be parse the attributes list and immediately try to parse 
> as a declaration then if that parsing fails attempt to parse as something 
> else. Although this approach also has the scary implication of things that 
> are supposed to be declarations getting reparsed as something entirely 
> different.


The issue is that a leading GNU-style attribute is not sufficient information 
to determine whether we're parsing a declaration or a statement; it shouldn't 
always be treated as a decl-specifier. I spoke with a GCC dev about how they 
handle this, and effectively, they parse the attributes first then attempt to 
parse a declaration; if that fails, they fall back to parsing a statement. I 
think the way forward for us that should be similar is to parse the attributes 
first and then wait until we see a decl-specifier before determining whether we 
want to parse a declaration or a statement, and attach the attributes after 
we've figured out which production we have. @rsmith may have even better 
approaches in mind, but we're definitely agreed that we should not parse 
statement/decl based on attribute identity. I would hope we could find a way to 
avoid lots of re-parsing work if we can (even to the point of perhaps breaking 
the `address_space` case because implicit int is pretty horrible to rely on in 
the first place; it depends on whether breaking that will break a lot of code 
or not).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64838



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


[PATCH] D64863: [clangd] Ignore diags from builtin files

2019-07-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 210834.
kadircet added a comment.

- Move deduplication logic back into the `flushLastDiag` as discussed offline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64863

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -907,7 +907,6 @@
 int x = 5/0;)cpp");
   TestTU TU = TestTU::withCode(Main.code());
   TU.AdditionalFiles = {{"a.h", Header.code()}};
-  auto diags = TU.build().getDiagnostics();
   EXPECT_THAT(TU.build().getDiagnostics(),
   UnorderedElementsAre(AllOf(
   Diag(Main.range(), "in included file: C++ requires "
@@ -915,6 +914,19 @@
   WithNote(Diag(Header.range(), "error occurred here");
 }
 
+TEST(IgnoreDiags, FromNonWrittenSources) {
+  Annotations Main(R"cpp(
+#include [["a.h"]]
+void foo() {})cpp");
+  Annotations Header(R"cpp(
+int x = 5/0;
+int b = [[FOO]];)cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.AdditionalFiles = {{"a.h", Header.code()}};
+  TU.ExtraArgs = {"-DFOO=NOOO"};
+  EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
+}
+
 } // namespace
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -145,6 +145,7 @@
   std::vector Output;
   llvm::Optional LangOpts;
   llvm::Optional LastDiag;
+  bool LastDiagWasAdjusted = false;
   llvm::DenseSet IncludeLinesWithErrors;
   bool LastPrimaryDiagnosticWasSuppressed = false;
 };
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -20,6 +20,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Capacity.h"
@@ -107,8 +108,12 @@
   return halfOpenToRange(M, R);
 }
 
-void adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info,
+bool adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info,
   const LangOptions &LangOpts) {
+  // We only report diagnostics with at least error severity from headers.
+  if (D.Severity < DiagnosticsEngine::Level::Error)
+return false;
+
   const SourceLocation &DiagLoc = Info.getLocation();
   const SourceManager &SM = Info.getSourceManager();
   SourceLocation IncludeInMainFile;
@@ -119,13 +124,15 @@
IncludeLocation = GetIncludeLoc(IncludeLocation))
 IncludeInMainFile = IncludeLocation;
   if (IncludeInMainFile.isInvalid())
-return;
+return false;
+  Position StartPos = sourceLocToPosition(SM, IncludeInMainFile);
 
   // Update diag to point at include inside main file.
   D.File = SM.getFileEntryForID(SM.getMainFileID())->getName().str();
-  D.Range.start = sourceLocToPosition(SM, IncludeInMainFile);
+  D.Range.start = std::move(StartPos);
   D.Range.end = sourceLocToPosition(
   SM, Lexer::getLocForEndOfToken(IncludeInMainFile, 0, SM, LangOpts));
+  D.InsideMainFile = true;
 
   // Add a note that will point to real diagnostic.
   const auto *FE = SM.getFileEntryForID(SM.getFileID(DiagLoc));
@@ -138,6 +145,7 @@
 
   // Update message to mention original file.
   D.Message = llvm::Twine("in included file: ", D.Message).str();
+  return true;
 }
 
 bool isInsideMainFile(const clang::Diagnostic &D) {
@@ -465,6 +473,7 @@
   }
 
   bool InsideMainFile = isInsideMainFile(Info);
+  SourceManager &SM = Info.getSourceManager();
 
   auto FillDiagBase = [&](DiagBase &D) {
 D.Range = diagnosticRange(Info, *LangOpts);
@@ -472,8 +481,7 @@
 Info.FormatDiagnostic(Message);
 D.Message = Message.str();
 D.InsideMainFile = InsideMainFile;
-D.File = Info.getSourceManager().getFilename(Info.getLocation());
-auto &SM = Info.getSourceManager();
+D.File = SM.getFilename(Info.getLocation());
 D.AbsFile = getCanonicalPath(
 SM.getFileEntryForID(SM.getFileID(Info.getLocation())), SM);
 D.Severity = DiagLevel;
@@ -496,10 +504,9 @@
   if (FixIt.RemoveRange.getBegin().isMacroID() ||
   FixIt.RemoveRange.getEnd().isMacroID())
 return false;
-  if (!isInsideMainFile(FixIt.RemoveRange.getBegin(),
-Info.getSourceManager()))
+  if (!isInsideMainFile(FixIt.RemoveRange.getBegin(), SM))
 return false;
-  Edits.push_back(toTextEdi

[PATCH] D64863: [clangd] Ignore diags from builtin files

2019-07-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:128
+return false;
+  Position StartPos = sourceLocToPosition(SM, IncludeInMainFile);
 

NIT: inline `StartPos`, it has online a single usage now.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:563
 FillDiagBase(*LastDiag);
-adjustDiagFromHeader(*LastDiag, Info, *LangOpts);
+if (!InsideMainFile)
+  LastDiagWasAdjusted = adjustDiagFromHeader(*LastDiag, Info, *LangOpts);

We probably want to **always** set the value of this field to avoid 
accidentally reading the flag for the previous `LastDiag`



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:608
+  (!LastDiagWasAdjusted ||
+   // Only report the first diagnostic coming from a header.
IncludeLinesWithErrors.insert(LastDiag->Range.start.line).second)) {

NIT: maybe be more specific? coming from **each particular** header?



Comment at: clang-tools-extra/clangd/Diagnostics.h:148
   llvm::Optional LastDiag;
+  bool LastDiagWasAdjusted = false;
   llvm::DenseSet IncludeLinesWithErrors;

NIT: add a comment that it was `adjustDiagFromHeader` that made the adjustment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64863



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


[PATCH] D64863: [clangd] Ignore diags from builtin files

2019-07-19 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 210838.
kadircet marked 5 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64863

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -907,7 +907,6 @@
 int x = 5/0;)cpp");
   TestTU TU = TestTU::withCode(Main.code());
   TU.AdditionalFiles = {{"a.h", Header.code()}};
-  auto diags = TU.build().getDiagnostics();
   EXPECT_THAT(TU.build().getDiagnostics(),
   UnorderedElementsAre(AllOf(
   Diag(Main.range(), "in included file: C++ requires "
@@ -915,6 +914,19 @@
   WithNote(Diag(Header.range(), "error occurred here");
 }
 
+TEST(IgnoreDiags, FromNonWrittenSources) {
+  Annotations Main(R"cpp(
+#include [["a.h"]]
+void foo() {})cpp");
+  Annotations Header(R"cpp(
+int x = 5/0;
+int b = [[FOO]];)cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.AdditionalFiles = {{"a.h", Header.code()}};
+  TU.ExtraArgs = {"-DFOO=NOOO"};
+  EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre());
+}
+
 } // namespace
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -145,6 +145,9 @@
   std::vector Output;
   llvm::Optional LangOpts;
   llvm::Optional LastDiag;
+  // Set by adjustDiagFromHeader to indicate the fact that LastDiag was not
+  // inside main file initially.
+  bool LastDiagWasAdjusted = false;
   llvm::DenseSet IncludeLinesWithErrors;
   bool LastPrimaryDiagnosticWasSuppressed = false;
 };
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -20,6 +20,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Capacity.h"
@@ -107,8 +108,12 @@
   return halfOpenToRange(M, R);
 }
 
-void adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info,
+bool adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info,
   const LangOptions &LangOpts) {
+  // We only report diagnostics with at least error severity from headers.
+  if (D.Severity < DiagnosticsEngine::Level::Error)
+return false;
+
   const SourceLocation &DiagLoc = Info.getLocation();
   const SourceManager &SM = Info.getSourceManager();
   SourceLocation IncludeInMainFile;
@@ -119,13 +124,14 @@
IncludeLocation = GetIncludeLoc(IncludeLocation))
 IncludeInMainFile = IncludeLocation;
   if (IncludeInMainFile.isInvalid())
-return;
+return false;
 
   // Update diag to point at include inside main file.
   D.File = SM.getFileEntryForID(SM.getMainFileID())->getName().str();
   D.Range.start = sourceLocToPosition(SM, IncludeInMainFile);
   D.Range.end = sourceLocToPosition(
   SM, Lexer::getLocForEndOfToken(IncludeInMainFile, 0, SM, LangOpts));
+  D.InsideMainFile = true;
 
   // Add a note that will point to real diagnostic.
   const auto *FE = SM.getFileEntryForID(SM.getFileID(DiagLoc));
@@ -138,6 +144,7 @@
 
   // Update message to mention original file.
   D.Message = llvm::Twine("in included file: ", D.Message).str();
+  return true;
 }
 
 bool isInsideMainFile(const clang::Diagnostic &D) {
@@ -465,6 +472,7 @@
   }
 
   bool InsideMainFile = isInsideMainFile(Info);
+  SourceManager &SM = Info.getSourceManager();
 
   auto FillDiagBase = [&](DiagBase &D) {
 D.Range = diagnosticRange(Info, *LangOpts);
@@ -472,8 +480,7 @@
 Info.FormatDiagnostic(Message);
 D.Message = Message.str();
 D.InsideMainFile = InsideMainFile;
-D.File = Info.getSourceManager().getFilename(Info.getLocation());
-auto &SM = Info.getSourceManager();
+D.File = SM.getFilename(Info.getLocation());
 D.AbsFile = getCanonicalPath(
 SM.getFileEntryForID(SM.getFileID(Info.getLocation())), SM);
 D.Severity = DiagLevel;
@@ -496,10 +503,9 @@
   if (FixIt.RemoveRange.getBegin().isMacroID() ||
   FixIt.RemoveRange.getEnd().isMacroID())
 return false;
-  if (!isInsideMainFile(FixIt.RemoveRange.getBegin(),
-Info.getSourceManager()))
+  if (!isInsideMainFile(FixIt.RemoveRange.getBegin(), SM))
 return false;
-  Edits.push_back(toTextEdit(FixIt, Info

[PATCH] D64998: Improve clang-format-diff help output

2019-07-19 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: krasimir.

The description in clang-format-diff.py is more useful than the one
in `clang-format-diff -h`, so use the same description in both places.


https://reviews.llvm.org/D64998

Files:
  clang/tools/clang-format/clang-format-diff.py


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -8,10 +8,7 @@
 #
 
#======#
 
-r"""
-ClangFormat Diff Reformatter
-
-
+"""
 This script reads input from a unified diff and reformats all the changed
 lines. This is useful to reformat all the lines touched by a specific patch.
 Example usage for git/svn users:
@@ -35,10 +32,9 @@
 
 
 def main():
-  parser = argparse.ArgumentParser(description=
-   'Reformat changed lines in diff. Without -i 
'
-   'option just output the diff that would be '
-   'introduced.')
+  parser = argparse.ArgumentParser(description=__doc__,
+   formatter_class=
+   
argparse.RawDescriptionHelpFormatter)
   parser.add_argument('-i', action='store_true', default=False,
   help='apply edits to files instead of displaying a diff')
   parser.add_argument('-p', metavar='NUM', default=0,


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -8,10 +8,7 @@
 #
 #======#
 
-r"""
-ClangFormat Diff Reformatter
-
-
+"""
 This script reads input from a unified diff and reformats all the changed
 lines. This is useful to reformat all the lines touched by a specific patch.
 Example usage for git/svn users:
@@ -35,10 +32,9 @@
 
 
 def main():
-  parser = argparse.ArgumentParser(description=
-   'Reformat changed lines in diff. Without -i '
-   'option just output the diff that would be '
-   'introduced.')
+  parser = argparse.ArgumentParser(description=__doc__,
+   formatter_class=
+   argparse.RawDescriptionHelpFormatter)
   parser.add_argument('-i', action='store_true', default=False,
   help='apply edits to files instead of displaying a diff')
   parser.add_argument('-p', metavar='NUM', default=0,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64696: Adds a warning when an inline Doxygen comment has no argument

2019-07-19 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

Is it true that all inline commands require an argument?

For example, "\&" does not.




Comment at: clang/test/Sema/warn-documentation.cpp:1030
 
+// The inline comments expect a string after the command.
+// expected-warning@+1 {{'\a' command does not have an argument}}

Please move this new section below the test_attach tests.



Comment at: clang/test/Sema/warn-documentation.cpp:1033
+/// \a
+int test_inline_no_argument_a_b(int);
+

Please un-abbreviate b and g into bad and good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64696



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


[PATCH] D63648: [Preprocessor] Honor absolute paths in diagnostics

2019-07-19 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D63648#1591469 , @aganea wrote:

> It totally makes sense, thanks for the explanation Nico! Let's forget about 
> `cl` compatibility, that wasn't my initial intent.
>
> We always pass //relative// paths on the cmd-line, for all the reasons you've 
> mentioned. We also pass `-fdiagnostics-absolute-paths` hoping to fix the 
> Visual Studio jump-to-location issue I've mentioned above. However that 
> doesn't work, because we do:
>
>   (locally, on my PC)
> $ clang-cl file.cpp -Isome/relative/path/ -fdiagnostics-absolute-paths 
> /showIncludes -E >file_pre.cpp
>  
>   (and then, on a remote PC)
> $ clang-cl file_pre.cpp -fdiagnostics-absolute-paths
>   (the remote stdout is then displayed on my PC)
>
>
> `-fdiagnostics-absolute-paths` has no effect in the latter case, because the 
> paths are extracted from the preprocessed file, and paths can't be 
> absolutized anymore on the remote PC because it doesn't have the source code 
> (it is only a worker server).
>  So we end with relative paths in diagnostics, and Visual Studio can't jump 
> to the location of the diagnostic.
>
> What would you suggest? Use absolute paths along with `-fdebug-prefix-map`?


I see, thanks for the details.  A few more questions (sorry!):

- Does fastbuild have something like distcc-pump? (In pump mode, distcc sends 
the raw cc files and all included headers to the server, and preprocessing 
happens remotely – 
http://manpages.ubuntu.com/manpages/bionic/man1/distcc.1.html#how%20distcc-pump%20mode%20works)
 I think this would address this (?)

- IIRC we used to use fdiagnostics-absolute-paths in Chromium but eventually 
stopped because someone figured out how to make MSVC's jump-to-diag work even 
with relative paths (?)

I'm not sure what the Right Fix is here – I can see use cases for `-E` both 
with relative and with absolute paths, even if `-fdiagnostics-absolute-paths` 
:-/

I think `-fdebug-prefix-map` doesn't affect `-E` output as far as I know.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63648



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


[PATCH] D64780: Disallow most calling convention attributes on PS4.

2019-07-19 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 aside from a nit. You should give other reviewers a chance to sign off in 
case they have additional comments.




Comment at: lib/Basic/Targets/OSTargets.h:564
   }
+  TargetInfo::CallingConvCheckResult checkCallingConvention(CallingConv CC) 
const override {
+return (CC == CC_C) ? TargetInfo::CCCR_OK : TargetInfo::CCCR_Error;

Line length seems a bit long for coding style requirements.


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

https://reviews.llvm.org/D64780



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


[libunwind] r366587 - [libunwind][ARM] Fix loading FP registers on big-endian targets

2019-07-19 Thread Mikhail Maltsev via cfe-commits
Author: miyuki
Date: Fri Jul 19 08:20:32 2019
New Revision: 366587

URL: http://llvm.org/viewvc/llvm-project?rev=366587&view=rev
Log:
[libunwind][ARM] Fix loading FP registers on big-endian targets

Summary:
The function Unwind-EHABI.cpp:_Unwind_VRS_Pop loads the saved values of
64-bit FP registers as two 32-bit words because they might not be
8-byte aligned. Combining these words into a 64-bit value has to be
done differently on big-endian platforms.

Reviewers: ostannard, john.brawn, dmgreen

Reviewed By: ostannard

Subscribers: kristof.beyls, christof, libcxx-commits

Tags: #libc

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

Modified:
libunwind/trunk/src/Unwind-EHABI.cpp

Modified: libunwind/trunk/src/Unwind-EHABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/Unwind-EHABI.cpp?rev=366587&r1=366586&r2=366587&view=diff
==
--- libunwind/trunk/src/Unwind-EHABI.cpp (original)
+++ libunwind/trunk/src/Unwind-EHABI.cpp Fri Jul 19 08:20:32 2019
@@ -941,8 +941,13 @@ _Unwind_VRS_Pop(_Unwind_Context *context
   // format 1", which is equivalent to FSTMD + a padding word.
   for (uint32_t i = first; i < end; ++i) {
 // SP is only 32-bit aligned so don't copy 64-bit at a time.
-uint64_t value = *sp++;
-value |= ((uint64_t)(*sp++)) << 32;
+uint32_t w0 = *sp++;
+uint32_t w1 = *sp++;
+#ifdef __LITTLE_ENDIAN__
+uint64_t value = (w1 << 32) | w0;
+#else
+uint64_t value = (w0 << 32) | w1;
+#endif
 if (_Unwind_VRS_Set(context, regclass, i, representation, &value) !=
 _UVRSR_OK)
   return _UVRSR_FAILED;


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


[PATCH] D61452: [WebAssembly] Always include /lib in library path

2019-07-19 Thread Dan Gohman via Phabricator via cfe-commits
sunfish added a comment.

> This allows for us to fall back from arch-specific to generic headers as 
> needed.  The same can be true of libraries.  Not all libraries contains 
> compiled code.  `.so` files can also be linker scripts that reference other 
> libraries in which case they can be arch-neutral.

If we add support for implicit linker scripts in wasm-ld, we can look into 
this. That said, it's not clear we'll want to. They're rare, and when they are 
used they're another moving part in the middle of a complex system. There are 
usually other ways to do what they do.

> Secondly, not everyone is going to want to use a multi-arch sysroot.  For 
> example I would argue that the wasi SDK would make more sense being single 
> arch since it has exactly one purpose.  Its only when installing wasi into an 
> existing system that one really needs to be multi-arch.  In any case we 
> should not dictate this.

We're anticipating wasm64. And it's possible WASI could have other triple 
variants in the future too.

I'm aware some users will sometimes know that they only care about wasm32-wasi. 
Some of those users may write code, and perhaps some of those that do will 
share it with others. If such code assumes it can install into $SYSROOT/lib, it 
may break things for others using a multiarch setup. Unless there are reasons 
otherwise, it seems valuable to minimize fragmentation between multiarch and 
non-multiarch users. That seems more valuable than enabling some users to have 
shorter library paths.

> We've already have one person trying to build a wasi-sdk without using 
> multi-arch paths.

They ended up deciding they misunderstood the project for other reasons and 
left, so it's unclear what conclusion to draw.

> I'm not sure what you mean by "single arch sysroots are possible either way". 
>  The point of a single arch sysroot would be avoid the unnecessary extra path 
> components and I thats exactly what this change is allowing for.

I just mean you can have a multi-arch-style directory tree with a single arch 
installed in it.

> Thirdly, its what the linux driver does, which is the example we are 
> following of how to build a multi-arch toolchain.

The Linux driver has to stay compatible with existing pre-multi-arch systems; 
we don't.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61452



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


[PATCH] D65000: [ARM] Set default alignment to 64bits

2019-07-19 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio created this revision.
dnsampaio added reviewers: ostannard, dmgreen.
Herald added subscribers: cfe-commits, kristof.beyls, javed.absar.
Herald added a project: clang.

The maximum alignment used by ARM arch
is 64bits, not 128.

This could cause overaligned memory
access for 128 bit neon vector that
have unpredictable behaviour.

This fixes: https://bugs.llvm.org/show_bug.cgi?id=42668


Repository:
  rC Clang

https://reviews.llvm.org/D65000

Files:
  lib/Basic/Targets/ARM.cpp
  test/CodeGen/ARM/exception-alignment.cpp
  test/SemaCXX/warn-overaligned-type-thrown.cpp


Index: test/SemaCXX/warn-overaligned-type-thrown.cpp
===
--- test/SemaCXX/warn-overaligned-type-thrown.cpp
+++ test/SemaCXX/warn-overaligned-type-thrown.cpp
@@ -2,11 +2,11 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios10 -verify -fsyntax-only -std=c++11 
-fcxx-exceptions -fexceptions -DUNDERALIGNED %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10 -verify -fsyntax-only -std=c++11 
-fcxx-exceptions -fexceptions -DUNDERALIGNED %s
 // RUN: %clang_cc1 -triple arm64-apple-watchos4 -verify -fsyntax-only 
-std=c++11 -fcxx-exceptions -fexceptions -DUNDERALIGNED %s
+// RUN: %clang_cc1 -triple arm-linux-gnueabi -verify -fsyntax-only -std=c++11 
-fcxx-exceptions -fexceptions  -DUNDERALIGNED %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14 -verify -fsyntax-only 
-std=c++11 -fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple arm64-apple-ios12 -verify -fsyntax-only -std=c++11 
-fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos12 -verify -fsyntax-only -std=c++11 
-fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple arm64-apple-watchos5 -verify -fsyntax-only 
-std=c++11 -fcxx-exceptions -fexceptions %s
-// RUN: %clang_cc1 -triple arm-linux-gnueabi -verify -fsyntax-only -std=c++11 
-fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnueabi -verify -fsyntax-only 
-std=c++11 -fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple mipsel-linux-gnu -verify -fsyntax-only -std=c++11 
-fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple mips64el-linux-gnu -verify -fsyntax-only -std=c++11 
-fcxx-exceptions -fexceptions %s
Index: test/CodeGen/ARM/exception-alignment.cpp
===
--- /dev/null
+++ test/CodeGen/ARM/exception-alignment.cpp
@@ -0,0 +1,17 @@
+// Bug: https://bugs.llvm.org/show_bug.cgi?id=42668
+// REQUIRES: arm-registered-target
+// RUN: %clang --target=arm-arm-none-eabi -march=armv8-a -S -emit-llvm -Os -o 
- %s | FileCheck %s
+// CHECK: [[E:%[A-z0-9]+]] = tail call i8* @__cxa_allocate_exception
+// CHECK-NEXT: [[BC:%[A-z0-9]+]] = bitcast i8* [[E]] to <2 x i64>*
+// CHECK-NEXT: store <2 x i64> , <2 x i64>* [[BC]], align 8
+#include 
+
+int main(void) {
+  try {
+throw vld1q_u64(((const uint64_t[2]){1, 2}));
+  } catch (uint64x2_t exc) {
+return 0;
+  }
+  return 1;
+}
+
Index: lib/Basic/Targets/ARM.cpp
===
--- lib/Basic/Targets/ARM.cpp
+++ lib/Basic/Targets/ARM.cpp
@@ -325,6 +325,9 @@
: "\01mcount";
 
   SoftFloatABI = llvm::is_contained(Opts.FeaturesAsWritten, "+soft-float-abi");
+
+  // For AArch32, the largest alignment required by the ABI is 64-bit
+  DefaultAlignForAttributeAligned = 64;
 }
 
 StringRef ARMTargetInfo::getABI() const { return ABI; }


Index: test/SemaCXX/warn-overaligned-type-thrown.cpp
===
--- test/SemaCXX/warn-overaligned-type-thrown.cpp
+++ test/SemaCXX/warn-overaligned-type-thrown.cpp
@@ -2,11 +2,11 @@
 // RUN: %clang_cc1 -triple arm64-apple-ios10 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions -DUNDERALIGNED %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions -DUNDERALIGNED %s
 // RUN: %clang_cc1 -triple arm64-apple-watchos4 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions -DUNDERALIGNED %s
+// RUN: %clang_cc1 -triple arm-linux-gnueabi -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions  -DUNDERALIGNED %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple arm64-apple-ios12 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos12 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple arm64-apple-watchos5 -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions %s
-// RUN: %clang_cc1 -triple arm-linux-gnueabi -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnueabi -verify -fsyntax-only -std=c++11 -fcxx-exceptions -fexceptions %s
 // RUN: %clang_cc1 -triple mipsel-linux-gnu -verify -fsyntax-only -std=c++1

[PATCH] D64569: [OpenCL] Improve destructor support in C++ for OpenCL

2019-07-19 Thread Marco Antognini via Phabricator via cfe-commits
mantognini updated this revision to Diff 210850.
mantognini added a comment.

- Add minimal regression test for PR42665
- Add CXXMemberCallExpr::getObjectType()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64569

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenCXX/PR42665.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-ctor.cl
  clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl

Index: clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCLCXX/addrspace-with-class.cl
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s --check-prefix=CHECK-DEFINITIONS
+
+// This test ensures the proper address spaces and address space cast are used
+// for constructors, member functions and destructors.
+// See also atexit.cl and global_init.cl for other specific tests.
+
+// CHECK: %struct.MyType = type { i32 }
+struct MyType {
+  MyType(int i) : i(i) {}
+  MyType(int i) __constant : i(i) {}
+  ~MyType() {}
+  ~MyType() __constant {}
+  int bar() { return i + 2; }
+  int bar() __constant { return i + 1; }
+  int i;
+};
+
+// CHECK: @const1 = addrspace(2) global %struct.MyType zeroinitializer
+__constant MyType const1 = 1;
+// CHECK: @const2 = addrspace(2) global %struct.MyType zeroinitializer
+__constant MyType const2(2);
+// CHECK: @glob = addrspace(1) global %struct.MyType zeroinitializer
+MyType glob(1);
+
+// CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const1, i32 1)
+// CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const2, i32 2)
+// CHECK: call void @_ZNU3AS46MyTypeC1Ei(%struct.MyType addrspace(4)* addrspacecast (%struct.MyType addrspace(1)* @glob to %struct.MyType addrspace(4)*), i32 1)
+
+// CHECK-LABEL: define spir_kernel void @fooGlobal()
+kernel void fooGlobal() {
+  // CHECK: call i32 @_ZNU3AS46MyType3barEv(%struct.MyType addrspace(4)* addrspacecast (%struct.MyType addrspace(1)* @glob to %struct.MyType addrspace(4)*))
+  glob.bar();
+  // CHECK: call i32 @_ZNU3AS26MyType3barEv(%struct.MyType addrspace(2)* @const1)
+  const1.bar();
+  // CHECK: call void @_ZNU3AS26MyTypeD1Ev(%struct.MyType addrspace(2)* @const1)
+  const1.~MyType();
+}
+
+// CHECK-LABEL: define spir_kernel void @fooLocal()
+kernel void fooLocal() {
+  // CHECK: [[VAR:%.*]] = alloca %struct.MyType
+  // CHECK: [[REG:%.*]] = addrspacecast %struct.MyType* [[VAR]] to %struct.MyType addrspace(4)*
+  // CHECK: call void @_ZNU3AS46MyTypeC1Ei(%struct.MyType addrspace(4)* [[REG]], i32 3)
+  MyType myLocal(3);
+  // CHECK: [[REG:%.*]] = addrspacecast %struct.MyType* [[VAR]] to %struct.MyType addrspace(4)*
+  // CHECK: call i32 @_ZNU3AS46MyType3barEv(%struct.MyType addrspace(4)* [[REG]])
+  myLocal.bar();
+  // CHECK: [[REG:%.*]] = addrspacecast %struct.MyType* [[VAR]] to %struct.MyType addrspace(4)*
+  // CHECK: call void @_ZNU3AS46MyTypeD1Ev(%struct.MyType addrspace(4)* [[REG]])
+}
+
+// Ensure all members are defined for all the required address spaces.
+// CHECK-DEFINITIONS-DAG: define linkonce_odr void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* %this, i32 %i)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr void @_ZNU3AS46MyTypeC1Ei(%struct.MyType addrspace(4)* %this, i32 %i)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr void @_ZNU3AS26MyTypeD1Ev(%struct.MyType addrspace(2)* %this)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr void @_ZNU3AS46MyTypeD1Ev(%struct.MyType addrspace(4)* %this)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr i32 @_ZNU3AS26MyType3barEv(%struct.MyType addrspace(2)* %this)
+// CHECK-DEFINITIONS-DAG: define linkonce_odr i32 @_ZNU3AS46MyType3barEv(%struct.MyType addrspace(4)* %this)
Index: clang/test/CodeGenOpenCLCXX/addrspace-ctor.cl
===
--- clang/test/CodeGenOpenCLCXX/addrspace-ctor.cl
+++ /dev/null
@@ -1,14 +0,0 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s
-
-struct MyType {
-  MyType(int i) : i(i) {}
-  MyType(int i) __constant : i(i) {}
-  int i;
-};
-
-//CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const1, i32 1)
-__constant MyType const1 = 1;
-//CHECK: call void @_ZNU3AS26MyTypeC1Ei(%struct.MyType addrspace(2)* @const2, i32 2)
-__constant My

[PATCH] D64569: [OpenCL] Improve destructor support in C++ for OpenCL

2019-07-19 Thread Marco Antognini via Phabricator via cfe-commits
mantognini added a comment.

In D64569#1592059 , @rjmccall wrote:

> Yes, that's the right fix, although you might also consider adding a 
> `getObjectType()` to `CXXMemberCallExpr`.


Thanks, John, it should be better now, but let me know if I can improve 
something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64569



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


[PATCH] D64863: [clangd] Ignore diags from builtin files

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



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:563
 FillDiagBase(*LastDiag);
-adjustDiagFromHeader(*LastDiag, Info, *LangOpts);
+if (!InsideMainFile)
+  LastDiagWasAdjusted = adjustDiagFromHeader(*LastDiag, Info, *LangOpts);

ilya-biryukov wrote:
> We probably want to **always** set the value of this field to avoid 
> accidentally reading the flag for the previous `LastDiag`
I don't follow, this is always set in line `475` at the beginning of 
`HandleDiagnostic` method.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64863



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


[PATCH] D64592: [OpenMP] Fix declare target link implementation

2019-07-19 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea marked an inline comment as done.
gtbercea added inline comments.



Comment at: test/OpenMP/declare_target_link_codegen.cpp:22-23
+// HOST-DAG: @c_decl_tgt_ref_ptr = weak global i32* @c
+// HOST-DAG: @_{{.*}}d = internal global i32 2
+// HOST-DAG: @_{{.*}}d_{{.*}}_decl_tgt_ref_ptr = weak global i32* @_{{.*}}d
 // DEVICE-NOT: @c =

ABataev wrote:
> Better to define the variable with the name of the original `d` variable for 
> better and stable check
Can you rephrase your comment please? I don't understand what you'd like me to 
do here.

Do you want me to use  [[...]] to define the variable? 


Repository:
  rC Clang

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

https://reviews.llvm.org/D64592



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


[PATCH] D64592: [OpenMP] Fix declare target link implementation

2019-07-19 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 210854.
gtbercea added a comment.

- Address comments.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64592

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/declare_target_codegen.cpp
  test/OpenMP/declare_target_link_codegen.cpp
  test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp

Index: test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
===
--- test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
+++ test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
@@ -31,10 +31,10 @@
 }
 
 // CHECK-HOST: [[VAR:@.+]] = global double 1.00e+01
-// CHECK-HOST: [[VAR_DECL_TGT_LINK_PTR:@.+]] = global double* [[VAR]]
+// CHECK-HOST: [[VAR_DECL_TGT_LINK_PTR:@.+]] = weak global double* [[VAR]]
 
 // CHECK-HOST: [[TO_VAR:@.+]] = global double 2.00e+01
-// CHECK-HOST: [[VAR_DECL_TGT_TO_PTR:@.+]] = global double* [[TO_VAR]]
+// CHECK-HOST: [[VAR_DECL_TGT_TO_PTR:@.+]] = weak global double* [[TO_VAR]]
 
 // CHECK-HOST: [[OFFLOAD_SIZES:@.+]] = private unnamed_addr constant [2 x i64] [i64 4, i64 8]
 // CHECK-HOST: [[OFFLOAD_MAPTYPES:@.+]] = private unnamed_addr constant [2 x i64] [i64 800, i64 800]
@@ -45,8 +45,6 @@
 // CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [24 x i8]
 // CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*), i8* getelementptr inbounds ([24 x i8], [24 x i8]* [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 0, i32 0 }, section ".omp_offloading.entries"
 
-// CHECK-HOST: @llvm.used = appending global [2 x i8*] [i8* bitcast (double** [[VAR_DECL_TGT_LINK_PTR]] to i8*), i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*)], section "llvm.metadata"
-
 // CHECK-HOST: [[N_CASTED:%.+]] = alloca i64
 // CHECK-HOST: [[SUM_CASTED:%.+]] = alloca i64
 
@@ -75,10 +73,8 @@
 
 // CHECK-HOST: call i32 @__tgt_target(i64 -1, i8* @{{.*}}.region_id, i32 2, i8** [[BPTR7]], i8** [[BPTR8]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[OFFLOAD_SIZES]], i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[OFFLOAD_MAPTYPES]], i32 0, i32 0))
 
-// CHECK-DEVICE: [[VAR_LINK:@.+]] = common global double* null
-// CHECK-DEVICE: [[VAR_TO:@.+]] = common global double* null
-
-// CHECK-DEVICE: @llvm.used = appending global [2 x i8*] [i8* bitcast (double** [[VAR_LINK]] to i8*), i8* bitcast (double** [[VAR_TO]] to i8*)], section "llvm.metadata"
+// CHECK-DEVICE: [[VAR_LINK:@.+]] = weak global double* null
+// CHECK-DEVICE: [[VAR_TO:@.+]] = weak global double* null
 
 // CHECK-DEVICE: [[VAR_TO_PTR:%.+]] = load double*, double** [[VAR_TO]]
 // CHECK-DEVICE: load double, double* [[VAR_TO_PTR]]
Index: test/OpenMP/declare_target_link_codegen.cpp
===
--- test/OpenMP/declare_target_link_codegen.cpp
+++ test/OpenMP/declare_target_link_codegen.cpp
@@ -18,24 +18,31 @@
 #define HEADER
 
 // HOST-DAG: @c = external global i32,
-// HOST-DAG: @c_decl_tgt_ref_ptr = global i32* @c
+// HOST-DAG: @c_decl_tgt_ref_ptr = weak global i32* @c
+// HOST-DAG: @[[D:.+]] = internal global i32 2
+// HOST-DAG: @[[D_PTR:.+]] = weak global i32* @[[D]]
 // DEVICE-NOT: @c =
-// DEVICE: @c_decl_tgt_ref_ptr = common global i32* null
-// HOST: [[SIZES:@.+]] = private unnamed_addr constant [2 x i64] [i64 4, i64 4]
-// HOST: [[MAPTYPES:@.+]] = private unnamed_addr constant [2 x i64] [i64 35, i64 531]
+// DEVICE: @c_decl_tgt_ref_ptr = weak global i32* null
+// HOST: [[SIZES:@.+]] = private unnamed_addr constant [3 x i64] [i64 4, i64 4, i64 4]
+// HOST: [[MAPTYPES:@.+]] = private unnamed_addr constant [3 x i64] [i64 35, i64 531, i64 531]
 // HOST: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_decl_tgt_ref_ptr\00"
 // HOST: @.omp_offloading.entry.c_decl_tgt_ref_ptr = weak constant %struct.__tgt_offload_entry { i8* bitcast (i32** @c_decl_tgt_ref_ptr to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name, i32 0, i32 0), i64 8, i32 1, i32 0 }, section ".omp_offloading.entries", align 1
-// DEVICE-NOT: internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_decl_tgt_ref_ptr\00"
-// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32** @c_decl_tgt_ref_ptr to i8*)]
+// DEVICE-NOT: internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_{{.*}}_decl_tgt_ref_ptr\00"
+// HOST: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"_{{.*}}d_{{.*}}_decl_tgt_ref_ptr\00"
+// HOST: @.omp_offloading.entry.[[D_PTR]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (i32** @[[D_PTR]] to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name{{.*}}, i32 0, i32 0
 
 extern i

[PATCH] D64569: [OpenCL] Improve destructor support in C++ for OpenCL

2019-07-19 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall 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/D64569/new/

https://reviews.llvm.org/D64569



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


[PATCH] D64592: [OpenMP] Fix declare target link implementation

2019-07-19 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

LG with a nit.




Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:2595
+unsigned DeviceID, Line;
+unsigned FileID = 0;
+getTargetEntryUniqueInfo(CGM.getContext(),

No need to initialize FileID.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64592



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


[PATCH] D64592: [OpenMP] Fix declare target link implementation

2019-07-19 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 210856.
gtbercea added a comment.

- Address comments.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64592

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/declare_target_codegen.cpp
  test/OpenMP/declare_target_link_codegen.cpp
  test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp

Index: test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
===
--- test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
+++ test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
@@ -31,10 +31,10 @@
 }
 
 // CHECK-HOST: [[VAR:@.+]] = global double 1.00e+01
-// CHECK-HOST: [[VAR_DECL_TGT_LINK_PTR:@.+]] = global double* [[VAR]]
+// CHECK-HOST: [[VAR_DECL_TGT_LINK_PTR:@.+]] = weak global double* [[VAR]]
 
 // CHECK-HOST: [[TO_VAR:@.+]] = global double 2.00e+01
-// CHECK-HOST: [[VAR_DECL_TGT_TO_PTR:@.+]] = global double* [[TO_VAR]]
+// CHECK-HOST: [[VAR_DECL_TGT_TO_PTR:@.+]] = weak global double* [[TO_VAR]]
 
 // CHECK-HOST: [[OFFLOAD_SIZES:@.+]] = private unnamed_addr constant [2 x i64] [i64 4, i64 8]
 // CHECK-HOST: [[OFFLOAD_MAPTYPES:@.+]] = private unnamed_addr constant [2 x i64] [i64 800, i64 800]
@@ -45,8 +45,6 @@
 // CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [24 x i8]
 // CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*), i8* getelementptr inbounds ([24 x i8], [24 x i8]* [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 0, i32 0 }, section ".omp_offloading.entries"
 
-// CHECK-HOST: @llvm.used = appending global [2 x i8*] [i8* bitcast (double** [[VAR_DECL_TGT_LINK_PTR]] to i8*), i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*)], section "llvm.metadata"
-
 // CHECK-HOST: [[N_CASTED:%.+]] = alloca i64
 // CHECK-HOST: [[SUM_CASTED:%.+]] = alloca i64
 
@@ -75,10 +73,8 @@
 
 // CHECK-HOST: call i32 @__tgt_target(i64 -1, i8* @{{.*}}.region_id, i32 2, i8** [[BPTR7]], i8** [[BPTR8]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[OFFLOAD_SIZES]], i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[OFFLOAD_MAPTYPES]], i32 0, i32 0))
 
-// CHECK-DEVICE: [[VAR_LINK:@.+]] = common global double* null
-// CHECK-DEVICE: [[VAR_TO:@.+]] = common global double* null
-
-// CHECK-DEVICE: @llvm.used = appending global [2 x i8*] [i8* bitcast (double** [[VAR_LINK]] to i8*), i8* bitcast (double** [[VAR_TO]] to i8*)], section "llvm.metadata"
+// CHECK-DEVICE: [[VAR_LINK:@.+]] = weak global double* null
+// CHECK-DEVICE: [[VAR_TO:@.+]] = weak global double* null
 
 // CHECK-DEVICE: [[VAR_TO_PTR:%.+]] = load double*, double** [[VAR_TO]]
 // CHECK-DEVICE: load double, double* [[VAR_TO_PTR]]
Index: test/OpenMP/declare_target_link_codegen.cpp
===
--- test/OpenMP/declare_target_link_codegen.cpp
+++ test/OpenMP/declare_target_link_codegen.cpp
@@ -18,24 +18,31 @@
 #define HEADER
 
 // HOST-DAG: @c = external global i32,
-// HOST-DAG: @c_decl_tgt_ref_ptr = global i32* @c
+// HOST-DAG: @c_decl_tgt_ref_ptr = weak global i32* @c
+// HOST-DAG: @[[D:.+]] = internal global i32 2
+// HOST-DAG: @[[D_PTR:.+]] = weak global i32* @[[D]]
 // DEVICE-NOT: @c =
-// DEVICE: @c_decl_tgt_ref_ptr = common global i32* null
-// HOST: [[SIZES:@.+]] = private unnamed_addr constant [2 x i64] [i64 4, i64 4]
-// HOST: [[MAPTYPES:@.+]] = private unnamed_addr constant [2 x i64] [i64 35, i64 531]
+// DEVICE: @c_decl_tgt_ref_ptr = weak global i32* null
+// HOST: [[SIZES:@.+]] = private unnamed_addr constant [3 x i64] [i64 4, i64 4, i64 4]
+// HOST: [[MAPTYPES:@.+]] = private unnamed_addr constant [3 x i64] [i64 35, i64 531, i64 531]
 // HOST: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_decl_tgt_ref_ptr\00"
 // HOST: @.omp_offloading.entry.c_decl_tgt_ref_ptr = weak constant %struct.__tgt_offload_entry { i8* bitcast (i32** @c_decl_tgt_ref_ptr to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name, i32 0, i32 0), i64 8, i32 1, i32 0 }, section ".omp_offloading.entries", align 1
-// DEVICE-NOT: internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_decl_tgt_ref_ptr\00"
-// CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (i32** @c_decl_tgt_ref_ptr to i8*)]
+// DEVICE-NOT: internal unnamed_addr constant [{{[0-9]+}} x i8] c"c_{{.*}}_decl_tgt_ref_ptr\00"
+// HOST: @.omp_offloading.entry_name{{.*}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"_{{.*}}d_{{.*}}_decl_tgt_ref_ptr\00"
+// HOST: @.omp_offloading.entry.[[D_PTR]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (i32** @[[D_PTR]] to i8*), i8* getelementptr inbounds ([{{[0-9]+}} x i8], [{{[0-9]+}} x i8]* @.omp_offloading.entry_name{{.*}}, i32 0, i32 0
 
 extern i

[PATCH] D64780: Disallow most calling convention attributes on PS4.

2019-07-19 Thread Sunil Srivastava via Phabricator via cfe-commits
Sunil_Srivastava marked an inline comment as done.
Sunil_Srivastava added inline comments.



Comment at: lib/Basic/Targets/OSTargets.h:564
   }
+  TargetInfo::CallingConvCheckResult checkCallingConvention(CallingConv CC) 
const override {
+return (CC == CC_C) ? TargetInfo::CCCR_OK : TargetInfo::CCCR_Error;

aaron.ballman wrote:
> Line length seems a bit long for coding style requirements.
Ooops. You are right. Will split according to clang-format. Would you want me 
to update the review?


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

https://reviews.llvm.org/D64780



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


r366592 - [Format/ObjC] Avoid breaking between unary operators and operands

2019-07-19 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Fri Jul 19 09:50:24 2019
New Revision: 366592

URL: http://llvm.org/viewvc/llvm-project?rev=366592&view=rev
Log:
[Format/ObjC] Avoid breaking between unary operators and operands

Summary:
Test Plan:
  New tests added. Ran tests with:
  % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests
  Confirmed tests failed before change and passed after change.

Reviewers: krasimir, djasper, sammccall, klimek

Reviewed By: sammccall

Subscribers: klimek, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=366592&r1=366591&r2=366592&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Jul 19 09:50:24 2019
@@ -2429,6 +2429,8 @@ unsigned TokenAnnotator::splitPenalty(co
   if (Left.is(TT_JavaAnnotation))
 return 50;
 
+  if (Left.is(TT_UnaryOperator))
+return 60;
   if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
   Left.Previous->isLabelString() &&
   (Left.NextOperator || Left.OperatorIndex != 0))

Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=366592&r1=366591&r2=366592&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Fri Jul 19 09:50:24 2019
@@ -886,6 +886,18 @@ TEST_F(FormatTestObjC, FormatObjCMethodE
" bb:42\n"
" cc:42];");
 
+  // Avoid breaking between unary operators and ObjC method expressions.
+  Style.ColumnLimit = 45;
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "![foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "+[foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "-[foo bar]) {\n"
+   "}");
+
   Style.ColumnLimit = 70;
   verifyFormat(
   "void f() {\n"


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


[PATCH] D64744: #pragma clang loop vectorize_predicate(enable|disable)

2019-07-19 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer updated this revision to Diff 210857.
SjoerdMeijer added a comment.

Removed the separate function that created the loop.llvm.vectorize.predicate 
metadata. This is now just part of function `createLoopVectorizeMetadata`, that 
creates all other vectorize metadata.


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

https://reviews.llvm.org/D64744

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/CodeGen/CGLoopInfo.cpp
  clang/lib/CodeGen/CGLoopInfo.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/AST/ast-print-pragmas.cpp
  clang/test/CodeGenCXX/pragma-loop.cpp
  clang/test/Parser/pragma-loop.cpp
  clang/test/Parser/pragma-unroll-and-jam.cpp

Index: clang/test/Parser/pragma-unroll-and-jam.cpp
===
--- clang/test/Parser/pragma-unroll-and-jam.cpp
+++ clang/test/Parser/pragma-unroll-and-jam.cpp
@@ -67,7 +67,7 @@
   }
 
 // pragma clang unroll_and_jam is disabled for the moment
-/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, or distribute}} */ #pragma clang loop unroll_and_jam(4)
+/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, or distribute}} */ #pragma clang loop unroll_and_jam(4)
   for (int i = 0; i < Length; i++) {
 for (int j = 0; j < Length; j++) {
   List[i * Length + j] = Value;
Index: clang/test/Parser/pragma-loop.cpp
===
--- clang/test/Parser/pragma-loop.cpp
+++ clang/test/Parser/pragma-loop.cpp
@@ -81,6 +81,7 @@
 
 #pragma clang loop vectorize(enable)
 #pragma clang loop interleave(enable)
+#pragma clang loop vectorize_predicate(enable)
 #pragma clang loop unroll(full)
   while (i + 1 < Length) {
 List[i] = i;
@@ -95,6 +96,7 @@
 
 #pragma clang loop vectorize(disable)
 #pragma clang loop interleave(disable)
+#pragma clang loop vectorize_predicate(disable)
 #pragma clang loop unroll(disable)
   while (i - 1 < Length) {
 List[i] = i;
@@ -111,7 +113,7 @@
   }
 
   int VList[Length];
-#pragma clang loop vectorize(disable) interleave(disable) unroll(disable)
+#pragma clang loop vectorize(disable) interleave(disable) unroll(disable) vectorize_predicate(disable)
   for (int j : VList) {
 VList[j] = List[j];
   }
@@ -130,11 +132,13 @@
 
 /* expected-error {{expected '('}} */ #pragma clang loop vectorize
 /* expected-error {{expected '('}} */ #pragma clang loop interleave
+/* expected-error {{expected '('}} */ #pragma clang loop vectorize_predicate
 /* expected-error {{expected '('}} */ #pragma clang loop unroll
 /* expected-error {{expected '('}} */ #pragma clang loop distribute
 
 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(enable
 /* expected-error {{expected ')'}} */ #pragma clang loop interleave(enable
+/* expected-error {{expected ')'}} */ #pragma clang loop vectorize_predicate(enable
 /* expected-error {{expected ')'}} */ #pragma clang loop unroll(full
 /* expected-error {{expected ')'}} */ #pragma clang loop distribute(enable
 
@@ -147,7 +151,7 @@
 /* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll()
 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute()
 
-/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, or distribute}} */ #pragma clang loop
+/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, or distribute}} */ #pragma clang loop
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable)
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword(4)
@@ -245,6 +249,8 @@
 /* expected-error {{duplicate directives 'vectorize(enable)' and 'vectorize(disable)'}} */ #pragma clang loop vectorize(disable)
 #pragma clang loop interleave(enable)
 /* expected-error {{duplicate directives 'interleave(enable)' and 'interleave(disable)'}} */ #pragma clang loop interleave(disable)
+#pragma clang loop vectorize_predicate(enable)
+/* expected-error {{duplicate directives 'vectorize_predicate(enable)' and 'vectorize_predicate(disable)'}} */ #pragma clang loop vectorize_predicate(disable)
 #pragma clang loop unroll(full)
 /* expected-error {{duplicate directives 'unroll(full)' and 'unroll(disable)'}} */ #pragma clang loop unroll(disable)

[PATCH] D64775: [Format/ObjC] Avoid breaking between unary operators and operands

2019-07-19 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366592: [Format/ObjC] Avoid breaking between unary operators 
and operands (authored by benhamilton, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64775?vs=210095&id=210859#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64775

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestObjC.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2429,6 +2429,8 @@
   if (Left.is(TT_JavaAnnotation))
 return 50;
 
+  if (Left.is(TT_UnaryOperator))
+return 60;
   if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
   Left.Previous->isLabelString() &&
   (Left.NextOperator || Left.OperatorIndex != 0))
Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp
===
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp
@@ -886,6 +886,18 @@
" bb:42\n"
" cc:42];");
 
+  // Avoid breaking between unary operators and ObjC method expressions.
+  Style.ColumnLimit = 45;
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "![foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "+[foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "-[foo bar]) {\n"
+   "}");
+
   Style.ColumnLimit = 70;
   verifyFormat(
   "void f() {\n"


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2429,6 +2429,8 @@
   if (Left.is(TT_JavaAnnotation))
 return 50;
 
+  if (Left.is(TT_UnaryOperator))
+return 60;
   if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
   Left.Previous->isLabelString() &&
   (Left.NextOperator || Left.OperatorIndex != 0))
Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp
===
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp
@@ -886,6 +886,18 @@
" bb:42\n"
" cc:42];");
 
+  // Avoid breaking between unary operators and ObjC method expressions.
+  Style.ColumnLimit = 45;
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "![foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "+[foo bar]) {\n"
+   "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+   "-[foo bar]) {\n"
+   "}");
+
   Style.ColumnLimit = 70;
   verifyFormat(
   "void f() {\n"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2019-07-19 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added inline comments.



Comment at: clang-tidy/bugprone/InfiniteLoopCheck.cpp:25
+
+static bool isAccessForVar(const Stmt *St, const VarDecl *Var) {
+  if (const auto *DRE = dyn_cast(St))

St => S

"S" is a common abbreviation in the Clang codebase, "St" isn't.

(everywhere in the patch)



Comment at: clang-tidy/bugprone/InfiniteLoopCheck.cpp:49
+
+static bool hasPtrOrReferenceBefore(const Stmt *St, const Stmt *LoopStmt,
+const VarDecl *Var) {

Please add documentation comments.



Comment at: clang-tidy/bugprone/InfiniteLoopCheck.cpp:92
+   ASTContext *Context) {
+  if (const auto *DRE = dyn_cast(Cond)) {
+if (const auto *Var = dyn_cast(DRE->getDecl())) {

Please separate the logic that finds variables from the rest of the logic.

Finding variables has to be recursive, the rest does not have to be.



Comment at: clang-tidy/bugprone/InfiniteLoopCheck.cpp:160
+  allOf(hasCondition(expr().bind("condition")),
+unless(hasBody(hasDescendant(loopEndingStmt();
+

hasDescendant will recurse into other functions defined in the loop body, for 
example into lambdas.

```
for (...) {
  auto x = []() { throw 0; }
}
```

You can add the forFunction matcher to the loop ending statement matcher, and 
then use equalsNode to confirm that the loop ending statement is in the same 
function as the for loop.

Please also add tests for this case.



Comment at: clang-tidy/bugprone/InfiniteLoopCheck.cpp:181
+
+  diag(getFirstCondVar(Cond)->getLocation(),
+   "None of the condition variables "

I'd suggest to attach the diagnostic to the loop -- the problem is with the 
loop, not with the first reference to the variable.



Comment at: clang-tidy/bugprone/InfiniteLoopCheck.cpp:182
+  diag(getFirstCondVar(Cond)->getLocation(),
+   "None of the condition variables "
+   "(%0) are updated in the loop body")

ClangTidy messages are sentence fragments that start with a lowercase letter.

It would be also helpful to state the problem explicitly.

"this loop is infinite; none of its condition variables are updated in the loop 
body"



Comment at: docs/clang-tidy/checks/bugprone-infinite-loop.rst:6
+
+Checks for obvious infinite loops (loops where the condition variable is not
+changed at all).

s/checks for/finds/ (everywhere in the patch)



Comment at: docs/clang-tidy/checks/bugprone-infinite-loop.rst:9
+
+Detecting infinite loops by a finite program is well known to be impossible
+(Halting-problem). However there are some simple but common cases where it

"Finding infinite loops is well-known to be impossible (halting problem)."



Comment at: docs/clang-tidy/checks/bugprone-infinite-loop.rst:10
+Detecting infinite loops by a finite program is well known to be impossible
+(Halting-problem). However there are some simple but common cases where it
+is possible: the loop condition is not changed in the loop at all. This check

"However, it is possible to detect some obvious infinite loops, for example, if 
the loop condition is not changed."



Comment at: docs/clang-tidy/checks/bugprone-infinite-loop.rst:16
+
+- It is a local variable of the function.
+- It has no reference or pointer aliases before or inside the loop.

"It is a local variable" (local variables can only be declared in functions)



Comment at: docs/clang-tidy/checks/bugprone-infinite-loop.rst:18
+- It has no reference or pointer aliases before or inside the loop.
+- It is no member expression.
+

I don't quite understand what you mean by "it is no member expression". Also, 
users likely won't understand the term "member expression".



Comment at: docs/clang-tidy/checks/bugprone-infinite-loop.rst:23
+
+For example, the following loop is considered as infinite since mistakenly
+`j` is incremented instead of `i`:

s/considered as infinite/considered infinite/



Comment at: docs/clang-tidy/checks/bugprone-infinite-loop.rst:24
+For example, the following loop is considered as infinite since mistakenly
+`j` is incremented instead of `i`:
+

I don't think we can say the "mistakenly" part. Explaining checker's behavior 
like that suggests that the checker detects the user's intent, which it does 
not. For example, it could also be the case that the user wanted to increment 
both i and j in the loop body.

All we can say is the loop is infinite because in the loop condition "i < 10" 
all variables (i) never change.



Comment at: test/clang-tidy/bugprone-infinite-loop.cpp:43
+  int Limit = 100;
+  while (i < Limit) { // Not an error

[PATCH] D64762: [AST] Treat semantic form of InitListExpr as implicit code in traversals

2019-07-19 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr accepted this revision.
gribozavr added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:2332
   S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
   TRY_TO(TraverseSynOrSemInitListExpr(
   S->isSemanticForm() ? S : S->getSemanticForm(), Queue));

ilya-biryukov wrote:
> ilya-biryukov wrote:
> > gribozavr wrote:
> > > Instead of adding a whole new if statement, could you wrap the second 
> > > existing TRY_TO in `if(shouldVisitImplicitCode())` ?
> > Despite looking very similar, that would **not** be equivalent to the 
> > current version.
> > 
> > For most init lists (that do not have alternative "form"), the following 
> > invariants hold:
> > ```
> > InitList* E = ...;
> > assert(E->isSemanticForm());
> > assert(E->isSyntacticForm()); 
> > assert(E->getSynacticForm() == nullptr);
> > ```
> > 
> > This subtle fact means the current code does not traversed the list twice 
> > if they do not have an alternative form (either semantic or syntactic).
> > 
> > Now, if we only run the first statement, we will call 
> > `TraverseSynOrSemInitListExpr(S->getSyntacticForm())` and 
> > `S->getSyntacticForm()` returns `null`. So we don't traverse anything.
> > 
> > I tried various ways to keep both calls, but they all ended up being too 
> > complicated, hence the final version. Let me know if you see a better way 
> > to address this.
> To make the last sentence less confusing:
> I tried various ways to keep **only two** calls, but they were too 
> complicated and I ended up introducing an extra call to `TraverseSyn...` 
> instead.
> 
> assert(E->getSynacticForm() == nullptr);

That's... a really nice API.

What do you think about the following:

```
if (S->isSyntacticForm() && S->isSemanticForm()) {
  // `S` does not have alternative forms, traverse the only form that's 
available.
  TRY_TO(TraverseSynOrSemInitListExpr(S, Queue));
  return true;
}

TRY_TO(TraverseSynOrSemInitListExpr(
  S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
if (getDerived().shouldVisitImplicitCode()) {
  TRY_TO(TraverseSynOrSemInitListExpr(
S->isSyntacticForm() ? S->getSemanticForm() : S, Queue));
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64762



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


[PATCH] D44100: [ASTImporter] Reorder fields after structure import is finished

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

- Further simplify by removing the last for loop


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D44100

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1472,7 +1472,7 @@
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
-   DISABLED_CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) {
+   CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
   // The original recursive algorithm of ASTImporter first imports 'c' then
@@ -5232,5 +5232,16 @@
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, LLDBLookupTest,
 DefaultTestValuesForRunOptions, );
 
+TEST_P(ImportDecl, ImportFieldOrder) {
+  MatchVerifier Verifier;
+  testImport("struct declToImport {"
+ "  int b = a + 2;"
+ "  int a = 5;"
+ "};",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ recordDecl(hasFieldOrder({"b", "a"})));
+}
+
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1645,7 +1645,6 @@
   bool AccumulateChildErrors = isa(FromDC);
 
   Error ChildErrors = Error::success();
-  llvm::SmallVector ImportedDecls;
   for (auto *From : FromDC->decls()) {
 ExpectedDecl ImportedOrErr = import(From);
 if (!ImportedOrErr) {
@@ -1657,6 +1656,58 @@
 }
   }
 
+  // We reorder declarations in RecordDecls because they may have another order
+  // in the "to" context than they have in the "from" context. This may happen
+  // e.g when we import a class like this:
+  //struct declToImport {
+  //int a = c + b;
+  //int b = 1;
+  //int c = 2;
+  //};
+  // During the import of `a` we import first the dependencies in sequence,
+  // thus the order would be `c`, `b`, `a`. We will get the normal order by
+  // first removing the already imported members and then adding them in the
+  // order as they apper in the "from" context.
+  //
+  // Keeping field order is vital because it determines structure layout.
+  //
+  // Here and below, we cannot call field_begin() method and its callers on
+  // ToDC if it has an external storage. Calling field_begin() will
+  // automatically load all the fields by calling
+  // LoadFieldsFromExternalStorage().  LoadFieldsFromExternalStorage() would
+  // call ASTImporter::Import(). This is because the ExternalASTSource
+  // interface in LLDB is implemented by the means of the ASTImporter. However,
+  // calling an import at this point would result in an uncontrolled import, we
+  // must avoid that.
+  const auto *FromRD = dyn_cast(FromDC);
+  if (!FromRD)
+return ChildErrors;
+  auto ToDCOrErr = Importer.ImportContext(FromDC);
+  if (!ToDCOrErr) {
+consumeError(std::move(ChildErrors));
+return ToDCOrErr.takeError();
+  }
+
+  DeclContext *ToDC = *ToDCOrErr;
+  // Remove all declarations, which may be in wrong order in the
+  // lexical DeclContext and then add them in the proper order.
+  for (auto *D : FromRD->decls()) {
+if (isa(D) || isa(D)) {
+  assert(D && "DC has a contained decl which is null?");
+  Decl *ToD = Importer.GetAlreadyImportedOrNull(D);
+  // Remove only the decls which we successfully imported.
+  if (ToD) {
+assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
+// Remove the decl from its wrong place in the linked list.
+ToDC->removeDecl(ToD);
+// Add the decl to the end of the linked list.
+// This time it will be at the proper place because the enclosing for
+// loop iterates in the original (good) order of the decls.
+ToDC->addDeclInternal(ToD);
+  }
+}
+  }
+
   return ChildErrors;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62648: [Sema][Typo] Fix assertion failure for expressions with multiple typos

2019-07-19 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 210862.
dgoldman added a comment.

- Minor fixes


Repository:
  rC Clang

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

https://reviews.llvm.org/D62648

Files:
  lib/Sema/SemaExprCXX.cpp
  test/Sema/typo-correction-recursive.cpp
  test/SemaCXX/typo-correction-cxx11.cpp

Index: test/SemaCXX/typo-correction-cxx11.cpp
===
--- test/SemaCXX/typo-correction-cxx11.cpp
+++ test/SemaCXX/typo-correction-cxx11.cpp
@@ -50,10 +50,10 @@
 };
 
 void run(A *annotations) {
-  map new_annotations;
+  map annotation_map;
 
   auto &annotation = *annotations;
-  auto new_it = new_annotations.find(5);
+  auto new_it = annotation_map.find(5);
   auto &new_anotation = new_it.second;  // expected-note {{'new_anotation' declared here}}
   new_annotation->Swap(&annotation);  // expected-error {{use of undeclared identifier 'new_annotation'; did you mean 'new_anotation'?}}
 }
Index: test/Sema/typo-correction-recursive.cpp
===
--- /dev/null
+++ test/Sema/typo-correction-recursive.cpp
@@ -0,0 +1,120 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Check the following typo correction behavior:
+// - multiple typos in a single member call chain are all diagnosed
+// - no typos are diagnosed for multiple typos in an expression when not all
+//   typos can be corrected
+
+class DeepClass
+{
+public:
+  void trigger() const;  // expected-note {{'trigger' declared here}}
+};
+
+class Y
+{
+public:
+  const DeepClass& getX() const { return m_deepInstance; }  // expected-note {{'getX' declared here}}
+private:
+  DeepClass m_deepInstance;
+  int m_n;
+};
+
+class Z
+{
+public:
+  const Y& getY0() const { return m_y0; }  // expected-note {{'getY0' declared here}}
+  const Y& getActiveY() const { return m_y0; }
+
+private:
+  Y m_y0;
+  Y m_y1;
+};
+
+Z z_obj;
+
+void testMultipleCorrections()
+{
+  z_obj.getY2().  // expected-error {{no member named 'getY2' in 'Z'; did you mean 'getY0'}}
+  getM(). // expected-error {{no member named 'getM' in 'Y'; did you mean 'getX'}}
+  triggee();  // expected-error {{no member named 'triggee' in 'DeepClass'; did you mean 'trigger'}}
+}
+
+void testNoCorrections()
+{
+  z_obj.getY2().  // expected-error {{no member named 'getY2' in 'Z'}}
+  getM().
+  thisDoesntSeemToMakeSense();
+}
+
+struct C {};
+struct D { int value; };
+struct A {
+  C get_me_a_C();
+};
+struct B {
+  D get_me_a_D();  // expected-note {{'get_me_a_D' declared here}}
+};
+class Scope {
+public:
+  A make_an_A();
+  B make_a_B();  // expected-note {{'make_a_B' declared here}}
+};
+
+Scope scope_obj;
+
+int testDiscardedCorrections() {
+  return scope_obj.make_an_E().  // expected-error {{no member named 'make_an_E' in 'Scope'; did you mean 'make_a_B'}}
+  get_me_a_Z().value;// expected-error {{no member named 'get_me_a_Z' in 'B'; did you mean 'get_me_a_D'}}
+}
+
+class AmbiguousHelper {
+public:
+  int helpMe();
+  int helpBe();
+};
+class Ambiguous {
+public:
+  int calculateA();
+  int calculateB();
+
+  AmbiguousHelper getHelp1();
+  AmbiguousHelper getHelp2();
+};
+
+Ambiguous ambiguous_obj;
+
+int testDirectAmbiguousCorrection() {
+  return ambiguous_obj.calculateZ();  // expected-error {{no member named 'calculateZ' in 'Ambiguous'}}
+}
+
+int testRecursiveAmbiguousCorrection() {
+  return ambiguous_obj.getHelp3().// expected-error {{no member named 'getHelp3' in 'Ambiguous'}}
+  helpCe();
+}
+
+
+class DeepAmbiguityHelper {
+public:
+  DeepAmbiguityHelper& help1();
+  DeepAmbiguityHelper& help2();
+
+  DeepAmbiguityHelper& methodA();
+  DeepAmbiguityHelper& somethingMethodB();
+  DeepAmbiguityHelper& functionC();
+  DeepAmbiguityHelper& deepMethodD();
+  DeepAmbiguityHelper& asDeepAsItGets();
+};
+
+DeepAmbiguityHelper deep_obj;
+
+int testDeepAmbiguity() {
+  deep_obj.
+  methodB(). // expected-error {{no member named 'methodB' in 'DeepAmbiguityHelper'}}
+  somethingMethodC().
+  functionD().
+  deepMethodD().
+  help3().
+  asDeepASItGet().
+  functionE();
+}
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -7610,15 +7610,22 @@
   llvm::SmallDenseMap OverloadResolution;
 
   /// Emit diagnostics for all of the TypoExprs encountered.
+  ///
   /// If the TypoExprs were successfully corrected, then the diagnostics should
   /// suggest the corrections. Otherwise the diagnostics will not suggest
   /// anything (having been passed an empty TypoCorrection).
-  void EmitAllDiagnostics() {
+  ///
+  /// If we've failed to correct due to ambiguous corrections, we need to
+  /// be sure to pass empty corrections and replacements. Otherwise it's
+  /// possible that the Consumer has a TypoCorrection that failed to ambiguity
+  /// and we don't want to report those diagnosti

[PATCH] D65003: [clang-doc] Add index in each info html file

2019-07-19 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich, lebedev.ri.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman, mgrang, mgorny.

An index structure is created while reducing the infos. This is then passed to 
the HTML generator so it's included in each file created.
Paths in the index are fixed (relative to the current file) for each file.
Index is currently rendered on top of the info content, this will be fixed 
later with CSS.


https://reviews.llvm.org/D65003

Files:
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/unittests/clang-doc/ClangDocTest.h
  clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -40,7 +40,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -94,7 +94,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -158,7 +158,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -206,7 +206,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -343,7 +343,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -38,7 +38,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# namespace Namespace
 
@@ -101,7 +101,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# class r
 
@@ -162,7 +162,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(### f
 
@@ -190,7 +190,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(| enum class e |
 
@@ -320,7 +320,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(&I, Actual);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(### f
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -9,6 +9,7 @@
 #include "ClangDocTest.h"
 #include "Gener

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

2019-07-19 Thread Jussi Pakkanen via Phabricator via cfe-commits
jpakkane marked 4 inline comments as done.
jpakkane added inline comments.



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

alexfh wrote:
> jpakkane wrote:
> > alexfh wrote:
> > > jpakkane wrote:
> > > > alexfh wrote:
> > > > > jpakkane wrote:
> > > > > > alexfh wrote:
> > > > > > > I believe, this should skip matches within template 
> > > > > > > instantiations. Consider this code:
> > > > > > > ```
> > > > > > > template
> > > > > > > void f(T) { T t; }
> > > > > > > void g() {
> > > > > > > f(0);
> > > > > > > f(0.0);
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > What will the fix  be?
> > > > > > I tested with the following function:
> > > > > > 
> > > > > > 
> > > > > > ```
> > > > > > template
> > > > > > void template_test_function() {
> > > > > >   T t;
> > > > > >   int uninitialized;
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > Currently it warns on the "uninitialized" variable regardless of 
> > > > > > whether the template is instantiated or not. If you call it with an 
> > > > > > int type, it will warn about variable t being uninitialized. If you 
> > > > > > call it with a, say, struct type, there is no warnings. Is this a 
> > > > > > reasonable approach?
> > > > > And what happens, if there are multiple instantiations of the same 
> > > > > template, each of them requiring a different fix? Can you try the 
> > > > > check with my example above (and maybe also add `f("");`inside 
> > > > > `g()`). I believe, the check will produce multiple warnings with 
> > > > > conflicting fixes (and each of them will be wrong, btw).
> > > > Interestingly it does warn about it, but only once, even if you have 
> > > > two different template specializations.
> > > > 
> > > > I tried to suppress this warning when the type being instantiated is a 
> > > > template argument type but no matter what I tried I could not get this 
> > > > to work. Is there a way to get this information from the MatchedDecl 
> > > > object or does one need to do something more complicated like going up 
> > > > the AST until a function definition is found and checking if it is a 
> > > > template specialization (presumably with TemplatedKind)? Any help would 
> > > > be appreciated.
> > > If there are multiple warnings with the same message at the same location 
> > > (clang-tidy/ClangTidyDiagnosticConsumer.cpp:745), they will be 
> > > deduplicated. Thus, a random fix will probably be suggested. The proper 
> > > way to filter out matches in template instantiations is to add 
> > > `unless(isInTemplateInstantiation())` to the matcher.
> > I tried to make this work but I just could not combine statement and 
> > declaration matching in a reliable way. Matching a statement that is not in 
> > a template declaration can be done, as well as matching a declaration 
> > without intial value, but combining those two into one is hard. After 
> > trying many, many things the best I could come up with was this:
> > 
> > ```
> > declStmt(containsDeclaration(0, 
> > varDecl(unless(hasInitializer(anything(.bind("vardecl"))), this)
> > ```
> > 
> > The problem is that `containsDeclaration` takes an integer denoting how 
> > manyth declaration should be processed. Manually adding matchers for, say, 
> > 0, 1, 2, 3 and 4 works and does the right thing but fails if anyone has an 
> > uninitialized variable in the sixth location, things will silently fail.
> > 
> > The weird thing is that if you do the matching this way, you don't need to 
> > filter out things with `unless(isInTemplateInstantiation())`. Maybe 
> > statements are handled differently from declarations?
> I was struggling to understand, why you want to match a statement, but then I 
> figured out that I should have been more precise: while 
> `isInTemplateInstantiation` only works for `Stmt`s, there's a related matcher 
> that works for `Decl`s: `isInstantiated`. See 
> clang/include/clang/ASTMatchers/ASTMatchers.h:5187. In general, looking into 
> this header can be useful, if you want to find a matcher that you can vaguely 
> describe (e.g. when looking for something related to instantiations, you can 
> search for the relevant substring and find  this and a bunch of other 
> matchers).
> 
> Sorry for the confusion. I hope, the suggestion helps.
Thanks, got it working now.



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

alexfh wrote:
> jpakkane wrote:
> > alexfh wrote:
> > > Should this just disallow all fixes within macros? Maybe warnings as well.
> > I can change that, seems reasonable. Should it still retain this check, 
> > though? One would i

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

2019-07-19 Thread Jussi Pakkanen via Phabricator via cfe-commits
jpakkane updated this revision to Diff 210868.
jpakkane added a comment.

Now properly deals with template instantiations and macros.


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

https://reviews.llvm.org/D64671

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp
  clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-init-local-variables.rst
  clang-tools-extra/test/clang-tidy/misc-init-local-variables.cpp

Index: clang-tools-extra/test/clang-tidy/misc-init-local-variables.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/misc-init-local-variables.cpp
@@ -0,0 +1,99 @@
+// RUN: %check_clang_tidy %s misc-init-local-variables %t
+
+#include 
+
+#define DO_NOTHING(x) ((void)x)
+
+// Ensure that function declarations are not changed.
+void some_func(int x, double d, bool b, const char *p);
+
+int do_not_modify_me;
+
+typedef struct {
+  int unaltered1;
+  int unaltered2;
+} UnusedStruct;
+
+typedef int my_int_type;
+#define MACRO_INT int
+#define FULL_DECLARATION() int macrodecl;
+
+template 
+void template_test_function() {
+  T t;
+  int uninitialized;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'uninitialized' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int uninitialized = 0;{{$}}
+
+  DO_NOTHING(t);
+  DO_NOTHING(uninitialized);
+}
+
+void init_unit_tests() {
+  int x;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'x' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int x = 0;{{$}}
+  int32_t sized_var;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: variable 'sized_var' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int32_t sized_var = 0;{{$}}
+  my_int_type myint;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'myint' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  my_int_type myint = 0;{{$}}
+
+  MACRO_INT macroint;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'macroint' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  MACRO_INT macroint = 0;{{$}}
+  FULL_DECLARATION();
+
+  int x0 = 1, x1, x2 = 2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'x1' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int x0 = 1, x1 = 0, x2 = 2;{{$}}
+  int y0, y1 = 1, y2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'y0' is not initialized [misc-init-local-variables]
+  // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: variable 'y2' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  int y0 = 0, y1 = 1, y2 = 0;{{$}}
+  int hasval = 42;
+
+  float f;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'f' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  float f = (0.0/0.0);{{$}}
+  float fval = 85.0;
+  double d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: variable 'd' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  double d = (0.0/0.0);{{$}}
+  double dval = 99.0;
+
+  bool b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  bool b = 0;{{$}}
+  bool bval = true;
+
+  const char *ptr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'ptr' is not initialized [misc-init-local-variables]
+  // CHECK-FIXES: {{^}}  const char *ptr = nullptr;{{$}}
+  const char *ptrval = "a string";
+
+  UnusedStruct u;
+
+  DO_NOTHING(x);
+  DO_NOTHING(sized_var);
+  DO_NOTHING(myint);
+  DO_NOTHING(macroint);
+  DO_NOTHING(macrodecl);
+  DO_NOTHING(x0);
+  DO_NOTHING(x1);
+  DO_NOTHING(x2);
+  DO_NOTHING(y0);
+  DO_NOTHING(y1);
+  DO_NOTHING(y2);
+  DO_NOTHING(hasval);
+  DO_NOTHING(f);
+  DO_NOTHING(fval);
+  DO_NOTHING(d);
+  DO_NOTHING(dval);
+  DO_NOTHING(b);
+  DO_NOTHING(bval);
+  DO_NOTHING(ptr);
+  DO_NOTHING(ptrval);
+  DO_NOTHING(u);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/misc-init-local-variables.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-init-local-variables.rst
@@ -0,0 +1,36 @@
+.. title:: clang-tidy - misc-init-local-variables
+
+misc-init-local-variables
+=
+
+Checks whether there are local variables that are declared without an
+initial value. These may lead to unexpected behaviour if there is a
+code path that reads the variable before assigning to it.
+
+Only integers, booleans, floats, doubles and pointers are checked. The
+fix option initializes all detected values with the value of zero. An
+exception is float and double types, which are initialized to NaN.
+

  1   2   >