Fix clang-format-vs to use characters position/count instead of the offset/length for Unicode Replacements

2018-10-20 Thread 김태석 via cfe-commits
Internally view.TextBuffer use sequence of Unicode characters encoded using
UTF-16 and use characters position/count for manipulating text.

When formatting an ANSI text, Replacements offset/length is same with
position/count but not an Unicode.

So conversion needed.
#include 
#include 

int main( int argc, char* argv[ ] )
{
std::string helloworld = "안녕, 세상!";

for( int i=0; i<3; ++i )
{
std::cout << helloworld << std::endl;
}

return 0;
}


ClangFormatPackage.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53475: Create ConstantExpr class

2018-10-20 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 170325.

Repository:
  rC Clang

https://reviews.llvm.org/D53475

Files:
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/StmtDataCollectors.td
  include/clang/Basic/StmtNodes.td
  include/clang/Serialization/ASTBitCodes.h
  lib/ARCMigrate/TransAutoreleasePool.cpp
  lib/ARCMigrate/TransRetainReleaseDealloc.cpp
  lib/ARCMigrate/TransUnbridgedCasts.cpp
  lib/ARCMigrate/Transforms.cpp
  lib/AST/Decl.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/ParentMap.cpp
  lib/AST/Stmt.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/Analysis/LiveVariables.cpp
  lib/Analysis/ThreadSafety.cpp
  lib/Analysis/ThreadSafetyCommon.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaStmt.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  lib/StaticAnalyzer/Core/BugReporter.cpp
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  lib/StaticAnalyzer/Core/Environment.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -343,6 +343,10 @@
 K = CXCursor_CharacterLiteral;
 break;
 
+  case Stmt::ConstantExprClass:
+return MakeCXCursor(cast(S)->getSubExpr(),
+Parent, TU, RegionOfInterest);
+
   case Stmt::ParenExprClass:
 K = CXCursor_ParenExpr;
 break;
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1267,6 +1267,9 @@
 case Stmt::ObjCPropertyRefExprClass:
   llvm_unreachable("These are handled by PseudoObjectExpr");
 
+case Expr::ConstantExprClass:
+  return Visit(cast(S)->getSubExpr(), Pred, DstTop);
+
 case Stmt::GNUNullExprClass: {
   // GNU __null is a pointer-width integer, not an actual pointer.
   ProgramStateRef state = Pred->getState();
Index: lib/StaticAnalyzer/Core/Environment.cpp
===
--- lib/StaticAnalyzer/Core/Environment.cpp
+++ lib/StaticAnalyzer/Core/Environment.cpp
@@ -44,6 +44,9 @@
   case Stmt::ExprWithCleanupsClass:
 E = cast(E)->getSubExpr();
 break;
+  case Stmt::ConstantExprClass:
+E = cast(E)->getSubExpr();
+break;
   case Stmt::CXXBindTemporaryExprClass:
 E = cast(E)->getSubExpr();
 break;
Index: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -142,8 +142,8 @@
   E = AE->getBase();
 } else if (const auto *PE = dyn_cast(E)) {
   E = PE->getSubExpr();
-} else if (const auto *EWC = dyn_cast(E)) {
-  E = EWC->getSubExpr();
+} else if (const auto *FE = dyn_cast(E)) {
+  E = FE->getSubExpr();
 } else {
   // Other arbitrary stuff.
   break;
@@ -1515,8 +1515,8 @@
 static const Expr *peelOffOuterExpr(const Expr *Ex,
 const ExplodedNode *N) {
   Ex = Ex->IgnoreParenCasts();
-  if (const auto *EWC = dyn_cast(Ex))
-return peelOffOuterExpr(EWC->getSubExpr(), N);
+  if (const auto *FE = dyn_cast(Ex))
+return peelOffOuterExpr(FE->getSubExpr(), N);
   if (const auto *OVE = dyn_cast(Ex))
 return peelOffOuterExpr(OVE->getSourceExpr(), N);
   if (const auto *POE = dyn_cast(Ex)) {
Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -1265,7 +1265,7 @@
 if (!S)
   break;
 
-if (isa(S) ||
+if (isa(S) ||
 isa(S) ||
 isa(S))
   continue;
Index: lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -329,9 +329,8 @@
 return;
 
   if (const Expr *E = V->getInit()) {
-while (const ExprWithCleanups *exprClean =
-dyn_cast(E))
-  E = exprClean->getSubExpr();
+while (const FullExpression *FE = dyn_cast(E))
+  E = FE->getSubExpr();
 
 // Look through transitive assignments, e.g.:
 // int x = y = 0;
Index: 

[PATCH] D53475: Create ConstantExpr class

2018-10-20 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 170324.
void marked an inline comment as done.
void added a comment.

Create a "FullExpression" parent class and skip full expressions in all places 
we skip with ExprWithCleanups.


Repository:
  rC Clang

https://reviews.llvm.org/D53475

Files:
  include/clang/AST/Expr.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/StmtDataCollectors.td
  include/clang/Basic/StmtNodes.td
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/Expr.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -343,6 +343,10 @@
 K = CXCursor_CharacterLiteral;
 break;
 
+  case Stmt::ConstantExprClass:
+return MakeCXCursor(cast(S)->getSubExpr(),
+Parent, TU, RegionOfInterest);
+
   case Stmt::ParenExprClass:
 K = CXCursor_ParenExpr;
 break;
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1267,6 +1267,9 @@
 case Stmt::ObjCPropertyRefExprClass:
   llvm_unreachable("These are handled by PseudoObjectExpr");
 
+case Expr::ConstantExprClass:
+  return Visit(cast(S)->getSubExpr(), Pred, DstTop);
+
 case Stmt::GNUNullExprClass: {
   // GNU __null is a pointer-width integer, not an actual pointer.
   ProgramStateRef state = Pred->getState();
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -386,6 +386,12 @@
   Record.push_back(E->getObjectKind());
 }
 
+void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
+  VisitExpr(E);
+  Record.AddStmt(E->getSubExpr());
+  Code = serialization::EXPR_CONSTANT;
+}
+
 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
   VisitExpr(E);
   Record.AddSourceLocation(E->getLocation());
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -491,6 +491,11 @@
  "Incorrect expression field count");
 }
 
+void ASTStmtReader::VisitConstantExpr(ConstantExpr *E) {
+  VisitExpr(E);
+  E->setSubExpr(Record.readSubExpr());
+}
+
 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
   VisitExpr(E);
   E->setLocation(ReadSourceLocation());
@@ -2335,6 +2340,10 @@
Record[ASTStmtReader::NumStmtFields]);
   break;
 
+case EXPR_CONSTANT:
+  S = new (Context) ConstantExpr(Empty);
+  break;
+
 case EXPR_PREDEFINED:
   S = new (Context) PredefinedExpr(Empty);
   break;
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -8914,6 +8914,12 @@
 //===--===//
 // Expression transformation
 //===--===//
+template
+ExprResult
+TreeTransform::TransformConstantExpr(ConstantExpr *E) {
+  return TransformExpr(E->getSubExpr());
+}
+
 template
 ExprResult
 TreeTransform::TransformPredefinedExpr(PredefinedExpr *E) {
Index: lib/Sema/SemaExceptionSpec.cpp
===
--- lib/Sema/SemaExceptionSpec.cpp
+++ lib/Sema/SemaExceptionSpec.cpp
@@ -1051,6 +1051,9 @@
   //   [Can throw] if in a potentially-evaluated context the expression would
   //   contain:
   switch (E->getStmtClass()) {
+  case Expr::ConstantExprClass:
+return canThrow(cast(E)->getSubExpr());
+
   case Expr::CXXThrowExprClass:
 //   - a potentially evaluated throw-expression
 return CT_Can;
Index: lib/AST/StmtProfile.cpp
===
--- lib/AST/StmtProfile.cpp
+++ lib/AST/StmtProfile.cpp
@@ -996,6 +996,11 @@
   VisitStmt(S);
 }
 
+void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
+  VisitExpr(S);
+  VisitExpr(S->getSubExpr());
+}
+
 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
   VisitExpr(S);
   if (!Canonical)
Index: lib/AST/StmtPrinter.cpp
===
--- lib/AST/StmtPrinter.cpp
+++ lib/AST/StmtPrinter.cpp
@@ -906,6 +906,10 @@
 //  Expr printing methods.
 

[PATCH] D45416: [AST, analyzer] Transform rvalue cast outputs to lvalues (fheinous-gnu-extensions)

2018-10-20 Thread Aleksei Sidorin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344864: [AST, analyzer] Transform rvalue cast outputs to 
lvalues (fheinous-gnu… (authored by a.sidorin, committed by ).
Herald added subscribers: llvm-commits, dkrupp, donat.nagy.

Changed prior to commit:
  https://reviews.llvm.org/D45416?vs=144998=170322#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45416

Files:
  cfe/trunk/lib/Sema/SemaStmtAsm.cpp
  cfe/trunk/test/Analysis/asm.cpp
  cfe/trunk/test/Analysis/cfg.cpp

Index: cfe/trunk/test/Analysis/cfg.cpp
===
--- cfe/trunk/test/Analysis/cfg.cpp
+++ cfe/trunk/test/Analysis/cfg.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++11 -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions -std=c++11 -analyzer-config cfg-rich-constructors=false %s > %t 2>&1
 // RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++11 -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions -std=c++11 -analyzer-config cfg-rich-constructors=true %s > %t 2>&1
 // RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s
 
 // This file tests how we construct two different flavors of the Clang CFG -
@@ -84,6 +84,24 @@
   static_assert(1, "abc");
 }
 
+
+// CHECK-LABEL: void checkGCCAsmRValueOutput()
+// CHECK: [B2 (ENTRY)]
+// CHECK-NEXT: Succs (1): B1
+// CHECK: [B1]
+// CHECK-NEXT:   1: int arg
+// CHECK-NEXT:   2: arg
+// CHECK-NEXT:   3: (int)[B1.2] (CStyleCastExpr, NoOp, int)
+// CHECK-NEXT:   4: asm ("" : "=r" ([B1.3]));
+// CHECK-NEXT:   5: arg
+// CHECK-NEXT:   6: asm ("" : "=r" ([B1.5]));
+void checkGCCAsmRValueOutput() {
+  int arg;
+  __asm__("" : "=r"((int)arg));  // rvalue output operand
+  __asm__("" : "=r"(arg));   // lvalue output operand
+}
+
+
 // CHECK-LABEL: void F(EmptyE e)
 // CHECK: ENTRY
 // CHECK-NEXT: Succs (1): B1
Index: cfe/trunk/test/Analysis/asm.cpp
===
--- cfe/trunk/test/Analysis/asm.cpp
+++ cfe/trunk/test/Analysis/asm.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker debug.ExprInspection -fheinous-gnu-extensions -w %s -verify
+
+int clang_analyzer_eval(int);
+
+int global;
+void testRValueOutput() {
+  int  = global;
+  ref = 1;
+  __asm__("" : "=r"(((int)(global;  // don't crash on rvalue output operand
+  clang_analyzer_eval(global == 1); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(ref == 1);// expected-warning{{UNKNOWN}}
+}
Index: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
===
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp
@@ -27,14 +27,66 @@
 using namespace clang;
 using namespace sema;
 
+/// Remove the upper-level LValueToRValue cast from an expression.
+static void removeLValueToRValueCast(Expr *E) {
+  Expr *Parent = E;
+  Expr *ExprUnderCast = nullptr;
+  SmallVector ParentsToUpdate;
+
+  while (true) {
+ParentsToUpdate.push_back(Parent);
+if (auto *ParenE = dyn_cast(Parent)) {
+  Parent = ParenE->getSubExpr();
+  continue;
+}
+
+Expr *Child = nullptr;
+CastExpr *ParentCast = dyn_cast(Parent);
+if (ParentCast)
+  Child = ParentCast->getSubExpr();
+else
+  return;
+
+if (auto *CastE = dyn_cast(Child))
+  if (CastE->getCastKind() == CK_LValueToRValue) {
+ExprUnderCast = CastE->getSubExpr();
+// LValueToRValue cast inside GCCAsmStmt requires an explicit cast.
+ParentCast->setSubExpr(ExprUnderCast);
+break;
+  }
+Parent = Child;
+  }
+
+  // Update parent expressions to have same ValueType as the underlying.
+  assert(ExprUnderCast &&
+ "Should be reachable only if LValueToRValue cast was found!");
+  auto ValueKind = ExprUnderCast->getValueKind();
+  for (Expr *E : ParentsToUpdate)
+E->setValueKind(ValueKind);
+}
+
+/// Emit a warning about usage of "noop"-like casts for lvalues (GNU extension)
+/// and fix the argument with removing LValueToRValue cast from the expression.
+static void emitAndFixInvalidAsmCastLValue(const Expr *LVal, Expr *BadArgument,
+   Sema ) {
+  if (!S.getLangOpts().HeinousExtensions) {
+S.Diag(LVal->getBeginLoc(), diag::err_invalid_asm_cast_lvalue)
+<< BadArgument->getSourceRange();
+  } else {
+S.Diag(LVal->getBeginLoc(), diag::warn_invalid_asm_cast_lvalue)
+<< BadArgument->getSourceRange();
+  }
+  removeLValueToRValueCast(BadArgument);
+}
+
 /// CheckAsmLValue - GNU C has an extremely ugly 

r344864 - [AST, analyzer] Transform rvalue cast outputs to lvalues (fheinous-gnu-extensions)

2018-10-20 Thread Aleksei Sidorin via cfe-commits
Author: a.sidorin
Date: Sat Oct 20 15:49:23 2018
New Revision: 344864

URL: http://llvm.org/viewvc/llvm-project?rev=344864=rev
Log:
[AST, analyzer] Transform rvalue cast outputs to lvalues 
(fheinous-gnu-extensions)

Despite the fact that cast expressions return rvalues, GCC still
handles such outputs as lvalues when compiling inline assembler.
In this commit, we are treating it by removing LValueToRValue
casts inside GCCAsmStmt outputs.

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

Added:
cfe/trunk/test/Analysis/asm.cpp
Modified:
cfe/trunk/lib/Sema/SemaStmtAsm.cpp
cfe/trunk/test/Analysis/cfg.cpp

Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=344864=344863=344864=diff
==
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Sat Oct 20 15:49:23 2018
@@ -27,6 +27,58 @@
 using namespace clang;
 using namespace sema;
 
+/// Remove the upper-level LValueToRValue cast from an expression.
+static void removeLValueToRValueCast(Expr *E) {
+  Expr *Parent = E;
+  Expr *ExprUnderCast = nullptr;
+  SmallVector ParentsToUpdate;
+
+  while (true) {
+ParentsToUpdate.push_back(Parent);
+if (auto *ParenE = dyn_cast(Parent)) {
+  Parent = ParenE->getSubExpr();
+  continue;
+}
+
+Expr *Child = nullptr;
+CastExpr *ParentCast = dyn_cast(Parent);
+if (ParentCast)
+  Child = ParentCast->getSubExpr();
+else
+  return;
+
+if (auto *CastE = dyn_cast(Child))
+  if (CastE->getCastKind() == CK_LValueToRValue) {
+ExprUnderCast = CastE->getSubExpr();
+// LValueToRValue cast inside GCCAsmStmt requires an explicit cast.
+ParentCast->setSubExpr(ExprUnderCast);
+break;
+  }
+Parent = Child;
+  }
+
+  // Update parent expressions to have same ValueType as the underlying.
+  assert(ExprUnderCast &&
+ "Should be reachable only if LValueToRValue cast was found!");
+  auto ValueKind = ExprUnderCast->getValueKind();
+  for (Expr *E : ParentsToUpdate)
+E->setValueKind(ValueKind);
+}
+
+/// Emit a warning about usage of "noop"-like casts for lvalues (GNU extension)
+/// and fix the argument with removing LValueToRValue cast from the expression.
+static void emitAndFixInvalidAsmCastLValue(const Expr *LVal, Expr *BadArgument,
+   Sema ) {
+  if (!S.getLangOpts().HeinousExtensions) {
+S.Diag(LVal->getBeginLoc(), diag::err_invalid_asm_cast_lvalue)
+<< BadArgument->getSourceRange();
+  } else {
+S.Diag(LVal->getBeginLoc(), diag::warn_invalid_asm_cast_lvalue)
+<< BadArgument->getSourceRange();
+  }
+  removeLValueToRValueCast(BadArgument);
+}
+
 /// CheckAsmLValue - GNU C has an extremely ugly extension whereby they 
silently
 /// ignore "noop" casts in places where an lvalue is required by an inline asm.
 /// We emulate this behavior when -fheinous-gnu-extensions is specified, but
@@ -34,7 +86,7 @@ using namespace sema;
 ///
 /// This method checks to see if the argument is an acceptable l-value and
 /// returns false if it is a case we can handle.
-static bool CheckAsmLValue(const Expr *E, Sema ) {
+static bool CheckAsmLValue(Expr *E, Sema ) {
   // Type dependent expressions will be checked during instantiation.
   if (E->isTypeDependent())
 return false;
@@ -46,12 +98,7 @@ static bool CheckAsmLValue(const Expr *E
   // are supposed to allow.
   const Expr *E2 = E->IgnoreParenNoopCasts(S.Context);
   if (E != E2 && E2->isLValue()) {
-if (!S.getLangOpts().HeinousExtensions)
-  S.Diag(E2->getBeginLoc(), diag::err_invalid_asm_cast_lvalue)
-  << E->getSourceRange();
-else
-  S.Diag(E2->getBeginLoc(), diag::warn_invalid_asm_cast_lvalue)
-  << E->getSourceRange();
+emitAndFixInvalidAsmCastLValue(E2, E, S);
 // Accept, even if we emitted an error diagnostic.
 return false;
   }
@@ -264,13 +311,7 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceL
   break;
 case Expr::MLV_LValueCast: {
   const Expr *LVal = OutputExpr->IgnoreParenNoopCasts(Context);
-  if (!getLangOpts().HeinousExtensions) {
-Diag(LVal->getBeginLoc(), diag::err_invalid_asm_cast_lvalue)
-<< OutputExpr->getSourceRange();
-  } else {
-Diag(LVal->getBeginLoc(), diag::warn_invalid_asm_cast_lvalue)
-<< OutputExpr->getSourceRange();
-  }
+  emitAndFixInvalidAsmCastLValue(LVal, OutputExpr, *this);
   // Accept, even if we emitted an error diagnostic.
   break;
 }

Added: cfe/trunk/test/Analysis/asm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/asm.cpp?rev=344864=auto
==
--- cfe/trunk/test/Analysis/asm.cpp (added)
+++ cfe/trunk/test/Analysis/asm.cpp Sat Oct 20 15:49:23 2018
@@ -0,0 +1,12 @@
+// RUN: 

[PATCH] D53475: Create ConstantExpr class

2018-10-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Looks fine as far as it goes, but we're going to need to change all the places 
that skip past ExprWithCleanups to also step over this node. Since both nodes 
represent the boundary of a particular kind of full-expression, it'd make sense 
to me for them to at least have a common base class for such "skipping" 
purposes.




Comment at: lib/AST/StmtProfile.cpp:1001
+  VisitExpr(S);
+  VisitExpr(S->getSubExpr());
+}

This is unnecessary: this visitor visits the children of the node for you.


Repository:
  rC Clang

https://reviews.llvm.org/D53475



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


[PATCH] D53475: Create ConstantExpr class

2018-10-20 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 170321.

Repository:
  rC Clang

https://reviews.llvm.org/D53475

Files:
  include/clang/AST/Expr.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/StmtDataCollectors.td
  include/clang/Basic/StmtNodes.td
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/Expr.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -343,6 +343,10 @@
 K = CXCursor_CharacterLiteral;
 break;
 
+  case Stmt::ConstantExprClass:
+return MakeCXCursor(cast(S)->getSubExpr(),
+Parent, TU, RegionOfInterest);
+
   case Stmt::ParenExprClass:
 K = CXCursor_ParenExpr;
 break;
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1267,6 +1267,9 @@
 case Stmt::ObjCPropertyRefExprClass:
   llvm_unreachable("These are handled by PseudoObjectExpr");
 
+case Expr::ConstantExprClass:
+  return Visit(cast(S)->getSubExpr(), Pred, DstTop);
+
 case Stmt::GNUNullExprClass: {
   // GNU __null is a pointer-width integer, not an actual pointer.
   ProgramStateRef state = Pred->getState();
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -386,6 +386,12 @@
   Record.push_back(E->getObjectKind());
 }
 
+void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
+  VisitExpr(E);
+  Record.AddStmt(E->getSubExpr());
+  Code = serialization::EXPR_CONSTANT;
+}
+
 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
   VisitExpr(E);
   Record.AddSourceLocation(E->getLocation());
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -491,6 +491,11 @@
  "Incorrect expression field count");
 }
 
+void ASTStmtReader::VisitConstantExpr(ConstantExpr *E) {
+  VisitExpr(E);
+  E->setSubExpr(Record.readSubExpr());
+}
+
 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
   VisitExpr(E);
   E->setLocation(ReadSourceLocation());
@@ -2335,6 +2340,10 @@
Record[ASTStmtReader::NumStmtFields]);
   break;
 
+case EXPR_CONSTANT:
+  S = new (Context) ConstantExpr(Empty);
+  break;
+
 case EXPR_PREDEFINED:
   S = new (Context) PredefinedExpr(Empty);
   break;
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -8914,6 +8914,12 @@
 //===--===//
 // Expression transformation
 //===--===//
+template
+ExprResult
+TreeTransform::TransformConstantExpr(ConstantExpr *E) {
+  return TransformExpr(E->getSubExpr());
+}
+
 template
 ExprResult
 TreeTransform::TransformPredefinedExpr(PredefinedExpr *E) {
Index: lib/Sema/SemaExceptionSpec.cpp
===
--- lib/Sema/SemaExceptionSpec.cpp
+++ lib/Sema/SemaExceptionSpec.cpp
@@ -1051,6 +1051,9 @@
   //   [Can throw] if in a potentially-evaluated context the expression would
   //   contain:
   switch (E->getStmtClass()) {
+  case Expr::ConstantExprClass:
+return canThrow(cast(E)->getSubExpr());
+
   case Expr::CXXThrowExprClass:
 //   - a potentially evaluated throw-expression
 return CT_Can;
Index: lib/AST/StmtProfile.cpp
===
--- lib/AST/StmtProfile.cpp
+++ lib/AST/StmtProfile.cpp
@@ -996,6 +996,11 @@
   VisitStmt(S);
 }
 
+void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
+  VisitExpr(S);
+  VisitExpr(S->getSubExpr());
+}
+
 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
   VisitExpr(S);
   if (!Canonical)
Index: lib/AST/StmtPrinter.cpp
===
--- lib/AST/StmtPrinter.cpp
+++ lib/AST/StmtPrinter.cpp
@@ -906,6 +906,10 @@
 //  Expr printing methods.
 //===--===//
 
+void StmtPrinter::VisitConstantExpr(ConstantExpr *Node) {
+  VisitExpr(Node->getSubExpr());
+}
+
 void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
   if 

[PATCH] D53475: Create ConstantExpr class

2018-10-20 Thread Bill Wendling via Phabricator via cfe-commits
void created this revision.
void added a reviewer: rsmith.
void added a project: clang.
Herald added a subscriber: cfe-commits.

A ConstantExpr class represents a full expression that's in a
context where a constant expression is required. This class reflects
the path the evaluator took to reach the expression rather than
the syntactic context in which the expression occurs.

In the future, the class will be expanded to cache the result of
the evaluated expression so that it's not needlessly re-evaluated.


Repository:
  rC Clang

https://reviews.llvm.org/D53475

Files:
  include/clang/AST/Expr.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/StmtDataCollectors.td
  include/clang/Basic/StmtNodes.td
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/Expr.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -343,6 +343,10 @@
 K = CXCursor_CharacterLiteral;
 break;
 
+  case Stmt::ConstantExprClass:
+return MakeCXCursor(cast(S)->getSubExpr(),
+Parent, TU, RegionOfInterest);
+
   case Stmt::ParenExprClass:
 K = CXCursor_ParenExpr;
 break;
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1267,6 +1267,9 @@
 case Stmt::ObjCPropertyRefExprClass:
   llvm_unreachable("These are handled by PseudoObjectExpr");
 
+case Expr::ConstantExprClass:
+  return Visit(cast(S)->getSubExpr(), Pred, DstTop);
+
 case Stmt::GNUNullExprClass: {
   // GNU __null is a pointer-width integer, not an actual pointer.
   ProgramStateRef state = Pred->getState();
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -386,6 +386,12 @@
   Record.push_back(E->getObjectKind());
 }
 
+void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) {
+  VisitExpr(E);
+  Record.AddStmt(E->getSubExpr());
+  Code = serialization::EXPR_CONSTANT;
+}
+
 void ASTStmtWriter::VisitPredefinedExpr(PredefinedExpr *E) {
   VisitExpr(E);
   Record.AddSourceLocation(E->getLocation());
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -491,6 +491,11 @@
  "Incorrect expression field count");
 }
 
+void ASTStmtReader::VisitConstantExpr(ConstantExpr *E) {
+  VisitExpr(E);
+  E->setSubExpr(Record.readSubExpr());
+}
+
 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
   VisitExpr(E);
   E->setLocation(ReadSourceLocation());
@@ -2335,6 +2340,10 @@
Record[ASTStmtReader::NumStmtFields]);
   break;
 
+case EXPR_CONSTANT:
+  S = new (Context) ConstantExpr(Empty);
+  break;
+
 case EXPR_PREDEFINED:
   S = new (Context) PredefinedExpr(Empty);
   break;
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -8914,6 +8914,12 @@
 //===--===//
 // Expression transformation
 //===--===//
+template
+ExprResult
+TreeTransform::TransformConstantExpr(ConstantExpr *E) {
+  return TransformExpr(E->getSubExpr());
+}
+
 template
 ExprResult
 TreeTransform::TransformPredefinedExpr(PredefinedExpr *E) {
Index: lib/Sema/SemaExceptionSpec.cpp
===
--- lib/Sema/SemaExceptionSpec.cpp
+++ lib/Sema/SemaExceptionSpec.cpp
@@ -1051,6 +1051,9 @@
   //   [Can throw] if in a potentially-evaluated context the expression would
   //   contain:
   switch (E->getStmtClass()) {
+  case Expr::ConstantExprClass:
+return canThrow(cast(E)->getSubExpr());
+
   case Expr::CXXThrowExprClass:
 //   - a potentially evaluated throw-expression
 return CT_Can;
Index: lib/AST/StmtProfile.cpp
===
--- lib/AST/StmtProfile.cpp
+++ lib/AST/StmtProfile.cpp
@@ -996,6 +996,11 @@
   VisitStmt(S);
 }
 
+void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
+  VisitExpr(S);
+  VisitExpr(S->getSubExpr());
+}
+
 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
   VisitExpr(S);
   

[PATCH] D53277: [analyzer][NFC] Collect all -analyzer-config options in a .def file

2018-10-20 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

In https://reviews.llvm.org/D53277#1269960, @NoQ wrote:

> I think this is awesome o_o







Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.def:386
+
+ANALYZER_OPTION_WITH_FN(StringRef, ModelPath, "model-path", "", "",
+getModelPath)

Found the use for this here: 
https://github.com/llvm-mirror/clang/blob/master/lib/StaticAnalyzer/Frontend/ModelInjector.cpp#L51

Which was added by this commit:
https://github.com/llvm-mirror/clang/commit/fdf0d3513240fd8e4da6942e9cd26d2d730eb37b#diff-6e67e63f578935f02bd1d5b20488ea8c
>This patch was contributed by Gábor Horváth as part of his Google Summer of 
>Code project.

@xazax.hun, what would be a good description for this flag?


https://reviews.llvm.org/D53277



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


[PATCH] D53277: [analyzer][NFC] Collect all -analyzer-config options in a .def file

2018-10-20 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 170318.
Szelethus added a comment.

Removed doxygen comments, rebased to `D53276`.

Please don't mind me saying this, but damn that's one pretty .def file compared 
to the mess that `AnalyzerOptions` currently is :).


https://reviews.llvm.org/D53277

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp

Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -56,17 +56,17 @@
 static std::unique_ptr generateWorkList(AnalyzerOptions ,
   SubEngine ) {
   switch (Opts.getExplorationStrategy()) {
-case AnalyzerOptions::ExplorationStrategyKind::DFS:
+case ExplorationStrategyKind::DFS:
   return WorkList::makeDFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFS:
+case ExplorationStrategyKind::BFS:
   return WorkList::makeBFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFSBlockDFSContents:
+case ExplorationStrategyKind::BFSBlockDFSContents:
   return WorkList::makeBFSBlockDFSContents();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirst:
+case ExplorationStrategyKind::UnexploredFirst:
   return WorkList::makeUnexploredFirst();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstQueue:
+case ExplorationStrategyKind::UnexploredFirstQueue:
   return WorkList::makeUnexploredFirstPriorityQueue();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue:
+case ExplorationStrategyKind::UnexploredFirstLocationQueue:
   return WorkList::makeUnexploredFirstPriorityLocationQueue();
   }
 }
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -49,7 +49,7 @@
   return Result;
 }
 
-AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() {
+UserModeKind AnalyzerOptions::getUserMode() {
   if (!UserMode.hasValue()) {
 StringRef ModeStr = getOptionAsString("mode", "deep");
 UserMode = llvm::StringSwitch>(ModeStr)
@@ -61,7 +61,7 @@
   return UserMode.getValue();
 }
 
-AnalyzerOptions::ExplorationStrategyKind
+ExplorationStrategyKind
 AnalyzerOptions::getExplorationStrategy() {
   if (!ExplorationStrategy.hasValue()) {
 StringRef StratStr = getOptionAsString("exploration_strategy",
@@ -183,137 +183,6 @@
   return V.getValue();
 }
 
-bool AnalyzerOptions::includeTemporaryDtorsInCFG() {
-  return getBooleanOption(IncludeTemporaryDtorsInCFG,
-  "cfg-temporary-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeImplicitDtorsInCFG() {
-  return getBooleanOption(IncludeImplicitDtorsInCFG,
-  "cfg-implicit-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeLifetimeInCFG() {
-  return getBooleanOption(IncludeLifetimeInCFG, "cfg-lifetime",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeLoopExitInCFG() {
-  return getBooleanOption(IncludeLoopExitInCFG, "cfg-loopexit",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeRichConstructorsInCFG() {
-  return getBooleanOption(IncludeRichConstructorsInCFG,
-  "cfg-rich-constructors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeScopesInCFG() {
-  return getBooleanOption(IncludeScopesInCFG,
-  "cfg-scopes",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
-  return getBooleanOption(InlineCXXStandardLibrary,
-  "c++-stdlib-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineTemplateFunctions() {
-  return getBooleanOption(InlineTemplateFunctions,
-  "c++-template-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXAllocator() {
-  return getBooleanOption(InlineCXXAllocator,
-  "c++-allocator-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXContainerMethods() {
-  return getBooleanOption(InlineCXXContainerMethods,
-  "c++-container-inlining",
-  /*Default=*/false);
-}
-
-bool AnalyzerOptions::mayInlineCXXSharedPtrDtor() {
-  return getBooleanOption(InlineCXXSharedPtrDtor,
-  "c++-shared_ptr-inlining",
-  /*Default=*/false);
-}
-
-bool 

[PATCH] D53276: [analyzer][NFC] Fix some incorrect uses of -analyzer-config options

2018-10-20 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp:1401-1402
   checker->IsAggressive =
-  mgr.getAnalyzerOptions().getBooleanOption("AggressiveReport", false);
+  mgr.getAnalyzerOptions().getBooleanOption("AggressiveReport", false,
+checker);
 }

NoQ wrote:
> Nice :)
> 
> I'll poke Devin about this, please wait on me before committing.
I added a similar change to `RetainCountChecker`, it takes its 
`"leak-diagnostics-reference-allocation"` as a checker option. Mention that too 
I guess.


https://reviews.llvm.org/D53276



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


[PATCH] D53276: [analyzer][NFC] Fix some incorrect uses of -analyzer-config options

2018-10-20 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 170315.
Szelethus edited the summary of this revision.
Szelethus added a comment.
Herald added a subscriber: mgorny.

Added two more fixes, and added this to the summary:

- `lib/StaticAnalyzer/Checkers/AllocationDiagnostics.cpp` and 
`lib/StaticAnalyzer/Checkers/AllocationDiagnostics.h` are weird, they actually 
only contain an option getter. I deleted them, and fixed `RetainCountChecker` 
to get it's `"leak-diagnostics-reference-allocation"` option as a checker 
option,
- `"region-store-small-struct-limit"` has a proper getter now.


https://reviews.llvm.org/D53276

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Checkers/AllocationDiagnostics.cpp
  lib/StaticAnalyzer/Checkers/AllocationDiagnostics.h
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  test/Analysis/analyzer-config.c
  test/Analysis/analyzer-config.cpp

Index: test/Analysis/analyzer-config.cpp
===
--- test/Analysis/analyzer-config.cpp
+++ test/Analysis/analyzer-config.cpp
@@ -41,7 +41,6 @@
 // CHECK-NEXT: inline-lambdas = true
 // CHECK-NEXT: ipa = dynamic-bifurcate
 // CHECK-NEXT: ipa-always-inline-size = 3
-// CHECK-NEXT: leak-diagnostics-reference-allocation = false
 // CHECK-NEXT: max-inlinable-size = 100
 // CHECK-NEXT: max-nodes = 225000
 // CHECK-NEXT: max-times-inline-large = 32
@@ -52,4 +51,4 @@
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 32
+// CHECK-NEXT: num-entries = 31
Index: test/Analysis/analyzer-config.c
===
--- test/Analysis/analyzer-config.c
+++ test/Analysis/analyzer-config.c
@@ -26,7 +26,6 @@
 // CHECK-NEXT: inline-lambdas = true
 // CHECK-NEXT: ipa = dynamic-bifurcate
 // CHECK-NEXT: ipa-always-inline-size = 3
-// CHECK-NEXT: leak-diagnostics-reference-allocation = false
 // CHECK-NEXT: max-inlinable-size = 100
 // CHECK-NEXT: max-nodes = 225000
 // CHECK-NEXT: max-times-inline-large = 32
@@ -37,4 +36,4 @@
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 25
+// CHECK-NEXT: num-entries = 24
Index: lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- lib/StaticAnalyzer/Core/RegionStore.cpp
+++ lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -350,7 +350,7 @@
 if (SubEngine *Eng = StateMgr.getOwningEngine()) {
   AnalyzerOptions  = Eng->getAnalysisManager().options;
   SmallStructLimit =
-Options.getOptionAsInteger("region-store-small-struct-limit", 2);
+Options.getRegionStoreSmallStructLimit();
 }
   }
 
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -497,8 +497,21 @@
   return NaiveCTU.getValue();
 }
 
+unsigned AnalyzerOptions::getRegionStoreSmallStructLimit() {
+  if (!RegionStoreSmallStructLimit.hasValue())
+RegionStoreSmallStructLimit =
+   getOptionAsInteger("region-store-small-struct-limit", 2);
+  return RegionStoreSmallStructLimit.getValue();
+}
+
 StringRef AnalyzerOptions::getCTUIndexName() {
   if (!CTUIndexName.hasValue())
 CTUIndexName = getOptionAsString("ctu-index-name", "externalFnMap.txt");
   return CTUIndexName.getValue();
 }
+
+StringRef AnalyzerOptions::getModelPath() {
+  if (!ModelPath.hasValue())
+ModelPath = getOptionAsString("model-path", "");
+  return ModelPath.getValue();
+}
Index: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
@@ -16,7 +16,6 @@
 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H
 
 #include "../ClangSACheckers.h"
-#include "../AllocationDiagnostics.h"
 #include "RetainCountDiagnostics.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
@@ -279,7 +278,8 @@
   RetainCountChecker(AnalyzerOptions )
   : Options(Options), ShouldResetSummaryLog(false),
 IncludeAllocationLine(
-shouldIncludeAllocationSiteInLeakDiagnostics(Options)) {}
+Options.getBooleanOption("leak-diagnostics-reference-allocation",
+ false, this)) {}
 
   ~RetainCountChecker() override { DeleteContainerSeconds(DeadSymbolTags); }
 
Index: lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- lib/StaticAnalyzer/Checkers/CMakeLists.txt

[PATCH] D53076: [analyzer] Enhance ConditionBRVisitor to write out more information

2018-10-20 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In https://reviews.llvm.org/D53076#1261134, @NoQ wrote:

> For example, in the `inline-plist.c`'s `bar()` on line 45, Static Analyzer 
> indeed doesn't assume that `p` is equal to null; instead, Static Analyzer 
> *knows* it for sure.


Thanks you! This a great example what I have to cover later on. I have a patch 
where we print out known integers. The basic style is the following: `Assuming 
'x' is not equal to 1`. I would like to emphasize the value and if it a known 
value, make it looks like this: `Variable 'x' is equal to '1'`, or `Variable 
'*ptr' is equal to '1'`. (If this is the situation: `Constant 'x' is equal to 
'1'` would be cool as well.)

I made that patch in a separated file called `BugReporterHelpers.cpp` next to 
the `BugReporterVisitors`. I also would like to move all the helper functions 
from `BugReporterVisitors.cpp` to that source file. My first idea with that to 
create a live documentation, how would a new clang-hacker obtain a value from a 
certain position (me with testing those things out). Also what you mentioned 
with this flow-sensitive chaining, this is could not be a short patch, so I 
think this is the time when we want to have something like this.

What do you think? If this patch goes well, should I attach the mentioned new 
patch to this, or create a new one?


https://reviews.llvm.org/D53076



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


r344862 - [X86] Add more intrinsics to match icc.

2018-10-20 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Sat Oct 20 12:28:52 2018
New Revision: 344862

URL: http://llvm.org/viewvc/llvm-project?rev=344862=rev
Log:
[X86] Add more intrinsics to match icc.

This adds
_mm_loadu_epi8, _mm256_loadu_epi8, _mm512_loadu_epi8
_mm_loadu_epi16, _mm256_loadu_epi16, _mm512_loadu_epi16
_mm_storeu_epi8, _mm256_storeu_epi8, _mm512_storeu_epi8
_mm_storeu_epi16, _mm256_storeu_epi16, _mm512_storeu_epi16

Modified:
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/avx512vlbwintrin.h
cfe/trunk/test/CodeGen/avx512bw-builtins.c
cfe/trunk/test/CodeGen/avx512vl-builtins.c
cfe/trunk/test/CodeGen/avx512vlbw-builtins.c

Modified: cfe/trunk/lib/Headers/avx512bwintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=344862=344861=344862=diff
==
--- cfe/trunk/lib/Headers/avx512bwintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512bwintrin.h Sat Oct 20 12:28:52 2018
@@ -1747,6 +1747,15 @@ _mm512_kunpackw (__mmask32 __A, __mmask3
 (__mmask32) __B);
 }
 
+static __inline __m512i __DEFAULT_FN_ATTRS512
+_mm512_loadu_epi16 (void const *__P)
+{
+  struct __loadu_epi16 {
+__m512i __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((struct __loadu_epi16*)__P)->__v;
+}
+
 static __inline__ __m512i __DEFAULT_FN_ATTRS512
 _mm512_mask_loadu_epi16 (__m512i __W, __mmask32 __U, void const *__P)
 {
@@ -1764,6 +1773,15 @@ _mm512_maskz_loadu_epi16 (__mmask32 __U,
  (__mmask32) __U);
 }
 
+static __inline __m512i __DEFAULT_FN_ATTRS512
+_mm512_loadu_epi8 (void const *__P)
+{
+  struct __loadu_epi8 {
+__m512i __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((struct __loadu_epi8*)__P)->__v;
+}
+
 static __inline__ __m512i __DEFAULT_FN_ATTRS512
 _mm512_mask_loadu_epi8 (__m512i __W, __mmask64 __U, void const *__P)
 {
@@ -1780,6 +1798,16 @@ _mm512_maskz_loadu_epi8 (__mmask64 __U,
  _mm512_setzero_si512 (),
  (__mmask64) __U);
 }
+
+static __inline void __DEFAULT_FN_ATTRS512
+_mm512_storeu_epi16 (void *__P, __m512i __A)
+{
+  struct __storeu_epi16 {
+__m512i __v;
+  } __attribute__((__packed__, __may_alias__));
+  ((struct __storeu_epi16*)__P)->__v = __A;
+}
+
 static __inline__ void __DEFAULT_FN_ATTRS512
 _mm512_mask_storeu_epi16 (void *__P, __mmask32 __U, __m512i __A)
 {
@@ -1788,6 +1816,15 @@ _mm512_mask_storeu_epi16 (void *__P, __m
  (__mmask32) __U);
 }
 
+static __inline void __DEFAULT_FN_ATTRS512
+_mm512_storeu_epi8 (void *__P, __m512i __A)
+{
+  struct __storeu_epi8 {
+__m512i __v;
+  } __attribute__((__packed__, __may_alias__));
+  ((struct __storeu_epi8*)__P)->__v = __A;
+}
+
 static __inline__ void __DEFAULT_FN_ATTRS512
 _mm512_mask_storeu_epi8 (void *__P, __mmask64 __U, __m512i __A)
 {

Modified: cfe/trunk/lib/Headers/avx512vlbwintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512vlbwintrin.h?rev=344862=344861=344862=diff
==
--- cfe/trunk/lib/Headers/avx512vlbwintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512vlbwintrin.h Sat Oct 20 12:28:52 2018
@@ -2297,6 +2297,15 @@ _mm256_maskz_set1_epi8 (__mmask32 __M, c
   (__v32qi) 
_mm256_setzero_si256());
 }
 
+static __inline __m128i __DEFAULT_FN_ATTRS128
+_mm_loadu_epi16 (void const *__P)
+{
+  struct __loadu_epi16 {
+__m128i __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((struct __loadu_epi16*)__P)->__v;
+}
+
 static __inline__ __m128i __DEFAULT_FN_ATTRS128
 _mm_mask_loadu_epi16 (__m128i __W, __mmask8 __U, void const *__P)
 {
@@ -2314,6 +2323,15 @@ _mm_maskz_loadu_epi16 (__mmask8 __U, voi
  (__mmask8) __U);
 }
 
+static __inline __m256i __DEFAULT_FN_ATTRS256
+_mm256_loadu_epi16 (void const *__P)
+{
+  struct __loadu_epi16 {
+__m256i __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((struct __loadu_epi16*)__P)->__v;
+}
+
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_mask_loadu_epi16 (__m256i __W, __mmask16 __U, void const *__P)
 {
@@ -2331,6 +2349,15 @@ _mm256_maskz_loadu_epi16 (__mmask16 __U,
  (__mmask16) __U);
 }
 
+static __inline __m128i __DEFAULT_FN_ATTRS128
+_mm_loadu_epi8 (void const *__P)
+{
+  struct __loadu_epi8 {
+__m128i __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((struct __loadu_epi8*)__P)->__v;
+}
+
 static __inline__ __m128i __DEFAULT_FN_ATTRS128
 _mm_mask_loadu_epi8 (__m128i __W, __mmask16 __U, void const *__P)
 {
@@ -2348,6 +2375,15 @@ _mm_maskz_loadu_epi8 (__mmask16 __U, voi
  (__mmask16) __U);
 }
 
+static __inline __m256i __DEFAULT_FN_ATTRS256
+_mm256_loadu_epi8 (void const *__P)
+{
+  struct __loadu_epi8 {
+__m256i __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((struct __loadu_epi8*)__P)->__v;
+}
+
 static __inline__ 

r344861 - [X86] Add missing intrinsics to match icc.

2018-10-20 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Sat Oct 20 12:28:50 2018
New Revision: 344861

URL: http://llvm.org/viewvc/llvm-project?rev=344861=rev
Log:
[X86] Add missing intrinsics to match icc.

This adds
_mm_and_epi32, _mm_and_epi64
_mm_andnot_epi32, _mm_andnot_epi64
_mm_or_epi32, _mm_or_epi64
_mm_xor_epi32, _mm_xor_epi64
_mm256_and_epi32, _mm256_and_epi64
_mm256_andnot_epi32, _mm256_andnot_epi64
_mm256_or_epi32, _mm256_or_epi64
_mm256_xor_epi32, _mm256_xor_epi64
_mm_loadu_epi32, _mm_loadu_epi64
_mm_load_epi32, _mm_load_epi64
_mm256_loadu_epi32, _mm256_loadu_epi64
_mm256_load_epi32, _mm256_load_epi64
_mm512_loadu_epi32, _mm512_loadu_epi64
_mm512_load_epi32, _mm512_load_epi64
_mm_storeu_epi32, _mm_storeu_epi64
_mm_store_epi32, _mm_load_epi64
_mm256_storeu_epi32, _mm256_storeu_epi64
_mm256_store_epi32, _mm256_load_epi64
_mm512_storeu_epi32, _mm512_storeu_epi64
_mm512_store_epi32,V _mm512_load_epi64

Modified:
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Headers/avx512vlintrin.h
cfe/trunk/test/CodeGen/avx512f-builtins.c
cfe/trunk/test/CodeGen/avx512vl-builtins.c

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=344861=344860=344861=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Sat Oct 20 12:28:50 2018
@@ -4330,6 +4330,15 @@ _mm512_loadu_si512 (void const *__P)
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS512
+_mm512_loadu_epi32 (void const *__P)
+{
+  struct __loadu_epi32 {
+__m512i __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((struct __loadu_epi32*)__P)->__v;
+}
+
+static __inline __m512i __DEFAULT_FN_ATTRS512
 _mm512_mask_loadu_epi32 (__m512i __W, __mmask16 __U, void const *__P)
 {
   return (__m512i) __builtin_ia32_loaddqusi512_mask ((const int *) __P,
@@ -4348,6 +4357,15 @@ _mm512_maskz_loadu_epi32(__mmask16 __U,
 }
 
 static __inline __m512i __DEFAULT_FN_ATTRS512
+_mm512_loadu_epi64 (void const *__P)
+{
+  struct __loadu_epi64 {
+__m512i __v;
+  } __attribute__((__packed__, __may_alias__));
+  return ((struct __loadu_epi64*)__P)->__v;
+}
+
+static __inline __m512i __DEFAULT_FN_ATTRS512
 _mm512_mask_loadu_epi64 (__m512i __W, __mmask8 __U, void const *__P)
 {
   return (__m512i) __builtin_ia32_loaddqudi512_mask ((const long long *) __P,
@@ -4483,6 +4501,15 @@ _mm512_load_epi64 (void const *__P)
 /* SIMD store ops */
 
 static __inline void __DEFAULT_FN_ATTRS512
+_mm512_storeu_epi64 (void *__P, __m512i __A)
+{
+  struct __storeu_epi64 {
+__m512i __v;
+  } __attribute__((__packed__, __may_alias__));
+  ((struct __storeu_epi64*)__P)->__v = __A;
+}
+
+static __inline void __DEFAULT_FN_ATTRS512
 _mm512_mask_storeu_epi64(void *__P, __mmask8 __U, __m512i __A)
 {
   __builtin_ia32_storedqudi512_mask ((long long *)__P, (__v8di) __A,
@@ -4499,6 +4526,15 @@ _mm512_storeu_si512 (void *__P, __m512i
 }
 
 static __inline void __DEFAULT_FN_ATTRS512
+_mm512_storeu_epi32 (void *__P, __m512i __A)
+{
+  struct __storeu_epi32 {
+__m512i __v;
+  } __attribute__((__packed__, __may_alias__));
+  ((struct __storeu_epi32*)__P)->__v = __A;
+}
+
+static __inline void __DEFAULT_FN_ATTRS512
 _mm512_mask_storeu_epi32(void *__P, __mmask16 __U, __m512i __A)
 {
   __builtin_ia32_storedqusi512_mask ((int *)__P, (__v16si) __A,

Modified: cfe/trunk/lib/Headers/avx512vlintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512vlintrin.h?rev=344861=344860=344861=diff
==
--- cfe/trunk/lib/Headers/avx512vlintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512vlintrin.h Sat Oct 20 12:28:50 2018
@@ -462,10 +462,16 @@ _mm_mask_mullo_epi32(__m128i __W, __mmas
 }
 
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
+_mm256_and_epi32(__m256i __a, __m256i __b)
+{
+  return (__m256i)((__v8su)__a & (__v8su)__b);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_mask_and_epi32(__m256i __W, __mmask8 __U, __m256i __A, __m256i __B)
 {
   return (__m256i)__builtin_ia32_selectd_256((__mmask8)__U,
- (__v8si)_mm256_and_si256(__A, 
__B),
+ (__v8si)_mm256_and_epi32(__A, 
__B),
  (__v8si)__W);
 }
 
@@ -476,10 +482,16 @@ _mm256_maskz_and_epi32(__mmask8 __U, __m
 }
 
 static __inline__ __m128i __DEFAULT_FN_ATTRS128
+_mm_and_epi32(__m128i __a, __m128i __b)
+{
+  return (__m128i)((__v4su)__a & (__v4su)__b);
+}
+
+static __inline__ __m128i __DEFAULT_FN_ATTRS128
 _mm_mask_and_epi32(__m128i __W, __mmask8 __U, __m128i __A, __m128i __B)
 {
   return (__m128i)__builtin_ia32_selectd_128((__mmask8)__U,
- (__v4si)_mm_and_si128(__A, __B),
+ (__v4si)_mm_and_epi32(__A, __B),
  

r344859 - Use llvm::{all, any, none}_of instead std::{all, any, none}_of. NFC

2018-10-20 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Sat Oct 20 10:53:42 2018
New Revision: 344859

URL: http://llvm.org/viewvc/llvm-project?rev=344859=rev
Log:
Use llvm::{all,any,none}_of instead std::{all,any,none}_of. NFC

Modified:
cfe/trunk/lib/AST/VTableBuilder.cpp
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/Analysis/CloneDetection.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp

Modified: cfe/trunk/lib/AST/VTableBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTableBuilder.cpp?rev=344859=344858=344859=diff
==
--- cfe/trunk/lib/AST/VTableBuilder.cpp (original)
+++ cfe/trunk/lib/AST/VTableBuilder.cpp Sat Oct 20 10:53:42 2018
@@ -3406,10 +3406,9 @@ static void removeRedundantPaths(std::li
 for (const FullPathTy  : FullPaths) {
   if ( == )
 continue;
-  if (std::all_of(SpecificPath.begin(), SpecificPath.end(),
-  [&](const BaseSubobject ) {
-return OtherPath.count(BSO) != 0;
-  })) {
+  if (llvm::all_of(SpecificPath, [&](const BaseSubobject ) {
+return OtherPath.count(BSO) != 0;
+  })) {
 return true;
   }
 }
@@ -3485,10 +3484,9 @@ static const FullPathTy *selectBestPath(
   // It's possible that the overrider isn't in this path.  If so, skip it
   // because this path didn't introduce it.
   const CXXRecordDecl *OverridingParent = OverridingMethod->getParent();
-  if (std::none_of(SpecificPath.begin(), SpecificPath.end(),
-   [&](const BaseSubobject ) {
- return BSO.getBase() == OverridingParent;
-   }))
+  if (llvm::none_of(SpecificPath, [&](const BaseSubobject ) {
+return BSO.getBase() == OverridingParent;
+  }))
 continue;
   CurrentOverrides.insert(OverridingMethod);
 }

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=344859=344858=344859=diff
==
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Sat Oct 20 10:53:42 2018
@@ -144,10 +144,10 @@ DynTypedMatcher DynTypedMatcher::constru
 ast_type_traits::ASTNodeKind SupportedKind,
 std::vector InnerMatchers) {
   assert(!InnerMatchers.empty() && "Array must not be empty.");
-  assert(std::all_of(InnerMatchers.begin(), InnerMatchers.end(),
- [SupportedKind](const DynTypedMatcher ) {
-   return M.canConvertTo(SupportedKind);
- }) &&
+  assert(llvm::all_of(InnerMatchers,
+  [SupportedKind](const DynTypedMatcher ) {
+return M.canConvertTo(SupportedKind);
+  }) &&
  "InnerMatchers must be convertible to SupportedKind!");
 
   // We must relax the restrict kind here.
@@ -449,7 +449,7 @@ bool HasNameMatcher::matchesNodeUnqualif
   assert(UseUnqualifiedMatch);
   llvm::SmallString<128> Scratch;
   StringRef NodeName = getNodeName(Node, Scratch);
-  return std::any_of(Names.begin(), Names.end(), [&](StringRef Name) {
+  return llvm::any_of(Names, [&](StringRef Name) {
 return consumeNameSuffix(Name, NodeName) && Name.empty();
   });
 }

Modified: cfe/trunk/lib/Analysis/CloneDetection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CloneDetection.cpp?rev=344859=344858=344859=diff
==
--- cfe/trunk/lib/Analysis/CloneDetection.cpp (original)
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp Sat Oct 20 10:53:42 2018
@@ -523,8 +523,7 @@ void CloneConstraint::splitCloneGroups(
   Result.push_back(PotentialGroup);
 }
 
-assert(std::all_of(Indexes.begin(), Indexes.end(),
-   [](char c) { return c == 1; }));
+assert(llvm::all_of(Indexes, [](char c) { return c == 1; }));
   }
   CloneGroups = Result;
 }

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=344859=344858=344859=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Sat Oct 20 10:53:42 2018
@@ -741,8 +741,8 @@ CodeGenTypes::arrangeLLVMFunctionInfo(Ca
   FunctionType::ExtInfo info,
  ArrayRef paramInfos,
   RequiredArgs required) {
-  

[clang-tools-extra] r344858 - [clangd] Fix unqualified make_unique after r344850. NFC

2018-10-20 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Sat Oct 20 10:40:12 2018
New Revision: 344858

URL: http://llvm.org/viewvc/llvm-project?rev=344858=rev
Log:
[clangd] Fix unqualified make_unique after r344850. NFC

Modified:
clang-tools-extra/trunk/clangd/index/dex/Dex.cpp

Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=344858=344857=344858=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Sat Oct 20 10:40:12 2018
@@ -29,8 +29,8 @@ std::unique_ptr Dex::build(
 ArrayRef URISchemes) {
   auto Size = Symbols.bytes() + Refs.bytes();
   auto Data = std::make_pair(std::move(Symbols), std::move(Refs));
-  return make_unique(Data.first, Data.second, std::move(Data), Size,
-  std::move(URISchemes));
+  return llvm::make_unique(Data.first, Data.second, std::move(Data), Size,
+std::move(URISchemes));
 }
 
 namespace {


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


[clang-tools-extra] r344856 - Check that __MAC_OS_X_VERSION_MIN_REQUIRED is defined before checking

2018-10-20 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Sat Oct 20 10:35:50 2018
New Revision: 344856

URL: http://llvm.org/viewvc/llvm-project?rev=344856=rev
Log:
Check that __MAC_OS_X_VERSION_MIN_REQUIRED is defined before checking
whether it is too old.

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

Modified: clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp?rev=344856=344855=344856=diff
==
--- clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp Sat Oct 20 
10:35:50 2018
@@ -19,7 +19,9 @@ namespace {
 
 // No fmemopen on windows or on versions of MacOS X earlier than 10.13, so we
 // can't easily run this test.
-#if !(defined(WIN32) || __MAC_OS_X_VERSION_MIN_REQUIRED < 101300)
+#if !(defined(WIN32) || \
+  (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
+   __MAC_OS_X_VERSION_MIN_REQUIRED < 101300))
 
 // Fixture takes care of managing the input/output buffers for the transport.
 class JSONTransportTest : public ::testing::Test {


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


r344847 - [NFC][Test commit] Fix typos in a comment

2018-10-20 Thread Aleksei Sidorin via cfe-commits
Author: a.sidorin
Date: Sat Oct 20 07:47:37 2018
New Revision: 344847

URL: http://llvm.org/viewvc/llvm-project?rev=344847=rev
Log:
[NFC][Test commit] Fix typos in a comment


Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp?rev=344847=344846=344847=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp Sat Oct 20 07:47:37 
2018
@@ -441,8 +441,8 @@ void CheckerManager::runCheckersForEndFu
ExplodedNode *Pred,
ExprEngine ,
const ReturnStmt *RS) {
-  // We define the builder outside of the loop bacause if at least one checkers
-  // creates a sucsessor for Pred, we do not need to generate an
+  // We define the builder outside of the loop because if at least one checker
+  // creates a successor for Pred, we do not need to generate an
   // autotransition for it.
   NodeBuilder Bldr(Pred, Dst, BC);
   for (const auto checkFn : EndFunctionCheckers) {


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


[clang-tools-extra] r344845 - Fix MSVC "truncation from 'double' to 'float'" warning. NFCI.

2018-10-20 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Sat Oct 20 06:20:26 2018
New Revision: 344845

URL: http://llvm.org/viewvc/llvm-project?rev=344845=rev
Log:
Fix MSVC "truncation from 'double' to 'float'" warning. NFCI.

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

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=344845=344844=344845=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Sat Oct 20 06:20:26 2018
@@ -323,7 +323,7 @@ static float scopeBoost(ScopeDistance 
 return 1;
   auto D = Distance.distance(*SymbolScope);
   if (D == FileDistance::Unreachable)
-return 0.4;
+return 0.4f;
   return std::max(0.5, 2.0 * std::pow(0.6, D / 2.0));
 }
 


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


[clang-tools-extra] r344844 - Fix MSVC "not all control paths return a value" warning. NFCI.

2018-10-20 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Sat Oct 20 06:18:49 2018
New Revision: 344844

URL: http://llvm.org/viewvc/llvm-project?rev=344844=rev
Log:
Fix MSVC "not all control paths return a value" warning. NFCI.

Modified:
clang-tools-extra/trunk/clangd/index/FileIndex.cpp

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=344844=344843=344844=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Sat Oct 20 06:18:49 2018
@@ -160,6 +160,7 @@ FileSymbols::buildIndex(IndexType Type,
 std::move(RefsStorage)),
 StorageSize, std::move(URISchemes));
   }
+  llvm_unreachable("Unknown clangd::IndexType");
 }
 
 FileIndex::FileIndex(std::vector URISchemes, bool UseDex)


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


[PATCH] D53472: Add gfx904 and gfx906 to GPU Arch

2018-10-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a subscriber: jholewinski.

https://reviews.llvm.org/D53472

Files:
  include/clang/Basic/Cuda.h
  lib/Basic/Cuda.cpp
  lib/Basic/Targets/NVPTX.cpp


Index: lib/Basic/Targets/NVPTX.cpp
===
--- lib/Basic/Targets/NVPTX.cpp
+++ lib/Basic/Targets/NVPTX.cpp
@@ -188,6 +188,8 @@
   case CudaArch::GFX810:
   case CudaArch::GFX900:
   case CudaArch::GFX902:
+  case CudaArch::GFX904:
+  case CudaArch::GFX906:
   case CudaArch::LAST:
 break;
   case CudaArch::UNKNOWN:
Index: lib/Basic/Cuda.cpp
===
--- lib/Basic/Cuda.cpp
+++ lib/Basic/Cuda.cpp
@@ -90,6 +90,10 @@
 return "gfx900";
   case CudaArch::GFX902: // TBA
 return "gfx902";
+  case CudaArch::GFX904: // TBA
+return "gfx904";
+  case CudaArch::GFX906: // TBA
+return "gfx906";
   }
   llvm_unreachable("invalid enum");
 }
@@ -124,6 +128,8 @@
   .Case("gfx810", CudaArch::GFX810)
   .Case("gfx900", CudaArch::GFX900)
   .Case("gfx902", CudaArch::GFX902)
+  .Case("gfx904", CudaArch::GFX904)
+  .Case("gfx906", CudaArch::GFX906)
   .Default(CudaArch::UNKNOWN);
 }
 
@@ -233,6 +239,8 @@
   case CudaArch::GFX810:
   case CudaArch::GFX900:
   case CudaArch::GFX902:
+  case CudaArch::GFX904:
+  case CudaArch::GFX906:
 return CudaVirtualArch::COMPUTE_AMDGCN;
   }
   llvm_unreachable("invalid enum");
@@ -277,6 +285,8 @@
   case CudaArch::GFX810:
   case CudaArch::GFX900:
   case CudaArch::GFX902:
+  case CudaArch::GFX904:
+  case CudaArch::GFX906:
 return CudaVersion::CUDA_70;
   }
   llvm_unreachable("invalid enum");
Index: include/clang/Basic/Cuda.h
===
--- include/clang/Basic/Cuda.h
+++ include/clang/Basic/Cuda.h
@@ -62,6 +62,8 @@
   GFX810,
   GFX900,
   GFX902,
+  GFX904,
+  GFX906,
   LAST,
 };
 const char *CudaArchToString(CudaArch A);


Index: lib/Basic/Targets/NVPTX.cpp
===
--- lib/Basic/Targets/NVPTX.cpp
+++ lib/Basic/Targets/NVPTX.cpp
@@ -188,6 +188,8 @@
   case CudaArch::GFX810:
   case CudaArch::GFX900:
   case CudaArch::GFX902:
+  case CudaArch::GFX904:
+  case CudaArch::GFX906:
   case CudaArch::LAST:
 break;
   case CudaArch::UNKNOWN:
Index: lib/Basic/Cuda.cpp
===
--- lib/Basic/Cuda.cpp
+++ lib/Basic/Cuda.cpp
@@ -90,6 +90,10 @@
 return "gfx900";
   case CudaArch::GFX902: // TBA
 return "gfx902";
+  case CudaArch::GFX904: // TBA
+return "gfx904";
+  case CudaArch::GFX906: // TBA
+return "gfx906";
   }
   llvm_unreachable("invalid enum");
 }
@@ -124,6 +128,8 @@
   .Case("gfx810", CudaArch::GFX810)
   .Case("gfx900", CudaArch::GFX900)
   .Case("gfx902", CudaArch::GFX902)
+  .Case("gfx904", CudaArch::GFX904)
+  .Case("gfx906", CudaArch::GFX906)
   .Default(CudaArch::UNKNOWN);
 }
 
@@ -233,6 +239,8 @@
   case CudaArch::GFX810:
   case CudaArch::GFX900:
   case CudaArch::GFX902:
+  case CudaArch::GFX904:
+  case CudaArch::GFX906:
 return CudaVirtualArch::COMPUTE_AMDGCN;
   }
   llvm_unreachable("invalid enum");
@@ -277,6 +285,8 @@
   case CudaArch::GFX810:
   case CudaArch::GFX900:
   case CudaArch::GFX902:
+  case CudaArch::GFX904:
+  case CudaArch::GFX906:
 return CudaVersion::CUDA_70;
   }
   llvm_unreachable("invalid enum");
Index: include/clang/Basic/Cuda.h
===
--- include/clang/Basic/Cuda.h
+++ include/clang/Basic/Cuda.h
@@ -62,6 +62,8 @@
   GFX810,
   GFX900,
   GFX902,
+  GFX904,
+  GFX906,
   LAST,
 };
 const char *CudaArchToString(CudaArch A);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52857: Deprecate 'set output foo' API of clang-query

2018-10-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 170310.
steveire added a comment.

Don't deprecate existing API


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52857

Files:
  clang-query/Query.cpp
  clang-query/Query.h
  clang-query/QueryParser.cpp
  clang-query/QuerySession.h
  unittests/clang-query/QueryEngineTest.cpp
  unittests/clang-query/QueryParserTest.cpp

Index: unittests/clang-query/QueryParserTest.cpp
===
--- unittests/clang-query/QueryParserTest.cpp
+++ unittests/clang-query/QueryParserTest.cpp
@@ -59,6 +59,35 @@
   EXPECT_EQ("unexpected extra input: ' me'", cast(Q)->ErrStr);
 }
 
+TEST_F(QueryParserTest, Exclusive) {
+  QueryRef Q = parse("set output");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+cast(Q)->ErrStr);
+
+  Q = parse("set output foo");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+cast(Q)->ErrStr);
+
+  Q = parse("set output dump");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ(::ASTOutput, cast(Q)->Var);
+  std::string Str;
+  llvm::raw_string_ostream OS(Str);
+  Q->run(OS, QS);
+  EXPECT_EQ(true, QS.ASTOutput);
+  EXPECT_EQ(false, QS.DiagOutput);
+  EXPECT_EQ(false, QS.PrintOutput);
+
+  std::vector Comps =
+  QueryParser::complete("", 0, QS);
+  Comps = QueryParser::complete("set o", 5, QS);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("utput ", Comps[0].TypedText);
+  EXPECT_EQ("output", Comps[0].DisplayText);
+}
+
 TEST_F(QueryParserTest, Set) {
   QueryRef Q = parse("set");
   ASSERT_TRUE(isa(Q));
@@ -68,24 +97,24 @@
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unknown variable: 'foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output");
+  Q = parse("set ast-output");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+  EXPECT_EQ("expected 'true' or 'false', got ''",
 cast(Q)->ErrStr);
 
   Q = parse("set bind-root true foo");
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unexpected extra input: ' foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output foo");
+  Q = parse("set ast-output foo");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+  EXPECT_EQ("expected 'true' or 'false', got 'foo'",
 cast(Q)->ErrStr);
 
-  Q = parse("set output dump");
-  ASSERT_TRUE(isa >(Q));
-  EXPECT_EQ(::OutKind, cast >(Q)->Var);
-  EXPECT_EQ(OK_Dump, cast >(Q)->Value);
+  Q = parse("set ast-output true");
+  ASSERT_TRUE(isa>(Q));
+  EXPECT_EQ(::ASTOutput, cast>(Q)->Var);
+  EXPECT_EQ(true, cast>(Q)->Value);
 
   Q = parse("set bind-root foo");
   ASSERT_TRUE(isa(Q));
@@ -174,10 +203,14 @@
   EXPECT_EQ("unlet ", Comps[5].TypedText);
   EXPECT_EQ("unlet", Comps[5].DisplayText);
 
-  Comps = QueryParser::complete("set o", 5, QS);
+  Comps = QueryParser::complete("set d", 5, QS);
   ASSERT_EQ(1u, Comps.size());
-  EXPECT_EQ("utput ", Comps[0].TypedText);
-  EXPECT_EQ("output", Comps[0].DisplayText);
+  EXPECT_EQ("iag-output ", Comps[0].TypedText);
+  EXPECT_EQ("diag-output", Comps[0].DisplayText);
+  Comps = QueryParser::complete("set a", 5, QS);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("st-output ", Comps[0].TypedText);
+  EXPECT_EQ("ast-output", Comps[0].DisplayText);
 
   Comps = QueryParser::complete("match while", 11, QS);
   ASSERT_EQ(1u, Comps.size());
Index: unittests/clang-query/QueryEngineTest.cpp
===
--- unittests/clang-query/QueryEngineTest.cpp
+++ unittests/clang-query/QueryEngineTest.cpp
@@ -48,6 +48,24 @@
   llvm::raw_string_ostream OS;
 };
 
+TEST_F(QueryEngineTest, Exclusive) {
+  DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
+
+  EXPECT_TRUE(SetOutputQuery(::PrintOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery("functionDecl(hasName(\"foo1\"))", FooMatcher).run(OS, S));
+
+  EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
+  std::string::npos);
+
+  Str.clear();
+
+  EXPECT_TRUE(SetOutputQuery(::ASTOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery("functionDecl(hasName(\"foo1\"))", FooMatcher).run(OS, S));
+  EXPECT_TRUE(OS.str().find("FunctionDecl") != std::string::npos);
+
+  Str.clear();
+}
+
 TEST_F(QueryEngineTest, Basic) {
   DynTypedMatcher FnMatcher = functionDecl();
   DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
@@ -94,22 +112,36 @@
 
   Str.clear();
 
-  EXPECT_TRUE(
-  SetQuery(::OutKind, OK_Print).run(OS, S));
+  EXPECT_TRUE(SetQuery(::DiagOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, true).run(OS, S));
   EXPECT_TRUE(MatchQuery(FooMatcherString, FooMatcher).run(OS, S));
 
   EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
   std::string::npos);
 
   Str.clear();
 
-  EXPECT_TRUE(SetQuery(::OutKind, OK_Dump).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::ASTOutput, true).run(OS, S));
   

[PATCH] D52857: Deprecate 'set output foo' API of clang-query

2018-10-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

Perhaps the best solution is to introduce this new API, but not deprecate the 
existing 'exclusive' API.

What do you think?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52857



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


[PATCH] D52857: Deprecate 'set output foo' API of clang-query

2018-10-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 170308.
steveire added a comment.

Update test


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52857

Files:
  clang-query/Query.cpp
  clang-query/Query.h
  clang-query/QueryParser.cpp
  clang-query/QuerySession.h
  unittests/clang-query/QueryEngineTest.cpp
  unittests/clang-query/QueryParserTest.cpp

Index: unittests/clang-query/QueryParserTest.cpp
===
--- unittests/clang-query/QueryParserTest.cpp
+++ unittests/clang-query/QueryParserTest.cpp
@@ -59,6 +59,35 @@
   EXPECT_EQ("unexpected extra input: ' me'", cast(Q)->ErrStr);
 }
 
+TEST_F(QueryParserTest, Deprecated) {
+  QueryRef Q = parse("set output");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+cast(Q)->ErrStr);
+
+  Q = parse("set output foo");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+cast(Q)->ErrStr);
+
+  Q = parse("set output dump");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ(::ASTOutput, cast(Q)->Var);
+  std::string Str;
+  llvm::raw_string_ostream OS(Str);
+  Q->run(OS, QS);
+  EXPECT_EQ(true, QS.ASTOutput);
+  EXPECT_EQ(false, QS.DiagOutput);
+  EXPECT_EQ(false, QS.PrintOutput);
+
+  std::vector Comps =
+  QueryParser::complete("", 0, QS);
+  Comps = QueryParser::complete("set o", 5, QS);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("utput ", Comps[0].TypedText);
+  EXPECT_EQ("output", Comps[0].DisplayText);
+}
+
 TEST_F(QueryParserTest, Set) {
   QueryRef Q = parse("set");
   ASSERT_TRUE(isa(Q));
@@ -68,24 +97,24 @@
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unknown variable: 'foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output");
+  Q = parse("set ast-output");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+  EXPECT_EQ("expected 'true' or 'false', got ''",
 cast(Q)->ErrStr);
 
   Q = parse("set bind-root true foo");
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unexpected extra input: ' foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output foo");
+  Q = parse("set ast-output foo");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+  EXPECT_EQ("expected 'true' or 'false', got 'foo'",
 cast(Q)->ErrStr);
 
-  Q = parse("set output dump");
-  ASSERT_TRUE(isa >(Q));
-  EXPECT_EQ(::OutKind, cast >(Q)->Var);
-  EXPECT_EQ(OK_Dump, cast >(Q)->Value);
+  Q = parse("set ast-output true");
+  ASSERT_TRUE(isa>(Q));
+  EXPECT_EQ(::ASTOutput, cast>(Q)->Var);
+  EXPECT_EQ(true, cast>(Q)->Value);
 
   Q = parse("set bind-root foo");
   ASSERT_TRUE(isa(Q));
@@ -174,10 +203,14 @@
   EXPECT_EQ("unlet ", Comps[5].TypedText);
   EXPECT_EQ("unlet", Comps[5].DisplayText);
 
-  Comps = QueryParser::complete("set o", 5, QS);
+  Comps = QueryParser::complete("set d", 5, QS);
   ASSERT_EQ(1u, Comps.size());
-  EXPECT_EQ("utput ", Comps[0].TypedText);
-  EXPECT_EQ("output", Comps[0].DisplayText);
+  EXPECT_EQ("iag-output ", Comps[0].TypedText);
+  EXPECT_EQ("diag-output", Comps[0].DisplayText);
+  Comps = QueryParser::complete("set a", 5, QS);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("st-output ", Comps[0].TypedText);
+  EXPECT_EQ("ast-output", Comps[0].DisplayText);
 
   Comps = QueryParser::complete("match while", 11, QS);
   ASSERT_EQ(1u, Comps.size());
Index: unittests/clang-query/QueryEngineTest.cpp
===
--- unittests/clang-query/QueryEngineTest.cpp
+++ unittests/clang-query/QueryEngineTest.cpp
@@ -48,6 +48,24 @@
   llvm::raw_string_ostream OS;
 };
 
+TEST_F(QueryEngineTest, Deprecated) {
+  DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
+
+  EXPECT_TRUE(SetOutputQuery(::PrintOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery("functionDecl(hasName(\"foo1\"))", FooMatcher).run(OS, S));
+
+  EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
+  std::string::npos);
+
+  Str.clear();
+
+  EXPECT_TRUE(SetOutputQuery(::ASTOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery("functionDecl(hasName(\"foo1\"))", FooMatcher).run(OS, S));
+  EXPECT_TRUE(OS.str().find("FunctionDecl") != std::string::npos);
+
+  Str.clear();
+}
+
 TEST_F(QueryEngineTest, Basic) {
   DynTypedMatcher FnMatcher = functionDecl();
   DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
@@ -94,22 +112,36 @@
 
   Str.clear();
 
-  EXPECT_TRUE(
-  SetQuery(::OutKind, OK_Print).run(OS, S));
+  EXPECT_TRUE(SetQuery(::DiagOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, true).run(OS, S));
   EXPECT_TRUE(MatchQuery(FooMatcherString, FooMatcher).run(OS, S));
 
   EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
   std::string::npos);
 
   Str.clear();
 
-  EXPECT_TRUE(SetQuery(::OutKind, OK_Dump).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::ASTOutput, true).run(OS, S));
   

[PATCH] D52859: [clang-query] Add option to print matcher expression

2018-10-20 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344840: [clang-query] Add option to print matcher expression 
(authored by steveire, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D52859?vs=168219=170307#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52859

Files:
  clang-tools-extra/trunk/clang-query/Query.cpp
  clang-tools-extra/trunk/clang-query/Query.h
  clang-tools-extra/trunk/clang-query/QueryParser.cpp
  clang-tools-extra/trunk/clang-query/QuerySession.h
  clang-tools-extra/trunk/unittests/clang-query/QueryEngineTest.cpp

Index: clang-tools-extra/trunk/clang-query/QueryParser.cpp
===
--- clang-tools-extra/trunk/clang-query/QueryParser.cpp
+++ clang-tools-extra/trunk/clang-query/QueryParser.cpp
@@ -142,7 +142,12 @@
   PQK_Quit
 };
 
-enum ParsedQueryVariable { PQV_Invalid, PQV_Output, PQV_BindRoot };
+enum ParsedQueryVariable {
+  PQV_Invalid,
+  PQV_Output,
+  PQV_BindRoot,
+  PQV_PrintMatcher
+};
 
 QueryRef makeInvalidQueryFromDiagnostics(const Diagnostics ) {
   std::string ErrStr;
@@ -214,21 +219,23 @@
   return completeMatcherExpression();
 
 Diagnostics Diag;
+auto MatcherSource = StringRef(Begin, End - Begin).trim();
 Optional Matcher = Parser::parseMatcherExpression(
-StringRef(Begin, End - Begin), nullptr, , );
+MatcherSource, nullptr, , );
 if (!Matcher) {
   return makeInvalidQueryFromDiagnostics(Diag);
 }
-return new MatchQuery(*Matcher);
+return new MatchQuery(MatcherSource, *Matcher);
   }
 
   case PQK_Set: {
 StringRef VarStr;
-ParsedQueryVariable Var = LexOrCompleteWord(this,
- VarStr)
-  .Case("output", PQV_Output)
-  .Case("bind-root", PQV_BindRoot)
-  .Default(PQV_Invalid);
+ParsedQueryVariable Var =
+LexOrCompleteWord(this, VarStr)
+.Case("output", PQV_Output)
+.Case("bind-root", PQV_BindRoot)
+.Case("print-matcher", PQV_PrintMatcher)
+.Default(PQV_Invalid);
 if (VarStr.empty())
   return new InvalidQuery("expected variable name");
 if (Var == PQV_Invalid)
@@ -242,6 +249,9 @@
 case PQV_BindRoot:
   Q = parseSetBool(::BindRoot);
   break;
+case PQV_PrintMatcher:
+  Q = parseSetBool(::PrintMatcher);
+  break;
 case PQV_Invalid:
   llvm_unreachable("Invalid query kind");
 }
Index: clang-tools-extra/trunk/clang-query/QuerySession.h
===
--- clang-tools-extra/trunk/clang-query/QuerySession.h
+++ clang-tools-extra/trunk/clang-query/QuerySession.h
@@ -25,11 +25,13 @@
 class QuerySession {
 public:
   QuerySession(llvm::ArrayRef> ASTs)
-  : ASTs(ASTs), OutKind(OK_Diag), BindRoot(true), Terminate(false) {}
+  : ASTs(ASTs), OutKind(OK_Diag), BindRoot(true), PrintMatcher(false),
+Terminate(false) {}
 
   llvm::ArrayRef> ASTs;
   OutputKind OutKind;
   bool BindRoot;
+  bool PrintMatcher;
   bool Terminate;
   llvm::StringMap NamedValues;
 };
Index: clang-tools-extra/trunk/clang-query/Query.h
===
--- clang-tools-extra/trunk/clang-query/Query.h
+++ clang-tools-extra/trunk/clang-query/Query.h
@@ -83,12 +83,15 @@
 
 /// Query for "match MATCHER".
 struct MatchQuery : Query {
-  MatchQuery(const ast_matchers::dynamic::DynTypedMatcher )
-  : Query(QK_Match), Matcher(Matcher) {}
+  MatchQuery(StringRef Source,
+ const ast_matchers::dynamic::DynTypedMatcher )
+  : Query(QK_Match), Matcher(Matcher), Source(Source) {}
   bool run(llvm::raw_ostream , QuerySession ) const override;
 
   ast_matchers::dynamic::DynTypedMatcher Matcher;
 
+  StringRef Source;
+
   static bool classof(const Query *Q) { return Q->Kind == QK_Match; }
 };
 
Index: clang-tools-extra/trunk/clang-query/Query.cpp
===
--- clang-tools-extra/trunk/clang-query/Query.cpp
+++ clang-tools-extra/trunk/clang-query/Query.cpp
@@ -41,6 +41,8 @@
 "as part of other expressions.\n"
 "  set bind-root (true|false)"
 "Set whether to bind the root matcher to \"root\".\n"
+"  set print-matcher (true|false)"
+"Set whether to print the current matcher,\n"
 "  set output (diag|print|dump)  "
 "Set whether to print bindings as diagnostics,\n"
 ""
@@ -86,6 +88,12 @@
 }
 Finder.matchAST(AST->getASTContext());
 
+if (QS.PrintMatcher) {
+  std::string prefixText = "Matcher: ";
+  OS << "\n  " << prefixText << Source << "\n";
+  OS << "  " << std::string(prefixText.size() + Source.size(), '=') 

[clang-tools-extra] r344840 - [clang-query] Add option to print matcher expression

2018-10-20 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Sat Oct 20 02:13:59 2018
New Revision: 344840

URL: http://llvm.org/viewvc/llvm-project?rev=344840=rev
Log:
[clang-query] Add option to print matcher expression

Summary:
This is useful if using clang-query -f with a file containing multiple
matchers.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-query/Query.cpp
clang-tools-extra/trunk/clang-query/Query.h
clang-tools-extra/trunk/clang-query/QueryParser.cpp
clang-tools-extra/trunk/clang-query/QuerySession.h
clang-tools-extra/trunk/unittests/clang-query/QueryEngineTest.cpp

Modified: clang-tools-extra/trunk/clang-query/Query.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/Query.cpp?rev=344840=344839=344840=diff
==
--- clang-tools-extra/trunk/clang-query/Query.cpp (original)
+++ clang-tools-extra/trunk/clang-query/Query.cpp Sat Oct 20 02:13:59 2018
@@ -41,6 +41,8 @@ bool HelpQuery::run(llvm::raw_ostream 
 "as part of other expressions.\n"
 "  set bind-root (true|false)"
 "Set whether to bind the root matcher to \"root\".\n"
+"  set print-matcher (true|false)"
+"Set whether to print the current matcher,\n"
 "  set output (diag|print|dump)  "
 "Set whether to print bindings as diagnostics,\n"
 ""
@@ -86,6 +88,12 @@ bool MatchQuery::run(llvm::raw_ostream &
 }
 Finder.matchAST(AST->getASTContext());
 
+if (QS.PrintMatcher) {
+  std::string prefixText = "Matcher: ";
+  OS << "\n  " << prefixText << Source << "\n";
+  OS << "  " << std::string(prefixText.size() + Source.size(), '=') << 
'\n';
+}
+
 for (auto MI = Matches.begin(), ME = Matches.end(); MI != ME; ++MI) {
   OS << "\nMatch #" << ++MatchCount << ":\n\n";
 

Modified: clang-tools-extra/trunk/clang-query/Query.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/Query.h?rev=344840=344839=344840=diff
==
--- clang-tools-extra/trunk/clang-query/Query.h (original)
+++ clang-tools-extra/trunk/clang-query/Query.h Sat Oct 20 02:13:59 2018
@@ -83,12 +83,15 @@ struct QuitQuery : Query {
 
 /// Query for "match MATCHER".
 struct MatchQuery : Query {
-  MatchQuery(const ast_matchers::dynamic::DynTypedMatcher )
-  : Query(QK_Match), Matcher(Matcher) {}
+  MatchQuery(StringRef Source,
+ const ast_matchers::dynamic::DynTypedMatcher )
+  : Query(QK_Match), Matcher(Matcher), Source(Source) {}
   bool run(llvm::raw_ostream , QuerySession ) const override;
 
   ast_matchers::dynamic::DynTypedMatcher Matcher;
 
+  StringRef Source;
+
   static bool classof(const Query *Q) { return Q->Kind == QK_Match; }
 };
 

Modified: clang-tools-extra/trunk/clang-query/QueryParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/QueryParser.cpp?rev=344840=344839=344840=diff
==
--- clang-tools-extra/trunk/clang-query/QueryParser.cpp (original)
+++ clang-tools-extra/trunk/clang-query/QueryParser.cpp Sat Oct 20 02:13:59 2018
@@ -142,7 +142,12 @@ enum ParsedQueryKind {
   PQK_Quit
 };
 
-enum ParsedQueryVariable { PQV_Invalid, PQV_Output, PQV_BindRoot };
+enum ParsedQueryVariable {
+  PQV_Invalid,
+  PQV_Output,
+  PQV_BindRoot,
+  PQV_PrintMatcher
+};
 
 QueryRef makeInvalidQueryFromDiagnostics(const Diagnostics ) {
   std::string ErrStr;
@@ -214,21 +219,23 @@ QueryRef QueryParser::doParse() {
   return completeMatcherExpression();
 
 Diagnostics Diag;
+auto MatcherSource = StringRef(Begin, End - Begin).trim();
 Optional Matcher = Parser::parseMatcherExpression(
-StringRef(Begin, End - Begin), nullptr, , );
+MatcherSource, nullptr, , );
 if (!Matcher) {
   return makeInvalidQueryFromDiagnostics(Diag);
 }
-return new MatchQuery(*Matcher);
+return new MatchQuery(MatcherSource, *Matcher);
   }
 
   case PQK_Set: {
 StringRef VarStr;
-ParsedQueryVariable Var = LexOrCompleteWord(this,
- VarStr)
-  .Case("output", PQV_Output)
-  .Case("bind-root", PQV_BindRoot)
-  .Default(PQV_Invalid);
+ParsedQueryVariable Var =
+LexOrCompleteWord(this, VarStr)
+.Case("output", PQV_Output)
+.Case("bind-root", PQV_BindRoot)
+.Case("print-matcher", PQV_PrintMatcher)
+.Default(PQV_Invalid);
 if (VarStr.empty())
   return new InvalidQuery("expected variable name");
 if (Var == PQV_Invalid)
@@ -242,6 +249,9 @@ QueryRef QueryParser::doParse() {
 

[PATCH] D52857: Deprecate 'set output foo' API of clang-query

2018-10-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 170306.
steveire added a comment.

Fix test


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52857

Files:
  clang-query/Query.cpp
  clang-query/Query.h
  clang-query/QueryParser.cpp
  clang-query/QuerySession.h
  unittests/clang-query/QueryEngineTest.cpp
  unittests/clang-query/QueryParserTest.cpp

Index: unittests/clang-query/QueryParserTest.cpp
===
--- unittests/clang-query/QueryParserTest.cpp
+++ unittests/clang-query/QueryParserTest.cpp
@@ -59,6 +59,35 @@
   EXPECT_EQ("unexpected extra input: ' me'", cast(Q)->ErrStr);
 }
 
+TEST_F(QueryParserTest, Deprecated) {
+  QueryRef Q = parse("set output");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+cast(Q)->ErrStr);
+
+  Q = parse("set output foo");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+cast(Q)->ErrStr);
+
+  Q = parse("set output dump");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ(::DumpOutput, cast(Q)->Var);
+  std::string Str;
+  llvm::raw_string_ostream OS(Str);
+  Q->run(OS, QS);
+  EXPECT_EQ(true, QS.DumpOutput);
+  EXPECT_EQ(false, QS.DiagOutput);
+  EXPECT_EQ(false, QS.PrintOutput);
+
+  std::vector Comps =
+  QueryParser::complete("", 0, QS);
+  Comps = QueryParser::complete("set o", 5, QS);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("utput ", Comps[0].TypedText);
+  EXPECT_EQ("output", Comps[0].DisplayText);
+}
+
 TEST_F(QueryParserTest, Set) {
   QueryRef Q = parse("set");
   ASSERT_TRUE(isa(Q));
@@ -68,24 +97,24 @@
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unknown variable: 'foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output");
+  Q = parse("set ast-output");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+  EXPECT_EQ("expected 'true' or 'false', got ''",
 cast(Q)->ErrStr);
 
   Q = parse("set bind-root true foo");
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unexpected extra input: ' foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output foo");
+  Q = parse("set ast-output foo");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+  EXPECT_EQ("expected 'true' or 'false', got 'foo'",
 cast(Q)->ErrStr);
 
-  Q = parse("set output dump");
-  ASSERT_TRUE(isa >(Q));
-  EXPECT_EQ(::OutKind, cast >(Q)->Var);
-  EXPECT_EQ(OK_Dump, cast >(Q)->Value);
+  Q = parse("set ast-output true");
+  ASSERT_TRUE(isa>(Q));
+  EXPECT_EQ(::DumpOutput, cast>(Q)->Var);
+  EXPECT_EQ(true, cast>(Q)->Value);
 
   Q = parse("set bind-root foo");
   ASSERT_TRUE(isa(Q));
@@ -174,10 +203,14 @@
   EXPECT_EQ("unlet ", Comps[5].TypedText);
   EXPECT_EQ("unlet", Comps[5].DisplayText);
 
-  Comps = QueryParser::complete("set o", 5, QS);
+  Comps = QueryParser::complete("set d", 5, QS);
   ASSERT_EQ(1u, Comps.size());
-  EXPECT_EQ("utput ", Comps[0].TypedText);
-  EXPECT_EQ("output", Comps[0].DisplayText);
+  EXPECT_EQ("iag-output ", Comps[1].TypedText);
+  EXPECT_EQ("diag-output", Comps[1].DisplayText);
+  Comps = QueryParser::complete("set a", 6, QS);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("st-output ", Comps[0].TypedText);
+  EXPECT_EQ("ast-output", Comps[0].DisplayText);
 
   Comps = QueryParser::complete("match while", 11, QS);
   ASSERT_EQ(1u, Comps.size());
Index: unittests/clang-query/QueryEngineTest.cpp
===
--- unittests/clang-query/QueryEngineTest.cpp
+++ unittests/clang-query/QueryEngineTest.cpp
@@ -48,6 +48,24 @@
   llvm::raw_string_ostream OS;
 };
 
+TEST_F(QueryEngineTest, Deprecated) {
+  DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
+
+  EXPECT_TRUE(SetOutputQuery(::PrintOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
+
+  EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
+  std::string::npos);
+
+  Str.clear();
+
+  EXPECT_TRUE(SetOutputQuery(::ASTOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
+  EXPECT_TRUE(OS.str().find("FunctionDecl") != std::string::npos);
+
+  Str.clear();
+}
+
 TEST_F(QueryEngineTest, Basic) {
   DynTypedMatcher FnMatcher = functionDecl();
   DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
@@ -92,22 +110,36 @@
 
   Str.clear();
 
-  EXPECT_TRUE(
-  SetQuery(::OutKind, OK_Print).run(OS, S));
+  EXPECT_TRUE(SetQuery(::DiagOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, true).run(OS, S));
   EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
 
   EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
   std::string::npos);
 
   Str.clear();
 
-  EXPECT_TRUE(SetQuery(::OutKind, OK_Dump).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::ASTOutput, true).run(OS, S));
   EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
 
   EXPECT_TRUE(OS.str().find("FunctionDecl") != 

[PATCH] D52857: Deprecate 'set output foo' API of clang-query

2018-10-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 170305.
steveire added a comment.

Fix tests


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52857

Files:
  clang-query/Query.cpp
  clang-query/Query.h
  clang-query/QueryParser.cpp
  clang-query/QuerySession.h
  unittests/clang-query/QueryEngineTest.cpp
  unittests/clang-query/QueryParserTest.cpp

Index: unittests/clang-query/QueryParserTest.cpp
===
--- unittests/clang-query/QueryParserTest.cpp
+++ unittests/clang-query/QueryParserTest.cpp
@@ -59,6 +59,35 @@
   EXPECT_EQ("unexpected extra input: ' me'", cast(Q)->ErrStr);
 }
 
+TEST_F(QueryParserTest, Deprecated) {
+  QueryRef Q = parse("set output");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+cast(Q)->ErrStr);
+
+  Q = parse("set output foo");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+cast(Q)->ErrStr);
+
+  Q = parse("set output dump");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ(::DumpOutput, cast(Q)->Var);
+  std::string Str;
+  llvm::raw_string_ostream OS(Str);
+  Q->run(OS, QS);
+  EXPECT_EQ(true, QS.DumpOutput);
+  EXPECT_EQ(false, QS.DiagOutput);
+  EXPECT_EQ(false, QS.PrintOutput);
+
+  std::vector Comps =
+  QueryParser::complete("", 0, QS);
+  Comps = QueryParser::complete("set o", 5, QS);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("utput ", Comps[0].TypedText);
+  EXPECT_EQ("output", Comps[0].DisplayText);
+}
+
 TEST_F(QueryParserTest, Set) {
   QueryRef Q = parse("set");
   ASSERT_TRUE(isa(Q));
@@ -68,24 +97,24 @@
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unknown variable: 'foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output");
+  Q = parse("set ast-output");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+  EXPECT_EQ("expected 'true' or 'false', got ''",
 cast(Q)->ErrStr);
 
   Q = parse("set bind-root true foo");
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unexpected extra input: ' foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output foo");
+  Q = parse("set ast-output foo");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+  EXPECT_EQ("expected 'true' or 'false', got 'foo'",
 cast(Q)->ErrStr);
 
-  Q = parse("set output dump");
-  ASSERT_TRUE(isa >(Q));
-  EXPECT_EQ(::OutKind, cast >(Q)->Var);
-  EXPECT_EQ(OK_Dump, cast >(Q)->Value);
+  Q = parse("set ast-output true");
+  ASSERT_TRUE(isa>(Q));
+  EXPECT_EQ(::DumpOutput, cast>(Q)->Var);
+  EXPECT_EQ(true, cast>(Q)->Value);
 
   Q = parse("set bind-root foo");
   ASSERT_TRUE(isa(Q));
@@ -174,10 +203,16 @@
   EXPECT_EQ("unlet ", Comps[5].TypedText);
   EXPECT_EQ("unlet", Comps[5].DisplayText);
 
-  Comps = QueryParser::complete("set o", 5, QS);
+  Comps = QueryParser::complete("set d", 5, QS);
+  ASSERT_EQ(2u, Comps.size());
+  EXPECT_EQ("ump-output ", Comps[0].TypedText);
+  EXPECT_EQ("ast-output", Comps[0].DisplayText);
+  EXPECT_EQ("iag-output ", Comps[1].TypedText);
+  EXPECT_EQ("diag-output", Comps[1].DisplayText);
+  Comps = QueryParser::complete("set du", 6, QS);
   ASSERT_EQ(1u, Comps.size());
-  EXPECT_EQ("utput ", Comps[0].TypedText);
-  EXPECT_EQ("output", Comps[0].DisplayText);
+  EXPECT_EQ("mp-output ", Comps[0].TypedText);
+  EXPECT_EQ("ast-output", Comps[0].DisplayText);
 
   Comps = QueryParser::complete("match while", 11, QS);
   ASSERT_EQ(1u, Comps.size());
Index: unittests/clang-query/QueryEngineTest.cpp
===
--- unittests/clang-query/QueryEngineTest.cpp
+++ unittests/clang-query/QueryEngineTest.cpp
@@ -48,6 +48,24 @@
   llvm::raw_string_ostream OS;
 };
 
+TEST_F(QueryEngineTest, Deprecated) {
+  DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
+
+  EXPECT_TRUE(SetOutputQuery(::PrintOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
+
+  EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
+  std::string::npos);
+
+  Str.clear();
+
+  EXPECT_TRUE(SetOutputQuery(::ASTOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
+  EXPECT_TRUE(OS.str().find("FunctionDecl") != std::string::npos);
+
+  Str.clear();
+}
+
 TEST_F(QueryEngineTest, Basic) {
   DynTypedMatcher FnMatcher = functionDecl();
   DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
@@ -92,22 +110,36 @@
 
   Str.clear();
 
-  EXPECT_TRUE(
-  SetQuery(::OutKind, OK_Print).run(OS, S));
+  EXPECT_TRUE(SetQuery(::DiagOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, true).run(OS, S));
   EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
 
   EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
   std::string::npos);
 
   Str.clear();
 
-  EXPECT_TRUE(SetQuery(::OutKind, OK_Dump).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::ASTOutput, true).run(OS, S));
   

[PATCH] D52857: Deprecate 'set output foo' API of clang-query

2018-10-20 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 170304.
steveire added a comment.

Rename dump-output to ast-output.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52857

Files:
  clang-query/Query.cpp
  clang-query/Query.h
  clang-query/QueryParser.cpp
  clang-query/QuerySession.h
  unittests/clang-query/QueryEngineTest.cpp
  unittests/clang-query/QueryParserTest.cpp

Index: unittests/clang-query/QueryParserTest.cpp
===
--- unittests/clang-query/QueryParserTest.cpp
+++ unittests/clang-query/QueryParserTest.cpp
@@ -59,6 +59,35 @@
   EXPECT_EQ("unexpected extra input: ' me'", cast(Q)->ErrStr);
 }
 
+TEST_F(QueryParserTest, Deprecated) {
+  QueryRef Q = parse("set output");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+cast(Q)->ErrStr);
+
+  Q = parse("set output foo");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+cast(Q)->ErrStr);
+
+  Q = parse("set output dump");
+  ASSERT_TRUE(isa(Q));
+  EXPECT_EQ(::DumpOutput, cast(Q)->Var);
+  std::string Str;
+  llvm::raw_string_ostream OS(Str);
+  Q->run(OS, QS);
+  EXPECT_EQ(true, QS.DumpOutput);
+  EXPECT_EQ(false, QS.DiagOutput);
+  EXPECT_EQ(false, QS.PrintOutput);
+
+  std::vector Comps =
+  QueryParser::complete("", 0, QS);
+  Comps = QueryParser::complete("set o", 5, QS);
+  ASSERT_EQ(1u, Comps.size());
+  EXPECT_EQ("utput ", Comps[0].TypedText);
+  EXPECT_EQ("output", Comps[0].DisplayText);
+}
+
 TEST_F(QueryParserTest, Set) {
   QueryRef Q = parse("set");
   ASSERT_TRUE(isa(Q));
@@ -68,24 +97,24 @@
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unknown variable: 'foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output");
+  Q = parse("set dump-output");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got ''",
+  EXPECT_EQ("expected 'true' or 'false', got ''",
 cast(Q)->ErrStr);
 
   Q = parse("set bind-root true foo");
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("unexpected extra input: ' foo'", cast(Q)->ErrStr);
 
-  Q = parse("set output foo");
+  Q = parse("set dump-output foo");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print' or 'dump', got 'foo'",
+  EXPECT_EQ("expected 'true' or 'false', got 'foo'",
 cast(Q)->ErrStr);
 
-  Q = parse("set output dump");
-  ASSERT_TRUE(isa >(Q));
-  EXPECT_EQ(::OutKind, cast >(Q)->Var);
-  EXPECT_EQ(OK_Dump, cast >(Q)->Value);
+  Q = parse("set dump-output true");
+  ASSERT_TRUE(isa>(Q));
+  EXPECT_EQ(::DumpOutput, cast>(Q)->Var);
+  EXPECT_EQ(true, cast>(Q)->Value);
 
   Q = parse("set bind-root foo");
   ASSERT_TRUE(isa(Q));
@@ -174,10 +203,16 @@
   EXPECT_EQ("unlet ", Comps[5].TypedText);
   EXPECT_EQ("unlet", Comps[5].DisplayText);
 
-  Comps = QueryParser::complete("set o", 5, QS);
+  Comps = QueryParser::complete("set d", 5, QS);
+  ASSERT_EQ(2u, Comps.size());
+  EXPECT_EQ("ump-output ", Comps[0].TypedText);
+  EXPECT_EQ("dump-output", Comps[0].DisplayText);
+  EXPECT_EQ("iag-output ", Comps[1].TypedText);
+  EXPECT_EQ("diag-output", Comps[1].DisplayText);
+  Comps = QueryParser::complete("set du", 6, QS);
   ASSERT_EQ(1u, Comps.size());
-  EXPECT_EQ("utput ", Comps[0].TypedText);
-  EXPECT_EQ("output", Comps[0].DisplayText);
+  EXPECT_EQ("mp-output ", Comps[0].TypedText);
+  EXPECT_EQ("dump-output", Comps[0].DisplayText);
 
   Comps = QueryParser::complete("match while", 11, QS);
   ASSERT_EQ(1u, Comps.size());
Index: unittests/clang-query/QueryEngineTest.cpp
===
--- unittests/clang-query/QueryEngineTest.cpp
+++ unittests/clang-query/QueryEngineTest.cpp
@@ -48,6 +48,24 @@
   llvm::raw_string_ostream OS;
 };
 
+TEST_F(QueryEngineTest, Deprecated) {
+  DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
+
+  EXPECT_TRUE(SetOutputQuery(::PrintOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
+
+  EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
+  std::string::npos);
+
+  Str.clear();
+
+  EXPECT_TRUE(SetOutputQuery(::DumpOutput).run(OS, S));
+  EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
+  EXPECT_TRUE(OS.str().find("FunctionDecl") != std::string::npos);
+
+  Str.clear();
+}
+
 TEST_F(QueryEngineTest, Basic) {
   DynTypedMatcher FnMatcher = functionDecl();
   DynTypedMatcher FooMatcher = functionDecl(hasName("foo1"));
@@ -92,22 +110,36 @@
 
   Str.clear();
 
-  EXPECT_TRUE(
-  SetQuery(::OutKind, OK_Print).run(OS, S));
+  EXPECT_TRUE(SetQuery(::DiagOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, true).run(OS, S));
   EXPECT_TRUE(MatchQuery(FooMatcher).run(OS, S));
 
   EXPECT_TRUE(OS.str().find("Binding for \"root\":\nvoid foo1()") !=
   std::string::npos);
 
   Str.clear();
 
-  EXPECT_TRUE(SetQuery(::OutKind, OK_Dump).run(OS, S));
+  EXPECT_TRUE(SetQuery(::PrintOutput, false).run(OS, S));
+  EXPECT_TRUE(SetQuery(::DumpOutput, 

[PATCH] D53200: [OpenCL] Fix serialization of OpenCLExtensionDecls

2018-10-20 Thread Alexey Sachkov via Phabricator via cfe-commits
AlexeySachkov added inline comments.



Comment at: test/Headers/opencl-pragma-extension-begin.cl:1
+// RUN: rm -rf %t
+// RUN: mkdir -p %t

Anastasia wrote:
> I think the tests in this folder are for standard includes only but you are 
> testing custom include file here.
> 
> Could this be integrated into test/SemaOpenCL/extension-begin.cl? Or if else 
> you could just move to that folder (it might be better to append module to 
> the name in that case).
> I think the tests in this folder are for standard includes only but you are 
> testing custom include file here.

Currently, standard include file doesn't contain begin/end ocl pragma 
directives and I decided to create a special one header for the test.

I will integrate it into existing test for extension-begin pragma.


https://reviews.llvm.org/D53200



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


[PATCH] D53329: Generate DIFile with main program if source is not available

2018-10-20 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

Sure. Let me provide a little bit more context and what I want to achieve:

  . I have a tool, called bcc (https://github.com/iovisor/bcc) which uses clang 
CompilerInvocation interface and
MCJIT to generates BPF code and load into kernel
  . Several files (the main.c and a few others headers) are clang memory mapped.
  . The particular fix here is related to https://reviews.llvm.org/D53261, 
getting source code into BTF, but
before that, based on that particular implementation, the source code needs 
to be in IR.
What I found is that for the memory mapped /virtual/main.c file, there is 
one DIFile entry in
generated IR, the associated 'source' is empty, which actually caused a seg 
fault later.
  
Not that this bug itself does not need https://reviews.llvm.org/D53261.

So without this fix, bcc tool will seg fault.
With this fix, bcc tool works properly and all DIFile entry has proper source 
codes embedded, which
if coupled with IR->BTF or Dwarf->BTF should generate correct BTF debug info.


Repository:
  rC Clang

https://reviews.llvm.org/D53329



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