[PATCH] D44189: [RISCV] Verify the input value of -march=

2018-03-06 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng created this revision.
kito-cheng added reviewers: asb, apazos.
Herald added subscribers: cfe-commits, shiva0217, niosHD, sabuasal, 
jordy.potman.lists, simoncook, johnrusso, rbar.

This patch doing more check and verify the -march= string and will issue and 
error if it's a invalid combination.


Repository:
  rC Clang

https://reviews.llvm.org/D44189

Files:
  lib/Driver/ToolChains/Arch/RISCV.cpp
  test/Driver/riscv-arch.c

Index: test/Driver/riscv-arch.c
===
--- /dev/null
+++ test/Driver/riscv-arch.c
@@ -0,0 +1,23 @@
+// RUN: %clang -target riscv32-unknown-elf -march=rv32 -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32 %s
+// RV32: error: invalid arch name 'rv32'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32m -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32M %s
+// RV32M: error: invalid arch name 'rv32m'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32id -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32ID %s
+// RV32ID: error: invalid arch name 'rv32id'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32l -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32L %s
+// RV32L: error: invalid arch name 'rv32l'
+
+// RUN: %clang -target riscv64-unknown-elf -march=rv64 -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64 %s
+// RV64: error: invalid arch name 'rv64'
+
+// RUN: %clang -target riscv64-unknown-elf -march=rv64m -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64M %s
+// RV64M: error: invalid arch name 'rv64m'
+
+// RUN: %clang -target riscv64-unknown-elf -march=rv64id -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64ID %s
+// RV64ID: error: invalid arch name 'rv64id'
+
+// RUN: %clang -target riscv64-unknown-elf -march=rv64l -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64L %s
+// RV64L: error: invalid arch name 'rv64l'
Index: lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- lib/Driver/ToolChains/Arch/RISCV.cpp
+++ lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -23,33 +23,65 @@
 void riscv::getRISCVTargetFeatures(const Driver &D, const ArgList &Args,
std::vector &Features) {
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
-StringRef MArch = A->getValue();
-// TODO: handle rv64
-std::pair MArchSplit = StringRef(MArch).split("rv32");
-if (!MArchSplit.second.size())
+StringRef March = A->getValue();
+if (!(March.startswith("rv32") || March.startswith("rv64")) ||
+(March.size() < 5)) {
+  // ISA string must begin with rv32 or rv64.
+  D.Diag(diag::err_drv_invalid_arch_name) << March;
   return;
+}
+
+bool hasF = false, hasD = false;
+char baseline = March[4];
+
+switch (baseline) {
+case 'i':
+  break;
+case 'g':
+  Features.push_back("+m");
+  Features.push_back("+a");
+  Features.push_back("+f");
+  Features.push_back("+d");
+  hasF = true;
+  hasD = true;
+  break;
+default:
+  // First letter should be 'i' or 'g'.
+  D.Diag(diag::err_drv_invalid_arch_name) << March;
+  break;
+}
 
-for (char c : MArchSplit.second) {
+// Skip rvxxx
+StringRef Exts = March.substr(5);
+
+for (char c : Exts) {
   switch (c) {
-  case 'i':
-break;
   case 'm':
 Features.push_back("+m");
 break;
   case 'a':
 Features.push_back("+a");
 break;
   case 'f':
 Features.push_back("+f");
+hasF = true;
 break;
   case 'd':
 Features.push_back("+d");
+hasD = true;
 break;
   case 'c':
 Features.push_back("+c");
 break;
+  default:
+D.Diag(diag::err_drv_invalid_arch_name) << March;
+break;
   }
 }
+
+// Dependency check
+if (hasD && !hasF)
+  D.Diag(diag::err_drv_invalid_arch_name) << March;
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43805: Optionally use nameless IR types

2018-03-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

In https://reviews.llvm.org/D43805#1029479, @pcc wrote:

> > If the backend will be changed so that it will not depend on IR type names
>
> Are you referring to https://reviews.llvm.org/D43199? If so it seems to me 
> that this should be a cc1 flag that defaults to whether `-flto=thin` is 
> passed. In any case it seems like a bad idea to deliberately generate 
> different code depending on whether we were compiled with NDEBUG.


No, I try to implement alternative approach, to solve the problem targeted in 
https://reviews.llvm.org/D40508. If  IR type names are only for human 
readability, than using them in opaque type resolution does not look 
reasonable. Probably, more correct way is to make type merge only as a side 
effect of merge of other entities, which may have "real" names, that is 
functions and variables.


Repository:
  rC Clang

https://reviews.llvm.org/D43805



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


r326873 - Remove a placeholder

2018-03-06 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Tue Mar  6 21:02:27 2018
New Revision: 326873

URL: http://llvm.org/viewvc/llvm-project?rev=326873&view=rev
Log:
Remove a placeholder

...Running tests in the wrong directory will often make them seem to
pass. Oops. :)

Modified:
cfe/trunk/test/CodeGenCXX/alloc-size.cpp

Modified: cfe/trunk/test/CodeGenCXX/alloc-size.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/alloc-size.cpp?rev=326873&r1=326872&r2=326873&view=diff
==
--- cfe/trunk/test/CodeGenCXX/alloc-size.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/alloc-size.cpp Tue Mar  6 21:02:27 2018
@@ -79,7 +79,7 @@ struct Foo {
 
 void *my_malloc(const Foo &, int N) __attribute__((alloc_size(2)));
 
-// CHECK-LABEL: define i32 lalala
+// CHECK-LABEL: define i32 @_ZN24alloc_size_with_cleanups6testItEv
 int testIt() {
   int *const p = (int *)my_malloc(Foo{}, 3);
   // CHECK: ret i32 3


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


[PATCH] D43805: Optionally use nameless IR types

2018-03-06 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

> If the backend will be changed so that it will not depend on IR type names

Are you referring to https://reviews.llvm.org/D43199? If so it seems to me that 
this should be a cc1 flag that defaults to whether `-flto=thin` is passed. In 
any case it seems like a bad idea to deliberately generate different code 
depending on whether we were compiled with NDEBUG.


Repository:
  rC Clang

https://reviews.llvm.org/D43805



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


Re: r326766 - [ExprConstant] Look through ExprWithCleanups for `allocsize`

2018-03-06 Thread George Burgess IV via cfe-commits
Relanded in r326872. Thanks!

On Tue, Mar 6, 2018 at 7:03 PM, Nico Weber  wrote:

> Apologies, I had to revert the change that touched alloc-size.cpp before
> this change in r326862. After that revert, your new test here failed, and
> since I didn't understand how to make it passed, I reverted your change
> in 326869 too. It should hopefully be easy for you to reland it.
>
> On Tue, Mar 6, 2018 at 2:42 AM, George Burgess IV via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: gbiv
>> Date: Mon Mar  5 23:42:36 2018
>> New Revision: 326766
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=326766&view=rev
>> Log:
>> [ExprConstant] Look through ExprWithCleanups for `allocsize`
>>
>> Modified:
>> cfe/trunk/lib/AST/ExprConstant.cpp
>> cfe/trunk/test/CodeGenCXX/alloc-size.cpp
>>
>> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCo
>> nstant.cpp?rev=326766&r1=326765&r2=326766&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
>> +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Mar  5 23:42:36 2018
>> @@ -133,7 +133,11 @@ namespace {
>>
>>  E = E->IgnoreParens();
>>  // If we're doing a variable assignment from e.g. malloc(N), there
>> will
>> -// probably be a cast of some kind. Ignore it.
>> +// probably be a cast of some kind. In exotic cases, we might also
>> see a
>> +// top-level ExprWithCleanups. Ignore them either way.
>> +if (const auto *EC = dyn_cast(E))
>> +  E = EC->getSubExpr()->IgnoreParens();
>> +
>>  if (const auto *Cast = dyn_cast(E))
>>E = Cast->getSubExpr()->IgnoreParens();
>>
>>
>> Modified: cfe/trunk/test/CodeGenCXX/alloc-size.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCX
>> X/alloc-size.cpp?rev=326766&r1=326765&r2=326766&view=diff
>> 
>> ==
>> --- cfe/trunk/test/CodeGenCXX/alloc-size.cpp (original)
>> +++ cfe/trunk/test/CodeGenCXX/alloc-size.cpp Mon Mar  5 23:42:36 2018
>> @@ -88,3 +88,15 @@ int callMemberCalloc() {
>>// CHECK: ret i32 32
>>return __builtin_object_size(C().my_calloc(16, 2), 0);
>>  }
>> +
>> +struct D {
>> +  ~D();
>> +  void *my_malloc(int N) __attribute__((alloc_size(2)));
>> +};
>> +
>> +// CHECK-LABEL: define i32 @_Z20callExprWithCleanupsv
>> +int callExprWithCleanups() {
>> +  int *const p = (int *)D().my_malloc(3);
>> +  // CHECK: ret i32 3
>> +  return __builtin_object_size(p, 0);
>> +}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r326872 - Reland r326766 (with a slightly modified test)

2018-03-06 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Tue Mar  6 20:52:34 2018
New Revision: 326872

URL: http://llvm.org/viewvc/llvm-project?rev=326872&view=rev
Log:
Reland r326766 (with a slightly modified test)

The original revert was done in r326869, since reverting r326602 broke
the test added by this.

The new test should be less dependent on r326602.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGenCXX/alloc-size.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=326872&r1=326871&r2=326872&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Mar  6 20:52:34 2018
@@ -133,7 +133,11 @@ namespace {
 
 E = E->IgnoreParens();
 // If we're doing a variable assignment from e.g. malloc(N), there will
-// probably be a cast of some kind. Ignore it.
+// probably be a cast of some kind. In exotic cases, we might also see a
+// top-level ExprWithCleanups. Ignore them either way.
+if (const auto *EC = dyn_cast(E))
+  E = EC->getSubExpr()->IgnoreParens();
+
 if (const auto *Cast = dyn_cast(E))
   E = Cast->getSubExpr()->IgnoreParens();
 

Modified: cfe/trunk/test/CodeGenCXX/alloc-size.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/alloc-size.cpp?rev=326872&r1=326871&r2=326872&view=diff
==
--- cfe/trunk/test/CodeGenCXX/alloc-size.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/alloc-size.cpp Tue Mar  6 20:52:34 2018
@@ -70,3 +70,19 @@ int testIt() {
  __builtin_object_size(dependent_calloc2(), 0);
 }
 } // namespace templated_alloc_size
+
+// Be sure that an ExprWithCleanups doesn't deter us.
+namespace alloc_size_with_cleanups {
+struct Foo {
+  ~Foo();
+};
+
+void *my_malloc(const Foo &, int N) __attribute__((alloc_size(2)));
+
+// CHECK-LABEL: define i32 lalala
+int testIt() {
+  int *const p = (int *)my_malloc(Foo{}, 3);
+  // CHECK: ret i32 3
+  return __builtin_object_size(p, 0);
+}
+} // namespace alloc_size_with_cleanups


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


[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2018-03-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I'm sorry, I did a review of your patch on Phabricator but apparently never 
submitted it.




Comment at: lib/CodeGen/CGCall.h:219
+  RValue RV;
+  LValue LV; /// The l-value from which the argument is derived.
+};

This could be clearer.  I would say something like "The argument is 
semantically a load from this l-value."



Comment at: lib/CodeGen/CGCall.h:221
+};
+bool HasLV;
+

Please add an IsUsed flag so that you can assert that e.g. getRValue and/or 
copyInto aren't called twice.  It's okay for this to be `mutable`, since it's 
just a data-flow assertion rather than logically a change to the value of the 
argument.



Comment at: lib/CodeGen/CGCall.h:226
+CallArg(RValue rv, QualType ty) : RV(rv), HasLV(false), Ty(ty) {}
+CallArg(LValue _LV, QualType ty) : LV(_LV), HasLV(true), Ty(ty) {}
+bool hasLValue() const { return HasLV; }

Why the two different naming conventions for these parameters?  Just call the 
new one `lv` for consistency, please.



Comment at: lib/CodeGen/CGCall.h:234
+
+LValue getLValue() const {
+  assert(HasLV);

Please name this something like `getKnownLValue` and add a parallel 
`getKnownRValue`. These should assert `!IsUsed` but not set it.



Comment at: lib/CodeGen/CGCall.h:248
+  return HasLV ? LV.getAddress() : RV.getAggregateAddress();
+}
+

Part of my thinking in suggesting this representation change was that the 
current representation was prone to a certain kind of bug where clients blindly 
use the RValue without realizing that it's actually something they need to copy 
from instead of using directly. That is generally a bug because indirect 
arguments are expected to be independent slots and are not permitted to alias. 
The new representation implicitly fixes these bugs by pushing users towards 
using one of these approaches.

All of this is to say that I'm not thrilled about having a getAggregateAddress 
here.


https://reviews.llvm.org/D34367



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


Re: [libcxxabi] r326797 - [demangler] Modernize the rest of the demangler.

2018-03-06 Thread Nico Weber via cfe-commits
Thanks for the quick fix!

On Tue, Mar 6, 2018 at 11:32 PM, Erik Pilkington 
wrote:

> No, that was a mistake, fixed in r326871. Thanks for pointing this out!
> Erik
>
>
> On 2018-03-06 11:10 PM, Nico Weber wrote:
>
> Hi Erik,
>
> before this change, ___Z10blocksNRVOv_block_invoke demangled to
> 'invocation function for block in blocksNRVO()', now it's no longer
> demangled. Was that an intentional change?
>
> On Tue, Mar 6, 2018 at 9:21 AM, Erik Pilkington via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: epilk
>> Date: Tue Mar  6 06:21:10 2018
>> New Revision: 326797
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=326797&view=rev
>> Log:
>> [demangler] Modernize the rest of the demangler.
>>
>> Modified:
>> libcxxabi/trunk/src/cxa_demangle.cpp
>> libcxxabi/trunk/test/test_demangle.pass.cpp
>>
>> Modified: libcxxabi/trunk/src/cxa_demangle.cpp
>> URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_
>> demangle.cpp?rev=326797&r1=326796&r2=326797&view=diff
>> 
>> ==
>> --- libcxxabi/trunk/src/cxa_demangle.cpp (original)
>> +++ libcxxabi/trunk/src/cxa_demangle.cpp Tue Mar  6 06:21:10 2018
>> @@ -2002,6 +2002,8 @@ struct Db {
>>
>>BumpPointerAllocator ASTAllocator;
>>
>> +  Db(const char *First_, const char *Last_) : First(First_), Last(Last_)
>> {}
>> +
>>template  T *make(Args &&... args) {
>>  return new (ASTAllocator.allocate(sizeof(T)))
>>  T(std::forward(args)...);
>> @@ -2054,6 +2056,12 @@ struct Db {
>>bool parsePositiveInteger(size_t *Out);
>>StringView parseBareSourceName();
>>
>> +  bool parseSeqId(size_t *Out);
>> +  Node *parseSubstitution();
>> +  Node *parseTemplateParam();
>> +  Node *parseTemplateArgs();
>> +  Node *parseTemplateArg();
>> +
>>/// Parse the  production.
>>Node *parseExpr();
>>Node *parsePrefixExpr(StringView Kind);
>> @@ -2109,66 +2117,11 @@ struct Db {
>>Node *parseUnresolvedType();
>>Node *parseDestructorName();
>>
>> -  // FIXME: remove this when all the parse_* functions have been
>> rewritten.
>> -  template 
>> -  Node *legacyParse() {
>> -size_t BeforeType = Names.size();
>> -const char *OrigFirst = First;
>> -const char *T = parse_fn(First, Last, *this);
>> -if (T == OrigFirst || BeforeType + 1 != Names.size())
>> -  return nullptr;
>> -First = T;
>> -Node *R = Names.back();
>> -Names.pop_back();
>> -return R;
>> -  }
>> +  /// Top-level entry point into the parser.
>> +  Node *parse();
>>  };
>>
>> -const char *parse_expression(const char *first, const char *last, Db
>> &db) {
>> -  db.First = first;
>> -  db.Last = last;
>> -  Node *R = db.parseExpr();
>> -  if (R == nullptr)
>> -return first;
>> -  db.Names.push_back(R);
>> -  return db.First;
>> -}
>> -
>> -const char *parse_expr_primary(const char *first, const char *last, Db
>> &db) {
>> -  db.First = first;
>> -  db.Last = last;
>> -  Node *R = db.parseExprPrimary();
>> -  if (R == nullptr)
>> -return first;
>> -  db.Names.push_back(R);
>> -  return db.First;
>> -}
>> -
>> -const char *parse_type(const char *first, const char *last, Db &db) {
>> -  db.First = first;
>> -  db.Last = last;
>> -  Node *R = db.parseType();
>> -  if (R == nullptr)
>> -return first;
>> -  db.Names.push_back(R);
>> -  return db.First;
>> -}
>> -
>> -const char *parse_encoding(const char *first, const char *last, Db &db) {
>> -  db.First = first;
>> -  db.Last = last;
>> -  Node *R = db.parseEncoding();
>> -  if (R == nullptr)
>> -return first;
>> -  db.Names.push_back(R);
>> -  return db.First;
>> -}
>> -
>>  const char* parse_discriminator(const char* first, const char* last);
>> -const char *parse_template_args(const char *first, const char *last, Db
>> &db);
>> -const char *parse_template_param(const char *, const char *, Db &);
>> -const char *parse_substitution(const char *, const char *, Db &);
>> -
>>
>>  //  ::=  // N
>>  //::=  # See Scope Encoding below  // Z
>> @@ -2187,10 +2140,12 @@ Node *Db::parseName(NameState *State) {
>>
>>//::=  
>>if (look() == 'S' && look(1) != 't') {
>> -Node *S = legacyParse();
>> +Node *S = parseSubstitution();
>> +if (S == nullptr)
>> +  return nullptr;
>>  if (look() != 'I')
>>return nullptr;
>> -Node *TA = legacyParse();
>> +Node *TA = parseTemplateArgs();
>>  if (TA == nullptr)
>>return nullptr;
>>  if (State) State->EndsWithTemplateArgs = true;
>> @@ -2203,7 +2158,7 @@ Node *Db::parseName(NameState *State) {
>>//::=  
>>if (look() == 'I') {
>>  Subs.push_back(N);
>> -Node *TA = legacyParse();
>> +Node *TA = parseTemplateArgs();
>>  if (TA == nullptr)
>>return nullptr;
>>  if (State) State->EndsWithTemplateArgs = true;
>> @@ -2693,7 +2648,7 @@ Node *Db::parseNestedName(NameState *Sta
>>
>>  //  ::= 
>>  if (look() == 'T') {
>> -  Node *TP = l

[PATCH] D43805: Optionally use nameless IR types

2018-03-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: include/clang/Driver/Options.td:644
+  HelpText<"Whether to use IR type names (option: auto, none, use)">,
+  Values<"auto,none,use">;
+

rsmith wrote:
> Having "none" and "use" as values for the same option seems like a category 
> error. always / never / auto would make some sense, though.
Indeed. Will change it.


Repository:
  rC Clang

https://reviews.llvm.org/D43805



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


Re: [libcxxabi] r326797 - [demangler] Modernize the rest of the demangler.

2018-03-06 Thread Erik Pilkington via cfe-commits

No, that was a mistake, fixed in r326871. Thanks for pointing this out!
Erik

On 2018-03-06 11:10 PM, Nico Weber wrote:

Hi Erik,

before this change, ___Z10blocksNRVOv_block_invoke demangled to 
'invocation function for block in blocksNRVO()', now it's no longer 
demangled. Was that an intentional change?


On Tue, Mar 6, 2018 at 9:21 AM, Erik Pilkington via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:


Author: epilk
Date: Tue Mar  6 06:21:10 2018
New Revision: 326797

URL: http://llvm.org/viewvc/llvm-project?rev=326797&view=rev

Log:
[demangler] Modernize the rest of the demangler.

Modified:
    libcxxabi/trunk/src/cxa_demangle.cpp
    libcxxabi/trunk/test/test_demangle.pass.cpp

Modified: libcxxabi/trunk/src/cxa_demangle.cpp
URL:

http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=326797&r1=326796&r2=326797&view=diff



==
--- libcxxabi/trunk/src/cxa_demangle.cpp (original)
+++ libcxxabi/trunk/src/cxa_demangle.cpp Tue Mar  6 06:21:10 2018
@@ -2002,6 +2002,8 @@ struct Db {

   BumpPointerAllocator ASTAllocator;

+  Db(const char *First_, const char *Last_) : First(First_),
Last(Last_) {}
+
   template  T *make(Args &&... args) {
     return new (ASTAllocator.allocate(sizeof(T)))
         T(std::forward(args)...);
@@ -2054,6 +2056,12 @@ struct Db {
   bool parsePositiveInteger(size_t *Out);
   StringView parseBareSourceName();

+  bool parseSeqId(size_t *Out);
+  Node *parseSubstitution();
+  Node *parseTemplateParam();
+  Node *parseTemplateArgs();
+  Node *parseTemplateArg();
+
   /// Parse the  production.
   Node *parseExpr();
   Node *parsePrefixExpr(StringView Kind);
@@ -2109,66 +2117,11 @@ struct Db {
   Node *parseUnresolvedType();
   Node *parseDestructorName();

-  // FIXME: remove this when all the parse_* functions have been
rewritten.
-  template 
-  Node *legacyParse() {
-    size_t BeforeType = Names.size();
-    const char *OrigFirst = First;
-    const char *T = parse_fn(First, Last, *this);
-    if (T == OrigFirst || BeforeType + 1 != Names.size())
-      return nullptr;
-    First = T;
-    Node *R = Names.back();
-    Names.pop_back();
-    return R;
-  }
+  /// Top-level entry point into the parser.
+  Node *parse();
 };

-const char *parse_expression(const char *first, const char *last,
Db &db) {
-  db.First = first;
-  db.Last = last;
-  Node *R = db.parseExpr();
-  if (R == nullptr)
-    return first;
-  db.Names.push_back(R);
-  return db.First;
-}
-
-const char *parse_expr_primary(const char *first, const char
*last, Db &db) {
-  db.First = first;
-  db.Last = last;
-  Node *R = db.parseExprPrimary();
-  if (R == nullptr)
-    return first;
-  db.Names.push_back(R);
-  return db.First;
-}
-
-const char *parse_type(const char *first, const char *last, Db &db) {
-  db.First = first;
-  db.Last = last;
-  Node *R = db.parseType();
-  if (R == nullptr)
-    return first;
-  db.Names.push_back(R);
-  return db.First;
-}
-
-const char *parse_encoding(const char *first, const char *last,
Db &db) {
-  db.First = first;
-  db.Last = last;
-  Node *R = db.parseEncoding();
-  if (R == nullptr)
-    return first;
-  db.Names.push_back(R);
-  return db.First;
-}
-
 const char* parse_discriminator(const char* first, const char* last);
-const char *parse_template_args(const char *first, const char
*last, Db &db);
-const char *parse_template_param(const char *, const char *, Db &);
-const char *parse_substitution(const char *, const char *, Db &);
-

 //  ::=  // N
 //        ::=  # See Scope Encoding below  // Z
@@ -2187,10 +2140,12 @@ Node *Db::parseName(NameState *State) {

   //        ::=  
   if (look() == 'S' && look(1) != 't') {
-    Node *S = legacyParse();
+    Node *S = parseSubstitution();
+    if (S == nullptr)
+      return nullptr;
     if (look() != 'I')
       return nullptr;
-    Node *TA = legacyParse();
+    Node *TA = parseTemplateArgs();
     if (TA == nullptr)
       return nullptr;
     if (State) State->EndsWithTemplateArgs = true;
@@ -2203,7 +2158,7 @@ Node *Db::parseName(NameState *State) {
   //        ::=  
   if (look() == 'I') {
     Subs.push_back(N);
-    Node *TA = legacyParse();
+    Node *TA = parseTemplateArgs();
     if (TA == nullptr)
       return nullptr;
   

[libcxxabi] r326871 - [demangler] Fix a mistake in r326797.

2018-03-06 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Tue Mar  6 20:29:33 2018
New Revision: 326871

URL: http://llvm.org/viewvc/llvm-project?rev=326871&view=rev
Log:
[demangler] Fix a mistake in r326797.

Thanks to Nico Weber for pointing this out!

Modified:
libcxxabi/trunk/src/cxa_demangle.cpp
libcxxabi/trunk/test/test_demangle.pass.cpp

Modified: libcxxabi/trunk/src/cxa_demangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=326871&r1=326870&r2=326871&view=diff
==
--- libcxxabi/trunk/src/cxa_demangle.cpp (original)
+++ libcxxabi/trunk/src/cxa_demangle.cpp Tue Mar  6 20:29:33 2018
@@ -4788,8 +4788,8 @@ Node *Db::parse() {
 Node *Encoding = parseEncoding();
 if (Encoding == nullptr || !consumeIf("_block_invoke"))
   return nullptr;
-consumeIf('_');
-if (parseNumber().empty())
+bool RequireNumber = consumeIf('_');
+if (parseNumber().empty() && RequireNumber)
   return nullptr;
 if (numLeft() != 0)
   return nullptr;

Modified: libcxxabi/trunk/test/test_demangle.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_demangle.pass.cpp?rev=326871&r1=326870&r2=326871&view=diff
==
--- libcxxabi/trunk/test/test_demangle.pass.cpp (original)
+++ libcxxabi/trunk/test/test_demangle.pass.cpp Tue Mar  6 20:29:33 2018
@@ -29716,6 +29716,8 @@ const char* cases[][2] =
 
 // ABI tags can apply to built-in substitutions.
 {"_Z1fSsB1XS_", "f(std::string[abi:X], std::string[abi:X])"},
+
+{"___Z10blocksNRVOv_block_invoke", "invocation function for block in 
blocksNRVO()"},
 };
 
 const unsigned N = sizeof(cases) / sizeof(cases[0]);


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


[PATCH] D43805: Optionally use nameless IR types

2018-03-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff marked an inline comment as done.
sepavloff added a comment.

In https://reviews.llvm.org/D43805#1029455, @pcc wrote:

> Why is this a driver flag? This seems like it ought to be a cc1-only flag to 
> me.


Yous are right, this is more like development option. But having the driver 
flag allows using compiler in builds with either option.
The option was hidden, probably it should be make hidden again.
If the backend will be changed so that it will not depend on IR type names, the 
default mode can be set to nameless types and the option can become -cc1 only.


Repository:
  rC Clang

https://reviews.llvm.org/D43805



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


[PATCH] D43805: Optionally use nameless IR types

2018-03-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Driver/Options.td:644
+  HelpText<"Whether to use IR type names (option: auto, none, use)">,
+  Values<"auto,none,use">;
+

Having "none" and "use" as values for the same option seems like a category 
error. always / never / auto would make some sense, though.


Repository:
  rC Clang

https://reviews.llvm.org/D43805



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


[PATCH] D43805: Optionally use nameless IR types

2018-03-06 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

Why is this a driver flag? This seems like it ought to be a cc1-only flag to me.


Repository:
  rC Clang

https://reviews.llvm.org/D43805



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


Re: [PATCH] D43805: Optionally use nameless IR types

2018-03-06 Thread Serge Pavlov via cfe-commits
Any feedback?

Thanks,
--Serge

2018-02-28 0:02 GMT+07:00 Serge Pavlov via Phabricator <
revi...@reviews.llvm.org>:

> sepavloff marked an inline comment as done.
> sepavloff added inline comments.
>
>
> 
> Comment at: include/clang/Driver/Options.td:1735
> +  HelpText<"Whether to use IR type names (option: none, use)">,
> +  Values<"none,use">;
>  def relocatable_pch : Flag<["-", "--"], "relocatable-pch">,
> Flags<[CC1Option]>,
> 
> rjmccall wrote:
> > This is an unusual spelling for the option in a number of ways:
> >   - We generally don't use `--` options; I think all the ones we have
> are strictly for legacy support.
> >   - A lot of similar options are in the `-f` or `-m` namespaces,
> although that's not as consistent and we could reasonably make this an
> exception.
> >   - `-foo=bar` options are generally used for options that are expected
> to take a variety of different values; this seems basically boolean.  Are
> you expecting future growth here?
> The option is in fact a three-state one, the third 'value' is absence of
> the option. In this case the option value is calculated from the type of
> action (produce ll file or not) and from the type of build (in debug builds
> types are named by default). To avoid misunderstanding I added new value,
> 'auto' for this purpose.
>
> The option was renamed to `-fir-type-names=` and it is not hidden anymore.
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D43805
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxxabi] r326797 - [demangler] Modernize the rest of the demangler.

2018-03-06 Thread Nico Weber via cfe-commits
Hi Erik,

before this change, ___Z10blocksNRVOv_block_invoke demangled to 'invocation
function for block in blocksNRVO()', now it's no longer demangled. Was that
an intentional change?

On Tue, Mar 6, 2018 at 9:21 AM, Erik Pilkington via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: epilk
> Date: Tue Mar  6 06:21:10 2018
> New Revision: 326797
>
> URL: http://llvm.org/viewvc/llvm-project?rev=326797&view=rev
> Log:
> [demangler] Modernize the rest of the demangler.
>
> Modified:
> libcxxabi/trunk/src/cxa_demangle.cpp
> libcxxabi/trunk/test/test_demangle.pass.cpp
>
> Modified: libcxxabi/trunk/src/cxa_demangle.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/
> cxa_demangle.cpp?rev=326797&r1=326796&r2=326797&view=diff
> 
> ==
> --- libcxxabi/trunk/src/cxa_demangle.cpp (original)
> +++ libcxxabi/trunk/src/cxa_demangle.cpp Tue Mar  6 06:21:10 2018
> @@ -2002,6 +2002,8 @@ struct Db {
>
>BumpPointerAllocator ASTAllocator;
>
> +  Db(const char *First_, const char *Last_) : First(First_), Last(Last_)
> {}
> +
>template  T *make(Args &&... args) {
>  return new (ASTAllocator.allocate(sizeof(T)))
>  T(std::forward(args)...);
> @@ -2054,6 +2056,12 @@ struct Db {
>bool parsePositiveInteger(size_t *Out);
>StringView parseBareSourceName();
>
> +  bool parseSeqId(size_t *Out);
> +  Node *parseSubstitution();
> +  Node *parseTemplateParam();
> +  Node *parseTemplateArgs();
> +  Node *parseTemplateArg();
> +
>/// Parse the  production.
>Node *parseExpr();
>Node *parsePrefixExpr(StringView Kind);
> @@ -2109,66 +2117,11 @@ struct Db {
>Node *parseUnresolvedType();
>Node *parseDestructorName();
>
> -  // FIXME: remove this when all the parse_* functions have been
> rewritten.
> -  template 
> -  Node *legacyParse() {
> -size_t BeforeType = Names.size();
> -const char *OrigFirst = First;
> -const char *T = parse_fn(First, Last, *this);
> -if (T == OrigFirst || BeforeType + 1 != Names.size())
> -  return nullptr;
> -First = T;
> -Node *R = Names.back();
> -Names.pop_back();
> -return R;
> -  }
> +  /// Top-level entry point into the parser.
> +  Node *parse();
>  };
>
> -const char *parse_expression(const char *first, const char *last, Db &db)
> {
> -  db.First = first;
> -  db.Last = last;
> -  Node *R = db.parseExpr();
> -  if (R == nullptr)
> -return first;
> -  db.Names.push_back(R);
> -  return db.First;
> -}
> -
> -const char *parse_expr_primary(const char *first, const char *last, Db
> &db) {
> -  db.First = first;
> -  db.Last = last;
> -  Node *R = db.parseExprPrimary();
> -  if (R == nullptr)
> -return first;
> -  db.Names.push_back(R);
> -  return db.First;
> -}
> -
> -const char *parse_type(const char *first, const char *last, Db &db) {
> -  db.First = first;
> -  db.Last = last;
> -  Node *R = db.parseType();
> -  if (R == nullptr)
> -return first;
> -  db.Names.push_back(R);
> -  return db.First;
> -}
> -
> -const char *parse_encoding(const char *first, const char *last, Db &db) {
> -  db.First = first;
> -  db.Last = last;
> -  Node *R = db.parseEncoding();
> -  if (R == nullptr)
> -return first;
> -  db.Names.push_back(R);
> -  return db.First;
> -}
> -
>  const char* parse_discriminator(const char* first, const char* last);
> -const char *parse_template_args(const char *first, const char *last, Db
> &db);
> -const char *parse_template_param(const char *, const char *, Db &);
> -const char *parse_substitution(const char *, const char *, Db &);
> -
>
>  //  ::=  // N
>  //::=  # See Scope Encoding below  // Z
> @@ -2187,10 +2140,12 @@ Node *Db::parseName(NameState *State) {
>
>//::=  
>if (look() == 'S' && look(1) != 't') {
> -Node *S = legacyParse();
> +Node *S = parseSubstitution();
> +if (S == nullptr)
> +  return nullptr;
>  if (look() != 'I')
>return nullptr;
> -Node *TA = legacyParse();
> +Node *TA = parseTemplateArgs();
>  if (TA == nullptr)
>return nullptr;
>  if (State) State->EndsWithTemplateArgs = true;
> @@ -2203,7 +2158,7 @@ Node *Db::parseName(NameState *State) {
>//::=  
>if (look() == 'I') {
>  Subs.push_back(N);
> -Node *TA = legacyParse();
> +Node *TA = parseTemplateArgs();
>  if (TA == nullptr)
>return nullptr;
>  if (State) State->EndsWithTemplateArgs = true;
> @@ -2693,7 +2648,7 @@ Node *Db::parseNestedName(NameState *Sta
>
>  //  ::= 
>  if (look() == 'T') {
> -  Node *TP = legacyParse();
> +  Node *TP = parseTemplateParam();
>if (TP == nullptr)
>  return nullptr;
>PushComponent(TP);
> @@ -2703,7 +2658,7 @@ Node *Db::parseNestedName(NameState *Sta
>
>  //  ::=  
>  if (look() == 'I') {
> -  Node *TA = legacyParse();
> +  Node *TA = parseTemplateArgs();
>if (TA == nullptr || SoFar == n

[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

2018-03-06 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 137320.
benhamilton added a comment.

Fix comment.


Repository:
  rC Clang

https://reviews.llvm.org/D43906

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


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -845,6 +845,15 @@
   verifyFormat("@ /*foo*/ interface");
 }
 
+TEST_F(FormatTestObjC, ObjCBlockTypesAndVariables) {
+  verifyFormat("void DoStuffWithBlockType(int (^)(char));");
+  verifyFormat("int (^foo)(char, float);");
+  verifyFormat("int (^foo[10])(char, float);");
+  verifyFormat("int (^foo[kNumEntries])(char, float);");
+  verifyFormat("int (^foo[kNumEntries + 10])(char, float);");
+  verifyFormat("int (^foo[(kNumEntries + 10)])(char, float);");
+}
+
 TEST_F(FormatTestObjC, ObjCSnippets) {
   verifyFormat("@autoreleasepool {\n"
"  foo();\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12128,6 +12128,22 @@
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithCaret) {
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^);"));
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^, Bar);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[10])(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[kNumEntries])(char, float);"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -142,8 +142,32 @@
 
 bool StartsObjCMethodExpr = false;
 if (CurrentToken->is(tok::caret)) {
-  // (^ can start a block type.
-  Left->Type = TT_ObjCBlockLParen;
+  // The following are valid ObjC block types and block variables:
+  //
+  // int (^)(char, float)
+  // int (^block)(char, float)
+  // int (^arrayOfTenBlocks[10])(char, float)
+  // int (^arrayOfManyBlocks[(kLen + 42)])(char, float)
+  const FormatToken *Next = CurrentToken->getNextNonComment();
+  int ParenDepth = 1;
+  // Handle nested parens in case we have an array of blocks with
+  // a parenthesized length.
+  while (Next) {
+if (Next->is(tok::l_paren))
+  ++ParenDepth;
+else if (Next->is(tok::r_paren))
+  --ParenDepth;
+if (ParenDepth == 0)
+  break;
+Next = Next->getNextNonComment();
+  }
+  if (Next) {
+const FormatToken *NextNext = Next->getNextNonComment();
+// If we have an opening paren at the end of (^...)( we assume
+// we have an Objective-C block.
+if (NextNext && NextNext->is(tok::l_paren))
+  Left->Type = TT_ObjCBlockLParen;
+  }
 } else if (FormatToken *MaybeSel = Left->Previous) {
   // @selector( starts a selector.
   if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Previous 
&&


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -845,6 +845,15 @@
   verifyFormat("@ /*foo*/ interface");
 }
 
+TEST_F(FormatTestObjC, ObjCBlockTypesAndVariables) {
+  verifyFormat("void DoStuffWithBlockType(int (^)(char));");
+  verifyFormat("int (^foo)(char, float);");
+  verifyFormat("int (^foo[10])(char, float);");
+  verifyFormat("int (^foo[kNumEntries])(char, float);");
+  verifyFormat("int (^foo[kNumEntries + 10])(char, float);");
+  verifyFormat("int (^foo[(kNumEntries + 10)])(char, float);");
+}
+
 TEST_F(FormatTestObjC, ObjCSnippets) {
   verifyFormat("@autoreleasepool {\n"
"  foo();\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12128,6 +12128,22 @@
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithCaret) {
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^);"));
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^, Bar);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "in

[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

2018-03-06 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

> Right. So the difference is that for blocks, there is always a "(" after the 
> "(^.)". That should be easy to parse, no?

Yep, I've updated this diff to implement that as you recommended. I just had to 
handle nested parens (I couldn't find an existing way to deal with these so I 
wrote my own—let me know if I missed something.)


Repository:
  rC Clang

https://reviews.llvm.org/D43906



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


[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

2018-03-06 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 137319.
benhamilton added a comment.

- Simplify logic and assume we have an ObjC block whenever we see rparen at the 
end of `(^...)(`.


Repository:
  rC Clang

https://reviews.llvm.org/D43906

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


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -845,6 +845,15 @@
   verifyFormat("@ /*foo*/ interface");
 }
 
+TEST_F(FormatTestObjC, ObjCBlockTypesAndVariables) {
+  verifyFormat("void DoStuffWithBlockType(int (^)(char));");
+  verifyFormat("int (^foo)(char, float);");
+  verifyFormat("int (^foo[10])(char, float);");
+  verifyFormat("int (^foo[kNumEntries])(char, float);");
+  verifyFormat("int (^foo[kNumEntries + 10])(char, float);");
+  verifyFormat("int (^foo[(kNumEntries + 10)])(char, float);");
+}
+
 TEST_F(FormatTestObjC, ObjCSnippets) {
   verifyFormat("@autoreleasepool {\n"
"  foo();\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12128,6 +12128,22 @@
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithCaret) {
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^);"));
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^, Bar);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo)(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[10])(char, float);"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "int(^foo[kNumEntries])(char, float);"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -142,8 +142,32 @@
 
 bool StartsObjCMethodExpr = false;
 if (CurrentToken->is(tok::caret)) {
-  // (^ can start a block type.
-  Left->Type = TT_ObjCBlockLParen;
+  // The following are valid block ObjC types and block variables:
+  //
+  // int (^)(char, float)
+  // int (^block)(char, float)
+  // int (^arrayOfTenBlocks[10])(char, float)
+  // int (^arrayOfManyBlocks[(kLen + 42)])(char, float)
+  const FormatToken *Next = CurrentToken->getNextNonComment();
+  int ParenDepth = 1;
+  // Handle nested parens in case we have an array of blocks with
+  // a parenthesized length.
+  while (Next) {
+if (Next->is(tok::l_paren))
+  ++ParenDepth;
+else if (Next->is(tok::r_paren))
+  --ParenDepth;
+if (ParenDepth == 0)
+  break;
+Next = Next->getNextNonComment();
+  }
+  if (Next) {
+const FormatToken *NextNext = Next->getNextNonComment();
+// If we have an opening paren at the end of (^...)( we assume
+// we have an Objective-C block.
+if (NextNext && NextNext->is(tok::l_paren))
+  Left->Type = TT_ObjCBlockLParen;
+  }
 } else if (FormatToken *MaybeSel = Left->Previous) {
   // @selector( starts a selector.
   if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Previous 
&&


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -845,6 +845,15 @@
   verifyFormat("@ /*foo*/ interface");
 }
 
+TEST_F(FormatTestObjC, ObjCBlockTypesAndVariables) {
+  verifyFormat("void DoStuffWithBlockType(int (^)(char));");
+  verifyFormat("int (^foo)(char, float);");
+  verifyFormat("int (^foo[10])(char, float);");
+  verifyFormat("int (^foo[kNumEntries])(char, float);");
+  verifyFormat("int (^foo[kNumEntries + 10])(char, float);");
+  verifyFormat("int (^foo[(kNumEntries + 10)])(char, float);");
+}
+
 TEST_F(FormatTestObjC, ObjCSnippets) {
   verifyFormat("@autoreleasepool {\n"
"  foo();\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12128,6 +12128,22 @@
   EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithCaret) {
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^);"));
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "FOO(^

Re: r326766 - [ExprConstant] Look through ExprWithCleanups for `allocsize`

2018-03-06 Thread Nico Weber via cfe-commits
Apologies, I had to revert the change that touched alloc-size.cpp before
this change in r326862. After that revert, your new test here failed, and
since I didn't understand how to make it passed, I reverted your change
in 326869 too. It should hopefully be easy for you to reland it.

On Tue, Mar 6, 2018 at 2:42 AM, George Burgess IV via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: gbiv
> Date: Mon Mar  5 23:42:36 2018
> New Revision: 326766
>
> URL: http://llvm.org/viewvc/llvm-project?rev=326766&view=rev
> Log:
> [ExprConstant] Look through ExprWithCleanups for `allocsize`
>
> Modified:
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/test/CodeGenCXX/alloc-size.cpp
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ExprConstant.cpp?rev=326766&r1=326765&r2=326766&view=diff
> 
> ==
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Mar  5 23:42:36 2018
> @@ -133,7 +133,11 @@ namespace {
>
>  E = E->IgnoreParens();
>  // If we're doing a variable assignment from e.g. malloc(N), there
> will
> -// probably be a cast of some kind. Ignore it.
> +// probably be a cast of some kind. In exotic cases, we might also
> see a
> +// top-level ExprWithCleanups. Ignore them either way.
> +if (const auto *EC = dyn_cast(E))
> +  E = EC->getSubExpr()->IgnoreParens();
> +
>  if (const auto *Cast = dyn_cast(E))
>E = Cast->getSubExpr()->IgnoreParens();
>
>
> Modified: cfe/trunk/test/CodeGenCXX/alloc-size.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGenCXX/alloc-size.cpp?rev=326766&r1=326765&r2=326766&view=diff
> 
> ==
> --- cfe/trunk/test/CodeGenCXX/alloc-size.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/alloc-size.cpp Mon Mar  5 23:42:36 2018
> @@ -88,3 +88,15 @@ int callMemberCalloc() {
>// CHECK: ret i32 32
>return __builtin_object_size(C().my_calloc(16, 2), 0);
>  }
> +
> +struct D {
> +  ~D();
> +  void *my_malloc(int N) __attribute__((alloc_size(2)));
> +};
> +
> +// CHECK-LABEL: define i32 @_Z20callExprWithCleanupsv
> +int callExprWithCleanups() {
> +  int *const p = (int *)D().my_malloc(3);
> +  // CHECK: ret i32 3
> +  return __builtin_object_size(p, 0);
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r326869 - Revert 326766 too, after r326862 the test fails and I don't know how to fix.

2018-03-06 Thread Nico Weber via cfe-commits
Author: nico
Date: Tue Mar  6 19:00:25 2018
New Revision: 326869

URL: http://llvm.org/viewvc/llvm-project?rev=326869&view=rev
Log:
Revert 326766 too, after r326862 the test fails and I don't know how to fix.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGenCXX/alloc-size.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=326869&r1=326868&r2=326869&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Mar  6 19:00:25 2018
@@ -133,11 +133,7 @@ namespace {
 
 E = E->IgnoreParens();
 // If we're doing a variable assignment from e.g. malloc(N), there will
-// probably be a cast of some kind. In exotic cases, we might also see a
-// top-level ExprWithCleanups. Ignore them either way.
-if (const auto *EC = dyn_cast(E))
-  E = EC->getSubExpr()->IgnoreParens();
-
+// probably be a cast of some kind. Ignore it.
 if (const auto *Cast = dyn_cast(E))
   E = Cast->getSubExpr()->IgnoreParens();
 

Modified: cfe/trunk/test/CodeGenCXX/alloc-size.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/alloc-size.cpp?rev=326869&r1=326868&r2=326869&view=diff
==
--- cfe/trunk/test/CodeGenCXX/alloc-size.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/alloc-size.cpp Tue Mar  6 19:00:25 2018
@@ -70,15 +70,3 @@ int testIt() {
  __builtin_object_size(dependent_calloc2(), 0);
 }
 } // namespace templated_alloc_size
-
-struct D {
-  ~D();
-  void *my_malloc(int N) __attribute__((alloc_size(2)));
-};
-
-// CHECK-LABEL: define i32 @_Z20callExprWithCleanupsv
-int callExprWithCleanups() {
-  int *const p = (int *)D().my_malloc(3);
-  // CHECK: ret i32 3
-  return __builtin_object_size(p, 0);
-}


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


[PATCH] D44170: [analyzer] Update GCDAsyncSemaphoreChecker to match messages send to ObjC objects

2018-03-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326868: [analyzer] Fix the checker for the performance 
anti-pattern to accept messages (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D44170

Files:
  lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
  test/Analysis/gcdasyncsemaphorechecker_test.m


Index: test/Analysis/gcdasyncsemaphorechecker_test.m
===
--- test/Analysis/gcdasyncsemaphorechecker_test.m
+++ test/Analysis/gcdasyncsemaphorechecker_test.m
@@ -177,7 +177,9 @@
 
 @interface Test1 : NSObject
 -(void)use_method_warn;
+-(void)use_objc_callback_warn;
 -(void)testNoWarn;
+-(void)acceptBlock:(block_t)callback;
 @end
 
 @implementation Test1
@@ -200,4 +202,33 @@
   dispatch_semaphore_wait(sema, 100);
 }
 
+-(void)acceptBlock:(block_t) callback {
+  callback();
+}
+
+-(void)use_objc_callback_warn {
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  [self acceptBlock:^{
+  dispatch_semaphore_signal(sema);
+  }];
+  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
+}
+
+void use_objc_and_c_callback(Test1 *t) {
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  func(^{
+  dispatch_semaphore_signal(sema);
+  });
+  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
+
+  dispatch_semaphore_t sema1 = dispatch_semaphore_create(0);
+
+  [t acceptBlock:^{
+  dispatch_semaphore_signal(sema1);
+  }];
+  dispatch_semaphore_wait(sema1, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
+}
+
 @end
Index: lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
@@ -111,23 +111,26 @@
   )
 ).bind(WarningBinding));
 
-  auto AcceptsBlockM =
-forEachDescendant(callExpr(hasAnyArgument(hasType(
+  auto HasBlockArgumentM = hasAnyArgument(hasType(
 hasCanonicalType(blockPointerType())
-;
+));
 
-  auto BlockSignallingM =
-forEachDescendant(callExpr(hasAnyArgument(hasDescendant(callExpr(
+  auto ArgCallsSignalM = hasArgument(0, hasDescendant(callExpr(
   allOf(
   callsName("dispatch_semaphore_signal"),
   equalsBoundArgDecl(0, SemaphoreBinding)
-  ));
+  ;
+
+  auto HasBlockAndCallsSignalM = allOf(HasBlockArgumentM, ArgCallsSignalM);
+
+  auto AcceptsBlockM =
+forEachDescendant(
+  stmt(anyOf(
+callExpr(HasBlockAndCallsSignalM),
+objcMessageExpr(HasBlockAndCallsSignalM)
+   )));
 
-  auto FinalM = compoundStmt(
-  SemaphoreBindingM,
-  SemaphoreWaitM,
-  AcceptsBlockM,
-  BlockSignallingM);
+  auto FinalM = compoundStmt(SemaphoreBindingM, SemaphoreWaitM, AcceptsBlockM);
 
   MatchFinder F;
   Callback CB(BR, AM.getAnalysisDeclContext(D), this);


Index: test/Analysis/gcdasyncsemaphorechecker_test.m
===
--- test/Analysis/gcdasyncsemaphorechecker_test.m
+++ test/Analysis/gcdasyncsemaphorechecker_test.m
@@ -177,7 +177,9 @@
 
 @interface Test1 : NSObject
 -(void)use_method_warn;
+-(void)use_objc_callback_warn;
 -(void)testNoWarn;
+-(void)acceptBlock:(block_t)callback;
 @end
 
 @implementation Test1
@@ -200,4 +202,33 @@
   dispatch_semaphore_wait(sema, 100);
 }
 
+-(void)acceptBlock:(block_t) callback {
+  callback();
+}
+
+-(void)use_objc_callback_warn {
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  [self acceptBlock:^{
+  dispatch_semaphore_signal(sema);
+  }];
+  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore performance anti-pattern}}
+}
+
+void use_objc_and_c_callback(Test1 *t) {
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  func(^{
+  dispatch_semaphore_signal(sema);
+  });
+  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore performance anti-pattern}}
+
+  dispatch_semaphore_t sema1 = dispatch_semaphore_create(0);
+
+  [t acceptBlock:^{
+  dispatch_semaphore_signal(sema1);
+  }];
+  dispatch_semaphore_wait(sema1, 100); // expected-warning{{Possible semaphore performance anti-pattern}}
+}
+
 @end
Index: lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
@@ -111,23 +111,26 @@
   )
 ).bind(WarningBinding));
 
-  auto AcceptsBlockM =
-forEachDescendant(callExpr(hasAnyArgument(hasType(
+  auto HasBlockArgumentM = hasAnyArgument(hasT

r326868 - [analyzer] Fix the checker for the performance anti-pattern to accept messages

2018-03-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Tue Mar  6 18:54:01 2018
New Revision: 326868

URL: http://llvm.org/viewvc/llvm-project?rev=326868&view=rev
Log:
[analyzer] Fix the checker for the performance anti-pattern to accept messages

send to ObjC objects.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp?rev=326868&r1=326867&r2=326868&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp Tue Mar  
6 18:54:01 2018
@@ -111,23 +111,26 @@ void GCDAsyncSemaphoreChecker::checkASTC
   )
 ).bind(WarningBinding));
 
-  auto AcceptsBlockM =
-forEachDescendant(callExpr(hasAnyArgument(hasType(
+  auto HasBlockArgumentM = hasAnyArgument(hasType(
 hasCanonicalType(blockPointerType())
-;
+));
 
-  auto BlockSignallingM =
-forEachDescendant(callExpr(hasAnyArgument(hasDescendant(callExpr(
+  auto ArgCallsSignalM = hasArgument(0, hasDescendant(callExpr(
   allOf(
   callsName("dispatch_semaphore_signal"),
   equalsBoundArgDecl(0, SemaphoreBinding)
-  ));
+  ;
+
+  auto HasBlockAndCallsSignalM = allOf(HasBlockArgumentM, ArgCallsSignalM);
+
+  auto AcceptsBlockM =
+forEachDescendant(
+  stmt(anyOf(
+callExpr(HasBlockAndCallsSignalM),
+objcMessageExpr(HasBlockAndCallsSignalM)
+   )));
 
-  auto FinalM = compoundStmt(
-  SemaphoreBindingM,
-  SemaphoreWaitM,
-  AcceptsBlockM,
-  BlockSignallingM);
+  auto FinalM = compoundStmt(SemaphoreBindingM, SemaphoreWaitM, AcceptsBlockM);
 
   MatchFinder F;
   Callback CB(BR, AM.getAnalysisDeclContext(D), this);

Modified: cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m?rev=326868&r1=326867&r2=326868&view=diff
==
--- cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m (original)
+++ cfe/trunk/test/Analysis/gcdasyncsemaphorechecker_test.m Tue Mar  6 18:54:01 
2018
@@ -177,7 +177,9 @@ void warn_with_cast() {
 
 @interface Test1 : NSObject
 -(void)use_method_warn;
+-(void)use_objc_callback_warn;
 -(void)testNoWarn;
+-(void)acceptBlock:(block_t)callback;
 @end
 
 @implementation Test1
@@ -200,4 +202,33 @@ void warn_with_cast() {
   dispatch_semaphore_wait(sema, 100);
 }
 
+-(void)acceptBlock:(block_t) callback {
+  callback();
+}
+
+-(void)use_objc_callback_warn {
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  [self acceptBlock:^{
+  dispatch_semaphore_signal(sema);
+  }];
+  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
+}
+
+void use_objc_and_c_callback(Test1 *t) {
+  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+  func(^{
+  dispatch_semaphore_signal(sema);
+  });
+  dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
+
+  dispatch_semaphore_t sema1 = dispatch_semaphore_create(0);
+
+  [t acceptBlock:^{
+  dispatch_semaphore_signal(sema1);
+  }];
+  dispatch_semaphore_wait(sema1, 100); // expected-warning{{Possible semaphore 
performance anti-pattern}}
+}
+
 @end


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


[PATCH] D44065: [Driver] Enable SafeStack by default on Fuchsia

2018-03-06 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326867: [Driver] Enable SafeStack by default on Fuchsia 
(authored by phosek, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44065?vs=137312&id=137314#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44065

Files:
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Fuchsia.h
  test/Driver/fuchsia.c


Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -284,3 +284,7 @@
   Res |= SanitizerKind::Scudo;
   return Res;
 }
+
+SanitizerMask Fuchsia::getDefaultSanitizers() const {
+  return SanitizerKind::SafeStack;
+}
Index: lib/Driver/ToolChains/Fuchsia.h
===
--- lib/Driver/ToolChains/Fuchsia.h
+++ lib/Driver/ToolChains/Fuchsia.h
@@ -60,10 +60,15 @@
 return llvm::DebuggerKind::GDB;
   }
 
+  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
+return 2; // SSPStrong
+  }
+
   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
   types::ID InputType) const override;
 
   SanitizerMask getSupportedSanitizers() const override;
+  SanitizerMask getDefaultSanitizers() const override;
 
   RuntimeLibType
   GetRuntimeLibType(const llvm::opt::ArgList &Args) const override;
Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -10,6 +10,8 @@
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
+// CHECK: "-fsanitize=safe-stack"
+// CHECK: "-stack-protector" "2"
 // CHECK: "-fno-common"
 // CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
@@ -84,31 +86,31 @@
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=fuzzer 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-X86
-// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link,safe-stack"
 // CHECK-FUZZER-X86: "{{.*[/\\]}}libclang_rt.fuzzer-x86_64.a"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=fuzzer 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-AARCH64
-// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link,safe-stack"
 // CHECK-FUZZER-AARCH64: "{{.*[/\\]}}libclang_rt.fuzzer-aarch64.a"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-X86
-// CHECK-SCUDO-X86: "-fsanitize=scudo"
+// CHECK-SCUDO-X86: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-X86: "-pie"
 // CHECK-SCUDO-X86: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-AARCH64
-// CHECK-SCUDO-AARCH64: "-fsanitize=scudo"
+// CHECK-SCUDO-AARCH64: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-AARCH64: "-pie"
 // CHECK-SCUDO-AARCH64: "{{.*[/\\]}}libclang_rt.scudo-aarch64.so"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo -fPIC -shared 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-SHARED
-// CHECK-SCUDO-SHARED: "-fsanitize=scudo"
+// CHECK-SCUDO-SHARED: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-SHARED: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"


Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -284,3 +284,7 @@
   Res |= SanitizerKind::Scudo;
   return Res;
 }
+
+SanitizerMask Fuchsia::getDefaultSanitizers() const {
+  return SanitizerKind::SafeStack;
+}
Index: lib/Driver/ToolChains/Fuchsia.h
===
--- lib/Driver/ToolChains/Fuchsia.h
+++ lib/Driver/ToolChains/Fuchsia.h
@@ -60,10 +60,15 @@
 return llvm::DebuggerKind::GDB;
   }
 
+  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
+return 2; // SSPStrong
+  }
+
   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
   types::ID InputType) const override;
 
   SanitizerMask getSupportedSanitizers() const override;
+  SanitizerMask getDefaultSanitizers() const override;
 
   RuntimeLibType
   GetRuntimeLibType(const llvm::opt::ArgList &Args) const override;
Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -10,6 +10,8 @@
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT

r326867 - [Driver] Enable SafeStack by default on Fuchsia

2018-03-06 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Mar  6 18:49:58 2018
New Revision: 326867

URL: http://llvm.org/viewvc/llvm-project?rev=326867&view=rev
Log:
[Driver] Enable SafeStack by default on Fuchsia

This is already used throughout the entire system, so make it a default.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
cfe/trunk/test/Driver/fuchsia.c

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp?rev=326867&r1=326866&r2=326867&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Tue Mar  6 18:49:58 2018
@@ -284,3 +284,7 @@ SanitizerMask Fuchsia::getSupportedSanit
   Res |= SanitizerKind::Scudo;
   return Res;
 }
+
+SanitizerMask Fuchsia::getDefaultSanitizers() const {
+  return SanitizerKind::SafeStack;
+}

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.h?rev=326867&r1=326866&r2=326867&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h Tue Mar  6 18:49:58 2018
@@ -60,10 +60,15 @@ public:
 return llvm::DebuggerKind::GDB;
   }
 
+  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
+return 2; // SSPStrong
+  }
+
   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
   types::ID InputType) const override;
 
   SanitizerMask getSupportedSanitizers() const override;
+  SanitizerMask getDefaultSanitizers() const override;
 
   RuntimeLibType
   GetRuntimeLibType(const llvm::opt::ArgList &Args) const override;

Modified: cfe/trunk/test/Driver/fuchsia.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuchsia.c?rev=326867&r1=326866&r2=326867&view=diff
==
--- cfe/trunk/test/Driver/fuchsia.c (original)
+++ cfe/trunk/test/Driver/fuchsia.c Tue Mar  6 18:49:58 2018
@@ -10,6 +10,8 @@
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
+// CHECK: "-fsanitize=safe-stack"
+// CHECK: "-stack-protector" "2"
 // CHECK: "-fno-common"
 // CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
@@ -84,31 +86,31 @@
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=fuzzer 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-X86
-// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link,safe-stack"
 // CHECK-FUZZER-X86: "{{.*[/\\]}}libclang_rt.fuzzer-x86_64.a"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=fuzzer 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-AARCH64
-// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link,safe-stack"
 // CHECK-FUZZER-AARCH64: "{{.*[/\\]}}libclang_rt.fuzzer-aarch64.a"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-X86
-// CHECK-SCUDO-X86: "-fsanitize=scudo"
+// CHECK-SCUDO-X86: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-X86: "-pie"
 // CHECK-SCUDO-X86: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-AARCH64
-// CHECK-SCUDO-AARCH64: "-fsanitize=scudo"
+// CHECK-SCUDO-AARCH64: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-AARCH64: "-pie"
 // CHECK-SCUDO-AARCH64: "{{.*[/\\]}}libclang_rt.scudo-aarch64.so"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo -fPIC -shared 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-SHARED
-// CHECK-SCUDO-SHARED: "-fsanitize=scudo"
+// CHECK-SCUDO-SHARED: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-SHARED: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"


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


[PATCH] D44065: [Driver] Enable SafeStack by default on Fuchsia

2018-03-06 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 137312.

Repository:
  rC Clang

https://reviews.llvm.org/D44065

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Fuchsia.h
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -10,6 +10,8 @@
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
+// CHECK: "-fsanitize=safe-stack"
+// CHECK: "-stack-protector" "2"
 // CHECK: "-fno-common"
 // CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
@@ -84,31 +86,31 @@
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=fuzzer 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-X86
-// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link,safe-stack"
 // CHECK-FUZZER-X86: "{{.*[/\\]}}libclang_rt.fuzzer-x86_64.a"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=fuzzer 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-AARCH64
-// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link,safe-stack"
 // CHECK-FUZZER-AARCH64: "{{.*[/\\]}}libclang_rt.fuzzer-aarch64.a"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-X86
-// CHECK-SCUDO-X86: "-fsanitize=scudo"
+// CHECK-SCUDO-X86: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-X86: "-pie"
 // CHECK-SCUDO-X86: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-AARCH64
-// CHECK-SCUDO-AARCH64: "-fsanitize=scudo"
+// CHECK-SCUDO-AARCH64: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-AARCH64: "-pie"
 // CHECK-SCUDO-AARCH64: "{{.*[/\\]}}libclang_rt.scudo-aarch64.so"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo -fPIC -shared 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-SHARED
-// CHECK-SCUDO-SHARED: "-fsanitize=scudo"
+// CHECK-SCUDO-SHARED: "-fsanitize=safe-stack,scudo"
 // CHECK-SCUDO-SHARED: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
Index: clang/lib/Driver/ToolChains/Fuchsia.h
===
--- clang/lib/Driver/ToolChains/Fuchsia.h
+++ clang/lib/Driver/ToolChains/Fuchsia.h
@@ -60,10 +60,15 @@
 return llvm::DebuggerKind::GDB;
   }
 
+  unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
+return 2; // SSPStrong
+  }
+
   std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
   types::ID InputType) const override;
 
   SanitizerMask getSupportedSanitizers() const override;
+  SanitizerMask getDefaultSanitizers() const override;
 
   RuntimeLibType
   GetRuntimeLibType(const llvm::opt::ArgList &Args) const override;
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -284,3 +284,7 @@
   Res |= SanitizerKind::Scudo;
   return Res;
 }
+
+SanitizerMask Fuchsia::getDefaultSanitizers() const {
+  return SanitizerKind::SafeStack;
+}


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -10,6 +10,8 @@
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
+// CHECK: "-fsanitize=safe-stack"
+// CHECK: "-stack-protector" "2"
 // CHECK: "-fno-common"
 // CHECK: {{.*}}ld.lld{{.*}}" "-z" "rodynamic"
 // CHECK: "--sysroot=[[SYSROOT]]"
@@ -84,31 +86,31 @@
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=fuzzer 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-X86
-// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link,safe-stack"
 // CHECK-FUZZER-X86: "{{.*[/\\]}}libclang_rt.fuzzer-x86_64.a"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=fuzzer 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-AARCH64
-// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link,safe-stack"
 // CHECK-FUZZER-AARCH64: "{{.*[/\\]}}libclang_rt.fuzzer-aarch64.a"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-X86
-// CHECK-SCUDO-X86: "-fsanitize=scudo"
+// CHECK-SCUDO-X86: "-fsanitize=safe-stack,scudo

[PATCH] D44169: [ASTMatcher] Extend hasAnyArgument to ObjCMessageExpr

2018-03-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326865: [ASTMatcher] Extend hasAnyArgument to 
ObjCMessageExpr (authored by george.karpenkov, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44169?vs=137295&id=137307#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44169

Files:
  cfe/trunk/docs/LibASTMatchersReference.html
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
  cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: cfe/trunk/docs/LibASTMatchersReference.html
===
--- cfe/trunk/docs/LibASTMatchersReference.html
+++ cfe/trunk/docs/LibASTMatchersReference.html
@@ -4342,14 +4342,20 @@
 
 MatcherCXXConstructExpr>hasAnyArgumentMatcherExpr> InnerMatcher
 Matches any argument of a call expression or a constructor call
-expression.
+expression, or an ObjC-message-send expression.
 
 Given
   void x(int, int, int) { int y; x(1, y, 42); }
 callExpr(hasAnyArgument(declRefExpr()))
   matches x(1, y, 42)
 with hasAnyArgument(...)
   matching y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+  void foo(I *i) { [i f:12] }
+objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+  matches [i f:12]
 
 
 
@@ -4689,14 +4695,20 @@
 
 MatcherCallExpr>hasAnyArgumentMatcherExpr> InnerMatcher
 Matches any argument of a call expression or a constructor call
-expression.
+expression, or an ObjC-message-send expression.
 
 Given
   void x(int, int, int) { int y; x(1, y, 42); }
 callExpr(hasAnyArgument(declRefExpr()))
   matches x(1, y, 42)
 with hasAnyArgument(...)
   matching y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+  void foo(I *i) { [i f:12] }
+objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+  matches [i f:12]
 
 
 
@@ -5634,6 +5646,25 @@
 
 
 
+MatcherObjCMessageExpr>hasAnyArgumentMatcherExpr> InnerMatcher
+Matches any argument of a call expression or a constructor call
+expression, or an ObjC-message-send expression.
+
+Given
+  void x(int, int, int) { int y; x(1, y, 42); }
+callExpr(hasAnyArgument(declRefExpr()))
+  matches x(1, y, 42)
+with hasAnyArgument(...)
+  matching y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+  void foo(I *i) { [i f:12] }
+objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+  matches [i f:12]
+
+
+
 MatcherObjCMessageExpr>hasArgumentunsigned N, MatcherExpr> InnerMatcher
 Matches the n'th argument of a call expression or a constructor
 call expression.
Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
===
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
@@ -3412,7 +3412,7 @@
 }
 
 /// \brief Matches any argument of a call expression or a constructor call
-/// expression.
+/// expression, or an ObjC-message-send expression.
 ///
 /// Given
 /// \code
@@ -3422,9 +3422,18 @@
 ///   matches x(1, y, 42)
 /// with hasAnyArgument(...)
 ///   matching y
+///
+/// For ObjectiveC, given
+/// \code
+///   @interface I - (void) f:(int) y; @end
+///   void foo(I *i) { [i f:12]; }
+/// \endcode
+/// objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+///   matches [i f:12]
 AST_POLYMORPHIC_MATCHER_P(hasAnyArgument,
   AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
-  CXXConstructExpr),
+  CXXConstructExpr,
+  ObjCMessageExpr),
   internal::Matcher, InnerMatcher) {
   for (const Expr *Arg : Node.arguments()) {
 BoundNodesTreeBuilder Result(*Builder);
Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -403,11 +403,18 @@
 }
 
 TEST(Matcher, AnyArgument) {
-  StatementMatcher CallArgumentY = callExpr(
-hasAnyArgument(
-  ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("y")));
+  auto HasArgumentY = hasAnyArgument(
+  ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("y"));
+  StatementMatcher CallArgumentY = callExpr(HasArgumentY);
+  StatementMatcher 

[PATCH] D44169: [ASTMatcher] Extend hasAnyArgument to ObjCMessageExpr

2018-03-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326865: [ASTMatcher] Extend hasAnyArgument to 
ObjCMessageExpr (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44169?vs=137295&id=137306#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44169

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -403,11 +403,18 @@
 }
 
 TEST(Matcher, AnyArgument) {
-  StatementMatcher CallArgumentY = callExpr(
-hasAnyArgument(
-  ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("y")));
+  auto HasArgumentY = hasAnyArgument(
+  ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("y"));
+  StatementMatcher CallArgumentY = callExpr(HasArgumentY);
+  StatementMatcher ObjCCallArgumentY = objcMessageExpr(HasArgumentY);
   EXPECT_TRUE(matches("void x(int, int) { int y; x(1, y); }", CallArgumentY));
   EXPECT_TRUE(matches("void x(int, int) { int y; x(y, 42); }", CallArgumentY));
+  EXPECT_TRUE(matchesObjC("@interface I -(void)f:(int) y; @end "
+  "void x(I* i) { int y; [i f:y]; }",
+  ObjCCallArgumentY));
+  EXPECT_FALSE(matchesObjC("@interface I -(void)f:(int) z; @end "
+   "void x(I* i) { int z; [i f:z]; }",
+   ObjCCallArgumentY));
   EXPECT_TRUE(notMatches("void x(int, int) { x(1, 2); }", CallArgumentY));
 
   StatementMatcher ImplicitCastedArgument = callExpr(
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -4342,14 +4342,20 @@
 
 MatcherCXXConstructExpr>hasAnyArgumentMatcherExpr> InnerMatcher
 Matches any argument of a call expression or a constructor call
-expression.
+expression, or an ObjC-message-send expression.
 
 Given
   void x(int, int, int) { int y; x(1, y, 42); }
 callExpr(hasAnyArgument(declRefExpr()))
   matches x(1, y, 42)
 with hasAnyArgument(...)
   matching y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+  void foo(I *i) { [i f:12] }
+objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+  matches [i f:12]
 
 
 
@@ -4689,14 +4695,20 @@
 
 MatcherCallExpr>hasAnyArgumentMatcherExpr> InnerMatcher
 Matches any argument of a call expression or a constructor call
-expression.
+expression, or an ObjC-message-send expression.
 
 Given
   void x(int, int, int) { int y; x(1, y, 42); }
 callExpr(hasAnyArgument(declRefExpr()))
   matches x(1, y, 42)
 with hasAnyArgument(...)
   matching y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+  void foo(I *i) { [i f:12] }
+objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+  matches [i f:12]
 
 
 
@@ -5634,6 +5646,25 @@
 
 
 
+MatcherObjCMessageExpr>hasAnyArgumentMatcherExpr> InnerMatcher
+Matches any argument of a call expression or a constructor call
+expression, or an ObjC-message-send expression.
+
+Given
+  void x(int, int, int) { int y; x(1, y, 42); }
+callExpr(hasAnyArgument(declRefExpr()))
+  matches x(1, y, 42)
+with hasAnyArgument(...)
+  matching y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+  void foo(I *i) { [i f:12] }
+objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+  matches [i f:12]
+
+
+
 MatcherObjCMessageExpr>hasArgumentunsigned N, MatcherExpr> InnerMatcher
 Matches the n'th argument of a call expression or a constructor
 call expression.
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3412,7 +3412,7 @@
 }
 
 /// \brief Matches any argument of a call expression or a constructor call
-/// expression.
+/// expression, or an ObjC-message-send expression.
 ///
 /// Given
 /// \code
@@ -3422,9 +3422,18 @@
 ///   matches x(1, y, 42)
 /// with hasAnyArgument(...)
 ///   matching y
+///
+/// For ObjectiveC, given
+/// \code
+///   @interface I - (void) f:(int) y; @end
+///   void foo(I *i) { [i f:12]; }
+/// \endcode
+///

r326865 - [ASTMatcher] Extend hasAnyArgument to ObjCMessageExpr

2018-03-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Tue Mar  6 18:32:44 2018
New Revision: 326865

URL: http://llvm.org/viewvc/llvm-project?rev=326865&view=rev
Log:
[ASTMatcher] Extend hasAnyArgument to ObjCMessageExpr

Currently hasArgument works with both ObjC messages and function calls,
but not hasAnyArgument.
This patch fixes that discrepancy, as it's often more convenient to use
hasAnyArgument.

On a more general note, it would be great to have a common superclass
for objc-call and function call, and a matcher matching that, but that's
probably a job for another commit.

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=326865&r1=326864&r2=326865&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Tue Mar  6 18:32:44 2018
@@ -4342,7 +4342,7 @@ and parmVarDecl(...)
 
 MatcherCXXConstructExpr>hasAnyArgumentMatcherExpr> 
InnerMatcher
 Matches any argument 
of a call expression or a constructor call
-expression.
+expression, or an ObjC-message-send expression.
 
 Given
   void x(int, int, int) { int y; x(1, y, 42); }
@@ -4350,6 +4350,12 @@ callExpr(hasAnyArgument(declRefExpr()))
   matches x(1, y, 42)
 with hasAnyArgument(...)
   matching y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+  void foo(I *i) { [i f:12] }
+objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+  matches [i f:12]
 
 
 
@@ -4689,7 +4695,7 @@ and parmVarDecl(...)
 
 MatcherCallExpr>hasAnyArgumentMatcherExpr> 
InnerMatcher
 Matches any argument 
of a call expression or a constructor call
-expression.
+expression, or an ObjC-message-send expression.
 
 Given
   void x(int, int, int) { int y; x(1, y, 42); }
@@ -4697,6 +4703,12 @@ callExpr(hasAnyArgument(declRefExpr()))
   matches x(1, y, 42)
 with hasAnyArgument(...)
   matching y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+  void foo(I *i) { [i f:12] }
+objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+  matches [i f:12]
 
 
 
@@ -5634,6 +5646,25 @@ nestedNameSpecifier(specifiesType(
 
 
 
+MatcherObjCMessageExpr>hasAnyArgumentMatcherExpr> 
InnerMatcher
+Matches any argument 
of a call expression or a constructor call
+expression, or an ObjC-message-send expression.
+
+Given
+  void x(int, int, int) { int y; x(1, y, 42); }
+callExpr(hasAnyArgument(declRefExpr()))
+  matches x(1, y, 42)
+with hasAnyArgument(...)
+  matching y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+  void foo(I *i) { [i f:12] }
+objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+  matches [i f:12]
+
+
+
 MatcherObjCMessageExpr>hasArgumentunsigned N, MatcherExpr> 
InnerMatcher
 Matches the n'th 
argument of a call expression or a constructor
 call expression.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=326865&r1=326864&r2=326865&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Mar  6 18:32:44 2018
@@ -3412,7 +3412,7 @@ AST_MATCHER(CXXCtorInitializer, isMember
 }
 
 /// \brief Matches any argument of a call expression or a constructor call
-/// expression.
+/// expression, or an ObjC-message-send expression.
 ///
 /// Given
 /// \code
@@ -3422,9 +3422,18 @@ AST_MATCHER(CXXCtorInitializer, isMember
 ///   matches x(1, y, 42)
 /// with hasAnyArgument(...)
 ///   matching y
+///
+/// For ObjectiveC, given
+/// \code
+///   @interface I - (void) f:(int) y; @end
+///   void foo(I *i) { [i f:12]; }
+/// \endcode
+/// objcMessageExpr(hasAnyArgument(integerLiteral(equals(12
+///   matches [i f:12]
 AST_POLYMORPHIC_MATCHER_P(hasAnyArgument,
   AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
-  CXXConstructExpr),
+  CXXConstructExpr,
+  ObjCMessageE

Re: r326860 - [Driver] Automatically disable incompatible default sanitizers

2018-03-06 Thread Nico Weber via cfe-commits
Test? (Also below)

On Tue, Mar 6, 2018 at 8:27 PM, Petr Hosek via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: phosek
> Date: Tue Mar  6 17:27:03 2018
> New Revision: 326860
>
> URL: http://llvm.org/viewvc/llvm-project?rev=326860&view=rev
> Log:
> [Driver] Automatically disable incompatible default sanitizers
>
> When a sanitizer incompatible with one of the default sanitizers
> is explicitly enabled, automatically disable all the conflicting
> default sanitizers.
>
> Differential Revision: https://reviews.llvm.org/D44064
>
> Modified:
> cfe/trunk/lib/Driver/SanitizerArgs.cpp
>
> Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/
> SanitizerArgs.cpp?rev=326860&r1=326859&r2=326860&view=diff
> 
> ==
> --- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
> +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Mar  6 17:27:03 2018
> @@ -332,8 +332,30 @@ SanitizerArgs::SanitizerArgs(const ToolC
>  }
>}
>
> +  std::pair IncompatibleGroups[] = {
> +  std::make_pair(Address, Thread | Memory),
> +  std::make_pair(Thread, Memory),
> +  std::make_pair(Leak, Thread | Memory),
> +  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
> +  std::make_pair(HWAddress, Address | Thread | Memory |
> KernelAddress),
> +  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread |
> Memory |
> + KernelAddress),
> +  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
> +KernelAddress | Efficiency),
> +  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread |
> Memory |
> +KernelAddress | Efficiency)};
> +
>// Enable toolchain specific default sanitizers if not explicitly
> disabled.
> -  Kinds |= TC.getDefaultSanitizers() & ~AllRemove;
> +  SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
> +
> +  // Disable default sanitizers that are incompatible with the default
> ones.
>

You probably mean "Disable default sanitizers that are incompatible with
explicitly requested ones"?


> +  for (auto G : IncompatibleGroups) {
> +SanitizerMask Group = G.first;
> +if ((Default & Group) && (Kinds & G.second))
> +  Default &= ~Group;
> +  }
> +
> +  Kinds |= Default;
>
>// We disable the vptr sanitizer if it was enabled by group expansion
> but RTTI
>// is disabled.
> @@ -369,18 +391,6 @@ SanitizerArgs::SanitizerArgs(const ToolC
>}
>
>// Warn about incompatible groups of sanitizers.
> -  std::pair IncompatibleGroups[] = {
> -  std::make_pair(Address, Thread | Memory),
> -  std::make_pair(Thread, Memory),
> -  std::make_pair(Leak, Thread | Memory),
> -  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
> -  std::make_pair(HWAddress, Address | Thread | Memory |
> KernelAddress),
> -  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread |
> Memory |
> - KernelAddress),
> -  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
> -KernelAddress | Efficiency),
> -  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread |
> Memory |
> -KernelAddress | Efficiency)};
>for (auto G : IncompatibleGroups) {
>  SanitizerMask Group = G.first;
>  if (Kinds & Group) {
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r326862 - Revert r326602, it caused PR36620.

2018-03-06 Thread Nico Weber via cfe-commits
Author: nico
Date: Tue Mar  6 18:22:41 2018
New Revision: 326862

URL: http://llvm.org/viewvc/llvm-project?rev=326862&view=rev
Log:
Revert r326602, it caused PR36620.

Removed:
cfe/trunk/test/Sema/attr-ownership.cpp
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
cfe/trunk/test/CodeGenCXX/alloc-size.cpp
cfe/trunk/test/Misc/ast-dump-attr.cpp
cfe/trunk/test/Sema/attr-print.cpp
cfe/trunk/test/Sema/error-type-safety.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=326862&r1=326861&r2=326862&view=diff
==
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Tue Mar  6 18:22:41 2018
@@ -195,120 +195,6 @@ public:
}
 };
 
-/// A single parameter index whose accessors require each use to make explicit
-/// the parameter index encoding needed.
-class ParamIdx {
-  // Idx is exposed only via accessors that specify specific encodings.
-  unsigned Idx : 30;
-  unsigned HasThis : 1;
-  unsigned IsValid : 1;
-
-  void assertComparable(const ParamIdx &I) const {
-assert(isValid() && I.isValid() &&
-   "ParamIdx must be valid to be compared");
-// It's possible to compare indices from separate functions, but so far
-// it's not proven useful.  Moreover, it might be confusing because a
-// comparison on the results of getASTIndex might be inconsistent with a
-// comparison on the ParamIdx objects themselves.
-assert(HasThis == I.HasThis &&
-   "ParamIdx must be for the same function to be compared");
-  }
-
-public:
-  /// Construct an invalid parameter index (\c isValid returns false and
-  /// accessors fail an assert).
-  ParamIdx() : Idx(0), HasThis(false), IsValid(false) {}
-
-  /// \param Idx is the parameter index as it is normally specified in
-  /// attributes in the source: one-origin including any C++ implicit this
-  /// parameter.
-  ///
-  /// \param D is the declaration containing the parameters.  It is used to
-  /// determine if there is a C++ implicit this parameter.
-  ParamIdx(unsigned Idx, const Decl *D)
-  : Idx(Idx), HasThis(false), IsValid(true) {
-if (const auto *FD = dyn_cast(D))
-  HasThis = FD->isCXXInstanceMember();
-  }
-
-  /// \param Idx is the parameter index as it is normally specified in
-  /// attributes in the source: one-origin including any C++ implicit this
-  /// parameter.
-  ///
-  /// \param HasThis specifies whether the function has a C++ implicit this
-  /// parameter.
-  ParamIdx(unsigned Idx, bool HasThis)
-  : Idx(Idx), HasThis(HasThis), IsValid(true) {}
-
-  /// Is this parameter index valid?
-  bool isValid() const { return IsValid; }
-
-  /// Is there a C++ implicit this parameter?
-  bool hasThis() const {
-assert(isValid() && "ParamIdx must be valid");
-return HasThis;
-  }
-
-  /// Get the parameter index as it would normally be encoded for attributes at
-  /// the source level of representation: one-origin including any C++ implicit
-  /// this parameter.
-  ///
-  /// This encoding thus makes sense for diagnostics, pretty printing, and
-  /// constructing new attributes from a source-like specification.
-  unsigned getSourceIndex() const {
-assert(isValid() && "ParamIdx must be valid");
-return Idx;
-  }
-
-  /// Get the parameter index as it would normally be encoded at the AST level
-  /// of representation: zero-origin not including any C++ implicit this
-  /// parameter.
-  ///
-  /// This is the encoding primarily used in Sema.  However, in diagnostics,
-  /// Sema uses \c getSourceIndex instead.
-  unsigned getASTIndex() const {
-assert(isValid() && "ParamIdx must be valid");
-assert(Idx >= 1 + HasThis &&
-   "stored index must be base-1 and not specify C++ implicit this");
-return Idx - 1 - HasThis;
-  }
-
-  /// Get the parameter index as it would normally be encoded at the LLVM level
-  /// of representation: zero-origin including any C++ implicit this parameter.
-  ///
-  /// This is the encoding primarily used in CodeGen.
-  unsigned getLLVMIndex() const {
-assert(isValid() && "ParamIdx must be valid");
-assert(Idx >= 1 && "stored index must be base-1");
-return Idx - 1;
-  }
-
-  bool operator==(const ParamIdx &I) const {
-assertComparable(I);
-return Idx == I.Idx;
-  }
-  bool operator!=(const ParamIdx &I) const {
-assertComparable(I);
-return Idx != I.Idx;
-  }
-  bo

[PATCH] D44064: [Driver] Automatically disable incompatible default sanitizers

2018-03-06 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326860: [Driver] Automatically disable incompatible default 
sanitizers (authored by phosek, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44064?vs=136893&id=137302#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44064

Files:
  cfe/trunk/lib/Driver/SanitizerArgs.cpp


Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair IncompatibleGroups[] = {
+  std::make_pair(Address, Thread | Memory),
+  std::make_pair(Thread, Memory),
+  std::make_pair(Leak, Thread | Memory),
+  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
+  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
+  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
+ KernelAddress),
+  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};
+
   // Enable toolchain specific default sanitizers if not explicitly disabled.
-  Kinds |= TC.getDefaultSanitizers() & ~AllRemove;
+  SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
+
+  // Disable default sanitizers that are incompatible with the default ones.
+  for (auto G : IncompatibleGroups) {
+SanitizerMask Group = G.first;
+if ((Default & Group) && (Kinds & G.second))
+  Default &= ~Group;
+  }
+
+  Kinds |= Default;
 
   // We disable the vptr sanitizer if it was enabled by group expansion but 
RTTI
   // is disabled.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair IncompatibleGroups[] = {
-  std::make_pair(Address, Thread | Memory),
-  std::make_pair(Thread, Memory),
-  std::make_pair(Leak, Thread | Memory),
-  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
-  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
-  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
- KernelAddress),
-  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency),
-  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency)};
   for (auto G : IncompatibleGroups) {
 SanitizerMask Group = G.first;
 if (Kinds & Group) {


Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair IncompatibleGroups[] = {
+  std::make_pair(Address, Thread | Memory),
+  std::make_pair(Thread, Memory),
+  std::make_pair(Leak, Thread | Memory),
+  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
+  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
+  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
+ KernelAddress),
+  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};
+
   // Enable toolchain specific default sanitizers if not explicitly disabled.
-  Kinds |= TC.getDefaultSanitizers() & ~AllRemove;
+  SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
+
+  // Disable default sanitizers that are incompatible with the default ones.
+  for (auto G : IncompatibleGroups) {
+SanitizerMask Group = G.first;
+if ((Default & Group) && (Kinds & G.second))
+  Default &= ~Group;
+  }
+
+  Kinds |= Default;
 
   // We disable the vptr sanitizer if it was enabled by group expansion but RTTI
   // is disabled.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair IncompatibleGroups[] = {
-  std::make_pair(Address, Thread | Memory),
-  std::make_pair(Thread, Memory),
-  std::make_pair(Leak, Thread | Memory),
-  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
-  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
-  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
- KernelAddress),
-  std::make_pair(Scudo,

[PATCH] D44064: [Driver] Automatically disable incompatible default sanitizers

2018-03-06 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326860: [Driver] Automatically disable incompatible default 
sanitizers (authored by phosek, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44064?vs=136893&id=137301#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44064

Files:
  lib/Driver/SanitizerArgs.cpp


Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair IncompatibleGroups[] = {
+  std::make_pair(Address, Thread | Memory),
+  std::make_pair(Thread, Memory),
+  std::make_pair(Leak, Thread | Memory),
+  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
+  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
+  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
+ KernelAddress),
+  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};
+
   // Enable toolchain specific default sanitizers if not explicitly disabled.
-  Kinds |= TC.getDefaultSanitizers() & ~AllRemove;
+  SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
+
+  // Disable default sanitizers that are incompatible with the default ones.
+  for (auto G : IncompatibleGroups) {
+SanitizerMask Group = G.first;
+if ((Default & Group) && (Kinds & G.second))
+  Default &= ~Group;
+  }
+
+  Kinds |= Default;
 
   // We disable the vptr sanitizer if it was enabled by group expansion but 
RTTI
   // is disabled.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair IncompatibleGroups[] = {
-  std::make_pair(Address, Thread | Memory),
-  std::make_pair(Thread, Memory),
-  std::make_pair(Leak, Thread | Memory),
-  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
-  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
-  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
- KernelAddress),
-  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency),
-  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency)};
   for (auto G : IncompatibleGroups) {
 SanitizerMask Group = G.first;
 if (Kinds & Group) {


Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair IncompatibleGroups[] = {
+  std::make_pair(Address, Thread | Memory),
+  std::make_pair(Thread, Memory),
+  std::make_pair(Leak, Thread | Memory),
+  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
+  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
+  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
+ KernelAddress),
+  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};
+
   // Enable toolchain specific default sanitizers if not explicitly disabled.
-  Kinds |= TC.getDefaultSanitizers() & ~AllRemove;
+  SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
+
+  // Disable default sanitizers that are incompatible with the default ones.
+  for (auto G : IncompatibleGroups) {
+SanitizerMask Group = G.first;
+if ((Default & Group) && (Kinds & G.second))
+  Default &= ~Group;
+  }
+
+  Kinds |= Default;
 
   // We disable the vptr sanitizer if it was enabled by group expansion but RTTI
   // is disabled.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair IncompatibleGroups[] = {
-  std::make_pair(Address, Thread | Memory),
-  std::make_pair(Thread, Memory),
-  std::make_pair(Leak, Thread | Memory),
-  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
-  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
-  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
- KernelAddress),
-  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency),
-

r326860 - [Driver] Automatically disable incompatible default sanitizers

2018-03-06 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Mar  6 17:27:03 2018
New Revision: 326860

URL: http://llvm.org/viewvc/llvm-project?rev=326860&view=rev
Log:
[Driver] Automatically disable incompatible default sanitizers

When a sanitizer incompatible with one of the default sanitizers
is explicitly enabled, automatically disable all the conflicting
default sanitizers.

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

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

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=326860&r1=326859&r2=326860&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Mar  6 17:27:03 2018
@@ -332,8 +332,30 @@ SanitizerArgs::SanitizerArgs(const ToolC
 }
   }
 
+  std::pair IncompatibleGroups[] = {
+  std::make_pair(Address, Thread | Memory),
+  std::make_pair(Thread, Memory),
+  std::make_pair(Leak, Thread | Memory),
+  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
+  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
+  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
+ KernelAddress),
+  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};
+
   // Enable toolchain specific default sanitizers if not explicitly disabled.
-  Kinds |= TC.getDefaultSanitizers() & ~AllRemove;
+  SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;
+
+  // Disable default sanitizers that are incompatible with the default ones.
+  for (auto G : IncompatibleGroups) {
+SanitizerMask Group = G.first;
+if ((Default & Group) && (Kinds & G.second))
+  Default &= ~Group;
+  }
+
+  Kinds |= Default;
 
   // We disable the vptr sanitizer if it was enabled by group expansion but 
RTTI
   // is disabled.
@@ -369,18 +391,6 @@ SanitizerArgs::SanitizerArgs(const ToolC
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair IncompatibleGroups[] = {
-  std::make_pair(Address, Thread | Memory),
-  std::make_pair(Thread, Memory),
-  std::make_pair(Leak, Thread | Memory),
-  std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
-  std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
-  std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
- KernelAddress),
-  std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency),
-  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency)};
   for (auto G : IncompatibleGroups) {
 SanitizerMask Group = G.first;
 if (Kinds & Group) {


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


[PATCH] D43494: [Modules] Fix creating fake definition data for lambdas.

2018-03-06 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:1795
   CXXRecordDecl *Canon = D->getCanonicalDecl();
-  if (Canon->DefinitionData) {
+  if (Canon->DefinitionData && Canon->DefinitionData != DD) {
 MergeDefinitionData(Canon, std::move(*DD));

rsmith wrote:
> It's a little odd that we'll temporarily have two different declarations that 
> think they're the definition in this case, but I don't actually know of 
> anything that'll go wrong as a result.
> 
> (This seems easy to avoid, though, by checking whether there already is a 
> definition earlier.)
Uploaded a new patch. Is this what you had in mind by not having two different 
declarations that think they're the definition?


https://reviews.llvm.org/D43494



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


[PATCH] D43494: [Modules] Fix creating fake definition data for lambdas.

2018-03-06 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 137299.
vsapsai added a comment.

- Don't set to-be-deserialized definition data if there is another decl with 
definition data.


https://reviews.llvm.org/D43494

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/self-referencing-lambda/a.h
  clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
  clang/test/Modules/self-referencing-lambda.cpp


Index: clang/test/Modules/self-referencing-lambda.cpp
===
--- /dev/null
+++ clang/test/Modules/self-referencing-lambda.cpp
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I 
%S/Inputs/self-referencing-lambda %s -verify -emit-obj -o %t2.o
+// expected-no-diagnostics
+
+#include "a.h"
Index: clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
@@ -0,0 +1,4 @@
+module "a.h" {
+  header "a.h"
+  export *
+}
Index: clang/test/Modules/Inputs/self-referencing-lambda/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/self-referencing-lambda/a.h
@@ -0,0 +1,4 @@
+void f() {
+  int x = 0;
+  auto q = [xm = x]{};
+}
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1782,21 +1782,25 @@
   else
 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
 
+  CXXRecordDecl *Canon = D->getCanonicalDecl();
+  if (!Canon->DefinitionData)
+// Set definition data before reading it, so that during deserialization
+// when we read CXXRecordDecl, it already has definition data and we don't
+// set fake one.
+D->DefinitionData = DD;
   ReadCXXDefinitionData(*DD, D);
 
   // We might already have a definition for this record. This can happen either
   // because we're reading an update record, or because we've already done some
   // merging. Either way, just merge into it.
-  CXXRecordDecl *Canon = D->getCanonicalDecl();
-  if (Canon->DefinitionData) {
+  if (Canon->DefinitionData && Canon->DefinitionData != DD) {
 MergeDefinitionData(Canon, std::move(*DD));
 D->DefinitionData = Canon->DefinitionData;
 return;
   }
 
   // Mark this declaration as being a definition.
   D->IsCompleteDefinition = true;
-  D->DefinitionData = DD;
 
   // If this is not the first declaration or is an update record, we can have
   // other redeclarations already. Make a note that we need to propagate the


Index: clang/test/Modules/self-referencing-lambda.cpp
===
--- /dev/null
+++ clang/test/Modules/self-referencing-lambda.cpp
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/self-referencing-lambda %s -verify -emit-obj -o %t2.o
+// expected-no-diagnostics
+
+#include "a.h"
Index: clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/self-referencing-lambda/module.modulemap
@@ -0,0 +1,4 @@
+module "a.h" {
+  header "a.h"
+  export *
+}
Index: clang/test/Modules/Inputs/self-referencing-lambda/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/self-referencing-lambda/a.h
@@ -0,0 +1,4 @@
+void f() {
+  int x = 0;
+  auto q = [xm = x]{};
+}
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1782,21 +1782,25 @@
   else
 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
 
+  CXXRecordDecl *Canon = D->getCanonicalDecl();
+  if (!Canon->DefinitionData)
+// Set definition data before reading it, so that during deserialization
+// when we read CXXRecordDecl, it already has definition data and we don't
+// set fake one.
+D->DefinitionData = DD;
   ReadCXXDefinitionData(*DD, D);
 
   // We might already have a definition for this record. This can happen either
   // because we're reading an update record, or because we've already done some
   // merging. Either way, just merge into it.
-  CXXRecordDecl *Canon = D->getCanonicalDecl();
-  if (Canon->DefinitionData) {
+  if (Canon->DefinitionData && Canon->DefinitionData != DD) {
 MergeDefinitionData(Canon, std::move(*DD));
 D->DefinitionData = Canon->DefinitionData;
 return;
   }
 
   // Mark this declaration as being a definition.
   D->IsCompleteDefinition = true;
-  D->DefinitionData = DD;
 
   // If this is not the first declaration

[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/ReleaseNotes.rst:60
 
+- New module `portability` and new `portability-simd-intrinsics
+  
`_
 check

Module and check from it should be mentioned separately. See Release Notes for 
previous release.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173



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


[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137293.
MaskRay marked 2 inline comments as done.
MaskRay added a comment.

Mention new module `portability` in docs/ReleaseNotes.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst

[PATCH] D44069: Test Driver sanitise, unsupported on OpenBSD

2018-03-06 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

Thanks, lgtm provided the bots are happy.


https://reviews.llvm.org/D44069



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


[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please mention new module in Release Notes. I think new modules should be 
before new checks there.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173



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


r326856 - [StaticAnalyzer] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

2018-03-06 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Tue Mar  6 16:17:48 2018
New Revision: 326856

URL: http://llvm.org/viewvc/llvm-project?rev=326856&view=rev
Log:
[StaticAnalyzer] Fix some Clang-tidy modernize and Include What You Use 
warnings; other minor fixes (NFC).

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=326856&r1=326855&r2=326856&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Tue Mar  6 
16:17:48 2018
@@ -1,4 +1,4 @@
-//===--- AnalyzerOptions.h - Analysis Engine Options *- C++ 
-*-===//
+//===- AnalyzerOptions.h - Analysis Engine Options --*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -19,18 +19,18 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
 #include 
+#include 
 #include 
 
 namespace clang {
-class ASTConsumer;
-class DiagnosticsEngine;
-class Preprocessor;
-class LangOptions;
 
 namespace ento {
+
 class CheckerBase;
-}
+
+} // namespace ento
 
 /// Analysis - Set of available source code analyses.
 enum Analyses {
@@ -123,20 +123,20 @@ enum IPAKind {
 
 class AnalyzerOptions : public RefCountedBase {
 public:
-  typedef llvm::StringMap ConfigTable;
+  using ConfigTable = llvm::StringMap;
 
   static std::vector
   getRegisteredCheckers(bool IncludeExperimental = false);
 
   /// \brief Pair of checker name and enable/disable.
-  std::vector > CheckersControlList;
+  std::vector> CheckersControlList;
   
   /// \brief A key-value table of use-specified configuration values.
   ConfigTable Config;
-  AnalysisStores AnalysisStoreOpt;
-  AnalysisConstraints AnalysisConstraintsOpt;
-  AnalysisDiagClients AnalysisDiagOpt;
-  AnalysisPurgeMode AnalysisPurgeOpt;
+  AnalysisStores AnalysisStoreOpt = RegionStoreModel;
+  AnalysisConstraints AnalysisConstraintsOpt = RangeConstraintsModel;
+  AnalysisDiagClients AnalysisDiagOpt = PD_HTML;
+  AnalysisPurgeMode AnalysisPurgeOpt = PurgeStmt;
   
   std::string AnalyzeSpecificFunction;
 
@@ -147,7 +147,6 @@ public:
   /// \brief The maximum number of times the analyzer visits a block.
   unsigned maxBlockVisitOnPath;
   
-  
   /// \brief Disable all analyzer checks.
   ///
   /// This flag allows one to disable analyzer checks on the code processed by
@@ -183,10 +182,11 @@ public:
   unsigned NoRetryExhausted : 1;
   
   /// \brief The inlining stack depth limit.
-  unsigned InlineMaxStackDepth;
+  // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
+  unsigned InlineMaxStackDepth = 5;
   
   /// \brief The mode of function selection used during inlining.
-  AnalysisInliningMode InliningMode;
+  AnalysisInliningMode InliningMode = NoRedundancy;
 
   enum class ExplorationStrategyKind {
 DFS,
@@ -198,14 +198,15 @@ public:
   };
 
 private:
-
-  ExplorationStrategyKind ExplorationStrategy;
+  ExplorationStrategyKind ExplorationStrategy = 
ExplorationStrategyKind::NotSet;
 
   /// \brief Describes the kinds for high-level analyzer mode.
   enum UserModeKind {
 UMK_NotSet = 0,
+
 /// Perform shallow but fast analyzes.
 UMK_Shallow = 1,
+
 /// Perform deep analyzes.
 UMK_Deep = 2
   };
@@ -213,10 +214,10 @@ private:
   /// Controls the high-level analyzer mode, which influences the default 
   /// settings for some of the lower-level config options (such as IPAMode).
   /// \sa getUserMode
-  UserModeKind UserMode;
+  UserModeKind UserMode = UMK_NotSet;
 
   /// Controls the mode of inter-procedural analysis.
-  IPAKind IPAMode;
+  IPAKind IPAMode = IPAK_NotSet;
 
   /// Controls which C++ member functions will be considered for inlining.
   CXXInlineableMemberKind CXXMemberInliningMode;
@@ -345,6 +346,15 @@ private:
  bool SearchInParents = false);
 
 public:
+  AnalyzerOptions()
+  : DisableAllChecks(false), ShowCheckerHelp(false),
+ShowEnabledCheckerList(false), AnalyzeAll(false),
+AnalyzerDisplayProgress(false), AnalyzeNestedBlocks(false),
+eagerlyAssumeBinOpBifurcation(false), TrimGraph(false),
+visualizeExplodedGraphWithGraphViz(false),
+visualizeExplodedGraphWithUbiGraph(false), UnoptimizedCFG(false),
+PrintStats(false), NoRetryExhausted(false), CXXMemberInliningMode() {}
+
   /// Interprets an option's string value as a boolean. The "true" string is
   /// interpreted as true and the "false" string is interpreted as false.
 

[PATCH] D44069: Test Driver sanitise, unsupported on OpenBSD

2018-03-06 Thread David CARLIER via Phabricator via cfe-commits
devnexen added inline comments.



Comment at: test/Driver/fsanitize.c:392
+// RUN %clang -target i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | 
FileCheck --check-prefix=CHECK_UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+

vsk wrote:
> Why does this work? The -check-prefix is "CHECK_UBSAN-OPENBSD", but there's 
> no underscore here.
Good catch



Comment at: test/Driver/unknown-arg.c:60
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+// XFAIL: openbsd

vsk wrote:
> This test should not be expected to fail on openbsd. Whatever it is that 
> you're checking for, please create a narrower test just for openbsd, and add 
> your checks there.
It works finally ... Dunno why I set it as XFAIL originally...


https://reviews.llvm.org/D44069



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


[PATCH] D44069: Test Driver sanitise, unsupported on OpenBSD

2018-03-06 Thread David CARLIER via Phabricator via cfe-commits
devnexen updated this revision to Diff 137284.

https://reviews.llvm.org/D44069

Files:
  test/Driver/fsanitize.c


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -388,6 +388,12 @@
 // RUN: %clang -target armv7-apple-ios7 -miphoneos-version-min=7.0 
-fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-IOS
 // CHECK-ASAN-IOS: -fsanitize=address
 
+// RUN %clang -target i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | 
FileCheck --check-prefix=CHECK-UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-OPENBSD
+// CHECK-ASAN-OPENBSD: unsupported option '-fsanitize=address' for target 
'i386-pc-openbsd'
+
 // RUN: %clang -target x86_64-apple-darwin -fsanitize=leak %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-LSAN-X86-64-DARWIN
 // CHECK-LSAN-X86-64-DARWIN-NOT: unsupported option
 


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -388,6 +388,12 @@
 // RUN: %clang -target armv7-apple-ios7 -miphoneos-version-min=7.0 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-IOS
 // CHECK-ASAN-IOS: -fsanitize=address
 
+// RUN %clang -target i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | FileCheck --check-prefix=CHECK-UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+
+// RUN: %clang -target i386-pc-openbsd -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-OPENBSD
+// CHECK-ASAN-OPENBSD: unsupported option '-fsanitize=address' for target 'i386-pc-openbsd'
+
 // RUN: %clang -target x86_64-apple-darwin -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LSAN-X86-64-DARWIN
 // CHECK-LSAN-X86-64-DARWIN-NOT: unsupported option
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44069: Test Driver sanitise, unsupported on OpenBSD

2018-03-06 Thread Vedant Kumar via Phabricator via cfe-commits
vsk requested changes to this revision.
vsk added inline comments.
This revision now requires changes to proceed.



Comment at: test/Driver/fsanitize.c:392
+// RUN %clang -target i386-pc-openbsd -fsanitize=undefined %s -### 2>&1 | 
FileCheck --check-prefix=CHECK_UBSAN-OPENBSD
+// CHECK-UBSAN-OPENBSD: -fsanitize=undefined
+

Why does this work? The -check-prefix is "CHECK_UBSAN-OPENBSD", but there's no 
underscore here.



Comment at: test/Driver/unknown-arg.c:60
 // IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'
+// XFAIL: openbsd

This test should not be expected to fail on openbsd. Whatever it is that you're 
checking for, please create a narrower test just for openbsd, and add your 
checks there.


https://reviews.llvm.org/D44069



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


r326845 - Fix a typo from r326844; NFC

2018-03-06 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Tue Mar  6 15:09:01 2018
New Revision: 326845

URL: http://llvm.org/viewvc/llvm-project?rev=326845&view=rev
Log:
Fix a typo from r326844; NFC

Modified:
cfe/trunk/test/CodeGen/64bit-swiftcall.c

Modified: cfe/trunk/test/CodeGen/64bit-swiftcall.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/64bit-swiftcall.c?rev=326845&r1=326844&r2=326845&view=diff
==
--- cfe/trunk/test/CodeGen/64bit-swiftcall.c (original)
+++ cfe/trunk/test/CodeGen/64bit-swiftcall.c Tue Mar  6 15:09:01 2018
@@ -1033,7 +1033,7 @@ TEST(union_hom_fp_partial2)
 // X86-64-LABEL: take_union_hom_fp_partial2(i64, float)
 // ARM64-LABEL: take_union_hom_fp_partial2(i64, float)
 
-// At one point, we emitted lifetime.ends without a matching lifetime.begin for
+// At one point, we emitted lifetime.ends without a matching lifetime.start for
 // CoerceAndExpanded args. Since we're not performing optimizations, neither
 // intrinsic should be emitted.
 // CHECK-LABEL: define void @no_lifetime_markers


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


r326844 - [CodeGen] Don't emit lifetime.end without lifetime.start

2018-03-06 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Tue Mar  6 15:07:00 2018
New Revision: 326844

URL: http://llvm.org/viewvc/llvm-project?rev=326844&view=rev
Log:
[CodeGen] Don't emit lifetime.end without lifetime.start

EmitLifetimeStart returns a non-null `size` pointer if it actually
emits a lifetime.start. Later in this function, we use `tempSize`'s
nullness to determine whether or not we should emit a lifetime.end.

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/test/CodeGen/64bit-swiftcall.c

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=326844&r1=326843&r2=326844&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Mar  6 15:07:00 2018
@@ -4010,13 +4010,11 @@ RValue CodeGenFunction::EmitCall(const C
 auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
 auto scalarAlign = 
CGM.getDataLayout().getPrefTypeAlignment(scalarType);
 
-tempSize = llvm::ConstantInt::get(CGM.Int64Ty, scalarSize);
-
 // Materialize to a temporary.
 addr = CreateTempAlloca(RV.getScalarVal()->getType(),
  CharUnits::fromQuantity(std::max(layout->getAlignment(),
   scalarAlign)));
-EmitLifetimeStart(scalarSize, addr.getPointer());
+tempSize = EmitLifetimeStart(scalarSize, addr.getPointer());
 
 Builder.CreateStore(RV.getScalarVal(), addr);
   }

Modified: cfe/trunk/test/CodeGen/64bit-swiftcall.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/64bit-swiftcall.c?rev=326844&r1=326843&r2=326844&view=diff
==
--- cfe/trunk/test/CodeGen/64bit-swiftcall.c (original)
+++ cfe/trunk/test/CodeGen/64bit-swiftcall.c Tue Mar  6 15:07:00 2018
@@ -1032,3 +1032,12 @@ typedef union {
 TEST(union_hom_fp_partial2)
 // X86-64-LABEL: take_union_hom_fp_partial2(i64, float)
 // ARM64-LABEL: take_union_hom_fp_partial2(i64, float)
+
+// At one point, we emitted lifetime.ends without a matching lifetime.begin for
+// CoerceAndExpanded args. Since we're not performing optimizations, neither
+// intrinsic should be emitted.
+// CHECK-LABEL: define void @no_lifetime_markers
+void no_lifetime_markers() {
+  // CHECK-NOT: call void @llvm.lifetime.
+  take_int5(return_int5());
+}


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


[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2018-03-06 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 137279.
yaxunl added a comment.

Clean up CallArg::getRValue() so that it always return independent value.


https://reviews.llvm.org/D34367

Files:
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGCall.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CGGPUBuiltin.cpp
  lib/CodeGen/CGObjCGNU.cpp
  lib/CodeGen/CGObjCMac.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/amdgcn-func-arg.cpp
  test/CodeGenOpenCL/addr-space-struct-arg.cl
  test/CodeGenOpenCL/byval.cl

Index: test/CodeGenOpenCL/byval.cl
===
--- test/CodeGenOpenCL/byval.cl
+++ test/CodeGenOpenCL/byval.cl
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn %s | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn---opencl %s | FileCheck %s
 
 struct A {
   int x[100];
Index: test/CodeGenOpenCL/addr-space-struct-arg.cl
===
--- test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple amdgcn-amdhsa-amd | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -finclude-default-header -triple amdgcn-amdhsa-amd | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,AMDGCN20 %s
 
 typedef struct {
   int cells[9];
@@ -35,6 +36,9 @@
   int2 y[20];
 };
 
+#if __OPENCL_C_VERSION__ >= 200
+struct LargeStructOneMember g_s;
+#endif
 
 // X86-LABEL: define void @foo(%struct.Mat4X4* noalias sret %agg.result, %struct.Mat3X3* byval align 4 %in)
 // AMDGCN-LABEL: define %struct.Mat4X4 @foo([9 x i32] %in.coerce)
@@ -80,10 +84,42 @@
 }
 
 // AMDGCN-LABEL: define void @FuncOneLargeMember(%struct.LargeStructOneMember addrspace(5)* byval align 8 %u)
+// AMDGCN-NOT: addrspacecast
+// AMDGCN:   store <2 x i32> %{{.*}}, <2 x i32> addrspace(5)*
 void FuncOneLargeMember(struct LargeStructOneMember u) {
   u.x[0] = (int2)(0, 0);
 }
 
+// AMDGCN20-LABEL: define void @test_indirect_arg_globl()
+// AMDGCN20:  %[[byval_temp:.*]] = alloca %struct.LargeStructOneMember, align 8, addrspace(5)
+// AMDGCN20:  %[[r0:.*]] = bitcast %struct.LargeStructOneMember addrspace(5)* %[[byval_temp]] to i8 addrspace(5)*
+// AMDGCN20:  call void @llvm.memcpy.p5i8.p1i8.i64(i8 addrspace(5)* align 8 %[[r0]], i8 addrspace(1)* align 8 bitcast (%struct.LargeStructOneMember addrspace(1)* @g_s to i8 addrspace(1)*), i64 800, i1 false)
+// AMDGCN20:  call void @FuncOneLargeMember(%struct.LargeStructOneMember addrspace(5)* byval align 8 %[[byval_temp]])
+#if __OPENCL_C_VERSION__ >= 200
+void test_indirect_arg_globl(void) {
+  FuncOneLargeMember(g_s);
+}
+#endif
+
+// AMDGCN-LABEL: define amdgpu_kernel void @test_indirect_arg_local()
+// AMDGCN: %[[byval_temp:.*]] = alloca %struct.LargeStructOneMember, align 8, addrspace(5)
+// AMDGCN: %[[r0:.*]] = bitcast %struct.LargeStructOneMember addrspace(5)* %[[byval_temp]] to i8 addrspace(5)*
+// AMDGCN: call void @llvm.memcpy.p5i8.p3i8.i64(i8 addrspace(5)* align 8 %[[r0]], i8 addrspace(3)* align 8 bitcast (%struct.LargeStructOneMember addrspace(3)* @test_indirect_arg_local.l_s to i8 addrspace(3)*), i64 800, i1 false)
+// AMDGCN: call void @FuncOneLargeMember(%struct.LargeStructOneMember addrspace(5)* byval align 8 %[[byval_temp]])
+kernel void test_indirect_arg_local(void) {
+  local struct LargeStructOneMember l_s;
+  FuncOneLargeMember(l_s);
+}
+
+// AMDGCN-LABEL: define void @test_indirect_arg_private()
+// AMDGCN: %[[p_s:.*]] = alloca %struct.LargeStructOneMember, align 8, addrspace(5)
+// AMDGCN-NOT: @llvm.memcpy
+// AMDGCN-NEXT: call void @FuncOneLargeMember(%struct.LargeStructOneMember addrspace(5)* byval align 8 %[[p_s]])
+void test_indirect_arg_private(void) {
+  struct LargeStructOneMember p_s;
+  FuncOneLargeMember(p_s);
+}
+
 // AMDGCN-LABEL: define amdgpu_kernel void @KernelOneMember
 // AMDGCN-SAME:  (<2 x i32> %[[u_coerce:.*]])
 // AMDGCN:  %[[u:.*]] = alloca %struct.StructOneMember, align 8, addrspace(5)
@@ -112,7 +148,6 @@
   u.y[0] = (int2)(0, 0);
 }
 
-
 // AMDGCN-LABEL: define amdgpu_kernel void @KernelTwoMember
 // AMDGCN-SAME:  (%struct.StructTwoMember %[[u_coerce:.*]])
 // AMDGCN:  %[[u:.*]] = alloca %struct.StructTwoMember, align 8, addrspace(5)
Index: test/CodeGenCXX/amdgcn-func-arg.cpp
===
--- /dev/null
+++ test/CodeGenCXX/amdgcn-func-arg.cpp
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 -O0 -triple amdgcn---amdgiz -emit-llvm %s -o - | FileCheck %s
+
+class A {
+public:
+  int x;
+  A():x(0) {}
+  ~A() {}
+};
+
+cl

[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 2 inline comments as done.
MaskRay added inline comments.



Comment at: clang-tidy/portability/SIMDIntrinsicsCheck.cpp:141
   if (!New.empty()) {
 std::string Message;
 // If Suggest is true, give a P0214 alternative, otherwise point it out it

lebedev.ri wrote:
> Here too, surely some sane static size can be picked?
Changed to   `llvm::SmallString<32> Std;`

The choices can be:

"std::experimental"
"std"
"dimsum" (https://github.com/google/dimsum)

strlen("std::experimental") = 17 is the longest. Raise to 32 because the <32u> 
template instantiation has been used elsewhere.



Comment at: clang-tidy/portability/SIMDIntrinsicsCheck.h:32
  private:
+  std::string Std;
   const bool Suggest;

lebedev.ri wrote:
> This could be `llvm::SmallString<32> Std;`, actually. (or 
> `strlen("std::experimental")`)
Answered above.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173



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


[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137275.
MaskRay added a comment.

std::string -> llvm::SmallString


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/Rele

[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

I should have seen in during the initial review, but better now than never, 
right? :)




Comment at: clang-tidy/portability/SIMDIntrinsicsCheck.cpp:141
   if (!New.empty()) {
 std::string Message;
 // If Suggest is true, give a P0214 alternative, otherwise point it out it

Here too, surely some sane static size can be picked?



Comment at: clang-tidy/portability/SIMDIntrinsicsCheck.h:32
  private:
+  std::string Std;
   const bool Suggest;

This could be `llvm::SmallString<32> Std;`, actually. (or 
`strlen("std::experimental")`)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173



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


[PATCH] D43797: [CMake] Copy the generated __config header into build directory

2018-03-06 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

Ping again?


Repository:
  rCXX libc++

https://reviews.llvm.org/D43797



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


[PATCH] D43667: [clang-doc] Implement a YAML generator

2018-03-06 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 137272.
juliehockett marked 6 inline comments as done.
juliehockett added a comment.

Updating based on parent changes


https://reviews.llvm.org/D43667

Files:
  clang-doc/CMakeLists.txt
  clang-doc/Representation.h
  clang-doc/generators/CMakeLists.txt
  clang-doc/generators/GeneratorBase.cpp
  clang-doc/generators/Generators.h
  clang-doc/generators/YAMLGenerator.cpp
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/yaml-comments.cpp
  test/clang-doc/yaml-namespace.cpp
  test/clang-doc/yaml-record.cpp

Index: test/clang-doc/yaml-record.cpp
===
--- /dev/null
+++ test/clang-doc/yaml-record.cpp
@@ -0,0 +1,161 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: cat %t/docs/yaml/docs.yaml | FileCheck %s
+
+union A { int X; int Y; };
+
+enum B { X, Y };
+
+enum class Bc { A, B };
+
+struct C { int i; };
+
+class D {};
+
+class E {
+public:
+  E() {}
+  ~E() {}
+
+protected:
+  void ProtectedMethod();
+};
+
+void E::ProtectedMethod() {}
+
+class F : virtual private D, public E {};
+
+class X {
+  class Y {};
+};
+
+void H() {
+  class I {};
+}
+
+// CHECK: ---
+// CHECK-NEXT: Records: 
+// CHECK-NEXT:   - USR: 'ACE81AFA6627B4CEF2B456FB6E1252925674AF7E'
+// CHECK-NEXT: Name:'A'
+// CHECK-NEXT: TagType: Union
+// CHECK-NEXT: Members: 
+// CHECK-NEXT:   - Type:
+// CHECK-NEXT:   USR: 'int'
+// CHECK-NEXT: Name:'A::X'
+// CHECK-NEXT:   - Type:
+// CHECK-NEXT:   USR: 'int'
+// CHECK-NEXT: Name:'A::Y'
+// CHECK-NEXT:   - USR: '06B5F6A19BA9F6A832E127C9968282B94619B210'
+// CHECK-NEXT: Name:'C'
+// CHECK-NEXT: Members: 
+// CHECK-NEXT:   - Type:
+// CHECK-NEXT:   USR: 'int'
+// CHECK-NEXT: Name:'C::i'
+// CHECK-NEXT:   - USR: '0921737541208B8FA9BB42B60F78AC1D779AA054'
+// CHECK-NEXT: Name:'D'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT:   - USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT: Name:'E'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT:   - USR: 'E3B54702FABFF4037025BA194FC27C47006330B5'
+// CHECK-NEXT: Name:'F'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT: Parents: 
+// CHECK-NEXT:   - USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT: Type:Record
+// CHECK-NEXT: VirtualParents:  
+// CHECK-NEXT:   - USR: '0921737541208B8FA9BB42B60F78AC1D779AA054'
+// CHECK-NEXT: Type:Record
+// CHECK-NEXT:   - USR: 'CA7C7935730B5EACD25F080E9C83FA087CCDC75E'
+// CHECK-NEXT: Name:'X'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT:   - USR: '641AB4A3D36399954ACDE29C7A8833032BF40472'
+// CHECK-NEXT: Name:'Y'
+// CHECK-NEXT: Namespace:   
+// CHECK-NEXT:   - USR: 'CA7C7935730B5EACD25F080E9C83FA087CCDC75E'
+// CHECK-NEXT: Type:Record
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT:   - USR: '73C72A405B7A00ECFAACE184766DE3ED7C3702DC'
+// CHECK-NEXT: Name:'I'
+// CHECK-NEXT: Namespace:   
+// CHECK-NEXT:   - USR: 'B6AC4C5C9F2EA3F2B3ECE1A33D349F4EE502B24E'
+// CHECK-NEXT: Type:Function
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT: Functions:   
+// CHECK-NEXT:   - USR: 'DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4'
+// CHECK-NEXT: Name:'E'
+// CHECK-NEXT: Namespace:   
+// CHECK-NEXT:   - USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT: Type:Record
+// CHECK-NEXT: IsMethod:true
+// CHECK-NEXT: Parent:  
+// CHECK-NEXT:   USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT:   Type:Record
+// CHECK-NEXT: ReturnType:  
+// CHECK-NEXT:   Type:
+// CHECK-NEXT: USR: 'void'
+// CHECK-NEXT:   - USR: 'BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17'
+// CHECK-NEXT: Name:'~E'
+// CHECK-NEXT: Namespace:   
+// CHECK-NEXT:   - USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT: Type:Record
+// CHECK-NEXT: IsMethod:true
+// CHECK-NEXT: Parent:  
+// CHECK-NEXT:   USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT:   Type:Record
+/

[PATCH] D44174: do not register matcher for objc-only checks when analyzing non-objc sources to save resources

2018-03-06 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added subscribers: cfe-commits, klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44174

Files:
  clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
  clang-tidy/objc/AvoidNSErrorInitCheck.cpp
  clang-tidy/objc/ForbiddenSubclassingCheck.cpp
  clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -170,6 +170,10 @@
   EscapedAcronyms() {}
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
 SpecialAcronyms.size());
Index: clang-tidy/objc/ForbiddenSubclassingCheck.cpp
===
--- clang-tidy/objc/ForbiddenSubclassingCheck.cpp
+++ clang-tidy/objc/ForbiddenSubclassingCheck.cpp
@@ -77,6 +77,10 @@
 }
 
 void ForbiddenSubclassingCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(
   objcInterfaceDecl(
   isSubclassOf(
Index: clang-tidy/objc/AvoidNSErrorInitCheck.cpp
===
--- clang-tidy/objc/AvoidNSErrorInitCheck.cpp
+++ clang-tidy/objc/AvoidNSErrorInitCheck.cpp
@@ -18,6 +18,10 @@
 namespace objc {
 
 void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(objcMessageExpr(hasSelector("init"),
  hasReceiverType(asString("NSError *")))
  .bind("nserrorInit"),
Index: clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
===
--- clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
+++ clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
@@ -19,6 +19,11 @@
 namespace objc {
 
 void AvoidThrowingObjCExceptionCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
+
   Finder->addMatcher(objcThrowStmt().bind("throwStmt"), this);
   Finder->addMatcher(
   objcMessageExpr(anyOf(hasSelector("raise:format:"),


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -170,6 +170,10 @@
   EscapedAcronyms() {}
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   if (IncludeDefaultAcronyms) {
 EscapedAcronyms.reserve(llvm::array_lengthof(DefaultSpecialAcronyms) +
 SpecialAcronyms.size());
Index: clang-tidy/objc/ForbiddenSubclassingCheck.cpp
===
--- clang-tidy/objc/ForbiddenSubclassingCheck.cpp
+++ clang-tidy/objc/ForbiddenSubclassingCheck.cpp
@@ -77,6 +77,10 @@
 }
 
 void ForbiddenSubclassingCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(
   objcInterfaceDecl(
   isSubclassOf(
Index: clang-tidy/objc/AvoidNSErrorInitCheck.cpp
===
--- clang-tidy/objc/AvoidNSErrorInitCheck.cpp
+++ clang-tidy/objc/AvoidNSErrorInitCheck.cpp
@@ -18,6 +18,10 @@
 namespace objc {
 
 void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (!getLangOpts().ObjC1 && !getLangOpts().ObjC2) {
+return;
+  }
   Finder->addMatcher(objcMessageExpr(hasSelector("init"),
  hasReceiverType(asString("NSError *")))
  .bind("nserrorInit"),
Index: clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
===
--- clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
+++ clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp
@@ -19,6 +19,11 @@
 namespace objc {
 
 void AvoidThrowingObjCExceptionCheck::registerMatchers(MatchFinder *Finder) {
+  // this check should only be applied to ObjC sources.
+  if (

[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137262.
MaskRay added a comment.

.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +95,8 @@

[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137260.
MaskRay added a comment.

comment


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +95

[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137259.
MaskRay added a comment.

index.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +

[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

2018-03-06 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

Right. So the difference is that for blocks, there is always a "(" after the 
"(^.)". That should be easy to parse, no?


Repository:
  rC Clang

https://reviews.llvm.org/D43906



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


[PATCH] D34365: [FrontEnd] Allow overriding the default C/C++ -std via CMake vars

2018-03-06 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326836: [FrontEnd] Allow overriding the default C/C++ -std 
via CMake vars (authored by mgorny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D34365?vs=137227&id=137258#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34365

Files:
  cfe/trunk/CMakeLists.txt
  cfe/trunk/include/clang/Config/config.h.cmake
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp


Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -1809,18 +1809,30 @@
   break;
 case InputKind::Asm:
 case InputKind::C:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   // The PS4 uses C99 as the default C standard.
   if (T.isPS4())
 LangStd = LangStandard::lang_gnu99;
   else
 LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::ObjC:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::CXX:
 case InputKind::ObjCXX:
+#if defined(CLANG_DEFAULT_STD_CXX)
+  LangStd = CLANG_DEFAULT_STD_CXX;
+#else
   LangStd = LangStandard::lang_gnucxx14;
+#endif
   break;
 case InputKind::RenderScript:
   LangStd = LangStandard::lang_c99;
Index: cfe/trunk/include/clang/Config/config.h.cmake
===
--- cfe/trunk/include/clang/Config/config.h.cmake
+++ cfe/trunk/include/clang/Config/config.h.cmake
@@ -11,6 +11,12 @@
 /* Default linker to use. */
 #define CLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}"
 
+/* Default C/ObjC standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+
+/* Default C++/ObjC++ standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
 
Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -212,6 +212,12 @@
 set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
 "enable x86 relax relocations by default")
 
+# TODO: verify the values against LangStandards.def?
+set(CLANG_DEFAULT_STD_C "" CACHE STRING
+  "Default standard to use for C/ObjC code (IDENT from LangStandards.def, 
empty for platform default)")
+set(CLANG_DEFAULT_STD_CXX "" CACHE STRING
+  "Default standard to use for C++/ObjC++ code (IDENT from LangStandards.def, 
empty for platform default)")
+
 set(CLANG_DEFAULT_LINKER "" CACHE STRING
   "Default linker to use (linker name or absolute path, empty for platform 
default)")
 


Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -1809,18 +1809,30 @@
   break;
 case InputKind::Asm:
 case InputKind::C:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   // The PS4 uses C99 as the default C standard.
   if (T.isPS4())
 LangStd = LangStandard::lang_gnu99;
   else
 LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::ObjC:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::CXX:
 case InputKind::ObjCXX:
+#if defined(CLANG_DEFAULT_STD_CXX)
+  LangStd = CLANG_DEFAULT_STD_CXX;
+#else
   LangStd = LangStandard::lang_gnucxx14;
+#endif
   break;
 case InputKind::RenderScript:
   LangStd = LangStandard::lang_c99;
Index: cfe/trunk/include/clang/Config/config.h.cmake
===
--- cfe/trunk/include/clang/Config/config.h.cmake
+++ cfe/trunk/include/clang/Config/config.h.cmake
@@ -11,6 +11,12 @@
 /* Default linker to use. */
 #define CLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}"
 
+/* Default C/ObjC standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+
+/* Default C++/ObjC++ standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
 
Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -212,6 +212,12 @@
 set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
 "enable x86 relax relocations by default")
 
+# TODO: ver

r326836 - [FrontEnd] Allow overriding the default C/C++ -std via CMake vars

2018-03-06 Thread Michal Gorny via cfe-commits
Author: mgorny
Date: Tue Mar  6 13:26:28 2018
New Revision: 326836

URL: http://llvm.org/viewvc/llvm-project?rev=326836&view=rev
Log:
[FrontEnd] Allow overriding the default C/C++ -std via CMake vars

Provide two new CMake cache variables -- CLANG_DEFAULT_STD_C
and CLANG_DEFAULT_STD_CXX -- that can be used to override the default
C/ObjC and C++/ObjC++ standards appropriately. They can be set to one of
the identifiers from LangStandards.def, or left unset (the default) to
respect the current platform default.

This option is mostly intended for compiler vendors that may wish
to adjust the defaults their compilers are using. For example, Gentoo
planned to use it to set clang and gcc to matching standards, so that
we could maintain as much compatibility between different compilers
as possible.

The code relies on explicit identifiers rather than the string aliases
for simplicity. This saves us from the necessity of parsing aliases at
build-time or adding additional processing at runtime. For the latter
case, it also adds trivial value check -- if incorrect value is passed,
the code simply fails to compile through referencing an undefined
constant.

If the variable is used to redefine the default standard, the explicit
value overrides the special case for PS4. It is done this way mostly
following other kinds of variables where 'platform defaults' are
redefined.

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

Modified:
cfe/trunk/CMakeLists.txt
cfe/trunk/include/clang/Config/config.h.cmake
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=326836&r1=326835&r2=326836&view=diff
==
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Tue Mar  6 13:26:28 2018
@@ -212,6 +212,12 @@ set(ENABLE_LINKER_BUILD_ID OFF CACHE BOO
 set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
 "enable x86 relax relocations by default")
 
+# TODO: verify the values against LangStandards.def?
+set(CLANG_DEFAULT_STD_C "" CACHE STRING
+  "Default standard to use for C/ObjC code (IDENT from LangStandards.def, 
empty for platform default)")
+set(CLANG_DEFAULT_STD_CXX "" CACHE STRING
+  "Default standard to use for C++/ObjC++ code (IDENT from LangStandards.def, 
empty for platform default)")
+
 set(CLANG_DEFAULT_LINKER "" CACHE STRING
   "Default linker to use (linker name or absolute path, empty for platform 
default)")
 

Modified: cfe/trunk/include/clang/Config/config.h.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Config/config.h.cmake?rev=326836&r1=326835&r2=326836&view=diff
==
--- cfe/trunk/include/clang/Config/config.h.cmake (original)
+++ cfe/trunk/include/clang/Config/config.h.cmake Tue Mar  6 13:26:28 2018
@@ -11,6 +11,12 @@
 /* Default linker to use. */
 #define CLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}"
 
+/* Default C/ObjC standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+
+/* Default C++/ObjC++ standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
 

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=326836&r1=326835&r2=326836&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Mar  6 13:26:28 2018
@@ -1809,18 +1809,30 @@ void CompilerInvocation::setLangDefaults
   break;
 case InputKind::Asm:
 case InputKind::C:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   // The PS4 uses C99 as the default C standard.
   if (T.isPS4())
 LangStd = LangStandard::lang_gnu99;
   else
 LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::ObjC:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::CXX:
 case InputKind::ObjCXX:
+#if defined(CLANG_DEFAULT_STD_CXX)
+  LangStd = CLANG_DEFAULT_STD_CXX;
+#else
   LangStd = LangStandard::lang_gnucxx14;
+#endif
   break;
 case InputKind::RenderScript:
   LangStd = LangStandard::lang_c99;


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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In https://reviews.llvm.org/D42983#1028241, @alexfh wrote:

> In https://reviews.llvm.org/D42983#1028093, @MaskRay wrote:
>
> > In https://reviews.llvm.org/D42983#1025179, @alexfh wrote:
> >
> > > A late comment here: should this check start a new "portability" module? 
> > > This seems to be the main focus of the check rather than making code more 
> > > readable.
> >
> >
> > SG. Should I rename it?
>
>
> If nobody objects, yes, please. You'll need create the module manually and 
> then use the rename_check.py script for the actual renaming.


I just created https://reviews.llvm.org/D44173 . Didn't know `rename_check.py` 
and manually renamed a bunch of files...


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D39562: [CodeGen][ObjC] Fix an assertion failure caused by copy elision

2018-03-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Sorry, this patch is not ready yet. There are several regression tests that are 
failing because of the assert in setIsUnique.


https://reviews.llvm.org/D39562



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


[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137256.
MaskRay added a comment.

.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +95,8 @@
   Finds and replaces deprecated uses of ``std::uncaught_exception`` to
   ``std::uncaught_exceptions``.
 
-- New `readability-simd-intrinsics
-  `_ check
+- New `portability-simd-intrinsics
+  `_ check
 
   Warns if SIMD intrinsics are used which can be replaced by
   ``std::experimental::simd`` operations.
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -554,6 +554,11 @@
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
 PerformanceModuleAnchorSource;
 
+// This 

[PATCH] D39562: [CodeGen][ObjC] Fix an assertion failure caused by copy elision

2018-03-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/AST/Expr.h:875
+  /// is set to true.
+  bool IsUnique = false;
+

rjmccall wrote:
> Humor me and pack this in the bitfields in Stmt, please. :)
Thanks!



Comment at: lib/CodeGen/CGExpr.cpp:4815
+}
+  }
+

Oh!  So it's an interesting point that the RHS might be used as the result 
expression, which means its use might not really be unique anymore.  It happens 
to work in some sense for non-trivial C++ class types (when they're passed 
indirectly, as under the Itanium ABI) because the temporary outlives the call; 
on the other hand, the call is allowed to mutate its argument, and it's not 
clear that it's okay to have those mutations be reflected in code that's using 
the result of the assignment.  Similarly, managed types (like non-trivial C 
structs, or ARC pointers) might be consumed by the call; if we're going to pass 
them, perhaps we need to copy the value before doing so.

What do you think?

I think the technical implication is that what you're doing here shouldn't be 
necessary; the OVE arguably should not be unique if its value is used in 
multiple places, and that includes being used as a result.


https://reviews.llvm.org/D39562



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


[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added a reviewer: alexfh.
Herald added subscribers: cfe-commits, kbarton, xazax.hun, mgorny, nemanjai, 
klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +95,8 @@
   Finds and replaces deprecated uses of ``std::uncaught_exception`` to
   ``std::uncaught_exceptions``.
 
-- New `readability-simd-intrinsics
-  `_ check
+- New `portability-simd-intrinsics
+  `_ check
 
   Warns if SIMD intrinsics are used which can be replaced by
   ``std::experimental::simd`` operations.
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -554,6 +554,11 @@
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
 PerformanceModuleAnchorSource;
 
+// This anchor is used to force the linker to link the PortabilityModule.
+extern volatile int PortabilityModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination =
+PortabilityModuleAnchorSour

[PATCH] D39562: [CodeGen][ObjC] Fix an assertion failure caused by copy elision

2018-03-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/Sema/SemaPseudoObject.cpp:432
+  if (capturedRHS->getType()->getAsCXXRecordDecl() && capturedRHS->isRValue())
+capturedRHS->setIsUnique();
+

rjmccall wrote:
> I think you can unconditionally set this here, actually.  You just need to 
> teach the other two exhaustive emitters in IRGen (scalar and complex) to look 
> through unique OVEs.  Plenty of other things in IRGen could benefit from 
> being able to peephole through unique OVEs.
> 
> Also, you can set it on the OVE for the base expression if this is a simple 
> assignment or load.
All the builders created in checkPseudoObjectRValue and 
checkPseudoObjectAssignment (only when the assignment is simple) set the OVE's 
IsUnique bit to true.


https://reviews.llvm.org/D39562



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


[PATCH] D39562: [CodeGen][ObjC] Fix an assertion failure caused by copy elision

2018-03-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 137250.
ahatanak marked 3 inline comments as done.
ahatanak added a comment.

Address review comments.


https://reviews.llvm.org/D39562

Files:
  include/clang/AST/Expr.h
  include/clang/AST/Stmt.h
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaPseudoObject.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/CodeGenCXX/ms-property.cpp
  test/CodeGenObjC/objc-container-subscripting-1.m
  test/CodeGenObjCXX/property-dot-copy-elision.mm
  test/CodeGenObjCXX/property-objects.mm

Index: test/CodeGenObjCXX/property-objects.mm
===
--- test/CodeGenObjCXX/property-objects.mm
+++ test/CodeGenObjCXX/property-objects.mm
@@ -72,7 +72,7 @@
 
 // rdar://8379892
 // CHECK-LABEL: define void @_Z1fP1A
-// CHECK: call void @_ZN1XC1Ev(%struct.X* [[LVTEMP:%[a-zA-Z0-9\.]+]])
+// CHECK: call void @_ZN1XC1Ev(%struct.X* [[LVTEMP:%.+]])
 // CHECK: call void @_ZN1XC1ERKS_(%struct.X* [[AGGTMP:%[a-zA-Z0-9\.]+]], %struct.X* dereferenceable({{[0-9]+}}) [[LVTEMP]])
 // CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, %struct.X*)*)({{.*}} %struct.X* [[AGGTMP]])
 struct X {
@@ -118,15 +118,14 @@
 }
 // CHECK:define void @_Z6testB0P1B([[B:%.*]]*
 // CHECK:  [[BVAR:%.*]] = alloca [[B]]*, align 8
-// CHECK:  [[TEMP:%.*]] = alloca [[B0:%.*]], align 8
+// CHECK:  alloca [[B0:%.*]], align 8
+// CHECK:  [[TEMP:%.*]] = alloca [[B0]], align 8
 // CHECK:  load [[B]]*, [[B]]** [[BVAR]]
 // CHECK-NEXT: [[X:%.*]] = getelementptr inbounds [[B0]], [[B0]]* [[TEMP]], i32 0, i32 0
 // CHECK-NEXT: [[T0:%.*]] = call i32 @_Z9b_makeIntv()
 // CHECK-NEXT: [[T1:%.*]] = sext i32 [[T0]] to i64
 // CHECK-NEXT: store i64 [[T1]], i64* [[X]], align 8
 // CHECK-NOT:  call
-// CHECK:  call void @llvm.memcpy
-// CHECK-NOT:  call
 // CHECK:  call void bitcast {{.*}} @objc_msgSend
 // CHECK-NOT:  call
 // CHECK:  ret void
@@ -168,8 +167,6 @@
 // CHECK-NOT:  call
 // CHECK:  store i64 [[T0]],
 // CHECK-NOT:  call
-// CHECK:  call void @llvm.memcpy
-// CHECK-NOT:  call
 // CHECK:  call void bitcast {{.*}} @objc_msgSend
 // CHECK-NOT:  call
 // CHECK:  ret void
Index: test/CodeGenObjCXX/property-dot-copy-elision.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/property-dot-copy-elision.mm
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -std=c++1z -fobjc-arc -o - %s | FileCheck %s
+
+struct S0 {
+  id f;
+};
+
+struct S1 {
+  S1();
+  S1(S0);
+  id f;
+};
+
+@interface C
+@property S1 f;
+@end
+@implementation C
+@end
+
+// CHECK-LABEL: define void @_Z5test0P1C(
+// CHECK: %{{.*}} = alloca %
+// CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_S1:.*]], align
+// CHECK: %[[AGG_TMP_1:.*]] = alloca %[[STRUCT_S0:.*]], align
+// CHECK: call void @_ZN2S0C1Ev(%[[STRUCT_S0]]* %[[AGG_TMP_1]])
+// CHECK: call void @_ZN2S1C1E2S0(%[[STRUCT_S1]]* %[[AGG_TMP]], %[[STRUCT_S0]]* %[[AGG_TMP_1]])
+// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, %[[STRUCT_S1]]*)*)(i8* %{{.*}}, i8* %{{.*}}, %[[STRUCT_S1]]* %[[AGG_TMP]])
+
+void test0(C *c) {
+  c.f = S0();
+}
+
+// CHECK: define void @_Z5test1P1C(
+// CHECK: %{{.*}} = alloca %
+// CHECK: %[[TEMP_LVALUE:.*]] = alloca %[[STRUCT_S1:.*]], align
+// CHECK: call void @_ZN2S1C1Ev(%[[STRUCT_S1]]* %[[TEMP_LVALUE]])
+// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, %[[STRUCT_S1]]*)*)(i8* %{{.*}}, i8* %{{.*}}, %[[STRUCT_S1]]* %[[TEMP_LVALUE]])
+
+void test1(C *c) {
+  c.f = S1();
+}
Index: test/CodeGenObjC/objc-container-subscripting-1.m
===
--- test/CodeGenObjC/objc-container-subscripting-1.m
+++ test/CodeGenObjC/objc-container-subscripting-1.m
@@ -46,8 +46,8 @@
 
   val = (dictionary[key] = newObject);
 // CHECK: [[TWELVE:%.*]] = load {{%.*}} [[DICTIONARY]], align 8
-// CHECK-NEXT:  [[THIRTEEN:%.*]] = load i8*, i8** [[KEY]], align 8
 // CHECK-NEXT:  [[FOURTEEN:%.*]] = load i8*, i8** [[NEWOBJECT:%.*]], align 8
+// CHECK-NEXT:  [[THIRTEEN:%.*]] = load i8*, i8** [[KEY]], align 8
 // CHECK-NEXT:  [[SIXTEEN:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_.6
 // CHECK-NEXT:  [[SEVENTEEN:%.*]] = bitcast {{%.*}} [[TWELVE]] to i8*
 // CHECK-NEXT:  call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*, i8*)*)(i8* [[SEVENTEEN]], i8* [[SIXTEEN]], i8* [[FOURTEEN]], i8* [[THIRTEEN]])
Index: test/CodeGenCXX/ms-property.cpp
===
--- test/CodeGenCXX/ms-property.cpp
+++ test/CodeGenCXX/ms-property.cpp
@@ -75,11 +75,11 @@
   // CHECK: call void @"\01??$foo@H@@YAXHH@Z"(i32 %{{.+}}, i32 %{{.+}})
   foo(argc, (int)argv[0][0]);
   // CHECK: [[P2:%.+]]

[PATCH] D43847: [clang-tidy] Add check: replace string::find(...) == 0 with absl::StartsWith

2018-03-06 Thread Niko Weh via Phabricator via cfe-commits
niko added inline comments.



Comment at: clang-tidy/abseil/AbseilTidyModule.cpp:15
+
+#include 
+

hokein wrote:
> What is this header used for?
Sorry, ended up in the wrong file, moved to StringFindStartswithCheck.cpp.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43847



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


[PATCH] D43847: [clang-tidy] Add check: replace string::find(...) == 0 with absl::StartsWith

2018-03-06 Thread Niko Weh via Phabricator via cfe-commits
niko updated this revision to Diff 137249.
niko marked 4 inline comments as done.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43847

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tidy/abseil/CMakeLists.txt
  clang-tidy/abseil/StringFindStartswithCheck.cpp
  clang-tidy/abseil/StringFindStartswithCheck.h
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/abseil-string-find-startswith.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/abseil-string-find-startswith.cpp

Index: test/clang-tidy/abseil-string-find-startswith.cpp
===
--- test/clang-tidy/abseil-string-find-startswith.cpp
+++ test/clang-tidy/abseil-string-find-startswith.cpp
@@ -0,0 +1,55 @@
+// RUN: %check_clang_tidy %s abseil-string-find-startswith %t
+
+namespace std {
+template  class allocator {};
+template  class char_traits {};
+template ,
+  typename A = std::allocator>
+struct basic_string {
+  basic_string();
+  basic_string(const basic_string &);
+  basic_string(const C *, const A &a = A());
+  ~basic_string();
+  int find(basic_string s, int pos = 0);
+  int find(const char *s, int pos = 0);
+};
+typedef basic_string string;
+typedef basic_string wstring;
+} // namespace std
+
+std::string foo(std::string);
+std::string bar();
+
+#define A_MACRO(x, y) ((x) == (y))
+
+void tests(std::string s) {
+  s.find("a") == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith instead of find() == 0 [abseil-string-find-startswith]
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, "a");{{$}}
+
+  s.find(s) == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith
+  // CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, s);{{$}}
+
+  s.find("aaa") != 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
+  // CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, "aaa");{{$}}
+
+  s.find(foo(foo(bar( != 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
+  // CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, foo(foo(bar(;{{$}}
+
+  if (s.find("") == 0) { /* do something */ }
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use absl::StartsWith
+  // CHECK-FIXES: {{^[[:space:]]*}}if (absl::StartsWith(s, "")) { /* do something */ }{{$}}
+
+  0 != s.find("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
+  // CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, "a");{{$}}
+
+  // expressions that don't trigger the check are here.
+  A_MACRO(s.find("a"), 0);
+  s.find("a", 1) == 0;
+  s.find("a", 1) == 1;
+  s.find("a") == 1;
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -4,6 +4,7 @@
 =
 
 .. toctree::
+   abseil-string-find-startswith
android-cloexec-accept
android-cloexec-accept4
android-cloexec-creat
Index: docs/clang-tidy/checks/abseil-string-find-startswith.rst
===
--- docs/clang-tidy/checks/abseil-string-find-startswith.rst
+++ docs/clang-tidy/checks/abseil-string-find-startswith.rst
@@ -0,0 +1,41 @@
+.. title:: clang-tidy - abseil-string-find-startswith
+
+abseil-string-find-startswith
+=
+
+Checks whether a ``std::string::find()`` result is compared with 0, and
+suggests replacing with ``absl::StartsWith()``. This is both a readability and
+performance issue.
+
+.. code-block:: c++
+
+  string s = "...";
+  if (s.find("Hello World") == 0) { /* do something */ }
+
+becomes
+
+
+.. code-block:: c++
+
+  string s = "...";
+  if (absl::StartsWith(s, "Hello World")) { /* do something */ }
+
+
+Options
+---
+
+.. option:: StringLikeClasses
+
+   Semicolon-separated list of names of string-like classes. By default only
+   ``std::basic_string`` is considered. The list of methods to considered is
+   fixed.
+
+.. option:: IncludeStyle
+
+   A string specifying which include-style is used, `llvm` or `google`. Default
+   is `llvm`.
+
+.. option:: AbseilStringsMatchHeader
+
+   The location of Abseil's ``strings/match.h``. Defaults to
+   ``absl/strings/match.h``.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -75,6 +75,15 @@
 
   Warns if a class inherits from multiple classes that are not pure virtual.
 
+- New `abseil` module for checks related to the `Abseil `_
+  library.
+
+- New `abseil-string-find-startswith
+  `_ check
+
+  Checks whether a ``std::string::find()`` result is compared with 0, and
+  suggests replacing with ``absl::StartsWith()``.
+

[PATCH] D43500: [clang-tidy]: modernize-use-default-member-init: Remove trailing comma and colon.

2018-03-06 Thread Jeremy Demeule via Phabricator via cfe-commits
jdemeule added inline comments.



Comment at: unittests/clang-tidy/ClangTidyTest.h:145
+
+  if (Options.FormatStyle) {
+llvm::Expected Style = format::getStyle(

alexfh wrote:
> I wonder whether it's better to use lit for the tests that require formatting 
> than to expand clang-tidy unit test utilities with runCheckAndFormatOnCode? 
> What was the reason to use unit tests in this patch as opposed to lit tests?
Indeed, that a good question.
Personally, I found unit test easier to launch and debug than lit test and I 
notice that it is not possible to made a unit test which react the same way as 
clang-tidy.
When I wrote this test, I want it to react as in clang-tidy and for this I try 
to call `cleanupAroundReplacements` in the test.
Adding formatting was more a side effect to have some sustainable and 
comprehensive way to write test.



https://reviews.llvm.org/D43500



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-03-06 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Nice!
Some further notes based on the SHA1 nature.




Comment at: clang-doc/BitcodeWriter.cpp:74
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer (ref type)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,

Those are mixed up.
`USRLengthSize` is definitively supposed to be second.



Comment at: clang-doc/BitcodeWriter.cpp:81
+ // 2. The string blob
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)});
+}

The sha1 is all-printable, so how about using 
`BitCodeAbbrevOp::Encoding::Char6` ?
Char4 would work best, but it is not there.



Comment at: clang-doc/BitcodeWriter.cpp:149
+  {MEMBER_TYPE_ACCESS, {"Access", &IntAbbrev}},
+  {NAMESPACE_USR, {"USR", &StringAbbrev}},
+  {NAMESPACE_NAME, {"Name", &StringAbbrev}},

Ha, and all the `*_USR` are actually `StringAbbrev`'s, not confusing at all :)



Comment at: clang-doc/BitcodeWriter.cpp:309
+  assert(Ref.USR.size() < (1U << BitCodeConstants::USRLengthSize));
+  Record.push_back(Ref.USR.size());
+  Stream.EmitRecordWithBlob(Abbrevs.get(ID), Record, Ref.USR);

Now it would make sense to also assert that this sha1(usr).strlen() == 20



Comment at: clang-doc/BitcodeWriter.h:46
+  static constexpr unsigned ReferenceTypeSize = 8U;
+  static constexpr unsigned USRLengthSize = 16U;
+};

Can definitively lower this to `5U` (2^6 == 32, which is more than the 20 8-bit 
chars of sha1)



Comment at: clang-doc/Representation.h:59
+
+  SmallString<16> USR;
+  InfoType RefType = InfoType::IT_default;

Now that USR is sha1'd, this is **always** 20 8-bit characters long.



Comment at: clang-doc/Representation.h:107
+
+  SmallString<16> USR;
+  SmallString<16> Name;

`20`
Maybe place `using USRString = SmallString<20>; // SHA1 of USR` somewhere and 
use it everywhere?


https://reviews.llvm.org/D41102



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-03-06 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/BitcodeReader.cpp:19
+
+void ClangDocBitcodeReader::storeData(llvm::SmallString<4> &Field,
+  llvm::StringRef Blob) {

lebedev.ri wrote:
> I think all these `SmallString` can be one `llvm::SmallVectorImpl`?
No, since there's not an implicit converter from `llvm::SmallVectorImpl` 
to `StringRef`. I templatized it on the size though, so it's only one function 
now.



Comment at: clang-doc/Representation.h:193
+ private:
+  void resolveReferences(llvm::SmallVector &References,
+ Reference &Caller);

lebedev.ri wrote:
> Similarly, i think those should be `SmallVectorImpl` (i assume those are 
> output params, too?)
Yup -- the pointer inside gets set.


https://reviews.llvm.org/D43341



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-03-06 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 137245.
juliehockett marked 8 inline comments as done.
juliehockett added a comment.

Adding in support for mapper tests and addressing comments.


https://reviews.llvm.org/D43341

Files:
  clang-doc/BitcodeReader.cpp
  clang-doc/BitcodeReader.h
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/Reducer.cpp
  clang-doc/Reducer.h
  clang-doc/Representation.cpp
  clang-doc/Representation.h
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/bc-comment.cpp
  test/clang-doc/bc-namespace.cpp
  test/clang-doc/bc-record.cpp

Index: test/clang-doc/bc-record.cpp
===
--- /dev/null
+++ test/clang-doc/bc-record.cpp
@@ -0,0 +1,168 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/docs.bc --dump | FileCheck %s
+
+union A { int X; int Y; };
+
+enum B { X, Y };
+
+enum class Bc { A, B };
+
+struct C { int i; };
+
+class D {};
+
+class E {
+public:
+  E() {}
+  ~E() {}
+
+protected:
+  void ProtectedMethod();
+};
+
+void E::ProtectedMethod() {}
+
+class F : virtual private D, public E {};
+
+class X {
+  class Y {};
+};
+
+void H() {
+  class I {};
+}
+
+// CHECK: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4'
+  // CHECK-NEXT:  blob data = 'E'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'void'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17'
+  // CHECK-NEXT:  blob data = '~E'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'void'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '5093D428CDC62096A67547BA52566E4FB9404EEE'
+  // CHECK-NEXT:  blob data = 'ProtectedMethod'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'void'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '5093D428CDC62096A67547BA52566E4FB9404EEE'
+  // CHECK-NEXT:  blob data = 'ProtectedMethod'
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'void'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'B6AC4C5C9F2EA3F2B3ECE1A33D349F4EE502B24E'
+  // CHECK-NEXT:  blob data = 'H'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'void'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'ACE81AFA6627B4CEF2B456FB6E1252925674AF7E'
+  // CHECK-NEXT:  blob data = 'A'
+  // CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'int'
+// CHECK-NEXT:  blob data = 'A::X'
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'int'
+// CHECK-NEXT:  blob data = 'A::Y'
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '06B5F6A19BA9F6A832E127C9968282B94619B210'
+  // CHECK-NEXT:  blob data = 'C'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'int'
+// CHECK-NEXT:  blob data = 'C::i'
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '0921737541208B8FA9BB42B60F78AC1D779AA054'
+  // CHECK-NEXT:  blob data = 'D'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT:  blob data = 'E'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'E3B54702FABFF4037025BA194FC27C47006330B5'
+  // CHECK-NEXT:  blob data = 'F'
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '289584A8E0FF4178A794622A547AA622503967A1'
+  // CHECK-NEXT:  blob data = '0921737541208B8FA9BB42B60F78AC1D779AA054'
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'CA7C7935730B5EACD25F080E9C83FA087CCDC75E'
+  // CHECK-NEXT:  blob data = 'X'
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '641AB4A3D36399954ACDE29C7A8833032BF40472'
+  // CHECK-NEXT:  blob data = 'Y'
+  // CHECK-NEXT:  blob data = 'CA7C7935730B5EACD25F080E9C83FA087CCDC75E'
+  // CHECK-NEXT: 
+// CHECK-

[PATCH] D41102: Setup clang-doc frontend framework

2018-03-06 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 137244.
juliehockett added a comment.

Adding hashing to reduce the size of USRs and updating tests.


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.h
  clang-doc/Serialize.cpp
  clang-doc/Serialize.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class-in-class.cpp
  test/clang-doc/mapper-class-in-function.cpp
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-comments.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,28 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump-mapper --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/0B8A6B938B939B77C63258AA3E938BF9E2E8.bc --dump | FileCheck %s
+
+union D { int X; int Y; };
+
+// CHECK: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '0B8A6B938B939B77C63258AA3E938BF9E2E8'
+  // CHECK-NEXT:  blob data = 'D'
+  // CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'int'
+// CHECK-NEXT:  blob data = 'D::X'
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'int'
+// CHECK-NEXT:  blob data = 'D::Y'
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump-mapper --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/06B5F6A19BA9F6A832E127C9968282B94619B210.bc --dump | FileCheck %s
+
+struct C { int i; };
+
+// CHECK: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '06B5F6A19BA9F6A832E127C9968282B94619B210'
+  // CHECK-NEXT:  blob data = 'C'
+  // CHECK-NEXT: 
+// CHECK-NEXT:  blob data = 'int'
+// CHECK-NEXT:  blob data = 'C::i'
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump-mapper --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/8D042EFFC98B373450BC6B5B90A330C25A150E9C.bc --dump | FileCheck %s
+
+namespace A {}
+
+// CHECK: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = '8D042EFFC98B373450BC6B5B90A330C25A150E9C'
+  // CHECK-NEXT:  blob data = 'A'
+// CHECK-NEXT: 
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,41 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump-mapper --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/F0F9FC65FC90F54F690144A7AFB15DFC3D69B6E6.bc --dump | FileCheck %s --check-prefix CHECK-G-F
+// RUN: llvm-bcanalyzer %t/docs/bc/4202E8BF0ECB12AE354C8499C52725B0EE30AED5.bc --dump | FileCheck %s --check-prefix CHECK-G
+
+class G {
+public: 
+	int Method(int param) { return param; }
+};
+
+// CHECK-G: 
+// CHECK-G-NEXT: 
+  // CHECK-G-NEXT: 
+// CHECK-G-NEXT: 
+// CHECK-G-NEXT: 
+  // CHECK-G-NEXT:  blob data = '4202E8BF0ECB12AE354C8499C52725B0EE30AED5'
+  // CHECK-G-NEXT:  blob data = 'G'
+  // CHECK-G-NEXT: 
+// CHECK-G-NEXT: 
+
+// CHECK-G-F: 
+// CHECK-G-F-NEXT: 
+  // CHECK-G-F-NEXT: 
+// CHECK-G-F-NEXT: 
+// CHECK-G-F-NEXT: 
+  // CHECK-G-F-NEXT:  blob data = 'F0F9FC65FC90F54F690144A7AFB15DFC3D69B6E6'
+  // CHECK-G-F-NEXT:  blob data = 'Method'
+  // CHECK-G-F-NEXT:  blob data = '4202E8BF0ECB12AE354C8499C52725B0EE30AED5'
+  // CHECK-G-F-NEXT: 
+  // CHECK-G-F-NEXT:  blob data = '4202E8BF0ECB12AE354C8499C52725B0EE30AED5'
+  // CHECK-G-F-NEXT: 
+// CHECK-G-F-NEXT:  blob data = 'int'
+  // CHECK-G-F-NEXT: 
+  // CHECK-G-F-NEXT: 
+// CHECK-G-F-NEXT:  blob data = 'int'
+ 

[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

2018-03-06 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:155
+   Next->startsSequence(tok::identifier, tok::l_square,
+tok::numeric_constant, tok::r_square,
+tok::r_paren, tok::l_paren))) {

djasper wrote:
> benhamilton wrote:
> > benhamilton wrote:
> > > djasper wrote:
> > > > benhamilton wrote:
> > > > > djasper wrote:
> > > > > > This seems suspect. Does it have to be a numeric_constant?
> > > > > Probably not, any constexpr would do, I suspect. What's the best way 
> > > > > to parse that?
> > > > I think this is the same answer for both of your questions. If what you 
> > > > are trying to prevent "FOO(^)" to be parsed as a block, wouldn't it be 
> > > > enough to look for whether there is a "(" after the ")" or even only 
> > > > after "(^)", everything else is already correct IIUC? That would get 
> > > > you out of need to parse the specifics here, which will be hard.
> > > > 
> > > > Or thinking about it another way. Previously, every "(^" would be 
> > > > parsed as an ObjC block. There seems to be only a really rare corner 
> > > > case in which it isn't (macros). Thus, I'd just try to detect that 
> > > > corner case. Instead you are completely inverting the defaults 
> > > > (defaulting to "^" is not a block) and then try to exactly parse ObjC 
> > > > where there might be many cases and edge cases that you won't even 
> > > > think of now.
> > > Hmm. Well, it's not just `FOO(^);` that isn't a block:
> > > 
> > > ```
> > > #define FOO(X) operator X
> > > 
> > > SomeType FOO(^)(int x, const SomeType& y) { ... }
> > > ```
> > > 
> > > Obviously we can't get this perfect without a pre-processor, but it seems 
> > > like our best bet is to only assign mark `TT_ObjCBlockLParen` when we are 
> > > sure the syntax is a valid block type or block variable.
> > I tried the suggestion to only treat `(^)(` as a block type, but it appears 
> > this is the primary place where we set `TT_ObjCBlockLParen`, so I think we 
> > really do need to handle the other cases here.
> I don't follow your logic. I'd like you to slowly change this as opposed to 
> completely going the opposite way.
> 
> So currently, the only know real-live problem is "FOO(^);". So address this 
> somehow, but still default/error to recognizing too much stuff as a block.
> 
> Have you actually seen
> 
>   SomeType FOO(^)(int x, const SomeType& y) { ... }
> 
> in real code?
I haven't seen that example, but I have seen `FOO(^, OtherParam);`.

I'm trying to change the parser to handle this now without explicitly parsing 
all block types, but it's tricky. The following should be ObjC block types:

```
(^)(int, char);
(^foo)(int, char);
(^foo[10])(int, char);
(^foo[kNum])(int, char);
(^foo[(kNum + kOtherNum)])(int, char);
```

but the following should not:

```
FOO(^);
FOO(^, int, char);
```

I'll make it work, it's just easy to make a mistake.


Repository:
  rC Clang

https://reviews.llvm.org/D43906



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


[PATCH] D43494: [Modules] Fix creating fake definition data for lambdas.

2018-03-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:1795
   CXXRecordDecl *Canon = D->getCanonicalDecl();
-  if (Canon->DefinitionData) {
+  if (Canon->DefinitionData && Canon->DefinitionData != DD) {
 MergeDefinitionData(Canon, std::move(*DD));

It's a little odd that we'll temporarily have two different declarations that 
think they're the definition in this case, but I don't actually know of 
anything that'll go wrong as a result.

(This seems easy to avoid, though, by checking whether there already is a 
definition earlier.)


https://reviews.llvm.org/D43494



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


[PATCH] D43494: [Modules] Fix creating fake definition data for lambdas.

2018-03-06 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Ping.


https://reviews.llvm.org/D43494



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


[PATCH] D34365: [FrontEnd] Allow overriding the default C/C++ -std via CMake vars

2018-03-06 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Yep, looks good. I'd leave renderscript alone. I think it's deprecated.


https://reviews.llvm.org/D34365



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


[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

2018-03-06 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:155
+   Next->startsSequence(tok::identifier, tok::l_square,
+tok::numeric_constant, tok::r_square,
+tok::r_paren, tok::l_paren))) {

benhamilton wrote:
> benhamilton wrote:
> > djasper wrote:
> > > benhamilton wrote:
> > > > djasper wrote:
> > > > > This seems suspect. Does it have to be a numeric_constant?
> > > > Probably not, any constexpr would do, I suspect. What's the best way to 
> > > > parse that?
> > > I think this is the same answer for both of your questions. If what you 
> > > are trying to prevent "FOO(^)" to be parsed as a block, wouldn't it be 
> > > enough to look for whether there is a "(" after the ")" or even only 
> > > after "(^)", everything else is already correct IIUC? That would get you 
> > > out of need to parse the specifics here, which will be hard.
> > > 
> > > Or thinking about it another way. Previously, every "(^" would be parsed 
> > > as an ObjC block. There seems to be only a really rare corner case in 
> > > which it isn't (macros). Thus, I'd just try to detect that corner case. 
> > > Instead you are completely inverting the defaults (defaulting to "^" is 
> > > not a block) and then try to exactly parse ObjC where there might be many 
> > > cases and edge cases that you won't even think of now.
> > Hmm. Well, it's not just `FOO(^);` that isn't a block:
> > 
> > ```
> > #define FOO(X) operator X
> > 
> > SomeType FOO(^)(int x, const SomeType& y) { ... }
> > ```
> > 
> > Obviously we can't get this perfect without a pre-processor, but it seems 
> > like our best bet is to only assign mark `TT_ObjCBlockLParen` when we are 
> > sure the syntax is a valid block type or block variable.
> I tried the suggestion to only treat `(^)(` as a block type, but it appears 
> this is the primary place where we set `TT_ObjCBlockLParen`, so I think we 
> really do need to handle the other cases here.
I don't follow your logic. I'd like you to slowly change this as opposed to 
completely going the opposite way.

So currently, the only know real-live problem is "FOO(^);". So address this 
somehow, but still default/error to recognizing too much stuff as a block.

Have you actually seen

  SomeType FOO(^)(int x, const SomeType& y) { ... }

in real code?


Repository:
  rC Clang

https://reviews.llvm.org/D43906



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


[PATCH] D44143: Create properly seeded random generator check

2018-03-06 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: docs/clang-tidy/checks/cert-properly-seeded-random-generator.rst:26
+std::random_device dev;
+std::mt19937 engine3(dev()); // Good
+  }

Seeding MT19937 with a single 32-bit integer is //not// "Good". It makes the 
seed super easy to brute-force; and for example, `engine3` will never produce 7 
or 13 as its first output.
http://www.pcg-random.org/posts/cpp-seeding-surprises.html

This doesn't affect the implementation or usefulness of this clang-tidy check, 
which is pretty nifty. I merely object to marking this sample code with the 
comment "Good" in official documentation. It should be marked "Will not warn" 
at best. Or replace it with something slightly more realistic, e.g.

int x = atoi(argv[1]);
std::mt19937 engine3(x);  // Will not warn

As Aaron said above, seeding with the current time is approximately as good an 
idea, and "will not warn" with the current diagnostic either.

The correct way to seed a PRNG is to initialize the //entire state// with 
random bits, not just 32 bits of the state. This can be done, but not yet in 
standard C++: 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0205r0.html



Comment at: test/clang-tidy/cert-properly-seeded-random-generator.cpp:76
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator must be 
seeded with a random_device instead of a constant 
[cert-properly-seeded-random-generator]
+  engine1.seed(seed);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: random number generator must be 
seeded with a random_device instead of a constant 
[cert-properly-seeded-random-generator]

Is the diagnostic suppressed if `seed` is a template parameter? (Not that I'd 
do this. It's just a corner case I thought of.)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44143



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


r326827 - [OPENMP] Fix generation of the unique names for task reduction

2018-03-06 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Mar  6 10:59:43 2018
New Revision: 326827

URL: http://llvm.org/viewvc/llvm-project?rev=326827&view=rev
Log:
[OPENMP] Fix generation of the unique names for task reduction
variables.

If the task has reduction construct and this construct for some variable
requires unique threadprivate storage, we may generate different names
for variables used in taskgroup task_reduction clause and in task
  in_reduction clause. Patch fixes this problem.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=326827&r1=326826&r2=326827&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Mar  6 10:59:43 2018
@@ -1101,11 +1101,9 @@ static Address castToBase(CodeGenFunctio
   return Address(Addr, BaseLVAlignment);
 }
 
-Address ReductionCodeGen::adjustPrivateAddress(CodeGenFunction &CGF, unsigned 
N,
-   Address PrivateAddr) {
-  const DeclRefExpr *DE;
+static const VarDecl *getBaseDecl(const Expr *Ref, const DeclRefExpr *&DE) {
   const VarDecl *OrigVD = nullptr;
-  if (auto *OASE = dyn_cast(ClausesData[N].Ref)) {
+  if (auto *OASE = dyn_cast(Ref)) {
 auto *Base = OASE->getBase()->IgnoreParenImpCasts();
 while (auto *TempOASE = dyn_cast(Base))
   Base = TempOASE->getBase()->IgnoreParenImpCasts();
@@ -1113,14 +,20 @@ Address ReductionCodeGen::adjustPrivateA
   Base = TempASE->getBase()->IgnoreParenImpCasts();
 DE = cast(Base);
 OrigVD = cast(DE->getDecl());
-  } else if (auto *ASE = dyn_cast(ClausesData[N].Ref)) {
+  } else if (auto *ASE = dyn_cast(Ref)) {
 auto *Base = ASE->getBase()->IgnoreParenImpCasts();
 while (auto *TempASE = dyn_cast(Base))
   Base = TempASE->getBase()->IgnoreParenImpCasts();
 DE = cast(Base);
 OrigVD = cast(DE->getDecl());
   }
-  if (OrigVD) {
+  return OrigVD;
+}
+
+Address ReductionCodeGen::adjustPrivateAddress(CodeGenFunction &CGF, unsigned 
N,
+   Address PrivateAddr) {
+  const DeclRefExpr *DE;
+  if (const VarDecl *OrigVD = ::getBaseDecl(ClausesData[N].Ref, DE)) {
 BaseDecls.emplace_back(OrigVD);
 auto OriginalBaseLValue = CGF.EmitLValue(DE);
 LValue BaseLValue =
@@ -5355,12 +5359,19 @@ void CGOpenMPRuntime::emitReduction(Code
 }
 
 /// Generates unique name for artificial threadprivate variables.
-/// Format is:  "."  "_" 
-static std::string generateUniqueName(StringRef Prefix, SourceLocation Loc,
-  unsigned N) {
+/// Format is:  "."  "_" ""
+static std::string generateUniqueName(CodeGenModule &CGM, StringRef Prefix,
+  const Expr *Ref) {
   SmallString<256> Buffer;
   llvm::raw_svector_ostream Out(Buffer);
-  Out << Prefix << "." << Loc.getRawEncoding() << "_" << N;
+  const clang::DeclRefExpr *DE;
+  const VarDecl *D = ::getBaseDecl(Ref, DE);
+  if (!D)
+D = cast(cast(Ref)->getDecl());
+  D = D->getCanonicalDecl();
+  Out << Prefix << "."
+  << (D->isLocalVarDeclOrParm() ? D->getName() : CGM.getMangledName(D))
+  << "_" << D->getCanonicalDecl()->getLocStart().getRawEncoding();
   return Out.str();
 }
 
@@ -5397,7 +5408,7 @@ static llvm::Value *emitReduceInitFuncti
   if (RCG.getSizes(N).second) {
 Address SizeAddr = CGM.getOpenMPRuntime().getAddrOfArtificialThreadPrivate(
 CGF, CGM.getContext().getSizeType(),
-generateUniqueName("reduction_size", Loc, N));
+generateUniqueName(CGM, "reduction_size", RCG.getRefExpr(N)));
 Size = CGF.EmitLoadOfScalar(SizeAddr, /*Volatile=*/false,
 CGM.getContext().getSizeType(), Loc);
   }
@@ -5410,7 +5421,7 @@ static llvm::Value *emitReduceInitFuncti
 Address SharedAddr =
 CGM.getOpenMPRuntime().getAddrOfArtificialThreadPrivate(
 CGF, CGM.getContext().VoidPtrTy,
-generateUniqueName("reduction", Loc, N));
+generateUniqueName(CGM, "reduction", RCG.getRefExpr(N)));
 SharedLVal = CGF.MakeAddrLValue(SharedAddr, CGM.getContext().VoidPtrTy);
   } else {
 SharedLVal = CGF.MakeNaturalAlignAddrLValue(
@@ -5466,7 +5477,7 @@ static llvm::Value *emitReduceCombFuncti
   if (RCG.getSizes(N).second) {
 Address SizeAddr = CGM.getOpenMPRuntime().getAddrOfArtificialThreadPrivate(
 CGF, CGM.getContext().getSizeType(),
-generateUniqueName("reduction_size", Loc, N));
+generateUniqueName(CGM, "reduction_size", RCG.getRefExpr(N)));
 Size = CGF.EmitLoadOfScalar(SizeAddr, /*Volatile=*/false,
 CGM.getContext().getSizeType(), Loc);
   }
@@ -5537,7 +5548,7 @@ static 

[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 137233.
gtbercea added a comment.

- Fix message and test.


Repository:
  rC Clang

https://reviews.llvm.org/D43197

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/openmp-offload-gpu.c


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,25 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60
+
+/// ###
+
+/// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
+/// bitcode library and add it to the LIBRARY_PATH.
+// RUN:   touch %T/libomptarget-nvptx-sm_60.bc
+// RUN:   env LIBRARY_PATH=%T %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_60 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB %s
+// RUN:   rm %T/libomptarget-nvptx-sm_60.bc
+
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-cuda-bitcode{{.*}}libomptarget-nvptx-sm_60.bc
+
+/// ###
+
+/// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
+/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck 
-check-prefix=CHK-BCLIB-WARN %s
+
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the 
default clang lib directory or in LIBRARY_PATH. Expect degraded performance due 
to no inlining of runtime functions on target devices.
Index: lib/Driver/ToolChains/Cuda.cpp
===
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include 
 
@@ -580,6 +581,43 @@
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+ptx42");
   }
+
+  if (DeviceOffloadingKind == Action::OFK_OpenMP) {
+SmallVector LibraryPaths;
+// Add path to lib and/or lib64 folders.
+SmallString<256> DefaultLibPath =
+  llvm::sys::path::parent_path(getDriver().Dir);
+llvm::sys::path::append(DefaultLibPath,
+Twine("lib") + CLANG_LIBDIR_SUFFIX);
+LibraryPaths.emplace_back(DefaultLibPath.c_str());
+
+// Add user defined library paths from LIBRARY_PATH.
+if (llvm::Optional LibPath =
+  llvm::sys::Process::GetEnv("LIBRARY_PATH")) {
+  SmallVector Frags;
+  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
+  llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
+  for (auto Path : Frags)
+LibraryPaths.emplace_back(Path.trim());
+}
+
+std::string LibOmpTargetName =
+  "libomptarget-nvptx-" + GpuArch.str() + ".bc";
+bool FoundBCLibrary = false;
+for (const std::string &LibraryPath : LibraryPaths) {
+  SmallString<128> LibOmpTargetFile(LibraryPath);
+  llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
+  if (llvm::sys::fs::exists(LibOmpTargetFile)) {
+CC1Args.push_back("-mlink-cuda-bitcode");
+CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
+FoundBCLibrary = true;
+break;
+  }
+}
+if (!FoundBCLibrary)
+  getDriver().Diag(diag::warn_drv_omp_offload_target_missingbcruntime)
+  << LibOmpTargetName;
+  }
 }
 
 void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -203,6 +203,9 @@
 def warn_drv_omp_offload_target_duplicate : Warning<
   "The OpenMP offloading target '%0' is similar to target '%1' already 
specified - will be ignored.">, 
   InGroup;
+def warn_drv_omp_offload_target_missingbcruntime : Warning<
+  "No library '%0' found in the default clang lib directory or in 
LIBRARY_PATH. Expect degraded performance due to no inlining of runtime 
functions on target devices.">,
+  InGroup;
 def err_drv_bitcode_unsupported_on_toolchain : Error<
   "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
 


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offlo

r326822 - TableGen: Give up on exact fixits for diagnostic groups

2018-03-06 Thread Nicolai Haehnle via cfe-commits
Author: nha
Date: Tue Mar  6 09:55:00 2018
New Revision: 326822

URL: http://llvm.org/viewvc/llvm-project?rev=326822&view=rev
Log:
TableGen: Give up on exact fixits for diagnostic groups

With recent changes in the TableGen frontend, we no longer have usable
location information for anonymous defs.

Fixes test breakage caused by r326788.

The normal, non-error TableGen output is not affected by this change.

Modified:
cfe/trunk/test/TableGen/anonymous-groups.td
cfe/trunk/test/TableGen/tg-fixits.td
cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp

Modified: cfe/trunk/test/TableGen/anonymous-groups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/TableGen/anonymous-groups.td?rev=326822&r1=326821&r2=326822&view=diff
==
--- cfe/trunk/test/TableGen/anonymous-groups.td (original)
+++ cfe/trunk/test/TableGen/anonymous-groups.td Tue Mar  6 09:55:00 2018
@@ -7,21 +7,17 @@ def NamedGroup : DiagGroup<"name">;
 
 
 def InNamedGroup : Warning<"">, InGroup>;
-//  CHECK: anonymous-groups.td:[[@LINE-1]]:41: error: group 'name' is 
referred to anonymously
+//  CHECK: anonymous-groups.td:[[@LINE-1]]:1: error: group 'name' is 
referred to anonymously
 // CHECK-NEXT: {{^def InNamedGroup : Warning<"">, InGroup>;}}
-// CHECK-NEXT: {{^\^~}}
-// CHECK-NEXT: {{^InGroup}}
-// CHECK-NEXT: anonymous-groups.td:6:1: note: group defined here
+//  CHECK: anonymous-groups.td:6:1: note: group defined here
 // CHECK-NEXT: def NamedGroup : DiagGroup<"name">;
 // CHECK-NEXT: ^
 
 
 def AlsoInNamedGroup : Warning<"">, InGroup  < DiagGroup<"name"> >;
-//  CHECK: anonymous-groups.td:[[@LINE-1]]:48: error: group 'name' is 
referred to anonymously
+//  CHECK: anonymous-groups.td:[[@LINE-1]]:1: error: group 'name' is 
referred to anonymously
 // CHECK-NEXT: {{^def AlsoInNamedGroup : Warning<"">, InGroup  < 
DiagGroup<"name"> >;}}
-// CHECK-NEXT: {{^
~~~\^~~}}
-// CHECK-NEXT: {{^InGroup}}
-// CHECK-NEXT: anonymous-groups.td:6:1: note: group defined here
+//  CHECK: anonymous-groups.td:6:1: note: group defined here
 // CHECK-NEXT: def NamedGroup : DiagGroup<"name">;
 // CHECK-NEXT: ^
 
@@ -31,12 +27,8 @@ def AlsoAnonymousGroup : Warning<"">, In
 def AnonymousGroupAgain : Warning<"">,
   InGroup>;
 
-//  CHECK: anonymous-groups.td:[[@LINE-5]]:43: error: group 'anonymous' is 
referred to anonymously
+//  CHECK: anonymous-groups.td:[[@LINE-5]]:1: error: group 'anonymous' is 
referred to anonymously
 // CHECK-NEXT: {{^def AnonymousGroup : Warning<"">, 
InGroup>;}}
-// CHECK-NEXT: {{^  
\^~~}}
-// CHECK-NEXT: anonymous-groups.td:[[@LINE-7]]:47: note: also referenced here
+//  CHECK: anonymous-groups.td:[[@LINE-6]]:1: note: also referenced here
 // CHECK-NEXT: {{^def AlsoAnonymousGroup : Warning<"">, 
InGroup>;}}
-// CHECK-NEXT: {{^  
\^~~}}
-// CHECK-NEXT: anonymous-groups.td:[[@LINE-8]]:11: note: also referenced here
-// CHECK-NEXT: {{^  InGroup>;}}
-// CHECK-NEXT: {{^  \^~~}}
+//  CHECK: anonymous-groups.td:[[@LINE-7]]:1: note: also referenced here

Modified: cfe/trunk/test/TableGen/tg-fixits.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/TableGen/tg-fixits.td?rev=326822&r1=326821&r2=326822&view=diff
==
--- cfe/trunk/test/TableGen/tg-fixits.td (original)
+++ cfe/trunk/test/TableGen/tg-fixits.td Tue Mar  6 09:55:00 2018
@@ -4,38 +4,22 @@ include "DiagnosticBase.inc"
 def NamedGroup : DiagGroup<"name">;
 
 def InNamedGroup : Warning<"">, InGroup>;
-//  CHECK: tg-fixits.td:[[@LINE-1]]:41: error: group 'name' is referred to 
anonymously
+//  CHECK: tg-fixits.td:[[@LINE-1]]:1: error: group 'name' is referred to 
anonymously
 // CHECK-NEXT: {{^def InNamedGroup : Warning<"">, InGroup>;}}
-// CHECK-NEXT: {{^\^~}}
-// CHECK-NEXT: {{^InGroup}}
 
 def Wrapped : Warning<"">, InGroup>;
-//  CHECK: tg-fixits.td:[[@LINE-2]]:36: error: group 'name' is referred to 
anonymously
+//  CHECK: tg-fixits.td:[[@LINE-2]]:1: error: group 'name' is referred to 
anonymously
 // CHECK-NEXT: {{^def Wrapped : Warning<"">, InGroup}}
 
 def AlsoWrapped : Warning<"">, InGroup<
   DiagGroup<"name">>;
-//  CHECK: tg-fixits.td:[[@LINE-1]]:3: error: group 'name' is referred to 
anonymously
-// CHECK-NEXT: {{^  DiagGroup<"name">>;}}
-// CHECK-NEXT: {{^~~\^~}}
-// CHECK-NEXT: {{^InGroup}}
-
-// The following lines contain hard tabs (\t); do not change this!
-def HardTabs : Warning<"">,
-   InGroup

[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 137230.
gtbercea added a comment.

Fix test.


Repository:
  rC Clang

https://reviews.llvm.org/D43197

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/openmp-offload-gpu.c


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,25 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60
+
+/// ###
+
+/// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
+/// bitcode library and add it to the LIBRARY_PATH.
+// RUN:   touch %T/libomptarget-nvptx-sm_60.bc
+// RUN:   env LIBRARY_PATH=%T %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_60 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB %s
+// RUN:   rm %T/libomptarget-nvptx-sm_60.bc
+
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-cuda-bitcode{{.*}}libomptarget-nvptx-sm_60.bc
+
+/// ###
+
+/// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
+/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck 
-check-prefix=CHK-BCLIB-WARN %s
+
+// CHK-BCLIB-WARN: No .bc library 'libomptarget-nvptx-sm_20.bc' found in the 
default clang lib directory or in LIBRARY_PATH. Expect degraded performance due 
to no inlining of runtime functions on target devices.
Index: lib/Driver/ToolChains/Cuda.cpp
===
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include 
 
@@ -580,6 +581,43 @@
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+ptx42");
   }
+
+  if (DeviceOffloadingKind == Action::OFK_OpenMP) {
+SmallVector LibraryPaths;
+// Add path to lib and/or lib64 folders.
+SmallString<256> DefaultLibPath =
+  llvm::sys::path::parent_path(getDriver().Dir);
+llvm::sys::path::append(DefaultLibPath,
+Twine("lib") + CLANG_LIBDIR_SUFFIX);
+LibraryPaths.emplace_back(DefaultLibPath.c_str());
+
+// Add user defined library paths from LIBRARY_PATH.
+if (llvm::Optional LibPath =
+  llvm::sys::Process::GetEnv("LIBRARY_PATH")) {
+  SmallVector Frags;
+  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
+  llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
+  for (auto Path : Frags)
+LibraryPaths.emplace_back(Path.trim());
+}
+
+std::string LibOmpTargetName =
+  "libomptarget-nvptx-" + GpuArch.str() + ".bc";
+bool FoundBCLibrary = false;
+for (const std::string &LibraryPath : LibraryPaths) {
+  SmallString<128> LibOmpTargetFile(LibraryPath);
+  llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
+  if (llvm::sys::fs::exists(LibOmpTargetFile)) {
+CC1Args.push_back("-mlink-cuda-bitcode");
+CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
+FoundBCLibrary = true;
+break;
+  }
+}
+if (!FoundBCLibrary)
+  getDriver().Diag(diag::remark_drv_omp_offload_target_missingbcruntime)
+  << LibOmpTargetName;
+  }
 }
 
 void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -203,6 +203,9 @@
 def warn_drv_omp_offload_target_duplicate : Warning<
   "The OpenMP offloading target '%0' is similar to target '%1' already 
specified - will be ignored.">, 
   InGroup;
+def remark_drv_omp_offload_target_missingbcruntime : Warning<
+  "No .bc library '%0' found in the default clang lib directory or in 
LIBRARY_PATH. Expect degraded performance due to no inlining of runtime 
functions on target devices.">,
+  InGroup;
 def err_drv_bitcode_unsupported_on_toolchain : Error<
   "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
 


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload

[PATCH] D34365: [FrontEnd] Allow overriding the default C/C++ -std via CMake vars

2018-03-06 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 137227.
mgorny added a comment.

@rnk, could you confirm the rebased patch? I'm not sure if I should override 
`InputKind::RenderScript` as well.


https://reviews.llvm.org/D34365

Files:
  CMakeLists.txt
  include/clang/Config/config.h.cmake
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1809,18 +1809,30 @@
   break;
 case InputKind::Asm:
 case InputKind::C:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   // The PS4 uses C99 as the default C standard.
   if (T.isPS4())
 LangStd = LangStandard::lang_gnu99;
   else
 LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::ObjC:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::CXX:
 case InputKind::ObjCXX:
+#if defined(CLANG_DEFAULT_STD_CXX)
+  LangStd = CLANG_DEFAULT_STD_CXX;
+#else
   LangStd = LangStandard::lang_gnucxx14;
+#endif
   break;
 case InputKind::RenderScript:
   LangStd = LangStandard::lang_c99;
Index: include/clang/Config/config.h.cmake
===
--- include/clang/Config/config.h.cmake
+++ include/clang/Config/config.h.cmake
@@ -11,6 +11,12 @@
 /* Default linker to use. */
 #define CLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}"
 
+/* Default C/ObjC standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+
+/* Default C++/ObjC++ standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
 
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -212,6 +212,12 @@
 set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
 "enable x86 relax relocations by default")
 
+# TODO: verify the values against LangStandards.def?
+set(CLANG_DEFAULT_STD_C "" CACHE STRING
+  "Default standard to use for C/ObjC code (IDENT from LangStandards.def, 
empty for platform default)")
+set(CLANG_DEFAULT_STD_CXX "" CACHE STRING
+  "Default standard to use for C++/ObjC++ code (IDENT from LangStandards.def, 
empty for platform default)")
+
 set(CLANG_DEFAULT_LINKER "" CACHE STRING
   "Default linker to use (linker name or absolute path, empty for platform 
default)")
 


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1809,18 +1809,30 @@
   break;
 case InputKind::Asm:
 case InputKind::C:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   // The PS4 uses C99 as the default C standard.
   if (T.isPS4())
 LangStd = LangStandard::lang_gnu99;
   else
 LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::ObjC:
+#if defined(CLANG_DEFAULT_STD_C)
+  LangStd = CLANG_DEFAULT_STD_C;
+#else
   LangStd = LangStandard::lang_gnu11;
+#endif
   break;
 case InputKind::CXX:
 case InputKind::ObjCXX:
+#if defined(CLANG_DEFAULT_STD_CXX)
+  LangStd = CLANG_DEFAULT_STD_CXX;
+#else
   LangStd = LangStandard::lang_gnucxx14;
+#endif
   break;
 case InputKind::RenderScript:
   LangStd = LangStandard::lang_c99;
Index: include/clang/Config/config.h.cmake
===
--- include/clang/Config/config.h.cmake
+++ include/clang/Config/config.h.cmake
@@ -11,6 +11,12 @@
 /* Default linker to use. */
 #define CLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}"
 
+/* Default C/ObjC standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_C LangStandard::lang_${CLANG_DEFAULT_STD_C}
+
+/* Default C++/ObjC++ standard to use. */
+#cmakedefine CLANG_DEFAULT_STD_CXX LangStandard::lang_${CLANG_DEFAULT_STD_CXX}
+
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
 
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -212,6 +212,12 @@
 set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
 "enable x86 relax relocations by default")
 
+# TODO: verify the values against LangStandards.def?
+set(CLANG_DEFAULT_STD_C "" CACHE STRING
+  "Default standard to use for C/ObjC code (IDENT from LangStandards.def, empty for platform default)")
+set(CLANG_DEFAULT_STD_CXX "" CACHE STRING
+  "Default standard to use for C++/ObjC++ code (IDENT from LangStandards.def, empty for platform default)")
+
 set(CLANG_DEFAULT_LINKER "" CACHE ST

[PATCH] D44142: [clangd] Revamp handling of diagnostics.

2018-03-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Behavior looks good. I think we can do a bit better with (most) fixits - your 
call on whether it makes sense to do here.

As discussed i'd simplify the diagnostic containers until we know there's a 
strong need.




Comment at: clangd/ClangdLSPServer.cpp:329
+  {"title",
+   llvm::formatv("Apply FixIt {0}", GetFixitMessage(D.message))},
   {"command", ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND},

nit: while here, can we add a colon after FixIt (or if appropriate in practice, 
just drop the prefix altogether?). My recollection is this is a bit hard to 
parse.



Comment at: clangd/Diagnostics.cpp:85
+
+bool isInsdieMainFile(const clang::Diagnostic &D) {
+  if (!D.hasSourceManager())

inside



Comment at: clangd/Diagnostics.cpp:125
+
+void printDiag(llvm::raw_string_ostream &OS, const PersistentDiag &D) {
+  if (D.InsideMainFile) {

mind pasting a small example as a function comment?
Logic looks good, but I had to reconstruct the message in my head.



Comment at: clangd/Diagnostics.cpp:147
+
+std::string presentMainMessage(const DiagWithNotes &D) {
+  std::string Result;

or just mainMessage (this is another verbs-for-pure-functions case where the 
style recommendation seems to hurt readability to me, but up to you)



Comment at: clangd/Diagnostics.cpp:192
+llvm::function_ref OutFn) {
+  auto PreBuild = [](const PersistentDiag &D) {
+DiagWithFixIts Res;

PreBuild could be FillBasicFields or something? found this name confusing.



Comment at: clangd/Diagnostics.cpp:200
+
+  DiagWithFixIts Main = PreBuild(D.main());
+  Main.Diag.message = presentMainMessage(D);

(nit: if the goal with the callback function is to avoid allocations, shouldn't 
we reuse the DiagWithFixIts?)



Comment at: clangd/Diagnostics.cpp:322
+  addToOutput(D);
+  }
+  LastDiagAndNotes.clear();

do you need else log here? (and just log the main diag)



Comment at: clangd/Diagnostics.h:28
+/// DiagList.
+struct PersistentDiag {
+  llvm::StringRef Message;

ilya-biryukov wrote:
> This could probably use a better name
I found it a bit confusing that this represents both "top-level" diagnostics 
and notes. It obscures the nature of the hierarchy a bit: there *are* a fixed 
number of levels with different "kinds", but the kinds are similar enough to 
share a type.

I'd actually consider using inheritance here to model the relationships more 
clearly. (Yes, gross, I know)
Like:

  struct DiagBase { Message, File, Range, InMainFile }
  struct Diag : DiagBase { FixIts, Notes, Severity }
  struct Note : DiagBase {} // or leave this one out until needed

(I think we came to the conclusion that different severity of notes isn't 
interesting and potentially just confusing)



Comment at: clangd/Diagnostics.h:35
+  DiagnosticsEngine::Level Severity;
+  llvm::SmallVector FixIts;
+  // Since File is only descriptive, we store a separate flag to distinguish

As discussed offline - I think fixits should probably be a different struct 
hanging off the main diagnostic, with a name. Following clang's example 
seems... less than clear here.

They could also be modeled as notes with an optional TextEdit - this seems 
sligthly less clear but more faithful to clang internals*.
Either way, it should be clear that they're only allowed in *one* of these 
locations - having notes and main diags be distinct types would help.

I think this probably affects how we should expose them through LSP - they 
should be named code actions attached to the original diagnostic.
Maybe they should also be separate diagnostics, but only if they contribute a 
unique opportunity to the user e.g. they have a non-empty range that isn't 
contained within the diagnostic's range.
This patch seems like a reasonable place to do that, but also OK if you want to 
defer.



Comment at: clangd/Diagnostics.h:35
+  DiagnosticsEngine::Level Severity;
+  llvm::SmallVector FixIts;
+  // Since File is only descriptive, we store a separate flag to distinguish

sammccall wrote:
> As discussed offline - I think fixits should probably be a different struct 
> hanging off the main diagnostic, with a name. Following clang's example 
> seems... less than clear here.
> 
> They could also be modeled as notes with an optional TextEdit - this seems 
> sligthly less clear but more faithful to clang internals*.
> Either way, it should be clear that they're only allowed in *one* of these 
> locations - having notes and main diags be distinct types would help.
> 
> I think this probably affects how we should expose them through LSP - they 
> should be named code actions attached to the original diagnostic.
> Maybe they 

[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 137226.
gtbercea added a comment.

Address comments.


Repository:
  rC Clang

https://reviews.llvm.org/D43197

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/openmp-offload-gpu.c


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,25 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60
+
+/// ###
+
+/// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
+/// bitcode library and add it to the LIBRARY_PATH.
+// RUN:   touch %T/libomptarget-nvptx-sm_60.bc
+// RUN:   env LIBRARY_PATH=%T %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_60 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB %s
+// RUN:   rm %T/libomptarget-nvptx-sm_60.bc
+
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-cuda-bitcode{{.*}}libomptarget-nvptx-sm_60.bc
+
+/// ###
+
+/// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
+/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck 
-check-prefix=CHK-BCLIB-WARN %s
+
+// CHK-BCLIB-WARN: Expect degraded performance on the target device due to 
missing 'libomptarget-nvptx-sm_20.bc' in LIBRARY_PATH.
Index: lib/Driver/ToolChains/Cuda.cpp
===
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include 
 
@@ -580,6 +581,43 @@
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+ptx42");
   }
+
+  if (DeviceOffloadingKind == Action::OFK_OpenMP) {
+SmallVector LibraryPaths;
+// Add path to lib and/or lib64 folders.
+SmallString<256> DefaultLibPath =
+  llvm::sys::path::parent_path(getDriver().Dir);
+llvm::sys::path::append(DefaultLibPath,
+Twine("lib") + CLANG_LIBDIR_SUFFIX);
+LibraryPaths.emplace_back(DefaultLibPath.c_str());
+
+// Add user defined library paths from LIBRARY_PATH.
+if (llvm::Optional LibPath =
+  llvm::sys::Process::GetEnv("LIBRARY_PATH")) {
+  SmallVector Frags;
+  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
+  llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
+  for (auto Path : Frags)
+LibraryPaths.emplace_back(Path.trim());
+}
+
+std::string LibOmpTargetName =
+  "libomptarget-nvptx-" + GpuArch.str() + ".bc";
+bool FoundBCLibrary = false;
+for (const std::string &LibraryPath : LibraryPaths) {
+  SmallString<128> LibOmpTargetFile(LibraryPath);
+  llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
+  if (llvm::sys::fs::exists(LibOmpTargetFile)) {
+CC1Args.push_back("-mlink-cuda-bitcode");
+CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
+FoundBCLibrary = true;
+break;
+  }
+}
+if (!FoundBCLibrary)
+  getDriver().Diag(diag::remark_drv_omp_offload_target_missingbcruntime)
+  << LibOmpTargetName;
+  }
 }
 
 void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -203,6 +203,9 @@
 def warn_drv_omp_offload_target_duplicate : Warning<
   "The OpenMP offloading target '%0' is similar to target '%1' already 
specified - will be ignored.">, 
   InGroup;
+def remark_drv_omp_offload_target_missingbcruntime : Warning<
+  "No .bc library found in the default clang lib directory or in LIBRARY_PATH. 
Expect degraded performance due to no inlining of runtime functions on target 
devices.">,
+  InGroup;
 def err_drv_bitcode_unsupported_on_toolchain : Error<
   "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
 


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,25 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE

[PATCH] D34365: [FrontEnd] Allow overriding the default C/C++ -std via CMake vars

2018-03-06 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

Let's do this. I thought we'd already have a higher C++ standard version by 
now, but apparently not.


https://reviews.llvm.org/D34365



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-03-06 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D41102#1028228, @Athosvk wrote:

> This seems like quite a decent approach! That being said, I don't see the 
> pointer yet? I assume you mean that you will be adding this? Additionally, a 
> slight disadvantage of doing this generic approach is that you need to do 
> bookkeeping on what it is referencing, but I guess there's no helping that 
> due to the architecture which makes you rely upon the USR? Personally I'd 
> prefer having the explicit types if and where possible. So for now a 
> RecordInfo has a vecotr of Reference's to its parents, but we know the 
> parents can only be of certain kinds (more than just a RecordType, but you 
> get the point); it won't be an enum, namespace or function.


If you take a look at the follow-on patch to this (D43341 
), you'll see that that is where the pointer 
is added in (since it is irrelevant to the mapper portion, as it cannot be 
filled out until the information has been reduced). The back references to 
children and whatnot are also added there.

> As I mentioned, we did this the other way around, which also has the slight 
> advantage that I only had to create and save the USR once per info instance 
> (as in, 10 references to a class only add the overhead of 10 pointers, rather 
> than each having the USR as well), but our disadvantage was of course that we 
> had delayed serialization (although we could arguably do both 
> simultaneously). It seems each method has its merits :).

The USRs are kept for serialization purposes -- given the modular nature of the 
design, the goal is to be able to write out the bitstream and have it be 
consumable with all necessary information. Since we can't write out pointers 
(and it would be useless if we did, since they would change as soon as the file 
was read in), we maintain the USRs to have a means of re-finding the referenced 
declaration.

That said, I was looking at the Clangd symbol indexing code yesterday, and 
noticed that they're hashing the USRs (since they get a little lengthy, 
particularly when you have nested and/or overloaded functions). I'm going to 
take a look at that today to try to make the USRs more space-efficient here.


https://reviews.llvm.org/D41102



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


[libclc] r326821 - lgamma_r: Move code from .inc to .cl file

2018-03-06 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Tue Mar  6 09:48:47 2018
New Revision: 326821

URL: http://llvm.org/viewvc/llvm-project?rev=326821&view=rev
Log:
lgamma_r: Move code from .inc to .cl file

Reviewed-by: Aaron Watry 
Signed-off-by: Jan Vesely 

Modified:
libclc/trunk/generic/lib/math/lgamma_r.cl
libclc/trunk/generic/lib/math/lgamma_r.inc

Modified: libclc/trunk/generic/lib/math/lgamma_r.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/lgamma_r.cl?rev=326821&r1=326820&r2=326821&view=diff
==
--- libclc/trunk/generic/lib/math/lgamma_r.cl (original)
+++ libclc/trunk/generic/lib/math/lgamma_r.cl Tue Mar  6 09:48:47 2018
@@ -1,7 +1,498 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ * Copyright (c) 2016 Aaron Watry 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
 #include 
 
 #include "../clcmacro.h"
 #include "math.h"
 
+/*
+ * 
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * 
+ */
+
+#define pi_f   3.1415927410e+00f/* 0x40490fdb */
+
+#define a0_f   7.7215664089e-02f/* 0x3d9e233f */
+#define a1_f   3.2246702909e-01f/* 0x3ea51a66 */
+#define a2_f   6.7352302372e-02f/* 0x3d89f001 */
+#define a3_f   2.0580807701e-02f/* 0x3ca89915 */
+#define a4_f   7.3855509982e-03f/* 0x3bf2027e */
+#define a5_f   2.8905137442e-03f/* 0x3b3d6ec6 */
+#define a6_f   1.1927076848e-03f/* 0x3a9c54a1 */
+#define a7_f   5.1006977446e-04f/* 0x3a05b634 */
+#define a8_f   2.2086278477e-04f/* 0x39679767 */
+#define a9_f   1.0801156895e-04f/* 0x38e28445 */
+#define a10_f  2.5214456400e-05f/* 0x37d383a2 */
+#define a11_f  4.4864096708e-05f/* 0x383c2c75 */
+
+#define tc_f   1.4616321325e+00f/* 0x3fbb16c3 */
+
+#define tf_f  -1.2148628384e-01f/* 0xbdf8cdcd */
+/* tt -(tail of tf) */
+#define tt_f   6.6971006518e-09f/* 0x31e61c52 */
+
+#define t0_f   4.8383611441e-01f/* 0x3ef7b95e */
+#define t1_f  -1.4758771658e-01f/* 0xbe17213c */
+#define t2_f   6.4624942839e-02f/* 0x3d845a15 */
+#define t3_f  -3.2788541168e-02f/* 0xbd064d47 */
+#define t4_f   1.7970675603e-02f/* 0x3c93373d */
+#define t5_f  -1.0314224288e-02f/* 0xbc28fcfe */
+#define t6_f   6.1005386524e-03f/* 0x3bc7e707 */
+#define t7_f  -3.6845202558e-03f/* 0xbb7177fe */
+#define t8_f   2.2596477065e-03f/* 0x3b141699 */
+#define t9_f  -1.4034647029e-03f/* 0xbab7f476 */
+#define t10_f  8.8108185446e-04f/* 0x3a66f867 */
+#define t11_f -5.3859531181e-04f/* 0xba0d3085 */
+#define t12_f  3.1563205994e-04f/* 0x39a57b6b */
+#define t13_f -3.1275415677e-04f/* 0xb9a3f927 */
+#define t14_f  3.3552918467e-04f/* 0x39afe9f7 */
+
+#define u0_f  -7.7215664089e-02f/* 0xbd9e233f */
+#define u1_f   6.3282704353e-01f/* 0x3f2200f4 */
+#define u2_f   1.4549225569e+00f/* 0x3fba3ae7 */
+#define u3_f   9.7771751881e-01f/* 0x3f7a4bb2 */
+#define u4_f   2.2896373272e-01f/* 0x3e6a7578 */
+#define u5_f   1.3381091878e-02f/* 0x3c5b3c5e */
+
+#define v1_f   2.4559779167e+00f/* 0x401d2ebe */
+#define v2_f   2.1284897327e+00f/* 0x4008392d */
+#define v3_f   7.6928514242e-01f/* 0x3f44efdf */
+#define v4_f   1.0422264785e-01f/* 0x3dd572af */
+#define v5_f   3.2170924824e-03f/* 0x3b52d5db */
+
+#define s0_f  -7.7215664089e-02f/* 0xbd9e233f */
+#define s1_f   2.1498242021e-01f/* 0x3e5c245a */
+#define s2_f   3.2577878

[libclc] r326820 - frexp: Reuse types provided by gentype.inc

2018-03-06 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Tue Mar  6 09:48:45 2018
New Revision: 326820

URL: http://llvm.org/viewvc/llvm-project?rev=326820&view=rev
Log:
frexp: Reuse types provided by gentype.inc

v2: Use select instead of bitselect to consolidate scalar and vector
versions

Passes CTS on Carrizo

Reviewed-by: Aaron Watry 
Signed-off-by: Jan Vesely 

Modified:
libclc/trunk/generic/lib/math/frexp.cl
libclc/trunk/generic/lib/math/frexp.inc

Modified: libclc/trunk/generic/lib/math/frexp.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/frexp.cl?rev=326820&r1=326819&r2=326820&view=diff
==
--- libclc/trunk/generic/lib/math/frexp.cl (original)
+++ libclc/trunk/generic/lib/math/frexp.cl Tue Mar  6 09:48:45 2018
@@ -1,6 +1,17 @@
 #include 
+#include 
 
-#include "math.h"
+#define __CLC_BODY 
+#define __CLC_ADDRESS_SPACE private
+#include 
+#undef __CLC_ADDRESS_SPACE
+
+#define __CLC_BODY 
+#define __CLC_ADDRESS_SPACE global
+#include 
+#undef __CLC_ADDRESS_SPACE
 
 #define __CLC_BODY 
+#define __CLC_ADDRESS_SPACE local
 #include 
+#undef __CLC_ADDRESS_SPACE

Modified: libclc/trunk/generic/lib/math/frexp.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/frexp.inc?rev=326820&r1=326819&r2=326820&view=diff
==
--- libclc/trunk/generic/lib/math/frexp.inc (original)
+++ libclc/trunk/generic/lib/math/frexp.inc Tue Mar  6 09:48:45 2018
@@ -20,91 +20,55 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+
+#define __CLC_AS_GENTYPE __CLC_XCONCAT(as_, __CLC_GENTYPE)
+#define __CLC_AS_INTN __CLC_XCONCAT(as_, __CLC_INTN)
+
 #if __CLC_FPSIZE == 32
-#ifdef __CLC_SCALAR
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE frexp(float x, private int *ep) {
-int i = as_int(x);
-int ai = i & 0x7fff;
-int d = ai > 0 & ai < 0x0080;
-// scale subnormal by 2^26 without multiplying
-float s = as_float(ai | 0x0d80) - 0x1.0p-100F;
-ai = d ? as_int(s) : ai;
-int e = (ai >> 23) - 126 - (d ? 26 : 0);
-int t = ai == 0 | e == 129;
-i = (i & 0x8000) | 0x3f00 | (ai & 0x007f);
-*ep = t ? 0 : e;
-return t ? x : as_float(i);
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE frexp(__CLC_GENTYPE x, 
__CLC_ADDRESS_SPACE __CLC_INTN *ep) {
+__CLC_INTN i = __CLC_AS_INTN(x);
+__CLC_INTN ai = i & 0x7fff;
+__CLC_INTN d = ai > 0 & ai < 0x0080;
+/* scale subnormal by 2^26 without multiplying */
+__CLC_GENTYPE s = __CLC_AS_GENTYPE(ai | 0x0d80) - 0x1.0p-100f;
+ai = select(ai, __CLC_AS_INTN(s), d);
+__CLC_INTN e = (ai >> 23) - 126 - select((__CLC_INTN)0, (__CLC_INTN)26, d);
+__CLC_INTN t = ai == (__CLC_INTN)0 | e == (__CLC_INTN)129;
+i = (i & (__CLC_INTN)0x8000) | (__CLC_INTN)0x3f00 | (ai & 
0x007f);
+*ep = select(e, (__CLC_INTN)0, t);
+return select(__CLC_AS_GENTYPE(i), x, t);
 }
-#define __CLC_FREXP_VEC(width) \
-_CLC_OVERLOAD _CLC_DEF float##width frexp(float##width x, private int##width 
*ep) { \
-int##width i = as_int##width(x); \
-int##width ai = i & 0x7fff; \
-int##width d = ai > 0 & ai < 0x0080; \
-/* scale subnormal by 2^26 without multiplying */ \
-float##width s = as_float##width(ai | 0x0d80) - 0x1.0p-100F; \
-ai = bitselect(ai, as_int##width(s), d); \
-int##width e = (ai >> 23) - 126 - bitselect((int##width)0, (int##width)26, 
d); \
-int##width t = ai == (int##width)0 | e == (int##width)129; \
-i = (i & (int##width)0x8000) | (int##width)0x3f00 | (ai & 
0x007f); \
-*ep = bitselect(e, (int##width)0, t); \
-return bitselect(as_float##width(i), x, as_float##width(t)); \
-}
-__CLC_FREXP_VEC(2)
-__CLC_FREXP_VEC(3)
-__CLC_FREXP_VEC(4)
-__CLC_FREXP_VEC(8)
-__CLC_FREXP_VEC(16)
-#undef __CLC_FREXP_VEC
-#endif
 #endif
 
 #if __CLC_FPSIZE == 64
 #ifdef __CLC_SCALAR
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE frexp(__CLC_GENTYPE x, private __CLC_INTN 
*ep) {
-long i = as_long(x);
-long ai = i & 0x7fffL;
-int d = ai > 0 & ai < 0x0010L;
-// scale subnormal by 2^54 without multiplying
-double s = as_double(ai | 0x0370L) - 0x1.0p-968;
-ai = d ? as_long(s) : ai;
-int e = (int)(ai >> 52) - 1022 - (d ? 54 : 0);
-int t = ai == 0 | e == 1025;
-i = (i & 0x8000L) | 0x3fe0L | (ai & 
0x000fL);
-*ep = t ? 0 : e;
-return t ? x : as_double(i);
-}
-#define __CLC_FREXP_VEC(width) \
-_CLC_OVERLOAD _CLC_DEF double##width frexp(double##width x, private int##width 
*ep) { \
-long##width i = as_long##width(x); \
-long##width ai = i & 0x7fffL; \
-long##width d = ai > 0 & ai < 0x0010L; \
-/* scale subnormal by 2^54 without multiplying */ \
-double##width s = as_double##width(ai | 0x0370L) - 0x1.0p-968; 
\
-a

[libclc] r326819 - select: Add vector implementation

2018-03-06 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Tue Mar  6 09:48:43 2018
New Revision: 326819

URL: http://llvm.org/viewvc/llvm-project?rev=326819&view=rev
Log:
select: Add vector implementation

Passes CTS on Carrizo

Reviewed-by: Aaron Watry 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/relational/select.inc
libclc/trunk/generic/lib/relational/select.cl
libclc/trunk/generic/lib/relational/select.inc
Modified:
libclc/trunk/generic/include/clc/relational/select.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/relational/select.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/relational/select.h?rev=326819&r1=326818&r2=326819&view=diff
==
--- libclc/trunk/generic/include/clc/relational/select.h (original)
+++ libclc/trunk/generic/include/clc/relational/select.h Tue Mar  6 09:48:43 
2018
@@ -1 +1,11 @@
-#define select(a, b, c) ((c) ? (b) : (a))
+/* Duplciate these so we don't have to distribute utils.h */
+#define __CLC_CONCAT(x, y) x ## y
+#define __CLC_XCONCAT(x, y) __CLC_CONCAT(x, y)
+
+#define __CLC_BODY 
+#include 
+#define __CLC_BODY 
+#include 
+
+#undef __CLC_CONCAT
+#undef __CLC_XCONCAT

Added: libclc/trunk/generic/include/clc/relational/select.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/relational/select.inc?rev=326819&view=auto
==
--- libclc/trunk/generic/include/clc/relational/select.inc (added)
+++ libclc/trunk/generic/include/clc/relational/select.inc Tue Mar  6 09:48:43 
2018
@@ -0,0 +1,25 @@
+#ifdef __CLC_SCALAR
+#define __CLC_VECSIZE
+#endif
+
+#if __CLC_FPSIZE == 64
+#define __CLC_S_GENTYPE __CLC_XCONCAT(long, __CLC_VECSIZE)
+#define __CLC_U_GENTYPE __CLC_XCONCAT(ulong, __CLC_VECSIZE)
+#elif __CLC_FPSIZE == 32
+#define __CLC_S_GENTYPE __CLC_XCONCAT(int, __CLC_VECSIZE)
+#define __CLC_U_GENTYPE __CLC_XCONCAT(uint, __CLC_VECSIZE)
+#elif __CLC_FPSIZE == 16
+#define __CLC_S_GENTYPE __CLC_XCONCAT(char, __CLC_VECSIZE)
+#define __CLC_U_GENTYPE __CLC_XCONCAT(uchar, __CLC_VECSIZE)
+#endif
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE select(__CLC_GENTYPE x, __CLC_GENTYPE y, 
__CLC_S_GENTYPE z);
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE select(__CLC_GENTYPE x, __CLC_GENTYPE y, 
__CLC_U_GENTYPE z);
+
+#ifdef __CLC_FPSIZE
+#undef __CLC_S_GENTYPE
+#undef __CLC_U_GENTYPE
+#endif
+#ifdef __CLC_SCALAR
+#undef __CLC_VECSIZE
+#endif

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=326819&r1=326818&r2=326819&view=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Tue Mar  6 09:48:43 2018
@@ -189,6 +189,7 @@ relational/isnormal.cl
 relational/isnotequal.cl
 relational/isordered.cl
 relational/isunordered.cl
+relational/select.cl
 relational/signbit.cl
 shared/clamp.cl
 shared/max.cl

Added: libclc/trunk/generic/lib/relational/select.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/select.cl?rev=326819&view=auto
==
--- libclc/trunk/generic/lib/relational/select.cl (added)
+++ libclc/trunk/generic/lib/relational/select.cl Tue Mar  6 09:48:43 2018
@@ -0,0 +1,7 @@
+#include 
+#include 
+
+#define __CLC_BODY 
+#include 
+#define __CLC_BODY 
+#include 

Added: libclc/trunk/generic/lib/relational/select.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/select.inc?rev=326819&view=auto
==
--- libclc/trunk/generic/lib/relational/select.inc (added)
+++ libclc/trunk/generic/lib/relational/select.inc Tue Mar  6 09:48:43 2018
@@ -0,0 +1,47 @@
+#ifdef __CLC_SCALAR
+#define __CLC_VECSIZE
+#endif
+
+#if __CLC_FPSIZE == 64
+#define __CLC_S_GENTYPE __CLC_XCONCAT(long, __CLC_VECSIZE)
+#define __CLC_U_GENTYPE __CLC_XCONCAT(ulong, __CLC_VECSIZE)
+#elif __CLC_FPSIZE == 32
+#define __CLC_S_GENTYPE __CLC_XCONCAT(int, __CLC_VECSIZE)
+#define __CLC_U_GENTYPE __CLC_XCONCAT(uint, __CLC_VECSIZE)
+#elif __CLC_FPSIZE == 16
+#define __CLC_S_GENTYPE __CLC_XCONCAT(char, __CLC_VECSIZE)
+#define __CLC_U_GENTYPE __CLC_XCONCAT(uchar, __CLC_VECSIZE)
+#endif
+#ifdef __CLC_FPSIZE
+#define __CLC_GENSIZE   __CLC_FPSIZE
+#endif
+
+#define __CLC_AS_S_GENTYPE __CLC_XCONCAT(as_, __CLC_S_GENTYPE)
+#define __CLC_AS_GENTYPE __CLC_XCONCAT(as_, __CLC_GENTYPE)
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE select(__CLC_GENTYPE x, __CLC_GENTYPE y, 
__CLC_S_GENTYPE z)
+{
+#ifdef __CLC_SCALAR
+   return z ? y : x;
+#else
+   __CLC_S_GENTYPE bitmask = z >> (__CLC_GENSIZE - 1);
+   return __CLC_AS_GENTYPE(bitselect(__CLC_AS_S_GENTYPE(x), 
__CLC_AS_S_GENTYPE(y), bitmask));
+#endif
+}
+
+_CLC_OVERLOAD _CLC_DEF __CLC_

[libclc] r326818 - minmag: Condition variable needs to be the same bitwidth as operands

2018-03-06 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Tue Mar  6 09:48:40 2018
New Revision: 326818

URL: http://llvm.org/viewvc/llvm-project?rev=326818&view=rev
Log:
minmag: Condition variable needs to be the same bitwidth as operands

No changes wrt CTS

Reviewed-by: Aaron Watry 
Signed-off-by: Jan Vesely 

Modified:
libclc/trunk/generic/lib/math/minmag.cl
libclc/trunk/generic/lib/math/minmag.inc

Modified: libclc/trunk/generic/lib/math/minmag.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/minmag.cl?rev=326818&r1=326817&r2=326818&view=diff
==
--- libclc/trunk/generic/lib/math/minmag.cl (original)
+++ libclc/trunk/generic/lib/math/minmag.cl Tue Mar  6 09:48:40 2018
@@ -1,4 +1,5 @@
 #include 
+#include 
 
 #define __CLC_BODY 
 #include 

Modified: libclc/trunk/generic/lib/math/minmag.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/minmag.inc?rev=326818&r1=326817&r2=326818&view=diff
==
--- libclc/trunk/generic/lib/math/minmag.inc (original)
+++ libclc/trunk/generic/lib/math/minmag.inc Tue Mar  6 09:48:40 2018
@@ -1,4 +1,22 @@
+#ifdef __CLC_SCALAR
+#define __CLC_VECSIZE
+#endif
+
+#if __CLC_FPSIZE == 64
+#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_long, __CLC_VECSIZE)
+#elif __CLC_FPSIZE == 32
+#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_int, __CLC_VECSIZE)
+#elif __CLC_FPSIZE == 16
+#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_short, __CLC_VECSIZE)
+#endif
+
 _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE minmag(__CLC_GENTYPE x, __CLC_GENTYPE y) {
-  const __CLC_GENTYPE res = select(y, x, isless(fabs(x), fabs(y)));
-  return select(res, fmin(x, y), isnan(x) | isnan(y) | isequal(fabs(x), 
fabs(y)));
+  const __CLC_GENTYPE res = select(y, x, __CLC_CONVERT_NATN(isless(fabs(x), 
fabs(y;
+  return select(res, fmin(x, y), __CLC_CONVERT_NATN(isnan(x) | isnan(y) | 
isequal(fabs(x), fabs(y;
 }
+
+#undef __CLC_CONVERT_NATN
+
+#ifdef __CLC_SCALAR
+#undef __CLC_VECSIZE
+#endif


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


[libclc] r326817 - maxmag: Condition variable needs to be the same bitwidth as operands

2018-03-06 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Tue Mar  6 09:48:38 2018
New Revision: 326817

URL: http://llvm.org/viewvc/llvm-project?rev=326817&view=rev
Log:
maxmag: Condition variable needs to be the same bitwidth as operands

No changes wrt CTS

Reviewed-by: Aaron Watry 
Signed-off-by: Jan Vesely 

Modified:
libclc/trunk/generic/lib/math/maxmag.cl
libclc/trunk/generic/lib/math/maxmag.inc

Modified: libclc/trunk/generic/lib/math/maxmag.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/maxmag.cl?rev=326817&r1=326816&r2=326817&view=diff
==
--- libclc/trunk/generic/lib/math/maxmag.cl (original)
+++ libclc/trunk/generic/lib/math/maxmag.cl Tue Mar  6 09:48:38 2018
@@ -1,4 +1,5 @@
 #include 
+#include 
 
 #define __CLC_BODY 
 #include 

Modified: libclc/trunk/generic/lib/math/maxmag.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/maxmag.inc?rev=326817&r1=326816&r2=326817&view=diff
==
--- libclc/trunk/generic/lib/math/maxmag.inc (original)
+++ libclc/trunk/generic/lib/math/maxmag.inc Tue Mar  6 09:48:38 2018
@@ -1,4 +1,22 @@
+#ifdef __CLC_SCALAR
+#define __CLC_VECSIZE
+#endif
+
+#if __CLC_FPSIZE == 64
+#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_long, __CLC_VECSIZE)
+#elif __CLC_FPSIZE == 32
+#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_int, __CLC_VECSIZE)
+#elif __CLC_FPSIZE == 16
+#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_short, __CLC_VECSIZE)
+#endif
+
 _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE maxmag(__CLC_GENTYPE x, __CLC_GENTYPE y) {
-  const __CLC_GENTYPE res = select(y, x, isgreater(fabs(x), fabs(y)));
-  return select(res, fmax(x, y), isnan(x) | isnan(y) | isequal(fabs(x), 
fabs(y)));
+  const __CLC_GENTYPE res = select(y, x, __CLC_CONVERT_NATN(isgreater(fabs(x), 
fabs(y;
+  return select(res, fmax(x, y), __CLC_CONVERT_NATN(isnan(x) | isnan(y) | 
isequal(fabs(x), fabs(y;
 }
+
+#undef __CLC_CONVERT_NATN
+
+#ifdef __CLC_SCALAR
+#undef __CLC_VECSIZE
+#endif


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


[libclc] r326816 - Move cl_khr_fp64 exntension enablement to gentype include lists

2018-03-06 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Tue Mar  6 09:48:35 2018
New Revision: 326816

URL: http://llvm.org/viewvc/llvm-project?rev=326816&view=rev
Log:
Move cl_khr_fp64 exntension enablement to gentype include lists

This will make adding cl_khr_fp16 support easier

Reviewed-by: Aaron Watry 
Signed-off-by: Jan Vesely 

Modified:
libclc/trunk/generic/include/clc/async/gentype.inc
libclc/trunk/generic/include/clc/geometric/floatn.inc
libclc/trunk/generic/include/clc/math/binary_intrin.inc
libclc/trunk/generic/include/clc/math/ternary_intrin.inc
libclc/trunk/generic/include/clc/math/unary_intrin.inc
libclc/trunk/generic/lib/async/async_work_group_copy.cl
libclc/trunk/generic/lib/async/async_work_group_strided_copy.cl
libclc/trunk/generic/lib/async/prefetch.cl
libclc/trunk/generic/lib/common/mix.cl
libclc/trunk/generic/lib/geometric/distance.cl
libclc/trunk/generic/lib/math/acos.cl
libclc/trunk/generic/lib/math/asin.cl
libclc/trunk/generic/lib/math/clc_sqrt.cl
libclc/trunk/generic/lib/math/exp10.cl
libclc/trunk/generic/lib/math/fdim.cl
libclc/trunk/generic/lib/math/fract.cl
libclc/trunk/generic/lib/math/frexp.cl
libclc/trunk/generic/lib/math/hypot.cl
libclc/trunk/generic/lib/math/lgamma_r.cl
libclc/trunk/generic/lib/math/log10.cl
libclc/trunk/generic/lib/math/mad.cl
libclc/trunk/generic/lib/math/modf.cl
libclc/trunk/generic/lib/math/sincos.cl
libclc/trunk/generic/lib/shared/clamp.cl
libclc/trunk/generic/lib/shared/max.cl
libclc/trunk/generic/lib/shared/min.cl

Modified: libclc/trunk/generic/include/clc/async/gentype.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/async/gentype.inc?rev=326816&r1=326815&r2=326816&view=diff
==
--- libclc/trunk/generic/include/clc/async/gentype.inc (original)
+++ libclc/trunk/generic/include/clc/async/gentype.inc Tue Mar  6 09:48:35 2018
@@ -180,6 +180,7 @@
 #undef __CLC_GENTYPE
 
 #ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
 #define __CLC_GENTYPE double
 #include __CLC_BODY
@@ -202,3 +203,5 @@
 #undef __CLC_GENTYPE
 
 #endif
+
+#undef __CLC_BODY

Modified: libclc/trunk/generic/include/clc/geometric/floatn.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/geometric/floatn.inc?rev=326816&r1=326815&r2=326816&view=diff
==
--- libclc/trunk/generic/include/clc/geometric/floatn.inc (original)
+++ libclc/trunk/generic/include/clc/geometric/floatn.inc Tue Mar  6 09:48:35 
2018
@@ -24,6 +24,7 @@
 
 #ifndef __FLOAT_ONLY
 #ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 
 #define __CLC_FLOAT double
 #define __CLC_FPSIZE 64

Modified: libclc/trunk/generic/include/clc/math/binary_intrin.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/binary_intrin.inc?rev=326816&r1=326815&r2=326816&view=diff
==
--- libclc/trunk/generic/include/clc/math/binary_intrin.inc (original)
+++ libclc/trunk/generic/include/clc/math/binary_intrin.inc Tue Mar  6 09:48:35 
2018
@@ -6,6 +6,7 @@ _CLC_OVERLOAD float8 __CLC_FUNCTION(floa
 _CLC_OVERLOAD float16 __CLC_FUNCTION(float16, float16) __asm(__CLC_INTRINSIC 
".v16f32");
 
 #ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 _CLC_OVERLOAD double __CLC_FUNCTION(double, double) __asm(__CLC_INTRINSIC 
".f64");
 _CLC_OVERLOAD double2 __CLC_FUNCTION(double2, double2) __asm(__CLC_INTRINSIC 
".v2f64");
 _CLC_OVERLOAD double3 __CLC_FUNCTION(double3, double3) __asm(__CLC_INTRINSIC 
".v3f64");

Modified: libclc/trunk/generic/include/clc/math/ternary_intrin.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/ternary_intrin.inc?rev=326816&r1=326815&r2=326816&view=diff
==
--- libclc/trunk/generic/include/clc/math/ternary_intrin.inc (original)
+++ libclc/trunk/generic/include/clc/math/ternary_intrin.inc Tue Mar  6 
09:48:35 2018
@@ -6,6 +6,7 @@ _CLC_OVERLOAD float8 __CLC_FUNCTION(floa
 _CLC_OVERLOAD float16 __CLC_FUNCTION(float16, float16, float16) 
__asm(__CLC_INTRINSIC ".v16f32");
 
 #ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 _CLC_OVERLOAD double __CLC_FUNCTION(double, double, double) 
__asm(__CLC_INTRINSIC ".f64");
 _CLC_OVERLOAD double2 __CLC_FUNCTION(double2, double2, double2) 
__asm(__CLC_INTRINSIC ".v2f64");
 _CLC_OVERLOAD double3 __CLC_FUNCTION(double3, double3, double3) 
__asm(__CLC_INTRINSIC ".v3f64");

Modified: libclc/trunk/generic/include/clc/math/unary_intrin.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/unary_intrin.inc?rev=326816&r1=326815&r2=326816&view=diff
==
--- li

[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-06 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: include/clang/Basic/DiagnosticDriverKinds.td:207-208
+def remark_drv_omp_offload_target_missingbcruntime : Warning<
+  "Expect degraded performance on the target device due to missing '%0' in 
LIBRARY_PATH.">,
+  InGroup;
 def err_drv_bitcode_unsupported_on_toolchain : Error<

Fix the message in the warning, it does not follow the logic of the patch



Comment at: lib/Driver/ToolChains/Cuda.cpp:586
+  if (DeviceOffloadingKind == Action::OFK_OpenMP) {
+SmallVector LibraryPaths;
+// Add path to lib and/or lib64 folders.

Do you really need `std::string` here? Or StringRef is enough?


Repository:
  rC Clang

https://reviews.llvm.org/D43197



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


[PATCH] D43783: [OpenCL] Remove block invoke function from emitted block literal struct

2018-03-06 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:1065-1067
+  llvm::Value *FuncPtr;
 
+  if (!CGM.getLangOpts().OpenCL) {

bader wrote:
> I think it would be more readable if we merge this if statement with the if 
> statement at the line #1103.
> It's used to initialize FuncPtr for non-OpenCL languages and the first use of 
> this variable is in the else block of if statement at the line #1103.
> If I didn't miss something it should reasonable to combine this if block with 
> 'else' block at the line #1106.
BlockPtr is used on line 1093, so it cannot be moved to line 1106.


https://reviews.llvm.org/D43783



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


[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-06 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 137219.
gtbercea added a comment.

Address comments.


Repository:
  rC Clang

https://reviews.llvm.org/D43197

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/openmp-offload-gpu.c


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,25 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60
+
+/// ###
+
+/// Check that the runtime bitcode library is part of the compile line. Create 
a bogus
+/// bitcode library and add it to the LIBRARY_PATH.
+// RUN:   touch %T/libomptarget-nvptx-sm_60.bc
+// RUN:   env LIBRARY_PATH=%T %clang -### -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_60 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck -check-prefix=CHK-BCLIB %s
+// RUN:   rm %T/libomptarget-nvptx-sm_60.bc
+
+// CHK-BCLIB: 
clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-cuda-bitcode{{.*}}libomptarget-nvptx-sm_60.bc
+
+/// ###
+
+/// Check that the warning is thrown when the libomptarget bitcode library is 
not found.
+/// Libomptarget requires sm_35 or newer so an sm_20 bitcode library should 
never exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 -fopenmp-relocatable-target -save-temps 
\
+// RUN:   -no-canonical-prefixes %s 2>&1 | FileCheck 
-check-prefix=CHK-BCLIB-WARN %s
+
+// CHK-BCLIB-WARN: Expect degraded performance on the target device due to 
missing 'libomptarget-nvptx-sm_20.bc' in LIBRARY_PATH.
Index: lib/Driver/ToolChains/Cuda.cpp
===
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
 #include 
 
@@ -580,6 +581,43 @@
 CC1Args.push_back("-target-feature");
 CC1Args.push_back("+ptx42");
   }
+
+  if (DeviceOffloadingKind == Action::OFK_OpenMP) {
+SmallVector LibraryPaths;
+// Add path to lib and/or lib64 folders.
+SmallString<256> DefaultLibPath =
+  llvm::sys::path::parent_path(getDriver().Dir);
+llvm::sys::path::append(DefaultLibPath,
+Twine("lib") + CLANG_LIBDIR_SUFFIX);
+LibraryPaths.emplace_back(DefaultLibPath.c_str());
+
+// Add user defined library paths from LIBRARY_PATH.
+if (llvm::Optional LibPath =
+  llvm::sys::Process::GetEnv("LIBRARY_PATH")) {
+  SmallVector Frags;
+  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
+  llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
+  for (auto Path : Frags)
+LibraryPaths.emplace_back(Path.trim());
+}
+
+std::string LibOmpTargetName =
+  "libomptarget-nvptx-" + GpuArch.str() + ".bc";
+bool FoundBCLibrary = false;
+for (const std::string &LibraryPath : LibraryPaths) {
+  SmallString<128> LibOmpTargetFile(LibraryPath);
+  llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
+  if (llvm::sys::fs::exists(LibOmpTargetFile)) {
+CC1Args.push_back("-mlink-cuda-bitcode");
+CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
+FoundBCLibrary = true;
+break;
+  }
+}
+if (!FoundBCLibrary)
+  getDriver().Diag(diag::remark_drv_omp_offload_target_missingbcruntime)
+  << LibOmpTargetName;
+  }
 }
 
 void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -203,6 +203,9 @@
 def warn_drv_omp_offload_target_duplicate : Warning<
   "The OpenMP offloading target '%0' is similar to target '%1' already 
specified - will be ignored.">, 
   InGroup;
+def remark_drv_omp_offload_target_missingbcruntime : Warning<
+  "Expect degraded performance on the target device due to missing '%0' in 
LIBRARY_PATH.">,
+  InGroup;
 def err_drv_bitcode_unsupported_on_toolchain : Error<
   "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
 


Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,25 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60
+
+/// ##

[PATCH] D43904: [clang-format] Improve detection of ObjC for-in statements

2018-03-06 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326815: [clang-format] Improve detection of ObjC for-in 
statements (authored by benhamilton, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43904?vs=137199&id=137218#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43904

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp
  cfe/trunk/unittests/Format/FormatTestObjC.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -216,6 +216,7 @@
 bool HasMultipleParametersOnALine = false;
 bool MightBeObjCForRangeLoop =
 Left->Previous && Left->Previous->is(tok::kw_for);
+FormatToken *PossibleObjCForInToken = nullptr;
 while (CurrentToken) {
   // LookForDecls is set when "if (" has been seen. Check for
   // 'identifier' '*' 'identifier' followed by not '=' -- this
@@ -301,10 +302,17 @@
CurrentToken->Previous->isSimpleTypeSpecifier()) &&
   !CurrentToken->is(tok::l_brace))
 Contexts.back().IsExpression = false;
-  if (CurrentToken->isOneOf(tok::semi, tok::colon))
+  if (CurrentToken->isOneOf(tok::semi, tok::colon)) {
 MightBeObjCForRangeLoop = false;
-  if (MightBeObjCForRangeLoop && CurrentToken->is(Keywords.kw_in))
-CurrentToken->Type = TT_ObjCForIn;
+if (PossibleObjCForInToken) {
+  PossibleObjCForInToken->Type = TT_Unknown;
+  PossibleObjCForInToken = nullptr;
+}
+  }
+  if (MightBeObjCForRangeLoop && CurrentToken->is(Keywords.kw_in)) {
+PossibleObjCForInToken = CurrentToken;
+PossibleObjCForInToken->Type = TT_ObjCForIn;
+  }
   // When we discover a 'new', we set CanBeExpression to 'false' in order 
to
   // parse the type correctly. Reset that after a comma.
   if (CurrentToken->is(tok::comma))
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -742,6 +742,12 @@
" aaa != bbb;\n"
" ++aaa) {");
 
+  // These should not be formatted as Objective-C for-in loops.
+  verifyFormat("for (Foo *x = 0; x != in; x++) {\n}");
+  verifyFormat("Foo *x;\nfor (x = 0; x != in; x++) {\n}");
+  verifyFormat("Foo *x;\nfor (x in y) {\n}");
+  verifyFormat("for (const Foo &baz = in.value(); !baz.at_end(); ++baz) 
{\n}");
+
   FormatStyle NoBinPacking = getLLVMStyle();
   NoBinPacking.BinPackParameters = false;
   verifyFormat("for (int aaa = 1;\n"
@@ -12082,6 +12088,31 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface 
Foo\n@end\n"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithForIn) {
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "for (Foo *x = 0; x != in; x++) {}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "for (Foo *x in bar) {}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "for (Foo *x in [bar baz]) {}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "for (Foo *x in [bar baz:blech]) {}"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "for (Foo *x in [bar baz:blech, 1, 2, 3, 0]) 
{}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "for (Foo *x in [bar baz:^{[uh oh];}]) 
{}"));
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "Foo *x; for (x = 0; x != in; x++) {}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "Foo *x; for (x in y) {}"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
+  guessLanguage(
+  "foo.h",
+  "for (const Foo& baz = in.value(); !baz.at_end(); ++baz) {}"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: cfe/trunk/unittests/Format/FormatTestObjC.cpp
===
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp
@@ -893,6 +893,13 @@
"foo(n);\n"
"  }\n"
"}");
+  verifyFormat("for (Foo *x in bar) {\n}");
+  verifyFormat("for (Foo *x in [bar baz]) {\n}");
+  verifyFormat("for (Foo *x in [bar baz:blech]) {\n}");
+  verifyFormat("for (Foo *x in [bar baz:blech, 1, 2, 3, 0]) {\n}");
+  verifyFormat("for (Foo *x in [bar baz:^{\n"
+   "   [uh oh];\n"
+   " }]) {\n}");
 }
 
 TEST_F(FormatTestObjC, ObjCLiterals) {


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp

r326815 - [clang-format] Improve detection of ObjC for-in statements

2018-03-06 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Tue Mar  6 09:21:42 2018
New Revision: 326815

URL: http://llvm.org/viewvc/llvm-project?rev=326815&view=rev
Log:
[clang-format] Improve detection of ObjC for-in statements

Summary:
Previously, clang-format would detect the following as an
Objective-C for-in statement:

  for (int x = in.value(); ...) {}

because the logic only decided a for-loop was definitely *not*
an Objective-C for-in loop after it saw a semicolon or a colon.

To fix this, I delayed the decision of whether this was a for-in
statement until after we found the matching right-paren, at which
point we know if we've seen a semicolon or not.

Test Plan: New tests added. Ran tests with:
  make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: krasimir, jolesiak

Reviewed By: jolesiak

Subscribers: djasper, cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=326815&r1=326814&r2=326815&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Mar  6 09:21:42 2018
@@ -216,6 +216,7 @@ private:
 bool HasMultipleParametersOnALine = false;
 bool MightBeObjCForRangeLoop =
 Left->Previous && Left->Previous->is(tok::kw_for);
+FormatToken *PossibleObjCForInToken = nullptr;
 while (CurrentToken) {
   // LookForDecls is set when "if (" has been seen. Check for
   // 'identifier' '*' 'identifier' followed by not '=' -- this
@@ -301,10 +302,17 @@ private:
CurrentToken->Previous->isSimpleTypeSpecifier()) &&
   !CurrentToken->is(tok::l_brace))
 Contexts.back().IsExpression = false;
-  if (CurrentToken->isOneOf(tok::semi, tok::colon))
+  if (CurrentToken->isOneOf(tok::semi, tok::colon)) {
 MightBeObjCForRangeLoop = false;
-  if (MightBeObjCForRangeLoop && CurrentToken->is(Keywords.kw_in))
-CurrentToken->Type = TT_ObjCForIn;
+if (PossibleObjCForInToken) {
+  PossibleObjCForInToken->Type = TT_Unknown;
+  PossibleObjCForInToken = nullptr;
+}
+  }
+  if (MightBeObjCForRangeLoop && CurrentToken->is(Keywords.kw_in)) {
+PossibleObjCForInToken = CurrentToken;
+PossibleObjCForInToken->Type = TT_ObjCForIn;
+  }
   // When we discover a 'new', we set CanBeExpression to 'false' in order 
to
   // parse the type correctly. Reset that after a comma.
   if (CurrentToken->is(tok::comma))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=326815&r1=326814&r2=326815&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Mar  6 09:21:42 2018
@@ -742,6 +742,12 @@ TEST_F(FormatTest, FormatsForLoop) {
" aaa != bbb;\n"
" ++aaa) {");
 
+  // These should not be formatted as Objective-C for-in loops.
+  verifyFormat("for (Foo *x = 0; x != in; x++) {\n}");
+  verifyFormat("Foo *x;\nfor (x = 0; x != in; x++) {\n}");
+  verifyFormat("Foo *x;\nfor (x in y) {\n}");
+  verifyFormat("for (const Foo &baz = in.value(); !baz.at_end(); ++baz) 
{\n}");
+
   FormatStyle NoBinPacking = getLLVMStyle();
   NoBinPacking.BinPackParameters = false;
   verifyFormat("for (int aaa = 1;\n"
@@ -12082,6 +12088,31 @@ TEST_F(FormatTest, FileAndCode) {
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface 
Foo\n@end\n"));
 }
 
+TEST_F(FormatTest, GuessLanguageWithForIn) {
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "for (Foo *x = 0; x != in; x++) {}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "for (Foo *x in bar) {}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "for (Foo *x in [bar baz]) {}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "for (Foo *x in [bar baz:blech]) {}"));
+  EXPECT_EQ(
+  FormatStyle::LK_ObjC,
+  guessLanguage("foo.h", "for (Foo *x in [bar baz:blech, 1, 2, 3, 0]) 
{}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "for (Foo *x in [bar baz:^{[uh oh];}]) 
{}"));
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "Foo *x; for (x = 0; x != in; x++) {}"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "Foo *x; for (x in y) {}"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
+  guessLanguage(
+  "foo.

Re: r326746 - [analyzer] AST-matching checker to detect global central dispatch performance anti-pattern

2018-03-06 Thread George Karpenkov via cfe-commits
Yep, sorry, bad typing skills.

> On Mar 6, 2018, at 2:44 AM, Alexander Kornienko  wrote:
> 
> On Tue, Mar 6, 2018 at 11:03 AM Alexander Kornienko  > wrote:
> On Mon, Mar 5, 2018 at 11:05 PM George Karpenkov via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: george.karpenkov
> Date: Mon Mar  5 14:03:32 2018
> New Revision: 326746
> 
> cfe/trunk/test/gcdasyncsemaphorechecker_test.m
> 
> The test doesn't belong here. The right place seems to be test/Analysis/.
> 
> Moved the test in r326772. 

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


  1   2   >