Re: [libcxx] r309474 - [libc++] Hoist extern template above first use

2017-07-28 Thread Shoaib Meenai via cfe-commits
Marshall, Eric, Hans,

Any objections to backporting this to 5.0? It fixes a potential visibility
issue for clients of the header.

On 7/28/17, 7:54 PM, "cfe-commits on behalf of Shoaib Meenai via cfe-commits" 
 
wrote:

Author: smeenai
Date: Fri Jul 28 19:54:41 2017
New Revision: 309474

URL: 
https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D309474-26view-3Drev=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=EcGbIxegCOTbSLMJelp_vOaeGiS_iQ1eciM_oeX41-E=5q7TS5mhaUsf-1jQBqX62RvjcqAiy2whh8RO7yFhPyA=
 
Log:
[libc++] Hoist extern template above first use

This function template is referenced inside class basic_string as a
friend function. The extern template declaration needs to be above that
friend declaration to actually take effect.

This is important because this function was marked as exported in
r307966, so without the extern template taking effect, it can leak into
other DSOs as a visible symbol.

Modified:
libcxx/trunk/include/string

Modified: libcxx/trunk/include/string
URL: 
https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_libcxx_trunk_include_string-3Frev-3D309474-26r1-3D309473-26r2-3D309474-26view-3Ddiff=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=EcGbIxegCOTbSLMJelp_vOaeGiS_iQ1eciM_oeX41-E=zFJXc9CA6Sgyh25kGeAh4Qo36gpNQX_zo2qRlRFJoL8=
 

==
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Fri Jul 28 19:54:41 2017
@@ -556,6 +556,8 @@ template
 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT 
__y);
 
+_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+(char const*, string const&))
+
 template 
 class _LIBCPP_TEMPLATE_VIS __basic_string_common
 {
@@ -3999,7 +4001,6 @@ basic_string<_CharT, _Traits, _Allocator
 
 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 
basic_string)
 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 
basic_string)
-_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+(char const*, string const&))
 
 #if _LIBCPP_STD_VER > 11 
 // Literal suffixes for basic_string [basic.string.literals]


___
cfe-commits mailing list
cfe-commits@lists.llvm.org

https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Dcommits=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=EcGbIxegCOTbSLMJelp_vOaeGiS_iQ1eciM_oeX41-E=95GYNfQT_kBVjYvYRYnF3mje6PEyF4EDl4MCBQKCu88=
 


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


[libcxx] r309474 - [libc++] Hoist extern template above first use

2017-07-28 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Fri Jul 28 19:54:41 2017
New Revision: 309474

URL: http://llvm.org/viewvc/llvm-project?rev=309474=rev
Log:
[libc++] Hoist extern template above first use

This function template is referenced inside class basic_string as a
friend function. The extern template declaration needs to be above that
friend declaration to actually take effect.

This is important because this function was marked as exported in
r307966, so without the extern template taking effect, it can leak into
other DSOs as a visible symbol.

Modified:
libcxx/trunk/include/string

Modified: libcxx/trunk/include/string
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=309474=309473=309474=diff
==
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Fri Jul 28 19:54:41 2017
@@ -556,6 +556,8 @@ template
 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
 
+_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+(char const*, string const&))
+
 template 
 class _LIBCPP_TEMPLATE_VIS __basic_string_common
 {
@@ -3999,7 +4001,6 @@ basic_string<_CharT, _Traits, _Allocator
 
 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 
basic_string)
 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 
basic_string)
-_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+(char const*, string const&))
 
 #if _LIBCPP_STD_VER > 11 
 // Literal suffixes for basic_string [basic.string.literals]


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


[PATCH] D35693: [Driver][Darwin] Pass -munwind-table when !UseSjLjExceptions

2017-07-28 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Okay.  Sounds fine to me.


https://reviews.llvm.org/D35693



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


[libcxx] r309468 - [libcxx] [test] Change comments to say C++ instead of c++. NFC.

2017-07-28 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Fri Jul 28 17:55:35 2017
New Revision: 309468

URL: http://llvm.org/viewvc/llvm-project?rev=309468=rev
Log:
[libcxx] [test] Change comments to say C++ instead of c++. NFC.

This makes them consistent (many comments already used uppercase).

The special REQUIRES, UNSUPPORTED, and XFAIL comments are excluded from this 
change.

Modified:
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp

libcxx/trunk/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp

libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp

libcxx/trunk/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp

libcxx/trunk/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp

libcxx/trunk/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp

libcxx/trunk/test/std/experimental/language.support/support.coroutines/end.to.end/fullexpr-dtor.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.cons/default.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.cons/iter.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.cons/reverse_iterator.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.make/make_reverse_iterator.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.op!=/test.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.op++/post.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.op++/pre.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.op+/difference_type.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.op-/difference_type.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.op.star/op_star.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.op=/reverse_iterator.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.op==/test.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.opdiff/test.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.opgt/test.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.opgt=/test.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.oplt/test.pass.cpp

libcxx/trunk/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.oplt=/test.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
libcxx/trunk/test/std/language.support/support.types/nullptr_t.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.nonmembers/string.special/swap_noexcept.pass.cpp
libcxx/trunk/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp

libcxx/trunk/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.single.pass.cpp

libcxx/trunk/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++.pass.cpp

libcxx/trunk/test/std/utilities/time/time.duration/time.duration.arithmetic/op_++int.pass.cpp

libcxx/trunk/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+=.pass.cpp

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp?rev=309468=309467=309468=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp 
Fri Jul 28 17:55:35 2017
@@ -26,7 +26,7 @@ int main()
 int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
 int ib[] = {0, 1, 2, 3, 0, 1, 2, 3};
-const unsigned sb = sizeof(ib)/sizeof(ib[0]); ((void)sb); // unused in 
c++11
+const unsigned sb = sizeof(ib)/sizeof(ib[0]); ((void)sb); // unused in 
C++11
 
 typedef 

[libcxx] r309465 - [libcxx] [test] Make files consistently end with newlines, NFC.

2017-07-28 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Fri Jul 28 17:55:22 2017
New Revision: 309465

URL: http://llvm.org/viewvc/llvm-project?rev=309465=rev
Log:
[libcxx] [test] Make files consistently end with newlines, NFC.

Modified:
libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp

libcxx/trunk/test/libcxx/containers/sequences/list/list.modifiers/insert_iter_rvalue_db1.pass.cpp

libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp
libcxx/trunk/test/libcxx/type_traits/lazy_metafunctions.pass.cpp

libcxx/trunk/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp

libcxx/trunk/test/libcxx/utilities/tuple/tuple.tuple/diagnose_reference_binding.pass.cpp

libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_or_assign.pass.cpp

libcxx/trunk/test/std/experimental/memory/memory.resource/memory.resource.priv/protected_members.fail.cpp

libcxx/trunk/test/std/experimental/string.view/string.view.cons/from_string1.fail.cpp
libcxx/trunk/test/std/language.support/support.dynamic/align_val_t.pass.cpp

libcxx/trunk/test/std/strings/string.view/string.view.cons/from_string1.fail.cpp

libcxx/trunk/test/std/utilities/function.objects/func.invoke/invoke_feature_test_macro.pass.cpp

libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.value/uninitialized_value_construct_n.pass.cpp

libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move.pass.cpp

libcxx/trunk/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move_n.pass.cpp
libcxx/trunk/test/support/test_convertible.hpp

Modified: libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp?rev=309465=309464=309465=diff
==
--- libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/algorithms/debug_less.pass.cpp Fri Jul 28 17:55:22 
2017
@@ -164,4 +164,4 @@ void test_failing() {
 int main() {
 test_passing();
 test_failing();
-}
\ No newline at end of file
+}

Modified: 
libcxx/trunk/test/libcxx/containers/sequences/list/list.modifiers/insert_iter_rvalue_db1.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/containers/sequences/list/list.modifiers/insert_iter_rvalue_db1.pass.cpp?rev=309465=309464=309465=diff
==
--- 
libcxx/trunk/test/libcxx/containers/sequences/list/list.modifiers/insert_iter_rvalue_db1.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/containers/sequences/list/list.modifiers/insert_iter_rvalue_db1.pass.cpp
 Fri Jul 28 17:55:22 2017
@@ -27,4 +27,4 @@ int main()
 std::list v2(3);
 v1.insert(v2.begin(), 4);
 assert(false);
-}
\ No newline at end of file
+}

Modified: 
libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp?rev=309465=309464=309465=diff
==
--- 
libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/experimental/filesystem/class.path/path.itr/iterator_db.pass.cpp
 Fri Jul 28 17:55:22 2017
@@ -71,4 +71,4 @@ int main() {
   assert(false);
 } catch (int) {}
   }
-}
\ No newline at end of file
+}

Modified: libcxx/trunk/test/libcxx/type_traits/lazy_metafunctions.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/type_traits/lazy_metafunctions.pass.cpp?rev=309465=309464=309465=diff
==
--- libcxx/trunk/test/libcxx/type_traits/lazy_metafunctions.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/type_traits/lazy_metafunctions.pass.cpp Fri Jul 28 
17:55:22 2017
@@ -134,4 +134,4 @@ int main() {
 LazyNotTest();
 LazyAndTest();
 LazyOrTest();
-}
\ No newline at end of file
+}

Modified: 
libcxx/trunk/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp?rev=309465=309464=309465=diff
==
--- 
libcxx/trunk/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp
 Fri Jul 28 17:55:22 2017
@@ -213,4 +213,4 @@ int main() {
 TestCase::run();
 TestCase::run();
 TestCase::run();
-}
\ No newline at end of file
+}


[libcxx] r309467 - [libcxx] [test] The entire file futures.shared_future/wait_until.pass.cpp was indented by 1 space. NFC.

2017-07-28 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Fri Jul 28 17:55:27 2017
New Revision: 309467

URL: http://llvm.org/viewvc/llvm-project?rev=309467=rev
Log:
[libcxx] [test] The entire file futures.shared_future/wait_until.pass.cpp was 
indented by 1 space. NFC.

Modified:

libcxx/trunk/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp

Modified: 
libcxx/trunk/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp?rev=309467=309466=309467=diff
==
--- 
libcxx/trunk/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp 
Fri Jul 28 17:55:27 2017
@@ -1,130 +1,130 @@
- 
//===--===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is dual licensed under the MIT and the University of Illinois 
Open
- // Source Licenses. See LICENSE.TXT for details.
- //
- 
//===--===//
- //
- // UNSUPPORTED: libcpp-has-no-threads
- // UNSUPPORTED: c++98, c++03
-
- // 
-
- // class shared_future
-
- // template 
- //   future_status
- //   wait_until(const chrono::time_point& abs_time) const;
-
- #include 
- #include 
- #include 
-
- enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting };
- typedef std::chrono::milliseconds ms;
-
- std::atomic thread_state(WorkerThreadState::Uninitialized);
-
- void set_worker_thread_state(WorkerThreadState state)
- {
- thread_state.store(state, std::memory_order_relaxed);
- }
-
- void wait_for_worker_thread_state(WorkerThreadState state)
- {
- while (thread_state.load(std::memory_order_relaxed) != state);
- }
-
- void func1(std::promise p)
- {
- wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
- p.set_value(3);
- set_worker_thread_state(WorkerThreadState::Exiting);
- }
-
- int j = 0;
-
- void func3(std::promise p)
- {
- wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
- j = 5;
- p.set_value(j);
- set_worker_thread_state(WorkerThreadState::Exiting);
- }
-
- void func5(std::promise p)
- {
- wait_for_worker_thread_state(WorkerThreadState::AllowedToRun);
- p.set_value();
- set_worker_thread_state(WorkerThreadState::Exiting);
- }
-
- int main()
- {
- typedef std::chrono::high_resolution_clock Clock;
- {
- typedef int T;
- std::promise p;
- std::shared_future f = p.get_future();
- std::thread(func1, std::move(p)).detach();
- assert(f.valid());
- assert(f.wait_until(Clock::now() + ms(10)) == 
std::future_status::timeout);
- assert(f.valid());
-
- // allow the worker thread to produce the result and wait until the 
worker is done
- set_worker_thread_state(WorkerThreadState::AllowedToRun);
- wait_for_worker_thread_state(WorkerThreadState::Exiting);
-
- assert(f.wait_until(Clock::now() + ms(10)) == 
std::future_status::ready);
- assert(f.valid());
- Clock::time_point t0 = Clock::now();
- f.wait();
- Clock::time_point t1 = Clock::now();
- assert(f.valid());
- assert(t1-t0 < ms(5));
- }
- {
- typedef int& T;
- std::promise p;
- std::shared_future f = p.get_future();
- std::thread(func3, std::move(p)).detach();
- assert(f.valid());
- assert(f.wait_until(Clock::now() + ms(10)) == 
std::future_status::timeout);
- assert(f.valid());
-
- // allow the worker thread to produce the result and wait until the 
worker is done
- set_worker_thread_state(WorkerThreadState::AllowedToRun);
- wait_for_worker_thread_state(WorkerThreadState::Exiting);
-
- assert(f.wait_until(Clock::now() + ms(10)) == 
std::future_status::ready);
- assert(f.valid());
- Clock::time_point t0 = Clock::now();
- f.wait();
- Clock::time_point t1 = Clock::now();
- assert(f.valid());
- assert(t1-t0 < ms(5));
- }
- {
- typedef void T;
- std::promise p;
- std::shared_future f = p.get_future();
- std::thread(func5, std::move(p)).detach();
- assert(f.valid());
- assert(f.wait_until(Clock::now() + ms(10)) == 
std::future_status::timeout);
- assert(f.valid());
-
- // allow the worker thread to produce the result and wait until the 
worker is done
- set_worker_thread_state(WorkerThreadState::AllowedToRun);
- wait_for_worker_thread_state(WorkerThreadState::Exiting);
-
- assert(f.wait_until(Clock::now() + ms(10)) == 
std::future_status::ready);
- assert(f.valid());
- Clock::time_point 

[libcxx] r309466 - [libcxx] [test] In func.wrap.func.con/alloc_F.pass.cpp, fix REQUIRES whitespace. NFC.

2017-07-28 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Fri Jul 28 17:55:25 2017
New Revision: 309466

URL: http://llvm.org/viewvc/llvm-project?rev=309466=rev
Log:
[libcxx] [test] In func.wrap.func.con/alloc_F.pass.cpp, fix REQUIRES 
whitespace. NFC.

Modified:

libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp?rev=309466=309465=309466=diff
==
--- 
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp
 Fri Jul 28 17:55:25 2017
@@ -8,7 +8,7 @@
 
//===--===//
 
 // 
-// REQUIRES: c++98 || c++03 || c++11 ||c++14
+// REQUIRES: c++98 || c++03 || c++11 || c++14
 
 // class function
 


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


[libcxx] r309463 - [libcxx] [test] Strip trailing whitespace, NFC.

2017-07-28 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Fri Jul 28 17:54:49 2017
New Revision: 309463

URL: http://llvm.org/viewvc/llvm-project?rev=309463=rev
Log:
[libcxx] [test] Strip trailing whitespace, NFC.

Modified:

libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp

Modified: 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp?rev=309463=309462=309463=diff
==
--- 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp
 Fri Jul 28 17:54:49 2017
@@ -13,7 +13,7 @@
 // template
 // OutputIterator inclusive_scan(InputIterator first, InputIterator last,
 //   OutputIterator result, T init);
-// 
+//
 
 #include 
 #include 
@@ -26,7 +26,7 @@ void
 test(Iter1 first, Iter1 last, Iter2 rFirst, Iter2 rLast)
 {
 std::vector::value_type> v;
-
+
 //  Not in place
 std::inclusive_scan(first, last, std::back_inserter(v));
 assert(std::equal(v.begin(), v.end(), rFirst, rLast));
@@ -35,7 +35,7 @@ test(Iter1 first, Iter1 last, Iter2 rFir
 v.clear();
 v.assign(first, last);
 std::inclusive_scan(v.begin(), v.end(), v.begin());
-assert(std::equal(v.begin(), v.end(), rFirst, rLast));  
+assert(std::equal(v.begin(), v.end(), rFirst, rLast));
 }
 
 

Modified: 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp?rev=309463=309462=309463=diff
==
--- 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp
 Fri Jul 28 17:54:49 2017
@@ -13,7 +13,7 @@
 // template
 // OutputIterator
 // inclusive_scan(InputIterator first, InputIterator last,
-//OutputIterator result, 
+//OutputIterator result,
 //BinaryOperation binary_op); // C++17
 
 #include 
@@ -37,7 +37,7 @@ test(Iter1 first, Iter1 last, Op op, Ite
 v.clear();
 v.assign(first, last);
 std::inclusive_scan(v.begin(), v.end(), v.begin(), op);
-assert(std::equal(v.begin(), v.end(), rFirst, rLast));  
+assert(std::equal(v.begin(), v.end(), rFirst, rLast));
 }
 
 
@@ -99,7 +99,7 @@ int main()
 {
 
 basic_tests();
-
+
 //  All the iterator categories
 // test >();
 // test >();
@@ -109,4 +109,3 @@ int main()
 // test<  int*>();
 
 }
- 
\ No newline at end of file

Modified: 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp?rev=309463=309462=309463=diff
==
--- 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp
 Fri Jul 28 17:54:49 2017
@@ -13,7 +13,7 @@
 // template
 // OutputIterator
 // inclusive_scan(InputIterator first, InputIterator last,
-//OutputIterator result, 
+//OutputIterator result,
 //BinaryOperation binary_op, T init); // C++17
 
 #include 
@@ -36,7 +36,7 @@ test(Iter1 first, Iter1 last, Op op, T i
 v.clear();
 v.assign(first, last);
 std::inclusive_scan(v.begin(), v.end(), v.begin(), op, init);
-assert(std::equal(v.begin(), v.end(), rFirst, rLast));  
+assert(std::equal(v.begin(), v.end(), rFirst, rLast));
 }
 
 
@@ -115,7 +115,7 @@ int main()
 {
 
 basic_tests();
-
+
 //  All the iterator categories
 test >();
 test >();
@@ -125,4 +125,3 @@ int main()
 test<  int*>();
 
 }
- 
\ No newline at end of file

Modified: 
libcxx/trunk/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp
URL: 

[PATCH] D34590: [ubsan] Diagnose invalid uses of builtins (clang)

2017-07-28 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309459: [ubsan] Diagnose invalid uses of builtins (clang) 
(authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D34590?vs=103827=108753#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34590

Files:
  cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
  cfe/trunk/include/clang/Basic/Sanitizers.def
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/CodeGen/ubsan-builtin-checks.c
  cfe/trunk/test/Driver/fsanitize.c

Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -3,27 +3,27 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize-undefined-trap-on-error -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
-// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}}
-// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
-// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
+// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute|function),?){19}"}}
+// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
+// CHECK-UNDEFINED-TRAP2: "-fsanitize-trap=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,unreachable,vla-bound"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED
-// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){19}"}}
+// CHECK-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|vptr|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){20}"}}
 
 // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-DARWIN
-// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
+// CHECK-UNDEFINED-DARWIN: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute),?){18}"}}
 
 // RUN: %clang -target i386-unknown-openbsd -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-OPENBSD
-// CHECK-UNDEFINED-OPENBSD: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|returns-nonnull-attribute|nonnull-attribute),?){17}"}}
+// CHECK-UNDEFINED-OPENBSD: 

[PATCH] D34591: [ubsan] Diagnose invalid uses of builtins (compiler-rt)

2017-07-28 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309461: [ubsan] Diagnose invalid uses of builtins 
(compiler-rt) (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D34591?vs=103828=108754#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34591

Files:
  compiler-rt/trunk/lib/ubsan/ubsan_checks.inc
  compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
  compiler-rt/trunk/lib/ubsan/ubsan_handlers.h
  compiler-rt/trunk/lib/ubsan/ubsan_interface.inc
  compiler-rt/trunk/test/ubsan/TestCases/Misc/builtins.cpp
  compiler-rt/trunk/test/ubsan/lit.common.cfg

Index: compiler-rt/trunk/test/ubsan/TestCases/Misc/builtins.cpp
===
--- compiler-rt/trunk/test/ubsan/TestCases/Misc/builtins.cpp
+++ compiler-rt/trunk/test/ubsan/TestCases/Misc/builtins.cpp
@@ -0,0 +1,35 @@
+// REQUIRES: arch=x86_64
+//
+// RUN: %clangxx -fsanitize=builtin -w %s -O3 -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER
+// RUN: %clangxx -fsanitize=builtin -fno-sanitize-recover=builtin -w %s -O3 -o %t.abort
+// RUN: not %run %t.abort 2>&1 | FileCheck %s --check-prefix=ABORT
+
+void check_ctz(int n) {
+  // ABORT: builtins.cpp:[[@LINE+2]]:17: runtime error: passing zero to ctz(), which is not a valid argument
+  // RECOVER: builtins.cpp:[[@LINE+1]]:17: runtime error: passing zero to ctz(), which is not a valid argument
+  __builtin_ctz(n);
+
+  // RECOVER: builtins.cpp:[[@LINE+1]]:18: runtime error: passing zero to ctz(), which is not a valid argument
+  __builtin_ctzl(n);
+
+  // RECOVER: builtins.cpp:[[@LINE+1]]:19: runtime error: passing zero to ctz(), which is not a valid argument
+  __builtin_ctzll(n);
+}
+
+void check_clz(int n) {
+  // RECOVER: builtins.cpp:[[@LINE+1]]:17: runtime error: passing zero to clz(), which is not a valid argument
+  __builtin_clz(n);
+
+  // RECOVER: builtins.cpp:[[@LINE+1]]:18: runtime error: passing zero to clz(), which is not a valid argument
+  __builtin_clzl(n);
+
+  // RECOVER: builtins.cpp:[[@LINE+1]]:19: runtime error: passing zero to clz(), which is not a valid argument
+  __builtin_clzll(n);
+}
+
+int main() {
+  check_ctz(0);
+  check_clz(0);
+  return 0;
+}
Index: compiler-rt/trunk/test/ubsan/lit.common.cfg
===
--- compiler-rt/trunk/test/ubsan/lit.common.cfg
+++ compiler-rt/trunk/test/ubsan/lit.common.cfg
@@ -77,3 +77,5 @@
 # because the test hangs or fails on one configuration and not the other.
 if config.target_arch.startswith('arm') == False and config.target_arch != 'aarch64':
   config.available_features.add('stable-runtime')
+
+config.available_features.add('arch=' + config.target_arch)
Index: compiler-rt/trunk/lib/ubsan/ubsan_handlers.h
===
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.h
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.h
@@ -122,6 +122,21 @@
 /// \brief Handle a load of an invalid value for the type.
 RECOVERABLE(load_invalid_value, InvalidValueData *Data, ValueHandle Val)
 
+/// Known builtin check kinds.
+/// Keep in sync with the enum of the same name in CodeGenFunction.h
+enum BuiltinCheckKind : unsigned char {
+  BCK_CTZPassedZero,
+  BCK_CLZPassedZero,
+};
+
+struct InvalidBuiltinData {
+  SourceLocation Loc;
+  unsigned char Kind;
+};
+
+/// Handle a builtin called in an invalid way.
+RECOVERABLE(invalid_builtin, InvalidBuiltinData *Data)
+
 struct FunctionTypeMismatchData {
   SourceLocation Loc;
   const TypeDescriptor 
Index: compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
===
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
@@ -437,6 +437,30 @@
   Die();
 }
 
+static void handleInvalidBuiltin(InvalidBuiltinData *Data, ReportOptions Opts) {
+  SourceLocation Loc = Data->Loc.acquire();
+  ErrorType ET = ErrorType::InvalidBuiltin;
+
+  if (ignoreReport(Loc, Opts, ET))
+return;
+
+  ScopedReport R(Opts, Loc, ET);
+
+  Diag(Loc, DL_Error,
+   "passing zero to %0, which is not a valid argument")
+<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
+}
+
+void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {
+  GET_REPORT_OPTIONS(true);
+  handleInvalidBuiltin(Data, Opts);
+}
+void __ubsan::__ubsan_handle_invalid_builtin_abort(InvalidBuiltinData *Data) {
+  GET_REPORT_OPTIONS(true);
+  handleInvalidBuiltin(Data, Opts);
+  Die();
+}
+
 static void handleFunctionTypeMismatch(FunctionTypeMismatchData *Data,
ValueHandle Function,
ReportOptions Opts) {
Index: compiler-rt/trunk/lib/ubsan/ubsan_interface.inc
===
--- compiler-rt/trunk/lib/ubsan/ubsan_interface.inc
+++ compiler-rt/trunk/lib/ubsan/ubsan_interface.inc
@@ -19,6 

r309460 - [test] FileCheck-ify a test to avoid a spurious failure, NFC

2017-07-28 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Jul 28 17:19:52 2017
New Revision: 309460

URL: http://llvm.org/viewvc/llvm-project?rev=309460=rev
Log:
[test] FileCheck-ify a test to avoid a spurious failure, NFC

The path to one of my source trees contains 'builtin' as a substring, so
this test failed. Fix it with FileCheck.

Modified:
cfe/trunk/test/CodeGen/2004-02-20-Builtins.c

Modified: cfe/trunk/test/CodeGen/2004-02-20-Builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2004-02-20-Builtins.c?rev=309460=309459=309460=diff
==
--- cfe/trunk/test/CodeGen/2004-02-20-Builtins.c (original)
+++ cfe/trunk/test/CodeGen/2004-02-20-Builtins.c Fri Jul 28 17:19:52 2017
@@ -1,5 +1,8 @@
-// RUN: %clang_cc1  %s -emit-llvm -o - | not grep builtin
+// RUN: %clang_cc1  %s -emit-llvm -o - | FileCheck %s
 double sqrt(double x);
+
+// CHECK-LABEL: @zsqrtxxx
+// CHECK-NOT: builtin
 void zsqrtxxx(float num) {
num = sqrt(num);
 }


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


r309459 - [ubsan] Diagnose invalid uses of builtins (clang)

2017-07-28 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Fri Jul 28 17:19:51 2017
New Revision: 309459

URL: http://llvm.org/viewvc/llvm-project?rev=309459=rev
Log:
[ubsan] Diagnose invalid uses of builtins (clang)

On some targets, passing zero to the clz() or ctz() builtins has undefined
behavior. I ran into this issue while debugging UB in __hash_table from libcxx:
the bug I was seeing manifested itself differently under -O0 vs -Os, due to a
UB call to clz() (see: libcxx/r304617).

This patch introduces a check which can detect UB calls to builtins.

llvm.org/PR26979

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

Added:
cfe/trunk/test/CodeGen/ubsan-builtin-checks.c
Modified:
cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/docs/UndefinedBehaviorSanitizer.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UndefinedBehaviorSanitizer.rst?rev=309459=309458=309459=diff
==
--- cfe/trunk/docs/UndefinedBehaviorSanitizer.rst (original)
+++ cfe/trunk/docs/UndefinedBehaviorSanitizer.rst Fri Jul 28 17:19:51 2017
@@ -75,6 +75,7 @@ Available checks are:
  of a misaligned reference.
   -  ``-fsanitize=bool``: Load of a ``bool`` value which is neither
  ``true`` nor ``false``.
+  -  ``-fsanitize=builtin``: Passing invalid values to compiler builtins.
   -  ``-fsanitize=bounds``: Out of bounds array indexing, in cases
  where the array bound can be statically determined.
   -  ``-fsanitize=enum``: Load of a value of an enumerated type which

Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=309459=309458=309459=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.def Fri Jul 28 17:19:51 2017
@@ -60,6 +60,7 @@ SANITIZER("leak", Leak)
 SANITIZER("alignment", Alignment)
 SANITIZER("array-bounds", ArrayBounds)
 SANITIZER("bool", Bool)
+SANITIZER("builtin", Builtin)
 SANITIZER("enum", Enum)
 SANITIZER("float-cast-overflow", FloatCastOverflow)
 SANITIZER("float-divide-by-zero", FloatDivideByZero)
@@ -107,11 +108,12 @@ SANITIZER("safe-stack", SafeStack)
 // -fsanitize=undefined includes all the sanitizers which have low overhead, no
 // ABI or address space layout implications, and only catch undefined behavior.
 SANITIZER_GROUP("undefined", Undefined,
-Alignment | Bool | ArrayBounds | Enum | FloatCastOverflow |
-FloatDivideByZero | IntegerDivideByZero | NonnullAttribute 
|
-Null | ObjectSize | PointerOverflow | Return |
-ReturnsNonnullAttribute | Shift | SignedIntegerOverflow |
-Unreachable | VLABound | Function | Vptr)
+Alignment | Bool | Builtin | ArrayBounds | Enum |
+FloatCastOverflow | FloatDivideByZero |
+IntegerDivideByZero | NonnullAttribute | Null | ObjectSize 
|
+PointerOverflow | Return | ReturnsNonnullAttribute | Shift 
|
+SignedIntegerOverflow | Unreachable | VLABound | Function |
+Vptr)
 
 // -fsanitize=undefined-trap is an alias for -fsanitize=undefined.
 SANITIZER_GROUP("undefined-trap", UndefinedTrap, Undefined)

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=309459=309458=309459=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Jul 28 17:19:51 2017
@@ -641,6 +641,26 @@ struct CallObjCArcUse final : EHScopeSta
 };
 }
 
+Value *CodeGenFunction::EmitCheckedArgForBuiltin(const Expr *E,
+ BuiltinCheckKind Kind) {
+  assert(Kind == BCK_CLZPassedZero ||
+ Kind == BCK_CTZPassedZero && "Unsupported builtin check kind");
+
+  Value *ArgValue = EmitScalarExpr(E);
+  if (!SanOpts.has(SanitizerKind::Builtin) || !getTarget().isCLZForZeroUndef())
+return ArgValue;
+
+  SanitizerScope SanScope(this);
+  Value *Cond = Builder.CreateICmpNE(
+  ArgValue, llvm::Constant::getNullValue(ArgValue->getType()));
+  EmitCheck(std::make_pair(Cond, SanitizerKind::Builtin),
+SanitizerHandler::InvalidBuiltin,
+{EmitCheckSourceLocation(E->getExprLoc()),
+ llvm::ConstantInt::get(Builder.getInt8Ty(), Kind)},
+None);
+  return ArgValue;
+}
+
 RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
 unsigned BuiltinID, const CallExpr *E,
 

Re: r309386 - Recommit r308327 3rd time: Add a warning for missing

2017-07-28 Thread Hans Wennborg via cfe-commits
On Fri, Jul 28, 2017 at 7:41 AM, Alex Lorenz via cfe-commits
 wrote:
> Author: arphaman
> Date: Fri Jul 28 07:41:21 2017
> New Revision: 309386
>
> URL: http://llvm.org/viewvc/llvm-project?rev=309386=rev
> Log:
> Recommit r308327 3rd time: Add a warning for missing
> '#pragma pack (pop)' and suspicious uses of '#pragma pack' in included files
>
> The second recommit (r309106) was reverted because the "non-default #pragma
> pack value chages the alignment of struct or union members in the included 
> file"
> warning proved to be too aggressive for external projects like Chromium
> (https://bugs.chromium.org/p/chromium/issues/detail?id=749197). This recommit
> makes the problematic warning a non-default one, and gives it the
> -Wpragma-pack-suspicious-include warning option.
>
> The first recommit (r308441) caused a "non-default #pragma pack value might
> change the alignment of struct or union members in the included file" warning
> in LLVM itself. This recommit tweaks the added warning to avoid warnings for
> #includes that don't have any records that are affected by the non-default
> alignment. This tweak avoids the previously emitted warning in LLVM.
>
> Original message:
>
> This commit adds a new -Wpragma-pack warning. It warns in the following cases:
>
> - When a translation unit is missing terminating #pragma pack (pop) 
> directives.
> - When entering an included file if the current alignment value as determined
>   by '#pragma pack' directives is different from the default alignment value.
> - When leaving an included file that changed the state of the current 
> alignment
>   value.
>
> rdar://10184173
>
> Differential Revision: https://reviews.llvm.org/D35484

We did get warnings with this version too, but this time it looks like
a real bug :-)

C:\b\c\builder\ClangToTWin_dll_\src\third_party\usrsctp\usrsctplib\usrsctplib\netinet\sctp.h(51,9):
 error: unterminated '#pragma pack (push, ...)' at end of file
[-Werror,-Wpragma-pack]

The interesting thing is that the file does reset the alignment, but
it does it with a "#pragma pack()" which doesn't pop the stack, but
just resets to the default value.

It might be worth tweaking the warning to give a better message for
this. A "#pragma pack(push, ..)" followed by "#pragma pack()" seems
pretty dodgy since there's no point in pushing if the code isn't going
to pop.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35923: Fix PR32332 - PCM nondeterminism with builtins caused by global module index

2017-07-28 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

After thinking about this some more, I think it should be safe to use the 
global module index as a negative cache like in this example. The conditions 
under which a module is rebuilt should not affect the contents, and if the 
module were out-of-date it would have been rebuilt anyway.
I will see if I can track down why the builtin macros make it into the module's 
identifier table. We already know that they are being marked incorrectly as 
FromAST, but I do not yet understand why.


https://reviews.llvm.org/D35923



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


[PATCH] D34590: [ubsan] Diagnose invalid uses of builtins (clang)

2017-07-28 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

Looks fine to me.


https://reviews.llvm.org/D34590



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


[PATCH] D35693: [Driver][Darwin] Pass -munwind-table when !UseSjLjExceptions

2017-07-28 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

In https://reviews.llvm.org/D35693#816994, @rjmccall wrote:

> Does the ARM64 ABI call for unwind tables to be emitted for all functions, 
> like the x86-64 ABI does?
>
> Anyway, it seems pretty unfortunate that the default behavior breaks 
> exceptions.


According to Nick Kledzik, the ARM64 ABI doesn't require unwind tables to be 
emitted for all functions, but the compiler has emitted the tables for all 
functions anyway. If I understood his explanation correctly, people often ran 
into problems when mixing C and C++ code because they forgot to use 
-fexceptions. Also, the compact unwind table is already small, so omitting it 
would most likely not make much difference in the size of the executable.

I'm also looking at r291172, which is the commit that directly caused this 
regression.


https://reviews.llvm.org/D35693



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


Re: [PATCH] D35961: [llvm] Update MachOObjectFile::exports interface

2017-07-28 Thread David Blaikie via cfe-commits
On Fri, Jul 28, 2017 at 4:01 PM Kevin Enderby  wrote:

> On Jul 28, 2017, at 10:30 AM, David Blaikie  wrote:
>
>
>
> On Fri, Jul 28, 2017 at 10:24 AM Kevin Enderby  wrote:
>
>> On Jul 27, 2017, at 9:50 PM, Saleem Abdulrasool via Phabricator <
>> revi...@reviews.llvm.org> wrote:
>>
>> compnerd added a comment.
>>
>> Does anyone use the overload with the `O` for `exports` with `nullptr`
>> instead of `this`?  If not, we could just inline `this` throughout.
>>
>>
>> This will break lld as it needs the default nullptr.  See r308691.
>>
>> The reason that O was added was so that this check from r308690 could be
>> added.
>>
>
> When O is specified is it always == this, though? That seems to be implied
> by the original post.
>
> If that's the case, then the ability to pass null is really only passing
> the on/off state for the diagnostic? Is that necessary, or would it be good
> to just always produce the Error, even in lld?
>
>
> Without O one can’t use O->getLibraryCount() which is what is needed for
> the test.  I guess one could change the interface if lld really wanted this
> check. But I’d leave that to the lld folks as to what level of error
> checking they want.
>

No worries - looks like Alex explained the disconnect that there were
different functions under discussion. (:


>
>
>
>>
>> +  if (O != nullptr) {
>> +if (State.Other > O->getLibraryCount()) {
>> +  *E = malformedError("bad library ordinal: " +
>> Twine((int)State.Other)
>> +   + " (max " + Twine((int)O->getLibraryCount()) + ") in
>> export "
>> +   "trie data at node: 0x" + utohexstr(offset));
>> +  moveToEnd();
>> +  return;
>> +}
>>
>> This is needed for the test case:
>>
>> +RUN: not llvm-objdump -macho -exports-trie
>> %p/Inputs/macho-trie-bad-library-ordinal 2>&1 | FileCheck -check-prefix
>> BAD_LIBRARY_ORDINAL %s
>> +BAD_LIBRARY_ORDINAL: macho-trie-bad-library-ordinal': truncated or
>> malformed object (bad library ordinal: 69 (max 3) in export trie data at
>> node: 0x33)
>>
>>
>>
>>
>> 
>> Comment at: tools/llvm-nm/llvm-nm.cpp:1230
>>   Error Err = Error::success();
>> -  for (const llvm::object::ExportEntry  : MachO->exports(Err,
>> -
>>   MachO)) {
>> +  for (const llvm::object::ExportEntry  : MachO->exports(Err))
>> {
>> bool found = false;
>> 
>> I think that using `auto` here instead of `llvm::object:ExportEntry` is
>> better for readability.
>>
>>
>> 
>> Comment at: tools/llvm-objdump/MachODump.cpp:9406
>>   Error Err = Error::success();
>> -  for (const llvm::object::ExportEntry  : Obj->exports(Err, Obj)) {
>> +  for (const llvm::object::ExportEntry  : Obj->exports(Err)) {
>> uint64_t Flags = Entry.flags();
>> 
>> Similar.
>>
>>
>> Repository:
>>  rL LLVM
>>
>> https://reviews.llvm.org/D35961
>>
>>
>>
>>
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35109: [Analyzer] SValBuilder Comparison Rearrangement

2017-07-28 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin requested changes to this revision.
dcoughlin added a comment.
This revision now requires changes to proceed.

Artem, Anna, and I discussed this a bit in person. We think that even though 
the benefits look great, it can't be generally applied. Maybe we could apply it 
in cases where other constraints guarantee that overflow cannot occur?


https://reviews.llvm.org/D35109



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


Re: [PATCH] D35961: [llvm] Update MachOObjectFile::exports interface

2017-07-28 Thread Kevin Enderby via cfe-commits
Looks fine to me.

Kev

> On Jul 28, 2017, at 3:49 PM, Alexander Shaposhnikov 
>  wrote:
> 
> Hi, 
> many thanks for looking at the diff.
> (i started working on this because this interface change broke some 
> out-of-tree code, but that's expected and not a big issue, i just wanted to 
> clean it up a bit). 
> 
> I assume I might be missing smth, 
> however my diff doesn't change the static method  
> /// For use examining a trie not in a MachOObjectFile.
> static iterator_range exports(Error ,
>  ArrayRef Trie,
>  const MachOObjectFile *O =
>   
> nullptr);
> 
> It changes only the regular method  
> /// For use iterating over all exported symbols.
> iterator_range exports(Error , const MachOObjectFile *O) 
> const;
> because I didn't like syntax Obj->exports(Err, Obj).
> LLD builds successfully with my patch - so I am wondering if this change 
> looks reasonable/safe to you.
>  
> Thanks,
> Alex Shaposhnikov
> 
> 
> 
> On Fri, Jul 28, 2017 at 10:30 AM, David Blaikie  > wrote:
> 
> 
> On Fri, Jul 28, 2017 at 10:24 AM Kevin Enderby  > wrote:
>> On Jul 27, 2017, at 9:50 PM, Saleem Abdulrasool via Phabricator 
>> > wrote:
>> 
>> compnerd added a comment.
>> 
>> Does anyone use the overload with the `O` for `exports` with `nullptr` 
>> instead of `this`?  If not, we could just inline `this` throughout.
> 
> This will break lld as it needs the default nullptr.  See r308691.
> 
> The reason that O was added was so that this check from r308690 could be 
> added.
> 
> When O is specified is it always == this, though? That seems to be implied by 
> the original post.
> 
> If that's the case, then the ability to pass null is really only passing the 
> on/off state for the diagnostic? Is that necessary, or would it be good to 
> just always produce the Error, even in lld?
>  
> 
> +  if (O != nullptr) {
> +if (State.Other > O->getLibraryCount()) {
> +  *E = malformedError("bad library ordinal: " + 
> Twine((int)State.Other)
> +   + " (max " + Twine((int)O->getLibraryCount()) + ") in export "
> +   "trie data at node: 0x" + utohexstr(offset));
> +  moveToEnd();
> +  return;
> +}
> 
> This is needed for the test case:
> 
> +RUN: not llvm-objdump -macho -exports-trie 
> %p/Inputs/macho-trie-bad-library-ordinal 2>&1 | FileCheck -check-prefix 
> BAD_LIBRARY_ORDINAL %s 
> +BAD_LIBRARY_ORDINAL: macho-trie-bad-library-ordinal': truncated or malformed 
> object (bad library ordinal: 69 (max 3) in export trie data at node: 0x33)
> 
>> 
>> 
>> 
>> 
>> Comment at: tools/llvm-nm/llvm-nm.cpp:1230
>>   Error Err = Error::success();
>> -  for (const llvm::object::ExportEntry  : MachO->exports(Err,
>> -   MachO)) {
>> +  for (const llvm::object::ExportEntry  : MachO->exports(Err)) {
>> bool found = false;
>> 
>> I think that using `auto` here instead of `llvm::object:ExportEntry` is 
>> better for readability.
>> 
>> 
>> 
>> Comment at: tools/llvm-objdump/MachODump.cpp:9406
>>   Error Err = Error::success();
>> -  for (const llvm::object::ExportEntry  : Obj->exports(Err, Obj)) {
>> +  for (const llvm::object::ExportEntry  : Obj->exports(Err)) {
>> uint64_t Flags = Entry.flags();
>> 
>> Similar.
>> 
>> 
>> Repository:
>>  rL LLVM
>> 
>> https://reviews.llvm.org/D35961 
>> 
>> 
>> 
> 
> 

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


Re: [PATCH] D35961: [llvm] Update MachOObjectFile::exports interface

2017-07-28 Thread Kevin Enderby via cfe-commits

> On Jul 28, 2017, at 10:30 AM, David Blaikie  wrote:
> 
> 
> 
> On Fri, Jul 28, 2017 at 10:24 AM Kevin Enderby  > wrote:
>> On Jul 27, 2017, at 9:50 PM, Saleem Abdulrasool via Phabricator 
>> > wrote:
>> 
>> compnerd added a comment.
>> 
>> Does anyone use the overload with the `O` for `exports` with `nullptr` 
>> instead of `this`?  If not, we could just inline `this` throughout.
> 
> This will break lld as it needs the default nullptr.  See r308691.
> 
> The reason that O was added was so that this check from r308690 could be 
> added.
> 
> When O is specified is it always == this, though? That seems to be implied by 
> the original post.
> 
> If that's the case, then the ability to pass null is really only passing the 
> on/off state for the diagnostic? Is that necessary, or would it be good to 
> just always produce the Error, even in lld?

Without O one can’t use O->getLibraryCount() which is what is needed for the 
test.  I guess one could change the interface if lld really wanted this check. 
But I’d leave that to the lld folks as to what level of error checking they 
want.

>  
> 
> +  if (O != nullptr) {
> +if (State.Other > O->getLibraryCount()) {
> +  *E = malformedError("bad library ordinal: " + 
> Twine((int)State.Other)
> +   + " (max " + Twine((int)O->getLibraryCount()) + ") in export "
> +   "trie data at node: 0x" + utohexstr(offset));
> +  moveToEnd();
> +  return;
> +}
> 
> This is needed for the test case:
> 
> +RUN: not llvm-objdump -macho -exports-trie 
> %p/Inputs/macho-trie-bad-library-ordinal 2>&1 | FileCheck -check-prefix 
> BAD_LIBRARY_ORDINAL %s 
> +BAD_LIBRARY_ORDINAL: macho-trie-bad-library-ordinal': truncated or malformed 
> object (bad library ordinal: 69 (max 3) in export trie data at node: 0x33)
> 
>> 
>> 
>> 
>> 
>> Comment at: tools/llvm-nm/llvm-nm.cpp:1230
>>   Error Err = Error::success();
>> -  for (const llvm::object::ExportEntry  : MachO->exports(Err,
>> -   MachO)) {
>> +  for (const llvm::object::ExportEntry  : MachO->exports(Err)) {
>> bool found = false;
>> 
>> I think that using `auto` here instead of `llvm::object:ExportEntry` is 
>> better for readability.
>> 
>> 
>> 
>> Comment at: tools/llvm-objdump/MachODump.cpp:9406
>>   Error Err = Error::success();
>> -  for (const llvm::object::ExportEntry  : Obj->exports(Err, Obj)) {
>> +  for (const llvm::object::ExportEntry  : Obj->exports(Err)) {
>> uint64_t Flags = Entry.flags();
>> 
>> Similar.
>> 
>> 
>> Repository:
>>  rL LLVM
>> 
>> https://reviews.llvm.org/D35961 
>> 
>> 
>> 
> 

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


Re: [PATCH] D35961: [llvm] Update MachOObjectFile::exports interface

2017-07-28 Thread Alexander Shaposhnikov via cfe-commits
Hi,
many thanks for looking at the diff.
(i started working on this because this interface change broke some
out-of-tree code, but that's expected and not a big issue, i just wanted to
clean it up a bit).

I assume I might be missing smth,
however my diff doesn't change the static method
/// For use examining a trie not in a MachOObjectFile.
static iterator_range exports(Error ,
 ArrayRef Trie,
 const MachOObjectFile *O =

nullptr);

It changes only the regular method
/// For use iterating over all exported symbols.
iterator_range exports(Error , const MachOObjectFile *O)
const;
because I didn't like syntax Obj->exports(Err, Obj).
LLD builds successfully with my patch - so I am wondering if this change
looks reasonable/safe to you.

Thanks,
Alex Shaposhnikov



On Fri, Jul 28, 2017 at 10:30 AM, David Blaikie  wrote:

>
>
> On Fri, Jul 28, 2017 at 10:24 AM Kevin Enderby  wrote:
>
>> On Jul 27, 2017, at 9:50 PM, Saleem Abdulrasool via Phabricator <
>> revi...@reviews.llvm.org> wrote:
>>
>> compnerd added a comment.
>>
>> Does anyone use the overload with the `O` for `exports` with `nullptr`
>> instead of `this`?  If not, we could just inline `this` throughout.
>>
>>
>> This will break lld as it needs the default nullptr.  See r308691.
>>
>> The reason that O was added was so that this check from r308690 could be
>> added.
>>
>
> When O is specified is it always == this, though? That seems to be implied
> by the original post.
>
> If that's the case, then the ability to pass null is really only passing
> the on/off state for the diagnostic? Is that necessary, or would it be good
> to just always produce the Error, even in lld?
>
>
>>
>> +  if (O != nullptr) {
>> +if (State.Other > O->getLibraryCount()) {
>> +  *E = malformedError("bad library ordinal: " +
>> Twine((int)State.Other)
>> +   + " (max " + Twine((int)O->getLibraryCount()) + ") in
>> export "
>> +   "trie data at node: 0x" + utohexstr(offset));
>> +  moveToEnd();
>> +  return;
>> +}
>>
>> This is needed for the test case:
>>
>> +RUN: not llvm-objdump -macho -exports-trie 
>> %p/Inputs/macho-trie-bad-library-ordinal
>> 2>&1 | FileCheck -check-prefix BAD_LIBRARY_ORDINAL %s
>> +BAD_LIBRARY_ORDINAL: macho-trie-bad-library-ordinal': truncated or
>> malformed object (bad library ordinal: 69 (max 3) in export trie data at
>> node: 0x33)
>>
>>
>>
>>
>> 
>> Comment at: tools/llvm-nm/llvm-nm.cpp:1230
>>   Error Err = Error::success();
>> -  for (const llvm::object::ExportEntry  : MachO->exports(Err,
>> -   MachO))
>> {
>> +  for (const llvm::object::ExportEntry  : MachO->exports(Err))
>> {
>> bool found = false;
>> 
>> I think that using `auto` here instead of `llvm::object:ExportEntry` is
>> better for readability.
>>
>>
>> 
>> Comment at: tools/llvm-objdump/MachODump.cpp:9406
>>   Error Err = Error::success();
>> -  for (const llvm::object::ExportEntry  : Obj->exports(Err, Obj)) {
>> +  for (const llvm::object::ExportEntry  : Obj->exports(Err)) {
>> uint64_t Flags = Entry.flags();
>> 
>> Similar.
>>
>>
>> Repository:
>>  rL LLVM
>>
>> https://reviews.llvm.org/D35961
>>
>>
>>
>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35959: Summary: For powerpc64, disable tests that assume long double is 80-bits.

2017-07-28 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine updated this revision to Diff 108727.
saugustine added a comment.
Herald added subscribers: aheejin, mgorny.

- Add clear_cache implementation for ppc64. Fix buffer to meet ppc64 alignment.
- Merge branch 'master' of https://github.com/llvm-project/llvm-project-20170507
- Merge branch 'master' of https://github.com/llvm-project/llvm-project-20170507
- Merge branch 'master' of https://github.com/llvm-project/llvm-project-20170507


https://reviews.llvm.org/D35959

Files:
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  compiler-rt/cmake/base-config-ix.cmake
  compiler-rt/cmake/builtin-config-ix.cmake
  compiler-rt/lib/builtins/CMakeLists.txt
  compiler-rt/test/builtins/Unit/fixunsxfti_test.c
  compiler-rt/test/builtins/Unit/fixxfti_test.c
  compiler-rt/test/builtins/Unit/floattixf_test.c
  compiler-rt/test/builtins/Unit/floatuntixf_test.c

Index: compiler-rt/test/builtins/Unit/floatuntixf_test.c
===
--- compiler-rt/test/builtins/Unit/floatuntixf_test.c
+++ compiler-rt/test/builtins/Unit/floatuntixf_test.c
@@ -2,7 +2,7 @@
 // XFAIL: aarch64
 // test fails for aarch64 (see pr32260)
 
-// UNSUPPORTED: mips
+// UNSUPPORTED: mips, powerpc64, powerpc64le
 
 //===-- floatuntixf.c - Test __floatuntixf ===//
 //
Index: compiler-rt/test/builtins/Unit/floattixf_test.c
===
--- compiler-rt/test/builtins/Unit/floattixf_test.c
+++ compiler-rt/test/builtins/Unit/floattixf_test.c
@@ -2,7 +2,7 @@
 // XFAIL: aarch64
 // test fails for aarch64 (see pr32260)
 
-// UNSUPPORTED: mips
+// UNSUPPORTED: mips, powerpc64, powerpc64le
 
 //===-- floattixf.c - Test __floattixf ===//
 //
Index: compiler-rt/test/builtins/Unit/fixxfti_test.c
===
--- compiler-rt/test/builtins/Unit/fixxfti_test.c
+++ compiler-rt/test/builtins/Unit/fixxfti_test.c
@@ -2,7 +2,7 @@
 // XFAIL: aarch64
 // test fails for aarch64 (see pr32260)
 
-// UNSUPPORTED: mips
+// UNSUPPORTED: mips, powerpc64, powerpc64le
 
 //===-- fixxfti_test.c - Test __fixxfti ---===//
 //
Index: compiler-rt/test/builtins/Unit/fixunsxfti_test.c
===
--- compiler-rt/test/builtins/Unit/fixunsxfti_test.c
+++ compiler-rt/test/builtins/Unit/fixunsxfti_test.c
@@ -2,7 +2,7 @@
 // XFAIL: aarch64
 // test fails for aarch64 (see pr32260)
 
-// UNSUPPORTED: mips
+// UNSUPPORTED: mips, powerpc64, powerpc64le
 
 //===-- fixunsxfti_test.c - Test __fixunsxfti -===//
 //
Index: compiler-rt/lib/builtins/CMakeLists.txt
===
--- compiler-rt/lib/builtins/CMakeLists.txt
+++ compiler-rt/lib/builtins/CMakeLists.txt
@@ -458,6 +458,20 @@
 set(mips64el_SOURCES ${GENERIC_TF_SOURCES}
  ${mips_SOURCES})
 
+set(powerpc64_SOURCES
+  ppc/divtc3.c
+  ppc/fixtfdi.c
+  ppc/fixunstfdi.c
+  ppc/floatditf.c
+  ppc/floatunditf.c
+  ppc/gcc_qadd.c
+  ppc/gcc_qdiv.c
+  ppc/gcc_qmul.c
+  ppc/gcc_qsub.c
+  ppc/multc3.c
+  ${GENERIC_SOURCES})
+set(powerpc64le_SOURCES ${powerpc64_SOURCES})
+
 set(wasm32_SOURCES ${GENERIC_SOURCES})
 set(wasm64_SOURCES ${GENERIC_SOURCES})
 
Index: compiler-rt/cmake/builtin-config-ix.cmake
===
--- compiler-rt/cmake/builtin-config-ix.cmake
+++ compiler-rt/cmake/builtin-config-ix.cmake
@@ -40,7 +40,7 @@
 endif()
 
 set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
-${MIPS32} ${MIPS64} ${WASM32} ${WASM64})
+${MIPS32} ${MIPS64} ${PPC64} ${WASM32} ${WASM64})
 
 include(CompilerRTUtils)
 include(CompilerRTDarwinUtils)
Index: compiler-rt/cmake/base-config-ix.cmake
===
--- compiler-rt/cmake/base-config-ix.cmake
+++ compiler-rt/cmake/base-config-ix.cmake
@@ -4,6 +4,7 @@
 # runtime libraries.
 
 include(CheckIncludeFile)
+include(TestBigEndian)
 check_include_file(unwind.h HAVE_UNWIND_H)
 
 # Top level target used to build all compiler-rt libraries.
@@ -180,6 +181,10 @@
   test_target_arch(aarch32 "" "-march=armv8-a")
 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch64")
   test_target_arch(aarch64 "" "-march=armv8-a")
+elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc64")
+  test_target_arch(powerpc64 "" "--target=powerpc64-unknown-unknown")
+elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc64le")
+  test_target_arch(powerpc64le "" "--target=powerpc64le-unknown-unknown")
 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "wasm32")
   test_target_arch(wasm32 "" "--target=wasm32-unknown-unknown")
 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "wasm64")
Index: compiler-rt/cmake/Modules/CompilerRTUtils.cmake

[PATCH] D36024: [analyzer] Improved bug reporting in MagentaHandleChecker

2017-07-28 Thread Haowei Wu via Phabricator via cfe-commits
haowei created this revision.
Herald added a subscriber: xazax.hun.

This commit improves the bug reporting of MagentaHandleChecker introduced in 
https://reviews.llvm.org/D35968 , https://reviews.llvm.org/D36022 and 
https://reviews.llvm.org/D36023.

After this commit, the allocation and release sites of the handle that causes a 
bug will be marked in the generated bug report.  If the handle is declared as a 
local variable, the naming of the handle will also be marked in the generated 
bug report as well.


https://reviews.llvm.org/D36024

Files:
  lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
  test/Analysis/mxhandle.c

Index: test/Analysis/mxhandle.c
===
--- test/Analysis/mxhandle.c
+++ test/Analysis/mxhandle.c
@@ -210,16 +210,16 @@
 void checkLeak01() {
   mx_handle_t sa, sb;
   mx_channel_create(0, , );
-} // expected-warning {{Potential leak of handle}}
+} // expected-warning 2 {{Potential leak of handle pointed to by}}
 
 
 void checkLeak02(int tag) {
   mx_handle_t sa, sb;
   mx_channel_create(0, , );
   if (tag) {
 mx_handle_close(sa);
   }
-  mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
+  mx_handle_close(sb); // expected-warning {{Potential leak of handle pointed to by 'sa'}}
 }
 
 void checkLeak03(mx_handle_t handle) {
@@ -273,24 +273,24 @@
   mx_channel_create(0, , );
 
   useHandle01(sa);
-  mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
+  mx_handle_close(sb); // expected-warning {{Potential leak of handle pointed to by 'sa'}}
 }
 
 void checkLeak08() {
   mx_handle_t sa, sb;
   mx_channel_create(0, , );
 
   useHandle02();
-  mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
+  mx_handle_close(sb); // expected-warning {{Potential leak of handle pointed to by 'sa'}}
 }
 
 void checkDoubleRelease01(int tag) {
   mx_handle_t sa, sb;
   mx_channel_create(0, , );
   if (tag) {
 mx_handle_close(sa);
   }
-  mx_handle_close(sa); // expected-warning {{Releasing a previously released handle}}
+  mx_handle_close(sa); // expected-warning {{Releasing a previously released handle pointed to by 'sa'}}
   mx_handle_close(sb);
 }
 
@@ -300,7 +300,27 @@
   if (tag) {
 mx_handle_close(sa);
   }
-  useHandle01(sa); // expected-warning {{Using a previously released handle}}
+  useHandle01(sa); // expected-warning {{Using a previously released handle pointed to by 'sa'}}
   mx_handle_close(sa);
   mx_handle_close(sb);
 }
+
+void checkSuppressWarning01() MX_SYSCALL_PARAM_ATTR(suppress_warning) {
+  mx_handle_t sa, sb;
+  if (mx_channel_create(0, , ) < 0) {
+return;
+  }
+  mx_handle_close(sa); // Should not report any bugs here
+}
+
+void checkSuppressWarning02() {
+  mx_handle_t sa, sb;
+  if (mx_channel_create(0, , ) < 0) {
+return;
+  }
+  mx_handle_close(sa); // Should not report any bugs here
+}
+
+void checkSuppressWarning03() MX_SYSCALL_PARAM_ATTR(suppress_warning) {
+  checkSuppressWarning02();
+}
Index: lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
@@ -235,6 +235,7 @@
 static const char *HANDLE_TYPE_NAME = "mx_handle_t";
 static const char *SYSCALL_RETURN_TYPE_NAME = "mx_status_t";
 static const int MAX_HANDLE_IN_ARRAY = 64;
+typedef std::pair AllocInfo;
 
 class MagentaHandleChecker
 : public Checker HandleState map
 REGISTER_MAP_WITH_PROGRAMSTATE(HStateMap, SymbolRef, HandleState)
 
+std::shared_ptr
+MagentaBugVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN,
+ BugReporterContext , BugReport ) {
+  ProgramStateRef State = N->getState();
+  

[PATCH] D36023: [analyzer] Add array support for MagentaHandleChecker

2017-07-28 Thread Haowei Wu via Phabricator via cfe-commits
haowei created this revision.
Herald added a subscriber: xazax.hun.

This commit adds support for syscalls that acquire/release handles in an array 
for MagentaHandleChecker introduced in https://reviews.llvm.org/D35968 and 
https://reviews.llvm.org/D36022.

Most magenta handle related syscalls will take a pointer to a local mx_handle_t 
variable for handle acquisition and take a value of a local mx_handle variable 
for handle release. A good example would be:

  mx_status_t mx_channel_create(uint32_t options,
mx_handle_t* out0, mx_handle_t* out1);

and

  mx_status_t mx_handle_close(mx_handle_t handle);

However, there are two exceptions, syscall

  mx_status_t mx_channel_read(mx_handle_t handle, uint32_t options,
  void* bytes, mx_handle_t* handles,
  uint32_t num_bytes, uint32_t num_handles,
  uint32_t* actual_bytes, uint32_t* actual_handles);

Will read(acquire) "num_handles" of  handles and save them to the array pointed 
to by "handles". The actual number of acquired handles will be saved to the 
variable pointed to by "actual_handles".

And syscall

  mx_status_t mx_channel_write(mx_handle_t handle, uint32_t options,
   void* bytes, uint32_t num_bytes,
   mx_handle_t* handles, uint32_t num_handles)

Will release "num_handles" of handles in array "handles".

This patch adds support to handle acquire/release through arrays so these two 
syscalls can be processed by this checker.


https://reviews.llvm.org/D36023

Files:
  lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
  test/Analysis/mxhandle.c

Index: test/Analysis/mxhandle.c
===
--- test/Analysis/mxhandle.c
+++ test/Analysis/mxhandle.c
@@ -20,6 +20,24 @@
 extern mx_status_t mx_handle_close(
 MX_SYSCALL_PARAM_ATTR(handle_release_always) mx_handle_t handle);
 
+extern mx_status_t mx_channel_read(
+MX_SYSCALL_PARAM_ATTR(handle_use) mx_handle_t handle,
+uint32_t options,
+void* bytes,
+mx_handle_t* handles,
+uint32_t num_bytes,
+uint32_t num_handles,
+uint32_t* actual_bytes,
+uint32_t* actual_handles);
+
+extern mx_status_t mx_channel_write(
+MX_SYSCALL_PARAM_ATTR(handle_use) mx_handle_t handle,
+uint32_t options,
+const void* bytes,
+uint32_t num_bytes,
+const mx_handle_t* handles,
+uint32_t num_handles);
+
 // Escape is the default behavior for any function take a handle as parameter
 // It should work with/without explicit annotations
 void escapeMethod01(mx_handle_t *in);
@@ -78,6 +96,44 @@
   return sb; // no warning
 }
 
+void checkNoLeak06(mx_handle_t handle) {
+  mx_handle_t handlebuf[4];
+  uint32_t hcount;
+  mx_channel_read(handle, 0, NULL, handlebuf, 0, 4, 0, );
+  for (int i = 0; i < hcount; i++) {
+mx_handle_close(handlebuf[i]);
+  }
+}
+
+void checkNoLeak07(mx_handle_t handle, uint32_t hcount) {
+  mx_handle_t handlebuf[6];
+  mx_channel_read(handle, 0, NULL, handlebuf, 0, hcount, 0, );
+  for (int i = 0; i < hcount; i++) {
+mx_handle_close(handlebuf[i]);
+  }
+}
+
+void checkNoLeak08(mx_handle_t handle) {
+  mx_handle_t handlebuf[4];
+  uint32_t hcount;
+  mx_channel_read(handle, 0, NULL, handlebuf, 0, 4, 0, );
+  if (mx_channel_write(handle, 0, NULL, 0, handlebuf, hcount) < 0) {
+for (int i = 0; i < hcount; i++) {
+  mx_handle_close(handlebuf[i]);
+}
+  }
+}
+
+void checkNoLeak09(mx_handle_t handle, uint32_t hcount) {
+  mx_handle_t handlebuf[6];
+  mx_channel_read(handle, 0, NULL, handlebuf, 0, hcount, 0, );
+  if (mx_channel_write(handle, 0, NULL, 0, handlebuf, hcount) < 0) {
+for (int i = 0; i < hcount; i++) {
+  mx_handle_close(handlebuf[i]);
+}
+  }
+}
+
 void checkNoLeak10() {
   mx_handle_t sa, sb;
   if (mx_channel_create(0, , ) < 0) {
@@ -87,6 +143,18 @@
   mx_handle_close(sb);
 }
 
+void checkNoLeak11(mx_handle_t handle, uint32_t hcount) {
+  mx_handle_t handlebuf[6];
+  mx_status_t r = mx_channel_read(handle, 0, NULL,
+  handlebuf, 0, hcount, 0, );
+  if (r < 0) {
+return;
+  }
+  for (int i = 0; i < hcount; i++) {
+mx_handle_close(handlebuf[i]);
+  }
+}
+
 void checkNoLeak12(int tag) {
   mx_handle_t sa, sb;
   if (mx_channel_create(0, , ) < 0) {
@@ -154,6 +222,52 @@
   mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
 }
 
+void checkLeak03(mx_handle_t handle) {
+  mx_handle_t handlebuf[4];
+  uint32_t hcount;
+  mx_status_t r = mx_channel_read(handle, 0, NULL, handlebuf, 0, 4, 0, );
+  if (r < 0) {
+return;
+  }
+  for (int i = 0; i < hcount -1; i++) {
+mx_handle_close(handlebuf[i]);
+  }
+} // expected-warning {{Potential leak of handle}}
+
+void checkLeak04(mx_handle_t handle) {
+  mx_handle_t handlebuf[3];
+  uint32_t hcount;
+  mx_status_t r = mx_channel_read(handle, 0, NULL, handlebuf, 0, 3, 0, );
+  if (r < 0) {
+return;
+  }
+  

[PATCH] D34590: [ubsan] Diagnose invalid uses of builtins (clang)

2017-07-28 Thread Vedant Kumar via Phabricator via cfe-commits
vsk edited reviewers, added: eugenis; removed: efriedma.
vsk added a comment.

Ping.


https://reviews.llvm.org/D34590



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


[PATCH] D36022: [analyzer] Add handle misuse analysis to MagentaHandleChecker

2017-07-28 Thread Haowei Wu via Phabricator via cfe-commits
haowei created this revision.
Herald added a subscriber: xazax.hun.

This commits add actual code for analyzing magenta handle misuse issues to 
MagentaHandleChecker, which is introduced in https://reviews.llvm.org/D35968. 
It supports magenta syscalls that acquires/release/use handle through pointers 
or values but not through arrays. The support for arrays will be added in a 
follow up commit.


https://reviews.llvm.org/D36022

Files:
  lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp
  test/Analysis/mxhandle.c

Index: test/Analysis/mxhandle.c
===
--- /dev/null
+++ test/Analysis/mxhandle.c
@@ -0,0 +1,192 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.magenta.MagentaHandleChecker -analyzer-store=region -verify %s
+
+typedef __typeof__(sizeof(int)) size_t;
+typedef int mx_status_t;
+typedef __typeof__(sizeof(int)) mx_handle_t;
+typedef unsigned int uint32_t;
+#define NULL ((void *)0)
+
+#if defined(__clang__)
+#define MX_SYSCALL_PARAM_ATTR(x)   __attribute__((annotate("mx_" #x)))
+#else
+#define MX_SYSCALL_PARAM_ATTR(x)   // no-op
+#endif
+
+extern mx_status_t mx_channel_create(
+uint32_t options,
+MX_SYSCALL_PARAM_ATTR(handle_acquire) mx_handle_t* out0,
+MX_SYSCALL_PARAM_ATTR(handle_acquire) mx_handle_t* out1);
+
+extern mx_status_t mx_handle_close(
+MX_SYSCALL_PARAM_ATTR(handle_release_always) mx_handle_t handle);
+
+// Escape is the default behavior for any function take a handle as parameter
+// It should work with/without explicit annotations
+void escapeMethod01(mx_handle_t *in);
+
+void escapeMethod02(
+MX_SYSCALL_PARAM_ATTR(handle_escape)  mx_handle_t *in);
+
+void escapeMethod03(mx_handle_t in);
+
+void escapeMethod04(
+MX_SYSCALL_PARAM_ATTR(handle_escape)  mx_handle_t in);
+
+// Handle should not escape when mx_handle_use is present. It should work
+// for both value type and pointer type arguments.
+void useHandle01(
+MX_SYSCALL_PARAM_ATTR(handle_use) mx_handle_t handle);
+
+void useHandle02(
+MX_SYSCALL_PARAM_ATTR(handle_use) mx_handle_t *handle);
+
+// End of declaration
+
+void checkNoLeak01() {
+  mx_handle_t sa, sb;
+  mx_channel_create(0, , );
+  mx_handle_close(sa);
+  mx_handle_close(sb);
+}
+
+void checkNoLeak02() {
+  mx_handle_t ay[2];
+  mx_channel_create(0, [0], [1]);
+  mx_handle_close(ay[0]);
+  mx_handle_close(ay[1]);
+}
+
+void checkNoLeak03() {
+  mx_handle_t ay[2];
+  mx_channel_create(0, [0], [1]);
+  for (int i = 0; i < 2; i++) {
+mx_handle_close(ay[i]);
+  }
+}
+
+mx_handle_t checkNoLeak04() {
+  mx_handle_t sa, sb;
+  mx_channel_create(0, , );
+  mx_handle_close(sa);
+  return sb; // no warning
+}
+
+mx_handle_t checkNoLeak05(mx_handle_t *out1) {
+  mx_handle_t sa, sb;
+  mx_channel_create(0, , );
+  *out1 = sa;
+  return sb; // no warning
+}
+
+void checkNoLeak10() {
+  mx_handle_t sa, sb;
+  if (mx_channel_create(0, , ) < 0) {
+return;
+  }
+  mx_handle_close(sa);
+  mx_handle_close(sb);
+}
+
+void checkNoLeak12(int tag) {
+  mx_handle_t sa, sb;
+  if (mx_channel_create(0, , ) < 0) {
+return;
+  }
+  if (tag) {
+escapeMethod01();
+escapeMethod01();
+  }
+  mx_handle_close(sa);
+  mx_handle_close(sb);
+}
+
+void checkNoLeak13(int tag) {
+  mx_handle_t sa, sb;
+  if (mx_channel_create(0, , ) < 0) {
+return;
+  }
+  if (tag) {
+escapeMethod02();
+escapeMethod02();
+  }
+  mx_handle_close(sa);
+  mx_handle_close(sb);
+}
+
+void checkNoLeak14(int tag) {
+  mx_handle_t sa, sb;
+  if (mx_channel_create(0, , ) < 0) {
+return;
+  }
+  if (tag) {
+escapeMethod03(sa);
+escapeMethod03(sb);
+  }
+  mx_handle_close(sa);
+  mx_handle_close(sb);
+}
+
+void checkNoLeak15(int tag) {
+  mx_handle_t sa, sb;
+  if (mx_channel_create(0, , ) < 0) {
+return;
+  }
+  if (tag) {
+escapeMethod04(sa);
+escapeMethod04(sb);
+  }
+  mx_handle_close(sa);
+  mx_handle_close(sb);
+}
+
+void checkLeak01() {
+  mx_handle_t sa, sb;
+  mx_channel_create(0, , );
+} // expected-warning {{Potential leak of handle}}
+
+
+void checkLeak02(int tag) {
+  mx_handle_t sa, sb;
+  mx_channel_create(0, , );
+  if (tag) {
+mx_handle_close(sa);
+  }
+  mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
+}
+
+void checkLeak07() {
+  mx_handle_t sa, sb;
+  mx_channel_create(0, , );
+
+  useHandle01(sa);
+  mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
+}
+
+void checkLeak08() {
+  mx_handle_t sa, sb;
+  mx_channel_create(0, , );
+
+  useHandle02();
+  mx_handle_close(sb); // expected-warning {{Potential leak of handle}}
+}
+
+void checkDoubleRelease01(int tag) {
+  mx_handle_t sa, sb;
+  mx_channel_create(0, , );
+  if (tag) {
+mx_handle_close(sa);
+  }
+  mx_handle_close(sa); // expected-warning {{Releasing a previously released handle}}
+  mx_handle_close(sb);
+}
+
+void checkUseAfterFree01(int tag) {
+  mx_handle_t sa, sb;
+  mx_channel_create(0, , );
+  if (tag) {
+mx_handle_close(sa);
+  }
+  useHandle01(sa); // 

Re: r309113 - [Bash-autocompletion] Show HelpText with possible flags

2017-07-28 Thread Hans Wennborg via cfe-commits
Merged to 5.0 in r309438.

On Wed, Jul 26, 2017 at 6:36 AM, Yuka Takahashi via cfe-commits
 wrote:
> Author: yamaguchi
> Date: Wed Jul 26 06:36:58 2017
> New Revision: 309113
>
> URL: http://llvm.org/viewvc/llvm-project?rev=309113=rev
> Log:
> [Bash-autocompletion] Show HelpText with possible flags
>
> Summary:
> `clang --autocomplete=-std` will show
> ```
> -std:   Language standard to compile for
> -std=   Language standard to compile for
> -stdlib=C++ standard library to use
> ```
> after this change.
>
> However, showing HelpText with completion in bash seems super tricky, so
> this feature will be used in other shells (fish, zsh...).
>
> Reviewers: v.g.vassilev, teemperor, ruiu
>
> Subscribers: cfe-commits, hiraditya
>
> Differential Revision: https://reviews.llvm.org/D35759
>
> Modified:
> cfe/trunk/lib/Driver/Driver.cpp
> cfe/trunk/test/Driver/autocomplete.c
> cfe/trunk/utils/bash-autocomplete.sh
>
> Modified: cfe/trunk/lib/Driver/Driver.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=309113=309112=309113=diff
> ==
> --- cfe/trunk/lib/Driver/Driver.cpp (original)
> +++ cfe/trunk/lib/Driver/Driver.cpp Wed Jul 26 06:36:58 2017
> @@ -1297,7 +1297,7 @@ bool Driver::HandleImmediateArgs(const C
>  std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
>[](StringRef A, StringRef B) { return A.compare_lower(B) < 0; 
> });
>
> -llvm::outs() << llvm::join(SuggestedCompletions, " ") << '\n';
> +llvm::outs() << llvm::join(SuggestedCompletions, "\n") << '\n';
>  return false;
>}
>
>
> Modified: cfe/trunk/test/Driver/autocomplete.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/autocomplete.c?rev=309113=309112=309113=diff
> ==
> --- cfe/trunk/test/Driver/autocomplete.c (original)
> +++ cfe/trunk/test/Driver/autocomplete.c Wed Jul 26 06:36:58 2017
> @@ -1,46 +1,91 @@
>  // RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
>  // FSYN: -fsyntax-only
> -// RUN: %clang --autocomplete=-s | FileCheck %s -check-prefix=STD
> -// STD: -std={{.*}}-stdlib=
> +// RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
> +// STD: -std= Language standard to compile for
>  // RUN: %clang --autocomplete=foo | FileCheck %s -check-prefix=FOO
>  // FOO-NOT: foo
>  // RUN: %clang --autocomplete=-stdlib=,l | FileCheck %s -check-prefix=STDLIB
> -// STDLIB: libc++ libstdc++
> +// STDLIB: libc++
> +// STDLIB-NEXT: libstdc++
>  // RUN: %clang --autocomplete=-stdlib=, | FileCheck %s 
> -check-prefix=STDLIBALL
> -// STDLIBALL: libc++ libstdc++ platform
> +// STDLIBALL: libc++
> +// STDLIBALL-NEXT: libstdc++
> +// STDLIBALL-NEXT: platform
>  // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
>  // MEABI: default
>  // RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
> -// MEABIALL: 4 5 default gnu
> +// MEABIALL: 4
> +// MEABIALL-NEXT: 5
> +// MEABIALL-NEXT: default
> +// MEABIALL-NEXT: gnu
>  // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD
>  // CLSTD: CL2.0
>  // RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL
> -// CLSTDALL: cl CL cl1.1 CL1.1 cl1.2 CL1.2 cl2.0 CL2.0
> +// CLSTDALL: cl
> +// CLSTDALL-NEXT: CL
> +// CLSTDALL-NEXT: cl1.1
> +// CLSTDALL-NEXT: CL1.1
> +// CLSTDALL-NEXT: cl1.2
> +// CLSTDALL-NEXT: CL1.2
> +// CLSTDALL-NEXT: cl2.0
> +// CLSTDALL-NEXT: CL2.0
>  // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s 
> -check-prefix=FNOSANICOVER
>  // FNOSANICOVER: func
>  // RUN: %clang --autocomplete=-fno-sanitize-coverage=, | FileCheck %s 
> -check-prefix=FNOSANICOVERALL
> -// FNOSANICOVERALL: 8bit-counters bb edge func indirect-calls 
> inline-8bit-counters no-prune trace-bb trace-cmp trace-div trace-gep trace-pc 
> trace-pc-guard
> +// FNOSANICOVERALL: 8bit-counters
> +// FNOSANICOVERALL-NEXT: bb
> +// FNOSANICOVERALL-NEXT: edge
> +// FNOSANICOVERALL-NEXT: func
> +// FNOSANICOVERALL-NEXT: indirect-calls
> +// FNOSANICOVERALL-NEXT: inline-8bit-counters
> +// FNOSANICOVERALL-NEXT: no-prune
> +// FNOSANICOVERALL-NEXT: trace-bb
> +// FNOSANICOVERALL-NEXT: trace-cmp
> +// FNOSANICOVERALL-NEXT: trace-div
> +// FNOSANICOVERALL-NEXT: trace-gep
> +// FNOSANICOVERALL-NEXT: trace-pc
> +// FNOSANICOVERALL-NEXT: trace-pc-guard
>  // RUN: %clang --autocomplete=-ffp-contract=, | FileCheck %s 
> -check-prefix=FFPALL
> -// FFPALL: fast off on
> +// FFPALL: fast
> +// FFPALL-NEXT: off
> +// FFPALL-NEXT: on
>  // RUN: %clang --autocomplete=-flto=, | FileCheck %s -check-prefix=FLTOALL
> -// FLTOALL: full thin
> +// FLTOALL: full
> +// FLTOALL-NEXT: thin
>  // RUN: %clang --autocomplete=-fveclib=, | FileCheck %s 
> -check-prefix=FVECLIBALL
> -// FVECLIBALL: Accelerate none SVML
> +// FVECLIBALL: 

Re: r309112 - [Bash-completion] Fixed a bug that file doesn't autocompleted after =

2017-07-28 Thread Hans Wennborg via cfe-commits
Merged to 5.0 in r309435.

On Wed, Jul 26, 2017 at 6:30 AM, Yuka Takahashi via cfe-commits
 wrote:
> Author: yamaguchi
> Date: Wed Jul 26 06:30:36 2017
> New Revision: 309112
>
> URL: http://llvm.org/viewvc/llvm-project?rev=309112=rev
> Log:
> [Bash-completion] Fixed a bug that file doesn't autocompleted after =
>
> Summary:
> File path wasn't autocompleted after `-fmodule-cache-path=[tab]`, so
> fixed this bug by checking if $flags contains only a newline or not.
>
> Differential Revision: https://reviews.llvm.org/D35763
>
> Modified:
> cfe/trunk/utils/bash-autocomplete.sh
>
> Modified: cfe/trunk/utils/bash-autocomplete.sh
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/bash-autocomplete.sh?rev=309112=309111=309112=diff
> ==
> --- cfe/trunk/utils/bash-autocomplete.sh (original)
> +++ cfe/trunk/utils/bash-autocomplete.sh Wed Jul 26 06:30:36 2017
> @@ -65,10 +65,14 @@ _clang()
>  return
>fi
>
> -  if [[ "$cur" == '=' ]]; then
> -COMPREPLY=( $( compgen -W "$flags" -- "") )
> -  elif [[ "$flags" == "" || "$arg" == "" ]]; then
> +  # When clang does not emit any possible autocompletion, or user pushed tab 
> after " ",
> +  # just autocomplete files.
> +  if [[ "$flags" == "$(echo -e '\n')" || "$arg" == "" ]]; then
> +# If -foo= and there was no possible values, autocomplete files.
> +[[ "$cur" == '=' || "$cur" == -*= ]] && cur=""
>  _clang_filedir
> +  elif [[ "$cur" == '=' ]]; then
> +COMPREPLY=( $( compgen -W "$flags" -- "") )
>else
>  # Bash automatically appends a space after '=' by default.
>  # Disable it so that it works nicely for options in the form of -foo=bar.
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36019: [clang-format] Fix bug with ENAS_DontAlign and empty lines

2017-07-28 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes created this revision.
Herald added a subscriber: klimek.

This fixes a bug in `ENAS_DontAlign` (introduced in 
https://reviews.llvm.org/D32733) where blank lines had an EscapedNewlineColumn 
of 0, causing a subtraction to overflow when converted back to `unsigned` and 
leading to runaway memory allocation.

This restores the original approach of a separate loop as originally proposed 
in https://reviews.llvm.org/D32733?vs=97397=97404, now with a proper 
justification :)


https://reviews.llvm.org/D36019

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2309,6 +2309,30 @@
   EXPECT_EQ("template  f();", format("\\\ntemplate  f();"));
   EXPECT_EQ("/* \\  \\  \\\n */", format("\\\n/* \\  \\  \\\n */"));
   EXPECT_EQ("", format(""));
+
+  FormatStyle DontAlign = getLLVMStyle();
+  DontAlign.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+  DontAlign.MaxEmptyLinesToKeep = 3;
+  // FIXME: can't use verifyFormat here because the newline before
+  // "public:" is not inserted the first time it's reformatted
+  EXPECT_EQ("#define A \\\n"
+"  class Foo { \\\n"
+"void bar(); \\\n"
+" \\\n"
+" \\\n"
+" \\\n"
+"  public: \\\n"
+"void baz(); \\\n"
+"  };",
+format("#define A \\\n"
+   "  class Foo { \\\n"
+   "void bar(); \\\n"
+   " \\\n"
+   " \\\n"
+   " \\\n"
+   "  public: \\\n"
+   "void baz(); \\\n"
+   "  };", DontAlign));
 }
 
 TEST_F(FormatTest, CalculateSpaceOnConsecutiveLinesInMacro) {
Index: lib/Format/WhitespaceManager.cpp
===
--- lib/Format/WhitespaceManager.cpp
+++ lib/Format/WhitespaceManager.cpp
@@ -557,9 +557,22 @@
 }
 
 void WhitespaceManager::alignEscapedNewlines() {
-  if (Style.AlignEscapedNewlines == FormatStyle::ENAS_DontAlign)
+  // If we are not aligning escaped newlines, just set EscapedNewlineColumn
+  // to point to the end of each line.
+  if (Style.AlignEscapedNewlines == FormatStyle::ENAS_DontAlign) {
+bool PreviousContinuerHadNLBefore = false;  // used to detect blank lines
+for (Change  : Changes) {
+  if (C.ContinuesPPDirective) {
+if (C.NewlinesBefore > 0)
+  C.EscapedNewlineColumn =
+PreviousContinuerHadNLBefore ? 2 : C.PreviousEndOfTokenColumn + 2;
+PreviousContinuerHadNLBefore = C.NewlinesBefore > 0;
+  }
+}
 return;
+  }
 
+  // Otherwise, compute the max width and then apply it to all lines.
   bool AlignLeft = Style.AlignEscapedNewlines == FormatStyle::ENAS_Left;
   unsigned MaxEndOfLine = AlignLeft ? 0 : Style.ColumnLimit;
   unsigned StartOfMacro = 0;
@@ -644,6 +657,7 @@
   unsigned PreviousEndOfTokenColumn,
   unsigned EscapedNewlineColumn) {
   if (Newlines > 0) {
+assert(EscapedNewlineColumn >= 2);
 unsigned Offset =
 std::min(EscapedNewlineColumn - 2, PreviousEndOfTokenColumn);
 for (unsigned i = 0; i < Newlines; ++i) {


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2309,6 +2309,30 @@
   EXPECT_EQ("template  f();", format("\\\ntemplate  f();"));
   EXPECT_EQ("/* \\  \\  \\\n */", format("\\\n/* \\  \\  \\\n */"));
   EXPECT_EQ("", format(""));
+
+  FormatStyle DontAlign = getLLVMStyle();
+  DontAlign.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+  DontAlign.MaxEmptyLinesToKeep = 3;
+  // FIXME: can't use verifyFormat here because the newline before
+  // "public:" is not inserted the first time it's reformatted
+  EXPECT_EQ("#define A \\\n"
+"  class Foo { \\\n"
+"void bar(); \\\n"
+" \\\n"
+" \\\n"
+" \\\n"
+"  public: \\\n"
+"void baz(); \\\n"
+"  };",
+format("#define A \\\n"
+   "  class Foo { \\\n"
+   "void bar(); \\\n"
+   " \\\n"
+   " \\\n"
+   " \\\n"
+   "  public: \\\n"
+   "void baz(); \\\n"
+   "  };", DontAlign));
 }
 
 TEST_F(FormatTest, CalculateSpaceOnConsecutiveLinesInMacro) {
Index: lib/Format/WhitespaceManager.cpp
===
--- lib/Format/WhitespaceManager.cpp
+++ lib/Format/WhitespaceManager.cpp
@@ -557,9 +557,22 @@
 }
 
 void WhitespaceManager::alignEscapedNewlines() {

[PATCH] D36013: Fix logic for generating llvm.type.test()s

2017-07-28 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich updated this revision to Diff 108702.
vlad.tsyrklevich marked 2 inline comments as done.

https://reviews.llvm.org/D36013

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/cfi-vcall-no-trap.cpp


Index: test/CodeGenCXX/cfi-vcall-no-trap.cpp
===
--- /dev/null
+++ test/CodeGenCXX/cfi-vcall-no-trap.cpp
@@ -0,0 +1,15 @@
+// Only output llvm.assume(llvm.type.test()) if cfi-vcall is disabled and 
whole-program-vtables is enabled
+// RUN: %clang_cc1 -fvisibility hidden -fsanitize=cfi-vcall 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CHECK 
--check-prefix=CFI %s
+// RUN: %clang_cc1 -fvisibility hidden -fwhole-program-vtables -emit-llvm -o - 
%s | FileCheck --check-prefix=CHECK --check-prefix=NOCFI %s
+
+struct S1 {
+  virtual void f();
+};
+
+// CHECK: define{{.*}}s1f
+// CHECK: llvm.type.test
+// CFI-NOT: llvm.assume
+// NOCFI: llvm.assume
+void s1f(S1 *s1) {
+  s1->f();
+}
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -2523,8 +2523,10 @@
 void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
llvm::Value *VTable,
SourceLocation Loc) {
-  if (CGM.getCodeGenOpts().WholeProgramVTables &&
-  CGM.HasHiddenLTOVisibility(RD)) {
+  if (SanOpts.has(SanitizerKind::CFIVCall))
+EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
+  else if (CGM.getCodeGenOpts().WholeProgramVTables &&
+   CGM.HasHiddenLTOVisibility(RD)) {
 llvm::Metadata *MD =
 CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
 llvm::Value *TypeId =
@@ -2536,9 +2538,6 @@
{CastedVTable, TypeId});
 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::assume), TypeTest);
   }
-
-  if (SanOpts.has(SanitizerKind::CFIVCall))
-EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
 }
 
 void CodeGenFunction::EmitVTablePtrCheckForCall(const CXXRecordDecl *RD,


Index: test/CodeGenCXX/cfi-vcall-no-trap.cpp
===
--- /dev/null
+++ test/CodeGenCXX/cfi-vcall-no-trap.cpp
@@ -0,0 +1,15 @@
+// Only output llvm.assume(llvm.type.test()) if cfi-vcall is disabled and whole-program-vtables is enabled
+// RUN: %clang_cc1 -fvisibility hidden -fsanitize=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=CFI %s
+// RUN: %clang_cc1 -fvisibility hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=NOCFI %s
+
+struct S1 {
+  virtual void f();
+};
+
+// CHECK: define{{.*}}s1f
+// CHECK: llvm.type.test
+// CFI-NOT: llvm.assume
+// NOCFI: llvm.assume
+void s1f(S1 *s1) {
+  s1->f();
+}
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -2523,8 +2523,10 @@
 void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
llvm::Value *VTable,
SourceLocation Loc) {
-  if (CGM.getCodeGenOpts().WholeProgramVTables &&
-  CGM.HasHiddenLTOVisibility(RD)) {
+  if (SanOpts.has(SanitizerKind::CFIVCall))
+EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
+  else if (CGM.getCodeGenOpts().WholeProgramVTables &&
+   CGM.HasHiddenLTOVisibility(RD)) {
 llvm::Metadata *MD =
 CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
 llvm::Value *TypeId =
@@ -2536,9 +2538,6 @@
{CastedVTable, TypeId});
 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::assume), TypeTest);
   }
-
-  if (SanOpts.has(SanitizerKind::CFIVCall))
-EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
 }
 
 void CodeGenFunction::EmitVTablePtrCheckForCall(const CXXRecordDecl *RD,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r309427 - Adopt to LLVM API change (llvm.dbg.value no longer has an offset)

2017-07-28 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Fri Jul 28 13:21:08 2017
New Revision: 309427

URL: http://llvm.org/viewvc/llvm-project?rev=309427=rev
Log:
Adopt to LLVM API change (llvm.dbg.value no longer has an offset)

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=309427=309426=309427=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Jul 28 13:21:08 2017
@@ -3799,7 +3799,7 @@ void CGDebugInfo::EmitDeclareOfBlockLite
   if (LocalAddr) {
 // Insert an llvm.dbg.value into the current block.
 DBuilder.insertDbgValueIntrinsic(
-LocalAddr, 0, debugVar, DBuilder.createExpression(),
+LocalAddr, debugVar, DBuilder.createExpression(),
 llvm::DebugLoc::get(line, column, scope, CurInlinedAt),
 Builder.GetInsertBlock());
   }

Modified: cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m?rev=309427=309426=309427=diff
==
--- cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m (original)
+++ cfe/trunk/test/CodeGenObjC/debug-info-block-captured-self.m Fri Jul 28 
13:21:08 2017
@@ -56,7 +56,7 @@ typedef enum {
 // CHECK-NEXT:   [[DBGADDR:%.*]] = alloca [[BLOCK_T:<{.*}>]]*, align 8
 // CHECK:store i8* [[BLOCK_DESC:%.*]], i8** %[[MEM1]], align 8
 // CHECK:%[[TMP0:.*]] = load i8*, i8** %[[MEM1]]
-// CHECK:call void @llvm.dbg.value(metadata i8* %[[TMP0]], i64 0, 
metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
+// CHECK:call void @llvm.dbg.value(metadata i8* %[[TMP0]], metadata 
![[BDMD:[0-9]+]], metadata !{{.*}})
 // CHECK:call void @llvm.dbg.declare(metadata i8* [[BLOCK_DESC]], 
metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
 // CHECK:store [[BLOCK_T]]* {{%.*}}, [[BLOCK_T]]** [[DBGADDR]], align 8
 // CHECK:call void @llvm.dbg.declare(metadata [[BLOCK_T]]** 
[[DBGADDR]], metadata ![[SELF:.*]], metadata !{{.*}})


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


[PATCH] D36016: [clang-tidy] Support initializer-list constructor cases in modernize-make-unique.

2017-07-28 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added subscribers: xazax.hun, JDevlieghere.

https://reviews.llvm.org/D36016

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -2,6 +2,7 @@
 // RUN:   -I%S/Inputs/modernize-smart-ptr
 
 #include "unique_ptr.h"
+#include "initializer_list.h"
 // CHECK-FIXES: #include 
 
 struct Base {
@@ -26,6 +27,22 @@
 
 struct Empty {};
 
+struct E {
+  E(std::initializer_list);
+  E();
+};
+
+struct F {
+  F(std::initializer_list);
+  F();
+  int a;
+};
+
+struct G {
+  G(std::initializer_list);
+  G(int);
+};
+
 namespace {
 class Foo {};
 } // namespace
@@ -225,6 +242,57 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
   // CHECK-FIXES: std::unique_ptr PEmpty = std::make_unique(Empty{});
 
+  // Initialization with default constructor.
+  std::unique_ptr PE1 = std::unique_ptr(new E{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PE1 = std::make_unique();
+
+  // Initialization with the initializer-list constructor.
+  std::unique_ptr PE2 = std::unique_ptr(new E{1, 2});
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PE2 = std::make_unique({1, 2});
+
+  // Initialization with default constructor.
+  std::unique_ptr PF1 = std::unique_ptr(new F());
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PF1 = std::make_unique();
+
+  // Initialization with default constructor.
+  std::unique_ptr PF2 = std::unique_ptr(new F{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PF2 = std::make_unique();
+
+  // Initialization with the initializer-list constructor.
+  std::unique_ptr PF3 = std::unique_ptr(new F{1});
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PF3 = std::make_unique({1});
+
+  // Initialization with the initializer-list constructor.
+  std::unique_ptr PF4 = std::unique_ptr(new F{1, 2});
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PF4 = std::make_unique({1, 2});
+
+  // Initialization with the initializer-list constructor.
+  std::unique_ptr PF5 = std::unique_ptr(new F({1, 2}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PF5 = std::make_unique({1, 2});
+
+  // Initialization with the initializer-list constructor as the default
+  // constructor is not present.
+  std::unique_ptr PG1 = std::unique_ptr(new G{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PG1 = std::make_unique({});
+
+  // Initialization with the initializer-list constructor.
+  std::unique_ptr PG2 = std::unique_ptr(new G{1});
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PG2 = std::make_unique({1});
+
+  // Initialization with ordinary constructor.
+  std::unique_ptr PG3 = std::unique_ptr(new G{1, 2});
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PG3 = std::make_unique({1, 2});
+
   std::unique_ptr FF = std::unique_ptr(new Foo());
   // CHECK-MESSAGES: :[[@LINE-1]]:29: warning:
   // CHECK-FIXES: std::unique_ptr FF = std::make_unique();
Index: test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h
@@ -0,0 +1,25 @@
+namespace std {
+typedef decltype(sizeof(int)) size_t;
+
+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_; }
+};
+} // namespace std
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -242,16 +242,33 @@
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
   

[PATCH] D36013: Fix logic for generating llvm.type.test()s

2017-07-28 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc accepted this revision.
pcc added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: test/CodeGenCXX/cfi-vcall-no-trap.cpp:2
+// Only output llvm.assume(llvm.type.test()) if cfi-vcall is disabled and 
whole-program-vtables is enabled
+// RUN: %clang_cc1 -cc1 -fvisibility hidden -fsanitize=cfi-vcall 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CHECK 
--check-prefix=CFI %s
+// RUN: %clang_cc1 -cc1 -fvisibility hidden -fwhole-program-vtables -emit-llvm 
-o - %s | FileCheck --check-prefix=CHECK --check-prefix=NOCFI %s

I don't think you need the `-cc1` here, it should be implied by `%clang_cc1`.



Comment at: test/CodeGenCXX/cfi-vcall-no-trap.cpp:10
+// CHECK: define{{.*}}s1f
+// CFI-NOT: llvm.assume
+// NOCFI: llvm.assume

I'd also test for presence of `llvm.type.test` to make sure that we're 
following the non-trapping CFI code path.


https://reviews.llvm.org/D36013



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


[PATCH] D36013: Fix logic for generating llvm.type.test()s

2017-07-28 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich created this revision.

`CodeGenFunction::EmitTypeMetadataCodeForVCall()` could output an 
`llvm.assume(llvm.type.test())`when CFI was enabled, optimizing out the vcall 
check. This case was only reached when: 1) CFI-vcall was enabled, 2) 
-fwhole-program-tables was specified, and 3) -fno-sanitize-trap=cfi-vcall was 
specified.

This change is blocked on https://reviews.llvm.org/D36012 as it uncovers that 
bug.


https://reviews.llvm.org/D36013

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/cfi-vcall-no-trap.cpp


Index: test/CodeGenCXX/cfi-vcall-no-trap.cpp
===
--- /dev/null
+++ test/CodeGenCXX/cfi-vcall-no-trap.cpp
@@ -0,0 +1,14 @@
+// Only output llvm.assume(llvm.type.test()) if cfi-vcall is disabled and 
whole-program-vtables is enabled
+// RUN: %clang_cc1 -cc1 -fvisibility hidden -fsanitize=cfi-vcall 
-fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CHECK 
--check-prefix=CFI %s
+// RUN: %clang_cc1 -cc1 -fvisibility hidden -fwhole-program-vtables -emit-llvm 
-o - %s | FileCheck --check-prefix=CHECK --check-prefix=NOCFI %s
+
+struct S1 {
+  virtual void f();
+};
+
+// CHECK: define{{.*}}s1f
+// CFI-NOT: llvm.assume
+// NOCFI: llvm.assume
+void s1f(S1 *s1) {
+  s1->f();
+}
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -2523,8 +2523,10 @@
 void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
llvm::Value *VTable,
SourceLocation Loc) {
-  if (CGM.getCodeGenOpts().WholeProgramVTables &&
-  CGM.HasHiddenLTOVisibility(RD)) {
+  if (SanOpts.has(SanitizerKind::CFIVCall))
+EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
+  else if (CGM.getCodeGenOpts().WholeProgramVTables &&
+   CGM.HasHiddenLTOVisibility(RD)) {
 llvm::Metadata *MD =
 CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
 llvm::Value *TypeId =
@@ -2536,9 +2538,6 @@
{CastedVTable, TypeId});
 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::assume), TypeTest);
   }
-
-  if (SanOpts.has(SanitizerKind::CFIVCall))
-EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
 }
 
 void CodeGenFunction::EmitVTablePtrCheckForCall(const CXXRecordDecl *RD,


Index: test/CodeGenCXX/cfi-vcall-no-trap.cpp
===
--- /dev/null
+++ test/CodeGenCXX/cfi-vcall-no-trap.cpp
@@ -0,0 +1,14 @@
+// Only output llvm.assume(llvm.type.test()) if cfi-vcall is disabled and whole-program-vtables is enabled
+// RUN: %clang_cc1 -cc1 -fvisibility hidden -fsanitize=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=CFI %s
+// RUN: %clang_cc1 -cc1 -fvisibility hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=NOCFI %s
+
+struct S1 {
+  virtual void f();
+};
+
+// CHECK: define{{.*}}s1f
+// CFI-NOT: llvm.assume
+// NOCFI: llvm.assume
+void s1f(S1 *s1) {
+  s1->f();
+}
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -2523,8 +2523,10 @@
 void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
llvm::Value *VTable,
SourceLocation Loc) {
-  if (CGM.getCodeGenOpts().WholeProgramVTables &&
-  CGM.HasHiddenLTOVisibility(RD)) {
+  if (SanOpts.has(SanitizerKind::CFIVCall))
+EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
+  else if (CGM.getCodeGenOpts().WholeProgramVTables &&
+   CGM.HasHiddenLTOVisibility(RD)) {
 llvm::Metadata *MD =
 CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
 llvm::Value *TypeId =
@@ -2536,9 +2538,6 @@
{CastedVTable, TypeId});
 Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::assume), TypeTest);
   }
-
-  if (SanOpts.has(SanitizerKind::CFIVCall))
-EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
 }
 
 void CodeGenFunction::EmitVTablePtrCheckForCall(const CXXRecordDecl *RD,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D33900: Print registered targets in clang's version information

2017-07-28 Thread Nico Weber via cfe-commits
Cool, then let's revert this and add it back under a different flag. Thanks!

On Fri, Jul 28, 2017 at 1:37 PM, Dimitry Andric via Phabricator via
cfe-commits  wrote:

> dim added a comment.
>
> In https://reviews.llvm.org/D33900#824172, @thakis wrote:
>
> > dim: Does putting the target listing behind a different flag work for
> you? Which problem are you trying to solve here?
>
>
> I'm fine with a different flag.  For the problem I was trying to solve,
> see my earlier comments, e.g. I wanted to 1) know what the compiled-in
> targets were and 2) achieve consistency with the other LLVM tools.
>
>
> https://reviews.llvm.org/D33900
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34030: Fix the postorder visting of the ClassTemplateSpecializationDecl nodes in the RecursiveASTVisitor.

2017-07-28 Thread Peter Siket via Phabricator via cfe-commits
MontyKutyi updated this revision to Diff 108678.
MontyKutyi added a comment.

Did the renamings.


https://reviews.llvm.org/D34030

Files:
  include/clang/AST/RecursiveASTVisitor.h
  unittests/AST/PostOrderASTVisitor.cpp


Index: unittests/AST/PostOrderASTVisitor.cpp
===
--- unittests/AST/PostOrderASTVisitor.cpp
+++ unittests/AST/PostOrderASTVisitor.cpp
@@ -15,6 +15,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
+#include 
 
 using namespace clang;
 
@@ -75,7 +76,33 @@
 }
   };
 
-}
+
+// Serializes the AST. It is not complete! It only serializes the Statement
+// and the Declaration nodes.
+class ASTSerializerVisitor : public RecursiveASTVisitor {
+private:
+  std::vector 
+  const bool PostOrderTraverse;
+
+public:
+  ASTSerializerVisitor(bool PostOrderTraverse,
+   std::vector )
+  : VisitedNodes(VisitedNodes), PostOrderTraverse(PostOrderTraverse) {}
+
+  bool shouldTraversePostOrder() const { return PostOrderTraverse; }
+
+  bool VisitStmt(Stmt *S) {
+VisitedNodes.push_back(S);
+return true;
+  }
+
+  bool VisitDecl(Decl *D) {
+VisitedNodes.push_back(D);
+return true;
+  }
+};
+
+} // anonymous namespace
 
 TEST(RecursiveASTVisitor, PostOrderTraversal) {
   auto ASTUnit = tooling::buildASTFromCode(
@@ -126,3 +153,30 @@
 ASSERT_EQ(expected[I], Visitor.VisitedNodes[I]);
   }
 }
+
+TEST(RecursiveASTVisitor, PrePostComparisonTest) {
+  auto ASTUnit = tooling::buildASTFromCode("template  class X {};"
+   "template class X;");
+
+  auto TU = ASTUnit->getASTContext().getTranslationUnitDecl();
+
+  std::vector PreorderNodeList, PostorderNodeList;
+
+  ASTSerializerVisitor PreVisitor(false, PreorderNodeList);
+  PreVisitor.TraverseTranslationUnitDecl(TU);
+
+  ASTSerializerVisitor PostVisitor(true, PostorderNodeList);
+  PostVisitor.TraverseTranslationUnitDecl(TU);
+
+  // The number of visited nodes must be independent of the ordering mode.
+  ASSERT_EQ(PreorderNodeList.size(), PostorderNodeList.size());
+
+  std::sort(PreorderNodeList.begin(), PreorderNodeList.end());
+  std::sort(PostorderNodeList.begin(), PostorderNodeList.end());
+
+  // Both traversal must visit the same nodes.
+  ASSERT_EQ(std::mismatch(PreorderNodeList.begin(), PreorderNodeList.end(),
+  PostorderNodeList.begin())
+.first,
+PreorderNodeList.end());
+}
Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -1802,11 +1802,10 @@
 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));  
\
 if (!getDerived().shouldVisitTemplateInstantiations() &&   
\
 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)  
\
-  /* Returning from here skips traversing the  
\
- declaration context of the *TemplateSpecializationDecl
\
- (embedded in the DEF_TRAVERSE_DECL() macro)   
\
- which contains the instantiated members of the template. */   
\
-  return true; 
\
+  /* Skip traversing the declaration context of the
\
+ *TemplateSpecializationDecl (embedded in the DEF_TRAVERSE_DECL()  
\
+ macro) which contains the instantiated members of the template. */
\
+  ShouldVisitChildren = false; 
\
   })
 
 DEF_TRAVERSE_TMPL_SPEC_DECL(Class)


Index: unittests/AST/PostOrderASTVisitor.cpp
===
--- unittests/AST/PostOrderASTVisitor.cpp
+++ unittests/AST/PostOrderASTVisitor.cpp
@@ -15,6 +15,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
+#include 
 
 using namespace clang;
 
@@ -75,7 +76,33 @@
 }
   };
 
-}
+
+// Serializes the AST. It is not complete! It only serializes the Statement
+// and the Declaration nodes.
+class ASTSerializerVisitor : public RecursiveASTVisitor {
+private:
+  std::vector 
+  const bool PostOrderTraverse;
+
+public:
+  ASTSerializerVisitor(bool PostOrderTraverse,
+   std::vector )
+  : VisitedNodes(VisitedNodes), PostOrderTraverse(PostOrderTraverse) {}
+
+  bool shouldTraversePostOrder() const { return PostOrderTraverse; }
+
+  bool VisitStmt(Stmt *S) {
+VisitedNodes.push_back(S);
+return true;
+  }
+
+  bool VisitDecl(Decl *D) {
+VisitedNodes.push_back(D);
+return true;
+  }
+};
+
+} // anonymous namespace
 
 TEST(RecursiveASTVisitor, PostOrderTraversal) {
   auto ASTUnit = tooling::buildASTFromCode(
@@ -126,3 +153,30 @@
 

r309407 - [CMake] Add Android toolchain CMake cache files.

2017-07-28 Thread Leo Li via cfe-commits
Author: aoli
Date: Fri Jul 28 10:40:28 2017
New Revision: 309407

URL: http://llvm.org/viewvc/llvm-project?rev=309407=rev
Log:
[CMake] Add Android toolchain CMake cache files.

Summary: Thoes files are used to build Android toolchain. D32816 makes it 
possible to build runtimes for targets.

Reviewers: beanz, srhines

Reviewed By: srhines

Subscribers: pirama, jroelofs, srhines, cfe-commits, mgorny

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

Added:
cfe/trunk/cmake/caches/Android-stage2.cmake
cfe/trunk/cmake/caches/Android.cmake

Added: cfe/trunk/cmake/caches/Android-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Android-stage2.cmake?rev=309407=auto
==
--- cfe/trunk/cmake/caches/Android-stage2.cmake (added)
+++ cfe/trunk/cmake/caches/Android-stage2.cmake Fri Jul 28 10:40:28 2017
@@ -0,0 +1,52 @@
+set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "")
+
+set(CLANG_VENDOR Android CACHE STRING "")
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(LLVM_ENABLE_THREADS OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_LIBDIR_SUFFIX 64 CACHE STRING "")
+set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
+
+set(ANDROID_RUNTIMES_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(ANDROID_RUNTIMES_BUILD_TYPE Release CACHE STRING "")
+set(ANDROID_BUILTINS_BUILD_TYPE Release CACHE STRING "")
+
+set(LLVM_BUILTIN_TARGETS 
"i686-linux-android;x86_64-linux-android;aarch64-linux-android;armv7-linux-android"
 CACHE STRING "")
+foreach(target i686;x86_64;aarch64;armv7)
+  set(BUILTINS_${target}-linux-android_ANDROID 1 CACHE STRING "")
+  set(BUILTINS_${target}-linux-android_CMAKE_BUILD_TYPE 
${ANDROID_BUILTINS_BUILD_TYPE} CACHE STRING "")
+  set(BUILTINS_${target}-linux-android_CMAKE_ASM_FLAGS 
${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_C_FLAGS 
${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_SYSROOT 
${ANDROID_${target}_SYSROOT} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_EXE_LINKER_FLAGS 
${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_SHARED_LINKER_FLAGS 
${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(BUILTINS_${target}-linux-android_CMAKE_MOUDLE_LINKER_FLAGS 
${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+endforeach()
+
+
+set(LLVM_RUNTIME_TARGETS 
"i686-linux-android;x86_64-linux-android;aarch64-linux-android;armv7-linux-android"
 CACHE STRING "")
+foreach(target i686;x86_64;aarch64;armv7)
+  set(RUNTIMES_${target}-linux-android_ANDROID 1 CACHE STRING "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_ASM_FLAGS 
${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_BUILD_TYPE 
${ANDROID_RUNTIMES_BUILD_TYPE} CACHE STRING "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_C_FLAGS 
${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_CXX_FLAGS 
${ANDROID_${target}_CXX_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_SYSROOT 
${ANDROID_${target}_SYSROOT} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_EXE_LINKER_FLAGS 
${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_SHARED_LINKER_FLAGS 
${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_CMAKE_MODULE_LINKER_FLAGS 
${ANDROID_${target}_LINKER_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_COMPILER_RT_ENABLE_WERROR ON CACHE BOOL 
"")
+  set(RUNTIMES_${target}-linux-android_COMPILER_RT_TEST_COMPILER_CFLAGS 
${ANDROID_${target}_C_FLAGS} CACHE PATH "")
+  set(RUNTIMES_${target}-linux-android_COMPILER_RT_INCLUDE_TESTS OFF CACHE 
BOOL "")
+  set(RUNTIMES_${target}-linux-android_LLVM_ENABLE_ASSERTIONS 
${ANDROID_RUNTIMES_ENABLE_ASSERTIONS} CACHE BOOL "")
+  set(RUNTIMES_${target}-linux-android_LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
+  set(RUNTIMES_${target}-linux-android_LLVM_ENABLE_THREADS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}-linux-android_LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
+  set(RUNTIMES_${target}-linux-android_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}-linux-android_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL 
"")
+  set(RUNTIMES_${target}-linux-android_LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG ON 
CACHE BOOL "")
+  set(RUNTIMES_${target}-linux-android_LIBUNWIND_HAS_FUNWIND_TABLES ON CACHE 
BOOL "")
+endforeach()
+
+set(RUNTIMES_armv7-linux-android_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+

Added: cfe/trunk/cmake/caches/Android.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Android.cmake?rev=309407=auto
==
--- cfe/trunk/cmake/caches/Android.cmake (added)
+++ cfe/trunk/cmake/caches/Android.cmake Fri Jul 28 10:40:28 2017
@@ -0,0 +1,43 @@
+# This file sets up a 

[PATCH] D33900: Print registered targets in clang's version information

2017-07-28 Thread Dimitry Andric via Phabricator via cfe-commits
dim added a comment.

In https://reviews.llvm.org/D33900#824172, @thakis wrote:

> dim: Does putting the target listing behind a different flag work for you? 
> Which problem are you trying to solve here?


I'm fine with a different flag.  For the problem I was trying to solve, see my 
earlier comments, e.g. I wanted to 1) know what the compiled-in targets were 
and 2) achieve consistency with the other LLVM tools.


https://reviews.llvm.org/D33900



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


[PATCH] D34114: [clang] Change the condition of unnecessary packed warning

2017-07-28 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added a comment.

LGTM.
rsmith, srhines, akyrtzi, rtrieu, do you have any comment?


https://reviews.llvm.org/D34114



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


Re: [PATCH] D35961: [llvm] Update MachOObjectFile::exports interface

2017-07-28 Thread David Blaikie via cfe-commits
On Fri, Jul 28, 2017 at 10:24 AM Kevin Enderby  wrote:

> On Jul 27, 2017, at 9:50 PM, Saleem Abdulrasool via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
> compnerd added a comment.
>
> Does anyone use the overload with the `O` for `exports` with `nullptr`
> instead of `this`?  If not, we could just inline `this` throughout.
>
>
> This will break lld as it needs the default nullptr.  See r308691.
>
> The reason that O was added was so that this check from r308690 could be
> added.
>

When O is specified is it always == this, though? That seems to be implied
by the original post.

If that's the case, then the ability to pass null is really only passing
the on/off state for the diagnostic? Is that necessary, or would it be good
to just always produce the Error, even in lld?


>
> +  if (O != nullptr) {
> +if (State.Other > O->getLibraryCount()) {
> +  *E = malformedError("bad library ordinal: " +
> Twine((int)State.Other)
> +   + " (max " + Twine((int)O->getLibraryCount()) + ") in
> export "
> +   "trie data at node: 0x" + utohexstr(offset));
> +  moveToEnd();
> +  return;
> +}
>
> This is needed for the test case:
>
> +RUN: not llvm-objdump -macho -exports-trie
> %p/Inputs/macho-trie-bad-library-ordinal 2>&1 | FileCheck -check-prefix
> BAD_LIBRARY_ORDINAL %s
> +BAD_LIBRARY_ORDINAL: macho-trie-bad-library-ordinal': truncated or
> malformed object (bad library ordinal: 69 (max 3) in export trie data at
> node: 0x33)
>
>
>
>
> 
> Comment at: tools/llvm-nm/llvm-nm.cpp:1230
>   Error Err = Error::success();
> -  for (const llvm::object::ExportEntry  : MachO->exports(Err,
> -
>   MachO)) {
> +  for (const llvm::object::ExportEntry  : MachO->exports(Err)) {
> bool found = false;
> 
> I think that using `auto` here instead of `llvm::object:ExportEntry` is
> better for readability.
>
>
> 
> Comment at: tools/llvm-objdump/MachODump.cpp:9406
>   Error Err = Error::success();
> -  for (const llvm::object::ExportEntry  : Obj->exports(Err, Obj)) {
> +  for (const llvm::object::ExportEntry  : Obj->exports(Err)) {
> uint64_t Flags = Entry.flags();
> 
> Similar.
>
>
> Repository:
>  rL LLVM
>
> https://reviews.llvm.org/D35961
>
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35925: [Coverage] Precise region termination with deferred regions

2017-07-28 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In https://reviews.llvm.org/D35925#823978, @arphaman wrote:

> This is awesome!
>
> I noticed in the sample output that llvm-cov is now forced to print some new 
> region markers because the terminator introduces a new region on the same 
> line, e.g.
>
>   |// CHECK-LABEL: _Z10while_loopv:
>  88|  1|void while_loop() {
>  89|  1|  if (false)
>  90|  1|return; // CHECK: [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - 
> #1)
> ^0^1  // Previously, llvm-cov didn't show region 
> markers for this line
>  91|  1|
>
>
> Do you think this can be avoided? Should llvm-cov even try to avoid emitting 
> the region markers? It seems to me that this situation affects just the 
> command-line output of llvm-cov, and region highlighting in HTML won't be 
> impacted by this.


Great question! The region highlighting for the html emitter matches exactly 
with the textual emitter's, so there is an impact. I think we can/should make 
two general improvements to llvm-cov to address the issue, which would be 
useful even without this patch. The first (as you brought up) is to stop 
emitting region markers for segments which start, but do not end, on one line. 
This fixes an existing annoyance with loops:

  for (...; ...; ...) -> { <- This singular curly brace gets a region marker 
because the body's region starts here. That's a little distracting.

It would also suppress highlighting for deferred regions, removing a visual 
distraction. The second improvement would be to to pick better line execution 
counts. In the sample output that you quoted, you see that the line with the 
return gets an execution count of 1. What's happening is that llvm-cov picks 
the maximum execution count from the regions on (or before) the line. The end 
result is a little weird, because we associate the line execution count with 
the first region on a line, and we know the "return" is never executed. I have 
a patch ready to fix this: it corrects a display issue in the existing llvm-cov 
test suite, and it helps even more with deferred regions enabled.


https://reviews.llvm.org/D35925



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


[PATCH] D35103: Expand clang-interpreter with example of throwing in and from the JIT for Windows64.

2017-07-28 Thread Frederich Munch via Phabricator via cfe-commits
marsupial marked 3 inline comments as done.
marsupial added a comment.

Done, thanks. Would it be possible to look at https://reviews.llvm.org/D30709 
as this depends on that. (ELF does not like Windows exceptions).


https://reviews.llvm.org/D35103



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


Re: [PATCH] D35961: [llvm] Update MachOObjectFile::exports interface

2017-07-28 Thread Kevin Enderby via cfe-commits

> On Jul 27, 2017, at 9:50 PM, Saleem Abdulrasool via Phabricator 
>  wrote:
> 
> compnerd added a comment.
> 
> Does anyone use the overload with the `O` for `exports` with `nullptr` 
> instead of `this`?  If not, we could just inline `this` throughout.

This will break lld as it needs the default nullptr.  See r308691.

The reason that O was added was so that this check from r308690 could be added.

+  if (O != nullptr) {
+if (State.Other > O->getLibraryCount()) {
+  *E = malformedError("bad library ordinal: " + Twine((int)State.Other)
+   + " (max " + Twine((int)O->getLibraryCount()) + ") in export "
+   "trie data at node: 0x" + utohexstr(offset));
+  moveToEnd();
+  return;
+}

This is needed for the test case:

+RUN: not llvm-objdump -macho -exports-trie 
%p/Inputs/macho-trie-bad-library-ordinal 2>&1 | FileCheck -check-prefix 
BAD_LIBRARY_ORDINAL %s 
+BAD_LIBRARY_ORDINAL: macho-trie-bad-library-ordinal': truncated or malformed 
object (bad library ordinal: 69 (max 3) in export trie data at node: 0x33)

> 
> 
> 
> 
> Comment at: tools/llvm-nm/llvm-nm.cpp:1230
>   Error Err = Error::success();
> -  for (const llvm::object::ExportEntry  : MachO->exports(Err,
> -   MachO)) {
> +  for (const llvm::object::ExportEntry  : MachO->exports(Err)) {
> bool found = false;
> 
> I think that using `auto` here instead of `llvm::object:ExportEntry` is 
> better for readability.
> 
> 
> 
> Comment at: tools/llvm-objdump/MachODump.cpp:9406
>   Error Err = Error::success();
> -  for (const llvm::object::ExportEntry  : Obj->exports(Err, Obj)) {
> +  for (const llvm::object::ExportEntry  : Obj->exports(Err)) {
> uint64_t Flags = Entry.flags();
> 
> Similar.
> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D35961
> 
> 
> 

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


[PATCH] D35103: Expand clang-interpreter with example of throwing in and from the JIT for Windows64.

2017-07-28 Thread Frederich Munch via Phabricator via cfe-commits
marsupial updated this revision to Diff 108676.
marsupial added a comment.

Use include guards, not pragma once and remove commented CMake debug lines.


https://reviews.llvm.org/D35103

Files:
  examples/clang-interpreter/CMakeLists.txt
  examples/clang-interpreter/Invoke.cpp
  examples/clang-interpreter/Invoke.h
  examples/clang-interpreter/Manager.cpp
  examples/clang-interpreter/Manager.h
  examples/clang-interpreter/README.txt
  examples/clang-interpreter/Test.cxx
  examples/clang-interpreter/main.cpp

Index: examples/clang-interpreter/main.cpp
===
--- examples/clang-interpreter/main.cpp
+++ examples/clang-interpreter/main.cpp
@@ -7,6 +7,9 @@
 //
 //===--===//
 
+#include "Invoke.h"
+#include "Manager.h"
+
 #include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Driver/Compilation.h"
@@ -26,73 +29,61 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
+
 using namespace clang;
 using namespace clang::driver;
 
+namespace interpreter {
+
+static llvm::ExecutionEngine *
+createExecutionEngine(std::unique_ptr M, std::string *ErrorStr) {
+  llvm::EngineBuilder EB(std::move(M));
+  EB.setErrorStr(ErrorStr);
+  EB.setMemoryManager(llvm::make_unique());
+  llvm::ExecutionEngine *EE = EB.create();
+  EE->finalizeObject();
+  return EE;
+}
+
+// Invoked from a try/catch block in invoke.cpp.
+//
+static int Invoke(llvm::ExecutionEngine *EE, llvm::Function *EntryFn,
+  const std::vector , char *const *EnvP) {
+  return EE->runFunctionAsMain(EntryFn, Args, EnvP);
+}
+
 // This function isn't referenced outside its translation unit, but it
 // can't use the "static" keyword because its address is used for
 // GetMainExecutable (since some platforms don't support taking the
 // address of main, and some platforms can't implement GetMainExecutable
 // without being given the address of a function in the main executable).
-std::string GetExecutablePath(const char *Argv0) {
-  // This just needs to be some symbol in the binary; C++ doesn't
-  // allow taking the address of ::main however.
-  void *MainAddr = (void*) (intptr_t) GetExecutablePath;
+std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
   return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
 }
 
-static llvm::ExecutionEngine *
-createExecutionEngine(std::unique_ptr M, std::string *ErrorStr) {
-  return llvm::EngineBuilder(std::move(M))
-  .setEngineKind(llvm::EngineKind::Either)
-  .setErrorStr(ErrorStr)
-  .create();
-}
-
-static int Execute(std::unique_ptr Mod, char *const *envp) {
-  llvm::InitializeNativeTarget();
-  llvm::InitializeNativeTargetAsmPrinter();
-
-  llvm::Module  = *Mod;
-  std::string Error;
-  std::unique_ptr EE(
-  createExecutionEngine(std::move(Mod), ));
-  if (!EE) {
-llvm::errs() << "unable to make execution engine: " << Error << "\n";
-return 255;
-  }
-
-  llvm::Function *EntryFn = M.getFunction("main");
-  if (!EntryFn) {
-llvm::errs() << "'main' function not found in module.\n";
-return 255;
-  }
-
-  // FIXME: Support passing arguments.
-  std::vector Args;
-  Args.push_back(M.getModuleIdentifier());
-
-  EE->finalizeObject();
-  return EE->runFunctionAsMain(EntryFn, Args, envp);
-}
+} // namespace interpreter
 
 int main(int argc, const char **argv, char * const *envp) {
-  void *MainAddr = (void*) (intptr_t) GetExecutablePath;
-  std::string Path = GetExecutablePath(argv[0]);
+  // This just needs to be some symbol in the binary; C++ doesn't
+  // allow taking the address of ::main however.
+  void *MainAddr = (void*) (intptr_t) interpreter::GetExecutablePath;
+  std::string Path = interpreter::GetExecutablePath(argv[0], MainAddr);
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
   TextDiagnosticPrinter *DiagClient =
 new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
 
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
   DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
 
-  // Use ELF on windows for now.
-  std::string TripleStr = llvm::sys::getProcessTriple();
+  const std::string TripleStr = llvm::sys::getProcessTriple();
   llvm::Triple T(TripleStr);
+
+  // Use ELF on Windows-32 and MingW for now.
+#ifndef CLANG_INTERPRETER_COFF_FORMAT
   if (T.isOSBinFormatCOFF())
 T.setObjectFormat(llvm::Triple::ELF);
-
+#endif
+	
   Driver TheDriver(Path, T.str(), Diags);
   TheDriver.setTitle("clang interpreter");
   TheDriver.setCheckInputsExist(false);
@@ -163,12 +154,36 @@
   if (!Clang.ExecuteAction(*Act))
 return 1;
 
+  llvm::InitializeNativeTarget();
+  llvm::InitializeNativeTargetAsmPrinter();
+
   int Res = 255;
-  if (std::unique_ptr Module = Act->takeModule())
-Res = Execute(std::move(Module), envp);
+  if (std::unique_ptr Module = Act->takeModule()) {
+llvm::Function 

[PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-07-28 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 108669.
mibintc added a comment.

Here's an updated patch which is using angle brackets to do the include, so the 
search for stdc-predef.h is limited to system directories. Also my previous 
revision was missing the new test cases since i had gotten a new sandbox but 
forgot to "svn add". This patch is showing the new test cases.


Repository:
  rL LLVM

https://reviews.llvm.org/D34158

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/InitPreprocessor.cpp
  test/Driver/Inputs/stdc-predef/usr/include/stdc-predef.h
  test/Driver/clang_cpp.c
  test/Driver/crash-report-header.h
  test/Driver/crash-report-spaces.c
  test/Driver/crash-report.c
  test/Driver/rewrite-legacy-objc.m
  test/Driver/rewrite-map-in-diagnostics.c
  test/Driver/rewrite-objc.m
  test/Driver/stdc-predef-not.c
  test/Driver/stdc-predef.c
  test/Index/IBOutletCollection.m
  test/Index/annotate-macro-args.m
  test/Index/annotate-tokens-pp.c
  test/Index/annotate-tokens.c
  test/Index/c-index-getCursor-test.m
  test/Index/get-cursor-macro-args.m
  test/Index/get-cursor.cpp
  test/Preprocessor/ignore-pragmas.c
  unittests/Tooling/TestVisitor.h

Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3243,6 +3243,11 @@
   KernelOrKext) {
 CmdArgs.push_back("-ffreestanding");
 IsHosted = false;
+  } else {
+// For standards compliance, clang will preinclude 
+// -ffreestanding suppresses this behavior.
+CmdArgs.push_back("-fsystem-include-if-exists");
+CmdArgs.push_back("stdc-predef.h");
   }
 
   // Forward -f (flag) options which we can pass directly.
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2502,6 +2502,10 @@
   for (const Arg *A : Args.filtered(OPT_chain_include))
 Opts.ChainedIncludes.emplace_back(A->getValue());
 
+  // Add the ordered list of -fsystem-include-if-exists.
+  for (const Arg *A : Args.filtered(OPT_fsystem_include_if_exists))
+Opts.FSystemIncludeIfExists.emplace_back(A->getValue());
+
   for (const Arg *A : Args.filtered(OPT_remap_file)) {
 std::pair Split = StringRef(A->getValue()).split(';');
 
Index: lib/Frontend/InitPreprocessor.cpp
===
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -69,6 +69,15 @@
   Builder.append(Twine("#include \"") + File + "\"");
 }
 
+/// AddImplicitSystemIncludeIfExists - Add an implicit system \#include of the 
+/// specified file to the predefines buffer: precheck with __has_include.
+static void AddImplicitSystemIncludeIfExists(MacroBuilder , 
+ StringRef File) {
+  Builder.append(Twine("#if __has_include( <") + File + ">)");
+  Builder.append(Twine("#include <") + File + ">");
+  Builder.append(Twine("#endif"));
+}
+
 static void AddImplicitIncludeMacros(MacroBuilder , StringRef File) {
   Builder.append(Twine("#__include_macros \"") + File + "\"");
   // Marker token to stop the __include_macros fetch loop.
@@ -1091,6 +1100,13 @@
   // Exit the command line and go back to  (2 is LC_LEAVE).
   if (!PP.getLangOpts().AsmPreprocessor)
 Builder.append("# 1 \"\" 2");
+  
+  // Process -fsystem-include-if-exists directives.
+  for (unsigned i = 0, 
+   e = InitOpts.FSystemIncludeIfExists.size(); i != e; ++i) {
+const std::string  = InitOpts.FSystemIncludeIfExists[i];
+AddImplicitSystemIncludeIfExists(Builder, Path);
+  }
 
   // If -imacros are specified, include them now.  These are processed before
   // any -include directives.
Index: unittests/Tooling/TestVisitor.h
===
--- unittests/Tooling/TestVisitor.h
+++ unittests/Tooling/TestVisitor.h
@@ -52,6 +52,7 @@
   /// \brief Runs the current AST visitor over the given code.
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
+Args.push_back("-ffreestanding");
 switch (L) {
   case Lang_C:
 Args.push_back("-x");
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -735,6 +735,8 @@
   HelpText<"Use specified token cache file">;
 def detailed_preprocessing_record : Flag<["-"], "detailed-preprocessing-record">,
   HelpText<"include a detailed record of preprocessing actions">;
+def fsystem_include_if_exists : Separate<["-"], "fsystem-include-if-exists">, MetaVarName<"">,
+  HelpText<"Include system file before parsing if file exists">;
 
 

[PATCH] D34114: [clang] Change the condition of unnecessary packed warning

2017-07-28 Thread Yan Wang via Phabricator via cfe-commits
yawanng updated this revision to Diff 108665.
yawanng marked 3 inline comments as done.

https://reviews.llvm.org/D34114

Files:
  lib/AST/RecordLayoutBuilder.cpp
  test/CodeGenCXX/warn-padded-packed.cpp

Index: test/CodeGenCXX/warn-padded-packed.cpp
===
--- test/CodeGenCXX/warn-padded-packed.cpp
+++ test/CodeGenCXX/warn-padded-packed.cpp
@@ -17,7 +17,7 @@
 } __attribute__((packed));
 
 struct S4 {
-  int i; // expected-warning {{packed attribute is unnecessary for 'i'}}
+  int i;
   char c;
 } __attribute__((packed));
 
@@ -46,18 +46,18 @@
   int i; // expected-warning {{padding struct 'S8' with 3 bytes to align 'i'}}
 };
 
-struct S9 { // expected-warning {{packed attribute is unnecessary for 'S9'}}
-  int x; // expected-warning {{packed attribute is unnecessary for 'x'}}
-  int y; // expected-warning {{packed attribute is unnecessary for 'y'}}
+struct S9 {
+  int x;
+  int y;
 } __attribute__((packed));
 
-struct S10 { // expected-warning {{packed attribute is unnecessary for 'S10'}}
-  int x; // expected-warning {{packed attribute is unnecessary for 'x'}}
+struct S10 {
+  int x;
   char a,b,c,d;
 } __attribute__((packed));
 
 
-struct S11 {
+struct S11 { // expected-warning {{packed attribute is unnecessary for 'S11'}}
   bool x;
   char a,b,c,d;
 } __attribute__((packed));
@@ -72,5 +72,82 @@
   bool b : 10;
 };
 
+struct S14 { // expected-warning {{packed attribute is unnecessary for 'S14'}}
+  char a,b,c,d;
+} __attribute__((packed));
+
+struct S15 { // expected-warning {{packed attribute is unnecessary for 'S15'}}
+  struct S14 s;
+  char a;
+} __attribute__((packed));
+
+struct S16 { // expected-warning {{padding size of 'S16' with 2 bytes to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S16'}}
+  char a,b;
+} __attribute__((packed, aligned(4)));
+
+struct S17 {
+  struct S16 s;
+  char a,b;
+} __attribute__((packed, aligned(2)));
+
+struct S18 { // expected-warning {{padding size of 'S18' with 2 bytes to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S18'}}
+  struct S16 s;
+  char a,b;
+} __attribute__((packed, aligned(4)));
+
+struct S19 { // expected-warning {{packed attribute is unnecessary for 'S19'}}
+  bool b;
+  char a;
+} __attribute__((packed, aligned(1)));
+
+struct S20 {
+  int i;
+  char a;
+} __attribute__((packed, aligned(1)));
+
+struct S21 { // expected-warning {{padding size of 'S21' with 4 bits to alignment boundary}}
+  unsigned char a : 6;
+  unsigned char b : 6;
+} __attribute__((packed, aligned(1)));
+
+struct S22 { // expected-warning {{packed attribute is unnecessary for 'S22'}}
+  unsigned char a : 4;
+  unsigned char b : 4;
+} __attribute__((packed));
+
+struct S23 { // expected-warning {{padding size of 'S23' with 4 bits to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S23'}}
+  unsigned char a : 2;
+  unsigned char b : 2;
+} __attribute__((packed));
+
+struct S24 {
+  unsigned char a : 6;
+  unsigned char b : 6;
+  unsigned char c : 6;
+  unsigned char d : 6;
+  unsigned char e : 6;
+  unsigned char f : 6;
+  unsigned char g : 6;
+  unsigned char h : 6;
+} __attribute__((packed));
+
+struct S25 { // expected-warning {{padding size of 'S25' with 7 bits to alignment boundary}} expected-warning {{packed attribute is unnecessary for 'S25'}}
+  unsigned char a;
+  unsigned char b : 1;
+} __attribute__((packed));
+
+struct S26 { // expected-warning {{packed attribute is unnecessary for 'S26'}}
+  unsigned char a : 1;
+  unsigned char b; //expected-warning {{padding struct 'S26' with 7 bits to align 'b'}}
+} __attribute__((packed));
+
+struct S27 { // expected-warning {{padding size of 'S27' with 7 bits to alignment boundary}}
+  unsigned char a : 1;
+  unsigned char b : 8;
+} __attribute__((packed));
+
+
 // The warnings are emitted when the layout of the structs is computed, so we have to use them.
-void f(S1*, S2*, S3*, S4*, S5*, S6*, S7*, S8*, S9*, S10*, S11*, S12*, S13*) { }
+void f(S1*, S2*, S3*, S4*, S5*, S6*, S7*, S8*, S9*, S10*, S11*, S12*, S13*,
+   S14*, S15*, S16*, S17*, S18*, S19*, S20*, S21*, S22*, S23*, S24*, S25*,
+   S26*, S27*){}
Index: lib/AST/RecordLayoutBuilder.cpp
===
--- lib/AST/RecordLayoutBuilder.cpp
+++ lib/AST/RecordLayoutBuilder.cpp
@@ -632,6 +632,9 @@
   /// pointer, as opposed to inheriting one from a primary base class.
   bool HasOwnVFPtr;
 
+  /// \brief the flag of field offset changing due to packed attribute.
+  bool HasPackedField;
+
   typedef llvm::DenseMap BaseOffsetsMapTy;
 
   /// Bases - base classes and their offsets in the record.
@@ -666,7 +669,7 @@
 NonVirtualSize(CharUnits::Zero()),
 NonVirtualAlignment(CharUnits::One()), PrimaryBase(nullptr),
 PrimaryBaseIsVirtual(false), HasOwnVFPtr(false),
-FirstNearlyEmptyVBase(nullptr) {}
+HasPackedField(false), 

[PATCH] D35941: Fix -Wshadow false positives with function-local classes.

2017-07-28 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone accepted this revision.
Quuxplusone added a comment.

> But if I'm overseeing reasons to issue a warning in this case, we could add 
> an analogue of `-Wshadow-uncaptured-local` for this case. WDYT?

I still think "any warning" is a marginally better UX than "no warning" on the 
particular code in question; but of course I defer to Reid/Richard/GCC on the 
practicalities. Adding a new warning option might not be worth the trouble. :)


https://reviews.llvm.org/D35941



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


[PATCH] D33900: Print registered targets in clang's version information

2017-07-28 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

dim: Does putting the target listing behind a different flag work for you? 
Which problem are you trying to solve here?


https://reviews.llvm.org/D33900



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


[PATCH] D34114: [clang] Change the condition of unnecessary packed warning

2017-07-28 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
chh added inline comments.



Comment at: lib/AST/RecordLayoutBuilder.cpp:1887
+// greater than the one after packing.
+if (Packed && UnpackedAlignment <= Alignment)
   Diag(D->getLocation(), diag::warn_unnecessary_packed)

chh wrote:
> With this change, UnpackedSize is unused and caused a warning about 
> unused-but-set-variable. Please use it or remove the variable.
> 
> I think UnpackedSizeInBits should be used somehow in the condition, because 
> bit fields can be affected by the packed attribute. Please add a few unit 
> test cases with bit fields. For example, the following cases showed that S21 
> is affected by packed, but got a wrong "unnecessary" warning after this 
> change.
> 
> 
> ```
> struct S21 {
>   unsigned char a:6;
>   unsigned char b:6;
> } __attribute__((packed, aligned(1)));
> struct S22 {
>   unsigned char a:6;
>   unsigned char b:6;
> } __attribute__((aligned(1)));
> struct S23 {
>   unsigned char a:6;
>   unsigned char b:6;
> };
> 
> ```
> Warnings:
> 
> ```
>   padding size of 'S21' with 4 bits to alignment boundary
>   packed attribute is unnecessary for 'S21'
>   padding struct 'S22' with 2 bits to align 'b'
>   padding size of 'S22' with 2 bits to alignment boundary
>   padding struct 'S23' with 2 bits to align 'b'
>   padding size of 'S23' with 2 bits to alignment boundary
> 
> ```
> 
I am still getting warning about unused-but-set-variable UnpackedSize.




Comment at: lib/AST/RecordLayoutBuilder.cpp:636
+  /// \brief the flag of field offset changing due to packed attribute.
+  bool IsFieldOffsetChangedWithPacked;
+

s/IsFieldOffsetChangedWithPacked/HasPackedField/




Comment at: lib/AST/RecordLayoutBuilder.cpp:1985
+ // If the offset of any field changed due to packed, then the packed is not
+ // necessary.
+ if (isPacked && Offset != UnpackedOffset) {

"then packed is not necessary" is incorrect.
Maybe this comment can be removed since the code is clear enough.




Comment at: test/CodeGenCXX/warn-padded-packed.cpp:152
+void f(S1*, S2*, S3*, S4*, S5*, S6*, S7*, S8*, S9*, S10*, S11*, S12*, S13*, 
S14*, S15*,
+   S16*, S17*, S18*, S19*, S20*, S21*, S22*, S23*, S24*, S25*, S26*, 
S27*){}

Please wrap line 150, 151, 152 to less than 80 chars per line.
The only exceptions in this file are the 'expected-warning' lines.
 


https://reviews.llvm.org/D34114



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


[PATCH] D34030: Fix the postorder visting of the ClassTemplateSpecializationDecl nodes in the RecursiveASTVisitor.

2017-07-28 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Nice!

One more comment: please also fix names of local variables, member variables 
and function parameters. See 
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly.
 Yes, there is precedence for violations in other places in this file, but that 
doesn't mean we should keep adding those :-)


https://reviews.llvm.org/D34030



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


[PATCH] D34873: Fix miscompiled 32bit binaries by mingw

2017-07-28 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover added inline comments.



Comment at: lib/AST/ExprConstant.cpp:583
+uint64_t& GetArrayInitIndex() {
+return reinterpret_cast(ArrayInitIndex[0]);
+}

rnk wrote:
> Surely this will fault on SPARC or ARM or other ISAs that care about 
> alignment?
As well as being horribly undefined behaviour.


https://reviews.llvm.org/D34873



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


[PATCH] D35996: [X86][AVX] Ensure vector non-temporal load/store intrinsics force pointer alignment (PR33830)

2017-07-28 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D35996



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


[PATCH] D35941: Fix -Wshadow false positives with function-local classes.

2017-07-28 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.

> Another data point is that GCC doesn't warn in this case.

That seems like a reasonable tie breaker when implementing these kinds of 
style-enforcement warnings. :)


https://reviews.llvm.org/D35941



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


[PATCH] D28691: Add OpenCL 2.0 atomic builtin functions as Clang builtin

2017-07-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/Basic/SyncScope.h:1
+//===--- SyncScope.h - atomic synchronization scopes *- C++ 
-*-===//
+//

Capitalization.



Comment at: include/clang/Basic/SyncScope.h:20
+
+namespace SyncScope {
+

LLVM uses this namespace pattern in code that predates the addition of scoped 
enums to C++.  Those days are behind us; we should just use a scoped enum.



Comment at: include/clang/Basic/SyncScope.h:22
+
+/// \brief Defines the synch scope values used by the atomic instructions.
+///

It defines the synch scope values used by the atomic builtins and expressions.  
LLVM's headers define the values used by the instructions.



Comment at: include/clang/Basic/SyncScope.h:25-29
+  SingleThread  = 0,
+  WorkGroup = 1,
+  Device= 2,
+  System= 3,
+  SubGroup  = 4,

Anastasia wrote:
> t-tye wrote:
> > Since the builtins are being named as __opencl then should these also be 
> > named as opencl_ since they are the memory scopes for OpenCL using the 
> > OpenCL numeric values?
> > 
> > If another language wants to use memory scopes, would it then add its own 
> > langx_* names in a similar way that is done for address spaces where the 
> > LangAS enumeration type has values for each distinct language. Each target 
> > is then responsible for mapping each language scope to the appropriate 
> > target specific scope as is done for address spaces?
> > 
> > If so then the builtins are really supporting the concept of memory scopes 
> > and are not language specific as this enumeration can support multiple 
> > languages in the same way as the LangAS enumeration supports multiple 
> > languages. If so the builtins would be better named to reflect this as 
> > @b-sumner suggested.
> We generally prefix the names of OpenCL specific implementations. So perhaps 
> we should do some renaming here in case we don't intend this to be generic 
> implementation.
I agree that we should name the OpenCL-specific ones, like WorkGroup, with an 
OpenCL prefix.



Comment at: include/clang/Basic/SyncScope.h:32
+
+inline unsigned getMaxValue(void) {
+  return SubGroup;

This is C++; please just use () instead of (void).



Comment at: lib/CodeGen/CGAtomic.cpp:503
+  ->getAs()
+  ->isSignedIntegerType();
+}

None of the .getTypePtr() stuff here is necessary.

This function shouldn't really be necessary.  I would encourage you to add a 
getValueType() accessor to AtomicExpr:

  QualType AtomicExpr::getValueType() const {
auto T = getPtr()->getType()->castTo()->getPointeeType();
if (auto AT = T->getAs()) {
  return AT->getValueType();
} else {
  return T;
}
  }

You can then just use E->getValueType()->isSignedIntegerType() and eliminate 
this helper function.



Comment at: lib/CodeGen/CGAtomic.cpp:919
+->getPointeeType()
+.getAddressSpace();
+  auto *DestType = T->getPointerElementType()->getPointerTo(DestAS);

Again you're using getTypePtr() unnecessarily.

The check should be whether the AST-level address spaces match, not whether the 
lowered address spaces match.

Please pass E->getType() instead of E here.

You should remove the DoIt parameter and just check E->isOpenCL() (where E is 
the AtomicExpr already in scope).



Comment at: lib/CodeGen/CGCall.cpp:3911
+  V = Builder.CreateBitOrPointerCast(V,
+  IRFuncTy->getParamType(FirstIRArg));
 

No.  Callers should ensure that they've added the right argument type, at least 
at the level of address spaces.



Comment at: lib/CodeGen/TargetInfo.h:266
+  /// Get the syncscope name used in LLVM IR.
+  virtual llvm::StringRef getSyncScopeName(SyncScope::ID S) const;
 };

Why does this return a StringRef instead of an llvm::SynchronizationScope?


https://reviews.llvm.org/D28691



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


[PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-07-28 Thread Melanie Blower via Phabricator via cfe-commits
mibintc planned changes to this revision.
mibintc added a comment.

@erichkeane contacted me offline and pointed out I'm twine-ing with " not <. 
i'm planning to change the option name from "finclude if exists" to "fsystem 
include if exists", then i'll quote with < not ". hope to get this updated 
patch into review later today. let me know if you think i'm off track. thanks 
for all your careful review. i knew there was something wrong with the include 
like Fedor pointed out but i couldn't see where i went wrong.


Repository:
  rL LLVM

https://reviews.llvm.org/D34158



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


[PATCH] D34873: Fix miscompiled 32bit binaries by mingw

2017-07-28 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/AST/ExprConstant.cpp:583
+uint64_t& GetArrayInitIndex() {
+return reinterpret_cast(ArrayInitIndex[0]);
+}

Surely this will fault on SPARC or ARM or other ISAs that care about alignment?


https://reviews.llvm.org/D34873



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


r309390 - [CMake] NFC. Add clang-tablegen-targets utility target

2017-07-28 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Fri Jul 28 08:33:47 2017
New Revision: 309390

URL: http://llvm.org/viewvc/llvm-project?rev=309390=rev
Log:
[CMake]  NFC. Add clang-tablegen-targets utility target

By creating this target other projects that depend on clang-generated headers 
(like LLDB) will no longer be order-dependent on Clang being processed by CMake 
first.

Also, by creating a dummy of this target in ClangConfig.cmake, projects that 
can build against out-of-tree clang can freely depend on the target without 
needing to have conditionals for if clang is in-tree or out-of-tree.

Modified:
cfe/trunk/CMakeLists.txt
cfe/trunk/cmake/modules/ClangConfig.cmake.in

Modified: cfe/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=309390=309389=309390=diff
==
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Fri Jul 28 08:33:47 2017
@@ -412,7 +412,8 @@ add_subdirectory(include)
 
 # All targets below may depend on all tablegen'd files.
 get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS)
-list(APPEND LLVM_COMMON_DEPENDS ${CLANG_TABLEGEN_TARGETS})
+add_custom_target(clang-tablegen-targets DEPENDS ${CLANG_TABLEGEN_TARGETS})
+list(APPEND LLVM_COMMON_DEPENDS clang-tablegen-targets)
 
 # Force target to be built as soon as possible. Clang modules builds depend
 # header-wise on it as they ship all headers from the umbrella folders. 
Building

Modified: cfe/trunk/cmake/modules/ClangConfig.cmake.in
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/ClangConfig.cmake.in?rev=309390=309389=309390=diff
==
--- cfe/trunk/cmake/modules/ClangConfig.cmake.in (original)
+++ cfe/trunk/cmake/modules/ClangConfig.cmake.in Fri Jul 28 08:33:47 2017
@@ -11,3 +11,10 @@ set(CLANG_INCLUDE_DIRS "@CLANG_CONFIG_IN
 
 # Provide all our library targets to users.
 include("@CLANG_CONFIG_EXPORTS_FILE@")
+
+# By creating clang-tablegen-targets here, subprojects that depend on Clang's
+# tablegen-generated headers can always depend on this target whether building
+# in-tree with Clang or not.
+if(NOT TARGET clang-tablegen-targets)
+  add_custom_target(clang-tablegen-targets)
+endif()


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


[PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-07-28 Thread Fedor Sergeev via Phabricator via cfe-commits
fedor.sergeev added a comment.

In https://reviews.llvm.org/D34158#824079, @jyknight wrote:

> In https://reviews.llvm.org/D34158#823316, @fedor.sergeev wrote:
>
> > Hmm... I tried this patch and now the following worries me:
> >
> > - it passes -finclude-if-exists stdc-predef.h on all platforms (say, 
> > including my Solaris platform that has no system stdc-predef.h)
>
>
> Right, but Solaris probably _ought_ to add one as well, to define those 
> macros.


Point taken, started internal discussion with Solaris header folks.

> +1 for using a <> include -- that does seem better.

This is the only remaining issue that I would like to see fixed here.


Repository:
  rL LLVM

https://reviews.llvm.org/D34158



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


[PATCH] D28691: Add OpenCL 2.0 atomic builtin functions as Clang builtin

2017-07-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D28691#823810, @Anastasia wrote:

> In https://reviews.llvm.org/D28691#820684, @rjmccall wrote:
>
> > In https://reviews.llvm.org/D28691#820641, @b-sumner wrote:
> >
> > > In https://reviews.llvm.org/D28691#820595, @rjmccall wrote:
> > >
> > > > In https://reviews.llvm.org/D28691#820541, @b-sumner wrote:
> > > >
> > > > > There are other languages for heterogeneous compute that have scopes, 
> > > > > although not exposed quite as explicitly as OpenCL.  For example 
> > > > > AMD's "HC" language.  And any language making use of clang and 
> > > > > targeting SPIR-V would likely use these builtins.  I think a more 
> > > > > generic prefix is appropriate, and "scoped" tells us exactly when 
> > > > > these are needed.
> > > >
> > > >
> > > > But would those languages use the same language design for these scopes 
> > > > as OpenCL if they did expose them, as opposed to some more elaborate 
> > > > scoping specification?  My objection is not that the concept is 
> > > > inherently OpenCL-specific, it's that the presentation in the language 
> > > > might be inherently OpenCL-specific, which makes staying in the opencl 
> > > > namespace is prudent.
> > >
> > >
> > > Are you envisioning a language far enough from C/C++ that a standard 
> > > library or header would not be able to map a scoped atomic operation into 
> > > a call to one of these new builtins?  Would we expect more of such 
> > > languages than languages that would do such a mapping?
> >
> >
> > If you're using Clang as a frontend for your language, it must be similar 
> > enough to C to call a builtin function.  That's not at issue.  The central 
> > question here is whether these builtins are meaningfully general outside of 
> > OpenCL.  The concept of heterogenous computation is certainly not specific 
> > to OpenCL;  however, these builtins are defined in terms of scopes — "work 
> > item", "work group", "device", and "all svm devices" — which, it seems to 
> > me, are basically only defined by reference to the OpenCL architecture.  A 
> > different heterogenous compute environment might reasonably formalize 
> > scopes in a completely different way; for example, it might wish to be more 
> > explicit about exactly which peers / devices to synchronize with.
> >
> > SPIR is explicitly defined on top of the OpenCL model.  Users should be 
> > able to use OpenCL builtins when targeting it.  That does not make those 
> > builtins more general than OpenCL.
> >
> > John.
>
>
> The scope concept in OpenCL is fairly generic. And the builtins just take one 
> extra argument on top of the existing C11 builtin style. The OpenCL scopes 
> have of course specific meaning to the OpenCL model, but there is nothing 
> preventing other uses of the scope feature.


Yes, it is possible that some other language could introduce exactly the same 
scope-atomics concept only with a slightly different enumeration of scopes.  
But then we really shouldn't allow the OpenCL scopes to be used in that 
language, which means there would still not be a language-independent way of 
using these builtins.

> As far as I understand atomic scope implementation in LLVM is fairly generic 
> wrt scope types and it is intended for broader functionality than just OpenCL.

In some ways this is reasoning the wrong way around.  I am not deeply informed 
about heterogenous computing, so I am happy to accept that 
llvm::SynchronizationScope is well-designed for our current needs.  But LLVM's 
representation is, by design, ultimately just an implementation detail and can 
be easily updated — it's just a matter of changing a few calls and adding an 
upgrade path to the bitcode loader, exactly as we did when we introduced 
llvm::SynchronizationScope.  That is not true of source language features, even 
builtins; their design is a contract with programmers, and the bar is 
substantially higher.

We do not have a compelling reason to claim that these are generally useful, so 
we should not.  They should stay namespaced and be flagged as language-specific 
builtins.

John.


https://reviews.llvm.org/D28691



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


Re: [PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-07-28 Thread Fedor Sergeev via cfe-commits
On Fri, Jul 28, 2017 at 02:07:29PM +, Blower, Melanie wrote:
>  
> 
> fedor.sergeev added a comment.
> 
> Hmm... I tried this patch and now the following worries me:
> 
> - it passes -finclude-if-exists stdc-predef.h on all platforms (say, 
> including my Solaris platform that has no system stdc-predef.h)
> - it searches all the paths, not just "system include" ones
> 
> That essentially disallows user to have stdc-predef.h include in my own 
> project, since there is a chance that this user header will be accidentally 
> included by this hidden machinery.
> 
> >> Yes, I recognize this problem. However, I don't know an acceptable way to 
> >> solve it. Does anyone have a recommendation? I had tried putting angle 
> >> brackets around the file name string to imply a system-only search but 
> >> that didn't work:  I guess the >angle brackets are taken to be part of the 
> >> file name.  I believe it's intentional that has_include doesn't recognize 
> >> the angle, I see test cases that have __has_include( "<...") Quoting from 
> >> the patch:
> // For standards compliance, clang will preinclude 
> // -ffreestanding suppresses this behavior.
> CmdArgs.push_back("-finclude-if-exists");
> CmdArgs.push_back(""); // This doesn't work to restrict 
> the search to system includes
>   } 
> 
> >I could change the argument scanner for __has_include to recognize the angle 
> >brackets -- would that be acceptable?  Alternatively, I could change the 
> >flag to be "finclude-if-exists" into "fsystem-include-if-exists". Then I 
> >could create a new preprocessing keyword(is that the right term?) 
> >__has_system_include and use that instead of __has_include.  
> 
> >I tried this test case with -c -E:
> >cat test1.c
> >#if __has_include( "stdio.h" )
> >#error it has stdio without angle  // This is printed
> >#else
> >#error it does not have stdio without angle
> >#endif
> 
> >#if __has_include( "" )

According to:
  https://clang.llvm.org/docs/LanguageExtensions.html

a proper syntax here is without "s:

  #if __has_include()

regards,
  Fedor.

> >#error it has stdio with angle
> >#else
> >#error it does not have stdio with angle // This is printed
> >#endif
> 
>   ] cat stdc-predef.h
>   #error I was not expecting to see that
>   ] bin/clang hello-world.c
>   In file included from :2:
>   ./stdc-predef.h:1:2: error: I was not expecting to see this!
>   #error I was not expecting to see this!
>^
>   1 error generated.
>   ]
> 
> 
> Repository:
>   rL LLVM
> 
> https://reviews.llvm.org/D34158
> 
> 
> 

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


RE: [PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-07-28 Thread Blower, Melanie via cfe-commits
 
jyknight added a comment.

In https://reviews.llvm.org/D34158#823316, @fedor.sergeev wrote:

> Hmm... I tried this patch and now the following worries me:
>
> - it passes -finclude-if-exists stdc-predef.h on all platforms (say, 
> including my Solaris platform that has no system stdc-predef.h)


Right, but Solaris probably _ought_ to add one as well, to define those macros.

> - it searches all the paths, not just "system include" ones
> 
>   That essentially disallows user to have stdc-predef.h include in my own 
> project, since there is a chance that this user header will be accidentally 
> included by this hidden machinery.

IMO, this is a fairly negligible issue, and so we go *shrug* oh well.

+1 for using a <> include -- that does seem better.

>> If I make a change like this: CmdArgs.push_back(""); the 
>> program fails to pre-include std-predef.h; so I assume that there is 
>> something that needs to be fixed with this line: 
>> Opts.FIncludeIfExists.emplace_back(A->getValue());   If we want those <> in 
>> there, but no extra " in there, I would need to study which value is 
>> returned and fiddle around with the characters to make sure the right thing 
>> gets put into the input stream. This will take me quite a bit more time 
>> since I know close to diddly at this point.

But, note, that will have no effect w.r.t. this issue for most users, since 
typically people use "cc -Isomepath", which adds 'somepath' to the list which 
gets searched by both <> and "" includes. Hardly anyone uses -iquote.


Repository:
  rL LLVM

https://reviews.llvm.org/D34158



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


Re: r309106 - Recommit r308327 2nd time: Add a warning for missing

2017-07-28 Thread Alex L via cfe-commits
Thanks, I recommitted it in r309386.

On 27 July 2017 at 15:53, Hans Wennborg  wrote:

> On Thu, Jul 27, 2017 at 3:41 AM, Alex L  wrote:
> >
> >
> > On 26 July 2017 at 22:32, Hans Wennborg  wrote:
> >>
> >> On Wed, Jul 26, 2017 at 11:27 AM, Hans Wennborg 
> wrote:
> >> > On Wed, Jul 26, 2017 at 5:20 AM, Alex Lorenz via cfe-commits
> >> >  wrote:
> >> >> Author: arphaman
> >> >> Date: Wed Jul 26 05:20:57 2017
> >> >> New Revision: 309106
> >> >>
> >> >> URL: http://llvm.org/viewvc/llvm-project?rev=309106=rev
> >> >> Log:
> >> >> Recommit r308327 2nd time: Add a warning for missing
> >> >> '#pragma pack (pop)' and suspicious uses of '#pragma pack' in
> included
> >> >> files
> >> >>
> >> >> The first recommit (r308441) caused a "non-default #pragma pack value
> >> >> might
> >> >> change the alignment of struct or union members in the included file"
> >> >> warning
> >> >> in LLVM itself. This recommit tweaks the added warning to avoid
> >> >> warnings for
> >> >> #includes that don't have any records that are affected by the
> >> >> non-default
> >> >> alignment. This tweak avoids the previously emitted warning in LLVM.
> >> >>
> >> >> Original message:
> >> >>
> >> >> This commit adds a new -Wpragma-pack warning. It warns in the
> following
> >> >> cases:
> >> >>
> >> >> - When a translation unit is missing terminating #pragma pack (pop)
> >> >> directives.
> >> >> - When entering an included file if the current alignment value as
> >> >> determined
> >> >>   by '#pragma pack' directives is different from the default
> alignment
> >> >> value.
> >> >> - When leaving an included file that changed the state of the current
> >> >> alignment
> >> >>   value.
> >> >>
> >> >> rdar://10184173
> >> >>
> >> >> Differential Revision: https://reviews.llvm.org/D35484
> >> >
> >> > We have code in Chromium that does exactly this:
> >> >
> >> > gles2_cmd_format.h does #pragma pack(push, 4) and then #includes a
> >> > file with some generated structs, with the intention that the pragma
> >> > applies to them.
> >> >
> >> > What's the best way to pacify the warning in this case?
> >> >
> >> > (We're tracking this in
> >> > https://bugs.chromium.org/p/chromium/issues/detail?id=749197)
> >>
> >> I agree that cases 1) and 3) from your patch description make sense to
> >> warn for, but I'm not sure that's the case for 2). Do you have
> >> examples where this catches any bugs? In our case #pragma packing an
> >> included file is intentional, and I suspect it might be a bit of a
> >> pattern.
> >
> >
> > I see, thanks for your input.
> >
> > 2) is generally designed for times when #pragma pack pop was accidentally
> > used too late (after some #includes that unintentionally receive the
> > alignment). I can see how some projects use this pattern heavily, and I
> > don't think there's a good way to pacify this warning in that case.
> >
> > I think that for us it would be reasonable to turn 2) off by default, and
> > allow users to enable it explicitly using a stronger flag (something like
> > -Wpragma-pack-suspicious-include?). I think that I will leave 2) out of
> this
> > commit, recommit it without 2) and then commit 2) as a non-default
> warning
> > that uses a separate flag.
>
> That sounds reasonable. You can probably still do it with the same
> commit, just moving 2) behind a separate flag.
>
> Thanks,
> Hans
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r309386 - Recommit r308327 3rd time: Add a warning for missing

2017-07-28 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Jul 28 07:41:21 2017
New Revision: 309386

URL: http://llvm.org/viewvc/llvm-project?rev=309386=rev
Log:
Recommit r308327 3rd time: Add a warning for missing
'#pragma pack (pop)' and suspicious uses of '#pragma pack' in included files

The second recommit (r309106) was reverted because the "non-default #pragma
pack value chages the alignment of struct or union members in the included file"
warning proved to be too aggressive for external projects like Chromium
(https://bugs.chromium.org/p/chromium/issues/detail?id=749197). This recommit
makes the problematic warning a non-default one, and gives it the
-Wpragma-pack-suspicious-include warning option.

The first recommit (r308441) caused a "non-default #pragma pack value might
change the alignment of struct or union members in the included file" warning
in LLVM itself. This recommit tweaks the added warning to avoid warnings for
#includes that don't have any records that are affected by the non-default
alignment. This tweak avoids the previously emitted warning in LLVM.

Original message:

This commit adds a new -Wpragma-pack warning. It warns in the following cases:

- When a translation unit is missing terminating #pragma pack (pop) directives.
- When entering an included file if the current alignment value as determined
  by '#pragma pack' directives is different from the default alignment value.
- When leaving an included file that changed the state of the current alignment
  value.

rdar://10184173

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

Added:
cfe/trunk/test/PCH/suspicious-pragma-pack.c
cfe/trunk/test/Sema/Inputs/pragma-pack1.h
cfe/trunk/test/Sema/Inputs/pragma-pack2.h
cfe/trunk/test/Sema/suspicious-pragma-pack.c
cfe/trunk/test/SemaObjC/Inputs/empty.h
cfe/trunk/test/SemaObjC/suspicious-pragma-pack.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Lex/PPCallbacks.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaAttr.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/OpenMP/declare_simd_messages.cpp
cfe/trunk/test/PCH/pragma-pack.c
cfe/trunk/test/Parser/pragma-options.c
cfe/trunk/test/Parser/pragma-options.cpp
cfe/trunk/test/Parser/pragma-pack.c
cfe/trunk/test/Sema/pragma-pack.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=309386=309385=309386=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Jul 28 07:41:21 2017
@@ -471,8 +471,10 @@ def IgnoredPragmaIntrinsic : DiagGroup<"
 def UnknownPragmas : DiagGroup<"unknown-pragmas">;
 def IgnoredPragmas : DiagGroup<"ignored-pragmas", [IgnoredPragmaIntrinsic]>;
 def PragmaClangAttribute : DiagGroup<"pragma-clang-attribute">;
+def PragmaPackSuspiciousInclude : DiagGroup<"pragma-pack-suspicious-include">;
+def PragmaPack : DiagGroup<"pragma-pack", [PragmaPackSuspiciousInclude]>;
 def Pragmas : DiagGroup<"pragmas", [UnknownPragmas, IgnoredPragmas,
-PragmaClangAttribute]>;
+PragmaClangAttribute, PragmaPack]>;
 def UnknownWarningOption : DiagGroup<"unknown-warning-option">;
 def NSobjectAttribute : DiagGroup<"NSObject-attribute">;
 def IndependentClassAttribute : DiagGroup<"IndependentClass-attribute">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=309386=309385=309386=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 28 07:41:21 
2017
@@ -712,6 +712,17 @@ def err_pragma_options_align_mac68k_targ
 def warn_pragma_pack_invalid_alignment : Warning<
   "expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">,
   InGroup;
+def warn_pragma_pack_non_default_at_include : Warning<
+  "non-default #pragma pack value changes the alignment of struct or union "
+  "members in the included file">, InGroup,
+  DefaultIgnore;
+def warn_pragma_pack_modified_after_include : Warning<
+  "the current #pragma pack aligment value is modified in the included "
+  "file">, InGroup;
+def warn_pragma_pack_no_pop_eof : Warning<"unterminated "
+  "'#pragma pack (push, ...)' at end of file">, InGroup;
+def note_pragma_pack_here : Note<
+  "previous '#pragma pack' directive that modifies alignment is here">;
 // Follow the 

[PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-07-28 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In https://reviews.llvm.org/D34158#823316, @fedor.sergeev wrote:

> Hmm... I tried this patch and now the following worries me:
>
> - it passes -finclude-if-exists stdc-predef.h on all platforms (say, 
> including my Solaris platform that has no system stdc-predef.h)


Right, but Solaris probably _ought_ to add one as well, to define those macros.

> - it searches all the paths, not just "system include" ones
> 
>   That essentially disallows user to have stdc-predef.h include in my own 
> project, since there is a chance that this user header will be accidentally 
> included by this hidden machinery.

IMO, this is a fairly negligible issue, and so we go *shrug* oh well.

+1 for using a <> include -- that does seem better.

But, note, that will have no effect w.r.t. this issue for most users, since 
typically people use "cc -Isomepath", which adds 'somepath' to the list which 
gets searched by both <> and "" includes. Hardly anyone uses -iquote.


Repository:
  rL LLVM

https://reviews.llvm.org/D34158



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-07-28 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 108651.
Typz added a comment.

Rebase


https://reviews.llvm.org/D33589

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9475,6 +9475,60 @@
   EXPECT_EQ("#pragma option -C -A", format("#pragmaoption   -C   -A"));
 }
 
+TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) {
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 20;
+
+  verifyFormat("int a; // the\n"
+   "   // comment", Style);
+  EXPECT_EQ("int a; /* first line\n"
+"* second\n"
+"* line third\n"
+"* line\n"
+"*/",
+			format("int a; /* first line\n"
+   "* second\n"
+   "* line third\n"
+   "* line\n"
+   "*/", Style));
+  EXPECT_EQ("int a; // first line\n"
+"   // second\n"
+"   // line third\n"
+"   // line",
+format("int a; // first line\n"
+   "   // second line\n"
+   "   // third line",
+   Style));
+
+  Style.PenaltyExcessCharacter = 90;
+  verifyFormat("int a; // the comment", Style);
+  EXPECT_EQ("int a; // the\n"
+"   // comment aa",
+format("int a; // the comment aa", Style));
+  EXPECT_EQ("int a; /* first line\n"
+"* second line\n"
+"* third line\n"
+"*/",
+			format("int a; /* first line\n"
+	   "* second line\n"
+			   "* third line\n"
+	   "*/", Style));
+  EXPECT_EQ("int a; // first line\n"
+"   // second line\n"
+"   // third line",
+format("int a; // first line\n"
+   "   // second line\n"
+   "   // third line",
+   Style));
+  EXPECT_EQ("int a; /* first line\n"
+"* second\n"
+"* line third\n"
+"* line\n"
+"*/",
+format("int a; /* first line second line third line"
+   "\n*/", Style));
+}
+
 #define EXPECT_ALL_STYLES_EQUAL(Styles)\
   for (size_t i = 1; i < Styles.size(); ++i)   \
   EXPECT_EQ(Styles[0], Styles[i]) << "Style #" << i << " of " << Styles.size() \
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -885,6 +885,7 @@
 for (std::deque::iterator I = Path.begin(), E = Path.end();
  I != E; ++I) {
   unsigned Penalty = 0;
+  State.Reflow = (*I)->State.Reflow;
   formatChildren(State, (*I)->NewLine, /*DryRun=*/false, Penalty);
   Penalty += Indenter->addTokenToState(State, (*I)->NewLine, false);
 
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -27,6 +27,7 @@
 namespace format {
 
 class AnnotatedLine;
+class BreakableToken;
 struct FormatToken;
 struct LineState;
 struct ParenState;
@@ -100,6 +101,11 @@
   unsigned breakProtrudingToken(const FormatToken , LineState ,
 bool DryRun);
 
+  unsigned reflowProtrudingToken(const FormatToken & Current, LineState & State,
+ std::unique_ptr & Token,
+ unsigned ColumnLimit, bool DryRun);
+
+
   /// \brief Appends the next token to \p State and updates information
   /// necessary for indentation.
   ///
@@ -350,6 +356,8 @@
   /// \brief The indent of the first token.
   unsigned FirstIndent;
 
+  bool Reflow = true;
+
   /// \brief The line that is being formatted.
   ///
   /// Does not need to be considered for memoization because it doesn't change.
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1219,92 +1219,10 @@
   return 0;
 }
 
-unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken ,
-LineState ,
-bool DryRun) {
-  // Don't break multi-line tokens other than block comments. Instead, just
-  // update the state.
-  if (Current.isNot(TT_BlockComment) && Current.IsMultiline)
-return addMultilineToken(Current, State);
-
-  // Don't break implicit string literals or 

[PATCH] D35996: [X86][AVX] Ensure vector non-temporal load/store intrinsics force pointer alignment (PR33830)

2017-07-28 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.

Clang specifies a max type alignment of 16 bytes on darwin targets (annoyingly 
in the driver not via cc1), meaning that the builtin nontemporal stores don't 
correctly align the loads/stores to 32 or 64 bytes when required, resulting in 
lowering to temporal unaligned loads/stores.

This patch casts the vectors to explicitly aligned types prior to the 
load/store to ensure that the require alignment is respected.


Repository:
  rL LLVM

https://reviews.llvm.org/D35996

Files:
  lib/Headers/avx2intrin.h
  lib/Headers/avx512fintrin.h
  lib/Headers/avxintrin.h
  test/CodeGen/x86-nontemporal.c

Index: test/CodeGen/x86-nontemporal.c
===
--- test/CodeGen/x86-nontemporal.c
+++ test/CodeGen/x86-nontemporal.c
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -target-feature +avx -target-feature +avx2 -target-feature +avx512f -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -target-feature +avx -target-feature +avx2 -target-feature +avx512f -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK
 
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -target-feature +avx -target-feature +avx2 -target-feature +avx512f -emit-llvm -o - -Wall -Werror -fmax-type-align=16 | FileCheck %s --check-prefix=CHECK16
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -target-feature +avx -target-feature +avx2 -target-feature +avx512f -fno-signed-char -emit-llvm -o - -Wall -Werror -fmax-type-align=16 | FileCheck %s --check-prefix=CHECK16
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -target-feature +avx -target-feature +avx2 -target-feature +avx512f -emit-llvm -o - -Wall -Werror -fmax-type-align=16 | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -target-feature +avx -target-feature +avx2 -target-feature +avx512f -fno-signed-char -emit-llvm -o - -Wall -Werror -fmax-type-align=16 | FileCheck %s --check-prefix=CHECK
 
 #include 
 
-// FIXME: (PR33830) Tests showing failure to correctly align non-temporal load/stores on darwin targets where fmax-type-align is set to 16.
+// (PR33830) Tests ensure the correct alignment of non-temporal load/stores on darwin targets where fmax-type-align is set to 16.
 
 //
 // 128-bit vectors
@@ -43,36 +43,24 @@
 void test_mm256_stream_pd(double* A, __m256d B) {
   // CHECK-LABEL: test_mm256_stream_pd
   // CHECK: store <4 x double> %{{.*}}, <4 x double>* %{{.*}}, align 32, !nontemporal
-
-  // CHECK16-LABEL: test_mm256_stream_pd
-  // CHECK16: store <4 x double> %{{.*}}, <4 x double>* %{{.*}}, align 16, !nontemporal
   _mm256_stream_pd(A, B);
 }
 
 void test_mm256_stream_ps(float* A, __m256 B) {
   // CHECK-LABEL: test_mm256_stream_ps
   // CHECK: store <8 x float> %{{.*}}, <8 x float>* %{{.*}}, align 32, !nontemporal
-
-  // CHECK16-LABEL: test_mm256_stream_ps
-  // CHECK16: store <8 x float> %{{.*}}, <8 x float>* %{{.*}}, align 16, !nontemporal
   _mm256_stream_ps(A, B);
 }
 
 void test_mm256_stream_si256(__m256i* A, __m256i B) {
   // CHECK-LABEL: test_mm256_stream_si256
   // CHECK: store <4 x i64> %{{.*}}, <4 x i64>* %{{.*}}, align 32, !nontemporal
-
-  // CHECK16-LABEL: test_mm256_stream_si256
-  // CHECK16: store <4 x i64> %{{.*}}, <4 x i64>* %{{.*}}, align 16, !nontemporal
   _mm256_stream_si256(A, B);
 }
 
 __m256i test_mm256_stream_load_si256(__m256i const *A) {
   // CHECK-LABEL: test_mm256_stream_load_si256
   // CHECK: load <4 x i64>, <4 x i64>* %{{.*}}, align 32, !nontemporal
-
-  // CHECK16-LABEL: test_mm256_stream_load_si256
-  // CHECK16: load <4 x i64>, <4 x i64>* %{{.*}}, align 16, !nontemporal
   return _mm256_stream_load_si256(A);
 }
 
@@ -83,35 +71,23 @@
 void test_mm512_stream_pd(double* A, __m512d B) {
   // CHECK-LABEL: test_mm512_stream_pd
   // CHECK: store <8 x double> %{{.*}}, <8 x double>* %{{.*}}, align 64, !nontemporal
-
-  // CHECK16-LABEL: test_mm512_stream_pd
-  // CHECK16: store <8 x double> %{{.*}}, <8 x double>* %{{.*}}, align 16, !nontemporal
   _mm512_stream_pd(A, B);
 }
 
 void test_mm512_stream_ps(float* A, __m512 B) {
   // CHECK-LABEL: test_mm512_stream_ps
   // CHECK: store <16 x float> %{{.*}}, <16 x float>* %{{.*}}, align 64, !nontemporal
-
-  // CHECK16-LABEL: test_mm512_stream_ps
-  // CHECK16: store <16 x float> %{{.*}}, <16 x float>* %{{.*}}, align 16, !nontemporal
   _mm512_stream_ps(A, B);
 }
 
 void test_mm512_stream_si512(__m512i* A, __m512i B) {
   // CHECK-LABEL: test_mm512_stream_si512
   // CHECK: store <8 x i64> %{{.*}}, <8 x i64>* %{{.*}}, align 64, !nontemporal
-
-  // CHECK16-LABEL: test_mm512_stream_si512
-  // CHECK16: store <8 x i64> %{{.*}}, <8 x i64>* 

[PATCH] D16403: Add scope information to CFG for If/While/For/Do/Compound/CXXRangeFor statements

2017-07-28 Thread Maxim Ostapenko via Phabricator via cfe-commits
m.ostapenko updated this revision to Diff 108644.
m.ostapenko added a comment.

Updated some comments. Could someone take a look please?


Repository:
  rL LLVM

https://reviews.llvm.org/D16403

Files:
  include/clang/Analysis/AnalysisContext.h
  include/clang/Analysis/CFG.h
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/Analysis/AnalysisDeclContext.cpp
  lib/Analysis/CFG.cpp
  lib/StaticAnalyzer/Core/AnalysisManager.cpp
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/analyzer-config.c
  test/Analysis/analyzer-config.cpp
  test/Analysis/scopes-cfg-output.cpp

Index: test/Analysis/scopes-cfg-output.cpp
===
--- /dev/null
+++ test/Analysis/scopes-cfg-output.cpp
@@ -0,0 +1,1099 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-scopes=true %s > %t 2>&1
+// RUN: FileCheck --input-file=%t %s
+
+class A {
+public:
+// CHECK:  [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  A() {}
+
+// CHECK:  [B1 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  ~A() {}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   2: 1
+// CHECK-NEXT:   3: return [B1.2];
+// CHECK-NEXT:   4: CFGScopeEnd(ReturnStmt)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+  operator int() const { return 1; }
+};
+
+int getX();
+extern const bool UV;
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: a
+// CHECK-NEXT:   5: [B1.4] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:   6: const A  = a;
+// CHECK-NEXT:   7: A() (CXXConstructExpr, class A)
+// CHECK-NEXT:   8: [B1.7] (BindTemporary)
+// CHECK-NEXT:   9: [B1.8] (ImplicitCastExpr, NoOp, const class A)
+// CHECK-NEXT:  10: [B1.9]
+// CHECK-NEXT:  11: const A  = A();
+// CHECK-NEXT:  12: [B1.11].~A() (Implicit destructor)
+// CHECK-NEXT:  13: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:  14: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+void test_const_ref() {
+  A a;
+  const A& b = a;
+  const A& c = A();
+}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A [2])
+// CHECK-NEXT:   3: A a[2];
+// CHECK-NEXT:   4:  (CXXConstructExpr, class A [0])
+// CHECK-NEXT:   5: A b[0];
+// CHECK-NEXT:   6: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:   7: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void test_array() {
+  A a[2];
+  A b[0];
+}
+
+// CHECK:  [B2 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B1
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   3: A a;
+// CHECK-NEXT:   4: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   5:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   6: A c;
+// CHECK-NEXT:   7:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   8: A d;
+// CHECK-NEXT:   9: [B1.8].~A() (Implicit destructor)
+// CHECK-NEXT:  10: [B1.6].~A() (Implicit destructor)
+// CHECK-NEXT:  11:  (CXXConstructExpr, class A)
+// CHECK-NEXT:  12: A b;
+// CHECK-NEXT:  13: [B1.12].~A() (Implicit destructor)
+// CHECK-NEXT:  14: [B1.3].~A() (Implicit destructor)
+// CHECK-NEXT:  15: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:  16: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:   Preds (1): B2
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+void test_scope() {
+  A a;
+  { A c;
+A d;
+  }
+  A b;
+}
+
+// CHECK:  [B4 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B3
+// CHECK:  [B1]
+// CHECK-NEXT:   1:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   2: A c;
+// CHECK-NEXT:   3: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   5: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   6: CFGScopeEnd(CompoundStmt)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B2]
+// CHECK-NEXT:   1: CFGScopeBegin(IfStmt)
+// CHECK-NEXT:   2: return;
+// CHECK-NEXT:   3: [B3.5].~A() (Implicit destructor)
+// CHECK-NEXT:   4: [B3.3].~A() (Implicit destructor)
+// CHECK-NEXT:   5: CFGScopeEnd(ReturnStmt)
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B0
+// CHECK:  [B3]
+// CHECK-NEXT:   1: CFGScopeBegin(CompoundStmt)
+// CHECK-NEXT:   2:  

RE: [PATCH] D34158: For standards compatibility, preinclude if the file is available

2017-07-28 Thread Blower, Melanie via cfe-commits
 

fedor.sergeev added a comment.

Hmm... I tried this patch and now the following worries me:

- it passes -finclude-if-exists stdc-predef.h on all platforms (say, including 
my Solaris platform that has no system stdc-predef.h)
- it searches all the paths, not just "system include" ones

That essentially disallows user to have stdc-predef.h include in my own 
project, since there is a chance that this user header will be accidentally 
included by this hidden machinery.

>> Yes, I recognize this problem. However, I don't know an acceptable way to 
>> solve it. Does anyone have a recommendation? I had tried putting angle 
>> brackets around the file name string to imply a system-only search but that 
>> didn't work:  I guess the >angle brackets are taken to be part of the file 
>> name.  I believe it's intentional that has_include doesn't recognize the 
>> angle, I see test cases that have __has_include( "<...") Quoting from the 
>> patch:
// For standards compliance, clang will preinclude 
// -ffreestanding suppresses this behavior.
CmdArgs.push_back("-finclude-if-exists");
CmdArgs.push_back(""); // This doesn't work to restrict the 
search to system includes
  } 

>I could change the argument scanner for __has_include to recognize the angle 
>brackets -- would that be acceptable?  Alternatively, I could change the flag 
>to be "finclude-if-exists" into "fsystem-include-if-exists". Then I could 
>create a new preprocessing keyword(is that the right term?) 
>__has_system_include and use that instead of __has_include.  

>I tried this test case with -c -E:
>cat test1.c
>#if __has_include( "stdio.h" )
>#error it has stdio without angle  // This is printed
>#else
>#error it does not have stdio without angle
>#endif

>#if __has_include( "" )
>#error it has stdio with angle
>#else
>#error it does not have stdio with angle // This is printed
>#endif

  ] cat stdc-predef.h
  #error I was not expecting to see that
  ] bin/clang hello-world.c
  In file included from :2:
  ./stdc-predef.h:1:2: error: I was not expecting to see this!
  #error I was not expecting to see this!
   ^
  1 error generated.
  ]


Repository:
  rL LLVM

https://reviews.llvm.org/D34158



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


r309383 - Strip trailing whitespace. NFCI.

2017-07-28 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Fri Jul 28 07:01:51 2017
New Revision: 309383

URL: http://llvm.org/viewvc/llvm-project?rev=309383=rev
Log:
Strip trailing whitespace. NFCI.

Modified:
cfe/trunk/lib/Headers/avx512fintrin.h

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=309383=309382=309383=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Fri Jul 28 07:01:51 2017
@@ -4289,7 +4289,7 @@ static __inline__ __m512i __DEFAULT_FN_A
 _mm512_maskz_cvtps_epu32 ( __mmask16 __U, __m512 __A)
 {
   return (__m512i) __builtin_ia32_cvtps2udq512_mask ((__v16sf) __A,
-  (__v16si) 
+  (__v16si)
   _mm512_setzero_si512 (),
   (__mmask16) __U ,
   _MM_FROUND_CUR_DIRECTION);
@@ -9217,39 +9217,39 @@ _mm512_maskz_moveldup_ps (__mmask16 __U,
 static __inline__ __m128 __DEFAULT_FN_ATTRS
 _mm_mask_move_ss (__m128 __W, __mmask8 __U, __m128 __A, __m128 __B)
 {
-  __m128 res = __A; 
+  __m128 res = __A;
   res[0] = (__U & 1) ? __B[0] : __W[0];
-  return res; 
+  return res;
 }
 
 static __inline__ __m128 __DEFAULT_FN_ATTRS
 _mm_maskz_move_ss (__mmask8 __U, __m128 __A, __m128 __B)
 {
-  __m128 res = __A; 
-  res[0] = (__U & 1) ? __B[0] : 0; 
-  return res; 
+  __m128 res = __A;
+  res[0] = (__U & 1) ? __B[0] : 0;
+  return res;
 }
 
 static __inline__ __m128d __DEFAULT_FN_ATTRS
 _mm_mask_move_sd (__m128d __W, __mmask8 __U, __m128d __A, __m128d __B)
 {
-  __m128d res = __A; 
+  __m128d res = __A;
   res[0] = (__U & 1) ? __B[0] : __W[0];
-  return res; 
+  return res;
 }
 
 static __inline__ __m128d __DEFAULT_FN_ATTRS
 _mm_maskz_move_sd (__mmask8 __U, __m128d __A, __m128d __B)
 {
-  __m128d res = __A; 
-  res[0] = (__U & 1) ? __B[0] : 0; 
-  return res; 
+  __m128d res = __A;
+  res[0] = (__U & 1) ? __B[0] : 0;
+  return res;
 }
 
 static __inline__ void __DEFAULT_FN_ATTRS
 _mm_mask_store_ss (float * __W, __mmask8 __U, __m128 __A)
 {
-  __builtin_ia32_storess128_mask ((__v16sf *)__W, 
+  __builtin_ia32_storess128_mask ((__v16sf *)__W,
 (__v16sf) _mm512_castps128_ps512(__A),
 (__mmask16) __U & (__mmask16)1);
 }
@@ -9257,7 +9257,7 @@ _mm_mask_store_ss (float * __W, __mmask8
 static __inline__ void __DEFAULT_FN_ATTRS
 _mm_mask_store_sd (double * __W, __mmask8 __U, __m128d __A)
 {
-  __builtin_ia32_storesd128_mask ((__v8df *)__W, 
+  __builtin_ia32_storesd128_mask ((__v8df *)__W,
 (__v8df) _mm512_castpd128_pd512(__A),
 (__mmask8) __U & 1);
 }
@@ -9606,7 +9606,7 @@ _mm_mask_cvtsd_ss (__m128 __W, __mmask8
 {
   return __builtin_ia32_cvtsd2ss_round_mask ((__v4sf)(__A),
  (__v2df)(__B),
- (__v4sf)(__W), 
+ (__v4sf)(__W),
  (__mmask8)(__U), 
_MM_FROUND_CUR_DIRECTION);
 }
 
@@ -9615,7 +9615,7 @@ _mm_maskz_cvtsd_ss (__mmask8 __U, __m128
 {
   return __builtin_ia32_cvtsd2ss_round_mask ((__v4sf)(__A),
  (__v2df)(__B),
- (__v4sf)_mm_setzero_ps(), 
+ (__v4sf)_mm_setzero_ps(),
  (__mmask8)(__U), 
_MM_FROUND_CUR_DIRECTION);
 }
 
@@ -9680,7 +9680,7 @@ _mm_mask_cvtss_sd (__m128d __W, __mmask8
   return __builtin_ia32_cvtss2sd_round_mask((__v2df)(__A),
   (__v4sf)(__B),
   (__v2df)(__W),
-  (__mmask8)(__U), 
_MM_FROUND_CUR_DIRECTION); 
+  (__mmask8)(__U), 
_MM_FROUND_CUR_DIRECTION);
 }
 
 static __inline__ __m128d __DEFAULT_FN_ATTRS
@@ -9688,8 +9688,8 @@ _mm_maskz_cvtss_sd (__mmask8 __U, __m128
 {
   return __builtin_ia32_cvtss2sd_round_mask((__v2df)(__A),
   (__v4sf)(__B),
-  (__v2df)_mm_setzero_pd(), 
-  (__mmask8)(__U), 
_MM_FROUND_CUR_DIRECTION); 
+  (__v2df)_mm_setzero_pd(),
+  (__mmask8)(__U), 
_MM_FROUND_CUR_DIRECTION);
 }
 
 static __inline__ __m128d __DEFAULT_FN_ATTRS
@@ -9935,7 +9935,7 @@ static __inline__ double __DEFAULT_FN_AT
 }
 
 // Vec512 - Vector with size 512.
-// Vec512Neutral - All vector elements set to the identity element. 
+// Vec512Neutral - All vector elements set to the identity element.
 // Identity element: {+,0},{*,1},{&,0x},{|,0}
 // Operator - Can be one of following: +,*,&,|
 // Mask - Intrinsic Mask
@@ -9965,19 +9965,19 @@ 

r309382 - [X86] Add tests showing inability of vector non-temporal load/store intrinsic to force pointer alignment (PR33830)

2017-07-28 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Fri Jul 28 06:47:02 2017
New Revision: 309382

URL: http://llvm.org/viewvc/llvm-project?rev=309382=rev
Log:
[X86] Add tests showing inability of vector non-temporal load/store intrinsic 
to force pointer alignment (PR33830)

Clang specifies a max type alignment of 16 bytes on darwin targets, meaning 
that the builtin nontemporal stores don't correctly align the loads/stores to 
32 or 64 bytes when required, resulting in lowering to temporal unaligned 
loads/stores.

Added:
cfe/trunk/test/CodeGen/x86-nontemporal.c

Added: cfe/trunk/test/CodeGen/x86-nontemporal.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86-nontemporal.c?rev=309382=auto
==
--- cfe/trunk/test/CodeGen/x86-nontemporal.c (added)
+++ cfe/trunk/test/CodeGen/x86-nontemporal.c Fri Jul 28 06:47:02 2017
@@ -0,0 +1,117 @@
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +sse4.1 -target-feature +avx -target-feature +avx2 
-target-feature +avx512f -emit-llvm -o - -Wall -Werror | FileCheck %s 
--check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +sse4.1 -target-feature +avx -target-feature +avx2 
-target-feature +avx512f -fno-signed-char -emit-llvm -o - -Wall -Werror | 
FileCheck %s --check-prefix=CHECK
+
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +sse4.1 -target-feature +avx -target-feature +avx2 
-target-feature +avx512f -emit-llvm -o - -Wall -Werror -fmax-type-align=16 | 
FileCheck %s --check-prefix=CHECK16
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +sse4.1 -target-feature +avx -target-feature +avx2 
-target-feature +avx512f -fno-signed-char -emit-llvm -o - -Wall -Werror 
-fmax-type-align=16 | FileCheck %s --check-prefix=CHECK16
+
+#include 
+
+// FIXME: (PR33830) Tests showing failure to correctly align non-temporal 
load/stores on darwin targets where fmax-type-align is set to 16.
+
+//
+// 128-bit vectors
+//
+
+void test_mm_stream_pd(double* A, __m128d B) {
+  // CHECK-LABEL: test_mm_stream_pd
+  // CHECK: store <2 x double> %{{.*}}, <2 x double>* %{{.*}}, align 16, 
!nontemporal
+  _mm_stream_pd(A, B);
+}
+
+void test_mm_stream_ps(float* A, __m128 B) {
+  // CHECK16-LABEL: test_mm_stream_ps
+  // CHECK16: store <4 x float> %{{.*}}, <4 x float>* %{{.*}}, align 16, 
!nontemporal
+  _mm_stream_ps(A, B);
+}
+
+void test_mm_stream_si128(__m128i* A, __m128i B) {
+  // CHECK-LABEL: test_mm_stream_si128
+  // CHECK: store <2 x i64> %{{.*}}, <2 x i64>* %{{.*}}, align 16, !nontemporal
+  _mm_stream_si128(A, B);
+}
+
+__m128i test_mm_stream_load_si128(__m128i const *A) {
+  // CHECK-LABEL: test_mm_stream_load_si128
+  // CHECK: load <2 x i64>, <2 x i64>* %{{.*}}, align 16, !nontemporal
+  return _mm_stream_load_si128(A);
+}
+
+//
+// 256-bit vectors
+//
+
+void test_mm256_stream_pd(double* A, __m256d B) {
+  // CHECK-LABEL: test_mm256_stream_pd
+  // CHECK: store <4 x double> %{{.*}}, <4 x double>* %{{.*}}, align 32, 
!nontemporal
+
+  // CHECK16-LABEL: test_mm256_stream_pd
+  // CHECK16: store <4 x double> %{{.*}}, <4 x double>* %{{.*}}, align 16, 
!nontemporal
+  _mm256_stream_pd(A, B);
+}
+
+void test_mm256_stream_ps(float* A, __m256 B) {
+  // CHECK-LABEL: test_mm256_stream_ps
+  // CHECK: store <8 x float> %{{.*}}, <8 x float>* %{{.*}}, align 32, 
!nontemporal
+
+  // CHECK16-LABEL: test_mm256_stream_ps
+  // CHECK16: store <8 x float> %{{.*}}, <8 x float>* %{{.*}}, align 16, 
!nontemporal
+  _mm256_stream_ps(A, B);
+}
+
+void test_mm256_stream_si256(__m256i* A, __m256i B) {
+  // CHECK-LABEL: test_mm256_stream_si256
+  // CHECK: store <4 x i64> %{{.*}}, <4 x i64>* %{{.*}}, align 32, !nontemporal
+
+  // CHECK16-LABEL: test_mm256_stream_si256
+  // CHECK16: store <4 x i64> %{{.*}}, <4 x i64>* %{{.*}}, align 16, 
!nontemporal
+  _mm256_stream_si256(A, B);
+}
+
+__m256i test_mm256_stream_load_si256(__m256i const *A) {
+  // CHECK-LABEL: test_mm256_stream_load_si256
+  // CHECK: load <4 x i64>, <4 x i64>* %{{.*}}, align 32, !nontemporal
+
+  // CHECK16-LABEL: test_mm256_stream_load_si256
+  // CHECK16: load <4 x i64>, <4 x i64>* %{{.*}}, align 16, !nontemporal
+  return _mm256_stream_load_si256(A);
+}
+
+//
+// 512-bit vectors
+//
+
+void test_mm512_stream_pd(double* A, __m512d B) {
+  // CHECK-LABEL: test_mm512_stream_pd
+  // CHECK: store <8 x double> %{{.*}}, <8 x double>* %{{.*}}, align 64, 
!nontemporal
+
+  // CHECK16-LABEL: test_mm512_stream_pd
+  // CHECK16: store <8 x double> %{{.*}}, <8 x double>* %{{.*}}, align 16, 
!nontemporal
+  _mm512_stream_pd(A, B);
+}
+
+void test_mm512_stream_ps(float* A, __m512 B) {
+  // CHECK-LABEL: test_mm512_stream_ps
+  // CHECK: store <16 x float> %{{.*}}, <16 x float>* %{{.*}}, align 64, 
!nontemporal
+
+  // CHECK16-LABEL: test_mm512_stream_ps
+  // CHECK16: store <16 x float> %{{.*}}, <16 x float>* %{{.*}}, align 16, 

[PATCH] D35925: [Coverage] Precise region termination with deferred regions

2017-07-28 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

This is awesome!

I noticed in the sample output that llvm-cov is now forced to print some new 
region markers because the terminator introduces a new region on the same line, 
e.g.

  |// CHECK-LABEL: _Z10while_loopv:
 88|  1|void while_loop() {
 89|  1|  if (false)
 90|  1|return; // CHECK: [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
^0^1  // Previously, llvm-cov didn't show region 
markers for this line
 91|  1|

Do you think this can be avoided? Should llvm-cov even try to avoid emitting 
the region markers? It seems to me that this situation affects just the 
command-line output of llvm-cov, and region highlighting in HTML won't be 
impacted by this.


https://reviews.llvm.org/D35925



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


[clang-tools-extra] r309380 - [clang-tidy] Expand readability-redundant-function-ptr-dereference test

2017-07-28 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Jul 28 05:46:08 2017
New Revision: 309380

URL: http://llvm.org/viewvc/llvm-project?rev=309380=rev
Log:
[clang-tidy] Expand readability-redundant-function-ptr-dereference test

Modified:

clang-tools-extra/trunk/test/clang-tidy/readability-redundant-function-ptr-dereference.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-function-ptr-dereference.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-redundant-function-ptr-dereference.cpp?rev=309380=309379=309380=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-function-ptr-dereference.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-function-ptr-dereference.cpp
 Fri Jul 28 05:46:08 2017
@@ -16,6 +16,27 @@ void positive() {
   // CHECK-FIXES: (*p)(2);
 }
 
+template
+void invoke(const T& fn) {
+  fn(0); // 1
+  (*fn)(0); // 2
+  // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated
+  // CHECK-FIXES: fn(0); // 1
+  // CHECK-FIXES: (fn)(0); // 2
+  // FIXME: Remove unnecessary parentheses.
+}
+
+void f1(int);
+void f2(double);
+void f3(char);
+
+void instantiate() {
+  invoke(f1);
+  invoke(f2);
+  invoke(f3);
+  invoke([](unsigned) {});
+}
+
 void negative() {
   void (*q)(int) = 
 


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


[clang-tools-extra] r309379 - [clang-tidy] readability-redundant-declaration: ignore friends and macros

2017-07-28 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Jul 28 05:46:02 2017
New Revision: 309379

URL: http://llvm.org/viewvc/llvm-project?rev=309379=rev
Log:
[clang-tidy] readability-redundant-declaration: ignore friends and macros

Added:

clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration-ignore-macros.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.h

clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp?rev=309379=309378=309379=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp 
Fri Jul 28 05:46:02 2017
@@ -18,11 +18,16 @@ namespace clang {
 namespace tidy {
 namespace readability {
 
+RedundantDeclarationCheck::RedundantDeclarationCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
+
 void RedundantDeclarationCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  namedDecl(
-  anyOf(varDecl(unless(isDefinition())),
-functionDecl(unless(anyOf(isDefinition(), isDefaulted())
+  namedDecl(anyOf(varDecl(unless(isDefinition())),
+  functionDecl(unless(anyOf(isDefinition(), isDefaulted(),
+hasParent(friendDecl()))
   .bind("Decl"),
   this);
 }
@@ -36,6 +41,13 @@ void RedundantDeclarationCheck::check(co
 return;
   if (Prev->getLocation() == D->getLocation())
 return;
+  if (IgnoreMacros &&
+  (D->getLocation().isMacroID() || Prev->getLocation().isMacroID()))
+return;
+  // Don't complain when the previous declaration is a friend declaration.
+  for (const auto  : Result.Context->getParents(*Prev))
+if (Parent.get())
+  return;
 
   const SourceManager  = *Result.SourceManager;
 

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.h?rev=309379=309378=309379=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.h 
Fri Jul 28 05:46:02 2017
@@ -22,10 +22,12 @@ namespace readability {
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/readability-redundant-declaration.html
 class RedundantDeclarationCheck : public ClangTidyCheck {
 public:
-  RedundantDeclarationCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  RedundantDeclarationCheck(StringRef Name, ClangTidyContext *Context);
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+
+private:
+  const bool IgnoreMacros;
 };
 
 } // namespace readability

Added: 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration-ignore-macros.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration-ignore-macros.cpp?rev=309379=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration-ignore-macros.cpp
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration-ignore-macros.cpp
 Fri Jul 28 05:46:02 2017
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy %s readability-redundant-declaration %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: readability-redundant-declaration.IgnoreMacros, \
+// RUN:   value: 1}]}" \
+// RUN:   -- -std=c++11
+
+extern int Xyz;
+extern int Xyz; // Xyz
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Xyz' declaration 
[readability-redundant-declaration]
+// CHECK-FIXES: {{^}}// Xyz{{$}}
+
+namespace macros {
+#define DECLARE(x) extern int x
+#define DEFINE(x) extern int x; int x = 42
+DECLARE(test);
+DEFINE(test);
+// CHECK-FIXES: {{^}}#define DECLARE(x) extern int x{{$}}
+// CHECK-FIXES: {{^}}#define DEFINE(x) extern int x; int x = 42{{$}}
+// CHECK-FIXES: {{^}}DECLARE(test);{{$}}
+// CHECK-FIXES: {{^}}DEFINE(test);{{$}}
+
+} // namespace macros

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp
URL: 

[clang-tools-extra] r309378 - [clangd] Workaround for a test failure on Windows.

2017-07-28 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Jul 28 05:25:51 2017
New Revision: 309378

URL: http://llvm.org/viewvc/llvm-project?rev=309378=rev
Log:
[clangd] Workaround for a test failure on Windows.

Previous workaround (r308959) didn't account for a case when system drive
letter is not 'C:'.

Modified:
clang-tools-extra/trunk/test/clangd/definitions.test

Modified: clang-tools-extra/trunk/test/clangd/definitions.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/definitions.test?rev=309378=309377=309378=diff
==
--- clang-tools-extra/trunk/test/clangd/definitions.test (original)
+++ clang-tools-extra/trunk/test/clangd/definitions.test Fri Jul 28 05:25:51 
2017
@@ -139,7 +139,7 @@ Content-Length: 148
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":2,"character":9}}}
 # Go to macro.
-# CHECK: {"jsonrpc":"2.0","id":1,"result":[{"uri": 
"file:///{{(C:/)?}}main.cpp", "range": {"start": {"line": 0, "character": 8}, 
"end": {"line": 0, "character": 18}}}]}
+# CHECK: {"jsonrpc":"2.0","id":1,"result":[{"uri": 
"file:///{{([A-Za-z]:/)?}}main.cpp", "range": {"start": {"line": 0, 
"character": 8}, "end": {"line": 0, "character": 18}}}]}
 
 Content-Length: 217
 
@@ -149,7 +149,7 @@ Content-Length: 148
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":1,"character":8}}}
 # Go to macro, re-defined later
-# CHECK: {"jsonrpc":"2.0","id":1,"result":[{"uri": 
"file:///{{(C:/)?}}main.cpp", "range": {"start": {"line": 0, "character": 8}, 
"end": {"line": 0, "character": 13}}}]}
+# CHECK: {"jsonrpc":"2.0","id":1,"result":[{"uri": 
"file:///{{([A-Za-z]:/)?}}main.cpp", "range": {"start": {"line": 0, 
"character": 8}, "end": {"line": 0, "character": 13}}}]}
 
 Content-Length: 148
 


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


[PATCH] D35937: [clang-tidy] Add new readability non-idiomatic static access

2017-07-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: test/clang-tidy/readability-static-accessed-through-instance.cpp:34
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through 
instance  [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  C::x;{{$}}
+}

baloghadamsoftware wrote:
> xazax.hun wrote:
> > baloghadamsoftware wrote:
> > > aaron.ballman wrote:
> > > > This fix-it worries me because it changes the semantics of the code. 
> > > > The function `f()` is no longer called, and so this isn't a valid 
> > > > source transformation.
> > > Maybe the correct fix would be here f(1, 2, 3, 4); C::x;
> > Maybe for now we should just skip this cases. Expr::HasSideEffects might be 
> > a  good candidate to filter these cases. 
> I think including the expression with side effect before the member access 
> (as I suggested) is not more complicated than skipping these cases.
Please ensure you handle the more complex cases then, such as:
```
struct S {
  static int X;
};

void g(int &);
S h();

void f(S s) {
  g(h().X);
  if ([s]() { return s; }().X == 15)
;
}
```


Repository:
  rL LLVM

https://reviews.llvm.org/D35937



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


[PATCH] D34030: Fix the postorder visting of the ClassTemplateSpecializationDecl nodes in the RecursiveASTVisitor.

2017-07-28 Thread Peter Siket via Phabricator via cfe-commits
MontyKutyi updated this revision to Diff 108626.
MontyKutyi added a comment.

I run the clang-format with -style=llvm on the added code parts.


https://reviews.llvm.org/D34030

Files:
  include/clang/AST/RecursiveASTVisitor.h
  unittests/AST/PostOrderASTVisitor.cpp


Index: unittests/AST/PostOrderASTVisitor.cpp
===
--- unittests/AST/PostOrderASTVisitor.cpp
+++ unittests/AST/PostOrderASTVisitor.cpp
@@ -15,6 +15,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
+#include 
 
 using namespace clang;
 
@@ -75,7 +76,32 @@
 }
   };
 
-}
+
+// Serializes the AST. It is not complete! It only serializes the Statement
+// and the Declaration nodes.
+class ASTSerializerVisitor : public RecursiveASTVisitor {
+private:
+  std::vector 
+  const bool visitPostOrder;
+
+public:
+  ASTSerializerVisitor(bool visitPostOrder, std::vector )
+  : visitedNodes(visitedNodes), visitPostOrder(visitPostOrder) {}
+
+  bool shouldTraversePostOrder() const { return visitPostOrder; }
+
+  bool VisitStmt(Stmt *s) {
+visitedNodes.push_back(s);
+return true;
+  }
+
+  bool VisitDecl(Decl *d) {
+visitedNodes.push_back(d);
+return true;
+  }
+};
+
+} // anonymous namespace
 
 TEST(RecursiveASTVisitor, PostOrderTraversal) {
   auto ASTUnit = tooling::buildASTFromCode(
@@ -126,3 +152,30 @@
 ASSERT_EQ(expected[I], Visitor.VisitedNodes[I]);
   }
 }
+
+TEST(RecursiveASTVisitor, PrePostComparisonTest) {
+  auto ASTUnit = tooling::buildASTFromCode("template  class X {};"
+   "template class X;");
+
+  auto TU = ASTUnit->getASTContext().getTranslationUnitDecl();
+
+  std::vector preorderNodeList, postorderNodeList;
+
+  ASTSerializerVisitor PreVisitor(false, preorderNodeList);
+  PreVisitor.TraverseTranslationUnitDecl(TU);
+
+  ASTSerializerVisitor PostVisitor(true, postorderNodeList);
+  PostVisitor.TraverseTranslationUnitDecl(TU);
+
+  // The number of visited nodes must be independent of the ordering mode.
+  ASSERT_EQ(preorderNodeList.size(), postorderNodeList.size());
+
+  std::sort(preorderNodeList.begin(), preorderNodeList.end());
+  std::sort(postorderNodeList.begin(), postorderNodeList.end());
+
+  // Both traversal must visit the same nodes.
+  ASSERT_EQ(std::mismatch(preorderNodeList.begin(), preorderNodeList.end(),
+  postorderNodeList.begin())
+.first,
+preorderNodeList.end());
+}
Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -1802,11 +1802,10 @@
 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));  
\
 if (!getDerived().shouldVisitTemplateInstantiations() &&   
\
 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)  
\
-  /* Returning from here skips traversing the  
\
- declaration context of the *TemplateSpecializationDecl
\
- (embedded in the DEF_TRAVERSE_DECL() macro)   
\
- which contains the instantiated members of the template. */   
\
-  return true; 
\
+  /* Skip traversing the declaration context of the
\
+ *TemplateSpecializationDecl (embedded in the DEF_TRAVERSE_DECL()  
\
+ macro) which contains the instantiated members of the template. */
\
+  ShouldVisitChildren = false; 
\
   })
 
 DEF_TRAVERSE_TMPL_SPEC_DECL(Class)


Index: unittests/AST/PostOrderASTVisitor.cpp
===
--- unittests/AST/PostOrderASTVisitor.cpp
+++ unittests/AST/PostOrderASTVisitor.cpp
@@ -15,6 +15,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
+#include 
 
 using namespace clang;
 
@@ -75,7 +76,32 @@
 }
   };
 
-}
+
+// Serializes the AST. It is not complete! It only serializes the Statement
+// and the Declaration nodes.
+class ASTSerializerVisitor : public RecursiveASTVisitor {
+private:
+  std::vector 
+  const bool visitPostOrder;
+
+public:
+  ASTSerializerVisitor(bool visitPostOrder, std::vector )
+  : visitedNodes(visitedNodes), visitPostOrder(visitPostOrder) {}
+
+  bool shouldTraversePostOrder() const { return visitPostOrder; }
+
+  bool VisitStmt(Stmt *s) {
+visitedNodes.push_back(s);
+return true;
+  }
+
+  bool VisitDecl(Decl *d) {
+visitedNodes.push_back(d);
+return true;
+  }
+};
+
+} // anonymous namespace
 
 TEST(RecursiveASTVisitor, PostOrderTraversal) {
   auto ASTUnit = tooling::buildASTFromCode(
@@ -126,3 +152,30 @@
 ASSERT_EQ(expected[I], 

[PATCH] D27104: Unify and simplify the behavior of the hasDeclaration matcher.

2017-07-28 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 under the precondition that clang-tidy tests still work.


https://reviews.llvm.org/D27104



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


[PATCH] D35986: [clangd] Add ':' to completion trigger characters.

2017-07-28 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

Without it we don't get completion requests from VSCode after
nested name qualifiers (e.g. after 'std::').


https://reviews.llvm.org/D35986

Files:
  clangd/ClangdLSPServer.cpp


Index: clangd/ClangdLSPServer.cpp
===
--- clangd/ClangdLSPServer.cpp
+++ clangd/ClangdLSPServer.cpp
@@ -86,7 +86,7 @@
   "documentRangeFormattingProvider": true,
   "documentOnTypeFormattingProvider": 
{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
   "codeActionProvider": true,
-  "completionProvider": {"resolveProvider": false, 
"triggerCharacters": [".",">"]},
+  "completionProvider": {"resolveProvider": false, 
"triggerCharacters": [".",">",":"]},
   "definitionProvider": true
 }}})");
 }


Index: clangd/ClangdLSPServer.cpp
===
--- clangd/ClangdLSPServer.cpp
+++ clangd/ClangdLSPServer.cpp
@@ -86,7 +86,7 @@
   "documentRangeFormattingProvider": true,
   "documentOnTypeFormattingProvider": {"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
   "codeActionProvider": true,
-  "completionProvider": {"resolveProvider": false, "triggerCharacters": [".",">"]},
+  "completionProvider": {"resolveProvider": false, "triggerCharacters": [".",">",":"]},
   "definitionProvider": true
 }}})");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34873: Fix miscompiled 32bit binaries by mingw

2017-07-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 108620.
yvvan added a comment.

Provide a workaround without regression


https://reviews.llvm.org/D34873

Files:
  lib/AST/ExprConstant.cpp


Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -537,7 +537,7 @@
   /// rules.  For example, the RHS of (0 && foo()) is not evaluated.  We can
   /// evaluate the expression regardless of what the RHS is, but C only allows
   /// certain things in certain situations.
-  struct LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) EvalInfo {
+  struct EvalInfo {
 ASTContext 
 
 /// EvalStatus - Contains information about the evaluation.
@@ -575,7 +575,13 @@
 
 /// The current array initialization index, if we're performing array
 /// initialization.
-uint64_t ArrayInitIndex = -1;
+/// uint64_t value is split into two uint32_t values as a workaround
+/// to deal with mingw 32-bit miscompilation
+uint32_t ArrayInitIndex[2] = {static_cast(-1), 
static_cast(-1)};
+
+uint64_t& GetArrayInitIndex() {
+return reinterpret_cast(ArrayInitIndex[0]);
+}
 
 /// HasActiveDiagnostic - Was the previous diagnostic stored? If so, 
further
 /// notes attached to it will also be stored, otherwise they will not be.
@@ -923,12 +929,12 @@
 
 public:
   ArrayInitLoopIndex(EvalInfo )
-  : Info(Info), OuterIndex(Info.ArrayInitIndex) {
-Info.ArrayInitIndex = 0;
+  : Info(Info), OuterIndex{Info.GetArrayInitIndex()} {
+Info.GetArrayInitIndex() = 0;
   }
-  ~ArrayInitLoopIndex() { Info.ArrayInitIndex = OuterIndex; }
+  ~ArrayInitLoopIndex() { Info.GetArrayInitIndex() = OuterIndex; }
 
-  operator uint64_t&() { return Info.ArrayInitIndex; }
+  operator uint64_t&() { return Info.GetArrayInitIndex(); }
 };
   };
 
@@ -6973,13 +6979,13 @@
   }
 
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
-if (Info.ArrayInitIndex == uint64_t(-1)) {
+if (Info.GetArrayInitIndex() == uint64_t(-1)) {
   // We were asked to evaluate this subexpression independent of the
   // enclosing ArrayInitLoopExpr. We can't do that.
   Info.FFDiag(E);
   return false;
 }
-return Success(Info.ArrayInitIndex, E);
+return Success(Info.GetArrayInitIndex(), E);
   }
 
   // Note, GNU defines __null as an integer, not a pointer.


Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -537,7 +537,7 @@
   /// rules.  For example, the RHS of (0 && foo()) is not evaluated.  We can
   /// evaluate the expression regardless of what the RHS is, but C only allows
   /// certain things in certain situations.
-  struct LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) EvalInfo {
+  struct EvalInfo {
 ASTContext 
 
 /// EvalStatus - Contains information about the evaluation.
@@ -575,7 +575,13 @@
 
 /// The current array initialization index, if we're performing array
 /// initialization.
-uint64_t ArrayInitIndex = -1;
+/// uint64_t value is split into two uint32_t values as a workaround
+/// to deal with mingw 32-bit miscompilation
+uint32_t ArrayInitIndex[2] = {static_cast(-1), static_cast(-1)};
+
+uint64_t& GetArrayInitIndex() {
+return reinterpret_cast(ArrayInitIndex[0]);
+}
 
 /// HasActiveDiagnostic - Was the previous diagnostic stored? If so, further
 /// notes attached to it will also be stored, otherwise they will not be.
@@ -923,12 +929,12 @@
 
 public:
   ArrayInitLoopIndex(EvalInfo )
-  : Info(Info), OuterIndex(Info.ArrayInitIndex) {
-Info.ArrayInitIndex = 0;
+  : Info(Info), OuterIndex{Info.GetArrayInitIndex()} {
+Info.GetArrayInitIndex() = 0;
   }
-  ~ArrayInitLoopIndex() { Info.ArrayInitIndex = OuterIndex; }
+  ~ArrayInitLoopIndex() { Info.GetArrayInitIndex() = OuterIndex; }
 
-  operator uint64_t&() { return Info.ArrayInitIndex; }
+  operator uint64_t&() { return Info.GetArrayInitIndex(); }
 };
   };
 
@@ -6973,13 +6979,13 @@
   }
 
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
-if (Info.ArrayInitIndex == uint64_t(-1)) {
+if (Info.GetArrayInitIndex() == uint64_t(-1)) {
   // We were asked to evaluate this subexpression independent of the
   // enclosing ArrayInitLoopExpr. We can't do that.
   Info.FFDiag(E);
   return false;
 }
-return Success(Info.ArrayInitIndex, E);
+return Success(Info.GetArrayInitIndex(), E);
   }
 
   // Note, GNU defines __null as an integer, not a pointer.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28691: Add OpenCL 2.0 atomic builtin functions as Clang builtin

2017-07-28 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In https://reviews.llvm.org/D28691#820684, @rjmccall wrote:

> In https://reviews.llvm.org/D28691#820641, @b-sumner wrote:
>
> > In https://reviews.llvm.org/D28691#820595, @rjmccall wrote:
> >
> > > In https://reviews.llvm.org/D28691#820541, @b-sumner wrote:
> > >
> > > > There are other languages for heterogeneous compute that have scopes, 
> > > > although not exposed quite as explicitly as OpenCL.  For example AMD's 
> > > > "HC" language.  And any language making use of clang and targeting 
> > > > SPIR-V would likely use these builtins.  I think a more generic prefix 
> > > > is appropriate, and "scoped" tells us exactly when these are needed.
> > >
> > >
> > > But would those languages use the same language design for these scopes 
> > > as OpenCL if they did expose them, as opposed to some more elaborate 
> > > scoping specification?  My objection is not that the concept is 
> > > inherently OpenCL-specific, it's that the presentation in the language 
> > > might be inherently OpenCL-specific, which makes staying in the opencl 
> > > namespace is prudent.
> >
> >
> > Are you envisioning a language far enough from C/C++ that a standard 
> > library or header would not be able to map a scoped atomic operation into a 
> > call to one of these new builtins?  Would we expect more of such languages 
> > than languages that would do such a mapping?
>
>
> If you're using Clang as a frontend for your language, it must be similar 
> enough to C to call a builtin function.  That's not at issue.  The central 
> question here is whether these builtins are meaningfully general outside of 
> OpenCL.  The concept of heterogenous computation is certainly not specific to 
> OpenCL;  however, these builtins are defined in terms of scopes — "work 
> item", "work group", "device", and "all svm devices" — which, it seems to me, 
> are basically only defined by reference to the OpenCL architecture.  A 
> different heterogenous compute environment might reasonably formalize scopes 
> in a completely different way; for example, it might wish to be more explicit 
> about exactly which peers / devices to synchronize with.
>
> SPIR is explicitly defined on top of the OpenCL model.  Users should be able 
> to use OpenCL builtins when targeting it.  That does not make those builtins 
> more general than OpenCL.
>
> John.


The scope concept in OpenCL is fairly generic. And the builtins just take one 
extra argument on top of the existing C11 builtin style. The OpenCL scopes have 
of course specific meaning to the OpenCL model, but there is nothing preventing 
other uses of the scope feature. As far as I understand atomic scope 
implementation in LLVM is fairly generic wrt scope types and it is intended for 
broader functionality than just OpenCL. So I would vote for having this as 
generic as possible in Clang too even though I don't think name prefix 
`__opencl` is preventing from using this feature in other languages unless we 
would disallow the builtins in the other language dialects. Which is not the 
case with the current patch because the builtins are added as `ATOMIC_BUILTIN` 
and not `LANGBUILTIN`. We have for example used C11 builtin in OpenCL already. 
So other cases are possible too.




Comment at: include/clang/Basic/SyncScope.h:25-29
+  SingleThread  = 0,
+  WorkGroup = 1,
+  Device= 2,
+  System= 3,
+  SubGroup  = 4,

t-tye wrote:
> Since the builtins are being named as __opencl then should these also be 
> named as opencl_ since they are the memory scopes for OpenCL using the OpenCL 
> numeric values?
> 
> If another language wants to use memory scopes, would it then add its own 
> langx_* names in a similar way that is done for address spaces where the 
> LangAS enumeration type has values for each distinct language. Each target is 
> then responsible for mapping each language scope to the appropriate target 
> specific scope as is done for address spaces?
> 
> If so then the builtins are really supporting the concept of memory scopes 
> and are not language specific as this enumeration can support multiple 
> languages in the same way as the LangAS enumeration supports multiple 
> languages. If so the builtins would be better named to reflect this as 
> @b-sumner suggested.
We generally prefix the names of OpenCL specific implementations. So perhaps we 
should do some renaming here in case we don't intend this to be generic 
implementation.



Comment at: lib/Sema/SemaChecking.cpp:3160
+Op == AtomicExpr::AO__opencl_atomic_load)
+? 0
+: 1);

Could we merge this and the line after please.


https://reviews.llvm.org/D28691



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


[PATCH] D35948: [CommonOptionsParser] Expose ArgumentsAdjustingCompilationDatabase

2017-07-28 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

This looks fine to me, just an NFC move. @klimek , is this change ok with you?


https://reviews.llvm.org/D35948



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


[PATCH] D27104: Unify and simplify the behavior of the hasDeclaration matcher.

2017-07-28 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a reviewer: bkramer.
klimek added a comment.

Adding Ben as reviewer.


https://reviews.llvm.org/D27104



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


[PATCH] D27104: Unify and simplify the behavior of the hasDeclaration matcher.

2017-07-28 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 108608.
klimek added a comment.

Update to handle hasDeclaration for type alias template decls.


https://reviews.llvm.org/D27104

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/ASTMatchers/ASTMatchersInternal.h
  unittests/AST/ASTImporterTest.cpp
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -230,6 +230,17 @@
 "Expected TemplateSpecializationType to *not* have a getDecl.");
 }
 
+TEST(HasDeclaration, ElaboratedType) {
+  EXPECT_TRUE(matches(
+  "namespace n { template  struct X {}; }"
+  "void f(n::X);",
+  parmVarDecl(hasType(qualType(hasDeclaration(cxxRecordDecl()));
+  EXPECT_TRUE(matches(
+  "namespace n { template  struct X {}; }"
+  "void f(n::X);",
+  parmVarDecl(hasType(elaboratedType(hasDeclaration(cxxRecordDecl()));
+}
+
 TEST(HasDeclaration, HasDeclarationOfTypeWithDecl) {
   EXPECT_TRUE(matches("typedef int X; X a;",
   varDecl(hasName("a"),
@@ -242,14 +253,27 @@
   EXPECT_TRUE(matches("template  class A {}; A a;",
   varDecl(hasType(templateSpecializationType(
 hasDeclaration(namedDecl(hasName("A";
+  EXPECT_TRUE(matches("template  class A {};"
+  "template  class B { A a; };",
+  fieldDecl(hasType(templateSpecializationType(
+hasDeclaration(namedDecl(hasName("A";
+  EXPECT_TRUE(matches("template  class A {}; A a;",
+  varDecl(hasType(templateSpecializationType(
+  hasDeclaration(cxxRecordDecl()));
 }
 
 TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) {
   EXPECT_TRUE(
   matches("int *A = new int();",
   cxxNewExpr(hasDeclaration(functionDecl(parameterCountIs(1));
 }
 
+TEST(HasDeclaration, HasDeclarationOfTypeAlias) {
+  EXPECT_TRUE(matches("template  using C = T; C c;",
+  varDecl(hasType(templateSpecializationType(
+  hasDeclaration(typeAliasTemplateDecl()));
+}
+
 TEST(HasUnqualifiedDesugaredType, DesugarsUsing) {
   EXPECT_TRUE(
   matches("struct A {}; using B = A; B b;",
@@ -2207,8 +2231,7 @@
functionDecl(hasName("bar"));
 }
 
-TEST(SubstTemplateTypeParmType, HasReplacementType)
-{
+TEST(SubstTemplateTypeParmType, HasReplacementType) {
   std::string Fragment = "template"
  "double F(T t);"
  "int i;"
@@ -2224,5 +2247,13 @@
  substTemplateTypeParmType(hasReplacementType(qualType();
 }
 
+TEST(ClassTemplateSpecializationDecl, HasSpecializedTemplate) {
+  auto Matcher = classTemplateSpecializationDecl(
+  hasSpecializedTemplate(classTemplateDecl()));
+  EXPECT_TRUE(
+  matches("template class A {}; typedef A B;", Matcher));
+  EXPECT_TRUE(notMatches("template class A {};", Matcher));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -252,35 +252,19 @@
 
 TEST(ImportExpr, ImportParenListExpr) {
   MatchVerifier Verifier;
-  EXPECT_TRUE(
-testImport(
-  "template class dummy { void f() { dummy X(*this); } };"
-  "typedef dummy declToImport;"
-  "template class dummy;",
-  Lang_CXX, "", Lang_CXX, Verifier,
-  typedefDecl(
-hasType(
-  templateSpecializationType(
-hasDeclaration(
-  classTemplateDecl(
-hasTemplateDecl(
-  cxxRecordDecl(
-hasMethod(
-allOf(
-  hasName("f"),
-  hasBody(
-compoundStmt(
-  has(
-declStmt(
-  hasSingleDecl(
-varDecl(
-  hasInitializer(
-parenListExpr(
-  has(
-unaryOperator(
-  hasOperatorName("*"),
-  hasUnaryOperand(cxxThisExpr())
-  );
+  EXPECT_TRUE(testImport(
+  "template class dummy { void f() { dummy X(*this); } };"
+  "typedef dummy declToImport;"
+  "template class dummy;",
+  Lang_CXX, "", Lang_CXX, Verifier,
+  

[PATCH] D35932: [clang-tidy] Add integer division check

2017-07-28 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs added a comment.

I run the check on LLVM-Clang, and got this one hit:

  
/home/reka/codechecker_dev_env/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp:1000:43:
 warning: integer division; possible precision loss [bugprone-integer-division]
SDValue TWOHW = DAG.getConstantFP(1 << (BW / 2), DL, Op.getValueType());
^

It warns because `getConstantFP()` expects a floating-point value as its first 
argument. Still seems to be a false positive. I might want to add an exception 
for bitshift operators.




Comment at: docs/clang-tidy/checks/bugprone-integer-division.rst:21-24
+  // Do not warn, there are signs of deliberateness.
+  sin(abs(3) / 5);
+  sin(1 + abs(1 + 7 / 2));
+  1 << 2 / 3;

alexfh wrote:
> I'd argue that the presence of `abs` here doesn't add any signal, since the 
> function has overloads both for integer and floating point types.
Well, I meant specifically the above declared function, but you're right, the 
naming was misleading, so I changed that.

To be honest, this check doesn't work for most of the std math functions 
involving template magic. Custom user-defined functions could be mainly 
targeted.


https://reviews.llvm.org/D35932



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


[PATCH] D35932: [clang-tidy] Add integer division check

2017-07-28 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs updated this revision to Diff 108605.
rnkovacs edited the summary of this revision.

https://reviews.llvm.org/D35932

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/IntegerDivisionCheck.cpp
  clang-tidy/bugprone/IntegerDivisionCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-integer-division.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-integer-division.cpp

Index: test/clang-tidy/bugprone-integer-division.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-integer-division.cpp
@@ -0,0 +1,130 @@
+// RUN: %check_clang_tidy %s bugprone-integer-division %t
+
+// Functions expecting a floating-point parameter.
+void floatArg(float x) {}
+void doubleArg(double x) {}
+void longDoubleArg(long double x) {}
+
+// Functions expected to return a floating-point value.
+float singleDiv() {
+  int x = -5;
+  int y = 2;
+  return x/y;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: integer division; possible precision loss [bugprone-integer-division]
+}
+
+double wrongOrder(int x, int y) {
+  return x/y/0.1;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: integer division; possible precision loss [bugprone-integer-division]
+}
+
+long double rightOrder(int x, int y) {
+  return 0.1/x/y; // OK
+}
+
+// Typical mathematical functions.
+float sin(float);
+double acos(double);
+long double tanh(long double);
+
+namespace std {
+  using ::sin;
+}
+
+template 
+void intDivSin(T x) {
+  sin(x);
+}
+
+int intFunc(int);
+
+struct X {
+  int n;
+  void m() {
+sin(n / 3);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: integer division; possible precision loss [bugprone-integer-division]
+  }
+};
+
+void integerDivision() {
+  char a = 2;
+  short b = -5;
+  int c = 9784;
+  enum third { x, y, z=2 };
+  third d = z;
+  char e[] = {'a', 'b', 'c'};
+  char f = *(e + 1 / a);
+  bool g = 1;
+
+  sin(1 + c / (2 + 2));
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: integer division; possible precision loss [bugprone-integer-division]
+  sin(c / (1 + .5));
+  sin((c + .5) / 3);
+
+  sin(intFunc(3) / 5);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: integer division; possible precision loss [bugprone-integer-division]
+  acos(2 / intFunc(7));
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: integer division; possible precision loss [bugprone-integer-division]
+
+  floatArg(1 + 2 / 3);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: integer division; possible precision loss [bugprone-integer-division]
+  sin(1 + 2 / 3);
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: integer division; possible precision loss [bugprone-integer-division]
+  intFunc(sin(1 + 2 / 3));
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: integer division; possible precision loss [bugprone-integer-division]
+
+  floatArg(1 + intFunc(1 + 2 / 3));
+  floatArg(1 + 3 * intFunc(a / b));
+
+  1 << (2 / 3);
+  1 << intFunc(2 / 3);
+
+#define M_SIN sin(a / b);
+  M_SIN
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: integer division; possible precision loss [bugprone-integer-division]
+
+  intDivSin(a / b);
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: integer division; possible precision loss [bugprone-integer-division]
+  intDivSin(c / d);
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: integer division; possible precision loss [bugprone-integer-division]
+  intDivSin(f / g);
+// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: integer division; possible precision loss [bugprone-integer-division]
+
+  floatArg(1 / 3);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: integer division; possible precision loss [bugprone-integer-division]
+  doubleArg(a / b);
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: integer division; possible precision loss [bugprone-integer-division]
+  longDoubleArg(3 / d);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: integer division; possible precision loss [bugprone-integer-division]
+  floatArg(a / b / 0.1);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: integer division; possible precision loss [bugprone-integer-division]
+  doubleArg(1 / 3 / 0.1);
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: integer division; possible precision loss [bugprone-integer-division]
+  longDoubleArg(2 / 3 / 5);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: integer division; possible precision loss [bugprone-integer-division]
+
+  std::sin(2 / 3);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: integer division; possible precision loss [bugprone-integer-division]
+  ::acos(7 / d);
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: integer division; possible precision loss [bugprone-integer-division]
+  tanh(f / g);
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: integer division; possible precision loss [bugprone-integer-division]
+
+  floatArg(0.1 / a / b);
+  doubleArg(0.1 / 3 / 1);
+
+  singleDiv();
+  wrongOrder(a,b);
+  rightOrder(a,b);
+
+  sin(a / b);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: integer division; possible precision 

[PATCH] D35982: [mips] Introducing option -mabs=[legacy/2008]

2017-07-28 Thread Aleksandar Beserminji via Phabricator via cfe-commits
abeserminji created this revision.
Herald added a subscriber: arichardson.

In patch https://reviews.llvm.org/D3274 using abs.[ds] instruction is forced, 
as they should behave in accordance with flags Has2008 and ABS2008. 
Unfortunately for revisions prior mips32r6 and mips64r6, abs.[ds] is not 
generating correct result when working with NaNs. To generate a sequence which 
always produce a correct result but also to allow user more control on how his 
code is compiled, option -mabs is added where user can choose legacy or 2008. 
By default legacy mode is used on revisions prior R6. Mips32r6 and mips64r6 use 
abs2008 mode by default.

This is Clang part of patch. LLVM part can be found here: 
https://reviews.llvm.org/D35983


Repository:
  rL LLVM

https://reviews.llvm.org/D35982

Files:
  Basic/Targets/Mips.cpp
  Basic/Targets/Mips.h
  Driver/ToolChains/Arch/Mips.cpp
  Driver/ToolChains/Arch/Mips.h
  Driver/mips-features.c
  Preprocessor/init.c
  clang/Basic/DiagnosticDriverKinds.td
  clang/Basic/DiagnosticGroups.td
  clang/Driver/Options.td

Index: Preprocessor/init.c
===
--- Preprocessor/init.c
+++ Preprocessor/init.c
@@ -4699,6 +4699,16 @@
 // RUN:   | FileCheck -match-full-lines -check-prefix NOMIPS-NAN2008 %s
 // NOMIPS-NAN2008-NOT:#define __mips_nan2008 1
 //
+// RUN: %clang_cc1 -target-cpu mips32r3 -target-feature +abs2008 \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS-ABS2008 %s
+// MIPS-ABS2008:#define __mips_abs2008 1
+//
+// RUN: %clang_cc1 -target-cpu mips32r3 -target-feature -abs2008 \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix NOMIPS-ABS2008 %s
+// NOMIPS-ABS2008-NOT:#define __mips_abs2008 1
+//
 // RUN: %clang_cc1 -target-feature -fp64 \
 // RUN:   -E -dM -triple=mips-none-none < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-MFP32 %s
Index: Driver/mips-features.c
===
--- Driver/mips-features.c
+++ Driver/mips-features.c
@@ -183,6 +183,18 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NANLEGACY %s
 // CHECK-NANLEGACY: "-target-feature" "-nan2008"
 //
+// -mabs=2008
+// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
+// RUN: -mabs=2008 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABS2008 %s
+// CHECK-ABS2008: "-target-feature" "+abs2008"
+//
+// -mabs=legacy
+// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \
+// RUN: -mabs=legacy 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ABSLEGACY %s
+// CHECK-ABSLEGACY: "-target-feature" "-abs2008"
+//
 // -mcompact-branches=never
 // RUN: %clang -target mips-linux-gnu -march=mips32r6 -### -c %s \
 // RUN: -mcompact-branches=never 2>&1 \
Index: Driver/ToolChains/Arch/Mips.h
===
--- Driver/ToolChains/Arch/Mips.h
+++ Driver/ToolChains/Arch/Mips.h
@@ -24,15 +24,15 @@
 bool isMipsArch(llvm::Triple::ArchType Arch);
 
 namespace mips {
-typedef enum { NanLegacy = 1, Nan2008 = 2 } NanEncoding;
+typedef enum { Legacy = 1, Std2008 = 2 } IEEE754Standard;
 
 enum class FloatABI {
   Invalid,
   Soft,
   Hard,
 };
 
-NanEncoding getSupportedNanEncoding(StringRef );
+IEEE754Standard getIEEE754Standard(StringRef );
 bool hasCompactBranches(StringRef );
 void getMipsCPUAndABI(const llvm::opt::ArgList ,
   const llvm::Triple , StringRef ,
Index: Driver/ToolChains/Arch/Mips.cpp
===
--- Driver/ToolChains/Arch/Mips.cpp
+++ Driver/ToolChains/Arch/Mips.cpp
@@ -244,14 +244,14 @@
   if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) {
 StringRef Val = StringRef(A->getValue());
 if (Val == "2008") {
-  if (mips::getSupportedNanEncoding(CPUName) & mips::Nan2008)
+  if (mips::getIEEE754Standard(CPUName) & mips::Std2008)
 Features.push_back("+nan2008");
   else {
 Features.push_back("-nan2008");
 D.Diag(diag::warn_target_unsupported_nan2008) << CPUName;
   }
 } else if (Val == "legacy") {
-  if (mips::getSupportedNanEncoding(CPUName) & mips::NanLegacy)
+  if (mips::getIEEE754Standard(CPUName) & mips::Legacy)
 Features.push_back("-nan2008");
   else {
 Features.push_back("+nan2008");
@@ -262,6 +262,28 @@
   << A->getOption().getName() << Val;
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_mabs_EQ)) {
+StringRef Val = StringRef(A->getValue());
+if (Val == "2008") {
+  if(mips::getIEEE754Standard(CPUName) & mips::Std2008) {
+Features.push_back("+abs2008");
+  } else {
+Features.push_back("-abs2008");
+D.Diag(diag::warn_target_unsupported_abs2008) << CPUName;
+  }
+} else if (Val == "legacy") {
+  if(mips::getIEEE754Standard(CPUName) & mips::Legacy) {

[PATCH] D35937: [clang-tidy] Add new readability non-idiomatic static access

2017-07-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: test/clang-tidy/readability-static-accessed-through-instance.cpp:34
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through 
instance  [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  C::x;{{$}}
+}

xazax.hun wrote:
> baloghadamsoftware wrote:
> > aaron.ballman wrote:
> > > This fix-it worries me because it changes the semantics of the code. The 
> > > function `f()` is no longer called, and so this isn't a valid source 
> > > transformation.
> > Maybe the correct fix would be here f(1, 2, 3, 4); C::x;
> Maybe for now we should just skip this cases. Expr::HasSideEffects might be a 
>  good candidate to filter these cases. 
I think including the expression with side effect before the member access (as 
I suggested) is not more complicated than skipping these cases.


Repository:
  rL LLVM

https://reviews.llvm.org/D35937



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


[PATCH] D35937: [clang-tidy] Add new readability non-idiomatic static access

2017-07-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

I am not sure whether we should copy with such ugly things as overloaded member 
access operators with side effects, but they can also cause troubles using this 
fix:

  #include 
  
  using std::cout;
  using std::endl;
  
  struct C {
static int N;
int n = 0;
  };
  
  int C::N = 0;
  
  struct Cptr {
C* c;
  
explicit Cptr(C *cc): c(cc) {}
  
C* operator->() {
  ++c->n;
  return c;
}
  };
  
  int main() {
Cptr cp(new C);
cout<<"n: "N = 10;
cout<<"n: "

[PATCH] D35557: clang-format: merge short case labels with trailing comments

2017-07-28 Thread Francois Ferrand via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309370: clang-format: merge short case labels with trailing 
comments (authored by Typz).

Repository:
  rL LLVM

https://reviews.llvm.org/D35557

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

Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
@@ -382,7 +382,9 @@
   return 0;
 unsigned NumStmts = 0;
 unsigned Length = 0;
+bool EndsWithComment = false;
 bool InPPDirective = I[0]->InPPDirective;
+const unsigned Level = I[0]->Level;
 for (; NumStmts < 3; ++NumStmts) {
   if (I + 1 + NumStmts == E)
 break;
@@ -392,9 +394,26 @@
   if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace))
 break;
   if (Line->First->isOneOf(tok::kw_if, tok::kw_for, tok::kw_switch,
-   tok::kw_while, tok::comment) ||
-  Line->Last->is(tok::comment))
+   tok::kw_while) ||
+  EndsWithComment)
 return 0;
+  if (Line->First->is(tok::comment)) {
+if (Level != Line->Level)
+  return 0;
+SmallVectorImpl::const_iterator J = I + 2 + NumStmts;
+for (; J != E; ++J) {
+  Line = *J;
+  if (Line->InPPDirective != InPPDirective)
+break;
+  if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace))
+break;
+  if (Line->First->isNot(tok::comment) || Level != Line->Level)
+return 0;
+}
+break;
+  }
+  if (Line->Last->is(tok::comment))
+EndsWithComment = true;
   Length += I[1 + NumStmts]->Last->TotalLength + 1; // 1 for the space.
 }
 if (NumStmts == 0 || NumStmts == 3 || Length > Limit)
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -907,6 +907,77 @@
"}",
Style);
   verifyFormat("switch (a) {\n"
+   "case 0: return; // comment\n"
+   "case 1: break;  // comment\n"
+   "case 2: return;\n"
+   "// comment\n"
+   "case 3: return;\n"
+   "// comment 1\n"
+   "// comment 2\n"
+   "// comment 3\n"
+   "case 4: break; /* comment */\n"
+   "case 5:\n"
+   "  // comment\n"
+   "  break;\n"
+   "case 6: /* comment */ x = 1; break;\n"
+   "case 7: x = /* comment */ 1; break;\n"
+   "case 8:\n"
+   "  x = 1; /* comment */\n"
+   "  break;\n"
+   "case 9:\n"
+   "  break; // comment line 1\n"
+   " // comment line 2\n"
+   "}",
+   Style);
+  EXPECT_EQ("switch (a) {\n"
+"case 1:\n"
+"  x = 8;\n"
+"  // fall through\n"
+"case 2: x = 8;\n"
+"// comment\n"
+"case 3:\n"
+"  return; /* comment line 1\n"
+"   * comment line 2 */\n"
+"case 4: i = 8;\n"
+"// something else\n"
+"#if FOO\n"
+"case 5: break;\n"
+"#endif\n"
+"}",
+format("switch (a) {\n"
+   "case 1: x = 8;\n"
+   "  // fall through\n"
+   "case 2:\n"
+   "  x = 8;\n"
+   "// comment\n"
+   "case 3:\n"
+   "  return; /* comment line 1\n"
+   "   * comment line 2 */\n"
+   "case 4:\n"
+   "  i = 8;\n"
+   "// something else\n"
+   "#if FOO\n"
+   "case 5: break;\n"
+   "#endif\n"
+   "}",
+   Style));
+  EXPECT_EQ("switch (a) {\n" "case 0:\n"
+"  return; // long long long long long long long long long long long long comment\n"
+"  // line\n" "}",
+format("switch (a) {\n"
+   "case 0: return; // long long long long long long long long long long long long comment line\n"
+   "}",
+   Style));
+  EXPECT_EQ("switch (a) {\n"
+"case 0:\n"
+"  return; /* long long long long long long long long long long long long comment\n"
+" line */\n"
+"}",
+format("switch (a) {\n"
+   "case 0: return; /* long long long long long long long long long long long long comment line */\n"
+   "}",
+

[PATCH] D35483: clang-format: fix block OpeningLineIndex around preprocessor

2017-07-28 Thread Francois Ferrand via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309369: clang-format: fix block OpeningLineIndex around 
preprocessor (authored by Typz).

Changed prior to commit:
  https://reviews.llvm.org/D35483?vs=107843=108598#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35483

Files:
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.h
  cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp

Index: cfe/trunk/lib/Format/UnwrappedLineParser.h
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.h
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h
@@ -160,6 +160,11 @@
 
   bool isOnNewLine(const FormatToken );
 
+  // Compute hash of the current preprocessor branch.
+  // This is used to identify the different branches, and thus track if block
+  // open and close in the same branch.
+  size_t computePPHash() const;
+
   // FIXME: We are constantly running into bugs where Line.Level is incorrectly
   // subtracted from beyond 0. Introduce a method to subtract from Line.Level
   // and use that everywhere in the Parser.
@@ -178,7 +183,7 @@
 
   // Preprocessor directives are parsed out-of-order from other unwrapped lines.
   // Thus, we need to keep a list of preprocessor directives to be reported
-  // after an unwarpped line that has been started was finished.
+  // after an unwrapped line that has been started was finished.
   SmallVector PreprocessorDirectives;
 
   // New unwrapped lines are added via CurrentLines.
@@ -211,8 +216,14 @@
 PP_Unreachable  // #if 0 or a conditional preprocessor block inside #if 0
   };
 
+  struct PPBranch {
+PPBranch(PPBranchKind Kind, size_t Line) : Kind(Kind), Line(Line) {}
+PPBranchKind Kind;
+size_t Line;
+  };
+
   // Keeps a stack of currently active preprocessor branching directives.
-  SmallVector PPStack;
+  SmallVector PPStack;
 
   // The \c UnwrappedLineParser re-parses the code for each combination
   // of preprocessor branches that can be taken.
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -452,23 +452,43 @@
   FormatTok = Tokens->setPosition(StoredPosition);
 }
 
+template 
+static inline void hash_combine(std::size_t , const T ) {
+  std::hash hasher;
+  seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
+}
+
+size_t UnwrappedLineParser::computePPHash() const {
+  size_t h = 0;
+  for (const auto  : PPStack) {
+hash_combine(h, size_t(i.Kind));
+hash_combine(h, i.Line);
+  }
+  return h;
+}
+
 void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
  bool MunchSemi) {
   assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) &&
  "'{' or macro block token expected");
   const bool MacroBlock = FormatTok->is(TT_MacroBlockBegin);
   FormatTok->BlockKind = BK_Block;
 
+  size_t PPStartHash = computePPHash();
+
   unsigned InitialLevel = Line->Level;
   nextToken(/*LevelDifference=*/AddLevel ? 1 : 0);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
 
+  size_t NbPreprocessorDirectives =
+  CurrentLines ==  ? PreprocessorDirectives.size() : 0;
   addUnwrappedLine();
-  size_t OpeningLineIndex = CurrentLines->empty()
-? (UnwrappedLine::kInvalidIndex)
-: (CurrentLines->size() - 1);
+  size_t OpeningLineIndex =
+  CurrentLines->empty()
+  ? (UnwrappedLine::kInvalidIndex)
+  : (CurrentLines->size() - 1 - NbPreprocessorDirectives);
 
   ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
   MustBeDeclaration);
@@ -486,6 +506,8 @@
 return;
   }
 
+  size_t PPEndHash = computePPHash();
+
   // Munch the closing brace.
   nextToken(/*LevelDifference=*/AddLevel ? -1 : 0);
 
@@ -495,11 +517,14 @@
   if (MunchSemi && FormatTok->Tok.is(tok::semi))
 nextToken();
   Line->Level = InitialLevel;
-  Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
-  if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
-// Update the opening line to add the forward reference as well
-(*CurrentLines)[OpeningLineIndex].MatchingOpeningBlockLineIndex =
-CurrentLines->size() - 1;
+
+  if (PPStartHash == PPEndHash) {
+Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
+if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
+  // Update the opening line to add the forward reference as well
+  (*CurrentLines)[OpeningLineIndex].MatchingOpeningBlockLineIndex =
+  CurrentLines->size() - 1;
+}
   }
 }
 
@@ -607,10 +632,15 @@
 }
 
 void UnwrappedLineParser::conditionalCompilationCondition(bool Unreachable) {

r309369 - clang-format: fix block OpeningLineIndex around preprocessor

2017-07-28 Thread Francois Ferrand via cfe-commits
Author: typz
Date: Fri Jul 28 00:56:14 2017
New Revision: 309369

URL: http://llvm.org/viewvc/llvm-project?rev=309369=rev
Log:
clang-format: fix block OpeningLineIndex around preprocessor

Summary:
The current code would return an incorrect value when a preprocessor
directive is present immediately after the opening brace: this causes
the nanespace end comment fixer to break in some places, for exemple it
would not add the comment in this case:

  namespace a {
  #define FOO
  }

Fixing the computation is simple enough, but it was breaking a feature,
as it would cause comments to be added also when the namespace
declaration was dependant on conditional compilation.

To fix this, a hash of the current preprocessor stack/branches is
computed at the beginning of parseBlock(), so that we explicitely do not
store the OpeningLineIndex when the beginning and end of the block are
not in the same preprocessor conditions.

Tthe hash is computed based on the line, but this could propbably be
improved by using the actual condition, so that clang-format would be
able to match multiple identical #ifdef blocks.

Reviewers: krasimir, djasper

Reviewed By: krasimir

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=309369=309368=309369=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Jul 28 00:56:14 2017
@@ -452,6 +452,21 @@ void UnwrappedLineParser::calculateBrace
   FormatTok = Tokens->setPosition(StoredPosition);
 }
 
+template 
+static inline void hash_combine(std::size_t , const T ) {
+  std::hash hasher;
+  seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
+}
+
+size_t UnwrappedLineParser::computePPHash() const {
+  size_t h = 0;
+  for (const auto  : PPStack) {
+hash_combine(h, size_t(i.Kind));
+hash_combine(h, i.Line);
+  }
+  return h;
+}
+
 void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
  bool MunchSemi) {
   assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) &&
@@ -459,16 +474,21 @@ void UnwrappedLineParser::parseBlock(boo
   const bool MacroBlock = FormatTok->is(TT_MacroBlockBegin);
   FormatTok->BlockKind = BK_Block;
 
+  size_t PPStartHash = computePPHash();
+
   unsigned InitialLevel = Line->Level;
   nextToken(/*LevelDifference=*/AddLevel ? 1 : 0);
 
   if (MacroBlock && FormatTok->is(tok::l_paren))
 parseParens();
 
+  size_t NbPreprocessorDirectives =
+  CurrentLines ==  ? PreprocessorDirectives.size() : 0;
   addUnwrappedLine();
-  size_t OpeningLineIndex = CurrentLines->empty()
-? (UnwrappedLine::kInvalidIndex)
-: (CurrentLines->size() - 1);
+  size_t OpeningLineIndex =
+  CurrentLines->empty()
+  ? (UnwrappedLine::kInvalidIndex)
+  : (CurrentLines->size() - 1 - NbPreprocessorDirectives);
 
   ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
   MustBeDeclaration);
@@ -486,6 +506,8 @@ void UnwrappedLineParser::parseBlock(boo
 return;
   }
 
+  size_t PPEndHash = computePPHash();
+
   // Munch the closing brace.
   nextToken(/*LevelDifference=*/AddLevel ? -1 : 0);
 
@@ -495,11 +517,14 @@ void UnwrappedLineParser::parseBlock(boo
   if (MunchSemi && FormatTok->Tok.is(tok::semi))
 nextToken();
   Line->Level = InitialLevel;
-  Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
-  if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
-// Update the opening line to add the forward reference as well
-(*CurrentLines)[OpeningLineIndex].MatchingOpeningBlockLineIndex =
-CurrentLines->size() - 1;
+
+  if (PPStartHash == PPEndHash) {
+Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
+if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) {
+  // Update the opening line to add the forward reference as well
+  (*CurrentLines)[OpeningLineIndex].MatchingOpeningBlockLineIndex =
+  CurrentLines->size() - 1;
+}
   }
 }
 
@@ -607,10 +632,15 @@ void UnwrappedLineParser::parsePPDirecti
 }
 
 void UnwrappedLineParser::conditionalCompilationCondition(bool Unreachable) {
-  if (Unreachable || (!PPStack.empty() && PPStack.back() == PP_Unreachable))
-PPStack.push_back(PP_Unreachable);
+  size_t Line = CurrentLines->size();
+  if (CurrentLines == )
+Line += Lines.size();
+
+  if (Unreachable ||
+  (!PPStack.empty() && PPStack.back().Kind == PP_Unreachable))
+PPStack.push_back({PP_Unreachable, Line});
   else
-   

r309370 - clang-format: merge short case labels with trailing comments

2017-07-28 Thread Francois Ferrand via cfe-commits
Author: typz
Date: Fri Jul 28 00:56:18 2017
New Revision: 309370

URL: http://llvm.org/viewvc/llvm-project?rev=309370=rev
Log:
clang-format: merge short case labels with trailing comments

Summary:
Allow merging short case labels when they actually end with a comment
(like a comment after the ``break``) and when followed by switch-level
comments (e.g. aligned with next case):

  switch(a) {
  case 0: break; // comment at end of case
  case 1: return value;
  // comment related to next case
  // comment related to next case
  case 2:
  }

Reviewers: krasimir, djasper

Reviewed By: krasimir

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=309370=309369=309370=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Fri Jul 28 00:56:18 2017
@@ -382,7 +382,9 @@ private:
   return 0;
 unsigned NumStmts = 0;
 unsigned Length = 0;
+bool EndsWithComment = false;
 bool InPPDirective = I[0]->InPPDirective;
+const unsigned Level = I[0]->Level;
 for (; NumStmts < 3; ++NumStmts) {
   if (I + 1 + NumStmts == E)
 break;
@@ -392,9 +394,26 @@ private:
   if (Line->First->isOneOf(tok::kw_case, tok::kw_default, tok::r_brace))
 break;
   if (Line->First->isOneOf(tok::kw_if, tok::kw_for, tok::kw_switch,
-   tok::kw_while, tok::comment) ||
-  Line->Last->is(tok::comment))
+   tok::kw_while) ||
+  EndsWithComment)
 return 0;
+  if (Line->First->is(tok::comment)) {
+if (Level != Line->Level)
+  return 0;
+SmallVectorImpl::const_iterator J = I + 2 + NumStmts;
+for (; J != E; ++J) {
+  Line = *J;
+  if (Line->InPPDirective != InPPDirective)
+break;
+  if (Line->First->isOneOf(tok::kw_case, tok::kw_default, 
tok::r_brace))
+break;
+  if (Line->First->isNot(tok::comment) || Level != Line->Level)
+return 0;
+}
+break;
+  }
+  if (Line->Last->is(tok::comment))
+EndsWithComment = true;
   Length += I[1 + NumStmts]->Last->TotalLength + 1; // 1 for the space.
 }
 if (NumStmts == 0 || NumStmts == 3 || Length > Limit)

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=309370=309369=309370=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jul 28 00:56:18 2017
@@ -907,6 +907,77 @@ TEST_F(FormatTest, ShortCaseLabels) {
"}",
Style);
   verifyFormat("switch (a) {\n"
+   "case 0: return; // comment\n"
+   "case 1: break;  // comment\n"
+   "case 2: return;\n"
+   "// comment\n"
+   "case 3: return;\n"
+   "// comment 1\n"
+   "// comment 2\n"
+   "// comment 3\n"
+   "case 4: break; /* comment */\n"
+   "case 5:\n"
+   "  // comment\n"
+   "  break;\n"
+   "case 6: /* comment */ x = 1; break;\n"
+   "case 7: x = /* comment */ 1; break;\n"
+   "case 8:\n"
+   "  x = 1; /* comment */\n"
+   "  break;\n"
+   "case 9:\n"
+   "  break; // comment line 1\n"
+   " // comment line 2\n"
+   "}",
+   Style);
+  EXPECT_EQ("switch (a) {\n"
+"case 1:\n"
+"  x = 8;\n"
+"  // fall through\n"
+"case 2: x = 8;\n"
+"// comment\n"
+"case 3:\n"
+"  return; /* comment line 1\n"
+"   * comment line 2 */\n"
+"case 4: i = 8;\n"
+"// something else\n"
+"#if FOO\n"
+"case 5: break;\n"
+"#endif\n"
+"}",
+format("switch (a) {\n"
+   "case 1: x = 8;\n"
+   "  // fall through\n"
+   "case 2:\n"
+   "  x = 8;\n"
+   "// comment\n"
+   "case 3:\n"
+   "  return; /* comment line 1\n"
+   "   * comment line 2 */\n"
+   "case 4:\n"
+   "  i = 8;\n"
+   "// something else\n"
+   "#if FOO\n"
+   "case 5: break;\n"
+   "#endif\n"
+ 

[PATCH] D35937: [clang-tidy] Add new readability non-idiomatic static access

2017-07-28 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: test/clang-tidy/readability-static-accessed-through-instance.cpp:34
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through 
instance  [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  C::x;{{$}}
+}

baloghadamsoftware wrote:
> aaron.ballman wrote:
> > This fix-it worries me because it changes the semantics of the code. The 
> > function `f()` is no longer called, and so this isn't a valid source 
> > transformation.
> Maybe the correct fix would be here f(1, 2, 3, 4); C::x;
Maybe for now we should just skip this cases. Expr::HasSideEffects might be a  
good candidate to filter these cases. 


Repository:
  rL LLVM

https://reviews.llvm.org/D35937



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


[PATCH] D35937: [clang-tidy] Add new readability non-idiomatic static access

2017-07-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: test/clang-tidy/readability-static-accessed-through-instance.cpp:34
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member accessed through 
instance  [readability-static-accessed-through-instance]
+  // CHECK-FIXES: {{^}}  C::x;{{$}}
+}

aaron.ballman wrote:
> This fix-it worries me because it changes the semantics of the code. The 
> function `f()` is no longer called, and so this isn't a valid source 
> transformation.
Maybe the correct fix would be here f(1, 2, 3, 4); C::x;


Repository:
  rL LLVM

https://reviews.llvm.org/D35937



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