[PATCH] D29151: [clang-tidy] Add misc-invalidated-iterators check.

2017-01-26 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In https://reviews.llvm.org/D29151#657435, @Prazek wrote:

> In https://reviews.llvm.org/D29151#656887, @Eugene.Zelenko wrote:
>
> > General question: isn't Static Analyzer is better place for such workflow 
> > checks?
>
>
> Probably yes, but it is much harder to implement this there. Other problem is 
> that it would be probably a part 
>  of one of the alpha checks, that are not developed and I don't know if they 
> will ever be fully supported.


But it'll be necessary to re-implement part of Static Analyzer functionality in 
Clang-tidy. Will it be generic enough to be used for similar purposes?

It'll be good idea to find out Static Analyzer release criteria.


Repository:
  rL LLVM

https://reviews.llvm.org/D29151



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


[PATCH] D28768: [clang-tidy] Add check 'modernize-return-braced-init-list'

2017-01-26 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere updated this revision to Diff 85937.
JDevlieghere added a comment.

- Added missing instantiations in test


Repository:
  rL LLVM

https://reviews.llvm.org/D28768

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/ReturnBracedInitListCheck.cpp
  clang-tidy/modernize/ReturnBracedInitListCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-return-braced-init-list.rst
  test/clang-tidy/modernize-return-braced-init-list.cpp

Index: test/clang-tidy/modernize-return-braced-init-list.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-return-braced-init-list.cpp
@@ -0,0 +1,188 @@
+// RUN: %check_clang_tidy %s modernize-return-braced-init-list %t -- --
+// -std=c++14
+
+namespace std {
+typedef decltype(sizeof(int)) size_t;
+
+// libc++'s implementation
+template 
+class initializer_list {
+  const _E *__begin_;
+  size_t __size_;
+
+  initializer_list(const _E *__b, size_t __s)
+  : __begin_(__b),
+__size_(__s) {}
+
+public:
+  typedef _E value_type;
+  typedef const _E 
+  typedef const _E _reference;
+  typedef size_t size_type;
+
+  typedef const _E *iterator;
+  typedef const _E *const_iterator;
+
+  initializer_list() : __begin_(nullptr), __size_(0) {}
+
+  size_t size() const { return __size_; }
+  const _E *begin() const { return __begin_; }
+  const _E *end() const { return __begin_ + __size_; }
+};
+
+template 
+class vector {
+public:
+  vector(T){};
+  vector(std::initializer_list) {}
+};
+}
+
+class Bar {};
+
+Bar b;
+
+class Foo {
+public:
+  Foo(Bar);
+  explicit Foo(Bar, unsigned int);
+  Foo(unsigned int);
+};
+
+class Baz {
+public:
+  Foo m() {
+Bar b;
+return Foo(b);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: to avoid repeating the return type from the declaration, use a braced initializer list instead [modernize-return-braced-init-list]
+// CHECK-FIXES: return {b};
+  }
+};
+
+class Quux : public Foo {
+public:
+  Quux(Bar bar) : Foo(bar){};
+};
+
+Foo f() {
+  Bar b;
+  return Foo(b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: to avoid repeating the return type from the declaration, use a braced initializer list instead [modernize-return-braced-init-list]
+  // CHECK-FIXES: return {b};
+}
+
+Foo f2() {
+  Bar b;
+  return {b};
+}
+
+auto f3() {
+  Bar b;
+  return Foo(b);
+}
+
+#define A(b) Foo(b)
+
+Foo f4() {
+  Bar b;
+  return A(b);
+}
+
+Foo f5() {
+  Bar b;
+  return Quux(b);
+}
+
+Foo f6() {
+  Bar b;
+  return Foo(b, 1);
+}
+
+std::vector f7() {
+  int i = 1;
+  return std::vector(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: to avoid repeating the return type from the declaration, use a braced initializer list instead [modernize-return-braced-init-list]
+  // CHECK-FIXES: return {i};
+}
+
+Bar f8() {
+  return {};
+}
+
+Bar f9() {
+  return Bar();
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: to avoid repeating the return type from the declaration, use a braced initializer list instead [modernize-return-braced-init-list]
+  // CHECK-FIXES: return {};
+}
+
+Bar f10() {
+  return Bar{};
+}
+
+Foo f11(Bar b) {
+  return Foo(b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: to avoid repeating the return type from the declaration, use a braced initializer list instead [modernize-return-braced-init-list]
+  // CHECK-FIXES: return {b};
+}
+
+Foo f12() {
+  return f11(Bar());
+}
+
+Foo f13() {
+  return Foo(Bar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: to avoid repeating the return type from the declaration, use a braced initializer list instead [modernize-return-braced-init-list]
+  // CHECK-FIXES: return {Bar()};
+}
+
+Foo f14() {
+  // FIXME: Type narrowing should not occur!
+  return Foo(-1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: to avoid repeating the return type from the declaration, use a braced initializer list instead [modernize-return-braced-init-list]
+  // CHECK-FIXES: return {-1};
+}
+
+Foo f15() {
+  return Foo(f10());
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: to avoid repeating the return type from the declaration, use a braced initializer list instead [modernize-return-braced-init-list]
+  // CHECK-FIXES: return {f10()};
+}
+
+template 
+T f16() {
+  return T();
+}
+
+Bar i1 = f16();
+Baz i2 = f16();
+
+template 
+Foo f17(T t) {
+  return Foo(t);
+}
+
+Foo i3 = f17(b);
+
+template 
+class BazT {
+public:
+  T m() {
+Bar b;
+return T(b);
+  }
+
+  Foo m2(T t) {
+return Foo(t);
+  }
+};
+
+BazT bazFoo;
+Foo i4 = bazFoo.m();
+Foo i5 = bazFoo.m2(b);
+
+BazT bazQuux;
+Foo i6 = bazQuux.m();
+Foo i7 = bazQuux.m2(b);
+
+auto v1 = []() { return std::vector({1, 2}); }();
+auto v2 = []() -> std::vector { return std::vector({1, 2}); }();
Index: docs/clang-tidy/checks/modernize-return-braced-init-list.rst
===
--- /dev/null
+++ 

[PATCH] D29186: clang-format: [JS] do not format MPEG transport streams.

2017-01-26 Thread Alex Eagle via Phabricator via cfe-commits
alexeagle added a comment.

confused, wasn't this committed last year? is this an extra check?


https://reviews.llvm.org/D29186



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


[PATCH] D28520: Disable -Wthread-safety-analysis for some functions in __thread_support

2017-01-26 Thread Dimitry Andric via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293197: Disable thread safety analysis for some functions in 
__thread_support (authored by dim).

Changed prior to commit:
  https://reviews.llvm.org/D28520?vs=85794=85939#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28520

Files:
  libcxx/trunk/include/__threading_support


Index: libcxx/trunk/include/__threading_support
===
--- libcxx/trunk/include/__threading_support
+++ libcxx/trunk/include/__threading_support
@@ -40,6 +40,12 @@
 #define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
 #endif
 
+#if defined(__FreeBSD__) && defined(__clang__) && 
__has_attribute(no_thread_safety_analysis)
+#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 
__attribute__((no_thread_safety_analysis))
+#else
+#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
@@ -102,25 +108,25 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_mutex_lock(__libcpp_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
@@ -133,10 +139,10 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
timespec *__ts);
 


Index: libcxx/trunk/include/__threading_support
===
--- libcxx/trunk/include/__threading_support
+++ libcxx/trunk/include/__threading_support
@@ -40,6 +40,12 @@
 #define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
 #endif
 
+#if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(no_thread_safety_analysis)
+#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
+#else
+#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
@@ -102,25 +108,25 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_mutex_lock(__libcpp_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_mutex_unlock(__libcpp_mutex_t *__m);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
@@ -133,10 +139,10 @@
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m);
 
-_LIBCPP_THREAD_ABI_VISIBILITY
+_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 int 

[PATCH] D26345: Extend small data threshold driver options to PPC target

2017-01-26 Thread Richard Smith via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

As of r293254, the `-G=` and `-msmall-data-threshold=` flags are just aliases 
of `-G`, so you don't need those parts of this patch any more. The PPC part 
looks fine, but please add a testcase.

In future, please add cfe-commits as a subscriber to Clang changes; otherwise 
mail doesn't get sent there and patches tend to get lost.


https://reviews.llvm.org/D26345



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


[PATCH] D29198: clang-cl: Warn about /U flags that look like filenames (PR31662)

2017-01-26 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added a comment.

Thanks for adding this, diagnosing what was going on here the first time around 
took a little bit of thinking.


https://reviews.llvm.org/D29198



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


[PATCH] D29208: Prevent ICE in dllexport class with _Atomic() data member

2017-01-26 Thread Warren Ristow via Phabricator via cfe-commits
wristow added a comment.

When a class that has been tagged as dllexport (for an MSVC target) contains an 
atomic data member via the C11 '_Atomic' approach, the front end crashes with a 
null pointer dereference.
This patch fixes it by guarding the null dereference with the approach used by 
similar code in the same method.


https://reviews.llvm.org/D29208



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


[PATCH] D29208: Prevent ICE in dllexport class with _Atomic() data member

2017-01-26 Thread Warren Ristow via Phabricator via cfe-commits
wristow created this revision.

Guard against a null pointer dereference that caused Clang to crash
when processing a class containing an _Atomic() data member,
and that is tagged with 'dllexport'.


https://reviews.llvm.org/D29208

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/atomic-dllexport.cpp


Index: test/CodeGenCXX/atomic-dllexport.cpp
===
--- test/CodeGenCXX/atomic-dllexport.cpp
+++ test/CodeGenCXX/atomic-dllexport.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++11 
-fms-extensions -O0 -o - %s | FileCheck --check-prefix=M32 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++11 
-fms-extensions -O0 -o - %s | FileCheck --check-prefix=M64 %s
+
+struct __declspec(dllexport) SomeStruct {
+  // Copy assignment operator should be produced, and exported:
+  // M32: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) 
%struct.SomeStruct* @"\01??4SomeStruct@@QAEAAU0@ABU0@@Z"
+  // M64: define weak_odr dllexportdereferenceable({{[0-9]+}}) 
%struct.SomeStruct* @"\01??4SomeStruct@@QEAAAEAU0@AEBU0@@Z"
+  _Atomic(int) mData;
+};
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1132,7 +1132,7 @@
 if (!RHS)
   return nullptr;
 MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
+if (!ME2 || dyn_cast(ME2->getMemberDecl()) != Field)
   return nullptr;
 return Field;
   } else if (CXXMemberCallExpr *MCE = dyn_cast(S)) {


Index: test/CodeGenCXX/atomic-dllexport.cpp
===
--- test/CodeGenCXX/atomic-dllexport.cpp
+++ test/CodeGenCXX/atomic-dllexport.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++11 -fms-extensions -O0 -o - %s | FileCheck --check-prefix=M32 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++11 -fms-extensions -O0 -o - %s | FileCheck --check-prefix=M64 %s
+
+struct __declspec(dllexport) SomeStruct {
+  // Copy assignment operator should be produced, and exported:
+  // M32: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.SomeStruct* @"\01??4SomeStruct@@QAEAAU0@ABU0@@Z"
+  // M64: define weak_odr dllexportdereferenceable({{[0-9]+}}) %struct.SomeStruct* @"\01??4SomeStruct@@QEAAAEAU0@AEBU0@@Z"
+  _Atomic(int) mData;
+};
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1132,7 +1132,7 @@
 if (!RHS)
   return nullptr;
 MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
+if (!ME2 || dyn_cast(ME2->getMemberDecl()) != Field)
   return nullptr;
 return Field;
   } else if (CXXMemberCallExpr *MCE = dyn_cast(S)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29209: Use copy.deepcopy instead of doing it manually.

2017-01-26 Thread Dan Albert via Phabricator via cfe-commits
danalbert created this revision.

Repository:
  rL LLVM

https://reviews.llvm.org/D29209

Files:
  test/libcxx/compiler.py
  test/libcxx/test/format.py


Index: test/libcxx/test/format.py
===
--- test/libcxx/test/format.py
+++ test/libcxx/test/format.py
@@ -7,6 +7,7 @@
 #
 #===--===##
 
+import copy
 import errno
 import os
 import time
@@ -36,7 +37,7 @@
 
 def __init__(self, cxx, use_verify_for_fail, execute_external,
  executor, exec_env):
-self.cxx = cxx.copy()
+self.cxx = copy.deepcopy(cxx)
 self.use_verify_for_fail = use_verify_for_fail
 self.execute_external = execute_external
 self.executor = executor
@@ -115,7 +116,7 @@
tmpBase)
 script = lit.TestRunner.applySubstitutions(script, substitutions)
 
-test_cxx = self.cxx.copy()
+test_cxx = copy.deepcopy(self.cxx)
 if is_fail_test:
 test_cxx.useCCache(False)
 test_cxx.useWarnings(False)
Index: test/libcxx/compiler.py
===
--- test/libcxx/compiler.py
+++ test/libcxx/compiler.py
@@ -49,18 +49,6 @@
 if self.type is None or self.version is None:
 self._initTypeAndVersion()
 
-def copy(self):
-new_cxx = CXXCompiler(
-self.path, flags=self.flags, compile_flags=self.compile_flags,
-link_flags=self.link_flags, warning_flags=self.warning_flags,
-verify_supported=self.verify_supported,
-verify_flags=self.verify_flags, use_verify=self.use_verify,
-modules_flags=self.modules_flags, use_modules=self.use_modules,
-use_ccache=self.use_ccache, use_warnings=self.use_warnings,
-compile_env=self.compile_env, cxx_type=self.type,
-cxx_version=self.version)
-return new_cxx
-
 def isVerifySupported(self):
 if self.verify_supported is None:
 self.verify_supported = self.hasCompileFlag(['-Xclang',


Index: test/libcxx/test/format.py
===
--- test/libcxx/test/format.py
+++ test/libcxx/test/format.py
@@ -7,6 +7,7 @@
 #
 #===--===##
 
+import copy
 import errno
 import os
 import time
@@ -36,7 +37,7 @@
 
 def __init__(self, cxx, use_verify_for_fail, execute_external,
  executor, exec_env):
-self.cxx = cxx.copy()
+self.cxx = copy.deepcopy(cxx)
 self.use_verify_for_fail = use_verify_for_fail
 self.execute_external = execute_external
 self.executor = executor
@@ -115,7 +116,7 @@
tmpBase)
 script = lit.TestRunner.applySubstitutions(script, substitutions)
 
-test_cxx = self.cxx.copy()
+test_cxx = copy.deepcopy(self.cxx)
 if is_fail_test:
 test_cxx.useCCache(False)
 test_cxx.useWarnings(False)
Index: test/libcxx/compiler.py
===
--- test/libcxx/compiler.py
+++ test/libcxx/compiler.py
@@ -49,18 +49,6 @@
 if self.type is None or self.version is None:
 self._initTypeAndVersion()
 
-def copy(self):
-new_cxx = CXXCompiler(
-self.path, flags=self.flags, compile_flags=self.compile_flags,
-link_flags=self.link_flags, warning_flags=self.warning_flags,
-verify_supported=self.verify_supported,
-verify_flags=self.verify_flags, use_verify=self.use_verify,
-modules_flags=self.modules_flags, use_modules=self.use_modules,
-use_ccache=self.use_ccache, use_warnings=self.use_warnings,
-compile_env=self.compile_env, cxx_type=self.type,
-cxx_version=self.version)
-return new_cxx
-
 def isVerifySupported(self):
 if self.verify_supported is None:
 self.verify_supported = self.hasCompileFlag(['-Xclang',
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25402: [Driver] Pass -lunwind along with compiler-rt when necessary on Linux

2017-01-26 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd requested changes to this revision.
compnerd added a comment.
This revision now requires changes to proceed.

This really needs a new driver flag (`-unwinder`?) similar to `-rtlib`, as 
there are multiple unwinders, and it is unclear which unwinder is the proper 
one on a given target.  This has been something on my TODO list for a while.  
Mixing and matching undwinders is not really possible, and it is perfectly 
valid to use compiler-rt with the gcc unwinder on Linux.


https://reviews.llvm.org/D25402



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


[PATCH] D20693: [clang-tidy] New checker to replace dynamic exception specifications

2017-01-27 Thread don hinton via Phabricator via cfe-commits
hintonda added a comment.

Thanks and sorry for the breakage.  Unfortunately, I'm unable to reproduce 
locally (OSX), but will try to get access to linux box this weekend.

Seems to be related to memory corruption wrt to improper StringRef usage, but I 
can't say for sure yet.


https://reviews.llvm.org/D20693



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


[PATCH] D29205: Change debug-info-for-profiling from a TargetOption to a function attribute.

2017-01-27 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:452
+  if (CodeGenOpts.DebugInfoForProfiling)
+getModule().addModuleFlag(llvm::Module::Warning, "DebugInfoForProfiling", 
1);
 

danielcdh wrote:
> mehdi_amini wrote:
> > Why should we warn on mismatch?
> In theory, we expect this to be the same across all modules. Otherwise when 
> we use this binary for profiling, we may get inaccurate profiles.
Oh I thought about the "unset" case but we wouldn't warn in this case.

Indeed we never even should have this flag with a zero value.


https://reviews.llvm.org/D29205



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


[PATCH] D29205: Change debug-info-for-profiling from a TargetOption to a function attribute.

2017-01-27 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:452
+  if (CodeGenOpts.DebugInfoForProfiling)
+getModule().addModuleFlag(llvm::Module::Warning, "DebugInfoForProfiling", 
1);
 

mehdi_amini wrote:
> danielcdh wrote:
> > mehdi_amini wrote:
> > > Why should we warn on mismatch?
> > In theory, we expect this to be the same across all modules. Otherwise when 
> > we use this binary for profiling, we may get inaccurate profiles.
> Oh I thought about the "unset" case but we wouldn't warn in this case.
> 
> Indeed we never even should have this flag with a zero value.
Unless you really intend to get a warning on mismatch, in which case you should 
always emit the flag, but with a zero value when not enabled.
I'd need more thought to really grasp all the consequences :)



https://reviews.llvm.org/D29205



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


[PATCH] D29205: Change debug-info-for-profiling from a TargetOption to a function attribute.

2017-01-27 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:452
+  if (CodeGenOpts.DebugInfoForProfiling)
+getModule().addModuleFlag(llvm::Module::Warning, "DebugInfoForProfiling", 
1);
 

mehdi_amini wrote:
> Why should we warn on mismatch?
In theory, we expect this to be the same across all modules. Otherwise when we 
use this binary for profiling, we may get inaccurate profiles.


https://reviews.llvm.org/D29205



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


[PATCH] D26345: Extend small data threshold driver options to PPC target

2017-01-27 Thread Jack Andersen via Phabricator via cfe-commits
jackoalan updated this revision to Diff 86088.
jackoalan added a comment.
Herald added a subscriber: nemanjai.

Remove already-aliased option matchings; add test case for patch.


https://reviews.llvm.org/D26345

Files:
  lib/Driver/Tools.cpp
  test/Driver/ppc-eabi-small-data.c


Index: test/Driver/ppc-eabi-small-data.c
===
--- /dev/null
+++ test/Driver/ppc-eabi-small-data.c
@@ -0,0 +1,9 @@
+// Check passing PowerPC EABI small-data threshold to the backend.
+
+// RUN: %clang -target powerpc-unknown-unknown-eabi -G 0 %s -### -o %t.o 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-SDATA0 %s
+// RUN: %clang -target powerpc-unknown-unknown-eabi -G 8 %s -### -o %t.o 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-SDATA8 %s
+
+// CHECK-SDATA0: "-mllvm" "-ppc-ssection-threshold=0"
+// CHECK-SDATA8: "-mllvm" "-ppc-ssection-threshold=8"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1887,6 +1887,13 @@
 CmdArgs.push_back("-target-abi");
 CmdArgs.push_back(ABIName);
   }
+
+  if (Arg *A = Args.getLastArg(options::OPT_G)) {
+StringRef v = A->getValue();
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-ppc-ssection-threshold=" + v));
+A->claim();
+  }
 }
 
 bool ppc::hasPPCAbiArg(const ArgList , const char *Value) {


Index: test/Driver/ppc-eabi-small-data.c
===
--- /dev/null
+++ test/Driver/ppc-eabi-small-data.c
@@ -0,0 +1,9 @@
+// Check passing PowerPC EABI small-data threshold to the backend.
+
+// RUN: %clang -target powerpc-unknown-unknown-eabi -G 0 %s -### -o %t.o 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-SDATA0 %s
+// RUN: %clang -target powerpc-unknown-unknown-eabi -G 8 %s -### -o %t.o 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-SDATA8 %s
+
+// CHECK-SDATA0: "-mllvm" "-ppc-ssection-threshold=0"
+// CHECK-SDATA8: "-mllvm" "-ppc-ssection-threshold=8"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1887,6 +1887,13 @@
 CmdArgs.push_back("-target-abi");
 CmdArgs.push_back(ABIName);
   }
+
+  if (Arg *A = Args.getLastArg(options::OPT_G)) {
+StringRef v = A->getValue();
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-ppc-ssection-threshold=" + v));
+A->claim();
+  }
 }
 
 bool ppc::hasPPCAbiArg(const ArgList , const char *Value) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27985: Add demangling support for C++11 thread_local variables

2017-01-30 Thread Dave Bozier via Phabricator via cfe-commits
davidb added a comment.

In https://reviews.llvm.org/D27985#660029, @mehdi_amini wrote:

> LGTM.
>
> Can you apply the patch in LLVM (libDemangle) as well please?


Thank you Mehdi. I have an LLVM (libDemangle) with an identical change (minus 
the tests) waiting. Would you like my to submit it as a separate patch?

I've just requested commit access so fingers crossed I can apply them both soon.


Repository:
  rL LLVM

https://reviews.llvm.org/D27985



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


[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.

Revert r293455, which breaks v8 with a spurious error. Testcase added.


https://reviews.llvm.org/D29271

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Sema/TreeTransform.h
  test/Parser/cxx1z-class-template-argument-deduction.cpp
  test/SemaCXX/cxx0x-class.cpp

Index: test/SemaCXX/cxx0x-class.cpp
===
--- test/SemaCXX/cxx0x-class.cpp
+++ test/SemaCXX/cxx0x-class.cpp
@@ -45,3 +45,12 @@
   DefaultMemberTemplate t = {};
   int *p = 
 };
+
+namespace composed_templates {
+  // Regression test -- obtaining the type from composed templates should not
+  // require out-of-line definition.
+  template  struct Foo { static constexpr bool value = true; };
+  template  struct Bar { using type = char; };
+  template  struct Baz { static const typename Bar::type value = 0; };
+  template struct Baz<0>;
+}
Index: test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -verify %s
 
-template struct A {}; // expected-note 35{{declared here}}
+template struct A {}; // expected-note 31{{declared here}}
 
 // Make sure we still correctly parse cases where a template can appear without arguments.
 namespace template_template_arg {
@@ -101,8 +101,6 @@
 (void)reinterpret_cast(); // expected-error{{requires template arguments; argument deduction not allowed here}}
 (void)const_cast(n); // expected-error{{requires template arguments; argument deduction not allowed here}}
 (void)*(A*)(); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(A)(n); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(A){n}; // expected-error{{requires template arguments; argument deduction not allowed here}}
 
 (void)A(n); // expected-error {{not yet supported}}
 (void)A{n}; // expected-error {{not yet supported}}
@@ -123,66 +121,11 @@
 
   A a; // expected-error {{requires an initializer}}
   A b = 0; // expected-error {{not yet supported}}
-  const A c = 0; // expected-error {{not yet supported}}
   A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}}
   A *p = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
   A  = *p; // expected-error {{cannot form reference to deduced class template specialization type}}
   A arr[3] = 0; // expected-error {{cannot form array of deduced class template specialization type}}
   A F::*pm = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
   A (*fp)() = 0; // expected-error {{cannot form function returning deduced class template specialization type}}
   A [x, y] = 0; // expected-error {{cannot be declared with type 'A'}} expected-error {{not yet supported}}
 }
-
-namespace typename_specifier {
-  struct F {};
-
-  void e() {
-(void) typename ::A(0); // expected-error {{not yet supported}}
-(void) typename ::A{0}; // expected-error {{not yet supported}}
-new typename ::A(0); // expected-error {{not yet supported}}
-new typename ::A{0}; // expected-error {{not yet supported}}
-typename ::A a = 0; // expected-error {{not yet supported}}
-const typename ::A b = 0; // expected-error {{not yet supported}}
-if (typename ::A a = 0) {} // expected-error {{not yet supported}}
-for (typename ::A a = 0; typename ::A b = 0; /**/) {} // expected-error 2{{not yet supported}}
-
-(void)(typename ::A)(0); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(typename ::A){0}; // expected-error{{requires template arguments; argument deduction not allowed here}}
-  }
-  typename ::A a = 0; // expected-error {{not yet supported}}
-  const typename ::A b = 0; // expected-error {{not yet supported}}
-  typename ::A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}}
-  typename ::A *p = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
-  typename ::A  = *p; // expected-error {{cannot form reference to deduced class template specialization type}}
-  typename ::A arr[3] = 0; // expected-error {{cannot form array of deduced class template specialization type}}
-  typename ::A F::*pm = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
-  typename ::A (*fp)() = 0; // 

[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

Btw, ran into that with the even simpler test case

  template struct S {
  static typename T::t const n = 0;
  };
  struct U { using t = int; };
  int main() { return S::n; }


https://reviews.llvm.org/D29271



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


[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In https://reviews.llvm.org/D29271#660169, @sberg wrote:

> Btw, ran into that with the even simpler test case


Thanks, I stole it :-)


https://reviews.llvm.org/D29271



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


[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293473: Revert r293455, which breaks v8 with a spurious 
error. Testcase added. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D29271?vs=86257=86259#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29271

Files:
  cfe/trunk/include/clang/AST/DeclTemplate.h
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaTemplate.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  cfe/trunk/lib/Sema/TreeTransform.h
  cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
  cfe/trunk/test/SemaCXX/cxx0x-class.cpp

Index: cfe/trunk/include/clang/AST/DeclTemplate.h
===
--- cfe/trunk/include/clang/AST/DeclTemplate.h
+++ cfe/trunk/include/clang/AST/DeclTemplate.h
@@ -2946,16 +2946,6 @@
   return P.get();
 }
 
-inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {
-  auto *TD = dyn_cast(D);
-  return TD && (isa(TD) ||
-isa(TD) ||
-isa(TD) ||
-isa(TD))
- ? TD
- : nullptr;
-}
-
 } /* end of namespace clang */
 
 #endif
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -7359,8 +7359,7 @@
 
   TypeSourceInfo *SubstType(TypeSourceInfo *T,
 const MultiLevelTemplateArgumentList ,
-SourceLocation Loc, DeclarationName Entity,
-bool AllowDeducedTST = false);
+SourceLocation Loc, DeclarationName Entity);
 
   QualType SubstType(QualType T,
  const MultiLevelTemplateArgumentList ,
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1884,11 +1884,6 @@
   "|in conversion function type|here|in lambda parameter"
   "|in type allocated by 'new'|in K function parameter"
   "|in template parameter|in friend declaration}1">;
-def err_dependent_deduced_tst : Error<
-  "typename specifier refers to "
-  "%select{class template|function template|variable template|alias template|"
-  "template template parameter|template}0 member in %1; "
-  "argument deduction not allowed here">;
 def err_auto_not_allowed_var_inst : Error<
   "'auto' variable template instantiation is not allowed">;
 def err_auto_var_requires_init : Error<
Index: cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -verify %s
 
-template struct A {}; // expected-note 35{{declared here}}
+template struct A {}; // expected-note 31{{declared here}}
 
 // Make sure we still correctly parse cases where a template can appear without arguments.
 namespace template_template_arg {
@@ -101,8 +101,6 @@
 (void)reinterpret_cast(); // expected-error{{requires template arguments; argument deduction not allowed here}}
 (void)const_cast(n); // expected-error{{requires template arguments; argument deduction not allowed here}}
 (void)*(A*)(); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(A)(n); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(A){n}; // expected-error{{requires template arguments; argument deduction not allowed here}}
 
 (void)A(n); // expected-error {{not yet supported}}
 (void)A{n}; // expected-error {{not yet supported}}
@@ -123,66 +121,11 @@
 
   A a; // expected-error {{requires an initializer}}
   A b = 0; // expected-error {{not yet supported}}
-  const A c = 0; // expected-error {{not yet supported}}
   A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}}
   A *p = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
   A  = *p; // expected-error {{cannot form reference to deduced class template specialization type}}
   A arr[3] = 0; // expected-error {{cannot form array of deduced class template specialization type}}
   A F::*pm = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
   A (*fp)() = 0; // expected-error {{cannot form function returning deduced class template specialization type}}
   A [x, y] = 

[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D29271



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


[PATCH] D29205: Change debug-info-for-profiling from a TargetOption to a function attribute.

2017-01-30 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh updated this revision to Diff 86292.
danielcdh added a comment.

update


https://reviews.llvm.org/D29205

Files:
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGDebugInfo.cpp


Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -509,7 +509,8 @@
Checksum),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
-  CGM.getCodeGenOpts().SplitDwarfInlining);
+  CGM.getCodeGenOpts().SplitDwarfInlining,
+  CGM.getCodeGenOpts().DebugInfoForProfiling);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -573,7 +573,6 @@
   Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
   Options.CompressDebugSections = CodeGenOpts.CompressDebugSections;
   Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
-  Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling;
 
   // Set EABI version.
   Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion)


Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -509,7 +509,8 @@
Checksum),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
-  CGM.getCodeGenOpts().SplitDwarfInlining);
+  CGM.getCodeGenOpts().SplitDwarfInlining,
+  CGM.getCodeGenOpts().DebugInfoForProfiling);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -573,7 +573,6 @@
   Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
   Options.CompressDebugSections = CodeGenOpts.CompressDebugSections;
   Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
-  Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling;
 
   // Set EABI version.
   Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29152: Drop 'dllimport' when redeclaring inline function template without the attribute (PR31695)

2017-01-30 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Ping?


https://reviews.llvm.org/D29152



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


[PATCH] D29152: Drop 'dllimport' when redeclaring inline function template without the attribute (PR31695)

2017-01-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D29152



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


[PATCH] D29262: Fixes to modernize-use-using

2017-01-30 Thread Krystyna via Phabricator via cfe-commits
krystyna updated this revision to Diff 86298.
krystyna edited the summary of this revision.
krystyna added a comment.

Style fixes.


https://reviews.llvm.org/D29262

Files:
  clang-tidy/modernize/UseUsingCheck.cpp
  clang-tidy/modernize/UseUsingCheck.h
  test/clang-tidy/modernize-use-using-macros.cpp
  test/clang-tidy/modernize-use-using.cpp

Index: test/clang-tidy/modernize-use-using.cpp
===
--- test/clang-tidy/modernize-use-using.cpp
+++ test/clang-tidy/modernize-use-using.cpp
@@ -89,7 +89,6 @@
 #define CODE typedef int INT
 
 CODE;
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: #define CODE typedef int INT
 // CHECK-FIXES: CODE;
 
@@ -102,7 +101,6 @@
 
 #define TYPEDEF typedef
 TYPEDEF Foo Bak;
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: #define TYPEDEF typedef
 // CHECK-FIXES: TYPEDEF Foo Bak;
 
@@ -148,3 +146,18 @@
 struct { int d; } typedef S4;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: struct { int d; } typedef S4;
+
+namespace my_space {
+  class my_cclass {};
+  typedef my_cclass FuncType;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using FuncType = my_cclass
+}
+
+#define lol 4
+typedef unsigned Map[lol]; 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+
+typedef void (*fun_type)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using fun_type = void (*)();
Index: test/clang-tidy/modernize-use-using-macros.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-using-macros.cpp
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-using.MacroWarning, value: 1}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/modernize-use-using
+
+#define CODE typedef int INT
+
+CODE;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define CODE typedef int INT
+// CHECK-FIXES: CODE;
+
+struct Foo;
+#define Bar Baz
+typedef Foo Bar;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define Bar Baz
+// CHECK-FIXES: using Baz = Foo;
+
+#define TYPEDEF typedef
+TYPEDEF Foo Bak;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define TYPEDEF typedef
+// CHECK-FIXES: TYPEDEF Foo Bak;
Index: clang-tidy/modernize/UseUsingCheck.h
===
--- clang-tidy/modernize/UseUsingCheck.h
+++ clang-tidy/modernize/UseUsingCheck.h
@@ -21,11 +21,15 @@
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize-use-using.html
 class UseUsingCheck : public ClangTidyCheck {
+
 public:
-  UseUsingCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  UseUsingCheck(StringRef Name, ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+
+private:
+  const bool MacroWarning;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/UseUsingCheck.cpp
===
--- clang-tidy/modernize/UseUsingCheck.cpp
+++ clang-tidy/modernize/UseUsingCheck.cpp
@@ -17,12 +17,20 @@
 namespace tidy {
 namespace modernize {
 
+UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  MacroWarning(Options.get("MacroWarning", false)) {}
+
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
 return;
   Finder->addMatcher(typedefDecl().bind("typedef"), this);
 }
 
+void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "MacroWarning", MacroWarning);
+}
+
 // Checks if 'typedef' keyword can be removed - we do it only if
 // it is the only declaration in a declaration chain.
 static bool CheckRemoval(SourceManager , SourceLocation StartLoc,
@@ -80,22 +88,32 @@
   auto  = *Result.SourceManager;
 
   if (auto *D = MatchedDecl->getUnderlyingType()->getAsCXXRecordDecl()) {
-//TypeLoc TL = MatchedDecl->getTypeSourceInfo()->getTypeLoc();
+// TypeLoc TL = MatchedDecl->getTypeSourceInfo()->getTypeLoc();
 llvm::errs() << D->getNameAsString() << "\n";
   }
 
+  SourceLocation StartLoc = MatchedDecl->getLocStart();
+
+  if (StartLoc.isMacroID() && !MacroWarning)
+return;
+
   auto Diag =
   diag(MatchedDecl->getLocStart(), "use 'using' instead of 'typedef'");
 
-  SourceLocation StartLoc = MatchedDecl->getLocStart();
-  if 

[PATCH] D28050: [Clang][Driver] Clean up Clang::ConstructJob a little bit, NFC

2017-01-30 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

I think this patch is an improvement, but Clang::ConstructJob is still one 
giant function.

Do you have ideas to improve readability of this function or plans to further 
reduce its size?


Repository:
  rL LLVM

https://reviews.llvm.org/D28050



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


[PATCH] D27985: Add demangling support for C++11 thread_local variables

2017-01-30 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

In https://reviews.llvm.org/D27985#660354, @davidb wrote:

> In https://reviews.llvm.org/D27985#660029, @mehdi_amini wrote:
>
> > LGTM.
> >
> > Can you apply the patch in LLVM (libDemangle) as well please?
>
>
> Thank you Mehdi. I have an LLVM (libDemangle) with an identical change (minus 
> the tests) waiting. Would you like my to submit it as a separate patch?


No, just commit it.


Repository:
  rL LLVM

https://reviews.llvm.org/D27985



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


[PATCH] D28835: [coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.

2017-01-30 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov added a comment.

LGTM? Pretty please :)


https://reviews.llvm.org/D28835



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


[PATCH] D22955: [MSVC] Improved late parsing of template functions.

2017-01-30 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Ping


https://reviews.llvm.org/D22955



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


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 86337.
sammccall added a comment.

Oops, reverted noise :(


https://reviews.llvm.org/D29303

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp


Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() 
&&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());


Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() &&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I couldn't work out how to add a test for this, advice appreciated.

Closest I could get was adding something like this to 
test/Analysis/virtualcall.cpp:

  class F { public: F(); void foo(); };
  F::F() { void (F::* ptr) = ::foo; (this->*ptr)(); }

which crashes, but only if I add extra logging :\


https://reviews.llvm.org/D29303



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


[PATCH] D24333: [CleanupInfo] Use cleanupsHaveSideEffects instead of exprNeedsCleanups in assertions

2017-01-30 Thread Richard Smith via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/test/SemaCXX/pr30306.cpp:5
+template 
+void g(T) { int a[f(3)]; } // expected-no-diagnostics
+

Shouldn't we be (somehow) handling the cleanups from the array bound expression 
here -- either discarding them or attaching them to the array bound? Looks like 
`TreeTransform::TransformVariableArrayType` is missing a call to 
`ActOnFinishFullExpr`.

If we modify the test to:

```
struct A { A(int); ~A(); };
int f(const A &);
template void g() { int a[f(3)]; }
int main() { g(); }
```

... we need to register the `~A()` destructor to actually be run at some point.


https://reviews.llvm.org/D24333



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


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 86342.
sammccall added a comment.

Add regression test.


https://reviews.llvm.org/D29303

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp


Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -115,12 +115,23 @@
   int foo() override;
 };
 
+// Regression test: don't crash when there's no direct callee.
+class F {
+public:
+  F() {
+void (F::* ptr)() = ::foo;
+(this->*ptr)();
+  }
+  void foo();
+};
+
 int main() {
   A *a;
   B *b;
   C *c;
   D *d;
   E *e;
+  F *f;
 }
 
 #include "virtualcall.h"
Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() 
&&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());


Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -115,12 +115,23 @@
   int foo() override;
 };
 
+// Regression test: don't crash when there's no direct callee.
+class F {
+public:
+  F() {
+void (F::* ptr)() = ::foo;
+(this->*ptr)();
+  }
+  void foo();
+};
+
 int main() {
   A *a;
   B *b;
   C *c;
   D *d;
   E *e;
+  F *f;
 }
 
 #include "virtualcall.h"
Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() &&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29304: [cmake] Hint find_package() to prefer LLVM installed alongside clang

2017-01-30 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.

Include a path hint for find_package() in ClangConfig.cmake to ensure
that CMake prefers LLVM installed alongside clang over the default
search path.

If two versions of LLVM are installed in the system, and one of them is
in PATH, CMake's find_package() magic prefers the CMake directory
alongside that install by default. Adding a relative hint makes it
possible to prioritize to the install from which find_package() is
called.

If you want to build e.g. LLDB against another install of LLVM, you can
pass LLVM_CONFIG override. In this case, LLDB queries the prefix from
llvm-config and uses the CMake files located there. However, when
including ClangConfig, the implicit find_package() nevertheless prefers
PATH-found LLVM over the one used previously by LLDB, and two versions
of LLVMConfig end up being loaded.

This could be fixed on LLDB end up by explicitly forcing custom package
search location. However, it seems simpler and safer to add a hint to
ClangConfig than to track every usage of ClangConfig.


Repository:
  rL LLVM

https://reviews.llvm.org/D29304

Files:
  cmake/modules/CMakeLists.txt
  cmake/modules/ClangConfig.cmake.in


Index: cmake/modules/ClangConfig.cmake.in
===
--- cmake/modules/ClangConfig.cmake.in
+++ cmake/modules/ClangConfig.cmake.in
@@ -1,9 +1,10 @@
 # This file allows users to call find_package(Clang) and pick up our targets.
 
-find_package(LLVM REQUIRED CONFIG)
-
 @CLANG_CONFIG_CODE@
 
+find_package(LLVM REQUIRED CONFIG
+ HINTS "@CLANG_CONFIG_LLVM_CMAKE_DIR@")
+
 set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")
 set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@")
 
Index: cmake/modules/CMakeLists.txt
===
--- cmake/modules/CMakeLists.txt
+++ cmake/modules/CMakeLists.txt
@@ -4,17 +4,23 @@
 set(CLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/clang)
 set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}")
 
+# Keep this in sync with llvm/cmake/CMakeLists.txt!
+set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
+set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
+
 get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
 export(TARGETS ${CLANG_EXPORTS} FILE 
${clang_cmake_builddir}/ClangTargets.cmake)
 
 # Generate ClangConfig.cmake for the build tree.
 set(CLANG_CONFIG_CMAKE_DIR "${clang_cmake_builddir}")
+set(CLANG_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
 set(CLANG_CONFIG_EXPORTS_FILE "${clang_cmake_builddir}/ClangTargets.cmake")
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${clang_cmake_builddir}/ClangConfig.cmake
   @ONLY)
 set(CLANG_CONFIG_CMAKE_DIR)
+set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 set(CLANG_CONFIG_EXPORTS_FILE)
 
 # Generate ClangConfig.cmake for the install tree.
@@ -29,6 +35,7 @@
 get_filename_component(CLANG_INSTALL_PREFIX \"\${CLANG_INSTALL_PREFIX}\" 
PATH)")
 endforeach(p)
 set(CLANG_CONFIG_CMAKE_DIR 
"\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}")
+set(CLANG_CONFIG_LLVM_CMAKE_DIR 
"\${CLANG_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
 set(CLANG_CONFIG_EXPORTS_FILE "\${CLANG_CMAKE_DIR}/ClangTargets.cmake")
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in


Index: cmake/modules/ClangConfig.cmake.in
===
--- cmake/modules/ClangConfig.cmake.in
+++ cmake/modules/ClangConfig.cmake.in
@@ -1,9 +1,10 @@
 # This file allows users to call find_package(Clang) and pick up our targets.
 
-find_package(LLVM REQUIRED CONFIG)
-
 @CLANG_CONFIG_CODE@
 
+find_package(LLVM REQUIRED CONFIG
+ HINTS "@CLANG_CONFIG_LLVM_CMAKE_DIR@")
+
 set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")
 set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@")
 
Index: cmake/modules/CMakeLists.txt
===
--- cmake/modules/CMakeLists.txt
+++ cmake/modules/CMakeLists.txt
@@ -4,17 +4,23 @@
 set(CLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/clang)
 set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}")
 
+# Keep this in sync with llvm/cmake/CMakeLists.txt!
+set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
+set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
+
 get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
 export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)
 
 # Generate ClangConfig.cmake for the build tree.
 set(CLANG_CONFIG_CMAKE_DIR "${clang_cmake_builddir}")
+set(CLANG_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
 set(CLANG_CONFIG_EXPORTS_FILE "${clang_cmake_builddir}/ClangTargets.cmake")
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${clang_cmake_builddir}/ClangConfig.cmake
   @ONLY)
 set(CLANG_CONFIG_CMAKE_DIR)
+set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 

[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D29303



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


[PATCH] D29291: [clang-format] Separate line comment sections after a right brace from comment sections in the scope.

2017-01-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293539: [clang-format] Separate line comment sections after 
a right brace from comment… (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29291?vs=86316=86317#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29291

Files:
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp

Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -2051,14 +2051,19 @@
  const UnwrappedLine ) {
   if (Line.Tokens.empty())
 return false;
-  const FormatToken  = *Line.Tokens.front().Tok;
+
   // If Line starts with a line comment, then FormatTok continues the comment
-  // section if its original column is greater or equal to the  original start
+  // section if its original column is greater or equal to the original start
   // column of the line.
   //
-  // If Line starts with a a different token, then FormatTok continues the
-  // comment section if its original column greater than the original start
-  // column of the line.
+  // Define the min column token of a line as follows: if a line ends in '{' or
+  // contains a '{' followed by a line comment, then the min column token is
+  // that '{'. Otherwise, the min column token of the line is the first token of
+  // the line.
+  //
+  // If Line starts with a token other than a line comment, then FormatTok
+  // continues the comment section if its original column is greater than the
+  // original start column of the min column token of the line.
   //
   // For example, the second line comment continues the first in these cases:
   // // first line
@@ -2069,16 +2074,43 @@
   // and:
   // int i; // first line
   //  // second line
+  // and:
+  // do { // first line
+  //  // second line
+  //   int i;
+  // } while (true);
   //
   // The second line comment doesn't continue the first in these cases:
   //   // first line
   //  // second line
   // and:
   // int i; // first line
   // // second line
+  // and:
+  // do { // first line
+  //   // second line
+  //   int i;
+  // } while (true);
+  const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
+
+  // Scan for '{//'. If found, use the column of '{' as a min column for line
+  // comment section continuation.
+  const FormatToken *PreviousToken = nullptr;
+  for (const UnwrappedLineNode Node : Line.Tokens) {
+if (PreviousToken && PreviousToken->is(tok::l_brace) &&
+isLineComment(*Node.Tok)) {
+  MinColumnToken = PreviousToken;
+  break;
+}
+PreviousToken = Node.Tok;
+  }
+  if (PreviousToken && PreviousToken->is(tok::l_brace)) {
+MinColumnToken = PreviousToken;
+  }
+
   unsigned MinContinueColumn =
-  FirstLineTok.OriginalColumn +
-  ((isLineComment(FirstLineTok) && !FirstLineTok.Next) ? 0 : 1);
+  MinColumnToken->OriginalColumn +
+  (isLineComment(*MinColumnToken) ? 0 : 1);
   return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&
  isLineComment(*(Line.Tokens.back().Tok)) &&
  FormatTok.OriginalColumn >= MinContinueColumn;
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -1783,6 +1783,64 @@
"0x00, 0x00, 0x00, 0x00};// comment\n");
 }
 
+TEST_F(FormatTest, LineCommentsAfterRightBrace) {
+  EXPECT_EQ("if (true) { // comment about branch\n"
+"  // comment about f\n"
+"  f();\n"
+"}",
+format("if (true) { // comment about branch\n"
+   "  // comment about f\n"
+   "  f();\n"
+   "}",
+   getLLVMStyleWithColumns(80)));
+  EXPECT_EQ("if (1) { // if line 1\n"
+" // if line 2\n"
+" // if line 3\n"
+"  // f line 1\n"
+"  // f line 2\n"
+"  f();\n"
+"} else { // else line 1\n"
+" // else line 2\n"
+" // else line 3\n"
+"  // g line 1\n"
+"  g();\n"
+"}",
+format("if (1) { // if line 1\n"
+   "  // if line 2\n"
+   "// if line 3\n"
+   "  // f line 1\n"
+   "// f line 2\n"
+   "  f();\n"
+   "} else { // else line 1\n"
+   "// else line 2\n"
+   " // else line 3\n"
+   "  // g line 1\n"
+   "  g();\n"
+   "}"));
+  EXPECT_EQ("do { // line 1\n"
+" // line 2\n"
+"   

[PATCH] D29298: [clang-format] Fix regression that breaks comments without a comment prefix

2017-01-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293548: [clang-format] Fix regression that breaks comments 
without a comment prefix (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29298?vs=86328=86331#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29298

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -642,7 +642,11 @@
 Prefix.resize(Lines.size());
 OriginalPrefix.resize(Lines.size());
 for (size_t i = FirstLineIndex, e = Lines.size(); i < e; ++i) {
-  StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i]);
+  // We need to trim the blanks in case this is not the first line in a
+  // multiline comment. Then the indent is included in Lines[i].
+  StringRef IndentPrefix =
+  getLineCommentIndentPrefix(Lines[i].ltrim(Blanks));
+  assert(IndentPrefix.startswith("//"));
   OriginalPrefix[i] = Prefix[i] = IndentPrefix;
   if (Lines[i].size() > Prefix[i].size() &&
   isAlphanumeric(Lines[i][Prefix[i].size()])) {
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -1386,6 +1386,18 @@
   "#define XXX // q w e r\n"
   "// t y u i",
   format("#define XXX //q w e r t y u i", getLLVMStyleWithColumns(22)));
+  EXPECT_EQ("{\n"
+"  //\n"
+"  //\\\n"
+"  // long 1 2 3 4\n"
+"  // 5\n"
+"}",
+format("{\n"
+   "  //\n"
+   "  //\\\n"
+   "  // long 1 2 3 4 5\n"
+   "}",
+   getLLVMStyleWithColumns(20)));
 }
 
 TEST_F(FormatTest, PreservesHangingIndentInCxxComments) {


Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -642,7 +642,11 @@
 Prefix.resize(Lines.size());
 OriginalPrefix.resize(Lines.size());
 for (size_t i = FirstLineIndex, e = Lines.size(); i < e; ++i) {
-  StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i]);
+  // We need to trim the blanks in case this is not the first line in a
+  // multiline comment. Then the indent is included in Lines[i].
+  StringRef IndentPrefix =
+  getLineCommentIndentPrefix(Lines[i].ltrim(Blanks));
+  assert(IndentPrefix.startswith("//"));
   OriginalPrefix[i] = Prefix[i] = IndentPrefix;
   if (Lines[i].size() > Prefix[i].size() &&
   isAlphanumeric(Lines[i][Prefix[i].size()])) {
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -1386,6 +1386,18 @@
   "#define XXX // q w e r\n"
   "// t y u i",
   format("#define XXX //q w e r t y u i", getLLVMStyleWithColumns(22)));
+  EXPECT_EQ("{\n"
+"  //\n"
+"  //\\\n"
+"  // long 1 2 3 4\n"
+"  // 5\n"
+"}",
+format("{\n"
+   "  //\n"
+   "  //\\\n"
+   "  // long 1 2 3 4 5\n"
+   "}",
+   getLLVMStyleWithColumns(20)));
 }
 
 TEST_F(FormatTest, PreservesHangingIndentInCxxComments) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added a comment.

Your test case is fine, it crashes with assertions enabled.


https://reviews.llvm.org/D29303



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


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.

In VirtualCallChecker, handle indirect calls.

getDirectCallee() can be nullptr, and dyn_cast(nullptr) is UB


https://reviews.llvm.org/D29303

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp

Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -1,3 +1,4 @@
+#include 
 //===- VirtualCallChecker.cpp *- C++ -*-==//
 //
 // The LLVM Compiler Infrastructure
@@ -44,7 +45,7 @@
   /// may result in unexpected behavior).
   bool ReportPureOnly = false;
 
-  typedef const CallExpr * WorkListUnit;
+  typedef const CallExpr *WorkListUnit;
   typedef SmallVector DFSWorkList;
 
   /// A vector representing the worklist which has a chain of CallExprs.
@@ -54,12 +55,13 @@
   // body has not been visited yet.
   // PostVisited : A CallExpr to this FunctionDecl is in the worklist, and the
   // body has been visited.
-  enum Kind { NotVisited,
-  PreVisited,  /**< A CallExpr to this FunctionDecl is in the
-worklist, but the body has not yet been
-visited. */
-  PostVisited  /**< A CallExpr to this FunctionDecl is in the
-worklist, and the body has been visited. */
+  enum Kind {
+NotVisited,
+PreVisited, /**< A CallExpr to this FunctionDecl is in the
+ worklist, but the body has not yet been
+ visited. */
+PostVisited /**< A CallExpr to this FunctionDecl is in the
+ worklist, and the body has been visited. */
   };
 
   /// A DenseMap that records visited states of FunctionDecls.
@@ -135,7 +137,6 @@
   void VisitChildren(Stmt *S);
 
   void ReportVirtualCall(const CallExpr *CE, bool isPure);
-
 };
 } // end anonymous namespace
 
@@ -179,7 +180,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() &&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());
@@ -208,8 +210,9 @@
   os << " <-- " << *visitingCallExpr->getDirectCallee();
 // Names of FunctionDecls in worklist with state PostVisited.
 for (SmallVectorImpl::iterator I = WList.end(),
- E = WList.begin(); I != E; --I) {
-  const FunctionDecl *FD = (*(I-1))->getDirectCallee();
+ E = WList.begin();
+ I != E; --I) {
+  const FunctionDecl *FD = (*(I - 1))->getDirectCallee();
   assert(FD);
   if (VisitedFunctions[FD] == PostVisited)
 os << " <-- " << *FD;
@@ -219,7 +222,7 @@
   }
 
   PathDiagnosticLocation CELoc =
-PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
+  PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
   SourceRange R = CE->getCallee()->getSourceRange();
 
   os << "Call to ";
@@ -249,12 +252,12 @@
 //===--===//
 
 namespace {
-class VirtualCallChecker : public Checker {
+class VirtualCallChecker : public Checker {
 public:
   DefaultBool isInterprocedural;
   DefaultBool isPureOnly;
 
-  void checkASTDecl(const CXXRecordDecl *RD, AnalysisManager& mgr,
+  void checkASTDecl(const CXXRecordDecl *RD, AnalysisManager ,
 BugReporter ) const {
 AnalysisDeclContext *ADC = mgr.getAnalysisDeclContext(RD);
 
@@ -281,11 +284,9 @@
 
 void ento::registerVirtualCallChecker(CheckerManager ) {
   VirtualCallChecker *checker = mgr.registerChecker();
-  checker->isInterprocedural =
-  mgr.getAnalyzerOptions().getBooleanOption("Interprocedural", false,
-checker);
+  checker->isInterprocedural = mgr.getAnalyzerOptions().getBooleanOption(
+  "Interprocedural", false, checker);
 
   checker->isPureOnly =
-  mgr.getAnalyzerOptions().getBooleanOption("PureOnly", false,
-checker);
+  mgr.getAnalyzerOptions().getBooleanOption("PureOnly", false, checker);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29291: [clang-format] Separate line comment sections after a right brace from comment sections in the scope.

2017-01-30 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Format/UnwrappedLineParser.cpp:2095
+  const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
+  {
+// Scan for '{//'. If found, use the column of '{' as a min column for line

Just remove this. It leaks PreviousToken, but that's ok.


https://reviews.llvm.org/D29291



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


[PATCH] D29300: [clang-format] Refactor WhitespaceManager and friends

2017-01-30 Thread Daniel Jasper via Phabricator via cfe-commits
djasper created this revision.

The main motivation behind this is to cleanup the WhitespaceManager and make it 
more extensible for future alignment etc. features. Specifically, 
WhitespaceManager has started to copy more and more code that is already 
present in FormatToken. Instead, I think it makes more sense to actually store 
a reference to each FormatToken for each change.

This has as a consequence led to a change in the calculation of indent levels. 
Now, we actually compute them for each Token ahead of time, which should be 
more efficient as it removes an unsigned value for the ParenState, which is 
used during the combinatorial exploration of the solution space.

No functional changes intended.


https://reviews.llvm.org/D29300

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  lib/Format/UnwrappedLineFormatter.h
  lib/Format/WhitespaceManager.cpp
  lib/Format/WhitespaceManager.h
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -497,6 +497,11 @@
"[];");
 
   verifyFormat("someFunction([], {a: a});");
+
+  verifyFormat("var string = [\n"
+   "  'aa',\n"
+   "  'bb',\n"
+   "].join('+');");
 }
 
 TEST_F(FormatTestJS, ColumnLayoutForArrayLiterals) {
@@ -587,6 +592,11 @@
"  doSomething();\n"
"}, this));");
 
+  verifyFormat("SomeFunction(function() {\n"
+   "  foo();\n"
+   "  bar();\n"
+   "}.bind(this));");
+
   // FIXME: This is bad, we should be wrapping before "function() {".
   verifyFormat("someFunction(function() {\n"
"  doSomething();  // break\n"
Index: lib/Format/WhitespaceManager.h
===
--- lib/Format/WhitespaceManager.h
+++ lib/Format/WhitespaceManager.h
@@ -43,8 +43,7 @@
 
   /// \brief Replaces the whitespace in front of \p Tok. Only call once for
   /// each \c AnnotatedToken.
-  void replaceWhitespace(FormatToken , unsigned Newlines,
- unsigned IndentLevel, unsigned Spaces,
+  void replaceWhitespace(FormatToken , unsigned Newlines, unsigned Spaces,
  unsigned StartOfTokenColumn,
  bool InPPDirective = false);
 
@@ -72,8 +71,7 @@
 unsigned ReplaceChars,
 StringRef PreviousPostfix,
 StringRef CurrentPrefix, bool InPPDirective,
-unsigned Newlines, unsigned IndentLevel,
-int Spaces);
+unsigned Newlines, int Spaces);
 
   /// \brief Returns all the \c Replacements created during formatting.
   const tooling::Replacements ();
@@ -91,8 +89,6 @@
   const SourceManager 
 };
 
-Change() {}
-
 /// \brief Creates a \c Change.
 ///
 /// The generated \c Change will replace the characters at
@@ -102,12 +98,18 @@
 ///
 /// \p StartOfTokenColumn and \p InPPDirective will be used to lay out
 /// trailing comments and escaped newlines.
-Change(bool CreateReplacement, SourceRange OriginalWhitespaceRange,
-   unsigned IndentLevel, int Spaces, unsigned StartOfTokenColumn,
-   unsigned NewlinesBefore, StringRef PreviousLinePostfix,
-   StringRef CurrentLinePrefix, tok::TokenKind Kind,
-   bool ContinuesPPDirective, bool IsStartOfDeclName,
-   bool IsInsideToken);
+Change(const FormatToken , bool CreateReplacement,
+   SourceRange OriginalWhitespaceRange, int Spaces,
+   unsigned StartOfTokenColumn, unsigned NewlinesBefore,
+   StringRef PreviousLinePostfix, StringRef CurrentLinePrefix,
+   bool ContinuesPPDirective, bool IsInsideToken);
+
+// The kind of the token whose whitespace this change replaces, or in which
+// this change inserts whitespace.
+// FIXME: Currently this is not set correctly for breaks inside comments, as
+// the \c BreakableToken is still doing its own alignment.
+const FormatToken *Tok;
+bool InToken;
 
 bool CreateReplacement;
 // Changes might be in the middle of a token, so we cannot just keep the
@@ -117,18 +119,7 @@
 unsigned NewlinesBefore;
 std::string PreviousLinePostfix;
 std::string CurrentLinePrefix;
-// The kind of the token whose whitespace this change replaces, or in which
-// this change inserts whitespace.
-// FIXME: Currently this is not set correctly for breaks inside comments, as
-// the \c BreakableToken is still doing its own alignment.
-tok::TokenKind 

[PATCH] D29291: [clang-format] Separate line comment sections after a right brace from comment sections in the scope.

2017-01-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 86316.
krasimir added a comment.

- Remove scope


https://reviews.llvm.org/D29291

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1783,6 +1783,64 @@
"0x00, 0x00, 0x00, 0x00};// comment\n");
 }
 
+TEST_F(FormatTest, LineCommentsAfterRightBrace) {
+  EXPECT_EQ("if (true) { // comment about branch\n"
+"  // comment about f\n"
+"  f();\n"
+"}",
+format("if (true) { // comment about branch\n"
+   "  // comment about f\n"
+   "  f();\n"
+   "}",
+   getLLVMStyleWithColumns(80)));
+  EXPECT_EQ("if (1) { // if line 1\n"
+" // if line 2\n"
+" // if line 3\n"
+"  // f line 1\n"
+"  // f line 2\n"
+"  f();\n"
+"} else { // else line 1\n"
+" // else line 2\n"
+" // else line 3\n"
+"  // g line 1\n"
+"  g();\n"
+"}",
+format("if (1) { // if line 1\n"
+   "  // if line 2\n"
+   "// if line 3\n"
+   "  // f line 1\n"
+   "// f line 2\n"
+   "  f();\n"
+   "} else { // else line 1\n"
+   "// else line 2\n"
+   " // else line 3\n"
+   "  // g line 1\n"
+   "  g();\n"
+   "}"));
+  EXPECT_EQ("do { // line 1\n"
+" // line 2\n"
+" // line 3\n"
+"  f();\n"
+"} while (true);",
+format("do { // line 1\n"
+   " // line 2\n"
+   "   // line 3\n"
+   "  f();\n"
+   "} while (true);",
+   getLLVMStyleWithColumns(80)));
+  EXPECT_EQ("while (a < b) { // line 1\n"
+"  // line 2\n"
+"  // line 3\n"
+"  f();\n"
+"}",
+format("while (a < b) {// line 1\n"
+   "  // line 2\n"
+   "  // line 3\n"
+   "  f();\n"
+   "}",
+   getLLVMStyleWithColumns(80)));
+}
+
 TEST_F(FormatTest, ReflowsComments) {
   // Break a long line and reflow with the full next line.
   EXPECT_EQ("// long long long\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2051,14 +2051,19 @@
  const UnwrappedLine ) {
   if (Line.Tokens.empty())
 return false;
-  const FormatToken  = *Line.Tokens.front().Tok;
+
   // If Line starts with a line comment, then FormatTok continues the comment
-  // section if its original column is greater or equal to the  original start
+  // section if its original column is greater or equal to the original start
   // column of the line.
   //
-  // If Line starts with a a different token, then FormatTok continues the
-  // comment section if its original column greater than the original start
-  // column of the line.
+  // Define the min column token of a line as follows: if a line ends in '{' or
+  // contains a '{' followed by a line comment, then the min column token is
+  // that '{'. Otherwise, the min column token of the line is the first token of
+  // the line.
+  //
+  // If Line starts with a token other than a line comment, then FormatTok
+  // continues the comment section if its original column is greater than the
+  // original start column of the min column token of the line.
   //
   // For example, the second line comment continues the first in these cases:
   // // first line
@@ -2069,16 +2074,43 @@
   // and:
   // int i; // first line
   //  // second line
+  // and:
+  // do { // first line
+  //  // second line
+  //   int i;
+  // } while (true);
   //
   // The second line comment doesn't continue the first in these cases:
   //   // first line
   //  // second line
   // and:
   // int i; // first line
   // // second line
+  // and:
+  // do { // first line
+  //   // second line
+  //   int i;
+  // } while (true);
+  const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
+
+  // Scan for '{//'. If found, use the column of '{' as a min column for line
+  // comment section continuation.
+  const FormatToken *PreviousToken = nullptr;
+  for (const UnwrappedLineNode Node : Line.Tokens) {
+if (PreviousToken && PreviousToken->is(tok::l_brace) &&
+isLineComment(*Node.Tok)) {
+  MinColumnToken = PreviousToken;
+  break;
+}
+PreviousToken = Node.Tok;

[PATCH] D28365: [Driver] Updated for Visual Studio 2017

2017-01-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: lib/Driver/MSVCToolChain.cpp:34
+  #if 0
+#define USE_VS_SETUP_CONFIG
+  #endif

hamzasood wrote:
> rnk wrote:
> > What are the outstanding issues preventing you from enabling this by 
> > default?
> Building on Win32 doesn't imply that you'll have the required header;  it 
> currently needs to be installed [[ 
> https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/
>  | separately ]] via nuget. While it would be possible to have cmake create a 
> packages.config file when configuring a visual studio project, the API is 
> only at the RC stage and so the distribution method could potentially change 
> between now and the Visual Studio 2017 release (even if that's not a concern, 
> it's probably out of the scope of this patch anyway).
> Although the code looks useless sitting there ifdefed out, it could be useful 
> for someone eager enough to get the package themselves and run a custom Clang 
> build.
> In the meantime, Visual Studio 2017 installations can only be detected when 
> running in the correct developer command prompt, or by putting one of its 
> toolchain's bin directories at the top of PATH.
This patch looks good, so I don't want to block it, but can you add something 
like:
 // FIXME: Use cmake to auto-detect if the necessary headers exist.
I'm assuming we should test for  eventually.


https://reviews.llvm.org/D28365



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


[PATCH] D16135: Macro Debug Info support in Clang

2017-01-30 Thread Michael Kuperstein via Phabricator via cfe-commits
mkuper resigned from this revision.
mkuper added a comment.

I admit it would be nice if someone reviewed this, but I'm really the wrong 
person for this code area. :-)


https://reviews.llvm.org/D16135



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


[PATCH] D24333: [CleanupInfo] Use cleanupsHaveSideEffects instead of exprNeedsCleanups in assertions

2017-01-30 Thread Tim Shen via Phabricator via cfe-commits
timshen updated this revision to Diff 86375.
timshen added a comment.

Fix in the right way as rsmith pointed out.


https://reviews.llvm.org/D24333

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/Sema/pr30306.cpp


Index: clang/test/Sema/pr30306.cpp
===
--- /dev/null
+++ clang/test/Sema/pr30306.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -emit-llvm < %s | FileCheck %s
+
+struct A { A(int); ~A(); };
+int f(const A &);
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+template void g() {
+  int a[f(3)];
+  int b[f(3)];
+}
+int main() { g(); }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4589,12 +4589,18 @@
   if (ElementType.isNull())
 return QualType();
 
-  ExprResult SizeResult
-= getDerived().TransformExpr(T->getSizeExpr());
-  if (SizeResult.isInvalid())
-return QualType();
-
-  Expr *Size = SizeResult.get();
+  Expr *Size;
+  {
+EnterExpressionEvaluationContext Context(SemaRef,
+ Sema::PotentiallyEvaluated);
+ExprResult SizeResult = getDerived().TransformExpr(T->getSizeExpr());
+if (SizeResult.isInvalid())
+  return QualType();
+SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
+if (SizeResult.isInvalid())
+  return QualType();
+Size = SizeResult.get();
+  }
 
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3858,6 +3858,8 @@
 if (Body.isInvalid())
   Function->setInvalidDecl();
 
+// FIXME: Exit expression evaluation context before finishing the function
+// body.
 ActOnFinishFunctionBody(Function, Body.get(),
 /*IsInstantiation=*/true);
 


Index: clang/test/Sema/pr30306.cpp
===
--- /dev/null
+++ clang/test/Sema/pr30306.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -emit-llvm < %s | FileCheck %s
+
+struct A { A(int); ~A(); };
+int f(const A &);
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+template void g() {
+  int a[f(3)];
+  int b[f(3)];
+}
+int main() { g(); }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4589,12 +4589,18 @@
   if (ElementType.isNull())
 return QualType();
 
-  ExprResult SizeResult
-= getDerived().TransformExpr(T->getSizeExpr());
-  if (SizeResult.isInvalid())
-return QualType();
-
-  Expr *Size = SizeResult.get();
+  Expr *Size;
+  {
+EnterExpressionEvaluationContext Context(SemaRef,
+ Sema::PotentiallyEvaluated);
+ExprResult SizeResult = getDerived().TransformExpr(T->getSizeExpr());
+if (SizeResult.isInvalid())
+  return QualType();
+SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
+if (SizeResult.isInvalid())
+  return QualType();
+Size = SizeResult.get();
+  }
 
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3858,6 +3858,8 @@
 if (Body.isInvalid())
   Function->setInvalidDecl();
 
+// FIXME: Exit expression evaluation context before finishing the function
+// body.
 ActOnFinishFunctionBody(Function, Body.get(),
 /*IsInstantiation=*/true);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21675: New ODR checker for modules

2017-01-30 Thread Richard Trieu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293585: Add better ODR checking for modules. (authored by 
rtrieu).

Changed prior to commit:
  https://reviews.llvm.org/D21675?vs=86142=86376#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D21675

Files:
  cfe/trunk/include/clang/AST/DeclCXX.h
  cfe/trunk/include/clang/AST/ODRHash.h
  cfe/trunk/include/clang/AST/Stmt.h
  cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
  cfe/trunk/lib/AST/CMakeLists.txt
  cfe/trunk/lib/AST/DeclCXX.cpp
  cfe/trunk/lib/AST/ODRHash.cpp
  cfe/trunk/lib/AST/StmtProfile.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/test/Modules/merge-using-decls.cpp
  cfe/trunk/test/Modules/odr_hash.cpp

Index: cfe/trunk/lib/AST/DeclCXX.cpp
===
--- cfe/trunk/lib/AST/DeclCXX.cpp
+++ cfe/trunk/lib/AST/DeclCXX.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/ODRHash.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "llvm/ADT/STLExtras.h"
@@ -71,8 +72,8 @@
   ImplicitCopyAssignmentHasConstParam(true),
   HasDeclaredCopyConstructorWithConstParam(false),
   HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false),
-  IsParsingBaseSpecifiers(false), NumBases(0), NumVBases(0), Bases(),
-  VBases(), Definition(D), FirstFriend() {}
+  IsParsingBaseSpecifiers(false), ODRHash(0), NumBases(0), NumVBases(0),
+  Bases(), VBases(), Definition(D), FirstFriend() {}
 
 CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const {
   return Bases.get(Definition->getASTContext().getExternalSource());
@@ -371,6 +372,16 @@
   data().IsParsingBaseSpecifiers = false;
 }
 
+void CXXRecordDecl::computeODRHash() {
+  if (!DefinitionData)
+return;
+
+  ODRHash Hash;
+  Hash.AddCXXRecordDecl(this);
+
+  DefinitionData->ODRHash = Hash.CalculateHash();
+}
+
 void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) {
   // C++11 [class.copy]p11:
   //   A defaulted copy/move constructor for a class X is defined as
Index: cfe/trunk/lib/AST/ODRHash.cpp
===
--- cfe/trunk/lib/AST/ODRHash.cpp
+++ cfe/trunk/lib/AST/ODRHash.cpp
@@ -0,0 +1,892 @@
+//===-- ODRHash.cpp - Hashing to diagnose ODR failures --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// This file implements the ODRHash class, which calculates a hash based
+/// on AST nodes, which is stable across different runs.
+///
+//===--===//
+
+#include "clang/AST/ODRHash.h"
+
+#include "clang/AST/DeclVisitor.h"
+#include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/StmtVisitor.h"
+#include "clang/AST/TypeVisitor.h"
+
+using namespace clang;
+
+// This method adds more information that AddDecl does.
+void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
+  assert(Record && Record->hasDefinition() &&
+ "Expected non-null record to be a definition.");
+  AddDecl(Record);
+
+  // Additional information that is not needed in AddDecl.  Do not move this
+  // to ODRTypeVisitor.
+  ID.AddInteger(Record->getNumBases());
+  for (auto base : Record->bases()) {
+AddBoolean(base.isVirtual());
+AddQualType(base.getType());
+  }
+
+  const ClassTemplateDecl *TD = Record->getDescribedClassTemplate();
+  AddBoolean(TD);
+  if (TD) {
+AddTemplateParameterList(TD->getTemplateParameters());
+  }
+}
+
+// Hashing for Stmt is with Stmt::Profile, since they derive from the same base
+// class.
+void ODRHash::AddStmt(const Stmt *S) {
+  assert(S && "Expecting non-null pointer.");
+  S->ProcessODRHash(ID, *this);
+}
+
+void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {
+  assert(II && "Expecting non-null pointer.");
+  ID.AddString(II->getName());
+}
+
+void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
+  assert(NNS && "Expecting non-null pointer.");
+  const auto *Prefix = NNS->getPrefix();
+  AddBoolean(Prefix);
+  if (Prefix) {
+AddNestedNameSpecifier(Prefix);
+  }
+
+  auto Kind = NNS->getKind();
+  ID.AddInteger(Kind);
+  switch (Kind) {
+  case NestedNameSpecifier::Identifier:
+AddIdentifierInfo(NNS->getAsIdentifier());
+break;
+  case NestedNameSpecifier::Namespace:
+AddDecl(NNS->getAsNamespace());
+break;
+  case NestedNameSpecifier::NamespaceAlias:
+AddDecl(NNS->getAsNamespaceAlias());
+break;
+  case 

[PATCH] D29304: [cmake] Hint find_package() to prefer LLVM installed alongside clang

2017-01-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rL LLVM

https://reviews.llvm.org/D29304



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


[PATCH] D24333: [CleanupInfo] Use cleanupsHaveSideEffects instead of exprNeedsCleanups in assertions

2017-01-30 Thread Tim Shen via Phabricator via cfe-commits
timshen updated this revision to Diff 86377.
timshen added a comment.

ActOnFinishFullExpr after exiting the expression evaluation context.


https://reviews.llvm.org/D24333

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/Sema/pr30306.cpp


Index: clang/test/Sema/pr30306.cpp
===
--- /dev/null
+++ clang/test/Sema/pr30306.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -emit-llvm < %s | FileCheck %s
+
+struct A { A(int); ~A(); };
+int f(const A &);
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+template void g() {
+  int a[f(3)];
+  int b[f(3)];
+}
+int main() { g(); }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4589,8 +4589,15 @@
   if (ElementType.isNull())
 return QualType();
 
-  ExprResult SizeResult
-= getDerived().TransformExpr(T->getSizeExpr());
+  ExprResult SizeResult;
+  {
+EnterExpressionEvaluationContext Context(SemaRef,
+ Sema::PotentiallyEvaluated);
+SizeResult = getDerived().TransformExpr(T->getSizeExpr());
+  }
+  if (SizeResult.isInvalid())
+return QualType();
+  SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
   if (SizeResult.isInvalid())
 return QualType();
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3858,6 +3858,8 @@
 if (Body.isInvalid())
   Function->setInvalidDecl();
 
+// FIXME: finishing the function body while in an expression evaluation
+// context seems wrong. Investigate more.
 ActOnFinishFunctionBody(Function, Body.get(),
 /*IsInstantiation=*/true);
 


Index: clang/test/Sema/pr30306.cpp
===
--- /dev/null
+++ clang/test/Sema/pr30306.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -emit-llvm < %s | FileCheck %s
+
+struct A { A(int); ~A(); };
+int f(const A &);
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+template void g() {
+  int a[f(3)];
+  int b[f(3)];
+}
+int main() { g(); }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4589,8 +4589,15 @@
   if (ElementType.isNull())
 return QualType();
 
-  ExprResult SizeResult
-= getDerived().TransformExpr(T->getSizeExpr());
+  ExprResult SizeResult;
+  {
+EnterExpressionEvaluationContext Context(SemaRef,
+ Sema::PotentiallyEvaluated);
+SizeResult = getDerived().TransformExpr(T->getSizeExpr());
+  }
+  if (SizeResult.isInvalid())
+return QualType();
+  SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
   if (SizeResult.isInvalid())
 return QualType();
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3858,6 +3858,8 @@
 if (Body.isInvalid())
   Function->setInvalidDecl();
 
+// FIXME: finishing the function body while in an expression evaluation
+// context seems wrong. Investigate more.
 ActOnFinishFunctionBody(Function, Body.get(),
 /*IsInstantiation=*/true);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24933: Enable configuration files in clang

2017-01-30 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added inline comments.



Comment at: lib/Driver/Driver.cpp:172
+NumConfigArgs = static_cast(NumCfgArgs);
+  }
+

sepavloff wrote:
> bruno wrote:
> > If `NumCfgArgs == 0` it would be nice to warn that the config file is empty?
> Not sure if it makes sense. Usually warning are used to attract attention to 
> the things that potentially may be harmful. An empty config file is strange 
> but does not look dangerous. 
I agree. The config files might be automatically generated by wrapper scripts, 
and adding special cases to avoid creating empty files seems like an 
unnecessary complication.



Comment at: lib/Driver/Driver.cpp:2695
 
+  // Clain all arguments that come from a configuration file so that the driver
+  // does not warn on any that are unused.

Clain -> Claim



Comment at: tools/driver/driver.cpp:332
+  StringRef PName = llvm::sys::path::stem(ProgramName);
+  size_t Pos = PName.find("-clang");
+  if (Pos == StringRef::npos)

Looking for "-clang" is too specific; our driver-name suffix processing allows 
more general naming than this. For one thing, it will not pick up armv7l-cpp 
correctly (which would be a problem because the config files likely contain 
options affecting preprocessing). I also have users which use symlinks to clang 
named fooclang.

I think that an easy way to do this is to use the result from 
ToolChain::getTargetAndModeFromProgramName, which we call from the caller of 
this function:

  std::string ProgName = argv[0];
  std::pair TargetAndMode =
  ToolChain::getTargetAndModeFromProgramName(ProgName);

We can use TargetAndMode.first here, instead of looking for the string before 
"-clang", and that should be consistent with the rest of our processing.



https://reviews.llvm.org/D24933



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


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293604: In VirtualCallChecker, handle indirect calls 
(authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D29303?vs=86342=86385#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29303

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  cfe/trunk/test/Analysis/virtualcall.cpp


Index: cfe/trunk/test/Analysis/virtualcall.cpp
===
--- cfe/trunk/test/Analysis/virtualcall.cpp
+++ cfe/trunk/test/Analysis/virtualcall.cpp
@@ -115,12 +115,23 @@
   int foo() override;
 };
 
+// Regression test: don't crash when there's no direct callee.
+class F {
+public:
+  F() {
+void (F::* ptr)() = ::foo;
+(this->*ptr)();
+  }
+  void foo();
+};
+
 int main() {
   A *a;
   B *b;
   C *c;
   D *d;
   E *e;
+  F *f;
 }
 
 #include "virtualcall.h"
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() 
&&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());


Index: cfe/trunk/test/Analysis/virtualcall.cpp
===
--- cfe/trunk/test/Analysis/virtualcall.cpp
+++ cfe/trunk/test/Analysis/virtualcall.cpp
@@ -115,12 +115,23 @@
   int foo() override;
 };
 
+// Regression test: don't crash when there's no direct callee.
+class F {
+public:
+  F() {
+void (F::* ptr)() = ::foo;
+(this->*ptr)();
+  }
+  void foo();
+};
+
 int main() {
   A *a;
   B *b;
   C *c;
   D *d;
   E *e;
+  F *f;
 }
 
 #include "virtualcall.h"
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() &&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29234: [ubsan] Sanity-check shift amounts before truncation (fixes PR27271)

2017-01-27 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293343: [ubsan] Sanity-check shift amounts before truncation 
(fixes PR27271) (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D29234?vs=86130=86134#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29234

Files:
  cfe/trunk/lib/CodeGen/CGExprScalar.cpp
  cfe/trunk/test/CodeGen/ubsan-shift.c


Index: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
===
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp
@@ -2751,8 +2751,8 @@
isa(Ops.LHS->getType())) {
 CodeGenFunction::SanitizerScope SanScope();
 SmallVector Checks;
-llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
-llvm::Value *ValidExponent = Builder.CreateICmpULE(RHS, WidthMinusOne);
+llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
+llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS, WidthMinusOne);
 
 if (SanitizeExponent) {
   Checks.push_back(
Index: cfe/trunk/test/CodeGen/ubsan-shift.c
===
--- cfe/trunk/test/CodeGen/ubsan-shift.c
+++ cfe/trunk/test/CodeGen/ubsan-shift.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsanitize=shift-exponent 
-emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: define i32 @f1
+int f1(int c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f2
+int f2(long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f3
+unsigned f3(unsigned c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f4
+unsigned f4(unsigned long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}


Index: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
===
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp
@@ -2751,8 +2751,8 @@
isa(Ops.LHS->getType())) {
 CodeGenFunction::SanitizerScope SanScope();
 SmallVector Checks;
-llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
-llvm::Value *ValidExponent = Builder.CreateICmpULE(RHS, WidthMinusOne);
+llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
+llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS, WidthMinusOne);
 
 if (SanitizeExponent) {
   Checks.push_back(
Index: cfe/trunk/test/CodeGen/ubsan-shift.c
===
--- cfe/trunk/test/CodeGen/ubsan-shift.c
+++ cfe/trunk/test/CodeGen/ubsan-shift.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsanitize=shift-exponent -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: define i32 @f1
+int f1(int c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f2
+int f2(long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f3
+unsigned f3(unsigned c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f4
+unsigned f4(unsigned long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29233: Fix linkage of static locals in available_externally functions to be DiscardableODR/linkonce_odr

2017-01-27 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini accepted this revision.
mehdi_amini added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: lib/AST/ASTContext.cpp:8909
+
+// Itanium ABI (& MSVC seems to do similarly) requires static locals in
+// inline functions to be emitted anywhere they're needed, even if the

I assume you looked it up, do you have a ref? (Citation or pointer to right 
section/paragraph).


https://reviews.llvm.org/D29233



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


[PATCH] D29233: Fix linkage of static locals in available_externally functions to be DiscardableODR/linkonce_odr

2017-01-27 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 86137.
dblaikie added a comment.

Improve comment/mention Itanium ABI


https://reviews.llvm.org/D29233

Files:
  lib/AST/ASTContext.cpp
  test/CodeGenCXX/explicit-instantiation.cpp


Index: test/CodeGenCXX/explicit-instantiation.cpp
===
--- test/CodeGenCXX/explicit-instantiation.cpp
+++ test/CodeGenCXX/explicit-instantiation.cpp
@@ -5,6 +5,9 @@
 // This check logically is attached to 'template int S::i;' below.
 // CHECK: @_ZN1SIiE1iE = weak_odr global i32
 
+// This check is logically attached to 'template int 
ExportedStaticLocal::f()' below.
+// CHECK-OPT: @_ZZN19ExportedStaticLocal1fIiEEvvE1i = linkonce_odr global
+
 template
 struct plus {
   Result operator()(const T& t, const U& u) const;
@@ -153,3 +156,17 @@
 template  void S::g() {}
 template  int S::i;
 template  void S::S2::h() {}
+
+namespace ExportedStaticLocal {
+void sink(int&);
+template 
+inline void f() {
+  static int i;
+  sink(i);
+}
+// See the check line at the top of the file.
+extern template void f();
+void use() {
+  f();
+}
+}
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8892,22 +8892,30 @@
 return GVA_Internal;
 
   if (VD->isStaticLocal()) {
-GVALinkage StaticLocalLinkage = GVA_DiscardableODR;
 const DeclContext *LexicalContext = VD->getParentFunctionOrMethod();
 while (LexicalContext && !isa(LexicalContext))
   LexicalContext = LexicalContext->getLexicalParent();
 
-// Let the static local variable inherit its linkage from the nearest
-// enclosing function.
-if (LexicalContext)
-  StaticLocalLinkage =
-  Context.GetGVALinkageForFunction(cast(LexicalContext));
-
-// GVA_StrongODR function linkage is stronger than what we need,
-// downgrade to GVA_DiscardableODR.
-// This allows us to discard the variable if we never end up needing it.
-return StaticLocalLinkage == GVA_StrongODR ? GVA_DiscardableODR
-   : StaticLocalLinkage;
+// ObjC Blocks can create local variables that don't have a FunctionDecl
+// LexicalContext.
+if (!LexicalContext)
+  return GVA_DiscardableODR;
+
+// Otherwise, let the static local variable inherit its linkage from the
+// nearest enclosing function.
+auto StaticLocalLinkage =
+Context.GetGVALinkageForFunction(cast(LexicalContext));
+
+// Itanium ABI 5.2.2: "Each COMDAT group [for a static local variable] must
+// be emitted in any object with references to the symbol for the object it
+// contains, whether inline or out-of-line."
+// Similar behavior is observed with MSVC. An alternative ABI could use
+// StrongODR/AvailableExternally to match the function, but none are
+// known/supported currently.
+if (StaticLocalLinkage == GVA_StrongODR ||
+StaticLocalLinkage == GVA_AvailableExternally)
+  return GVA_DiscardableODR;
+return StaticLocalLinkage;
   }
 
   // MSVC treats in-class initialized static data members as definitions.


Index: test/CodeGenCXX/explicit-instantiation.cpp
===
--- test/CodeGenCXX/explicit-instantiation.cpp
+++ test/CodeGenCXX/explicit-instantiation.cpp
@@ -5,6 +5,9 @@
 // This check logically is attached to 'template int S::i;' below.
 // CHECK: @_ZN1SIiE1iE = weak_odr global i32
 
+// This check is logically attached to 'template int ExportedStaticLocal::f()' below.
+// CHECK-OPT: @_ZZN19ExportedStaticLocal1fIiEEvvE1i = linkonce_odr global
+
 template
 struct plus {
   Result operator()(const T& t, const U& u) const;
@@ -153,3 +156,17 @@
 template  void S::g() {}
 template  int S::i;
 template  void S::S2::h() {}
+
+namespace ExportedStaticLocal {
+void sink(int&);
+template 
+inline void f() {
+  static int i;
+  sink(i);
+}
+// See the check line at the top of the file.
+extern template void f();
+void use() {
+  f();
+}
+}
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8892,22 +8892,30 @@
 return GVA_Internal;
 
   if (VD->isStaticLocal()) {
-GVALinkage StaticLocalLinkage = GVA_DiscardableODR;
 const DeclContext *LexicalContext = VD->getParentFunctionOrMethod();
 while (LexicalContext && !isa(LexicalContext))
   LexicalContext = LexicalContext->getLexicalParent();
 
-// Let the static local variable inherit its linkage from the nearest
-// enclosing function.
-if (LexicalContext)
-  StaticLocalLinkage =
-  Context.GetGVALinkageForFunction(cast(LexicalContext));
-
-// GVA_StrongODR function linkage is stronger than what we need,
-// downgrade to GVA_DiscardableODR.
-// This allows us to discard the variable if we never end up needing it.
-return 

[PATCH] D29233: Fix linkage of static locals in available_externally functions to be DiscardableODR/linkonce_odr

2017-01-27 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293344: Fix linkage of static locals in available_externally 
functions to be… (authored by dblaikie).

Changed prior to commit:
  https://reviews.llvm.org/D29233?vs=86137=86138#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29233

Files:
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp


Index: cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp
===
--- cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp
+++ cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp
@@ -5,6 +5,9 @@
 // This check logically is attached to 'template int S::i;' below.
 // CHECK: @_ZN1SIiE1iE = weak_odr global i32
 
+// This check is logically attached to 'template int 
ExportedStaticLocal::f()' below.
+// CHECK-OPT: @_ZZN19ExportedStaticLocal1fIiEEvvE1i = linkonce_odr global
+
 template
 struct plus {
   Result operator()(const T& t, const U& u) const;
@@ -153,3 +156,17 @@
 template  void S::g() {}
 template  int S::i;
 template  void S::S2::h() {}
+
+namespace ExportedStaticLocal {
+void sink(int&);
+template 
+inline void f() {
+  static int i;
+  sink(i);
+}
+// See the check line at the top of the file.
+extern template void f();
+void use() {
+  f();
+}
+}
Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -8892,22 +8892,30 @@
 return GVA_Internal;
 
   if (VD->isStaticLocal()) {
-GVALinkage StaticLocalLinkage = GVA_DiscardableODR;
 const DeclContext *LexicalContext = VD->getParentFunctionOrMethod();
 while (LexicalContext && !isa(LexicalContext))
   LexicalContext = LexicalContext->getLexicalParent();
 
-// Let the static local variable inherit its linkage from the nearest
-// enclosing function.
-if (LexicalContext)
-  StaticLocalLinkage =
-  Context.GetGVALinkageForFunction(cast(LexicalContext));
-
-// GVA_StrongODR function linkage is stronger than what we need,
-// downgrade to GVA_DiscardableODR.
-// This allows us to discard the variable if we never end up needing it.
-return StaticLocalLinkage == GVA_StrongODR ? GVA_DiscardableODR
-   : StaticLocalLinkage;
+// ObjC Blocks can create local variables that don't have a FunctionDecl
+// LexicalContext.
+if (!LexicalContext)
+  return GVA_DiscardableODR;
+
+// Otherwise, let the static local variable inherit its linkage from the
+// nearest enclosing function.
+auto StaticLocalLinkage =
+Context.GetGVALinkageForFunction(cast(LexicalContext));
+
+// Itanium ABI 5.2.2: "Each COMDAT group [for a static local variable] must
+// be emitted in any object with references to the symbol for the object it
+// contains, whether inline or out-of-line."
+// Similar behavior is observed with MSVC. An alternative ABI could use
+// StrongODR/AvailableExternally to match the function, but none are
+// known/supported currently.
+if (StaticLocalLinkage == GVA_StrongODR ||
+StaticLocalLinkage == GVA_AvailableExternally)
+  return GVA_DiscardableODR;
+return StaticLocalLinkage;
   }
 
   // MSVC treats in-class initialized static data members as definitions.


Index: cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp
===
--- cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp
+++ cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp
@@ -5,6 +5,9 @@
 // This check logically is attached to 'template int S::i;' below.
 // CHECK: @_ZN1SIiE1iE = weak_odr global i32
 
+// This check is logically attached to 'template int ExportedStaticLocal::f()' below.
+// CHECK-OPT: @_ZZN19ExportedStaticLocal1fIiEEvvE1i = linkonce_odr global
+
 template
 struct plus {
   Result operator()(const T& t, const U& u) const;
@@ -153,3 +156,17 @@
 template  void S::g() {}
 template  int S::i;
 template  void S::S2::h() {}
+
+namespace ExportedStaticLocal {
+void sink(int&);
+template 
+inline void f() {
+  static int i;
+  sink(i);
+}
+// See the check line at the top of the file.
+extern template void f();
+void use() {
+  f();
+}
+}
Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -8892,22 +8892,30 @@
 return GVA_Internal;
 
   if (VD->isStaticLocal()) {
-GVALinkage StaticLocalLinkage = GVA_DiscardableODR;
 const DeclContext *LexicalContext = VD->getParentFunctionOrMethod();
 while (LexicalContext && !isa(LexicalContext))
   LexicalContext = LexicalContext->getLexicalParent();
 
-// Let the static local variable inherit its linkage from the nearest
-// enclosing function.
-

[PATCH] D28845: Prototype of modules codegen

2017-01-27 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 86140.
dblaikie added a comment.

- More test coverage (for local static variables)


https://reviews.llvm.org/D28845

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/ExternalASTSource.h
  include/clang/Basic/LangOptions.def
  include/clang/Basic/Module.h
  include/clang/Driver/CC1Options.td
  include/clang/Serialization/ASTBitCodes.h
  include/clang/Serialization/ASTReader.h
  include/clang/Serialization/ASTWriter.h
  lib/AST/ASTContext.cpp
  lib/AST/ExternalASTSource.cpp
  lib/Basic/Module.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/ModuleMap.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/Modules/Inputs/codegen/bar.h
  test/Modules/Inputs/codegen/bar.modulemap
  test/Modules/Inputs/codegen/foo.h
  test/Modules/Inputs/codegen/foo.modulemap
  test/Modules/Inputs/codegen/use.cpp
  test/Modules/codegen.test

Index: test/Modules/codegen.test
===
--- /dev/null
+++ test/Modules/codegen.test
@@ -0,0 +1,64 @@
+RUN: rm -rf %t
+
+RUN: %clang_cc1 -fmodule-codegen -x c++ -fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen/foo.modulemap -o %t/foo.pcm
+RUN: %clang_cc1 -fmodule-codegen -x c++ -fmodules -emit-module -fmodule-name=bar %S/Inputs/codegen/bar.modulemap -o %t/bar.pcm -fmodule-file=%t/foo.pcm
+
+RUN: %clang_cc1 -emit-llvm %t/foo.pcm -o - | FileCheck --check-prefix=FOO %s
+RUN: %clang_cc1 -emit-llvm %t/bar.pcm -o - -fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-prefix=BAR %s
+RUN: %clang_cc1 -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-llvm -o - | FileCheck --check-prefix=USE-CMN --check-prefix=USE %s
+
+RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/foo.pcm -o - | FileCheck --check-prefix=FOO %s
+RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/bar.pcm -o - -fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-prefix=BAR-OPT %s
+RUN: %clang_cc1 -O2 -disable-llvm-passes -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-llvm -o - | FileCheck --check-prefix=USE-CMN --check-prefix=USE-OPT %s
+
+FOO-NOT: comdat
+FOO: $_Z3foov = comdat any
+FOO: $_Z4foo2v = comdat any
+FOO: $_ZZ3foovE1i = comdat any
+FOO: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat
+FOO-NOT: {{comdat|define|declare}}
+FOO: define void @_Z7foo_extv()
+FOO-NOT: {{define|declare}}
+FOO: define weak_odr void @_Z3foov() #{{[0-9]+}} comdat
+FOO-NOT: {{define|declare}}
+FOO: declare void @_Z2f1Ri(i32*
+FOO-NOT: {{define|declare}}
+
+FIXME: this internal function should be weak_odr, comdat, and with a new mangling
+FOO: define internal void @_ZL2f2v() #{{[0-9]+}}
+FOO-NOT: {{define|declare}}
+
+FOO: define weak_odr void @_Z4foo2v() #{{[0-9]+}} comdat
+FOO-NOT: {{define|declare}}
+
+
+BAR-CMN-NOT: comdat
+BAR-CMN: $_Z3barv = comdat any
+BAR-OPT: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat
+BAR-CMN-NOT: {{comdat|define|declare}}
+BAR-CMN: define weak_odr void @_Z3barv() #{{[0-9]+}} comdat
+BAR-CMN-NOT: {{define|declare}}
+BAR: declare void @_Z3foov()
+Include all the available_externally definitions required for bar (foo -> f2)
+BAR-OPT: define available_externally void @_Z3foov()
+BAR-CMN-NOT: {{define|declare}}
+BAR-OPT: declare void @_Z2f1Ri(i32*
+BAR-OPT-NOT: {{define|declare}}
+BAR-OPT: define available_externally void @_ZL2f2v()
+BAR-OPT-NOT: {{define|declare}}
+
+
+USE-OPT: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat
+USE-CMN-NOT: {{comdat|define|declare}}
+USE-CMN: define i32 @main()
+USE-CMN-NOT: {{define|declare}}
+USE: declare void @_Z3barv()
+Include all the available_externally definitions required for main (bar -> foo -> f2)
+USE-OPT: define available_externally void @_Z3barv()
+USE-CMN-NOT: {{define|declare}}
+USE-OPT: define available_externally void @_Z3foov()
+USE-OPT-NOT: {{define|declare}}
+USE-OPT: declare void @_Z2f1Ri(i32*
+USE-OPT-NOT: {{define|declare}}
+USE-OPT: define available_externally void @_ZL2f2v()
+USE-OPT-NOT: {{define|declare}}
Index: test/Modules/Inputs/codegen/use.cpp
===
--- /dev/null
+++ test/Modules/Inputs/codegen/use.cpp
@@ -0,0 +1,2 @@
+#include "bar.h"
+int main() { bar(); }
Index: test/Modules/Inputs/codegen/foo.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/codegen/foo.modulemap
@@ -0,0 +1 @@
+module foo { header "foo.h" }
Index: test/Modules/Inputs/codegen/foo.h
===
--- /dev/null
+++ test/Modules/Inputs/codegen/foo.h
@@ -0,0 +1,10 @@
+void f1(int&);
+static void f2() { }
+inline void foo() {
+  static int i;
+  f1(i);
+  f2();
+}
+inline void foo2() {
+}
+void foo_ext() {}
Index: test/Modules/Inputs/codegen/bar.modulemap

[PATCH] D21675: New ODR checker for modules

2017-01-27 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu updated this revision to Diff 86142.
rtrieu added a comment.

Changes made to the ODR hash algorithm:

Separated Decl and Type pointers into their own DenseMap's.
Removed the queue of pointers to process at the end.  Instead, process pointers 
at first use.
Save Boolean values and add them together at the end to reduce bits wasted.  
Shrinks data from bools 32x.

With these changes, the overhead is now 1-1.5%


https://reviews.llvm.org/D21675

Files:
  include/clang/AST/DeclCXX.h
  include/clang/AST/ODRHash.h
  include/clang/AST/Stmt.h
  include/clang/Basic/DiagnosticSerializationKinds.td
  lib/AST/CMakeLists.txt
  lib/AST/DeclCXX.cpp
  lib/AST/ODRHash.cpp
  lib/AST/StmtProfile.cpp
  lib/Sema/SemaDecl.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  test/Modules/merge-using-decls.cpp
  test/Modules/odr_hash.cpp

Index: test/Modules/odr_hash.cpp
===
--- test/Modules/odr_hash.cpp
+++ test/Modules/odr_hash.cpp
@@ -0,0 +1,1077 @@
+// Clear and create directories
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: mkdir %t/cache
+// RUN: mkdir %t/Inputs
+
+// Build first header file
+// RUN: echo "#define FIRST" >> %t/Inputs/first.h
+// RUN: cat %s   >> %t/Inputs/first.h
+
+// Build second header file
+// RUN: echo "#define SECOND" >> %t/Inputs/second.h
+// RUN: cat %s>> %t/Inputs/second.h
+
+// Build module map file
+// RUN: echo "module first {"   >> %t/Inputs/module.map
+// RUN: echo "header \"first.h\""   >> %t/Inputs/module.map
+// RUN: echo "}">> %t/Inputs/module.map
+// RUN: echo "module second {"  >> %t/Inputs/module.map
+// RUN: echo "header \"second.h\""  >> %t/Inputs/module.map
+// RUN: echo "}">> %t/Inputs/module.map
+
+// Run test
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++11
+
+#if !defined(FIRST) && !defined(SECOND)
+#include "first.h"
+#include "second.h"
+#endif
+
+#if defined(FIRST)
+struct S1 {
+  public:
+};
+#elif defined(SECOND)
+struct S1 {
+  private:
+};
+#else
+S1 s1;
+// expected-error@first.h:* {{'S1' has different definitions in different modules; first difference is definition in module 'first' found public access specifier}}
+// expected-note@second.h:* {{but in 'second' found private access specifier}}
+#endif
+
+#if defined(FIRST)
+struct S2Friend2 {};
+struct S2 {
+  friend S2Friend2;
+};
+#elif defined(SECOND)
+struct S2Friend1 {};
+struct S2 {
+  friend S2Friend1;
+};
+#else
+S2 s2;
+// expected-error@first.h:* {{'S2' has different definitions in different modules; first difference is definition in module 'first' found friend 'S2Friend2'}}
+// expected-note@second.h:* {{but in 'second' found other friend 'S2Friend1'}}
+#endif
+
+#if defined(FIRST)
+template
+struct S3Template {};
+struct S3 {
+  friend S3Template;
+};
+#elif defined(SECOND)
+template
+struct S3Template {};
+struct S3 {
+  friend S3Template;
+};
+#else
+S3 s3;
+// expected-error@first.h:* {{'S3' has different definitions in different modules; first difference is definition in module 'first' found friend 'S3Template'}}
+// expected-note@second.h:* {{but in 'second' found other friend 'S3Template'}}
+#endif
+
+#if defined(FIRST)
+struct S4 {
+  static_assert(1 == 1, "First");
+};
+#elif defined(SECOND)
+struct S4 {
+  static_assert(1 == 1, "Second");
+};
+#else
+S4 s4;
+// expected-error@first.h:* {{'S4' has different definitions in different modules; first difference is definition in module 'first' found static assert with message}}
+// expected-note@second.h:* {{but in 'second' found static assert with different message}}
+#endif
+
+#if defined(FIRST)
+struct S5 {
+  static_assert(1 == 1, "Message");
+};
+#elif defined(SECOND)
+struct S5 {
+  static_assert(2 == 2, "Message");
+};
+#else
+S5 s5;
+// expected-error@first.h:* {{'S5' has different definitions in different modules; first difference is definition in module 'first' found static assert with condition}}
+// expected-note@second.h:* {{but in 'second' found static assert with different condition}}
+#endif
+
+#if defined(FIRST)
+struct S6 {
+  int First();
+};
+#elif defined(SECOND)
+struct S6 {
+  int Second();
+};
+#else
+S6 s6;
+// expected-error@second.h:* {{'S6::Second' from module 'second' is not present in definition of 'S6' in module 'first'}}
+// expected-note@first.h:* {{definition has no member 'Second'}}
+#endif
+
+#if defined(FIRST)
+struct S7 {
+  double foo();
+};
+#elif defined(SECOND)
+struct S7 {
+  int foo();
+};
+#else
+S7 s7;
+// expected-error@second.h:* {{'S7::foo' from module 'second' is not present in definition of 'S7' in module 'first'}}
+// expected-note@first.h:* {{declaration of 'foo' does not match}}
+#endif
+
+#if defined(FIRST)
+struct S8 {
+  void foo();
+};
+#elif defined(SECOND)
+struct S8 {
+  void foo() {}
+};
+#else

[PATCH] D28845: Prototype of modules codegen

2017-01-27 Thread Richard Smith via Phabricator via cfe-commits
rsmith added a comment.






Comment at: include/clang/AST/ASTContext.h:2490
   /// it is not used.
-  bool DeclMustBeEmitted(const Decl *D);
+  bool DeclMustBeEmitted(const Decl *D, bool WritingModule = false);
 

I think the name of this flag might be out of sync with its meaning; it looks 
like it means "must this declaration be emitted when performing modular 
codegen?"



Comment at: include/clang/Basic/Module.h:208
 
+  unsigned WithCodegen : 2;
+

Does this need to be two bits wide? Seems to only store true/false.



Comment at: include/clang/Driver/CC1Options.td:435-438
+def fmodule_codegen :
+  Flag<["-"], "fmodule-codegen">,
+  HelpText<"Generate code for uses of this module that assumes an explicit "
+   "object file will be built for the module">;

Maybe `module` -> `modules`, to match the other `-fmodules-*` flags controlling 
various options.



Comment at: lib/AST/ASTContext.cpp:9020-9023
+  if (auto *Ext = getExternalSource())
+if (Ext->hasExternalDefinitions(FD->getOwningModuleID()) ==
+ExternalASTSource::EK_Never)
+  return true;

I think this `return true` is unreachable and can be deleted: if we get here 
with `Linkage == GVA_DiscardableODR`, then the call to `hasExternalDefinitions` 
in `GetGVALinkageForFunction` must have returned `EK_ReplyHazy`. (In the case 
this is checking for, `GetGVALinkageForFunction` would return `GVA_StrongODR`, 
so the check below will return `true` anyway.)



Comment at: lib/AST/ASTContext.cpp:9029
 // Implicit template instantiations can also be deferred in C++.
 return !isDiscardableGVALinkage(GetGVALinkageForFunction(FD));
   }

Pass `Linkage` in here instead of recomputing it



Comment at: lib/AST/ExternalASTSource.cpp:33
+ExternalASTSource::hasExternalDefinitions(unsigned ID) {
+  return EK_ReplyHazy;
+}

You should add support for this function to 
`clang::MultiplexExternalSemaSource` too.



Comment at: lib/Serialization/ASTWriterDecl.cpp:2215-2219
+  if (isRequiredDecl(D, Context, WritingModule, false))
 EagerlyDeserializedDecls.push_back(ID);
+  else if (Context.getLangOpts().ModularCodegen && WritingModule &&
+   isRequiredDecl(D, Context, true, true))
+ModularCodegenDecls.push_back(ID);

I suspect we'll want to seriously prune back the contents of 
`EagerlyDeserializedDecls` for the modular codegen case at some point, but we 
don't need to do that in this change.


https://reviews.llvm.org/D28845



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


[PATCH] D28889: Change where we handle arg-dependent diagnose_if attributes

2017-01-27 Thread Richard Smith via Phabricator via cfe-commits
rsmith added a comment.

Another "fun" testcase:

  struct S {
void operator++(int n) _diagnose_if(n, "wat", "warning");
  };
  void f(S s) {
s++; // no warning
s.operator++(1); // warning
  }




Comment at: include/clang/Sema/Sema.h:2638
 
-  /// Check the diagnose_if attributes on the given function. Returns the
-  /// first succesful fatal attribute, or null if calling Function(Args) isn't
-  /// an error.
+  /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any
+  /// non-ArgDependent DiagnoseIfAttrs.

Can you add a comment somewhere about here explaining why these functions are 
split? Something like "Argument-dependent diagnose_if attributes are checked 
when the function is used as a direct callee of a function call." here, and 
"Argument-independent diagnose_if attributes are checked on every use of the 
function." below.



Comment at: include/clang/Sema/Sema.h:9925
  SourceLocation Loc, SourceRange Range,
- VariadicCallType CallType);
+ VariadicCallType CallType, const Expr *ThisArg);
 

We have a loose convention that function parameter argument order matches 
source order, which would suggest that `ThisArg` should precede `Args` here.



Comment at: lib/Sema/SemaExprCXX.cpp:6717
+
+  checkDiagnoseIfAttrsOnCall(Method, CE);
   return CE;

Can you call  `CheckFunctionCall` instead here, and remove 
`checkDiagnoseIfAttrsOnCall`? It looks like the only reason we don't already 
call that is because none of its checks could ever fire for a call to a 
conversion function before, and that's no longer true.



Comment at: lib/Sema/SemaOverload.cpp:12035
 
+  checkDiagnoseIfAttrsOnCall(FnDecl, TheCall);
   return MaybeBindToTemporary(TheCall);

Likewise call `CheckFunctionCall` here.



Comment at: lib/Sema/SemaOverload.cpp:12488
 
+checkDiagnoseIfAttrsOnCall(Method, TheCall);
 return MaybeBindToTemporary(TheCall);

... and here.



Comment at: lib/Sema/SemaOverload.cpp:13228
 
+  checkDiagnoseIfAttrsOnCall(Method, TheCall);
   return MaybeBindToTemporary(TheCall);

... and here.



Comment at: test/SemaCXX/diagnose_if.cpp:614
+// FIXME: This should emit diagnostics. It seems that our constexpr
+// evaluator isn't able to evaluate `adl::Foo(1)` to a constexpr, though.
+// I'm assuming this is because we assign it to a temporary.

`constexpr` is an adjective; "to a constant" might make more sense.



Comment at: test/SemaCXX/diagnose_if.cpp:615
+// evaluator isn't able to evaluate `adl::Foo(1)` to a constexpr, though.
+// I'm assuming this is because we assign it to a temporary.
+for (void *p : adl::Foo(1)) {}

The range-based for is desugared to

```
auto &&__range = adl::Foo(1);
auto __begin = begin(__range);
auto __end = end(__range);
// ...
```

so the argument in the call to `begin` is not considered constant.


https://reviews.llvm.org/D28889



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


[PATCH] D26345: Extend small data threshold driver options to PPC target

2017-01-27 Thread Richard Smith via Phabricator via cfe-commits
rsmith added a comment.

LGTM


https://reviews.llvm.org/D26345



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


[PATCH] D29233: Fix linkage of static locals in available_externally functions to be DiscardableODR/linkonce_odr

2017-01-27 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.

As Mehdi put it, entities should either be
available_externally+weak_odr, or linkonce_odr+linkonce_odr. While some
functions are emitted a_e/weak, their local variables were emitted
a_e/linkonce_odr.

While it might be nice to emit them a_e/weak, the Itanium ABI (& best
guess at MSVC's behavior as well) requires the local to be
linkonce/linkonce.


https://reviews.llvm.org/D29233

Files:
  lib/AST/ASTContext.cpp
  test/CodeGenCXX/explicit-instantiation.cpp


Index: test/CodeGenCXX/explicit-instantiation.cpp
===
--- test/CodeGenCXX/explicit-instantiation.cpp
+++ test/CodeGenCXX/explicit-instantiation.cpp
@@ -5,6 +5,9 @@
 // This check logically is attached to 'template int S::i;' below.
 // CHECK: @_ZN1SIiE1iE = weak_odr global i32
 
+// This check is logically attached to 'template int 
ExportedStaticLocal::f()' below.
+// CHECK-OPT: @_ZZN19ExportedStaticLocal1fIiEEvvE1i = linkonce_odr global
+
 template
 struct plus {
   Result operator()(const T& t, const U& u) const;
@@ -153,3 +156,17 @@
 template  void S::g() {}
 template  int S::i;
 template  void S::S2::h() {}
+
+namespace ExportedStaticLocal {
+void sink(int&);
+template 
+inline void f() {
+  static int i;
+  sink(i);
+}
+// See the check line at the top of the file.
+extern template void f();
+void use() {
+  f();
+}
+}
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8892,22 +8892,27 @@
 return GVA_Internal;
 
   if (VD->isStaticLocal()) {
-GVALinkage StaticLocalLinkage = GVA_DiscardableODR;
 const DeclContext *LexicalContext = VD->getParentFunctionOrMethod();
 while (LexicalContext && !isa(LexicalContext))
   LexicalContext = LexicalContext->getLexicalParent();
 
-// Let the static local variable inherit its linkage from the nearest
-// enclosing function.
-if (LexicalContext)
-  StaticLocalLinkage =
-  Context.GetGVALinkageForFunction(cast(LexicalContext));
-
-// GVA_StrongODR function linkage is stronger than what we need,
-// downgrade to GVA_DiscardableODR.
-// This allows us to discard the variable if we never end up needing it.
-return StaticLocalLinkage == GVA_StrongODR ? GVA_DiscardableODR
-   : StaticLocalLinkage;
+// ObjC Blocks can create local variables that don't have a FunctionDecl
+// LexicalContext.
+if (!LexicalContext)
+  return GVA_DiscardableODR;
+
+// Otherwise, let the static local variable inherit its linkage from the
+// nearest enclosing function.
+auto StaticLocalLinkage =
+Context.GetGVALinkageForFunction(cast(LexicalContext));
+
+// Itanium ABI (& MSVC seems to do similarly) requires static locals in
+// inline functions to be emitted anywhere they're needed, even if the
+// function they are local to is emitted StrongODR/AvailableExternally.
+if (StaticLocalLinkage == GVA_StrongODR ||
+StaticLocalLinkage == GVA_AvailableExternally)
+  return GVA_DiscardableODR;
+return StaticLocalLinkage;
   }
 
   // MSVC treats in-class initialized static data members as definitions.


Index: test/CodeGenCXX/explicit-instantiation.cpp
===
--- test/CodeGenCXX/explicit-instantiation.cpp
+++ test/CodeGenCXX/explicit-instantiation.cpp
@@ -5,6 +5,9 @@
 // This check logically is attached to 'template int S::i;' below.
 // CHECK: @_ZN1SIiE1iE = weak_odr global i32
 
+// This check is logically attached to 'template int ExportedStaticLocal::f()' below.
+// CHECK-OPT: @_ZZN19ExportedStaticLocal1fIiEEvvE1i = linkonce_odr global
+
 template
 struct plus {
   Result operator()(const T& t, const U& u) const;
@@ -153,3 +156,17 @@
 template  void S::g() {}
 template  int S::i;
 template  void S::S2::h() {}
+
+namespace ExportedStaticLocal {
+void sink(int&);
+template 
+inline void f() {
+  static int i;
+  sink(i);
+}
+// See the check line at the top of the file.
+extern template void f();
+void use() {
+  f();
+}
+}
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8892,22 +8892,27 @@
 return GVA_Internal;
 
   if (VD->isStaticLocal()) {
-GVALinkage StaticLocalLinkage = GVA_DiscardableODR;
 const DeclContext *LexicalContext = VD->getParentFunctionOrMethod();
 while (LexicalContext && !isa(LexicalContext))
   LexicalContext = LexicalContext->getLexicalParent();
 
-// Let the static local variable inherit its linkage from the nearest
-// enclosing function.
-if (LexicalContext)
-  StaticLocalLinkage =
-  Context.GetGVALinkageForFunction(cast(LexicalContext));
-
-// GVA_StrongODR function linkage is stronger than what we need,
-// downgrade to 

[PATCH] D29234: [ubsan] Sanity-check shift amounts before truncation (fixes PR27271)

2017-01-27 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

Ubsan does not report UB shifts in some cases where the shift exponent
needs to be truncated to match the type of the shift base. We perform a
range check on the truncated shift amount, leading to false negatives.

Fix the issue (PR27271) by performing the range check on the original
shift amount.


https://reviews.llvm.org/D29234

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGen/ubsan-shift.c


Index: test/CodeGen/ubsan-shift.c
===
--- /dev/null
+++ test/CodeGen/ubsan-shift.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsanitize=shift-exponent 
-emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: define i32 @f1
+int f1(int c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f2
+int f2(long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f3
+unsigned f3(unsigned c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f4
+unsigned f4(unsigned long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -2751,8 +2751,8 @@
isa(Ops.LHS->getType())) {
 CodeGenFunction::SanitizerScope SanScope();
 SmallVector Checks;
-llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
-llvm::Value *ValidExponent = Builder.CreateICmpULE(RHS, WidthMinusOne);
+llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
+llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS, WidthMinusOne);
 
 if (SanitizeExponent) {
   Checks.push_back(


Index: test/CodeGen/ubsan-shift.c
===
--- /dev/null
+++ test/CodeGen/ubsan-shift.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsanitize=shift-exponent -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: define i32 @f1
+int f1(int c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f2
+int f2(long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f3
+unsigned f3(unsigned c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f4
+unsigned f4(unsigned long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -2751,8 +2751,8 @@
isa(Ops.LHS->getType())) {
 CodeGenFunction::SanitizerScope SanScope();
 SmallVector Checks;
-llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
-llvm::Value *ValidExponent = Builder.CreateICmpULE(RHS, WidthMinusOne);
+llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
+llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS, WidthMinusOne);
 
 if (SanitizeExponent) {
   Checks.push_back(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28952: [analyzer] Add new Z3 constraint manager backend

2017-01-27 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

> Regarding incremental solving with Z3 (or with most SMT solvers in general), 
> let me just lower the expectations a bit: 

Ok, that is good to know. It seems that the performance benefits of incremental 
solving are unclear, and would be nontrivial to implement (maybe store the 
states in a DAG, then pop back to the lowest common ancestor from the previous 
state, and push down to the new state).

> The improvement here (200s vs. 250s) makes me think that some form of 
> caching/incrementalization could pay off.

I'm optimistic that implementing a SMT query cache would significantly improve 
performance (for both constraint managers), but the current version of that 
patch has some memory-safety problems (since ProgramStateRef is a 
reference-counting pointer), and I currently don't have the time to fix it up.

> We could add a new lit substitution '%clang_cc1_analyze' that expands to 
> '%clang_cc1 -analyze -analyzer-constraints=foo 
> -DANALYZER_HAS_CONSTRAINT_MANAGER_FOO" and change the analyzer tests to use 
> it.

I've updated the current version of this diff to use this approach, though 
there are still the two remaining testcase failures mentioned earlier that I'm 
not sure how to handle. I also had to remove the argument `-fsyntax-only` in 
some testcases, because the argument seems to need to appear before `-analyze` 
(which isn't possible using the substitution-based approach), though it doesn't 
seem to affect the outcome of the testcase. However, I haven't been able to 
figure out how to get llvm-lit to execute the same statement twice with 
different substitutions. From lit.cfg, it seems that I can only define 
additional substitutions, and not execute a test multiple times. I'm not 
familiar with the test infrastructure, do you have any suggestions?


https://reviews.llvm.org/D28952



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


[PATCH] D29065: Split isUsingLTO() outside of embedBitcodeInObject() and embedBitcodeMarkerOnly().

2017-01-27 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

Sorry I just notice that when I look at driver today.




Comment at: cfe/trunk/lib/Driver/Tools.cpp:6464
   if (C.getDriver().isSaveTempsEnabled() &&
-  !C.getDriver().embedBitcodeInObject() && isa(JA))
+  !C.getDriver().embedBitcodeInObject() && !C.getDriver().isUsingLTO() &&
+  isa(JA))

Should this line actually be:

```
!(C.getDriver().embedBitcodeInObject() && !C.getDriver().isUsingLTO()) &&

```



Repository:
  rL LLVM

https://reviews.llvm.org/D29065



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


[PATCH] D29065: Split isUsingLTO() outside of embedBitcodeInObject() and embedBitcodeMarkerOnly().

2017-01-27 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



Comment at: cfe/trunk/lib/Driver/Tools.cpp:6464
   if (C.getDriver().isSaveTempsEnabled() &&
-  !C.getDriver().embedBitcodeInObject() && isa(JA))
+  !C.getDriver().embedBitcodeInObject() && !C.getDriver().isUsingLTO() &&
+  isa(JA))

steven_wu wrote:
> Should this line actually be:
> 
> ```
> !(C.getDriver().embedBitcodeInObject() && !C.getDriver().isUsingLTO()) &&
> 
> ```
> 
Thanks, r293370


Repository:
  rL LLVM

https://reviews.llvm.org/D29065



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


[PATCH] D28952: [analyzer] Add new Z3 constraint manager backend

2017-01-28 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added a comment.

Let me give just 2 more Z3-related suggestions:

- instead of re-creating the solver, it might be faster to do Z3_solver_reset
- "once in a while" it might be helpful to delete everything (all solvers, 
asts, context) and call Z3_reset_memory.  Z3's small object pool is not very 
good and keeps growing /ad infinitum/, so cleaning it up once a while is a good 
thing (improves cache usage and reduces memory consumption).

BTW, you may want to call Z3_finalize_memory at exit to keep clang 
valgrind/asan-clean.  (Z3 keeps a lot of internal buffers otherwise)


https://reviews.llvm.org/D28952



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


[PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.

2017-01-28 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added a comment.

I have read the patch, but I don't have enough knowledge about C++ rules and 
fronted to accept it. Richard?




Comment at: lib/Sema/Sema.cpp:684
+  for (auto PII : Pending) 
+if (FunctionDecl *Func = dyn_cast(PII.first))
+  Func->setMarkedForPendingInstantiation();

Prazek wrote:
> Dry. Use auto
auto *


https://reviews.llvm.org/D22057



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


[PATCH] D28845: Prototype of modules codegen

2017-01-29 Thread Richard Smith via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/AST/ExternalASTSource.cpp:33
+ExternalASTSource::hasExternalDefinitions(unsigned ID) {
+  return EK_ReplyHazy;
+}

dblaikie wrote:
> rsmith wrote:
> > You should add support for this function to 
> > `clang::MultiplexExternalSemaSource` too.
> Done - though is there any test coverage I should add? Not sure exactly 
> when/where/how this is used.
> 
> Also only made a rough guess at what the right behavior is here. It could be 
> a bit more obvious if I made "hasExternalDefinitions" return 
> Optional - then when we find an ExternalASTSource that owns the ID 
> (are the IDs unique across the MultiplexExternalSemaSource? I assume they 
> have to be, but thought they'd only be valid within a single Module... guess 
> I'm confused in a few ways - certainly haven't thought about it in great 
> detail) we'd know to stop asking other sources. Probably not worth it unless 
> there's a lot of sources?
You could test this with `-chain-include`. I don't think there's any other 
in-tree way to get multiple external sources.


https://reviews.llvm.org/D28845



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


[PATCH] D17890: [OpenMP][NVPTX][CUDA] Adding support for printf for an NVPTX OpenMP device.

2017-01-29 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293444: [OpenMP][NVPTX][CUDA] Adding support for printf for 
an NVPTX OpenMP device. (authored by arpith).

Changed prior to commit:
  https://reviews.llvm.org/D17890?vs=49832=86222#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D17890

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/CodeGen/CGCUDABuiltin.cpp
  cfe/trunk/lib/CodeGen/CGGPUBuiltin.cpp
  cfe/trunk/lib/CodeGen/CMakeLists.txt
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/OpenMP/nvptx_target_printf_codegen.c

Index: cfe/trunk/test/OpenMP/nvptx_target_printf_codegen.c
===
--- cfe/trunk/test/OpenMP/nvptx_target_printf_codegen.c
+++ cfe/trunk/test/OpenMP/nvptx_target_printf_codegen.c
@@ -0,0 +1,116 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+
+#include 
+
+// expected-no-diagnostics
+extern int printf(const char *, ...);
+extern int vprintf(const char *, va_list);
+
+// Check a simple call to printf end-to-end.
+// CHECK: [[SIMPLE_PRINTF_TY:%[a-zA-Z0-9_]+]] = type { i32, i64, double }
+int CheckSimple() {
+// CHECK: define {{.*}}void [[T1:@__omp_offloading_.+CheckSimple.+]]_worker()
+#pragma omp target
+  {
+// Entry point.
+// CHECK: define {{.*}}void [[T1]]()
+// Alloca in entry block.
+// CHECK: [[BUF:%[a-zA-Z0-9_]+]] = alloca [[SIMPLE_PRINTF_TY]]
+
+// CHECK: {{call|invoke}} void [[T1]]_worker()
+// CHECK: br label {{%?}}[[EXIT:.+]]
+//
+// CHECK-DAG: [[CMTID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
+// CHECK-DAG: [[CMNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[CMWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK: [[IS_MASTER:%.+]] = icmp eq i32 [[CMTID]],
+// CHECK: br i1 [[IS_MASTER]], label {{%?}}[[MASTER:.+]], label {{%?}}[[EXIT]]
+//
+// CHECK: [[MASTER]]
+// CHECK-DAG: [[MNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[MWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK: [[MTMP1:%.+]] = sub i32 [[MNTH]], [[MWS]]
+// CHECK: call void @__kmpc_kernel_init(i32 [[MTMP1]]
+
+// printf in master-only basic block.
+// CHECK: [[FMT:%[0-9]+]] = load{{.*}}%fmt
+const char* fmt = "%d %lld %f";
+// CHECK: [[PTR0:%[0-9]+]] = getelementptr inbounds [[SIMPLE_PRINTF_TY]], [[SIMPLE_PRINTF_TY]]* [[BUF]], i32 0, i32 0
+// CHECK: store i32 1, i32* [[PTR0]], align 4
+// CHECK: [[PTR1:%[0-9]+]] = getelementptr inbounds [[SIMPLE_PRINTF_TY]], [[SIMPLE_PRINTF_TY]]* [[BUF]], i32 0, i32 1
+// CHECK: store i64 2, i64* [[PTR1]], align 8
+// CHECK: [[PTR2:%[0-9]+]] = getelementptr inbounds [[SIMPLE_PRINTF_TY]], [[SIMPLE_PRINTF_TY]]* [[BUF]], i32 0, i32 2
+
+// CHECK: store double 3.0{{[^,]*}}, double* [[PTR2]], align 8
+// CHECK: [[BUF_CAST:%[0-9]+]] = bitcast [[SIMPLE_PRINTF_TY]]* [[BUF]] to i8*
+// CHECK: [[RET:%[0-9]+]] = call i32 @vprintf(i8* [[FMT]], i8* [[BUF_CAST]])
+printf(fmt, 1, 2ll, 3.0);
+  }
+
+  return 0;
+}
+
+void CheckNoArgs() {
+// CHECK: define {{.*}}void [[T2:@__omp_offloading_.+CheckNoArgs.+]]_worker()
+#pragma omp target
+  {
+// Entry point.
+// CHECK: define {{.*}}void [[T2]]()
+
+// CHECK: {{call|invoke}} void [[T2]]_worker()
+// CHECK: br label {{%?}}[[EXIT:.+]]
+//
+// CHECK-DAG: [[CMTID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
+// CHECK-DAG: [[CMNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[CMWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK: [[IS_MASTER:%.+]] = icmp eq i32 [[CMTID]],
+// CHECK: br i1 [[IS_MASTER]], label {{%?}}[[MASTER:.+]], label {{%?}}[[EXIT]]
+//
+// CHECK: [[MASTER]]
+// CHECK-DAG: [[MNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[MWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK: [[MTMP1:%.+]] = sub i32 [[MNTH]], [[MWS]]
+// CHECK: call void @__kmpc_kernel_init(i32 [[MTMP1]]
+
+// printf in master-only basic block.
+// CHECK: call i32 @vprintf({{.*}}, i8* 

[PATCH] D27985: Add demangling support for C++11 thread_local variables

2017-01-29 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini accepted this revision.
mehdi_amini added a comment.
This revision is now accepted and ready to land.

LGTM.

Can you apply the patch in LLVM (libDemangle) as well please?


Repository:
  rL LLVM

https://reviews.llvm.org/D27985



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


[PATCH] D16135: Macro Debug Info support in Clang

2017-01-29 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud added a comment.

Kindly reminder, I am still waiting for a review on this new patch.

Thanks


https://reviews.llvm.org/D16135



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


[PATCH] D29267: [clang-tidy] safety-no-assembler

2017-01-29 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:60
 
-The improvements are...
+Added a safety module for safety-critical checks like those from High 
Integrity C++.
+

Please take look on Release Notes format in previous releases branches (3.9 and 
40).



Comment at: clang-tools-extra/docs/clang-tidy/checks/safety-no-assembler.rst:9
+Inline assembler is forbidden by safety-critical C++ standards like High
+Intergrity C++ as it restricts the portability of code.

Link to particular standard will be helpful.


https://reviews.llvm.org/D29267



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


[PATCH] D28845: Prototype of modules codegen

2017-01-29 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
dblaikie marked 2 inline comments as done.
Closed by commit rL293456: Prototype of modules codegen (authored by dblaikie).

Changed prior to commit:
  https://reviews.llvm.org/D28845?vs=86200=86239#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28845

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/AST/ExternalASTSource.h
  cfe/trunk/include/clang/Basic/LangOptions.def
  cfe/trunk/include/clang/Basic/Module.h
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h
  cfe/trunk/include/clang/Serialization/ASTBitCodes.h
  cfe/trunk/include/clang/Serialization/ASTReader.h
  cfe/trunk/include/clang/Serialization/ASTWriter.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/ExternalASTSource.cpp
  cfe/trunk/lib/Basic/Module.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Lex/ModuleMap.cpp
  cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
  cfe/trunk/test/Modules/Inputs/codegen/bar.h
  cfe/trunk/test/Modules/Inputs/codegen/bar.modulemap
  cfe/trunk/test/Modules/Inputs/codegen/foo.h
  cfe/trunk/test/Modules/Inputs/codegen/foo.modulemap
  cfe/trunk/test/Modules/Inputs/codegen/use.cpp
  cfe/trunk/test/Modules/codegen.test

Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -432,6 +432,10 @@
   Flag<["-"], "fmodules-local-submodule-visibility">,
   HelpText<"Enforce name visibility rules across submodules of the same "
"top-level module.">;
+def fmodule_codegen :
+  Flag<["-"], "fmodules-codegen">,
+  HelpText<"Generate code for uses of this module that assumes an explicit "
+   "object file will be built for the module">;
 def fmodule_format_EQ : Joined<["-"], "fmodule-format=">,
   HelpText<"Select the container format for clang modules and PCH. "
"Supported options are 'raw' and 'obj'.">;
Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -2494,7 +2494,7 @@
   ///
   /// \returns true if the function/var must be CodeGen'ed/deserialized even if
   /// it is not used.
-  bool DeclMustBeEmitted(const Decl *D);
+  bool DeclMustBeEmitted(const Decl *D, bool ForModularCodegen = false);
 
   const CXXConstructorDecl *
   getCopyConstructorForExceptionObject(CXXRecordDecl *RD);
Index: cfe/trunk/include/clang/AST/ExternalASTSource.h
===
--- cfe/trunk/include/clang/AST/ExternalASTSource.h
+++ cfe/trunk/include/clang/AST/ExternalASTSource.h
@@ -16,6 +16,7 @@
 
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/Basic/Module.h"
 #include "llvm/ADT/DenseMap.h"
 
 namespace clang {
@@ -169,6 +170,10 @@
   /// Return a descriptor for the corresponding module, if one exists.
   virtual llvm::Optional getSourceDescriptor(unsigned ID);
 
+  enum ExtKind { EK_Always, EK_Never, EK_ReplyHazy };
+
+  virtual ExtKind hasExternalDefinitions(unsigned ID);
+
   /// \brief Finds all declarations lexically contained within the given
   /// DeclContext, after applying an optional filter predicate.
   ///
Index: cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h
===
--- cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h
+++ cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h
@@ -90,6 +90,8 @@
   /// initializers themselves.
   CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
 
+  ExtKind hasExternalDefinitions(unsigned ID) override;
+
   /// \brief Find all declarations with the given name in the
   /// given context.
   bool FindExternalVisibleDeclsByName(const DeclContext *DC,
Index: cfe/trunk/include/clang/Basic/LangOptions.def
===
--- cfe/trunk/include/clang/Basic/LangOptions.def
+++ cfe/trunk/include/clang/Basic/LangOptions.def
@@ -201,6 +201,7 @@
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(NewAlignOverride  , 32, 0, "maximum alignment guaranteed by '::operator new(size_t)'")
 LANGOPT(ConceptsTS , 1, 0, "enable C++ Extensions for Concepts")
+BENIGN_LANGOPT(ModularCodegen , 1, 0, "Modular codegen")
 BENIGN_LANGOPT(ElideConstructors , 1, 1, "C++ copy constructor elision")
 BENIGN_LANGOPT(DumpRecordLayouts , 1, 0, "dumping the layout of IRgen'd records")
 BENIGN_LANGOPT(DumpRecordLayoutsSimple , 1, 0, "dumping the layout of IRgen'd 

[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293055: [clang-format] Implement comment reflowing. 
(authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D28764?vs=85739=85740#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28764

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/lib/Format/BreakableToken.h
  cfe/trunk/lib/Format/CMakeLists.txt
  cfe/trunk/lib/Format/Comments.cpp
  cfe/trunk/lib/Format/Comments.h
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/lib/Format/WhitespaceManager.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp
  cfe/trunk/unittests/Format/FormatTestSelective.cpp

Index: cfe/trunk/lib/Format/BreakableToken.h
===
--- cfe/trunk/lib/Format/BreakableToken.h
+++ cfe/trunk/lib/Format/BreakableToken.h
@@ -8,9 +8,10 @@
 //===--===//
 ///
 /// \file
-/// \brief Declares BreakableToken, BreakableStringLiteral, and
-/// BreakableBlockComment classes, that contain token type-specific logic to
-/// break long lines in tokens.
+/// \brief Declares BreakableToken, BreakableStringLiteral, BreakableComment,
+/// BreakableBlockComment and BreakableLineCommentSection classes, that contain
+/// token type-specific logic to break long lines in tokens and reflow content
+/// between tokens.
 ///
 //===--===//
 
@@ -25,10 +26,43 @@
 namespace clang {
 namespace format {
 
+/// \brief Checks if \p Token switches formatting, like /* clang-format off */.
+/// \p Token must be a comment.
+bool switchesFormatting(const FormatToken );
+
 struct FormatStyle;
 
 /// \brief Base class for strategies on how to break tokens.
 ///
+/// This is organised around the concept of a \c Split, which is a whitespace
+/// range that signifies a position of the content of a token where a
+/// reformatting might be done. Operating with splits is divided into 3
+/// operations:
+/// - getSplit, for finding a split starting at a position,
+/// - getLineLengthAfterSplit, for calculating the size in columns of the rest
+///   of the content after a split has been used for breaking, and
+/// - insertBreak, for executing the split using a whitespace manager.
+///
+/// There is a pair of operations that are used to compress a long whitespace
+/// range with a single space if that will bring the line lenght under the
+/// column limit:
+/// - getLineLengthAfterCompression, for calculating the size in columns of the
+///   line after a whitespace range has been compressed, and
+/// - compressWhitespace, for executing the whitespace compression using a
+///   whitespace manager; note that the compressed whitespace may be in the
+///   middle of the original line and of the reformatted line.
+///
+/// For tokens where the whitespace before each line needs to be also
+/// reformatted, for example for tokens supporting reflow, there are analogous
+/// operations that might be executed before the main line breaking occurs:
+/// - getSplitBefore, for finding a split such that the content preceding it
+///   needs to be specially reflown,
+/// - getLineLengthAfterSplitBefore, for calculating the line length in columns
+///   of the remainder of the content after the beginning of the content has
+///   been reformatted, and
+/// - replaceWhitespaceBefore, for executing the reflow using a whitespace
+///   manager.
+///
 /// FIXME: The interface seems set in stone, so we might want to just pull the
 /// strategy into the class, instead of controlling it from the outside.
 class BreakableToken {
@@ -42,13 +76,13 @@
   virtual unsigned getLineCount() const = 0;
 
   /// \brief Returns the number of columns required to format the piece of line
-  /// at \p LineIndex, from byte offset \p Offset with length \p Length.
+  /// at \p LineIndex, from byte offset \p TailOffset with length \p Length.
   ///
-  /// Note that previous breaks are not taken into account. \p Offset is always
-  /// specified from the start of the (original) line.
+  /// Note that previous breaks are not taken into account. \p TailOffset is
+  /// always specified from the start of the (original) line.
   /// \p Length can be set to StringRef::npos, which means "to the end of line".
   virtual unsigned
-  getLineLengthAfterSplit(unsigned LineIndex, unsigned Offset,
+  getLineLengthAfterSplit(unsigned LineIndex, unsigned TailOffset,
   StringRef::size_type Length) const = 0;
 
   /// \brief Returns a range (offset, length) at which to break the line at
@@ -61,16 +95,59 @@
   virtual void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split,
WhitespaceManager ) = 0;
 
+  /// \brief Returns the number of columns required to format the 

[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: lib/Format/BreakableToken.cpp:279-280
+  return Content.size() >= 2 &&
+  Content != "clang-format on" &&
+  Content != "clang-format off" &&
+  !Content.endswith("\\") &&

Can we now use delimitsRegion here?



Comment at: lib/Format/ContinuationIndenter.cpp:1090-1092
+// Checks if Token delimits formatting regions, like /* clang-format off */.
+// Token must be a comment.
+static bool delimitsRegion(const FormatToken ) {

delimitsRegion seems overly abstract. Perhaps switchesFormatting?



Comment at: lib/Format/ContinuationIndenter.cpp:1205-1210
+if (SplitBefore.first != StringRef::npos) {
+  TailOffset = SplitBefore.first + SplitBefore.second;
+  ReflowInProgress = true;
+} else {
+  ReflowInProgress = false;
+}

krasimir wrote:
> klimek wrote:
> > (optional) I'd probably write this:
> >   ReflowInProgress = SplitBefore.first != StringRef::npos;
> >   if (ReflowInProgress) {
> > TailOffset = SplitBefore.first + SplitBefore.second;
> >   }
> How about this?
That works.



Comment at: lib/Format/ContinuationIndenter.cpp:1231-1233
+  unsigned RemainingTokenColumnsAfterCompress =
+  Token->getLineLengthAfterCompress(LineIndex, TailOffset,
+RemainingTokenColumns, Split);

krasimir wrote:
> klimek wrote:
> > I think AfterCompression reads more naturally. Perhaps we should use "trim" 
> > instead of compress, now that I think about it.
> > So I'd probably go for getTrimmedLineLength or something.
> I don't agree with "trimmig" because i have a connotation of "trimming" 
> around the ends of strings like in ltrim/rtrim and this fundamentally 
> operates somewhere inside. +1 for AfterCompression, though.
Yea, correct, I completely missed that this might happen in the middle of the 
string if we happen to be the first token that runs over, which is a rather 
interesting case :)



Comment at: lib/Format/WhitespaceManager.cpp:131
+Changes[i - 1].Kind == tok::comment &&
+OriginalWhitespaceStart != PreviousOriginalWhitespaceEnd;
   }

krasimir wrote:
> klimek wrote:
> > Why was this needed? (what breaks without this change)
> This is a dirty hack. The problem is that WhitespaceManager does its own 
> formatting for trailing comments and sometimes it re-formats a piece of line 
> even after it's been reflown with the previous line. Consider if we reflow 
> the second line up:
> ```
> // line 1
> // line 2
> ```
> That amounts to 2 changes, first (delimited by ()) for the whitespace between 
> the two tokens, and second (delimited by []) for the beginning of the next 
> line:
> ```
> // line 1(
> )[// ]line 2
> ``` 
> So in the end we have two changes like this:
> ```
> // line 1()[ ]line 2
> ```
> Note that the OriginalWhitespaceStart of the second change is the same as the 
> PreviousOriginalWhitespaceEnd of the first change.
> In this case, the above code marks the second line as trailing comment and 
> afterwards applies its own trailing-comment-alignment logic to it, which 
> might introduce extra whitespace before "line 2".
> 
> For a proper solution we need a mechanism to say that a particular change 
> emitted through the whitespace manager breaks the sequence of trailing 
> comments.
> 
> 
Ok. In this case this needs a largish comment with a FIXME, like you just 
described ;)


https://reviews.llvm.org/D28764



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


[PATCH] D29123: [Driver] Prevent no-arc-exception-silence.m test from writing output.

2017-01-25 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.

This enables the test to run on systems where output cannot be written.


https://reviews.llvm.org/D29123

Files:
  test/Driver/no-arc-exception-silence.m


Index: test/Driver/no-arc-exception-silence.m
===
--- test/Driver/no-arc-exception-silence.m
+++ test/Driver/no-arc-exception-silence.m
@@ -1,2 +1,2 @@
-// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang 
-verify -c %s
+// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang 
-verify -c -o /dev/null %s
 // expected-no-diagnostics


Index: test/Driver/no-arc-exception-silence.m
===
--- test/Driver/no-arc-exception-silence.m
+++ test/Driver/no-arc-exception-silence.m
@@ -1,2 +1,2 @@
-// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang -verify -c %s
+// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang -verify -c -o /dev/null %s
 // expected-no-diagnostics
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 85739.
krasimir marked 2 inline comments as done.
krasimir added a comment.

- Address review comments.


https://reviews.llvm.org/D28764

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/CMakeLists.txt
  lib/Format/Comments.cpp
  lib/Format/Comments.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/WhitespaceManager.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestSelective.cpp

Index: unittests/Format/FormatTestSelective.cpp
===
--- unittests/Format/FormatTestSelective.cpp
+++ unittests/Format/FormatTestSelective.cpp
@@ -111,13 +111,19 @@
 format("int   a; // comment\n"
"intb; // comment",
0, 0));
-  EXPECT_EQ("int   a; // comment\n"
-" // line 2\n"
+  EXPECT_EQ("int a; // comment\n"
+"   // line 2\n"
 "int b;",
 format("int   a; // comment\n"
"// line 2\n"
"int b;",
28, 0));
+  EXPECT_EQ("int   a; // comment\n"
+"// comment 2\n"
+"int b;",
+format("int   a; // comment\n"
+   "// comment 2\n"
+   "int b;", 28, 0));
   EXPECT_EQ("int aa; // comment\n"
 "int b;\n"
 "int c; // unrelated comment",
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1783,6 +1783,463 @@
"0x00, 0x00, 0x00, 0x00};// comment\n");
 }
 
+TEST_F(FormatTest, ReflowsComments) {
+  // Break a long line and reflow with the full next line.
+  EXPECT_EQ("// long long long\n"
+"// long long",
+format("// long long long long\n"
+   "// long",
+   getLLVMStyleWithColumns(20)));
+
+  // Keep the trailing newline while reflowing.
+  EXPECT_EQ("// long long long\n"
+"// long long\n",
+format("// long long long long\n"
+   "// long\n",
+   getLLVMStyleWithColumns(20)));
+
+  // Break a long line and reflow with a part of the next line.
+  EXPECT_EQ("// long long long\n"
+"// long long\n"
+"// long_long",
+format("// long long long long\n"
+   "// long long_long",
+   getLLVMStyleWithColumns(20)));
+
+  // Break but do not reflow if the first word from the next line is too long.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// long_long_long\n",
+format("// long long long long\n"
+   "// long_long_long\n",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't break or reflow short lines.
+  verifyFormat("// long\n"
+   "// long long long lo\n"
+   "// long long long lo\n"
+   "// long",
+   getLLVMStyleWithColumns(20));
+
+  // Keep prefixes and decorations while reflowing.
+  EXPECT_EQ("/// long long long\n"
+"/// long long\n",
+format("/// long long long long\n"
+   "/// long\n",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("//! long long long\n"
+"//! long long\n",
+format("//! long long long long\n"
+   "//! long\n",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("/* long long long\n"
+" * long long */",
+format("/* long long long long\n"
+   " * long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't bring leading whitespace up while reflowing.
+  EXPECT_EQ("/*  long long long\n"
+" * long long long\n"
+" */",
+format("/*  long long long long\n"
+   " *  long long\n"
+   " */",
+   getLLVMStyleWithColumns(20)));
+
+  // Reflow the last line of a block comment with its trailing '*/'.
+  EXPECT_EQ("/* long long long\n"
+"   long long */",
+format("/* long long long long\n"
+   "   long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Reflow two short lines; keep the postfix of the last one.
+  EXPECT_EQ("/* long long long\n"
+" * long long long */",
+format("/* long long long long\n"
+   " * long\n"
+   " * long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Put the postfix of the last short reflow line on a newline if it doesn't
+  // fit.
+  EXPECT_EQ("/* long long long\n"
+" * long long longg\n"
+" */",
+format("/* long long long long\n"
+   " * long\n"
+  

[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/BreakableToken.cpp:747
+Split SplitBefore, WhitespaceManager ) {
+  // If this is the first line of a token, we need to inform Whitespace Manager
+  // about it: either adapt the whitespace range preceding it, or mark it as an

klimek wrote:
> What do you mean by "first line of a token"?
Sadly, there are multi-line line comment tokens, as in:
```
// line 1 \
// line 2
```
Add a note about it.



Comment at: lib/Format/BreakableToken.h:110-111
+
+  /// \brief Returns a whitespace range (offset, length) of the content at \p
+  /// LineIndex such that the content preceding this range needs to be
+  /// reformatted before any breaks are made to this line.

klimek wrote:
> I'd keep \p and LineIndex in the same line...
Sadly, that's one thing that the reflowing doesn't support yet...


https://reviews.llvm.org/D28764



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


[PATCH] D28520: Disable -Wthread-safety-analysis for some functions in __thread_support

2017-01-25 Thread Delesley Hutchins via Phabricator via cfe-commits
delesley added a comment.

The big question for me is whether these functions are exposed as part of the 
public libcxx API, or whether they are only used internally.  (Again, I'm not a 
libcxx expert.)  If they are part of the public API, then users may want to 
switch them on and off in their own code.  In that case, I'm happy with the 
current variant.

If they are only used internally, then no_thread_safety_analysis is probably 
the correct option.  (Unless, of course, the libcxx developers want to start 
using the analysis themselves, but I suspect they don't.)


https://reviews.llvm.org/D28520



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


[PATCH] D25674: [Concepts] Class template associated constraints

2017-01-25 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast updated this revision to Diff 85752.
hubert.reinterpretcast added a comment.

Address review comments; update to revision 292996

Fix possibly ill-formed NDR case

Test template-dependent cases for class redeclaration

Address review comment: use lambda instead of do while(0)

Address review comment: use PointerUnion w/struct


https://reviews.llvm.org/D25674

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/DeclTemplate.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Serialization/ASTReaderDecl.cpp
  test/CXX/concepts-ts/temp/
  test/CXX/concepts-ts/temp/temp.constr/
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp

Index: test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ -verify %s
+
+namespace nodiag {
+
+template  requires bool(T())
+struct A;
+template  requires bool(U())
+struct A;
+
+} // end namespace nodiag
+
+namespace diag {
+
+template  requires true // expected-note{{previous template declaration is here}}
+struct A;
+template  struct A; // expected-error{{associated constraints differ in template redeclaration}}
+
+template  struct B; // expected-note{{previous template declaration is here}}
+template  requires true // expected-error{{associated constraints differ in template redeclaration}}
+struct B;
+
+template  requires true // expected-note{{previous template declaration is here}}
+struct C;
+template  requires !0 // expected-error{{associated constraints differ in template redeclaration}}
+struct C;
+
+} // end namespace diag
+
+namespace nodiag {
+
+struct AA {
+  template  requires someFunc(T())
+  struct A;
+};
+
+template  requires someFunc(T())
+struct AA::A { };
+
+struct AAF {
+  template  requires someFunc(T())
+  friend struct AA::A;
+};
+
+} // end namespace nodiag
+
+namespace diag {
+
+template 
+struct TA {
+  template  class TT> requires TT::happy // expected-note 2{{previous template declaration is here}}
+  struct A;
+
+  struct AF;
+};
+
+template 
+template  class TT> struct TA::A { }; // expected-error{{associated constraints differ in template redeclaration}}
+
+template 
+struct TA::AF {
+  template  class TT> requires TT::happy // expected-error{{associated constraints differ in template redeclaration}}
+  friend struct TA::A;
+};
+
+} // end namespace diag
Index: lib/Serialization/ASTReaderDecl.cpp
===
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -1873,6 +1873,7 @@
   DeclID PatternID = ReadDeclID();
   NamedDecl *TemplatedDecl = cast_or_null(Reader.GetDecl(PatternID));
   TemplateParameterList *TemplateParams = Record.readTemplateParameterList();
+  // FIXME handle associated constraints
   D->init(TemplatedDecl, TemplateParams);
 
   return PatternID;
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -45,6 +45,26 @@
   return SourceRange(Ps[0]->getTemplateLoc(), Ps[N-1]->getRAngleLoc());
 }
 
+namespace clang {
+/// \brief [temp.constr.decl]p2: A template's associated constraints are
+/// defined as a single constraint-expression derived from the introduced
+/// constraint-expressions [ ... ].
+///
+/// \param Params The template parameter list and optional requires-clause.
+///
+/// \param FD The underlying templated function declaration for a function
+/// template.
+static Expr *formAssociatedConstraints(TemplateParameterList *Params,
+   FunctionDecl *FD);
+}
+
+static Expr *clang::formAssociatedConstraints(TemplateParameterList *Params,
+  FunctionDecl *FD) {
+  // FIXME: Concepts: collect additional introduced constraint-expressions
+  assert(!FD && "Cannot collect constraints from function declaration yet.");
+  return Params->getRequiresClause();
+}
+
 /// \brief Determine whether the declaration found is acceptable as the name
 /// of a template and, if so, return that template declaration. Otherwise,
 /// returns NULL.
@@ -1137,6 +1157,9 @@
 }
   }
 
+  // TODO Memory management; associated constraints are not always stored.
+  Expr *const CurAC = formAssociatedConstraints(TemplateParams, nullptr);
+
   if (PrevClassTemplate) {
 // Ensure that the template parameter lists are compatible. Skip this check
 // for a friend in a dependent context: the template parameter list itself
@@ -1148,6 +1171,29 @@
 TPL_TemplateMatch))
   return true;
 
+// Check for matching associated constraints on 

[PATCH] D28946: [analyzer] Fix memory space for block-captured static locals.

2017-01-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293043: [analyzer] Fix MacOSXAPIChecker fp with static 
locals seen from nested blocks. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D28946?vs=85588=85722#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28946

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
  cfe/trunk/test/Analysis/dispatch-once.m
  cfe/trunk/test/Analysis/null-deref-static.m

Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1849,6 +1849,8 @@
 
 // Function-scoped static variables are default-initialized to 0; if they
 // have an initializer, it would have been processed by now.
+// FIXME: This is only true when we're starting analysis from main().
+// We're losing a lot of coverage here.
 if (isa(MS))
   return svalBuilder.makeZeroVal(T);
 
Index: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -816,9 +816,11 @@
 
 const StackFrameContext *STC = V.get();
 
-if (!STC)
+if (!STC) {
+  // FIXME: Assign a more sensible memory space to static locals
+  // we see from within blocks that we analyze as top-level declarations.
   sReg = getUnknownRegion();
-else {
+} else {
   if (D->hasLocalStorage()) {
 sReg = isa(D) || isa(D)
? static_cast(getStackArgumentsRegion(STC))
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
@@ -94,11 +94,18 @@
   bool SuggestStatic = false;
   os << "Call to '" << FName << "' uses";
   if (const VarRegion *VR = dyn_cast(RB)) {
+const VarDecl *VD = VR->getDecl();
+// FIXME: These should have correct memory space and thus should be filtered
+// out earlier. This branch only fires when we're looking from a block,
+// which we analyze as a top-level declaration, onto a static local
+// in a function that contains the block.
+if (VD->isStaticLocal())
+  return;
 // We filtered out globals earlier, so it must be a local variable
 // or a block variable which is under UnknownSpaceRegion.
 if (VR != R)
   os << " memory within";
-if (VR->getDecl()->hasAttr())
+if (VD->hasAttr())
   os << " the block variable '";
 else
   os << " the local variable '";
Index: cfe/trunk/test/Analysis/null-deref-static.m
===
--- cfe/trunk/test/Analysis/null-deref-static.m
+++ cfe/trunk/test/Analysis/null-deref-static.m
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -w -fblocks -analyze -analyzer-checker=core,deadcode,alpha.core,debug.ExprInspection -verify %s
+
+void *malloc(unsigned long);
+void clang_analyzer_warnIfReached();
+
+void test_static_from_block() {
+  static int *x;
+  ^{
+*x; // no-warning
+  };
+}
+
+void test_static_within_block() {
+  ^{
+static int *x;
+*x; // expected-warning{{Dereference of null pointer}}
+  };
+}
+
+void test_static_control_flow(int y) {
+  static int *x;
+  if (x) {
+// FIXME: Should be reachable.
+clang_analyzer_warnIfReached(); // no-warning
+  }
+  if (y) {
+// We are not sure if this branch is possible, because the developer
+// may argue that function is always called with y == 1 for the first time.
+// In this case, we can only advise the developer to add assertions
+// for suppressing such path.
+*x; // expected-warning{{Dereference of null pointer}}
+  } else {
+x = malloc(1);
+  }
+}
Index: cfe/trunk/test/Analysis/dispatch-once.m
===
--- cfe/trunk/test/Analysis/dispatch-once.m
+++ cfe/trunk/test/Analysis/dispatch-once.m
@@ -107,3 +107,10 @@
   };
   dispatch_once(, ^{}); // expected-warning{{Call to 'dispatch_once' uses the block variable 'once' for the predicate value.}}
 }
+
+void test_static_var_from_outside_block() {
+  static dispatch_once_t once;
+  ^{
+dispatch_once(, ^{}); // no-warning
+  };
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:1158-1159
+CommentPragmasRegex.match(Current.TokenText.substr(2)) ||
+Current.TokenText.substr(2).ltrim().startswith("clang-format on") ||
+Current.TokenText.substr(2).ltrim().startswith("clang-format off"))
   return addMultilineToken(Current, State);

klimek wrote:
> krasimir wrote:
> > klimek wrote:
> > > krasimir wrote:
> > > > klimek wrote:
> > > > > Generally, we shouldn't need those here, as those should be part of 
> > > > > the Token.Finalized state.
> > > > Here the problem is that the comments /* clang-format on */ and /* 
> > > > clang-format off */ control the formatting of the tokens in between, 
> > > > but do not control their own formatting, that is they are not finalized 
> > > > themselves.
> > > > What happens is that if we rely solely on Token.Finalized and the 
> > > > ColumnLimit is small, say 20, then:
> > > > ```
> > > > /* clang-format off */ 
> > > > ```
> > > > gets broken into:
> > > > ```
> > > > /* clang-format off
> > > >   */
> > > > ```
> > > > 
> > > > Add comments about this.
> > > Isn't the right fix to change the tokens of the comment to be finalized?
> > That's arguable. Consider [[ 
> > https://github.com/llvm-mirror/clang/blob/master/unittests/Format/FormatTest.cpp#L10916
> >  | FormatTest.cpp:10916 ]]: in this case we still want to re-indent the /* 
> > clang-format on/off */ comments, just not break them. If we finalize the 
> > token, we can't re-indent.
> I see two options:
> - mark the comment with a special token type for clang-format on/off
> - pull out a function - I see you already have one called mayReflowContent; 
> can we use that?
mayReflowContent is too specific for content during region. I'll add a 
delimitsRegion method.



Comment at: lib/Format/ContinuationIndenter.cpp:1205-1210
+if (SplitBefore.first != StringRef::npos) {
+  TailOffset = SplitBefore.first + SplitBefore.second;
+  ReflowInProgress = true;
+} else {
+  ReflowInProgress = false;
+}

klimek wrote:
> (optional) I'd probably write this:
>   ReflowInProgress = SplitBefore.first != StringRef::npos;
>   if (ReflowInProgress) {
> TailOffset = SplitBefore.first + SplitBefore.second;
>   }
How about this?



Comment at: lib/Format/ContinuationIndenter.cpp:1231-1233
+  unsigned RemainingTokenColumnsAfterCompress =
+  Token->getLineLengthAfterCompress(LineIndex, TailOffset,
+RemainingTokenColumns, Split);

klimek wrote:
> I think AfterCompression reads more naturally. Perhaps we should use "trim" 
> instead of compress, now that I think about it.
> So I'd probably go for getTrimmedLineLength or something.
I don't agree with "trimmig" because i have a connotation of "trimming" around 
the ends of strings like in ltrim/rtrim and this fundamentally operates 
somewhere inside. +1 for AfterCompression, though.



Comment at: lib/Format/WhitespaceManager.cpp:131
+Changes[i - 1].Kind == tok::comment &&
+OriginalWhitespaceStart != PreviousOriginalWhitespaceEnd;
   }

klimek wrote:
> Why was this needed? (what breaks without this change)
This is a dirty hack. The problem is that WhitespaceManager does its own 
formatting for trailing comments and sometimes it re-formats a piece of line 
even after it's been reflown with the previous line. Consider if we reflow the 
second line up:
```
// line 1
// line 2
```
That amounts to 2 changes, first (delimited by ()) for the whitespace between 
the two tokens, and second (delimited by []) for the beginning of the next line:
```
// line 1(
)[// ]line 2
``` 
So in the end we have two changes like this:
```
// line 1()[ ]line 2
```
Note that the OriginalWhitespaceStart of the second change is the same as the 
PreviousOriginalWhitespaceEnd of the first change.
In this case, the above code marks the second line as trailing comment and 
afterwards applies its own trailing-comment-alignment logic to it, which might 
introduce extra whitespace before "line 2".

For a proper solution we need a mechanism to say that a particular change 
emitted through the whitespace manager breaks the sequence of trailing comments.





Comment at: unittests/Format/FormatTest.cpp:2169
+
+  // Don't reflow lines starting with two punctuation characters.
+  EXPECT_EQ("// long long long\n"

klimek wrote:
> But we want to reflow lines starting with one punctuation character?
I guess I'm looking at lines that start like this: "ala", 'ala'. So it may be 
better to special-case these two instead.
The heuristic for now, in mayReflowContent is: the content of the line needs to 
have at least two characters and either the first or the second character must 
be non-punctuation.

Another approach would be to not do these funny things 

[PATCH] D28529: [test] Port clang tests to canonicalized booleans

2017-01-25 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293052: [test] Port clang tests to canonicalized booleans 
(authored by mgorny).

Changed prior to commit:
  https://reviews.llvm.org/D28529?vs=83852=85736#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28529

Files:
  cfe/trunk/CMakeLists.txt
  cfe/trunk/test/ARCMT/lit.local.cfg
  cfe/trunk/test/Analysis/lit.local.cfg
  cfe/trunk/test/CMakeLists.txt
  cfe/trunk/test/Rewriter/lit.local.cfg
  cfe/trunk/test/Tooling/lit.local.cfg
  cfe/trunk/test/lit.cfg
  cfe/trunk/test/lit.site.cfg.in

Index: cfe/trunk/test/Analysis/lit.local.cfg
===
--- cfe/trunk/test/Analysis/lit.local.cfg
+++ cfe/trunk/test/Analysis/lit.local.cfg
@@ -1,2 +1,2 @@
-if config.root.clang_staticanalyzer == 0:
+if not config.root.clang_staticanalyzer:
 config.unsupported = True
Index: cfe/trunk/test/ARCMT/lit.local.cfg
===
--- cfe/trunk/test/ARCMT/lit.local.cfg
+++ cfe/trunk/test/ARCMT/lit.local.cfg
@@ -1,2 +1,2 @@
-if config.root.clang_arcmt == 0:
+if not config.root.clang_arcmt:
 config.unsupported = True
Index: cfe/trunk/test/Rewriter/lit.local.cfg
===
--- cfe/trunk/test/Rewriter/lit.local.cfg
+++ cfe/trunk/test/Rewriter/lit.local.cfg
@@ -1,3 +1,3 @@
 # The Objective-C rewriters are currently grouped with ARCMT.
-if config.root.clang_arcmt == 0:
+if not config.root.clang_arcmt:
 config.unsupported = True
Index: cfe/trunk/test/lit.site.cfg.in
===
--- cfe/trunk/test/lit.site.cfg.in
+++ cfe/trunk/test/lit.site.cfg.in
@@ -14,13 +14,13 @@
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.target_triple = "@TARGET_TRIPLE@"
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
-config.have_zlib = "@HAVE_LIBZ@"
-config.clang_arcmt = @ENABLE_CLANG_ARCMT@
+config.have_zlib = @HAVE_LIBZ@
+config.clang_arcmt = @CLANG_ENABLE_ARCMT@
 config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
-config.clang_staticanalyzer = @ENABLE_CLANG_STATIC_ANALYZER@
-config.clang_examples = @ENABLE_CLANG_EXAMPLES@
+config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
+config.clang_examples = @CLANG_BUILD_EXAMPLES@
 config.enable_shared = @ENABLE_SHARED@
-config.enable_backtrace = "@ENABLE_BACKTRACES@"
+config.enable_backtrace = @ENABLE_BACKTRACES@
 config.host_arch = "@HOST_ARCH@"
 
 # Support substitution of the tools and libs dirs with user parameters. This is
Index: cfe/trunk/test/lit.cfg
===
--- cfe/trunk/test/lit.cfg
+++ cfe/trunk/test/lit.cfg
@@ -202,7 +202,7 @@
 # Plugins (loadable modules)
 # TODO: This should be supplied by Makefile or autoconf.
 if sys.platform in ['win32', 'cygwin']:
-has_plugins = (config.enable_shared == 1)
+has_plugins = config.enable_shared
 else:
 has_plugins = True
 
@@ -353,7 +353,7 @@
 config.available_features.add('default-cxx-stdlib-set')
 
 # Enabled/disabled features
-if config.clang_staticanalyzer != 0:
+if config.clang_staticanalyzer:
 config.available_features.add("staticanalyzer")
 
 # As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
@@ -474,10 +474,10 @@
 else:
 config.available_features.add("not_ubsan")
 
-if config.enable_backtrace == "1":
+if config.enable_backtrace:
 config.available_features.add("backtrace")
 
-if config.have_zlib == "1":
+if config.have_zlib:
 config.available_features.add("zlib")
 else:
 config.available_features.add("nozlib")
Index: cfe/trunk/test/CMakeLists.txt
===
--- cfe/trunk/test/CMakeLists.txt
+++ cfe/trunk/test/CMakeLists.txt
@@ -18,6 +18,12 @@
   endif()
 endif()
 
+llvm_canonicalize_cmake_booleans(
+  CLANG_BUILD_EXAMPLES
+  CLANG_ENABLE_ARCMT
+  CLANG_ENABLE_STATIC_ANALYZER
+  ENABLE_BACKTRACES)
+
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
@@ -55,15 +61,15 @@
   )
 endif ()
 
-if (ENABLE_CLANG_EXAMPLES)
+if (CLANG_BUILD_EXAMPLES)
   list(APPEND CLANG_TEST_DEPS
 AnnotateFunctions
 clang-interpreter
 PrintFunctionNames
 )
 endif ()
 
-if (ENABLE_CLANG_STATIC_ANALYZER AND ENABLE_CLANG_EXAMPLES)
+if (CLANG_ENABLE_STATIC_ANALYZER AND CLANG_BUILD_EXAMPLES)
   list(APPEND CLANG_TEST_DEPS
 SampleAnalyzerPlugin
 )
Index: cfe/trunk/test/Tooling/lit.local.cfg
===
--- cfe/trunk/test/Tooling/lit.local.cfg
+++ cfe/trunk/test/Tooling/lit.local.cfg
@@ -1,2 +1,2 @@
-if config.root.clang_staticanalyzer == 0:
+if not config.root.clang_staticanalyzer:
 config.unsupported = True
Index: cfe/trunk/CMakeLists.txt
===
--- 

[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 85737.
krasimir marked 3 inline comments as done.
krasimir added a comment.

- Address comments. Add a bunch of comments about various range computations.


https://reviews.llvm.org/D28764

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/CMakeLists.txt
  lib/Format/Comments.cpp
  lib/Format/Comments.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/WhitespaceManager.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestSelective.cpp

Index: unittests/Format/FormatTestSelective.cpp
===
--- unittests/Format/FormatTestSelective.cpp
+++ unittests/Format/FormatTestSelective.cpp
@@ -111,13 +111,19 @@
 format("int   a; // comment\n"
"intb; // comment",
0, 0));
-  EXPECT_EQ("int   a; // comment\n"
-" // line 2\n"
+  EXPECT_EQ("int a; // comment\n"
+"   // line 2\n"
 "int b;",
 format("int   a; // comment\n"
"// line 2\n"
"int b;",
28, 0));
+  EXPECT_EQ("int   a; // comment\n"
+"// comment 2\n"
+"int b;",
+format("int   a; // comment\n"
+   "// comment 2\n"
+   "int b;", 28, 0));
   EXPECT_EQ("int aa; // comment\n"
 "int b;\n"
 "int c; // unrelated comment",
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1783,6 +1783,463 @@
"0x00, 0x00, 0x00, 0x00};// comment\n");
 }
 
+TEST_F(FormatTest, ReflowsComments) {
+  // Break a long line and reflow with the full next line.
+  EXPECT_EQ("// long long long\n"
+"// long long",
+format("// long long long long\n"
+   "// long",
+   getLLVMStyleWithColumns(20)));
+
+  // Keep the trailing newline while reflowing.
+  EXPECT_EQ("// long long long\n"
+"// long long\n",
+format("// long long long long\n"
+   "// long\n",
+   getLLVMStyleWithColumns(20)));
+
+  // Break a long line and reflow with a part of the next line.
+  EXPECT_EQ("// long long long\n"
+"// long long\n"
+"// long_long",
+format("// long long long long\n"
+   "// long long_long",
+   getLLVMStyleWithColumns(20)));
+
+  // Break but do not reflow if the first word from the next line is too long.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// long_long_long\n",
+format("// long long long long\n"
+   "// long_long_long\n",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't break or reflow short lines.
+  verifyFormat("// long\n"
+   "// long long long lo\n"
+   "// long long long lo\n"
+   "// long",
+   getLLVMStyleWithColumns(20));
+
+  // Keep prefixes and decorations while reflowing.
+  EXPECT_EQ("/// long long long\n"
+"/// long long\n",
+format("/// long long long long\n"
+   "/// long\n",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("//! long long long\n"
+"//! long long\n",
+format("//! long long long long\n"
+   "//! long\n",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("/* long long long\n"
+" * long long */",
+format("/* long long long long\n"
+   " * long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't bring leading whitespace up while reflowing.
+  EXPECT_EQ("/*  long long long\n"
+" * long long long\n"
+" */",
+format("/*  long long long long\n"
+   " *  long long\n"
+   " */",
+   getLLVMStyleWithColumns(20)));
+
+  // Reflow the last line of a block comment with its trailing '*/'.
+  EXPECT_EQ("/* long long long\n"
+"   long long */",
+format("/* long long long long\n"
+   "   long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Reflow two short lines; keep the postfix of the last one.
+  EXPECT_EQ("/* long long long\n"
+" * long long long */",
+format("/* long long long long\n"
+   " * long\n"
+   " * long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Put the postfix of the last short reflow line on a newline if it doesn't
+  // fit.
+  EXPECT_EQ("/* long long long\n"
+" * long long longg\n"
+" */",
+format("/* long long 

[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: lib/Format/BreakableToken.cpp:747
+Split SplitBefore, WhitespaceManager ) {
+  // If this is the first line of a token, we need to inform Whitespace Manager
+  // about it: either adapt the whitespace range preceding it, or mark it as an

What do you mean by "first line of a token"?



Comment at: lib/Format/BreakableToken.h:110-111
+
+  /// \brief Returns a whitespace range (offset, length) of the content at \p
+  /// LineIndex such that the content preceding this range needs to be
+  /// reformatted before any breaks are made to this line.

I'd keep \p and LineIndex in the same line...


https://reviews.llvm.org/D28764



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


[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D28764



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


[PATCH] D29087: [OpenMP] Support for thread_limit-clause on the 'target teams' directive.

2017-01-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293049: [OpenMP] Support for thread_limit-clause on the 
'target teams' directive. (authored by arpith).

Changed prior to commit:
  https://reviews.llvm.org/D29087?vs=85592=85728#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29087

Files:
  cfe/trunk/include/clang/AST/OpenMPClause.h
  cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
  cfe/trunk/lib/AST/OpenMPClause.cpp
  cfe/trunk/lib/AST/StmtProfile.cpp
  cfe/trunk/lib/Sema/SemaOpenMP.cpp
  cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
  cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
  cfe/trunk/test/OpenMP/target_teams_thread_limit_codegen.cpp
  cfe/trunk/tools/libclang/CIndex.cpp

Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -3003,6 +3003,7 @@
 template 
 bool RecursiveASTVisitor::VisitOMPThreadLimitClause(
 OMPThreadLimitClause *C) {
+  TRY_TO(VisitOMPClauseWithPreInit(C));
   TRY_TO(TraverseStmt(C->getThreadLimit()));
   return true;
 }
Index: cfe/trunk/include/clang/AST/OpenMPClause.h
===
--- cfe/trunk/include/clang/AST/OpenMPClause.h
+++ cfe/trunk/include/clang/AST/OpenMPClause.h
@@ -3541,7 +3541,7 @@
 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
 /// with single expression 'n'.
 ///
-class OMPThreadLimitClause : public OMPClause {
+class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
   friend class OMPClauseReader;
   /// \brief Location of '('.
   SourceLocation LParenLoc;
@@ -3557,20 +3557,28 @@
   /// \brief Build 'thread_limit' clause.
   ///
   /// \param E Expression associated with this clause.
+  /// \param HelperE Helper Expression associated with this clause.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
   ///
-  OMPThreadLimitClause(Expr *E, SourceLocation StartLoc,
-   SourceLocation LParenLoc, SourceLocation EndLoc)
-  : OMPClause(OMPC_thread_limit, StartLoc, EndLoc), LParenLoc(LParenLoc),
-ThreadLimit(E) {}
+  OMPThreadLimitClause(Expr *E, Stmt *HelperE,
+   OpenMPDirectiveKind CaptureRegion,
+   SourceLocation StartLoc, SourceLocation LParenLoc,
+   SourceLocation EndLoc)
+  : OMPClause(OMPC_thread_limit, StartLoc, EndLoc),
+OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
+setPreInitStmt(HelperE, CaptureRegion);
+  }
 
   /// \brief Build an empty clause.
   ///
   OMPThreadLimitClause()
   : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
-LParenLoc(SourceLocation()), ThreadLimit(nullptr) {}
+OMPClauseWithPreInit(this), LParenLoc(SourceLocation()),
+ThreadLimit(nullptr) {}
   /// \brief Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   /// \brief Returns the location of '('.
Index: cfe/trunk/test/OpenMP/target_teams_thread_limit_codegen.cpp
===
--- cfe/trunk/test/OpenMP/target_teams_thread_limit_codegen.cpp
+++ cfe/trunk/test/OpenMP/target_teams_thread_limit_codegen.cpp
@@ -0,0 +1,357 @@
+// Test host codegen.
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ 

[PATCH] D28860: [OpenCL] Diagnose write_only image3d when extension is disabled

2017-01-25 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia closed this revision.
Anastasia added a comment.

Committed in r293050!


https://reviews.llvm.org/D28860



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


[PATCH] D29123: [Driver] Prevent no-arc-exception-silence.m test from writing output.

2017-01-25 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293051: [Driver] Prevent no-arc-exception-silence.m test 
from writing output. (authored by mboehme).

Changed prior to commit:
  https://reviews.llvm.org/D29123?vs=85734=85735#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29123

Files:
  cfe/trunk/test/Driver/no-arc-exception-silence.m


Index: cfe/trunk/test/Driver/no-arc-exception-silence.m
===
--- cfe/trunk/test/Driver/no-arc-exception-silence.m
+++ cfe/trunk/test/Driver/no-arc-exception-silence.m
@@ -1,2 +1,2 @@
-// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang 
-verify -c %s
+// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang 
-verify -c -o /dev/null %s
 // expected-no-diagnostics


Index: cfe/trunk/test/Driver/no-arc-exception-silence.m
===
--- cfe/trunk/test/Driver/no-arc-exception-silence.m
+++ cfe/trunk/test/Driver/no-arc-exception-silence.m
@@ -1,2 +1,2 @@
-// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang -verify -c %s
+// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang -verify -c -o /dev/null %s
 // expected-no-diagnostics
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Tried to add some comments around range computations. Most of the time it's 
about converting range offsets from local line-based values to 
start-of-token-based offsets.




Comment at: lib/Format/BreakableToken.cpp:279-280
+  return Content.size() >= 2 &&
+  Content != "clang-format on" &&
+  Content != "clang-format off" &&
+  !Content.endswith("\\") &&

klimek wrote:
> Can we now use delimitsRegion here?
Yep! Actually came up with even better alternative: we use switchesFormatting() 
below:



Comment at: lib/Format/ContinuationIndenter.cpp:1090-1092
+// Checks if Token delimits formatting regions, like /* clang-format off */.
+// Token must be a comment.
+static bool delimitsRegion(const FormatToken ) {

klimek wrote:
> delimitsRegion seems overly abstract. Perhaps switchesFormatting?
Yep. Also moved it to BreakableToken.h/.cpp so it can be used from both 
ContinuationIndenter::breakProtrudingToken and BreakableComment::mayReflow!


https://reviews.llvm.org/D28764



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


[PATCH] D28952: [analyzer] Add new Z3 constraint manager backend

2017-01-25 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added a comment.

Regarding incremental solving with Z3 (or with most SMT solvers in general), 
let me just lower the expectations a bit:
In Z3, when you do push(), there are a few things that change immediately: 1) 
it uses a different SAT solver (one that supports incremental reasoning), and 
2) some preprocessing steps are disabled completely.
The advantage of incremental solving is that it shares the state of the SAT 
solver between queries. On the other hand, Z3 disables a bunch of nice 
preprocessors, and also it switches to eager bit-blasting.  So whether going 
incremental pays off, it depends..  I've seen cases where it's faster to create 
a new solver for each query and cases where incremental is a good thing.
It's on our plans to "fix" Z3 to do better preprocessing in incremental mode, 
but there's no ETA at the moment to start this work..


https://reviews.llvm.org/D28952



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


[PATCH] D29085: [OpenMP] Support for num_teams-clause on the 'target teams' directive.

2017-01-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293048: [OpenMP] Support for num_teams-clause on the 'target 
teams' directive. (authored by arpith).

Changed prior to commit:
  https://reviews.llvm.org/D29085?vs=85587=85726#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29085

Files:
  cfe/trunk/include/clang/AST/OpenMPClause.h
  cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
  cfe/trunk/lib/AST/OpenMPClause.cpp
  cfe/trunk/lib/AST/StmtProfile.cpp
  cfe/trunk/lib/Sema/SemaOpenMP.cpp
  cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
  cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
  cfe/trunk/test/OpenMP/target_teams_num_teams_codegen.cpp
  cfe/trunk/tools/libclang/CIndex.cpp

Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -2995,6 +2995,7 @@
 template 
 bool RecursiveASTVisitor::VisitOMPNumTeamsClause(
 OMPNumTeamsClause *C) {
+  TRY_TO(VisitOMPClauseWithPreInit(C));
   TRY_TO(TraverseStmt(C->getNumTeams()));
   return true;
 }
Index: cfe/trunk/include/clang/AST/OpenMPClause.h
===
--- cfe/trunk/include/clang/AST/OpenMPClause.h
+++ cfe/trunk/include/clang/AST/OpenMPClause.h
@@ -3479,7 +3479,7 @@
 /// In this example directive '#pragma omp teams' has clause 'num_teams'
 /// with single expression 'n'.
 ///
-class OMPNumTeamsClause : public OMPClause {
+class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
   friend class OMPClauseReader;
   /// \brief Location of '('.
   SourceLocation LParenLoc;
@@ -3495,20 +3495,27 @@
   /// \brief Build 'num_teams' clause.
   ///
   /// \param E Expression associated with this clause.
+  /// \param HelperE Helper Expression associated with this clause.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
   ///
-  OMPNumTeamsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
+  OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
+SourceLocation StartLoc, SourceLocation LParenLoc,
 SourceLocation EndLoc)
-  : OMPClause(OMPC_num_teams, StartLoc, EndLoc), LParenLoc(LParenLoc), 
-NumTeams(E) {}
+  : OMPClause(OMPC_num_teams, StartLoc, EndLoc), OMPClauseWithPreInit(this),
+LParenLoc(LParenLoc), NumTeams(E) {
+setPreInitStmt(HelperE, CaptureRegion);
+  }
 
   /// \brief Build an empty clause.
   ///
   OMPNumTeamsClause()
-  : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()), 
-LParenLoc(SourceLocation()), NumTeams(nullptr) {}
+  : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
+OMPClauseWithPreInit(this), LParenLoc(SourceLocation()),
+NumTeams(nullptr) {}
   /// \brief Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   /// \brief Returns the location of '('.
Index: cfe/trunk/test/OpenMP/target_teams_num_teams_codegen.cpp
===
--- cfe/trunk/test/OpenMP/target_teams_num_teams_codegen.cpp
+++ cfe/trunk/test/OpenMP/target_teams_num_teams_codegen.cpp
@@ -0,0 +1,344 @@
+// Test host codegen.
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown 

[PATCH] D28764: [clang-format] Implement comment reflowing (v3)

2017-01-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 85725.
krasimir marked 8 inline comments as done.
krasimir added a comment.

- Address review comments.


https://reviews.llvm.org/D28764

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/CMakeLists.txt
  lib/Format/Comments.cpp
  lib/Format/Comments.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/WhitespaceManager.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestSelective.cpp

Index: unittests/Format/FormatTestSelective.cpp
===
--- unittests/Format/FormatTestSelective.cpp
+++ unittests/Format/FormatTestSelective.cpp
@@ -111,13 +111,19 @@
 format("int   a; // comment\n"
"intb; // comment",
0, 0));
-  EXPECT_EQ("int   a; // comment\n"
-" // line 2\n"
+  EXPECT_EQ("int a; // comment\n"
+"   // line 2\n"
 "int b;",
 format("int   a; // comment\n"
"// line 2\n"
"int b;",
28, 0));
+  EXPECT_EQ("int   a; // comment\n"
+"// comment 2\n"
+"int b;",
+format("int   a; // comment\n"
+   "// comment 2\n"
+   "int b;", 28, 0));
   EXPECT_EQ("int aa; // comment\n"
 "int b;\n"
 "int c; // unrelated comment",
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1783,6 +1783,463 @@
"0x00, 0x00, 0x00, 0x00};// comment\n");
 }
 
+TEST_F(FormatTest, ReflowsComments) {
+  // Break a long line and reflow with the full next line.
+  EXPECT_EQ("// long long long\n"
+"// long long",
+format("// long long long long\n"
+   "// long",
+   getLLVMStyleWithColumns(20)));
+
+  // Keep the trailing newline while reflowing.
+  EXPECT_EQ("// long long long\n"
+"// long long\n",
+format("// long long long long\n"
+   "// long\n",
+   getLLVMStyleWithColumns(20)));
+
+  // Break a long line and reflow with a part of the next line.
+  EXPECT_EQ("// long long long\n"
+"// long long\n"
+"// long_long",
+format("// long long long long\n"
+   "// long long_long",
+   getLLVMStyleWithColumns(20)));
+
+  // Break but do not reflow if the first word from the next line is too long.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// long_long_long\n",
+format("// long long long long\n"
+   "// long_long_long\n",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't break or reflow short lines.
+  verifyFormat("// long\n"
+   "// long long long lo\n"
+   "// long long long lo\n"
+   "// long",
+   getLLVMStyleWithColumns(20));
+
+  // Keep prefixes and decorations while reflowing.
+  EXPECT_EQ("/// long long long\n"
+"/// long long\n",
+format("/// long long long long\n"
+   "/// long\n",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("//! long long long\n"
+"//! long long\n",
+format("//! long long long long\n"
+   "//! long\n",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("/* long long long\n"
+" * long long */",
+format("/* long long long long\n"
+   " * long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't bring leading whitespace up while reflowing.
+  EXPECT_EQ("/*  long long long\n"
+" * long long long\n"
+" */",
+format("/*  long long long long\n"
+   " *  long long\n"
+   " */",
+   getLLVMStyleWithColumns(20)));
+
+  // Reflow the last line of a block comment with its trailing '*/'.
+  EXPECT_EQ("/* long long long\n"
+"   long long */",
+format("/* long long long long\n"
+   "   long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Reflow two short lines; keep the postfix of the last one.
+  EXPECT_EQ("/* long long long\n"
+" * long long long */",
+format("/* long long long long\n"
+   " * long\n"
+   " * long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Put the postfix of the last short reflow line on a newline if it doesn't
+  // fit.
+  EXPECT_EQ("/* long long long\n"
+" * long long longg\n"
+" */",
+format("/* long long long long\n"
+   " * long\n"
+  

[PATCH] D29077: [lsan] Enable LSan for x86 Linux.

2017-01-25 Thread Maxim Ostapenko via Phabricator via cfe-commits
m.ostapenko updated this revision to Diff 85756.
m.ostapenko added a comment.

Add a test case.


Repository:
  rL LLVM

https://reviews.llvm.org/D29077

Files:
  lib/Driver/ToolChains.cpp
  test/Driver/fsanitize.c


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -231,6 +231,12 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address,leak 
-fno-sanitize=address %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANA-SANL-NO-SANA
 // CHECK-SANA-SANL-NO-SANA: "-fsanitize=leak"
 
+// RUN: %clang -target i686-linux-gnu -fsanitize=leak %s -### 2>&1 | FileCheck 
%s --check-prefix=CHECK-SANL-X86
+// CHECK-SANL-X86: "-fsanitize=leak"
+
+// RUN: %clang -target i686-linux-gnu -fsanitize=address,leak 
-fno-sanitize=address %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANA-SANL-NO-SANA-X86
+// CHECK-SANA-SANL-NO-SANA-X86: "-fsanitize=leak"
+
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN
 // CHECK-MSAN: "-fno-assume-sane-operator-new"
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -4730,7 +4730,7 @@
   Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
-  if (IsX86_64 || IsMIPS64 || IsAArch64)
+  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
 Res |= SanitizerKind::Thread;


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -231,6 +231,12 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address,leak -fno-sanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANL-NO-SANA
 // CHECK-SANA-SANL-NO-SANA: "-fsanitize=leak"
 
+// RUN: %clang -target i686-linux-gnu -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANL-X86
+// CHECK-SANL-X86: "-fsanitize=leak"
+
+// RUN: %clang -target i686-linux-gnu -fsanitize=address,leak -fno-sanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANL-NO-SANA-X86
+// CHECK-SANA-SANL-NO-SANA-X86: "-fsanitize=leak"
+
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN
 // CHECK-MSAN: "-fno-assume-sane-operator-new"
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -4730,7 +4730,7 @@
   Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
-  if (IsX86_64 || IsMIPS64 || IsAArch64)
+  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
 Res |= SanitizerKind::Thread;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29128: [OpenMP] Support for the proc_bind-clause on 'target parallel' on the NVPTX device.

2017-01-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D29128



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


[PATCH] D29128: [OpenMP] Support for the proc_bind-clause on 'target parallel' on the NVPTX device.

2017-01-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293069: [OpenMP] Support for the proc_bind-clause on 'target 
parallel' on the NVPTX… (authored by arpith).

Changed prior to commit:
  https://reviews.llvm.org/D29128?vs=85759=85765#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29128

Files:
  cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp

Index: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -642,6 +642,17 @@
 llvm_unreachable("OpenMP NVPTX can only handle device code.");
 }
 
+void CGOpenMPRuntimeNVPTX::emitProcBindClause(CodeGenFunction ,
+  OpenMPProcBindClauseKind ProcBind,
+  SourceLocation Loc) {
+  // Do nothing in case of Spmd mode and L0 parallel.
+  // TODO: If in Spmd mode and L1 parallel emit the clause.
+  if (isInSpmdExecutionMode())
+return;
+
+  CGOpenMPRuntime::emitProcBindClause(CGF, ProcBind, Loc);
+}
+
 void CGOpenMPRuntimeNVPTX::emitNumThreadsClause(CodeGenFunction ,
 llvm::Value *NumThreads,
 SourceLocation Loc) {
Index: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
===
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
@@ -170,6 +170,12 @@
 public:
   explicit CGOpenMPRuntimeNVPTX(CodeGenModule );
 
+  /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
+  /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
+  virtual void emitProcBindClause(CodeGenFunction ,
+  OpenMPProcBindClauseKind ProcBind,
+  SourceLocation Loc) override;
+
   /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32
   /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads'
   /// clause.
Index: cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
===
--- cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
+++ cfe/trunk/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
@@ -0,0 +1,106 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -fexceptions -fcxx-exceptions -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// Check that the execution mode of all 3 target regions on the gpu is set to SPMD Mode.
+// CHECK-DAG: {{@__omp_offloading_.+l22}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l26}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l31}}_exec_mode = weak constant i8 0
+
+template
+tx ftemplate(int n) {
+  tx a = 0;
+  short aa = 0;
+  tx b[10];
+
+  #pragma omp target parallel proc_bind(master)
+  {
+  }
+
+  #pragma omp target parallel proc_bind(spread)
+  {
+aa += 1;
+  }
+
+  #pragma omp target parallel proc_bind(close)
+  {
+a += 1;
+aa += 1;
+b[2] += 1;
+  }
+
+  return a;
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l22}}(
+  // CHECK: call void @__kmpc_spmd_kernel_init(
+  // CHECK: br label {{%?}}[[EXEC:.+]]
+  //
+  // CHECK: [[EXEC]]
+  // CHECK-NOT: call void @__kmpc_push_proc_bind
+  // CHECK: {{call|invoke}} void [[OP1:@.+]](i32* null, i32* null
+  // CHECK: br label {{%?}}[[DONE:.+]]
+  //
+  // CHECK: 

[PATCH] D28814: [OpenCL] Add missing address spaces in IR generation of Blocks

2017-01-25 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:723
+? CGM.getNSConcreteStackBlock()
+: llvm::Constant::getNullValue(
+  CGM.getNSConcreteStackBlock()->getType());

yaxunl wrote:
> should use CGM.getNullPointer to create a null pointer.
Btw, does it mean we can no longer use generic llvm::Constant::getNullValue 
helper for PointerTypes? This feels wrong! Is it possible to extend the helper?

Also I find it a bit counter intuitive to use getNullPointer with the second 
argument QualType for the case like this where we don't have an actual AST 
type. Why is it needed? Some documentation might be helpful here. :) Could we 
extend this helper to use default second argument or an overload with one 
argument only. 


https://reviews.llvm.org/D28814



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


[PATCH] D29128: [OpenMP] Support for the proc_bind-clause on 'target parallel' on the NVPTX device.

2017-01-25 Thread Arpith Jacob via Phabricator via cfe-commits
arpith-jacob created this revision.
Herald added a subscriber: jholewinski.

This patch adds support for the proc_bind clause on the Spmd construct
'target parallel' on the NVPTX device.  Since the parallel region is created
upon kernel launch, this clause can be safely ignored on the NVPTX device at
codegen time for level 0 parallelism.


https://reviews.llvm.org/D29128

Files:
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp

Index: test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
===
--- /dev/null
+++ test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
@@ -0,0 +1,106 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -fexceptions -fcxx-exceptions -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// Check that the execution mode of all 3 target regions on the gpu is set to SPMD Mode.
+// CHECK-DAG: {{@__omp_offloading_.+l22}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l26}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l31}}_exec_mode = weak constant i8 0
+
+template
+tx ftemplate(int n) {
+  tx a = 0;
+  short aa = 0;
+  tx b[10];
+
+  #pragma omp target parallel proc_bind(master)
+  {
+  }
+
+  #pragma omp target parallel proc_bind(spread)
+  {
+aa += 1;
+  }
+
+  #pragma omp target parallel proc_bind(close)
+  {
+a += 1;
+aa += 1;
+b[2] += 1;
+  }
+
+  return a;
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l22}}(
+  // CHECK: call void @__kmpc_spmd_kernel_init(
+  // CHECK: br label {{%?}}[[EXEC:.+]]
+  //
+  // CHECK: [[EXEC]]
+  // CHECK-NOT: call void @__kmpc_push_proc_bind
+  // CHECK: {{call|invoke}} void [[OP1:@.+]](i32* null, i32* null
+  // CHECK: br label {{%?}}[[DONE:.+]]
+  //
+  // CHECK: [[DONE]]
+  // CHECK: call void @__kmpc_spmd_kernel_deinit()
+  // CHECK: br label {{%?}}[[EXIT:.+]]
+  //
+  // CHECK: [[EXIT]]
+  // CHECK: ret void
+  // CHECK: }
+
+
+
+
+
+  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l26}}(
+  // CHECK: call void @__kmpc_spmd_kernel_init(
+  // CHECK: br label {{%?}}[[EXEC:.+]]
+  //
+  // CHECK: [[EXEC]]
+  // CHECK-NOT: call void @__kmpc_push_proc_bind
+  // CHECK: {{call|invoke}} void [[OP1:@.+]](i32* null, i32* null
+  // CHECK: br label {{%?}}[[DONE:.+]]
+  //
+  // CHECK: [[DONE]]
+  // CHECK: call void @__kmpc_spmd_kernel_deinit()
+  // CHECK: br label {{%?}}[[EXIT:.+]]
+  //
+  // CHECK: [[EXIT]]
+  // CHECK: ret void
+  // CHECK: }
+
+
+
+
+  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l31}}(
+  // CHECK: call void @__kmpc_spmd_kernel_init(
+  // CHECK: br label {{%?}}[[EXEC:.+]]
+  //
+  // CHECK: [[EXEC]]
+  // CHECK-NOT: call void @__kmpc_push_proc_bind
+  // CHECK: {{call|invoke}} void [[OP1:@.+]](i32* null, i32* null
+  // CHECK: br label {{%?}}[[DONE:.+]]
+  //
+  // CHECK: [[DONE]]
+  // CHECK: call void @__kmpc_spmd_kernel_deinit()
+  // CHECK: br label {{%?}}[[EXIT:.+]]
+  //
+  // CHECK: [[EXIT]]
+  // CHECK: ret void
+  // CHECK: }
+#endif
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.h
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.h
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.h
@@ -170,6 +170,12 @@
 public:
   explicit CGOpenMPRuntimeNVPTX(CodeGenModule );
 
+  /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
+  /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
+  virtual void emitProcBindClause(CodeGenFunction ,
+  OpenMPProcBindClauseKind ProcBind,
+  SourceLocation Loc) 

[PATCH] D28814: [OpenCL] Add missing address spaces in IR generation of Blocks

2017-01-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:726
+   CGM.getNSConcreteStackBlock()->getType()),
+   QualType());
   isa = llvm::ConstantExpr::getBitCast(isa, VoidPtrTy);

The QualType needs to be the real QualType corresponding to the LLVM type, 
otherwise it won't work on targets with non-zero null pointer.



Comment at: lib/CodeGen/CGBlocks.cpp:1129
+   CGM.getNSConcreteGlobalBlock()->getType()),
+   QualType()));
 

same issue as above.



Comment at: test/CodeGenOpenCL/cl20-device-side-enqueue.cl:3
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o 
- -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=COMMON 
--check-prefix=B64
 
 typedef void (^bl_t)(local void *);

Can we add a run line for triple amdgcn-amd-amdhsa-opencl to make sure the null 
pointer is generated correctly?


https://reviews.llvm.org/D28814



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


[PATCH] D28814: [OpenCL] Add missing address spaces in IR generation of Blocks

2017-01-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:723
+? CGM.getNSConcreteStackBlock()
+: llvm::Constant::getNullValue(
+  CGM.getNSConcreteStackBlock()->getType());

Anastasia wrote:
> yaxunl wrote:
> > should use CGM.getNullPointer to create a null pointer.
> Btw, does it mean we can no longer use generic llvm::Constant::getNullValue 
> helper for PointerTypes? This feels wrong! Is it possible to extend the 
> helper?
> 
> Also I find it a bit counter intuitive to use getNullPointer with the second 
> argument QualType for the case like this where we don't have an actual AST 
> type. Why is it needed? Some documentation might be helpful here. :) Could we 
> extend this helper to use default second argument or an overload with one 
> argument only. 
The LLVM type may not have sufficient information, so in general situation 
QualType is needed. The comment before getNullPointer declaration explains the 
meaning of the parameters:

```
  /// Get target specific null pointer.
  /// \param T is the LLVM type of the null pointer.
  /// \param QT is the clang QualType of the null pointer.
  /// \return ConstantPointerNull with the given type \p T.
  /// Each target can override it to return its own desired constant value.
  virtual llvm::Constant *getNullPointer(const CodeGen::CodeGenModule ,
  llvm::PointerType *T, QualType QT) const;
```



https://reviews.llvm.org/D28814



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


[PATCH] D29157: [libc++] Make _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS export members

2017-01-25 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai created this revision.

When building libc++ with hidden visibility, we want explicit template
instantiations to export members. This is consistent with existing
Windows behavior, and is necessary for clients to be able to link
against a hidden visibility built libc++ without running into lots of
missing symbols.

An unfortunate side effect, however, is that any template methods of a
class with an explicit instantiation will get default visibility when
instantiated, unless the methods are explicitly marked inline or hidden
visibility. This is not desirable for clients of libc++ headers who wish
to control their visibility, and led to PR30642.

Annotate all problematic methods with an explicit visibility specifier
to avoid this. The problematic methods were found by running
https://github.com/smeenai/bad-visibility-finder against the libc++
headers after making the _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS change. The
small methods were marked for inlining; the larger ones hidden.

It should be noted that _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS was originally
intended to expand to default visibility, and was changed to expanding
to default type visibility to fix PR30642. The visibility macro
documentation was not updated accordingly, however, so this change makes
the macro consistent with its documentation again, while explicitly
fixing the methods which resulted in that PR.


https://reviews.llvm.org/D29157

Files:
  include/__config
  include/locale
  include/string

Index: include/string
===
--- include/string
+++ include/string
@@ -792,6 +792,7 @@
 basic_string(const basic_string& __str, size_type __pos,
  const allocator_type& __a = allocator_type());
 template
+_LIBCPP_HIDDEN
 basic_string(const _Tp& __t, size_type __pos, size_type __n, 
  const allocator_type& __a = allocator_type(),
  typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0);
@@ -927,6 +928,7 @@
 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
 template 
+_LIBCPP_HIDDEN
 typename enable_if
 <
 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
@@ -988,6 +990,7 @@
 #endif
 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
 template 
+_LIBCPP_HIDDEN
 typename enable_if
 <
 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
@@ -998,14 +1001,16 @@
 basic_string& assign(const value_type* __s);
 basic_string& assign(size_type __n, value_type __c);
 template
+_LIBCPP_HIDDEN
 typename enable_if
 <
__is_exactly_input_iterator<_InputIterator>::value
 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
 basic_string&
 >::type
 assign(_InputIterator __first, _InputIterator __last);
 template
+_LIBCPP_HIDDEN
 typename enable_if
 <
 __is_forward_iterator<_ForwardIterator>::value
@@ -1023,6 +1028,7 @@
 _LIBCPP_INLINE_VISIBILITY
 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
 template 
+_LIBCPP_HIDDEN
 typename enable_if
 <
 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
@@ -1037,14 +1043,16 @@
 _LIBCPP_INLINE_VISIBILITY
 iterator  insert(const_iterator __pos, size_type __n, value_type __c);
 template
+_LIBCPP_HIDDEN
 typename enable_if
 <
__is_exactly_input_iterator<_InputIterator>::value
 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
 iterator
 >::type
 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
 template
+_LIBCPP_HIDDEN
 typename enable_if
 <
 __is_forward_iterator<_ForwardIterator>::value
@@ -1070,6 +1078,7 @@
 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); }
 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
 template 
+_LIBCPP_HIDDEN
 typename enable_if
 <
 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
@@ -1090,6 +1099,7 @@
 _LIBCPP_INLINE_VISIBILITY
 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
 template
+inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
 __is_input_iterator<_InputIterator>::value,
Index: 

<    7   8   9   10   11   12   13   14   15   16   >