[libcxx] r339987 - Merging r339675:

2018-08-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Aug 17 00:19:32 2018
New Revision: 339987

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

r339675 | ldionne | 2018-08-14 15:29:17 +0200 (Tue, 14 Aug 2018) | 15 lines

[libc++] Add missing #include in C11 features tests

Summary:
These #includes are quite important, since otherwise any

#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)

checks are always false, and so we don't actually test for C11 support
in the standard library.

Reviewers: mclow.lists, EricWF

Subscribers: christof, dexonsmith, cfe-commits

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


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

libcxx/branches/release_70/test/libcxx/language.support/has_c11_features.pass.cpp
libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp

libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp

Propchange: libcxx/branches/release_70/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 17 00:19:32 2018
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:339431,339697,339743,339794,339874
+/libcxx/trunk:339431,339675,339697,339743,339794,339874

Modified: 
libcxx/branches/release_70/test/libcxx/language.support/has_c11_features.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/libcxx/language.support/has_c11_features.pass.cpp?rev=339987&r1=339986&r2=339987&view=diff
==
--- 
libcxx/branches/release_70/test/libcxx/language.support/has_c11_features.pass.cpp
 (original)
+++ 
libcxx/branches/release_70/test/libcxx/language.support/has_c11_features.pass.cpp
 Fri Aug 17 00:19:32 2018
@@ -14,6 +14,9 @@
 // _LIBCPP_HAS_C11_FEATURES - which is defined in <__config>
 // They should always be the same
 
+#include <__config>
+#include "test_macros.h"
+
 #ifdef TEST_HAS_C11_FEATURES
 # ifndef _LIBCPP_HAS_C11_FEATURES
 #  error "TEST_HAS_C11_FEATURES is defined, but _LIBCPP_HAS_C11_FEATURES is 
not"

Modified: 
libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp?rev=339987&r1=339986&r2=339987&view=diff
==
--- libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp 
(original)
+++ libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp 
Fri Aug 17 00:19:32 2018
@@ -11,6 +11,8 @@
 
 #include 
 
+#include "test_macros.h"
+
 #ifndef FLT_ROUNDS
 #error FLT_ROUNDS not defined
 #endif

Modified: 
libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp?rev=339987&r1=339986&r2=339987&view=diff
==
--- 
libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
 (original)
+++ 
libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
 Fri Aug 17 00:19:32 2018
@@ -11,6 +11,8 @@
 
 #include 
 
+#include "test_macros.h"
+
 #ifndef FLT_ROUNDS
 #error FLT_ROUNDS not defined
 #endif


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


[libcxx] r339988 - Merging r339702:

2018-08-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Aug 17 00:20:04 2018
New Revision: 339988

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

r339702 | ldionne | 2018-08-14 20:16:56 +0200 (Tue, 14 Aug 2018) | 11 lines

[libc++] Fix incorrect definition of TEST_HAS_C11_FEATURES

Summary:
The macro was not defined in C++11 mode when it should have been, at least
according to how _LIBCPP_HAS_C11_FEATURES is defined.

Reviewers: mclow.lists, EricWF, jfb, dexonsmith

Subscribers: christof, dexonsmith, cfe-commits

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


Modified:
libcxx/branches/release_70/   (props changed)
libcxx/branches/release_70/test/support/test_macros.h

Propchange: libcxx/branches/release_70/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 17 00:20:04 2018
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:339431,339675,339697,339743,339794,339874
+/libcxx/trunk:339431,339675,339697,339702,339743,339794,339874

Modified: libcxx/branches/release_70/test/support/test_macros.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/support/test_macros.h?rev=339988&r1=339987&r2=339988&view=diff
==
--- libcxx/branches/release_70/test/support/test_macros.h (original)
+++ libcxx/branches/release_70/test/support/test_macros.h Fri Aug 17 00:20:04 
2018
@@ -124,7 +124,7 @@
 
 // Sniff out to see if the underling C library has C11 features
 // Note that at this time (July 2018), MacOS X and iOS do NOT.
-#if __ISO_C_VISIBLE >= 2011
+#if __ISO_C_VISIBLE >= 2011 || TEST_STD_VER >= 11
 #  if defined(__FreeBSD__)
 #define TEST_HAS_C11_FEATURES
 #  elif defined(__Fuchsia__)


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


[libcxx] r339989 - Merging r339741:

2018-08-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Aug 17 00:20:30 2018
New Revision: 339989

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

r339741 | ldionne | 2018-08-15 02:16:41 +0200 (Wed, 15 Aug 2018) | 12 lines

[libc++] Detect C11 features on non-Clang compilers

Summary:
The macros were inside `#if defined(_LIBCPP_COMPILER_CLANG)`, which means
we would never detect C11 features on non-Clang compilers. According to
Marshall Clow, this is not the intended behavior.

Reviewers: mclow.lists, EricWF

Subscribers: krytarowski, christof, dexonsmith, cfe-commits

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


Modified:
libcxx/branches/release_70/   (props changed)
libcxx/branches/release_70/include/__config

Propchange: libcxx/branches/release_70/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 17 00:20:30 2018
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:339431,339675,339697,339702,339743,339794,339874
+/libcxx/trunk:339431,339675,339697,339702,339741,339743,339794,339874

Modified: libcxx/branches/release_70/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/include/__config?rev=339989&r1=339988&r2=339989&view=diff
==
--- libcxx/branches/release_70/include/__config (original)
+++ libcxx/branches/release_70/include/__config Fri Aug 17 00:20:30 2018
@@ -328,6 +328,28 @@
 #  define _LIBCPP_NO_CFI
 #endif
 
+#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
+#  if defined(__FreeBSD__)
+#define _LIBCPP_HAS_QUICK_EXIT
+#define _LIBCPP_HAS_C11_FEATURES
+#  elif defined(__Fuchsia__)
+#define _LIBCPP_HAS_QUICK_EXIT
+#define _LIBCPP_HAS_C11_FEATURES
+#  elif defined(__linux__)
+#if !defined(_LIBCPP_HAS_MUSL_LIBC)
+#  if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
+#define _LIBCPP_HAS_QUICK_EXIT
+#  endif
+#  if _LIBCPP_GLIBC_PREREQ(2, 17)
+#define _LIBCPP_HAS_C11_FEATURES
+#  endif
+#else // defined(_LIBCPP_HAS_MUSL_LIBC)
+#  define _LIBCPP_HAS_QUICK_EXIT
+#  define _LIBCPP_HAS_C11_FEATURES
+#endif
+#  endif // __linux__
+#endif
+
 #if defined(_LIBCPP_COMPILER_CLANG)
 
 // _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for
@@ -430,28 +452,6 @@ typedef __char32_t char32_t;
 #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
 #endif
 
-#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
-#  if defined(__FreeBSD__)
-#define _LIBCPP_HAS_QUICK_EXIT
-#define _LIBCPP_HAS_C11_FEATURES
-#  elif defined(__Fuchsia__)
-#define _LIBCPP_HAS_QUICK_EXIT
-#define _LIBCPP_HAS_C11_FEATURES
-#  elif defined(__linux__)
-#if !defined(_LIBCPP_HAS_MUSL_LIBC)
-#  if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
-#define _LIBCPP_HAS_QUICK_EXIT
-#  endif
-#  if _LIBCPP_GLIBC_PREREQ(2, 17)
-#define _LIBCPP_HAS_C11_FEATURES
-#  endif
-#else // defined(_LIBCPP_HAS_MUSL_LIBC)
-#  define _LIBCPP_HAS_QUICK_EXIT
-#  define _LIBCPP_HAS_C11_FEATURES
-#endif
-#  endif // __linux__
-#endif
-
 #if !(__has_feature(cxx_noexcept))
 #define _LIBCPP_HAS_NO_NOEXCEPT
 #endif


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


[libcxx] r339990 - Merging r339742:

2018-08-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Aug 17 00:20:52 2018
New Revision: 339990

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

r339742 | ldionne | 2018-08-15 02:18:01 +0200 (Wed, 15 Aug 2018) | 11 lines

[libc++] Disable failing C11 feature tests for  and 

Summary:
Those tests are breaking the test bots. A Bugzilla has been filed to
make sure those tests are re-enabled: 
https://bugs.llvm.org/show_bug.cgi?id=38572

Reviewers: mclow.lists, EricWF

Subscribers: krytarowski, christof, dexonsmith, cfe-commits

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


Modified:
libcxx/branches/release_70/   (props changed)
libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp

libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp

Propchange: libcxx/branches/release_70/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 17 00:20:52 2018
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:339431,339675,339697,339702,339741,339743,339794,339874
+/libcxx/trunk:339431,339675,339697,339702,339741-339743,339794,339874

Modified: 
libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp?rev=339990&r1=339989&r2=339990&view=diff
==
--- libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp 
(original)
+++ libcxx/branches/release_70/test/std/depr/depr.c.headers/float_h.pass.cpp 
Fri Aug 17 00:20:52 2018
@@ -25,7 +25,7 @@
 #error FLT_RADIX not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
 #ifndef FLT_HAS_SUBNORM
 #error FLT_HAS_SUBNORM not defined
 #endif
@@ -55,7 +55,7 @@
 #error DECIMAL_DIG not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
 #ifndef FLT_DECIMAL_DIG
 #error FLT_DECIMAL_DIG not defined
 #endif
@@ -165,7 +165,7 @@
 #error LDBL_MIN not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
 #ifndef FLT_TRUE_MIN
 #error FLT_TRUE_MIN not defined
 #endif

Modified: 
libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp?rev=339990&r1=339989&r2=339990&view=diff
==
--- 
libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
 (original)
+++ 
libcxx/branches/release_70/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
 Fri Aug 17 00:20:52 2018
@@ -25,7 +25,7 @@
 #error FLT_RADIX not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
 #ifndef FLT_HAS_SUBNORM
 #error FLT_HAS_SUBNORM not defined
 #endif
@@ -55,7 +55,7 @@
 #error DECIMAL_DIG not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
 #ifndef FLT_DECIMAL_DIG
 #error FLT_DECIMAL_DIG not defined
 #endif
@@ -165,7 +165,7 @@
 #error LDBL_MIN not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
 #ifndef FLT_TRUE_MIN
 #error FLT_TRUE_MIN not defined
 #endif


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


[libcxx] r339991 - Merging r339804:

2018-08-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Aug 17 00:21:26 2018
New Revision: 339991

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

r339804 | marshall | 2018-08-15 21:27:53 +0200 (Wed, 15 Aug 2018) | 1 line

Mark the at_exit and at_quick_exit tests as unsupported under C++98 an 03, 
since those calls were introduced in C++11.  They're already guarded by an 
ifdef in the code, so this is a 'belt-and-suspenders' change.


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

libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit.pass.cpp

libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check1.fail.cpp

libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check2.fail.cpp

Propchange: libcxx/branches/release_70/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 17 00:21:26 2018
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:339431,339675,339697,339702,339741-339743,339794,339874
+/libcxx/trunk:339431,339675,339697,339702,339741-339743,339794,339804,339874

Modified: 
libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit.pass.cpp?rev=339991&r1=339990&r2=339991&view=diff
==
--- 
libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit.pass.cpp
 (original)
+++ 
libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit.pass.cpp
 Fri Aug 17 00:21:26 2018
@@ -6,7 +6,7 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 
//===--===//
-//
+// UNSUPPORTED: c++98, c++03
 
 // test quick_exit and at_quick_exit
 

Modified: 
libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check1.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check1.fail.cpp?rev=339991&r1=339990&r2=339991&view=diff
==
--- 
libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check1.fail.cpp
 (original)
+++ 
libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check1.fail.cpp
 Fri Aug 17 00:21:26 2018
@@ -7,6 +7,7 @@
 //
 
//===--===//
 //
+// UNSUPPORTED: c++98, c++03
 
 // test that referencing at_quick_exit when _LIBCPP_HAS_QUICK_EXIT is not 
defined
 // results in a compile error.

Modified: 
libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check2.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check2.fail.cpp?rev=339991&r1=339990&r2=339991&view=diff
==
--- 
libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check2.fail.cpp
 (original)
+++ 
libcxx/branches/release_70/test/std/language.support/support.start.term/quick_exit_check2.fail.cpp
 Fri Aug 17 00:21:26 2018
@@ -6,7 +6,7 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 
//===--===//
-//
+// UNSUPPORTED: c++98, c++03
 
 // test that referencing quick_exit when _LIBCPP_HAS_QUICK_EXIT is not defined
 // results in a compile error.


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


[libcxx] r339992 - Merging r339816:

2018-08-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Aug 17 00:22:08 2018
New Revision: 339992

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

r339816 | marshall | 2018-08-15 23:19:08 +0200 (Wed, 15 Aug 2018) | 1 line

Selectively import timespec_get into namespace std, since some C libraries 
don't have it. Reviewed as https://reviews.llvm.org/D50799


Modified:
libcxx/branches/release_70/   (props changed)
libcxx/branches/release_70/include/__config
libcxx/branches/release_70/include/cstdlib
libcxx/branches/release_70/include/ctime

libcxx/branches/release_70/test/std/language.support/support.runtime/ctime.pass.cpp
libcxx/branches/release_70/test/std/utilities/time/date.time/ctime.pass.cpp
libcxx/branches/release_70/test/support/test_macros.h

Propchange: libcxx/branches/release_70/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 17 00:22:08 2018
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:339431,339675,339697,339702,339741-339743,339794,339804,339874
+/libcxx/trunk:339431,339675,339697,339702,339741-339743,339794,339804,339816,339874

Modified: libcxx/branches/release_70/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/include/__config?rev=339992&r1=339991&r2=339992&view=diff
==
--- libcxx/branches/release_70/include/__config (original)
+++ libcxx/branches/release_70/include/__config Fri Aug 17 00:22:08 2018
@@ -334,6 +334,7 @@
 #define _LIBCPP_HAS_C11_FEATURES
 #  elif defined(__Fuchsia__)
 #define _LIBCPP_HAS_QUICK_EXIT
+#define _LIBCPP_HAS_TIMESPEC_GET
 #define _LIBCPP_HAS_C11_FEATURES
 #  elif defined(__linux__)
 #if !defined(_LIBCPP_HAS_MUSL_LIBC)
@@ -342,9 +343,11 @@
 #  endif
 #  if _LIBCPP_GLIBC_PREREQ(2, 17)
 #define _LIBCPP_HAS_C11_FEATURES
+#define _LIBCPP_HAS_TIMESPEC_GET
 #  endif
 #else // defined(_LIBCPP_HAS_MUSL_LIBC)
 #  define _LIBCPP_HAS_QUICK_EXIT
+#  define _LIBCPP_HAS_TIMESPEC_GET
 #  define _LIBCPP_HAS_C11_FEATURES
 #endif
 #  endif // __linux__

Modified: libcxx/branches/release_70/include/cstdlib
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/include/cstdlib?rev=339992&r1=339991&r2=339992&view=diff
==
--- libcxx/branches/release_70/include/cstdlib (original)
+++ libcxx/branches/release_70/include/cstdlib Fri Aug 17 00:22:08 2018
@@ -151,11 +151,11 @@ using ::mbtowc;
 using ::wctomb;
 using ::mbstowcs;
 using ::wcstombs;
-#ifdef _LIBCPP_HAS_QUICK_EXIT
+#if !defined(_LIBCPP_CXX03_LANG) && defined(_LIBCPP_HAS_QUICK_EXIT)
 using ::at_quick_exit;
 using ::quick_exit;
 #endif
-#ifdef _LIBCPP_HAS_C11_FEATURES
+#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_C11_FEATURES)
 using ::aligned_alloc;
 #endif
 

Modified: libcxx/branches/release_70/include/ctime
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/include/ctime?rev=339992&r1=339991&r2=339992&view=diff
==
--- libcxx/branches/release_70/include/ctime (original)
+++ libcxx/branches/release_70/include/ctime Fri Aug 17 00:22:08 2018
@@ -73,7 +73,7 @@ using ::gmtime;
 using ::localtime;
 #endif
 using ::strftime;
-#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_C11_FEATURES)
+#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
 using ::timespec_get;
 #endif
 

Modified: 
libcxx/branches/release_70/test/std/language.support/support.runtime/ctime.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/std/language.support/support.runtime/ctime.pass.cpp?rev=339992&r1=339991&r2=339992&view=diff
==
--- 
libcxx/branches/release_70/test/std/language.support/support.runtime/ctime.pass.cpp
 (original)
+++ 
libcxx/branches/release_70/test/std/language.support/support.runtime/ctime.pass.cpp
 Fri Aug 17 00:22:08 2018
@@ -45,7 +45,7 @@ int main()
 static_assert((std::is_same::value), 
"");
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), 
"");
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET)
 static_assert((std::is_same::value), "");
 #endif
 #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS

Modified: 
libcxx/branches/release_70/test/std/utilities/time/date.time/ctime.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_70/test/std/utilities/time/date.time/ctime.pass.cpp?rev=339992&r1=339991&r2=339992&view=diff
==

[PATCH] D50852: [clang-tidy] abseil-auto-make-unique

2018-08-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: test/clang-tidy/abseil-auto-make-unique.cpp:73
+  // Different type. No change.
+  std::unique_ptr z = make_unique();
+  std::unique_ptr z2(make_unique());

JonasToth wrote:
> lets consider a 3 level class hierarchy.
> 
> ```
> struct A { virtual void Something(); };
> struct B : A { void Something() override; };
> struct C : B { void Something() override; };
> 
> std::unique_ptr b_ptr = make_unique(), c_ptr = make_unique();
> std::unique_ptr c_ptr2 = make_unique(), b_ptr2 = make_unique();
> ```
> 
> What is the behaviour? I expect that these places break when transformed. To 
> avoid you can check the `VarDecl` `isSingleDecl()` (or similar, i forgot the 
> exact name) and only emit a fixit if it is.
> Doing type transformations for the multi-definitions is tricky.
`isSingleDecl()` is a member of `DeclStmt`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50852



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


[PATCH] D49851: [clang-tidy] run-clang-tidy add synchronisation to the output

2018-08-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In https://reviews.llvm.org/D49851#1202764, @Abpostelnicu wrote:

> Strangely I haven't had those kind of issues but since you propose those 
> modifications I would do one more modification, let's output everything to 
> stdout and not stderr by doing:
>
>   if err:
> sys.stdout.write(str(err) + '\n')
>   


You can make this a new revision, fixing the `byte` and `str` issues would be 
more important now.

The `byte` and `str` thingie is since the whole python3 releases or did it 
change?


Repository:
  rL LLVM

https://reviews.llvm.org/D49851



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


r339995 - [NFC] Some small test updates for Implicit Conversion sanitizer.

2018-08-17 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Fri Aug 17 00:33:25 2018
New Revision: 339995

URL: http://llvm.org/viewvc/llvm-project?rev=339995&view=rev
Log:
[NFC] Some small test updates for Implicit Conversion sanitizer.

Split off from D50250.

Added:
cfe/trunk/test/CodeGen/catch-implicit-integer-conversions-basics.c
cfe/trunk/test/CodeGen/catch-implicit-integer-truncations-basics.c
Modified:
cfe/trunk/test/CodeGen/catch-implicit-integer-truncations.c

Added: cfe/trunk/test/CodeGen/catch-implicit-integer-conversions-basics.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/catch-implicit-integer-conversions-basics.c?rev=339995&view=auto
==
--- cfe/trunk/test/CodeGen/catch-implicit-integer-conversions-basics.c (added)
+++ cfe/trunk/test/CodeGen/catch-implicit-integer-conversions-basics.c Fri Aug 
17 00:33:25 2018
@@ -0,0 +1,131 @@
+// RUN: %clang_cc1 -fsanitize=implicit-integer-truncation 
-fsanitize-recover=implicit-integer-truncation -emit-llvm %s -o - -triple 
x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void 
@__ubsan_handle_implicit_conversion" --check-prefixes=CHECK
+
+// Test plan:
+//  * Two types - int and char
+//  * Two signs - signed and unsigned
+//  * Square that - we have input and output types.
+// Thus, there are total of (2*2)^2 == 16 tests.
+// These are all the possible variations/combinations of casts.
+// However, not all of them should result in the check.
+// So here, we *only* check which should and which should not result in checks.
+
+// CHECK-DAG: @[[LINE_500_TRUNCATION:.*]] = {{.*}}, i32 500, i32 10 }, {{.*}}, 
{{.*}}, i8 0 }
+// CHECK-DAG: @[[LINE_1100_TRUNCATION:.*]] = {{.*}}, i32 1100, i32 10 }, 
{{.*}}, {{.*}}, i8 0 }
+// CHECK-DAG: @[[LINE_1500_TRUNCATION:.*]] = {{.*}}, i32 1500, i32 10 }, 
{{.*}}, {{.*}}, i8 0 }
+// CHECK-DAG: @[[LINE_1600_TRUNCATION:.*]] = {{.*}}, i32 1600, i32 10 }, 
{{.*}}, {{.*}}, i8 0 }
+
+// CHECK-LABEL: @convert_unsigned_int_to_unsigned_int
+unsigned int convert_unsigned_int_to_unsigned_int(unsigned int x) {
+  // CHECK: }
+#line 100
+  return x;
+}
+
+// CHECK-LABEL: @convert_unsigned_char_to_unsigned_char
+unsigned char convert_unsigned_char_to_unsigned_char(unsigned char x) {
+  // CHECK: }
+#line 200
+  return x;
+}
+
+// CHECK-LABEL: @convert_signed_int_to_signed_int
+signed int convert_signed_int_to_signed_int(signed int x) {
+  // CHECK: }
+#line 300
+  return x;
+}
+
+// CHECK-LABEL: @convert_signed_char_to_signed_char
+signed char convert_signed_char_to_signed_char(signed char x) {
+  // CHECK: }
+#line 400
+  return x;
+}
+
+// CHECK-LABEL: @convert_unsigned_int_to_unsigned_char
+unsigned char convert_unsigned_int_to_unsigned_char(unsigned int x) {
+  // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ 
{{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_500_TRUNCATION]] to i8*)
+  // CHECK: }
+#line 500
+  return x;
+}
+
+// CHECK-LABEL: @convert_unsigned_char_to_unsigned_int
+unsigned int convert_unsigned_char_to_unsigned_int(unsigned char x) {
+  // CHECK: }
+#line 600
+  return x;
+}
+
+// CHECK-LABEL: @convert_unsigned_char_to_signed_int
+signed int convert_unsigned_char_to_signed_int(unsigned char x) {
+  // CHECK: }
+#line 700
+  return x;
+}
+
+// CHECK-LABEL: @convert_signed_char_to_signed_int
+signed int convert_signed_char_to_signed_int(signed char x) {
+  // CHECK: }
+#line 800
+  return x;
+}
+
+// CHECK-LABEL: @convert_unsigned_int_to_signed_int
+signed int convert_unsigned_int_to_signed_int(unsigned int x) {
+  // CHECK: }
+#line 900
+  return x;
+}
+
+// CHECK-LABEL: @convert_signed_int_to_unsigned_int
+unsigned int convert_signed_int_to_unsigned_int(signed int x) {
+  // CHECK: }
+#line 1000
+  return x;
+}
+
+// CHECK-LABEL: @convert_signed_int_to_unsigned_char
+unsigned char convert_signed_int_to_unsigned_char(signed int x) {
+  // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ 
{{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1100_TRUNCATION]] to i8*)
+  // CHECK: }
+#line 1100
+  return x;
+}
+
+// CHECK-LABEL: @convert_signed_char_to_unsigned_char
+unsigned char convert_signed_char_to_unsigned_char(signed char x) {
+  // CHECK: }
+#line 1200
+  return x;
+}
+
+// CHECK-LABEL: @convert_unsigned_char_to_signed_char
+signed char convert_unsigned_char_to_signed_char(unsigned char x) {
+  // CHECK: }
+#line 1300
+  return x;
+}
+
+// CHECK-LABEL: @convert_signed_char_to_unsigned_int
+unsigned int convert_signed_char_to_unsigned_int(signed char x) {
+  // CHECK: }
+#line 1400
+  return x;
+}
+
+// CHECK-LABEL: @convert_unsigned_int_to_signed_char
+signed char convert_unsigned_int_to_signed_char(unsigned int x) {
+  // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ 
{{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_1500_TRUNCATION]] to i8*)
+  // CHECK: }
+#line 1500
+  return x;
+}
+
+// CHECK-LABEL: @convert_signed_int_to_signed_char
+signed char convert_signed_int_to_signed_cha

[PATCH] D50542: [clang-tidy] Add abseil-no-internal-deps check

2018-08-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/abseil/NoInternalDepsCheck.cpp:21
+bool IsInAbseilFile(const SourceManager& manager, SourceLocation loc){
+  if (loc.isInvalid()) {
+return false;

You can elide the braces for single stmt ifs



Comment at: clang-tidy/abseil/NoInternalDepsCheck.cpp:24
+  }
+  auto FileEntry =
+  manager.getFileEntryForID(manager.getFileID(loc));

Please dont use `auto` here as the typ is not clear



Comment at: clang-tidy/abseil/NoInternalDepsCheck.cpp:26
+  manager.getFileEntryForID(manager.getFileID(loc));
+  if (!FileEntry) {
+return false;

ellide braces



Comment at: clang-tidy/abseil/NoInternalDepsCheck.cpp:29
+  }
+  auto Filename = FileEntry->getName();
+  llvm::Regex RE("absl/(base|container|debugging|memory|meta|numeric|strings|"

no `auto` plz



Comment at: clang-tidy/abseil/NoInternalDepsCheck.cpp:32
+  "synchronization|types|utiliy)");
+  return (RE.match(Filename));
+}

Are the parens necessary? I think `match` does return a `bool`, then you can 
just return it without the braces. If not, please make it a boolean with an 
expression like `match() > 0` or so.


https://reviews.llvm.org/D50542



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


[PATCH] D50883: [clang-tidy] Handle unique owning smart pointers in ExprMutationAnalyzer

2018-08-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

I am suprised that this does not automatically follow from the general rules. 
At the end, smartpointers cant do anything else then 'normal' classes.

The `operator+/->` were not handled before? The mutation of `SmartPtr x; 
x->mf();` should already be catched, not?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50883



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


[PATCH] D50616: [Fixed Point Arithmetic] FixedPointCast

2018-08-17 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

In https://reviews.llvm.org/D50616#1203446, @leonardchan wrote:

> Sorry I forgot to address this also. Just to make sure I understand this 
> correctly since I haven't used these before: target hooks are essentially for 
> emitting target specific code for some operations right? Does this mean that 
> the `EmitFixedPointConversion` function should be moved to a virtual method 
> under `TargetCodeGenInfo` that can be overridden and this is what get's 
> called instead during conversion?


Yes, the thought I had was to have a virtual function in TargetCodeGenInfo that 
would be called first thing in EmitFixedPointConversion, and if it returns 
non-null it uses that value instead. It's a bit unfortunate in this instance as 
the only thing that doesn't work for us is the saturation, but letting you 
configure *parts* of the emission is a bit too specific.

In https://reviews.llvm.org/D50616#1203635, @rjmccall wrote:

> If this is more than just a hobby — like if there's a backend that wants to 
> do serious work with matching fixed-point operations to hardware support — we 
> should just add real LLVM IR support for fixed-point types instead of adding 
> a bunch of frontend customization hooks.  I don't know what better 
> opportunity we're expecting might come along to justify that, and I don't 
> think it's some incredibly onerous task to add a new leaf to the LLVM type 
> hierarchy.  Honestly, LLVM programmers across the board have become far too 
> accustomed to pushing things opaquely through an uncooperative IR with an 
> obscure muddle of intrinsics.
>
> In the meantime, we can continue working on this code.  Even if there's 
> eventually real IR support for fixed-point types, this code will still be 
> useful; it'll just become the core of some legalization pass in the generic 
> backend.


It definitely is; our downstream target requires it. As far as I know there's 
no real use case upstream, which is why it's likely quite hard to add any 
extensions to LLVM proper. Our implementation is done through intrinsics rather 
than an extension of the type system, as fixed-point numbers are really just 
integers under the hood. We've always wanted to upstream our fixed-point 
support (or some reasonable adaptation of it) but never gotten the impression 
that it would be possible since there's no upstream user.

A mail I sent to the mailing list a while back has more details on our 
implementation, including what intrinsics we've added: 
http://lists.llvm.org/pipermail/cfe-dev/2018-May/058019.html We also have an 
LLVM pass that converts these intrinsics into pure IR, but it's likely that it 
won't work properly with some parts of this upstream design.

Leonard's original proposal for this work has always been Clang-centric and 
never planned for implementing anything on the LLVM side, so we need to make 
due with what we get, but we would prefer as small a diff from upstream as 
possible.




Comment at: lib/CodeGen/CGExprScalar.cpp:331
+  SourceLocation Loc);
+
   /// Emit a conversion from the specified complex type to the specified

leonardchan wrote:
> ebevhan wrote:
> > What's the plan for the other conversions (int<->fix, float<->fix)? 
> > Functions for those as well?
> > 
> > What about `EmitScalarConversion`? If it cannot handle conversions of 
> > fixed-point values it should probably be made to assert, since it will 
> > likely mess up.
> Ideally, my plan was to have separate functions for each cast since it seems 
> the logic for each of them is unique, other than saturation which may be 
> abstracted to its own function and be used by the others.
> 
> I wasn't sure if I should also place the logic for these casts in 
> `EmitScalarConversion` since `EmitScalarConversion` seemed pretty large 
> enough and thought it was easier if we instead had separate, self contained 
> functions for each fixed point conversion. But I'm open for hearing ideas on 
> different ways on implementing them.
> 
> Will add the assertion.
Yes, you have a point. Our EmitScalarConversion does all of the fixed-point 
stuff at once and it's a pretty big mess.

It might be a bit confusing for users if they use EmitScalarConversion, 
expecting it to work on fixed-point scalars as well but then it doesn't work 
properly.

So long as it asserts to tell them that, it should be fine but someone else 
might have an opinion on the expected behavior of the function.


Repository:
  rC Clang

https://reviews.llvm.org/D50616



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


[PATCH] D50627: [clangd] Add a testcase for empty preamble.

2018-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 161176.
hokein marked an inline comment as done.
hokein added a comment.

Remove ASSERT_TRUE(bool(Preamble)).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50627

Files:
  unittests/clangd/TUSchedulerTests.cpp


Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -308,6 +308,51 @@
   UnorderedElementsAre(Foo, AnyOf(Bar, Baz)));
 }
 
+TEST_F(TUSchedulerTests, EmptyPreamble) {
+  TUScheduler S(
+  /*AsyncThreadsCount=*/4, /*StorePreambleInMemory=*/true,
+  PreambleParsedCallback(),
+  /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+  ASTRetentionPolicy());
+
+  auto Foo = testPath("foo.cpp");
+  auto Header = testPath("foo.h");
+
+  Files[Header] = "void foo()";
+  Timestamps[Header] = time_t(0);
+  auto WithPreamble = R"cpp(
+#include "foo.h"
+int main() {}
+  )cpp";
+  auto WithEmptyPreamble = R"cpp(int main() {})cpp";
+  S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  S.runWithPreamble("getNonEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get a non-empty preamble.
+  EXPECT_GT(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+
+  // Update the file which results in an empty preamble.
+  S.update(Foo, getInputs(Foo, WithEmptyPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  S.runWithPreamble("getEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get an empty preamble.
+  EXPECT_EQ(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+}
+
 TEST_F(TUSchedulerTests, RunWaitsForPreamble) {
   // Testing strategy: we update the file and schedule a few preamble reads at
   // the same time. All reads should get the same non-null preamble.


Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -308,6 +308,51 @@
   UnorderedElementsAre(Foo, AnyOf(Bar, Baz)));
 }
 
+TEST_F(TUSchedulerTests, EmptyPreamble) {
+  TUScheduler S(
+  /*AsyncThreadsCount=*/4, /*StorePreambleInMemory=*/true,
+  PreambleParsedCallback(),
+  /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+  ASTRetentionPolicy());
+
+  auto Foo = testPath("foo.cpp");
+  auto Header = testPath("foo.h");
+
+  Files[Header] = "void foo()";
+  Timestamps[Header] = time_t(0);
+  auto WithPreamble = R"cpp(
+#include "foo.h"
+int main() {}
+  )cpp";
+  auto WithEmptyPreamble = R"cpp(int main() {})cpp";
+  S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  S.runWithPreamble("getNonEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get a non-empty preamble.
+  EXPECT_GT(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+
+  // Update the file which results in an empty preamble.
+  S.update(Foo, getInputs(Foo, WithEmptyPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  S.runWithPreamble("getEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get an empty preamble.
+  EXPECT_EQ(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+}
+
 TEST_F(TUSchedulerTests, RunWaitsForPreamble) {
   // Testing strategy: we update the file and schedule a few preamble reads at
   // the same time. All reads should get the same non-null preamble.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/list

[clang-tools-extra] r340001 - [clangd] Always use the latest preamble

2018-08-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 17 01:15:22 2018
New Revision: 340001

URL: http://llvm.org/viewvc/llvm-project?rev=340001&view=rev
Log:
[clangd] Always use the latest preamble

Summary:
Fix an inconsistent behavior of using `LastBuiltPreamble`/`NewPreamble`
in TUScheduler (see the test for details), AST should always use
NewPreamble. This patch makes LastBuiltPreamble always point to
NewPreamble.

Preamble rarely fails to build, even there are errors in headers, so we
assume it would not cause performace issue for code completion.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=340001&r1=34&r2=340001&view=diff
==
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Fri Aug 17 01:15:22 2018
@@ -370,8 +370,7 @@ void ASTWorker::update(
 bool CanReuseAST = InputsAreTheSame && (OldPreamble == NewPreamble);
 {
   std::lock_guard Lock(Mutex);
-  if (NewPreamble)
-LastBuiltPreamble = NewPreamble;
+  LastBuiltPreamble = NewPreamble;
 }
 // Before doing the expensive AST reparse, we want to release our reference
 // to the old preamble, so it can be freed if there are no other references

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=340001&r1=34&r2=340001&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Fri Aug 17 01:15:22 
2018
@@ -1021,6 +1021,51 @@ TEST(GoToInclude, All) {
   EXPECT_THAT(*Locations, IsEmpty());
 }
 
+TEST(GoToDefinition, WithPreamble) {
+  // Test stragety: AST should always use the latest preamble instead of last
+  // good preamble.
+  MockFSProvider FS;
+  IgnoreDiagnostics DiagConsumer;
+  MockCompilationDatabase CDB;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  auto FooCpp = testPath("foo.cpp");
+  auto FooCppUri = URIForFile{FooCpp};
+  // The trigger locations must be the same.
+  Annotations FooWithHeader(R"cpp(#include "fo^o.h")cpp");
+  Annotations FooWithoutHeader(R"cpp(double[[fo^o]]();)cpp");
+
+  FS.Files[FooCpp] = FooWithHeader.code();
+
+  auto FooH = testPath("foo.h");
+  auto FooHUri = URIForFile{FooH};
+  Annotations FooHeader(R"cpp([[]])cpp");
+  FS.Files[FooH] = FooHeader.code();
+
+  runAddDocument(Server, FooCpp, FooWithHeader.code());
+  // GoToDefinition goes to a #include file: the result comes from the 
preamble.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithHeader.point())),
+  ElementsAre(Location{FooHUri, FooHeader.range()}));
+
+  // Only preamble is built, and no AST is built in this request.
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::No);
+  // We build AST here, and it should use the latest preamble rather than the
+  // stale one.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithoutHeader.point())),
+  ElementsAre(Location{FooCppUri, FooWithoutHeader.range()}));
+
+  // Reset test environment.
+  runAddDocument(Server, FooCpp, FooWithHeader.code());
+  // Both preamble and AST are built in this request.
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::Yes);
+  // Use the AST being built in above request.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithoutHeader.point())),
+  ElementsAre(Location{FooCppUri, FooWithoutHeader.range()}));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


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


[PATCH] D50695: [clangd] Always use the latest preamble

2018-08-17 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE340001: [clangd] Always use the latest preamble (authored 
by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50695?vs=160983&id=161177#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50695

Files:
  clangd/TUScheduler.cpp
  unittests/clangd/XRefsTests.cpp


Index: clangd/TUScheduler.cpp
===
--- clangd/TUScheduler.cpp
+++ clangd/TUScheduler.cpp
@@ -370,8 +370,7 @@
 bool CanReuseAST = InputsAreTheSame && (OldPreamble == NewPreamble);
 {
   std::lock_guard Lock(Mutex);
-  if (NewPreamble)
-LastBuiltPreamble = NewPreamble;
+  LastBuiltPreamble = NewPreamble;
 }
 // Before doing the expensive AST reparse, we want to release our reference
 // to the old preamble, so it can be freed if there are no other references
Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -1021,6 +1021,51 @@
   EXPECT_THAT(*Locations, IsEmpty());
 }
 
+TEST(GoToDefinition, WithPreamble) {
+  // Test stragety: AST should always use the latest preamble instead of last
+  // good preamble.
+  MockFSProvider FS;
+  IgnoreDiagnostics DiagConsumer;
+  MockCompilationDatabase CDB;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  auto FooCpp = testPath("foo.cpp");
+  auto FooCppUri = URIForFile{FooCpp};
+  // The trigger locations must be the same.
+  Annotations FooWithHeader(R"cpp(#include "fo^o.h")cpp");
+  Annotations FooWithoutHeader(R"cpp(double[[fo^o]]();)cpp");
+
+  FS.Files[FooCpp] = FooWithHeader.code();
+
+  auto FooH = testPath("foo.h");
+  auto FooHUri = URIForFile{FooH};
+  Annotations FooHeader(R"cpp([[]])cpp");
+  FS.Files[FooH] = FooHeader.code();
+
+  runAddDocument(Server, FooCpp, FooWithHeader.code());
+  // GoToDefinition goes to a #include file: the result comes from the 
preamble.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithHeader.point())),
+  ElementsAre(Location{FooHUri, FooHeader.range()}));
+
+  // Only preamble is built, and no AST is built in this request.
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::No);
+  // We build AST here, and it should use the latest preamble rather than the
+  // stale one.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithoutHeader.point())),
+  ElementsAre(Location{FooCppUri, FooWithoutHeader.range()}));
+
+  // Reset test environment.
+  runAddDocument(Server, FooCpp, FooWithHeader.code());
+  // Both preamble and AST are built in this request.
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::Yes);
+  // Use the AST being built in above request.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithoutHeader.point())),
+  ElementsAre(Location{FooCppUri, FooWithoutHeader.range()}));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: clangd/TUScheduler.cpp
===
--- clangd/TUScheduler.cpp
+++ clangd/TUScheduler.cpp
@@ -370,8 +370,7 @@
 bool CanReuseAST = InputsAreTheSame && (OldPreamble == NewPreamble);
 {
   std::lock_guard Lock(Mutex);
-  if (NewPreamble)
-LastBuiltPreamble = NewPreamble;
+  LastBuiltPreamble = NewPreamble;
 }
 // Before doing the expensive AST reparse, we want to release our reference
 // to the old preamble, so it can be freed if there are no other references
Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -1021,6 +1021,51 @@
   EXPECT_THAT(*Locations, IsEmpty());
 }
 
+TEST(GoToDefinition, WithPreamble) {
+  // Test stragety: AST should always use the latest preamble instead of last
+  // good preamble.
+  MockFSProvider FS;
+  IgnoreDiagnostics DiagConsumer;
+  MockCompilationDatabase CDB;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  auto FooCpp = testPath("foo.cpp");
+  auto FooCppUri = URIForFile{FooCpp};
+  // The trigger locations must be the same.
+  Annotations FooWithHeader(R"cpp(#include "fo^o.h")cpp");
+  Annotations FooWithoutHeader(R"cpp(double[[fo^o]]();)cpp");
+
+  FS.Files[FooCpp] = FooWithHeader.code();
+
+  auto FooH = testPath("foo.h");
+  auto FooHUri = URIForFile{FooH};
+  Annotations FooHeader(R"cpp([[]])cpp");
+  FS.Files[FooH] = FooHeader.code();
+
+  runAddDocument(Server, FooCpp, FooWithHeader.code());
+  // GoToDefinition goes to a #include file: the result comes from the preamble.
+  EXPECT_THAT(
+  cantFail(runFindDefinitions(Server, FooCpp, FooWithHeader.point())),
+  ElementsAre(Location{FooH

[PATCH] D50726: [clangd] Show function documentation in sigHelp

2018-08-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: clangd/CodeCompletionStrings.cpp:52
   // get this declaration, so we don't show documentation in that case.
   if (Result.Kind != CodeCompletionResult::RK_Declaration)
 return "";

`RK_Pattern` can also have declaration. Do we want to consider those?



Comment at: clangd/CodeCompletionStrings.cpp:57
+return "";
+  return getDeclComment(Ctx, *Decl);
+}

nit: maybe `return Decl ? getDeclComment(...) : "";`



Comment at: clangd/CodeCompletionStrings.cpp:77
 return "";
   return Doc;
 }

nit: `return looksLikeDocComment(Doc) ? Doc : "";` 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50726



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


[PATCH] D50616: [Fixed Point Arithmetic] FixedPointCast

2018-08-17 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D50616#1203692, @ebevhan wrote:

> In https://reviews.llvm.org/D50616#1203446, @leonardchan wrote:
>
> > Sorry I forgot to address this also. Just to make sure I understand this 
> > correctly since I haven't used these before: target hooks are essentially 
> > for emitting target specific code for some operations right? Does this mean 
> > that the `EmitFixedPointConversion` function should be moved to a virtual 
> > method under `TargetCodeGenInfo` that can be overridden and this is what 
> > get's called instead during conversion?
>
>
> Yes, the thought I had was to have a virtual function in TargetCodeGenInfo 
> that would be called first thing in EmitFixedPointConversion, and if it 
> returns non-null it uses that value instead. It's a bit unfortunate in this 
> instance as the only thing that doesn't work for us is the saturation, but 
> letting you configure *parts* of the emission is a bit too specific.
>
> In https://reviews.llvm.org/D50616#1203635, @rjmccall wrote:
>
> > If this is more than just a hobby — like if there's a backend that wants to 
> > do serious work with matching fixed-point operations to hardware support — 
> > we should just add real LLVM IR support for fixed-point types instead of 
> > adding a bunch of frontend customization hooks.  I don't know what better 
> > opportunity we're expecting might come along to justify that, and I don't 
> > think it's some incredibly onerous task to add a new leaf to the LLVM type 
> > hierarchy.  Honestly, LLVM programmers across the board have become far too 
> > accustomed to pushing things opaquely through an uncooperative IR with an 
> > obscure muddle of intrinsics.
> >
> > In the meantime, we can continue working on this code.  Even if there's 
> > eventually real IR support for fixed-point types, this code will still be 
> > useful; it'll just become the core of some legalization pass in the generic 
> > backend.
>
>
> It definitely is; our downstream target requires it. As far as I know there's 
> no real use case upstream, which is why it's likely quite hard to add any 
> extensions to LLVM proper. Our implementation is done through intrinsics 
> rather than an extension of the type system, as fixed-point numbers are 
> really just integers under the hood. We've always wanted to upstream our 
> fixed-point support (or some reasonable adaptation of it) but never gotten 
> the impression that it would be possible since there's no upstream user.
>
> A mail I sent to the mailing list a while back has more details on our 
> implementation, including what intrinsics we've added: 
> http://lists.llvm.org/pipermail/cfe-dev/2018-May/058019.html We also have an 
> LLVM pass that converts these intrinsics into pure IR, but it's likely that 
> it won't work properly with some parts of this upstream design.
>
> Leonard's original proposal for this work has always been Clang-centric and 
> never planned for implementing anything on the LLVM side, so we need to make 
> due with what we get, but we would prefer as small a diff from upstream as 
> possible.


Has anyone actually asked LLVM whether they would accept fixed-point types into 
IR?  I'm just a frontend guy, but it seems to me that there are advantages to 
directly representing these operations in a portable way even if there are no 
in-tree targets providing special support for them.  And there are certainly 
in-tree targets that could provide such support if someone was motivated to do 
it.


Repository:
  rC Clang

https://reviews.llvm.org/D50616



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


[PATCH] D50726: [clangd] Show function documentation in sigHelp

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 161187.
ilya-biryukov marked 2 inline comments as done.
ilya-biryukov added a comment.

- Turn ifs to ternary ops


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50726

Files:
  clangd/CodeComplete.cpp
  clangd/CodeCompletionStrings.cpp
  clangd/CodeCompletionStrings.h


Index: clangd/CodeCompletionStrings.h
===
--- clangd/CodeCompletionStrings.h
+++ clangd/CodeCompletionStrings.h
@@ -32,18 +32,8 @@
   const CodeCompletionResult &Result,
   bool CommentsFromHeaders);
 
-/// Gets a minimally formatted documentation for parameter of \p Result,
-/// corresponding to argument number \p ArgIndex.
-/// This currently looks for comments attached to the parameter itself, and
-/// doesn't extract them from function documentation.
-/// Returns empty string when no comment is available.
-/// If \p CommentsFromHeaders parameter is set, only comments from the main
-/// file will be returned. It is used to workaround crashes when parsing
-/// comments in the stale headers, coming from completion preamble.
-std::string
-getParameterDocComment(const ASTContext &Ctx,
-   const CodeCompleteConsumer::OverloadCandidate &Result,
-   unsigned ArgIndex, bool CommentsFromHeaders);
+/// Similar to getDocComment, but returns the comment for a NamedDecl.
+std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &D);
 
 /// Formats the signature for an item, as a display string and snippet.
 /// e.g. for const_reference std::vector::at(size_type) const, this returns:
Index: clangd/CodeCompletionStrings.cpp
===
--- clangd/CodeCompletionStrings.cpp
+++ clangd/CodeCompletionStrings.cpp
@@ -51,44 +51,26 @@
   // get this declaration, so we don't show documentation in that case.
   if (Result.Kind != CodeCompletionResult::RK_Declaration)
 return "";
-  auto *Decl = Result.getDeclaration();
-  if (!Decl || llvm::isa(Decl)) {
+  return Result.getDeclaration() ? getDeclComment(Ctx, 
*Result.getDeclaration())
+ : "";
+}
+
+std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) {
+  if (llvm::isa(Decl)) {
 // Namespaces often have too many redecls for any particular redecl comment
 // to be useful. Moreover, we often confuse file headers or generated
 // comments with namespace comments. Therefore we choose to just ignore
 // the comments for namespaces.
 return "";
   }
-  const RawComment *RC = getCompletionComment(Ctx, Decl);
-  if (!RC)
-return "";
-
-  // Sanity check that the comment does not come from the PCH. We choose to not
-  // write them into PCH, because they are racy and slow to load.
-  assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
-  std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), 
Ctx.getDiagnostics());
-  if (!looksLikeDocComment(Doc))
-return "";
-  return Doc;
-}
-
-std::string
-getParameterDocComment(const ASTContext &Ctx,
-   const CodeCompleteConsumer::OverloadCandidate &Result,
-   unsigned ArgIndex, bool CommentsFromHeaders) {
-  auto *Func = Result.getFunction();
-  if (!Func)
-return "";
-  const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex);
+  const RawComment *RC = getCompletionComment(Ctx, &Decl);
   if (!RC)
 return "";
   // Sanity check that the comment does not come from the PCH. We choose to not
   // write them into PCH, because they are racy and slow to load.
   assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
   std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), 
Ctx.getDiagnostics());
-  if (!looksLikeDocComment(Doc))
-return "";
-  return Doc;
+  return looksLikeDocComment(Doc) ? Doc : "";
 }
 
 void getSignature(const CodeCompletionString &CCS, std::string *Signature,
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -729,8 +729,9 @@
   // FIXME: for headers, we need to get a comment from the index.
   ScoredSignatures.push_back(processOverloadCandidate(
   Candidate, *CCS,
-  getParameterDocComment(S.getASTContext(), Candidate, CurrentArg,
- /*CommentsFromHeaders=*/false)));
+  Candidate.getFunction()
+  ? getDeclComment(S.getASTContext(), *Candidate.getFunction())
+  : ""));
 }
 std::sort(ScoredSignatures.begin(), ScoredSignatures.end(),
   [](const ScoredSignature &L, const ScoredSignature &R) {


Index: clangd/CodeCompletionStrings.h
===
--- clangd/CodeCompletionStrings.h
+++ clangd/CodeCompletionStrings.h
@@ -32,18

[PATCH] D50726: [clangd] Show function documentation in sigHelp

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/CodeCompletionStrings.cpp:52
   // get this declaration, so we don't show documentation in that case.
   if (Result.Kind != CodeCompletionResult::RK_Declaration)
 return "";

ioeric wrote:
> `RK_Pattern` can also have declaration. Do we want to consider those?
See the FIXME at the top, we don't have the API exposed from clang to get the 
proper declarations (IIRC, this only shows up for ObjC properties and we need 
to look at both getters and setters when looking for a comment, and the clang 
code does not expose the API to do that).

We should probably fix this, but that's a separate issue.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50726



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


[PATCH] D50726: [clangd] Show function documentation in sigHelp

2018-08-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/CodeCompletionStrings.cpp:52
   // get this declaration, so we don't show documentation in that case.
   if (Result.Kind != CodeCompletionResult::RK_Declaration)
 return "";

ilya-biryukov wrote:
> ioeric wrote:
> > `RK_Pattern` can also have declaration. Do we want to consider those?
> See the FIXME at the top, we don't have the API exposed from clang to get the 
> proper declarations (IIRC, this only shows up for ObjC properties and we need 
> to look at both getters and setters when looking for a comment, and the clang 
> code does not expose the API to do that).
> 
> We should probably fix this, but that's a separate issue.
`getDeclaration()` has started supporting `RK_Pattern` recently, so this should 
be fixable now. But feel free to leave it to future.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50726



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


[PATCH] D50726: [clangd] Show function documentation in sigHelp

2018-08-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340004: [clangd] Show function documentation in signature 
help (authored by ibiryukov, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D50726

Files:
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/trunk/clangd/CodeCompletionStrings.h


Index: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
===
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
@@ -51,44 +51,26 @@
   // get this declaration, so we don't show documentation in that case.
   if (Result.Kind != CodeCompletionResult::RK_Declaration)
 return "";
-  auto *Decl = Result.getDeclaration();
-  if (!Decl || llvm::isa(Decl)) {
+  return Result.getDeclaration() ? getDeclComment(Ctx, 
*Result.getDeclaration())
+ : "";
+}
+
+std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) {
+  if (llvm::isa(Decl)) {
 // Namespaces often have too many redecls for any particular redecl comment
 // to be useful. Moreover, we often confuse file headers or generated
 // comments with namespace comments. Therefore we choose to just ignore
 // the comments for namespaces.
 return "";
   }
-  const RawComment *RC = getCompletionComment(Ctx, Decl);
-  if (!RC)
-return "";
-
-  // Sanity check that the comment does not come from the PCH. We choose to not
-  // write them into PCH, because they are racy and slow to load.
-  assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
-  std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), 
Ctx.getDiagnostics());
-  if (!looksLikeDocComment(Doc))
-return "";
-  return Doc;
-}
-
-std::string
-getParameterDocComment(const ASTContext &Ctx,
-   const CodeCompleteConsumer::OverloadCandidate &Result,
-   unsigned ArgIndex, bool CommentsFromHeaders) {
-  auto *Func = Result.getFunction();
-  if (!Func)
-return "";
-  const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex);
+  const RawComment *RC = getCompletionComment(Ctx, &Decl);
   if (!RC)
 return "";
   // Sanity check that the comment does not come from the PCH. We choose to not
   // write them into PCH, because they are racy and slow to load.
   assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
   std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), 
Ctx.getDiagnostics());
-  if (!looksLikeDocComment(Doc))
-return "";
-  return Doc;
+  return looksLikeDocComment(Doc) ? Doc : "";
 }
 
 void getSignature(const CodeCompletionString &CCS, std::string *Signature,
Index: clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
===
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
@@ -33,18 +33,8 @@
   const CodeCompletionResult &Result,
   bool CommentsFromHeaders);
 
-/// Gets a minimally formatted documentation for parameter of \p Result,
-/// corresponding to argument number \p ArgIndex.
-/// This currently looks for comments attached to the parameter itself, and
-/// doesn't extract them from function documentation.
-/// Returns empty string when no comment is available.
-/// If \p CommentsFromHeaders parameter is set, only comments from the main
-/// file will be returned. It is used to workaround crashes when parsing
-/// comments in the stale headers, coming from completion preamble.
-std::string
-getParameterDocComment(const ASTContext &Ctx,
-   const CodeCompleteConsumer::OverloadCandidate &Result,
-   unsigned ArgIndex, bool CommentsFromHeaders);
+/// Similar to getDocComment, but returns the comment for a NamedDecl.
+std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &D);
 
 /// Formats the signature for an item, as a display string and snippet.
 /// e.g. for const_reference std::vector::at(size_type) const, this returns:
Index: clang-tools-extra/trunk/clangd/CodeComplete.cpp
===
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp
@@ -729,8 +729,9 @@
   // FIXME: for headers, we need to get a comment from the index.
   ScoredSignatures.push_back(processOverloadCandidate(
   Candidate, *CCS,
-  getParameterDocComment(S.getASTContext(), Candidate, CurrentArg,
- /*CommentsFromHeaders=*/false)));
+  Candidate.getFunction()
+  ? getDeclComment(S.getASTContext(), *Candidate.getFunction())
+ 

[clang-tools-extra] r340004 - [clangd] Show function documentation in signature help

2018-08-17 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Aug 17 02:29:38 2018
New Revision: 340004

URL: http://llvm.org/viewvc/llvm-project?rev=340004&view=rev
Log:
[clangd] Show function documentation in signature help

Summary:
Previously, clangd was trying to show documentation for the active
parameter instead, which is wrong per LSP specification.

Moreover, the code path that attempts to get parameter comments never
succeds, because no attempt is made to parse function doc comment and
extract parameter-specific parts out of it. So we also remove the code
that claims to fetch parameter comments: it is not used anymore and is
incorrect.

Reviewers: hokein, ioeric, kadircet

Reviewed By: ioeric

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.h

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=340004&r1=340003&r2=340004&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Aug 17 02:29:38 2018
@@ -729,8 +729,9 @@ public:
   // FIXME: for headers, we need to get a comment from the index.
   ScoredSignatures.push_back(processOverloadCandidate(
   Candidate, *CCS,
-  getParameterDocComment(S.getASTContext(), Candidate, CurrentArg,
- /*CommentsFromHeaders=*/false)));
+  Candidate.getFunction()
+  ? getDeclComment(S.getASTContext(), *Candidate.getFunction())
+  : ""));
 }
 std::sort(ScoredSignatures.begin(), ScoredSignatures.end(),
   [](const ScoredSignature &L, const ScoredSignature &R) {

Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp?rev=340004&r1=340003&r2=340004&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp Fri Aug 17 
02:29:38 2018
@@ -51,44 +51,26 @@ std::string getDocComment(const ASTConte
   // get this declaration, so we don't show documentation in that case.
   if (Result.Kind != CodeCompletionResult::RK_Declaration)
 return "";
-  auto *Decl = Result.getDeclaration();
-  if (!Decl || llvm::isa(Decl)) {
+  return Result.getDeclaration() ? getDeclComment(Ctx, 
*Result.getDeclaration())
+ : "";
+}
+
+std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) {
+  if (llvm::isa(Decl)) {
 // Namespaces often have too many redecls for any particular redecl comment
 // to be useful. Moreover, we often confuse file headers or generated
 // comments with namespace comments. Therefore we choose to just ignore
 // the comments for namespaces.
 return "";
   }
-  const RawComment *RC = getCompletionComment(Ctx, Decl);
-  if (!RC)
-return "";
-
-  // Sanity check that the comment does not come from the PCH. We choose to not
-  // write them into PCH, because they are racy and slow to load.
-  assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
-  std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), 
Ctx.getDiagnostics());
-  if (!looksLikeDocComment(Doc))
-return "";
-  return Doc;
-}
-
-std::string
-getParameterDocComment(const ASTContext &Ctx,
-   const CodeCompleteConsumer::OverloadCandidate &Result,
-   unsigned ArgIndex, bool CommentsFromHeaders) {
-  auto *Func = Result.getFunction();
-  if (!Func)
-return "";
-  const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex);
+  const RawComment *RC = getCompletionComment(Ctx, &Decl);
   if (!RC)
 return "";
   // Sanity check that the comment does not come from the PCH. We choose to not
   // write them into PCH, because they are racy and slow to load.
   assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
   std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), 
Ctx.getDiagnostics());
-  if (!looksLikeDocComment(Doc))
-return "";
-  return Doc;
+  return looksLikeDocComment(Doc) ? Doc : "";
 }
 
 void getSignature(const CodeCompletionString &CCS, std::string *Signature,

Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.h?rev=340004&r1=340003&r2=340004&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeCompletionStri

[clang-tools-extra] r340005 - [clangd] Fetch documentation from the Index during signature help

2018-08-17 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Aug 17 02:32:30 2018
New Revision: 340005

URL: http://llvm.org/viewvc/llvm-project?rev=340005&view=rev
Log:
[clangd] Fetch documentation from the Index during signature help

Summary:
Sema can only be used for documentation in the current file, other doc
comments should be fetched from the index.

Reviewers: hokein, ioeric, kadircet

Reviewed By: hokein, kadircet

Subscribers: MaskRay, jkorous, mgrang, arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=340005&r1=340004&r2=340005&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Fri Aug 17 02:32:30 2018
@@ -177,15 +177,16 @@ void ClangdServer::signatureHelp(PathRef
 
   auto PCHs = this->PCHs;
   auto FS = FSProvider.getFileSystem();
-  auto Action = [Pos, FS, PCHs](Path File, Callback CB,
-llvm::Expected IP) {
+  auto *Index = this->Index;
+  auto Action = [Pos, FS, PCHs, Index](Path File, Callback CB,
+   llvm::Expected IP) {
 if (!IP)
   return CB(IP.takeError());
 
 auto PreambleData = IP->Preamble;
 CB(clangd::signatureHelp(File, IP->Command,
  PreambleData ? &PreambleData->Preamble : nullptr,
- IP->Contents, Pos, FS, PCHs));
+ IP->Contents, Pos, FS, PCHs, Index));
   };
 
   WorkScheduler.runWithPreamble("SignatureHelp", File,

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=340005&r1=340004&r2=340005&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Aug 17 02:32:30 2018
@@ -687,18 +687,23 @@ private:
   llvm::unique_function ResultsCallback;
 };
 
-using ScoredSignature =
-std::pair;
+struct ScoredSignature {
+  // When set, requires documentation to be requested from the index with this
+  // ID.
+  llvm::Optional IDForDoc;
+  SignatureInformation Signature;
+  SignatureQualitySignals Quality;
+};
 
 class SignatureHelpCollector final : public CodeCompleteConsumer {
-
 public:
   SignatureHelpCollector(const clang::CodeCompleteOptions &CodeCompleteOpts,
- SignatureHelp &SigHelp)
-  : CodeCompleteConsumer(CodeCompleteOpts, /*OutputIsBinary=*/false),
+ SymbolIndex *Index, SignatureHelp &SigHelp)
+  : CodeCompleteConsumer(CodeCompleteOpts,
+ /*OutputIsBinary=*/false),
 SigHelp(SigHelp),
 Allocator(std::make_shared()),
-CCTUInfo(Allocator) {}
+CCTUInfo(Allocator), Index(Index) {}
 
   void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
  OverloadCandidate *Candidates,
@@ -726,47 +731,74 @@ public:
   const auto *CCS = Candidate.CreateSignatureString(
   CurrentArg, S, *Allocator, CCTUInfo, true);
   assert(CCS && "Expected the CodeCompletionString to be non-null");
-  // FIXME: for headers, we need to get a comment from the index.
   ScoredSignatures.push_back(processOverloadCandidate(
   Candidate, *CCS,
   Candidate.getFunction()
   ? getDeclComment(S.getASTContext(), *Candidate.getFunction())
   : ""));
 }
-std::sort(ScoredSignatures.begin(), ScoredSignatures.end(),
-  [](const ScoredSignature &L, const ScoredSignature &R) {
-// Ordering follows:
-// - Less number of parameters is better.
-// - Function is better than FunctionType which is better than
-// Function Template.
-// - High score is better.
-// - Shorter signature is better.
-// - Alphebatically smaller is better.
-if (L.first.NumberOfParameters != R.first.NumberOfParameters)
-  return L.first.NumberOfParameters <
- R.first.NumberOfParameters;
-if (L.first.NumberOfOptionalParameters !=
-R.first.NumberOfOptionalParameters)
-  return L.first.NumberOfOptionalParameters <
- R.first.NumberOfOptionalParameters;
-if (L.first.Kind != R.first.Kind) {
-  using OC = CodeCompleteConsum

[PATCH] D50616: [Fixed Point Arithmetic] FixedPointCast

2018-08-17 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D50616#1203751, @rjmccall wrote:

> In https://reviews.llvm.org/D50616#1203692, @ebevhan wrote:
>
> >
>
>
> Has anyone actually asked LLVM whether they would accept fixed-point types 
> into IR?  I'm just a frontend guy, but it seems to me that there are 
> advantages to directly representing these operations in a portable way even 
> if there are no in-tree targets providing special support for them.  And 
> there are certainly in-tree targets that could provide such support if 
> someone was motivated to do it.


Even just adding one new LLVM IR instruction (well, intrinsic too, ideally) 
already 'requires' you to to
then go around and make sure it is properly handled wrt all the other 
instructions, optimizations, codegen.

Adding a whole new type, i suspect, would be *much* more impactful.
And since it can already be represented via existing operations on existing 
integer type,
it isn't obvious why that would be the right way forward.


Repository:
  rC Clang

https://reviews.llvm.org/D50616



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


[PATCH] D50727: [clangd] Fetch documentation from the Index during signature help

2018-08-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340005: [clangd] Fetch documentation from the Index during 
signature help (authored by ibiryukov, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50727?vs=160992&id=161189#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50727

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  clang-tools-extra/trunk/clangd/CodeComplete.h
  clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
@@ -826,11 +826,19 @@
   EXPECT_TRUE(Results.Completions.empty());
 }
 
-SignatureHelp signatures(StringRef Text) {
+SignatureHelp signatures(StringRef Text,
+ std::vector IndexSymbols = {}) {
+  std::unique_ptr Index;
+  if (!IndexSymbols.empty())
+Index = memIndex(IndexSymbols);
+
   MockFSProvider FS;
   MockCompilationDatabase CDB;
   IgnoreDiagnostics DiagConsumer;
-  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+  ClangdServer::Options Opts = ClangdServer::optsForTest();
+  Opts.StaticIndex = Index.get();
+
+  ClangdServer Server(CDB, FS, DiagConsumer, Opts);
   auto File = testPath("foo.cpp");
   Annotations Test(Text);
   runAddDocument(Server, File, Test.code());
@@ -845,6 +853,7 @@
   return false;
   return true;
 }
+MATCHER_P(SigDoc, Doc, "") { return arg.documentation == Doc; }
 
 Matcher Sig(std::string Label,
   std::vector Params) {
@@ -1594,6 +1603,51 @@
   ElementsAre(Sig("foo(T, U) -> void", {"T", "U"})));
 }
 
+TEST(SignatureHelpTest, IndexDocumentation) {
+  Symbol::Details DocDetails;
+  DocDetails.Documentation = "Doc from the index";
+
+  Symbol Foo0 = sym("foo", index::SymbolKind::Function, "@F@\\0#");
+  Foo0.Detail = &DocDetails;
+  Symbol Foo1 = sym("foo", index::SymbolKind::Function, "@F@\\0#I#");
+  Foo1.Detail = &DocDetails;
+  Symbol Foo2 = sym("foo", index::SymbolKind::Function, "@F@\\0#I#I#");
+
+  EXPECT_THAT(
+  signatures(R"cpp(
+int foo();
+int foo(double);
+
+void test() {
+  foo(^);
+}
+  )cpp",
+ {Foo0})
+  .signatures,
+  ElementsAre(AllOf(Sig("foo() -> int", {}), SigDoc("Doc from the index")),
+  AllOf(Sig("foo(double) -> int", {"double"}), SigDoc("";
+
+  EXPECT_THAT(
+  signatures(R"cpp(
+int foo();
+// Overriden doc from sema
+int foo(int);
+// Doc from sema
+int foo(int, int);
+
+void test() {
+  foo(^);
+}
+  )cpp",
+ {Foo0, Foo1, Foo2})
+  .signatures,
+  ElementsAre(AllOf(Sig("foo() -> int", {}), SigDoc("Doc from the index")),
+  AllOf(Sig("foo(int) -> int", {"int"}),
+SigDoc("Overriden doc from sema")),
+  AllOf(Sig("foo(int, int) -> int", {"int", "int"}),
+SigDoc("Doc from sema";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/trunk/clangd/CodeComplete.h
===
--- clang-tools-extra/trunk/clangd/CodeComplete.h
+++ clang-tools-extra/trunk/clangd/CodeComplete.h
@@ -172,12 +172,11 @@
 CodeCompleteOptions Opts);
 
 /// Get signature help at a specified \p Pos in \p FileName.
-SignatureHelp signatureHelp(PathRef FileName,
-const tooling::CompileCommand &Command,
-PrecompiledPreamble const *Preamble,
-StringRef Contents, Position Pos,
-IntrusiveRefCntPtr VFS,
-std::shared_ptr PCHs);
+SignatureHelp
+signatureHelp(PathRef FileName, const tooling::CompileCommand &Command,
+  PrecompiledPreamble const *Preamble, StringRef Contents,
+  Position Pos, IntrusiveRefCntPtr VFS,
+  std::shared_ptr PCHs, SymbolIndex *Index);
 
 // For index-based completion, we only consider:
 //   * symbols in namespaces or translation unit scopes (e.g. no class
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -177,15 +177,16 @@
 
   auto PCHs = this->PCHs;
   auto FS = FSProvider.getFileSystem();
-  auto Action = [Pos, FS, PCHs](Path File, Callback CB,
-llvm::Expected IP) {
+  auto *Index = this->Index;
+  auto Action = [Pos, FS, PCHs, Index](Path File, Callback CB,
+  

[PATCH] D50847: [clangd] Add callbacks on parsed AST in addition to parsed preambles

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D50847#1202658, @ioeric wrote:

> > Dynamic index misses important information from the body of the file, e.g. 
> > locations of definitions
> >  XRefs cannot be collected at all, since we can only obtain full 
> > information for the current file (preamble is parsed with skipped function 
> > bodies, therefore not reliable).
>
> These seem to be known limitations of the dynamic index. The dynamic index, 
> in general, only handles things that are in headers; information in the main 
> file can usually be obtained from Sema/AST (outside of the index). For 
> example, definition/xrefs locations can be merged from index and the AST.


We still want this information in the index. One can obtain this information 
for the **current** file. However, we still need to keep this info in the index 
for definitions in the other open files.

>> This patch only adds the new callback, actually updating the index will be 
>> added in a follow-up patch.
> 
> How do we plan to merge symbols from the preamble callback and the main file 
> callback? The current FileIndex only allows swapping all symbols.

There are multiple ways to do that, lowest overhead is having two separate 
slabs: one for preamble symbols, another for symbols in the main file. They 
will be merged on-the-go when requested.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50847



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


[PATCH] D50119: Compiler support for P1144R0 "__is_trivially_relocatable(T)"

2018-08-17 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 161190.
Quuxplusone added a comment.

A type with no move-constructor, and some non-defaulted copy-constructors (even 
if it *also* has some defaulted copy-constructors) should not be considered 
naturally trivially relocatable. The paper already said this, but the Clang 
patch was misimplemented.

Thanks to @Rakete for either finding or inspiring this fix. :)

I suspect there may be some way of doing this without the extra bitflag, but I 
didn't immediately see how.


Repository:
  rC Clang

https://reviews.llvm.org/D50119

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Features.def
  include/clang/Basic/TokenKinds.def
  include/clang/Basic/TypeTraits.h
  lib/AST/ASTImporter.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  test/Lexer/has_extension_cxx.cpp
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/SemaCXX/trivially-relocatable.cpp

Index: test/SemaCXX/trivially-relocatable.cpp
===
--- /dev/null
+++ test/SemaCXX/trivially-relocatable.cpp
@@ -0,0 +1,518 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// expected-diagnostics
+
+static_assert(__has_extension(trivially_relocatable), "");
+
+// It shall appear at most once in each attribute-list
+// and no attribute-argument-clause shall be present.
+
+struct [[trivially_relocatable, trivially_relocatable]] B1 {};
+// expected-error@-1{{attribute 'trivially_relocatable' cannot appear multiple times in an attribute specifier}}
+
+struct [[trivially_relocatable]] [[trivially_relocatable]] B2 {}; // should really be an error
+
+struct [[trivially_relocatable(42)]] B3 {};
+// expected-error@-1{{attribute 'trivially_relocatable' cannot have an argument list}}
+
+
+//   The first declaration of a type shall specify the
+//   trivially_relocatable attribute if any declaration of that
+//   type specifies the trivially_relocatable attribute.
+
+struct [[trivially_relocatable]] A1 {};  // ok
+struct [[trivially_relocatable]] A1;
+
+struct [[trivially_relocatable]] A2;  // ok
+struct [[trivially_relocatable]] A2 {};
+
+struct [[trivially_relocatable]] A3 {};  // ok
+struct A3;
+
+struct [[trivially_relocatable]] A4;  // ok
+struct A4 {};
+
+struct A5 {};
+struct [[trivially_relocatable]] A5;
+// expected-error@-1{{type A5 declared 'trivially_relocatable' after its first declaration}}
+// expected-note@-3{{declaration missing 'trivially_relocatable' attribute is here}}
+// expected-warning@-3{{attribute declaration must precede definition}}
+// expected-note@-5{{previous definition is here}}
+
+struct A6;
+struct [[trivially_relocatable]] A6 {};
+// expected-error@-1{{type A6 declared 'trivially_relocatable' after its first declaration}}
+// expected-note@-3{{declaration missing 'trivially_relocatable' attribute is here}}
+
+
+// If a type T is declared with the trivially_relocatable attribute, and T is
+// either not move-constructible or not destructible, the program is ill-formed.
+
+struct NonDestructible {
+NonDestructible(const NonDestructible&) = default;
+NonDestructible(NonDestructible&&) = default;
+~NonDestructible() = delete;
+};
+struct NonCopyConstructible {
+NonCopyConstructible(const NonCopyConstructible&) = delete;
+};
+struct NonMoveConstructible {
+NonMoveConstructible(const NonMoveConstructible&) = default;
+NonMoveConstructible(NonMoveConstructible&&) = delete;
+};
+static_assert(!__is_trivially_relocatable(NonDestructible), "");
+static_assert(!__is_trivially_relocatable(NonCopyConstructible), "");
+static_assert(!__is_constructible(NonCopyConstructible, NonCopyConstructible&&), "");
+static_assert(!__is_trivially_relocatable(NonMoveConstructible), "");
+static_assert(!__is_constructible(NonMoveConstructible, NonMoveConstructible&&), "");
+
+struct [[trivially_relocatable]] D1 { ~D1() = delete; };
+// expected-error@-1{{cannot be applied to struct 'D1' because it is not destructible}}
+
+struct [[trivially_relocatable]] D2 : private NonDestructible { };
+// expected-error@-1{{cannot be applied to struct 'D2' because it is not destructible}}
+
+struct [[trivially_relocatable]] D3 { D3(const D3&) = delete; };
+// expected-error@-1{{cannot be applied to struct 'D3' because it is not move-constructible}}
+
+struct [[trivially_relocatable]] D4 { D4(const D4&) = default; D4(D4&&) = delete; };
+// expected-error@-1{{cannot be applied to struct 'D4' because it is not move-constructible}}
+
+struct [[trivially_relocatable]] D5 : private NonCopyConstructible { };
+// expected-error@-1{{cannot be applied to struct 'D5'

[PATCH] D50839: [llvm] Optimize YAML::isNumeric

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 161191.
kbobyrev marked 4 inline comments as done.
kbobyrev added a comment.

Upload version which is IMO readable.


https://reviews.llvm.org/D50839

Files:
  llvm/include/llvm/Support/YAMLTraits.h
  llvm/tools/llvm-yaml-numeric-parser-fuzzer/CMakeLists.txt
  llvm/tools/llvm-yaml-numeric-parser-fuzzer/DummyYAMLNumericParserFuzzer.cpp
  llvm/tools/llvm-yaml-numeric-parser-fuzzer/yaml-numeric-parser-fuzzer.cpp
  llvm/unittests/Support/YAMLIOTest.cpp

Index: llvm/unittests/Support/YAMLIOTest.cpp
===
--- llvm/unittests/Support/YAMLIOTest.cpp
+++ llvm/unittests/Support/YAMLIOTest.cpp
@@ -16,16 +16,17 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using llvm::yaml::Hex16;
+using llvm::yaml::Hex32;
+using llvm::yaml::Hex64;
+using llvm::yaml::Hex8;
 using llvm::yaml::Input;
-using llvm::yaml::Output;
 using llvm::yaml::IO;
-using llvm::yaml::MappingTraits;
+using llvm::yaml::isNumeric;
 using llvm::yaml::MappingNormalization;
+using llvm::yaml::MappingTraits;
+using llvm::yaml::Output;
 using llvm::yaml::ScalarTraits;
-using llvm::yaml::Hex8;
-using llvm::yaml::Hex16;
-using llvm::yaml::Hex32;
-using llvm::yaml::Hex64;
 using ::testing::StartsWith;
 
 
@@ -2569,3 +2570,66 @@
 TestEscaped((char const *)foobar, "\"foo\\u200Bbar\"");
   }
 }
+
+TEST(YAMLIO, Numeric) {
+  EXPECT_TRUE(isNumeric(".inf"));
+  EXPECT_TRUE(isNumeric(".INF"));
+  EXPECT_TRUE(isNumeric(".Inf"));
+  EXPECT_TRUE(isNumeric("-.inf"));
+  EXPECT_TRUE(isNumeric("+.inf"));
+
+  EXPECT_TRUE(isNumeric(".nan"));
+  EXPECT_TRUE(isNumeric(".NaN"));
+  EXPECT_TRUE(isNumeric(".NAN"));
+
+  EXPECT_TRUE(isNumeric("0"));
+  EXPECT_TRUE(isNumeric("0."));
+  EXPECT_TRUE(isNumeric("0.0"));
+  EXPECT_TRUE(isNumeric("-0.0"));
+  EXPECT_TRUE(isNumeric("+0.0"));
+
+  EXPECT_TRUE(isNumeric("12345"));
+  EXPECT_TRUE(isNumeric("012345"));
+  EXPECT_TRUE(isNumeric("+12.0"));
+  EXPECT_TRUE(isNumeric(".5"));
+  EXPECT_TRUE(isNumeric("+.5"));
+  EXPECT_TRUE(isNumeric("-1.0"));
+
+  EXPECT_TRUE(isNumeric("2.3e4"));
+  EXPECT_TRUE(isNumeric("-2E+05"));
+  EXPECT_TRUE(isNumeric("+12e03"));
+  EXPECT_TRUE(isNumeric("6.8523015e+5"));
+
+  EXPECT_TRUE(isNumeric("1.e+1"));
+  EXPECT_TRUE(isNumeric(".0e+1"));
+
+  EXPECT_TRUE(isNumeric("0x2aF3"));
+  EXPECT_TRUE(isNumeric("0o01234567"));
+
+  EXPECT_FALSE(isNumeric("not a number"));
+  EXPECT_FALSE(isNumeric("."));
+  EXPECT_FALSE(isNumeric(".e+1"));
+  EXPECT_FALSE(isNumeric(".1e"));
+  EXPECT_FALSE(isNumeric(".1e+"));
+  EXPECT_FALSE(isNumeric(".1e++1"));
+
+  EXPECT_FALSE(isNumeric("ABCD"));
+  EXPECT_FALSE(isNumeric("+0x2AF3"));
+  EXPECT_FALSE(isNumeric("-0x2AF3"));
+  EXPECT_FALSE(isNumeric("0x2AF3Z"));
+  EXPECT_FALSE(isNumeric("0o012345678"));
+  EXPECT_FALSE(isNumeric("0xZ"));
+  EXPECT_FALSE(isNumeric("-0o012345678"));
+  EXPECT_FALSE(isNumeric("03A8229434B839616A25C16B0291F77A438B"));
+
+  // Deprecated formats: as for YAML 1.2 specification, the following are not
+  // valid numbers anymore:
+  //
+  // * Sexagecimal numbers
+  // * Decimal numbers with comma s the delimiter
+  // * "inf", "nan" without '.' prefix
+  EXPECT_FALSE(isNumeric("3:25:45"));
+  EXPECT_FALSE(isNumeric("+12,345"));
+  EXPECT_FALSE(isNumeric("-inf"));
+  EXPECT_FALSE(isNumeric("1,230.15"));
+}
Index: llvm/tools/llvm-yaml-numeric-parser-fuzzer/yaml-numeric-parser-fuzzer.cpp
===
--- /dev/null
+++ llvm/tools/llvm-yaml-numeric-parser-fuzzer/yaml-numeric-parser-fuzzer.cpp
@@ -0,0 +1,44 @@
+//===--- special-case-list-fuzzer.cpp - Fuzzer for special case lists -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Regex.h"
+#include "llvm/Support/YAMLTraits.h"
+#include 
+#include 
+
+llvm::Regex Infinity("^[-+]?(\\.inf|\\.Inf|\\.INF)$");
+llvm::Regex Base8("^0o[0-7]+$");
+llvm::Regex Base16("^0x[0-9a-fA-F]+$");
+llvm::Regex Float("^[-+]?(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
+
+inline bool isNumericRegex(llvm::StringRef S) {
+  if (S.equals(".nan") || S.equals(".NaN") || S.equals(".NAN"))
+return true;
+
+  if (Infinity.match(S))
+return true;
+
+  if (Base8.match(S))
+return true;
+
+  if (Base16.match(S))
+return true;
+
+  if (Float.match(S))
+return true;
+
+  return false;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+  std::string Input(reinterpret_cast(Data), Size);
+  assert(llvm::yaml::isNumeric(Input) == isNumericRegex(Input));
+  return 0;
+}
Index: llvm/tools/llvm-yaml-numeric-parser-fuzzer/DummyYAMLNumericParserFuzzer.cpp
===
--- /dev/null
+++ 

[PATCH] D50839: [llvm] Optimize YAML::isNumeric

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: llvm/include/llvm/Support/YAMLTraits.h:454
+inline bool isNumeric(StringRef S) {
+  if (S.empty())
+return false;

zturner wrote:
> What would happen if we re-wrote this entire function as:
> 
> ```
> inline bool isNumeric(StringRef S) {
>   uint64_t N;
>   int64_t I;
>   APFloat F;
>   return S.getAsInteger(N) || S.getAsInteger(I) || (F.convertFromString(S) == 
> opOK);
> }
> ```
> 
> Would this a) Be correct, and b) have similar performance characteristics to 
> what you've got here?
Thank you for the suggestion!

I have tried the proposed approach, but there are several caveats:

First, `APInt` (which I believe should be used in this case since YAML numbers 
are of arbitrary length) parsing does not look simpler than the current 
approach (and it's also unnecessary overhead and potentially some cases which 
are invalid in YAML but are perfectly fine in `APInt` parser). An example would 
be the prefix of octal numbers: `APInt` accepts `0` while it should be `0o` in 
YAML, so the `Radix` should be manually inferred anyway.

The main problem, however, is with the `APFloat` parser, which accepts a huge 
number of items which are not valid in YAML numeric format. Examples are:

* `.`
* `.e+1`
* `.e+`
* `.e`

Even worse, the parser appears to have bugs. I was able to find several classes 
of inputs which cause global-buffer-overflow caught by AddressSanitizer (e.g. 
`.+`). This should be investigated independently. However, the above cases lead 
me to believe that:

1) The LLVM parser is likely to have a huge number of cases which are invalid 
in YAML numeric format but are valid `APFloat`s. Finding all of these cases is 
non-trivial and is probably not rewarding.
2) The parser is unreliable.

What do you think?


https://reviews.llvm.org/D50839



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


[PATCH] D50839: [llvm] Optimize YAML::isNumeric

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 161192.
kbobyrev added a comment.

I tried to rewrite the loop, but IMO it looks even worse now.


https://reviews.llvm.org/D50839

Files:
  llvm/include/llvm/Support/YAMLTraits.h
  llvm/tools/llvm-yaml-numeric-parser-fuzzer/CMakeLists.txt
  llvm/tools/llvm-yaml-numeric-parser-fuzzer/DummyYAMLNumericParserFuzzer.cpp
  llvm/tools/llvm-yaml-numeric-parser-fuzzer/yaml-numeric-parser-fuzzer.cpp
  llvm/unittests/Support/YAMLIOTest.cpp

Index: llvm/unittests/Support/YAMLIOTest.cpp
===
--- llvm/unittests/Support/YAMLIOTest.cpp
+++ llvm/unittests/Support/YAMLIOTest.cpp
@@ -16,16 +16,17 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using llvm::yaml::Hex16;
+using llvm::yaml::Hex32;
+using llvm::yaml::Hex64;
+using llvm::yaml::Hex8;
 using llvm::yaml::Input;
-using llvm::yaml::Output;
 using llvm::yaml::IO;
-using llvm::yaml::MappingTraits;
+using llvm::yaml::isNumeric;
 using llvm::yaml::MappingNormalization;
+using llvm::yaml::MappingTraits;
+using llvm::yaml::Output;
 using llvm::yaml::ScalarTraits;
-using llvm::yaml::Hex8;
-using llvm::yaml::Hex16;
-using llvm::yaml::Hex32;
-using llvm::yaml::Hex64;
 using ::testing::StartsWith;
 
 
@@ -2569,3 +2570,71 @@
 TestEscaped((char const *)foobar, "\"foo\\u200Bbar\"");
   }
 }
+
+TEST(YAMLIO, Numeric) {
+  EXPECT_TRUE(isNumeric(".inf"));
+  EXPECT_TRUE(isNumeric(".INF"));
+  EXPECT_TRUE(isNumeric(".Inf"));
+  EXPECT_TRUE(isNumeric("-.inf"));
+  EXPECT_TRUE(isNumeric("+.inf"));
+
+  EXPECT_TRUE(isNumeric(".nan"));
+  EXPECT_TRUE(isNumeric(".NaN"));
+  EXPECT_TRUE(isNumeric(".NAN"));
+
+  EXPECT_TRUE(isNumeric("0"));
+  EXPECT_TRUE(isNumeric("0."));
+  EXPECT_TRUE(isNumeric("0.0"));
+  EXPECT_TRUE(isNumeric("-0.0"));
+  EXPECT_TRUE(isNumeric("+0.0"));
+
+  EXPECT_TRUE(isNumeric("12345"));
+  EXPECT_TRUE(isNumeric("012345"));
+  EXPECT_TRUE(isNumeric("+12.0"));
+  EXPECT_TRUE(isNumeric(".5"));
+  EXPECT_TRUE(isNumeric("+.5"));
+  EXPECT_TRUE(isNumeric("-1.0"));
+
+  EXPECT_TRUE(isNumeric("2.3e4"));
+  EXPECT_TRUE(isNumeric("-2E+05"));
+  EXPECT_TRUE(isNumeric("+12e03"));
+  EXPECT_TRUE(isNumeric("6.8523015e+5"));
+
+  EXPECT_TRUE(isNumeric("1.e+1"));
+  EXPECT_TRUE(isNumeric(".0e+1"));
+
+  EXPECT_TRUE(isNumeric("0x2aF3"));
+  EXPECT_TRUE(isNumeric("0o01234567"));
+
+  EXPECT_FALSE(isNumeric("not a number"));
+  EXPECT_FALSE(isNumeric("."));
+  EXPECT_FALSE(isNumeric(".e+1"));
+  EXPECT_FALSE(isNumeric(".1e"));
+  EXPECT_FALSE(isNumeric(".1e+"));
+  EXPECT_FALSE(isNumeric(".1e++1"));
+
+  EXPECT_FALSE(isNumeric("ABCD"));
+  EXPECT_FALSE(isNumeric("+0x2AF3"));
+  EXPECT_FALSE(isNumeric("-0x2AF3"));
+  EXPECT_FALSE(isNumeric("0x2AF3Z"));
+  EXPECT_FALSE(isNumeric("0o012345678"));
+  EXPECT_FALSE(isNumeric("0xZ"));
+  EXPECT_FALSE(isNumeric("-0o012345678"));
+  EXPECT_FALSE(isNumeric("03A8229434B839616A25C16B0291F77A438B"));
+
+  EXPECT_FALSE(isNumeric("."));
+  EXPECT_FALSE(isNumeric(".e+1"));
+  EXPECT_FALSE(isNumeric(".e+"));
+  EXPECT_FALSE(isNumeric(".e"));
+
+  // Deprecated formats: as for YAML 1.2 specification, the following are not
+  // valid numbers anymore:
+  //
+  // * Sexagecimal numbers
+  // * Decimal numbers with comma s the delimiter
+  // * "inf", "nan" without '.' prefix
+  EXPECT_FALSE(isNumeric("3:25:45"));
+  EXPECT_FALSE(isNumeric("+12,345"));
+  EXPECT_FALSE(isNumeric("-inf"));
+  EXPECT_FALSE(isNumeric("1,230.15"));
+}
Index: llvm/tools/llvm-yaml-numeric-parser-fuzzer/yaml-numeric-parser-fuzzer.cpp
===
--- /dev/null
+++ llvm/tools/llvm-yaml-numeric-parser-fuzzer/yaml-numeric-parser-fuzzer.cpp
@@ -0,0 +1,45 @@
+//===--- special-case-list-fuzzer.cpp - Fuzzer for special case lists -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Regex.h"
+#include "llvm/Support/YAMLTraits.h"
+#include 
+#include 
+
+llvm::Regex Infinity("^[-+]?(\\.inf|\\.Inf|\\.INF)$");
+llvm::Regex Base8("^0o[0-7]+$");
+llvm::Regex Base16("^0x[0-9a-fA-F]+$");
+llvm::Regex Float("^[-+]?(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
+
+inline bool isNumericRegex(llvm::StringRef S) {
+  if (S.equals(".nan") || S.equals(".NaN") || S.equals(".NAN"))
+return true;
+
+  if (Infinity.match(S))
+return true;
+
+  if (Base8.match(S))
+return true;
+
+  if (Base16.match(S))
+return true;
+
+  if (Float.match(S))
+return true;
+
+  return false;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+  std::string Input(reinterpret_cast(Data), Size);
+  if (llvm::yaml::isNumeric(Input) != isNumericRegex(Input))
+__builtin_trap();
+  return 0;
+}
Index: llvm/tools/llvm-yaml-n

[PATCH] D50703: [clangd] NFC: Mark Workspace Symbol feature complete in the documentation

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340007: [clangd] NFC: Mark Workspace Symbol feature complete 
in the documentation (authored by omtcyfz, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50703?vs=160566&id=161195#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50703

Files:
  clang-tools-extra/trunk/docs/clangd.rst


Index: clang-tools-extra/trunk/docs/clangd.rst
===
--- clang-tools-extra/trunk/docs/clangd.rst
+++ clang-tools-extra/trunk/docs/clangd.rst
@@ -64,7 +64,7 @@
 | Completion  | Yes|   Yes|
 +-++--+
 | Diagnostics | Yes|   Yes|
-+-++--+ 
++-++--+
 | Fix-its | Yes|   Yes|
 +-++--+
 | Go to Definition| Yes|   Yes|
@@ -83,7 +83,7 @@
 +-++--+
 | Document Symbols| Yes|   Yes|
 +-++--+
-| Workspace Symbols   | Yes|   No |
+| Workspace Symbols   | Yes|   Yes|
 +-++--+
 | Syntax and Semantic Coloring| No |   No |
 +-++--+


Index: clang-tools-extra/trunk/docs/clangd.rst
===
--- clang-tools-extra/trunk/docs/clangd.rst
+++ clang-tools-extra/trunk/docs/clangd.rst
@@ -64,7 +64,7 @@
 | Completion  | Yes|   Yes|
 +-++--+
 | Diagnostics | Yes|   Yes|
-+-++--+ 
++-++--+
 | Fix-its | Yes|   Yes|
 +-++--+
 | Go to Definition| Yes|   Yes|
@@ -83,7 +83,7 @@
 +-++--+
 | Document Symbols| Yes|   Yes|
 +-++--+
-| Workspace Symbols   | Yes|   No |
+| Workspace Symbols   | Yes|   Yes|
 +-++--+
 | Syntax and Semantic Coloring| No |   No |
 +-++--+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r340007 - [clangd] NFC: Mark Workspace Symbol feature complete in the documentation

2018-08-17 Thread Kirill Bobyrev via cfe-commits
Author: omtcyfz
Date: Fri Aug 17 03:14:31 2018
New Revision: 340007

URL: http://llvm.org/viewvc/llvm-project?rev=340007&view=rev
Log:
[clangd] NFC: Mark Workspace Symbol feature complete in the documentation

Workspace Symbol implementation was introduced in D44882 and should be
complete now.

Reviewed by: ioeric

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

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

Modified: clang-tools-extra/trunk/docs/clangd.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clangd.rst?rev=340007&r1=340006&r2=340007&view=diff
==
--- clang-tools-extra/trunk/docs/clangd.rst (original)
+++ clang-tools-extra/trunk/docs/clangd.rst Fri Aug 17 03:14:31 2018
@@ -64,7 +64,7 @@ extension to the protocol.
 | Completion  | Yes|   Yes|
 +-++--+
 | Diagnostics | Yes|   Yes|
-+-++--+ 
++-++--+
 | Fix-its | Yes|   Yes|
 +-++--+
 | Go to Definition| Yes|   Yes|
@@ -83,7 +83,7 @@ extension to the protocol.
 +-++--+
 | Document Symbols| Yes|   Yes|
 +-++--+
-| Workspace Symbols   | Yes|   No |
+| Workspace Symbols   | Yes|   Yes|
 +-++--+
 | Syntax and Semantic Coloring| No |   No |
 +-++--+


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


[PATCH] D50703: [clangd] NFC: Mark Workspace Symbol feature complete in the documentation

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE340007: [clangd] NFC: Mark Workspace Symbol feature 
complete in the documentation (authored by omtcyfz, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50703?vs=160566&id=161196#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50703

Files:
  docs/clangd.rst


Index: docs/clangd.rst
===
--- docs/clangd.rst
+++ docs/clangd.rst
@@ -64,7 +64,7 @@
 | Completion  | Yes|   Yes|
 +-++--+
 | Diagnostics | Yes|   Yes|
-+-++--+ 
++-++--+
 | Fix-its | Yes|   Yes|
 +-++--+
 | Go to Definition| Yes|   Yes|
@@ -83,7 +83,7 @@
 +-++--+
 | Document Symbols| Yes|   Yes|
 +-++--+
-| Workspace Symbols   | Yes|   No |
+| Workspace Symbols   | Yes|   Yes|
 +-++--+
 | Syntax and Semantic Coloring| No |   No |
 +-++--+


Index: docs/clangd.rst
===
--- docs/clangd.rst
+++ docs/clangd.rst
@@ -64,7 +64,7 @@
 | Completion  | Yes|   Yes|
 +-++--+
 | Diagnostics | Yes|   Yes|
-+-++--+ 
++-++--+
 | Fix-its | Yes|   Yes|
 +-++--+
 | Go to Definition| Yes|   Yes|
@@ -83,7 +83,7 @@
 +-++--+
 | Document Symbols| Yes|   Yes|
 +-++--+
-| Workspace Symbols   | Yes|   No |
+| Workspace Symbols   | Yes|   Yes|
 +-++--+
 | Syntax and Semantic Coloring| No |   No |
 +-++--+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50889: [clangd] Make FileIndex aware of the main file

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: hokein, ioeric.
Herald added subscribers: arphaman, jkorous, MaskRay.

It was previously only indexing the preamble decls. The new
implementation will index both the preamble and the main AST and
report both sets of symbols, preferring the ones from the main AST
whenever the symbol is present in both.
The symbols in the main AST slab always store all information
available in the preamble symbols, possibly adding more,
e.g. definition locations.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50889

Files:
  clangd/ClangdServer.cpp
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/Index.h
  clangd/index/SymbolCollector.h
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/TestTU.cpp

Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -45,7 +45,7 @@
 
 SymbolSlab TestTU::headerSymbols() const {
   auto AST = build();
-  return indexAST(AST.getASTContext(), AST.getPreprocessorPtr());
+  return indexPreambleAST(AST.getASTContext(), AST.getPreprocessorPtr());
 }
 
 std::unique_ptr TestTU::index() const {
Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -51,28 +51,28 @@
   FileSymbols FS;
   EXPECT_THAT(getSymbolNames(*FS.allSymbols()), UnorderedElementsAre());
 
-  FS.update("f1", numSlab(1, 3));
+  FS.updatePreamble("f1", numSlab(1, 3));
   EXPECT_THAT(getSymbolNames(*FS.allSymbols()),
   UnorderedElementsAre("1", "2", "3"));
 }
 
 TEST(FileSymbolsTest, Overlap) {
   FileSymbols FS;
-  FS.update("f1", numSlab(1, 3));
-  FS.update("f2", numSlab(3, 5));
+  FS.updatePreamble("f1", numSlab(1, 3));
+  FS.updatePreamble("f2", numSlab(3, 5));
   EXPECT_THAT(getSymbolNames(*FS.allSymbols()),
   UnorderedElementsAre("1", "2", "3", "3", "4", "5"));
 }
 
 TEST(FileSymbolsTest, SnapshotAliveAfterRemove) {
   FileSymbols FS;
 
-  FS.update("f1", numSlab(1, 3));
+  FS.updatePreamble("f1", numSlab(1, 3));
 
   auto Symbols = FS.allSymbols();
   EXPECT_THAT(getSymbolNames(*Symbols), UnorderedElementsAre("1", "2", "3"));
 
-  FS.update("f1", nullptr);
+  FS.updatePreamble("f1", nullptr);
   EXPECT_THAT(getSymbolNames(*FS.allSymbols()), UnorderedElementsAre());
   EXPECT_THAT(getSymbolNames(*Symbols), UnorderedElementsAre("1", "2", "3"));
 }
@@ -93,7 +93,7 @@
   File.HeaderFilename = (Basename + ".h").str();
   File.HeaderCode = Code;
   auto AST = File.build();
-  M.update(File.Filename, &AST.getASTContext(), AST.getPreprocessorPtr());
+  M.updatePreamble(File.Filename, &AST.getASTContext(), AST.getPreprocessorPtr());
 }
 
 TEST(FileIndexTest, CustomizedURIScheme) {
@@ -149,13 +149,13 @@
   Req.Scopes = {"ns::"};
   EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X"));
 
-  M.update("f1.cpp", nullptr, nullptr);
+  M.updatePreamble("f1.cpp", nullptr, nullptr);
   EXPECT_THAT(match(M, Req), UnorderedElementsAre());
 }
 
 TEST(FileIndexTest, RemoveNonExisting) {
   FileIndex M;
-  M.update("no.cpp", nullptr, nullptr);
+  M.updatePreamble("no.cpp", nullptr, nullptr);
   EXPECT_THAT(match(M, FuzzyFindRequest()), UnorderedElementsAre());
 }
 
@@ -255,7 +255,7 @@
   std::shared_ptr PP) {
 EXPECT_FALSE(IndexUpdated) << "Expected only a single index update";
 IndexUpdated = true;
-Index.update(FilePath, &Ctx, std::move(PP));
+Index.updatePreamble(FilePath, &Ctx, std::move(PP));
   });
   ASSERT_TRUE(IndexUpdated);
 
Index: clangd/index/SymbolCollector.h
===
--- clangd/index/SymbolCollector.h
+++ clangd/index/SymbolCollector.h
@@ -85,6 +85,7 @@
 SourceLocation Loc) override;
 
   SymbolSlab takeSymbols() { return std::move(Symbols).build(); }
+  SymbolSlab::Builder takeBuilder() { return std::move(Symbols); }
 
   void finish() override;
 
Index: clangd/index/Index.h
===
--- clangd/index/Index.h
+++ clangd/index/Index.h
@@ -267,6 +267,8 @@
   return I == SymbolIndex.end() ? nullptr : &Symbols[I->second];
 }
 
+llvm::ArrayRef symbols() const { return Symbols; }
+
 // Consumes the builder to finalize the slab.
 SymbolSlab build() &&;
 
Index: clangd/index/FileIndex.h
===
--- clangd/index/FileIndex.h
+++ clangd/index/FileIndex.h
@@ -41,16 +41,23 @@
 public:
   /// \brief Updates all symbols in a file. If \p Slab is nullptr, symbols for
   /// \p Path will be removed.
-  void update(PathRef Path, std::unique_ptr Slab);
+  void updatePreamble(PathRef Path, std::unique_ptr Slab);
+  void updateMainFile(PathRef Path, SymbolSlab::Builder Bu

[PATCH] D50847: [clangd] Add callbacks on parsed AST in addition to parsed preambles

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

@ioeric, specifically, see https://reviews.llvm.org/D50889 for an updated 
FileIndex


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50847



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


[PATCH] D50889: [clangd] Make FileIndex aware of the main file

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

This is still WIP, but wanted to share anyway the progress anyway.
Need to fix the FIXMEs currently added to the code and add tests.




Comment at: clangd/index/FileIndex.cpp:81
   if (!Slab)
 FileToSlabs.erase(Path);
   else

We need to be more careful here now that we have to slabs in the list. Should 
only erase when both are removed.



Comment at: clangd/index/FileIndex.cpp:87
+void FileSymbols::updateMainFile(PathRef Path, SymbolSlab::Builder Builder) {
+  // FIXME(ibiryukov): most of this work should be done outside the lock.
+  std::lock_guard Lock(Mutex);

This should definitely be done outside the lock, only the actual swap of the 
symbol tables should be there.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50889



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


Re: r339807 - Refactor Darwin driver to refer to runtimes by component

2018-08-17 Thread Hans Wennborg via cfe-commits
Just a heads up that this broke the Chromium build on Mac:
https://crbug.com/874997

Apparently we have some target that explicitly targets 10.5. I don't
know if that's really necessary, but the fact that we ran into this at
all suggests others will too, so maybe this change warrants a release
notes entry.

Thanks,
Hans

On Wed, Aug 15, 2018 at 10:09 PM, Chris Bieneman via cfe-commits
 wrote:
> Author: cbieneman
> Date: Wed Aug 15 13:09:38 2018
> New Revision: 339807
>
> URL: http://llvm.org/viewvc/llvm-project?rev=339807&view=rev
> Log:
> Refactor Darwin driver to refer to runtimes by component
>
> Summary:
> In r335809, Petr Hosek lays out support for what he calls the multiarch
> runtimes layout. This new way of laying out the directories for runtime
> libraries is workable for all platforms. Petr did some of the common
> infrastructure and made it work for Linux and Fuscia. This patch is a
> cleanup to the Darwin and MachO drivers to serve as a step toward
> supporting it in Darwin.
>
> This patch does primarily two things:
> (1) Changes the APIs for how the Darwin driver refers to compiler-rt
> libraries to use the component names, similar to how Linux and Fuscia do
>
> (2) Removes some legacy functionality for supporting macOS versions
> before 10.6. This functionality is effectively dead code because in
> r339277, the support was removed from compiler-rt for generating the 10.4
> runtime support library, and Xcode 10 (currently in beta) removes
> libgcc_s.10.4 and libgcc_s.10.5 from the macOS SDK.
>
> With this patch landed a subsequent patch can modify
> MachO::AddLinkRuntimeLib to support the multiarch runtimes layout.
>
> Worth noting: None of the removed functionality was actually covered in
> the test suite. So no test case updates are required.
>
> Reviewers: phosek, bruno, arphaman
>
> Reviewed By: phosek, arphaman
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D50618
>
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
> cfe/trunk/lib/Driver/ToolChains/Darwin.h
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=339807&r1=339806&r2=339807&view=diff
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Wed Aug 15 13:09:38 2018
> @@ -908,8 +908,17 @@ unsigned DarwinClang::GetDefaultDwarfVer
>  }
>
>  void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
> -  StringRef DarwinLibName,
> -  RuntimeLinkOptions Opts) const {
> +  StringRef Component, RuntimeLinkOptions Opts,
> +  bool IsShared) const {
> +  SmallString<64> DarwinLibName = StringRef("libclang_rt.");
> +  // an Darwin the builtins compomnent is not in the library name
> +  if (Component != "builtins") {
> +DarwinLibName += Component;
> +if (!(Opts & RLO_IsEmbedded))
> +  DarwinLibName += "_";
> +  }
> +  DarwinLibName += getOSLibraryNameSuffix();
> +  DarwinLibName += IsShared ? "_dynamic.dylib" : ".a";
>SmallString<128> Dir(getDriver().ResourceDir);
>llvm::sys::path::append(
>Dir, "lib", (Opts & RLO_IsEmbedded) ? "macho_embedded" : "darwin");
> @@ -1013,10 +1022,8 @@ void Darwin::addProfileRTLibs(const ArgL
>ArgStringList &CmdArgs) const {
>if (!needsProfileRT(Args)) return;
>
> -  AddLinkRuntimeLib(
> -  Args, CmdArgs,
> -  (Twine("libclang_rt.profile_") + getOSLibraryNameSuffix() + 
> ".a").str(),
> -  RuntimeLinkOptions(RLO_AlwaysLink | RLO_FirstLink));
> +  AddLinkRuntimeLib(Args, CmdArgs, "profile",
> +RuntimeLinkOptions(RLO_AlwaysLink | RLO_FirstLink));
>
>// If we have a symbol export directive and we're linking in the profile
>// runtime, automatically export symbols necessary to implement some of the
> @@ -1033,12 +1040,7 @@ void DarwinClang::AddLinkSanitizerLibArg
>StringRef Sanitizer,
>bool Shared) const {
>auto RLO = RuntimeLinkOptions(RLO_AlwaysLink | (Shared ? RLO_AddRPath : 
> 0U));
> -  AddLinkRuntimeLib(Args, CmdArgs,
> -(Twine("libclang_rt.") + Sanitizer + "_" +
> - getOSLibraryNameSuffix() +
> - (Shared ? "_dynamic.dylib" : ".a"))
> -.str(),
> -RLO);
> +  AddLinkRuntimeLib(Args, CmdArgs, Sanitizer, RLO, Shared);
>  }
>
>  ToolChain::RuntimeLibType DarwinClang::GetRuntimeLibType(
> @@ -1092,10 +1094,7 @@ void DarwinClang::AddLinkRuntimeLibArgs(
>  AddCXXStdlibLibArgs(Args, CmdArgs);
>}
>if (Sanitize.needsStatsRt()) {
> -StringRef OS = isTargetMacOS() ? "osx" : "iossim";
> -AddLinkRuntimeLib(Arg

[clang-tools-extra] r340009 - Fix clangd tests on older compilers

2018-08-17 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Fri Aug 17 03:40:05 2018
New Revision: 340009

URL: http://llvm.org/viewvc/llvm-project?rev=340009&view=rev
Log:
Fix clangd tests on older compilers

Old versions of gcc struggle with raw string literals inside macros.

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=340009&r1=340008&r2=340009&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri Aug 17 
03:40:05 2018
@@ -1613,22 +1613,21 @@ TEST(SignatureHelpTest, IndexDocumentati
   Foo1.Detail = &DocDetails;
   Symbol Foo2 = sym("foo", index::SymbolKind::Function, "@F@\\0#I#I#");
 
-  EXPECT_THAT(
-  signatures(R"cpp(
+  StringRef Sig0 = R"cpp(
 int foo();
 int foo(double);
 
 void test() {
   foo(^);
 }
-  )cpp",
- {Foo0})
-  .signatures,
+  )cpp";
+
+  EXPECT_THAT(
+  signatures(Sig0, {Foo0}).signatures,
   ElementsAre(AllOf(Sig("foo() -> int", {}), SigDoc("Doc from the index")),
   AllOf(Sig("foo(double) -> int", {"double"}), SigDoc("";
 
-  EXPECT_THAT(
-  signatures(R"cpp(
+  StringRef Sig1 = R"cpp(
 int foo();
 // Overriden doc from sema
 int foo(int);
@@ -1638,9 +1637,10 @@ TEST(SignatureHelpTest, IndexDocumentati
 void test() {
   foo(^);
 }
-  )cpp",
- {Foo0, Foo1, Foo2})
-  .signatures,
+  )cpp";
+
+  EXPECT_THAT(
+  signatures(Sig1, {Foo0, Foo1, Foo2}).signatures,
   ElementsAre(AllOf(Sig("foo() -> int", {}), SigDoc("Doc from the index")),
   AllOf(Sig("foo(int) -> int", {"int"}),
 SigDoc("Overriden doc from sema")),


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


[PATCH] D50337: [clangd] DexIndex implementation prototype

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 161202.
kbobyrev marked 6 inline comments as done.
kbobyrev added a comment.

Address a round of comments.


https://reviews.llvm.org/D50337

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/clangd/index/dex/DexIndex.h
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/unittests/clangd/CMakeLists.txt
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp
  clang-tools-extra/unittests/clangd/IndexTests.cpp
  clang-tools-extra/unittests/clangd/TestIndex.cpp
  clang-tools-extra/unittests/clangd/TestIndex.h

Index: clang-tools-extra/unittests/clangd/TestIndex.h
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/TestIndex.h
@@ -0,0 +1,57 @@
+//===-- IndexHelpers.h --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_INDEXTESTCOMMON_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_INDEXTESTCOMMON_H
+
+#include "index/Index.h"
+#include "index/Merge.h"
+#include "index/dex/DexIndex.h"
+#include "index/dex/Iterator.h"
+#include "index/dex/Token.h"
+#include "index/dex/Trigram.h"
+
+namespace clang {
+namespace clangd {
+
+Symbol symbol(llvm::StringRef QName);
+
+struct SlabAndPointers {
+  SymbolSlab Slab;
+  std::vector Pointers;
+};
+
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
+std::shared_ptr>
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols = nullptr);
+
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols = nullptr);
+
+std::string getQualifiedName(const Symbol &Sym);
+
+std::vector match(const SymbolIndex &I,
+   const FuzzyFindRequest &Req,
+   bool *Incomplete = nullptr);
+
+// Returns qualified names of symbols with any of IDs in the index.
+std::vector lookup(const SymbolIndex &I,
+llvm::ArrayRef IDs);
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/unittests/clangd/TestIndex.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/TestIndex.cpp
@@ -0,0 +1,89 @@
+//===-- IndexHelpers.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestIndex.h"
+
+namespace clang {
+namespace clangd {
+
+Symbol symbol(llvm::StringRef QName) {
+  Symbol Sym;
+  Sym.ID = SymbolID(QName.str());
+  size_t Pos = QName.rfind("::");
+  if (Pos == llvm::StringRef::npos) {
+Sym.Name = QName;
+Sym.Scope = "";
+  } else {
+Sym.Name = QName.substr(Pos + 2);
+Sym.Scope = QName.substr(0, Pos + 2);
+  }
+  return Sym;
+}
+
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
+std::shared_ptr>
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols) {
+  SymbolSlab::Builder Slab;
+  for (llvm::StringRef QName : QualifiedNames)
+Slab.insert(symbol(QName));
+
+  auto Storage = std::make_shared();
+  Storage->Slab = std::move(Slab).build();
+  for (const auto &Sym : Storage->Slab)
+Storage->Pointers.push_back(&Sym);
+  if (WeakSymbols)
+*WeakSymbols = Storage;
+  auto *Pointers = &Storage->Pointers;
+  return {std::move(Storage), Pointers};
+}
+
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols) {
+  std::vector Names;
+  for (int i = Begin; i <= End; i++)
+Names.push_back(std::to_string(i));
+  return generateSymbols(Names, WeakSymbols);
+}
+
+std::string getQualifiedName(const Symbol &Sym) {
+  return (Sym.Scope + Sym.Name).str();
+}
+
+std::vector match(const SymbolIndex &I,
+  

[PATCH] D50839: [llvm] Optimize YAML::isNumeric

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 161204.
kbobyrev added a comment.

Add couple tests, fix formatting issues, use `__builtin_trap()` instead of 
`assert` in fuzzer so that it's more transparent.

Also, fuzzing this unreadable version for a couple of hours suggests that it is 
valid.


https://reviews.llvm.org/D50839

Files:
  llvm/include/llvm/Support/YAMLTraits.h
  llvm/tools/llvm-yaml-numeric-parser-fuzzer/CMakeLists.txt
  llvm/tools/llvm-yaml-numeric-parser-fuzzer/DummyYAMLNumericParserFuzzer.cpp
  llvm/tools/llvm-yaml-numeric-parser-fuzzer/yaml-numeric-parser-fuzzer.cpp
  llvm/unittests/Support/YAMLIOTest.cpp

Index: llvm/unittests/Support/YAMLIOTest.cpp
===
--- llvm/unittests/Support/YAMLIOTest.cpp
+++ llvm/unittests/Support/YAMLIOTest.cpp
@@ -16,16 +16,17 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using llvm::yaml::Hex16;
+using llvm::yaml::Hex32;
+using llvm::yaml::Hex64;
+using llvm::yaml::Hex8;
 using llvm::yaml::Input;
-using llvm::yaml::Output;
 using llvm::yaml::IO;
-using llvm::yaml::MappingTraits;
+using llvm::yaml::isNumeric;
 using llvm::yaml::MappingNormalization;
+using llvm::yaml::MappingTraits;
+using llvm::yaml::Output;
 using llvm::yaml::ScalarTraits;
-using llvm::yaml::Hex8;
-using llvm::yaml::Hex16;
-using llvm::yaml::Hex32;
-using llvm::yaml::Hex64;
 using ::testing::StartsWith;
 
 
@@ -2569,3 +2570,73 @@
 TestEscaped((char const *)foobar, "\"foo\\u200Bbar\"");
   }
 }
+
+TEST(YAMLIO, Numeric) {
+  EXPECT_TRUE(isNumeric(".inf"));
+  EXPECT_TRUE(isNumeric(".INF"));
+  EXPECT_TRUE(isNumeric(".Inf"));
+  EXPECT_TRUE(isNumeric("-.inf"));
+  EXPECT_TRUE(isNumeric("+.inf"));
+
+  EXPECT_TRUE(isNumeric(".nan"));
+  EXPECT_TRUE(isNumeric(".NaN"));
+  EXPECT_TRUE(isNumeric(".NAN"));
+
+  EXPECT_TRUE(isNumeric("0"));
+  EXPECT_TRUE(isNumeric("0."));
+  EXPECT_TRUE(isNumeric("0.0"));
+  EXPECT_TRUE(isNumeric("-0.0"));
+  EXPECT_TRUE(isNumeric("+0.0"));
+
+  EXPECT_TRUE(isNumeric("12345"));
+  EXPECT_TRUE(isNumeric("012345"));
+  EXPECT_TRUE(isNumeric("+12.0"));
+  EXPECT_TRUE(isNumeric(".5"));
+  EXPECT_TRUE(isNumeric("+.5"));
+  EXPECT_TRUE(isNumeric("-1.0"));
+
+  EXPECT_TRUE(isNumeric("2.3e4"));
+  EXPECT_TRUE(isNumeric("-2E+05"));
+  EXPECT_TRUE(isNumeric("+12e03"));
+  EXPECT_TRUE(isNumeric("6.8523015e+5"));
+
+  EXPECT_TRUE(isNumeric("1.e+1"));
+  EXPECT_TRUE(isNumeric(".0e+1"));
+
+  EXPECT_TRUE(isNumeric("0x2aF3"));
+  EXPECT_TRUE(isNumeric("0o01234567"));
+
+  EXPECT_FALSE(isNumeric("not a number"));
+  EXPECT_FALSE(isNumeric("."));
+  EXPECT_FALSE(isNumeric(".e+1"));
+  EXPECT_FALSE(isNumeric(".1e"));
+  EXPECT_FALSE(isNumeric(".1e+"));
+  EXPECT_FALSE(isNumeric(".1e++1"));
+
+  EXPECT_FALSE(isNumeric("ABCD"));
+  EXPECT_FALSE(isNumeric("+0x2AF3"));
+  EXPECT_FALSE(isNumeric("-0x2AF3"));
+  EXPECT_FALSE(isNumeric("0x2AF3Z"));
+  EXPECT_FALSE(isNumeric("0o012345678"));
+  EXPECT_FALSE(isNumeric("0xZ"));
+  EXPECT_FALSE(isNumeric("-0o012345678"));
+  EXPECT_FALSE(isNumeric("03A8229434B839616A25C16B0291F77A438B"));
+
+  EXPECT_FALSE(isNumeric(""));
+  EXPECT_FALSE(isNumeric("."));
+  EXPECT_FALSE(isNumeric(".e+1"));
+  EXPECT_FALSE(isNumeric(".e+"));
+  EXPECT_FALSE(isNumeric(".e"));
+  EXPECT_FALSE(isNumeric("e1"));
+
+  // Deprecated formats: as for YAML 1.2 specification, the following are not
+  // valid numbers anymore:
+  //
+  // * Sexagecimal numbers
+  // * Decimal numbers with comma s the delimiter
+  // * "inf", "nan" without '.' prefix
+  EXPECT_FALSE(isNumeric("3:25:45"));
+  EXPECT_FALSE(isNumeric("+12,345"));
+  EXPECT_FALSE(isNumeric("-inf"));
+  EXPECT_FALSE(isNumeric("1,230.15"));
+}
Index: llvm/tools/llvm-yaml-numeric-parser-fuzzer/yaml-numeric-parser-fuzzer.cpp
===
--- /dev/null
+++ llvm/tools/llvm-yaml-numeric-parser-fuzzer/yaml-numeric-parser-fuzzer.cpp
@@ -0,0 +1,47 @@
+//===--- special-case-list-fuzzer.cpp - Fuzzer for special case lists -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Regex.h"
+#include "llvm/Support/YAMLTraits.h"
+#include 
+#include 
+
+llvm::Regex Infinity("^[-+]?(\\.inf|\\.Inf|\\.INF)$");
+llvm::Regex Base8("^0o[0-7]+$");
+llvm::Regex Base16("^0x[0-9a-fA-F]+$");
+llvm::Regex Float("^[-+]?(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
+
+inline bool isNumericRegex(llvm::StringRef S) {
+
+  if (S.equals(".nan") || S.equals(".NaN") || S.equals(".NAN"))
+return true;
+
+  if (Infinity.match(S))
+return true;
+
+  if (Base8.match(S))
+return true;
+
+  if (Base16.match(S))
+return true;
+
+  if (Float.match(S))
+return true;
+
+  return false;
+}
+
+extern "C" int LLVMFuzzerTestOneInp

[PATCH] D47196: [Time-report ](2): Recursive timers in Clang

2018-08-17 Thread Andrew V. Tischenko via Phabricator via cfe-commits
avt77 added a comment.

In https://reviews.llvm.org/D47196#1202805, @efriedma wrote:

> > :start: means the timer was started
>
> In some cases, the ChildTime is already non-zero at the "start" point; what 
> does that mean?


It means there was recursive call and this child time should be removed from 
the time of the current func (parent) otherwise it could be calculated twice.

>> ActOnFunctionDeclarator:start:._exception:
> 
> That's weird... DeclarationName::print should generally return something 
> ASCII; do you know what kind of declaration it is?

There are a lot of such names (see the attach as example.)F6964637: b.log 

BTW, I use getNameAsString() (see getFirstName). I tried getIdentifier () 
->getName() but it was broken rather often.


https://reviews.llvm.org/D47196



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like keys

2018-08-17 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

I think testcases for non-class iterator objects would be valuable.




Comment at: lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp:72-76
+  auto IteratesPointerKeysM = hasType(cxxRecordDecl(has(
+fieldDecl(hasType(hasCanonicalType(
+  pointsTo(hasCanonicalType(pointerType()))
+)))
+  )));

I'm not a matcher-expert, but here we go:

As I understand it, you're matching iterator objects that wrap a pointer to 
pointer. Would it match this case?:

```
void fill(int **IntPointerArray);

int main() {
  int *IntPointerArray[20]; // or a simple int array
  fill(IntPointerArray);

  std::sort(IntPointerArray, IntPointerArray + 20);
}
```
`int**` is an [[ 
https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator | 
RandomAccessIterator ]], but is not a `CXXRecordDecl`. As I mentioned earlier, 
it might be worth taking a look at `hasType`, and attempt to acquire 
`value_type`, as it is required for STL algorithms (it could be in a base class 
as well). `value_type` is also predefined through `std::iterator_traits` for 
pointer iterators like `int**`.


https://reviews.llvm.org/D50488



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


[PATCH] D50509: [analyzer][UninitializedObjectChecker] Refactoring p6.: Move dereferencing to a function

2018-08-17 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 161209.
Szelethus edited the summary of this revision.

https://reviews.llvm.org/D50509

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp

Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -95,6 +95,12 @@
 /// known, and thus FD can not be analyzed.
 static bool isVoidPointer(QualType T);
 
+/// Dereferences \p V and returns the value and dynamic type of the pointee, as
+/// well as wether \p FR needs to be casted back to that type. If for whatever
+/// reason dereferencing fails, returns with None.
+static llvm::Optional>
+dereference(ProgramStateRef State, const FieldRegion *FR);
+
 //===--===//
 //   Methods for FindUninitializedFields.
 //===--===//
@@ -126,67 +132,21 @@
 return false;
   }
 
-  assert(V.getAs() &&
- "At this point V must be loc::MemRegionVal!");
-  auto L = V.castAs();
-
-  // We can't reason about symbolic regions, assume its initialized.
-  // Note that this also avoids a potential infinite recursion, because
-  // constructors for list-like classes are checked without being called, and
-  // the Static Analyzer will construct a symbolic region for Node *next; or
-  // similar code snippets.
-  if (L.getRegion()->getSymbolicBase()) {
-IsAnyFieldInitialized = true;
-return false;
-  }
-
-  DynamicTypeInfo DynTInfo = getDynamicTypeInfo(State, L.getRegion());
-  if (!DynTInfo.isValid()) {
-IsAnyFieldInitialized = true;
-return false;
-  }
-
-  QualType DynT = DynTInfo.getType();
-
-  // If the static type of the field is a void pointer, we need to cast it back
-  // to the dynamic type before dereferencing.
-  bool NeedsCastBack = isVoidPointer(FR->getDecl()->getType());
-
-  if (isVoidPointer(DynT)) {
+  // At this point the pointer itself is initialized and points to a valid
+  // location, we'll now check the pointee.
+  llvm::Optional> DerefInfo = dereference(State, FR);
+  if (!DerefInfo) {
 IsAnyFieldInitialized = true;
 return false;
   }
 
-  // At this point the pointer itself is initialized and points to a valid
-  // location, we'll now check the pointee.
-  SVal DerefdV = State->getSVal(V.castAs(), DynT);
-
-  // If DerefdV is still a pointer value, we'll dereference it again (e.g.:
-  // int** -> int*).
-  while (auto Tmp = DerefdV.getAs()) {
-if (Tmp->getRegion()->getSymbolicBase()) {
-  IsAnyFieldInitialized = true;
-  return false;
-}
-
-DynTInfo = getDynamicTypeInfo(State, Tmp->getRegion());
-if (!DynTInfo.isValid()) {
-  IsAnyFieldInitialized = true;
-  return false;
-}
-
-DynT = DynTInfo.getType();
-if (isVoidPointer(DynT)) {
-  IsAnyFieldInitialized = true;
-  return false;
-}
-
-DerefdV = State->getSVal(*Tmp, DynT);
-  }
+  V = std::get<0>(*DerefInfo);
+  QualType DynT = std::get<1>(*DerefInfo);
+  bool NeedsCastBack = std::get<2>(*DerefInfo);
 
   // If FR is a pointer pointing to a non-primitive type.
   if (Optional RecordV =
-  DerefdV.getAs()) {
+  V.getAs()) {
 
 const TypedValueRegion *R = RecordV->getRegion();
 
@@ -222,7 +182,7 @@
  "must be a null, undefined, unknown or concrete pointer!");
   (void)IsPrimitive;
 
-  if (isPrimitiveUninit(DerefdV)) {
+  if (isPrimitiveUninit(V)) {
 if (NeedsCastBack)
   return addFieldToUninits(LocalChain.add(NeedsCastLocField(FR, DynT)));
 return addFieldToUninits(LocalChain.add(LocField(FR)));
@@ -244,3 +204,45 @@
   }
   return false;
 }
+
+static llvm::Optional>
+dereference(ProgramStateRef State, const FieldRegion *FR) {
+
+  DynamicTypeInfo DynTInfo;
+  QualType DynT;
+
+  // If the static type of the field is a void pointer, we need to cast it back
+  // to the dynamic type before dereferencing.
+  bool NeedsCastBack = isVoidPointer(FR->getDecl()->getType());
+
+  SVal V = State->getSVal(FR);
+  assert(V.getAs() && "V must be loc::MemRegionVal!");
+
+  // If V is multiple pointer value, we'll dereference it again (e.g.: int** ->
+  // int*).
+  while (auto Tmp = V.getAs()) {
+// We can't reason about symbolic regions, assume its initialized.
+// Note that this also avoids a potential infinite recursion, because
+// constructors for list-like classes are checked without being called, and
+// the Static Analyzer will construct a symbolic region for Node *next; or
+// similar code snippets.
+if (Tmp->getRegion()->getSymbolicBase()) {
+  return None;
+}
+
+DynTInfo = getDynamicTypeInfo(State, Tmp->ge

Re: r339807 - Refactor Darwin driver to refer to runtimes by component

2018-08-17 Thread Hans Wennborg via cfe-commits
Oh, and maybe the driver should diagnose if -mmacosx-version-min= is
set too low?

On Fri, Aug 17, 2018 at 12:38 PM, Hans Wennborg  wrote:
> Just a heads up that this broke the Chromium build on Mac:
> https://crbug.com/874997
>
> Apparently we have some target that explicitly targets 10.5. I don't
> know if that's really necessary, but the fact that we ran into this at
> all suggests others will too, so maybe this change warrants a release
> notes entry.
>
> Thanks,
> Hans
>
> On Wed, Aug 15, 2018 at 10:09 PM, Chris Bieneman via cfe-commits
>  wrote:
>> Author: cbieneman
>> Date: Wed Aug 15 13:09:38 2018
>> New Revision: 339807
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=339807&view=rev
>> Log:
>> Refactor Darwin driver to refer to runtimes by component
>>
>> Summary:
>> In r335809, Petr Hosek lays out support for what he calls the multiarch
>> runtimes layout. This new way of laying out the directories for runtime
>> libraries is workable for all platforms. Petr did some of the common
>> infrastructure and made it work for Linux and Fuscia. This patch is a
>> cleanup to the Darwin and MachO drivers to serve as a step toward
>> supporting it in Darwin.
>>
>> This patch does primarily two things:
>> (1) Changes the APIs for how the Darwin driver refers to compiler-rt
>> libraries to use the component names, similar to how Linux and Fuscia do
>>
>> (2) Removes some legacy functionality for supporting macOS versions
>> before 10.6. This functionality is effectively dead code because in
>> r339277, the support was removed from compiler-rt for generating the 10.4
>> runtime support library, and Xcode 10 (currently in beta) removes
>> libgcc_s.10.4 and libgcc_s.10.5 from the macOS SDK.
>>
>> With this patch landed a subsequent patch can modify
>> MachO::AddLinkRuntimeLib to support the multiarch runtimes layout.
>>
>> Worth noting: None of the removed functionality was actually covered in
>> the test suite. So no test case updates are required.
>>
>> Reviewers: phosek, bruno, arphaman
>>
>> Reviewed By: phosek, arphaman
>>
>> Subscribers: cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D50618
>>
>> Modified:
>> cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
>> cfe/trunk/lib/Driver/ToolChains/Darwin.h
>>
>> Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=339807&r1=339806&r2=339807&view=diff
>> ==
>> --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
>> +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Wed Aug 15 13:09:38 2018
>> @@ -908,8 +908,17 @@ unsigned DarwinClang::GetDefaultDwarfVer
>>  }
>>
>>  void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
>> -  StringRef DarwinLibName,
>> -  RuntimeLinkOptions Opts) const {
>> +  StringRef Component, RuntimeLinkOptions Opts,
>> +  bool IsShared) const {
>> +  SmallString<64> DarwinLibName = StringRef("libclang_rt.");
>> +  // an Darwin the builtins compomnent is not in the library name
>> +  if (Component != "builtins") {
>> +DarwinLibName += Component;
>> +if (!(Opts & RLO_IsEmbedded))
>> +  DarwinLibName += "_";
>> +  }
>> +  DarwinLibName += getOSLibraryNameSuffix();
>> +  DarwinLibName += IsShared ? "_dynamic.dylib" : ".a";
>>SmallString<128> Dir(getDriver().ResourceDir);
>>llvm::sys::path::append(
>>Dir, "lib", (Opts & RLO_IsEmbedded) ? "macho_embedded" : "darwin");
>> @@ -1013,10 +1022,8 @@ void Darwin::addProfileRTLibs(const ArgL
>>ArgStringList &CmdArgs) const {
>>if (!needsProfileRT(Args)) return;
>>
>> -  AddLinkRuntimeLib(
>> -  Args, CmdArgs,
>> -  (Twine("libclang_rt.profile_") + getOSLibraryNameSuffix() + 
>> ".a").str(),
>> -  RuntimeLinkOptions(RLO_AlwaysLink | RLO_FirstLink));
>> +  AddLinkRuntimeLib(Args, CmdArgs, "profile",
>> +RuntimeLinkOptions(RLO_AlwaysLink | RLO_FirstLink));
>>
>>// If we have a symbol export directive and we're linking in the profile
>>// runtime, automatically export symbols necessary to implement some of 
>> the
>> @@ -1033,12 +1040,7 @@ void DarwinClang::AddLinkSanitizerLibArg
>>StringRef Sanitizer,
>>bool Shared) const {
>>auto RLO = RuntimeLinkOptions(RLO_AlwaysLink | (Shared ? RLO_AddRPath : 
>> 0U));
>> -  AddLinkRuntimeLib(Args, CmdArgs,
>> -(Twine("libclang_rt.") + Sanitizer + "_" +
>> - getOSLibraryNameSuffix() +
>> - (Shared ? "_dynamic.dylib" : ".a"))
>> -.str(),
>> -RLO);
>> +  AddLinkRuntimeLib(Args, CmdArgs, Sanitizer, RLO, Shared);
>>  }
>>
>>  ToolChain::RuntimeLibType Darwi

[PATCH] D50889: [clangd] Make FileIndex aware of the main file

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov planned changes to this revision.
ilya-biryukov added a comment.

As discussed offline, we could instead have a two-layer scheme for dynamic 
index. A top layer will contain main file symbols, second layer will contain 
preamble symbols.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50889



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


[PATCH] D50847: [clangd] Add callbacks on parsed AST in addition to parsed preambles

2018-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks for adding it.




Comment at: clangd/TUScheduler.cpp:406
 // We only need to build the AST if diagnostics were requested.
 if (WantDiags == WantDiagnostics::No)
   return;

The AST might not get built if `WantDiags::No`, and will be built in 
`runWithAST`.



Comment at: clangd/TUScheduler.h:66
+  /// instead.
+  virtual void onMainAST(PathRef Path, ParsedAST &AST) = 0;
+};

Does the callback get called every time we built an AST? clangd only has 3 idle 
ASTs, if the AST is not there, we rebuild it when needed (even the source code 
is not changed), and we will update the dynamic index, which seems unnecessary.

It may rarely happen, 3 idle ASTs  might cover most cases, I think? 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50847



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


[PATCH] D50892: [analyzer][UninitializedObjectChecker] Correct dynamic type is acquired for record pointees

2018-08-17 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: george.karpenkov, NoQ, xazax.hun, rnkovacs.
Herald added subscribers: cfe-commits, mikhail.ramalho, a.sidorin, szepet, 
whisperity.

Repository:
  rC Clang

https://reviews.llvm.org/D50892

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
  test/Analysis/cxx-uninitialized-object-inheritance.cpp


Index: test/Analysis/cxx-uninitialized-object-inheritance.cpp
===
--- test/Analysis/cxx-uninitialized-object-inheritance.cpp
+++ test/Analysis/cxx-uninitialized-object-inheritance.cpp
@@ -781,21 +781,40 @@
 // Dynamic type test.
 
//===--===//
 
-struct DynTBase {};
-struct DynTDerived : DynTBase {
+struct DynTBase1 {};
+struct DynTDerived1 : DynTBase1 {
   // TODO: we'd expect the note: {{uninitialized field 'this->x'}}
   int x; // no-note
 };
 
-struct DynamicTypeTest {
-  DynTBase *bptr;
+struct DynamicTypeTest1 {
+  DynTBase1 *bptr;
   int i = 0;
 
   // TODO: we'd expect the warning: {{1 uninitialized field}}
-  DynamicTypeTest(DynTBase *bptr) : bptr(bptr) {} // no-warning
+  DynamicTypeTest1(DynTBase1 *bptr) : bptr(bptr) {} // no-warning
 };
 
-void f() {
-  DynTDerived d;
-  DynamicTypeTest t(&d);
+void fDynamicTypeTest1() {
+  DynTDerived1 d;
+  DynamicTypeTest1 t(&d);
 };
+
+struct DynTBase2 {
+  int x; // expected-note{{uninitialized field 'this->bptr->x'}}
+};
+struct DynTDerived2 : DynTBase2 {
+  int y; // expected-note{{uninitialized field 'this->bptr->y'}}
+};
+
+struct DynamicTypeTest2 {
+  DynTBase2 *bptr;
+  int i = 0;
+
+  DynamicTypeTest2(DynTBase2 *bptr) : bptr(bptr) {} // expected-warning{{2 
uninitialized fields}}
+};
+
+void fDynamicTypeTest2() {
+  DynTDerived2 d;
+  DynamicTypeTest2 t(&d);
+}
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -190,6 +190,10 @@
 
 const TypedValueRegion *R = RecordV->getRegion();
 
+while (R->getAs()) {
+  R = R->getSuperRegion()->getAs();
+}
+
 if (DynT->getPointeeType()->isStructureOrClassType()) {
   if (NeedsCastBack)
 return isNonUnionUninit(R, LocalChain.add(NeedsCastLocField(FR, 
DynT)));


Index: test/Analysis/cxx-uninitialized-object-inheritance.cpp
===
--- test/Analysis/cxx-uninitialized-object-inheritance.cpp
+++ test/Analysis/cxx-uninitialized-object-inheritance.cpp
@@ -781,21 +781,40 @@
 // Dynamic type test.
 //===--===//
 
-struct DynTBase {};
-struct DynTDerived : DynTBase {
+struct DynTBase1 {};
+struct DynTDerived1 : DynTBase1 {
   // TODO: we'd expect the note: {{uninitialized field 'this->x'}}
   int x; // no-note
 };
 
-struct DynamicTypeTest {
-  DynTBase *bptr;
+struct DynamicTypeTest1 {
+  DynTBase1 *bptr;
   int i = 0;
 
   // TODO: we'd expect the warning: {{1 uninitialized field}}
-  DynamicTypeTest(DynTBase *bptr) : bptr(bptr) {} // no-warning
+  DynamicTypeTest1(DynTBase1 *bptr) : bptr(bptr) {} // no-warning
 };
 
-void f() {
-  DynTDerived d;
-  DynamicTypeTest t(&d);
+void fDynamicTypeTest1() {
+  DynTDerived1 d;
+  DynamicTypeTest1 t(&d);
 };
+
+struct DynTBase2 {
+  int x; // expected-note{{uninitialized field 'this->bptr->x'}}
+};
+struct DynTDerived2 : DynTBase2 {
+  int y; // expected-note{{uninitialized field 'this->bptr->y'}}
+};
+
+struct DynamicTypeTest2 {
+  DynTBase2 *bptr;
+  int i = 0;
+
+  DynamicTypeTest2(DynTBase2 *bptr) : bptr(bptr) {} // expected-warning{{2 uninitialized fields}}
+};
+
+void fDynamicTypeTest2() {
+  DynTDerived2 d;
+  DynamicTypeTest2 t(&d);
+}
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -190,6 +190,10 @@
 
 const TypedValueRegion *R = RecordV->getRegion();
 
+while (R->getAs()) {
+  R = R->getSuperRegion()->getAs();
+}
+
 if (DynT->getPointeeType()->isStructureOrClassType()) {
   if (NeedsCastBack)
 return isNonUnionUninit(R, LocalChain.add(NeedsCastLocField(FR, DynT)));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50892: [analyzer][UninitializedObjectChecker] Correct dynamic type is acquired for record pointees

2018-08-17 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: test/Analysis/cxx-uninitialized-object-inheritance.cpp:787
   // TODO: we'd expect the note: {{uninitialized field 'this->x'}}
   int x; // no-note
 };

The checker should be able to catch this one -- for some reason it is regarded 
as an unknown region. Odd, as the test case right after this one works 
perfectly.


Repository:
  rC Clang

https://reviews.llvm.org/D50892



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


[PATCH] D50462: Try building complete AST after a fatal error was emitted if further diagnostics are expected

2018-08-17 Thread Dmitry via Phabricator via cfe-commits
Dmitry.Kozhevnikov added a comment.

In https://reviews.llvm.org/D50462#1203038, @vsapsai wrote:

> Have you checked that produced AST is of sufficient quality to be used? 
> Because, for example, for invalid code error recovery tries to keep going but 
> the end result isn't always good.
>  In the test you verify that you can ignore bogus includes. Is this the 
> real-world use case you want to address? Or something like "stddef.h not 
> found"?


I'm assuming it should help when the recovery is good enough (e.g. when the 
symbols from the missing header are used rarely, or only used inside function 
bodies). For the case like "`stddef.h` not found" there is a chance that 
resulting AST wouldn't be too useful, however, for IDE-like tasks, where we 
usually want to get as much info from the incomplete code as possible, it's not 
too bad IMO (comparing to just disabling all IDE features altogether after a 
missing include).

The only required property is that the resulting issues shouldn't be 
catastrophic (further processing shouldn't crash or hang), however, it would be 
a separate issue - after all, you always can remove the include directive in 
question.

The main use case I have is that it's inconvenient to browse or edit code in 
clang-based IDEs when either:

- there is a typo in an include directive somewhere (e.g. because I'm still 
modifying the code, moving files around, etc)
- there is a missing/misconfigured 3rd-party dependency. Obviously, the code is 
not supposed to compile, however, I'd expect e.g. "Goto Declaration" still work 
for unrelated code, assuming it recovered properly, which, in my anecdotical 
experience, it usually does
- (a very specific use case I'm often hitting) you often have missing includes 
when you browse llvm/clang code base and haven't built some part of it, so you 
don't have generated headers. The parser usually recovers very well in this 
case, if not for these two cut-offs I'm changing in this patch


Repository:
  rC Clang

https://reviews.llvm.org/D50462



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


[PATCH] D48027: [analyzer] Improve `CallDescription` to handle c++ method.

2018-08-17 Thread Henry Wong via Phabricator via cfe-commits
MTC updated this revision to Diff 161217.
MTC added a comment.

- rebase
- Since we have enhanced the ability of `CallDescription`, remove the helper 
method `isCalledOnStringObject()`.


https://reviews.llvm.org/D48027

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
  lib/StaticAnalyzer/Core/CallEvent.cpp

Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -359,11 +359,38 @@
 return false;
   if (!CD.IsLookupDone) {
 CD.IsLookupDone = true;
-CD.II = &getState()->getStateManager().getContext().Idents.get(CD.FuncName);
+CD.II = &getState()->getStateManager().getContext().Idents.get(
+CD.getFunctionName());
   }
   const IdentifierInfo *II = getCalleeIdentifier();
   if (!II || II != CD.II)
 return false;
+
+  const Decl *D = getDecl();
+  // If CallDescription provides prefix names, use them to improve matching
+  // accuracy.
+  if (CD.QualifiedName.size() > 1 && D) {
+const DeclContext *Ctx = D->getDeclContext();
+std::vector QualifiedName = CD.QualifiedName;
+QualifiedName.pop_back();
+for (; Ctx && isa(Ctx); Ctx = Ctx->getParent()) {
+  if (const auto *ND = dyn_cast(Ctx)) {
+if (!QualifiedName.empty() && ND->getName() == QualifiedName.back())
+  QualifiedName.pop_back();
+continue;
+  }
+
+  if (const auto *RD = dyn_cast(Ctx)) {
+if (!QualifiedName.empty() && RD->getName() == QualifiedName.back())
+  QualifiedName.pop_back();
+continue;
+  }
+}
+
+if (!QualifiedName.empty())
+  return false;
+  }
+
   return (CD.RequiredArgs == CallDescription::NoArgRequirement ||
   CD.RequiredArgs == getNumArgs());
 }
Index: lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
+++ lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
@@ -86,14 +86,20 @@
   };
 
   InnerPointerChecker()
-  : AppendFn("append"), AssignFn("assign"), ClearFn("clear"),
-CStrFn("c_str"), DataFn("data"), EraseFn("erase"), InsertFn("insert"),
-PopBackFn("pop_back"), PushBackFn("push_back"), ReplaceFn("replace"),
-ReserveFn("reserve"), ResizeFn("resize"),
-ShrinkToFitFn("shrink_to_fit"), SwapFn("swap") {}
-
-  /// Check if the object of this member function call is a `basic_string`.
-  bool isCalledOnStringObject(const CXXInstanceCall *ICall) const;
+  : AppendFn({"std", "basic_string", "append"}),
+AssignFn({"std", "basic_string", "assign"}),
+ClearFn({"std", "basic_string", "clear"}),
+CStrFn({"std", "basic_string", "c_str"}),
+DataFn({"std", "basic_string", "data"}),
+EraseFn({"std", "basic_string", "erase"}),
+InsertFn({"std", "basic_string", "insert"}),
+PopBackFn({"std", "basic_string", "pop_back"}),
+PushBackFn({"std", "basic_string", "push_back"}),
+ReplaceFn({"std", "basic_string", "replace"}),
+ReserveFn({"std", "basic_string", "reserve"}),
+ResizeFn({"std", "basic_string", "resize"}),
+ShrinkToFitFn({"std", "basic_string", "shrink_to_fit"}),
+SwapFn({"std", "basic_string", "swap"}) {}
 
   /// Check whether the called member function potentially invalidates
   /// pointers referring to the container object's inner buffer.
@@ -122,21 +128,6 @@
 
 } // end anonymous namespace
 
-bool InnerPointerChecker::isCalledOnStringObject(
-const CXXInstanceCall *ICall) const {
-  const auto *ObjRegion =
-dyn_cast_or_null(ICall->getCXXThisVal().getAsRegion());
-  if (!ObjRegion)
-return false;
-
-  QualType ObjTy = ObjRegion->getValueType();
-  if (ObjTy.isNull())
-return false;
-
-  CXXRecordDecl *Decl = ObjTy->getAsCXXRecordDecl();
-  return Decl && Decl->getName() == "basic_string";
-}
-
 bool InnerPointerChecker::isInvalidatingMemberFunction(
 const CallEvent &Call) const {
   if (const auto *MemOpCall = dyn_cast(&Call)) {
@@ -220,33 +211,31 @@
   ProgramStateRef State = C.getState();
 
   if (const auto *ICall = dyn_cast(&Call)) {
-if (isCalledOnStringObject(ICall)) {
-  const auto *ObjRegion = dyn_cast_or_null(
-  ICall->getCXXThisVal().getAsRegion());
-
-  if (Call.isCalled(CStrFn) || Call.isCalled(DataFn)) {
-SVal RawPtr = Call.getReturnValue();
-if (SymbolRef Sym = RawPtr.getAsSymbol(/*IncludeBaseRegions=*/true)) {
-  // Start tracking this raw pointer by adding it to the set of symbols
-  // associated with this container object in the program state map.
-
-  PtrSet::Factory &F = State->getStateManager().get_context();
-  const PtrSet *SetPtr = State->get(ObjRegion);
-  PtrSet Set = SetPtr ? *SetPtr : F.getEmptySet();
- 

[PATCH] D49793: [AArch64] - return address signing

2018-08-17 Thread Oliver Stannard via Phabricator via cfe-commits
olista01 accepted this revision.
olista01 added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


https://reviews.llvm.org/D49793



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


[PATCH] D48027: [analyzer] Improve `CallDescription` to handle c++ method.

2018-08-17 Thread Henry Wong via Phabricator via cfe-commits
MTC added a comment.

In https://reviews.llvm.org/D48027#1201248, @xazax.hun wrote:

> Generally looks good, I only wonder if this works well with inline 
> namespaces. Could you test? Probably it will.


Thank you for reminding me! Yea, this can handle inline namespaces.

However this approach has limit. Given the code below, we cannot distinguish 
whether the `basic_string` is user-defined struct or namespace. That's means 
when the user provide {"std", "basic_string", "append"}, we can only know the 
qualified name of the call sequentially contains `std`, `basic_string`, 
`append`. We don't know if these names come from `RecordDecl` or 
`NamespaceDecl`.

  namespace  std {
namespace basic_string {
  struct A {
void append() {}
  };
}
  }
  
  void foo() {
std::basic_string::A a;
a.append(); // Match
  }

@rnkovacs What do you think? Can this approach meet `InnerPointerChecker`'s 
needs?


https://reviews.llvm.org/D48027



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


[PATCH] D49793: [AArch64] - return address signing

2018-08-17 Thread Luke Cheeseman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340018: [AArch64] - Generate pointer authentication 
instructions (authored by LukeCheeseman, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49793?vs=158491&id=161220#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49793

Files:
  llvm/trunk/lib/Target/AArch64/AArch64FrameLowering.cpp
  llvm/trunk/test/CodeGen/AArch64/sign-return-address.ll

Index: llvm/trunk/test/CodeGen/AArch64/sign-return-address.ll
===
--- llvm/trunk/test/CodeGen/AArch64/sign-return-address.ll
+++ llvm/trunk/test/CodeGen/AArch64/sign-return-address.ll
@@ -0,0 +1,86 @@
+; RUN: llc -mtriple=aarch64-none-eabi < %s | FileCheck %s
+
+; CHECK-LABEL: @leaf
+; CHECK-NOT: paci{{[a,b]}}sp
+; CHECK-NOT: auti{{[a,b]}}sp
+define i32 @leaf(i32 %x) {
+  ret i32 %x
+}
+
+; CHECK-LABEL: @leaf_sign_none
+; CHECK-NOT: paci{{[a,b]}}sp
+; CHECK-NOT: auti{{[a,b]}}sp
+define i32 @leaf_sign_none(i32 %x) "sign-return-address"="none"  {
+  ret i32 %x
+}
+
+; CHECK-LABEL: @leaf_sign_non_leaf
+; CHECK-NOT: paci{{[a,b]}}sp
+; CHECK-NOT: auti{{[a,b]}}sp
+define i32 @leaf_sign_non_leaf(i32 %x) "sign-return-address"="non-leaf"  {
+  ret i32 %x
+}
+
+; CHECK-LABEL: @leaf_sign_all
+; CHECK: paciasp
+; CHECK: autiasp
+; CHECK-NEXT: ret
+define i32 @leaf_sign_all(i32 %x) "sign-return-address"="all" {
+  ret i32 %x
+}
+
+; CHECK: @leaf_clobbers_lr
+; CHECK: paciasp
+; CHECK-NEXT: str x30, [sp, #-16]!
+; CHECK: ldr  x30, [sp], #16
+; CHECK-NEXT: autiasp
+; CHECK-NEXT: ret
+define i64 @leaf_clobbers_lr(i64 %x) "sign-return-address"="non-leaf"  {
+  call void asm sideeffect "mov x30, $0", "r,~{lr}"(i64 %x) #1
+  ret i64 %x
+}
+
+declare i32 @foo(i32)
+
+; CHECK: @non_leaf_sign_all
+; CHECK: paciasp
+; CHECK: autiasp
+; CHECK-NEXT: ret
+define i32 @non_leaf_sign_all(i32 %x) "sign-return-address"="all" {
+  %call = call i32 @foo(i32 %x)
+  ret i32 %call
+}
+
+; CHECK: @non_leaf_sign_non_leaf
+; CHECK: paciasp
+; CHECK-NEXT: str x30, [sp, #-16]!
+; CHECK: ldr  x30, [sp], #16
+; CHECK-NEXT: autiasp
+; CHECK-NEXT: ret
+define i32 @non_leaf_sign_non_leaf(i32 %x) "sign-return-address"="non-leaf"  {
+  %call = call i32 @foo(i32 %x)
+  ret i32 %call
+}
+
+; CHECK-LABEL: @leaf_sign_all_v83
+; CHECK: paciasp
+; CHECK-NOT: ret
+; CHECK-NEXT: retaa
+; CHECK-NOT: ret
+define i32 @leaf_sign_all_v83(i32 %x) "sign-return-address"="all" "target-features"="+v8.3a" {
+  ret i32 %x
+}
+
+declare fastcc i64 @bar(i64)
+
+; CHECK-LABEL: @spill_lr_and_tail_call
+; CHECK: paciasp
+; CHECK-NEXT: str x30, [sp, #-16]!
+; CHECK: ldr  x30, [sp], #16
+; CHECK-NEXT: autiasp
+; CHECK-NEXT: b  bar
+define fastcc void @spill_lr_and_tail_call(i64 %x) "sign-return-address"="all" {
+  call void asm sideeffect "mov x30, $0", "r,~{lr}"(i64 %x) #1
+  tail call fastcc i64 @bar(i64 %x)
+  ret void
+}
Index: llvm/trunk/lib/Target/AArch64/AArch64FrameLowering.cpp
===
--- llvm/trunk/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ llvm/trunk/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -98,6 +98,7 @@
 #include "AArch64Subtarget.h"
 #include "AArch64TargetMachine.h"
 #include "MCTargetDesc/AArch64AddressingModes.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/CodeGen/LivePhysRegs.h"
@@ -279,6 +280,31 @@
   return MBB.erase(I);
 }
 
+static bool ShouldSignReturnAddress(MachineFunction &MF) {
+  // The function should be signed in the following situations:
+  // - sign-return-address=all
+  // - sign-return-address=non-leaf and the functions spills the LR
+
+  const Function &F = MF.getFunction();
+  if (!F.hasFnAttribute("sign-return-address"))
+return false;
+
+  StringRef Scope = F.getFnAttribute("sign-return-address").getValueAsString();
+  if (Scope.equals("none"))
+return false;
+
+  if (Scope.equals("all"))
+return true;
+
+  assert(Scope.equals("non-leaf") && "Expected all, none or non-leaf");
+
+  for (const auto &Info : MF.getFrameInfo().getCalleeSavedInfo())
+if (Info.getReg() == AArch64::LR)
+  return true;
+
+  return false;
+}
+
 void AArch64FrameLowering::emitCalleeSavedFrameMoves(
 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) const {
   MachineFunction &MF = *MBB.getParent();
@@ -568,6 +594,11 @@
   // to determine the end of the prologue.
   DebugLoc DL;
 
+  if (ShouldSignReturnAddress(MF)) {
+BuildMI(MBB, MBBI, DL, TII->get(AArch64::PACIASP))
+.setMIFlag(MachineInstr::FrameSetup);
+  }
+
   // All calls are tail calls in GHC calling conv, and functions have no
   // prologue/epilogue.
   if (MF.getFunction().getCallingConv() == CallingConv::GHC)
@@ -832,6 +863,32 @@
   }
 }
 
+static void InsertReturnAddressAuth(MachineFunction &MF,
+MachineBasicBlock &MBB) {
+  if

[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D50845#1202973, @ABataev wrote:

> > So ideally I think Clang should determine which functions are really 
> > `declare target` (either explicit or implicit) and only run semantical 
> > analysis on them. If a function is then found to be "broken" it's perfectly 
> > desirable to error back to the user.
>
> It is not possible for OpenMP because we support implicit declare target 
> functions. Clang cannot identify whether the function is going to be used on 
> the device or not during sema analysis.


You are right, we can't do this during device compilation because we don't have 
an AST before Sema.

However I'm currently thinking about the following:

1. Identify explicit and implicit `declare target` functions during host Sema 
and CodeGen.
2. Attach meta-data for all of them to LLVM IR `.bc` which is passed via  
`-fopenmp-host-ir-file-path`. I think we already do something similar for 
outlined `target` regions?
3. During device Sema query that meta-data so Clang knows when a function will 
be called from within a `target` region. Skip analysis of functions that are 
not needed for the device, just as CUDA does.
4. Check that we don't need functions that weren't marked in 2. That's to catch 
users doing something like:

  #pragma omp target
  {
  #ifdef __NVPTX__
target_func()
  #endif
  }

For now that's just an idea, I didn't start implementing any of this yet. Do 
you think that could work?


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


r340019 - [AArch64] - return address signing

2018-08-17 Thread Luke Cheeseman via cfe-commits
Author: lukecheeseman
Date: Fri Aug 17 05:55:05 2018
New Revision: 340019

URL: http://llvm.org/viewvc/llvm-project?rev=340019&view=rev
Log:
[AArch64] - return address signing

- Add a command line options -msign-return-address to enable return address
  signing
- Armv8.3a added instructions to sign the return address to help mitigate
  against ROP attacks
- This patch adds command line options to generate function attributes that
  signal to the back whether return address signing instructions should be
  added

Differential revision: https://reviews.llvm.org/D49793


Added:
cfe/trunk/test/CodeGen/aarch64-sign-return-address.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=340019&r1=340018&r2=340019&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Aug 17 05:55:05 2018
@@ -2030,6 +2030,10 @@ def ffixed_x18 : Flag<["-"], "ffixed-x18
 def ffixed_x20 : Flag<["-"], "ffixed-x20">, Group,
   HelpText<"Reserve the x20 register (AArch64 only)">;
 
+def msign_return_address : Joined<["-"], "msign-return-address=">,
+  Flags<[CC1Option]>, Group,
+  HelpText<"Select return address signing scope">, Values<"none,all,non-leaf">;
+
 def msimd128 : Flag<["-"], "msimd128">, Group;
 def mno_simd128 : Flag<["-"], "mno-simd128">, Group;
 def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, 
Group;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=340019&r1=340018&r2=340019&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Fri Aug 17 05:55:05 2018
@@ -339,6 +339,7 @@ CODEGENOPT(ForceEmitVTables, 1, 0)
 /// Whether to emit an address-significance table into the object file.
 CODEGENOPT(Addrsig, 1, 0)
 
+ENUM_CODEGENOPT(SignReturnAddress, SignReturnAddressScope, 2, None)
 
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=340019&r1=340018&r2=340019&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Fri Aug 17 05:55:05 2018
@@ -108,6 +108,12 @@ public:
 Embed_Marker// Embed a marker as a placeholder for bitcode.
   };
 
+  enum SignReturnAddressScope {
+None,// No signing for any function
+NonLeaf, // Sign the return address of functions that spill LR
+All  // Sign the return address of all functions
+  };
+
   /// The code model to use (-mcmodel).
   std::string CodeModel;
 

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=340019&r1=340018&r2=340019&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Fri Aug 17 05:55:05 2018
@@ -4969,6 +4969,23 @@ public:
   }
 
   bool doesReturnSlotInterfereWithArgs() const override { return false; }
+
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &CGM) const override {
+const FunctionDecl *FD = dyn_cast_or_null(D);
+if (!FD)
+  return;
+llvm::Function *Fn = cast(GV);
+
+auto Kind = CGM.getCodeGenOpts().getSignReturnAddress();
+if (Kind == CodeGenOptions::SignReturnAddressScope::None)
+  return;
+
+Fn->addFnAttr("sign-return-address",
+  Kind == CodeGenOptions::SignReturnAddressScope::All
+  ? "all"
+  : "non-leaf");
+  }
 };
 
 class WindowsAArch64TargetCodeGenInfo : public AArch64TargetCodeGenInfo {

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=340019&r1=340018&r2=340019&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Aug 17 05:55:05 2018
@@ -1455,6 +1455,11 @@ void Clang::AddAArch64TargetArgs(const A
 else
   CmdArgs.push_back("-aarch64

[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In https://reviews.llvm.org/D50845#1203961, @Hahnfeld wrote:

> In https://reviews.llvm.org/D50845#1202973, @ABataev wrote:
>
> > > So ideally I think Clang should determine which functions are really 
> > > `declare target` (either explicit or implicit) and only run semantical 
> > > analysis on them. If a function is then found to be "broken" it's 
> > > perfectly desirable to error back to the user.
> >
> > It is not possible for OpenMP because we support implicit declare target 
> > functions. Clang cannot identify whether the function is going to be used 
> > on the device or not during sema analysis.
>
>
> You are right, we can't do this during device compilation because we don't 
> have an AST before Sema.
>
> However I'm currently thinking about the following:
>
> 1. Identify explicit and implicit `declare target` functions during host Sema 
> and CodeGen.
> 2. Attach meta-data for all of them to LLVM IR `.bc` which is passed via  
> `-fopenmp-host-ir-file-path`. I think we already do something similar for 
> outlined `target` regions?
> 3. During device Sema query that meta-data so Clang knows when a function 
> will be called from within a `target` region. Skip analysis of functions that 
> are not needed for the device, just as CUDA does.
> 4. Check that we don't need functions that weren't marked in 2. That's to 
> catch users doing something like: ```lang=c #pragma omp target { #ifdef 
> __NVPTX__ target_func() #endif } ```
>
>   For now that's just an idea, I didn't start implementing any of this yet. 
> Do you think that could work?


I thought about this approach already. But it won't work in general. The main 
problem here is that host and device compilation phases may end up with the 
different set of implicit declare target functions. The main problem here not 
the user code, but the system libraries, which may use the different set of 
functions.
Another one problem here is that the user may use the function that has some 
host assembler inside. In this case we still need to emit error message, 
otherwise, we may end up with the compiler crash.

The best solution is to use only device specific header files. Device 
compilation phase should use system header files for the host at all.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


r340021 - [ThinLTO] Correct documentation on default number of threads

2018-08-17 Thread Teresa Johnson via cfe-commits
Author: tejohnson
Date: Fri Aug 17 06:19:36 2018
New Revision: 340021

URL: http://llvm.org/viewvc/llvm-project?rev=340021&view=rev
Log:
[ThinLTO] Correct documentation on default number of threads

Summary:
The number of threads used for ThinLTO backend parallelism was
dropped to the number of cores in r284618 to avoid oversubscribing
physical cores due to hyperthreading. This updates the documentation
to reflect that change.

Fixes PR38610.

Reviewers: pcc

Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, cfe-commits

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

Modified:
cfe/trunk/docs/ThinLTO.rst

Modified: cfe/trunk/docs/ThinLTO.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ThinLTO.rst?rev=340021&r1=340020&r2=340021&view=diff
==
--- cfe/trunk/docs/ThinLTO.rst (original)
+++ cfe/trunk/docs/ThinLTO.rst Fri Aug 17 06:19:36 2018
@@ -105,7 +105,9 @@ Controlling Backend Parallelism
 ---
 .. _parallelism:
 
-By default, the ThinLTO link step will launch up to
+By default, the ThinLTO link step will launch as many
+threads in parallel as there are cores. If the number of
+cores can't be computed for the architecture, then it will launch
 ``std::thread::hardware_concurrency`` number of threads in parallel.
 For machines with hyper-threading, this is the total number of
 virtual cores. For some applications and machine configurations this


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


[PATCH] D50882: [ThinLTO] Correct documentation on default number of threads

2018-08-17 Thread Teresa Johnson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC340021: [ThinLTO] Correct documentation on default number of 
threads (authored by tejohnson, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50882?vs=161161&id=161223#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50882

Files:
  docs/ThinLTO.rst


Index: docs/ThinLTO.rst
===
--- docs/ThinLTO.rst
+++ docs/ThinLTO.rst
@@ -105,7 +105,9 @@
 ---
 .. _parallelism:
 
-By default, the ThinLTO link step will launch up to
+By default, the ThinLTO link step will launch as many
+threads in parallel as there are cores. If the number of
+cores can't be computed for the architecture, then it will launch
 ``std::thread::hardware_concurrency`` number of threads in parallel.
 For machines with hyper-threading, this is the total number of
 virtual cores. For some applications and machine configurations this


Index: docs/ThinLTO.rst
===
--- docs/ThinLTO.rst
+++ docs/ThinLTO.rst
@@ -105,7 +105,9 @@
 ---
 .. _parallelism:
 
-By default, the ThinLTO link step will launch up to
+By default, the ThinLTO link step will launch as many
+threads in parallel as there are cores. If the number of
+cores can't be computed for the architecture, then it will launch
 ``std::thread::hardware_concurrency`` number of threads in parallel.
 For machines with hyper-threading, this is the total number of
 virtual cores. For some applications and machine configurations this
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D50845#1203967, @ABataev wrote:

> In https://reviews.llvm.org/D50845#1203961, @Hahnfeld wrote:
>
> > In https://reviews.llvm.org/D50845#1202973, @ABataev wrote:
> >
> > > > So ideally I think Clang should determine which functions are really 
> > > > `declare target` (either explicit or implicit) and only run semantical 
> > > > analysis on them. If a function is then found to be "broken" it's 
> > > > perfectly desirable to error back to the user.
> > >
> > > It is not possible for OpenMP because we support implicit declare target 
> > > functions. Clang cannot identify whether the function is going to be used 
> > > on the device or not during sema analysis.
> >
> >
> > You are right, we can't do this during device compilation because we don't 
> > have an AST before Sema.
> >
> > However I'm currently thinking about the following:
> >
> > 1. Identify explicit and implicit `declare target` functions during host 
> > Sema and CodeGen.
> > 2. Attach meta-data for all of them to LLVM IR `.bc` which is passed via  
> > `-fopenmp-host-ir-file-path`. I think we already do something similar for 
> > outlined `target` regions?
> > 3. During device Sema query that meta-data so Clang knows when a function 
> > will be called from within a `target` region. Skip analysis of functions 
> > that are not needed for the device, just as CUDA does.
> > 4. Check that we don't need functions that weren't marked in 2. That's to 
> > catch users doing something like: ```lang=c #pragma omp target { #ifdef 
> > __NVPTX__ target_func() #endif } ```
> >
> >   For now that's just an idea, I didn't start implementing any of this yet. 
> > Do you think that could work?
>
>
> I thought about this approach already. But it won't work in general. The main 
> problem here is that host and device compilation phases may end up with the 
> different set of implicit declare target functions. The main problem here not 
> the user code, but the system libraries, which may use the different set of 
> functions.


How common is that for functions that are used in `target` regions? In the 
worst case we can make my fourth point a warning and lose Sema checking for 
those functions.

> Another one problem here is that the user may use the function that has some 
> host assembler inside. In this case we still need to emit error message, 
> otherwise, we may end up with the compiler crash.

Once we know which functions are used, they can be checked as usual.

> The best solution is to use only device specific header files. Device 
> compilation phase should use system header files for the host at all.

You mean "shouldn't use system header files for the host"? I think that may be 
hard to achieve, especially if we want to Sema check all of the source code 
during device compilation.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50337: [clangd] DexIndex implementation prototype

2018-08-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:86
+  const auto TrigramTokens = generateIdentifierTrigrams(Req.Query);
+  TopLevelChildren.push_back(createAnd(createTrigramIterators(TrigramTokens)));
+

`createTrigramIterators` and `createScopeIterators` use `InvertedIndex`, so 
they should be called in the critical section. 

Maybe 

```
/// 
/// Requires: Called from a critical section of `InvertedIndex`.
std::vector> createTrigramIterators(
const llvm::DenseMap &InvertedIndex, TrigramTokens);
```



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:102
+// final score might not be retrieved otherwise.
+const unsigned ItemsToRetrieve = 100 * Req.MaxCandidateCount;
+SymbolDocIDs = consume(*QueryIterator, ItemsToRetrieve);

Maybe add a `FIXME` about finding the best pre-scoring retrieval threshold. I'm 
not sure if `100*MaxCandidateCount` would work well in practice. For example, 
if the `MaxCandidateCount` is small e.g. `5`, then the retrieval threshold 
would only be 50, which still seems to be too small.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:110
+  const auto Score = Filter.match(Sym->Name);
+  assert(Score.hasValue() && "Matched symbol has all Fuzzy Matching "
+ "trigrams, it should match the query");

I don't think this assertion is well justified. I think we should just skip if 
the fuzzy match fails.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:118
+// in the order of descending score.
+std::sort(begin(Scores), end(Scores),
+  [](const std::pair &LHS,

I think we should use a priority queue so that we don't need to store/sort all 
retrieved symbols.



Comment at: clang-tools-extra/unittests/clangd/DexIndexTests.cpp:367
+// FIXME(kbobyrev): Use 3+ symbols long names so that trigram index is used.
+TEST(MergeDexIndex, Lookup) {
+  DexIndex I, J;

This seems to be testing `mergeIndex(...)` which is not relevant in this patch? 



Comment at: clang-tools-extra/unittests/clangd/DexIndexTests.cpp:388
+
+// FIXME(kbobyrev): Add more tests on DexIndex? Right now, it's mostly a 
wrapper
+// around DexIndex, adopting tests from IndexTests.cpp sounds reasonable.

Now that we are handling both short and long queries. I think we can address 
this FIXME in this patch?



Comment at: clang-tools-extra/unittests/clangd/DexIndexTests.cpp:540
+
+TEST(DexMergeIndexTest, Lookup) {
+  DexIndex I, J;

Again, `mergeIndex(...)` is not interesting here.


https://reviews.llvm.org/D50337



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In https://reviews.llvm.org/D50845#1203973, @Hahnfeld wrote:

> In https://reviews.llvm.org/D50845#1203967, @ABataev wrote:
>
> > In https://reviews.llvm.org/D50845#1203961, @Hahnfeld wrote:
> >
> > > In https://reviews.llvm.org/D50845#1202973, @ABataev wrote:
> > >
> > > > > So ideally I think Clang should determine which functions are really 
> > > > > `declare target` (either explicit or implicit) and only run 
> > > > > semantical analysis on them. If a function is then found to be 
> > > > > "broken" it's perfectly desirable to error back to the user.
> > > >
> > > > It is not possible for OpenMP because we support implicit declare 
> > > > target functions. Clang cannot identify whether the function is going 
> > > > to be used on the device or not during sema analysis.
> > >
> > >
> > > You are right, we can't do this during device compilation because we 
> > > don't have an AST before Sema.
> > >
> > > However I'm currently thinking about the following:
> > >
> > > 1. Identify explicit and implicit `declare target` functions during host 
> > > Sema and CodeGen.
> > > 2. Attach meta-data for all of them to LLVM IR `.bc` which is passed via  
> > > `-fopenmp-host-ir-file-path`. I think we already do something similar for 
> > > outlined `target` regions?
> > > 3. During device Sema query that meta-data so Clang knows when a function 
> > > will be called from within a `target` region. Skip analysis of functions 
> > > that are not needed for the device, just as CUDA does.
> > > 4. Check that we don't need functions that weren't marked in 2. That's to 
> > > catch users doing something like: ```lang=c #pragma omp target { #ifdef 
> > > __NVPTX__ target_func() #endif } ```
> > >
> > >   For now that's just an idea, I didn't start implementing any of this 
> > > yet. Do you think that could work?
> >
> >
> > I thought about this approach already. But it won't work in general. The 
> > main problem here is that host and device compilation phases may end up 
> > with the different set of implicit declare target functions. The main 
> > problem here not the user code, but the system libraries, which may use the 
> > different set of functions.
>
>
> How common is that for functions that are used in `target` regions? In the 
> worst case we can make my fourth point a warning and lose Sema checking for 
> those functions.


It does not matter how common is it or not. If the bad situation can happen, it 
will happen.
Warning won't work here, because, again, you may end up with the code that may 
cause compiler crash for the device. For example, if the system function uses 
throw/catch stmts, we may emit the warning for this function, but will have 
troubles during the codegen.

> 
> 
>> Another one problem here is that the user may use the function that has some 
>> host assembler inside. In this case we still need to emit error message, 
>> otherwise, we may end up with the compiler crash.
> 
> Once we know which functions are used, they can be checked as usual.
> 
>> The best solution is to use only device specific header files. Device 
>> compilation phase should use system header files for the host at all.
> 
> You mean "shouldn't use system header files for the host"? I think that may 
> be hard to achieve, especially if we want to Sema check all of the source 
> code during device compilation.

Yes, I mean should not. Yes, this is hard to achieve but that's the only 
complete and correct solution. Everything else looks like a non-stable hack.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


r340023 - clang-cl: Expose -fno-crash-diagnostics (PR38574)

2018-08-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Aug 17 06:37:57 2018
New Revision: 340023

URL: http://llvm.org/viewvc/llvm-project?rev=340023&view=rev
Log:
clang-cl: Expose -fno-crash-diagnostics (PR38574)

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/test/Driver/cl-options.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=340023&r1=340022&r2=340023&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Aug 17 06:37:57 2018
@@ -800,7 +800,7 @@ def fconstexpr_depth_EQ : Joined<["-"],
 def fconstexpr_steps_EQ : Joined<["-"], "fconstexpr-steps=">, Group;
 def fconstexpr_backtrace_limit_EQ : Joined<["-"], 
"fconstexpr-backtrace-limit=">,
 Group;
-def fno_crash_diagnostics : Flag<["-"], "fno-crash-diagnostics">, 
Group, Flags<[NoArgumentUnused]>,
+def fno_crash_diagnostics : Flag<["-"], "fno-crash-diagnostics">, 
Group, Flags<[NoArgumentUnused, CoreOption]>,
   HelpText<"Disable auto-generation of preprocessed source files and a script 
for reproduction during a clang crash">;
 def fcrash_diagnostics_dir : Joined<["-"], "fcrash-diagnostics-dir=">, 
Group, Flags<[NoArgumentUnused, CoreOption]>;
 def fcreate_profile : Flag<["-"], "fcreate-profile">, Group;

Modified: cfe/trunk/test/Driver/cl-options.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=340023&r1=340022&r2=340023&view=diff
==
--- cfe/trunk/test/Driver/cl-options.c (original)
+++ cfe/trunk/test/Driver/cl-options.c Fri Aug 17 06:37:57 2018
@@ -578,6 +578,7 @@
 // RUN: --driver-mode=cl \
 // RUN: -fblocks \
 // RUN: -fcrash-diagnostics-dir=/foo \
+// RUN: -fno-crash-diagnostics \
 // RUN: -fno-blocks \
 // RUN: -fbuiltin \
 // RUN: -fno-builtin \


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


[PATCH] D50640: Fix for bug 38508 - Don't do PCH processing when only generating preprocessor output

2018-08-17 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340025: Fix for bug 38508 - Don't do PCH processing 
when only generating preprocessor… (authored by erichkeane, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50640?vs=161116&id=161229#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50640

Files:
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/test/Driver/cl-pch.cpp
  cfe/trunk/test/PCH/Inputs/pch-through-use3c.cpp
  cfe/trunk/test/PCH/Inputs/pch-through3c.h
  cfe/trunk/test/PCH/pch-through3c.cpp


Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -3010,9 +3010,10 @@
 Args.eraseArg(options::OPT__SLASH_Yc);
 YcArg = nullptr;
   }
-  if (Args.hasArg(options::OPT__SLASH_Y_)) {
-// /Y- disables all pch handling.  Rather than check for it everywhere,
-// just remove clang-cl pch-related flags here.
+  if (FinalPhase == phases::Preprocess || Args.hasArg(options::OPT__SLASH_Y_)) 
{
+// If only preprocessing or /Y- is used, all pch handling is disabled.
+// Rather than check for it everywhere, just remove clang-cl pch-related
+// flags here.
 Args.eraseArg(options::OPT__SLASH_Fp);
 Args.eraseArg(options::OPT__SLASH_Yc);
 Args.eraseArg(options::OPT__SLASH_Yu);
Index: cfe/trunk/test/Driver/cl-pch.cpp
===
--- cfe/trunk/test/Driver/cl-pch.cpp
+++ cfe/trunk/test/Driver/cl-pch.cpp
@@ -345,3 +345,24 @@
 // CHECK-NoSourceTP: pchfile.pch
 // CHECK-NoSourceTP: -x
 // CHECK-NoSourceTP: "c++"
+
+// If only preprocessing, PCH options are ignored.
+// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YC-P %s
+// CHECK-YC-P-NOT: -emit-pch
+// CHECK-YC-P-NOT: -include-pch
+
+// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YC-E %s
+// CHECK-YC-E-NOT: -emit-pch
+// CHECK-YC-E-NOT: -include-pch
+
+// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YU-P %s
+// CHECK-YU-P-NOT: -emit-pch
+// CHECK-YU-P-NOT: -include-pch
+
+// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YU-E %s
+// CHECK-YU-E-NOT: -emit-pch
+// CHECK-YU-E-NOT: -include-pch
Index: cfe/trunk/test/PCH/Inputs/pch-through-use3c.cpp
===
--- cfe/trunk/test/PCH/Inputs/pch-through-use3c.cpp
+++ cfe/trunk/test/PCH/Inputs/pch-through-use3c.cpp
@@ -0,0 +1,2 @@
+int a = A;
+// expected-no-diagnostics
Index: cfe/trunk/test/PCH/Inputs/pch-through3c.h
===
--- cfe/trunk/test/PCH/Inputs/pch-through3c.h
+++ cfe/trunk/test/PCH/Inputs/pch-through3c.h
@@ -0,0 +1 @@
+#define A 1
Index: cfe/trunk/test/PCH/pch-through3c.cpp
===
--- cfe/trunk/test/PCH/pch-through3c.cpp
+++ cfe/trunk/test/PCH/pch-through3c.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -I %S -emit-pch \
+// RUN:   -include Inputs/pch-through3c.h \
+// RUN:   -pch-through-header=Inputs/pch-through3c.h -o %t.3c %s
+
+// RUN: %clang_cc1 -verify -I %S -include-pch %t.3c \
+// RUN:   -include Inputs/pch-through3c.h \
+// RUN:   -pch-through-header=Inputs/pch-through3c.h \
+// RUN:   %S/Inputs/pch-through-use3c.cpp 2>&1


Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -3010,9 +3010,10 @@
 Args.eraseArg(options::OPT__SLASH_Yc);
 YcArg = nullptr;
   }
-  if (Args.hasArg(options::OPT__SLASH_Y_)) {
-// /Y- disables all pch handling.  Rather than check for it everywhere,
-// just remove clang-cl pch-related flags here.
+  if (FinalPhase == phases::Preprocess || Args.hasArg(options::OPT__SLASH_Y_)) {
+// If only preprocessing or /Y- is used, all pch handling is disabled.
+// Rather than check for it everywhere, just remove clang-cl pch-related
+// flags here.
 Args.eraseArg(options::OPT__SLASH_Fp);
 Args.eraseArg(options::OPT__SLASH_Yc);
 Args.eraseArg(options::OPT__SLASH_Yu);
Index: cfe/trunk/test/Driver/cl-pch.cpp
===
--- cfe/trunk/test/Driver/cl-pch.cpp
+++ cfe/trunk/test/Driver/cl-pch.cpp
@@ -345,3 +345,24 @@
 // CHECK-NoSourceTP: pchfile.pch
 // CHECK-NoSourceTP: -x
 // CHECK-NoSourceTP: "c++"
+
+// If only preprocessing, PCH options are ignored.
+// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YC-P %s
+// CHECK-YC-P-NOT: -emit-pch
+// CHECK-YC-P-NOT: -include-pch
+
+// RUN: %cl

r340025 - Fix for bug 38508 - Don't do PCH processing when only generating preprocessor output

2018-08-17 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Aug 17 06:43:39 2018
New Revision: 340025

URL: http://llvm.org/viewvc/llvm-project?rev=340025&view=rev
Log:
Fix for bug 38508 - Don't do PCH processing when only generating preprocessor 
output

This clang-cl driver change removes the PCH options when we are only generating
preprocessed output. This is similar to the behavior of Y-.

Patch by: mikerice
Differential Revision: https://reviews.llvm.org/D50640

Added:
cfe/trunk/test/PCH/Inputs/pch-through-use3c.cpp
cfe/trunk/test/PCH/Inputs/pch-through3c.h
cfe/trunk/test/PCH/pch-through3c.cpp
Modified:
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/test/Driver/cl-pch.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=340025&r1=340024&r2=340025&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Aug 17 06:43:39 2018
@@ -3010,9 +3010,10 @@ void Driver::BuildActions(Compilation &C
 Args.eraseArg(options::OPT__SLASH_Yc);
 YcArg = nullptr;
   }
-  if (Args.hasArg(options::OPT__SLASH_Y_)) {
-// /Y- disables all pch handling.  Rather than check for it everywhere,
-// just remove clang-cl pch-related flags here.
+  if (FinalPhase == phases::Preprocess || Args.hasArg(options::OPT__SLASH_Y_)) 
{
+// If only preprocessing or /Y- is used, all pch handling is disabled.
+// Rather than check for it everywhere, just remove clang-cl pch-related
+// flags here.
 Args.eraseArg(options::OPT__SLASH_Fp);
 Args.eraseArg(options::OPT__SLASH_Yc);
 Args.eraseArg(options::OPT__SLASH_Yu);

Modified: cfe/trunk/test/Driver/cl-pch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-pch.cpp?rev=340025&r1=340024&r2=340025&view=diff
==
--- cfe/trunk/test/Driver/cl-pch.cpp (original)
+++ cfe/trunk/test/Driver/cl-pch.cpp Fri Aug 17 06:43:39 2018
@@ -345,3 +345,24 @@
 // CHECK-NoSourceTP: pchfile.pch
 // CHECK-NoSourceTP: -x
 // CHECK-NoSourceTP: "c++"
+
+// If only preprocessing, PCH options are ignored.
+// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YC-P %s
+// CHECK-YC-P-NOT: -emit-pch
+// CHECK-YC-P-NOT: -include-pch
+
+// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YC-E %s
+// CHECK-YC-E-NOT: -emit-pch
+// CHECK-YC-E-NOT: -include-pch
+
+// RUN: %clang_cl /P /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YU-P %s
+// CHECK-YU-P-NOT: -emit-pch
+// CHECK-YU-P-NOT: -include-pch
+
+// RUN: %clang_cl /E /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-YU-E %s
+// CHECK-YU-E-NOT: -emit-pch
+// CHECK-YU-E-NOT: -include-pch

Added: cfe/trunk/test/PCH/Inputs/pch-through-use3c.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pch-through-use3c.cpp?rev=340025&view=auto
==
--- cfe/trunk/test/PCH/Inputs/pch-through-use3c.cpp (added)
+++ cfe/trunk/test/PCH/Inputs/pch-through-use3c.cpp Fri Aug 17 06:43:39 2018
@@ -0,0 +1,2 @@
+int a = A;
+// expected-no-diagnostics

Added: cfe/trunk/test/PCH/Inputs/pch-through3c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pch-through3c.h?rev=340025&view=auto
==
--- cfe/trunk/test/PCH/Inputs/pch-through3c.h (added)
+++ cfe/trunk/test/PCH/Inputs/pch-through3c.h Fri Aug 17 06:43:39 2018
@@ -0,0 +1 @@
+#define A 1

Added: cfe/trunk/test/PCH/pch-through3c.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/pch-through3c.cpp?rev=340025&view=auto
==
--- cfe/trunk/test/PCH/pch-through3c.cpp (added)
+++ cfe/trunk/test/PCH/pch-through3c.cpp Fri Aug 17 06:43:39 2018
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -I %S -emit-pch \
+// RUN:   -include Inputs/pch-through3c.h \
+// RUN:   -pch-through-header=Inputs/pch-through3c.h -o %t.3c %s
+
+// RUN: %clang_cc1 -verify -I %S -include-pch %t.3c \
+// RUN:   -include Inputs/pch-through3c.h \
+// RUN:   -pch-through-header=Inputs/pch-through3c.h \
+// RUN:   %S/Inputs/pch-through-use3c.cpp 2>&1


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


[PATCH] D50835: [clangd] Add parantheses while auto-completing functions.

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/CodeComplete.h:85
+
+  /// Enables cursor to be moved around according to completions needs even 
when
+  /// snippets are disabled. For example selecting a function with parameters 
as

kadircet wrote:
> ioeric wrote:
> > IIRC, the goal of this patch is to allow disabling snippet templates for 
> > function parameters while still allow appending `()` or `($0)` to function 
> > candidates. If that's still the case, I think what we want is probably an 
> > option like `DisableSnippetTemplateForFunctionArgs`? 
> Yeah, that makes totally more sense. Thanks!
- Maybe use positive option names to avoid double negation?
- Maybe also use a shorter name? E.g. removing 'template' and 'disable' from 
the name gives a name that does not look any worse: `FunctionArgSnippets`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50835



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


[PATCH] D50876: Clean up newly created header

2018-08-17 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

LGTM with the `__clz` you missed.




Comment at: include/bit:61
+inline _LIBCPP_INLINE_VISIBILITY
+int __popcount(unsigned __x)   { return __builtin_popcount  (__x); }
+

Funny spacing between `__builtin_popcount` and `(__x)`


https://reviews.llvm.org/D50876



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


[PATCH] D50876: Clean up newly created header

2018-08-17 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: include/bit:117
+  unsigned long __where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.

Like i commented in the original review, this should probably be 
```
// Search from *M*SB to *L*SB for first set bit.
```


https://reviews.llvm.org/D50876



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


[PATCH] D50814: [clangd] transfer the fixits with the notes instead of adding them to the main diagnostic if request by the client

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Why do we want an alternative mode for transferring fix-its and notes? Any 
reason why our current model is bad?
One thing that comes to mind is inconsistency between clang and our model, but 
I wonder where would it affect the user experience in a bad way?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50814



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


[PATCH] D50557: [clang][mips] Set __mips_fpr correctly for -mfpxx

2018-08-17 Thread Stefan Maksimovic via Phabricator via cfe-commits
smaksimovic updated this revision to Diff 161233.
smaksimovic added a comment.

Added test cases.


https://reviews.llvm.org/D50557

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  lib/Basic/Targets/Mips.cpp
  lib/Basic/Targets/Mips.h
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -3442,7 +3442,7 @@
 // MIPS32BE:#define __mips 32
 // MIPS32BE:#define __mips__ 1
 // MIPS32BE:#define __mips_abicalls 1
-// MIPS32BE:#define __mips_fpr 32
+// MIPS32BE:#define __mips_fpr 0
 // MIPS32BE:#define __mips_hard_float 1
 // MIPS32BE:#define __mips_o32 1
 // MIPS32BE:#define _mips 1
@@ -3649,7 +3649,7 @@
 // MIPS32EL:#define __mips 32
 // MIPS32EL:#define __mips__ 1
 // MIPS32EL:#define __mips_abicalls 1
-// MIPS32EL:#define __mips_fpr 32
+// MIPS32EL:#define __mips_fpr 0
 // MIPS32EL:#define __mips_hard_float 1
 // MIPS32EL:#define __mips_o32 1
 // MIPS32EL:#define _mips 1
@@ -4900,6 +4900,41 @@
 // RUN:   | FileCheck -match-full-lines -check-prefix NOMIPS-ABS2008 %s
 // NOMIPS-ABS2008-NOT:#define __mips_abs2008 1
 //
+// RUN: %clang_cc1  \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-NOFP %s
+// MIPS32-NOFP:#define __mips_fpr 0
+//
+// RUN: %clang_cc1 -target-feature +fpxx \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-MFPXX %s
+// MIPS32-MFPXX:#define __mips_fpr 0
+//
+// RUN: %clang_cc1 -target-cpu mips32r6 -target-feature +fpxx \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS32R6-MFPXX %s
+// MIPS32R6-MFPXX:#define __mips_fpr 0
+//
+// RUN: %clang_cc1  \
+// RUN:   -E -dM -triple=mips64-none-none < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS64-NOFP %s
+// MIPS64-NOFP:#define __mips_fpr 64
+//
+// RUN: not %clang_cc1 -target-feature -fp64 \
+// RUN:   -E -dM -triple=mips64-none-none < /dev/null 2>&1 \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS64-MFP32 %s
+// MIPS64-MFP32:error: option '-mfpxx' cannot be specified with 'mips64r2'
+//
+// RUN: not %clang_cc1 -target-feature +fpxx \
+// RUN:   -E -dM -triple=mips64-none-none < /dev/null 2>&1 \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS64-MFPXX %s
+// MIPS64-MFPXX:error: '-mfpxx' can only be used with the 'o32' ABI
+//
+// RUN: not %clang_cc1 -target-cpu mips64r6 -target-feature +fpxx \
+// RUN:   -E -dM -triple=mips64-none-none < /dev/null 2>&1 \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS64R6-MFPXX %s
+// MIPS64R6-MFPXX:error: '-mfpxx' can only be used with the 'o32' ABI
+//
 // 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
@@ -4916,7 +4951,7 @@
 // RUN:   -E -dM -triple=mips-none-none < /dev/null \
 // RUN:   | FileCheck -match-full-lines -check-prefix MIPS32-MFP32SF %s
 // MIPS32-MFP32SF:#define _MIPS_FPSET 32
-// MIPS32-MFP32SF:#define __mips_fpr 32
+// MIPS32-MFP32SF:#define __mips_fpr 0
 //
 // RUN: %clang_cc1 -target-feature +fp64 \
 // RUN:   -E -dM -triple=mips64-none-none < /dev/null \
Index: lib/Basic/Targets/Mips.h
===
--- lib/Basic/Targets/Mips.h
+++ lib/Basic/Targets/Mips.h
@@ -57,16 +57,16 @@
   bool UseIndirectJumpHazard;
 
 protected:
-  bool HasFP64;
+  enum FPModeEnum { FPXX, FP32, FP64 } FPMode;
   std::string ABI;
 
 public:
   MipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
   : TargetInfo(Triple), IsMips16(false), IsMicromips(false),
 IsNan2008(false), IsAbs2008(false), IsSingleFloat(false),
 IsNoABICalls(false), CanUseBSDABICalls(false), FloatABI(HardFloat),
 DspRev(NoDSP), HasMSA(false), DisableMadd4(false),
-UseIndirectJumpHazard(false), HasFP64(false) {
+UseIndirectJumpHazard(false), FPMode(FPXX) {
 TheCXXABI.set(TargetCXXABI::GenericMIPS);
 
 setABI(getTriple().isMIPS32() ? "o32" : "n64");
@@ -181,6 +181,8 @@
 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
   }
 
+  unsigned getISARev() const;
+
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override;
 
@@ -305,7 +307,7 @@
 IsSingleFloat = false;
 FloatABI = HardFloat;
 DspRev = NoDSP;
-HasFP64 = isFP64Default();
+FPMode = isFP64Default() ? FP64 : FPXX;
 
 for (const auto &Feature : Features) {
   if (Feature == "+single-float")
@@ -325,9 +327,11 @@
   else if (Feature == "+nomadd4")
 DisableMadd4 = true;
   else if (Feature == "+fp64")
-HasFP64 = true;
+FPMode = FP64;
   else if (Feature == "-fp64")
-HasFP64 = false;
+FPMode = FP32;
+  else if (

[PATCH] D50896: [clangd] Add xrefs LSP boilerplate implementation.

2018-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: ilya-biryukov, ioeric.
Herald added subscribers: arphaman, jkorous, MaskRay.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50896

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/XRefs.cpp
  clangd/XRefs.h
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test

Index: test/clangd/initialize-params.test
===
--- test/clangd/initialize-params.test
+++ test/clangd/initialize-params.test
@@ -29,6 +29,7 @@
 # CHECK-NEXT:]
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "hoverProvider": true,
+# CHECK-NEXT:  "referencesProvider": false,
 # CHECK-NEXT:  "renameProvider": true,
 # CHECK-NEXT:  "signatureHelpProvider": {
 # CHECK-NEXT:"triggerCharacters": [
Index: test/clangd/initialize-params-invalid.test
===
--- test/clangd/initialize-params-invalid.test
+++ test/clangd/initialize-params-invalid.test
@@ -29,6 +29,7 @@
 # CHECK-NEXT:]
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "hoverProvider": true,
+# CHECK-NEXT:  "referencesProvider": false,
 # CHECK-NEXT:  "renameProvider": true,
 # CHECK-NEXT:  "signatureHelpProvider": {
 # CHECK-NEXT:"triggerCharacters": [
Index: clangd/XRefs.h
===
--- clangd/XRefs.h
+++ clangd/XRefs.h
@@ -34,6 +34,11 @@
 /// Get the hover information when hovering at \p Pos.
 llvm::Optional getHover(ParsedAST &AST, Position Pos);
 
+/// Get references of symbol at a \p Pos.
+std::vector references(ParsedAST &AST, Position Pos,
+ bool includeDeclaration,
+ const SymbolIndex *Index = nullptr);
+
 } // namespace clangd
 } // namespace clang
 
Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -17,6 +17,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/USRGeneration.h"
 #include "llvm/Support/Path.h"
+
 namespace clang {
 namespace clangd {
 using namespace llvm;
@@ -660,5 +661,12 @@
   return None;
 }
 
+std::vector references(ParsedAST &AST, Position Pos,
+ bool IncludeDeclaration,
+ const SymbolIndex *Index) {
+  // FIXME: implement it.
+  return {};
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -55,6 +55,7 @@
   virtual void onDocumentHighlight(TextDocumentPositionParams &Params) = 0;
   virtual void onHover(TextDocumentPositionParams &Params) = 0;
   virtual void onChangeConfiguration(DidChangeConfigurationParams &Params) = 0;
+  virtual void onReference(ReferenceParams &Params) = 0;
 };
 
 void registerCallbackHandlers(JSONRPCDispatcher &Dispatcher,
Index: clangd/ProtocolHandlers.cpp
===
--- clangd/ProtocolHandlers.cpp
+++ clangd/ProtocolHandlers.cpp
@@ -75,4 +75,5 @@
   Register("workspace/didChangeConfiguration",
&ProtocolCallbacks::onChangeConfiguration);
   Register("workspace/symbol", &ProtocolCallbacks::onWorkspaceSymbol);
+  Register("textDocument/references", &ProtocolCallbacks::onReference);
 }
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -867,6 +867,17 @@
 llvm::json::Value toJSON(const DocumentHighlight &DH);
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DocumentHighlight &);
 
+struct ReferenceContext {
+  // Include the declaration of the current symbol.
+  bool includeDeclaration;
+};
+bool fromJSON(const llvm::json::Value &, ReferenceContext &);
+
+struct ReferenceParams : public TextDocumentPositionParams {
+  ReferenceContext context;
+};
+bool fromJSON(const llvm::json::Value &, ReferenceParams &);
+
 } // namespace clangd
 } // namespace clang
 
Index: clangd/Protocol.cpp
===
--- clangd/Protocol.cpp
+++ clangd/Protocol.cpp
@@ -615,5 +615,16 @@
  O.map("compilationDatabaseChanges", CCPC.compilationDatabaseChanges);
 }
 
+bool fromJSON(const json::Value &Params, ReferenceContext &RC) {
+  json::ObjectMapper O(Params);
+  return O && O.map("includeDeclaration", RC.includeDeclaration);
+}
+
+bool fromJSON(const json::Value &Params, ReferenceParams &R) {
+  json::ObjectMapper O(Params);
+  return O && O.map("context", R.context) &&
+ O.map("textDocument", R.textDocument) && O.map("position", R.position);
+}
+
 } // name

[PATCH] D50835: [clangd] Add parantheses while auto-completing functions.

2018-08-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/CodeComplete.cpp:1377
+  // Check whether function has any parameters or not.
+  LSP.textEdit->newText += SnippetSuffix.size() > 2 ? "(${0})" : "()";
+else

There seems to be no guarantee on whether the snippet is function arg template 
when `SnippetSuffix.size() > 2`. A heuristic we could use is probably checking 
that the template starts with `(` and ends with `)`? Alternatively, we could 
try to avoid generating the proper snippet according to the flag when we still 
have the function declaration around. Not sure if this is feasible for index 
results though.



Comment at: clangd/CodeComplete.h:85
+
+  /// Enables cursor to be moved around according to completions needs even 
when
+  /// snippets are disabled. For example selecting a function with parameters 
as

ilya-biryukov wrote:
> kadircet wrote:
> > ioeric wrote:
> > > IIRC, the goal of this patch is to allow disabling snippet templates for 
> > > function parameters while still allow appending `()` or `($0)` to 
> > > function candidates. If that's still the case, I think what we want is 
> > > probably an option like `DisableSnippetTemplateForFunctionArgs`? 
> > Yeah, that makes totally more sense. Thanks!
> - Maybe use positive option names to avoid double negation?
> - Maybe also use a shorter name? E.g. removing 'template' and 'disable' from 
> the name gives a name that does not look any worse: `FunctionArgSnippets`.
+1 to a better name. I didn't really give much thought about the name and just 
wanted to get the idea across :)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50835



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


[PATCH] D50337: [clangd] DexIndex implementation prototype

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 161235.
kbobyrev marked 7 inline comments as done.
kbobyrev added a comment.

Address another round of comments.


https://reviews.llvm.org/D50337

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/clangd/index/dex/DexIndex.h
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/unittests/clangd/CMakeLists.txt
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp
  clang-tools-extra/unittests/clangd/IndexTests.cpp
  clang-tools-extra/unittests/clangd/TestIndex.cpp
  clang-tools-extra/unittests/clangd/TestIndex.h

Index: clang-tools-extra/unittests/clangd/TestIndex.h
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/TestIndex.h
@@ -0,0 +1,57 @@
+//===-- IndexHelpers.h --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_INDEXTESTCOMMON_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_INDEXTESTCOMMON_H
+
+#include "index/Index.h"
+#include "index/Merge.h"
+#include "index/dex/DexIndex.h"
+#include "index/dex/Iterator.h"
+#include "index/dex/Token.h"
+#include "index/dex/Trigram.h"
+
+namespace clang {
+namespace clangd {
+
+Symbol symbol(llvm::StringRef QName);
+
+struct SlabAndPointers {
+  SymbolSlab Slab;
+  std::vector Pointers;
+};
+
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
+std::shared_ptr>
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols = nullptr);
+
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols = nullptr);
+
+std::string getQualifiedName(const Symbol &Sym);
+
+std::vector match(const SymbolIndex &I,
+   const FuzzyFindRequest &Req,
+   bool *Incomplete = nullptr);
+
+// Returns qualified names of symbols with any of IDs in the index.
+std::vector lookup(const SymbolIndex &I,
+llvm::ArrayRef IDs);
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/unittests/clangd/TestIndex.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/TestIndex.cpp
@@ -0,0 +1,89 @@
+//===-- IndexHelpers.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestIndex.h"
+
+namespace clang {
+namespace clangd {
+
+Symbol symbol(llvm::StringRef QName) {
+  Symbol Sym;
+  Sym.ID = SymbolID(QName.str());
+  size_t Pos = QName.rfind("::");
+  if (Pos == llvm::StringRef::npos) {
+Sym.Name = QName;
+Sym.Scope = "";
+  } else {
+Sym.Name = QName.substr(Pos + 2);
+Sym.Scope = QName.substr(0, Pos + 2);
+  }
+  return Sym;
+}
+
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
+std::shared_ptr>
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols) {
+  SymbolSlab::Builder Slab;
+  for (llvm::StringRef QName : QualifiedNames)
+Slab.insert(symbol(QName));
+
+  auto Storage = std::make_shared();
+  Storage->Slab = std::move(Slab).build();
+  for (const auto &Sym : Storage->Slab)
+Storage->Pointers.push_back(&Sym);
+  if (WeakSymbols)
+*WeakSymbols = Storage;
+  auto *Pointers = &Storage->Pointers;
+  return {std::move(Storage), Pointers};
+}
+
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols) {
+  std::vector Names;
+  for (int i = Begin; i <= End; i++)
+Names.push_back(std::to_string(i));
+  return generateSymbols(Names, WeakSymbols);
+}
+
+std::string getQualifiedName(const Symbol &Sym) {
+  return (Sym.Scope + Sym.Name).str();
+}
+
+std::vector match(const SymbolIndex &I,
+

[PATCH] D50557: [clang][mips] Set __mips_fpr correctly for -mfpxx

2018-08-17 Thread Stefan Maksimovic via Phabricator via cfe-commits
smaksimovic added inline comments.



Comment at: lib/Basic/Targets/Mips.cpp:62
 
+unsigned MipsTargetInfo::getISARev(const std::string& CPU) const {
+  return llvm::StringSwitch(getCPU())

atanasyan wrote:
> The CPU argument looks unused. We can either remove it or make this routine a 
> non-member static function. Probably we can change the CPU’s type to 
> StringRef.
I opted to remove the argument.



Comment at: lib/Basic/Targets/Mips.cpp:97
 
-  const std::string ISARev = llvm::StringSwitch(getCPU())
- .Cases("mips32", "mips64", "1")
- .Cases("mips32r2", "mips64r2", "2")
- .Cases("mips32r3", "mips64r3", "3")
- .Cases("mips32r5", "mips64r5", "5")
- .Cases("mips32r6", "mips64r6", "6")
- .Default("");
+  const std::string ISARev = std::to_string(getISARev(getCPU()));
+

atanasyan wrote:
> Is this change required for the fix? It looks like a refactoring and maybe 
> done by a separate commit.
Since I took the code that originally was here in order to reuse it down below, 
I changed this line because the new function returns an int instead, as it was 
easier to do comparisons at line 264.


https://reviews.llvm.org/D50557



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


[PATCH] D50862: [clang-tidy] Abseil: faster strsplit delimiter check

2018-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a subscriber: sbenza.
hokein added a comment.

Thanks for porting the check to upstream (context: the check was developed 
internally, and has been run on our codebase for a while, it is pretty stable). 
Could you please update the patch message to indicate this is a porting change, 
and add the original check author @sbenza in the patch description?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50862



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


[PATCH] D50337: [clangd] DexIndex implementation prototype

2018-08-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Almost LG! Just a few more nits.




Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:87
+  std::vector SymbolDocIDs;
+  std::priority_queue> Top;
+

nit: move `SymbolDocIDs` and `Top` closer to where they're used.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:97
+// Add OR iterator for scopes if the request contains scopes.
+if (!Req.Scopes.empty()) {
+  TopLevelChildren.push_back(createScopeIterator(Req.Scopes));

I think we should let `createScopeIterator` handle empty scope list case; it 
can return an empty list anyway.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:109
+SymbolDocIDs = consume(*QueryIterator, ItemsToRetrieve);
+More = SymbolDocIDs.size() >= Req.MaxCandidateCount;
+

This is not a proper place to set `More`. It's already handled below.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:112
+// Populate scores.
+for (size_t SymbolIdx = 0; SymbolIdx < SymbolDocIDs.size(); ++SymbolIdx) {
+  const auto Sym = (*Symbols)[SymbolDocIDs[SymbolIdx]];

nit: use range-based for loop?



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:113
+for (size_t SymbolIdx = 0; SymbolIdx < SymbolDocIDs.size(); ++SymbolIdx) {
+  const auto Sym = (*Symbols)[SymbolDocIDs[SymbolIdx]];
+  const auto Score = Filter.match(Sym->Name);

nit: Maybe take `const auto &Sym`?



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:119
+  // highest actual score.
+  Top.emplace(-*Score * SymbolQuality.find(Sym)->second, Sym);
+  if (Top.size() > Req.MaxCandidateCount) {

nit: `- (*Score) * ...` for readability.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:127
+// Apply callback to the top Req.MaxCandidateCount items.
+for (; !Top.empty(); Top.pop())
+  Callback(*Top.top().second);

Can we simply iterate without `pop()`?



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:150
+std::unique_ptr
+DexIndex::createTrigramIterator(std::vector TrigramTokens) const {
+  std::vector> TrigramIterators;

This assumes that `createTrigramIterator` and `createScopeIterator` are already 
guarded by the mutex, which is implicit. I think we can make it clearer by 
making these local helpers that take in InvertedIndex` with the requirement 
that local has been acquired.



Comment at: clang-tools-extra/unittests/clangd/DexIndexTests.cpp:366
+
+// FIXME(kbobyrev): Add more tests on DexIndex? Right now, it's mostly a 
wrapper
+// around DexIndex, adopting tests from IndexTests.cpp sounds reasonable.

What tests do we want? If it's related to the changes in this patch, we should 
add it now. Tests shouldn't be `FIXME` :)


https://reviews.llvm.org/D50337



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


[PATCH] D50897: [clangd] Allow using experimental Dex index

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added reviewers: ioeric, ilya-biryukov.
kbobyrev added a project: clang-tools-extra.
Herald added subscribers: arphaman, jkorous, MaskRay.

This patch adds hidden Clangd flag which replaces (currently) default 
`MemIndex` with `DexIndex` for the static index.


https://reviews.llvm.org/D50897

Files:
  clang-tools-extra/clangd/index/Index.h
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/MemIndex.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
  clang-tools-extra/unittests/clangd/TestTU.cpp

Index: clang-tools-extra/unittests/clangd/TestTU.cpp
===
--- clang-tools-extra/unittests/clangd/TestTU.cpp
+++ clang-tools-extra/unittests/clangd/TestTU.cpp
@@ -49,7 +49,7 @@
 }
 
 std::unique_ptr TestTU::index() const {
-  return MemIndex::build(headerSymbols());
+  return SymbolIndex::build(headerSymbols());
 }
 
 const Symbol &findSymbol(const SymbolSlab &Slab, llvm::StringRef QName) {
Index: clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
===
--- clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
@@ -76,7 +76,7 @@
   SymbolSlab::Builder Slab;
   for (const auto &Sym : Symbols)
 Slab.insert(Sym);
-  return MemIndex::build(std::move(Slab).build());
+  return SymbolIndex::build(std::move(Slab).build());
 }
 
 CodeCompleteResult completions(ClangdServer &Server, StringRef TestCode,
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -7,48 +7,31 @@
 //
 //===--===//
 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include "ClangdLSPServer.h"
 #include "JSONRPCDispatcher.h"
 #include "Path.h"
 #include "Trace.h"
-#include "index/SymbolYAML.h"
 #include "clang/Basic/Version.h"
+#include "index/SymbolYAML.h"
+#include "index/dex/DexIndex.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
-#include 
-#include 
-#include 
-#include 
 
 using namespace clang;
 using namespace clang::clangd;
 
 namespace {
 enum class PCHStorageFlag { Disk, Memory };
 
-// Build an in-memory static index for global symbols from a YAML-format file.
-// The size of global symbols should be relatively small, so that all symbols
-// can be managed in memory.
-std::unique_ptr buildStaticIndex(llvm::StringRef YamlSymbolFile) {
-  auto Buffer = llvm::MemoryBuffer::getFile(YamlSymbolFile);
-  if (!Buffer) {
-llvm::errs() << "Can't open " << YamlSymbolFile << "\n";
-return nullptr;
-  }
-  auto Slab = symbolsFromYAML(Buffer.get()->getBuffer());
-  SymbolSlab::Builder SymsBuilder;
-  for (auto Sym : Slab)
-SymsBuilder.insert(Sym);
-
-  return MemIndex::build(std::move(SymsBuilder).build());
-}
-} // namespace
-
 static llvm::cl::opt CompileCommandsDir(
 "compile-commands-dir",
 llvm::cl::desc("Specify a path to look for compile_commands.json. If path "
@@ -185,6 +168,29 @@
 "'compile_commands.json' files")),
 llvm::cl::init(FilesystemCompileArgs), llvm::cl::Hidden);
 
+static llvm::cl::opt UseDex(
+"use-dex-index", llvm::cl::desc("Use experimental Dex static index."),
+llvm::cl::init(false), llvm::cl::Hidden);
+
+// Build an in-memory static index for global symbols from a YAML-format file.
+// The size of global symbols should be relatively small, so that all symbols
+// can be managed in memory.
+std::unique_ptr buildStaticIndex(llvm::StringRef YamlSymbolFile) {
+  auto Buffer = llvm::MemoryBuffer::getFile(YamlSymbolFile);
+  if (!Buffer) {
+llvm::errs() << "Can't open " << YamlSymbolFile << "\n";
+return nullptr;
+  }
+  auto Slab = symbolsFromYAML(Buffer.get()->getBuffer());
+  SymbolSlab::Builder SymsBuilder;
+  for (auto Sym : Slab) SymsBuilder.insert(Sym);
+
+  return UseDex
+ ? SymbolIndex::build(std::move(SymsBuilder).build())
+ : SymbolIndex::build(std::move(SymsBuilder).build());
+}
+}  // namespace
+
 int main(int argc, char *argv[]) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
Index: clang-tools-extra/clangd/index/MemIndex.h
===
--- clang-tools-extra/clangd/index/MemIndex.h
+++ clang-tools-extra/clangd/index/MemIndex.h
@@ -24,9 +24,6 @@
   /// accessible as long as `Symbols` is kept alive.
   void build(std::shared_ptr> Symbols);
 
-  /// \brief Build index from 

[PATCH] D50897: [clangd] Allow using experimental Dex index

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 161239.
kbobyrev added a comment.

Fix anonymous namespace beginning placement in Clangd driver.


https://reviews.llvm.org/D50897

Files:
  clang-tools-extra/clangd/index/Index.h
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/MemIndex.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
  clang-tools-extra/unittests/clangd/TestTU.cpp

Index: clang-tools-extra/unittests/clangd/TestTU.cpp
===
--- clang-tools-extra/unittests/clangd/TestTU.cpp
+++ clang-tools-extra/unittests/clangd/TestTU.cpp
@@ -49,7 +49,7 @@
 }
 
 std::unique_ptr TestTU::index() const {
-  return MemIndex::build(headerSymbols());
+  return SymbolIndex::build(headerSymbols());
 }
 
 const Symbol &findSymbol(const SymbolSlab &Slab, llvm::StringRef QName) {
Index: clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
===
--- clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp
@@ -76,7 +76,7 @@
   SymbolSlab::Builder Slab;
   for (const auto &Sym : Symbols)
 Slab.insert(Sym);
-  return MemIndex::build(std::move(Slab).build());
+  return SymbolIndex::build(std::move(Slab).build());
 }
 
 CodeCompleteResult completions(ClangdServer &Server, StringRef TestCode,
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -7,48 +7,28 @@
 //
 //===--===//
 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include "ClangdLSPServer.h"
 #include "JSONRPCDispatcher.h"
 #include "Path.h"
 #include "Trace.h"
-#include "index/SymbolYAML.h"
 #include "clang/Basic/Version.h"
+#include "index/SymbolYAML.h"
+#include "index/dex/DexIndex.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
-#include 
-#include 
-#include 
-#include 
 
 using namespace clang;
 using namespace clang::clangd;
 
-namespace {
-enum class PCHStorageFlag { Disk, Memory };
-
-// Build an in-memory static index for global symbols from a YAML-format file.
-// The size of global symbols should be relatively small, so that all symbols
-// can be managed in memory.
-std::unique_ptr buildStaticIndex(llvm::StringRef YamlSymbolFile) {
-  auto Buffer = llvm::MemoryBuffer::getFile(YamlSymbolFile);
-  if (!Buffer) {
-llvm::errs() << "Can't open " << YamlSymbolFile << "\n";
-return nullptr;
-  }
-  auto Slab = symbolsFromYAML(Buffer.get()->getBuffer());
-  SymbolSlab::Builder SymsBuilder;
-  for (auto Sym : Slab)
-SymsBuilder.insert(Sym);
-
-  return MemIndex::build(std::move(SymsBuilder).build());
-}
-} // namespace
-
 static llvm::cl::opt CompileCommandsDir(
 "compile-commands-dir",
 llvm::cl::desc("Specify a path to look for compile_commands.json. If path "
@@ -113,6 +93,31 @@
 "Intended to simplify lit tests."),
 llvm::cl::init(false), llvm::cl::Hidden);
 
+
+namespace {
+
+enum class PCHStorageFlag { Disk, Memory };
+
+// Build an in-memory static index for global symbols from a YAML-format file.
+// The size of global symbols should be relatively small, so that all symbols
+// can be managed in memory.
+std::unique_ptr buildStaticIndex(llvm::StringRef YamlSymbolFile) {
+  auto Buffer = llvm::MemoryBuffer::getFile(YamlSymbolFile);
+  if (!Buffer) {
+llvm::errs() << "Can't open " << YamlSymbolFile << "\n";
+return nullptr;
+  }
+  auto Slab = symbolsFromYAML(Buffer.get()->getBuffer());
+  SymbolSlab::Builder SymsBuilder;
+  for (auto Sym : Slab) SymsBuilder.insert(Sym);
+
+  return UseDex
+ ? SymbolIndex::build(std::move(SymsBuilder).build())
+ : SymbolIndex::build(std::move(SymsBuilder).build());
+}
+
+}  // namespace
+
 static llvm::cl::opt PCHStorage(
 "pch-storage",
 llvm::cl::desc("Storing PCHs in memory increases memory usages, but may "
@@ -185,6 +190,10 @@
 "'compile_commands.json' files")),
 llvm::cl::init(FilesystemCompileArgs), llvm::cl::Hidden);
 
+static llvm::cl::opt UseDex(
+"use-dex-index", llvm::cl::desc("Use experimental Dex static index."),
+llvm::cl::init(false), llvm::cl::Hidden);
+
 int main(int argc, char *argv[]) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
Index: clang-tools-extra/clangd/index/MemIndex.h
===
--- clang-tools-extra/clangd/index/MemIndex.h
+++ clang-tools-extra/clangd/index/MemIndex.

[PATCH] D50502: [clangd] Initial cancellation mechanism for LSP requests.

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Mostly NITs, but please take a look at the `CancelParams` handling problem. I 
believe there might be a potential bug hiding there :-)




Comment at: clangd/Cancellation.h:87
+/// Enables async tasks to check for cancellation signal, contains a read only
+/// token cached from context. Can be created with clangd::isCancelled. It is
+/// thread-safe, multiple threads can check for cancellation on the same token.

s/Can be created with `clangd::isCancelled()`/Tokens for the currently running 
task can be obtained via clangd::getCurrentCancellationToken/?
(to focus on which kind of tokens can be obtained from the tokens)

Another idea: maybe add a reference no why someone would want to use 
`CancellationToken` instead of `isCancelled()` helper, e.g.
```
/// If cancellation checks are rare, one could use the isCancelled() helper to 
simplify the code.
/// However, if cancellation checks are frequent, the guideline is first obtain 
the CancellationToken for the currently running task with 
getCurrentCancellationToken() and do cancel checks using it to avoid extra 
lookups in the Context
```



Comment at: clangd/Cancellation.h:137
+  void log(llvm::raw_ostream &OS) const override {
+OS << "Task got cancelled.";
+  }

s/got/was?



Comment at: clangd/ClangdLSPServer.cpp:621
+  std::lock_guard Lock(TaskHandlesMutex);
+  const auto &it = TaskHandles.find(Params.ID);
+  if (it != TaskHandles.end()) {

Wouldn't it work incorrectly for string IDs?
When normalizing `json::Value` from `getRequestID`, we simply print out json. 
For strings, this should result in quoted output, e.g. `"req"`. However, when 
parsing `CancelParams`, we parse this json. So we'll end up inserting with a 
key `"req"` and erasing with a key 'req' (without the quotes).



Comment at: clangd/ClangdLSPServer.cpp:643
+  std::lock_guard Lock(TaskHandlesMutex);
+  TaskHandles.insert({NormalizedID, std::move(TH)});
+}

Could we `elog` if `insert` indicated that a value already exists in a map? 
This would probably mean malformed user input, but could also be immensely 
helpful for debugging.



Comment at: clangd/ClangdLSPServer.h:179
+  // associated with only their thread.
+  void CleanupTaskHandle();
+  void StoreTaskHandle(TaskHandle TH);

kadircet wrote:
> ilya-biryukov wrote:
> > These two methods look like a nice suit for better wrapped in a 
> > RAII-object. It would add the value to the associated map on construction 
> > and remove on destruction.
> > One problem is that all operations calls would become weird, because we'll 
> > have to move this RAII object around and moving into lambdas is not fun 
> > without C++14 (which allows `[x=std::move(y)]() {}`..
> > 
> > Maybe add a comment that calls to this function should always be paired and 
> > a FIXME that we should have an API that enforces this?
> > 
> Yeah that would be really nice to have them in a RAII object, but the thing 
> is cleanup can occur only after the task dies. Which we don't directly know 
> since threads are being detached. So the only way to trigger destruction is 
> at the callback, which is where I call cleanup currently. Maybe we can store 
> the object within context to trigger destructor at the end of the thread, but 
> still don't think it would look any better or ease the job of the caller.
Having these paired method calls is probably fine for the first iteration, but 
we should abstract away this pattern when supporting cancellations for more 
operations.
LG with a FIXME.



Comment at: clangd/ClangdServer.cpp:152
 
+  auto CancellableTaskHandle = TaskHandle::create();
+  auto CT = CancellableTaskHandle.createCancellationToken();

Maybe use a shorter name? E.g. `Task` or `TH` :-)



Comment at: clangd/ClangdServer.cpp:153
+  auto CancellableTaskHandle = TaskHandle::create();
+  auto CT = CancellableTaskHandle.createCancellationToken();
   // Copy PCHs to avoid accessing this->PCHs concurrently

Instead of moving cancellation token around explicitly, we could stash in a 
context right away and it would nicely propagate into the thread. This looks 
like less boilerplate.
E.g.
```
  auto CancellableTaskHandle = TaskHandle::create();
  WithContext 
ContextWithCancellation(setCurrentCancellationToken(TaskHandle.createCancellationToken()));

  auto Task = [](File, Callback CB, 
llvm::Expected IP) {
if (getCancellationToken().isCancelled())
  return CB(make_error());
   };
   /// rest of the code is the same
```



Comment at: clangd/ClangdServer.cpp:178
 
-  WorkScheduler.runWithPreamble("CodeComplete", File,
-Bind(Task, File.str(), std::move(CB)));
+  WorkScheduler.runWithPreamble(
+  "CodeComplete", File,

Thinking out loud: the TaskH

[PATCH] D50898: Suggest code-completions for overriding base class virtual methods.

2018-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: ilya-biryukov, hokein, ioeric.
Herald added subscribers: cfe-commits, arphaman, jkorous.

Whenever a code-completion is triggered within a class/struct/union looks at
base classes and figures out non-overriden virtual functions. Than suggests
completions for those.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50898

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -61,6 +61,7 @@
 MATCHER(InsertInclude, "") { return bool(arg.HeaderInsertion); }
 MATCHER_P(SnippetSuffix, Text, "") { return arg.SnippetSuffix == Text; }
 MATCHER_P(Origin, OriginSet, "") { return arg.Origin == OriginSet; }
+MATCHER(IsOverride, "") { return bool(arg.IsOverride); }
 
 // Shorthand for Contains(Named(Name)).
 Matcher &> Has(std::string Name) {
@@ -1648,6 +1649,58 @@
 SigDoc("Doc from sema";
 }
 
+TEST(CompletionTest, SuggestOverrides) {
+  constexpr const char *const Text(R"cpp(
+  class A {
+   public:
+virtual void vfunc(bool param);
+virtual void vfunc(bool param, int p);
+void func(bool param);
+  };
+  class B : public A {
+  virtual void ttt(bool param);
+  void vfunc(bool param, int p) override;
+  };
+  class C : public B {
+   public:
+void vfunc(bool param) override;
+^
+  };
+  )cpp");
+  const auto Results = completions(Text);
+  EXPECT_THAT(Results.Completions,
+  AllOf(Contains(AllOf(Named("vfunc"), IsOverride(),
+   Labeled("vfunc(bool param, int p)"))),
+Contains(AllOf(Named("ttt"), IsOverride(),
+   Labeled("ttt(bool param)"))),
+Not(Contains(AllOf(Named("vfunc"), IsOverride(),
+   Labeled("vfunc(bool param)"));
+}
+
+TEST(CompletionTest, RenderOverride) {
+  CodeCompletion C;
+  C.Name = "x";
+  C.Signature = "(bool) const";
+  C.SnippetSuffix = "(${0:bool})";
+  C.ReturnType = "int";
+  C.Documentation = "This is x().";
+  C.Kind = CompletionItemKind::Method;
+  C.Score.Total = 1.0;
+  C.Origin = SymbolOrigin::AST;
+  C.IsOverride = true;
+
+  CodeCompleteOptions Opts;
+  Opts.IncludeIndicator.NoInsert = "";
+  auto R = C.render(Opts);
+  EXPECT_EQ(R.label, "int x(bool) const override");
+  EXPECT_EQ(R.insertText, "int x(bool) const override");
+  EXPECT_EQ(R.insertTextFormat, InsertTextFormat::PlainText);
+  EXPECT_EQ(R.filterText, "x");
+  EXPECT_EQ(R.detail, "int");
+  EXPECT_EQ(R.documentation, "This is x().");
+  EXPECT_THAT(R.additionalTextEdits, IsEmpty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/CodeComplete.h
===
--- clangd/CodeComplete.h
+++ clangd/CodeComplete.h
@@ -127,6 +127,9 @@
   /// Holds the range of the token we are going to replace with this completion.
   Range CompletionTokenRange;
 
+  /// Whether this completion is for overriding a virtual method.
+  bool IsOverride = false;
+
   // Scores are used to rank completion items.
   struct Scores {
 // The score that items are ranked by.
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -188,6 +188,58 @@
   return HeaderFile{std::move(*Resolved), /*Verbatim=*/false};
 }
 
+// First traverses all method definitions inside current class/struct/union
+// definition. Than traverses base classes to find virtual methods that haven't
+// been overriden within current context.
+// FIXME(kadircet): Currently we cannot see declarations below completion point.
+// It is because Sema gets run only upto completion point. Need to find a
+// solution to run it for the whole class/struct/union definition.
+static std::vector
+getVirtualNonOverridenMethods(const DeclContext *DC, Sema *S) {
+  const auto *CR = llvm::dyn_cast(DC);
+  // If not inside a class/struct/union return empty.
+  if (!CR)
+return {};
+  // First store overrides within current class.
+  // These are stored by name to make querying fast in the later step.
+  llvm::StringMap> Overrides;
+  for (auto *Method : dyn_cast(DC)->methods()) {
+if (!Method->isVirtual())
+  continue;
+const std::string Name = Method->getNameAsString();
+const auto it = Overrides.find(Name);
+if (it == Overrides.end())
+  Overrides.insert({Name, {Method}});
+else
+  it->second.push_back(Method);
+  }
+
+  std::vector Results;
+  for (const auto &Base : CR->bases()) {
+const auto *BR = Base.getType().getTypePtr()->getAsCXXRecordDecl();
+for (auto *Method : BR->methods()) {
+  if (!Method->isVirtual())
+continue;
+  const s

r340029 - [Preamble] Empty preamble is not an error.

2018-08-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 17 07:25:10 2018
New Revision: 340029

URL: http://llvm.org/viewvc/llvm-project?rev=340029&view=rev
Log:
[Preamble] Empty preamble is not an error.

Summary:
Empty preamble is valid for source file which doesn't have any
preprocessor and #includes.

This patch makes clang treat an empty preamble as a normal preamble.

Check: ninja check-clang

A testcase is added in https://reviews.llvm.org/D50627.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp

Modified: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h?rev=340029&r1=340028&r2=340029&view=diff
==
--- cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h (original)
+++ cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h Fri Aug 17 07:25:10 
2018
@@ -286,8 +286,7 @@ public:
 };
 
 enum class BuildPreambleError {
-  PreambleIsEmpty = 1,
-  CouldntCreateTempFile,
+  CouldntCreateTempFile = 1,
   CouldntCreateTargetInfo,
   BeginSourceFileFailed,
   CouldntEmitPCH

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=340029&r1=340028&r2=340029&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Aug 17 07:25:10 2018
@@ -1363,7 +1363,6 @@ ASTUnit::getMainBufferWithPrecompiledPre
 } else {
   switch (static_cast(NewPreamble.getError().value())) 
{
   case BuildPreambleError::CouldntCreateTempFile:
-  case BuildPreambleError::PreambleIsEmpty:
 // Try again next time.
 PreambleRebuildCounter = 1;
 return nullptr;

Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=340029&r1=340028&r2=340029&view=diff
==
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Fri Aug 17 07:25:10 2018
@@ -237,9 +237,6 @@ llvm::ErrorOr Preco
 PreambleCallbacks &Callbacks) {
   assert(VFS && "VFS is null");
 
-  if (!Bounds.Size)
-return BuildPreambleError::PreambleIsEmpty;
-
   auto PreambleInvocation = std::make_shared(Invocation);
   FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts();
   PreprocessorOptions &PreprocessorOpts =
@@ -423,9 +420,6 @@ bool PrecompiledPreamble::CanReuse(const
   PreprocessorOptions &PreprocessorOpts =
   PreambleInvocation->getPreprocessorOpts();
 
-  if (!Bounds.Size)
-return false;
-
   // We've previously computed a preamble. Check whether we have the same
   // preamble now that we did before, and that there's enough space in
   // the main-file buffer within the precompiled preamble to fit the
@@ -758,8 +752,6 @@ const char *BuildPreambleErrorCategory::
 
 std::string BuildPreambleErrorCategory::message(int condition) const {
   switch (static_cast(condition)) {
-  case BuildPreambleError::PreambleIsEmpty:
-return "Preamble is empty";
   case BuildPreambleError::CouldntCreateTempFile:
 return "Could not create temporary file for PCH";
   case BuildPreambleError::CouldntCreateTargetInfo:


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


[PATCH] D50628: [Preamble] Empty preamble is not an error.

2018-08-17 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC340029: [Preamble] Empty preamble is not an error. (authored 
by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50628?vs=160319&id=161241#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50628

Files:
  include/clang/Frontend/PrecompiledPreamble.h
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/PrecompiledPreamble.cpp


Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1363,7 +1363,6 @@
 } else {
   switch (static_cast(NewPreamble.getError().value())) 
{
   case BuildPreambleError::CouldntCreateTempFile:
-  case BuildPreambleError::PreambleIsEmpty:
 // Try again next time.
 PreambleRebuildCounter = 1;
 return nullptr;
Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -237,9 +237,6 @@
 PreambleCallbacks &Callbacks) {
   assert(VFS && "VFS is null");
 
-  if (!Bounds.Size)
-return BuildPreambleError::PreambleIsEmpty;
-
   auto PreambleInvocation = std::make_shared(Invocation);
   FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts();
   PreprocessorOptions &PreprocessorOpts =
@@ -423,9 +420,6 @@
   PreprocessorOptions &PreprocessorOpts =
   PreambleInvocation->getPreprocessorOpts();
 
-  if (!Bounds.Size)
-return false;
-
   // We've previously computed a preamble. Check whether we have the same
   // preamble now that we did before, and that there's enough space in
   // the main-file buffer within the precompiled preamble to fit the
@@ -758,8 +752,6 @@
 
 std::string BuildPreambleErrorCategory::message(int condition) const {
   switch (static_cast(condition)) {
-  case BuildPreambleError::PreambleIsEmpty:
-return "Preamble is empty";
   case BuildPreambleError::CouldntCreateTempFile:
 return "Could not create temporary file for PCH";
   case BuildPreambleError::CouldntCreateTargetInfo:
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -286,8 +286,7 @@
 };
 
 enum class BuildPreambleError {
-  PreambleIsEmpty = 1,
-  CouldntCreateTempFile,
+  CouldntCreateTempFile = 1,
   CouldntCreateTargetInfo,
   BeginSourceFileFailed,
   CouldntEmitPCH


Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1363,7 +1363,6 @@
 } else {
   switch (static_cast(NewPreamble.getError().value())) {
   case BuildPreambleError::CouldntCreateTempFile:
-  case BuildPreambleError::PreambleIsEmpty:
 // Try again next time.
 PreambleRebuildCounter = 1;
 return nullptr;
Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -237,9 +237,6 @@
 PreambleCallbacks &Callbacks) {
   assert(VFS && "VFS is null");
 
-  if (!Bounds.Size)
-return BuildPreambleError::PreambleIsEmpty;
-
   auto PreambleInvocation = std::make_shared(Invocation);
   FrontendOptions &FrontendOpts = PreambleInvocation->getFrontendOpts();
   PreprocessorOptions &PreprocessorOpts =
@@ -423,9 +420,6 @@
   PreprocessorOptions &PreprocessorOpts =
   PreambleInvocation->getPreprocessorOpts();
 
-  if (!Bounds.Size)
-return false;
-
   // We've previously computed a preamble. Check whether we have the same
   // preamble now that we did before, and that there's enough space in
   // the main-file buffer within the precompiled preamble to fit the
@@ -758,8 +752,6 @@
 
 std::string BuildPreambleErrorCategory::message(int condition) const {
   switch (static_cast(condition)) {
-  case BuildPreambleError::PreambleIsEmpty:
-return "Preamble is empty";
   case BuildPreambleError::CouldntCreateTempFile:
 return "Could not create temporary file for PCH";
   case BuildPreambleError::CouldntCreateTargetInfo:
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -286,8 +286,7 @@
 };
 
 enum class BuildPreambleError {
-  PreambleIsEmpty = 1,
-  CouldntCreateTempFile,
+  CouldntCreateTempFile = 1,
   CouldntCreateTargetInfo,
   BeginSourceFileFailed,
   CouldntEmitPCH
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50835: [clangd] Add parantheses while auto-completing functions.

2018-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 161243.
kadircet added a comment.

- Change option name.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50835

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -1590,6 +1590,56 @@
   ElementsAre(Sig("foo(T, U) -> void", {"T", "U"})));
 }
 
+TEST(CompletionTest, RenderWithSnippetsForFunctionArgsDisabled) {
+  CodeCompleteOptions Opts;
+  Opts.EnableFunctionArgSnippets = true;
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "()";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::PlainText);
+  }
+
+  Opts.EnableSnippets = true;
+  Opts.EnableFunctionArgSnippets = false;
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "()";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x()");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "(${0:bool})";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x(${0})");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/CodeComplete.h
===
--- clangd/CodeComplete.h
+++ clangd/CodeComplete.h
@@ -82,6 +82,10 @@
   /// Include completions that require small corrections, e.g. change '.' to
   /// '->' on member access etc.
   bool IncludeFixIts = false;
+
+  /// Whether to generate snippets for function arguments on code-completion.
+  /// Needs snippets to be enabled as well.
+  bool EnableFunctionArgSnippets = true;
 };
 
 // Semi-structured representation of a code-complete suggestion for our C++ 
API.
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -1371,8 +1371,14 @@
   LSP.additionalTextEdits.push_back(FixIt);
 }
   }
-  if (Opts.EnableSnippets)
-LSP.textEdit->newText += SnippetSuffix;
+  if (Opts.EnableSnippets && !SnippetSuffix.empty()) {
+if (Opts.EnableFunctionArgSnippets)
+  LSP.textEdit->newText += SnippetSuffix;
+else
+  // Check whether function has any parameters or not.
+  LSP.textEdit->newText += SnippetSuffix.size() > 2 ? "(${0})" : "()";
+  }
+
   // FIXME(kadircet): Do not even fill insertText after making sure textEdit is
   // compatible with most of the editors.
   LSP.insertText = LSP.textEdit->newText;


Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -1590,6 +1590,56 @@
   ElementsAre(Sig("foo(T, U) -> void", {"T", "U"})));
 }
 
+TEST(CompletionTest, RenderWithSnippetsForFunctionArgsDisabled) {
+  CodeCompleteOptions Opts;
+  Opts.EnableFunctionArgSnippets = true;
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "()";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::PlainText);
+  }
+
+  Opts.EnableSnippets = true;
+  Opts.EnableFunctionArgSnippets = false;
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "()";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x()");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "(${0:bool})";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x(${0})");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/CodeComplete.h
===
--- clangd/CodeComplete

[PATCH] D50835: [clangd] Add parantheses while auto-completing functions.

2018-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 3 inline comments as done.
kadircet added inline comments.



Comment at: clangd/CodeComplete.cpp:1377
+  // Check whether function has any parameters or not.
+  LSP.textEdit->newText += SnippetSuffix.size() > 2 ? "(${0})" : "()";
+else

ioeric wrote:
> There seems to be no guarantee on whether the snippet is function arg 
> template when `SnippetSuffix.size() > 2`. A heuristic we could use is 
> probably checking that the template starts with `(` and ends with `)`? 
> Alternatively, we could try to avoid generating the proper snippet according 
> to the flag when we still have the function declaration around. Not sure if 
> this is feasible for index results though.
Actually I was first trying to directly look at function argument count as you 
mentioned, but unfortunately Symbols coming from index don't have any 
declarations. Therefore it turns back to looking at Signature in this case, 
which is same with this one. Apart from that, IIUC, SnippetSuffix contains 
anything only when completion item is a function otherwise it is empty. So IMO 
this check should be OK.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50835



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


[PATCH] D50896: [clangd] Add xrefs LSP boilerplate implementation.

2018-08-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/XRefs.cpp:665
+std::vector references(ParsedAST &AST, Position Pos,
+ bool IncludeDeclaration,
+ const SymbolIndex *Index) {

Are we going to support the `IncludeDeclaration` option?
What should its semantics be?

I'm trying to figure out a better name for it, can't get what should it do by 
looking at the code at the moment :-)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50896



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


[PATCH] D50542: [clang-tidy] Add abseil-no-internal-deps check

2018-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tidy/abseil/NoInternalDepsCheck.cpp:20
+
+bool IsInAbseilFile(const SourceManager& manager, SourceLocation loc){
+  if (loc.isInvalid()) {

I think we can make it as an ASTMatcher instead of a function like:

```
AST_POLYMORPHIC_MATCHER_P(isInAbseilFile,
  AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) 
{
   // your code here.
}
```


https://reviews.llvm.org/D50542



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


[PATCH] D50876: Clean up newly created header

2018-08-17 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added inline comments.



Comment at: include/bit:117
+  unsigned long __where;
   // Search from LSB to MSB for first set bit.
   // Returns zero if no set bit is found.

lebedev.ri wrote:
> Like i commented in the original review, this should probably be 
> ```
> // Search from *M*SB to *L*SB for first set bit.
> ```
I think my preference would be to just remove the comment.


https://reviews.llvm.org/D50876



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


[PATCH] D50259: [OpenCL] Disallow negative attribute arguments

2018-08-17 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D50259



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


[PATCH] D50896: [clangd] Add xrefs LSP boilerplate implementation.

2018-08-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clangd/XRefs.cpp:665
+std::vector references(ParsedAST &AST, Position Pos,
+ bool IncludeDeclaration,
+ const SymbolIndex *Index) {

ilya-biryukov wrote:
> Are we going to support the `IncludeDeclaration` option?
> What should its semantics be?
> 
> I'm trying to figure out a better name for it, can't get what should it do by 
> looking at the code at the moment :-)
I think so. It is a term defined in LSP (although vscode always sets it 
`true`).  I think it aligns with the `clang::index::SymbolRole::Declaration`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50896



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


[clang-tools-extra] r340035 - [clangd] Add a testcase for empty preamble.

2018-08-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Aug 17 07:55:57 2018
New Revision: 340035

URL: http://llvm.org/viewvc/llvm-project?rev=340035&view=rev
Log:
[clangd] Add a testcase for empty preamble.

Summary: This is a patch of add a testcase for https://reviews.llvm.org/D50628.

Reviewers: ilya-biryukov

Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp?rev=340035&r1=340034&r2=340035&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp Fri Aug 17 
07:55:57 2018
@@ -308,6 +308,51 @@ TEST_F(TUSchedulerTests, EvictedAST) {
   UnorderedElementsAre(Foo, AnyOf(Bar, Baz)));
 }
 
+TEST_F(TUSchedulerTests, EmptyPreamble) {
+  TUScheduler S(
+  /*AsyncThreadsCount=*/4, /*StorePreambleInMemory=*/true,
+  PreambleParsedCallback(),
+  /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+  ASTRetentionPolicy());
+
+  auto Foo = testPath("foo.cpp");
+  auto Header = testPath("foo.h");
+
+  Files[Header] = "void foo()";
+  Timestamps[Header] = time_t(0);
+  auto WithPreamble = R"cpp(
+#include "foo.h"
+int main() {}
+  )cpp";
+  auto WithEmptyPreamble = R"cpp(int main() {})cpp";
+  S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  S.runWithPreamble("getNonEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get a non-empty preamble.
+  EXPECT_GT(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+
+  // Update the file which results in an empty preamble.
+  S.update(Foo, getInputs(Foo, WithEmptyPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  S.runWithPreamble("getEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get an empty preamble.
+  EXPECT_EQ(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+}
+
 TEST_F(TUSchedulerTests, RunWaitsForPreamble) {
   // Testing strategy: we update the file and schedule a few preamble reads at
   // the same time. All reads should get the same non-null preamble.


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


[PATCH] D50627: [clangd] Add a testcase for empty preamble.

2018-08-17 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340035: [clangd] Add a testcase for empty preamble. 
(authored by hokein, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D50627

Files:
  clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp


Index: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
@@ -308,6 +308,51 @@
   UnorderedElementsAre(Foo, AnyOf(Bar, Baz)));
 }
 
+TEST_F(TUSchedulerTests, EmptyPreamble) {
+  TUScheduler S(
+  /*AsyncThreadsCount=*/4, /*StorePreambleInMemory=*/true,
+  PreambleParsedCallback(),
+  /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+  ASTRetentionPolicy());
+
+  auto Foo = testPath("foo.cpp");
+  auto Header = testPath("foo.h");
+
+  Files[Header] = "void foo()";
+  Timestamps[Header] = time_t(0);
+  auto WithPreamble = R"cpp(
+#include "foo.h"
+int main() {}
+  )cpp";
+  auto WithEmptyPreamble = R"cpp(int main() {})cpp";
+  S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  S.runWithPreamble("getNonEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get a non-empty preamble.
+  EXPECT_GT(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+
+  // Update the file which results in an empty preamble.
+  S.update(Foo, getInputs(Foo, WithEmptyPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  S.runWithPreamble("getEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get an empty preamble.
+  EXPECT_EQ(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+}
+
 TEST_F(TUSchedulerTests, RunWaitsForPreamble) {
   // Testing strategy: we update the file and schedule a few preamble reads at
   // the same time. All reads should get the same non-null preamble.


Index: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
@@ -308,6 +308,51 @@
   UnorderedElementsAre(Foo, AnyOf(Bar, Baz)));
 }
 
+TEST_F(TUSchedulerTests, EmptyPreamble) {
+  TUScheduler S(
+  /*AsyncThreadsCount=*/4, /*StorePreambleInMemory=*/true,
+  PreambleParsedCallback(),
+  /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+  ASTRetentionPolicy());
+
+  auto Foo = testPath("foo.cpp");
+  auto Header = testPath("foo.h");
+
+  Files[Header] = "void foo()";
+  Timestamps[Header] = time_t(0);
+  auto WithPreamble = R"cpp(
+#include "foo.h"
+int main() {}
+  )cpp";
+  auto WithEmptyPreamble = R"cpp(int main() {})cpp";
+  S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  S.runWithPreamble("getNonEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get a non-empty preamble.
+  EXPECT_GT(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+
+  // Update the file which results in an empty preamble.
+  S.update(Foo, getInputs(Foo, WithEmptyPreamble), WantDiagnostics::Auto,
+   [](std::vector) {});
+  // Wait for the preamble is being built.
+  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+  S.runWithPreamble("getEmptyPreamble", Foo,
+[&](llvm::Expected Preamble) {
+  // We expect to get an empty preamble.
+  EXPECT_EQ(cantFail(std::move(Preamble))
+.Preamble->Preamble.getBounds()
+.Size,
+0u);
+});
+}
+
 TEST_F(TUSchedulerTests, RunWaitsForPreamble) {
   // Testing strategy: we update the file and schedule a few p

[PATCH] D50337: [clangd] DexIndex implementation prototype

2018-08-17 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 161252.
kbobyrev marked 9 inline comments as done.
kbobyrev added a comment.

Address another round of comments.


https://reviews.llvm.org/D50337

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/DexIndex.cpp
  clang-tools-extra/clangd/index/dex/DexIndex.h
  clang-tools-extra/clangd/index/dex/Token.h
  clang-tools-extra/unittests/clangd/CMakeLists.txt
  clang-tools-extra/unittests/clangd/DexIndexTests.cpp
  clang-tools-extra/unittests/clangd/IndexTests.cpp
  clang-tools-extra/unittests/clangd/TestIndex.cpp
  clang-tools-extra/unittests/clangd/TestIndex.h

Index: clang-tools-extra/unittests/clangd/TestIndex.h
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/TestIndex.h
@@ -0,0 +1,57 @@
+//===-- IndexHelpers.h --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_INDEXTESTCOMMON_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_INDEXTESTCOMMON_H
+
+#include "index/Index.h"
+#include "index/Merge.h"
+#include "index/dex/DexIndex.h"
+#include "index/dex/Iterator.h"
+#include "index/dex/Token.h"
+#include "index/dex/Trigram.h"
+
+namespace clang {
+namespace clangd {
+
+Symbol symbol(llvm::StringRef QName);
+
+struct SlabAndPointers {
+  SymbolSlab Slab;
+  std::vector Pointers;
+};
+
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
+std::shared_ptr>
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols = nullptr);
+
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols = nullptr);
+
+std::string getQualifiedName(const Symbol &Sym);
+
+std::vector match(const SymbolIndex &I,
+   const FuzzyFindRequest &Req,
+   bool *Incomplete = nullptr);
+
+// Returns qualified names of symbols with any of IDs in the index.
+std::vector lookup(const SymbolIndex &I,
+llvm::ArrayRef IDs);
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/unittests/clangd/TestIndex.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/TestIndex.cpp
@@ -0,0 +1,89 @@
+//===-- IndexHelpers.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestIndex.h"
+
+namespace clang {
+namespace clangd {
+
+Symbol symbol(llvm::StringRef QName) {
+  Symbol Sym;
+  Sym.ID = SymbolID(QName.str());
+  size_t Pos = QName.rfind("::");
+  if (Pos == llvm::StringRef::npos) {
+Sym.Name = QName;
+Sym.Scope = "";
+  } else {
+Sym.Name = QName.substr(Pos + 2);
+Sym.Scope = QName.substr(0, Pos + 2);
+  }
+  return Sym;
+}
+
+// Create a slab of symbols with the given qualified names as both IDs and
+// names. The life time of the slab is managed by the returned shared pointer.
+// If \p WeakSymbols is provided, it will be pointed to the managed object in
+// the returned shared pointer.
+std::shared_ptr>
+generateSymbols(std::vector QualifiedNames,
+std::weak_ptr *WeakSymbols) {
+  SymbolSlab::Builder Slab;
+  for (llvm::StringRef QName : QualifiedNames)
+Slab.insert(symbol(QName));
+
+  auto Storage = std::make_shared();
+  Storage->Slab = std::move(Slab).build();
+  for (const auto &Sym : Storage->Slab)
+Storage->Pointers.push_back(&Sym);
+  if (WeakSymbols)
+*WeakSymbols = Storage;
+  auto *Pointers = &Storage->Pointers;
+  return {std::move(Storage), Pointers};
+}
+
+// Create a slab of symbols with IDs and names [Begin, End], otherwise identical
+// to the `generateSymbols` above.
+std::shared_ptr>
+generateNumSymbols(int Begin, int End,
+   std::weak_ptr *WeakSymbols) {
+  std::vector Names;
+  for (int i = Begin; i <= End; i++)
+Names.push_back(std::to_string(i));
+  return generateSymbols(Names, WeakSymbols);
+}
+
+std::string getQualifiedName(const Symbol &Sym) {
+  return (Sym.Scope + Sym.Name).str();
+}
+
+std::vector match(const SymbolIndex &I,
+

[PATCH] D50876: Clean up newly created header

2018-08-17 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added inline comments.



Comment at: include/bit:61
+inline _LIBCPP_INLINE_VISIBILITY
+int __popcount(unsigned __x)   { return __builtin_popcount  (__x); }
+

ldionne wrote:
> Funny spacing between `__builtin_popcount` and `(__x)`
It's actually there to line up with the ones below.
(Though now that I look, I didn't do that for the ones above)


https://reviews.llvm.org/D50876



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D50845#1203991, @ABataev wrote:

> In https://reviews.llvm.org/D50845#1203973, @Hahnfeld wrote:
>
> > In https://reviews.llvm.org/D50845#1203967, @ABataev wrote:
> >
> > > I thought about this approach already. But it won't work in general. The 
> > > main problem here is that host and device compilation phases may end up 
> > > with the different set of implicit declare target functions. The main 
> > > problem here not the user code, but the system libraries, which may use 
> > > the different set of functions.
> >
> >
> > How common is that for functions that are used in `target` regions? In the 
> > worst case we can make my fourth point a warning and lose Sema checking for 
> > those functions.
>
>
> It does not matter how common is it or not. If the bad situation can happen, 
> it will happen.
>  Warning won't work here, because, again, you may end up with the code that 
> may cause compiler crash for the device. For example, if the system function 
> uses throw/catch stmts, we may emit the warning for this function, but will 
> have troubles during the codegen.


Right, warning wasn't a good thought. We really want strict checking and would 
have to error out when we find a function that wasn't implicitly `declare 
target` on the host.
I meant to ask how common that would be? If that's only some known functions we 
could handle them separately.

>>> The best solution is to use only device specific header files. Device 
>>> compilation phase should use system header files for the host at all.
>> 
>> You mean "shouldn't use system header files for the host"? I think that may 
>> be hard to achieve, especially if we want to Sema check all of the source 
>> code during device compilation.
> 
> Yes, I mean should not. Yes, this is hard to achieve but that's the only 
> complete and correct solution. Everything else looks like a non-stable hack.

How do you propose to handle inline assembly in non-system header files?


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50901: [clang][ubsan] Split Implicit Integer Truncation Sanitizer into unsigned and signed checks

2018-08-17 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added reviewers: rsmith, vsk, Sanitizers.
lebedev.ri added projects: Sanitizers, clang.

As per IRC disscussion, it seems we really want to have more fine-grained 
`-fsanitize=implicit-integer-truncation`:

- A check when both of the types are unsigned.
- Another check for the other cases (either one of the types is signed, or both 
of the types is signed).

This is clang part.
Compiler-rt part is .


Repository:
  rC Clang

https://reviews.llvm.org/D50901

Files:
  docs/UndefinedBehaviorSanitizer.rst
  include/clang/Basic/Sanitizers.def
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGen/catch-implicit-integer-conversions-basics.c
  test/CodeGen/catch-implicit-integer-truncations-basics-negatives.c
  test/CodeGen/catch-implicit-integer-truncations-basics.c
  test/CodeGen/catch-implicit-integer-truncations.c
  test/CodeGen/catch-implicit-signed-integer-truncations-basics-negatives.c
  test/CodeGen/catch-implicit-signed-integer-truncations-basics.c
  test/CodeGen/catch-implicit-unsigned-integer-truncations-basics-negatives.c
  test/CodeGen/catch-implicit-unsigned-integer-truncations-basics.c
  test/CodeGenCXX/catch-implicit-integer-truncations.cpp
  test/Driver/fsanitize.c

Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -29,22 +29,37 @@
 // CHECK-COVERAGE-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone-x86_64.lib"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=integer %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-INTEGER -implicit-check-not="-fsanitize-address-use-after-scope"
-// CHECK-INTEGER: "-fsanitize={{((signed-integer-overflow|unsigned-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|implicit-integer-truncation),?){6}"}}
+// CHECK-INTEGER: "-fsanitize={{((signed-integer-overflow|unsigned-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|implicit-unsigned-integer-truncation|implicit-signed-integer-truncation),?){7}"}}
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-conversion %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-implicit-conversion,CHECK-implicit-conversion-RECOVER
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-conversion -fsanitize-recover=implicit-conversion %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-implicit-conversion,CHECK-implicit-conversion-RECOVER
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-conversion -fno-sanitize-recover=implicit-conversion %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-implicit-conversion,CHECK-implicit-conversion-NORECOVER
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-conversion -fsanitize-trap=implicit-conversion %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-implicit-conversion,CHECK-implicit-conversion-TRAP
-// CHECK-implicit-conversion: "-fsanitize={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-RECOVER: "-fsanitize-recover={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-RECOVER-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-RECOVER-NOT: "-fsanitize-trap={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-NORECOVER-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation),?){1}"}} // ???
-// CHECK-implicit-conversion-NORECOVER-NOT: "-fsanitize-recover={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-NORECOVER-NOT: "-fsanitize-trap={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-TRAP: "-fsanitize-trap={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-TRAP-NOT: "-fsanitize-recover={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-TRAP-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation),?){1}"}}
+// CHECK-implicit-conversion: "-fsanitize={{((implicit-unsigned-integer-truncation|implicit-signed-integer-truncation),?){2}"}}
+// CHECK-implicit-conversion-RECOVER: "-fsanitize-recover={{((implicit-unsigned-integer-truncation|implicit-signed-integer-truncation),?){2}"}}
+// CHECK-implicit-conversion-RECOVER-NOT: "-fno-sanitize-recover={{((implicit-unsigned-integer-truncation|implicit-signed-integer-truncation),?){2}"}}
+// CHECK-implicit-conversion-RECOVER-NOT: "-fsanitize-trap={{((implicit-unsigned-integer-truncation|implicit-signed-integer-truncation),?){2}"}}
+// CHECK-implicit-conversion-NORECOVER-NOT: "-fno-sanitize-recover={{((implicit-unsigned-integer-truncation|implicit-signed-integer-truncation),?){2}"}} // ???
+// CHECK-implicit-conversion-NORECOVER-NOT: "-fsanitize-recover={{((implicit-unsigned-integer-truncation|implicit-signed-integer-truncation),?){2}"}}
+// CHECK-implicit-conversion-NORECOVER-NOT: "-fsanitize-trap={{((implicit-unsigned-integer-truncation|implicit-signed-integer-truncation),?){2}"}}
+// CHECK-implicit-conversion-TRAP: "-fsanitize-trap={{((implici

[PATCH] D50259: [OpenCL] Disallow negative attribute arguments

2018-08-17 Thread Alexey Bader via Phabricator via cfe-commits
bader accepted this revision.
bader added a comment.

LGTM.
Please, remove "Change-Id: I910b5c077f5f29e02a1572d9202f0fdbea5280fd" from the 
log message - it not relevant to the project.


Repository:
  rC Clang

https://reviews.llvm.org/D50259



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

> Right, warning wasn't a good thought. We really want strict checking and 
> would have to error out when we find a function that wasn't implicitly 
> `declare target` on the host.
>  I meant to ask how common that would be? If that's only some known functions 
> we could handle them separately.

Again, it does not matter how common is this situation. We cannot rely on the 
probability here, we need to make the compiler to work correctly in all 
possible situation, no matter how often they can occur.

 The best solution is to use only device specific header files. Device 
 compilation phase should use system header files for the host at all.
>>> 
>>> You mean "shouldn't use system header files for the host"? I think that may 
>>> be hard to achieve, especially if we want to Sema check all of the source 
>>> code during device compilation.
>> 
>> Yes, I mean should not. Yes, this is hard to achieve but that's the only 
>> complete and correct solution. Everything else looks like a non-stable hack.
> 
> How do you propose to handle inline assembly in non-system header files?

Just like as usual - if the assembler is supported by the device - it is ok, 
otherwise - error message.


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50835: [clangd] Add parantheses while auto-completing functions.

2018-08-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/CodeComplete.cpp:1377
+  // Check whether function has any parameters or not.
+  LSP.textEdit->newText += SnippetSuffix.size() > 2 ? "(${0})" : "()";
+else

kadircet wrote:
> ioeric wrote:
> > There seems to be no guarantee on whether the snippet is function arg 
> > template when `SnippetSuffix.size() > 2`. A heuristic we could use is 
> > probably checking that the template starts with `(` and ends with `)`? 
> > Alternatively, we could try to avoid generating the proper snippet 
> > according to the flag when we still have the function declaration around. 
> > Not sure if this is feasible for index results though.
> Actually I was first trying to directly look at function argument count as 
> you mentioned, but unfortunately Symbols coming from index don't have any 
> declarations. Therefore it turns back to looking at Signature in this case, 
> which is same with this one. Apart from that, IIUC, SnippetSuffix contains 
> anything only when completion item is a function otherwise it is empty. So 
> IMO this check should be OK.
> Apart from that, IIUC, SnippetSuffix contains anything only when completion 
> item is a function otherwise it is empty. So IMO this check should be OK.
This seems to be true for the current use cases, but I suspect the assumption 
can change when we add more snippet-based completion results in the future e.g. 
a snippet for if-statement `if (${0}) {${1}}`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50835



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


[PATCH] D50845: [CUDA/OpenMP] Define only some host macros during device compilation

2018-08-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D50845#1204210, @ABataev wrote:

> > Right, warning wasn't a good thought. We really want strict checking and 
> > would have to error out when we find a function that wasn't implicitly 
> > `declare target` on the host.
> >  I meant to ask how common that would be? If that's only some known 
> > functions we could handle them separately.
>
> Again, it does not matter how common is this situation. We cannot rely on the 
> probability here, we need to make the compiler to work correctly in all 
> possible situation, no matter how often they can occur.


Got that, I agree on the conservative approach: If we find a function to be 
called that wasn't checked (because it wasn't implicitly `declare target` on 
the host) the compiler can error out. That should be correct in all cases, 
shouldn't it?

There's a trade-off here:

- How many TUs pass full analysis and how many don't? (today's situation; we 
know that some headers don't work)
- How many TUs pass when we only check called functions (and error if we call 
non-checked ones) and how many regress compared to today's situation?

If the number of regressions is zero for all practical situations but we can 
compile some important cases, that should be a win.

> The best solution is to use only device specific header files. Device 
> compilation phase should use system header files for the host at all.
 
 You mean "shouldn't use system header files for the host"? I think that 
 may be hard to achieve, especially if we want to Sema check all of the 
 source code during device compilation.
>>> 
>>> Yes, I mean should not. Yes, this is hard to achieve but that's the only 
>>> complete and correct solution. Everything else looks like a non-stable hack.
>> 
>> How do you propose to handle inline assembly in non-system header files?
> 
> Just like as usual - if the assembler is supported by the device - it is ok, 
> otherwise - error message.

Even if the function is never called? That would mean you can't include any 
`Eigen` header...


Repository:
  rC Clang

https://reviews.llvm.org/D50845



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


[PATCH] D50835: [clangd] Add parantheses while auto-completing functions.

2018-08-17 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 161256.
kadircet added a comment.

- Only append to snippets of type function or method.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50835

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -1590,6 +1590,58 @@
   ElementsAre(Sig("foo(T, U) -> void", {"T", "U"})));
 }
 
+TEST(CompletionTest, RenderWithSnippetsForFunctionArgsDisabled) {
+  CodeCompleteOptions Opts;
+  Opts.EnableFunctionArgSnippets = true;
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "()";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::PlainText);
+  }
+
+  Opts.EnableSnippets = true;
+  Opts.EnableFunctionArgSnippets = false;
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "()";
+C.Kind = CompletionItemKind::Method;
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x()");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "(${0:bool})";
+C.Kind = CompletionItemKind::Function;
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x(${0})");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/CodeComplete.h
===
--- clangd/CodeComplete.h
+++ clangd/CodeComplete.h
@@ -82,6 +82,10 @@
   /// Include completions that require small corrections, e.g. change '.' to
   /// '->' on member access etc.
   bool IncludeFixIts = false;
+
+  /// Whether to generate snippets for function arguments on code-completion.
+  /// Needs snippets to be enabled as well.
+  bool EnableFunctionArgSnippets = true;
 };
 
 // Semi-structured representation of a code-complete suggestion for our C++ API.
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -1371,8 +1371,17 @@
   LSP.additionalTextEdits.push_back(FixIt);
 }
   }
-  if (Opts.EnableSnippets)
-LSP.textEdit->newText += SnippetSuffix;
+  if (Opts.EnableSnippets && !SnippetSuffix.empty()) {
+if (Opts.EnableFunctionArgSnippets)
+  LSP.textEdit->newText += SnippetSuffix;
+else if ((Kind == CompletionItemKind::Function ||
+  Kind == CompletionItemKind::Method) &&
+ SnippetSuffix.front() == '(' && SnippetSuffix.back() == ')') {
+  // Check whether function has any parameters or not.
+  LSP.textEdit->newText += SnippetSuffix.size() > 2 ? "(${0})" : "()";
+}
+  }
+
   // FIXME(kadircet): Do not even fill insertText after making sure textEdit is
   // compatible with most of the editors.
   LSP.insertText = LSP.textEdit->newText;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50337: [clangd] DexIndex implementation prototype

2018-08-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:97
+}
+// FIXME(kbobyrev): Add True iterator as soon as it's implemented 
otherwise.
+// If TopLevelChildren vector will be empty it will trigger an assertion.

As discussed offline, triggering assertion seems to be a pretty bad behavior. 
Although the trigram generation, as you suggested, always more than one token, 
we should try to get rid of this FIXME by introducing the true iterator as 
proposed here.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.cpp:121
+std::vector SymbolDocIDs = consume(*QueryIterator, ItemsToRetrieve);
+More = SymbolDocIDs.size() >= Req.MaxCandidateCount;
+

Still, we shouldn't set `More` here.



Comment at: clang-tools-extra/clangd/index/dex/DexIndex.h:58
+private:
+  std::shared_ptr> Symbols;
+  llvm::DenseMap LookupTable;

nit: add /*GUARDED_BY(Mutex)*/



Comment at: clang-tools-extra/unittests/clangd/DexIndexTests.cpp:366
+
+TEST(DexIndex, FuzzyFind) {
+  DexIndex Index;

Please add tests with empty `Query`.


https://reviews.llvm.org/D50337



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


  1   2   3   >