[clang-tools-extra] 24130d6 - [clang-tidy] Add readability-make-member-function-const

2019-11-06 Thread Matthias Gehre via cfe-commits

Author: Matthias Gehre
Date: 2019-11-06T09:27:02+01:00
New Revision: 24130d661ed42c30f009b695d3c9ce57d2208b5e

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

LOG: [clang-tidy] Add readability-make-member-function-const

Summary:
Finds non-static member functions that can be made ``const``
because the functions don't use ``this`` in a non-const way.

The check conservatively tries to preserve logical costness in favor of
physical costness. See readability-make-member-function-const.rst for more
details.

Reviewers: aaron.ballman, gribozavr, hokein, alexfh

Subscribers: mgorny, xazax.hun, cfe-commits

Tags: #clang

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

Added: 
clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.h

clang-tools-extra/docs/clang-tidy/checks/readability-make-member-function-const.rst
clang-tools-extra/test/clang-tidy/readability-make-member-function-const.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 7455e10831ce..bac7164508cf 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -15,6 +15,7 @@ add_clang_library(clangTidyReadabilityModule
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
+  MakeMemberFunctionConstCheck.cpp
   MisleadingIndentationCheck.cpp
   MisplacedArrayIndexCheck.cpp
   NamedParameterCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
new file mode 100644
index ..aca8d0fe89d8
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
@@ -0,0 +1,264 @@
+//===--- MakeMemberFunctionConstCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MakeMemberFunctionConstCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+
+AST_MATCHER(CXXMethodDecl, hasTrivialBody) { return Node.hasTrivialBody(); }
+
+AST_MATCHER(CXXRecordDecl, hasAnyDependentBases) {
+  return Node.hasAnyDependentBases();
+}
+
+AST_MATCHER(CXXMethodDecl, isTemplate) {
+  return Node.getTemplatedKind() != FunctionDecl::TK_NonTemplate;
+}
+
+AST_MATCHER(CXXMethodDecl, isDependentContext) {
+  return Node.isDependentContext();
+}
+
+AST_MATCHER(CXXMethodDecl, isInsideMacroDefinition) {
+  const ASTContext &Ctxt = Finder->getASTContext();
+  return clang::Lexer::makeFileCharRange(
+ clang::CharSourceRange::getCharRange(
+ Node.getTypeSourceInfo()->getTypeLoc().getSourceRange()),
+ Ctxt.getSourceManager(), Ctxt.getLangOpts())
+  .isInvalid();
+}
+
+AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(*Node.getCanonicalDecl(), Finder, Builder);
+}
+
+enum UsageKind { Unused, Const, NonConst };
+
+class FindUsageOfThis : public RecursiveASTVisitor {
+  ASTContext &Ctxt;
+
+public:
+  FindUsageOfThis(ASTContext &Ctxt) : Ctxt(Ctxt) {}
+  UsageKind Usage = Unused;
+
+  template  const T *getParent(const Expr *E) {
+ASTContext::DynTypedNodeList Parents = Ctxt.getParents(*E);
+if (Parents.size() != 1)
+  return nullptr;
+
+return Parents.begin()->get();
+  }
+
+  bool VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *) {
+// An UnresolvedMemberExpr might resolve to a non-const non-static
+// member function.
+Usage = NonConst;
+return false; // Stop traversal.
+  }
+
+  bool VisitCXXConstCastExpr(const CXXConstCastExpr *) {
+// Workaround to support the pattern
+// class C {
+//   const S *get() const;
+//   S* get() {
+// return const_cast(const_cast(this)->get());
+//   }
+// };
+// Here,

[PATCH] D68074: [clang-tidy] Add readability-make-member-function-const

2019-11-06 Thread Matthias Gehre via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG24130d661ed4: [clang-tidy] Add 
readability-make-member-function-const (authored by mgehre).

Changed prior to commit:
  https://reviews.llvm.org/D68074?vs=225804&id=228006#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68074

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
  clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability-make-member-function-const.rst
  clang-tools-extra/test/clang-tidy/readability-make-member-function-const.cpp

Index: clang-tools-extra/test/clang-tidy/readability-make-member-function-const.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-make-member-function-const.cpp
@@ -0,0 +1,332 @@
+// RUN: %check_clang_tidy %s readability-make-member-function-const %t
+
+struct Str {
+  void const_method() const;
+  void non_const_method();
+};
+
+namespace Diagnose {
+struct A;
+
+void free_const_use(const A *);
+void free_const_use(const A &);
+
+struct A {
+  int M;
+  const int ConstM;
+  struct {
+int M;
+  } Struct;
+  Str S;
+  Str &Sref;
+
+  void already_const() const;
+
+  int read_field() {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'read_field' can be made const
+// CHECK-FIXES: {{^}}  int read_field() const {
+return M;
+  }
+
+  int read_struct_field() {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'read_struct_field' can be made const
+// CHECK-FIXES: {{^}}  int read_struct_field() const {
+return Struct.M;
+  }
+
+  int read_const_field() {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'read_const_field' can be made const
+// CHECK-FIXES: {{^}}  int read_const_field() const {
+return ConstM;
+  }
+
+  void call_const_member() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'call_const_member' can be made const
+// CHECK-FIXES: {{^}}  void call_const_member() const {
+already_const();
+  }
+
+  void call_const_member_on_public_field() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'call_const_member_on_public_field' can be made const
+// CHECK-FIXES: {{^}}  void call_const_member_on_public_field() const {
+S.const_method();
+  }
+
+  void call_const_member_on_public_field_ref() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'call_const_member_on_public_field_ref' can be made const
+// CHECK-FIXES: {{^}}  void call_const_member_on_public_field_ref() const {
+Sref.const_method();
+  }
+
+  const Str &return_public_field_ref() {
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: method 'return_public_field_ref' can be made const
+// CHECK-FIXES: {{^}}  const Str &return_public_field_ref() const {
+return S;
+  }
+
+  const A *return_this_const() {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: method 'return_this_const' can be made const
+// CHECK-FIXES: {{^}}  const A *return_this_const() const {
+return this;
+  }
+
+  const A &return_this_const_ref() {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: method 'return_this_const_ref' can be made const
+// CHECK-FIXES: {{^}}  const A &return_this_const_ref() const {
+return *this;
+  }
+
+  void const_use() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'const_use' can be made const
+// CHECK-FIXES: {{^}}  void const_use() const {
+free_const_use(this);
+  }
+
+  void const_use_ref() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'const_use_ref' can be made const
+// CHECK-FIXES: {{^}}  void const_use_ref() const {
+free_const_use(*this);
+  }
+
+  auto trailingReturn() -> int {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'trailingReturn' can be made const
+// CHECK-FIXES: {{^}}  auto trailingReturn() const -> int {
+return M;
+  }
+
+  int volatileFunction() volatile {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'volatileFunction' can be made const
+// CHECK-FIXES: {{^}}  int volatileFunction() const volatile {
+return M;
+  }
+
+  int restrictFunction() __restrict {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'restrictFunction' can be made const
+// CHECK-FIXES: {{^}}  int restrictFunction() const __restrict {
+return M;
+  }
+
+  int refFunction() & {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: method 'refFunction' can be made const
+// CHECK-FIXES: {{^}}  int refFunction() const & {
+return M;
+  }
+
+  void out_of_line_call_const();
+  // CHECK-FIXES: {{^}}  void out_of_line_call_const()

[clang] 76ec6b1 - [clang-format] [PR35518] C++17 deduction guides are wrongly formatted

2019-11-06 Thread via cfe-commits

Author: paulhoad
Date: 2019-11-06T09:34:48Z
New Revision: 76ec6b1ef69fcbd27cb0d587a5eb2d51a135a6bb

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

LOG: [clang-format] [PR35518] C++17 deduction guides are wrongly formatted

Summary:
see https://bugs.llvm.org/show_bug.cgi?id=35518

clang-format removes spaces around deduction guides but not trailing return 
types, make the consistent

```
template  S(T)->S;
auto f(int, int) -> double;
```

becomes

```
template  S(T) -> S;
auto f(int, int) -> double;
```

Reviewers: klimek, mitchell-stellar, owenpan, sammccall, lichray, curdeius, 
KyrBoh

Reviewed By: curdeius

Subscribers: merge_guards_bot, hans, lichray, cfe-commits

Tags: #clang-format, #clang-tools-extra, #clang

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 98b87c0f5a25..3bd415ebd699 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1350,6 +1350,70 @@ class AnnotatingParser {
 }
   }
 
+  static FormatToken *untilMatchingParen(FormatToken *Current) {
+// Used when `MatchingParen` is not yet established.
+int ParenLevel = 0;
+while (Current) {
+  if (Current->is(tok::l_paren))
+ParenLevel++;
+  if (Current->is(tok::r_paren))
+ParenLevel--;
+  if (ParenLevel < 1)
+break;
+  Current = Current->Next;
+}
+return Current;
+  }
+
+  static bool isDeductionGuide(FormatToken &Current) {
+// Look for a deduction guide template A(...) -> A<...>;
+if (Current.Previous && Current.Previous->is(tok::r_paren) &&
+Current.startsSequence(tok::arrow, tok::identifier, tok::less)) {
+  // Find the TemplateCloser.
+  FormatToken *TemplateCloser = Current.Next->Next;
+  int NestingLevel = 0;
+  while (TemplateCloser) {
+// Skip over an expressions in parens  A<(3 < 2)>;
+if (TemplateCloser->is(tok::l_paren)) {
+  // No Matching Paren yet so skip to matching paren
+  TemplateCloser = untilMatchingParen(TemplateCloser);
+}
+if (TemplateCloser->is(tok::less))
+  NestingLevel++;
+if (TemplateCloser->is(tok::greater))
+  NestingLevel--;
+if (NestingLevel < 1)
+  break;
+TemplateCloser = TemplateCloser->Next;
+  }
+  // Assuming we have found the end of the template ensure its followed
+  // with a semi-colon.
+  if (TemplateCloser && TemplateCloser->Next &&
+  TemplateCloser->Next->is(tok::semi) &&
+  Current.Previous->MatchingParen) {
+// Determine if the identifier `A` prior to the A<..>; is the same as
+// prior to the A(..)
+FormatToken *LeadingIdentifier =
+Current.Previous->MatchingParen->Previous;
+
+// Differentiate a deduction guide by seeing the
+// > of the template prior to the leading identifier.
+if (LeadingIdentifier) {
+  FormatToken *PriorLeadingIdentifier = LeadingIdentifier->Previous;
+  // Skip back past explicit decoration
+  if (PriorLeadingIdentifier &&
+  PriorLeadingIdentifier->is(tok::kw_explicit))
+PriorLeadingIdentifier = PriorLeadingIdentifier->Previous;
+
+  return (PriorLeadingIdentifier &&
+  PriorLeadingIdentifier->is(TT_TemplateCloser) &&
+  LeadingIdentifier->TokenText == Current.Next->TokenText);
+}
+  }
+}
+return false;
+  }
+
   void determineTokenType(FormatToken &Current) {
 if (!Current.is(TT_Unknown))
   // The token type is already known.
@@ -1397,6 +1461,10 @@ class AnnotatingParser {
!Current.Previous->is(tok::kw_operator)) {
   // not auto operator->() -> xxx;
   Current.Type = TT_TrailingReturnArrow;
+
+} else if (isDeductionGuide(Current)) {
+  // Deduction guides trailing arrow " A(...) -> A;".
+  Current.Type = TT_TrailingReturnArrow;
 } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) {
   Current.Type = determineStarAmpUsage(Current,
Contexts.back().CanBeExpression &&

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index ea03ee1c3cc9..eacb389400b4 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4977,6 +4977,29 @@ TEST_F(FormatTest, TrailingReturnType) {
   verifyFormat("void f() { auto a = b->c(); }");
 }
 
+TEST_F(FormatTest, DeductionGuides) {
+  verifyFormat("template  A(const T &, const T &) -> A;");

[PATCH] D69577: [clang-format] [PR35518] C++17 deduction guides are wrongly formatted

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG76ec6b1ef69f: [clang-format] [PR35518] C++17 deduction 
guides are wrongly formatted (authored by MyDeveloperDay).

Changed prior to commit:
  https://reviews.llvm.org/D69577?vs=227952&id=228008#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69577

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4977,6 +4977,29 @@
   verifyFormat("void f() { auto a = b->c(); }");
 }
 
+TEST_F(FormatTest, DeductionGuides) {
+  verifyFormat("template  A(const T &, const T &) -> A;");
+  verifyFormat("template  explicit A(T &, T &&) -> A;");
+  verifyFormat("template  S(Ts...) -> S;");
+  verifyFormat(
+  "template \n"
+  "array(T &&... t) -> array, sizeof...(T)>;");
+  verifyFormat("template  A() -> Afoo<3>())>;");
+  verifyFormat("template  A() -> A>)>;");
+  verifyFormat("template  A() -> Afoo<1>)>;");
+  verifyFormat("template  A() -> A<(3 < 2)>;");
+  verifyFormat("template  A() -> A<((3) < (2))>;");
+  verifyFormat("template  x() -> x<1>;");
+  verifyFormat("template  explicit x(T &) -> x<1>;");
+
+  // Ensure not deduction guides.
+  verifyFormat("c()->f();");
+  verifyFormat("x()->foo<1>;");
+  verifyFormat("x = p->foo<3>();");
+  verifyFormat("x()->x<1>();");
+  verifyFormat("x()->x<1>;");
+}
+
 TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
   // Avoid breaking before trailing 'const' or other trailing annotations, if
   // they are not function-like.
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1350,6 +1350,70 @@
 }
   }
 
+  static FormatToken *untilMatchingParen(FormatToken *Current) {
+// Used when `MatchingParen` is not yet established.
+int ParenLevel = 0;
+while (Current) {
+  if (Current->is(tok::l_paren))
+ParenLevel++;
+  if (Current->is(tok::r_paren))
+ParenLevel--;
+  if (ParenLevel < 1)
+break;
+  Current = Current->Next;
+}
+return Current;
+  }
+
+  static bool isDeductionGuide(FormatToken &Current) {
+// Look for a deduction guide template A(...) -> A<...>;
+if (Current.Previous && Current.Previous->is(tok::r_paren) &&
+Current.startsSequence(tok::arrow, tok::identifier, tok::less)) {
+  // Find the TemplateCloser.
+  FormatToken *TemplateCloser = Current.Next->Next;
+  int NestingLevel = 0;
+  while (TemplateCloser) {
+// Skip over an expressions in parens  A<(3 < 2)>;
+if (TemplateCloser->is(tok::l_paren)) {
+  // No Matching Paren yet so skip to matching paren
+  TemplateCloser = untilMatchingParen(TemplateCloser);
+}
+if (TemplateCloser->is(tok::less))
+  NestingLevel++;
+if (TemplateCloser->is(tok::greater))
+  NestingLevel--;
+if (NestingLevel < 1)
+  break;
+TemplateCloser = TemplateCloser->Next;
+  }
+  // Assuming we have found the end of the template ensure its followed
+  // with a semi-colon.
+  if (TemplateCloser && TemplateCloser->Next &&
+  TemplateCloser->Next->is(tok::semi) &&
+  Current.Previous->MatchingParen) {
+// Determine if the identifier `A` prior to the A<..>; is the same as
+// prior to the A(..)
+FormatToken *LeadingIdentifier =
+Current.Previous->MatchingParen->Previous;
+
+// Differentiate a deduction guide by seeing the
+// > of the template prior to the leading identifier.
+if (LeadingIdentifier) {
+  FormatToken *PriorLeadingIdentifier = LeadingIdentifier->Previous;
+  // Skip back past explicit decoration
+  if (PriorLeadingIdentifier &&
+  PriorLeadingIdentifier->is(tok::kw_explicit))
+PriorLeadingIdentifier = PriorLeadingIdentifier->Previous;
+
+  return (PriorLeadingIdentifier &&
+  PriorLeadingIdentifier->is(TT_TemplateCloser) &&
+  LeadingIdentifier->TokenText == Current.Next->TokenText);
+}
+  }
+}
+return false;
+  }
+
   void determineTokenType(FormatToken &Current) {
 if (!Current.is(TT_Unknown))
   // The token type is already known.
@@ -1397,6 +1461,10 @@
!Current.Previous->is(tok::kw_operator)) {
   // not auto operator->() -> xxx;
   Current.Type = TT_TrailingReturnArrow;
+
+} else if (isDeductionGuide(Current)) {
+  // Deduction guides trailing arrow " A(...) -> A;".
+  Current.Type = TT_TrailingReturnArrow;
 } else if (Current.isOneO

[PATCH] D69752: clang-format: Add a fallback style to Emacs mode

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf349cc37cc48: clang-format: Add a fallback style to Emacs 
mode (authored by MyDeveloperDay).

Changed prior to commit:
  https://reviews.llvm.org/D69752?vs=227584&id=228010#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69752

Files:
  clang/tools/clang-format/clang-format.el


Index: clang/tools/clang-format/clang-format.el
===
--- clang/tools/clang-format/clang-format.el
+++ clang/tools/clang-format/clang-format.el
@@ -57,6 +57,18 @@
   :safe #'stringp)
 (make-variable-buffer-local 'clang-format-style)
 
+(defcustom clang-format-fallback-style "none"
+  "Fallback style to pass to clang-format.
+
+This style will be used if clang-format-style is set to \"file\"
+and no .clang-format is found in the directory of the buffer or
+one of parent directories. Set to \"none\" to disable formatting
+in such buffers."
+  :group 'clang-format
+  :type 'string
+  :safe #'stringp)
+(make-variable-buffer-local 'clang-format-fallback-style)
+
 (defun clang-format--extract (xml-node)
   "Extract replacements and cursor information from XML-NODE."
   (unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements))
@@ -162,6 +174,7 @@
,@(and assume-file-name
   (list "-assume-filename" 
assume-file-name))
,@(and style (list "-style" style))
+   "-fallback-style" ,clang-format-fallback-style
"-offset" ,(number-to-string file-start)
"-length" ,(number-to-string (- file-end 
file-start))
"-cursor" ,(number-to-string cursor


Index: clang/tools/clang-format/clang-format.el
===
--- clang/tools/clang-format/clang-format.el
+++ clang/tools/clang-format/clang-format.el
@@ -57,6 +57,18 @@
   :safe #'stringp)
 (make-variable-buffer-local 'clang-format-style)
 
+(defcustom clang-format-fallback-style "none"
+  "Fallback style to pass to clang-format.
+
+This style will be used if clang-format-style is set to \"file\"
+and no .clang-format is found in the directory of the buffer or
+one of parent directories. Set to \"none\" to disable formatting
+in such buffers."
+  :group 'clang-format
+  :type 'string
+  :safe #'stringp)
+(make-variable-buffer-local 'clang-format-fallback-style)
+
 (defun clang-format--extract (xml-node)
   "Extract replacements and cursor information from XML-NODE."
   (unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements))
@@ -162,6 +174,7 @@
,@(and assume-file-name
   (list "-assume-filename" assume-file-name))
,@(and style (list "-style" style))
+   "-fallback-style" ,clang-format-fallback-style
"-offset" ,(number-to-string file-start)
"-length" ,(number-to-string (- file-end file-start))
"-cursor" ,(number-to-string cursor
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69433: [clang-format] [NFC] update the documentation in Format.h to allow dump_format_style.py to get a little closer to being correct. (part 2)

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 228009.
MyDeveloperDay marked 9 inline comments as done.
MyDeveloperDay added a comment.

Address a few grammatical review comments

After modifications

F10640074: image.png 


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

https://reviews.llvm.org/D69433

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -708,7 +708,7 @@
 BS_Allman,
 /// Like ``Allman`` but always indent braces and line up code with braces.
 /// \code
-///try
+///   try
 /// {
 /// foo();
 /// }
@@ -850,6 +850,7 @@
 ///   {};
 /// \endcode
 bool AfterClass;
+
 /// Wrap control statements (``if``/``for``/``while``/``switch``/..).
 BraceWrappingAfterControlStatementStyle AfterControlStatement;
 /// Wrap enum definitions.
@@ -1965,7 +1966,8 @@
   bool SpacesInParentheses;
 
   /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
-  /// Lambdas or unspecified size array declarations will not be affected.
+  /// Lambdas without arguments or unspecified size array declarations will not
+  /// be affected.
   /// \code
   ///true:  false:
   ///int a[ 5 ];vs. int a[5];
@@ -1982,26 +1984,29 @@
   /// The correct way to spell a specific language version is e.g. ``c++11``.
   /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
   enum LanguageStandard {
-/// c++03: Parse and format as C++03.
-LS_Cpp03,
-/// c++11: Parse and format as C++11.
-LS_Cpp11,
-/// c++14: Parse and format as C++14.
-LS_Cpp14,
-/// c++17: Parse and format as C++17.
-LS_Cpp17,
-/// c++20: Parse and format as C++20.
-LS_Cpp20,
-/// Latest: Parse and format using the latest supported language version.
-/// 'Cpp11' is an alias for LS_Latest for historical reasons.
+/// Parse and format as C++03.
+/// ``Cpp03`` is a deprecated alias for ``c++03``
+LS_Cpp03, // c++03
+/// Parse and format as C++11.
+LS_Cpp11, // c++11
+/// Parse and format as C++14.
+LS_Cpp14, // c++14
+/// Parse and format as C++17.
+LS_Cpp17, // c++17
+/// Parse and format as C++20.
+LS_Cpp20, // c++20
+/// Parse and format using the latest supported language version.
+/// ``Cpp11`` is a deprecated alias for ``Latest``
 LS_Latest,
-/// Auto: Automatic detection based on the input.
-/// Parse using the latest language version. Format based on detected input.
+/// Automatic detection based on the input.
 LS_Auto,
   };
 
-  /// Format compatible with this standard, e.g. use ``A >``
-  /// instead of ``A>`` for ``LS_Cpp03``.
+  /// Parse and format C++ constructs compatible with this standard.
+  /// \code
+  ///c++03: latest:
+  ///vector > x;   vs. vector> x;
+  /// \endcode
   LanguageStandard Standard;
 
   /// The number of columns used for tab stops.
Index: clang/docs/tools/dump_format_style.py
===
--- clang/docs/tools/dump_format_style.py
+++ clang/docs/tools/dump_format_style.py
@@ -78,14 +78,15 @@
 return '\n'.join(map(str, self.values))
 
 class EnumValue(object):
-  def __init__(self, name, comment):
+  def __init__(self, name, comment, config):
 self.name = name
 self.comment = comment
+self.config = config
 
   def __str__(self):
 return '* ``%s`` (in configuration: ``%s``)\n%s' % (
 self.name,
-re.sub('.*_', '', self.name),
+re.sub('.*_', '', self.config),
 doxygen2rst(indent(self.comment, 2)))
 
 def clean_comment_line(line):
@@ -170,7 +171,14 @@
 comment += clean_comment_line(line)
   else:
 state = State.InEnum
-enum.values.append(EnumValue(line.replace(',', ''), comment))
+val = line.replace(',', '')
+pos = val.find(" // ")
+if (pos != -1):
+config = val[pos+4:]
+val = val[:pos]
+else:
+config = val;
+enum.values.append(EnumValue(val, comment,config))
   if state != State.Finished:
 raise Exception('Not finished by the end of file')
 
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -2312,8 +2312,8 @@
 
 **SpacesInSquareBrackets** (``bool``)
   If ``true``, spaces will be inserted after ``[`` and before ``]``.
-  Lambdas without arguments or unspecified size array declarations will not be
-  affected.
+  Lambdas without argumen

[PATCH] D69433: [clang-format] [NFC] update the documentation in Format.h to allow dump_format_style.py to get a little closer to being correct. (part 2)

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/include/clang/Format/Format.h:2001
 LS_Latest,
-/// Auto: Automatic detection based on the input.
-/// Parse using the latest language version. Format based on detected 
input.
+/// Automatic detection based on the input.
 LS_Auto,

sammccall wrote:
> The new text (two lines) is better, please add it back.
you can't this breaks the script


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

https://reviews.llvm.org/D69433



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


[clang] f349cc3 - clang-format: Add a fallback style to Emacs mode

2019-11-06 Thread via cfe-commits

Author: paulhoad
Date: 2019-11-06T09:50:54Z
New Revision: f349cc37cc485fd5fc7b34cb84053af459337ecc

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

LOG: clang-format: Add a fallback style to Emacs mode

Summary:
This allows one to enable `clang-format-buffer` on file save and avoid
reformatting files that are outside of any project with .clang-format style.

Reviewers: djasper, klimek, sammccall, owenpan, mitchell-stellar, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Patch By: dottedmag

Tags: #clang, #clang-format

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

Added: 


Modified: 
clang/tools/clang-format/clang-format.el

Removed: 




diff  --git a/clang/tools/clang-format/clang-format.el 
b/clang/tools/clang-format/clang-format.el
index 3096ec12f558..768acb3a5d0d 100644
--- a/clang/tools/clang-format/clang-format.el
+++ b/clang/tools/clang-format/clang-format.el
@@ -57,6 +57,18 @@ of the buffer."
   :safe #'stringp)
 (make-variable-buffer-local 'clang-format-style)
 
+(defcustom clang-format-fallback-style "none"
+  "Fallback style to pass to clang-format.
+
+This style will be used if clang-format-style is set to \"file\"
+and no .clang-format is found in the directory of the buffer or
+one of parent directories. Set to \"none\" to disable formatting
+in such buffers."
+  :group 'clang-format
+  :type 'string
+  :safe #'stringp)
+(make-variable-buffer-local 'clang-format-fallback-style)
+
 (defun clang-format--extract (xml-node)
   "Extract replacements and cursor information from XML-NODE."
   (unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements))
@@ -162,6 +174,7 @@ uses the function `buffer-file-name'."
,@(and assume-file-name
   (list "-assume-filename" 
assume-file-name))
,@(and style (list "-style" style))
+   "-fallback-style" ,clang-format-fallback-style
"-offset" ,(number-to-string file-start)
"-length" ,(number-to-string (- file-end 
file-start))
"-cursor" ,(number-to-string cursor



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


[clang-tools-extra] 7ea4c6f - [clangd] Implement a function to lex the file to find candidate occurrences.

2019-11-06 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2019-11-06T09:56:02+01:00
New Revision: 7ea4c6fa5121b2417875dc1b547162e18be7dbe2

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

LOG: [clangd] Implement a function to lex the file to find candidate 
occurrences.

Summary:
This will be used for incoming cross-file rename (to detect index
staleness issue).

Reviewers: ilya-biryukov

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/SourceCode.h
clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index a0cec30f10aa..e52588d6aa84 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -719,41 +719,53 @@ cleanupAndFormat(StringRef Code, const 
tooling::Replacements &Replaces,
   return formatReplacements(Code, std::move(*CleanReplaces), Style);
 }
 
-void lex(llvm::StringRef Code, const format::FormatStyle &Style,
- llvm::function_ref Action) {
+void lex(llvm::StringRef Code, const LangOptions &LangOpts,
+ llvm::function_ref
+ Action) {
   // FIXME: InMemoryFileAdapter crashes unless the buffer is null terminated!
   std::string NullTerminatedCode = Code.str();
   SourceManagerForFile FileSM("dummy.cpp", NullTerminatedCode);
   auto &SM = FileSM.get();
   auto FID = SM.getMainFileID();
-  Lexer Lex(FID, SM.getBuffer(FID), SM, format::getFormattingLangOpts(Style));
+  // Create a raw lexer (with no associated preprocessor object).
+  Lexer Lex(FID, SM.getBuffer(FID), SM, LangOpts);
   Token Tok;
 
   while (!Lex.LexFromRawLexer(Tok))
-Action(Tok, sourceLocToPosition(SM, Tok.getLocation()));
+Action(Tok, SM);
   // LexFromRawLexer returns true after it lexes last token, so we still have
   // one more token to report.
-  Action(Tok, sourceLocToPosition(SM, Tok.getLocation()));
+  Action(Tok, SM);
 }
 
 llvm::StringMap collectIdentifiers(llvm::StringRef Content,
  const format::FormatStyle &Style) 
{
   llvm::StringMap Identifiers;
-  lex(Content, Style, [&](const clang::Token &Tok, Position) {
-switch (Tok.getKind()) {
-case tok::identifier:
-  ++Identifiers[Tok.getIdentifierInfo()->getName()];
-  break;
-case tok::raw_identifier:
+  auto LangOpt = format::getFormattingLangOpts(Style);
+  lex(Content, LangOpt, [&](const clang::Token &Tok, const SourceManager &) {
+if (Tok.getKind() == tok::raw_identifier)
   ++Identifiers[Tok.getRawIdentifier()];
-  break;
-default:
-  break;
-}
   });
   return Identifiers;
 }
 
+std::vector collectIdentifierRanges(llvm::StringRef Identifier,
+   llvm::StringRef Content,
+   const LangOptions &LangOpts) {
+  std::vector Ranges;
+  lex(Content, LangOpts, [&](const clang::Token &Tok, const SourceManager &SM) 
{
+if (Tok.getKind() != tok::raw_identifier)
+  return;
+if (Tok.getRawIdentifier() != Identifier)
+  return;
+auto Range = getTokenRange(SM, LangOpts, Tok.getLocation());
+if (!Range)
+  return;
+Ranges.push_back(*Range);
+  });
+  return Ranges;
+}
+
 namespace {
 struct NamespaceEvent {
   enum {
@@ -786,8 +798,9 @@ void parseNamespaceEvents(llvm::StringRef Code,
   std::string NSName;
 
   NamespaceEvent Event;
-  lex(Code, Style, [&](const clang::Token &Tok, Position P) {
-Event.Pos = std::move(P);
+  lex(Code, format::getFormattingLangOpts(Style),
+  [&](const clang::Token &Tok,const SourceManager &SM) {
+Event.Pos = sourceLocToPosition(SM, Tok.getLocation());
 switch (Tok.getKind()) {
 case tok::raw_identifier:
   // In raw mode, this could be a keyword or a name.

diff  --git a/clang-tools-extra/clangd/SourceCode.h 
b/clang-tools-extra/clangd/SourceCode.h
index a05d8adf923d..d20e03f5b87f 100644
--- a/clang-tools-extra/clangd/SourceCode.h
+++ b/clang-tools-extra/clangd/SourceCode.h
@@ -232,6 +232,11 @@ llvm::Error reformatEdit(Edit &E, const 
format::FormatStyle &Style);
 llvm::StringMap collectIdentifiers(llvm::StringRef Content,
  const format::FormatStyle &Style);
 
+/// Collects all ranges of the given identifier in the source code.
+std::vector collectIdentifierRanges(llvm::StringRef Identifier,
+   llvm::StringRef Content,
+   const LangOptions &LangOpts);
+
 /// Collects words from the source code.
 /// Unlike collectIdentifiers:
 /// - 

[PATCH] D69615: [clangd] Implement a function to lex the file to find candidate occurrences.

2019-11-06 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ea4c6fa5121: [clangd] Implement a function to lex the file 
to find candidate occurrences. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69615

Files:
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -680,6 +680,27 @@
 EXPECT_EQ(Res.EnclosingNamespace, Case.EnclosingNamespace) << Test.code();
   }
 }
+
+TEST(SourceCodeTests, IdentifierRanges) {
+  Annotations Code(R"cpp(
+   class [[Foo]] {};
+   // Foo
+   /* Foo */
+   void f([[Foo]]* foo1) {
+ [[Foo]] foo2;
+ auto S = [[Foo]]();
+// cross-line identifier is not supported.
+F\
+o\
+o foo2;
+   }
+  )cpp");
+  LangOptions LangOpts;
+  LangOpts.CPlusPlus = true;
+  EXPECT_EQ(Code.ranges(),
+collectIdentifierRanges("Foo", Code.code(), LangOpts));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -232,6 +232,11 @@
 llvm::StringMap collectIdentifiers(llvm::StringRef Content,
  const format::FormatStyle &Style);
 
+/// Collects all ranges of the given identifier in the source code.
+std::vector collectIdentifierRanges(llvm::StringRef Identifier,
+   llvm::StringRef Content,
+   const LangOptions &LangOpts);
+
 /// Collects words from the source code.
 /// Unlike collectIdentifiers:
 /// - also finds text in comments:
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -719,41 +719,53 @@
   return formatReplacements(Code, std::move(*CleanReplaces), Style);
 }
 
-void lex(llvm::StringRef Code, const format::FormatStyle &Style,
- llvm::function_ref Action) {
+void lex(llvm::StringRef Code, const LangOptions &LangOpts,
+ llvm::function_ref
+ Action) {
   // FIXME: InMemoryFileAdapter crashes unless the buffer is null terminated!
   std::string NullTerminatedCode = Code.str();
   SourceManagerForFile FileSM("dummy.cpp", NullTerminatedCode);
   auto &SM = FileSM.get();
   auto FID = SM.getMainFileID();
-  Lexer Lex(FID, SM.getBuffer(FID), SM, format::getFormattingLangOpts(Style));
+  // Create a raw lexer (with no associated preprocessor object).
+  Lexer Lex(FID, SM.getBuffer(FID), SM, LangOpts);
   Token Tok;
 
   while (!Lex.LexFromRawLexer(Tok))
-Action(Tok, sourceLocToPosition(SM, Tok.getLocation()));
+Action(Tok, SM);
   // LexFromRawLexer returns true after it lexes last token, so we still have
   // one more token to report.
-  Action(Tok, sourceLocToPosition(SM, Tok.getLocation()));
+  Action(Tok, SM);
 }
 
 llvm::StringMap collectIdentifiers(llvm::StringRef Content,
  const format::FormatStyle &Style) {
   llvm::StringMap Identifiers;
-  lex(Content, Style, [&](const clang::Token &Tok, Position) {
-switch (Tok.getKind()) {
-case tok::identifier:
-  ++Identifiers[Tok.getIdentifierInfo()->getName()];
-  break;
-case tok::raw_identifier:
+  auto LangOpt = format::getFormattingLangOpts(Style);
+  lex(Content, LangOpt, [&](const clang::Token &Tok, const SourceManager &) {
+if (Tok.getKind() == tok::raw_identifier)
   ++Identifiers[Tok.getRawIdentifier()];
-  break;
-default:
-  break;
-}
   });
   return Identifiers;
 }
 
+std::vector collectIdentifierRanges(llvm::StringRef Identifier,
+   llvm::StringRef Content,
+   const LangOptions &LangOpts) {
+  std::vector Ranges;
+  lex(Content, LangOpts, [&](const clang::Token &Tok, const SourceManager &SM) {
+if (Tok.getKind() != tok::raw_identifier)
+  return;
+if (Tok.getRawIdentifier() != Identifier)
+  return;
+auto Range = getTokenRange(SM, LangOpts, Tok.getLocation());
+if (!Range)
+  return;
+Ranges.push_back(*Range);
+  });
+  return Ranges;
+}
+
 namespace {
 struct NamespaceEvent {
   enum {
@@ -786,8 +798,9 @@
   std::string NSName;
 
   NamespaceEvent Event;
-  lex(Code, Style, [&](const clang::Token &Tok, Position P) {
-Event.Pos = std::move(P);
+  lex(Code, format::getFormattingLangOpts(Style),
+  [&](const clang::Token &To

[PATCH] D69615: [clangd] Implement a function to lex the file to find candidate occurrences.

2019-11-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 228011.
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/D69615/new/

https://reviews.llvm.org/D69615

Files:
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -680,6 +680,27 @@
 EXPECT_EQ(Res.EnclosingNamespace, Case.EnclosingNamespace) << Test.code();
   }
 }
+
+TEST(SourceCodeTests, IdentifierRanges) {
+  Annotations Code(R"cpp(
+   class [[Foo]] {};
+   // Foo
+   /* Foo */
+   void f([[Foo]]* foo1) {
+ [[Foo]] foo2;
+ auto S = [[Foo]]();
+// cross-line identifier is not supported.
+F\
+o\
+o foo2;
+   }
+  )cpp");
+  LangOptions LangOpts;
+  LangOpts.CPlusPlus = true;
+  EXPECT_EQ(Code.ranges(),
+collectIdentifierRanges("Foo", Code.code(), LangOpts));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -232,6 +232,11 @@
 llvm::StringMap collectIdentifiers(llvm::StringRef Content,
  const format::FormatStyle &Style);
 
+/// Collects all ranges of the given identifier in the source code.
+std::vector collectIdentifierRanges(llvm::StringRef Identifier,
+   llvm::StringRef Content,
+   const LangOptions &LangOpts);
+
 /// Collects words from the source code.
 /// Unlike collectIdentifiers:
 /// - also finds text in comments:
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -719,41 +719,53 @@
   return formatReplacements(Code, std::move(*CleanReplaces), Style);
 }
 
-void lex(llvm::StringRef Code, const format::FormatStyle &Style,
- llvm::function_ref Action) {
+void lex(llvm::StringRef Code, const LangOptions &LangOpts,
+ llvm::function_ref
+ Action) {
   // FIXME: InMemoryFileAdapter crashes unless the buffer is null terminated!
   std::string NullTerminatedCode = Code.str();
   SourceManagerForFile FileSM("dummy.cpp", NullTerminatedCode);
   auto &SM = FileSM.get();
   auto FID = SM.getMainFileID();
-  Lexer Lex(FID, SM.getBuffer(FID), SM, format::getFormattingLangOpts(Style));
+  // Create a raw lexer (with no associated preprocessor object).
+  Lexer Lex(FID, SM.getBuffer(FID), SM, LangOpts);
   Token Tok;
 
   while (!Lex.LexFromRawLexer(Tok))
-Action(Tok, sourceLocToPosition(SM, Tok.getLocation()));
+Action(Tok, SM);
   // LexFromRawLexer returns true after it lexes last token, so we still have
   // one more token to report.
-  Action(Tok, sourceLocToPosition(SM, Tok.getLocation()));
+  Action(Tok, SM);
 }
 
 llvm::StringMap collectIdentifiers(llvm::StringRef Content,
  const format::FormatStyle &Style) {
   llvm::StringMap Identifiers;
-  lex(Content, Style, [&](const clang::Token &Tok, Position) {
-switch (Tok.getKind()) {
-case tok::identifier:
-  ++Identifiers[Tok.getIdentifierInfo()->getName()];
-  break;
-case tok::raw_identifier:
+  auto LangOpt = format::getFormattingLangOpts(Style);
+  lex(Content, LangOpt, [&](const clang::Token &Tok, const SourceManager &) {
+if (Tok.getKind() == tok::raw_identifier)
   ++Identifiers[Tok.getRawIdentifier()];
-  break;
-default:
-  break;
-}
   });
   return Identifiers;
 }
 
+std::vector collectIdentifierRanges(llvm::StringRef Identifier,
+   llvm::StringRef Content,
+   const LangOptions &LangOpts) {
+  std::vector Ranges;
+  lex(Content, LangOpts, [&](const clang::Token &Tok, const SourceManager &SM) {
+if (Tok.getKind() != tok::raw_identifier)
+  return;
+if (Tok.getRawIdentifier() != Identifier)
+  return;
+auto Range = getTokenRange(SM, LangOpts, Tok.getLocation());
+if (!Range)
+  return;
+Ranges.push_back(*Range);
+  });
+  return Ranges;
+}
+
 namespace {
 struct NamespaceEvent {
   enum {
@@ -786,8 +798,9 @@
   std::string NSName;
 
   NamespaceEvent Event;
-  lex(Code, Style, [&](const clang::Token &Tok, Position P) {
-Event.Pos = std::move(P);
+  lex(Code, format::getFormattingLangOpts(Style),
+  [&](const clang::Token &Tok,const SourceManager &SM) {
+Event.Pos = sourceLocToPosition(SM, Tok.getL

[clang] 26bc7cb - [clang, MveEmitter] Fix sign/zero extension in range limits.

2019-11-06 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2019-11-06T09:01:42Z
New Revision: 26bc7cb05edd6bea4b9a1593baf0fbe9e45f54e4

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

LOG: [clang,MveEmitter] Fix sign/zero extension in range limits.

In the code that generates Sema range checks on constant arguments, I
had a piece of code that checks the bounds specified in the Tablegen
intrinsic description against the range of the integer type being
tested. If the bounds are large enough to permit any value of the
integer type, you can omit the compile-time range check. (This case is
expected to come up in some of the bitwise operation intrinsics.)

But somehow I got my signed/unsigned check backwards (asking for the
signed min/max of an unsigned type and vice versa), and also made a
sign extension error in which a signed negative value gets
zero-extended. Now rewritten more sensibly, and it should get its
first sensible test from the next batch of intrinsics I'm planning to
add in D69791.

Reviewers: dmgreen

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/utils/TableGen/MveEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/MveEmitter.cpp 
b/clang/utils/TableGen/MveEmitter.cpp
index 9c3328e3bbfb..1f9752261fbf 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -782,15 +782,14 @@ class ACLEIntrinsic {
   }
 
   llvm::APInt typelo, typehi;
-  if (cast(IA.ArgType)->kind() == ScalarTypeKind::UnsignedInt) 
{
-typelo = llvm::APInt::getSignedMinValue(IA.ArgType->sizeInBits());
-typehi = llvm::APInt::getSignedMaxValue(IA.ArgType->sizeInBits());
+  unsigned Bits = IA.ArgType->sizeInBits();
+  if (cast(IA.ArgType)->kind() == ScalarTypeKind::SignedInt) {
+typelo = llvm::APInt::getSignedMinValue(Bits).sext(128);
+typehi = llvm::APInt::getSignedMaxValue(Bits).sext(128);
   } else {
-typelo = llvm::APInt::getMinValue(IA.ArgType->sizeInBits());
-typehi = llvm::APInt::getMaxValue(IA.ArgType->sizeInBits());
+typelo = llvm::APInt::getMinValue(Bits).zext(128);
+typehi = llvm::APInt::getMaxValue(Bits).zext(128);
   }
-  typelo = typelo.sext(128);
-  typehi = typehi.sext(128);
 
   std::string Index = utostr(kv.first);
 



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


[clang] 38f0165 - [ARM MVE] Remove accidental 64-bit vst2/vld2 intrinsics.

2019-11-06 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2019-11-06T09:01:42Z
New Revision: 38f016520f6edbfa7d059b60ac54e80dd955ada5

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

LOG: [ARM MVE] Remove accidental 64-bit vst2/vld2 intrinsics.

ACLE defines no such intrinsic as vst2q_u64, and the MVE instruction
set has no corresponding instruction. But I had accidentally added
them to the fledgling  anyway, and if you used them, you'd
get a compiler crash.

Reviewers: dmgreen

Subscribers: kristof.beyls, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Basic/arm_mve.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index a760fdd87b1a..30a76511a3cd 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -18,7 +18,7 @@
 
 include "arm_mve_defs.td"
 
-let params = T.All in
+let params = T.Usual in
 foreach n = [ 2, 4 ] in {
   def "vst"#n#"q": Intrinsic, MultiVector),
  (CustomCodegen<"VST24"> n:$NumVectors,



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


[PATCH] D56345: [clang-format] Assert that filenames are not empty

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 228014.
MyDeveloperDay added a reviewer: mitchell-stellar.
MyDeveloperDay added a comment.

remove the asserts at least for now.

This fix is important for people using clang-format  integrated into some 
editor tools.


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

https://reviews.llvm.org/D56345

Files:
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -390,6 +390,10 @@
   if (fillRanges(Code.get(), Ranges))
 return true;
   StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
+  if (AssumedFileName.empty()) {
+llvm::errs() << "error: empty filenames are not allowed\n";
+return true;
+  }
 
   llvm::Expected FormatStyle =
   getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -390,6 +390,10 @@
   if (fillRanges(Code.get(), Ranges))
 return true;
   StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
+  if (AssumedFileName.empty()) {
+llvm::errs() << "error: empty filenames are not allowed\n";
+return true;
+  }
 
   llvm::Expected FormatStyle =
   getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69789: [clang,MveEmitter] Fix sign/zero extension in range limits.

2019-11-06 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG26bc7cb05edd: [clang,MveEmitter] Fix sign/zero extension in 
range limits. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69789

Files:
  clang/utils/TableGen/MveEmitter.cpp


Index: clang/utils/TableGen/MveEmitter.cpp
===
--- clang/utils/TableGen/MveEmitter.cpp
+++ clang/utils/TableGen/MveEmitter.cpp
@@ -782,15 +782,14 @@
   }
 
   llvm::APInt typelo, typehi;
-  if (cast(IA.ArgType)->kind() == ScalarTypeKind::UnsignedInt) 
{
-typelo = llvm::APInt::getSignedMinValue(IA.ArgType->sizeInBits());
-typehi = llvm::APInt::getSignedMaxValue(IA.ArgType->sizeInBits());
+  unsigned Bits = IA.ArgType->sizeInBits();
+  if (cast(IA.ArgType)->kind() == ScalarTypeKind::SignedInt) {
+typelo = llvm::APInt::getSignedMinValue(Bits).sext(128);
+typehi = llvm::APInt::getSignedMaxValue(Bits).sext(128);
   } else {
-typelo = llvm::APInt::getMinValue(IA.ArgType->sizeInBits());
-typehi = llvm::APInt::getMaxValue(IA.ArgType->sizeInBits());
+typelo = llvm::APInt::getMinValue(Bits).zext(128);
+typehi = llvm::APInt::getMaxValue(Bits).zext(128);
   }
-  typelo = typelo.sext(128);
-  typehi = typehi.sext(128);
 
   std::string Index = utostr(kv.first);
 


Index: clang/utils/TableGen/MveEmitter.cpp
===
--- clang/utils/TableGen/MveEmitter.cpp
+++ clang/utils/TableGen/MveEmitter.cpp
@@ -782,15 +782,14 @@
   }
 
   llvm::APInt typelo, typehi;
-  if (cast(IA.ArgType)->kind() == ScalarTypeKind::UnsignedInt) {
-typelo = llvm::APInt::getSignedMinValue(IA.ArgType->sizeInBits());
-typehi = llvm::APInt::getSignedMaxValue(IA.ArgType->sizeInBits());
+  unsigned Bits = IA.ArgType->sizeInBits();
+  if (cast(IA.ArgType)->kind() == ScalarTypeKind::SignedInt) {
+typelo = llvm::APInt::getSignedMinValue(Bits).sext(128);
+typehi = llvm::APInt::getSignedMaxValue(Bits).sext(128);
   } else {
-typelo = llvm::APInt::getMinValue(IA.ArgType->sizeInBits());
-typehi = llvm::APInt::getMaxValue(IA.ArgType->sizeInBits());
+typelo = llvm::APInt::getMinValue(Bits).zext(128);
+typehi = llvm::APInt::getMaxValue(Bits).zext(128);
   }
-  typelo = typelo.sext(128);
-  typehi = typehi.sext(128);
 
   std::string Index = utostr(kv.first);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69788: [ARM MVE] Remove accidental 64-bit vst2/vld2 intrinsics.

2019-11-06 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG38f016520f6e: [ARM MVE] Remove accidental 64-bit vst2/vld2 
intrinsics. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69788

Files:
  clang/include/clang/Basic/arm_mve.td


Index: clang/include/clang/Basic/arm_mve.td
===
--- clang/include/clang/Basic/arm_mve.td
+++ clang/include/clang/Basic/arm_mve.td
@@ -18,7 +18,7 @@
 
 include "arm_mve_defs.td"
 
-let params = T.All in
+let params = T.Usual in
 foreach n = [ 2, 4 ] in {
   def "vst"#n#"q": Intrinsic, MultiVector),
  (CustomCodegen<"VST24"> n:$NumVectors,


Index: clang/include/clang/Basic/arm_mve.td
===
--- clang/include/clang/Basic/arm_mve.td
+++ clang/include/clang/Basic/arm_mve.td
@@ -18,7 +18,7 @@
 
 include "arm_mve_defs.td"
 
-let params = T.All in
+let params = T.Usual in
 foreach n = [ 2, 4 ] in {
   def "vst"#n#"q": Intrinsic, MultiVector),
  (CustomCodegen<"VST24"> n:$NumVectors,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69790: [ARM,MVE] Integer-type nitpicks in MVE intrinsics.

2019-11-06 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf0c6890f32c0: [ARM,MVE] Integer-type nitpicks in MVE 
intrinsics. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69790

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/include/clang/Basic/arm_mve_defs.td
  clang/utils/TableGen/MveEmitter.cpp

Index: clang/utils/TableGen/MveEmitter.cpp
===
--- clang/utils/TableGen/MveEmitter.cpp
+++ clang/utils/TableGen/MveEmitter.cpp
@@ -229,6 +229,7 @@
 class ScalarType : public CRegularNamedType {
   ScalarTypeKind Kind;
   unsigned Bits;
+  std::string NameOverride;
 
 public:
   ScalarType(const Record *Record) : CRegularNamedType(TypeKind::Scalar) {
@@ -237,6 +238,7 @@
.Case("u", ScalarTypeKind::UnsignedInt)
.Case("f", ScalarTypeKind::Float);
 Bits = Record->getValueAsInt("size");
+NameOverride = Record->getValueAsString("nameOverride");
   }
   unsigned sizeInBits() const override { return Bits; }
   ScalarTypeKind kind() const { return Kind; }
@@ -244,6 +246,11 @@
   std::string cNameBase() const override {
 return toCPrefix(Kind) + utostr(Bits);
   }
+  std::string cName() const override {
+if (NameOverride.empty())
+  return CRegularNamedType::cName();
+return NameOverride;
+  }
   std::string llvmName() const override {
 if (Kind == ScalarTypeKind::Float) {
   if (Bits == 16)
@@ -261,6 +268,7 @@
   }
   bool isInteger() const { return Kind != ScalarTypeKind::Float; }
   bool requiresFloat() const override { return !isInteger(); }
+  bool hasNonstandardName() const { return !NameOverride.empty(); }
 
   static bool classof(const Type *T) {
 return T->typeKind() == TypeKind::Scalar;
@@ -1263,6 +1271,8 @@
   "typedef float float32_t;\n";
   for (const auto &kv : ScalarTypes) {
 const ScalarType *ST = kv.second.get();
+if (ST->hasNonstandardName())
+  continue;
 raw_ostream &OS = parts[ST->requiresFloat() ? Float : 0];
 const VectorType *VT = getVectorType(ST);
 
Index: clang/include/clang/Basic/arm_mve_defs.td
===
--- clang/include/clang/Basic/arm_mve_defs.td
+++ clang/include/clang/Basic/arm_mve_defs.td
@@ -125,7 +125,9 @@
 class PrimitiveType: Type {
   string kind = kind_;
   int size = size_;
+  string nameOverride = "";
 }
+
 // The type records defined by these foreaches have names like s32, f16, u8.
 foreach size = [8, 16, 32, 64] in
   foreach kind = ["u", "s"] in
@@ -134,6 +136,12 @@
   foreach kind = ["f"] in
 def kind # size: PrimitiveType;
 
+// Sometimes we need to refer to a type by a different name in C, when
+// ACLE defines a function parameter to be something like 'unsigned'
+// rather than uint32_t.
+def uint: PrimitiveType<"u", 32> { let nameOverride = "unsigned"; }
+def sint: PrimitiveType<"s", 32> { let nameOverride = "int"; }
+
 // VecOf expects t to be a scalar, and gives a 128-bit vector of whatever it
 // is.
 class VecOf: ComplexType<(CTO_Vec t)>;
@@ -222,7 +230,7 @@
 // memory access size is n bytes (e.g. 1 for vldrb_[whatever], 2 for vldrh,
 // ...). The set of valid immediates for these is {0*n, 1*n, ..., 127*n}.
 class imm_mem7bit
-  : Immediate> {
+  : Immediate> {
   let extra = !if(!eq(membytes, 1), ?, "Multiple");
   let extraarg = !cast(membytes);
 }
Index: clang/include/clang/Basic/arm_mve.td
===
--- clang/include/clang/Basic/arm_mve.td
+++ clang/include/clang/Basic/arm_mve.td
@@ -98,22 +98,22 @@
(u64 (xval $pair, 0>;
 
 let params = T.Int32 in {
-def vadcq: Intrinsic:$carry),
+def vadcq: Intrinsic:$carry),
 (seq (IRInt<"vadc", [Vector]> $a, $b, (shl (load $carry), 29)):$pair,
  (store (and 1, (lshr (xval $pair, 1), 29)), $carry),
  (xval $pair, 0))>;
-def vadciq: Intrinsic:$carry),
+def vadciq: Intrinsic:$carry),
 (seq (IRInt<"vadc", [Vector]> $a, $b, 0):$pair,
  (store (and 1, (lshr (xval $pair, 1), 29)), $carry),
  (xval $pair, 0))>;
 def vadcq_m: Intrinsic:$carry, Predicate:$pred),
+ Ptr:$carry, Predicate:$pred),
 (seq (IRInt<"vadc_predicated", [Vector, Predicate]> $inactive, $a, $b,
  (shl (load $carry), 29), $pred):$pair,
  (store (and 1, (lshr (xval $pair, 1), 29)), $carry),
  (xval $pair, 0))>;
 def vadciq_m: Intrinsic:$carry, Predicate:$pred),
+  Ptr:$carry, Predicate:$pred),
 (seq (IRInt<"vadc_predicated", [Vector, Predicate]> $inactive, $a, $b,
  0, $pred):$pair,
  (store (and 1, (lshr (xval $pair, 1), 29)), $carry),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
h

[PATCH] D56345: [clang-format] Assert that filenames are not empty

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay commandeered this revision.
MyDeveloperDay edited reviewers, added: jr; removed: MyDeveloperDay.
MyDeveloperDay added a comment.
This revision now requires review to proceed.

@jr As there is no response from you, I wonder if you are ok with me taking 
this over, I'd like to recommend we keep just the:

  if (AssumedFileName.empty()) {
  llvm::errs() << "error: empty filenames are not allowed\n";
  return true;
}

For now, as the other functions where you are adding an assert might be being 
called from other tooling areas and I don't want to cause others problems, I'd 
like to keep this change localized, (I hope it's ok but I'll rebase and update 
the patch)


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

https://reviews.llvm.org/D56345



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


[PATCH] D69615: [clangd] Implement a function to lex the file to find candidate occurrences.

2019-11-06 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: fail - 59859 tests passed, 22 failed and 763 were skipped.

  failed: 
libc++.std/thread/thread_mutex/thread_mutex_requirements/thread_mutex_requirements_mutex/thread_mutex_class/try_lock.pass.cpp
  failed: lld.ELF/linkerscript/filename-spec.s
  failed: Clang.Index/index-module-with-vfs.m
  failed: Clang.Modules/double-quotes.m
  failed: Clang.Modules/framework-public-includes-private.m
  failed: Clang.VFS/external-names.c
  failed: Clang.VFS/framework-import.m
  failed: Clang.VFS/implicit-include.c
  failed: Clang.VFS/include-mixed-real-and-virtual.c
  failed: Clang.VFS/include-real-from-virtual.c
  failed: Clang.VFS/include-virtual-from-real.c
  failed: Clang.VFS/include.c
  failed: Clang.VFS/incomplete-umbrella.m
  failed: Clang.VFS/module-import.m
  failed: Clang.VFS/module_missing_vfs.m
  failed: Clang.VFS/real-path-found-first.m
  failed: Clang.VFS/relative-path.c
  failed: Clang.VFS/test_nonmodular.c
  failed: Clang.VFS/umbrella-framework-import-skipnonexist.m
  failed: Clang.VFS/vfsroot-include.c
  failed: Clang.VFS/vfsroot-module.m
  failed: Clang.VFS/vfsroot-with-overlay.c

Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69615



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


[PATCH] D63835: [Syntax] Add nodes for most common statements

2019-11-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 228023.
ilya-biryukov marked 20 inline comments as done.
ilya-biryukov added a comment.

- Group Traverse* and Walk* together
- s/RAT/RAV
- Add a comment about nullability of the accessors
- Name function for consuming statements and expressions differently


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63835

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.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
@@ -41,8 +41,8 @@
 
   void HandleTranslationUnit(ASTContext &Ctx) override {
 Arena = std::make_unique(Ctx.getSourceManager(),
- Ctx.getLangOpts(),
- std::move(*Tokens).consume());
+Ctx.getLangOpts(),
+std::move(*Tokens).consume());
 Tokens = nullptr; // make sure we fail if this gets called twice.
 Root = syntax::buildSyntaxTree(*Arena, *Ctx.getTranslationUnitDecl());
   }
@@ -65,7 +65,7 @@
 auto Tokens =
 std::make_unique(CI.getPreprocessor());
 return std::make_unique(Root, Arena,
-  std::move(Tokens));
+ std::move(Tokens));
   }
 
 private:
@@ -136,18 +136,315 @@
 | |-(
 | |-)
 | `-CompoundStatement
-|   |-2: {
-|   `-3: }
+|   |-{
+|   `-}
 `-TopLevelDeclaration
   |-void
   |-foo
   |-(
   |-)
   `-CompoundStatement
-|-2: {
-`-3: }
+|-{
+`-}
 )txt"},
-  };
+  // if.
+  {
+  R"cpp(
+int main() {
+  if (true) {}
+  if (true) {} else if (false) {}
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-int
+  |-main
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-IfStatement
+| |-if
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-)
+| `-CompoundStatement
+|   |-{
+|   `-}
+|-IfStatement
+| |-if
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-)
+| |-CompoundStatement
+| | |-{
+| | `-}
+| |-else
+| `-IfStatement
+|   |-if
+|   |-(
+|   |-UnknownExpression
+|   | `-false
+|   |-)
+|   `-CompoundStatement
+| |-{
+| `-}
+`-}
+)txt"},
+  // for.
+  {R"cpp(
+void test() {
+  for (;;)  {}
+}
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-ForStatement
+| |-for
+| |-(
+| |-;
+| |-;
+| |-)
+| `-CompoundStatement
+|   |-{
+|   `-}
+`-}
+)txt"},
+  // declaration statement.
+  {"void test() { int a = 10; }",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-int
+| |-a
+| |-=
+| |-10
+| `-;
+`-}
+)txt"},
+  {"void test() { ; }", R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-EmptyStatement
+| `-;
+`-}
+)txt"},
+  // switch, case and default.
+  {R"cpp(
+void test() {
+  switch (true) {
+case 0:
+default:;
+  }
+}
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-SwitchStatement
+| |-switch
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-CaseStatement
+|   | |-case
+|   | |-UnknownExpression
+|   | | `-0
+|   | |-:
+|   | `-DefaultStatement
+|   |   |-default
+|   |   |-:
+|   |   `-EmptyStatement
+|   | `-;
+|   `-}
+`-}
+)txt"},
+  // while.
+  {R"cpp(
+void test() {
+  while (true) { continue; break; }
+}
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-WhileStatement
+| |-while
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-ContinueStatement
+|   | |-continue
+|   | `-;
+|   |-BreakStatement
+|   | |-break
+|   | `-;
+|   `-}
+`-}
+)txt"},
+  // return.
+  {R"cpp(
+int test() { return 1; }
+  )cpp",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-int
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-Retu

[PATCH] D63835: [Syntax] Add nodes for most common statements

2019-11-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:193
+  syntax::Statement *thenStatement();
+  syntax::Leaf *elseKeyword();
+  syntax::Statement *elseStatement();

sammccall wrote:
> ilya-biryukov wrote:
> > sammccall wrote:
> > > I think throughout it's important to mark which of these are:
> > >  - nullable in correct code
> > >  - nullable in code generated by recovery
> > I would suggest to only mark the nodes that are nullable in the correct 
> > code. For recovery, I would assume the following rule (please tell me if 
> > I'm wrong):
> > 
> > On a construct whose parsing involved recovery:
> > - if the node has an introducing token (`if`, `try`, etc.), the 
> > corresponding child cannot be null.
> > - any other child can be null.
> Agree with this strategy, and the fact that it doesn't need to be documented 
> on every node/occurrence.
> 
> But it should definitely be documented somewhere at a high level! (With clang 
> AST, this sort of thing feels like tribal knowledge)
Added a corresponding comment to the file header.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:79
+  ExpressionStatement_expression,
+  CompoundStatement_statement
 };

sammccall wrote:
> As discussed offline, there's some options about how abstract/concrete these 
> roles should be.
> 
> e.g. for a list of function args, this could be 
> FunctionOpenParen/FunctionArgExpr/FunctionArgComma/FunctionCloseParam 
> (specific) <-> OpenParen/Arg/Comma/CloseParen <-> Open/Item/Separator/Close.
> 
> The more specific ones are somewhat redundant with the parent/child type (but 
> easy to assign systematically), and the more generic ones are more orthogonal 
> (but require more design and may by hard to always make consistent).
> 
> The concrete advantage of the generic roles is being able to write code like 
> `getTrailingSemicolon(Tree*)` or `findLoopBreak(Stmt*)` or 
> `removeListItem(Tree*, int)` in a fairly generic way, without resorting to 
> adding a `Loop` base class or handling each case with separate code.
> 
> This is up to you, though.
I definitely agree that writing generic functions is simpler with the proposed 
approach.

However, I am aiming for safer APIs here, albeit less generic. E.g. we'll have 
something like 
`removeFunctionArgument(ArgumentList*, int)` and 
`removeInitializer(InitializerList*, int)`
rather than `removeListItem(Tree*, int)` in the public API.

Reasons are discoverability of the operations for particular node types.

Generic functions might still make sense as an implementation detail to share 
the code.
I'll keep as is for now, but will keep the suggestion in mind.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:265
+  syntax::Leaf *returnKeyword();
+  syntax::Expression *value();
+};

sammccall wrote:
> nullable, marked somehow
> 
> Optional is tempting as a systematic and hard-to-ignore way of 
> documenting that.
> And it reflects the fact that there are three conceptual states for children: 
> present, legally missing, brokenly missing.
> 
> At the same time, I'm not sure how to feel about the fact that in practice 
> this can't be present but null, and the fact that *other* non-optional 
> pointers can be null.
Having `Optional` models the problem space better, but is much 
harder to use on the client side.
I'd keep as is, the file comment explains that one should assume all accessors 
can return null.

Update the comment here to indicate both `return;` and `return ;` are 
represented by this node.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:99
+  /// semicolon when needed.
   llvm::ArrayRef getRange(const Stmt *S) const {
+auto Tokens = getRange(S->getBeginLoc(), S->getEndLoc());

sammccall wrote:
> since Expr : Stmt, we need to be a bit wary of overloading based on static 
> type.
> 
> It's tempting to say it's correct here: if we statically know E is an Expr, 
> then maybe it's never correct to consume the semicolon. But is the converse 
> true? e.g. if we're traversing using RAV and call getRange() in visitstmt...
> 
> (The alternatives seem to be a) removing the expr version of the function, 
> and having the stmt version take a `bool ConsumeSemi` or b) change the stmt 
> version to have (dynamic) expr behave like the expr overload, and handle it 
> specially when forming exprstmt. More verbose, genuinely conflicted here)
Using two functions with different names now.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:270
+
+  bool TraverseCXXForRangeStmt(CXXForRangeStmt *S) {
+// We override to traverse range initializer as VarDecl.

sammccall wrote:
> maybe group with corresponding `WalkUpFromCXXForRangeStmt`?
> (Could also group all `Traverse*` together if you prefer. Current ordering 
> seems a little random)
Went for grouping `Traverse*` and `Wa

[clang] 9577ee8 - NeonEmitter: switch to enum for internal Type representation.

2019-11-06 Thread Tim Northover via cfe-commits

Author: Tim Northover
Date: 2019-11-06T10:02:15Z
New Revision: 9577ee84e638530be7a310c9d50526a36e3c212e

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

LOG: NeonEmitter: switch to enum for internal Type representation.

Previously we had a handful of bools (Signed, Floating, ...) that could
easily end up in an inconsistent state. This adds an enum Kind which
holds the mutually exclusive states a type might be in, retaining some
of the bools that modified an underlying type.

https://reviews.llvm.org/D69715

Added: 


Modified: 
clang/utils/TableGen/NeonEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/NeonEmitter.cpp 
b/clang/utils/TableGen/NeonEmitter.cpp
index 9d668a281534..ecd932475cb1 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -140,7 +140,15 @@ class Type {
 private:
   TypeSpec TS;
 
-  bool Float, Signed, Immediate, Void, Poly, Constant, Pointer;
+  enum TypeKind {
+Void,
+Float,
+SInt,
+UInt,
+Poly,
+  };
+  TypeKind Kind;
+  bool Immediate, Constant, Pointer;
   // ScalarForMangling and NoManglingQ are really not suited to live here as
   // they are not related to the type. But they live in the TypeSpec (not the
   // prototype), so this is really the only place to store them.
@@ -149,15 +157,14 @@ class Type {
 
 public:
   Type()
-  : Float(false), Signed(false), Immediate(false), Void(true), Poly(false),
-Constant(false), Pointer(false), ScalarForMangling(false),
-NoManglingQ(false), Bitwidth(0), ElementBitwidth(0), NumVectors(0) {}
+  : Kind(Void), Immediate(false), Constant(false),
+Pointer(false), ScalarForMangling(false), NoManglingQ(false),
+Bitwidth(0), ElementBitwidth(0), NumVectors(0) {}
 
   Type(TypeSpec TS, char CharMod)
-  : TS(std::move(TS)), Float(false), Signed(false), Immediate(false),
-Void(false), Poly(false), Constant(false), Pointer(false),
-ScalarForMangling(false), NoManglingQ(false), Bitwidth(0),
-ElementBitwidth(0), NumVectors(0) {
+  : TS(std::move(TS)), Kind(Void), Immediate(false),
+Constant(false), Pointer(false), ScalarForMangling(false),
+NoManglingQ(false), Bitwidth(0), ElementBitwidth(0), NumVectors(0) {
 applyModifier(CharMod);
   }
 
@@ -174,21 +181,21 @@ class Type {
   bool noManglingQ() const { return NoManglingQ; }
 
   bool isPointer() const { return Pointer; }
-  bool isFloating() const { return Float; }
-  bool isInteger() const { return !Float && !Poly; }
-  bool isSigned() const { return Signed; }
+  bool isFloating() const { return Kind == Float; }
+  bool isInteger() const { return Kind == SInt || Kind == UInt; }
+  bool isPoly() const { return Kind == Poly; }
+  bool isSigned() const { return Kind == SInt; }
   bool isImmediate() const { return Immediate; }
   bool isScalar() const { return NumVectors == 0; }
   bool isVector() const { return NumVectors > 0; }
-  bool isFloat() const { return Float && ElementBitwidth == 32; }
-  bool isDouble() const { return Float && ElementBitwidth == 64; }
-  bool isHalf() const { return Float && ElementBitwidth == 16; }
-  bool isPoly() const { return Poly; }
+  bool isFloat() const { return isFloating() && ElementBitwidth == 32; }
+  bool isDouble() const { return isFloating() && ElementBitwidth == 64; }
+  bool isHalf() const { return isFloating() && ElementBitwidth == 16; }
   bool isChar() const { return ElementBitwidth == 8; }
-  bool isShort() const { return !Float && ElementBitwidth == 16; }
-  bool isInt() const { return !Float && ElementBitwidth == 32; }
-  bool isLong() const { return !Float && ElementBitwidth == 64; }
-  bool isVoid() const { return Void; }
+  bool isShort() const { return isInteger() && ElementBitwidth == 16; }
+  bool isInt() const { return isInteger() && ElementBitwidth == 32; }
+  bool isLong() const { return isInteger() && ElementBitwidth == 64; }
+  bool isVoid() const { return Kind == Void; }
   unsigned getNumElements() const { return Bitwidth / ElementBitwidth; }
   unsigned getSizeInBits() const { return Bitwidth; }
   unsigned getElementSizeInBits() const { return ElementBitwidth; }
@@ -197,21 +204,24 @@ class Type {
   //
   // Mutator functions
   //
-  void makeUnsigned() { Signed = false; }
-  void makeSigned() { Signed = true; }
+  void makeUnsigned() {
+assert(isInteger() && "not a potentially signed type");
+Kind = UInt;
+  }
+  void makeSigned() {
+assert(isInteger() && "not a potentially signed type");
+Kind = SInt;
+  }
 
   void makeInteger(unsigned ElemWidth, bool Sign) {
-Float = false;
-Poly = false;
-Signed = Sign;
+assert(!isVoid() && "converting void to int probably not useful");
+Kind = Sign ? SInt : UInt;
 Immed

[PATCH] D69715: NeonEmitter: change Type representation. NFC.

2019-11-06 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover closed this revision.
t.p.northover added a comment.

> I guess the extra checks are due to existing code "accidentally" doing the 
> right thing?

Yep, they were helpful while I was in the process of converting (in the end I 
went via `AAAFloating` enumerators to make sure all uses were flushed out). And 
yes, diff showed no change in clang-tblgen output.

Anyway, thanks, committed as 9577ee84e6 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69715



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


[PATCH] D63835: [Syntax] Add nodes for most common statements

2019-11-06 Thread Ilya Biryukov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58fa50f43701: [Syntax] Add nodes for most common statements 
(authored by ilya-biryukov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63835

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.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
@@ -41,8 +41,8 @@
 
   void HandleTranslationUnit(ASTContext &Ctx) override {
 Arena = std::make_unique(Ctx.getSourceManager(),
- Ctx.getLangOpts(),
- std::move(*Tokens).consume());
+Ctx.getLangOpts(),
+std::move(*Tokens).consume());
 Tokens = nullptr; // make sure we fail if this gets called twice.
 Root = syntax::buildSyntaxTree(*Arena, *Ctx.getTranslationUnitDecl());
   }
@@ -65,7 +65,7 @@
 auto Tokens =
 std::make_unique(CI.getPreprocessor());
 return std::make_unique(Root, Arena,
-  std::move(Tokens));
+ std::move(Tokens));
   }
 
 private:
@@ -136,18 +136,315 @@
 | |-(
 | |-)
 | `-CompoundStatement
-|   |-2: {
-|   `-3: }
+|   |-{
+|   `-}
 `-TopLevelDeclaration
   |-void
   |-foo
   |-(
   |-)
   `-CompoundStatement
-|-2: {
-`-3: }
+|-{
+`-}
 )txt"},
-  };
+  // if.
+  {
+  R"cpp(
+int main() {
+  if (true) {}
+  if (true) {} else if (false) {}
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-int
+  |-main
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-IfStatement
+| |-if
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-)
+| `-CompoundStatement
+|   |-{
+|   `-}
+|-IfStatement
+| |-if
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-)
+| |-CompoundStatement
+| | |-{
+| | `-}
+| |-else
+| `-IfStatement
+|   |-if
+|   |-(
+|   |-UnknownExpression
+|   | `-false
+|   |-)
+|   `-CompoundStatement
+| |-{
+| `-}
+`-}
+)txt"},
+  // for.
+  {R"cpp(
+void test() {
+  for (;;)  {}
+}
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-ForStatement
+| |-for
+| |-(
+| |-;
+| |-;
+| |-)
+| `-CompoundStatement
+|   |-{
+|   `-}
+`-}
+)txt"},
+  // declaration statement.
+  {"void test() { int a = 10; }",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-int
+| |-a
+| |-=
+| |-10
+| `-;
+`-}
+)txt"},
+  {"void test() { ; }", R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-EmptyStatement
+| `-;
+`-}
+)txt"},
+  // switch, case and default.
+  {R"cpp(
+void test() {
+  switch (true) {
+case 0:
+default:;
+  }
+}
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-SwitchStatement
+| |-switch
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-CaseStatement
+|   | |-case
+|   | |-UnknownExpression
+|   | | `-0
+|   | |-:
+|   | `-DefaultStatement
+|   |   |-default
+|   |   |-:
+|   |   `-EmptyStatement
+|   | `-;
+|   `-}
+`-}
+)txt"},
+  // while.
+  {R"cpp(
+void test() {
+  while (true) { continue; break; }
+}
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-void
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-WhileStatement
+| |-while
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-ContinueStatement
+|   | |-continue
+|   | `-;
+|   |-BreakStatement
+|   | |-break
+|   | `-;
+|   `-}
+`-}
+)txt"},
+  // return.
+  {R"cpp(
+int test() { return 1; }
+  )cpp",
+   R"txt(
+*: TranslationUnit
+`-TopLevelDeclaration
+  |-int
+  |-test
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-ReturnStatement
+| |-return
+| |-UnknownExpression
+| | `-1
+| `-;
+`-}
+)txt"},
+  // Range-based f

[PATCH] D69883: [OpenCL] Add math and common builtin functions

2019-11-06 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: Anastasia, Pierre, Nicola.
Herald added subscribers: cfe-commits, kristina, yaxunl.
Herald added a reviewer: rengolin.
Herald added a project: clang.

Add the math and common builtin functions from the OpenCL C
specification.

Patch by Pierre Gondois and Sven van Haastregt.


Repository:
  rC Clang

https://reviews.llvm.org/D69883

Files:
  clang/lib/Sema/OpenCLBuiltins.td

Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -350,7 +350,160 @@
   }
 }
 
+
+//
+// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
+// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
+// --- Table 8 ---
+// --- 1 argument ---
+foreach name = ["acos", "acosh", "acospi",
+"asin", "asinh", "asinpi",
+"atan", "atanh", "atanpi",
+"cbrt", "ceil",
+"cos", "cosh", "cospi",
+"erfc", "erf",
+"exp", "exp2", "exp10", "expm1",
+"fabs", "floor",
+"log", "log2", "log10", "log1p", "logb",
+"rint", "round", "rsqrt",
+"sin", "sinh", "sinpi",
+"sqrt",
+"tan", "tanh", "tanpi",
+"tgamma", "trunc",
+"lgamma"] in {
+def : Builtin;
+}
+foreach name = ["nan"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+
+// --- 2 arguments ---
+foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
+"maxmag", "minmag", "nextafter", "pow", "powr",
+"remainder"] in {
+  def : Builtin;
+}
+foreach name = ["fmax", "fmin"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["ilogb"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["ldexp"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["pown", "rootn"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+
+// --- 3 arguments ---
+foreach name = ["fma", "mad"] in {
+  def : Builtin;
+}
+
+// --- Version dependent ---
+let MaxVersion = CL20 in {
+  foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
+foreach name = ["fract", "modf", "sincos"] in {
+  def : Builtin]>;
+}
+foreach name = ["frexp", "lgamma_r"] in {
+  foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
+def : Builtin]>;
+  }
+}
+foreach name = ["remquo"] in {
+  foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
+def : Builtin]>;
+  }
+}
+  }
+}
+let MinVersion = CL20 in {
+  foreach name = ["fract", "modf", "sincos"] in {
+def : Builtin]>;
+  }
+  foreach name = ["frexp", "lgamma_r"] in {
+foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
+  def : Builtin]>;
+}  }
+  foreach name = ["remquo"] in {
+foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
+  def : Builtin]>;
+}
+  }
+}
+
+// --- Table 9 ---
+foreach name = ["half_cos",
+"half_exp", "half_exp2", "half_exp10",
+"half_log", "half_log2", "half_log10",
+"half_recip", "half_rsqrt",
+"half_sin", "half_sqrt", "half_tan",
+"native_cos",
+"native_exp", "native_exp2", "native_exp10",
+"native_log", "native_log2", "native_log10",
+"native_recip", "native_rsqrt",
+"native_sin", "native_sqrt", "native_tan"] in {
+  def : Builtin;
+}
+foreach name = ["half_divide", "half_powr",
+"native_divide", "native_powr"] in {
+  def : Builtin;
+}
+
 //
+// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
+// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
+// --- Table 12 ---
+// --- 1 argument ---
+foreach name = ["degrees", "radians", "sign"] in {
+  def : Builtin;
+}
+
+// --- 2 arguments ---
+foreach name = ["max", "min"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["step"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+
+// --- 3 arguments ---
+foreach name = ["clamp", "mix"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["smoothstep"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+
+
 // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
 // OpenCL Extension v1.

[PATCH] D63835: [Syntax] Add nodes for most common statements

2019-11-06 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: fail - 59843 tests passed, 21 failed and 768 were skipped.

  failed: lld.ELF/linkerscript/filename-spec.s
  failed: Clang.Index/index-module-with-vfs.m
  failed: Clang.Modules/double-quotes.m
  failed: Clang.Modules/framework-public-includes-private.m
  failed: Clang.VFS/external-names.c
  failed: Clang.VFS/framework-import.m
  failed: Clang.VFS/implicit-include.c
  failed: Clang.VFS/include-mixed-real-and-virtual.c
  failed: Clang.VFS/include-real-from-virtual.c
  failed: Clang.VFS/include-virtual-from-real.c
  failed: Clang.VFS/include.c
  failed: Clang.VFS/incomplete-umbrella.m
  failed: Clang.VFS/module-import.m
  failed: Clang.VFS/module_missing_vfs.m
  failed: Clang.VFS/real-path-found-first.m
  failed: Clang.VFS/relative-path.c
  failed: Clang.VFS/test_nonmodular.c
  failed: Clang.VFS/umbrella-framework-import-skipnonexist.m
  failed: Clang.VFS/vfsroot-include.c
  failed: Clang.VFS/vfsroot-module.m
  failed: Clang.VFS/vfsroot-with-overlay.c

Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63835



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


[clang] 59f063b - NeonEmitter: remove special 'a' type modifier.

2019-11-06 Thread Tim Northover via cfe-commits

Author: Tim Northover
Date: 2019-11-06T10:23:36Z
New Revision: 59f063b89c518ae81467f6015d1c428c61583f71

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

LOG: NeonEmitter: remove special 'a' type modifier.

'a' used to implement a splat in C++ code in NeonEmitter.cpp, but this
can be done directly from .td expansions now (and most ops already did).
So removing it simplifies the overall code.

https://reviews.llvm.org/D69716

Added: 


Modified: 
clang/include/clang/Basic/arm_neon.td
clang/include/clang/Basic/arm_neon_incl.td
clang/test/CodeGen/aarch64-neon-2velem.c
clang/test/CodeGen/arm_neon_intrinsics.c
clang/utils/TableGen/NeonEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index a52ed496580d..127c5af97ce6 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -53,6 +53,7 @@ def OP_MLAL_N   : Op<(op "+", $p0, (call "vmull", $p1, (dup 
$p2)))>;
 def OP_MLSL_N   : Op<(op "-", $p0, (call "vmull", $p1, (dup $p2)))>;
 def OP_MUL_LN   : Op<(op "*", $p0, (splat $p1, $p2))>;
 def OP_MULX_LN  : Op<(call "vmulx", $p0, (splat $p1, $p2))>;
+def OP_MULL_N  : Op<(call "vmull", $p0, (dup $p1))>;
 def OP_MULL_LN  : Op<(call "vmull", $p0, (splat $p1, $p2))>;
 def OP_MULLHi_LN: Op<(call "vmull", (call "vget_high", $p0), (splat $p1, 
$p2))>;
 def OP_MLA_LN   : Op<(op "+", $p0, (op "*", $p1, (splat $p2, $p3)))>;
@@ -63,17 +64,22 @@ def OP_MLALHi_LN: Op<(op "+", $p0, (call "vmull", (call 
"vget_high", $p1),
 def OP_MLSL_LN  : Op<(op "-", $p0, (call "vmull", $p1, (splat $p2, $p3)))>;
 def OP_MLSLHi_LN : Op<(op "-", $p0, (call "vmull", (call "vget_high", $p1),
(splat $p2, $p3)))>;
+def OP_QDMULL_N : Op<(call "vqdmull", $p0, (dup $p1))>;
 def OP_QDMULL_LN : Op<(call "vqdmull", $p0, (splat $p1, $p2))>;
 def OP_QDMULLHi_LN : Op<(call "vqdmull", (call "vget_high", $p0),
  (splat $p1, $p2))>;
+def OP_QDMLAL_N : Op<(call "vqdmlal", $p0, $p1, (dup $p2))>;
 def OP_QDMLAL_LN : Op<(call "vqdmlal", $p0, $p1, (splat $p2, $p3))>;
 def OP_QDMLALHi_LN : Op<(call "vqdmlal", $p0, (call "vget_high", $p1),
   (splat $p2, $p3))>;
+def OP_QDMLSL_N : Op<(call "vqdmlsl", $p0, $p1, (dup $p2))>;
 def OP_QDMLSL_LN : Op<(call "vqdmlsl", $p0, $p1, (splat $p2, $p3))>;
 def OP_QDMLSLHi_LN : Op<(call "vqdmlsl", $p0, (call "vget_high", $p1),
   (splat $p2, $p3))>;
+def OP_QDMULH_N : Op<(call "vqdmulh", $p0, (dup $p1))>;
 def OP_QDMULH_LN : Op<(call "vqdmulh", $p0, (splat $p1, $p2))>;
 def OP_QRDMULH_LN : Op<(call "vqrdmulh", $p0, (splat $p1, $p2))>;
+def OP_QRDMULH_N : Op<(call "vqrdmulh", $p0, (dup $p1))>;
 def OP_QRDMLAH : Op<(call "vqadd", $p0, (call "vqrdmulh", $p1, $p2))>;
 def OP_QRDMLSH : Op<(call "vqsub", $p0, (call "vqrdmulh", $p1, $p2))>;
 def OP_QRDMLAH_LN : Op<(call "vqadd", $p0, (call "vqrdmulh", $p1, (splat $p2, 
$p3)))>;
@@ -516,13 +522,13 @@ def VQDMLSL_LANE  : SOpInst<"vqdmlsl_lane", "wwddi", 
"si", OP_QDMLSL_LN>;
 def VMUL_N: IOpInst<"vmul_n", "dds", "sifUsUiQsQiQfQUsQUi", OP_MUL_N>;
 def VMUL_LANE : IOpInst<"vmul_lane", "ddgi",
 "sifUsUiQsQiQfQUsQUi", OP_MUL_LN>;
-def VMULL_N   : SInst<"vmull_n", "wda", "siUsUi">;
+def VMULL_N   : SOpInst<"vmull_n", "wds", "siUsUi", OP_MULL_N>;
 def VMULL_LANE: SOpInst<"vmull_lane", "wddi", "siUsUi", OP_MULL_LN>;
-def VQDMULL_N : SInst<"vqdmull_n", "wda", "si">;
+def VQDMULL_N : SOpInst<"vqdmull_n", "wds", "si", OP_QDMULL_N>;
 def VQDMULL_LANE  : SOpInst<"vqdmull_lane", "wddi", "si", OP_QDMULL_LN>;
-def VQDMULH_N : SInst<"vqdmulh_n", "dda", "siQsQi">;
+def VQDMULH_N : SOpInst<"vqdmulh_n", "dds", "siQsQi", OP_QDMULH_N>;
 def VQDMULH_LANE  : SOpInst<"vqdmulh_lane", "ddgi", "siQsQi", OP_QDMULH_LN>;
-def VQRDMULH_N: SInst<"vqrdmulh_n", "dda", "siQsQi">;
+def VQRDMULH_N: SOpInst<"vqrdmulh_n", "dds", "siQsQi", OP_QRDMULH_N>;
 def VQRDMULH_LANE : SOpInst<"vqrdmulh_lane", "ddgi", "siQsQi", OP_QRDMULH_LN>;
 
 let ArchGuard = "defined(__ARM_FEATURE_QRDMX)" in {
@@ -530,12 +536,12 @@ def VQRDMLAH_LANE : SOpInst<"vqrdmlah_lane", "dddgi", 
"siQsQi", OP_QRDMLAH_LN>;
 def VQRDMLSH_LANE : SOpInst<"vqrdmlsh_lane", "dddgi", "siQsQi", OP_QRDMLSH_LN>;
 }
 
-def VMLA_N: IOpInst<"vmla_n", "ddda", "siUsUifQsQiQUsQUiQf", OP_MLA_N>;
-def VMLAL_N   : SOpInst<"vmlal_n", "wwda", "siUsUi", OP_MLAL_N>;
-def VQDMLAL_N : SInst<"vqdmlal_n", "wwda", "si">;
+def VMLA_N: IOpInst<"vmla_n", "ddds", "siUsUifQsQiQUsQUiQf", OP_MLA_N>;
+def VMLAL_N   : SOpInst<"vmlal_n", "wwds", "siUsUi", OP_MLAL_N>;
+def VQDML

[PATCH] D69716: NeonEmitter: remove special 'a' modifier.

2019-11-06 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover closed this revision.
t.p.northover added a comment.

Thanks:

To github.com:llvm/llvm-project.git

  6c2a4f5ff93..59f063b89c5  master -> master


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69716



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


[PATCH] D69263: [clangd] Implement cross-file rename.

2019-11-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 228028.
hokein marked 5 inline comments as done.
hokein added a comment.

- use blacklist
- change to enum scope


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69263

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/refactor/Rename.h
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.h

Index: clang-tools-extra/clangd/unittests/SyncAPI.h
===
--- clang-tools-extra/clangd/unittests/SyncAPI.h
+++ clang-tools-extra/clangd/unittests/SyncAPI.h
@@ -38,8 +38,8 @@
 llvm::Expected>
 runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos);
 
-llvm::Expected>
-runRename(ClangdServer &Server, PathRef File, Position Pos, StringRef NewName);
+llvm::Expected runRename(ClangdServer &Server, PathRef File,
+Position Pos, StringRef NewName);
 
 std::string runDumpAST(ClangdServer &Server, PathRef File);
 
Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -96,11 +96,11 @@
   return std::move(*Result);
 }
 
-llvm::Expected> runRename(ClangdServer &Server,
-PathRef File, Position Pos,
-llvm::StringRef NewName) {
-  llvm::Optional>> Result;
-  Server.rename(File, Pos, NewName, /*WantFormat=*/true, capture(Result));
+llvm::Expected runRename(ClangdServer &Server, PathRef File,
+Position Pos, llvm::StringRef NewName) {
+  llvm::Optional> Result;
+  Server.rename(File, Pos, NewName, /*WantFormat=*/true,
+/*DirtyBuffer=*/nullptr, capture(Result));
   return std::move(*Result);
 }
 
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -9,8 +9,10 @@
 #include "Annotations.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "index/Ref.h"
 #include "refactor/Rename.h"
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -18,9 +20,54 @@
 namespace clangd {
 namespace {
 
+using testing::Eq;
+using testing::Matches;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
 MATCHER_P2(RenameRange, Code, Range, "") {
   return replacementToEdit(Code, arg).range == Range;
 }
+MATCHER_P2(EqualFileEdit, Code, Ranges, "") {
+  using ReplacementMatcher = testing::Matcher;
+  std::vector Expected;
+  for (const auto &R : Ranges)
+Expected.push_back(RenameRange(Code, R));
+  auto Matcher =
+  testing::internal::UnorderedElementsAreArrayMatcher(
+  Expected.begin(), Expected.end());
+  return arg.InitialCode == Code && Matches(Matcher)(arg.Replacements);
+}
+
+std::unique_ptr buildRefSlab(const Annotations &Code,
+  llvm::StringRef SymbolName,
+  llvm::StringRef Path) {
+  RefSlab::Builder Builder;
+  TestTU TU;
+  TU.HeaderCode = Code.code();
+  auto Symbols = TU.headerSymbols();
+  const auto &SymbolID = findSymbol(Symbols, SymbolName).ID;
+  for (const auto &Range : Code.ranges()) {
+Ref R;
+R.Kind = RefKind::Reference;
+R.Location.Start.setLine(Range.start.line);
+R.Location.Start.setColumn(Range.start.character);
+R.Location.End.setLine(Range.end.line);
+R.Location.End.setColumn(Range.end.character);
+auto U = URI::create(Path).toString();
+R.Location.FileURI = U.c_str();
+Builder.insert(SymbolID, R);
+  }
+
+  return std::make_unique(std::move(Builder).build());
+}
+
+std::vector> toVector(FileEdits FE) {
+  std::vector> Results;
+  for (auto &It : FE)
+Results.emplace_back(It.first().str(), std::move(It.getValue()));
+  return Results;
+}
 
 TEST(RenameTest, SingleFile) {
   struct Test {
@@ -80,10 +127,12 @@
 auto TU = TestTU::withCode(Code.code());
 auto AST = TU.build();
 auto RenameResult =
-renameWithinFile(AST, testPath(TU.Filename), Code.point(), "abcde");
+rename({Code.point(), "abcde", AST, testPath(TU.Filename)});
 ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
-auto ApplyResult =
-tooling::applyAllReplacements(Code.code(), *Rename

[PATCH] D69263: [clangd] Implement cross-file rename.

2019-11-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:107
+if (!Index)
+  return NoIndexProvided;
+

ilya-biryukov wrote:
> hokein wrote:
> > ilya-biryukov wrote:
> > > Why isn't this a scope enum in the first place?
> > this is tricky, the reason why I put it here and another copy below is to 
> > avoid regression of local rename (keep existing tests passed), if we move 
> > it in the first place, the error message of local rename may be changed, 
> > e.g. when renaming an external symbol (we know that from AST) without Index 
> > support, we'd like to return "used outside of the main file" rather than 
> > "no index provided".
> > 
> > thinking more about this, the no-index case is making our code complicated 
> > (within-file rename with no-index, cross-file rename with no-index), I 
> > believe the no-index case is not important, and is rare in practice, we 
> > could change this behavior, or assume the index is always provided, this 
> > would help to simplify the code, WDYT?
> Agree, we shouldn't bother about the no-index case too much.
> My comment here was referring to the lack of `ReasonToReject::` qualifier of 
> the name.
> 
> Maybe make `ReasonToReject` a scoped enum, i.e. `enum class ReasonToReject` 
> rather than `enum ReasonToReject`?
ah, I see. Done.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:128
+
+  // A whitelist of renamable symbols.
+  if (llvm::isa(RenameDecl))

ilya-biryukov wrote:
> hokein wrote:
> > ilya-biryukov wrote:
> > > Why not a blacklist? I'd expect us to blacklist:
> > > - things with custom names (operators, constructors, etc)
> > > - virtual methods
> > > 
> > > Probably some things are missing from the list, but fundamentally most 
> > > that have names are pretty similar, right?
> > I believe our plan is to support major kinds of symbols (class, functions, 
> > enums, typedef, alias) , I feel scary to allow renaming nearly all 
> > `NamedDecl` (in theory, it should work but we're uncertain, for our 
> > experience of local rename, it sometimes leads to very surprising results). 
> > Having a whitelist can lead us to a better state, these symbols are 
> > **officially supported**.
> I disagree here, I don't see how `NamedDecl` is special if its name is an 
> identifier unless we something smart about it.
> My recollection is that local rename issues come from the fact that there are 
> certain kinds of references, which are not handled in the corresponding 
> visitor.
> 
> In any case, I'd suggest blacklisting symbols we know are broken, e.g. IIRC 
> we don't index references to namespaces, so they're definitely broken. And 
> finding the issues with the rest of the symbols and fixing those.
> In practice, this should improve both rename and cross-references - whenever 
> we have broken cross-file rename, there's a good chance that the indexer is 
> also broken.
Re-thinking this, you are right. Also, the indexable symbol kinds have a large 
overlap with the renamable symbol kinds.  Changed to blacklist.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:132
+  if (const auto *S = llvm::dyn_cast(&RenameDecl)) {
+// FIXME: renaming virtual methods requires to rename all overridens in
+// subclasses, which our index doesn't support yet.

ilya-biryukov wrote:
> hokein wrote:
> > ilya-biryukov wrote:
> > > Isn't the same true for local rename?
> > no, actually the local rename does handle this, it finds all overriden 
> > methods from the AST, and updates all of them when doing rename.
> Do we properly check overriden methods are not used outside the main file, 
> though?
> We might be assuming rename is "local" because there are not usages of the 
> original function, but there may still be usages of the overriden function.
> 
> Worth adding a comment that local rename handles that through the AST.
> Also useful to keep in mind that this is a regression, compared to the local 
> rename (i.e. if we switch to cross-file rename by default, we'll break this 
> use-case)
> Do we properly check overriden methods are not used outside the main file, 
> though?
> We might be assuming rename is "local" because there are not usages of the 
> original function, but there may still be usages of the overriden function.

No, we only check the original function, and we may encounter false positives, 
but we don't see any reports about this.

> Worth adding a comment that local rename handles that through the AST.
> Also useful to keep in mind that this is a regression, compared to the local 
> rename (i.e. if we switch to cross-file rename by default, we'll break this 
> use-case)

exactly,  a way to avoid this regression when turning on cross-file rename by 
default is to first detect whether it is safe&sufficient to perform local 
rename, if yes, we just perform the local-rename.



Comment at: clang-

[PATCH] D69263: [clangd] Implement cross-file rename.

2019-11-06 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: fail - 59861 tests passed, 21 failed and 763 were skipped.

  failed: lld.ELF/linkerscript/filename-spec.s
  failed: Clang.Index/index-module-with-vfs.m
  failed: Clang.Modules/double-quotes.m
  failed: Clang.Modules/framework-public-includes-private.m
  failed: Clang.VFS/external-names.c
  failed: Clang.VFS/framework-import.m
  failed: Clang.VFS/implicit-include.c
  failed: Clang.VFS/include-mixed-real-and-virtual.c
  failed: Clang.VFS/include-real-from-virtual.c
  failed: Clang.VFS/include-virtual-from-real.c
  failed: Clang.VFS/include.c
  failed: Clang.VFS/incomplete-umbrella.m
  failed: Clang.VFS/module-import.m
  failed: Clang.VFS/module_missing_vfs.m
  failed: Clang.VFS/real-path-found-first.m
  failed: Clang.VFS/relative-path.c
  failed: Clang.VFS/test_nonmodular.c
  failed: Clang.VFS/umbrella-framework-import-skipnonexist.m
  failed: Clang.VFS/vfsroot-include.c
  failed: Clang.VFS/vfsroot-module.m
  failed: Clang.VFS/vfsroot-with-overlay.c

Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69263



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


[PATCH] D69564: Include the mangled name in -ast-dump=json

2019-11-06 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

Ping. Does this seem an acceptable change to the JSON output @aaron.ballman ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69564



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


[PATCH] D69664: [Diagnostics] Teach -Wnull-dereference about address_space attribute

2019-11-06 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69664



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


[PATCH] D69760: [Clang][Driver] Don't pun -fuse-ld=lld as -fuse-ld=lld-link with msvc

2019-11-06 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D69760#1734534 , @thakis wrote:

> In D69760#1734524 , @thakis wrote:
>
> > We currently do cross builds of chrome/win on linux, and this breaks that.
> >
> > As far as I know, no linker other than lld-link is able to write PDB files, 
> > so when targeting windows-msvc we definitely shouldn't change the current 
> > behavior. I don't have an opinion on windows-mingw.
>
>
> Actually, we don't call the linker through the compiler driver when targeting 
> Windows, so this doesn't break our cross build. I manually use `clang-cl 
> -fuse-ld=lld` often though, so it'd make me type a lot more :)


IIUC, with Martin and Reid's suggestion to key this off the driver mode rather 
than the triple, "clang-cl -fuse-ld=lld" would still work though? I like that 
approach as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69760



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


[PATCH] D69263: [clangd] Implement cross-file rename.

2019-11-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks, this is in a good shape!
The only concern I have is the racy way to get dirty buffers, please see the 
corresponding comment.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:764
+  /*WantFormat=*/true,
+  [this](PathRef File) { return DraftMgr.getDraft(File); },
+  [File, Params, Reply = std::move(Reply),

We should probably get a snapshot of all dirty buffers here instead.
A racy  way (rename is run on a separate thread, new files updates might come 
in in the meantime) to get contents of the file looks like a bad idea, this 
will lead to hard-to-debug failures...

Note that `ClangdServer` also has access to all contents of all the files, they 
are stored in `TUScheduler`, so we don't need to pass `GetDirtyBuffer` callback 
up until the final run of `rename`



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:317
+if (!Range)
+  // Return null if the "rename" is not valid at the position.
+  return CB(llvm::None);

NIT: comment could be shortened to 
```
/// "rename" is not valid at the position.
```
Or even removed.
Both would allow saving a line (if we put the comment on the same line as 
`return`



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:320
+if (CrossFileRename)
+  return CB(*Range); // FIXME: assueme cross-file rename always succeeds.
+

NIT: s/assueme/assume

also, in FIXME we normally give the final state, so it should probably be 
```
/// FIXME: do not assume cross-file rename always succeeds
```





Comment at: clang-tools-extra/clangd/ClangdServer.cpp:340
 void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  bool WantFormat, Callback> CB) 
{
+  bool WantFormat, DirtyBufferGetter GetDirtyBuffer,
+  Callback CB) {

`ClangdServer` can obtain the dirty buffers via `TUScheduler::getContents`



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69263



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


[PATCH] D56345: [clang-format] Assert that filenames are not empty

2019-11-06 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar accepted this revision.
mitchell-stellar added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D56345



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


[PATCH] D69854: [clang-format] [RELAND] Remove the dependency on frontend

2019-11-06 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Thanks! One comment (the stale pointer one) and a more general suggestion 
(potentially for a future change) below, else I think this is good to go.




Comment at: clang/tools/clang-format/ClangFormat.cpp:310
   SourceManager Sources(*Diags, Files);
   FileID FileID = createInMemoryFile(AssumedFileName, Code.get(), Sources,
  Files, InMemoryFileSystem.get());

Maybe not for this change, but do you need all this machinery up here? 
SMDiagnostics takes a pointer and a file name, so yu can just pass 
Code->getBufferStart() + R.getOffset() for the pointer and you don't need the 
FileManager, the SourceManager, createInMemoryFile(), the PresumedLoc, 
translateFileLineCol.

You can either try to use SourceMgr::getLineAndColumn() or compute line/col 
yourself -- either should be a lot less code than the current machinery here.



Comment at: clang/tools/clang-format/ClangFormat.cpp:334
+  SMDiagnostic Diags(
+  llvm::SourceMgr(), SMLoc::getFromPointer(StartBuf), AssumedFileName,
+  PLoc.getLine(), PLoc.getColumn(),

I think the idea is that you have a llvm::SourceMgr() hanging around (above the 
loop or somewhere). SMDiagnostic stores a pointer to this argument, and you 
pass in a temporary. The SourceMgr needs to outlive the Diags object. (In 
practice, the pointer is not used by anything so it happens to work, but having 
the object store a stale pointer seems like potential future trouble, and it's 
easy to prevent -- just put the SourceMgr on the stack).

Also, probably "Diag", not "Diags"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69854



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


[PATCH] D69322: [hip][cuda] Enable extended lambda support on Windows.

2019-11-06 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

PING for review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69322



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


[PATCH] D69890: [clangd] Improve the output of rename tests where there are failures.

2019-11-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Previously, we match ranges, which is hard to spot the difference.
Now, we diff the code after rename against the expected result, it
produces much nicer output.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69890

Files:
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -22,71 +22,62 @@
   return replacementToEdit(Code, arg).range == Range;
 }
 
+// Generates an expected rename result by replacing all ranges in the given
+// annotation with the NewName.
+std::string expectedResult(Annotations Test, llvm::StringRef NewName) {
+  std::string Result;
+  unsigned NextChar = 0;
+  llvm::StringRef Code = Test.code();
+  for (const auto &R : Test.ranges()) {
+unsigned StartOffset = llvm::cantFail(positionToOffset(Code, R.start));
+unsigned EndOffset = llvm::cantFail(positionToOffset(Code, R.end));
+assert(StartOffset <= EndOffset && NextChar <= StartOffset);
+Result += Code.substr(NextChar, StartOffset - NextChar);
+Result += NewName;
+NextChar = EndOffset;
+  }
+  Result += Code.substr(NextChar);
+  return Result;
+}
+
 TEST(RenameTest, SingleFile) {
-  struct Test {
-const char* Before;
-const char* After;
-  } Tests[] = {
+  const char *Tests[] = {
   // Rename function.
-  {
-  R"cpp(
-void foo() {
-  fo^o();
-}
-  )cpp",
-  R"cpp(
-void abcde() {
-  abcde();
-}
-  )cpp",
-  },
+  R"cpp(
+void [[foo]]() {
+  [[fo^o]]();
+}
+  )cpp",
+
   // Rename type.
-  {
-  R"cpp(
-struct foo{};
-foo test() {
-   f^oo x;
-   return x;
-}
-  )cpp",
-  R"cpp(
-struct abcde{};
-abcde test() {
-   abcde x;
-   return x;
-}
-  )cpp",
-  },
+  R"cpp(
+struct [[foo]]{};
+[[foo]] test() {
+   [[f^oo]] x;
+   return x;
+}
+  )cpp",
+
   // Rename variable.
-  {
-  R"cpp(
-void bar() {
-  if (auto ^foo = 5) {
-foo = 3;
-  }
-}
-  )cpp",
-  R"cpp(
-void bar() {
-  if (auto abcde = 5) {
-abcde = 3;
-  }
-}
-  )cpp",
-  },
+  R"cpp(
+void bar() {
+  if (auto [[^foo]] = 5) {
+[[foo]] = 3;
+  }
+}
+  )cpp",
   };
-  for (const Test &T : Tests) {
-Annotations Code(T.Before);
+  for (const auto *T : Tests) {
+Annotations Code(T);
 auto TU = TestTU::withCode(Code.code());
 auto AST = TU.build();
+llvm::StringRef NewName = "abcde";
 auto RenameResult =
-renameWithinFile(AST, testPath(TU.Filename), Code.point(), "abcde");
+renameWithinFile(AST, testPath(TU.Filename), Code.point(), NewName);
 ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
-auto ApplyResult =
-tooling::applyAllReplacements(Code.code(), *RenameResult);
-ASSERT_TRUE(bool(ApplyResult)) << ApplyResult.takeError();
-
-EXPECT_EQ(T.After, *ApplyResult) << T.Before;
+auto ApplyResult = llvm::cantFail(
+tooling::applyAllReplacements(Code.code(), *RenameResult));
+EXPECT_EQ(expectedResult(Code, NewName), ApplyResult);
   }
 }
 
@@ -176,25 +167,24 @@
   TU.ExtraArgs.push_back("-xobjective-c++-header");
 }
 auto AST = TU.build();
-
+llvm::StringRef NewName = "dummyNewName";
 auto Results = renameWithinFile(AST, testPath(TU.Filename), T.point(),
-"dummyNewName", Case.Index);
+NewName, Case.Index);
 bool WantRename = true;
 if (T.ranges().empty())
   WantRename = false;
 if (!WantRename) {
   assert(Case.ErrorMessage && "Error message must be set!");
-  EXPECT_FALSE(Results) << "expected renameWithinFile returned an error: "
-<< T.code();
+  EXPECT_FALSE(Results)
+  << "expected renameWithinFile returned an error: " << T.code();
   auto ActualMessage = llvm::toString(Results.takeError());
   EXPECT_THAT(ActualMessage, testing::HasSubstr(Case.ErrorMessage));
 } else {
   EXPECT_TRUE(bool(Results)) << "renameWithinFile returned an error: "
  << llvm::toString(Results.takeError());
-  std::vector> Expected;
-  for (const auto &R : T.ranges())
-Expe

[PATCH] D69804: [clang-tidy] Update TransformerClangTidyCheck to use new Transformer bindings.

2019-11-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69804



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


[PATCH] D69890: [clangd] Improve the output of rename tests where there are failures.

2019-11-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM! Many thanks, the new tests are much simpler to read!




Comment at: clang-tools-extra/clangd/unittests/RenameTests.cpp:31
+  llvm::StringRef Code = Test.code();
+  for (const auto &R : Test.ranges()) {
+unsigned StartOffset = llvm::cantFail(positionToOffset(Code, R.start));

NIT: `Test.llvm::Annotations::ranges()` will return ranges with offsets.
Should simplify the code.



Comment at: clang-tools-extra/clangd/unittests/RenameTests.cpp:44
 TEST(RenameTest, SingleFile) {
-  struct Test {
-const char* Before;
-const char* After;
-  } Tests[] = {
+  const char *Tests[] = {
   // Rename function.

NIT: worth documenting that `^` points to the start position of the rename and 
ranges point to the identifier that is being renamed.



Comment at: clang-tools-extra/clangd/unittests/RenameTests.cpp:44
 TEST(RenameTest, SingleFile) {
-  struct Test {
-const char* Before;
-const char* After;
-  } Tests[] = {
+  const char *Tests[] = {
   // Rename function.

ilya-biryukov wrote:
> NIT: worth documenting that `^` points to the start position of the rename 
> and ranges point to the identifier that is being renamed.
NIT: maybe use `llvm::StringRef Tests[]` instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69890



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


[PATCH] D69890: [clangd] Improve the output of rename tests where there are failures.

2019-11-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 228054.
hokein marked 3 inline comments as done.
hokein added a comment.

address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69890

Files:
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -22,71 +22,62 @@
   return replacementToEdit(Code, arg).range == Range;
 }
 
+// Generates an expected rename result by replacing all ranges in the given
+// annotation with the NewName.
+std::string expectedResult(Annotations Test, llvm::StringRef NewName) {
+  std::string Result;
+  unsigned NextChar = 0;
+  llvm::StringRef Code = Test.code();
+  for (const auto &R : Test.llvm::Annotations::ranges()) {
+assert(R.Begin <= R.End && NextChar <= R.Begin);
+Result += Code.substr(NextChar, R.Begin - NextChar);
+Result += NewName;
+NextChar = R.End;
+  }
+  Result += Code.substr(NextChar);
+  return Result;
+}
+
 TEST(RenameTest, SingleFile) {
-  struct Test {
-const char* Before;
-const char* After;
-  } Tests[] = {
+  // "^" points to the position of the rename, and "[[]]" ranges point to the
+  // identifier that is being renamed.
+  llvm::StringRef Tests[] = {
   // Rename function.
-  {
-  R"cpp(
-void foo() {
-  fo^o();
-}
-  )cpp",
-  R"cpp(
-void abcde() {
-  abcde();
-}
-  )cpp",
-  },
+  R"cpp(
+void [[foo]]() {
+  [[fo^o]]();
+}
+  )cpp",
+
   // Rename type.
-  {
-  R"cpp(
-struct foo{};
-foo test() {
-   f^oo x;
-   return x;
-}
-  )cpp",
-  R"cpp(
-struct abcde{};
-abcde test() {
-   abcde x;
-   return x;
-}
-  )cpp",
-  },
+  R"cpp(
+struct [[foo]]{};
+[[foo]] test() {
+   [[f^oo]] x;
+   return x;
+}
+  )cpp",
+
   // Rename variable.
-  {
-  R"cpp(
-void bar() {
-  if (auto ^foo = 5) {
-foo = 3;
-  }
-}
-  )cpp",
-  R"cpp(
-void bar() {
-  if (auto abcde = 5) {
-abcde = 3;
-  }
-}
-  )cpp",
-  },
+  R"cpp(
+void bar() {
+  if (auto [[^foo]] = 5) {
+[[foo]] = 3;
+  }
+}
+  )cpp",
   };
-  for (const Test &T : Tests) {
-Annotations Code(T.Before);
+  for (const auto T : Tests) {
+Annotations Code(T);
 auto TU = TestTU::withCode(Code.code());
 auto AST = TU.build();
+llvm::StringRef NewName = "abcde";
 auto RenameResult =
-renameWithinFile(AST, testPath(TU.Filename), Code.point(), "abcde");
+renameWithinFile(AST, testPath(TU.Filename), Code.point(), NewName);
 ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
-auto ApplyResult =
-tooling::applyAllReplacements(Code.code(), *RenameResult);
-ASSERT_TRUE(bool(ApplyResult)) << ApplyResult.takeError();
-
-EXPECT_EQ(T.After, *ApplyResult) << T.Before;
+auto ApplyResult = llvm::cantFail(
+tooling::applyAllReplacements(Code.code(), *RenameResult));
+EXPECT_EQ(expectedResult(Code, NewName), ApplyResult);
   }
 }
 
@@ -176,25 +167,24 @@
   TU.ExtraArgs.push_back("-xobjective-c++-header");
 }
 auto AST = TU.build();
-
+llvm::StringRef NewName = "dummyNewName";
 auto Results = renameWithinFile(AST, testPath(TU.Filename), T.point(),
-"dummyNewName", Case.Index);
+NewName, Case.Index);
 bool WantRename = true;
 if (T.ranges().empty())
   WantRename = false;
 if (!WantRename) {
   assert(Case.ErrorMessage && "Error message must be set!");
-  EXPECT_FALSE(Results) << "expected renameWithinFile returned an error: "
-<< T.code();
+  EXPECT_FALSE(Results)
+  << "expected renameWithinFile returned an error: " << T.code();
   auto ActualMessage = llvm::toString(Results.takeError());
   EXPECT_THAT(ActualMessage, testing::HasSubstr(Case.ErrorMessage));
 } else {
   EXPECT_TRUE(bool(Results)) << "renameWithinFile returned an error: "
  << llvm::toString(Results.takeError());
-  std::vector> Expected;
-  for (const auto &R : T.ranges())
-Expected.push_back(RenameRange(TU.Code, R));
-  EXPECT_THAT(*Results, UnorderedElementsAreArray(Expected));
+  auto ApplyResult =
+  llvm::cantFail(toolin

[PATCH] D69892: [clang-rename] Respect the traversal scope when traversing the entire AST.

2019-11-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, kadircet.
Herald added a project: clang.

This should be NFC to clang-rename, by default the traversal scope is
TUDecl. Traversing the TUDecl in clangd is a performance cliff, we should
avoid it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69892

Files:
  clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp


Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -67,7 +67,7 @@
 
   std::vector Find() {
 // Fill OverriddenMethods and PartialSpecs storages.
-TraverseDecl(Context.getTranslationUnitDecl());
+TraverseAST(Context);
 if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
   addUSRsOfOverridenFunctions(MethodDecl);
   for (const auto &OverriddenMethod : OverriddenMethods) {


Index: clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -67,7 +67,7 @@
 
   std::vector Find() {
 // Fill OverriddenMethods and PartialSpecs storages.
-TraverseDecl(Context.getTranslationUnitDecl());
+TraverseAST(Context);
 if (const auto *MethodDecl = dyn_cast(FoundDecl)) {
   addUSRsOfOverridenFunctions(MethodDecl);
   for (const auto &OverriddenMethod : OverriddenMethods) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] b0eed2a - [clangd] Improve the output of rename tests where there are failures.

2019-11-06 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2019-11-06T15:34:38+01:00
New Revision: b0eed2a5cfe13a7cd13e2446b7dfe2d7b588d416

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

LOG: [clangd] Improve the output of rename tests where there are failures.

Summary:
Previously, we match ranges, which is hard to spot the difference.
Now, we diff the code after rename against the expected result, it
produces much nicer output.

Reviewers: ilya-biryukov

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/RenameTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp 
b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index e3af711fbe36..c4ee649e5001 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -22,71 +22,62 @@ MATCHER_P2(RenameRange, Code, Range, "") {
   return replacementToEdit(Code, arg).range == Range;
 }
 
+// Generates an expected rename result by replacing all ranges in the given
+// annotation with the NewName.
+std::string expectedResult(Annotations Test, llvm::StringRef NewName) {
+  std::string Result;
+  unsigned NextChar = 0;
+  llvm::StringRef Code = Test.code();
+  for (const auto &R : Test.llvm::Annotations::ranges()) {
+assert(R.Begin <= R.End && NextChar <= R.Begin);
+Result += Code.substr(NextChar, R.Begin - NextChar);
+Result += NewName;
+NextChar = R.End;
+  }
+  Result += Code.substr(NextChar);
+  return Result;
+}
+
 TEST(RenameTest, SingleFile) {
-  struct Test {
-const char* Before;
-const char* After;
-  } Tests[] = {
+  // "^" points to the position of the rename, and "[[]]" ranges point to the
+  // identifier that is being renamed.
+  llvm::StringRef Tests[] = {
   // Rename function.
-  {
-  R"cpp(
-void foo() {
-  fo^o();
-}
-  )cpp",
-  R"cpp(
-void abcde() {
-  abcde();
-}
-  )cpp",
-  },
+  R"cpp(
+void [[foo]]() {
+  [[fo^o]]();
+}
+  )cpp",
+
   // Rename type.
-  {
-  R"cpp(
-struct foo{};
-foo test() {
-   f^oo x;
-   return x;
-}
-  )cpp",
-  R"cpp(
-struct abcde{};
-abcde test() {
-   abcde x;
-   return x;
-}
-  )cpp",
-  },
+  R"cpp(
+struct [[foo]]{};
+[[foo]] test() {
+   [[f^oo]] x;
+   return x;
+}
+  )cpp",
+
   // Rename variable.
-  {
-  R"cpp(
-void bar() {
-  if (auto ^foo = 5) {
-foo = 3;
-  }
-}
-  )cpp",
-  R"cpp(
-void bar() {
-  if (auto abcde = 5) {
-abcde = 3;
-  }
-}
-  )cpp",
-  },
+  R"cpp(
+void bar() {
+  if (auto [[^foo]] = 5) {
+[[foo]] = 3;
+  }
+}
+  )cpp",
   };
-  for (const Test &T : Tests) {
-Annotations Code(T.Before);
+  for (const auto T : Tests) {
+Annotations Code(T);
 auto TU = TestTU::withCode(Code.code());
 auto AST = TU.build();
+llvm::StringRef NewName = "abcde";
 auto RenameResult =
-renameWithinFile(AST, testPath(TU.Filename), Code.point(), "abcde");
+renameWithinFile(AST, testPath(TU.Filename), Code.point(), NewName);
 ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
-auto ApplyResult =
-tooling::applyAllReplacements(Code.code(), *RenameResult);
-ASSERT_TRUE(bool(ApplyResult)) << ApplyResult.takeError();
-
-EXPECT_EQ(T.After, *ApplyResult) << T.Before;
+auto ApplyResult = llvm::cantFail(
+tooling::applyAllReplacements(Code.code(), *RenameResult));
+EXPECT_EQ(expectedResult(Code, NewName), ApplyResult);
   }
 }
 
@@ -176,25 +167,24 @@ TEST(RenameTest, Renameable) {
   TU.ExtraArgs.push_back("-xobjective-c++-header");
 }
 auto AST = TU.build();
-
+llvm::StringRef NewName = "dummyNewName";
 auto Results = renameWithinFile(AST, testPath(TU.Filename), T.point(),
-"dummyNewName", Case.Index);
+NewName, Case.Index);
 bool WantRename = true;
 if (T.ranges().empty())
   WantRename = false;
 if (!WantRename) {
   assert(Case.ErrorMessage && "Error message must be set!");
-  EXPECT_FALSE(Results) << "expected renameWithinFile returned an error: "
-

[PATCH] D69892: [clang-rename] Respect the traversal scope when traversing the entire AST.

2019-11-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69892



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


[PATCH] D69785: [OpenMP] Introduce the OpenMP-IR-Builder

2019-11-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: llvm/lib/IR/OpenMPConstants.cpp:1
-//===- OpenMPConstants.cpp - Helpers related to OpenMP code generation ---===//
+//===- OpenMPIRBuilder.cpp - Builder for LLVM-IR for OpenMP directives 
===//
 //

Constants?



Comment at: llvm/lib/IR/OpenMPIRBuilder.cpp:120
+  if (!SrcLocStr) {
+Constant *Initializer =
+ConstantDataArray::getString(M.getContext(), LocStr);

`auto *`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69785



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


[PATCH] D69890: [clangd] Improve the output of rename tests where there are failures.

2019-11-06 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0eed2a5cfe1: [clangd] Improve the output of rename tests 
where there are failures. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69890

Files:
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -22,71 +22,62 @@
   return replacementToEdit(Code, arg).range == Range;
 }
 
+// Generates an expected rename result by replacing all ranges in the given
+// annotation with the NewName.
+std::string expectedResult(Annotations Test, llvm::StringRef NewName) {
+  std::string Result;
+  unsigned NextChar = 0;
+  llvm::StringRef Code = Test.code();
+  for (const auto &R : Test.llvm::Annotations::ranges()) {
+assert(R.Begin <= R.End && NextChar <= R.Begin);
+Result += Code.substr(NextChar, R.Begin - NextChar);
+Result += NewName;
+NextChar = R.End;
+  }
+  Result += Code.substr(NextChar);
+  return Result;
+}
+
 TEST(RenameTest, SingleFile) {
-  struct Test {
-const char* Before;
-const char* After;
-  } Tests[] = {
+  // "^" points to the position of the rename, and "[[]]" ranges point to the
+  // identifier that is being renamed.
+  llvm::StringRef Tests[] = {
   // Rename function.
-  {
-  R"cpp(
-void foo() {
-  fo^o();
-}
-  )cpp",
-  R"cpp(
-void abcde() {
-  abcde();
-}
-  )cpp",
-  },
+  R"cpp(
+void [[foo]]() {
+  [[fo^o]]();
+}
+  )cpp",
+
   // Rename type.
-  {
-  R"cpp(
-struct foo{};
-foo test() {
-   f^oo x;
-   return x;
-}
-  )cpp",
-  R"cpp(
-struct abcde{};
-abcde test() {
-   abcde x;
-   return x;
-}
-  )cpp",
-  },
+  R"cpp(
+struct [[foo]]{};
+[[foo]] test() {
+   [[f^oo]] x;
+   return x;
+}
+  )cpp",
+
   // Rename variable.
-  {
-  R"cpp(
-void bar() {
-  if (auto ^foo = 5) {
-foo = 3;
-  }
-}
-  )cpp",
-  R"cpp(
-void bar() {
-  if (auto abcde = 5) {
-abcde = 3;
-  }
-}
-  )cpp",
-  },
+  R"cpp(
+void bar() {
+  if (auto [[^foo]] = 5) {
+[[foo]] = 3;
+  }
+}
+  )cpp",
   };
-  for (const Test &T : Tests) {
-Annotations Code(T.Before);
+  for (const auto T : Tests) {
+Annotations Code(T);
 auto TU = TestTU::withCode(Code.code());
 auto AST = TU.build();
+llvm::StringRef NewName = "abcde";
 auto RenameResult =
-renameWithinFile(AST, testPath(TU.Filename), Code.point(), "abcde");
+renameWithinFile(AST, testPath(TU.Filename), Code.point(), NewName);
 ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
-auto ApplyResult =
-tooling::applyAllReplacements(Code.code(), *RenameResult);
-ASSERT_TRUE(bool(ApplyResult)) << ApplyResult.takeError();
-
-EXPECT_EQ(T.After, *ApplyResult) << T.Before;
+auto ApplyResult = llvm::cantFail(
+tooling::applyAllReplacements(Code.code(), *RenameResult));
+EXPECT_EQ(expectedResult(Code, NewName), ApplyResult);
   }
 }
 
@@ -176,25 +167,24 @@
   TU.ExtraArgs.push_back("-xobjective-c++-header");
 }
 auto AST = TU.build();
-
+llvm::StringRef NewName = "dummyNewName";
 auto Results = renameWithinFile(AST, testPath(TU.Filename), T.point(),
-"dummyNewName", Case.Index);
+NewName, Case.Index);
 bool WantRename = true;
 if (T.ranges().empty())
   WantRename = false;
 if (!WantRename) {
   assert(Case.ErrorMessage && "Error message must be set!");
-  EXPECT_FALSE(Results) << "expected renameWithinFile returned an error: "
-<< T.code();
+  EXPECT_FALSE(Results)
+  << "expected renameWithinFile returned an error: " << T.code();
   auto ActualMessage = llvm::toString(Results.takeError());
   EXPECT_THAT(ActualMessage, testing::HasSubstr(Case.ErrorMessage));
 } else {
   EXPECT_TRUE(bool(Results)) << "renameWithinFile returned an error: "
  << llvm::toString(Results.takeError());
-  std::vector> Expected;
-  for (const auto &R : T.ranges())
-Expected.push_back(RenameRange(TU.Code, R));
-  EXPECT_THAT(*Results, UnorderedElementsAreArray(Expecte

[PATCH] D69893: libunwind: Evaluating DWARF operation DW_OP_pick is broken

2019-11-06 Thread kamlesh kumar via Phabricator via cfe-commits
kamleshbhalui created this revision.
kamleshbhalui added a reviewer: phosek.
Herald added subscribers: libcxx-commits, ldionne, christof.
kamleshbhalui edited the summary of this revision.

reg is unsigned type and used here for getting array element from the end  by 
negating it.
negation of unsigned can result in large number and array access with that 
index will result in segmentation
 fault.
As a Fix we cast reg to int then negate it.
Fixes this. 
https://bugs.llvm.org/show_bug.cgi?id=43872


Repository:
  rUNW libunwind

https://reviews.llvm.org/D69893

Files:
  libunwind/src/DwarfInstructions.hpp


Index: libunwind/src/DwarfInstructions.hpp
===
--- libunwind/src/DwarfInstructions.hpp
+++ libunwind/src/DwarfInstructions.hpp
@@ -430,7 +430,7 @@
   // pick from
   reg = addressSpace.get8(p);
   p += 1;
-  value = sp[-reg];
+  value = sp[-(int)reg];
   *(++sp) = value;
   if (log)
 fprintf(stderr, "duplicate %d in stack\n", reg);


Index: libunwind/src/DwarfInstructions.hpp
===
--- libunwind/src/DwarfInstructions.hpp
+++ libunwind/src/DwarfInstructions.hpp
@@ -430,7 +430,7 @@
   // pick from
   reg = addressSpace.get8(p);
   p += 1;
-  value = sp[-reg];
+  value = sp[-(int)reg];
   *(++sp) = value;
   if (log)
 fprintf(stderr, "duplicate %d in stack\n", reg);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69204: [OpenMP 5.0] - Extend defaultmap

2019-11-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1967
   (DSAStack->isForceCaptureByReferenceInTargetExecutable() &&
!Ty->isAnyPointerType()) ||
   !Ty->isScalarType() ||

ABataev wrote:
> Seems to me, you're missing additional checks for pointers here.
Not done



Comment at: clang/lib/Sema/SemaOpenMP.cpp:2830
+return DMVC_pointer;
+  } else if (VD->getType()->isScalarType()) {
+return DMVC_scalar;

No need `else if` here , just `if`



Comment at: clang/lib/Sema/SemaOpenMP.cpp:2832
+return DMVC_scalar;
+  } else {
+return DMVC_aggregate;

No need for `else` here, just `return`



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3200-3201
   }
-  ArrayRef getImplicitMap() const { return ImplicitMap; }
+  std::array, DMVC_unspecified> getImplicitMap()
+  const { return ImplicitMap; }
   const Sema::VarsWithInheritedDSAType &getVarsWithInheritedDSA() const {

Better to get each particular list via the `DMVC_` key passed as parameter



Comment at: clang/lib/Sema/SemaOpenMP.cpp:4374
+  case DMIB_unspecified:
+return OMPC_MAP_tofrom;
+  }

`OMPC_MAP_tofrom` must be returned only for `DMIB_tofrom`, for others, it must 
be `llvm_unreachable()`



Comment at: clang/lib/Sema/SemaOpenMP.cpp:16512
+case OMPC_DEFAULTMAP_MODIFIER_default:
+  DSAStack->setDefaultDMAAttr(DMIB_default, DMVC_pointer, StartLoc);
+  break;

Just create 2 variables and initialize them. Call `setDefault...` only once.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69204



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


[clang-tools-extra] bde3293 - [clang-tidy] Update TransformerClangTidyCheck to use new Transformer bindings.

2019-11-06 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2019-11-06T10:13:33-05:00
New Revision: bde32933027a096b6cfe14b0e9385ac1005fc28a

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

LOG: [clang-tidy] Update TransformerClangTidyCheck to use new Transformer 
bindings.

Summary:
Updates the relevant source files to use bindings in `clang::transformer` rather
than `clang::tooling`.

Reviewers: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
index 06899108ea36..1c31cf56c68a 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -12,7 +12,7 @@
 namespace clang {
 namespace tidy {
 namespace utils {
-using tooling::RewriteRule;
+using transformer::RewriteRule;
 
 #ifndef NDEBUG
 static bool hasExplanation(const RewriteRule::Case &C) {
@@ -62,7 +62,7 @@ void TransformerClangTidyCheck::registerPPCallbacks(
 void TransformerClangTidyCheck::registerMatchers(
 ast_matchers::MatchFinder *Finder) {
   if (Rule)
-for (auto &Matcher : tooling::detail::buildMatchers(*Rule))
+for (auto &Matcher : transformer::detail::buildMatchers(*Rule))
   Finder->addDynamicMatcher(Matcher, this);
 }
 
@@ -72,9 +72,9 @@ void TransformerClangTidyCheck::check(
 return;
 
   assert(Rule && "check() should not fire if Rule is None");
-  RewriteRule::Case Case = tooling::detail::findSelectedCase(Result, *Rule);
-  Expected> Transformations =
-  tooling::detail::translateEdits(Result, Case.Edits);
+  RewriteRule::Case Case = transformer::detail::findSelectedCase(Result, 
*Rule);
+  Expected>
+  Transformations = transformer::detail::translateEdits(Result, 
Case.Edits);
   if (!Transformations) {
 llvm::errs() << "Rewrite failed: "
  << llvm::toString(Transformations.takeError()) << "\n";
@@ -102,7 +102,7 @@ void TransformerClangTidyCheck::check(
 auto &Header = I.first;
 if (Optional Fix = Inserter->CreateIncludeInsertion(
 Result.SourceManager->getMainFileID(), Header,
-/*IsAngled=*/I.second == tooling::IncludeFormat::Angled)) {
+/*IsAngled=*/I.second == transformer::IncludeFormat::Angled)) {
   Diag << *Fix;
 }
   }

diff  --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
index bcbc41507db2..e411a3f6f0f5 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -44,14 +44,14 @@ class TransformerClangTidyCheck : public ClangTidyCheck {
   // no explanation is desired, indicate that explicitly (for example, by
   // passing `text("no explanation")` to `makeRule` as the `Explanation`
   // argument).
-  TransformerClangTidyCheck(std::function(
+  TransformerClangTidyCheck(std::function(
 const LangOptions &, const OptionsView &)>
 MakeRule,
 StringRef Name, ClangTidyContext *Context);
 
   // Convenience overload of the constructor when the rule doesn't depend on 
any
   // of the language or clang-tidy options.
-  TransformerClangTidyCheck(tooling::RewriteRule R, StringRef Name,
+  TransformerClangTidyCheck(transformer::RewriteRule R, StringRef Name,
 ClangTidyContext *Context);
 
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
@@ -60,7 +60,7 @@ class TransformerClangTidyCheck : public ClangTidyCheck {
   void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
 
 private:
-  Optional Rule;
+  Optional Rule;
   std::unique_ptr Inserter;
 };
 

diff  --git 
a/clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
index c8e65e9bf988..28ea7e229f35 100644
--- a/clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
@@ -20,13 +20,12 @@ namespace utils {
 namespace {
 using namespace ::clang::ast_matchers;
 
-using tooling::change;
-using tooling::IncludeFormat;
-using tooling::node;
-using tooling::RewriteRule;
-using tooling::statement;
-using tooling::text;
-using tooling::s

[PATCH] D69804: [clang-tidy] Update TransformerClangTidyCheck to use new Transformer bindings.

2019-11-06 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbde32933027a: [clang-tidy] Update TransformerClangTidyCheck 
to use new Transformer bindings. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69804

Files:
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
@@ -20,13 +20,12 @@
 namespace {
 using namespace ::clang::ast_matchers;
 
-using tooling::change;
-using tooling::IncludeFormat;
-using tooling::node;
-using tooling::RewriteRule;
-using tooling::statement;
-using tooling::text;
-using tooling::stencil::cat;
+using transformer::cat;
+using transformer::change;
+using transformer::IncludeFormat;
+using transformer::node;
+using transformer::RewriteRule;
+using transformer::statement;
 
 // Invert the code of an if-statement, while maintaining its semantics.
 RewriteRule invertIf() {
@@ -37,7 +36,7 @@
   change(
   statement(RewriteRule::RootID),
   cat("if(!(", node(C), ")) ", statement(E), " else ", statement(T))),
-  text("negate condition and reverse `then` and `else` branches"));
+  cat("negate condition and reverse `then` and `else` branches"));
   return Rule;
 }
 
@@ -71,8 +70,8 @@
 public:
   IntLitCheck(StringRef Name, ClangTidyContext *Context)
   : TransformerClangTidyCheck(tooling::makeRule(integerLiteral(),
-change(text("LIT")),
-text("no message")),
+change(cat("LIT")),
+cat("no message")),
   Name, Context) {}
 };
 
@@ -97,7 +96,7 @@
   : TransformerClangTidyCheck(
 tooling::makeRule(
 binaryOperator(hasOperatorName("+"), hasRHS(expr().bind("r"))),
-change(node("r"), text("RIGHT")), text("no message")),
+change(node("r"), cat("RIGHT")), cat("no message")),
 Name, Context) {}
 };
 
@@ -123,7 +122,7 @@
   if (!LangOpts.ObjC)
 return None;
   return tooling::makeRule(clang::ast_matchers::functionDecl(),
-   change(cat("void changed() {}")), text("no message"));
+   change(cat("void changed() {}")), cat("no message"));
 }
 
 class NeedsObjCCheck : public TransformerClangTidyCheck {
@@ -148,7 +147,7 @@
   if (Options.get("Skip", "false") == "true")
 return None;
   return tooling::makeRule(clang::ast_matchers::functionDecl(),
-   change(cat("void nothing()")), text("no message"));
+   change(cat("void nothing()")), cat("no message"));
 }
 
 class ConfigurableCheck : public TransformerClangTidyCheck {
@@ -176,7 +175,7 @@
   using namespace ::clang::ast_matchers;
   RewriteRule Rule =
   tooling::makeRule(callExpr(callee(functionDecl(hasName("f",
-change(text("other()")), text("no message"));
+change(cat("other()")), cat("no message"));
   addInclude(Rule, "clang/OtherLib.h", Format);
   return Rule;
 }
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -44,14 +44,14 @@
   // no explanation is desired, indicate that explicitly (for example, by
   // passing `text("no explanation")` to `makeRule` as the `Explanation`
   // argument).
-  TransformerClangTidyCheck(std::function(
+  TransformerClangTidyCheck(std::function(
 const LangOptions &, const OptionsView &)>
 MakeRule,
 StringRef Name, ClangTidyContext *Context);
 
   // Convenience overload of the constructor when the rule doesn't depend on any
   // of the language or clang-tidy options.
-  TransformerClangTidyCheck(tooling::RewriteRule R, StringRef Name,
+  TransformerClangTidyCheck(transformer::RewriteRule R, StringRef Name,
 ClangTidyContext *Context);
 
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
@@ -60,7 +60,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
 
 private:
-  Optional Rule;
+  Optional Rule;
   std::unique_ptr Inserter;
 };
 
Index: c

[PATCH] D69598: Work on cleaning up denormal mode handling

2019-11-06 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:1736-1737
+if (CodeGenOpts.FPSubnormalMode != llvm::SubnormalMode::Invalid)
+  FuncAttrs.addAttribute("denormal-fp-math",
+ 
llvm::subnormalModeName(CodeGenOpts.FPSubnormalMode));
 

arsenm wrote:
> spatel wrote:
> > Do you plan to change the attribute string from "denormal" to "subnormal" 
> > as part of upgrading it to work per-FP-type? Would we need to auto-upgrade 
> > old IR as part of making the string consistent with the code?
> > 
> > Can we stash the attribute string name inside a getter function in the new 
> > ADT file, so clang and LLVM have a common source of truth for the attribute 
> > name?
> I'm considering it, but at the moment I'm trying to avoid changes. The next 
> step I'm working on is adding denormal-fp-math-f32 (or maybe 
> subnormal-fp-math-f32), which will co-exist and override the current 
> attribute if the type matches
I think it would be better to not change the vocabulary incrementally then. Ie, 
keep everything "denormal" in this patch, and then universally change the 
terminology to "subnormal" in one step. That way we won't have any 
inconsistency/confusion between the attribute name and the code.


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

https://reviews.llvm.org/D69598



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


[clang] ce2b5cb - [libTooling] Simplify type structure of `Stencil`s.

2019-11-06 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2019-11-06T10:28:34-05:00
New Revision: ce2b5cb6decb5cce32adde0d23bdea521da0908b

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

LOG: [libTooling] Simplify type structure of `Stencil`s.

Summary:
Currently, stencils are defined as a sequence of `StencilParts`. This
differentiation adds an unneeded layer of complexity to the definition of
Stencils. This change significantly simplifies the type structure: a stencil is
now conceptually any object implementing `StencilInterface` and `Stencil` is
just a thin wrapper for pointers to this interface.

To account for the sequencing that was supported by the old `Stencil` type, we
introduce a sequencing class that implements `StencilInterface`. That is,
sequences are just another kind of Stencil and no longer have any special
status.

Corresponding to this change in the type structure, we change the way `cat` is
used (and defined). `cat` bundles multiple features: it builds a stencil from a
sequence of subcomponents and admits multiple different types for its arguments,
while coercing them into the right type. Previously, `cat` was also used to
coerce a single `StencilPart` into a `Stencil`. With that distinction gone, many
uses of `cat` (e.g. in the tests) are unnecessary and have, therefore, been
removed.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Transformer/Stencil.h
clang/lib/Tooling/Transformer/Stencil.cpp
clang/unittests/Tooling/StencilTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Transformer/Stencil.h 
b/clang/include/clang/Tooling/Transformer/Stencil.h
index 6ef44e5ce7ba..ca23a6355f81 100644
--- a/clang/include/clang/Tooling/Transformer/Stencil.h
+++ b/clang/include/clang/Tooling/Transformer/Stencil.h
@@ -32,197 +32,132 @@
 
 namespace clang {
 namespace transformer {
-/// A stencil is represented as a sequence of "parts" that can each 
individually
-/// generate a code string based on a match result.  The 
diff erent kinds of
-/// parts include (raw) text, references to bound nodes and assorted operations
-/// on bound nodes.
-///
-/// Users can create custom Stencil operations by implementing this interface.
-class StencilPartInterface {
+class StencilInterface {
 public:
-  virtual ~StencilPartInterface() = default;
+  virtual ~StencilInterface() = default;
 
   /// Evaluates this part to a string and appends it to \c Result.  \c Result 
is
-  /// undefined in the case of an error.
+  /// undefined in the case of an error. `Result` is an out parameter to
+  /// optimize the expected common case of evaluating a sequence of generators.
   virtual llvm::Error eval(const ast_matchers::MatchFinder::MatchResult &Match,
std::string *Result) const = 0;
 
-  /// Constructs a string representation of the StencilPart. StencilParts
-  /// generated by the `selection` and `run` functions do not have a unique
-  /// string representation.
+  /// Convenience version of `eval`, for the case where the generator is being
+  /// evaluated on its own.
+  llvm::Expected
+  eval(const ast_matchers::MatchFinder::MatchResult &R) const;
+
+  /// Constructs a string representation of the StencilInterface. The
+  /// representation must be deterministic, but is not required to be unique.
   virtual std::string toString() const = 0;
 
 protected:
-  StencilPartInterface() = default;
+  StencilInterface() = default;
 
   // Since this is an abstract class, copying/assigning only make sense for
   // derived classes implementing `clone()`.
-  StencilPartInterface(const StencilPartInterface &) = default;
-  StencilPartInterface &operator=(const StencilPartInterface &) = default;
-};
-
-/// A copyable facade for a std::unique_ptr. Copies 
result
-/// in a copy of the underlying pointee object.
-class StencilPart {
-public:
-  explicit StencilPart(std::shared_ptr Impl)
-  : Impl(std::move(Impl)) {}
-
-  /// See `StencilPartInterface::eval()`.
-  llvm::Error eval(const ast_matchers::MatchFinder::MatchResult &Match,
-   std::string *Result) const {
-return Impl->eval(Match, Result);
-  }
-
-  std::string toString() const {
-if (Impl == nullptr)
-  return "";
-return Impl->toString();
-  }
-
-private:
-  std::shared_ptr Impl;
+  StencilInterface(const StencilInterface &) = default;
+  StencilInterface &operator=(const StencilInterface &) = default;
 };
 
 /// A sequence of code fragments, references to parameters and code-generation
-/// operations that together can be evaluated to (a fragment of) source code,
-/// given a match result.
+/// operations that together can be evaluated to (a fragment of) source code 

[PATCH] D69893: libunwind: Evaluating DWARF operation DW_OP_pick is broken

2019-11-06 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a reviewer: kledzik.
ldionne accepted this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

This looks good to me, but I must admit I'm surprised this problem has never 
come up before (this code is very old), and also I don't know what the code is 
trying to do. Adding Saleem and Nick who have more experience with `libunwind` 
just to double-check.


Repository:
  rUNW libunwind

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

https://reviews.llvm.org/D69893



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


[PATCH] D69613: [libTooling] Simplify type structure of `Stencil`s.

2019-11-06 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGce2b5cb6decb: [libTooling] Simplify type structure of 
`Stencil`s. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69613

Files:
  clang/include/clang/Tooling/Transformer/Stencil.h
  clang/lib/Tooling/Transformer/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -96,7 +96,7 @@
  .bind("expr")))
 .bind("stmt"));
 ASSERT_TRUE(StmtMatch);
-if (auto ResultOrErr = Stencil.eval(StmtMatch->Result)) {
+if (auto ResultOrErr = Stencil->eval(StmtMatch->Result)) {
   ADD_FAILURE() << "Expected failure but succeeded: " << *ResultOrErr;
 } else {
   auto Err = llvm::handleErrors(ResultOrErr.takeError(),
@@ -131,11 +131,12 @@
   // Invert the if-then-else.
   auto Stencil = cat("if (!", node(Condition), ") ", statement(Else), " else ",
  statement(Then));
-  EXPECT_THAT_EXPECTED(Stencil.eval(StmtMatch->Result),
+  EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
HasValue("if (!true) return 0; else return 1;"));
 }
 
-TEST_F(StencilTest, SingleStatementCallOperator) {
+// Tests `stencil`.
+TEST_F(StencilTest, StencilFactoryFunction) {
   StringRef Condition("C"), Then("T"), Else("E");
   const std::string Snippet = R"cc(
 if (true)
@@ -148,9 +149,9 @@
   hasThen(stmt().bind(Then)), hasElse(stmt().bind(Else;
   ASSERT_TRUE(StmtMatch);
   // Invert the if-then-else.
-  Stencil S = cat("if (!", node(Condition), ") ", statement(Else), " else ",
-  statement(Then));
-  EXPECT_THAT_EXPECTED(S(StmtMatch->Result),
+  auto Consumer = cat("if (!", node(Condition), ") ", statement(Else), " else ",
+  statement(Then));
+  EXPECT_THAT_EXPECTED(Consumer(StmtMatch->Result),
HasValue("if (!true) return 0; else return 1;"));
 }
 
@@ -165,7 +166,7 @@
  hasThen(stmt().bind("a2";
   ASSERT_TRUE(StmtMatch);
   auto Stencil = cat("if(!", node("a1"), ") ", node("UNBOUND"), ";");
-  auto ResultOrErr = Stencil.eval(StmtMatch->Result);
+  auto ResultOrErr = Stencil->eval(StmtMatch->Result);
   EXPECT_TRUE(llvm::errorToBool(ResultOrErr.takeError()))
   << "Expected unbound node, got " << *ResultOrErr;
 }
@@ -176,14 +177,14 @@
   StringRef Expected) {
   auto StmtMatch = matchStmt(Snippet, expr().bind(Id));
   ASSERT_TRUE(StmtMatch);
-  EXPECT_THAT_EXPECTED(Stencil.eval(StmtMatch->Result), HasValue(Expected));
+  EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result), HasValue(Expected));
 }
 
 void testFailure(StringRef Id, StringRef Snippet, const Stencil &Stencil,
  testing::Matcher MessageMatcher) {
   auto StmtMatch = matchStmt(Snippet, expr().bind(Id));
   ASSERT_TRUE(StmtMatch);
-  EXPECT_THAT_EXPECTED(Stencil.eval(StmtMatch->Result),
+  EXPECT_THAT_EXPECTED(Stencil->eval(StmtMatch->Result),
Failed(testing::Property(
&StringError::getMessage, MessageMatcher)));
 }
@@ -195,28 +196,28 @@
 
 TEST_F(StencilTest, IfBoundOpBound) {
   StringRef Id = "id";
-  testExpr(Id, "3;", cat(ifBound(Id, text("5"), text("7"))), "5");
+  testExpr(Id, "3;", ifBound(Id, text("5"), text("7")), "5");
 }
 
 TEST_F(StencilTest, IfBoundOpUnbound) {
   StringRef Id = "id";
-  testExpr(Id, "3;", cat(ifBound("other", text("5"), text("7"))), "7");
+  testExpr(Id, "3;", ifBound("other", text("5"), text("7")), "7");
 }
 
 TEST_F(StencilTest, ExpressionOpNoParens) {
   StringRef Id = "id";
-  testExpr(Id, "3;", cat(expression(Id)), "3");
+  testExpr(Id, "3;", expression(Id), "3");
 }
 
 // Don't parenthesize a parens expression.
 TEST_F(StencilTest, ExpressionOpNoParensParens) {
   StringRef Id = "id";
-  testExpr(Id, "(3);", cat(expression(Id)), "(3)");
+  testExpr(Id, "(3);", expression(Id), "(3)");
 }
 
 TEST_F(StencilTest, ExpressionOpBinaryOpParens) {
   StringRef Id = "id";
-  testExpr(Id, "3+4;", cat(expression(Id)), "(3+4)");
+  testExpr(Id, "3+4;", expression(Id), "(3+4)");
 }
 
 // `expression` shares code with other ops, so we get sufficient coverage of the
@@ -224,33 +225,33 @@
 // tests should be added.
 TEST_F(StencilTest, ExpressionOpUnbound) {
   StringRef Id = "id";
-  testFailure(Id, "3;", cat(expression("ACACA")),
+  testFailure(Id, "3;", expression("ACACA"),
   AllOf(HasSubstr("ACACA"), HasSubstr("not bound")));
 }
 
 TEST_F(StencilTest, DerefPointer) {
   StringRef Id = "id";
-  testExpr(Id, "int *x; x;", cat(deref(Id)), "*x");
+  testExpr(Id, "int *x; x;", deref(Id), "*x");
 }
 
 TEST_F(StencilTest, DerefBinOp) {
   Str

[PATCH] D69896: [libTooling] Small changes in Transformer API.

2019-11-06 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: ilya-biryukov.
Herald added a project: clang.

- Rename `transformer::change` to `transformer::changeTo`, make `change` 
forward to `changeTo` and mark it deprecated.

- Mark `transformer::text` and `transformer::selection` deprecated and migrate 
references to them in tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69896

Files:
  clang/include/clang/Tooling/Transformer/RewriteRule.h
  clang/include/clang/Tooling/Transformer/Stencil.h
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -147,7 +147,7 @@
   on(expr(hasType(isOrPointsTo(StringType)))
  .bind(StringExpr)),
   callee(cxxMethodDecl(hasName("c_str")),
-  change(text("REPLACED")), text("Use size() method directly on string."));
+  changeTo(cat("REPLACED")), cat("Use size() method directly on string."));
   return R;
 }
 
@@ -171,7 +171,7 @@
 hasName("proto::ProtoCommandLineFlag"
.bind(Flag)),
 unless(callee(cxxMethodDecl(hasName("GetProto"),
-  change(node(Flag), text("EXPR")));
+  changeTo(node(Flag), cat("EXPR")));
 
   std::string Input = R"cc(
 proto::ProtoCommandLineFlag flag;
@@ -189,7 +189,7 @@
 
 TEST_F(TransformerTest, AddIncludeQuoted) {
   RewriteRule Rule = makeRule(callExpr(callee(functionDecl(hasName("f",
-  change(text("other()")));
+  changeTo(cat("other()")));
   addInclude(Rule, "clang/OtherLib.h");
 
   std::string Input = R"cc(
@@ -207,7 +207,7 @@
 
 TEST_F(TransformerTest, AddIncludeAngled) {
   RewriteRule Rule = makeRule(callExpr(callee(functionDecl(hasName("f",
-  change(text("other()")));
+  changeTo(cat("other()")));
   addInclude(Rule, "clang/OtherLib.h", transformer::IncludeFormat::Angled);
 
   std::string Input = R"cc(
@@ -226,7 +226,7 @@
 TEST_F(TransformerTest, NodePartNameNamedDecl) {
   StringRef Fun = "fun";
   RewriteRule Rule = makeRule(functionDecl(hasName("bad")).bind(Fun),
-  change(name(Fun), text("good")));
+  changeTo(name(Fun), cat("good")));
 
   std::string Input = R"cc(
 int bad(int x);
@@ -258,7 +258,7 @@
 
   StringRef Ref = "ref";
   testRule(makeRule(declRefExpr(to(functionDecl(hasName("bad".bind(Ref),
-change(name(Ref), text("good"))),
+changeTo(name(Ref), cat("good"))),
Input, Expected);
 }
 
@@ -276,7 +276,7 @@
 
   StringRef Ref = "ref";
   Transformer T(makeRule(declRefExpr(to(functionDecl())).bind(Ref),
- change(name(Ref), text("good"))),
+ changeTo(name(Ref), cat("good"))),
 consumer());
   T.registerMatchers(&MatchFinder);
   EXPECT_FALSE(rewrite(Input));
@@ -285,7 +285,7 @@
 TEST_F(TransformerTest, NodePartMember) {
   StringRef E = "expr";
   RewriteRule Rule = makeRule(memberExpr(member(hasName("bad"))).bind(E),
-  change(member(E), text("good")));
+  changeTo(member(E), cat("good")));
 
   std::string Input = R"cc(
 struct S {
@@ -338,7 +338,7 @@
   )cc";
 
   StringRef E = "expr";
-  testRule(makeRule(memberExpr().bind(E), change(member(E), text("good"))),
+  testRule(makeRule(memberExpr().bind(E), changeTo(member(E), cat("good"))),
Input, Expected);
 }
 
@@ -370,7 +370,7 @@
 
   StringRef MemExpr = "member";
   testRule(makeRule(memberExpr().bind(MemExpr),
-change(member(MemExpr), text("good"))),
+changeTo(member(MemExpr), cat("good"))),
Input, Expected);
 }
 
@@ -389,7 +389,7 @@
 
   StringRef Ret = "return";
   testRule(makeRule(returnStmt().bind(Ret),
-insertBefore(statement(Ret), text("int y = 3;"))),
+insertBefore(statement(Ret), cat("int y = 3;"))),
Input, Expected);
 }
 
@@ -410,7 +410,7 @@
 
   StringRef Decl = "decl";
   testRule(makeRule(declStmt().bind(Decl),
-insertAfter(statement(Decl), text("int y = 3;"))),
+insertAfter(statement(Decl), cat("int y = 3;"))),
Input, Expected);
 }
 
@@ -451,9 +451,9 @@
   StringRef C = "C", T = "T", E = "E";
   testRule(makeRule(ifStmt(hasCondition(expr().bind(C)),
hasThen(stmt().bind(T)), hasElse(stmt().bind(E))),
-{change(node(C), text("true")),
- change(statement(T), text("{ /* then */ }")),
- change(statement(E), tex

[PATCH] D69896: [libTooling] Small changes in Transformer API.

2019-11-06 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69896



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


[PATCH] D69896: [libTooling] Small changes in Transformer API.

2019-11-06 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f97480cddd7: [libTooling] Small changes in Transformer API. 
(authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69896

Files:
  clang/include/clang/Tooling/Transformer/RewriteRule.h
  clang/include/clang/Tooling/Transformer/Stencil.h
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -147,7 +147,7 @@
   on(expr(hasType(isOrPointsTo(StringType)))
  .bind(StringExpr)),
   callee(cxxMethodDecl(hasName("c_str")),
-  change(text("REPLACED")), text("Use size() method directly on string."));
+  changeTo(cat("REPLACED")), cat("Use size() method directly on string."));
   return R;
 }
 
@@ -171,7 +171,7 @@
 hasName("proto::ProtoCommandLineFlag"
.bind(Flag)),
 unless(callee(cxxMethodDecl(hasName("GetProto"),
-  change(node(Flag), text("EXPR")));
+  changeTo(node(Flag), cat("EXPR")));
 
   std::string Input = R"cc(
 proto::ProtoCommandLineFlag flag;
@@ -189,7 +189,7 @@
 
 TEST_F(TransformerTest, AddIncludeQuoted) {
   RewriteRule Rule = makeRule(callExpr(callee(functionDecl(hasName("f",
-  change(text("other()")));
+  changeTo(cat("other()")));
   addInclude(Rule, "clang/OtherLib.h");
 
   std::string Input = R"cc(
@@ -207,7 +207,7 @@
 
 TEST_F(TransformerTest, AddIncludeAngled) {
   RewriteRule Rule = makeRule(callExpr(callee(functionDecl(hasName("f",
-  change(text("other()")));
+  changeTo(cat("other()")));
   addInclude(Rule, "clang/OtherLib.h", transformer::IncludeFormat::Angled);
 
   std::string Input = R"cc(
@@ -226,7 +226,7 @@
 TEST_F(TransformerTest, NodePartNameNamedDecl) {
   StringRef Fun = "fun";
   RewriteRule Rule = makeRule(functionDecl(hasName("bad")).bind(Fun),
-  change(name(Fun), text("good")));
+  changeTo(name(Fun), cat("good")));
 
   std::string Input = R"cc(
 int bad(int x);
@@ -258,7 +258,7 @@
 
   StringRef Ref = "ref";
   testRule(makeRule(declRefExpr(to(functionDecl(hasName("bad".bind(Ref),
-change(name(Ref), text("good"))),
+changeTo(name(Ref), cat("good"))),
Input, Expected);
 }
 
@@ -276,7 +276,7 @@
 
   StringRef Ref = "ref";
   Transformer T(makeRule(declRefExpr(to(functionDecl())).bind(Ref),
- change(name(Ref), text("good"))),
+ changeTo(name(Ref), cat("good"))),
 consumer());
   T.registerMatchers(&MatchFinder);
   EXPECT_FALSE(rewrite(Input));
@@ -285,7 +285,7 @@
 TEST_F(TransformerTest, NodePartMember) {
   StringRef E = "expr";
   RewriteRule Rule = makeRule(memberExpr(member(hasName("bad"))).bind(E),
-  change(member(E), text("good")));
+  changeTo(member(E), cat("good")));
 
   std::string Input = R"cc(
 struct S {
@@ -338,7 +338,7 @@
   )cc";
 
   StringRef E = "expr";
-  testRule(makeRule(memberExpr().bind(E), change(member(E), text("good"))),
+  testRule(makeRule(memberExpr().bind(E), changeTo(member(E), cat("good"))),
Input, Expected);
 }
 
@@ -370,7 +370,7 @@
 
   StringRef MemExpr = "member";
   testRule(makeRule(memberExpr().bind(MemExpr),
-change(member(MemExpr), text("good"))),
+changeTo(member(MemExpr), cat("good"))),
Input, Expected);
 }
 
@@ -389,7 +389,7 @@
 
   StringRef Ret = "return";
   testRule(makeRule(returnStmt().bind(Ret),
-insertBefore(statement(Ret), text("int y = 3;"))),
+insertBefore(statement(Ret), cat("int y = 3;"))),
Input, Expected);
 }
 
@@ -410,7 +410,7 @@
 
   StringRef Decl = "decl";
   testRule(makeRule(declStmt().bind(Decl),
-insertAfter(statement(Decl), text("int y = 3;"))),
+insertAfter(statement(Decl), cat("int y = 3;"))),
Input, Expected);
 }
 
@@ -451,9 +451,9 @@
   StringRef C = "C", T = "T", E = "E";
   testRule(makeRule(ifStmt(hasCondition(expr().bind(C)),
hasThen(stmt().bind(T)), hasElse(stmt().bind(E))),
-{change(node(C), text("true")),
- change(statement(T), text("{ /* then */ }")),
- change(statement(E), text("{ /* else */ }"))}),
+{changeTo(node(C), cat("true")),
+

[clang] 9f97480 - [libTooling] Small changes in Transformer API.

2019-11-06 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2019-11-06T11:16:50-05:00
New Revision: 9f97480cddd77bd2d169131a290cc996fc78df0f

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

LOG: [libTooling] Small changes in Transformer API.

Summary:
* Rename `transformer::change` to `transformer::changeTo`, make `change` forward
  to `changeTo` and mark it deprecated.

* Mark `transformer::text` and `transformer::selection` deprecated and migrate
  references to them in tests.

Reviewers: ilya-biryukov

Subscribers: gribozavr, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Transformer/RewriteRule.h
clang/include/clang/Tooling/Transformer/Stencil.h
clang/unittests/Tooling/TransformerTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Transformer/RewriteRule.h 
b/clang/include/clang/Tooling/Transformer/RewriteRule.h
index 6e99151c1c7f..11ff2bc9867f 100644
--- a/clang/include/clang/Tooling/Transformer/RewriteRule.h
+++ b/clang/include/clang/Tooling/Transformer/RewriteRule.h
@@ -55,18 +55,18 @@ using TextGenerator = MatchConsumer;
 // `ASTEdit` should be built using the `change` convenience functions. For
 // example,
 // \code
-//   change(name(fun), text("Frodo"))
+//   changeTo(name(fun), cat("Frodo"))
 // \endcode
 // Or, if we use Stencil for the TextGenerator:
 // \code
 //   using stencil::cat;
-//   change(statement(thenNode), cat("{", thenNode, "}"))
-//   change(callArgs(call), cat(x, ",", y))
+//   changeTo(statement(thenNode), cat("{", thenNode, "}"))
+//   changeTo(callArgs(call), cat(x, ",", y))
 // \endcode
 // Or, if you are changing the node corresponding to the rule's matcher, you 
can
 // use the single-argument override of \c change:
 // \code
-//   change(cat("
diff erent_expr"))
+//   changeTo(cat("
diff erent_expr"))
 // \endcode
 struct ASTEdit {
   RangeSelector TargetRange;
@@ -141,7 +141,7 @@ inline RewriteRule 
makeRule(ast_matchers::internal::DynTypedMatcher M,
 /// could write:
 /// \code
 ///   auto R = makeRule(callExpr(callee(functionDecl(hasName("foo",
-///change(text("bar()")));
+///changeTo(cat("bar()")));
 ///   AddInclude(R, "path/to/bar_header.h");
 ///   AddInclude(R, "vector", IncludeFormat::Angled);
 /// \endcode
@@ -190,28 +190,36 @@ void addInclude(RewriteRule &Rule, llvm::StringRef Header,
 RewriteRule applyFirst(ArrayRef Rules);
 
 /// Replaces a portion of the source text with \p Replacement.
-ASTEdit change(RangeSelector Target, TextGenerator Replacement);
+ASTEdit changeTo(RangeSelector Target, TextGenerator Replacement);
+/// DEPRECATED: use \c changeTo.
+inline ASTEdit change(RangeSelector Target, TextGenerator Replacement) {
+  return changeTo(std::move(Target), std::move(Replacement));
+}
 
 /// Replaces the entirety of a RewriteRule's match with \p Replacement.  For
 /// example, to replace a function call, one could write:
 /// \code
 ///   makeRule(callExpr(callee(functionDecl(hasName("foo",
-///change(text("bar()")))
+///changeTo(cat("bar()")))
 /// \endcode
+inline ASTEdit changeTo(TextGenerator Replacement) {
+  return changeTo(node(RewriteRule::RootID), std::move(Replacement));
+}
+/// DEPRECATED: use \c changeTo.
 inline ASTEdit change(TextGenerator Replacement) {
-  return change(node(RewriteRule::RootID), std::move(Replacement));
+  return changeTo(std::move(Replacement));
 }
 
 /// Inserts \p Replacement before \p S, leaving the source selected by \S
 /// unchanged.
 inline ASTEdit insertBefore(RangeSelector S, TextGenerator Replacement) {
-  return change(before(std::move(S)), std::move(Replacement));
+  return changeTo(before(std::move(S)), std::move(Replacement));
 }
 
 /// Inserts \p Replacement after \p S, leaving the source selected by \S
 /// unchanged.
 inline ASTEdit insertAfter(RangeSelector S, TextGenerator Replacement) {
-  return change(after(std::move(S)), std::move(Replacement));
+  return changeTo(after(std::move(S)), std::move(Replacement));
 }
 
 /// Removes the source selected by \p S.

diff  --git a/clang/include/clang/Tooling/Transformer/Stencil.h 
b/clang/include/clang/Tooling/Transformer/Stencil.h
index ca23a6355f81..5c1139875a19 100644
--- a/clang/include/clang/Tooling/Transformer/Stencil.h
+++ b/clang/include/clang/Tooling/Transformer/Stencil.h
@@ -108,9 +108,11 @@ template  Stencil cat(Ts &&... Parts) {
 // Functions for conveniently building stencils.
 //
 
+/// DEPRECATED: Use `cat` instead.
 /// \returns exactly the text provided.
 Stencil text(llvm::StringRef Text);
 
+/// DEPRECATED: Use `cat` instead.
 /// \returns the source corresponding to the selected range.
 Stencil selection(RangeSelector Selector);
 

diff  --git a/clang/unittests/Tooling/Trans

[PATCH] D69897: Add #pragma clang loop aligned

2019-11-06 Thread Happy via Phabricator via cfe-commits
m-happy created this revision.
m-happy added reviewers: hfinkel, DTharun, rscottmanley, Meinersbur.
m-happy added a project: clang.
Herald added subscribers: cfe-commits, zzheng.

This patch adds functionality '#pragma clang loop aligned'. The load/store 
access in for loop following the '#pragma clang loop aligned' uses 32 bit for 
align access.

  #pragma clang loop aligned(enable)
  for(){

  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69897

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

Index: clang/test/Parser/pragma-unroll-and-jam.cpp
===
--- clang/test/Parser/pragma-unroll-and-jam.cpp
+++ clang/test/Parser/pragma-unroll-and-jam.cpp
@@ -67,7 +67,7 @@
   }
 
 // pragma clang unroll_and_jam is disabled for the moment
-/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, or distribute}} */ #pragma clang loop unroll_and_jam(4)
+/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, aligned, or distribute}} */ #pragma clang loop unroll_and_jam(4)
   for (int i = 0; i < Length; i++) {
 for (int j = 0; j < Length; j++) {
   List[i * Length + j] = Value;
Index: clang/test/Parser/pragma-loop.cpp
===
--- clang/test/Parser/pragma-loop.cpp
+++ clang/test/Parser/pragma-loop.cpp
@@ -82,6 +82,7 @@
 #pragma clang loop vectorize(enable)
 #pragma clang loop interleave(enable)
 #pragma clang loop vectorize_predicate(enable)
+#pragma clagn loop aligned(enable)
 #pragma clang loop unroll(full)
   while (i + 1 < Length) {
 List[i] = i;
@@ -97,6 +98,7 @@
 #pragma clang loop vectorize(disable)
 #pragma clang loop interleave(disable)
 #pragma clang loop vectorize_predicate(disable)
+#pragma clang loop aligned(disable)
 #pragma clang loop unroll(disable)
   while (i - 1 < Length) {
 List[i] = i;
@@ -113,7 +115,7 @@
   }
 
   int VList[Length];
-#pragma clang loop vectorize(disable) interleave(disable) unroll(disable) vectorize_predicate(disable)
+#pragma clang loop vectorize(disable) interleave(disable) unroll(disable) vectorize_predicate(disable) aligned(disable)
   for (int j : VList) {
 VList[j] = List[j];
   }
@@ -133,12 +135,14 @@
 /* expected-error {{expected '('}} */ #pragma clang loop vectorize
 /* expected-error {{expected '('}} */ #pragma clang loop interleave
 /* expected-error {{expected '('}} */ #pragma clang loop vectorize_predicate
+/* expected-error {{expected '('}} */ #pragma clang loop aligned
 /* expected-error {{expected '('}} */ #pragma clang loop unroll
 /* expected-error {{expected '('}} */ #pragma clang loop distribute
 
 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize(enable
 /* expected-error {{expected ')'}} */ #pragma clang loop interleave(enable
 /* expected-error {{expected ')'}} */ #pragma clang loop vectorize_predicate(enable
+/* expected-error {{expected ')'}} */ #pragma clang loop aligned(enable
 /* expected-error {{expected ')'}} */ #pragma clang loop unroll(full
 /* expected-error {{expected ')'}} */ #pragma clang loop distribute(enable
 
@@ -151,7 +155,7 @@
 /* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll()
 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute()
 
-/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, or distribute}} */ #pragma clang loop
+/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval, vectorize_predicate, aligned, or distribute}} */ #pragma clang loop
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkeyword(enable)
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop vectorize(enable) badkeyword(4)
@@ -252,6 +256,9 @@
 #pragma clang loop vectorize_predicate(enable)
 /* expected-error@+1 {{duplicate directives 'vectorize_predicate(enable)' and 'vectorize_predicate(disable)'}} */

[clang] 6c683aa - [libTooling] Fix breakage from change #84922

2019-11-06 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2019-11-06T11:31:35-05:00
New Revision: 6c683aa8d7d9dcda30b2a9eb42b43cbce5c645b8

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

LOG: [libTooling] Fix breakage from change #84922

Added: 


Modified: 
clang/lib/Tooling/Transformer/RewriteRule.cpp
clang/unittests/Tooling/TransformerTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Transformer/RewriteRule.cpp 
b/clang/lib/Tooling/Transformer/RewriteRule.cpp
index 6fa558f7b2ee..b96b5eeabad0 100644
--- a/clang/lib/Tooling/Transformer/RewriteRule.cpp
+++ b/clang/lib/Tooling/Transformer/RewriteRule.cpp
@@ -54,7 +54,7 @@ transformer::detail::translateEdits(const MatchResult &Result,
   return Transformations;
 }
 
-ASTEdit transformer::change(RangeSelector S, TextGenerator Replacement) {
+ASTEdit transformer::changeTo(RangeSelector S, TextGenerator Replacement) {
   ASTEdit E;
   E.TargetRange = std::move(S);
   E.Replacement = std::move(Replacement);

diff  --git a/clang/unittests/Tooling/TransformerTest.cpp 
b/clang/unittests/Tooling/TransformerTest.cpp
index ddfa00187d2c..c99bf974f88e 100644
--- a/clang/unittests/Tooling/TransformerTest.cpp
+++ b/clang/unittests/Tooling/TransformerTest.cpp
@@ -8,8 +8,9 @@
 
 #include "clang/Tooling/Transformer/Transformer.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Tooling/Transformer/RangeSelector.h"
 #include "clang/Tooling/Tooling.h"
+#include "clang/Tooling/Transformer/RangeSelector.h"
+#include "clang/Tooling/Transformer/Stencil.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
@@ -20,6 +21,8 @@ using namespace tooling;
 using namespace ast_matchers;
 namespace {
 using ::testing::IsEmpty;
+using transformer::cat;
+using transformer::changeTo;
 using transformer::RewriteRule;
 
 constexpr char KHeaderContents[] = R"cc(



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


[libunwind] 049f94a - Revert "build: explicitly set the linker language for unwind"

2019-11-06 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2019-11-06T08:34:13-08:00
New Revision: 049f94af487fc8be704f8740e2d2946ac5c6efc9

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

LOG: Revert "build: explicitly set the linker language for unwind"

This reverts commit 6db7a5cd7c800a588e94ce5c1ef24ae4d60ecdd3.
This adversely impacted the NetBSD libc++ bot for some reason, reverting
while investigating.

Added: 


Modified: 
libunwind/src/CMakeLists.txt

Removed: 




diff  --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 1ecda26406b1..ed20ff0015f4 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -127,8 +127,6 @@ if (LIBUNWIND_ENABLE_SHARED)
 "${LIBUNWIND_COMPILE_FLAGS}"
   LINK_FLAGS
 "${LIBUNWIND_LINK_FLAGS}"
-  LINKER_LANGUAGE
-C
   OUTPUT_NAME
 "unwind"
   VERSION



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


[PATCH] D69897: Add #pragma clang loop aligned

2019-11-06 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:3135
+
+This predicates all the array references inside the loop to be aligned. The 
aligned access to them can increase fetch time and increase the performance. 
+

What does this actually mean, in the end?
Will it assume that whatever alignment is required
for whatever vectorization width chosen,
is the actual alignment?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69897



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


[PATCH] D69896: [libTooling] Small changes in Transformer API.

2019-11-06 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Build breakage fixed in commit  "6c683aa8d7d 
 
[libTooling] Fix breakage from change #84922"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69896



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


[PATCH] D69781: [analyzer] Add test directory for scan-build

2019-11-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Also, you probably need to make clang/test/CMakeLists.txt depend on the install 
target, to make sure scan-build is in bin/.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69781



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


[PATCH] D69810: [OpenCL] Fix address space for base method call (PR43145)

2019-11-06 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh marked an inline comment as done.
svenvh added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:4091
+V = Builder.CreatePointerBitCastOrAddrSpaceCast(
+V, IRFuncTy->getParamType(FirstIRArg));
+  else

@Anastasia pointed out that the AST might not be correct to begin with, which 
could cause us to fail here.

```
| `-MemberExpr 0x558af2c0  '' 
.getRef 0x558a4008
|   `-ImplicitCastExpr 0x558af310  '__generic B2' lvalue 

| `-DeclRefExpr 0x558af2a0  'Derived' lvalue Var 
0x558ab290 'd' 'Derived'
```

The question is whether it's fine for the `UncheckedDerivedToBase 
ImplicitCastExpr` to cast from `private` to `__generic`; or do we need another 
`AddrSpaceConversion ImplicitCastExpr` node perhaps?


Repository:
  rC Clang

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

https://reviews.llvm.org/D69810



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


[PATCH] D69204: [OpenMP 5.0] - Extend defaultmap

2019-11-06 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen marked 2 inline comments as done.
cchen added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1967
   (DSAStack->isForceCaptureByReferenceInTargetExecutable() &&
!Ty->isAnyPointerType()) ||
   !Ty->isScalarType() ||

ABataev wrote:
> ABataev wrote:
> > Seems to me, you're missing additional checks for pointers here.
> Not done
I think I check for `pointer` in line 1897-1898 or I could just misunderstand 
what you are saying.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:4374
+  case DMIB_unspecified:
+return OMPC_MAP_tofrom;
+  }

ABataev wrote:
> `OMPC_MAP_tofrom` must be returned only for `DMIB_tofrom`, for others, it 
> must be `llvm_unreachable()`
For DMIB_firstprivate, I think you are right, it should be unreachable, 
however, for DMIB_default and DMIB_unspecified, they are definitely reachable 
in `ActOnOpenMPExecutableDirective`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69204



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


[PATCH] D69204: [OpenMP 5.0] - Extend defaultmap

2019-11-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:4374
+  case DMIB_unspecified:
+return OMPC_MAP_tofrom;
+  }

cchen wrote:
> ABataev wrote:
> > `OMPC_MAP_tofrom` must be returned only for `DMIB_tofrom`, for others, it 
> > must be `llvm_unreachable()`
> For DMIB_firstprivate, I think you are right, it should be unreachable, 
> however, for DMIB_default and DMIB_unspecified, they are definitely reachable 
> in `ActOnOpenMPExecutableDirective`.
Then this function is not correct because for scalars default is not tofrom.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69204



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


[PATCH] D69897: Add #pragma clang loop aligned

2019-11-06 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:3135
+
+This predicates all the array references inside the loop to be aligned. The 
aligned access to them can increase fetch time and increase the performance. 
+

lebedev.ri wrote:
> What does this actually mean, in the end?
> Will it assume that whatever alignment is required
> for whatever vectorization width chosen,
> is the actual alignment?
Also, just arrays, or also pointers?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69897



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


[PATCH] D69901: [OpenCL] Add integer functions to builtin functions

2019-11-06 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: Anastasia, Nicola, Pierre.
Herald added subscribers: cfe-commits, kristina, yaxunl.
Herald added a project: clang.

This patch adds the integer builtin functions from the OpenCL C
specification.


Repository:
  rC Clang

https://reviews.llvm.org/D69901

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -20,18 +20,19 @@
 
 // Provide typedefs when invoking clang without -finclude-default-header.
 #ifdef NO_HEADER
+typedef unsigned char uchar;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+typedef unsigned short ushort;
+typedef __SIZE_TYPE__ size_t;
 typedef char char2 __attribute__((ext_vector_type(2)));
 typedef char char4 __attribute__((ext_vector_type(4)));
+typedef uchar uchar4 __attribute__((ext_vector_type(4)));
 typedef float float4 __attribute__((ext_vector_type(4)));
 typedef half half4 __attribute__((ext_vector_type(4)));
 typedef int int2 __attribute__((ext_vector_type(2)));
 typedef int int4 __attribute__((ext_vector_type(4)));
 typedef long long2 __attribute__((ext_vector_type(2)));
-typedef unsigned char uchar;
-typedef unsigned int uint;
-typedef unsigned long ulong;
-typedef unsigned short ushort;
-typedef __SIZE_TYPE__ size_t;
 #endif
 
 kernel void test_pointers(volatile global void *global_p, global const int4 *a) {
@@ -61,6 +62,8 @@
 char4 test_int(char c, char4 c4) {
   char m = max(c, c);
   char4 m4 = max(c4, c4);
+  uchar4 abs1 = abs(c4);
+  uchar4 abs2 = abs(abs1);
   return max(c4, c);
 }
 
Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -279,6 +279,11 @@
 def TLAll   : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
 def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
 
+// All unsigned integer types twice, to facilitate unsigned return types for e.g.
+// uchar abs(char) and
+// uchar abs(uchar).
+def TLAllUIntsTwice : TypeList<"TLAllUIntsTwice", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
+
 def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
 
 // GenType definitions for multiple base types (e.g. all floating point types,
@@ -290,6 +295,8 @@
 def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
 def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
 def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
+// All integer to unsigned
+def AI2UGenTypeN   : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
 // Float
 def FGenTypeN  : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
 
@@ -466,6 +473,61 @@
   def : Builtin;
 }
 
+//
+// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
+// --- Table 10 ---
+// --- 1 argument ---
+foreach name = ["abs"] in {
+  def : Builtin;
+}
+foreach name = ["clz", "popcount"] in {
+  def : Builtin;
+}
+let MinVersion = CL20 in {
+  foreach name = ["ctz"] in {
+def : Builtin;
+  }
+}
+
+// --- 2 arguments ---
+foreach name = ["abs_diff"] in {
+  def : Builtin;
+}
+foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
+  def : Builtin;
+}
+foreach name = ["max", "min"] in {
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["upsample"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+
+// --- 3 arguments ---
+foreach name = ["clamp"] in {
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["mad_hi", "mad_sat"] in {
+  def : Builtin;
+}
+
+// --- Table 11 ---
+foreach name = ["mad24"] in {
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["mul24"] in {
+  def : Builtin;
+  def : Builtin;
+}
+
 //
 // OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
 // OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
@@ -655,12 +717,6 @@
   }
 }
 
-// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
-foreach name = ["max", "min"] in {
-  def : Builtin;
-  def : Builtin;
-}
-
 //
 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
 // OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69903: [Basic] Introduce PODSourceLocation, NFCI

2019-11-06 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: faisalv, rsmith, aprantl, JDevlieghere.
Herald added subscribers: cfe-commits, jfb, arphaman.
Herald added a project: clang.
miyuki added a parent revision: D69840: [Basic] Make SourceLocation usable as 
key in hash maps, NFCI.
miyuki edited parent revisions, added: D69844: [Basic] Integrate SourceLocation 
with FoldingSet, NFCI; removed: D69840: [Basic] Make SourceLocation usable as 
key in hash maps, NFCI.

The goal of this change is to further reduce the number of cases when
the internal representation of SourceLocation is accessed directly.

The change adds a new class PODSourceLocation and replaces 'unsigned'
with 'PODSourceLocation' where possible. The PODSourceLocation class
holds the same information as SourceLocation, but it is a POD type,
hence it can be used in contexts where SourceLocation cannot be used
(e.g. unions with implicit default constructors).

SourceLocation objects can be converted to PODSourceLocation and
constructed from PODSourceLocation using the corresponding helpers
getPOD and getFromPOD.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69903

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/AST/DeclarationName.h
  clang/include/clang/AST/DependentDiagnostic.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/Basic/SourceLocation.h
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Lex/Token.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Designator.h
  clang/include/clang/Sema/Initialization.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclObjC.cpp
  clang/lib/AST/DeclarationName.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/NestedNameSpecifier.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/tools/clang-refactor/TestSupport.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3251,9 +3251,9 @@
 Pieces.push_back(*TemplateArgsLoc);
 
   if (Kind == DeclarationName::CXXOperatorName) {
-Pieces.push_back(SourceLocation::getFromRawEncoding(
+Pieces.push_back(SourceLocation::getFromPOD(
NI.getInfo().CXXOperatorName.BeginOpNameLoc));
-Pieces.push_back(SourceLocation::getFromRawEncoding(
+Pieces.push_back(SourceLocation::getFromPOD(
NI.getInfo().CXXOperatorName.EndOpNameLoc));
   }
   
Index: clang/tools/clang-refactor/TestSupport.cpp
===
--- clang/tools/clang-refactor/TestSupport.cpp
+++ clang/tools/clang-refactor/TestSupport.cpp
@@ -312,7 +312,9 @@
   LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
   LangOpts.CPlusPlus11 = 1;
-  Lexer Lex(SourceLocation::getFromRawEncoding(0), LangOpts, Source.begin(),
+  PODSourceLocation BeginLoc;
+  BeginLoc.clear();
+  Lexer Lex(SourceLocation::getFromPOD(BeginLoc), LangOpts, Source.begin(),
 Source.begin(), Source.end());
   Lex.SetCommentRetentionState(true);
   Token Tok;
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -5831,14 +5831,14 @@
 break;
 
   case DeclarationName::CXXOperatorName:
-AddSourceLocation(SourceLocation::getFromRawEncoding(
+AddSourceLocation(SourceLocation::getFromPOD(
 DNLoc.CXXOperatorName.BeginOpNameLoc));
 AddSourceLocation(
-SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc));
+SourceLocation::getFromPOD(DNLoc.CXXOperatorName.EndOpNameLoc));
 break;
 
   case DeclarationName::CXXLiteralOperatorName:
-AddSourceLocation(SourceLocation::getFromRawEncoding(
+AddSourceLocation(SourceLocation::getFromPOD(
 DNLoc.CXXLiteralOperatorName.OpNameLoc));
 break;
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -9170,14 +9170,14 @@
 
   case DeclarationName::CXXOperatorName:
 DNLoc.CXXOperatorName.BeginOpNameLoc
-= ReadSourceLocation(F, Record, Idx).getRawEncoding();
+= ReadSourceLocation(F, Record, Idx).getPOD();
 DNLoc.CXXOperatorName.EndOpNameLoc
-= ReadSourceLocation(F, Record, Idx).getRawEncoding();
+= ReadSourceLocation(F, Record, Idx).getPOD();
 break;
 
   case DeclarationName::CXXLiteralOperatorName:
 DNLoc

[PATCH] D69822: [clang] Add new -fdebug-default-version flag.

2019-11-06 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Just a couple of typos, and I'm happy.  I agree with the other reviewers on the 
last needed test tweaks.




Comment at: clang/include/clang/Driver/Options.td:1955
   Flags<[CC1Option]>;
+def fdebug_default_version: Joined<["-"], "fdebug-default-version=">, 
Group, HelpText<"Default DWARF version to use, if a -g option caused 
DWARF debug info to be produced.">;
 def fdebug_prefix_map_EQ

HelpText does not want a final period.



Comment at: clang/test/Driver/debug-default-version.c:10
+// The -isysroot is used as a hack to avoid LIT messing with the SDKROOT
+// environment variable which indirecty overrides the version in the target
+// triple used here.

indirectly


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

https://reviews.llvm.org/D69822



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


[clang] 7681435 - [clang-format] Assert that filenames are not empty

2019-11-06 Thread via cfe-commits

Author: paulhoad
Date: 2019-11-06T17:25:17Z
New Revision: 7681435de148cf7a1c7db1b0daba0497630989d2

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

LOG: [clang-format] Assert that filenames are not empty

Summary:
Adds asserts to catch empty filenames, which otherwise will cause a crash in 
SourceManager.
The clang-format tool now outputs an error if an empty filename is used.
Fixes bug: 34667

Reviewers: krasimir, djasper, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Patch by: @jr

Tags: #clang-format, #clang

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

Added: 


Modified: 
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index db00d41d0351..8a2ec2dde03b 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -390,6 +390,10 @@ static bool format(StringRef FileName) {
   if (fillRanges(Code.get(), Ranges))
 return true;
   StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
+  if (AssumedFileName.empty()) {
+llvm::errs() << "error: empty filenames are not allowed\n";
+return true;
+  }
 
   llvm::Expected FormatStyle =
   getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());



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


[PATCH] D69822: [clang] Add new -fdebug-default-version flag.

2019-11-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/debug-default-version.c:66
+// NOCODEVIEW-NOT: "-gcodeview"
+// NODWARF-NOT: "-dwarf-version="
+// NODWARF-NOT: "-dwarf-version="

This is not correct. I suppose this to be `"-dwarf-version=`.

The pattern `"-dwarf-version="` does not match `"-dwarf-version=5"`


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

https://reviews.llvm.org/D69822



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


[PATCH] D69598: Work on cleaning up denormal mode handling

2019-11-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm marked an inline comment as done.
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:1736-1737
+if (CodeGenOpts.FPSubnormalMode != llvm::SubnormalMode::Invalid)
+  FuncAttrs.addAttribute("denormal-fp-math",
+ 
llvm::subnormalModeName(CodeGenOpts.FPSubnormalMode));
 

spatel wrote:
> arsenm wrote:
> > spatel wrote:
> > > Do you plan to change the attribute string from "denormal" to "subnormal" 
> > > as part of upgrading it to work per-FP-type? Would we need to 
> > > auto-upgrade old IR as part of making the string consistent with the code?
> > > 
> > > Can we stash the attribute string name inside a getter function in the 
> > > new ADT file, so clang and LLVM have a common source of truth for the 
> > > attribute name?
> > I'm considering it, but at the moment I'm trying to avoid changes. The next 
> > step I'm working on is adding denormal-fp-math-f32 (or maybe 
> > subnormal-fp-math-f32), which will co-exist and override the current 
> > attribute if the type matches
> I think it would be better to not change the vocabulary incrementally then. 
> Ie, keep everything "denormal" in this patch, and then universally change the 
> terminology to "subnormal" in one step. That way we won't have any 
> inconsistency/confusion between the attribute name and the code.
In the follow up patch, the new attribute uses the old denormal  name. The 
clang option handling maintains the old name to match the flag, but the new 
internal  enums and functions use the subnormal name. Is that a reasonable 
state? I don’t want to spread the old name through the new utilities, but also 
don’t want to have to auto upgrade bitcode for a name change 


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

https://reviews.llvm.org/D69598



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


[PATCH] D56345: [clang-format] Assert that filenames are not empty

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7681435de148: [clang-format] Assert that filenames are not 
empty (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D56345

Files:
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -390,6 +390,10 @@
   if (fillRanges(Code.get(), Ranges))
 return true;
   StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
+  if (AssumedFileName.empty()) {
+llvm::errs() << "error: empty filenames are not allowed\n";
+return true;
+  }
 
   llvm::Expected FormatStyle =
   getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -390,6 +390,10 @@
   if (fillRanges(Code.get(), Ranges))
 return true;
   StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
+  if (AssumedFileName.empty()) {
+llvm::errs() << "error: empty filenames are not allowed\n";
+return true;
+  }
 
   llvm::Expected FormatStyle =
   getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3ddac7e - [clang-format] [RELAND] Remove the dependency on frontend

2019-11-06 Thread via cfe-commits

Author: paulhoad
Date: 2019-11-06T17:33:37Z
New Revision: 3ddac7e563633632d4a3e673f3224ee66e1a717e

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

LOG: [clang-format] [RELAND] Remove the dependency on frontend

Summary: relanding {D68969} after it failed UBSAN build caused by the passing 
of an invalid SMLoc() (nullptr)

Reviewers: thakis, vlad.tsyrklevich, klimek, mitchell-stellar

Reviewed By: thakis

Subscribers: merge_guards_bot, mgorny, cfe-commits

Tags: #clang-format, #clang

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

Added: 


Modified: 
clang/tools/clang-format/CMakeLists.txt
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/tools/clang-format/CMakeLists.txt 
b/clang/tools/clang-format/CMakeLists.txt
index 28ac4fb5913e..35ecdb11253c 100644
--- a/clang/tools/clang-format/CMakeLists.txt
+++ b/clang/tools/clang-format/CMakeLists.txt
@@ -7,7 +7,6 @@ add_clang_tool(clang-format
 set(CLANG_FORMAT_LIB_DEPS
   clangBasic
   clangFormat
-  clangFrontend
   clangRewrite
   clangToolingCore
   )

diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 8a2ec2dde03b..aa6890ebff3d 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -18,7 +18,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/Format/Format.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
@@ -300,12 +299,9 @@ emitReplacementWarnings(const Replacements &Replaces, 
StringRef AssumedFileName,
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
   DiagOpts->ShowColors = (ShowColors && !NoShowColors);
 
-  TextDiagnosticPrinter *DiagsBuffer =
-  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts, false);
-
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
   IntrusiveRefCntPtr Diags(
-  new DiagnosticsEngine(DiagID, &*DiagOpts, DiagsBuffer));
+  new DiagnosticsEngine(DiagID, &*DiagOpts));
 
   IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
@@ -314,24 +310,41 @@ emitReplacementWarnings(const Replacements &Replaces, 
StringRef AssumedFileName,
   FileID FileID = createInMemoryFile(AssumedFileName, Code.get(), Sources,
  Files, InMemoryFileSystem.get());
 
-  const unsigned ID = Diags->getCustomDiagID(
-  WarningsAsErrors ? clang::DiagnosticsEngine::Error
-   : clang::DiagnosticsEngine::Warning,
-  "code should be clang-formatted [-Wclang-format-violations]");
+  FileManager &FileMgr = Sources.getFileManager();
+  llvm::ErrorOr FileEntryPtr =
+  FileMgr.getFile(AssumedFileName);
 
   unsigned Errors = 0;
-  DiagsBuffer->BeginSourceFile(LangOptions(), nullptr);
   if (WarnFormat && !NoWarnFormat) {
+llvm::SourceMgr Mgr;
 for (const auto &R : Replaces) {
-  Diags->Report(
-  Sources.getLocForStartOfFile(FileID).getLocWithOffset(R.getOffset()),
-  ID);
+  PresumedLoc PLoc = Sources.getPresumedLoc(
+  
Sources.getLocForStartOfFile(FileID).getLocWithOffset(R.getOffset()));
+
+  SourceLocation LineBegin =
+  Sources.translateFileLineCol(FileEntryPtr.get(), PLoc.getLine(), 1);
+  SourceLocation NextLineBegin = Sources.translateFileLineCol(
+  FileEntryPtr.get(), PLoc.getLine() + 1, 1);
+
+  const char *StartBuf = Sources.getCharacterData(LineBegin);
+  const char *EndBuf = Sources.getCharacterData(NextLineBegin);
+
+  StringRef Line(StartBuf, (EndBuf - StartBuf) - 1);
+
+  SMDiagnostic Diag(
+  Mgr, SMLoc::getFromPointer(StartBuf), AssumedFileName,
+  PLoc.getLine(), PLoc.getColumn(),
+  WarningsAsErrors ? SourceMgr::DiagKind::DK_Error
+   : SourceMgr::DiagKind::DK_Warning,
+  "code should be clang-formatted [-Wclang-format-violations]", Line,
+  ArrayRef>());
+
+  Diag.print(nullptr, llvm::errs(), (ShowColors && !NoShowColors));
   Errors++;
   if (ErrorLimit && Errors >= ErrorLimit)
 break;
 }
   }
-  DiagsBuffer->EndSourceFile();
   return WarningsAsErrors;
 }
 



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


[PATCH] D38446: update comments in clang-format.py for python3 compatibility

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Do you need help landing this?


Repository:
  rC Clang

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

https://reviews.llvm.org/D38446



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


[PATCH] D69854: [clang-format] [RELAND] Remove the dependency on frontend

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay marked 5 inline comments as done.
MyDeveloperDay added inline comments.



Comment at: clang/tools/clang-format/ClangFormat.cpp:310
   SourceManager Sources(*Diags, Files);
   FileID FileID = createInMemoryFile(AssumedFileName, Code.get(), Sources,
  Files, InMemoryFileSystem.get());

thakis wrote:
> Maybe not for this change, but do you need all this machinery up here? 
> SMDiagnostics takes a pointer and a file name, so yu can just pass 
> Code->getBufferStart() + R.getOffset() for the pointer and you don't need the 
> FileManager, the SourceManager, createInMemoryFile(), the PresumedLoc, 
> translateFileLineCol.
> 
> You can either try to use SourceMgr::getLineAndColumn() or compute line/col 
> yourself -- either should be a lot less code than the current machinery here.
So I definitely agree here, I'm afraid I shamelessly copied this from 
elsewhere.. but I see there should be a better way, let me work on that 
separately and if its ok I'll send a later review your way.

For now let me reland the frontEnd removal, with your suggested change before.



Comment at: clang/tools/clang-format/ClangFormat.cpp:334
+  SMDiagnostic Diags(
+  llvm::SourceMgr(), SMLoc::getFromPointer(StartBuf), AssumedFileName,
+  PLoc.getLine(), PLoc.getColumn(),

thakis wrote:
> I think the idea is that you have a llvm::SourceMgr() hanging around (above 
> the loop or somewhere). SMDiagnostic stores a pointer to this argument, and 
> you pass in a temporary. The SourceMgr needs to outlive the Diags object. (In 
> practice, the pointer is not used by anything so it happens to work, but 
> having the object store a stale pointer seems like potential future trouble, 
> and it's easy to prevent -- just put the SourceMgr on the stack).
> 
> Also, probably "Diag", not "Diags"?
I made the suggested changes just prior to landing, hope that is ok.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69854



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


[PATCH] D68568: [clang-format] Make '.clang-format' variants finding a loop

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Do you need help landing this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68568



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


[PATCH] D69204: [OpenMP 5.0] - Extend defaultmap

2019-11-06 Thread Chi Chun Chen via Phabricator via cfe-commits
cchen marked an inline comment as done.
cchen added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:4374
+  case DMIB_unspecified:
+return OMPC_MAP_tofrom;
+  }

ABataev wrote:
> cchen wrote:
> > ABataev wrote:
> > > `OMPC_MAP_tofrom` must be returned only for `DMIB_tofrom`, for others, it 
> > > must be `llvm_unreachable()`
> > For DMIB_firstprivate, I think you are right, it should be unreachable, 
> > however, for DMIB_default and DMIB_unspecified, they are definitely 
> > reachable in `ActOnOpenMPExecutableDirective`.
> Then this function is not correct because for scalars default is not tofrom.
You are right, for scalar and pointer, the implicit behavior is firstprivate, 
so they are unreachable in this case, however, for aggregate, the implicit 
behavior is tofrom (I emit the .ll file for aggregate using the master branch 
and found that the maptype is 547).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69204



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


[PATCH] D69854: [clang-format] [RELAND] Remove the dependency on frontend

2019-11-06 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
MyDeveloperDay marked 2 inline comments as done.
Closed by commit rG3ddac7e56363: [clang-format] [RELAND] Remove the dependency 
on frontend (authored by MyDeveloperDay).

Changed prior to commit:
  https://reviews.llvm.org/D69854?vs=227899&id=228086#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69854

Files:
  clang/tools/clang-format/CMakeLists.txt
  clang/tools/clang-format/ClangFormat.cpp


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -18,7 +18,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/Format/Format.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
@@ -300,12 +299,9 @@
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
   DiagOpts->ShowColors = (ShowColors && !NoShowColors);
 
-  TextDiagnosticPrinter *DiagsBuffer =
-  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts, false);
-
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
   IntrusiveRefCntPtr Diags(
-  new DiagnosticsEngine(DiagID, &*DiagOpts, DiagsBuffer));
+  new DiagnosticsEngine(DiagID, &*DiagOpts));
 
   IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
@@ -314,24 +310,41 @@
   FileID FileID = createInMemoryFile(AssumedFileName, Code.get(), Sources,
  Files, InMemoryFileSystem.get());
 
-  const unsigned ID = Diags->getCustomDiagID(
-  WarningsAsErrors ? clang::DiagnosticsEngine::Error
-   : clang::DiagnosticsEngine::Warning,
-  "code should be clang-formatted [-Wclang-format-violations]");
+  FileManager &FileMgr = Sources.getFileManager();
+  llvm::ErrorOr FileEntryPtr =
+  FileMgr.getFile(AssumedFileName);
 
   unsigned Errors = 0;
-  DiagsBuffer->BeginSourceFile(LangOptions(), nullptr);
   if (WarnFormat && !NoWarnFormat) {
+llvm::SourceMgr Mgr;
 for (const auto &R : Replaces) {
-  Diags->Report(
-  Sources.getLocForStartOfFile(FileID).getLocWithOffset(R.getOffset()),
-  ID);
+  PresumedLoc PLoc = Sources.getPresumedLoc(
+  
Sources.getLocForStartOfFile(FileID).getLocWithOffset(R.getOffset()));
+
+  SourceLocation LineBegin =
+  Sources.translateFileLineCol(FileEntryPtr.get(), PLoc.getLine(), 1);
+  SourceLocation NextLineBegin = Sources.translateFileLineCol(
+  FileEntryPtr.get(), PLoc.getLine() + 1, 1);
+
+  const char *StartBuf = Sources.getCharacterData(LineBegin);
+  const char *EndBuf = Sources.getCharacterData(NextLineBegin);
+
+  StringRef Line(StartBuf, (EndBuf - StartBuf) - 1);
+
+  SMDiagnostic Diag(
+  Mgr, SMLoc::getFromPointer(StartBuf), AssumedFileName,
+  PLoc.getLine(), PLoc.getColumn(),
+  WarningsAsErrors ? SourceMgr::DiagKind::DK_Error
+   : SourceMgr::DiagKind::DK_Warning,
+  "code should be clang-formatted [-Wclang-format-violations]", Line,
+  ArrayRef>());
+
+  Diag.print(nullptr, llvm::errs(), (ShowColors && !NoShowColors));
   Errors++;
   if (ErrorLimit && Errors >= ErrorLimit)
 break;
 }
   }
-  DiagsBuffer->EndSourceFile();
   return WarningsAsErrors;
 }
 
Index: clang/tools/clang-format/CMakeLists.txt
===
--- clang/tools/clang-format/CMakeLists.txt
+++ clang/tools/clang-format/CMakeLists.txt
@@ -7,7 +7,6 @@
 set(CLANG_FORMAT_LIB_DEPS
   clangBasic
   clangFormat
-  clangFrontend
   clangRewrite
   clangToolingCore
   )


Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -18,7 +18,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Version.h"
 #include "clang/Format/Format.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
@@ -300,12 +299,9 @@
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
   DiagOpts->ShowColors = (ShowColors && !NoShowColors);
 
-  TextDiagnosticPrinter *DiagsBuffer =
-  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts, false);
-
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
   IntrusiveRefCntPtr Diags(
-  new DiagnosticsEngine(DiagID, &*DiagOpts, DiagsBuffer));
+  new DiagnosticsEngine(DiagID, &*DiagOpts));
 
   IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
@@ -314,24 +310,41 @@
   FileID Fi

[PATCH] D69498: IR: Invert convergent attribute handling

2019-11-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D69498#1731265 , @mehdi_amini wrote:

> In D69498#1727650 , @dexonsmith 
> wrote:
>
> > In D69498#1723606 , @rjmccall 
> > wrote:
> >
> > > Perhaps there should be a global metadata, or something in the 
> > > increasingly-misnamed "data layout" string, which says that convergence 
> > > is meaningful, and we should only add the attribute in 
> > > appropriately-annotated modules?
> >
> >
> > Just wanted to resurface these alternatives from John.  Given that some 
> > targets want a fundamentally different default from what most frontends 
> > expect, I think we ought to find some way to encode the difference.
>
>
> Just thought about a slight variation on this: what about adding a flag on 
> the datalayout (or a module flag) but not use it in the 
> transformations/analyses, instead use it only when creating Function by 
> always setting the `convergent` attribute when the flag is present? This 
> would require to always have a Module passed to the Function constructor 
> though (the C API already does, we would just need to update the C++ users).
>
> So creating a Function in a Module with this flag would have the convergent 
> attribute set on creation (can be unset explicitly).


This sounds almost too low level. The bitcode loading of a function shouldn’t 
be adding attributes to non-intrinsics, otherwise it’s changing the meaning of 
the program and not preserving the input


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

https://reviews.llvm.org/D69498



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


[PATCH] D69855: [clang-tidy] Fix llvm-namespace-comment for macro expansions

2019-11-06 Thread Marcin Twardak via Phabricator via cfe-commits
twardakm updated this revision to Diff 228088.
twardakm added a comment.

Remove unnecessary line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69855

Files:
  clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
  clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h
  clang-tools-extra/test/clang-tidy/checkers/llvm-namespace-comment.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvm-namespace-comment.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvm-namespace-comment.cpp
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s llvm-namespace-comment %t
+
+namespace n1 {
+namespace n2 {
+  void f();
+
+
+  // CHECK-MESSAGES: :[[@LINE+2]]:1: warning: namespace 'n2' not terminated with a closing comment [llvm-namespace-comment]
+  // CHECK-MESSAGES: :[[@LINE+1]]:2: warning: namespace 'n1' not terminated with a closing comment [llvm-namespace-comment]
+}}
+// CHECK-FIXES: } // namespace n2
+// CHECK-FIXES: } // namespace n1
+
+#define MACRO macro_expansion
+namespace MACRO {
+  void f();
+  // CHECK-MESSAGES: :[[@LINE+1]]:1: warning: namespace 'macro_expansion' not terminated with a closing comment [llvm-namespace-comment]
+}
+// CHECK-FIXES: } // namespace macro_expansion
+
+namespace MACRO {
+  void g();
+} // namespace MACRO
+
+namespace MACRO {
+  void h();
+} // namespace macro_expansion
Index: clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h
===
--- clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h
+++ clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h
@@ -26,6 +26,10 @@
   NamespaceCommentCheck(StringRef Name, ClangTidyContext *Context);
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+
+  void addMacro(const std::string &Name, const std::string &Value) noexcept;
 
 private:
   void storeOptions(ClangTidyOptions::OptionMap &Options) override;
@@ -34,6 +38,10 @@
   const unsigned ShortNamespaceLines;
   const unsigned SpacesBeforeComments;
   llvm::SmallVector Ends;
+
+  // Store macros to verify that warning is not thrown when namespace name is a
+  // preprocessed define
+  std::vector> Macros;
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -19,6 +19,44 @@
 namespace tidy {
 namespace readability {
 
+namespace {
+class NamespaceCommentPPCallbacks : public PPCallbacks {
+public:
+  NamespaceCommentPPCallbacks(Preprocessor *PP, NamespaceCommentCheck *Check)
+  : PP(PP), Check(Check) {}
+
+  void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) {
+// Record all defined macros. We store the whole token to compare names
+// later
+
+const MacroInfo *const MI = MD->getMacroInfo();
+
+if (MI->isFunctionLike())
+  return;
+
+std::string ValueBuffer;
+llvm::raw_string_ostream Value(ValueBuffer);
+
+SmallString<128> SpellingBuffer;
+bool First = true;
+for (const auto &T : MI->tokens()) {
+  if (!First && T.hasLeadingSpace())
+Value << ' ';
+
+  Value << PP->getSpelling(T, SpellingBuffer);
+  First = false;
+}
+
+Check->addMacro(MacroNameTok.getIdentifierInfo()->getName().str(),
+Value.str());
+  }
+
+private:
+  Preprocessor *PP;
+  NamespaceCommentCheck *Check;
+};
+} // namespace
+
 NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -40,6 +78,11 @@
 Finder->addMatcher(namespaceDecl().bind("namespace"), this);
 }
 
+void NamespaceCommentCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  PP->addPPCallbacks(std::make_unique(PP, this));
+}
+
 static bool locationsInSameFile(const SourceManager &Sources,
 SourceLocation Loc1, SourceLocation Loc2) {
   return Loc1.isFileID() && Loc2.isFileID() &&
@@ -65,6 +108,11 @@
   return Fix;
 }
 
+void NamespaceCommentCheck::addMacro(const std::string &Name,
+ const std::string &Value) noexcept {
+  Macros.emplace_back(Name, Value);
+}
+
 void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *ND = Result.Nodes.getNodeAs("namespace");
   const SourceManager &Sources = *Re

[PATCH] D69204: [OpenMP 5.0] - Extend defaultmap

2019-11-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:4374
+  case DMIB_unspecified:
+return OMPC_MAP_tofrom;
+  }

cchen wrote:
> ABataev wrote:
> > cchen wrote:
> > > ABataev wrote:
> > > > `OMPC_MAP_tofrom` must be returned only for `DMIB_tofrom`, for others, 
> > > > it must be `llvm_unreachable()`
> > > For DMIB_firstprivate, I think you are right, it should be unreachable, 
> > > however, for DMIB_default and DMIB_unspecified, they are definitely 
> > > reachable in `ActOnOpenMPExecutableDirective`.
> > Then this function is not correct because for scalars default is not tofrom.
> You are right, for scalar and pointer, the implicit behavior is firstprivate, 
> so they are unreachable in this case, however, for aggregate, the implicit 
> behavior is tofrom (I emit the .ll file for aggregate using the master branch 
> and found that the maptype is 547).
You need to add extra checks for scalars and pointers in this function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69204



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


[clang] ba73aad - [X86] Add 'mmx' to all CPUs that have a version of 'sse' and weren't already enabling '3dnow'

2019-11-06 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2019-11-06T10:02:40-08:00
New Revision: ba73aad4f64f52f2acb5394210ed829355b44383

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

LOG: [X86] Add 'mmx' to all CPUs that have a version of 'sse' and weren't 
already enabling '3dnow'

All SSE capable CPUs have MMX. 3dnow implicitly enables MMX.

We have code that detects if sse is enabled and implicitly enables
MMX unless -mno-mmx is passed. So in most cases we were already
enabling MMX if march passed a CPU that supported SSE.

The exception to this is if you pass -march for a cpu supports SSE
and also pass -mno-sse. We should still enable MMX since its part
of the CPU capability.

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp
clang/test/Preprocessor/x86_target_features.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 311ae6e17028..9ccc6d7945e9 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -131,13 +131,6 @@ bool X86TargetInfo::initFeatureMap(
   case CK_Lakemont:
 break;
 
-  case CK_PentiumMMX:
-  case CK_Pentium2:
-  case CK_K6:
-  case CK_WinChipC6:
-setFeatureEnabledImpl(Features, "mmx", true);
-break;
-
   case CK_Cooperlake:
 // CPX inherits all CLX features plus AVX512BF16
 setFeatureEnabledImpl(Features, "avx512bf16", true);
@@ -254,6 +247,12 @@ bool X86TargetInfo::initFeatureMap(
   case CK_C3_2:
 setFeatureEnabledImpl(Features, "sse", true);
 setFeatureEnabledImpl(Features, "fxsr", true);
+LLVM_FALLTHROUGH;
+  case CK_PentiumMMX:
+  case CK_Pentium2:
+  case CK_K6:
+  case CK_WinChipC6:
+setFeatureEnabledImpl(Features, "mmx", true);
 break;
 
   case CK_Tremont:
@@ -291,6 +290,7 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabledImpl(Features, "fxsr", true);
 setFeatureEnabledImpl(Features, "cx16", true);
 setFeatureEnabledImpl(Features, "sahf", true);
+setFeatureEnabledImpl(Features, "mmx", true);
 break;
 
   case CK_KNM:
@@ -321,6 +321,7 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabledImpl(Features, "xsave", true);
 setFeatureEnabledImpl(Features, "movbe", true);
 setFeatureEnabledImpl(Features, "sahf", true);
+setFeatureEnabledImpl(Features, "mmx", true);
 break;
 
   case CK_K6_2:
@@ -369,6 +370,7 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabledImpl(Features, "cx16", true);
 setFeatureEnabledImpl(Features, "fxsr", true);
 setFeatureEnabledImpl(Features, "sahf", true);
+setFeatureEnabledImpl(Features, "mmx", true);
 break;
 
   case CK_ZNVER2:
@@ -390,6 +392,7 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabledImpl(Features, "fsgsbase", true);
 setFeatureEnabledImpl(Features, "fxsr", true);
 setFeatureEnabledImpl(Features, "lzcnt", true);
+setFeatureEnabledImpl(Features, "mmx", true);
 setFeatureEnabledImpl(Features, "mwaitx", true);
 setFeatureEnabledImpl(Features, "movbe", true);
 setFeatureEnabledImpl(Features, "pclmul", true);
@@ -433,6 +436,7 @@ bool X86TargetInfo::initFeatureMap(
 setFeatureEnabledImpl(Features, "fxsr", true);
 setFeatureEnabledImpl(Features, "xsave", true);
 setFeatureEnabledImpl(Features, "sahf", true);
+setFeatureEnabledImpl(Features, "mmx", true);
 break;
   }
   if (!TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec))

diff  --git a/clang/test/Preprocessor/x86_target_features.c 
b/clang/test/Preprocessor/x86_target_features.c
index 290ce3bf1dcb..8d55c5d29e12 100644
--- a/clang/test/Preprocessor/x86_target_features.c
+++ b/clang/test/Preprocessor/x86_target_features.c
@@ -269,18 +269,26 @@
 
 // NOSSE42POPCNT: #define __POPCNT__ 1
 
-// RUN: %clang -target i386-unknown-unknown -march=atom -msse -x c -E -dM -o - 
%s | FileCheck -match-full-lines --check-prefix=SSEMMX %s
+// RUN: %clang -target i386-unknown-unknown -march=pentium -msse -x c -E -dM 
-o - %s | FileCheck -match-full-lines --check-prefix=SSEMMX %s
 
 // SSEMMX: #define __MMX__ 1
 
-// RUN: %clang -target i386-unknown-unknown -march=atom -msse -mno-sse -x c -E 
-dM -o - %s | FileCheck -match-full-lines --check-prefix=SSENOSSEMMX %s
+// RUN: %clang -target i386-unknown-unknown -march=pentium -msse -mno-sse -x c 
-E -dM -o - %s | FileCheck -match-full-lines --check-prefix=SSENOSSEMMX %s
 
 // SSENOSSEMMX-NOT: #define __MMX__ 1
 
-// RUN: %clang -target i386-unknown-unknown -march=atom -msse -mno-mmx -x c -E 
-dM -o - %s | FileCheck -match-full-lines --check-prefix=SSENOMMX %s
+// RUN: %clang -target i386-unknown-unknown -march=pentium -msse -mno-mmx -x c 
-E -dM -o - %s | FileCheck -match-full-lines --check-prefix=SSENOMMX %s
 
 // SSENOMMX-NOT: #define __MMX__ 1
 
+// RUN: %clang -target i386-unknown-unknown -march=

[PATCH] D69908: [OpenCL] Add geometric and relational builtin functions

2019-11-06 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: Anastasia, Nicola, Pierre.
Herald added subscribers: cfe-commits, kristina, yaxunl.
Herald added a reviewer: rengolin.
Herald added a project: clang.

Adds the geometric and relational builtin functions from the OpenCL C
specification.

Patch by Pierre Gondois and Sven van Haastregt.


Repository:
  rC Clang

https://reviews.llvm.org/D69908

Files:
  clang/lib/Sema/OpenCLBuiltins.td

Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -274,10 +274,13 @@
 def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
 def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
 def Vec1: IntList<"Vec1", [1]>;
+def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
 
 // Type lists.
 def TLAll   : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
 def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
+def TLSignedInts   : TypeList<"TLSignedInts", [Char, Short, Int, Long]>;
+def TLUnsignedInts : TypeList<"TLUnsignedInts", [UChar, UShort, UInt, ULong]>;
 
 // All unsigned integer types twice, to facilitate unsigned return types for e.g.
 // uchar abs(char) and
@@ -297,6 +300,10 @@
 def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
 // All integer to unsigned
 def AI2UGenTypeN   : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
+// Signed integer
+def SGenTypeN  : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
+// Unsigned integer
+def UGenTypeN  : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
 // Float
 def FGenTypeN  : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
 
@@ -313,6 +320,14 @@
   }
 }
 
+// GenType definitions for vec1234.
+foreach Type = [Float, Double, Half] in {
+  def "GenType" # Type # Vec1234 :
+  GenericType<"GenType" # Type # Vec1234,
+  TypeList<"GL" # Type.Name, [Type]>,
+  Vec1234>;
+}
+
 
 //===--===//
 // Definitions of OpenCL builtin functions
@@ -566,6 +581,91 @@
 }
 
 
+//
+// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
+// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
+// --- Table 13 ---
+// --- 1 argument ---
+foreach name = ["length"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["normalize"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["fast_length"] in {
+  def : Builtin;
+}
+foreach name = ["fast_normalize"] in {
+  def : Builtin;
+}
+
+// --- 2 arguments ---
+foreach name = ["cross"] in {
+  foreach VSize = [3, 4] in {
+def : Builtin, VectorType, VectorType], Attr.Const>;
+def : Builtin, VectorType, VectorType], Attr.Const>;
+def : Builtin, VectorType, VectorType], Attr.Const>;
+  }
+}
+foreach name = ["dot", "distance"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["fast_distance"] in {
+  def : Builtin;
+}
+
+
+//
+// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
+// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
+// --- Table 14 ---
+// --- 1 argument ---
+foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+foreach name = ["any", "all"] in {
+  def : Builtin;
+}
+
+// --- 2 arguments ---
+foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
+"isless", "islessequal", "islessgreater", "isordered",
+"isunordered"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+
+// --- 3 arguments ---
+foreach name = ["bitselect"] in {
+  def : Builtin;
+}
+foreach name = ["select"] in {
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+  def : Builtin;
+}
+
+
 // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
 // OpenCL Extension v1.1 s9.3.6 and s9.6.6, v1.2 s9.5.6, v2.0 s9.4.6, v2.0 s5.1.6 and 6.1.6 - Vector Data Load and Store Functions
 // --- Table 15 ---
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69813: [analyzer] CERTStrChecker: Model gets()

2019-11-06 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D69813#1734272 , @Charusso wrote:

> In D69813#1734193 , @Szelethus wrote:
>
> > Hmm, so this checker is rather a collection of CERT rule checkers, right? 
> > Shouldn't the checker name contain the actual rule name (STR31-C)? User 
> > interfacewise, I would much prefer smaller, leaner checkers than a big one 
> > with a lot of options, which are barely supported for end-users. I would 
> > expect a `cert` package to contain subpackages like `cert.str`, and checker 
> > names `cert.str.31StringSize`, or similar.
>
>
> It is the STR rules of CERT, nothing else. Most of the rules are tied 
> together, and that is why the checker needs to be designed as one checker at 
> first. I am not sure which part of the STR I will cover, so may when the 
> checker evolves and some functions does not need the same helper methods we 
> need to create new checkers. STR31 and STR32 are my projects which is like 
> one single project. Also I did not except the users to specify the rule 
> number, but this checker could be something like `cert.str.Termination`. 
> There is two floating-point CERT checkers inside the `insecureAPI` that is 
> why I have introduced the `cert` package, which will have three members, one 
> is that new checker. I think a new package is only necessary if it contains 
> at least two checkers.


Implementationwise that sounds wonderful, these rules are fairly similar to 
have a single checker responsible for them. The user interface however 
(enabling different CERT rules) they should probably be split up into separate 
checkers per rule, rather than options, wouldn't you agree? @NoQ? Also,  
`cert.str.Termination` sounds like a wonderful name, I don't insist on the rule 
number being present in it, but at the very least, it should be in the 
description.

>> Also, shouldn't we move related checkers from `security.insecureAPI` to 
>> `cert`? Or just mention the rule name in the description, and continue not 
>> having a  `cert` package?
> 
> We should not, they does not fit into CERT rules, but it has two CERT 
> floating-point checkers. The `cert` package should be well described with 
> CERT rules. I want to move the CERT checkers from it into that `cert` 
> package, and leave the rest.

I meant //related// ones only, though I didn't go through the checkers 
individually, it might just be the case that `insecureApi` doesn't implement 
any specific CERT rules :)


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

https://reviews.llvm.org/D69813



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


[PATCH] D69872: Improve modernize-avoid-bind to support more types of expressions

2019-11-06 Thread Zachary Turner via Phabricator via cfe-commits
zturner updated this revision to Diff 228093.
zturner added a comment.

Minor cleanup -- moved `isFixitSupported` logic to its own function.


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

https://reviews.llvm.org/D69872

Files:
  clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-avoid-bind.cpp
@@ -78,6 +78,39 @@
   // CHECK-FIXES: auto clj = [] { return C::add(1, 1); };
 }
 
+struct D {
+  void operator()(int x, int y) {}
+
+  void MemberFunction(int x) {}
+};
+
+void o() {
+  D d;
+  auto clj = std::bind(d, 1, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
+  // CHECK-FIXES: auto clj = std::bind(d, 1, 2);
+}
+
+void p() {
+  auto clj = std::bind(D{}, 1, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
+  // CHECK-FIXES: auto clj = std::bind(D{}, 1, 2);
+}
+
+void q() {
+  D *d;
+  auto clj = std::bind(*d, 1, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
+  // CHECK-FIXES: auto clj = std::bind(*d, 1, 2);
+}
+
+void r() {
+  D *d;
+  auto clj = std::bind(&D::MemberFunction, d, 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind
+  // CHECK-FIXES: auto clj = std::bind(&D::MemberFunction, d, 1);
+}
+
 // Let's fake a minimal std::function-like facility.
 namespace std {
 template 
Index: clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
@@ -120,41 +120,49 @@
   if (!getLangOpts().CPlusPlus14) // Need C++14 for generic lambdas.
 return;
 
-  Finder->addMatcher(
-  callExpr(
-  callee(namedDecl(hasName("::std::bind"))),
-  hasArgument(0, declRefExpr(to(functionDecl().bind("f"))).bind("ref")))
-  .bind("bind"),
-  this);
+  Finder->addMatcher(callExpr(callee(namedDecl(hasName("::std::bind"))),
+  hasArgument(0, expr().bind("ref")))
+ .bind("bind"),
+ this);
 }
 
-void AvoidBindCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *MatchedDecl = Result.Nodes.getNodeAs("bind");
-  auto Diag = diag(MatchedDecl->getBeginLoc(), "prefer a lambda to std::bind");
-
-  const auto Args = buildBindArguments(Result, MatchedDecl);
-
+static bool isFixitSupported(const Expr *Expr, ArrayRef Args) {
   // Do not attempt to create fixits for nested call expressions.
   // FIXME: Create lambda capture variables to capture output of calls.
   // NOTE: Supporting nested std::bind will be more difficult due to placeholder
   // sharing between outer and inner std:bind invocations.
   if (llvm::any_of(Args,
[](const BindArgument &B) { return B.Kind == BK_CallExpr; }))
-return;
+return false;
 
   // Do not attempt to create fixits when placeholders are reused.
   // Unused placeholders are supported by requiring C++14 generic lambdas.
   // FIXME: Support this case by deducing the common type.
   if (isPlaceHolderIndexRepeated(Args))
-return;
+return false;
+
+  if (const auto *DRE = llvm::dyn_cast(Expr)) {
+const auto *FD = llvm::dyn_cast_or_null(DRE->getDecl());
+// std::bind can support argument count mismatch between its arguments and
+// the bound function's arguments. Do not attempt to generate a fixit for
+// such cases.
+// FIXME: Support this case by creating unused lambda capture variables.
+if (FD && (FD->getNumParams() == Args.size()))
+  return true;
+  }
 
-  const auto *F = Result.Nodes.getNodeAs("f");
+  // Do not attempt to create fixits for generalized call expressions.
+  return false;
+}
+
+void AvoidBindCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("bind");
+  auto Diag = diag(MatchedDecl->getBeginLoc(), "prefer a lambda to std::bind");
+
+  const auto Args = buildBindArguments(Result, MatchedDecl);
 
-  // std::bind can support argument count mismatch between its arguments and the
-  // bound function's arguments. Do not attempt to generate a fixit for such
-  // cases.
-  // FIXME: Support this case by creating unused lambda capture variables.
-  if (F->getNumParams() != Args.size())
+  const auto *Ref = Result.Nodes.getNodeAs("ref");
+  if (!isFixitSupported(Ref, Args))
 return;
 
   std::string Buffer;
@@ -162,7 +170,6 @@
 
   bool HasCapturedArgument = llvm::any_of(
   Args, [](const BindArgument &B) { return B.Kind == BK_Other; });
-  const auto *Ref = Result.Nodes.ge

[PATCH] D69866: [clang-tools-extra] [cmake] Add install target for clangd-indexer

2019-11-06 Thread Mike Pozulp via Phabricator via cfe-commits
mmpozulp abandoned this revision.
mmpozulp added a comment.

I'm switching to using the background index, so I no longer need to run 
clangd-indexer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69866



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


[PATCH] D69853: [OpenMP][NFCI] Introduce llvm/IR/OpenMPConstants.h

2019-11-06 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert marked 5 inline comments as done.
jdoerfert added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:4011
   unsigned NamedModifiersNumber = 0;
-  SmallVector FoundNameModifiers(
-  OMPD_unknown + 1);
+  SmallVector
+  FoundNameModifiers(unsigned(OMPD_unknown) + 1);

Meinersbur wrote:
> ABataev wrote:
> > jdoerfert wrote:
> > > ABataev wrote:
> > > > jdoerfert wrote:
> > > > > ABataev wrote:
> > > > > > JonChesterfield wrote:
> > > > > > > I wonder if it would be worth wrapping the accesses to 
> > > > > > > FoundNameModifiers in functor that does the enum class to 
> > > > > > > unsigned conversion. E.g. a class instance that contains the 
> > > > > > > small vector and exposes operator[] that takes the enum class.
> > > > > > > 
> > > > > > > FoundNameModifiers[unsigned(val)] is quite a lot of line noise.
> > > > > > Why `map`? It can be represented as a simple c-style array without 
> > > > > > any problems.
> > > > > No, these are not enums that auto-convert to unsigned.
> > > > Convert them manually. Replacing the simple hash array with map does 
> > > > not look like a good solution.
> > > I feel this this is a micro optimization that will make the code less 
> > > maintainable and, as Jon noted, "FoundNameModifiers[unsigned(val)] is 
> > > quite a lot of line noise.". 
> > > Take a look at the first version and let me know if you want to go back 
> > > to that one for this part, if so, I can do that.
> > You already introduced special wrapper class in the same file, maybe you 
> > can reuse for implicit conversions?
> We are introducing an `EnumeratedArray` class in 
> https://reviews.llvm.org/D68827#change-XphX8PAWFr8V . It should reduce the 
> need for casting and `OpenMPDirectiveKindExWrapper`.
Arguably, the easiest and cleanest way is to use a `map` to *map directives to 
if clauses*.

The wrapper is in a different file but I can write another one for here.

EnumeratedArray could probably be used here, it is not in yet though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69853



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


[PATCH] D69878: Consoldiate internal denormal flushing controls

2019-11-06 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm marked an inline comment as done.
arsenm added inline comments.



Comment at: llvm/docs/LangRef.rst:1828-1831
+   be flushed to zero by standard floating point operations. It is not
+   mandated that flushing to zero occurs, but if a subnormal output is
+   flushed to zero, it must respect the sign mode. Not all targets
+   support all modes.

On second thought I think this may be too permissive. I think based on the use 
in DAGCombiner, that flushing of outputs is compulsory.


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

https://reviews.llvm.org/D69878



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


[clang] a8ccb48 - [X86] Add 'fxsr' feature to -march=pentium2 to match X86.td and gcc.

2019-11-06 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2019-11-06T10:27:53-08:00
New Revision: a8ccb48f697d3fbe85c593248ff1053fdf522a6e

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

LOG: [X86] Add 'fxsr' feature to -march=pentium2 to match X86.td and gcc.

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp
clang/test/Preprocessor/predefined-arch-macros.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 9ccc6d7945e9..51f2006ddbdc 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -246,10 +246,11 @@ bool X86TargetInfo::initFeatureMap(
   case CK_Pentium3:
   case CK_C3_2:
 setFeatureEnabledImpl(Features, "sse", true);
+LLVM_FALLTHROUGH;
+  case CK_Pentium2:
 setFeatureEnabledImpl(Features, "fxsr", true);
 LLVM_FALLTHROUGH;
   case CK_PentiumMMX:
-  case CK_Pentium2:
   case CK_K6:
   case CK_WinChipC6:
 setFeatureEnabledImpl(Features, "mmx", true);

diff  --git a/clang/test/Preprocessor/predefined-arch-macros.c 
b/clang/test/Preprocessor/predefined-arch-macros.c
index 95bea654fe22..ab36e98beb71 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -184,6 +184,7 @@
 // RUN: %clang -march=pentium2 -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_PENTIUM2_M32
+// CHECK_PENTIUM2_M32: #define __FXSR__ 1
 // CHECK_PENTIUM2_M32: #define __MMX__ 1
 // CHECK_PENTIUM2_M32: #define __i386 1
 // CHECK_PENTIUM2_M32: #define __i386__ 1



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


[libunwind] cbc872a - unwind: disable RTTI during the build of libunwind

2019-11-06 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2019-11-06T10:51:42-08:00
New Revision: cbc872a63f81ad9482bb288165af63d7444fa3ed

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

LOG: unwind: disable RTTI during the build of libunwind

Disable the type information emission for libunwind.  libunwind does not
use `dynamic_cast`.  This results in a smaller binary, and more
importantly, avoids the dependency on libc++abi.  This ensures that we
have complete symbol resolution of symbols on ELF targets without
linking to the C++ runtime support library.  This change avoids the
emission of a reference to `__si_class_type_info`.

Added: 


Modified: 
libunwind/src/CMakeLists.txt

Removed: 




diff  --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index ed20ff0015f4..2dab16afbdf9 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -111,6 +111,11 @@ set_property(SOURCE ${LIBUNWIND_C_SOURCES}
 # Build the shared library.
 if (LIBUNWIND_ENABLE_SHARED)
   add_library(unwind_shared SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
+  if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
+target_compile_options(unwind_shared PRIVATE /GR-)
+  else()
+target_compile_options(unwind_shared PRIVATE -fno-rtti)
+  endif()
   if(COMMAND llvm_setup_rpath)
 llvm_setup_rpath(unwind_shared)
   endif()
@@ -142,6 +147,11 @@ endif()
 # Build the static library.
 if (LIBUNWIND_ENABLE_STATIC)
   add_library(unwind_static STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
+  if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
+target_compile_options(unwind_static PRIVATE /GR-)
+  else()
+target_compile_options(unwind_static PRIVATE -fno-rtti)
+  endif()
   target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES})
   set_target_properties(unwind_static
 PROPERTIES



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


[PATCH] D69897: Add #pragma clang loop aligned

2019-11-06 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:3135
+
+This predicates all the array references inside the loop to be aligned. The 
aligned access to them can increase fetch time and increase the performance. 
+

hfinkel wrote:
> lebedev.ri wrote:
> > What does this actually mean, in the end?
> > Will it assume that whatever alignment is required
> > for whatever vectorization width chosen,
> > is the actual alignment?
> Also, just arrays, or also pointers?
> Currently, it is using 32 bit.

You'll need to use the preferred alignment of the element type.

> By pointers, if you mean pointers to arrays? Then Yes.

No, I mean pointers.

What do you intend for these cases:

  double A[Size], B[Size];

  void foo() {
  #pragma clang loop aligned
for (int i = 0; i < n; ++i) {
  A[i] = B[i] + 1;
}
  }

or this:

  void foo(double *A, double *B) {
  #pragma clang loop aligned
for (int i = 0; i < n; ++i) {
  A[i] = B[i] + 1;
}
  }

or this:

  void foo(double *A, double *B, double *C) {
  #pragma clang loop aligned
for (int i = 0; i < n; ++i) {
  A[i] = B[i] + *C + 1;
}
  }

or this:

  void foo(double *A, double *B) {
  #pragma clang loop aligned
for (int i = 0; i < n; ++i) {
  *A++ = *B++ + 1;
}
  }

what about arrays of structs?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69897



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


[PATCH] D69598: Work on cleaning up denormal mode handling

2019-11-06 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:1736-1737
+if (CodeGenOpts.FPSubnormalMode != llvm::SubnormalMode::Invalid)
+  FuncAttrs.addAttribute("denormal-fp-math",
+ 
llvm::subnormalModeName(CodeGenOpts.FPSubnormalMode));
 

arsenm wrote:
> spatel wrote:
> > arsenm wrote:
> > > spatel wrote:
> > > > Do you plan to change the attribute string from "denormal" to 
> > > > "subnormal" as part of upgrading it to work per-FP-type? Would we need 
> > > > to auto-upgrade old IR as part of making the string consistent with the 
> > > > code?
> > > > 
> > > > Can we stash the attribute string name inside a getter function in the 
> > > > new ADT file, so clang and LLVM have a common source of truth for the 
> > > > attribute name?
> > > I'm considering it, but at the moment I'm trying to avoid changes. The 
> > > next step I'm working on is adding denormal-fp-math-f32 (or maybe 
> > > subnormal-fp-math-f32), which will co-exist and override the current 
> > > attribute if the type matches
> > I think it would be better to not change the vocabulary incrementally then. 
> > Ie, keep everything "denormal" in this patch, and then universally change 
> > the terminology to "subnormal" in one step. That way we won't have any 
> > inconsistency/confusion between the attribute name and the code.
> In the follow up patch, the new attribute uses the old denormal  name. The 
> clang option handling maintains the old name to match the flag, but the new 
> internal  enums and functions use the subnormal name. Is that a reasonable 
> state? I don’t want to spread the old name through the new utilities, but 
> also don’t want to have to auto upgrade bitcode for a name change 
I'm not seeing the value in using "subnormal" relative to the confusion cost 
then. If we're always going to use the "denormal" flag in clang, then I'd 
prefer to have the code be consistent with that name. That's what I'd grep for, 
so I think that's what anyone viewing the code for the first time would expect 
too.


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

https://reviews.llvm.org/D69598



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


[PATCH] D69897: Add #pragma clang loop aligned

2019-11-06 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

Please see my comments in D69900  as well.

For the font-end side, I suggest the syntax `vectorize_assume_alignment(32)` 
instead. We also need to define what this assumes to be aligned. The first 
element of the array? Every array element? In an array-of-structs, the struct 
of the element that is accessed? Scalars?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69897



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


[PATCH] D69893: libunwind: Evaluating DWARF operation DW_OP_pick is broken

2019-11-06 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Is it tested?  Intuitively I would expect DW_OP_pick to be kind of an unusual 
operator, unlikely to be seen in the wild.


Repository:
  rUNW libunwind

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

https://reviews.llvm.org/D69893



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


[PATCH] D69897: Add #pragma clang loop aligned

2019-11-06 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D69897#1735961 , @Meinersbur wrote:

> Please see my comments in D69900  as well.
>
> For the font-end side, I suggest the syntax `vectorize_assume_alignment(32)` 
> instead. We also need to define what this assumes to be aligned. The first 
> element of the array? Every array element? In an array-of-structs, the struct 
> of the element that is accessed? Scalars?


It would be really best if this could just make use of 
`CodeGenFunction::EmitAlignmentAssumption()`,
else this is a heavy hammer with loose handle.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69897



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


[PATCH] D69638: [NFC] Add SUPPORT_PLUGINS to add_llvm_executable()

2019-11-06 Thread David Tenty via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6740a88dc18d: [NFC] Add SUPPORT_PLUGINS to 
add_llvm_executable() (authored by daltenty).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69638

Files:
  clang/tools/driver/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/tools/bugpoint/CMakeLists.txt
  llvm/tools/llc/CMakeLists.txt
  llvm/tools/opt/CMakeLists.txt

Index: llvm/tools/opt/CMakeLists.txt
===
--- llvm/tools/opt/CMakeLists.txt
+++ llvm/tools/opt/CMakeLists.txt
@@ -24,9 +24,6 @@
   Passes
   )
 
-# Support plugins.
-set(LLVM_NO_DEAD_STRIP 1)
-
 add_llvm_tool(opt
   AnalysisWrappers.cpp
   BreakpointPrinter.cpp
@@ -39,6 +36,7 @@
 
   DEPENDS
   intrinsics_gen
+  SUPPORT_PLUGINS
   )
 export_executable_symbols(opt)
 
Index: llvm/tools/llc/CMakeLists.txt
===
--- llvm/tools/llc/CMakeLists.txt
+++ llvm/tools/llc/CMakeLists.txt
@@ -19,13 +19,11 @@
   Vectorize
   )
 
-# Support plugins.
-set(LLVM_NO_DEAD_STRIP 1)
-
 add_llvm_tool(llc
   llc.cpp
 
   DEPENDS
   intrinsics_gen
+  SUPPORT_PLUGINS
   )
 export_executable_symbols(llc)
Index: llvm/tools/bugpoint/CMakeLists.txt
===
--- llvm/tools/bugpoint/CMakeLists.txt
+++ llvm/tools/bugpoint/CMakeLists.txt
@@ -21,9 +21,6 @@
   Vectorize
   )
 
-# Support plugins.
-set(LLVM_NO_DEAD_STRIP 1)
-
 add_llvm_tool(bugpoint
   BugDriver.cpp
   CrashDebugger.cpp
@@ -37,6 +34,7 @@
 
   DEPENDS
   intrinsics_gen
+  SUPPORT_PLUGINS
   )
 export_executable_symbols(bugpoint)
 
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -732,7 +732,7 @@
 
 macro(add_llvm_executable name)
   cmake_parse_arguments(ARG
-"DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH"
+"DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS"
 "ENTITLEMENTS;BUNDLE_PATH"
 "DEPENDS"
 ${ARGN})
@@ -782,6 +782,11 @@
   if(NOT LLVM_ENABLE_OBJLIB)
 llvm_update_compile_flags(${name})
   endif()
+
+  if (ARG_SUPPORT_PLUGINS)
+set(LLVM_NO_DEAD_STRIP On)
+  endif()
+
   add_link_opts( ${name} )
 
   # Do not add -Dname_EXPORTS to the command-line when building files in this
Index: clang/tools/driver/CMakeLists.txt
===
--- clang/tools/driver/CMakeLists.txt
+++ clang/tools/driver/CMakeLists.txt
@@ -19,10 +19,9 @@
 
 option(CLANG_PLUGIN_SUPPORT "Build clang with plugin support" ON)
 
-# Support plugins. This must be before add_clang_executable as it reads
-# LLVM_NO_DEAD_STRIP.
+# Support plugins.
 if(CLANG_PLUGIN_SUPPORT)
-  set(LLVM_NO_DEAD_STRIP 1)
+  set(support_plugins SUPPORT_PLUGINS)
 endif()
 
 if(NOT CLANG_BUILT_STANDALONE)
@@ -37,6 +36,7 @@
 
   DEPENDS
   ${tablegen_deps}
+  ${support_plugins}
   )
 
 clang_target_link_libraries(clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >