[PATCH] D23657: Remove some false positives when taking the address of packed members

2016-10-21 Thread Roger Ferrer Ibanez via cfe-commits
rogfer01 updated this revision to Diff 75395.
rogfer01 added a comment.

Mark comment as TODO


https://reviews.llvm.org/D23657

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaChecking.cpp
  test/Sema/address-packed.c

Index: test/Sema/address-packed.c
===
--- test/Sema/address-packed.c
+++ test/Sema/address-packed.c
@@ -26,6 +26,7 @@
 struct Arguable *get_arguable();
 
 void to_void(void *);
+void to_intptr(intptr_t);
 
 void g0(void) {
   {
@@ -41,43 +42,48 @@
 
 f1((int *)(void *)&arguable.x); // no-warning
 to_void(&arguable.x);   // no-warning
-void *p = &arguable.x;  // no-warning;
+void *p = &arguable.x;  // no-warning
 to_void(p);
+to_intptr((intptr_t)p); // no-warning
   }
   {
 union UnionArguable arguable;
 f2(&arguable.c); // no-warning
 f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'UnionArguable'}}
 
-f1((int *)(void *)&arguable.x); // no-warning
-to_void(&arguable.x);   // no-warning
+f1((int *)(void *)&arguable.x);   // no-warning
+to_void(&arguable.x); // no-warning
+to_intptr((intptr_t)&arguable.x); // no-warning
   }
   {
 ArguableT arguable;
 f2(&arguable.c0); // no-warning
 f1(&arguable.x);  // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
 f2(&arguable.c1); // no-warning
 
-f1((int *)(void *)&arguable.x); // no-warning
-to_void(&arguable.x);   // no-warning
+f1((int *)(void *)&arguable.x);   // no-warning
+to_void(&arguable.x); // no-warning
+to_intptr((intptr_t)&arguable.x); // no-warning
   }
   {
 struct Arguable *arguable = get_arguable();
 f2(&arguable->c0); // no-warning
 f1(&arguable->x);  // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
 f2(&arguable->c1); // no-warning
 
-f1((int *)(void *)&arguable->x); // no-warning
-to_void(&arguable->c1);  // no-warning
+f1((int *)(void *)&arguable->x);// no-warning
+to_void(&arguable->c1); // no-warning
+to_intptr((intptr_t)&arguable->c1); // no-warning
   }
   {
 ArguableT *arguable = get_arguable();
 f2(&(arguable->c0)); // no-warning
 f1(&(arguable->x));  // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
 f2(&(arguable->c1)); // no-warning
 
-f1((int *)(void *)&(arguable->x)); // no-warning
-to_void(&(arguable->c1));  // no-warning
+f1((int *)(void *)&(arguable->x));  // no-warning
+to_void(&(arguable->c1));   // no-warning
+to_intptr((intptr_t)&(arguable->c1));   // no-warning
   }
 }
 
@@ -161,3 +167,130 @@
 {
 return (struct AlignedTo2Bis*)&s->x; // no-warning
 }
+
+struct S6 {
+int a;
+int _;
+int c;
+char __;
+int d;
+} __attribute__((packed, aligned(16))) s6;
+
+void g8()
+{ 
+f1(&s6.a); // no-warning
+f1(&s6.c); // no-warning
+f1(&s6.d); // expected-warning {{packed member 'd' of class or structure 'S6'}}
+}
+
+struct __attribute__((packed, aligned(1))) MisalignedContainee { double d; };
+struct __attribute__((aligned(8))) AlignedContainer { struct MisalignedContainee b; };
+
+struct AlignedContainer *p;
+double* g9() {
+  return &p->b.d; // no-warning
+}
+
+union OneUnion
+{
+uint32_t a;
+uint32_t b:1;
+};
+
+struct __attribute__((packed)) S7 {
+uint8_t length;
+uint8_t stuff;
+uint8_t padding[2];
+union OneUnion one_union;
+};
+
+union AnotherUnion {
+long data;
+struct S7 s;
+} *au;
+
+union OneUnion* get_OneUnion(void)
+{
+return &au->s.one_union; // no-warning
+}
+
+struct __attribute__((packed)) S8 {
+uint8_t data1;
+uint8_t data2;
+	uint16_t wider_data;
+};
+
+#define LE_READ_2(p)	\
+	((uint16_t)	\
+	 const uint8_t *)(p))[0]  ) |		\
+	  (((const uint8_t *)(p))[1] <<  8)))
+
+uint32_t get_wider_data(struct S8 *s)
+{
+return LE_READ_2(&s->wider_data); // no-warning
+}
+
+struct S9 {
+  uint32_t x;
+  uint8_t y[2];
+  uint16_t z;
+} __attribute__((__packed__));
+
+typedef struct S9 __attribute__((__aligned__(16))) aligned_S9;
+
+void g10() {
+  struct S9 x;
+  struct S9 __attribute__((__aligned__(8))) y;
+  aligned_S9 z;
+
+  uint32_t *p32;
+  p32 = &x.x; // expected-warning {{packed member 'x' of class or structure 'S9'}}
+  p32 = &y.x; // no-warning
+  p32 = &z.x; // no-warning
+}
+
+typedef struct {
+  uint32_t msgh_bits;
+  uint32_t msgh_size;
+  int32_t msgh_voucher_port;
+  int32_t msgh_id;
+} S10Header;
+
+typedef struct {
+  uint32_t t;
+  uint64_t m;
+  uint32_t p;
+  union {
+struct {
+  uint32_t a;
+  double z;
+} __attribute__((aligned(8), packed)) a;
+struct {
+  uint32_t b;
+  double z;
+  uint32_t a;
+} __attribute__((aligned(8), packed)) b;
+  };
+} __attribute__((aligned(8), packed)) S10Data;
+
+typedef struct {
+  S10Hea

r284811 - Revert "DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' rules."

2016-10-21 Thread Renato Golin via cfe-commits
Author: rengolin
Date: Fri Oct 21 03:03:49 2016
New Revision: 284811

URL: http://llvm.org/viewvc/llvm-project?rev=284811&view=rev
Log:
Revert "DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' 
rules."

This reverts commit r284800, as it failed all ARM/AArch64 bots.

Removed:
cfe/trunk/test/CXX/over/over.built/p15.cpp
cfe/trunk/test/CXX/over/over.built/p16.cpp
cfe/trunk/test/SemaCXX/libstdcxx_libcxx_less_hack.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CXX/drs/dr15xx.cpp
cfe/trunk/test/CXX/drs/dr5xx.cpp
cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp
cfe/trunk/test/Misc/warning-flags.c
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/distribute_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/target_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/taskloop_simd_aligned_messages.cpp
cfe/trunk/test/SemaCXX/compare.cpp
cfe/trunk/test/SemaCXX/composite-pointer-type.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
cfe/trunk/test/SemaCXX/null_in_arithmetic_ops.cpp
cfe/trunk/test/SemaCXX/nullptr.cpp
cfe/trunk/test/SemaCXX/nullptr_in_arithmetic_ops.cpp
cfe/trunk/test/SemaCXX/warn-memsize-comparison.cpp
cfe/trunk/test/SemaObjCXX/null_objc_pointer.mm
cfe/trunk/www/cxx_dr_status.html

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=284811&r1=284810&r2=284811&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Oct 21 03:03:49 
2016
@@ -5536,8 +5536,6 @@ def ext_typecheck_ordered_comparison_of_
   "ordered comparison between pointer and integer (%0 and %1)">;
 def ext_typecheck_ordered_comparison_of_pointer_and_zero : Extension<
   "ordered comparison between pointer and zero (%0 and %1) is an extension">;
-def err_typecheck_ordered_comparison_of_pointer_and_zero : Error<
-  "ordered comparison between pointer and zero (%0 and %1)">;
 def ext_typecheck_ordered_comparison_of_function_pointers : ExtWarn<
   "ordered comparison of function pointers (%0 and %1)">;
 def ext_typecheck_comparison_of_fptr_to_void : Extension<
@@ -5558,6 +5556,9 @@ def err_cond_voidptr_arc : Error <
   "in ARC mode">;
 def err_typecheck_comparison_of_distinct_pointers : Error<
   "comparison of distinct pointer types%diff{ ($ and $)|}0,1">;
+def ext_typecheck_comparison_of_distinct_pointers_nonstandard : ExtWarn<
+  "comparison of distinct pointer types (%0 and %1) uses non-standard "
+  "composite pointer type %2">, InGroup;
 def err_typecheck_op_on_nonoverlapping_address_space_pointers : Error<
   "%select{comparison between %diff{ ($ and $)|}0,1"
   "|arithmetic operation with operands of type %diff{ ($ and $)|}0,1"
@@ -6836,6 +6837,9 @@ def err_typecheck_expect_scalar_operand
   "operand of type %0 where arithmetic or pointer type is required">;
 def err_typecheck_cond_incompatible_operands : Error<
   "incompatible operand types%diff{ ($ and $)|}0,1">;
+def ext_typecheck_cond_incompatible_operands_nonstandard : ExtWarn<
+  "incompatible operand types%diff{ ($ and $)|}0,1 use non-standard composite "
+  "pointer type %2">;
 def err_cast_selector_expr : Error<
   "cannot type cast @selector expression">;
 def ext_typecheck_cond_incompatible_pointers : ExtWarn<

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=284811&r1=284810&r2=284811&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Oct 21 03:03:49 2016
@@ -8954,13 +8954,15 @@ public:
 ExprResult &cond, ExprResult &lhs, ExprResult &rhs,
 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
   QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
+bool *NonStandardCompositeType = nullptr,
 bool ConvertArgs = true);
   QualType FindCompositePointerType(SourceLocation Loc,
 ExprResult &E1, ExprResult &E2,
+bool *NonStandardCompositeType = nullptr,
 bool ConvertArgs = true) {
 Expr *E1Tmp = E1.get(), *E2Tmp

Re: r284800 - DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' rules.

2016-10-21 Thread Renato Golin via cfe-commits
On 21 October 2016 at 03:36, Richard Smith via cfe-commits
 wrote:
> Author: rsmith
> Date: Thu Oct 20 21:36:37 2016
> New Revision: 284800
>
> URL: http://llvm.org/viewvc/llvm-project?rev=284800&view=rev
> Log:
> DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' rules.

Hi Richard,

This failed all our bots:

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-42vma/builds/13274

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/11260

http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15/builds/16281

http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/15991

I've reverted in r284811.

Let me know if you need help testing.

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


[PATCH] D25866: [Sema] Support implicit scalar to vector conversions

2016-10-21 Thread Simon Dardis via cfe-commits
sdardis created this revision.
sdardis added subscribers: rnk, bruno, ahatanak, cfe-commits.
Herald added a reviewer: vkalintiris.

This patch teaches clang to perform implicit scalar to vector conversions
when one of the operands to a binary vector expression is a scalar like GCC.

The scalar is implicitly casted to the vector elements type and splatted to
produce a vector of the same type.


https://reviews.llvm.org/D25866

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/vector-cast.c
  test/Sema/vector-scalar-implict-conv.c
  test/Sema/zvector.c

Index: test/Sema/zvector.c
===
--- test/Sema/zvector.c
+++ test/Sema/zvector.c
@@ -326,14 +326,14 @@
   bc = bc + sc2; // expected-error {{incompatible type}}
   bc = sc + bc2; // expected-error {{incompatible type}}
 
-  sc = sc + sc_scalar; // expected-error {{cannot convert}}
-  sc = sc + uc_scalar; // expected-error {{cannot convert}}
-  sc = sc_scalar + sc; // expected-error {{cannot convert}}
-  sc = uc_scalar + sc; // expected-error {{cannot convert}}
-  uc = uc + sc_scalar; // expected-error {{cannot convert}}
-  uc = uc + uc_scalar; // expected-error {{cannot convert}}
-  uc = sc_scalar + uc; // expected-error {{cannot convert}}
-  uc = uc_scalar + uc; // expected-error {{cannot convert}}
+  sc = sc + sc_scalar;
+  sc = sc + uc_scalar; // expected-error {{implicit conversion changes signedness: 'unsigned char' to '__vector signed char' (vector of 16 'signed char' values)}}
+  sc = sc_scalar + sc;
+  sc = uc_scalar + sc; // expected-error {{implicit conversion changes signedness: 'unsigned char' to '__vector signed char' (vector of 16 'signed char' values)}}
+  uc = uc + sc_scalar; // expected-error {{implicit conversion changes signedness: 'signed char' to '__vector unsigned char' (vector of 16 'unsigned char' values)}}
+  uc = uc + uc_scalar;
+  uc = sc_scalar + uc; // expected-error {{implicit conversion changes signedness: 'signed char' to '__vector unsigned char' (vector of 16 'unsigned char' values)}}
+  uc = uc_scalar + uc;
 
   ss = ss + ss2;
   us = us + us2;
@@ -368,10 +368,10 @@
   sc += sl2; // expected-error {{cannot convert}}
   sc += fd2; // expected-error {{cannot convert}}
 
-  sc += sc_scalar; // expected-error {{cannot convert}}
-  sc += uc_scalar; // expected-error {{cannot convert}}
-  uc += sc_scalar; // expected-error {{cannot convert}}
-  uc += uc_scalar; // expected-error {{cannot convert}}
+  sc += sc_scalar;
+  sc += uc_scalar; // expected-error {{implicit conversion changes signedness: 'unsigned char' to '__vector signed char' (vector of 16 'signed char' values)}}
+  uc += sc_scalar; // expected-error {{implicit conversion changes signedness: 'signed char' to '__vector unsigned char' (vector of 16 'unsigned char' values)}}
+  uc += uc_scalar;
 
   ss += ss2;
   us += us2;
Index: test/Sema/vector-scalar-implict-conv.c
===
--- /dev/null
+++ test/Sema/vector-scalar-implict-conv.c
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Weverything
+
+typedef long long v2i64 __attribute__((vector_size(16)));
+typedef long long v2i64 __attribute__((vector_size(16)));
+
+typedef int v2i32 __attribute__((vector_size(8)));
+typedef int v2i32 __attribute__((vector_size(8)));
+
+typedef unsigned long long v2u64 __attribute__((vector_size(16)));
+typedef unsigned long long v2u64 __attribute__((vector_size(16)));
+
+typedef float v4f32 __attribute__((vector_size(16)));
+typedef double v4f64 __attribute__((vector_size(32)));
+
+void test (void);
+
+void test (void){
+
+  v2i64 v2i64_a = (v2i64) {0, 1};
+  v2i64 v2i64_r;
+
+  v2i32 v2i32_a = (v2i32) {0 , 1};
+
+  v2u64 v2u64_a = (v2u64) {0, 1};
+
+  v4f32 v4f32_a = (v4f32) {0.1f, 0.2f, 0.3f, 0.4f};
+
+  v4f64 v4f64_r = v4f32_a; // expected-error {{initializing 'v4f64' (vector of 4 'double' values) with an expression of incompatible type 'v4f32' (vector of 4 'float' values)}}
+
+  v4f64_r = v4f32_a;
+
+  // FIXME: this should warn about truncation.
+  v4f32_a = v4f64_r;
+
+  v2i64_r = v2i32_a; // expected-error {{assigning to 'v2i64' (vector of 2 'long long' values) from incompatible type 'v2i32' (vector of 2 'int' values)}}
+
+  v2i64_r = v2u64_a; // expected-warning {{incompatible vector types assigning to 'v2i64' (vector of 2 'long long' values) from 'v2u64' (vector of 2 'unsigned long long' values)}}
+
+  v2i64_r = v2i64_a + 1;
+  v2i64_r = v2i64_a - 1;
+  v2i64_r = v2i64_a * 1;
+  v2i64_r = v2i64_a / 1;
+  v2i64_r = v2i64_a % 1;
+
+  v2i64_a += 1;
+  v2i64_a -= 1;
+  v2i64_a *= 1;
+  v2i64_a /= 1;
+  v2i64_a %= 1;
+
+  v2i64_r = v2i64_a == 1; // expected-warning {{incompatible vector types assigning to 'v2i64' (vector of 2 'long long' values) from 'long __attribute__((ext_vector_type(2)))' (vector of 2 'long' values)}}
+  v2i64_r = v2i64_a != 1; // expected-warning {{incompatible vector types assigning to 'v2i64' (vector of 2 'long long' values) from 'long __

[PATCH] D25817: [Sema] Improve the error diagnostic for dot destructor calls on pointer objects

2016-10-21 Thread Alex Lorenz via cfe-commits
arphaman updated this revision to Diff 75403.
arphaman added a comment.

The updated patch improves error handling and adds a test for the fixit.

> If we issue a fixit we should recover as-if the code was written with the 
> fixit in. Does this code do that? (can we test it? I know we test some fixits 
> - not sure it's necessary/worthwhile to test them all, but maybe we have a 
> good idiom for testing that the recovery is correct)

This code does perform recovery, but the constructed AST for the destructor 
calls is different from the AST that would have been constructed if the code 
was correct: we still end up building the pseudo destructor expression. I'm not 
sure how important is that though, so please let me know if I should try and 
make the ASTs the same.


Repository:
  rL LLVM

https://reviews.llvm.org/D25817

Files:
  lib/Sema/SemaExprCXX.cpp
  test/CXX/special/class.dtor/p10-0x.cpp
  test/FixIt/fixit.cpp
  test/SemaCXX/pseudo-destructors.cpp

Index: test/SemaCXX/pseudo-destructors.cpp
===
--- test/SemaCXX/pseudo-destructors.cpp
+++ test/SemaCXX/pseudo-destructors.cpp
@@ -89,3 +89,26 @@
 void AliasTemplate(int *p) {
   p->~Id();
 }
+
+namespace dotPointerAccess {
+struct Base {
+  virtual ~Base() {}
+};
+
+struct Derived : Base {
+  ~Derived() {}
+};
+
+void test() {
+  Derived d;
+  static_cast(&d).~Base(); // expected-error {{member reference type 'dotPointerAccess::Base *' is a pointer; did you mean to use '->'}}
+  d->~Derived(); // expected-error {{member reference type 'dotPointerAccess::Derived' is not a pointer; did you mean to use '.'}}
+}
+
+typedef Derived *Foo;
+
+void test2(Foo d) {
+  d.~Foo(); // This is ok
+  d.~Derived(); // expected-error {{member reference type 'Foo' (aka 'dotPointerAccess::Derived *') is a pointer; did you mean to use '->'}}
+}
+}
Index: test/FixIt/fixit.cpp
===
--- test/FixIt/fixit.cpp
+++ test/FixIt/fixit.cpp
@@ -395,3 +395,14 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:26-[[@LINE-1]]:26}:"{}"
 int use_czi = czi.a;
 
+namespace dotPointerDestructor {
+
+struct Bar {
+  ~Bar();
+};
+
+void bar(Bar *o) {
+  o.~Bar(); // expected-error {{member reference type 'dotPointerAccess::Base *' is a pointer; did you mean to use '->'}}
+}  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:4-[[@LINE-1]]:5}:"->"
+
+}
Index: test/CXX/special/class.dtor/p10-0x.cpp
===
--- test/CXX/special/class.dtor/p10-0x.cpp
+++ test/CXX/special/class.dtor/p10-0x.cpp
@@ -33,7 +33,7 @@
  expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
   i.~decltype(intp())(); // expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
   pi->~decltype(int())();
-  pi.~decltype(int())(); // expected-error{{the type of object expression ('int *') does not match the type being destroyed ('decltype(int())' (aka 'int')) in pseudo-destructor expression}}
+  pi.~decltype(int())(); // expected-error{{member reference type 'int *' is a pointer; did you mean to use '->'?}}
   pi.~decltype(intp())();
   pi->~decltype(intp())(); // expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
 }
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -6275,15 +6275,31 @@
   = DestructedTypeInfo->getTypeLoc().getLocalSourceRange().getBegin();
 if (!DestructedType->isDependentType() && !ObjectType->isDependentType()) {
   if (!Context.hasSameUnqualifiedType(DestructedType, ObjectType)) {
-Diag(DestructedTypeStart, diag::err_pseudo_dtor_type_mismatch)
-  << ObjectType << DestructedType << Base->getSourceRange()
-  << DestructedTypeInfo->getTypeLoc().getLocalSourceRange();
-
-// Recover by setting the destructed type to the object type.
-DestructedType = ObjectType;
-DestructedTypeInfo = Context.getTrivialTypeSourceInfo(ObjectType,
-   DestructedTypeStart);
-Destructed = PseudoDestructorTypeStorage(DestructedTypeInfo);
+// Detect dot pseudo destructor calls on pointer objects, e.g.:
+//   Foo *foo;
+//   foo.~Foo();
+if (OpKind == tok::period && ObjectType->isPointerType() &&
+Context.hasSameUnqualifiedType(DestructedType,
+   ObjectType->getPointeeType())) {
+  Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
+  << ObjectType << /*IsArrow=*/0 << Base->getSour

[PATCH] D25816: Use descriptive message if list initializer is incorrectly parenthesized.

2016-10-21 Thread Serge Pavlov via cfe-commits
sepavloff updated this revision to Diff 75404.
sepavloff added a comment.

Addressed reviewr's notes.


https://reviews.llvm.org/D25816

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/cxx0x-initializer-references.cpp
  test/SemaCXX/cxx0x-initializer-scalars.cpp

Index: test/SemaCXX/cxx0x-initializer-scalars.cpp
===
--- test/SemaCXX/cxx0x-initializer-scalars.cpp
+++ test/SemaCXX/cxx0x-initializer-scalars.cpp
@@ -91,10 +91,23 @@
   }
 
   void edge_cases() {
-// FIXME: very poor error message
-int a({0}); // expected-error {{cannot initialize}}
-(void) int({0}); // expected-error {{functional-style cast}}
-new int({0});  // expected-error {{cannot initialize}}
+int a({0}); // expected-error {{list-initializer for non-class type 'int' must not be parenthesized}}
+(void) int({0}); // expected-error {{list-initializer for non-class type 'int' must not be parenthesized}}
+new int({0});  // expected-error {{list-initializer for non-class type 'int' must not be parenthesized}}
+
+int *b({0});  // expected-error {{list-initializer for non-class type 'int *' must not be parenthesized}}
+typedef int *intptr;
+int *c = intptr({0});  // expected-error {{list-initializer for non-class type 'intptr' (aka 'int *') must not be parenthesized}}
+  }
+
+  template void dependent_edge_cases() {
+T a({0});
+(void) T({0});
+new T({0});
+
+T *b({0});
+typedef T *tptr;
+T *c = tptr({0});
   }
 
   void default_argument(int i = {}) {
Index: test/SemaCXX/cxx0x-initializer-references.cpp
===
--- test/SemaCXX/cxx0x-initializer-references.cpp
+++ test/SemaCXX/cxx0x-initializer-references.cpp
@@ -72,10 +72,9 @@
   }
 
   void edge_cases() {
-// FIXME: very poor error message
-int const &b({0}); // expected-error {{could not bind}}
+int const &b({0}); // expected-error {{list-initializer for non-class type 'const int &' must not be parenthesized}}
+const int (&arr)[3] ({1, 2, 3}); // expected-error {{list-initializer for non-class type 'const int (&)[3]' must not be parenthesized}}
   }
-
 }
 
 namespace PR12182 {
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -1221,6 +1221,17 @@
   if (!TInfo)
 TInfo = Context.getTrivialTypeSourceInfo(Ty, SourceLocation());
 
+  // Handle errors like: int({0})
+  if (exprs.size() == 1 && !canInitializeWithParenthesizedList(Ty) &&
+  LParenLoc.isValid() && RParenLoc.isValid())
+if (auto IList = dyn_cast(exprs[0])) {
+  Diag(TInfo->getTypeLoc().getLocStart(), diag::err_list_init_in_parens)
+  << Ty << IList->getSourceRange()
+  << FixItHint::CreateRemoval(LParenLoc)
+  << FixItHint::CreateRemoval(RParenLoc);
+  LParenLoc = RParenLoc = SourceLocation();
+}
+
   auto Result = BuildCXXTypeConstructExpr(TInfo, LParenLoc, exprs, RParenLoc);
   // Avoid creating a non-type-dependent expression that contains typos.
   // Non-type-dependent expressions are liable to be discarded without
@@ -1562,8 +1573,20 @@
 return ExprError();
 
   SourceRange DirectInitRange;
-  if (ParenListExpr *List = dyn_cast_or_null(Initializer))
+  if (ParenListExpr *List = dyn_cast_or_null(Initializer)) {
 DirectInitRange = List->getSourceRange();
+// Handle errors like: new int a({0})
+if (List->getNumExprs() == 1 &&
+!canInitializeWithParenthesizedList(AllocType))
+  if (auto IList = dyn_cast(List->getExpr(0))) {
+Diag(TInfo->getTypeLoc().getLocStart(), diag::err_list_init_in_parens)
+<< AllocType << List->getSourceRange()
+<< FixItHint::CreateRemoval(List->getLocStart())
+<< FixItHint::CreateRemoval(List->getLocEnd());
+DirectInitRange = SourceRange();
+Initializer = IList;
+  }
+  }
 
   return BuildCXXNew(SourceRange(StartLoc, D.getLocEnd()), UseGlobal,
  PlacementLParen,
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -9786,6 +9786,18 @@
   // Perform the initialization.
   ParenListExpr *CXXDirectInit = dyn_cast(Init);
   if (!VDecl->isInvalidDecl()) {
+// Handle errors like: int a({0})
+if (CXXDirectInit && CXXDirectInit->getNumExprs() == 1 &&
+!canInitializeWithParenthesizedList(VDecl->getType()))
+  if (auto IList = dyn_cast(CXXDirectInit->getExpr(0))) {
+Diag(VDecl->getLocation(), diag::err_list_init_in_parens)
+<< VDecl->getType() << CXXDirectInit->getSourceRange()
+<< FixItHint::CreateRemoval(CXXDirectInit->getLocStart())
+<< FixItHint::CreateRemoval(CXXDirectInit->getLocEnd());
+

r284815 - Remove non-existing file from modulemap.

2016-10-21 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Fri Oct 21 05:19:37 2016
New Revision: 284815

URL: http://llvm.org/viewvc/llvm-project?rev=284815&view=rev
Log:
Remove non-existing file from modulemap.

This picked up a builtin header if it happened to be available.

Modified:

cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap

Modified: 
cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap?rev=284815&r1=284814&r2=284815&view=diff
==
--- 
cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap 
(original)
+++ 
cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap 
Fri Oct 21 05:19:37 2016
@@ -1,7 +1,6 @@
 module libc [no_undeclared_includes] {
   module math { header "math.h" export * }
   module stdlib { header "stdlib.h" export * }
-  module stdatomic { header "stdatomic.h" export * }
   module stddef { header "stddef.h" export * }
   module stdint { header "stdint.h" export * }
   module stdio { header "stdio.h" export * }


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


[PATCH] D25816: Use descriptive message if list initializer is incorrectly parenthesized.

2016-10-21 Thread Serge Pavlov via cfe-commits
sepavloff marked 5 inline comments as done.
sepavloff added inline comments.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:1762
 def err_init_incomplete_type : Error<"initialization of incomplete type %0">;
+def err_list_init_in_parens : Error<"list-initializer for non-class type "
+  "must not be parenthesized">;

arphaman wrote:
> Wouldn't it be better if we had a diagnostic with the type information? So, 
> instead of showing `list-initializer for non-class type must not be 
> parenthesized` clang would show `list-initializer for non-class type 'int' 
> must not be parenthesized`. What do you think?
> 
> As well as that, it seems that GCC issues a warning instead of an error for 
> this diagnostic, so should this be a warning in clang as well?
Putting type name into the diagnostic message is a good idea, implemented.

As for making this message a warning instead of an error, I am in doubt.
Pros:
- it enhances GCC compatibility,
- wrong code may be easily fixed by compiler,
Cons:
- this is a violation of the standard,
- this extension does not add any benefits,
- wrong code can be easily fixed by user.
I chose to retain current clang behavior and reject questionable code. GCC [[ 
https://gcc.gnu.org/ml/gcc-patches/2011-08/msg00644.html | patch]] that 
introduced this message explains using warning by some uncertainty, 5 years 
passed, I think the standard is stable in viewpoint on such usage.



Comment at: lib/Sema/SemaExprCXX.cpp:1229
+  Diag(TInfo->getTypeLoc().getLocStart(), diag::err_list_init_in_parens)
+  << IList->getSourceRange()
+  << FixItHint::CreateRemoval(LParenLoc)

arphaman wrote:
> Formatting issue: clang-format replaces
> 
> ```
>   << IList->getSourceRange()
>   << FixItHint::CreateRemoval(LParenLoc)
> ```
> with
> ```
>   << IList->getSourceRange() << FixItHint::CreateRemoval(LParenLoc)
> ```
After insertion of type `Ty` this is no more the case.


https://reviews.llvm.org/D25816



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


[PATCH] D25817: [Sema] Improve the error diagnostic for dot destructor calls on pointer objects

2016-10-21 Thread Alex Lorenz via cfe-commits
arphaman updated this revision to Diff 75405.
arphaman added a comment.

Fix a typo in the fixit test.


Repository:
  rL LLVM

https://reviews.llvm.org/D25817

Files:
  lib/Sema/SemaExprCXX.cpp
  test/CXX/special/class.dtor/p10-0x.cpp
  test/FixIt/fixit.cpp
  test/SemaCXX/pseudo-destructors.cpp

Index: test/SemaCXX/pseudo-destructors.cpp
===
--- test/SemaCXX/pseudo-destructors.cpp
+++ test/SemaCXX/pseudo-destructors.cpp
@@ -89,3 +89,26 @@
 void AliasTemplate(int *p) {
   p->~Id();
 }
+
+namespace dotPointerAccess {
+struct Base {
+  virtual ~Base() {}
+};
+
+struct Derived : Base {
+  ~Derived() {}
+};
+
+void test() {
+  Derived d;
+  static_cast(&d).~Base(); // expected-error {{member reference type 'dotPointerAccess::Base *' is a pointer; did you mean to use '->'}}
+  d->~Derived(); // expected-error {{member reference type 'dotPointerAccess::Derived' is not a pointer; did you mean to use '.'}}
+}
+
+typedef Derived *Foo;
+
+void test2(Foo d) {
+  d.~Foo(); // This is ok
+  d.~Derived(); // expected-error {{member reference type 'Foo' (aka 'dotPointerAccess::Derived *') is a pointer; did you mean to use '->'}}
+}
+}
Index: test/FixIt/fixit.cpp
===
--- test/FixIt/fixit.cpp
+++ test/FixIt/fixit.cpp
@@ -395,3 +395,14 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:26-[[@LINE-1]]:26}:"{}"
 int use_czi = czi.a;
 
+namespace dotPointerDestructor {
+
+struct Bar {
+  ~Bar();
+};
+
+void bar(Bar *o) {
+  o.~Bar(); // expected-error {{member reference type 'dotPointerDestructor::Bar *' is a pointer; did you mean to use '->'}}
+}  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:4-[[@LINE-1]]:5}:"->"
+
+}
Index: test/CXX/special/class.dtor/p10-0x.cpp
===
--- test/CXX/special/class.dtor/p10-0x.cpp
+++ test/CXX/special/class.dtor/p10-0x.cpp
@@ -33,7 +33,7 @@
  expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
   i.~decltype(intp())(); // expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
   pi->~decltype(int())();
-  pi.~decltype(int())(); // expected-error{{the type of object expression ('int *') does not match the type being destroyed ('decltype(int())' (aka 'int')) in pseudo-destructor expression}}
+  pi.~decltype(int())(); // expected-error{{member reference type 'int *' is a pointer; did you mean to use '->'?}}
   pi.~decltype(intp())();
   pi->~decltype(intp())(); // expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
 }
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -6275,15 +6275,31 @@
   = DestructedTypeInfo->getTypeLoc().getLocalSourceRange().getBegin();
 if (!DestructedType->isDependentType() && !ObjectType->isDependentType()) {
   if (!Context.hasSameUnqualifiedType(DestructedType, ObjectType)) {
-Diag(DestructedTypeStart, diag::err_pseudo_dtor_type_mismatch)
-  << ObjectType << DestructedType << Base->getSourceRange()
-  << DestructedTypeInfo->getTypeLoc().getLocalSourceRange();
-
-// Recover by setting the destructed type to the object type.
-DestructedType = ObjectType;
-DestructedTypeInfo = Context.getTrivialTypeSourceInfo(ObjectType,
-   DestructedTypeStart);
-Destructed = PseudoDestructorTypeStorage(DestructedTypeInfo);
+// Detect dot pseudo destructor calls on pointer objects, e.g.:
+//   Foo *foo;
+//   foo.~Foo();
+if (OpKind == tok::period && ObjectType->isPointerType() &&
+Context.hasSameUnqualifiedType(DestructedType,
+   ObjectType->getPointeeType())) {
+  Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
+  << ObjectType << /*IsArrow=*/0 << Base->getSourceRange()
+  << FixItHint::CreateReplacement(OpLoc, "->");
+
+  // Recover by setting the object type to the destructed type and the
+  // operator to '->'.
+  ObjectType = DestructedType;
+  OpKind = tok::arrow;
+} else {
+  Diag(DestructedTypeStart, diag::err_pseudo_dtor_type_mismatch)
+  << ObjectType << DestructedType << Base->getSourceRange()
+  << DestructedTypeInfo->getTypeLoc().getLocalSourceRange();
+
+  // Recover by setting the destructed type to the object type.
+  DestructedType = ObjectType;
+  DestructedTypeInfo =
+  Context.getTr

[PATCH] D25820: [Sema][Objective-C] Formatting warnings should see through Objective-C message sends

2016-10-21 Thread Alex Lorenz via cfe-commits
arphaman updated this revision to Diff 75408.
arphaman marked an inline comment as done.
arphaman added a comment.

The updated patch includes positive test cases.


Repository:
  rL LLVM

https://reviews.llvm.org/D25820

Files:
  lib/Sema/SemaChecking.cpp
  test/SemaObjC/format-strings-objc.m


Index: test/SemaObjC/format-strings-objc.m
===
--- test/SemaObjC/format-strings-objc.m
+++ test/SemaObjC/format-strings-objc.m
@@ -264,3 +264,41 @@
   NSLog(@"%2$[tt]@ %1$[tt]@", @"Foo", @"Bar"); // no-warning
   NSLog(@"%2$[tt]@ %1$[tt]s", @"Foo", @"Bar"); // expected-warning {{object 
format flags cannot be used with 's' conversion specifier}}
 }
+
+// rdar://23622446
+@interface RD23622446_Tester: NSObject
+
++ (void)stringWithFormat:(const char *)format, ... 
__attribute__((format(__printf__, 1, 2)));
+
+@end
+
+@implementation RD23622446_Tester
+
+__attribute__ ((format_arg(1)))
+const char *rd23622446(const char *format) {
+  return format;
+}
+
++ (void)stringWithFormat:(const char *)format, ... {
+  return;
+}
+
+- (const char *)test:(const char *)format __attribute__ ((format_arg(1))) {
+  return format;
+}
+
+- (NSString *)str:(NSString *)format __attribute__ ((format_arg(1))) {
+  return format;
+}
+
+- (void)foo {
+  [RD23622446_Tester stringWithFormat:rd23622446("%u"), 1, 2]; // 
expected-warning {{data argument not used by format string}}
+  [RD23622446_Tester stringWithFormat:[self test: "%u"], 1, 2]; // 
expected-warning {{data argument not used by format string}}
+  [RD23622446_Tester stringWithFormat:[self test: "%s %s"], "name"]; // 
expected-warning {{more '%' conversions than data arguments}}
+  NSLog([self str: @"%@ %@"], @"name"); // expected-warning {{more '%' 
conversions than data arguments}}
+  [RD23622446_Tester stringWithFormat:rd23622446("%d"), 1]; // ok
+  [RD23622446_Tester stringWithFormat:[self test: "%d %d"], 1, 2]; // ok
+  NSLog([self str: @"%@"], @"string"); // ok
+}
+
+@end
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -4481,6 +4481,20 @@
 
 return SLCT_NotALiteral;
   }
+  case Stmt::ObjCMessageExprClass: {
+const auto *ME = cast(E);
+if (const auto *ND = ME->getMethodDecl()) {
+  if (const auto *FA = ND->getAttr()) {
+unsigned ArgIndex = FA->getFormatIdx();
+const Expr *Arg = ME->getArg(ArgIndex - 1);
+return checkFormatStringExpr(
+S, Arg, Args, HasVAListArg, format_idx, firstDataArg, Type,
+CallType, InFunctionCall, CheckedVarArgs, UncoveredArg, Offset);
+  }
+}
+
+return SLCT_NotALiteral;
+  }
   case Stmt::ObjCStringLiteralClass:
   case Stmt::StringLiteralClass: {
 const StringLiteral *StrE = nullptr;


Index: test/SemaObjC/format-strings-objc.m
===
--- test/SemaObjC/format-strings-objc.m
+++ test/SemaObjC/format-strings-objc.m
@@ -264,3 +264,41 @@
   NSLog(@"%2$[tt]@ %1$[tt]@", @"Foo", @"Bar"); // no-warning
   NSLog(@"%2$[tt]@ %1$[tt]s", @"Foo", @"Bar"); // expected-warning {{object format flags cannot be used with 's' conversion specifier}}
 }
+
+// rdar://23622446
+@interface RD23622446_Tester: NSObject
+
++ (void)stringWithFormat:(const char *)format, ... __attribute__((format(__printf__, 1, 2)));
+
+@end
+
+@implementation RD23622446_Tester
+
+__attribute__ ((format_arg(1)))
+const char *rd23622446(const char *format) {
+  return format;
+}
+
++ (void)stringWithFormat:(const char *)format, ... {
+  return;
+}
+
+- (const char *)test:(const char *)format __attribute__ ((format_arg(1))) {
+  return format;
+}
+
+- (NSString *)str:(NSString *)format __attribute__ ((format_arg(1))) {
+  return format;
+}
+
+- (void)foo {
+  [RD23622446_Tester stringWithFormat:rd23622446("%u"), 1, 2]; // expected-warning {{data argument not used by format string}}
+  [RD23622446_Tester stringWithFormat:[self test: "%u"], 1, 2]; // expected-warning {{data argument not used by format string}}
+  [RD23622446_Tester stringWithFormat:[self test: "%s %s"], "name"]; // expected-warning {{more '%' conversions than data arguments}}
+  NSLog([self str: @"%@ %@"], @"name"); // expected-warning {{more '%' conversions than data arguments}}
+  [RD23622446_Tester stringWithFormat:rd23622446("%d"), 1]; // ok
+  [RD23622446_Tester stringWithFormat:[self test: "%d %d"], 1, 2]; // ok
+  NSLog([self str: @"%@"], @"string"); // ok
+}
+
+@end
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -4481,6 +4481,20 @@
 
 return SLCT_NotALiteral;
   }
+  case Stmt::ObjCMessageExprClass: {
+const auto *ME = cast(E);
+if (const auto *ND = ME->getMethodDecl()) {
+  if (const auto *FA = ND->getAttr()) {
+unsigned ArgIndex = FA->getFormatIdx();
+const Expr 

[PATCH] D25816: Use descriptive message if list initializer is incorrectly parenthesized.

2016-10-21 Thread Alex Lorenz via cfe-commits
arphaman added a subscriber: rsmith.
arphaman added a comment.

LGTM, I added Richard in case he has something to add.

> I chose to retain current clang behavior and reject questionable code. GCC 
> patch that introduced this message explains using warning by some 
> uncertainty, 5 years passed, I think the standard is stable in viewpoint on 
> such usage.

Thanks for the detailed explanation, I wasn't sure if GCC's was behaving 
according to the standard or not.


https://reviews.llvm.org/D25816



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


[PATCH] D23765: Fix for clang PR 29087

2016-10-21 Thread Serge Pavlov via cfe-commits
sepavloff added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:4231
+const CXXConstructorDecl *Constructor = nullptr;
+if (const ConstructorUsingShadowDecl *CSD =
+dyn_cast(ND)) {

Use `auto` here. Type of `CSD` is clear from `dyn_cast`.



Comment at: lib/Sema/SemaExprCXX.cpp:4233
+dyn_cast(ND)) {
+  assert(isa(CSD->getTargetDecl()));
+  Constructor = cast(CSD->getTargetDecl());

This `assert` is excessive. The subsequent `cast` makes this check.



Comment at: lib/Sema/SemaExprCXX.cpp:4239-4240
+continue;
+}
+else
+  Constructor = cast(ND);

Put `else` on the same line as `}`.



Comment at: lib/Sema/SemaExprCXX.cpp:4281
+const CXXConstructorDecl *Constructor = nullptr;
+if (const ConstructorUsingShadowDecl *CSD =
+dyn_cast(ND)) {

Use `auto` here.



Comment at: lib/Sema/SemaExprCXX.cpp:4283
+dyn_cast(ND)) {
+  assert(isa(CSD->getTargetDecl()));
+  Constructor = cast(CSD->getTargetDecl());

The `assert` is excessive.



Comment at: lib/Sema/SemaExprCXX.cpp:4289-4290
+continue;
+}
+else
+  Constructor = cast(ND);

Put `else` on the same line as `}`.


https://reviews.llvm.org/D23765



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


[PATCH] D25731: [analyzer] NumberObjectConversion: Support OSNumber and CFNumberRef.

2016-10-21 Thread Artem Dergachev via cfe-commits
NoQ updated this revision to Diff 75411.
NoQ marked 5 inline comments as done.
NoQ added a comment.

Address review comments. Add the forgotten tests.


https://reviews.llvm.org/D25731

Files:
  lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  test/Analysis/number-object-conversion.c
  test/Analysis/number-object-conversion.cpp
  test/Analysis/number-object-conversion.m

Index: test/Analysis/number-object-conversion.m
===
--- test/Analysis/number-object-conversion.m
+++ test/Analysis/number-object-conversion.m
@@ -10,30 +10,36 @@
 
 void bad(NSNumber *p) {
 #ifdef PEDANTIC
-  if (p) {} // expected-warning{{Converting 'NSNumber *' to a plain boolean value for branching; please compare the pointer to nil instead to suppress this warning}}
-  if (!p) {} // expected-warning{{Converting 'NSNumber *' to a plain boolean value for branching; please compare the pointer to nil instead to suppress this warning}}
-  (!p) ? 1 : 2; // expected-warning{{Converting 'NSNumber *' to a plain boolean value for branching; please compare the pointer to nil instead to suppress this warning}}
-  (BOOL)p; // expected-warning{{Converting 'NSNumber *' to a plain BOOL value; please compare the pointer to nil instead to suppress this warning}}
-  if (p == 0) {} // expected-warning{{Converting 'NSNumber *' to a plain integer value; please compare the pointer to nil instead to suppress this warning}}
-  if (p > 0) {} // expected-warning{{Converting 'NSNumber *' to a plain integer value; pointer value is being used instead}}
+  if (p) {} // expected-warning{{Converting 'NSNumber *' pointer to a branch condition; instead, compare the pointer to nil or take the encapsulated scalar value}}
+  if (!p) {} // expected-warning{{Converting 'NSNumber *' pointer to a branch condition; instead, compare the pointer to nil or take the encapsulated scalar value}}
+  (!p) ? 1 : 2; // expected-warning{{Converting 'NSNumber *' pointer to a branch condition; instead, compare the pointer to nil or take the encapsulated scalar value}}
+  (BOOL)p; // expected-warning{{Converting 'NSNumber *' pointer to a plain BOOL value; instead, compare the pointer to nil or take the encapsulated scalar value}}
+  if (p == 0) {} // expected-warning{{Converting 'NSNumber *' pointer to a plain integer value; instead, compare the pointer to nil or take the encapsulated scalar value}}
+#else
+  if (p) {} // no-warning
+  if (!p) {} // no-warning
+  (!p) ? 1 : 2; // no-warning
+  (BOOL)p; // no-warning
+  if (p == 0) {} // no-warning
 #endif
-  if (p == YES) {} // expected-warning{{Converting 'NSNumber *' to a plain BOOL value; pointer value is being used instead}}
-  if (p == NO) {} // expected-warning{{Converting 'NSNumber *' to a plain BOOL value; pointer value is being used instead}}
-  BOOL x = p; // expected-warning{{Converting 'NSNumber *' to a plain BOOL value; pointer value is being used instead}}
-  x = p; // expected-warning{{Converting 'NSNumber *' to a plain BOOL value; pointer value is being used instead}}
-  x = (p == YES); // expected-warning{{Converting 'NSNumber *' to a plain BOOL value; pointer value is being used instead}}
-  if (p == 1) {} // expected-warning{{Converting 'NSNumber *' to a plain integer value; pointer value is being used instead}}
-  int y = p; // expected-warning{{Converting 'NSNumber *' to a plain integer value; pointer value is being used instead}}
-  y = p; // expected-warning{{Converting 'NSNumber *' to a plain integer value; pointer value is being used instead}}
-  takes_boolean(p); // expected-warning{{Converting 'NSNumber *' to a plain BOOL value; pointer value is being used instead}}
-  takes_integer(p); // expected-warning{{Converting 'NSNumber *' to a plain integer value; pointer value is being used instead}}
+  if (p > 0) {} // expected-warning{{Converting 'NSNumber *' pointer to a plain integer value; pointer value is being used instead}}
+  if (p == YES) {} // expected-warning{{Converting 'NSNumber *' pointer to a plain BOOL value; pointer value is being used instead}}
+  if (p == NO) {} // expected-warning{{Converting 'NSNumber *' pointer to a plain BOOL value; pointer value is being used instead}}
+  BOOL x = p; // expected-warning{{Converting 'NSNumber *' pointer to a plain BOOL value; pointer value is being used instead}}
+  x = p; // expected-warning{{Converting 'NSNumber *' pointer to a plain BOOL value; pointer value is being used instead}}
+  x = (p == YES); // expected-warning{{Converting 'NSNumber *' pointer to a plain BOOL value; pointer value is being used instead}}
+  if (p == 1) {} // expected-warning{{Converting 'NSNumber *' pointer to a plain integer value; pointer value is being used instead}}
+  int y = p; // expected-warning{{Converting 'NSNumber *' pointer to a plain integer value; pointer value is being used instead}}
+  y = p; // expected-warning{{Converting 'NSNumber *' pointer to a plain integer value; pointer value is being u

[PATCH] D25731: [analyzer] NumberObjectConversion: Support OSNumber and CFNumberRef.

2016-10-21 Thread Artem Dergachev via cfe-commits
NoQ marked an inline comment as done.
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp:149
  BugReporter &BR) const {
   MatchFinder F;
   Callback CB(this, BR, AM.getAnalysisDeclContext(D));

alexshap wrote:
> probably it would make sense to move "MatchFinder F;" to the line 276 (closer 
> to the place where it's actually being used)(or maybe i'm missing smth ?) 
Yep, great idea.



Comment at: test/Analysis/number-object-conversion.c:14
+  if (p) {} // expected-warning{{Converting 'CFNumberRef' to a plain boolean 
value for branching; please compare the pointer to NULL instead to suppress 
this warning}}
+  if (!p) {} // expected-warning{{Converting 'CFNumberRef' to a plain boolean 
value for branching; please compare the pointer to NULL instead to suppress 
this warning}}
+  p ? 1 : 2; // expected-warning{{Converting 'CFNumberRef' to a plain boolean 
value for branching; please compare the pointer to NULL instead to suppress 
this warning}}

zaks.anna wrote:
> How about:
> "Converting 'CFNumberRef' pointer to a plain boolean value; instead, compare 
> the pointer to NULL or compare to the encapsulated scalar value"
> 
> - I've added "pointer".
> - I would remove "for branching". Does it add anything?
> - Also, we should remove "please" as it makes the warning text longer.
> 
> I would remove "for branching". Does it add anything?

Because there's otherwise no obvious boolean value around, i wanted to point 
out what exactly is going on.

> or compare to the encapsulated scalar value

They don't necessarily compare the value. Maybe "take"?

> I've added "pointer".

Not sure it's worth keeping for other objects ("`'NSNumber *' pointer`" sounds 
like a pointer to a pointer).


https://reviews.llvm.org/D25731



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


[PATCH] D25777: [Sema][TreeTransform] Re-create DesignatedInitExpr when it has a field designator with a valid FieldDecl

2016-10-21 Thread Alex Lorenz via cfe-commits
arphaman added a comment.

In https://reviews.llvm.org/D25777#575564, @rjmccall wrote:

> The fact that this bug only arises when performing a *second* instantiation 
> suggests that there's a deeper bug here, because template instantiation is 
> not supposed to modify the pattern AST.  In this case, the basic problem is 
> that, when the parser processes a designator, it only has an identifier, not 
> a FieldDecl*, because it doesn't know what type is being initialized yet.  
> SemaInit eventually resolves that identifier to a FieldDecl and needs to 
> record that in the AST; typically the AST is treated as immutable, but in 
> this case, instead of cloning the expression, Sema just modifies the field 
> designator in-place.  That's not completely unreasonable, and it's definitely 
> the most space-efficient solution for non-template code-building; but in 
> template code, it does mean that we have to take care to not present the same 
> unresolved field designator to Sema twice.
>
> Fortunately, this is pretty easy: we just need to need to flag the expression 
> as needing rebuilding when there isn't a resolved field in the field 
> designator.  When there *is* a resolved field, we just need to map it using 
> TransformDecl; the expression then only needs to be rebuilt if that fails or 
> returns a different declaration.


You're right, the point that you made about modifying the pattern AST is 
correct. I will update the patch accordingly.


Repository:
  rL LLVM

https://reviews.llvm.org/D25777



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


[PATCH] D25777: [Sema][TreeTransform] Re-create DesignatedInitExpr when it has a field designator with a valid FieldDecl

2016-10-21 Thread Alex Lorenz via cfe-commits
arphaman updated this revision to Diff 75414.
arphaman added a comment.

The updated patch addresses John's comment by modifying the 
`DesignatedInitExpr` re-creation logic.


Repository:
  rL LLVM

https://reviews.llvm.org/D25777

Files:
  lib/Sema/TreeTransform.h
  test/SemaCXX/designated-initializers.cpp


Index: test/SemaCXX/designated-initializers.cpp
===
--- /dev/null
+++ test/SemaCXX/designated-initializers.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Winitializer-overrides %s
+
+template  struct Foo {
+  struct SubFoo {
+int bar1;
+int bar2;
+  };
+
+  static void Test() { SubFoo sf = {.bar1 = 10, .bar2 = 20}; } // Expected no 
warning
+};
+
+void foo() {
+  Foo::Test();
+  Foo::Test();
+  Foo::Test();
+}
+
+template  struct Bar {
+  struct SubFoo {
+int bar1;
+int bar2;
+  };
+
+  static void Test() { SubFoo sf = {.bar1 = 10,// expected-note 2 
{{previous initialization is here}}
+.bar1 = 20}; } // expected-warning 2 
{{initializer overrides prior initialization of this subobject}}
+};
+
+void bar() {
+  Bar::Test();  // expected-note {{in instantiation of member function 
'Bar::Test' requested here}}
+  Bar::Test(); // expected-note {{in instantiation of member function 
'Bar::Test' requested here}}
+}
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -8923,6 +8923,19 @@
   Desig.AddDesignator(Designator::getField(D.getFieldName(),
D.getDotLoc(),
D.getFieldLoc()));
+  if (D.getField()) {
+FieldDecl *Field = dyn_cast_or_null(
+getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
+if (Field != D.getField())
+  // Rebuild the expression when the transformed FieldDecl is
+  // different to the already assigned FieldDecl.
+  ExprChanged = true;
+  } else {
+// Ensure that the designator expression is rebuilt when there isn't
+// a resolved FieldDecl in the designator as we don't want to assign
+// a FieldDecl to a pattern designator that will be instantiated again.
+ExprChanged = true;
+  }
   continue;
 }
 


Index: test/SemaCXX/designated-initializers.cpp
===
--- /dev/null
+++ test/SemaCXX/designated-initializers.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Winitializer-overrides %s
+
+template  struct Foo {
+  struct SubFoo {
+int bar1;
+int bar2;
+  };
+
+  static void Test() { SubFoo sf = {.bar1 = 10, .bar2 = 20}; } // Expected no warning
+};
+
+void foo() {
+  Foo::Test();
+  Foo::Test();
+  Foo::Test();
+}
+
+template  struct Bar {
+  struct SubFoo {
+int bar1;
+int bar2;
+  };
+
+  static void Test() { SubFoo sf = {.bar1 = 10,// expected-note 2 {{previous initialization is here}}
+.bar1 = 20}; } // expected-warning 2 {{initializer overrides prior initialization of this subobject}}
+};
+
+void bar() {
+  Bar::Test();  // expected-note {{in instantiation of member function 'Bar::Test' requested here}}
+  Bar::Test(); // expected-note {{in instantiation of member function 'Bar::Test' requested here}}
+}
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -8923,6 +8923,19 @@
   Desig.AddDesignator(Designator::getField(D.getFieldName(),
D.getDotLoc(),
D.getFieldLoc()));
+  if (D.getField()) {
+FieldDecl *Field = dyn_cast_or_null(
+getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
+if (Field != D.getField())
+  // Rebuild the expression when the transformed FieldDecl is
+  // different to the already assigned FieldDecl.
+  ExprChanged = true;
+  } else {
+// Ensure that the designator expression is rebuilt when there isn't
+// a resolved FieldDecl in the designator as we don't want to assign
+// a FieldDecl to a pattern designator that will be instantiated again.
+ExprChanged = true;
+  }
   continue;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25311: Add FixItHint for missing #include (err_module_unimported_use_header)

2016-10-21 Thread Sam McCall via cfe-commits
sammccall added a comment.

> I don't know the history behind the desired dependencies, I'll let others 
> comment whether this is OK, but my guess it that it depends on the tradeoff, 
> it's hard to justify 3 new deps for a change that is supposed to be simple. 
> How hard is to implement this without using libFormat?

What libFormat does is fairly complex:

- it parses header guards/file comments to avoid violating them
- it locates existing includes to insert nearby
- it is aware of "main header", and system vs user headers
- it avoids generating a fixit if the header is already included somewhere
- it preserves sort order within include blocks (I forgot to include this!)

This is fixCppIncludeInsertions in Format.cpp plus its helpers, and 
sortCppIncludes.

Altogether this looks like being around 500LOC that would be directly 
duplicated, plus some replacements for policy handled by LLVMStyle, plus tests 
(a new impl would need to be more thoroughly tested).
I also don't know what the costs of the dependency are.

ioeric: is my estimate about right?




Comment at: lib/Sema/SemaLookup.cpp:4997
+format::getLLVMStyle());
+  if (Reps)
+for (const auto &Placed : *Reps) {

Hmm, I probably want to formatReplacements here for sorting...


https://reviews.llvm.org/D25311



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


[PATCH] D25869: [Driver] Add unit tests for DetectDistro()

2016-10-21 Thread Michał Górny via cfe-commits
mgorny created this revision.
mgorny added reviewers: bruno, bkramer, rafael.
mgorny added a subscriber: cfe-commits.
Herald added a subscriber: beanz.

Add a set of unit tests for the DetectDistro() function in Driver. Make
the function itself (and the enum) visible in the library for the tests.

The tests use an in-memory virtual filesystems resembling release files
for various distributions supported. All release files are provided (not
only the ones directly used) in order to guarantee that one of the rules
will not mistakenly recognize the distribution incorrectly due to
the additional files (e.g. Ubuntu as Debian).


https://reviews.llvm.org/D25869

Files:
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h
  unittests/Driver/CMakeLists.txt
  unittests/Driver/ToolChainsTest.cpp

Index: unittests/Driver/ToolChainsTest.cpp
===
--- /dev/null
+++ unittests/Driver/ToolChainsTest.cpp
@@ -0,0 +1,157 @@
+//===- unittests/Driver/ToolChainsTest.cpp --- ToolChains tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Unit tests for ToolChains.
+//
+//===--===//
+
+// FIXME: I presume this is not the correct way of doing this
+#include "../lib/Driver/ToolChains.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+using namespace clang;
+using namespace clang::driver::toolchains;
+
+namespace {
+
+TEST(ToolChainsTest, DetectDistro) {
+  // The tests include all release-related files for each distribution
+  // in the VFS, in order to make sure that earlier tests do not
+  // accidentally result in incorrect distribution guess.
+
+  vfs::InMemoryFileSystem UbuntuTrustyFileSystem;
+  // Ubuntu uses Debian Sid version.
+  UbuntuTrustyFileSystem.addFile("/etc/debian_version", 0,
+  llvm::MemoryBuffer::getMemBuffer("jessie/sid\n"));
+  UbuntuTrustyFileSystem.addFile("/etc/lsb-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("DISTRIB_ID=Ubuntu\n"
+   "DISTRIB_RELEASE=14.04\n"
+   "DISTRIB_CODENAME=trusty\n"
+   "DISTRIB_DESCRIPTION=\"Ubuntu 14.04 LTS\"\n"));
+  UbuntuTrustyFileSystem.addFile("/etc/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("NAME=\"Ubuntu\"\n"
+   "VERSION=\"14.04, Trusty Tahr\"\n"
+   "ID=ubuntu\n"
+   "ID_LIKE=debian\n"
+   "PRETTY_NAME=\"Ubuntu 14.04 LTS\"\n"
+   "VERSION_ID=\"14.04\"\n"
+   "HOME_URL=\"http://www.ubuntu.com/\"\n";
+   "SUPPORT_URL=\"http://help.ubuntu.com/\"\n";
+   "BUG_REPORT_URL=\"http://bugs.launchpad.net/ubuntu/\"\n";));
+  ASSERT_EQ(UbuntuTrusty, DetectDistro(UbuntuTrustyFileSystem));
+
+  vfs::InMemoryFileSystem UbuntuYakketyFileSystem;
+  UbuntuYakketyFileSystem.addFile("/etc/debian_version", 0,
+  llvm::MemoryBuffer::getMemBuffer("stretch/sid\n"));
+  UbuntuYakketyFileSystem.addFile("/etc/lsb-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("DISTRIB_ID=Ubuntu\n"
+   "DISTRIB_RELEASE=16.10\n"
+   "DISTRIB_CODENAME=yakkety\n"
+   "DISTRIB_DESCRIPTION=\"Ubuntu 16.10\"\n"));
+  UbuntuYakketyFileSystem.addFile("/etc/os-release", 0,
+  llvm::MemoryBuffer::getMemBuffer("NAME=\"Ubuntu\"\n"
+   "VERSION=\"16.10 (Yakkety Yak)\"\n"
+   "ID=ubuntu\n"
+   "ID_LIKE=debian\n"
+   "PRETTY_NAME=\"Ubuntu 16.10\"\n"
+   "VERSION_ID=\"16.10\"\n"
+   "HOME_URL=\"http://www.ubuntu.com/\"\n";
+   "SUPPORT_URL=\"http://help.ubuntu.com/\"\n";
+   "BUG_REPORT_URL=\"http://bugs.launchpad.net/ubuntu/\"\n";
+   "PRIVACY_POLICY_URL=\"http://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"\n";
+   "VERSION_CODENAME=yakkety\n"
+   "UBUNTU_CODENAME=yakkety\n"));
+  ASSERT_EQ(UbuntuYakkety, DetectDistro(UbuntuYakketyFileSystem));
+
+  vfs::InMemoryFileSystem Fedora25FileSystem;
+  Fedora25FileSystem.addFile("/etc/system-release-cpe", 0,
+  llvm::Memor

[PATCH] D25311: Add FixItHint for missing #include (err_module_unimported_use_header)

2016-10-21 Thread Benjamin Kramer via cfe-commits
bkramer added a comment.

In https://reviews.llvm.org/D25311#574806, @bruno wrote:

> I don't know the history behind the desired dependencies, I'll let others 
> comment whether this is OK, but my guess it that it depends on the tradeoff, 
> it's hard to justify 3 new deps for a change that is supposed to be simple. 
> How hard is to implement this without using libFormat?


I think clang already depends on libclangRewrite. libclangToolingCore is tiny, 
it's basically just the Replacement class and a couple of utilities. While it 
would be possible to hoist just the include handling and its dependencies out 
of libclangFormat into a separate library I'm not convinced that it's worth it. 
libclangFormat is tiny, the .a file is less than a megabyte and the impact on 
the clang binary is 400kB in a Release+Asserts build, a 0.5% increase.


https://reviews.llvm.org/D25311



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


[PATCH] D25871: Include full filename range for missing includes

2016-10-21 Thread Erik Verbruggen via cfe-commits
erikjv created this revision.
erikjv added reviewers: bkramer, klimek.
erikjv added a subscriber: cfe-commits.

For the purpose of highlighting in an IDE.


https://reviews.llvm.org/D25871

Files:
  lib/Lex/PPDirectives.cpp
  test/Preprocessor/missing-include-range-check.h


Index: test/Preprocessor/missing-include-range-check.h
===
--- /dev/null
+++ test/Preprocessor/missing-include-range-check.h
@@ -0,0 +1,8 @@
+// RUN: env CINDEXTEST_KEEP_GOING=1 c-index-test -test-load-source all %s > 
/dev/null 2> %t.err
+// RUN: FileCheck < %t.err -check-prefix=CHECK-RANGE %s
+
+#include 
+#include "moozegnarf.h"
+
+// CHECK-RANGE: rewrite-includes-missing.c:4:10:{4:10-4:19}: fatal error: 
'foobar.h' file not found
+// CHECK-RANGE: rewrite-includes-missing.c:5:10:{5:10-5:24}: fatal error: 
'moozegnarf.h' file not found
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1847,7 +1847,8 @@
 
   // If the file is still not found, just go with the vanilla diagnostic
   if (!File)
-Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
+Diag(FilenameTok, diag::err_pp_file_not_found) << Filename
+   << FilenameRange;
 }
   }
 


Index: test/Preprocessor/missing-include-range-check.h
===
--- /dev/null
+++ test/Preprocessor/missing-include-range-check.h
@@ -0,0 +1,8 @@
+// RUN: env CINDEXTEST_KEEP_GOING=1 c-index-test -test-load-source all %s > /dev/null 2> %t.err
+// RUN: FileCheck < %t.err -check-prefix=CHECK-RANGE %s
+
+#include 
+#include "moozegnarf.h"
+
+// CHECK-RANGE: rewrite-includes-missing.c:4:10:{4:10-4:19}: fatal error: 'foobar.h' file not found
+// CHECK-RANGE: rewrite-includes-missing.c:5:10:{5:10-5:24}: fatal error: 'moozegnarf.h' file not found
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1847,7 +1847,8 @@
 
   // If the file is still not found, just go with the vanilla diagnostic
   if (!File)
-Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
+Diag(FilenameTok, diag::err_pp_file_not_found) << Filename
+   << FilenameRange;
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25870: Fix 'unknown documentation command' warning ranges

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

Nice. Thanks!


https://reviews.llvm.org/D25870



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


[PATCH] D25870: Fix 'unknown documentation command' warning ranges

2016-10-21 Thread Erik Verbruggen via cfe-commits
erikjv created this revision.
erikjv added reviewers: bkramer, klimek.
erikjv added a subscriber: cfe-commits.

Warnings generated by -Wdocumentation-unknown-command did only have a
start location, not a full source range. This resulted in only the
"carret" being show in messages, and IDEs highlighting only the single
initial character.

Now that the full range is available, nice underlineing can be done, and
tools that support more/other commands than doxygen can filter out those
warnings.


https://reviews.llvm.org/D25870

Files:
  lib/AST/CommentLexer.cpp
  test/Sema/warn-documentation-unknown-command.cpp


Index: test/Sema/warn-documentation-unknown-command.cpp
===
--- test/Sema/warn-documentation-unknown-command.cpp
+++ test/Sema/warn-documentation-unknown-command.cpp
@@ -9,3 +9,7 @@
 /// \retur aaa
 int test_unknown_comand_2();
 
+// RUN: c-index-test -test-load-source all -Wdocumentation-unknown-command %s 
> /dev/null 2> %t.err
+// RUN: FileCheck < %t.err -check-prefix=CHECK-RANGE %s
+// CHECK-RANGE: warn-documentation-unknown-command.cpp:5:9:{5:9-5:17}: 
warning: unknown command tag name
+// CHECK-RANGE: warn-documentation-unknown-command.cpp:9:5:{9:5-9:11}: 
warning: unknown command tag name 'retur'; did you mean 'return'?
Index: lib/AST/CommentLexer.cpp
===
--- lib/AST/CommentLexer.cpp
+++ lib/AST/CommentLexer.cpp
@@ -378,15 +378,17 @@
   if ((Info = Traits.getTypoCorrectCommandInfo(CommandName))) {
 StringRef CorrectedName = Info->Name;
 SourceLocation Loc = getSourceLocation(BufferPtr);
-SourceRange CommandRange(Loc.getLocWithOffset(1),
- getSourceLocation(TokenPtr));
+SourceLocation EndLoc = getSourceLocation(TokenPtr);
+SourceRange FullRange = SourceRange(Loc, EndLoc);
+SourceRange CommandRange(Loc.getLocWithOffset(1), EndLoc);
 Diag(Loc, diag::warn_correct_comment_command_name)
-  << CommandName << CorrectedName
+  << FullRange << CommandName << CorrectedName
   << FixItHint::CreateReplacement(CommandRange, CorrectedName);
   } else {
 formTokenWithChars(T, TokenPtr, tok::unknown_command);
 T.setUnknownCommandName(CommandName);
-Diag(T.getLocation(), diag::warn_unknown_comment_command_name);
+Diag(T.getLocation(), diag::warn_unknown_comment_command_name)
+<< SourceRange(T.getLocation(), T.getEndLocation());
 return;
   }
 }


Index: test/Sema/warn-documentation-unknown-command.cpp
===
--- test/Sema/warn-documentation-unknown-command.cpp
+++ test/Sema/warn-documentation-unknown-command.cpp
@@ -9,3 +9,7 @@
 /// \retur aaa
 int test_unknown_comand_2();
 
+// RUN: c-index-test -test-load-source all -Wdocumentation-unknown-command %s > /dev/null 2> %t.err
+// RUN: FileCheck < %t.err -check-prefix=CHECK-RANGE %s
+// CHECK-RANGE: warn-documentation-unknown-command.cpp:5:9:{5:9-5:17}: warning: unknown command tag name
+// CHECK-RANGE: warn-documentation-unknown-command.cpp:9:5:{9:5-9:11}: warning: unknown command tag name 'retur'; did you mean 'return'?
Index: lib/AST/CommentLexer.cpp
===
--- lib/AST/CommentLexer.cpp
+++ lib/AST/CommentLexer.cpp
@@ -378,15 +378,17 @@
   if ((Info = Traits.getTypoCorrectCommandInfo(CommandName))) {
 StringRef CorrectedName = Info->Name;
 SourceLocation Loc = getSourceLocation(BufferPtr);
-SourceRange CommandRange(Loc.getLocWithOffset(1),
- getSourceLocation(TokenPtr));
+SourceLocation EndLoc = getSourceLocation(TokenPtr);
+SourceRange FullRange = SourceRange(Loc, EndLoc);
+SourceRange CommandRange(Loc.getLocWithOffset(1), EndLoc);
 Diag(Loc, diag::warn_correct_comment_command_name)
-  << CommandName << CorrectedName
+  << FullRange << CommandName << CorrectedName
   << FixItHint::CreateReplacement(CommandRange, CorrectedName);
   } else {
 formTokenWithChars(T, TokenPtr, tok::unknown_command);
 T.setUnknownCommandName(CommandName);
-Diag(T.getLocation(), diag::warn_unknown_comment_command_name);
+Diag(T.getLocation(), diag::warn_unknown_comment_command_name)
+<< SourceRange(T.getLocation(), T.getEndLocation());
 return;
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25871: Include full filename range for missing includes

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

lg


https://reviews.llvm.org/D25871



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


[PATCH] D25450: [clang-tidy] Fix identifier naming in macro args.

2016-10-21 Thread Jason Henline via cfe-commits
jhen updated this revision to Diff 75430.
jhen added a comment.

- Early exit if not Failure.ShouldFix


https://reviews.llvm.org/D25450

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -95,14 +95,41 @@
 USER_MACRO(var2);
 // NO warnings or fixes expected as var2 is declared in a macro expansion
 
+#define BLA int FOO_bar
+BLA;
+// NO warnings or fixes expected as FOO_bar is from macro expansion
+
+int global0;
+#define USE_NUMBERED_GLOBAL(number) auto use_global##number = global##number
+USE_NUMBERED_GLOBAL(0);
+// NO warnings or fixes expected as global0 is pieced together in a macro
+// expansion.
+
+int global1;
+#define USE_NUMBERED_BAL(prefix, number) \
+  auto use_##prefix##bal##number = prefix##bal##number
+USE_NUMBERED_BAL(glo, 1);
+// NO warnings or fixes expected as global1 is pieced together in a macro
+// expansion.
+
+int global2;
+#define USE_RECONSTRUCTED(glo, bal) auto use_##glo##bal = glo##bal
+USE_RECONSTRUCTED(glo, bal2);
+// NO warnings or fixes expected as global2 is pieced together in a macro
+// expansion.
+
 int global;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'global'
+// CHECK-FIXES: {{^}}int g_global;{{$}}
 #define USE_IN_MACRO(m) auto use_##m = m
 USE_IN_MACRO(global);
-// NO warnings or fixes expected as global is used in a macro expansion
 
-#define BLA int FOO_bar
-BLA;
-// NO warnings or fixes expected as FOO_bar is from macro expansion
+int global3;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'global3'
+// CHECK-FIXES: {{^}}int g_global3;{{$}}
+#define ADD_TO_SELF(m) (m) + (m)
+int g_twice_global3 = ADD_TO_SELF(global3);
+// CHECK-FIXES: {{^}}int g_twice_global3 = ADD_TO_SELF(g_global3);{{$}}
 
 enum my_enumeration {
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for enum 'my_enumeration'
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -612,27 +612,57 @@
 
 static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap &Failures,
  const IdentifierNamingCheck::NamingCheckId &Decl,
- SourceRange Range) {
+ SourceRange Range, SourceManager *SourceMgr = nullptr) {
   // Do nothing if the provided range is invalid.
   if (Range.getBegin().isInvalid() || Range.getEnd().isInvalid())
 return;
 
+  // If we have a source manager, use it to convert to the spelling location for
+  // performing the fix. This is necessary because macros can map the same
+  // spelling location to different source locations, and we only want to fix
+  // the token once, before it is expanded by the macro.
+  SourceLocation FixLocation = Range.getBegin();
+  if (SourceMgr)
+FixLocation = SourceMgr->getSpellingLoc(FixLocation);
+  if (FixLocation.isInvalid())
+return;
+
   // Try to insert the identifier location in the Usages map, and bail out if it
   // is already in there
   auto &Failure = Failures[Decl];
-  if (!Failure.RawUsageLocs.insert(Range.getBegin().getRawEncoding()).second)
+  if (!Failure.RawUsageLocs.insert(FixLocation.getRawEncoding()).second)
+return;
+
+  if (!Failure.ShouldFix)
 return;
 
-  Failure.ShouldFix = Failure.ShouldFix && !Range.getBegin().isMacroID() &&
-  !Range.getEnd().isMacroID();
+  // Check if the range is entirely contained within a macro argument.
+  SourceLocation MacroArgExpansionStartForRangeBegin;
+  SourceLocation MacroArgExpansionStartForRangeEnd;
+  bool RangeIsEntirelyWithinMacroArgument =
+  SourceMgr &&
+  SourceMgr->isMacroArgExpansion(Range.getBegin(),
+ &MacroArgExpansionStartForRangeBegin) &&
+  SourceMgr->isMacroArgExpansion(Range.getEnd(),
+ &MacroArgExpansionStartForRangeEnd) &&
+  MacroArgExpansionStartForRangeBegin == MacroArgExpansionStartForRangeEnd;
+
+  // Check if the range contains any locations from a macro expansion.
+  bool RangeContainsMacroExpansion = RangeIsEntirelyWithinMacroArgument ||
+ Range.getBegin().isMacroID() ||
+ Range.getEnd().isMacroID();
+
+  bool RangeCanBeFixed =
+  RangeIsEntirelyWithinMacroArgument || !RangeContainsMacroExpansion;
+  Failure.ShouldFix = RangeCanBeFixed;
 }
 
 /// Convenience method when the usage to be added is a NamedDecl
 static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap &Failures,
- const NamedDecl *Decl, SourceRange Range) {
+ 

[PATCH] D25450: [clang-tidy] Fix identifier naming in macro args.

2016-10-21 Thread Jason Henline via cfe-commits
jhen marked an inline comment as done.
jhen added inline comments.



Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:654
+  RangeIsEntirelyWithinMacroArgument || !RangeContainsMacroExpansion;
+  Failure.ShouldFix = Failure.ShouldFix && RangeCanBeFixed;
 }

aaron.ballman wrote:
> We could do an early return if `ShouldFix` is already false and simplify this 
> expression with `ShouldFix = RangeCanBeFixed;`, can't we?
Thanks for pointing that out. The early exit is much more efficient.


https://reviews.llvm.org/D25450



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


[PATCH] D25450: [clang-tidy] Fix identifier naming in macro args.

2016-10-21 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


https://reviews.llvm.org/D25450



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


[PATCH] D25820: [Sema][Objective-C] Formatting warnings should see through Objective-C message sends

2016-10-21 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


Repository:
  rL LLVM

https://reviews.llvm.org/D25820



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


[PATCH] D25363: [Sema] Store a SourceRange for multi-token builtin types

2016-10-21 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: include/clang/AST/TypeLoc.h:533
+} else {
+  BuiltinRange.setBegin(std::min(Range.getBegin(), 
BuiltinRange.getBegin()));
+  BuiltinRange.setEnd(std::max(Range.getEnd(), BuiltinRange.getEnd()));

aaron.ballman wrote:
> malcolm.parsons wrote:
> > I suspect that using `min` and `max` on `SourceLocation`s is only valid if 
> > both locations are in the same file.
> > 
> > Doing this
> > long.h:
> > ```
> > long
> > ```
> > unsigned.cpp:
> > ```
> > unsigned
> > #include "long.h"
> > i;
> > ```
> > 
> > causes
> > clang-query> match typeLoc()
> > ...
> > clang-query: llvm/tools/clang/lib/Frontend/DiagnosticRenderer.cpp:273: 
> > clang::SourceLocation retrieveMacroLocation(clang::SourceLocation, 
> > clang::FileID, clang::FileID, const llvm::SmallVectorImpl&, 
> > bool, const clang::SourceManager*): Assertion `SM->getFileID(Loc) == 
> > MacroFileID' failed.
> > 
> > Is there a better way to combine `SourceRange`s, or should the final range 
> > be accumulated in DeclSpec.cpp?
> Hmm, that's a good point, but I'm not aware of a better utility. Perhaps 
> @rsmith knows of one?
I get the same assertion failure from a clang-query without my changes if I 
match a `CompoundStmt` that starts and ends in different files.
So I don't think it's my fault.
It's also a very rare case.
OK to commit?


https://reviews.llvm.org/D25363



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


[PATCH] D25363: [Sema] Store a SourceRange for multi-token builtin types

2016-10-21 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/AST/TypeLoc.h:533
+} else {
+  BuiltinRange.setBegin(std::min(Range.getBegin(), 
BuiltinRange.getBegin()));
+  BuiltinRange.setEnd(std::max(Range.getEnd(), BuiltinRange.getEnd()));

malcolm.parsons wrote:
> aaron.ballman wrote:
> > malcolm.parsons wrote:
> > > I suspect that using `min` and `max` on `SourceLocation`s is only valid 
> > > if both locations are in the same file.
> > > 
> > > Doing this
> > > long.h:
> > > ```
> > > long
> > > ```
> > > unsigned.cpp:
> > > ```
> > > unsigned
> > > #include "long.h"
> > > i;
> > > ```
> > > 
> > > causes
> > > clang-query> match typeLoc()
> > > ...
> > > clang-query: llvm/tools/clang/lib/Frontend/DiagnosticRenderer.cpp:273: 
> > > clang::SourceLocation retrieveMacroLocation(clang::SourceLocation, 
> > > clang::FileID, clang::FileID, const 
> > > llvm::SmallVectorImpl&, bool, const 
> > > clang::SourceManager*): Assertion `SM->getFileID(Loc) == MacroFileID' 
> > > failed.
> > > 
> > > Is there a better way to combine `SourceRange`s, or should the final 
> > > range be accumulated in DeclSpec.cpp?
> > Hmm, that's a good point, but I'm not aware of a better utility. Perhaps 
> > @rsmith knows of one?
> I get the same assertion failure from a clang-query without my changes if I 
> match a `CompoundStmt` that starts and ends in different files.
> So I don't think it's my fault.
> It's also a very rare case.
> OK to commit?
Thank you for checking. I think you are okay to commit, we can correct the bug 
in another patch. However, if you wouldn't mind filing a bug in bugzilla so 
that we don't lose this information, that would be great.


https://reviews.llvm.org/D25363



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


[PATCH] D25796: [CUDA] Create __host__ and device variants of standard allocator declarations.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added a comment.

Is it not possible to write a testcase for this?


https://reviews.llvm.org/D25796



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


[PATCH] D25647: [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM with two minor nits.




Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp:102
+  SpecialMemberFunctionKind Kind = KV.second;
+  auto &Members = ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end()) Members.push_back(Kind);

Please don't use `auto` since the type is not spelled out in the initializer.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp:103
+  auto &Members = ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end()) Members.push_back(Kind);
+}

Please drop the `push_back()` onto its own line.


Repository:
  rL LLVM

https://reviews.llvm.org/D25647



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


[PATCH] D25647: [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added a comment.

Hi, friendly ping?  This trivial patch is the only blocker remaining before I 
can land https://reviews.llvm.org/D25648, which is the first part of my Grand 
Set Refactoring (see mail to llvm-dev about a week ago).


Repository:
  rL LLVM

https://reviews.llvm.org/D25647



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


[PATCH] D25647: [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Benjamin Kramer via cfe-commits
bkramer added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp:103
+  auto &Members = ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end()) Members.push_back(Kind);
+}

jlebar wrote:
> aaron.ballman wrote:
> > Please drop the `push_back()` onto its own line.
> This was actually how clang-tidy formatted the line.  My understanding is 
> that we go with that in llvm projects?  Unless you're saying I have an 
> outdated clang-tidy, in which case I will investigate that.
It's what happens when your clang-format is using Google style. Some versions 
of clang-format ship with weird defaults, so you have to add -style=LLVM 
manually.


Repository:
  rL LLVM

https://reviews.llvm.org/D25647



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


[PATCH] D25647: [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added a comment.

Thank you very much for the review!




Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp:103
+  auto &Members = ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end()) Members.push_back(Kind);
+}

bkramer wrote:
> jlebar wrote:
> > aaron.ballman wrote:
> > > Please drop the `push_back()` onto its own line.
> > This was actually how clang-tidy formatted the line.  My understanding is 
> > that we go with that in llvm projects?  Unless you're saying I have an 
> > outdated clang-tidy, in which case I will investigate that.
> It's what happens when your clang-format is using Google style. Some versions 
> of clang-format ship with weird defaults, so you have to add -style=LLVM 
> manually.
Er, s/clang-tidy/clang-format/


Repository:
  rL LLVM

https://reviews.llvm.org/D25647



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


[PATCH] D25647: [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added a comment.

Thank you very much for the review!




Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp:103
+  auto &Members = ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end()) Members.push_back(Kind);
+}

aaron.ballman wrote:
> Please drop the `push_back()` onto its own line.
This was actually how clang-tidy formatted the line.  My understanding is that 
we go with that in llvm projects?  Unless you're saying I have an outdated 
clang-tidy, in which case I will investigate that.


Repository:
  rL LLVM

https://reviews.llvm.org/D25647



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


[PATCH] D23765: Fix for clang PR 29087

2016-10-21 Thread Taewook Oh via cfe-commits
twoh updated this revision to Diff 75441.
twoh marked an inline comment as done.
twoh added a comment.

Addressing comments from @sepavloff. Thanks!


https://reviews.llvm.org/D23765

Files:
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/cxx11-crashes.cpp


Index: test/SemaCXX/cxx11-crashes.cpp
===
--- test/SemaCXX/cxx11-crashes.cpp
+++ test/SemaCXX/cxx11-crashes.cpp
@@ -91,3 +91,10 @@
   Foo(lambda);
 }
 }
+
+namespace pr29091 {
+  struct X{ X(const X &x); };
+  struct Y: X { using X::X; };
+  bool foo() { return __has_nothrow_constructor(Y); }
+  bool bar() { return __has_nothrow_copy(Y); }
+}
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -4389,7 +4389,18 @@
 // resolution point.
 if (isa(ND))
   continue;
-const CXXConstructorDecl *Constructor = cast(ND);
+// UsingDecl itself is not a constructor
+if (isa(ND))
+  continue;
+const CXXConstructorDecl *Constructor = nullptr;
+if (auto *CSD = dyn_cast(ND)) {
+  Constructor = cast(CSD->getTargetDecl());
+  // Default constructor and copy/move constructor are not inherited.
+  if (Constructor->isDefaultConstructor() ||
+  Constructor->isCopyOrMoveConstructor())
+continue;
+} else
+  Constructor = cast(ND);
 if (Constructor->isCopyConstructor(FoundTQs)) {
   FoundConstructor = true;
   const FunctionProtoType *CPT
@@ -4425,7 +4436,18 @@
 // FIXME: In C++0x, a constructor template can be a default 
constructor.
 if (isa(ND))
   continue;
-const CXXConstructorDecl *Constructor = cast(ND);
+// UsingDecl itself is not a constructor
+if (isa(ND))
+  continue;
+const CXXConstructorDecl *Constructor = nullptr;
+if (auto *CSD = dyn_cast(ND)) {
+  Constructor = cast(CSD->getTargetDecl());
+  // Default constructor and copy/move constructor are not inherited.
+  if (Constructor->isDefaultConstructor() ||
+  Constructor->isCopyOrMoveConstructor())
+continue;
+} else
+  Constructor = cast(ND);
 if (Constructor->isDefaultConstructor()) {
   FoundConstructor = true;
   const FunctionProtoType *CPT


Index: test/SemaCXX/cxx11-crashes.cpp
===
--- test/SemaCXX/cxx11-crashes.cpp
+++ test/SemaCXX/cxx11-crashes.cpp
@@ -91,3 +91,10 @@
   Foo(lambda);
 }
 }
+
+namespace pr29091 {
+  struct X{ X(const X &x); };
+  struct Y: X { using X::X; };
+  bool foo() { return __has_nothrow_constructor(Y); }
+  bool bar() { return __has_nothrow_copy(Y); }
+}
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -4389,7 +4389,18 @@
 // resolution point.
 if (isa(ND))
   continue;
-const CXXConstructorDecl *Constructor = cast(ND);
+// UsingDecl itself is not a constructor
+if (isa(ND))
+  continue;
+const CXXConstructorDecl *Constructor = nullptr;
+if (auto *CSD = dyn_cast(ND)) {
+  Constructor = cast(CSD->getTargetDecl());
+  // Default constructor and copy/move constructor are not inherited.
+  if (Constructor->isDefaultConstructor() ||
+  Constructor->isCopyOrMoveConstructor())
+continue;
+} else
+  Constructor = cast(ND);
 if (Constructor->isCopyConstructor(FoundTQs)) {
   FoundConstructor = true;
   const FunctionProtoType *CPT
@@ -4425,7 +4436,18 @@
 // FIXME: In C++0x, a constructor template can be a default constructor.
 if (isa(ND))
   continue;
-const CXXConstructorDecl *Constructor = cast(ND);
+// UsingDecl itself is not a constructor
+if (isa(ND))
+  continue;
+const CXXConstructorDecl *Constructor = nullptr;
+if (auto *CSD = dyn_cast(ND)) {
+  Constructor = cast(CSD->getTargetDecl());
+  // Default constructor and copy/move constructor are not inherited.
+  if (Constructor->isDefaultConstructor() ||
+  Constructor->isCopyOrMoveConstructor())
+continue;
+} else
+  Constructor = cast(ND);
 if (Constructor->isDefaultConstructor()) {
   FoundConstructor = true;
   const FunctionProtoType *CPT
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r284836 - Remove unnecessary x86 backend requirements from OpenMP tests

2016-10-21 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Oct 21 11:09:20 2016
New Revision: 284836

URL: http://llvm.org/viewvc/llvm-project?rev=284836&view=rev
Log:
Remove unnecessary x86 backend requirements from OpenMP tests

Clang can generate LLVM IR for x86 without a registered x86 backend.

Modified:
cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp
cfe/trunk/test/OpenMP/atomic_update_codegen.cpp
cfe/trunk/test/OpenMP/barrier_codegen.cpp
cfe/trunk/test/OpenMP/cancel_codegen.cpp
cfe/trunk/test/OpenMP/cancellation_point_codegen.cpp
cfe/trunk/test/OpenMP/critical_codegen.cpp
cfe/trunk/test/OpenMP/declare_simd_codegen.cpp
cfe/trunk/test/OpenMP/flush_codegen.cpp
cfe/trunk/test/OpenMP/for_codegen.cpp
cfe/trunk/test/OpenMP/for_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/for_lastprivate_codegen.cpp
cfe/trunk/test/OpenMP/for_linear_codegen.cpp
cfe/trunk/test/OpenMP/for_private_codegen.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen.cpp
cfe/trunk/test/OpenMP/for_reduction_codegen_UDR.cpp
cfe/trunk/test/OpenMP/for_simd_codegen.cpp
cfe/trunk/test/OpenMP/master_codegen.cpp
cfe/trunk/test/OpenMP/ordered_codegen.cpp
cfe/trunk/test/OpenMP/ordered_doacross_codegen.cpp
cfe/trunk/test/OpenMP/parallel_codegen.cpp
cfe/trunk/test/OpenMP/parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/parallel_for_linear_codegen.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_codegen.cpp
cfe/trunk/test/OpenMP/parallel_private_codegen.cpp
cfe/trunk/test/OpenMP/parallel_reduction_codegen.cpp
cfe/trunk/test/OpenMP/parallel_sections_codegen.cpp
cfe/trunk/test/OpenMP/sections_codegen.cpp
cfe/trunk/test/OpenMP/sections_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/sections_lastprivate_codegen.cpp
cfe/trunk/test/OpenMP/sections_private_codegen.cpp
cfe/trunk/test/OpenMP/sections_reduction_codegen.cpp
cfe/trunk/test/OpenMP/simd_codegen.cpp
cfe/trunk/test/OpenMP/single_codegen.cpp
cfe/trunk/test/OpenMP/single_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/single_private_codegen.cpp
cfe/trunk/test/OpenMP/task_codegen.cpp
cfe/trunk/test/OpenMP/task_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/task_if_codegen.cpp
cfe/trunk/test/OpenMP/task_private_codegen.cpp
cfe/trunk/test/OpenMP/taskgroup_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_lastprivate_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_private_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_simd_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_simd_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_simd_lastprivate_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_simd_private_codegen.cpp
cfe/trunk/test/OpenMP/taskwait_codegen.cpp
cfe/trunk/test/OpenMP/taskyield_codegen.cpp
cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp
cfe/trunk/test/OpenMP/threadprivate_codegen.cpp

Modified: cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp?rev=284836&r1=284835&r2=284836&view=diff
==
--- cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/atomic_capture_codegen.cpp Fri Oct 21 11:09:20 2016
@@ -2,7 +2,6 @@
 // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -emit-pch -o %t 
%s
 // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s
 // expected-no-diagnostics
-// REQUIRES: x86-registered-target
 #ifndef HEADER
 #define HEADER
 

Modified: cfe/trunk/test/OpenMP/atomic_update_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/atomic_update_codegen.cpp?rev=284836&r1=284835&r2=284836&view=diff
==
--- cfe/trunk/test/OpenMP/atomic_update_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/atomic_update_codegen.cpp Fri Oct 21 11:09:20 2016
@@ -2,7 +2,6 @@
 // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -emit-pch -o %t 
%s
 // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s
 // expected-no-diagnostics
-// REQUIRES: x86-registered-target
 #ifndef HEADER
 #define HEADER
 

Modified: cfe/trunk/test/OpenMP/barrier_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/barrier_codegen.cpp?rev=284836&r1=284835&r2=284836&view=diff
==
--- cfe/trunk/test/OpenMP/barrier_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/barrier_codegen.cpp Fri Oct 21 11:09:20 2016
@@ -2,7 +2,6 @@
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-u

[PATCH] D25647: [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar updated this revision to Diff 75443.
jlebar marked 5 inline comments as done.
jlebar added a comment.

Adjust formatting, write out type of 'auto'.


https://reviews.llvm.org/D25647

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h


Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
@@ -31,7 +31,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void onEndOfTranslationUnit() override;
 
-  enum class SpecialMemberFunctionKind {
+  enum class SpecialMemberFunctionKind : uint8_t {
 Destructor,
 CopyConstructor,
 CopyAssignment,
@@ -43,7 +43,7 @@
 
   using ClassDefiningSpecialMembersMap =
   llvm::DenseMap>;
+ llvm::SmallVector>;
 
 private:
   ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -97,8 +97,13 @@
   {"move-assign", SpecialMemberFunctionKind::MoveAssignment}};
 
   for (const auto &KV : Matchers)
-if (Result.Nodes.getNodeAs(KV.first))
-  ClassWithSpecialMembers[ID].insert(KV.second);
+if (Result.Nodes.getNodeAs(KV.first)) {
+  SpecialMemberFunctionKind Kind = KV.second;
+  llvm::SmallVectorImpl &Members =
+  ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end())
+Members.push_back(Kind);
+}
 }
 
 void SpecialMemberFunctionsCheck::onEndOfTranslationUnit() {
@@ -125,7 +130,7 @@
 std::back_inserter(UndefinedSpecialMembers));
 
 diag(C.first.first, "class '%0' defines %1 but does not define %2")
-<< C.first.second << join(DefinedSpecialMembers.getArrayRef(), " and ")
+<< C.first.second << join(DefinedSpecialMembers, " and ")
 << join(UndefinedSpecialMembers, " or ");
   }
 }


Index: clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
@@ -31,7 +31,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void onEndOfTranslationUnit() override;
 
-  enum class SpecialMemberFunctionKind {
+  enum class SpecialMemberFunctionKind : uint8_t {
 Destructor,
 CopyConstructor,
 CopyAssignment,
@@ -43,7 +43,7 @@
 
   using ClassDefiningSpecialMembersMap =
   llvm::DenseMap>;
+ llvm::SmallVector>;
 
 private:
   ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -97,8 +97,13 @@
   {"move-assign", SpecialMemberFunctionKind::MoveAssignment}};
 
   for (const auto &KV : Matchers)
-if (Result.Nodes.getNodeAs(KV.first))
-  ClassWithSpecialMembers[ID].insert(KV.second);
+if (Result.Nodes.getNodeAs(KV.first)) {
+  SpecialMemberFunctionKind Kind = KV.second;
+  llvm::SmallVectorImpl &Members =
+  ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end())
+Members.push_back(Kind);
+}
 }
 
 void SpecialMemberFunctionsCheck::onEndOfTranslationUnit() {
@@ -125,7 +130,7 @@
 std::back_inserter(UndefinedSpecialMembers));
 
 diag(C.first.first, "class '%0' defines %1 but does not define %2")
-<< C.first.second << join(DefinedSpecialMembers.getArrayRef(), " and ")
+<< C.first.second << join(DefinedSpecialMembers, " and ")
 << join(UndefinedSpecialMembers, " or ");
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25647: [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp:103
+  auto &Members = ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end()) Members.push_back(Kind);
+}

jlebar wrote:
> bkramer wrote:
> > jlebar wrote:
> > > aaron.ballman wrote:
> > > > Please drop the `push_back()` onto its own line.
> > > This was actually how clang-tidy formatted the line.  My understanding is 
> > > that we go with that in llvm projects?  Unless you're saying I have an 
> > > outdated clang-tidy, in which case I will investigate that.
> > It's what happens when your clang-format is using Google style. Some 
> > versions of clang-format ship with weird defaults, so you have to add 
> > -style=LLVM manually.
> Er, s/clang-tidy/clang-format/
Oh, this is happening because clang-tools-extra does not have a .clang-format 
file in tree.  It's relying on us picking up clang's .clang-format file, but if 
you use the monorepo [0] (or if you have a tool that's smart and stops at git 
repository boundaries) you won't find it.

Mystery solved.  I can check those files in if you want, or not if you want.  :)

[0] https://github.com/llvm-project/llvm-project


https://reviews.llvm.org/D25647



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


[PATCH] D25844: [Sema][ObjC] Warn about implicitly autoreleasing indirect parameters that are captured by blocks

2016-10-21 Thread Akira Hatanaka via cfe-commits
ahatanak updated this revision to Diff 75442.
ahatanak marked an inline comment as done.
ahatanak added a comment.

Improve warning messages.


https://reviews.llvm.org/D25844

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/SemaObjC/arc.m


Index: test/SemaObjC/arc.m
===
--- test/SemaObjC/arc.m
+++ test/SemaObjC/arc.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak 
-fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak 
-fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class 
-Wblock-capture-autoreleasing %s
 
 typedef unsigned long NSUInteger;
 typedef const void * CFTypeRef;
@@ -808,3 +808,10 @@
   TKAssertEqual(object, nil);
   TKAssertEqual(object, (id)nil);
 }
+
+void block_capture_autoreleasing(A * __autoreleasing *a, A **b) { // 
expected-note {{declare the parameter __autoreleasing explicitly to suppress 
this warning}} expected-note {{declare the parameter __strong or capture a 
__block __strong variable to keep values alive across autorelease pools}}
+  ^{
+(void)*a;
+(void)*b; // expected-warning {{block captures an autoreleasing 
out-parameter, which may result in use-after-free bugs}}
+  }();
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13473,6 +13473,23 @@
 }
 return false;
   }
+
+  // Warn about implicitly autoreleasing indirect parameters captured by 
blocks.
+  if (auto *PT = dyn_cast(CaptureType)) {
+QualType PointeeTy = PT->getPointeeType();
+if (isa(PointeeTy.getCanonicalType()) &&
+PointeeTy.getObjCLifetime() == Qualifiers::OCL_Autoreleasing &&
+!isa(PointeeTy)) {
+  if (BuildAndDiagnose) {
+SourceLocation VarLoc = Var->getLocation();
+S.Diag(Loc, diag::warn_block_capture_autoreleasing);
+S.Diag(VarLoc, diag::note_declare_parameter_autoreleasing) <<
+FixItHint::CreateInsertion(VarLoc, "__autoreleasing");;
+S.Diag(VarLoc, diag::note_declare_parameter_strong);
+  }
+}
+  }
+
   const bool HasBlocksAttr = Var->hasAttr();
   if (HasBlocksAttr || CaptureType->isReferenceType() ||
   (S.getLangOpts().OpenMP && S.IsOpenMPCapturedDecl(Var))) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5073,6 +5073,16 @@
 
 } // end "ARC and @properties" category
 
+def warn_block_capture_autoreleasing : Warning<
+  "block captures an autoreleasing out-parameter, which may result in "
+  "use-after-free bugs">,
+  InGroup, DefaultIgnore;
+def note_declare_parameter_autoreleasing : Note<
+  "declare the parameter __autoreleasing explicitly to suppress this warning">;
+def note_declare_parameter_strong : Note<
+  "declare the parameter __strong or capture a __block __strong variable to "
+  "keep values alive across autorelease pools">;
+
 def err_arc_atomic_ownership : Error<
   "cannot perform atomic operation on a pointer to type %0: type has "
   "non-trivial ownership">;
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -498,6 +498,7 @@
 def ARCRepeatedUseOfWeakMaybe : DiagGroup<"arc-maybe-repeated-use-of-weak">;
 def ARCRepeatedUseOfWeak : DiagGroup<"arc-repeated-use-of-weak",
  [ARCRepeatedUseOfWeakMaybe]>;
+def BlockCaptureAutoReleasing : DiagGroup<"block-capture-autoreleasing">;
 def ObjCBridge : DiagGroup<"bridge-cast">;
 
 def DeallocInCategory:DiagGroup<"dealloc-in-category">;


Index: test/SemaObjC/arc.m
===
--- test/SemaObjC/arc.m
+++ test/SemaObjC/arc.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class -Wblock-capture-autoreleasing %s
 
 typedef unsigned long NSUInteger;
 typedef const void * CFTypeRef;
@@ -808,3 +808,10 @@
   TKAssertEqual(object, nil);
   TKAssertEqual(object, (id)nil);
 }
+
+void block_capture_autoreleasing(A * __autoreleasing *a, A **b) { // expected-note {{declare the parameter __autoreleasing explicitly to suppress this warning}} expected-note {{declare the parameter __strong or capture a __block __strong variable to keep values alive across autorelease pools}}
+  ^{
+(void)*a;
+(void)*b; // expected-warning {{block captures an 

[PATCH] D25866: [Sema] Support implicit scalar to vector conversions

2016-10-21 Thread Akira Hatanaka via cfe-commits
ahatanak added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:8044
   // the vector element type and splat.
-  // FIXME: this should also work for regular vector types as supported in GCC.
-  if (!RHSVecType && isa(LHSVecType)) {
+  if (!RHSVecType && isa(LHSVecType)) {
 if (!tryVectorConvertAndSplat(*this, &RHS, RHSType,

Is this the same as "!RHSVecType && LHSVecType" in this context?


https://reviews.llvm.org/D25866



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


[PATCH] D25796: [CUDA] Create __host__ and device variants of standard allocator declarations.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:2596
 
-  QualType FnType = Context.getFunctionType(Return, Params, EPI);
-  FunctionDecl *Alloc =
-FunctionDecl::Create(Context, GlobalCtx, SourceLocation(),
- SourceLocation(), Name,
- FnType, /*TInfo=*/nullptr, SC_None, false, true);
-  Alloc->setImplicit();
+  auto CreateAllocationFunctionDecl = [&]() {
+QualType FnType = Context.getFunctionType(Return, Params, EPI);

Nit, no need for empty parens.



Comment at: lib/Sema/SemaExprCXX.cpp:2622
   Context.getTranslationUnitDecl()->addDecl(Alloc);
   IdResolver.tryAddTopLevelDecl(Alloc, Name);
+

I kind of feel like it would be easier to add a boolean parameter to 
CreateAllocationFunctionDecl, then you don't need to repeat these two lines.


https://reviews.llvm.org/D25796



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


[PATCH] D25866: [Sema] Support implicit scalar to vector conversions

2016-10-21 Thread Akira Hatanaka via cfe-commits
ahatanak added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:8044
   // the vector element type and splat.
-  // FIXME: this should also work for regular vector types as supported in GCC.
-  if (!RHSVecType && isa(LHSVecType)) {
+  if (!RHSVecType && isa(LHSVecType)) {
 if (!tryVectorConvertAndSplat(*this, &RHS, RHSType,

ahatanak wrote:
> Is this the same as "!RHSVecType && LHSVecType" in this context?
Actually, LHS's type should be a vector here if RHS isn't a vector since 
CheckVectorOperands is called only when at least one operand is a vector.


https://reviews.llvm.org/D25866



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


[PATCH] D25731: [analyzer] NumberObjectConversion: Support OSNumber and CFNumberRef.

2016-10-21 Thread Anna Zaks via cfe-commits
zaks.anna added inline comments.



Comment at: test/Analysis/number-object-conversion.c:14
+  if (p) {} // expected-warning{{Converting 'CFNumberRef' to a plain boolean 
value for branching; please compare the pointer to NULL instead to suppress 
this warning}}
+  if (!p) {} // expected-warning{{Converting 'CFNumberRef' to a plain boolean 
value for branching; please compare the pointer to NULL instead to suppress 
this warning}}
+  p ? 1 : 2; // expected-warning{{Converting 'CFNumberRef' to a plain boolean 
value for branching; please compare the pointer to NULL instead to suppress 
this warning}}

NoQ wrote:
> zaks.anna wrote:
> > How about:
> > "Converting 'CFNumberRef' pointer to a plain boolean value; instead, 
> > compare the pointer to NULL or compare to the encapsulated scalar value"
> > 
> > - I've added "pointer".
> > - I would remove "for branching". Does it add anything?
> > - Also, we should remove "please" as it makes the warning text longer.
> > 
> > I would remove "for branching". Does it add anything?
> 
> Because there's otherwise no obvious boolean value around, i wanted to point 
> out what exactly is going on.
> 
> > or compare to the encapsulated scalar value
> 
> They don't necessarily compare the value. Maybe "take"?
> 
> > I've added "pointer".
> 
> Not sure it's worth keeping for other objects ("`'NSNumber *' pointer`" 
> sounds like a pointer to a pointer).
>> or compare to the encapsulated scalar value
> They don't necessarily compare the value. Maybe "take"?

OSBoolean or CFNumber:
[Comparing|Converting] a pointer value of type '[CFNumberRef|NSNumber *]' to a 
scalar [boolean|integer] value; instead, either compare the pointer to 
[NULL|nullptr|nil] or [call [APIName] | compare the result of calling [API 
Name]].

NSNumber or OSNumber:
Converting a pointer value of type '[NSNumber *]' to a scalar [boolean|integer] 
value; instead, either compare the pointer to [NULL|nullptr|nil] or call a 
method on '[NSNumber *]' to get the scalar value.

Comparing a pointer value of type '[NSNumber *]' to a scalar [boolean|integer] 
value; instead, either compare the pointer to [NULL|nullptr|nil] or call a 
method on '[NSNumber *]' to get the scalar value.




Comment at: test/Analysis/number-object-conversion.c:23
+#endif
+  if (p > 0) {} // expected-warning{{Converting 'CFNumberRef' pointer to a 
plain integer value; pointer value is being used instead}}
+  int x = p; // expected-warning{{Converting 'CFNumberRef' pointer to a plain 
integer value; pointer value is being used instead}}

Comparing a pointer value of type '[CFNumberRef|NSNumber *]' to a primitive 
[boolean|integer] value; did you mean to compare the result of calling [API 
Name].



Comment at: test/Analysis/number-object-conversion.cpp:32
+  p ? 1 : 2; // expected-warning{{Converting 'const class OSBoolean *' pointer 
to a branch condition; instead, compare the pointer to nullptr or take the 
encapsulated scalar value}}
+  (bool)p; // expected-warning{{Converting 'const class OSBoolean *' pointer 
to a plain bool value; instead, compare the pointer to nullptr or take the 
encapsulated scalar value}}
+#else

Converting a pointer value of type '[CFNumberRef|NSNumber *]' to a primitive 
[boolean|integer] value; did you mean to call [APIName].




Comment at: test/Analysis/number-object-conversion.cpp:41
+  x = p; // expected-warning{{Converting 'const class OSBoolean *' pointer to 
a plain bool value; pointer value is being used instead}}
+  takes_bool(p); // expected-warning{{Converting 'const class OSBoolean *' 
pointer to a plain bool value; pointer value is being used instead}}
   takes_bool(x); // no-warning

Same as cast.


https://reviews.llvm.org/D25731



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


[PATCH] D20811: [analyzer] Model some library functions

2016-10-21 Thread Artem Dergachev via cfe-commits
NoQ updated this revision to Diff 75446.
NoQ added a comment.
Herald added a subscriber: modocache.

Update the domain-specific language for function specs/summaries.


https://reviews.llvm.org/D20811

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  test/Analysis/std-c-library-functions.c
  test/Analysis/std-c-library-functions.cpp

Index: test/Analysis/std-c-library-functions.cpp
===
--- /dev/null
+++ test/Analysis/std-c-library-functions.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
+
+// Test that we don't model functions with broken prototypes.
+// Because they probably work differently as well.
+//
+// This test lives in a separate file because we wanted to test all functions
+// in the .c file, however in C there are no overloads.
+
+void clang_analyzer_eval(bool);
+bool isalpha(char);
+
+void test() {
+  clang_analyzer_eval(isalpha('A')); // no-crash // expected-warning{{UNKNOWN}}
+}
Index: test/Analysis/std-c-library-functions.c
===
--- /dev/null
+++ test/Analysis/std-c-library-functions.c
@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(int);
+
+int glob;
+
+typedef struct FILE FILE;
+#define EOF -1
+
+int getc(FILE *);
+void test_getc(FILE *fp) {
+  int x;
+  while ((x = getc(fp)) != EOF) {
+clang_analyzer_eval(x > 255); // expected-warning{{FALSE}}
+clang_analyzer_eval(x >= 0); // expected-warning{{TRUE}}
+  }
+}
+
+int fgetc(FILE *);
+void test_fgets(FILE *fp) {
+  clang_analyzer_eval(fgetc(fp) < 256); // expected-warning{{TRUE}}
+  clang_analyzer_eval(fgetc(fp) >= 0); // expected-warning{{UNKNOWN}}
+}
+
+
+typedef unsigned long size_t;
+typedef signed long ssize_t;
+ssize_t read(int, void *, size_t);
+ssize_t write(int, const void *, size_t);
+void test_read_write(int fd, char *buf) {
+  glob = 1;
+  ssize_t x = write(fd, buf, 10);
+  clang_analyzer_eval(glob); // expected-warning{{UNKNOWN}}
+  if (x >= 0) {
+clang_analyzer_eval(x <= 10); // expected-warning{{TRUE}}
+ssize_t y = read(fd, &glob, sizeof(glob));
+if (y >= 0) {
+  clang_analyzer_eval(y <= sizeof(glob)); // expected-warning{{TRUE}}
+} else {
+  // -1 overflows on promotion!
+  clang_analyzer_eval(y <= sizeof(glob)); // expected-warning{{FALSE}}
+}
+  } else {
+clang_analyzer_eval(x == -1); // expected-warning{{TRUE}}
+  }
+}
+
+size_t fread(void *, size_t, size_t, FILE *);
+size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
+void test_fread_fwrite(FILE *fp, int *buf) {
+  size_t x = fwrite(buf, sizeof(int), 10, fp);
+  clang_analyzer_eval(x <= 10); // expected-warning{{TRUE}}
+  size_t y = fread(buf, sizeof(int), 10, fp);
+  clang_analyzer_eval(y <= 10); // expected-warning{{TRUE}}
+  size_t z = fwrite(buf, sizeof(int), y, fp);
+  // FIXME: should be TRUE once symbol-symbol constraint support is improved.
+  clang_analyzer_eval(z <= y); // expected-warning{{UNKNOWN}}
+}
+
+ssize_t getline(char **, size_t *, FILE *);
+void test_getline(FILE *fp) {
+  char *line = 0;
+  size_t n = 0;
+  ssize_t len;
+  while ((len = getline(&line, &n, fp)) != -1) {
+clang_analyzer_eval(len == 0); // expected-warning{{FALSE}}
+  }
+}
+
+int isascii(int);
+void test_isascii(int x) {
+  clang_analyzer_eval(isascii(123)); // expected-warning{{TRUE}}
+  clang_analyzer_eval(isascii(-1)); // expected-warning{{FALSE}}
+  if (isascii(x)) {
+clang_analyzer_eval(x < 128); // expected-warning{{TRUE}}
+clang_analyzer_eval(x >= 0); // expected-warning{{TRUE}}
+  } else {
+if (x > 42)
+  clang_analyzer_eval(x >= 128); // expected-warning{{TRUE}}
+else
+  clang_analyzer_eval(x < 0); // expected-warning{{TRUE}}
+  }
+  glob = 1;
+  isascii('a');
+  clang_analyzer_eval(glob); // expected-warning{{TRUE}}
+}
+
+int islower(int);
+void test_islower(int x) {
+  clang_analyzer_eval(islower('x')); // expected-warning{{TRUE}}
+  clang_analyzer_eval(islower('X')); // expected-warning{{FALSE}}
+  if (islower(x))
+clang_analyzer_eval(x < 'a'); // expected-warning{{FALSE}}
+}
+
+int getchar(void);
+void test_getchar() {
+  int x = getchar();
+  if (x == EOF)
+return;
+  clang_analyzer_eval(x < 0); // expected-warning{{FALSE}}
+  clang_analyzer_eval(x < 256); // expected-warning{{TRUE}}
+}
+
+int isalpha(int);
+void test_isalpha() {
+  clang_analyzer_eval(isalpha(']')); // expected-warning{{FALSE}}
+  clang_analyzer_eval(isalpha('Q')); // expected-warning{{TRUE}}
+  clang_analyzer_eval(isalpha(128)); // expected-warning{{UNKNOWN}}
+}
+
+int isalnum(int);
+void test_alnum() {
+  clang_analyzer_eval(isalnum('1')); // expected-warning{{TRUE}}
+  clang_analyzer_eval(

r284843 - Removed unused function argument. NFC.

2016-10-21 Thread Artem Belevich via cfe-commits
Author: tra
Date: Fri Oct 21 12:15:46 2016
New Revision: 284843

URL: http://llvm.org/viewvc/llvm-project?rev=284843&view=rev
Log:
Removed unused function argument. NFC.

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCUDA.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=284843&r1=284842&r2=284843&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Oct 21 12:15:46 2016
@@ -9445,7 +9445,7 @@ public:
 
   /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD,
   /// depending on FD and the current compilation settings.
-  void maybeAddCUDAHostDeviceAttrs(Scope *S, FunctionDecl *FD,
+  void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD,
const LookupResult &Previous);
 
 public:

Modified: cfe/trunk/lib/Sema/SemaCUDA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCUDA.cpp?rev=284843&r1=284842&r2=284843&view=diff
==
--- cfe/trunk/lib/Sema/SemaCUDA.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp Fri Oct 21 12:15:46 2016
@@ -439,7 +439,7 @@ bool Sema::isEmptyCudaDestructor(SourceL
 // ForceCUDAHostDeviceDepth > 0 (corresponding to code within a
 //   #pragma clang force_cuda_host_device_begin/end
 // pair).
-void Sema::maybeAddCUDAHostDeviceAttrs(Scope *S, FunctionDecl *NewD,
+void Sema::maybeAddCUDAHostDeviceAttrs(FunctionDecl *NewD,
const LookupResult &Previous) {
   assert(getLangOpts().CUDA && "Should only be called during CUDA 
compilation");
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=284843&r1=284842&r2=284843&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Oct 21 12:15:46 2016
@@ -8264,7 +8264,7 @@ Sema::ActOnFunctionDeclarator(Scope *S,
   ProcessDeclAttributes(S, NewFD, D);
 
   if (getLangOpts().CUDA)
-maybeAddCUDAHostDeviceAttrs(S, NewFD, Previous);
+maybeAddCUDAHostDeviceAttrs(NewFD, Previous);
 
   if (getLangOpts().OpenCL) {
 // OpenCL v1.1 s6.5: Using an address space qualifier in a function return


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


[PATCH] D25839: Removed unused function argument. NFC.

2016-10-21 Thread Artem Belevich via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284843: Removed unused function argument. NFC. (authored by 
tra).

Changed prior to commit:
  https://reviews.llvm.org/D25839?vs=75339&id=75447#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25839

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaCUDA.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp


Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -9445,7 +9445,7 @@
 
   /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD,
   /// depending on FD and the current compilation settings.
-  void maybeAddCUDAHostDeviceAttrs(Scope *S, FunctionDecl *FD,
+  void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD,
const LookupResult &Previous);
 
 public:
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -8264,7 +8264,7 @@
   ProcessDeclAttributes(S, NewFD, D);
 
   if (getLangOpts().CUDA)
-maybeAddCUDAHostDeviceAttrs(S, NewFD, Previous);
+maybeAddCUDAHostDeviceAttrs(NewFD, Previous);
 
   if (getLangOpts().OpenCL) {
 // OpenCL v1.1 s6.5: Using an address space qualifier in a function return
Index: cfe/trunk/lib/Sema/SemaCUDA.cpp
===
--- cfe/trunk/lib/Sema/SemaCUDA.cpp
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp
@@ -439,7 +439,7 @@
 // ForceCUDAHostDeviceDepth > 0 (corresponding to code within a
 //   #pragma clang force_cuda_host_device_begin/end
 // pair).
-void Sema::maybeAddCUDAHostDeviceAttrs(Scope *S, FunctionDecl *NewD,
+void Sema::maybeAddCUDAHostDeviceAttrs(FunctionDecl *NewD,
const LookupResult &Previous) {
   assert(getLangOpts().CUDA && "Should only be called during CUDA 
compilation");
 


Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -9445,7 +9445,7 @@
 
   /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD,
   /// depending on FD and the current compilation settings.
-  void maybeAddCUDAHostDeviceAttrs(Scope *S, FunctionDecl *FD,
+  void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD,
const LookupResult &Previous);
 
 public:
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -8264,7 +8264,7 @@
   ProcessDeclAttributes(S, NewFD, D);
 
   if (getLangOpts().CUDA)
-maybeAddCUDAHostDeviceAttrs(S, NewFD, Previous);
+maybeAddCUDAHostDeviceAttrs(NewFD, Previous);
 
   if (getLangOpts().OpenCL) {
 // OpenCL v1.1 s6.5: Using an address space qualifier in a function return
Index: cfe/trunk/lib/Sema/SemaCUDA.cpp
===
--- cfe/trunk/lib/Sema/SemaCUDA.cpp
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp
@@ -439,7 +439,7 @@
 // ForceCUDAHostDeviceDepth > 0 (corresponding to code within a
 //   #pragma clang force_cuda_host_device_begin/end
 // pair).
-void Sema::maybeAddCUDAHostDeviceAttrs(Scope *S, FunctionDecl *NewD,
+void Sema::maybeAddCUDAHostDeviceAttrs(FunctionDecl *NewD,
const LookupResult &Previous) {
   assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes

2016-10-21 Thread Bob Haarman via cfe-commits
inglorion added a comment.

We also need https://reviews.llvm.org/D25578 in before this can land.


https://reviews.llvm.org/D25579



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


[PATCH] D20811: [analyzer] Model some library functions

2016-10-21 Thread Devin Coughlin via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.

This looks great!




Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:694
+INVALIDATION_APPROACH(EvalCallAsPure))
+  CASE // Is certainly uppercase.
+ARGUMENT_CONDITION(ARG_NO(0), WithinRange)

I think think this comment should say 'lowercase'.



Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:702
+  END_CASE
+  CASE // Is ascii but not uppercase.
+ARGUMENT_CONDITION(ARG_NO(0), WithinRange)

Same here.


https://reviews.llvm.org/D20811



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


Re: r284815 - Remove non-existing file from modulemap.

2016-10-21 Thread Bruno Cardoso Lopes via cfe-commits
Thanks Ben!

On Fri, Oct 21, 2016 at 3:19 AM, Benjamin Kramer via cfe-commits
 wrote:
> Author: d0k
> Date: Fri Oct 21 05:19:37 2016
> New Revision: 284815
>
> URL: http://llvm.org/viewvc/llvm-project?rev=284815&view=rev
> Log:
> Remove non-existing file from modulemap.
>
> This picked up a builtin header if it happened to be available.
>
> Modified:
> 
> cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap
>
> Modified: 
> cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap?rev=284815&r1=284814&r2=284815&view=diff
> ==
> --- 
> cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap
>  (original)
> +++ 
> cfe/trunk/test/Modules/Inputs/libc-libcxx/sysroot/usr/include/module.modulemap
>  Fri Oct 21 05:19:37 2016
> @@ -1,7 +1,6 @@
>  module libc [no_undeclared_includes] {
>module math { header "math.h" export * }
>module stdlib { header "stdlib.h" export * }
> -  module stdatomic { header "stdatomic.h" export * }
>module stddef { header "stddef.h" export * }
>module stdint { header "stdint.h" export * }
>module stdio { header "stdio.h" export * }
>
>
> ___
> 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


[PATCH] D24799: [XRay] Check in Clang whether XRay supports the target when -fxray-instrument is passed

2016-10-21 Thread Serge Rogatch via cfe-commits
rSerge updated this revision to Diff 75452.
rSerge added a comment.

I had to add the root directories `a` and `b` manually, as I couldn't find an 
`svn diff` argument for that.
The code file `Tools.cpp` was run via `clang-format`, then just my changes were 
copy-pasted.
2 tests have been added to enable both OS and CPU checking.
`const string` approach was leading to undefined behavior, because the lifetime 
of the string is shorter than the lifetime of the `const char *` array using 
its data. So I had to return to `const char* const`.


https://reviews.llvm.org/D24799

Files:
  lib/Driver/Tools.cpp
  test/Driver/XRay/lit.local.cfg
  test/Driver/XRay/xray-instrument-cpu.c
  test/Driver/XRay/xray-instrument-os.c


Index: test/Driver/XRay/xray-instrument-os.c
===
--- test/Driver/XRay/xray-instrument-os.c
+++ test/Driver/XRay/xray-instrument-os.c
@@ -0,0 +1,4 @@
+// RUN: not %clang -v -fxray-instrument -c %s
+// XFAIL: -linux-
+// REQUIRES-ANY: amd64, x86_64, x86_64h, arm
+typedef int a;
Index: test/Driver/XRay/xray-instrument-cpu.c
===
--- test/Driver/XRay/xray-instrument-cpu.c
+++ test/Driver/XRay/xray-instrument-cpu.c
@@ -0,0 +1,4 @@
+// RUN: not %clang -v -fxray-instrument -c %s
+// XFAIL: amd64-, x86_64-, x86_64h-, arm
+// REQUIRES: linux
+typedef int a;
Index: test/Driver/XRay/lit.local.cfg
===
--- test/Driver/XRay/lit.local.cfg
+++ test/Driver/XRay/lit.local.cfg
@@ -0,0 +1,2 @@
+target_triple_components = config.target_triple.split('-')
+config.available_features.update(target_triple_components)
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4804,7 +4804,16 @@
 
   if (Args.hasFlag(options::OPT_fxray_instrument,
options::OPT_fnoxray_instrument, false)) {
-CmdArgs.push_back("-fxray-instrument");
+const char *const XRayInstrumentOption = "-fxray-instrument";
+if (Triple.getOS() == llvm::Triple::Linux &&
+(Triple.getArch() == llvm::Triple::arm ||
+ Triple.getArch() == llvm::Triple::x86_64)) {
+  // Supported.
+} else {
+  D.Diag(diag::err_drv_clang_unsupported)
+  << (std::string(XRayInstrumentOption) + " on " + Triple.str());
+}
+CmdArgs.push_back(XRayInstrumentOption);
 if (const Arg *A =
 Args.getLastArg(options::OPT_fxray_instruction_threshold_,
 options::OPT_fxray_instruction_threshold_EQ)) {


Index: test/Driver/XRay/xray-instrument-os.c
===
--- test/Driver/XRay/xray-instrument-os.c
+++ test/Driver/XRay/xray-instrument-os.c
@@ -0,0 +1,4 @@
+// RUN: not %clang -v -fxray-instrument -c %s
+// XFAIL: -linux-
+// REQUIRES-ANY: amd64, x86_64, x86_64h, arm
+typedef int a;
Index: test/Driver/XRay/xray-instrument-cpu.c
===
--- test/Driver/XRay/xray-instrument-cpu.c
+++ test/Driver/XRay/xray-instrument-cpu.c
@@ -0,0 +1,4 @@
+// RUN: not %clang -v -fxray-instrument -c %s
+// XFAIL: amd64-, x86_64-, x86_64h-, arm
+// REQUIRES: linux
+typedef int a;
Index: test/Driver/XRay/lit.local.cfg
===
--- test/Driver/XRay/lit.local.cfg
+++ test/Driver/XRay/lit.local.cfg
@@ -0,0 +1,2 @@
+target_triple_components = config.target_triple.split('-')
+config.available_features.update(target_triple_components)
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4804,7 +4804,16 @@
 
   if (Args.hasFlag(options::OPT_fxray_instrument,
options::OPT_fnoxray_instrument, false)) {
-CmdArgs.push_back("-fxray-instrument");
+const char *const XRayInstrumentOption = "-fxray-instrument";
+if (Triple.getOS() == llvm::Triple::Linux &&
+(Triple.getArch() == llvm::Triple::arm ||
+ Triple.getArch() == llvm::Triple::x86_64)) {
+  // Supported.
+} else {
+  D.Diag(diag::err_drv_clang_unsupported)
+  << (std::string(XRayInstrumentOption) + " on " + Triple.str());
+}
+CmdArgs.push_back(XRayInstrumentOption);
 if (const Arg *A =
 Args.getLastArg(options::OPT_fxray_instruction_threshold_,
 options::OPT_fxray_instruction_threshold_EQ)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25845: [CUDA] Ignore implicit target attributes during function template instantiation.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added inline comments.



Comment at: test/SemaCUDA/function-template-overload.cu:62
+template  constexpr T overload_ce_implicit_hd(T a) { return a+1; }
+// expected-note@-1 3 {{candidate template ignored: target attributes do not 
match}}
+

Oh, I didn't know you could specify a count like this.  I have a bunch of tests 
to fix now!



Comment at: test/SemaCUDA/function-template-overload.cu:79
+template <> constexpr double overload_ce_implicit_hd(double a) { return a + 
3.0; };
+
 __host__ void hf() {

D25809's patch description says:

> [New behavior]: Require matching target attributes for explicit function 
> template instantiation/specialization and narrow [the] list of candidates to 
> templates with the same target.

Based on this, I do not see why most of the "these should work" candidates work.

Rather than explain here, can you please add a comment to the test?

(At some point someone is probably going to have to write down and make sense 
of all of the semantics we have invented.  It's going to be a pain either way, 
but at least we can preserve our reasoning in code rather than phab comments.)


https://reviews.llvm.org/D25845



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


[PATCH] D25876: [analyzer] Report CFNumberGetValue API misuse

2016-10-21 Thread Anna Zaks via cfe-commits
zaks.anna created this revision.
zaks.anna added reviewers: dcoughlin, NoQ.
zaks.anna added subscribers: cfe-commits, rgov.

This patch contains 2 improvements to the CFNumber checker:

- Checking of CFNumberGetValue misuse.
- Treating all CFNumber API misuse errors as non-fatal. (Previously we treated 
errors that could cause uninitialized memory as syncs and the truncation errors 
as non-fatal.)

This implements a subset of functionality from https://reviews.llvm.org/D17954.


https://reviews.llvm.org/D25876

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  test/Analysis/CFNumber.c

Index: test/Analysis/CFNumber.c
===
--- test/Analysis/CFNumber.c
+++ test/Analysis/CFNumber.c
@@ -13,21 +13,35 @@
kCFNumberMaxType = 16 };
 typedef CFIndex CFNumberType;
 typedef const struct __CFNumber * CFNumberRef;
+typedef unsigned char Boolean;
 extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
+Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
 
-CFNumberRef f1(unsigned char x) {
+__attribute__((cf_returns_retained)) CFNumberRef f1(unsigned char x) {
   return CFNumberCreate(0, kCFNumberSInt16Type, &x);  // expected-warning{{An 8 bit integer is used to initialize a CFNumber object that represents a 16 bit integer. 8 bits of the CFNumber value will be garbage}}
 }
 
 __attribute__((cf_returns_retained)) CFNumberRef f2(unsigned short x) {
-  return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{A 16 bit integer is used to initialize a CFNumber object that represents an 8 bit integer. 8 bits of the input integer will be lost}}
+  return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{A 16 bit integer is used to initialize a CFNumber object that represents an 8 bit integer. 8 bits of the integer value will be lost}}
 }
 
 // test that the attribute overrides the naming convention.
 __attribute__((cf_returns_not_retained)) CFNumberRef CreateNum(unsigned char x) {
   return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{leak}}
 }
 
-CFNumberRef f3(unsigned i) {
+__attribute__((cf_returns_retained)) CFNumberRef f3(unsigned i) {
   return CFNumberCreate(0, kCFNumberLongType, &i); // expected-warning{{A 32 bit integer is used to initialize a CFNumber object that represents a 64 bit integer}}
 }
+
+unsigned char getValueTest1(CFNumberRef x) {
+  unsigned char scalar = 0;
+  CFNumberGetValue(x, kCFNumberSInt16Type, &scalar);  // expected-warning{{A CFNumber object that represents a 16 bit integer is used to initialize an 8 bit integer. 8 bits of the CFNumber value will be lost}}
+  return scalar;
+}
+
+unsigned char getValueTest2(CFNumberRef x) {
+  unsigned short scalar = 0;
+  CFNumberGetValue(x, kCFNumberSInt8Type, &scalar);  // expected-warning{{A CFNumber object that represents an 8 bit integer is used to initialize a 16 bit integer. 8 bits of the integer value will be garbage}}
+  return scalar;
+}
Index: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
===
--- lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -336,15 +336,15 @@
 }
 
 //===--===//
-// Error reporting.
+// Checking for mismatched types passed to CFNumberCreate/CFNumberGetValue.
 //===--===//
 
 namespace {
-class CFNumberCreateChecker : public Checker< check::PreStmt > {
+class CFNumberChecker : public Checker< check::PreStmt > {
   mutable std::unique_ptr BT;
-  mutable IdentifierInfo* II;
+  mutable IdentifierInfo *ICreate, *IGetValue;
 public:
-  CFNumberCreateChecker() : II(nullptr) {}
+  CFNumberChecker() : ICreate(nullptr), IGetValue(nullptr) {}
 
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
@@ -425,18 +425,20 @@
 }
 #endif
 
-void CFNumberCreateChecker::checkPreStmt(const CallExpr *CE,
+void CFNumberChecker::checkPreStmt(const CallExpr *CE,
  CheckerContext &C) const {
   ProgramStateRef state = C.getState();
   const FunctionDecl *FD = C.getCalleeDecl(CE);
   if (!FD)
 return;
 
   ASTContext &Ctx = C.getASTContext();
-  if (!II)
-II = &Ctx.Idents.get("CFNumberCreate");
-
-  if (FD->getIdentifier() != II || CE->getNumArgs() != 3)
+  if (!ICreate) {
+ICreate = &Ctx.Idents.get("CFNumberCreate");
+IGetValue = &Ctx.Idents.get("CFNumberGetValue");
+  }
+  if (!(FD->getIdentifier() == ICreate || FD->getIdentifier() == IGetValue) ||
+  CE->getNumArgs() != 3)
 return;
 
   // Get the value of the "theType" argument.
@@ -450,13 +452,13 @@
 return;
 
   uint64_t NumberKind = V->getValue().getLimitedValue();
-  Option

r284856 - Remove move constructors that are identical to the generated default move ctor.

2016-10-21 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Fri Oct 21 13:55:07 2016
New Revision: 284856

URL: http://llvm.org/viewvc/llvm-project?rev=284856&view=rev
Log:
Remove move constructors that are identical to the generated default move ctor.

Modified:
cfe/trunk/include/clang/Analysis/Analyses/Consumed.h
cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/lib/Serialization/ASTReaderInternals.h

Modified: cfe/trunk/include/clang/Analysis/Analyses/Consumed.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/Consumed.h?rev=284856&r1=284855&r2=284856&view=diff
==
--- cfe/trunk/include/clang/Analysis/Analyses/Consumed.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/Consumed.h Fri Oct 21 13:55:07 
2016
@@ -201,11 +201,6 @@ namespace consumed {
 
   public:
 ConsumedBlockInfo() = default;
-ConsumedBlockInfo &operator=(ConsumedBlockInfo &&Other) {
-  StateMapsArray = std::move(Other.StateMapsArray);
-  VisitOrder = std::move(Other.VisitOrder);
-  return *this;
-}
 
 ConsumedBlockInfo(unsigned int NumBlocks, PostOrderCFGView *SortedGraph)
 : StateMapsArray(NumBlocks), VisitOrder(NumBlocks, 0) {

Modified: cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h?rev=284856&r1=284855&r2=284856&view=diff
==
--- cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/ThreadSafetyCommon.h Fri Oct 21 
13:55:07 2016
@@ -415,25 +415,8 @@ private:
 BlockInfo()
 : HasBackEdges(false), UnprocessedSuccessors(0),
   ProcessedPredecessors(0) {}
-BlockInfo(BlockInfo &&RHS)
-: ExitMap(std::move(RHS.ExitMap)),
-  HasBackEdges(RHS.HasBackEdges),
-  UnprocessedSuccessors(RHS.UnprocessedSuccessors),
-  ProcessedPredecessors(RHS.ProcessedPredecessors) {}
-
-BlockInfo &operator=(BlockInfo &&RHS) {
-  if (this != &RHS) {
-ExitMap = std::move(RHS.ExitMap);
-HasBackEdges = RHS.HasBackEdges;
-UnprocessedSuccessors = RHS.UnprocessedSuccessors;
-ProcessedPredecessors = RHS.ProcessedPredecessors;
-  }
-  return *this;
-}
-
-  private:
-BlockInfo(const BlockInfo &) = delete;
-void operator=(const BlockInfo &) = delete;
+BlockInfo(BlockInfo &&) = default;
+BlockInfo &operator=(BlockInfo &&) = default;
   };
 
   // We implement the CFGVisitor API

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=284856&r1=284855&r2=284856&view=diff
==
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Fri Oct 21 13:55:07 2016
@@ -432,9 +432,6 @@ private:
  bool PreambleEndsAtStartOfLine)
 : Buffer(Buffer), Owner(std::move(Owner)), Size(Size),
   PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {}
-ComputedPreamble(ComputedPreamble &&C)
-: Buffer(C.Buffer), Owner(std::move(C.Owner)), Size(C.Size),
-  PreambleEndsAtStartOfLine(C.PreambleEndsAtStartOfLine) {}
   };
   ComputedPreamble ComputePreamble(CompilerInvocation &Invocation,
unsigned MaxLines);

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=284856&r1=284855&r2=284856&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Oct 21 13:55:07 2016
@@ -350,14 +350,6 @@ class Preprocessor : public RefCountedBa
   ThePPLexer(std::move(ThePPLexer)),
   TheTokenLexer(std::move(TheTokenLexer)),
   TheDirLookup(std::move(TheDirLookup)) {}
-IncludeStackInfo(IncludeStackInfo &&RHS)
-: CurLexerKind(std::move(RHS.CurLexerKind)),
-  TheSubmodule(std::move(RHS.TheSubmodule)),
-  TheLexer(std::move(RHS.TheLexer)),
-  ThePTHLexer(std::move(RHS.ThePTHLexer)),
-  ThePPLexer(std::move(RHS.ThePPLexer)),
-  TheTokenLexer(std::move(RHS.TheTokenLexer)),
-  TheDirLookup(std::move(RHS.TheDirLookup)) {}
   };
   std::vector IncludeMacroStack;
 

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?r

[PATCH] D25796: [CUDA] Create __host__ and device variants of standard allocator declarations.

2016-10-21 Thread Artem Belevich via cfe-commits
tra updated this revision to Diff 75462.
tra added a comment.

Addressed jlebar's comments.


https://reviews.llvm.org/D25796

Files:
  lib/Sema/SemaExprCXX.cpp
  test/SemaCUDA/overloaded-delete.cu

Index: test/SemaCUDA/overloaded-delete.cu
===
--- test/SemaCUDA/overloaded-delete.cu
+++ test/SemaCUDA/overloaded-delete.cu
@@ -16,10 +16,54 @@
   delete s;
 }
 
+// Code should work with no explicit declarations/definitions of
+// allocator functions.
+__host__ __device__ void test_default_global_delete_hd(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+
+__device__ void test_default_global_delete(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+__host__ void test_default_global_delete(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+
+// It should work with only some of allocators (re-)declared.
+__device__ void operator delete(void *ptr);
+
+__host__ __device__ void test_partial_global_delete_hd(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+
+__device__ void test_partial_global_delete(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+__host__ void test_partial_global_delete(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+
+
+// We should be able to define both host and device variants.
 __host__ void operator delete(void *ptr) {}
 __device__ void operator delete(void *ptr) {}
 
-__host__ __device__ void test_global_delete(int *ptr) {
+__host__ __device__ void test_overloaded_global_delete_hd(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+
+__device__ void test_overloaded_global_delete(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+__host__ void test_overloaded_global_delete(int *ptr) {
   // Again, there should be no ambiguity between which operator delete we call.
   ::delete ptr;
 }
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2593,28 +2593,39 @@
 getLangOpts().CPlusPlus11 ? EST_BasicNoexcept : EST_DynamicNone;
   }
 
-  QualType FnType = Context.getFunctionType(Return, Params, EPI);
-  FunctionDecl *Alloc =
-FunctionDecl::Create(Context, GlobalCtx, SourceLocation(),
- SourceLocation(), Name,
- FnType, /*TInfo=*/nullptr, SC_None, false, true);
-  Alloc->setImplicit();
+  auto CreateAllocationFunctionDecl = [&](Attr *ExtraAttr) {
+QualType FnType = Context.getFunctionType(Return, Params, EPI);
+FunctionDecl *Alloc = FunctionDecl::Create(
+Context, GlobalCtx, SourceLocation(), SourceLocation(), Name,
+FnType, /*TInfo=*/nullptr, SC_None, false, true);
+Alloc->setImplicit();
 
-  // Implicit sized deallocation functions always have default visibility.
-  Alloc->addAttr(VisibilityAttr::CreateImplicit(Context,
-VisibilityAttr::Default));
+// Implicit sized deallocation functions always have default visibility.
+Alloc->addAttr(
+VisibilityAttr::CreateImplicit(Context, VisibilityAttr::Default));
 
-  llvm::SmallVector ParamDecls;
-  for (QualType T : Params) {
-ParamDecls.push_back(
-ParmVarDecl::Create(Context, Alloc, SourceLocation(), SourceLocation(),
-nullptr, T, /*TInfo=*/nullptr, SC_None, nullptr));
-ParamDecls.back()->setImplicit();
+llvm::SmallVector ParamDecls;
+for (QualType T : Params) {
+  ParamDecls.push_back(ParmVarDecl::Create(
+  Context, Alloc, SourceLocation(), SourceLocation(), nullptr, T,
+  /*TInfo=*/nullptr, SC_None, nullptr));
+  ParamDecls.back()->setImplicit();
+}
+Alloc->setParams(ParamDecls);
+if (ExtraAttr)
+  Alloc->addAttr(ExtraAttr);
+Context.getTranslationUnitDecl()->addDecl(Alloc);
+IdResolver.tryAddTopLevelDecl(Alloc, Name);
+  };
+
+  if (!LangOpts.CUDA)
+CreateAllocationFunctionDecl(nullptr);
+  else {
+// Host and device get their own declaration so each can be
+// defined or re-declared independently.
+CreateAllocationFunctionDecl(CUDAHostAttr::CreateImplicit(Context));
+CreateAllocationFunctionDecl(CUDADeviceAttr::CreateImplicit(Context));
   }
-  Alloc->setParams(ParamDecls);
-
-  Context.getTranslationUnitDecl()->addDecl(Alloc);
-  IdResolver.tryAddTopLevelDecl(Alloc, Name);
 }
 
 FunctionDecl *Sema::FindUsualDeallocationFunction(SourceLocation StartLoc,
___
cfe-commit

[clang-tools-extra] r284859 - [clang-move] Support moving template class forward declarations.

2016-10-21 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Oct 21 14:26:43 2016
New Revision: 284859

URL: http://llvm.org/viewvc/llvm-project?rev=284859&view=rev
Log:
[clang-move] Support moving template class forward declarations.

Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=284859&r1=284858&r2=284859&view=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Fri Oct 21 14:26:43 2016
@@ -406,8 +406,13 @@ void ClangMoveTool::run(const ast_matche
   } else if (const auto *FWD =
  Result.Nodes.getNodeAs("fwd_decl")) {
 // Skip all forwad declarations which appear after moved class declaration.
-if (RemovedDecls.empty())
-  MovedDecls.emplace_back(FWD, &Result.Context->getSourceManager());
+if (RemovedDecls.empty()) {
+  if (const auto *DCT = FWD->getDescribedClassTemplate()) {
+MovedDecls.emplace_back(DCT, &Result.Context->getSourceManager());
+  } else {
+MovedDecls.emplace_back(FWD, &Result.Context->getSourceManager());
+  }
+}
   } else if (const auto *ANS = Result.Nodes.getNodeAs(
  "anonymous_ns")) {
 MovedDecls.emplace_back(ANS, &Result.Context->getSourceManager());

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=284859&r1=284858&r2=284859&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Fri Oct 21 
14:26:43 2016
@@ -30,6 +30,7 @@ const char TestCCName[] = "foo.cc";
 
 const char TestHeader[] = "namespace a {\n"
   "class C1; // test\n"
+  "template  class C2;\n"
   "namespace b {\n"
   "// This is a Foo class\n"
   "// which is used in\n"
@@ -87,6 +88,7 @@ const char TestCC[] = "#include \"foo.h\
 
 const char ExpectedTestHeader[] = "namespace a {\n"
   "class C1; // test\n"
+  "template  class C2;\n"
   "namespace b {\n"
   "\n"
   "class Foo2 {\n"
@@ -127,6 +129,7 @@ const char ExpectedNewHeader[] = "#ifnde
  "#define NEW_FOO_H\n"
  "namespace a {\n"
  "class C1; // test\n"
+ "template  class C2;\n"
  "namespace b {\n"
  "// This is a Foo class\n"
  "// which is used in\n"


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


Re: [PATCH] D25199: [ubsan] Sanitize deleted pointers

2016-10-21 Thread Richard Smith via cfe-commits
On Tue, Oct 4, 2016 at 11:43 AM, Matt Gingell  wrote:

> Hi Richard,
>
> Thanks for your analysis.
>
> This patch is intended to mitigate use-after-free bugs. In that context a
> “define strict behavior for invalid pointer values” we could deploy in
> production code would be very useful. Maybe calling this a sanitizer is
> misleading, and instead it could be presented as “change implementation
> defined behavior to be less convenient but more security friendly."


OK, but you still need to address points #1-#3 of my email, which show
things that go wrong with this patch if you interpret it in that way. Point
#3 seems especially problematic. You can't store through the pointer before
the destructor runs, because the destructor is permitted to look at the
pointer, and you can't store through the pointer *after* the destructor
runs, because the destructor might have (say) deallocated the memory
containing the pointer.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25796: [CUDA] Create __host__ and device variants of standard allocator declarations.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar accepted this revision.
jlebar added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Sema/SemaExprCXX.cpp:2596
 
-  QualType FnType = Context.getFunctionType(Return, Params, EPI);
-  FunctionDecl *Alloc =
-FunctionDecl::Create(Context, GlobalCtx, SourceLocation(),
- SourceLocation(), Name,
- FnType, /*TInfo=*/nullptr, SC_None, false, true);
-  Alloc->setImplicit();
+  auto CreateAllocationFunctionDecl = [&](Attr *ExtraAttr) {
+QualType FnType = Context.getFunctionType(Return, Params, EPI);

Oh, I like this way better than a bool arg.


https://reviews.llvm.org/D25796



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


[PATCH] D25876: [analyzer] Report CFNumberGetValue API misuse

2016-10-21 Thread Devin Coughlin via cfe-commits
dcoughlin added inline comments.



Comment at: test/Analysis/CFNumber.c:39
+  unsigned char scalar = 0;
+  CFNumberGetValue(x, kCFNumberSInt16Type, &scalar);  // expected-warning{{A 
CFNumber object that represents a 16 bit integer is used to initialize an 8 bit 
integer. 8 bits of the CFNumber value will be lost}}
+  return scalar;

I feel like this diagnostic is not dire enough. The problem is not that the 
bits will be lost -- but rather that they will be overwritten on top of 
something else!

How about something like "The remaining 8 bits will overwrite adjacent 
storage."?



Comment at: test/Analysis/CFNumber.c:45
+  unsigned short scalar = 0;
+  CFNumberGetValue(x, kCFNumberSInt8Type, &scalar);  // expected-warning{{A 
CFNumber object that represents an 8 bit integer is used to initialize a 16 bit 
integer. 8 bits of the integer value will be garbage}}
+  return scalar;

Some grammar/style nits. (I realize these also hold for the pre-existing 
checks):

- There should be a dash between the number and 'bit'. That is, it should be 
"16-bit" and "8-bit".
- It is generally considered bad style to start a sentence with a number that 
is not written out (except for dates). How about starting the second sentence 
with "The remaining 8 bits ..."?


https://reviews.llvm.org/D25876



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


r284869 - [CUDA] Use FunctionDeclAndLoc for the Sema::LocsWithCUDACallDiags hashtable.

2016-10-21 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Fri Oct 21 15:08:52 2016
New Revision: 284869

URL: http://llvm.org/viewvc/llvm-project?rev=284869&view=rev
Log:
[CUDA] Use FunctionDeclAndLoc for the Sema::LocsWithCUDACallDiags hashtable.

Summary: NFC

Reviewers: rnk

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCUDA.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=284869&r1=284868&r2=284869&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Oct 21 15:08:52 2016
@@ -9250,18 +9250,18 @@ public:
  std::vector>
   CUDADeferredDiags;
 
-  /// FunctionDecls plus raw encodings of SourceLocations for which
-  /// CheckCUDACall has emitted a (maybe deferred) "bad call" diagnostic.  We
-  /// use this to avoid emitting the same deferred diag twice.
-  llvm::DenseSet, unsigned>>
-  LocsWithCUDACallDiags;
-
-  /// A pair of a canonical FunctionDecl and a SourceLocation.
+  /// A pair of a canonical FunctionDecl and a SourceLocation.  When used as 
the
+  /// key in a hashtable, both the FD and location are hashed.
   struct FunctionDeclAndLoc {
 CanonicalDeclPtr FD;
 SourceLocation Loc;
   };
 
+  /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a
+  /// (maybe deferred) "bad call" diagnostic.  We use this to avoid emitting 
the
+  /// same deferred diag twice.
+  llvm::DenseSet LocsWithCUDACallDiags;
+
   /// An inverse call graph, mapping known-emitted functions to one of their
   /// known-emitted callers (plus the location of the call).
   ///
@@ -10035,4 +10035,31 @@ struct LateParsedTemplate {
 
 } // end namespace clang
 
+namespace llvm {
+// Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its
+// SourceLocation.
+template <> struct DenseMapInfo {
+  using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc;
+  using FDBaseInfo = 
DenseMapInfo>;
+
+  static FunctionDeclAndLoc getEmptyKey() {
+return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()};
+  }
+
+  static FunctionDeclAndLoc getTombstoneKey() {
+return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()};
+  }
+
+  static unsigned getHashValue(const FunctionDeclAndLoc &FDL) {
+return hash_combine(FDBaseInfo::getHashValue(FDL.FD),
+FDL.Loc.getRawEncoding());
+  }
+
+  static bool isEqual(const FunctionDeclAndLoc &LHS,
+  const FunctionDeclAndLoc &RHS) {
+return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc;
+  }
+};
+} // namespace llvm
+
 #endif

Modified: cfe/trunk/lib/Sema/SemaCUDA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCUDA.cpp?rev=284869&r1=284868&r2=284869&view=diff
==
--- cfe/trunk/lib/Sema/SemaCUDA.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp Fri Oct 21 15:08:52 2016
@@ -774,7 +774,7 @@ bool Sema::CheckCUDACall(SourceLocation
   // like this is unfortunate, but because we must continue parsing as normal
   // after encountering a deferred error, it's otherwise very tricky for us to
   // ensure that we only emit this deferred error once.
-  if (!LocsWithCUDACallDiags.insert({Caller, Loc.getRawEncoding()}).second)
+  if (!LocsWithCUDACallDiags.insert({Caller, Loc}).second)
 return true;
 
   CUDADiagBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller, *this)


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


[PATCH] D25797: [CUDA] Use FunctionDeclAndLoc for the Sema::LocsWithCUDACallDiags hashtable.

2016-10-21 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284869: [CUDA] Use FunctionDeclAndLoc for the 
Sema::LocsWithCUDACallDiags hashtable. (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D25797?vs=75231&id=75474#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25797

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaCUDA.cpp


Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -9250,18 +9250,18 @@
  std::vector>
   CUDADeferredDiags;
 
-  /// FunctionDecls plus raw encodings of SourceLocations for which
-  /// CheckCUDACall has emitted a (maybe deferred) "bad call" diagnostic.  We
-  /// use this to avoid emitting the same deferred diag twice.
-  llvm::DenseSet, unsigned>>
-  LocsWithCUDACallDiags;
-
-  /// A pair of a canonical FunctionDecl and a SourceLocation.
+  /// A pair of a canonical FunctionDecl and a SourceLocation.  When used as 
the
+  /// key in a hashtable, both the FD and location are hashed.
   struct FunctionDeclAndLoc {
 CanonicalDeclPtr FD;
 SourceLocation Loc;
   };
 
+  /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a
+  /// (maybe deferred) "bad call" diagnostic.  We use this to avoid emitting 
the
+  /// same deferred diag twice.
+  llvm::DenseSet LocsWithCUDACallDiags;
+
   /// An inverse call graph, mapping known-emitted functions to one of their
   /// known-emitted callers (plus the location of the call).
   ///
@@ -10035,4 +10035,31 @@
 
 } // end namespace clang
 
+namespace llvm {
+// Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its
+// SourceLocation.
+template <> struct DenseMapInfo {
+  using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc;
+  using FDBaseInfo = 
DenseMapInfo>;
+
+  static FunctionDeclAndLoc getEmptyKey() {
+return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()};
+  }
+
+  static FunctionDeclAndLoc getTombstoneKey() {
+return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()};
+  }
+
+  static unsigned getHashValue(const FunctionDeclAndLoc &FDL) {
+return hash_combine(FDBaseInfo::getHashValue(FDL.FD),
+FDL.Loc.getRawEncoding());
+  }
+
+  static bool isEqual(const FunctionDeclAndLoc &LHS,
+  const FunctionDeclAndLoc &RHS) {
+return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc;
+  }
+};
+} // namespace llvm
+
 #endif
Index: cfe/trunk/lib/Sema/SemaCUDA.cpp
===
--- cfe/trunk/lib/Sema/SemaCUDA.cpp
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp
@@ -774,7 +774,7 @@
   // like this is unfortunate, but because we must continue parsing as normal
   // after encountering a deferred error, it's otherwise very tricky for us to
   // ensure that we only emit this deferred error once.
-  if (!LocsWithCUDACallDiags.insert({Caller, Loc.getRawEncoding()}).second)
+  if (!LocsWithCUDACallDiags.insert({Caller, Loc}).second)
 return true;
 
   CUDADiagBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller, *this)


Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -9250,18 +9250,18 @@
  std::vector>
   CUDADeferredDiags;
 
-  /// FunctionDecls plus raw encodings of SourceLocations for which
-  /// CheckCUDACall has emitted a (maybe deferred) "bad call" diagnostic.  We
-  /// use this to avoid emitting the same deferred diag twice.
-  llvm::DenseSet, unsigned>>
-  LocsWithCUDACallDiags;
-
-  /// A pair of a canonical FunctionDecl and a SourceLocation.
+  /// A pair of a canonical FunctionDecl and a SourceLocation.  When used as the
+  /// key in a hashtable, both the FD and location are hashed.
   struct FunctionDeclAndLoc {
 CanonicalDeclPtr FD;
 SourceLocation Loc;
   };
 
+  /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a
+  /// (maybe deferred) "bad call" diagnostic.  We use this to avoid emitting the
+  /// same deferred diag twice.
+  llvm::DenseSet LocsWithCUDACallDiags;
+
   /// An inverse call graph, mapping known-emitted functions to one of their
   /// known-emitted callers (plus the location of the call).
   ///
@@ -10035,4 +10035,31 @@
 
 } // end namespace clang
 
+namespace llvm {
+// Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its
+// SourceLocation.
+template <> struct DenseMapInfo {
+  using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc;
+  using FDBaseInfo = DenseMapInfo>;
+
+  static FunctionDeclAndLoc getEmptyKey() {
+return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()};
+  }
+
+  static FunctionDeclAndLoc getTombstoneKey() {
+return {FDBaseInfo::getTombstoneKey(), clang::SourceL

[clang-tools-extra] r284873 - [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Fri Oct 21 15:13:39 2016
New Revision: 284873

URL: http://llvm.org/viewvc/llvm-project?rev=284873&view=rev
Log:
[clang-tidy] Don't use a SmallSetVector of an enum.

Summary:
This doesn't work after converting SmallSetVector to use DenseSet.

Instead we can just use a SmallVector.

Reviewers: timshen

Subscribers: nemanjai, cfe-commits

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

Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp?rev=284873&r1=284872&r2=284873&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
 Fri Oct 21 15:13:39 2016
@@ -97,8 +97,13 @@ void SpecialMemberFunctionsCheck::check(
   {"move-assign", SpecialMemberFunctionKind::MoveAssignment}};
 
   for (const auto &KV : Matchers)
-if (Result.Nodes.getNodeAs(KV.first))
-  ClassWithSpecialMembers[ID].insert(KV.second);
+if (Result.Nodes.getNodeAs(KV.first)) {
+  SpecialMemberFunctionKind Kind = KV.second;
+  llvm::SmallVectorImpl &Members =
+  ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end())
+Members.push_back(Kind);
+}
 }
 
 void SpecialMemberFunctionsCheck::onEndOfTranslationUnit() {
@@ -125,7 +130,7 @@ void SpecialMemberFunctionsCheck::onEndO
 std::back_inserter(UndefinedSpecialMembers));
 
 diag(C.first.first, "class '%0' defines %1 but does not define %2")
-<< C.first.second << join(DefinedSpecialMembers.getArrayRef(), " and ")
+<< C.first.second << join(DefinedSpecialMembers, " and ")
 << join(UndefinedSpecialMembers, " or ");
   }
 }

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h?rev=284873&r1=284872&r2=284873&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
 Fri Oct 21 15:13:39 2016
@@ -31,7 +31,7 @@ public:
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void onEndOfTranslationUnit() override;
 
-  enum class SpecialMemberFunctionKind {
+  enum class SpecialMemberFunctionKind : uint8_t {
 Destructor,
 CopyConstructor,
 CopyAssignment,
@@ -43,7 +43,7 @@ public:
 
   using ClassDefiningSpecialMembersMap =
   llvm::DenseMap>;
+ llvm::SmallVector>;
 
 private:
   ClassDefiningSpecialMembersMap ClassWithSpecialMembers;


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


[PATCH] D25647: [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284873: [clang-tidy] Don't use a SmallSetVector of an enum. 
(authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D25647?vs=75443&id=75478#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25647

Files:
  
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
  
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h


Index: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
===
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
@@ -31,7 +31,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void onEndOfTranslationUnit() override;
 
-  enum class SpecialMemberFunctionKind {
+  enum class SpecialMemberFunctionKind : uint8_t {
 Destructor,
 CopyConstructor,
 CopyAssignment,
@@ -43,7 +43,7 @@
 
   using ClassDefiningSpecialMembersMap =
   llvm::DenseMap>;
+ llvm::SmallVector>;
 
 private:
   ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
Index: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
===
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -97,8 +97,13 @@
   {"move-assign", SpecialMemberFunctionKind::MoveAssignment}};
 
   for (const auto &KV : Matchers)
-if (Result.Nodes.getNodeAs(KV.first))
-  ClassWithSpecialMembers[ID].insert(KV.second);
+if (Result.Nodes.getNodeAs(KV.first)) {
+  SpecialMemberFunctionKind Kind = KV.second;
+  llvm::SmallVectorImpl &Members =
+  ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end())
+Members.push_back(Kind);
+}
 }
 
 void SpecialMemberFunctionsCheck::onEndOfTranslationUnit() {
@@ -125,7 +130,7 @@
 std::back_inserter(UndefinedSpecialMembers));
 
 diag(C.first.first, "class '%0' defines %1 but does not define %2")
-<< C.first.second << join(DefinedSpecialMembers.getArrayRef(), " and ")
+<< C.first.second << join(DefinedSpecialMembers, " and ")
 << join(UndefinedSpecialMembers, " or ");
   }
 }


Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
@@ -31,7 +31,7 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void onEndOfTranslationUnit() override;
 
-  enum class SpecialMemberFunctionKind {
+  enum class SpecialMemberFunctionKind : uint8_t {
 Destructor,
 CopyConstructor,
 CopyAssignment,
@@ -43,7 +43,7 @@
 
   using ClassDefiningSpecialMembersMap =
   llvm::DenseMap>;
+ llvm::SmallVector>;
 
 private:
   ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -97,8 +97,13 @@
   {"move-assign", SpecialMemberFunctionKind::MoveAssignment}};
 
   for (const auto &KV : Matchers)
-if (Result.Nodes.getNodeAs(KV.first))
-  ClassWithSpecialMembers[ID].insert(KV.second);
+if (Result.Nodes.getNodeAs(KV.first)) {
+  SpecialMemberFunctionKind Kind = KV.second;
+  llvm::SmallVectorImpl &Members =
+  ClassWithSpecialMembers[ID];
+  if (find(Members, Kind) == Members.end())
+Members.push_back(Kind);
+}
 }
 
 void SpecialMemberFunctionsCheck::onEndOfTranslationUnit() {
@@ -125,7 +130,7 @@
 std::back_inserter(UndefinedSpecialMembers));
 
 diag(C.first.first, "class '%0' defines %1 but does not define %2")
-<< C.first.second << join(DefinedSpecialMembers.getArrayRef(), " and ")
+<< C.first.second << join(DefinedSpecialMembers, " and ")
 << join(UndefinedSpecialMembers, " or ");
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25647: [clang-tidy] Don't use a SmallSetVector of an enum.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added a comment.

Thank you for the reviews, everyone!


Repository:
  rL LLVM

https://reviews.llvm.org/D25647



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


r284877 - Remove accidentally checked in assert.

2016-10-21 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Fri Oct 21 15:30:30 2016
New Revision: 284877

URL: http://llvm.org/viewvc/llvm-project?rev=284877&view=rev
Log:
Remove accidentally checked in assert.

Thanks to Manman for spotting this.

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

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=284877&r1=284876&r2=284877&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Oct 21 15:30:30 2016
@@ -10124,9 +10124,6 @@ void Sema::ActOnUninitializedDecl(Decl *
 // member.
 if (Var->isConstexpr() && !Var->isThisDeclarationADefinition() &&
 !Var->isThisDeclarationADemotedDefinition()) {
-  assert((!Var->isThisDeclarationADemotedDefinition() ||
-  getLangOpts().Modules) &&
- "Demoting decls is only in the contest of modules!");
   if (Var->isStaticDataMember()) {
 // C++1z removes the relevant rule; the in-class declaration is always
 // a definition there.


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


Re: r284577 - [modules] Do not report missing definitions of demoted constexpr variable templates.

2016-10-21 Thread Vassil Vassilev via cfe-commits

On 21/10/16 00:19, Manman wrote:

On Oct 19, 2016, at 4:19 AM, Vassil Vassilev via cfe-commits 
 wrote:

Author: vvassilev
Date: Wed Oct 19 06:19:30 2016
New Revision: 284577

URL: http://llvm.org/viewvc/llvm-project?rev=284577&view=rev
Log:
[modules] Do not report missing definitions of demoted constexpr variable 
templates.

This is a followup to regression introduced in r284284.

This should fix our libstdc++ modules builds.

https://reviews.llvm.org/D25678

Reviewed by Richard Smith!

Added:
cfe/trunk/test/Modules/Inputs/merge-var-template-def/a.h
cfe/trunk/test/Modules/Inputs/merge-var-template-def/b1.h
cfe/trunk/test/Modules/Inputs/merge-var-template-def/b2.h
cfe/trunk/test/Modules/Inputs/merge-var-template-def/module.modulemap
cfe/trunk/test/Modules/merge-var-template-def.cpp
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=284577&r1=284576&r2=284577&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Oct 19 06:19:30 2016
@@ -10124,7 +10124,11 @@ void Sema::ActOnUninitializedDecl(Decl *
 // C++11 [dcl.constexpr]p1: The constexpr specifier shall be applied only 
to
 // the definition of a variable [...] or the declaration of a static data
 // member.
-if (Var->isConstexpr() && !Var->isThisDeclarationADefinition()) {
+if (Var->isConstexpr() && !Var->isThisDeclarationADefinition() &&
+!Var->isThisDeclarationADemotedDefinition()) {
+  assert((!Var->isThisDeclarationADemotedDefinition() ||
+  getLangOpts().Modules) &&
+ "Demoting decls is only in the contest of modules!”);

Just noticed the mismatch between this commit and the last reviewed patch :]
The assert is still here.

Good catch! Done in r284877.


Manman


   if (Var->isStaticDataMember()) {
 // C++1z removes the relevant rule; the in-class declaration is always
 // a definition there.

Added: cfe/trunk/test/Modules/Inputs/merge-var-template-def/a.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-var-template-def/a.h?rev=284577&view=auto
==
--- cfe/trunk/test/Modules/Inputs/merge-var-template-def/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-var-template-def/a.h Wed Oct 19 
06:19:30 2016
@@ -0,0 +1,8 @@
+#ifndef A_H
+#define A_H
+template
+struct S { static constexpr T value = v; };
+template
+constexpr T S::value;
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/merge-var-template-def/b1.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-var-template-def/b1.h?rev=284577&view=auto
==
--- cfe/trunk/test/Modules/Inputs/merge-var-template-def/b1.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-var-template-def/b1.h Wed Oct 19 
06:19:30 2016
@@ -0,0 +1,9 @@
+#ifndef B1_H
+#define B1_H
+template
+struct S { static constexpr T value = v; };
+template
+constexpr T S::value;
+
+#include "a.h"
+#endif

Added: cfe/trunk/test/Modules/Inputs/merge-var-template-def/b2.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-var-template-def/b2.h?rev=284577&view=auto
==
--- cfe/trunk/test/Modules/Inputs/merge-var-template-def/b2.h (added)
+++ cfe/trunk/test/Modules/Inputs/merge-var-template-def/b2.h Wed Oct 19 
06:19:30 2016
@@ -0,0 +1,9 @@
+#ifndef B2_H
+#define B2_H
+
+template
+struct S { static constexpr T value = v; };
+template
+constexpr T S::value;
+
+#endif

Added: cfe/trunk/test/Modules/Inputs/merge-var-template-def/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-var-template-def/module.modulemap?rev=284577&view=auto
==
--- cfe/trunk/test/Modules/Inputs/merge-var-template-def/module.modulemap 
(added)
+++ cfe/trunk/test/Modules/Inputs/merge-var-template-def/module.modulemap Wed 
Oct 19 06:19:30 2016
@@ -0,0 +1,5 @@
+module a { header "a.h" export * }
+module b {
+  module b1 { header "b1.h" export * }
+  module b2 { header "b2.h" export * }
+}

Added: cfe/trunk/test/Modules/merge-var-template-def.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-var-template-def.cpp?rev=284577&view=auto
==
--- cfe/trunk/test/Modules/merge-var-template-def.cpp (added)
+++ cfe/trunk/test/Modules/merge-var-template-def.cpp Wed Oct 19 06:19:30 2016
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -I%S/Inputs/merge-var-template-def -std=c++11 -verify %s
+// RUN: %clang_cc1 -I%S/Inputs/merge-var-template

[PATCH] D25845: [CUDA] Ignore implicit target attributes during function template instantiation.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added a comment.

> This patch changes the way we match target attributes of base template vs 
> attributes used in explicit instantiation or specialization so that only 
> explicitly specified attributes are considered.

Another question about this: When we have something inside of the 
force-host-device pragma, the HD attributes it gets are implicit.

This means that the only way to specialize something inside one of these 
pragmas is to use the pragma around the specialization?  That...seems weird?


https://reviews.llvm.org/D25845



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


r284879 - Declare H and H new/delete.

2016-10-21 Thread Artem Belevich via cfe-commits
Author: tra
Date: Fri Oct 21 15:34:05 2016
New Revision: 284879

URL: http://llvm.org/viewvc/llvm-project?rev=284879&view=rev
Log:
Declare H and H new/delete.

Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCUDA/overloaded-delete.cu

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=284879&r1=284878&r2=284879&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Oct 21 15:34:05 2016
@@ -2593,28 +2593,39 @@ void Sema::DeclareGlobalAllocationFuncti
 getLangOpts().CPlusPlus11 ? EST_BasicNoexcept : EST_DynamicNone;
   }
 
-  QualType FnType = Context.getFunctionType(Return, Params, EPI);
-  FunctionDecl *Alloc =
-FunctionDecl::Create(Context, GlobalCtx, SourceLocation(),
- SourceLocation(), Name,
- FnType, /*TInfo=*/nullptr, SC_None, false, true);
-  Alloc->setImplicit();
+  auto CreateAllocationFunctionDecl = [&](Attr *ExtraAttr) {
+QualType FnType = Context.getFunctionType(Return, Params, EPI);
+FunctionDecl *Alloc = FunctionDecl::Create(
+Context, GlobalCtx, SourceLocation(), SourceLocation(), Name,
+FnType, /*TInfo=*/nullptr, SC_None, false, true);
+Alloc->setImplicit();
 
-  // Implicit sized deallocation functions always have default visibility.
-  Alloc->addAttr(VisibilityAttr::CreateImplicit(Context,
-VisibilityAttr::Default));
+// Implicit sized deallocation functions always have default visibility.
+Alloc->addAttr(
+VisibilityAttr::CreateImplicit(Context, VisibilityAttr::Default));
 
-  llvm::SmallVector ParamDecls;
-  for (QualType T : Params) {
-ParamDecls.push_back(
-ParmVarDecl::Create(Context, Alloc, SourceLocation(), SourceLocation(),
-nullptr, T, /*TInfo=*/nullptr, SC_None, nullptr));
-ParamDecls.back()->setImplicit();
-  }
-  Alloc->setParams(ParamDecls);
+llvm::SmallVector ParamDecls;
+for (QualType T : Params) {
+  ParamDecls.push_back(ParmVarDecl::Create(
+  Context, Alloc, SourceLocation(), SourceLocation(), nullptr, T,
+  /*TInfo=*/nullptr, SC_None, nullptr));
+  ParamDecls.back()->setImplicit();
+}
+Alloc->setParams(ParamDecls);
+if (ExtraAttr)
+  Alloc->addAttr(ExtraAttr);
+Context.getTranslationUnitDecl()->addDecl(Alloc);
+IdResolver.tryAddTopLevelDecl(Alloc, Name);
+  };
 
-  Context.getTranslationUnitDecl()->addDecl(Alloc);
-  IdResolver.tryAddTopLevelDecl(Alloc, Name);
+  if (!LangOpts.CUDA)
+CreateAllocationFunctionDecl(nullptr);
+  else {
+// Host and device get their own declaration so each can be
+// defined or re-declared independently.
+CreateAllocationFunctionDecl(CUDAHostAttr::CreateImplicit(Context));
+CreateAllocationFunctionDecl(CUDADeviceAttr::CreateImplicit(Context));
+  }
 }
 
 FunctionDecl *Sema::FindUsualDeallocationFunction(SourceLocation StartLoc,

Modified: cfe/trunk/test/SemaCUDA/overloaded-delete.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/overloaded-delete.cu?rev=284879&r1=284878&r2=284879&view=diff
==
--- cfe/trunk/test/SemaCUDA/overloaded-delete.cu (original)
+++ cfe/trunk/test/SemaCUDA/overloaded-delete.cu Fri Oct 21 15:34:05 2016
@@ -16,10 +16,54 @@ __host__ __device__ void test(S* s) {
   delete s;
 }
 
+// Code should work with no explicit declarations/definitions of
+// allocator functions.
+__host__ __device__ void test_default_global_delete_hd(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+
+__device__ void test_default_global_delete(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+__host__ void test_default_global_delete(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+
+// It should work with only some of allocators (re-)declared.
+__device__ void operator delete(void *ptr);
+
+__host__ __device__ void test_partial_global_delete_hd(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+
+__device__ void test_partial_global_delete(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+__host__ void test_partial_global_delete(int *ptr) {
+  // Again, there should be no ambiguity between which operator delete we call.
+  ::delete ptr;
+}
+
+
+// We should be able to define both host and device variants.
 __host__ void operator delete(void *ptr) {}
 __device__ void operator delete(void *ptr) {}
 
-__host__ __device__ void test_global_delete(int *ptr) {
+

[libcxx] r284881 - [libcxx] Support std::regex_constants::match_not_null

2016-10-21 Thread Tim Shen via cfe-commits
Author: timshen
Date: Fri Oct 21 15:41:47 2016
New Revision: 284881

URL: http://llvm.org/viewvc/llvm-project?rev=284881&view=rev
Log:
[libcxx] Support std::regex_constants::match_not_null

Summary: Fixes PR21597.

Reviewers: mclow.lists, EricWF

Subscribers: cfe-commits

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

Added:
libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_null.pass.cpp
Modified:
libcxx/trunk/include/regex

Modified: libcxx/trunk/include/regex
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=284881&r1=284880&r2=284881&view=diff
==
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Fri Oct 21 15:41:47 2016
@@ -,6 +,12 @@ basic_regex<_CharT, _Traits>::__match_at
 switch (__s.__do_)
 {
 case __state::__end_state:
+if (__flags & regex_constants::match_not_null &&
+__s.__current_ == __first)
+{
+  __states.pop_back();
+  break;
+}
 __m.__matches_[0].first = __first;
 __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ 
- __first);
 __m.__matches_[0].matched = true;
@@ -5618,6 +5624,12 @@ basic_regex<_CharT, _Traits>::__match_at
 switch (__s.__do_)
 {
 case __state::__end_state:
+if (__flags & regex_constants::match_not_null &&
+__s.__current_ == __first)
+{
+  __states.pop_back();
+  break;
+}
 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
 __highest_j = __s.__current_ - __s.__first_;
 __matched = true;
@@ -5703,6 +5715,12 @@ basic_regex<_CharT, _Traits>::__match_at
 switch (__s.__do_)
 {
 case __state::__end_state:
+if (__flags & regex_constants::match_not_null &&
+__s.__current_ == __first)
+{
+  __states.pop_back();
+  break;
+}
 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
 {
 __highest_j = __s.__current_ - __s.__first_;

Added: libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_null.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_null.pass.cpp?rev=284881&view=auto
==
--- libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_null.pass.cpp 
(added)
+++ libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_null.pass.cpp Fri 
Oct 21 15:41:47 2016
@@ -0,0 +1,46 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// match_not_null:
+// The regular expression shall not match an empty sequence.
+
+#include "test_macros.h"
+#include 
+#include 
+
+int main()
+{
+  // When match_not_null is on, the regex engine should reject empty matches 
and
+  // move on to try other solutions.
+  std::cmatch m;
+  assert(!std::regex_search("a", m, std::regex("b*"),
+std::regex_constants::match_not_null));
+  assert(std::regex_search("aa", m, std::regex("a*?"),
+   std::regex_constants::match_not_null));
+  assert(m[0].length() == 1);
+  assert(!std::regex_search("a", m, std::regex("b*", std::regex::extended),
+std::regex_constants::match_not_null));
+  assert(!std::regex_search(
+  "a", m,
+  std::regex("b*", std::regex::extended | std::regex_constants::nosubs),
+  std::regex_constants::match_not_null));
+
+  assert(!std::regex_match("", m, std::regex("a*"),
+   std::regex_constants::match_not_null));
+  assert(!std::regex_match("", m, std::regex("a*", std::regex::extended),
+   std::regex_constants::match_not_null));
+  assert(!std::regex_match(
+  "", m,
+  std::regex("a*", std::regex::extended | std::regex_constants::nosubs),
+  std::regex_constants::match_not_null));
+
+  return 0;
+}


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


[PATCH] D25595: [libcxx] Support std::regex_constants::match_not_null

2016-10-21 Thread Tim Shen via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284881: [libcxx] Support 
std::regex_constants::match_not_null (authored by timshen).

Changed prior to commit:
  https://reviews.llvm.org/D25595?vs=75186&id=75480#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25595

Files:
  libcxx/trunk/include/regex
  libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_null.pass.cpp


Index: libcxx/trunk/include/regex
===
--- libcxx/trunk/include/regex
+++ libcxx/trunk/include/regex
@@ -,6 +,12 @@
 switch (__s.__do_)
 {
 case __state::__end_state:
+if (__flags & regex_constants::match_not_null &&
+__s.__current_ == __first)
+{
+  __states.pop_back();
+  break;
+}
 __m.__matches_[0].first = __first;
 __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ 
- __first);
 __m.__matches_[0].matched = true;
@@ -5618,6 +5624,12 @@
 switch (__s.__do_)
 {
 case __state::__end_state:
+if (__flags & regex_constants::match_not_null &&
+__s.__current_ == __first)
+{
+  __states.pop_back();
+  break;
+}
 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
 __highest_j = __s.__current_ - __s.__first_;
 __matched = true;
@@ -5703,6 +5715,12 @@
 switch (__s.__do_)
 {
 case __state::__end_state:
+if (__flags & regex_constants::match_not_null &&
+__s.__current_ == __first)
+{
+  __states.pop_back();
+  break;
+}
 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
 {
 __highest_j = __s.__current_ - __s.__first_;
Index: libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_null.pass.cpp
===
--- libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_null.pass.cpp
+++ libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_null.pass.cpp
@@ -0,0 +1,46 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// match_not_null:
+// The regular expression shall not match an empty sequence.
+
+#include "test_macros.h"
+#include 
+#include 
+
+int main()
+{
+  // When match_not_null is on, the regex engine should reject empty matches 
and
+  // move on to try other solutions.
+  std::cmatch m;
+  assert(!std::regex_search("a", m, std::regex("b*"),
+std::regex_constants::match_not_null));
+  assert(std::regex_search("aa", m, std::regex("a*?"),
+   std::regex_constants::match_not_null));
+  assert(m[0].length() == 1);
+  assert(!std::regex_search("a", m, std::regex("b*", std::regex::extended),
+std::regex_constants::match_not_null));
+  assert(!std::regex_search(
+  "a", m,
+  std::regex("b*", std::regex::extended | std::regex_constants::nosubs),
+  std::regex_constants::match_not_null));
+
+  assert(!std::regex_match("", m, std::regex("a*"),
+   std::regex_constants::match_not_null));
+  assert(!std::regex_match("", m, std::regex("a*", std::regex::extended),
+   std::regex_constants::match_not_null));
+  assert(!std::regex_match(
+  "", m,
+  std::regex("a*", std::regex::extended | std::regex_constants::nosubs),
+  std::regex_constants::match_not_null));
+
+  return 0;
+}


Index: libcxx/trunk/include/regex
===
--- libcxx/trunk/include/regex
+++ libcxx/trunk/include/regex
@@ -,6 +,12 @@
 switch (__s.__do_)
 {
 case __state::__end_state:
+if (__flags & regex_constants::match_not_null &&
+__s.__current_ == __first)
+{
+  __states.pop_back();
+  break;
+}
 __m.__matches_[0].first = __first;
 __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
 __m.__matches_[0].matched = true;
@@ -5618,6 +5624,12 @@
 switch (__s.__do_)
 {
 case __state::__end_state:
+if (__flags & regex_constants::match_no

[PATCH] D25845: [CUDA] Ignore implicit target attributes during function template instantiation.

2016-10-21 Thread Artem Belevich via cfe-commits
tra updated this revision to Diff 75482.
tra added a comment.

Added a comment explaining expected constexpr function template matching 
behavior.


https://reviews.llvm.org/D25845

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaCUDA.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaTemplate.cpp
  test/SemaCUDA/function-template-overload.cu

Index: test/SemaCUDA/function-template-overload.cu
===
--- test/SemaCUDA/function-template-overload.cu
+++ test/SemaCUDA/function-template-overload.cu
@@ -56,24 +56,54 @@
 template  __host__ __device__ HDType overload_h_d2(T a) { return HDType(); }
 template  __device__ DType overload_h_d2(T1 a) { T1 x; T2 y; return DType(); }
 
+// constexpr functions are implicitly HD, but explicit
+// instantiation/specialization must use target attributes as written.
+template  constexpr T overload_ce_implicit_hd(T a) { return a+1; }
+// expected-note@-1 3 {{candidate template ignored: target attributes do not match}}
+
+// These will not match the template.
+template __host__ __device__ int overload_ce_implicit_hd(int a);
+// expected-error@-1 {{explicit instantiation of 'overload_ce_implicit_hd' does not refer to a function template, variable template, member function, member class, or static data member}}
+template <> __host__ __device__ long overload_ce_implicit_hd(long a);
+// expected-error@-1 {{no function template matches function template specialization 'overload_ce_implicit_hd'}}
+template <> __host__ __device__ constexpr long overload_ce_implicit_hd(long a);
+// expected-error@-1 {{no function template matches function template specialization 'overload_ce_implicit_hd'}}
+
+// These should work, because template matching ignores implicit HD
+// attributes compiler gives to constexpr functions/templates so
+// 'overload_ce_implicit_hd' template will match __host__ functions
+// only.
+template __host__ int overload_ce_implicit_hd(int a);
+template <> __host__ long overload_ce_implicit_hd(long a);
+
+template float overload_ce_implicit_hd(float a);
+template <> float* overload_ce_implicit_hd(float *a);
+template <> constexpr double overload_ce_implicit_hd(double a) { return a + 3.0; };
+
 __host__ void hf() {
   overload_hd(13);
+  overload_ce_implicit_hd('h');// Implicitly instantiated
+  overload_ce_implicit_hd(1.0f);   // Explicitly instantiated
+  overload_ce_implicit_hd(2.0);// Explicitly specialized
 
   HType h = overload_h_d(10);
   HType h2i = overload_h_d2(11);
   HType h2ii = overload_h_d2(12);
 
   // These should be implicitly instantiated from __host__ template returning HType.
-  DType d = overload_h_d(20); // expected-error {{no viable conversion from 'HType' to 'DType'}}
-  DType d2i = overload_h_d2(21); // expected-error {{no viable conversion from 'HType' to 'DType'}}
+  DType d = overload_h_d(20);  // expected-error {{no viable conversion from 'HType' to 'DType'}}
+  DType d2i = overload_h_d2(21);  // expected-error {{no viable conversion from 'HType' to 'DType'}}
   DType d2ii = overload_h_d2(22); // expected-error {{no viable conversion from 'HType' to 'DType'}}
 }
 __device__ void df() {
   overload_hd(23);
+  overload_ce_implicit_hd('d');// Implicitly instantiated
+  overload_ce_implicit_hd(1.0f);   // Explicitly instantiated
+  overload_ce_implicit_hd(2.0);// Explicitly specialized
 
   // These should be implicitly instantiated from __device__ template returning DType.
-  HType h = overload_h_d(10); // expected-error {{no viable conversion from 'DType' to 'HType'}}
-  HType h2i = overload_h_d2(11); // expected-error {{no viable conversion from 'DType' to 'HType'}}
+  HType h = overload_h_d(10);  // expected-error {{no viable conversion from 'DType' to 'HType'}}
+  HType h2i = overload_h_d2(11);  // expected-error {{no viable conversion from 'DType' to 'HType'}}
   HType h2ii = overload_h_d2(12); // expected-error {{no viable conversion from 'DType' to 'HType'}}
 
   DType d = overload_h_d(20);
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -7043,13 +7043,13 @@
 
   // Filter out matches that have different target.
   if (LangOpts.CUDA &&
-  IdentifyCUDATarget(Specialization) != IdentifyCUDATarget(FD)) {
+  IdentifyCUDATarget(Specialization, true) !=
+  IdentifyCUDATarget(FD, true)) {
 FailedCandidates.addCandidate().set(
 I.getPair(), FunTmpl->getTemplatedDecl(),
 MakeDeductionFailureInfo(Context, TDK_CUDATargetMismatch, Info));
 continue;
   }
-
   // Record this candidate.
   if (ExplicitTemplateArgs)
 ConvertedTemplateArgs[Specialization] = std::move(Args);
@@ -7164,6 +7164,8 @@
   // the prior function template specialization.
   Previous.clear();
   Previous.addDecl(Specialization);
+  if (LangOpts.CUDA)
+mergeCU

r284882 - [CUDA] Simplify some repeated diagnostic expectations in CUDA tests.

2016-10-21 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Fri Oct 21 15:50:47 2016
New Revision: 284882

URL: http://llvm.org/viewvc/llvm-project?rev=284882&view=rev
Log:
[CUDA] Simplify some repeated diagnostic expectations in CUDA tests.

Instead of repeating the diagnostic, use "expected-note N".

Test-only change.

Modified:
cfe/trunk/test/SemaCUDA/bad-calls-on-same-line.cu
cfe/trunk/test/SemaCUDA/call-device-fn-from-host.cu
cfe/trunk/test/SemaCUDA/call-host-fn-from-device.cu
cfe/trunk/test/SemaCUDA/trace-through-global.cu

Modified: cfe/trunk/test/SemaCUDA/bad-calls-on-same-line.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/bad-calls-on-same-line.cu?rev=284882&r1=284881&r2=284882&view=diff
==
--- cfe/trunk/test/SemaCUDA/bad-calls-on-same-line.cu (original)
+++ cfe/trunk/test/SemaCUDA/bad-calls-on-same-line.cu Fri Oct 21 15:50:47 2016
@@ -28,8 +28,7 @@ struct Selector {
 template 
 inline __host__ __device__ void hd() {
   Selector().f();
-  // expected-error@-1 {{reference to __device__ function}}
-  // expected-error@-2 {{reference to __device__ function}}
+  // expected-error@-1 2 {{reference to __device__ function}}
 }
 
 void host_fn() {

Modified: cfe/trunk/test/SemaCUDA/call-device-fn-from-host.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/call-device-fn-from-host.cu?rev=284882&r1=284881&r2=284882&view=diff
==
--- cfe/trunk/test/SemaCUDA/call-device-fn-from-host.cu (original)
+++ cfe/trunk/test/SemaCUDA/call-device-fn-from-host.cu Fri Oct 21 15:50:47 2016
@@ -7,16 +7,11 @@
 #include "Inputs/cuda.h"
 
 __device__ void device_fn() {}
-// expected-note@-1 {{'device_fn' declared here}}
-// expected-note@-2 {{'device_fn' declared here}}
-// expected-note@-3 {{'device_fn' declared here}}
-// expected-note@-4 {{'device_fn' declared here}}
-// expected-note@-5 {{'device_fn' declared here}}
+// expected-note@-1 5 {{'device_fn' declared here}}
 
 struct S {
   __device__ S() {}
-  // expected-note@-1 {{'S' declared here}}
-  // expected-note@-2 {{'S' declared here}}
+  // expected-note@-1 2 {{'S' declared here}}
   __device__ ~S() { device_fn(); }
   // expected-note@-1 {{'~S' declared here}}
   int x;

Modified: cfe/trunk/test/SemaCUDA/call-host-fn-from-device.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/call-host-fn-from-device.cu?rev=284882&r1=284881&r2=284882&view=diff
==
--- cfe/trunk/test/SemaCUDA/call-host-fn-from-device.cu (original)
+++ cfe/trunk/test/SemaCUDA/call-host-fn-from-device.cu Fri Oct 21 15:50:47 2016
@@ -7,20 +7,13 @@
 #include "Inputs/cuda.h"
 
 extern "C" void host_fn() {}
-// expected-note@-1 {{'host_fn' declared here}}
-// expected-note@-2 {{'host_fn' declared here}}
-// expected-note@-3 {{'host_fn' declared here}}
-// expected-note@-4 {{'host_fn' declared here}}
-// expected-note@-5 {{'host_fn' declared here}}
-// expected-note@-6 {{'host_fn' declared here}}
-// expected-note@-7 {{'host_fn' declared here}}
+// expected-note@-1 7 {{'host_fn' declared here}}
 
 struct Dummy {};
 
 struct S {
   S() {}
-  // expected-note@-1 {{'S' declared here}}
-  // expected-note@-2 {{'S' declared here}}
+  // expected-note@-1 2 {{'S' declared here}}
   ~S() { host_fn(); }
   // expected-note@-1 {{'~S' declared here}}
   int x;

Modified: cfe/trunk/test/SemaCUDA/trace-through-global.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/trace-through-global.cu?rev=284882&r1=284881&r2=284882&view=diff
==
--- cfe/trunk/test/SemaCUDA/trace-through-global.cu (original)
+++ cfe/trunk/test/SemaCUDA/trace-through-global.cu Fri Oct 21 15:50:47 2016
@@ -6,8 +6,7 @@
 #include "Inputs/cuda.h"
 
 __device__ void device_fn(int) {}
-// expected-note@-1 {{declared here}}
-// expected-note@-2 {{declared here}}
+// expected-note@-1 2 {{declared here}}
 
 inline __host__ __device__ int hd1() {
   device_fn(0);  // expected-error {{reference to __device__ function}}
@@ -45,6 +44,5 @@ void launch_kernel() {
 
 void host_fn() {
   launch_kernel();
-  // expected-note@-1 {{called by 'host_fn'}}
-  // expected-note@-2 {{called by 'host_fn'}}
+  // expected-note@-1 2 {{called by 'host_fn'}}
 }


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


[PATCH] D25845: [CUDA] Ignore implicit target attributes during function template instantiation.

2016-10-21 Thread Artem Belevich via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D25845#576819, @jlebar wrote:

> > This patch changes the way we match target attributes of base template vs 
> > attributes used in explicit instantiation or specialization so that only 
> > explicitly specified attributes are considered.
>
> Another question about this: When we have something inside of the 
> force-host-device pragma, the HD attributes it gets are implicit.


.. and therefore ignored for the purposes of matching specialization to 
template.

> This means that the only way to specialize something inside one of these 
> pragmas is to use the pragma around the specialization?  That...seems weird?

The whole purpose of this patch is to *ignore* implicit attributes added by 
compiler and only consider what user has written in the source code. 
Specialization will work exactly the same regardless of whether template or its 
specialization are within the pragma. In all cases we'll only consider 
attributes explicitly specified by the user. I've used constexpr template to 
illustrate the case where compiler adds implicit HD attributes to the template, 
but the logic will apply to the specialization, too -- if attributes are not 
written, they are not considered when we consider which template to match.


https://reviews.llvm.org/D25845



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


[PATCH] D25363: [Sema] Store a SourceRange for multi-token builtin types

2016-10-21 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284885: [Sema] Store a SourceRange for multi-token builtin 
types (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D25363?vs=74975&id=75485#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25363

Files:
  cfe/trunk/include/clang/AST/TypeLoc.h
  cfe/trunk/include/clang/Sema/DeclSpec.h
  cfe/trunk/lib/Sema/DeclSpec.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/unittests/AST/SourceLocationTest.cpp

Index: cfe/trunk/lib/Sema/DeclSpec.cpp
===
--- cfe/trunk/lib/Sema/DeclSpec.cpp
+++ cfe/trunk/lib/Sema/DeclSpec.cpp
@@ -610,14 +610,16 @@
 const char *&PrevSpec,
 unsigned &DiagID,
 const PrintingPolicy &Policy) {
-  // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that
+  // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that
   // for 'long long' we will keep the source location of the first 'long'.
   if (TypeSpecWidth == TSW_unspecified)
-TSWLoc = Loc;
+TSWRange.setBegin(Loc);
   // Allow turning long -> long long.
   else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
   TypeSpecWidth = W;
+  // Remember location of the last 'long'
+  TSWRange.setEnd(Loc);
   return false;
 }
 
@@ -997,9 +999,9 @@
TypeQualifiers)) {
 const unsigned NumLocs = 9;
 SourceLocation ExtraLocs[NumLocs] = {
-  TSWLoc, TSCLoc, TSSLoc, AltiVecLoc,
-  TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc, TQ_unalignedLoc
-};
+TSWRange.getBegin(), TSCLoc,   TSSLoc,
+AltiVecLoc,  TQ_constLoc,  TQ_restrictLoc,
+TQ_volatileLoc,  TQ_atomicLoc, TQ_unalignedLoc};
 FixItHint Hints[NumLocs];
 SourceLocation FirstLoc;
 for (unsigned I = 0; I != NumLocs; ++I) {
@@ -1041,8 +1043,8 @@
   // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1)
   if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short) &&
   (TypeSpecWidth != TSW_longlong))
-S.Diag(TSWLoc, diag::err_invalid_vector_bool_decl_spec)
-  << getSpecifierName((TSW)TypeSpecWidth);
+S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec)
+<< getSpecifierName((TSW)TypeSpecWidth);
 
   // vector bool long long requires VSX support or ZVector.
   if ((TypeSpecWidth == TSW_longlong) &&
@@ -1059,7 +1061,8 @@
   // vector long double and vector long long double are never allowed.
   // vector double is OK for Power7 and later, and ZVector.
   if (TypeSpecWidth == TSW_long || TypeSpecWidth == TSW_longlong)
-S.Diag(TSWLoc, diag::err_invalid_vector_long_double_decl_spec);
+S.Diag(TSWRange.getBegin(),
+   diag::err_invalid_vector_long_double_decl_spec);
   else if (!S.Context.getTargetInfo().hasFeature("vsx") &&
!S.getLangOpts().ZVector)
 S.Diag(TSTLoc, diag::err_invalid_vector_double_decl_spec);
@@ -1070,10 +1073,11 @@
 } else if (TypeSpecWidth == TSW_long) {
   // vector long is unsupported for ZVector and deprecated for AltiVec.
   if (S.getLangOpts().ZVector)
-S.Diag(TSWLoc, diag::err_invalid_vector_long_decl_spec);
+S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_decl_spec);
   else
-S.Diag(TSWLoc, diag::warn_vector_long_decl_spec_combination)
-  << getSpecifierName((TST)TypeSpecType, Policy);
+S.Diag(TSWRange.getBegin(),
+   diag::warn_vector_long_decl_spec_combination)
+<< getSpecifierName((TST)TypeSpecType, Policy);
 }
 
 if (TypeAltiVecPixel) {
@@ -1106,18 +1110,18 @@
 if (TypeSpecType == TST_unspecified)
   TypeSpecType = TST_int; // short -> short int, long long -> long long int.
 else if (TypeSpecType != TST_int) {
-  S.Diag(TSWLoc, diag::err_invalid_width_spec) << (int)TypeSpecWidth
-<<  getSpecifierName((TST)TypeSpecType, Policy);
+  S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
+  << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
   TypeSpecType = TST_int;
   TypeSpecOwned = false;
 }
 break;
   case TSW_long:  // long double, long int
 if (TypeSpecType == TST_unspecified)
   TypeSpecType = TST_int;  // long -> long int.
 else if (TypeSpecType != TST_int && TypeSpecType != TST_double) {
-  S.Diag(TSWLoc, diag::err_invalid_width_spec) << (int)TypeSpecWidth
-<< getSpecifierName((TST)TypeSpecType, Policy);
+  S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
+  << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
   TypeSpecType = TST_int;
   TypeSpecOwned = false;
 }
Index: cfe/trunk/lib/Sem

r284885 - [Sema] Store a SourceRange for multi-token builtin types

2016-10-21 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Fri Oct 21 16:13:56 2016
New Revision: 284885

URL: http://llvm.org/viewvc/llvm-project?rev=284885&view=rev
Log:
[Sema] Store a SourceRange for multi-token builtin types

Summary:
clang-tidy's modernize-use-auto check uses the SourceRange of a
TypeLoc when replacing the type with auto.
This was producing the wrong result for multi-token builtin types
like long long:

-long long *ll = new long long();
+auto long *ll = new long long();

Reviewers: alexfh, hokein, rsmith, Prazek, aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/unittests/AST/SourceLocationTest.cpp

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=284885&r1=284884&r2=284885&view=diff
==
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Fri Oct 21 16:13:56 2016
@@ -512,7 +512,7 @@ private:
 
 
 struct BuiltinLocInfo {
-  SourceLocation BuiltinLoc;
+  SourceRange BuiltinRange;
 };
 
 /// \brief Wrapper for source info for builtin types.
@@ -522,10 +522,19 @@ class BuiltinTypeLoc : public ConcreteTy
   BuiltinLocInfo> {
 public:
   SourceLocation getBuiltinLoc() const {
-return getLocalData()->BuiltinLoc;
+return getLocalData()->BuiltinRange.getBegin();
   }
   void setBuiltinLoc(SourceLocation Loc) {
-getLocalData()->BuiltinLoc = Loc;
+getLocalData()->BuiltinRange = Loc;
+  }
+  void expandBuiltinRange(SourceRange Range) {
+SourceRange &BuiltinRange = getLocalData()->BuiltinRange;
+if (!BuiltinRange.getBegin().isValid()) {
+  BuiltinRange = Range;
+} else {
+  BuiltinRange.setBegin(std::min(Range.getBegin(), 
BuiltinRange.getBegin()));
+  BuiltinRange.setEnd(std::max(Range.getEnd(), BuiltinRange.getEnd()));
+}
   }
 
   SourceLocation getNameLoc() const { return getBuiltinLoc(); }
@@ -554,7 +563,7 @@ public:
   }
 
   SourceRange getLocalSourceRange() const {
-return SourceRange(getBuiltinLoc(), getBuiltinLoc());
+return getLocalData()->BuiltinRange;
   }
 
   TypeSpecifierSign getWrittenSignSpec() const {

Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=284885&r1=284884&r2=284885&view=diff
==
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Fri Oct 21 16:13:56 2016
@@ -380,7 +380,8 @@ private:
   SourceRange Range;
 
   SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc;
-  SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc;
+  SourceRange TSWRange;
+  SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc;
   /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
   /// typename, then this is the location of the named type (if present);
   /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
@@ -503,7 +504,8 @@ public:
   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
 
-  SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; }
+  SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); }
+  SourceRange getTypeSpecWidthRange() const { return TSWRange; }
   SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
   SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
   SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }

Modified: cfe/trunk/lib/Sema/DeclSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=284885&r1=284884&r2=284885&view=diff
==
--- cfe/trunk/lib/Sema/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Sema/DeclSpec.cpp Fri Oct 21 16:13:56 2016
@@ -610,14 +610,16 @@ bool DeclSpec::SetTypeSpecWidth(TSW W, S
 const char *&PrevSpec,
 unsigned &DiagID,
 const PrintingPolicy &Policy) {
-  // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that
+  // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that
   // for 'long long' we will keep the source location of the first 'long'.
   if (TypeSpecWidth == TSW_unspecified)
-TSWLoc = Loc;
+TSWRange.setBegin(Loc);
   // Allow turning long -> long long.
   else if (W != TSW_longlong || TypeSpecWidth != TSW_long)
 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID);
   TypeSpecWidth = W;
+  // Rem

[PATCH] D25876: [analyzer] Report CFNumberGetValue API misuse

2016-10-21 Thread Devin Coughlin via cfe-commits
dcoughlin added a comment.

LGTM!


https://reviews.llvm.org/D25876



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


[PATCH] D25876: [analyzer] Report CFNumberGetValue API misuse

2016-10-21 Thread Anna Zaks via cfe-commits
zaks.anna updated this revision to Diff 75488.
zaks.anna added a comment.

Address comments from Devin.


https://reviews.llvm.org/D25876

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  test/Analysis/CFNumber.c

Index: test/Analysis/CFNumber.c
===
--- test/Analysis/CFNumber.c
+++ test/Analysis/CFNumber.c
@@ -13,21 +13,35 @@
kCFNumberMaxType = 16 };
 typedef CFIndex CFNumberType;
 typedef const struct __CFNumber * CFNumberRef;
+typedef unsigned char Boolean;
 extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
+Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
 
-CFNumberRef f1(unsigned char x) {
-  return CFNumberCreate(0, kCFNumberSInt16Type, &x);  // expected-warning{{An 8 bit integer is used to initialize a CFNumber object that represents a 16 bit integer. 8 bits of the CFNumber value will be garbage}}
+__attribute__((cf_returns_retained)) CFNumberRef f1(unsigned char x) {
+  return CFNumberCreate(0, kCFNumberSInt16Type, &x);  // expected-warning{{An 8-bit integer is used to initialize a CFNumber object that represents a 16-bit integer; 8 bits of the CFNumber value will be garbage}}
 }
 
 __attribute__((cf_returns_retained)) CFNumberRef f2(unsigned short x) {
-  return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{A 16 bit integer is used to initialize a CFNumber object that represents an 8 bit integer. 8 bits of the input integer will be lost}}
+  return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{A 16-bit integer is used to initialize a CFNumber object that represents an 8-bit integer; 8 bits of the integer value will be lost}}
 }
 
 // test that the attribute overrides the naming convention.
 __attribute__((cf_returns_not_retained)) CFNumberRef CreateNum(unsigned char x) {
   return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{leak}}
 }
 
-CFNumberRef f3(unsigned i) {
-  return CFNumberCreate(0, kCFNumberLongType, &i); // expected-warning{{A 32 bit integer is used to initialize a CFNumber object that represents a 64 bit integer}}
+__attribute__((cf_returns_retained)) CFNumberRef f3(unsigned i) {
+  return CFNumberCreate(0, kCFNumberLongType, &i); // expected-warning{{A 32-bit integer is used to initialize a CFNumber object that represents a 64-bit integer}}
+}
+
+unsigned char getValueTest1(CFNumberRef x) {
+  unsigned char scalar = 0;
+  CFNumberGetValue(x, kCFNumberSInt16Type, &scalar);  // expected-warning{{A CFNumber object that represents a 16-bit integer is used to initialize an 8-bit integer; 8 bits of the CFNumber value will overwrite adjacent storage}}
+  return scalar;
+}
+
+unsigned char getValueTest2(CFNumberRef x) {
+  unsigned short scalar = 0;
+  CFNumberGetValue(x, kCFNumberSInt8Type, &scalar);  // expected-warning{{A CFNumber object that represents an 8-bit integer is used to initialize a 16-bit integer; 8 bits of the integer value will be garbage}}
+  return scalar;
 }
Index: lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
===
--- lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -336,15 +336,15 @@
 }
 
 //===--===//
-// Error reporting.
+// Checking for mismatched types passed to CFNumberCreate/CFNumberGetValue.
 //===--===//
 
 namespace {
-class CFNumberCreateChecker : public Checker< check::PreStmt > {
+class CFNumberChecker : public Checker< check::PreStmt > {
   mutable std::unique_ptr BT;
-  mutable IdentifierInfo* II;
+  mutable IdentifierInfo *ICreate, *IGetValue;
 public:
-  CFNumberCreateChecker() : II(nullptr) {}
+  CFNumberChecker() : ICreate(nullptr), IGetValue(nullptr) {}
 
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
@@ -425,18 +425,20 @@
 }
 #endif
 
-void CFNumberCreateChecker::checkPreStmt(const CallExpr *CE,
+void CFNumberChecker::checkPreStmt(const CallExpr *CE,
  CheckerContext &C) const {
   ProgramStateRef state = C.getState();
   const FunctionDecl *FD = C.getCalleeDecl(CE);
   if (!FD)
 return;
 
   ASTContext &Ctx = C.getASTContext();
-  if (!II)
-II = &Ctx.Idents.get("CFNumberCreate");
-
-  if (FD->getIdentifier() != II || CE->getNumArgs() != 3)
+  if (!ICreate) {
+ICreate = &Ctx.Idents.get("CFNumberCreate");
+IGetValue = &Ctx.Idents.get("CFNumberGetValue");
+  }
+  if (!(FD->getIdentifier() == ICreate || FD->getIdentifier() == IGetValue) ||
+  CE->getNumArgs() != 3)
 return;
 
   // Get the value of the "theType" argument.
@@ -450,13 +452,13 @@
 return;
 
   uint64_t NumberKind = V->getValue().getLimit

[PATCH] D25882: Remove special error recovery for ::(id)

2016-10-21 Thread Reid Kleckner via cfe-commits
rnk created this revision.
rnk added reviewers: rsmith, rtrieu.
rnk added a subscriber: cfe-commits.

The code pattern used to implement the token rewriting hack doesn't
interact well with token caching in the pre-processor. As a result,
clang would crash on 'int f(::(id));' while doing a tenative parse of
the contents of the outer parentheses. The original code from PR11852
still doesn't crash the compiler.

This error recovery also often does the wrong thing with member function
pointers. The test case from the original PR doesn't recover the right
way either:

  void S::(*pf)() = S::f; // should be 'void (S::*pf)()'

Instead we were recovering as 'void S::*pf()', which is still wrong.

If we still think that users mistakenly parenthesize identifiers in
nested name specifiers, we should change clang to intentionally parse
that form with an error, rather than doing a token rewrite.

Fixes PR26623, but I think there will be many more bugs of this nature
due to other token rewriting attempts.


https://reviews.llvm.org/D25882

Files:
  include/clang/Parse/Parser.h
  lib/Parse/ParseExprCXX.cpp
  test/Parser/colon-colon-parentheses.cpp

Index: test/Parser/colon-colon-parentheses.cpp
===
--- test/Parser/colon-colon-parentheses.cpp
+++ test/Parser/colon-colon-parentheses.cpp
@@ -1,30 +1,36 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify -DPR21815
-// RUN: cp %s %t
-// RUN: not %clang_cc1 -x c++ -fixit %t
-// RUN: %clang_cc1 -x c++ %t
+// RUN: %clang_cc1 %s -verify -fno-spell-checking
 
 struct S { static int a,b,c;};
-int S::(a);  // expected-error{{unexpected parenthesis after '::'}}
-int S::(b;  // expected-error{{unexpected parenthesis after '::'}}
+int S::(a);  // expected-error{{expected unqualified-id}}
+int S::(b;  // expected-error{{expected unqualified-id}}
+);
 int S::c;
-int S::(*d);  // expected-error{{unexpected parenthesis after '::'}}
-int S::(*e;  // expected-error{{unexpected parenthesis after '::'}}
+int S::(*d);  // expected-error{{expected unqualified-id}}
+int S::(*e;  // expected-error{{expected unqualified-id}}
+);
 int S::*f;
-int g = S::(a);  // expected-error{{unexpected parenthesis after '::'}}
-int h = S::(b;  // expected-error{{unexpected parenthesis after '::'}}
+int g = S::(a);  // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'a'}}
+int h = S::(b;  // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'b'}}
+);
 int i = S::c;
 
 void foo() {
   int a;
-  a = ::(g);  // expected-error{{unexpected parenthesis after '::'}}
-  a = ::(h;  // expected-error{{unexpected parenthesis after '::'}}
+  a = ::(g);  // expected-error{{expected unqualified-id}}
+  a = ::(h;  // expected-error{{expected unqualified-id}}
   a = ::i;
 }
 
-#ifdef PR21815
+// The following tests used to be crash bugs.
+
+// PR21815
 // expected-error@+2{{C++ requires a type specifier for all declarations}}
 // expected-error@+1{{expected unqualified-id}}
 a (::( ));
 
 ::((c )); // expected-error{{expected unqualified-id}}
-#endif
+
+// PR26623
+int f1(::(B) p); // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'B'}}
+
+int f2(::S::(C) p); // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'C'}}
Index: lib/Parse/ParseExprCXX.cpp
===
--- lib/Parse/ParseExprCXX.cpp
+++ lib/Parse/ParseExprCXX.cpp
@@ -100,48 +100,6 @@
  /*AtDigraph*/false);
 }
 
-/// \brief Emits an error for a left parentheses after a double colon.
-///
-/// When a '(' is found after a '::', emit an error.  Attempt to fix the token
-/// stream by removing the '(', and the matching ')' if found.
-void Parser::CheckForLParenAfterColonColon() {
-  if (!Tok.is(tok::l_paren))
-return;
-
-  Token LParen = Tok;
-  Token NextTok = GetLookAheadToken(1);
-  Token StarTok = NextTok;
-  // Check for (identifier or (*identifier
-  Token IdentifierTok = StarTok.is(tok::star) ? GetLookAheadToken(2) : StarTok;
-  if (IdentifierTok.isNot(tok::identifier))
-return;
-  // Eat the '('.
-  ConsumeParen();
-  Token RParen;
-  RParen.setLocation(SourceLocation());
-  // Do we have a ')' ?
-  NextTok = StarTok.is(tok::star) ? GetLookAheadToken(2) : GetLookAheadToken(1);
-  if (NextTok.is(tok::r_paren)) {
-RParen = NextTok;
-// Eat the '*' if it is present.
-if (StarTok.is(tok::star))
-  ConsumeToken();
-// Eat the identifier.
-ConsumeToken();
-// Add the identifier token back.
-PP.EnterToken(IdentifierTok);
-// Add the '*' back if it was present.
-if (StarTok.is(tok::star))
-  PP.EnterToken(StarTok);
-// Eat the ')'.
-ConsumeParen();
-  }
-
-  Diag(LParen.getLocation(), diag::err_paren_after_colon_colon)
-  << FixItHint::CreateRemoval(LParen.getLocation())
-  << FixItHint::CreateRem

[PATCH] D22296: CodeGen: New vtable group representation: struct of vtable arrays.

2016-10-21 Thread Peter Collingbourne via cfe-commits
pcc updated this revision to Diff 75493.
pcc added a comment.

Refresh


https://reviews.llvm.org/D22296

Files:
  clang/include/clang/AST/VTableBuilder.h
  clang/lib/AST/VTableBuilder.cpp
  clang/lib/CodeGen/CGCXX.cpp
  clang/lib/CodeGen/CGVTT.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CGVTables.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/PR26569.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call-2.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/ctor-dtor-alias.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-rtti.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/invariant.group-for-vptrs.cpp
  clang/test/CodeGenCXX/key-function-vtable.cpp
  clang/test/CodeGenCXX/microsoft-abi-constexpr-vs-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-abi-extern-template.cpp
  clang/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp
  clang/test/CodeGenCXX/microsoft-abi-vftables.cpp
  clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-abi-vtables-return-thunks.cpp
  clang/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-interface.cpp
  clang/test/CodeGenCXX/microsoft-no-rtti-data.cpp
  clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
  clang/test/CodeGenCXX/strict-vtable-pointers.cpp
  clang/test/CodeGenCXX/vtable-align.cpp
  clang/test/CodeGenCXX/vtable-assume-load.cpp
  clang/test/CodeGenCXX/vtable-pointer-initialization.cpp
  clang/test/CodeGenCXX/vtt-layout.cpp

Index: clang/test/CodeGenCXX/vtt-layout.cpp
===
--- clang/test/CodeGenCXX/vtt-layout.cpp
+++ clang/test/CodeGenCXX/vtt-layout.cpp
@@ -78,11 +78,12 @@
   }
 }
 
-// CHECK: @_ZTTN5Test11BE = unnamed_addr constant [1 x i8*] [i8* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @_ZTVN5Test11BE, i32 0, i32 3) to i8*)]
-// CHECK: @_ZTVN5Test51AE = unnamed_addr constant [4 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTIN5Test51AE to i8*), i8* bitcast (void ()* @__cxa_pure_virtual to i8*), i8* bitcast (void (%"struct.Test5::A"*)* @_ZN5Test51A6anchorEv to i8*)]
-// CHECK: @_ZTVN5Test61AE = unnamed_addr constant [4 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTIN5Test61AE to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to i8*), i8* bitcast (void (%"struct.Test6::A"*)* @_ZN5Test61A6anchorEv to i8*)]
-// CHECK: @_ZTTN5Test21CE = linkonce_odr unnamed_addr constant [2 x i8*] [i8* bitcast (i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @_ZTVN5Test21CE, i32 0, i32 4) to i8*), i8* bitcast (i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @_ZTVN5Test21CE, i32 0, i32 4) to i8*)] 
-// CHECK: @_ZTTN5Test31DE = linkonce_odr unnamed_addr constant [13 x i8*] [i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i32 0, i32 5) to i8*), i8* bitcast (i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @_ZTCN5Test31DE0_NS_2C1E, i32 0, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @_ZTCN5Test31DE0_NS_2C1E, i32 0, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ([14 x i8*], [14 x i8*]* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ([14 x i8*], [14 x i8*]* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ([14 x i8*], [14 x i8*]* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 10) to i8*), i8* bitcast (i8** getelementptr inbounds ([14 x i8*], [14 x i8*]* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 13) to i8*), i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i32 0, i32 15) to i8*), i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i32 0, i32 11) to i8*), i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i32 0, i32 11) to i8*), i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i64 1, i32 0) to i8*), i8* bitcast (i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @_ZTCN5Test31DE64_NS_2V2E, i32 0, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @_ZTCN5Test31DE64_NS_2V2E, i32 0, i32 6) to i8*)] 
-// CHECK: @_ZTTN5Test41DE = linkonce_odr unnamed_addr constant [19 x i8*] [i8* bitcast (i8** getelementptr inbounds ([25 x i8*], [25 x i8*]* @_ZTVN5Test41DE, i32 0, i32 6) to i8*), i8* bitcast (i8** getelementptr inboun

[PATCH] D24431: CodeGen: Start using inrange annotations on vtable getelementptr.

2016-10-21 Thread Peter Collingbourne via cfe-commits
pcc updated this revision to Diff 75494.
pcc added a comment.

Refresh


https://reviews.llvm.org/D24431

Files:
  clang/lib/CodeGen/CGVTT.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/microsoft-interface.cpp
  clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
  clang/test/CodeGenCXX/strict-vtable-pointers.cpp
  clang/test/CodeGenCXX/vtable-assume-load.cpp
  clang/test/CodeGenCXX/vtable-pointer-initialization.cpp
  clang/test/CodeGenCXX/vtt-layout.cpp

Index: clang/test/CodeGenCXX/vtt-layout.cpp
===
--- clang/test/CodeGenCXX/vtt-layout.cpp
+++ clang/test/CodeGenCXX/vtt-layout.cpp
@@ -78,12 +78,12 @@
   }
 }
 
-// CHECK: @_ZTTN5Test11BE = unnamed_addr constant [1 x i8*] [i8* bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTVN5Test11BE, i32 0, i32 0, i32 3) to i8*)]
+// CHECK: @_ZTTN5Test11BE = unnamed_addr constant [1 x i8*] [i8* bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTVN5Test11BE, i32 0, inrange i32 0, i32 3) to i8*)]
 // CHECK: @_ZTVN5Test51AE = unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTIN5Test51AE to i8*), i8* bitcast (void ()* @__cxa_pure_virtual to i8*), i8* bitcast (void (%"struct.Test5::A"*)* @_ZN5Test51A6anchorEv to i8*)] }
 // CHECK: @_ZTVN5Test61AE = unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTIN5Test61AE to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to i8*), i8* bitcast (void (%"struct.Test6::A"*)* @_ZN5Test61A6anchorEv to i8*)] }
-// CHECK: @_ZTTN5Test21CE = linkonce_odr unnamed_addr constant [2 x i8*] [i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTVN5Test21CE, i32 0, i32 0, i32 4) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTVN5Test21CE, i32 0, i32 0, i32 4) to i8*)]
-// CHECK: @_ZTTN5Test31DE = linkonce_odr unnamed_addr constant [13 x i8*] [i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }, { [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }* @_ZTVN5Test31DE, i32 0, i32 0, i32 5) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [3 x i8*], [4 x i8*] }, { [3 x i8*], [4 x i8*] }* @_ZTCN5Test31DE0_NS_2C1E, i32 0, i32 0, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [3 x i8*], [4 x i8*] }, { [3 x i8*], [4 x i8*] }* @_ZTCN5Test31DE0_NS_2C1E, i32 0, i32 1, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [7 x i8*], [3 x i8*], [4 x i8*] }, { [7 x i8*], [3 x i8*], [4 x i8*] }* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 0, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [7 x i8*], [3 x i8*], [4 x i8*] }, { [7 x i8*], [3 x i8*], [4 x i8*] }* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 0, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [7 x i8*], [3 x i8*], [4 x i8*] }, { [7 x i8*], [3 x i8*], [4 x i8*] }* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 1, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [7 x i8*], [3 x i8*], [4 x i8*] }, { [7 x i8*], [3 x i8*], [4 x i8*] }* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 2, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }, { [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }* @_ZTVN5Test31DE, i32 0, i32 2, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }, { [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }* @_ZTVN5Test31DE, i32 0, i32 1, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }, { [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }* @_ZTVN5Test31DE, i32 0, i32 1, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }, { [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }* @_ZTVN5Test31DE, i32 0, i32 3, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [3 x i8*], [4 x i8*] }, { [3 x i8*], [4 x i8*] }* @_ZTCN5Test31DE64_NS_2V2E, i32 0, i32 0, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [3 x i8*], [4 x i8*] }, { [3 x i8*], [4 x i8*] }* @_ZTCN5Test31DE64_NS_2V2E, i32 0, i32 1, i32 3) to i8*)]
+// CHECK: @_ZTTN5Test21CE = linkonce_odr unnamed_addr constant [2 x i8*] [i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTVN5Test21CE, i32 0, inrange i32 0, i32 4) to i8*), i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTVN5Test21CE, i32 0, inrange i32 0, i32 4) to i8*)]
+// CHECK: @_ZTTN5Test31DE = linkonce_odr unnamed_addr constant [13 x i8*] [i8* bitcast (i8** getelementptr inbounds ({ [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }, { [5 x i8*], [7 x i8*], [4 x i8*], [3 x i8*] }* @_ZTVN5Test31DE, i32 0, inrange

r284887 - Switch SmallSetVector to use DenseSet when it overflows its inline space.

2016-10-21 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Fri Oct 21 16:45:01 2016
New Revision: 284887

URL: http://llvm.org/viewvc/llvm-project?rev=284887&view=rev
Log:
Switch SmallSetVector to use DenseSet when it overflows its inline space.

Summary:
SetVector already used DenseSet, but SmallSetVector used std::set.  This
leads to surprising performance differences.  Moreover, it means that
the set of key types accepted by SetVector and SmallSetVector are
quite different!

In order to make this change, we had to convert some callsites that used
SmallSetVector to use SmallSetVector
instead.

Reviewers: timshen

Subscribers: llvm-commits

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

Modified:
cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearchOptions.h?rev=284887&r1=284886&r2=284887&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearchOptions.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearchOptions.h Fri Oct 21 16:45:01 2016
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/CachedHashString.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -144,7 +145,7 @@ public:
 
   /// \brief The set of macro names that should be ignored for the purposes
   /// of computing the module hash.
-  llvm::SmallSetVector ModulesIgnoreMacros;
+  llvm::SmallSetVector ModulesIgnoreMacros;
 
   /// \brief The set of user-provided virtual filesystem overlay files.
   std::vector VFSOverlayFiles;

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=284887&r1=284886&r2=284887&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Fri Oct 21 16:45:01 2016
@@ -11,9 +11,9 @@
 //
 
//===--===//
 
-#include "CGObjCRuntime.h"
 #include "CGBlocks.h"
 #include "CGCleanup.h"
+#include "CGObjCRuntime.h"
 #include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
@@ -25,6 +25,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
 #include "clang/Frontend/CodeGenOptions.h"
+#include "llvm/ADT/CachedHashString.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -843,7 +844,7 @@ protected:
   llvm::DenseMap MethodVarNames;
 
   /// DefinedCategoryNames - list of category names in form Class_Category.
-  llvm::SmallSetVector DefinedCategoryNames;
+  llvm::SmallSetVector DefinedCategoryNames;
 
   /// MethodVarTypes - uniqued method type signatures. We have to use
   /// a StringMap here because have no other unique reference.
@@ -3156,7 +3157,7 @@ void CGObjCMac::GenerateCategory(const O
 "__OBJC,__category,regular,no_dead_strip",
 CGM.getPointerAlign(), true);
   DefinedCategories.push_back(GV);
-  DefinedCategoryNames.insert(ExtName.str());
+  DefinedCategoryNames.insert(llvm::CachedHashString(ExtName));
   // method definition entries must be clear for next implementation.
   MethodDefinitions.clear();
 }

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=284887&r1=284886&r2=284887&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Fri Oct 21 16:45:01 2016
@@ -955,7 +955,8 @@ static bool compileModuleImpl(CompilerIn
   std::remove_if(PPOpts.Macros.begin(), PPOpts.Macros.end(),
  [&HSOpts](const std::pair &def) {
 StringRef MacroDef = def.first;
-return HSOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first) > 0;
+return HSOpts.ModulesIgnoreMacros.count(
+   llvm::CachedHashString(MacroDef.split('=').first)) > 0;
   }),
   PPOpts.Macros.end());
 

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=284887&r1=284886&r2=284887&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Oct 21 16:45:01 2016
@@ -1432,7 +1432,8 @@ static void ParseHeaderSearchArgs(Header
 
   for (const Arg *A : Args.filtered(OPT_f

[clang-tools-extra] r284888 - Remove 'misc-pointer-and-integral-operation' clang-tidy check. The only cases

2016-10-21 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct 21 16:50:28 2016
New Revision: 284888

URL: http://llvm.org/viewvc/llvm-project?rev=284888&view=rev
Log:
Remove 'misc-pointer-and-integral-operation' clang-tidy check. The only cases
it detects are ill-formed (some per C++ core issue 1512, others always have
been).

Removed:
clang-tools-extra/trunk/clang-tidy/misc/PointerAndIntegralOperationCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/PointerAndIntegralOperationCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-pointer-and-integral-operation.rst

clang-tools-extra/trunk/test/clang-tidy/misc-pointer-and-integral-operation-cxx98.cpp

clang-tools-extra/trunk/test/clang-tidy/misc-pointer-and-integral-operation.cpp
Modified:

clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: 
clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml?rev=284888&r1=284887&r2=284888&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy-vs/ClangTidy/Resources/ClangTidyChecks.yaml 
Fri Oct 21 16:50:28 2016
@@ -239,10 +239,6 @@ Checks:
 Description: 
 Name:misc-non-copyable-objects
   - Category:Miscellaneous
-Label:   Suspicious pointer / integer operations
-Description: 
-Name:misc-pointer-and-integral-operation
-  - Category:Miscellaneous
 Label:   Find redundant expressions
 Description: 
 Name:misc-redundant-expression

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=284888&r1=284887&r2=284888&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Fri Oct 21 16:50:28 
2016
@@ -24,7 +24,6 @@ add_clang_library(clangTidyMiscModule
   NewDeleteOverloadsCheck.cpp
   NoexceptMoveConstructorCheck.cpp
   NonCopyableObjects.cpp
-  PointerAndIntegralOperationCheck.cpp
   RedundantExpressionCheck.cpp
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=284888&r1=284887&r2=284888&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Fri Oct 21 
16:50:28 2016
@@ -32,7 +32,6 @@
 #include "NewDeleteOverloadsCheck.h"
 #include "NoexceptMoveConstructorCheck.h"
 #include "NonCopyableObjects.h"
-#include "PointerAndIntegralOperationCheck.h"
 #include "RedundantExpressionCheck.h"
 #include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
@@ -104,8 +103,6 @@ public:
 "misc-noexcept-move-constructor");
 CheckFactories.registerCheck(
 "misc-non-copyable-objects");
-CheckFactories.registerCheck(
-"misc-pointer-and-integral-operation");
 CheckFactories.registerCheck(
 "misc-redundant-expression");
 
CheckFactories.registerCheck("misc-sizeof-container");

Removed: 
clang-tools-extra/trunk/clang-tidy/misc/PointerAndIntegralOperationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/PointerAndIntegralOperationCheck.cpp?rev=284887&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/misc/PointerAndIntegralOperationCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/misc/PointerAndIntegralOperationCheck.cpp 
(removed)
@@ -1,104 +0,0 @@
-//===--- PointerAndIntegralOperationCheck.cpp - 
clang-tidy-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "PointerAndIntegralOperationCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "../utils/Matchers.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace misc {
-
-void PointerAndIntegralOperationCheck::registerMatchers(MatchFinder *Finder) {
-  const auto PointerExpr = e

Re: r284800 - DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' rules.

2016-10-21 Thread Richard Smith via cfe-commits
On Fri, Oct 21, 2016 at 1:13 AM, Renato Golin 
wrote:

> On 21 October 2016 at 03:36, Richard Smith via cfe-commits
>  wrote:
> > Author: rsmith
> > Date: Thu Oct 20 21:36:37 2016
> > New Revision: 284800
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=284800&view=rev
> > Log:
> > DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type'
> rules.
>
> Hi Richard,
>
> This failed all our bots:
>
> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-42vma/builds/13274
>
> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/11260
>
> http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15/builds/16281
>
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/15991
>
> I've reverted in r284811.
>
> Let me know if you need help testing.


 msan bug fixed in r284886, now-redundant clang-tidy check removed in
r284888, re-committed as r284890.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r284890 - DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' rules.

2016-10-21 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct 21 17:00:42 2016
New Revision: 284890

URL: http://llvm.org/viewvc/llvm-project?rev=284890&view=rev
Log:
DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' rules.
This has two significant effects:

1) Direct relational comparisons between null pointer constants (0 and nullopt)
   and pointers are now ill-formed. This was always the case for C, and it
   appears that C++ only ever permitted by accident. For instance, cases like
 nullptr < &a
   are now rejected.

2) Comparisons and conditional operators between differently-cv-qualified
   pointer types now work, and produce a composite type that both source
   pointer types can convert to (when possible). For instance, comparison
   between 'int **' and 'const int **' is now valid, and uses an intermediate
   type of 'const int *const *'.

Clang previously supported #2 as an extension.

We do not accept the cases in #1 as an extension. I've tested a fair amount of
code to check that this doesn't break it, but if it turns out that someone is
relying on this, we can easily add it back as an extension.

This is a re-commit of r284800.

Added:
cfe/trunk/test/CXX/over/over.built/p15.cpp
  - copied unchanged from r284810, 
cfe/trunk/test/CXX/over/over.built/p15.cpp
cfe/trunk/test/CXX/over/over.built/p16.cpp
  - copied unchanged from r284810, 
cfe/trunk/test/CXX/over/over.built/p16.cpp
cfe/trunk/test/SemaCXX/libstdcxx_libcxx_less_hack.cpp
  - copied unchanged from r284810, 
cfe/trunk/test/SemaCXX/libstdcxx_libcxx_less_hack.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CXX/drs/dr15xx.cpp
cfe/trunk/test/CXX/drs/dr5xx.cpp
cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp
cfe/trunk/test/Misc/warning-flags.c
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/distribute_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/target_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/taskloop_simd_aligned_messages.cpp
cfe/trunk/test/SemaCXX/compare.cpp
cfe/trunk/test/SemaCXX/composite-pointer-type.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
cfe/trunk/test/SemaCXX/null_in_arithmetic_ops.cpp
cfe/trunk/test/SemaCXX/nullptr.cpp
cfe/trunk/test/SemaCXX/nullptr_in_arithmetic_ops.cpp
cfe/trunk/test/SemaCXX/warn-memsize-comparison.cpp
cfe/trunk/test/SemaObjCXX/null_objc_pointer.mm
cfe/trunk/www/cxx_dr_status.html

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=284890&r1=284889&r2=284890&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Oct 21 17:00:42 
2016
@@ -5536,6 +5536,8 @@ def ext_typecheck_ordered_comparison_of_
   "ordered comparison between pointer and integer (%0 and %1)">;
 def ext_typecheck_ordered_comparison_of_pointer_and_zero : Extension<
   "ordered comparison between pointer and zero (%0 and %1) is an extension">;
+def err_typecheck_ordered_comparison_of_pointer_and_zero : Error<
+  "ordered comparison between pointer and zero (%0 and %1)">;
 def ext_typecheck_ordered_comparison_of_function_pointers : ExtWarn<
   "ordered comparison of function pointers (%0 and %1)">;
 def ext_typecheck_comparison_of_fptr_to_void : Extension<
@@ -5556,9 +5558,6 @@ def err_cond_voidptr_arc : Error <
   "in ARC mode">;
 def err_typecheck_comparison_of_distinct_pointers : Error<
   "comparison of distinct pointer types%diff{ ($ and $)|}0,1">;
-def ext_typecheck_comparison_of_distinct_pointers_nonstandard : ExtWarn<
-  "comparison of distinct pointer types (%0 and %1) uses non-standard "
-  "composite pointer type %2">, InGroup;
 def err_typecheck_op_on_nonoverlapping_address_space_pointers : Error<
   "%select{comparison between %diff{ ($ and $)|}0,1"
   "|arithmetic operation with operands of type %diff{ ($ and $)|}0,1"
@@ -6837,9 +6836,6 @@ def err_typecheck_expect_scalar_operand
   "operand of type %0 where arithmetic or pointer type is required">;
 def err_typecheck_cond_incompatible_operands : Error<
   "incompatible operand types%diff{ ($ and $)|}0,1">;
-def ext_typecheck_cond_incompatible_operands_nonstandard : ExtWarn<
-  "incompatible operand types%diff{ ($ and $)|}0,1 use non-standard composite "
-  "pointer type %2">;
 def err_cast_selector_expr : Error<
   "cannot type cast @selector

[PATCH] D25838: [Fuchsia] Support for 32-bit architectures

2016-10-21 Thread Petr Hosek via cfe-commits
phosek retitled this revision from "[Fuchsia] Support for additional 
architectures" to "[Fuchsia] Support for 32-bit architectures".
phosek updated the summary for this revision.
phosek updated this revision to Diff 75496.

Repository:
  rL LLVM

https://reviews.llvm.org/D25838

Files:
  lib/Basic/Targets.cpp


Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -8296,20 +8296,22 @@
   return new CloudABITargetInfo(Triple, Opts);
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::Linux:
   return new LinuxTargetInfo(Triple, Opts);
 case llvm::Triple::NetBSD:
   return new NetBSDTargetInfo(Triple, Opts);
-case llvm::Triple::Fuchsia:
-  return new FuchsiaTargetInfo(Triple, Opts);
 default:
   return new AArch64leTargetInfo(Triple, Opts);
 }
 
   case llvm::Triple::aarch64_be:
 switch (os) {
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::Linux:
   return new LinuxTargetInfo(Triple, Opts);
 case llvm::Triple::NetBSD:
@@ -8330,6 +8332,8 @@
   return new LinuxTargetInfo(Triple, Opts);
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::NetBSD:
   return new NetBSDTargetInfo(Triple, Opts);
 case llvm::Triple::OpenBSD:
@@ -8366,6 +8370,8 @@
   return new LinuxTargetInfo(Triple, Opts);
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::NetBSD:
   return new NetBSDTargetInfo(Triple, Opts);
 case llvm::Triple::OpenBSD:
@@ -8596,6 +8602,8 @@
   return new BitrigI386TargetInfo(Triple, Opts);
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::KFreeBSD:
   return new KFreeBSDTargetInfo(Triple, Opts);
 case llvm::Triple::Minix:
@@ -8651,6 +8659,8 @@
   return new BitrigX86_64TargetInfo(Triple, Opts);
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::KFreeBSD:
   return new KFreeBSDTargetInfo(Triple, Opts);
 case llvm::Triple::Solaris:
@@ -8670,8 +8680,6 @@
   return new HaikuTargetInfo(Triple, Opts);
 case llvm::Triple::NaCl:
   return new NaClTargetInfo(Triple, Opts);
-case llvm::Triple::Fuchsia:
-  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::PS4:
   return new PS4OSTargetInfo(Triple, Opts);
 default:


Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -8296,20 +8296,22 @@
   return new CloudABITargetInfo(Triple, Opts);
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::Linux:
   return new LinuxTargetInfo(Triple, Opts);
 case llvm::Triple::NetBSD:
   return new NetBSDTargetInfo(Triple, Opts);
-case llvm::Triple::Fuchsia:
-  return new FuchsiaTargetInfo(Triple, Opts);
 default:
   return new AArch64leTargetInfo(Triple, Opts);
 }
 
   case llvm::Triple::aarch64_be:
 switch (os) {
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::Linux:
   return new LinuxTargetInfo(Triple, Opts);
 case llvm::Triple::NetBSD:
@@ -8330,6 +8332,8 @@
   return new LinuxTargetInfo(Triple, Opts);
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::NetBSD:
   return new NetBSDTargetInfo(Triple, Opts);
 case llvm::Triple::OpenBSD:
@@ -8366,6 +8370,8 @@
   return new LinuxTargetInfo(Triple, Opts);
 case llvm::Triple::FreeBSD:
   return new FreeBSDTargetInfo(Triple, Opts);
+case llvm::Triple::Fuchsia:
+  return new FuchsiaTargetInfo(Triple, Opts);
 case llvm::Triple::NetBSD:
   return new NetBSDTargetInfo(Triple, Opts);
 case llvm::Triple::OpenBSD:
@@ -8596,6 +8602,8 @@
   return new BitrigI386TargetInfo(Triple, Opts);
 case llvm::Triple::FreeBSD:
   retu

[PATCH] D25882: Remove special error recovery for ::(id)

2016-10-21 Thread Richard Smith via cfe-commits
rsmith added a comment.

Can you also remove the corresponding diagnostic?




Comment at: lib/Parse/ParseExprCXX.cpp:73-75
   PP.EnterToken(ColonToken);
   if (!AtDigraph)
 PP.EnterToken(DigraphToken);

This seems to mess up the cached token buffer in the same way; it's a little 
surprising we don't see problems here too.


https://reviews.llvm.org/D25882



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


[PATCH] D25845: [CUDA] Ignore implicit target attributes during function template instantiation.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added a comment.

To close the loop, we talked about this IRL, and I agree this is the most sane 
option we can come up with.  The user-facing principle is that the signatures 
of function template specializations must match.  We consider CUDA attributes 
to be part of the function's signature.  Therefore the target attributes should 
match.

Now the question is, should the *implicit plus explicit* or *only explicit* 
target attributes match?  To me, implicit+explicit makes more sense on face.  
But the problem is, we need to allow C++ code like

  constexpr template void foo(T);
  template<> void foo(int);

We implicitly make constexpr functions HD.  The template specialization is not 
constexpr, so is not implicitly HD.  But we cannot disallow this code, because 
it's valid C++.  That effectively constrains our choice above to *only 
explicit* target attributes.


https://reviews.llvm.org/D25845



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


[PATCH] D25845: [CUDA] Ignore implicit target attributes during function template instantiation.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added inline comments.



Comment at: include/clang/Sema/Sema.h:9396
+  CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D,
+bool IgnoreImplicitHDAttr = false);
   CUDAFunctionTarget IdentifyCUDATarget(const AttributeList *Attr);

We usually call them "target attributes", not "HD attributes"?



Comment at: lib/Sema/SemaCUDA.cpp:97
+template 
+static bool getAttr(const FunctionDecl *D, bool IgnoreImplicitAttr) {
+  if (Attr *Attribute = D->getAttr()) {

hasAttr?



Comment at: lib/Sema/SemaCUDA.cpp:900
+  }
+}

I don't see where this function is declared?



Comment at: lib/Sema/SemaDeclAttr.cpp:5628
   case AttributeList::AT_CUDAHost:
-handleSimpleAttributeWithExclusions(S, D,
-  Attr);
+if (!D->hasAttr())
+  handleSimpleAttributeWithExclusions(S, D,

Is this a functional change in this patch?  We don't check for duplicates of 
most other attributes, so I'm not sure why it should matter with these.  If it 
does matter, we should have comments...



Comment at: lib/Sema/SemaTemplate.cpp:7046
   if (LangOpts.CUDA &&
-  IdentifyCUDATarget(Specialization) != IdentifyCUDATarget(FD)) {
+  IdentifyCUDATarget(Specialization, true) !=
+  IdentifyCUDATarget(FD, true)) {

http://jlebar.com/2011/12/16/Boolean_parameters_to_API_functions_considered_harmful..html
  :)

At least please do

  IdentifyCUDATarget(Specialization, /* IgnoreImplicitTargetAttrs = */ true);



Comment at: lib/Sema/SemaTemplate.cpp:7168
+  if (LangOpts.CUDA)
+mergeCUDATargetAttributes(FD, Specialization);
   return false;

I am unsure of whether or why we need this anymore, since I don't see this 
declared in any header, and also since I thought we weren't merging attrs 
anymore?



Comment at: lib/Sema/SemaTemplate.cpp:8119
 if (LangOpts.CUDA &&
-IdentifyCUDATarget(Specialization) != IdentifyCUDATarget(Attr)) {
+IdentifyCUDATarget(Specialization, true) != IdentifyCUDATarget(Attr)) {
   FailedCandidates.addCandidate().set(

Same here wrt bool param.


https://reviews.llvm.org/D25845



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


[clang-tools-extra] r284894 - [Release notes] Mention removed Clang-tidy misc-pointer-and-integral-operation check

2016-10-21 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Fri Oct 21 17:35:58 2016
New Revision: 284894

URL: http://llvm.org/viewvc/llvm-project?rev=284894&view=rev
Log:
[Release notes] Mention removed Clang-tidy misc-pointer-and-integral-operation 
check

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=284894&r1=284893&r2=284894&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Fri Oct 21 17:35:58 2016
@@ -73,6 +73,8 @@ Improvements to clang-tidy
   Warns when ``std::move`` is applied to a forwarding reference instead of
   ``std::forward``.
 
+- `misc-pointer-and-integral-operation` check was removed.
+
 - New `misc-use-after-move
   `_ 
check
 


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


[PATCH] D25809: [CUDA] Improved target attribute-based overloading.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added inline comments.



Comment at: lib/Sema/SemaCUDA.cpp:87
+
+  if ((HasHostAttr && HasDeviceAttr) || ForceCUDAHostDeviceDepth > 0)
+return CFT_HostDevice;

Checking ForceCUDAHostDeviceDepth here is...yeah.  Especially because the other 
overload of this function doesn't do it.

I know you get rid of it in the next patch, but how much work would it be to 
get rid of it here?  It definitely makes this patch harder to check.



Comment at: lib/Sema/SemaCUDA.cpp:790
+   LookupResult &Previous) {
+  CUDAFunctionTarget NewTarget = IdentifyCUDATarget(NewFD);
+  for (auto OldND : Previous) {

Nit, can we assert that we're in cuda mode?



Comment at: lib/Sema/SemaCUDA.cpp:791
+  CUDAFunctionTarget NewTarget = IdentifyCUDATarget(NewFD);
+  for (auto OldND : Previous) {
+FunctionDecl *OldFD = OldND->getAsFunction();

If this is just a Decl* or NamedDecl*, can we write out the type?



Comment at: lib/Sema/SemaCUDA.cpp:793
+FunctionDecl *OldFD = OldND->getAsFunction();
+if (!OldFD || OldFD->isFunctionTemplateSpecialization())
+  continue;

Please add a comment explaining why we ignore template specializations.



Comment at: lib/Sema/SemaTemplate.cpp:7044
 
+  // Filter out matches that have different target.
+  if (LangOpts.CUDA &&

Can we have a better comment here?  (And, can we expand upon it in D25845?)



Comment at: lib/Sema/SemaTemplate.cpp:8117
+if (LangOpts.CUDA &&
+IdentifyCUDATarget(Specialization) != IdentifyCUDATarget(Attr)) {
+  FailedCandidates.addCandidate().set(

Can we just pass D here (and thus not write the new overload of 
IdentifyCUDATarget)?



Comment at: test/SemaCUDA/function-template-overload.cu:34
+
+// Can't overload HD template with H or D template, though functions are OK.
+template  __host__ __device__ HDType overload_hd(T a) { return 
HDType(); }

"though non-template functions are OK"?



Comment at: test/SemaCUDA/function-template-overload.cu:44
+// explicitly specialize or instantiate function tempaltes.
+template <> __host__ HType overload_hd(int a);
+// expected-error@-1 {{no function template matches function template 
specialization 'overload_hd'}}

This is OK:

  template  __host__ __device__ HDType overload_hd(T a);
  template <> __host__ HType overload_hd(int a);

but this is not OK:

  template  __host__ HType overload_h_d(T a) { return HType(); }
  template  __device__ DType overload_h_d(T a) { return DType(); }
  template  <> __device__ __host__ DType overload_h_d(long a);

Is the rule that you *can* specialize an HD function template as H or D, but 
you can't go in reverse?  If so, I am not getting that from the commit message 
or comments here.

Like in D25705, please clarify this somewhere in the code (and commit message) 
if this isn't just me blatantly misreading things (which is possible).



Comment at: test/SemaCUDA/function-template-overload.cu:44
+// explicitly specialize or instantiate function tempaltes.
+template <> __host__ HType overload_hd(int a);
+// expected-error@-1 {{no function template matches function template 
specialization 'overload_hd'}}

Please ignore the above comment; it is not correct, but I cannot delete it or 
edit it in phab.  :-/


https://reviews.llvm.org/D25809



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


[PATCH] D25882: Remove special error recovery for ::(id)

2016-10-21 Thread Reid Kleckner via cfe-commits
rnk added inline comments.



Comment at: lib/Parse/ParseExprCXX.cpp:73-75
   PP.EnterToken(ColonToken);
   if (!AtDigraph)
 PP.EnterToken(DigraphToken);

rsmith wrote:
> This seems to mess up the cached token buffer in the same way; it's a little 
> surprising we don't see problems here too.
Fuzzing shows that there are more ways to trigger this assertion, so whether we 
keep this recovery mode or not, we might want to implement that token rewrite 
functionality.


https://reviews.llvm.org/D25882



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


[PATCH] D25809: [CUDA] Improved target attribute-based overloading.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added inline comments.



Comment at: test/SemaCUDA/function-template-overload.cu:44
+// explicitly specialize or instantiate function tempaltes.
+template <> __host__ HType overload_hd(int a);
+// expected-error@-1 {{no function template matches function template 
specialization 'overload_hd'}}

jlebar wrote:
> Please ignore the above comment; it is not correct, but I cannot delete it or 
> edit it in phab.  :-/
(Wow, it also didn't submit the comment I was referring to.  How broken.)


https://reviews.llvm.org/D25809



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


r284895 - Remove unnecessary distinction between Ref_Compatible and

2016-10-21 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct 21 18:01:55 2016
New Revision: 284895

URL: http://llvm.org/viewvc/llvm-project?rev=284895&view=rev
Log:
Remove unnecessary distinction between Ref_Compatible and
Ref_Compatible_With_Added_Qualification. We always treated these two values the
same way.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCast.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=284895&r1=284894&r2=284895&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Oct 21 18:01:55 2016
@@ -8992,13 +8992,7 @@ public:
 /// that their unqualified forms (T1 and T2) are either the same
 /// or T1 is a base class of T2.
 Ref_Related,
-/// Ref_Compatible_With_Added_Qualification - The two types are
-/// reference-compatible with added qualification, meaning that
-/// they are reference-compatible and the qualifiers on T1 (cv1)
-/// are greater than the qualifiers on T2 (cv2).
-Ref_Compatible_With_Added_Qualification,
-/// Ref_Compatible - The two types are reference-compatible and
-/// have equivalent qualifiers (cv1 == cv2).
+/// Ref_Compatible - The two types are reference-compatible.
 Ref_Compatible
   };
 

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=284895&r1=284894&r2=284895&view=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Fri Oct 21 18:01:55 2016
@@ -1165,7 +1165,7 @@ TryLValueToRValueCast(Sema &Self, Expr *
 ToType, FromType,
 DerivedToBase, ObjCConversion,
 ObjCLifetimeConversion) 
-< Sema::Ref_Compatible_With_Added_Qualification) {
+!= Sema::Ref_Compatible) {
 if (CStyle)
   return TC_NotApplicable;
 msg = diag::err_bad_lvalue_to_rvalue_cast;

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=284895&r1=284894&r2=284895&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Oct 21 18:01:55 2016
@@ -4263,7 +4263,7 @@ static void TryReferenceInitializationCo
   bool T1Function = T1->isFunctionType();
   if (isLValueRef || T1Function) {
 if (InitCategory.isLValue() &&
-(RefRelationship >= Sema::Ref_Compatible_With_Added_Qualification ||
+(RefRelationship == Sema::Ref_Compatible ||
  (Kind.isCStyleOrFunctionalCast() &&
   RefRelationship == Sema::Ref_Related))) {
   //   - is an lvalue (but is not a bit-field), and "cv1 T1" is
@@ -4336,7 +4336,7 @@ static void TryReferenceInitializationCo
   //"cv1 T1" is reference-compatible with "cv2 T2"
   // Note: functions are handled below.
   if (!T1Function &&
-  (RefRelationship >= Sema::Ref_Compatible_With_Added_Qualification ||
+  (RefRelationship == Sema::Ref_Compatible ||
(Kind.isCStyleOrFunctionalCast() &&
 RefRelationship == Sema::Ref_Related)) &&
   (InitCategory.isXValue() ||
@@ -4393,8 +4393,7 @@ static void TryReferenceInitializationCo
   return;
 }
 
-if ((RefRelationship == Sema::Ref_Compatible ||
- RefRelationship == Sema::Ref_Compatible_With_Added_Qualification) &&
+if (RefRelationship == Sema::Ref_Compatible &&
 isRValueRef && InitCategory.isLValue()) {
   Sequence.SetFailed(
 InitializationSequence::FK_RValueReferenceBindingToLValue);

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=284895&r1=284894&r2=284895&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Oct 21 18:01:55 2016
@@ -4220,10 +4220,8 @@ Sema::CompareReferenceRelationship(Sourc
   T1Quals.removeUnaligned();
   T2Quals.removeUnaligned();
 
-  if (T1Quals == T2Quals)
+  if (T1Quals.compatiblyIncludes(T2Quals))
 return Ref_Compatible;
-  else if (T1Quals.compatiblyIncludes(T2Quals))
-return Ref_Compatible_With_Added_Qualification;
   else
 return Ref_Related;
 }
@@ -4401,8 +4399,7 @@ TryReferenceInit(Sema &S, Expr *Init, Qu
 //reference-compatible with "cv2 T2," or
 //
 // Per C++ [over.ics.ref]p4, we don't check the bit-field property here.
-if (InitCategory.isLValue() &&
-RefRelationship >= Sema::Ref_Compatible_With_Added_Qualificati

[PATCH] D25640: [CUDA] [AST] Allow isInlineDefinitionExternallyVisible to be called on functions without bodies.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added a comment.

Friendly ping.  This assert breaks basically all cuda compilation on certain 
libstdc++ versions.  If this change is wrong, I sort of urgently need to figure 
out the right thing.


https://reviews.llvm.org/D25640



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


r284897 - Module: improve the diagnostic message for include of non-modular header.

2016-10-21 Thread Manman Ren via cfe-commits
Author: mren
Date: Fri Oct 21 18:27:37 2016
New Revision: 284897

URL: http://llvm.org/viewvc/llvm-project?rev=284897&view=rev
Log:
Module: improve the diagnostic message for include of non-modular header.

Emit the actual path to the non-modular include.

rdar://28897010

Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/test/Modules/incomplete-module.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=284897&r1=284896&r2=284897&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Fri Oct 21 18:27:37 2016
@@ -659,10 +659,10 @@ def warn_use_of_private_header_outside_m
 def err_undeclared_use_of_module : Error<
   "module %0 does not depend on a module exporting '%1'">;
 def warn_non_modular_include_in_framework_module : Warning<
-  "include of non-modular header inside framework module '%0'">,
+  "include of non-modular header inside framework module '%0': '%1'">,
   InGroup, DefaultIgnore;
 def warn_non_modular_include_in_module : Warning<
-  "include of non-modular header inside module '%0'">,
+  "include of non-modular header inside module '%0': '%1'">,
   InGroup, DefaultIgnore;
 def warn_module_conflict : Warning<
   "module '%0' conflicts with already-imported module '%1': %2">, 

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=284897&r1=284896&r2=284897&view=diff
==
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Oct 21 18:27:37 2016
@@ -303,7 +303,8 @@ void ModuleMap::diagnoseHeaderInclusion(
 diag::kind DiagID = RequestingModule->getTopLevelModule()->IsFramework ?
 diag::warn_non_modular_include_in_framework_module :
 diag::warn_non_modular_include_in_module;
-Diags.Report(FilenameLoc, DiagID) << RequestingModule->getFullModuleName();
+Diags.Report(FilenameLoc, DiagID) << RequestingModule->getFullModuleName()
+<< File->getName();
   }
 }
 

Modified: cfe/trunk/test/Modules/incomplete-module.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/incomplete-module.m?rev=284897&r1=284896&r2=284897&view=diff
==
--- cfe/trunk/test/Modules/incomplete-module.m (original)
+++ cfe/trunk/test/Modules/incomplete-module.m Fri Oct 21 18:27:37 2016
@@ -2,7 +2,7 @@
 
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules-cache-path=%t -Wincomplete-module -fmodules 
-fimplicit-module-maps -I %S/Inputs %s 2>&1 | FileCheck %s
-// CHECK: warning: include of non-modular header inside module 'incomplete_mod'
+// CHECK: warning: include of non-modular header inside module 
'incomplete_mod': {{'.*incomplete_mod_missing.h'}}
 
 // RUN: rm -rf %t
 // RUN: not %clang_cc1 -fmodules-cache-path=%t -fmodules-strict-decluse 
-fmodules -fimplicit-module-maps -I %S/Inputs %s 2>&1 | FileCheck %s 
-check-prefix=DECLUSE


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


[PATCH] D25882: Remove special error recovery for ::(id)

2016-10-21 Thread Reid Kleckner via cfe-commits
rnk updated this revision to Diff 75509.
rnk added a comment.

- Remove unused diagnostic


https://reviews.llvm.org/D25882

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Parse/Parser.h
  lib/Parse/ParseExprCXX.cpp
  test/Parser/colon-colon-parentheses.cpp

Index: test/Parser/colon-colon-parentheses.cpp
===
--- test/Parser/colon-colon-parentheses.cpp
+++ test/Parser/colon-colon-parentheses.cpp
@@ -1,30 +1,36 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify -DPR21815
-// RUN: cp %s %t
-// RUN: not %clang_cc1 -x c++ -fixit %t
-// RUN: %clang_cc1 -x c++ %t
+// RUN: %clang_cc1 %s -verify -fno-spell-checking
 
 struct S { static int a,b,c;};
-int S::(a);  // expected-error{{unexpected parenthesis after '::'}}
-int S::(b;  // expected-error{{unexpected parenthesis after '::'}}
+int S::(a);  // expected-error{{expected unqualified-id}}
+int S::(b;  // expected-error{{expected unqualified-id}}
+);
 int S::c;
-int S::(*d);  // expected-error{{unexpected parenthesis after '::'}}
-int S::(*e;  // expected-error{{unexpected parenthesis after '::'}}
+int S::(*d);  // expected-error{{expected unqualified-id}}
+int S::(*e;  // expected-error{{expected unqualified-id}}
+);
 int S::*f;
-int g = S::(a);  // expected-error{{unexpected parenthesis after '::'}}
-int h = S::(b;  // expected-error{{unexpected parenthesis after '::'}}
+int g = S::(a);  // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'a'}}
+int h = S::(b;  // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'b'}}
+);
 int i = S::c;
 
 void foo() {
   int a;
-  a = ::(g);  // expected-error{{unexpected parenthesis after '::'}}
-  a = ::(h;  // expected-error{{unexpected parenthesis after '::'}}
+  a = ::(g);  // expected-error{{expected unqualified-id}}
+  a = ::(h;  // expected-error{{expected unqualified-id}}
   a = ::i;
 }
 
-#ifdef PR21815
+// The following tests used to be crash bugs.
+
+// PR21815
 // expected-error@+2{{C++ requires a type specifier for all declarations}}
 // expected-error@+1{{expected unqualified-id}}
 a (::( ));
 
 ::((c )); // expected-error{{expected unqualified-id}}
-#endif
+
+// PR26623
+int f1(::(B) p); // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'B'}}
+
+int f2(::S::(C) p); // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'C'}}
Index: lib/Parse/ParseExprCXX.cpp
===
--- lib/Parse/ParseExprCXX.cpp
+++ lib/Parse/ParseExprCXX.cpp
@@ -100,48 +100,6 @@
  /*AtDigraph*/false);
 }
 
-/// \brief Emits an error for a left parentheses after a double colon.
-///
-/// When a '(' is found after a '::', emit an error.  Attempt to fix the token
-/// stream by removing the '(', and the matching ')' if found.
-void Parser::CheckForLParenAfterColonColon() {
-  if (!Tok.is(tok::l_paren))
-return;
-
-  Token LParen = Tok;
-  Token NextTok = GetLookAheadToken(1);
-  Token StarTok = NextTok;
-  // Check for (identifier or (*identifier
-  Token IdentifierTok = StarTok.is(tok::star) ? GetLookAheadToken(2) : StarTok;
-  if (IdentifierTok.isNot(tok::identifier))
-return;
-  // Eat the '('.
-  ConsumeParen();
-  Token RParen;
-  RParen.setLocation(SourceLocation());
-  // Do we have a ')' ?
-  NextTok = StarTok.is(tok::star) ? GetLookAheadToken(2) : GetLookAheadToken(1);
-  if (NextTok.is(tok::r_paren)) {
-RParen = NextTok;
-// Eat the '*' if it is present.
-if (StarTok.is(tok::star))
-  ConsumeToken();
-// Eat the identifier.
-ConsumeToken();
-// Add the identifier token back.
-PP.EnterToken(IdentifierTok);
-// Add the '*' back if it was present.
-if (StarTok.is(tok::star))
-  PP.EnterToken(StarTok);
-// Eat the ')'.
-ConsumeParen();
-  }
-
-  Diag(LParen.getLocation(), diag::err_paren_after_colon_colon)
-  << FixItHint::CreateRemoval(LParen.getLocation())
-  << FixItHint::CreateRemoval(RParen.getLocation());
-}
-
 /// \brief Parse global scope or nested-name-specifier if present.
 ///
 /// Parses a C++ global scope specifier ('::') or nested-name-specifier (which
@@ -237,8 +195,6 @@
   if (Actions.ActOnCXXGlobalScopeSpecifier(ConsumeToken(), SS))
 return true;
 
-  CheckForLParenAfterColonColon();
-
   HasScopeSpecifier = true;
 }
   }
@@ -491,8 +447,6 @@
   Token ColonColon = Tok;
   SourceLocation CCLoc = ConsumeToken();
 
-  CheckForLParenAfterColonColon();
-
   bool IsCorrectedToColon = false;
   bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon : nullptr;
   if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), IdInfo,
Index: include/clang/Parse/Parser.h
===
--- include/clang/Parse/Parser.h
+++ include/clang

[PATCH] D25806: Module: correctly set the module file kind when emitting diagnostics for file_modified

2016-10-21 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284899: Module: correctly set the module file kind when 
emitting file_modified. (authored by mren).

Changed prior to commit:
  https://reviews.llvm.org/D25806?vs=75326&id=75510#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25806

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/test/Modules/module-file-modified.c


Index: cfe/trunk/lib/Serialization/ASTReader.cpp
===
--- cfe/trunk/lib/Serialization/ASTReader.cpp
+++ cfe/trunk/lib/Serialization/ASTReader.cpp
@@ -1983,6 +1983,7 @@
   return R;
 }
 
+static unsigned moduleKindForDiagnostic(ModuleKind Kind);
 InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
   // If this ID is bogus, just return an empty input file.
   if (ID == 0 || ID > F.InputFilesLoaded.size())
@@ -2079,7 +2080,13 @@
 
   // The top-level PCH is stale.
   StringRef TopLevelPCHName(ImportStack.back()->FileName);
-  Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  unsigned DiagnosticKind = 
moduleKindForDiagnostic(ImportStack.back()->Kind);
+  if (DiagnosticKind == 0)
+Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  else if (DiagnosticKind == 1)
+Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
+  else
+Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
 
   // Print the import stack.
   if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
Index: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -21,6 +21,12 @@
 def err_fe_pch_file_modified : Error<
 "file '%0' has been modified since the precompiled header '%1' was built">,
 DefaultFatal;
+def err_fe_module_file_modified : Error<
+"file '%0' has been modified since the module file '%1' was built">,
+DefaultFatal;
+def err_fe_ast_file_modified : Error<
+"file '%0' has been modified since the AST file '%1' was built">,
+DefaultFatal;
 def err_fe_pch_file_overridden : Error<
 "file '%0' from the precompiled header has been overridden">;
 def note_pch_required_by : Note<"'%0' required by '%1'">;
Index: cfe/trunk/test/Modules/module-file-modified.c
===
--- cfe/trunk/test/Modules/module-file-modified.c
+++ cfe/trunk/test/Modules/module-file-modified.c
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo 'int foo = 0;' > %t/a.h
+// RUN: echo 'module A { header "a.h" }' > %t/m.modulemap
+// RUN: %clang_cc1 -fmodules -emit-module -fmodule-name=A -x c %t/m.modulemap 
-o %t/m.pcm
+// RUN: echo 'int bar;' > %t/a.h
+// RUN: not %clang_cc1 -fmodules -fmodule-file=%t/m.pcm 
-fmodule-map-file=%t/m.modulemap -x c %s -I%t -fsyntax-only 2>&1 | FileCheck %s
+#include "a.h"
+int foo = 0; // redefinition of 'foo'
+// CHECK: fatal error: file {{.*}} has been modified since the module file 
{{.*}} was built
+// REQUIRES: shell


Index: cfe/trunk/lib/Serialization/ASTReader.cpp
===
--- cfe/trunk/lib/Serialization/ASTReader.cpp
+++ cfe/trunk/lib/Serialization/ASTReader.cpp
@@ -1983,6 +1983,7 @@
   return R;
 }
 
+static unsigned moduleKindForDiagnostic(ModuleKind Kind);
 InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
   // If this ID is bogus, just return an empty input file.
   if (ID == 0 || ID > F.InputFilesLoaded.size())
@@ -2079,7 +2080,13 @@
 
   // The top-level PCH is stale.
   StringRef TopLevelPCHName(ImportStack.back()->FileName);
-  Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind);
+  if (DiagnosticKind == 0)
+Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  else if (DiagnosticKind == 1)
+Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
+  else
+Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
 
   // Print the import stack.
   if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
Index: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -21,6 +21,12 @@
 def err_fe_pch_file_modified : Error<
 "file '%0' has been modified since the precompiled header '%1' was built">,
 DefaultFatal;
+def err_fe_mo

r284899 - Module: correctly set the module file kind when emitting file_modified.

2016-10-21 Thread Manman Ren via cfe-commits
Author: mren
Date: Fri Oct 21 18:35:03 2016
New Revision: 284899

URL: http://llvm.org/viewvc/llvm-project?rev=284899&view=rev
Log:
Module: correctly set the module file kind when emitting file_modified.

rdar://28503343

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

Added:
cfe/trunk/test/Modules/module-file-modified.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=284899&r1=284898&r2=284899&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Fri Oct 21 
18:35:03 2016
@@ -21,6 +21,12 @@ def err_fe_pch_malformed_block : Error<
 def err_fe_pch_file_modified : Error<
 "file '%0' has been modified since the precompiled header '%1' was built">,
 DefaultFatal;
+def err_fe_module_file_modified : Error<
+"file '%0' has been modified since the module file '%1' was built">,
+DefaultFatal;
+def err_fe_ast_file_modified : Error<
+"file '%0' has been modified since the AST file '%1' was built">,
+DefaultFatal;
 def err_fe_pch_file_overridden : Error<
 "file '%0' from the precompiled header has been overridden">;
 def note_pch_required_by : Note<"'%0' required by '%1'">;

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=284899&r1=284898&r2=284899&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Oct 21 18:35:03 2016
@@ -1983,6 +1983,7 @@ ASTReader::readInputFileInfo(ModuleFile
   return R;
 }
 
+static unsigned moduleKindForDiagnostic(ModuleKind Kind);
 InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
   // If this ID is bogus, just return an empty input file.
   if (ID == 0 || ID > F.InputFilesLoaded.size())
@@ -2079,7 +2080,13 @@ InputFile ASTReader::getInputFile(Module
 
   // The top-level PCH is stale.
   StringRef TopLevelPCHName(ImportStack.back()->FileName);
-  Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  unsigned DiagnosticKind = 
moduleKindForDiagnostic(ImportStack.back()->Kind);
+  if (DiagnosticKind == 0)
+Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+  else if (DiagnosticKind == 1)
+Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
+  else
+Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
 
   // Print the import stack.
   if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {

Added: cfe/trunk/test/Modules/module-file-modified.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/module-file-modified.c?rev=284899&view=auto
==
--- cfe/trunk/test/Modules/module-file-modified.c (added)
+++ cfe/trunk/test/Modules/module-file-modified.c Fri Oct 21 18:35:03 2016
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo 'int foo = 0;' > %t/a.h
+// RUN: echo 'module A { header "a.h" }' > %t/m.modulemap
+// RUN: %clang_cc1 -fmodules -emit-module -fmodule-name=A -x c %t/m.modulemap 
-o %t/m.pcm
+// RUN: echo 'int bar;' > %t/a.h
+// RUN: not %clang_cc1 -fmodules -fmodule-file=%t/m.pcm 
-fmodule-map-file=%t/m.modulemap -x c %s -I%t -fsyntax-only 2>&1 | FileCheck %s
+#include "a.h"
+int foo = 0; // redefinition of 'foo'
+// CHECK: fatal error: file {{.*}} has been modified since the module file 
{{.*}} was built
+// REQUIRES: shell


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


[PATCH] D25888: Add support for __builtin_os_log_format[_buffer_size]

2016-10-21 Thread Mehdi AMINI via cfe-commits
mehdi_amini created this revision.
mehdi_amini added a reviewer: bkramer.
mehdi_amini added a subscriber: cfe-commits.
Herald added subscribers: modocache, mgorny, beanz.

These new builtins support a mechanism for logging OS events, using a
printf-like format string to specify the layout of data in a buffer.
The _buffer_size version of the builtin can be used to determine the size
of the buffer to allocate to hold the data, and then __builtin_os_log_format
can write data into that buffer. This implements format checking to report
mismatches between the format string and the data arguments. Most of this
code was written by Chris Willmore.


https://reviews.llvm.org/D25888

Files:
  clang/include/clang/Analysis/Analyses/FormatString.h
  clang/include/clang/Analysis/Analyses/OSLog.h
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Analysis/FormatString.cpp
  clang/lib/Analysis/OSLog.cpp
  clang/lib/Analysis/PrintfFormatString.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/builtins.c
  clang/test/CodeGenObjC/os_log.m
  clang/test/SemaObjC/format-strings-oslog.m

Index: clang/test/SemaObjC/format-strings-oslog.m
===
--- /dev/null
+++ clang/test/SemaObjC/format-strings-oslog.m
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#include 
+#include 
+#define __need_wint_t
+#include  // For wint_t and wchar_t
+
+int printf(const char *restrict, ...);
+
+@interface NSString
+@end
+
+void test_os_log_format(const char *pc, int i, void *p, void *buf) {
+  __builtin_os_log_format(buf, "");
+  __builtin_os_log_format(buf, "%d"); // expected-warning {{more '%' conversions than data arguments}}
+  __builtin_os_log_format(buf, "%d", i);
+  __builtin_os_log_format(buf, "%P", p); // expected-warning {{using '%P' format specifier without precision}}
+  __builtin_os_log_format(buf, "%.10P", p);
+  __builtin_os_log_format(buf, "%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}}
+  __builtin_os_log_format(buf, "%.*P", i, p);
+  __builtin_os_log_format(buf, "%.*P", i, i); // expected-warning {{format specifies type 'void *' but the argument has type 'int'}}
+  __builtin_os_log_format(buf, "%n"); // expected-error {{os_log() '%n' format specifier is not allowed}}
+  __builtin_os_log_format(buf, pc);   // expected-error {{os_log() format argument is not a string constant}}
+
+  printf("%{private}s", pc); // expected-warning {{using 'private' format specifier annotation outside of os_log()/os_trace()}}
+  __builtin_os_log_format(buf, "%{private}s", pc);
+
+  // 
+  __builtin_os_log_format_buffer_size("no-args");
+  __builtin_os_log_format(buf, "%s", "hi");
+
+  // 
+  wchar_t wc = 'a';
+  __builtin_os_log_format(buf, "%C", wc);
+  printf("%C", wc);
+  wchar_t wcs[] = {'a', 0};
+  __builtin_os_log_format(buf, "%S", wcs);
+  printf("%S", wcs);
+}
+
+// Test os_log_format primitive with ObjC string literal format argument.
+void test_objc(const char *pc, int i, void *p, void *buf, NSString *nss) {
+  __builtin_os_log_format(buf, @"");
+  __builtin_os_log_format(buf, @"%d"); // expected-warning {{more '%' conversions than data arguments}}
+  __builtin_os_log_format(buf, @"%d", i);
+  __builtin_os_log_format(buf, @"%P", p); // expected-warning {{using '%P' format specifier without precision}}
+  __builtin_os_log_format(buf, @"%.10P", p);
+  __builtin_os_log_format(buf, @"%.*P", p); // expected-warning {{field precision should have type 'int', but argument has type 'void *'}}
+  __builtin_os_log_format(buf, @"%.*P", i, p);
+  __builtin_os_log_format(buf, @"%.*P", i, i); // expected-warning {{format specifies type 'void *' but the argument has type 'int'}}
+
+  __builtin_os_log_format(buf, @"%{private}s", pc);
+  __builtin_os_log_format(buf, @"%@", nss);
+}
+
+// Test the os_log format attribute.
+void MyOSLog(const char *format, ...) __attribute__((format(os_log, 1, 2)));
+void test_attribute(void *p) {
+  MyOSLog("%s\n", "Hello");
+  MyOSLog("%d");// expected-warning {{more '%' conversions than data arguments}}
+  MyOSLog("%P", p); // expected-warning {{using '%P' format specifier without precision}}
+}
Index: clang/test/CodeGenObjC/os_log.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/os_log.m
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 | FileCheck %s
+
+// Make sure we emit clang.arc.use before calling objc_release as part of the
+// cleanup. This way we make sure the object will not be released until the
+// end of the full expression.
+
+// rdar://problem/24528966
+
+@class NSString;
+extern __attribute__((visibility("default"))) NSString *GenString();
+
+// Behavi

[PATCH] D25206: [Parser] Correct typo after lambda capture initializer is parsed

2016-10-21 Thread Akira Hatanaka via cfe-commits
ahatanak added a comment.

ping


https://reviews.llvm.org/D25206



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


  1   2   >