Re: [PATCH] D20150: clang-rename: fix renaming of field with implicit initializers

2016-05-12 Thread Miklos Vajna via cfe-commits
vmiklos added a comment.

Hi,

> Also: should we add a check that the token of the source location we find 
> actually has the old name?


Hmm, how do I get the token at a specific SourceLocation? The best I found so 
far is SourceManager::getBuffer(), but that looks more like looking up raw 
bytes from the source file at a location, not a token.

Thanks,

Miklos


Repository:
  rL LLVM

http://reviews.llvm.org/D20150



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


Re: [PATCH] D20150: clang-rename: fix renaming of field with implicit initializers

2016-05-12 Thread Manuel Klimek via cfe-commits
On Thu, May 12, 2016 at 9:22 AM Miklos Vajna  wrote:

> vmiklos added a comment.
>
> Hi,
>
> > Also: should we add a check that the token of the source location we
> find actually has the old name?
>
>
> Hmm, how do I get the token at a specific SourceLocation? The best I found
> so far is SourceManager::getBuffer(), but that looks more like looking up
> raw bytes from the source file at a location, not a token.
>

Usually you'll want Lexer::getSourceText; that also gets the bytes from the
source file, but that's also what we really want to check.


>
> Thanks,
>
> Miklos
>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D20150
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20197: [clang-tidy] Ignore using-declarations defined in marcro in misc-unused-using-decls checks.

2016-05-12 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.



Comment at: clang-tidy/misc/UnusedUsingDeclsCheck.cpp:38
@@ -37,1 +37,3 @@
 
+// Ignores using-declarations defined in macro.
+if (Result.SourceManager->isMacroBodyExpansion(TargetDecl->getLocStart()),

nit: "in a macro" or "in macros".


Comment at: clang-tidy/misc/UnusedUsingDeclsCheck.cpp:40
@@ +39,3 @@
+if (Result.SourceManager->isMacroBodyExpansion(TargetDecl->getLocStart()),
+Result.SourceManager->isMacroBodyExpansion(TargetDecl->getLocEnd())) {
+  return;

nit: remove braces


Repository:
  rL LLVM

http://reviews.llvm.org/D20197



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


Re: [PATCH] D20197: [clang-tidy] Ignore using-declarations defined in marcro in misc-unused-using-decls checks.

2016-05-12 Thread Daniel Jasper via cfe-commits
djasper added inline comments.


Comment at: clang-tidy/misc/UnusedUsingDeclsCheck.cpp:39
@@ +38,3 @@
+// Ignores using-declarations defined in macro.
+if (Result.SourceManager->isMacroBodyExpansion(TargetDecl->getLocStart()),
+Result.SourceManager->isMacroBodyExpansion(TargetDecl->getLocEnd())) {

Thinking some more, maybe just use TargetDecl->getLocation().isMacroID()?


Repository:
  rL LLVM

http://reviews.llvm.org/D20197



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


Re: [PATCH] D19156: [ms][dll] #27212: Generating of implicit special members should take into account MSVC compatibility version

2016-05-12 Thread Andrew V. Tischenko via cfe-commits
avt77 marked 2 inline comments as done.


Comment at: lib/Sema/SemaDeclCXX.cpp:4813
@@ +4812,3 @@
+// and move constructor, so don't attempt to import/export them if
+// we have a definition.
+auto *CXXC = dyn_cast(MD);

rnk wrote:
> Oh, so we were already doing this check. I don't see what's wrong with our 
> current behavior, though. We export a few more symbols than MSVC 2013, but 
> there's no ABI problem with that.
Yes, it's a question about binary compatibility only


Comment at: lib/Sema/SemaDeclCXX.cpp:4816
@@ -4815,1 +4815,3 @@
+if ((MD->isMoveAssignmentOperator() ||
+ (CXXC && CXXC->isMoveConstructor())) &&
 !getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015))

rnk wrote:
> The move constructor part of this is definitely a good fix though.
And what's the decision? Could I commit the patch?


http://reviews.llvm.org/D19156



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


Re: [PATCH] D19932: [OpenCL] Add to_{global|local|private} builtin functions.

2016-05-12 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.
This revision is now accepted and ready to land.

LGTM



Comment at: test/SemaOpenCL/to_addr_builtin.cl:26
@@ +25,3 @@
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
+  // expected-error@-2{{'to_global' needs OpenCL version 2.0 or above}}
+#else

Anastasia wrote:
> @Xiuli, I think Sam is right. Passing constant to generic violates AS 
> conversion rules from s6.5.5. So error would be correct behavior of the 
> compiler.
Yes, I think I just misunderstand some address space problem.


http://reviews.llvm.org/D19932



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


Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-05-12 Thread Krystyna via cfe-commits
krystyna updated this revision to Diff 57007.
krystyna marked 8 inline comments as done.

Repository:
  rL LLVM

http://reviews.llvm.org/D18919

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseUsingCheck.cpp
  clang-tidy/modernize/UseUsingCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-using.rst
  test/clang-tidy/modernize-use-using.cpp

Index: test/clang-tidy/modernize-use-using.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-using.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t
+
+typedef int Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Type = int;
+
+typedef long LL;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using LL = long;
+
+typedef int Bla;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using Bla = int;
+
+typedef Bla Bla2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using Bla2 = Bla;
+
+typedef void (*type)(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using type = void (*)(int);
+
+typedef void (*type2)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using type2 = void (*)();
+
+class Class {
+  typedef long long Type;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use using instead of typedef
+  // CHECK-FIXES: using Type = long long;
+};
+
+typedef void (Class::*MyPtrType)(Bla) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using MyPtrType = void (Class::*)(Bla) const;
+
+class Iterable {
+public:
+  class Iterator {};
+};
+
+template 
+class Test {
+  typedef typename T::iterator Iter;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use using instead of typedef
+  // CHECK-FIXES: using Iter = typename T::iterator;
+};
+
+using balba = long long;
+
+union A {};
+
+typedef void (A::*PtrType)(int, int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using PtrType = void (A::*)(int, int) const;
+
+typedef Class some_class;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using some_class = Class;
+
+typedef Class Cclass;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using Cclass = Class;
+
+typedef Cclass cclass2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using cclass2 = Cclass;
+
+class cclass {};
+
+typedef void (cclass::*MyPtrType3)(Bla);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla);
+
+using my_class = int;
+
+typedef Test another;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using another = Test;
Index: docs/clang-tidy/checks/modernize-use-using.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-using.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - modernize-use-using
+
+modernize-use-using
+===
+
+Use C++11's ``using`` instead of ``typedef``.
+
+Before:
+
+.. code:: c++
+
+  typedef int variable;
+
+  class Class{};
+  typedef void (Class::* MyPtrType)() const;
+
+After:
+
+.. code:: c++
+
+  using variable = int;
+
+  class Class{};
+  using MyPtrType = void (Class::*)() const;
+
+This check requires using C++11 or higher to run.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -96,6 +96,7 @@
modernize-use-default
modernize-use-nullptr
modernize-use-override
+   modernize-use-using
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -161,6 +161,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-using
+  `_ check
+
+  Finds typedefs and replaces it with usings.
+
 - New `performance-faster-string-find
   `_ check
 
Index: clang-tidy/modernize/UseUsingCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseUsingCheck.h
@@ -0,0 +1,35 @@
+//===--- UseUsingCheck.h - clang-tidy---

Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-05-12 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: clang-tidy/modernize/UseUsingCheck.cpp:13
@@ +12,3 @@
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 
+

Is this required?


Repository:
  rL LLVM

http://reviews.llvm.org/D18919



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


Re: [PATCH] D20197: [clang-tidy] Ignore using-declarations defined in marcro in misc-unused-using-decls checks.

2016-05-12 Thread Haojian Wu via cfe-commits
hokein updated this revision to Diff 57008.
hokein added a comment.

Address review comments.


http://reviews.llvm.org/D20197

Files:
  clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  test/clang-tidy/misc-unused-using-decls.cpp

Index: test/clang-tidy/misc-unused-using-decls.cpp
===
--- test/clang-tidy/misc-unused-using-decls.cpp
+++ test/clang-tidy/misc-unused-using-decls.cpp
@@ -70,6 +70,14 @@
 using n::cout;
 using n::endl;
 
+#define DEFINE_INT(name)\
+  namespace INT {   \
+  static const int _##name = 1; \
+  } \
+  using INT::_##name
+DEFINE_INT(test);
+#undef DEFIND_INT
+
 // - Usages -
 void f(B b);
 void g() {
Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -35,6 +35,10 @@
 const auto *TargetDecl =
 Using->shadow_begin()->getTargetDecl()->getCanonicalDecl();
 
+// Ignores using-declarations defined in macros.
+if (TargetDecl->getLocation().isMacroID())
+  return;
+
 // Ignores using-declarations defined in class definition.
 if (isa(TargetDecl->getDeclContext()))
   return;


Index: test/clang-tidy/misc-unused-using-decls.cpp
===
--- test/clang-tidy/misc-unused-using-decls.cpp
+++ test/clang-tidy/misc-unused-using-decls.cpp
@@ -70,6 +70,14 @@
 using n::cout;
 using n::endl;
 
+#define DEFINE_INT(name)\
+  namespace INT {   \
+  static const int _##name = 1; \
+  } \
+  using INT::_##name
+DEFINE_INT(test);
+#undef DEFIND_INT
+
 // - Usages -
 void f(B b);
 void g() {
Index: clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -35,6 +35,10 @@
 const auto *TargetDecl =
 Using->shadow_begin()->getTargetDecl()->getCanonicalDecl();
 
+// Ignores using-declarations defined in macros.
+if (TargetDecl->getLocation().isMacroID())
+  return;
+
 // Ignores using-declarations defined in class definition.
 if (isa(TargetDecl->getDeclContext()))
   return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20197: [clang-tidy] Ignore using-declarations defined in marcro in misc-unused-using-decls checks.

2016-05-12 Thread Haojian Wu via cfe-commits
hokein marked 3 inline comments as done.


Comment at: clang-tidy/misc/UnusedUsingDeclsCheck.cpp:39
@@ +38,3 @@
+// Ignores using-declarations defined in macros.
+if (TargetDecl->getLocation().isMacroID())
+  return;

Good point. Using `isMacroID` is enough.


http://reviews.llvm.org/D20197



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


[PATCH] D20198: clang-format: [JS] sort ES6 imports.

2016-05-12 Thread Martin Probst via cfe-commits
mprobst created this revision.
mprobst added a reviewer: djasper.
mprobst added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

This change automatically sorts ES6 imports and exports into four groups:
absolute imports, parent imports, relative imports, and then exports. Exports
are sorted in the same order, but not grouped further.

http://reviews.llvm.org/D20198

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  unittests/Format/CMakeLists.txt
  unittests/Format/SortImportsTestJS.cpp

Index: unittests/Format/SortImportsTestJS.cpp
===
--- /dev/null
+++ unittests/Format/SortImportsTestJS.cpp
@@ -0,0 +1,130 @@
+//===- unittest/Format/SortImportsTestJS.cpp - JS import sort unit tests --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+namespace {
+
+class SortImportsTestJS : public ::testing::Test {
+protected:
+  std::vector GetCodeRange(StringRef Code) {
+return std::vector(1, tooling::Range(0, Code.size()));
+  }
+
+  std::string sort(StringRef Code, StringRef FileName = "input.js") {
+auto Ranges = GetCodeRange(Code);
+std::string Sorted = applyAllReplacements(
+Code, sortJavaScriptIncludes(Style, Code, Ranges, FileName));
+return applyAllReplacements(Sorted,
+reformat(Style, Sorted, Ranges, FileName));
+  }
+
+  void verifySort(llvm::StringRef Expected, llvm::StringRef Code) {
+std::string Result = sort(Code);
+EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
+  }
+
+  unsigned newCursor(llvm::StringRef Code, unsigned Cursor) {
+sortJavaScriptIncludes(Style, Code, GetCodeRange(Code), "input.js",
+   &Cursor);
+return Cursor;
+  }
+
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
+};
+
+TEST_F(SortImportsTestJS, BasicSorting) {
+  verifySort("import {sym} from 'a';\n"
+ "import {sym} from 'b';\n"
+ "import {sym} from 'c';\n"
+ "\n"
+ "let x = 1;",
+ "import {sym} from 'a';\n"
+ "import {sym} from 'c';\n"
+ "import {sym} from 'b';\n"
+ "let x = 1;");
+}
+
+TEST_F(SortImportsTestJS, Comments) {
+  verifySort("/** @fileoverview This is a great file. */\n"
+ "// A very important import follows.\n"
+ "import {sym} from 'a'; /* more comments */\n"
+ "import {sym} from 'b'; // from //foo:bar\n",
+ "/** @fileoverview This is a great file. */\n"
+ "import {sym} from 'b'; // from //foo:bar\n"
+ "// A very important import follows.\n"
+ "import {sym} from 'a'; /* more comments */\n");
+}
+
+TEST_F(SortImportsTestJS, SortStar) {
+  verifySort("import * as foo from 'a';\n"
+ "import {sym} from 'a';\n"
+ "import * as bar from 'b';\n",
+ "import {sym} from 'a';\n"
+ "import * as foo from 'a';\n"
+ "import * as bar from 'b';\n");
+}
+
+TEST_F(SortImportsTestJS, AliasesSymbols) {
+  verifySort("import {sym1 as alias1} from 'b';\n"
+ "import {sym2 as alias2, sym3 as alias3} from 'c';\n",
+ "import {sym2 as alias2, sym3 as alias3} from 'c';\n"
+ "import {sym1 as alias1} from 'b';\n");
+}
+
+TEST_F(SortImportsTestJS, GroupImports) {
+  verifySort("import {a} from 'absolute';\n"
+ "\n"
+ "import {b} from '../parent';\n"
+ "import {b} from '../parent/nested';\n"
+ "\n"
+ "import {b} from './relative/path';\n"
+ "import {b} from './relative/path/nested';\n"
+ "\n"
+ "let x = 1;\n",
+ "import {b} from './relative/path/nested';\n"
+ "import {b} from './relative/path';\n"
+ "import {b} from '../parent/nested';\n"
+ "import {b} from '../parent';\n"
+ "import {a} from 'absolute';\n"
+ "let x = 1;\n");
+}
+
+TEST_F(SortImportsTestJS, Exports) {
+  verifySort("import {S} from 'bpath';\n"
+ "\n"
+ "import {T} from './cpath';\n"
+ "\n"
+ "export {A, B} from 'apath';\n"
+ "export {P} from '../parent';\n"
+ "export {R} from './relative';\n"
+ "export {S};\n"
+ "\n"
+ "let x = 1;\n"
+ "export y = 1;\n",
+ "export {R} from './relative';\n"
+ "import {T} from './cpath';\n"
+ "export {S};\n

[clang-tools-extra] r269278 - [clang-tidy] Ignore using-declarations defined in marcro in misc-unused-using-decls checks.

2016-05-12 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu May 12 05:00:49 2016
New Revision: 269278

URL: http://llvm.org/viewvc/llvm-project?rev=269278&view=rev
Log:
[clang-tidy] Ignore using-declarations defined in marcro in 
misc-unused-using-decls checks.

Reviewers: djasper

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20197

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp?rev=269278&r1=269277&r2=269278&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp Thu May 
12 05:00:49 2016
@@ -35,6 +35,10 @@ void UnusedUsingDeclsCheck::check(const
 const auto *TargetDecl =
 Using->shadow_begin()->getTargetDecl()->getCanonicalDecl();
 
+// Ignores using-declarations defined in macros.
+if (TargetDecl->getLocation().isMacroID())
+  return;
+
 // Ignores using-declarations defined in class definition.
 if (isa(TargetDecl->getDeclContext()))
   return;

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp?rev=269278&r1=269277&r2=269278&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp Thu May 
12 05:00:49 2016
@@ -70,6 +70,14 @@ using n::UnusedFunc; // UnusedFunc
 using n::cout;
 using n::endl;
 
+#define DEFINE_INT(name)\
+  namespace INT {   \
+  static const int _##name = 1; \
+  } \
+  using INT::_##name
+DEFINE_INT(test);
+#undef DEFIND_INT
+
 // - Usages -
 void f(B b);
 void g() {


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


Re: [PATCH] D20197: [clang-tidy] Ignore using-declarations defined in marcro in misc-unused-using-decls checks.

2016-05-12 Thread Haojian Wu via cfe-commits
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rL269278: [clang-tidy] Ignore using-declarations defined in 
marcro in misc-unused-using… (authored by hokein).

Changed prior to commit:
  http://reviews.llvm.org/D20197?vs=57008&id=57012#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20197

Files:
  clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
@@ -70,6 +70,14 @@
 using n::cout;
 using n::endl;
 
+#define DEFINE_INT(name)\
+  namespace INT {   \
+  static const int _##name = 1; \
+  } \
+  using INT::_##name
+DEFINE_INT(test);
+#undef DEFIND_INT
+
 // - Usages -
 void f(B b);
 void g() {
Index: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -35,6 +35,10 @@
 const auto *TargetDecl =
 Using->shadow_begin()->getTargetDecl()->getCanonicalDecl();
 
+// Ignores using-declarations defined in macros.
+if (TargetDecl->getLocation().isMacroID())
+  return;
+
 // Ignores using-declarations defined in class definition.
 if (isa(TargetDecl->getDeclContext()))
   return;


Index: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
@@ -70,6 +70,14 @@
 using n::cout;
 using n::endl;
 
+#define DEFINE_INT(name)\
+  namespace INT {   \
+  static const int _##name = 1; \
+  } \
+  using INT::_##name
+DEFINE_INT(test);
+#undef DEFIND_INT
+
 // - Usages -
 void f(B b);
 void g() {
Index: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -35,6 +35,10 @@
 const auto *TargetDecl =
 Using->shadow_begin()->getTargetDecl()->getCanonicalDecl();
 
+// Ignores using-declarations defined in macros.
+if (TargetDecl->getLocation().isMacroID())
+  return;
+
 // Ignores using-declarations defined in class definition.
 if (isa(TargetDecl->getDeclContext()))
   return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20198: clang-format: [JS] sort ES6 imports.

2016-05-12 Thread Daniel Jasper via cfe-commits
djasper added a comment.

Just two high-level comments. Will review in more depth later.



Comment at: include/clang/Format/Format.h:770
@@ +769,3 @@
+/// ``export`` blocks are affected by ``Ranges``.
+tooling::Replacements sortJavaScriptIncludes(const FormatStyle &Style,
+ StringRef Code,

Why is this a separate function as opposed to looking at Style.Language?


Comment at: lib/Format/Format.cpp:1958
@@ +1957,3 @@
+// An imported symbol in a JavaScript ES6 import/export, possibly aliased.
+struct JsImportedSymbol {
+  StringRef Symbol;

I know this file is already a huge mess, but can you move all of the JS import 
sorting stuff to a separate file?


http://reviews.llvm.org/D20198



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


r269279 - [Driver] Squash misleading indentation warning.

2016-05-12 Thread Marcin Koscielnicki via cfe-commits
Author: koriakin
Date: Thu May 12 05:27:59 2016
New Revision: 269279

URL: http://llvm.org/viewvc/llvm-project?rev=269279&view=rev
Log:
[Driver] Squash misleading indentation warning.

Modified:
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=269279&r1=269278&r2=269279&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu May 12 05:27:59 2016
@@ -10483,12 +10483,12 @@ void CrossWindows::Linker::ConstructJob(
 } else {
   for (const auto &Lib : {"asan_dynamic", "asan_dynamic_runtime_thunk"})
 CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
-// Make sure the dynamic runtime thunk is not optimized out at link 
time
-// to ensure proper SEH handling.
-CmdArgs.push_back(Args.MakeArgString("--undefined"));
-CmdArgs.push_back(Args.MakeArgString(TC.getArch() == llvm::Triple::x86
- ? "___asan_seh_interceptor"
- : "__asan_seh_interceptor"));
+  // Make sure the dynamic runtime thunk is not optimized out at link time
+  // to ensure proper SEH handling.
+  CmdArgs.push_back(Args.MakeArgString("--undefined"));
+  CmdArgs.push_back(Args.MakeArgString(TC.getArch() == llvm::Triple::x86
+   ? "___asan_seh_interceptor"
+   : "__asan_seh_interceptor"));
 }
   }
 


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


[PATCH] D20200: clang-format: [JS] respect clang-format off when requoting strings.

2016-05-12 Thread Martin Probst via cfe-commits
mprobst created this revision.
mprobst added a reviewer: djasper.
mprobst added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

http://reviews.llvm.org/D20200

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1236,6 +1236,14 @@
   // Code below fits into 15 chars *after* removing the \ escape.
   verifyFormat("var x = 'fo\"o';", "var x = \"fo\\\"o\";",
getGoogleJSStyleWithColumns(15));
+  verifyFormat("// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = 'single';\n",
+   "// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = \"single\";\n");
 }
 
 TEST_F(FormatTestJS, RequoteStringsDouble) {
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1652,7 +1652,7 @@
   for (FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 StringRef Input = FormatTok->TokenText;
-if (!FormatTok->isStringLiteral() ||
+if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
 // NB: testing for not starting with a double quote to avoid
 // breaking
 // `template strings`.


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1236,6 +1236,14 @@
   // Code below fits into 15 chars *after* removing the \ escape.
   verifyFormat("var x = 'fo\"o';", "var x = \"fo\\\"o\";",
getGoogleJSStyleWithColumns(15));
+  verifyFormat("// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = 'single';\n",
+   "// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = \"single\";\n");
 }
 
 TEST_F(FormatTestJS, RequoteStringsDouble) {
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1652,7 +1652,7 @@
   for (FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 StringRef Input = FormatTok->TokenText;
-if (!FormatTok->isStringLiteral() ||
+if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
 // NB: testing for not starting with a double quote to avoid
 // breaking
 // `template strings`.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20200: clang-format: [JS] respect clang-format off when requoting strings.

2016-05-12 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


http://reviews.llvm.org/D20200



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


Re: [PATCH] D19274: Compilation for Intel MCU (Part 2/3)

2016-05-12 Thread Andrey Turetskiy via cfe-commits
aturetsk updated this revision to Diff 57017.
aturetsk added a comment.

Fix the remarks.


http://reviews.llvm.org/D19274

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/ToolChain.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp
  test/Driver/miamcu-opt.c
  test/Driver/miamcu-opt.cpp

Index: test/Driver/miamcu-opt.cpp
===
--- /dev/null
+++ test/Driver/miamcu-opt.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang -miamcu %s -### -o %t.o 2>&1 | FileCheck %s
+
+// CHECK: error: C++ is not supported for target 'i586-intel-elfiamcu'
Index: test/Driver/miamcu-opt.c
===
--- test/Driver/miamcu-opt.c
+++ test/Driver/miamcu-opt.c
@@ -16,3 +16,6 @@
 // CHECK: "-static-define"
 // CHECK: "-mfloat-abi" "soft"
 // CHECK: "-mstack-alignment=4"
+
+// CHECK: bin/ld
+// CHECK: "-static"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -295,6 +295,7 @@
 const InputInfoList &Inputs,
 const ToolChain *AuxToolChain) const {
   Arg *A;
+  const bool IsIAMCU = getToolChain().getTriple().isOSIAMCU();
 
   CheckPreprocessingOptions(D, Args);
 
@@ -562,10 +563,15 @@
   AuxToolChain->AddClangCXXStdlibIncludeArgs(Args, CmdArgs);
   }
 
-  // Add system include arguments.
-  getToolChain().AddClangSystemIncludeArgs(Args, CmdArgs);
-  if (AuxToolChain)
+  // Add system include arguments for all targets but IAMCU.
+  if (!IsIAMCU) {
+getToolChain().AddClangSystemIncludeArgs(Args, CmdArgs);
+if (AuxToolChain)
   AuxToolChain->AddClangCXXStdlibIncludeArgs(Args, CmdArgs);
+  } else {
+// For IAMCU add special include arguments.
+getToolChain().AddIAMCUIncludeArgs(Args, CmdArgs);
+  }
 
   // Add CUDA include arguments, if needed.
   if (types::isCuda(Inputs[0].getType()))
@@ -3635,6 +3641,7 @@
   getToolChain().getTriple().isWindowsCygwinEnvironment();
   bool IsWindowsMSVC = getToolChain().getTriple().isWindowsMSVCEnvironment();
   bool IsPS4CPU = getToolChain().getTriple().isPS4CPU();
+  bool IsIAMCU = getToolChain().getTriple().isOSIAMCU();
 
   // Check number of inputs for sanity. We need at least one input.
   assert(Inputs.size() >= 1 && "Must have at least one input.");
@@ -3645,6 +3652,10 @@
   bool IsCuda = types::isCuda(Input.getType());
   assert((IsCuda || Inputs.size() == 1) && "Unable to handle multiple inputs.");
 
+  // C++ is not supported for IAMCU.
+  if (IsIAMCU && types::isCXX(Input.getType()))
+D.Diag(diag::err_drv_cxx_not_supported) << getToolChain().getTriple().str();
+
   // Invoke ourselves in -cc1 mode.
   //
   // FIXME: Implement custom jobs for internal actions.
Index: lib/Driver/ToolChains.h
===
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -808,6 +808,8 @@
   llvm::opt::ArgStringList &CC1Args) const override;
   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const override;
+  void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+   llvm::opt::ArgStringList &CC1Args) const override;
   bool isPIEDefault() const override;
   SanitizerMask getSupportedSanitizers() const override;
   void addProfileRTLibs(const llvm::opt::ArgList &Args,
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -1610,9 +1610,13 @@
 break;
   case llvm::Triple::x86:
 LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
-TripleAliases.append(begin(X86Triples), end(X86Triples));
-BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
-BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
+// MCU toolchain is 32 bit only and its triple alias is TargetTriple
+// itself, which will be appended below.
+if (!TargetTriple.isOSIAMCU()) {
+  TripleAliases.append(begin(X86Triples), end(X86Triples));
+  BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
+  BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
+}
 break;
   case llvm::Triple::mips:
 LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
@@ -1758,14 +1762,14 @@
 namespace {
 // Filter to remove Multilibs that don't exist as a suffix to Path
 class FilterNonExistent {
-  StringRef Base;
+  StringRef Base, File;
   vfs::FileSystem &VFS;
 
 public:
-  FilterNonExistent(StringRef Base, vfs::FileSystem &VFS)
-  : Base(Base), VFS(VFS) {}
+  FilterNonExistent(StringRef Base, StringRef File, vfs::FileSystem &VFS)
+  : Base(Base), File(File), VFS(VFS) {}
   b

r269282 - clang-format: [JS] respect clang-format off when requoting strings.

2016-05-12 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Thu May 12 06:20:32 2016
New Revision: 269282

URL: http://llvm.org/viewvc/llvm-project?rev=269282&view=rev
Log:
clang-format: [JS] respect clang-format off when requoting strings.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D20200

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=269282&r1=269281&r2=269282&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu May 12 06:20:32 2016
@@ -1652,7 +1652,7 @@ private:
   for (FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 StringRef Input = FormatTok->TokenText;
-if (!FormatTok->isStringLiteral() ||
+if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
 // NB: testing for not starting with a double quote to avoid
 // breaking
 // `template strings`.

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=269282&r1=269281&r2=269282&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu May 12 06:20:32 2016
@@ -1236,6 +1236,14 @@ TEST_F(FormatTestJS, RequoteStringsSingl
   // Code below fits into 15 chars *after* removing the \ escape.
   verifyFormat("var x = 'fo\"o';", "var x = \"fo\\\"o\";",
getGoogleJSStyleWithColumns(15));
+  verifyFormat("// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = 'single';\n",
+   "// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = \"single\";\n");
 }
 
 TEST_F(FormatTestJS, RequoteStringsDouble) {


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


Re: [PATCH] D20200: clang-format: [JS] respect clang-format off when requoting strings.

2016-05-12 Thread Martin Probst via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269282: clang-format: [JS] respect clang-format off when 
requoting strings. (authored by mprobst).

Changed prior to commit:
  http://reviews.llvm.org/D20200?vs=57014&id=57018#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20200

Files:
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp

Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1652,7 +1652,7 @@
   for (FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 StringRef Input = FormatTok->TokenText;
-if (!FormatTok->isStringLiteral() ||
+if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
 // NB: testing for not starting with a double quote to avoid
 // breaking
 // `template strings`.
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1236,6 +1236,14 @@
   // Code below fits into 15 chars *after* removing the \ escape.
   verifyFormat("var x = 'fo\"o';", "var x = \"fo\\\"o\";",
getGoogleJSStyleWithColumns(15));
+  verifyFormat("// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = 'single';\n",
+   "// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = \"single\";\n");
 }
 
 TEST_F(FormatTestJS, RequoteStringsDouble) {


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -1652,7 +1652,7 @@
   for (FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
 StringRef Input = FormatTok->TokenText;
-if (!FormatTok->isStringLiteral() ||
+if (FormatTok->Finalized || !FormatTok->isStringLiteral() ||
 // NB: testing for not starting with a double quote to avoid
 // breaking
 // `template strings`.
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1236,6 +1236,14 @@
   // Code below fits into 15 chars *after* removing the \ escape.
   verifyFormat("var x = 'fo\"o';", "var x = \"fo\\\"o\";",
getGoogleJSStyleWithColumns(15));
+  verifyFormat("// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = 'single';\n",
+   "// clang-format off\n"
+   "let x = \"double\";\n"
+   "// clang-format on\n"
+   "let x = \"single\";\n");
 }
 
 TEST_F(FormatTestJS, RequoteStringsDouble) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19274: Compilation for Intel MCU (Part 2/3)

2016-05-12 Thread Andrey Turetskiy via cfe-commits
aturetsk added a comment.

Hi Bruno,
Thanks for the review.



Comment at: include/clang/Basic/DiagnosticDriverKinds.td:157
@@ -156,1 +156,3 @@
+def err_drv_cxx_not_supported : Error<
+  "C++ is not supported for target '%0'">;
 

Yes. I've found nothing similar.


Comment at: lib/Driver/Tools.cpp:301
@@ -299,3 +300,3 @@
   CheckPreprocessingOptions(D, Args);
 
   Args.AddLastArg(CmdArgs, options::OPT_C);

Done.


Comment at: lib/Driver/Tools.cpp:574
@@ -569,1 +573,3 @@
+getToolChain().AddIAMCUIncludeArgs(Args, CmdArgs);
+  }
 

Done.


http://reviews.llvm.org/D19274



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


Re: [PATCH] D16962: clang-tidy: avoid std::bind

2016-05-12 Thread Jonathan B Coe via cfe-commits
jbcoe updated this revision to Diff 57022.
jbcoe marked 6 inline comments as done.
jbcoe added a comment.

Apply fixes from review.


http://reviews.llvm.org/D16962

Files:
  clang-tidy/modernize/AvoidBindCheck.cpp
  clang-tidy/modernize/AvoidBindCheck.h
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-avoid-bind.rst
  test/clang-tidy/modernize-avoid-bind.cpp

Index: test/clang-tidy/modernize-avoid-bind.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-avoid-bind.cpp
@@ -0,0 +1,70 @@
+// RUN: %check_clang_tidy %s modernize-avoid-bind %t -- -- -std=c++14
+
+namespace std {
+inline namespace impl {
+template 
+class bind_rt {};
+
+template 
+bind_rt bind(Fp &&, Arguments &&...);
+}
+}
+
+int add(int x, int y) { return x + y; }
+
+void f() {
+  auto clj = std::bind(add, 2, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind [modernize-avoid-bind]
+  // CHECK-FIXES: auto clj = [] { return add(2, 2); };
+}
+
+void g() {
+  int x = 2;
+  int y = 2;
+  auto clj = std::bind(add, x, y);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // CHECK-FIXES: auto clj = [=] { return add(x, y); };
+}
+
+struct placeholder {};
+placeholder _1;
+placeholder _2;
+
+void h() {
+  int x = 2;
+  auto clj = std::bind(add, x, _1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // CHECK-FIXES: auto clj = [=](auto && arg1) { return add(x, arg1); };
+}
+
+struct A;
+struct B;
+bool ABTest(const A &, const B &);
+
+void i() {
+  auto BATest = std::bind(ABTest, _2, _1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: prefer a lambda to std::bind 
+  // CHECK-FIXES: auto BATest = [](auto && arg1, auto && arg2) { return ABTest(arg2, arg1); };
+}
+
+void j() {
+  auto clj = std::bind(add, 2, 2, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // No fix is applied for argument mismatches.
+  // CHECK-FIXES: auto clj = std::bind(add, 2, 2, 2);
+}
+
+void k() {
+  auto clj = std::bind(add, _1, _1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // No fix is applied for reused placeholders.
+  // CHECK-FIXES: auto clj = std::bind(add, _1, _1);
+}
+
+void m() {
+  auto clj = std::bind(add, 1, add(2, 5));
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // No fix is applied for nested calls.
+  // CHECK-FIXES: auto clj = std::bind(add, 1, add(2, 5));
+}
+
Index: docs/clang-tidy/checks/modernize-avoid-bind.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-avoid-bind.rst
@@ -0,0 +1,38 @@
+.. title:: clang-tidy - modernize-avoid-std-bind
+
+modernize-avoid-bind
+==
+
+The check finds uses of ``std::bind`` and replaces simple uses with lambdas.
+Lambdas will use value-capture where required.
+
+Right now it only handles free functions, not member functions.
+
+Given:
+
+.. code:: C++
+
+  int add(int x, int y) { return x + y; }
+
+Then:
+
+.. code:: C++
+  
+  void f() {
+int x = 2;
+auto clj = std::bind(add, x, _1);
+  }
+
+is replaced by:
+  
+.. code:: C++
+  
+  void f() {
+int x = 2;
+auto clj = [=](auto && arg1) { return add(x, arg1); };
+  }
+
+``std::bind`` can be hard to read and can result in larger object files and
+binaries due to type information that will not be produced by equivalent
+lambdas.
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -87,6 +87,7 @@
misc-unused-raii
misc-unused-using-decls
misc-virtual-near-miss
+   modernize-avoid-bind
modernize-deprecated-headers
modernize-loop-convert
modernize-make-unique
Index: clang-tidy/modernize/ModernizeTidyModule.cpp
===
--- clang-tidy/modernize/ModernizeTidyModule.cpp
+++ clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidBindCheck.h"
 #include "DeprecatedHeadersCheck.h"
 #include "LoopConvertCheck.h"
 #include "MakeUniqueCheck.h"
@@ -32,6 +33,8 @@
 class ModernizeModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"modernize-avoid-bind");
 CheckFactories.registerCheck(
 "modernize-deprecated-headers");
 CheckFactories.registerCheck("modernize-loop-convert");
Index: clang-tidy/modernize/CMakeLists.txt
===
--- clang-tidy/modernize/CMakeLists.txt
+++ clang-tidy/modernize/CMakeList

Re: [PATCH] D20168: [CodeGen] Handle structs directly in AMDGPUABIInfo

2016-05-12 Thread Vedran Miletić via cfe-commits
rivanvx updated this revision to Diff 57023.
rivanvx added a comment.

Now with 100% more tests.


http://reviews.llvm.org/D20168

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl

Index: test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
@@ -0,0 +1,16 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK: %struct.struct_arg = type { i32, float, i32 }
+typedef struct struct_arg
+{
+int i1;
+float f;
+int i2;
+} struct_arg_t;
+
+// CHECK-LABEL: @test_struct_arg
+// CHECK: %struct.struct_arg %arg1.coerce
+kernel void test_struct_arg(struct_arg_t arg1)
+{
+}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -6808,10 +6808,41 @@
 
 namespace {
 
+class AMDGPUABIInfo final : public DefaultABIInfo {
+public:
+  explicit AMDGPUABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
+
+private:
+  ABIArgInfo classifyArgumentType(QualType Ty) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override;
+};
+
+void AMDGPUABIInfo::computeInfo(CGFunctionInfo &FI) const {
+  if (!getCXXABI().classifyReturnType(FI))
+FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+  for (auto &Arg : FI.arguments())
+Arg.info = classifyArgumentType(Arg.type);
+}
+
+/// \brief Classify argument of given type \p Ty.
+ABIArgInfo AMDGPUABIInfo::classifyArgumentType(QualType Ty) const {
+  llvm::StructType *StrTy = dyn_cast(CGT.ConvertType(Ty));
+  if (!StrTy) {
+return DefaultABIInfo::classifyArgumentType(Ty);
+  }
+
+  // If we set CanBeFlattened to true, CodeGen will expand the struct to its
+  // individual elements, which confuses the Clover OpenCL backend; therefore 
we
+  // have to set it to false here. Other args of getDirect() are just defaults.
+  return ABIArgInfo::getDirect(nullptr, 0, nullptr, false);
+}
+
 class AMDGPUTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   AMDGPUTargetCodeGenInfo(CodeGenTypes &CGT)
-: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
+: TargetCodeGenInfo(new AMDGPUABIInfo(CGT)) {}
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;
 };


Index: test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
@@ -0,0 +1,16 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: %struct.struct_arg = type { i32, float, i32 }
+typedef struct struct_arg
+{
+int i1;
+float f;
+int i2;
+} struct_arg_t;
+
+// CHECK-LABEL: @test_struct_arg
+// CHECK: %struct.struct_arg %arg1.coerce
+kernel void test_struct_arg(struct_arg_t arg1)
+{
+}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -6808,10 +6808,41 @@
 
 namespace {
 
+class AMDGPUABIInfo final : public DefaultABIInfo {
+public:
+  explicit AMDGPUABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
+
+private:
+  ABIArgInfo classifyArgumentType(QualType Ty) const;
+
+  void computeInfo(CGFunctionInfo &FI) const override;
+};
+
+void AMDGPUABIInfo::computeInfo(CGFunctionInfo &FI) const {
+  if (!getCXXABI().classifyReturnType(FI))
+FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+
+  for (auto &Arg : FI.arguments())
+Arg.info = classifyArgumentType(Arg.type);
+}
+
+/// \brief Classify argument of given type \p Ty.
+ABIArgInfo AMDGPUABIInfo::classifyArgumentType(QualType Ty) const {
+  llvm::StructType *StrTy = dyn_cast(CGT.ConvertType(Ty));
+  if (!StrTy) {
+return DefaultABIInfo::classifyArgumentType(Ty);
+  }
+
+  // If we set CanBeFlattened to true, CodeGen will expand the struct to its
+  // individual elements, which confuses the Clover OpenCL backend; therefore we
+  // have to set it to false here. Other args of getDirect() are just defaults.
+  return ABIArgInfo::getDirect(nullptr, 0, nullptr, false);
+}
+
 class AMDGPUTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   AMDGPUTargetCodeGenInfo(CodeGenTypes &CGT)
-: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
+: TargetCodeGenInfo(new AMDGPUABIInfo(CGT)) {}
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-12 Thread Alexander Makarov via cfe-commits
a.makarov added inline comments.


Comment at: lib/AST/ASTContext.cpp:8604-8606
@@ -8603,5 +8603,5 @@
 bool IsCXXMethod) const {
   // Pass through to the C++ ABI object
   if (IsCXXMethod)
 return ABI->getDefaultMethodCallConv(IsVariadic);
 

majnemer wrote:
> rnk wrote:
> > majnemer wrote:
> > > Do these flags not have an effect on methods?
> > Nope:
> > https://msdn.microsoft.com/en-us/library/46t77ak2.aspx
> > "for all functions except C++ member functions..."
> Yeah, that's what the documentation says.  But do they really have no effect? 
> :)
Yes, I've checked. Member functions are not affected =)


http://reviews.llvm.org/D20171



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


Re: [PATCH] D16962: clang-tidy: avoid std::bind

2016-05-12 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good. Thank you!

Do you need someone to submit the patch for you?



Comment at: clang-tidy/modernize/AvoidBindCheck.cpp:28
@@ +27,3 @@
+  BindArgumentKind Kind = BK_Other;
+  size_t PlaceHolderIndex = 0;
+};

Answering my own question: according to 
https://msdn.microsoft.com/en-us/library/hh567368.aspx non-static member 
initializers are supported by VS2013. This should be fine.


http://reviews.llvm.org/D16962



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


Re: [PATCH] D16962: clang-tidy: avoid std::bind

2016-05-12 Thread Jonathan B Coe via cfe-commits
jbcoe added a comment.

I can submit the patch myself, thanks.

Thanks again for taking the time to give such a thorough review.


http://reviews.llvm.org/D16962



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


Re: [PATCH] D19703: [clang-tidy] Improve misc-redundant-expression and decrease false-positive

2016-05-12 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:139
@@ +138,3 @@
+  const LangOptions &LO = Finder->getASTContext().getLangOpts();
+  SourceLocation Loc = Node.getExprLoc();
+  while (Loc.isMacroID()) {

Ah, found it: `llvm/ADT/StringSet.h` seems to be a better choice here.


http://reviews.llvm.org/D19703



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


Re: [PATCH] D20170: [clang-tidy] TypeTraits - Type is not expensive to copy when it has a deleted copy constructor.

2016-05-12 Thread Felix Berger via cfe-commits
flx added inline comments.


Comment at: clang-tidy/utils/TypeTraits.cpp:32
@@ +31,3 @@
+  auto *Record = Type->getAsCXXRecordDecl();
+  if (Record == nullptr || !Record->hasDefinition())
+return false;

aaron.ballman wrote:
> `!Record` instead of explicit comparison.
Does this make a difference for code generation or is this just a convention 
here for conciseness?


http://reviews.llvm.org/D20170



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


Re: [PATCH] D20170: [clang-tidy] TypeTraits - Type is not expensive to copy when it has a deleted copy constructor.

2016-05-12 Thread Felix Berger via cfe-commits
flx removed rL LLVM as the repository for this revision.
flx updated this revision to Diff 57035.
flx marked 5 inline comments as done.

http://reviews.llvm.org/D20170

Files:
  clang-tidy/utils/TypeTraits.cpp
  test/clang-tidy/performance-unnecessary-value-param.cpp

Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -23,6 +23,13 @@
   SomewhatTrivial& operator=(const SomewhatTrivial&);
 };
 
+struct MoveOnlyType {
+  MoveOnlyType(const MoveOnlyType &) = delete;
+  MoveOnlyType(MoveOnlyType &&) = default;
+  ~MoveOnlyType();
+  void constMethod() const;
+};
+
 void positiveExpensiveConstValue(const ExpensiveToCopyType Obj);
 // CHECK-FIXES: void positiveExpensiveConstValue(const ExpensiveToCopyType& 
Obj);
 void positiveExpensiveConstValue(const ExpensiveToCopyType Obj) {
@@ -169,3 +176,7 @@
   NegativeDeletedMethod& operator=(NegativeDeletedMethod N) = delete;
   // CHECK-FIXES: NegativeDeletedMethod& operator=(NegativeDeletedMethod N) = 
delete;
 };
+
+void NegativeMoveOnlyTypePassedByValue(MoveOnlyType M) {
+  M.constMethod();
+}
Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -10,26 +10,43 @@
 #include "TypeTraits.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 
 namespace clang {
 namespace tidy {
 namespace utils {
 namespace type_traits {
 
 namespace {
+
+using namespace ::clang::ast_matchers;
+
 bool classHasTrivialCopyAndDestroy(QualType Type) {
   auto *Record = Type->getAsCXXRecordDecl();
   return Record && Record->hasDefinition() &&
  !Record->hasNonTrivialCopyConstructor() &&
  !Record->hasNonTrivialDestructor();
 }
+
+bool hasDeletedCopyConstructor(QualType Type, ASTContext &Context) {
+  auto *Record = Type->getAsCXXRecordDecl();
+  if (!Record || !Record->hasDefinition())
+return false;
+  for (const CXXConstructorDecl *Constructor : Record->ctors()) {
+if (Constructor->isCopyConstructor() && Constructor->isDeleted())
+  return true;
+  }
+  return false;
+}
+
 } // namespace
 
 llvm::Optional isExpensiveToCopy(QualType Type, ASTContext &Context) {
   if (Type->isDependentType())
 return llvm::None;
   return !Type.isTriviallyCopyableType(Context) &&
- !classHasTrivialCopyAndDestroy(Type);
+ !classHasTrivialCopyAndDestroy(Type) &&
+ !hasDeletedCopyConstructor(Type, Context);
 }
 
 bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl,


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -23,6 +23,13 @@
   SomewhatTrivial& operator=(const SomewhatTrivial&);
 };
 
+struct MoveOnlyType {
+  MoveOnlyType(const MoveOnlyType &) = delete;
+  MoveOnlyType(MoveOnlyType &&) = default;
+  ~MoveOnlyType();
+  void constMethod() const;
+};
+
 void positiveExpensiveConstValue(const ExpensiveToCopyType Obj);
 // CHECK-FIXES: void positiveExpensiveConstValue(const ExpensiveToCopyType& Obj);
 void positiveExpensiveConstValue(const ExpensiveToCopyType Obj) {
@@ -169,3 +176,7 @@
   NegativeDeletedMethod& operator=(NegativeDeletedMethod N) = delete;
   // CHECK-FIXES: NegativeDeletedMethod& operator=(NegativeDeletedMethod N) = delete;
 };
+
+void NegativeMoveOnlyTypePassedByValue(MoveOnlyType M) {
+  M.constMethod();
+}
Index: clang-tidy/utils/TypeTraits.cpp
===
--- clang-tidy/utils/TypeTraits.cpp
+++ clang-tidy/utils/TypeTraits.cpp
@@ -10,26 +10,43 @@
 #include "TypeTraits.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 
 namespace clang {
 namespace tidy {
 namespace utils {
 namespace type_traits {
 
 namespace {
+
+using namespace ::clang::ast_matchers;
+
 bool classHasTrivialCopyAndDestroy(QualType Type) {
   auto *Record = Type->getAsCXXRecordDecl();
   return Record && Record->hasDefinition() &&
  !Record->hasNonTrivialCopyConstructor() &&
  !Record->hasNonTrivialDestructor();
 }
+
+bool hasDeletedCopyConstructor(QualType Type, ASTContext &Context) {
+  auto *Record = Type->getAsCXXRecordDecl();
+  if (!Record || !Record->hasDefinition())
+return false;
+  for (const CXXConstructorDecl *Constructor : Record->ctors()) {
+if (Constructor->isCopyConstructor() && Constructor->isDeleted())
+  return true;
+  }
+  return false;
+}
+
 } // namespace
 
 llvm::Optional isExpensiveToCopy(QualType Type, ASTContext &Context) {
   if (Type->isDependentType())
 return llvm::None;

Re: [PATCH] D20198: clang-format: [JS] sort ES6 imports.

2016-05-12 Thread Martin Probst via cfe-commits
mprobst updated this revision to Diff 57037.
mprobst added a comment.

- extract TokenAnalyzer.h and SortJavaScriptImports.h/cpp
- clean up imports


http://reviews.llvm.org/D20198

Files:
  lib/Format/CMakeLists.txt
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/FormatTokenLexer.h
  lib/Format/SortJavaScriptImports.cpp
  lib/Format/SortJavaScriptImports.h
  lib/Format/TokenAnalyzer.h
  unittests/Format/CMakeLists.txt
  unittests/Format/SortImportsTestJS.cpp

Index: unittests/Format/SortImportsTestJS.cpp
===
--- /dev/null
+++ unittests/Format/SortImportsTestJS.cpp
@@ -0,0 +1,124 @@
+//===- unittest/Format/SortImportsTestJS.cpp - JS import sort unit tests --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+namespace {
+
+class SortImportsTestJS : public ::testing::Test {
+protected:
+  std::vector GetCodeRange(StringRef Code) {
+return std::vector(1, tooling::Range(0, Code.size()));
+  }
+
+  std::string sort(StringRef Code, StringRef FileName = "input.js") {
+auto Ranges = GetCodeRange(Code);
+std::string Sorted =
+applyAllReplacements(Code, sortIncludes(Style, Code, Ranges, FileName));
+return applyAllReplacements(Sorted,
+reformat(Style, Sorted, Ranges, FileName));
+  }
+
+  void verifySort(llvm::StringRef Expected, llvm::StringRef Code) {
+std::string Result = sort(Code);
+EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
+  }
+
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
+};
+
+TEST_F(SortImportsTestJS, BasicSorting) {
+  verifySort("import {sym} from 'a';\n"
+ "import {sym} from 'b';\n"
+ "import {sym} from 'c';\n"
+ "\n"
+ "let x = 1;",
+ "import {sym} from 'a';\n"
+ "import {sym} from 'c';\n"
+ "import {sym} from 'b';\n"
+ "let x = 1;");
+}
+
+TEST_F(SortImportsTestJS, Comments) {
+  verifySort("/** @fileoverview This is a great file. */\n"
+ "// A very important import follows.\n"
+ "import {sym} from 'a'; /* more comments */\n"
+ "import {sym} from 'b'; // from //foo:bar\n",
+ "/** @fileoverview This is a great file. */\n"
+ "import {sym} from 'b'; // from //foo:bar\n"
+ "// A very important import follows.\n"
+ "import {sym} from 'a'; /* more comments */\n");
+}
+
+TEST_F(SortImportsTestJS, SortStar) {
+  verifySort("import * as foo from 'a';\n"
+ "import {sym} from 'a';\n"
+ "import * as bar from 'b';\n",
+ "import {sym} from 'a';\n"
+ "import * as foo from 'a';\n"
+ "import * as bar from 'b';\n");
+}
+
+TEST_F(SortImportsTestJS, AliasesSymbols) {
+  verifySort("import {sym1 as alias1} from 'b';\n"
+ "import {sym2 as alias2, sym3 as alias3} from 'c';\n",
+ "import {sym2 as alias2, sym3 as alias3} from 'c';\n"
+ "import {sym1 as alias1} from 'b';\n");
+}
+
+TEST_F(SortImportsTestJS, GroupImports) {
+  verifySort("import {a} from 'absolute';\n"
+ "\n"
+ "import {b} from '../parent';\n"
+ "import {b} from '../parent/nested';\n"
+ "\n"
+ "import {b} from './relative/path';\n"
+ "import {b} from './relative/path/nested';\n"
+ "\n"
+ "let x = 1;\n",
+ "import {b} from './relative/path/nested';\n"
+ "import {b} from './relative/path';\n"
+ "import {b} from '../parent/nested';\n"
+ "import {b} from '../parent';\n"
+ "import {a} from 'absolute';\n"
+ "let x = 1;\n");
+}
+
+TEST_F(SortImportsTestJS, Exports) {
+  verifySort("import {S} from 'bpath';\n"
+ "\n"
+ "import {T} from './cpath';\n"
+ "\n"
+ "export {A, B} from 'apath';\n"
+ "export {P} from '../parent';\n"
+ "export {R} from './relative';\n"
+ "export {S};\n"
+ "\n"
+ "let x = 1;\n"
+ "export y = 1;\n",
+ "export {R} from './relative';\n"
+ "import {T} from './cpath';\n"
+ "export {S};\n"
+ "export {A, B} from 'apath';\n"
+ "import {S} from 'bpath';\n"
+ "export {P} from '../parent';\n"
+ "let x = 1;\n"
+ "export y = 1;\n");
+}
+
+} // end namespace
+} // end namespace format
+} // end namespace clang
I

Re: [PATCH] D20198: clang-format: [JS] sort ES6 imports.

2016-05-12 Thread Martin Probst via cfe-commits
mprobst marked 2 inline comments as done.
mprobst added a comment.

http://reviews.llvm.org/D20198



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


Re: [PATCH] D20134: [libclang] Fixed bug where ranges in spelling locations (in macro expansions) would get mangled

2016-05-12 Thread Cameron via cfe-commits
cameron314 added a comment.

You're right, this breaks that test. The corner case that it exercises is 
arguably less important than breaking all spelling ranges, though. But I'm 
going to see if I can fix both with a little wizardry (ideally there wouldn't 
be open ranges in the first place, since clang doesn't really support them, but 
failing that we can distinguish between an inclusive and exclusive source 
location internally and that might be enough).


http://reviews.llvm.org/D20134



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


Re: [PATCH] D20170: [clang-tidy] TypeTraits - Type is not expensive to copy when it has a deleted copy constructor.

2016-05-12 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.


Comment at: clang-tidy/utils/TypeTraits.cpp:31
@@ +30,3 @@
+
+bool hasDeletedCopyConstructor(QualType Type, ASTContext &Context) {
+  auto *Record = Type->getAsCXXRecordDecl();

No need to pass in `Context` any longer.


Comment at: clang-tidy/utils/TypeTraits.cpp:33
@@ +32,3 @@
+  auto *Record = Type->getAsCXXRecordDecl();
+  if (!Record || !Record->hasDefinition())
+return false;

Should be no codegen difference in practice; it's just conciseness.


Comment at: clang-tidy/utils/TypeTraits.cpp:35
@@ +34,3 @@
+return false;
+  for (const CXXConstructorDecl *Constructor : Record->ctors()) {
+if (Constructor->isCopyConstructor() && Constructor->isDeleted())

Can just use `const auto *` for this, but I'm fine either way.


http://reviews.llvm.org/D20170



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


Re: [PATCH] D20014: [libc++] Explicit return in non-void function

2016-05-12 Thread Marshall Clow via cfe-commits
mclow.lists added a subscriber: mclow.lists.
mclow.lists accepted this revision.
mclow.lists added a reviewer: mclow.lists.
mclow.lists added a comment.
This revision is now accepted and ready to land.

LGTM.

`C` and `D` are different failure modes for `uses_allocator`, since the 
standard says that it has to be a nested type.


http://reviews.llvm.org/D20014



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


Re: [PATCH] D20198: clang-format: [JS] sort ES6 imports.

2016-05-12 Thread Martin Probst via cfe-commits
mprobst updated this revision to Diff 57039.
mprobst added a comment.

- extract TokenAnalyzer.h and SortJavaScriptImports.h/cpp
- clean up imports/
- includes


http://reviews.llvm.org/D20198

Files:
  lib/Format/CMakeLists.txt
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/FormatTokenLexer.h
  lib/Format/SortJavaScriptImports.cpp
  lib/Format/SortJavaScriptImports.h
  lib/Format/TokenAnalyzer.h
  unittests/Format/CMakeLists.txt
  unittests/Format/SortImportsTestJS.cpp

Index: unittests/Format/SortImportsTestJS.cpp
===
--- /dev/null
+++ unittests/Format/SortImportsTestJS.cpp
@@ -0,0 +1,124 @@
+//===- unittest/Format/SortImportsTestJS.cpp - JS import sort unit tests --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+namespace {
+
+class SortImportsTestJS : public ::testing::Test {
+protected:
+  std::vector GetCodeRange(StringRef Code) {
+return std::vector(1, tooling::Range(0, Code.size()));
+  }
+
+  std::string sort(StringRef Code, StringRef FileName = "input.js") {
+auto Ranges = GetCodeRange(Code);
+std::string Sorted =
+applyAllReplacements(Code, sortIncludes(Style, Code, Ranges, FileName));
+return applyAllReplacements(Sorted,
+reformat(Style, Sorted, Ranges, FileName));
+  }
+
+  void verifySort(llvm::StringRef Expected, llvm::StringRef Code) {
+std::string Result = sort(Code);
+EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
+  }
+
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
+};
+
+TEST_F(SortImportsTestJS, BasicSorting) {
+  verifySort("import {sym} from 'a';\n"
+ "import {sym} from 'b';\n"
+ "import {sym} from 'c';\n"
+ "\n"
+ "let x = 1;",
+ "import {sym} from 'a';\n"
+ "import {sym} from 'c';\n"
+ "import {sym} from 'b';\n"
+ "let x = 1;");
+}
+
+TEST_F(SortImportsTestJS, Comments) {
+  verifySort("/** @fileoverview This is a great file. */\n"
+ "// A very important import follows.\n"
+ "import {sym} from 'a'; /* more comments */\n"
+ "import {sym} from 'b'; // from //foo:bar\n",
+ "/** @fileoverview This is a great file. */\n"
+ "import {sym} from 'b'; // from //foo:bar\n"
+ "// A very important import follows.\n"
+ "import {sym} from 'a'; /* more comments */\n");
+}
+
+TEST_F(SortImportsTestJS, SortStar) {
+  verifySort("import * as foo from 'a';\n"
+ "import {sym} from 'a';\n"
+ "import * as bar from 'b';\n",
+ "import {sym} from 'a';\n"
+ "import * as foo from 'a';\n"
+ "import * as bar from 'b';\n");
+}
+
+TEST_F(SortImportsTestJS, AliasesSymbols) {
+  verifySort("import {sym1 as alias1} from 'b';\n"
+ "import {sym2 as alias2, sym3 as alias3} from 'c';\n",
+ "import {sym2 as alias2, sym3 as alias3} from 'c';\n"
+ "import {sym1 as alias1} from 'b';\n");
+}
+
+TEST_F(SortImportsTestJS, GroupImports) {
+  verifySort("import {a} from 'absolute';\n"
+ "\n"
+ "import {b} from '../parent';\n"
+ "import {b} from '../parent/nested';\n"
+ "\n"
+ "import {b} from './relative/path';\n"
+ "import {b} from './relative/path/nested';\n"
+ "\n"
+ "let x = 1;\n",
+ "import {b} from './relative/path/nested';\n"
+ "import {b} from './relative/path';\n"
+ "import {b} from '../parent/nested';\n"
+ "import {b} from '../parent';\n"
+ "import {a} from 'absolute';\n"
+ "let x = 1;\n");
+}
+
+TEST_F(SortImportsTestJS, Exports) {
+  verifySort("import {S} from 'bpath';\n"
+ "\n"
+ "import {T} from './cpath';\n"
+ "\n"
+ "export {A, B} from 'apath';\n"
+ "export {P} from '../parent';\n"
+ "export {R} from './relative';\n"
+ "export {S};\n"
+ "\n"
+ "let x = 1;\n"
+ "export y = 1;\n",
+ "export {R} from './relative';\n"
+ "import {T} from './cpath';\n"
+ "export {S};\n"
+ "export {A, B} from 'apath';\n"
+ "import {S} from 'bpath';\n"
+ "export {P} from '../parent';\n"
+ "let x = 1;\n"
+ "export y = 1;\n");
+}
+
+} // end namespace
+} // end namespace format
+} // end names

Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-12 Thread Alexander Makarov via cfe-commits
a.makarov added inline comments.


Comment at: lib/AST/ASTContext.cpp:8616-8619
@@ +8615,6 @@
+  return CC_C;
+case LangOptions::DCC_FastCall:
+  return CC_X86FastCall;
+case LangOptions::DCC_StdCall:
+  return CC_X86StdCall;
+case LangOptions::DCC_VectorCall:

rnk wrote:
> Neither fastcall nor stdcall can be applied to variadic functions.
As I've got from MSDN, **vectorcall** and stdcall cannot be applied to vararg 
functions. Are you sure about fastcall?)


http://reviews.llvm.org/D20171



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


[libcxx] r269298 - Apply D20014 - fix a missing return in a test. Fixes PR#27720

2016-05-12 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu May 12 09:31:35 2016
New Revision: 269298

URL: http://llvm.org/viewvc/llvm-project?rev=269298&view=rev
Log:
Apply D20014 - fix a missing return in a test. Fixes PR#27720

Modified:

libcxx/trunk/test/std/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp?rev=269298&r1=269297&r2=269298&view=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp
 Thu May 12 09:31:35 2016
@@ -30,7 +30,7 @@ struct C {
 };
 
 struct D {
-  static int allocator_type() {}
+  static int allocator_type() { return 0; }
 };
 
 struct E {


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


Re: [PATCH] D20053: [clang-tidy] Add misc-unnecessary-mutable check.

2016-05-12 Thread Piotr Padlewski via cfe-commits
Prazek added a reviewer: Prazek.


Comment at: clang-tidy/misc/UnnecessaryMutableCheck.cpp:152
@@ +151,3 @@
+// it is the only declaration in a declaration chain.
+static bool CheckRemoval(SourceManager &SM, const SourceLocation &LocStart,
+ const SourceLocation &LocEnd, ASTContext &Context,

I guess you can use hasSingleDecl in matcher to solve this


http://reviews.llvm.org/D20053



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


[PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added reviewers: klimek, aaron.ballman.
etienneb added subscribers: cfe-commits, alexfh, sbenza.

This patch moves the enum definitions to a definition (.def) file.

These modifications provide way to list enumerator of a given type.

As an example, this allow parsing of "kinds" in the dynamic matchers.
see: http://reviews.llvm.org/D19871
The dynamic matcher "ofKind" also required this patch to be fixed.

http://reviews.llvm.org/D20207

Files:
  include/clang/AST/OperationKinds.def
  include/clang/AST/OperationKinds.h
  include/clang/module.modulemap
  lib/AST/Expr.cpp

Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -1084,20 +1084,8 @@
 /// corresponds to, e.g. "sizeof" or "[pre]++".
 StringRef UnaryOperator::getOpcodeStr(Opcode Op) {
   switch (Op) {
-  case UO_PostInc: return "++";
-  case UO_PostDec: return "--";
-  case UO_PreInc:  return "++";
-  case UO_PreDec:  return "--";
-  case UO_AddrOf:  return "&";
-  case UO_Deref:   return "*";
-  case UO_Plus:return "+";
-  case UO_Minus:   return "-";
-  case UO_Not: return "~";
-  case UO_LNot:return "!";
-  case UO_Real:return "__real";
-  case UO_Imag:return "__imag";
-  case UO_Extension: return "__extension__";
-  case UO_Coawait: return "co_await";
+#define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling;
+#include "clang/AST/OperationKinds.def"
   }
   llvm_unreachable("Unknown unary operator");
 }
@@ -1608,120 +1596,9 @@
 
 const char *CastExpr::getCastKindName() const {
   switch (getCastKind()) {
-  case CK_Dependent:
-return "Dependent";
-  case CK_BitCast:
-return "BitCast";
-  case CK_LValueBitCast:
-return "LValueBitCast";
-  case CK_LValueToRValue:
-return "LValueToRValue";
-  case CK_NoOp:
-return "NoOp";
-  case CK_BaseToDerived:
-return "BaseToDerived";
-  case CK_DerivedToBase:
-return "DerivedToBase";
-  case CK_UncheckedDerivedToBase:
-return "UncheckedDerivedToBase";
-  case CK_Dynamic:
-return "Dynamic";
-  case CK_ToUnion:
-return "ToUnion";
-  case CK_ArrayToPointerDecay:
-return "ArrayToPointerDecay";
-  case CK_FunctionToPointerDecay:
-return "FunctionToPointerDecay";
-  case CK_NullToMemberPointer:
-return "NullToMemberPointer";
-  case CK_NullToPointer:
-return "NullToPointer";
-  case CK_BaseToDerivedMemberPointer:
-return "BaseToDerivedMemberPointer";
-  case CK_DerivedToBaseMemberPointer:
-return "DerivedToBaseMemberPointer";
-  case CK_ReinterpretMemberPointer:
-return "ReinterpretMemberPointer";
-  case CK_UserDefinedConversion:
-return "UserDefinedConversion";
-  case CK_ConstructorConversion:
-return "ConstructorConversion";
-  case CK_IntegralToPointer:
-return "IntegralToPointer";
-  case CK_PointerToIntegral:
-return "PointerToIntegral";
-  case CK_PointerToBoolean:
-return "PointerToBoolean";
-  case CK_ToVoid:
-return "ToVoid";
-  case CK_VectorSplat:
-return "VectorSplat";
-  case CK_IntegralCast:
-return "IntegralCast";
-  case CK_BooleanToSignedIntegral:
-return "BooleanToSignedIntegral";
-  case CK_IntegralToBoolean:
-return "IntegralToBoolean";
-  case CK_IntegralToFloating:
-return "IntegralToFloating";
-  case CK_FloatingToIntegral:
-return "FloatingToIntegral";
-  case CK_FloatingCast:
-return "FloatingCast";
-  case CK_FloatingToBoolean:
-return "FloatingToBoolean";
-  case CK_MemberPointerToBoolean:
-return "MemberPointerToBoolean";
-  case CK_CPointerToObjCPointerCast:
-return "CPointerToObjCPointerCast";
-  case CK_BlockPointerToObjCPointerCast:
-return "BlockPointerToObjCPointerCast";
-  case CK_AnyPointerToBlockPointerCast:
-return "AnyPointerToBlockPointerCast";
-  case CK_ObjCObjectLValueCast:
-return "ObjCObjectLValueCast";
-  case CK_FloatingRealToComplex:
-return "FloatingRealToComplex";
-  case CK_FloatingComplexToReal:
-return "FloatingComplexToReal";
-  case CK_FloatingComplexToBoolean:
-return "FloatingComplexToBoolean";
-  case CK_FloatingComplexCast:
-return "FloatingComplexCast";
-  case CK_FloatingComplexToIntegralComplex:
-return "FloatingComplexToIntegralComplex";
-  case CK_IntegralRealToComplex:
-return "IntegralRealToComplex";
-  case CK_IntegralComplexToReal:
-return "IntegralComplexToReal";
-  case CK_IntegralComplexToBoolean:
-return "IntegralComplexToBoolean";
-  case CK_IntegralComplexCast:
-return "IntegralComplexCast";
-  case CK_IntegralComplexToFloatingComplex:
-return "IntegralComplexToFloatingComplex";
-  case CK_ARCConsumeObject:
-return "ARCConsumeObject";
-  case CK_ARCProduceObject:
-return "ARCProduceObject";
-  case CK_ARCReclaimReturnedObject:
-return "ARCReclaimReturnedObject";
-  case CK_ARCExtendBlockObject:
-return "ARCExtendBlockObject";
-  case CK_AtomicToNonAtomic:
-return "AtomicToNonAtomic";
-

Re: [PATCH] D20119: [libunwind] Improve unwinder stack usage

2016-05-12 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

Gentle ping.


http://reviews.llvm.org/D20119



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


Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-05-12 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added inline comments.


Comment at: clang-tidy/modernize/UseUsingCheck.cpp:13
@@ +12,3 @@
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 
+

Prazek wrote:
> Is this required?
It'll be reasonable to run Include What You Use at least on new files.


Repository:
  rL LLVM

http://reviews.llvm.org/D18919



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


Re: [PATCH] D17981: [clang-tidy] Fix clang-tidy to support parsing of assembly statements.

2016-05-12 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

Manuel, ping.


http://reviews.llvm.org/D17981



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


Re: [PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57043.
etienneb added a comment.
Herald added a subscriber: klimek.

rebase over AST modifications


http://reviews.llvm.org/D20207

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,13 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() &&  
+  getCastKind(Value.getString()) != CK_Invalid;
+  }
+  static clang::CastKind get(const VariantValue &Value) {
+return getCastKind(Value.getString());
+  }
+  static ArgKind getKind() {
+return ArgKind(ArgKind::AK_String);
+  }
+};
+
 /// \brief Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3551,6 +3551,17 @@
   InnerMatcher.matches(*SubExpression, Finder, Builder));
 }
 
+/// \brief Matches casts that has a given cast kind.
+///
+/// Example: matches the implicit cast around \c 0
+/// (matcher = castExpr(hasCastKind(CK_NullToPointer)))
+/// \code
+///   int *p = 0;
+/// \endcode
+AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
+  return Node.getCastKind() == Kind;
+}
+
 /// \brief Matches casts whose destination type matches a given matcher.
 ///
 /// (Note: Clang's AST refers to other conversions as "casts" too, and calls


Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,13 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return 

Re: Patch submission for bug 27400

2016-05-12 Thread Mads Ravn via cfe-commits
Hi,

I have fixed the things you mentioned now. I have attached the new patch to
this email.

Best regards,
Mads Ravn

On Wed, May 11, 2016 at 11:54 PM Vedant Kumar  wrote:

> Hi,
>
> Thanks for the patch!
>
> This patch is missing a small, lit-style test case. You can find examples
> of test cases here:
>
>   extra/test/clang-tidy/
>
> Apart from that, my only other nit-pick is that llvm uses 2-space indents,
> and spaces between "if" and "(".
>
> If you reply to this list with an updated patch, someone would be happy to
> commit it for you.
>
> best
> vedant
>
> > On May 11, 2016, at 10:01 AM, Mads Ravn via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > Hi,
> >
> > I would like to submit a patch for
> https://llvm.org/bugs/show_bug.cgi?id=27400 .
> >
> > Beside attaching the patch, is there anything I should be aware of? I
> have not submitted a patch before.
> >
> > You can find the patch attached to this mail.
> >
> > Kind regards,
> > Mads Ravn
> >
> ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
Index: clang-tidy/misc/MacroParenthesesCheck.cpp
===
--- clang-tidy/misc/MacroParenthesesCheck.cpp	(revision 268956)
+++ clang-tidy/misc/MacroParenthesesCheck.cpp	(working copy)
@@ -184,6 +184,9 @@
 Next.isOneOf(tok::comma, tok::greater))
   continue;
 
+if (Prev.is(tok::kw_namespace))
+  continue;
+
 Check->diag(Tok.getLocation(), "macro argument should be enclosed in "
"parentheses")
 << FixItHint::CreateInsertion(Tok.getLocation(), "(")
Index: test/clang-tidy/misc-macro-parentheses.cpp
===
--- test/clang-tidy/misc-macro-parentheses.cpp	(revision 268956)
+++ test/clang-tidy/misc-macro-parentheses.cpp	(working copy)
@@ -36,6 +36,7 @@
 #define GOOD25(t) std::set s
 #define GOOD26(x) (a->*x)
 #define GOOD27(x) (a.*x)
+#define GOOD28(x) namespace x {int b;}
 
 // These are allowed for now..
 #define MAYBE1*12.34
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19871: Add an AST matcher for CastExpr kind

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57044.
etienneb marked an inline comment as done.
etienneb added a comment.

rebase over AST modifications


http://reviews.llvm.org/D19871

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,13 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() &&  
+  getCastKind(Value.getString()) != CK_Invalid;
+  }
+  static clang::CastKind get(const VariantValue &Value) {
+return getCastKind(Value.getString());
+  }
+  static ArgKind getKind() {
+return ArgKind(ArgKind::AK_String);
+  }
+};
+
 /// \brief Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3551,6 +3551,17 @@
   InnerMatcher.matches(*SubExpression, Finder, Builder));
 }
 
+/// \brief Matches casts that has a given cast kind.
+///
+/// Example: matches the implicit cast around \c 0
+/// (matcher = castExpr(hasCastKind(CK_NullToPointer)))
+/// \code
+///   int *p = 0;
+/// \endcode
+AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
+  return Node.getCastKind() == Kind;
+}
+
 /// \brief Matches casts whose destination type matches a given matcher.
 ///
 /// (Note: Clang's AST refers to other conversions as "casts" too, and calls


Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3485,6 +3485,13 @@
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }
 
+TEST(CastExpression, HasCastKind) {
+  EXPECT_TRUE(matches("char *p = 0;",
+  castExpr(hasCastKind(CK_NullToPointer;
+  EXPECT_TRUE(notMatches("char *p = 0;",
+  castExpr(hasCastKind(CK_DerivedToBase;
+}
+
 TEST(ReinterpretCast, MatchesSimpleCase) {
   EXPECT_TRUE(matches("char* p = reinterpret_cast(&p);",
   cxxReinterpretCastExpr()));
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasBody);
   REGISTER_MATCHER(hasCanonicalType);
   REGISTER_MATCHER(hasCaseConstant);
+  REGISTER_MATCHER(hasCastKind);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
   REGISTER_MATCHER(hasDecayedType);
Index: lib/ASTMatchers/Dynamic/Marshallers.h
===
--- lib/ASTMatchers/Dynamic/Marshallers.h
+++ lib/ASTMatchers/Dynamic/Marshallers.h
@@ -96,6 +96,28 @@
   }
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#include "clang/AST/OperationKinds.def"
+.Default(CK_Invalid);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+   

Re: [PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 57045.
etienneb added a comment.

remove incorrect patch upload (sorry)


http://reviews.llvm.org/D20207

Files:
  include/clang/AST/OperationKinds.def
  include/clang/AST/OperationKinds.h
  include/clang/module.modulemap
  lib/AST/Expr.cpp

Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -1084,20 +1084,8 @@
 /// corresponds to, e.g. "sizeof" or "[pre]++".
 StringRef UnaryOperator::getOpcodeStr(Opcode Op) {
   switch (Op) {
-  case UO_PostInc: return "++";
-  case UO_PostDec: return "--";
-  case UO_PreInc:  return "++";
-  case UO_PreDec:  return "--";
-  case UO_AddrOf:  return "&";
-  case UO_Deref:   return "*";
-  case UO_Plus:return "+";
-  case UO_Minus:   return "-";
-  case UO_Not: return "~";
-  case UO_LNot:return "!";
-  case UO_Real:return "__real";
-  case UO_Imag:return "__imag";
-  case UO_Extension: return "__extension__";
-  case UO_Coawait: return "co_await";
+#define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling;
+#include "clang/AST/OperationKinds.def"
   }
   llvm_unreachable("Unknown unary operator");
 }
@@ -1608,120 +1596,9 @@
 
 const char *CastExpr::getCastKindName() const {
   switch (getCastKind()) {
-  case CK_Dependent:
-return "Dependent";
-  case CK_BitCast:
-return "BitCast";
-  case CK_LValueBitCast:
-return "LValueBitCast";
-  case CK_LValueToRValue:
-return "LValueToRValue";
-  case CK_NoOp:
-return "NoOp";
-  case CK_BaseToDerived:
-return "BaseToDerived";
-  case CK_DerivedToBase:
-return "DerivedToBase";
-  case CK_UncheckedDerivedToBase:
-return "UncheckedDerivedToBase";
-  case CK_Dynamic:
-return "Dynamic";
-  case CK_ToUnion:
-return "ToUnion";
-  case CK_ArrayToPointerDecay:
-return "ArrayToPointerDecay";
-  case CK_FunctionToPointerDecay:
-return "FunctionToPointerDecay";
-  case CK_NullToMemberPointer:
-return "NullToMemberPointer";
-  case CK_NullToPointer:
-return "NullToPointer";
-  case CK_BaseToDerivedMemberPointer:
-return "BaseToDerivedMemberPointer";
-  case CK_DerivedToBaseMemberPointer:
-return "DerivedToBaseMemberPointer";
-  case CK_ReinterpretMemberPointer:
-return "ReinterpretMemberPointer";
-  case CK_UserDefinedConversion:
-return "UserDefinedConversion";
-  case CK_ConstructorConversion:
-return "ConstructorConversion";
-  case CK_IntegralToPointer:
-return "IntegralToPointer";
-  case CK_PointerToIntegral:
-return "PointerToIntegral";
-  case CK_PointerToBoolean:
-return "PointerToBoolean";
-  case CK_ToVoid:
-return "ToVoid";
-  case CK_VectorSplat:
-return "VectorSplat";
-  case CK_IntegralCast:
-return "IntegralCast";
-  case CK_BooleanToSignedIntegral:
-return "BooleanToSignedIntegral";
-  case CK_IntegralToBoolean:
-return "IntegralToBoolean";
-  case CK_IntegralToFloating:
-return "IntegralToFloating";
-  case CK_FloatingToIntegral:
-return "FloatingToIntegral";
-  case CK_FloatingCast:
-return "FloatingCast";
-  case CK_FloatingToBoolean:
-return "FloatingToBoolean";
-  case CK_MemberPointerToBoolean:
-return "MemberPointerToBoolean";
-  case CK_CPointerToObjCPointerCast:
-return "CPointerToObjCPointerCast";
-  case CK_BlockPointerToObjCPointerCast:
-return "BlockPointerToObjCPointerCast";
-  case CK_AnyPointerToBlockPointerCast:
-return "AnyPointerToBlockPointerCast";
-  case CK_ObjCObjectLValueCast:
-return "ObjCObjectLValueCast";
-  case CK_FloatingRealToComplex:
-return "FloatingRealToComplex";
-  case CK_FloatingComplexToReal:
-return "FloatingComplexToReal";
-  case CK_FloatingComplexToBoolean:
-return "FloatingComplexToBoolean";
-  case CK_FloatingComplexCast:
-return "FloatingComplexCast";
-  case CK_FloatingComplexToIntegralComplex:
-return "FloatingComplexToIntegralComplex";
-  case CK_IntegralRealToComplex:
-return "IntegralRealToComplex";
-  case CK_IntegralComplexToReal:
-return "IntegralComplexToReal";
-  case CK_IntegralComplexToBoolean:
-return "IntegralComplexToBoolean";
-  case CK_IntegralComplexCast:
-return "IntegralComplexCast";
-  case CK_IntegralComplexToFloatingComplex:
-return "IntegralComplexToFloatingComplex";
-  case CK_ARCConsumeObject:
-return "ARCConsumeObject";
-  case CK_ARCProduceObject:
-return "ARCProduceObject";
-  case CK_ARCReclaimReturnedObject:
-return "ARCReclaimReturnedObject";
-  case CK_ARCExtendBlockObject:
-return "ARCExtendBlockObject";
-  case CK_AtomicToNonAtomic:
-return "AtomicToNonAtomic";
-  case CK_NonAtomicToAtomic:
-return "NonAtomicToAtomic";
-  case CK_CopyAndAutoreleaseBlockObject:
-return "CopyAndAutoreleaseBlockObject";
-  case CK_BuiltinFnToFnPtr:
-return "BuiltinFnToFnPtr";
-  case CK_ZeroToOCLEvent:
-return "ZeroToOCLEvent";
-  case CK_AddressSpaceConversion:
-return "AddressSpaceConversion

[PATCH] D20208: clang-format: [JS] fix template string width counting.

2016-05-12 Thread Martin Probst via cfe-commits
mprobst created this revision.
mprobst added reviewers: djasper, bkramer.
mprobst added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Simply looking at the final text greatly simplifies the algorithm and also
fixes a reported issue. This requires duplicating the "actual encoding width"
logic, but that seems cleaner than the column acrobatics before.

http://reviews.llvm.org/D20208

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1076,6 +1076,8 @@
getGoogleJSStyleWithColumns(34)); // Barely doesn't fit.
   verifyFormat("var x = `hello ${world}` >= some();",
getGoogleJSStyleWithColumns(35)); // Barely fits.
+  verifyFormat("var x = `hellö ${wörld}` >= söme();",
+   getGoogleJSStyleWithColumns(35)); // Fits due to UTF-8.
   verifyFormat("var x = `hello\n"
 "  ${world}` >=\n"
 "some();",
@@ -1097,6 +1099,13 @@
getGoogleJSStyleWithColumns(13));
   verifyFormat("aaa(\n"
"`a`);");
+  // Repro for an obscure width-miscounting issue with template strings.
+  verifyFormat(
+  "someLongVariable =\n"
+  ""
+  "`${logPrefix[11]}/${logPrefix[12]}/${logPrefix[13]}${logPrefix[14]}`;",
+  "someLongVariable = "
+  "`${logPrefix[11]}/${logPrefix[12]}/${logPrefix[13]}${logPrefix[14]}`;");
 
   // Make sure template strings get a proper ColumnWidth assigned, even if they
   // are first token in line.
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1010,70 +1010,48 @@
   return false;
 
 unsigned TokenCount = 0;
-bool IsMultiline = false;
-unsigned EndColumnInFirstLine =
-EndBacktick->OriginalColumn + EndBacktick->ColumnWidth;
 for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; I++) {
   ++TokenCount;
-  if (I[0]->IsMultiline)
-IsMultiline = true;
 
   // If there was a preceding template string, this must be the start of a
   // template string, not the end.
   if (I[0]->is(TT_TemplateString))
 return false;
 
-  if (I[0]->isNot(tok::unknown) || I[0]->TokenText != "`") {
-// Keep track of the rhs offset of the last token to wrap across lines -
-// its the rhs offset of the first line of the template string, used to
-// determine its width.
-if (I[0]->IsMultiline)
-  EndColumnInFirstLine = I[0]->OriginalColumn + I[0]->ColumnWidth;
-// If the token has newlines, the token before it (if it exists) is the
-// rhs end of the previous line.
-if (I[0]->NewlinesBefore > 0 && (I + 1 != E)) {
-  EndColumnInFirstLine = I[1]->OriginalColumn + I[1]->ColumnWidth;
-  IsMultiline = true;
-}
+  if (I[0]->isNot(tok::unknown) || I[0]->TokenText != "`")
 continue;
-  }
 
   Tokens.resize(Tokens.size() - TokenCount);
-  Tokens.back()->Type = TT_TemplateString;
+  FormatToken *TemplateStringToken = Tokens.back();
+  TemplateStringToken->Type = TT_TemplateString;
   const char *EndOffset =
   EndBacktick->TokenText.data() + 1 + CommentBacktickPos;
   if (CommentBacktickPos != 0) {
 // If the backtick was not the first character (e.g. in a comment),
 // re-lex after the backtick position.
 SourceLocation Loc = EndBacktick->Tok.getLocation();
 resetLexer(SourceMgr.getFileOffset(Loc) + CommentBacktickPos + 1);
   }
-  Tokens.back()->TokenText =
-  StringRef(Tokens.back()->TokenText.data(),
-EndOffset - Tokens.back()->TokenText.data());
-
-  unsigned EndOriginalColumn = EndBacktick->OriginalColumn;
-  if (EndOriginalColumn == 0) {
-SourceLocation Loc = EndBacktick->Tok.getLocation();
-EndOriginalColumn = SourceMgr.getSpellingColumnNumber(Loc);
-  }
-  // If the ` is further down within the token (e.g. in a comment).
-  EndOriginalColumn += CommentBacktickPos;
-
-  if (IsMultiline) {
-// ColumnWidth is from backtick to last token in line.
-// LastLineColumnWidth is 0 to backtick.
-// x = `some content
-// until here`;
-Tokens.back()->ColumnWidth =
-EndColumnInFirstLine - Tokens.back()->OriginalColumn;
-// +1 for the ` itself.
-Tokens.back()->LastLineColumnWidth = EndOriginalColumn + 1;
-Tokens.back()->IsMultiline = true;
-  } else {
-// Token simply spans from start to end, +1 for the ` itself.
-Tokens.back()->ColumnWidth =
-EndOriginalColumn - Tokens.back()->OriginalColumn + 1;
+  StringRef Litera

Re: [PATCH] D19871: Add an AST matcher for CastExpr kind

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb marked 3 inline comments as done.
etienneb added a comment.

This patch has been modified to support dynamic matchers.
It rely on : http://reviews.llvm.org/D20207

Comments?



Comment at: lib/ASTMatchers/Dynamic/Marshallers.h:102
@@ +101,3 @@
+  static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
+return llvm::StringSwitch(AttrKind)
+#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)

moved to that solution. (let try it)


Comment at: lib/ASTMatchers/Dynamic/Registry.cpp:78
@@ -77,2 +77,3 @@
   // Need Variant/Parser fixes:
+  // hasCastKind  
   // ofKind

sbenza wrote:
> Is it registered or not?
> You add this comment, but also add the matcher in the registry below.
bad revert.
I'm making a patch to allow dynamic matcher, and I'll come back fixing this CL.


http://reviews.llvm.org/D19871



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


Re: [PATCH] D20205: [include-fixer] Use scope contexts information to improve query.

2016-05-12 Thread Benjamin Kramer via cfe-commits
bkramer requested changes to this revision.
bkramer added a comment.
This revision now requires changes to proceed.

This needs more tests (check that using stuff from a different namespace in 
namespace scope still works). It's also better written as a unit test against 
the in-memory database, that way we don't have to create a file for every test.


Repository:
  rL LLVM

http://reviews.llvm.org/D20205



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


Re: [PATCH] D20203: [find-all-symbols] Add enum type support.

2016-05-12 Thread Benjamin Kramer via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


Repository:
  rL LLVM

http://reviews.llvm.org/D20203



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


Re: [PATCH] D20170: [clang-tidy] TypeTraits - Type is not expensive to copy when it has a deleted copy constructor.

2016-05-12 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-tidy/utils/TypeTraits.cpp:22
@@ +21,3 @@
+
+using namespace ::clang::ast_matchers;
+

Now seems to be unused.


http://reviews.llvm.org/D20170



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


Re: [PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Aaron Ballman via cfe-commits
aaron.ballman added a reviewer: rsmith.
aaron.ballman added a comment.

Generally, I think this looks good. It will definitely help with AST matchers. 
Richard, do you have any problems with this approach?



Comment at: include/clang/AST/OperationKinds.def:15
@@ +14,3 @@
+//
+/// @file OperationKinds.def
+///

Do we use @file doxygen comments usually? I'm not certain if I've never seen 
them, or if I'm just unobservant.


http://reviews.llvm.org/D20207



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


Re: [PATCH] D20196: [clang-tidy] Inefficient string operation

2016-05-12 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a subscriber: Eugene.Zelenko.
Eugene.Zelenko added a comment.

Please mention this check in docs/ReleaseNotes.rst (in alphabetical order).



Comment at: docs/clang-tidy/checks/performance-inefficient-string-addition.rst:8
@@ +7,3 @@
+--
+This check is to warn about the performance overhead arising from 
concatenating strings, using the operator+, for instance:
+

Please highlight operator+ and other class/methods with ``. Same for other 
places in documentation.


Comment at: 
docs/clang-tidy/checks/performance-inefficient-string-addition.rst:21
@@ +20,3 @@
+   
+   std::string a = "Foo", b = "Baz";
+   for(int i = 0; i < 2; ++i)

Please use constructor initialization instead of assignment.


Comment at: 
docs/clang-tidy/checks/performance-inefficient-string-addition.rst:58
@@ +57,1 @@
+   }
\ No newline at end of file


Please add new line.


Comment at: test/clang-tidy/performance-inefficient-string-addition.cpp:1
@@ +1,2 @@
+// RUN: %check_clang_tidy %s performance-inefficient-string-addition %t -- -- 
-std=c++11
+

Does it really need to be C++11?


Comment at: test/clang-tidy/performance-inefficient-string-addition.cpp:45
@@ +44,1 @@
+}
\ No newline at end of file

Please add new line.


http://reviews.llvm.org/D20196



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


[PATCH] D20213: [Clang] Fix Clang-tidy modernize-use-bool-literals in generated code.

2016-05-12 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko created this revision.
Eugene.Zelenko added reviewers: hans, aaron.ballman.
Eugene.Zelenko added a subscriber: cfe-commits.
Eugene.Zelenko set the repository for this revision to rL LLVM.

Reduce space in empty constructors and between data members and first public 
section.

Fix some Include What You Use warnings.


Repository:
  rL LLVM

http://reviews.llvm.org/D20213

Files:
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -11,24 +11,36 @@
 //
 //===--===//
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/StringMatcher.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 using namespace llvm;
 
 namespace {
+
 class FlattenedSpelling {
   std::string V, N, NS;
   bool K;
@@ -54,6 +66,7 @@
   const std::string &nameSpace() const { return NS; }
   bool knownToGCC() const { return K; }
 };
+
 } // end anonymous namespace
 
 static std::vector
@@ -159,6 +172,7 @@
 }
 
 namespace {
+
   class Argument {
 std::string lowerName, upperName;
 StringRef attrName;
@@ -230,35 +244,45 @@
   OS << "return " << getLowerName() << ";\n";
   OS << "  }";
 }
+
 void writeCloneArgs(raw_ostream &OS) const override {
   OS << getLowerName();
 }
+
 void writeTemplateInstantiationArgs(raw_ostream &OS) const override {
   OS << "A->get" << getUpperName() << "()";
 }
+
 void writeCtorInitializers(raw_ostream &OS) const override {
   OS << getLowerName() << "(" << getUpperName() << ")";
 }
+
 void writeCtorDefaultInitializers(raw_ostream &OS) const override {
   OS << getLowerName() << "()";
 }
+
 void writeCtorParameters(raw_ostream &OS) const override {
   OS << type << " " << getUpperName();
 }
+
 void writeDeclarations(raw_ostream &OS) const override {
   OS << type << " " << getLowerName() << ";";
 }
+
 void writePCHReadDecls(raw_ostream &OS) const override {
   std::string read = ReadPCHRecord(type);
   OS << "" << type << " " << getLowerName() << " = " << read << ";\n";
 }
+
 void writePCHReadArgs(raw_ostream &OS) const override {
   OS << getLowerName();
 }
+
 void writePCHWrite(raw_ostream &OS) const override {
   OS << "" << WritePCHRecord(type, "SA->get" +
std::string(getUpperName()) + "()");
 }
+
 void writeValue(raw_ostream &OS) const override {
   if (type == "FunctionDecl *") {
 OS << "\" << get" << getUpperName()
@@ -271,6 +295,7 @@
 OS << "\" << get" << getUpperName() << "() << \"";
   }
 }
+
 void writeDump(raw_ostream &OS) const override {
   if (type == "FunctionDecl *") {
 OS << "OS << \" \";\n";
@@ -305,8 +330,12 @@
 void writeAccessors(raw_ostream &OS) const override {
   SimpleArgument::writeAccessors(OS);
 
-  OS << "\n\n  static const " << getType() << " Default" << getUpperName()
- << " = " << Default << ";";
+  if (getType() == "bool")
+OS << "\n\n  static const " << getType() << " Default" << getUpperName()
+   << " = " << (Default != 0 ? "true" : "false") << ";";
+  else
+OS << "\n\n  static const " << getType() << " Default" << getUpperName()
+   << " = " << Default << ";";
 }
   };
 
@@ -334,45 +363,57 @@
  << getLowerName() << "Length);\n";
   OS << "  }";
 }
+
 void writeCloneArgs(raw_ostream &OS) const override {
   OS << "get" << getUpperName() << "()";
 }
+
 void writeTemplateInstantiationArgs(raw_ostream &OS) const override {
   OS << "A->get" << getUpperName() << "()";
 }
+
 void writeCtorBody(raw_ostream &OS) const override {
   OS << "  if (!" << getUpperName() << ".empty())\n";
   OS << "std::memcpy(" << getLowerName() << ", " << getUpperName()
- << ".data(), " << getLowerName() << "Length);";
+ << ".data(), " << getLowerName() << "Length);\n";
 }
+
 void writeCtorInitializers(raw_ostream &OS) const override {
   OS << getLowerName() << "Length(" << getUpperName() << ".size()),"
  << getLowerName() << "(new (Ctx, 1) char[" << getLowerName()
  << "Length])";
 }
+
 void writeCtorDefaultInitialize

r269305 - [OpenCL] Output OpenCL version in diagnostics.

2016-05-12 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu May 12 11:28:25 2016
New Revision: 269305

URL: http://llvm.org/viewvc/llvm-project?rev=269305&view=rev
Log:
[OpenCL] Output OpenCL version in diagnostics.

Diagnostics should note version dependent issues by giving
a hint about current version being compiled for.

This patch changes diagnostics of static storage class specifier
and generic type qualifier to specify OpenCL version as well as
converts other diagnostics to match the style.

Patch by Vedran Miletic!

Review: http://reviews.llvm.org/D19780


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/test/Parser/opencl-cl20.cl
cfe/trunk/test/Parser/opencl-storage-class.cl
cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
cfe/trunk/test/SemaOpenCL/storageclass.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=269305&r1=269304&r2=269305&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu May 12 11:28:25 
2016
@@ -7865,13 +7865,13 @@ def err_opencl_builtin_pipe_invalid_acce
 def err_opencl_invalid_access_qualifier : Error<
   "access qualifier can only be used for pipe and image type">;
 def err_opencl_invalid_read_write : Error<
-  "access qualifier %0 can not be used for %1 %select{|earlier than OpenCL2.0 
version}2">;
+  "access qualifier %0 can not be used for %1 %select{|earlier than OpenCL 
version 2.0}2">;
 def err_opencl_multiple_access_qualifiers : Error<
   "multiple access qualifiers">;
 
 // OpenCL Section 6.8.g
 def err_opencl_unknown_type_specifier : Error<
-  "OpenCL does not support the '%0' %select{type qualifier|storage class 
specifier}1">;
+  "OpenCL version %0 does not support the '%1' %select{type qualifier|storage 
class specifier}2">;
 
 // OpenCL v2.0 s6.12.5 Blocks restrictions
 def err_opencl_block_storage_type : Error<

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=269305&r1=269304&r2=269305&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu May 12 11:28:25 2016
@@ -28,6 +28,7 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/ScopedPrinter.h"
 
 using namespace clang;
 
@@ -3514,9 +3515,13 @@ void Parser::ParseDeclarationSpecifiers(
   if (DiagID == diag::ext_duplicate_declspec)
 Diag(Tok, DiagID)
   << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation());
-  else if (DiagID == diag::err_opencl_unknown_type_specifier)
-Diag(Tok, DiagID) << PrevSpec << isStorageClass;
-  else
+  else if (DiagID == diag::err_opencl_unknown_type_specifier) {
+const int OpenCLVer = getLangOpts().OpenCLVersion;
+std::string VerSpec = llvm::to_string(OpenCLVer / 100) +
+  std::string (".") +
+  llvm::to_string((OpenCLVer % 100) / 10);
+Diag(Tok, DiagID) << VerSpec << PrevSpec << isStorageClass;
+  } else
 Diag(Tok, DiagID) << PrevSpec;
 }
 

Modified: cfe/trunk/test/Parser/opencl-cl20.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/opencl-cl20.cl?rev=269305&r1=269304&r2=269305&view=diff
==
--- cfe/trunk/test/Parser/opencl-cl20.cl (original)
+++ cfe/trunk/test/Parser/opencl-cl20.cl Thu May 12 11:28:25 2016
@@ -10,9 +10,9 @@ __generic int * __generic_test(__generic
   return var;  
 }
 #ifndef CL20
-// expected-error@-5 {{OpenCL does not support the '__generic' type qualifier}}
-// expected-error@-6 {{OpenCL does not support the '__generic' type qualifier}}
-// expected-error@-6 {{OpenCL does not support the '__generic' type qualifier}}
+// expected-error@-5 {{OpenCL version 1.0 does not support the '__generic' 
type qualifier}}
+// expected-error@-6 {{OpenCL version 1.0 does not support the '__generic' 
type qualifier}}
+// expected-error@-6 {{OpenCL version 1.0 does not support the '__generic' 
type qualifier}}
 #endif
 
 generic int * generic_test(generic int *arg) {
@@ -20,7 +20,7 @@ generic int * generic_test(generic int *
   return var;  
 }
 #ifndef CL20
-// expected-error@-5 {{OpenCL does not support the 'generic' type qualifier}}
-// expected-error@-6 {{OpenCL does not support the 'generic' type qualifier}}
-// expected-error@-6 {{OpenCL does not support the 'generic' type qualifier}}
+// expected-error@-5 {{OpenCL version 1.0 does not support the 'generic' type 
qualifier}}
+// expected-error@-6 {{OpenCL version 1.0 does not support the 'generic' 

Re: [PATCH] D19780: Output OpenCL version in Clang diagnostics

2016-05-12 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

Sure. Committed in r269305!

Thanks!


http://reviews.llvm.org/D19780



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


Re: [PATCH] D19815: Support '#pragma once' in headers when using PCH

2016-05-12 Thread Warren Ristow via cfe-commits
wristow added a comment.

Ping


http://reviews.llvm.org/D19815



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


Re: [PATCH] D19932: [OpenCL] Add to_{global|local|private} builtin functions.

2016-05-12 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:501
@@ -500,1 +500,3 @@
 def err_builtin_needs_feature : Error<"%0 needs target feature %1">;
+def err_builtin_needs_opencl_version
+: Error<"%0 needs OpenCL version %1%select{| or above}2">;

Could we move this to all the other OpenCL diagnostics to have them grouped 
together?


Comment at: lib/Sema/SemaChecking.cpp:463
@@ +462,3 @@
+// \return True if a semantic error has been found, false otherwise.
+static bool SemaBuiltinToAddr(Sema &S, unsigned BuiltinID, CallExpr *Call) {
+  // OpenCL v2.0 s6.13.9 - Address space qualifier functions.

Could we rename this please to SemaOpenCLBuiltinToAddr.

I think Pipe functions should be better renamed too at some point.


Comment at: lib/Sema/SemaChecking.cpp:478
@@ +477,3 @@
+  auto RT = Call->getArg(0)->getType();
+  if (!RT->isPointerType() || RT->getPointeeType().getCanonicalType()
+  .getQualifiers().getAddressSpace() == LangAS::opencl_constant) {

Could the second check be written a bit simpler? I have a feeling something 
like this might work too:
  RT->getPointeeType().getAddressSpace()



Comment at: lib/Sema/SemaChecking.cpp:485
@@ +484,3 @@
+
+  RT = RT->getPointeeType().getCanonicalType();
+  auto Qual = RT.getQualifiers();

Is canonical type really necessary here?


http://reviews.llvm.org/D19932



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


Re: [PATCH] D19804: Make clang-format cleaner remove redundant commas in list and redundant colon in constructor initializer.

2016-05-12 Thread Daniel Jasper via cfe-commits
djasper added a comment.

I experimented a bit. What do you think of this?



Comment at: lib/Format/Format.cpp:1822
@@ +1821,3 @@
+cleanupRight(Line->First, Line->Last, tok::comma, tok::comma);
+checkConstructorInitList(*Line);
+  }

You could turn this into:

for (auto &Line : AnnotatedLines) {
  if (Line->Affected) {
cleanupRight(Line->First, tok::comma, tok::comma);
cleanupRight(Line->First, TT_CtorInitializerColon, tok::comma);
cleanupLeft(Line->First, tok::comma, tok::l_brace);
cleanupLeft(Line->First, TT_CtorInitializerColon, tok::l_brace);
  }
}


Comment at: lib/Format/Format.cpp:1914
@@ -1906,1 +1913,3 @@
 
+  FormatToken *getNextTokenNotDeletedUntilEnd(const FormatToken *Tok,
+  const FormatToken *End,

And all of this into:

  // Checks pairs {start, start->next},..., {end->previous, end} and deletes one
  // of the token in the pair if the left token has \p LK token kind and the
  // right token has \p RK token kind. If \p DeleteLeft is true, the left token
  // is deleted on match; otherwise, the right token is deleted.
  template 
  void cleanupPair(FormatToken *Start, LeftKind LK, RightKind RK,
   bool DeleteLeft) {
auto NextNotDeleted = [this](const FormatToken &Tok) -> FormatToken * {
  for (auto *Res = Tok.Next; Res; Res = Res->Next)
if (!Res->is(tok::comment) &&
DeletedTokens.find(Res) == DeletedTokens.end())
  return Res;
  return nullptr;
};
for (auto *Left = Start; Left;) {
  auto *Right = NextNotDeleted(*Left);
  if (!Right)
break;
  if (Left->is(LK) && Right->is(RK)) {
deleteToken(DeleteLeft ? Left : Right);
// If the right token is deleted, we should keep the left token
// unchanged and pair it with the new right token.
if (!DeleteLeft)
  continue;
  }
  Left = Right;
}
  }

  template 
  void cleanupLeft(FormatToken *Start, LeftKind LK, RightKind RK) {
cleanupPair(Start, LK, RK, /*DeleteLeft=*/true);
  }

  template 
  void cleanupRight(FormatToken *Start, LeftKind LK, RightKind RK) {
cleanupPair(Start, LK, RK, /*DeleteLeft=*/false);
  }




http://reviews.llvm.org/D19804



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


Re: [PATCH] D20213: [Clang] Fix Clang-tidy modernize-use-bool-literals in generated code.

2016-05-12 Thread Hans Wennborg via cfe-commits
hans added inline comments.


Comment at: utils/TableGen/ClangAttrEmitter.cpp:338
@@ -310,1 +337,3 @@
+OS << "\n\n  static const " << getType() << " Default" << 
getUpperName()
+   << " = " << Default << ";";
 }

Everything up to the " = " part is the same for the two branches of the if 
statements.

Maybe re-write this as

```
OS << "\n\n  static const  = ";
if (getType() == "bool")
  OS << true or false..
else
  OS << Default..
```


Repository:
  rL LLVM

http://reviews.llvm.org/D20213



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


Re: [PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb marked an inline comment as done.
etienneb added a comment.





Comment at: include/clang/AST/OperationKinds.def:15
@@ +14,3 @@
+//
+/// @file OperationKinds.def
+///

aaron.ballman wrote:
> Do we use @file doxygen comments usually? I'm not certain if I've never seen 
> them, or if I'm just unobservant.
I can't tell if it's largely used.

I based my modifications on 'include/clang/Basic/OperatorKinds.def'

https://llvm.org/svn/llvm-project/cfe/trunk/include/clang/Basic/OperatorKinds.def
And there are doxygen comments.


http://reviews.llvm.org/D20207



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


Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-12 Thread Alexander Makarov via cfe-commits
a.makarov updated this revision to Diff 57062.
a.makarov added a comment.

Thanks for the review! I've updated the patch, please take a look.
Modifications:

- the dependency from MS compatibility mode is removed;
- the option is renamed into '-fdefault-calling-conv' (since it's not in MS 
compatibility mode);
- the '-mrtd' option is now an alias for '-fdefault-calling-conv=stdcall';
- 'stdcall' is now ignored for variadic functions;
- since 'vectorcall' requires SSE2 or higher 
(https://msdn.microsoft.com/en-us/library/dn375768.aspx) the necessary check is 
added


http://reviews.llvm.org/D20171

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  include/clang/Driver/Options.td
  lib/AST/ASTContext.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/default_calling_conv.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6140,6 +6140,15 @@
   CmdArgs.push_back("-fms-memptr-rep=virtual");
   }
 
+  if (Args.getLastArg(options::OPT__SLASH_Gd))
+ CmdArgs.push_back("-fdefault-calling-conv=cdecl");
+  else if (Args.getLastArg(options::OPT__SLASH_Gr))
+ CmdArgs.push_back("-fdefault-calling-conv=fastcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gz))
+ CmdArgs.push_back("-fdefault-calling-conv=stdcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gv))
+ CmdArgs.push_back("-fdefault-calling-conv=vectorcall");
+
   if (Arg *A = Args.getLastArg(options::OPT_vtordisp_mode_EQ))
 A->render(Args, CmdArgs);
 
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8605,8 +8605,25 @@
   if (IsCXXMethod)
 return ABI->getDefaultMethodCallConv(IsVariadic);
 
-  if (LangOpts.MRTD && !IsVariadic) return CC_X86StdCall;
-
+  switch (LangOpts.getDefaultMSCallingConv()) {
+  case LangOptions::DCC_None:
+break;
+  case LangOptions::DCC_CDecl:
+return CC_C;
+  case LangOptions::DCC_FastCall:
+if (getTargetInfo().hasFeature("sse2"))
+  return CC_X86FastCall;
+break;
+  case LangOptions::DCC_StdCall:
+if (!IsVariadic)
+  return CC_X86StdCall;
+break;
+  case LangOptions::DCC_VectorCall:
+// __vectorcall cannot be applied to variadic functions.
+if (!IsVariadic)
+  return CC_X86VectorCall;
+break;
+  }
   return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
 }
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3895,11 +3895,12 @@
 
 // This convention is not valid for the target. Use the default function or
 // method calling convention.
-TargetInfo::CallingConvMethodType MT = TargetInfo::CCMT_Unknown;
-if (FD)
-  MT = FD->isCXXInstanceMember() ? TargetInfo::CCMT_Member : 
-TargetInfo::CCMT_NonMember;
-CC = TI.getDefaultCallingConv(MT);
+bool isCXXMethod = false, isVariadic = false;
+if (FD) {
+  isCXXMethod = FD->isCXXInstanceMember();
+  isVariadic = FD->isVariadic();
+}
+CC = Context.getDefaultCallingConvention(isVariadic, isCXXMethod);
   }
 
   attr.setProcessingCache((unsigned) CC);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1772,7 +1772,6 @@
   Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
   Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
   Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
-  Opts.MRTD = Args.hasArg(OPT_mrtd);
   Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat);
   Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
   Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
@@ -1849,6 +1848,34 @@
 Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel);
   }
 
+  // Check for MS default calling conventions being specified.
+  if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
+LangOptions::DefaultMSCallingConvention DefaultCC =
+llvm::StringSwitch(
+A->getValue())
+.Case("cdecl", LangOptions::DCC_CDecl)
+.Case("fastcall", LangOptions::DCC_FastCall)
+.Case("stdcall", LangOptions::DCC_StdCall)
+.Case("vectorcall", LangOptions::DCC_VectorCall)
+.Default(LangOptions::DCC_None);
+if (DefaultCC == LangOptions::DCC_None)
+  Diags.Report(diag::err_drv_invalid_value)
+  << "-fdefault-calling-conv=" << A->getValue();
+
+llvm::Triple T(TargetOpts.Triple);
+llvm::Triple::ArchType Arch = 

r269309 - [ubsan] Add -fsanitize-undefined-strip-path-components=N

2016-05-12 Thread Filipe Cabecinhas via cfe-commits
Author: filcab
Date: Thu May 12 11:51:36 2016
New Revision: 269309

URL: http://llvm.org/viewvc/llvm-project?rev=269309&view=rev
Log:
[ubsan] Add -fsanitize-undefined-strip-path-components=N

Summary:
This option allows the user to control how much of the file name is
emitted by UBSan. Tuning this option allows one to save space in the
resulting binary, which is helpful for restricted execution
environments.

With a positive N, UBSan skips the first N path components.
With a negative N, UBSan only keeps the last N path components.

Reviewers: rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19666

Added:
cfe/trunk/test/CodeGen/ubsan-strip-path-components.cpp
cfe/trunk/test/Driver/fubsan-strip-path-components.cpp
Modified:
cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UndefinedBehaviorSanitizer.rst?rev=269309&r1=269308&r2=269309&view=diff
==
--- cfe/trunk/docs/UndefinedBehaviorSanitizer.rst (original)
+++ cfe/trunk/docs/UndefinedBehaviorSanitizer.rst Thu May 12 11:51:36 2016
@@ -228,6 +228,26 @@ UndefinedBehaviorSanitizer is available
 3.3. The test suite is integrated into the CMake build and can be run with
 ``check-ubsan`` command.
 
+Additional Configuration
+
+
+UndefinedBehaviorSanitizer adds static check data for each check unless it is
+in trap mode. This check data includes the full file name. The option
+``-fsanitize-undefined-strip-path-components=N`` can be used to trim this
+information. If ``N`` is positive, file information emitted by
+UndefinedBehaviorSanitizer will drop the first ``N`` components from the file
+path. If ``N`` is negative, the last ``N`` components will be kept.
+
+Example
+---
+
+For a file called ``/code/library/file.cpp``, here is what would be emitted:
+* Default (No flag, or ``-fsanitize-undefined-strip-path-components=0``): 
``/code/library/file.cpp``
+* ``-fsanitize-undefined-strip-path-components=1``: ``code/library/file.cpp``
+* ``-fsanitize-undefined-strip-path-components=2``: ``library/file.cpp``
+* ``-fsanitize-undefined-strip-path-components=-1``: ``file.cpp``
+* ``-fsanitize-undefined-strip-path-components=-2``: ``library/file.cpp``
+
 More Information
 
 

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=269309&r1=269308&r2=269309&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu May 12 11:51:36 2016
@@ -677,6 +677,10 @@ def fsanitize_stats : Flag<["-"], "fsani
 def fno_sanitize_stats : Flag<["-"], "fno-sanitize-stats">,
  Group, Flags<[CC1Option]>,
  HelpText<"Disable sanitizer statistics 
gathering.">;
+def fsanitize_undefined_strip_path_components_EQ : Joined<["-"], 
"fsanitize-undefined-strip-path-components=">,
+  Group, Flags<[CC1Option]>, MetaVarName<"">,
+  HelpText<"Strip (or keep only, if negative) a given number of path 
components "
+   "when emitting check metadata.">;
 def funsafe_math_optimizations : Flag<["-"], "funsafe-math-optimizations">,
   Group;
 def fno_unsafe_math_optimizations : Flag<["-"], 
"fno-unsafe-math-optimizations">,

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=269309&r1=269308&r2=269309&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Thu May 12 11:51:36 2016
@@ -225,6 +225,10 @@ ENUM_CODEGENOPT(VecLib, VectorLibrary, 1
 /// The default TLS model to use.
 ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel)
 
+/// Number of path components to strip when emitting checks. (0 == full
+/// filename)
+VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=269309&r1=269308&r2=269309&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu May 12 11:51:36 2016
@@ -32,6 +32,7 @@
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/Support/Conve

Re: [PATCH] D19666: [ubsan] Add -fubsan-strip-path-components=N

2016-05-12 Thread Filipe Cabecinhas via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269309: [ubsan] Add 
-fsanitize-undefined-strip-path-components=N (authored by filcab).

Changed prior to commit:
  http://reviews.llvm.org/D19666?vs=56396&id=57063#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19666

Files:
  cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/ubsan-strip-path-components.cpp
  cfe/trunk/test/Driver/fubsan-strip-path-components.cpp

Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -677,6 +677,10 @@
 def fno_sanitize_stats : Flag<["-"], "fno-sanitize-stats">,
  Group, Flags<[CC1Option]>,
  HelpText<"Disable sanitizer statistics gathering.">;
+def fsanitize_undefined_strip_path_components_EQ : Joined<["-"], "fsanitize-undefined-strip-path-components=">,
+  Group, Flags<[CC1Option]>, MetaVarName<"">,
+  HelpText<"Strip (or keep only, if negative) a given number of path components "
+   "when emitting check metadata.">;
 def funsafe_math_optimizations : Flag<["-"], "funsafe-math-optimizations">,
   Group;
 def fno_unsafe_math_optimizations : Flag<["-"], "fno-unsafe-math-optimizations">,
Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
===
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def
@@ -225,6 +225,10 @@
 /// The default TLS model to use.
 ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel)
 
+/// Number of path components to strip when emitting checks. (0 == full
+/// filename)
+VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: cfe/trunk/test/Driver/fubsan-strip-path-components.cpp
===
--- cfe/trunk/test/Driver/fubsan-strip-path-components.cpp
+++ cfe/trunk/test/Driver/fubsan-strip-path-components.cpp
@@ -0,0 +1,2 @@
+// RUN: %clang %s -### -o %t.o -fsanitize-undefined-strip-path-components=42 2>&1 | FileCheck %s
+// CHECK: "-fsanitize-undefined-strip-path-components=42"
Index: cfe/trunk/test/CodeGen/ubsan-strip-path-components.cpp
===
--- cfe/trunk/test/CodeGen/ubsan-strip-path-components.cpp
+++ cfe/trunk/test/CodeGen/ubsan-strip-path-components.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -fsanitize=unreachable -o - | FileCheck %s -check-prefix=REGULAR -check-prefix=CHECK
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -fsanitize=unreachable -o - -fsanitize-undefined-strip-path-components=0 | FileCheck %s -check-prefix=REGULAR -check-prefix=CHECK
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -fsanitize=unreachable -o - -fsanitize-undefined-strip-path-components=2 | FileCheck %s -check-prefix=REMOVE-FIRST-TWO -check-prefix=CHECK
+
+// Try to strip too much:
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -fsanitize=unreachable -o - -fsanitize-undefined-strip-path-components=-9 | FileCheck %s -check-prefix=REGULAR
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -fsanitize=unreachable -o - -fsanitize-undefined-strip-path-components=9 | FileCheck %s -check-prefix=LAST-ONLY
+
+// Check stripping from the file name
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -fsanitize=unreachable -o - -fsanitize-undefined-strip-path-components=-2 | FileCheck %s -check-prefix=LAST-TWO
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -fsanitize=unreachable -o - -fsanitize-undefined-strip-path-components=-1 | FileCheck %s -check-prefix=LAST-ONLY
+
+// REGULAR: @[[SRC:[0-9.a-zA-Z_]+]] =  private unnamed_addr constant [{{.*}} x i8] c"{{.*test(.|\\5C)CodeGen(.|\\5C)ubsan-strip-path-components\.cpp}}\00", align 1
+
+// First path component: "/" or "$drive_letter:", then a name, or '\5C' on Windows
+// REMOVE-FIRST-TWO: @[[STR:[0-9.a-zA-Z_]+]] = private unnamed_addr constant [{{.*}} x i8] c"{{(.:|/)([^\\/]*(/|\\5C))}}[[REST:.*ubsan-strip-path-components\.cpp]]\00", align 1
+// REMOVE-FIRST-TWO: @[[SRC:[0-9.a-zA-Z_]+]] = private unnamed_addr constant [{{.*}} x i8] c"[[REST]]\00", align 1
+
+// LAST-TWO: @[[SRC:[0-9.a-zA-Z_]+]] = private unnamed_addr constant [{{.*}} x i8] c"CodeGen{{/|\\5C}}ubsan-strip-path-components.cpp\00", align 1
+// LAST-ONLY: @[[SRC:[0-9.a-zA-Z_]+]] =private unnamed_addr constant [{{.*}} x i8] c"ubsan-strip-path-components.cpp\00", align

Re: [PATCH] D18369: [OpenCL] Upstreaming khronos OpenCL header file.

2016-05-12 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

In http://reviews.llvm.org/D18369#424617, @yaxunl wrote:

> In http://reviews.llvm.org/D18369#424347, @pxli168 wrote:
>
> > In http://reviews.llvm.org/D18369#422367, @yaxunl wrote:
> >
> > > In http://reviews.llvm.org/D18369#421963, @pxli168 wrote:
> > >
> > > > If we want to save some space, could we use some macro to expand the 
> > > > gentype or some script to expand the gentype into each types when the 
> > > > clang is build?
> > >
> > >
> > > We need to balance between space and readability. When I absorbed 
> > > __attribute__((overloadable)) into __const_func to save space, it did not 
> > > sacrifice readability. However using macro with gentype will cause the 
> > > header file more difficult to read.
> >
> >
> > But I don't think this kind of so long header is easy to read, it contains 
> > full pages of the same function with different types and it is hard to see 
> > if anyone is missing or find where these functions end. In spec builtin 
> > functions can be represented by
> >
> > > gentype ctz (gentype x)
> >
> > >  gentype max (gentype x, gentype y)
> >
> > >  gentype max (gentype x, sgentype y)
> >
> >
> > If we could use some macro or script to generate the actual builtin 
> > functions, it seems more likely spec and clear to read, also will avoid 
> > missing or typo.
>
>
> For simple cases, we could define something like this:
>
> #define MATH_FUN(F) \
>  float F(float x); \
>  double F(double x); \
>  half F(half x);
>
> MATH_FUN(sin)
>  MATH_FUN(cos)
>
> It could be concise without sacrificing much clarity. However, for more 
> complicated patterns, like
>
> uchar8 __const_func convert_uchar8_rtn(int8);
>
> It seems hard to balance between readability and brevity. Mostly it will ends 
> up with multiple layers of macros calling each other, and the original 
> function declarations obscured. This also opens Pandora's box of subjectivity 
> of readability.
>
> I think using macro and not using macro both have advantages and 
> disadvantages. That's why I did not take efforts to change one representation 
> to another.
>
> It will take considerable efforts to define all builtin functions as macros, 
> whereas this review already dragged too long.
>
> Anastasia, what's your suggestion? Thanks.


Let's don't exaggerate with macros for this. Using them has negative effect of 
diagnostics being reported about a macro and not the original function, which 
won't conform the Spec any longer.

See my earlier comment to line 6582:

  error: too many arguments provided to function-like macro invocation



Comment at: lib/Headers/opencl-c.h:14057
@@ +14056,3 @@
+event_t __attribute__((overloadable)) async_work_group_copy(__local float2 
*dst, const __global float2 *src, size_t num_elements, event_t event);
+event_t __attribute__((overloadable)) async_work_group_copy(__local char3 
*dst, const __global char3 *src, size_t num_elements, event_t event);
+event_t __attribute__((overloadable)) async_work_group_copy(__local uchar3 
*dst, const __global uchar3 *src, size_t num_elements, event_t event);

yaxunl wrote:
> If this representation is not generic enough. Any suggestion for an 
> alternative? Thanks.
I don't think Spec imposes any specific implementation of this macro.

I am thinking we might better leave it out to allow adding in a way suitable 
for other implementations.


http://reviews.llvm.org/D18369



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


Re: [PATCH] D20198: clang-format: [JS] sort ES6 imports.

2016-05-12 Thread Daniel Jasper via cfe-commits
djasper added inline comments.


Comment at: lib/Format/Format.cpp:21
@@ -19,1 +20,3 @@
 #include "TokenAnnotator.h"
+#include "FormatTokenLexer.h"
+#include "TokenAnalyzer.h"

Use clang-format to fix the order :-)


Comment at: lib/Format/FormatTokenLexer.h:28
@@ +27,3 @@
+
+class FormatTokenLexer {
+public:

I believe it is a bit harmful to have that much code in a header. It now gets 
pulled into multiple translation units and is thus compiled multiple times only 
for the linker to deduplicate it afterwards. We should move the implementation 
in FormatTokenLexer.cpp. I am happy to do that as a follow up, though.


Comment at: lib/Format/SortJavaScriptImports.cpp:54
@@ +53,3 @@
+  JsImportCategory Category;
+  // Empty for `export {a, b};`.
+  StringRef URL;

This comment doesn't really explain what it is and it is not obvious to me.


Comment at: lib/Format/SortJavaScriptImports.cpp:112
@@ +111,3 @@
+  skipComments();
+  if (LastStart.isInvalid() || Imports.empty()) {
+// After the first file level comment, consider line comments to be 
part

No braces.


Comment at: lib/Format/SortJavaScriptImports.cpp:150
@@ +149,3 @@
+
+bool OutOfOrder = false;
+for (unsigned i = 0, e = Indices.size(); i != e; ++i) {

Add:

  // FIXME: Pull this into a common function.


Comment at: lib/Format/SortJavaScriptImports.cpp:162
@@ +161,3 @@
+std::string ImportsText;
+for (unsigned i = 0, e = Indices.size(); i != e; ++i) {
+  JsImportExport ImpExp = Imports[Indices[i]];

Is there any chance you are changing the total length of an import block?


Comment at: lib/Format/SortJavaScriptImports.cpp:226
@@ +225,3 @@
+  ImpExp.URL = Current->TokenText.substr(1, Current->TokenText.size() - 2);
+  if (ImpExp.URL.startswith("..")) {
+ImpExp.Category = JsImportExport::JsImportCategory::RELATIVE_PARENT;

No braces.


Comment at: lib/Format/SortJavaScriptImports.cpp:291
@@ +290,3 @@
+unsigned *Cursor) {
+  // TODO(martinprobst): Cursor support.
+  std::unique_ptr Env =

s/TODO(martinprobst)/FIXME/

Also, I'd probably remove the parameter until this is supported. This FIXME is 
quite hidden but if there is no Cursor in the interface, there is no confusion.


Comment at: lib/Format/TokenAnalyzer.h:1
@@ +1,2 @@
+//===--- TokenAnalyzer.h - Analyze Token Streams *- C++ 
-*-===//
+//

This isn't quite as bad as the other, but we probably want a dedicated .cpp 
file, too.


http://reviews.llvm.org/D20198



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


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-12 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: lib/Sema/SemaType.cpp:2055
@@ -2054,3 +2054,3 @@
 
-  return S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser,

pxli168 wrote:
> Anastasia wrote:
> > Formatting looks weird though... may be better to leave the first line 
> > unmodified?
> I felt very strange, too. But this is what clang-format gives me.
I see. clang-format doesn't take readability into account unfortunately. :)

Let's just leave the first line of this change unmodified at least to make it 
more readable.


Comment at: test/CodeGenOpenCL/vla.cl:1
@@ +1,2 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20

pxli168 wrote:
> Anastasia wrote:
> > Could we have a Sema test instead where we accept the VLA if constant AS 
> > object is used and give an error otherwise?
> > 
> > Also do we need to test CL2.0? We don't seem to be doing anything different 
> > for that version. 
> In earier than OpenCL1.2  program scope variable must reside in constant 
> address space and no
> ```
> const global int
> ```
> can be here.
> But const global value should also not be seen as VLA either.
Why not? Could you write a complete example perhaps? I am not sure I understand 
your point.

Thanks!


http://reviews.llvm.org/D20090



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


Re: [PATCH] D19084: [scan-build] fix warnings emitted on Clang AST code base

2016-05-12 Thread Apelete Seketeli via cfe-commits
apelete added inline comments.


Comment at: lib/AST/ASTDiagnostic.cpp:1686
@@ -1685,3 +1685,3 @@
 
-if (Same) {
+if (Same && FromTD) {
   OS << "template " << FromTD->getNameAsString();

rtrieu wrote:
> dblaikie wrote:
> > Should this be a condition, or just an assertion?
> This should be an assertion.  Same == true implies FromTD and ToTD are not 
> null.
What do you mean by "This should be an assertion" ?
There's already an assertion on FromTD and ToTD values at the beginning of 
PrintTemplateTemplate() so duplicating it here didn't make sense to me: should 
I replace the if() with an assertion anyway ?


Comment at: lib/AST/ExprConstant.cpp:1992
@@ -1991,2 +1991,3 @@
 int64_t Adjustment) {
+  assert(E && "expression to be evaluated must be not NULL");
   CharUnits SizeOfPointee;

dblaikie wrote:
> Does the static analyzer assume any pointer parameter may be null? (I didn't 
> think it did that - I thought it only assumed it could be null if there was a 
> null test somewhere in the function?) That seems a bit too pessimistic in 
> most codebases, especially LLVM - we pass a lot of non-null pointers around.
Not all pointer parameters trigger a warning during static analysis of Clang 
codebase, but for the ones that do the reason isn't always clear to me (I'm 
probably missing some background on static analysis here).

Let me know if you think the warning here should be ignored.


Comment at: lib/AST/NestedNameSpecifier.cpp:460
@@ +459,3 @@
+
+assert(Buffer && "Buffer cannot be NULL");
+

dblaikie wrote:
> Again, is this assuming that the Buffer parameter may be null? That seems 
> unlikely to be useful in the LLVM codebase where we have lots of guaranteed 
> non-null pointers floating around (I'm surprised this wouldn't cause tons of 
> analyzer warnings, so presumably it's something more subtle?)
Code path proposed by the analyzer is the following:

484. NestedNameSpecifierLocBuilder::
485. NestedNameSpecifierLocBuilder(const NestedNameSpecifierLocBuilder &Other) 
486.   : Representation(Other.Representation), Buffer(nullptr),
487. BufferSize(0), BufferCapacity(0)
488. {
...
500.   Append(Other.Buffer, Other.Buffer + Other.BufferSize, Buffer, BufferSize,
501. BufferCapacity);
502. }
The constructor is called on line 484 and it initalizes Buffer to nullptr, 
BufferSIze to 0 and BufferCapacity to 0 as shown above.
Then, after evaluating all branches in the constructor body to false, it calls 
Append() with the parameters previously initialized:

441.   void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize,
442 unsigned &BufferCapacity) {
443. if (Start == End)
444.   return;
445.
446. if (BufferSize + (End - Start) > BufferCapacity) {
...
458. }
459.
460. memcpy(Buffer + BufferSize, Start, End - Start);

At this point, after evaluating the branches at lines 443 and 446 to false, the 
analyzer concludes that 'Buffer + BufferSize' is a "Null pointer passed as an 
argument to a 'nonnull' parameter", hence the assert I proposed just before 
this line.

It turns out that this suggested codepath is indeed unlikely because either:
- Buffer parameter is null and so is BufferCapacity when Append() is called, in 
which case branch at line 446 is unlikely to evaluate to false, or
- Buffer parameter is initialized to a non-null value in the constructor at 
line 494 and is passed as a non-null parameter when Append() is called.

I chose however to trust the tool and prevent unforseen conditions to lead to 
that path by asserting Buffer value.

Let me know if you think the warning here should be ignored.


http://reviews.llvm.org/D19084



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


Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-12 Thread David Majnemer via cfe-commits
majnemer added inline comments.


Comment at: include/clang/Basic/LangOptions.def:175
@@ -174,2 +174,3 @@
 ENUM_LANGOPT(MSPointerToMemberRepresentationMethod, 
PragmaMSPointersToMembersKind, 2, PPTMK_BestCase, "member-pointer 
representation method")
+ENUM_LANGOPT(DefaultMSCallingConv, DefaultMSCallingConvention, 3, DCC_None, 
"default calling convention")
 

I'd remove the "MS" from this langopt now that it helps implement `-mrtd`.


http://reviews.llvm.org/D20171



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


Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread don hinton via cfe-commits
hintonda updated this revision to Diff 57065.
hintonda added a comment.

- Renamed private helper method


http://reviews.llvm.org/D18575

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNoexceptCheck.cpp
  clang-tidy/modernize/UseNoexceptCheck.h
  clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-noexcept.rst
  test/clang-tidy/modernize-use-noexcept-macro.cpp
  test/clang-tidy/modernize-use-noexcept.cpp

Index: test/clang-tidy/modernize-use-noexcept.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept.cpp
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -- -std=c++11
+
+class A{};
+class B{};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'foo' uses dynamic exception specification 'throw()'; use 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bar' uses dynamic exception specification 'throw(...)'; use 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() noexcept(false);
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:6: warning: function 'foobar' uses dynamic exception specification 'throw(A, B)'; use 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar() noexcept(false)
+
+// Should not trigger a replacement.
+void titi() noexcept {}
+void toto() noexcept(true) {}
Index: test/clang-tidy/modernize-use-noexcept-macro.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept-macro.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-noexcept.ReplacementString, value: 'NOEXCEPT'}]}" \
+// RUN:   -- -std=c++11
+
+#define NOEXCEPT noexcept
+
+void bar() throw() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bar' uses dynamic exception specification 'throw()'; use 'NOEXCEPT' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() NOEXCEPT {}
+
+// Should not trigger a replacement.
+void foo() noexcept(true);
+
Index: docs/clang-tidy/checks/modernize-use-noexcept.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-noexcept.rst
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - modernize-use-noexcept
+
+modernize-use-noexcept
+==
+
+The check converts dynamic exception specifications, e.g., throw(),
+throw([,...]), or throw(...) to noexcept, noexcept(false),
+or a user defined macro.
+
+Example
+---
+
+.. code-block:: c++
+
+  void foo() throw();
+	void bar() throw(int) {}
+
+transforms to:
+
+.. code-block:: c++
+
+  void foo() noexcept;
+	void bar() noexcept(false) {}
+
+
+User defined macros
+---
+
+By default this check will only replace ``throw()`` with ``noexcept``,
+and ``throw([,...])`` or ``throw(...)`` with
+``noexcept(false)``.  Additinally, users can also use
+:option:``ReplacementString`` to specify a macro to use instead of
+``noexcept``.  This is useful when maintaining source code that must
+be compiled with older compilers that don't support the ``noexcept``
+keyword.
+
+Example
+^^^
+
+.. code-block:: c++
+
+  void foo() throw() {}
+
+transforms to:
+
+.. code-block:: c++
+
+  void foo() NOEXCEPT {}
+
+if the ``ReplacementString`` option is set to ``NOEXCEPT``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -191,6 +191,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-noexcept
+  `_ check
+
+  Replaces dynamic exception specifications with noexcept.
+
 - New `performance-faster-string-find
   `_ check
 
Index: clang-tidy/utils/LexerUtils.h
===
--- clang-tidy/utils/LexerUtils.h
+++ clang-tidy/utils/LexerUtils.h
@@ -12,6 +12,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/SmallVector.h"
 
 namespace clang {
 namespace tidy {
@@ -23,6 +24,10 @@
 Token getPreviousNonCommentToken(const ASTContext &Context,
  SourceLocation Location);
 
+SmallVector ParseTokens(const ASTContext &Context,
+   const SourceManager &Sources,
+   CharSourceRange Range);
+
 } // namespace lexer
 } /

Re: [PATCH] D20208: clang-format: [JS] fix template string width counting.

2016-05-12 Thread Martin Probst via cfe-commits
mprobst updated this revision to Diff 57066.
mprobst added a comment.

- simplify logic by parsing forward, reduce complexity to O(n) from O(n^2)


http://reviews.llvm.org/D20208

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1076,6 +1076,8 @@
getGoogleJSStyleWithColumns(34)); // Barely doesn't fit.
   verifyFormat("var x = `hello ${world}` >= some();",
getGoogleJSStyleWithColumns(35)); // Barely fits.
+  verifyFormat("var x = `hellö ${wörld}` >= söme();",
+   getGoogleJSStyleWithColumns(35)); // Fits due to UTF-8.
   verifyFormat("var x = `hello\n"
 "  ${world}` >=\n"
 "some();",
@@ -1097,6 +1099,13 @@
getGoogleJSStyleWithColumns(13));
   verifyFormat("aaa(\n"
"`a`);");
+  // Repro for an obscure width-miscounting issue with template strings.
+  verifyFormat(
+  "someLongVariable =\n"
+  ""
+  "`${logPrefix[11]}/${logPrefix[12]}/${logPrefix[13]}${logPrefix[14]}`;",
+  "someLongVariable = "
+  "`${logPrefix[11]}/${logPrefix[12]}/${logPrefix[13]}${logPrefix[14]}`;");
 
   // Make sure template strings get a proper ColumnWidth assigned, even if they
   // are first token in line.
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -807,8 +807,10 @@
 assert(FirstInLineIndex == 0);
 do {
   Tokens.push_back(getNextToken());
-  if (Style.Language == FormatStyle::LK_JavaScript)
+  if (Style.Language == FormatStyle::LK_JavaScript) {
 tryParseJSRegexLiteral();
+tryParseTemplateString();
+  }
   tryMergePreviousTokens();
   if (Tokens.back()->NewlinesBefore > 0 || Tokens.back()->IsMultiline)
 FirstInLineIndex = Tokens.size() - 1;
@@ -828,9 +830,6 @@
   return;
 
 if (Style.Language == FormatStyle::LK_JavaScript) {
-  if (tryMergeTemplateString())
-return;
-
   static const tok::TokenKind JSIdentity[] = {tok::equalequal, tok::equal};
   static const tok::TokenKind JSNotIdentity[] = {tok::exclaimequal,
  tok::equal};
@@ -992,92 +991,42 @@
 resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset)));
   }
 
-  bool tryMergeTemplateString() {
-if (Tokens.size() < 2)
-  return false;
-
-FormatToken *EndBacktick = Tokens.back();
-// Backticks get lexed as tok::unknown tokens. If a template string contains
-// a comment start, it gets lexed as a tok::comment, or tok::unknown if
-// unterminated.
-if (!EndBacktick->isOneOf(tok::comment, tok::string_literal,
-  tok::char_constant, tok::unknown))
-  return false;
-size_t CommentBacktickPos = EndBacktick->TokenText.find('`');
-// Unknown token that's not actually a backtick, or a comment that doesn't
-// contain a backtick.
-if (CommentBacktickPos == StringRef::npos)
-  return false;
-
-unsigned TokenCount = 0;
-bool IsMultiline = false;
-unsigned EndColumnInFirstLine =
-EndBacktick->OriginalColumn + EndBacktick->ColumnWidth;
-for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; I++) {
-  ++TokenCount;
-  if (I[0]->IsMultiline)
-IsMultiline = true;
-
-  // If there was a preceding template string, this must be the start of a
-  // template string, not the end.
-  if (I[0]->is(TT_TemplateString))
-return false;
+  void tryParseTemplateString() {
+FormatToken *BacktickToken = Tokens.back();
+if (!BacktickToken->is(tok::unknown) || BacktickToken->TokenText != "`")
+  return;
 
-  if (I[0]->isNot(tok::unknown) || I[0]->TokenText != "`") {
-// Keep track of the rhs offset of the last token to wrap across lines -
-// its the rhs offset of the first line of the template string, used to
-// determine its width.
-if (I[0]->IsMultiline)
-  EndColumnInFirstLine = I[0]->OriginalColumn + I[0]->ColumnWidth;
-// If the token has newlines, the token before it (if it exists) is the
-// rhs end of the previous line.
-if (I[0]->NewlinesBefore > 0 && (I + 1 != E)) {
-  EndColumnInFirstLine = I[1]->OriginalColumn + I[1]->ColumnWidth;
-  IsMultiline = true;
-}
-continue;
-  }
+// 'Manually' lex ahead in the current file buffer.
+const char *Offset = Lex->getBufferLocation();
+const char *TmplBegin = Offset - BacktickToken->TokenText.size(); // at "`"
+for (; Offset != Lex->getBuffer().end() && *Offset != '`'; ++Offset) {
+  if (*Offset == '\\')
+++Offset; // S

Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added inline comments.


Comment at: docs/ReleaseNotes.rst:197
@@ +196,3 @@
+
+  Replaces dynamic exception specifications with noexcept.
+

Please highlight noexcept with ``.


Comment at: docs/clang-tidy/checks/modernize-use-noexcept.rst:6
@@ +5,3 @@
+
+The check converts dynamic exception specifications, e.g., throw(),
+throw([,...]), or throw(...) to noexcept, noexcept(false),

Please highlight throw() and other keywords with ``.


http://reviews.llvm.org/D18575



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


Re: [PATCH] D16962: clang-tidy: avoid std::bind

2016-05-12 Thread Jonathan B Coe via cfe-commits
jbcoe updated this revision to Diff 57067.
jbcoe added a comment.

update diff to allow arc to apply patch.


http://reviews.llvm.org/D16962

Files:
  clang-tidy/modernize/AvoidBindCheck.cpp
  clang-tidy/modernize/AvoidBindCheck.h
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-avoid-bind.rst
  test/clang-tidy/modernize-avoid-bind.cpp

Index: test/clang-tidy/modernize-avoid-bind.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-avoid-bind.cpp
@@ -0,0 +1,70 @@
+// RUN: %check_clang_tidy %s modernize-avoid-bind %t -- -- -std=c++14
+
+namespace std {
+inline namespace impl {
+template 
+class bind_rt {};
+
+template 
+bind_rt bind(Fp &&, Arguments &&...);
+}
+}
+
+int add(int x, int y) { return x + y; }
+
+void f() {
+  auto clj = std::bind(add, 2, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind [modernize-avoid-bind]
+  // CHECK-FIXES: auto clj = [] { return add(2, 2); };
+}
+
+void g() {
+  int x = 2;
+  int y = 2;
+  auto clj = std::bind(add, x, y);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // CHECK-FIXES: auto clj = [=] { return add(x, y); };
+}
+
+struct placeholder {};
+placeholder _1;
+placeholder _2;
+
+void h() {
+  int x = 2;
+  auto clj = std::bind(add, x, _1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // CHECK-FIXES: auto clj = [=](auto && arg1) { return add(x, arg1); };
+}
+
+struct A;
+struct B;
+bool ABTest(const A &, const B &);
+
+void i() {
+  auto BATest = std::bind(ABTest, _2, _1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: prefer a lambda to std::bind 
+  // CHECK-FIXES: auto BATest = [](auto && arg1, auto && arg2) { return ABTest(arg2, arg1); };
+}
+
+void j() {
+  auto clj = std::bind(add, 2, 2, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // No fix is applied for argument mismatches.
+  // CHECK-FIXES: auto clj = std::bind(add, 2, 2, 2);
+}
+
+void k() {
+  auto clj = std::bind(add, _1, _1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // No fix is applied for reused placeholders.
+  // CHECK-FIXES: auto clj = std::bind(add, _1, _1);
+}
+
+void m() {
+  auto clj = std::bind(add, 1, add(2, 5));
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind 
+  // No fix is applied for nested calls.
+  // CHECK-FIXES: auto clj = std::bind(add, 1, add(2, 5));
+}
+
Index: docs/clang-tidy/checks/modernize-avoid-bind.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-avoid-bind.rst
@@ -0,0 +1,38 @@
+.. title:: clang-tidy - modernize-avoid-std-bind
+
+modernize-avoid-bind
+==
+
+The check finds uses of ``std::bind`` and replaces simple uses with lambdas.
+Lambdas will use value-capture where required.
+
+Right now it only handles free functions, not member functions.
+
+Given:
+
+.. code:: C++
+
+  int add(int x, int y) { return x + y; }
+
+Then:
+
+.. code:: C++
+  
+  void f() {
+int x = 2;
+auto clj = std::bind(add, x, _1);
+  }
+
+is replaced by:
+  
+.. code:: C++
+  
+  void f() {
+int x = 2;
+auto clj = [=](auto && arg1) { return add(x, arg1); };
+  }
+
+``std::bind`` can be hard to read and can result in larger object files and
+binaries due to type information that will not be produced by equivalent
+lambdas.
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -91,6 +91,7 @@
misc-unused-raii
misc-unused-using-decls
misc-virtual-near-miss
+   modernize-avoid-bind
modernize-deprecated-headers
modernize-loop-convert
modernize-make-shared
Index: clang-tidy/modernize/ModernizeTidyModule.cpp
===
--- clang-tidy/modernize/ModernizeTidyModule.cpp
+++ clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AvoidBindCheck.h"
 #include "DeprecatedHeadersCheck.h"
 #include "LoopConvertCheck.h"
 #include "MakeSharedCheck.h"
@@ -34,6 +35,8 @@
 class ModernizeModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"modernize-avoid-bind");
 CheckFactories.registerCheck(
 "modernize-deprecated-headers");
 CheckFactories.registerCheck("modernize-loop-convert");
Index: clang-tidy/modernize/CMakeLists.txt
===
--- clang-tidy/modernize/CMakeLists.txt
+++ clang-tidy/modernize/CMakeLists.txt
@@ -1,6 +1,7 @@
 s

Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread don hinton via cfe-commits
hintonda updated this revision to Diff 57070.
hintonda added a comment.

- Added 's around keywords in docs.


http://reviews.llvm.org/D18575

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNoexceptCheck.cpp
  clang-tidy/modernize/UseNoexceptCheck.h
  clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-noexcept.rst
  test/clang-tidy/modernize-use-noexcept-macro.cpp
  test/clang-tidy/modernize-use-noexcept.cpp

Index: test/clang-tidy/modernize-use-noexcept.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept.cpp
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -- -std=c++11
+
+class A{};
+class B{};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'foo' uses dynamic exception specification 'throw()'; use 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bar' uses dynamic exception specification 'throw(...)'; use 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() noexcept(false);
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:6: warning: function 'foobar' uses dynamic exception specification 'throw(A, B)'; use 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar() noexcept(false)
+
+// Should not trigger a replacement.
+void titi() noexcept {}
+void toto() noexcept(true) {}
Index: test/clang-tidy/modernize-use-noexcept-macro.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept-macro.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-noexcept.ReplacementString, value: 'NOEXCEPT'}]}" \
+// RUN:   -- -std=c++11
+
+#define NOEXCEPT noexcept
+
+void bar() throw() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bar' uses dynamic exception specification 'throw()'; use 'NOEXCEPT' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() NOEXCEPT {}
+
+// Should not trigger a replacement.
+void foo() noexcept(true);
+
Index: docs/clang-tidy/checks/modernize-use-noexcept.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-noexcept.rst
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - modernize-use-noexcept
+
+modernize-use-noexcept
+==
+
+The check converts dynamic exception specifications, e.g., ``throw()``,
+``throw([,...])``, or ``throw(...)`` to ``noexcept``, ``noexcept(false)``,
+or a user defined macro.
+
+Example
+---
+
+.. code-block:: c++
+
+  void foo() throw();
+	void bar() throw(int) {}
+
+transforms to:
+
+.. code-block:: c++
+
+  void foo() noexcept;
+	void bar() noexcept(false) {}
+
+
+User defined macros
+---
+
+By default this check will only replace ``throw()`` with ``noexcept``,
+and ``throw([,...])`` or ``throw(...)`` with
+``noexcept(false)``.  Additinally, users can also use
+:option:``ReplacementString`` to specify a macro to use instead of
+``noexcept``.  This is useful when maintaining source code that must
+be compiled with older compilers that don't support the ``noexcept``
+keyword.
+
+Example
+^^^
+
+.. code-block:: c++
+
+  void foo() throw() {}
+
+transforms to:
+
+.. code-block:: c++
+
+  void foo() NOEXCEPT {}
+
+if the ``ReplacementString`` option is set to ``NOEXCEPT``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -191,6 +191,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-noexcept
+  `_ check
+
+  Replaces dynamic exception specifications with ``noexcept`` or a user defined macro.
+
 - New `performance-faster-string-find
   `_ check
 
Index: clang-tidy/utils/LexerUtils.h
===
--- clang-tidy/utils/LexerUtils.h
+++ clang-tidy/utils/LexerUtils.h
@@ -12,6 +12,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/SmallVector.h"
 
 namespace clang {
 namespace tidy {
@@ -23,6 +24,10 @@
 Token getPreviousNonCommentToken(const ASTContext &Context,
  SourceLocation Location);
 
+SmallVector ParseTokens(const ASTContext &Context,
+   const SourceManager &Sources,
+   

Re: [PATCH] D19156: [ms][dll] #27212: Generating of implicit special members should take into account MSVC compatibility version

2016-05-12 Thread Reid Kleckner via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm

I've been trying to say that ABI compatibility is not the same thing as 
generating the same set of exported symbols, but it really doesn't matter. If 
MSVC 2013 and 2015 are not ABI compatible in this corner case, there is no need 
for clang to bend over backward to provide a marginally better experience. It 
sounds like it makes your life easier if we can always produce the exact same 
set of exports as the MSVC version we are targeting.


http://reviews.llvm.org/D19156



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


Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added inline comments.


Comment at: docs/clang-tidy/checks/modernize-use-noexcept.rst:32
@@ +31,3 @@
+``noexcept(false)``.  Additinally, users can also use
+:option:``ReplacementString`` to specify a macro to use instead of
+``noexcept``.  This is useful when maintaining source code that must

Sorry, missed last time. Please use ` for check option and its value(s). Same 
for last line in file.


http://reviews.llvm.org/D18575



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


Re: [PATCH] D19815: Support '#pragma once' in headers when using PCH

2016-05-12 Thread Richard Smith via cfe-commits
rsmith added a comment.

Rather than threading through a new flag, can you test the existing `TUKind` 
field?


http://reviews.llvm.org/D19815



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


Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-12 Thread Alexander Makarov via cfe-commits
a.makarov updated this revision to Diff 57071.
a.makarov added a comment.

Renamed option 'DefaultMSCallingConv' into 'DefaultCallingConv' and enum 
'DefaultMSCallingConvention' into 'DefaultCallingConvention'.


http://reviews.llvm.org/D20171

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  include/clang/Driver/Options.td
  lib/AST/ASTContext.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/default_calling_conv.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6140,6 +6140,15 @@
   CmdArgs.push_back("-fms-memptr-rep=virtual");
   }
 
+  if (Args.getLastArg(options::OPT__SLASH_Gd))
+ CmdArgs.push_back("-fdefault-calling-conv=cdecl");
+  else if (Args.getLastArg(options::OPT__SLASH_Gr))
+ CmdArgs.push_back("-fdefault-calling-conv=fastcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gz))
+ CmdArgs.push_back("-fdefault-calling-conv=stdcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gv))
+ CmdArgs.push_back("-fdefault-calling-conv=vectorcall");
+
   if (Arg *A = Args.getLastArg(options::OPT_vtordisp_mode_EQ))
 A->render(Args, CmdArgs);
 
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8605,8 +8605,25 @@
   if (IsCXXMethod)
 return ABI->getDefaultMethodCallConv(IsVariadic);
 
-  if (LangOpts.MRTD && !IsVariadic) return CC_X86StdCall;
-
+  switch (LangOpts.getDefaultCallingConv()) {
+  case LangOptions::DCC_None:
+break;
+  case LangOptions::DCC_CDecl:
+return CC_C;
+  case LangOptions::DCC_FastCall:
+if (getTargetInfo().hasFeature("sse2"))
+  return CC_X86FastCall;
+break;
+  case LangOptions::DCC_StdCall:
+if (!IsVariadic)
+  return CC_X86StdCall;
+break;
+  case LangOptions::DCC_VectorCall:
+// __vectorcall cannot be applied to variadic functions.
+if (!IsVariadic)
+  return CC_X86VectorCall;
+break;
+  }
   return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
 }
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3895,11 +3895,12 @@
 
 // This convention is not valid for the target. Use the default function or
 // method calling convention.
-TargetInfo::CallingConvMethodType MT = TargetInfo::CCMT_Unknown;
-if (FD)
-  MT = FD->isCXXInstanceMember() ? TargetInfo::CCMT_Member : 
-TargetInfo::CCMT_NonMember;
-CC = TI.getDefaultCallingConv(MT);
+bool isCXXMethod = false, isVariadic = false;
+if (FD) {
+  isCXXMethod = FD->isCXXInstanceMember();
+  isVariadic = FD->isVariadic();
+}
+CC = Context.getDefaultCallingConvention(isVariadic, isCXXMethod);
   }
 
   attr.setProcessingCache((unsigned) CC);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1772,7 +1772,6 @@
   Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
   Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
   Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
-  Opts.MRTD = Args.hasArg(OPT_mrtd);
   Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat);
   Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
   Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
@@ -1849,6 +1848,34 @@
 Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel);
   }
 
+  // Check for MS default calling conventions being specified.
+  if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
+LangOptions::DefaultCallingConvention DefaultCC =
+llvm::StringSwitch(
+A->getValue())
+.Case("cdecl", LangOptions::DCC_CDecl)
+.Case("fastcall", LangOptions::DCC_FastCall)
+.Case("stdcall", LangOptions::DCC_StdCall)
+.Case("vectorcall", LangOptions::DCC_VectorCall)
+.Default(LangOptions::DCC_None);
+if (DefaultCC == LangOptions::DCC_None)
+  Diags.Report(diag::err_drv_invalid_value)
+  << "-fdefault-calling-conv=" << A->getValue();
+
+llvm::Triple T(TargetOpts.Triple);
+llvm::Triple::ArchType Arch = T.getArch();
+bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
+  DefaultCC == LangOptions::DCC_StdCall) &&
+ Arch != llvm::Triple::x86;
+emitError |= DefaultCC == LangOptions::DCC_VectorCall &&
+ !(Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64);
+if (emitError)
+  Diags.Repor

Re: [PATCH] D20198: clang-format: [JS] sort ES6 imports.

2016-05-12 Thread Martin Probst via cfe-commits
mprobst updated this revision to Diff 57073.
mprobst marked 9 inline comments as done.
mprobst added a comment.

- extract TokenAnalyzer.h and SortJavaScriptImports.h/cpp
- clean up imports/
- includes
- address review comments
- pull out implementations from header files.


http://reviews.llvm.org/D20198

Files:
  lib/Format/CMakeLists.txt
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/FormatTokenLexer.cpp
  lib/Format/FormatTokenLexer.h
  lib/Format/SortJavaScriptImports.cpp
  lib/Format/SortJavaScriptImports.h
  lib/Format/TokenAnalyzer.cpp
  lib/Format/TokenAnalyzer.h
  unittests/Format/CMakeLists.txt
  unittests/Format/SortImportsTestJS.cpp

Index: unittests/Format/SortImportsTestJS.cpp
===
--- /dev/null
+++ unittests/Format/SortImportsTestJS.cpp
@@ -0,0 +1,124 @@
+//===- unittest/Format/SortImportsTestJS.cpp - JS import sort unit tests --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+namespace {
+
+class SortImportsTestJS : public ::testing::Test {
+protected:
+  std::vector GetCodeRange(StringRef Code) {
+return std::vector(1, tooling::Range(0, Code.size()));
+  }
+
+  std::string sort(StringRef Code, StringRef FileName = "input.js") {
+auto Ranges = GetCodeRange(Code);
+std::string Sorted =
+applyAllReplacements(Code, sortIncludes(Style, Code, Ranges, FileName));
+return applyAllReplacements(Sorted,
+reformat(Style, Sorted, Ranges, FileName));
+  }
+
+  void verifySort(llvm::StringRef Expected, llvm::StringRef Code) {
+std::string Result = sort(Code);
+EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
+  }
+
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
+};
+
+TEST_F(SortImportsTestJS, BasicSorting) {
+  verifySort("import {sym} from 'a';\n"
+ "import {sym} from 'b';\n"
+ "import {sym} from 'c';\n"
+ "\n"
+ "let x = 1;",
+ "import {sym} from 'a';\n"
+ "import {sym} from 'c';\n"
+ "import {sym} from 'b';\n"
+ "let x = 1;");
+}
+
+TEST_F(SortImportsTestJS, Comments) {
+  verifySort("/** @fileoverview This is a great file. */\n"
+ "// A very important import follows.\n"
+ "import {sym} from 'a'; /* more comments */\n"
+ "import {sym} from 'b'; // from //foo:bar\n",
+ "/** @fileoverview This is a great file. */\n"
+ "import {sym} from 'b'; // from //foo:bar\n"
+ "// A very important import follows.\n"
+ "import {sym} from 'a'; /* more comments */\n");
+}
+
+TEST_F(SortImportsTestJS, SortStar) {
+  verifySort("import * as foo from 'a';\n"
+ "import {sym} from 'a';\n"
+ "import * as bar from 'b';\n",
+ "import {sym} from 'a';\n"
+ "import * as foo from 'a';\n"
+ "import * as bar from 'b';\n");
+}
+
+TEST_F(SortImportsTestJS, AliasesSymbols) {
+  verifySort("import {sym1 as alias1} from 'b';\n"
+ "import {sym2 as alias2, sym3 as alias3} from 'c';\n",
+ "import {sym2 as alias2, sym3 as alias3} from 'c';\n"
+ "import {sym1 as alias1} from 'b';\n");
+}
+
+TEST_F(SortImportsTestJS, GroupImports) {
+  verifySort("import {a} from 'absolute';\n"
+ "\n"
+ "import {b} from '../parent';\n"
+ "import {b} from '../parent/nested';\n"
+ "\n"
+ "import {b} from './relative/path';\n"
+ "import {b} from './relative/path/nested';\n"
+ "\n"
+ "let x = 1;\n",
+ "import {b} from './relative/path/nested';\n"
+ "import {b} from './relative/path';\n"
+ "import {b} from '../parent/nested';\n"
+ "import {b} from '../parent';\n"
+ "import {a} from 'absolute';\n"
+ "let x = 1;\n");
+}
+
+TEST_F(SortImportsTestJS, Exports) {
+  verifySort("import {S} from 'bpath';\n"
+ "\n"
+ "import {T} from './cpath';\n"
+ "\n"
+ "export {A, B} from 'apath';\n"
+ "export {P} from '../parent';\n"
+ "export {R} from './relative';\n"
+ "export {S};\n"
+ "\n"
+ "let x = 1;\n"
+ "export y = 1;\n",
+ "export {R} from './relative';\n"
+ "import {T} from './cpath';\n"
+ "export {S};\n"
+ "export {A, B} from 'apath';\n"
+ "import {S} from 'bpath';\n

Re: [PATCH] D20198: clang-format: [JS] sort ES6 imports.

2016-05-12 Thread Martin Probst via cfe-commits
mprobst added a comment.

PTAL.



Comment at: lib/Format/SortJavaScriptImports.cpp:162
@@ +161,3 @@
+std::string ImportsText;
+for (unsigned i = 0, e = Indices.size(); i != e; ++i) {
+  JsImportExport ImpExp = Imports[Indices[i]];

djasper wrote:
> Is there any chance you are changing the total length of an import block?
No, this only ever monotonously increases the length. I'm aware things fall 
apart if it doesn't ;-)


Comment at: lib/Format/SortJavaScriptImports.cpp:226
@@ +225,3 @@
+  ImpExp.URL = Current->TokenText.substr(1, Current->TokenText.size() - 2);
+  if (ImpExp.URL.startswith("..")) {
+ImpExp.Category = JsImportExport::JsImportCategory::RELATIVE_PARENT;

djasper wrote:
> No braces.
Just can't get used to that, it feels so wrong...


http://reviews.llvm.org/D20198



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


Re: [PATCH] D20207: [AST] Move operations enum to a definition file.

2016-05-12 Thread Richard Smith via cfe-commits
rsmith added a comment.

In http://reviews.llvm.org/D20207#428486, @aaron.ballman wrote:

> Generally, I think this looks good. It will definitely help with AST 
> matchers. Richard, do you have any problems with this approach?


Not at all. This would be a nice improvement even if it didn't also provide 
value to the dynamic matchers.


http://reviews.llvm.org/D20207



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


Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread don hinton via cfe-commits
hintonda added inline comments.


Comment at: docs/clang-tidy/checks/modernize-use-noexcept.rst:32
@@ +31,3 @@
+``noexcept(false)``.  Additinally, users can also use
+:option:``ReplacementString`` to specify a macro to use instead of
+``noexcept``.  This is useful when maintaining source code that must

Eugene.Zelenko wrote:
> Sorry, missed last time. Please use ` for check option and its value(s). Same 
> for last line in file.
I'm not sure I understand what you want me to change.  Did you want me to 
append that phrase, or replace something?


http://reviews.llvm.org/D18575



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


Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added inline comments.


Comment at: docs/clang-tidy/checks/modernize-use-noexcept.rst:32
@@ +31,3 @@
+``noexcept(false)``.  Additinally, users can also use
+:option:``ReplacementString`` to specify a macro to use instead of
+``noexcept``.  This is useful when maintaining source code that must

hintonda wrote:
> Eugene.Zelenko wrote:
> > Sorry, missed last time. Please use ` for check option and its value(s). 
> > Same for last line in file.
> I'm not sure I understand what you want me to change.  Did you want me to 
> append that phrase, or replace something?
Replace :option:``ReplacementString`` with :option:`ReplacementString`. Same in 
last line with option and NOEXCEPT.

'' is for language constructs, ' is for command line options and their 
parameters.


http://reviews.llvm.org/D18575



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


Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread don hinton via cfe-commits
hintonda added inline comments.


Comment at: docs/clang-tidy/checks/modernize-use-noexcept.rst:32
@@ +31,3 @@
+``noexcept(false)``.  Additinally, users can also use
+:option:``ReplacementString`` to specify a macro to use instead of
+``noexcept``.  This is useful when maintaining source code that must

Eugene.Zelenko wrote:
> hintonda wrote:
> > Eugene.Zelenko wrote:
> > > Sorry, missed last time. Please use ` for check option and its value(s). 
> > > Same for last line in file.
> > I'm not sure I understand what you want me to change.  Did you want me to 
> > append that phrase, or replace something?
> Replace :option:``ReplacementString`` with :option:`ReplacementString`. Same 
> in last line with option and NOEXCEPT.
> 
> '' is for language constructs, ' is for command line options and their 
> parameters.
Ah, got it.  Sorry for being so dense...  Will checkin shortly...


http://reviews.llvm.org/D18575



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


[PATCH] D20216: clang-rename: check that the source location we find actually has the old name

2016-05-12 Thread Miklos Vajna via cfe-commits
vmiklos created this revision.
vmiklos added subscribers: cfe-commits, klimek.

This more general check could have prevented the specific problem
"getSourceOrder() == -1" guards.

http://reviews.llvm.org/D20216

Files:
  clang-rename/RenamingAction.cpp
  clang-rename/USRLocFinder.cpp
  clang-rename/USRLocFinder.h

Index: clang-rename/USRLocFinder.h
===
--- clang-rename/USRLocFinder.h
+++ clang-rename/USRLocFinder.h
@@ -28,6 +28,7 @@
 
 // FIXME: make this an AST matcher. Wouldn't that be awesome??? I agree!
 std::vector getLocationsOfUSR(const std::string usr,
+  const std::string &PrevName,
   Decl *decl);
 }
 }
Index: clang-rename/USRLocFinder.cpp
===
--- clang-rename/USRLocFinder.cpp
+++ clang-rename/USRLocFinder.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/SmallVector.h"
 
 using namespace llvm;
@@ -33,7 +34,7 @@
 class USRLocFindingASTVisitor
 : public clang::RecursiveASTVisitor {
 public:
-  explicit USRLocFindingASTVisitor(const std::string USR) : USR(USR) {
+  explicit USRLocFindingASTVisitor(const std::string USR, const std::string 
&PrevName) : USR(USR), PrevName(PrevName) {
   }
 
   // Declaration visitors:
@@ -58,6 +59,7 @@
   }
 
   bool VisitCXXConstructorDecl(clang::CXXConstructorDecl *ConstructorDecl) {
+const ASTContext &Context = ConstructorDecl->getASTContext();
 for (clang::CXXConstructorDecl::init_const_iterator it = 
ConstructorDecl->init_begin(); it != ConstructorDecl->init_end(); ++it) {
   const clang::CXXCtorInitializer* Initializer = *it;
   if (Initializer->getSourceOrder() == -1) {
@@ -68,7 +70,12 @@
   if (const clang::FieldDecl *FieldDecl = Initializer->getAnyMember()) {
 if (getUSRForDecl(FieldDecl) == USR) {
   // The initializer refers to a field that is to be renamed.
-  LocationsFound.push_back(Initializer->getSourceLocation());
+  SourceRange Range = Initializer->getSourceRange();
+  StringRef TokenName = 
Lexer::getSourceText(CharSourceRange::getTokenRange(Range), 
Context.getSourceManager(), Context.getLangOpts());
+  if (TokenName.startswith(PrevName)) {
+// The token of the source location we find actually has the old 
name.
+LocationsFound.push_back(Initializer->getSourceLocation());
+  }
 }
   }
 }
@@ -117,13 +124,16 @@
 
   // All the locations of the USR were found.
   const std::string USR;
+  // Old name that is renamed.
+  const std::string PrevName;
   std::vector LocationsFound;
 };
 } // namespace
 
 std::vector getLocationsOfUSR(const std::string USR,
+  const std::string &PrevName,
   Decl *Decl) {
-  USRLocFindingASTVisitor visitor(USR);
+  USRLocFindingASTVisitor visitor(USR, PrevName);
 
   visitor.TraverseDecl(Decl);
   return visitor.getLocationsFound();
Index: clang-rename/RenamingAction.cpp
===
--- clang-rename/RenamingAction.cpp
+++ clang-rename/RenamingAction.cpp
@@ -49,7 +49,7 @@
 std::vector NewCandidates;
 
 for (const auto &USR : USRs) {
-  NewCandidates = getLocationsOfUSR(USR, Context.getTranslationUnitDecl());
+  NewCandidates = getLocationsOfUSR(USR, PrevName, 
Context.getTranslationUnitDecl());
   RenamingCandidates.insert(RenamingCandidates.end(), 
NewCandidates.begin(),
 NewCandidates.end());
   NewCandidates.clear();


Index: clang-rename/USRLocFinder.h
===
--- clang-rename/USRLocFinder.h
+++ clang-rename/USRLocFinder.h
@@ -28,6 +28,7 @@
 
 // FIXME: make this an AST matcher. Wouldn't that be awesome??? I agree!
 std::vector getLocationsOfUSR(const std::string usr,
+  const std::string &PrevName,
   Decl *decl);
 }
 }
Index: clang-rename/USRLocFinder.cpp
===
--- clang-rename/USRLocFinder.cpp
+++ clang-rename/USRLocFinder.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/SmallVector.h"
 
 using namespace llvm;
@@ -33,7 +34,7 @@
 class USRLocFindingASTVisitor
 : public clang::RecursiveASTVisitor {
 public:
-  explicit USRLocFindingASTVisitor(const std::string USR) : USR(USR) {
+  explicit USRLocFindingASTVisitor(const std::string USR, const std::string &PrevName) : USR(USR), PrevName(PrevName

Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread don hinton via cfe-commits
hintonda updated this revision to Diff 57078.
hintonda added a comment.

- Fix quote problem in docs.


http://reviews.llvm.org/D18575

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNoexceptCheck.cpp
  clang-tidy/modernize/UseNoexceptCheck.h
  clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-noexcept.rst
  test/clang-tidy/modernize-use-noexcept-macro.cpp
  test/clang-tidy/modernize-use-noexcept.cpp

Index: test/clang-tidy/modernize-use-noexcept.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept.cpp
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -- -std=c++11
+
+class A{};
+class B{};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'foo' uses dynamic exception specification 'throw()'; use 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bar' uses dynamic exception specification 'throw(...)'; use 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() noexcept(false);
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:6: warning: function 'foobar' uses dynamic exception specification 'throw(A, B)'; use 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar() noexcept(false)
+
+// Should not trigger a replacement.
+void titi() noexcept {}
+void toto() noexcept(true) {}
Index: test/clang-tidy/modernize-use-noexcept-macro.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept-macro.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-noexcept.ReplacementString, value: 'NOEXCEPT'}]}" \
+// RUN:   -- -std=c++11
+
+#define NOEXCEPT noexcept
+
+void bar() throw() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bar' uses dynamic exception specification 'throw()'; use 'NOEXCEPT' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() NOEXCEPT {}
+
+// Should not trigger a replacement.
+void foo() noexcept(true);
+
Index: docs/clang-tidy/checks/modernize-use-noexcept.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-noexcept.rst
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - modernize-use-noexcept
+
+modernize-use-noexcept
+==
+
+The check converts dynamic exception specifications, e.g., ``throw()``,
+``throw([,...])``, or ``throw(...)`` to ``noexcept``, ``noexcept(false)``,
+or a user defined macro.
+
+Example
+---
+
+.. code-block:: c++
+
+  void foo() throw();
+	void bar() throw(int) {}
+
+transforms to:
+
+.. code-block:: c++
+
+  void foo() noexcept;
+	void bar() noexcept(false) {}
+
+
+User defined macros
+---
+
+By default this check will only replace ``throw()`` with ``noexcept``,
+and ``throw([,...])`` or ``throw(...)`` with
+``noexcept(false)``.  Additionally, users can also use
+:option:`ReplacementString` to specify a macro to use instead of
+``noexcept``.  This is useful when maintaining source code that must
+be compiled with older compilers that don't support the ``noexcept``
+keyword.
+
+Example
+^^^
+
+.. code-block:: c++
+
+  void foo() throw() {}
+
+transforms to:
+
+.. code-block:: c++
+
+  void foo() NOEXCEPT {}
+
+if the `ReplacementString` option is set to `NOEXCEPT`.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -191,6 +191,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-noexcept
+  `_ check
+
+  Replaces dynamic exception specifications with ``noexcept`` or a user defined macro.
+
 - New `performance-faster-string-find
   `_ check
 
Index: clang-tidy/utils/LexerUtils.h
===
--- clang-tidy/utils/LexerUtils.h
+++ clang-tidy/utils/LexerUtils.h
@@ -12,6 +12,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/SmallVector.h"
 
 namespace clang {
 namespace tidy {
@@ -23,6 +24,10 @@
 Token getPreviousNonCommentToken(const ASTContext &Context,
  SourceLocation Location);
 
+SmallVector ParseTokens(const ASTContext &Context,
+   const SourceManager &Sources,
+   CharSourceRa

Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added inline comments.


Comment at: docs/clang-tidy/checks/modernize-use-noexcept.rst:50
@@ +49,2 @@
+
+if the `ReplacementString` option is set to `NOEXCEPT`.

Actually :option: still need to prepend `ReplacementString`.


http://reviews.llvm.org/D18575



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


Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread don hinton via cfe-commits
hintonda updated this revision to Diff 57080.
hintonda added a comment.

- Add :option: prefix for clarity.


http://reviews.llvm.org/D18575

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNoexceptCheck.cpp
  clang-tidy/modernize/UseNoexceptCheck.h
  clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-noexcept.rst
  test/clang-tidy/modernize-use-noexcept-macro.cpp
  test/clang-tidy/modernize-use-noexcept.cpp

Index: test/clang-tidy/modernize-use-noexcept.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept.cpp
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -- -std=c++11
+
+class A{};
+class B{};
+
+void foo() throw();
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'foo' uses dynamic exception specification 'throw()'; use 'noexcept' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foo() noexcept;
+
+void bar() throw(...);
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bar' uses dynamic exception specification 'throw(...)'; use 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() noexcept(false);
+
+void foobar() throw(A, B)
+{}
+// CHECK-MESSAGES: :[[@LINE-2]]:6: warning: function 'foobar' uses dynamic exception specification 'throw(A, B)'; use 'noexcept(false)' instead [modernize-use-noexcept]
+// CHECK-FIXES: void foobar() noexcept(false)
+
+// Should not trigger a replacement.
+void titi() noexcept {}
+void toto() noexcept(true) {}
Index: test/clang-tidy/modernize-use-noexcept-macro.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-noexcept-macro.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s modernize-use-noexcept %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-noexcept.ReplacementString, value: 'NOEXCEPT'}]}" \
+// RUN:   -- -std=c++11
+
+#define NOEXCEPT noexcept
+
+void bar() throw() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bar' uses dynamic exception specification 'throw()'; use 'NOEXCEPT' instead [modernize-use-noexcept]
+// CHECK-FIXES: void bar() NOEXCEPT {}
+
+// Should not trigger a replacement.
+void foo() noexcept(true);
+
Index: docs/clang-tidy/checks/modernize-use-noexcept.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-noexcept.rst
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - modernize-use-noexcept
+
+modernize-use-noexcept
+==
+
+The check converts dynamic exception specifications, e.g., ``throw()``,
+``throw([,...])``, or ``throw(...)`` to ``noexcept``, ``noexcept(false)``,
+or a user defined macro.
+
+Example
+---
+
+.. code-block:: c++
+
+  void foo() throw();
+	void bar() throw(int) {}
+
+transforms to:
+
+.. code-block:: c++
+
+  void foo() noexcept;
+	void bar() noexcept(false) {}
+
+
+User defined macros
+---
+
+By default this check will only replace ``throw()`` with ``noexcept``,
+and ``throw([,...])`` or ``throw(...)`` with
+``noexcept(false)``.  Additionally, users can also use
+:option:`ReplacementString` to specify a macro to use instead of
+``noexcept``.  This is useful when maintaining source code that must
+be compiled with older compilers that don't support the ``noexcept``
+keyword.
+
+Example
+^^^
+
+.. code-block:: c++
+
+  void foo() throw() {}
+
+transforms to:
+
+.. code-block:: c++
+
+  void foo() NOEXCEPT {}
+
+if the :option:`ReplacementString` option is set to `NOEXCEPT`.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -191,6 +191,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-noexcept
+  `_ check
+
+  Replaces dynamic exception specifications with ``noexcept`` or a user defined macro.
+
 - New `performance-faster-string-find
   `_ check
 
Index: clang-tidy/utils/LexerUtils.h
===
--- clang-tidy/utils/LexerUtils.h
+++ clang-tidy/utils/LexerUtils.h
@@ -12,6 +12,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/SmallVector.h"
 
 namespace clang {
 namespace tidy {
@@ -23,6 +24,10 @@
 Token getPreviousNonCommentToken(const ASTContext &Context,
  SourceLocation Location);
 
+SmallVector ParseTokens(const ASTContext &Context,
+   const SourceManager &Sources,
+ 

Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-05-12 Thread don hinton via cfe-commits
hintonda added inline comments.


Comment at: docs/clang-tidy/checks/modernize-use-noexcept.rst:50
@@ +49,2 @@
+
+if the :option:`ReplacementString` option is set to `NOEXCEPT`.

I'll get it eventually...  ;-)


http://reviews.llvm.org/D18575



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


r269326 - [Unittests] Reverse the order of arguments for correct debug output

2016-05-12 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Thu May 12 14:13:04 2016
New Revision: 269326

URL: http://llvm.org/viewvc/llvm-project?rev=269326&view=rev
Log:
[Unittests] Reverse the order of arguments for correct debug output

Modified:
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp

Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=269326&r1=269325&r2=269326&view=diff
==
--- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original)
+++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Thu May 12 14:13:04 2016
@@ -386,7 +386,7 @@ static void checkContents(DirIter I, Arr
 
   unsigned LastElt = std::min(InputToCheck.size(), Expected.size());
   for (unsigned Idx = 0; Idx != LastElt; ++Idx)
-EXPECT_EQ(Expected[Idx], StringRef(InputToCheck[Idx]));
+EXPECT_EQ(StringRef(InputToCheck[Idx]), Expected[Idx]);
 }
 
 TEST(VirtualFileSystemTest, OverlayIteration) {


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


r269327 - [VFS] Reapply #2: Reconstruct the VFS overlay tree for more accurate lookup

2016-05-12 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Thu May 12 14:13:07 2016
New Revision: 269327

URL: http://llvm.org/viewvc/llvm-project?rev=269327&view=rev
Log:
[VFS] Reapply #2: Reconstruct the VFS overlay tree for more accurate lookup

Reapply r269100 and r269270, reverted due to
https://llvm.org/bugs/show_bug.cgi?id=27725. Isolate the testcase that
corresponds to the new feature side of this commit and skip it on
windows hosts until we find why it does not work on these platforms.

Original commit message:

The way we currently build the internal VFS overlay representation leads
to inefficient path search and might yield wrong answers when asked for
recursive or regular directory iteration.

Currently, when reading an YAML file, each YAML root entry is placed
inside a new root in the filesystem overlay. In the crash reproducer, a
simple "@import Foundation" currently maps to 43 roots, and when looking
up paths, we traverse a directory tree for each of these different
roots, until we find a match (or don't). This has two consequences:

- It's slow.
- Directory iteration gives incomplete results since it only return
results within one root - since contents of the same directory can be
declared inside different roots, the result isn't accurate.

This is in part fault of the way we currently write out the YAML file
when emitting the crash reproducer - we could generate only one root and
that would make it fast and correct again. However, we should not rely
on how the client writes the YAML, but provide a good internal
representation regardless.

Build a proper virtual directory tree out of the YAML representation,
allowing faster search and proper iteration. Besides the crash
reproducer, this potentially benefits other VFS clients.

Modified:
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=269327&r1=269326&r2=269327&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Thu May 12 14:13:07 2016
@@ -719,7 +719,13 @@ public:
 Status S)
   : Entry(EK_Directory, Name), Contents(std::move(Contents)),
 S(std::move(S)) {}
+  RedirectingDirectoryEntry(StringRef Name, Status S)
+  : Entry(EK_Directory, Name), S(std::move(S)) {}
   Status getStatus() { return S; }
+  void addContent(std::unique_ptr Content) {
+Contents.push_back(std::move(Content));
+  }
+  Entry *getLastContent() const { return Contents.back().get(); }
   typedef decltype(Contents)::iterator iterator;
   iterator contents_begin() { return Contents.begin(); }
   iterator contents_end() { return Contents.end(); }
@@ -747,6 +753,7 @@ public:
 return UseName == NK_NotSet ? GlobalUseExternalName
 : (UseName == NK_External);
   }
+  NameKind getUseName() const { return UseName; }
   static bool classof(const Entry *E) { return E->getKind() == EK_File; }
 };
 
@@ -1023,6 +1030,70 @@ class RedirectingFileSystemParser {
 return true;
   }
 
+  Entry *lookupOrCreateEntry(RedirectingFileSystem *FS, StringRef Name,
+ Entry *ParentEntry = nullptr) {
+if (!ParentEntry) { // Look for a existent root
+  for (const std::unique_ptr &Root : FS->Roots) {
+if (Name.equals(Root->getName())) {
+  ParentEntry = Root.get();
+  return ParentEntry;
+}
+  }
+} else { // Advance to the next component
+  auto *DE = dyn_cast(ParentEntry);
+  for (std::unique_ptr &Content :
+   llvm::make_range(DE->contents_begin(), DE->contents_end())) {
+auto *DirContent = dyn_cast(Content.get());
+if (DirContent && Name.equals(Content->getName()))
+  return DirContent;
+  }
+}
+
+// ... or create a new one
+std::unique_ptr E = llvm::make_unique(
+Name, Status("", getNextVirtualUniqueID(), sys::TimeValue::now(), 0, 0,
+ 0, file_type::directory_file, sys::fs::all_all));
+
+if (!ParentEntry) { // Add a new root to the overlay
+  FS->Roots.push_back(std::move(E));
+  ParentEntry = FS->Roots.back().get();
+  return ParentEntry;
+}
+
+auto *DE = dyn_cast(ParentEntry);
+DE->addContent(std::move(E));
+return DE->getLastContent();
+  }
+
+  void uniqueOverlayTree(RedirectingFileSystem *FS, Entry *SrcE,
+ Entry *NewParentE = nullptr) {
+StringRef Name = SrcE->getName();
+switch (SrcE->getKind()) {
+case EK_Directory: {
+  auto *DE = dyn_cast(SrcE);
+  assert(DE && "Must be a directory");
+  // Empty directories could be present in the YAML as a way to
+  // describe a file for a current directory after some of its subdir
+  // is parsed. This only leads to redundant walks, ign

Re: [PATCH] D20196: [clang-tidy] Inefficient string operation

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.
etienneb added a comment.

drive-by, some nits.



Comment at: clang-tidy/performance/InefficientStringAdditionCheck.cpp:31
@@ +30,3 @@
+void InefficientStringAdditionCheck::registerMatchers(MatchFinder *Finder) {
+  auto BasicStringType = 
hasType(cxxRecordDecl(hasName("::std::basic_string")));
+

nits: I kind of prefer :

const auto BasicStringType

here and below.


Comment at: clang-tidy/performance/InefficientStringAdditionCheck.cpp:74
@@ +73,3 @@
+Finder->addMatcher(WholeMatcher, this);
+
+Finder->addMatcher(exprWithCleanups(hasDescendant(PlusOperatorMatcher),

nits: remove this line


Comment at: docs/clang-tidy/checks/performance-inefficient-string-addition.rst:4
@@ +3,3 @@
+performance-inefficient-string-addition
+=
+

line with "===" should be the same length than title.


Comment at: 
docs/clang-tidy/checks/performance-inefficient-string-addition.rst:11
@@ +10,3 @@
+.. code:: c++
+
+

nits: delete one blank line


Comment at: 
docs/clang-tidy/checks/performance-inefficient-string-addition.rst:19
@@ +18,3 @@
+.. code:: c++
+
+   

remove extra blank line (only one)


Comment at: 
docs/clang-tidy/checks/performance-inefficient-string-addition.rst:45
@@ +44,3 @@
+   {
+   f(a+"Bar"+b);
+   }

nits: spaces between operator "+"


http://reviews.llvm.org/D20196



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


Re: [PATCH] D20133: [OpenCL] Fix __builtin_astype for vec3 types.

2016-05-12 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a comment.
This revision is now accepted and ready to land.

LGTM.



Comment at: test/CodeGenOpenCL/as_type.cl:6
@@ +5,3 @@
+
+//CHECK: define spir_func <3 x i8> @f1(<4 x i8> %[[x:.*]])
+//CHECK: %[[astype:.*]] = shufflevector <4 x i8> %[[x]], <4 x i8> undef, <3 x 
i32> 

Could you also one test case that requires bitcast from vector type to 
4-element vector type, please?
E.g. short2 <-> char3 or char16 <-> int3.


http://reviews.llvm.org/D20133



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


[PATCH] D20218: [Tooling] Fix broken dependency for shared build

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

There virtual destructor can't be found and cause a compilation error
on a shared build.

To repro: [Release + Shared]
```
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
```

Which produce this error:
```
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ToolingTest.cpp.o: In 
function 
`clang::tooling::newFrontendActionFactory_CreatesFrontendActionFactoryFromType_Test::TestBody()':
ToolingTest.cpp:(.text._ZN5clang7tooling66newFrontendActionFactory_CreatesFrontendActionFactoryFromType_Test8TestBodyEv+0x49):
 undefined reference to `clang::SyntaxOnlyAction::~SyntaxOnlyAction()'
```

http://reviews.llvm.org/D20218

Files:
  include/clang/Frontend/FrontendActions.h
  lib/Frontend/FrontendActions.cpp

Index: lib/Frontend/FrontendActions.cpp
===
--- lib/Frontend/FrontendActions.cpp
+++ lib/Frontend/FrontendActions.cpp
@@ -401,6 +401,9 @@
   return OS;
 }
 
+SyntaxOnlyAction::~SyntaxOnlyAction() {
+}
+
 std::unique_ptr
 SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
   return llvm::make_unique();
Index: include/clang/Frontend/FrontendActions.h
===
--- include/clang/Frontend/FrontendActions.h
+++ include/clang/Frontend/FrontendActions.h
@@ -129,6 +129,7 @@
  StringRef InFile) override;
 
 public:
+  ~SyntaxOnlyAction() override;
   bool hasCodeCompletionSupport() const override { return true; }
 };
 


Index: lib/Frontend/FrontendActions.cpp
===
--- lib/Frontend/FrontendActions.cpp
+++ lib/Frontend/FrontendActions.cpp
@@ -401,6 +401,9 @@
   return OS;
 }
 
+SyntaxOnlyAction::~SyntaxOnlyAction() {
+}
+
 std::unique_ptr
 SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
   return llvm::make_unique();
Index: include/clang/Frontend/FrontendActions.h
===
--- include/clang/Frontend/FrontendActions.h
+++ include/clang/Frontend/FrontendActions.h
@@ -129,6 +129,7 @@
  StringRef InFile) override;
 
 public:
+  ~SyntaxOnlyAction() override;
   bool hasCodeCompletionSupport() const override { return true; }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20218: [Tooling] Fix broken dependency for shared build

2016-05-12 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

note: To repro, you must compile the tests.

  % ninja check-all


http://reviews.llvm.org/D20218



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


Re: [PATCH] D20218: [Tooling] Fix broken dependency for shared build

2016-05-12 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


http://reviews.llvm.org/D20218



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


Re: [PATCH] D19484: [OpenCL] Add supported OpenCL extensions to target info.

2016-05-12 Thread Alexey Bader via cfe-commits
bader added inline comments.


Comment at: include/clang/Basic/OpenCLExtensions.def:64
@@ +63,3 @@
+OPENCLEXT_INTERNAL(cl_khr_initialize_memory, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_spir, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)

Minimum required version should be 120.
cl_khr_spir was available in OpenCL 1.2 as well as cl_khr_depth_images and 
cl_khr_gl_depth_images.
https://www.khronos.org/registry/cl/specs/opencl-1.2-extensions.pdf



http://reviews.llvm.org/D19484



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


Re: [PATCH] D20045: [ObjC][CodeGen] Remove an assert that is no longer correct.

2016-05-12 Thread Akira Hatanaka via cfe-commits
ahatanak updated this revision to Diff 57088.
ahatanak added a comment.

Add a comment explaining why it is OK to return early if the global variable 
has an initializer.


http://reviews.llvm.org/D20045

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenObjCXX/arc-cxx11-init-list.mm

Index: test/CodeGenObjCXX/arc-cxx11-init-list.mm
===
--- test/CodeGenObjCXX/arc-cxx11-init-list.mm
+++ test/CodeGenObjCXX/arc-cxx11-init-list.mm
@@ -1,5 +1,11 @@
 // RUN: %clang_cc1 -triple armv7-ios5.0 -std=c++11 -fobjc-arc -Os -emit-llvm 
-o - %s | FileCheck %s
 
+// CHECK: @[[STR0:.*]] = private unnamed_addr constant [5 x i8] c"str0\00", 
section "__TEXT,__cstring,cstring_literals"
+// CHECK: @[[UNNAMED_CFSTRING0:.*]] = private constant 
%struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x 
i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* 
getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR0]], i32 0, i32 0), i32 4 }, 
section "__DATA,__cfstring"
+// CHECK: @[[STR1:.*]] = private unnamed_addr constant [5 x i8] c"str1\00", 
section "__TEXT,__cstring,cstring_literals"
+// CHECK: @[[UNNAMED_CFSTRING1:.*]] = private constant 
%struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x 
i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* 
getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR1]], i32 0, i32 0), i32 4 }, 
section "__DATA,__cfstring"
+// CHECK: @[[REFTMP:.*]] = private constant [2 x i8*] [i8* bitcast 
(%struct.__NSConstantString_tag* @[[UNNAMED_CFSTRING0]] to i8*), i8* bitcast 
(%struct.__NSConstantString_tag* @[[UNNAMED_CFSTRING1]] to i8*)]
+
 typedef __SIZE_TYPE__ size_t;
 
 namespace std {
@@ -32,6 +38,17 @@
 // CHECK-NEXT: store i8* [[INSTANCE]], i8** [[CAST]],
 // CHECK: call void @objc_release(i8* {{.*}})
 
+std::initializer_list foo1() {
+  return {@"str0", @"str1"};
+}
+
+// CHECK: define void @_Z4foo1v(%"class.std::initializer_list.0"* {{.*}} 
%[[AGG_RESULT:.*]])
+// CHECK: %[[BEGIN:.*]] = getelementptr inbounds 
%"class.std::initializer_list.0", %"class.std::initializer_list.0"* 
%[[AGG_RESULT]], i32 0, i32 0
+// CHECK: store i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* 
@[[REFTMP]], i32 0, i32 0), i8*** %[[BEGIN]]
+// CHECK: %[[SIZE:.*]] = getelementptr inbounds 
%"class.std::initializer_list.0", %"class.std::initializer_list.0"* 
%[[AGG_RESULT]], i32 0, i32 1
+// CHECK: store i32 2, i32* %[[SIZE]]
+// CHECK: ret void
+
 void external();
 
 extern "C" void extended() {
@@ -49,4 +66,3 @@
 // CHECK: [[INSTANCE:%.*]] = {{.*}} call i8* bitcast (i8* (i8*, i8*, ...)* 
@objc_msgSend to i8* (i8*, i8*)*)(i8* {{.*}}, i8* {{.*}})
 // CHECK-NEXT: store i8* [[INSTANCE]], i8** bitcast ([1 x %0*]* @_ZGR2il_ to 
i8**)
 // CHECK: {{.*}} call void @objc_autoreleasePoolPop(i8* [[POOL]])
-
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -360,9 +360,12 @@
ConvertTypeForMem(E->getType())
  ->getPointerTo(Object.getAddressSpace())),
Object.getAlignment());
-  // We should not have emitted the initializer for this temporary as a
-  // constant.
-  assert(!Var->hasInitializer());
+
+  // If the global variable already has an initializer, there is no need to
+  // emit code for initialization or push a cleanup.
+  if (Var->hasInitializer())
+return MakeAddrLValue(Object, M->getType(), AlignmentSource::Decl);
+
   Var->setInitializer(CGM.EmitNullConstant(E->getType()));
 }
 LValue RefTempDst = MakeAddrLValue(Object, M->getType(),


Index: test/CodeGenObjCXX/arc-cxx11-init-list.mm
===
--- test/CodeGenObjCXX/arc-cxx11-init-list.mm
+++ test/CodeGenObjCXX/arc-cxx11-init-list.mm
@@ -1,5 +1,11 @@
 // RUN: %clang_cc1 -triple armv7-ios5.0 -std=c++11 -fobjc-arc -Os -emit-llvm -o - %s | FileCheck %s
 
+// CHECK: @[[STR0:.*]] = private unnamed_addr constant [5 x i8] c"str0\00", section "__TEXT,__cstring,cstring_literals"
+// CHECK: @[[UNNAMED_CFSTRING0:.*]] = private constant %struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR0]], i32 0, i32 0), i32 4 }, section "__DATA,__cfstring"
+// CHECK: @[[STR1:.*]] = private unnamed_addr constant [5 x i8] c"str1\00", section "__TEXT,__cstring,cstring_literals"
+// CHECK: @[[UNNAMED_CFSTRING1:.*]] = private constant %struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR1]], i32 0, i32 0), i32 4 }, section "__DATA,__cfstring"
+// CHECK: @[[REFTMP:.*]] = private constant [2 x i8*] [i8* b

[PATCH] D20219: [CodeGen] Clang does not choose aapcs-vfp calling convention for ARM bare metal target with hard float (EABIHF)

2016-05-12 Thread Oleg Ranevskyy via cfe-commits
iid_iunknown created this revision.
iid_iunknown added reviewers: rengolin, t.p.northover, compnerd.
iid_iunknown added subscribers: cfe-commits, asl.
iid_iunknown set the repository for this revision to rL LLVM.
Herald added subscribers: rengolin, aemerson.

Clang does not detect `aapcs-vfp` for the EABIHF environment. The reason is 
that only GNUEABIHF is considered while choosing calling convention, EABIHF is 
ignored.

This causes clang to use `aapcs` for EABIHF and add the `arm_aapcscc` specifier 
to functions in generated IR.

The modified `arm-cc.c` test checks that no calling convention specifier is 
added to functions for EABIHF, which means the default one is used 
(`CallingConv::ARM_AAPCS_VFP`).

Repository:
  rL LLVM

http://reviews.llvm.org/D20219

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/arm-cc.c

Index: test/CodeGen/arm-cc.c
===
--- test/CodeGen/arm-cc.c
+++ test/CodeGen/arm-cc.c
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-abi aapcs  -emit-llvm 
-w -o - %s | FileCheck -check-prefix=DARWIN-AAPCS %s
 // RUN: %clang_cc1 -triple arm-none-linux-gnueabi -target-abi apcs-gnu 
-emit-llvm -w -o - %s | FileCheck -check-prefix=LINUX-APCS %s
 // RUN: %clang_cc1 -triple arm-none-linux-gnueabi -target-abi aapcs  
-emit-llvm -w -o - %s | FileCheck -check-prefix=LINUX-AAPCS %s
+// RUN: %clang_cc1 -triple armv7-none-eabihf -target-abi aapcs-vfp -emit-llvm 
-w -o - %s | FileCheck -check-prefix=BAREMETAL-AAPCS_VFP %s
 
 
 // DARWIN-APCS-LABEL: define void @f()
@@ -13,6 +14,9 @@
 // LINUX-APCS: call arm_apcscc void @g
 // LINUX-AAPCS-LABEL: define void @f()
 // LINUX-AAPCS: call void @g
+// BAREMETAL-AAPCS_VFP-LABEL: define void @f()
+// BAREMETAL-AAPCS_VFP: call void @g
+// BAREMETAL-AAPCS_VFP: declare void @g()
 void g(void);
 void f(void) {
   g();
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -7804,7 +7804,8 @@
   Kind = ARMABIInfo::AAPCS16_VFP;
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
-  Triple.getEnvironment() == llvm::Triple::GNUEABIHF))
+  (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+   Triple.getEnvironment() == llvm::Triple::EABIHF)))
   Kind = ARMABIInfo::AAPCS_VFP;
 
 return SetCGInfo(new ARMTargetCodeGenInfo(Types, Kind));


Index: test/CodeGen/arm-cc.c
===
--- test/CodeGen/arm-cc.c
+++ test/CodeGen/arm-cc.c
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -triple armv7-apple-darwin9 -target-abi aapcs  -emit-llvm -w -o - %s | FileCheck -check-prefix=DARWIN-AAPCS %s
 // RUN: %clang_cc1 -triple arm-none-linux-gnueabi -target-abi apcs-gnu -emit-llvm -w -o - %s | FileCheck -check-prefix=LINUX-APCS %s
 // RUN: %clang_cc1 -triple arm-none-linux-gnueabi -target-abi aapcs  -emit-llvm -w -o - %s | FileCheck -check-prefix=LINUX-AAPCS %s
+// RUN: %clang_cc1 -triple armv7-none-eabihf -target-abi aapcs-vfp -emit-llvm -w -o - %s | FileCheck -check-prefix=BAREMETAL-AAPCS_VFP %s
 
 
 // DARWIN-APCS-LABEL: define void @f()
@@ -13,6 +14,9 @@
 // LINUX-APCS: call arm_apcscc void @g
 // LINUX-AAPCS-LABEL: define void @f()
 // LINUX-AAPCS: call void @g
+// BAREMETAL-AAPCS_VFP-LABEL: define void @f()
+// BAREMETAL-AAPCS_VFP: call void @g
+// BAREMETAL-AAPCS_VFP: declare void @g()
 void g(void);
 void f(void) {
   g();
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -7804,7 +7804,8 @@
   Kind = ARMABIInfo::AAPCS16_VFP;
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
-  Triple.getEnvironment() == llvm::Triple::GNUEABIHF))
+  (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+   Triple.getEnvironment() == llvm::Triple::EABIHF)))
   Kind = ARMABIInfo::AAPCS_VFP;
 
 return SetCGInfo(new ARMTargetCodeGenInfo(Types, Kind));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19708: [CGDebugInfo] Generate debug info for member calls in the context of the callee expression

2016-05-12 Thread David Blaikie via cfe-commits
On Mon, May 2, 2016 at 1:17 PM, Hal Finkel  wrote:

> - Original Message -
> > From: "David Blaikie" 
> > To: reviews+d19708+public+e9ddc42503732...@reviews.llvm.org, "Hal
> Finkel" 
> > Cc: "Richard Smith" , "Adrian Prantl" <
> apra...@apple.com>, "Duncan P. N. Exon Smith"
> > , "Eric Christopher" , "Jun
> Bum Lim" ,
> > "cfe-commits" 
> > Sent: Friday, April 29, 2016 4:52:26 PM
> > Subject: Re: [PATCH] D19708: [CGDebugInfo] Generate debug info for
> member calls in the context of the callee
> > expression
> >
> >
> > You could simplify the test case further, down to just:
> >
> > struct foo { void bar(); };
> > void f(foo *f) {
> > f->bar();
> > }
> >
> > and check that the call instruction has the desired column (or if you
> > want a test that doesn't depend on column info (you can force it on
> > with a flag, but we might vary whether it's on by default based on
> > target, etc, I'm not sure) you could put 'bar();' on a separate line
> > from 'f->' and check the call was on the second line and not the
> > first).
>
> Certainly. I'm not sure much we want to reduce the test case, however,
> because I particularly want to cover the case of two calls on the same line
> with column info.


Why is it helpful to cover two calls? That's certainly where the issue was
observed, but it's not the bug/fix as such. Once we put the location at the
start of the function name we incidentally improve the situation where
there are two calls.


> Given that this is still pretty simple, I think that covering it directly
> seems reasonable.
>

I think it can make tests more confusing when it comes to tracking the
actual behavior change/intent of the test, etc.


> > Richard might be able to tell us whether there's a preferred place
> > for a test for a change like this - should it be a debug info test,
> > a diagnostic test,
>
> At least for the test you suggested in a previous e-mail, this patch has
> no effect on the output diagnostics (although it certainly does have the
> desired effect on the debug info). Specifically, even with this patch, we
> still have:
>
>   $ cat /tmp/loc.cpp
>   struct foo {
> const foo *x() const;
> void y();
>   };
>
>   void f(const foo *g) {
> g->x()->y();
> g->x()->x()->y();
>   }
>
> $ clang /tmp/loc.cpp -fsyntax-only
>   /tmp/loc.cpp:7:3: error: member function 'y' not viable: 'this' argument
> has type 'const foo', but function is not marked const
> g->x()->y();
> ^~
>   /tmp/loc.cpp:3:8: note: 'y' declared here
> void y();
>  ^
>   /tmp/loc.cpp:8:3: error: member function 'y' not viable: 'this' argument
> has type 'const foo', but function is not marked const
> g->x()->x()->y();
> ^~~
>   /tmp/loc.cpp:3:8: note: 'y' declared here
> void y();
>  ^
>   2 errors generated.
>

Curious - perhaps we should fix the diagnostic too? I guess it's using the
start location instead of the preferred location?

Hmm, yeah, maybe that's not right anyway - it's specifically trying to
describe the left operand, though that's different from any case where a
normal operand is mismatched by constness. Then it just says it can't call
the function & points to the function (with a note explaining)

Anyway - seems OK. Please commit.

- David


>
> Thanks again,
> Hal
>
> > or perhaps just an ast dump test?
> >
> > Perhaps a test for the case where there is no valid callee would be
> > good? Where does that come up - call through a member function
> > pointer?
> >
> >
> > On Fri, Apr 29, 2016 at 9:19 AM, Hal Finkel via cfe-commits <
> > cfe-commits@lists.llvm.org > wrote:
> >
> >
> > hfinkel updated this revision to Diff 55610.
> > hfinkel added a comment.
> >
> > Use David's suggested approach: Modify the preferred expression
> > location for member calls. If the callee has a valid location (not
> > all do), then use that. Otherwise, fall back to the starting
> > location. This seems to cleanly fix the debug-info problem.
> >
> >
> > http://reviews.llvm.org/D19708
> >
> > Files:
> > include/clang/AST/ExprCXX.h
> >
> >
> > test/CodeGenCXX/debug-info-member-call.cpp
> >
> > Index: test/CodeGenCXX/debug-info-member-call.cpp
> > ===
> > --- /dev/null
> > +++ test/CodeGenCXX/debug-info-member-call.cpp
> > @@ -0,0 +1,24 @@
> > +// RUN: %clang_cc1 -triple x86_64-unknown_unknown -emit-llvm
> > -debug-info-kind=standalone -dwarf-column-info %s -o - | FileCheck
> > %s
> > +void ext();
> > +
> > +struct Bar {
> > + void bar() { ext(); }
> > +};
> > +
> > +struct Foo {
> > + Bar *b;
> > +
> > + Bar *foo() { return b; }
> > +};
> > +
> > +void test(Foo *f) {
> > + f->foo()->bar();
> > +}
> > +
> > +// CHECK-LABEL: @_Z4testP3Foo
> > +// CHECK: call {{.*}} @_ZN3Foo3fooEv{{.*}}, !dbg ![[CALL1LOC:.*]]
> > +// CHECK: call void @_ZN3Bar3barEv{{.*}}, !dbg ![[CALL2LOC:.*]]
> > +
> > +// CHECK: ![[CALL1LOC]] = !DILocation(line: [[LINE:[0-9]+]], column:
> > 6,
> > +// CHECK: ![[CALL2LOC]] = !DILoc

  1   2   >