[PATCH] D82739: Improve heuristic resolution of dependent types in TargetFinder

2020-07-08 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Split out the refactoring into D83371  which 
this depends on now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82739



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


[PATCH] D83371: [clangd] Factor out some helper functions related to heuristic resolution in TargetFinder

2020-07-08 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 276321.
nridge added a comment.

Improve patch split


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83371

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

Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -58,6 +58,23 @@
   return S;
 }
 
+// Helper function for getMembersReferencedViaDependentName()
+// which takes a dependent type `T` and heuristically
+// resolves it to a CXXRecordDecl in which we can try name lookup.
+CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
+  if (auto *ICNT = T->getAs()) {
+T = ICNT->getInjectedSpecializationType().getTypePtrOrNull();
+  }
+  auto *TST = T->getAs();
+  if (!TST)
+return nullptr;
+  const ClassTemplateDecl *TD = dyn_cast_or_null(
+  TST->getTemplateName().getAsTemplateDecl());
+  if (!TD)
+return nullptr;
+  return TD->getTemplatedDecl();
+}
+
 // Given a dependent type and a member name, heuristically resolve the
 // name to one or more declarations.
 // The current heuristic is simply to look up the name in the primary
@@ -82,25 +99,17 @@
 ET->getDecl()->lookup(NameFactory(ET->getDecl()->getASTContext()));
 return {Result.begin(), Result.end()};
   }
-  if (auto *ICNT = T->getAs()) {
-T = ICNT->getInjectedSpecializationType().getTypePtrOrNull();
+  if (auto *RD = resolveTypeToRecordDecl(T)) {
+if (!RD->hasDefinition())
+  return {};
+RD = RD->getDefinition();
+DeclarationName Name = NameFactory(RD->getASTContext());
+return RD->lookupDependentName(Name, [=](const NamedDecl *D) {
+  return IsNonstaticMember ? D->isCXXInstanceMember()
+   : !D->isCXXInstanceMember();
+});
   }
-  auto *TST = T->getAs();
-  if (!TST)
-return {};
-  const ClassTemplateDecl *TD = dyn_cast_or_null(
-  TST->getTemplateName().getAsTemplateDecl());
-  if (!TD)
-return {};
-  CXXRecordDecl *RD = TD->getTemplatedDecl();
-  if (!RD->hasDefinition())
-return {};
-  RD = RD->getDefinition();
-  DeclarationName Name = NameFactory(RD->getASTContext());
-  return RD->lookupDependentName(Name, [=](const NamedDecl *D) {
-return IsNonstaticMember ? D->isCXXInstanceMember()
- : !D->isCXXInstanceMember();
-  });
+  return {};
 }
 
 // Given the type T of a dependent expression that appears of the LHS of a "->",
@@ -144,6 +153,32 @@
   return FirstArg.getAsType().getTypePtrOrNull();
 }
 
+// Try to heuristically resolve a dependent expression `E` to one
+// or more declarations that it likely references.
+std::vector resolveDependentExprToDecls(const Expr *E) {
+  switch (E->getStmtClass()) {
+  case Stmt::CXXDependentScopeMemberExprClass: {
+const auto *ME = llvm::cast(E);
+const Type *BaseType = ME->getBaseType().getTypePtrOrNull();
+if (ME->isArrow()) {
+  BaseType = getPointeeType(BaseType);
+}
+return getMembersReferencedViaDependentName(
+BaseType, [ME](ASTContext &) { return ME->getMember(); },
+/*IsNonstaticMember=*/true);
+  }
+  case Stmt::DependentScopeDeclRefExprClass: {
+const auto *RE = llvm::cast(E);
+return getMembersReferencedViaDependentName(
+RE->getQualifier()->getAsType(),
+[RE](ASTContext &) { return RE->getDeclName(); },
+/*IsNonstaticMember=*/false);
+  }
+  default:
+return {};
+  }
+}
+
 const NamedDecl *getTemplatePattern(const NamedDecl *D) {
   if (const CXXRecordDecl *CRD = dyn_cast(D)) {
 if (const auto *Result = CRD->getTemplateInstantiationPattern())
@@ -341,21 +376,12 @@
   }
   void
   VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
-const Type *BaseType = E->getBaseType().getTypePtrOrNull();
-if (E->isArrow()) {
-  BaseType = getPointeeType(BaseType);
-}
-for (const NamedDecl *D : getMembersReferencedViaDependentName(
- BaseType, [E](ASTContext &) { return E->getMember(); },
- /*IsNonstaticMember=*/true)) {
+for (const NamedDecl *D : resolveDependentExprToDecls(E)) {
   Outer.add(D, Flags);
 }
   }
   void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E) {
-for (const NamedDecl *D : getMembersReferencedViaDependentName(
- E->getQualifier()->getAsType(),
- [E](ASTContext &) { return E->getDeclName(); },
- /*IsNonstaticMember=*/false)) {
+for (const NamedDecl *D : resolveDependentExprToDecls(E)) {
   Outer.add(D, Flags);
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82739: Improve heuristic resolution of dependent types in TargetFinder

2020-07-08 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 276322.
nridge added a comment.

Improve patch split


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82739

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -548,6 +548,23 @@
   EXPECT_DECLS("UnresolvedMemberExpr", "void func(int *)", "void func(char *)");
 }
 
+TEST_F(TargetDeclTest, DependentExprs) {
+  Flags = {"-fno-delayed-template-parsing"};
+
+  // Heuristic resolution of method of dependent field
+  Code = R"cpp(
+struct A { void foo() {} };
+template 
+struct B {
+  A a;
+  void bar() {
+this->a.[[foo]]();
+  }
+};
+  )cpp";
+  EXPECT_DECLS("CXXDependentScopeMemberExpr", "void foo()");
+}
+
 TEST_F(TargetDeclTest, ObjC) {
   Flags = {"-xobjective-c"};
   Code = R"cpp(
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -58,10 +58,18 @@
   return S;
 }
 
+// Forward declaration, needed as this function is mutually recursive
+// with some of the other helpers below.
+std::vector resolveDependentExprToDecls(const Expr *E);
+
 // Helper function for getMembersReferencedViaDependentName()
-// which takes a dependent type `T` and heuristically
+// which takes a possibly-dependent type `T` and heuristically
 // resolves it to a CXXRecordDecl in which we can try name lookup.
 CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
+  if (auto *RT = T->getAs()) {
+return dyn_cast(RT->getDecl());
+  }
+
   if (auto *ICNT = T->getAs()) {
 T = ICNT->getInjectedSpecializationType().getTypePtrOrNull();
   }
@@ -75,6 +83,19 @@
   return TD->getTemplatedDecl();
 }
 
+// Try to heuristically resolve the type of a dependent expression `E`.
+const Type *resolveDependentExprToType(const Expr *E) {
+  std::vector Decls = resolveDependentExprToDecls(E);
+  if (Decls.size() != 1) // Names an overload set -- just bail.
+return nullptr;
+  if (const auto *TD = dyn_cast(Decls[0])) {
+return TD->getTypeForDecl();
+  } else if (const auto *VD = dyn_cast(Decls[0])) {
+return VD->getType().getTypePtrOrNull();
+  }
+  return nullptr;
+}
+
 // Given a dependent type and a member name, heuristically resolve the
 // name to one or more declarations.
 // The current heuristic is simply to look up the name in the primary
@@ -88,12 +109,27 @@
 // an ASTContext, because an ASTContext may be needed to obtain the
 // name (e.g. if it's an operator name), but the caller may not have
 // access to an ASTContext.
+// Optionally, in cases where the type represents the type of a
+// dependent expression, the expression `E` in question can be
+// provided, which allows us to provide richer heuristics by
+// introspecting the expression and trying to reason about its type.
 std::vector getMembersReferencedViaDependentName(
-const Type *T,
+Expr *E, const Type *T,
 llvm::function_ref NameFactory,
 bool IsNonstaticMember) {
   if (!T)
 return {};
+  if (auto *BT = T->getAs()) {
+// If T is the type of a dependent expression, it's just represented
+// as BultinType::Dependent which gives us no information. If the
+// caller provides the expression `E`, we can get further by
+// analyzing it.
+if (E && BT->getKind() == BuiltinType::Dependent) {
+  T = resolveDependentExprToType(E);
+  if (!T)
+return {};
+}
+  }
   if (auto *ET = T->getAs()) {
 auto Result =
 ET->getDecl()->lookup(NameFactory(ET->getDecl()->getASTContext()));
@@ -128,7 +164,7 @@
   // Look up operator-> in the primary template. If we find one, it's probably a
   // smart pointer type.
   auto ArrowOps = getMembersReferencedViaDependentName(
-  T,
+  nullptr, T,
   [](ASTContext &Ctx) {
 return Ctx.DeclarationNames.getCXXOperatorName(OO_Arrow);
   },
@@ -163,14 +199,15 @@
 if (ME->isArrow()) {
   BaseType = getPointeeType(BaseType);
 }
+Expr *Base = ME->isImplicitAccess() ? nullptr : ME->getBase();
 return getMembersReferencedViaDependentName(
-BaseType, [ME](ASTContext &) { return ME->getMember(); },
+Base, BaseType, [ME](ASTContext &) { return ME->getMember(); },
 /*IsNonstaticMember=*/true);
   }
   case Stmt::DependentScopeDeclRefExprClass: {
 const auto *RE = llvm::cast(E);
 return getMembersReferencedViaDependentName(
-RE->getQualifier()->getAsType(),
+nullptr, RE->getQualifier()->getAsType(),
 [RE](ASTContext &) { return RE->getDeclName(); },

[PATCH] D82805: [clang] Fix a crash on passing C structure of incompatible type to function with reference parameter

2020-07-08 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82805



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


[PATCH] D79773: [clang-format] Improve clang-formats handling of concepts

2020-07-08 Thread Johel Ernesto Guerrero Peña via Phabricator via cfe-commits
JohelEGP added a comment.

Ah, that makes sense. The very definition of Allman is to always break before 
braces. I suppose I'll need to use `BreakBeforeBraces: Custom` and 
`BraceWrapping:`. I did some testing and noticed that the weird format comes 
with any of these:

  BreakBeforeBraces: Custom
  BraceWrapping:
AfterControlStatement: MultiLine

  BreakBeforeBraces: Custom
  BraceWrapping:
AfterFunction: true

Since a requires-expression is neither a control statement nor a function, I 
suppose it might eventually need its own `BraceWrapping` nested configuration 
flag. For now, I'd prefer if they never break.


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

https://reviews.llvm.org/D79773



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


[PATCH] D83201: [AST][RecoveryExpr] Fix the value category for recovery expr.

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 276325.
hokein marked an inline comment as done.
hokein added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83201

Files:
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp

Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -62,3 +62,8 @@
  // expected-note {{in instantiation of member function}} \
  // expected-note {{in call to}}
 }
+
+namespace test4 {
+int &&f(int);  // expected-note {{candidate function not viable}}
+int &&k = f(); // expected-error {{no matching function for call}}
+}
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -4,7 +4,6 @@
 int some_func(int *);
 
 // CHECK: VarDecl {{.*}} invalid_call
-// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:|-UnresolvedLookupExpr {{.*}} 'some_func'
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
@@ -34,7 +33,6 @@
 int ambig_func(float);
 
 // CHECK: VarDecl {{.*}} ambig_call
-// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:|-UnresolvedLookupExpr {{.*}} 'ambig_func'
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
@@ -211,3 +209,16 @@
 } NoCrashOnInvalidInitList = {
   .abc = nullptr,
 };
+
+// Verify the value category of recovery expression.
+int prvalue(int);
+int& lvalue(int);
+int&& xvalue(int);
+void ValueCategory() {
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors
+  prvalue(); // call to a function (nonreference return type) yields a prvalue (not print by default)
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors lvalue
+  lvalue(); // call to a function (lvalue reference return type) yields an lvalue.
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors xvalue
+  xvalue(); // call to a function (rvalue reference return type) yields an xvalue.
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -12818,7 +12818,7 @@
   auto ConsiderCandidate = [&](const OverloadCandidate &Candidate) {
 if (!Candidate.Function)
   return;
-QualType T = Candidate.Function->getCallResultType();
+QualType T = Candidate.Function->getReturnType();
 if (T.isNull())
   return;
 if (!Result)
Index: clang/lib/AST/ExprClassification.cpp
===
--- clang/lib/AST/ExprClassification.cpp
+++ clang/lib/AST/ExprClassification.cpp
@@ -130,7 +130,6 @@
   case Expr::UnresolvedLookupExprClass:
   case Expr::UnresolvedMemberExprClass:
   case Expr::TypoExprClass:
-  case Expr::RecoveryExprClass:
   case Expr::DependentCoawaitExprClass:
   case Expr::CXXDependentScopeMemberExprClass:
   case Expr::DependentScopeDeclRefExprClass:
@@ -145,6 +144,9 @@
   case Expr::OMPIteratorExprClass:
 return Cl::CL_LValue;
 
+  case Expr::RecoveryExprClass:
+return ClassifyExprValueKind(Lang, E, E->getValueKind());
+
 // C99 6.5.2.5p5 says that compound literals are lvalues.
 // In C++, they're prvalue temporaries, except for file-scope arrays.
   case Expr::CompoundLiteralExprClass:
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4779,8 +4779,10 @@
 
 RecoveryExpr::RecoveryExpr(ASTContext &Ctx, QualType T, SourceLocation BeginLoc,
SourceLocation EndLoc, ArrayRef SubExprs)
-: Expr(RecoveryExprClass, T, VK_LValue, OK_Ordinary), BeginLoc(BeginLoc),
-  EndLoc(EndLoc), NumExprs(SubExprs.size()) {
+: Expr(RecoveryExprClass, T.getNonReferenceType(),
+   T->isDependentType() ? VK_LValue : getValueKindForType(T),
+   OK_Ordinary),
+  BeginLoc(BeginLoc), EndLoc(EndLoc), NumExprs(SubExprs.size()) {
   assert(!T.isNull());
   assert(llvm::all_of(SubExprs, [](Expr* E) { return E != nullptr; }));
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83201: [AST][RecoveryExpr] Fix the value category for recovery expr.

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:12944
+  Fn->getBeginLoc(), RParenLoc, SubExprs,
+  ReturnType.isNull()
+  ? ReturnType

sammccall wrote:
> here we're splitting the type (e.g. int&&) into a type + VK, and passing both 
> to createrecoveryexpr.
> 
> Why not do that on recoveryexpr side? e.g. if we request a recoveryexpr of 
> type int&, return an LValue recoveryexpr of type int?
right, good idea, this is simpler. I was somehow taking `CallExpr` as a 
reference when writing this code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83201



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


[PATCH] D83233: [clangd] Enable reading config from files by default.

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.

looks like you didn't upload the latest version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83233



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


[PATCH] D83079: [clang][aarch64] Generate preprocessor macros for -march=armv8.6a+sve.

2020-07-08 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:369
+  if (llvm::is_contained(Features, "+v8.6a")) {
+if (!llvm::is_contained(Features, "-i8mm") &&
+!llvm::is_contained(Features, "+noi8mm"))

Is this correct and/or necessary? I would expect LLVM to just handle features 
in the order they're passed, and the architecture version is always processed 
first, e.g. `-march=armv8.6-a+noi8mm` will always first process `armv8.6a` 
before processing features like `noi8mm`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83079



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


[PATCH] D81315: [analyzer] Warning for default constructed unique pointer dereferences

2020-07-08 Thread Nithin VR via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG20e271a98de5: [analyzer] Warning for default constructed 
unique_ptr dereference (authored by vrnithinkumar).

Changed prior to commit:
  https://reviews.llvm.org/D81315?vs=275434&id=276327#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81315

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/smart-ptr.cpp
  clang/test/Analysis/use-after-move.cpp

Index: clang/test/Analysis/use-after-move.cpp
===
--- clang/test/Analysis/use-after-move.cpp
+++ clang/test/Analysis/use-after-move.cpp
@@ -1,36 +1,36 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=All\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=All\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,aggressive
 
 // RUN: not %clang_analyze_cc1 -verify %s \
@@ -49,7 +49,7 @@
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=All -DAGGRESSIVE_DFS\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,aggressive %s 2>&1 | FileCheck %s
 
 #include "Inputs/system-header-simulator-cxx.h"
Index: clang/test/Analysis/smart-ptr.cpp
===
--- clang/test/Analysis/smart-ptr.cpp
+++ clang/test/Analysis/smart-ptr.cpp
@@ -1,16 +1,18 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection\
-// RUN:   -analyzer-checker cplusplus.Move,cplusplus.SmartPtr\
+// RUN:   -analyzer-checker cplusplus.Move,alpha.cplusplus.SmartPtr\
+// RUN:   -analyzer-config cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
 // RUN:   -std=c++1

[clang] 20e271a - [analyzer] Warning for default constructed unique_ptr dereference

2020-07-08 Thread Nithin Vadukkumchery Rajendrakumar via cfe-commits

Author: Nithin Vadukkumchery Rajendrakumar
Date: 2020-07-08T09:51:02+02:00
New Revision: 20e271a98de5609e22766e56f9c374b150f06982

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

LOG: [analyzer] Warning for default constructed unique_ptr dereference

Summary: Add support for warning incase of default constructed unique pointer 
dereferences

Reviewed By: NoQ, Szelethus, vsavchenko, xazax.hun

Tags: #clang

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

Added: 
clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp

Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
clang/test/Analysis/Inputs/system-header-simulator-cxx.h
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/smart-ptr.cpp
clang/test/Analysis/use-after-move.cpp

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index d14bd2d68af9..1583da7aff09 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1836,6 +1836,19 @@ Check unreachable code.
[x retain]; // warn
  }
 
+.. _alpha-cplusplus-SmartPtr:
+
+alpha.cplusplus.SmartPtr (C++)
+""
+Check for dereference of null smart pointers.
+
+.. code-block:: cpp
+
+ void deref_smart_ptr() {
+   std::unique_ptr P;
+   *P; // warn: dereference of a default constructed smart unique_ptr
+ }
+
 alpha.llvm
 ^^
 

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index dc1269890f93..cbd925400328 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -577,9 +577,17 @@ def CXXSelfAssignmentChecker : Checker<"SelfAssignment">,
   Documentation,
   Hidden;
 
-def SmartPtrModeling: Checker<"SmartPtr">,
+def SmartPtrModeling: Checker<"SmartPtrModeling">,
   HelpText<"Model behavior of C++ smart pointers">,
   Documentation,
+CheckerOptions<[
+CmdLineOption,
+  ]>,
   Hidden;
 
 def MoveChecker: Checker<"Move">,
@@ -736,6 +744,11 @@ def MismatchedIteratorChecker : 
Checker<"MismatchedIterator">,
   Dependencies<[IteratorModeling]>,
   Documentation;
 
+def SmartPtrChecker: Checker<"SmartPtr">,
+  HelpText<"Find the dereference of null SmrtPtr">,
+  Dependencies<[SmartPtrModeling]>,
+  Documentation;
+
 } // end: "alpha.cplusplus"
 
 

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index a71469e90ea2..d75f9f63286d 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -788,6 +788,10 @@ class CXXMemberOperatorCall : public CXXInstanceCall {
 // to implicit this-parameter on the declaration.
 return CallArgumentIndex + 1;
   }
+
+  OverloadedOperatorKind getOverloadedOperator() const {
+return getOriginExpr()->getOperator();
+  }
 };
 
 /// Represents an implicit call to a C++ destructor.

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 80cac237fc3b..9be1fdeb3ebf 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -98,6 +98,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   ReturnValueChecker.cpp
   RunLoopAutoreleaseLeakChecker.cpp
   SimpleStreamChecker.cpp
+  SmartPtrChecker.cpp
   SmartPtrModeling.cpp
   StackAddrEscapeChecker.cpp
   StdLibraryFunctionsChecker.cpp

diff  --git a/clang/lib/StaticAnalyzer/Checkers/SmartPtr.h 
b/clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
new file mode 100644
index ..89b8965e4c9a
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
@@ -0,0 +1,40 @@
+//=== SmartPtr.h - Tracking smart pointer state. ---*- C++ 
-*-//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Defines inter-checker API for the smart pointer modeling. It allows
+// dependent checkers to figure out if an smart pointer is null or not.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHE

[PATCH] D81315: [analyzer] Warning for default constructed unique pointer dereferences

2020-07-08 Thread Nithin VR via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG20e271a98de5: [analyzer] Warning for default constructed 
unique_ptr dereference (authored by vrnithinkumar).

Changed prior to commit:
  https://reviews.llvm.org/D81315?vs=275434&id=275699#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81315

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/smart-ptr.cpp
  clang/test/Analysis/use-after-move.cpp

Index: clang/test/Analysis/use-after-move.cpp
===
--- clang/test/Analysis/use-after-move.cpp
+++ clang/test/Analysis/use-after-move.cpp
@@ -1,36 +1,36 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,non-aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=unexplored_first_queue\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=All\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,aggressive
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=All\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,aggressive
 
 // RUN: not %clang_analyze_cc1 -verify %s \
@@ -49,7 +49,7 @@
 // RUN:  -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
 // RUN:  -analyzer-config exploration_strategy=dfs -DDFS\
 // RUN:  -analyzer-config cplusplus.Move:WarnOn=All -DAGGRESSIVE_DFS\
-// RUN:  -analyzer-checker core,cplusplus.SmartPtr,debug.ExprInspection\
+// RUN:  -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
 // RUN:  -verify=expected,peaceful,aggressive %s 2>&1 | FileCheck %s
 
 #include "Inputs/system-header-simulator-cxx.h"
Index: clang/test/Analysis/smart-ptr.cpp
===
--- clang/test/Analysis/smart-ptr.cpp
+++ clang/test/Analysis/smart-ptr.cpp
@@ -1,16 +1,18 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection\
-// RUN:   -analyzer-checker cplusplus.Move,cplusplus.SmartPtr\
+// RUN:   -analyzer-checker cplusplus.Move,alpha.cplusplus.SmartPtr\
+// RUN:   -analyzer-co

[clang] cfcf8e1 - [analyzer] Silence gcc -Wparentheses warning [NFC]

2020-07-08 Thread Mikael Holmen via cfe-commits

Author: Mikael Holmen
Date: 2020-07-08T10:23:59+02:00
New Revision: cfcf8e17ef537686e03c58921a10593a2b0c4a3d

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

LOG: [analyzer] Silence gcc -Wparentheses warning [NFC]

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporter.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 7df8dea56055..72be4e81c83d 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2145,12 +2145,12 @@ PathSensitiveBugReport::PathSensitiveBugReport(
  "*modeling*, not *diagnostics*.");
 
   assert(
-  bt.getCheckerName().startswith("debug") ||
-  !isHidden(ErrorNode->getState()
-->getAnalysisManager()
-.getCheckerManager()
-->getCheckerRegistryData(),
-bt.getCheckerName()) &&
+  (bt.getCheckerName().startswith("debug") ||
+   !isHidden(ErrorNode->getState()
+ ->getAnalysisManager()
+ .getCheckerManager()
+ ->getCheckerRegistryData(),
+ bt.getCheckerName())) &&
   "Hidden checkers musn't emit diagnostics as they are by definition "
   "non-user facing!");
 }



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


[PATCH] D80873: [clang][cmake] Force CMAKE_LINKER for multistage build in case of BOOTSTRAP_LLVM_ENABLE_LLD and MSVC

2020-07-08 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/CMakeLists.txt:751
+  if(BOOTSTRAP_LLVM_ENABLE_LLD)
+if(MSVC AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME)
+  set(${CLANG_STAGE}_LINKER 
-DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe)

I don't understand the second part of this condition, can you elaborate? Why 
not set `CMAKE_LINKER` to `lld-link.exe` even if `BOOTSTRAP_CMAKE_SYSTEM_NAME 
STREQUAL "Windows"`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80873



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


[PATCH] D83373: [analyzer][tests] Make test interruption safe

2020-07-08 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added reviewers: NoQ, dcoughlin, xazax.hun.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83373

Files:
  clang/utils/analyzer/SATest.py


Index: clang/utils/analyzer/SATest.py
===
--- clang/utils/analyzer/SATest.py
+++ clang/utils/analyzer/SATest.py
@@ -132,27 +132,35 @@
 pass
 
 finally:
-print("Please wait for docker to clean up")
-call("docker stop satest", shell=True)
+docker_cleanup()
 
 
 def docker_run(args, command, docker_args=""):
-return call("docker run --rm --name satest "
-"-v {llvm}:/llvm-project "
-"-v {build}:/build "
-"-v {clang}:/analyzer "
-"-v {scripts}:/scripts "
-"-v {projects}:/projects "
-"{docker_args} "
-"satest-image:latest {command}"
-.format(llvm=args.llvm_project_dir,
-build=args.build_dir,
-clang=args.clang_dir,
-scripts=SCRIPTS_DIR,
-projects=PROJECTS_DIR,
-docker_args=docker_args,
-command=command),
-shell=True)
+try:
+return call("docker run --rm --name satest "
+"-v {llvm}:/llvm-project "
+"-v {build}:/build "
+"-v {clang}:/analyzer "
+"-v {scripts}:/scripts "
+"-v {projects}:/projects "
+"{docker_args} "
+"satest-image:latest {command}"
+.format(llvm=args.llvm_project_dir,
+build=args.build_dir,
+clang=args.clang_dir,
+scripts=SCRIPTS_DIR,
+projects=PROJECTS_DIR,
+docker_args=docker_args,
+command=command),
+shell=True)
+
+except KeyboardInterrupt:
+docker_cleanup()
+
+
+def docker_cleanup():
+print("Please wait for docker to clean up")
+call("docker stop satest", shell=True)
 
 
 def main():


Index: clang/utils/analyzer/SATest.py
===
--- clang/utils/analyzer/SATest.py
+++ clang/utils/analyzer/SATest.py
@@ -132,27 +132,35 @@
 pass
 
 finally:
-print("Please wait for docker to clean up")
-call("docker stop satest", shell=True)
+docker_cleanup()
 
 
 def docker_run(args, command, docker_args=""):
-return call("docker run --rm --name satest "
-"-v {llvm}:/llvm-project "
-"-v {build}:/build "
-"-v {clang}:/analyzer "
-"-v {scripts}:/scripts "
-"-v {projects}:/projects "
-"{docker_args} "
-"satest-image:latest {command}"
-.format(llvm=args.llvm_project_dir,
-build=args.build_dir,
-clang=args.clang_dir,
-scripts=SCRIPTS_DIR,
-projects=PROJECTS_DIR,
-docker_args=docker_args,
-command=command),
-shell=True)
+try:
+return call("docker run --rm --name satest "
+"-v {llvm}:/llvm-project "
+"-v {build}:/build "
+"-v {clang}:/analyzer "
+"-v {scripts}:/scripts "
+"-v {projects}:/projects "
+"{docker_args} "
+"satest-image:latest {command}"
+.format(llvm=args.llvm_project_dir,
+build=args.build_dir,
+clang=args.clang_dir,
+scripts=SCRIPTS_DIR,
+projects=PROJECTS_DIR,
+docker_args=docker_args,
+command=command),
+shell=True)
+
+except KeyboardInterrupt:
+docker_cleanup()
+
+
+def docker_cleanup():
+print("Please wait for docker to clean up")
+call("docker stop satest", shell=True)
 
 
 def main():
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69318: [analyzer] Add SufficientSizeArrayIndexingChecker

2020-07-08 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked 7 inline comments as done.
gamesh411 added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp:27
+: public Checker> {
+  mutable std::unique_ptr BT;
+

balazske wrote:
> The bug type can be initialized here:
> `BT{this, "...", "..."}`
> How did this compile with only one text argument to constructor? I think the 
> first is a short name of the bug, second is a category that is not omittable. 
> The text that is used here should be passed to the `BugReport`. 
> `BugType::getDescription` returns the "name" of the bug that is the first 
> argument. But I am not sure what matters from these texts, the code design 
> looks confusing.
I think because it is initialized with a `BuiltinBug`, which must be a subclass 
of BugType. I don't really know what should be preferable nowadays, as this 
code was actually written more than a year ago. Thanks for pointing out that it 
can be initialized there, I think lazy initialization seems not that important 
with this particular checker.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp:50
+  if (isa(Index->IgnoreParenCasts()))
+return;
+

balazske wrote:
> `if (isa(Index))` should be used. `IntegerLiteral` is a 
> subclass of `Expr`, not a `QualType`.
The way I have structured the code is very misleading, sorry for that, I will 
move the type extraction if lower, where it is actually used.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp:72
+  llvm::APSInt::getMaxValue(C.getASTContext().getIntWidth(IndexType),
+IndexType->isUnsignedIntegerType());
+  const nonloc::ConcreteInt MaxIndexValue{MaxIndex};

balazske wrote:
> I would use `SVB.getBasicValueFactory().getMaxValue(IndexType)` to get the 
> max value.
Good point, thanks for pointing out such a method existed in 
`BasicValueFactory`!



Comment at: 
clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp:82
+  SVB.evalBinOp(State, BO_Sub, SizeInElements, ConstantOne,
+C.getASTContext().UnsignedLongLongTy);
+

balazske wrote:
> `SValBuilder::getArrayIndexType` should be better than the 
> `UnsignedLongLongTy`.
Seems reasonable :)



Comment at: 
clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp:86
+  const SVal TypeCanIndexEveryElement = SVB.evalBinOp(
+  State, BO_LE, SizeInElementsMinusOne, MaxIndexValue, IndexType);
+

balazske wrote:
> I think `SVB.getConditionType()` should be used for condition result.
I will use that, thanks.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp:121
+  // Mark the array expression interesting.
+  R->markInteresting(FirstElement->getSuperRegion());
+  C.emitReport(std::move(R));

balazske wrote:
> I am not sure if this `markInteresting` call is correct. 
What I wanted to do conceptually is to mark the array itself interesting. I am 
however not sure whether this is the best way. I will try this and 
`FirstElement` itself and maybe look at whether there are some additional notes 
emitted along the way.



Comment at: clang/test/Analysis/sufficient-size-array-indexing-32bit.c:37
+const short two_byte_signed_index = 1; // sizeof(short) == 2
+const int four_byte_signed_index = 1;  // sizeof(int) == 4
+

balazske wrote:
> I do not know if it is safe to make such assumptions about `sizeof`.
You are definitely right! However it is common as per:
https://en.cppreference.com/w/cpp/language/types#Data_models
```
Data models

The choices made by each implementation about the sizes of the fundamental 
types are collectively known as data model. Four data models found wide 
acceptance:

32 bit systems:

LP32 or 2/4/4 (int is 16-bit, long and pointer are 32-bit) 

Win16 API 

ILP32 or 4/4/4 (int, long, and pointer are 32-bit); 

Win32 API
Unix and Unix-like systems (Linux, macOS) 

64 bit systems:

LLP64 or 4/4/8 (int and long are 32-bit, pointer is 64-bit) 

Win64 API 

LP64 or 4/8/8 (int is 32-bit, long and pointer are 64-bit) 

Unix and Unix-like systems (Linux, macOS) 

Other models are very rare. For example, ILP64 (8/8/8: int, long, and pointer 
are 64-bit) only appeared in some early 64-bit Unix systems (e.g. Unicos on 
Cray). 
```
Only ILP32 has 16 bit ints.
Next idea would be to use fixed-width integer types from `cstdint`. But tests 
should not use system headers, and there are mentions in test files to 
`int32_t`, howevery they are just typedefs for int. And I think we maintaining 
a whole standard library headers is a bit too much a hassle.


Repository:
  rG LLVM Github Monorepo

[PATCH] D83374: [analyzer][tests] Fix zip unpacking

2020-07-08 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added reviewers: NoQ, xazax.hun.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83374

Files:
  clang/utils/analyzer/SATestBuild.py


Index: clang/utils/analyzer/SATestBuild.py
===
--- clang/utils/analyzer/SATestBuild.py
+++ clang/utils/analyzer/SATestBuild.py
@@ -601,7 +601,7 @@
stdout=build_log_file, shell=True)
 
 def _unpack_zip(self, directory: str, build_log_file: IO):
-zip_files = list(glob.glob(os.path.join(directory, "/*.zip")))
+zip_files = list(glob.glob(directory + "/*.zip"))
 
 if len(zip_files) == 0:
 raise ValueError(


Index: clang/utils/analyzer/SATestBuild.py
===
--- clang/utils/analyzer/SATestBuild.py
+++ clang/utils/analyzer/SATestBuild.py
@@ -601,7 +601,7 @@
stdout=build_log_file, shell=True)
 
 def _unpack_zip(self, directory: str, build_log_file: IO):
-zip_files = list(glob.glob(os.path.join(directory, "/*.zip")))
+zip_files = list(glob.glob(directory + "/*.zip"))
 
 if len(zip_files) == 0:
 raise ValueError(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2192
   R"cpp(
+class osstream {};
 struct X {

gribozavr2 wrote:
> I don't think we need a separate class to show the left shift operator. The 
> declaration below can be:
> 
> ```
>   friend X operator<<(X&, const X&);
> ```
If we don't bother much about "realistic" operator declarations we could drop 
all the `friend` and declare every operator in their most concise form. WDYT


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954



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


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276344.
eduucaldas marked 4 inline comments as done.
eduucaldas added a comment.

answering minor comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+

[PATCH] D69318: [analyzer] Add SufficientSizeArrayIndexingChecker

2020-07-08 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 276346.
gamesh411 added a comment.

apply review suggestions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69318

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/SufficientSizeArrayIndexingChecker.cpp
  clang/test/Analysis/sufficient-size-array-indexing-32bit.c
  clang/test/Analysis/sufficient-size-array-indexing-64bit.c

Index: clang/test/Analysis/sufficient-size-array-indexing-64bit.c
===
--- /dev/null
+++ clang/test/Analysis/sufficient-size-array-indexing-64bit.c
@@ -0,0 +1,127 @@
+// RUN: %clang_analyze_cc1 -triple x86_64 -analyzer-checker=core,alpha.core.SufficientSizeArrayIndexing %s -verify
+
+#include "Inputs/system-header-simulator.h"
+
+const unsigned long long one_byte_signed_max = (1ULL << 7) - 1;
+const unsigned long long two_byte_signed_max = (1ULL << 15) - 1;
+const unsigned long long four_byte_signed_max = (1ULL << 31) - 1;
+
+const unsigned long long one_byte_unsigned_max = (1ULL << 8) - 1;
+const unsigned long long two_byte_unsigned_max = (1ULL << 16) - 1;
+const unsigned long long four_byte_unsigned_max = (1ULL << 32) - 1;
+
+char smaller_than_1byte_signed_range[one_byte_signed_max];
+char exactly_1byte_signed_range[one_byte_signed_max + 1];
+char greater_than_1byte_signed_range[one_byte_signed_max + 2];
+
+char smaller_than_2byte_signed_range[two_byte_signed_max];
+char exactly_2byte_signed_range[two_byte_signed_max + 1];
+char greater_than_2byte_signed_range[two_byte_signed_max + 2];
+
+char smaller_than_4byte_signed_range[four_byte_signed_max];
+char exactly_4byte_signed_range[four_byte_signed_max + 1];
+char greater_than_4byte_signed_range[four_byte_signed_max + 2];
+
+char smaller_than_1byte_unsigned_range[one_byte_unsigned_max];
+char exactly_1byte_unsigned_range[one_byte_unsigned_max + 1];
+char greater_than_1byte_unsigned_range[one_byte_unsigned_max + 2];
+
+char smaller_than_2byte_unsigned_range[two_byte_unsigned_max];
+char exactly_2byte_unsigned_range[two_byte_unsigned_max + 1];
+char greater_than_2byte_unsigned_range[two_byte_unsigned_max + 2];
+
+char smaller_than_4byte_unsigned_range[four_byte_unsigned_max];
+char exactly_4byte_unsigned_range[four_byte_unsigned_max + 1];
+char greater_than_4byte_unsigned_range[four_byte_unsigned_max + 2];
+
+const char one_byte_signed_index = 1;  // sizeof(char) == 1
+const short two_byte_signed_index = 1; // sizeof(short) == 2
+const int four_byte_signed_index = 1;  // sizeof(int) == 4
+
+const unsigned char one_byte_unsigned_index = 1;
+const unsigned short two_byte_unsigned_index = 1;
+const unsigned int four_byte_unsigned_index = 1;
+
+void ignore_literal_indexing() {
+  char a = exactly_4byte_unsigned_range[32]; // nowarning
+}
+
+void ignore_literal_indexing_with_parens() {
+  char a = exactly_4byte_unsigned_range[(32)]; // nowarning
+}
+
+void range_check_one_byte_index() {
+  char r;
+  char *pr = &r;
+  *pr = smaller_than_1byte_signed_range[one_byte_signed_index]; // nowarning
+  *pr = exactly_1byte_signed_range[one_byte_signed_index];  // nowarning
+  *pr = greater_than_1byte_signed_range[one_byte_signed_index]; // expected-warning{{Index type cannot cover the whole range of the array's index set, which may result in memory waste in form of unindexable elements. Consider using a type with greater maximum value}}
+  *pr = smaller_than_1byte_unsigned_range[one_byte_unsigned_index]; // nowarning
+  *pr = exactly_1byte_unsigned_range[one_byte_unsigned_index];  // nowarning
+  *pr = greater_than_1byte_unsigned_range[one_byte_unsigned_index]; // expected-warning{{Index type cannot cover the whole range of the array's index set, which may result in memory waste in form of unindexable elements. Consider using a type with greater maximum value}}
+}
+
+void range_check_two_byte_index() {
+  char r;
+  char *pr = &r;
+  *pr = smaller_than_2byte_signed_range[two_byte_signed_index]; // nowarning
+  *pr = exactly_2byte_signed_range[two_byte_signed_index];  // nowarning
+  *pr = greater_than_2byte_signed_range[two_byte_signed_index]; // expected-warning{{Index type cannot cover the whole range of the array's index set, which may result in memory waste in form of unindexable elements. Consider using a type with greater maximum value}}
+  *pr = smaller_than_2byte_unsigned_range[two_byte_unsigned_index]; // nowarning
+  *pr = exactly_2byte_unsigned_range[two_byte_unsigned_index];  // nowarning
+  *pr = greater_than_2byte_unsigned_range[two_byte_unsigned_index]; // expected-warning{{Index type cannot cover the whole range of the array's index set, which may result in memory waste in form of unindexable elements. Consider using a type with greater maximum value}}
+}
+
+void range_check_four_byte_index() {
+  char r;
+  ch

[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-07-08 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 276351.
gargvaibhav64 edited the summary of this revision.
gargvaibhav64 added a comment.

I incorporated the changes


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

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -ast-dump -I%S/Inputs/inherit-attribute -fmodules-cache-path=%t -fimplicit-module-maps -verify %s -fmodules-local-submodule-visibility
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+// expected-no-diagnostics
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1,7 @@
+#include "a.h"
+
+class Foo;
+class C {
+public:
+  C();
+};
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,12 @@
+#include "a.h"
+
+class Foo;
+
+void bar() {
+  &Foo::step;
+}
+
+class B {
+public:
+  B();
+};
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
\ No newline at end of file
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,8 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(Decl *D, Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3533,17 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(Decl *D, Decl *Previous) {
+  InheritableAttr *IA = nullptr;
+  if (Previous->hasAttr() &&
+  !D->hasAttr()) {
+IA = cast(
+(Previous->getAttr())->clone(D->getASTContext()));
+IA->setInherited(true);
+D->addAttr(IA);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D,
@@ -3689,6 +3702,12 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+  // be extended for all inheritable attributes.
+  mergeInheritableAttributes(D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2192
   R"cpp(
+class osstream {};
 struct X {

eduucaldas wrote:
> gribozavr2 wrote:
> > I don't think we need a separate class to show the left shift operator. The 
> > declaration below can be:
> > 
> > ```
> >   friend X operator<<(X&, const X&);
> > ```
> If we don't bother much about "realistic" operator declarations we could drop 
> all the `friend` and declare every operator in their most concise form. WDYT
I think we shouldn't try to make tests realistic in terms of function names 
etc., but we should try to cover as many different AST shapes as possible. In 
the case of binary operators, we have three cases -- free function, friend 
function, member function, that all generate slightly different ASTs, so I 
believe we should try to cover them all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954



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


[clang] a80afc0 - [UpdateTestChecks] Add UTC_ARGS support for update_{llc,cc}_test_checks.py

2020-07-08 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2020-07-08T11:00:10+01:00
New Revision: a80afc032859ebe65af283f76b38a0f5921b683f

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

LOG: [UpdateTestChecks] Add UTC_ARGS support for update_{llc,cc}_test_checks.py

https://reviews.llvm.org/D69701 added support for on-the-fly argument
changes for update scripts. I recently wanted to keep some manual check
lines in a test generated by update_cc_test_checks.py in our CHERI fork, so
this commit adds support for UTC_ARGS in update_cc_test_checks.py. And since
I was refactoring the code to be in common.py, I also added it for
update_llc_test_checks.py.

Reviewed By: jdoerfert, MaskRay
Differential Revision: https://reviews.llvm.org/D78478

Added: 
clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c

clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c.expected
clang/test/utils/update_cc_test_checks/on_the_fly_arg_change.test

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/on_the_fly_arg_change.ll

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/on_the_fly_arg_change.ll.expected

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/on_the_fly_arg_change.test

Modified: 

clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
clang/test/utils/update_cc_test_checks/mangled_names.test

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/basic.ll.expected
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/basic.test
llvm/utils/update_cc_test_checks.py
llvm/utils/update_llc_test_checks.py

Removed: 




diff  --git 
a/clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
 
b/clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
index 005b2f242747..e76cf074bdb7 100644
--- 
a/clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
+++ 
b/clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature
 // Example input for update_cc_test_checks
 // RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
 

diff  --git 
a/clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c 
b/clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c
new file mode 100644
index ..8956e6b52a21
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+
+int checks_please() {
+  return 1;
+}
+
+// UTC_ARGS: --disable
+
+int no_checks_please() {
+  // Manual CHECK line should be retained:
+  // CHECK: manual check line
+  return -1;
+}
+
+// UTC_ARGS: --enable
+
+
+int checks_again() {
+  return 2;
+}

diff  --git 
a/clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c.expected
 
b/clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c.expected
new file mode 100644
index ..cb7846c7b3d5
--- /dev/null
+++ 
b/clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c.expected
@@ -0,0 +1,29 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK-LABEL: @checks_please(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 1
+//
+int checks_please() {
+  return 1;
+}
+
+// UTC_ARGS: --disable
+
+int no_checks_please() {
+  // Manual CHECK line should be retained:
+  // CHECK: manual check line
+  return -1;
+}
+
+// UTC_ARGS: --enable
+
+
+// CHECK-LABEL: @checks_again(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret i32 2
+//
+int checks_again() {
+  return 2;
+}

diff  --git a/clang/test/utils/update_cc_test_checks/mangled_names.test 
b/clang/test/utils/update_cc_test_checks/mangled_names.test
index 082ed74304f0..bc88c9b5a382 100644
--- a/clang/test/utils/update_cc_test_checks/mangled_names.test
+++ b/clang/test/utils/update_cc_test_checks/mangled_names.test
@@ -8,6 +8,11 @@
 ## Also try the --function-signature flag
 # RUN: %update_cc_test_checks %t.c --function-signature
 # RUN: 
diff  -u %t.c %S/Inputs/mangled_names.c.funcsig.expected
-## Verify that running without the --function-signature flag removes the 
-SAME: lines:
+## Running it again should implicitly add the function-signature flag due to 
UTC_ARGS:
 # RUN: %update_cc_test_checks %t.c
-# RUN: 
diff  -u %t.c %S/Inputs/mangled_names.c.expected
+# RUN: 
diff  -u %t.c %S/I

[PATCH] D78478: [UpdateTestChecks] Add UTC_ARGS support for update_{llc,cc}_test_checks.py

2020-07-08 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa80afc032859: [UpdateTestChecks] Add UTC_ARGS support for 
update_{llc,cc}_test_checks.py (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78478

Files:
  clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
  clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c
  clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c.expected
  clang/test/utils/update_cc_test_checks/mangled_names.test
  clang/test/utils/update_cc_test_checks/on_the_fly_arg_change.test
  
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/basic.ll.expected
  
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/on_the_fly_arg_change.ll
  
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/on_the_fly_arg_change.ll.expected
  llvm/test/tools/UpdateTestChecks/update_llc_test_checks/basic.test
  
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/on_the_fly_arg_change.test
  llvm/utils/update_cc_test_checks.py
  llvm/utils/update_llc_test_checks.py

Index: llvm/utils/update_llc_test_checks.py
===
--- llvm/utils/update_llc_test_checks.py
+++ llvm/utils/update_llc_test_checks.py
@@ -10,19 +10,13 @@
 from __future__ import print_function
 
 import argparse
-import glob
-import os # Used to advertise this file's name ("autogenerated_note").
-import string
-import subprocess
-import sys
-import re
+import os  # Used to advertise this file's name ("autogenerated_note").
 
 from UpdateTestChecks import asm, common
 
-ADVERT = ' NOTE: Assertions have been autogenerated by '
 # llc is the only llc-like in the LLVM tree but downstream forks can add
 # additional ones here if they have them.
-LLC_LIKE_TOOLS = ('llc',) 
+LLC_LIKE_TOOLS = ('llc',)
 
 def main():
   parser = argparse.ArgumentParser(description=__doc__)
@@ -42,35 +36,21 @@
   '--no_x86_scrub_mem_shuffle', action='store_true', default=False,
   help='Reduce scrubbing shuffles with memory operands')
   parser.add_argument('tests', nargs='+')
-  args = common.parse_commandline_args(parser)
+  initial_args = common.parse_commandline_args(parser)
 
   script_name = os.path.basename(__file__)
 
-  test_paths = [test for pattern in args.tests for test in glob.glob(pattern)]
-  for test in test_paths:
-with open(test) as f:
-  input_lines = [l.rstrip() for l in f]
-
-first_line = input_lines[0] if input_lines else ""
-if 'autogenerated' in first_line and script_name not in first_line:
-  common.warn("Skipping test which wasn't autogenerated by " + script_name, test)
-  continue
-
-if args.update_only:
-  if not first_line or 'autogenerated' not in first_line:
-common.warn("Skipping test which isn't autogenerated: " + test)
-continue
-
+  for ti in common.itertests(initial_args.tests, parser,
+ script_name='utils/' + script_name):
 triple_in_ir = None
-for l in input_lines:
+for l in ti.input_lines:
   m = common.TRIPLE_IR_RE.match(l)
   if m:
 triple_in_ir = m.groups()[0]
 break
 
-run_lines = common.find_run_lines(test, input_lines)
 run_list = []
-for l in run_lines:
+for l in ti.run_lines:
   if '|' not in l:
 common.warn('Skipping unparseable RUN line: ' + l)
 continue
@@ -103,7 +83,7 @@
 
   llc_cmd_args = llc_cmd[len(llc_tool):].strip()
   llc_cmd_args = llc_cmd_args.replace('< %s', '').replace('%s', '').strip()
-  if test.endswith('.mir'):
+  if ti.path.endswith('.mir'):
 llc_cmd_args += ' -x mir'
   check_prefixes = [item for m in common.CHECK_PREFIX_RE.finditer(filecheck_cmd)
for item in m.group(1).split(',')]
@@ -114,13 +94,10 @@
   # now, we just ignore all but the last.
   run_list.append((check_prefixes, llc_cmd_args, triple_in_cmd, march_in_cmd))
 
-if test.endswith('.mir'):
-  comment_sym = '#'
+if ti.path.endswith('.mir'):
   check_indent = '  '
 else:
-  comment_sym = ';'
   check_indent = ''
-autogenerated_note = (comment_sym + ADVERT + 'utils/' + script_name)
 
 func_dict = {}
 for p in run_list:
@@ -131,13 +108,12 @@
   common.debug('Extracted LLC cmd:', llc_tool, llc_args)
   common.debug('Extracted FileCheck prefixes:', str(prefixes))
 
-  raw_tool_output = common.invoke_tool(args.llc_binary or llc_tool,
-   llc_args, test)
+  raw_tool_output = common.invoke_tool(ti.args.llc_binary or llc_tool, llc_args, ti.path)
   triple = triple_in_cmd or triple_in_ir
   if not triple:
 triple = asm.get_triple_from_march(march_in_cmd)
 
-  asm.build_function_body_dictionary_for_triple(args, ra

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276361.
eduucaldas added a comment.

Reflect fix on RecursiveASTVisitor


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82157

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -1184,6 +1184,93 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+long double operator "" _w(long double);
+unsigned operator "" _w(const char*);
+template  unsigned operator "" _x();
+int main() {
+1.2_w; // calls operator "" _w(1.2L)
+12_w;  // calls operator "" _w("12")
+12_x;  // calls operator<'1', '2'> "" _x()
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-long
+| |-double
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-long
+| |   | `-double
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-const
+| |   | |-char
+| |   | `-SimpleDeclarator
+| |   |   `-*
+| |   `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+|   |-unsigned
+|   |-SimpleDeclarator
+|   | |-operator
+|   | |-""
+|   | |-_x
+|   | `-ParametersAndQualifiers
+|   |   |-(
+|   |   `-)
+|   `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-main
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UserDefinedLiteralExpression
+| | `-1.2_w
+| `-;
+|-ExpressionStatement
+| |-UserDefinedLiteralExpression
+| | `-12_w
+| `-;
+|-ExpressionStatement
+| |-UserDefinedLiteralExpression
+| | `-12_x
+| `-;
+`-}
+)txt"));
+}
 TEST_P(SyntaxTreeTest, IntegerLiteral) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -32,6 +32,8 @@
 return OS << "BoolLiteralExpression";
   case NodeKind::CxxNullPtrExpression:
 return OS << "CxxNullPtrExpression";
+  case NodeKind::UserDefinedLiteralExpression:
+return OS << "UserDefinedLiteralExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -252,6 +254,11 @@
   findChild(syntax::NodeRole::LiteralToken));
 }
 
+syntax::Leaf *syntax::UserDefinedLiteralExpression::literalToken() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::LiteralToken));
+}
+
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::BinaryOperatorExpression_leftHandSide));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -627,6 +627,26 @@
 return NNS;
   }
 
+  bool TraverseUserDefinedLiteral(UserDefinedLiteral *S) {
+// The user-defined literal `1.2_w` corresponds to *one* token. The semantic
+// node for it however may have two children nodes, both with valid
+// `SourceLocation`s. As a result one of these nodes has a valid
+// `SourceLocation` that doesn't point to a token.
+//
+// If we traverse the children of a user-defined literal, we then arrive to
+// a semantic node that doesn't have a token, and that breaks an invariant
+// of the syntax tree. For that reason we skip traversing user-defined
+// literal children.
+
+return WalkUpFromUserDefinedLiteral(S);
+  }
+
+  bool WalkUpFromUserDefinedLiteral(UserDefinedLiteral *S) {
+Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::UserDefinedLiteralExpression, S);
+return true;
+  }
   bool WalkUpFromDeclRefExpr(DeclRefExpr *S) {
 if (auto *NNS = BuildNestedNameSpecifier(S->getQualifierLoc()))
   Builder.markChild(NNS, syntax::NodeRole::IdExpression_qualifier);
Index: clang/include/clang/Tooling/Syntax/Nodes.h
===
--- clang/include/clang/Tooling/Syntax/Nodes.h
+++ clang/include/clang/Tooling/Syn

[PATCH] D83201: [AST][RecoveryExpr] Fix the value category for recovery expr.

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



Comment at: clang/lib/AST/ExprClassification.cpp:147
 
+  case Expr::RecoveryExprClass:
+return ClassifyExprValueKind(Lang, E, E->getValueKind());

there's a block of cases with a similar implementation (near OpaqueValueKind), 
maybe move there



Comment at: clang/lib/Sema/SemaOverload.cpp:12944
+  Fn->getBeginLoc(), RParenLoc, SubExprs,
+  ReturnType.isNull()
+  ? ReturnType

hokein wrote:
> sammccall wrote:
> > here we're splitting the type (e.g. int&&) into a type + VK, and passing 
> > both to createrecoveryexpr.
> > 
> > Why not do that on recoveryexpr side? e.g. if we request a recoveryexpr of 
> > type int&, return an LValue recoveryexpr of type int?
> right, good idea, this is simpler. I was somehow taking `CallExpr` as a 
> reference when writing this code.
Hmm, this does seem simpler to me but it also seems that a few places 
deliberately make this mapping between two related concepts explicit.
Maybe we should at least have a comment on createrecoveryexpr that the value 
category will be inferred from the (reference) type.



Comment at: clang/test/SemaCXX/recovery-expr-type.cpp:66
+
+namespace test4 {
+int &&f(int);  // expected-note {{candidate function not viable}}

I liked the comment explaining the purpose of the test (no crash for wrong 
value category)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83201



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


[PATCH] D78478: [UpdateTestChecks] Add UTC_ARGS support for update_{llc,cc}_test_checks.py

2020-07-08 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa80afc032859: [UpdateTestChecks] Add UTC_ARGS support for 
update_{llc,cc}_test_checks.py (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78478

Files:
  clang/test/utils/update_cc_test_checks/Inputs/mangled_names.c.funcsig.expected
  clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c
  clang/test/utils/update_cc_test_checks/Inputs/on_the_fly_arg_change.c.expected
  clang/test/utils/update_cc_test_checks/mangled_names.test
  clang/test/utils/update_cc_test_checks/on_the_fly_arg_change.test
  
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/basic.ll.expected
  
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/on_the_fly_arg_change.ll
  
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/on_the_fly_arg_change.ll.expected
  llvm/test/tools/UpdateTestChecks/update_llc_test_checks/basic.test
  
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/on_the_fly_arg_change.test
  llvm/utils/update_cc_test_checks.py
  llvm/utils/update_llc_test_checks.py

Index: llvm/utils/update_llc_test_checks.py
===
--- llvm/utils/update_llc_test_checks.py
+++ llvm/utils/update_llc_test_checks.py
@@ -10,19 +10,13 @@
 from __future__ import print_function
 
 import argparse
-import glob
-import os # Used to advertise this file's name ("autogenerated_note").
-import string
-import subprocess
-import sys
-import re
+import os  # Used to advertise this file's name ("autogenerated_note").
 
 from UpdateTestChecks import asm, common
 
-ADVERT = ' NOTE: Assertions have been autogenerated by '
 # llc is the only llc-like in the LLVM tree but downstream forks can add
 # additional ones here if they have them.
-LLC_LIKE_TOOLS = ('llc',) 
+LLC_LIKE_TOOLS = ('llc',)
 
 def main():
   parser = argparse.ArgumentParser(description=__doc__)
@@ -42,35 +36,21 @@
   '--no_x86_scrub_mem_shuffle', action='store_true', default=False,
   help='Reduce scrubbing shuffles with memory operands')
   parser.add_argument('tests', nargs='+')
-  args = common.parse_commandline_args(parser)
+  initial_args = common.parse_commandline_args(parser)
 
   script_name = os.path.basename(__file__)
 
-  test_paths = [test for pattern in args.tests for test in glob.glob(pattern)]
-  for test in test_paths:
-with open(test) as f:
-  input_lines = [l.rstrip() for l in f]
-
-first_line = input_lines[0] if input_lines else ""
-if 'autogenerated' in first_line and script_name not in first_line:
-  common.warn("Skipping test which wasn't autogenerated by " + script_name, test)
-  continue
-
-if args.update_only:
-  if not first_line or 'autogenerated' not in first_line:
-common.warn("Skipping test which isn't autogenerated: " + test)
-continue
-
+  for ti in common.itertests(initial_args.tests, parser,
+ script_name='utils/' + script_name):
 triple_in_ir = None
-for l in input_lines:
+for l in ti.input_lines:
   m = common.TRIPLE_IR_RE.match(l)
   if m:
 triple_in_ir = m.groups()[0]
 break
 
-run_lines = common.find_run_lines(test, input_lines)
 run_list = []
-for l in run_lines:
+for l in ti.run_lines:
   if '|' not in l:
 common.warn('Skipping unparseable RUN line: ' + l)
 continue
@@ -103,7 +83,7 @@
 
   llc_cmd_args = llc_cmd[len(llc_tool):].strip()
   llc_cmd_args = llc_cmd_args.replace('< %s', '').replace('%s', '').strip()
-  if test.endswith('.mir'):
+  if ti.path.endswith('.mir'):
 llc_cmd_args += ' -x mir'
   check_prefixes = [item for m in common.CHECK_PREFIX_RE.finditer(filecheck_cmd)
for item in m.group(1).split(',')]
@@ -114,13 +94,10 @@
   # now, we just ignore all but the last.
   run_list.append((check_prefixes, llc_cmd_args, triple_in_cmd, march_in_cmd))
 
-if test.endswith('.mir'):
-  comment_sym = '#'
+if ti.path.endswith('.mir'):
   check_indent = '  '
 else:
-  comment_sym = ';'
   check_indent = ''
-autogenerated_note = (comment_sym + ADVERT + 'utils/' + script_name)
 
 func_dict = {}
 for p in run_list:
@@ -131,13 +108,12 @@
   common.debug('Extracted LLC cmd:', llc_tool, llc_args)
   common.debug('Extracted FileCheck prefixes:', str(prefixes))
 
-  raw_tool_output = common.invoke_tool(args.llc_binary or llc_tool,
-   llc_args, test)
+  raw_tool_output = common.invoke_tool(ti.args.llc_binary or llc_tool, llc_args, ti.path)
   triple = triple_in_cmd or triple_in_ir
   if not triple:
 triple = asm.get_triple_from_march(march_in_cmd)
 
-  asm.build_function_body_dictionary_for_triple(args, ra

[PATCH] D82938: [clangd] Implement path and URI translation for remote index

2020-07-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 276366.
kbobyrev marked 12 inline comments as done.
kbobyrev added a comment.

Store progress. Still WIP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82938

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/Client.h
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/index/remote/unimplemented/UnimplementedClient.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -7,16 +7,34 @@
 //===--===//
 
 #include "../TestTU.h"
+#include "TestFS.h"
 #include "index/Serialization.h"
+#include "index/Symbol.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace clangd {
 namespace remote {
 namespace {
 
+using llvm::sys::path::convert_to_slash;
+
+const char *unittestURIToFilesystem(const char *UnittestURI,
+llvm::UniqueStringSaver &Strings) {
+  auto URI = URI::parse(UnittestURI);
+  EXPECT_TRUE(bool(URI));
+  const auto FileSystemURI =
+  URI::createFile(testPath(llvm::sys::path::relative_path(URI->body(;
+  return Strings.save(FileSystemURI.toString()).begin();
+}
+
 TEST(RemoteMarshallingTest, SymbolSerialization) {
   const auto *Header = R"(
   // This is a class.
@@ -39,9 +57,18 @@
   EXPECT_GE(Symbols.size(), 5UL);
   llvm::BumpPtrAllocator Arena;
   llvm::UniqueStringSaver Strings(Arena);
-  for (auto &Sym : Symbols) {
-const auto ProtobufMeessage = toProtobuf(Sym);
-const auto SymToProtobufAndBack = fromProtobuf(ProtobufMeessage, &Strings);
+  for (auto Sym : Symbols) {
+Sym.CanonicalDeclaration.FileURI =
+unittestURIToFilesystem(Sym.CanonicalDeclaration.FileURI, Strings);
+if (std::strlen(Sym.Definition.FileURI))
+  Sym.Definition.FileURI =
+  unittestURIToFilesystem(Sym.Definition.FileURI, Strings);
+for (auto &Header : Sym.IncludeHeaders)
+  Header.IncludeHeader =
+  unittestURIToFilesystem(Header.IncludeHeader.str().c_str(), Strings);
+auto ProtobufMessage = toProtobuf(Sym, convert_to_slash("/"));
+const auto SymToProtobufAndBack =
+fromProtobuf(ProtobufMessage, &Strings, "/");
 EXPECT_TRUE(SymToProtobufAndBack.hasValue());
 EXPECT_EQ(toYAML(Sym), toYAML(*SymToProtobufAndBack));
   }
@@ -79,13 +106,106 @@
   // Sanity check: there are more than 5 references available.
   EXPECT_GE(References.numRefs(), 5UL);
   for (const auto &SymbolWithRefs : References) {
-for (const auto &Ref : SymbolWithRefs.second) {
-  const auto RefToProtobufAndBack = fromProtobuf(toProtobuf(Ref), &Strings);
+for (auto Ref : SymbolWithRefs.second) {
+  Ref.Location.FileURI =
+  unittestURIToFilesystem(Ref.Location.FileURI, Strings);
+  const auto RefToProtobufAndBack =
+  fromProtobuf(toProtobuf(Ref, convert_to_slash("/")), &Strings, "/");
   EXPECT_TRUE(RefToProtobufAndBack.hasValue());
   EXPECT_EQ(toYAML(Ref), toYAML(*RefToProtobufAndBack));
 }
   }
-} // namespace
+}
+
+TEST(RemoteMarshallingTest, URITranslation) {
+  llvm::BumpPtrAllocator Arena;
+  llvm::UniqueStringSaver Strings(Arena);
+  clangd::Ref Original;
+  const std::string RemoteIndexPrefix = testPath("remote/machine/project/");
+  const std::string RelativePath =
+  convert_to_slash("llvm-project/clang-tools-extra/clangd/unittests/remote/"
+   "MarshallingTests.cpp");
+  const URI FullURI = URI::createFile(RemoteIndexPrefix + RelativePath);
+  Original.Location.FileURI = Strings.save(FullURI.toString()).begin();
+  auto Serialized = toProtobuf(Original, RemoteIndexPrefix);
+  EXPECT_EQ(Serialized.location().file_path(), RelativePath);
+  const std::string LocalIndexPrefix = testPath("local/machine/project/");
+  auto Deserialized = fromProtobuf(Serialized, &Strings, LocalIndexPrefix);
+  EXPECT_TRUE(Deserialized);
+  EXPECT_EQ(Deserialized->Location.FileURI,
+URI::createFile(LocalIndexPrefix + RelativePath).toString());
+
+  clangd::Ref WithInvalidURI;
+  // Invalid URI results in empty path.
+  WithInvalidURI.Location.FileURI = "This is not 

[PATCH] D82938: [clangd] Implement path and URI translation for remote index

2020-07-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev marked 2 inline comments as done.
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:25
 
+const char *unittestURIToFilesystem(const char *UnittestURI,
+llvm::UniqueStringSaver &Strings) {

sammccall wrote:
> The File scheme is special. Using a different URI scheme here when we only 
> support `file` in production is confusing and seems like a last resort to be 
> used when we can't make it work any other way.
> (For example we use it in lit tests because we must specify input filenames 
> and the presence/absence of drive letters caused problems)
> What's being solved there that the much smaller hammer of testPath() plus a 
> local testPathURI() helper can't solve?
This is dealing with the consequences of test infrastructure being set up in a 
way that makes all URIs in Symbols and Refs use "unittest" scheme, this helper 
simply translates those URIs into "file" URIs which are the ones being 
supported in production. I can not understand why this is not desirable but 
I'll just clear all URIs and leave those two tests as sanity checks.



Comment at: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp:130
+  EXPECT_EQ(Serialized.location().file_path(), RelativePath);
+  // Local index prefix should have UNIX slashes since the relative path in
+  // Protobuf message will.

sammccall wrote:
> hmm, I don't think that's the reason.
> Either that's the contract of fromProtobuf, or it's not required and we 
> shouldn't do it.
Ah, `llvm::sys::path::append` already does that for me. Okay, makes sense to 
remove this then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82938



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


[PATCH] D82781: [OpenCL] Fix missing address space deduction in template variables

2020-07-08 Thread Ole Strohm via Phabricator via cfe-commits
olestrohm updated this revision to Diff 276369.
olestrohm marked an inline comment as done.
olestrohm added a comment.

I've removed the comments calling for a fix because I no longer feel that this 
approach needs that. Given the code that already exists, and without changing 
too much of it, adding address space deduction in both cases seems like the 
right choice.


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

https://reviews.llvm.org/D82781

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaOpenCLCXX/address-space-deduction.cl

Index: clang/test/SemaOpenCLCXX/address-space-deduction.cl
===
--- clang/test/SemaOpenCLCXX/address-space-deduction.cl
+++ clang/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -5,6 +5,11 @@
 //CHECK: |-VarDecl {{.*}} foo 'const __global int'
 constexpr int foo = 0;
 
+//CHECK: |-VarDecl {{.*}} foo1 'T' cinit
+//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' cinit
+template 
+T foo1 = 0;
+
 class c {
 public:
   //CHECK: `-VarDecl {{.*}} foo2 'const __global int'
@@ -30,7 +35,7 @@
 
 template 
 struct x1 {
-//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &__private){{( __attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} operator= 'x1 &(const x1 &){{( __attribute__.*)?}} __generic'
 //CHECK: -CXXMethodDecl {{.*}} operator= '__generic x1 &(const __generic x1 &__private){{( __attribute__.*)?}} __generic'
   x1& operator=(const x1& xx) {
 y = xx.y;
@@ -41,7 +46,7 @@
 
 template 
 struct x2 {
-//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *__private){{( __attribute__.*)?}} __generic'
+//CHECK: -CXXMethodDecl {{.*}} foo 'void (x1 *){{( __attribute__.*)?}} __generic'
 //CHECK: -CXXMethodDecl {{.*}} foo 'void (__generic x1 *__private){{( __attribute__.*)?}} __generic'
   void foo(x1* xx) {
 m[0] = *xx;
@@ -57,10 +62,10 @@
 template 
 class x3 : public T {
 public:
-  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( __attribute__.*)?}} __generic'
+  //CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( __attribute__.*)?}} __generic'
   x3(const x3 &t);
 };
-//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &__private){{( __attribute__.*)?}} __generic'
+//CHECK: -CXXConstructorDecl {{.*}} x3 'void (const x3 &){{( __attribute__.*)?}} __generic'
 template 
 x3::x3(const x3 &t) {}
 
@@ -68,7 +73,8 @@
 T xxx(T *in1, T in2) {
   // This pointer can't be deduced to generic because addr space
   // will be taken from the template argument.
-  //CHECK: `-VarDecl {{.*}} '__private T *__private' cinit
+  //CHECK: `-VarDecl {{.*}} 'T *' cinit
+  //CHECK: `-VarDecl {{.*}} i '__private int *__private' cinit
   T *i = in1;
   T ii;
   __private T *ptr = ⅈ
@@ -111,4 +117,5 @@
   t3(&x);
   t4(&p);
   t5(&p);
+  long f1 = foo1;
 }
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3625,6 +3625,9 @@
   if (InsertPos)
 VarTemplate->AddSpecialization(Var, InsertPos);
 
+  if (SemaRef.getLangOpts().OpenCL)
+SemaRef.deduceOpenCLAddressSpace(Var);
+
   // Substitute the nested name specifier, if any.
   if (SubstQualifier(D, Var))
 return nullptr;
@@ -4803,6 +4806,9 @@
   // Instantiate the initializer.
   InstantiateVariableInitializer(VarSpec, PatternDecl, TemplateArgs);
 
+  if (getLangOpts().OpenCL)
+deduceOpenCLAddressSpace(VarSpec);
+
   return VarSpec;
 }
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -6287,6 +6287,8 @@
 void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
   if (Decl->getType().hasAddressSpace())
 return;
+  if (Decl->getType()->isDependentType())
+return;
   if (VarDecl *Var = dyn_cast(Decl)) {
 QualType Type = Var->getType();
 if (Type->isSamplerT() || Type->isVoidType())
@@ -7856,6 +7858,7 @@
 if (NewVD->isFileVarDecl() || NewVD->isStaticLocal() ||
 NewVD->hasExternalStorage()) {
   if (!T->isSamplerT() &&
+  !T->isDependentType() &&
   !(T.getAddressSpace() == LangAS::opencl_constant ||
 (T.getAddressSpace() == LangAS::opencl_global &&
  (getLangOpts().OpenCLVersion == 200 ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82381: [analyzer] Introduce small improvements to the solver infra

2020-07-08 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

Hi @vsavchenko , sorry for the late review.




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:367-378
+RangeSet RangeSet::Delete(BasicValueFactory &BV, Factory &F,
+  const llvm::APSInt &Point) const {
+  llvm::APSInt Upper = Point;
+  llvm::APSInt Lower = Point;
+
+  ++Upper;
+  --Lower;

Useful function. But I'd better rename it to `subtract` as we are working with 
sets (as a mathimatical collection). We should have a such one for the Ranges 
not only for Points.
We have `intersect`, `delete` aka `subtract`. And we also need to have 
functions `union` and `symmetricDifference` to cover full palette of common 
operations on sets.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:734
   //expressions which we currently do not know how to negate.
-  const RangeSet *getRangeForMinusSymbol(ProgramStateRef State, SymbolRef Sym) 
{
+  Optional getRangeForInvertedSub(SymbolRef Sym) {
 if (const SymSymExpr *SSE = dyn_cast(Sym)) {

As for me, I'd call this like `getRangeForNegatedSymSymExpr`, since you do 
Negate operation inside.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:841-844
+  RangeSet getTrueRange(QualType T) {
+RangeSet TypeRange = infer(T);
+return assumeNonZero(TypeRange, T);
+  }

Don't you think this is too complicated for such a simple getter?
Maybe we can just construct the range using smth about `RangeSet(RangeFactory, 
++Zero, --Zero);` ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82381



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


[PATCH] D83386: clang: Don't show a trailing space with --version when not built from the repo

2020-07-08 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru created this revision.
sylvestre.ledru added reviewers: thakis, hans.
Herald added a project: clang.

Reported here:
https://bugs.llvm.org/show_bug.cgi?id=38998#c15


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83386

Files:
  clang/lib/Basic/Version.cpp


Index: clang/lib/Basic/Version.cpp
===
--- clang/lib/Basic/Version.cpp
+++ clang/lib/Basic/Version.cpp
@@ -97,8 +97,12 @@
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << ToolName << " version " CLANG_VERSION_STRING " "
- << getClangFullRepositoryVersion();
+  OS << ToolName << " version " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
 
   return OS.str();
 }
@@ -111,7 +115,13 @@
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
+  OS << "Clang " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
+
   return OS.str();
 }
 


Index: clang/lib/Basic/Version.cpp
===
--- clang/lib/Basic/Version.cpp
+++ clang/lib/Basic/Version.cpp
@@ -97,8 +97,12 @@
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << ToolName << " version " CLANG_VERSION_STRING " "
- << getClangFullRepositoryVersion();
+  OS << ToolName << " version " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
 
   return OS.str();
 }
@@ -111,7 +115,13 @@
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
+  OS << "Clang " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
+
   return OS.str();
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83201: [AST][RecoveryExpr] Fix the value category for recovery expr.

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 276379.
hokein marked 3 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83201

Files:
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp

Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -62,3 +62,9 @@
  // expected-note {{in instantiation of member function}} \
  // expected-note {{in call to}}
 }
+
+// verify no assertion failure on violating value category.
+namespace test4 {
+int &&f(int);  // expected-note {{candidate function not viable}}
+int &&k = f(); // expected-error {{no matching function for call}}
+}
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -4,7 +4,6 @@
 int some_func(int *);
 
 // CHECK: VarDecl {{.*}} invalid_call
-// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:|-UnresolvedLookupExpr {{.*}} 'some_func'
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
@@ -34,7 +33,6 @@
 int ambig_func(float);
 
 // CHECK: VarDecl {{.*}} ambig_call
-// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:|-UnresolvedLookupExpr {{.*}} 'ambig_func'
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
@@ -211,3 +209,16 @@
 } NoCrashOnInvalidInitList = {
   .abc = nullptr,
 };
+
+// Verify the value category of recovery expression.
+int prvalue(int);
+int &lvalue(int);
+int &&xvalue(int);
+void ValueCategory() {
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors
+  prvalue(); // call to a function (nonreference return type) yields a prvalue (not print by default)
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors lvalue
+  lvalue(); // call to a function (lvalue reference return type) yields an lvalue.
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors xvalue
+  xvalue(); // call to a function (rvalue reference return type) yields an xvalue.
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -12818,7 +12818,7 @@
   auto ConsiderCandidate = [&](const OverloadCandidate &Candidate) {
 if (!Candidate.Function)
   return;
-QualType T = Candidate.Function->getCallResultType();
+QualType T = Candidate.Function->getReturnType();
 if (T.isNull())
   return;
 if (!Result)
Index: clang/lib/AST/ExprClassification.cpp
===
--- clang/lib/AST/ExprClassification.cpp
+++ clang/lib/AST/ExprClassification.cpp
@@ -130,7 +130,6 @@
   case Expr::UnresolvedLookupExprClass:
   case Expr::UnresolvedMemberExprClass:
   case Expr::TypoExprClass:
-  case Expr::RecoveryExprClass:
   case Expr::DependentCoawaitExprClass:
   case Expr::CXXDependentScopeMemberExprClass:
   case Expr::DependentScopeDeclRefExprClass:
@@ -276,6 +275,7 @@
   return Cl::CL_PRValue;
 }
 
+  case Expr::RecoveryExprClass:
   case Expr::OpaqueValueExprClass:
 return ClassifyExprValueKind(Lang, E, E->getValueKind());
 
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4779,8 +4779,10 @@
 
 RecoveryExpr::RecoveryExpr(ASTContext &Ctx, QualType T, SourceLocation BeginLoc,
SourceLocation EndLoc, ArrayRef SubExprs)
-: Expr(RecoveryExprClass, T, VK_LValue, OK_Ordinary), BeginLoc(BeginLoc),
-  EndLoc(EndLoc), NumExprs(SubExprs.size()) {
+: Expr(RecoveryExprClass, T.getNonReferenceType(),
+   T->isDependentType() ? VK_LValue : getValueKindForType(T),
+   OK_Ordinary),
+  BeginLoc(BeginLoc), EndLoc(EndLoc), NumExprs(SubExprs.size()) {
   assert(!T.isNull());
   assert(llvm::all_of(SubExprs, [](Expr* E) { return E != nullptr; }));
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83201: [AST][RecoveryExpr] Fix the value category for recovery expr.

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:12944
+  Fn->getBeginLoc(), RParenLoc, SubExprs,
+  ReturnType.isNull()
+  ? ReturnType

sammccall wrote:
> hokein wrote:
> > sammccall wrote:
> > > here we're splitting the type (e.g. int&&) into a type + VK, and passing 
> > > both to createrecoveryexpr.
> > > 
> > > Why not do that on recoveryexpr side? e.g. if we request a recoveryexpr 
> > > of type int&, return an LValue recoveryexpr of type int?
> > right, good idea, this is simpler. I was somehow taking `CallExpr` as a 
> > reference when writing this code.
> Hmm, this does seem simpler to me but it also seems that a few places 
> deliberately make this mapping between two related concepts explicit.
> Maybe we should at least have a comment on createrecoveryexpr that the value 
> category will be inferred from the (reference) type.
> Hmm, this does seem simpler to me but it also seems that a few places 
> deliberately make this mapping between two related concepts explicit.

yeah, that's true for at least `CallExpr`. Expr provides a `setValueKind` 
method, ideally (if we enable the type propagation), we could call it to set 
the value category here. I think it is fine to leave it at recoveryexpr side -- 
our case is really simple.





Comment at: clang/test/SemaCXX/recovery-expr-type.cpp:66
+
+namespace test4 {
+int &&f(int);  // expected-note {{candidate function not viable}}

sammccall wrote:
> I liked the comment explaining the purpose of the test (no crash for wrong 
> value category)
oops, the comment gets lost during my rebase :(.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83201



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


[PATCH] D82781: [OpenCL] Fix missing address space deduction in template variables

2020-07-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


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

https://reviews.llvm.org/D82781



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


[PATCH] D83013: [LPM] Port CGProfilePass from NPM to LPM

2020-07-08 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D83013#2137607 , @MaskRay wrote:

> `Opts.getProfileUse() != CodeGenOptions::ProfileNone ` in
>
>   Opts.CallGraphProfile = Opts.getProfileUse() != CodeGenOptions::ProfileNone 
> &&
> !Opts.DisableIntegratedAS;
>
>
> is redundant. CGProfile.cpp is a no-op if no function provides 
> `getEntryFreq()`.


It's a functional no-op, but it runs the BFI analysis, which as Nikita pointed 
out above adds some compile-time cost. Not scheduling the pass unless we're 
using profile info seems like a reasonable way to avoid that cost to me.

The alternative of using LazyBlockFrequencyInfoPass and checking 
PSI->hasProfileSummary() first would also work I guess. If you think that's 
cleaner, maybe that's the better way to go.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83013



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


[clang] 96a5cff - [AST][RecoveryExpr] Fix the value category for recovery expr.

2020-07-08 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-07-08T13:55:07+02:00
New Revision: 96a5cfff208d8e86a598e64412d9ef5dde0f9c9e

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

LOG: [AST][RecoveryExpr] Fix the value category for recovery expr.

RecoveryExpr was always lvalue, but it is wrong if we use it to model
broken function calls, function call expression has more compliated rules:

- a call to a function whose return type is an lvalue reference yields an 
lvalue;
- a call to a function whose return type is an rvalue reference yields an 
xvalue;
- a call to a function whose return type is nonreference type yields a prvalue;

This patch makes the recovery-expr align with the function call if it is
modeled a broken call.

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

Added: 


Modified: 
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/SemaCXX/recovery-expr-type.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 96a70307235b..343a271c3394 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4779,8 +4779,10 @@ QualType OMPArraySectionExpr::getBaseOriginalType(const 
Expr *Base) {
 
 RecoveryExpr::RecoveryExpr(ASTContext &Ctx, QualType T, SourceLocation 
BeginLoc,
SourceLocation EndLoc, ArrayRef SubExprs)
-: Expr(RecoveryExprClass, T, VK_LValue, OK_Ordinary), BeginLoc(BeginLoc),
-  EndLoc(EndLoc), NumExprs(SubExprs.size()) {
+: Expr(RecoveryExprClass, T.getNonReferenceType(),
+   T->isDependentType() ? VK_LValue : getValueKindForType(T),
+   OK_Ordinary),
+  BeginLoc(BeginLoc), EndLoc(EndLoc), NumExprs(SubExprs.size()) {
   assert(!T.isNull());
   assert(llvm::all_of(SubExprs, [](Expr* E) { return E != nullptr; }));
 

diff  --git a/clang/lib/AST/ExprClassification.cpp 
b/clang/lib/AST/ExprClassification.cpp
index 42873d090ffa..31aa734ffedb 100644
--- a/clang/lib/AST/ExprClassification.cpp
+++ b/clang/lib/AST/ExprClassification.cpp
@@ -130,7 +130,6 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const 
Expr *E) {
   case Expr::UnresolvedLookupExprClass:
   case Expr::UnresolvedMemberExprClass:
   case Expr::TypoExprClass:
-  case Expr::RecoveryExprClass:
   case Expr::DependentCoawaitExprClass:
   case Expr::CXXDependentScopeMemberExprClass:
   case Expr::DependentScopeDeclRefExprClass:
@@ -276,6 +275,7 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const 
Expr *E) {
   return Cl::CL_PRValue;
 }
 
+  case Expr::RecoveryExprClass:
   case Expr::OpaqueValueExprClass:
 return ClassifyExprValueKind(Lang, E, E->getValueKind());
 

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 599e81d1b4d0..8635397f4806 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -12818,7 +12818,7 @@ static QualType chooseRecoveryType(OverloadCandidateSet 
&CS,
   auto ConsiderCandidate = [&](const OverloadCandidate &Candidate) {
 if (!Candidate.Function)
   return;
-QualType T = Candidate.Function->getCallResultType();
+QualType T = Candidate.Function->getReturnType();
 if (T.isNull())
   return;
 if (!Result)

diff  --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index e2a715130628..740864a26481 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -4,7 +4,6 @@
 int some_func(int *);
 
 // CHECK: VarDecl {{.*}} invalid_call
-// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:|-UnresolvedLookupExpr {{.*}} 'some_func'
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
@@ -34,7 +33,6 @@ int ambig_func(double);
 int ambig_func(float);
 
 // CHECK: VarDecl {{.*}} ambig_call
-// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:|-UnresolvedLookupExpr {{.*}} 'ambig_func'
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
@@ -211,3 +209,16 @@ struct {
 } NoCrashOnInvalidInitList = {
   .abc = nullptr,
 };
+
+// Verify the value category of recovery expression.
+int prvalue(int);
+int &lvalue(int);
+int &&xvalue(int);
+void ValueCategory() {
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors
+  prvalue(); // call to a function (nonreference return type) yields a prvalue 
(not print by default)
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors lvalue
+  lvalue(); // call to a function (lvalue reference return type) yields an 
lvalue.
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors xvalue
+  xvalue(); // call to a

[PATCH] D83201: [AST][RecoveryExpr] Fix the value category for recovery expr.

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG96a5cfff208d: [AST][RecoveryExpr] Fix the value category for 
recovery expr. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83201

Files:
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp

Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -62,3 +62,9 @@
  // expected-note {{in instantiation of member function}} \
  // expected-note {{in call to}}
 }
+
+// verify no assertion failure on violating value category.
+namespace test4 {
+int &&f(int);  // expected-note {{candidate function not viable}}
+int &&k = f(); // expected-error {{no matching function for call}}
+}
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -4,7 +4,6 @@
 int some_func(int *);
 
 // CHECK: VarDecl {{.*}} invalid_call
-// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:|-UnresolvedLookupExpr {{.*}} 'some_func'
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
@@ -34,7 +33,6 @@
 int ambig_func(float);
 
 // CHECK: VarDecl {{.*}} ambig_call
-// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:  `-RecoveryExpr {{.*}} 'int' contains-errors
 // CHECK-NEXT:|-UnresolvedLookupExpr {{.*}} 'ambig_func'
 // CHECK-NEXT:`-IntegerLiteral {{.*}} 123
@@ -211,3 +209,16 @@
 } NoCrashOnInvalidInitList = {
   .abc = nullptr,
 };
+
+// Verify the value category of recovery expression.
+int prvalue(int);
+int &lvalue(int);
+int &&xvalue(int);
+void ValueCategory() {
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors
+  prvalue(); // call to a function (nonreference return type) yields a prvalue (not print by default)
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors lvalue
+  lvalue(); // call to a function (lvalue reference return type) yields an lvalue.
+  // CHECK:  RecoveryExpr {{.*}} 'int' contains-errors xvalue
+  xvalue(); // call to a function (rvalue reference return type) yields an xvalue.
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -12818,7 +12818,7 @@
   auto ConsiderCandidate = [&](const OverloadCandidate &Candidate) {
 if (!Candidate.Function)
   return;
-QualType T = Candidate.Function->getCallResultType();
+QualType T = Candidate.Function->getReturnType();
 if (T.isNull())
   return;
 if (!Result)
Index: clang/lib/AST/ExprClassification.cpp
===
--- clang/lib/AST/ExprClassification.cpp
+++ clang/lib/AST/ExprClassification.cpp
@@ -130,7 +130,6 @@
   case Expr::UnresolvedLookupExprClass:
   case Expr::UnresolvedMemberExprClass:
   case Expr::TypoExprClass:
-  case Expr::RecoveryExprClass:
   case Expr::DependentCoawaitExprClass:
   case Expr::CXXDependentScopeMemberExprClass:
   case Expr::DependentScopeDeclRefExprClass:
@@ -276,6 +275,7 @@
   return Cl::CL_PRValue;
 }
 
+  case Expr::RecoveryExprClass:
   case Expr::OpaqueValueExprClass:
 return ClassifyExprValueKind(Lang, E, E->getValueKind());
 
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4779,8 +4779,10 @@
 
 RecoveryExpr::RecoveryExpr(ASTContext &Ctx, QualType T, SourceLocation BeginLoc,
SourceLocation EndLoc, ArrayRef SubExprs)
-: Expr(RecoveryExprClass, T, VK_LValue, OK_Ordinary), BeginLoc(BeginLoc),
-  EndLoc(EndLoc), NumExprs(SubExprs.size()) {
+: Expr(RecoveryExprClass, T.getNonReferenceType(),
+   T->isDependentType() ? VK_LValue : getValueKindForType(T),
+   OK_Ordinary),
+  BeginLoc(BeginLoc), EndLoc(EndLoc), NumExprs(SubExprs.size()) {
   assert(!T.isNull());
   assert(llvm::all_of(SubExprs, [](Expr* E) { return E != nullptr; }));
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 2 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2192
   R"cpp(
+class osstream {};
 struct X {

gribozavr2 wrote:
> eduucaldas wrote:
> > gribozavr2 wrote:
> > > I don't think we need a separate class to show the left shift operator. 
> > > The declaration below can be:
> > > 
> > > ```
> > >   friend X operator<<(X&, const X&);
> > > ```
> > If we don't bother much about "realistic" operator declarations we could 
> > drop all the `friend` and declare every operator in their most concise 
> > form. WDYT
> I think we shouldn't try to make tests realistic in terms of function names 
> etc., but we should try to cover as many different AST shapes as possible. In 
> the case of binary operators, we have three cases -- free function, friend 
> function, member function, that all generate slightly different ASTs, so I 
> believe we should try to cover them all.
But those all regard the operators declaration. 
Here we test the operator call expression - `CXXOperatorCallExpr`.

I think we should test friend function declarations when we add support for 
them in the tree, and then we add tests for declaration of friend operators, 
friend member functions and whatnot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954



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


[clang] bbea4d5 - clang: Don't show a trailing space with --version when not built from the repo

2020-07-08 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2020-07-08T14:02:02+02:00
New Revision: bbea4d5e6b82a683dccaa8f4916e2a44f5dd3490

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

LOG: clang: Don't show a trailing space with --version when not built from the 
repo

Reported here:
https://bugs.llvm.org/show_bug.cgi?id=38998#c15

Reviewers: hans

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

Added: 


Modified: 
clang/lib/Basic/Version.cpp

Removed: 




diff  --git a/clang/lib/Basic/Version.cpp b/clang/lib/Basic/Version.cpp
index c4b7d34ed168..286107cab9d7 100644
--- a/clang/lib/Basic/Version.cpp
+++ b/clang/lib/Basic/Version.cpp
@@ -97,8 +97,12 @@ std::string getClangToolFullVersion(StringRef ToolName) {
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << ToolName << " version " CLANG_VERSION_STRING " "
- << getClangFullRepositoryVersion();
+  OS << ToolName << " version " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
 
   return OS.str();
 }
@@ -111,7 +115,13 @@ std::string getClangFullCPPVersion() {
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
+  OS << "Clang " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
+
   return OS.str();
 }
 



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


[PATCH] D83386: clang: Don't show a trailing space with --version when not built from the repo

2020-07-08 Thread Sylvestre Ledru via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbbea4d5e6b82: clang: Don't show a trailing space with 
--version when not built from the repo (authored by sylvestre.ledru).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83386

Files:
  clang/lib/Basic/Version.cpp


Index: clang/lib/Basic/Version.cpp
===
--- clang/lib/Basic/Version.cpp
+++ clang/lib/Basic/Version.cpp
@@ -97,8 +97,12 @@
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << ToolName << " version " CLANG_VERSION_STRING " "
- << getClangFullRepositoryVersion();
+  OS << ToolName << " version " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
 
   return OS.str();
 }
@@ -111,7 +115,13 @@
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
+  OS << "Clang " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
+
   return OS.str();
 }
 


Index: clang/lib/Basic/Version.cpp
===
--- clang/lib/Basic/Version.cpp
+++ clang/lib/Basic/Version.cpp
@@ -97,8 +97,12 @@
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << ToolName << " version " CLANG_VERSION_STRING " "
- << getClangFullRepositoryVersion();
+  OS << ToolName << " version " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
 
   return OS.str();
 }
@@ -111,7 +115,13 @@
 #ifdef CLANG_VENDOR
   OS << CLANG_VENDOR;
 #endif
-  OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
+  OS << "Clang " CLANG_VERSION_STRING;
+
+  std::string repo = getClangFullRepositoryVersion();
+  if (!repo.empty()) {
+OS << " " << repo;
+  }
+
   return OS.str();
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83206: [PATCH] [ARM] Add Cortex-A78 and Cortex-X1 Support for Clang and LLVM

2020-07-08 Thread Luke Geeson via Phabricator via cfe-commits
LukeGeeson updated this revision to Diff 276383.
LukeGeeson marked 2 inline comments as done.
LukeGeeson added a comment.

Addressed Mikhail's feedback: Sorted CPU lists accordingly


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

https://reviews.llvm.org/D83206

Files:
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arm-cortex-cpus.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMSubtarget.cpp
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -262,6 +262,18 @@
  ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_FP16 |
  ARM::AEK_RAS | ARM::AEK_DOTPROD,
  "8.2-A"));
+  EXPECT_TRUE(testARMCPU("cortex-x1", "armv8.2-a", "crypto-neon-fp-armv8",
+ ARM::AEK_RAS | ARM::AEK_DOTPROD |
+ ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
+ ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
+ ARM::AEK_DSP | ARM::AEK_CRC | ARM::AEK_RAS,
+ "8.2-A"));
+  EXPECT_TRUE(testARMCPU("cortex-a78", "armv8.2-a", "crypto-neon-fp-armv8",
+ ARM::AEK_RAS | ARM::AEK_DOTPROD |
+ ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
+ ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | 
+ ARM::AEK_DSP | ARM::AEK_CRC | ARM::AEK_RAS,
+ "8.2-A"));
   EXPECT_TRUE(testARMCPU("neoverse-n1", "armv8.2-a", "crypto-neon-fp-armv8",
 ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
 ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
@@ -310,7 +322,7 @@
  "7-S"));
 }
 
-static constexpr unsigned NumARMCPUArchs = 87;
+static constexpr unsigned NumARMCPUArchs = 89;
 
 TEST(TargetParserTest, testARMCPUArchList) {
   SmallVector List;
@@ -865,6 +877,20 @@
   AArch64::AEK_LSE | AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
   AArch64::AEK_RCPC | AArch64::AEK_SSBS, "8.2-A"));
   EXPECT_TRUE(testAArch64CPU(
+  "cortex-a78", "armv8.2-a", "crypto-neon-fp-armv8",
+  AArch64::AEK_CRC | AArch64::AEK_CRYPTO  | AArch64::AEK_FP |
+  AArch64::AEK_RDM | AArch64::AEK_SIMD | AArch64::AEK_RAS |
+  AArch64::AEK_LSE | AArch64::AEK_DOTPROD |
+  AArch64::AEK_RCPC | AArch64::AEK_SSBS,
+  "8.2-A"));
+  EXPECT_TRUE(testAArch64CPU(
+  "cortex-x1", "armv8.2-a", "crypto-neon-fp-armv8",
+  AArch64::AEK_CRC | AArch64::AEK_CRYPTO | AArch64::AEK_FP |
+  AArch64::AEK_RDM | AArch64::AEK_SIMD | AArch64::AEK_RAS |
+  AArch64::AEK_LSE | AArch64::AEK_DOTPROD |
+  AArch64::AEK_RCPC | AArch64::AEK_SSBS,
+  "8.2-A"));
+  EXPECT_TRUE(testAArch64CPU(
   "cyclone", "armv8-a", "crypto-neon-fp-armv8",
   AArch64::AEK_CRYPTO | AArch64::AEK_FP | AArch64::AEK_SIMD, "8-A"));
   EXPECT_TRUE(testAArch64CPU(
@@ -1002,7 +1028,7 @@
   "8.2-A"));
 }
 
-static constexpr unsigned NumAArch64CPUArchs = 40;
+static constexpr unsigned NumAArch64CPUArchs = 42;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/ARM/ARMSubtarget.h
===
--- llvm/lib/Target/ARM/ARMSubtarget.h
+++ llvm/lib/Target/ARM/ARMSubtarget.h
@@ -62,6 +62,7 @@
 CortexA75,
 CortexA76,
 CortexA77,
+CortexA78,
 CortexA8,
 CortexA9,
 CortexM3,
@@ -70,6 +71,7 @@
 CortexR5,
 CortexR52,
 CortexR7,
+CortexX1,
 Exynos,
 Krait,
 Kryo,
Index: llvm/lib/Target/ARM/ARMSubtarget.cpp
===
--- llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -319,6 +319,9 @@
 PreISelOperandLatencyAdjustment = 1;
 PartialUpdateClearance = 12;
 break;
+  case CortexX1:
+  case CortexA78:
+break;
   }
 }
 
Index: llvm/lib/Target/ARM/ARM.td
===
--- llvm/lib/Target/ARM/ARM.td
+++ llvm/lib/Target/ARM/ARM.td
@@ -596,6 +596,10 @@
"Cortex-A76 ARM processors", []>;
 def ProcA77 : SubtargetFeature<"a77", "ARMProcFamily", "CortexA77",
"Cortex-A77 ARM processors", []>;
+def ProcX1  : SubtargetFeature<"cortex-x1", "ARMProcFamily", "CortexX1",
+   "Cortex-X1 ARM processors", []>;
+def ProcA78 : SubtargetFeature<"cortex-a78", "ARMPr

[PATCH] D83286: [analyzer][solver] Track symbol disequalities

2020-07-08 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@vsavchenko

> if a != b and b == C where C is a constant, a != C

Did you take into account that e.g. `a > b` also is a disequality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83286



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


[PATCH] D82646: [MSP430] Align the _Complex ABI with current msp430-gcc

2020-07-08 Thread Anton Korobeynikov via Phabricator via cfe-commits
asl added inline comments.



Comment at: clang/test/CodeGen/msp430-abi-complex.c:8
+
+void complex_float_arg_first(float _Complex x, int n) {
+// CHECK-LABEL: @complex_float_arg_first

What's about Complex Int?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82646



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


[PATCH] D83206: [PATCH] [ARM] Add Cortex-A78 and Cortex-X1 Support for Clang and LLVM

2020-07-08 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

I would expect this to be very similar to 
https://reviews.llvm.org/rG8bf99f1e6f0f9b426d6060361ea6d9d47c1868d1, but some 
parts seems to be missing. Can you make sure that everything is included and in 
a sensible order.




Comment at: llvm/include/llvm/Support/AArch64TargetParser.def:131
+AARCH64_CPU_NAME("cortex-a78", ARMV8_2A, FK_CRYPTO_NEON_FP_ARMV8, false,
+ (AArch64::AEK_RAS | AArch64::AEK_DOTPROD | AArch64::AEK_RCPC 
| AArch64::AEK_SSBS))
+AARCH64_CPU_NAME("cortex-x1", ARMV8_2A, FK_CRYPTO_NEON_FP_ARMV8, false,

This no longer has FP16?

AEK_RAS I believe should be included in ARMV8_2A,



Comment at: llvm/include/llvm/Support/ARMTargetParser.def:301
+ (ARM::AEK_RAS | ARM::AEK_DOTPROD))
+ARM_CPU_NAME("cortex-a78",ARMV8_2A, FK_CRYPTO_NEON_FP_ARMV8, false,
+ (ARM::AEK_RAS | ARM::AEK_DOTPROD))

All these can go in a better order, please. A78 can go next to A77. Same 
everywhere else.



Comment at: llvm/lib/Target/AArch64/AArch64Subtarget.cpp:196
+  case CortexX1:
+  case CortexA78:
+PrefFunctionLogAlignment = 4;

These can go with the other CortexAXX cpu's, which seem to set the same 
PrefFunctionLogAlignment. Same for the ARM equivalent.


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

https://reviews.llvm.org/D83206



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


[PATCH] D73242: [WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP

2020-07-08 Thread Eugene Leviant via Phabricator via cfe-commits
evgeny777 accepted this revision.
evgeny777 added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73242



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


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:2192
   R"cpp(
+class osstream {};
 struct X {

eduucaldas wrote:
> gribozavr2 wrote:
> > eduucaldas wrote:
> > > gribozavr2 wrote:
> > > > I don't think we need a separate class to show the left shift operator. 
> > > > The declaration below can be:
> > > > 
> > > > ```
> > > >   friend X operator<<(X&, const X&);
> > > > ```
> > > If we don't bother much about "realistic" operator declarations we could 
> > > drop all the `friend` and declare every operator in their most concise 
> > > form. WDYT
> > I think we shouldn't try to make tests realistic in terms of function names 
> > etc., but we should try to cover as many different AST shapes as possible. 
> > In the case of binary operators, we have three cases -- free function, 
> > friend function, member function, that all generate slightly different 
> > ASTs, so I believe we should try to cover them all.
> But those all regard the operators declaration. 
> Here we test the operator call expression - `CXXOperatorCallExpr`.
> 
> I think we should test friend function declarations when we add support for 
> them in the tree, and then we add tests for declaration of friend operators, 
> friend member functions and whatnot.
The call expression AST node can be meaningfully different between calls to 
member and non-member functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954



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


[PATCH] D82157: Fix crash on `user defined literals`

2020-07-08 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

> Fix crash on `user defined literals`

WDYT:

Implement support for user defined literals (which also fixes a crash)

> Given an UserDefinedLiteral 1.2_w:
>  Problem: Lexer generates one Token for the literal, but ClangAST
>  references two source locations
>  Fix: Ignore the operator and interpret it as the underlying literal.
>  e.g.: 1.2_w token generates syntax node IntegerLiteral(1.2_w)

WDYT:

A user defined literal (for example, `1.2_w`) is one token. The Clang AST for a 
user defined literal references two source locations: the beginning of the 
token (the location of `1` in `1.2_w`) and the beginning of the suffix (the 
location of `_`). When constructing the syntax tree, we were trying to find a 
token that starts at the underscore, but couldn't find one, and crashed on an 
assertion failure. To fix this issue, we ignore the Clang AST nodes for UDLs 
that have source locations that point in the middle of a token.




Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:634
+// `SourceLocation`s. As a result one of these nodes has a valid
+// `SourceLocation` that doesn't point to a token.
+//

"The semantic AST node for has child nodes that reference two source locations, 
the location of the beginning of the token (`1`), and the location of the 
beginning of the UDL suffix (`_`). The UDL suffix location does not point to 
the beginning of a token, so we can't represent the UDL suffix as a separate 
syntax tree node."



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1197-1199
+1.2_w; // calls operator "" _w(1.2L)
+12_w;  // calls operator "" _w("12")
+12_x;  // calls operator<'1', '2'> "" _x()

Indent -2.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1200
+12_x;  // calls operator<'1', '2'> "" _x()
+}
+)cpp",

Could you also add tests for user-defined string literals and user-defined 
character literals? ("abc"_mystr, u"abc"_mystr, 'c'_mychar)



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1265
+| |-UserDefinedLiteralExpression
+| | `-12_w
+| `-;

It looks somewhat weird to me that integer and floating point literals end up 
with the same syntax tree node type. WDYT about making different nodes for 
different literals (integer, floating-point, string, character)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82157



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


[PATCH] D82381: [analyzer] Introduce small improvements to the solver infra

2020-07-08 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko marked 3 inline comments as done.
vsavchenko added a comment.

Hi @ASDenysPetrov no problem at all!  Thanks for taking your time and checking 
it.




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:367-378
+RangeSet RangeSet::Delete(BasicValueFactory &BV, Factory &F,
+  const llvm::APSInt &Point) const {
+  llvm::APSInt Upper = Point;
+  llvm::APSInt Lower = Point;
+
+  ++Upper;
+  --Lower;

ASDenysPetrov wrote:
> Useful function. But I'd better rename it to `subtract` as we are working 
> with sets (as a mathimatical collection). We should have a such one for the 
> Ranges not only for Points.
> We have `intersect`, `delete` aka `subtract`. And we also need to have 
> functions `union` and `symmetricDifference` to cover full palette of common 
> operations on sets.
I agree that we should have a full set of functions.  I don't agree however, 
that this function is a `subtract`.  Subtract is an operation on two sets and 
here we have a set and a point.  One might argue that a point is just a very 
simple set, that's true, but real `subtract` would be more complex in its 
implementation.

Naming it `delete`, on the other hand, I was coming from a notion of deleting 
points or neighbourhoods 
(https://en.wikipedia.org/wiki/Neighbourhood_(mathematics)#Deleted_neighbourhood).



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:734
   //expressions which we currently do not know how to negate.
-  const RangeSet *getRangeForMinusSymbol(ProgramStateRef State, SymbolRef Sym) 
{
+  Optional getRangeForInvertedSub(SymbolRef Sym) {
 if (const SymSymExpr *SSE = dyn_cast(Sym)) {

ASDenysPetrov wrote:
> As for me, I'd call this like `getRangeForNegatedSymSymExpr`, since you do 
> Negate operation inside.
I'm not super happy about my name either, but I feel like it describes it 
better than the previous name and your version.  That function doesn't work for 
any `SymSymExpr` and it doesn't simply negate whatever we gave it.  It works 
specifically for symbolic subtractions and this is the information I want to be 
reflected in the name.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:841-844
+  RangeSet getTrueRange(QualType T) {
+RangeSet TypeRange = infer(T);
+return assumeNonZero(TypeRange, T);
+  }

ASDenysPetrov wrote:
> Don't you think this is too complicated for such a simple getter?
> Maybe we can just construct the range using smth about 
> `RangeSet(RangeFactory, ++Zero, --Zero);` ?
It is more complex than a false range but there is a reason for it.

First of all, `RangeSet` can't have ranges where the end is greater than its 
start.  Only `Intersect` can handle such ranges correctly.  Another thing is 
that ranges like that mean `[MIN, --Zero], [++Zero, MAX]` and without a type we 
can't really say what `MIN` and `MAX` are, so such constructor for `RangeSet` 
simply cannot exist.

Another point is that we do need to have `[MIN, -1], [+1, MAX]` as opposed to 
`[-1, -1], [+1, +1]` because of C language (it doesn't have boolean type), and 
because of the cases like `a - b` where we know that `a != b`.

I hope that answers the question.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82381



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

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



Comment at: clang/lib/CodeGen/BackendUtil.cpp:855
 
+class ClangCustomPassManager : public legacy::PassManager {
+public:

djtodoro wrote:
> vsk wrote:
> > Please factor out OptCustomPassManager from opt and generalize it so it can 
> > be used by both opt and clang. That should help ensure that extensions and 
> > bug fixes are only made to one custom 'debugify' pass manager.
> I'll try that with the latest code. I remember I've tried it once, but I 
> ended up moving it into the IR library (since we need to link it within 
> legacy pass manager).
Hi @vsk, I've posted the patch as D83391. Thanks!


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

https://reviews.llvm.org/D82547



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


[PATCH] D82547: [Debugify] Expose debugify (original mode) as CC1 option

2020-07-08 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro updated this revision to Diff 276398.
djtodoro added a comment.

- Rebase on top of D83391 


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

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/debugify-each-original.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -317,6 +317,16 @@
 
   $ llvm-debugify-original.py sample.json sample.html
 
+The `original` mode can be invoked from front-end level as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fenable-debugify-each-original -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fenable-debugify-each-original -Xclang -fenable-debugify-original-export=sample.json -g -O2 sample.c
+
 Using ``debugify``
 ^^
 
Index: clang/test/Driver/debugify-each-original.c
===
--- /dev/null
+++ clang/test/Driver/debugify-each-original.c
@@ -0,0 +1,14 @@
+// We support the CC1 options for testing whether each LLVM pass preserves
+// original debug info.
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY %s
+
+// DEBUGIFY: "-fenable-debugify-each-original"
+
+// RUN: %clang -g -Xclang -fenable-debugify-each-original \
+// RUN: -Xclang -fenable-debugify-original-export=%t.json -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=DEBUGIFY-JSON-EXPORT %s
+
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-each-original"
+// DEBUGIFY-JSON-EXPORT: "-fenable-debugify-original-export={{.*}}"
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -791,6 +791,16 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  Opts.EnableDebugifyEachOriginal =
+  Args.hasArg(OPT_fenable_debugify_each_original);
+  // Ignore the option if the -fenable-debugify-each-original wasn't enabled.
+  if (Opts.EnableDebugifyEachOriginal &&
+  Args.hasArg(OPT_fenable_debugify_original_export)) {
+  Opts.DIBugsReportFilePath =
+  std::string(
+  Args.getLastArgValue(OPT_fenable_debugify_original_export));
+  }
+
   Opts.DisableO0ImplyOptNone = Args.hasArg(OPT_disable_O0_optnone);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
   Opts.IndirectTlsSegRefs = Args.hasArg(OPT_mno_tls_direct_seg_refs);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -76,6 +76,7 @@
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
@@ -867,7 +868,14 @@
   if (TM)
 TheModule->setDataLayout(TM->createDataLayout());
 
-  legacy::PassManager PerModulePasses;
+  llvm::legacy::DebugifyCustomPassManager PerModulePasses;
+  if (CodeGenOpts.EnableDebugifyEachOriginal) {
+PerModulePasses.enableDebugifyEachOriginal();
+
+if (!CodeGenOpts.DIBugsReportFilePath.empty())
+  PerModulePasses.setDebugifyOriginalBugsReportFilePath(
+  CodeGenOpts.DIBugsReportFilePath);
+  }
   PerModulePasses.add(
   createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
 
Index: clang/include/clang/Driver/CC1Options.td
===
--- clang/include/clang/Driver/CC1Options.td
+++ clang/include/clang/Driver/CC1Options.td
@@ -389,6 +389,16 @@
 HelpText<"Prints debug information for the new pass manager">;
 def fno_debug_pass_manager : Flag<["-"], "fno-debug-pass-manager">,
 HelpText<"Disables debug printing for the new pass manager">;
+def fenable_debugify_each_original
+: Flag<["-"], "fenable-debugify-each-original">,
+  HelpText<"Enable Debug Info Metadata preservation testing in "
+   "optimizations.">;
+def fenable_debugify_original_export
+: Joined<["-"], "fenable-debugify-original-export=">,
+  MetaVarName<"">,
+  HelpText<"Export debugify (by testing original Debug Info) failures into "
+   "specified (JSON) file (should be abs path as we use "
+   "append

[PATCH] D79842: [clang][Driver] Correct tool search path priority

2020-07-08 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

Right, I see the issue.

The code that gets the default triple name 
(https://reviews.llvm.org/D13340?id=36227#inline-108606) looks up the one you 
have in cmake, not the actual default which you get in --version. We could 
"fix" this by doing so when we make the tool name as well, but this breaks 
whatever mips toolchain was using that. (their tools won't be 
mips-unknown-elf-)

So yes it looks up powerpc64le-linux-gnu but shows 
powerpc64le-unknown-linux-gnu. Can't go back to using cmake's value because on 
Mac OS, cmake has x86_64-darwin, clang has x86_64-darwin. Writing to 
both is a short term option so I will try that and fold it into 
https://reviews.llvm.org/D83055. (will add you on review once I update it)

(this whole default triple lookup should probably go but I'd really like to do 
that in its own commit)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79842



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


[PATCH] D83071: Add support for options with two flags for controlling the same field.

2020-07-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276400.
dang added a comment.

Split into two macro kinds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83071

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -61,8 +61,9 @@
 
 class MarshallingInfo {
 public:
-  static constexpr const char *MacroName = "OPTION_WITH_MARSHALLING";
+  using Ptr = std::unique_ptr;
 
+  const char *MacroName;
   const Record &R;
   bool ShouldAlwaysEmit;
   StringRef KeyPath;
@@ -78,6 +79,8 @@
   std::vector NormalizedValues;
   std::string ValueTableName;
 
+  static size_t NextTableIndex;
+
   static constexpr const char *ValueTablePreamble = R"(
 struct SimpleEnumValue {
   const char *Name;
@@ -93,7 +96,14 @@
   static constexpr const char *ValueTablesDecl =
   "static const SimpleEnumValueTable SimpleEnumValueTables[] = ";
 
-  void emit(raw_ostream &OS) const {
+  MarshallingInfo(const Record &R)
+  : MacroName("OPTION_WITH_MARSHALLING"), R(R) {}
+  MarshallingInfo(const char *MacroName, const Record &R)
+  : MacroName(MacroName), R(R){};
+
+  virtual ~MarshallingInfo() = default;
+
+  virtual void emit(raw_ostream &OS) const {
 write_cstring(OS, StringRef(getOptionSpelling(R)));
 OS << ", ";
 OS << ShouldAlwaysEmit;
@@ -131,53 +141,6 @@
 return StringRef(ValueTableName);
   }
 
-  static MarshallingInfo create(const Record &R) {
-assert(!isa(R.getValueInit("KeyPath")) &&
-   !isa(R.getValueInit("DefaultValue")) &&
-   !isa(R.getValueInit("NormalizerRetTy")) &&
-   !isa(R.getValueInit("ValueMerger")) &&
-   "MarshallingInfo must have a type");
-
-MarshallingInfo Ret(R);
-Ret.ShouldAlwaysEmit = R.getValueAsBit("ShouldAlwaysEmit");
-Ret.KeyPath = R.getValueAsString("KeyPath");
-Ret.DefaultValue = R.getValueAsString("DefaultValue");
-Ret.NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
-Ret.NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
-
-Ret.Normalizer = R.getValueAsString("Normalizer");
-Ret.Denormalizer = R.getValueAsString("Denormalizer");
-Ret.ValueMerger = R.getValueAsString("ValueMerger");
-Ret.ValueExtractor = R.getValueAsString("ValueExtractor");
-
-if (!isa(R.getValueInit("NormalizedValues"))) {
-  assert(!isa(R.getValueInit("Values")) &&
- "Cannot provide normalized values for value-less options");
-  Ret.TableIndex = NextTableIndex++;
-  Ret.NormalizedValues = R.getValueAsListOfStrings("NormalizedValues");
-  Ret.Values.reserve(Ret.NormalizedValues.size());
-  Ret.ValueTableName = getOptionName(R) + "ValueTable";
-
-  StringRef ValuesStr = R.getValueAsString("Values");
-  for (;;) {
-size_t Idx = ValuesStr.find(',');
-if (Idx == StringRef::npos)
-  break;
-if (Idx > 0)
-  Ret.Values.push_back(ValuesStr.slice(0, Idx));
-ValuesStr = ValuesStr.slice(Idx + 1, StringRef::npos);
-  }
-  if (!ValuesStr.empty())
-Ret.Values.push_back(ValuesStr);
-
-  assert(Ret.Values.size() == Ret.NormalizedValues.size() &&
- "The number of normalized values doesn't match the number of "
- "values");
-}
-
-return Ret;
-  }
-
 private:
   void emitScopedNormalizedValue(raw_ostream &OS,
  StringRef NormalizedValue) const {
@@ -185,13 +148,79 @@
   OS << NormalizedValuesScope << "::";
 OS << NormalizedValue;
   }
+};
+
+size_t MarshallingInfo::NextTableIndex = 0;
 
-  MarshallingInfo(const Record &R) : R(R){};
+class MarshallingInfoBooleanFlag : public MarshallingInfo {
+public:
+  const Record &NegOption;
 
-  static size_t NextTableIndex;
+  MarshallingInfoBooleanFlag(const Record &Option, const Record &NegOption)
+  : MarshallingInfo("OPTION_WITH_MARSHALLING_BOOLEAN", Option),
+NegOption(NegOption) {}
+
+  void emit(raw_ostream &OS) const override {
+MarshallingInfo::emit(OS);
+OS << ", ";
+OS << getOptionName(NegOption);
+OS << ", ";
+write_cstring(OS, getOptionSpelling(NegOption));
+  }
 };
 
-size_t MarshallingInfo::NextTableIndex = 0;
+static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) {
+  assert(!isa(R.getValueInit("KeyPath")) &&
+ !isa(R.getValueInit("DefaultValue")) &&
+ !isa(R.getValueInit("NormalizerRetTy")) &&
+ !isa(R.getValueInit("ValueMerger")) &&
+ "MarshallingInfo must have a type");
+
+  MarshallingInfo::Ptr Ret;
+  if (Record *MaybeNegOption = R.getValueAsOptionalDef("NegOption")) {
+Ret = std::make_unique(R, *MaybeNegOpti

[PATCH] D83362: Fix warning caused by __builtin_expect_with_probability was not handled in places such as constant folding

2020-07-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/Sema/builtin-expect-with-probability.cpp:12
+  }
+}  // should not emit warn "control may reach end of non-void function" here 
since expr is constantly true, so the "if(__bui..)" should be constantly true 
condition and be ignored
+

Please also validate this by doing some sort of test in a constexpr function if 
possible. That way you can make sure the parameter is evaluated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83362



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


[PATCH] D83286: [analyzer][solver] Track symbol disequalities

2020-07-08 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

In D83286#2138734 , @ASDenysPetrov 
wrote:

> Did you take into account that e.g. `a > b` also is a disequality.


It is a very good point! I didn't take them into account (yet?) because they 
make the implementation a bit harder.
Right now we can decide by the look of the assumption (or symbolic expression) 
if it's an equality/disequality check.  Later on, if we see an expression that 
looks like equality/disequality, we can try to see what we know about its 
operands.  So here we have a fairly easy table (2x2) of possible outcomes: if 
our current knowledge of the equality/disequality matches the current check - 
it's true, if it's opposite - it's false.

When it comes to things like `a > b`, we can consider it as disequality when we 
start tracking it because `a > b -> a != b`, but cannot in the second case 
because `a != b -/-> a > b`.  As the result, this beautiful symmetry that I use 
is gone and we need to add more data into `EqualityInfo` so we support the 
one-sidedness of that implication.

It is not a big change, but I would prefer making it separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83286



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


[PATCH] D82659: Fix missing build dependency on omp_gen.

2020-07-08 Thread Valentin Clement via Phabricator via cfe-commits
clementval added a comment.

In D82659#2138228 , @michele.scandale 
wrote:

> In D82659#2136999 , @clementval 
> wrote:
>
> > Looks good but just one question ... When clang is built as standalone it 
> > does not build the OpenMP part inside Clang? I haven't seen any code to 
> > avoid compiling the OpenMP parsing and semantic checking inside clang.
>
>
> I don't think there is a way to avoid compiling the OpenMP support in Clang. 
> The standalone build is just building the content of the `clang` directory as 
> a separate CMake project reusing the an already built LLVM -- therefore the 
> `libLLVMFrontendOpenMP` as well as the `OMP.h.inc` would have been generated 
> already.


Ok then your fix should work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82659



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


[PATCH] D83008: Fix ItaniumRecordLayoutBuilder so that is grabs the correct bases class offsets from the external source

2020-07-08 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:2197
 // least as many of them as possible).
 return RD->isTrivial() && RD->isCXX11StandardLayout();
   }

teemperor wrote:
> See here for the POD check that we might get wrong.
I don't believe we are getting this wrong or at least not in the original 
problem. Going back and checking it we seem to be getting this right.



Comment at: lldb/test/Shell/Expr/Inputs/layout.cpp:40
+  D2 d2;
+  D3 d3;
+

teemperor wrote:
> Do we actually need these locals in addition to the globals?
I left them in by accident.


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

https://reviews.llvm.org/D83008



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


[PATCH] D83301: [clang-tidy] More strict on matching the standard memset function in memset-usage check.

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D83301#2137140 , @njames93 wrote:

> If you want to be super explicit. Why not add `parameterCountIs(3)`?


good idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83301



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


[PATCH] D83301: [clang-tidy] More strict on matching the standard memset function in memset-usage check.

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 276405.
hokein added a comment.

add parameterCountIs(3).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83301

Files:
  clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memset-usage.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memset-usage.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memset-usage.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memset-usage.cpp
@@ -75,3 +75,8 @@
   // despite v == 0.
   memset(p, -1, v);
 }
+
+void *memset(int);
+void NoCrash() {
+  memset(1);
+}
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
@@ -20,11 +20,19 @@
 namespace bugprone {
 
 void SuspiciousMemsetUsageCheck::registerMatchers(MatchFinder *Finder) {
-  // Note: void *memset(void *buffer, int fill_char, size_t byte_count);
+  // Match the standard memset:
+  // void *memset(void *buffer, int fill_char, size_t byte_count);
+  auto MemsetDecl =
+  functionDecl(hasName("::memset"),
+   parameterCountIs(3),
+   hasParameter(0, hasType(pointerType(pointee(voidType(),
+   hasParameter(1, hasType(isInteger())),
+   hasParameter(2, hasType(isInteger(;
+
   // Look for memset(x, '0', z). Probably memset(x, 0, z) was intended.
   Finder->addMatcher(
   callExpr(
-  callee(functionDecl(hasName("::memset"))),
+  callee(MemsetDecl),
   hasArgument(1, characterLiteral(equals(static_cast('0')))
  .bind("char-zero-fill")),
   unless(
@@ -36,14 +44,14 @@
 
   // Look for memset with an integer literal in its fill_char argument.
   // Will check if it gets truncated.
-  Finder->addMatcher(callExpr(callee(functionDecl(hasName("::memset"))),
+  Finder->addMatcher(callExpr(callee(MemsetDecl),
   hasArgument(1, 
integerLiteral().bind("num-fill")),
   unless(isInTemplateInstantiation())),
  this);
 
   // Look for memset(x, y, 0) as that is most likely an argument swap.
   Finder->addMatcher(
-  callExpr(callee(functionDecl(hasName("::memset"))),
+  callExpr(callee(MemsetDecl),
unless(hasArgument(1, anyOf(characterLiteral(equals(
static_cast('0'))),
integerLiteral(,


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memset-usage.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memset-usage.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memset-usage.cpp
@@ -75,3 +75,8 @@
   // despite v == 0.
   memset(p, -1, v);
 }
+
+void *memset(int);
+void NoCrash() {
+  memset(1);
+}
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
@@ -20,11 +20,19 @@
 namespace bugprone {
 
 void SuspiciousMemsetUsageCheck::registerMatchers(MatchFinder *Finder) {
-  // Note: void *memset(void *buffer, int fill_char, size_t byte_count);
+  // Match the standard memset:
+  // void *memset(void *buffer, int fill_char, size_t byte_count);
+  auto MemsetDecl =
+  functionDecl(hasName("::memset"),
+   parameterCountIs(3),
+   hasParameter(0, hasType(pointerType(pointee(voidType(),
+   hasParameter(1, hasType(isInteger())),
+   hasParameter(2, hasType(isInteger(;
+
   // Look for memset(x, '0', z). Probably memset(x, 0, z) was intended.
   Finder->addMatcher(
   callExpr(
-  callee(functionDecl(hasName("::memset"))),
+  callee(MemsetDecl),
   hasArgument(1, characterLiteral(equals(static_cast('0')))
  .bind("char-zero-fill")),
   unless(
@@ -36,14 +44,14 @@
 
   // Look for memset with an integer literal in its fill_char argument.
   // Will check if it gets truncated.
-  Finder->addMatcher(callExpr(callee(functionDecl(hasName("::memset"))),
+  Finder->addMatcher(callExpr(callee(MemsetDecl),
   hasArgument(1, integerLiteral().bind("num-fill")),
   unless(isInTemplateInstantiation())),
  

[PATCH] D82756: Port some floating point options to new option marshalling infrastructure

2020-07-08 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1176
+defm reciprocal_math : OptInFFlag< "reciprocal-math", "Allow division 
operations to be reassociated", "", "", [], "LangOpts->AllowRecip">;
+def fapprox_func : Flag<["-"], "fapprox-func">, Group, 
Flags<[CC1Option, NoDriverOption]>,
+  MarshallingInfoFlag<"LangOpts->ApproxFunc", "false">;

could this also be OptInFFlag?



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2805
 CmdArgs.push_back("-menable-unsafe-fp-math");
+ApproxFunc = true;
+  }

Is this a bug fix ?



Comment at: clang/test/CodeGen/fp-function-attrs.cpp:2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffast-math -ffinite-math-only 
-menable-unsafe-fp-math \
+// RUN:   -menable-no-infs -menable-no-nans -fno-signed-zeros 
-freciprocal-math \
+// RUN:   -fapprox-func -mreassociate -ffp-contract=fast -emit-llvm -o - %s | 
FileCheck %s

Not clear why do you need to pass these extra flags now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82756



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


[PATCH] D83055: [clang][Driver] Fix tool path priority test failure

2020-07-08 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett updated this revision to Diff 276406.
DavidSpickett added a subscriber: stevewan.
DavidSpickett added a comment.

- Write to cmake and clang's default triple to also fix failure reported by 
@stevewan.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83055

Files:
  clang/test/Driver/program-path-priority.c
  clang/test/lit.cfg.py

Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -46,6 +46,8 @@
 config.substitutions.append(
 ('%src_include_dir', config.clang_src_dir + '/include'))
 
+config.substitutions.append(
+('%target_triple', config.target_triple))
 
 # Propagate path to symbolizer for ASan/MSan.
 llvm_config.with_system_environment(
Index: clang/test/Driver/program-path-priority.c
===
--- clang/test/Driver/program-path-priority.c
+++ clang/test/Driver/program-path-priority.c
@@ -13,6 +13,11 @@
 /// so only name priority is accounted for, unless we fail to find
 /// anything at all in the prefix.
 
+/// Note: All matches are expected to be at the end of file paths.
+/// So we match " on the end to account for build systems that
+/// put the name of the compiler in the build path.
+/// E.g. /build/gcc_X.Y.Z/0/...
+
 /// Symlink clang to a new dir which will be its
 /// "program path" for these tests
 // RUN: rm -rf %t && mkdir -p %t
@@ -21,14 +26,18 @@
 /// No gccs at all, nothing is found
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NO_NOTREAL_GCC %s
-// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc
-// NO_NOTREAL_GCC-NOT: /gcc
+// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc"
+/// Some systems will have "gcc-x.y.z" so for this first check
+/// make sure we don't find "gcc" or "gcc-x.y.z". If we do find either
+/// then there is no point continuing as this copy of clang is not
+/// isolated as we expected.
+// NO_NOTREAL_GCC-NOT: {{/gcc[^/]*"}}
 
 /// -gcc in program path is found
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=PROG_PATH_NOTREAL_GCC %s
-// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc
+// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc"
 
 /// -gcc on the PATH is found
 // RUN: mkdir -p %t/env
@@ -36,74 +45,85 @@
 // RUN: touch %t/env/notreal-none-elf-gcc && chmod +x %t/env/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s
-// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc
+// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc"
 
 /// -gcc in program path is preferred to one on the PATH
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=BOTH_NOTREAL_GCC %s
-// BOTH_NOTREAL_GCC: notreal-none-elf-gcc
-// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc
+// BOTH_NOTREAL_GCC: notreal-none-elf-gcc"
+// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc"
 
 /// On program path, -gcc is preferred to plain gcc
 // RUN: touch %t/gcc && chmod +x %t/gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_GCC_PREFERRED %s
-// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc
-// NOTREAL_GCC_PREFERRED-NOT: /gcc
+// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc"
+// NOTREAL_GCC_PREFERRED-NOT: /gcc"
 
 /// -gcc on the PATH is preferred to gcc in program path
 // RUN: rm %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PROG %s
-// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc
-// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc
+// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc"
+// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc"
 
 /// -gcc on the PATH is preferred to gcc on the PATH
 // RUN: rm %t/gcc
 // RUN: touch %t/env/gcc && chmod +x %t/env/gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PATH %s
-// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc
-// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc
+// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc"
+// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc"
+
+/// We cannot trust clang --version, or cmake's LLVM_DEFAULT_TARGET_TRIPLE
+/// to give us the one and only default triple.
+/// Can't trust cmake because on Darwin, triples have a verison appended to them.
+/// (and clang uses the versioned string to search)
+/// Can't trust --version because it will pad 3 item triples to 4 e.g.
+/// powerpc64le-linux-gnu -> powerpc64le-unkn

[PATCH] D83055: [clang][Driver] Fix tool path priority test failures

2020-07-08 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

For the record my logic here is that I could change the tool names to use the 
same name as --version. However that will break whatever mips toolchain needed 
this code in the first place. 
(https://reviews.llvm.org/D13340?id=36227#inline-108606)

This default triple lookup code had some support to be removed anyway, so I'd 
rather patch up this test first before doing so. So that it's easier to roll 
back if there are still users of it. Having tests of the existing behaviour is 
a good thing and I don't think writing to both potential default triples 
undermines that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83055



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


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276408.
eduucaldas marked an inline comment as done.
eduucaldas added a comment.

Switch to `TraverseCXXOperatorCallExpr`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `

[PATCH] D83008: Fix ItaniumRecordLayoutBuilder so that is grabs the correct bases class offsets from the external source

2020-07-08 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 276407.
shafik added a comment.

Moved from shell test


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

https://reviews.llvm.org/D83008

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  lldb/test/API/lang/cpp/alignas_base_class/Makefile
  lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
  lldb/test/API/lang/cpp/alignas_base_class/main.cpp


Index: lldb/test/API/lang/cpp/alignas_base_class/main.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/alignas_base_class/main.cpp
@@ -0,0 +1,13 @@
+struct B1 {
+  char f1;
+};
+
+struct alignas(8) B2 {
+  char f2;
+};
+
+struct D : B1, B2 {};
+
+D d3g;
+
+int main() {}
Index: lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
===
--- /dev/null
+++ lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
@@ -0,0 +1,16 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@no_debug_info_test
+def test(self):
+self.build()
+self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+
+# The offset of f2 should be 8 because of `alignas(8)`.
+self.expect_expr("(intptr_t)&d3g.f2 - (intptr_t)&d3g", 
result_value="8")
Index: lldb/test/API/lang/cpp/alignas_base_class/Makefile
===
--- /dev/null
+++ lldb/test/API/lang/cpp/alignas_base_class/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1187,11 +1187,10 @@
   // Query the external layout to see if it provides an offset.
   bool HasExternalLayout = false;
   if (UseExternalLayout) {
-// FIXME: This appears to be reversed.
 if (Base->IsVirtual)
-  HasExternalLayout = External.getExternalNVBaseOffset(Base->Class, 
Offset);
-else
   HasExternalLayout = External.getExternalVBaseOffset(Base->Class, Offset);
+else
+  HasExternalLayout = External.getExternalNVBaseOffset(Base->Class, 
Offset);
   }
 
   // Clang <= 6 incorrectly applied the 'packed' attribute to base classes.


Index: lldb/test/API/lang/cpp/alignas_base_class/main.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/alignas_base_class/main.cpp
@@ -0,0 +1,13 @@
+struct B1 {
+  char f1;
+};
+
+struct alignas(8) B2 {
+  char f2;
+};
+
+struct D : B1, B2 {};
+
+D d3g;
+
+int main() {}
Index: lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
===
--- /dev/null
+++ lldb/test/API/lang/cpp/alignas_base_class/TestAlignAsBaseClass.py
@@ -0,0 +1,16 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@no_debug_info_test
+def test(self):
+self.build()
+self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+
+# The offset of f2 should be 8 because of `alignas(8)`.
+self.expect_expr("(intptr_t)&d3g.f2 - (intptr_t)&d3g", result_value="8")
Index: lldb/test/API/lang/cpp/alignas_base_class/Makefile
===
--- /dev/null
+++ lldb/test/API/lang/cpp/alignas_base_class/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1187,11 +1187,10 @@
   // Query the external layout to see if it provides an offset.
   bool HasExternalLayout = false;
   if (UseExternalLayout) {
-// FIXME: This appears to be reversed.
 if (Base->IsVirtual)
-  HasExternalLayout = External.getExternalNVBaseOffset(Base->Class, Offset);
-else
   HasExternalLayout = External.getExternalVBaseOffset(Base->Class, Offset);
+else
+  HasExternalLayout = External.getExternalNVBaseOffset(Base->Class, Offset);
   }
 
   // Clang <= 6 incorrectly applied the 'packed' attribute to base classes.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83008: Fix ItaniumRecordLayoutBuilder so that is grabs the correct bases class offsets from the external source

2020-07-08 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor accepted this revision.
teemperor added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for the patch!


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

https://reviews.llvm.org/D83008



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


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:820
+  // A postfix unary operator is declared as taking two operands. The
+  // second operand is used to differ from its prefix counterpart. In the
+  // semantic AST this "phantom" operand is represented as a

"is used to distinguish"



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:823
+  // `IntegerLiteral` with invalid `SourceLocation`. We skip visiting this
+  // operand because we are not able to generate a syntax node from a
+  // semantic node with an invalid `SourceLocation`.

"... because does not correspond to anything written in the source code"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954



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


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 276411.
eduucaldas marked 2 inline comments as done.
eduucaldas added a comment.

minor fix comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-Co

[PATCH] D81583: Update SystemZ ABI to handle C++20 [[no_unique_address]] attribute

2020-07-08 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand updated this revision to Diff 276414.
uweigand added a comment.

Handle array of empty records correctly.


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

https://reviews.llvm.org/D81583

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/systemz-abi.cpp

Index: clang/test/CodeGen/systemz-abi.cpp
===
--- clang/test/CodeGen/systemz-abi.cpp
+++ clang/test/CodeGen/systemz-abi.cpp
@@ -23,3 +23,37 @@
 // CHECK-LABEL: define void @_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias sret align 4 %{{.*}}, float %{{.*}})
 // SOFT-FLOAT-LABEL:  define void @_Z18pass_agg_float_cpp13agg_float_cpp(%struct.agg_float_cpp* noalias sret align 4 %{{.*}}, i32 %{{.*}})
 
+
+// A field member of empty class type in C++ makes the record nonhomogeneous,
+// unless it is marked as [[no_unique_address]].  This does not apply to arrays.
+struct empty { };
+struct agg_nofloat_empty { float a; empty dummy; };
+struct agg_nofloat_empty pass_agg_nofloat_empty(struct agg_nofloat_empty arg) { return arg; }
+// CHECK-LABEL: define void @_Z22pass_agg_nofloat_empty17agg_nofloat_empty(%struct.agg_nofloat_empty* noalias sret align 4 %{{.*}}, i64 %{{.*}})
+// SOFT-FLOAT-LABEL:  define void @_Z22pass_agg_nofloat_empty17agg_nofloat_empty(%struct.agg_nofloat_empty* noalias sret align 4 %{{.*}}, i64 %{{.*}})
+struct agg_float_empty { float a; [[no_unique_address]] empty dummy; };
+struct agg_float_empty pass_agg_float_empty(struct agg_float_empty arg) { return arg; }
+// CHECK-LABEL: define void @_Z20pass_agg_float_empty15agg_float_empty(%struct.agg_float_empty* noalias sret align 4 %{{.*}}, float %{{.*}})
+// SOFT-FLOAT-LABEL:  define void @_Z20pass_agg_float_empty15agg_float_empty(%struct.agg_float_empty* noalias sret align 4 %{{.*}}, i32 %{{.*}})
+struct agg_nofloat_emptyarray { float a; [[no_unique_address]] empty dummy[3]; };
+struct agg_nofloat_emptyarray pass_agg_nofloat_emptyarray(struct agg_nofloat_emptyarray arg) { return arg; }
+// CHECK-LABEL: define void @_Z27pass_agg_nofloat_emptyarray22agg_nofloat_emptyarray(%struct.agg_nofloat_emptyarray* noalias sret align 4 %{{.*}}, i64 %{{.*}})
+// SOFT-FLOAT-LABEL:  define void @_Z27pass_agg_nofloat_emptyarray22agg_nofloat_emptyarray(%struct.agg_nofloat_emptyarray* noalias sret align 4 %{{.*}}, i64 %{{.*}})
+
+// And likewise for members of base classes.
+struct noemptybase { empty dummy; };
+struct agg_nofloat_emptybase : noemptybase { float a; };
+struct agg_nofloat_emptybase pass_agg_nofloat_emptybase(struct agg_nofloat_emptybase arg) { return arg; }
+// CHECK-LABEL: define void @_Z26pass_agg_nofloat_emptybase21agg_nofloat_emptybase(%struct.agg_nofloat_emptybase* noalias sret align 4 %{{.*}}, i64 %{{.*}})
+// SOFT-FLOAT-LABEL:  define void @_Z26pass_agg_nofloat_emptybase21agg_nofloat_emptybase(%struct.agg_nofloat_emptybase* noalias sret align 4 %{{.*}}, i64 %{{.*}})
+struct emptybase { [[no_unique_address]] empty dummy; };
+struct agg_float_emptybase : emptybase { float a; };
+struct agg_float_emptybase pass_agg_float_emptybase(struct agg_float_emptybase arg) { return arg; }
+// CHECK-LABEL: define void @_Z24pass_agg_float_emptybase19agg_float_emptybase(%struct.agg_float_emptybase* noalias sret align 4 %{{.*}}, float %{{.*}})
+// SOFT-FLOAT-LABEL:  define void @_Z24pass_agg_float_emptybase19agg_float_emptybase(%struct.agg_float_emptybase* noalias sret align 4 %{{.*}}, i32 %{{.*}})
+struct noemptybasearray { [[no_unique_address]] empty dummy[3]; };
+struct agg_nofloat_emptybasearray : noemptybasearray { float a; };
+struct agg_nofloat_emptybasearray pass_agg_nofloat_emptybasearray(struct agg_nofloat_emptybasearray arg) { return arg; }
+// CHECK-LABEL: define void @_Z31pass_agg_nofloat_emptybasearray26agg_nofloat_emptybasearray(%struct.agg_nofloat_emptybasearray* noalias sret align 4 %{{.*}}, i64 %{{.*}})
+// SOFT-FLOAT-LABEL:  define void @_Z31pass_agg_nofloat_emptybasearray26agg_nofloat_emptybasearray(%struct.agg_nofloat_emptybasearray* noalias sret align 4 %{{.*}}, i64 %{{.*}})
+
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -486,12 +486,13 @@
   return Ctx.getOrInsertSyncScopeID(""); /* default sync scope */
 }
 
-static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays);
+static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,
+  bool AllowNoUniqueAddr = false);
 
 /// isEmptyField - Return true iff a the field is "empty", that is it
 /// is an unnamed bit-field or an (array of) empty record(s).
 static bool isEmptyField(ASTContext &Context, const FieldDecl *FD,
- bool AllowArrays) {
+ bool AllowArrays, bool AllowNoUniqueAddr = false) {
   if (FD->isUnnamedBitfield())
 return true;
 
@@ -499,11 +500,15 @@
 
   // Consta

[PATCH] D80514: [clang-tidy] modernize-use-trailing-return-type support for C++20 concepts and decltype

2020-07-08 Thread Bernhard Manfred Gruber via Phabricator via cfe-commits
bernhardmgruber added a comment.

Ping.

Is there anything I am not seeing here that you still would like me to do? I 
feel like you are waiting for something obvious from my side :S.


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

https://reviews.llvm.org/D80514



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


[PATCH] D81583: Update SystemZ ABI to handle C++20 [[no_unique_address]] attribute

2020-07-08 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand marked 6 inline comments as done.
uweigand added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:521
+  // [[no_unique_address]] attribute (since C++20).  Those do count
+  // as empty according to the Itanium ABI.  This property is currently
+  // only respected if the AllowNoUniqueAddr parameter is true.

hubert.reinterpretcast wrote:
> This check is being done after removal of the array types by `AllowArrays`, 
> so this code is also conferring the property of being empty to arrays. It 
> seems GCC erroneously does the same for base class fields (but not for direct 
> members).
> 
> ```
> struct Empty {};
> 
> struct A {
>   Empty emp [[no_unique_address]][3];
> };
> 
> struct B : A {
>   float f;
> };
> 
> struct C {
>   Empty emp [[no_unique_address]][3];
>   float f;
> };
> 
> extern char szb[sizeof(B)];
> extern char szb[sizeof(float)]; // GCC likes this
> extern char szc[sizeof(C)];
> extern char szc[sizeof(float)]; // GCC does not like this
> ```
> 
> Compiler Explorer link: https://godbolt.org/z/NFuca9
This version should fix clang; I agree that GCC still gets this wrong.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:524
+  if (isa(RT->getDecl()) &&
+  !(AllowNoUniqueAddr && FD->hasAttr()))
 return false;

efriedma wrote:
> Does this do the right thing with a field that's an array of empty classes?
You're right.  As Hubert notes, arrays of empty classes do not count as empty.  
This version should fix the problem.  



Comment at: clang/lib/CodeGen/TargetInfo.cpp:7245
   // do count.  So do anonymous bitfields that aren't zero-sized.
-  if (getContext().getLangOpts().CPlusPlus &&
-  FD->isZeroLengthBitField(getContext()))
-continue;
+  if (getContext().getLangOpts().CPlusPlus) {
+if (FD->isZeroLengthBitField(getContext()))

efriedma wrote:
> Only loosely relevant to this patch, but checking getLangOpts().CPlusPlus 
> here seems weird; doesn't that break calling functions defined in C from C++ 
> code?
I agree that this difference between C and C++ is weird, but it does match the 
behavior of GCC.  (Which is itself weird, but a long-standing accident that we 
probably cannot fix without breaking existing code at this point.)

Now, you bring up an interesting point: When C++ code calls a function defined 
in C code, the C++ part would have to refer to an `extern "C"` declaration.  
The correct thing to do would probably be to handle those according to the C 
ABI rules, not the C++ rules, in this case where the two differ.  But currently 
GCC doesn't do that either.  (But since that would be broken anyway, I think we 
**can** fix that.)  In any case, I agree that this is really a separate 
problem, distinct from this patch.


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

https://reviews.llvm.org/D81583



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


[PATCH] D78655: [CUDA][HIP] Let lambda be host device by default

2020-07-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 276417.
yaxunl added a comment.

revised by Artem's comments


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

https://reviews.llvm.org/D78655

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCUDA/lambda.cu
  clang/test/SemaCUDA/Inputs/cuda.h
  clang/test/SemaCUDA/lambda.cu

Index: clang/test/SemaCUDA/lambda.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/lambda.cu
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=com %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev %s
+
+#include "Inputs/cuda.h"
+
+auto global_lambda = [] () { return 123; };
+
+template
+__global__ void kernel(F f) { f(); }
+// dev-note@-1 7{{called by 'kernel<(lambda}}
+
+__host__ __device__ void hd(int x);
+
+class A {
+  int b;
+public:
+  void test() {
+[=](){ hd(b); }();
+
+[&](){ hd(b); }();
+
+kernel<<<1,1>>>([](){ hd(0); });
+
+kernel<<<1,1>>>([=](){ hd(b); });
+// dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
+
+kernel<<<1,1>>>([&](){ hd(b); });
+// dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
+
+kernel<<<1,1>>>([&] __device__ (){ hd(b); });
+// dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
+
+kernel<<<1,1>>>([&](){
+  auto f = [&]{ hd(b); };
+  // dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
+  f();
+});
+  }
+};
+
+int main(void) {
+  auto lambda_kernel = [&]__global__(){};
+  // com-error@-1 {{kernel function 'operator()' must be a free function or static member function}}
+
+  int b;
+  [&](){ hd(b); }();
+
+  [=, &b](){ hd(b); }();
+
+  kernel<<<1,1>>>(global_lambda);
+
+  kernel<<<1,1>>>([](){ hd(0); });
+
+  kernel<<<1,1>>>([=](){ hd(b); });
+
+  kernel<<<1,1>>>([b](){ hd(b); });
+
+  kernel<<<1,1>>>([&](){ hd(b); });
+  // dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
+
+  kernel<<<1,1>>>([=, &b](){ hd(b); });
+  // dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
+
+  kernel<<<1,1>>>([&, b](){ hd(b); });
+
+  kernel<<<1,1>>>([&](){
+  auto f = [&]{ hd(b); };
+  // dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
+  f();
+  });
+
+  return 0;
+}
Index: clang/test/SemaCUDA/Inputs/cuda.h
===
--- clang/test/SemaCUDA/Inputs/cuda.h
+++ clang/test/SemaCUDA/Inputs/cuda.h
@@ -17,6 +17,19 @@
   __host__ __device__ dim3(unsigned x, unsigned y = 1, unsigned z = 1) : x(x), y(y), z(z) {}
 };
 
+#ifdef __HIP__
+typedef struct hipStream *hipStream_t;
+typedef enum hipError {} hipError_t;
+int hipConfigureCall(dim3 gridSize, dim3 blockSize, size_t sharedSize = 0,
+ hipStream_t stream = 0);
+extern "C" hipError_t __hipPushCallConfiguration(dim3 gridSize, dim3 blockSize,
+ size_t sharedSize = 0,
+ hipStream_t stream = 0);
+extern "C" hipError_t hipLaunchKernel(const void *func, dim3 gridDim,
+  dim3 blockDim, void **args,
+  size_t sharedMem,
+  hipStream_t stream);
+#else
 typedef struct cudaStream *cudaStream_t;
 typedef enum cudaError {} cudaError_t;
 
@@ -29,6 +42,7 @@
 extern "C" cudaError_t cudaLaunchKernel(const void *func, dim3 gridDim,
 dim3 blockDim, void **args,
 size_t sharedMem, cudaStream_t stream);
+#endif
 
 // Host- and device-side placement new overloads.
 void *operator new(__SIZE_TYPE__, void *p) { return p; }
Index: clang/test/CodeGenCUDA/lambda.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/lambda.cu
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -x hip -emit-llvm -std=c++11 %s -o - \
+// RUN:   -triple x86_64-linux-gnu \
+// RUN:   | FileCheck -check-prefix=HOST %s
+// RUN: %clang_cc1 -x hip -emit-llvm -std=c++11 %s -o - \
+// RUN:   -triple amdgcn-amd-amdhsa -fcuda-is-device \
+// RUN:   | FileCheck -check-prefix=DEV %s
+
+#include "Inputs/cuda.h"
+
+// Device side kernel name.
+// HOST: @[[KERN_CAPTURE:[0-9]+]] = {{.*}} c"_Z1gIZ12test_capturevEUlvE_EvT_\00"
+// HOST: @[[KERN_RESOLVE:[0-9]+]] = {{.*}} c"_Z1gIZ12test_resolvevEUlvE_EvT_\00"
+
+// Check functions emitted for test_capture in host compilation.
+// Check lambda is not emitted in host comp

[PATCH] D81003: [clang] SequenceChecker: Also visit default arguments and default initializers.

2020-07-08 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

@rsmith I have modified this patch to address your comment above (we should 
track where default argument(s) and/or default member initializer(s) were 
used). You accepted this originally but I would like to make sure that you are 
happy with the updated patch.

I was also confused for a while about the example:

  int a;
  struct S { int b = ++a; };
  void Test() {
int c = S{}.b + a; // Warn in C++14 and above, but not before.
  }

I *think* that this should warn in C++14 and above, because `S` is an aggregate 
in C++14 and above, and the default member initializers of an aggregate are 
also part of the full-expression containing the initialization of the aggregate 
(`[intro.execution]p12`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81003



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


[PATCH] D81583: Update SystemZ ABI to handle C++20 [[no_unique_address]] attribute

2020-07-08 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand marked 2 inline comments as done.
uweigand added a comment.

In D81583#2137277 , @efriedma wrote:

> I'm tempted to say this is a bugfix for the implementation of 
> no_unique_address, and just fix it globally for all ABIs.  We're never going 
> to get anything done here if we require a separate patch for each ABI variant 
> clang supports.


Well, I can certainly do that.  Would you prefer me to completely remove the 
AllowNoUniqueAddress parameter, or keep it but default to true (so ABIs can 
still override if necessary)?


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

https://reviews.llvm.org/D81583



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


[PATCH] D78655: [CUDA][HIP] Let lambda be host device by default

2020-07-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 3 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/Sema/SemaCUDA.cpp:757-759
+  // In host compilation, deferred diagnostics are only emitted for functions
+  // which are sure to be emitted on host side since there is no reliable
+  // way to check if a function is emitted on device side. Therefore in

tra wrote:
> I don't think this is completely correct. Postponed diags get emitted if we 
> know we're attempoting to codegen wrong things.
> E.g. during host compilation when HD function used by host code ends up 
> attempting to call a device function.
> It also works in the other direction -- it kicks in during device compilation 
> when HD function calls a host function.
> AFAICT it has nothing to do with what happens on the other side of the 
> compilation, but rather what we're attempting to codegen during *this* 
> compilation.
> 
> I don't think that we can reason that checks can be done on the host side 
> only, based only on the argument you're making above (at least based on the 
> way I understand it).
> 
> The point you're making below that a captured lambda created by device code 
> can't ever be used by the host code is probably a better argument why the 
> check may not be necessary.
> 
Revised the comments.


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

https://reviews.llvm.org/D78655



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


[PATCH] D81583: Update SystemZ ABI to handle C++20 [[no_unique_address]] attribute

2020-07-08 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

In D81583#2138127 , @qiucf wrote:

> Thanks for this patch!
>
> If I understand correctly, only `isEmptyRecord`/`isEmptyField` and places 
> checking any field is zero bit-width may need change for this? Since 
> `isSingleElementStruct` and `isHomogeneousAggregate` just use them to skip 
> empty fields in aggregate. I didn't see direct checking for empty fields on 
> PowerPC. So all change needed on PPC seems to be generic. By enabling 
> `AllowNoUniqueAddr` in these methods, case in 
> https://lists.llvm.org/pipermail/llvm-dev/2020-July/143141.html can be 
> correctly recognized as homogeneous aggregate.


I agree that probably the only required change is to set the 
`AllowNoUniqueAddr` parameter to true in those methods.  Given the discussion 
with @efriedma above, that may actually happen automatically if we remove the 
parameter (or default it to true).

In any case, I guess it would still be good to also have test cases for this 
aspect of the ABI on Power ...


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

https://reviews.llvm.org/D81583



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


[PATCH] D83079: [clang][aarch64] Generate preprocessor macros for -march=armv8.6a+sve.

2020-07-08 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli marked 2 inline comments as done.
fpetrogalli added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:369
+  if (llvm::is_contained(Features, "+v8.6a")) {
+if (!llvm::is_contained(Features, "-i8mm") &&
+!llvm::is_contained(Features, "+noi8mm"))

sdesmalen wrote:
> Is this correct and/or necessary? I would expect LLVM to just handle features 
> in the order they're passed, and the architecture version is always processed 
> first, e.g. `-march=armv8.6-a+noi8mm` will always first process `armv8.6a` 
> before processing features like `noi8mm`.
I was expecting that too, but in in this place the `+i8mm` is added after 
whatever the user have passed to -march, which means that without this extra 
check the user input `-mattr=armv8.6a+sve+noimm8` becomes broken because we are 
adding `-target-feature=+i8mm` after `-i8mm`.  This behavior is guarded by a 
regression tests that starts failing if I don't use these extra checks. This 
was not needed in the original place were I added the functionality because the 
`+i8mm` was being added right after `+v8.6a` and before splitting up the 
`+sve+noi8mm`, so that the user input was the one (un)setting the feature.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83079



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


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGea8bba7e8d0d: Fix crash on overloaded postfix unary 
operators due to invalid sloc (authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+ 

[clang] ea8bba7 - Fix crash on overloaded postfix unary operators due to invalid sloc

2020-07-08 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-07-08T14:09:40Z
New Revision: ea8bba7e8d0db3541a386ad649c4bf21d53e8380

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

LOG: Fix crash on overloaded postfix unary operators due to invalid sloc

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 4371a303bb9d..361455e69f5a 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TypeLoc.h"
@@ -114,6 +115,85 @@ struct GetStartLoc : TypeLocVisitor {
 };
 } // namespace
 
+static syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr &E) {
+  switch (E.getOperator()) {
+  // Comparison
+  case OO_EqualEqual:
+  case OO_ExclaimEqual:
+  case OO_Greater:
+  case OO_GreaterEqual:
+  case OO_Less:
+  case OO_LessEqual:
+  case OO_Spaceship:
+  // Assignment
+  case OO_Equal:
+  case OO_SlashEqual:
+  case OO_PercentEqual:
+  case OO_CaretEqual:
+  case OO_PipeEqual:
+  case OO_LessLessEqual:
+  case OO_GreaterGreaterEqual:
+  case OO_PlusEqual:
+  case OO_MinusEqual:
+  case OO_StarEqual:
+  case OO_AmpEqual:
+  // Binary computation
+  case OO_Slash:
+  case OO_Percent:
+  case OO_Caret:
+  case OO_Pipe:
+  case OO_LessLess:
+  case OO_GreaterGreater:
+  case OO_AmpAmp:
+  case OO_PipePipe:
+  case OO_ArrowStar:
+  case OO_Comma:
+return syntax::NodeKind::BinaryOperatorExpression;
+  case OO_Tilde:
+  case OO_Exclaim:
+return syntax::NodeKind::PrefixUnaryOperatorExpression;
+  // Prefix/Postfix increment/decrement
+  case OO_PlusPlus:
+  case OO_MinusMinus:
+switch (E.getNumArgs()) {
+case 1:
+  return syntax::NodeKind::PrefixUnaryOperatorExpression;
+case 2:
+  return syntax::NodeKind::PostfixUnaryOperatorExpression;
+default:
+  llvm_unreachable("Invalid number of arguments for operator");
+}
+  // Operators that can be unary or binary
+  case OO_Plus:
+  case OO_Minus:
+  case OO_Star:
+  case OO_Amp:
+switch (E.getNumArgs()) {
+case 1:
+  return syntax::NodeKind::PrefixUnaryOperatorExpression;
+case 2:
+  return syntax::NodeKind::BinaryOperatorExpression;
+default:
+  llvm_unreachable("Invalid number of arguments for operator");
+}
+return syntax::NodeKind::BinaryOperatorExpression;
+  // Not yet supported by SyntaxTree
+  case OO_New:
+  case OO_Delete:
+  case OO_Array_New:
+  case OO_Array_Delete:
+  case OO_Coawait:
+  case OO_Call:
+  case OO_Subscript:
+  case OO_Arrow:
+return syntax::NodeKind::UnknownExpression;
+  case OO_Conditional: // not overloadable
+  case NUM_OVERLOADED_OPERATORS:
+  case OO_None:
+llvm_unreachable("Not an overloadable operator");
+  }
+}
+
 /// Gets the range of declarator as defined by the C++ grammar. E.g.
 /// `int a;` -> range of `a`,
 /// `int *a;` -> range of `*a`,
@@ -733,8 +813,29 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
+if (getOperatorNodeKind(*S) ==
+syntax::NodeKind::PostfixUnaryOperatorExpression) {
+  // A postfix unary operator is declared as taking two operands. The 
second
+  // operand is used to distinguish from its prefix counterpart. In the
+  // semantic AST this "phantom" operand is represented as a
+  // `IntegerLiteral` with invalid `SourceLocation`. We skip visiting this
+  // operand because it does not correspond to anything written in source
+  // code
+  for (auto *child : S->children()) {
+if (child->getSourceRange().isInvalid())
+  continue;
+if (!TraverseStmt(child))
+  return false;
+  }
+  return WalkUpFromCXXOperatorCallExpr(S);
+} else
+  return RecursiveASTVisitor::TraverseCXXOperatorCallExpr(S);
+  }
+
   bool WalkUpFromCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
-if (S->isInfixBinaryOp()) {
+switch (getOperatorNodeKind(*S)) {
+case syntax::NodeKind::BinaryOperatorExpression:
   Builder.markExprChild(
   S->getArg(0),
   syntax::NodeRole::BinaryOperatorExpression_leftHandSide);
@@ -747,8 +848,31 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   Builder.foldNode(Builder.getExprRange(S),
new (allocator()) syntax::BinaryOperato

[PATCH] D82157: Fix crash on `user defined literals`

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas marked 2 inline comments as done.
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1265
+| |-UserDefinedLiteralExpression
+| | `-12_w
+| `-;

gribozavr2 wrote:
> It looks somewhat weird to me that integer and floating point literals end up 
> with the same syntax tree node type. WDYT about making different nodes for 
> different literals (integer, floating-point, string, character)?
Makes sense. Let's follow the [[ 
https://eel.is/c++draft/lex.ext#nt:user-defined-literal | grammar ]] then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82157



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


[PATCH] D82954: Fix crash on overloaded postfix unary operators due to invalid SourceLocation

2020-07-08 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGea8bba7e8d0d: Fix crash on overloaded postfix unary 
operators due to invalid sloc (authored by eduucaldas).

Changed prior to commit:
  https://reviews.llvm.org/D82954?vs=275318&id=275709#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82954

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2193,11 +2193,18 @@
   X& operator=(const X&);
   friend X operator+(X, const X&);
   friend bool operator<(const X&, const X&);
+  friend X operator<<(X&, const X&);
+  X operator,(X&);
+  // TODO: Fix crash on member function pointer and add a test for `->*`
+  // TODO: Unbox operators in syntax tree. 
+  // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+`
 };
 void test(X x, X y) {
   x = y;
   x + y;
   x < y;
+  x << y;
+  x, y;
 }
 )cpp",
   R"txt(
@@ -2262,6 +2269,40 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-,
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
 | |-}
 | `-;
 `-SimpleDeclaration
@@ -2319,6 +2360,185 @@
 | |   `-UnqualifiedId
 | | `-y
 | `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-<<
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-x
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-,
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-y
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++();
+  bool operator!();
+  X* operator&();
+};
+void test(X x) {
+  ++x;
+  !x;
+  &x;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-bool
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-!
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-*
+| | | |-operator
+| | | |-&
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-++
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-!
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   `-&
+| | `-IdExpression
+| |   `-UnqualifiedId
+| | `-x
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  X operator++(int);
+};
+void test(X x) {
+  x++;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-++
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | `-int
+| | |   `-)
+| | 

[PATCH] D83364: [PowerPC][Power10] Implement Instruction definition and MC Tests for Load and Store VSX Vector with Zero or Sign Extend

2020-07-08 Thread Amy Kwan via Phabricator via cfe-commits
amyk accepted this revision as: amyk.
amyk added a comment.
This revision is now accepted and ready to land.

This LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83364



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


[PATCH] D83398: [OPENMP50]Perform data mapping analysis only for explicitly mapped data.

2020-07-08 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev created this revision.
ABataev added a reviewer: jdoerfert.
Herald added subscribers: sstefan1, guansong, yaxunl.
Herald added a project: clang.

According to OpenMP 5.0, the restrictions for mapping of overlapped data
apply only for explicitly mapped data, there is no restriction for
implicitly mapped data just like in OpenMP 4.5.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83398

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_map_messages.cpp


Index: clang/test/OpenMP/target_map_messages.cpp
===
--- clang/test/OpenMP/target_map_messages.cpp
+++ clang/test/OpenMP/target_map_messages.cpp
@@ -598,6 +598,7 @@
   const int (&l)[5] = da;
   SC1 s;
   SC1 *p;
+  int Arr[10];
 #pragma omp target data map // expected-error {{expected '(' after 'map'}} 
le45-error {{expected at least one 'map' or 'use_device_ptr' clause for 
'#pragma omp target data'}} le50-error {{expected at least one 'map', 
'use_device_ptr', or 'use_device_addr' clause for '#pragma omp target data'}}
 #pragma omp target data map( // expected-error {{expected ')'}} expected-note 
{{to match this '('}} expected-error {{expected expression}}
 #pragma omp target data map() // expected-error {{expected expression}}
@@ -737,6 +738,12 @@
 #pragma omp target map(release: a) // expected-error {{map type 'release' is 
not allowed for '#pragma omp target'}}
   {}
 
+#pragma omp target data map(Arr[0:4]) // le45-note {{used here}}
+  {
+#pragma omp target
+Arr[0] = 2; // le45-error {{original storage of expression in data 
environment is shared but data environment do not fully contain mapped 
expression storage}}
+  }
+
   return tmain(argc)+tmain(argc); // expected-note {{in 
instantiation of function template specialization 'tmain' requested 
here}} expected-note {{in instantiation of function template specialization 
'tmain' requested here}}
 }
 #endif
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -17428,6 +17428,7 @@
   /*CurrentRegionOnly=*/true, CurComponents, CKind))
   break;
 if (CKind == OMPC_map &&
+(SemaRef.getLangOpts().OpenMP <= 45 || StartLoc.isValid()) &&
 checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr,
   /*CurrentRegionOnly=*/false, CurComponents, CKind))
   break;


Index: clang/test/OpenMP/target_map_messages.cpp
===
--- clang/test/OpenMP/target_map_messages.cpp
+++ clang/test/OpenMP/target_map_messages.cpp
@@ -598,6 +598,7 @@
   const int (&l)[5] = da;
   SC1 s;
   SC1 *p;
+  int Arr[10];
 #pragma omp target data map // expected-error {{expected '(' after 'map'}} le45-error {{expected at least one 'map' or 'use_device_ptr' clause for '#pragma omp target data'}} le50-error {{expected at least one 'map', 'use_device_ptr', or 'use_device_addr' clause for '#pragma omp target data'}}
 #pragma omp target data map( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
 #pragma omp target data map() // expected-error {{expected expression}}
@@ -737,6 +738,12 @@
 #pragma omp target map(release: a) // expected-error {{map type 'release' is not allowed for '#pragma omp target'}}
   {}
 
+#pragma omp target data map(Arr[0:4]) // le45-note {{used here}}
+  {
+#pragma omp target
+Arr[0] = 2; // le45-error {{original storage of expression in data environment is shared but data environment do not fully contain mapped expression storage}}
+  }
+
   return tmain(argc)+tmain(argc); // expected-note {{in instantiation of function template specialization 'tmain' requested here}} expected-note {{in instantiation of function template specialization 'tmain' requested here}}
 }
 #endif
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -17428,6 +17428,7 @@
   /*CurrentRegionOnly=*/true, CurComponents, CKind))
   break;
 if (CKind == OMPC_map &&
+(SemaRef.getLangOpts().OpenMP <= 45 || StartLoc.isValid()) &&
 checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr,
   /*CurrentRegionOnly=*/false, CurComponents, CKind))
   break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 69c22ed - [clangd] Enable reading config from files behind a flag

2020-07-08 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-07-08T16:48:01+02:00
New Revision: 69c22edb7d30983f1bb9d21154e427ebcc5f699c

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

LOG: [clangd] Enable reading config from files behind a flag

Reviewers: kadircet, hokein

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

Tags: #clang

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index c77f92d3f183..6e3d6a231da1 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -320,7 +320,7 @@ opt Test{
 "lit-test",
 cat(Misc),
 desc("Abbreviation for -input-style=delimited -pretty -sync "
- "-enable-test-scheme -log=verbose. "
+ "-enable-test-scheme -enable-config=0 -log=verbose. "
  "Intended to simplify lit tests"),
 init(false),
 Hidden,
@@ -427,6 +427,20 @@ opt AsyncPreamble{
 Hidden,
 };
 
+opt EnableConfig{
+"enable-config",
+cat(Misc),
+desc(
+"Read user and project configuration from YAML files.\n"
+"Project config is from a .clangd file in the project directory.\n"
+"User config is from clangd/config.yaml in the following 
directories:\n"
+"\tWindows: %USERPROFILE%\\AppData\\Local\n"
+"\tMac OS: ~/Library/Preferences/\n"
+"\tOthers: $XDG_CONFIG_HOME, usually ~/.config\n"
+"Configuration is documented at https://clangd.llvm.org/config.html";),
+init(false),
+};
+
 /// Supports a test URI scheme with relaxed constraints for lit tests.
 /// The path in a test URI will be combined with a platform-specific fake
 /// directory to form an absolute path. For example, test:///a.cpp is resolved
@@ -510,6 +524,9 @@ clangd accepts flags on the commandline, and in the 
CLANGD_FLAGS environment var
 InputStyle = JSONStreamStyle::Delimited;
 LogLevel = Logger::Verbose;
 PrettyPrint = true;
+// Disable config system by default to avoid external reads.
+if (!EnableConfig.getNumOccurrences())
+  EnableConfig = false;
 // Disable background index on lit tests by default to prevent disk writes.
 if (!EnableBackgroundIndex.getNumOccurrences())
   EnableBackgroundIndex = false;
@@ -677,6 +694,23 @@ clangd accepts flags on the commandline, and in the 
CLANGD_FLAGS environment var
   CCOpts.RunParser = CodeCompletionParse;
 
   RealThreadsafeFS TFS;
+  std::unique_ptr Config;
+  if (EnableConfig) {
+std::vector> ProviderStack;
+ProviderStack.push_back(
+config::Provider::fromAncestorRelativeYAMLFiles(".clangd", TFS));
+llvm::SmallString<256> UserConfig;
+if (llvm::sys::path::user_config_directory(UserConfig)) {
+  llvm::sys::path::append(UserConfig, "clangd", "config.yaml");
+  vlog("User config file is {0}", UserConfig);
+  ProviderStack.push_back(config::Provider::fromYAMLFile(UserConfig, TFS));
+} else {
+  elog("Couldn't determine user config file, not loading");
+}
+Config = config::Provider::combine(std::move(ProviderStack));
+Opts.ConfigProvider = Config.get();
+  }
+
   // Initialize and run ClangdLSPServer.
   // Change stdin to binary to not lose \r\n on windows.
   llvm::sys::ChangeStdinToBinary();



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


[PATCH] D83233: [clangd] Enable reading config from files by default.

2020-07-08 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG69c22edb7d30: [clangd] Enable reading config from files 
behind a flag (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D83233?vs=275724&id=276437#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83233

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


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -320,7 +320,7 @@
 "lit-test",
 cat(Misc),
 desc("Abbreviation for -input-style=delimited -pretty -sync "
- "-enable-test-scheme -log=verbose. "
+ "-enable-test-scheme -enable-config=0 -log=verbose. "
  "Intended to simplify lit tests"),
 init(false),
 Hidden,
@@ -427,6 +427,20 @@
 Hidden,
 };
 
+opt EnableConfig{
+"enable-config",
+cat(Misc),
+desc(
+"Read user and project configuration from YAML files.\n"
+"Project config is from a .clangd file in the project directory.\n"
+"User config is from clangd/config.yaml in the following 
directories:\n"
+"\tWindows: %USERPROFILE%\\AppData\\Local\n"
+"\tMac OS: ~/Library/Preferences/\n"
+"\tOthers: $XDG_CONFIG_HOME, usually ~/.config\n"
+"Configuration is documented at https://clangd.llvm.org/config.html";),
+init(false),
+};
+
 /// Supports a test URI scheme with relaxed constraints for lit tests.
 /// The path in a test URI will be combined with a platform-specific fake
 /// directory to form an absolute path. For example, test:///a.cpp is resolved
@@ -510,6 +524,9 @@
 InputStyle = JSONStreamStyle::Delimited;
 LogLevel = Logger::Verbose;
 PrettyPrint = true;
+// Disable config system by default to avoid external reads.
+if (!EnableConfig.getNumOccurrences())
+  EnableConfig = false;
 // Disable background index on lit tests by default to prevent disk writes.
 if (!EnableBackgroundIndex.getNumOccurrences())
   EnableBackgroundIndex = false;
@@ -677,6 +694,23 @@
   CCOpts.RunParser = CodeCompletionParse;
 
   RealThreadsafeFS TFS;
+  std::unique_ptr Config;
+  if (EnableConfig) {
+std::vector> ProviderStack;
+ProviderStack.push_back(
+config::Provider::fromAncestorRelativeYAMLFiles(".clangd", TFS));
+llvm::SmallString<256> UserConfig;
+if (llvm::sys::path::user_config_directory(UserConfig)) {
+  llvm::sys::path::append(UserConfig, "clangd", "config.yaml");
+  vlog("User config file is {0}", UserConfig);
+  ProviderStack.push_back(config::Provider::fromYAMLFile(UserConfig, TFS));
+} else {
+  elog("Couldn't determine user config file, not loading");
+}
+Config = config::Provider::combine(std::move(ProviderStack));
+Opts.ConfigProvider = Config.get();
+  }
+
   // Initialize and run ClangdLSPServer.
   // Change stdin to binary to not lose \r\n on windows.
   llvm::sys::ChangeStdinToBinary();


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -320,7 +320,7 @@
 "lit-test",
 cat(Misc),
 desc("Abbreviation for -input-style=delimited -pretty -sync "
- "-enable-test-scheme -log=verbose. "
+ "-enable-test-scheme -enable-config=0 -log=verbose. "
  "Intended to simplify lit tests"),
 init(false),
 Hidden,
@@ -427,6 +427,20 @@
 Hidden,
 };
 
+opt EnableConfig{
+"enable-config",
+cat(Misc),
+desc(
+"Read user and project configuration from YAML files.\n"
+"Project config is from a .clangd file in the project directory.\n"
+"User config is from clangd/config.yaml in the following directories:\n"
+"\tWindows: %USERPROFILE%\\AppData\\Local\n"
+"\tMac OS: ~/Library/Preferences/\n"
+"\tOthers: $XDG_CONFIG_HOME, usually ~/.config\n"
+"Configuration is documented at https://clangd.llvm.org/config.html";),
+init(false),
+};
+
 /// Supports a test URI scheme with relaxed constraints for lit tests.
 /// The path in a test URI will be combined with a platform-specific fake
 /// directory to form an absolute path. For example, test:///a.cpp is resolved
@@ -510,6 +524,9 @@
 InputStyle = JSONStreamStyle::Delimited;
 LogLevel = Logger::Verbose;
 PrettyPrint = true;
+// Disable config system by default to avoid external reads.
+if (!EnableConfig.getNumOccurrences())
+  EnableConfig = false;
 // Disable background index on lit tests by default to prevent disk writes.
 if (!EnableBackgroundIndex.getNumOccurrences())
   EnableBackgroundIndex = f

[PATCH] D83315: Turn arcmt-* options into a single option

2020-07-08 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 276438.
dang added a comment.

Instead of using a Separate option kind (-arcmt-action action) use a Joined 
kind (-arcmt-action=*)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83315

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/ARCMT/GC-check-warn-nsalloc.m
  clang/test/ARCMT/GC-check.m
  clang/test/ARCMT/atautorelease-check.m
  clang/test/ARCMT/check-api.m
  clang/test/ARCMT/check-with-pch.m
  clang/test/ARCMT/check-with-serialized-diag.m
  clang/test/ARCMT/checking-in-arc.m
  clang/test/ARCMT/checking.m
  clang/test/ARCMT/cxx-checking.mm
  clang/test/ARCMT/driver-migrate.m
  clang/test/ARCMT/migrate-emit-errors.m
  clang/test/ARCMT/migrate-plist-output.m
  clang/test/ARCMT/migrate-space-in-path.m
  clang/test/ARCMT/migrate-with-pch.m
  clang/test/ARCMT/migrate.m
  clang/test/ARCMT/no-canceling-bridge-to-bridge-cast.m
  clang/test/ARCMT/nonobjc-to-objc-cast-2.m
  clang/test/ARCMT/releases-driver.m
  clang/test/ARCMT/releases-driver.m.result
  clang/test/ARCMT/verify.m
  clang/test/ARCMT/with-arc-mode-modify.m
  clang/test/ARCMT/with-arc-mode-modify.m.result
  llvm/include/llvm/Option/OptParser.td
  llvm/utils/TableGen/OptParserEmitter.cpp

Index: llvm/utils/TableGen/OptParserEmitter.cpp
===
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -112,7 +112,7 @@
 OS << ", ";
 emitScopedNormalizedValue(OS, DefaultValue);
 OS << ", ";
-emitScopedNormalizedValue(OS, NormalizerRetTy);
+OS << NormalizerRetTy;
 OS << ", ";
 OS << Normalizer;
 OS << ", ";
Index: llvm/include/llvm/Option/OptParser.td
===
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -193,6 +193,9 @@
   code Normalizer = "normalizeSimpleEnum";
   code Denormalizer = "denormalizeSimpleEnum";
 }
+class AutoNormalizeEnumJoined : AutoNormalizeEnum {
+  code Denormalizer = "denormalizeSimpleEnumJoined";
+}
 class ValueMerger { code ValueMerger = merger; }
 class ValueExtractor { code ValueExtractor = extractor; }
 
Index: clang/test/ARCMT/with-arc-mode-modify.m.result
===
--- clang/test/ARCMT/with-arc-mode-modify.m.result
+++ clang/test/ARCMT/with-arc-mode-modify.m.result
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -fsyntax-only -fobjc-arc -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action=modify -fsyntax-only -fobjc-arc -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/with-arc-mode-modify.m
===
--- clang/test/ARCMT/with-arc-mode-modify.m
+++ clang/test/ARCMT/with-arc-mode-modify.m
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -fsyntax-only -fobjc-arc -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action=modify -fsyntax-only -fobjc-arc -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/verify.m
===
--- clang/test/ARCMT/verify.m
+++ clang/test/ARCMT/verify.m
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -arcmt-check -verify %s
-// RUN: not %clang_cc1 -arcmt-check -verify %t.invalid 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -arcmt-action=check -verify %s
+// RUN: not %clang_cc1 -arcmt-action=check -verify %t.invalid 2>&1 | FileCheck %s
 
 #if 0
 // expected-error {{should be ignored}}
Index: clang/test/ARCMT/releases-driver.m.result
===
--- clang/test/ARCMT/releases-driver.m.result
+++ clang/test/ARCMT/releases-driver.m.result
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action=modify -triple x86_64-apple-macosx10.6 -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/releases-driver.m
===
--- clang/test/ARCMT/releases-driver.m
+++ clang/test/ARCMT/releases-driver.m
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fblocks -fsyntax-only -fobjc-arc -x objective-c %s.result
 // RUN: cat %s > %t
-// RUN: %clang_cc1 -arcmt-modify -triple x86_64-apple-macosx10.6 -x objective-c %t
+// RUN: %clang_cc1 -arcmt-action=modify -triple x86_64-apple-macosx10.6 -x objective-c %t
 // RUN: diff %t %s.result
 // RUN: rm %t
 
Index: clang/test/ARCMT/nonobjc-to-obj

[PATCH] D83371: [clangd] Factor out some helper functions related to heuristic resolution in TargetFinder

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, looks good.




Comment at: clang-tools-extra/clangd/FindTarget.cpp:64
+// resolves it to a CXXRecordDecl in which we can try name lookup.
+CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
+  if (auto *ICNT = T->getAs()) {

nit: add assert(T), or even use `const Type&` as the parameter type.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:158
+// or more declarations that it likely references.
+std::vector resolveDependentExprToDecls(const Expr *E) {
+  switch (E->getStmtClass()) {

nit: add  `assert(E->isTypeDepndent())`;





Comment at: clang-tools-extra/clangd/FindTarget.cpp:159
+std::vector resolveDependentExprToDecls(const Expr *E) {
+  switch (E->getStmtClass()) {
+  case Stmt::CXXDependentScopeMemberExprClass: {

nit: looks like the code will be a bit simpler if we just use if branch like 

```
if (const auto * a = dyn_cast());
```

but up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83371



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


[PATCH] D83364: [PowerPC][Power10] Implement Instruction definition and MC Tests for Load and Store VSX Vector with Zero or Sign Extend

2020-07-08 Thread Kamau Bridgeman via Phabricator via cfe-commits
kamaub accepted this revision.
kamaub added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83364



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


[PATCH] D83087: DomTree: remove explicit use of DomTreeNodeBase::iterator

2020-07-08 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

In D83087#2134881 , @kuhar wrote:

> modulo accidental formatting changes.


I'm not aware of any. Some line breaks changed because "const_iterator" is 
longer than "iterator".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83087



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


[PATCH] D82739: Improve heuristic resolution of dependent types in TargetFinder

2020-07-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D82739#2138260 , @nridge wrote:

> In D82739#2133155 , @hokein wrote:
>
> > looks like we use this heuristic for go-to-def, I think we might want to 
> > use it in more places, e.g.  libindex (for xrefs), sema code completion (so 
> > that `this->a.^` can suggest something).
>
>
> Yeah, this is a great point. I would definitely like to reuse this heuristic 
> resolution for other features like code completion (including in 
> https://github.com/clangd/clangd/issues/443 where I hope to build on it to 
> improve the original STR which involves completion).
>
> I will explore relocating this code to a place where things like code 
> completion can reuse it, in a follow-up patch.


thanks, this sounds a good plan.




Comment at: clang-tools-extra/clangd/FindTarget.cpp:196
   switch (E->getStmtClass()) {
   case Stmt::CXXDependentScopeMemberExprClass: {
 const auto *ME = llvm::cast(E);

I'm doubting whether we will miss some other exprs, since we are using it to 
find the decls for the base expr of `CXXDependentScopeMemberExpr`. 

could you try the following testcase (also add it to the unittest)?

```
struct A {
  void foo() {}
};
struct B {
  A getA();
};

template  struct C {
  C c;

  void bar() { this->c.getA().foo(); }
};
```



Comment at: clang-tools-extra/clangd/FindTarget.cpp:198
+// analyzing it.
+if (E && BT->getKind() == BuiltinType::Dependent) {
+  T = resolveDependentExprToType(E);

nridge wrote:
> hokein wrote:
> > I think this is the key point of the fix?
> > 
> > It would be nice if you could find a way to split it into two (one for 
> > refactoring, one for the fix). The diff of this patch contains large chunk 
> > of refactoring changes which make the fix less obvious.
> Yeah, sorry about that. I've split the patch and cleaned it up further (to 
> avoid unnecessary reordering of functions) to make the diff neater.
it looks better now, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82739



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


[clang] 6aab27b - [OpenMPIRBuilder][Fix] Move llvm::omp::types to OpenMPIRBuilder.

2020-07-08 Thread via cfe-commits

Author: sstefan1
Date: 2020-07-08T17:23:55+02:00
New Revision: 6aab27ba851f132f01ea8e87f92243918dc23cfd

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

LOG: [OpenMPIRBuilder][Fix] Move llvm::omp::types to OpenMPIRBuilder.

Summary:
D82193 exposed a problem with global type definitions in
`OMPConstants.h`. This causes a race when running in thinLTO mode.
Types now live inside of OpenMPIRBuilder to prevent this from happening.

Reviewers: jdoerfert

Subscribers: yaxunl, hiraditya, guansong, dexonsmith, aaron.ballman, 
cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/lib/Frontend/OpenMP/OMPConstants.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 09593531af83..1729c7ed3c31 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1401,7 +1401,7 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
   Address address = Address::invalid();
   Address AllocaAddr = Address::invalid();
   Address OpenMPLocalAddr = Address::invalid();
-  if (CGM.getOpenMPIRBuilder())
+  if (CGM.getLangOpts().OpenMPIRBuilder)
 OpenMPLocalAddr = OMPBuilderCBHelpers::getAddressOfLocalVariable(*this, 
&D);
   else
 OpenMPLocalAddr =

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 2547690ed3a3..be5d976f346c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2398,7 +2398,7 @@ EmitBitCastOfLValueToProperType(CodeGenFunction &CGF,
 static LValue EmitThreadPrivateVarDeclLValue(
 CodeGenFunction &CGF, const VarDecl *VD, QualType T, Address Addr,
 llvm::Type *RealVarTy, SourceLocation Loc) {
-  if (CGF.CGM.getOpenMPIRBuilder())
+  if (CGF.CGM.getLangOpts().OpenMPIRBuilder)
 Addr = CodeGenFunction::OMPBuilderCBHelpers::getAddrOfThreadPrivate(
 CGF, VD, Addr, Loc);
   else

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 858dbbf81f20..fb2ce60f2e41 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1060,7 +1060,7 @@ static FieldDecl *addFieldToRecordDecl(ASTContext &C, 
DeclContext *DC,
 CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM, StringRef FirstSeparator,
  StringRef Separator)
 : CGM(CGM), FirstSeparator(FirstSeparator), Separator(Separator),
-  OffloadEntriesInfoManager(CGM) {
+  OMPBuilder(CGM.getModule()), OffloadEntriesInfoManager(CGM) {
   ASTContext &C = CGM.getContext();
   RecordDecl *RD = C.buildImplicitRecord("ident_t");
   QualType KmpInt32Ty = C.getIntTypeForBitwidth(/*DestWidth=*/32, 
/*Signed=*/1);
@@ -1081,7 +1081,7 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM, 
StringRef FirstSeparator,
   KmpCriticalNameTy = llvm::ArrayType::get(CGM.Int32Ty, /*NumElements*/ 8);
 
   // Initialize Types used in OpenMPIRBuilder from OMPKinds.def
-  llvm::omp::types::initializeTypes(CGM.getModule());
+  OMPBuilder.initialize();
   loadOffloadInfoMetadata();
 }
 
@@ -1278,8 +1278,8 @@ static llvm::Function 
*emitParallelOrTeamsOutlinedFunction(
 
   // TODO: Temporarily inform the OpenMPIRBuilder, if any, about the new
   //   parallel region to make cancellation barriers work properly.
-  llvm::OpenMPIRBuilder *OMPBuilder = CGM.getOpenMPIRBuilder();
-  PushAndPopStackRAII PSR(OMPBuilder, CGF, HasCancel);
+  llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
+  PushAndPopStackRAII PSR(&OMPBuilder, CGF, HasCancel);
   CGOpenMPOutlinedRegionInfo CGInfo(*CS, ThreadIDVar, CodeGen, InnermostKind,
 HasCancel, OutlinedHelperName);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo);
@@ -1316,7 +1316,7 @@ llvm::Function *CGOpenMPRuntime::emitTaskOutlinedFunction(
 CGF.EmitLoadOfPointerLValue(CGF.GetAddrOfLocalVar(TaskTVar),
 TaskTVar->getType()->castAs())
 .getPointer(CGF)};
-CGF.EmitRuntimeCall(llvm::OpenMPIRBuilder::getOrCreateRuntimeFunction(
+CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
 CGM.ge

[PATCH] D82805: [clang] Fix a crash on passing C structure of incompatible type to function with reference parameter

2020-07-08 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno accepted this revision.
riccibruno added a comment.
This revision is now accepted and ready to land.

This LGTM, with a few wording nits.

> This patch fix clang crashes at using these functions in C and passing 
> incompatible structures as parameters in case of 
> __builtin_va_list/__builtin_ms_va_list are structures.

This patch fix a crash when using these functions in C where an argument of 
structure type is incompatible with the parameter type.

Do you want me to commit it for you? If so I need a name and an email for the 
attribution.




Comment at: clang/lib/Sema/SemaInit.cpp:4698
+/// We also can get here in C if we call builtin which is declared as
+/// a function with reference arguments (e.g. __builtin_va_end()).
 static void TryReferenceInitializationCore(Sema &S,

s/call builtin/call a builtin/
s/with reference arguments/with a parameter of reference type/

The second wording change is important since "argument" != "parameter".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82805



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


[PATCH] D83176: [OpenMPIRBuilder][Fix] Move llvm::omp::types to OpenMPIRBuilder.

2020-07-08 Thread Stefan Stipanovic via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6aab27ba851f: [OpenMPIRBuilder][Fix] Move llvm::omp::types 
to OpenMPIRBuilder. (authored by sstefan1).

Changed prior to commit:
  https://reviews.llvm.org/D83176?vs=275549&id=276445#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83176

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPConstants.cpp
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -19,7 +19,6 @@
 
 using namespace llvm;
 using namespace omp;
-using namespace types;
 
 namespace {
 
@@ -50,7 +49,6 @@
   void TearDown() override {
 BB = nullptr;
 M.reset();
-uninitializeTypes();
   }
 
   LLVMContext Ctx;
Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp
===
--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -29,7 +29,6 @@
 
 using namespace llvm;
 using namespace omp;
-using namespace types;
 
 #define DEBUG_TYPE "openmp-opt"
 
@@ -263,11 +262,11 @@
   ICV.InitValue = nullptr; \
   break;   \
 case ICV_ZERO: \
-  ICV.InitValue =  \
-  ConstantInt::get(Type::getInt32Ty(Int32->getContext()), 0);  \
+  ICV.InitValue = ConstantInt::get(\
+  Type::getInt32Ty(OMPBuilder.Int32->getContext()), 0);\
   break;   \
 case ICV_FALSE:\
-  ICV.InitValue = ConstantInt::getFalse(Int1->getContext());   \
+  ICV.InitValue = ConstantInt::getFalse(OMPBuilder.Int1->getContext());\
   break;   \
 case ICV_LAST: \
   break;   \
@@ -332,16 +331,39 @@
 
 Module &M = *((*ModuleSlice.begin())->getParent());
 
+// Helper macros for handling __VA_ARGS__ in OMP_RTL
+#define OMP_TYPE(VarName, ...) \
+  Type *VarName = OMPBuilder.VarName;  \
+  (void)VarName;
+
+#define OMP_ARRAY_TYPE(VarName, ...)   \
+  ArrayType *VarName##Ty = OMPBuilder.VarName##Ty; \
+  (void)VarName##Ty;   \
+  PointerType *VarName##PtrTy = OMPBuilder.VarName##PtrTy; \
+  (void)VarName##PtrTy;
+
+#define OMP_FUNCTION_TYPE(VarName, ...)\
+  FunctionType *VarName = OMPBuilder.VarName;  \
+  (void)VarName;   \
+  PointerType *VarName##Ptr = OMPBuilder.VarName##Ptr; \
+  (void)VarName##Ptr;
+
+#define OMP_STRUCT_TYPE(VarName, ...)  \
+  StructType *VarName = OMPBuilder.VarName;\
+  (void)VarName;   \
+  PointerType *VarName##Ptr = OMPBuilder.VarName##Ptr; \
+  (void)VarName##Ptr;
+
 #define OMP_RTL(_Enum, _Name, _IsVarArg, _ReturnType, ...) \
   {\
 SmallVector ArgsTypes({__VA_ARGS__});   \
 Function *F = M.getFunction(_Name);\
-if (declMatchesRTFTypes(F, _ReturnType, ArgsTypes)) {  \
+if (declMatchesRTFTypes(F, OMPBuilder._ReturnType, ArgsTypes)) {   \
   auto &RFI = RFIs[_Enum]; \
   RFI.Kind = _Enum;\
   

[clang-tools-extra] a15d798 - [clangd] Improve serialization error messages. NFC

2020-07-08 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-07-08T17:31:40+02:00
New Revision: a15d798594ae340b037efec2cdba5ec77221e7e7

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

LOG: [clangd] Improve serialization error messages. NFC

Added: 


Modified: 
clang-tools-extra/clangd/RIFF.cpp
clang-tools-extra/clangd/RIFF.h
clang-tools-extra/clangd/index/Serialization.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/RIFF.cpp 
b/clang-tools-extra/clangd/RIFF.cpp
index cdbae4f72739..b87c2d56af0c 100644
--- a/clang-tools-extra/clangd/RIFF.cpp
+++ b/clang-tools-extra/clangd/RIFF.cpp
@@ -8,25 +8,29 @@
 
 #include "RIFF.h"
 #include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
 
 namespace clang {
 namespace clangd {
 namespace riff {
 
-static llvm::Error makeError(const char *Msg) {
-  return llvm::createStringError(llvm::inconvertibleErrorCode(), Msg);
+static llvm::Error makeError(const llvm::Twine &Msg) {
+  return llvm::make_error(Msg,
+ llvm::inconvertibleErrorCode());
 }
 
 llvm::Expected readChunk(llvm::StringRef &Stream) {
   if (Stream.size() < 8)
-return makeError("incomplete chunk header");
+return makeError("incomplete chunk header: " + llvm::Twine(Stream.size()) +
+ " bytes available");
   Chunk C;
   std::copy(Stream.begin(), Stream.begin() + 4, C.ID.begin());
   Stream = Stream.drop_front(4);
   uint32_t Len = llvm::support::endian::read32le(Stream.take_front(4).begin());
   Stream = Stream.drop_front(4);
   if (Stream.size() < Len)
-return makeError("truncated chunk");
+return makeError("truncated chunk: want " + llvm::Twine(Len) + ", got " +
+ llvm::Twine(Stream.size()));
   C.Data = Stream.take_front(Len);
   Stream = Stream.drop_front(Len);
   if (Len % 2 & !Stream.empty()) { // Skip padding byte.
@@ -53,7 +57,7 @@ llvm::Expected readFile(llvm::StringRef Stream) {
   if (!RIFF)
 return RIFF.takeError();
   if (RIFF->ID != fourCC("RIFF"))
-return makeError("not a RIFF container");
+return makeError("not a RIFF container: root is " + fourCCStr(RIFF->ID));
   if (RIFF->Data.size() < 4)
 return makeError("RIFF chunk too short");
   File F;

diff  --git a/clang-tools-extra/clangd/RIFF.h b/clang-tools-extra/clangd/RIFF.h
index d827a90f2bd7..96d8ab5463d3 100644
--- a/clang-tools-extra/clangd/RIFF.h
+++ b/clang-tools-extra/clangd/RIFF.h
@@ -44,6 +44,9 @@ using FourCC = std::array;
 inline constexpr FourCC fourCC(const char (&Literal)[5]) {
   return FourCC{{Literal[0], Literal[1], Literal[2], Literal[3]}};
 }
+inline constexpr llvm::StringRef fourCCStr(const FourCC &Data) {
+  return llvm::StringRef(&Data[0], Data.size());
+}
 // A chunk is a section in a RIFF container.
 struct Chunk {
   FourCC ID;

diff  --git a/clang-tools-extra/clangd/index/Serialization.cpp 
b/clang-tools-extra/clangd/index/Serialization.cpp
index 06527a615c20..11d70b550642 100644
--- a/clang-tools-extra/clangd/index/Serialization.cpp
+++ b/clang-tools-extra/clangd/index/Serialization.cpp
@@ -426,20 +426,25 @@ llvm::Expected readRIFF(llvm::StringRef 
Data) {
   if (!RIFF)
 return RIFF.takeError();
   if (RIFF->Type != riff::fourCC("CdIx"))
-return makeError("wrong RIFF type");
+return makeError("wrong RIFF filetype: " + riff::fourCCStr(RIFF->Type));
   llvm::StringMap Chunks;
   for (const auto &Chunk : RIFF->Chunks)
 Chunks.try_emplace(llvm::StringRef(Chunk.ID.data(), Chunk.ID.size()),
Chunk.Data);
 
-  for (llvm::StringRef RequiredChunk : {"meta", "stri"})
+  if (!Chunks.count("meta"))
+return makeError("missing meta chunk");
+  Reader Meta(Chunks.lookup("meta"));
+  auto SeenVersion = Meta.consume32();
+  if (SeenVersion != Version)
+return makeError("wrong version: want " + llvm::Twine(Version) + ", got " +
+ llvm::Twine(SeenVersion));
+
+  // meta chunk is checked above, as we prefer the "version mismatch" error.
+  for (llvm::StringRef RequiredChunk : {"stri"})
 if (!Chunks.count(RequiredChunk))
   return makeError("missing required chunk " + RequiredChunk);
 
-  Reader Meta(Chunks.lookup("meta"));
-  if (Meta.consume32() != Version)
-return makeError("wrong version");
-
   auto Strings = readStringTable(Chunks.lookup("stri"));
   if (!Strings)
 return Strings.takeError();
@@ -665,7 +670,7 @@ std::unique_ptr loadIndex(llvm::StringRef 
SymbolFilename,
   trace::Span OverallTracer("LoadIndex");
   auto Buffer = llvm::MemoryBuffer::getFile(SymbolFilename);
   if (!Buffer) {
-elog("Can't open {0}", SymbolFilename);
+elog("Can't open {0}: {1}", SymbolFilename, Buffer.getError().message());
 return nullptr;
   }
 
@@ -682,7 +687,7 @@ std::unique_ptr loadIndex(llvm::StringRef 
SymbolFilen

[PATCH] D82381: [analyzer] Introduce small improvements to the solver infra

2020-07-08 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@vsavchenko
Thank you.
Despite of all of my nits, LGTM!




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:367-378
+RangeSet RangeSet::Delete(BasicValueFactory &BV, Factory &F,
+  const llvm::APSInt &Point) const {
+  llvm::APSInt Upper = Point;
+  llvm::APSInt Lower = Point;
+
+  ++Upper;
+  --Lower;

vsavchenko wrote:
> ASDenysPetrov wrote:
> > Useful function. But I'd better rename it to `subtract` as we are working 
> > with sets (as a mathimatical collection). We should have a such one for the 
> > Ranges not only for Points.
> > We have `intersect`, `delete` aka `subtract`. And we also need to have 
> > functions `union` and `symmetricDifference` to cover full palette of common 
> > operations on sets.
> I agree that we should have a full set of functions.  I don't agree however, 
> that this function is a `subtract`.  Subtract is an operation on two sets and 
> here we have a set and a point.  One might argue that a point is just a very 
> simple set, that's true, but real `subtract` would be more complex in its 
> implementation.
> 
> Naming it `delete`, on the other hand, I was coming from a notion of deleting 
> points or neighbourhoods 
> (https://en.wikipedia.org/wiki/Neighbourhood_(mathematics)#Deleted_neighbourhood).
>One might argue that a point is just a very simple set
That's actually what I mean :) and for this particular case you may leave the 
implementation as is. And for me it still does what `subtract` does. But I'm 
OK,  I don't insist.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:734
   //expressions which we currently do not know how to negate.
-  const RangeSet *getRangeForMinusSymbol(ProgramStateRef State, SymbolRef Sym) 
{
+  Optional getRangeForInvertedSub(SymbolRef Sym) {
 if (const SymSymExpr *SSE = dyn_cast(Sym)) {

vsavchenko wrote:
> ASDenysPetrov wrote:
> > As for me, I'd call this like `getRangeForNegatedSymSymExpr`, since you do 
> > Negate operation inside.
> I'm not super happy about my name either, but I feel like it describes it 
> better than the previous name and your version.  That function doesn't work 
> for any `SymSymExpr` and it doesn't simply negate whatever we gave it.  It 
> works specifically for symbolic subtractions and this is the information I 
> want to be reflected in the name.
Oh, I just assumed //...Sub// at the end as a //subexpression// but you mean 
//subtraction//. What I'm trying to say is that we can rename it like 
`getRangeFor...`//the expression which this function can handle//. E.g. 
`getRangeForNegatedSubtractionSymSymExpr`. My point is in a speaking name.

I think //invertion// is not something appropriate in terms of applying minus 
operator. I think invertion of zero should be something opposite but not a 
zero. Because when you would like to implement the function which turns [A, B] 
into [MIN, A)U(B, MAX], what would be the name of it? I think this is an 
//invertion//.

But this is not a big deal, it's just my thoughts.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:841-844
+  RangeSet getTrueRange(QualType T) {
+RangeSet TypeRange = infer(T);
+return assumeNonZero(TypeRange, T);
+  }

vsavchenko wrote:
> ASDenysPetrov wrote:
> > Don't you think this is too complicated for such a simple getter?
> > Maybe we can just construct the range using smth about 
> > `RangeSet(RangeFactory, ++Zero, --Zero);` ?
> It is more complex than a false range but there is a reason for it.
> 
> First of all, `RangeSet` can't have ranges where the end is greater than its 
> start.  Only `Intersect` can handle such ranges correctly.  Another thing is 
> that ranges like that mean `[MIN, --Zero], [++Zero, MAX]` and without a type 
> we can't really say what `MIN` and `MAX` are, so such constructor for 
> `RangeSet` simply cannot exist.
> 
> Another point is that we do need to have `[MIN, -1], [+1, MAX]` as opposed to 
> `[-1, -1], [+1, +1]` because of C language (it doesn't have boolean type), 
> and because of the cases like `a - b` where we know that `a != b`.
> 
> I hope that answers the question.
I just want this function has low complexity and be more lightweight as 
`getFalseRange`. And if we have any chance to simplify it (and you have all the 
data to get MIN and MAX), it'd be cool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82381



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


[clang] 7a7d50e - [clang][NFC] Also test for serialization in test/AST/ast-dump-APValue-*

2020-07-08 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-08T16:39:11+01:00
New Revision: 7a7d50e1f0d84c701fd2aa1b84a73a3e194fb91a

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

LOG: [clang][NFC] Also test for serialization in test/AST/ast-dump-APValue-*

This does not actually exercise the serialization of APValue, but it
will at least prevent a regression in the future. NFC.

Added: 


Modified: 
clang/test/AST/ast-dump-APValue-anon-union.cpp
clang/test/AST/ast-dump-APValue-arithmetic.cpp
clang/test/AST/ast-dump-APValue-array.cpp
clang/test/AST/ast-dump-APValue-struct.cpp
clang/test/AST/ast-dump-APValue-todo.cpp
clang/test/AST/ast-dump-APValue-union.cpp
clang/test/AST/ast-dump-APValue-vector.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-APValue-anon-union.cpp 
b/clang/test/AST/ast-dump-APValue-anon-union.cpp
index c50fe70be911..1c9480c5a943 100644
--- a/clang/test/AST/ast-dump-APValue-anon-union.cpp
+++ b/clang/test/AST/ast-dump-APValue-anon-union.cpp
@@ -1,6 +1,14 @@
+// Test without serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-ast-dump %s -ast-dump-filter Test \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:   -include-pch %t -ast-dump-all -ast-dump-filter Test 
/dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 struct S0 {
   union {

diff  --git a/clang/test/AST/ast-dump-APValue-arithmetic.cpp 
b/clang/test/AST/ast-dump-APValue-arithmetic.cpp
index a4e1d82eeb37..835d8c810834 100644
--- a/clang/test/AST/ast-dump-APValue-arithmetic.cpp
+++ b/clang/test/AST/ast-dump-APValue-arithmetic.cpp
@@ -1,6 +1,14 @@
+// Test without serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-ast-dump %s -ast-dump-filter Test \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:   -include-pch %t -ast-dump-all -ast-dump-filter Test 
/dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 void Test() {
   constexpr int Int = 42;

diff  --git a/clang/test/AST/ast-dump-APValue-array.cpp 
b/clang/test/AST/ast-dump-APValue-array.cpp
index 4b7dfab09eaf..f9b38ec332a5 100644
--- a/clang/test/AST/ast-dump-APValue-array.cpp
+++ b/clang/test/AST/ast-dump-APValue-array.cpp
@@ -1,6 +1,14 @@
+// Test without serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-ast-dump %s -ast-dump-filter Test \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:   -include-pch %t -ast-dump-all -ast-dump-filter Test 
/dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 struct S0 {
   int arr[2];

diff  --git a/clang/test/AST/ast-dump-APValue-struct.cpp 
b/clang/test/AST/ast-dump-APValue-struct.cpp
index d69ddffda031..4730404abc28 100644
--- a/clang/test/AST/ast-dump-APValue-struct.cpp
+++ b/clang/test/AST/ast-dump-APValue-struct.cpp
@@ -1,6 +1,14 @@
+// Test without serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-ast-dump %s -ast-dump-filter Test \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:   -include-pch %t -ast-dump-all -ast-dump-filter Test 
/dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 struct S0 {
   int i = 0;

diff  --git a/clang/test/AST/ast-dump-APValue-todo.cpp 
b/clang/test/AST/ast-dump-APValue-todo.cpp
index 5de8146910f7..78cc9cf36c73 100644
--- a/clang/test/AST/ast-dump-APValue-todo.cpp
+++ b/clang/test/AST/ast-dump-

[PATCH] D82805: [clang] Fix a crash on passing C structure of incompatible type to function with reference parameter

2020-07-08 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

In D82805#2139243 , @riccibruno wrote:

> Do you want me to commit it for you?


Yes, thank you.

>   If so I need a name and an email for the attribution.

Aleksandr Platonov 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82805



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


[PATCH] D83087: DomTree: remove explicit use of DomTreeNodeBase::iterator

2020-07-08 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar added a comment.

In D83087#2139211 , @nhaehnle wrote:

> In D83087#2134881 , @kuhar wrote:
>
> > modulo accidental formatting changes.
>
>
> I'm not aware of any. Some line breaks changed because "const_iterator" is 
> longer than "iterator".


Ack.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83087



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


[PATCH] D83176: [OpenMPIRBuilder][Fix] Move llvm::omp::types to OpenMPIRBuilder.

2020-07-08 Thread Stefan Stipanovic via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6aab27ba851f: [OpenMPIRBuilder][Fix] Move llvm::omp::types 
to OpenMPIRBuilder. (authored by sstefan1).

Changed prior to commit:
  https://reviews.llvm.org/D83176?vs=275549&id=275711#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83176

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPConstants.cpp
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -19,7 +19,6 @@
 
 using namespace llvm;
 using namespace omp;
-using namespace types;
 
 namespace {
 
@@ -50,7 +49,6 @@
   void TearDown() override {
 BB = nullptr;
 M.reset();
-uninitializeTypes();
   }
 
   LLVMContext Ctx;
Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp
===
--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -29,7 +29,6 @@
 
 using namespace llvm;
 using namespace omp;
-using namespace types;
 
 #define DEBUG_TYPE "openmp-opt"
 
@@ -263,11 +262,11 @@
   ICV.InitValue = nullptr; \
   break;   \
 case ICV_ZERO: \
-  ICV.InitValue =  \
-  ConstantInt::get(Type::getInt32Ty(Int32->getContext()), 0);  \
+  ICV.InitValue = ConstantInt::get(\
+  Type::getInt32Ty(OMPBuilder.Int32->getContext()), 0);\
   break;   \
 case ICV_FALSE:\
-  ICV.InitValue = ConstantInt::getFalse(Int1->getContext());   \
+  ICV.InitValue = ConstantInt::getFalse(OMPBuilder.Int1->getContext());\
   break;   \
 case ICV_LAST: \
   break;   \
@@ -332,16 +331,39 @@
 
 Module &M = *((*ModuleSlice.begin())->getParent());
 
+// Helper macros for handling __VA_ARGS__ in OMP_RTL
+#define OMP_TYPE(VarName, ...) \
+  Type *VarName = OMPBuilder.VarName;  \
+  (void)VarName;
+
+#define OMP_ARRAY_TYPE(VarName, ...)   \
+  ArrayType *VarName##Ty = OMPBuilder.VarName##Ty; \
+  (void)VarName##Ty;   \
+  PointerType *VarName##PtrTy = OMPBuilder.VarName##PtrTy; \
+  (void)VarName##PtrTy;
+
+#define OMP_FUNCTION_TYPE(VarName, ...)\
+  FunctionType *VarName = OMPBuilder.VarName;  \
+  (void)VarName;   \
+  PointerType *VarName##Ptr = OMPBuilder.VarName##Ptr; \
+  (void)VarName##Ptr;
+
+#define OMP_STRUCT_TYPE(VarName, ...)  \
+  StructType *VarName = OMPBuilder.VarName;\
+  (void)VarName;   \
+  PointerType *VarName##Ptr = OMPBuilder.VarName##Ptr; \
+  (void)VarName##Ptr;
+
 #define OMP_RTL(_Enum, _Name, _IsVarArg, _ReturnType, ...) \
   {\
 SmallVector ArgsTypes({__VA_ARGS__});   \
 Function *F = M.getFunction(_Name);\
-if (declMatchesRTFTypes(F, _ReturnType, ArgsTypes)) {  \
+if (declMatchesRTFTypes(F, OMPBuilder._ReturnType, ArgsTypes)) {   \
   auto &RFI = RFIs[_Enum]; \
  

[PATCH] D82938: [clangd] Implement path and URI translation for remote index

2020-07-08 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 276454.
kbobyrev marked 10 inline comments as done.
kbobyrev added a comment.

Address the rest of the comments and refactor code.

Patch is ready for the review again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82938

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/Client.h
  clang-tools-extra/clangd/index/remote/Index.proto
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/index/remote/unimplemented/UnimplementedClient.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -7,85 +7,257 @@
 //===--===//
 
 #include "../TestTU.h"
+#include "TestFS.h"
+#include "index/Index.h"
+#include "index/Ref.h"
 #include "index/Serialization.h"
+#include "index/Symbol.h"
+#include "index/SymbolID.h"
 #include "index/remote/marshalling/Marshalling.h"
+#include "clang/Index/IndexSymbol.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace clangd {
 namespace remote {
 namespace {
 
+using llvm::sys::path::convert_to_slash;
+
+const char *testPathURI(llvm::StringRef Path,
+llvm::UniqueStringSaver &Strings) {
+  const auto URI = URI::createFile(testPath(Path));
+  return Strings.save(URI.toString()).begin();
+}
+
+TEST(RemoteMarshallingTest, URITranslation) {
+  llvm::BumpPtrAllocator Arena;
+  llvm::UniqueStringSaver Strings(Arena);
+  clangd::Ref Original;
+  Original.Location.FileURI =
+  testPathURI("remote/machine/projects/llvm-project/clang-tools-extra/"
+  "clangd/unittests/remote/MarshallingTests.cpp",
+  Strings);
+  auto Serialized =
+  toProtobuf(Original, testPath("remote/machine/projects/llvm-project/"));
+  EXPECT_EQ(Serialized.location().file_path(),
+"clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp");
+  const std::string LocalIndexPrefix = testPath("local/machine/project/");
+  auto Deserialized = fromProtobuf(Serialized, &Strings,
+   testPath("home/my-projects/llvm-project"));
+  EXPECT_TRUE(Deserialized);
+  EXPECT_EQ(Deserialized->Location.FileURI,
+testPathURI("home/my-projects/llvm-project/clang-tools-extra/"
+"clangd/unittests/remote/MarshallingTests.cpp",
+Strings));
+
+  clangd::Ref WithInvalidURI;
+  // Invalid URI results in empty path.
+  WithInvalidURI.Location.FileURI = "This is not a URI";
+  Serialized = toProtobuf(WithInvalidURI, testPath("home/"));
+  EXPECT_EQ(Serialized.location().file_path(), "");
+
+  // Can not use URIs with scheme different from "file".
+  auto UnittestURI =
+  URI::create(testPath("project/lib/HelloWorld.cpp"), "unittest");
+  EXPECT_TRUE(bool(UnittestURI));
+  WithInvalidURI.Location.FileURI =
+  Strings.save(UnittestURI->toString()).begin();
+  Serialized = toProtobuf(WithInvalidURI, testPath("project/lib/"));
+  EXPECT_EQ(Serialized.location().file_path(), "");
+
+  Ref WithAbsolutePath;
+  *WithAbsolutePath.mutable_location()->mutable_file_path() =
+  "/usr/local/user/home/HelloWorld.cpp";
+  Deserialized = fromProtobuf(WithAbsolutePath, &Strings, LocalIndexPrefix);
+  // Paths transmitted over the wire can not be absolute, they have to be
+  // relative.
+  EXPECT_FALSE(Deserialized);
+}
+
 TEST(RemoteMarshallingTest, SymbolSerialization) {
-  const auto *Header = R"(
-  // This is a class.
-  class Foo {
-  public:
-Foo();
-
-int Bar;
-  private:
-double Number;
-  };
-  /// This is a function.
-  char baz();
-  template 
-  T getT ();
-  )";
-  const auto TU = TestTU::withHeaderCode(Header);
-  const auto Symbols = TU.headerSymbols();
-  // Sanity check: there are more than 5 symbols available.
-  EXPECT_GE(Symbols.size(), 5UL);
+  clangd::Symbol Sym;
+
+  auto ID = SymbolID::fromStr("057557CEBF6E6B2D");
+  EXPECT_TRUE(bool(ID));
+  Sym.ID = *ID;
+
+  index::SymbolInfo Info;
+  Info.Kind = index::SymbolKind::Function;
+  Info.SubKind = index::SymbolSubKind::AccessorGetter;
+  Info.Lang = index::SymbolLanguage::CXX;
+  Info.Properties = static_cast(
+  index::SymbolProperty::TemplateSpecialization);
+  Sym.SymInfo = Info;
+
   ll

[PATCH] D83369: hwasan: Don't pass the tagged-globals target-feature to non-aarch64 backends.

2020-07-08 Thread Mitch Phillips via Phabricator via cfe-commits
hctim accepted this revision.
hctim added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83369



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


  1   2   3   >