[PATCH] D60455: [SYCL] Add support for SYCL device attributes

2019-04-18 Thread Ronan Keryell via Phabricator via cfe-commits
keryell added a comment.

In D60455#1470402 , @Anastasia wrote:

>




> In the interest of speeding up the upstreaming work, would you be able to 
> highlight the differences and similarity at least for SYCL and OpenCL kernel 
> modes? Not sure if you are familiar enough with both. Because apart from the 
> public announcements I can't see what has been changed in SYCL that would 
> disallow to use OpenCL mode. It would be a valuable input to determine the 
> implementation choices.

SYCL is similar to OpenMP 5 for C++, where you use only C++ classes instead of 
`#pragma`. So it is quite C++-friendlier than OpenMP.
But that means also there is not the same concept of explicit kernel like in 
OpenCL or CUDA. In OpenCL or CUDA, when there is a function with a specific 
attribute, you know it is a kernel and you can compile as such.

In SYCL or OpenMP you need an outliner that will estimate what should be 
executed as an heterogeneous kernel, split the code between the host side and 
the device side, add some glue/stub to implement an RPC between the host and 
the device, manage potentially some allocation/memory transfers, etc. This is 
quite more complex than compiling OpenCL, CUDA or other graphics shader 
languages. This is also why, while SYCL is technically pure standard C++, you 
need some specific compiler magic to do the code massaging to have everything 
working well between a host and some devices.

The attribute we discuss here is just an implementation detail to help the 
coordination between the compiler and the SYCL frontend classes to mark some 
area to outline, without relying to do some precise pattern matching, allowing 
more flexibility in the runtime without changing the compiler every time. So 
while it defines a zone to be outlined as a kernel, it is not really a kernel 
in the sense of OpenCL.

In triSYCL I made some completely different choices, using late outlining in 
LLVM and detecting some specific functions such as 
`cl::sycl::detail::instantiate_kernel()` that defines some stuff I 
want to outline 
https://github.com/triSYCL/triSYCL/blob/master/doc/architecture.rst#low-level-view-of-the-device-compiler-workflow
For me an attribute was not an option because I wanted to change Clang as 
little as possible. But at the end, I think it is quite more brittle than doing 
early outlining in Clang as discussed here, which also requires quite more 
knowledge of Clang than I have. :-)

So at the end, I think we should use a different keyword from OpenCL or CUDA 
because the semantics is different.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60455



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


r358733 - Fix overly-long line after r358731.

2019-04-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Apr 18 19:46:50 2019
New Revision: 358733

URL: http://llvm.org/viewvc/llvm-project?rev=358733=rev
Log:
Fix overly-long line after r358731.

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

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=358733=358732=358733=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Apr 18 19:46:50 2019
@@ -603,8 +603,8 @@ static LinkageInfo getExternalLinkageFor
   //   - A name declared at namespace scope that does not have internal linkage
   // by the previous rules and that is introduced by a non-exported
   // declaration has module linkage.
-  if (isInModulePurview(D) &&
-  
!isExportedFromModuleInterfaceUnit(cast(D->getCanonicalDecl(
+  if (isInModulePurview(D) && !isExportedFromModuleInterfaceUnit(
+  cast(D->getCanonicalDecl(
 return LinkageInfo(ModuleLinkage, DefaultVisibility, false);
 
   return LinkageInfo::external();


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


r358731 - Fix typo in function name [NFC]

2019-04-18 Thread Ali Tamur via cfe-commits
Author: tamur
Date: Thu Apr 18 19:15:57 2019
New Revision: 358731

URL: http://llvm.org/viewvc/llvm-project?rev=358731=rev
Log:
Fix typo in function name [NFC]

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

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=358731=358730=358731=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Apr 18 19:15:57 2019
@@ -574,7 +574,7 @@ static bool isInModulePurview(const Name
   return false;
 }
 
-static bool isExportedFromModuleIntefaceUnit(const NamedDecl *D) {
+static bool isExportedFromModuleInterfaceUnit(const NamedDecl *D) {
   // FIXME: Handle isModulePrivate.
   switch (D->getModuleOwnershipKind()) {
   case Decl::ModuleOwnershipKind::Unowned:
@@ -604,7 +604,7 @@ static LinkageInfo getExternalLinkageFor
   // by the previous rules and that is introduced by a non-exported
   // declaration has module linkage.
   if (isInModulePurview(D) &&
-  
!isExportedFromModuleIntefaceUnit(cast(D->getCanonicalDecl(
+  
!isExportedFromModuleInterfaceUnit(cast(D->getCanonicalDecl(
 return LinkageInfo(ModuleLinkage, DefaultVisibility, false);
 
   return LinkageInfo::external();
@@ -638,7 +638,7 @@ LinkageComputer::getLVForNamespaceScopeD
 Var->getType().isConstQualified() &&
 !Var->getType().isVolatileQualified() &&
 !Var->isInline() &&
-!isExportedFromModuleIntefaceUnit(Var)) {
+!isExportedFromModuleInterfaceUnit(Var)) {
   const VarDecl *PrevVar = Var->getPreviousDecl();
   if (PrevVar)
 return getLVForDecl(PrevVar, computation);


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


r358729 - [analyzer] Fix -Wunused-local-typedef after rC358695

2019-04-18 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Thu Apr 18 18:54:36 2019
New Revision: 358729

URL: http://llvm.org/viewvc/llvm-project?rev=358729=rev
Log:
[analyzer] Fix -Wunused-local-typedef after rC358695

Modified:
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp?rev=358729=358728=358729=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp Thu Apr 18 
18:54:36 2019
@@ -63,11 +63,8 @@ static
  "In order to efficiently gather checkers/packages, this function "
  "expects them to be already sorted!");
 
-  typename CheckerOrPackageInfoList::value_type Info(FullName);
-
-  return llvm::lower_bound(
-  Collection, Info,
-  FullNameLT{});
+  return llvm::lower_bound(Collection, CheckerOrPackage(FullName),
+   CheckerOrPackageFullNameLT{});
 }
 
 static constexpr char PackageSeparator = '.';


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


[PATCH] D60899: [analyzer] Unbreak body farms in presence of multiple declarations.

2019-04-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a_sidorin, rnkovacs, 
mikhail.ramalho, Szelethus, baloghadamsoftware, Charusso.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, jfb, a.sidorin, 
JDevlieghere, szepet, kristof.beyls, javed.absar.
Herald added a project: clang.
NoQ added a parent revision: D60808: [analyzer] pr41335: NoStoreFuncVisitor: 
Fix crash when no-store event is in a body-farmed function..

Split out of D60808 .

When growing a body on a body farm, it's essential to use the same 
redeclaration of the function that's going to be used during analysis. 
Otherwise our `ParmVarDecl`s won't match the ones that are used to identify 
argument regions. This boils down to trusting the reasoning in 
`AnalysisDeclContext`. We shouldn't canonicalize the declaration before farming 
the body because it makes us not obey the sophisticated decision-making process 
of `AnalysisDeclContext`.


Repository:
  rC Clang

https://reviews.llvm.org/D60899

Files:
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/OSAtomic_mac.c


Index: clang/test/Analysis/OSAtomic_mac.c
===
--- clang/test/Analysis/OSAtomic_mac.c
+++ clang/test/Analysis/OSAtomic_mac.c
@@ -8,13 +8,20 @@
 }
 
 int *invalidSLocOnRedecl() {
-  int *b; // expected-note{{'b' declared without an initial value}}
-
+  // Was crashing when trying to throw a report about returning an 
uninitialized
+  // value to the caller. FIXME: We should probably still throw that report,
+  // something like "The "compare" part of CompareAndSwap depends on an
+  // undefined value".
+  int *b;
   OSAtomicCompareAndSwapPtrBarrier(0, 0, ); // no-crash
-  // FIXME: We don't really need these notes.
-  // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}}
-  // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}}
+  return b;
+}
 
-  return b; // expected-warning{{Undefined or garbage value returned to 
caller}}
-// expected-note@-1{{Undefined or garbage value returned to 
caller}}
+void testThatItActuallyWorks() {
+  void *x = 0;
+  int res = OSAtomicCompareAndSwapPtrBarrier(0, , );
+  clang_analyzer_eval(res); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+  clang_analyzer_eval(x == ); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
 }
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -579,6 +579,9 @@
 PathDiagnosticLocation L =
 PathDiagnosticLocation::create(N->getLocation(), SM);
 
+// For now this shouldn't trigger, but once it does (as we add more
+// functions to the body farm), we'll need to decide if these reports
+// are worth suppressing as well.
 if (!L.hasValidLocation())
   return nullptr;
 
Index: clang/lib/Analysis/BodyFarm.cpp
===
--- clang/lib/Analysis/BodyFarm.cpp
+++ clang/lib/Analysis/BodyFarm.cpp
@@ -665,8 +665,6 @@
 }
 
 Stmt *BodyFarm::getBody(const FunctionDecl *D) {
-  D = D->getCanonicalDecl();
-
   Optional  = Bodies[D];
   if (Val.hasValue())
 return Val.getValue();


Index: clang/test/Analysis/OSAtomic_mac.c
===
--- clang/test/Analysis/OSAtomic_mac.c
+++ clang/test/Analysis/OSAtomic_mac.c
@@ -8,13 +8,20 @@
 }
 
 int *invalidSLocOnRedecl() {
-  int *b; // expected-note{{'b' declared without an initial value}}
-
+  // Was crashing when trying to throw a report about returning an uninitialized
+  // value to the caller. FIXME: We should probably still throw that report,
+  // something like "The "compare" part of CompareAndSwap depends on an
+  // undefined value".
+  int *b;
   OSAtomicCompareAndSwapPtrBarrier(0, 0, ); // no-crash
-  // FIXME: We don't really need these notes.
-  // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}}
-  // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}}
+  return b;
+}
 
-  return b; // expected-warning{{Undefined or garbage value returned to caller}}
-// expected-note@-1{{Undefined or garbage value returned to caller}}
+void testThatItActuallyWorks() {
+  void *x = 0;
+  int res = OSAtomicCompareAndSwapPtrBarrier(0, , );
+  clang_analyzer_eval(res); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+  clang_analyzer_eval(x == ); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
 }
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- 

[PATCH] D60808: [analyzer] pr41335: NoStoreFuncVisitor: Fix crash when no-store event is in a body-farmed function.

2019-04-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 195851.
NoQ marked an inline comment as done.
NoQ added a comment.

Add space before `\`.


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

https://reviews.llvm.org/D60808

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/OSAtomic_mac.c

Index: clang/test/Analysis/OSAtomic_mac.c
===
--- /dev/null
+++ clang/test/Analysis/OSAtomic_mac.c
@@ -0,0 +1,20 @@
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection \
+// RUN:-analyzer-output=text -verify %s
+
+int OSAtomicCompareAndSwapPtrBarrier(*, *, **);
+int OSAtomicCompareAndSwapPtrBarrier() {
+  // There is some body in the actual header,
+  // but we should trust our BodyFarm instead.
+}
+
+int *invalidSLocOnRedecl() {
+  int *b; // expected-note{{'b' declared without an initial value}}
+
+  OSAtomicCompareAndSwapPtrBarrier(0, 0, ); // no-crash
+  // FIXME: We don't really need these notes.
+  // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}}
+  // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}}
+
+  return b; // expected-warning{{Undefined or garbage value returned to caller}}
+// expected-note@-1{{Undefined or garbage value returned to caller}}
+}
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -335,7 +335,7 @@
 if (RegionOfInterest->isSubRegionOf(SelfRegion) &&
 potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
   IvarR->getDecl()))
-  return maybeEmitNode(R, *Call, N, {}, SelfRegion, "self",
+  return maybeEmitNote(R, *Call, N, {}, SelfRegion, "self",
/*FirstIsReferenceType=*/false, 1);
   }
 }
@@ -344,7 +344,7 @@
   const MemRegion *ThisR = CCall->getCXXThisVal().getAsRegion();
   if (RegionOfInterest->isSubRegionOf(ThisR)
   && !CCall->getDecl()->isImplicit())
-return maybeEmitNode(R, *Call, N, {}, ThisR, "this",
+return maybeEmitNote(R, *Call, N, {}, ThisR, "this",
  /*FirstIsReferenceType=*/false, 1);
 
   // Do not generate diagnostics for not modified parameters in
@@ -363,7 +363,7 @@
   QualType T = PVD->getType();
   while (const MemRegion *MR = V.getAsRegion()) {
 if (RegionOfInterest->isSubRegionOf(MR) && !isPointerToConst(T))
-  return maybeEmitNode(R, *Call, N, {}, MR, ParamName,
+  return maybeEmitNote(R, *Call, N, {}, MR, ParamName,
ParamIsReferenceType, IndirectionLevel);
 
 QualType PT = T->getPointeeType();
@@ -371,7 +371,7 @@
 
 if (const RecordDecl *RD = PT->getAsRecordDecl())
   if (auto P = findRegionOfInterestInRecord(RD, State, MR))
-return maybeEmitNode(R, *Call, N, *P, RegionOfInterest, ParamName,
+return maybeEmitNote(R, *Call, N, *P, RegionOfInterest, ParamName,
  ParamIsReferenceType, IndirectionLevel);
 
 V = State->getSVal(MR, PT);
@@ -549,7 +549,7 @@
   /// \return Diagnostics piece for region not modified in the current function,
   /// if it decides to emit one.
   std::shared_ptr
-  maybeEmitNode(BugReport , const CallEvent , const ExplodedNode *N,
+  maybeEmitNote(BugReport , const CallEvent , const ExplodedNode *N,
 const RegionVector , const MemRegion *MatchedRegion,
 StringRef FirstElement, bool FirstIsReferenceType,
 unsigned IndirectionLevel) {
@@ -579,6 +579,9 @@
 PathDiagnosticLocation L =
 PathDiagnosticLocation::create(N->getLocation(), SM);
 
+if (!L.hasValidLocation())
+  return nullptr;
+
 SmallString<256> sbuf;
 llvm::raw_svector_ostream os(sbuf);
 os << "Returning without writing to '";
Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
===
--- clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
+++ clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
@@ -313,6 +313,8 @@
 
   bool hasRange() const { return K == StmtK || K == RangeK || K == DeclK; }
 
+  bool hasValidLocation() const { return asLocation().isValid(); }
+
   void invalidate() {
 *this = PathDiagnosticLocation();
   }
@@ -468,7 +470,7 @@
   PathDiagnosticPiece::Kind k,
   bool addPosRange = true)
   : PathDiagnosticPiece(s, k), Pos(pos) {
-assert(Pos.isValid() && Pos.asLocation().isValid() &&
+assert(Pos.isValid() && Pos.hasValidLocation() &&

[PATCH] D60808: [analyzer] pr41335: NoStoreFuncVisitor: Fix crash when no-store event is in a body-farmed function.

2019-04-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 195850.
NoQ added a comment.

Separate the canonicalization change that unbreaks body farms into a separate 
patch.


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

https://reviews.llvm.org/D60808

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/OSAtomic_mac.c

Index: clang/test/Analysis/OSAtomic_mac.c
===
--- /dev/null
+++ clang/test/Analysis/OSAtomic_mac.c
@@ -0,0 +1,20 @@
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection\
+// RUN:-analyzer-output=text -verify %s
+
+int OSAtomicCompareAndSwapPtrBarrier(*, *, **);
+int OSAtomicCompareAndSwapPtrBarrier() {
+  // There is some body in the actual header,
+  // but we should trust our BodyFarm instead.
+}
+
+int *invalidSLocOnRedecl() {
+  int *b; // expected-note{{'b' declared without an initial value}}
+
+  OSAtomicCompareAndSwapPtrBarrier(0, 0, ); // no-crash
+  // FIXME: We don't really need these notes.
+  // expected-note@-2{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}}
+  // expected-note@-3{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}}
+
+  return b; // expected-warning{{Undefined or garbage value returned to caller}}
+// expected-note@-1{{Undefined or garbage value returned to caller}}
+}
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -335,7 +335,7 @@
 if (RegionOfInterest->isSubRegionOf(SelfRegion) &&
 potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
   IvarR->getDecl()))
-  return maybeEmitNode(R, *Call, N, {}, SelfRegion, "self",
+  return maybeEmitNote(R, *Call, N, {}, SelfRegion, "self",
/*FirstIsReferenceType=*/false, 1);
   }
 }
@@ -344,7 +344,7 @@
   const MemRegion *ThisR = CCall->getCXXThisVal().getAsRegion();
   if (RegionOfInterest->isSubRegionOf(ThisR)
   && !CCall->getDecl()->isImplicit())
-return maybeEmitNode(R, *Call, N, {}, ThisR, "this",
+return maybeEmitNote(R, *Call, N, {}, ThisR, "this",
  /*FirstIsReferenceType=*/false, 1);
 
   // Do not generate diagnostics for not modified parameters in
@@ -363,7 +363,7 @@
   QualType T = PVD->getType();
   while (const MemRegion *MR = V.getAsRegion()) {
 if (RegionOfInterest->isSubRegionOf(MR) && !isPointerToConst(T))
-  return maybeEmitNode(R, *Call, N, {}, MR, ParamName,
+  return maybeEmitNote(R, *Call, N, {}, MR, ParamName,
ParamIsReferenceType, IndirectionLevel);
 
 QualType PT = T->getPointeeType();
@@ -371,7 +371,7 @@
 
 if (const RecordDecl *RD = PT->getAsRecordDecl())
   if (auto P = findRegionOfInterestInRecord(RD, State, MR))
-return maybeEmitNode(R, *Call, N, *P, RegionOfInterest, ParamName,
+return maybeEmitNote(R, *Call, N, *P, RegionOfInterest, ParamName,
  ParamIsReferenceType, IndirectionLevel);
 
 V = State->getSVal(MR, PT);
@@ -549,7 +549,7 @@
   /// \return Diagnostics piece for region not modified in the current function,
   /// if it decides to emit one.
   std::shared_ptr
-  maybeEmitNode(BugReport , const CallEvent , const ExplodedNode *N,
+  maybeEmitNote(BugReport , const CallEvent , const ExplodedNode *N,
 const RegionVector , const MemRegion *MatchedRegion,
 StringRef FirstElement, bool FirstIsReferenceType,
 unsigned IndirectionLevel) {
@@ -579,6 +579,9 @@
 PathDiagnosticLocation L =
 PathDiagnosticLocation::create(N->getLocation(), SM);
 
+if (!L.hasValidLocation())
+  return nullptr;
+
 SmallString<256> sbuf;
 llvm::raw_svector_ostream os(sbuf);
 os << "Returning without writing to '";
Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
===
--- clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
+++ clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
@@ -313,6 +313,8 @@
 
   bool hasRange() const { return K == StmtK || K == RangeK || K == DeclK; }
 
+  bool hasValidLocation() const { return asLocation().isValid(); }
+
   void invalidate() {
 *this = PathDiagnosticLocation();
   }
@@ -468,7 +470,7 @@
   PathDiagnosticPiece::Kind k,
   bool addPosRange = true)
   : PathDiagnosticPiece(s, k), Pos(pos) {
-assert(Pos.isValid() && Pos.asLocation().isValid() &&
+assert(Pos.isValid() && 

r358724 - Add header guard to Reusables.h [NFC]

2019-04-18 Thread Ali Tamur via cfe-commits
Author: tamur
Date: Thu Apr 18 17:42:54 2019
New Revision: 358724

URL: http://llvm.org/viewvc/llvm-project?rev=358724=rev
Log:
Add header guard to Reusables.h [NFC]

Modified:
cfe/trunk/unittests/StaticAnalyzer/Reusables.h

Modified: cfe/trunk/unittests/StaticAnalyzer/Reusables.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/Reusables.h?rev=358724=358723=358724=diff
==
--- cfe/trunk/unittests/StaticAnalyzer/Reusables.h (original)
+++ cfe/trunk/unittests/StaticAnalyzer/Reusables.h Thu Apr 18 17:42:54 2019
@@ -6,6 +6,9 @@
 //
 
//===--===//
 
+#ifndef LLVM_CLANG_UNITTESTS_STATICANALYZER_REUSABLES_H
+#define LLVM_CLANG_UNITTESTS_STATICANALYZER_REUSABLES_H
+
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
@@ -56,3 +59,5 @@ public:
 
 } // namespace ento
 } // namespace clang
+
+#endif


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


[PATCH] D59712: [APSInt][OpenMP] Fix isNegative, etc. for unsigned types

2019-04-18 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In D59712#1472544 , @jdenny wrote:

> In D59712#1472358 , @hfinkel wrote:
>
> > > I've never tried running the other tests you mention, for any patch.  I 
> > > thought people normally left those to the bots.  Should this patch be 
> > > handled differently?
> >
> > We have a lot of people actively working off of trunk, and we try very hard 
> > to keep trunk clean. The bots are a second line of defense, not the primary 
> > checkers. In any case, this comes down to professional judgement. It is not 
> > uncommon to ask for a patch author to check self hosting and a test suite 
> > run before committing - specifically, those patches that might affect 
> > correctness, or introduce other subtle problems, and for which running the 
> > compiler over a bunch of C/C++ code might uncover a problem.
>
>
> Thanks for explaining.  It's my first time receiving these particular 
> requests (probably because of what parts of LLVM I normally edit), so I 
> wasn't sure I understood.


No problem.

> For self-hosting, is it best to build again with CMAKE_C_COMPILER and 
> CMAKE_CXX_COMPILE pointing into the previous build, or is there a better 
> approach?

That's what I do.

> 
> 
>> Also, is this review now missing some files? I see here only updates to  
>> APSInt.h (only adding functions), APSIntTest.cpp, and a bunch of tests. 
>> Nothing that would cause changes to the tests, however (maybe I'm just 
>> missing something).
> 
> All looks fine to me.  The APSInt.h changes are the reason for all the test 
> changes.

Indeed. I forgot that you were changing overrides.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59712



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


[PATCH] D59712: [APSInt][OpenMP] Fix isNegative, etc. for unsigned types

2019-04-18 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D59712#1472358 , @hfinkel wrote:

> > I've never tried running the other tests you mention, for any patch.  I 
> > thought people normally left those to the bots.  Should this patch be 
> > handled differently?
>
> We have a lot of people actively working off of trunk, and we try very hard 
> to keep trunk clean. The bots are a second line of defense, not the primary 
> checkers. In any case, this comes down to professional judgement. It is not 
> uncommon to ask for a patch author to check self hosting and a test suite run 
> before committing - specifically, those patches that might affect 
> correctness, or introduce other subtle problems, and for which running the 
> compiler over a bunch of C/C++ code might uncover a problem.


Thanks for explaining.  It's my first time receiving these particular requests 
(probably because of what parts of LLVM I normally edit), so I wasn't sure I 
understood.

For self-hosting, is it best to build again with CMAKE_C_COMPILER and 
CMAKE_CXX_COMPILE pointing into the previous build, or is there a better 
approach?

> Also, is this review now missing some files? I see here only updates to  
> APSInt.h (only adding functions), APSIntTest.cpp, and a bunch of tests. 
> Nothing that would cause changes to the tests, however (maybe I'm just 
> missing something).

All looks fine to me.  The APSInt.h changes are the reason for all the test 
changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59712



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


[PATCH] D41284: [Concepts] Associated constraints infrastructure.

2019-04-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/AST/DeclTemplate.h:177
+  /// conjunction ("and").
+  llvm::SmallVector getAssociatedConstraints() const;
+

Returning a `SmallVector` by value is not idiomatic. If you need to make a copy 
here, you should take a `SmallVectorImpl` by reference, so the caller can 
choose the inline size. If not, you should return an `ArrayRef`.



Comment at: include/clang/Sema/Sema.h:5772-5776
+  /// \brief Check that the associated constraints of a template declaration
+  /// match the associated constraints of an older declaration of which it is a
+  /// redeclaration
+  bool CheckRedeclarationConstraintMatch(ArrayRef OldAC,
+ ArrayRef NewAC);

This is not how redeclaration checking is specified any more. A redeclaration 
is valid only if its //template-head// is equivalent to that of the prior 
declaration, not if it has the same associated constraints. You should instead 
take two `TemplateParameterList`s, profile them, and compare the results.



Comment at: lib/Serialization/ASTReaderDecl.cpp:2375
 D->ParameterPack = Record.readInt();
+// TODO: Concepts: Constrained parameters
 if (Record.readInt())

There's no such thing any more.



Comment at: lib/Serialization/ASTReaderDecl.cpp:2393
 // Rest of TemplateTemplateParmDecl.
+// TODO: Concepts: Constrained parameters
 D->ParameterPack = Record.readInt();

There's no such thing any more.


Repository:
  rC Clang

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

https://reviews.llvm.org/D41284



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


[PATCH] D44352: [Concepts] Constrained template parameters

2019-04-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith requested changes to this revision.
rsmith added a comment.
This revision now requires changes to proceed.

This needs revision to reflect changes between the Concepts TS and C++20. In 
particular, only the name of a //type-concept// can be used to declare a 
//template-parameter// in the new rules:

  template concept A = true;
  template typename> B = true;
  template concept C = true;
  
  template struct XA {}; // ok
  template struct XB {}; // error, not a type-concept
  template struct XC {}; // error, not a type-concept

We don't appear to have any explicit representation of the //type-concept// as 
written, only of its immediately-declared constraint. One design goal of Clang 
is for the AST to directly represent the program as written (to the extent 
possible) to facilitate writing tools on top of Clang's AST. Please consider 
adding a representation of the `TypeConstraint` itself. (This could be as 
simple as a wrapper around the `Expr*` that you currently have, that provides 
access to the concept name and the template arguments, and additionally stores 
a flag to determine whether an explicit template argument list was specified, 
to distinguish `TypeConcept` from `TypeConcept<>`.)




Comment at: lib/Parse/ParseTemplate.cpp:590-619
+/// constrained-parameter
+///
+///   type-parameter: (See below)
+/// type-parameter-key ...[opt] identifier[opt]
+/// type-parameter-key identifier[opt] = type-id
+/// 'template' '<' template-parameter-list '>' type-parameter-key
+///   ...[opt] identifier[opt]

This is out of date compared to the current C++20 wording.



Comment at: lib/Parse/ParseTemplate.cpp:677
+  TemplateArgumentListInfo ) {
+  TentativeParsingAction TPA(*this);
+

This should not require tentative parsing. We should be able to annotate the 
nested-name-specifier (if any) then determine whether we have a //type-name// 
or a //type-constraint// with a single token of lookahead.



Comment at: lib/Parse/ParseTemplate.cpp:1039-1045
+if (!EllipsisLoc.isInvalid()
+&& CD->getTemplateParameters()->hasParameterPack())
+  // C++ [temp.param]p11.1
+  //   If P declares a template parameter pack and C is a variadic concept,
+  //   then A is the pack expansion P... . Otherwise, A is the
+  //   id-expression P.
+  Q = Actions.Context.getPackExpansionType(Q, /*NumExpansions=*/None);

This is incorrect; this rule was removed when concepts were merged into C++20.



Comment at: lib/Parse/ParseTemplate.cpp:1153-1176
+  Expr *IntroducedConstraint = Result.get();
+  if (EllipsisLoc.isValid() && 
!CD->getTemplateParameters()->hasParameterPack())
+// We have the following case:
+//
+// template concept C1 = true;
+// template struct s1;
+//

All the work to build expressions and establish the semantic effects of 
declarations should be done by `Sema`, not by the `Parser`. The `Parser` should 
just figure out how the program matches the grammar, and report to `Sema` what 
it found.


Repository:
  rC Clang

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

https://reviews.llvm.org/D44352



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


[PATCH] D60742: [analyzer] RegionStore: Enable loading default bindings from variables.

2019-04-18 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358722: [analyzer] Make default bindings to variables 
actually work. (authored by dergachev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60742?vs=195500=195842#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60742

Files:
  lib/StaticAnalyzer/Core/RegionStore.cpp
  test/Analysis/string.c
  unittests/StaticAnalyzer/CMakeLists.txt
  unittests/StaticAnalyzer/StoreTest.cpp

Index: test/Analysis/string.c
===
--- test/Analysis/string.c
+++ test/Analysis/string.c
@@ -1554,3 +1554,9 @@
   // This should be true.
   clang_analyzer_eval(x == 0x101); // expected-warning{{UNKNOWN}}
 }
+
+void memset29_plain_int_zero() {
+  short x;
+  memset(, 0, sizeof(short));
+  clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
+}
Index: lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- lib/StaticAnalyzer/Core/RegionStore.cpp
+++ lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1927,7 +1927,10 @@
   const VarRegion *R) {
 
   // Check if the region has a binding.
-  if (const Optional  = B.getDirectBinding(R))
+  if (Optional V = B.getDirectBinding(R))
+return *V;
+
+  if (Optional V = B.getDefaultBinding(R))
 return *V;
 
   // Lazily derive a value for the VarRegion.
Index: unittests/StaticAnalyzer/StoreTest.cpp
===
--- unittests/StaticAnalyzer/StoreTest.cpp
+++ unittests/StaticAnalyzer/StoreTest.cpp
@@ -0,0 +1,105 @@
+//===- unittests/StaticAnalyzer/StoreTest.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Reusables.h"
+
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace ento {
+namespace {
+
+// Test that we can put a value into an int-type variable and load it
+// back from that variable. Test what happens if default bindings are used.
+class VariableBindConsumer : public ExprEngineConsumer {
+  void performTest(const Decl *D) {
+StoreManager  = Eng.getStoreManager();
+SValBuilder  = Eng.getSValBuilder();
+MemRegionManager  = StMgr.getRegionManager();
+const ASTContext  = Eng.getContext();
+
+const auto *VDX0 = findDeclByName(D, "x0");
+const auto *VDY0 = findDeclByName(D, "y0");
+const auto *VDZ0 = findDeclByName(D, "z0");
+const auto *VDX1 = findDeclByName(D, "x1");
+const auto *VDY1 = findDeclByName(D, "y1");
+assert(VDX0 && VDY0 && VDZ0 && VDX1 && VDY1);
+
+const StackFrameContext *SFC =
+Eng.getAnalysisDeclContextManager().getStackFrame(D);
+
+Loc LX0 = loc::MemRegionVal(MRMgr.getVarRegion(VDX0, SFC));
+Loc LY0 = loc::MemRegionVal(MRMgr.getVarRegion(VDY0, SFC));
+Loc LZ0 = loc::MemRegionVal(MRMgr.getVarRegion(VDZ0, SFC));
+Loc LX1 = loc::MemRegionVal(MRMgr.getVarRegion(VDX1, SFC));
+Loc LY1 = loc::MemRegionVal(MRMgr.getVarRegion(VDY1, SFC));
+
+Store StInit = StMgr.getInitialStore(SFC).getStore();
+SVal Zero = SVB.makeZeroVal(ACtx.IntTy);
+SVal One = SVB.makeIntVal(1, ACtx.IntTy);
+SVal NarrowZero = SVB.makeZeroVal(ACtx.CharTy);
+
+// Bind(Zero)
+Store StX0 =
+StMgr.Bind(StInit, LX0, Zero).getStore();
+ASSERT_EQ(Zero, StMgr.getBinding(StX0, LX0, ACtx.IntTy));
+
+// BindDefaultInitial(Zero)
+Store StY0 =
+StMgr.BindDefaultInitial(StInit, LY0.getAsRegion(), Zero).getStore();
+ASSERT_EQ(Zero, StMgr.getBinding(StY0, LY0, ACtx.IntTy));
+ASSERT_EQ(Zero, *StMgr.getDefaultBinding(StY0, LY0.getAsRegion()));
+
+// BindDefaultZero()
+Store StZ0 =
+StMgr.BindDefaultZero(StInit, LZ0.getAsRegion()).getStore();
+// BindDefaultZero wipes the region with '0 S8b', not with out Zero.
+// Direct load, however, does give us back the object of the type
+// that we specify for loading.
+ASSERT_EQ(Zero, StMgr.getBinding(StZ0, LZ0, ACtx.IntTy));
+ASSERT_EQ(NarrowZero, *StMgr.getDefaultBinding(StZ0, LZ0.getAsRegion()));
+
+// Bind(One)
+Store StX1 =
+StMgr.Bind(StInit, LX1, One).getStore();
+ASSERT_EQ(One, StMgr.getBinding(StX1, LX1, ACtx.IntTy));
+
+// BindDefaultInitial(One)
+Store StY1 =
+StMgr.BindDefaultInitial(StInit, LY1.getAsRegion(), One).getStore();
+ASSERT_EQ(One, StMgr.getBinding(StY1, LY1, ACtx.IntTy));
+ASSERT_EQ(One, *StMgr.getDefaultBinding(StY1, LY1.getAsRegion()));
+  }
+
+public:
+  VariableBindConsumer(CompilerInstance ) : ExprEngineConsumer(C) {}
+
+  bool 

r358722 - [analyzer] Make default bindings to variables actually work.

2019-04-18 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Apr 18 16:35:56 2019
New Revision: 358722

URL: http://llvm.org/viewvc/llvm-project?rev=358722=rev
Log:
[analyzer] Make default bindings to variables actually work.

Default RegionStore bindings represent values that can be obtained by loading
from anywhere within the region, not just the specific offset within the region
that they are said to be bound to. For example, default-binding a character \0
to an int (eg., via memset()) means that the whole int is 0, not just
that its lower byte is 0.

Even though memset and bzero were modeled this way, it didn't work correctly
when applied to simple variables. Eg., in

  int x;
  memset(x, 0, sizeof(x));

we did produce a default binding, but were unable to read it later, and 'x'
was perceived as an uninitialized variable even after memset.

At the same time, if we replace 'x' with a variable of a structure or array
type, accessing fields or elements of such variable was working correctly,
which was enough for most cases. So this was only a problem for variables of
simple integer/enumeration/floating-point/pointer types.

Fix loading default bindings from RegionStore for regions of simple variables.

Add a unit test to document the API contract as well.

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

Added:
cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/trunk/test/Analysis/string.c
cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=358722=358721=358722=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Thu Apr 18 16:35:56 2019
@@ -1927,7 +1927,10 @@ SVal RegionStoreManager::getBindingForVa
   const VarRegion *R) {
 
   // Check if the region has a binding.
-  if (const Optional  = B.getDirectBinding(R))
+  if (Optional V = B.getDirectBinding(R))
+return *V;
+
+  if (Optional V = B.getDefaultBinding(R))
 return *V;
 
   // Lazily derive a value for the VarRegion.

Modified: cfe/trunk/test/Analysis/string.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/string.c?rev=358722=358721=358722=diff
==
--- cfe/trunk/test/Analysis/string.c (original)
+++ cfe/trunk/test/Analysis/string.c Thu Apr 18 16:35:56 2019
@@ -1554,3 +1554,9 @@ void memset28() {
   // This should be true.
   clang_analyzer_eval(x == 0x101); // expected-warning{{UNKNOWN}}
 }
+
+void memset29_plain_int_zero() {
+  short x;
+  memset(, 0, sizeof(short));
+  clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
+}

Modified: cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt?rev=358722=358721=358722=diff
==
--- cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt (original)
+++ cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt Thu Apr 18 16:35:56 2019
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_unittest(StaticAnalysisTests
   AnalyzerOptionsTest.cpp
+  StoreTest.cpp
   RegisterCustomCheckersTest.cpp
   SymbolReaperTest.cpp
   )

Added: cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp?rev=358722=auto
==
--- cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp (added)
+++ cfe/trunk/unittests/StaticAnalyzer/StoreTest.cpp Thu Apr 18 16:35:56 2019
@@ -0,0 +1,105 @@
+//===- unittests/StaticAnalyzer/StoreTest.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Reusables.h"
+
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace ento {
+namespace {
+
+// Test that we can put a value into an int-type variable and load it
+// back from that variable. Test what happens if default bindings are used.
+class VariableBindConsumer : public ExprEngineConsumer {
+  void performTest(const Decl *D) {
+StoreManager  = Eng.getStoreManager();
+SValBuilder  = Eng.getSValBuilder();
+MemRegionManager  = StMgr.getRegionManager();
+const ASTContext  = Eng.getContext();
+
+const auto *VDX0 = findDeclByName(D, "x0");
+const auto *VDY0 = findDeclByName(D, "y0");
+const auto *VDZ0 = 

[PATCH] D60739: [analyzer] NFC: Re-use reusable unittest mocks.

2019-04-18 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358720: [analyzer] NFC: Make reusable unittest mocks 
reusable. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60739?vs=195272=195839#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60739

Files:
  cfe/trunk/unittests/StaticAnalyzer/Reusables.h
  cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp

Index: cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp
===
--- cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp
+++ cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp
@@ -6,13 +6,8 @@
 //
 //===--===//
 
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
-#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
-#include "clang/CrossTU/CrossTranslationUnit.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
-#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#include "Reusables.h"
+
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
 
@@ -20,50 +15,6 @@
 namespace ento {
 namespace {
 
-using namespace ast_matchers;
-
-// A re-usable consumer that constructs ExprEngine out of CompilerInvocation.
-// TODO: Actually re-use it when we write our second test.
-class ExprEngineConsumer : public ASTConsumer {
-protected:
-  CompilerInstance 
-
-private:
-  // We need to construct all of these in order to construct ExprEngine.
-  CheckerManager ChkMgr;
-  cross_tu::CrossTranslationUnitContext CTU;
-  PathDiagnosticConsumers Consumers;
-  AnalysisManager AMgr;
-  SetOfConstDecls VisitedCallees;
-  FunctionSummariesTy FS;
-
-protected:
-  ExprEngine Eng;
-
-  // Find a declaration in the current AST by name. This has nothing to do
-  // with ExprEngine but turns out to be handy.
-  // TODO: There's probably a better place for it.
-  template 
-  const T *findDeclByName(const Decl *Where, StringRef Name) {
-auto Matcher = decl(hasDescendant(namedDecl(hasName(Name)).bind("d")));
-auto Matches = match(Matcher, *Where, Eng.getContext());
-assert(Matches.size() == 1 && "Ambiguous name!");
-const T *Node = selectFirst("d", Matches);
-assert(Node && "Name not found!");
-return Node;
-  }
-
-public:
-  ExprEngineConsumer(CompilerInstance )
-  : C(C), ChkMgr(C.getASTContext(), *C.getAnalyzerOpts()), CTU(C),
-Consumers(),
-AMgr(C.getASTContext(), C.getDiagnostics(), Consumers,
- CreateRegionStoreManager, CreateRangeConstraintManager, ,
- *C.getAnalyzerOpts()),
-VisitedCallees(), FS(),
-Eng(CTU, AMgr, , , ExprEngine::Inline_Regular) {}
-};
-
 class SuperRegionLivenessConsumer : public ExprEngineConsumer {
   void performTest(const Decl *D) {
 const auto *FD = findDeclByName(D, "x");
@@ -99,7 +50,7 @@
   }
 };
 
-class SuperRegionLivenessAction: public ASTFrontendAction {
+class SuperRegionLivenessAction : public ASTFrontendAction {
 public:
   SuperRegionLivenessAction() {}
   std::unique_ptr CreateASTConsumer(CompilerInstance ,
Index: cfe/trunk/unittests/StaticAnalyzer/Reusables.h
===
--- cfe/trunk/unittests/StaticAnalyzer/Reusables.h
+++ cfe/trunk/unittests/StaticAnalyzer/Reusables.h
@@ -0,0 +1,58 @@
+//===- unittests/StaticAnalyzer/Reusables.h ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/CrossTU/CrossTranslationUnit.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+
+namespace clang {
+namespace ento {
+
+// Find a declaration in the current AST by name.
+template 
+const T *findDeclByName(const Decl *Where, StringRef Name) {
+  using namespace ast_matchers;
+  auto Matcher = decl(hasDescendant(namedDecl(hasName(Name)).bind("d")));
+  auto Matches = match(Matcher, *Where, Where->getASTContext());
+  assert(Matches.size() == 1 && "Ambiguous name!");
+  const T *Node = selectFirst("d", Matches);
+  assert(Node && "Name not found!");
+  return Node;
+}
+
+// A re-usable consumer that constructs ExprEngine out of CompilerInvocation.
+class ExprEngineConsumer : public ASTConsumer {
+protected:
+  CompilerInstance 
+
+private:
+  // We need to construct all of these in order to construct ExprEngine.
+  

r358720 - [analyzer] NFC: Make reusable unittest mocks reusable.

2019-04-18 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Apr 18 16:24:50 2019
New Revision: 358720

URL: http://llvm.org/viewvc/llvm-project?rev=358720=rev
Log:
[analyzer] NFC: Make reusable unittest mocks reusable.

Put them in a header for other Analyzer unittests to include.

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

Added:
cfe/trunk/unittests/StaticAnalyzer/Reusables.h
Modified:
cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp

Added: cfe/trunk/unittests/StaticAnalyzer/Reusables.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/Reusables.h?rev=358720=auto
==
--- cfe/trunk/unittests/StaticAnalyzer/Reusables.h (added)
+++ cfe/trunk/unittests/StaticAnalyzer/Reusables.h Thu Apr 18 16:24:50 2019
@@ -0,0 +1,58 @@
+//===- unittests/StaticAnalyzer/Reusables.h 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/CrossTU/CrossTranslationUnit.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+
+namespace clang {
+namespace ento {
+
+// Find a declaration in the current AST by name.
+template 
+const T *findDeclByName(const Decl *Where, StringRef Name) {
+  using namespace ast_matchers;
+  auto Matcher = decl(hasDescendant(namedDecl(hasName(Name)).bind("d")));
+  auto Matches = match(Matcher, *Where, Where->getASTContext());
+  assert(Matches.size() == 1 && "Ambiguous name!");
+  const T *Node = selectFirst("d", Matches);
+  assert(Node && "Name not found!");
+  return Node;
+}
+
+// A re-usable consumer that constructs ExprEngine out of CompilerInvocation.
+class ExprEngineConsumer : public ASTConsumer {
+protected:
+  CompilerInstance 
+
+private:
+  // We need to construct all of these in order to construct ExprEngine.
+  CheckerManager ChkMgr;
+  cross_tu::CrossTranslationUnitContext CTU;
+  PathDiagnosticConsumers Consumers;
+  AnalysisManager AMgr;
+  SetOfConstDecls VisitedCallees;
+  FunctionSummariesTy FS;
+
+protected:
+  ExprEngine Eng;
+
+public:
+  ExprEngineConsumer(CompilerInstance )
+  : C(C), ChkMgr(C.getASTContext(), *C.getAnalyzerOpts()), CTU(C),
+Consumers(),
+AMgr(C.getASTContext(), C.getDiagnostics(), Consumers,
+ CreateRegionStoreManager, CreateRangeConstraintManager, ,
+ *C.getAnalyzerOpts()),
+VisitedCallees(), FS(),
+Eng(CTU, AMgr, , , ExprEngine::Inline_Regular) {}
+};
+
+} // namespace ento
+} // namespace clang

Modified: cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp?rev=358720=358719=358720=diff
==
--- cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp (original)
+++ cfe/trunk/unittests/StaticAnalyzer/SymbolReaperTest.cpp Thu Apr 18 16:24:50 
2019
@@ -6,13 +6,8 @@
 //
 
//===--===//
 
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
-#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
-#include "clang/CrossTU/CrossTranslationUnit.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
-#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#include "Reusables.h"
+
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
 
@@ -20,50 +15,6 @@ namespace clang {
 namespace ento {
 namespace {
 
-using namespace ast_matchers;
-
-// A re-usable consumer that constructs ExprEngine out of CompilerInvocation.
-// TODO: Actually re-use it when we write our second test.
-class ExprEngineConsumer : public ASTConsumer {
-protected:
-  CompilerInstance 
-
-private:
-  // We need to construct all of these in order to construct ExprEngine.
-  CheckerManager ChkMgr;
-  cross_tu::CrossTranslationUnitContext CTU;
-  PathDiagnosticConsumers Consumers;
-  AnalysisManager AMgr;
-  SetOfConstDecls VisitedCallees;
-  FunctionSummariesTy FS;
-
-protected:
-  ExprEngine Eng;
-
-  // Find a declaration in the current AST by name. This has nothing to do
-  // with ExprEngine but turns out to be handy.
-  // TODO: There's probably a better place for it.
-  template 
-  const T *findDeclByName(const Decl *Where, StringRef Name) {
-auto Matcher = decl(hasDescendant(namedDecl(hasName(Name)).bind("d")));
-auto Matches = match(Matcher, *Where, Eng.getContext());
-assert(Matches.size() == 1 && "Ambiguous name!");
-const T *Node = selectFirst("d", 

[PATCH] D60732: [analyzer] NFC: Use -verify=... in MoveChecker tests.

2019-04-18 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358719: [analyzer] NFC: MoveChecker: Refactor tests to use 
-verify=prefix. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60732?vs=195250=195838#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60732

Files:
  cfe/trunk/test/Analysis/use-after-move.cpp

Index: cfe/trunk/test/Analysis/use-after-move.cpp
===
--- cfe/trunk/test/Analysis/use-after-move.cpp
+++ cfe/trunk/test/Analysis/use-after-move.cpp
@@ -1,31 +1,37 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,peaceful,non-aggressive
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,peaceful,non-aggressive
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly -DPEACEFUL\
-// RUN:  -analyzer-checker debug.ExprInspection
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly -DPEACEFUL\
-// RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,non-aggressive
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-config cplusplus.Move:WarnOn=All -DAGGRESSIVE\
-// RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=All\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,peaceful,aggressive
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-config cplusplus.Move:WarnOn=All -DAGGRESSIVE\
-// RUN:  -analyzer-checker debug.ExprInspection
+// RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=All\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,peaceful,aggressive
 
 // RUN: not %clang_analyze_cc1 -verify %s \
 // RUN:   -analyzer-checker=core \
@@ -75,10 +81,7 @@
 moveconstruct(std::move(*a));
   }
   A(const A ) : i(other.i), d(other.d), b(other.b) {}
-  A(A &) : i(other.i), d(other.d), b(std::move(other.b)) {
-#ifdef AGGRESSIVE
-// expected-note@-2{{Object 'b' is moved}}
-#endif
+  A(A &) : i(other.i), d(other.d), b(std::move(other.b)) { // aggressive-note{{Object 'b' is moved}}
   }
   A(A &, char *k) {
 moveconstruct(std::move(other));
@@ -141,33 +144,21 @@
 void simpleMoveCtorTest() {
   {
 A a;
-A b = std::move(a);
-a.foo();
-#ifndef PEACEFUL
-// expected-note@-3 {{Object 'a' is moved}}
-// expected-warning@-3 {{Method called on moved-from object 'a'}}
-// expected-note@-4{{Method called on moved-from object 'a'}}
-#endif
+A b = std::move(a); // peaceful-note {{Object 'a' is moved}}
+a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}}
+ // peaceful-note@-1 {{Method called on 

r358719 - [analyzer] NFC: MoveChecker: Refactor tests to use -verify=prefix.

2019-04-18 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Apr 18 16:17:58 2019
New Revision: 358719

URL: http://llvm.org/viewvc/llvm-project?rev=358719=rev
Log:
[analyzer] NFC: MoveChecker: Refactor tests to use -verify=prefix.

This -verify=prefix feature is quite underrated.

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

Modified:
cfe/trunk/test/Analysis/use-after-move.cpp

Modified: cfe/trunk/test/Analysis/use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/use-after-move.cpp?rev=358719=358718=358719=diff
==
--- cfe/trunk/test/Analysis/use-after-move.cpp (original)
+++ cfe/trunk/test/Analysis/use-after-move.cpp Thu Apr 18 16:17:58 2019
@@ -1,31 +1,37 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config 
eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,peaceful,non-aggressive
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config 
eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,peaceful,non-aggressive
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config 
eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly -DPEACEFUL\
-// RUN:  -analyzer-checker debug.ExprInspection
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config 
eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly -DPEACEFUL\
-// RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,non-aggressive
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config 
eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-config cplusplus.Move:WarnOn=All -DAGGRESSIVE\
-// RUN:  -analyzer-checker debug.ExprInspection
-// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=All\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,peaceful,aggressive
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config 
eagerly-assume=false\
-// RUN:  -analyzer-config exploration_strategy=dfs -DDFS=1\
-// RUN:  -analyzer-config cplusplus.Move:WarnOn=All -DAGGRESSIVE\
-// RUN:  -analyzer-checker debug.ExprInspection
+// RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
+// RUN:  -analyzer-config cplusplus.Move:WarnOn=All\
+// RUN:  -analyzer-checker debug.ExprInspection\
+// RUN:  -verify=expected,peaceful,aggressive
 
 // RUN: not %clang_analyze_cc1 -verify %s \
 // RUN:   -analyzer-checker=core \
@@ -75,10 +81,7 @@ public:
 moveconstruct(std::move(*a));
   }
   A(const A ) : i(other.i), d(other.d), b(other.b) {}
-  A(A &) : i(other.i), d(other.d), b(std::move(other.b)) {
-#ifdef AGGRESSIVE
-// expected-note@-2{{Object 'b' is moved}}
-#endif
+  A(A &) : i(other.i), d(other.d), b(std::move(other.b)) { // 
aggressive-note{{Object 'b' is moved}}
   }
   A(A &, char *k) {
 moveconstruct(std::move(other));
@@ -141,33 +144,21 @@ void copyOrMoveCall(A a) {
 void simpleMoveCtorTest() {
   {
 A a;
-A b = std::move(a);
-a.foo();
-#ifndef PEACEFUL
-// expected-note@-3 {{Object 'a' is moved}}
-// expected-warning@-3 {{Method called on moved-from object 'a'}}
-// expected-note@-4{{Method called on moved-from object 'a'}}
-#endif
+A b = std::move(a); // peaceful-note {{Object 'a' is moved}}
+a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}}
+ // 

[PATCH] D58367: [analyzer] NFC: Improve upon the concept of BugReporterVisitor.

2019-04-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 195835.
NoQ added a comment.

Fall back to the previous `std::vector>` approach.


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

https://reviews.llvm.org/D58367

Files:
  clang/include/clang/Analysis/ProgramPoint.h
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/Analysis/mig.mm

Index: clang/test/Analysis/mig.mm
===
--- clang/test/Analysis/mig.mm
+++ clang/test/Analysis/mig.mm
@@ -91,6 +91,14 @@
  // expected-note@-1{{MIG callback fails with error after deallocating argument value. This is a use-after-free vulnerability because the caller will try to deallocate it again}}
 }
 
+MIG_SERVER_ROUTINE
+kern_return_t no_unrelated_notes(mach_port_name_t port, vm_address_t address, vm_size_t size) {
+  vm_deallocate(port, address, size); // no-note
+  1 / 0; // expected-warning{{Division by zero}}
+ // expected-note@-1{{Division by zero}}
+  return KERN_SUCCESS;
+}
+
 // Make sure we find the bug when the object is destroyed within an
 // automatic destructor.
 MIG_SERVER_ROUTINE
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -201,7 +201,9 @@
   svalBuilder(StateMgr.getSValBuilder()),
   ObjCNoRet(mgr.getASTContext()),
   BR(mgr, *this),
-  VisitedCallees(VisitedCalleesIn), HowToInline(HowToInlineIn) {
+  VisitedCallees(VisitedCalleesIn),
+  HowToInline(HowToInlineIn)
+  {
   unsigned TrimInterval = mgr.options.GraphTrimInterval;
   if (TrimInterval != 0) {
 // Enable eager node reclamation when constructing the ExplodedGraph.
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2492,6 +2492,30 @@
   return nullptr;
 }
 
+int NoteTag::Kind = 0;
+
+void TagVisitor::Profile(llvm::FoldingSetNodeID ) const {
+  static int Tag = 0;
+  ID.AddPointer();
+}
+
+std::shared_ptr
+TagVisitor::VisitNode(const ExplodedNode *N, BugReporterContext ,
+  BugReport ) {
+  ProgramPoint PP = N->getLocation();
+  const NoteTag *T = dyn_cast_or_null(PP.getTag());
+  if (!T)
+return nullptr;
+
+  if (Optional Msg = T->generateMessage(BRC, R)) {
+PathDiagnosticLocation Loc =
+PathDiagnosticLocation::create(PP, BRC.getSourceManager());
+return std::make_shared(Loc, *Msg);
+  }
+
+  return nullptr;
+}
+
 void FalsePositiveRefutationBRVisitor::Profile(
 llvm::FoldingSetNodeID ) const {
   static int Tag = 0;
Index: clang/lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2612,6 +2612,7 @@
 R->addVisitor(llvm::make_unique());
 R->addVisitor(llvm::make_unique());
 R->addVisitor(llvm::make_unique());
+R->addVisitor(llvm::make_unique());
 
 BugReporterContext BRC(Reporter, ErrorGraph.BackMap);
 
Index: clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
@@ -80,43 +80,10 @@
 checkReturnAux(RS, C);
   }
 
-  class Visitor : public BugReporterVisitor {
-  public:
-void Profile(llvm::FoldingSetNodeID ) const {
-  static int X = 0;
-  ID.AddPointer();
-}
-
-std::shared_ptr VisitNode(const ExplodedNode *N,
-BugReporterContext , BugReport );
-  };
 };
 } // end anonymous namespace
 
-// FIXME: It's a 'const ParmVarDecl *' but there's no ready-made GDM traits
-// specialization for this sort of types.
-REGISTER_TRAIT_WITH_PROGRAMSTATE(ReleasedParameter, const void *)
-
-std::shared_ptr
-MIGChecker::Visitor::VisitNode(const ExplodedNode *N, BugReporterContext ,
-   BugReport ) {
-  const auto *NewPVD = static_cast(
-  N->getState()->get());
-  const auto *OldPVD = static_cast(
-  N->getFirstPred()->getState()->get());
-  if (OldPVD == NewPVD)
-return nullptr;
-
-  assert(NewPVD && "What is deallocated cannot be un-deallocated!");
-  SmallString<64> Str;
-  llvm::raw_svector_ostream OS(Str);
-  OS << "Value passed 

[PATCH] D60892: Modules: Search for a visible definition of the decl context when computing visibility of a default template parameter

2019-04-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.
dblaikie added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The code is/was already correct for the case where a parameter is a
parameter of its enclosing lexical DeclContext (functions and classes).
But for other templates (alias and variable templates) they don't create
their own scope to be members of - in those cases, they parameter should
be considered visible if any definition of the lexical decl context is
visible.

[this should cleanup the failure on the libstdc++ modules buildbot]
[this doesn't actually fix the variable template case for a
secondary/compounding reason (its lexical decl context is incorrectly
considered to be the translation unit)]

Test covers all 4 kinds of templates with default args, including a
regression test for the still broken variable template case.


Repository:
  rC Clang

https://reviews.llvm.org/D60892

Files:
  lib/Sema/SemaLookup.cpp
  test/Modules/Inputs/nested-template-default-arg-redecl/alias.h
  test/Modules/Inputs/nested-template-default-arg-redecl/alias1.h
  test/Modules/Inputs/nested-template-default-arg-redecl/alias2.h
  test/Modules/Inputs/nested-template-default-arg-redecl/func.h
  test/Modules/Inputs/nested-template-default-arg-redecl/func1.h
  test/Modules/Inputs/nested-template-default-arg-redecl/func2.h
  test/Modules/Inputs/nested-template-default-arg-redecl/module.modulemap
  test/Modules/Inputs/nested-template-default-arg-redecl/strct.h
  test/Modules/Inputs/nested-template-default-arg-redecl/strct1.h
  test/Modules/Inputs/nested-template-default-arg-redecl/strct2.h
  test/Modules/Inputs/nested-template-default-arg-redecl/var.h
  test/Modules/Inputs/nested-template-default-arg-redecl/var1.h
  test/Modules/Inputs/nested-template-default-arg-redecl/var2.h
  test/Modules/nested-template-default-arg-redecl.cpp

Index: test/Modules/nested-template-default-arg-redecl.cpp
===
--- /dev/null
+++ test/Modules/nested-template-default-arg-redecl.cpp
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
+// RUN: -I %S/Inputs/nested-template-default-arg-redecl -std=c++14 \
+// RUN: -fmodules-local-submodule-visibility -verify %s
+#include "alias2.h"
+#include "var2.h"
+#include "strct2.h"
+#include "func2.h"
+
+// FIXME: Variable templates lexical decl context appears to be the translation
+// unit, which is incorrect. Fixing this will hopefully address the following
+// error/bug:
+
+// expected-note@Inputs/nested-template-default-arg-redecl/var.h:4 {{default argument declared here}}
+auto var = _outer::var<>; // expected-error {{default argument of 'var' must be imported from module 'VAR1' before it is required}}
+auto func = _outer::func<>;
+strct_outer::strct<> *strct;
+alias_outer::alias<> *alias;
Index: test/Modules/Inputs/nested-template-default-arg-redecl/var2.h
===
--- /dev/null
+++ test/Modules/Inputs/nested-template-default-arg-redecl/var2.h
@@ -0,0 +1 @@
+#include "var.h"
Index: test/Modules/Inputs/nested-template-default-arg-redecl/var1.h
===
--- /dev/null
+++ test/Modules/Inputs/nested-template-default-arg-redecl/var1.h
@@ -0,0 +1 @@
+#include "var.h"
Index: test/Modules/Inputs/nested-template-default-arg-redecl/var.h
===
--- /dev/null
+++ test/Modules/Inputs/nested-template-default-arg-redecl/var.h
@@ -0,0 +1,9 @@
+#ifndef VAR_H
+#define VAR_H
+struct var_outer {
+  template 
+  static int var;
+};
+#endif
+
+
Index: test/Modules/Inputs/nested-template-default-arg-redecl/strct2.h
===
--- /dev/null
+++ test/Modules/Inputs/nested-template-default-arg-redecl/strct2.h
@@ -0,0 +1 @@
+#include "strct.h"
Index: test/Modules/Inputs/nested-template-default-arg-redecl/strct1.h
===
--- /dev/null
+++ test/Modules/Inputs/nested-template-default-arg-redecl/strct1.h
@@ -0,0 +1 @@
+#include "strct.h"
Index: test/Modules/Inputs/nested-template-default-arg-redecl/strct.h
===
--- /dev/null
+++ test/Modules/Inputs/nested-template-default-arg-redecl/strct.h
@@ -0,0 +1,7 @@
+#ifndef STRCT_H
+#define STRCT_H
+struct strct_outer {
+  template 
+  struct strct;
+};
+#endif
Index: test/Modules/Inputs/nested-template-default-arg-redecl/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/nested-template-default-arg-redecl/module.modulemap
@@ -0,0 +1,24 @@
+module ALIAS1 {
+  header "alias1.h"
+  module ALIAS2 {
+header "alias2.h"
+  }
+}
+module VAR1 {
+  header "var1.h"
+  module VAR2 {
+header "var2.h"
+ 

[PATCH] D59712: [APSInt][OpenMP] Fix isNegative, etc. for unsigned types

2019-04-18 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In D59712#1472318 , @jdenny wrote:

> In D59712#1469760 , @lebedev.ri 
> wrote:
>
> > In D59712#1469693 , @jdenny wrote:
> >
> > > In D59712#1469392 , @lebedev.ri 
> > > wrote:
> > >
> > > > In D59712#1469358 , @jdenny 
> > > > wrote:
> > > >
> > > > > In D59712#1469301 , 
> > > > > @lebedev.ri wrote:
> > > > >
> > > > > > In D59712#1469295 , 
> > > > > > @craig.topper wrote:
> > > > > >
> > > > > > > Wondering if it would be better to assert for asking for the sign 
> > > > > > > of an unsigned APSInt. I could see a caller just wanting to get 
> > > > > > > the msb for some reason and not knowing that isNegative won’t 
> > > > > > > work.
> > > > > >
> > > > > >
> > > > > > Yes, i, too, would think an assert is much better solution (since i 
> > > > > > literally just tripped over this in this review.)
> > > > >
> > > >
> > > >
> > > > Does this pass `check-all`? `check-all` of stage-2? test-suite?
> > >
> > >
> > > No.  The assert breaks cases in at least ExprConstant.cpp and 
> > > SemaExpr.cpp.
> >
> >
> > Err, i was talking about the current code in the patch :)
>
>
> For me, check-all's success is not affected by the current patch.  I built 
> all subprojects except llgo, which gave me a build problem independently of 
> this patch.
>
> I've never tried running the other tests you mention, for any patch.  I 
> thought people normally left those to the bots.  Should this patch be handled 
> differently?


We have a lot of people actively working off of trunk, and we try very hard to 
keep trunk clean. The bots are a second line of defense, not the primary 
checkers. In any case, this comes down to professional judgement. It is not 
uncommon to ask for a patch author to check self hosting and a test suite run 
before committing - specifically, those patches that might affect correctness, 
or introduce other subtle problems, and for which running the compiler over a 
bunch of C/C++ code might uncover a problem.

Also, is this review now missing some files? I see here only updates to  
APSInt.h (only adding functions), APSIntTest.cpp, and a bunch of tests. Nothing 
that would cause changes to the tests, however (maybe I'm just missing 
something).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59712



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


[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info

2019-04-18 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm with a minor whitespace issue




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1972
   }
-
   CI->setMetadata("heapallocsite", node);

Please revert the white space only change to this file.



Comment at: llvm/lib/CodeGen/MachineFunction.cpp:816
+
+  DIType *DI = dyn_cast(MD);
+  CodeViewHeapAllocSites.push_back({BeginLabel, EndLabel, DI});

I guess it's reasonable to treat any non-DIType as "void". The only other 
reasonable thing to do would be to report an error, but it's not worth it.



Comment at: llvm/test/CodeGen/X86/label-heapallocsite.ll:1
+; RUN: llc -O0 < %s | FileCheck %s
+; FIXME: Add test for llc with optimizations once it is implemented.

akhuang wrote:
> hans wrote:
> > Does llc have a "-fast-isel" flag or similar that could be used instead, to 
> > make it more clear that it's fast-isel that's significant for the test?
> I couldn't find a flag that makes llc use fast-isel; it should soon work for 
> both cases though.
FWIW, -O0 is the typical way to enable fast isel in other codegen tests, so 
even if it's opaque, it's consistent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60800



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


[PATCH] D59712: [APSInt][OpenMP] Fix isNegative, etc. for unsigned types

2019-04-18 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D59712#1472342 , @lebedev.ri wrote:

> In D59712#1472318 , @jdenny wrote:
>
> > For me, check-all's success is not affected by the current patch.  I built 
> > all subprojects except llgo, which gave me a build problem independently of 
> > this patch.
>
>
> (Built natively, or with clang with this patch?)


Built natively.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59712



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


[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info

2019-04-18 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked an inline comment as done.
akhuang added inline comments.



Comment at: llvm/test/CodeGen/X86/label-heapallocsite.ll:1
+; RUN: llc -O0 < %s | FileCheck %s
+; FIXME: Add test for llc with optimizations once it is implemented.

hans wrote:
> Does llc have a "-fast-isel" flag or similar that could be used instead, to 
> make it more clear that it's fast-isel that's significant for the test?
I couldn't find a flag that makes llc use fast-isel; it should soon work for 
both cases though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60800



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


[PATCH] D59712: [APSInt][OpenMP] Fix isNegative, etc. for unsigned types

2019-04-18 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri resigned from this revision.
lebedev.ri added a comment.

In D59712#1472318 , @jdenny wrote:

> In D59712#1469760 , @lebedev.ri 
> wrote:
>
> > In D59712#1469693 , @jdenny wrote:
> >
> > > In D59712#1469392 , @lebedev.ri 
> > > wrote:
> > >
> > > > In D59712#1469358 , @jdenny 
> > > > wrote:
> > > >
> > > > > In D59712#1469301 , 
> > > > > @lebedev.ri wrote:
> > > > >
> > > > > > In D59712#1469295 , 
> > > > > > @craig.topper wrote:
> > > > > >
> > > > > > > Wondering if it would be better to assert for asking for the sign 
> > > > > > > of an unsigned APSInt. I could see a caller just wanting to get 
> > > > > > > the msb for some reason and not knowing that isNegative won’t 
> > > > > > > work.
> > > > > >
> > > > > >
> > > > > > Yes, i, too, would think an assert is much better solution (since i 
> > > > > > literally just tripped over this in this review.)
> > > > >
> > > >
> > > >
> > > > Does this pass `check-all`? `check-all` of stage-2? test-suite?
> > >
> > >
> > > No.  The assert breaks cases in at least ExprConstant.cpp and 
> > > SemaExpr.cpp.
> >
> >
> > Err, i was talking about the current code in the patch :)
>
>
> For me, check-all's success is not affected by the current patch.  I built 
> all subprojects except llgo, which gave me a build problem independently of 
> this patch.


(Built natively, or with clang with this patch?)

> I've never tried running the other tests you mention, for any patch.  I 
> thought people normally left those to the bots.  Should this patch be handled 
> differently?

Sounds good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59712



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


[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info

2019-04-18 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 195821.
akhuang marked 2 inline comments as done.
akhuang added a comment.

- Changed test case back to original


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60800

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/test/CodeGen/X86/label-heapallocsite.ll

Index: llvm/test/CodeGen/X86/label-heapallocsite.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/label-heapallocsite.ll
@@ -0,0 +1,68 @@
+; RUN: llc -O0 < %s | FileCheck %s
+; FIXME: Add test for llc with optimizations once it is implemented.
+
+; Source to regenerate:
+; $ clang --target=x86_64-windows-msvc -S heapallocsite.c  -g -gcodeview -o t.ll \
+;  -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions
+; __declspec(allocator) char *myalloc();
+; void g();
+; void foo() {
+;   g();
+;   myalloc()
+;   g();
+; }
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+; Function Attrs: noinline nounwind optnone
+define dso_local void @f() #0 !dbg !7 {
+entry:
+  call void @g(), !dbg !11
+  %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13
+  call void @g(), !dbg !14
+  ret void, !dbg !15
+}
+
+; CHECK-LABEL: f: # @f
+; CHECK: callq g
+; CHECK: .Lheapallocsite0:
+; CHECK: callq myalloc
+; CHECK: .Lheapallocsite1:
+; CHECK: retq
+
+; CHECK-LABEL: .short  4423# Record kind: S_GPROC32_ID
+; CHECK:   .short  4446# Record kind: S_HEAPALLOCSITE
+; CHECK-NEXT:  .secrel32   .Lheapallocsite0
+; CHECK-NEXT:  .secidx .Lheapallocsite0
+; CHECK-NEXT:  .short  .Lheapallocsite1-.Lheapallocsite0
+; CHECK-NEXT:  .long 112
+; CHECK-NEXT:  .p2align 2
+
+; CHECK-LABEL: .short  4431# Record kind: S_PROC_ID_END
+
+declare dso_local void @g() #1
+
+declare dso_local i8* @myalloc() #1
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
+!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9")
+!2 = !{}
+!3 = !{i32 2, !"CodeView", i32 1}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 2}
+!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"}
+!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9")
+!9 = !DISubroutineType(types: !10)
+!10 = !{null}
+!11 = !DILocation(line: 5, scope: !7)
+!12 = !DILocation(line: 6, scope: !7)
+!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!14 = !DILocation(line: 7, scope: !7)
+!15 = !DILocation(line: 8, scope: !7)
+
Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1234,6 +1234,12 @@
   if (CLI.NumResultRegs && CLI.CS)
 updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs);
 
+  // Set labels for heapallocsite call.
+  if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) {
+MDNode *MD = CLI.CS->getInstruction()->getMetadata("heapallocsite");
+MF->addCodeViewHeapAllocSite(CLI.Call, MD);
+  }
+
   return true;
 }
 
Index: llvm/lib/CodeGen/MachineFunction.cpp
===
--- llvm/lib/CodeGen/MachineFunction.cpp
+++ llvm/lib/CodeGen/MachineFunction.cpp
@@ -43,6 +43,7 @@
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constant.h"
 #include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalValue.h"
@@ -806,6 +807,16 @@
   return FilterID;
 }
 
+void MachineFunction::addCodeViewHeapAllocSite(MachineInstr *I, MDNode *MD) {
+  MCSymbol *BeginLabel = Ctx.createTempSymbol("heapallocsite", true);
+  MCSymbol *EndLabel = Ctx.createTempSymbol("heapallocsite", true);
+  I->setPreInstrSymbol(*this, BeginLabel);
+  I->setPostInstrSymbol(*this, EndLabel);
+
+  DIType *DI = dyn_cast(MD);
+  

[PATCH] D59712: [APSInt][OpenMP] Fix isNegative, etc. for unsigned types

2019-04-18 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D59712#1469760 , @lebedev.ri wrote:

> In D59712#1469693 , @jdenny wrote:
>
> > In D59712#1469392 , @lebedev.ri 
> > wrote:
> >
> > > In D59712#1469358 , @jdenny 
> > > wrote:
> > >
> > > > In D59712#1469301 , 
> > > > @lebedev.ri wrote:
> > > >
> > > > > In D59712#1469295 , 
> > > > > @craig.topper wrote:
> > > > >
> > > > > > Wondering if it would be better to assert for asking for the sign 
> > > > > > of an unsigned APSInt. I could see a caller just wanting to get the 
> > > > > > msb for some reason and not knowing that isNegative won’t work.
> > > > >
> > > > >
> > > > > Yes, i, too, would think an assert is much better solution (since i 
> > > > > literally just tripped over this in this review.)
> > > >
> > >
> > >
> > > Does this pass `check-all`? `check-all` of stage-2? test-suite?
> >
> >
> > No.  The assert breaks cases in at least ExprConstant.cpp and SemaExpr.cpp.
>
>
> Err, i was talking about the current code in the patch :)


For me, check-all's success is not affected by the current patch.  I built all 
subprojects except llgo, which gave me a build problem independently of this 
patch.

I've never tried running the other tests you mention, for any patch.  I thought 
people normally left those to the bots.  Should this patch be handled 
differently?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59712



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


[PATCH] D58367: [analyzer] NFC: Improve upon the concept of BugReporterVisitor.

2019-04-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D58367#1462026 , @Szelethus wrote:

> Hmmm, interesting. Could there be an issue with `NoteTag` not being trivially 
> destructible?


Yeah, i think you're right. Which means we cannot allocate it in a 
`BumpPtrAllocator`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58367



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


[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info

2019-04-18 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 195818.
akhuang marked 2 inline comments as done.
akhuang added a comment.

- Pass void metadata as null DIType


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60800

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/test/CodeGen/X86/label-heapallocsite.ll

Index: llvm/test/CodeGen/X86/label-heapallocsite.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/label-heapallocsite.ll
@@ -0,0 +1,68 @@
+; RUN: llc -O0 < %s | FileCheck %s
+; FIXME: Add test for llc with optimizations once it is implemented.
+
+; Source to regenerate:
+; $ clang --target=x86_64-windows-msvc -S heapallocsite.c  -g -gcodeview -o t.ll \
+;  -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions
+; __declspec(allocator) char *myalloc();
+; void g();
+; void foo() {
+;   g();
+;   myalloc()
+;   g();
+; }
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+; Function Attrs: noinline nounwind optnone
+define dso_local void @f() #0 !dbg !7 {
+entry:
+  call void @g(), !dbg !11
+  %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13
+  call void @g(), !dbg !14
+  ret void, !dbg !15
+}
+
+; CHECK-LABEL: f: # @f
+; CHECK: callq g
+; CHECK: .Lheapallocsite0:
+; CHECK: callq myalloc
+; CHECK: .Lheapallocsite1:
+; CHECK: retq
+
+; CHECK-LABEL: .short  4423# Record kind: S_GPROC32_ID
+; CHECK:   .short  4446# Record kind: S_HEAPALLOCSITE
+; CHECK-NEXT:  .secrel32   .Lheapallocsite0
+; CHECK-NEXT:  .secidx .Lheapallocsite0
+; CHECK-NEXT:  .short  .Lheapallocsite1-.Lheapallocsite0
+; CHECK-NEXT:  .long 112
+; CHECK-NEXT:  .p2align 2
+
+; CHECK-LABEL: .short  4431# Record kind: S_PROC_ID_END
+
+declare dso_local void @g() #1
+
+declare dso_local i8* @myalloc() #1
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
+!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9")
+!2 = !{}
+!3 = !{i32 2, !"CodeView", i32 1}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 2}
+!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"}
+!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9")
+!9 = !DISubroutineType(types: !10)
+!10 = !{null}
+!11 = !DILocation(line: 5, scope: !7)
+!12 = !DILocation(line: 6, scope: !7)
+!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!14 = !DILocation(line: 7, scope: !7)
+!15 = !DILocation(line: 8, scope: !7)
+
Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1234,6 +1234,12 @@
   if (CLI.NumResultRegs && CLI.CS)
 updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs);
 
+  // Set labels for heapallocsite call.
+  if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) {
+MDNode *MD = CLI.CS->getInstruction()->getMetadata("heapallocsite");
+MF->addCodeViewHeapAllocSite(CLI.Call, MD);
+  }
+
   return true;
 }
 
Index: llvm/lib/CodeGen/MachineFunction.cpp
===
--- llvm/lib/CodeGen/MachineFunction.cpp
+++ llvm/lib/CodeGen/MachineFunction.cpp
@@ -43,6 +43,7 @@
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constant.h"
 #include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalValue.h"
@@ -806,6 +807,16 @@
   return FilterID;
 }
 
+void MachineFunction::addCodeViewHeapAllocSite(MachineInstr *I, MDNode *MD) {
+  MCSymbol *BeginLabel = Ctx.createTempSymbol("heapallocsite", true);
+  MCSymbol *EndLabel = Ctx.createTempSymbol("heapallocsite", true);
+  I->setPreInstrSymbol(*this, BeginLabel);
+  I->setPostInstrSymbol(*this, 

[PATCH] D60845: [VerifyDiagnosticConsumer] Document -verify= in doxygen

2019-04-18 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D60845#1472291 , @rsmith wrote:

> In D60845#1471741 , @jdenny wrote:
>
> > In D60845#1471002 , @rsmith wrote:
> >
> > > I've seen a few projects outside of clang use `-verify` mode for their 
> > > own testing of various things.
> >
> >
> > Interesting.  What's an example?
>
>
> libc++ and absl both use `-verify` in their test suites.


Thanks.  I just took a quick glance at libc++.  I see checks that the library 
manages to induce desired compiler diagnostics in code that incorrectly 
interfaces with the library.  That's a nice capability to expose, especially 
for people writing C++ libraries.


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

https://reviews.llvm.org/D60845



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


r358713 - [c++2a] Add semantic support for private module fragments.

2019-04-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Apr 18 14:12:54 2019
New Revision: 358713

URL: http://llvm.org/viewvc/llvm-project?rev=358713=rev
Log:
[c++2a] Add semantic support for private module fragments.

Added:
cfe/trunk/test/CXX/basic/basic.link/p2.cpp
cfe/trunk/test/CXX/module/module.interface/
cfe/trunk/test/CXX/module/module.interface/p1.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/Module.h
cfe/trunk/include/clang/Lex/ModuleMap.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaModule.cpp
cfe/trunk/test/CXX/basic/basic.link/p1.cpp
cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.interface/p1.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=358713=358712=358713=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 18 14:12:54 
2019
@@ -9276,8 +9276,20 @@ def note_global_module_introducer_missin
 def err_export_within_export : Error<
   "export declaration appears within another export declaration">;
 def err_export_not_in_module_interface : Error<
-  "export declaration can only be used within a module interface unit after "
-  "the module declaration">;
+  "export declaration can only be used within a module interface unit"
+  "%select{ after the module declaration|}0">;
+def err_export_in_private_module_fragment : Error<
+  "export declaration cannot be used in a private module fragment">;
+def note_private_module_fragment : Note<
+  "private module fragment begins here">;
+def err_private_module_fragment_not_module : Error<
+  "private module fragment declaration with no preceding module declaration">;
+def err_private_module_fragment_redefined : Error<
+  "private module fragment redefined">;
+def err_private_module_fragment_not_module_interface : Error<
+  "private module fragment in module implementation unit">;
+def note_not_module_interface_add_export : Note<
+  "add 'export' here if this is intended to be a module interface unit">;
 
 def ext_equivalent_internal_linkage_decl_in_modules : ExtWarn<
   "ambiguous use of internal linkage declaration %0 defined in multiple 
modules">,

Modified: cfe/trunk/include/clang/Basic/Module.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=358713=358712=358713=diff
==
--- cfe/trunk/include/clang/Basic/Module.h (original)
+++ cfe/trunk/include/clang/Basic/Module.h Thu Apr 18 14:12:54 2019
@@ -77,9 +77,11 @@ public:
 /// This is a C++ Modules TS module interface unit.
 ModuleInterfaceUnit,
 
-/// This is a fragment of the global module within some C++ Modules
-/// TS module.
+/// This is a fragment of the global module within some C++ module.
 GlobalModuleFragment,
+
+/// This is the private module fragment within some C++ module.
+PrivateModuleFragment,
   };
 
   /// The kind of this module.
@@ -111,6 +113,11 @@ public:
   /// eventually be exposed, for use in "private" modules.
   std::string ExportAsModule;
 
+  /// Does this Module scope describe part of the purview of a named C++ 
module?
+  bool isModulePurview() const {
+return Kind == ModuleInterfaceUnit || Kind == PrivateModuleFragment;
+  }
+
 private:
   /// The submodules of this module, indexed by name.
   std::vector SubModules;

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=358713=358712=358713=diff
==
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Thu Apr 18 14:12:54 2019
@@ -520,14 +520,18 @@ public:
bool IsFramework,
bool IsExplicit);
 
-  /// Create a 'global module' for a C++ Modules TS module interface unit.
+  /// Create a global module fragment for a C++ module unit.
   ///
-  /// We model the global module as a submodule of the module interface unit.
-  /// Unfortunately, we can't create the module interface unit's Module until
-  /// later, because we don't know what it will be called.
-  Module *createGlobalModuleForInterfaceUnit(SourceLocation Loc);
+  /// We model the global module fragment as a submodule of the module
+  /// interface unit. Unfortunately, we can't create the module interface
+  /// unit's Module until later, because we don't know what it will be called.
+  Module 

[PATCH] D60845: [VerifyDiagnosticConsumer] Document -verify= in doxygen

2019-04-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D60845#1471741 , @jdenny wrote:

> In D60845#1471002 , @rsmith wrote:
>
> > I've seen a few projects outside of clang use `-verify` mode for their own 
> > testing of various things.
>
>
> Interesting.  What's an example?


libc++ and absl both use `-verify` in their test suites.


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

https://reviews.llvm.org/D60845



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


[PATCH] D60873: [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

2019-04-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/unittests/clangd/HeadersTests.cpp:220
+  BarHeader = testPath("sub/bar.h");
+  EXPECT_EQ(calculate(BarHeader), "\"sub/bar.h\"");
 }

ormris wrote:
> sammccall wrote:
> > ormris wrote:
> > > Quick nit: This test won't work on Windows as it only tests for 
> > > POSIX-style path separators. You could easily add a Windows ifdef, though.
> > testPath() returns an appropriate native path, and calculate() returns an 
> > #include string (which always uses /).
> > The "../" on line 217 looks a little more suspicious, but I think the clang 
> > driver might silently Do What I Mean here.
> > Are you seeing test failures?
> Yes, here's the output.
> 
> ```
> [ RUN  ] HeadersTest.ShortenedInclude
> C:\llvm\tools\clang\tools\extra\unittests\clangd\HeadersTests.cpp(220): 
> error:   Expected: calculate(BarHeader)
>   Which is: "\"sub\\bar.h\""
> To be equal to: "\"sub/bar.h\""
> ```
Hmm, that suggests the test is catching a real bug in the code: we should be 
inserting paths with forward slashes even on Windows.

Looking at the test cases, i have the sinking feeling we've always been doing 
this and never noticed as no test case has a slash in the final #include. (And 
none of the main clangd devs are primarily using Windows)

Thank you for pointing this out!

@kadircet: we should either fix this before this patch lands, or ifdef it until 
we can fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60873



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


[PATCH] D60808: [analyzer] pr41335: NoStoreFuncVisitor: Fix crash when no-store event is in a body-farmed function.

2019-04-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 195810.
NoQ added a comment.
This revision is now accepted and ready to land.

Don't canonicalize the decl in the body farm. The decl supplied by the 
AnalysisDeclContext is already the correct one (and not necessarily the 
canonical one).

Keep the defensive behavior for NoStoreFuncVisitor because it's generally the 
right thing to do for future-proofness.


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

https://reviews.llvm.org/D60808

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/OSAtomic_mac.c

Index: clang/test/Analysis/OSAtomic_mac.c
===
--- /dev/null
+++ clang/test/Analysis/OSAtomic_mac.c
@@ -0,0 +1,27 @@
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection\
+// RUN:-analyzer-output=text -verify %s
+
+int OSAtomicCompareAndSwapPtrBarrier(*, *, **);
+int OSAtomicCompareAndSwapPtrBarrier() {
+  // There is some body in the actual header,
+  // but we should trust our BodyFarm instead.
+}
+
+int *invalidSLocOnRedecl() {
+  // Was crashing when trying to throw a report about returning an uninitialized
+  // value to the caller. FIXME: We should probably still throw that report,
+  // something like "The "compare" part of CompareAndSwap depends on an
+  // undefined value".
+  int *b;
+  OSAtomicCompareAndSwapPtrBarrier(0, 0, ); // no-crash
+  return b;
+}
+
+void testThatItActuallyWorks() {
+  void *x = 0;
+  int res = OSAtomicCompareAndSwapPtrBarrier(0, , );
+  clang_analyzer_eval(res); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+  clang_analyzer_eval(x == ); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -335,7 +335,7 @@
 if (RegionOfInterest->isSubRegionOf(SelfRegion) &&
 potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
   IvarR->getDecl()))
-  return maybeEmitNode(R, *Call, N, {}, SelfRegion, "self",
+  return maybeEmitNote(R, *Call, N, {}, SelfRegion, "self",
/*FirstIsReferenceType=*/false, 1);
   }
 }
@@ -344,7 +344,7 @@
   const MemRegion *ThisR = CCall->getCXXThisVal().getAsRegion();
   if (RegionOfInterest->isSubRegionOf(ThisR)
   && !CCall->getDecl()->isImplicit())
-return maybeEmitNode(R, *Call, N, {}, ThisR, "this",
+return maybeEmitNote(R, *Call, N, {}, ThisR, "this",
  /*FirstIsReferenceType=*/false, 1);
 
   // Do not generate diagnostics for not modified parameters in
@@ -363,7 +363,7 @@
   QualType T = PVD->getType();
   while (const MemRegion *MR = V.getAsRegion()) {
 if (RegionOfInterest->isSubRegionOf(MR) && !isPointerToConst(T))
-  return maybeEmitNode(R, *Call, N, {}, MR, ParamName,
+  return maybeEmitNote(R, *Call, N, {}, MR, ParamName,
ParamIsReferenceType, IndirectionLevel);
 
 QualType PT = T->getPointeeType();
@@ -371,7 +371,7 @@
 
 if (const RecordDecl *RD = PT->getAsRecordDecl())
   if (auto P = findRegionOfInterestInRecord(RD, State, MR))
-return maybeEmitNode(R, *Call, N, *P, RegionOfInterest, ParamName,
+return maybeEmitNote(R, *Call, N, *P, RegionOfInterest, ParamName,
  ParamIsReferenceType, IndirectionLevel);
 
 V = State->getSVal(MR, PT);
@@ -549,7 +549,7 @@
   /// \return Diagnostics piece for region not modified in the current function,
   /// if it decides to emit one.
   std::shared_ptr
-  maybeEmitNode(BugReport , const CallEvent , const ExplodedNode *N,
+  maybeEmitNote(BugReport , const CallEvent , const ExplodedNode *N,
 const RegionVector , const MemRegion *MatchedRegion,
 StringRef FirstElement, bool FirstIsReferenceType,
 unsigned IndirectionLevel) {
@@ -579,6 +579,11 @@
 PathDiagnosticLocation L =
 PathDiagnosticLocation::create(N->getLocation(), SM);
 
+// For now this shouldn't trigger, but once it does, we'll need to decide
+// if these reports are worth suppressing as well.
+if (!L.hasValidLocation())
+  return nullptr;
+
 SmallString<256> sbuf;
 llvm::raw_svector_ostream os(sbuf);
 os << "Returning without writing to '";
Index: clang/lib/Analysis/BodyFarm.cpp
===
--- clang/lib/Analysis/BodyFarm.cpp
+++ clang/lib/Analysis/BodyFarm.cpp
@@ 

[PATCH] D60808: [analyzer] pr41335: NoStoreFuncVisitor: Fix crash when no-store event is in a body-farmed function.

2019-04-18 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

(also fix typo in the function name)


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

https://reviews.llvm.org/D60808



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


[PATCH] D60886: [OpenMP][NFC] Fix requires target test.

2019-04-18 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358711: [OpenMP][NFC] Fix requires target test. (authored by 
gbercea, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D60886

Files:
  test/OpenMP/requires_target_messages.cpp


Index: test/OpenMP/requires_target_messages.cpp
===
--- test/OpenMP/requires_target_messages.cpp
+++ test/OpenMP/requires_target_messages.cpp
@@ -2,14 +2,14 @@
 
 void foo2() {
   int a;
-  #pragma omp target // expected-note 4 {{Target previously encountered here}}
+  #pragma omp target // expected-note 4 {{target previously encountered here}}
   {
 a = a + 1;
   }
 }
 
 #pragma omp requires atomic_default_mem_order(seq_cst)
-#pragma omp requires unified_address //expected-error {{Target region 
encountered before requires directive with 'unified_address' clause}}
-#pragma omp requires unified_shared_memory //expected-error {{Target region 
encountered before requires directive with 'unified_shared_memory' clause}}
-#pragma omp requires reverse_offload //expected-error {{Target region 
encountered before requires directive with 'reverse_offload' clause}}
-#pragma omp requires dynamic_allocators //expected-error {{Target region 
encountered before requires directive with 'dynamic_allocators' clause}}
+#pragma omp requires unified_address //expected-error {{target region 
encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{target region 
encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{target region 
encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{target region 
encountered before requires directive with 'dynamic_allocators' clause}}


Index: test/OpenMP/requires_target_messages.cpp
===
--- test/OpenMP/requires_target_messages.cpp
+++ test/OpenMP/requires_target_messages.cpp
@@ -2,14 +2,14 @@
 
 void foo2() {
   int a;
-  #pragma omp target // expected-note 4 {{Target previously encountered here}}
+  #pragma omp target // expected-note 4 {{target previously encountered here}}
   {
 a = a + 1;
   }
 }
 
 #pragma omp requires atomic_default_mem_order(seq_cst)
-#pragma omp requires unified_address //expected-error {{Target region encountered before requires directive with 'unified_address' clause}}
-#pragma omp requires unified_shared_memory //expected-error {{Target region encountered before requires directive with 'unified_shared_memory' clause}}
-#pragma omp requires reverse_offload //expected-error {{Target region encountered before requires directive with 'reverse_offload' clause}}
-#pragma omp requires dynamic_allocators //expected-error {{Target region encountered before requires directive with 'dynamic_allocators' clause}}
+#pragma omp requires unified_address //expected-error {{target region encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{target region encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{target region encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{target region encountered before requires directive with 'dynamic_allocators' clause}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r358711 - [OpenMP][NFC] Fix requires target test.

2019-04-18 Thread Gheorghe-Teodor Bercea via cfe-commits
Author: gbercea
Date: Thu Apr 18 13:34:43 2019
New Revision: 358711

URL: http://llvm.org/viewvc/llvm-project?rev=358711=rev
Log:
[OpenMP][NFC] Fix requires target test.

Summary:
Fix requires target test.


Reviewers: ABataev

Subscribers: guansong, jdoerfert, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/test/OpenMP/requires_target_messages.cpp

Modified: cfe/trunk/test/OpenMP/requires_target_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/requires_target_messages.cpp?rev=358711=358710=358711=diff
==
--- cfe/trunk/test/OpenMP/requires_target_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/requires_target_messages.cpp Thu Apr 18 13:34:43 2019
@@ -2,14 +2,14 @@
 
 void foo2() {
   int a;
-  #pragma omp target // expected-note 4 {{Target previously encountered here}}
+  #pragma omp target // expected-note 4 {{target previously encountered here}}
   {
 a = a + 1;
   }
 }
 
 #pragma omp requires atomic_default_mem_order(seq_cst)
-#pragma omp requires unified_address //expected-error {{Target region 
encountered before requires directive with 'unified_address' clause}}
-#pragma omp requires unified_shared_memory //expected-error {{Target region 
encountered before requires directive with 'unified_shared_memory' clause}}
-#pragma omp requires reverse_offload //expected-error {{Target region 
encountered before requires directive with 'reverse_offload' clause}}
-#pragma omp requires dynamic_allocators //expected-error {{Target region 
encountered before requires directive with 'dynamic_allocators' clause}}
+#pragma omp requires unified_address //expected-error {{target region 
encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{target region 
encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{target region 
encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{target region 
encountered before requires directive with 'dynamic_allocators' clause}}


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


[PATCH] D60886: [OpenMP][NFC] Fix requires target test.

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea created this revision.
gtbercea added a reviewer: ABataev.
Herald added subscribers: cfe-commits, jdoerfert, guansong.
Herald added a project: clang.

Fix requires target test.


Repository:
  rC Clang

https://reviews.llvm.org/D60886

Files:
  test/OpenMP/requires_target_messages.cpp


Index: test/OpenMP/requires_target_messages.cpp
===
--- test/OpenMP/requires_target_messages.cpp
+++ test/OpenMP/requires_target_messages.cpp
@@ -2,14 +2,14 @@
 
 void foo2() {
   int a;
-  #pragma omp target // expected-note 4 {{Target previously encountered here}}
+  #pragma omp target // expected-note 4 {{target previously encountered here}}
   {
 a = a + 1;
   }
 }
 
 #pragma omp requires atomic_default_mem_order(seq_cst)
-#pragma omp requires unified_address //expected-error {{Target region 
encountered before requires directive with 'unified_address' clause}}
-#pragma omp requires unified_shared_memory //expected-error {{Target region 
encountered before requires directive with 'unified_shared_memory' clause}}
-#pragma omp requires reverse_offload //expected-error {{Target region 
encountered before requires directive with 'reverse_offload' clause}}
-#pragma omp requires dynamic_allocators //expected-error {{Target region 
encountered before requires directive with 'dynamic_allocators' clause}}
+#pragma omp requires unified_address //expected-error {{target region 
encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{target region 
encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{target region 
encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{target region 
encountered before requires directive with 'dynamic_allocators' clause}}


Index: test/OpenMP/requires_target_messages.cpp
===
--- test/OpenMP/requires_target_messages.cpp
+++ test/OpenMP/requires_target_messages.cpp
@@ -2,14 +2,14 @@
 
 void foo2() {
   int a;
-  #pragma omp target // expected-note 4 {{Target previously encountered here}}
+  #pragma omp target // expected-note 4 {{target previously encountered here}}
   {
 a = a + 1;
   }
 }
 
 #pragma omp requires atomic_default_mem_order(seq_cst)
-#pragma omp requires unified_address //expected-error {{Target region encountered before requires directive with 'unified_address' clause}}
-#pragma omp requires unified_shared_memory //expected-error {{Target region encountered before requires directive with 'unified_shared_memory' clause}}
-#pragma omp requires reverse_offload //expected-error {{Target region encountered before requires directive with 'reverse_offload' clause}}
-#pragma omp requires dynamic_allocators //expected-error {{Target region encountered before requires directive with 'dynamic_allocators' clause}}
+#pragma omp requires unified_address //expected-error {{target region encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{target region encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{target region encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{target region encountered before requires directive with 'dynamic_allocators' clause}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60873: [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

2019-04-18 Thread Matthew Voss via Phabricator via cfe-commits
ormris added inline comments.



Comment at: clang-tools-extra/unittests/clangd/HeadersTests.cpp:220
+  BarHeader = testPath("sub/bar.h");
+  EXPECT_EQ(calculate(BarHeader), "\"sub/bar.h\"");
 }

sammccall wrote:
> ormris wrote:
> > Quick nit: This test won't work on Windows as it only tests for POSIX-style 
> > path separators. You could easily add a Windows ifdef, though.
> testPath() returns an appropriate native path, and calculate() returns an 
> #include string (which always uses /).
> The "../" on line 217 looks a little more suspicious, but I think the clang 
> driver might silently Do What I Mean here.
> Are you seeing test failures?
Yes, here's the output.

```
[ RUN  ] HeadersTest.ShortenedInclude
C:\llvm\tools\clang\tools\extra\unittests\clangd\HeadersTests.cpp(220): error:  
 Expected: calculate(BarHeader)
  Which is: "\"sub\\bar.h\""
To be equal to: "\"sub/bar.h\""
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60873



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


[PATCH] D60853: clang-format converts a keyword macro definition to a macro function

2019-04-18 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358710: [clang-format] Fix incorrect formatting of keyword 
macro definition (authored by owenpan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60853?vs=195675=195806#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60853

Files:
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -805,7 +805,7 @@
 void UnwrappedLineParser::parsePPDefine() {
   nextToken();
 
-  if (FormatTok->Tok.getKind() != tok::identifier) {
+  if (!FormatTok->Tok.getIdentifierInfo()) {
 IncludeGuard = IG_Rejected;
 IncludeGuardToken = nullptr;
 parsePPUnknown();
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -2468,6 +2468,12 @@
 TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {
   EXPECT_EQ("#define A (x)", format("#define A (x)"));
   EXPECT_EQ("#define A(x)", format("#define A(x)"));
+
+  FormatStyle Style = getLLVMStyle();
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
+  verifyFormat("#define true ((foo)1)", Style);
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+  verifyFormat("#define false((foo)0)", Style);
 }
 
 TEST_F(FormatTest, EmptyLinesInMacroDefinitions) {


Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -805,7 +805,7 @@
 void UnwrappedLineParser::parsePPDefine() {
   nextToken();
 
-  if (FormatTok->Tok.getKind() != tok::identifier) {
+  if (!FormatTok->Tok.getIdentifierInfo()) {
 IncludeGuard = IG_Rejected;
 IncludeGuardToken = nullptr;
 parsePPUnknown();
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -2468,6 +2468,12 @@
 TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {
   EXPECT_EQ("#define A (x)", format("#define A (x)"));
   EXPECT_EQ("#define A(x)", format("#define A(x)"));
+
+  FormatStyle Style = getLLVMStyle();
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
+  verifyFormat("#define true ((foo)1)", Style);
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+  verifyFormat("#define false((foo)0)", Style);
 }
 
 TEST_F(FormatTest, EmptyLinesInMacroDefinitions) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info

2019-04-18 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1966
+  QualType PointeeTy = D.getTypePtr()->getPointeeType();
+  llvm::DIType *DI = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
+  CI->setMetadata("heapallocsite", DI);

akhuang wrote:
> hans wrote:
> > I don't really know this code, but does this also work for void pointers, 
> > i.e. the if statement in the old code was unnecessary?
> I think `getOrCreateType` returns null if it gets a void type, so it doesn't 
> quite work for void pointers. In theory we shouldn't be getting void pointers 
> here since the type should be cast to something but that hasn't been 
> implemented yet.
I think in practice void will be pretty common, so I think we want to leave 
this as it is, and come up with some other workaround in CodeViewDebug.cpp. We 
can leave this as is and have the CodeViewDebug.cpp code interpret an empty 
tuple as a void type.

In hindsight, I think this "void is null" convention wasn't such a good idea, 
since we can't pass it through APIs like Instruction::setMetadata.



Comment at: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp:1239
+  if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) {
+DIType *DI = cast(CLI.CS->getInstruction()->
+  getMetadata("heapallocsite"));

I think you could make `addCodeViewHeapAllocSite` take an `MDNode*` and then do 
this cast inside, and if the cast fails, see if it's the special empty tuple 
that means void, and put a null `DIType*` in the pointer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60800



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


r358710 - [clang-format] Fix incorrect formatting of keyword macro definition

2019-04-18 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Thu Apr 18 13:17:08 2019
New Revision: 358710

URL: http://llvm.org/viewvc/llvm-project?rev=358710=rev
Log:
[clang-format] Fix incorrect formatting of keyword macro definition

See PR39719

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

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=358710=358709=358710=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Apr 18 13:17:08 2019
@@ -805,7 +805,7 @@ void UnwrappedLineParser::parsePPEndIf()
 void UnwrappedLineParser::parsePPDefine() {
   nextToken();
 
-  if (FormatTok->Tok.getKind() != tok::identifier) {
+  if (!FormatTok->Tok.getIdentifierInfo()) {
 IncludeGuard = IG_Rejected;
 IncludeGuardToken = nullptr;
 parsePPUnknown();

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=358710=358709=358710=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Apr 18 13:17:08 2019
@@ -2468,6 +2468,12 @@ TEST_F(FormatTest, HashInMacroDefinition
 TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {
   EXPECT_EQ("#define A (x)", format("#define A (x)"));
   EXPECT_EQ("#define A(x)", format("#define A(x)"));
+
+  FormatStyle Style = getLLVMStyle();
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
+  verifyFormat("#define true ((foo)1)", Style);
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+  verifyFormat("#define false((foo)0)", Style);
 }
 
 TEST_F(FormatTest, EmptyLinesInMacroDefinitions) {


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


[PATCH] D60873: [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

2019-04-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/unittests/clangd/HeadersTests.cpp:220
+  BarHeader = testPath("sub/bar.h");
+  EXPECT_EQ(calculate(BarHeader), "\"sub/bar.h\"");
 }

ormris wrote:
> Quick nit: This test won't work on Windows as it only tests for POSIX-style 
> path separators. You could easily add a Windows ifdef, though.
testPath() returns an appropriate native path, and calculate() returns an 
#include string (which always uses /).
The "../" on line 217 looks a little more suspicious, but I think the clang 
driver might silently Do What I Mean here.
Are you seeing test failures?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60873



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


r358709 - [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Gheorghe-Teodor Bercea via cfe-commits
Author: gbercea
Date: Thu Apr 18 12:53:43 2019
New Revision: 358709

URL: http://llvm.org/viewvc/llvm-project?rev=358709=rev
Log:
[OpenMP] Add checks for requires and target directives.

Summary: The requires directive containing target related clauses must appear 
before any target region in the compilation unit.

Reviewers: ABataev, AlexEichenberger, caomhin

Reviewed By: ABataev

Subscribers: guansong, jfb, jdoerfert, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/OpenMP/requires_target_messages.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/requires_messages.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=358709=358708=358709=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 18 12:53:43 
2019
@@ -9132,6 +9132,10 @@ def err_omp_requires_clause_redeclaratio
   "Only one %0 clause can appear on a requires directive in a single 
translation unit">;
 def note_omp_requires_previous_clause : Note <
   "%0 clause previously used here">;
+def err_omp_target_before_requires : Error <
+  "target region encountered before requires directive with '%0' clause">;
+def note_omp_requires_encountered_target : Note <
+  "target previously encountered here">;
 def err_omp_invalid_scope : Error <
   "'#pragma omp %0' directive must appear only in file scope">;
 def note_omp_invalid_length_on_this_ptr_mapping : Note <

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=358709=358708=358709=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Apr 18 12:53:43 2019
@@ -193,6 +193,8 @@ private:
   /// Expression for the predefined allocators.
   Expr *OMPPredefinedAllocators[OMPAllocateDeclAttr::OMPUserDefinedMemAlloc] = 
{
   nullptr};
+  /// Vector of previously encountered target directives
+  SmallVector TargetLocations;
 
 public:
   explicit DSAStackTy(Sema ) : SemaRef(S) {}
@@ -454,6 +456,16 @@ public:
 return IsDuplicate;
   }
 
+  /// Add location of previously encountered target to internal vector
+  void addTargetDirLocation(SourceLocation LocStart) {
+TargetLocations.push_back(LocStart);
+  }
+
+  // Return previously encountered target region locations.
+  ArrayRef getEncounteredTargetLocs() const {
+return TargetLocations;
+  }
+
   /// Set default data sharing attribute to none.
   void setDefaultDSANone(SourceLocation Loc) {
 assert(!isStackEmpty());
@@ -2418,6 +2430,27 @@ Sema::ActOnOpenMPRequiresDirective(Sourc
 
 OMPRequiresDecl *Sema::CheckOMPRequiresDecl(SourceLocation Loc,
 ArrayRef ClauseList) {
+  /// For target specific clauses, the requires directive cannot be
+  /// specified after the handling of any of the target regions in the
+  /// current compilation unit.
+  ArrayRef TargetLocations =
+  DSAStack->getEncounteredTargetLocs();
+  if (!TargetLocations.empty()) {
+for (const OMPClause *CNew : ClauseList) {
+  // Check if any of the requires clauses affect target regions.
+  if (isa(CNew) ||
+  isa(CNew) ||
+  isa(CNew) ||
+  isa(CNew)) {
+Diag(Loc, diag::err_omp_target_before_requires)
+<< getOpenMPClauseName(CNew->getClauseKind());
+for (SourceLocation TargetLoc : TargetLocations) {
+  Diag(TargetLoc, diag::note_omp_requires_encountered_target);
+}
+  }
+}
+  }
+
   if (!DSAStack->hasDuplicateRequiresClause(ClauseList))
 return OMPRequiresDecl::Create(Context, getCurLexicalContext(), Loc,
ClauseList);
@@ -4167,6 +4200,16 @@ StmtResult Sema::ActOnOpenMPExecutableDi
 ->setIsOMPStructuredBlock(true);
   }
 
+  if (!CurContext->isDependentContext() &&
+  isOpenMPTargetExecutionDirective(Kind) &&
+  !(DSAStack->hasRequiresDeclWithClause() ||
+DSAStack->hasRequiresDeclWithClause() ||
+DSAStack->hasRequiresDeclWithClause() ||
+DSAStack->hasRequiresDeclWithClause())) {
+// Register target to DSA Stack.
+DSAStack->addTargetDirLocation(StartLoc);
+  }
+
   return Res;
 }
 

Modified: cfe/trunk/test/OpenMP/requires_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/requires_messages.cpp?rev=358709=358708=358709=diff
==
--- cfe/trunk/test/OpenMP/requires_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/requires_messages.cpp Thu Apr 18 12:53:43 2019

[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358709: [OpenMP] Add checks for requires and target 
directives. (authored by gbercea, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60875?vs=195793=195803#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60875

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/requires_messages.cpp
  test/OpenMP/requires_target_messages.cpp

Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -9132,6 +9132,10 @@
   "Only one %0 clause can appear on a requires directive in a single translation unit">;
 def note_omp_requires_previous_clause : Note <
   "%0 clause previously used here">;
+def err_omp_target_before_requires : Error <
+  "target region encountered before requires directive with '%0' clause">;
+def note_omp_requires_encountered_target : Note <
+  "target previously encountered here">;
 def err_omp_invalid_scope : Error <
   "'#pragma omp %0' directive must appear only in file scope">;
 def note_omp_invalid_length_on_this_ptr_mapping : Note <
Index: test/OpenMP/requires_target_messages.cpp
===
--- test/OpenMP/requires_target_messages.cpp
+++ test/OpenMP/requires_target_messages.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100  %s
+
+void foo2() {
+  int a;
+  #pragma omp target // expected-note 4 {{Target previously encountered here}}
+  {
+a = a + 1;
+  }
+}
+
+#pragma omp requires atomic_default_mem_order(seq_cst)
+#pragma omp requires unified_address //expected-error {{Target region encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{Target region encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{Target region encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{Target region encountered before requires directive with 'dynamic_allocators' clause}}
Index: test/OpenMP/requires_messages.cpp
===
--- test/OpenMP/requires_messages.cpp
+++ test/OpenMP/requires_messages.cpp
@@ -7,7 +7,7 @@
 
 #pragma omp requires unified_shared_memory, unified_shared_memory // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_shared_memory' clause}}
 
-#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires unified_address, unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_address' clause}}
 
@@ -29,13 +29,13 @@
 
 #pragma omp requires atomic_default_mem_order( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
-#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} 
+#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
 #pragma omp requires atomic_default_mem_order(shared) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 

[PATCH] D60883: [OpenMP] Avoid emitting maps for target link variables when unified memory is used

2019-04-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:7956
+// If using unified memory, no need to do the mappings.
+if (CGF.CGM.getOpenMPRuntime().hasUnifiedAddressingSupport())
+  return;

Hmm, what about regular declare target declarations? Also, this is not enough. 
You also should not capture such variables in the captured regions.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60883



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


[PATCH] D60568: [OpenMP] Add support for registering requires directives with the runtime

2019-04-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: test/OpenMP/openmp_offload_registration.cpp:40
+// CHECK: ret void
+// CHECK: declare void @__tgt_register_requires(i64)
+

ABataev wrote:
> Why do you need this check?
Again, this check is not required



Comment at: test/OpenMP/target_codegen.cpp:99
 // Check target registration is registered as a Ctor.
-// CHECK: appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* 
} { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }]
+// CHECK: appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* 
} { i32 0, void ()* @.omp_offloading.requires_reg, i8* null }, { i32, void ()*, 
i8* } { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }]
 

Add a check for function too


Repository:
  rC Clang

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

https://reviews.llvm.org/D60568



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


[PATCH] D59168: [runtimes] Move libunwind, libc++abi and libc++ to lib/clang/ and include/

2019-04-18 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D59168#1470578 , @phosek wrote:

> In D59168#1469186 , @jdenny wrote:
>
> >
>
>
> I was also thinking about alternative names for the library path, 
> specifically for headers we use `include/c++` but for libraries we'll now use 
> `lib/clang/` which is not very consistent.


Does that inconsistency cause a practical problem?

> I was considering `lib/c++/` instead

A practical benefit might be the ability to use `-L` to expose clang's c++ libs 
without exposing other clang libs as well, but I'm not sure whether that's a 
real use case.

> but that wouldn't work for libomp

If we decide libomp shouldn't be version-locked, then I guess 
`lib/openmp/` would work.

Is it safe to assume that `lib/c++` and `lib/openmp` would manage to be as 
clang-dedicated as `lib/clang`?  If other packages don't install to 
`include/c++`, then I suppose they don't install to `lib/c++`.


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

https://reviews.llvm.org/D59168



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


r358705 - [LibTooling] Fix build breakage from commit 7b7ce6683ee.

2019-04-18 Thread Yitzhak Mandelbaum via cfe-commits
Author: ymandel
Date: Thu Apr 18 12:19:01 2019
New Revision: 358705

URL: http://llvm.org/viewvc/llvm-project?rev=358705=rev
Log:
[LibTooling] Fix build breakage from commit 7b7ce6683ee.

On configurations with -Werror,-Wmissing-field-initializers, the commit does 
not compile. This commit fixes the offending line.

Original Differential Revision: https://reviews.llvm.org/D60408

Modified:
cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp

Modified: cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp?rev=358705=358704=358705=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp Thu Apr 18 12:19:01 2019
@@ -172,7 +172,8 @@ RewriteRule tooling::makeRule(ast_matche
   SmallVector Edits) {
   M.setAllowBind(true);
   // `tryBind` is guaranteed to succeed, because `AllowBind` was set to true.
-  return RewriteRule{*M.tryBind(RewriteRule::RootId), std::move(Edits)};
+  return RewriteRule{*M.tryBind(RewriteRule::RootId), std::move(Edits),
+ nullptr};
 }
 
 constexpr llvm::StringLiteral RewriteRule::RootId;


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


[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rC Clang

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

https://reviews.llvm.org/D60875



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


[PATCH] D60883: [OpenMP] Avoid emitting maps for target link variables when unified memory is used

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea created this revision.
gtbercea added reviewers: ABataev, caomhin.
Herald added subscribers: cfe-commits, jdoerfert, guansong.
Herald added a project: clang.

This patch avoids the emission of maps for target link variables when unified 
memory is present.


Repository:
  rC Clang

https://reviews.llvm.org/D60883

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7952,6 +7952,10 @@
 MapValuesArrayTy ,
 MapValuesArrayTy ,
 MapFlagsArrayTy ) const {
+// If using unified memory, no need to do the mappings.
+if (CGF.CGM.getOpenMPRuntime().hasUnifiedAddressingSupport())
+  return;
+
 // Map other list items in the map clause which are not captured variables
 // but "declare target link" global variables.
 for (const auto *C : this->CurDir.getClausesOfKind()) {


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7952,6 +7952,10 @@
 MapValuesArrayTy ,
 MapValuesArrayTy ,
 MapFlagsArrayTy ) const {
+// If using unified memory, no need to do the mappings.
+if (CGF.CGM.getOpenMPRuntime().hasUnifiedAddressingSupport())
+  return;
+
 // Map other list items in the map clause which are not captured variables
 // but "declare target link" global variables.
 for (const auto *C : this->CurDir.getClausesOfKind()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60873: [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

2019-04-18 Thread Matthew Voss via Phabricator via cfe-commits
ormris added inline comments.



Comment at: clang-tools-extra/unittests/clangd/HeadersTests.cpp:220
+  BarHeader = testPath("sub/bar.h");
+  EXPECT_EQ(calculate(BarHeader), "\"sub/bar.h\"");
 }

Quick nit: This test won't work on Windows as it only tests for POSIX-style 
path separators. You could easily add a Windows ifdef, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60873



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


[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 195793.
gtbercea added a comment.

- Lower case.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60875

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/requires_messages.cpp
  test/OpenMP/requires_target_messages.cpp

Index: test/OpenMP/requires_target_messages.cpp
===
--- /dev/null
+++ test/OpenMP/requires_target_messages.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100  %s
+
+void foo2() {
+  int a;
+  #pragma omp target // expected-note 4 {{Target previously encountered here}}
+  {
+a = a + 1;
+  }
+}
+
+#pragma omp requires atomic_default_mem_order(seq_cst)
+#pragma omp requires unified_address //expected-error {{Target region encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{Target region encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{Target region encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{Target region encountered before requires directive with 'dynamic_allocators' clause}}
Index: test/OpenMP/requires_messages.cpp
===
--- test/OpenMP/requires_messages.cpp
+++ test/OpenMP/requires_messages.cpp
@@ -7,7 +7,7 @@
 
 #pragma omp requires unified_shared_memory, unified_shared_memory // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_shared_memory' clause}}
 
-#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires unified_address, unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_address' clause}}
 
@@ -29,13 +29,13 @@
 
 #pragma omp requires atomic_default_mem_order( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
-#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} 
+#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
 #pragma omp requires atomic_default_mem_order(shared) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires // expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
Index: lib/Sema/SemaOpenMP.cpp
===
--- 

[PATCH] D60872: Add new warning knob for unknown attribute namespaces

2019-04-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Seems pretty good to me - if you'd like to wait for more/other feedback from 
@rsmith or the like, that's OK too.


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

https://reviews.llvm.org/D60872



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


[PATCH] D55044: [clang-tidy] check for Abseil make_unique

2019-04-18 Thread Andy Zhang via Phabricator via cfe-commits
axzhang updated this revision to Diff 195791.
axzhang added a comment.

Simplify tests and fix issues with Options.


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

https://reviews.llvm.org/D55044

Files:
  clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/abseil-make-unique.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-make-unique.rst
  test/clang-tidy/abseil-make-unique.cpp

Index: test/clang-tidy/abseil-make-unique.cpp
===
--- /dev/null
+++ test/clang-tidy/abseil-make-unique.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy %s abseil-make-unique %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+#include "initializer_list.h"
+// CHECK-FIXES: #include "absl/memory/memory.h"
+
+class A {
+ int x;
+ int y;
+
+ public:
+   A(int _x, int _y): x(_x), y(_y) {}
+};
+
+struct B {
+  B(std::initializer_list);
+  B();
+};
+
+struct Base {
+  Base();
+};
+
+struct Derived : public Base {
+  Derived();
+};
+
+int* returnPointer();
+
+std::unique_ptr makeAndReturnPointer() {
+  return std::unique_ptr(new int(0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use absl::make_unique instead [abseil-make-unique]
+  // CHECK-FIXES: return absl::make_unique(0);
+}
+
+void Positives() {
+  std::unique_ptr P1 = std::unique_ptr(new int(1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use absl::make_unique instead [abseil-make-unique]
+  // CHECK-FIXES: std::unique_ptr P1 = absl::make_unique(1);
+
+  P1.reset(new int(2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use absl::make_unique instead [abseil-make-unique]
+  // CHECK-FIXES: P1 = absl::make_unique(2);
+
+  // Non-primitive paramter
+  std::unique_ptr P2 = std::unique_ptr(new A(1, 2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use absl::make_unique instead [abseil-make-unique]
+  // CHECK-FIXES: std::unique_ptr P2 = absl::make_unique(1, 2);
+
+  P2.reset(new A(3, 4));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use absl::make_unique instead [abseil-make-unique]
+  // CHECK-FIXES: P2 = absl::make_unique(3, 4);
+}
+
+void Negatives() {
+  // Only warn if explicitly allocating a new object
+  std::unique_ptr R = std::unique_ptr(returnPointer());
+  R.reset(returnPointer());
+
+  // Only replace if the template type is same as new type
+  auto Pderived = std::unique_ptr(new Derived());
+
+  // Ignore initializer-list constructors
+  std::unique_ptr PInit = std::unique_ptr(new B{1, 2});
+  PInit.reset(new B{1, 2});
+}
Index: docs/clang-tidy/checks/modernize-make-unique.rst
===
--- docs/clang-tidy/checks/modernize-make-unique.rst
+++ docs/clang-tidy/checks/modernize-make-unique.rst
@@ -48,3 +48,9 @@
 
If set to non-zero, the check will not give warnings inside macros. Default
is `1`.
+
+.. option:: IgnoreListInit
+   
+   If set to non-zero, the check will ignore list initializations of `new`
+   expressions. Default is `0`.
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -13,6 +13,7 @@
abseil-duration-subtraction
abseil-duration-unnecessary-conversion
abseil-faster-strsplit-delimiter
+   abseil-make-unique (redirects to modernize-make-unique) 
abseil-no-internal-dependencies
abseil-no-namespace
abseil-redundant-strcat-calls
Index: docs/clang-tidy/checks/abseil-make-unique.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/abseil-make-unique.rst
@@ -0,0 +1,22 @@
+.. title:: clang-tidy - abseil-make-unique
+.. meta::
+   :http-equiv=refresh: 5;URL=abseil-make-unique.html
+
+abseil-make-unique
+==
+
+This check finds the creation of ``std::unique_ptr`` objects by explicitly
+calling the constructor and a ``new`` expression, and replaces it with a call
+to ``absl::make_unique``, the Abseil implementation of ``std::make_unique`` 
+in C++11.
+
+.. code-block:: c++
+
+  auto ptr = std::unique_ptr(new int(1));
+
+  // becomes
+
+  auto ptr = absl::make_unique(1);
+
+The Abseil Style Guide _ discusses this issue in
+more detail.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -85,6 +85,11 @@
   Finds and fixes cases where ``absl::Duration`` values are being converted to
   numeric types and back again.
 
+- New alias :doc:`abseil-make-unique
+  ` to :doc:`modernize-make-unique
+  `
+  added.
+
 - New :doc:`abseil-time-subtraction
   ` check.
 
@@ -104,6 +109,11 @@
   `CommentUserDefiniedLiterals`, `CommentStringLiterals`,
   `CommentCharacterLiterals` & 

[PATCH] D55044: [clang-tidy] check for Abseil make_unique

2019-04-18 Thread Andy Zhang via Phabricator via cfe-commits
axzhang marked 3 inline comments as done.
axzhang added inline comments.



Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:69
+  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
+  IgnoreListInit(Options.get("IgnoreListInit", false)) {}
 

hintonda wrote:
> hintonda wrote:
> > axzhang wrote:
> > > hintonda wrote:
> > > > You’re setting it false here.
> > > I thought that false was the default value if the options do not contain 
> > > "IgnoreListInit"?
> > Do you have a test that passes this option?  I didn’t see one.
> I could be wrong, but when you do an Options.get(), that looks at what was 
> passed on the commandline, and if it wasn't found, it sets the default 
> provided.
Fixed by changing the Options value to "1" instead of true in the 
AbseilTidyModule


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

https://reviews.llvm.org/D55044



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


[PATCH] D60163: [ThinLTO] Handle -fno-builtin* options for distributed backends

2019-04-18 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

ping


Repository:
  rC Clang

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

https://reviews.llvm.org/D60163



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


[PATCH] D60872: Add new warning knob for unknown attribute namespaces

2019-04-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 195790.
aaron.ballman marked 3 inline comments as done.
aaron.ballman added a comment.

Updated based on review feedback.


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

https://reviews.llvm.org/D60872

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Sema/Sema.h
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaStmtAttr.cpp
  lib/Sema/SemaType.cpp
  test/SemaCXX/attr-cxx0x.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -17,7 +17,6 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -2551,6 +2550,16 @@
   ::emitAttrList(OS, Descriptor.MacroName, Attrs);
 }
 
+void addAttrNamespacesTo(std::set ) const {
+  for (const Record *R : Attrs) {
+std::vector Spellings = GetFlattenedSpellings(*R);
+for (const auto  : Spellings) {
+  if (!Spell.nameSpace().empty())
+S.insert(Spell.nameSpace());
+}
+  }
+}
+
 void classifyAttrOnRoot(Record *Attr) {
   bool result = classifyAttr(Attr);
   assert(result && "failed to classify on root"); (void) result;
@@ -2621,6 +2630,19 @@
 #endif
 }
 
+void emitAttrNamespaces(raw_ostream ) const {
+  // Gather the unique set of attribute namespaces Clang knows about. We
+  // want this set to be ordered so we can do efficient lookups.
+  std::set Namespaces;
+  for (const auto  : Classes) {
+Class->addAttrNamespacesTo(Namespaces);
+  }
+  // Emit the list of namespaces.
+  for (const auto  : Namespaces) {
+OS << "ATTR_NAMESPACE(" << Namespace << ")\n";
+  }
+}
+
 void emitDefaultDefines(raw_ostream ) const {
   for (auto  : Classes) {
 Class->emitDefaultDefines(OS);
@@ -2682,6 +2704,7 @@
   // Add defaulting macro definitions.
   Hierarchy.emitDefaultDefines(OS);
   emitDefaultDefine(OS, "PRAGMA_SPELLING_ATTR", nullptr);
+  emitDefaultDefine(OS, "ATTR_NAMESPACE", nullptr);
 
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
   std::vector PragmaAttrs;
@@ -2702,6 +2725,7 @@
 
   // Emit the ad hoc groups.
   emitAttrList(OS, "PRAGMA_SPELLING_ATTR", PragmaAttrs);
+  Hierarchy.emitAttrNamespaces(OS);
 
   // Emit the attribute ranges.
   OS << "#ifdef ATTR_RANGE\n";
@@ -2711,6 +2735,7 @@
 
   Hierarchy.emitUndefs(OS);
   OS << "#undef PRAGMA_SPELLING_ATTR\n";
+  OS << "#undef ATTR_NAMESPACE\n";
 }
 
 // Emits the enumeration list for attributes.
Index: test/SemaCXX/attr-cxx0x.cpp
===
--- test/SemaCXX/attr-cxx0x.cpp
+++ test/SemaCXX/attr-cxx0x.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -pedantic -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -pedantic -DUNKNOWN_ATTRS -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -pedantic -Wno-unknown-attributes -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -pedantic -Wno-unknown-attributes -Wunknown-attribute-namespaces -DUNKNOWN_NAMESPACE -std=c++11 %s
 
 int align_illegal alignas(3); //expected-error {{requested alignment is not a power of 2}}
 char align_big alignas(int);
@@ -46,7 +48,25 @@
 
 static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expected-error{{invalid application of 'alignof' to a function type}}
 
-[[__carries_dependency__]]  // expected-warning{{unknown attribute '__carries_dependency__' ignored}}
+#if defined(UNKNOWN_ATTRS) || defined(UNKNOWN_NAMESPACE)
+// expected-warning@+2 {{unknown attribute '__carries_dependency__' ignored}}
+#endif
+[[__carries_dependency__]]
 void func(void);
 
 alignas(4) auto PR19252 = 0;
+
+#if defined(UNKNOWN_ATTRS) || defined(UNKNOWN_NAMESPACE)
+// expected-warning@+2 {{unknown attribute 'frobble' ignored}}
+#endif
+[[frobble]] int unknown1;
+
+#if defined(UNKNOWN_ATTRS) || defined(UNKNOWN_NAMESPACE)
+// expected-warning@+2 {{unknown attribute 'bobble' ignored}}
+#endif
+[[frobble::bobble]] int unknown2;
+
+#ifdef UNKNOWN_ATTRS
+// expected-warning@+2 {{unknown attribute 'unknown_attribute' ignored}}
+#endif
+[[gsl::unknown_attribute]] int unknown3;
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7441,9 +7441,7 @@
 
 case ParsedAttr::UnknownAttribute:
   if (attr.isCXX11Attribute() && TAL == TAL_DeclChunk)
-state.getSema().Diag(attr.getLoc(),
-  

[PATCH] D60872: Add new warning knob for unknown attribute namespaces

2019-04-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked 7 inline comments as done.
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaDeclAttr.cpp:8623
+  } else if (A.hasScope()) {
+#define ATTR(A)
+#define ATTR_NAMESPACE(A) .Case(#A, false)

dblaikie wrote:
> dblaikie wrote:
> > Not sure how it's done elsewhere - but I'd sink these #defines down to 
> > immediately before the #include
> I think most other uses of .inc files only #define the macros they need to - 
> assuming the others aren't defined, rather than explicitly providing an empty 
> definition? (but I'm not sure - I guess that means teh .inc file needs a 
> #ifndef X \ #define X #endif - but perhaps .inc files usually have those?)
This file is generated without a default for `ATTR`, so there are a few places 
where we have to define it to an empty macro. I could add it to the emitter and 
remove a few of these spurious definitions, but that can be done in a follow-up.



Comment at: lib/Sema/SemaDeclAttr.cpp:8623-8624
+  } else if (A.hasScope()) {
+#define ATTR(A)
+#define ATTR_NAMESPACE(A) .Case(#A, false)
+if (llvm::StringSwitch(A.getScopeName()->getName())

aaron.ballman wrote:
> dblaikie wrote:
> > dblaikie wrote:
> > > Not sure how it's done elsewhere - but I'd sink these #defines down to 
> > > immediately before the #include
> > I think most other uses of .inc files only #define the macros they need to 
> > - assuming the others aren't defined, rather than explicitly providing an 
> > empty definition? (but I'm not sure - I guess that means teh .inc file 
> > needs a #ifndef X \ #define X #endif - but perhaps .inc files usually have 
> > those?)
> This file is generated without a default for `ATTR`, so there are a few 
> places where we have to define it to an empty macro. I could add it to the 
> emitter and remove a few of these spurious definitions, but that can be done 
> in a follow-up.
I think it's pretty awkward either way, so I'll go with your approach.



Comment at: lib/Sema/SemaDeclAttr.cpp:8629-8630
+  Warning = diag::warn_unknown_attribute_namespace_ignored;
+#undef ATTR_NAMESPACE
+#undef ATTR
+  } else if (A.isC2xAttribute() || A.isCXX11Attribute()) {

dblaikie wrote:
> Should AttrList.inc handle undefing all its attributes - so all its users 
> don't have to?
Good catch -- it already does that for me. I'll remove.



Comment at: utils/TableGen/ClangAttrEmitter.cpp:2553
 
+void copyAttrNamespaces(std::set ) const {
+  for (const Record *R : Attrs) {

dblaikie wrote:
> Maybe "addAttrNamespacesTo" (not clear whether this would overwrite the 
> contens of the std::set, or add to it)
Good catch, I missed renaming it after a signature change where it was 
accepting an iterator instead of the container directly.


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

https://reviews.llvm.org/D60872



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


[PATCH] D55044: [clang-tidy] check for Abseil make_unique

2019-04-18 Thread Don Hinton via Phabricator via cfe-commits
hintonda added inline comments.



Comment at: clang-tidy/abseil/AbseilTidyModule.cpp:77
+Opts["abseil-make-unique.MakeSmartPtrFunction"] = "absl::make_unique";
+Opts["abseil-make-unique.IgnoreListInit"] = true;
+return Options;

This is defined as `typedef std::map OptionMap;`, so 
you need to assign a string, not a literal `true` value.  hth...


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

https://reviews.llvm.org/D55044



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


[PATCH] D60872: Add new warning knob for unknown attribute namespaces

2019-04-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: lib/Sema/SemaDeclAttr.cpp:8623
+  } else if (A.hasScope()) {
+#define ATTR(A)
+#define ATTR_NAMESPACE(A) .Case(#A, false)

dblaikie wrote:
> Not sure how it's done elsewhere - but I'd sink these #defines down to 
> immediately before the #include
I think most other uses of .inc files only #define the macros they need to - 
assuming the others aren't defined, rather than explicitly providing an empty 
definition? (but I'm not sure - I guess that means teh .inc file needs a 
#ifndef X \ #define X #endif - but perhaps .inc files usually have those?)



Comment at: lib/Sema/SemaDeclAttr.cpp:8623-8624
+  } else if (A.hasScope()) {
+#define ATTR(A)
+#define ATTR_NAMESPACE(A) .Case(#A, false)
+if (llvm::StringSwitch(A.getScopeName()->getName())

Not sure how it's done elsewhere - but I'd sink these #defines down to 
immediately before the #include



Comment at: lib/Sema/SemaDeclAttr.cpp:8629-8630
+  Warning = diag::warn_unknown_attribute_namespace_ignored;
+#undef ATTR_NAMESPACE
+#undef ATTR
+  } else if (A.isC2xAttribute() || A.isCXX11Attribute()) {

Should AttrList.inc handle undefing all its attributes - so all its users don't 
have to?



Comment at: utils/TableGen/ClangAttrEmitter.cpp:2553
 
+void copyAttrNamespaces(std::set ) const {
+  for (const Record *R : Attrs) {

Maybe "addAttrNamespacesTo" (not clear whether this would overwrite the contens 
of the std::set, or add to it)


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

https://reviews.llvm.org/D60872



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


[PATCH] D60408: [LibTooling] Extend Transformer to support multiple simultaneous changes.

2019-04-18 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
ymandel marked 2 inline comments as done.
Closed by commit rL358697: [LibTooling] Extend Transformer to support multiple 
simultaneous changes. (authored by ymandel, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60408?vs=195365=195785#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60408

Files:
  cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h
  cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp
  cfe/trunk/unittests/Tooling/TransformerTest.cpp

Index: cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp
===
--- cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp
+++ cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp
@@ -144,60 +144,78 @@
   llvm_unreachable("Unexpected case in NodePart type.");
 }
 
-Expected
-tooling::applyRewriteRule(const RewriteRule ,
-  const ast_matchers::MatchFinder::MatchResult ) {
-  if (Match.Context->getDiagnostics().hasErrorOccurred())
-return Transformation();
-
-  auto  = Match.Nodes.getMap();
-  auto It = NodesMap.find(Rule.Target);
-  assert (It != NodesMap.end() && "Rule.Target must be bound in the match.");
-
-  Expected TargetOrErr =
-  getTargetRange(Rule.Target, It->second, Rule.TargetKind, Rule.TargetPart,
- *Match.Context);
-  if (auto Err = TargetOrErr.takeError())
-return std::move(Err);
-  auto  = *TargetOrErr;
-  if (Target.isInvalid() ||
-  isOriginMacroBody(*Match.SourceManager, Target.getBegin()))
-return Transformation();
-
-  return Transformation{Target, Rule.Replacement(Match)};
+Expected>
+tooling::translateEdits(const MatchResult ,
+llvm::ArrayRef Edits) {
+  SmallVector Transformations;
+  auto  = Result.Nodes.getMap();
+  for (const auto  : Edits) {
+auto It = NodesMap.find(Edit.Target);
+assert(It != NodesMap.end() && "Edit target must be bound in the match.");
+
+Expected RangeOrErr = getTargetRange(
+Edit.Target, It->second, Edit.Kind, Edit.Part, *Result.Context);
+if (auto Err = RangeOrErr.takeError())
+  return std::move(Err);
+Transformation T;
+T.Range = *RangeOrErr;
+if (T.Range.isInvalid() ||
+isOriginMacroBody(*Result.SourceManager, T.Range.getBegin()))
+  return SmallVector();
+T.Replacement = Edit.Replacement(Result);
+Transformations.push_back(std::move(T));
+  }
+  return Transformations;
 }
 
-constexpr llvm::StringLiteral RewriteRule::RootId;
-
-RewriteRuleBuilder RewriteRuleBuilder::replaceWith(TextGenerator T) {
-  Rule.Replacement = std::move(T);
-  return *this;
+RewriteRule tooling::makeRule(ast_matchers::internal::DynTypedMatcher M,
+  SmallVector Edits) {
+  M.setAllowBind(true);
+  // `tryBind` is guaranteed to succeed, because `AllowBind` was set to true.
+  return RewriteRule{*M.tryBind(RewriteRule::RootId), std::move(Edits)};
 }
 
-RewriteRuleBuilder RewriteRuleBuilder::because(TextGenerator T) {
-  Rule.Explanation = std::move(T);
-  return *this;
-}
+constexpr llvm::StringLiteral RewriteRule::RootId;
 
 void Transformer::registerMatchers(MatchFinder *MatchFinder) {
   MatchFinder->addDynamicMatcher(Rule.Matcher, this);
 }
 
 void Transformer::run(const MatchResult ) {
-  auto ChangeOrErr = applyRewriteRule(Rule, Result);
-  if (auto Err = ChangeOrErr.takeError()) {
-llvm::errs() << "Rewrite failed: " << llvm::toString(std::move(Err))
+  if (Result.Context->getDiagnostics().hasErrorOccurred())
+return;
+
+  // Verify the existence and validity of the AST node that roots this rule.
+  auto  = Result.Nodes.getMap();
+  auto Root = NodesMap.find(RewriteRule::RootId);
+  assert(Root != NodesMap.end() && "Transformation failed: missing root node.");
+  SourceLocation RootLoc = Result.SourceManager->getExpansionLoc(
+  Root->second.getSourceRange().getBegin());
+  assert(RootLoc.isValid() && "Invalid location for Root node of match.");
+
+  auto TransformationsOrErr = translateEdits(Result, Rule.Edits);
+  if (auto Err = TransformationsOrErr.takeError()) {
+llvm::errs() << "Transformation failed: " << llvm::toString(std::move(Err))
  << "\n";
 return;
   }
-  auto  = *ChangeOrErr;
-  auto  = Change.Range;
-  if (Range.isInvalid()) {
+  auto  = *TransformationsOrErr;
+  if (Transformations.empty()) {
 // No rewrite applied (but no error encountered either).
+RootLoc.print(llvm::errs() << "note: skipping match at loc ",
+  *Result.SourceManager);
+llvm::errs() << "\n";
 return;
   }
-  AtomicChange AC(*Result.SourceManager, Range.getBegin());
-  if (auto Err = AC.replace(*Result.SourceManager, Range, Change.Replacement))
-AC.setError(llvm::toString(std::move(Err)));
+
+  // Convert 

r358697 - [LibTooling] Extend Transformer to support multiple simultaneous changes.

2019-04-18 Thread Yitzhak Mandelbaum via cfe-commits
Author: ymandel
Date: Thu Apr 18 10:52:24 2019
New Revision: 358697

URL: http://llvm.org/viewvc/llvm-project?rev=358697=rev
Log:
[LibTooling] Extend Transformer to support multiple simultaneous changes.

Summary: This revision allows users to specify independent changes to multiple 
(related) sections of the input.  Previously, only a single section of input 
could be selected for replacement.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: jfb, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h
cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp
cfe/trunk/unittests/Tooling/TransformerTest.cpp

Modified: cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h?rev=358697=358696=358697=diff
==
--- cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h (original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h Thu Apr 18 
10:52:24 2019
@@ -20,13 +20,13 @@
 #include "clang/ASTMatchers/ASTMatchersInternal.h"
 #include "clang/Tooling/Refactoring/AtomicChange.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Error.h"
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
 
 namespace clang {
 namespace tooling {
@@ -47,6 +47,98 @@ enum class NodePart {
 using TextGenerator =
 std::function;
 
+/// Wraps a string as a TextGenerator.
+inline TextGenerator text(std::string M) {
+  return [M](const ast_matchers::MatchFinder::MatchResult &) { return M; };
+}
+
+// Description of a source-code edit, expressed in terms of an AST node.
+// Includes: an ID for the (bound) node, a selector for source related to the
+// node, a replacement and, optionally, an explanation for the edit.
+//
+// * Target: the source code impacted by the rule. This identifies an AST node,
+//   or part thereof (\c Part), whose source range indicates the extent of the
+//   replacement applied by the replacement term.  By default, the extent is 
the
+//   node matched by the pattern term (\c NodePart::Node). Target's are typed
+//   (\c Kind), which guides the determination of the node extent.
+//
+// * Replacement: a function that produces a replacement string for the target,
+//   based on the match result.
+//
+// * Note: (optional) a note specifically for this edit, potentially 
referencing
+//   elements of the match.  This will be displayed to the user, where 
possible;
+//   for example, in clang-tidy diagnostics.  Use of notes should be rare --
+//   explanations of the entire rewrite should be set in the rule
+//   (`RewriteRule::Explanation`) instead.  Notes serve the rare cases wherein
+//   edit-specific diagnostics are required.
+//
+// `ASTEdit` should be built using the `change` convenience fucntions. For
+// example,
+// \code
+//   change(fun, NodePart::Name, "Frodo")
+// \endcode
+// Or, if we use Stencil for the TextGenerator:
+// \code
+//   change(thenNode, stencil::cat("{", thenNode, "}"))
+//   change(call, NodePart::Args, stencil::cat(x, ",", y))
+// .note("argument order changed.")
+// \endcode
+// Or, if you are changing the node corresponding to the rule's matcher, you 
can
+// use the single-argument override of \c change:
+// \code
+//   change("different_expr")
+// \endcode
+struct ASTEdit {
+  // The (bound) id of the node whose source will be replaced.  This id should
+  // never be the empty string.
+  std::string Target;
+  ast_type_traits::ASTNodeKind Kind;
+  NodePart Part;
+  TextGenerator Replacement;
+  TextGenerator Note;
+};
+
+// Convenience functions for creating \c ASTEdits.  They all must be explicitly
+// instantiated with the desired AST type.  Each overload includes both \c
+// std::string and \c TextGenerator versions.
+
+// FIXME: For overloads taking a \c NodePart, constrain the valid values of \c
+// Part based on the type \c T.
+template 
+ASTEdit change(StringRef Target, NodePart Part, TextGenerator Replacement) {
+  ASTEdit E;
+  E.Target = Target.str();
+  E.Kind = ast_type_traits::ASTNodeKind::getFromNodeKind();
+  E.Part = Part;
+  E.Replacement = std::move(Replacement);
+  return E;
+}
+
+template 
+ASTEdit change(StringRef Target, NodePart Part, std::string Replacement) {
+  return change(Target, Part, text(std::move(Replacement)));
+}
+
+/// Variant of \c change for which the NodePart defaults to the whole node.
+template 
+ASTEdit change(StringRef Target, TextGenerator Replacement) {
+  return change(Target, NodePart::Node, std::move(Replacement));
+}
+
+/// Variant of \c change for which the NodePart defaults to the whole node.
+template 
+ASTEdit change(StringRef Target, std::string Replacement) {
+  return change(Target, text(std::move(Replacement)));
+}
+
+/// Variant of \c change that selects the 

[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info

2019-04-18 Thread Amy Huang via Phabricator via cfe-commits
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1966
+  QualType PointeeTy = D.getTypePtr()->getPointeeType();
+  llvm::DIType *DI = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
+  CI->setMetadata("heapallocsite", DI);

hans wrote:
> I don't really know this code, but does this also work for void pointers, 
> i.e. the if statement in the old code was unnecessary?
I think `getOrCreateType` returns null if it gets a void type, so it doesn't 
quite work for void pointers. In theory we shouldn't be getting void pointers 
here since the type should be cast to something but that hasn't been 
implemented yet.



Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:1078
+  MCSymbol *EndLabel = std::get<1>(HeapAllocSite);
+  DIType *DITy = cast(std::get<2>(HeapAllocSite));
+

hans wrote:
> Is the cast necessary? Couldn't the tuple member be made a DIType* in the 
> first place?
Changed the tuple member to be a DIType.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60800



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


[PATCH] D60800: [MS] Emit S_HEAPALLOCSITE debug info

2019-04-18 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 195783.
akhuang marked 4 inline comments as done.
akhuang added a comment.

Removed extraneous information from test; changed type to DIType


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60800

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/test/CodeGen/X86/label-heapallocsite.ll

Index: llvm/test/CodeGen/X86/label-heapallocsite.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/label-heapallocsite.ll
@@ -0,0 +1,68 @@
+; RUN: llc -O0 < %s | FileCheck %s
+; FIXME: Add test for llc with optimizations once it is implemented.
+
+; Source to regenerate:
+; $ clang --target=x86_64-windows-msvc -S heapallocsite.c  -g -gcodeview -o t.ll \
+;  -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions
+; __declspec(allocator) char *myalloc();
+; void g();
+; void foo() {
+;   g();
+;   myalloc()
+;   g();
+; }
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+; Function Attrs: noinline nounwind optnone
+define dso_local void @f() #0 !dbg !7 {
+entry:
+  call void @g(), !dbg !11
+  %call = call i8* @myalloc(), !dbg !12, !heapallocsite !13
+  call void @g(), !dbg !14
+  ret void, !dbg !15
+}
+
+; CHECK-LABEL: f: # @f
+; CHECK: callq g
+; CHECK: .Lheapallocsite0:
+; CHECK: callq myalloc
+; CHECK: .Lheapallocsite1:
+; CHECK: retq
+
+; CHECK-LABEL: .short  4423# Record kind: S_GPROC32_ID
+; CHECK:   .short  4446# Record kind: S_HEAPALLOCSITE
+; CHECK-NEXT:  .secrel32   .Lheapallocsite0
+; CHECK-NEXT:  .secidx .Lheapallocsite0
+; CHECK-NEXT:  .short  .Lheapallocsite1-.Lheapallocsite0
+; CHECK-NEXT:  .long 112
+; CHECK-NEXT:  .p2align 2
+
+; CHECK-LABEL: .short  4431# Record kind: S_PROC_ID_END
+
+declare dso_local void @g() #1
+
+declare dso_local i8* @myalloc() #1
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
+!1 = !DIFile(filename: "", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9")
+!2 = !{}
+!3 = !{i32 2, !"CodeView", i32 1}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 2}
+!6 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"}
+!7 = distinct !DISubprogram(name: "f", scope: !8, file: !8, line: 4, type: !9, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DIFile(filename: "heapallocsite.c", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9")
+!9 = !DISubroutineType(types: !10)
+!10 = !{null}
+!11 = !DILocation(line: 5, scope: !7)
+!12 = !DILocation(line: 6, scope: !7)
+!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!14 = !DILocation(line: 7, scope: !7)
+!15 = !DILocation(line: 8, scope: !7)
+
Index: llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1234,6 +1234,13 @@
   if (CLI.NumResultRegs && CLI.CS)
 updateValueMap(CLI.CS->getInstruction(), CLI.ResultReg, CLI.NumResultRegs);
 
+  // Set labels for heapallocsite call.
+  if (CLI.CS && CLI.CS->getInstruction()->getMetadata("heapallocsite")) {
+DIType *DI = cast(CLI.CS->getInstruction()->
+  getMetadata("heapallocsite"));
+MF->addCodeViewHeapAllocSite(CLI.Call, DI);
+  }
+
   return true;
 }
 
Index: llvm/lib/CodeGen/MachineFunction.cpp
===
--- llvm/lib/CodeGen/MachineFunction.cpp
+++ llvm/lib/CodeGen/MachineFunction.cpp
@@ -806,6 +806,14 @@
   return FilterID;
 }
 
+void MachineFunction::addCodeViewHeapAllocSite(MachineInstr *I, DIType *DI) {
+  MCSymbol *BeginLabel = Ctx.createTempSymbol("heapallocsite", true);
+  MCSymbol *EndLabel = Ctx.createTempSymbol("heapallocsite", true);
+  I->setPreInstrSymbol(*this, BeginLabel);
+  I->setPostInstrSymbol(*this, EndLabel);
+  CodeViewHeapAllocSites.push_back({BeginLabel, EndLabel, DI});
+}
+
 /// \}
 
 //===--===//
Index: 

[PATCH] D60349: [COFF, ARM64] Fix ABI implementation of struct returns

2019-04-18 Thread Richard Townsend (Arm) via Phabricator via cfe-commits
richard.townsend.arm added inline comments.



Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:1090
+FI.getReturnInfo().setSRetAfterThis(isInstanceMethod);
+FI.getReturnInfo().setInReg(isAArch64 && isIndirectReturn);
 

Based on https://reviews.llvm.org/D60348 - 
lib/Target/AArch64/AArch64CallingConvention.td (line 44), should this be 
(isIndirectReturn || isInstanceMethod)? 


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

https://reviews.llvm.org/D60349



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


[PATCH] D59459: [analyzer][NFC] Prefer binary searches in CheckerRegistry

2019-04-18 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358695: [analyzer][NFC] Prefer binary searches in 
CheckerRegistry (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59459?vs=195358=195781#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59459

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
  cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -48,6 +48,28 @@
 using CheckerNameLT = FullNameLT;
 } // end of anonymous namespace
 
+template 
+static
+typename std::conditional::value,
+  typename CheckerOrPackageInfoList::const_iterator,
+  typename CheckerOrPackageInfoList::iterator>::type
+binaryFind(CheckerOrPackageInfoList , StringRef FullName) {
+
+  using CheckerOrPackage = typename CheckerOrPackageInfoList::value_type;
+  using CheckerOrPackageFullNameLT = FullNameLT;
+
+  assert(std::is_sorted(Collection.begin(), Collection.end(),
+CheckerOrPackageFullNameLT{}) &&
+ "In order to efficiently gather checkers/packages, this function "
+ "expects them to be already sorted!");
+
+  typename CheckerOrPackageInfoList::value_type Info(FullName);
+
+  return llvm::lower_bound(
+  Collection, Info,
+  FullNameLT{});
+}
+
 static constexpr char PackageSeparator = '.';
 
 static bool isInPackage(const CheckerRegistry::CheckerInfo ,
@@ -69,16 +91,7 @@
 
 CheckerRegistry::CheckerInfoListRange
 CheckerRegistry::getMutableCheckersForCmdLineArg(StringRef CmdLineArg) {
-
-  assert(std::is_sorted(Checkers.begin(), Checkers.end(), CheckerNameLT{}) &&
- "In order to efficiently gather checkers, this function expects them "
- "to be already sorted!");
-
-  // Use a binary search to find the possible start of the package.
-  CheckerRegistry::CheckerInfo PackageInfo(nullptr, nullptr, CmdLineArg, "",
-   "");
-  auto It = std::lower_bound(Checkers.begin(), Checkers.end(), PackageInfo,
- CheckerNameLT{});
+  auto It = binaryFind(Checkers, CmdLineArg);
 
   if (!isInPackage(*It, CmdLineArg))
 return {Checkers.end(), Checkers.end()};
@@ -268,24 +281,18 @@
   }
 }
 
-void CheckerRegistry::addDependency(StringRef FullName, StringRef dependency) {
-  auto CheckerThatNeedsDeps = [](const CheckerInfo ) {
-return Chk.FullName == FullName;
-  };
-  auto Dependency = [](const CheckerInfo ) {
-return Chk.FullName == dependency;
-  };
-
-  auto CheckerIt = llvm::find_if(Checkers, CheckerThatNeedsDeps);
-  assert(CheckerIt != Checkers.end() &&
+void CheckerRegistry::addDependency(StringRef FullName, StringRef Dependency) {
+  auto CheckerIt = binaryFind(Checkers, FullName);
+  assert(CheckerIt != Checkers.end() && CheckerIt->FullName == FullName &&
  "Failed to find the checker while attempting to set up its "
  "dependencies!");
 
-  auto DependencyIt = llvm::find_if(Checkers, Dependency);
+  auto DependencyIt = binaryFind(Checkers, Dependency);
   assert(DependencyIt != Checkers.end() &&
+ DependencyIt->FullName == Dependency &&
  "Failed to find the dependency of a checker!");
 
-  CheckerIt->Dependencies.push_back(&*DependencyIt);
+  CheckerIt->Dependencies.emplace_back(&*DependencyIt);
 }
 
 void CheckerRegistry::initializeManager(CheckerManager ) const {
Index: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -108,8 +108,8 @@
   State_Enabled
 };
 
-InitializationFunction Initialize;
-ShouldRegisterFunction ShouldRegister;
+InitializationFunction Initialize = nullptr;
+ShouldRegisterFunction ShouldRegister = nullptr;
 StringRef FullName;
 StringRef Desc;
 StringRef DocumentationUri;
@@ -129,6 +129,9 @@
 StringRef Name, StringRef Desc, StringRef DocsUri)
 : Initialize(Fn), ShouldRegister(sfn), FullName(Name), Desc(Desc),
   DocumentationUri(DocsUri) {}
+
+// Used for lower_bound.
+explicit CheckerInfo(StringRef FullName) : FullName(FullName) {}
   };
 
   using StateFromCmdLine = CheckerInfo::StateFromCmdLine;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r358696 - [CodeComplete] Remove obsolete isOutputBinary().

2019-04-18 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Apr 18 10:35:55 2019
New Revision: 358696

URL: http://llvm.org/viewvc/llvm-project?rev=358696=rev
Log:
[CodeComplete] Remove obsolete isOutputBinary().

Summary:
It's never set to true. Its only effect would be to set stdout to binary mode.
Hopefully we have better ways of doing this by now :-)

Reviewers: hokein

Subscribers: jkorous, arphaman, kadircet, llvm-commits

Tags: #llvm

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

Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
cfe/trunk/unittests/Sema/CodeCompleteTest.cpp

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=358696=358695=358696=diff
==
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Thu Apr 18 10:35:55 2019
@@ -992,10 +992,6 @@ class CodeCompleteConsumer {
 protected:
   const CodeCompleteOptions CodeCompleteOpts;
 
-  /// Whether the output format for the code-completion consumer is
-  /// binary.
-  bool OutputIsBinary;
-
 public:
   class OverloadCandidate {
   public:
@@ -1066,9 +1062,8 @@ public:
   bool IncludeBriefComments) const;
   };
 
-  CodeCompleteConsumer(const CodeCompleteOptions ,
-   bool OutputIsBinary)
-  : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary) {}
+  CodeCompleteConsumer(const CodeCompleteOptions )
+  : CodeCompleteOpts(CodeCompleteOpts) {}
 
   /// Whether the code-completion consumer wants to see macros.
   bool includeMacros() const {
@@ -1106,9 +1101,6 @@ public:
 return CodeCompleteOpts.LoadExternal;
   }
 
-  /// Determine whether the output of this consumer is binary.
-  bool isOutputBinary() const { return OutputIsBinary; }
-
   /// Deregisters and destroys this code-completion consumer.
   virtual ~CodeCompleteConsumer();
 
@@ -1181,7 +1173,7 @@ public:
   /// results to the given raw output stream.
   PrintingCodeCompleteConsumer(const CodeCompleteOptions ,
raw_ostream )
-  : CodeCompleteConsumer(CodeCompleteOpts, false), OS(OS),
+  : CodeCompleteConsumer(CodeCompleteOpts), OS(OS),
 CCTUInfo(std::make_shared()) {}
 
   /// Prints the finalized code-completion results.

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=358696=358695=358696=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Apr 18 10:35:55 2019
@@ -1877,8 +1877,7 @@ namespace {
   public:
 AugmentedCodeCompleteConsumer(ASTUnit , CodeCompleteConsumer ,
   const CodeCompleteOptions )
-: CodeCompleteConsumer(CodeCompleteOpts, Next.isOutputBinary()),
-  AST(AST), Next(Next) {
+: CodeCompleteConsumer(CodeCompleteOpts), AST(AST), Next(Next) {
   // Compute the set of contexts in which we will look when we don't have
   // any information about the specific context.
   NormalContexts

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=358696=358695=358696=diff
==
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Apr 18 10:35:55 2019
@@ -585,12 +585,6 @@ void CompilerInstance::createCodeComplet
 setCodeCompletionConsumer(nullptr);
 return;
   }
-
-  if (CompletionConsumer->isOutputBinary() &&
-  llvm::sys::ChangeStdoutToBinary()) {
-getPreprocessor().getDiagnostics().Report(diag::err_fe_stdout_binary);
-setCodeCompletionConsumer(nullptr);
-  }
 }
 
 void CompilerInstance::createFrontendTimer() {

Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=358696=358695=358696=diff
==
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Thu Apr 18 10:35:55 2019
@@ -568,9 +568,8 @@ namespace {
 CaptureCompletionResults(const CodeCompleteOptions ,
  AllocatedCXCodeCompleteResults ,
  CXTranslationUnit *TranslationUnit)
-  : CodeCompleteConsumer(Opts, false), 
-AllocatedResults(Results), CCTUInfo(Results.CodeCompletionAllocator),
-

[PATCH] D59458: [analyzer][NFC] Clang-format CheckerRegistry

2019-04-18 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358694: [analyzer][NFC] Clang-format CheckerRegistry 
(authored by Szelethus, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D59458

Files:
  include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
  lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Index: lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===
--- lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -11,8 +11,8 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
-#include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/StringMap.h"
@@ -39,8 +39,7 @@
 }
 
 namespace {
-template 
-struct FullNameLT {
+template  struct FullNameLT {
   bool operator()(const T , const T ) {
 return Lhs.FullName < Rhs.FullName;
   }
@@ -76,13 +75,13 @@
  "to be already sorted!");
 
   // Use a binary search to find the possible start of the package.
-  CheckerRegistry::CheckerInfo
-  PackageInfo(nullptr, nullptr, CmdLineArg, "", "");
-  auto It = std::lower_bound(Checkers.begin(), Checkers.end(),
- PackageInfo, CheckerNameLT{});
+  CheckerRegistry::CheckerInfo PackageInfo(nullptr, nullptr, CmdLineArg, "",
+   "");
+  auto It = std::lower_bound(Checkers.begin(), Checkers.end(), PackageInfo,
+ CheckerNameLT{});
 
   if (!isInPackage(*It, CmdLineArg))
-return { Checkers.end(), Checkers.end() };
+return {Checkers.end(), Checkers.end()};
 
   // See how large the package is.
   // If the package doesn't exist, assume the option refers to a single
@@ -94,15 +93,14 @@
   if (PackageSize != PackageSizes.end())
 Size = PackageSize->getValue();
 
-  return { It, It + Size };
+  return {It, It + Size};
 }
 
 CheckerRegistry::CheckerRegistry(
- ArrayRef Plugins, DiagnosticsEngine ,
- AnalyzerOptions , const LangOptions ,
- ArrayRef>
- CheckerRegistrationFns)
-  : Diags(Diags), AnOpts(AnOpts), LangOpts(LangOpts) {
+ArrayRef Plugins, DiagnosticsEngine ,
+AnalyzerOptions , const LangOptions ,
+ArrayRef> CheckerRegistrationFns)
+: Diags(Diags), AnOpts(AnOpts), LangOpts(LangOpts) {
 
   // Register builtin checkers.
 #define GET_CHECKERS
@@ -135,22 +133,21 @@
   Diags.Report(diag::warn_incompatible_analyzer_plugin_api)
   << llvm::sys::path::filename(Plugin);
   Diags.Report(diag::note_incompatible_analyzer_plugin_api)
-  << CLANG_ANALYZER_API_VERSION_STRING
-  << PluginAPIVersion;
+  << CLANG_ANALYZER_API_VERSION_STRING << PluginAPIVersion;
   continue;
 }
 
 // Register its checkers.
 RegisterCheckersFn RegisterPluginCheckers =
-reinterpret_cast(Lib.getAddressOfSymbol(
- "clang_registerCheckers"));
+reinterpret_cast(
+Lib.getAddressOfSymbol("clang_registerCheckers"));
 if (RegisterPluginCheckers)
   RegisterPluginCheckers(*this);
   }
 
   // Register statically linked checkers, that aren't generated from the tblgen
-  // file, but rather passed their registry function as a parameter in 
-  // checkerRegistrationFns. 
+  // file, but rather passed their registry function as a parameter in
+  // checkerRegistrationFns.
 
   for (const auto  : CheckerRegistrationFns)
 Fn(*this);
@@ -174,7 +171,7 @@
   // command line.
   for (const std::pair  : AnOpts.CheckersControlList) {
 CheckerInfoListRange CheckerForCmdLineArg =
- getMutableCheckersForCmdLineArg(Opt.first);
+getMutableCheckersForCmdLineArg(Opt.first);
 
 if (CheckerForCmdLineArg.begin() == CheckerForCmdLineArg.end()) {
   Diags.Report(diag::err_unknown_analyzer_checker) << Opt.first;
@@ -182,22 +179,23 @@
 }
 
 for (CheckerInfo  : CheckerForCmdLineArg) {
-  checker.State = Opt.second ? StateFromCmdLine::State_Enabled :
-   StateFromCmdLine::State_Disabled;
+  checker.State = Opt.second ? StateFromCmdLine::State_Enabled
+ : StateFromCmdLine::State_Disabled;
 }
   }
 }
 
 /// Collects dependencies in \p ret, returns false on failure.
-static bool collectDependenciesImpl(
-  const CheckerRegistry::ConstCheckerInfoList ,
-  const LangOptions ,
-  CheckerRegistry::CheckerInfoSet );
+static bool
+collectDependenciesImpl(const 

[clang-tools-extra] r358696 - [CodeComplete] Remove obsolete isOutputBinary().

2019-04-18 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Apr 18 10:35:55 2019
New Revision: 358696

URL: http://llvm.org/viewvc/llvm-project?rev=358696=rev
Log:
[CodeComplete] Remove obsolete isOutputBinary().

Summary:
It's never set to true. Its only effect would be to set stdout to binary mode.
Hopefully we have better ways of doing this by now :-)

Reviewers: hokein

Subscribers: jkorous, arphaman, kadircet, llvm-commits

Tags: #llvm

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=358696=358695=358696=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Apr 18 10:35:55 2019
@@ -701,8 +701,7 @@ static bool isBlacklistedMember(const Na
 struct CompletionRecorder : public CodeCompleteConsumer {
   CompletionRecorder(const CodeCompleteOptions ,
  llvm::unique_function ResultsCallback)
-  : CodeCompleteConsumer(Opts.getClangCompleteOpts(),
- /*OutputIsBinary=*/false),
+  : CodeCompleteConsumer(Opts.getClangCompleteOpts()),
 CCContext(CodeCompletionContext::CCC_Other), Opts(Opts),
 CCAllocator(std::make_shared()),
 CCTUInfo(CCAllocator), ResultsCallback(std::move(ResultsCallback)) {
@@ -823,8 +822,7 @@ class SignatureHelpCollector final : pub
 public:
   SignatureHelpCollector(const clang::CodeCompleteOptions ,
  const SymbolIndex *Index, SignatureHelp )
-  : CodeCompleteConsumer(CodeCompleteOpts,
- /*OutputIsBinary=*/false),
+  : CodeCompleteConsumer(CodeCompleteOpts),
 SigHelp(SigHelp),
 Allocator(std::make_shared()),
 CCTUInfo(Allocator), Index(Index) {}


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


r358694 - [analyzer][NFC] Clang-format CheckerRegistry

2019-04-18 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Thu Apr 18 10:32:51 2019
New Revision: 358694

URL: http://llvm.org/viewvc/llvm-project?rev=358694=rev
Log:
[analyzer][NFC] Clang-format CheckerRegistry

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h?rev=358694=358693=358694=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h Thu Apr 
18 10:32:51 2019
@@ -81,11 +81,10 @@ namespace ento {
 /// "core.builtin", or the full name "core.builtin.NoReturnFunctionChecker".
 class CheckerRegistry {
 public:
-  CheckerRegistry(
-  ArrayRef plugins, DiagnosticsEngine ,
-  AnalyzerOptions , const LangOptions ,
-  ArrayRef>
-  checkerRegistrationFns = {});
+  CheckerRegistry(ArrayRef plugins, DiagnosticsEngine ,
+  AnalyzerOptions , const LangOptions ,
+  ArrayRef>
+  checkerRegistrationFns = {});
 
   /// Initialization functions perform any necessary setup for a checker.
   /// They should include a call to CheckerManager::registerChecker.
@@ -135,14 +134,11 @@ public:
   using StateFromCmdLine = CheckerInfo::StateFromCmdLine;
 
 private:
-  template 
-  static void initializeManager(CheckerManager ) {
+  template  static void initializeManager(CheckerManager ) {
 mgr.registerChecker();
   }
 
-
-  template 
-  static bool returnTrue(const LangOptions ) {
+  template  static bool returnTrue(const LangOptions ) {
 return true;
   }
 

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp?rev=358694=358693=358694=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp Thu Apr 18 
10:32:51 2019
@@ -11,8 +11,8 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
-#include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/StringMap.h"
@@ -39,8 +39,7 @@ static bool isCompatibleAPIVersion(const
 }
 
 namespace {
-template 
-struct FullNameLT {
+template  struct FullNameLT {
   bool operator()(const T , const T ) {
 return Lhs.FullName < Rhs.FullName;
   }
@@ -76,13 +75,13 @@ CheckerRegistry::getMutableCheckersForCm
  "to be already sorted!");
 
   // Use a binary search to find the possible start of the package.
-  CheckerRegistry::CheckerInfo
-  PackageInfo(nullptr, nullptr, CmdLineArg, "", "");
-  auto It = std::lower_bound(Checkers.begin(), Checkers.end(),
- PackageInfo, CheckerNameLT{});
+  CheckerRegistry::CheckerInfo PackageInfo(nullptr, nullptr, CmdLineArg, "",
+   "");
+  auto It = std::lower_bound(Checkers.begin(), Checkers.end(), PackageInfo,
+ CheckerNameLT{});
 
   if (!isInPackage(*It, CmdLineArg))
-return { Checkers.end(), Checkers.end() };
+return {Checkers.end(), Checkers.end()};
 
   // See how large the package is.
   // If the package doesn't exist, assume the option refers to a single
@@ -94,15 +93,14 @@ CheckerRegistry::getMutableCheckersForCm
   if (PackageSize != PackageSizes.end())
 Size = PackageSize->getValue();
 
-  return { It, It + Size };
+  return {It, It + Size};
 }
 
 CheckerRegistry::CheckerRegistry(
- ArrayRef Plugins, DiagnosticsEngine ,
- AnalyzerOptions , const LangOptions ,
- ArrayRef>
- CheckerRegistrationFns)
-  : Diags(Diags), AnOpts(AnOpts), LangOpts(LangOpts) {
+ArrayRef Plugins, DiagnosticsEngine ,
+AnalyzerOptions , const LangOptions ,
+ArrayRef> CheckerRegistrationFns)
+: Diags(Diags), AnOpts(AnOpts), LangOpts(LangOpts) {
 
   // Register builtin checkers.
 #define GET_CHECKERS
@@ -135,22 +133,21 @@ CheckerRegistry::CheckerRegistry(
   Diags.Report(diag::warn_incompatible_analyzer_plugin_api)
   << llvm::sys::path::filename(Plugin);
   Diags.Report(diag::note_incompatible_analyzer_plugin_api)
-  << CLANG_ANALYZER_API_VERSION_STRING
-  << PluginAPIVersion;
+  << CLANG_ANALYZER_API_VERSION_STRING << PluginAPIVersion;
   continue;
 }
 
 // Register its 

r358695 - [analyzer][NFC] Prefer binary searches in CheckerRegistry

2019-04-18 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Thu Apr 18 10:34:45 2019
New Revision: 358695

URL: http://llvm.org/viewvc/llvm-project?rev=358695=rev
Log:
[analyzer][NFC] Prefer binary searches in CheckerRegistry

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h?rev=358695=358694=358695=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h Thu Apr 
18 10:34:45 2019
@@ -108,8 +108,8 @@ public:
   State_Enabled
 };
 
-InitializationFunction Initialize;
-ShouldRegisterFunction ShouldRegister;
+InitializationFunction Initialize = nullptr;
+ShouldRegisterFunction ShouldRegister = nullptr;
 StringRef FullName;
 StringRef Desc;
 StringRef DocumentationUri;
@@ -129,6 +129,9 @@ public:
 StringRef Name, StringRef Desc, StringRef DocsUri)
 : Initialize(Fn), ShouldRegister(sfn), FullName(Name), Desc(Desc),
   DocumentationUri(DocsUri) {}
+
+// Used for lower_bound.
+explicit CheckerInfo(StringRef FullName) : FullName(FullName) {}
   };
 
   using StateFromCmdLine = CheckerInfo::StateFromCmdLine;

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp?rev=358695=358694=358695=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp Thu Apr 18 
10:34:45 2019
@@ -48,6 +48,28 @@ template  struct FullNameLT {
 using CheckerNameLT = FullNameLT;
 } // end of anonymous namespace
 
+template 
+static
+typename std::conditional::value,
+  typename 
CheckerOrPackageInfoList::const_iterator,
+  typename 
CheckerOrPackageInfoList::iterator>::type
+binaryFind(CheckerOrPackageInfoList , StringRef FullName) {
+
+  using CheckerOrPackage = typename CheckerOrPackageInfoList::value_type;
+  using CheckerOrPackageFullNameLT = FullNameLT;
+
+  assert(std::is_sorted(Collection.begin(), Collection.end(),
+CheckerOrPackageFullNameLT{}) &&
+ "In order to efficiently gather checkers/packages, this function "
+ "expects them to be already sorted!");
+
+  typename CheckerOrPackageInfoList::value_type Info(FullName);
+
+  return llvm::lower_bound(
+  Collection, Info,
+  FullNameLT{});
+}
+
 static constexpr char PackageSeparator = '.';
 
 static bool isInPackage(const CheckerRegistry::CheckerInfo ,
@@ -69,16 +91,7 @@ static bool isInPackage(const CheckerReg
 
 CheckerRegistry::CheckerInfoListRange
 CheckerRegistry::getMutableCheckersForCmdLineArg(StringRef CmdLineArg) {
-
-  assert(std::is_sorted(Checkers.begin(), Checkers.end(), CheckerNameLT{}) &&
- "In order to efficiently gather checkers, this function expects them "
- "to be already sorted!");
-
-  // Use a binary search to find the possible start of the package.
-  CheckerRegistry::CheckerInfo PackageInfo(nullptr, nullptr, CmdLineArg, "",
-   "");
-  auto It = std::lower_bound(Checkers.begin(), Checkers.end(), PackageInfo,
- CheckerNameLT{});
+  auto It = binaryFind(Checkers, CmdLineArg);
 
   if (!isInPackage(*It, CmdLineArg))
 return {Checkers.end(), Checkers.end()};
@@ -268,24 +281,18 @@ void CheckerRegistry::addChecker(Initial
   }
 }
 
-void CheckerRegistry::addDependency(StringRef FullName, StringRef dependency) {
-  auto CheckerThatNeedsDeps = [](const CheckerInfo ) {
-return Chk.FullName == FullName;
-  };
-  auto Dependency = [](const CheckerInfo ) {
-return Chk.FullName == dependency;
-  };
-
-  auto CheckerIt = llvm::find_if(Checkers, CheckerThatNeedsDeps);
-  assert(CheckerIt != Checkers.end() &&
+void CheckerRegistry::addDependency(StringRef FullName, StringRef Dependency) {
+  auto CheckerIt = binaryFind(Checkers, FullName);
+  assert(CheckerIt != Checkers.end() && CheckerIt->FullName == FullName &&
  "Failed to find the checker while attempting to set up its "
  "dependencies!");
 
-  auto DependencyIt = llvm::find_if(Checkers, Dependency);
+  auto DependencyIt = binaryFind(Checkers, Dependency);
   assert(DependencyIt != Checkers.end() &&
+ DependencyIt->FullName == Dependency &&
  "Failed to find the dependency of a checker!");
 
-  CheckerIt->Dependencies.push_back(&*DependencyIt);
+  

[PATCH] D59371: [LibTooling] Add Stencil library for format-string style codegen.

2019-04-18 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358691: [LibTooling] Add Stencil library for format-string 
style codegen. (authored by ymandel, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D59371?vs=195606=195778#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D59371

Files:
  include/clang/Tooling/Refactoring/Stencil.h
  lib/Tooling/Refactoring/CMakeLists.txt
  lib/Tooling/Refactoring/Stencil.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/StencilTest.cpp

Index: unittests/Tooling/StencilTest.cpp
===
--- unittests/Tooling/StencilTest.cpp
+++ unittests/Tooling/StencilTest.cpp
@@ -0,0 +1,223 @@
+//===- unittest/Tooling/StencilTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/Stencil.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/FixIt.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace tooling;
+using namespace ast_matchers;
+
+namespace {
+using ::testing::AllOf;
+using ::testing::Eq;
+using ::testing::HasSubstr;
+using MatchResult = MatchFinder::MatchResult;
+using tooling::stencil::node;
+using tooling::stencil::sNode;
+using tooling::stencil::text;
+
+// In tests, we can't directly match on llvm::Expected since its accessors
+// mutate the object. So, we collapse it to an Optional.
+static llvm::Optional toOptional(llvm::Expected V) {
+  if (V)
+return *V;
+  ADD_FAILURE() << "Losing error in conversion to IsSomething: "
+<< llvm::toString(V.takeError());
+  return llvm::None;
+}
+
+// A very simple matcher for llvm::Optional values.
+MATCHER_P(IsSomething, ValueMatcher, "") {
+  if (!arg)
+return false;
+  return ::testing::ExplainMatchResult(ValueMatcher, *arg, result_listener);
+}
+
+// Create a valid translation-unit from a statement.
+static std::string wrapSnippet(llvm::Twine StatementCode) {
+  return ("auto stencil_test_snippet = []{" + StatementCode + "};").str();
+}
+
+static DeclarationMatcher wrapMatcher(const StatementMatcher ) {
+  return varDecl(hasName("stencil_test_snippet"),
+ hasDescendant(compoundStmt(hasAnySubstatement(Matcher;
+}
+
+struct TestMatch {
+  // The AST unit from which `result` is built. We bundle it because it backs
+  // the result. Users are not expected to access it.
+  std::unique_ptr AstUnit;
+  // The result to use in the test. References `ast_unit`.
+  MatchResult Result;
+};
+
+// Matches `Matcher` against the statement `StatementCode` and returns the
+// result. Handles putting the statement inside a function and modifying the
+// matcher correspondingly. `Matcher` should match `StatementCode` exactly --
+// that is, produce exactly one match.
+static llvm::Optional matchStmt(llvm::Twine StatementCode,
+   StatementMatcher Matcher) {
+  auto AstUnit = buildASTFromCode(wrapSnippet(StatementCode));
+  if (AstUnit == nullptr) {
+ADD_FAILURE() << "AST construction failed";
+return llvm::None;
+  }
+  ASTContext  = AstUnit->getASTContext();
+  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  // We expect a single, exact match for the statement.
+  if (Matches.size() != 1) {
+ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
+return llvm::None;
+  }
+  return TestMatch{std::move(AstUnit), MatchResult(Matches[0], )};
+}
+
+class StencilTest : public ::testing::Test {
+protected:
+  // Verifies that the given stencil fails when evaluated on a valid match
+  // result. Binds a statement to "stmt", a (non-member) ctor-initializer to
+  // "init", an expression to "expr" and a (nameless) declaration to "decl".
+  void testError(const Stencil ,
+ ::testing::Matcher Matcher) {
+const std::string Snippet = R"cc(
+  struct A {};
+  class F : public A {
+   public:
+F(int) {}
+  };
+  F(1);
+)cc";
+auto StmtMatch = matchStmt(
+Snippet,
+stmt(hasDescendant(
+ cxxConstructExpr(
+ hasDeclaration(decl(hasDescendant(cxxCtorInitializer(
+   isBaseInitializer())
+   .bind("init")))
+.bind("decl")))
+ .bind("expr")))
+.bind("stmt"));
+ASSERT_TRUE(StmtMatch);
+if (auto ResultOrErr = 

r358691 - [LibTooling] Add Stencil library for format-string style codegen.

2019-04-18 Thread Yitzhak Mandelbaum via cfe-commits
Author: ymandel
Date: Thu Apr 18 10:23:01 2019
New Revision: 358691

URL: http://llvm.org/viewvc/llvm-project?rev=358691=rev
Log:
[LibTooling] Add Stencil library for format-string style codegen.

Summary:
This file defines the *Stencil* abstraction: a code-generating object, 
parameterized by named references to (bound) AST nodes.  Given a match result, 
a stencil can be evaluated to a string of source code.

A stencil is similar in spirit to a format string: it is composed of a series 
of raw text strings, references to nodes (the parameters) and helper 
code-generation operations.

See thread on cfe-dev list with subject "[RFC] Easier source-to-source 
transformations with clang tooling" for background.

Reviewers: sbenza

Reviewed By: sbenza

Subscribers: ilya-biryukov, mgorny, jfb, jdoerfert, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h
cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp
cfe/trunk/unittests/Tooling/StencilTest.cpp
Modified:
cfe/trunk/lib/Tooling/Refactoring/CMakeLists.txt
cfe/trunk/unittests/Tooling/CMakeLists.txt

Added: cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h?rev=358691=auto
==
--- cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h (added)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h Thu Apr 18 10:23:01 
2019
@@ -0,0 +1,161 @@
+//===--- Stencil.h - Stencil class --*- 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
+//
+//===--===//
+///
+/// /file
+/// This file defines the *Stencil* abstraction: a code-generating object,
+/// parameterized by named references to (bound) AST nodes.  Given a match
+/// result, a stencil can be evaluated to a string of source code.
+///
+/// A stencil is similar in spirit to a format string: it is composed of a
+/// series of raw text strings, references to nodes (the parameters) and helper
+/// code-generation operations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_REFACTOR_STENCIL_H_
+#define LLVM_CLANG_TOOLING_REFACTOR_STENCIL_H_
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+
+namespace clang {
+namespace tooling {
+
+/// A stencil is represented as a sequence of "parts" that can each 
individually
+/// generate a code string based on a match result.  The different kinds of
+/// parts include (raw) text, references to bound nodes and assorted operations
+/// on bound nodes.
+///
+/// Users can create custom Stencil operations by implementing this interface.
+class StencilPartInterface {
+public:
+  virtual ~StencilPartInterface() = default;
+
+  /// Evaluates this part to a string and appends it to \c Result.  \c Result 
is
+  /// undefined in the case of an error.
+  virtual llvm::Error eval(const ast_matchers::MatchFinder::MatchResult ,
+   std::string *Result) const = 0;
+
+  virtual bool isEqual(const StencilPartInterface ) const = 0;
+
+  const void *typeId() const { return TypeId; }
+
+protected:
+  StencilPartInterface(const void *DerivedId) : TypeId(DerivedId) {}
+
+  // Since this is an abstract class, copying/assigning only make sense for
+  // derived classes implementing `clone()`.
+  StencilPartInterface(const StencilPartInterface &) = default;
+  StencilPartInterface =(const StencilPartInterface &) = default;
+
+  /// Unique identifier of the concrete type of this instance.  Supports safe
+  /// downcasting.
+  const void *TypeId;
+};
+
+/// A copyable facade for a std::unique_ptr. Copies 
result
+/// in a copy of the underlying pointee object.
+class StencilPart {
+public:
+  explicit StencilPart(std::shared_ptr Impl)
+  : Impl(std::move(Impl)) {}
+
+  /// See `StencilPartInterface::eval()`.
+  llvm::Error eval(const ast_matchers::MatchFinder::MatchResult ,
+   std::string *Result) const {
+return Impl->eval(Match, Result);
+  }
+
+  bool operator==(const StencilPart ) const {
+if (Impl == Other.Impl)
+  return true;
+if (Impl == nullptr || Other.Impl == nullptr)
+  return false;
+return Impl->isEqual(*Other.Impl);
+  }
+
+private:
+  std::shared_ptr Impl;
+};
+
+/// A sequence of code fragments, references to parameters and code-generation
+/// operations that together can be evaluated to (a fragment of) source code,
+/// given a match result.
+class 

[PATCH] D60568: [OpenMP] Add support for registering requires directives with the runtime

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 195775.
gtbercea added a comment.

- Move error check in sema.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60568

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CodeGenModule.cpp
  test/OpenMP/openmp_offload_registration.cpp
  test/OpenMP/target_codegen.cpp
  test/OpenMP/target_codegen_registration.cpp

Index: test/OpenMP/target_codegen_registration.cpp
===
--- test/OpenMP/target_codegen_registration.cpp
+++ test/OpenMP/target_codegen_registration.cpp
@@ -180,10 +180,11 @@
 // CHECK: [[DESC:@.+]] = internal constant [[DSCTY]] { i32 1, [[DEVTY]]* getelementptr inbounds ([1 x [[DEVTY]]], [1 x [[DEVTY]]]* [[IMAGES]], i32 0, i32 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, comdat($[[REGFN]])
 
 // We have 4 initializers, one for the 500 priority, another one for 501, or more for the default priority, and the last one for the offloading registration function.
-// CHECK: @llvm.global_ctors = appending global [4 x { i32, void ()*, i8* }] [
+// CHECK: @llvm.global_ctors = appending global [5 x { i32, void ()*, i8* }] [
 // CHECK-SAME: { i32, void ()*, i8* } { i32 500, void ()* [[P500:@[^,]+]], i8* null },
 // CHECK-SAME: { i32, void ()*, i8* } { i32 501, void ()* [[P501:@[^,]+]], i8* null },
 // CHECK-SAME: { i32, void ()*, i8* } { i32 65535, void ()* [[PMAX:@[^,]+]], i8* null },
+// CHECK-SAME: { i32, void ()*, i8* } { i32 0, void ()* @.omp_offloading.requires_reg, i8* null },
 // CHECK-SAME: { i32, void ()*, i8* } { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }]
 
 // CHECK-NTARGET: @llvm.global_ctors = appending global [3   x { i32, void ()*, i8* }] [
@@ -387,6 +388,10 @@
 
 // Check registration and unregistration
 
+//CHECK: define internal void @.omp_offloading.requires_reg()
+//CHECK: call void @__tgt_register_requires(i64 1)
+//CHECK: ret void
+
 //CHECK: define internal void @[[UNREGFN:.+]](i8*)
 //CHECK-SAME: comdat($[[REGFN]]) {
 //CHECK: call i32 @__tgt_unregister_lib([[DSCTY]]* [[DESC]])
@@ -432,31 +437,31 @@
 
 // Check metadata is properly generated:
 // CHECK: !omp_offload.info = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID:-?[0-9]+]], i32 [[FILEID:-?[0-9]+]], !"_ZN2SB3fooEv", i32 216, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SDD1Ev", i32 266, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SEC1Ev", i32 282, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SED1Ev", i32 288, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EE3fooEv", i32 299, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EEC1Ev", i32 305, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_Z3bari", i32 427, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EED1Ev", i32 311, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EEC1Ev", i32 305, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EED1Ev", i32 311, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EE3fooEv", i32 299, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SCC1Ev", i32 241, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID:-?[0-9]+]], i32 [[FILEID:-?[0-9]+]], !"_ZN2SB3fooEv", i32 217, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SDD1Ev", i32 267, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SEC1Ev", i32 283, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SED1Ev", i32 289, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EE3fooEv", i32 300, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EEC1Ev", i32 306, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_Z3bari", i32 432, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EED1Ev", i32 312, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EEC1Ev", i32 306, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EED1Ev", i32 312, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EE3fooEv", i32 300, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SCC1Ev", i32 242, i32 

[PATCH] D60873: [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

2019-04-18 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.

Well done!
I never managed to track this one down, this was really annoying.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60873



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


[PATCH] D60558: [clang-format] Fix indent of trailing raw string param after newline

2019-04-18 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC358689: [clang-format] Fix indent of trailing raw string 
param after newline (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60558?vs=194654=195772#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60558

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  unittests/Format/FormatTestRawStrings.cpp

Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -111,12 +111,12 @@
   unsigned reformatRawStringLiteral(const FormatToken ,
 LineState ,
 const FormatStyle ,
-bool DryRun);
+bool DryRun, bool Newline);
 
   /// If the current token is at the end of the current line, handle
   /// the transition to the next line.
   unsigned handleEndOfLine(const FormatToken , LineState ,
-   bool DryRun, bool AllowBreak);
+   bool DryRun, bool AllowBreak, bool Newline);
 
   /// If \p Current is a raw string that is configured to be reformatted,
   /// return the style to be used.
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1196,7 +1196,8 @@
   State.Column += Current.ColumnWidth;
   State.NextToken = State.NextToken->Next;
 
-  unsigned Penalty = handleEndOfLine(Current, State, DryRun, AllowBreak);
+  unsigned Penalty =
+  handleEndOfLine(Current, State, DryRun, AllowBreak, Newline);
 
   if (Current.Role)
 Current.Role->formatFromToken(State, this, DryRun);
@@ -1490,7 +1491,7 @@
 
 unsigned ContinuationIndenter::reformatRawStringLiteral(
 const FormatToken , LineState ,
-const FormatStyle , bool DryRun) {
+const FormatStyle , bool DryRun, bool Newline) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText);
   StringRef NewDelimiter =
@@ -1530,8 +1531,10 @@
   // source.
   bool ContentStartsOnNewline = Current.TokenText[OldPrefixSize] == '\n';
   // If this token is the last parameter (checked by looking if it's followed by
-  // `)`, the base the indent off the line's nested block indent. Otherwise,
-  // base the indent off the arguments indent, so we can achieve:
+  // `)` and is not on a newline, the base the indent off the line's nested
+  // block indent. Otherwise, base the indent off the arguments indent, so we
+  // can achieve:
+  //
   // fff(1, 2, 3, R"pb(
   // key1: 1  #
   // key2: 2)pb");
@@ -1540,11 +1543,18 @@
   // R"pb(
   //   key1: 1  #
   //   key2: 2
+  // )pb");
+  //
+  // fff(1, 2, 3,
+  // R"pb(
+  //   key1: 1  #
+  //   key2: 2
   // )pb",
   // 5);
-  unsigned CurrentIndent = (Current.Next && Current.Next->is(tok::r_paren))
-   ? State.Stack.back().NestedBlockIndent
-   : State.Stack.back().Indent;
+  unsigned CurrentIndent =
+  (!Newline && Current.Next && Current.Next->is(tok::r_paren))
+  ? State.Stack.back().NestedBlockIndent
+  : State.Stack.back().Indent;
   unsigned NextStartColumn = ContentStartsOnNewline
  ? CurrentIndent + Style.IndentWidth
  : FirstStartColumn;
@@ -1646,13 +1656,14 @@
 
 unsigned ContinuationIndenter::handleEndOfLine(const FormatToken ,
LineState , bool DryRun,
-   bool AllowBreak) {
+   bool AllowBreak, bool Newline) {
   unsigned Penalty = 0;
   // Compute the raw string style to use in case this is a raw string literal
   // that can be reformatted.
   auto RawStringStyle = getRawStringStyle(Current, State);
   if (RawStringStyle && !Current.Finalized) {
-Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, DryRun);
+Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, DryRun,
+   Newline);
   } else if (Current.IsMultiline && Current.isNot(TT_BlockComment)) {
 // Don't break multi-line tokens other than block comments and raw string
 // literals. Instead, just update the state.
Index: unittests/Format/FormatTestRawStrings.cpp
===
--- unittests/Format/FormatTestRawStrings.cpp
+++ 

r358689 - [clang-format] Fix indent of trailing raw string param after newline

2019-04-18 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Apr 18 10:14:05 2019
New Revision: 358689

URL: http://llvm.org/viewvc/llvm-project?rev=358689=rev
Log:
[clang-format] Fix indent of trailing raw string param after newline

Summary:
Currently clang-format uses ContinuationIndent to indent the contents of a raw
string literal that is the last parameter of the function call. This is to
achieve formatting similar to trailing:
```
f(1, 2, R"pb(
x: y)pb");
```
However this had the unfortunate consequence of producing format like this:
```
fff(1, 2,
R"pb(
a: b
)pb");
```

This patch makes clang-format consider indenting a trailing raw string param
after a newline based off the start of the format delimiter, producing:
```
fff(1, 2,
R"pb(
  a: b
)pb");
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/ContinuationIndenter.h
cfe/trunk/unittests/Format/FormatTestRawStrings.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=358689=358688=358689=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Apr 18 10:14:05 2019
@@ -1196,7 +1196,8 @@ unsigned ContinuationIndenter::moveState
   State.Column += Current.ColumnWidth;
   State.NextToken = State.NextToken->Next;
 
-  unsigned Penalty = handleEndOfLine(Current, State, DryRun, AllowBreak);
+  unsigned Penalty =
+  handleEndOfLine(Current, State, DryRun, AllowBreak, Newline);
 
   if (Current.Role)
 Current.Role->formatFromToken(State, this, DryRun);
@@ -1490,7 +1491,7 @@ static unsigned getLastLineEndColumn(Str
 
 unsigned ContinuationIndenter::reformatRawStringLiteral(
 const FormatToken , LineState ,
-const FormatStyle , bool DryRun) {
+const FormatStyle , bool DryRun, bool Newline) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText);
   StringRef NewDelimiter =
@@ -1530,8 +1531,10 @@ unsigned ContinuationIndenter::reformatR
   // source.
   bool ContentStartsOnNewline = Current.TokenText[OldPrefixSize] == '\n';
   // If this token is the last parameter (checked by looking if it's followed 
by
-  // `)`, the base the indent off the line's nested block indent. Otherwise,
-  // base the indent off the arguments indent, so we can achieve:
+  // `)` and is not on a newline, the base the indent off the line's nested
+  // block indent. Otherwise, base the indent off the arguments indent, so we
+  // can achieve:
+  //
   // fff(1, 2, 3, R"pb(
   // key1: 1  #
   // key2: 2)pb");
@@ -1540,11 +1543,18 @@ unsigned ContinuationIndenter::reformatR
   // R"pb(
   //   key1: 1  #
   //   key2: 2
+  // )pb");
+  //
+  // fff(1, 2, 3,
+  // R"pb(
+  //   key1: 1  #
+  //   key2: 2
   // )pb",
   // 5);
-  unsigned CurrentIndent = (Current.Next && Current.Next->is(tok::r_paren))
-   ? State.Stack.back().NestedBlockIndent
-   : State.Stack.back().Indent;
+  unsigned CurrentIndent =
+  (!Newline && Current.Next && Current.Next->is(tok::r_paren))
+  ? State.Stack.back().NestedBlockIndent
+  : State.Stack.back().Indent;
   unsigned NextStartColumn = ContentStartsOnNewline
  ? CurrentIndent + Style.IndentWidth
  : FirstStartColumn;
@@ -1646,13 +1656,14 @@ unsigned ContinuationIndenter::addMultil
 
 unsigned ContinuationIndenter::handleEndOfLine(const FormatToken ,
LineState , bool DryRun,
-   bool AllowBreak) {
+   bool AllowBreak, bool Newline) {
   unsigned Penalty = 0;
   // Compute the raw string style to use in case this is a raw string literal
   // that can be reformatted.
   auto RawStringStyle = getRawStringStyle(Current, State);
   if (RawStringStyle && !Current.Finalized) {
-Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, 
DryRun);
+Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, DryRun,
+   Newline);
   } else if (Current.IsMultiline && Current.isNot(TT_BlockComment)) {
 // Don't break multi-line tokens other than block comments and raw string
 // literals. Instead, just update the state.

Modified: cfe/trunk/lib/Format/ContinuationIndenter.h
URL: 

[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:9136
+def err_omp_target_before_requires : Error <
+  "Target region encountered before requires directive with '%0' clause">;
+def note_omp_requires_encountered_target : Note <

The messages must start from lower letter. Other messages must be fixed too in 
separate patches.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60875



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


[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 195771.
gtbercea added a comment.

- Fix.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60875

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/requires_messages.cpp
  test/OpenMP/requires_target_messages.cpp

Index: test/OpenMP/requires_target_messages.cpp
===
--- /dev/null
+++ test/OpenMP/requires_target_messages.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100  %s
+
+void foo2() {
+  int a;
+  #pragma omp target // expected-note 4 {{Target previously encountered here}}
+  {
+a = a + 1;
+  }
+}
+
+#pragma omp requires atomic_default_mem_order(seq_cst)
+#pragma omp requires unified_address //expected-error {{Target region encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{Target region encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{Target region encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{Target region encountered before requires directive with 'dynamic_allocators' clause}}
Index: test/OpenMP/requires_messages.cpp
===
--- test/OpenMP/requires_messages.cpp
+++ test/OpenMP/requires_messages.cpp
@@ -7,7 +7,7 @@
 
 #pragma omp requires unified_shared_memory, unified_shared_memory // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_shared_memory' clause}}
 
-#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires unified_address, unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_address' clause}}
 
@@ -29,13 +29,13 @@
 
 #pragma omp requires atomic_default_mem_order( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
-#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} 
+#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
 #pragma omp requires atomic_default_mem_order(shared) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires // expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
Index: lib/Sema/SemaOpenMP.cpp
===
--- 

[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 195770.
gtbercea marked an inline comment as done.
gtbercea added a comment.

- Fix.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60875

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/requires_messages.cpp
  test/OpenMP/requires_target_messages.cpp

Index: test/OpenMP/requires_target_messages.cpp
===
--- /dev/null
+++ test/OpenMP/requires_target_messages.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100  %s
+
+void foo2() {
+  int a;
+  #pragma omp target // expected-note {{Target previously encountered here}} expected-note {{Target previously encountered here}} expected-note {{Target previously encountered here}} expected-note {{Target previously encountered here}}
+  {
+a = a + 1;
+  }
+}
+
+#pragma omp requires atomic_default_mem_order(seq_cst)
+#pragma omp requires unified_address //expected-error {{Target region encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{Target region encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{Target region encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{Target region encountered before requires directive with 'dynamic_allocators' clause}}
Index: test/OpenMP/requires_messages.cpp
===
--- test/OpenMP/requires_messages.cpp
+++ test/OpenMP/requires_messages.cpp
@@ -7,7 +7,7 @@
 
 #pragma omp requires unified_shared_memory, unified_shared_memory // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_shared_memory' clause}}
 
-#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires unified_address, unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_address' clause}}
 
@@ -29,13 +29,13 @@
 
 #pragma omp requires atomic_default_mem_order( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
-#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} 
+#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
 #pragma omp requires atomic_default_mem_order(shared) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires // 

[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/Sema/SemaOpenMP.cpp:4207
+DSAStack->hasRequiresDeclWithClause()) &&
+  !CurContext->isDependentContext()) {
+// Register target to DSA Stack.

ABataev wrote:
> Better to check for the dependent context at first, only after that check for 
> the clause
Better to check for the dependent context at first, only after that check for 
the clause



Comment at: test/OpenMP/requires_target_messages.cpp:5
+  int a;
+  #pragma omp target // expected-note {{Target previously encountered here}} 
expected-note {{Target previously encountered here}} expected-note {{Target 
previously encountered here}} expected-note {{Target previously encountered 
here}}
+  {

Just `expected-note 4 {{`


Repository:
  rC Clang

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

https://reviews.llvm.org/D60875



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


[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 195768.
gtbercea marked an inline comment as done.
gtbercea added a comment.

- Fix test.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60875

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/requires_messages.cpp
  test/OpenMP/requires_target_messages.cpp

Index: test/OpenMP/requires_target_messages.cpp
===
--- /dev/null
+++ test/OpenMP/requires_target_messages.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100  %s
+
+void foo2() {
+  int a;
+  #pragma omp target // expected-note {{Target previously encountered here}} expected-note {{Target previously encountered here}} expected-note {{Target previously encountered here}} expected-note {{Target previously encountered here}}
+  {
+a = a + 1;
+  }
+}
+
+#pragma omp requires atomic_default_mem_order(seq_cst)
+#pragma omp requires unified_address //expected-error {{Target region encountered before requires directive with 'unified_address' clause}}
+#pragma omp requires unified_shared_memory //expected-error {{Target region encountered before requires directive with 'unified_shared_memory' clause}}
+#pragma omp requires reverse_offload //expected-error {{Target region encountered before requires directive with 'reverse_offload' clause}}
+#pragma omp requires dynamic_allocators //expected-error {{Target region encountered before requires directive with 'dynamic_allocators' clause}}
Index: test/OpenMP/requires_messages.cpp
===
--- test/OpenMP/requires_messages.cpp
+++ test/OpenMP/requires_messages.cpp
@@ -7,7 +7,7 @@
 
 #pragma omp requires unified_shared_memory, unified_shared_memory // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_shared_memory' clause}}
 
-#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires unified_address, unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_address' clause}}
 
@@ -29,13 +29,13 @@
 
 #pragma omp requires atomic_default_mem_order( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
-#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} 
+#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
 #pragma omp requires atomic_default_mem_order(shared) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires // 

[PATCH] D60853: clang-format converts a keyword macro definition to a macro function

2019-04-18 Thread Owen Pan via Phabricator via cfe-commits
owenpan marked 2 inline comments as done.
owenpan added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:808
 
-  if (FormatTok->Tok.getKind() != tok::identifier) {
+  if (!FormatTok->Tok.getIdentifierInfo()) {
 IncludeGuard = IG_Rejected;

MyDeveloperDay wrote:
> Is this equivalent to saying something that means `FormatTok->isKeyWord()` ? 
> for those case where the #define 
The condition tests if `FormatTok` is neither a keyword (`true`, `false`, etc.) 
nor a non-keyword identifier.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60853



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


[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 195762.
gtbercea added a comment.

  Fix test,


Repository:
  rC Clang

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

https://reviews.llvm.org/D60875

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/requires_messages.cpp
  test/OpenMP/requires_target_messages.cpp

Index: test/OpenMP/requires_target_messages.cpp
===
--- /dev/null
+++ test/OpenMP/requires_target_messages.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100  %s
+
+void foo2() {
+  int a;
+  #pragma omp target // expected-note {{Target previously encountered here}}
+  {
+a = a + 1;
+  }
+}
+
+#pragma omp requires atomic_default_mem_order(seq_cst)
+#pragma omp requires unified_shared_memory //expected-error {{Target region encountered before requires directive with unified_shared_memory clause}}
Index: test/OpenMP/requires_messages.cpp
===
--- test/OpenMP/requires_messages.cpp
+++ test/OpenMP/requires_messages.cpp
@@ -7,7 +7,7 @@
 
 #pragma omp requires unified_shared_memory, unified_shared_memory // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_shared_memory' clause}}
 
-#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires unified_address, unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_address' clause}}
 
@@ -29,13 +29,13 @@
 
 #pragma omp requires atomic_default_mem_order( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
-#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} 
+#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
 #pragma omp requires atomic_default_mem_order(shared) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires // expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -193,6 +193,8 @@
   /// Expression for the predefined allocators.
   Expr *OMPPredefinedAllocators[OMPAllocateDeclAttr::OMPUserDefinedMemAlloc] = {
   nullptr};
+  /// Vector of previously encountered target directives
+  SmallVector TargetLocations;
 
 public:
   explicit DSAStackTy(Sema ) : SemaRef(S) {}
@@ -454,6 +456,16 @@
 return IsDuplicate;
   }
 
+  /// Add location of 

[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:9136
+def err_omp_target_before_requires : Error <
+  "Target region encountered before requires directive with %0 clause">;
+def note_omp_requires_encountered_target : Note <

Enclose `%0` in single quotes for better reading



Comment at: lib/Sema/SemaOpenMP.cpp:2440
+// Check if any of the requires clauses affect target regions.
+if (!TargetLocations.empty() &&
+(isa(CNew) ||

Better to check for `TargetLocations.empty()` before the loop



Comment at: lib/Sema/SemaOpenMP.cpp:4207
+DSAStack->hasRequiresDeclWithClause()) &&
+  !CurContext->isDependentContext()) {
+// Register target to DSA Stack.

Better to check for the dependent context at first, only after that check for 
the clause



Comment at: test/OpenMP/requires_target_messages.cpp:11
+
+#pragma omp requires unified_shared_memory //expected-error {{Target region 
encountered before requires directive with unified_shared_memory clause}}

Add the checks for all the clauses that may cause this error


Repository:
  rC Clang

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

https://reviews.llvm.org/D60875



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


[PATCH] D60875: [OpenMP] Add checks for requires and target directives.

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea created this revision.
gtbercea added reviewers: ABataev, AlexEichenberger, caomhin.
Herald added subscribers: cfe-commits, jdoerfert, jfb, guansong.
Herald added a project: clang.

The requires directive containing target related clauses must appear before any 
target region in the compilation unit.


Repository:
  rC Clang

https://reviews.llvm.org/D60875

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/requires_messages.cpp
  test/OpenMP/requires_target_messages.cpp

Index: test/OpenMP/requires_target_messages.cpp
===
--- /dev/null
+++ test/OpenMP/requires_target_messages.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100  %s
+
+void foo2() {
+  int a;
+  #pragma omp target // expected-note {{Target previously encountered here}}
+  {
+a = a + 1;
+  }
+}
+
+#pragma omp requires unified_shared_memory //expected-error {{Target region encountered before requires directive with unified_shared_memory clause}}
Index: test/OpenMP/requires_messages.cpp
===
--- test/OpenMP/requires_messages.cpp
+++ test/OpenMP/requires_messages.cpp
@@ -7,7 +7,7 @@
 
 #pragma omp requires unified_shared_memory, unified_shared_memory // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_shared_memory' clause}}
 
-#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires unified_address, unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'unified_address' clause}}
 
@@ -29,13 +29,13 @@
 
 #pragma omp requires atomic_default_mem_order( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(seq_cst // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
-#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} 
+#pragma omp requires atomic_default_mem_order(invalid_modifier) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
 #pragma omp requires atomic_default_mem_order(shared) // expected-error {{expected 'seq_cst', 'acq_rel' or 'relaxed' in OpenMP clause 'atomic_default_mem_order'}} expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
-#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}} 
+#pragma omp requires atomic_default_mem_order(acq_rel), atomic_default_mem_order(relaxed) // expected-error {{directive '#pragma omp requires' cannot contain more than one 'atomic_default_mem_order' claus}} expected-error {{Only one atomic_default_mem_order clause can appear on a requires directive in a single translation unit}}
 
 #pragma omp requires // expected-error {{expected at least one clause on '#pragma omp requires' directive}}
 
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -193,6 +193,8 @@
   /// Expression for the predefined allocators.
   Expr *OMPPredefinedAllocators[OMPAllocateDeclAttr::OMPUserDefinedMemAlloc] = {
   nullptr};
+  /// Vector of previously encountered target directives
+  SmallVector TargetLocations;
 
 public:
   explicit 

r358679 - [Sema][NFC] Mark DR1563 as done (List-initialization and overloaded function disambiguation)

2019-04-18 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Thu Apr 18 08:45:08 2019
New Revision: 358679

URL: http://llvm.org/viewvc/llvm-project?rev=358679=rev
Log:
[Sema][NFC] Mark DR1563 as done (List-initialization and overloaded function 
disambiguation)

It has been supported since at least clang 3.1 so just mark it as done.


Modified:
cfe/trunk/test/CXX/drs/dr15xx.cpp

Modified: cfe/trunk/test/CXX/drs/dr15xx.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr15xx.cpp?rev=358679=358678=358679=diff
==
--- cfe/trunk/test/CXX/drs/dr15xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr15xx.cpp Thu Apr 18 08:45:08 2019
@@ -236,6 +236,16 @@ namespace dr1560 { // dr1560: 3.5
   const X  = true ? get() : throw 0;
 }
 
+namespace dr1563 { // dr1563: yes
+#if __cplusplus >= 201103L
+  double bar(double) { return 0.0; }
+  float bar(float) { return 0.0f; }
+
+  using fun = double(double);
+  fun {bar}; // ok
+#endif
+}
+
 namespace dr1573 { // dr1573: 3.9
 #if __cplusplus >= 201103L
   // ellipsis is inherited (p0136r1 supersedes this part).


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


r358678 - [Sema][NFC] Mark DR705 (Suppressing argument-dependent lookup via parentheses) as done

2019-04-18 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Thu Apr 18 08:34:03 2019
New Revision: 358678

URL: http://llvm.org/viewvc/llvm-project?rev=358678=rev
Log:
[Sema][NFC] Mark DR705 (Suppressing argument-dependent lookup via parentheses) 
as done

It was supported since at least clang 3 so just mark it as done.


Modified:
cfe/trunk/test/CXX/drs/dr7xx.cpp

Modified: cfe/trunk/test/CXX/drs/dr7xx.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr7xx.cpp?rev=358678=358677=358678=diff
==
--- cfe/trunk/test/CXX/drs/dr7xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr7xx.cpp Thu Apr 18 08:34:03 2019
@@ -3,6 +3,19 @@
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 
+namespace dr705 { // dr705: yes
+  namespace N {
+struct S {};
+void f(S); // expected-note {{declared here}}
+  }
+
+  void g() {
+N::S s;
+f(s);  // ok
+(f)(s);// expected-error {{use of undeclared}}
+  }
+}
+
 namespace dr727 { // dr727: partial
   struct A {
 template struct C; // expected-note 6{{here}}


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


[PATCH] D60873: [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

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

Include insertion in clangd was inserting absolute paths when the
include directory was an absolute path with a double dot. This patch makes sure
double dots are handled both with absolute and relative paths.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60873

Files:
  clang-tools-extra/unittests/clangd/HeadersTests.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/unittests/Lex/HeaderSearchTest.cpp


Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -91,5 +91,12 @@
 "z");
 }
 
+TEST_F(HeaderSearchTest, DotDotsWithAbsPath) {
+  addSearchDir("/x/../y/");
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z",
+   /*WorkingDir=*/""),
+"z");
+}
+
 } // namespace
 } // namespace clang
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1685,11 +1685,10 @@
 
 StringRef Dir = SearchDirs[I].getDir()->getName();
 llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
-if (!WorkingDir.empty() && !path::is_absolute(Dir)) {
+if (!WorkingDir.empty() && !path::is_absolute(Dir))
   fs::make_absolute(WorkingDir, DirPath);
-  path::remove_dots(DirPath, /*remove_dot_dot=*/true);
-  Dir = DirPath;
-}
+path::remove_dots(DirPath, /*remove_dot_dot=*/true);
+Dir = DirPath;
 for (auto NI = path::begin(File), NE = path::end(File),
   DI = path::begin(Dir), DE = path::end(Dir);
  /*termination condition in loop*/; ++NI, ++DI) {
Index: clang-tools-extra/unittests/clangd/HeadersTests.cpp
===
--- clang-tools-extra/unittests/clangd/HeadersTests.cpp
+++ clang-tools-extra/unittests/clangd/HeadersTests.cpp
@@ -213,6 +213,11 @@
 TEST_F(HeadersTest, ShortenedInclude) {
   std::string BarHeader = testPath("sub/bar.h");
   EXPECT_EQ(calculate(BarHeader), "\"bar.h\"");
+
+  SearchDirArg = (llvm::Twine("-I") + Subdir + "/..").str();
+  CDB.ExtraClangFlags = {SearchDirArg.c_str()};
+  BarHeader = testPath("sub/bar.h");
+  EXPECT_EQ(calculate(BarHeader), "\"sub/bar.h\"");
 }
 
 TEST_F(HeadersTest, NotShortenedInclude) {


Index: clang/unittests/Lex/HeaderSearchTest.cpp
===
--- clang/unittests/Lex/HeaderSearchTest.cpp
+++ clang/unittests/Lex/HeaderSearchTest.cpp
@@ -91,5 +91,12 @@
 "z");
 }
 
+TEST_F(HeaderSearchTest, DotDotsWithAbsPath) {
+  addSearchDir("/x/../y/");
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z",
+   /*WorkingDir=*/""),
+"z");
+}
+
 } // namespace
 } // namespace clang
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1685,11 +1685,10 @@
 
 StringRef Dir = SearchDirs[I].getDir()->getName();
 llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
-if (!WorkingDir.empty() && !path::is_absolute(Dir)) {
+if (!WorkingDir.empty() && !path::is_absolute(Dir))
   fs::make_absolute(WorkingDir, DirPath);
-  path::remove_dots(DirPath, /*remove_dot_dot=*/true);
-  Dir = DirPath;
-}
+path::remove_dots(DirPath, /*remove_dot_dot=*/true);
+Dir = DirPath;
 for (auto NI = path::begin(File), NE = path::end(File),
   DI = path::begin(Dir), DE = path::end(Dir);
  /*termination condition in loop*/; ++NI, ++DI) {
Index: clang-tools-extra/unittests/clangd/HeadersTests.cpp
===
--- clang-tools-extra/unittests/clangd/HeadersTests.cpp
+++ clang-tools-extra/unittests/clangd/HeadersTests.cpp
@@ -213,6 +213,11 @@
 TEST_F(HeadersTest, ShortenedInclude) {
   std::string BarHeader = testPath("sub/bar.h");
   EXPECT_EQ(calculate(BarHeader), "\"bar.h\"");
+
+  SearchDirArg = (llvm::Twine("-I") + Subdir + "/..").str();
+  CDB.ExtraClangFlags = {SearchDirArg.c_str()};
+  BarHeader = testPath("sub/bar.h");
+  EXPECT_EQ(calculate(BarHeader), "\"sub/bar.h\"");
 }
 
 TEST_F(HeadersTest, NotShortenedInclude) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r358676 - [analyzer][NFC] Use capital variable names, move methods out-of-line, rename some in CheckerRegistry

2019-04-18 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Thu Apr 18 08:19:16 2019
New Revision: 358676

URL: http://llvm.org/viewvc/llvm-project?rev=358676=rev
Log:
[analyzer][NFC] Use capital variable names, move methods out-of-line, rename 
some in CheckerRegistry

There are barely any lines I haven't changed in these files, so I think I could
might as well leave it in an LLVM coding style conforming state. I also renamed
2 functions and moved addDependency out of line to ease on followup patches.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h?rev=358676=358675=358676=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h Thu Apr 
18 08:19:16 2019
@@ -164,40 +164,23 @@ public:
 
   /// Makes the checker with the full name \p fullName depends on the checker
   /// called \p dependency.
-  void addDependency(StringRef fullName, StringRef dependency) {
-auto CheckerThatNeedsDeps =
-   [](const CheckerInfo ) { return Chk.FullName == fullName; 
};
-auto Dependency =
-  [](const CheckerInfo ) {
-return Chk.FullName == dependency;
-  };
-
-auto CheckerIt = llvm::find_if(Checkers, CheckerThatNeedsDeps);
-assert(CheckerIt != Checkers.end() &&
-   "Failed to find the checker while attempting to set up it's "
-   "dependencies!");
-
-auto DependencyIt = llvm::find_if(Checkers, Dependency);
-assert(DependencyIt != Checkers.end() &&
-   "Failed to find the dependency of a checker!");
-
-CheckerIt->Dependencies.push_back(&*DependencyIt);
-  }
+  void addDependency(StringRef FullName, StringRef Dependency);
 
   // FIXME: This *really* should be added to the frontend flag descriptions.
   /// Initializes a CheckerManager by calling the initialization functions for
   /// all checkers specified by the given CheckerOptInfo list. The order of 
this
   /// list is significant; later options can be used to reverse earlier ones.
   /// This can be used to exclude certain checkers in an included package.
-  void initializeManager(CheckerManager ) const;
+  void initializeManager(CheckerManager ) const;
 
   /// Check if every option corresponds to a specific checker or package.
   void validateCheckerOptions() const;
 
   /// Prints the name and description of all checkers in this registry.
   /// This output is not intended to be machine-parseable.
-  void printHelp(raw_ostream , size_t maxNameChars = 30) const;
-  void printList(raw_ostream ) const;
+  void printCheckerWithDescList(raw_ostream ,
+size_t MaxNameChars = 30) const;
+  void printEnabledCheckerList(raw_ostream ) const;
 
 private:
   /// Collect all enabled checkers. The returned container preserves the order
@@ -211,7 +194,7 @@ private:
   CheckerInfoListRange getMutableCheckersForCmdLineArg(StringRef CmdLineArg);
 
   CheckerInfoList Checkers;
-  llvm::StringMap Packages;
+  llvm::StringMap PackageSizes;
 
   DiagnosticsEngine 
   AnalyzerOptions 

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp?rev=358676=358675=358676=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp Thu Apr 18 
08:19:16 2019
@@ -50,7 +50,8 @@ void ento::printCheckerHelp(raw_ostream
   out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n";
   out << "USAGE: -analyzer-checker \n\n";
 
-  CheckerRegistry(plugins, diags, anopts, langOpts).printHelp(out);
+  CheckerRegistry(plugins, diags, anopts, langOpts)
+  .printCheckerWithDescList(out);
 }
 
 void ento::printEnabledCheckerList(raw_ostream ,
@@ -60,7 +61,8 @@ void ento::printEnabledCheckerList(raw_o
const LangOptions ) {
   out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n";
 
-  CheckerRegistry(plugins, diags, anopts, langOpts).printList(out);
+  CheckerRegistry(plugins, diags, anopts, langOpts)
+  .printEnabledCheckerList(out);
 }
 
 void ento::printAnalyzerConfigList(raw_ostream ) {

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp?rev=358676=358675=358676=diff

[PATCH] D59457: [analyzer][NFC] Use capital variable names, move methods out-of-line, rename some in CheckerRegistry

2019-04-18 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358676: [analyzer][NFC] Use capital variable names, move 
methods out-of-line, rename… (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59457?vs=190970=195747#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59457

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
  cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
  cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp

Index: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -164,40 +164,23 @@
 
   /// Makes the checker with the full name \p fullName depends on the checker
   /// called \p dependency.
-  void addDependency(StringRef fullName, StringRef dependency) {
-auto CheckerThatNeedsDeps =
-   [](const CheckerInfo ) { return Chk.FullName == fullName; };
-auto Dependency =
-  [](const CheckerInfo ) {
-return Chk.FullName == dependency;
-  };
-
-auto CheckerIt = llvm::find_if(Checkers, CheckerThatNeedsDeps);
-assert(CheckerIt != Checkers.end() &&
-   "Failed to find the checker while attempting to set up it's "
-   "dependencies!");
-
-auto DependencyIt = llvm::find_if(Checkers, Dependency);
-assert(DependencyIt != Checkers.end() &&
-   "Failed to find the dependency of a checker!");
-
-CheckerIt->Dependencies.push_back(&*DependencyIt);
-  }
+  void addDependency(StringRef FullName, StringRef Dependency);
 
   // FIXME: This *really* should be added to the frontend flag descriptions.
   /// Initializes a CheckerManager by calling the initialization functions for
   /// all checkers specified by the given CheckerOptInfo list. The order of this
   /// list is significant; later options can be used to reverse earlier ones.
   /// This can be used to exclude certain checkers in an included package.
-  void initializeManager(CheckerManager ) const;
+  void initializeManager(CheckerManager ) const;
 
   /// Check if every option corresponds to a specific checker or package.
   void validateCheckerOptions() const;
 
   /// Prints the name and description of all checkers in this registry.
   /// This output is not intended to be machine-parseable.
-  void printHelp(raw_ostream , size_t maxNameChars = 30) const;
-  void printList(raw_ostream ) const;
+  void printCheckerWithDescList(raw_ostream ,
+size_t MaxNameChars = 30) const;
+  void printEnabledCheckerList(raw_ostream ) const;
 
 private:
   /// Collect all enabled checkers. The returned container preserves the order
@@ -211,7 +194,7 @@
   CheckerInfoListRange getMutableCheckersForCmdLineArg(StringRef CmdLineArg);
 
   CheckerInfoList Checkers;
-  llvm::StringMap Packages;
+  llvm::StringMap PackageSizes;
 
   DiagnosticsEngine 
   AnalyzerOptions 
Index: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -28,35 +28,41 @@
 
 using RegisterCheckersFn = void (*)(CheckerRegistry &);
 
-static bool isCompatibleAPIVersion(const char *versionString) {
-  // If the version string is null, it's not an analyzer plugin.
-  if (!versionString)
+static bool isCompatibleAPIVersion(const char *VersionString) {
+  // If the version string is null, its not an analyzer plugin.
+  if (!VersionString)
 return false;
 
   // For now, none of the static analyzer API is considered stable.
   // Versions must match exactly.
-  return strcmp(versionString, CLANG_ANALYZER_API_VERSION_STRING) == 0;
+  return strcmp(VersionString, CLANG_ANALYZER_API_VERSION_STRING) == 0;
 }
 
-static bool checkerNameLT(const CheckerRegistry::CheckerInfo ,
-  const CheckerRegistry::CheckerInfo ) {
-  return a.FullName < b.FullName;
-}
+namespace {
+template 
+struct FullNameLT {
+  bool operator()(const T , const T ) {
+return Lhs.FullName < Rhs.FullName;
+  }
+};
+
+using CheckerNameLT = FullNameLT;
+} // end of anonymous namespace
 
 static constexpr char PackageSeparator = '.';
 
-static bool isInPackage(const CheckerRegistry::CheckerInfo ,
-StringRef packageName) {
+static bool isInPackage(const CheckerRegistry::CheckerInfo ,
+StringRef PackageName) {
   // Does the checker's full name have the package as a prefix?
-  if (!checker.FullName.startswith(packageName))
+  if (!Checker.FullName.startswith(PackageName))
 return 

[PATCH] D60267: [clangd] Support relatedInformation in diagnostics.

2019-04-18 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358675: [clangd] Support relatedInformation in diagnostics. 
(authored by sammccall, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60267

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/Diagnostics.cpp
  clang-tools-extra/trunk/clangd/Diagnostics.h
  clang-tools-extra/trunk/clangd/Protocol.cpp
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/test/clangd/diagnostics-notes.test
  clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp

Index: clang-tools-extra/trunk/test/clangd/diagnostics-notes.test
===
--- clang-tools-extra/trunk/test/clangd/diagnostics-notes.test
+++ clang-tools-extra/trunk/test/clangd/diagnostics-notes.test
@@ -0,0 +1,48 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"publishDiagnostics":{"relatedInformation":true}}},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.cc","languageId":"cpp","version":1,"text":"int x;\nint x;"}}}
+#  CHECK:  "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "redefinition",
+# CHECK-NEXT:"message": "Redefinition of 'x'",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 5,
+# CHECK-NEXT:"line": 1
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 4,
+# CHECK-NEXT:"line": 1
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"relatedInformation": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"location": {
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 5,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 4,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "uri": "{{.*}}foo.cc"
+# CHECK-NEXT:},
+# CHECK-NEXT:"message": "Previous definition is here"
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
+# CHECK-NEXT:"severity": 1,
+# CHECK-NEXT:"source": "clang"
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
+# CHECK-NEXT:"uri": "file://{{.*}}/foo.cc"
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp
@@ -8,10 +8,14 @@
 
 #include "Annotations.h"
 #include "ClangdUnit.h"
+#include "Diagnostics.h"
+#include "Protocol.h"
 #include "SourceCode.h"
 #include "TestIndex.h"
+#include "TestFS.h"
 #include "TestTU.h"
 #include "index/MemIndex.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "gmock/gmock.h"
@@ -55,8 +59,12 @@
 
 MATCHER_P(EqualToLSPDiag, LSPDiag,
   "LSP diagnostic " + llvm::to_string(LSPDiag)) {
-  return std::tie(arg.range, arg.severity, arg.message) ==
- std::tie(LSPDiag.range, LSPDiag.severity, LSPDiag.message);
+  if (toJSON(arg) != toJSON(LSPDiag)) {
+*result_listener << llvm::formatv("expected:\n{0:2}\ngot\n{1:2}",
+  toJSON(LSPDiag), toJSON(arg)).str();
+return false;
+  }
+  return true;
 }
 
 MATCHER_P(DiagSource, S, "") { return arg.Source == S; }
@@ -248,6 +256,11 @@
 }
 
 TEST(DiagnosticsTest, ToLSP) {
+  URIForFile MainFile =
+  URIForFile::canonicalize(testPath("foo/bar/main.cpp"), "");
+  URIForFile HeaderFile =
+  URIForFile::canonicalize(testPath("foo/bar/header.h"), "");
+
   clangd::Diag D;
   D.ID = clang::diag::err_enum_class_reference;
   D.Name = "enum_class_reference";
@@ -257,6 +270,7 @@
   D.InsideMainFile = true;
   D.Severity = DiagnosticsEngine::Error;
   D.File = "foo/bar/main.cpp";
+  D.AbsFile = MainFile.file();
 
   clangd::Note NoteInMain;
   NoteInMain.Message = "declared somewhere in the main file";
@@ -264,6 +278,8 @@
   NoteInMain.Severity = DiagnosticsEngine::Remark;
   NoteInMain.File = "../foo/bar/main.cpp";
   NoteInMain.InsideMainFile = true;
+  NoteInMain.AbsFile = 

[clang-tools-extra] r358675 - [clangd] Support relatedInformation in diagnostics.

2019-04-18 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Apr 18 08:17:07 2019
New Revision: 358675

URL: http://llvm.org/viewvc/llvm-project?rev=358675=rev
Log:
[clangd] Support relatedInformation in diagnostics.

Summary: We already have the structure internally, we just need to expose it.

Reviewers: ilya-biryukov

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

Tags: #clang

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

Added:
clang-tools-extra/trunk/test/clangd/diagnostics-notes.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/clangd/Diagnostics.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=358675=358674=358675=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Apr 18 08:17:07 2019
@@ -348,6 +348,8 @@ void ClangdLSPServer::onInitialize(const
   CCOpts.EnableSnippets = Params.capabilities.CompletionSnippets;
   DiagOpts.EmbedFixesInDiagnostics = Params.capabilities.DiagnosticFixes;
   DiagOpts.SendDiagnosticCategory = Params.capabilities.DiagnosticCategory;
+  DiagOpts.EmitRelatedLocations =
+  Params.capabilities.DiagnosticRelatedInformation;
   if (Params.capabilities.WorkspaceSymbolKinds)
 SupportedSymbolKinds |= *Params.capabilities.WorkspaceSymbolKinds;
   if (Params.capabilities.CompletionItemKinds)

Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=358675=358674=358675=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Thu Apr 18 08:17:07 2019
@@ -10,6 +10,7 @@
 #include "../clang-tidy/ClangTidyDiagnosticConsumer.h"
 #include "Compiler.h"
 #include "Logger.h"
+#include "Protocol.h"
 #include "SourceCode.h"
 #include "clang/Basic/AllDiagnostics.h"
 #include "clang/Basic/DiagnosticIDs.h"
@@ -175,9 +176,7 @@ std::string capitalize(std::string Messa
 }
 
 /// Returns a message sent to LSP for the main diagnostic in \p D.
-/// The message includes all the notes with their corresponding locations.
-/// However, notes with fix-its are excluded as those usually only contain a
-/// fix-it message and just add noise if included in the message for 
diagnostic.
+/// This message may include notes, if they're not emited in some other way.
 /// Example output:
 ///
 /// no matching function for call to 'foo'
@@ -186,29 +185,34 @@ std::string capitalize(std::string Messa
 ///
 /// dir1/dir2/dir3/../../dir4/header.h:12:23
 /// note: candidate function not viable: requires 3 arguments
-std::string mainMessage(const Diag , bool DisplayFixesCount) {
+std::string mainMessage(const Diag , const ClangdDiagnosticOptions ) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << D.Message;
-  if (DisplayFixesCount && !D.Fixes.empty())
+  if (Opts.DisplayFixesCount && !D.Fixes.empty())
 OS << " (" << (D.Fixes.size() > 1 ? "fixes" : "fix") << " available)";
-  for (auto  : D.Notes) {
-OS << "\n\n";
-printDiag(OS, Note);
-  }
+  // If notes aren't emitted as structured info, add them to the message.
+  if (!Opts.EmitRelatedLocations)
+for (auto  : D.Notes) {
+  OS << "\n\n";
+  printDiag(OS, Note);
+}
   OS.flush();
   return capitalize(std::move(Result));
 }
 
 /// Returns a message sent to LSP for the note of the main diagnostic.
-/// The message includes the main diagnostic to provide the necessary context
-/// for the user to understand the note.
-std::string noteMessage(const Diag , const DiagBase ) {
+std::string noteMessage(const Diag , const DiagBase ,
+const ClangdDiagnosticOptions ) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << Note.Message;
-  OS << "\n\n";
-  printDiag(OS, Main);
+  // If the client doesn't support structured links between the note and the
+  // original diagnostic, then emit the main diagnostic to give context.
+  if (!Opts.EmitRelatedLocations) {
+OS << "\n\n";
+printDiag(OS, Main);
+  }
   OS.flush();
   return capitalize(std::move(Result));
 }
@@ -275,39 +279,54 @@ void toLSPDiags(
 return Res;
   };
 
-  {
-clangd::Diagnostic Main = FillBasicFields(D);
-Main.message = mainMessage(D, Opts.DisplayFixesCount);
-if (!D.Name.empty())
-  Main.code = D.Name;
-switch (D.Source) {
-case Diag::Clang:
-  Main.source = "clang";
-  break;
-case Diag::ClangTidy:
- 

[PATCH] D60835: [Serialization] Stable serialization order for OpenCLTypeExtMap and OpenCLDeclExtMap

2019-04-18 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358674: [Serialization] Stable serialization order for 
OpenCLTypeExtMap and… (authored by brunoricci, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60835?vs=195627=195744#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60835

Files:
  cfe/trunk/lib/Serialization/ASTWriter.cpp


Index: cfe/trunk/lib/Serialization/ASTWriter.cpp
===
--- cfe/trunk/lib/Serialization/ASTWriter.cpp
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp
@@ -4278,14 +4278,32 @@
   if (!SemaRef.Context.getLangOpts().OpenCL)
 return;
 
+  // Sort the elements of the map OpenCLTypeExtMap by TypeIDs,
+  // without copying them.
+  const llvm::DenseMap>  =
+  SemaRef.OpenCLTypeExtMap;
+  using ElementTy = std::pair *>;
+  llvm::SmallVector StableOpenCLTypeExtMap;
+  StableOpenCLTypeExtMap.reserve(OpenCLTypeExtMap.size());
+
+  for (const auto  : OpenCLTypeExtMap)
+StableOpenCLTypeExtMap.emplace_back(
+getTypeID(I.first->getCanonicalTypeInternal()), );
+
+  auto CompareByTypeID = [](const ElementTy , const ElementTy ) -> bool {
+return E1.first < E2.first;
+  };
+  llvm::sort(StableOpenCLTypeExtMap, CompareByTypeID);
+
   RecordData Record;
-  for (const auto  : SemaRef.OpenCLTypeExtMap) {
-Record.push_back(
-static_cast(getTypeID(I.first->getCanonicalTypeInternal(;
-Record.push_back(I.second.size());
-for (auto Ext : I.second)
+  for (const ElementTy  : StableOpenCLTypeExtMap) {
+Record.push_back(E.first); // TypeID
+const std::set *ExtSet = E.second;
+Record.push_back(static_cast(ExtSet->size()));
+for (const std::string  : *ExtSet)
   AddString(Ext, Record);
   }
+
   Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record);
 }
 
@@ -4293,13 +4311,31 @@
   if (!SemaRef.Context.getLangOpts().OpenCL)
 return;
 
+  // Sort the elements of the map OpenCLDeclExtMap by DeclIDs,
+  // without copying them.
+  const llvm::DenseMap>  =
+  SemaRef.OpenCLDeclExtMap;
+  using ElementTy = std::pair *>;
+  llvm::SmallVector StableOpenCLDeclExtMap;
+  StableOpenCLDeclExtMap.reserve(OpenCLDeclExtMap.size());
+
+  for (const auto  : OpenCLDeclExtMap)
+StableOpenCLDeclExtMap.emplace_back(getDeclID(I.first), );
+
+  auto CompareByDeclID = [](const ElementTy , const ElementTy ) -> bool {
+return E1.first < E2.first;
+  };
+  llvm::sort(StableOpenCLDeclExtMap, CompareByDeclID);
+
   RecordData Record;
-  for (const auto  : SemaRef.OpenCLDeclExtMap) {
-Record.push_back(getDeclID(I.first));
-Record.push_back(static_cast(I.second.size()));
-for (auto Ext : I.second)
+  for (const ElementTy  : StableOpenCLDeclExtMap) {
+Record.push_back(E.first); // DeclID
+const std::set *ExtSet = E.second;
+Record.push_back(static_cast(ExtSet->size()));
+for (const std::string  : *ExtSet)
   AddString(Ext, Record);
   }
+
   Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record);
 }
 


Index: cfe/trunk/lib/Serialization/ASTWriter.cpp
===
--- cfe/trunk/lib/Serialization/ASTWriter.cpp
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp
@@ -4278,14 +4278,32 @@
   if (!SemaRef.Context.getLangOpts().OpenCL)
 return;
 
+  // Sort the elements of the map OpenCLTypeExtMap by TypeIDs,
+  // without copying them.
+  const llvm::DenseMap>  =
+  SemaRef.OpenCLTypeExtMap;
+  using ElementTy = std::pair *>;
+  llvm::SmallVector StableOpenCLTypeExtMap;
+  StableOpenCLTypeExtMap.reserve(OpenCLTypeExtMap.size());
+
+  for (const auto  : OpenCLTypeExtMap)
+StableOpenCLTypeExtMap.emplace_back(
+getTypeID(I.first->getCanonicalTypeInternal()), );
+
+  auto CompareByTypeID = [](const ElementTy , const ElementTy ) -> bool {
+return E1.first < E2.first;
+  };
+  llvm::sort(StableOpenCLTypeExtMap, CompareByTypeID);
+
   RecordData Record;
-  for (const auto  : SemaRef.OpenCLTypeExtMap) {
-Record.push_back(
-static_cast(getTypeID(I.first->getCanonicalTypeInternal(;
-Record.push_back(I.second.size());
-for (auto Ext : I.second)
+  for (const ElementTy  : StableOpenCLTypeExtMap) {
+Record.push_back(E.first); // TypeID
+const std::set *ExtSet = E.second;
+Record.push_back(static_cast(ExtSet->size()));
+for (const std::string  : *ExtSet)
   AddString(Ext, Record);
   }
+
   Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record);
 }
 
@@ -4293,13 +4311,31 @@
   if (!SemaRef.Context.getLangOpts().OpenCL)
 return;
 
+  // Sort the elements of the map OpenCLDeclExtMap by DeclIDs,
+  // without copying them.
+  const llvm::DenseMap>  =
+  SemaRef.OpenCLDeclExtMap;
+  using ElementTy = std::pair *>;
+  llvm::SmallVector StableOpenCLDeclExtMap;
+  

r358674 - [Serialization] Stable serialization order for OpenCLTypeExtMap and OpenCLDeclExtMap

2019-04-18 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Thu Apr 18 08:13:27 2019
New Revision: 358674

URL: http://llvm.org/viewvc/llvm-project?rev=358674=rev
Log:
[Serialization] Stable serialization order for OpenCLTypeExtMap and 
OpenCLDeclExtMap

Sort the elements of Sema::OpenCLTypeExtMap and Sema::OpenCLDeclExtMap
by TypeIDs and DeclIDs to guarantee a stable serialization order.

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

Reviewed By: Anastasia

Reviewers: Anastasia, lebedev.ri


Modified:
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=358674=358673=358674=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Apr 18 08:13:27 2019
@@ -4278,14 +4278,32 @@ void ASTWriter::WriteOpenCLExtensionType
   if (!SemaRef.Context.getLangOpts().OpenCL)
 return;
 
+  // Sort the elements of the map OpenCLTypeExtMap by TypeIDs,
+  // without copying them.
+  const llvm::DenseMap>  =
+  SemaRef.OpenCLTypeExtMap;
+  using ElementTy = std::pair *>;
+  llvm::SmallVector StableOpenCLTypeExtMap;
+  StableOpenCLTypeExtMap.reserve(OpenCLTypeExtMap.size());
+
+  for (const auto  : OpenCLTypeExtMap)
+StableOpenCLTypeExtMap.emplace_back(
+getTypeID(I.first->getCanonicalTypeInternal()), );
+
+  auto CompareByTypeID = [](const ElementTy , const ElementTy ) -> bool {
+return E1.first < E2.first;
+  };
+  llvm::sort(StableOpenCLTypeExtMap, CompareByTypeID);
+
   RecordData Record;
-  for (const auto  : SemaRef.OpenCLTypeExtMap) {
-Record.push_back(
-static_cast(getTypeID(I.first->getCanonicalTypeInternal(;
-Record.push_back(I.second.size());
-for (auto Ext : I.second)
+  for (const ElementTy  : StableOpenCLTypeExtMap) {
+Record.push_back(E.first); // TypeID
+const std::set *ExtSet = E.second;
+Record.push_back(static_cast(ExtSet->size()));
+for (const std::string  : *ExtSet)
   AddString(Ext, Record);
   }
+
   Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record);
 }
 
@@ -4293,13 +4311,31 @@ void ASTWriter::WriteOpenCLExtensionDecl
   if (!SemaRef.Context.getLangOpts().OpenCL)
 return;
 
+  // Sort the elements of the map OpenCLDeclExtMap by DeclIDs,
+  // without copying them.
+  const llvm::DenseMap>  =
+  SemaRef.OpenCLDeclExtMap;
+  using ElementTy = std::pair *>;
+  llvm::SmallVector StableOpenCLDeclExtMap;
+  StableOpenCLDeclExtMap.reserve(OpenCLDeclExtMap.size());
+
+  for (const auto  : OpenCLDeclExtMap)
+StableOpenCLDeclExtMap.emplace_back(getDeclID(I.first), );
+
+  auto CompareByDeclID = [](const ElementTy , const ElementTy ) -> bool {
+return E1.first < E2.first;
+  };
+  llvm::sort(StableOpenCLDeclExtMap, CompareByDeclID);
+
   RecordData Record;
-  for (const auto  : SemaRef.OpenCLDeclExtMap) {
-Record.push_back(getDeclID(I.first));
-Record.push_back(static_cast(I.second.size()));
-for (auto Ext : I.second)
+  for (const ElementTy  : StableOpenCLDeclExtMap) {
+Record.push_back(E.first); // DeclID
+const std::set *ExtSet = E.second;
+Record.push_back(static_cast(ExtSet->size()));
+for (const std::string  : *ExtSet)
   AddString(Ext, Record);
   }
+
   Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record);
 }
 


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


[PATCH] D60845: [VerifyDiagnosticConsumer] Document -verify= in doxygen

2019-04-18 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Thanks for the accepts.

In D60845#1470986 , @NoQ wrote:

> In D60845#1470980 , @Charusso wrote:
>
> > I really like live working examples, I hope not just me. Could you link 
> > https://github.com/llvm/llvm-project/blob/master/clang/test/Analysis/use-after-move.cpp
> >  as well as a live example?
>
>
> I'd rather reserve an ability for myself to move the test around without 
> breaking links all over the place. Live examples are easy to grep for as soon 
> as you know what to grep for.


Agreed.

In D60845#1471002 , @rsmith wrote:

> I've seen a few projects outside of clang use `-verify` mode for their own 
> testing of various things.


Interesting.  What's an example?


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

https://reviews.llvm.org/D60845



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


[PATCH] D60845: [VerifyDiagnosticConsumer] Document -verify= in doxygen

2019-04-18 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 195742.
jdenny added a comment.

Clarify the behavior of multiple -verify options.


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

https://reviews.llvm.org/D60845

Files:
  clang/include/clang/Frontend/VerifyDiagnosticConsumer.h


Index: clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
===
--- clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
+++ clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
@@ -33,7 +33,33 @@
 /// markers in the input source to check that all the emitted diagnostics match
 /// those expected.
 ///
-/// USING THE DIAGNOSTIC CHECKER:
+/// INVOKING THE DIAGNOSTIC CHECKER:
+///
+/// VerifyDiagnosticConsumer is typically invoked via the "-verify" option to
+/// "clang -cc1".  "-verify" is equivalent to "-verify=expected", so all
+/// diagnostics are typically specified with the prefix "expected".  For
+/// example:
+///
+/// \code
+///   int A = B; // expected-error {{use of undeclared identifier 'B'}}
+/// \endcode
+///
+/// Custom prefixes can be specified as a comma-separated sequence.  Each
+/// prefix must start with a letter and contain only alphanumeric characters,
+/// hyphens, and underscores.  For example, given just "-verify=foo,bar",
+/// the above diagnostic would be ignored, but the following diagnostics would
+/// be recognized:
+///
+/// \code
+///   int A = B; // foo-error {{use of undeclared identifier 'B'}}
+///   int C = D; // bar-error {{use of undeclared identifier 'D'}}
+/// \endcode
+///
+/// Multiple occurrences accumulate prefixes.  For example,
+/// "-verify -verify=foo,bar -verify=baz" is equivalent to
+/// "-verify=expected,foo,bar,baz".
+///
+/// SPECIFYING DIAGNOSTICS:
 ///
 /// Indicating that a line expects an error or a warning is simple. Put a
 /// comment on the line that has the diagnostic, use:


Index: clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
===
--- clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
+++ clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
@@ -33,7 +33,33 @@
 /// markers in the input source to check that all the emitted diagnostics match
 /// those expected.
 ///
-/// USING THE DIAGNOSTIC CHECKER:
+/// INVOKING THE DIAGNOSTIC CHECKER:
+///
+/// VerifyDiagnosticConsumer is typically invoked via the "-verify" option to
+/// "clang -cc1".  "-verify" is equivalent to "-verify=expected", so all
+/// diagnostics are typically specified with the prefix "expected".  For
+/// example:
+///
+/// \code
+///   int A = B; // expected-error {{use of undeclared identifier 'B'}}
+/// \endcode
+///
+/// Custom prefixes can be specified as a comma-separated sequence.  Each
+/// prefix must start with a letter and contain only alphanumeric characters,
+/// hyphens, and underscores.  For example, given just "-verify=foo,bar",
+/// the above diagnostic would be ignored, but the following diagnostics would
+/// be recognized:
+///
+/// \code
+///   int A = B; // foo-error {{use of undeclared identifier 'B'}}
+///   int C = D; // bar-error {{use of undeclared identifier 'D'}}
+/// \endcode
+///
+/// Multiple occurrences accumulate prefixes.  For example,
+/// "-verify -verify=foo,bar -verify=baz" is equivalent to
+/// "-verify=expected,foo,bar,baz".
+///
+/// SPECIFYING DIAGNOSTICS:
 ///
 /// Indicating that a line expects an error or a warning is simple. Put a
 /// comment on the line that has the diagnostic, use:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60568: [OpenMP] Add support for registering requires directives with the runtime

2019-04-18 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:9135
   "%0 clause previously used here">;
+def err_omp_target_before_requires : Error <
+  "Target region encountered before requires directive with %0 clause.">;

Split the patch, sema part must be separate.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60568



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


[PATCH] D60568: [OpenMP] Add support for registering requires directives with the runtime

2019-04-18 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 195739.
gtbercea added a comment.

- Add const.
- Address comments.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60568

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/openmp_offload_registration.cpp
  test/OpenMP/target_codegen.cpp
  test/OpenMP/target_codegen_registration.cpp

Index: test/OpenMP/target_codegen_registration.cpp
===
--- test/OpenMP/target_codegen_registration.cpp
+++ test/OpenMP/target_codegen_registration.cpp
@@ -180,10 +180,11 @@
 // CHECK: [[DESC:@.+]] = internal constant [[DSCTY]] { i32 1, [[DEVTY]]* getelementptr inbounds ([1 x [[DEVTY]]], [1 x [[DEVTY]]]* [[IMAGES]], i32 0, i32 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, comdat($[[REGFN]])
 
 // We have 4 initializers, one for the 500 priority, another one for 501, or more for the default priority, and the last one for the offloading registration function.
-// CHECK: @llvm.global_ctors = appending global [4 x { i32, void ()*, i8* }] [
+// CHECK: @llvm.global_ctors = appending global [5 x { i32, void ()*, i8* }] [
 // CHECK-SAME: { i32, void ()*, i8* } { i32 500, void ()* [[P500:@[^,]+]], i8* null },
 // CHECK-SAME: { i32, void ()*, i8* } { i32 501, void ()* [[P501:@[^,]+]], i8* null },
 // CHECK-SAME: { i32, void ()*, i8* } { i32 65535, void ()* [[PMAX:@[^,]+]], i8* null },
+// CHECK-SAME: { i32, void ()*, i8* } { i32 0, void ()* @.omp_offloading.requires_reg, i8* null },
 // CHECK-SAME: { i32, void ()*, i8* } { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }]
 
 // CHECK-NTARGET: @llvm.global_ctors = appending global [3   x { i32, void ()*, i8* }] [
@@ -387,6 +388,10 @@
 
 // Check registration and unregistration
 
+//CHECK: define internal void @.omp_offloading.requires_reg()
+//CHECK: call void @__tgt_register_requires(i64 1)
+//CHECK: ret void
+
 //CHECK: define internal void @[[UNREGFN:.+]](i8*)
 //CHECK-SAME: comdat($[[REGFN]]) {
 //CHECK: call i32 @__tgt_unregister_lib([[DSCTY]]* [[DESC]])
@@ -432,31 +437,31 @@
 
 // Check metadata is properly generated:
 // CHECK: !omp_offload.info = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID:-?[0-9]+]], i32 [[FILEID:-?[0-9]+]], !"_ZN2SB3fooEv", i32 216, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SDD1Ev", i32 266, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SEC1Ev", i32 282, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SED1Ev", i32 288, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EE3fooEv", i32 299, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EEC1Ev", i32 305, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_Z3bari", i32 427, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EED1Ev", i32 311, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EEC1Ev", i32 305, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EED1Ev", i32 311, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EE3fooEv", i32 299, i32 {{[0-9]+}}}
-// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SCC1Ev", i32 241, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID:-?[0-9]+]], i32 [[FILEID:-?[0-9]+]], !"_ZN2SB3fooEv", i32 217, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SDD1Ev", i32 267, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SEC1Ev", i32 283, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SED1Ev", i32 289, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EE3fooEv", i32 300, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EEC1Ev", i32 306, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_Z3bari", i32 432, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EED1Ev", i32 312, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EEC1Ev", i32 306, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EED1Ev", i32 312, i32 {{[0-9]+}}}
+// CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EE3fooEv", i32 300, i32 {{[0-9]+}}}
+// CHECK-DAG: 

  1   2   >