[PATCH] D18473: AMDGPU: Add test for generic builtin behavior

2016-03-25 Thread Matt Arsenault via cfe-commits
arsenm created this revision.
arsenm added a reviewer: tstellarAMD.
arsenm added a subscriber: cfe-commits.

This is the same as the default implementation, but
add a comment and make sure the behavior is tested.

http://reviews.llvm.org/D18473

Files:
  lib/Basic/Targets.cpp
  test/CodeGenOpenCL/builtins-generic-amdgcn.cl

Index: test/CodeGenOpenCL/builtins-generic-amdgcn.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/builtins-generic-amdgcn.cl
@@ -0,0 +1,16 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK-LABEL: @test_builtin_clz(
+// CHECK: tail call i32 @llvm.ctlz.i32(i32 %a, i1 true)
+void test_builtin_clz(global int* out, int a)
+{
+  *out = __builtin_clz(a);
+}
+
+// CHECK-LABEL: @test_builtin_clzl(
+// CHECK: tail call i64 @llvm.ctlz.i64(i64 %a, i1 true)
+void test_builtin_clzl(global long* out, long a)
+{
+  *out = __builtin_clzl(a);
+}
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1851,6 +1851,11 @@
 clang::AMDGPU::LastTSBuiltin - 
Builtin::FirstTSBuiltin);
   }
 
+  bool isCLZForZeroUndef() const override {
+// It is -1 instead of expected for intrinsic.
+return true;
+  }
+
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 if (getTriple().getArch() == llvm::Triple::amdgcn)


Index: test/CodeGenOpenCL/builtins-generic-amdgcn.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/builtins-generic-amdgcn.cl
@@ -0,0 +1,16 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: @test_builtin_clz(
+// CHECK: tail call i32 @llvm.ctlz.i32(i32 %a, i1 true)
+void test_builtin_clz(global int* out, int a)
+{
+  *out = __builtin_clz(a);
+}
+
+// CHECK-LABEL: @test_builtin_clzl(
+// CHECK: tail call i64 @llvm.ctlz.i64(i64 %a, i1 true)
+void test_builtin_clzl(global long* out, long a)
+{
+  *out = __builtin_clzl(a);
+}
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1851,6 +1851,11 @@
 clang::AMDGPU::LastTSBuiltin - Builtin::FirstTSBuiltin);
   }
 
+  bool isCLZForZeroUndef() const override {
+// It is -1 instead of expected for intrinsic.
+return true;
+  }
+
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 if (getTriple().getArch() == llvm::Triple::amdgcn)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17987: [clang-tidy] Extension of checker misc-misplaced-widening-cast

2016-03-25 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware updated this revision to Diff 51633.
baloghadamsoftware added a comment.

Requested revision done.


http://reviews.llvm.org/D17987

Files:
  clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
  clang-tidy/misc/MisplacedWideningCastCheck.cpp
  clang-tidy/misc/MisplacedWideningCastCheck.h
  docs/clang-tidy/checks/misc-misplaced-widening-cast.rst
  test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
  test/clang-tidy/misc-misplaced-widening-cast.cpp

Index: test/clang-tidy/misc-misplaced-widening-cast.cpp
===
--- test/clang-tidy/misc-misplaced-widening-cast.cpp
+++ test/clang-tidy/misc-misplaced-widening-cast.cpp
@@ -1,29 +1,67 @@
-// RUN: %check_clang_tidy %s misc-misplaced-widening-cast %t
+// RUN: %check_clang_tidy %s misc-misplaced-widening-cast %t -- -config="{CheckOptions: [{key: misc-misplaced-widening-cast.CheckImplicitCasts, value: 1}]}" --
+
+void func(long arg) {}
 
 void assign(int a, int b) {
   long l;
 
   l = a * b;
-  l = (long)(a * b);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long' is ineffective, or there is loss of precision before the conversion [misc-misplaced-widening-cast]
+  l = (long)(a * b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long'
   l = (long)a * b;
 
+  l = a << 8;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long'
   l = (long)(a << 8);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long'
   l = (long)b << 8;
 
   l = static_cast(a * b);
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long' is ineffective, or there is loss of precision before the conversion [misc-misplaced-widening-cast]
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long'
+}
+
+void compare(int a, int b, long c) {
+  bool l;
+
+  l = a * b == c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long'
+  l = c == a * b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: either cast from 'int' to 'long'
+  l = (long)(a * b) == c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long'
+  l = c == (long)(a * b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: either cast from 'int' to 'long'
+  l = (long)a * b == c;
+  l = c == (long)a * b;
 }
 
 void init(unsigned int n) {
-  long l = (long)(n << 8);
-  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: either cast from 'unsigned int'
+  long l1 = n << 8;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: either cast from 'unsigned int' to 'long'
+  long l2 = (long)(n << 8);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: either cast from 'unsigned int' to 'long'
+  long l3 = (long)n << 8;
+}
+
+void call(unsigned int n) {
+  func(n << 8);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: either cast from 'unsigned int' to 'long'
+  func((long)(n << 8));
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: either cast from 'unsigned int' to 'long'
+  func((long)n << 8);
 }
 
 long ret(int a) {
-  return (long)(a * 1000);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: either cast from 'int' to 'long'
+  if (a < 0) {
+return a * 1000;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: either cast from 'int' to 'long'
+  } else if (a > 0) {
+return (long)(a * 1000);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: either cast from 'int' to 'long'
+  } else {
+return (long)a * 1000;
+  }
 }
 
 void dontwarn1(unsigned char a, int i, unsigned char *p) {
@@ -33,9 +71,9 @@
   // The result is a 12 bit value, there is no truncation in the implicit cast.
   l = (long)(a << 4);
   // The result is a 3 bit value, there is no truncation in the implicit cast.
-  l = (long)((i%5)+1);
+  l = (long)((i % 5) + 1);
   // The result is a 16 bit value, there is no truncation in the implicit cast.
-  l = (long)(((*p)<<8) + *(p+1));
+  l = (long)(((*p) << 8) + *(p + 1));
 }
 
 template  struct DontWarn2 {
Index: test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
@@ -0,0 +1,58 @@
+// RUN: %check_clang_tidy %s misc-misplaced-widening-cast %t -- -config="{CheckOptions: [{key: misc-misplaced-widening-cast.CheckImplicitCasts, value: 0}]}" --
+
+void func(long arg) {}
+
+void assign(int a, int b) {
+  long l;
+
+  l = a * b;
+  l = (long)(a * b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long' is ineffective, or there is loss of precision before the conversion [misc-misplaced-widening-cast]
+  l = (long)a * b;
+
+  l = a << 8;
+  l = (long)(a << 8);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long'
+  l = (long)b << 8;
+
+  l = static_cast(a * b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: either cast from 'int' to 'long'
+}
+
+void compare(int a, int b, 

Re: [PATCH] D17987: [clang-tidy] Extension of checker misc-misplaced-widening-cast

2016-03-25 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware marked 9 inline comments as done.


Comment at: clang-tidy/misc/MisplacedWideningCastCheck.cpp:117
@@ +116,3 @@
+static llvm::SmallDenseMap createRelativeCharSizesMap() {
+  llvm::SmallDenseMap Result(6);
+  Result[BuiltinType::UChar] = 1;

I changed to SmallDenseMap and its lookup() member function is nice. However it 
unfortunately lacks an initializer_list constructor.


Comment at: clang-tidy/misc/MisplacedWideningCastCheck.cpp:188
@@ -114,1 +187,3 @@
+if (CastBuiltinType && CalcBuiltinType &&
+!isFirstWider(CastBuiltinType->getKind(), CalcBuiltinType->getKind()))
   return;

Is this an LLVM style rule? I always learned that it is the safest to use 
braces even for single-line if bodies.


http://reviews.llvm.org/D17987



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


Re: [PATCH] D17516: AMDGPU: Verify subtarget specific builtins

2016-03-25 Thread Matt Arsenault via cfe-commits
arsenm updated this revision to Diff 51636.
arsenm added a comment.

Try to move more code into initFeatureMap.

I'm not sure how the booleans for features in the class are for now. X86 seems 
to have them, but it seems they are only used with user specified features? The 
only ones that matter right now don't depend on the subtarget, so I've left 
that in the constructor


http://reviews.llvm.org/D17516

Files:
  include/clang/Basic/BuiltinsAMDGPU.def
  lib/Basic/Targets.cpp
  lib/Driver/Tools.cpp
  test/CodeGenOpenCL/builtins-amdgcn-error.cl
  test/CodeGenOpenCL/builtins-amdgcn-vi.cl
  test/CodeGenOpenCL/builtins-amdgcn.cl
  test/SemaOpenCL/builtins-amdgcn.cl

Index: test/SemaOpenCL/builtins-amdgcn.cl
===
--- test/SemaOpenCL/builtins-amdgcn.cl
+++ /dev/null
@@ -1,6 +0,0 @@
-// RUN: %clang_cc1 -triple amdgcn-unknown-amdhsa -fsyntax-only -verify %s
-
-void test_s_sleep(int x)
-{
-  __builtin_amdgcn_s_sleep(x); // expected-error {{argument to '__builtin_amdgcn_s_sleep' must be a constant integer}}
-}
Index: test/CodeGenOpenCL/builtins-amdgcn.cl
===
--- test/CodeGenOpenCL/builtins-amdgcn.cl
+++ test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -178,13 +178,6 @@
   *out = __builtin_amdgcn_s_memtime();
 }
 
-// CHECK-LABEL: @test_s_memrealtime
-// CHECK: call i64 @llvm.amdgcn.s.memrealtime()
-void test_s_memrealtime(global ulong* out)
-{
-  *out = __builtin_amdgcn_s_memrealtime();
-}
-
 // CHECK-LABEL: @test_s_sleep
 // CHECK: call void @llvm.amdgcn.s.sleep(i32 1)
 // CHECK: call void @llvm.amdgcn.s.sleep(i32 15)
Index: test/CodeGenOpenCL/builtins-amdgcn-vi.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/builtins-amdgcn-vi.cl
@@ -0,0 +1,12 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu tonga -S -emit-llvm -o - %s | FileCheck %s
+
+typedef unsigned long ulong;
+
+
+// CHECK-LABEL: @test_s_memrealtime
+// CHECK: call i64 @llvm.amdgcn.s.memrealtime()
+void test_s_memrealtime(global ulong* out)
+{
+  *out = __builtin_amdgcn_s_memrealtime();
+}
Index: test/CodeGenOpenCL/builtins-amdgcn-error.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/builtins-amdgcn-error.cl
@@ -0,0 +1,18 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-amdhsa -target-cpu tahiti -verify -S -o - %s
+
+// FIXME: We only get one error if the functions are the other order in the
+// file.
+
+typedef unsigned long ulong;
+
+ulong test_s_memrealtime()
+{
+  return __builtin_amdgcn_s_memrealtime(); // expected-error {{'__builtin_amdgcn_s_memrealtime' needs target feature s-memrealtime}}
+}
+
+void test_s_sleep(int x)
+{
+  __builtin_amdgcn_s_sleep(x); // expected-error {{argument to '__builtin_amdgcn_s_sleep' must be a constant integer}}
+}
+
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1839,8 +1839,9 @@
   case llvm::Triple::systemz:
 return getSystemZTargetCPU(Args);
 
-  case llvm::Triple::r600:
   case llvm::Triple::amdgcn:
+return getAMDGCNTargetGPU(Args);
+  case llvm::Triple::r600:
 return getR600TargetGPU(Args);
 
   case llvm::Triple::wasm32:
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1752,7 +1752,7 @@
   "-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
   "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64";
 
-class AMDGPUTargetInfo : public TargetInfo {
+class AMDGPUTargetInfo final : public TargetInfo {
   static const Builtin::Info BuiltinInfo[];
   static const char * const GCCRegNames[];
 
@@ -1776,23 +1776,26 @@
   bool hasFMAF:1;
   bool hasLDEXPF:1;
 
+  static bool isAMDGCN(const llvm::Triple &TT) {
+return TT.getArch() == llvm::Triple::amdgcn;
+  }
+
 public:
   AMDGPUTargetInfo(const llvm::Triple &Triple)
-: TargetInfo(Triple) {
-
-if (Triple.getArch() == llvm::Triple::amdgcn) {
-  resetDataLayout(DataLayoutStringSI);
-  GPU = GK_SOUTHERN_ISLANDS;
+: TargetInfo(Triple) ,
+  GPU(isAMDGCN(Triple) ? GK_SOUTHERN_ISLANDS : GK_R600),
+  hasFP64(false),
+  hasFMAF(false),
+  hasLDEXPF(false) {
+if (getTriple().getArch() == llvm::Triple::amdgcn) {
   hasFP64 = true;
   hasFMAF = true;
   hasLDEXPF = true;
-} else {
-  resetDataLayout(DataLayoutStringR600);
-  GPU = GK_R600;
-  hasFP64 = false;
-  hasFMAF = false;
-  hasLDEXPF = false;
 }
+
+resetDataLayout(getTriple().getArch() == llvm::Triple::amdgcn ?
+DataLayoutStringSI : DataLayoutStringR600);
+
 AddrSpaceMap = &AMDGPUAddrSpaceMap;
 UseAddrSpaceMapMangling = true;
   }
@@ -1833,6 +1836,10 @@
 return false;
   }
 

Re: [PATCH] D17951: Implement is_always_lock_free

2016-03-25 Thread JF Bastien via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL264413: Implement is_always_lock_free (authored by jfb).

Changed prior to commit:
  http://reviews.llvm.org/D17951?vs=51607&id=51638#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17951

Files:
  libcxx/trunk/include/atomic
  libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp

Index: libcxx/trunk/include/atomic
===
--- libcxx/trunk/include/atomic
+++ libcxx/trunk/include/atomic
@@ -17,6 +17,10 @@
 namespace std
 {
 
+// feature test macro
+
+#define __cpp_lib_atomic_is_always_lock_free // as specified by SG10
+
 // order and consistency
 
 typedef enum memory_order
@@ -89,6 +93,7 @@
 template 
 struct atomic
 {
+static constexpr bool is_always_lock_free;
 bool is_lock_free() const volatile noexcept;
 bool is_lock_free() const noexcept;
 void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
@@ -127,6 +132,7 @@
 template <>
 struct atomic
 {
+static constexpr bool is_always_lock_free;
 bool is_lock_free() const volatile noexcept;
 bool is_lock_free() const noexcept;
 void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
@@ -202,6 +208,7 @@
 template 
 struct atomic
 {
+static constexpr bool is_always_lock_free;
 bool is_lock_free() const volatile noexcept;
 bool is_lock_free() const noexcept;
 void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
@@ -540,6 +547,11 @@
 #error  is not implemented
 #endif
 
+#if _LIBCPP_STD_VER > 14
+// FIXME: use the right feature test macro value as chose by SG10.
+# define __cpp_lib_atomic_is_always_lock_free 201603L
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 typedef enum memory_order
@@ -825,13 +837,28 @@
 return __y;
 }
 
+#define ATOMIC_BOOL_LOCK_FREE  __GCC_ATOMIC_BOOL_LOCK_FREE
+#define ATOMIC_CHAR_LOCK_FREE  __GCC_ATOMIC_CHAR_LOCK_FREE
+#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
+#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
+#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
+#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
+#define ATOMIC_INT_LOCK_FREE   __GCC_ATOMIC_INT_LOCK_FREE
+#define ATOMIC_LONG_LOCK_FREE  __GCC_ATOMIC_LONG_LOCK_FREE
+#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
+#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
+
 // general atomic
 
 template ::value && !is_same<_Tp, bool>::value>
 struct __atomic_base  // false
 {
 mutable _Atomic(_Tp) __a_;
 
+#if defined(__cpp_lib_atomic_is_always_lock_free)
+  static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
+#endif
+
 _LIBCPP_INLINE_VISIBILITY
 bool is_lock_free() const volatile _NOEXCEPT
 {
@@ -920,6 +947,11 @@
 #endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 };
 
+#if defined(__cpp_lib_atomic_is_always_lock_free)
+template 
+_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
+#endif
+
 // atomic
 
 template 
@@ -1789,17 +1821,6 @@
 #define ATOMIC_FLAG_INIT {false}
 #define ATOMIC_VAR_INIT(__v) {__v}
 
-#define ATOMIC_BOOL_LOCK_FREE  __GCC_ATOMIC_BOOL_LOCK_FREE
-#define ATOMIC_CHAR_LOCK_FREE  __GCC_ATOMIC_CHAR_LOCK_FREE
-#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
-#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
-#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
-#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
-#define ATOMIC_INT_LOCK_FREE   __GCC_ATOMIC_INT_LOCK_FREE
-#define ATOMIC_LONG_LOCK_FREE  __GCC_ATOMIC_LONG_LOCK_FREE
-#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
-#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_ATOMIC
Index: libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
===
--- libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
+++ libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
@@ -0,0 +1,101 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+//
+// UNSUPPORTED: libcpp-has-no-threads, c++98, c++03, c++11, c++14
+
+// 
+
+// static constexpr bool is_always_lock_free;
+
+#include 
+#include 
+
+#if !defined(__cpp_lib_atomic_is_always_lock_free)
+# error Feature test macro missing.
+#endif
+
+template  void checkAlwaysLockFree() {
+  if (std::atomic::is_always_lock_fr

[libcxx] r264413 - Implement is_always_lock_free

2016-03-25 Thread JF Bastien via cfe-commits
Author: jfb
Date: Fri Mar 25 10:48:21 2016
New Revision: 264413

URL: http://llvm.org/viewvc/llvm-project?rev=264413&view=rev
Log:
Implement is_always_lock_free

Summary:

This was voted into C++17 at the Jacksonville meeting. The final P0152R1
paper will be in the upcoming post-Jacksonville mailing, and is also
available here:

  http://jfbastien.github.io/papers/P0152R1.html

Reviewers: mclow.lists, rsmith

Subscribers: cfe-commits

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

Added:
libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
Modified:
libcxx/trunk/include/atomic

Modified: libcxx/trunk/include/atomic
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=264413&r1=264412&r2=264413&view=diff
==
--- libcxx/trunk/include/atomic (original)
+++ libcxx/trunk/include/atomic Fri Mar 25 10:48:21 2016
@@ -17,6 +17,10 @@
 namespace std
 {
 
+// feature test macro
+
+#define __cpp_lib_atomic_is_always_lock_free // as specified by SG10
+
 // order and consistency
 
 typedef enum memory_order
@@ -89,6 +93,7 @@ void
 template 
 struct atomic
 {
+static constexpr bool is_always_lock_free;
 bool is_lock_free() const volatile noexcept;
 bool is_lock_free() const noexcept;
 void store(T desr, memory_order m = memory_order_seq_cst) volatile 
noexcept;
@@ -127,6 +132,7 @@ struct atomic
 template <>
 struct atomic
 {
+static constexpr bool is_always_lock_free;
 bool is_lock_free() const volatile noexcept;
 bool is_lock_free() const noexcept;
 void store(integral desr, memory_order m = memory_order_seq_cst) volatile 
noexcept;
@@ -202,6 +208,7 @@ struct atomic
 template 
 struct atomic
 {
+static constexpr bool is_always_lock_free;
 bool is_lock_free() const volatile noexcept;
 bool is_lock_free() const noexcept;
 void store(T* desr, memory_order m = memory_order_seq_cst) volatile 
noexcept;
@@ -540,6 +547,11 @@ void atomic_signal_fence(memory_order m)
 #error  is not implemented
 #endif
 
+#if _LIBCPP_STD_VER > 14
+// FIXME: use the right feature test macro value as chose by SG10.
+# define __cpp_lib_atomic_is_always_lock_free 201603L
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 typedef enum memory_order
@@ -825,6 +837,17 @@ kill_dependency(_Tp __y) _NOEXCEPT
 return __y;
 }
 
+#define ATOMIC_BOOL_LOCK_FREE  __GCC_ATOMIC_BOOL_LOCK_FREE
+#define ATOMIC_CHAR_LOCK_FREE  __GCC_ATOMIC_CHAR_LOCK_FREE
+#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
+#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
+#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
+#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
+#define ATOMIC_INT_LOCK_FREE   __GCC_ATOMIC_INT_LOCK_FREE
+#define ATOMIC_LONG_LOCK_FREE  __GCC_ATOMIC_LONG_LOCK_FREE
+#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
+#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
+
 // general atomic
 
 template ::value && !is_same<_Tp, 
bool>::value>
@@ -832,6 +855,10 @@ struct __atomic_base  // false
 {
 mutable _Atomic(_Tp) __a_;
 
+#if defined(__cpp_lib_atomic_is_always_lock_free)
+  static _LIBCPP_CONSTEXPR bool is_always_lock_free = 
__atomic_always_lock_free(sizeof(__a_), 0);
+#endif
+
 _LIBCPP_INLINE_VISIBILITY
 bool is_lock_free() const volatile _NOEXCEPT
 {
@@ -920,6 +947,11 @@ private:
 #endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 };
 
+#if defined(__cpp_lib_atomic_is_always_lock_free)
+template 
+_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
+#endif
+
 // atomic
 
 template 
@@ -1789,17 +1821,6 @@ typedef atomic atomic_uintmax
 #define ATOMIC_FLAG_INIT {false}
 #define ATOMIC_VAR_INIT(__v) {__v}
 
-#define ATOMIC_BOOL_LOCK_FREE  __GCC_ATOMIC_BOOL_LOCK_FREE
-#define ATOMIC_CHAR_LOCK_FREE  __GCC_ATOMIC_CHAR_LOCK_FREE
-#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
-#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
-#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
-#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
-#define ATOMIC_INT_LOCK_FREE   __GCC_ATOMIC_INT_LOCK_FREE
-#define ATOMIC_LONG_LOCK_FREE  __GCC_ATOMIC_LONG_LOCK_FREE
-#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
-#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_ATOMIC

Added: libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp?rev=264413&view=auto
==
--- libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp 
(added)
+++ libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp 

[PATCH] D18474: [OPENMP] Enable correct generation of runtime call when target directive is separated from teams directive by multiple curly brackets

2016-03-25 Thread Carlo Bertolli via cfe-commits
carlo.bertolli created this revision.
carlo.bertolli added reviewers: ABataev, sfantao, Hahnfeld.
carlo.bertolli added subscribers: arpith-jacob, caomhin, cfe-commits.
carlo.bertolli set the repository for this revision to rL LLVM.

This patch fixes a bug in code generation of the correct OpenMP runtime library 
call in presence of target and teams, when target is separated by teams with 
multiple curly brackets. The current implementation will not be able to see the 
teams directive inside target and issue a call to tgt_target instead of the 
correct one tgt_target_teams.

Repository:
  rL LLVM

http://reviews.llvm.org/D18474

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/teams_codegen.cpp

Index: test/OpenMP/teams_codegen.cpp
===
--- test/OpenMP/teams_codegen.cpp
+++ test/OpenMP/teams_codegen.cpp
@@ -29,6 +29,16 @@
 ++comp;
   }
 
+  // CK1: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 1, i8** 
%{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* 
{{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
+  // CK1: call void @{{.+}}(i{{64|32}} %{{.+}})
+  #pragma omp target
+  {{{
+#pragma omp teams
+{
+  ++comp;
+}
+  }}}
+  
   // CK1-DAG: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 2, i8** 
%{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* 
{{.+}}@{{[^,]+}}, i32 0, i32 0), i32 [[NT:%[^,]+]], i32 0)
   // CK1-DAG: [[NT]] = load i32, i32* [[NTA:%[^,]+]],
 
Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4249,6 +4249,29 @@
   DeviceID, FileID, ParentName, Line, OutlinedFn, OutlinedFnID);
 }
 
+/// \brief Search in a target region until either a teams directive is found
+/// or a different statement or construct. Return the teams directive object
+/// in the former case, nullptr otherwise.
+const static OMPTeamsDirective *
+hasEnclosingTeams(const Stmt *TargetBody) {
+  if(auto *TeamsDir = dyn_cast(TargetBody)) return TeamsDir;
+
+  auto *NextBlock = dyn_cast(TargetBody);
+  auto *LastBlock = NextBlock;
+  // keep reading compound statements until something else is found
+  // or there is nothing more to read
+  while (NextBlock && NextBlock->body_front()) {
+LastBlock = NextBlock;
+NextBlock = dyn_cast(NextBlock->body_front());
+  }
+
+  if (LastBlock && LastBlock->body_front())
+return dyn_cast(LastBlock->body_front());
+
+  // no teams or no compund stmt in the target region body
+  return nullptr;
+}
+
 /// \brief Emit the num_teams clause of an enclosed teams directive at the
 /// target region scope. If there is no teams directive associated with the
 /// target directive, or if there is no num_teams clause associated with the
@@ -4279,7 +4302,7 @@
 
   // FIXME: Accommodate other combined directives with teams when they become
   // available.
-  if (auto *TeamsDir = dyn_cast(CS.getCapturedStmt())) {
+   if (auto *TeamsDir = hasEnclosingTeams(CS.getCapturedStmt())) {
 if (auto *NTE = TeamsDir->getSingleClause()) {
   CGOpenMPInnerExprInfo CGInfo(CGF, CS);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo);
@@ -4327,7 +4350,7 @@
 
   // FIXME: Accommodate other combined directives with teams when they become
   // available.
-  if (auto *TeamsDir = dyn_cast(CS.getCapturedStmt())) {
+  if (auto *TeamsDir = hasEnclosingTeams(CS.getCapturedStmt())) {
 if (auto *TLE = TeamsDir->getSingleClause()) {
   CGOpenMPInnerExprInfo CGInfo(CGF, CS);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo);


Index: test/OpenMP/teams_codegen.cpp
===
--- test/OpenMP/teams_codegen.cpp
+++ test/OpenMP/teams_codegen.cpp
@@ -29,6 +29,16 @@
 ++comp;
   }
 
+  // CK1: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
+  // CK1: call void @{{.+}}(i{{64|32}} %{{.+}})
+  #pragma omp target
+  {{{
+#pragma omp teams
+{
+  ++comp;
+}
+  }}}
+  
   // CK1-DAG: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 [[NT:%[^,]+]], i32 0)
   // CK1-DAG: [[NT]] = load i32, i32* [[NTA:%[^,]+]],
 
Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4249,6 +4249,29 @@
   DeviceID, FileID, ParentName, Line, OutlinedFn, OutlinedFnID);
 }
 
+/// \brief Search in a target region until either a teams directive is found
+/// or a different statement or construct. Return the teams directive object
+/// in the fo

Re: [PATCH] D18474: [OPENMP] Enable correct generation of runtime call when target directive is separated from teams directive by multiple curly brackets

2016-03-25 Thread Samuel Antao via cfe-commits
sfantao added a comment.

Thanks for the fix!



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:4257
@@ +4256,3 @@
+hasEnclosingTeams(const Stmt *TargetBody) {
+  if(auto *TeamsDir = dyn_cast(TargetBody)) return TeamsDir;
+

I think that this can be simplified to:

```
while (auto *S = dyn_cast(TargetBody))
  TargetBody = S->body_front();

return dyn_cast(OMPTeamsDirective);
```

I know that this is currently used only for teams, but I think it would be nice 
to make this a templated function to look for other possible nests. I suspect 
this will very useful for other cases like 'target teams parallel distribute'.


Repository:
  rL LLVM

http://reviews.llvm.org/D18474



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


Re: [PATCH] D15944: [OpenMP] Parsing and sema support for target update directive

2016-03-25 Thread Kelvin Li via cfe-commits
kkwli0 added a comment.

Thanks for the review.

As request, I will split this patch into two:

1. to and from clause (without test cases)
2. target update directive (with test cases)

I will use this review for the target update directive.


http://reviews.llvm.org/D15944



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


r264417 - [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Samuel Benzaquen via cfe-commits
Author: sbenza
Date: Fri Mar 25 11:29:30 2016
New Revision: 264417

URL: http://llvm.org/viewvc/llvm-project?rev=264417&view=rev
Log:
[ASTMatchers] Add own version of VariadicFunction.

Summary:
llvm::VariadicFunction is only being used by ASTMatchers.
Having our own copy here allows us to remove the other one from llvm/ADT.
Also, we can extend the API to meet our needs without modifying the common
implementation.

Reviewers: alexfh

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=264417&r1=264416&r2=264417&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar 25 11:29:30 2016
@@ -1990,8 +1990,8 @@ inline internal::Matcher hasN
 /// \code
 /// anyOf(hasName(a), hasName(b), hasName(c))
 /// \endcode
-const llvm::VariadicFunction, StringRef,
- internal::hasAnyNameFunc>
+const internal::VariadicFunction, StringRef,
+ internal::hasAnyNameFunc>
 hasAnyName = {};
 
 /// \brief Matches NamedDecl nodes whose fully qualified names contain

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264417&r1=264416&r2=264417&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25 
11:29:30 2016
@@ -46,8 +46,9 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/Type.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
-#include "llvm/ADT/VariadicFunction.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/ManagedStatic.h"
 #include 
 #include 
@@ -60,6 +61,39 @@ class BoundNodes;
 
 namespace internal {
 
+/// \brief Variadic function object.
+///
+/// Most of the functions below that use VariadicFunction could be implemented
+/// using plain C++11 variadic functions, but the function object allows us to
+/// capture it on the dynamic matcher registry.
+template )>
+struct VariadicFunction {
+  ResultT operator()() const { return Func({}); }
+
+  template 
+  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
+return Execute(Arg1, static_cast(Args)...);
+  }
+
+  // We also allow calls with an already created array, in case the caller
+  // already had it.
+  ResultT operator()(ArrayRef Args) const {
+SmallVector InnerArgs;
+for (const ArgT &Arg : Args)
+  InnerArgs.push_back(&Arg);
+return Func(InnerArgs);
+  }
+
+private:
+  // Trampoline function to allow for implicit conversions to take place
+  // before we make the array.
+  template  ResultT Execute(const ArgsT &... Args) const {
+const ArgT *const ArgsArray[] = {&Args...};
+return Func(ArgsArray);
+  }
+};
+
 /// \brief Unifies obtaining the underlying type of a regular node through
 /// `getType` and a TypedefNameDecl node through `getUnderlyingType`.
 template 
@@ -1405,9 +1439,8 @@ inline bool ValueEqualsMatcher
 class VariadicDynCastAllOfMatcher
-: public llvm::VariadicFunction<
-BindableMatcher, Matcher,
-makeDynCastAllOfComposite > {
+: public VariadicFunction, Matcher,
+  makeDynCastAllOfComposite> {
 public:
   VariadicDynCastAllOfMatcher() {}
 };
@@ -1423,9 +1456,9 @@ public:
 /// \c Matcher.
 /// The returned matcher matches if all given matchers match.
 template 
-class VariadicAllOfMatcher : public llvm::VariadicFunction<
-   BindableMatcher, Matcher,
-   makeAllOfComposite > {
+class VariadicAllOfMatcher
+: public VariadicFunction, Matcher,
+  makeAllOfComposite> {
 public:
   VariadicAllOfMatcher() {}
 };
@@ -1546,8 +1579,8 @@ public:
 new MatcherImpl(InnerMatcher, Getter::value()));
   }
 
-  struct Func : public llvm::VariadicFunction,
-  &Self::create> {
+  struct Func
+  : public VariadicFunction, &Self::create> {
 Func() {}
   };
 

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h?rev=264417&r1=264416&r2=264417&view=diff
==
--- cfe/t

Re: [PATCH] D18275: [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Samuel Benzaquen via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL264417: [ASTMatchers] Add own version of VariadicFunction. 
(authored by sbenza).

Changed prior to commit:
  http://reviews.llvm.org/D18275?vs=51447&id=51645#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18275

Files:
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
  cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
  cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
  cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
===
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
@@ -1990,8 +1990,8 @@
 /// \code
 /// anyOf(hasName(a), hasName(b), hasName(c))
 /// \endcode
-const llvm::VariadicFunction, StringRef,
- internal::hasAnyNameFunc>
+const internal::VariadicFunction, StringRef,
+ internal::hasAnyNameFunc>
 hasAnyName = {};
 
 /// \brief Matches NamedDecl nodes whose fully qualified names contain
Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -46,8 +46,9 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/Type.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
-#include "llvm/ADT/VariadicFunction.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/ManagedStatic.h"
 #include 
 #include 
@@ -60,6 +61,39 @@
 
 namespace internal {
 
+/// \brief Variadic function object.
+///
+/// Most of the functions below that use VariadicFunction could be implemented
+/// using plain C++11 variadic functions, but the function object allows us to
+/// capture it on the dynamic matcher registry.
+template )>
+struct VariadicFunction {
+  ResultT operator()() const { return Func({}); }
+
+  template 
+  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
+return Execute(Arg1, static_cast(Args)...);
+  }
+
+  // We also allow calls with an already created array, in case the caller
+  // already had it.
+  ResultT operator()(ArrayRef Args) const {
+SmallVector InnerArgs;
+for (const ArgT &Arg : Args)
+  InnerArgs.push_back(&Arg);
+return Func(InnerArgs);
+  }
+
+private:
+  // Trampoline function to allow for implicit conversions to take place
+  // before we make the array.
+  template  ResultT Execute(const ArgsT &... Args) const {
+const ArgT *const ArgsArray[] = {&Args...};
+return Func(ArgsArray);
+  }
+};
+
 /// \brief Unifies obtaining the underlying type of a regular node through
 /// `getType` and a TypedefNameDecl node through `getUnderlyingType`.
 template 
@@ -1405,9 +1439,8 @@
 /// casted to CXXRecordDecl and all given matchers match.
 template 
 class VariadicDynCastAllOfMatcher
-: public llvm::VariadicFunction<
-BindableMatcher, Matcher,
-makeDynCastAllOfComposite > {
+: public VariadicFunction, Matcher,
+  makeDynCastAllOfComposite> {
 public:
   VariadicDynCastAllOfMatcher() {}
 };
@@ -1423,9 +1456,9 @@
 /// \c Matcher.
 /// The returned matcher matches if all given matchers match.
 template 
-class VariadicAllOfMatcher : public llvm::VariadicFunction<
-   BindableMatcher, Matcher,
-   makeAllOfComposite > {
+class VariadicAllOfMatcher
+: public VariadicFunction, Matcher,
+  makeAllOfComposite> {
 public:
   VariadicAllOfMatcher() {}
 };
@@ -1546,8 +1579,8 @@
 new MatcherImpl(InnerMatcher, Getter::value()));
   }
 
-  struct Func : public llvm::VariadicFunction,
-  &Self::create> {
+  struct Func
+  : public VariadicFunction, &Self::create> {
 Func() {}
   };
 
Index: cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -325,8 +325,9 @@
 
   template )>
-  VariadicFuncMatcherDescriptor(llvm::VariadicFunction Func,
-  StringRef MatcherName)
+  VariadicFuncMatcherDescriptor(
+  ast_matchers::internal::VariadicFunction Func,
+  StringRef MatcherName)
   : Func(&variadicMatcherDescriptor),
 MatcherName(MatcherName.str()),
 ArgsKind(ArgTypeTraits::getKind()) {
@@ -655,9 +656,9 @@
 /// \brief Variadic overload.
 template )>
-MatcherDescriptor *
-makeMatcherAutoMarshall(llvm::VariadicFunction VarFunc,
-StringRef MatcherName) {
+MatcherDescriptor *makeMatcherAutoMarshall(
+ast_matchers::internal::VariadicFunctio

Re: [PATCH] D18474: [OPENMP] Enable correct generation of runtime call when target directive is separated from teams directive by multiple curly brackets

2016-03-25 Thread Carlo Bertolli via cfe-commits
carlo.bertolli added inline comments.


Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:4257
@@ +4256,3 @@
+hasEnclosingTeams(const Stmt *TargetBody) {
+  if(auto *TeamsDir = dyn_cast(TargetBody)) return TeamsDir;
+

sfantao wrote:
> I think that this can be simplified to:
> 
> ```
> while (auto *S = dyn_cast(TargetBody))
>   TargetBody = S->body_front();
> 
> return dyn_cast(OMPTeamsDirective);
> ```
> 
> I know that this is currently used only for teams, but I think it would be 
> nice to make this a templated function to look for other possible nests. I 
> suspect this will very useful for other cases like 'target teams parallel 
> distribute'.
Thanks! I agree that having this as a template will help with combined 
directives. I will produce a new version of the patch with that support.

About your new loop: this would crash if S->body_front() is nullptr. This may 
happen if you have something like this:

```
#target
{
}
```
A solution may be

```
while (auto *S = dyn_cast_or_null(TargetBody))
  TargetBody = S->body_front();

return dyn_cast_or_null(OMPTeamsDirective);
```

Thoughts?


Repository:
  rL LLVM

http://reviews.llvm.org/D18474



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


[PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.

2016-03-25 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a subscriber: cfe-commits.

The string class contains methods which support receiving either a string 
literal or a string object.

For example, calls to append can receive either a char* or a string.
```
  string& append (const string& str);
  string& append (const char* s);
```

Which make these cases equivalent, and the .c_str() useless:
```
  std::string s = "123";
  str.append(s);
  str.append(s.c_str());
```

In these cases, removing .c_str()  doesn't provide any size or speed 
improvement.
It's only a readability issue.

If the string contains embedded NUL characters,  the string literal and the 
string
object won't produce the same semantic.


http://reviews.llvm.org/D18475

Files:
  clang-tidy/readability/RedundantStringCStrCheck.cpp
  test/clang-tidy/readability-redundant-string-cstr.cpp

Index: clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -103,12 +103,79 @@
 callee(cxxMethodDecl(hasName("c_str"
   .bind("call");
 
+  // Detect redundant 'c_str()' calls through a string constructor.
   Finder->addMatcher(
   cxxConstructExpr(StringConstructorExpr,
hasArgument(0, StringCStrCallExpr)),
   this);
 
+  // Detect: 's == str.c_str()'  ->  's == str'
   Finder->addMatcher(
+  cxxOperatorCallExpr(
+  anyOf(hasOverloadedOperatorName("<"),
+hasOverloadedOperatorName(">"),
+hasOverloadedOperatorName(">="),
+hasOverloadedOperatorName("<="),
+hasOverloadedOperatorName("!="),
+hasOverloadedOperatorName("=="),
+hasOverloadedOperatorName("+")),
+  anyOf(allOf(hasArgument(0, StringExpr),
+  hasArgument(1, StringCStrCallExpr)),
+allOf(hasArgument(0, StringCStrCallExpr),
+  hasArgument(1, StringExpr,
+  this);
+
+  // Detect: 'dst += str.c_str()'  ->  'dst += str'
+  // Detect: 's == str.c_str()'  ->  's == str'
+  Finder->addMatcher(
+  cxxOperatorCallExpr(
+  anyOf(hasOverloadedOperatorName("="),
+hasOverloadedOperatorName("+=")),
+  hasArgument(0, StringExpr),
+  hasArgument(1, StringCStrCallExpr)),
+  this);
+
+  // Detect: 'dst.append(str.c_str())'  ->  'dst.append(str)'
+  Finder->addMatcher(
+  cxxMemberCallExpr(on(StringExpr),
+  callee(decl(cxxMethodDecl(anyOf(hasName("append"),
+  hasName("assign"),
+  hasName("compare"),
+  argumentCountIs(1),
+  hasArgument(0, StringCStrCallExpr)),
+  this);
+
+  // Detect: 'dst.compare(p, n, str.c_str())'  ->  'dst.compare(p, n, str)'
+  Finder->addMatcher(
+  cxxMemberCallExpr(on(StringExpr),
+  callee(decl(cxxMethodDecl(hasName("compare",
+  argumentCountIs(3),
+  hasArgument(2, StringCStrCallExpr)),
+  this);
+
+  // Detect: 'dst.find(str.c_str())'  ->  'dst.find(str)'
+  Finder->addMatcher(
+  cxxMemberCallExpr(on(StringExpr),
+  callee(decl(cxxMethodDecl(anyOf(hasName("find"),
+  hasName("find_first_not_of"),
+  hasName("find_first_of"),
+  hasName("find_last_not_of"),
+  hasName("find_last_of"),
+  hasName("rfind"),
+  anyOf(argumentCountIs(1), argumentCountIs(2)),
+  hasArgument(0, StringCStrCallExpr)),
+  this);
+
+  // Detect: 'dst.insert(pos, str.c_str())'  ->  'dst.insert(pos, str)'
+  Finder->addMatcher(
+  cxxMemberCallExpr(on(StringExpr),
+  callee(decl(cxxMethodDecl(hasName("insert",
+  argumentCountIs(2),
+  hasArgument(1, StringCStrCallExpr)),
+  this);
+
+  // Detect redundant 'c_str()' calls through a StringRef constructor.
+  Finder->addMatcher(
   cxxConstructExpr(
   // Implicit constructors of these classes are overloaded
   // wrt. string types and they internally make a StringRef
Index: test/clang-tidy/readability-redundant-string-cstr.cpp
===
--- test/clang-tidy/readability-redundant-string-cstr.cpp
+++ test/clang-tidy/readability-redundant-string-cstr.cpp
@@ -1,5 +1,8 @@
 // RUN: %check_clang_tidy %s readability-redundant-string-cstr %t
 
+typedef unsigned __INT16_TYPE__ char16;
+typedef unsigned __INT32_TYPE__ char32;
+
 namespace std {
 template 
 class allocator {};
@@ -7,16 +10,50 @@
 class char_traits {};
 template 
 struct basic_string {
+  typedef basic_string _Type;
   basic_string();
   basic_string(const C *p, c

Re: [PATCH] D18474: [OPENMP] Enable correct generation of runtime call when target directive is separated from teams directive by multiple curly brackets

2016-03-25 Thread Samuel Antao via cfe-commits
sfantao added inline comments.


Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:4257
@@ +4256,3 @@
+hasEnclosingTeams(const Stmt *TargetBody) {
+  if(auto *TeamsDir = dyn_cast(TargetBody)) return TeamsDir;
+

carlo.bertolli wrote:
> sfantao wrote:
> > I think that this can be simplified to:
> > 
> > ```
> > while (auto *S = dyn_cast(TargetBody))
> >   TargetBody = S->body_front();
> > 
> > return dyn_cast(OMPTeamsDirective);
> > ```
> > 
> > I know that this is currently used only for teams, but I think it would be 
> > nice to make this a templated function to look for other possible nests. I 
> > suspect this will very useful for other cases like 'target teams parallel 
> > distribute'.
> Thanks! I agree that having this as a template will help with combined 
> directives. I will produce a new version of the patch with that support.
> 
> About your new loop: this would crash if S->body_front() is nullptr. This may 
> happen if you have something like this:
> 
> ```
> #target
> {
> }
> ```
> A solution may be
> 
> ```
> while (auto *S = dyn_cast_or_null(TargetBody))
>   TargetBody = S->body_front();
> 
> return dyn_cast_or_null(OMPTeamsDirective);
> ```
> 
> Thoughts?
You're totally right, dyn_cast_or_null is the right cast to use in the return 
statement.


Repository:
  rL LLVM

http://reviews.llvm.org/D18474



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


Re: [PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.

2016-03-25 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a subscriber: Eugene.Zelenko.
Eugene.Zelenko added a comment.

Thank you for enhancement!

I think will be good idea to extend check for any function call that receives 
.c_str(), since it mat be in other classes could have methods which receives 
both C++ or C strings. See also PR24870.


http://reviews.llvm.org/D18475



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


r264423 - [index] Remove redundancy between symbol kind and language

2016-03-25 Thread Ben Langmuir via cfe-commits
Author: benlangmuir
Date: Fri Mar 25 12:01:59 2016
New Revision: 264423

URL: http://llvm.org/viewvc/llvm-project?rev=264423&view=rev
Log:
[index] Remove redundancy between symbol kind and language

Condense the ObjCKIND and CXXKIND options into just KIND, since the
language was already specified on a per-symbol basis and this
information was redundant. This only changes the internal
representation; naturally the libclang interface remains the same.

Modified:
cfe/trunk/include/clang/Index/IndexSymbol.h
cfe/trunk/lib/Index/IndexSymbol.cpp
cfe/trunk/test/Index/Core/index-source.cpp
cfe/trunk/test/Index/Core/index-source.m
cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp

Modified: cfe/trunk/include/clang/Index/IndexSymbol.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=264423&r1=264422&r2=264423&view=diff
==
--- cfe/trunk/include/clang/Index/IndexSymbol.h (original)
+++ cfe/trunk/include/clang/Index/IndexSymbol.h Fri Mar 25 12:01:59 2016
@@ -24,38 +24,33 @@ enum class SymbolKind : uint8_t {
   Unknown,
 
   Module,
+  Namespace,
+  NamespaceAlias,
   Macro,
 
   Enum,
   Struct,
+  Class,
+  Protocol,
+  Extension,
   Union,
-  Typedef,
+  TypeAlias,
 
   Function,
   Variable,
   Field,
   EnumConstant,
 
-  ObjCClass,
-  ObjCProtocol,
-  ObjCCategory,
-
-  ObjCInstanceMethod,
-  ObjCClassMethod,
-  ObjCProperty,
-  ObjCIvar,
-
-  CXXClass,
-  CXXNamespace,
-  CXXNamespaceAlias,
-  CXXStaticVariable,
-  CXXStaticMethod,
-  CXXInstanceMethod,
-  CXXConstructor,
-  CXXDestructor,
-  CXXConversionFunction,
-  CXXTypeAlias,
-  CXXInterface,
+  InstanceMethod,
+  ClassMethod,
+  StaticMethod,
+  InstanceProperty,
+  ClassProperty,
+  StaticProperty,
+
+  Constructor,
+  Destructor,
+  ConversionFunction,
 };
 
 enum class SymbolLanguage {

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=264423&r1=264422&r2=264423&view=diff
==
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Fri Mar 25 12:01:59 2016
@@ -30,11 +30,11 @@ SymbolInfo index::getSymbolInfo(const De
 case TTK_Union:
   Info.Kind = SymbolKind::Union; break;
 case TTK_Class:
-  Info.Kind = SymbolKind::CXXClass;
+  Info.Kind = SymbolKind::Class;
   Info.Lang = SymbolLanguage::CXX;
   break;
 case TTK_Interface:
-  Info.Kind = SymbolKind::CXXInterface;
+  Info.Kind = SymbolKind::Protocol;
   Info.Lang = SymbolLanguage::CXX;
   break;
 case TTK_Enum:
@@ -57,7 +57,7 @@ SymbolInfo index::getSymbolInfo(const De
   Info.Kind = SymbolKind::Module;
   break;
 case Decl::Typedef:
-  Info.Kind = SymbolKind::Typedef; break;
+  Info.Kind = SymbolKind::TypeAlias; break; // Lang = C
 case Decl::Function:
   Info.Kind = SymbolKind::Function;
   break;
@@ -67,7 +67,7 @@ SymbolInfo index::getSymbolInfo(const De
 case Decl::Var:
   Info.Kind = SymbolKind::Variable;
   if (isa(D->getDeclContext())) {
-Info.Kind = SymbolKind::CXXStaticVariable;
+Info.Kind = SymbolKind::StaticProperty;
 Info.Lang = SymbolLanguage::CXX;
   }
   break;
@@ -83,91 +83,94 @@ SymbolInfo index::getSymbolInfo(const De
   Info.Kind = SymbolKind::EnumConstant; break;
 case Decl::ObjCInterface:
 case Decl::ObjCImplementation:
-  Info.Kind = SymbolKind::ObjCClass;
+  Info.Kind = SymbolKind::Class;
   Info.Lang = SymbolLanguage::ObjC;
   break;
 case Decl::ObjCProtocol:
-  Info.Kind = SymbolKind::ObjCProtocol;
+  Info.Kind = SymbolKind::Protocol;
   Info.Lang = SymbolLanguage::ObjC;
   break;
 case Decl::ObjCCategory:
 case Decl::ObjCCategoryImpl:
-  Info.Kind = SymbolKind::ObjCCategory;
+  Info.Kind = SymbolKind::Extension;
   Info.Lang = SymbolLanguage::ObjC;
   break;
 case Decl::ObjCMethod:
   if (cast(D)->isInstanceMethod())
-Info.Kind = SymbolKind::ObjCInstanceMethod;
+Info.Kind = SymbolKind::InstanceMethod;
   else
-Info.Kind = SymbolKind::ObjCClassMethod;
+Info.Kind = SymbolKind::ClassMethod;
   Info.Lang = SymbolLanguage::ObjC;
   break;
 case Decl::ObjCProperty:
-  Info.Kind = SymbolKind::ObjCProperty;
+  Info.Kind = SymbolKind::InstanceProperty;
   Info.Lang = SymbolLanguage::ObjC;
   break;
 case Decl::ObjCIvar:
-  Info.Kind = SymbolKind::ObjCIvar;
+  Info.Kind = SymbolKind::Field;
   Info.Lang = SymbolLanguage::ObjC;
   break;
 case Decl::Namespace:
-  Info.Kind = SymbolKind::CXXNamespace;
+  Info.Kind = SymbolKind::Namespace;
   Info.Lang = SymbolLanguage::CXX;
   break;
 case Decl::NamespaceAlias:
-  Info.Kind = SymbolKind::CXXNamespaceAlias;
+ 

Re: [PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.

2016-03-25 Thread David Blaikie via cfe-commits
On Fri, Mar 25, 2016 at 9:59 AM, Etienne Bergeron via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> etienneb created this revision.
> etienneb added a subscriber: cfe-commits.
>
> The string class contains methods which support receiving either a string
> literal or a string object.
>
> For example, calls to append can receive either a char* or a string.
> ```
>   string& append (const string& str);
>   string& append (const char* s);
> ```
>
> Which make these cases equivalent, and the .c_str() useless:
> ```
>   std::string s = "123";
>   str.append(s);
>   str.append(s.c_str());
> ```
>
> In these cases, removing .c_str()  doesn't provide any size or speed
> improvement.
> It's only a readability issue.
>

potential speed improvement by not having to search for the null terminator


>
> If the string contains embedded NUL characters,  the string literal and
> the string
> object won't produce the same semantic.
>
>
> http://reviews.llvm.org/D18475
>
> Files:
>   clang-tidy/readability/RedundantStringCStrCheck.cpp
>   test/clang-tidy/readability-redundant-string-cstr.cpp
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.

2016-03-25 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D18475#383520, @Eugene.Zelenko wrote:

> Thank you for enhancement!
>
> I think will be good idea to extend check for any function call that receives 
> .c_str(), since it mat be in other classes could have methods which receives 
> both C++ or C strings. See also PR24870.


I was thinking the same when I started that patch. But, there is multiple cases 
where it will bring a false-positive.
As an example:

  string& insert (size_t pos, const string& str, size_t subpos, size_t sublen = 
npos);
  string& insert (size_t pos, const char* s, size_t n);

Even if the overloaded name/types are compatible, the semantic is not the same. 
You can't simply remove the .c_str() here.

I agree that a more general cases could exists, but I would like to be able to 
turn it off over a large code base when trying to keep false positives as low 
as posible.


http://reviews.llvm.org/D18475



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


Re: [PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.

2016-03-25 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 51657.
etienneb added a comment.

Fixing some matchers to use the recent new AstMatcher.
(see http://reviews.llvm.org/D18275)


http://reviews.llvm.org/D18475

Files:
  clang-tidy/readability/RedundantStringCStrCheck.cpp
  test/clang-tidy/readability-redundant-string-cstr.cpp

Index: clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -103,20 +103,83 @@
 callee(cxxMethodDecl(hasName("c_str"
   .bind("call");

+  // Detect redundant 'c_str()' calls through a string constructor.
   Finder->addMatcher(
   cxxConstructExpr(StringConstructorExpr,
hasArgument(0, StringCStrCallExpr)),
   this);

+  // Detect: 's == str.c_str()'  ->  's == str'
   Finder->addMatcher(
+  cxxOperatorCallExpr(
+  anyOf(hasOverloadedOperatorName("<"),
+hasOverloadedOperatorName(">"),
+hasOverloadedOperatorName(">="),
+hasOverloadedOperatorName("<="),
+hasOverloadedOperatorName("!="),
+hasOverloadedOperatorName("=="),
+hasOverloadedOperatorName("+")),
+  anyOf(allOf(hasArgument(0, StringExpr),
+  hasArgument(1, StringCStrCallExpr)),
+allOf(hasArgument(0, StringCStrCallExpr),
+  hasArgument(1, StringExpr,
+  this);
+
+  // Detect: 'dst += str.c_str()'  ->  'dst += str'
+  // Detect: 's == str.c_str()'  ->  's == str'
+  Finder->addMatcher(
+  cxxOperatorCallExpr(
+  anyOf(hasOverloadedOperatorName("="),
+hasOverloadedOperatorName("+=")),
+  hasArgument(0, StringExpr),
+  hasArgument(1, StringCStrCallExpr)),
+  this);
+
+  // Detect: 'dst.append(str.c_str())'  ->  'dst.append(str)'
+  Finder->addMatcher(
+  cxxMemberCallExpr(on(StringExpr),
+  callee(decl(cxxMethodDecl(
+  hasAnyName("append", "assign", "compare",
+  argumentCountIs(1),
+  hasArgument(0, StringCStrCallExpr)),
+  this);
+
+  // Detect: 'dst.compare(p, n, str.c_str())'  ->  'dst.compare(p, n, str)'
+  Finder->addMatcher(
+  cxxMemberCallExpr(on(StringExpr),
+  callee(decl(cxxMethodDecl(hasName("compare",
+  argumentCountIs(3),
+  hasArgument(2, StringCStrCallExpr)),
+  this);
+
+  // Detect: 'dst.find(str.c_str())'  ->  'dst.find(str)'
+  Finder->addMatcher(
+  cxxMemberCallExpr(on(StringExpr),
+  callee(decl(cxxMethodDecl(
+  hasAnyName("find", "find_first_not_of", "find_first_of",
+ "find_last_not_of", "find_last_of", "rfind",
+  anyOf(argumentCountIs(1), argumentCountIs(2)),
+  hasArgument(0, StringCStrCallExpr)),
+  this);
+
+  // Detect: 'dst.insert(pos, str.c_str())'  ->  'dst.insert(pos, str)'
+  Finder->addMatcher(
+  cxxMemberCallExpr(on(StringExpr),
+  callee(decl(cxxMethodDecl(hasName("insert",
+  argumentCountIs(2),
+  hasArgument(1, StringCStrCallExpr)),
+  this);
+
+  // Detect redundant 'c_str()' calls through a StringRef constructor.
+  Finder->addMatcher(
   cxxConstructExpr(
   // Implicit constructors of these classes are overloaded
   // wrt. string types and they internally make a StringRef
   // referring to the argument.  Passing a string directly to
   // them is preferred to passing a char pointer.
   hasDeclaration(
-  cxxMethodDecl(anyOf(hasName("::llvm::StringRef::StringRef"),
-  hasName("::llvm::Twine::Twine",
+  cxxMethodDecl(hasAnyName("::llvm::StringRef::StringRef",
+   "::llvm::Twine::Twine"))),
   argumentCountIs(1),
   // The only argument must have the form x.c_str() or p->c_str()
   // where the method is string::c_str().  StringRef also has
Index: test/clang-tidy/readability-redundant-string-cstr.cpp
===
--- test/clang-tidy/readability-redundant-string-cstr.cpp
+++ test/clang-tidy/readability-redundant-string-cstr.cpp
@@ -1,5 +1,8 @@
-// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t -- -- -target x86_64-unknown -std=c++11
+// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t -- -- -std=c++11

+typedef unsigned __INT16_TYPE__ char16;
+typedef unsigned __INT32_TYPE__ char32;
+
 namespace std {
 template 
 class allocator {};
@@ -7,16 +10,50 @@
 class char_traits {};
 template 
 struct basic_string {
+  typedef basic_string _Type;
   basic_string();
   basic_string(const C *p, const A &a = A());
+
   const C *c_str() const;
+
+  _Type& append(const C *s);
+  _Type& append(const C *s, size_

Re: [PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.

2016-03-25 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

chapuni@: I would like to know why "-target x86_64-unknown -std=c++11" was 
needed.

I'm fixing an issue with char16_t/char32_t. Is that the problem you just fixed?


http://reviews.llvm.org/D18475



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


r264428 - [ASTMatchers] Fix build for VariadicFunction.

2016-03-25 Thread Samuel Benzaquen via cfe-commits
Author: sbenza
Date: Fri Mar 25 12:46:02 2016
New Revision: 264428

URL: http://llvm.org/viewvc/llvm-project?rev=264428&view=rev
Log:
[ASTMatchers] Fix build for VariadicFunction.

Under some conditions the implicit conversion from array to ArrayRef<>
is not working.
Fix the build by making it explicit.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264428&r1=264427&r2=264428&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25 
12:46:02 2016
@@ -90,7 +90,7 @@ private:
   // before we make the array.
   template  ResultT Execute(const ArgsT &... Args) const {
 const ArgT *const ArgsArray[] = {&Args...};
-return Func(ArgsArray);
+return Func(ArrayRef(ArgsArray, sizeof...(ArgsT)));
   }
 };
 


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


Re: [PATCH] D18461: ObjCXX: Warn undeclared identifiers.

2016-03-25 Thread Manman Ren via cfe-commits
manmanren added a comment.

In http://reviews.llvm.org/D18461#383218, @rjmccall wrote:

> Oh, you know, this should really propagate all the dependence bits, not just 
> instantiation-dependence.  It would be safer, at least.  You could probably 
> find a contrived example involving value-dependence.


Thanks for the quick review, John!

I will propagate all the dependence bits and commit.

Cheers,
Manman


http://reviews.llvm.org/D18461



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


Re: r264428 - [ASTMatchers] Fix build for VariadicFunction.

2016-03-25 Thread David Blaikie via cfe-commits
On Fri, Mar 25, 2016 at 10:46 AM, Samuel Benzaquen via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: sbenza
> Date: Fri Mar 25 12:46:02 2016
> New Revision: 264428
>
> URL: http://llvm.org/viewvc/llvm-project?rev=264428&view=rev
> Log:
> [ASTMatchers] Fix build for VariadicFunction.
>
> Under some conditions the implicit conversion from array to ArrayRef<>
> is not working.
>

Any idea what those conditions are?


> Fix the build by making it explicit.
>
> Modified:
> cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264428&r1=264427&r2=264428&view=diff
>
> ==
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25
> 12:46:02 2016
> @@ -90,7 +90,7 @@ private:
>// before we make the array.
>template  ResultT Execute(const ArgsT &... Args)
> const {
>  const ArgT *const ArgsArray[] = {&Args...};
> -return Func(ArgsArray);
> +return Func(ArrayRef(ArgsArray, sizeof...(ArgsT)));
>}
>  };
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18275: [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.
etienneb added a comment.

Any plan for doing the same for : hasOverloadedOperatorName ?


Repository:
  rL LLVM

http://reviews.llvm.org/D18275



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


Re: r264428 - [ASTMatchers] Fix build for VariadicFunction.

2016-03-25 Thread Alexey Samsonov via cfe-commits
On Fri, Mar 25, 2016 at 10:55 AM, David Blaikie via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
>
> On Fri, Mar 25, 2016 at 10:46 AM, Samuel Benzaquen via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: sbenza
>> Date: Fri Mar 25 12:46:02 2016
>> New Revision: 264428
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=264428&view=rev
>> Log:
>> [ASTMatchers] Fix build for VariadicFunction.
>>
>> Under some conditions the implicit conversion from array to ArrayRef<>
>> is not working.
>>
>
> Any idea what those conditions are?
>

This was causing the build failure with opt GCC. I will try to create a
smaller reproducer later today.


>
>
>> Fix the build by making it explicit.
>>
>> Modified:
>> cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>>
>> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264428&r1=264427&r2=264428&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
>> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25
>> 12:46:02 2016
>> @@ -90,7 +90,7 @@ private:
>>// before we make the array.
>>template  ResultT Execute(const ArgsT &... Args)
>> const {
>>  const ArgT *const ArgsArray[] = {&Args...};
>> -return Func(ArgsArray);
>> +return Func(ArrayRef(ArgsArray, sizeof...(ArgsT)));
>>}
>>  };
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>


-- 
Alexey Samsonov
vonos...@gmail.com
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18275: [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Samuel Benzaquen via cfe-commits
On Fri, Mar 25, 2016 at 1:55 PM, Etienne Bergeron 
wrote:

> etienneb added a subscriber: etienneb.
> etienneb added a comment.
>
> Any plan for doing the same for : hasOverloadedOperatorName ?
>

hasAnyName() was added mostly for performance reasons.
We could add the 'Any' version of hasOverloadedOperatorName, but there
doesn't seem to be that much need for it right now.


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


Re: [PATCH] D18275: [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Etienne Bergeron via cfe-commits
> hasAnyName() was added mostly for performance reasons.

Fair enough. Thanks.

On Fri, Mar 25, 2016 at 2:01 PM, Samuel Benzaquen  wrote:

> On Fri, Mar 25, 2016 at 1:55 PM, Etienne Bergeron 
> wrote:
>
>> etienneb added a subscriber: etienneb.
>> etienneb added a comment.
>>
>> Any plan for doing the same for : hasOverloadedOperatorName ?
>>
>
> hasAnyName() was added mostly for performance reasons.
> We could add the 'Any' version of hasOverloadedOperatorName, but there
> doesn't seem to be that much need for it right now.
>
>
>>
>>
>> Repository:
>>   rL LLVM
>>
>> http://reviews.llvm.org/D18275
>>
>>
>>
>>
>


-- 
Etienne Bergeron
Chrome Protector team, Chrome
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18475: [clang-tidy] Add more detection rules for redundant c_str calls.

2016-03-25 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 51664.
etienneb updated the summary for this revision.
etienneb added a comment.

fix unittest on linux/32-bits.
tested on windows/32-bits.


http://reviews.llvm.org/D18475

Files:
  clang-tidy/readability/RedundantStringCStrCheck.cpp
  test/clang-tidy/readability-redundant-string-cstr.cpp

Index: test/clang-tidy/readability-redundant-string-cstr.cpp
===
--- test/clang-tidy/readability-redundant-string-cstr.cpp
+++ test/clang-tidy/readability-redundant-string-cstr.cpp
@@ -1,22 +1,60 @@
-// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t -- -- -target x86_64-unknown -std=c++11
+// RUN: %check_clang_tidy %s readability-redundant-string-cstr %t -- -- -std=c++11
+
+typedef unsigned __INT16_TYPE__ char16;
+typedef unsigned __INT32_TYPE__ char32;
+typedef __SIZE_TYPE__ size;
 
 namespace std {
 template 
 class allocator {};
 template 
 class char_traits {};
 template 
 struct basic_string {
+  typedef basic_string _Type;
   basic_string();
   basic_string(const C *p, const A &a = A());
+
   const C *c_str() const;
+
+  _Type& append(const C *s);
+  _Type& append(const C *s, size n);
+  _Type& assign(const C *s);
+  _Type& assign(const C *s, size n);
+
+  int compare(const _Type&) const;
+  int compare(const C* s) const;
+  int compare(size pos, size len, const _Type&) const;
+  int compare(size pos, size len, const C* s) const;
+
+  size find(const _Type& str, size pos = 0) const;
+  size find(const C* s, size pos = 0) const;
+  size find(const C* s, size pos, size n) const;
+
+  _Type& insert(size pos, const _Type& str);
+  _Type& insert(size pos, const C* s);
+  _Type& insert(size pos, const C* s, size n);
+
+  _Type& operator+=(const _Type& str);
+  _Type& operator+=(const C* s);
+  _Type& operator=(const _Type& str);
+  _Type& operator=(const C* s);
 };
+
 typedef basic_string, std::allocator> string;
 typedef basic_string, std::allocator> wstring;
-typedef basic_string, std::allocator> u16string;
-typedef basic_string, std::allocator> u32string;
+typedef basic_string, std::allocator> u16string;
+typedef basic_string, std::allocator> u32string;
 }
 
+std::string operator+(const std::string&, const std::string&);
+std::string operator+(const std::string&, const char*);
+std::string operator+(const char*, const std::string&);
+
+bool operator==(const std::string&, const std::string&);
+bool operator==(const std::string&, const char*);
+bool operator==(const char*, const std::string&);
+
 namespace llvm {
 struct StringRef {
   StringRef(const char *p);
@@ -51,6 +89,80 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: redundant call to `c_str()` [readability-redundant-string-cstr]
   // CHECK-FIXES: {{^  }}f1(*ptr);{{$}}
 }
+void f5(const std::string &s) {
+  std::string tmp;
+  tmp.append(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}tmp.append(s);{{$}}
+  tmp.assign(s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}tmp.assign(s);{{$}}
+
+  if (tmp.compare(s.c_str()) == 0) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}if (tmp.compare(s) == 0) return;{{$}}
+
+  if (tmp.compare(1, 2, s.c_str()) == 0) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}if (tmp.compare(1, 2, s) == 0) return;{{$}}
+
+  if (tmp.find(s.c_str()) == 0) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}if (tmp.find(s) == 0) return;{{$}}
+
+  if (tmp.find(s.c_str(), 2) == 0) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}if (tmp.find(s, 2) == 0) return;{{$}}
+
+  if (tmp.find(s.c_str(), 2) == 0) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}if (tmp.find(s, 2) == 0) return;{{$}}
+
+  tmp.insert(1, s.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}tmp.insert(1, s);{{$}}
+
+  tmp = s.c_str();
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}tmp = s;{{$}}
+
+  tmp += s.c_str();
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}tmp += s;{{$}}
+
+  if (tmp == s.c_str()) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}if (tmp == s) return;{{$}}
+
+  tmp = s + s.c_str();
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}tmp = s + s;{{$}}
+
+  tmp = s.c_str() + s;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant call {{.*}}
+  // CHECK-FIXES: {{^  }}tmp = s + s;{{$}}
+}
+void f6(const std::string &s) {
+  std::string tmp;
+  tmp.append(s.c_str(), 2);
+  tmp.assign(s.c_str(), 2);
+
+ 

Re: r264417 - [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Mehdi Amini via cfe-commits
Hi,

I think this broke clang-tidy somehow: 
http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10881/steps/build%20stage%201/logs/stdio

-- 
Mehdi




> On Mar 25, 2016, at 9:29 AM, Samuel Benzaquen via cfe-commits 
>  wrote:
> 
> Author: sbenza
> Date: Fri Mar 25 11:29:30 2016
> New Revision: 264417
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=264417&view=rev
> Log:
> [ASTMatchers] Add own version of VariadicFunction.
> 
> Summary:
> llvm::VariadicFunction is only being used by ASTMatchers.
> Having our own copy here allows us to remove the other one from llvm/ADT.
> Also, we can extend the API to meet our needs without modifying the common
> implementation.
> 
> Reviewers: alexfh
> 
> Subscribers: klimek, cfe-commits
> 
> Differential Revision: http://reviews.llvm.org/D18275
> 
> Modified:
>cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
>cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
> 
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=264417&r1=264416&r2=264417&view=diff
> ==
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar 25 11:29:30 2016
> @@ -1990,8 +1990,8 @@ inline internal::Matcher hasN
> /// \code
> /// anyOf(hasName(a), hasName(b), hasName(c))
> /// \endcode
> -const llvm::VariadicFunction, StringRef,
> - internal::hasAnyNameFunc>
> +const internal::VariadicFunction, StringRef,
> + internal::hasAnyNameFunc>
> hasAnyName = {};
> 
> /// \brief Matches NamedDecl nodes whose fully qualified names contain
> 
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264417&r1=264416&r2=264417&view=diff
> ==
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25 
> 11:29:30 2016
> @@ -46,8 +46,9 @@
> #include "clang/AST/StmtCXX.h"
> #include "clang/AST/StmtObjC.h"
> #include "clang/AST/Type.h"
> +#include "llvm/ADT/ArrayRef.h"
> #include "llvm/ADT/Optional.h"
> -#include "llvm/ADT/VariadicFunction.h"
> +#include "llvm/ADT/SmallVector.h"
> #include "llvm/Support/ManagedStatic.h"
> #include 
> #include 
> @@ -60,6 +61,39 @@ class BoundNodes;
> 
> namespace internal {
> 
> +/// \brief Variadic function object.
> +///
> +/// Most of the functions below that use VariadicFunction could be 
> implemented
> +/// using plain C++11 variadic functions, but the function object allows us 
> to
> +/// capture it on the dynamic matcher registry.
> +template  +  ResultT (*Func)(ArrayRef)>
> +struct VariadicFunction {
> +  ResultT operator()() const { return Func({}); }
> +
> +  template 
> +  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
> +return Execute(Arg1, static_cast(Args)...);
> +  }
> +
> +  // We also allow calls with an already created array, in case the caller
> +  // already had it.
> +  ResultT operator()(ArrayRef Args) const {
> +SmallVector InnerArgs;
> +for (const ArgT &Arg : Args)
> +  InnerArgs.push_back(&Arg);
> +return Func(InnerArgs);
> +  }
> +
> +private:
> +  // Trampoline function to allow for implicit conversions to take place
> +  // before we make the array.
> +  template  ResultT Execute(const ArgsT &... Args) const {
> +const ArgT *const ArgsArray[] = {&Args...};
> +return Func(ArgsArray);
> +  }
> +};
> +
> /// \brief Unifies obtaining the underlying type of a regular node through
> /// `getType` and a TypedefNameDecl node through `getUnderlyingType`.
> template 
> @@ -1405,9 +1439,8 @@ inline bool ValueEqualsMatcher /// casted to CXXRecordDecl and all given matchers match.
> template 
> class VariadicDynCastAllOfMatcher
> -: public llvm::VariadicFunction<
> -BindableMatcher, Matcher,
> -makeDynCastAllOfComposite > {
> +: public VariadicFunction, Matcher,
> +  makeDynCastAllOfComposite> {
> public:
>   VariadicDynCastAllOfMatcher() {}
> };
> @@ -1423,9 +1456,9 @@ public:
> /// \c Matcher.
> /// The returned matcher matches if all given matchers match.
> template 
> -class VariadicAllOfMatcher : public llvm::VariadicFunction<
> -   BindableMatcher, Matcher,
> -   makeAllOfComposite > {
> +class VariadicAllOfMatcher
> +: public VariadicFunction, Matcher,
> +  makeAllOfComposite> {
> public:
>   VariadicAllOfMatcher() {}
> };
> @@ -

Re: [PATCH] D18461: ObjCXX: Warn undeclared identifiers.

2016-03-25 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL26: [ObjCXX] Warn undeclared identifiers. (authored by 
mren).

Changed prior to commit:
  http://reviews.llvm.org/D18461?vs=51598&id=51667#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18461

Files:
  cfe/trunk/include/clang/AST/Expr.h
  cfe/trunk/include/clang/AST/Stmt.h
  cfe/trunk/test/SemaObjCXX/typo-correction.mm

Index: cfe/trunk/include/clang/AST/Stmt.h
===
--- cfe/trunk/include/clang/AST/Stmt.h
+++ cfe/trunk/include/clang/AST/Stmt.h
@@ -115,6 +115,7 @@
 friend class OverloadExpr; // ctor
 friend class PseudoObjectExpr; // ctor
 friend class AtomicExpr; // ctor
+friend class OpaqueValueExpr; // ctor
 unsigned : NumStmtBits;
 
 unsigned ValueKind : 2;
Index: cfe/trunk/include/clang/AST/Expr.h
===
--- cfe/trunk/include/clang/AST/Expr.h
+++ cfe/trunk/include/clang/AST/Expr.h
@@ -847,10 +847,12 @@
   ExprObjectKind OK = OK_Ordinary,
   Expr *SourceExpr = nullptr)
 : Expr(OpaqueValueExprClass, T, VK, OK,
-   T->isDependentType(), 
+   T->isDependentType() ||
+   (SourceExpr && SourceExpr->isTypeDependent()),
T->isDependentType() || 
(SourceExpr && SourceExpr->isValueDependent()),
-   T->isInstantiationDependentType(),
+   T->isInstantiationDependentType() ||
+   (SourceExpr && SourceExpr->isInstantiationDependent()),
false),
   SourceExpr(SourceExpr), Loc(Loc) {
   }
Index: cfe/trunk/test/SemaObjCXX/typo-correction.mm
===
--- cfe/trunk/test/SemaObjCXX/typo-correction.mm
+++ cfe/trunk/test/SemaObjCXX/typo-correction.mm
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+class ClassA {};
+
+class ClassB {
+public:
+  ClassB(ClassA* parent=0);
+  ~ClassB();
+};
+
+@interface NSObject
+@end
+
+@interface InterfaceA : NSObject
+@property(nonatomic, assign) ClassA *m_prop1; // expected-note {{here}}
+@property(nonatomic, assign) ClassB *m_prop2;
+@end
+
+@implementation InterfaceA
+- (id)test {
+  self.m_prop2 = new ClassB(m_prop1); // expected-error {{use of undeclared 
identifier 'm_prop1'; did you mean '_m_prop1'?}}
+}
+@end


Index: cfe/trunk/include/clang/AST/Stmt.h
===
--- cfe/trunk/include/clang/AST/Stmt.h
+++ cfe/trunk/include/clang/AST/Stmt.h
@@ -115,6 +115,7 @@
 friend class OverloadExpr; // ctor
 friend class PseudoObjectExpr; // ctor
 friend class AtomicExpr; // ctor
+friend class OpaqueValueExpr; // ctor
 unsigned : NumStmtBits;
 
 unsigned ValueKind : 2;
Index: cfe/trunk/include/clang/AST/Expr.h
===
--- cfe/trunk/include/clang/AST/Expr.h
+++ cfe/trunk/include/clang/AST/Expr.h
@@ -847,10 +847,12 @@
   ExprObjectKind OK = OK_Ordinary,
   Expr *SourceExpr = nullptr)
 : Expr(OpaqueValueExprClass, T, VK, OK,
-   T->isDependentType(), 
+   T->isDependentType() ||
+   (SourceExpr && SourceExpr->isTypeDependent()),
T->isDependentType() || 
(SourceExpr && SourceExpr->isValueDependent()),
-   T->isInstantiationDependentType(),
+   T->isInstantiationDependentType() ||
+   (SourceExpr && SourceExpr->isInstantiationDependent()),
false),
   SourceExpr(SourceExpr), Loc(Loc) {
   }
Index: cfe/trunk/test/SemaObjCXX/typo-correction.mm
===
--- cfe/trunk/test/SemaObjCXX/typo-correction.mm
+++ cfe/trunk/test/SemaObjCXX/typo-correction.mm
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+class ClassA {};
+
+class ClassB {
+public:
+  ClassB(ClassA* parent=0);
+  ~ClassB();
+};
+
+@interface NSObject
+@end
+
+@interface InterfaceA : NSObject
+@property(nonatomic, assign) ClassA *m_prop1; // expected-note {{here}}
+@property(nonatomic, assign) ClassB *m_prop2;
+@end
+
+@implementation InterfaceA
+- (id)test {
+  self.m_prop2 = new ClassB(m_prop1); // expected-error {{use of undeclared identifier 'm_prop1'; did you mean '_m_prop1'?}}
+}
+@end
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r264444 - [ObjCXX] Warn undeclared identifiers.

2016-03-25 Thread Manman Ren via cfe-commits
Author: mren
Date: Fri Mar 25 13:43:46 2016
New Revision: 26

URL: http://llvm.org/viewvc/llvm-project?rev=26&view=rev
Log:
[ObjCXX] Warn undeclared identifiers.

Instantiation dependence were not being handled correctly for OpqaueValueExpr
AST nodes. As a result, if an undeclared identifier was used in a CXXNewExpr
that is assigned to a ObjC property, there would be no error during parsing, and
there would be a crash during code gen. This patch makes sure that an error
will be issued during parsing in this case.

Before the fix, if CXXNewExpr has a typo, its InstantiationDependent will be
set to true, but if it is wrapped in a OpaqueValueExpr, the OpaqueValueExpr will
not be instantiation dependent, causing the TypoExpr not be to resolved. The fix
propagates InstantiationDependent to OpaqueValueExpr from its SourceExpr. It
also propagates the other instantiation bits.

rdar://24975562

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

Added:
cfe/trunk/test/SemaObjCXX/typo-correction.mm
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=26&r1=264443&r2=26&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Mar 25 13:43:46 2016
@@ -847,10 +847,12 @@ public:
   ExprObjectKind OK = OK_Ordinary,
   Expr *SourceExpr = nullptr)
 : Expr(OpaqueValueExprClass, T, VK, OK,
-   T->isDependentType(), 
+   T->isDependentType() ||
+   (SourceExpr && SourceExpr->isTypeDependent()),
T->isDependentType() || 
(SourceExpr && SourceExpr->isValueDependent()),
-   T->isInstantiationDependentType(),
+   T->isInstantiationDependentType() ||
+   (SourceExpr && SourceExpr->isInstantiationDependent()),
false),
   SourceExpr(SourceExpr), Loc(Loc) {
   }

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=26&r1=264443&r2=26&view=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Mar 25 13:43:46 2016
@@ -115,6 +115,7 @@ protected:
 friend class OverloadExpr; // ctor
 friend class PseudoObjectExpr; // ctor
 friend class AtomicExpr; // ctor
+friend class OpaqueValueExpr; // ctor
 unsigned : NumStmtBits;
 
 unsigned ValueKind : 2;

Added: cfe/trunk/test/SemaObjCXX/typo-correction.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/typo-correction.mm?rev=26&view=auto
==
--- cfe/trunk/test/SemaObjCXX/typo-correction.mm (added)
+++ cfe/trunk/test/SemaObjCXX/typo-correction.mm Fri Mar 25 13:43:46 2016
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+class ClassA {};
+
+class ClassB {
+public:
+  ClassB(ClassA* parent=0);
+  ~ClassB();
+};
+
+@interface NSObject
+@end
+
+@interface InterfaceA : NSObject
+@property(nonatomic, assign) ClassA *m_prop1; // expected-note {{here}}
+@property(nonatomic, assign) ClassB *m_prop2;
+@end
+
+@implementation InterfaceA
+- (id)test {
+  self.m_prop2 = new ClassB(m_prop1); // expected-error {{use of undeclared 
identifier 'm_prop1'; did you mean '_m_prop1'?}}
+}
+@end


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


[PATCH] D18478: python bindings: expose the clang version string

2016-03-25 Thread John Törnblom via cfe-commits
john.tornblom created this revision.
john.tornblom added reviewers: eliben, compnerd.
john.tornblom added a subscriber: cfe-commits.

http://reviews.llvm.org/D18478

Files:
  bindings/python/clang/cindex.py

Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -3007,6 +3007,9 @@
Type,
Type.from_result),
 
+  ("clang_getClangVersion",
+   [], _CXString),
+
   ("clang_getCompletionAvailability",
[c_void_p],
c_int),
@@ -3625,6 +3628,16 @@
 
 return True
 
+@property
+def version_string(self):
+"""Return a version string, suitable for showing to a user
+
+The version string is not intended to be parsed, and the format is not
+guaranteed to be stable.
+"""
+version = self.lib.clang_getClangVersion()
+return version.spelling
+
 def register_enumerations():
 for name, value in clang.enumerations.TokenKinds:
 TokenKind.register(value, name)


Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -3007,6 +3007,9 @@
Type,
Type.from_result),
 
+  ("clang_getClangVersion",
+   [], _CXString),
+
   ("clang_getCompletionAvailability",
[c_void_p],
c_int),
@@ -3625,6 +3628,16 @@
 
 return True
 
+@property
+def version_string(self):
+"""Return a version string, suitable for showing to a user
+
+The version string is not intended to be parsed, and the format is not
+guaranteed to be stable.
+"""
+version = self.lib.clang_getClangVersion()
+return version.spelling
+
 def register_enumerations():
 for name, value in clang.enumerations.TokenKinds:
 TokenKind.register(value, name)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r264417 - [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Samuel Benzaquen via cfe-commits
I believe r264428 fixes this problem.

On Fri, Mar 25, 2016 at 2:18 PM, Mehdi Amini  wrote:

> Hi,
>
> I think this broke clang-tidy somehow:
> http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10881/steps/build%20stage%201/logs/stdio
>
> --
> Mehdi
>
>
>
>
> > On Mar 25, 2016, at 9:29 AM, Samuel Benzaquen via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > Author: sbenza
> > Date: Fri Mar 25 11:29:30 2016
> > New Revision: 264417
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=264417&view=rev
> > Log:
> > [ASTMatchers] Add own version of VariadicFunction.
> >
> > Summary:
> > llvm::VariadicFunction is only being used by ASTMatchers.
> > Having our own copy here allows us to remove the other one from llvm/ADT.
> > Also, we can extend the API to meet our needs without modifying the
> common
> > implementation.
> >
> > Reviewers: alexfh
> >
> > Subscribers: klimek, cfe-commits
> >
> > Differential Revision: http://reviews.llvm.org/D18275
> >
> > Modified:
> >cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> >cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> >cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
> >cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
> >
> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=264417&r1=264416&r2=264417&view=diff
> >
> ==
> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar 25
> 11:29:30 2016
> > @@ -1990,8 +1990,8 @@ inline internal::Matcher hasN
> > /// \code
> > /// anyOf(hasName(a), hasName(b), hasName(c))
> > /// \endcode
> > -const llvm::VariadicFunction, StringRef,
> > - internal::hasAnyNameFunc>
> > +const internal::VariadicFunction,
> StringRef,
> > + internal::hasAnyNameFunc>
> > hasAnyName = {};
> >
> > /// \brief Matches NamedDecl nodes whose fully qualified names contain
> >
> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264417&r1=264416&r2=264417&view=diff
> >
> ==
> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25
> 11:29:30 2016
> > @@ -46,8 +46,9 @@
> > #include "clang/AST/StmtCXX.h"
> > #include "clang/AST/StmtObjC.h"
> > #include "clang/AST/Type.h"
> > +#include "llvm/ADT/ArrayRef.h"
> > #include "llvm/ADT/Optional.h"
> > -#include "llvm/ADT/VariadicFunction.h"
> > +#include "llvm/ADT/SmallVector.h"
> > #include "llvm/Support/ManagedStatic.h"
> > #include 
> > #include 
> > @@ -60,6 +61,39 @@ class BoundNodes;
> >
> > namespace internal {
> >
> > +/// \brief Variadic function object.
> > +///
> > +/// Most of the functions below that use VariadicFunction could be
> implemented
> > +/// using plain C++11 variadic functions, but the function object
> allows us to
> > +/// capture it on the dynamic matcher registry.
> > +template  > +  ResultT (*Func)(ArrayRef)>
> > +struct VariadicFunction {
> > +  ResultT operator()() const { return Func({}); }
> > +
> > +  template 
> > +  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
> > +return Execute(Arg1, static_cast(Args)...);
> > +  }
> > +
> > +  // We also allow calls with an already created array, in case the
> caller
> > +  // already had it.
> > +  ResultT operator()(ArrayRef Args) const {
> > +SmallVector InnerArgs;
> > +for (const ArgT &Arg : Args)
> > +  InnerArgs.push_back(&Arg);
> > +return Func(InnerArgs);
> > +  }
> > +
> > +private:
> > +  // Trampoline function to allow for implicit conversions to take place
> > +  // before we make the array.
> > +  template  ResultT Execute(const ArgsT &... Args)
> const {
> > +const ArgT *const ArgsArray[] = {&Args...};
> > +return Func(ArgsArray);
> > +  }
> > +};
> > +
> > /// \brief Unifies obtaining the underlying type of a regular node
> through
> > /// `getType` and a TypedefNameDecl node through `getUnderlyingType`.
> > template 
> > @@ -1405,9 +1439,8 @@ inline bool ValueEqualsMatcher > /// casted to CXXRecordDecl and all given matchers match.
> > template 
> > class VariadicDynCastAllOfMatcher
> > -: public llvm::VariadicFunction<
> > -BindableMatcher, Matcher,
> > -makeDynCastAllOfComposite > {
> > +: public VariadicFunction,
> Matcher,
> > +  makeDynCastAllOfComposite TargetT>> {
> > public:
> >   VariadicDynCastAllOfMatcher() {}
> > };
> > @@ -1423,9 +1456,9 @@ public:
> > /// \c Matcher.
> > /// The returned matcher matches if all given matchers m

Re: r264417 - [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Mehdi Amini via cfe-commits
The link I provided is testing r264430...

-- 
Mehdi

> On Mar 25, 2016, at 12:25 PM, Samuel Benzaquen  wrote:
> 
> I believe r264428 fixes this problem.
> 
> On Fri, Mar 25, 2016 at 2:18 PM, Mehdi Amini  > wrote:
> Hi,
> 
> I think this broke clang-tidy somehow: 
> http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10881/steps/build%20stage%201/logs/stdio
>  
> 
> 
> --
> Mehdi
> 
> 
> 
> 
> > On Mar 25, 2016, at 9:29 AM, Samuel Benzaquen via cfe-commits 
> > mailto:cfe-commits@lists.llvm.org>> wrote:
> >
> > Author: sbenza
> > Date: Fri Mar 25 11:29:30 2016
> > New Revision: 264417
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=264417&view=rev 
> > 
> > Log:
> > [ASTMatchers] Add own version of VariadicFunction.
> >
> > Summary:
> > llvm::VariadicFunction is only being used by ASTMatchers.
> > Having our own copy here allows us to remove the other one from llvm/ADT.
> > Also, we can extend the API to meet our needs without modifying the common
> > implementation.
> >
> > Reviewers: alexfh
> >
> > Subscribers: klimek, cfe-commits
> >
> > Differential Revision: http://reviews.llvm.org/D18275 
> > 
> >
> > Modified:
> >cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> >cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> >cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
> >cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
> >
> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=264417&r1=264416&r2=264417&view=diff
> >  
> > 
> > ==
> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar 25 11:29:30 
> > 2016
> > @@ -1990,8 +1990,8 @@ inline internal::Matcher hasN
> > /// \code
> > /// anyOf(hasName(a), hasName(b), hasName(c))
> > /// \endcode
> > -const llvm::VariadicFunction, StringRef,
> > - internal::hasAnyNameFunc>
> > +const internal::VariadicFunction, StringRef,
> > + internal::hasAnyNameFunc>
> > hasAnyName = {};
> >
> > /// \brief Matches NamedDecl nodes whose fully qualified names contain
> >
> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> > URL: 
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264417&r1=264416&r2=264417&view=diff
> >  
> > 
> > ==
> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25 
> > 11:29:30 2016
> > @@ -46,8 +46,9 @@
> > #include "clang/AST/StmtCXX.h"
> > #include "clang/AST/StmtObjC.h"
> > #include "clang/AST/Type.h"
> > +#include "llvm/ADT/ArrayRef.h"
> > #include "llvm/ADT/Optional.h"
> > -#include "llvm/ADT/VariadicFunction.h"
> > +#include "llvm/ADT/SmallVector.h"
> > #include "llvm/Support/ManagedStatic.h"
> > #include 
> > #include 
> > @@ -60,6 +61,39 @@ class BoundNodes;
> >
> > namespace internal {
> >
> > +/// \brief Variadic function object.
> > +///
> > +/// Most of the functions below that use VariadicFunction could be 
> > implemented
> > +/// using plain C++11 variadic functions, but the function object allows 
> > us to
> > +/// capture it on the dynamic matcher registry.
> > +template  > +  ResultT (*Func)(ArrayRef)>
> > +struct VariadicFunction {
> > +  ResultT operator()() const { return Func({}); }
> > +
> > +  template 
> > +  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
> > +return Execute(Arg1, static_cast(Args)...);
> > +  }
> > +
> > +  // We also allow calls with an already created array, in case the caller
> > +  // already had it.
> > +  ResultT operator()(ArrayRef Args) const {
> > +SmallVector InnerArgs;
> > +for (const ArgT &Arg : Args)
> > +  InnerArgs.push_back(&Arg);
> > +return Func(InnerArgs);
> > +  }
> > +
> > +private:
> > +  // Trampoline function to allow for implicit conversions to take place
> > +  // before we make the array.
> > +  template  ResultT Execute(const ArgsT &... Args) 
> > const {
> > +const ArgT *const ArgsArray[] = {&Args...};
> > +return Func(ArgsArray);
> > +  }
> > +};
> > +
> > /// \brief Unifies obtaining the underlying type of a regular node through

Re: r264417 - [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Samuel Benzaquen via cfe-commits
Sorry, this is an unrelated problem.
It is using brace-init lists and the supported MSVC version does not
support them.
I'll fix that.

On Fri, Mar 25, 2016 at 3:27 PM, Mehdi Amini  wrote:

> The link I provided is testing r264430...
>
> --
> Mehdi
>
> On Mar 25, 2016, at 12:25 PM, Samuel Benzaquen  wrote:
>
> I believe r264428 fixes this problem.
>
> On Fri, Mar 25, 2016 at 2:18 PM, Mehdi Amini 
> wrote:
>
>> Hi,
>>
>> I think this broke clang-tidy somehow:
>> http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10881/steps/build%20stage%201/logs/stdio
>>
>> --
>> Mehdi
>>
>>
>>
>>
>> > On Mar 25, 2016, at 9:29 AM, Samuel Benzaquen via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>> >
>> > Author: sbenza
>> > Date: Fri Mar 25 11:29:30 2016
>> > New Revision: 264417
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=264417&view=rev
>> > Log:
>> > [ASTMatchers] Add own version of VariadicFunction.
>> >
>> > Summary:
>> > llvm::VariadicFunction is only being used by ASTMatchers.
>> > Having our own copy here allows us to remove the other one from
>> llvm/ADT.
>> > Also, we can extend the API to meet our needs without modifying the
>> common
>> > implementation.
>> >
>> > Reviewers: alexfh
>> >
>> > Subscribers: klimek, cfe-commits
>> >
>> > Differential Revision: http://reviews.llvm.org/D18275
>> >
>> > Modified:
>> >cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>> >cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>> >cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
>> >cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
>> >
>> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>> > URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=264417&r1=264416&r2=264417&view=diff
>> >
>> ==
>> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
>> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar 25
>> 11:29:30 2016
>> > @@ -1990,8 +1990,8 @@ inline internal::Matcher hasN
>> > /// \code
>> > /// anyOf(hasName(a), hasName(b), hasName(c))
>> > /// \endcode
>> > -const llvm::VariadicFunction, StringRef,
>> > - internal::hasAnyNameFunc>
>> > +const internal::VariadicFunction,
>> StringRef,
>> > + internal::hasAnyNameFunc>
>> > hasAnyName = {};
>> >
>> > /// \brief Matches NamedDecl nodes whose fully qualified names contain
>> >
>> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>> > URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264417&r1=264416&r2=264417&view=diff
>> >
>> ==
>> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
>> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar
>> 25 11:29:30 2016
>> > @@ -46,8 +46,9 @@
>> > #include "clang/AST/StmtCXX.h"
>> > #include "clang/AST/StmtObjC.h"
>> > #include "clang/AST/Type.h"
>> > +#include "llvm/ADT/ArrayRef.h"
>> > #include "llvm/ADT/Optional.h"
>> > -#include "llvm/ADT/VariadicFunction.h"
>> > +#include "llvm/ADT/SmallVector.h"
>> > #include "llvm/Support/ManagedStatic.h"
>> > #include 
>> > #include 
>> > @@ -60,6 +61,39 @@ class BoundNodes;
>> >
>> > namespace internal {
>> >
>> > +/// \brief Variadic function object.
>> > +///
>> > +/// Most of the functions below that use VariadicFunction could be
>> implemented
>> > +/// using plain C++11 variadic functions, but the function object
>> allows us to
>> > +/// capture it on the dynamic matcher registry.
>> > +template > > +  ResultT (*Func)(ArrayRef)>
>> > +struct VariadicFunction {
>> > +  ResultT operator()() const { return Func({}); }
>> > +
>> > +  template 
>> > +  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
>> > +return Execute(Arg1, static_cast(Args)...);
>> > +  }
>> > +
>> > +  // We also allow calls with an already created array, in case the
>> caller
>> > +  // already had it.
>> > +  ResultT operator()(ArrayRef Args) const {
>> > +SmallVector InnerArgs;
>> > +for (const ArgT &Arg : Args)
>> > +  InnerArgs.push_back(&Arg);
>> > +return Func(InnerArgs);
>> > +  }
>> > +
>> > +private:
>> > +  // Trampoline function to allow for implicit conversions to take
>> place
>> > +  // before we make the array.
>> > +  template  ResultT Execute(const ArgsT &... Args)
>> const {
>> > +const ArgT *const ArgsArray[] = {&Args...};
>> > +return Func(ArgsArray);
>> > +  }
>> > +};
>> > +
>> > /// \brief Unifies obtaining the underlying type of a regular node
>> through
>> > /// `getType` and a TypedefNameDecl node through `getUnderlyingType`.
>> > template 
>> > @@ -1405,9 +1439,8 @@ inline bool ValueEqualsMatcher> > /// casted to CXXRecordDecl and all given matchers match.
>> > template 
>

r264453 - [ASTMatchers] Don't use brace-init lists.

2016-03-25 Thread Samuel Benzaquen via cfe-commits
Author: sbenza
Date: Fri Mar 25 14:41:32 2016
New Revision: 264453

URL: http://llvm.org/viewvc/llvm-project?rev=264453&view=rev
Log:
[ASTMatchers] Don't use brace-init lists.

They are not supported everywhere yet.
This fixes the MSVC build.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264453&r1=264452&r2=264453&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25 
14:41:32 2016
@@ -69,7 +69,7 @@ namespace internal {
 template )>
 struct VariadicFunction {
-  ResultT operator()() const { return Func({}); }
+  ResultT operator()() const { return Func(None); }
 
   template 
   ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {


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


Re: r264417 - [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Samuel Benzaquen via cfe-commits
Fixed in r264453.
Sorry for the inconvenience.

_Sam

On Fri, Mar 25, 2016 at 3:31 PM, Samuel Benzaquen  wrote:

> Sorry, this is an unrelated problem.
> It is using brace-init lists and the supported MSVC version does not
> support them.
> I'll fix that.
>
>
> On Fri, Mar 25, 2016 at 3:27 PM, Mehdi Amini 
> wrote:
>
>> The link I provided is testing r264430...
>>
>> --
>> Mehdi
>>
>> On Mar 25, 2016, at 12:25 PM, Samuel Benzaquen  wrote:
>>
>> I believe r264428 fixes this problem.
>>
>> On Fri, Mar 25, 2016 at 2:18 PM, Mehdi Amini 
>> wrote:
>>
>>> Hi,
>>>
>>> I think this broke clang-tidy somehow:
>>> http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10881/steps/build%20stage%201/logs/stdio
>>>
>>> --
>>> Mehdi
>>>
>>>
>>>
>>>
>>> > On Mar 25, 2016, at 9:29 AM, Samuel Benzaquen via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>> >
>>> > Author: sbenza
>>> > Date: Fri Mar 25 11:29:30 2016
>>> > New Revision: 264417
>>> >
>>> > URL: http://llvm.org/viewvc/llvm-project?rev=264417&view=rev
>>> > Log:
>>> > [ASTMatchers] Add own version of VariadicFunction.
>>> >
>>> > Summary:
>>> > llvm::VariadicFunction is only being used by ASTMatchers.
>>> > Having our own copy here allows us to remove the other one from
>>> llvm/ADT.
>>> > Also, we can extend the API to meet our needs without modifying the
>>> common
>>> > implementation.
>>> >
>>> > Reviewers: alexfh
>>> >
>>> > Subscribers: klimek, cfe-commits
>>> >
>>> > Differential Revision: http://reviews.llvm.org/D18275
>>> >
>>> > Modified:
>>> >cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>>> >cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>>> >cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
>>> >cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
>>> >
>>> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>>> > URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=264417&r1=264416&r2=264417&view=diff
>>> >
>>> ==
>>> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
>>> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar 25
>>> 11:29:30 2016
>>> > @@ -1990,8 +1990,8 @@ inline internal::Matcher hasN
>>> > /// \code
>>> > /// anyOf(hasName(a), hasName(b), hasName(c))
>>> > /// \endcode
>>> > -const llvm::VariadicFunction, StringRef,
>>> > - internal::hasAnyNameFunc>
>>> > +const internal::VariadicFunction,
>>> StringRef,
>>> > + internal::hasAnyNameFunc>
>>> > hasAnyName = {};
>>> >
>>> > /// \brief Matches NamedDecl nodes whose fully qualified names contain
>>> >
>>> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>>> > URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264417&r1=264416&r2=264417&view=diff
>>> >
>>> ==
>>> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>>> (original)
>>> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar
>>> 25 11:29:30 2016
>>> > @@ -46,8 +46,9 @@
>>> > #include "clang/AST/StmtCXX.h"
>>> > #include "clang/AST/StmtObjC.h"
>>> > #include "clang/AST/Type.h"
>>> > +#include "llvm/ADT/ArrayRef.h"
>>> > #include "llvm/ADT/Optional.h"
>>> > -#include "llvm/ADT/VariadicFunction.h"
>>> > +#include "llvm/ADT/SmallVector.h"
>>> > #include "llvm/Support/ManagedStatic.h"
>>> > #include 
>>> > #include 
>>> > @@ -60,6 +61,39 @@ class BoundNodes;
>>> >
>>> > namespace internal {
>>> >
>>> > +/// \brief Variadic function object.
>>> > +///
>>> > +/// Most of the functions below that use VariadicFunction could be
>>> implemented
>>> > +/// using plain C++11 variadic functions, but the function object
>>> allows us to
>>> > +/// capture it on the dynamic matcher registry.
>>> > +template >> > +  ResultT (*Func)(ArrayRef)>
>>> > +struct VariadicFunction {
>>> > +  ResultT operator()() const { return Func({}); }
>>> > +
>>> > +  template 
>>> > +  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
>>> > +return Execute(Arg1, static_cast(Args)...);
>>> > +  }
>>> > +
>>> > +  // We also allow calls with an already created array, in case the
>>> caller
>>> > +  // already had it.
>>> > +  ResultT operator()(ArrayRef Args) const {
>>> > +SmallVector InnerArgs;
>>> > +for (const ArgT &Arg : Args)
>>> > +  InnerArgs.push_back(&Arg);
>>> > +return Func(InnerArgs);
>>> > +  }
>>> > +
>>> > +private:
>>> > +  // Trampoline function to allow for implicit conversions to take
>>> place
>>> > +  // before we make the array.
>>> > +  template  ResultT Execute(const ArgsT &... Args)
>>> const {
>>> > +const ArgT *const ArgsArray[] = {&Args...};
>>> > +return Func(ArgsArray);
>>> > +  }
>>> > +};
>>> > +
>>> > /// \brief Unifies obtaining the 

Re: r264417 - [ASTMatchers] Add own version of VariadicFunction.

2016-03-25 Thread Mehdi Amini via cfe-commits
Thanks!

> On Mar 25, 2016, at 12:47 PM, Samuel Benzaquen  wrote:
> 
> Fixed in r264453.
> Sorry for the inconvenience.
> 
> _Sam
> 
> On Fri, Mar 25, 2016 at 3:31 PM, Samuel Benzaquen  > wrote:
> Sorry, this is an unrelated problem.
> It is using brace-init lists and the supported MSVC version does not support 
> them.
> I'll fix that.
> 
> 
> On Fri, Mar 25, 2016 at 3:27 PM, Mehdi Amini  > wrote:
> The link I provided is testing r264430...
> 
> -- 
> Mehdi
> 
>> On Mar 25, 2016, at 12:25 PM, Samuel Benzaquen > > wrote:
>> 
>> I believe r264428 fixes this problem.
>> 
>> On Fri, Mar 25, 2016 at 2:18 PM, Mehdi Amini > > wrote:
>> Hi,
>> 
>> I think this broke clang-tidy somehow: 
>> http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10881/steps/build%20stage%201/logs/stdio
>>  
>> 
>> 
>> --
>> Mehdi
>> 
>> 
>> 
>> 
>> > On Mar 25, 2016, at 9:29 AM, Samuel Benzaquen via cfe-commits 
>> > mailto:cfe-commits@lists.llvm.org>> wrote:
>> >
>> > Author: sbenza
>> > Date: Fri Mar 25 11:29:30 2016
>> > New Revision: 264417
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=264417&view=rev 
>> > 
>> > Log:
>> > [ASTMatchers] Add own version of VariadicFunction.
>> >
>> > Summary:
>> > llvm::VariadicFunction is only being used by ASTMatchers.
>> > Having our own copy here allows us to remove the other one from llvm/ADT.
>> > Also, we can extend the API to meet our needs without modifying the common
>> > implementation.
>> >
>> > Reviewers: alexfh
>> >
>> > Subscribers: klimek, cfe-commits
>> >
>> > Differential Revision: http://reviews.llvm.org/D18275 
>> > 
>> >
>> > Modified:
>> >cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>> >cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>> >cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
>> >cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
>> >
>> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>> > URL: 
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=264417&r1=264416&r2=264417&view=diff
>> >  
>> > 
>> > ==
>> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
>> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar 25 11:29:30 
>> > 2016
>> > @@ -1990,8 +1990,8 @@ inline internal::Matcher hasN
>> > /// \code
>> > /// anyOf(hasName(a), hasName(b), hasName(c))
>> > /// \endcode
>> > -const llvm::VariadicFunction, StringRef,
>> > - internal::hasAnyNameFunc>
>> > +const internal::VariadicFunction, StringRef,
>> > + internal::hasAnyNameFunc>
>> > hasAnyName = {};
>> >
>> > /// \brief Matches NamedDecl nodes whose fully qualified names contain
>> >
>> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>> > URL: 
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264417&r1=264416&r2=264417&view=diff
>> >  
>> > 
>> > ==
>> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
>> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25 
>> > 11:29:30 2016
>> > @@ -46,8 +46,9 @@
>> > #include "clang/AST/StmtCXX.h"
>> > #include "clang/AST/StmtObjC.h"
>> > #include "clang/AST/Type.h"
>> > +#include "llvm/ADT/ArrayRef.h"
>> > #include "llvm/ADT/Optional.h"
>> > -#include "llvm/ADT/VariadicFunction.h"
>> > +#include "llvm/ADT/SmallVector.h"
>> > #include "llvm/Support/ManagedStatic.h"
>> > #include 
>> > #include 
>> > @@ -60,6 +61,39 @@ class BoundNodes;
>> >
>> > namespace internal {
>> >
>> > +/// \brief Variadic function object.
>> > +///
>> > +/// Most of the functions below that use VariadicFunction could be 
>> > implemented
>> > +/// using plain C++11 variadic functions, but the function object allows 
>> > us to
>> > +/// capture it on the dynamic matcher registry.
>> > +template > > +  ResultT (*Func)(ArrayRef)>
>> > +struct VariadicFunction {
>> > +  ResultT operator()() const { return Func({}); }
>> > +
>> > +  template 
>> > +  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
>> > +return Execute(Arg1, static_cast(Args)...);
>> > +  }
>> > +
>> > +  // We also allow calls with an already created array, in case the caller
>> > 

[PATCH] D18479: [CodeGenCXX] Fix ItaniumCXXABI::getAlignmentOfExnObject to return 8-byte alignment on Darwin

2016-03-25 Thread Akira Hatanaka via cfe-commits
ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
ahatanak added a subscriber: cfe-commits.

r246985 made changes to give a higher alignment for exception objects on the 
grounds that Itanium says _Unwind_Exception should be "double-word" aligned and 
the structure is normally declared with __attribute__((aligned)) guaranteeing 
16-byte alignment. It turns out that libc++abi doesn't declare the structure 
with __attribute__((aligned)) and therefore only guarantees 8-byte alignment on 
32-bit and 64-bit platforms. This caused a crash in some cases when the backend 
emitted SIMD store instructions that requires 16-byte alignment (such as 
movaps).

This patch makes ItaniumCXXABI::getAlignmentOfExnObject return an 8-byte 
alignment on Darwin to fix the crash.

http://reviews.llvm.org/D18479

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/eh.cpp

Index: test/CodeGenCXX/eh.cpp
===
--- test/CodeGenCXX/eh.cpp
+++ test/CodeGenCXX/eh.cpp
@@ -448,5 +448,27 @@
   }
 }
 
+namespace test17 {
+class BaseException {
+private:
+  int a[4];
+public:
+  BaseException() {};
+};
+
+class DerivedException: public BaseException {
+};
+
+int foo() {
+  throw DerivedException();
+  // The alignment passed to memset is 8, not 16, on Darwin.
+
+  // CHECK: [[T0:%.*]] = call i8* @__cxa_allocate_exception(i64 16)
+  // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to 
%"class.test17::DerivedException"*
+  // CHECK-NEXT: [[T2:%.*]] = bitcast %"class.test17::DerivedException"* 
[[T1]] to i8*
+  // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T2]], i8 0, i64 16, i32 
8, i1 false)
+}
+}
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK: attributes [[NR]] = { noreturn }
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -163,8 +163,17 @@
   /// we assume that alignment here.  (It's generally 16 bytes, but
   /// some targets overwrite it.)
   CharUnits getAlignmentOfExnObject() {
-auto align = CGM.getContext().getTargetDefaultAlignForAttributeAligned();
-return CGM.getContext().toCharUnitsFromBits(align);
+unsigned Align;
+
+// Alignment is 8 for darwin since libc++abi doesn't declare
+// _Unwind_Exception with __attribute__((aligned)) and therefore doesn't
+// guarantee 16-byte alignment.
+if (CGM.getContext().getTargetInfo().getTriple().isOSDarwin())
+  Align = 64;
+else
+  Align = CGM.getContext().getTargetDefaultAlignForAttributeAligned();
+
+return CGM.getContext().toCharUnitsFromBits(Align);
   }
 
   void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) override;


Index: test/CodeGenCXX/eh.cpp
===
--- test/CodeGenCXX/eh.cpp
+++ test/CodeGenCXX/eh.cpp
@@ -448,5 +448,27 @@
   }
 }
 
+namespace test17 {
+class BaseException {
+private:
+  int a[4];
+public:
+  BaseException() {};
+};
+
+class DerivedException: public BaseException {
+};
+
+int foo() {
+  throw DerivedException();
+  // The alignment passed to memset is 8, not 16, on Darwin.
+
+  // CHECK: [[T0:%.*]] = call i8* @__cxa_allocate_exception(i64 16)
+  // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to %"class.test17::DerivedException"*
+  // CHECK-NEXT: [[T2:%.*]] = bitcast %"class.test17::DerivedException"* [[T1]] to i8*
+  // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T2]], i8 0, i64 16, i32 8, i1 false)
+}
+}
+
 // CHECK: attributes [[NUW]] = { nounwind }
 // CHECK: attributes [[NR]] = { noreturn }
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -163,8 +163,17 @@
   /// we assume that alignment here.  (It's generally 16 bytes, but
   /// some targets overwrite it.)
   CharUnits getAlignmentOfExnObject() {
-auto align = CGM.getContext().getTargetDefaultAlignForAttributeAligned();
-return CGM.getContext().toCharUnitsFromBits(align);
+unsigned Align;
+
+// Alignment is 8 for darwin since libc++abi doesn't declare
+// _Unwind_Exception with __attribute__((aligned)) and therefore doesn't
+// guarantee 16-byte alignment.
+if (CGM.getContext().getTargetInfo().getTriple().isOSDarwin())
+  Align = 64;
+else
+  Align = CGM.getContext().getTargetDefaultAlignForAttributeAligned();
+
+return CGM.getContext().toCharUnitsFromBits(Align);
   }
 
   void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) override;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18474: [OPENMP] Enable correct generation of runtime call when target directive is separated from teams directive by multiple curly brackets

2016-03-25 Thread Carlo Bertolli via cfe-commits
carlo.bertolli updated this revision to Diff 51676.
carlo.bertolli added a comment.

Simplify the search function and generalize by using a template.


Repository:
  rL LLVM

http://reviews.llvm.org/D18474

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/teams_codegen.cpp

Index: test/OpenMP/teams_codegen.cpp
===
--- test/OpenMP/teams_codegen.cpp
+++ test/OpenMP/teams_codegen.cpp
@@ -29,6 +29,16 @@
 ++comp;
   }
 
+  // CK1: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 1, i8** 
%{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* 
{{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
+  // CK1: call void @{{.+}}(i{{64|32}} %{{.+}})
+  #pragma omp target
+  {{{
+#pragma omp teams
+{
+  ++comp;
+}
+  }}}
+  
   // CK1-DAG: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 2, i8** 
%{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* 
{{.+}}@{{[^,]+}}, i32 0, i32 0), i32 [[NT:%[^,]+]], i32 0)
   // CK1-DAG: [[NT]] = load i32, i32* [[NTA:%[^,]+]],
 
Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4249,6 +4249,20 @@
   DeviceID, FileID, ParentName, Line, OutlinedFn, OutlinedFnID);
 }
 
+/// \brief look inside a Body stmt for a LF statement discarding any
+/// intervening SK statements
+template
+const static LF *
+hasEnclosingOpenMPDirective(const Stmt *Body) {
+  const SK *S = nullptr;
+  // keep iterating until we find an LF or not an SK or a nullptr
+  while ((S = dyn_cast_or_null(Body)) && (!dyn_cast_or_null(Body)))
+  Body = S->body_front();
+
+  return (Body) ? dyn_cast_or_null(Body) :
+  nullptr;
+}
+
 /// \brief Emit the num_teams clause of an enclosed teams directive at the
 /// target region scope. If there is no teams directive associated with the
 /// target directive, or if there is no num_teams clause associated with the
@@ -4279,7 +4293,9 @@
 
   // FIXME: Accommodate other combined directives with teams when they become
   // available.
-  if (auto *TeamsDir = dyn_cast(CS.getCapturedStmt())) {
+  if (auto *TeamsDir =
+  hasEnclosingOpenMPDirective(
+  CS.getCapturedStmt())) {
 if (auto *NTE = TeamsDir->getSingleClause()) {
   CGOpenMPInnerExprInfo CGInfo(CGF, CS);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo);
@@ -4327,7 +4343,9 @@
 
   // FIXME: Accommodate other combined directives with teams when they become
   // available.
-  if (auto *TeamsDir = dyn_cast(CS.getCapturedStmt())) {
+  if (auto *TeamsDir =
+  hasEnclosingOpenMPDirective(
+  CS.getCapturedStmt())) {
 if (auto *TLE = TeamsDir->getSingleClause()) {
   CGOpenMPInnerExprInfo CGInfo(CGF, CS);
   CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo);


Index: test/OpenMP/teams_codegen.cpp
===
--- test/OpenMP/teams_codegen.cpp
+++ test/OpenMP/teams_codegen.cpp
@@ -29,6 +29,16 @@
 ++comp;
   }
 
+  // CK1: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
+  // CK1: call void @{{.+}}(i{{64|32}} %{{.+}})
+  #pragma omp target
+  {{{
+#pragma omp teams
+{
+  ++comp;
+}
+  }}}
+  
   // CK1-DAG: call i32 @__tgt_target_teams(i32 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 [[NT:%[^,]+]], i32 0)
   // CK1-DAG: [[NT]] = load i32, i32* [[NTA:%[^,]+]],
 
Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4249,6 +4249,20 @@
   DeviceID, FileID, ParentName, Line, OutlinedFn, OutlinedFnID);
 }
 
+/// \brief look inside a Body stmt for a LF statement discarding any
+/// intervening SK statements
+template
+const static LF *
+hasEnclosingOpenMPDirective(const Stmt *Body) {
+  const SK *S = nullptr;
+  // keep iterating until we find an LF or not an SK or a nullptr
+  while ((S = dyn_cast_or_null(Body)) && (!dyn_cast_or_null(Body)))
+  Body = S->body_front();
+
+  return (Body) ? dyn_cast_or_null(Body) :
+  nullptr;
+}
+
 /// \brief Emit the num_teams clause of an enclosed teams directive at the
 /// target region scope. If there is no teams directive associated with the
 /// target directive, or if there is no num_teams clause associated with the
@@ -4279,7 +4293,9 @@
 
   // FIXME: Accommodate other combined directives with teams when they become
   // available.
-  if (auto *TeamsDir = dyn_cast(CS.getCapturedStmt())) {
+  if (auto *TeamsDir =
+  hasEnclosingOpenMPDirective(
+  C

Re: [PATCH] D18458: [CUDA] Mangle __host__ __device__ functions differently than __host__ or __device__ functions.

2016-03-25 Thread Justin Lebar via cfe-commits
jlebar added a comment.

> ! In http://reviews.llvm.org/D18458#383276, @jlebar wrote:

> 

> > ! In http://reviews.llvm.org/D18458#383266, @rsmith wrote:

> 

> 

> This makes the "`constexpr` implies `__host__` `__device__`" patch look 
> slightly questionable: two translation units defining the same `constexpr` 
> function will mangle that function differently depending on whether the 
> translation unit is built with CUDA support enabled. That will cause you to 
> get duplicates of static locals and the like (but I suppose you do anyway 
> between the host and the device, so maybe that's not much more broken than it 
> would be regardless).


The breakage seems to be worse than this.  :(  Eigen seems to do the following:

  foo.h:
#ifdef __CUDACC__  // If compiling CUDA code
#define HOST_DEVICE __host__ __device__
#else
#define HOST_DEVICE
#endif
  
HOST_DEVICE void foo();
  
  foo.cc:  // Compiled as CUDA
HOST_DEVICE void foo() { ... }
  
  bar.cc:  // *Not* compiled as CUDA
#include "foo.h"
void bar() { foo(); }

With this patch, foo() has a different mangled name in foo.o and bar.cc, and
we're hosed.

If we think this use-case is reasonable (I think it is?) I think this means
that we cannot mangle __host__ __device__ functions differently when doing host
compilation.  That seems to restrict us to saying that H and HD functions with
the same signatures cannot overload.  This leaves us with two options:

1. No overloading between HD and H or D functions with the same signature.

  I don't see how to do this while still letting constexpr be HD; the issue is 
that there are constexpr std math functions which we want to overload for 
device.  We could let constexpr be something other than HD, but if that new 
thing can overload with D, then I think we still have the same problem.
2. No overloading between HD and H, but OK to overload HD and D.

  If we did this, we'd still need to give D functions a different mangled name. 
 But we don't have this problem of referencing symbols defined in a file 
compiled in CUDA mode from a file compiled without CUDA.

  tra pointed out a problem with this, which is that if someone (say, nvidia) 
gave us a C++ library consisting of precompiled device code plus headers, we 
wouldn't be able to link with it, because we would use different mangling.

  I also don't like this because it's inconsistent to say HD can overload D but 
not H.  But that's a minor point at this point.

Richard, what do you think?  Maybe you have an alternative idea?


http://reviews.llvm.org/D18458



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


Re: [PATCH] D18458: [CUDA] Mangle __host__ __device__ functions differently than __host__ or __device__ functions.

2016-03-25 Thread Richard Smith via cfe-commits
rsmith added a comment.

It seems like we have the following constraint: on host, no attributes must 
mangle the same as `__host__ __device__` and `constexpr` (and probably 
`__global__`?).

Are there any others? What do we need to do to be ABI-compatible with NVCC? 
(And is that possible if we allow `__host__` to overload `__host__ __device__`?)

One possibility given only that constraint would be to use a different mangling 
for H functions and D functions, but mangle HD and unattributed functions the 
same.


http://reviews.llvm.org/D18458



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


Re: [PATCH] D18479: [CodeGenCXX] Fix ItaniumCXXABI::getAlignmentOfExnObject to return 8-byte alignment on Darwin

2016-03-25 Thread David Majnemer via cfe-commits
On Fri, Mar 25, 2016 at 12:57 PM, Akira Hatanaka via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> ahatanak created this revision.
> ahatanak added a reviewer: rjmccall.
> ahatanak added a subscriber: cfe-commits.
>
> r246985 made changes to give a higher alignment for exception objects on
> the grounds that Itanium says _Unwind_Exception should be "double-word"
> aligned and the structure is normally declared with
> __attribute__((aligned)) guaranteeing 16-byte alignment. It turns out that
> libc++abi doesn't declare the structure with __attribute__((aligned)) and
> therefore only guarantees 8-byte alignment on 32-bit and 64-bit platforms.
> This caused a crash in some cases when the backend emitted SIMD store
> instructions that requires 16-byte alignment (such as movaps).
>
> This patch makes ItaniumCXXABI::getAlignmentOfExnObject return an 8-byte
> alignment on Darwin to fix the crash.
>
> http://reviews.llvm.org/D18479
>
> Files:
>   lib/CodeGen/ItaniumCXXABI.cpp
>   test/CodeGenCXX/eh.cpp
>
> Index: test/CodeGenCXX/eh.cpp
> ===
> --- test/CodeGenCXX/eh.cpp
> +++ test/CodeGenCXX/eh.cpp
> @@ -448,5 +448,27 @@
>}
>  }
>
> +namespace test17 {
> +class BaseException {
> +private:
> +  int a[4];
> +public:
> +  BaseException() {};
> +};
> +
> +class DerivedException: public BaseException {
> +};
> +
> +int foo() {
> +  throw DerivedException();
> +  // The alignment passed to memset is 8, not 16, on Darwin.
> +
> +  // CHECK: [[T0:%.*]] = call i8* @__cxa_allocate_exception(i64 16)
> +  // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to
> %"class.test17::DerivedException"*
> +  // CHECK-NEXT: [[T2:%.*]] = bitcast %"class.test17::DerivedException"*
> [[T1]] to i8*
> +  // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T2]], i8 0, i64
> 16, i32 8, i1 false)
> +}
> +}
> +
>  // CHECK: attributes [[NUW]] = { nounwind }
>  // CHECK: attributes [[NR]] = { noreturn }
> Index: lib/CodeGen/ItaniumCXXABI.cpp
> ===
> --- lib/CodeGen/ItaniumCXXABI.cpp
> +++ lib/CodeGen/ItaniumCXXABI.cpp
> @@ -163,8 +163,17 @@
>/// we assume that alignment here.  (It's generally 16 bytes, but
>/// some targets overwrite it.)
>CharUnits getAlignmentOfExnObject() {
> -auto align =
> CGM.getContext().getTargetDefaultAlignForAttributeAligned();
> -return CGM.getContext().toCharUnitsFromBits(align);
> +unsigned Align;
> +
> +// Alignment is 8 for darwin since libc++abi doesn't declare
> +// _Unwind_Exception with __attribute__((aligned)) and therefore
> doesn't
> +// guarantee 16-byte alignment.
> +if (CGM.getContext().getTargetInfo().getTriple().isOSDarwin())
>

What about Linux/FreeBSD targets which use libc++abi?


> +  Align = 64;
> +else
> +  Align = CGM.getContext().getTargetDefaultAlignForAttributeAligned();
> +
> +return CGM.getContext().toCharUnitsFromBits(Align);
>}
>
>void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) override;
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17811: [clang-tidy] Add check to detect dangling references in value handlers.

2016-03-25 Thread Samuel Benzaquen via cfe-commits
sbenza updated this revision to Diff 51684.
sbenza added a comment.

Using new public hasAnyName API.


http://reviews.llvm.org/D17811

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/DanglingHandleCheck.cpp
  clang-tidy/misc/DanglingHandleCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-dangling-handle.rst
  test/clang-tidy/misc-dangling-handle.cpp

Index: test/clang-tidy/misc-dangling-handle.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-dangling-handle.cpp
@@ -0,0 +1,191 @@
+// RUN: %check_clang_tidy %s misc-dangling-handle %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: misc-dangling-handle.HandleClasses, \
+// RUN:   value: 'std::basic_string_view; ::llvm::StringRef;'}]}" \
+// RUN:   -- -std=c++11
+
+namespace std {
+
+template 
+class vector {
+ public:
+  using const_iterator = const T*;
+  using iterator = T*;
+  using size_type = int;
+
+  void assign(size_type count, const T& value);
+  iterator insert(const_iterator pos, const T& value);
+  iterator insert(const_iterator pos, T&& value);
+  iterator insert(const_iterator pos, size_type count, const T& value);
+  void push_back(const T&);
+  void push_back(T&&);
+  void resize(size_type count, const T& value);
+};
+
+template 
+class pair {};
+
+template 
+class set {
+ public:
+  using const_iterator = const T*;
+  using iterator = T*;
+
+  std::pair insert(const T& value);
+  std::pair insert(T&& value);
+  iterator insert(const_iterator hint, const T& value);
+  iterator insert(const_iterator hint, T&& value);
+};
+
+template 
+class map {
+ public:
+  using value_type = pair;
+  value_type& operator[](const Key& key);
+  value_type& operator[](Key&& key);
+};
+
+class basic_string {
+ public:
+  basic_string();
+  basic_string(const char*);
+  ~basic_string();
+};
+
+typedef basic_string string;
+
+class basic_string_view {
+ public:
+  basic_string_view(const char*);
+  basic_string_view(const basic_string&);
+};
+
+typedef basic_string_view string_view;
+
+}  // namespace std
+
+namespace llvm {
+
+class StringRef {
+ public:
+  StringRef();
+  StringRef(const char*);
+  StringRef(const std::string&);
+};
+
+}  // namespace llvm
+
+std::string ReturnsAString();
+
+void Positives() {
+  std::string_view view1 = std::string();
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives its value [misc-dangling-handle]
+
+  std::string_view view_2 = ReturnsAString();
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives
+
+  view1 = std::string();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: std::basic_string_view outlives
+
+  const std::string& str_ref = "";
+  std::string_view view3 = true ? "A" : str_ref;
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives
+  view3 = true ? "A" : str_ref;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: std::basic_string_view outlives
+
+  std::string_view view4(ReturnsAString());
+  // CHECK-MESSAGES: [[@LINE-1]]:20: warning: std::basic_string_view outlives
+}
+
+void OtherTypes() {
+  llvm::StringRef ref = std::string();
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: llvm::StringRef outlives its value
+}
+
+const char static_array[] = "A";
+std::string_view ReturnStatements(int i, std::string value_arg,
+  const std::string &ref_arg) {
+  const char array[] = "A";
+  const char* ptr = "A";
+  std::string s;
+  static std::string ss;
+  switch (i) {
+// Bad cases
+case 0:
+  return array;  // refers to local
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: std::basic_string_view outliv
+case 1:
+  return s;  // refers to local
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: std::basic_string_view outliv
+case 2:
+  return std::string();  // refers to temporary
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: std::basic_string_view outliv
+case 3:
+  return value_arg;  // refers to by-value arg
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: std::basic_string_view outliv
+
+// Ok cases
+case 100:
+  return ss;  // refers to static
+case 101:
+  return static_array;  // refers to static
+case 102:
+  return ptr;  // pointer is ok
+case 103:
+  return ref_arg;  // refers to by-ref arg
+  }
+
+  struct S {
+std::string_view view() { return value; }
+std::string value;
+  };
+
+  (void)[&]()->std::string_view {
+// This should not warn. The string is bound by reference.
+return s;
+  };
+  (void)[=]() -> std::string_view {
+// This should not warn. The reference is valid as long as the lambda.
+return s;
+  };
+  (void)[=]() -> std::string_view {
+// FIXME: This one should warn. We are returning a reference to a local
+// lambda variable.
+std::string local;
+return local;
+  };
+  return "";
+}
+
+void Containers() {
+  std::

Re: [PATCH] D18479: [CodeGenCXX] Fix ItaniumCXXABI::getAlignmentOfExnObject to return 8-byte alignment on Darwin

2016-03-25 Thread Akira Hatanaka via cfe-commits

> On Mar 25, 2016, at 2:06 PM, David Majnemer via cfe-commits 
>  wrote:
> 
> 
> 
> On Fri, Mar 25, 2016 at 12:57 PM, Akira Hatanaka via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> ahatanak created this revision.
> ahatanak added a reviewer: rjmccall.
> ahatanak added a subscriber: cfe-commits.
> 
> r246985 made changes to give a higher alignment for exception objects on the 
> grounds that Itanium says _Unwind_Exception should be "double-word" aligned 
> and the structure is normally declared with __attribute__((aligned)) 
> guaranteeing 16-byte alignment. It turns out that libc++abi doesn't declare 
> the structure with __attribute__((aligned)) and therefore only guarantees 
> 8-byte alignment on 32-bit and 64-bit platforms. This caused a crash in some 
> cases when the backend emitted SIMD store instructions that requires 16-byte 
> alignment (such as movaps).
> 
> This patch makes ItaniumCXXABI::getAlignmentOfExnObject return an 8-byte 
> alignment on Darwin to fix the crash.
> 
> http://reviews.llvm.org/D18479 
> 
> Files:
>   lib/CodeGen/ItaniumCXXABI.cpp
>   test/CodeGenCXX/eh.cpp
> 
> Index: test/CodeGenCXX/eh.cpp
> ===
> --- test/CodeGenCXX/eh.cpp
> +++ test/CodeGenCXX/eh.cpp
> @@ -448,5 +448,27 @@
>}
>  }
> 
> +namespace test17 {
> +class BaseException {
> +private:
> +  int a[4];
> +public:
> +  BaseException() {};
> +};
> +
> +class DerivedException: public BaseException {
> +};
> +
> +int foo() {
> +  throw DerivedException();
> +  // The alignment passed to memset is 8, not 16, on Darwin.
> +
> +  // CHECK: [[T0:%.*]] = call i8* @__cxa_allocate_exception(i64 16)
> +  // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to 
> %"class.test17::DerivedException"*
> +  // CHECK-NEXT: [[T2:%.*]] = bitcast %"class.test17::DerivedException"* 
> [[T1]] to i8*
> +  // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T2]], i8 0, i64 16, 
> i32 8, i1 false)
> +}
> +}
> +
>  // CHECK: attributes [[NUW]] = { nounwind }
>  // CHECK: attributes [[NR]] = { noreturn }
> Index: lib/CodeGen/ItaniumCXXABI.cpp
> ===
> --- lib/CodeGen/ItaniumCXXABI.cpp
> +++ lib/CodeGen/ItaniumCXXABI.cpp
> @@ -163,8 +163,17 @@
>/// we assume that alignment here.  (It's generally 16 bytes, but
>/// some targets overwrite it.)
>CharUnits getAlignmentOfExnObject() {
> -auto align = CGM.getContext().getTargetDefaultAlignForAttributeAligned();
> -return CGM.getContext().toCharUnitsFromBits(align);
> +unsigned Align;
> +
> +// Alignment is 8 for darwin since libc++abi doesn't declare
> +// _Unwind_Exception with __attribute__((aligned)) and therefore doesn't
> +// guarantee 16-byte alignment.
> +if (CGM.getContext().getTargetInfo().getTriple().isOSDarwin())
> 
> What about Linux/FreeBSD targets which use libc++abi?
>  

Is there a way to detect whether libc++abi is used?

> +  Align = 64;
> +else
> +  Align = CGM.getContext().getTargetDefaultAlignForAttributeAligned();
> +
> +return CGM.getContext().toCharUnitsFromBits(Align);
>}
> 
>void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) override;
> 
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org 
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> 
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org 
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r264463 - [analyzer] Add CIFIlter modeling to DeallocChecker.

2016-03-25 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Fri Mar 25 16:18:22 2016
New Revision: 264463

URL: http://llvm.org/viewvc/llvm-project?rev=264463&view=rev
Log:
[analyzer] Add CIFIlter modeling to DeallocChecker.

The -dealloc method in CIFilter is highly unusual in that it will release
instance variables belonging to its *subclasses* if the variable name
starts with "input" or backs a property whose name starts with "input".
Subclasses should not release these ivars in their own -dealloc method --
doing so could result in an over release.

Before this commit, the DeallocChecker would warn about missing releases for
such "input" properties -- which could cause users of the analyzer to add
over releases to silence the warning.

To avoid this, DeallocChecker now treats CIFilter "input-prefixed" ivars
as MustNotReleaseDirectly and so will not require a release. Further, it
will now warn when such an ivar is directly released in -dealloc.

rdar://problem/25364901

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
cfe/trunk/test/Analysis/DeallocMissingRelease.m
cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-objc-dealloc.h

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp?rev=264463&r1=264462&r2=264463&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp Fri Mar 25 
16:18:22 2016
@@ -98,7 +98,8 @@ class ObjCDeallocChecker
  check::PointerEscape,
  check::PreStmt> {
 
-  mutable IdentifierInfo *NSObjectII, *SenTestCaseII, *Block_releaseII;
+  mutable IdentifierInfo *NSObjectII, *SenTestCaseII, *Block_releaseII,
+ *CIFilterII;
   mutable Selector DeallocSel, ReleaseSel;
 
   std::unique_ptr MissingReleaseBugType;
@@ -169,6 +170,8 @@ private:
   void initIdentifierInfoAndSelectors(ASTContext &Ctx) const;
 
   bool classHasSeparateTeardown(const ObjCInterfaceDecl *ID) const;
+
+  bool isReleasedByCIFilterDealloc(const ObjCPropertyImplDecl *PropImpl) const;
 };
 } // End anonymous namespace.
 
@@ -688,19 +691,27 @@ bool ObjCDeallocChecker::diagnoseExtraRe
 
   assert(PropDecl->getSetterKind() == ObjCPropertyDecl::Weak ||
  (PropDecl->getSetterKind() == ObjCPropertyDecl::Assign &&
-  !PropDecl->isReadOnly()));
+  !PropDecl->isReadOnly()) ||
+ isReleasedByCIFilterDealloc(PropImpl)
+ );
 
   const ObjCImplDecl *Container = 
getContainingObjCImpl(C.getLocationContext());
   OS << "The '" << *PropImpl->getPropertyIvarDecl()
- << "' ivar in '" << *Container
- << "' was synthesized for ";
+ << "' ivar in '" << *Container;
 
-  if (PropDecl->getSetterKind() == ObjCPropertyDecl::Weak)
-OS << "a weak";
-  else
-OS << "an assign, readwrite";
 
-  OS <<  " property but was released in 'dealloc'";
+  if (isReleasedByCIFilterDealloc(PropImpl)) {
+OS << "' will be released by '-[CIFilter dealloc]' but also released here";
+  } else {
+OS << "' was synthesized for ";
+
+if (PropDecl->getSetterKind() == ObjCPropertyDecl::Weak)
+  OS << "a weak";
+else
+  OS << "an assign, readwrite";
+
+OS <<  " property but was released in 'dealloc'";
+  }
 
   std::unique_ptr BR(
   new BugReport(*ExtraReleaseBugType, OS.str(), ErrNode));
@@ -751,7 +762,7 @@ bool ObjCDeallocChecker::diagnoseMistake
 
 ObjCDeallocChecker::
 ObjCDeallocChecker()
-: NSObjectII(nullptr), SenTestCaseII(nullptr) {
+: NSObjectII(nullptr), SenTestCaseII(nullptr), CIFilterII(nullptr) {
 
   MissingReleaseBugType.reset(
   new BugType(this, "Missing ivar release (leak)",
@@ -774,6 +785,7 @@ void ObjCDeallocChecker::initIdentifierI
   NSObjectII = &Ctx.Idents.get("NSObject");
   SenTestCaseII = &Ctx.Idents.get("SenTestCase");
   Block_releaseII = &Ctx.Idents.get("_Block_release");
+  CIFilterII = &Ctx.Idents.get("CIFilter");
 
   IdentifierInfo *DeallocII = &Ctx.Idents.get("dealloc");
   IdentifierInfo *ReleaseII = &Ctx.Idents.get("release");
@@ -894,6 +906,9 @@ ReleaseRequirement ObjCDeallocChecker::g
   // the value in their instance variables must be released in -dealloc.
   case ObjCPropertyDecl::Retain:
   case ObjCPropertyDecl::Copy:
+if (isReleasedByCIFilterDealloc(PropImpl))
+  return ReleaseRequirement::MustNotReleaseDirectly;
+
 return ReleaseRequirement::MustRelease;
 
   case ObjCPropertyDecl::Weak:
@@ -1019,6 +1034,37 @@ bool ObjCDeallocChecker::classHasSeparat
   return true;
 }
 
+/// The -dealloc method in CIFilter highly unusual in that is will release
+/// instance variables belonging to its *subclasses* if the variable name
+/// starts with "input" or backs a property whose name starts with "input".
+/// Subclasses should not release these ivars in their own -dealloc me

Re: [PATCH] D18458: [CUDA] Mangle __host__ __device__ functions differently than __host__ or __device__ functions.

2016-03-25 Thread Justin Lebar via cfe-commits
jlebar added a comment.

In http://reviews.llvm.org/D18458#383719, @rsmith wrote:

> It seems like we have the following constraint: on host, no attributes must 
> mangle the same as `__host__ __device__` and `constexpr` (and probably 
> `__global__`?).


Yes to `__host__ __device__` and `constexpr`.  Unsure about `__global__`, but 
let's also say yes for now, to be conservative.

> Are there any others?


An existing assumption is that `__host__` is identical to unattributed.  
Probably makes sense to keep that one around for now if we can (modulo changes 
to unattributed constexpr), as it makes things simpler.

> What do we need to do to be ABI-compatible with NVCC? (And is that possible 
> if we allow `__host__` to overload `__host__ __device__`?)


NVCC doesn't apply any special mangling to D or HD functions, so I think 
maintaining naming compatibility means, basically, not screwing with mangled 
names based on attributes.

> One possibility given only that constraint would be to use a different 
> mangling for H functions and D functions, but mangle HD and unattributed 
> functions the same.


I guess using a different mangling for both H and D functions, rather than just 
for D functions, is in some sense more consistent.  But this  would also be 
very subtle: We'd be saying, non-constexpr H and unattributed are identical, 
*except* for their mangled names.


http://reviews.llvm.org/D18458



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


r264464 - Delete dead variable.

2016-03-25 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Mar 25 16:46:44 2016
New Revision: 264464

URL: http://llvm.org/viewvc/llvm-project?rev=264464&view=rev
Log:
Delete dead variable.

Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=264464&r1=264463&r2=264464&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Mar 25 16:46:44 2016
@@ -1138,11 +1138,9 @@ bool ASTUnit::Parse(std::shared_ptrBeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
 goto error;
 
-  if (SavedMainFileBuffer) {
-std::string ModName = getPreambleFile(this);
+  if (SavedMainFileBuffer)
 TranslateStoredDiagnostics(getFileManager(), getSourceManager(),
PreambleDiagnostics, StoredDiagnostics);
-  }
 
   if (!Act->Execute())
 goto error;


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


r264466 - Store list of undefined-but-used objects in a deterministic order to fix

2016-03-25 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Mar 25 16:49:43 2016
New Revision: 264466

URL: http://llvm.org/viewvc/llvm-project?rev=264466&view=rev
Log:
Store list of undefined-but-used objects in a deterministic order to fix
non-deterministic diagnostics (and non-deterministic PCH files). Check these
when building a module rather than serializing it; it's not reasonable for a
module's use to be satisfied by a definition in the user of the module.

Modified:
cfe/trunk/include/clang/Sema/ExternalSemaSource.h
cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/SemaCXX/diagnostic-order.cpp

Modified: cfe/trunk/include/clang/Sema/ExternalSemaSource.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ExternalSemaSource.h?rev=264466&r1=264465&r2=264466&view=diff
==
--- cfe/trunk/include/clang/Sema/ExternalSemaSource.h (original)
+++ cfe/trunk/include/clang/Sema/ExternalSemaSource.h Fri Mar 25 16:49:43 2016
@@ -77,8 +77,8 @@ public:
 
   /// \brief Load the set of used but not defined functions or variables with
   /// internal linkage, or used but not defined internal functions.
-  virtual void ReadUndefinedButUsed(
- llvm::DenseMap 
&Undefined);
+  virtual void
+  ReadUndefinedButUsed(llvm::MapVector 
&Undefined);
 
   virtual void ReadMismatchingDeleteExpressions(llvm::MapVector<
   FieldDecl *, llvm::SmallVector, 4>> &);

Modified: cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h?rev=264466&r1=264465&r2=264466&view=diff
==
--- cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h (original)
+++ cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h Fri Mar 25 
16:49:43 2016
@@ -211,7 +211,7 @@ public:
   /// \brief Load the set of used but not defined functions or variables with
   /// internal linkage, or used but not defined inline functions.
   void ReadUndefinedButUsed(
-llvm::DenseMap &Undefined) 
override;
+  llvm::MapVector &Undefined) override;
 
   void ReadMismatchingDeleteExpressions(llvm::MapVector<
   FieldDecl *, llvm::SmallVector, 4>> &

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=264466&r1=264465&r2=264466&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Mar 25 16:49:43 2016
@@ -941,7 +941,7 @@ public:
 
   /// UndefinedInternals - all the used, undefined objects which require a
   /// definition in this translation unit.
-  llvm::DenseMap UndefinedButUsed;
+  llvm::MapVector UndefinedButUsed;
 
   /// Obtain a sorted list of functions that are undefined but ODR-used.
   void getUndefinedButUsed(

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=264466&r1=264465&r2=264466&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri Mar 25 16:49:43 2016
@@ -1807,7 +1807,7 @@ public:
  SmallVectorImpl &Namespaces) 
override;
 
   void ReadUndefinedButUsed(
-   llvm::DenseMap &Undefined) 
override;
+  llvm::MapVector &Undefined) override;
 
   void ReadMismatchingDeleteExpressions(llvm::MapVector<
   FieldDecl *, llvm::SmallVector, 4>> &

Modified: cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp?rev=264466&r1=264465&r2=264466&view=diff
==
--- cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp (original)
+++ cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp Fri Mar 25 16:49:43 2016
@@ -204,7 +204,7 @@ void MultiplexExternalSemaSource::ReadKn
 }
 
 void MultiplexExternalSemaSource::ReadUndefinedButUsed(
- llvm::DenseMap 
&Undefined){
+llvm::MapVector &Undefined) {
   for(size_t i = 0; i < Sources.size(); ++i)
 Sources[i]->ReadUndefinedButUsed(Undefined);
 }

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=264466&r1=264465&r2=264466&view=diff
==
--- cfe/trunk/lib/Sema/Sema.c

r264471 - Don't warn on "use" of undefined inline function that isn't actually an ODR

2016-03-25 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Mar 25 17:29:27 2016
New Revision: 264471

URL: http://llvm.org/viewvc/llvm-project?rev=264471&view=rev
Log:
Don't warn on "use" of undefined inline function that isn't actually an ODR
use. In order for this to fire, the function needed to be a templated function
marked 'constexpr' and declared but not defined. This weird pattern appears in
libstdc++'s alloc_traits.h.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/undefined-inline.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=264471&r1=264470&r2=264471&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Mar 25 17:29:27 2016
@@ -3593,9 +3593,15 @@ public:
   // for expressions referring to a decl; these exist because odr-use marking
   // needs to be delayed for some constant variables when we build one of the
   // named expressions.
-  void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool OdrUse);
+  //
+  // MightBeOdrUse indicates whether the use could possibly be an odr-use, and
+  // should usually be true. This only needs to be set to false if the lack of
+  // odr-use cannot be determined from the current context (for instance,
+  // because the name denotes a virtual function and was written without an
+  // explicit nested-name-specifier).
+  void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse);
   void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
-  bool OdrUse = true);
+  bool MightBeOdrUse = true);
   void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var);
   void MarkDeclRefReferenced(DeclRefExpr *E);
   void MarkMemberReferenced(MemberExpr *E);

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=264471&r1=264470&r2=264471&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar 25 17:29:27 2016
@@ -12770,7 +12770,7 @@ static bool IsPotentiallyEvaluatedContex
 /// \brief Mark a function referenced, and check whether it is odr-used
 /// (C++ [basic.def.odr]p2, C99 6.9p3)
 void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
-  bool OdrUse) {
+  bool MightBeOdrUse) {
   assert(Func && "No function?");
 
   Func->setReferenced();
@@ -12783,8 +12783,8 @@ void Sema::MarkFunctionReferenced(Source
   // We (incorrectly) mark overload resolution as an unevaluated context, so we
   // can just check that here. Skip the rest of this function if we've already
   // marked the function as used.
-  if (Func->isUsed(/*CheckUsedAttr=*/false) ||
-  !IsPotentiallyEvaluatedContext(*this)) {
+  bool OdrUse = MightBeOdrUse && IsPotentiallyEvaluatedContext(*this);
+  if (Func->isUsed(/*CheckUsedAttr=*/false) || !OdrUse) {
 // C++11 [temp.inst]p3:
 //   Unless a function template specialization has been explicitly
 //   instantiated or explicitly specialized, the function template
@@ -12873,8 +12873,6 @@ void Sema::MarkFunctionReferenced(Source
   if (FPT && isUnresolvedExceptionSpec(FPT->getExceptionSpecType()))
 ResolveExceptionSpec(Loc, FPT);
 
-  if (!OdrUse) return;
-
   // Implicit instantiation of function templates and member functions of
   // class templates.
   if (Func->isImplicitlyInstantiable()) {
@@ -12922,10 +12920,12 @@ void Sema::MarkFunctionReferenced(Source
 // Walk redefinitions, as some of them may be instantiable.
 for (auto i : Func->redecls()) {
   if (!i->isUsed(false) && i->isImplicitlyInstantiable())
-MarkFunctionReferenced(Loc, i);
+MarkFunctionReferenced(Loc, i, OdrUse);
 }
   }
 
+  if (!OdrUse) return;
+
   // Keep track of used but undefined functions.
   if (!Func->isDefined()) {
 if (mightHaveNonExternalLinkage(Func))
@@ -13800,13 +13800,13 @@ void Sema::MarkVariableReferenced(Source
 }
 
 static void MarkExprReferenced(Sema &SemaRef, SourceLocation Loc,
-   Decl *D, Expr *E, bool OdrUse) {
+   Decl *D, Expr *E, bool MightBeOdrUse) {
   if (VarDecl *Var = dyn_cast(D)) {
 DoMarkVarDeclReferenced(SemaRef, Loc, Var, E);
 return;
   }
 
-  SemaRef.MarkAnyDeclReferenced(Loc, D, OdrUse);
+  SemaRef.MarkAnyDeclReferenced(Loc, D, MightBeOdrUse);
 
   // If this is a call to a method via a cast, also mark the method in the
   // derived class used in case codegen can devirtualize the call.
@@ -13828,7 +13828,7 @@ static void MarkExprReferenced(Sema &Sem
   CXXMethodDecl *DM = MD->getCorrespondingMethodInClass(MostDerivedClassDecl);
   i

Re: [PATCH] D18458: [CUDA] Mangle __host__ __device__ functions differently than __host__ or __device__ functions.

2016-03-25 Thread Richard Smith via cfe-commits
rsmith added a comment.

In http://reviews.llvm.org/D18458#383755, @jlebar wrote:

> In http://reviews.llvm.org/D18458#383719, @rsmith wrote:
>
> > It seems like we have the following constraint: on host, no attributes must 
> > mangle the same as `__host__ __device__` and `constexpr` (and probably 
> > `__global__`?).
>
>
> Yes to `__host__ __device__` and `constexpr`.  Unsure about `__global__`, but 
> let's also say yes for now, to be conservative.
>
> > Are there any others?
>
>
> An existing assumption is that `__host__` is identical to unattributed.  
> Probably makes sense to keep that one around for now if we can (modulo 
> changes to unattributed constexpr), as it makes things simpler.


OK, that makes things pretty easy (though we don't get the answer we might 
want): unattributed must be mangled the same as H and HD, so we cannot support 
overloading H and HD.

> > What do we need to do to be ABI-compatible with NVCC? (And is that possible 
> > if we allow `__host__` to overload `__host__ __device__`?)

> 

> 

> NVCC doesn't apply any special mangling to D or HD functions, so I think 
> maintaining naming compatibility means, basically, not screwing with mangled 
> names based on attributes.

> 

> That suggests, to your second question, that it's not possible to maintain 
> ABI compatibility if we allow D or H to overload HD.


OK, so the question for you is, how much ABI compatibility with NVCC are you 
prepared to give up in order to allow HD / D overloading and HD / H overloading?

> > One possibility given only that constraint would be to use a different 
> > mangling for H functions and D functions, but mangle HD and unattributed 
> > functions the same.

> 

> 

> I guess using a different mangling for both H and D functions, rather than 
> just for D functions, is in some sense more consistent.  But this  would also 
> be very subtle: We'd be saying, non-constexpr H and unattributed are 
> identical, *except* for their mangled names.


Yes, that seems like a good argument for mangling H the same as unattributed.


http://reviews.llvm.org/D18458



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


Re: r264428 - [ASTMatchers] Fix build for VariadicFunction.

2016-03-25 Thread Richard Smith via cfe-commits
On Fri, Mar 25, 2016 at 10:55 AM, David Blaikie via cfe-commits
 wrote:
>
>
> On Fri, Mar 25, 2016 at 10:46 AM, Samuel Benzaquen via cfe-commits
>  wrote:
>>
>> Author: sbenza
>> Date: Fri Mar 25 12:46:02 2016
>> New Revision: 264428
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=264428&view=rev
>> Log:
>> [ASTMatchers] Fix build for VariadicFunction.
>>
>> Under some conditions the implicit conversion from array to ArrayRef<>
>> is not working.
>
> Any idea what those conditions are?

Well, the code's ill-formed (relying on a compiler extension) when
Args is empty. Maybe GCC diagnoses that in some cases?

>> Fix the build by making it explicit.
>>
>> Modified:
>> cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>>
>> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264428&r1=264427&r2=264428&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
>> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25
>> 12:46:02 2016
>> @@ -90,7 +90,7 @@ private:
>>// before we make the array.
>>template  ResultT Execute(const ArgsT &... Args)
>> const {
>>  const ArgT *const ArgsArray[] = {&Args...};
>> -return Func(ArgsArray);
>> +return Func(ArrayRef(ArgsArray, sizeof...(ArgsT)));
>>}
>>  };
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18271: Avoid -Wshadow warnings about constructor parameters named after fields

2016-03-25 Thread Reid Kleckner via cfe-commits
rnk updated this revision to Diff 51697.
rnk added a comment.

- Address review comments, use a DenseMap instead of redoing lookup


http://reviews.llvm.org/D18271

Files:
  include/clang/Basic/Diagnostic.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/warn-shadow.cpp

Index: test/SemaCXX/warn-shadow.cpp
===
--- test/SemaCXX/warn-shadow.cpp
+++ test/SemaCXX/warn-shadow.cpp
@@ -29,7 +29,18 @@
 
 class A {
   static int data; // expected-note {{previous declaration}}
-  int field; // expected-note {{previous declaration}}
+  // expected-note@+1 {{previous declaration}}
+  int field;
+  int f1, f2, f3, f4; // expected-note 4 {{previous declaration is here}}
+
+  // The initialization is safe, but the modifications are not.
+  A(int f1, int f2, int f3, int f4) : f1(f1) {
+f1 = 3; // expected-warning {{modifying variable 'f1' that shadows a field of 'A'}}
+f1 = 4; // one warning per shadow
+f2++; // expected-warning {{modifying variable 'f2' that shadows a field of 'A'}}
+--f3; // expected-warning {{modifying variable 'f3' that shadows a field of 'A'}}
+f4 += 2; // expected-warning {{modifying variable 'f4' that shadows a field of 'A'}}
+  }
 
   void test() {
 char *field; // expected-warning {{declaration shadows a field of 'A'}}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -9658,6 +9658,9 @@
 /// emit an error and return true.  If so, return false.
 static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) {
   assert(!E->hasPlaceholderType(BuiltinType::PseudoObject));
+
+  S.CheckShadowingDeclModification(E, Loc);
+
   SourceLocation OrigLoc = Loc;
   Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context,
   &Loc);
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -1612,6 +1612,7 @@
 
 // Remove this name from our lexical scope.
 IdResolver.RemoveDecl(D);
+ShadowingDecls.erase(D);
   }
 }
 
@@ -6361,6 +6362,23 @@
   return NewVD;
 }
 
+enum ShadowedDeclKind { SDK_Local, SDK_Global, SDK_StaticMember, SDK_Field };
+
+/// Determine what kind of declaration we're shadowing.  The order must be
+/// consistent with the %select in the warning message.
+static ShadowedDeclKind computeShadowedDeclKind(const NamedDecl *ShadowedDecl,
+const DeclContext *OldDC) {
+  if (isa(OldDC)) {
+if (isa(ShadowedDecl))
+  return SDK_Field;
+else
+  return SDK_StaticMember;
+  } else if (OldDC->isFileContext()) {
+return SDK_Global;
+  }
+  return SDK_Local;
+}
+
 /// \brief Diagnose variable or built-in function shadowing.  Implements
 /// -Wshadow.
 ///
@@ -6389,11 +6407,18 @@
   if (!isa(ShadowedDecl) && !isa(ShadowedDecl))
 return;
 
-  // Fields are not shadowed by variables in C++ static methods.
-  if (isa(ShadowedDecl))
+  if (isa(ShadowedDecl)) {
+// Fields are not shadowed by variables in C++ static methods.
 if (CXXMethodDecl *MD = dyn_cast(NewDC))
   if (MD->isStatic())
 return;
+// Fields are not shadowed by constructor parameters. This allows a popular
+// pattern where constructor parameters are named after fields.
+if (isa(NewDC) && isa(D)) {
+  ShadowingDecls.insert({D, ShadowedDecl});
+  return;
+}
+  }
 
   if (VarDecl *shadowedVar = dyn_cast(ShadowedDecl))
 if (shadowedVar->isExternC()) {
@@ -6422,27 +6447,13 @@
 // shadowing context, but that's just a false negative.
   }
 
-  // Determine what kind of declaration we're shadowing.
-
-  // The order must be consistent with the %select in the warning message.
-  enum ShadowedDeclKind { Local, Global, StaticMember, Field };
-  ShadowedDeclKind Kind;
-  if (isa(OldDC)) {
-if (isa(ShadowedDecl))
-  Kind = Field;
-else
-  Kind = StaticMember;
-  } else if (OldDC->isFileContext()) {
-Kind = Global;
-  } else {
-Kind = Local;
-  }
 
   DeclarationName Name = R.getLookupName();
 
   // Emit warning and note.
   if (getSourceManager().isInSystemMacro(R.getNameLoc()))
 return;
+  ShadowedDeclKind Kind = computeShadowedDeclKind(ShadowedDecl, OldDC);
   Diag(R.getNameLoc(), diag::warn_decl_shadow) << Name << Kind << OldDC;
   Diag(ShadowedDecl->getLocation(), diag::note_previous_declaration);
 }
@@ -6458,6 +6469,30 @@
   CheckShadow(S, D, R);
 }
 
+/// Check if 'E', which is an expression that is about to be modified, refers
+/// to a constructor parameter that shadows a field.
+void Sema::CheckShadowingDeclModification(Expr *E, SourceLocation Loc) {
+  // Quickly ignore expressions that can't be shadowing ctor parameters.
+  if (!getLang

Re: r264428 - [ASTMatchers] Fix build for VariadicFunction.

2016-03-25 Thread David Blaikie via cfe-commits
On Fri, Mar 25, 2016 at 4:01 PM, Richard Smith 
wrote:

> On Fri, Mar 25, 2016 at 10:55 AM, David Blaikie via cfe-commits
>  wrote:
> >
> >
> > On Fri, Mar 25, 2016 at 10:46 AM, Samuel Benzaquen via cfe-commits
> >  wrote:
> >>
> >> Author: sbenza
> >> Date: Fri Mar 25 12:46:02 2016
> >> New Revision: 264428
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=264428&view=rev
> >> Log:
> >> [ASTMatchers] Fix build for VariadicFunction.
> >>
> >> Under some conditions the implicit conversion from array to ArrayRef<>
> >> is not working.
> >
> > Any idea what those conditions are?
>
> Well, the code's ill-formed (relying on a compiler extension) when
> Args is empty.


Because there are no zero length arrays, I take it?

Any nice way around that, do you think? (just have a null element at the
start that we prune off in the call site?)


> Maybe GCC diagnoses that in some cases?
>
> >> Fix the build by making it explicit.
> >>
> >> Modified:
> >> cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> >>
> >> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264428&r1=264427&r2=264428&view=diff
> >>
> >>
> ==
> >> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
> >> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar 25
> >> 12:46:02 2016
> >> @@ -90,7 +90,7 @@ private:
> >>// before we make the array.
> >>template  ResultT Execute(const ArgsT &... Args)
> >> const {
> >>  const ArgT *const ArgsArray[] = {&Args...};
> >> -return Func(ArgsArray);
> >> +return Func(ArrayRef(ArgsArray, sizeof...(ArgsT)));
> >>}
> >>  };
> >>
> >>
> >>
> >> ___
> >> cfe-commits mailing list
> >> cfe-commits@lists.llvm.org
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> >
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> >
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14905: [constexpr-lambda] Support parsing of constexpr specifier (and its inference) on lambda expressions

2016-03-25 Thread Richard Smith via cfe-commits
rsmith accepted this revision.
This revision is now accepted and ready to land.


Comment at: include/clang/Basic/DiagnosticParseKinds.td:769
@@ +768,3 @@
+  "attribute specifier|'constexpr'}0">;
+def err_lambda_declspecifier_repeated : Error<
+  "%select{'mutable'|'constexpr'}0 cannot appear multiple times in a lambda 
declarator">;

declspecifier -> decl_specifier


Comment at: lib/AST/ExprConstant.cpp:2049-2063
@@ -2047,3 +2048,17 @@
 Result = Frame->getTemporary(VD);
+if (!Result && isLambdaCallOperator(Frame->Callee) &&
+(VD->getDeclContext() != Frame->Callee || VD->isInitCapture())) {
+  // Assume variables referenced within a lambda's call operator that were
+  // not declared within the call operator are captures and during checking
+  // of a potential constant expression, assume they are unknown constant
+  // expressions. 
+  if (Info.checkingPotentialConstantExpression())
+return false;
+  // FIXME: implement capture evaluation during constant expr evaluation.
+  Info.Diag(E->getLocStart(),
+   diag::note_unimplemented_constexpr_lambda_feature_ast)
+  << "captures not currently allowed";
+  return false;
+}
 assert(Result && "missing value for local variable");
 return true;

I'd prefer to phrase this if/assert arrangement as:

  if (!Result) {
assert(isLambdaCallOperator(...) && (VD->getDeclContext != ...


Comment at: lib/Parse/ParseExprCXX.cpp:1077
@@ +1076,3 @@
+default:
+  return ;
+}

No space before `;`.


http://reviews.llvm.org/D14905



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


Re: [PATCH] D15944: [OpenMP] Parsing and sema support for target update directive

2016-03-25 Thread Kelvin Li via cfe-commits
kkwli0 added a comment.

Patch for the to and from clauses is in http://reviews.llvm.org/D18488.


http://reviews.llvm.org/D15944



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