[PATCH] D40486: [clangd] Implemented logging using Context

2017-12-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In https://reviews.llvm.org/D40486#945193, @ilya-biryukov wrote:

> I'll update the implementation and place the `Context` as the first parameter 
> everywhere instead.
>  Could you take a look at other changes in the patch while I'm at it?


Just pinging this - there's still places where Context is in a different 
position (at least in ClangdServer)




Comment at: clangd/ClangdServer.cpp:36
 
-  ~FulfillPromiseGuard() { Promise.set_value(); }
+  ~FulfillContextPromiseGuard() { Promise.set_value(std::move(Ctx)); }
 

ilya-biryukov wrote:
> sammccall wrote:
> > Yikes, I can see how we got here, but we really don't get to move out of 
> > something we received an lvalue-reference to...
> > 
> > I think a safer idiom here is turning a whole lambda into a destructor:
> > 
> >auto Fulfil = MakeDestructor([&]{
> >   DonePromise.set_value(std::move(Ctx));
> >});
> > 
> > I'm not sure if LLVM has a shared utility for this, I've seen it in other 
> > codebases. Either way we could just define it here.
> > 
> > (Or we could copy the context to avoid the awkwardness)
> Thanks for suggestion. I totally agree, callbacks on scope exit are better.
> 
> I couldn't find an utility like that in LLVM, but I think it's a useful one. 
> I'll add this locally to this file, but maybe we should make this helper 
> public and put it into clangd?
> What are you thoughts on that?
Sounds good. I'm wary of adding lots of tiny utility headers - maybe if we 
squint it could go in Function.h?



Comment at: clangd/ProtocolHandlers.h:32
 public:
-  using Ctx = RequestContext;
+  using Ctx = Context;
   virtual ~ProtocolCallbacks() = default;

We should use one name or the other. Fine to do this to keep the patch small, 
but leave a FIXME?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40486



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


[PATCH] D40715: [analyser] different.LabelInsideSwitch checker implementation

2017-12-11 Thread Alexey Knyshev via Phabricator via cfe-commits
alexey.knyshev added a comment.

In https://reviews.llvm.org/D40715#951665, @dcoughlin wrote:

> Thanks for looking into this!
>
> This checker is in the 'core' package, which means (when moved out of alpha) 
> it will be enabled by default.
>
> - Do you think that this checker should be enabled by default for all users 
> of the analyzer?


I think so

> - If users do actually want to use labels in their switch statements, how 
> should they suppress the diagnostics from the checker?

Good point, is there recommended way to implement options for checker? Where 
can I find any reference example?

> - What is the benefit of adding this check in the static analyzer vs. in 
> clang-tidy?
> 
> (My own sense is that the check for labels that are close to "default" could 
> be on by default but that warning on *any* label inside a switch is more 
> stylistic. I think users should have to opt in to that check.)

It makes sense. So, I can make generic case when we found any label in 
swichStmt opt-in (default=off) and left cases when it looks like typo in 'case' 
or 'default' keywords enabled by default.
Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D40715



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


[PATCH] D41087: [Preprocessor] Implement __is_target_{arch|vendor|os|environment} function-like builtin macros

2017-12-11 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: lib/Lex/PPMacroExpansion.cpp:1923
+  Tok, *this, diag::err_feature_check_malformed);
+  return II ? getTargetInfo().getTriple().getArchName().equals_lower(
+  II->getName())

Hmm, the one thing to consider here is the canonicalized vs spelt target.  e.g. 
`armv7-windows` will map to `thumbv7-unknown-windows-msvc`.



Comment at: test/Preprocessor/is_target.c:8
+#if __is_target_arch(arm64)
+  #error "invalid arch"
+#endif

Can you use `mismatching arch` instead?  This helps differentiate between the 
invalid arch case below as apposed to the condition being false.  Similar for 
the other warnings.


Repository:
  rC Clang

https://reviews.llvm.org/D41087



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


[PATCH] D41048: [libcxx] workaround PR 28385 in __find_exactly_one_checked

2017-12-11 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray accepted this revision.
lichray added a comment.
This revision is now accepted and ready to land.

Reproduced with

  lit -sv --param=cxx_under_test="$HOME/bin/clang++" test/std/utilities/tuple/
  lit: [...] note: Using available_features: ['libc++', 'verify-support', 
'clang-6', 'modules-support', 'locale.en_US.UTF-8', 'diagnose-if-support', 
'long_tests', 'fdelayed-template-parsing', '-faligned-allocation', 
'locale.zh_CN.UTF-8', 'c++2a', 'locale.fr_CA.ISO8859-1', 'c++filesystem', 
'c++experimental', 'clang', 'locale.fr_FR.UTF-8', 'locale.ru_RU.UTF-8', 
'fsized-deallocation', 'freebsd11', 'fcoroutines-ts', 'locale.cs_CZ.ISO8859-2', 
'clang-6.0', 'thread-safety']


https://reviews.llvm.org/D41048



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


[PATCH] D40743: Make rehash(0) work with ubsan's unsigned-integer-overflow.

2017-12-11 Thread Dan Albert via Phabricator via cfe-commits
danalbert added inline comments.



Comment at: include/__hash_table:2141
 __n = 2;
 else if (__n & (__n - 1))
 __n = __next_prime(__n);

With `rehash(0)` this is `0 & (0 - 1)`, which triggers 
unsigned-integer-overflow.


Repository:
  rCXX libc++

https://reviews.llvm.org/D40743



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


[PATCH] D40925: Add option -fkeep-static-consts

2017-12-11 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

*ping*


https://reviews.llvm.org/D40925



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


r320455 - [analyzer] StackAddrEscape: For now, disable the new async escape checks.

2017-12-11 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Dec 11 18:59:09 2017
New Revision: 320455

URL: http://llvm.org/viewvc/llvm-project?rev=320455=rev
Log:
[analyzer] StackAddrEscape: For now, disable the new async escape checks.

The new check introduced in r318705 is useful, but suffers from a particular
class of false positives, namely, it does not account for
dispatch_barrier_sync() API which allows one to ensure that the asyncronously
executed block that captures a pointer to a local variable does not actually
outlive that variable.

The new check is split into a separate checker, under the name of
alpha.core.StackAddressAsyncEscape, which is likely to get enabled by default
again once these positives are fixed. The rest of the StackAddressEscapeChecker
is still enabled by default.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
cfe/trunk/test/Analysis/stack-capture-leak-arc.mm
cfe/trunk/test/Analysis/stack-capture-leak-no-arc.mm

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=320455=320454=320455=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Mon Dec 11 
18:59:09 2017
@@ -188,6 +188,10 @@ def DynamicTypeChecker : Checker<"Dynami
   HelpText<"Check for cases where the dynamic and the static type of an object 
are unrelated.">,
   DescFile<"DynamicTypeChecker.cpp">;
 
+def StackAddrAsyncEscapeChecker : Checker<"StackAddressAsyncEscape">,
+  HelpText<"Check that addresses to stack memory do not escape the function">,
+  DescFile<"StackAddrEscapeChecker.cpp">;
+
 } // end "alpha.core"
 
 let ParentPackage = Nullability in {

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp?rev=320455=320454=320455=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp Mon Dec 11 
18:59:09 2017
@@ -37,6 +37,14 @@ class StackAddrEscapeChecker
   mutable std::unique_ptr BT_capturedstackret;
 
 public:
+  enum CheckKind {
+CK_StackAddrEscapeChecker,
+CK_StackAddrAsyncEscapeChecker,
+CK_NumCheckKinds
+  };
+
+  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+
   void checkPreCall(const CallEvent , CheckerContext ) const;
   void checkPreStmt(const ReturnStmt *RS, CheckerContext ) const;
   void checkEndFunction(CheckerContext ) const;
@@ -225,6 +233,8 @@ void StackAddrEscapeChecker::checkReturn
 
 void StackAddrEscapeChecker::checkPreCall(const CallEvent ,
   CheckerContext ) const {
+  if (!ChecksEnabled[CK_StackAddrAsyncEscapeChecker])
+return;
   if (!Call.isGlobalCFunction("dispatch_after") &&
   !Call.isGlobalCFunction("dispatch_async"))
 return;
@@ -237,6 +247,8 @@ void StackAddrEscapeChecker::checkPreCal
 
 void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS,
   CheckerContext ) const {
+  if (!ChecksEnabled[CK_StackAddrEscapeChecker])
+return;
 
   const Expr *RetE = RS->getRetValue();
   if (!RetE)
@@ -277,6 +289,9 @@ void StackAddrEscapeChecker::checkPreStm
 }
 
 void StackAddrEscapeChecker::checkEndFunction(CheckerContext ) const {
+  if (!ChecksEnabled[CK_StackAddrEscapeChecker])
+return;
+
   ProgramStateRef State = Ctx.getState();
 
   // Iterate over all bindings to global variables and see if it contains
@@ -346,6 +361,12 @@ void StackAddrEscapeChecker::checkEndFun
   }
 }
 
-void ento::registerStackAddrEscapeChecker(CheckerManager ) {
-  Mgr.registerChecker();
-}
+#define REGISTER_CHECKER(name) \
+  void ento::register##name(CheckerManager ) { \
+StackAddrEscapeChecker *Chk = \
+Mgr.registerChecker(); \
+Chk->ChecksEnabled[StackAddrEscapeChecker::CK_##name] = true; \
+  }
+
+REGISTER_CHECKER(StackAddrEscapeChecker)
+REGISTER_CHECKER(StackAddrAsyncEscapeChecker)

Modified: cfe/trunk/test/Analysis/stack-capture-leak-arc.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/stack-capture-leak-arc.mm?rev=320455=320454=320455=diff
==
--- cfe/trunk/test/Analysis/stack-capture-leak-arc.mm (original)
+++ cfe/trunk/test/Analysis/stack-capture-leak-arc.mm Mon Dec 11 18:59:09 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core -fblocks -fobjc-arc -verify %s
+// RUN: %clang_analyze_cc1 -triple 

[PATCH] D41042: [analyzer] StackAddrEscape: Delay turning on by default a little bit?

2017-12-11 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320455: [analyzer] StackAddrEscape: For now, disable the new 
async escape checks. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D41042?vs=126390=126496#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41042

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
  cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  cfe/trunk/test/Analysis/stack-capture-leak-arc.mm
  cfe/trunk/test/Analysis/stack-capture-leak-no-arc.mm

Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -188,6 +188,10 @@
   HelpText<"Check for cases where the dynamic and the static type of an object are unrelated.">,
   DescFile<"DynamicTypeChecker.cpp">;
 
+def StackAddrAsyncEscapeChecker : Checker<"StackAddressAsyncEscape">,
+  HelpText<"Check that addresses to stack memory do not escape the function">,
+  DescFile<"StackAddrEscapeChecker.cpp">;
+
 } // end "alpha.core"
 
 let ParentPackage = Nullability in {
Index: cfe/trunk/test/Analysis/stack-capture-leak-no-arc.mm
===
--- cfe/trunk/test/Analysis/stack-capture-leak-no-arc.mm
+++ cfe/trunk/test/Analysis/stack-capture-leak-no-arc.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,alpha.core.StackAddressAsyncEscape -fblocks -verify %s
 
 typedef struct dispatch_queue_s *dispatch_queue_t;
 typedef void (^dispatch_block_t)(void);
Index: cfe/trunk/test/Analysis/stack-capture-leak-arc.mm
===
--- cfe/trunk/test/Analysis/stack-capture-leak-arc.mm
+++ cfe/trunk/test/Analysis/stack-capture-leak-arc.mm
@@ -1,12 +1,13 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -fobjc-arc -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,alpha.core.StackAddressAsyncEscape -fblocks -fobjc-arc -verify %s
 
 typedef struct dispatch_queue_s *dispatch_queue_t;
 typedef void (^dispatch_block_t)(void);
 void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
 typedef long dispatch_once_t;
 void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);
 typedef long dispatch_time_t;
 void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_barrier_sync(dispatch_queue_t queue, dispatch_block_t block);
 
 extern dispatch_queue_t queue;
 extern dispatch_once_t *predicate;
@@ -173,3 +174,16 @@
   // Wait for the asynchronous work to finish
   dispatch_semaphore_wait(semaphore, 1000);
 }
+
+void test_dispatch_barrier_sync() {
+  int buf[16];
+  for (int n = 0; n < 16; ++n) {
+int *ptr = [n];
+// FIXME: Should not warn. The dispatch_barrier_sync() call ensures
+// that the block does not outlive 'buf'.
+dispatch_async(queue, ^{ // expected-warning{{Address of stack memory associated with local variable 'buf' is captured by an asynchronously-executed block}}
+  (void)ptr;
+});
+  }
+  dispatch_barrier_sync(queue, ^{});
+}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -37,6 +37,14 @@
   mutable std::unique_ptr BT_capturedstackret;
 
 public:
+  enum CheckKind {
+CK_StackAddrEscapeChecker,
+CK_StackAddrAsyncEscapeChecker,
+CK_NumCheckKinds
+  };
+
+  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+
   void checkPreCall(const CallEvent , CheckerContext ) const;
   void checkPreStmt(const ReturnStmt *RS, CheckerContext ) const;
   void checkEndFunction(CheckerContext ) const;
@@ -225,6 +233,8 @@
 
 void StackAddrEscapeChecker::checkPreCall(const CallEvent ,
   CheckerContext ) const {
+  if (!ChecksEnabled[CK_StackAddrAsyncEscapeChecker])
+return;
   if (!Call.isGlobalCFunction("dispatch_after") &&
   !Call.isGlobalCFunction("dispatch_async"))
 return;
@@ -237,6 +247,8 @@
 
 void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS,
   CheckerContext ) const {
+  if (!ChecksEnabled[CK_StackAddrEscapeChecker])
+return;
 
   const Expr *RetE = RS->getRetValue();
   if (!RetE)
@@ -277,6 +289,9 @@
 }
 
 void StackAddrEscapeChecker::checkEndFunction(CheckerContext ) const {
+  if (!ChecksEnabled[CK_StackAddrEscapeChecker])
+return;
+
   ProgramStateRef State = 

r320451 - [analyzer] In getSVal() API, disable auto-detection of void type as char type.

2017-12-11 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Dec 11 18:27:55 2017
New Revision: 320451

URL: http://llvm.org/viewvc/llvm-project?rev=320451=rev
Log:
[analyzer] In getSVal() API, disable auto-detection of void type as char type.

This is a follow-up from r314910. When a checker developer attempts to
dereference a location in memory through ProgramState::getSVal(Loc) or
ProgramState::getSVal(const MemRegion *), without specifying the second
optional QualType parameter for the type of the value he tries to find at this
location, the type is auto-detected from location type. If the location
represents a value beyond a void pointer, we thought that auto-detecting the
type as 'char' is a good idea. However, in most practical cases, the correct
behavior would be to specify the type explicitly, as it is available from other
sources, and the few cases where we actually need to take a 'char' are
workarounds rather than an intended behavior. Therefore, try to fail with an
easy-to-understand assertion when asked to read from a void pointer location.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=320451=320450=320451=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Mon Dec 11 18:27:55 2017
@@ -308,8 +308,12 @@ public:
 
   /// \brief Return the value bound to the specified location.
   /// Returns UnknownVal() if none found.
-  SVal getSVal(const MemRegion* R) const;
+  SVal getSVal(const MemRegion* R, QualType T = QualType()) const;
 
+  /// \brief Return the value bound to the specified location, assuming
+  /// that the value is a scalar integer or an enumeration or a pointer.
+  /// Returns UnknownVal() if none found or the region is not known to hold
+  /// a value of such type.
   SVal getSValAsScalarOrLoc(const MemRegion *R) const;
 
   /// \brief Visits the symbols reachable from the given SVal using the 
provided
@@ -758,9 +762,10 @@ inline SVal ProgramState::getRawSVal(Loc
   return getStateManager().StoreMgr->getBinding(getStore(), LV, T);
 }
 
-inline SVal ProgramState::getSVal(const MemRegion* R) const {
+inline SVal ProgramState::getSVal(const MemRegion* R, QualType T) const {
   return getStateManager().StoreMgr->getBinding(getStore(),
-loc::MemRegionVal(R));
+loc::MemRegionVal(R),
+T);
 }
 
 inline BasicValueFactory ::getBasicVals() const {

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp?rev=320451=320450=320451=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp Mon Dec 11 
18:27:55 2017
@@ -179,7 +179,7 @@ bool CallAndMessageChecker::uninitRefOrP
 
   if (const MemRegion *SValMemRegion = V.getAsRegion()) {
 const ProgramStateRef State = C.getState();
-const SVal PSV = State->getSVal(SValMemRegion);
+const SVal PSV = State->getSVal(SValMemRegion, C.getASTContext().CharTy);
 if (PSV.isUndef()) {
   if (ExplodedNode *N = C.generateErrorNode()) {
 LazyInit_BT(BD, BT);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp?rev=320451=320450=320451=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp Mon Dec 11 
18:27:55 2017
@@ -466,7 +466,7 @@ bool GenericTaintChecker::checkPre(const
 }
 
 Optional GenericTaintChecker::getPointedToSVal(CheckerContext ,
-const Expr* Arg) {
+ const Expr *Arg) {
   ProgramStateRef State = C.getState();
   SVal AddrVal = State->getSVal(Arg->IgnoreParens(), C.getLocationContext());
   if (AddrVal.isUnknownOrUndef())
@@ -476,9 +476,18 @@ Optional GenericTaintChecker::getP
   if (!AddrLoc)
 return None;
 
-  const PointerType *ArgTy =
-

[PATCH] D38801: [analyzer] In getSVal() API, disable auto-detection of void type as char type.

2017-12-11 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320451: [analyzer] In getSVal() API, disable auto-detection 
of void type as char type. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D38801?vs=12=126493#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38801

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp


Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -308,8 +308,12 @@
 
   /// \brief Return the value bound to the specified location.
   /// Returns UnknownVal() if none found.
-  SVal getSVal(const MemRegion* R) const;
+  SVal getSVal(const MemRegion* R, QualType T = QualType()) const;
 
+  /// \brief Return the value bound to the specified location, assuming
+  /// that the value is a scalar integer or an enumeration or a pointer.
+  /// Returns UnknownVal() if none found or the region is not known to hold
+  /// a value of such type.
   SVal getSValAsScalarOrLoc(const MemRegion *R) const;
 
   /// \brief Visits the symbols reachable from the given SVal using the 
provided
@@ -758,9 +762,10 @@
   return getStateManager().StoreMgr->getBinding(getStore(), LV, T);
 }
 
-inline SVal ProgramState::getSVal(const MemRegion* R) const {
+inline SVal ProgramState::getSVal(const MemRegion* R, QualType T) const {
   return getStateManager().StoreMgr->getBinding(getStore(),
-loc::MemRegionVal(R));
+loc::MemRegionVal(R),
+T);
 }
 
 inline BasicValueFactory ::getBasicVals() const {
Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1405,10 +1405,7 @@
 T = Ctx.VoidTy;
 }
 assert(!T.isNull() && "Unable to auto-detect binding type!");
-if (T->isVoidType()) {
-  // When trying to dereference a void pointer, read the first byte.
-  T = Ctx.CharTy;
-}
+assert(!T->isVoidType() && "Attempting to dereference a void pointer!");
 MR = GetElementZeroRegion(cast(MR), T);
   }
 
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -466,7 +466,7 @@
 }
 
 Optional GenericTaintChecker::getPointedToSVal(CheckerContext ,
-const Expr* Arg) {
+ const Expr *Arg) {
   ProgramStateRef State = C.getState();
   SVal AddrVal = State->getSVal(Arg->IgnoreParens(), C.getLocationContext());
   if (AddrVal.isUnknownOrUndef())
@@ -476,9 +476,18 @@
   if (!AddrLoc)
 return None;
 
-  const PointerType *ArgTy =
-dyn_cast(Arg->getType().getCanonicalType().getTypePtr());
-  return State->getSVal(*AddrLoc, ArgTy ? ArgTy->getPointeeType(): QualType());
+  QualType ArgTy = Arg->getType().getCanonicalType();
+  if (!ArgTy->isPointerType())
+return None;
+
+  QualType ValTy = ArgTy->getPointeeType();
+
+  // Do not dereference void pointers. Treat them as byte pointers instead.
+  // FIXME: we might want to consider more than just the first byte.
+  if (ValTy->isVoidType())
+ValTy = C.getASTContext().CharTy;
+
+  return State->getSVal(*AddrLoc, ValTy);
 }
 
 ProgramStateRef
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -179,7 +179,7 @@
 
   if (const MemRegion *SValMemRegion = V.getAsRegion()) {
 const ProgramStateRef State = C.getState();
-const SVal PSV = State->getSVal(SValMemRegion);
+const SVal PSV = State->getSVal(SValMemRegion, C.getASTContext().CharTy);
 if (PSV.isUndef()) {
   if (ExplodedNode *N = C.generateErrorNode()) {
 LazyInit_BT(BD, BT);


Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -308,8 +308,12 

[PATCH] D41103: [CMake] Allow passing extra CMake arguments to custom libc++

2017-12-11 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
Herald added subscribers: Sanitizers, llvm-commits, mgorny.
Herald added a reviewer: EricWF.

This can be used to customize the libc++ build.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D41103

Files:
  cmake/Modules/AddCompilerRT.cmake


Index: cmake/Modules/AddCompilerRT.cmake
===
--- cmake/Modules/AddCompilerRT.cmake
+++ cmake/Modules/AddCompilerRT.cmake
@@ -469,7 +469,7 @@
 message(FATAL_ERROR "libcxx not found!")
   endif()
 
-  cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS" ${ARGN})
+  cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS;CMAKE_ARGS" ${ARGN})
   foreach(flag ${LIBCXX_CFLAGS})
 set(flagstr "${flagstr} ${flag}")
   endforeach()
@@ -491,6 +491,7 @@
-DCMAKE_INSTALL_PREFIX:PATH=
-DLLVM_PATH=${LLVM_MAIN_SRC_DIR}
-DLIBCXX_STANDALONE_BUILD=On
+   ${LIBCXX_CMAKE_ARGS}
 LOG_BUILD 1
 LOG_CONFIGURE 1
 LOG_INSTALL 1


Index: cmake/Modules/AddCompilerRT.cmake
===
--- cmake/Modules/AddCompilerRT.cmake
+++ cmake/Modules/AddCompilerRT.cmake
@@ -469,7 +469,7 @@
 message(FATAL_ERROR "libcxx not found!")
   endif()
 
-  cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS" ${ARGN})
+  cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS;CMAKE_ARGS" ${ARGN})
   foreach(flag ${LIBCXX_CFLAGS})
 set(flagstr "${flagstr} ${flag}")
   endforeach()
@@ -491,6 +491,7 @@
-DCMAKE_INSTALL_PREFIX:PATH=
-DLLVM_PATH=${LLVM_MAIN_SRC_DIR}
-DLIBCXX_STANDALONE_BUILD=On
+   ${LIBCXX_CMAKE_ARGS}
 LOG_BUILD 1
 LOG_CONFIGURE 1
 LOG_INSTALL 1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D41039: Add support for attribute "trivial_abi"

2017-12-11 Thread John McCall via cfe-commits
On Mon, Dec 11, 2017 at 6:19 PM, David Blaikie  wrote:

> On Mon, Dec 11, 2017 at 3:16 PM John McCall via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
>> rjmccall added a comment.
>>
>> In https://reviews.llvm.org/D41039#951648, @ahatanak wrote:
>>
>> > I had a discussion with Duncan today and he pointed out that perhaps we
>> shouldn't allow users to annotate a struct with "trivial_abi" if one of its
>> subobjects is non-trivial and is not annotated with "trivial_abi" since
>> that gives users too much power.
>> >
>> > Should we error out or drop "trivial_abi" from struct Outer when the
>> following code is compiled?
>> >
>> >   struct Inner1 {
>> > ~Inner1(); // non-trivial
>> > int x;
>> >   };
>> >
>> >   struct __attribute__((trivial_abi)) Outer {
>> > ~Outer();
>> > Inner1 x;
>> >   };
>> >
>> >
>> > The current patch doesn't error out or drop the attribute, but the
>> patch would probably be much simpler if we didn't allow it.
>>
>>
>> I think it makes sense to emit an error if there is provably a
>> non-trivial-ABI component.  However, for class temploids I think that
>> diagnostic should only fire on the definition, not on instantiations; for
>> example:
>>
>>   template  struct __attribute__((trivial_abi)) holder {
>>  T value;
>>  ~holder() {}
>>   };
>>   holder hs; // this instantiation should be legal despite
>> the fact that holder cannot be trivial-ABI.
>>
>> But we should still be able to emit the diagnostic in template
>> definitions, e.g.:
>>
>>   template  struct __attribute__((trivial_abi)) named_holder {
>>  std::string name; // there are no instantiations of this template
>> that could ever be trivial-ABI
>>  T value;
>>  ~named_holder() {}
>>   };
>>
>> The wording should be something akin to the standard template rule that a
>> template is ill-formed if it has no valid instantiations, no diagnostic
>> required.
>>
>> I would definitely like to open the conversation about the name of the
>> attribute.  I don't think we've used "abi" in an existing attribute name;
>> usually it's more descriptive.  And "trivial" is a weighty word in the
>> standard.  I'm not sure I have a great counter-proposal off the top of my
>> head, though.
>>
>
> Agreed on both counts (would love a better name, don't have any stand-out
> candidates off the top of my head).
>
> I feel like a more descriptive term about the property of the object would
> make me happier - something like "address_independent_identity"
> (s/identity/value/?) though, yeah, that's not spectacular by any stretch.
>

Incidentally, your comments are not showing up on Phabricator for some
reason.

The term "trivially movable" suggests itself, with two caveats:
  - What we're talking about is trivial *destructive* movability, i.e. that
the combination of moving the value to a new object and not destroying the
old object can be done trivially, which is not quite the same as trivial
movability in the normal C++ sense, which I guess could be a property that
someone theoretically might care about (if the type is trivially
destructed, but it isn't copyable for semantic reasons?).
  - Trivial destructive movability is a really common property, and it's
something that a compiler would really like to optimize based on even in
cases where trivial_abi can't be adopted for binary-compatibility reasons.
Stealing the term for the stronger property that the type is trivially
destructively movable *and its ABI should reflect that in a specific way*
would be unfortunate.

"trivially_movable" is a long attribute anyway, and
"trivially_destructively_movable" is even worse.

Maybe that second point is telling us that this isn't purely descriptive —
it's inherently talking about the ABI, not just the semantics of the type.
I might be talking myself into accepting trivial_abi if we don't end up
with a better suggestion.

Random thing that occurred to me: is it actually reasonable to enforce
trivial_abi correctness in a non-template context?  Templates aren't the
only case where a user could reasonably want to add trivial_abi and just
have it be suppressed if it's wrong.  Imagine if some stdlib made
std::string trivial_abi; someone might reasonably want to make my
named_holder example above trivial_abi as well, with the expectation that
it would only have an effect on targets where std::string was trivial_abi.
At the very least, I'm concerned that we might be opening ourselves up to a
need to add supporting features, like a way to be conditionally trivial_abi
based on context.

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


[PATCH] D41102: Setup clang-doc frontend framework

2017-12-11 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added a project: clang.
Herald added a subscriber: mgorny.

Setting up a basic frontend framework for a clang-doc tool. It creates a 
frontend action for traversing the AST to extract comments and declarations, 
with a flag to only extract documentation-style comments. Right now, it outputs 
its findings in YAML format to the command line.

For a more detailed overview of the tool, see the design document on the 
mailing list: RFC: clang-doc proposal 



https://reviews.llvm.org/D41102

Files:
  tools/CMakeLists.txt
  tools/clang-doc/CMakeLists.txt
  tools/clang-doc/ClangDoc.cpp
  tools/clang-doc/ClangDoc.h
  tools/clang-doc/ClangDocReporter.cpp
  tools/clang-doc/ClangDocReporter.h
  tools/clang-doc/tool/CMakeLists.txt
  tools/clang-doc/tool/ClangDocMain.cpp

Index: tools/clang-doc/tool/ClangDocMain.cpp
===
--- /dev/null
+++ tools/clang-doc/tool/ClangDocMain.cpp
@@ -0,0 +1,70 @@
+//===-- ClangDocMain.cpp - Clangdoc -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangDoc.h"
+#include "clang/Driver/Options.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Signals.h"
+#include 
+
+using namespace clang;
+using namespace llvm;
+
+namespace {
+
+cl::OptionCategory ClangDocCategory("clang-doc options");
+
+cl::opt
+EmitFormat("emit",
+   cl::desc("Output format (valid options are -emit=json and "
+"-emit=llvm)."),
+   cl::init("llvm"), cl::cat(ClangDocCategory));
+
+cl::opt
+DoxygenOnly("doxygen",
+cl::desc("Use only doxygen-style comments to generate docs."),
+cl::init(false), cl::cat(ClangDocCategory));
+
+} // namespace
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+  tooling::CommonOptionsParser OptionsParser(argc, argv, ClangDocCategory);
+
+  if (EmitFormat != "llvm" && EmitFormat != "json") {
+llvm::errs() << "Please specify llvm or json output.\n";
+return 1;
+  }
+
+  // TODO: Update the source path list to only consider changed files for
+  // incremental doc updates
+  doc::ClangDocReporter Reporter(OptionsParser.getSourcePathList());
+  doc::ClangDocContext Context{EmitFormat};
+  llvm::outs() << "Output results in " << Context.EmitFormat << " format.\n";
+
+  tooling::ClangTool Tool(OptionsParser.getCompilations(),
+  OptionsParser.getSourcePathList());
+
+  if (!DoxygenOnly)
+Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(
+"-fparse-all-comments", tooling::ArgumentInsertPosition::BEGIN));
+
+  doc::ClangDocActionFactory Factory(Context, Reporter);
+
+  llvm::outs() << "Parsing codebase...\n";
+  int Status = Tool.run();
+  if (Status)
+return Status;
+
+  llvm::outs() << "Writing docs...\n";
+  Reporter.Serialize(EmitFormat, llvm::outs());
+}
Index: tools/clang-doc/tool/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-doc/tool/CMakeLists.txt
@@ -0,0 +1,17 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_executable(clang-doc
+  ClangDocMain.cpp
+  )
+
+target_link_libraries(clang-doc
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangFormat
+  clangFrontend
+  clangDoc
+  clangRewrite
+  clangTooling
+  clangToolingCore
+  )
\ No newline at end of file
Index: tools/clang-doc/ClangDocReporter.h
===
--- /dev/null
+++ tools/clang-doc/ClangDocReporter.h
@@ -0,0 +1,111 @@
+//===-- Doc.cpp - ClangDoc --*- 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_CLANG_DOC_CLANG_DOC_REPORTER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_CLANG_DOC_REPORTER_H
+
+#include "clang/AST/AST.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/CommentVisitor.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/ASTConsumers.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+using namespace clang::comments;
+
+namespace clang {

[PATCH] D40637: [CMake] Support runtimes and monorepo layouts when looking for libc++

2017-12-11 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320446: [CMake] Support runtimes and monorepo layouts when 
looking for libcxx (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D40637?vs=124876=126482#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40637

Files:
  compiler-rt/trunk/CMakeLists.txt
  compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
  compiler-rt/trunk/lib/msan/tests/CMakeLists.txt
  compiler-rt/trunk/lib/tsan/CMakeLists.txt
  compiler-rt/trunk/test/msan/CMakeLists.txt
  compiler-rt/trunk/test/tsan/CMakeLists.txt


Index: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
===
--- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
+++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
@@ -465,7 +465,7 @@
 #   DEPS 
 #   CFLAGS )
 macro(add_custom_libcxx name prefix)
-  if(NOT COMPILER_RT_HAS_LIBCXX_SOURCES)
+  if(NOT COMPILER_RT_LIBCXX_PATH)
 message(FATAL_ERROR "libcxx not found!")
   endif()
 
Index: compiler-rt/trunk/test/msan/CMakeLists.txt
===
--- compiler-rt/trunk/test/msan/CMakeLists.txt
+++ compiler-rt/trunk/test/msan/CMakeLists.txt
@@ -25,7 +25,7 @@
   list(APPEND MSAN_TEST_DEPS msan)
 endif()
 
-if(COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_LIBCXX_SOURCES)
+if(COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_LIBCXX_PATH)
   configure_lit_site_cfg(
 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
 ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)
Index: compiler-rt/trunk/test/tsan/CMakeLists.txt
===
--- compiler-rt/trunk/test/tsan/CMakeLists.txt
+++ compiler-rt/trunk/test/tsan/CMakeLists.txt
@@ -7,7 +7,7 @@
 if(NOT COMPILER_RT_STANDALONE_BUILD)
   list(APPEND TSAN_TEST_DEPS tsan)
 endif()
-if(COMPILER_RT_HAS_LIBCXX_SOURCES AND
+if(COMPILER_RT_LIBCXX_PATH AND
COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang"
AND NOT APPLE AND NOT ANDROID)
   list(APPEND TSAN_TEST_DEPS libcxx_tsan)
Index: compiler-rt/trunk/CMakeLists.txt
===
--- compiler-rt/trunk/CMakeLists.txt
+++ compiler-rt/trunk/CMakeLists.txt
@@ -344,17 +344,15 @@
 
 add_subdirectory(include)
 
-set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx)
-if(EXISTS ${COMPILER_RT_LIBCXX_PATH}/)
-  set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE)
-else()
-  set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/../libcxx)
-  if(EXISTS ${COMPILER_RT_LIBCXX_PATH}/)
-set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE)
-  else()
-set(COMPILER_RT_HAS_LIBCXX_SOURCES FALSE)
+foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxx
+  ${LLVM_MAIN_SRC_DIR}/runtimes/libcxx
+  ${LLVM_MAIN_SRC_DIR}/../libcxx
+  ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
+  if(IS_DIRECTORY ${path})
+set(COMPILER_RT_LIBCXX_PATH ${path})
+break()
   endif()
-endif()
+endforeach()
 
 set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld)
 if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
Index: compiler-rt/trunk/lib/tsan/CMakeLists.txt
===
--- compiler-rt/trunk/lib/tsan/CMakeLists.txt
+++ compiler-rt/trunk/lib/tsan/CMakeLists.txt
@@ -203,7 +203,7 @@
 endif()
 
 # Build libcxx instrumented with TSan.
-if(COMPILER_RT_HAS_LIBCXX_SOURCES AND
+if(COMPILER_RT_LIBCXX_PATH AND
COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang" AND
NOT ANDROID)
   set(libcxx_tsan_deps)
Index: compiler-rt/trunk/lib/msan/tests/CMakeLists.txt
===
--- compiler-rt/trunk/lib/msan/tests/CMakeLists.txt
+++ compiler-rt/trunk/lib/msan/tests/CMakeLists.txt
@@ -122,7 +122,7 @@
 endmacro()
 
 # We should only build MSan unit tests if we can build instrumented libcxx.
-if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_HAS_LIBCXX_SOURCES)
+if(COMPILER_RT_CAN_EXECUTE_TESTS AND COMPILER_RT_LIBCXX_PATH)
   foreach(arch ${MSAN_SUPPORTED_ARCH})
 get_target_flags_for_arch(${arch} TARGET_CFLAGS)
 set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/../libcxx_msan_${arch})


Index: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
===
--- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
+++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
@@ -465,7 +465,7 @@
 #   DEPS 
 #   CFLAGS )
 macro(add_custom_libcxx name prefix)
-  if(NOT COMPILER_RT_HAS_LIBCXX_SOURCES)
+  if(NOT COMPILER_RT_LIBCXX_PATH)
 message(FATAL_ERROR "libcxx not found!")
   endif()
 
Index: compiler-rt/trunk/test/msan/CMakeLists.txt
===
--- compiler-rt/trunk/test/msan/CMakeLists.txt
+++ 

[PATCH] D40818: [libcxxabi] Pass LIBCXXABI_SYSROOT and LIBCXXABI_GCC_TOOLCHAIN to lit

2017-12-11 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320445: [libcxxabi] Pass LIBCXXABI_SYSROOT and 
LIBCXXABI_GCC_TOOLCHAIN to lit (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D40818?vs=125457=126481#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40818

Files:
  libcxxabi/trunk/test/lit.site.cfg.in


Index: libcxxabi/trunk/test/lit.site.cfg.in
===
--- libcxxabi/trunk/test/lit.site.cfg.in
+++ libcxxabi/trunk/test/lit.site.cfg.in
@@ -20,6 +20,8 @@
 config.host_triple  = "@LLVM_HOST_TRIPLE@"
 config.target_triple= "@TARGET_TRIPLE@"
 config.use_target   = len("@LIBCXXABI_TARGET_TRIPLE@") > 0
+config.sysroot  = "@LIBCXXABI_SYSROOT@"
+config.gcc_toolchain= "@LIBCXXABI_GCC_TOOLCHAIN@"
 config.cxx_ext_threads  = "@LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY@"
 
 # Let the main config do the real work.


Index: libcxxabi/trunk/test/lit.site.cfg.in
===
--- libcxxabi/trunk/test/lit.site.cfg.in
+++ libcxxabi/trunk/test/lit.site.cfg.in
@@ -20,6 +20,8 @@
 config.host_triple  = "@LLVM_HOST_TRIPLE@"
 config.target_triple= "@TARGET_TRIPLE@"
 config.use_target   = len("@LIBCXXABI_TARGET_TRIPLE@") > 0
+config.sysroot  = "@LIBCXXABI_SYSROOT@"
+config.gcc_toolchain= "@LIBCXXABI_GCC_TOOLCHAIN@"
 config.cxx_ext_threads  = "@LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY@"
 
 # Let the main config do the real work.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxxabi] r320445 - [libcxxabi] Pass LIBCXXABI_SYSROOT and LIBCXXABI_GCC_TOOLCHAIN to lit

2017-12-11 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Mon Dec 11 17:20:37 2017
New Revision: 320445

URL: http://llvm.org/viewvc/llvm-project?rev=320445=rev
Log:
[libcxxabi] Pass LIBCXXABI_SYSROOT and LIBCXXABI_GCC_TOOLCHAIN to lit

These are expected to be set by the shared lit scripts used from libc++.

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

Modified:
libcxxabi/trunk/test/lit.site.cfg.in

Modified: libcxxabi/trunk/test/lit.site.cfg.in
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/lit.site.cfg.in?rev=320445=320444=320445=diff
==
--- libcxxabi/trunk/test/lit.site.cfg.in (original)
+++ libcxxabi/trunk/test/lit.site.cfg.in Mon Dec 11 17:20:37 2017
@@ -20,6 +20,8 @@ config.enable_exceptions= "@LIBC
 config.host_triple  = "@LLVM_HOST_TRIPLE@"
 config.target_triple= "@TARGET_TRIPLE@"
 config.use_target   = len("@LIBCXXABI_TARGET_TRIPLE@") > 0
+config.sysroot  = "@LIBCXXABI_SYSROOT@"
+config.gcc_toolchain= "@LIBCXXABI_GCC_TOOLCHAIN@"
 config.cxx_ext_threads  = "@LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY@"
 
 # Let the main config do the real work.


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


Re: [PATCH] D41039: Add support for attribute "trivial_abi"

2017-12-11 Thread David Blaikie via cfe-commits
On Mon, Dec 11, 2017 at 3:16 PM John McCall via Phabricator <
revi...@reviews.llvm.org> wrote:

> rjmccall added a comment.
>
> In https://reviews.llvm.org/D41039#951648, @ahatanak wrote:
>
> > I had a discussion with Duncan today and he pointed out that perhaps we
> shouldn't allow users to annotate a struct with "trivial_abi" if one of its
> subobjects is non-trivial and is not annotated with "trivial_abi" since
> that gives users too much power.
> >
> > Should we error out or drop "trivial_abi" from struct Outer when the
> following code is compiled?
> >
> >   struct Inner1 {
> > ~Inner1(); // non-trivial
> > int x;
> >   };
> >
> >   struct __attribute__((trivial_abi)) Outer {
> > ~Outer();
> > Inner1 x;
> >   };
> >
> >
> > The current patch doesn't error out or drop the attribute, but the patch
> would probably be much simpler if we didn't allow it.
>
>
> I think it makes sense to emit an error if there is provably a
> non-trivial-ABI component.  However, for class temploids I think that
> diagnostic should only fire on the definition, not on instantiations; for
> example:
>
>   template  struct __attribute__((trivial_abi)) holder {
>  T value;
>  ~holder() {}
>   };
>   holder hs; // this instantiation should be legal despite
> the fact that holder cannot be trivial-ABI.
>
> But we should still be able to emit the diagnostic in template
> definitions, e.g.:
>
>   template  struct __attribute__((trivial_abi)) named_holder {
>  std::string name; // there are no instantiations of this template
> that could ever be trivial-ABI
>  T value;
>  ~named_holder() {}
>   };
>
> The wording should be something akin to the standard template rule that a
> template is ill-formed if it has no valid instantiations, no diagnostic
> required.
>
> I would definitely like to open the conversation about the name of the
> attribute.  I don't think we've used "abi" in an existing attribute name;
> usually it's more descriptive.  And "trivial" is a weighty word in the
> standard.  I'm not sure I have a great counter-proposal off the top of my
> head, though.
>

Agreed on both counts (would love a better name, don't have any stand-out
candidates off the top of my head).

I feel like a more descriptive term about the property of the object would
make me happier - something like "address_independent_identity"
(s/identity/value/?) though, yeah, that's not spectacular by any stretch.


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


[PATCH] D41039: Add support for attribute "trivial_abi"

2017-12-11 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D41039#951648, @ahatanak wrote:

> I had a discussion with Duncan today and he pointed out that perhaps we 
> shouldn't allow users to annotate a struct with "trivial_abi" if one of its 
> subobjects is non-trivial and is not annotated with "trivial_abi" since that 
> gives users too much power.
>
> Should we error out or drop "trivial_abi" from struct Outer when the 
> following code is compiled?
>
>   struct Inner1 {
> ~Inner1(); // non-trivial
> int x;
>   };
>  
>   struct __attribute__((trivial_abi)) Outer {
> ~Outer();
> Inner1 x;
>   };
>
>
> The current patch doesn't error out or drop the attribute, but the patch 
> would probably be much simpler if we didn't allow it.


I think it makes sense to emit an error if there is provably a non-trivial-ABI 
component.  However, for class temploids I think that diagnostic should only 
fire on the definition, not on instantiations; for example:

  template  struct __attribute__((trivial_abi)) holder {
 T value;
 ~holder() {}
  };
  holder hs; // this instantiation should be legal despite the 
fact that holder cannot be trivial-ABI.

But we should still be able to emit the diagnostic in template definitions, 
e.g.:

  template  struct __attribute__((trivial_abi)) named_holder {
 std::string name; // there are no instantiations of this template that 
could ever be trivial-ABI
 T value;
 ~named_holder() {}
  };

The wording should be something akin to the standard template rule that a 
template is ill-formed if it has no valid instantiations, no diagnostic 
required.

I would definitely like to open the conversation about the name of the 
attribute.  I don't think we've used "abi" in an existing attribute name; 
usually it's more descriptive.  And "trivial" is a weighty word in the 
standard.  I'm not sure I have a great counter-proposal off the top of my head, 
though.


https://reviews.llvm.org/D41039



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


[PATCH] D40956: [AMDGPU] Switch to the new addr space mapping by default for clang

2017-12-11 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm accepted this revision.
arsenm added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D40956



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


[PATCH] D39571: [clangd] DidChangeConfiguration Notification

2017-12-11 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 126449.
Nebiroth added a comment.

Removed some more empty lines


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D39571

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/DraftStore.cpp
  clangd/DraftStore.h
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  test/clangd/did-change-configuration.test
  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
@@ -18,6 +18,7 @@
 # CHECK-NEXT:  ":"
 # CHECK-NEXT:]
 # CHECK-NEXT:  },
+# CHECK-NEXT:  "configurationChangeProvider": true,
 # CHECK-NEXT:  "definitionProvider": true,
 # CHECK-NEXT:  "documentFormattingProvider": true,
 # CHECK-NEXT:  "documentOnTypeFormattingProvider": {
Index: test/clangd/initialize-params-invalid.test
===
--- test/clangd/initialize-params-invalid.test
+++ test/clangd/initialize-params-invalid.test
@@ -18,6 +18,7 @@
 # CHECK-NEXT:  ":"
 # CHECK-NEXT:]
 # CHECK-NEXT:  },
+# CHECK-NEXT:  "configurationChangeProvider": true,
 # CHECK-NEXT:  "definitionProvider": true,
 # CHECK-NEXT:  "documentFormattingProvider": true,
 # CHECK-NEXT:  "documentOnTypeFormattingProvider": {
Index: test/clangd/did-change-configuration.test
===
--- /dev/null
+++ test/clangd/did-change-configuration.test
@@ -0,0 +1,46 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+
+Content-Length: 150
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"voidmain(){}"}}}
+
+Content-Length: 86
+
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":""}}
+#Failed to decode workspace/didChangeConfiguration request.
+#Incorrect mapping node
+
+Content-Length: 114
+
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":{
+#Failed to decode workspace/didChangeConfiguration request.
+#compilationDatabasePath is not a scalar node
+
+Content-Length: 140
+
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"/","testBadValue":"foo1234"}}}
+#Ignored unknown field "testBadValue"
+#Failed to find compilation database for / in overriden directory /
+#Bad field, bad compilation database
+
+Content-Length: 722
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///compile_commands.json","languageId":"json","version":1,"text":"[\n{\n"directory":"/",\n"command":"/usr/bin/c++-DGTEST_HAS_RTTI=0-D_GNU_SOURCE-D__STDC_CONSTANT_MACROS-D__STDC_FORMAT_MACROS-D__STDC_LIMIT_MACROS-Ilib/Demangle-I../lib/Demangle-I/usr/include/libxml2-Iinclude-I../include-fPIC-fvisibility-inlines-hidden-Werror=date-time-std=c++11-Wall-W-Wno-unused-parameter-Wwrite-strings-Wcast-qual-Wno-missing-field-initializers-pedantic-Wno-long-long-Wno-maybe-uninitialized-Wdelete-non-virtual-dtor-Wno-comment-O0-g-fno-exceptions-fno-rtti-o/foo.c.o-c/foo.c",\n"file":"/foo.c"\n},"}}}
+
+Content-Length: 115
+
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"/"}}}
+#CHECK:{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"message":"type specifier missing, defaults to 'int'","range":{"end":{"character":1,"line":0},"start":{"character":1,"line":0}},"severity":2},{"message":"control reaches end of non-void function","range":{"end":{"character":12,"line":0},"start":{"character":12,"line":0}},"severity":2}],"uri":"file:///foo.c"}}
+
+Content-Length: 48
+
+{"jsonrpc":"2.0","id":1,"method":"shutdown"}
+
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -54,6 +54,8 @@
   virtual void onFileEvent(Ctx C, DidChangeWatchedFilesParams ) = 0;
   virtual void onCommand(Ctx C, ExecuteCommandParams ) = 0;
   virtual void onRename(Ctx C, RenameParams ) = 0;
+  virtual void onChangeConfiguration(Ctx C,
+ DidChangeConfigurationParams ) = 0;
 };
 
 void registerCallbackHandlers(JSONRPCDispatcher , JSONOutput ,

[PATCH] D39571: [clangd] DidChangeConfiguration Notification

2017-12-11 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 126447.
Nebiroth added a comment.
Herald added a subscriber: klimek.

Merged with latest llvm + clang
Minor code cleanup


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D39571

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/DraftStore.cpp
  clangd/DraftStore.h
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  test/clangd/did-change-configuration.test
  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
@@ -18,6 +18,7 @@
 # CHECK-NEXT:  ":"
 # CHECK-NEXT:]
 # CHECK-NEXT:  },
+# CHECK-NEXT:  "configurationChangeProvider": true,
 # CHECK-NEXT:  "definitionProvider": true,
 # CHECK-NEXT:  "documentFormattingProvider": true,
 # CHECK-NEXT:  "documentOnTypeFormattingProvider": {
Index: test/clangd/initialize-params-invalid.test
===
--- test/clangd/initialize-params-invalid.test
+++ test/clangd/initialize-params-invalid.test
@@ -18,6 +18,7 @@
 # CHECK-NEXT:  ":"
 # CHECK-NEXT:]
 # CHECK-NEXT:  },
+# CHECK-NEXT:  "configurationChangeProvider": true,
 # CHECK-NEXT:  "definitionProvider": true,
 # CHECK-NEXT:  "documentFormattingProvider": true,
 # CHECK-NEXT:  "documentOnTypeFormattingProvider": {
Index: test/clangd/did-change-configuration.test
===
--- /dev/null
+++ test/clangd/did-change-configuration.test
@@ -0,0 +1,46 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+
+Content-Length: 150
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"voidmain(){}"}}}
+
+Content-Length: 86
+
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":""}}
+#Failed to decode workspace/didChangeConfiguration request.
+#Incorrect mapping node
+
+Content-Length: 114
+
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":{
+#Failed to decode workspace/didChangeConfiguration request.
+#compilationDatabasePath is not a scalar node
+
+Content-Length: 140
+
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"/","testBadValue":"foo1234"}}}
+#Ignored unknown field "testBadValue"
+#Failed to find compilation database for / in overriden directory /
+#Bad field, bad compilation database
+
+Content-Length: 722
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///compile_commands.json","languageId":"json","version":1,"text":"[\n{\n"directory":"/",\n"command":"/usr/bin/c++-DGTEST_HAS_RTTI=0-D_GNU_SOURCE-D__STDC_CONSTANT_MACROS-D__STDC_FORMAT_MACROS-D__STDC_LIMIT_MACROS-Ilib/Demangle-I../lib/Demangle-I/usr/include/libxml2-Iinclude-I../include-fPIC-fvisibility-inlines-hidden-Werror=date-time-std=c++11-Wall-W-Wno-unused-parameter-Wwrite-strings-Wcast-qual-Wno-missing-field-initializers-pedantic-Wno-long-long-Wno-maybe-uninitialized-Wdelete-non-virtual-dtor-Wno-comment-O0-g-fno-exceptions-fno-rtti-o/foo.c.o-c/foo.c",\n"file":"/foo.c"\n},"}}}
+
+Content-Length: 115
+
+{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"/"}}}
+#CHECK:{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"message":"type specifier missing, defaults to 'int'","range":{"end":{"character":1,"line":0},"start":{"character":1,"line":0}},"severity":2},{"message":"control reaches end of non-void function","range":{"end":{"character":12,"line":0},"start":{"character":12,"line":0}},"severity":2}],"uri":"file:///foo.c"}}
+
+Content-Length: 48
+
+{"jsonrpc":"2.0","id":1,"method":"shutdown"}
+
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -54,6 +54,8 @@
   virtual void onFileEvent(Ctx C, DidChangeWatchedFilesParams ) = 0;
   virtual void onCommand(Ctx C, ExecuteCommandParams ) = 0;
   virtual void onRename(Ctx C, RenameParams ) = 0;
+  virtual void onChangeConfiguration(Ctx C,
+ DidChangeConfigurationParams ) = 0;
 };
 
 void 

[PATCH] D39050: Add index-while-building support to Clang

2017-12-11 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Thanks a lot for the changes! Some more comments inlined.

Please mark addressed comments as done so that reviewers could know what to 
look :) Thanks!




Comment at: include/clang/Frontend/CompilerInstance.h:187
+  typedef std::function
+  ActionWrapperTy;

nit: LLVM variable names start with upper-case letters.



Comment at: include/clang/Index/IndexingAction.h:34
   class IndexDataConsumer;
+  class IndexUnitWriter;
 

This should be removed?

Some forward declarations above are not used as well.



Comment at: lib/Driver/Job.cpp:293
+if (HaveCrashVFS) {
+  IndexStoreDir = llvm::sys::path::parent_path(
+  llvm::sys::path::parent_path(CrashInfo->VFSPath));

Could you share this code with line 278 above, which already has a nice 
comment? 



Comment at: lib/Index/FileIndexRecord.cpp:39
+  auto It = std::upper_bound(Decls.begin(), Decls.end(), NewInfo);
+  Decls.insert(It, std::move(NewInfo));
+}

nathawes wrote:
> ioeric wrote:
> > Why do we need `Decls` to be sorted by offset? If we want this for 
> > printing, it might make sense to just do a sort there.
> It's mostly for when we hash them, so that ordering doesn't change the hash, 
> but it's also for printing. The IndexASTConsumer doesn't always report symbol 
> occurrences in source order, due to the preprocessor and a few other cases.
> We can sort them when the IndexRecordDataConsumer's finish() is called rather 
> than as they're added to avoid the copying from repeated insert calls if 
> that's the concern.
I would leave the sorting to the point where records are hashed to avoid making 
the record stateful. Consider changing `getDeclOccurrences` to 
`getOccurrencesSortedByOffset`; this should make the behavior more explicit.



Comment at: lib/Index/FileIndexRecord.h:51
+public:
+  FileIndexRecord(FileID FID, bool isSystem) : FID(FID), IsSystem(isSystem) {}
+

s/isSystem/IsSystem/

Also, I wonder if we can filter out system decls proactively and avoid creating 
file index record for them. We could also avoid propogating `IsSystem` here.



Comment at: lib/Index/IndexingAction.cpp:504
+
+CreatedASTConsumer = true;
+std::vector Consumers;

nathawes wrote:
> ioeric wrote:
> >  Can we get this state from the base class instead of maintaining a another 
> > state, which seems to be identical?
> I don't see this state in either base class (WrapperFrontendAction and 
> IndexRecordActionBase). WrappingIndexAction and WrappingIndexRecordAction 
> both have this, though. Were you thinking a new intermediate common base 
> class between them and WrapperFrontendAction?
I thought this could be a state in the `WrapperFrontendAction` since both 
derived classes maintain this state, but after a closer look, this seems to 
depend on both base classes. I'm not a big fun of maintaining states in 
multi-stage classes (e.g. `FrontendAction`), which could be confusing and hard 
to follow; I think `IndexRecordActionBase::finish(...)` should be able to 
handle the case where no index consumer is created (i.e. no 
record/dependency/... is collected).

Also, `IndexRecordActionBase` (and the existing `IndexActionBase `) should 
really be a component instead of a base class since none of its methods is 
`virtual`.



Comment at: lib/Index/IndexingAction.cpp:370
+public:
+  SourceFilesIndexDependencyCollector(IsSystemFileCache ,
+  RecordingOptions recordOpts)

`IsSystemFileCache `? What is this parameter?



Comment at: lib/Index/IndexingAction.cpp:459
+
+class IndexRecordActionBase {
+protected:

Please document this class. This can be easily confused with `IndexActionBase` 
which has a similar name. Same for `IndexAction`/`IndexRecordAction` and 
`WrappingIndexRecordAction`/`WrappingIndexRecordAction`.  I think these pairs 
share (especially the wrapping actions) some common logics and could probably 
be merged. 



Comment at: lib/Index/IndexingAction.cpp:485
+
+  void finish(CompilerInstance );
+};

This does a lot of stuff... please document the behavior!



Comment at: lib/Index/IndexingAction.cpp:577
+  if (!isModuleGeneration &&
+  CI.getFrontendOpts().ProgramAction != frontend::GeneratePCH) {
+RootFile = SM.getFileEntryForID(SM.getMainFileID());

nit: no need for braces. Same below.



Comment at: lib/Index/IndexingAction.cpp:589
+
+static void writeUnitData(const CompilerInstance ,
+  IndexDataRecorder ,

In the previous patch, `writeUnitData` does several things including handling 
modules, dependencies, 

Re: [PATCH] D41039: Add support for attribute "trivial_abi"

2017-12-11 Thread David Blaikie via cfe-commits
My bet would be: warn and ignore it, but probably Richard's & John might
have stronger thoughts/justifications/etc.

On Mon, Dec 11, 2017 at 1:38 PM Akira Hatanaka via Phabricator <
revi...@reviews.llvm.org> wrote:

> ahatanak added a comment.
>
> I had a discussion with Duncan today and he pointed out that perhaps we
> shouldn't allow users to annotate a struct with "trivial_abi" if one of its
> subobjects is non-trivial and is not annotated with "trivial_abi" since
> that gives users too much power.
>
> Should we error out or drop "trivial_abi" from struct Outer when the
> following code is compiled?
>
>   struct Inner1 {
> ~Inner1(); // non-trivial
> int x;
>   };
>
>   struct __attribute__((trivial_abi)) Outer {
> ~Outer();
> Inner1 x;
>   };
>
> The current patch doesn't error out or drop the attribute, but the patch
> would probably be much simpler if we didn't allow it.
>
>
> https://reviews.llvm.org/D41039
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41044: Implementation of -fextend-lifetimes and -fextend-this-ptr to aid with debugging of optimized code

2017-12-11 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

I should note we've had at least one request to make this specifiable 
per-function, which would mean defining an attribute to control the emission of 
the fake-use intrinsics.  Doing the feature that way would be consistent with 
'optnone'.


https://reviews.llvm.org/D41044



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


[PATCH] D40715: [analyser] different.LabelInsideSwitch checker implementation

2017-12-11 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

Thanks for looking into this!

This checker is in the 'core' package, which means (when moved out of alpha) it 
will be enabled by default.

- Do you think that this checker should be enabled by default for all users of 
the analyzer?
- If users do actually want to use labels in their switch statements, how 
should they suppress the diagnostics from the checker?
- What is the benefit of adding this check in the static analyzer vs. in 
clang-tidy?

(My own sense is that the check for labels that are close to "default" could be 
on by default but that warning on *any* label inside a switch is more 
stylistic. I think users should have to opt in to that check.)


Repository:
  rC Clang

https://reviews.llvm.org/D40715



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


[PATCH] D41080: Don't trigger -Wuser-defined-literals for system headers

2017-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM (wait for a day or so for @rsmith to respond in case he disagrees).


Repository:
  rC Clang

https://reviews.llvm.org/D41080



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


[PATCH] D41039: Add support for attribute "trivial_abi"

2017-12-11 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

I had a discussion with Duncan today and he pointed out that perhaps we 
shouldn't allow users to annotate a struct with "trivial_abi" if one of its 
subobjects is non-trivial and is not annotated with "trivial_abi" since that 
gives users too much power.

Should we error out or drop "trivial_abi" from struct Outer when the following 
code is compiled?

  struct Inner1 {
~Inner1(); // non-trivial
int x;
  };
  
  struct __attribute__((trivial_abi)) Outer {
~Outer();
Inner1 x;
  };

The current patch doesn't error out or drop the attribute, but the patch would 
probably be much simpler if we didn't allow it.


https://reviews.llvm.org/D41039



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


Re: r319875 - Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in C++.

2017-12-11 Thread Galina Kistanova via cfe-commits
Hans,

Thank you for fixing the test!

Thanks

Galina


On Mon, Dec 11, 2017 at 10:59 AM, Hans Wennborg  wrote:

> I've committed a fix to pacify the test in r320405.
>
> On Wed, Dec 6, 2017 at 12:27 PM, Galina Kistanova via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Hello Richard,
>>
>> This commit broke the tests on the builder:
>>
>> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensiv
>> e-checks-win/builds/6598
>>
>> . . .
>> Failing Tests (1):
>> Clang :: SemaCXX/warn-enum-compare.cpp
>>
>> Please have a look?
>>
>> Thanks
>>
>> Galina
>>
>> On Tue, Dec 5, 2017 at 7:00 PM, Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: rsmith
>>> Date: Tue Dec  5 19:00:51 2017
>>> New Revision: 319875
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=319875=rev
>>> Log:
>>> Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in
>>> C++.
>>>
>>> An enumeration with a fixed underlying type can have any value in its
>>> underlying type, not just those spanned by the values of its enumerators.
>>>
>>> Modified:
>>> cfe/trunk/lib/Sema/SemaChecking.cpp
>>> cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaC
>>> hecking.cpp?rev=319875=319874=319875=diff
>>> 
>>> ==
>>> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec  5 19:00:51 2017
>>> @@ -8260,11 +8260,12 @@ struct IntRange {
>>>  } else if (const EnumType *ET = dyn_cast(T)) {
>>>// For enum types in C++, use the known bit width of the
>>> enumerators.
>>>EnumDecl *Enum = ET->getDecl();
>>> -  // In C++11, enums without definitions can have an explicitly
>>> specified
>>> -  // underlying type.  Use this type to compute the range.
>>> -  if (!Enum->isCompleteDefinition())
>>> +  // In C++11, enums can have a fixed underlying type. Use this
>>> type to
>>> +  // compute the range.
>>> +  if (Enum->isFixed()) {
>>>  return IntRange(C.getIntWidth(QualType(T, 0)),
>>>  !ET->isSignedIntegerOrEnumerationType());
>>> +  }
>>>
>>>unsigned NumPositive = Enum->getNumPositiveBits();
>>>unsigned NumNegative = Enum->getNumNegativeBits();
>>>
>>> Modified: cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.
>>> cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/taut
>>> ological-unsigned-enum-zero-compare.cpp?rev=319875=319874
>>> =319875=diff
>>> 
>>> ==
>>> --- cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
>>> (original)
>>> +++ cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp Tue
>>> Dec  5 19:00:51 2017
>>> @@ -2,11 +2,11 @@
>>>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only
>>> -DSIGNED -verify %s
>>>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only
>>> -DSILENCE -Wno-tautological-unsigned-enum-zero-compare -verify %s
>>>
>>> -// Okay, this is where it gets complicated.
>>> -// Then default enum sigdness is target-specific.
>>> -// On windows, it is signed by default. We do not want to warn in that
>>> case.
>>> -
>>>  int main() {
>>> +  // On Windows, all enumerations have a fixed underlying type, which
>>> is 'int'
>>> +  // if not otherwise specified, so A is identical to C on Windows.
>>> Otherwise,
>>> +  // we follow the C++ rules, which say that the only valid values of A
>>> are 0
>>> +  // and 1.
>>>enum A { A_foo = 0, A_bar, };
>>>enum A a;
>>>
>>> @@ -87,21 +87,23 @@ int main() {
>>>
>>>if (c < 0)
>>>  return 0;
>>> -  if (0 >= c) // expected-warning {{comparison 0 >= 'enum C' is always
>>> true}}
>>> +  if (0 >= c)
>>>  return 0;
>>> -  if (c > 0) // expected-warning {{comparison 'enum C' > 0 is always
>>> false}}
>>> +  if (c > 0)
>>>  return 0;
>>>if (0 <= c)
>>>  return 0;
>>> -  if (c <= 0) // expected-warning {{comparison 'enum C' <= 0 is always
>>> true}}
>>> +  if (c <= 0)
>>>  return 0;
>>>if (0 > c)
>>>  return 0;
>>>if (c >= 0)
>>>  return 0;
>>> -  if (0 < c) // expected-warning {{0 < 'enum C' is always false}}
>>> +  if (0 < c)
>>>  return 0;
>>>
>>> +  // FIXME: These diagnostics are terrible. The issue here is that the
>>> signed
>>> +  // enumeration value was promoted to an unsigned type.
>>>if (c < 0U) // expected-warning {{comparison of unsigned enum
>>> expression < 0 is always false}}
>>>  return 0;
>>>if (0U >= c)
>>> @@ -121,21 +123,23 @@ int main() {
>>>  #elif defined(SIGNED)
>>>if (a < 0)
>>>  return 0;
>>> -  if (0 >= a) // expected-warning {{comparison 0 >= 'enum A' is always
>>> true}}
>>> +  if (0 >= a)
>>>  return 0;

[PATCH] D41080: Don't trigger -Wuser-defined-literals for system headers

2017-12-11 Thread Dimitry Andric via Phabricator via cfe-commits
dim updated this revision to Diff 126436.
dim added a comment.

Add a test case.


Repository:
  rC Clang

https://reviews.llvm.org/D41080

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
  test/SemaCXX/no-warn-user-defined-literals-in-system-headers.h


Index: test/SemaCXX/no-warn-user-defined-literals-in-system-headers.h
===
--- /dev/null
+++ test/SemaCXX/no-warn-user-defined-literals-in-system-headers.h
@@ -0,0 +1,2 @@
+// Header for no-warn-user-defined-literals-in-system-headers.cpp
+void operator "" foo (const char *);
Index: test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
===
--- /dev/null
+++ test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wsystem-headers -isystem 
%S %s
+
+#include 
+
+void operator "" bar(long double); // expected-warning{{user-defined literal 
suffixes not starting with '_' are reserved}}
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -13076,7 +13076,8 @@
 
   StringRef LiteralName
 = FnDecl->getDeclName().getCXXLiteralIdentifier()->getName();
-  if (LiteralName[0] != '_') {
+  if (LiteralName[0] != '_' &&
+  !getSourceManager().isInSystemHeader(FnDecl->getLocation())) {
 // C++11 [usrlit.suffix]p1:
 //   Literal suffix identifiers that do not start with an underscore
 //   are reserved for future standardization.


Index: test/SemaCXX/no-warn-user-defined-literals-in-system-headers.h
===
--- /dev/null
+++ test/SemaCXX/no-warn-user-defined-literals-in-system-headers.h
@@ -0,0 +1,2 @@
+// Header for no-warn-user-defined-literals-in-system-headers.cpp
+void operator "" foo (const char *);
Index: test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
===
--- /dev/null
+++ test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wsystem-headers -isystem %S %s
+
+#include 
+
+void operator "" bar(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -13076,7 +13076,8 @@
 
   StringRef LiteralName
 = FnDecl->getDeclName().getCXXLiteralIdentifier()->getName();
-  if (LiteralName[0] != '_') {
+  if (LiteralName[0] != '_' &&
+  !getSourceManager().isInSystemHeader(FnDecl->getLocation())) {
 // C++11 [usrlit.suffix]p1:
 //   Literal suffix identifiers that do not start with an underscore
 //   are reserved for future standardization.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: [PATCH] D41081: Fix clang Lexer Windows line-ending bug

2017-12-11 Thread Zhen Cao via cfe-commits
Thank you very much, Zachary :)

From: Zachary Turner [mailto:ztur...@google.com]
Sent: Monday, December 11, 2017 4:21 PM
To: Zhen Cao 
Cc: Benoit Belley ; 
reviews+d41081+public+5a71b504a12c1...@reviews.llvm.org; r...@google.com; 
cfe-commits@lists.llvm.org
Subject: Re: [PATCH] D41081: Fix clang Lexer Windows line-ending bug

I'll let rnk@ weigh in (he's on vacation today though).

I don't feel comfortable lgtm'ing any change where "don't use 
core.autocrlf=true" is an alternative solution, but if other people want to 
disagree with me and lgtm this, then that suggests I'm in the minority, which 
is fine.  :)

On Mon, Dec 11, 2017 at 1:13 PM Zhen Cao 
> wrote:
I think adding two lit substitutions is not a significant issue since dos2unix 
and unix2dos are common Unix utilities. This solution also has the advantage of 
testing both styles of line-endings with only one test case, which I think 
actually reduces complexity and maintenance burden.

From: Zachary Turner [mailto:ztur...@google.com]
Sent: Monday, December 11, 2017 3:42 PM
To: Benoit Belley 
>
Cc: 
reviews+d41081+public+5a71b504a12c1...@reviews.llvm.org;
 Zhen Cao >; 
r...@google.com

Subject: Re: [PATCH] D41081: Fix clang Lexer Windows line-ending bug

To be honest, I'm not a fan of testing code in a way that tries to work around 
issues related to source control.  I think we had a similar discussion before 
on a previous patch, and my suggested fix was to simply set core.autocrlf=false 
in your git config.  This solves all of these problems and does not come with 
any real downsides that I'm aware of.

It also yields better tests IMO, because the fewer steps of translation that an 
input has to go through before being fed to the test program the better.  If 
you want to test the behavior of a file with \r\n, just check in an input file 
with \r\n and you're ready to go.  Furthermore, by not doing this we are adding 
complexity (and hence, technical debt) *to the code* to deal with issues that 
could easily be solved using an appropriate developer configuration.  I'm not 
saying that we should not be testing the case of \r\n newlines, because we 
can't control what perforce outputs and the tool itself needs to work with 
either style of newline.  But we can control how we configure our git clones, 
and if doing so leads to better tests with less testing infrastructure hacks 
and workarounds, then I think we should do that.

On Mon, Dec 11, 2017 at 12:32 PM Benoit Belley 
> wrote:
Hi Zachary,

We are trying to be agnostic to how a particular SCM (SVN, Git) is handling 
line termination. For example, any CR, CRLF line-ending would be translated 
automatically by Git (CR only on unix, and CRLF on windows) unless these files 
are marked explicitly as binary files using a special .gitattribute file.

In summary, the proposed solution is:

  *   SCM agnostic
  *   Tests the handling both types of line endings on any platforms where the 
tests are run.
Cheers,
Benoit

From: Zachary Turner >
Date: lundi 11 décembre 2017 à 15:22
To: 
"reviews+d41081+public+5a71b504a12c1...@reviews.llvm.org"
 
>
Cc: Zhen Cao >, 
"r...@google.com" 
>, Benoit Belley 
>
Subject: Re: [PATCH] D41081: Fix clang Lexer Windows line-ending bug

Would it be possible to do this without any substitutions at all? It seems a 
little heavy handed to add a new lit substitution for something that is only 
going to be used in one test.

Can we just check in two different input files, one with CR and another with 
CRLF, and use those as inputs to the test?
On Mon, Dec 11, 2017 at 12:18 PM Zhen Cao via Phabricator 
> wrote:
caoz added a subscriber: cfe-commits.

https://reviews.llvm.org/D41081

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


Re: [PATCH] D41081: Fix clang Lexer Windows line-ending bug

2017-12-11 Thread Zachary Turner via cfe-commits
I'll let rnk@ weigh in (he's on vacation today though).

I don't feel comfortable lgtm'ing any change where "don't use
core.autocrlf=true" is an alternative solution, but if other people want to
disagree with me and lgtm this, then that suggests I'm in the minority,
which is fine.  :)

On Mon, Dec 11, 2017 at 1:13 PM Zhen Cao  wrote:

> I think adding two lit substitutions is not a significant issue since
> dos2unix and unix2dos are common Unix utilities. This solution also has the
> advantage of testing both styles of line-endings with only one test case,
> which I think actually reduces complexity and maintenance burden.
>
>
>
> *From:* Zachary Turner [mailto:ztur...@google.com]
> *Sent:* Monday, December 11, 2017 3:42 PM
> *To:* Benoit Belley 
> *Cc:* reviews+d41081+public+5a71b504a12c1...@reviews.llvm.org; Zhen Cao <
> zhen@autodesk.com>; r...@google.com
>
>
> *Subject:* Re: [PATCH] D41081: Fix clang Lexer Windows line-ending bug
>
>
>
> To be honest, I'm not a fan of testing code in a way that tries to work
> around issues related to source control.  I think we had a similar
> discussion before on a previous patch, and my suggested fix was to simply
> set core.autocrlf=false in your git config.  This solves all of these
> problems and does not come with any real downsides that I'm aware of.
>
>
>
> It also yields better tests IMO, because the fewer steps of translation
> that an input has to go through before being fed to the test program the
> better.  If you want to test the behavior of a file with \r\n, just check
> in an input file with \r\n and you're ready to go.  Furthermore, by not
> doing this we are adding complexity (and hence, technical debt) *to the
> code* to deal with issues that could easily be solved using an appropriate
> developer configuration.  I'm not saying that we should not be testing the
> case of \r\n newlines, because we can't control what perforce outputs and
> the tool itself needs to work with either style of newline.  But we can
> control how we configure our git clones, and if doing so leads to better
> tests with less testing infrastructure hacks and workarounds, then I think
> we should do that.
>
>
>
> On Mon, Dec 11, 2017 at 12:32 PM Benoit Belley 
> wrote:
>
> Hi Zachary,
>
>
>
> We are trying to be agnostic to how a particular SCM (SVN, Git) is
> handling line termination. For example, any CR, CRLF line-ending would be
> translated automatically by Git (CR only on unix, and CRLF on windows)
> unless these files are marked explicitly as binary files using a special
> .gitattribute file.
>
>
>
> In summary, the proposed solution is:
>
>- SCM agnostic
>- Tests the handling both types of line endings on any platforms where
>the tests are run.
>
> Cheers,
>
> Benoit
>
>
>
> *From: *Zachary Turner 
> *Date: *lundi 11 décembre 2017 à 15:22
> *To: *"reviews+d41081+public+5a71b504a12c1...@reviews.llvm.org" <
> reviews+d41081+public+5a71b504a12c1...@reviews.llvm.org>
> *Cc: *Zhen Cao , "r...@google.com" ,
> Benoit Belley 
> *Subject: *Re: [PATCH] D41081: Fix clang Lexer Windows line-ending bug
>
>
>
> Would it be possible to do this without any substitutions at all? It seems
> a little heavy handed to add a new lit substitution for something that is
> only going to be used in one test.
>
> Can we just check in two different input files, one with CR and another
> with CRLF, and use those as inputs to the test?
>
> On Mon, Dec 11, 2017 at 12:18 PM Zhen Cao via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
> caoz added a subscriber: cfe-commits.
>
> https://reviews.llvm.org/D41081
> 
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36952: [libclang] Add support for checking abstractness of records

2017-12-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D36952



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


RE: [PATCH] D41081: Fix clang Lexer Windows line-ending bug

2017-12-11 Thread Zhen Cao via cfe-commits
I think adding two lit substitutions is not a significant issue since dos2unix 
and unix2dos are common Unix utilities. This solution also has the advantage of 
testing both styles of line-endings with only one test case, which I think 
actually reduces complexity and maintenance burden.

From: Zachary Turner [mailto:ztur...@google.com]
Sent: Monday, December 11, 2017 3:42 PM
To: Benoit Belley 
Cc: reviews+d41081+public+5a71b504a12c1...@reviews.llvm.org; Zhen Cao 
; r...@google.com
Subject: Re: [PATCH] D41081: Fix clang Lexer Windows line-ending bug

To be honest, I'm not a fan of testing code in a way that tries to work around 
issues related to source control.  I think we had a similar discussion before 
on a previous patch, and my suggested fix was to simply set core.autocrlf=false 
in your git config.  This solves all of these problems and does not come with 
any real downsides that I'm aware of.

It also yields better tests IMO, because the fewer steps of translation that an 
input has to go through before being fed to the test program the better.  If 
you want to test the behavior of a file with \r\n, just check in an input file 
with \r\n and you're ready to go.  Furthermore, by not doing this we are adding 
complexity (and hence, technical debt) *to the code* to deal with issues that 
could easily be solved using an appropriate developer configuration.  I'm not 
saying that we should not be testing the case of \r\n newlines, because we 
can't control what perforce outputs and the tool itself needs to work with 
either style of newline.  But we can control how we configure our git clones, 
and if doing so leads to better tests with less testing infrastructure hacks 
and workarounds, then I think we should do that.

On Mon, Dec 11, 2017 at 12:32 PM Benoit Belley 
> wrote:
Hi Zachary,

We are trying to be agnostic to how a particular SCM (SVN, Git) is handling 
line termination. For example, any CR, CRLF line-ending would be translated 
automatically by Git (CR only on unix, and CRLF on windows) unless these files 
are marked explicitly as binary files using a special .gitattribute file.

In summary, the proposed solution is:

  *   SCM agnostic
  *   Tests the handling both types of line endings on any platforms where the 
tests are run.
Cheers,
Benoit

From: Zachary Turner >
Date: lundi 11 décembre 2017 à 15:22
To: 
"reviews+d41081+public+5a71b504a12c1...@reviews.llvm.org"
 
>
Cc: Zhen Cao >, 
"r...@google.com" 
>, Benoit Belley 
>
Subject: Re: [PATCH] D41081: Fix clang Lexer Windows line-ending bug

Would it be possible to do this without any substitutions at all? It seems a 
little heavy handed to add a new lit substitution for something that is only 
going to be used in one test.

Can we just check in two different input files, one with CR and another with 
CRLF, and use those as inputs to the test?
On Mon, Dec 11, 2017 at 12:18 PM Zhen Cao via Phabricator 
> wrote:
caoz added a subscriber: cfe-commits.

https://reviews.llvm.org/D41081


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


[PATCH] D40230: Add -mprefer-vector-width driver option and attribute during CodeGen.

2017-12-11 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320419: [Driver][CodeGen] Add -mprefer-vector-width driver 
option and attribute during… (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D40230?vs=123709=126434#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40230

Files:
  cfe/trunk/docs/ClangCommandLineReference.rst
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.h
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c
  cfe/trunk/test/Driver/mprefer-vector-width.c

Index: cfe/trunk/docs/ClangCommandLineReference.rst
===
--- cfe/trunk/docs/ClangCommandLineReference.rst
+++ cfe/trunk/docs/ClangCommandLineReference.rst
@@ -2120,6 +2120,10 @@
 
 Use copy relocations support for PIE builds
 
+.. option:: -mprefer-vector-width=
+
+Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.
+
 .. option:: -mqdsp6-compat
 
 Enable hexagon-qdsp6 backward compatibility
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -1954,6 +1954,8 @@
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, Flags<[CC1Option]>;
+def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, Group, Flags<[CC1Option]>,
+  HelpText<"Specifies preferred vector width for auto-vectorization. Defaults to 'none' which allows target specific decisions.">;
 def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, Group,
   Flags<[CC1Option]>,
   HelpText<"Use copy relocations support for PIE builds">;
Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
===
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h
@@ -253,6 +253,11 @@
 
   std::vector Reciprocals;
 
+  /// The preferred width for auto-vectorization transforms. This is intended to
+  /// override default transforms based on the width of the architected vector
+  /// registers.
+  std::string PreferVectorWidth;
+
 public:
   // Define accessors/mutators for code generation options of enumeration type.
 #define CODEGENOPT(Name, Bits, Default)
Index: cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c
===
--- cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c
+++ cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -mprefer-vector-width=128 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK128
+// RUN: %clang_cc1 -mprefer-vector-width=256 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK256
+// RUN: %clang_cc1 -mprefer-vector-width=none -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECKNONE
+
+int baz(int a) { return 4; }
+
+// CHECK128: baz{{.*}} #0
+// CHECK128: #0 = {{.*}}"prefer-vector-width"="128"
+
+// CHECK256: baz{{.*}} #0
+// CHECK256: #0 = {{.*}}"prefer-vector-width"="256"
+
+// CHECKNONE: baz{{.*}} #0
+// CHECKNONE-NOT: #0 = {{.*}}"prefer-vector-width"="none"
Index: cfe/trunk/test/Driver/mprefer-vector-width.c
===
--- cfe/trunk/test/Driver/mprefer-vector-width.c
+++ cfe/trunk/test/Driver/mprefer-vector-width.c
@@ -0,0 +1,24 @@
+
+ Verify that valid options for the -mprefer-vector-width flag are passed through and invalid options cause an error.
+
+
+ If there are no options, convert to 'all'.
+
+// RUN: %clang -### -S %s -mprefer-vector-width=none  2>&1 | FileCheck --check-prefix=WIDTHNONE %s
+// WIDTHNONE: "-mprefer-vector-width=none"
+
+ Check options that cover all types.
+
+// RUN: %clang -### -S %s -mprefer-vector-width=128  2>&1 | FileCheck --check-prefix=WIDTH128 %s
+// WIDTH128: "-mprefer-vector-width=128"
+
+ Check invalid parameters.
+
+// RUN: %clang -### -S %s -mprefer-vector-width=one  2>&1 | FileCheck --check-prefix=WIDTHONE %s
+// WIDTHONE: invalid value 'one' in 'mprefer-vector-width='
+
+// RUN: %clang -### -S %s -mprefer-vector-width=128.5  2>&1 | FileCheck --check-prefix=WIDTH128p5 %s
+// WIDTH128p5: invalid value '128.5' in 'mprefer-vector-width='
+
+// RUN: %clang -### -S %s -mprefer-vector-width=-128  2>&1 | FileCheck --check-prefix=WIDTHNEG128 %s
+// WIDTHNEG128: invalid value '-128' in 'mprefer-vector-width='
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ 

r320419 - [Driver][CodeGen] Add -mprefer-vector-width driver option and attribute during CodeGen.

2017-12-11 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon Dec 11 13:09:19 2017
New Revision: 320419

URL: http://llvm.org/viewvc/llvm-project?rev=320419=rev
Log:
[Driver][CodeGen] Add -mprefer-vector-width driver option and attribute during 
CodeGen.

This adds a new command line option -mprefer-vector-width to specify a 
preferred vector width for the vectorizers. Valid values are 'none' and 
unsigned integers. The driver will check that it meets those constraints. 
Specific supported integers will be managed by the targets in the backend.

Clang will take the value and add it as a new function attribute during CodeGen.

This represents the alternate direction proposed by Sanjay in this RFC: 
http://lists.llvm.org/pipermail/llvm-dev/2017-November/118734.html

The syntax here matches gcc, though gcc treats it as an x86 specific command 
line argument. gcc only allows values of 128, 256, and 512. I'm not having 
clang check any values.

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

Added:
cfe/trunk/test/CodeGen/attr-mprefer-vector-width.c   (with props)
cfe/trunk/test/Driver/mprefer-vector-width.c   (with props)
Modified:
cfe/trunk/docs/ClangCommandLineReference.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=320419=320418=320419=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Mon Dec 11 13:09:19 2017
@@ -2120,6 +2120,10 @@ Omit frame pointer setup for leaf functi
 
 Use copy relocations support for PIE builds
 
+.. option:: -mprefer-vector-width=
+
+Specifies preferred vector width for auto-vectorization. Defaults to 'none' 
which allows target specific decisions.
+
 .. option:: -mqdsp6-compat
 
 Enable hexagon-qdsp6 backward compatibility

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=320419=320418=320419=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Dec 11 13:09:19 2017
@@ -1954,6 +1954,8 @@ def mno_implicit_float : Flag<["-"], "mn
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>;
+def mprefer_vector_width_EQ : Joined<["-"], "mprefer-vector-width=">, 
Group, Flags<[CC1Option]>,
+  HelpText<"Specifies preferred vector width for auto-vectorization. Defaults 
to 'none' which allows target specific decisions.">;
 def mpie_copy_relocations : Flag<["-"], "mpie-copy-relocations">, 
Group,
   Flags<[CC1Option]>,
   HelpText<"Use copy relocations support for PIE builds">;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=320419=320418=320419=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Mon Dec 11 13:09:19 2017
@@ -253,6 +253,11 @@ public:
 
   std::vector Reciprocals;
 
+  /// The preferred width for auto-vectorization transforms. This is intended 
to
+  /// override default transforms based on the width of the architected vector
+  /// registers.
+  std::string PreferVectorWidth;
+
 public:
   // Define accessors/mutators for code generation options of enumeration type.
 #define CODEGENOPT(Name, Bits, Default)

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=320419=320418=320419=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Dec 11 13:09:19 2017
@@ -1744,6 +1744,11 @@ void CodeGenModule::ConstructDefaultFnAt
   FuncAttrs.addAttribute("reciprocal-estimates",
  llvm::join(Recips, ","));
 
+if (!CodeGenOpts.PreferVectorWidth.empty() &&
+CodeGenOpts.PreferVectorWidth != "none")
+  FuncAttrs.addAttribute("prefer-vector-width",
+ CodeGenOpts.PreferVectorWidth);
+
 if (CodeGenOpts.StackRealignment)
   FuncAttrs.addAttribute("stackrealign");
 if (CodeGenOpts.Backchain)

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=320419=320418=320419=diff

r320418 - [Docs] Regenerate command line documentation.

2017-12-11 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Mon Dec 11 13:09:16 2017
New Revision: 320418

URL: http://llvm.org/viewvc/llvm-project?rev=320418=rev
Log:
[Docs] Regenerate command line documentation.

Modified:
cfe/trunk/docs/ClangCommandLineReference.rst

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=320418=320417=320418=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Mon Dec 11 13:09:16 2017
@@ -1281,6 +1281,10 @@ Enable '\[\[\]\]' attributes in all C an
 
 .. option:: -fdwarf-directory-asm, -fno-dwarf-directory-asm
 
+.. option:: -fdwarf-exceptions
+
+Use DWARF style exceptions
+
 .. option:: -felide-constructors, -fno-elide-constructors
 
 .. option:: -feliminate-unused-debug-symbols, 
-fno-eliminate-unused-debug-symbols
@@ -1357,6 +1361,10 @@ Implicitly search the file system for mo
 
 .. option:: -finput-charset=
 
+.. option:: -finstrument-function-entry-bare
+
+Instrument function entry only, after inlining, without arguments to the 
instrumentation call
+
 .. option:: -finstrument-functions
 
 Generate calls to instrument function entry and exit
@@ -1678,6 +1686,10 @@ Turn on loop reroller
 
 Generate a YAML optimization record file
 
+.. option:: -fseh-exceptions
+
+Use SEH style exceptions
+
 .. option:: -fshort-enums, -fno-short-enums
 
 Allocate to an enum type only as many bytes as it needs for the declared range 
of possible values
@@ -1706,18 +1718,10 @@ Which overload candidates to show when o
 
 Enable C++14 sized global deallocation functions
 
-.. option:: -fdwarf-exceptions
-
-Use DWARF style exceptions
-
 .. option:: -fsjlj-exceptions
 
 Use SjLj style exceptions
 
-.. option:: -fseh-exceptions
-
-Use SEH style exceptions
-
 .. option:: -fslp-vectorize, -fno-slp-vectorize, -ftree-slp-vectorize
 
 Enable the superword-level parallelism vectorization passes
@@ -1870,6 +1874,10 @@ Treat signed integer overflow as two's c
 
 Store string literals as writable data
 
+.. option:: -fxray-always-emit-customevents, -fno-xray-always-emit-customevents
+
+Determine whether to always emit \_\_xray\_customevent(...) calls even if the 
function it appears in is not always instrumented.
+
 .. option:: -fxray-always-instrument=
 
 Filename defining the whitelist for imbuing the 'always instrument' XRay 
attribute.
@@ -2298,6 +2306,8 @@ PowerPC
 
 WebAssembly
 ---
+.. option:: -mnontrapping-fptoint, -mno-nontrapping-fptoint
+
 .. option:: -msimd128, -mno-simd128
 
 X86
@@ -2356,6 +2366,8 @@ X86
 
 .. option:: -mfxsr, -mno-fxsr
 
+.. option:: -mibt, -mno-ibt
+
 .. option:: -mlwp, -mno-lwp
 
 .. option:: -mlzcnt, -mno-lzcnt
@@ -2388,6 +2400,8 @@ X86
 
 .. option:: -msha, -mno-sha
 
+.. option:: -mshstk, -mno-shstk
+
 .. option:: -msse, -mno-sse
 
 .. option:: -msse2, -mno-sse2


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


[PATCH] D39375: [clang] Add PPCallbacks list to preprocessor when building a preacompiled preamble.

2017-12-11 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 126430.
Nebiroth added a comment.

Removed unique_ptr parameter in PrecompiledPreamble::Build
Added method createPPCallbacks() in PreambleCallback to be overriden


Repository:
  rC Clang

https://reviews.llvm.org/D39375

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


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -351,6 +351,8 @@
   if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
 return BuildPreambleError::BeginSourceFileFailed;
 
+  if (Callbacks.createPPCallbacks())
+
Clang->getPreprocessor().addPPCallbacks(std::move(Callbacks.createPPCallbacks()));
   Act->Execute();
 
   // Run the callbacks.
@@ -709,6 +711,7 @@
 void PreambleCallbacks::HandleTopLevelDecl(DeclGroupRef DG) {}
 void PreambleCallbacks::HandleMacroDefined(const Token ,
const MacroDirective *MD) {}
+std::unique_ptr PreambleCallbacks::createPPCallbacks() {return 
nullptr;}
 
 std::error_code clang::make_error_code(BuildPreambleError Error) {
   return std::error_code(static_cast(Error), 
BuildPreambleErrorCategory());
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -260,6 +260,9 @@
   /// used instead, but having only this method allows a simpler API.
   virtual void HandleMacroDefined(const Token ,
   const MacroDirective *MD);
+  /// Adds list of Preprocessor callbacks so we can also process information
+  /// about includes that are outside of a preamble i.e in the middle of a file
+  virtual std::unique_ptr createPPCallbacks();
 };
 
 enum class BuildPreambleError {


Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -351,6 +351,8 @@
   if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
 return BuildPreambleError::BeginSourceFileFailed;
 
+  if (Callbacks.createPPCallbacks())
+Clang->getPreprocessor().addPPCallbacks(std::move(Callbacks.createPPCallbacks()));
   Act->Execute();
 
   // Run the callbacks.
@@ -709,6 +711,7 @@
 void PreambleCallbacks::HandleTopLevelDecl(DeclGroupRef DG) {}
 void PreambleCallbacks::HandleMacroDefined(const Token ,
const MacroDirective *MD) {}
+std::unique_ptr PreambleCallbacks::createPPCallbacks() {return nullptr;}
 
 std::error_code clang::make_error_code(BuildPreambleError Error) {
   return std::error_code(static_cast(Error), BuildPreambleErrorCategory());
Index: include/clang/Frontend/PrecompiledPreamble.h
===
--- include/clang/Frontend/PrecompiledPreamble.h
+++ include/clang/Frontend/PrecompiledPreamble.h
@@ -260,6 +260,9 @@
   /// used instead, but having only this method allows a simpler API.
   virtual void HandleMacroDefined(const Token ,
   const MacroDirective *MD);
+  /// Adds list of Preprocessor callbacks so we can also process information
+  /// about includes that are outside of a preamble i.e in the middle of a file
+  virtual std::unique_ptr createPPCallbacks();
 };
 
 enum class BuildPreambleError {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38639: [clangd] #include statements support for Open definition

2017-12-11 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 126429.
Nebiroth added a comment.

  Creating unique_ptr for wrapper class now uses overriden method 
createPPCallbacks() from PrecompiledPreamble class
  Moved wrapper class to inline inside createPPCallbacks()
  Wrapper class now uses CppFilePreambleCallbacks as field


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38639

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Protocol.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-#include "ClangdLSPServer.h"
 #include "ClangdServer.h"
 #include "Logger.h"
 #include "TestFS.h"
@@ -620,7 +619,7 @@
 AddDocument(FileIndex);
 
   Position Pos{LineDist(RandGen), ColumnDist(RandGen)};
-  ASSERT_TRUE(!!Server.findDefinitions(FilePaths[FileIndex], Pos));
+  Server.findDefinitions(FilePaths[FileIndex], Pos);
 };
 
 std::vector> AsyncRequests = {
@@ -749,6 +748,58 @@
   EXPECT_FALSE(PathResult.hasValue());
 }
 
+TEST_F(ClangdVFSTest, CheckDefinitionIncludes) {
+  MockFSProvider FS;
+  ErrorCheckingDiagConsumer DiagConsumer;
+  MockCompilationDatabase CDB;
+
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  EmptyLogger::getInstance());
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  const auto SourceContents = R"cpp(
+  #include "foo.h"
+  #include "invalid.h"
+  int b = a;
+  )cpp";
+  FS.Files[FooCpp] = SourceContents;
+  auto FooH = getVirtualTestFilePath("foo.h");
+  const auto HeaderContents = "int a;";
+
+  FS.Files[FooCpp] = SourceContents;
+  FS.Files[FooH] = HeaderContents;
+
+  Server.addDocument(FooH, HeaderContents);
+  Server.addDocument(FooCpp, SourceContents);
+
+  Position P = Position{1, 11};
+
+  std::vector Locations = Server.findDefinitions(FooCpp, P).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+  std::string s("file:///");
+  std::string check = Locations[0].uri.uri;
+  check = check.erase(0, s.size());
+  check = check.substr(0, check.size() - 1);
+  ASSERT_EQ(check, FooH);
+  ASSERT_EQ(Locations[0].range.start.line, 0);
+  ASSERT_EQ(Locations[0].range.start.character, 0);
+  ASSERT_EQ(Locations[0].range.end.line, 0);
+  ASSERT_EQ(Locations[0].range.end.character, 0);
+
+  // Test ctrl-clicking on the #include part on the statement
+  Position P3 = Position{1, 3};
+
+  Locations = Server.findDefinitions(FooCpp, P3).get().Value;
+  EXPECT_TRUE(!Locations.empty());
+
+  // Test invalid include
+  Position P2 = Position{2, 11};
+
+  Locations = Server.findDefinitions(FooCpp, P2).get().Value;
+  EXPECT_TRUE(Locations.empty());
+}
+
 TEST_F(ClangdThreadingTest, NoConcurrentDiagnostics) {
   class NoConcurrentAccessDiagConsumer : public DiagnosticsConsumer {
   public:
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -108,6 +108,14 @@
 bool fromJSON(const json::Expr &, Range &);
 json::Expr toJSON(const Range &);
 
+class RangeHash {
+public:
+  std::size_t operator()(const Range ) const {
+return ((R.start.line & 0x18) << 3) | ((R.start.character & 0x18) << 1) |
+   ((R.end.line & 0x18) >> 1) | ((R.end.character & 0x18) >> 3);
+  }
+};
+
 struct Location {
   /// The text document's URI.
   URI uri;
Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace llvm {
 class raw_ostream;
@@ -59,6 +60,15 @@
   std::vector Diags;
 };
 
+class IncludeReferenceMap {
+  llvm::Optional findIncludeTargetAtLoc(Location Loc);
+
+public:
+  std::unordered_map IncludeLocationMap;
+  std::vector> DataVector;
+  std::vector RangeVector;
+};
+
 /// Stores and provides access to parsed AST.
 class ParsedAST {
 public:
@@ -69,7 +79,8 @@
 std::shared_ptr Preamble,
 std::unique_ptr Buffer,
 std::shared_ptr PCHs,
-IntrusiveRefCntPtr VFS, clangd::Logger );
+IntrusiveRefCntPtr VFS, clangd::Logger ,
+IncludeReferenceMap IRM);
 
   ParsedAST(ParsedAST &);
   ParsedAST =(ParsedAST &);
@@ -89,12 +100,14 @@
 
   const std::vector () const;
 
+  IncludeReferenceMap takeIRM() { return IRM; };
+
 private:
   ParsedAST(std::shared_ptr Preamble,
 std::unique_ptr Clang,
 std::unique_ptr Action,
 std::vector TopLevelDecls,
-std::vector Diags);
+std::vector Diags, IncludeReferenceMap IRM);
 
 private:
   void ensurePreambleDeclsDeserialized();
@@ -114,6 +127,8 @@
   

[PATCH] D41087: [Preprocessor] Implement __is_target_{arch|vendor|os|environment} function-like builtin macros

2017-12-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

This patch implements the `__is_target_arch`, `__is_target_vendor`, 
`__is_target_os`, and `__is_target_environment` Clang preprocessor extensions 
that were proposed by @compnerd in Bob's cfe-dev post: 
http://lists.llvm.org/pipermail/cfe-dev/2017-November/056166.html.

These macros can be used to examine the components of the target triple at 
compile time. A`__has_builtin(__is_target_???)` preprocessor check can be used 
to check for their availability.


Repository:
  rC Clang

https://reviews.llvm.org/D41087

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/PPMacroExpansion.cpp
  test/Preprocessor/is_target.c
  test/Preprocessor/is_target_os_darwin.c
  test/Preprocessor/is_target_unknown.c

Index: test/Preprocessor/is_target_unknown.c
===
--- /dev/null
+++ test/Preprocessor/is_target_unknown.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -triple i686-unknown-unknown -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple i686-- -verify %s
+// expected-no-diagnostics
+
+#if __is_target_arch(unknown)
+  #error "invalid arch"
+#endif
+
+// Unknown vendor is allowed.
+#if !__is_target_vendor(unknown)
+  #error "invalid vendor"
+#endif
+
+// Unknown OS is allowed.
+#if !__is_target_os(unknown)
+  #error "invalid OS"
+#endif
+
+// Unknown environment is allowed.
+#if !__is_target_environment(unknown)
+  #error "invalid environment"
+#endif
Index: test/Preprocessor/is_target_os_darwin.c
===
--- /dev/null
+++ test/Preprocessor/is_target_os_darwin.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macos -DMAC -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-ios -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-tvos -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-watchos -verify %s
+// expected-no-diagnostics
+
+#if !__is_target_os(darwin)
+  #error "invalid os"
+#endif
+
+// macOS matches both macOS and macOSX.
+#ifdef MAC
+
+#if !__is_target_os(macos)
+  #error "invalid os"
+#endif
+
+#if !__is_target_os(macosx)
+  #error "invalid os"
+#endif
+
+#if __is_target_os(ios)
+  #error "invalid os"
+#endif
+
+#endif
Index: test/Preprocessor/is_target.c
===
--- /dev/null
+++ test/Preprocessor/is_target.c
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin-simulator -verify %s
+
+#if !__is_target_arch(x86_64) || !__is_target_arch(X86_64)
+  #error "invalid arch"
+#endif
+
+#if __is_target_arch(arm64)
+  #error "invalid arch"
+#endif
+
+// Silently ignore invalid archs. This will ensure that older compilers will
+// accept headers that support new arches/vendors/os variants.
+#if __is_target_arch(foo)
+  #error "invalid arch"
+#endif
+
+#if !__is_target_vendor(apple) || !__is_target_vendor(APPLE)
+  #error "invalid vendor"
+#endif
+
+#if __is_target_vendor(unknown)
+  #error "invalid vendor"
+#endif
+
+#if __is_target_vendor(foo)
+  #error "invalid vendor"
+#endif
+
+#if !__is_target_os(darwin) || !__is_target_os(DARWIN)
+  #error "invalid os"
+#endif
+
+#if __is_target_os(ios)
+  #error "invalid os"
+#endif
+
+#if __is_target_os(foo)
+  #error "invalid os"
+#endif
+
+#if !__is_target_environment(simulator) || !__is_target_environment(SIMULATOR)
+  #error "invalid environment"
+#endif
+
+#if __is_target_environment(unknown)
+  #error "invalid environment"
+#endif
+
+#if __is_target_environment(foo)
+  #error "invalid environment"
+#endif
+
+#if !__has_builtin(__is_target_arch) || !__has_builtin(__is_target_os) || !__has_builtin(__is_target_vendor) || !__has_builtin(__is_target_environment)
+  #error "has feature doesn't work"
+#endif
+
+#if __is_target_arch(11) // expected-error {{builtin feature check macro requires a parenthesized identifier}}
+  #error "invalid arch"
+#endif
+
+#if __is_target_arch x86 // expected-error{{missing '(' after '__is_target_arch'}}
+  #error "invalid arch"
+#endif
+
+#if __is_target_arch ( x86  // expected-error {{unterminated function-like macro invocation}}
+  #error "invalid arch"
+#endif // expected-error@-2 {{expected value in expression}}
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -375,6 +375,11 @@
   Ident__has_include_next = RegisterBuiltinMacro(*this, "__has_include_next");
   Ident__has_warning  = RegisterBuiltinMacro(*this, "__has_warning");
   Ident__is_identifier= RegisterBuiltinMacro(*this, "__is_identifier");
+  Ident__is_target_arch   = RegisterBuiltinMacro(*this, "__is_target_arch");
+  Ident__is_target_vendor = RegisterBuiltinMacro(*this, "__is_target_vendor");
+  Ident__is_target_os = RegisterBuiltinMacro(*this, "__is_target_os");
+  Ident__is_target_environment =
+  RegisterBuiltinMacro(*this, 

Re: [PATCH] D41081: Fix clang Lexer Windows line-ending bug

2017-12-11 Thread Zachary Turner via cfe-commits
See my other response. Maybe we don’t even need a substitution at all?
On Mon, Dec 11, 2017 at 12:24 PM Benoit Belley via Phabricator <
revi...@reviews.llvm.org> wrote:

> belleyb added inline comments.
>
>
> 
> Comment at: test/lit.cfg.py:52-57
> +if platform.system() in ['Windows']:
> +config.substitutions.append(('dos2unix', 'sed -b "s/\r$//"'))
> +config.substitutions.append(('unix2dos', 'sed -b "s/\r*$/\r/"'))
> +else:
> +config.substitutions.append(('dos2unix', "sed $'s/\r$//'"))
> +config.substitutions.append(('unix2dos', "sed $'s/\r*$/\r/'"))
> 
> caoz wrote:
> > zturner wrote:
> > > Since the user has `sed` already, why wouldn't they have the actual
> tool `dos2unix` and `unix2dos`?
> > Thanks Zachary. dos2unix and unix2dos aren't installed by default on
> Linux/Mac. However, if the user can be assumed to have them, I can remove
> these substitutions.
> @zturner According to https://llvm.org/docs/GettingStarted.html#software,
> we shouldn't be relying on `dos2unix` nor `unix2dos` to be present on a
> build machine.
>
> Note that the `$'string'` syntax (ANSI-C quotes) is a `bash` extension.
> According to the page mentioned above, the LLVM builds should only be
> relying on having a Bourne shell (`sh`). But, are there still any *nix
> system out there where `/bin/sh` isn't a link for `\bin\bash` ? I.e. Is
> relying on `bash+sed` fine here ?
>
> A fully portable solution would be to write python scripts for
> `dos2unix.py` and `unix2dos.py`. That way, one would not be relying on
> build tools that LLVM isn't already using.
>
> Any advice on how to proceed ?
>
>
>
>
> https://reviews.llvm.org/D41081
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41081: Fix clang Lexer Windows line-ending bug

2017-12-11 Thread Benoit Belley via Phabricator via cfe-commits
belleyb added inline comments.



Comment at: test/lit.cfg.py:52-57
+if platform.system() in ['Windows']:
+config.substitutions.append(('dos2unix', 'sed -b "s/\r$//"'))
+config.substitutions.append(('unix2dos', 'sed -b "s/\r*$/\r/"'))
+else:
+config.substitutions.append(('dos2unix', "sed $'s/\r$//'"))
+config.substitutions.append(('unix2dos', "sed $'s/\r*$/\r/'"))

caoz wrote:
> zturner wrote:
> > Since the user has `sed` already, why wouldn't they have the actual tool 
> > `dos2unix` and `unix2dos`?
> Thanks Zachary. dos2unix and unix2dos aren't installed by default on 
> Linux/Mac. However, if the user can be assumed to have them, I can remove 
> these substitutions.
@zturner According to https://llvm.org/docs/GettingStarted.html#software, we 
shouldn't be relying on `dos2unix` nor `unix2dos` to be present on a build 
machine. 

Note that the `$'string'` syntax (ANSI-C quotes) is a `bash` extension. 
According to the page mentioned above, the LLVM builds should only be relying 
on having a Bourne shell (`sh`). But, are there still any *nix system out there 
where `/bin/sh` isn't a link for `\bin\bash` ? I.e. Is relying on `bash+sed` 
fine here ?

A fully portable solution would be to write python scripts for `dos2unix.py` 
and `unix2dos.py`. That way, one would not be relying on build tools that LLVM 
isn't already using.

Any advice on how to proceed ?




https://reviews.llvm.org/D41081



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


[PATCH] D41056: [clang-tidy] New check misc-uniqueptr-release-unused-retval

2017-12-11 Thread Kalle Huttunen via Phabricator via cfe-commits
khuttun added a comment.

In https://reviews.llvm.org/D41056#951145, @aaron.ballman wrote:

> In https://reviews.llvm.org/D41056#951083, @alexfh wrote:
>
> > In https://reviews.llvm.org/D41056#950605, @khuttun wrote:
> >
> > > In https://reviews.llvm.org/D41056#950570, @Eugene.Zelenko wrote:
> > >
> > > > May be //bugprone// is better module then //misc//?
> > >
> > >
> > > Maybe. I can move it if all the reviewers think that it would be better 
> > > suited there.
> >
> >
> > Yup, bugprone- should be a better category for this, IMO.
> >
> > I wonder whether libc++ folks are interested in marking 
> > unique_ptr::release() with `__attribute__ ((warn_unused_result))`. A 
> > compiler warning (with -Werror) would be a better protection against this 
> > kind of a bug.
>
>
> There's a push in WG21 to mark more of the library with `[[nodiscard]]`: 
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0600r1.pdf
>
> If we have a check for this, I do not think it should be specific to 
> `unique_ptr::release()`, but instead be more broadly applicable to APIs that 
> should be marked `[[nodiscard]]` but are not (currently). P0600R1 is a good 
> place to start, but I'm guessing there are POSIX APIs (among others) that 
> would also qualify.


P0600R1 seems to suggest quite conservative approach (and rightly so, IMO) in 
taking `[[nodiscard]]` in use in std lib. For example it proposes *not* to use 
it with `unique_ptr::release`. I think there could still be room for static 
unused ret val checking for parts of std lib not covered by P0600R1, but also 
for boost, POSIX APIs etc.

What do you think about making this check fully configurable through the check 
options? The options could list the functions to check. The documentation could 
suggest some candidate functions from std lib to configure checks for.


Repository:
  rL LLVM

https://reviews.llvm.org/D41056



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


[PATCH] D41044: Implementation of -fextend-lifetimes and -fextend-this-ptr to aid with debugging of optimized code

2017-12-11 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a project: debug-info.
vsk added a comment.

Thanks for your patches @wolfgangp! I agree with Eli that we should evaluate 
enabling this automatically with -Og. I'll test this out on a few internal 
projects and report back.


https://reviews.llvm.org/D41044



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


r320411 - PR35586: Relax two asserts that are overly restrictive

2017-12-11 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Mon Dec 11 11:44:28 2017
New Revision: 320411

URL: http://llvm.org/viewvc/llvm-project?rev=320411=rev
Log:
PR35586: Relax two asserts that are overly restrictive

The two asserts are too aggressive.  In C++  mode, an
enum is NOT considered an integral type, but an enum value
is allowed to be an enum.  This patch relaxes the two asserts
to allow the enum value as well (as typechecking does).

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/enum-scoped.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=320411=320410=320411=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Dec 11 11:44:28 2017
@@ -15217,7 +15217,8 @@ void Sema::ActOnFields(Scope *S, SourceL
 static bool isRepresentableIntegerValue(ASTContext ,
 llvm::APSInt ,
 QualType T) {
-  assert(T->isIntegralType(Context) && "Integral type required!");
+  assert((T->isIntegralType(Context) || T->isEnumeralType()) &&
+ "Integral type required!");
   unsigned BitWidth = Context.getIntWidth(T);
 
   if (Value.isUnsigned() || Value.isNonNegative()) {
@@ -15233,7 +15234,8 @@ static bool isRepresentableIntegerValue(
 static QualType getNextLargerIntegralType(ASTContext , QualType T) {
   // FIXME: Int128/UInt128 support, which also needs to be introduced into
   // enum checking below.
-  assert(T->isIntegralType(Context) && "Integral type required!");
+  assert((T->isIntegralType(Context) ||
+ T->isEnumeralType()) && "Integral type required!");
   const unsigned NumTypes = 4;
   QualType SignedIntegralTypes[NumTypes] = {
 Context.ShortTy, Context.IntTy, Context.LongTy, Context.LongLongTy

Modified: cfe/trunk/test/SemaCXX/enum-scoped.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum-scoped.cpp?rev=320411=320410=320411=diff
==
--- cfe/trunk/test/SemaCXX/enum-scoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum-scoped.cpp Mon Dec 11 11:44:28 2017
@@ -309,3 +309,8 @@ namespace test11 {
 
   bool f() { return !f1(); } // expected-error {{invalid argument type 
'test11::E2' (aka 'test11::E') to unary expression}}
 }
+
+namespace PR35586 {
+  enum C { R, G, B };
+  enum B { F = (enum C) -1, T}; // this should compile cleanly, it used to 
assert.
+};


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


[PATCH] D41048: [libcxx] workaround PR 28385 in __find_exactly_one_checked

2017-12-11 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter marked 2 inline comments as done.
CaseyCarter added a comment.

This unconditional workaround addresses Marshall's concerns about the naked 
version test.


https://reviews.llvm.org/D41048



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


[PATCH] D41073: Wasm: add support in libcxx

2017-12-11 Thread Dan Gohman via Phabricator via cfe-commits
sunfish accepted this revision.
sunfish added a comment.
This revision is now accepted and ready to land.

Yes, wasm has its own object format, so this change makes sense.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41073



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


r320410 - [Hexagon] Remove unsupported vlut intrinsics

2017-12-11 Thread Krzysztof Parzyszek via cfe-commits
Author: kparzysz
Date: Mon Dec 11 11:29:56 2017
New Revision: 320410

URL: http://llvm.org/viewvc/llvm-project?rev=320410=rev
Log:
[Hexagon] Remove unsupported vlut intrinsics

Modified:
cfe/trunk/test/CodeGen/builtins-hexagon.c

Modified: cfe/trunk/test/CodeGen/builtins-hexagon.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-hexagon.c?rev=320410=320409=320410=diff
==
--- cfe/trunk/test/CodeGen/builtins-hexagon.c (original)
+++ cfe/trunk/test/CodeGen/builtins-hexagon.c Mon Dec 11 11:29:56 2017
@@ -2346,22 +2346,6 @@ void foo() {
   // CHECK: @llvm.hexagon.V6.vlsrw
   __builtin_HEXAGON_V6_vlsrwv(v16, v16);
   // CHECK: @llvm.hexagon.V6.vlsrwv
-  __builtin_HEXAGON_V6_vlutb_128B(v32, 0, 0);
-  // CHECK: @llvm.hexagon.V6.vlutb.128B
-  __builtin_HEXAGON_V6_vlutb_acc_128B(v32, v32, 0, 0);
-  // CHECK: @llvm.hexagon.V6.vlutb.acc.128B
-  __builtin_HEXAGON_V6_vlutb_acc(v16, v16, 0, 0);
-  // CHECK: @llvm.hexagon.V6.vlutb.acc
-  __builtin_HEXAGON_V6_vlutb_dv_128B(v64, 0, 0);
-  // CHECK: @llvm.hexagon.V6.vlutb.dv.128B
-  __builtin_HEXAGON_V6_vlutb_dv_acc_128B(v64, v64, 0, 0);
-  // CHECK: @llvm.hexagon.V6.vlutb.dv.acc.128B
-  __builtin_HEXAGON_V6_vlutb_dv_acc(v32, v32, 0, 0);
-  // CHECK: @llvm.hexagon.V6.vlutb.dv.acc
-  __builtin_HEXAGON_V6_vlutb_dv(v32, 0, 0);
-  // CHECK: @llvm.hexagon.V6.vlutb.dv
-  __builtin_HEXAGON_V6_vlutb(v16, 0, 0);
-  // CHECK: @llvm.hexagon.V6.vlutb
   __builtin_HEXAGON_V6_vlutvvb_128B(v32, v32, 0);
   // CHECK: @llvm.hexagon.V6.vlutvvb.128B
   __builtin_HEXAGON_V6_vlutvvb_oracc_128B(v32, v32, v32, 0);


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


[PATCH] D41080: Don't trigger -Wuser-defined-literals for system headers

2017-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

This is missing a test case.


Repository:
  rC Clang

https://reviews.llvm.org/D41080



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


[PATCH] D40991: [libcxx] [test] Fix line endings, avoid unnecessary non-ASCII.

2017-12-11 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added a comment.

LGTM as-is with the changes to the TODO file...


https://reviews.llvm.org/D40991



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


[PATCH] D40991: [libcxx] [test] Fix line endings, avoid unnecessary non-ASCII.

2017-12-11 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT added a comment.

Would you like me to drop the changes to TODO.TXT?


https://reviews.llvm.org/D40991



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


[PATCH] D41064: Suppress -Wuser-defined-literals for and

2017-12-11 Thread Dimitry Andric via Phabricator via cfe-commits
dim abandoned this revision.
dim added a comment.

Abandoned in favor of https://reviews.llvm.org/D41080.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41064



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


[PATCH] D41080: Don't trigger -Wuser-defined-literals for system headers

2017-12-11 Thread Dimitry Andric via Phabricator via cfe-commits
dim created this revision.

In https://reviews.llvm.org/D41064, I proposed adding `#pragma clang diagnostic 
ignored
"-Wuser-defined-literals"` to some of libc++'s headers, since these
warnings are now triggered by clang's new `-std=gnu++14` default:

  $ cat test.cpp
  #include 
  
  $ clang -std=c++14 -Wsystem-headers -Wall -Wextra -c test.cpp
  In file included from test.cpp:1:
  In file included from /usr/include/c++/v1/string:470:
  /usr/include/c++/v1/string_view:763:29: warning: user-defined literal 
suffixes not starting with '_' are reserved [-Wuser-defined-literals]
  basic_string_view operator "" sv(const char *__str, size_t __len)
  ^
  /usr/include/c++/v1/string_view:769:32: warning: user-defined literal 
suffixes not starting with '_' are reserved [-Wuser-defined-literals]
  basic_string_view operator "" sv(const wchar_t *__str, size_t 
__len)
 ^
  /usr/include/c++/v1/string_view:775:33: warning: user-defined literal 
suffixes not starting with '_' are reserved [-Wuser-defined-literals]
  basic_string_view operator "" sv(const char16_t *__str, size_t 
__len)
  ^
  /usr/include/c++/v1/string_view:781:33: warning: user-defined literal 
suffixes not starting with '_' are reserved [-Wuser-defined-literals]
  basic_string_view operator "" sv(const char32_t *__str, size_t 
__len)
  ^
  In file included from test.cpp:1:
  /usr/include/c++/v1/string:4012:24: warning: user-defined literal suffixes 
not starting with '_' are reserved [-Wuser-defined-literals]
  basic_string operator "" s( const char *__str, size_t __len )
 ^
  /usr/include/c++/v1/string:4018:27: warning: user-defined literal suffixes 
not starting with '_' are reserved [-Wuser-defined-literals]
  basic_string operator "" s( const wchar_t *__str, size_t __len )
^
  /usr/include/c++/v1/string:4024:28: warning: user-defined literal suffixes 
not starting with '_' are reserved [-Wuser-defined-literals]
  basic_string operator "" s( const char16_t *__str, size_t __len 
)
 ^
  /usr/include/c++/v1/string:4030:28: warning: user-defined literal suffixes 
not starting with '_' are reserved [-Wuser-defined-literals]
  basic_string operator "" s( const char32_t *__str, size_t __len 
)
 ^
  8 warnings generated.

Both @aaron.ballman and @mclow.lists felt that adding this workaround to
the libc++ headers was the wrong way, and it should be fixed in clang
instead.

Here is a proposal to do just that.  I verified that this suppresses the
warning, even when -Wsystem-headers is used, and that the warning is
still emitted for a declaration outside of system headers.


Repository:
  rC Clang

https://reviews.llvm.org/D41080

Files:
  lib/Sema/SemaDeclCXX.cpp


Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -13076,7 +13076,8 @@
 
   StringRef LiteralName
 = FnDecl->getDeclName().getCXXLiteralIdentifier()->getName();
-  if (LiteralName[0] != '_') {
+  if (LiteralName[0] != '_' &&
+  !getSourceManager().isInSystemHeader(FnDecl->getLocation())) {
 // C++11 [usrlit.suffix]p1:
 //   Literal suffix identifiers that do not start with an underscore
 //   are reserved for future standardization.


Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -13076,7 +13076,8 @@
 
   StringRef LiteralName
 = FnDecl->getDeclName().getCXXLiteralIdentifier()->getName();
-  if (LiteralName[0] != '_') {
+  if (LiteralName[0] != '_' &&
+  !getSourceManager().isInSystemHeader(FnDecl->getLocation())) {
 // C++11 [usrlit.suffix]p1:
 //   Literal suffix identifiers that do not start with an underscore
 //   are reserved for future standardization.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39363: [clang-tidy] Correctly classify constant arrays and constant strings as constants when checking identifiers naming

2017-12-11 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320406: [clang-tidy] Correctly classify constant arrays and 
constant strings as… (authored by alexfh).

Repository:
  rL LLVM

https://reviews.llvm.org/D39363

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

Index: clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp
@@ -405,6 +405,38 @@
 
   using ::FOO_NS::InlineNamespace::CE_function;
 // CHECK-FIXES: {{^}}  using ::foo_ns::inline_namespace::ce_function;{{$}}
+
+  unsigned MY_LOCAL_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for local variable 'MY_LOCAL_array'
+// CHECK-FIXES: {{^}}  unsigned my_local_array[] = {1,2,3};{{$}}
+
+  unsigned const MyConstLocal_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for local constant 'MyConstLocal_array'
+// CHECK-FIXES: {{^}}  unsigned const kMyConstLocalArray[] = {1,2,3};{{$}}
+
+  static unsigned MY_STATIC_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for static variable 'MY_STATIC_array'
+// CHECK-FIXES: {{^}}  static unsigned s_myStaticArray[] = {1,2,3};{{$}}
+
+  static unsigned const MyConstStatic_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: invalid case style for static constant 'MyConstStatic_array'
+// CHECK-FIXES: {{^}}  static unsigned const MY_CONST_STATIC_ARRAY[] = {1,2,3};{{$}}
+
+  char MY_LOCAL_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local variable 'MY_LOCAL_string'
+// CHECK-FIXES: {{^}}  char my_local_string[] = "123";{{$}}
+
+  char const MyConstLocal_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant 'MyConstLocal_string'
+// CHECK-FIXES: {{^}}  char const kMyConstLocalString[] = "123";{{$}}
+
+  static char MY_STATIC_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for static variable 'MY_STATIC_string'
+// CHECK-FIXES: {{^}}  static char s_myStaticString[] = "123";{{$}}
+
+  static char const MyConstStatic_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for static constant 'MyConstStatic_string'
+// CHECK-FIXES: {{^}}  static char const MY_CONST_STATIC_STRING[] = "123";{{$}}
 }
 
 #define MY_TEST_Macro(X) X()
@@ -418,6 +450,27 @@
 
 template  struct a {
   typename t_t::template b<> c;
+
+  char const MY_ConstMember_string[4] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'MY_ConstMember_string'
+// CHECK-FIXES: {{^}}  char const my_const_member_string[4] = "123";{{$}}
+
+  static char const MyConstClass_string[];
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: invalid case style for class constant 'MyConstClass_string'
+// CHECK-FIXES: {{^}}  static char const kMyConstClassString[];{{$}}
 };
 
+template
+char const a::MyConstClass_string[] = "123";
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for class constant 'MyConstClass_string'
+// CHECK-FIXES: {{^}}char const a::kMyConstClassString[] = "123";{{$}}
+
 template  class A> struct b { A c; };
+
+unsigned MY_GLOBAL_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'MY_GLOBAL_array'
+// CHECK-FIXES: {{^}}unsigned g_my_global_array[] = {1,2,3};{{$}}
+
+unsigned const MyConstGlobal_array[] = {1,2,3};
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global constant 'MyConstGlobal_array'
+// CHECK-FIXES: {{^}}unsigned const MY_CONST_GLOBAL_ARRAY[] = {1,2,3};{{$}}
Index: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -449,13 +449,13 @@
   if (const auto *Decl = dyn_cast(D)) {
 QualType Type = Decl->getType();
 
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-NamingStyles[SK_ConstantMember])
-  return SK_ConstantMember;
+if (!Type.isNull() && Type.isConstQualified()) {
+  if (NamingStyles[SK_ConstantMember])
+return SK_ConstantMember;
 
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-NamingStyles[SK_Constant])
-  return SK_Constant;
+  if (NamingStyles[SK_Constant])
+return SK_Constant;
+}
 
 if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMember])
   return SK_PrivateMember;
@@ -478,13 +478,13 @@
 if 

[clang-tools-extra] r320406 - [clang-tidy] Correctly classify constant arrays and constant strings as constants when checking identifiers naming

2017-12-11 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon Dec 11 11:02:26 2017
New Revision: 320406

URL: http://llvm.org/viewvc/llvm-project?rev=320406=rev
Log:
[clang-tidy] Correctly classify constant arrays and constant strings as 
constants when checking identifiers naming

Summary:
They are not locally const qualified so they weren't classified as
constants by the readability-identifier-naming check.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: klimek, cfe-commits, xazax.hun

Patch by Beren Minor!

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

Modified:
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=320406=320405=320406=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
Mon Dec 11 11:02:26 2017
@@ -449,13 +449,13 @@ static StyleKind findStyleKind(
   if (const auto *Decl = dyn_cast(D)) {
 QualType Type = Decl->getType();
 
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-NamingStyles[SK_ConstantMember])
-  return SK_ConstantMember;
-
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-NamingStyles[SK_Constant])
-  return SK_Constant;
+if (!Type.isNull() && Type.isConstQualified()) {
+  if (NamingStyles[SK_ConstantMember])
+return SK_ConstantMember;
+
+  if (NamingStyles[SK_Constant])
+return SK_Constant;
+}
 
 if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMember])
   return SK_PrivateMember;
@@ -478,13 +478,13 @@ static StyleKind findStyleKind(
 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
   return SK_ConstexprVariable;
 
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-NamingStyles[SK_ConstantParameter])
-  return SK_ConstantParameter;
-
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-NamingStyles[SK_Constant])
-  return SK_Constant;
+if (!Type.isNull() && Type.isConstQualified()) {
+  if (NamingStyles[SK_ConstantParameter])
+return SK_ConstantParameter;
+
+  if (NamingStyles[SK_Constant])
+return SK_Constant;
+}
 
 if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack])
   return SK_ParameterPack;
@@ -501,29 +501,25 @@ static StyleKind findStyleKind(
 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
   return SK_ConstexprVariable;
 
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant])
-  return SK_ClassConstant;
-
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant])
-  return SK_GlobalConstant;
-
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-Decl->isStaticLocal() && NamingStyles[SK_StaticConstant])
-  return SK_StaticConstant;
-
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant])
-  return SK_LocalConstant;
-
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalConstant])
-  return SK_LocalConstant;
-
-if (!Type.isNull() && Type.isLocalConstQualified() &&
-NamingStyles[SK_Constant])
-  return SK_Constant;
+if (!Type.isNull() && Type.isConstQualified()) {
+  if (Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant])
+return SK_ClassConstant;
+
+  if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant])
+return SK_GlobalConstant;
+
+  if (Decl->isStaticLocal() && NamingStyles[SK_StaticConstant])
+return SK_StaticConstant;
+
+  if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant])
+return SK_LocalConstant;
+
+  if (Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalConstant])
+return SK_LocalConstant;
+
+  if (NamingStyles[SK_Constant])
+return SK_Constant;
+}
 
 if (Decl->isStaticDataMember() && NamingStyles[SK_ClassMember])
   return SK_ClassMember;
@@ -681,8 +677,9 @@ static void addUsage(IdentifierNamingChe
 static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap ,
  const NamedDecl *Decl, SourceRange Range,
  SourceManager *SourceMgr = nullptr) {
-  return addUsage(Failures, IdentifierNamingCheck::NamingCheckId(
-Decl->getLocation(), Decl->getNameAsString()),
+  return addUsage(Failures,
+  

[PATCH] D41048: [libcxx] workaround PR 28385 in __find_exactly_one_checked

2017-12-11 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter updated this revision to Diff 126406.
CaseyCarter added a comment.

Make the workaround unconditional.


https://reviews.llvm.org/D41048

Files:
  include/tuple


Index: include/tuple
===
--- include/tuple
+++ include/tuple
@@ -1012,10 +1012,15 @@
 
 template 
 struct __find_exactly_one_checked {
-  static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
-static constexpr size_t value = __find_detail::__find_idx(0, __matches);
-static_assert (value != __not_found, "type not found in type list" );
-static_assert(value != __ambiguous,"type occurs more than once in type 
list");
+inline _LIBCPP_INLINE_VISIBILITY
+static constexpr size_t __index()
+{
+constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
+return __find_detail::__find_idx(0, __matches);
+}
+static constexpr size_t value = __index();
+static_assert(value != __not_found, "type not found in type list" );
+static_assert(value != __ambiguous, "type occurs more than once in type 
list");
 };
 
 template 


Index: include/tuple
===
--- include/tuple
+++ include/tuple
@@ -1012,10 +1012,15 @@
 
 template 
 struct __find_exactly_one_checked {
-  static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
-static constexpr size_t value = __find_detail::__find_idx(0, __matches);
-static_assert (value != __not_found, "type not found in type list" );
-static_assert(value != __ambiguous,"type occurs more than once in type list");
+inline _LIBCPP_INLINE_VISIBILITY
+static constexpr size_t __index()
+{
+constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
+return __find_detail::__find_idx(0, __matches);
+}
+static constexpr size_t value = __index();
+static_assert(value != __not_found, "type not found in type list" );
+static_assert(value != __ambiguous, "type occurs more than once in type list");
 };
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r319875 - Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in C++.

2017-12-11 Thread Hans Wennborg via cfe-commits
I've committed a fix to pacify the test in r320405.

On Wed, Dec 6, 2017 at 12:27 PM, Galina Kistanova via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hello Richard,
>
> This commit broke the tests on the builder:
>
> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-
> expensive-checks-win/builds/6598
>
> . . .
> Failing Tests (1):
> Clang :: SemaCXX/warn-enum-compare.cpp
>
> Please have a look?
>
> Thanks
>
> Galina
>
> On Tue, Dec 5, 2017 at 7:00 PM, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: rsmith
>> Date: Tue Dec  5 19:00:51 2017
>> New Revision: 319875
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=319875=rev
>> Log:
>> Fix a bunch of wrong "tautological unsigned enum compare" diagnostics in
>> C++.
>>
>> An enumeration with a fixed underlying type can have any value in its
>> underlying type, not just those spanned by the values of its enumerators.
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaChecking.cpp
>> cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaC
>> hecking.cpp?rev=319875=319874=319875=diff
>> 
>> ==
>> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec  5 19:00:51 2017
>> @@ -8260,11 +8260,12 @@ struct IntRange {
>>  } else if (const EnumType *ET = dyn_cast(T)) {
>>// For enum types in C++, use the known bit width of the
>> enumerators.
>>EnumDecl *Enum = ET->getDecl();
>> -  // In C++11, enums without definitions can have an explicitly
>> specified
>> -  // underlying type.  Use this type to compute the range.
>> -  if (!Enum->isCompleteDefinition())
>> +  // In C++11, enums can have a fixed underlying type. Use this type
>> to
>> +  // compute the range.
>> +  if (Enum->isFixed()) {
>>  return IntRange(C.getIntWidth(QualType(T, 0)),
>>  !ET->isSignedIntegerOrEnumerationType());
>> +  }
>>
>>unsigned NumPositive = Enum->getNumPositiveBits();
>>unsigned NumNegative = Enum->getNumNegativeBits();
>>
>> Modified: cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/taut
>> ological-unsigned-enum-zero-compare.cpp?rev=319875=
>> 319874=319875=diff
>> 
>> ==
>> --- cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
>> (original)
>> +++ cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp Tue
>> Dec  5 19:00:51 2017
>> @@ -2,11 +2,11 @@
>>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only
>> -DSIGNED -verify %s
>>  // RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only
>> -DSILENCE -Wno-tautological-unsigned-enum-zero-compare -verify %s
>>
>> -// Okay, this is where it gets complicated.
>> -// Then default enum sigdness is target-specific.
>> -// On windows, it is signed by default. We do not want to warn in that
>> case.
>> -
>>  int main() {
>> +  // On Windows, all enumerations have a fixed underlying type, which is
>> 'int'
>> +  // if not otherwise specified, so A is identical to C on Windows.
>> Otherwise,
>> +  // we follow the C++ rules, which say that the only valid values of A
>> are 0
>> +  // and 1.
>>enum A { A_foo = 0, A_bar, };
>>enum A a;
>>
>> @@ -87,21 +87,23 @@ int main() {
>>
>>if (c < 0)
>>  return 0;
>> -  if (0 >= c) // expected-warning {{comparison 0 >= 'enum C' is always
>> true}}
>> +  if (0 >= c)
>>  return 0;
>> -  if (c > 0) // expected-warning {{comparison 'enum C' > 0 is always
>> false}}
>> +  if (c > 0)
>>  return 0;
>>if (0 <= c)
>>  return 0;
>> -  if (c <= 0) // expected-warning {{comparison 'enum C' <= 0 is always
>> true}}
>> +  if (c <= 0)
>>  return 0;
>>if (0 > c)
>>  return 0;
>>if (c >= 0)
>>  return 0;
>> -  if (0 < c) // expected-warning {{0 < 'enum C' is always false}}
>> +  if (0 < c)
>>  return 0;
>>
>> +  // FIXME: These diagnostics are terrible. The issue here is that the
>> signed
>> +  // enumeration value was promoted to an unsigned type.
>>if (c < 0U) // expected-warning {{comparison of unsigned enum
>> expression < 0 is always false}}
>>  return 0;
>>if (0U >= c)
>> @@ -121,21 +123,23 @@ int main() {
>>  #elif defined(SIGNED)
>>if (a < 0)
>>  return 0;
>> -  if (0 >= a) // expected-warning {{comparison 0 >= 'enum A' is always
>> true}}
>> +  if (0 >= a)
>>  return 0;
>> -  if (a > 0) // expected-warning {{comparison 'enum A' > 0 is always
>> false}}
>> +  if (a > 0)
>>  return 0;
>>if (0 <= a)
>>  return 0;
>> -  if (a <= 0) // expected-warning {{comparison 'enum A' <= 0 is always
>> true}}
>> +  if (a <= 0)
>>  return 0;
>>

r320405 - Fix warn-enum-compare.cpp on Windows

2017-12-11 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Mon Dec 11 10:58:18 2017
New Revision: 320405

URL: http://llvm.org/viewvc/llvm-project?rev=320405=rev
Log:
Fix warn-enum-compare.cpp on Windows

It's been failing since r319875.

Modified:
cfe/trunk/test/SemaCXX/warn-enum-compare.cpp

Modified: cfe/trunk/test/SemaCXX/warn-enum-compare.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-enum-compare.cpp?rev=320405=320404=320405=diff
==
--- cfe/trunk/test/SemaCXX/warn-enum-compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-enum-compare.cpp Mon Dec 11 10:58:18 2017
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -verify -triple %itanium_abi_triple
+// RUN: %clang_cc1 %s -fsyntax-only -verify -triple %ms_abi_triple -DMSABI
 
 enum Foo { FooA, FooB, FooC };
 enum Bar { BarD, BarE, BarF };
@@ -42,8 +43,10 @@ void test () {
   while (b == c);
   while (B1 == name1::B2);
   while (B2 == name2::B1);
+#ifndef MSABI
   while (x == AnonAA); // expected-warning {{comparison of constant 'AnonAA' 
(42) with expression of type 'Foo' is always false}}
   while (AnonBB == y); // expected-warning {{comparison of constant 'AnonBB' 
(45) with expression of type 'Bar' is always false}}
+#endif
   while (AnonAA == AnonAB);
   while (AnonAB == AnonBA);
   while (AnonBB == AnonAA);
@@ -69,7 +72,9 @@ void test () {
   while (B2 == ((name2::B1)));
 
   while (td == Anon1);
+#ifndef MSABI
   while (td == AnonAA);  // expected-warning {{comparison of constant 'AnonAA' 
(42) with expression of type 'TD' is always false}}
+#endif
 
   while (B1 == B2); // expected-warning  {{comparison of two values with 
different enumeration types ('name1::Baz' and 'name2::Baz')}}
   while (name1::B2 == name2::B3); // expected-warning  {{comparison of two 
values with different enumeration types ('name1::Baz' and 'name2::Baz')}}


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


[PATCH] D39963: [RISCV] Add initial RISC-V target and driver support

2017-12-11 Thread Alex Bradbury via Phabricator via cfe-commits
asb updated this revision to Diff 126404.
asb marked 3 inline comments as done.
asb retitled this revision from "[RISCV][RFC] Add initial RISC-V target and 
driver support" to "[RISCV] Add initial RISC-V target and driver support".
asb edited the summary of this revision.
asb added a comment.
Herald added a subscriber: sabuasal.

Patch updates:

- Address review comments
- (u)int64_type is `long int` on RV64 rather than `long long int`
- Remove driver for bare metal RV32 target (to be posted in a subsequent patch 
and maybe discussed on cfe-dev).

>From my perspective, the only deficiency in this patch is now the tests (which 
>I'll add to this review ASAP). Let me know if you see other remaining problems.


https://reviews.llvm.org/D39963

Files:
  lib/Basic/CMakeLists.txt
  lib/Basic/Targets.cpp
  lib/Basic/Targets/RISCV.cpp
  lib/Basic/Targets/RISCV.h
  lib/Driver/CMakeLists.txt
  lib/Driver/ToolChains/Arch/RISCV.cpp
  lib/Driver/ToolChains/Arch/RISCV.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/Clang.h
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Linux.cpp
  test/Driver/frame-pointer.c
  test/Driver/riscv-abi.c
  test/Driver/riscv-features.c
  test/Driver/riscv32-toolchain.c
  test/Driver/riscv64-toolchain.c
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -10003,3 +10003,398 @@
 // ARM-DARWIN-BAREMETAL-64: #define __PTRDIFF_TYPE__ long int
 // ARM-DARWIN-BAREMETAL-64: #define __SIZE_TYPE__ long unsigned int
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=riscv32 < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix=RISCV32 %s
+// RISCV32: #define _ILP32 1
+// RISCV32: #define __ATOMIC_ACQUIRE 2
+// RISCV32: #define __ATOMIC_ACQ_REL 4
+// RISCV32: #define __ATOMIC_CONSUME 1
+// RISCV32: #define __ATOMIC_RELAXED 0
+// RISCV32: #define __ATOMIC_RELEASE 3
+// RISCV32: #define __ATOMIC_SEQ_CST 5
+// RISCV32: #define __BIGGEST_ALIGNMENT__ 16
+// RISCV32: #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+// RISCV32: #define __CHAR16_TYPE__ unsigned short
+// RISCV32: #define __CHAR32_TYPE__ unsigned int
+// RISCV32: #define __CHAR_BIT__ 8
+// RISCV32: #define __DBL_DECIMAL_DIG__ 17
+// RISCV32: #define __DBL_DENORM_MIN__ 4.9406564584124654e-324
+// RISCV32: #define __DBL_DIG__ 15
+// RISCV32: #define __DBL_EPSILON__ 2.2204460492503131e-16
+// RISCV32: #define __DBL_HAS_DENORM__ 1
+// RISCV32: #define __DBL_HAS_INFINITY__ 1
+// RISCV32: #define __DBL_HAS_QUIET_NAN__ 1
+// RISCV32: #define __DBL_MANT_DIG__ 53
+// RISCV32: #define __DBL_MAX_10_EXP__ 308
+// RISCV32: #define __DBL_MAX_EXP__ 1024
+// RISCV32: #define __DBL_MAX__ 1.7976931348623157e+308
+// RISCV32: #define __DBL_MIN_10_EXP__ (-307)
+// RISCV32: #define __DBL_MIN_EXP__ (-1021)
+// RISCV32: #define __DBL_MIN__ 2.2250738585072014e-308
+// RISCV32: #define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
+// RISCV32: #define __ELF__ 1
+// RISCV32: #define __FINITE_MATH_ONLY__ 0
+// RISCV32: #define __FLT_DECIMAL_DIG__ 9
+// RISCV32: #define __FLT_DENORM_MIN__ 1.40129846e-45F
+// RISCV32: #define __FLT_DIG__ 6
+// RISCV32: #define __FLT_EPSILON__ 1.19209290e-7F
+// RISCV32: #define __FLT_EVAL_METHOD__ 0
+// RISCV32: #define __FLT_HAS_DENORM__ 1
+// RISCV32: #define __FLT_HAS_INFINITY__ 1
+// RISCV32: #define __FLT_HAS_QUIET_NAN__ 1
+// RISCV32: #define __FLT_MANT_DIG__ 24
+// RISCV32: #define __FLT_MAX_10_EXP__ 38
+// RISCV32: #define __FLT_MAX_EXP__ 128
+// RISCV32: #define __FLT_MAX__ 3.40282347e+38F
+// RISCV32: #define __FLT_MIN_10_EXP__ (-37)
+// RISCV32: #define __FLT_MIN_EXP__ (-125)
+// RISCV32: #define __FLT_MIN__ 1.17549435e-38F
+// RISCV32: #define __FLT_RADIX__ 2
+// RISCV32: #define __GCC_ATOMIC_BOOL_LOCK_FREE 1
+// RISCV32: #define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 1
+// RISCV32: #define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 1
+// RISCV32: #define __GCC_ATOMIC_CHAR_LOCK_FREE 1
+// RISCV32: #define __GCC_ATOMIC_INT_LOCK_FREE 1
+// RISCV32: #define __GCC_ATOMIC_LLONG_LOCK_FREE 1
+// RISCV32: #define __GCC_ATOMIC_LONG_LOCK_FREE 1
+// RISCV32: #define __GCC_ATOMIC_POINTER_LOCK_FREE 1
+// RISCV32: #define __GCC_ATOMIC_SHORT_LOCK_FREE 1
+// RISCV32: #define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
+// RISCV32: #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 1
+// RISCV32: #define __GNUC_MINOR__ {{.*}}
+// RISCV32: #define __GNUC_PATCHLEVEL__ {{.*}}
+// RISCV32: #define __GNUC_STDC_INLINE__ 1
+// RISCV32: #define __GNUC__ {{.*}}
+// RISCV32: #define __GXX_ABI_VERSION {{.*}}
+// RISCV32: #define __ILP32__ 1
+// RISCV32: #define __INT16_C_SUFFIX__
+// RISCV32: #define __INT16_MAX__ 32767
+// RISCV32: #define __INT16_TYPE__ short
+// RISCV32: #define __INT32_C_SUFFIX__
+// RISCV32: #define __INT32_MAX__ 2147483647
+// RISCV32: #define __INT32_TYPE__ int
+// RISCV32: #define __INT64_C_SUFFIX__ LL
+// RISCV32: #define __INT64_MAX__ 9223372036854775807LL
+// RISCV32: #define __INT64_TYPE__ long long int

[PATCH] D41077: [analyser] different.CallArgsOrder checker implementation

2017-12-11 Thread Alexey Knyshev via Phabricator via cfe-commits
alexey.knyshev created this revision.
alexey.knyshev added a project: clang.
Herald added a subscriber: mgorny.

CallArgsOrderChecker which looks for accidental swap or skip of arguments in 
function, methods, constructors and operators calls


Repository:
  rC Clang

https://reviews.llvm.org/D41077

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/CallArgsOrderChecker.cpp
  test/Analysis/call-args-order.c
  test/Analysis/call-args-order.cpp

Index: test/Analysis/call-args-order.cpp
===
--- test/Analysis/call-args-order.cpp
+++ test/Analysis/call-args-order.cpp
@@ -0,0 +1,103 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.CallArgsOrder -verify -x c++ %s
+
+typedef unsigned char byte;
+
+class Color {
+  byte r, g, b, a;
+
+public:
+  Color(byte R, byte G, byte B, byte A = 0)
+  : r(R), g(G), b(B), a(A) {}
+
+  void set(byte R, byte G, byte B, byte A = 0) {
+r = R;
+g = G;
+b = B;
+a = A;
+  }
+
+  void operator()(byte R, byte G, byte B, byte A = 0);
+  void operator+=(byte Delta);
+
+  byte getR() const { return r; }
+  byte getG() const { return g; }
+  byte getB() const { return b; }
+  byte getA() const { return a; }
+
+  static Color copy1(const Color );
+  static Color copy2(const Color );
+  static Color copy3(const Color );
+  static Color copy4(const Color );
+  static Color copy5(const Color );
+  static Color copy6(const Color );
+};
+
+void Color::operator()(byte R, byte G, byte B, byte A) {
+  set(R, B, G, A); // expected-warning {{possibly wrong order of args 'B' and 'G' passed as params 'G' and 'B'}}
+}
+
+void Color::operator+=(byte Delta) {
+  r += Delta;
+  g += Delta;
+  b += Delta;
+  a += Delta;
+}
+
+Color newRed1(byte r, byte b, byte a) {
+  return Color(r, b, a); // expected-warning {{possibly missing arg for param 'G'}}
+}
+
+Color newRed2(byte r, byte g, byte a) {
+  return Color(r, g, a); // expected-warning {{possibly missing arg for param 'B'}}
+}
+
+Color Color::copy1(const Color ) {
+  return Color(o.r, o.b, o.g, o.a); // expected-warning {{possibly wrong order of args 'o.b' and 'o.g' passed as params 'G' and 'B'}}
+}
+
+Color Color::copy2(const Color ) {
+  return Color(o.r, o.g, o.a, o.b); // expected-warning {{possibly wrong order of args 'o.a' and 'o.b' passed as params 'B' and 'A'}}
+}
+
+Color Color::copy3(const Color ) {
+  return Color(o.r, o.g, o.g, o.g); // no-warning
+}
+
+Color Color::copy4(const Color ) {
+  return Color(o.r, o.r, o.r, o.r); // no-warning
+}
+
+Color Color::copy5(const Color ) {
+  return Color(o.getR(), o.getB(), o.getG(), o.getA()); // expected-warning {{possibly wrong order of args 'o.getB()' and 'o.getG()' passed as params 'G' and 'B'}}
+}
+
+Color Color::copy6(const Color ) {
+  // totaly messed up (not sure if it's wrong or not)
+  return Color(o.a, o.r, o.g, o.b); // no-warning
+}
+
+Color newMagicColor() {
+  const byte r = 200;
+  const byte g = 150;
+  const byte b = 100;
+  const byte a = 0;
+
+  return Color(r, b, g, a); // expected-warning {{possibly wrong order of args 'b' and 'g' passed as params 'G' and 'B'}}
+}
+
+void modify(Color ) {
+  int red = 1;
+  int green = 2;
+  int blue = 3;
+  c.set(red, green, blue); // no-warning
+  c.set(red, blue, green); // expected-warning {{possibly wrong order of args 'blue' and 'green' passed as params 'G' and 'B'}}
+  c.set(red, green, 0);// no-warning
+  c.set(red, green, c.getA()); // no-warning
+
+  c(red, green, blue); // no-warning
+  c(green, red, blue); // expected-warning {{possibly wrong order of args 'green' and 'red' passed as params 'R' and 'G'}}
+
+  c += 1; // no-warning
+
+  c(red, blue, green, 0); // expected-warning {{possibly wrong order of args 'blue' and 'green' passed as params 'G' and 'B'}}
+}
Index: test/Analysis/call-args-order.c
===
--- test/Analysis/call-args-order.c
+++ test/Analysis/call-args-order.c
@@ -0,0 +1,57 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.CallArgsOrder -verify -std=c99 %s
+
+struct Viewport {
+  int width;
+  int height;
+
+  float aspectRatio;
+};
+
+void setDimentions(struct Viewport *vp, int width, int height) {
+  vp->width = width;
+  vp->height = height;
+  vp->aspectRatio = width / height;
+}
+
+float getWidth(struct Viewport *vp) { return vp->width; }
+float getHeight(struct Viewport *vp) { return vp->height; }
+
+float getFloat() {
+  return 128.5;
+}
+
+int main() {
+  struct Viewport vp;
+
+  int newWidth = 800;
+  int newHeight = 600;
+  setDimentions(, newHeight, newWidth);// expected-warning {{possibly wrong order of args 'newHeight' and 'newWidth' passed as params 'width' and 'height'}}
+  setDimentions(, newWidth, newHeight);// no-warning
+  setDimentions(, newWidth, newWidth); // no-warning
+  setDimentions(, newHeight, newHeight);   

[PATCH] D40707: [libcxx] Fix basic_stringbuf constructor

2017-12-11 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

This looks good to me; with a couple of nits.




Comment at: 
test/std/input.output/string.streams/stringbuf/stringbuf.cons/default.pass.cpp:26
+{
+assert(this->eback() == 0);
+assert(this->gptr() == 0);

Not zero, please. `nullptr` or `NULL` .
`nullptr` would be better, but we can't assume c++11 here, so I guess it's 
`NULL`.


https://reviews.llvm.org/D40707



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


[PATCH] D41076: [driver][darwin] Set the 'simulator' environment when it's specified in '-target'

2017-12-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

This patch ensures that '-target' can be used to set the 'simulator' 
environment component in the target triple.


Repository:
  rC Clang

https://reviews.llvm.org/D41076

Files:
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c


Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -262,3 +262,13 @@
 // RUN: %clang -target uknown-apple-macos10.11.2 -arch=armv7k -c %s -### 2>&1 
| \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TIGNORE-ARCH1 %s
 // CHECK-VERSION-TIGNORE-ARCH1: "unknown-apple-macosx10.11.2"
+
+// Target can be used to specify the environment:
+
+// RUN: %clang -target x86_64-apple-ios11-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM1 %s
+// CHECK-VERSION-TENV-SIM1: "x86_64-apple-ios11.0.0-simulator"
+
+// RUN: %clang -target armv7k-apple-ios10.1-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM2 %s
+// CHECK-VERSION-TENV-SIM2: "thumbv7k-apple-ios10.1.0-simulator"
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1181,9 +1181,12 @@
   };
 
   using DarwinPlatformKind = Darwin::DarwinPlatformKind;
+  using DarwinEnvironmentKind = Darwin::DarwinEnvironmentKind;
 
   DarwinPlatformKind getPlatform() const { return Platform; }
 
+  DarwinEnvironmentKind getEnvironment() const { return Environment; }
+
   StringRef getOSVersion() const {
 if (Kind == OSVersionArg)
   return Argument->getValue();
@@ -1234,8 +1237,17 @@
   }
 
   static DarwinPlatform createFromTarget(llvm::Triple::OSType OS,
- StringRef OSVersion, Arg *A) {
-return DarwinPlatform(TargetArg, getPlatformFromOS(OS), OSVersion, A);
+ StringRef OSVersion, Arg *A,
+ llvm::Triple::EnvironmentType Env) {
+DarwinPlatform Result(TargetArg, getPlatformFromOS(OS), OSVersion, A);
+switch (Env) {
+case llvm::Triple::Simulator:
+  Result.Environment = DarwinEnvironmentKind::Simulator;
+  break;
+default:
+  break;
+}
+return Result;
   }
   static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
Arg *A) {
@@ -1282,6 +1294,7 @@
 
   SourceKind Kind;
   DarwinPlatformKind Platform;
+  DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
   std::string OSVersion;
   Arg *Argument;
   StringRef EnvVarName;
@@ -1478,7 +1491,8 @@
 return None;
   std::string OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
   return DarwinPlatform::createFromTarget(Triple.getOS(), OSVersion,
-  
Args.getLastArg(options::OPT_target));
+  Args.getLastArg(options::OPT_target),
+  Triple.getEnvironment());
 }
 
 } // namespace
@@ -1584,10 +1598,11 @@
   } else
 llvm_unreachable("unknown kind of Darwin platform");
 
-  DarwinEnvironmentKind Environment = NativeEnvironment;
+  DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
   // Recognize iOS targets with an x86 architecture as the iOS simulator.
-  if (Platform != MacOS && (getTriple().getArch() == llvm::Triple::x86 ||
-getTriple().getArch() == llvm::Triple::x86_64))
+  if (Environment == NativeEnvironment && Platform != MacOS &&
+  (getTriple().getArch() == llvm::Triple::x86 ||
+   getTriple().getArch() == llvm::Triple::x86_64))
 Environment = Simulator;
 
   setTarget(Platform, Environment, Major, Minor, Micro);


Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -262,3 +262,13 @@
 // RUN: %clang -target uknown-apple-macos10.11.2 -arch=armv7k -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TIGNORE-ARCH1 %s
 // CHECK-VERSION-TIGNORE-ARCH1: "unknown-apple-macosx10.11.2"
+
+// Target can be used to specify the environment:
+
+// RUN: %clang -target x86_64-apple-ios11-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM1 %s
+// CHECK-VERSION-TENV-SIM1: "x86_64-apple-ios11.0.0-simulator"
+
+// RUN: %clang -target armv7k-apple-ios10.1-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM2 %s
+// CHECK-VERSION-TENV-SIM2: "thumbv7k-apple-ios10.1.0-simulator"
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1181,9 +1181,12 @@
   };
 
   using 

[PATCH] D41075: [driver][darwin] Infer the 'simuluator

2017-12-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D41075

Files:
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c


Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -262,3 +262,13 @@
 // RUN: %clang -target uknown-apple-macos10.11.2 -arch=armv7k -c %s -### 2>&1 
| \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TIGNORE-ARCH1 %s
 // CHECK-VERSION-TIGNORE-ARCH1: "unknown-apple-macosx10.11.2"
+
+// Target can be used to specify the environment:
+
+// RUN: %clang -target x86_64-apple-ios11-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM1 %s
+// CHECK-VERSION-TENV-SIM1: "x86_64-apple-ios11.0.0-simulator"
+
+// RUN: %clang -target armv7k-apple-ios10.1-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM2 %s
+// CHECK-VERSION-TENV-SIM2: "thumbv7k-apple-ios10.1.0-simulator"
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1181,9 +1181,12 @@
   };
 
   using DarwinPlatformKind = Darwin::DarwinPlatformKind;
+  using DarwinEnvironmentKind = Darwin::DarwinEnvironmentKind;
 
   DarwinPlatformKind getPlatform() const { return Platform; }
 
+  DarwinEnvironmentKind getEnvironment() const { return Environment; }
+
   StringRef getOSVersion() const {
 if (Kind == OSVersionArg)
   return Argument->getValue();
@@ -1234,8 +1237,17 @@
   }
 
   static DarwinPlatform createFromTarget(llvm::Triple::OSType OS,
- StringRef OSVersion, Arg *A) {
-return DarwinPlatform(TargetArg, getPlatformFromOS(OS), OSVersion, A);
+ StringRef OSVersion, Arg *A,
+ llvm::Triple::EnvironmentType Env) {
+DarwinPlatform Result(TargetArg, getPlatformFromOS(OS), OSVersion, A);
+switch (Env) {
+case llvm::Triple::Simulator:
+  Result.Environment = DarwinEnvironmentKind::Simulator;
+  break;
+default:
+  break;
+}
+return Result;
   }
   static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
Arg *A) {
@@ -1282,6 +1294,7 @@
 
   SourceKind Kind;
   DarwinPlatformKind Platform;
+  DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
   std::string OSVersion;
   Arg *Argument;
   StringRef EnvVarName;
@@ -1478,7 +1491,8 @@
 return None;
   std::string OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
   return DarwinPlatform::createFromTarget(Triple.getOS(), OSVersion,
-  
Args.getLastArg(options::OPT_target));
+  Args.getLastArg(options::OPT_target),
+  Triple.getEnvironment());
 }
 
 } // namespace
@@ -1584,10 +1598,11 @@
   } else
 llvm_unreachable("unknown kind of Darwin platform");
 
-  DarwinEnvironmentKind Environment = NativeEnvironment;
+  DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
   // Recognize iOS targets with an x86 architecture as the iOS simulator.
-  if (Platform != MacOS && (getTriple().getArch() == llvm::Triple::x86 ||
-getTriple().getArch() == llvm::Triple::x86_64))
+  if (Environment == NativeEnvironment && Platform != MacOS &&
+  (getTriple().getArch() == llvm::Triple::x86 ||
+   getTriple().getArch() == llvm::Triple::x86_64))
 Environment = Simulator;
 
   setTarget(Platform, Environment, Major, Minor, Micro);


Index: test/Driver/darwin-version.c
===
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -262,3 +262,13 @@
 // RUN: %clang -target uknown-apple-macos10.11.2 -arch=armv7k -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TIGNORE-ARCH1 %s
 // CHECK-VERSION-TIGNORE-ARCH1: "unknown-apple-macosx10.11.2"
+
+// Target can be used to specify the environment:
+
+// RUN: %clang -target x86_64-apple-ios11-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM1 %s
+// CHECK-VERSION-TENV-SIM1: "x86_64-apple-ios11.0.0-simulator"
+
+// RUN: %clang -target armv7k-apple-ios10.1-simulator -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TENV-SIM2 %s
+// CHECK-VERSION-TENV-SIM2: "thumbv7k-apple-ios10.1.0-simulator"
Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1181,9 +1181,12 @@
   };
 
   using DarwinPlatformKind = Darwin::DarwinPlatformKind;
+  using DarwinEnvironmentKind = 

[PATCH] D41075: [driver][darwin] Infer the 'simuluator

2017-12-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman abandoned this revision.
arphaman added a comment.

Accidental 'return', will reopen


Repository:
  rC Clang

https://reviews.llvm.org/D41075



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


r320401 - P0620 follow-up: deducing `auto` from braced-init-list in new expr

2017-12-11 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Mon Dec 11 10:29:54 2017
New Revision: 320401

URL: http://llvm.org/viewvc/llvm-project?rev=320401=rev
Log:
P0620 follow-up: deducing `auto` from braced-init-list in new expr

Summary:
This is a side-effect brought in by p0620r0, which allows other placeholder 
types (derived from `auto` and `decltype(auto)`) to be usable in a `new` 
expression with a single-clause //braced-init-list// as its initializer (8.3.4 
[expr.new]/2).  N3922 defined its semantics.

References:
 http://wg21.link/p0620r0
 http://wg21.link/n3922

Reviewers: rsmith, aaron.ballman

Reviewed By: rsmith

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx14.cpp
cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=320401=320400=320401=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Dec 11 10:29:54 
2017
@@ -1988,8 +1988,9 @@ def err_auto_var_requires_init : Error<
   "declaration of variable %0 with deduced type %1 requires an initializer">;
 def err_auto_new_requires_ctor_arg : Error<
   "new expression for type %0 requires a constructor argument">;
-def err_auto_new_list_init : Error<
-  "new expression for type %0 cannot use list-initialization">;
+def ext_auto_new_list_init : Extension<
+  "ISO C++ standards before C++17 do not allow new expression for "
+  "type %0 to use list-initialization">, InGroup;
 def err_auto_var_init_no_expression : Error<
   "initializer for variable %0 with type %1 is empty">;
 def err_auto_var_init_multiple_expressions : Error<

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=320401=320400=320401=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Dec 11 10:29:54 2017
@@ -1748,20 +1748,27 @@ Sema::BuildCXXNew(SourceRange Range, boo
 if (AllocType.isNull())
   return ExprError();
   } else if (Deduced) {
+bool Braced = (initStyle == CXXNewExpr::ListInit);
+if (NumInits == 1) {
+  if (auto p = dyn_cast_or_null(Inits[0])) {
+Inits = p->getInits();
+NumInits = p->getNumInits();
+Braced = true;
+  }
+}
+
 if (initStyle == CXXNewExpr::NoInit || NumInits == 0)
   return ExprError(Diag(StartLoc, diag::err_auto_new_requires_ctor_arg)
<< AllocType << TypeRange);
-if (initStyle == CXXNewExpr::ListInit ||
-(NumInits == 1 && isa(Inits[0])))
-  return ExprError(Diag(Inits[0]->getLocStart(),
-diag::err_auto_new_list_init)
-   << AllocType << TypeRange);
 if (NumInits > 1) {
   Expr *FirstBad = Inits[1];
   return ExprError(Diag(FirstBad->getLocStart(),
 diag::err_auto_new_ctor_multiple_expressions)
<< AllocType << TypeRange);
 }
+if (Braced && !getLangOpts().CPlusPlus17)
+  Diag(Initializer->getLocStart(), diag::ext_auto_new_list_init)
+  << AllocType << TypeRange;
 Expr *Deduce = Inits[0];
 QualType DeducedType;
 if (DeduceAutoType(AllocTypeInfo, Deduce, DeducedType) == DAR_Failed)

Modified: cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp?rev=320401=320400=320401=diff
==
--- cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp Mon Dec 11 
10:29:54 2017
@@ -9,12 +9,14 @@ struct only {
 void f() {
   only p = new const auto (0);
   only q = new (auto) (0.0);
+  only r = new auto {'a'};
 
   new auto; // expected-error{{new expression for type 'auto' requires a 
constructor argument}}
   new (const auto)(); // expected-error{{new expression for type 'const auto' 
requires a constructor argument}}
   new (auto) (1,2,3); // expected-error{{new expression for type 'auto' 
contains multiple constructor arguments}}
-  new auto {1,2,3}; // expected-error{{new expression for type 'auto' cannot 
use list-initialization}}
-  new auto ({1,2,3}); // expected-error{{new expression for type 'auto' cannot 
use list-initialization}}
+  new auto {}; // 

[PATCH] D39451: P0620 follow-up: deducing `auto` from braced-init-list in new expr

2017-12-11 Thread Zhihao Yuan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC320401: P0620 follow-up: deducing `auto` from 
braced-init-list in new expr (authored by lichray).

Changed prior to commit:
  https://reviews.llvm.org/D39451?vs=126092=126400#toc

Repository:
  rC Clang

https://reviews.llvm.org/D39451

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExprCXX.cpp
  test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
  test/CXX/expr/expr.unary/expr.new/p2-cxx14.cpp
  test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
  test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp

Index: test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
===
--- test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
+++ test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
@@ -148,7 +148,7 @@
 }
 
 void dangle() {
-  new auto{1, 2, 3}; // expected-error {{cannot use list-initialization}}
+  new auto{1, 2, 3}; // expected-error {{new expression for type 'auto' contains multiple constructor arguments}}
   new std::initializer_list{1, 2, 3}; // expected-warning {{at the end of the full-expression}}
 }
 
Index: test/CXX/expr/expr.unary/expr.new/p2-cxx14.cpp
===
--- test/CXX/expr/expr.unary/expr.new/p2-cxx14.cpp
+++ test/CXX/expr/expr.unary/expr.new/p2-cxx14.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14 -pedantic
+
+void f() {
+  new auto('a');
+  new auto {2}; // expected-warning {{ISO C++ standards before C++17 do not allow new expression for type 'auto' to use list-initialization}}
+  new auto {1, 2}; // expected-error{{new expression for type 'auto' contains multiple constructor arguments}}
+  new auto {}; // expected-error{{new expression for type 'auto' requires a constructor argument}}
+  new decltype(auto)({1}); // expected-warning {{ISO C++ standards before C++17 do not allow new expression for type 'decltype(auto)' to use list-initialization}}
+  new decltype(auto)({1, 2}); // expected-error{{new expression for type 'decltype(auto)' contains multiple constructor arguments}}
+}
Index: test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
===
--- test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
+++ test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++17 -pedantic
+
+void f() {
+  new auto('a');
+  new auto {2};
+  new auto {1, 2}; // expected-error{{new expression for type 'auto' contains multiple constructor arguments}}
+  new auto {}; // expected-error{{new expression for type 'auto' requires a constructor argument}}
+  new decltype(auto)({1});
+  new decltype(auto)({1, 2}); // expected-error{{new expression for type 'decltype(auto)' contains multiple constructor arguments}}
+}
Index: test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
===
--- test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
+++ test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
@@ -9,12 +9,14 @@
 void f() {
   only p = new const auto (0);
   only q = new (auto) (0.0);
+  only r = new auto {'a'};
 
   new auto; // expected-error{{new expression for type 'auto' requires a constructor argument}}
   new (const auto)(); // expected-error{{new expression for type 'const auto' requires a constructor argument}}
   new (auto) (1,2,3); // expected-error{{new expression for type 'auto' contains multiple constructor arguments}}
-  new auto {1,2,3}; // expected-error{{new expression for type 'auto' cannot use list-initialization}}
-  new auto ({1,2,3}); // expected-error{{new expression for type 'auto' cannot use list-initialization}}
+  new auto {}; // expected-error{{new expression for type 'auto' requires a constructor argument}}
+  new auto {1,2,3}; // expected-error{{new expression for type 'auto' contains multiple constructor arguments}}
+  new auto ({1,2,3}); // expected-error{{new expression for type 'auto' contains multiple constructor arguments}}
 }
 
 void p2example() {
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -1748,20 +1748,27 @@
 if (AllocType.isNull())
   return ExprError();
   } else if (Deduced) {
+bool Braced = (initStyle == CXXNewExpr::ListInit);
+if (NumInits == 1) {
+  if (auto p = dyn_cast_or_null(Inits[0])) {
+Inits = p->getInits();
+NumInits = p->getNumInits();
+Braced = true;
+  }
+}
+
 if (initStyle == CXXNewExpr::NoInit || NumInits == 0)
   return ExprError(Diag(StartLoc, diag::err_auto_new_requires_ctor_arg)
<< AllocType << TypeRange);
-if (initStyle == CXXNewExpr::ListInit ||
-(NumInits == 1 && 

[PATCH] D40743: Make rehash(0) work with ubsan's unsigned-integer-overflow.

2017-12-11 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

Dan - I think I need a bit more context here.
How does UBSan get triggered?


Repository:
  rCXX libc++

https://reviews.llvm.org/D40743



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


[PATCH] D40991: [libcxx] [test] Fix line endings, avoid unnecessary non-ASCII.

2017-12-11 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

Except for the stuff in TODO.txt these look good to me.
We need to do some work on that file - it's pretty out of date.


https://reviews.llvm.org/D40991



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


r320398 - Revert 320391: Certain targets are failing, pulling back to diagnose.

2017-12-11 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Mon Dec 11 10:14:51 2017
New Revision: 320398

URL: http://llvm.org/viewvc/llvm-project?rev=320398=rev
Log:
Revert 320391: Certain targets are failing, pulling back to diagnose.

Removed:
cfe/trunk/test/Driver/Inputs/stdc-predef/
cfe/trunk/test/Driver/stdc-predef.c
cfe/trunk/test/Driver/stdc-predef.i
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Lex/PreprocessorOptions.h
cfe/trunk/lib/Driver/Job.cpp
cfe/trunk/lib/Driver/ToolChains/Linux.cpp
cfe/trunk/lib/Driver/ToolChains/Linux.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Driver/crash-report-header.h
cfe/trunk/test/Driver/crash-report-spaces.c
cfe/trunk/test/Driver/crash-report.c
cfe/trunk/test/Driver/rewrite-map-in-diagnostics.c
cfe/trunk/test/Index/IBOutletCollection.m
cfe/trunk/test/Index/annotate-macro-args.m
cfe/trunk/test/Index/annotate-tokens-pp.c
cfe/trunk/test/Index/annotate-tokens.c
cfe/trunk/test/Index/c-index-getCursor-test.m
cfe/trunk/test/Index/get-cursor-macro-args.m
cfe/trunk/test/Index/get-cursor.cpp
cfe/trunk/test/Preprocessor/ignore-pragmas.c
cfe/trunk/unittests/Tooling/TestVisitor.h
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=320398=320397=320398=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Dec 11 10:14:51 2017
@@ -769,8 +769,6 @@ def token_cache : Separate<["-"], "token
   HelpText<"Use specified token cache file">;
 def detailed_preprocessing_record : Flag<["-"], 
"detailed-preprocessing-record">,
   HelpText<"include a detailed record of preprocessing actions">;
-def fsystem_include_if_exists : Separate<["-"], "fsystem-include-if-exists">, 
MetaVarName<"">,
-  HelpText<"Include system file before parsing if file exists">;
 
 
//===--===//
 // OpenCL Options

Modified: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorOptions.h?rev=320398=320397=320398=diff
==
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h Mon Dec 11 10:14:51 2017
@@ -60,9 +60,6 @@ public:
   /// \brief Headers that will be converted to chained PCHs in memory.
   std::vector ChainedIncludes;
 
-  /// \brief System Headers that are pre-included if they exist.
-  std::vector FSystemIncludeIfExists;
-
   /// \brief When true, disables most of the normal validation performed on
   /// precompiled headers.
   bool DisablePCHValidation = false;
@@ -186,7 +183,6 @@ public:
 DumpDeserializedPCHDecls = false;
 ImplicitPCHInclude.clear();
 ImplicitPTHInclude.clear();
-FSystemIncludeIfExists.clear();
 TokenCache.clear();
 SingleFileParseMode = false;
 LexEditorPlaceholders = true;

Modified: cfe/trunk/lib/Driver/Job.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Job.cpp?rev=320398=320397=320398=diff
==
--- cfe/trunk/lib/Driver/Job.cpp (original)
+++ cfe/trunk/lib/Driver/Job.cpp Mon Dec 11 10:14:51 2017
@@ -64,7 +64,7 @@ static bool skipArgs(const char *Flag, b
 .Cases("-internal-externc-isystem", "-iprefix", true)
 .Cases("-iwithprefixbefore", "-isystem", "-iquote", true)
 .Cases("-isysroot", "-I", "-F", "-resource-dir", true)
-.Cases("-iframework", "-include-pch", "-fsystem-include-if-exists", true)
+.Cases("-iframework", "-include-pch", true)
 .Default(false);
   if (IsInclude)
 return HaveCrashVFS ? false : true;

Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.cpp?rev=320398=320397=320398=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Linux.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp Mon Dec 11 10:14:51 2017
@@ -710,8 +710,6 @@ void Linux::AddClangSystemIncludeArgs(co
   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
 
   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
-
-  AddGnuIncludeArgs(DriverArgs, CC1Args);
 }
 
 static std::string DetectLibcxxIncludePath(StringRef base) {
@@ -750,16 +748,6 @@ std::string Linux::findLibCxxIncludePath
   return "";
 }
 
-void Linux::AddGnuIncludeArgs(const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ) const {
-  if 

[PATCH] D41074: [ClangFormat] ObjCSpaceBeforeProtocolList should be true in the google style

2017-12-11 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
Herald added a subscriber: cfe-commits.

The Google style guide is neutral on whether there should be a
space before the protocol list in an Objective-C @interface or
@implementation.

The majority of Objective-C code in both Apple's public
header files and Google's open-source uses a space before
the protocol list, so this changes the google style to
default ObjCSpaceBeforeProtocolList to true.

Test Plan: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D41074

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -200,7 +200,7 @@
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@interface Foo : NSObject {\n"
+  verifyFormat("@interface Foo : NSObject  {\n"
" @public\n"
"  int field1;\n"
" @protected\n"
@@ -212,15 +212,15 @@
"}\n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo : Bar\n"
+  verifyFormat("@interface Foo : Bar \n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo (HackStuff)\n"
+  verifyFormat("@interface Foo (HackStuff) \n"
"+ (id)init;\n"
"@end");
   Style.BinPackParameters = false;
   Style.ColumnLimit = 80;
-  verifyFormat("@interface a ()<\n"
+  verifyFormat("@interface a () <\n"
"a,\n"
",\n"
"aa,\n"
@@ -343,7 +343,7 @@
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@protocol MyProtocol\n"
+  verifyFormat("@protocol MyProtocol \n"
"- (NSUInteger)numberOfThings;\n"
"@end");
 }
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -693,7 +693,7 @@
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCSpaceAfterProperty = false;
-  GoogleStyle.ObjCSpaceBeforeProtocolList = false;
+  GoogleStyle.ObjCSpaceBeforeProtocolList = true;
   GoogleStyle.PointerAlignment = FormatStyle::PAS_Left;
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.Standard = FormatStyle::LS_Auto;


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -200,7 +200,7 @@
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@interface Foo : NSObject {\n"
+  verifyFormat("@interface Foo : NSObject  {\n"
" @public\n"
"  int field1;\n"
" @protected\n"
@@ -212,15 +212,15 @@
"}\n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo : Bar\n"
+  verifyFormat("@interface Foo : Bar \n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo (HackStuff)\n"
+  verifyFormat("@interface Foo (HackStuff) \n"
"+ (id)init;\n"
"@end");
   Style.BinPackParameters = false;
   Style.ColumnLimit = 80;
-  verifyFormat("@interface a ()<\n"
+  verifyFormat("@interface a () <\n"
"a,\n"
",\n"
"aa,\n"
@@ -343,7 +343,7 @@
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@protocol MyProtocol\n"
+  verifyFormat("@protocol MyProtocol \n"
"- (NSUInteger)numberOfThings;\n"
"@end");
 }
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -693,7 +693,7 @@
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCSpaceAfterProperty = false;
-  GoogleStyle.ObjCSpaceBeforeProtocolList = false;
+  GoogleStyle.ObjCSpaceBeforeProtocolList = true;
   GoogleStyle.PointerAlignment = FormatStyle::PAS_Left;
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.Standard = FormatStyle::LS_Auto;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D41064: Suppress -Wuser-defined-literals for and

2017-12-11 Thread Dimitry Andric via Phabricator via cfe-commits
dim updated this revision to Diff 126397.
dim added a comment.

Updated to also include  and .  I think all cases are
covered now.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41064

Files:
  include/chrono
  include/complex
  include/string
  include/string_view


Index: include/string_view
===
--- include/string_view
+++ include/string_view
@@ -792,6 +792,10 @@
 {
   inline namespace string_view_literals
   {
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wuser-defined-literals"
+#endif
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 basic_string_view operator "" sv(const char *__str, size_t __len) 
_NOEXCEPT
 {
@@ -815,6 +819,9 @@
 {
 return basic_string_view (__str, __len);
 }
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
   }
 }
 #endif
Index: include/string
===
--- include/string
+++ include/string
@@ -4042,6 +4042,10 @@
 {
   inline namespace string_literals
   {
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wuser-defined-literals"
+#endif
 inline _LIBCPP_INLINE_VISIBILITY
 basic_string operator "" s( const char *__str, size_t __len )
 {
@@ -4065,6 +4069,9 @@
 {
 return basic_string (__str, __len);
 }
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
   }
 }
 #endif
Index: include/complex
===
--- include/complex
+++ include/complex
@@ -1444,6 +1444,10 @@
 { 
   inline namespace complex_literals
   {
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wuser-defined-literals"
+#endif
 constexpr complex operator""il(long double __im)
 {
 return { 0.0l, __im };
@@ -1475,6 +1479,9 @@
 {
 return { 0.0f, static_cast(__im) };
 }
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
   }
 }
 #endif
Index: include/chrono
===
--- include/chrono
+++ include/chrono
@@ -1086,6 +1086,10 @@
 { 
   inline namespace chrono_literals
   {
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wuser-defined-literals"
+#endif
 
 constexpr chrono::hours operator""h(unsigned long long __h)
 {
@@ -1152,6 +1156,9 @@
 return chrono::duration (__ns);
 }
 
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
 }}
 
 namespace chrono { // hoist the literals into namespace std::chrono


Index: include/string_view
===
--- include/string_view
+++ include/string_view
@@ -792,6 +792,10 @@
 {
   inline namespace string_view_literals
   {
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wuser-defined-literals"
+#endif
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 basic_string_view operator "" sv(const char *__str, size_t __len) _NOEXCEPT
 {
@@ -815,6 +819,9 @@
 {
 return basic_string_view (__str, __len);
 }
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
   }
 }
 #endif
Index: include/string
===
--- include/string
+++ include/string
@@ -4042,6 +4042,10 @@
 {
   inline namespace string_literals
   {
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wuser-defined-literals"
+#endif
 inline _LIBCPP_INLINE_VISIBILITY
 basic_string operator "" s( const char *__str, size_t __len )
 {
@@ -4065,6 +4069,9 @@
 {
 return basic_string (__str, __len);
 }
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
   }
 }
 #endif
Index: include/complex
===
--- include/complex
+++ include/complex
@@ -1444,6 +1444,10 @@
 { 
   inline namespace complex_literals
   {
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wuser-defined-literals"
+#endif
 constexpr complex operator""il(long double __im)
 {
 return { 0.0l, __im };
@@ -1475,6 +1479,9 @@
 {
 return { 0.0f, static_cast(__im) };
 }
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
   }
 }
 #endif
Index: include/chrono
===
--- include/chrono
+++ include/chrono
@@ -1086,6 +1086,10 @@
 { 
   inline namespace chrono_literals
   {
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wuser-defined-literals"
+#endif
 
 constexpr chrono::hours operator""h(unsigned long long __h)
 {
@@ -1152,6 +1156,9 @@
 return chrono::duration (__ns);
 }
 
+#if defined(__clang__)
+#pragma clang 

[PATCH] D41073: Wasm: add support in libcxx

2017-12-11 Thread Nicholas Wilson via Phabricator via cfe-commits
ncw created this revision.
Herald added subscribers: cfe-commits, aheejin, jfb.
Herald added a reviewer: EricWF.

It turns out that this is the only change required in libcxx for it to compile 
with the new `wasm32-unknown-unknown-wasm` target recently added to Clang.

I haven't done much testing of whether libc++ //works// with Wasm, but 
committing the compile fix is at least a start.

Adding Marshall Clow and Dan Gohman as reviewers since they landed the last 
Emscripten-related changes in libcxx.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41073

Files:
  include/__config


Index: include/__config
===
--- include/__config
+++ include/__config
@@ -45,6 +45,8 @@
 #define _LIBCPP_OBJECT_FORMAT_MACHO 1
 #elif defined(_WIN32)
 #define _LIBCPP_OBJECT_FORMAT_COFF  1
+#elif defined(__wasm__)
+#define _LIBCPP_OBJECT_FORMAT_WASM  1
 #else
 #error Unknown object file format
 #endif


Index: include/__config
===
--- include/__config
+++ include/__config
@@ -45,6 +45,8 @@
 #define _LIBCPP_OBJECT_FORMAT_MACHO 1
 #elif defined(_WIN32)
 #define _LIBCPP_OBJECT_FORMAT_COFF  1
+#elif defined(__wasm__)
+#define _LIBCPP_OBJECT_FORMAT_WASM  1
 #else
 #error Unknown object file format
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41064: Suppress -Wuser-defined-literals for and

2017-12-11 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists requested changes to this revision.
mclow.lists added a comment.
This revision now requires changes to proceed.

In https://reviews.llvm.org/D41064#950946, @aaron.ballman wrote:

> I think that it would be more appropriate to fix this in Clang rather than 
> libc++. For instance, we don't want libstdc++ to have to silence our same 
> diagnostic here.


I agree.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41064



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


[PATCH] D41016: [Sema] Fix crash in unused-lambda-capture warning for VLAs

2017-12-11 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: lib/Sema/SemaLambda.cpp:1491
   else
 diag << From.getVariable();
   diag << From.isNonODRUsed();

dim wrote:
> Just for sanity's sake, I would still put an assert here, that 
> `getVariable()` does not return `nullptr`.  That might catch similar issues 
> in the future.  (And it is better than a segfault... :) )
> 
I'm adding an assert to `getVariable()` instead.


Repository:
  rC Clang

https://reviews.llvm.org/D41016



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


[PATCH] D41016: [Sema] Fix crash in unused-lambda-capture warning for VLAs

2017-12-11 Thread Malcolm Parsons via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320396: [Sema] Fix crash in unused-lambda-capture warning 
for VLAs (authored by malcolm.parsons).

Repository:
  rL LLVM

https://reviews.llvm.org/D41016

Files:
  cfe/trunk/include/clang/Sema/ScopeInfo.h
  cfe/trunk/lib/Sema/SemaLambda.cpp
  cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp


Index: cfe/trunk/include/clang/Sema/ScopeInfo.h
===
--- cfe/trunk/include/clang/Sema/ScopeInfo.h
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h
@@ -560,6 +560,7 @@
 void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
 
 VarDecl *getVariable() const {
+  assert(isVariableCapture());
   return VarAndNestedAndThis.getPointer();
 }
 
Index: cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
===
--- cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
+++ cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
@@ -191,3 +191,12 @@
 void test_use_template() {
   test_templated(); // expected-note{{in instantiation of function 
template specialization 'test_templated' requested here}}
 }
+
+namespace pr3 {
+int a;
+void b() {
+  int c[a];
+  auto vla_used = [] { return c[0]; };
+  auto vla_unused = [] {}; // expected-warning{{lambda capture 'c' is not 
used}}
+}
+} // namespace pr3
Index: cfe/trunk/lib/Sema/SemaLambda.cpp
===
--- cfe/trunk/lib/Sema/SemaLambda.cpp
+++ cfe/trunk/lib/Sema/SemaLambda.cpp
@@ -1481,6 +1481,9 @@
   if (CaptureHasSideEffects(From))
 return;
 
+  if (From.isVLATypeCapture())
+return;
+
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
 diag << "'this'";


Index: cfe/trunk/include/clang/Sema/ScopeInfo.h
===
--- cfe/trunk/include/clang/Sema/ScopeInfo.h
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h
@@ -560,6 +560,7 @@
 void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
 
 VarDecl *getVariable() const {
+  assert(isVariableCapture());
   return VarAndNestedAndThis.getPointer();
 }
 
Index: cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
===
--- cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
+++ cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
@@ -191,3 +191,12 @@
 void test_use_template() {
   test_templated(); // expected-note{{in instantiation of function template specialization 'test_templated' requested here}}
 }
+
+namespace pr3 {
+int a;
+void b() {
+  int c[a];
+  auto vla_used = [] { return c[0]; };
+  auto vla_unused = [] {}; // expected-warning{{lambda capture 'c' is not used}}
+}
+} // namespace pr3
Index: cfe/trunk/lib/Sema/SemaLambda.cpp
===
--- cfe/trunk/lib/Sema/SemaLambda.cpp
+++ cfe/trunk/lib/Sema/SemaLambda.cpp
@@ -1481,6 +1481,9 @@
   if (CaptureHasSideEffects(From))
 return;
 
+  if (From.isVLATypeCapture())
+return;
+
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
 diag << "'this'";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r320396 - [Sema] Fix crash in unused-lambda-capture warning for VLAs

2017-12-11 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Mon Dec 11 10:00:36 2017
New Revision: 320396

URL: http://llvm.org/viewvc/llvm-project?rev=320396=rev
Log:
[Sema] Fix crash in unused-lambda-capture warning for VLAs

Summary:
Clang was crashing when diagnosing an unused-lambda-capture for a VLA because
From.getVariable() is null for the capture of a VLA bound.
Warning about the VLA bound capture is not helpful, so only warn for the VLA
itself.

Fixes: PR3

Reviewers: aaron.ballman, dim, rsmith

Reviewed By: aaron.ballman, dim

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=320396=320395=320396=diff
==
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Mon Dec 11 10:00:36 2017
@@ -560,6 +560,7 @@ public:
 void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
 
 VarDecl *getVariable() const {
+  assert(isVariableCapture());
   return VarAndNestedAndThis.getPointer();
 }
 

Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=320396=320395=320396=diff
==
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Mon Dec 11 10:00:36 2017
@@ -1481,6 +1481,9 @@ void Sema::DiagnoseUnusedLambdaCapture(c
   if (CaptureHasSideEffects(From))
 return;
 
+  if (From.isVLATypeCapture())
+return;
+
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
 diag << "'this'";

Modified: cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp?rev=320396=320395=320396=diff
==
--- cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp Mon Dec 11 10:00:36 
2017
@@ -191,3 +191,12 @@ void test_templated() {
 void test_use_template() {
   test_templated(); // expected-note{{in instantiation of function 
template specialization 'test_templated' requested here}}
 }
+
+namespace pr3 {
+int a;
+void b() {
+  int c[a];
+  auto vla_used = [] { return c[0]; };
+  auto vla_unused = [] {}; // expected-warning{{lambda capture 'c' is not 
used}}
+}
+} // namespace pr3


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


[PATCH] D41016: [Sema] Fix crash in unused-lambda-capture warning for VLAs

2017-12-11 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 126394.
malcolm.parsons marked an inline comment as done.
malcolm.parsons added a comment.

Add assert.


Repository:
  rC Clang

https://reviews.llvm.org/D41016

Files:
  include/clang/Sema/ScopeInfo.h
  lib/Sema/SemaLambda.cpp
  test/SemaCXX/warn-unused-lambda-capture.cpp


Index: test/SemaCXX/warn-unused-lambda-capture.cpp
===
--- test/SemaCXX/warn-unused-lambda-capture.cpp
+++ test/SemaCXX/warn-unused-lambda-capture.cpp
@@ -191,3 +191,12 @@
 void test_use_template() {
   test_templated(); // expected-note{{in instantiation of function 
template specialization 'test_templated' requested here}}
 }
+
+namespace pr3 {
+int a;
+void b() {
+  int c[a];
+  auto vla_used = [] { return c[0]; };
+  auto vla_unused = [] {}; // expected-warning{{lambda capture 'c' is not 
used}}
+}
+} // namespace pr3
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -1481,6 +1481,9 @@
   if (CaptureHasSideEffects(From))
 return;
 
+  if (From.isVLATypeCapture())
+return;
+
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
 diag << "'this'";
Index: include/clang/Sema/ScopeInfo.h
===
--- include/clang/Sema/ScopeInfo.h
+++ include/clang/Sema/ScopeInfo.h
@@ -560,6 +560,7 @@
 void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
 
 VarDecl *getVariable() const {
+  assert(isVariableCapture());
   return VarAndNestedAndThis.getPointer();
 }
 


Index: test/SemaCXX/warn-unused-lambda-capture.cpp
===
--- test/SemaCXX/warn-unused-lambda-capture.cpp
+++ test/SemaCXX/warn-unused-lambda-capture.cpp
@@ -191,3 +191,12 @@
 void test_use_template() {
   test_templated(); // expected-note{{in instantiation of function template specialization 'test_templated' requested here}}
 }
+
+namespace pr3 {
+int a;
+void b() {
+  int c[a];
+  auto vla_used = [] { return c[0]; };
+  auto vla_unused = [] {}; // expected-warning{{lambda capture 'c' is not used}}
+}
+} // namespace pr3
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -1481,6 +1481,9 @@
   if (CaptureHasSideEffects(From))
 return;
 
+  if (From.isVLATypeCapture())
+return;
+
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
 diag << "'this'";
Index: include/clang/Sema/ScopeInfo.h
===
--- include/clang/Sema/ScopeInfo.h
+++ include/clang/Sema/ScopeInfo.h
@@ -560,6 +560,7 @@
 void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
 
 VarDecl *getVariable() const {
+  assert(isVariableCapture());
   return VarAndNestedAndThis.getPointer();
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41042: [analyzer] StackAddrEscape: Delay turning on by default a little bit?

2017-12-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 126390.
NoQ added a comment.

Add a FIXME test.


https://reviews.llvm.org/D41042

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  test/Analysis/stack-capture-leak-arc.mm
  test/Analysis/stack-capture-leak-no-arc.mm

Index: test/Analysis/stack-capture-leak-no-arc.mm
===
--- test/Analysis/stack-capture-leak-no-arc.mm
+++ test/Analysis/stack-capture-leak-no-arc.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,alpha.core.StackAddressAsyncEscape -fblocks -verify %s
 
 typedef struct dispatch_queue_s *dispatch_queue_t;
 typedef void (^dispatch_block_t)(void);
Index: test/Analysis/stack-capture-leak-arc.mm
===
--- test/Analysis/stack-capture-leak-arc.mm
+++ test/Analysis/stack-capture-leak-arc.mm
@@ -1,12 +1,13 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -fobjc-arc -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,alpha.core.StackAddressAsyncEscape -fblocks -fobjc-arc -verify %s
 
 typedef struct dispatch_queue_s *dispatch_queue_t;
 typedef void (^dispatch_block_t)(void);
 void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
 typedef long dispatch_once_t;
 void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);
 typedef long dispatch_time_t;
 void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_barrier_sync(dispatch_queue_t queue, dispatch_block_t block);
 
 extern dispatch_queue_t queue;
 extern dispatch_once_t *predicate;
@@ -173,3 +174,16 @@
   // Wait for the asynchronous work to finish
   dispatch_semaphore_wait(semaphore, 1000);
 }
+
+void test_dispatch_barrier_sync() {
+  int buf[16];
+  for (int n = 0; n < 16; ++n) {
+int *ptr = [n];
+// FIXME: Should not warn. The dispatch_barrier_sync() call ensures
+// that the block does not outlive 'buf'.
+dispatch_async(queue, ^{ // expected-warning{{Address of stack memory associated with local variable 'buf' is captured by an asynchronously-executed block}}
+  (void)ptr;
+});
+  }
+  dispatch_barrier_sync(queue, ^{});
+}
Index: lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -37,6 +37,14 @@
   mutable std::unique_ptr BT_capturedstackret;
 
 public:
+  enum CheckKind {
+CK_StackAddrEscapeChecker,
+CK_StackAddrAsyncEscapeChecker,
+CK_NumCheckKinds
+  };
+
+  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+
   void checkPreCall(const CallEvent , CheckerContext ) const;
   void checkPreStmt(const ReturnStmt *RS, CheckerContext ) const;
   void checkEndFunction(CheckerContext ) const;
@@ -225,6 +233,8 @@
 
 void StackAddrEscapeChecker::checkPreCall(const CallEvent ,
   CheckerContext ) const {
+  if (!ChecksEnabled[CK_StackAddrAsyncEscapeChecker])
+return;
   if (!Call.isGlobalCFunction("dispatch_after") &&
   !Call.isGlobalCFunction("dispatch_async"))
 return;
@@ -237,6 +247,8 @@
 
 void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS,
   CheckerContext ) const {
+  if (!ChecksEnabled[CK_StackAddrEscapeChecker])
+return;
 
   const Expr *RetE = RS->getRetValue();
   if (!RetE)
@@ -277,6 +289,9 @@
 }
 
 void StackAddrEscapeChecker::checkEndFunction(CheckerContext ) const {
+  if (!ChecksEnabled[CK_StackAddrEscapeChecker])
+return;
+
   ProgramStateRef State = Ctx.getState();
 
   // Iterate over all bindings to global variables and see if it contains
@@ -346,6 +361,12 @@
   }
 }
 
-void ento::registerStackAddrEscapeChecker(CheckerManager ) {
-  Mgr.registerChecker();
-}
+#define REGISTER_CHECKER(name) \
+  void ento::register##name(CheckerManager ) { \
+StackAddrEscapeChecker *Chk = \
+Mgr.registerChecker(); \
+Chk->ChecksEnabled[StackAddrEscapeChecker::CK_##name] = true; \
+  }
+
+REGISTER_CHECKER(StackAddrEscapeChecker)
+REGISTER_CHECKER(StackAddrAsyncEscapeChecker)
Index: include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -188,6 +188,10 @@
   HelpText<"Check for cases where the dynamic and the static type of an object are unrelated.">,
   DescFile<"DynamicTypeChecker.cpp">;
 
+def StackAddrAsyncEscapeChecker : Checker<"StackAddressAsyncEscape">,
+  HelpText<"Check that addresses to stack 

[PATCH] D39053: [Bitfield] Add more cases to making the bitfield a separate location

2017-12-11 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic added a comment.

ping


https://reviews.llvm.org/D39053



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


[PATCH] D40998: [driver][darwin] Take the OS version specified in "-target" as the target OS instead of inferring it from SDK / environment

2017-12-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 126388.
arphaman marked an inline comment as done.
arphaman added a comment.

Don't warn about the redundant environment variable


Repository:
  rC Clang

https://reviews.llvm.org/D40998

Files:
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c
  test/Driver/objc-weak.m
  test/Driver/pic.c
  test/Driver/unavailable_aligned_allocation.cpp

Index: test/Driver/unavailable_aligned_allocation.cpp
===
--- test/Driver/unavailable_aligned_allocation.cpp
+++ test/Driver/unavailable_aligned_allocation.cpp
@@ -10,15 +10,15 @@
 // RUN: %clang -target thumbv7-apple-watchos3 -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=UNAVAILABLE
 //
-// RUN: %clang -target x86_64-apple-macosx10.13 -mios-simulator-version-min=10 \
+// RUN: %clang -target x86_64-apple-darwin -mios-simulator-version-min=10 \
 // RUN:  -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=UNAVAILABLE
 //
-// RUN: %clang -target x86_64-apple-macosx10.13 -mtvos-simulator-version-min=10 \
+// RUN: %clang -target x86_64-apple-darwin -mtvos-simulator-version-min=10 \
 // RUN: -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=UNAVAILABLE
 //
-// RUN: %clang -target x86_64-apple-macosx10.13 -mwatchos-simulator-version-min=3 \
+// RUN: %clang -target x86_64-apple-darwin -mwatchos-simulator-version-min=3 \
 // RUN: -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=UNAVAILABLE
 //
@@ -39,15 +39,15 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=AVAILABLE
 //
-// RUN: %clang -target x86_64-apple-macosx10.12 -mios-simulator-version-min=11 \
+// RUN: %clang -target x86_64-apple-darwin -mios-simulator-version-min=11 \
 // RUN:  -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=AVAILABLE
 //
-// RUN: %clang -target x86_64-apple-macosx10.12 -mtvos-simulator-version-min=11 \
+// RUN: %clang -target x86_64-apple-darwin -mtvos-simulator-version-min=11 \
 // RUN: -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=AVAILABLE
 //
-// RUN: %clang -target x86_64-apple-macosx10.12 -mwatchos-simulator-version-min=4 \
+// RUN: %clang -target x86_64-apple-darwin -mwatchos-simulator-version-min=4 \
 // RUN: -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=AVAILABLE
 //
Index: test/Driver/pic.c
===
--- test/Driver/pic.c
+++ test/Driver/pic.c
@@ -221,19 +221,19 @@
 //
 // Checks for ARM+Apple+IOS including -fapple-kext, -mkernel, and iphoneos
 // version boundaries.
-// RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=6.0.0 -### 2>&1 \
+// RUN: %clang -c %s -target armv7-apple-ios6 -fapple-kext -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
-// RUN: %clang -c %s -target armv7-apple-ios -mkernel -miphoneos-version-min=6.0.0 -### 2>&1 \
+// RUN: %clang -c %s -target armv7-apple-ios6 -mkernel -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
-// RUN: %clang -c %s -target arm64-apple-ios -mkernel -miphoneos-version-min=7.0.0 -### 2>&1 \
+// RUN: %clang -c %s -target arm64-apple-ios7 -mkernel -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
-// RUN: %clang -x assembler -c %s -target arm64-apple-ios -mkernel -miphoneos-version-min=7.0.0 -no-integrated-as -### 2>&1 \
+// RUN: %clang -x assembler -c %s -target arm64-apple-ios7 -mkernel -no-integrated-as -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-STATIC
-// RUN: %clang -c %s -target armv7k-apple-watchos -fapple-kext -mwatchos-version-min=1.0.0 -### 2>&1 \
+// RUN: %clang -c %s -target armv7k-apple-watchos1 -fapple-kext -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
-// RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=5.0.0 -### 2>&1 \
+// RUN: %clang -c %s -target armv7-apple-ios5 -fapple-kext -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
-// RUN: %clang -c %s -target armv7-apple-ios -fapple-kext -miphoneos-version-min=6.0.0 -static -### 2>&1 \
+// RUN: %clang -c %s -target armv7-apple-ios6 -fapple-kext -static -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
 // RUN: %clang -c %s -target armv7-apple-unknown-macho -static -### 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-NO-PIC
Index: test/Driver/objc-weak.m
===
--- test/Driver/objc-weak.m
+++ test/Driver/objc-weak.m
@@ -1,27 +1,27 @@
 // Check miscellaneous Objective-C options.
 
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fobjc-arc -fobjc-weak 2>&1 | FileCheck %s --check-prefix ARC-WEAK
-// RUN: %clang -target x86_64-apple-macosx -mmacosx-version-min=10.7 -S -### %s -fno-objc-weak -fobjc-weak -fobjc-arc  2>&1 | FileCheck %s --check-prefix ARC-WEAK
+// RUN: %clang -target x86_64-apple-macosx10.7 -S -### %s 

[PATCH] D40897: [clangd] Introduce a "Symbol" class.

2017-12-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

\o/




Comment at: clangd/index/Index.cpp:34
+
+SymbolSlab::const_iterator SymbolSlab::find(const SymbolID& SymID) const {
+  return Symbols.find(SymID);

assert frozen? (and in begin())



Comment at: clangd/index/Index.h:45
+  SymbolID(llvm::StringRef USR);
+  std::array HashValue;
+};

nit: make HashValue private?

provide operator== (and use it from DenseMapInfo).



Comment at: clangd/index/Index.h:108
+  static inline clang::clangd::SymbolID getEmptyKey() {
+return clang::clangd::SymbolID("EMPTYKEY");
+  }

nit: you may want to memoize this in a local static variable, rather than 
compute it each time: DenseMap calls it a lot.



Comment at: clangd/index/SymbolCollector.cpp:37
+ << '\n';
+  // Handle symbolic link path cases.
+  // We are trying to get the real file path of the symlink.

Can you spell out here which symbolic link cases we're handling, and what 
problems we're trying to avoid?

Offline, we talked about the CWD being a symlink. But this is a different 
case...



Comment at: clangd/index/SymbolCollector.h:35
+
+  StringRef getFilename() const {
+return Filename;

What's this for? Seems like we should be able to handle multiple TUs with one 
collector?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40897



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


[PATCH] D34158: For Linux/gnu compatibility, preinclude if the file is available

2017-12-11 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320391: For Linux/gnu compatibility, preinclude 
 if the file is available (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D34158?vs=123613=126386#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34158

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

Index: cfe/trunk/unittests/Tooling/TestVisitor.h
===
--- cfe/trunk/unittests/Tooling/TestVisitor.h
+++ cfe/trunk/unittests/Tooling/TestVisitor.h
@@ -52,6 +52,7 @@
   /// \brief Runs the current AST visitor over the given code.
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
+Args.push_back("-ffreestanding");
 switch (L) {
   case Lang_C:
 Args.push_back("-x");
Index: cfe/trunk/unittests/libclang/LibclangTest.cpp
===
--- cfe/trunk/unittests/libclang/LibclangTest.cpp
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp
@@ -434,8 +434,10 @@
 "#ifdef KIWIS\n"
 "printf(\"mmm!!\");\n"
 "#endif");
+  const char *Args[] = { "-ffreestanding" };
+  int NumArgs = sizeof(Args) / sizeof(Args[0]);
 
-  ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
+  ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), Args, NumArgs,
nullptr, 0, TUFlags);
 
   CXSourceRangeList *Ranges = clang_getAllSkippedRanges(ClangTU);
Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -769,6 +769,8 @@
   HelpText<"Use specified token cache file">;
 def detailed_preprocessing_record : Flag<["-"], "detailed-preprocessing-record">,
   HelpText<"include a detailed record of preprocessing actions">;
+def fsystem_include_if_exists : Separate<["-"], "fsystem-include-if-exists">, MetaVarName<"">,
+  HelpText<"Include system file before parsing if file exists">;
 
 //===--===//
 // OpenCL Options
Index: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
===
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h
@@ -60,6 +60,9 @@
   /// \brief Headers that will be converted to chained PCHs in memory.
   std::vector ChainedIncludes;
 
+  /// \brief System Headers that are pre-included if they exist.
+  std::vector FSystemIncludeIfExists;
+
   /// \brief When true, disables most of the normal validation performed on
   /// precompiled headers.
   bool DisablePCHValidation = false;
@@ -183,6 +186,7 @@
 DumpDeserializedPCHDecls = false;
 ImplicitPCHInclude.clear();
 ImplicitPTHInclude.clear();
+FSystemIncludeIfExists.clear();
 TokenCache.clear();
 SingleFileParseMode = false;
 LexEditorPlaceholders = true;
Index: cfe/trunk/test/Index/annotate-tokens.c
===
--- cfe/trunk/test/Index/annotate-tokens.c
+++ cfe/trunk/test/Index/annotate-tokens.c
@@ -68,7 +68,7 @@
   reg.field = 1;
 }
 
-// RUN: c-index-test -test-annotate-tokens=%s:4:1:37:1 %s | FileCheck %s
+// RUN: c-index-test -test-annotate-tokens=%s:4:1:37:1 -ffreestanding %s | FileCheck %s
 // CHECK: Identifier: "T" [4:3 - 4:4] TypeRef=T:1:13
 // CHECK: Punctuation: "*" [4:4 - 4:5] VarDecl=t_ptr:4:6 (Definition)
 // CHECK: Identifier: "t_ptr" [4:6 - 4:11] VarDecl=t_ptr:4:6 (Definition)
@@ -191,10 +191,10 @@
 // CHECK: Punctuation: ")" [36:97 - 36:98] FunctionDecl=test:36:63 (unavailable)  (always unavailable: "")
 // CHECK: Punctuation: ";" [36:98 - 36:99]
 
-// RUN: c-index-test -test-annotate-tokens=%s:4:1:165:32 %s | 

[PATCH] D34158: For Linux/gnu compatibility, preinclude if the file is available

2017-12-11 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC320391: For Linux/gnu compatibility, preinclude 
 if the file is available (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D34158?vs=123613=126387#toc

Repository:
  rC Clang

https://reviews.llvm.org/D34158

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

Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -769,6 +769,8 @@
   HelpText<"Use specified token cache file">;
 def detailed_preprocessing_record : Flag<["-"], "detailed-preprocessing-record">,
   HelpText<"include a detailed record of preprocessing actions">;
+def fsystem_include_if_exists : Separate<["-"], "fsystem-include-if-exists">, MetaVarName<"">,
+  HelpText<"Include system file before parsing if file exists">;
 
 //===--===//
 // OpenCL Options
Index: include/clang/Lex/PreprocessorOptions.h
===
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -60,6 +60,9 @@
   /// \brief Headers that will be converted to chained PCHs in memory.
   std::vector ChainedIncludes;
 
+  /// \brief System Headers that are pre-included if they exist.
+  std::vector FSystemIncludeIfExists;
+
   /// \brief When true, disables most of the normal validation performed on
   /// precompiled headers.
   bool DisablePCHValidation = false;
@@ -183,6 +186,7 @@
 DumpDeserializedPCHDecls = false;
 ImplicitPCHInclude.clear();
 ImplicitPTHInclude.clear();
+FSystemIncludeIfExists.clear();
 TokenCache.clear();
 SingleFileParseMode = false;
 LexEditorPlaceholders = true;
Index: test/Driver/crash-report-spaces.c
===
--- test/Driver/crash-report-spaces.c
+++ test/Driver/crash-report-spaces.c
@@ -1,7 +1,7 @@
 // RUN: rm -rf "%t"
 // RUN: mkdir "%t"
 // RUN: cp "%s" "%t/crash report spaces.c"
-// RUN: not env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTIONS=1 %clang -fsyntax-only "%t/crash report spaces.c" 2>&1 | FileCheck "%s"
+// RUN: not env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTIONS=1 %clang -ffreestanding -fsyntax-only "%t/crash report spaces.c" 2>&1 | FileCheck "%s"
 // RUN: cat "%t/crash report spaces"-*.c | FileCheck --check-prefix=CHECKSRC "%s"
 // RUN: cat "%t/crash report spaces"-*.sh | FileCheck --check-prefix=CHECKSH "%s"
 // REQUIRES: crash-recovery
Index: test/Driver/rewrite-map-in-diagnostics.c
===
--- test/Driver/rewrite-map-in-diagnostics.c
+++ test/Driver/rewrite-map-in-diagnostics.c
@@ -1,7 +1,7 @@
 // RUN: rm -rf "%t"
 // RUN: mkdir -p "%t"
 // RUN: not env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTION=1 \
-// RUN: %clang -fsyntax-only -frewrite-map-file %p/Inputs/rewrite.map %s 2>&1 \
+// RUN: %clang -ffreestanding -fsyntax-only -frewrite-map-file %p/Inputs/rewrite.map %s 2>&1 \
 // RUN:   | FileCheck %s
 
 #pragma clang __debug parser_crash
Index: test/Driver/stdc-predef.i
===
--- test/Driver/stdc-predef.i
+++ test/Driver/stdc-predef.i
@@ -0,0 +1,16 @@
+// The automatic preinclude of stdc-predef.h should not occur if
+// the source filename indicates a preprocessed file.
+//
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --sysroot=%S/Inputs/stdc-predef \
+// RUN: | FileCheck --implicit-check-not "stdc-predef.h" %s
+
+int i;
+// The automatic preinclude of stdc-predef.h should not occur if
+// the source filename indicates a preprocessed file.
+//
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --sysroot=%S/Inputs/stdc-predef \
+// RUN: | FileCheck --implicit-check-not "stdc-predef.h" %s
+
+int i;
Index: test/Driver/stdc-predef.c
===
--- test/Driver/stdc-predef.c
+++ test/Driver/stdc-predef.c
@@ -0,0 +1,25 @@
+// Test that clang preincludes stdc-predef.h, if the 

[PATCH] D41042: [analyzer] StackAddrEscape: Delay turning on by default a little bit?

2017-12-11 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Yeah, we usually try to avoid omissions of modeling in on-by-default checkers 
because the user may accidentally run into projects in which the unmodeled 
idiom is common, and then he'd get false positives all over the place. In my 
case it was just two new positives, both false due to this 
`dispatch_barrier_sync` idiom.


https://reviews.llvm.org/D41042



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


r320391 - For Linux/gnu compatibility, preinclude if the file is available

2017-12-11 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Mon Dec 11 09:36:42 2017
New Revision: 320391

URL: http://llvm.org/viewvc/llvm-project?rev=320391=rev
Log:
For Linux/gnu compatibility, preinclude  if the file is available

As reported in llvm bugzilla 32377.
Here’s a patch to add preinclude of stdc-predef.h.

The gcc documentation says “On GNU/Linux,  is pre-included.” See 
https://gcc.gnu.org/gcc-4.8/porting_to.html;

The preinclude is inhibited with –ffreestanding.

Basically I fixed the failing test cases by adding –ffreestanding which 
inhibits this behavior.

I fixed all the failing tests, including some in extra/test, there's a separate 
patch for that which is linked here

Note: this is a recommit after a test failure took down the original (r318669)

Patch By: mibintc
Differential Revision: https://reviews.llvm.org/D34158

Added:
cfe/trunk/test/Driver/Inputs/stdc-predef/
cfe/trunk/test/Driver/Inputs/stdc-predef/usr/
cfe/trunk/test/Driver/Inputs/stdc-predef/usr/include/
cfe/trunk/test/Driver/Inputs/stdc-predef/usr/include/stdc-predef.h
cfe/trunk/test/Driver/stdc-predef.c
cfe/trunk/test/Driver/stdc-predef.i
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Lex/PreprocessorOptions.h
cfe/trunk/lib/Driver/Job.cpp
cfe/trunk/lib/Driver/ToolChains/Linux.cpp
cfe/trunk/lib/Driver/ToolChains/Linux.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Driver/crash-report-header.h
cfe/trunk/test/Driver/crash-report-spaces.c
cfe/trunk/test/Driver/crash-report.c
cfe/trunk/test/Driver/rewrite-map-in-diagnostics.c
cfe/trunk/test/Index/IBOutletCollection.m
cfe/trunk/test/Index/annotate-macro-args.m
cfe/trunk/test/Index/annotate-tokens-pp.c
cfe/trunk/test/Index/annotate-tokens.c
cfe/trunk/test/Index/c-index-getCursor-test.m
cfe/trunk/test/Index/get-cursor-macro-args.m
cfe/trunk/test/Index/get-cursor.cpp
cfe/trunk/test/Preprocessor/ignore-pragmas.c
cfe/trunk/unittests/Tooling/TestVisitor.h
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=320391=320390=320391=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Dec 11 09:36:42 2017
@@ -769,6 +769,8 @@ def token_cache : Separate<["-"], "token
   HelpText<"Use specified token cache file">;
 def detailed_preprocessing_record : Flag<["-"], 
"detailed-preprocessing-record">,
   HelpText<"include a detailed record of preprocessing actions">;
+def fsystem_include_if_exists : Separate<["-"], "fsystem-include-if-exists">, 
MetaVarName<"">,
+  HelpText<"Include system file before parsing if file exists">;
 
 
//===--===//
 // OpenCL Options

Modified: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorOptions.h?rev=320391=320390=320391=diff
==
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h Mon Dec 11 09:36:42 2017
@@ -60,6 +60,9 @@ public:
   /// \brief Headers that will be converted to chained PCHs in memory.
   std::vector ChainedIncludes;
 
+  /// \brief System Headers that are pre-included if they exist.
+  std::vector FSystemIncludeIfExists;
+
   /// \brief When true, disables most of the normal validation performed on
   /// precompiled headers.
   bool DisablePCHValidation = false;
@@ -183,6 +186,7 @@ public:
 DumpDeserializedPCHDecls = false;
 ImplicitPCHInclude.clear();
 ImplicitPTHInclude.clear();
+FSystemIncludeIfExists.clear();
 TokenCache.clear();
 SingleFileParseMode = false;
 LexEditorPlaceholders = true;

Modified: cfe/trunk/lib/Driver/Job.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Job.cpp?rev=320391=320390=320391=diff
==
--- cfe/trunk/lib/Driver/Job.cpp (original)
+++ cfe/trunk/lib/Driver/Job.cpp Mon Dec 11 09:36:42 2017
@@ -64,7 +64,7 @@ static bool skipArgs(const char *Flag, b
 .Cases("-internal-externc-isystem", "-iprefix", true)
 .Cases("-iwithprefixbefore", "-isystem", "-iquote", true)
 .Cases("-isysroot", "-I", "-F", "-resource-dir", true)
-.Cases("-iframework", "-include-pch", true)
+.Cases("-iframework", "-include-pch", "-fsystem-include-if-exists", true)
 .Default(false);
   if (IsInclude)
 return HaveCrashVFS ? false : true;

Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp
URL: 

Re: r320297 - Fix MSVC 'not all control paths return a value' warning

2017-12-11 Thread Alex L via cfe-commits
Thanks!

On 10 December 2017 at 03:05, Simon Pilgrim via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rksimon
> Date: Sun Dec 10 03:05:14 2017
> New Revision: 320297
>
> URL: http://llvm.org/viewvc/llvm-project?rev=320297=rev
> Log:
> Fix MSVC 'not all control paths return a value' warning
>
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/
> ToolChains/Darwin.cpp?rev=320297=320296=320297=diff
> 
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Sun Dec 10 03:05:14 2017
> @@ -1230,6 +1230,7 @@ struct DarwinPlatform {
>  case DeploymentTargetEnv:
>return (llvm::Twine(EnvVarName) + "=" + OSVersion).str();
>  }
> +llvm_unreachable("Unsupported Darwin Source Kind");
>}
>
>static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D40746: Correctly handle line table entries without filenames during AST serialization

2017-12-11 Thread Hans Wennborg via cfe-commits
+Tom

I expect it's too late since 5.0.1 is virtually out the door already.

On Mon, Dec 11, 2017 at 2:35 AM, Ivan Donchevskii via Phabricator <
revi...@reviews.llvm.org> wrote:

> yvvan added a comment.
>
> Can we still have it in 5.0?
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D40746
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40485: [clangd] Introduced a Context that stores implicit data

2017-12-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

Thanks, this looks like exactly the right amount of magic to me :-)




Comment at: clangd/Context.h:91
+  /// functions that require a context when no explicit context is available.
+  static const Context ();
+

as discussed offline, this could also return a value, which might make some use 
cases (testing) slightly cleaner. Up to you



Comment at: clangd/Context.h:109
+  template  const Type *get(const Key ) const {
+const ContextData *DataPtr = this->DataPtr.get();
+while (DataPtr != nullptr) {

nit: this is a for loop in disguise :-)



Comment at: clangd/Context.h:131
+  template 
+  Context derive(const Key , Args &&... As) const & {
+return Context(std::make_shared(ContextData{

I'd find the interface (and in particular the error messages) here easier to 
understand if we took a `Type` by value, rather than having `emplace` semantics.

If this function took a `Type`, and `TypedAnyStorage` took a `Type&&`, the cost 
would be one extra move, which doesn't seem too bad.

Up to you, though. (If you change it, don't forget the other `derive` overload)



Comment at: clangd/Context.h:168
+
+  struct ContextData {
+// We need to make sure Parent outlives the Value, so the order of members

nit: now this is private it could just be called Data



Comment at: clangd/Context.h:169
+  struct ContextData {
+// We need to make sure Parent outlives the Value, so the order of members
+// is important. We do that to allow classes stored in Context's child

Is this comment still true/relevant?
I thought the motivating case was Span, but Span now stores a copy of the 
parent pointer (and ContextData isn't accessible by it).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40485



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


[PATCH] D40548: [clangd] Symbol index interfaces and index-based code completion.

2017-12-11 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/ClangdIndex.h:1
+//===--- ClangdIndex.h - Symbol indexes for clangd.---*- 
C++-*-===//
+//

sammccall wrote:
> nit: `Clangd` prefix doesn't do much.
> I'd suggest `Index.h` for the interface (including Symbol), and `MemIndex.h` 
> for the in-memory implementations?
I'll do the renaming when D40897  is landed since it defines Symbol and would 
probably create `Index.h` as well.



Comment at: clangd/ClangdIndex.h:50
+// relatively small symbol table built offline.
+class InMemoryIndexSourcer {
+public:

sammccall wrote:
> As discussed offline - the lifetime of the contained symbols and the 
> operations on the index derived from it need to be carefully considered.
> 
> Involving inheritance here seems likely to make these tricky interactions 
> even trickier.
> 
> Would suggest:
>  - a concrete class (`SymbolCache`? `FileSymbols`?) to hold a collection of 
> symbols from multiple files, with the ability to iterate over them and 
> replace all the symbols from one file at once
>  - a concrete class `MemIndex` that can be constructed from a sequence of 
> symbols and implements `Index`
> 
> You probably want to make them both immutable with snapshot semantics, or 
> have a reader-writer lock that spans both.
The current revision implements a `FileSymbols` with the snapshot semantics. 
Not entirely sure if this is what you are looking for. Let me know...



Comment at: clangd/ClangdIndex.h:72
+   /// collected.
+   void update(PathRef Path, ASTContext ,
+   std::shared_ptr PP,

sammccall wrote:
> The AST -> symbol conversion doesn't seem to have much to do with the rest of 
> the class - we can move this to a free function I think, which would give the 
> class a narrower responsibility.
Moved the conversion code to ClangdUnit.cpp



Comment at: clangd/CodeComplete.cpp:378
+// FIXME: output a warning to logger if there are results from sema.
+return qualifiedIdCompletionWithIndex(*Index, S, **OptSS, );
+  }

sammccall wrote:
> I don't like the idea of doing index lookups from the middle of a sema 
> callback!
> 
> Can we just record the CCContext  in the Collector instead, and do this work 
> afterwards?
Good point!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40548



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


[PATCH] D40548: [clangd] Symbol index interfaces and index-based code completion.

2017-12-11 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 126379.
ioeric marked 8 inline comments as done.
ioeric added a comment.

- Address review comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40548

Files:
  clangd/CMakeLists.txt
  clangd/ClangdIndex.cpp
  clangd/ClangdIndex.h
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Symbol.cpp
  clangd/Symbol.h
  clangd/SymbolCompletionInfo.cpp
  clangd/SymbolCompletionInfo.h
  clangd/SymbolIndex.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/CMakeLists.txt
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- /dev/null
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -0,0 +1,110 @@
+//===-- SymbolCollectorTests.cpp  ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Symbol.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include 
+#include 
+
+using testing::ElementsAre;
+using testing::Eq;
+using testing::Field;
+
+namespace clang {
+namespace clangd {
+
+namespace {
+class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
+ public:
+  SymbolIndexActionFactory() = default;
+
+  clang::FrontendAction *create() override {
+index::IndexingOptions IndexOpts;
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;
+Collector = std::make_shared();
+FrontendAction *Action =
+index::createIndexingAction(Collector, IndexOpts, nullptr).release();
+return Action;
+  }
+
+  std::shared_ptr Collector;
+};
+
+class SymbolCollectorTest : public ::testing::Test {
+public:
+  bool runSymbolCollector(StringRef HeaderCode, StringRef MainCode) {
+llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+new vfs::InMemoryFileSystem);
+llvm::IntrusiveRefCntPtr Files(
+new FileManager(FileSystemOptions(), InMemoryFileSystem));
+
+const std::string FileName = "symbol.cc";
+const std::string HeaderName = "symbols.h";
+auto Factory = llvm::make_unique();
+
+tooling::ToolInvocation Invocation(
+{"symbol_collector", "-fsyntax-only", "-std=c++11", FileName},
+Factory->create(), Files.get(),
+std::make_shared());
+
+InMemoryFileSystem->addFile(HeaderName, 0,
+llvm::MemoryBuffer::getMemBuffer(HeaderCode));
+
+std::string Content = "#include\"" + std::string(HeaderName) + "\"";
+Content += "\n" + MainCode.str();
+InMemoryFileSystem->addFile(FileName, 0,
+llvm::MemoryBuffer::getMemBuffer(Content));
+Invocation.run();
+Symbols = Factory->Collector->getSymbols();
+return true;
+  }
+
+protected:
+  std::set Symbols;
+};
+
+TEST_F(SymbolCollectorTest, CollectSymbol) {
+  const std::string Header = R"(
+class Foo {
+ void f();
+};
+void f1();
+inline void f2() {}
+  )";
+  const std::string Main = R"(
+namespace {
+void ff() {} // ignore
+}
+void f1() {}
+  )";
+  runSymbolCollector(Header, Main);
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAre(Field(::QualifiedName, Eq("Foo")),
+   Field(::QualifiedName, Eq("Foo::f")),
+   Field(::QualifiedName, Eq("f1")),
+   Field(::QualifiedName, Eq("f2";
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: unittests/clangd/CMakeLists.txt
===
--- unittests/clangd/CMakeLists.txt
+++ unittests/clangd/CMakeLists.txt
@@ -15,6 +15,7 @@
   JSONExprTests.cpp
   TestFS.cpp
   TraceTests.cpp
+  SymbolCollectorTests.cpp
   )
 
 target_link_libraries(ClangdTests
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -90,6 +90,15 @@
 "Trace internal events and timestamps in chrome://tracing JSON format"),
 llvm::cl::init(""), llvm::cl::Hidden);
 

[PATCH] D40486: [clangd] Implemented logging using Context

2017-12-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdServer.cpp:36
 
-  ~FulfillPromiseGuard() { Promise.set_value(); }
+  ~FulfillContextPromiseGuard() { Promise.set_value(std::move(Ctx)); }
 

sammccall wrote:
> Yikes, I can see how we got here, but we really don't get to move out of 
> something we received an lvalue-reference to...
> 
> I think a safer idiom here is turning a whole lambda into a destructor:
> 
>auto Fulfil = MakeDestructor([&]{
>   DonePromise.set_value(std::move(Ctx));
>});
> 
> I'm not sure if LLVM has a shared utility for this, I've seen it in other 
> codebases. Either way we could just define it here.
> 
> (Or we could copy the context to avoid the awkwardness)
Thanks for suggestion. I totally agree, callbacks on scope exit are better.

I couldn't find an utility like that in LLVM, but I think it's a useful one. 
I'll add this locally to this file, but maybe we should make this helper public 
and put it into clangd?
What are you thoughts on that?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40486



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


[PATCH] D41056: [clang-tidy] New check misc-uniqueptr-release-unused-retval

2017-12-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D41056#951083, @alexfh wrote:

> In https://reviews.llvm.org/D41056#950605, @khuttun wrote:
>
> > In https://reviews.llvm.org/D41056#950570, @Eugene.Zelenko wrote:
> >
> > > May be //bugprone// is better module then //misc//?
> >
> >
> > Maybe. I can move it if all the reviewers think that it would be better 
> > suited there.
>
>
> Yup, bugprone- should be a better category for this, IMO.
>
> I wonder whether libc++ folks are interested in marking unique_ptr::release() 
> with `__attribute__ ((warn_unused_result))`. A compiler warning (with 
> -Werror) would be a better protection against this kind of a bug.


There's a push in WG21 to mark more of the library with `[[nodiscard]]`: 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0600r1.pdf

If we have a check for this, I do not think it should be specific to 
`unique_ptr::release()`, but instead be more broadly applicable to APIs that 
should be marked `[[nodiscard]]` but are not (currently). P0600R1 is a good 
place to start, but I'm guessing there are POSIX APIs (among others) that would 
also qualify.


Repository:
  rL LLVM

https://reviews.llvm.org/D41056



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


[PATCH] D40897: [clangd] Introduce a "Symbol" class.

2017-12-11 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 126378.
hokein marked 5 inline comments as done.
hokein added a comment.

Address comments on SymbolID.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40897

Files:
  clangd/CMakeLists.txt
  clangd/index/CMakeLists.txt
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolCollector.h
  unittests/clangd/CMakeLists.txt
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- /dev/null
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -0,0 +1,112 @@
+//===-- SymbolCollectorTests.cpp  ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "index/SymbolCollector.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include 
+#include 
+
+using testing::UnorderedElementsAre;
+using testing::Eq;
+using testing::Field;
+
+// GMock helpers for matching Symbol.
+MATCHER_P(QName, Name, "") { return arg.second.QualifiedName == Name; }
+
+namespace clang {
+namespace clangd {
+
+namespace {
+class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
+ public:
+  SymbolIndexActionFactory() = default;
+
+  clang::FrontendAction *create() override {
+index::IndexingOptions IndexOpts;
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;
+Collector = std::make_shared();
+FrontendAction *Action =
+index::createIndexingAction(Collector, IndexOpts, nullptr).release();
+return Action;
+  }
+
+  std::shared_ptr Collector;
+};
+
+class SymbolCollectorTest : public ::testing::Test {
+public:
+  bool runSymbolCollector(StringRef HeaderCode, StringRef MainCode) {
+llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+new vfs::InMemoryFileSystem);
+llvm::IntrusiveRefCntPtr Files(
+new FileManager(FileSystemOptions(), InMemoryFileSystem));
+
+const std::string FileName = "symbol.cc";
+const std::string HeaderName = "symbols.h";
+auto Factory = llvm::make_unique();
+
+tooling::ToolInvocation Invocation(
+{"symbol_collector", "-fsyntax-only", "-std=c++11", FileName},
+Factory->create(), Files.get(),
+std::make_shared());
+
+InMemoryFileSystem->addFile(HeaderName, 0,
+llvm::MemoryBuffer::getMemBuffer(HeaderCode));
+
+std::string Content = "#include\"" + std::string(HeaderName) + "\"";
+Content += "\n" + MainCode.str();
+InMemoryFileSystem->addFile(FileName, 0,
+llvm::MemoryBuffer::getMemBuffer(Content));
+Invocation.run();
+Symbols = Factory->Collector->takeSymbols();
+
+EXPECT_EQ(FileName, Factory->Collector->getFilename());
+return true;
+  }
+
+protected:
+  SymbolSlab Symbols;
+};
+
+TEST_F(SymbolCollectorTest, CollectSymbol) {
+  const std::string Header = R"(
+class Foo {
+  void f();
+};
+void f1();
+inline void f2() {}
+  )";
+  const std::string Main = R"(
+namespace {
+void ff() {} // ignore
+}
+void f1() {}
+  )";
+  runSymbolCollector(Header, Main);
+  EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo"), QName("Foo::f"),
+QName("f1"), QName("f2")));
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: unittests/clangd/CMakeLists.txt
===
--- unittests/clangd/CMakeLists.txt
+++ unittests/clangd/CMakeLists.txt
@@ -15,12 +15,14 @@
   JSONExprTests.cpp
   TestFS.cpp
   TraceTests.cpp
+  SymbolCollectorTests.cpp
   )
 
 target_link_libraries(ClangdTests
   PRIVATE
   clangBasic
   clangDaemon
+  clangdIndex
   clangFormat
   clangFrontend
   clangSema
Index: clangd/index/SymbolCollector.h
===
--- /dev/null
+++ clangd/index/SymbolCollector.h
@@ -0,0 +1,52 @@
+//===--- SymbolCollector.h ---*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//

[PATCH] D40485: [clangd] Introduced a Context that stores implicit data

2017-12-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as done.
ilya-biryukov added inline comments.



Comment at: clangd/Context.h:65
+  Context *Parent;
+  TypedValueMap Data;
+};

klimek wrote:
> sammccall wrote:
> > ilya-biryukov wrote:
> > > sammccall wrote:
> > > > ilya-biryukov wrote:
> > > > > sammccall wrote:
> > > > > > We add complexity here (implementation and conceptual) to allow 
> > > > > > multiple properties to be set at the same level (vs having a key 
> > > > > > and an AnyStorage and making Context a linked list).
> > > > > > Is this for performance? I'm not convinced it'll actually be faster 
> > > > > > for our workloads, or that it matters.
> > > > > Conceptually, a `Context` is more convenient to use when it stores 
> > > > > multiple values. This allows to put a bunch of things and assign 
> > > > > meaning to `Context` (i.e., a `Context` for processing a single LSP 
> > > > > request, global context). If `Context`s were a linked list, the 
> > > > > intermediate `Context`s would be hard to assign the meaning to.
> > > > > 
> > > > > That being said, storage strategy for `Context`s is an implementation 
> > > > > detail and could be changed anytime. I don't have big preferences 
> > > > > here, but I think that storing a linked list of maps has, in general, 
> > > > > a better performance than storing a linked list.
> > > > > And given that it's already there, I'd leave it this way.
> > > > With the new shared_ptr semantics:
> > > > 
> > > >  Context D = move(C).derive(K1, V1).derive(K2, V2);
> > > > 
> > > > Is just as meaningful as
> > > > 
> > > > Context D = move(C).derive().add(K1, V1).add(K2, V2);
> > > > 
> > > > Yeah, the list of maps in an implementation detail. It's one that comes 
> > > > with a bunch of complexity (`ContextBuilder` and most of 
> > > > `TypedValueMap`). It really doesn't seem to buy us anything (the 
> > > > performance is both uninteresting and seems likely to be worse in this 
> > > > specific case with very few entries). 
> > > The thing I like about it is that the `Context`s are layered properly in 
> > > a sense that there's a Context corresponding to the request, a Context 
> > > corresponding to the forked subrequests, etc.
> > > If we change the interface, we'll be creating a bunch of temporary 
> > > Contexts that don't correspond to a nice meaningful abstraction (like 
> > > request) in my head, even though we don't give those contexts any names.
> > > 
> > > I do agree we currently pay with some complexity for that. Though I'd 
> > > argue it's all hidden from the users of the interface, as building and 
> > > consuming contexts is still super-easy and you don't need to mention 
> > > ContextBuilder or TypedValueMap. And the implementation complexity is 
> > > totally manageable from my point of view, but I am the one who 
> > > implemented it in the first place, so there's certainly a bias there.
> > I don't see temporary unnamed `Context`s being any different from temporary 
> > unnamed `ContextBuilder`s.
> > 
> > But we've gone around on this point a bit, and this really seems to be a 
> > question of taste. @klimek, can we have a third opinion?
> > 
> > The options we're looking at are:
> >   - `Context` stores a map and a parent pointer. `derive()` returns a 
> > `ContextBuilder` used to create new contexts containing 0 or more new KV 
> > pairs. `TypedValueMap` stores the payloads.
> >   - `Context` stores a single KV pair and a parent pointer. `derive(K, V)` 
> > is used to create a new context with one new KV pair. A Key-pointer and 
> > AnyStorage in `Context` store the payloads, the rest of `TypedValueMap` 
> > goes away.
> I'd agree that Context::derive(K, V) would be simpler here, mainly because 
> there is only one way to pass around contexts while we're building them up; 
> specifically, there's no temptation to pass around ContextBuilders.
Done. `ContextBuilder` and `TypedValueMap` are now removed.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40485



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


[PATCH] D40488: [clangd] Implemented tracing using Context

2017-12-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 126376.
ilya-biryukov added a comment.

- Use derive(key, value) instead of derive().add(key, value).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40488

Files:
  clangd/ClangdUnit.cpp
  clangd/JSONRPCDispatcher.cpp
  clangd/Trace.cpp
  clangd/Trace.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/TraceTests.cpp

Index: unittests/clangd/TraceTests.cpp
===
--- unittests/clangd/TraceTests.cpp
+++ unittests/clangd/TraceTests.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "Context.h"
 #include "Trace.h"
 
 #include "llvm/ADT/DenseMap.h"
@@ -74,10 +75,11 @@
   std::string JSON;
   {
 raw_string_ostream OS(JSON);
-auto Session = trace::Session::create(OS);
+auto JSONTracer = trace::createJSONTracer(OS);
+trace::TracingSession Session(*JSONTracer);
 {
-  trace::Span S("A");
-  trace::log("B");
+  trace::Span S(Context::empty(), "A");
+  trace::log(Context::empty(), "B");
 }
   }
 
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -115,19 +115,25 @@
<< EC.message();
 }
   }
+
+  // Setup tracing facilities.
   llvm::Optional TraceStream;
-  std::unique_ptr TraceSession;
+  std::unique_ptr Tracer;
   if (!TraceFile.empty()) {
 std::error_code EC;
 TraceStream.emplace(TraceFile, /*ref*/ EC, llvm::sys::fs::F_RW);
 if (EC) {
   TraceFile.reset();
   llvm::errs() << "Error while opening trace file: " << EC.message();
 } else {
-  TraceSession = trace::Session::create(*TraceStream, PrettyPrint);
+  Tracer = trace::createJSONTracer(*TraceStream, PrettyPrint);
 }
   }
 
+  llvm::Optional TracingSession;
+  if (Tracer)
+TracingSession.emplace(*Tracer);
+
   llvm::raw_ostream  = llvm::outs();
   llvm::raw_ostream  = llvm::errs();
   JSONOutput Out(Outs, Logs,
Index: clangd/Trace.h
===
--- clangd/Trace.h
+++ clangd/Trace.h
@@ -8,60 +8,74 @@
 //===--===//
 //
 // Supports writing performance traces describing clangd's behavior.
-// Traces are written in the Trace Event format supported by chrome's trace
-// viewer (chrome://tracing).
+// Traces are consumed by implementations of the EventTracer interface.
 //
-// The format is documented here:
-// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
 //
 // All APIs are no-ops unless a Session is active (created by ClangdMain).
 //
 //===--===//
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRACE_H_
 
+#include "Context.h"
 #include "JSONExpr.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
 namespace trace {
 
-// A session directs the output of trace events. Only one Session can exist.
-// It should be created before clangd threads are spawned, and destroyed after
-// they exit.
-// TODO: we may want to add pluggable support for other tracing backends.
-class Session {
+/// A consumer of trace events. The events are produced by Spans and trace::log.
+class EventTracer {
 public:
-  // Starts a sessions capturing trace events and writing Trace Event JSON.
-  static std::unique_ptr create(llvm::raw_ostream ,
- bool Pretty = false);
-  ~Session();
+  virtual ~EventTracer() = default;
+  /// Consume a trace event.
+  virtual void event(const Context , llvm::StringRef Phase,
+ json::obj &) = 0;
+};
 
-private:
-  Session() = default;
+/// Sets up a global EventTracer that consumes events produced by Span and
+/// trace::log. Only one TracingSession can be active at a time and it should be
+/// set up before calling any clangd-specific functions.
+class TracingSession {
+public:
+  TracingSession(EventTracer );
+  ~TracingSession();
 };
 
-// Records a single instant event, associated with the current thread.
-void log(const llvm::Twine );
+/// Create an instance of EventTracer that produces an output in the Trace Event
+/// format supported by Chrome's trace viewer (chrome://tracing).
+///
+/// The format is documented here:
+/// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
+///
+/// The implementation supports concurrent calls and can be used as a global
+/// tracer (i.e., can be put into a global Context).
+std::unique_ptr createJSONTracer(llvm::raw_ostream ,
+  bool Pretty = false);
 
-// Records an event whose duration is the lifetime of the Span object.
-//
-// Arbitrary JSON 

[PATCH] D40486: [clangd] Implemented logging using Context

2017-12-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 126375.
ilya-biryukov added a comment.

- Use derive(key, val) instead of derive().add(key, val).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40486

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  clangd/JSONRPCDispatcher.cpp
  clangd/JSONRPCDispatcher.h
  clangd/Logger.cpp
  clangd/Logger.h
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -8,6 +8,7 @@
 //===--===//
 #include "ClangdServer.h"
 #include "Compiler.h"
+#include "Context.h"
 #include "Protocol.h"
 #include "TestFS.h"
 #include "gtest/gtest.h"
@@ -17,6 +18,10 @@
 namespace {
 using namespace llvm;
 
+/// Creates an empty context that is used for running async methods inside the
+/// testing code.
+Context testCtx() { return Context::empty().clone(); }
+
 class IgnoreDiagnostics : public DiagnosticsConsumer {
   void onDiagnosticsReady(
   PathRef File, Tagged Diagnostics) override {}
@@ -74,8 +79,7 @@
   MockCompilationDatabase CDB;
 
   ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
-  /*StorePreamblesInMemory=*/true,
-  EmptyLogger::getInstance());
+  /*StorePreamblesInMemory=*/true);
 
   auto FooCpp = getVirtualTestFilePath("foo.cpp");
   const auto SourceContents = R"cpp(
@@ -101,29 +105,33 @@
 
   // No need to sync reparses here as there are no asserts on diagnostics (or
   // other async operations).
-  Server.addDocument(FooCpp, SourceContents);
+  Server.addDocument(FooCpp, SourceContents, testCtx());
 
   {
 auto CodeCompletionResults1 =
-Server.codeComplete(FooCpp, CompletePos, CCOpts, None).get().Value;
+Server.codeComplete(FooCpp, CompletePos, CCOpts, testCtx(), None)
+.get()
+.first.Value;
 EXPECT_TRUE(ContainsItem(CodeCompletionResults1, "aba"));
 EXPECT_FALSE(ContainsItem(CodeCompletionResults1, "cbc"));
   }
 
   {
 auto CodeCompletionResultsOverriden =
 Server
-.codeComplete(FooCpp, CompletePos, CCOpts,
+.codeComplete(FooCpp, CompletePos, CCOpts, testCtx(),
   StringRef(OverridenSourceContents))
 .get()
-.Value;
+.first.Value;
 EXPECT_TRUE(ContainsItem(CodeCompletionResultsOverriden, "cbc"));
 EXPECT_FALSE(ContainsItem(CodeCompletionResultsOverriden, "aba"));
   }
 
   {
 auto CodeCompletionResults2 =
-Server.codeComplete(FooCpp, CompletePos, CCOpts, None).get().Value;
+Server.codeComplete(FooCpp, CompletePos, CCOpts, testCtx(), None)
+.get()
+.first.Value;
 EXPECT_TRUE(ContainsItem(CodeCompletionResults2, "aba"));
 EXPECT_FALSE(ContainsItem(CodeCompletionResults2, "cbc"));
   }
@@ -135,8 +143,7 @@
   CDB.ExtraClangFlags.push_back("-xc++");
   IgnoreDiagnostics DiagConsumer;
   ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
-  /*StorePreamblesInMemory=*/true,
-  EmptyLogger::getInstance());
+  /*StorePreamblesInMemory=*/true);
 
   auto FooCpp = getVirtualTestFilePath("foo.cpp");
   FS.Files[FooCpp] = "";
@@ -150,17 +157,17 @@
 int main() { ClassWithMembers().{complete} }
   )cpp",
  "complete");
-  Server.addDocument(FooCpp, Completion.Text);
+  Server.addDocument(FooCpp, Completion.Text, testCtx());
 
   clangd::CodeCompleteOptions Opts;
   Opts.Limit = 2;
 
   /// For after-dot completion we must always get consistent results.
   auto Results = Server
  .codeComplete(FooCpp, Completion.MarkerPos, Opts,
-   StringRef(Completion.Text))
+   testCtx(), StringRef(Completion.Text))
  .get()
- .Value;
+ .first.Value;
 
   EXPECT_TRUE(Results.isIncomplete);
   EXPECT_EQ(Opts.Limit, Results.items.size());
@@ -175,8 +182,7 @@
   CDB.ExtraClangFlags.push_back("-xc++");
   IgnoreDiagnostics DiagConsumer;
   ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
-  /*StorePreamblesInMemory=*/true,
-  EmptyLogger::getInstance());
+  

[PATCH] D40485: [clangd] Introduced a Context that stores implicit data

2017-12-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 126373.
ilya-biryukov added a comment.

- Removed ContextBuilder and TypedValueMap.
- Updated the docs.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40485

Files:
  clangd/CMakeLists.txt
  clangd/Context.cpp
  clangd/Context.h
  unittests/clangd/CMakeLists.txt
  unittests/clangd/ContextTests.cpp

Index: unittests/clangd/ContextTests.cpp
===
--- /dev/null
+++ unittests/clangd/ContextTests.cpp
@@ -0,0 +1,57 @@
+//===-- ContextTests.cpp - Context tests *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Context.h"
+
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+
+TEST(ContextTests, Simple) {
+  Key IntParam;
+  Key ExtraIntParam;
+
+  Context Ctx = Context::empty().derive(IntParam, 10).derive(ExtraIntParam, 20);
+
+  EXPECT_EQ(*Ctx.get(IntParam), 10);
+  EXPECT_EQ(*Ctx.get(ExtraIntParam), 20);
+}
+
+TEST(ContextTests, MoveOps) {
+  Key Param;
+
+  Context Ctx = Context::empty().derive(Param, llvm::make_unique(10));
+  EXPECT_EQ(**Ctx.get(Param), 10);
+
+  Context NewCtx = std::move(Ctx);
+  EXPECT_EQ(**NewCtx.get(Param), 10);
+}
+
+TEST(ContextTests, Builders) {
+  Key ParentParam;
+  Key ParentAndChildParam;
+  Key ChildParam;
+
+  Context ParentCtx =
+  Context::empty().derive(ParentParam, 10).derive(ParentAndChildParam, 20);
+  Context ChildCtx =
+  ParentCtx.derive(ParentAndChildParam, 30).derive(ChildParam, 40);
+
+  EXPECT_EQ(*ParentCtx.get(ParentParam), 10);
+  EXPECT_EQ(*ParentCtx.get(ParentAndChildParam), 20);
+  EXPECT_EQ(ParentCtx.get(ChildParam), nullptr);
+
+  EXPECT_EQ(*ChildCtx.get(ParentParam), 10);
+  EXPECT_EQ(*ChildCtx.get(ParentAndChildParam), 30);
+  EXPECT_EQ(*ChildCtx.get(ChildParam), 40);
+}
+
+} // namespace clangd
+} // namespace clang
Index: unittests/clangd/CMakeLists.txt
===
--- unittests/clangd/CMakeLists.txt
+++ unittests/clangd/CMakeLists.txt
@@ -11,6 +11,7 @@
 add_extra_unittest(ClangdTests
   ClangdTests.cpp
   CodeCompleteTests.cpp
+  ContextTests.cpp
   FuzzyMatchTests.cpp
   JSONExprTests.cpp
   TestFS.cpp
Index: clangd/Context.h
===
--- /dev/null
+++ clangd/Context.h
@@ -0,0 +1,183 @@
+//===--- Context.h - Mechanism for passing implicit data *- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Context for storing and retrieving implicit data. Useful for passing implicit
+// parameters on a per-request basis.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CONTEXT_H_
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CONTEXT_H_
+
+#include "llvm/ADT/STLExtras.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// A key for a value of type \p Type, stored inside a context. Keys are
+/// non-movable and non-copyable. See documentation of the Context class for
+/// more details and usage examples.
+template  class Key {
+public:
+  static_assert(!std::is_reference::value,
+"Reference arguments to Key<> are not allowed");
+
+  Key() = default;
+
+  Key(Key const &) = delete;
+  Key =(Key const &) = delete;
+  Key(Key &&) = delete;
+  Key =(Key &&) = delete;
+};
+
+/// A context is an immutable container for per-request data that must be
+/// propagated through layers that don't care about it. An example is a request
+/// ID that we may want to use when logging.
+///
+/// Conceptually, a context is a heterogeneous map. Each key has
+/// an associated value type, which allows the map to be typesafe.
+///
+/// You can't add data to an existing context, instead you create a new
+/// immutable context derived from it with extra data added. When you retrieve
+/// data, the context will walk up the parent chain until the key is found.
+///
+/// Contexts should be:
+///  - passed by reference when calling synchronous functions
+///  - passed by value (move) when calling asynchronous functions. The result
+///callback of async operations will receive the context again.
+///  - cloned only when 'forking' an asynchronous computation that we don't wait
+///for.
+///
+/// Copy operations for this class are deleted, use an explicit clone() method
+/// when you need a copy of the context instead.
+///
+/// To derive a child context use derive() function, e.g.
+/// 

[PATCH] D38425: [clangd] Document highlights for clangd

2017-12-11 Thread William Enright via Phabricator via cfe-commits
Nebiroth updated this revision to Diff 126371.
Nebiroth marked 3 inline comments as done.
Nebiroth added a comment.
Herald added a subscriber: mgrang.

Merged with latest llvm/clang
Minor code cleanup


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38425

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  test/clangd/documenthighlight.test
  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
@@ -20,6 +20,7 @@
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "definitionProvider": true,
 # CHECK-NEXT:  "documentFormattingProvider": true,
+# CHECK-NEXT:  "documentHighlightProvider": true,
 # CHECK-NEXT:  "documentOnTypeFormattingProvider": {
 # CHECK-NEXT:"firstTriggerCharacter": "}",
 # CHECK-NEXT:"moreTriggerCharacter": []
Index: test/clangd/initialize-params-invalid.test
===
--- test/clangd/initialize-params-invalid.test
+++ test/clangd/initialize-params-invalid.test
@@ -20,6 +20,7 @@
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "definitionProvider": true,
 # CHECK-NEXT:  "documentFormattingProvider": true,
+# CHECK-NEXT:  "documentHighlightProvider": true,
 # CHECK-NEXT:  "documentOnTypeFormattingProvider": {
 # CHECK-NEXT:"firstTriggerCharacter": "}",
 # CHECK-NEXT:"moreTriggerCharacter": []
Index: test/clangd/documenthighlight.test
===
--- /dev/null
+++ test/clangd/documenthighlight.test
@@ -0,0 +1,42 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+
+Content-Length: 479
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"#define MACRO 1\nnamespace ns1 {\nstruct MyClass {\nint xasd;\nvoid anotherOperation() {\n}\nstatic int foo(MyClass*) {\nreturn 0;\n}\n\n};\nstruct Foo {\nint xasd;\n};\n}\nint main() {\nint bonjour;\nbonjour = 2;\nint test1 = bonjour;\nns1::Foo bar = { xasd : 1};\nbar.xasd = 3;\nns1::MyClass* Params;\nParams->anotherOperation();\n}\n"}}}
+
+Content-Length: 156
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":17,"character":2}}}
+# Verify local variable 
+# CHECK: {"id":1,"jsonrpc":"2.0","result":[{"kind":1,"range":{"end":{"character":11,"line":16},"start":{"character":4,"line":16}}},{"kind":3,"range":{"end":{"character":7,"line":17},"start":{"character":0,"line":17}}},{"kind":2,"range":{"end":{"character":19,"line":18},"start":{"character":12,"line":18}}}]}
+
+Content-Length: 157
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":18,"character":17}}}
+# Verify struct highlight
+# CHECK: {"id":1,"jsonrpc":"2.0","result":[{"kind":1,"range":{"end":{"character":11,"line":16},"start":{"character":4,"line":16}}},{"kind":3,"range":{"end":{"character":7,"line":17},"start":{"character":0,"line":17}}},{"kind":2,"range":{"end":{"character":19,"line":18},"start":{"character":12,"line":18}}}]}
+
+Content-Length: 157
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":21,"character":10}}}
+# Verify method highlight
+# CHECK: {"id":1,"jsonrpc":"2.0","result":[{"kind":1,"range":{"end":{"character":14,"line":2},"start":{"character":7,"line":2}}},{"kind":1,"range":{"end":{"character":22,"line":6},"start":{"character":15,"line":6}}},{"kind":1,"range":{"end":{"character":12,"line":21},"start":{"character":5,"line":21}}}]}
+
+Content-Length: 157
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":18,"character":14}}}
+# Verify Read-access of a symbol (kind = 2) 
+# CHECK: {"id":1,"jsonrpc":"2.0","result":[{"kind":1,"range":{"end":{"character":11,"line":16},"start":{"character":4,"line":16}}},{"kind":3,"range":{"end":{"character":7,"line":17},"start":{"character":0,"line":17}}},{"kind":2,"range":{"end":{"character":19,"line":18},"start":{"character":12,"line":18}}}]}
+
+Content-Length: 48
+
+{"jsonrpc":"2.0","id":1,"method":"shutdown"}
+
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
\ No newline at end of file
Index: 

[PATCH] D41056: [clang-tidy] New check misc-uniqueptr-release-unused-retval

2017-12-11 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D41056#950605, @khuttun wrote:

> In https://reviews.llvm.org/D41056#950570, @Eugene.Zelenko wrote:
>
> > May be //bugprone// is better module then //misc//?
>
>
> Maybe. I can move it if all the reviewers think that it would be better 
> suited there.


Yup, bugprone- should be a better category for this, IMO.

I wonder whether libc++ folks are interested in marking unique_ptr::release() 
with `__attribute__ ((warn_unused_result))`. A compiler warning (with -Werror) 
would be a better protection against this kind of a bug.


Repository:
  rL LLVM

https://reviews.llvm.org/D41056



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


[PATCH] D40860: [clangd] Fix diagnostic positions

2017-12-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Sorry for the delay getting this reviewed.
LG, thanks for fixing this! Just style nits.




Comment at: clang-tools-extra/clangd/ClangdUnit.cpp:124
+/// Convert a clang::SourceLocation to a clangd::Position
+Position SourceLocToClangdPosition(const SourceManager ,
+   SourceLocation Location) {

nit: functions are `lowerCamelCase`.
Here and below.



Comment at: clang-tools-extra/clangd/ClangdUnit.cpp:136
+/// Convert a clang::FullSourceLoc to a clangd::Position
+Position SourceLocToClangdPosition(const FullSourceLoc ) {
+  return SourceLocToClangdPosition(Location.getManager(), Location);

only used once and private - inline this for now?



Comment at: clang-tools-extra/clangd/ClangdUnit.cpp:150
+/// Convert a clang::CharSourceRange to a clangd::Range
+Range CharSourceRangeToClangdRange(const SourceManager ,
+   const LangOptions ,

It seems like this could be decomposed into

  - CharSourceRange -> `SourceRange`
  - existing `SourceRangeToClangdRange`

The first probably belongs (or exists) elsewhere in clang, though I can't find 
it - fine to keep it here.



Comment at: clang-tools-extra/test/clangd/diagnostics.test:32
 # CHECK-NEXT:  "end": {
-# CHECK-NEXT:"character": 1,
+# CHECK-NEXT:"character": 0,
 # CHECK-NEXT:"line": 0

Incidentally, these tests seem to be wrong! The ranges shouldn't be empty (at 
least this one).

Unrelated to your patch though, I'll look into it separately.


https://reviews.llvm.org/D40860



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


[PATCH] D40485: [clangd] Introduced a Context that stores implicit data

2017-12-11 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: clangd/Context.h:65
+  Context *Parent;
+  TypedValueMap Data;
+};

sammccall wrote:
> ilya-biryukov wrote:
> > sammccall wrote:
> > > ilya-biryukov wrote:
> > > > sammccall wrote:
> > > > > We add complexity here (implementation and conceptual) to allow 
> > > > > multiple properties to be set at the same level (vs having a key and 
> > > > > an AnyStorage and making Context a linked list).
> > > > > Is this for performance? I'm not convinced it'll actually be faster 
> > > > > for our workloads, or that it matters.
> > > > Conceptually, a `Context` is more convenient to use when it stores 
> > > > multiple values. This allows to put a bunch of things and assign 
> > > > meaning to `Context` (i.e., a `Context` for processing a single LSP 
> > > > request, global context). If `Context`s were a linked list, the 
> > > > intermediate `Context`s would be hard to assign the meaning to.
> > > > 
> > > > That being said, storage strategy for `Context`s is an implementation 
> > > > detail and could be changed anytime. I don't have big preferences here, 
> > > > but I think that storing a linked list of maps has, in general, a 
> > > > better performance than storing a linked list.
> > > > And given that it's already there, I'd leave it this way.
> > > With the new shared_ptr semantics:
> > > 
> > >  Context D = move(C).derive(K1, V1).derive(K2, V2);
> > > 
> > > Is just as meaningful as
> > > 
> > > Context D = move(C).derive().add(K1, V1).add(K2, V2);
> > > 
> > > Yeah, the list of maps in an implementation detail. It's one that comes 
> > > with a bunch of complexity (`ContextBuilder` and most of 
> > > `TypedValueMap`). It really doesn't seem to buy us anything (the 
> > > performance is both uninteresting and seems likely to be worse in this 
> > > specific case with very few entries). 
> > The thing I like about it is that the `Context`s are layered properly in a 
> > sense that there's a Context corresponding to the request, a Context 
> > corresponding to the forked subrequests, etc.
> > If we change the interface, we'll be creating a bunch of temporary Contexts 
> > that don't correspond to a nice meaningful abstraction (like request) in my 
> > head, even though we don't give those contexts any names.
> > 
> > I do agree we currently pay with some complexity for that. Though I'd argue 
> > it's all hidden from the users of the interface, as building and consuming 
> > contexts is still super-easy and you don't need to mention ContextBuilder 
> > or TypedValueMap. And the implementation complexity is totally manageable 
> > from my point of view, but I am the one who implemented it in the first 
> > place, so there's certainly a bias there.
> I don't see temporary unnamed `Context`s being any different from temporary 
> unnamed `ContextBuilder`s.
> 
> But we've gone around on this point a bit, and this really seems to be a 
> question of taste. @klimek, can we have a third opinion?
> 
> The options we're looking at are:
>   - `Context` stores a map and a parent pointer. `derive()` returns a 
> `ContextBuilder` used to create new contexts containing 0 or more new KV 
> pairs. `TypedValueMap` stores the payloads.
>   - `Context` stores a single KV pair and a parent pointer. `derive(K, V)` is 
> used to create a new context with one new KV pair. A Key-pointer and 
> AnyStorage in `Context` store the payloads, the rest of `TypedValueMap` goes 
> away.
I'd agree that Context::derive(K, V) would be simpler here, mainly because 
there is only one way to pass around contexts while we're building them up; 
specifically, there's no temptation to pass around ContextBuilders.



Comment at: clangd/TypedValueMap.h:38
+
+/// A type-safe map from Key to T.
+class TypedValueMap {

Should we say "from Key*" or &? If you say Key I expect something that 
compares by value.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40485



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


  1   2   >