Re: r278471 - [Sema] Fix a crash on variadic enable_if functions.

2016-08-11 Thread George Burgess IV via cfe-commits
r278479.

Thank you! :)

On Thu, Aug 11, 2016 at 10:08 PM, Richard Smith 
wrote:

> Sure, looks safe enough to me.
>
> On 11 Aug 2016 9:23 p.m., "George Burgess IV" 
> wrote:
>
> Hi Richard,
>
> Would you mind if I merged this into the 3.9 branch? :)
>
> Thanks,
> George
>
> On Thu, Aug 11, 2016 at 9:12 PM, George Burgess IV via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: gbiv
>> Date: Thu Aug 11 23:12:31 2016
>> New Revision: 278471
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=278471&view=rev
>> Log:
>> [Sema] Fix a crash on variadic enable_if functions.
>>
>> Currently, when trying to evaluate an enable_if condition, we try to
>> evaluate all arguments a user passes to a function. Given that we can't
>> use variadic arguments from said condition anyway, not converting them
>> is a reasonable thing to do. So, this patch makes us ignore any varargs
>> when attempting to check an enable_if condition.
>>
>> We'd crash because, in order to convert an argument, we need its
>> ParmVarDecl. Variadic arguments don't have ParmVarDecls.
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaOverload.cpp
>> cfe/trunk/test/Sema/enable_if.c
>> cfe/trunk/test/SemaCXX/enable_if.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaO
>> verload.cpp?rev=278471&r1=278470&r2=278471&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Aug 11 23:12:31 2016
>> @@ -5974,8 +5974,12 @@ EnableIfAttr *Sema::CheckEnableIf(Functi
>>SmallVector ConvertedArgs;
>>bool InitializationFailed = false;
>>
>> +  // Ignore any variadic parameters. Converting them is pointless, since
>> the
>> +  // user can't refer to them in the enable_if condition.
>> +  unsigned ArgSizeNoVarargs = std::min(Function->param_size(),
>> Args.size());
>> +
>>// Convert the arguments.
>> -  for (unsigned I = 0, E = Args.size(); I != E; ++I) {
>> +  for (unsigned I = 0; I != ArgSizeNoVarargs; ++I) {
>>  ExprResult R;
>>  if (I == 0 && !MissingImplicitThis && isa(Function) &&
>>  !cast(Function)->isStatic() &&
>>
>> Modified: cfe/trunk/test/Sema/enable_if.c
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enab
>> le_if.c?rev=278471&r1=278470&r2=278471&view=diff
>> 
>> ==
>> --- cfe/trunk/test/Sema/enable_if.c (original)
>> +++ cfe/trunk/test/Sema/enable_if.c Thu Aug 11 23:12:31 2016
>> @@ -149,4 +149,25 @@ void PR27122_ext() {
>>regular_enable_if(1, 2); // expected-error{{too many arguments}}
>>regular_enable_if(); // expected-error{{too few arguments}}
>>  }
>> +
>> +// We had a bug where we'd crash upon trying to evaluate varargs.
>> +void variadic_enable_if(int a, ...) __attribute__((enable_if(a, "")));
>> // expected-note 6 {{disabled}}
>> +void variadic_test() {
>> +  variadic_enable_if(1);
>> +  variadic_enable_if(1, 2);
>> +  variadic_enable_if(1, "c", 3);
>> +
>> +  variadic_enable_if(0); // expected-error{{no matching}}
>> +  variadic_enable_if(0, 2); // expected-error{{no matching}}
>> +  variadic_enable_if(0, "c", 3); // expected-error{{no matching}}
>> +
>> +  int m;
>> +  variadic_enable_if(1);
>> +  variadic_enable_if(1, m);
>> +  variadic_enable_if(1, m, "c");
>> +
>> +  variadic_enable_if(0); // expected-error{{no matching}}
>> +  variadic_enable_if(0, m); // expected-error{{no matching}}
>> +  variadic_enable_if(0, m, 3); // expected-error{{no matching}}
>> +}
>>  #endif
>>
>> Modified: cfe/trunk/test/SemaCXX/enable_if.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/e
>> nable_if.cpp?rev=278471&r1=278470&r2=278471&view=diff
>> 
>> ==
>> --- cfe/trunk/test/SemaCXX/enable_if.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/enable_if.cpp Thu Aug 11 23:12:31 2016
>> @@ -417,3 +417,26 @@ template  constexpr int callTempl
>>  constexpr int B = callTemplated<0>(); // expected-error{{initialized by
>> a constant expression}} expected-error@-2{{no matching function for call
>> to 'templated'}} expected-note{{in instantiation of function template}}
>> expected-note@-9{{candidate disabled}}
>>  static_assert(callTemplated<1>() == 1, "");
>>  }
>> +
>> +namespace variadic {
>> +void foo(int a, int b = 0, ...) __attribute__((enable_if(a && b, "")));
>> // expected-note 6{{disabled}}
>> +
>> +void testFoo() {
>> +  foo(1, 1);
>> +  foo(1, 1, 2);
>> +  foo(1, 1, 2, 3);
>> +
>> +  foo(1, 0); // expected-error{{no matching}}
>> +  foo(1, 0, 2); // expected-error{{no matching}}
>> +  foo(1, 0, 2, 3); // expected-error{{no matching}}
>> +
>> +  int m;
>> +  foo(1, 1);
>> +  foo(1, 1, m);
>> +  foo(1, 1, m, 3);
>> +
>> +  foo(1, 0); // expected-error{{no matching}}
>> +  foo(1, 0, m); // expected-error{{no matching}}

Re: r278471 - [Sema] Fix a crash on variadic enable_if functions.

2016-08-11 Thread Richard Smith via cfe-commits
Sure, looks safe enough to me.

On 11 Aug 2016 9:23 p.m., "George Burgess IV" 
wrote:

Hi Richard,

Would you mind if I merged this into the 3.9 branch? :)

Thanks,
George

On Thu, Aug 11, 2016 at 9:12 PM, George Burgess IV via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: gbiv
> Date: Thu Aug 11 23:12:31 2016
> New Revision: 278471
>
> URL: http://llvm.org/viewvc/llvm-project?rev=278471&view=rev
> Log:
> [Sema] Fix a crash on variadic enable_if functions.
>
> Currently, when trying to evaluate an enable_if condition, we try to
> evaluate all arguments a user passes to a function. Given that we can't
> use variadic arguments from said condition anyway, not converting them
> is a reasonable thing to do. So, this patch makes us ignore any varargs
> when attempting to check an enable_if condition.
>
> We'd crash because, in order to convert an argument, we need its
> ParmVarDecl. Variadic arguments don't have ParmVarDecls.
>
> Modified:
> cfe/trunk/lib/Sema/SemaOverload.cpp
> cfe/trunk/test/Sema/enable_if.c
> cfe/trunk/test/SemaCXX/enable_if.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaO
> verload.cpp?rev=278471&r1=278470&r2=278471&view=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Aug 11 23:12:31 2016
> @@ -5974,8 +5974,12 @@ EnableIfAttr *Sema::CheckEnableIf(Functi
>SmallVector ConvertedArgs;
>bool InitializationFailed = false;
>
> +  // Ignore any variadic parameters. Converting them is pointless, since
> the
> +  // user can't refer to them in the enable_if condition.
> +  unsigned ArgSizeNoVarargs = std::min(Function->param_size(),
> Args.size());
> +
>// Convert the arguments.
> -  for (unsigned I = 0, E = Args.size(); I != E; ++I) {
> +  for (unsigned I = 0; I != ArgSizeNoVarargs; ++I) {
>  ExprResult R;
>  if (I == 0 && !MissingImplicitThis && isa(Function) &&
>  !cast(Function)->isStatic() &&
>
> Modified: cfe/trunk/test/Sema/enable_if.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enab
> le_if.c?rev=278471&r1=278470&r2=278471&view=diff
> 
> ==
> --- cfe/trunk/test/Sema/enable_if.c (original)
> +++ cfe/trunk/test/Sema/enable_if.c Thu Aug 11 23:12:31 2016
> @@ -149,4 +149,25 @@ void PR27122_ext() {
>regular_enable_if(1, 2); // expected-error{{too many arguments}}
>regular_enable_if(); // expected-error{{too few arguments}}
>  }
> +
> +// We had a bug where we'd crash upon trying to evaluate varargs.
> +void variadic_enable_if(int a, ...) __attribute__((enable_if(a, ""))); //
> expected-note 6 {{disabled}}
> +void variadic_test() {
> +  variadic_enable_if(1);
> +  variadic_enable_if(1, 2);
> +  variadic_enable_if(1, "c", 3);
> +
> +  variadic_enable_if(0); // expected-error{{no matching}}
> +  variadic_enable_if(0, 2); // expected-error{{no matching}}
> +  variadic_enable_if(0, "c", 3); // expected-error{{no matching}}
> +
> +  int m;
> +  variadic_enable_if(1);
> +  variadic_enable_if(1, m);
> +  variadic_enable_if(1, m, "c");
> +
> +  variadic_enable_if(0); // expected-error{{no matching}}
> +  variadic_enable_if(0, m); // expected-error{{no matching}}
> +  variadic_enable_if(0, m, 3); // expected-error{{no matching}}
> +}
>  #endif
>
> Modified: cfe/trunk/test/SemaCXX/enable_if.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/
> enable_if.cpp?rev=278471&r1=278470&r2=278471&view=diff
> 
> ==
> --- cfe/trunk/test/SemaCXX/enable_if.cpp (original)
> +++ cfe/trunk/test/SemaCXX/enable_if.cpp Thu Aug 11 23:12:31 2016
> @@ -417,3 +417,26 @@ template  constexpr int callTempl
>  constexpr int B = callTemplated<0>(); // expected-error{{initialized by a
> constant expression}} expected-error@-2{{no matching function for call to
> 'templated'}} expected-note{{in instantiation of function template}}
> expected-note@-9{{candidate disabled}}
>  static_assert(callTemplated<1>() == 1, "");
>  }
> +
> +namespace variadic {
> +void foo(int a, int b = 0, ...) __attribute__((enable_if(a && b, "")));
> // expected-note 6{{disabled}}
> +
> +void testFoo() {
> +  foo(1, 1);
> +  foo(1, 1, 2);
> +  foo(1, 1, 2, 3);
> +
> +  foo(1, 0); // expected-error{{no matching}}
> +  foo(1, 0, 2); // expected-error{{no matching}}
> +  foo(1, 0, 2, 3); // expected-error{{no matching}}
> +
> +  int m;
> +  foo(1, 1);
> +  foo(1, 1, m);
> +  foo(1, 1, m, 3);
> +
> +  foo(1, 0); // expected-error{{no matching}}
> +  foo(1, 0, m); // expected-error{{no matching}}
> +  foo(1, 0, m, 3); // expected-error{{no matching}}
> +}
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listin

Re: [PATCH] D23387: [Analyzer] Report found fields order in PaddingChecker.

2016-08-11 Thread Alexander Shaposhnikov via cfe-commits
alexshap updated this revision to Diff 67797.
alexshap added a comment.

Update the tests. Update the format again (do not include the type name because 
the diagnostics becomes too verbose and unreadable (i ran it against LLVM and 
clang - with type names the diagnostic messages are getting very long, without 
them they look normal (IMO)),
Test plan: make -j8 check-clang-analysis (passed).


https://reviews.llvm.org/D23387

Files:
  lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  test/Analysis/padding_message.cpp

Index: test/Analysis/padding_message.cpp
===
--- test/Analysis/padding_message.cpp
+++ test/Analysis/padding_message.cpp
@@ -1,13 +1,25 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux -std=c++14 -analyze -analyzer-checker=optin.performance -analyzer-config optin.performance.Padding:AllowedPad=2 -verify %s
 
-// expected-warning@+1{{Excessive padding in 'struct IntSandwich' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct IntSandwich' (6 padding bytes, where 2 is optimal). \
+Optimal fields order: \
+i, \
+c1, \
+c2, \
+}}
 struct IntSandwich {
   char c1;
   int i;
   char c2;
 };
 
-// expected-warning@+1{{Excessive padding in 'struct TurDuckHen' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct TurDuckHen' (6 padding bytes, where 2 is optimal). \
+Optimal fields order: \
+i, \
+c1, \
+c2, \
+}}
 struct TurDuckHen {
   char c1;
   struct IntSandwich i;
@@ -16,7 +28,17 @@
 
 #pragma pack(push)
 #pragma pack(2)
-// expected-warning@+1{{Excessive padding in 'struct SmallIntSandwich' (4 padding bytes, where 0 is optimal)}}
+// expected-warning@+11{{\
+Excessive padding in 'struct SmallIntSandwich' (4 padding bytes, where 0 is optimal). \
+Optimal fields order: \
+i1, \
+i2, \
+i3, \
+c1, \
+c2, \
+c3, \
+c4, \
+}}
 struct SmallIntSandwich {
   char c1;
   int i1;
@@ -34,7 +56,13 @@
   int i;
 };
 
-// expected-warning@+1{{Excessive padding in 'struct HoldsAUnion' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct HoldsAUnion' (6 padding bytes, where 2 is optimal). \
+Optimal fields order: \
+u, \
+c1, \
+c2, \
+}}
 struct HoldsAUnion {
   char c1;
   union SomeUnion u;
@@ -49,28 +77,53 @@
   int i[5];
 };
 
-// expected-warning@+1{{Excessive padding in 'struct StructSandwich' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct StructSandwich' (6 padding bytes, where 2 is optimal). \
+Optimal fields order: \
+m, \
+s, \
+s2, \
+}}
 struct StructSandwich {
   struct SmallCharArray s;
   struct MediumIntArray m;
   struct SmallCharArray s2;
 };
 
-// expected-warning@+1{{Excessive padding in 'TypedefSandwich' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'TypedefSandwich' (6 padding bytes, where 2 is optimal). \
+Optimal fields order: \
+i, \
+c1, \
+c2, \
+}}
 typedef struct {
   char c1;
   int i;
   char c2;
 } TypedefSandwich;
 
-// expected-warning@+1{{Excessive padding in 'struct StructAttrAlign' (10 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct StructAttrAlign' (10 padding bytes, where 2 is optimal). \
+Optimal fields order: \
+i, \
+c1, \
+c2, \
+}}
 struct StructAttrAlign {
   char c1;
   int i;
   char c2;
 } __attribute__((aligned(8)));
 
-// expected-warning@+1{{Excessive padding in 'struct OverlyAlignedChar' (8185 padding bytes, where 4089 is optimal)}}
+// expected-warning@+8{{\
+Excessive padding in 'struct OverlyAlignedChar' (8185 padding bytes, where 4089 is optimal). \
+Optimal fields order: \
+c, \
+c1, \
+c2, \
+x, \
+}}
 struct OverlyAlignedChar {
   char c1;
   int x;
@@ -78,7 +131,13 @@
   char c __attribute__((aligned(4096)));
 };
 
-// expected-warning@+1{{Excessive padding in 'struct HoldsOverlyAlignedChar' (8190 padding bytes, where 4094 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct HoldsOverlyAlignedChar' (8190 padding bytes, where 4094 is optimal). \
+Optimal fields order: \
+o, \
+c1, \
+c2, \
+}}
 struct HoldsOverlyAlignedChar {
   char c1;
   struct OverlyAlignedChar o;
@@ -86,7 +145,13 @@
 };
 
 void internalStructFunc() {
-  // expected-warning@+1{{Excessive padding in 'struct X' (6 padding bytes, where 2 is optimal)}}
+  // expected-warning@+7{{\
+Excessive padding in 'struct X' (6 padding bytes, where 2 is optimal). \
+Optimal fields order: \
+t, \
+c1, \
+c2, \
+}}
   struct X {
 char c1;
 int t;
@@ -96,7 +161,13 @@
 }
 
 void typedefStructFunc() {
-  // expected-warning@+1{{Excessive padding in 'S' (6 padding bytes, where 2 is optimal)}}
+  // expected-warning@+7{{\
+Excessive padding in 'S' (6 padding bytes, where 2 is optimal). \
+Optimal fields order: \
+t, \
+c1, \
+c2, \
+}}
   typedef struct {
 char c1;
 int t;
@@ -105,21 +176,39 @@
   S obj;
 }
 
-// expected-warning@+1{{Excess

r278472 - [Sema] Fix the wording of a comment. NFC.

2016-08-11 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Thu Aug 11 23:19:35 2016
New Revision: 278472

URL: http://llvm.org/viewvc/llvm-project?rev=278472&view=rev
Log:
[Sema] Fix the wording of a comment. NFC.

Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=278472&r1=278471&r2=278472&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Aug 11 23:19:35 2016
@@ -5974,7 +5974,7 @@ EnableIfAttr *Sema::CheckEnableIf(Functi
   SmallVector ConvertedArgs;
   bool InitializationFailed = false;
 
-  // Ignore any variadic parameters. Converting them is pointless, since the
+  // Ignore any variadic arguments. Converting them is pointless, since the
   // user can't refer to them in the enable_if condition.
   unsigned ArgSizeNoVarargs = std::min(Function->param_size(), Args.size());
 


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


Re: r278471 - [Sema] Fix a crash on variadic enable_if functions.

2016-08-11 Thread George Burgess IV via cfe-commits
Hi Richard,

Would you mind if I merged this into the 3.9 branch? :)

Thanks,
George

On Thu, Aug 11, 2016 at 9:12 PM, George Burgess IV via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: gbiv
> Date: Thu Aug 11 23:12:31 2016
> New Revision: 278471
>
> URL: http://llvm.org/viewvc/llvm-project?rev=278471&view=rev
> Log:
> [Sema] Fix a crash on variadic enable_if functions.
>
> Currently, when trying to evaluate an enable_if condition, we try to
> evaluate all arguments a user passes to a function. Given that we can't
> use variadic arguments from said condition anyway, not converting them
> is a reasonable thing to do. So, this patch makes us ignore any varargs
> when attempting to check an enable_if condition.
>
> We'd crash because, in order to convert an argument, we need its
> ParmVarDecl. Variadic arguments don't have ParmVarDecls.
>
> Modified:
> cfe/trunk/lib/Sema/SemaOverload.cpp
> cfe/trunk/test/Sema/enable_if.c
> cfe/trunk/test/SemaCXX/enable_if.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaOverload.cpp?rev=278471&r1=278470&r2=278471&view=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Aug 11 23:12:31 2016
> @@ -5974,8 +5974,12 @@ EnableIfAttr *Sema::CheckEnableIf(Functi
>SmallVector ConvertedArgs;
>bool InitializationFailed = false;
>
> +  // Ignore any variadic parameters. Converting them is pointless, since
> the
> +  // user can't refer to them in the enable_if condition.
> +  unsigned ArgSizeNoVarargs = std::min(Function->param_size(),
> Args.size());
> +
>// Convert the arguments.
> -  for (unsigned I = 0, E = Args.size(); I != E; ++I) {
> +  for (unsigned I = 0; I != ArgSizeNoVarargs; ++I) {
>  ExprResult R;
>  if (I == 0 && !MissingImplicitThis && isa(Function) &&
>  !cast(Function)->isStatic() &&
>
> Modified: cfe/trunk/test/Sema/enable_if.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/
> enable_if.c?rev=278471&r1=278470&r2=278471&view=diff
> 
> ==
> --- cfe/trunk/test/Sema/enable_if.c (original)
> +++ cfe/trunk/test/Sema/enable_if.c Thu Aug 11 23:12:31 2016
> @@ -149,4 +149,25 @@ void PR27122_ext() {
>regular_enable_if(1, 2); // expected-error{{too many arguments}}
>regular_enable_if(); // expected-error{{too few arguments}}
>  }
> +
> +// We had a bug where we'd crash upon trying to evaluate varargs.
> +void variadic_enable_if(int a, ...) __attribute__((enable_if(a, ""))); //
> expected-note 6 {{disabled}}
> +void variadic_test() {
> +  variadic_enable_if(1);
> +  variadic_enable_if(1, 2);
> +  variadic_enable_if(1, "c", 3);
> +
> +  variadic_enable_if(0); // expected-error{{no matching}}
> +  variadic_enable_if(0, 2); // expected-error{{no matching}}
> +  variadic_enable_if(0, "c", 3); // expected-error{{no matching}}
> +
> +  int m;
> +  variadic_enable_if(1);
> +  variadic_enable_if(1, m);
> +  variadic_enable_if(1, m, "c");
> +
> +  variadic_enable_if(0); // expected-error{{no matching}}
> +  variadic_enable_if(0, m); // expected-error{{no matching}}
> +  variadic_enable_if(0, m, 3); // expected-error{{no matching}}
> +}
>  #endif
>
> Modified: cfe/trunk/test/SemaCXX/enable_if.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/enable_if.cpp?rev=278471&r1=278470&r2=278471&view=diff
> 
> ==
> --- cfe/trunk/test/SemaCXX/enable_if.cpp (original)
> +++ cfe/trunk/test/SemaCXX/enable_if.cpp Thu Aug 11 23:12:31 2016
> @@ -417,3 +417,26 @@ template  constexpr int callTempl
>  constexpr int B = callTemplated<0>(); // expected-error{{initialized by a
> constant expression}} expected-error@-2{{no matching function for call to
> 'templated'}} expected-note{{in instantiation of function template}}
> expected-note@-9{{candidate disabled}}
>  static_assert(callTemplated<1>() == 1, "");
>  }
> +
> +namespace variadic {
> +void foo(int a, int b = 0, ...) __attribute__((enable_if(a && b, "")));
> // expected-note 6{{disabled}}
> +
> +void testFoo() {
> +  foo(1, 1);
> +  foo(1, 1, 2);
> +  foo(1, 1, 2, 3);
> +
> +  foo(1, 0); // expected-error{{no matching}}
> +  foo(1, 0, 2); // expected-error{{no matching}}
> +  foo(1, 0, 2, 3); // expected-error{{no matching}}
> +
> +  int m;
> +  foo(1, 1);
> +  foo(1, 1, m);
> +  foo(1, 1, m, 3);
> +
> +  foo(1, 0); // expected-error{{no matching}}
> +  foo(1, 0, m); // expected-error{{no matching}}
> +  foo(1, 0, m, 3); // expected-error{{no matching}}
> +}
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing li

r278471 - [Sema] Fix a crash on variadic enable_if functions.

2016-08-11 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Thu Aug 11 23:12:31 2016
New Revision: 278471

URL: http://llvm.org/viewvc/llvm-project?rev=278471&view=rev
Log:
[Sema] Fix a crash on variadic enable_if functions.

Currently, when trying to evaluate an enable_if condition, we try to
evaluate all arguments a user passes to a function. Given that we can't
use variadic arguments from said condition anyway, not converting them
is a reasonable thing to do. So, this patch makes us ignore any varargs
when attempting to check an enable_if condition.

We'd crash because, in order to convert an argument, we need its
ParmVarDecl. Variadic arguments don't have ParmVarDecls.

Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/Sema/enable_if.c
cfe/trunk/test/SemaCXX/enable_if.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=278471&r1=278470&r2=278471&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Aug 11 23:12:31 2016
@@ -5974,8 +5974,12 @@ EnableIfAttr *Sema::CheckEnableIf(Functi
   SmallVector ConvertedArgs;
   bool InitializationFailed = false;
 
+  // Ignore any variadic parameters. Converting them is pointless, since the
+  // user can't refer to them in the enable_if condition.
+  unsigned ArgSizeNoVarargs = std::min(Function->param_size(), Args.size());
+
   // Convert the arguments.
-  for (unsigned I = 0, E = Args.size(); I != E; ++I) {
+  for (unsigned I = 0; I != ArgSizeNoVarargs; ++I) {
 ExprResult R;
 if (I == 0 && !MissingImplicitThis && isa(Function) &&
 !cast(Function)->isStatic() &&

Modified: cfe/trunk/test/Sema/enable_if.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enable_if.c?rev=278471&r1=278470&r2=278471&view=diff
==
--- cfe/trunk/test/Sema/enable_if.c (original)
+++ cfe/trunk/test/Sema/enable_if.c Thu Aug 11 23:12:31 2016
@@ -149,4 +149,25 @@ void PR27122_ext() {
   regular_enable_if(1, 2); // expected-error{{too many arguments}}
   regular_enable_if(); // expected-error{{too few arguments}}
 }
+
+// We had a bug where we'd crash upon trying to evaluate varargs.
+void variadic_enable_if(int a, ...) __attribute__((enable_if(a, ""))); // 
expected-note 6 {{disabled}}
+void variadic_test() {
+  variadic_enable_if(1);
+  variadic_enable_if(1, 2);
+  variadic_enable_if(1, "c", 3);
+
+  variadic_enable_if(0); // expected-error{{no matching}}
+  variadic_enable_if(0, 2); // expected-error{{no matching}}
+  variadic_enable_if(0, "c", 3); // expected-error{{no matching}}
+
+  int m;
+  variadic_enable_if(1);
+  variadic_enable_if(1, m);
+  variadic_enable_if(1, m, "c");
+
+  variadic_enable_if(0); // expected-error{{no matching}}
+  variadic_enable_if(0, m); // expected-error{{no matching}}
+  variadic_enable_if(0, m, 3); // expected-error{{no matching}}
+}
 #endif

Modified: cfe/trunk/test/SemaCXX/enable_if.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enable_if.cpp?rev=278471&r1=278470&r2=278471&view=diff
==
--- cfe/trunk/test/SemaCXX/enable_if.cpp (original)
+++ cfe/trunk/test/SemaCXX/enable_if.cpp Thu Aug 11 23:12:31 2016
@@ -417,3 +417,26 @@ template  constexpr int callTempl
 constexpr int B = callTemplated<0>(); // expected-error{{initialized by a 
constant expression}} expected-error@-2{{no matching function for call to 
'templated'}} expected-note{{in instantiation of function template}} 
expected-note@-9{{candidate disabled}}
 static_assert(callTemplated<1>() == 1, "");
 }
+
+namespace variadic {
+void foo(int a, int b = 0, ...) __attribute__((enable_if(a && b, ""))); // 
expected-note 6{{disabled}}
+
+void testFoo() {
+  foo(1, 1);
+  foo(1, 1, 2);
+  foo(1, 1, 2, 3);
+
+  foo(1, 0); // expected-error{{no matching}}
+  foo(1, 0, 2); // expected-error{{no matching}}
+  foo(1, 0, 2, 3); // expected-error{{no matching}}
+
+  int m;
+  foo(1, 1);
+  foo(1, 1, m);
+  foo(1, 1, m, 3);
+
+  foo(1, 0); // expected-error{{no matching}}
+  foo(1, 0, m); // expected-error{{no matching}}
+  foo(1, 0, m, 3); // expected-error{{no matching}}
+}
+}


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


Re: [libcxx] r278357 - test: relax the FS test a slight bit to be more reliable

2016-08-11 Thread Saleem Abdulrasool via cfe-commits
On Thu, Aug 11, 2016 at 9:58 AM, Saleem Abdulrasool via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: compnerd
> Date: Thu Aug 11 11:58:12 2016
> New Revision: 278357
>
> URL: http://llvm.org/viewvc/llvm-project?rev=278357&view=rev
> Log:
> test: relax the FS test a slight bit to be more reliable
>
> Some filesystems track atime always.  This relaxes the test to accept
> either a
> filesystem which does not accurately track atime or does track the atime
> accurately.  This allows the test to pass on filesystems mounted with
> `strictatime` on Linux or on macOS.
>

Thoughts on merging this to 3.9?  It fixes tests on Linux.


> Modified:
> libcxx/trunk/test/std/experimental/filesystem/fs.op.
> funcs/fs.op.last_write_time/last_write_time.pass.cpp
>
> Modified: libcxx/trunk/test/std/experimental/filesystem/fs.op.
> funcs/fs.op.last_write_time/last_write_time.pass.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/
> experimental/filesystem/fs.op.funcs/fs.op.last_write_time/
> last_write_time.pass.cpp?rev=278357&r1=278356&r2=278357&view=diff
> 
> ==
> --- libcxx/trunk/test/std/experimental/filesystem/fs.op.
> funcs/fs.op.last_write_time/last_write_time.pass.cpp (original)
> +++ libcxx/trunk/test/std/experimental/filesystem/fs.op.
> funcs/fs.op.last_write_time/last_write_time.pass.cpp Thu Aug 11 11:58:12
> 2016
> @@ -158,7 +158,8 @@ TEST_CASE(get_last_write_time_dynamic_en
>
>  TEST_CHECK(ftime2 > ftime);
>  TEST_CHECK(dtime2 > dtime);
> -TEST_CHECK(LastAccessTime(file) == file_access_time);
> +TEST_CHECK(LastAccessTime(file) == file_access_time ||
> +   LastAccessTime(file) == Clock::to_time_t(ftime2));
>  TEST_CHECK(LastAccessTime(dir) == dir_access_time);
>  }
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>



-- 
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22666: Frontend: Fix mcount inlining bug

2016-08-11 Thread Saleem Abdulrasool via cfe-commits
compnerd added a comment.

No, the inserted character is a literal SOH, not the string "\01".


https://reviews.llvm.org/D22666



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


Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Eric Fiselier via cfe-commits
EricWF marked an inline comment as done.
EricWF added a comment.

In https://reviews.llvm.org/D23385#513443, @rsmith wrote:

> Have you considered modelling this as an attribute on the declaration of the 
> variable instead of as a separate check? If so, why do you prefer this 
> approach? (If I were to suggest this for standardization, an attribute is the 
> approach I'd probably take.)


An attribute would be a much better approach! I only went this root because I 
figured out how to do it. If you could give me a starting point I'll change it 
over to an attribute.


https://reviews.llvm.org/D23385



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


Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Richard Smith via cfe-commits
rsmith added a comment.

Have you considered modelling this as an attribute on the declaration of the 
variable instead of as a separate check? If so, why do you prefer this 
approach? (If I were to suggest this for standardization, an attribute is the 
approach I'd probably take.)



Comment at: lib/AST/Expr.cpp:2653-2662
@@ -2651,4 +2652,12 @@
 }
-
+if (CE->getConstructor()->isConstexpr() &&
+(CE->getConstructor()->getParent()->hasTrivialDestructor() ||
+AllowNonLiteral)) {
+for (auto *Arg : CE->arguments()) {
+  if (!Arg->isConstantInitializer(Ctx, false, Culprit))
+return false;
+}
+return true;
+}
 break;
   }

This doesn't look right: just because we're calling a constexpr constructor 
with constant arguments doesn't imply that the initializer is constant.


https://reviews.llvm.org/D23385



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


r278460 - P0217R3: serialization/deserialization support for c++17 decomposition declarations.

2016-08-11 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 11 21:21:25 2016
New Revision: 278460

URL: http://llvm.org/viewvc/llvm-project?rev=278460&view=rev
Log:
P0217R3: serialization/deserialization support for c++17 decomposition 
declarations.

Added:
cfe/trunk/test/PCH/cxx1z-decomposition.cpp
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=278460&r1=278459&r2=278460&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Aug 11 21:21:25 2016
@@ -3414,6 +3414,8 @@ public:
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == Decl::Binding; }
+
+  friend class ASTDeclReader;
 };
 
 /// A decomposition declaration. For instance, given:
@@ -3463,6 +3465,7 @@ public:
   static bool classofKind(Kind K) { return K == Decomposition; }
 
   friend TrailingObjects;
+  friend class ASTDeclReader;
 };
 
 /// An instance of this class represents the declaration of a property

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=278460&r1=278459&r2=278460&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Thu Aug 11 21:21:25 2016
@@ -1056,6 +1056,10 @@ namespace clang {
   DECL_IMPLICIT_PARAM,
   /// \brief A ParmVarDecl record.
   DECL_PARM_VAR,
+  /// \brief A DecompositionDecl record.
+  DECL_DECOMPOSITION,
+  /// \brief A BindingDecl record.
+  DECL_BINDING,
   /// \brief A FileScopeAsmDecl record.
   DECL_FILE_SCOPE_ASM,
   /// \brief A BlockDecl record.

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=278460&r1=278459&r2=278460&view=diff
==
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Thu Aug 11 21:21:25 2016
@@ -2334,8 +2334,9 @@ DecompositionDecl *DecompositionDecl::Cr
  unsigned ID,
  unsigned NumBindings) 
{
   size_t Extra = additionalSizeToAlloc(NumBindings);
-  auto *Result = new (C, ID, Extra) DecompositionDecl(
-  C, nullptr, SourceLocation(), SourceLocation(), QualType(), nullptr, 
StorageClass(), None);
+  auto *Result = new (C, ID, Extra)
+  DecompositionDecl(C, nullptr, SourceLocation(), SourceLocation(),
+QualType(), nullptr, StorageClass(), None);
   // Set up and clean out the bindings array.
   Result->NumBindings = NumBindings;
   auto *Trail = Result->getTrailingObjects();

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=278460&r1=278459&r2=278460&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Aug 11 21:21:25 2016
@@ -312,6 +312,8 @@ namespace clang {
 void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); }
 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
 void VisitParmVarDecl(ParmVarDecl *PD);
+void VisitDecompositionDecl(DecompositionDecl *DD);
+void VisitBindingDecl(BindingDecl *BD);
 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
 DeclID VisitTemplateDecl(TemplateDecl *D);
 RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl 
*D);
@@ -1295,6 +1297,18 @@ void ASTDeclReader::VisitParmVarDecl(Par
   // inheritance of default arguments.
 }
 
+void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) {
+  VisitVarDecl(DD);
+  BindingDecl **BDs = DD->getTrailingObjects();
+  for (unsigned I = 0; I != DD->NumBindings; ++I)
+BDs[I] = ReadDeclAs(Record, Idx);
+}
+
+void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) {
+  VisitValueDecl(BD);
+  BD->Binding = Reader.ReadExpr(F);
+}
+
 void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
   VisitDecl(AD);
   AD->setAsmString(cast(Reader.ReadExpr(F)));
@@ -3400,6 +3414,12 @@ Decl *ASTReader::ReadDeclRecord(DeclID I
   case DECL_PARM_VAR:
 D = ParmVarDecl::CreateDeserialized(Context, ID);
 break;
+  case DECL_DECOMPOSITION:

Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Jonathan Roelofs via cfe-commits
jroelofs added a comment.

I don't think I have any more comments, but I'll let one of the other reviewers 
give the final go/no-go.



Comment at: docs/LanguageExtensions.rst:1047
@@ +1046,3 @@
+  Determines whether `expr` names
+  a object that will be initialized during
+  `constant initialization 
`_

s/a object/an object/

(english sucks)


https://reviews.llvm.org/D23385



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


r278459 - Revert "[VFS] Skip non existent files from the VFS tree"

2016-08-11 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Thu Aug 11 21:17:26 2016
New Revision: 278459

URL: http://llvm.org/viewvc/llvm-project?rev=278459&view=rev
Log:
Revert "[VFS] Skip non existent files from the VFS tree"

Breaking bots:
http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/27281/

This reverts commit r278457.

Removed:
cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h
cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h
cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h
cfe/trunk/test/VFS/Inputs/Bar.framework/Modules/module.modulemap
cfe/trunk/test/VFS/Inputs/bar-headers.yaml
cfe/trunk/test/VFS/umbrella-framework-import-skipnonexist.m
Modified:
cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=278459&r1=278458&r2=278459&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Thu Aug 11 21:17:26 2016
@@ -1778,47 +1778,29 @@ VFSFromYamlDirIterImpl::VFSFromYamlDirIt
 RedirectingDirectoryEntry::iterator Begin,
 RedirectingDirectoryEntry::iterator End, std::error_code &EC)
 : Dir(_Path.str()), FS(FS), Current(Begin), End(End) {
-  while (Current != End) {
+  if (Current != End) {
 SmallString<128> PathStr(Dir);
 llvm::sys::path::append(PathStr, (*Current)->getName());
 llvm::ErrorOr S = FS.status(PathStr);
-if (S) {
+if (S)
   CurrentEntry = *S;
-  return;
-}
-// Skip entries which do not map to a reliable external content.
-if (FS.ignoreNonExistentContents() &&
-S.getError() == llvm::errc::no_such_file_or_directory) {
-  ++Current;
-  continue;
-} else {
+else
   EC = S.getError();
-  break;
-}
   }
 }
 
 std::error_code VFSFromYamlDirIterImpl::increment() {
   assert(Current != End && "cannot iterate past end");
-  while (++Current != End) {
+  if (++Current != End) {
 SmallString<128> PathStr(Dir);
 llvm::sys::path::append(PathStr, (*Current)->getName());
 llvm::ErrorOr S = FS.status(PathStr);
-if (!S) {
-  // Skip entries which do not map to a reliable external content.
-  if (FS.ignoreNonExistentContents() &&
-  S.getError() == llvm::errc::no_such_file_or_directory) {
-continue;
-  } else {
-return S.getError();
-  }
-}
+if (!S)
+  return S.getError();
 CurrentEntry = *S;
-break;
-  }
-
-  if (Current == End)
+  } else {
 CurrentEntry = Status();
+  }
   return std::error_code();
 }
 

Removed: cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h?rev=278458&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h (original)
+++ cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h (removed)
@@ -1 +0,0 @@
-// A.h

Removed: cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h?rev=278458&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h (original)
+++ cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h (removed)
@@ -1 +0,0 @@
-// B.h

Removed: cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h?rev=278458&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h (original)
+++ cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h (removed)
@@ -1 +0,0 @@
-// C.h

Removed: cfe/trunk/test/VFS/Inputs/Bar.framework/Modules/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Bar.framework/Modules/module.modulemap?rev=278458&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Bar.framework/Modules/module.modulemap (original)
+++ cfe/trunk/test/VFS/Inputs/Bar.framework/Modules/module.modulemap (removed)
@@ -1,6 +0,0 @@
-framework module Bar [extern_c] {
-  umbrella "Headers"
-  export *
-  module * { export * }
-}
-

Removed: cfe/trunk/test/VFS/Inputs/bar-headers.yaml
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/bar-headers.yaml?rev=278458&view=auto
==
--- cfe/trunk/test/VFS/Inputs/bar-headers.yaml (original)
+++ cfe/trunk/test/VFS/Inputs/bar-headers.yaml (removed)
@@ -1,39 +0,0 @@
-{
-  'version': 0,
-  'case-sensitive': 'false',
-  'ignore-non-existent-contents': 'true',
-  'roots': [
-{
-  'type': 'directory',

r278458 - P0217R3: template instantiation support for decomposition declarations.

2016-08-11 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 11 20:55:21 2016
New Revision: 278458

URL: http://llvm.org/viewvc/llvm-project?rev=278458&view=rev
Log:
P0217R3: template instantiation support for decomposition declarations.

Added:
cfe/trunk/test/SemaTemplate/cxx1z-decomposition.cpp
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Sema/Template.h
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=278458&r1=278457&r2=278458&view=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Thu Aug 11 20:55:21 2016
@@ -4011,6 +4011,12 @@ public:
 // within a default initializer.
 if (isa(ExtendingDecl))
   return SD_Automatic;
+// FIXME: This only works because storage class specifiers are not allowed
+// on decomposition declarations.
+if (isa(ExtendingDecl))
+  return ExtendingDecl->getDeclContext()->isFunctionOrMethod()
+ ? SD_Automatic
+ : SD_Static;
 return cast(ExtendingDecl)->getStorageDuration();
   }
 

Modified: cfe/trunk/include/clang/Sema/Initialization.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=278458&r1=278457&r2=278458&view=diff
==
--- cfe/trunk/include/clang/Sema/Initialization.h (original)
+++ cfe/trunk/include/clang/Sema/Initialization.h Thu Aug 11 20:55:21 2016
@@ -184,9 +184,8 @@ private:
   ManglingNumber(0), VariableOrMember(Member) { }
   
   /// \brief Create the initialization entity for a binding.
-  InitializedEntity(BindingDecl *Binding, QualType Type,
-const InitializedEntity &Parent)
-: Kind(EK_Binding), Parent(&Parent), Type(Type),
+  InitializedEntity(BindingDecl *Binding, QualType Type)
+: Kind(EK_Binding), Parent(nullptr), Type(Type),
   ManglingNumber(0), VariableOrMember(Binding) {}
 
   /// \brief Create the initialization entity for an array element.
@@ -324,10 +323,9 @@ public:
   }
 
   /// \brief Create the initialization entity for a structured binding.
-  static InitializedEntity InitializeBinding(const InitializedEntity &Parent,
- BindingDecl *Binding,
+  static InitializedEntity InitializeBinding(BindingDecl *Binding,
  QualType Type) {
-return InitializedEntity(Binding, Type, Parent);
+return InitializedEntity(Binding, Type);
   }
 
   /// \brief Create the initialization entity for a lambda capture.

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=278458&r1=278457&r2=278458&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Aug 11 20:55:21 2016
@@ -1728,9 +1728,8 @@ public:
   // Returns true if the variable declaration is a redeclaration
   bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
   void CheckVariableDeclarationType(VarDecl *NewVD);
-  void CheckCompleteVariableDeclaration(VarDecl *VD, InitializedEntity 
&Entity);
-  void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD,
- InitializedEntity &Entity);
+  void CheckCompleteVariableDeclaration(VarDecl *VD);
+  void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD);
   void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D);
 
   NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,

Modified: cfe/trunk/include/clang/Sema/Template.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Template.h?rev=278458&r1=278457&r2=278458&view=diff
==
--- cfe/trunk/include/clang/Sema/Template.h (original)
+++ cfe/trunk/include/clang/Sema/Template.h Thu Aug 11 20:55:21 2016
@@ -433,7 +433,8 @@ namespace clang {
 Decl *VisitFunctionDecl(FunctionDecl *D,
 TemplateParameterList *TemplateParams);
 Decl *VisitDecl(Decl *D);
-Decl *VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate);
+Decl *VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate,
+   ArrayRef *Bindings = nullptr);
 
 // Enable late instantiation of attributes.  Late instantiated attributes
 // will be stored in 

Re: [PATCH] D23422: [VFS] Add 'ignore-non-existent-contents' field to YAML

2016-08-11 Thread Bruno Cardoso Lopes via cfe-commits
bruno accepted this revision.
bruno added a reviewer: bruno.
bruno added a comment.
This revision is now accepted and ready to land.

Applied your comments, and committed in r278456!

Thanks


https://reviews.llvm.org/D23422



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


r278457 - [VFS] Skip non existent files from the VFS tree

2016-08-11 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Thu Aug 11 20:51:04 2016
New Revision: 278457

URL: http://llvm.org/viewvc/llvm-project?rev=278457&view=rev
Log:
[VFS] Skip non existent files from the VFS tree

When the VFS uses a YAML file, the real file path for a
virtual file is described in the "external-contents" field. Example:

  ...
  {
 'type': 'file',
 'name': 'a.h',
 'external-contents': '/a/b/c/a.h'
  }

Currently, when parsing umbrella directories, we use
vfs::recursive_directory_iterator to gather the header files to generate the
equivalent modules for. If the external contents for a header does not exist,
we currently are unable to build a module, since the VFS
vfs::recursive_directory_iterator will fail when it finds an entry without a
reliable real path.

Since the YAML file could be prepared ahead of time and shared among
different compiler invocations, an entry might not yet have a reliable
path in 'external-contents', breaking the iteration.

Give the VFS the capability to skip such entries whenever
'ignore-non-existent-contents' property is set in the YAML file.

rdar://problem/27531549

Added:
cfe/trunk/test/VFS/Inputs/Bar.framework/
cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/
cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h
cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h
cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h
cfe/trunk/test/VFS/Inputs/Bar.framework/Modules/
cfe/trunk/test/VFS/Inputs/Bar.framework/Modules/module.modulemap
cfe/trunk/test/VFS/Inputs/bar-headers.yaml
cfe/trunk/test/VFS/umbrella-framework-import-skipnonexist.m
Modified:
cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=278457&r1=278456&r2=278457&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Thu Aug 11 20:51:04 2016
@@ -1778,29 +1778,47 @@ VFSFromYamlDirIterImpl::VFSFromYamlDirIt
 RedirectingDirectoryEntry::iterator Begin,
 RedirectingDirectoryEntry::iterator End, std::error_code &EC)
 : Dir(_Path.str()), FS(FS), Current(Begin), End(End) {
-  if (Current != End) {
+  while (Current != End) {
 SmallString<128> PathStr(Dir);
 llvm::sys::path::append(PathStr, (*Current)->getName());
 llvm::ErrorOr S = FS.status(PathStr);
-if (S)
+if (S) {
   CurrentEntry = *S;
-else
+  return;
+}
+// Skip entries which do not map to a reliable external content.
+if (FS.ignoreNonExistentContents() &&
+S.getError() == llvm::errc::no_such_file_or_directory) {
+  ++Current;
+  continue;
+} else {
   EC = S.getError();
+  break;
+}
   }
 }
 
 std::error_code VFSFromYamlDirIterImpl::increment() {
   assert(Current != End && "cannot iterate past end");
-  if (++Current != End) {
+  while (++Current != End) {
 SmallString<128> PathStr(Dir);
 llvm::sys::path::append(PathStr, (*Current)->getName());
 llvm::ErrorOr S = FS.status(PathStr);
-if (!S)
-  return S.getError();
+if (!S) {
+  // Skip entries which do not map to a reliable external content.
+  if (FS.ignoreNonExistentContents() &&
+  S.getError() == llvm::errc::no_such_file_or_directory) {
+continue;
+  } else {
+return S.getError();
+  }
+}
 CurrentEntry = *S;
-  } else {
-CurrentEntry = Status();
+break;
   }
+
+  if (Current == End)
+CurrentEntry = Status();
   return std::error_code();
 }
 

Added: cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h?rev=278457&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h (added)
+++ cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/A.h Thu Aug 11 20:51:04 2016
@@ -0,0 +1 @@
+// A.h

Added: cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h?rev=278457&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h (added)
+++ cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/B.h Thu Aug 11 20:51:04 2016
@@ -0,0 +1 @@
+// B.h

Added: cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h?rev=278457&view=auto
==
--- cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h (added)
+++ cfe/trunk/test/VFS/Inputs/Bar.framework/Headers/C.h Thu Aug 11 20:51:04 2016
@@ -0,0 +1 @@
+// C.h

Added: cfe/trunk/test/VFS/Inputs/Bar.framework/Modules/module.modulemap
U

r278456 - [VFS] Add 'ignore-non-existent-contents' field to YAML files

2016-08-11 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Thu Aug 11 20:50:53 2016
New Revision: 278456

URL: http://llvm.org/viewvc/llvm-project?rev=278456&view=rev
Log:
[VFS] Add 'ignore-non-existent-contents' field to YAML files

Add 'ignore-non-existent-contents' to tell the VFS whether an invalid path
obtained via 'external-contents' should cause iteration on the VFS to stop.

If 'true', the VFS should ignore the entry and continue with the next. Allows
YAML files to be shared across multiple compiler invocations regardless of
prior existent paths in 'external-contents'. This global value is overridable
on a per-file basis.

This adds the parsing and write test part, but use by VFS comes next.

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

rdar://problem/27531549

Modified:
cfe/trunk/include/clang/Basic/VirtualFileSystem.h
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
cfe/trunk/test/Modules/crash-vfs-run-reproducer.m
cfe/trunk/test/VFS/Inputs/vfsoverlay2.yaml

Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=278456&r1=278455&r2=278456&view=diff
==
--- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)
+++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Thu Aug 11 20:50:53 2016
@@ -340,6 +340,7 @@ class YAMLVFSWriter {
   Optional IsCaseSensitive;
   Optional IsOverlayRelative;
   Optional UseExternalNames;
+  Optional IgnoreNonExistentContents;
   std::string OverlayDir;
 
 public:
@@ -351,6 +352,9 @@ public:
   void setUseExternalNames(bool UseExtNames) {
 UseExternalNames = UseExtNames;
   }
+  void setIgnoreNonExistentContents(bool IgnoreContents) {
+IgnoreNonExistentContents = IgnoreContents;
+  }
   void setOverlayDir(StringRef OverlayDirectory) {
 IsOverlayRelative = true;
 OverlayDir.assign(OverlayDirectory.str());

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=278456&r1=278455&r2=278456&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Thu Aug 11 20:50:53 2016
@@ -801,6 +801,7 @@ public:
 ///   'case-sensitive': 
 ///   'use-external-names': 
 ///   'overlay-relative': 
+///   'ignore-non-existent-contents': 
 ///
 /// Virtual directories are represented as
 /// \verbatim
@@ -860,6 +861,14 @@ class RedirectingFileSystem : public vfs
   /// \brief Whether to use to use the value of 'external-contents' for the
   /// names of files.  This global value is overridable on a per-file basis.
   bool UseExternalNames = true;
+
+  /// \brief Whether an invalid path obtained via 'external-contents' should
+  /// cause iteration on the VFS to stop. If 'true', the VFS should ignore
+  /// the entry and continue with the next. Allows YAML files to be shared
+  /// across multiple compiler invocations regardless of prior existent
+  /// paths in 'external-contents'. This global value is overridable on a
+  /// per-file basis.
+  bool IgnoreNonExistentContents = true;
   /// @}
 
   /// Virtual file paths and external files could be canonicalized without 
"..",
@@ -937,6 +946,10 @@ public:
 return ExternalContentsPrefixDir;
   }
 
+  bool ignoreNonExistentContents() const {
+return IgnoreNonExistentContents;
+  }
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 LLVM_DUMP_METHOD void dump() const {
 for (const std::unique_ptr &Root : Roots)
@@ -1301,6 +1314,7 @@ public:
   KeyStatusPair("case-sensitive", false),
   KeyStatusPair("use-external-names", false),
   KeyStatusPair("overlay-relative", false),
+  KeyStatusPair("ignore-non-existent-contents", false),
   KeyStatusPair("roots", true),
 };
 
@@ -1359,6 +1373,9 @@ public:
   } else if (Key == "use-external-names") {
 if (!parseScalarBool(I->getValue(), FS->UseExternalNames))
   return false;
+  } else if (Key == "ignore-non-existent-contents") {
+if (!parseScalarBool(I->getValue(), FS->IgnoreNonExistentContents))
+  return false;
   } else {
 llvm_unreachable("key missing from Keys");
   }
@@ -1619,7 +1636,7 @@ public:
   JSONWriter(llvm::raw_ostream &OS) : OS(OS) {}
   void write(ArrayRef Entries, Optional UseExternalNames,
  Optional IsCaseSensitive, Optional IsOverlayRelative,
- StringRef OverlayDir);
+ Optional IgnoreNonExistentContents, StringRef OverlayDir);
 };
 }
 
@@ -1675,6 +1692,7 @@ void JSONWriter::write(ArrayRef UseExternalNames,
Optional IsCaseSensitive,
Optional IsOverlayRelative,
+   Optional IgnoreNonExistentContents,
StringRef OverlayDir

Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Eric Fiselier via cfe-commits
EricWF marked an inline comment as done.


Comment at: lib/Sema/SemaExprCXX.cpp:4775
@@ +4774,3 @@
+  // duration. AObjects with automatic or dynamic lifetime never have
+  // a 'constant initializer'.
+  if ((VD->hasGlobalStorage() ||

I've added docs to LanguageExtensions.rst specifying the semantics I intend for 
the trait.


https://reviews.llvm.org/D23385



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


Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 67790.
EricWF marked an inline comment as done.
EricWF added a comment.

- Add documentation for `__has_constant_initializer` and expression traits in 
general.
- Make expression traits detectable using `__has_extension`.


https://reviews.llvm.org/D23385

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/Expr.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/ExpressionTraits.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/StmtPrinter.cpp
  lib/Lex/PPMacroExpansion.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  test/Lexer/has_extension_cxx.cpp
  test/SemaCXX/expression-traits.cpp

Index: test/SemaCXX/expression-traits.cpp
===
--- test/SemaCXX/expression-traits.cpp
+++ test/SemaCXX/expression-traits.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions %s
-
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions -std=c++14 %s
 //
 // Tests for "expression traits" intrinsics such as __is_lvalue_expr.
 //
@@ -617,3 +617,275 @@
 {
 check_temp_param_6<3,AnInt>();
 }
+
+//===//
+// __has_constant_initializer
+//===//
+struct PODType {
+int value;
+int value2;
+};
+#if __cplusplus >= 201103L
+struct LitType {
+constexpr LitType() : value(0) {}
+constexpr LitType(int x) : value(x) {}
+LitType(void*) : value(-1) {}
+int value;
+};
+#endif
+
+struct NonLit {
+#if __cplusplus >= 201402L
+constexpr NonLit() : value(0) {}
+constexpr NonLit(int x ) : value(x) {}
+#else
+NonLit() : value(0) {}
+NonLit(int x) : value(x) {}
+#endif
+NonLit(void*) : value(-1) {}
+~NonLit() {}
+int value;
+};
+
+struct StoresNonLit {
+#if __cplusplus >= 201402L
+constexpr StoresNonLit() : obj() {}
+constexpr StoresNonLit(int x) : obj(x) {}
+#else
+StoresNonLit() : obj() {}
+StoresNonLit(int x) : obj(x) {}
+#endif
+StoresNonLit(void* p) : obj(p) {}
+NonLit obj;
+};
+
+const bool NonLitHasConstInit =
+#if __cplusplus >= 201402L
+true;
+#else
+false;
+#endif
+
+// Test diagnostics when the argument does not refer to a named identifier
+void check_is_constant_init_bogus()
+{
+(void)__has_constant_initializer(42); // expected-error {{does not reference a named variable}}
+(void)__has_constant_initializer(ReturnInt()); // expected-error {{does not reference a named variable}}
+(void)__has_constant_initializer(42, 43); // expected-error {{does not reference a named variable}}
+}
+
+// [basic.start.static]p2.1
+// if each full-expression (including implicit conversions) that appears in
+// the initializer of a reference with static or thread storage duration is
+// a constant expression (5.20) and the reference is bound to a glvalue
+// designating an object with static storage duration, to a temporary object
+// (see 12.2) or subobject thereof, or to a function;
+
+// Test binding to a static glvalue
+const int glvalue_int = 42;
+const int glvalue_int2 = ReturnInt();
+const int& glvalue_ref = glvalue_int;
+const int& glvalue_ref2 = glvalue_int2;
+static_assert(__has_constant_initializer(glvalue_ref), "");
+static_assert(__has_constant_initializer(glvalue_ref2), "");
+
+__thread const int& glvalue_ref_tl = glvalue_int;
+static_assert(__has_constant_initializer(glvalue_ref_tl), "");
+
+void test_basic_start_static_2_1() {
+const int non_global = 42;
+const int& non_global_ref = non_global;
+static_assert(!__has_constant_initializer(non_global), "automatic variables never have const init");
+static_assert(!__has_constant_initializer(non_global_ref), "automatic variables never have const init");
+
+static const int& local_init = non_global;
+static_assert(!__has_constant_initializer(local_init), "init must be static glvalue");
+static const int& global_init = glvalue_int;
+static_assert(__has_constant_initializer(global_init), "");
+static const int& temp_init = 42;
+static_assert(__has_constant_initializer(temp_init), "");
+#if 0
+/// FIXME: Why is this failing?
+__thread const int& tl_init = 42;
+static_assert(__has_constant_initializer(tl_init), "");
+#endif
+}
+
+const int& temp_ref = 42;
+const int& temp_ref2 = ReturnInt();
+static_assert(__has_constant_initializer(temp_ref), "");
+static_assert(!__has_constant_initializer(temp_ref2), "");
+
+const NonLit& nl_temp_ref = 42;
+static_assert(!__has_constant_initializer(nl_temp_ref), "");
+
+#if __cplusplus >= 201103L
+const LitType& lit_temp_ref = 42;
+static_assert(__has_constant_initializer(lit_temp_ref), "");
+
+const int& subobj_ref = LitType{}.value;
+static_assert(__has_constant_initializer(subobj_ref), "");
+#endif
+
+const int& nl_subobj_ref = NonLit().value;
+s

r278448 - Remove unused and undesirable reference from BindingDecl to DecompositionDecl.

2016-08-11 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 11 19:53:41 2016
New Revision: 278448

URL: http://llvm.org/viewvc/llvm-project?rev=278448&view=rev
Log:
Remove unused and undesirable reference from BindingDecl to DecompositionDecl.

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=278448&r1=278447&r2=278448&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Aug 11 19:53:41 2016
@@ -3385,28 +3385,20 @@ public:
 class BindingDecl : public ValueDecl {
   void anchor() override;
 
-  DecompositionDecl *Decomp;
-
   /// The binding represented by this declaration. References to this
   /// declaration are effectively equivalent to this expression (except
   /// that it is only evaluated once at the point of declaration of the
   /// binding).
   Expr *Binding;
 
-  BindingDecl(DeclContext *DC, DecompositionDecl *Decomp, SourceLocation IdLoc,
-  IdentifierInfo *Id)
-  : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()), Decomp(Decomp),
-Binding(nullptr) {}
+  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
+  : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()), Binding(nullptr) 
{}
 
 public:
   static BindingDecl *Create(ASTContext &C, DeclContext *DC,
- DecompositionDecl *Decomp, SourceLocation IdLoc,
- IdentifierInfo *Id);
+ SourceLocation IdLoc, IdentifierInfo *Id);
   static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
-  void setDecompositionDecl(DecompositionDecl *DD) { Decomp = DD; }
-  DecompositionDecl *getDecompositionDecl() const { return Decomp; }
-
   /// Get the expression to which this declaration is bound. This may be null
   /// in two different cases: while parsing the initializer for the
   /// decomposition declaration, and when the initializer is type-dependent.

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=278448&r1=278447&r2=278448&view=diff
==
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Thu Aug 11 19:53:41 2016
@@ -2309,13 +2309,12 @@ StaticAssertDecl *StaticAssertDecl::Crea
 void BindingDecl::anchor() {}
 
 BindingDecl *BindingDecl::Create(ASTContext &C, DeclContext *DC,
- DecompositionDecl *Decomp,
  SourceLocation IdLoc, IdentifierInfo *Id) {
-  return new (C, DC) BindingDecl(DC, Decomp, IdLoc, Id);
+  return new (C, DC) BindingDecl(DC, IdLoc, Id);
 }
 
 BindingDecl *BindingDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  return new (C, ID) BindingDecl(nullptr, nullptr, SourceLocation(), nullptr);
+  return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
 }
 
 void DecompositionDecl::anchor() {}

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=278448&r1=278447&r2=278448&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Aug 11 19:53:41 2016
@@ -6107,12 +6107,9 @@ NamedDecl *Sema::ActOnVariableDeclarator
   NewVD = cast(Res.get());
   AddToScope = false;
 } else if (D.isDecompositionDeclarator()) {
-  auto *NewDD = DecompositionDecl::Create(Context, DC, D.getLocStart(),
-  D.getIdentifierLoc(), R, TInfo,
-  SC, Bindings);
-  for (auto *B : Bindings)
-B->setDecompositionDecl(NewDD);
-  NewVD = NewDD;
+  NewVD = DecompositionDecl::Create(Context, DC, D.getLocStart(),
+D.getIdentifierLoc(), R, TInfo, SC,
+Bindings);
 } else
   NewVD = VarDecl::Create(Context, DC, D.getLocStart(),
   D.getIdentifierLoc(), II, R, TInfo, SC);

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=278448&r1=278447&r2=278448&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Aug 11 19:53:41 2016
@@ -791,7 +791,7 @@ Sema::ActOnDecompositionDeclarator(Scope
   Diag(Old->getLocation(), diag::note_previous_definition);
 }
 
-auto *BD = BindingDecl:

r278447 - P0217R3: Constant expression evaluation for decomposition declarations.

2016-08-11 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 11 19:39:32 2016
New Revision: 278447

URL: http://llvm.org/viewvc/llvm-project?rev=278447&view=rev
Log:
P0217R3: Constant expression evaluation for decomposition declarations.

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p2.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p4.cpp
cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=278447&r1=278446&r2=278447&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Aug 11 19:39:32 2016
@@ -3385,20 +3385,28 @@ public:
 class BindingDecl : public ValueDecl {
   void anchor() override;
 
+  DecompositionDecl *Decomp;
+
   /// The binding represented by this declaration. References to this
   /// declaration are effectively equivalent to this expression (except
   /// that it is only evaluated once at the point of declaration of the
   /// binding).
   Expr *Binding;
 
-  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
-  : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()), Binding(nullptr) 
{}
+  BindingDecl(DeclContext *DC, DecompositionDecl *Decomp, SourceLocation IdLoc,
+  IdentifierInfo *Id)
+  : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()), Decomp(Decomp),
+Binding(nullptr) {}
 
 public:
   static BindingDecl *Create(ASTContext &C, DeclContext *DC,
- SourceLocation IdLoc, IdentifierInfo *Id);
+ DecompositionDecl *Decomp, SourceLocation IdLoc,
+ IdentifierInfo *Id);
   static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
+  void setDecompositionDecl(DecompositionDecl *DD) { Decomp = DD; }
+  DecompositionDecl *getDecompositionDecl() const { return Decomp; }
+
   /// Get the expression to which this declaration is bound. This may be null
   /// in two different cases: while parsing the initializer for the
   /// decomposition declaration, and when the initializer is type-dependent.

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=278447&r1=278446&r2=278447&view=diff
==
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Thu Aug 11 19:39:32 2016
@@ -2309,12 +2309,13 @@ StaticAssertDecl *StaticAssertDecl::Crea
 void BindingDecl::anchor() {}
 
 BindingDecl *BindingDecl::Create(ASTContext &C, DeclContext *DC,
+ DecompositionDecl *Decomp,
  SourceLocation IdLoc, IdentifierInfo *Id) {
-  return new (C, DC) BindingDecl(DC, IdLoc, Id);
+  return new (C, DC) BindingDecl(DC, Decomp, IdLoc, Id);
 }
 
 BindingDecl *BindingDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
+  return new (C, ID) BindingDecl(nullptr, nullptr, SourceLocation(), nullptr);
 }
 
 void DecompositionDecl::anchor() {}

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=278447&r1=278446&r2=278447&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Aug 11 19:39:32 2016
@@ -3427,6 +3427,18 @@ static bool EvaluateDecl(EvalInfo &Info,
   Val = APValue();
   return false;
 }
+
+// Evaluate initializers for any structured bindings.
+if (auto *DD = dyn_cast(VD)) {
+  for (auto *BD : DD->bindings()) {
+APValue &Val = Info.CurrentCall->createTemporary(BD, true);
+
+LValue Result;
+if (!EvaluateLValue(BD->getBinding(), Result, Info))
+  return false;
+Result.moveInto(Val);
+  }
+}
   }
 
   return true;
@@ -4724,6 +4736,7 @@ public:
 LValueExprEvaluatorBaseTy(Info, Result) {}
 
   bool VisitVarDecl(const Expr *E, const VarDecl *VD);
+  bool VisitBindingDecl(const Expr *E, const BindingDecl *BD);
   bool VisitUnaryPreIncDec(const UnaryOperator *UO);
 
   bool VisitDeclRefExpr(const DeclRefExpr *E);
@@ -4785,6 +4798,8 @@ bool LValueExprEvaluator::VisitDeclRefEx
 return Success(FD);
   if (const VarDecl *VD = dyn_cast(E->getDecl()))
 return VisitVarDecl(E, VD);
+  if (const BindingDecl *BD = dyn_cast(E->getDecl()))
+return VisitBindingDecl(E, BD);
   return Error(E);
 }
 
@@ -48

Re: [PATCH] D23433: [Basic] Add missing `const` qualifier (NFC)

2016-08-11 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL278444: [Basic] Add const qualifier to SM.isInSystemMacro 
(NFC) (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D23433?vs=67737&id=67781#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23433

Files:
  cfe/trunk/include/clang/Basic/SourceManager.h

Index: cfe/trunk/include/clang/Basic/SourceManager.h
===
--- cfe/trunk/include/clang/Basic/SourceManager.h
+++ cfe/trunk/include/clang/Basic/SourceManager.h
@@ -1357,7 +1357,7 @@
   }
 
   /// \brief Returns whether \p Loc is expanded from a macro in a system 
header.
-  bool isInSystemMacro(SourceLocation loc) {
+  bool isInSystemMacro(SourceLocation loc) const {
 return loc.isMacroID() && isInSystemHeader(getSpellingLoc(loc));
   }
 


Index: cfe/trunk/include/clang/Basic/SourceManager.h
===
--- cfe/trunk/include/clang/Basic/SourceManager.h
+++ cfe/trunk/include/clang/Basic/SourceManager.h
@@ -1357,7 +1357,7 @@
   }
 
   /// \brief Returns whether \p Loc is expanded from a macro in a system header.
-  bool isInSystemMacro(SourceLocation loc) {
+  bool isInSystemMacro(SourceLocation loc) const {
 return loc.isMacroID() && isInSystemHeader(getSpellingLoc(loc));
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r278444 - [Basic] Add const qualifier to SM.isInSystemMacro (NFC)

2016-08-11 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Thu Aug 11 19:20:39 2016
New Revision: 278444

URL: http://llvm.org/viewvc/llvm-project?rev=278444&view=rev
Log:
[Basic] Add const qualifier to SM.isInSystemMacro (NFC)

The member function is a predicate, and doesn't apply any changes on the
object.

Patch by Visoiu Mistrih Francis!

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

Modified:
cfe/trunk/include/clang/Basic/SourceManager.h

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=278444&r1=278443&r2=278444&view=diff
==
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Thu Aug 11 19:20:39 2016
@@ -1357,7 +1357,7 @@ public:
   }
 
   /// \brief Returns whether \p Loc is expanded from a macro in a system 
header.
-  bool isInSystemMacro(SourceLocation loc) {
+  bool isInSystemMacro(SourceLocation loc) const {
 return loc.isMacroID() && isInSystemHeader(getSpellingLoc(loc));
   }
 


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


Re: [PATCH] D23434: Don't allow llvm-include-order to intermingle includes from different files.

2016-08-11 Thread Zachary Turner via cfe-commits
zturner updated this revision to Diff 6.
zturner added a comment.

Seems like dropping all non-main-file include directives is wrong because then 
it won't be able to detect errors in "non user code".  Seems like the real fix 
is to bucket the include directives by file in which they were declared in, and 
then process each bucket in order.  This way we process all include directives, 
including those in non-user code, but block analysis is done at a per-file 
level.


https://reviews.llvm.org/D23434

Files:
  clang-tidy/llvm/IncludeOrderCheck.cpp
  test/clang-tidy/Inputs/Headers/cross-file-a.h
  test/clang-tidy/Inputs/Headers/cross-file-b.h
  test/clang-tidy/Inputs/Headers/cross-file-c.h
  test/clang-tidy/llvm-include-order.cpp

Index: test/clang-tidy/llvm-include-order.cpp
===
--- test/clang-tidy/llvm-include-order.cpp
+++ test/clang-tidy/llvm-include-order.cpp
@@ -35,3 +35,8 @@
 
 // CHECK-FIXES: #include "a.h"
 // CHECK-FIXES-NEXT: #include "b.h"
+
+// CHECK-MESSAGES-NOT: [[@LINE+1]]:1: warning: #includes are not sorted properly
+#include "cross-file-c.h"
+// This line number should correspond to the position of the #include in cross-file-c.h
+#include "cross-file-a.h"
Index: test/clang-tidy/Inputs/Headers/cross-file-c.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/Headers/cross-file-c.h
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// The line number of the following include should match the location of the
+// corresponding comment in llvm-include-order.cpp
+#include "cross-file-b.h"
Index: clang-tidy/llvm/IncludeOrderCheck.cpp
===
--- clang-tidy/llvm/IncludeOrderCheck.cpp
+++ clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -12,6 +12,8 @@
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 
+#include 
+
 namespace clang {
 namespace tidy {
 namespace llvm {
@@ -37,7 +39,9 @@
 bool IsAngled; ///< true if this was an include with angle brackets
 bool IsMainModule; ///< true if this was the first include in a file
   };
-  std::vector IncludeDirectives;
+
+  typedef std::vector FileIncludes;
+  std::map IncludeDirectives;
   bool LookForMainModule;
 
   ClangTidyCheck &Check;
@@ -80,7 +84,9 @@
 ID.IsMainModule = true;
 LookForMainModule = false;
   }
-  IncludeDirectives.push_back(std::move(ID));
+
+  // Bucket the include directives by the id of the file they were declared in.
+  IncludeDirectives[SM.getFileID(HashLoc)].push_back(std::move(ID));
 }
 
 void IncludeOrderPPCallbacks::EndOfMainFile() {
@@ -95,69 +101,73 @@
   // FIXME: We should be more careful about sorting below comments as we don't
   // know if the comment refers to the next include or the whole block that
   // follows.
-  std::vector Blocks(1, 0);
-  for (unsigned I = 1, E = IncludeDirectives.size(); I != E; ++I)
-if (SM.getExpansionLineNumber(IncludeDirectives[I].Loc) !=
-SM.getExpansionLineNumber(IncludeDirectives[I - 1].Loc) + 1)
-  Blocks.push_back(I);
-  Blocks.push_back(IncludeDirectives.size()); // Sentinel value.
-
-  // Get a vector of indices.
-  std::vector IncludeIndices;
-  for (unsigned I = 0, E = IncludeDirectives.size(); I != E; ++I)
-IncludeIndices.push_back(I);
-
-  // Sort the includes. We first sort by priority, then lexicographically.
-  for (unsigned BI = 0, BE = Blocks.size() - 1; BI != BE; ++BI)
-std::sort(IncludeIndices.begin() + Blocks[BI],
-  IncludeIndices.begin() + Blocks[BI + 1],
-  [this](unsigned LHSI, unsigned RHSI) {
-  IncludeDirective &LHS = IncludeDirectives[LHSI];
-  IncludeDirective &RHS = IncludeDirectives[RHSI];
-
-  int PriorityLHS =
-  getPriority(LHS.Filename, LHS.IsAngled, LHS.IsMainModule);
-  int PriorityRHS =
-  getPriority(RHS.Filename, RHS.IsAngled, RHS.IsMainModule);
-
-  return std::tie(PriorityLHS, LHS.Filename) <
- std::tie(PriorityRHS, RHS.Filename);
-});
-
-  // Emit a warning for each block and fixits for all changes within that block.
-  for (unsigned BI = 0, BE = Blocks.size() - 1; BI != BE; ++BI) {
-// Find the first include that's not in the right position.
-unsigned I, E;
-for (I = Blocks[BI], E = Blocks[BI + 1]; I != E; ++I)
-  if (IncludeIndices[I] != I)
-break;
-
-if (I == E)
-  continue;
-
-// Emit a warning.
-auto D = Check.diag(IncludeDirectives[I].Loc,
-"#includes are not sorted properly");
-
-// Emit fix-its for all following includes in this block.
-for (; I != E; ++I) {
-  if (IncludeIndices[I] == I)
+  for (auto &Bucket : IncludeDirectives) {
+auto &FileDirectives = Bucket.second;
+std::vector Blocks(1, 0);
+for (unsigned I = 1, E = FileDirectives.size(); I != E; ++I)
+  if (SM.getExpansionLi

Re: [PATCH] D23397: [clang-rename] cleanup `auto` usages

2016-08-11 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

A couple of comments inline.



Comment at: clang-rename/RenamingAction.cpp:73
@@ -72,3 +72,3 @@
   // FIXME: better error handling.
-  auto Replace = tooling::Replacement(SourceMgr, Loc, PrevNameLen, 
NewName);
-  auto Err = FileToReplaces[Replace.getFilePath()].add(Replace);
+  tooling::Replacement Replace =
+  tooling::Replacement(SourceMgr, Loc, PrevNameLen, NewName);

Just remove the ` = tooling::Replacement` part.


Comment at: clang-rename/USRFinder.cpp:78
@@ +77,3 @@
+const SourceLocation TypeBeginLoc = Loc.getBeginLoc(),
+ TypeEndLoc = Lexer::getLocForEndOfToken(
+ TypeBeginLoc, 0, Context.getSourceManager(),

Look, when you join these two declarations, the code becomes slightly less 
clear, slightly worse formatted and takes a bit more screen space. And I don't 
think any aspects of the code improve with this change. Seems like a net loss?


Comment at: clang-rename/USRLocFinder.cpp:130
@@ -128,4 +129,3 @@
   void checkAndAddLocation(SourceLocation Loc) {
-const auto BeginLoc = Loc;
-const auto EndLoc = Lexer::getLocForEndOfToken(
-BeginLoc, 0, Context.getSourceManager(), Context.getLangOpts());
+const SourceLocation BeginLoc = Loc,
+ EndLoc = Lexer::getLocForEndOfToken(

Same problem with multiple values per declaration here.


https://reviews.llvm.org/D23397



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


Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 67776.
EricWF added a comment.

- Apply @jroelof's suggestions
- Add tests for static class members


https://reviews.llvm.org/D23385

Files:
  include/clang/AST/Expr.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/ExpressionTraits.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/StmtPrinter.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/expression-traits.cpp

Index: test/SemaCXX/expression-traits.cpp
===
--- test/SemaCXX/expression-traits.cpp
+++ test/SemaCXX/expression-traits.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions %s
-
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions -std=c++14 %s
 //
 // Tests for "expression traits" intrinsics such as __is_lvalue_expr.
 //
@@ -617,3 +617,275 @@
 {
 check_temp_param_6<3,AnInt>();
 }
+
+//===//
+// __has_constant_initializer
+//===//
+struct PODType {
+int value;
+int value2;
+};
+#if __cplusplus >= 201103L
+struct LitType {
+constexpr LitType() : value(0) {}
+constexpr LitType(int x) : value(x) {}
+LitType(void*) : value(-1) {}
+int value;
+};
+#endif
+
+struct NonLit {
+#if __cplusplus >= 201402L
+constexpr NonLit() : value(0) {}
+constexpr NonLit(int x ) : value(x) {}
+#else
+NonLit() : value(0) {}
+NonLit(int x) : value(x) {}
+#endif
+NonLit(void*) : value(-1) {}
+~NonLit() {}
+int value;
+};
+
+struct StoresNonLit {
+#if __cplusplus >= 201402L
+constexpr StoresNonLit() : obj() {}
+constexpr StoresNonLit(int x) : obj(x) {}
+#else
+StoresNonLit() : obj() {}
+StoresNonLit(int x) : obj(x) {}
+#endif
+StoresNonLit(void* p) : obj(p) {}
+NonLit obj;
+};
+
+const bool NonLitHasConstInit =
+#if __cplusplus >= 201402L
+true;
+#else
+false;
+#endif
+
+// Test diagnostics when the argument does not refer to a named identifier
+void check_is_constant_init_bogus()
+{
+(void)__has_constant_initializer(42); // expected-error {{does not reference a named variable}}
+(void)__has_constant_initializer(ReturnInt()); // expected-error {{does not reference a named variable}}
+(void)__has_constant_initializer(42, 43); // expected-error {{does not reference a named variable}}
+}
+
+// [basic.start.static]p2.1
+// if each full-expression (including implicit conversions) that appears in
+// the initializer of a reference with static or thread storage duration is
+// a constant expression (5.20) and the reference is bound to a glvalue
+// designating an object with static storage duration, to a temporary object
+// (see 12.2) or subobject thereof, or to a function;
+
+// Test binding to a static glvalue
+const int glvalue_int = 42;
+const int glvalue_int2 = ReturnInt();
+const int& glvalue_ref = glvalue_int;
+const int& glvalue_ref2 = glvalue_int2;
+static_assert(__has_constant_initializer(glvalue_ref), "");
+static_assert(__has_constant_initializer(glvalue_ref2), "");
+
+__thread const int& glvalue_ref_tl = glvalue_int;
+static_assert(__has_constant_initializer(glvalue_ref_tl), "");
+
+void test_basic_start_static_2_1() {
+const int non_global = 42;
+const int& non_global_ref = non_global;
+static_assert(!__has_constant_initializer(non_global), "automatic variables never have const init");
+static_assert(!__has_constant_initializer(non_global_ref), "automatic variables never have const init");
+
+static const int& local_init = non_global;
+static_assert(!__has_constant_initializer(local_init), "init must be static glvalue");
+static const int& global_init = glvalue_int;
+static_assert(__has_constant_initializer(global_init), "");
+static const int& temp_init = 42;
+static_assert(__has_constant_initializer(temp_init), "");
+#if 0
+/// FIXME: Why is this failing?
+__thread const int& tl_init = 42;
+static_assert(__has_constant_initializer(tl_init), "");
+#endif
+}
+
+const int& temp_ref = 42;
+const int& temp_ref2 = ReturnInt();
+static_assert(__has_constant_initializer(temp_ref), "");
+static_assert(!__has_constant_initializer(temp_ref2), "");
+
+const NonLit& nl_temp_ref = 42;
+static_assert(!__has_constant_initializer(nl_temp_ref), "");
+
+#if __cplusplus >= 201103L
+const LitType& lit_temp_ref = 42;
+static_assert(__has_constant_initializer(lit_temp_ref), "");
+
+const int& subobj_ref = LitType{}.value;
+static_assert(__has_constant_initializer(subobj_ref), "");
+#endif
+
+const int& nl_subobj_ref = NonLit().value;
+static_assert(!__has_constant_initializer(nl_subobj_ref), "");
+
+struct TT1 {
+  static const int& no_init;
+  static const int& glvalue_init;
+  static const int& temp_init;
+  static const int& subobj_init;
+#if __cp

Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Jonathan Roelofs via cfe-commits
jroelofs added inline comments.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6807
@@ +6806,3 @@
+
+def err_has_constant_init_expression_trait_invalid_arg : Error<
+  "expression does not reference a named variable">;

EricWF wrote:
> Help improving this wording would be appreciated.
`"expression must be a named variable"`, maybe?

A "counterexample" to the original wording is `__has_constant_initializer(x+1)`.


Comment at: lib/Sema/SemaExprCXX.cpp:4775
@@ +4774,3 @@
+  // a 'constant initializer'.
+  else if ((VD->hasGlobalStorage() ||
+  VD->getTLSKind() != VarDecl::TLS_None) && VD->hasInit()) {

EricWF wrote:
> EricWF wrote:
> > jroelofs wrote:
> > > no else after return.
> > > 
> > > Also, what do you want this to do for `ParmVarDecl`s that happen to have 
> > > an initializer? i.e:
> > > 
> > > ```
> > > void foo(int i = 45) {}
> > > ```
> > I believe that case should return false. `i` isn't static or thread local 
> > so it doesn't have a "constant initializer" according to 
> > [basic.start.static].
> > 
> Perhaps using `__has_constant_initializer` should emit a diagnostic when used 
> on non-static, non-thread-local objects?
//Maybe// a warning... And you might want it to behave differently when it 
comes from a macro expansion. I'm not sure what the norm is for that sort of 
thing though.

I think the more important thing at this point is to precisely document what 
you want the behavior to be in the docs. Then any difference from that spec is 
"just a compiler bug", rather than potentially being a breaking change in 
behavior for someone who used your API in a way that you didn't expect.


https://reviews.llvm.org/D23385



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


Re: [PATCH] D23387: [Analyzer] Report found fields order in PaddingChecker.

2016-08-11 Thread Alexander Shaposhnikov via cfe-commits
alexshap added a comment.

toy example: F2262237: toy_example.png 


https://reviews.llvm.org/D23387



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


Re: [PATCH] D23433: [Basic] Add missing `const` qualifier (NFC)

2016-08-11 Thread Visoiu Mistrih Francis via cfe-commits
thegameg added a comment.

Thanks @vsk. As I don't have commit access, is it possible to commit this for 
me, please? Thanks.


https://reviews.llvm.org/D23433



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


Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Eric Fiselier via cfe-commits
EricWF added inline comments.


Comment at: lib/Sema/SemaExprCXX.cpp:4775
@@ +4774,3 @@
+  // a 'constant initializer'.
+  else if ((VD->hasGlobalStorage() ||
+  VD->getTLSKind() != VarDecl::TLS_None) && VD->hasInit()) {

EricWF wrote:
> jroelofs wrote:
> > no else after return.
> > 
> > Also, what do you want this to do for `ParmVarDecl`s that happen to have an 
> > initializer? i.e:
> > 
> > ```
> > void foo(int i = 45) {}
> > ```
> I believe that case should return false. `i` isn't static or thread local so 
> it doesn't have a "constant initializer" according to [basic.start.static].
> 
Perhaps using `__has_constant_initializer` should emit a diagnostic when used 
on non-static, non-thread-local objects?


https://reviews.llvm.org/D23385



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


Re: [PATCH] D23387: [Analyzer] Report found fields order in PaddingChecker.

2016-08-11 Thread Alexander Shaposhnikov via cfe-commits
alexshap updated this revision to Diff 67773.
alexshap added a comment.

Use more stable sort (preserving the original order if possible).
Change the format of the report.
Update the tests.
I have not turned it to "note:" or "remark:" because in this case 
it's not included into the description and it's not being displayed by 
scan-build
(not very convenient).


https://reviews.llvm.org/D23387

Files:
  lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  test/Analysis/padding_message.cpp

Index: test/Analysis/padding_message.cpp
===
--- test/Analysis/padding_message.cpp
+++ test/Analysis/padding_message.cpp
@@ -1,13 +1,25 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux -std=c++14 -analyze -analyzer-checker=optin.performance -analyzer-config optin.performance.Padding:AllowedPad=2 -verify %s
 
-// expected-warning@+1{{Excessive padding in 'struct IntSandwich' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct IntSandwich' (6 padding bytes, where 2 is optimal).\
+Optimal fields order:\
+int i \
+char c1 \
+char c2 \
+}}
 struct IntSandwich {
   char c1;
   int i;
   char c2;
 };
 
-// expected-warning@+1{{Excessive padding in 'struct TurDuckHen' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct TurDuckHen' (6 padding bytes, where 2 is optimal).\
+Optimal fields order:\
+struct IntSandwich i \
+char c1 \
+char c2 \
+}}
 struct TurDuckHen {
   char c1;
   struct IntSandwich i;
@@ -16,7 +28,17 @@
 
 #pragma pack(push)
 #pragma pack(2)
-// expected-warning@+1{{Excessive padding in 'struct SmallIntSandwich' (4 padding bytes, where 0 is optimal)}}
+// expected-warning@+11{{\
+Excessive padding in 'struct SmallIntSandwich' (4 padding bytes, where 0 is optimal).\
+Optimal fields order:\
+int i1 \
+int i2 \
+int i3 \
+char c1 \
+char c2 \
+char c3 \
+char c4 \
+}}
 struct SmallIntSandwich {
   char c1;
   int i1;
@@ -34,7 +56,13 @@
   int i;
 };
 
-// expected-warning@+1{{Excessive padding in 'struct HoldsAUnion' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct HoldsAUnion' (6 padding bytes, where 2 is optimal).\
+Optimal fields order:\
+union SomeUnion u \
+char c1 \
+char c2 \
+}}
 struct HoldsAUnion {
   char c1;
   union SomeUnion u;
@@ -49,28 +77,53 @@
   int i[5];
 };
 
-// expected-warning@+1{{Excessive padding in 'struct StructSandwich' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct StructSandwich' (6 padding bytes, where 2 is optimal).\
+Optimal fields order:\
+struct MediumIntArray m \
+struct SmallCharArray s \
+struct SmallCharArray s2 \
+}}
 struct StructSandwich {
   struct SmallCharArray s;
   struct MediumIntArray m;
   struct SmallCharArray s2;
 };
 
-// expected-warning@+1{{Excessive padding in 'TypedefSandwich' (6 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'TypedefSandwich' (6 padding bytes, where 2 is optimal).\
+Optimal fields order:\
+int i \
+char c1 \
+char c2 \
+}}
 typedef struct {
   char c1;
   int i;
   char c2;
 } TypedefSandwich;
 
-// expected-warning@+1{{Excessive padding in 'struct StructAttrAlign' (10 padding bytes, where 2 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct StructAttrAlign' (10 padding bytes, where 2 is optimal).\
+Optimal fields order:\
+int i \
+char c1 \
+char c2 \
+}}
 struct StructAttrAlign {
   char c1;
   int i;
   char c2;
 } __attribute__((aligned(8)));
 
-// expected-warning@+1{{Excessive padding in 'struct OverlyAlignedChar' (8185 padding bytes, where 4089 is optimal)}}
+// expected-warning@+8{{\
+Excessive padding in 'struct OverlyAlignedChar' (8185 padding bytes, where 4089 is optimal).\
+Optimal fields order:\
+char c \
+char c1 \
+char c2 \
+int x \
+}}
 struct OverlyAlignedChar {
   char c1;
   int x;
@@ -78,7 +131,13 @@
   char c __attribute__((aligned(4096)));
 };
 
-// expected-warning@+1{{Excessive padding in 'struct HoldsOverlyAlignedChar' (8190 padding bytes, where 4094 is optimal)}}
+// expected-warning@+7{{\
+Excessive padding in 'struct HoldsOverlyAlignedChar' (8190 padding bytes, where 4094 is optimal).\
+Optimal fields order:\
+struct OverlyAlignedChar o \
+char c1 \
+char c2 \
+}}
 struct HoldsOverlyAlignedChar {
   char c1;
   struct OverlyAlignedChar o;
@@ -86,7 +145,13 @@
 };
 
 void internalStructFunc() {
-  // expected-warning@+1{{Excessive padding in 'struct X' (6 padding bytes, where 2 is optimal)}}
+  // expected-warning@+7{{\
+Excessive padding in 'struct X' (6 padding bytes, where 2 is optimal).\
+Optimal fields order:\
+int t \
+char c1 \
+char c2 \
+}}
   struct X {
 char c1;
 int t;
@@ -96,7 +161,13 @@
 }
 
 void typedefStructFunc() {
-  // expected-warning@+1{{Excessive padding in 'S' (6 padding bytes, where 2 is optimal)}}
+  // expected-warning@+7{{\
+Excessive padding in 'S' (6 padding bytes, where 2 i

Re: [PATCH] D23434: Don't allow llvm-include-order to intermingle includes from different files.

2016-08-11 Thread Zachary Turner via cfe-commits
zturner updated this revision to Diff 67772.
zturner added a comment.

Fixed the test for this.  Confirmed that it fails before the patch and succeeds 
after the patch.


https://reviews.llvm.org/D23434

Files:
  clang-tidy/llvm/IncludeOrderCheck.cpp
  test/clang-tidy/Inputs/Headers/cross-file-a.h
  test/clang-tidy/Inputs/Headers/cross-file-b.h
  test/clang-tidy/Inputs/Headers/cross-file-c.h
  test/clang-tidy/llvm-include-order.cpp

Index: test/clang-tidy/llvm-include-order.cpp
===
--- test/clang-tidy/llvm-include-order.cpp
+++ test/clang-tidy/llvm-include-order.cpp
@@ -35,3 +35,8 @@
 
 // CHECK-FIXES: #include "a.h"
 // CHECK-FIXES-NEXT: #include "b.h"
+
+// CHECK-MESSAGES-NOT: [[@LINE+1]]:1: warning: #includes are not sorted 
properly
+#include "cross-file-c.h"
+
+#include "cross-file-a.h"
Index: test/clang-tidy/Inputs/Headers/cross-file-c.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/Headers/cross-file-c.h
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "cross-file-b.h"
Index: clang-tidy/llvm/IncludeOrderCheck.cpp
===
--- clang-tidy/llvm/IncludeOrderCheck.cpp
+++ clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -73,6 +73,9 @@
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
 StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  if (SM.getFileID(HashLoc) != SM.getMainFileID())
+return;
+
   // We recognize the first include as a special main module header and want
   // to leave it in the top position.
   IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled, false};


Index: test/clang-tidy/llvm-include-order.cpp
===
--- test/clang-tidy/llvm-include-order.cpp
+++ test/clang-tidy/llvm-include-order.cpp
@@ -35,3 +35,8 @@
 
 // CHECK-FIXES: #include "a.h"
 // CHECK-FIXES-NEXT: #include "b.h"
+
+// CHECK-MESSAGES-NOT: [[@LINE+1]]:1: warning: #includes are not sorted properly
+#include "cross-file-c.h"
+
+#include "cross-file-a.h"
Index: test/clang-tidy/Inputs/Headers/cross-file-c.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/Headers/cross-file-c.h
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "cross-file-b.h"
Index: clang-tidy/llvm/IncludeOrderCheck.cpp
===
--- clang-tidy/llvm/IncludeOrderCheck.cpp
+++ clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -73,6 +73,9 @@
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
 StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  if (SM.getFileID(HashLoc) != SM.getMainFileID())
+return;
+
   // We recognize the first include as a special main module header and want
   // to leave it in the top position.
   IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled, false};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Eric Fiselier via cfe-commits
EricWF marked an inline comment as done.


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6807
@@ +6806,3 @@
+
+def err_has_constant_init_expression_trait_invalid_arg : Error<
+  "expression does not reference a named variable">;

Help improving this wording would be appreciated.


Comment at: lib/Sema/SemaExprCXX.cpp:4775
@@ +4774,3 @@
+  // a 'constant initializer'.
+  else if ((VD->hasGlobalStorage() ||
+  VD->getTLSKind() != VarDecl::TLS_None) && VD->hasInit()) {

jroelofs wrote:
> no else after return.
> 
> Also, what do you want this to do for `ParmVarDecl`s that happen to have an 
> initializer? i.e:
> 
> ```
> void foo(int i = 45) {}
> ```
I believe that case should return false. `i` isn't static or thread local so it 
doesn't have a "constant initializer" according to [basic.start.static].



https://reviews.llvm.org/D23385



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


Re: [PATCH] D23420: libcxx: Fix libcxx test on aarch64 with libunwind

2016-08-11 Thread Adhemerval Zanella via cfe-commits
zatrazz added a comment.

I tried to find why exactly libgcc has to appear before and after but I 
couldn't get any information from commit history. On my system (aarch64/linux) 
I am also getting "-lc++" "-lm" "-lgcc_s" "-lgcc" "-lpthread" "-lc" "-lgcc_s" 
"-lgcc".

I think we can got by the safe side and just add the final libgcc at the end 
for the soft-fp symbols.


https://reviews.llvm.org/D23420



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


[PATCH] D23434: Don't allow llvm-include-order to intermingle includes from different files.

2016-08-11 Thread Zachary Turner via cfe-commits
zturner created this revision.
zturner added reviewers: alexfh, djasper.
zturner added a subscriber: cfe-commits.

See llvm.org/pr28943 for some context.

I'm not sure if this is the right fix, but it seems to pass the test suite for 
me.

https://reviews.llvm.org/D23434

Files:
  clang-tidy/llvm/IncludeOrderCheck.cpp
  test/clang-tidy/Inputs/Headers/cross-file-a.h
  test/clang-tidy/Inputs/Headers/cross-file-b.h
  test/clang-tidy/Inputs/Headers/cross-file-c.h
  test/clang-tidy/llvm-include-order.cpp

Index: test/clang-tidy/llvm-include-order.cpp
===
--- test/clang-tidy/llvm-include-order.cpp
+++ test/clang-tidy/llvm-include-order.cpp
@@ -35,3 +35,8 @@
 
 // CHECK-FIXES: #include "a.h"
 // CHECK-FIXES-NEXT: #include "b.h"
+
+// CHECK-MESSAGES-NOT: [[@LINE+1]]:1: warning: #includes are not sorted 
properly
+#include "cross-file-a.h"
+
+#include "cross-file-c.h"
Index: test/clang-tidy/Inputs/Headers/cross-file-c.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/Headers/cross-file-c.h
@@ -0,0 +1,2 @@
+
+#include "cross-file-b.h"
Index: clang-tidy/llvm/IncludeOrderCheck.cpp
===
--- clang-tidy/llvm/IncludeOrderCheck.cpp
+++ clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -73,6 +73,9 @@
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
 StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  if (SM.getFileID(HashLoc) != SM.getMainFileID())
+return;
+
   // We recognize the first include as a special main module header and want
   // to leave it in the top position.
   IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled, false};


Index: test/clang-tidy/llvm-include-order.cpp
===
--- test/clang-tidy/llvm-include-order.cpp
+++ test/clang-tidy/llvm-include-order.cpp
@@ -35,3 +35,8 @@
 
 // CHECK-FIXES: #include "a.h"
 // CHECK-FIXES-NEXT: #include "b.h"
+
+// CHECK-MESSAGES-NOT: [[@LINE+1]]:1: warning: #includes are not sorted properly
+#include "cross-file-a.h"
+
+#include "cross-file-c.h"
Index: test/clang-tidy/Inputs/Headers/cross-file-c.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/Headers/cross-file-c.h
@@ -0,0 +1,2 @@
+
+#include "cross-file-b.h"
Index: clang-tidy/llvm/IncludeOrderCheck.cpp
===
--- clang-tidy/llvm/IncludeOrderCheck.cpp
+++ clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -73,6 +73,9 @@
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
 StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  if (SM.getFileID(HashLoc) != SM.getMainFileID())
+return;
+
   // We recognize the first include as a special main module header and want
   // to leave it in the top position.
   IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled, false};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Jonathan Roelofs via cfe-commits
jroelofs added a comment.

One more thing: need to add docs to `clang/docs/LanguageExtensions.rst`.


https://reviews.llvm.org/D23385



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


Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Jonathan Roelofs via cfe-commits
jroelofs added a subscriber: jroelofs.


Comment at: lib/AST/Expr.cpp:2656
@@ +2655,3 @@
+AllowNonLiteral)) {
+if (!CE->getNumArgs()) return true;
+unsigned numArgs = CE->getNumArgs();

no need for this `if`.

Also, I think the `for` should be written:

```
for (auto *Arg : CE->arguments())
  if (Arg->isConstantInitializer(Ctx, false, Culprit))
return false;
```


Comment at: lib/Sema/SemaExprCXX.cpp:4775
@@ +4774,3 @@
+  // a 'constant initializer'.
+  else if ((VD->hasGlobalStorage() ||
+  VD->getTLSKind() != VarDecl::TLS_None) && VD->hasInit()) {

no else after return.

Also, what do you want this to do for `ParmVarDecl`s that happen to have an 
initializer? i.e:

```
void foo(int i = 45) {}
```


https://reviews.llvm.org/D23385



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


Re: [PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

2016-08-11 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 67768.
EricWF added a comment.

Re-flow comments because I suck at English.


https://reviews.llvm.org/D23385

Files:
  include/clang/AST/Expr.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/ExpressionTraits.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/StmtPrinter.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/expression-traits.cpp

Index: test/SemaCXX/expression-traits.cpp
===
--- test/SemaCXX/expression-traits.cpp
+++ test/SemaCXX/expression-traits.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions %s
-
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions -std=c++14 %s
 //
 // Tests for "expression traits" intrinsics such as __is_lvalue_expr.
 //
@@ -617,3 +617,219 @@
 {
 check_temp_param_6<3,AnInt>();
 }
+
+//===//
+// __has_constant_initializer
+//===//
+struct PODType {
+int value;
+int value2;
+};
+#if __cplusplus >= 201103L
+struct LitType {
+constexpr LitType() : value(0) {}
+constexpr LitType(int x) : value(x) {}
+LitType(void*) : value(-1) {}
+int value;
+};
+#endif
+
+struct NonLit {
+#if __cplusplus >= 201402L
+constexpr NonLit() : value(0) {}
+constexpr NonLit(int x ) : value(x) {}
+#else
+NonLit() : value(0) {}
+NonLit(int x ) : value(x) {}
+#endif
+NonLit(void*) : value(-1) {}
+~NonLit() {}
+int value;
+};
+
+struct StoresNonLit {
+#if __cplusplus >= 201402L
+constexpr StoresNonLit() : obj() {}
+constexpr StoresNonLit(int x) : obj(x) {}
+#else
+StoresNonLit() : obj() {}
+StoresNonLit(int x) : obj(x) {}
+#endif
+StoresNonLit(void* p) : obj(p) {}
+NonLit obj;
+};
+
+const bool NonLitHasConstInit =
+#if __cplusplus >= 201402L
+true;
+#else
+false;
+#endif
+
+// Test diagnostics when the argument does not refer to a named identifier
+void check_is_constant_init_bogus()
+{
+(void)__has_constant_initializer(42); // expected-error {{does not reference a named variable}}
+(void)__has_constant_initializer(ReturnInt()); // expected-error {{does not reference a named variable}}
+(void)__has_constant_initializer(42, 43); // expected-error {{does not reference a named variable}}
+}
+
+// [basic.start.static]p2.1
+// if each full-expression (including implicit conversions) that appears in
+// the initializer of a reference with static or thread storage duration is
+// a constant expression (5.20) and the reference is bound to a glvalue
+// designating an object with static storage duration, to a temporary object
+// (see 12.2) or subobject thereof, or to a function;
+
+// Test binding to a static glvalue
+const int glvalue_int = 42;
+const int glvalue_int2 = ReturnInt();
+const int& glvalue_ref = glvalue_int;
+const int& glvalue_ref2 = glvalue_int2;
+static_assert(__has_constant_initializer(glvalue_ref), "");
+static_assert(__has_constant_initializer(glvalue_ref2), "");
+
+__thread const int& glvalue_ref_tl = glvalue_int;
+static_assert(__has_constant_initializer(glvalue_ref_tl), "");
+
+void test_basic_start_static_2_1() {
+const int non_global = 42;
+const int& non_global_ref = non_global;
+static_assert(!__has_constant_initializer(non_global), "automatic variables never have const init");
+static_assert(!__has_constant_initializer(non_global_ref), "automatic variables never have const init");
+
+static const int& local_init = non_global;
+static_assert(!__has_constant_initializer(local_init), "init must be static glvalue");
+static const int& global_init = glvalue_int;
+static_assert(__has_constant_initializer(global_init), "");
+static const int& temp_init = 42;
+static_assert(__has_constant_initializer(temp_init), "");
+#if 0
+/// FIXME: Why is this failing?
+__thread const int& tl_init = 42;
+static_assert(__has_constant_initializer(tl_init), "");
+#endif
+}
+
+const int& temp_ref = 42;
+const int& temp_ref2 = ReturnInt();
+static_assert(__has_constant_initializer(temp_ref), "");
+static_assert(!__has_constant_initializer(temp_ref2), "");
+
+const NonLit& nl_temp_ref = 42;
+static_assert(!__has_constant_initializer(nl_temp_ref), "");
+
+#if __cplusplus >= 201103L
+const LitType& lit_temp_ref = 42;
+static_assert(__has_constant_initializer(lit_temp_ref), "");
+
+const int& subobj_ref = LitType{}.value;
+static_assert(__has_constant_initializer(subobj_ref), "");
+#endif
+
+const int& nl_subobj_ref = NonLit().value;
+static_assert(!__has_constant_initializer(nl_subobj_ref), "");
+
+// [basic.start.static]p2.2
+// if an object with static or thread storage duration is initialized by a
+// constructor call, and if the initialization full-expression is a con

[PATCH] D23433: [Basic] Add missing `const` qualifier (NFC)

2016-08-11 Thread Visoiu Mistrih Francis via cfe-commits
thegameg created this revision.
thegameg added reviewers: joker-eph, vsk, dblaikie.
thegameg added a subscriber: cfe-commits.

The member function is a predicate, and doesn't apply any changes on the object.

https://reviews.llvm.org/D23433

Files:
  include/clang/Basic/SourceManager.h

Index: include/clang/Basic/SourceManager.h
===
--- include/clang/Basic/SourceManager.h
+++ include/clang/Basic/SourceManager.h
@@ -1357,7 +1357,7 @@
   }
 
   /// \brief Returns whether \p Loc is expanded from a macro in a system 
header.
-  bool isInSystemMacro(SourceLocation loc) {
+  bool isInSystemMacro(SourceLocation loc) const {
 return loc.isMacroID() && isInSystemHeader(getSpellingLoc(loc));
   }
 


Index: include/clang/Basic/SourceManager.h
===
--- include/clang/Basic/SourceManager.h
+++ include/clang/Basic/SourceManager.h
@@ -1357,7 +1357,7 @@
   }
 
   /// \brief Returns whether \p Loc is expanded from a macro in a system header.
-  bool isInSystemMacro(SourceLocation loc) {
+  bool isInSystemMacro(SourceLocation loc) const {
 return loc.isMacroID() && isInSystemHeader(getSpellingLoc(loc));
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23429: [CUDA] Place GPU binary into .nv_fatbin section and align it by 8.

2016-08-11 Thread Justin Lebar via cfe-commits
jlebar added inline comments.


Comment at: lib/CodeGen/CGCUDANV.cpp:62
@@ -60,2 +61,3 @@
llvm::ConstantInt::get(SizeTy, 0)};
-auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
+auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.data());
+llvm::GlobalVariable *GV =

StringRefs aren't necessarily null-terminated.  :)


https://reviews.llvm.org/D23429



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


Re: [PATCH] D23433: [Basic] Add missing `const` qualifier (NFC)

2016-08-11 Thread Vedant Kumar via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

Makes sense. isMacroID and isInSystemHeader are both already marked const.


https://reviews.llvm.org/D23433



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


Re: [PATCH] D23341: [CUDA] Include CUDA headers before anything else.

2016-08-11 Thread Artem Belevich via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

OK. This should help with PR26966.


https://reviews.llvm.org/D23341



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


r278435 - P0217R3: Perform semantic checks and initialization for the bindings in a

2016-08-11 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 11 17:25:46 2016
New Revision: 278435

URL: http://llvm.org/viewvc/llvm-project?rev=278435&view=rev
Log:
P0217R3: Perform semantic checks and initialization for the bindings in a
decomposition declaration for arrays, aggregate-like structs, tuple-like
types, and (as an extension) for complex and vector types.

Added:
cfe/trunk/test/CXX/dcl.decl/dcl.decomp/
cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p2.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p4.cpp
Modified:
cfe/trunk/include/clang/AST/CXXInheritance.h
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/UnresolvedSet.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Parser/cxx1z-decomposition.cpp
cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp

Modified: cfe/trunk/include/clang/AST/CXXInheritance.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CXXInheritance.h?rev=278435&r1=278434&r2=278435&view=diff
==
--- cfe/trunk/include/clang/AST/CXXInheritance.h (original)
+++ cfe/trunk/include/clang/AST/CXXInheritance.h Thu Aug 11 17:25:46 2016
@@ -172,7 +172,7 @@ public:
   /// paths for a derived-to-base search.
   explicit CXXBasePaths(bool FindAmbiguities = true, bool RecordPaths = true,
 bool DetectVirtual = true)
-  : FindAmbiguities(FindAmbiguities), RecordPaths(RecordPaths),
+  : Origin(), FindAmbiguities(FindAmbiguities), RecordPaths(RecordPaths),
 DetectVirtual(DetectVirtual), DetectedVirtual(nullptr),
 NumDeclsFound(0) {}
 

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=278435&r1=278434&r2=278435&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Aug 11 17:25:46 2016
@@ -251,7 +251,7 @@ public:
   // FIXME: Deprecated, move clients to getName().
   std::string getNameAsString() const { return Name.getAsString(); }
 
-  void printName(raw_ostream &os) const { os << Name; }
+  virtual void printName(raw_ostream &os) const;
 
   /// getDeclName - Get the actual, stored name of the declaration,
   /// which may be a special name.
@@ -1025,7 +1025,7 @@ public:
   ///   void foo() { int x; static int y; extern int z; }
   ///
   bool isLocalVarDecl() const {
-if (getKind() != Decl::Var)
+if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
   return false;
 if (const DeclContext *DC = getLexicalDeclContext())
   return DC->getRedeclContext()->isFunctionOrMethod();
@@ -1040,7 +1040,7 @@ public:
   /// isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but
   /// excludes variables declared in blocks.
   bool isFunctionOrMethodVarDecl() const {
-if (getKind() != Decl::Var)
+if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
   return false;
 const DeclContext *DC = getLexicalDeclContext()->getRedeclContext();
 return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block;

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=278435&r1=278434&r2=278435&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Aug 11 17:25:46 2016
@@ -1147,6 +1147,12 @@ public:
   /// \note This does NOT include a check for union-ness.
   bool isEmpty() const { return data().Empty; }
 
+  /// \brief Determine whether this class has direct non-static data members.
+  bool hasDirectFields() const {
+auto &D = data();
+return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields;
+  }
+
   /// Whether this class is polymorphic (C++ [class.virtual]),
   /// which means that the class contains or inherits a virtual function.
   bool isPolymorphic() const { return data().Polymorphic; }
@@ -3451,6 +3457,8 @@ public:
 return llvm::makeArrayRef(getTrailingObjects(), 
NumBindings);
   }
 
+  void printName(raw_ostream &os) const override;
+
   static bool cl

[PATCH] D23429: [CUDA] Place GPU binary into .nv_fatbin section and align it by 8.

2016-08-11 Thread Artem Belevich via cfe-commits
tra created this revision.
tra added a reviewer: jlebar.
tra added a subscriber: cfe-commits.

This matches the way nvcc encapsulates GPU binaries into host object file.
Now cuobjdump can deal with clang-compiled object files.



https://reviews.llvm.org/D23429

Files:
  lib/CodeGen/CGCUDANV.cpp
  test/CodeGenCUDA/device-stub.cu

Index: test/CodeGenCUDA/device-stub.cu
===
--- test/CodeGenCUDA/device-stub.cu
+++ test/CodeGenCUDA/device-stub.cu
@@ -45,10 +45,12 @@
 // * constant unnamed string with the kernel name
 // CHECK: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
 // * constant unnamed string with GPU binary
-// CHECK: private unnamed_addr constant{{.*}}\00"
+// CHECK: private unnamed_addr constant{{.*GPU binary would be here.*}}\00"
+// CHECK-SAME: section ".nv_fatbin", align 8
 // * constant struct that wraps GPU binary
 // CHECK: @__cuda_fatbin_wrapper = internal constant { i32, i32, i8*, i8* } 
-// CHECK:   { i32 1180844977, i32 1, {{.*}}, i8* null }
+// CHECK-SAME: { i32 1180844977, i32 1, {{.*}}, i8* null }
+// CHECK-SAME: section ".nvFatBinSegment"
 // * variable to save GPU binary handle after initialization
 // CHECK: @__cuda_gpubin_handle = internal global i8** null
 // * Make sure our constructor/destructor was added to global ctor/dtor list.
Index: lib/CodeGen/CGCUDANV.cpp
===
--- lib/CodeGen/CGCUDANV.cpp
+++ lib/CodeGen/CGCUDANV.cpp
@@ -53,12 +53,20 @@
   /// Helper function that generates a constant string and returns a pointer to
   /// the start of the string.  The result of this function can be used 
anywhere
   /// where the C code specifies const char*.
-  llvm::Constant *makeConstantString(const std::string &Str,
- const std::string &Name = "",
+  llvm::Constant *makeConstantString(const StringRef Str,
+ const StringRef Name = "",
+ const StringRef SectionName = "",
  unsigned Alignment = 0) {
 llvm::Constant *Zeros[] = {llvm::ConstantInt::get(SizeTy, 0),
llvm::ConstantInt::get(SizeTy, 0)};
-auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
+auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.data());
+llvm::GlobalVariable *GV =
+cast(ConstStr.getPointer());
+if (!SectionName.empty())
+  GV->setSection(SectionName);
+if (Alignment)
+  GV->setAlignment(Alignment);
+
 return llvm::ConstantExpr::getGetElementPtr(ConstStr.getElementType(),
 ConstStr.getPointer(), Zeros);
  }
@@ -285,7 +293,8 @@
 llvm::Constant *Values[] = {
 llvm::ConstantInt::get(IntTy, 0x466243b1), // Fatbin wrapper magic.
 llvm::ConstantInt::get(IntTy, 1),  // Fatbin version.
-makeConstantString(GpuBinaryOrErr.get()->getBuffer(), "", 16), // Data.
+makeConstantString(GpuBinaryOrErr.get()->getBuffer(), // Data.
+   "", ".nv_fatbin", 8),  //
 llvm::ConstantPointerNull::get(VoidPtrTy)}; // Unused in fatbin v1.
 llvm::GlobalVariable *FatbinWrapper = new llvm::GlobalVariable(
 TheModule, FatbinWrapperTy, true, llvm::GlobalValue::InternalLinkage,


Index: test/CodeGenCUDA/device-stub.cu
===
--- test/CodeGenCUDA/device-stub.cu
+++ test/CodeGenCUDA/device-stub.cu
@@ -45,10 +45,12 @@
 // * constant unnamed string with the kernel name
 // CHECK: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
 // * constant unnamed string with GPU binary
-// CHECK: private unnamed_addr constant{{.*}}\00"
+// CHECK: private unnamed_addr constant{{.*GPU binary would be here.*}}\00"
+// CHECK-SAME: section ".nv_fatbin", align 8
 // * constant struct that wraps GPU binary
 // CHECK: @__cuda_fatbin_wrapper = internal constant { i32, i32, i8*, i8* } 
-// CHECK:   { i32 1180844977, i32 1, {{.*}}, i8* null }
+// CHECK-SAME: { i32 1180844977, i32 1, {{.*}}, i8* null }
+// CHECK-SAME: section ".nvFatBinSegment"
 // * variable to save GPU binary handle after initialization
 // CHECK: @__cuda_gpubin_handle = internal global i8** null
 // * Make sure our constructor/destructor was added to global ctor/dtor list.
Index: lib/CodeGen/CGCUDANV.cpp
===
--- lib/CodeGen/CGCUDANV.cpp
+++ lib/CodeGen/CGCUDANV.cpp
@@ -53,12 +53,20 @@
   /// Helper function that generates a constant string and returns a pointer to
   /// the start of the string.  The result of this function can be used anywhere
   /// where the C code specifies const char*.
-  llvm::Constant *makeConstantString(const std::string &Str,
- const std::string &Name = "",
+  llvm::Constant *makeConstantString(const

Re: r276900 - [Sema] Teach getCurrentThisType to reconize lambda in in-class initializer

2016-08-11 Thread Richard Smith via cfe-commits
On Thu, Aug 11, 2016 at 1:38 PM, Faisal Vali  wrote:

> On Thu, Aug 11, 2016 at 1:07 PM, Richard Smith 
> wrote:
> > Yes, this should be merged. It's not quite right, but it's certainly
> better
> > than what we had before.
>
> I would agree  that the comment is broken - but, unless i'm missing
> something subtle, the subsequent logic and call to
> adjustCVQualifiersForCXXThisWithinLambda should handle the scenario
> you describe.


Ah, thanks, I agree. Looks like it's just the comment that's slightly
misleading.


> >
> > On Mon, Aug 8, 2016 at 1:34 PM, Hans Wennborg  wrote:
> >>
> >> Richard: ping?
> >>
> >> On Wed, Jul 27, 2016 at 4:46 PM, Hans Wennborg 
> wrote:
> >> > Should this be merged to 3.9?
> >> >
> >> > Thanks,
> >> > Hans
> >> >
> >> > On Wed, Jul 27, 2016 at 11:25 AM, Erik Pilkington via cfe-commits
> >> >  wrote:
> >> >> Author: epilk
> >> >> Date: Wed Jul 27 13:25:10 2016
> >> >> New Revision: 276900
> >> >>
> >> >> URL: http://llvm.org/viewvc/llvm-project?rev=276900&view=rev
> >> >> Log:
> >> >> [Sema] Teach getCurrentThisType to reconize lambda in in-class
> >> >> initializer
> >> >>
> >> >> Fixes PR27994, a crash on valid.
> >> >>
> >> >> Differential revision: https://reviews.llvm.org/D21145
> >> >>
> >> >> Modified:
> >> >> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> >> >> cfe/trunk/test/SemaCXX/lambda-expressions.cpp
> >> >>
> >> >> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> >> >> URL:
> >> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaExprCXX.cpp?rev=276900&r1=276899&r2=276900&view=diff
> >> >>
> >> >> 
> ==
> >> >> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> >> >> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jul 27 13:25:10 2016
> >> >> @@ -961,32 +961,26 @@ static QualType adjustCVQualifiersForCXX
> >> >>  QualType Sema::getCurrentThisType() {
> >> >>DeclContext *DC = getFunctionLevelDeclContext();
> >> >>QualType ThisTy = CXXThisTypeOverride;
> >> >> +
> >> >>if (CXXMethodDecl *method = dyn_cast(DC)) {
> >> >>  if (method && method->isInstance())
> >> >>ThisTy = method->getThisType(Context);
> >> >>}
> >> >> -  if (ThisTy.isNull()) {
> >> >> -if (isGenericLambdaCallOperatorSpecialization(CurContext) &&
> >> >> -CurContext->getParent()->getParent()->isRecord()) {
> >> >> -  // This is a generic lambda call operator that is being
> >> >> instantiated
> >> >> -  // within a default initializer - so use the enclosing class
> as
> >> >> 'this'.
> >> >> -  // There is no enclosing member function to retrieve the
> 'this'
> >> >> pointer
> >> >> -  // from.
> >> >> -
> >> >> -  // FIXME: This looks wrong. If we're in a lambda within a
> lambda
> >> >> within a
> >> >> -  // default member initializer, we need to recurse up more
> >> >> parents to find
> >> >> -  // the right context. Looks like we should be walking up to
> the
> >> >> parent of
> >> >> -  // the closure type, checking whether that is itself a lambda,
> >> >> and if so,
> >> >> -  // recursing, until we reach a class or a function that isn't
> a
> >> >> lambda
> >> >> -  // call operator. And we should accumulate the constness of
> >> >> *this on the
> >> >> -  // way.
> >> >> -
> >> >> -  QualType ClassTy = Context.getTypeDeclType(
> >> >> -  cast(CurContext->getParent()->
> getParent()));
> >> >> -  // There are no cv-qualifiers for 'this' within default
> >> >> initializers,
> >> >> -  // per [expr.prim.general]p4.
> >> >> -  ThisTy = Context.getPointerType(ClassTy);
> >> >> -}
> >> >> +
> >> >> +  if (ThisTy.isNull() && isLambdaCallOperator(CurContext) &&
> >> >> +  !ActiveTemplateInstantiations.empty()) {
> >> >> +
> >> >> +assert(isa(DC) &&
> >> >> +   "Trying to get 'this' type from static method?");
> >> >> +
> >> >> +// This is a lambda call operator that is being instantiated as
> a
> >> >> default
> >> >> +// initializer. DC must point to the enclosing class type, so we
> >> >> can recover
> >> >> +// the 'this' type from it.
> >> >> +
> >> >> +QualType ClassTy =
> >> >> Context.getTypeDeclType(cast(DC));
> >> >> +// There are no cv-qualifiers for 'this' within default
> >> >> initializers,
> >> >> +// per [expr.prim.general]p4.
> >
> >
> > This is wrong in C++17 onwards: if *this is captured by value by a
> > non-mutable lambda, it should become const-qualified.
> >
> >>
> >> >> +ThisTy = Context.getPointerType(ClassTy);
> >> >>}
> >> >>
> >> >>// If we are within a lambda's call operator, the cv-qualifiers of
> >> >> 'this'
> >> >>
> >> >> Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
> >> >> URL:
> >> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/lambda-expressions.cpp?rev=276900&r1=276899&r2=276900&view=diff
> >> >>
> >> >> 
> ==
> >> >> 

Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Zachary Turner via cfe-commits
zturner updated this revision to Diff 67751.
zturner added a comment.

I added a test for the clang Driver changes.

It seems I'm still having some trouble writing the clang-cl test for 
clang-tidy.  It depends on having a different compilation database that uses 
clang-cl instead of clang.  I found one set of tests called 
`clang-tidy-run-with-database.cpp` but it requires shell, which will make it 
not work on Windows, which is the main place it should be tested in the first 
place.


https://reviews.llvm.org/D23409

Files:
  include/clang/Driver/Driver.h
  lib/Driver/Driver.cpp
  lib/Tooling/JSONCompilationDatabase.cpp
  unittests/Driver/ToolChainTest.cpp

Index: unittests/Driver/ToolChainTest.cpp
===
--- unittests/Driver/ToolChainTest.cpp
+++ unittests/Driver/ToolChainTest.cpp
@@ -117,4 +117,29 @@
 S);
 }
 
+TEST(ToolChainTest, DefaultDriverMode) {
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+  DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new vfs::InMemoryFileSystem);
+
+  Driver CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
+  InMemoryFileSystem);
+  Driver CXXDriver("/home/test/bin/clang++", "arm-linux-gnueabi", Diags,
+   InMemoryFileSystem);
+  Driver CLDriver("/home/test/bin/clang-cl", "arm-linux-gnueabi", Diags,
+  InMemoryFileSystem);
+
+  std::unique_ptr CC(CCDriver.BuildCompilation({"foo.cpp"}));
+  std::unique_ptr CXX(CXXDriver.BuildCompilation({"foo.cpp"}));
+  std::unique_ptr CL(CLDriver.BuildCompilation({"foo.cpp"}));
+
+  EXPECT_TRUE(CCDriver.CCCIsCC());
+  EXPECT_TRUE(CXXDriver.CCCIsCXX());
+  EXPECT_TRUE(CLDriver.IsCLMode());
+}
+
 } // end anonymous namespace
Index: lib/Tooling/JSONCompilationDatabase.cpp
===
--- lib/Tooling/JSONCompilationDatabase.cpp
+++ lib/Tooling/JSONCompilationDatabase.cpp
@@ -16,7 +16,10 @@
 #include "clang/Tooling/CompilationDatabasePluginRegistry.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 
 namespace clang {
@@ -113,8 +116,17 @@
 
 std::vector unescapeCommandLine(
 StringRef EscapedCommandLine) {
+#if defined(LLVM_ON_WIN32)
+  llvm::BumpPtrAllocator Alloc;
+  llvm::StringSaver Saver(Alloc);
+  llvm::SmallVector T;
+  llvm::cl::TokenizeWindowsCommandLine(EscapedCommandLine, Saver, T);
+  std::vector Result(T.begin(), T.end());
+  return Result;
+#else
   CommandLineArgumentParser parser(EscapedCommandLine);
   return parser.parse();
+#endif
 }
 
 class JSONCompilationDatabasePlugin : public CompilationDatabasePlugin {
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -88,31 +88,39 @@
   llvm::DeleteContainerSeconds(ToolChains);
 }
 
-void Driver::ParseDriverMode(ArrayRef Args) {
-  const std::string OptName =
-  getOpts().getOption(options::OPT_driver_mode).getPrefixedName();
+void Driver::ParseDriverMode(StringRef ProgramName,
+ ArrayRef Args) {
+  auto Default = ToolChain::getTargetAndModeFromProgramName(ProgramName);
+  StringRef DefaultMode(Default.second);
+  setDriverModeFromOption(DefaultMode);
 
   for (const char *ArgPtr : Args) {
 // Ingore nullptrs, they are response file's EOL markers
 if (ArgPtr == nullptr)
   continue;
 const StringRef Arg = ArgPtr;
-if (!Arg.startswith(OptName))
-  continue;
+setDriverModeFromOption(Arg);
+  }
+}
+
+void Driver::setDriverModeFromOption(StringRef Opt) {
+  const std::string OptName =
+  getOpts().getOption(options::OPT_driver_mode).getPrefixedName();
+  if (!Opt.startswith(OptName))
+return;
+  StringRef Value = Opt.drop_front(OptName.size());
 
-const StringRef Value = Arg.drop_front(OptName.size());
-const unsigned M = llvm::StringSwitch(Value)
-   .Case("gcc", GCCMode)
-   .Case("g++", GXXMode)
-   .Case("cpp", CPPMode)
-   .Case("cl", CLMode)
-   .Default(~0U);
+  const unsigned M = llvm::StringSwitch(Value)
+ .Case("gcc", GCCMode)
+ .Case("g++", GXXMode)
+ .Case("cpp", CPPMode)
+ .Case("cl", CLMode)
+ .Default(~0U);
 
-if (M != ~0U)
-  Mode = static_cast(M);
-else
-  Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
-  }
+  if (M != ~0U)
+Mode = static_cast(M);
+  el

Re: [libcxx] r278282 - std:: quailfy the calls for cend/crend/cbegin/cend. Fixes bug 28927.

2016-08-11 Thread Hans Wennborg via cfe-commits
I've gone ahead and merged it in r278426.

On Wed, Aug 10, 2016 at 5:19 PM, Eric Fiselier  wrote:
> I would support merging this change.
>
> /Eric
>
> On Wed, Aug 10, 2016 at 3:20 PM, Hans Wennborg via cfe-commits
>  wrote:
>>
>> Should we merge this to 3.9? Looks like a straight-forward fix for
>> something that was hit by real code.
>>
>> Thanks,
>> Hans
>>
>> On Wed, Aug 10, 2016 at 1:04 PM, Marshall Clow via cfe-commits
>>  wrote:
>> > Author: marshall
>> > Date: Wed Aug 10 15:04:46 2016
>> > New Revision: 278282
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=278282&view=rev
>> > Log:
>> > std:: quailfy the calls for cend/crend/cbegin/cend. Fixes bug 28927.
>> >
>> > Added:
>> > libcxx/trunk/test/std/iterators/iterator.range/begin-end.fail.cpp
>> > Modified:
>> > libcxx/trunk/include/iterator
>> >
>> > Modified: libcxx/trunk/include/iterator
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=278282&r1=278281&r2=278282&view=diff
>> >
>> > ==
>> > --- libcxx/trunk/include/iterator (original)
>> > +++ libcxx/trunk/include/iterator Wed Aug 10 15:04:46 2016
>> > @@ -1632,16 +1632,16 @@ reverse_iterator rend(initia
>> >
>> >  template 
>> >  inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
>> > -auto cbegin(const _Cp& __c) -> decltype(begin(__c))
>> > +auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
>> >  {
>> > -return begin(__c);
>> > +return _VSTD::begin(__c);
>> >  }
>> >
>> >  template 
>> >  inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
>> > -auto cend(const _Cp& __c) -> decltype(end(__c))
>> > +auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
>> >  {
>> > -return end(__c);
>> > +return _VSTD::end(__c);
>> >  }
>> >
>> >  template 
>> > @@ -1674,16 +1674,16 @@ auto rend(const _Cp& __c) -> decltype(__
>> >
>> >  template 
>> >  inline _LIBCPP_INLINE_VISIBILITY
>> > -auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
>> > +auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
>> >  {
>> > -return rbegin(__c);
>> > +return _VSTD::rbegin(__c);
>> >  }
>> >
>> >  template 
>> >  inline _LIBCPP_INLINE_VISIBILITY
>> > -auto crend(const _Cp& __c) -> decltype(rend(__c))
>> > +auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
>> >  {
>> > -return rend(__c);
>> > +return _VSTD::rend(__c);
>> >  }
>> >
>> >  #endif
>> >
>> > Added: libcxx/trunk/test/std/iterators/iterator.range/begin-end.fail.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.range/begin-end.fail.cpp?rev=278282&view=auto
>> >
>> > ==
>> > --- libcxx/trunk/test/std/iterators/iterator.range/begin-end.fail.cpp
>> > (added)
>> > +++ libcxx/trunk/test/std/iterators/iterator.range/begin-end.fail.cpp
>> > Wed Aug 10 15:04:46 2016
>> > @@ -0,0 +1,51 @@
>> >
>> > +//===--===//
>> > +//
>> > +// The LLVM Compiler Infrastructure
>> > +//
>> > +// This file is dual licensed under the MIT and the University of
>> > Illinois Open
>> > +// Source Licenses. See LICENSE.TXT for details.
>> > +//
>> >
>> > +//===--===//
>> > +
>> > +#include "test_macros.h"
>> > +
>> > +#if TEST_STD_VER < 11
>> > +#error
>> > +#else
>> > +
>> > +// 
>> > +// template  auto begin(C& c) -> decltype(c.begin());
>> > +// template  auto begin(const C& c) -> decltype(c.begin());
>> > +// template  auto end(C& c) -> decltype(c.end());
>> > +// template  auto end(const C& c) -> decltype(c.end());
>> > +// template  reverse_iterator
>> > rbegin(initializer_list il);
>> > +// template  reverse_iterator
>> > rend(initializer_list il);
>> > +
>> > +
>> > +#include 
>> > +#include 
>> > +
>> > +namespace Foo {
>> > +   struct FakeContainer {};
>> > +   typedef int FakeIter;
>> > +
>> > +   FakeIter begin(const FakeContainer &)   { return 1; }
>> > +   FakeIter end  (const FakeContainer &)   { return 2; }
>> > +   FakeIter rbegin(const FakeContainer &)  { return 3; }
>> > +   FakeIter rend  (const FakeContainer &)  { return 4; }
>> > +
>> > +   FakeIter cbegin(const FakeContainer &)  { return 11; }
>> > +   FakeIter cend  (const FakeContainer &)  { return 12; }
>> > +   FakeIter crbegin(const FakeContainer &) { return 13; }
>> > +   FakeIter crend  (const FakeContainer &) { return 14; }
>> > +}
>> > +
>> > +
>> > +int main(){
>> > +// Bug #28927 - shouldn't find these via ADL
>> > +   (void) std::cbegin (Foo::FakeContainer());
>> > +   (void) std::cend   (Foo::FakeContainer());
>> > +   (void) std::crbegin(Foo::FakeContainer());
>> > +   (void) std::crend  (Foo::FakeContainer());
>> > +}
>> > +#endif
>> >
>> >
>> > ___

[libcxx] r278426 - Merging r278282:

2016-08-11 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Thu Aug 11 16:48:37 2016
New Revision: 278426

URL: http://llvm.org/viewvc/llvm-project?rev=278426&view=rev
Log:
Merging r278282:

r278282 | marshall | 2016-08-10 13:04:46 -0700 (Wed, 10 Aug 2016) | 1 line

std:: quailfy the calls for cend/crend/cbegin/cend. Fixes bug 28927.


Added:

libcxx/branches/release_39/test/std/iterators/iterator.range/begin-end.fail.cpp
  - copied unchanged from r278282, 
libcxx/trunk/test/std/iterators/iterator.range/begin-end.fail.cpp
Modified:
libcxx/branches/release_39/   (props changed)
libcxx/branches/release_39/include/iterator

Propchange: libcxx/branches/release_39/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 11 16:48:37 2016
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:278387
+/libcxx/trunk:278282,278387

Modified: libcxx/branches/release_39/include/iterator
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_39/include/iterator?rev=278426&r1=278425&r2=278426&view=diff
==
--- libcxx/branches/release_39/include/iterator (original)
+++ libcxx/branches/release_39/include/iterator Thu Aug 11 16:48:37 2016
@@ -1632,16 +1632,16 @@ reverse_iterator rend(initia
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-auto cbegin(const _Cp& __c) -> decltype(begin(__c))
+auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
 {
-return begin(__c);
+return _VSTD::begin(__c);
 }
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-auto cend(const _Cp& __c) -> decltype(end(__c))
+auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
 {
-return end(__c);
+return _VSTD::end(__c);
 }
 
 template 
@@ -1674,16 +1674,16 @@ auto rend(const _Cp& __c) -> decltype(__
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY
-auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
+auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
 {
-return rbegin(__c);
+return _VSTD::rbegin(__c);
 }
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY
-auto crend(const _Cp& __c) -> decltype(rend(__c))
+auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
 {
-return rend(__c);
+return _VSTD::rend(__c);
 }
 
 #endif


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


Re: [PATCH] D23420: libcxx: Fix libcxx test on aarch64 with libunwind

2016-08-11 Thread Eric Fiselier via cfe-commits
EricWF added a subscriber: EricWF.
EricWF added a reviewer: EricWF.
EricWF added a comment.

Urg... Not this again. This link order is important. I can't remember *why*, 
but libgcc has to appear both before and after `pthread` and `libc` IIRC.  
Either way the intention here is to mimic the output of Clangs driver. For 
example the order Clang generates on Linux is:

  // clang++ -### -pthread -stdlib=libc++ -xc++ - < /dev/null
  "-lc++" "-lm" "-lgcc_s" "-lgcc" "-lpthread" "-lc" "-lgcc_s" "-lgcc"

What link order does the compiler generate on your platform?


https://reviews.llvm.org/D23420



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


Re: [libcxx] r278387 - Remove test for the sign of a NaN - doesn't work on MIPS, not strictly legal. Fixes bug 28936

2016-08-11 Thread Hans Wennborg via cfe-commits
Merged to 3.9 in r278425, as the PR was marked as a release blocker.

On Thu, Aug 11, 2016 at 11:46 AM, Marshall Clow via cfe-commits
 wrote:
> Author: marshall
> Date: Thu Aug 11 13:46:24 2016
> New Revision: 278387
>
> URL: http://llvm.org/viewvc/llvm-project?rev=278387&view=rev
> Log:
> Remove test for the sign of a NaN - doesn't work on MIPS, not strictly legal. 
> Fixes bug 28936
>
> Modified:
> 
> libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
>
> Modified: 
> libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp?rev=278387&r1=278386&r2=278387&view=diff
> ==
> --- 
> libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
>  (original)
> +++ 
> libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
>  Thu Aug 11 13:46:24 2016
> @@ -91,7 +91,6 @@ void test_edges()
>  {
>  assert(std::isnan(r.real()));
>  assert(std::isnan(r.imag()));
> -assert(std::signbit(testcases[i].imag()) == 
> std::signbit(r.imag()));
>  }
>  else if (std::isnan(testcases[i].real()) && 
> std::isinf(testcases[i].imag()))
>  {
>
>
> ___
> 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


[libcxx] r278425 - Merging r278387:

2016-08-11 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Thu Aug 11 16:47:28 2016
New Revision: 278425

URL: http://llvm.org/viewvc/llvm-project?rev=278425&view=rev
Log:
Merging r278387:

r278387 | marshall | 2016-08-11 11:46:24 -0700 (Thu, 11 Aug 2016) | 1 line

Remove test for the sign of a NaN - doesn't work on MIPS, not strictly legal. 
Fixes bug 28936


Modified:
libcxx/branches/release_39/   (props changed)

libcxx/branches/release_39/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp

Propchange: libcxx/branches/release_39/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 11 16:47:28 2016
@@ -1 +1,2 @@
 /libcxx/branches/apple:136569-137939
+/libcxx/trunk:278387

Modified: 
libcxx/branches/release_39/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_39/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp?rev=278425&r1=278424&r2=278425&view=diff
==
--- 
libcxx/branches/release_39/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
 (original)
+++ 
libcxx/branches/release_39/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
 Thu Aug 11 16:47:28 2016
@@ -91,7 +91,6 @@ void test_edges()
 {
 assert(std::isnan(r.real()));
 assert(std::isnan(r.imag()));
-assert(std::signbit(testcases[i].imag()) == 
std::signbit(r.imag()));
 }
 else if (std::isnan(testcases[i].real()) && 
std::isinf(testcases[i].imag()))
 {


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


Re: [PATCH] D23422: [VFS] Add 'ignore-non-existent-contents' field to YAML

2016-08-11 Thread Ben Langmuir via cfe-commits
benlangmuir added a comment.

This should have a test for the writer change.  Otherwise LGTM.


https://reviews.llvm.org/D23422



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


Re: [PATCH] D23423: [Clang-tidy] Comparison Function Address

2016-08-11 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a comment.

This check looks like specific case of https://reviews.llvm.org/D23427. May be 
they should be merged?


Repository:
  rL LLVM

https://reviews.llvm.org/D23423



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


Re: [PATCH] D23427: [Clang-tidy] Comparison Misuse

2016-08-11 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added inline comments.


Comment at: clang-tidy/misc/ComparisonMisuseCheck.cpp:21
@@ +20,3 @@
+void ComparisonMisuseCheck::registerMatchers(MatchFinder *Finder) {
+
+  Finder->addMatcher(

Please remove this line.


Repository:
  rL LLVM

https://reviews.llvm.org/D23427



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


Re: [PATCH] D23427: [Clang-tidy] Comparison Misuse

2016-08-11 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a subscriber: Eugene.Zelenko.
Eugene.Zelenko added a comment.

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

Please run Clang-format on newly added files. Test case is definitely needs it.



Comment at: clang-tidy/misc/ComparisonMisuseCheck.h:19
@@ +18,3 @@
+
+/// This checker reports errors related to the misuse of the comparison 
operator.
+/// It should warn for the following cases:

Check, please.


Comment at: clang-tidy/misc/ComparisonMisuseCheck.h:21
@@ +20,3 @@
+/// It should warn for the following cases:
+///   - strcmp,strncmp,memcmp misuse.
+///   - char* is compared to a string literal

Spaces after commas,


Comment at: docs/clang-tidy/checks/misc-comparison-misuse.rst:6
@@ +5,3 @@
+
+This checker reports errors related to the misuse of the comparison operator.
+It should warn for the following cases:

Check, please.


Comment at: docs/clang-tidy/checks/misc-comparison-misuse.rst:13
@@ +12,3 @@
+.. code-block::
+   bool isMyString(const char * my){
+return "mystring"==my;//error. comparing pointer to string literal

Clang-format examples, please.


Repository:
  rL LLVM

https://reviews.llvm.org/D23427



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


Re: [PATCH] D23421: [Clang-tidy] CERT-MSC53-CPP (checker for std namespace modification)

2016-08-11 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

Thank you for working on this check! There is a slight problem, however, in 
that the check as-written will flag false positives because there are times 
when it is permissible to modify the std namespace. The important bit of the 
CERT requirement is "Do not add declarations or definitions to the standard 
namespaces std or posix, or to a namespace contained therein, except for a 
template specialization that depends on a user-defined type that meets the 
standard library requirements for the original template." So the part that's 
missing from this check is excluding template specializations that depend on 
user-defined types. For instance, the following should be valid:

  namespace std {
  template <>
  struct is_error_code_enum : std::true_type {};
  }

(This comes from Error.h in LLVM.)



Comment at: clang-tidy/cert/CERTTidyModule.cpp:37-38
@@ -35,2 +36,4 @@
 // DCL
+CheckFactories.registerCheck(
+"cert-msc53-cpp");
 CheckFactories.registerCheck(

Should put this under a `// MSC` comment rather than the `// DCL` one.


Comment at: clang-tidy/cert/DontModifyStdNamespaceCheck.cpp:33
@@ +32,3 @@
+
+  diag(Nmspc->getLocation(), "Modification of " + namespaceName +
+ " namespace can result to undefined 
behavior");

Should use format specifiers instead of building the string manually. e.g., 
using %0. Also, diagnostics should start with a lowercase letter and "to" 
should be "in".


Comment at: clang-tidy/cert/DontModifyStdNamespaceCheck.h:19
@@ +18,3 @@
+
+/// Modification of the std or posix namespace can result to undefined 
behavior.
+/// This checker warns for such modifications.

s/to/in


Comment at: docs/clang-tidy/checks/list.rst:12
@@ -11,2 +11,3 @@
cert-dcl59-cpp (redirects to google-build-namespaces) 
+   cert-msc53-cpp
cert-env33-c

Should keep this in alphabetical order.


Repository:
  rL LLVM

https://reviews.llvm.org/D23421



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


Re: [PATCH] D22346: [Clang-tidy] CERT-MSC50-CPP (std:rand() )

2016-08-11 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a comment.

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



Comment at: docs/clang-tidy/checks/cert-msc50-cpp.rst:4
@@ +3,3 @@
+cert-msc-50
+===
+

Should be same length as section name above.


Comment at: docs/clang-tidy/checks/cert-msc50-cpp.rst:6
@@ +5,2 @@
+
+Pseudorandom number generators use mathematical algorithms to produce a 
sequence of numbers with good statistical properties, but the numbers produced 
are not genuinely random. This checker warns for the usage of std::rand().

Please use check and highlight std::rand() with ``.


Repository:
  rL LLVM

https://reviews.llvm.org/D22346



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


Re: [PATCH] D23420: libcxx: Fix libcxx test on aarch64 with libunwind

2016-08-11 Thread Asiri Rathnayake via cfe-commits
rmaprath added a subscriber: rmaprath.
rmaprath added a comment.

I too noticed this very recently (on our non-bare-metal builds), and wondered 
why these dependencies are not included by default. Thanks for looking into it. 
I'll let someone familiar with the details approve.


https://reviews.llvm.org/D23420



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


Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Zachary Turner via cfe-commits
zturner added a comment.

In https://reviews.llvm.org/D23409#513017, @alexfh wrote:

> May I ask you to upload patches with full diff context next time? I know, 
> it's not directly supported by TortoiseGit, but there are at least two other 
> reasonable ways of generating full diffs for Phabricator: 
> http://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface
>  and 
> http://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-command-line.
>
> Wrt testing, I think, apart from a new clang-tidy test, the changes to Driver 
> and Tooling need separate tests as well.


I'm unsure what to actually test in the Driver and Tooling tests.  For example, 
in Tooling we just change from using one function to using another function.  
And that function is already tested in the LLVM test suite.  It seems redundant 
to add another test that is for all intents and purposes equivalent to "Does 
LLVM's windows command line parser work correctly?", which is already tested.

How necessary is this?

For the clang-tidy test, I will need to make it only enabled on Windows, since 
other platforms are not going to be building clang-cl.  I think I should be 
able to figure that out.


https://reviews.llvm.org/D23409



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


[PATCH] D23427: [Clang-tidy] Comparison Misuse

2016-08-11 Thread Benedek Kiss via cfe-commits
falho created this revision.
falho added reviewers: xazax.hun, o.gyorgy, alexfh, aaron.ballman, etienneb, 
hokein, Prazek.
falho added a subscriber: cfe-commits.
falho set the repository for this revision to rL LLVM.

This checker warns for the misuse of comparison operators
- char* is compared to a string literal
- inequality operator usage for NULL

Repository:
  rL LLVM

https://reviews.llvm.org/D23427

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/ComparisonMisuseCheck.cpp
  clang-tidy/misc/ComparisonMisuseCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-comparison-misuse.rst
  test/clang-tidy/misc-comparison-misuse.cpp

Index: test/clang-tidy/misc-comparison-misuse.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-comparison-misuse.cpp
@@ -0,0 +1,20 @@
+// RUN: %check_clang_tidy %s misc-comparison-misuse %t
+
+#define NULL __null
+
+bool test_pointer_to_literal(const char *my){
+  bool b = (my=="mystring");
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: char* is compared to a string literal [misc-comparison-misuse]
+  return "mystring"==my;
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: char* is compared to a string literal [misc-comparison-misuse]
+}
+
+void test_null_to_pointer(int *p){
+  if (NULL>=p);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: comparison to nullptr [misc-comparison-misuse]
+  
+  if (NULL==p);
+  
+  if (NULL!=p);
+}
+
Index: docs/clang-tidy/checks/misc-comparison-misuse.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-comparison-misuse.rst
@@ -0,0 +1,25 @@
+.. title:: clang-tidy - misc-comparison-misuse
+
+misc-comparison-misuse
+==
+
+This checker reports errors related to the misuse of the comparison operator.
+It should warn for the following cases:
+
+Case 1:
+  ``char*`` is compared to a string literal.
+
+.. code-block::
+   bool isMyString(const char * my){
+return "mystring"==my;//error. comparing pointer to string literal
+   }
+
+
+Case 2:
+  Inequality operator usage for ``NULL``.
+
+.. code-block:: c++
+   void(int * p){
+ if (NULL>=p)//error, use only NULL==p, NULL!=p
+   }
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -55,6 +55,7 @@
misc-argument-comment
misc-assert-side-effect
misc-bool-pointer-implicit-conversion
+   misc-comparison-misuse
misc-dangling-handle
misc-definitions-in-headers
misc-fold-init-type
Index: clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tidy/misc/MiscTidyModule.cpp
@@ -15,6 +15,7 @@
 #include "MisplacedConstCheck.h"
 #include "UnconventionalAssignOperatorCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
+#include "ComparisonMisuseCheck.h"
 #include "DanglingHandleCheck.h"
 #include "DefinitionsInHeadersCheck.h"
 #include "FoldInitTypeCheck.h"
@@ -68,6 +69,8 @@
 "misc-unconventional-assign-operator");
 CheckFactories.registerCheck(
 "misc-bool-pointer-implicit-conversion");
+CheckFactories.registerCheck(
+"misc-comparison-misuse");
 CheckFactories.registerCheck(
 "misc-dangling-handle");
 CheckFactories.registerCheck(
Index: clang-tidy/misc/ComparisonMisuseCheck.h
===
--- /dev/null
+++ clang-tidy/misc/ComparisonMisuseCheck.h
@@ -0,0 +1,39 @@
+//===--- ComparisonMisuseCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COMPARISON_MISUSE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COMPARISON_MISUSE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// This checker reports errors related to the misuse of the comparison operator.
+/// It should warn for the following cases:
+///   - strcmp,strncmp,memcmp misuse.
+///   - char* is compared to a string literal
+///   - inequality operator usage for NULL
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/misc-comparison-misuse.html
+class ComparisonMisuseCheck : public ClangTidyCheck {
+public:
+  ComparisonMisuseCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) over

Re: [PATCH] D23423: [Clang-tidy] Comparison Function Address

2016-08-11 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a comment.

Clang-tidy terminology use //checks//, not //checkers//.


Repository:
  rL LLVM

https://reviews.llvm.org/D23423



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


Re: [PATCH] D23423: [Clang-tidy] Comparison Function Address

2016-08-11 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a comment.

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

If I'm not mistaken, GCC or Clang has warning that result of comparison is 
always true for such situations.



Comment at: clang-tidy/misc/ComparisonFunctionAddressCheck.h:19
@@ +18,3 @@
+
+/// This Checker gives a warning if address of a function is compared.
+/// For example: the programmer wants to write getc()==0 but writes getc==0.

Please lowercase Checker. Add add spaces across == below.


Comment at: docs/clang-tidy/checks/misc-comparison-function-address.rst:6
@@ +5,3 @@
+
+This Checker gives a warning if address of a function is compared.
+For example: the programmer wants to write ``getc()==0`` but writes ``getc==0``

Please lowercase Checker.


Comment at: docs/clang-tidy/checks/misc-comparison-function-address.rst:7
@@ +6,3 @@
+This Checker gives a warning if address of a function is compared.
+For example: the programmer wants to write ``getc()==0`` but writes ``getc==0``
+

Please add space across ==. Please also run Clang-format over examples code.


Comment at: docs/clang-tidy/checks/misc-comparison-function-address.rst:18
@@ +17,3 @@
+
+as a general rule, function pointers can be compared to other function 
pointers, function, 0, nullptr
+functions can be compared only against function pointers

Please highlight nullptr with ``.


Comment at: test/clang-tidy/misc-comparison-function-address.cpp:16
@@ +15,3 @@
+
+
+void test_function_warning() {

Unnecessary empty line.


Comment at: test/clang-tidy/misc-comparison-function-address.cpp:30
@@ +29,3 @@
+}
+
+

Unnecessary empty line.


Repository:
  rL LLVM

https://reviews.llvm.org/D23423



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


Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

May I ask you to upload patches with full diff context next time? I know, it's 
not directly supported by TortoiseGit, but there are at least two other 
reasonable ways of generating full diffs for Phabricator: 
http://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface 
and 
http://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-command-line.

Wrt testing, I think, apart from a new clang-tidy test, the changes to Driver 
and Tooling need separate tests as well.



Comment at: lib/Tooling/JSONCompilationDatabase.cpp:119
@@ -115,1 +118,3 @@
 StringRef EscapedCommandLine) {
+#if defined(LLVM_ON_WIN32)
+  llvm::BumpPtrAllocator Alloc;

zturner wrote:
> rnk wrote:
> > It would be nice if the JSON file just told us which quoting mechanism it 
> > was using. You can imagine building the compilation database on one system 
> > and sending it off to another for indexing.
> Correct me if I've got this wrong but:
> 
> 1. If you had a compile command database generated on non-Windows, and you 
> used it on Windows, then it would necessarily be referring to something other 
> than clang-cl right?  In which case, we don't support running clang in non-cl 
> mode on Windows.
> 
> 2. If you had a compile command database generated on Windows, then the only 
> supported configuration would involve clang-cl, in which case you couldn't 
> use it on non-Windows.
> 
> Is there a supported use case where a non-Windows compile database would be 
> used on Windows or vice versa?
> we don't support running clang in non-cl mode on Windows.

I think, clang in non-cl mode is functional on Windows to a certain degree 
(mingw-compatibility or something like this). Artificially preventing it from 
working doesn't seem to be right.


https://reviews.llvm.org/D23409



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


Re: r278395 - Don't enable PIE on i686-unknown-cloudabi.

2016-08-11 Thread Joerg Sonnenberger via cfe-commits
On Thu, Aug 11, 2016 at 08:03:22PM -, Ed Schouten via cfe-commits wrote:
> Modified: cfe/trunk/lib/Driver/ToolChains.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=278395&r1=278394&r2=278395&view=diff
> ==
> --- cfe/trunk/lib/Driver/ToolChains.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Aug 11 15:03:22 2016
> @@ -3344,6 +3344,19 @@ Tool *CloudABI::buildLinker() const {
>return new tools::cloudabi::Linker(*this);
>  }
>  
> +bool CloudABI::isPIEDefault() const {
> +  // Only enable PIE on architectures that support PC-relative
> +  // addressing. PC-relative addressing is required, as the process
> +  // startup code must be able to relocate itself.
> +  switch (getTriple().getArch()) {
> +  case llvm::Triple::aarch64:
> +  case llvm::Triple::x86_64:
> +return true;
> +  default:
> +return false;
> +  }
> +}
> +
>  SanitizerMask CloudABI::getSupportedSanitizers() const {
>SanitizerMask Res = ToolChain::getSupportedSanitizers();
>Res |= SanitizerKind::SafeStack;
> 

This comment doesn't make sense to me. x86 requires a relative call per
function to effectively compute EIP. The only difference for relocation
purposes is that GP register. All other questions are identical between
x86 and x86_64.

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


Re: r276900 - [Sema] Teach getCurrentThisType to reconize lambda in in-class initializer

2016-08-11 Thread Faisal Vali via cfe-commits
On Thu, Aug 11, 2016 at 1:07 PM, Richard Smith  wrote:
> Yes, this should be merged. It's not quite right, but it's certainly better
> than what we had before.

I would agree  that the comment is broken - but, unless i'm missing
something subtle, the subsequent logic and call to
adjustCVQualifiersForCXXThisWithinLambda should handle the scenario
you describe.

>
> On Mon, Aug 8, 2016 at 1:34 PM, Hans Wennborg  wrote:
>>
>> Richard: ping?
>>
>> On Wed, Jul 27, 2016 at 4:46 PM, Hans Wennborg  wrote:
>> > Should this be merged to 3.9?
>> >
>> > Thanks,
>> > Hans
>> >
>> > On Wed, Jul 27, 2016 at 11:25 AM, Erik Pilkington via cfe-commits
>> >  wrote:
>> >> Author: epilk
>> >> Date: Wed Jul 27 13:25:10 2016
>> >> New Revision: 276900
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=276900&view=rev
>> >> Log:
>> >> [Sema] Teach getCurrentThisType to reconize lambda in in-class
>> >> initializer
>> >>
>> >> Fixes PR27994, a crash on valid.
>> >>
>> >> Differential revision: https://reviews.llvm.org/D21145
>> >>
>> >> Modified:
>> >> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> >> cfe/trunk/test/SemaCXX/lambda-expressions.cpp
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=276900&r1=276899&r2=276900&view=diff
>> >>
>> >> ==
>> >> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jul 27 13:25:10 2016
>> >> @@ -961,32 +961,26 @@ static QualType adjustCVQualifiersForCXX
>> >>  QualType Sema::getCurrentThisType() {
>> >>DeclContext *DC = getFunctionLevelDeclContext();
>> >>QualType ThisTy = CXXThisTypeOverride;
>> >> +
>> >>if (CXXMethodDecl *method = dyn_cast(DC)) {
>> >>  if (method && method->isInstance())
>> >>ThisTy = method->getThisType(Context);
>> >>}
>> >> -  if (ThisTy.isNull()) {
>> >> -if (isGenericLambdaCallOperatorSpecialization(CurContext) &&
>> >> -CurContext->getParent()->getParent()->isRecord()) {
>> >> -  // This is a generic lambda call operator that is being
>> >> instantiated
>> >> -  // within a default initializer - so use the enclosing class as
>> >> 'this'.
>> >> -  // There is no enclosing member function to retrieve the 'this'
>> >> pointer
>> >> -  // from.
>> >> -
>> >> -  // FIXME: This looks wrong. If we're in a lambda within a lambda
>> >> within a
>> >> -  // default member initializer, we need to recurse up more
>> >> parents to find
>> >> -  // the right context. Looks like we should be walking up to the
>> >> parent of
>> >> -  // the closure type, checking whether that is itself a lambda,
>> >> and if so,
>> >> -  // recursing, until we reach a class or a function that isn't a
>> >> lambda
>> >> -  // call operator. And we should accumulate the constness of
>> >> *this on the
>> >> -  // way.
>> >> -
>> >> -  QualType ClassTy = Context.getTypeDeclType(
>> >> -  cast(CurContext->getParent()->getParent()));
>> >> -  // There are no cv-qualifiers for 'this' within default
>> >> initializers,
>> >> -  // per [expr.prim.general]p4.
>> >> -  ThisTy = Context.getPointerType(ClassTy);
>> >> -}
>> >> +
>> >> +  if (ThisTy.isNull() && isLambdaCallOperator(CurContext) &&
>> >> +  !ActiveTemplateInstantiations.empty()) {
>> >> +
>> >> +assert(isa(DC) &&
>> >> +   "Trying to get 'this' type from static method?");
>> >> +
>> >> +// This is a lambda call operator that is being instantiated as a
>> >> default
>> >> +// initializer. DC must point to the enclosing class type, so we
>> >> can recover
>> >> +// the 'this' type from it.
>> >> +
>> >> +QualType ClassTy =
>> >> Context.getTypeDeclType(cast(DC));
>> >> +// There are no cv-qualifiers for 'this' within default
>> >> initializers,
>> >> +// per [expr.prim.general]p4.
>
>
> This is wrong in C++17 onwards: if *this is captured by value by a
> non-mutable lambda, it should become const-qualified.
>
>>
>> >> +ThisTy = Context.getPointerType(ClassTy);
>> >>}
>> >>
>> >>// If we are within a lambda's call operator, the cv-qualifiers of
>> >> 'this'
>> >>
>> >> Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=276900&r1=276899&r2=276900&view=diff
>> >>
>> >> ==
>> >> --- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
>> >> +++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Wed Jul 27 13:25:10
>> >> 2016
>> >> @@ -1,5 +1,4 @@
>> >> -// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only -verify
>> >> -fblocks %s
>> >> -// RUN: %clang_cc1 -std=c++1y -Wno-unused-value -fsyntax-only -verify
>> >> -fblocks %s
>> >> +// RUN: %clang_cc1 -std=c++14 -Wno-unused-value 

Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D23409#512819, @zturner wrote:

> In https://reviews.llvm.org/D23409#512745, @zturner wrote:
>
> > In https://reviews.llvm.org/D23409#512720, @aaron.ballman wrote:
> >
> > > Patch generally LGTM, though I wonder if there's a way we can add test 
> > > coverage for this.
> >
> >
> > I'd imagine we can just enable the clang-tidy test suite on Windows (I'm 
> > assuming it's currently disabled).  I'll look into it.
>
>
> Actually yea I'm not sure how to go about doing this.  All the existing tests 
> are written to use GCC style command line, and it seems unreasonable to add a 
> cl style command line variant of every single test.  maybe alexfh@ or someone 
> has a suggestion.


I think a single test for cl-style command line variant should be enough, if it 
verifies different aspects of the transformation of the command line (`/` 
prefix for flags, `\` path separators, different quoting, what else?).


https://reviews.llvm.org/D23409



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


[PATCH] D23422: [VFS] Add 'ignore-non-existent-contents' field to YAML

2016-08-11 Thread Bruno Cardoso Lopes via cfe-commits
bruno created this revision.
bruno added a reviewer: benlangmuir.
bruno added a subscriber: cfe-commits.

Add 'ignore-non-existent-contents' to tell the VFS whether an invalid path
obtained via 'external-contents' should cause iteration on the VFS to stop.

If 'true', the VFS should ignore the entry and continue with the next. Allows
YAML files to be shared across multiple compiler invocations regardless of
prior existent paths in 'external-contents'. This global value is overridable
on a per-file basis.

This only adds the parsing part. Logic to actually use it will come next.

https://reviews.llvm.org/D23422

Files:
  include/clang/Basic/VirtualFileSystem.h
  lib/Basic/VirtualFileSystem.cpp
  test/VFS/Inputs/vfsoverlay2.yaml

Index: test/VFS/Inputs/vfsoverlay2.yaml
===
--- test/VFS/Inputs/vfsoverlay2.yaml
+++ test/VFS/Inputs/vfsoverlay2.yaml
@@ -1,5 +1,6 @@
 {
   'version': 0,
+  'ignore-non-existent-contents': false,
   'roots': [
 { 'name': 'OUT_DIR', 'type': 'directory',
   'contents': [
Index: lib/Basic/VirtualFileSystem.cpp
===
--- lib/Basic/VirtualFileSystem.cpp
+++ lib/Basic/VirtualFileSystem.cpp
@@ -801,6 +801,7 @@
 ///   'case-sensitive': 
 ///   'use-external-names': 
 ///   'overlay-relative': 
+///   'ignore-non-existent-contents': 
 ///
 /// Virtual directories are represented as
 /// \verbatim
@@ -860,6 +861,14 @@
   /// \brief Whether to use to use the value of 'external-contents' for the
   /// names of files.  This global value is overridable on a per-file basis.
   bool UseExternalNames = true;
+
+  /// \brief Whether an invalid path obtained via 'external-contents' should
+  /// cause iteration on the VFS to stop. If 'true', the VFS should ignore
+  /// the entry and continue with the next. Allows YAML files to be shared
+  /// across multiple compiler invocations regardless of prior existent
+  /// paths in 'external-contents'. This global value is overridable on a
+  /// per-file basis.
+  bool IgnoreNonExistentContents = true;
   /// @}
 
   /// Virtual file paths and external files could be canonicalized without "..",
@@ -1301,6 +1310,7 @@
   KeyStatusPair("case-sensitive", false),
   KeyStatusPair("use-external-names", false),
   KeyStatusPair("overlay-relative", false),
+  KeyStatusPair("ignore-non-existent-contents", false),
   KeyStatusPair("roots", true),
 };
 
@@ -1359,6 +1369,9 @@
   } else if (Key == "use-external-names") {
 if (!parseScalarBool(I->getValue(), FS->UseExternalNames))
   return false;
+  } else if (Key == "ignore-non-existent-contents") {
+if (!parseScalarBool(I->getValue(), FS->IgnoreNonExistentContents))
+  return false;
   } else {
 llvm_unreachable("key missing from Keys");
   }
@@ -1619,7 +1632,7 @@
   JSONWriter(llvm::raw_ostream &OS) : OS(OS) {}
   void write(ArrayRef Entries, Optional UseExternalNames,
  Optional IsCaseSensitive, Optional IsOverlayRelative,
- StringRef OverlayDir);
+ Optional IgnoreNonExistentContents, StringRef OverlayDir);
 };
 }
 
@@ -1675,6 +1688,7 @@
Optional UseExternalNames,
Optional IsCaseSensitive,
Optional IsOverlayRelative,
+   Optional IgnoreNonExistentContents,
StringRef OverlayDir) {
   using namespace llvm::sys;
 
@@ -1692,6 +1706,9 @@
 OS << "  'overlay-relative': '"
<< (UseOverlayRelative ? "true" : "false") << "',\n";
   }
+  if (IgnoreNonExistentContents.hasValue())
+OS << "  'ignore-non-existent-contents': '"
+   << (IgnoreNonExistentContents.getValue() ? "true" : "false") << "',\n";
   OS << "  'roots': [\n";
 
   if (!Entries.empty()) {
@@ -1748,7 +1765,8 @@
   });
 
   JSONWriter(OS).write(Mappings, UseExternalNames, IsCaseSensitive,
-   IsOverlayRelative, OverlayDir);
+   IsOverlayRelative, IgnoreNonExistentContents,
+   OverlayDir);
 }
 
 VFSFromYamlDirIterImpl::VFSFromYamlDirIterImpl(
Index: include/clang/Basic/VirtualFileSystem.h
===
--- include/clang/Basic/VirtualFileSystem.h
+++ include/clang/Basic/VirtualFileSystem.h
@@ -340,6 +340,7 @@
   Optional IsCaseSensitive;
   Optional IsOverlayRelative;
   Optional UseExternalNames;
+  Optional IgnoreNonExistentContents;
   std::string OverlayDir;
 
 public:
@@ -351,6 +352,9 @@
   void setUseExternalNames(bool UseExtNames) {
 UseExternalNames = UseExtNames;
   }
+  void setIgnoreNonExistentContents(bool IgnoreContents) {
+IgnoreNonExistentContents = IgnoreContents;
+  }
   void setOverlayDir(StringRef OverlayDirectory) {
 IsOverlayRelative = true;
 OverlayDir.assign(OverlayDirectory.str());
___
cfe-com

r278395 - Don't enable PIE on i686-unknown-cloudabi.

2016-08-11 Thread Ed Schouten via cfe-commits
Author: ed
Date: Thu Aug 11 15:03:22 2016
New Revision: 278395

URL: http://llvm.org/viewvc/llvm-project?rev=278395&view=rev
Log:
Don't enable PIE on i686-unknown-cloudabi.

We're only going to provide support for using PIE on architectures that
provide PC-relative addressing. i686 is not one of those, so add the
necessary bits for only passing in -pie -zrelro conditionally.

Modified:
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/cloudabi.c
cfe/trunk/test/Driver/cloudabi.cpp

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=278395&r1=278394&r2=278395&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Aug 11 15:03:22 2016
@@ -3344,6 +3344,19 @@ Tool *CloudABI::buildLinker() const {
   return new tools::cloudabi::Linker(*this);
 }
 
+bool CloudABI::isPIEDefault() const {
+  // Only enable PIE on architectures that support PC-relative
+  // addressing. PC-relative addressing is required, as the process
+  // startup code must be able to relocate itself.
+  switch (getTriple().getArch()) {
+  case llvm::Triple::aarch64:
+  case llvm::Triple::x86_64:
+return true;
+  default:
+return false;
+  }
+}
+
 SanitizerMask CloudABI::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::SafeStack;

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=278395&r1=278394&r2=278395&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Thu Aug 11 15:03:22 2016
@@ -632,8 +632,7 @@ public:
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
 
-  bool isPIEDefault() const override { return true; }
-
+  bool isPIEDefault() const override;
   SanitizerMask getSupportedSanitizers() const override;
   SanitizerMask getDefaultSanitizers() const override;
 

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=278395&r1=278394&r2=278395&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Aug 11 15:03:22 2016
@@ -7523,11 +7523,13 @@ void cloudabi::Linker::ConstructJob(Comp
 
   // CloudABI only supports static linkage.
   CmdArgs.push_back("-Bstatic");
-
-  // CloudABI uses Position Independent Executables exclusively.
-  CmdArgs.push_back("-pie");
   CmdArgs.push_back("--no-dynamic-linker");
-  CmdArgs.push_back("-zrelro");
+
+  // Provide PIE linker flags in case PIE is default for the architecture.
+  if (ToolChain.isPIEDefault()) {
+CmdArgs.push_back("-pie");
+CmdArgs.push_back("-zrelro");
+  }
 
   CmdArgs.push_back("--eh-frame-hdr");
   CmdArgs.push_back("--gc-sections");

Modified: cfe/trunk/test/Driver/cloudabi.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cloudabi.c?rev=278395&r1=278394&r2=278395&view=diff
==
--- cfe/trunk/test/Driver/cloudabi.c (original)
+++ cfe/trunk/test/Driver/cloudabi.c Thu Aug 11 15:03:22 2016
@@ -1,8 +1,14 @@
 // RUN: %clang %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s 
-check-prefix=SAFESTACK
 // SAFESTACK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} 
"-ffunction-sections" "-fdata-sections" {{.*}} "-fsanitize=safe-stack"
-// SAFESTACK: "-Bstatic" "-pie" "--no-dynamic-linker" "-zrelro" 
"--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" 
"{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
+// SAFESTACK: "-Bstatic" "--no-dynamic-linker" "-pie" "-zrelro" 
"--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" 
"{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
 
 // RUN: %clang %s -### -target x86_64-unknown-cloudabi 
-fno-sanitize=safe-stack 2>&1 | FileCheck %s -check-prefix=NOSAFESTACK
 // NOSAFESTACK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} 
"-ffunction-sections" "-fdata-sections"
 // NOSAFESTACK-NOT: "-fsanitize=safe-stack"
-// NOSAFESTACK: "-Bstatic" "-pie" "--no-dynamic-linker" "-zrelro" 
"--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" 
"{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
+// NOSAFESTACK: "-Bstatic" "--no-dynamic-linker" "-pie" "-zrelro" 
"--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" 
"{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
+
+// PIE shouldn't be enabled on i686. Just on architectures that provide
+// PC-relative addressing.
+// RUN: %cla

[PATCH] D23420: libcxx: Fix libcxx test on aarch64 with libunwind

2016-08-11 Thread Adhemerval Zanella via cfe-commits
zatrazz created this revision.
zatrazz added reviewers: jroelofs, danalbert.
zatrazz added subscribers: rengolin, cfe-commits.
Herald added a subscriber: aemerson.

Some tests uses 'long double' to/from conversions and for some targets
they are provided by compiler runtime (either compiler-rt or libgcc).
However when building libcxx with linunwinder current test configuration
at target_info.py do not include the required libraries, as:

  not llvm_unwinder:
[-lgcc_s] [-lgcc] [...] [-lgcc_s] [-lgcc]

  llvm_unwinder
[-lunwind] [-ldl]

This causes some tests build issues with missing symbols on aarch64,
for instance, where 'long double' is a binary float with 128-bits with
mostly of internal operations being provided by software routines.

This patch changes how to define the default linker flags by:

  not llvm_unwinder:
[-lgcc_s] [-lgcc]

  llvm_unwinder
[-lunwind] [-ldl] [-lgcc_s] [-lgcc]

I checked and aarch64 and x86_64 with libcxx and libunwind (with and without
LIBCXXABI_USE_LLVM_UNWINDER).

https://reviews.llvm.org/D23420

Files:
  test/libcxx/test/target_info.py

Index: test/libcxx/test/target_info.py
===
--- test/libcxx/test/target_info.py
+++ test/libcxx/test/target_info.py
@@ -170,17 +170,14 @@
 llvm_unwinder = self.full_config.get_lit_bool('llvm_unwinder', False)
 shared_libcxx = self.full_config.get_lit_bool('enable_shared', True)
 flags += ['-lm']
-if not llvm_unwinder:
-flags += ['-lgcc_s', '-lgcc']
 if enable_threads:
 flags += ['-lpthread']
 if not shared_libcxx:
   flags += ['-lrt']
 flags += ['-lc']
 if llvm_unwinder:
 flags += ['-lunwind', '-ldl']
-else:
-flags += ['-lgcc_s', '-lgcc']
+flags += ['-lgcc_s', '-lgcc']
 use_libatomic = self.full_config.get_lit_bool('use_libatomic', False)
 if use_libatomic:
 flags += ['-latomic']


Index: test/libcxx/test/target_info.py
===
--- test/libcxx/test/target_info.py
+++ test/libcxx/test/target_info.py
@@ -170,17 +170,14 @@
 llvm_unwinder = self.full_config.get_lit_bool('llvm_unwinder', False)
 shared_libcxx = self.full_config.get_lit_bool('enable_shared', True)
 flags += ['-lm']
-if not llvm_unwinder:
-flags += ['-lgcc_s', '-lgcc']
 if enable_threads:
 flags += ['-lpthread']
 if not shared_libcxx:
   flags += ['-lrt']
 flags += ['-lc']
 if llvm_unwinder:
 flags += ['-lunwind', '-ldl']
-else:
-flags += ['-lgcc_s', '-lgcc']
+flags += ['-lgcc_s', '-lgcc']
 use_libatomic = self.full_config.get_lit_bool('use_libatomic', False)
 if use_libatomic:
 flags += ['-latomic']
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23418: [analyzer] Added a pass architecture to the CloneDetector

2016-08-11 Thread Raphael Isemann via cfe-commits
teemperor planned changes to this revision.
teemperor added a comment.

- Add description
- Make sure functions in CloneDetection.cpp are in a more logical order.


https://reviews.llvm.org/D23418



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


[PATCH] D23418: [analyzer] Added a pass architecture to the CloneDetector

2016-08-11 Thread Raphael Isemann via cfe-commits
teemperor created this revision.
teemperor added reviewers: v.g.vassilev, NoQ, zaks.anna.
teemperor added a subscriber: cfe-commits.

https://reviews.llvm.org/D23418

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  lib/StaticAnalyzer/Checkers/CloneChecker.cpp

Index: lib/StaticAnalyzer/Checkers/CloneChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CloneChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CloneChecker.cpp
@@ -36,11 +36,9 @@
  AnalysisManager &Mgr, BugReporter &BR) const;
 
   /// \brief Reports all clones to the user.
-  void reportClones(SourceManager &SM, AnalysisManager &Mgr,
-int MinComplexity) const {
-
-std::vector CloneGroups;
-CloneDetector.findClones(CloneGroups, MinComplexity);
+  void
+  reportClones(SourceManager &SM, AnalysisManager &Mgr,
+   const std::vector &Clones) const {
 
 DiagnosticsEngine &DiagEngine = Mgr.getDiagnostic();
 
@@ -50,7 +48,7 @@
 unsigned NoteID = DiagEngine.getCustomDiagID(DiagnosticsEngine::Note,
  "Related code clone is here.");
 
-for (CloneDetector::CloneGroup &Group : CloneGroups) {
+for (const CloneDetector::CloneGroup &Group : Clones) {
   // We group the clones by printing the first as a warning and all others
   // as a note.
   DiagEngine.Report(Group.Sequences.front().getStartLoc(), WarnID);
@@ -62,11 +60,37 @@
 
   /// \brief Reports only suspicious clones to the user along with informaton
   ///that explain why they are suspicious.
-  void reportSuspiciousClones(SourceManager &SM, AnalysisManager &Mgr,
-  int MinComplexity) const {
-
-std::vector Clones;
-CloneDetector.findSuspiciousClones(Clones, MinComplexity);
+  void reportSuspiciousClones(
+  SourceManager &SM, AnalysisManager &Mgr,
+  const std::vector &Clones) const {
+
+std::vector Pairs;
+
+for (const CloneDetector::CloneGroup &Group : Clones) {
+  for (unsigned i = 0; i < Group.Sequences.size(); ++i) {
+VariablePattern PatternA(Group.Sequences[i]);
+
+for (unsigned j = i + 1; j < Group.Sequences.size(); ++j) {
+  VariablePattern PatternB(Group.Sequences[j]);
+
+  VariablePattern::SuspiciousClonePair ClonePair;
+  // For now, we only report clones which break the variable pattern
+  // just
+  // once because multiple differences in a pattern are an indicator
+  // that
+  // those differences are maybe intended (e.g. because it's actually
+  // a different algorithm).
+  // TODO: In very big clones even multiple variables can be unintended,
+  // so replacing this number with a percentage could better handle such
+  // cases. On the other hand it could increase the false-positive rate
+  // for all clones if the percentage is too high.
+  if (PatternA.getPatternDifferences(PatternB, &ClonePair) == 1) {
+Pairs.push_back(ClonePair);
+break;
+  }
+}
+  }
+}
 
 DiagnosticsEngine &DiagEngine = Mgr.getDiagnostic();
 
@@ -81,7 +105,7 @@
 DiagnosticsEngine::Note, "Or maybe you wanted to use %0 here in this "
  "similar piece of code?");
 
-for (CloneDetector::SuspiciousClonePair &Pair : Clones) {
+for (VariablePattern::SuspiciousClonePair &Pair : Pairs) {
   // The first clone always has a suggestion and we report it to the user
   // along with the place where the suggestion should be used.
   DiagEngine.Report(Pair.FirstClone.Location.getBegin(), WarnID)
@@ -118,6 +142,8 @@
   // At this point, every statement in the translation unit has been analyzed by
   // the CloneDetector. The only thing left to do is to report the found clones.
 
+  SourceManager &SM = BR.getSourceManager();
+
   int MinComplexity = Mgr.getAnalyzerOptions().getOptionAsInteger(
   "MinimumCloneComplexity", 10, this);
   assert(MinComplexity >= 0);
@@ -128,11 +154,24 @@
   bool ReportNormalClones = Mgr.getAnalyzerOptions().getBooleanOption(
   "ReportNormalClones", true, this);
 
+  std::vector AllCloneGroups;
+  CloneDetector::PassList Passes = {
+  new MinComplexityPass(MinComplexity), new MinGroupSizePass(2),
+  new VerifyCloneHashesPass(), new OnlyLargestClonePass()};
+  CloneDetector.findClones(AllCloneGroups, Passes);
+
   if (ReportSuspiciousClones)
-reportSuspiciousClones(BR.getSourceManager(), Mgr, MinComplexity);
+reportSuspiciousClones(SM, Mgr, AllCloneGroups);
+
+  CloneDetector::PassList OnlyMatchingVariablePatterns = {
+  new MinGroupSizePass(2), new MatchingVariablePatternPass()};
+
+  std::vector CloneGroups;
+  CloneDetector::applyPasses(AllCloneGroups, CloneGroups,
+ OnlyMatchingVariablePatterns);
 
   if (ReportNormal

r278393 - Pass in frame pointer omitting compiler flags for CloudABI as well.

2016-08-11 Thread Ed Schouten via cfe-commits
Author: ed
Date: Thu Aug 11 14:23:30 2016
New Revision: 278393

URL: http://llvm.org/viewvc/llvm-project?rev=278393&view=rev
Log:
Pass in frame pointer omitting compiler flags for CloudABI as well.

On Linux we pass in -fomit-frame-pointer flags (and similar)
automatically if optimization is enabled. Let's do the same thing on
CloudABI. Without this, Clang seems to run out of registers quite
quickly while trying to build code with inline assembly.


Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/frame-pointer-elim.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=278393&r1=278392&r2=278393&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Aug 11 14:23:30 2016
@@ -3242,7 +3242,7 @@ static bool shouldUseFramePointerForTarg
 break;
   }
 
-  if (Triple.isOSLinux()) {
+  if (Triple.isOSLinux() || Triple.getOS() == llvm::Triple::CloudABI) {
 switch (Triple.getArch()) {
 // Don't use a frame pointer on linux if optimizing for certain targets.
 case llvm::Triple::mips64:

Modified: cfe/trunk/test/Driver/frame-pointer-elim.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/frame-pointer-elim.c?rev=278393&r1=278392&r2=278393&view=diff
==
--- cfe/trunk/test/Driver/frame-pointer-elim.c (original)
+++ cfe/trunk/test/Driver/frame-pointer-elim.c Thu Aug 11 14:23:30 2016
@@ -8,6 +8,15 @@
 // RUN:   FileCheck --check-prefix=LINUX %s
 // LINUX-NOT: "-momit-leaf-frame-pointer"
 
+// CloudABI follows the same rules as Linux.
+// RUN: %clang -### -target x86_64-unknown-cloudabi -S -O1 %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CLOUDABI-OPT %s
+// CLOUDABI-OPT: "-momit-leaf-frame-pointer"
+
+// RUN: %clang -### -target x86_64-unknown-cloudabi -S %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=CLOUDABI %s
+// CLOUDABI-NOT: "-momit-leaf-frame-pointer"
+
 // Darwin disables omitting the leaf frame pointer even under optimization
 // unless the command lines are given.
 // RUN: %clang -### -target i386-apple-darwin -S %s 2>&1 | \


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


Re: [PATCH] D23125: Modules: add command line option to support loading prebuilt modules on demand, without parsing any module map

2016-08-11 Thread Manman Ren via cfe-commits
manmanren updated this revision to Diff 67727.
manmanren added a comment.

Addressing Richard's comments.


https://reviews.llvm.org/D23125

Files:
  docs/Modules.rst
  include/clang/Driver/Options.td
  include/clang/Lex/HeaderSearch.h
  include/clang/Lex/HeaderSearchOptions.h
  include/clang/Serialization/Module.h
  lib/Driver/Tools.cpp
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/FrontendActions.cpp
  lib/Lex/HeaderSearch.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ModuleManager.cpp
  test/Driver/modules.m
  test/Modules/Inputs/prebuilt-module/a.h
  test/Modules/Inputs/prebuilt-module/module.modulemap
  test/Modules/prebuilt-module.m

Index: test/Modules/prebuilt-module.m
===
--- test/Modules/prebuilt-module.m
+++ test/Modules/prebuilt-module.m
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -fmodules -x objective-c -I %S/Inputs/prebuilt-module -triple %itanium_abi_triple -emit-module %S/Inputs/prebuilt-module/module.modulemap -fmodule-name=prebuilt -o %t/prebuilt.pcm
+// RUN: %clang_cc1 -fmodules -fprebuilt-module-path=%t/ -fdisable-module-hash %s -verify
+
+// expected-no-diagnostics
+@import prebuilt;
+int test() {
+  return a;
+}
Index: test/Modules/Inputs/prebuilt-module/module.modulemap
===
--- test/Modules/Inputs/prebuilt-module/module.modulemap
+++ test/Modules/Inputs/prebuilt-module/module.modulemap
@@ -0,0 +1 @@
+module prebuilt { header "a.h" }
Index: test/Modules/Inputs/prebuilt-module/a.h
===
--- test/Modules/Inputs/prebuilt-module/a.h
+++ test/Modules/Inputs/prebuilt-module/a.h
@@ -0,0 +1 @@
+const int a = 1;
Index: test/Driver/modules.m
===
--- test/Driver/modules.m
+++ test/Driver/modules.m
@@ -39,6 +39,13 @@
 // RUN: %clang -fmodules-disable-diagnostic-validation -### %s 2>&1 | FileCheck -check-prefix=MODULES_DISABLE_DIAGNOSTIC_VALIDATION %s
 // MODULES_DISABLE_DIAGNOSTIC_VALIDATION: -fmodules-disable-diagnostic-validation
 
+// RUN: %clang -fmodules -### %s 2>&1 | FileCheck -check-prefix=MODULES_PREBUILT_PATH_DEFAULT %s
+// MODULES_PREBUILT_PATH_DEFAULT-NOT: -fprebuilt-module-path
+
+// RUN: %clang -fmodules -fprebuilt-module-path=foo -fprebuilt-module-path=bar -### %s 2>&1 | FileCheck -check-prefix=MODULES_PREBUILT_PATH %s
+// MODULES_PREBUILT_PATH: "-fprebuilt-module-path=foo"
+// MODULES_PREBUILT_PATH: "-fprebuilt-module-path=bar"
+
 // RUN: %clang -fmodules -fmodule-map-file=foo.map -fmodule-map-file=bar.map -### %s 2>&1 | FileCheck -check-prefix=CHECK-MODULE-MAP-FILES %s
 // CHECK-MODULE-MAP-FILES: "-fmodules"
 // CHECK-MODULE-MAP-FILES: "-fmodule-map-file=foo.map"
Index: lib/Serialization/ModuleManager.cpp
===
--- lib/Serialization/ModuleManager.cpp
+++ lib/Serialization/ModuleManager.cpp
@@ -66,7 +66,7 @@
   // Look for the file entry. This only fails if the expected size or
   // modification time differ.
   const FileEntry *Entry;
-  if (Type == MK_ExplicitModule) {
+  if (Type == MK_ExplicitModule || Type == MK_PrebuiltModule) {
 // If we're not expecting to pull this file out of the module cache, it
 // might have a different mtime due to being moved across filesystems in
 // a distributed build. The size must still match, though. (As must the
Index: lib/Serialization/ASTReaderDecl.cpp
===
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -1384,7 +1384,7 @@
 // any other module's anonymous namespaces, so don't attach the anonymous
 // namespace at all.
 NamespaceDecl *Anon = cast(Reader.GetDecl(AnonNamespace));
-if (F.Kind != MK_ImplicitModule && F.Kind != MK_ExplicitModule)
+if (!F.isModule())
   D->setAnonymousNamespace(Anon);
   }
 }
@@ -3747,8 +3747,7 @@
   // Each module has its own anonymous namespace, which is disjoint from
   // any other module's anonymous namespaces, so don't attach the anonymous
   // namespace at all.
-  if (ModuleFile.Kind != MK_ImplicitModule &&
-  ModuleFile.Kind != MK_ExplicitModule) {
+  if (!ModuleFile.isModule()) {
 if (TranslationUnitDecl *TU = dyn_cast(D))
   TU->setAnonymousNamespace(Anon);
 else
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -1312,8 +1312,7 @@
 SrcMgr::CharacteristicKind
   FileCharacter = (SrcMgr::CharacteristicKind)Record[2];
 SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]);
-if (IncludeLoc.isInvalid() &&
-(F->Kind == MK

Re: [libcxx] r278191 - test/hard_link_count(): Fix test on darwin

2016-08-11 Thread Adrian Prantl via cfe-commits
I'm just curious: Is libcxx generally supposed to merely pass through what the 
operating system is returning (as in this case) or is is supposed to provide a 
common abstraction that behaves the same on all platforms?

-- adrian

> On Aug 10, 2016, at 8:23 PM, Eric Fiselier via cfe-commits 
>  wrote:
> 
> Thanks Matthias. My apoligies, I lost track of this patch.
> 
> On Tue, Aug 9, 2016 at 7:31 PM, Bruno Cardoso Lopes via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Thanks Matthias!
> 
> On Tue, Aug 9, 2016 at 6:02 PM, Matthias Braun via cfe-commits
> mailto:cfe-commits@lists.llvm.org>> wrote:
> > Author: matze
> > Date: Tue Aug  9 20:02:28 2016
> > New Revision: 278191
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=278191&view=rev 
> > 
> > Log:
> > test/hard_link_count(): Fix test on darwin
> >
> > The hard link count that stat reports are different between normal hfs and 
> > the
> > case sensitive variant. Accept both.
> >
> > Modified:
> > 
> > libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
> >
> > Modified: 
> > libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
> > URL: 
> > http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp?rev=278191&r1=278190&r2=278191&view=diff
> >  
> > 
> > ==
> > --- 
> > libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
> >  (original)
> > +++ 
> > libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
> >  Tue Aug  9 20:02:28 2016
> > @@ -45,18 +45,27 @@ TEST_CASE(hard_link_count_for_file)
> >
> >  TEST_CASE(hard_link_count_for_directory)
> >  {
> > -uintmax_t DirExpect = 3;
> > -uintmax_t Dir3Expect = 2;
> > +uintmax_t DirExpect = 3; // hard link from . .. and Dir2
> > +uintmax_t Dir3Expect = 2; // hard link from . ..
> > +uintmax_t DirExpectAlt = DirExpect;
> > +uintmax_t Dir3ExpectAlt = Dir3Expect;
> >  #if defined(__APPLE__)
> > -DirExpect += 2;
> > -Dir3Expect += 1;
> > +// Filesystems formatted with case sensitive hfs+ behave unixish as
> > +// expected. Normal hfs+ filesystems report the number of directory
> > +// entries instead.
> > +DirExpectAlt = 5; // .  ..  Dir2  file1  file2
> > +Dir3Expect = 3; // .  ..  file5
> >  #endif
> > -TEST_CHECK(hard_link_count(StaticEnv::Dir) == DirExpect);
> > -TEST_CHECK(hard_link_count(StaticEnv::Dir3) == Dir3Expect);
> > +TEST_CHECK(hard_link_count(StaticEnv::Dir) == DirExpect ||
> > +   hard_link_count(StaticEnv::Dir) == DirExpectAlt);
> > +TEST_CHECK(hard_link_count(StaticEnv::Dir3) == Dir3Expect ||
> > +   hard_link_count(StaticEnv::Dir3) == Dir3ExpectAlt);
> >
> >  std::error_code ec;
> > -TEST_CHECK(hard_link_count(StaticEnv::Dir, ec) == DirExpect);
> > -TEST_CHECK(hard_link_count(StaticEnv::Dir3, ec) == Dir3Expect);
> > +TEST_CHECK(hard_link_count(StaticEnv::Dir, ec) == DirExpect ||
> > +   hard_link_count(StaticEnv::Dir, ec) == DirExpectAlt);
> > +TEST_CHECK(hard_link_count(StaticEnv::Dir3, ec) == Dir3Expect ||
> > +   hard_link_count(StaticEnv::Dir3, ec) == Dir3ExpectAlt);
> >  }
> >  TEST_CASE(hard_link_count_increments_test)
> >  {
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org 
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> > 
> 
> 
> 
> --
> Bruno Cardoso Lopes
> http://www.brunocardoso.cc 
> ___
> 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

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


[libcxx] r278387 - Remove test for the sign of a NaN - doesn't work on MIPS, not strictly legal. Fixes bug 28936

2016-08-11 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Aug 11 13:46:24 2016
New Revision: 278387

URL: http://llvm.org/viewvc/llvm-project?rev=278387&view=rev
Log:
Remove test for the sign of a NaN - doesn't work on MIPS, not strictly legal. 
Fixes bug 28936

Modified:

libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp

Modified: 
libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp?rev=278387&r1=278386&r2=278387&view=diff
==
--- 
libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp
 Thu Aug 11 13:46:24 2016
@@ -91,7 +91,6 @@ void test_edges()
 {
 assert(std::isnan(r.real()));
 assert(std::isnan(r.imag()));
-assert(std::signbit(testcases[i].imag()) == 
std::signbit(r.imag()));
 }
 else if (std::isnan(testcases[i].real()) && 
std::isinf(testcases[i].imag()))
 {


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


Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-11 Thread Erik Pilkington via cfe-commits
erik.pilkington updated this revision to Diff 67713.
erik.pilkington added a comment.

This new patch adds some testcases for templates, and simplifies some control 
flow in `TraverseIfStmt`. This patch also removes diagnostics for instantiated 
templates, instead just using the pattern. This means that a dependent type 
that was resolved during instantiation can refer to an unavailable declaration. 
For example, the following now compiles cleanly (when we want a diagnostic):

  void f(int);
  void f(char) __attribute__((availability(macos, introduced=10.12)));
  
  template  void use_f(T p) { f(p); }
  
  template void use_f();

This is done so containers, such as `vector` can be used 
safely provided `partially_available` is safe at the point of instantiation. I 
think the way to improve this is in `Sema::getVersionForDecl()`. There we could 
look at function and template parameters to determine the best base version, 
then diagnose against it.


https://reviews.llvm.org/D23003

Files:
  include/clang/AST/Stmt.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/AST/Stmt.cpp
  lib/Sema/JumpDiagnostics.cpp
  lib/Sema/ScopeInfo.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/objc-available.m
  test/Sema/attr-availability.c
  test/SemaObjC/attr-availability.m
  test/SemaObjC/property-deprecated-warning.m
  test/SemaObjC/unguarded-availability.m

Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -0,0 +1,180 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -DOBJCPP -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
+
+#define AVAILABLE_10_0  __attribute__((availability(macos, introduced = 10.0)))
+#define AVAILABLE_10_11 __attribute__((availability(macos, introduced = 10.11)))
+#define AVAILABLE_10_12 __attribute__((availability(macos, introduced = 10.12)))
+
+int func_10_11() AVAILABLE_10_11; // expected-note 4 {{'func_10_11' has been explicitly marked partial here}}
+
+#ifdef OBJCPP
+// expected-note@+2 {{marked partial here}}
+#endif
+int func_10_12() AVAILABLE_10_12; // expected-note 5 {{'func_10_12' has been explicitly marked partial here}}
+
+int func_10_0() AVAILABLE_10_0;
+
+void use_func() {
+  func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *))
+func_10_11();
+  else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+}
+
+void defn_10_11() AVAILABLE_10_11;
+
+void defn_10_11() {
+  func_10_11();
+}
+
+void nested_ifs() {
+  if (@available(macos 10.12, *)) {
+if (@available(macos 10.10, *)) {
+  func_10_12();
+} else {
+  func_10_12();
+}
+  } else {
+func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
+  }
+}
+
+void star_case() {
+  if (@available(ios 9, *)) {
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+func_10_0();
+  } else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *)) {
+if (@available(ios 8, *)) {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
+} else {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
+}
+  }
+}
+
+typedef int int_10_11 AVAILABLE_10_11; // expected-note {{'int_10_11' has been explicitly marked partial here}}
+#ifdef OBJCPP
+// expected-note@+2 {{marked partial here}}
+#endif
+typedef int int_10_12 AVAILABLE_10_12; // expected-note 3 {{'int_10_12' has been explicitly marked partial here}}
+
+void use_typedef() {
+  int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}}
+}
+
+__attribute__((objc_root_class))
+AVAILABLE_10_11 @interface Class_10_11 {
+  int_10_11 foo;
+  int_10_12 bar; // expected-warning {{'int_10_12' is partial: introduced in macOS 10.

r278382 - [analyzer] Teach RetainCountChecker about CVFooRetain

2016-08-11 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Thu Aug 11 13:41:29 2016
New Revision: 278382

URL: http://llvm.org/viewvc/llvm-project?rev=278382&view=rev
Log:
[analyzer] Teach RetainCountChecker about CVFooRetain

Change the retain count checker to treat CoreFoundation-style "CV"-prefixed
reference types from CoreVideo similarly to CoreGraphics types. With this
change, we treat CVFooRetain() on a CVFooRef type as a retain. CVFooRelease()
APIs are annotated as consuming their parameter, so this change prevents false
positives about incorrect decrements of reference counts.



Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
cfe/trunk/test/Analysis/retain-release.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=278382&r1=278381&r2=278382&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Thu Aug 11 
13:41:29 2016
@@ -1171,8 +1171,9 @@ RetainSummaryManager::getFunctionSummary
 break;
   }
 
-  // For CoreGraphics ('CG') types.
-  if (cocoa::isRefType(RetTy, "CG", FName)) {
+  // For CoreGraphics ('CG') and CoreVideo ('CV') types.
+  if (cocoa::isRefType(RetTy, "CG", FName) ||
+  cocoa::isRefType(RetTy, "CV", FName)) {
 if (isRetain(FD, FName))
   S = getUnarySummary(FT, cfretain);
 else
@@ -3372,12 +3373,13 @@ bool RetainCountChecker::evalCall(const
 // Handle: id NSMakeCollectable(CFTypeRef)
 canEval = II->isStr("NSMakeCollectable");
   } else if (ResultTy->isPointerType()) {
-// Handle: (CF|CG)Retain
+// Handle: (CF|CG|CV)Retain
 // CFAutorelease
 // CFMakeCollectable
 // It's okay to be a little sloppy here (CGMakeCollectable doesn't exist).
 if (cocoa::isRefType(ResultTy, "CF", FName) ||
-cocoa::isRefType(ResultTy, "CG", FName)) {
+cocoa::isRefType(ResultTy, "CG", FName) ||
+cocoa::isRefType(ResultTy, "CV", FName)) {
   canEval = isRetain(FD, FName) || isAutorelease(FD, FName) ||
 isMakeCollectable(FD, FName);
 }

Modified: cfe/trunk/test/Analysis/retain-release.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=278382&r1=278381&r2=278382&view=diff
==
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Aug 11 13:41:29 2016
@@ -1247,6 +1247,26 @@ CVReturn rdar_7283567_2(CFAllocatorRef a
   pixelBufferAttributes, pixelBufferOut) ;
 }
 
+#pragma clang arc_cf_code_audited begin
+typedef struct SomeOpaqueStruct *CMSampleBufferRef;
+CVImageBufferRef _Nonnull CMSampleBufferGetImageBuffer(CMSampleBufferRef 
_Nonnull sbuf);
+#pragma clang arc_cf_code_audited end
+
+CVBufferRef _Nullable CVBufferRetain(CVBufferRef _Nullable buffer);
+void CVBufferRelease(CF_CONSUMED CVBufferRef _Nullable buffer);
+
+void testCVPrefixRetain(CMSampleBufferRef sbuf) {
+  // Make sure RetainCountChecker treats CVFooRetain() as a CF-style retain.
+  CVPixelBufferRef pixelBuf = CMSampleBufferGetImageBuffer(sbuf);
+  CVBufferRetain(pixelBuf);
+  CVBufferRelease(pixelBuf); // no-warning
+
+
+  // Make sure result of CVFooRetain() is the same as its argument.
+  CVPixelBufferRef pixelBufAlias = CVBufferRetain(pixelBuf);
+  CVBufferRelease(pixelBufAlias); // no-warning
+}
+
 
//===--===//
 //  False leak associated with 
 //  CGBitmapContextCreateWithData


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


Re: r278264 - Reapply [Sema] Add sizeof diagnostics for bzero

2016-08-11 Thread Bruno Cardoso Lopes via cfe-commits
On Thu, Aug 11, 2016 at 5:43 AM, Joerg Sonnenberger via cfe-commits
 wrote:
>
> On Wed, Aug 10, 2016 at 02:36:01PM -0700, Bruno Cardoso Lopes wrote:
> > Hi Joerg,
> >
> > > Given that bzero is pretty much non-standard at this point, I strongly
> > > dislike the approach of checking only the function name.
> >
> > Thanks for the feedback. bzero it's widely used though, I think it's a
> > usability win to perform a diagnostic here, despite bzero being
> > non-standard.
>
> Oh, I don't disagree that it is useful. Some projects still have a
> ridiculous amount of non-standard bzero and bcmp invocations.
>
> >
> > Is there any additional reason why you dislike it or additional checks
> > you suggest? IIUC, Sema::CheckMemaccessArguments already checks if the
> > number of arguments is the same and if they are indeed what they're
> > supposed to be.
>
> It checks the number of arguments, but that's about it. It doesn't for
> example check that the first argument is a pointer.

Right, it does not specifically check it's the first. Fixed in r278379.

-- 
Bruno Cardoso Lopes
http://www.brunocardoso.cc
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23125: Modules: add command line option to support loading prebuilt modules on demand, without parsing any module map

2016-08-11 Thread Manman Ren via cfe-commits
manmanren added inline comments.


Comment at: lib/Frontend/CompilerInstance.cpp:1438-1450
@@ -1437,3 +1437,15 @@
 // Search for a module with the given name.
 Module = PP->getHeaderSearchInfo().lookupModule(ModuleName);
-if (!Module) {
+HeaderSearchOptions &HSOpts =
+PP->getHeaderSearchInfo().getHeaderSearchOpts();
+
+std::string ModuleFileName;
+bool LoadFromPrebuiltModulePath = false;
+if (Module) {
+  ModuleFileName = PP->getHeaderSearchInfo().getModuleFileName(Module);
+} else if (!HSOpts.PrebuiltModulePath.empty()) {
+  // Try to load the module from the prebuilt module path.
+  ModuleFileName =
+  PP->getHeaderSearchInfo().getModuleFileName(ModuleName, "", true);
+  LoadFromPrebuiltModulePath = true;
+} else {

bruno wrote:
> manmanren wrote:
> > rsmith wrote:
> > > It looks like the logic here is:
> > > 
> > >  * if we found the module in a module map, then look for it in the module 
> > > cache
> > >  * otherwise, if we have a prebuilt module path, then look for it there
> > >  * otherwise, error
> > > 
> > > I think that may be surprising; if I explicitly load a module map, 
> > > perhaps via `-fmodule-map-file=`, and supply a prebuilt form of that 
> > > module in the prebuilt modules path, I'd expect my prebuilt form to still 
> > > be used.
> > > 
> > > Perhaps instead we could first search the prebuilt module path for an 
> > > existing .pcm file, and if that fails and we have a `Module` then look 
> > > for it in the module cache?
> > I was wondering about the priority of loading from prebuilt module path vs. 
> > loading from module cache. Your suggestion makes sense.
> +1 to Richard's suggestion here.
> 
> I wonder about the workflow on generating such modules. Suppose I want to 
> build some modules to re-use later with -fprebuilt-module-path=. RIght now, 
> we get a module cache with hash in the names unless we disable hash 
> computation via cc1 option -fdisable-module-hash. Should we assume that the 
> user will have to copy out the cache dir and rename the modules OR that it 
> will use -fdisable-module-hash instead? Should this option also try to read 
> out modules with a hash in the name? Should we promote -fdisable-module-hash 
> to a driver option as well?
> 
> @Manman, do you have any workflow in mind? @Richard, do you have any feedback 
> in this respect?
> 
> In the crash reproducer we often have to rebuild the modules when running the 
> script in a different machine because of the paths used to hash the modules, 
> it would be nice (depending on the resulting design) if the crash reproducer 
> could use -fprebuilt-module-path in order to try to re-use the pre-built 
> modules resulting from the crash. 
If the modules are built implicitly with module hash, to load the module files 
as prebuilt modules, the user needs to copy out the cache dir and rename the 
modules. The user can choose to emit the modules explicitly or disable module 
hash when building the modules.


Comment at: lib/Frontend/CompilerInstance.cpp:1497-1505
@@ +1496,11 @@
+  if (LoadFromPrebuiltModulePath && !Module) {
+// Create a Module if we are using the prebuilt module path.
+Module = PP->getHeaderSearchInfo().getModuleMap().findOrCreateModule(
+ModuleName, nullptr, false/*IsFramework*/,
+false/*IsExplicit*/).first;
+// FIXME: Since we are mostly prebuilding system modules, we set
+// IsSystem to true here. This is not always the correct choice,
+// and IsSystem can affect diagnostics.
+Module->IsSystem = true;
+Module->IsFromModuleFile = true;
+  }

manmanren wrote:
> rsmith wrote:
> > The module file will have provided a `Module` instance, if it is in fact a 
> > module file for the requested module. Instead of inventing a `Module` here, 
> > can you check that one exists and produce an error if not?
> This is nice to know. I didn't realize we construct a Module when calling 
> ReadAST. Can you be more specific on how to check if a Module exists?
I assumed ReadAST only constructed Module instances for submodules, because it 
is inside ReadSubmoduleBlock. It turns out it also constructed Module instance 
for the top level module. I will update the patch.


https://reviews.llvm.org/D23125



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


r278379 - [Sema] Add more strict check for sizeof diagnostics for bzero

2016-08-11 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Thu Aug 11 13:33:15 2016
New Revision: 278379

URL: http://llvm.org/viewvc/llvm-project?rev=278379&view=rev
Log:
[Sema] Add more strict check for sizeof diagnostics for bzero

Follow-up from r278264 after Joerg's feedback.

Since bzero is not standard, be more strict: also check if the first
argument is a pointer, which harden the check for when it does not come
originally from a builtin.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=278379&r1=278378&r2=278379&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Aug 11 13:33:15 2016
@@ -6199,6 +6199,13 @@ void Sema::CheckMemaccessArguments(const
   const Expr *SizeOfArg = getSizeOfExprArg(LenExpr);
   llvm::FoldingSetNodeID SizeOfArgID;
 
+  // Although widely used, 'bzero' is not a standard function. Be more strict
+  // with the argument types before allowing diagnostics and only allow the
+  // form bzero(ptr, sizeof(...)).
+  QualType FirstArgTy = Call->getArg(0)->IgnoreParenImpCasts()->getType();
+  if (BId == Builtin::BIbzero && !FirstArgTy->getAs())
+return;
+
   for (unsigned ArgIdx = 0; ArgIdx != LastArg; ++ArgIdx) {
 const Expr *Dest = Call->getArg(ArgIdx)->IgnoreParenImpCasts();
 SourceRange ArgRange = Call->getArg(ArgIdx)->getSourceRange();


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


Re: r277522 - [CFG] Fix crash finding destructor of lifetime-extended temporary.

2016-08-11 Thread Hans Wennborg via cfe-commits
Merged in r278376.

Thanks,
Hans

On Thu, Aug 11, 2016 at 11:13 AM, Richard Smith  wrote:
> Well, the whole approach here is still wrong (per the FIXME in
> CFGBuilder::addLocalScopeForVarDecl) but this at least makes it consistent.
> Let's take this for 3.9 to at least stem the bleeding.
>
>
> On Tue, Aug 9, 2016 at 11:57 AM, Hans Wennborg  wrote:
>>
>> For the record, this was for PR28666.
>>
>> Richard: what do you think about merging this to 3.9?
>>
>> On Tue, Aug 2, 2016 at 2:07 PM, Devin Coughlin via cfe-commits
>>  wrote:
>> > Author: dcoughlin
>> > Date: Tue Aug  2 16:07:23 2016
>> > New Revision: 277522
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=277522&view=rev
>> > Log:
>> > [CFG] Fix crash finding destructor of lifetime-extended temporary.
>> >
>> > Fix a crash under -Wthread-safety when finding the destructor for a
>> > lifetime-extending reference.
>> >
>> > A patch by Nandor Licker!
>> >
>> > Differential Revision: https://reviews.llvm.org/D22419
>> >
>> > Modified:
>> > cfe/trunk/lib/Analysis/CFG.cpp
>> > cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
>> >
>> > Modified: cfe/trunk/lib/Analysis/CFG.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=277522&r1=277521&r2=277522&view=diff
>> >
>> > ==
>> > --- cfe/trunk/lib/Analysis/CFG.cpp (original)
>> > +++ cfe/trunk/lib/Analysis/CFG.cpp Tue Aug  2 16:07:23 2016
>> > @@ -3902,7 +3902,17 @@ CFGImplicitDtor::getDestructorDecl(ASTCo
>> >  case CFGElement::AutomaticObjectDtor: {
>> >const VarDecl *var = castAs().getVarDecl();
>> >QualType ty = var->getType();
>> > -  ty = ty.getNonReferenceType();
>> > +
>> > +  // FIXME: See CFGBuilder::addLocalScopeForVarDecl.
>> > +  //
>> > +  // Lifetime-extending constructs are handled here. This works for
>> > a single
>> > +  // temporary in an initializer expression.
>> > +  if (ty->isReferenceType()) {
>> > +if (const Expr *Init = var->getInit()) {
>> > +  ty = getReferenceInitTemporaryType(astContext, Init);
>> > +}
>> > +  }
>> > +
>> >while (const ArrayType *arrayType =
>> > astContext.getAsArrayType(ty)) {
>> >  ty = arrayType->getElementType();
>> >}
>> >
>> > Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=277522&r1=277521&r2=277522&view=diff
>> >
>> > ==
>> > --- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
>> > +++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Tue Aug  2
>> > 16:07:23 2016
>> > @@ -5160,6 +5160,21 @@ void test3() {
>> >  }  // end namespace  GlobalAcquiredBeforeAfterTest
>> >
>> >
>> > +namespace LifetimeExtensionText {
>> > +
>> > +struct Holder {
>> > +  virtual ~Holder() throw() {}
>> > +  int i = 0;
>> > +};
>> > +
>> > +void test() {
>> > +  // Should not crash.
>> > +  const auto &value = Holder().i;
>> > +}
>> > +
>> > +} // end namespace LifetimeExtensionTest
>> > +
>> > +
>> >  namespace LockableUnions {
>> >
>> >  union LOCKABLE MutexUnion {
>> >
>> >
>> > ___
>> > 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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-11 Thread Yaxun Liu via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added a comment.

In https://reviews.llvm.org/D23361#512729, @Anastasia wrote:

> I think Clang is supposed to generate the IR specific to the target 
> architecture. It seems strange to ignore the pointer size. I am not sure if 
> it might lead to some issues for the backends.


This change only affects AMDGCN target which has different pointer size for 
different address spaces. There is no change for other targets.

For AMDGCN target, since there can be only one definition for size_t type, it 
has to be 64 bit to accommodate all pointers.

For operations not involving pointers, this is fine since it does not matter 
whether size_t is i32 or i64.

For operations involving pointers, it only affects ptrtoint instruction, which 
allows a pointer to be casted to any integer. If the integer size is larger 
than the pointer size, it is zero extended. If the integer is smaller than the 
pointer size, it is truncated.

When clang casts a pointer to size_t, there are two cases:

1. non-private pointers: before this change, it was casted to i32, which is 
wrong. now it is casted to i64 correctly.

2. private pointer: before this change, it was casted to i32, now it is casted 
to i64. It is still correct. Backend should be able to optimize these 
instructions.


https://reviews.llvm.org/D23361



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


Re: [PATCH] D22515: [analyzer] Added custom hashing to the CloneDetector.

2016-08-11 Thread Raphael Isemann via cfe-commits
teemperor retitled this revision from "Added false-positive filter for 
unintended hash code collisions to the CloneDetector." to "[analyzer] Added 
custom hashing to the CloneDetector.".
teemperor updated the summary for this revision.
teemperor updated this revision to Diff 67715.
teemperor added a comment.

- Fixed some formatting problems.
- Updated Title/Summary


https://reviews.llvm.org/D22515

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  lib/StaticAnalyzer/Checkers/CloneChecker.cpp

Index: lib/StaticAnalyzer/Checkers/CloneChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CloneChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CloneChecker.cpp
@@ -51,15 +51,6 @@
  "Related code clone is here.");
 
 for (CloneDetector::CloneGroup &Group : CloneGroups) {
-  // For readability reasons we sort the clones by line numbers.
-  std::sort(Group.Sequences.begin(), Group.Sequences.end(),
-[&SM](const StmtSequence &LHS, const StmtSequence &RHS) {
-  return SM.isBeforeInTranslationUnit(LHS.getStartLoc(),
-  RHS.getStartLoc()) &&
- SM.isBeforeInTranslationUnit(LHS.getEndLoc(),
-  RHS.getEndLoc());
-});
-
   // We group the clones by printing the first as a warning and all others
   // as a note.
   DiagEngine.Report(Group.Sequences.front().getStartLoc(), WarnID);
Index: lib/Analysis/CloneDetection.cpp
===
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -243,46 +243,35 @@
 /// This class defines what a code clone is: If it collects for two statements
 /// the same data, then those two statements are considered to be clones of each
 /// other.
-class StmtDataCollector : public ConstStmtVisitor {
+///
+/// All collected data is forwarded to the given data consumer of the type T.
+/// The data consumer class needs to provide a member method with the signature:
+///   write(const char *Data, size_t Size)
+template 
+class StmtDataCollector : public ConstStmtVisitor> {
 
   ASTContext &Context;
-  std::vector &CollectedData;
+  /// \brief The data sink to which all data is forwarded.
+  T &DataConsumer;
 
 public:
   /// \brief Collects data of the given Stmt.
   /// \param S The given statement.
   /// \param Context The ASTContext of S.
-  /// \param D The given data vector to which all collected data is appended.
-  StmtDataCollector(const Stmt *S, ASTContext &Context,
-std::vector &D)
-  : Context(Context), CollectedData(D) {
-Visit(S);
+  /// \param D The data sink to which all data is forwarded.
+  StmtDataCollector(const Stmt *S, ASTContext &Context, T &DataConsumer)
+  : Context(Context), DataConsumer(DataConsumer) {
+this->Visit(S);
   }
 
   // Below are utility methods for appending different data to the vector.
 
   void addData(CloneDetector::DataPiece Integer) {
-CollectedData.push_back(Integer);
+DataConsumer.write(reinterpret_cast(&Integer), sizeof(Integer));
   }
 
-  // FIXME: The functions below add long strings to the data vector which are
-  // probably not good for performance. Replace the strings with pointer values
-  // or a some other unique integer.
-
   void addData(llvm::StringRef Str) {
-if (Str.empty())
-  return;
-
-const size_t OldSize = CollectedData.size();
-
-const size_t PieceSize = sizeof(CloneDetector::DataPiece);
-// Calculate how many vector units we need to accomodate all string bytes.
-size_t RoundedUpPieceNumber = (Str.size() + PieceSize - 1) / PieceSize;
-// Allocate space for the string in the data vector.
-CollectedData.resize(CollectedData.size() + RoundedUpPieceNumber);
-
-// Copy the string to the allocated space at the end of the vector.
-std::memcpy(CollectedData.data() + OldSize, Str.data(), Str.size());
+DataConsumer.write(Str.data(), Str.size());
   }
 
   void addData(const QualType &QT) { addData(QT.getAsString()); }
@@ -426,8 +415,10 @@
 // Create an empty signature that will be filled in this method.
 CloneDetector::CloneSignature Signature;
 
+llvm::hash_stream Hash;
+
 // Collect all relevant data from S and put it into the empty signature.
-StmtDataCollector(S, Context, Signature.Data);
+StmtDataCollector(S, Context, Hash);
 
 // If this code is generated by a macro, it won't increase the complexity
 // level of it's containing clone. This prevents false-positives caused by
@@ -457,7 +448,8 @@
   auto ChildSignature = generateSignatures(Child);
 
   // Add the collected data to the signature of the current statement.
-  Signature.add(ChildSignature);
+  Signature.Complexity += ChildSignature.Complex

Re: r276900 - [Sema] Teach getCurrentThisType to reconize lambda in in-class initializer

2016-08-11 Thread Hans Wennborg via cfe-commits
Merged in r278374.

Thanks,
Hans

On Thu, Aug 11, 2016 at 11:07 AM, Richard Smith  wrote:
> Yes, this should be merged. It's not quite right, but it's certainly better
> than what we had before.
>
> On Mon, Aug 8, 2016 at 1:34 PM, Hans Wennborg  wrote:
>>
>> Richard: ping?
>>
>> On Wed, Jul 27, 2016 at 4:46 PM, Hans Wennborg  wrote:
>> > Should this be merged to 3.9?
>> >
>> > Thanks,
>> > Hans
>> >
>> > On Wed, Jul 27, 2016 at 11:25 AM, Erik Pilkington via cfe-commits
>> >  wrote:
>> >> Author: epilk
>> >> Date: Wed Jul 27 13:25:10 2016
>> >> New Revision: 276900
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=276900&view=rev
>> >> Log:
>> >> [Sema] Teach getCurrentThisType to reconize lambda in in-class
>> >> initializer
>> >>
>> >> Fixes PR27994, a crash on valid.
>> >>
>> >> Differential revision: https://reviews.llvm.org/D21145
>> >>
>> >> Modified:
>> >> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> >> cfe/trunk/test/SemaCXX/lambda-expressions.cpp
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=276900&r1=276899&r2=276900&view=diff
>> >>
>> >> ==
>> >> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jul 27 13:25:10 2016
>> >> @@ -961,32 +961,26 @@ static QualType adjustCVQualifiersForCXX
>> >>  QualType Sema::getCurrentThisType() {
>> >>DeclContext *DC = getFunctionLevelDeclContext();
>> >>QualType ThisTy = CXXThisTypeOverride;
>> >> +
>> >>if (CXXMethodDecl *method = dyn_cast(DC)) {
>> >>  if (method && method->isInstance())
>> >>ThisTy = method->getThisType(Context);
>> >>}
>> >> -  if (ThisTy.isNull()) {
>> >> -if (isGenericLambdaCallOperatorSpecialization(CurContext) &&
>> >> -CurContext->getParent()->getParent()->isRecord()) {
>> >> -  // This is a generic lambda call operator that is being
>> >> instantiated
>> >> -  // within a default initializer - so use the enclosing class as
>> >> 'this'.
>> >> -  // There is no enclosing member function to retrieve the 'this'
>> >> pointer
>> >> -  // from.
>> >> -
>> >> -  // FIXME: This looks wrong. If we're in a lambda within a lambda
>> >> within a
>> >> -  // default member initializer, we need to recurse up more
>> >> parents to find
>> >> -  // the right context. Looks like we should be walking up to the
>> >> parent of
>> >> -  // the closure type, checking whether that is itself a lambda,
>> >> and if so,
>> >> -  // recursing, until we reach a class or a function that isn't a
>> >> lambda
>> >> -  // call operator. And we should accumulate the constness of
>> >> *this on the
>> >> -  // way.
>> >> -
>> >> -  QualType ClassTy = Context.getTypeDeclType(
>> >> -  cast(CurContext->getParent()->getParent()));
>> >> -  // There are no cv-qualifiers for 'this' within default
>> >> initializers,
>> >> -  // per [expr.prim.general]p4.
>> >> -  ThisTy = Context.getPointerType(ClassTy);
>> >> -}
>> >> +
>> >> +  if (ThisTy.isNull() && isLambdaCallOperator(CurContext) &&
>> >> +  !ActiveTemplateInstantiations.empty()) {
>> >> +
>> >> +assert(isa(DC) &&
>> >> +   "Trying to get 'this' type from static method?");
>> >> +
>> >> +// This is a lambda call operator that is being instantiated as a
>> >> default
>> >> +// initializer. DC must point to the enclosing class type, so we
>> >> can recover
>> >> +// the 'this' type from it.
>> >> +
>> >> +QualType ClassTy =
>> >> Context.getTypeDeclType(cast(DC));
>> >> +// There are no cv-qualifiers for 'this' within default
>> >> initializers,
>> >> +// per [expr.prim.general]p4.
>
>
> This is wrong in C++17 onwards: if *this is captured by value by a
> non-mutable lambda, it should become const-qualified.
>
>>
>> >> +ThisTy = Context.getPointerType(ClassTy);
>> >>}
>> >>
>> >>// If we are within a lambda's call operator, the cv-qualifiers of
>> >> 'this'
>> >>
>> >> Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
>> >> URL:
>> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=276900&r1=276899&r2=276900&view=diff
>> >>
>> >> ==
>> >> --- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
>> >> +++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Wed Jul 27 13:25:10
>> >> 2016
>> >> @@ -1,5 +1,4 @@
>> >> -// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only -verify
>> >> -fblocks %s
>> >> -// RUN: %clang_cc1 -std=c++1y -Wno-unused-value -fsyntax-only -verify
>> >> -fblocks %s
>> >> +// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify
>> >> -fblocks %s
>> >>
>> >>  namespace std { class type_info; };
>> >>
>> >> @@ -499,3 +498,30 @@ void foo() {
>> >>};
>> >>  }
>> >>  }
>> 

Re: [PATCH] D23322: [OpenCL] AMDGPU: Add extensions cl_amd_media_ops and cl_amd_media_ops2

2016-08-11 Thread Yaxun Liu via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D23322#512823, @Anastasia wrote:

> Ok, sure. Is the plan to refactor this bit in case we implement the generic 
> support later then?
>
> It seems fine, although I can't check much without any documentation. Is 
> there any reference available online?


Yes we will refactor it after the generic support is implemented.

The documentations are here:
https://www.khronos.org/registry/cl/extensions/amd/cl_amd_media_ops.txt
https://www.khronos.org/registry/cl/extensions/amd/cl_amd_media_ops2.txt


https://reviews.llvm.org/D23322



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


Re: [PATCH] D23322: [OpenCL] AMDGPU: Add extensions cl_amd_media_ops and cl_amd_media_ops2

2016-08-11 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

Ok, sure. Is the plan to refactor this bit in case we implement the generic 
support later then?

It seems fine, although I can't check much without any documentation. Is there 
any reference available online?


https://reviews.llvm.org/D23322



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


Re: r277522 - [CFG] Fix crash finding destructor of lifetime-extended temporary.

2016-08-11 Thread Richard Smith via cfe-commits
Well, the whole approach here is still wrong (per the FIXME in
CFGBuilder::addLocalScopeForVarDecl) but this at least makes it consistent.
Let's take this for 3.9 to at least stem the bleeding.

On Tue, Aug 9, 2016 at 11:57 AM, Hans Wennborg  wrote:

> For the record, this was for PR28666.
>
> Richard: what do you think about merging this to 3.9?
>
> On Tue, Aug 2, 2016 at 2:07 PM, Devin Coughlin via cfe-commits
>  wrote:
> > Author: dcoughlin
> > Date: Tue Aug  2 16:07:23 2016
> > New Revision: 277522
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=277522&view=rev
> > Log:
> > [CFG] Fix crash finding destructor of lifetime-extended temporary.
> >
> > Fix a crash under -Wthread-safety when finding the destructor for a
> > lifetime-extending reference.
> >
> > A patch by Nandor Licker!
> >
> > Differential Revision: https://reviews.llvm.org/D22419
> >
> > Modified:
> > cfe/trunk/lib/Analysis/CFG.cpp
> > cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
> >
> > Modified: cfe/trunk/lib/Analysis/CFG.cpp
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> Analysis/CFG.cpp?rev=277522&r1=277521&r2=277522&view=diff
> > 
> ==
> > --- cfe/trunk/lib/Analysis/CFG.cpp (original)
> > +++ cfe/trunk/lib/Analysis/CFG.cpp Tue Aug  2 16:07:23 2016
> > @@ -3902,7 +3902,17 @@ CFGImplicitDtor::getDestructorDecl(ASTCo
> >  case CFGElement::AutomaticObjectDtor: {
> >const VarDecl *var = castAs().getVarDecl();
> >QualType ty = var->getType();
> > -  ty = ty.getNonReferenceType();
> > +
> > +  // FIXME: See CFGBuilder::addLocalScopeForVarDecl.
> > +  //
> > +  // Lifetime-extending constructs are handled here. This works for
> a single
> > +  // temporary in an initializer expression.
> > +  if (ty->isReferenceType()) {
> > +if (const Expr *Init = var->getInit()) {
> > +  ty = getReferenceInitTemporaryType(astContext, Init);
> > +}
> > +  }
> > +
> >while (const ArrayType *arrayType =
> astContext.getAsArrayType(ty)) {
> >  ty = arrayType->getElementType();
> >}
> >
> > Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/warn-thread-safety-analysis.cpp?rev=277522&r1=
> 277521&r2=277522&view=diff
> > 
> ==
> > --- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
> > +++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Tue Aug  2
> 16:07:23 2016
> > @@ -5160,6 +5160,21 @@ void test3() {
> >  }  // end namespace  GlobalAcquiredBeforeAfterTest
> >
> >
> > +namespace LifetimeExtensionText {
> > +
> > +struct Holder {
> > +  virtual ~Holder() throw() {}
> > +  int i = 0;
> > +};
> > +
> > +void test() {
> > +  // Should not crash.
> > +  const auto &value = Holder().i;
> > +}
> > +
> > +} // end namespace LifetimeExtensionTest
> > +
> > +
> >  namespace LockableUnions {
> >
> >  union LOCKABLE MutexUnion {
> >
> >
> > ___
> > 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


Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Zachary Turner via cfe-commits
zturner added a comment.

In https://reviews.llvm.org/D23409#512745, @zturner wrote:

> In https://reviews.llvm.org/D23409#512720, @aaron.ballman wrote:
>
> > Patch generally LGTM, though I wonder if there's a way we can add test 
> > coverage for this.
>
>
> I'd imagine we can just enable the clang-tidy test suite on Windows (I'm 
> assuming it's currently disabled).  I'll look into it.


Actually yea I'm not sure how to go about doing this.  All the existing tests 
are written to use GCC style command line, and it seems unreasonable to add a 
cl style command line variant of every single test.  maybe alexfh@ or someone 
has a suggestion.


https://reviews.llvm.org/D23409



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


Re: r276900 - [Sema] Teach getCurrentThisType to reconize lambda in in-class initializer

2016-08-11 Thread Richard Smith via cfe-commits
Yes, this should be merged. It's not quite right, but it's certainly better
than what we had before.

On Mon, Aug 8, 2016 at 1:34 PM, Hans Wennborg  wrote:

> Richard: ping?
>
> On Wed, Jul 27, 2016 at 4:46 PM, Hans Wennborg  wrote:
> > Should this be merged to 3.9?
> >
> > Thanks,
> > Hans
> >
> > On Wed, Jul 27, 2016 at 11:25 AM, Erik Pilkington via cfe-commits
> >  wrote:
> >> Author: epilk
> >> Date: Wed Jul 27 13:25:10 2016
> >> New Revision: 276900
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=276900&view=rev
> >> Log:
> >> [Sema] Teach getCurrentThisType to reconize lambda in in-class
> initializer
> >>
> >> Fixes PR27994, a crash on valid.
> >>
> >> Differential revision: https://reviews.llvm.org/D21145
> >>
> >> Modified:
> >> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> >> cfe/trunk/test/SemaCXX/lambda-expressions.cpp
> >>
> >> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaExprCXX.cpp?rev=276900&r1=276899&r2=276900&view=diff
> >> 
> ==
> >> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> >> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jul 27 13:25:10 2016
> >> @@ -961,32 +961,26 @@ static QualType adjustCVQualifiersForCXX
> >>  QualType Sema::getCurrentThisType() {
> >>DeclContext *DC = getFunctionLevelDeclContext();
> >>QualType ThisTy = CXXThisTypeOverride;
> >> +
> >>if (CXXMethodDecl *method = dyn_cast(DC)) {
> >>  if (method && method->isInstance())
> >>ThisTy = method->getThisType(Context);
> >>}
> >> -  if (ThisTy.isNull()) {
> >> -if (isGenericLambdaCallOperatorSpecialization(CurContext) &&
> >> -CurContext->getParent()->getParent()->isRecord()) {
> >> -  // This is a generic lambda call operator that is being
> instantiated
> >> -  // within a default initializer - so use the enclosing class as
> 'this'.
> >> -  // There is no enclosing member function to retrieve the 'this'
> pointer
> >> -  // from.
> >> -
> >> -  // FIXME: This looks wrong. If we're in a lambda within a lambda
> within a
> >> -  // default member initializer, we need to recurse up more
> parents to find
> >> -  // the right context. Looks like we should be walking up to the
> parent of
> >> -  // the closure type, checking whether that is itself a lambda,
> and if so,
> >> -  // recursing, until we reach a class or a function that isn't a
> lambda
> >> -  // call operator. And we should accumulate the constness of
> *this on the
> >> -  // way.
> >> -
> >> -  QualType ClassTy = Context.getTypeDeclType(
> >> -  cast(CurContext->getParent()->getParent()));
> >> -  // There are no cv-qualifiers for 'this' within default
> initializers,
> >> -  // per [expr.prim.general]p4.
> >> -  ThisTy = Context.getPointerType(ClassTy);
> >> -}
> >> +
> >> +  if (ThisTy.isNull() && isLambdaCallOperator(CurContext) &&
> >> +  !ActiveTemplateInstantiations.empty()) {
> >> +
> >> +assert(isa(DC) &&
> >> +   "Trying to get 'this' type from static method?");
> >> +
> >> +// This is a lambda call operator that is being instantiated as a
> default
> >> +// initializer. DC must point to the enclosing class type, so we
> can recover
> >> +// the 'this' type from it.
> >> +
> >> +QualType ClassTy = Context.getTypeDeclType(cast<
> CXXRecordDecl>(DC));
> >> +// There are no cv-qualifiers for 'this' within default
> initializers,
> >> +// per [expr.prim.general]p4.
>

This is wrong in C++17 onwards: if *this is captured by value by a
non-mutable lambda, it should become const-qualified.


> >> +ThisTy = Context.getPointerType(ClassTy);
> >>}
> >>
> >>// If we are within a lambda's call operator, the cv-qualifiers of
> 'this'
> >>
> >> Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
> >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/lambda-expressions.cpp?rev=276900&r1=276899&r2=276900&view=diff
> >> 
> ==
> >> --- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
> >> +++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Wed Jul 27 13:25:10
> 2016
> >> @@ -1,5 +1,4 @@
> >> -// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only -verify
> -fblocks %s
> >> -// RUN: %clang_cc1 -std=c++1y -Wno-unused-value -fsyntax-only -verify
> -fblocks %s
> >> +// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify
> -fblocks %s
> >>
> >>  namespace std { class type_info; };
> >>
> >> @@ -499,3 +498,30 @@ void foo() {
> >>};
> >>  }
> >>  }
> >> +
> >> +namespace PR27994 {
> >> +struct A { template  A(T); };
> >> +
> >> +template 
> >> +struct B {
> >> +  int x;
> >> +  A a = [&] { int y = x; };
> >> +  A b = [&] { [&] { [&] { int y = x; }; }; };
> >> +  A d = [&](auto param) { int y = x; };
> >> +  A e = [&](auto para

Re: [PATCH] D23387: [Analyzer] Report found fields order in PaddingChecker.

2016-08-11 Thread Alexander Shaposhnikov via cfe-commits
alexshap added a comment.

Thanks, your points regarding better formatting of the diagnostics / moving it 
into a note or fixit  and using more stable sort 
are valid, i will update this diff today or tomorrow. Regarding the type name - 
i am not sure - for example for template specializations
(for instance think about the standard containers) the full name of the type 
might be really long - not sure if it's really useful to print it here.


https://reviews.llvm.org/D23387



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


Re: [PATCH] D23322: [OpenCL] AMDGPU: Add extensions cl_amd_media_ops and cl_amd_media_ops2

2016-08-11 Thread Yaxun Liu via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D23322#512732, @Anastasia wrote:

> Is this related to our discussion on cfe-dev about the extensions and also 
> the earlier review you have created: https://reviews.llvm.org/D21698?


Since that feature takes time to implement, we decide to add our extensions to 
Clang directly first.


https://reviews.llvm.org/D23322



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


Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Zachary Turner via cfe-commits
zturner added inline comments.


Comment at: lib/Driver/Driver.cpp:93
@@ +92,3 @@
+ ArrayRef Args) {
+  auto Default = ToolChain::getTargetAndModeFromProgramName(ProgramName);
+  StringRef DefaultMode(Default.second);

rnk wrote:
> Why not change ToolInvocation::run() to behave more like clang's main? I'd 
> rather not do this twice, mostly for consistency with the regular driver, not 
> because it's inefficient.
I am very inexperienced with clang's driver model, but it seems to me like 
putting it here is actually the *correct* way, and what clang is doing is sort 
of a hackish workaround for the fact that it needs to parse response files the 
way it does.

If someone else comes along and builds another tool based off of clang, we 
don't want them to have to remember to do all this every single time.  Seems 
like the Driver should "just work", and if a particular tool (such as clang) 
needs to do something funky, that's on the tool.

Thoughts?


https://reviews.llvm.org/D23409



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


Re: [PATCH] D23167: emit_DW_AT_noreturn flag

2016-08-11 Thread Adrian Prantl via cfe-commits
aprantl added a comment.

You are adding a new constant to the LLVM IR, so there should be a round-trip 
test that tests the LLVM IR parser, bitcode writer, bitcode reader, and LLVM IR 
printer to make sure we're handling the new constant correctly.

One easy way to do this is by adding the new flag to the already existing test 
in test/IR/disubprogram.ll.


https://reviews.llvm.org/D23167



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


Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Zachary Turner via cfe-commits
zturner added inline comments.


Comment at: lib/Tooling/JSONCompilationDatabase.cpp:119
@@ -115,1 +118,3 @@
 StringRef EscapedCommandLine) {
+#if defined(LLVM_ON_WIN32)
+  llvm::BumpPtrAllocator Alloc;

rnk wrote:
> It would be nice if the JSON file just told us which quoting mechanism it was 
> using. You can imagine building the compilation database on one system and 
> sending it off to another for indexing.
Correct me if I've got this wrong but:

1. If you had a compile command database generated on non-Windows, and you used 
it on Windows, then it would necessarily be referring to something other than 
clang-cl right?  In which case, we don't support running clang in non-cl mode 
on Windows.

2. If you had a compile command database generated on Windows, then the only 
supported configuration would involve clang-cl, in which case you couldn't use 
it on non-Windows.

Is there a supported use case where a non-Windows compile database would be 
used on Windows or vice versa?


https://reviews.llvm.org/D23409



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


Re: [PATCH] D23168: emit_DW_AT_noreturn flag

2016-08-11 Thread Adrian Prantl via cfe-commits
aprantl added inline comments.


Comment at: test/Frontend/dinoreturn.c:2
@@ +1,3 @@
+// RUN: %clang %s -c -std=c11 -emit-llvm -S -g -o - | FileCheck %s
+// CHECK: DIFlagNoReturn 
+#include 

Please check for more context. For example:
  CHECK: !DISubprogram({{.*}}name: "f"{{.*}}flags: DIFlagNoreturn
would be good here.


https://reviews.llvm.org/D23168



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


Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Zachary Turner via cfe-commits
zturner added a comment.

In https://reviews.llvm.org/D23409#512720, @aaron.ballman wrote:

> Patch generally LGTM, though I wonder if there's a way we can add test 
> coverage for this.


I'd imagine we can just enable the clang-tidy test suite on Windows (I'm 
assuming it's currently disabled).  I'll look into it.


https://reviews.llvm.org/D23409



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


Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Reid Kleckner via cfe-commits
rnk added inline comments.


Comment at: lib/Driver/Driver.cpp:93
@@ +92,3 @@
+ ArrayRef Args) {
+  auto Default = ToolChain::getTargetAndModeFromProgramName(ProgramName);
+  StringRef DefaultMode(Default.second);

Why not change ToolInvocation::run() to behave more like clang's main? I'd 
rather not do this twice, mostly for consistency with the regular driver, not 
because it's inefficient.


Comment at: lib/Tooling/JSONCompilationDatabase.cpp:119
@@ -115,1 +118,3 @@
 StringRef EscapedCommandLine) {
+#if defined(LLVM_ON_WIN32)
+  llvm::BumpPtrAllocator Alloc;

It would be nice if the JSON file just told us which quoting mechanism it was 
using. You can imagine building the compilation database on one system and 
sending it off to another for indexing.


Comment at: lib/Tooling/JSONCompilationDatabase.cpp:127
@@ -116,2 +126,3 @@
+#else
   CommandLineArgumentParser parser(EscapedCommandLine);
   return parser.parse();

I bet we could replace this with TokenizeGNUCommandLine some other day.


https://reviews.llvm.org/D23409



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


Re: [PATCH] D23322: [OpenCL] AMDGPU: Add extensions cl_amd_media_ops and cl_amd_media_ops2

2016-08-11 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

Is this related to our discussion on cfe-dev about the extensions and also the 
earlier review you have created: https://reviews.llvm.org/D21698?


https://reviews.llvm.org/D23322



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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-11 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

I think Clang is supposed to generate the IR specific to the target 
architecture. It seems strange to ignore the pointer size. I am not sure if it 
might lead to some issues for the backends.



Comment at: lib/CodeGen/CodeGenModule.cpp:107
@@ -106,2 +106,3 @@
   IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
-  IntPtrTy = llvm::IntegerType::get(LLVMContext, PointerWidthInBits);
+  IntPtrTy = llvm::IntegerType::get(LLVMContext, LangOpts.OpenCL ?
+  C.getTargetInfo().getOpenCLMaxPointerWidth() : PointerWidthInBits);

It seems wrong to call OpenCL specific function in generic code path?


https://reviews.llvm.org/D23361



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


Re: [PATCH] D23409: Make clang-tidy work with clang-cl

2016-08-11 Thread Aaron Ballman via cfe-commits
aaron.ballman added a subscriber: aaron.ballman.
aaron.ballman added a comment.

Patch generally LGTM, though I wonder if there's a way we can add test coverage 
for this.


https://reviews.llvm.org/D23409



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


  1   2   >