[PATCH] D31700: [clang-tidy] Ignore blank spaces between cast's ")" and its sub expr.

2017-05-16 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Sorry, missed your patch somehow. LG with one nit.




Comment at: clang-tidy/google/AvoidCStyleCastsCheck.cpp:139
   ")");
+  ReplaceRange = CharSourceRange::getCharRange(CastExpr->getLParenLoc(),
+   SubExpr->getLocStart());

Why is this only done on non-parenthesized expressions? Will `(int)  (b)` turn 
into `static_cast  (b)` as well?


https://reviews.llvm.org/D31700



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


[PATCH] D32524: [clang-format] Fix MatchingOpeningBlockLineIndex computation

2017-05-16 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

I tried to add some test, but could not find a simple way: I could not find any 
'parser' tests from which to start, and I don't see with current master how 
this can be an issue (though it becomes an issue with some of other patches).
Any hint how to implement some test?


https://reviews.llvm.org/D32524



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


r303170 - [Sema] Avoid duplicate -Wunguarded-availability warnings in nested functions

2017-05-16 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue May 16 08:58:53 2017
New Revision: 303170

URL: http://llvm.org/viewvc/llvm-project?rev=303170=rev
Log:
[Sema] Avoid duplicate -Wunguarded-availability warnings in nested functions

rdar://31862310

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/SemaObjC/unguarded-availability.m

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=303170=303169=303170=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue May 16 08:58:53 2017
@@ -7230,6 +7230,13 @@ public:
 SemaRef.Context.getTargetInfo().getPlatformMinVersion());
   }
 
+  bool TraverseDecl(Decl *D) {
+// Avoid visiting nested functions to prevent duplicate warnings.
+if (!D || isa(D))
+  return true;
+return Base::TraverseDecl(D);
+  }
+
   bool TraverseStmt(Stmt *S) {
 if (!S)
   return true;
@@ -7243,6 +7250,8 @@ public:
 
   bool TraverseIfStmt(IfStmt *If);
 
+  bool TraverseLambdaExpr(LambdaExpr *E) { return true; }
+
   bool VisitObjCMessageExpr(ObjCMessageExpr *Msg) {
 if (ObjCMethodDecl *D = Msg->getMethodDecl())
   DiagnoseDeclAvailability(

Modified: cfe/trunk/test/SemaObjC/unguarded-availability.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/unguarded-availability.m?rev=303170=303169=303170=diff
==
--- cfe/trunk/test/SemaObjC/unguarded-availability.m (original)
+++ cfe/trunk/test/SemaObjC/unguarded-availability.m Tue May 16 08:58:53 2017
@@ -8,7 +8,7 @@
 int func_10_11() AVAILABLE_10_11; // expected-note 4 {{'func_10_11' has been 
explicitly marked partial here}}
 
 #ifdef OBJCPP
-// expected-note@+2 2 {{marked partial here}}
+// expected-note@+2 6 {{marked partial here}}
 #endif
 int func_10_12() AVAILABLE_10_12; // expected-note 6 {{'func_10_12' has been 
explicitly marked partial here}}
 
@@ -188,4 +188,19 @@ auto topLevelLambda = [] () {
 func_10_12();
 };
 
+void functionInFunction() {
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 
10.12 or newer}} expected-note{{@available}}
+  struct DontWarnTwice {
+void f() {
+  func_10_12(); // expected-warning{{'func_10_12' is only available on 
macOS 10.12 or newer}} expected-note{{@available}}
+}
+  };
+  void([] () {
+func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 
10.12 or newer}} expected-note{{@available}}
+  });
+  (void)(^ {
+func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 
10.12 or newer}} expected-note{{@available}}
+  });
+}
+
 #endif


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


[PATCH] D32525: [clang-format] Add SpaceBeforeColon option

2017-05-16 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D32525



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


[PATCH] D32477: [clang-format] Allow customizing the penalty for breaking assignment

2017-05-16 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D32477



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


[PATCH] D32480: [clang-format] Add BinPackNamespaces option

2017-05-16 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D32480



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


[PATCH] D32479: [clang-format] Add BreakConstructorInitializersBeforeColon option

2017-05-16 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

Or would it be better to replace (i.e. deprecate) the 
BreakConstructorInitializersBeforeComma option with a multiple choice option, 
as suggested here:
http://clang-developers.42468.n3.nabble.com/clang-format-Proposal-for-a-new-style-for-constructor-and-initializers-line-break-td4041595.html

  /// \brief Different ways to break initializers.
  enum BreakConstructorInitializersStyle
  {
/// Constructor()
/// : initializer1(),
///   initializer2()
BCIS_BeforeColonAfterComma,
/// Constructor()
/// : initializer1()
/// , initializer2()
BCIS_BeforeColonAndComma,
/// Constructor() :
/// initializer1(),
/// initializer2()
BCIS_AfterColonAndComma
  };
  BreakConstructorInitializersStyle BreakConstructorInitializers


https://reviews.llvm.org/D32479



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 13 inline comments as done.
yaxunl added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:7296
+  unsigned getASTAllocaAddressSpace() const override {
+return LangAS::Count + getABIInfo().getDataLayout().getAllocaAddrSpace();
+  }

rjmccall wrote:
> Can we rename LangAS::Count to something more meaningful like 
> LangAS::FirstTargetAddressSpace?  I think this would clarify a lot of code.
> 
> Is the OpenCL special case in ASTContext::getTargetAddressSpace still correct 
> with this patch?  A pointer in LangAS::Default should be lowered as a generic 
> pointer instead of a pointer into the alloca address space, right?
Will do.

The OpenCL special case in ASTContext::getTargetAddressSpace is still correct 
with this patch. In OpenCL private address space is still represented in AST by 
LangAS::Default, so a pointer in LangAS::Default should be lowered as a pointer 
to alloca address space.


https://reviews.llvm.org/D32248



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


[PATCH] D33191: [analyzer] ObjCGenerics: account for __kindof specifiers met along a chain of casts.

2017-05-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 99150.
NoQ added a comment.

Cover more cases and be more conservative.

@Gábor: I didn't want to bother you with this, but i'm not entirely sure about 
how to deal with these false positives; since you're the original author of 
this check, if you see anything obviously wrong here please comment on me :)


https://reviews.llvm.org/D33191

Files:
  lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  test/Analysis/generics.m

Index: test/Analysis/generics.m
===
--- test/Analysis/generics.m
+++ test/Analysis/generics.m
@@ -390,6 +390,39 @@
   [arrayOfStrings containsObject:someString]; // no-warning
 }
 
+NSArray *getStringMutableArray() {
+  NSMutableArray *arr = [[NSMutableArray alloc] init];
+  return arr;
+}
+
+NSArray *getStringMutableArraySpecialized() {
+  NSMutableArray *arr =
+  [[NSMutableArray alloc] init];
+  return arr;
+}
+
+NSArray<__kindof NSString *> *getKindofStringMutableArray() {
+  NSMutableArray *arr = [[NSMutableArray alloc] init];
+  return arr;
+}
+
+NSArray<__kindof NSString *> *getKindofStringMutableArraySpecialized() {
+  NSMutableArray *arr =
+  [[NSMutableArray alloc] init];
+  return arr;
+}
+
+void testKindofPropagation() {
+  NSArray *arr1 =
+  (NSArray *)getKindofStringMutableArray(); // no-warning
+  NSArray *arr2 =
+  (NSArray *)getKindofStringMutableArraySpecialized(); // no-warning
+  NSArray *arr3 =
+  (NSArray *)getStringMutableArray(); // expected-warning{{Conversion from value of type 'NSMutableArray *' to incompatible type 'NSArray *'}}
+  NSArray *arr4 =
+  (NSArray *)getStringMutableArraySpecialized(); // expected-warning{{Conversion from value of type 'NSMutableArray *' to incompatible type 'NSArray *'}}
+}
+
 // CHECK:  diagnostics
 // CHECK-NEXT:  
 // CHECK-NEXT:   
@@ -7140,4 +7173,644 @@
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:path
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line416
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line416
+// CHECK-NEXT:col9
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT: end
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line420
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line420
+// CHECK-NEXT:col9
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT:   
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line420
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line420
+// CHECK-NEXT:col9
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT: end
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line421
+// CHECK-NEXT:col37
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line421
+// CHECK-NEXT:col57
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT:   
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindevent
+// CHECK-NEXT:  location
+// CHECK-NEXT:  
+// CHECK-NEXT:   line421
+// CHECK-NEXT:   col37
+// CHECK-NEXT:   file0
+// CHECK-NEXT:  
+// CHECK-NEXT:  ranges
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  line421
+// CHECK-NEXT:  col37
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  line421
+// CHECK-NEXT:  col59
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT:
+// CHECK-NEXT:  
+// CHECK-NEXT:  depth0
+// CHECK-NEXT:  extended_message
+// CHECK-NEXT:  Calling getStringMutableArray
+// CHECK-NEXT:  message
+// CHECK-NEXT:  Calling getStringMutableArray
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindevent
+// CHECK-NEXT:  location
+// CHECK-NEXT:  
+// CHECK-NEXT:   line393
+// CHECK-NEXT:   col1
+// CHECK-NEXT:   file0

[clang-tools-extra] r303180 - [clang-tidy] Optimize matchers in readability-implicit-bool-cast. NFC

2017-05-16 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue May 16 10:44:42 2017
New Revision: 303180

URL: http://llvm.org/viewvc/llvm-project?rev=303180=rev
Log:
[clang-tidy] Optimize matchers in readability-implicit-bool-cast. NFC

Don't repeat `isInTemplateInstantiation()` and `hasAncestor()` unnecessarily.
This speeds up the check by a factor of up to 3 on some large files.

Modified:
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp?rev=303180=303179=303180=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp 
Tue May 16 10:44:42 2017
@@ -267,10 +267,9 @@ void ImplicitBoolCastCheck::registerMatc
 return;
   }
 
-  auto exceptionCases = expr(
-  anyOf(hasParent(explicitCastExpr()),
-allOf(isMacroExpansion(), unless(isNULLMacroExpansion())),
-isInTemplateInstantiation(), hasAncestor(functionTemplateDecl(;
+  auto exceptionCases =
+  expr(anyOf(hasParent(explicitCastExpr()),
+ allOf(isMacroExpansion(), unless(isNULLMacroExpansion();
   auto implicitCastFromBool = implicitCastExpr(
   unless(exceptionCases),
   anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating),
@@ -285,8 +284,7 @@ void ImplicitBoolCastCheck::registerMatc
   Finder->addMatcher(
   implicitCastExpr(
   // Exclude cases common to implicit cast to and from bool.
-  unless(exceptionCases),
-  unless(has(boolXor)),
+  unless(exceptionCases), unless(has(boolXor)),
   // Exclude case of using if or while statements with variable
   // declaration, e.g.:
   //   if (int var = functionCall()) {}
@@ -298,7 +296,9 @@ void ImplicitBoolCastCheck::registerMatc
 hasCastKind(CK_MemberPointerToBoolean)),
   // Retrive also parent statement, to check if we need additional
   // parens in replacement.
-  anyOf(hasParent(stmt().bind("parentStmt")), anything()))
+  anyOf(hasParent(stmt().bind("parentStmt")), anything()),
+  unless(isInTemplateInstantiation()),
+  unless(hasAncestor(functionTemplateDecl(
   .bind("implicitCastToBool"),
   this);
 
@@ -319,7 +319,9 @@ void ImplicitBoolCastCheck::registerMatc
   anyOf(boolComparison, boolXor, boolOpAssignment,
   // Check also for nested casts, for example: bool -> int -> float.
   anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")),
-anything()))
+anything()),
+  unless(isInTemplateInstantiation()),
+  unless(hasAncestor(functionTemplateDecl(
   .bind("implicitCastFromBool"),
   this);
 }


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


[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)

2017-05-16 Thread Peter Szecsi via Phabricator via cfe-commits
szepet added inline comments.



Comment at: lib/AST/ASTImporter.cpp:1464
+
+  NamespaceDecl *TargetDecl = cast(
+Importer.Import(D->getNamespace()));

Since the Import can result nullptr (which is checked 2 lines below) this 
should be a cast_or_null as I see.


https://reviews.llvm.org/D32751



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


[PATCH] D32524: [clang-format] Fix MatchingOpeningBlockLineIndex computation

2017-05-16 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 99136.
Typz added a comment.

Reformat and remove unneeded comment


https://reviews.llvm.org/D32524

Files:
  lib/Format/UnwrappedLineParser.cpp


Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -428,8 +428,9 @@
 parseParens();
 
   addUnwrappedLine();
-  size_t OpeningLineIndex =
-  Lines.empty() ? (UnwrappedLine::kInvalidIndex) : (Lines.size() - 1);
+  size_t OpeningLineIndex = CurrentLines->empty()
+? (UnwrappedLine::kInvalidIndex)
+: (CurrentLines->size() - 1);
 
   ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
   MustBeDeclaration);


Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -428,8 +428,9 @@
 parseParens();
 
   addUnwrappedLine();
-  size_t OpeningLineIndex =
-  Lines.empty() ? (UnwrappedLine::kInvalidIndex) : (Lines.size() - 1);
+  size_t OpeningLineIndex = CurrentLines->empty()
+? (UnwrappedLine::kInvalidIndex)
+: (CurrentLines->size() - 1);
 
   ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
   MustBeDeclaration);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33201: [clangd] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

2017-05-16 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303173: [clangd] Refactor ProtocolHandlers to decouple them 
from ClangdLSPServer (authored by ibiryukov).

Changed prior to commit:
  https://reviews.llvm.org/D33201?vs=99129=99145#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33201

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdLSPServer.h
  clang-tools-extra/trunk/clangd/ClangdMain.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
  clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
  clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
  clang-tools-extra/trunk/clangd/ProtocolHandlers.h

Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h
@@ -20,50 +20,36 @@
 
 class JSONOutput;
 
-/// This class serves as an intermediate layer of LSP server implementation,
-/// glueing the JSON LSP protocol layer and ClangdServer together. It doesn't
-/// directly handle input from LSP client.
-/// Most methods are synchronous and return their result directly, but
-/// diagnostics are provided asynchronously when ready via
-/// JSONOutput::writeMessage.
+/// This class provides implementation of an LSP server, glueing the JSON
+/// dispatch and ClangdServer together.
 class ClangdLSPServer {
 public:
   ClangdLSPServer(JSONOutput , bool RunSynchronously);
 
-  /// Update the document text for \p File with \p Contents, schedule update of
-  /// diagnostics. Out.writeMessage will called to push diagnostics to LSP
-  /// client asynchronously when they are ready.
-  void openDocument(PathRef File, StringRef Contents);
-  /// Stop tracking the document for \p File.
-  void closeDocument(PathRef File);
-
-  /// Run code completion synchronously.
-  std::vector codeComplete(PathRef File, Position Pos);
-
-  /// Get the fixes associated with a certain diagnostic in a specified file as
-  /// replacements.
-  ///
-  /// This function is thread-safe. It returns a copy to avoid handing out
-  /// references to unguarded data.
-  std::vector
-  getFixIts(StringRef File, const clangd::Diagnostic );
-
-  /// Get the current document contents stored for \p File.
-  /// FIXME(ibiryukov): This function is here to allow implementation of
-  /// formatCode from ProtocolHandlers.cpp. We should move formatCode to
-  /// ClangdServer class and remove this function from public interface.
-  std::string getDocument(PathRef File);
+  /// Run LSP server loop, receiving input for it from \p In. \p In must be
+  /// opened in binary mode. Output will be written using Out variable passed to
+  /// class constructor. This method must not be executed more than once for
+  /// each instance of ClangdLSPServer.
+  void run(std::istream );
 
 private:
+  class LSPProtocolCallbacks;
   class LSPDiagnosticsConsumer;
 
+  std::vector
+  getFixIts(StringRef File, const clangd::Diagnostic );
+
   /// Function that will be called on a separate thread when diagnostics are
   /// ready. Sends the Dianostics to LSP client via Out.writeMessage and caches
   /// corresponding fixits in the FixItsMap.
   void consumeDiagnostics(PathRef File,
   std::vector Diagnostics);
 
   JSONOutput 
+  /// Used to indicate that the 'shutdown' request was received from the
+  /// Language Server client.
+  /// It's used to break out of the LSP parsing loop.
+  bool IsDone = false;
 
   std::mutex FixItsMutex;
   typedef std::map
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -9,10 +9,35 @@
 
 #include "ClangdLSPServer.h"
 #include "JSONRPCDispatcher.h"
+#include "ProtocolHandlers.h"
 
 using namespace clang::clangd;
 using namespace clang;
 
+namespace {
+
+std::string
+replacementsToEdits(StringRef Code,
+const std::vector ) {
+  // Turn the replacements into the format specified by the Language Server
+  // Protocol. Fuse them into one big JSON array.
+  std::string Edits;
+  for (auto  : Replacements) {
+Range ReplacementRange = {
+offsetToPosition(Code, R.getOffset()),
+offsetToPosition(Code, R.getOffset() + R.getLength())};
+TextEdit TE = {ReplacementRange, R.getReplacementText()};
+Edits += TextEdit::unparse(TE);
+Edits += ',';
+  }
+  if (!Edits.empty())
+Edits.pop_back();
+
+  return Edits;
+}
+
+} // namespace
+
 class ClangdLSPServer::LSPDiagnosticsConsumer : public DiagnosticsConsumer {
 public:
   LSPDiagnosticsConsumer(ClangdLSPServer ) : Server(Server) {}
@@ -26,23 +51,170 @@
   

[PATCH] D32479: [clang-format] Add BreakConstructorInitializersBeforeColon option

2017-05-16 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D32479



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 99149.
yaxunl marked an inline comment as done.
yaxunl added a comment.

Revised by John's comments.


https://reviews.llvm.org/D32248

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Basic/AddressSpaces.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ASTContext.cpp
  lib/AST/TypePrinter.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenTypeCache.h
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenOpenCL/amdgcn-automatic-variable.cl
  test/SemaOpenCL/storageclass-cl20.cl
  test/SemaOpenCL/storageclass.cl

Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -13,29 +13,37 @@
   constant int L1 = 0;
   local int L2;
 
-  auto int L3 = 7; // expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
-  global int L4;   // expected-error{{function scope variable cannot be declared in global address space}}
-
-  constant int L5 = x; // expected-error {{initializer element is not a compile-time constant}}
-  global int *constant L6 = 
-  private int *constant L7 =  // expected-error {{initializer element is not a compile-time constant}}
-  constant int *constant L8 = 
-  local int *constant L9 =  // expected-error {{initializer element is not a compile-time constant}}
+  auto int L3 = 7;// expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
+  global int L4;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L5; // expected-error{{automatic variable qualified with an invalid address space}}
+
+  constant int L6 = x;// expected-error {{initializer element is not a compile-time constant}}
+  global int *constant L7 = 
+  private int *constant L8 =   // expected-error {{initializer element is not a compile-time constant}}
+  constant int *constant L9 = 
+  local int *constant L10 =   // expected-error {{initializer element is not a compile-time constant}}
 }
 
 static void kernel bar() { // expected-error{{kernel functions cannot be declared static}}
 }
 
 void f() {
-  constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-  local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+  constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+  local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+  global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
+
   {
-constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+__attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
   }
-  global int L3; // expected-error{{function scope variable cannot be declared in global address space}}
-  extern constant float L4;
-  extern local float L5; // expected-error{{extern variable must reside in constant address space}}
-  static int L6 = 0; // expected-error{{variables in function scope cannot be declared static}}
-  static int L7; // expected-error{{variables in function scope cannot be declared static}}
+
+
+  extern constant float L5;
+  extern local float L6; // expected-error{{extern variable must reside in constant address space}}
+
+  static int L7 = 0; // expected-error{{variables in function scope cannot be declared static}}
+  static int L8; // expected-error{{variables in function scope cannot be declared static}}
 }
Index: test/SemaOpenCL/storageclass-cl20.cl

[PATCH] D33250: [Sema][ObjC] Fix a bug where -Wunguarded-availability was emitted at the wrong location

2017-05-16 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 99235.
erik.pilkington added a comment.

Just noticed this can be simplified a bit, NFC compared to the last version of 
the diff.


https://reviews.llvm.org/D33250

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/SemaObjC/unguarded-availability.m


Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -135,6 +135,17 @@
 func_10_12();
 };
 
+AVAILABLE_10_12
+__attribute__((objc_root_class))
+@interface InterWithProp // expected-note 2 {{marked partial here}}
+@property int x;
+@end
+
+void test_property(void) {
+  int y = InterWithProp.x; // expected-warning{{'InterWithProp' is only 
available on macOS 10.12 or newer}} expected-note{{@available}}
+  InterWithProp.x = y; // expected-warning{{'InterWithProp' is only available 
on macOS 10.12 or newer}} expected-note{{@available}}
+}
+
 #ifdef OBJCPP
 
 int f(char) AVAILABLE_10_12;
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7370,7 +7370,8 @@
 
 bool DiagnoseUnguardedAvailability::VisitTypeLoc(TypeLoc Ty) {
   const Type *TyPtr = Ty.getTypePtr();
-  SourceRange Range{Ty.getBeginLoc(), Ty.getEndLoc()};
+  SourceRange Range(StmtStack.back()->getLocStart(),
+StmtStack.back()->getLocEnd());
 
   if (const TagType *TT = dyn_cast(TyPtr)) {
 TagDecl *TD = TT->getDecl();


Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -135,6 +135,17 @@
 func_10_12();
 };
 
+AVAILABLE_10_12
+__attribute__((objc_root_class))
+@interface InterWithProp // expected-note 2 {{marked partial here}}
+@property int x;
+@end
+
+void test_property(void) {
+  int y = InterWithProp.x; // expected-warning{{'InterWithProp' is only available on macOS 10.12 or newer}} expected-note{{@available}}
+  InterWithProp.x = y; // expected-warning{{'InterWithProp' is only available on macOS 10.12 or newer}} expected-note{{@available}}
+}
+
 #ifdef OBJCPP
 
 int f(char) AVAILABLE_10_12;
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7370,7 +7370,8 @@
 
 bool DiagnoseUnguardedAvailability::VisitTypeLoc(TypeLoc Ty) {
   const Type *TyPtr = Ty.getTypePtr();
-  SourceRange Range{Ty.getBeginLoc(), Ty.getEndLoc()};
+  SourceRange Range(StmtStack.back()->getLocStart(),
+StmtStack.back()->getLocEnd());
 
   if (const TagType *TT = dyn_cast(TyPtr)) {
 TagDecl *TD = TT->getDecl();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r303233 - [ODRHash] Support NestedNameSpecifier

2017-05-16 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Tue May 16 22:23:35 2017
New Revision: 303233

URL: http://llvm.org/viewvc/llvm-project?rev=303233=rev
Log:
[ODRHash] Support NestedNameSpecifier

Modified:
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=303233=303232=303233=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Tue May 16 22:23:35 2017
@@ -81,7 +81,35 @@ void ODRHash::AddDeclarationName(Declara
   }
 }
 
-void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {}
+void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
+  assert(NNS && "Expecting non-null pointer.");
+  const auto *Prefix = NNS->getPrefix();
+  AddBoolean(Prefix);
+  if (Prefix) {
+AddNestedNameSpecifier(Prefix);
+  }
+  auto Kind = NNS->getKind();
+  ID.AddInteger(Kind);
+  switch (Kind) {
+  case NestedNameSpecifier::Identifier:
+AddIdentifierInfo(NNS->getAsIdentifier());
+break;
+  case NestedNameSpecifier::Namespace:
+AddDecl(NNS->getAsNamespace());
+break;
+  case NestedNameSpecifier::NamespaceAlias:
+AddDecl(NNS->getAsNamespaceAlias());
+break;
+  case NestedNameSpecifier::TypeSpec:
+  case NestedNameSpecifier::TypeSpecWithTemplate:
+AddType(NNS->getAsType());
+break;
+  case NestedNameSpecifier::Global:
+  case NestedNameSpecifier::Super:
+break;
+  }
+}
+
 void ODRHash::AddTemplateName(TemplateName Name) {}
 void ODRHash::AddTemplateArgument(TemplateArgument TA) {}
 void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) {}

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=303233=303232=303233=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue May 16 22:23:35 2017
@@ -9348,12 +9348,6 @@ void ASTReader::diagnoseOdrViolations()
 return Hash.CalculateHash();
   };
 
-  auto ComputeDeclNameODRHash = [](const DeclarationName Name) {
-Hash.clear();
-Hash.AddDeclarationName(Name);
-return Hash.CalculateHash();
-  };
-
   auto ComputeQualTypeODRHash = [](QualType Ty) {
 Hash.clear();
 Hash.AddQualType(Ty);
@@ -9446,11 +9440,8 @@ void ASTReader::diagnoseOdrViolations()
 
 QualType FirstType = FirstField->getType();
 QualType SecondType = SecondField->getType();
-const TypedefType *FirstTypedef = dyn_cast(FirstType);
-const TypedefType *SecondTypedef = dyn_cast(SecondType);
-
-if ((FirstTypedef && !SecondTypedef) ||
-(!FirstTypedef && SecondTypedef)) {
+if (ComputeQualTypeODRHash(FirstType) !=
+ComputeQualTypeODRHash(SecondType)) {
   ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(),
FieldTypeName)
   << FirstII << FirstType;
@@ -9462,24 +9453,6 @@ void ASTReader::diagnoseOdrViolations()
   break;
 }
 
-if (FirstTypedef && SecondTypedef) {
-  unsigned FirstHash = ComputeDeclNameODRHash(
-  FirstTypedef->getDecl()->getDeclName());
-  unsigned SecondHash = ComputeDeclNameODRHash(
-  SecondTypedef->getDecl()->getDeclName());
-  if (FirstHash != SecondHash) {
-ODRDiagError(FirstField->getLocation(),
- FirstField->getSourceRange(), FieldTypeName)
-<< FirstII << FirstType;
-ODRDiagNote(SecondField->getLocation(),
-SecondField->getSourceRange(), FieldTypeName)
-<< SecondII << SecondType;
-
-Diagnosed = true;
-break;
-  }
-}
-
 const bool IsFirstBitField = FirstField->isBitField();
 const bool IsSecondBitField = SecondField->isBitField();
 if (IsFirstBitField != IsSecondBitField) {

Modified: cfe/trunk/test/Modules/odr_hash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=303233=303232=303233=diff
==
--- cfe/trunk/test/Modules/odr_hash.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash.cpp Tue May 16 22:23:35 2017
@@ -707,6 +707,165 @@ S1 s1;
 #endif
 }
 
+namespace NestedNamespaceSpecifier {
+#if defined(FIRST)
+namespace LevelA1 {
+using Type = int;
+}
+
+struct S1 {
+  LevelA1::Type x;
+};
+# elif defined(SECOND)
+namespace LevelB1 {
+namespace LevelC1 {
+using Type = int;
+}
+}
+
+struct S1 {
+  LevelB1::LevelC1::Type x;
+};
+#else
+S1 s1;
+// expected-error@second.h:* {{'NestedNamespaceSpecifier::S1' has 

[clang-tools-extra] r303187 - [clang-tidy] Optimize readability-implicit-bool-cast, NFC

2017-05-16 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue May 16 11:40:46 2017
New Revision: 303187

URL: http://llvm.org/viewvc/llvm-project?rev=303187=rev
Log:
[clang-tidy] Optimize readability-implicit-bool-cast, NFC

Rearrange matchers to put the most expensive ones closer to the end. Speed up
another 3-5x on some files.

Modified:
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp?rev=303187=303186=303187=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp 
Tue May 16 11:40:46 2017
@@ -268,32 +268,32 @@ void ImplicitBoolCastCheck::registerMatc
   }
 
   auto exceptionCases =
-  expr(anyOf(hasParent(explicitCastExpr()),
- allOf(isMacroExpansion(), unless(isNULLMacroExpansion();
+  expr(anyOf(allOf(isMacroExpansion(), unless(isNULLMacroExpansion())),
+ hasParent(explicitCastExpr(;
   auto implicitCastFromBool = implicitCastExpr(
-  unless(exceptionCases),
   anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating),
 // Prior to C++11 cast from bool literal to pointer was allowed.
 allOf(anyOf(hasCastKind(CK_NullToPointer),
 hasCastKind(CK_NullToMemberPointer)),
   hasSourceExpression(cxxBoolLiteral(,
-  hasSourceExpression(expr(hasType(booleanType();
+  hasSourceExpression(expr(hasType(booleanType(,
+  unless(exceptionCases));
   auto boolXor =
   binaryOperator(hasOperatorName("^"), hasLHS(implicitCastFromBool),
  hasRHS(implicitCastFromBool));
   Finder->addMatcher(
   implicitCastExpr(
-  // Exclude cases common to implicit cast to and from bool.
-  unless(exceptionCases), unless(has(boolXor)),
+  anyOf(hasCastKind(CK_IntegralToBoolean),
+hasCastKind(CK_FloatingToBoolean),
+hasCastKind(CK_PointerToBoolean),
+hasCastKind(CK_MemberPointerToBoolean)),
   // Exclude case of using if or while statements with variable
   // declaration, e.g.:
   //   if (int var = functionCall()) {}
   unless(
   hasParent(stmt(anyOf(ifStmt(), whileStmt()), has(declStmt(),
-  anyOf(hasCastKind(CK_IntegralToBoolean),
-hasCastKind(CK_FloatingToBoolean),
-hasCastKind(CK_PointerToBoolean),
-hasCastKind(CK_MemberPointerToBoolean)),
+  // Exclude cases common to implicit cast to and from bool.
+  unless(exceptionCases), unless(has(boolXor)),
   // Retrive also parent statement, to check if we need additional
   // parens in replacement.
   anyOf(hasParent(stmt().bind("parentStmt")), anything()),


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


RE: Potential self-hosting failure

2017-05-16 Thread John Brawn via cfe-commits
I've managed to reproduce this, but no luck so far in figuring out
what exactly is going wrong. I'll continue looking into it tomorrow.

John

> -Original Message-
> From: Renato Golin [mailto:renato.go...@linaro.org]
> Sent: 16 May 2017 12:18
> To: John Brawn
> Cc: James Molloy; Diana Picus; LLVM Commits; Clang Commits
> Subject: Potential self-hosting failure
> 
> Hi John,
> 
> It seems the LEApcrel patches have broken our self-hosting:
> 
> http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-
> sh/builds/1550
> 
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-
> neon/builds/1349
> 
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-
> selfhost/builds/1845
> 
> The range in each is big, but the overlapping range is actually just
> 303051 ~ 303054.
> 
> Since two of those patches are yours and since this is a self-hosting
> issue, my money is on your patches, not the Dwarf one. :)
> 
> The tests don't help much, unfortunately.
> 
> I have had problems like this in Clang, where the code assumed some
> ABI that wasn't as generic as initially assumed, and changes in
> relocation are normally the ones that expose those wrong assumptions.
> 
> Can you have a look on your side, while we're testing on our side, too?
> 
> Thanks!
> --renato
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33250: [Sema][ObjC] Fix a bug where -Wunguarded-availability was emitted at the wrong location

2017-05-16 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.

Previously, we used TypeLocs to find the correct SourceLocations to emit 
-Wunguarded-availability. Unfortunately, TypeLocs can't be trusted as they 
sometimes have an an empty SourceLocation component. This new patch maintains 
the enclosing SourceLocation to be used instead.
Thanks for taking a look,
Erik


https://reviews.llvm.org/D33250

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/SemaObjC/unguarded-availability.m


Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -135,6 +135,17 @@
 func_10_12();
 };
 
+AVAILABLE_10_12
+__attribute__((objc_root_class))
+@interface InterWithProp // expected-note 2 {{marked partial here}}
+@property int x;
+@end
+
+void test_property(void) {
+  int y = InterWithProp.x; // expected-warning{{'InterWithProp' is only 
available on macOS 10.12 or newer}} expected-note{{@available}}
+  InterWithProp.x = y; // expected-warning{{'InterWithProp' is only available 
on macOS 10.12 or newer}} expected-note{{@available}}
+}
+
 #ifdef OBJCPP
 
 int f(char) AVAILABLE_10_12;
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7221,6 +7221,8 @@
   SmallVector AvailabilityStack;
   SmallVector StmtStack;
 
+  SourceRange CurrentRange;
+
   void DiagnoseDeclAvailability(NamedDecl *D, SourceRange Range);
 
 public:
@@ -7234,7 +7236,10 @@
 if (!S)
   return true;
 StmtStack.push_back(S);
+SourceRange LastRange(S->getLocStart(), S->getLocEnd());
+std::swap(LastRange, CurrentRange);
 bool Result = Base::TraverseStmt(S);
+std::swap(LastRange, CurrentRange);
 StmtStack.pop_back();
 return Result;
   }
@@ -7370,21 +7375,18 @@
 
 bool DiagnoseUnguardedAvailability::VisitTypeLoc(TypeLoc Ty) {
   const Type *TyPtr = Ty.getTypePtr();
-  SourceRange Range{Ty.getBeginLoc(), Ty.getEndLoc()};
-
   if (const TagType *TT = dyn_cast(TyPtr)) {
 TagDecl *TD = TT->getDecl();
-DiagnoseDeclAvailability(TD, Range);
+DiagnoseDeclAvailability(TD, CurrentRange);
 
   } else if (const TypedefType *TD = dyn_cast(TyPtr)) {
 TypedefNameDecl *D = TD->getDecl();
-DiagnoseDeclAvailability(D, Range);
+DiagnoseDeclAvailability(D, CurrentRange);
 
   } else if (const auto *ObjCO = dyn_cast(TyPtr)) {
 if (NamedDecl *D = ObjCO->getInterface())
-  DiagnoseDeclAvailability(D, Range);
+  DiagnoseDeclAvailability(D, CurrentRange);
   }
-
   return true;
 }
 


Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -135,6 +135,17 @@
 func_10_12();
 };
 
+AVAILABLE_10_12
+__attribute__((objc_root_class))
+@interface InterWithProp // expected-note 2 {{marked partial here}}
+@property int x;
+@end
+
+void test_property(void) {
+  int y = InterWithProp.x; // expected-warning{{'InterWithProp' is only available on macOS 10.12 or newer}} expected-note{{@available}}
+  InterWithProp.x = y; // expected-warning{{'InterWithProp' is only available on macOS 10.12 or newer}} expected-note{{@available}}
+}
+
 #ifdef OBJCPP
 
 int f(char) AVAILABLE_10_12;
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7221,6 +7221,8 @@
   SmallVector AvailabilityStack;
   SmallVector StmtStack;
 
+  SourceRange CurrentRange;
+
   void DiagnoseDeclAvailability(NamedDecl *D, SourceRange Range);
 
 public:
@@ -7234,7 +7236,10 @@
 if (!S)
   return true;
 StmtStack.push_back(S);
+SourceRange LastRange(S->getLocStart(), S->getLocEnd());
+std::swap(LastRange, CurrentRange);
 bool Result = Base::TraverseStmt(S);
+std::swap(LastRange, CurrentRange);
 StmtStack.pop_back();
 return Result;
   }
@@ -7370,21 +7375,18 @@
 
 bool DiagnoseUnguardedAvailability::VisitTypeLoc(TypeLoc Ty) {
   const Type *TyPtr = Ty.getTypePtr();
-  SourceRange Range{Ty.getBeginLoc(), Ty.getEndLoc()};
-
   if (const TagType *TT = dyn_cast(TyPtr)) {
 TagDecl *TD = TT->getDecl();
-DiagnoseDeclAvailability(TD, Range);
+DiagnoseDeclAvailability(TD, CurrentRange);
 
   } else if (const TypedefType *TD = dyn_cast(TyPtr)) {
 TypedefNameDecl *D = TD->getDecl();
-DiagnoseDeclAvailability(D, Range);
+DiagnoseDeclAvailability(D, CurrentRange);
 
   } else if (const auto *ObjCO = dyn_cast(TyPtr)) {
 if (NamedDecl *D = ObjCO->getInterface())
-  DiagnoseDeclAvailability(D, Range);
+  DiagnoseDeclAvailability(D, CurrentRange);
   }
-
   return true;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang-tools-extra] r303191 - [clang-tidy] Speed up performance-unnecessary-value-param check

2017-05-16 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue May 16 12:28:17 2017
New Revision: 303191

URL: http://llvm.org/viewvc/llvm-project?rev=303191=rev
Log:
[clang-tidy] Speed up performance-unnecessary-value-param check

Moved slower matchers closer to the end. The total speed up on a large file I
was interested in is not huge, just about 10%, since the check seems to be doing
a lot in the check() method.

Modified:

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp?rev=303191=303190=303191=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp 
Tue May 16 12:28:17 2017
@@ -68,15 +68,14 @@ UnnecessaryValueParamCheck::UnnecessaryV
 
 void UnnecessaryValueParamCheck::registerMatchers(MatchFinder *Finder) {
   const auto ExpensiveValueParamDecl =
-  parmVarDecl(hasType(hasCanonicalType(allOf(matchers::isExpensiveToCopy(),
- unless(referenceType(),
+  parmVarDecl(hasType(hasCanonicalType(allOf(
+  unless(referenceType()), 
matchers::isExpensiveToCopy(,
   decl().bind("param"));
   Finder->addMatcher(
-  functionDecl(hasBody(stmt()), isDefinition(),
+  functionDecl(hasBody(stmt()), isDefinition(), unless(isImplicit()),
unless(cxxMethodDecl(anyOf(isOverride(), isFinal(,
-   unless(anyOf(isInstantiated(), isImplicit())),
has(typeLoc(forEach(ExpensiveValueParamDecl))),
-   decl().bind("functionDecl")),
+   unless(isInstantiated()), decl().bind("functionDecl")),
   this);
 }
 


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


r303192 - [index] Avoid another crash that happens when looking up a dependent name

2017-05-16 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue May 16 12:33:17 2017
New Revision: 303192

URL: http://llvm.org/viewvc/llvm-project?rev=303192=rev
Log:
[index] Avoid another crash that happens when looking up a dependent name
in a record that has a base without a definition

rdar://32224197

Modified:
cfe/trunk/lib/AST/CXXInheritance.cpp
cfe/trunk/test/Index/Core/index-dependent-source.cpp

Modified: cfe/trunk/lib/AST/CXXInheritance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CXXInheritance.cpp?rev=303192=303191=303192=diff
==
--- cfe/trunk/lib/AST/CXXInheritance.cpp (original)
+++ cfe/trunk/lib/AST/CXXInheritance.cpp Tue May 16 12:33:17 2017
@@ -278,6 +278,8 @@ bool CXXBasePaths::lookupInBases(ASTCont
   dyn_cast_or_null(TN.getAsTemplateDecl()))
 BaseRecord = TD->getTemplatedDecl();
 }
+if (BaseRecord && !BaseRecord->hasDefinition())
+  BaseRecord = nullptr;
   } else {
 BaseRecord = cast(
 BaseSpec.getType()->castAs()->getDecl());

Modified: cfe/trunk/test/Index/Core/index-dependent-source.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-dependent-source.cpp?rev=303192=303191=303192=diff
==
--- cfe/trunk/test/Index/Core/index-dependent-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-dependent-source.cpp Tue May 16 12:33:17 
2017
@@ -131,3 +131,13 @@ void undefinedTemplateLookup(UndefinedTe
   x.lookup;
   typename UndefinedTemplateClass::Type y;
 }
+
+template
+struct UserOfUndefinedTemplateClass: UndefinedTemplateClass { };
+
+template
+void undefinedTemplateLookup2(UserOfUndefinedTemplateClass ) {
+// Shouldn't crash!
+  x.lookup;
+  typename UserOfUndefinedTemplateClass::Type y;
+}


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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:7296
+  unsigned getASTAllocaAddressSpace() const override {
+return LangAS::Count + getABIInfo().getDataLayout().getAllocaAddrSpace();
+  }

yaxunl wrote:
> rjmccall wrote:
> > Can we rename LangAS::Count to something more meaningful like 
> > LangAS::FirstTargetAddressSpace?  I think this would clarify a lot of code.
> > 
> > Is the OpenCL special case in ASTContext::getTargetAddressSpace still 
> > correct with this patch?  A pointer in LangAS::Default should be lowered as 
> > a generic pointer instead of a pointer into the alloca address space, right?
> Will do.
> 
> The OpenCL special case in ASTContext::getTargetAddressSpace is still correct 
> with this patch. In OpenCL private address space is still represented in AST 
> by LangAS::Default, so a pointer in LangAS::Default should be lowered as a 
> pointer to alloca address space.
Then I don't understand.  If __private is always the alloca address space, why 
does IRGen have to add addrspace casts after allocating local variables in it?  
IRGen's invariant is that the value stored in LocalDeclMap for a variable of 
AST type T is a value of type [[T]] addrspace([[AS]]) *, where [[T]] is the 
lowered IR type for T and [[AS]] is the target address space of the variable.  
For auto variables, AS is always LangAS::Default, which according to you means 
that [[AS]] is always LLVM's notion of the alloca address space, which is 
exactly the type produced by alloca.  So why is there ever a cast?

My understanding was that, on your target, __private is (at least sometimes) a 
64-bit extension of the alloca address space, which is 32-bit.  But that makes 
__private a different address space from the alloca address space, so the 
special case in getTargetAddressSpace is still wrong, because that special case 
means that a pointer-to-__private type will be lowered to be a 32-bit pointer 
type.

Also, I'm not sure why the normal AddrSpaceMap mechanism isn't sufficient for 
mapping LangAS::Default.


https://reviews.llvm.org/D32248



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


Re: Potential self-hosting failure

2017-05-16 Thread Renato Golin via cfe-commits
On 16 May 2017 at 18:26, John Brawn  wrote:
> I've managed to reproduce this, but no luck so far in figuring out
> what exactly is going wrong. I'll continue looking into it tomorrow.

Thanks John,

I have reverted it for now on r303193, to get the bots green.

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


[PATCH] D32825: [clang-format] Improve understanding of combined typedef+record declarations

2017-05-16 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes marked an inline comment as done.
jtbandes added a comment.

Another ping.


https://reviews.llvm.org/D32825



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


[libcxxabi] r303175 - [libcxxabi] Align unwindHeader on a double-word boundary.

2017-05-16 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue May 16 10:19:08 2017
New Revision: 303175

URL: http://llvm.org/viewvc/llvm-project?rev=303175=rev
Log:
[libcxxabi] Align unwindHeader on a double-word boundary.

r276215 made a change to annotate _Unwind_Exception with attribute
"aligned" so that an exception object following field __cxa_exception
is sufficiently aligned. This fix hasn't been incorporated to unwind.h
on Darwin since it is an ABI breaking change.

Instead of annotating struct _Unwind_Exception with the attribute, this
commit annotates field unwindHeader of __cxa_exception. This ensures the
exception object is sufficiently aligned without breaking the ABI.

This recommits r302978 and r302981, which were reverted in r303016
because a libcxx test was failing on an AArch64 bot. I also modified the
libcxxabi test case to check the alignment of the pointer returned by
__cxa_allocate_exception rather than compiling the test with -O1 and
checking whether it segfaults.

rdar://problem/25364625

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

Added:
libcxxabi/trunk/test/exception_object_alignment.pass.cpp
Modified:
libcxxabi/trunk/src/cxa_exception.hpp

Modified: libcxxabi/trunk/src/cxa_exception.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.hpp?rev=303175=303174=303175=diff
==
--- libcxxabi/trunk/src/cxa_exception.hpp (original)
+++ libcxxabi/trunk/src/cxa_exception.hpp Tue May 16 10:19:08 2017
@@ -61,7 +61,21 @@ struct _LIBCXXABI_HIDDEN __cxa_exception
 size_t referenceCount;
 #endif
 
+// This field is annotated with attribute aligned so that the exception
+// object following the field is sufficiently aligned and there is no
+// gap between the field and the exception object. r276215 made a change to
+// annotate _Unwind_Exception in unwind.h with __attribute__((aligned)), 
but
+// we cannot incorporate the fix on Darwin since it is an ABI-breaking
+// change, which is why we need the attribute on this field.
+//
+// For ARM EHABI, we do not align this field since _Unwind_Exception is an
+// alias of _Unwind_Control_Block, which is not annotated with
+// __attribute__((aligned).
+#if defined(_LIBCXXABI_ARM_EHABI)
 _Unwind_Exception unwindHeader;
+#else
+_Unwind_Exception unwindHeader __attribute__((aligned));
+#endif
 };
 
 // http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
@@ -96,7 +110,13 @@ struct _LIBCXXABI_HIDDEN __cxa_dependent
 void* primaryException;
 #endif
 
+// See the comment in __cxa_exception as to why this field has attribute
+// aligned.
+#if defined(_LIBCXXABI_ARM_EHABI)
 _Unwind_Exception unwindHeader;
+#else
+_Unwind_Exception unwindHeader __attribute__((aligned));
+#endif
 };
 
 struct _LIBCXXABI_HIDDEN __cxa_eh_globals {

Added: libcxxabi/trunk/test/exception_object_alignment.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/exception_object_alignment.pass.cpp?rev=303175=auto
==
--- libcxxabi/trunk/test/exception_object_alignment.pass.cpp (added)
+++ libcxxabi/trunk/test/exception_object_alignment.pass.cpp Tue May 16 
10:19:08 2017
@@ -0,0 +1,33 @@
+//=== exception_object_alignment.pass.cpp 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: libcxxabi-no-exceptions
+
+// Check that the pointer __cxa_allocate_exception returns is aligned to the
+// default alignment for the target architecture.
+
+#include 
+#include 
+#include 
+#include 
+#include <__cxxabi_config.h>
+
+struct S {
+  int a[4];
+} __attribute__((aligned));
+
+int main() {
+#if !defined(_LIBCXXABI_ARM_EHABI)
+  void *p = __cxxabiv1::__cxa_allocate_exception(16);
+  auto i = reinterpret_cast(p);
+  auto a = std::alignment_of::value;
+  assert(i % a == 0);
+#endif
+  return 0;
+}


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


r303158 - [StaticAnalyzer] Move inline counter increaser to inlineCall function

2017-05-16 Thread Peter Szecsi via cfe-commits
Author: szepet
Date: Tue May 16 06:54:00 2017
New Revision: 303158

URL: http://llvm.org/viewvc/llvm-project?rev=303158=rev
Log:
[StaticAnalyzer] Move inline counter increaser to inlineCall function

Even though the shouldInlineCall function returns true, it can happen that the
function is not going to be inlined (as it can be seen at line 913 and below).
Moved the bumpNumTimesInlined(D) (the counter increaser) call to the inlineCall
function where it logically belongs.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=303158=303157=303158=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Tue May 16 
06:54:00 2017
@@ -447,6 +447,7 @@ bool ExprEngine::inlineCall(const CallEv
   Bldr.takeNodes(Pred);
 
   NumInlinedCalls++;
+  Engine.FunctionSummaries->bumpNumTimesInlined(D);
 
   // Mark the decl as visited.
   if (VisitedCallees)
@@ -868,8 +869,6 @@ bool ExprEngine::shouldInlineCall(const
   || IsRecursive))
 return false;
 
-  Engine.FunctionSummaries->bumpNumTimesInlined(D);
-
   return true;
 }
 


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


[PATCH] D33263: [scan-build] Patch to scan-build tool to support "--target=" flag

2017-05-16 Thread Haowei Wu via Phabricator via cfe-commits
haowei created this revision.

The scan-build script provided by clang can be used to detect defects in code 
in the compile time. However, we discovered that the "--target=" flag in 
clang is not properly handled by this script, which results in failures when 
analyzing projects that have used this flag in their makefile.

This single line of change allows scan-build script to properly handle the 
"--target=" flag


https://reviews.llvm.org/D33263

Files:
  tools/scan-build/libexec/ccc-analyzer


Index: tools/scan-build/libexec/ccc-analyzer
===
--- tools/scan-build/libexec/ccc-analyzer
+++ tools/scan-build/libexec/ccc-analyzer
@@ -385,7 +385,8 @@
   '-target' => 1,
   '-v' => 0,
   '-mmacosx-version-min' => 0, # This is really a 1 argument, but always has 
'='
-  '-miphoneos-version-min' => 0 # This is really a 1 argument, but always has 
'='
+  '-miphoneos-version-min' => 0, # This is really a 1 argument, but always has 
'='
+  '--target' => 0
 );
 
 my %IgnoredOptionMap = (


Index: tools/scan-build/libexec/ccc-analyzer
===
--- tools/scan-build/libexec/ccc-analyzer
+++ tools/scan-build/libexec/ccc-analyzer
@@ -385,7 +385,8 @@
   '-target' => 1,
   '-v' => 0,
   '-mmacosx-version-min' => 0, # This is really a 1 argument, but always has '='
-  '-miphoneos-version-min' => 0 # This is really a 1 argument, but always has '='
+  '-miphoneos-version-min' => 0, # This is really a 1 argument, but always has '='
+  '--target' => 0
 );
 
 my %IgnoredOptionMap = (
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33259: Don't defer to the GCC driver for linking arm-baremetal

2017-05-16 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

While I fully agree that the current fallback-to-GCC behavior is far from 
helpful, I'm not sure how much sense providing linker support for bare-metal 
makes. I would expect this to changes wildly depending on the specific 
environment.


https://reviews.llvm.org/D33259



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


Potential self-hosting failure

2017-05-16 Thread Renato Golin via cfe-commits
Hi John,

It seems the LEApcrel patches have broken our self-hosting:

http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh/builds/1550

http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-neon/builds/1349

http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost/builds/1845

The range in each is big, but the overlapping range is actually just
303051 ~ 303054.

Since two of those patches are yours and since this is a self-hosting
issue, my money is on your patches, not the Dwarf one. :)

The tests don't help much, unfortunately.

I have had problems like this in Clang, where the code assumed some
ABI that wasn't as generic as initially assumed, and changes in
relocation are normally the ones that expose those wrong assumptions.

Can you have a look on your side, while we're testing on our side, too?

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


[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 99119.
hokein marked an inline comment as done.
hokein added a comment.

Adress review comments.


https://reviews.llvm.org/D33209

Files:
  clang-tidy/performance/InefficientVectorOperationCheck.cpp
  docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
  test/clang-tidy/performance-inefficient-vector-operation.cpp

Index: test/clang-tidy/performance-inefficient-vector-operation.cpp
===
--- test/clang-tidy/performance-inefficient-vector-operation.cpp
+++ test/clang-tidy/performance-inefficient-vector-operation.cpp
@@ -35,6 +35,9 @@
   explicit vector(size_type n);
 
   void push_back(const T& val);
+
+  template  void emplace_back(Args &&... args);
+
   void reserve(size_t n);
   void resize(size_t n);
 
@@ -150,6 +153,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
 }
   }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size());
+for (const auto  : t) {
+  v.emplace_back(e);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'emplace_back' is called
+}
+  }
   //  Non-fixed Cases 
   {
 std::vector v;
Index: docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
===
--- docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
+++ docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
@@ -3,8 +3,8 @@
 performance-inefficient-vector-operation
 
 
-Finds possible inefficient ``std::vector`` operations (e.g. ``push_back``) that
-may cause unnecessary memory reallocations.
+Finds possible inefficient ``std::vector`` operations (e.g. ``push_back``,
+``emplace_back``) that may cause unnecessary memory reallocations.
 
 Currently, the check only detects following kinds of loops with a single
 statement body:
@@ -24,7 +24,7 @@
 
 * For-range loops like ``for (range-declaration : range_expression)``, the type
   of ``range_expression`` can be ``std::vector``, ``std::array``,
-  ``std::dequeue``, ``std::set``, ``std::unordered_set``, ``std::map``,
+  ``std::deque``, ``std::set``, ``std::unordered_set``, ``std::map``,
   ``std::unordered_set``:
 
 .. code-block:: c++
Index: clang-tidy/performance/InefficientVectorOperationCheck.cpp
===
--- clang-tidy/performance/InefficientVectorOperationCheck.cpp
+++ clang-tidy/performance/InefficientVectorOperationCheck.cpp
@@ -39,14 +39,15 @@
 //   - VectorVarDeclName: 'v' in  (as VarDecl).
 //   - VectorVarDeclStmatName: The entire 'std::vector v;' statement (as
 // DeclStmt).
-//   - PushBackCallName: 'v.push_back(i)' (as cxxMemberCallExpr).
+//   - PushBackOrEmplaceBackCallName: 'v.push_back(i)' (as cxxMemberCallExpr).
 //   - LoopInitVarName: 'i' (as VarDecl).
 //   - LoopEndExpr: '10+1' (as Expr).
 static const char LoopCounterName[] = "for_loop_counter";
 static const char LoopParentName[] = "loop_parent";
 static const char VectorVarDeclName[] = "vector_var_decl";
 static const char VectorVarDeclStmtName[] = "vector_var_decl_stmt";
-static const char PushBackCallName[] = "push_back_call";
+static const char PushBackOrEmplaceBackCallName[] =
+"push_back_or_emplace_back_call";
 static const char LoopInitVarName[] = "loop_init_var";
 static const char LoopEndExprName[] = "loop_end_expr";
 
@@ -81,13 +82,13 @@
   const auto VectorVarDecl =
   varDecl(hasInitializer(VectorDefaultConstructorCall))
   .bind(VectorVarDeclName);
-  const auto PushBackCallExpr =
+  const auto VectorAppendCallExpr =
   cxxMemberCallExpr(
-  callee(cxxMethodDecl(hasName("push_back"))), on(hasType(VectorDecl)),
+  callee(cxxMethodDecl(hasAnyName("push_back", "emplace_back"))),
+  on(hasType(VectorDecl)),
   onImplicitObjectArgument(declRefExpr(to(VectorVarDecl
-  .bind(PushBackCallName);
-  const auto PushBackCall =
-  expr(anyOf(PushBackCallExpr, exprWithCleanups(has(PushBackCallExpr;
+  .bind(PushBackOrEmplaceBackCallName);
+  const auto VectorAppendCall = expr(ignoringImplicit(VectorAppendCallExpr));
   const auto VectorVarDefStmt =
   declStmt(hasSingleDecl(equalsBoundNode(VectorVarDeclName)))
   .bind(VectorVarDeclStmtName);
@@ -98,9 +99,11 @@
   const auto RefersToLoopVar = ignoringParenImpCasts(
   declRefExpr(to(varDecl(equalsBoundNode(LoopInitVarName);
 
-  // Matchers for the loop whose body has only 1 push_back calling statement.
-  const auto HasInterestingLoopBody = hasBody(anyOf(
-  compoundStmt(statementCountIs(1), has(PushBackCall)), PushBackCall));
+  // Matchers for the loop whose body has only 1 push_back/emplace_back calling
+  // statement.
+  const auto HasInterestingLoopBody =
+  hasBody(anyOf(compoundStmt(statementCountIs(1), has(VectorAppendCall)),
+

[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked an inline comment as done.
hokein added inline comments.



Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:92
+  const auto VectorAppendCall = expr(
+  anyOf(VectorAppendCallExpr, 
exprWithCleanups(has(VectorAppendCallExpr;
   const auto VectorVarDefStmt =

malcolm.parsons wrote:
> I'd use ignoringImplicit(VectorAppendCallExpr) to ignore ExprWithCleanups.
Good to know. Thanks!



Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:208
+   "consider pre-allocating the vector capacity before the loop")
+  << VectorAppendCall->getMethodDecl()->getDeclName();
 

alexfh wrote:
> Diagnostic builder should be able to format NamedDecls directly, this 
> `->getDeclName()` is not necessary. The only difference is that it will 
> likely add quotes around the name, which seems to be good anyway.
I tried it, but I found the behavior between using `getDeclName()` and not 
using `getDeclName()` is different when handling the template functions:

* `diag(...) << VectorAppendCall->getMethodDecl()` will print the function name 
with instantiated template arguments like "emplace_back";
*  `diag(...) << VectorAppendCall->getMethodDecl()->getDeclName()` will just 
print the function name without template arguments, which is what we expect.


https://reviews.llvm.org/D33209



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


[clang-tools-extra] r303145 - [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-05-16 Thread Jakub Kuderski via cfe-commits
Author: kuhar
Date: Tue May 16 01:32:38 2017
New Revision: 303145

URL: http://llvm.org/viewvc/llvm-project?rev=303145=rev
Log:
[clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

Summary:
This patch makes modernize-use-emplace remove unnecessary make_ calls from 
push_back calls and turn them into emplace_back -- the same way make_pair calls 
are handled.
Custom make_ calls can be removed for custom tuple-like types -- two new 
options that control that are `TupleTypes` and `TupleMakeFunctions`. By 
default, the check removes calls to `std::make_pair` and `std::make_tuple`.

Eq.

```
std::vector> v;
v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true);
```

Reviewers: alexfh, aaron.ballman, Prazek, hokein

Reviewed By: Prazek

Subscribers: JDevlieghere, xazax.hun, JonasToth, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
clang-tools-extra/trunk/test/clang-tidy/modernize-use-emplace.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp?rev=303145=303144=303145=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp Tue May 16 
01:32:38 2017
@@ -24,6 +24,8 @@ const auto DefaultContainersWithPushBack
 "::std::vector; ::std::list; ::std::deque";
 const auto DefaultSmartPointers =
 "::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr";
+const auto DefaultTupleTypes = "::std::pair; ::std::tuple";
+const auto DefaultTupleMakeFunctions = "::std::make_pair; ::std::make_tuple";
 } // namespace
 
 UseEmplaceCheck::UseEmplaceCheck(StringRef Name, ClangTidyContext *Context)
@@ -31,7 +33,11 @@ UseEmplaceCheck::UseEmplaceCheck(StringR
   ContainersWithPushBack(utils::options::parseStringList(Options.get(
   "ContainersWithPushBack", DefaultContainersWithPushBack))),
   SmartPointers(utils::options::parseStringList(
-  Options.get("SmartPointers", DefaultSmartPointers))) {}
+  Options.get("SmartPointers", DefaultSmartPointers))),
+  TupleTypes(utils::options::parseStringList(
+  Options.get("TupleTypes", DefaultTupleTypes))),
+  TupleMakeFunctions(utils::options::parseStringList(
+  Options.get("TupleMakeFunctions", DefaultTupleMakeFunctions))) {}
 
 void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
@@ -87,20 +93,23 @@ void UseEmplaceCheck::registerMatchers(M
   .bind("ctor");
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
-  auto MakePair = ignoringImplicit(
-  callExpr(callee(expr(ignoringImplicit(
-  declRefExpr(unless(hasExplicitTemplateArgs()),
-  to(functionDecl(hasName("::std::make_pair"
-  .bind("make_pair"));
+  auto MakeTuple = ignoringImplicit(
+  callExpr(
+  callee(expr(ignoringImplicit(declRefExpr(
+  unless(hasExplicitTemplateArgs()),
+  to(functionDecl(hasAnyName(SmallVector(
+  TupleMakeFunctions.begin(), TupleMakeFunctions.end())
+  .bind("make"));
 
-  // make_pair can return type convertible to container's element type.
+  // make_something can return type convertible to container's element type.
   // Allow the conversion only on containers of pairs.
-  auto MakePairCtor = ignoringImplicit(cxxConstructExpr(
-  has(materializeTemporaryExpr(MakePair)),
-  hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
+  auto MakeTupleCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(MakeTuple)),
+  hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
+  SmallVector(TupleTypes.begin(), 
TupleTypes.end(;
 
   auto SoughtParam = materializeTemporaryExpr(
-  anyOf(has(MakePair), has(MakePairCtor),
+  anyOf(has(MakeTuple), has(MakeTupleCtor),
 HasConstructExpr, has(cxxFunctionalCastExpr(HasConstructExpr;
 
   Finder->addMatcher(cxxMemberCallExpr(CallPushBack, has(SoughtParam),
@@ -112,8 +121,8 @@ void UseEmplaceCheck::registerMatchers(M
 void UseEmplaceCheck::check(const MatchFinder::MatchResult ) {
   const auto *Call = Result.Nodes.getNodeAs("call");
   const auto *InnerCtorCall = Result.Nodes.getNodeAs("ctor");
-  const auto *MakePairCall = Result.Nodes.getNodeAs("make_pair");
-  assert((InnerCtorCall || MakePairCall) && 

[PATCH] D33201: [ClangD] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

2017-05-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clangd/ClangdLSPServer.cpp:20
+template 
+std::string replacementsToEdits(StringRef Code, const T ) {
+  // Turn the replacements into the format specified by the Language Server

Hm, this is a bit too generic for my taste. Is it ever used generically?


https://reviews.llvm.org/D33201



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


[PATCH] D33201: [ClangD] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

2017-05-16 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 99129.
ilya-biryukov marked 3 inline comments as done.
ilya-biryukov added a comment.

Addressed review comments


https://reviews.llvm.org/D33201

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdMain.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/JSONRPCDispatcher.cpp
  clangd/JSONRPCDispatcher.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h

Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -22,118 +22,34 @@
 
 namespace clang {
 namespace clangd {
-class ClangdLSPServer;
-class ClangdLSPServer;
 
-struct InitializeHandler : Handler {
-  InitializeHandler(JSONOutput ) : Handler(Output) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override {
-writeMessage(
-R"({"jsonrpc":"2.0","id":)" + ID +
-R"(,"result":{"capabilities":{
-  "textDocumentSync": 1,
-  "documentFormattingProvider": true,
-  "documentRangeFormattingProvider": true,
-  "documentOnTypeFormattingProvider": {"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
-  "codeActionProvider": true,
-  "completionProvider": {"resolveProvider": false, "triggerCharacters": [".",">"]}
-}}})");
-  }
-};
-
-struct ShutdownHandler : Handler {
-  ShutdownHandler(JSONOutput ) : Handler(Output) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override {
-IsDone = true;
-  }
-
-  bool isDone() const { return IsDone; }
-
-private:
-  bool IsDone = false;
-};
-
-struct TextDocumentDidOpenHandler : Handler {
-  TextDocumentDidOpenHandler(JSONOutput , ClangdLSPServer )
-  : Handler(Output), AST(AST) {}
-
-  void handleNotification(llvm::yaml::MappingNode *Params) override;
-
-private:
-  ClangdLSPServer 
+class ProtocolCallbacks {
+public:
+  virtual ~ProtocolCallbacks() = default;
+
+  virtual void onInitialize(StringRef ID, JSONOutput ) = 0;
+  virtual void onShutdown(JSONOutput ) = 0;
+  virtual void onDocumentDidOpen(DidOpenTextDocumentParams Params,
+ JSONOutput ) = 0;
+  virtual void onDocumentDidChange(DidChangeTextDocumentParams Params,
+   JSONOutput ) = 0;
+
+  virtual void onDocumentDidClose(DidCloseTextDocumentParams Params,
+  JSONOutput ) = 0;
+  virtual void onDocumentFormatting(DocumentFormattingParams Params,
+StringRef ID, JSONOutput ) = 0;
+  virtual void onDocumentOnTypeFormatting(DocumentOnTypeFormattingParams Params,
+  StringRef ID, JSONOutput ) = 0;
+  virtual void onDocumentRangeFormatting(DocumentRangeFormattingParams Params,
+ StringRef ID, JSONOutput ) = 0;
+  virtual void onCodeAction(CodeActionParams Params, StringRef ID,
+JSONOutput ) = 0;
+  virtual void onCompletion(TextDocumentPositionParams Params, StringRef ID,
+JSONOutput ) = 0;
 };
 
-struct TextDocumentDidChangeHandler : Handler {
-  TextDocumentDidChangeHandler(JSONOutput , ClangdLSPServer )
-  : Handler(Output), AST(AST) {}
-
-  void handleNotification(llvm::yaml::MappingNode *Params) override;
-
-private:
-  ClangdLSPServer 
-};
-
-struct TextDocumentDidCloseHandler : Handler {
-  TextDocumentDidCloseHandler(JSONOutput , ClangdLSPServer )
-  : Handler(Output), AST(AST) {}
-
-  void handleNotification(llvm::yaml::MappingNode *Params) override;
-
-private:
-  ClangdLSPServer 
-};
-
-struct TextDocumentOnTypeFormattingHandler : Handler {
-  TextDocumentOnTypeFormattingHandler(JSONOutput , ClangdLSPServer )
-  : Handler(Output), AST(AST) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
-
-private:
-  ClangdLSPServer 
-};
-
-struct TextDocumentRangeFormattingHandler : Handler {
-  TextDocumentRangeFormattingHandler(JSONOutput , ClangdLSPServer )
-  : Handler(Output), AST(AST) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
-
-private:
-  ClangdLSPServer 
-};
-
-struct TextDocumentFormattingHandler : Handler {
-  TextDocumentFormattingHandler(JSONOutput , ClangdLSPServer )
-  : Handler(Output), AST(AST) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
-
-private:
-  ClangdLSPServer 
-};
-
-struct CodeActionHandler : Handler {
-  CodeActionHandler(JSONOutput , ClangdLSPServer )
-  : Handler(Output), AST(AST) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
-
-private:
-  ClangdLSPServer 
-};
-
-struct CompletionHandler : Handler {
-  CompletionHandler(JSONOutput , ClangdLSPServer )
-  : Handler(Output), AST(AST) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
-
- private:
-  

[PATCH] D32901: [clang-format] Handle trailing comment sections in import statement lines

2017-05-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

@djasper: ping


https://reviews.llvm.org/D32901



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


[PATCH] D31588: Fix PR25627: Certain constant local variables must be usable as template arguments (without being odr-used)

2017-05-16 Thread Faisal Vali via Phabricator via cfe-commits
faisalv added a comment.

*ping*
*ping*


https://reviews.llvm.org/D31588



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


[PATCH] D33201: [ClangD] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

2017-05-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

nit: rename this patch title to start with [clangd]


https://reviews.llvm.org/D33201



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


[PATCH] D33201: [clangd] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

2017-05-16 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdLSPServer.cpp:20
+template 
+std::string replacementsToEdits(StringRef Code, const T ) {
+  // Turn the replacements into the format specified by the Language Server

krasimir wrote:
> Hm, this is a bit too generic for my taste. Is it ever used generically?
Nope, it's now only used with one type, specialized it to it.



Comment at: clangd/ClangdLSPServer.h:33
+  /// each instance of ClangdLSPServer.
+  void run(std::istream );
 

krasimir wrote:
> It seems strange to have the In here and the Out in the constructor.
Didn't want to store unnecessary fields in the class, but we do need JSONOutput 
 as a member, since there's consumeDiagnostics which uses it.
Would you prefer std::istream  to be moved into a constructor parameter and 
stored as a field?


https://reviews.llvm.org/D33201



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


[PATCH] D32351: [Tooling][libclang] Remove unused CompilationDatabase::MappedSources

2017-05-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

@klimek: ping


https://reviews.llvm.org/D32351



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


[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-16 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303157: [clang-tidy] Add "emplace_back" detection in 
inefficient-vector-operation. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D33209?vs=99124=99127#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33209

Files:
  
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
  
clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
  
clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-vector-operation.cpp

Index: clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
@@ -39,14 +39,14 @@
 //   - VectorVarDeclName: 'v' in  (as VarDecl).
 //   - VectorVarDeclStmatName: The entire 'std::vector v;' statement (as
 // DeclStmt).
-//   - PushBackCallName: 'v.push_back(i)' (as cxxMemberCallExpr).
+//   - PushBackOrEmplaceBackCallName: 'v.push_back(i)' (as cxxMemberCallExpr).
 //   - LoopInitVarName: 'i' (as VarDecl).
 //   - LoopEndExpr: '10+1' (as Expr).
 static const char LoopCounterName[] = "for_loop_counter";
 static const char LoopParentName[] = "loop_parent";
 static const char VectorVarDeclName[] = "vector_var_decl";
 static const char VectorVarDeclStmtName[] = "vector_var_decl_stmt";
-static const char PushBackCallName[] = "push_back_call";
+static const char PushBackOrEmplaceBackCallName[] = "append_call";
 static const char LoopInitVarName[] = "loop_init_var";
 static const char LoopEndExprName[] = "loop_end_expr";
 
@@ -81,13 +81,13 @@
   const auto VectorVarDecl =
   varDecl(hasInitializer(VectorDefaultConstructorCall))
   .bind(VectorVarDeclName);
-  const auto PushBackCallExpr =
+  const auto VectorAppendCallExpr =
   cxxMemberCallExpr(
-  callee(cxxMethodDecl(hasName("push_back"))), on(hasType(VectorDecl)),
+  callee(cxxMethodDecl(hasAnyName("push_back", "emplace_back"))),
+  on(hasType(VectorDecl)),
   onImplicitObjectArgument(declRefExpr(to(VectorVarDecl
-  .bind(PushBackCallName);
-  const auto PushBackCall =
-  expr(anyOf(PushBackCallExpr, exprWithCleanups(has(PushBackCallExpr;
+  .bind(PushBackOrEmplaceBackCallName);
+  const auto VectorAppendCall = expr(ignoringImplicit(VectorAppendCallExpr));
   const auto VectorVarDefStmt =
   declStmt(hasSingleDecl(equalsBoundNode(VectorVarDeclName)))
   .bind(VectorVarDeclStmtName);
@@ -98,9 +98,11 @@
   const auto RefersToLoopVar = ignoringParenImpCasts(
   declRefExpr(to(varDecl(equalsBoundNode(LoopInitVarName);
 
-  // Matchers for the loop whose body has only 1 push_back calling statement.
-  const auto HasInterestingLoopBody = hasBody(anyOf(
-  compoundStmt(statementCountIs(1), has(PushBackCall)), PushBackCall));
+  // Matchers for the loop whose body has only 1 push_back/emplace_back calling
+  // statement.
+  const auto HasInterestingLoopBody =
+  hasBody(anyOf(compoundStmt(statementCountIs(1), has(VectorAppendCall)),
+VectorAppendCall));
   const auto InInterestingCompoundStmt =
   hasParent(compoundStmt(has(VectorVarDefStmt)).bind(LoopParentName));
 
@@ -145,8 +147,8 @@
   const auto *ForLoop = Result.Nodes.getNodeAs(LoopCounterName);
   const auto *RangeLoop =
   Result.Nodes.getNodeAs(RangeLoopName);
-  const auto *PushBackCall =
-  Result.Nodes.getNodeAs(PushBackCallName);
+  const auto *VectorAppendCall =
+  Result.Nodes.getNodeAs(PushBackOrEmplaceBackCallName);
   const auto *LoopEndExpr = Result.Nodes.getNodeAs(LoopEndExprName);
   const auto *LoopParent = Result.Nodes.getNodeAs(LoopParentName);
 
@@ -173,7 +175,7 @@
 
   llvm::StringRef VectorVarName = Lexer::getSourceText(
   CharSourceRange::getTokenRange(
-  PushBackCall->getImplicitObjectArgument()->getSourceRange()),
+  VectorAppendCall->getImplicitObjectArgument()->getSourceRange()),
   SM, Context->getLangOpts());
 
   std::string ReserveStmt;
@@ -197,9 +199,11 @@
 ReserveStmt = (VectorVarName + ".reserve(" + LoopEndSource + ");\n").str();
   }
 
-  auto Diag = diag(PushBackCall->getLocStart(),
-   "'push_back' is called inside a loop; "
-   "consider pre-allocating the vector capacity before the loop");
+  auto Diag =
+  diag(VectorAppendCall->getLocStart(),
+   "%0 is called inside a loop; "
+   "consider pre-allocating the vector capacity before the loop")
+  << VectorAppendCall->getMethodDecl()->getDeclName();
 
   if (!ReserveStmt.empty())
 Diag << FixItHint::CreateInsertion(LoopStmt->getLocStart(), ReserveStmt);
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst

[clang-tools-extra] r303157 - [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-16 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue May 16 05:39:55 2017
New Revision: 303157

URL: http://llvm.org/viewvc/llvm-project?rev=303157=rev
Log:
[clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

Reviewers: alexfh, aaron.ballman

Reviewed By: alexfh

Subscribers: cfe-commits, Prazek, malcolm.parsons, xazax.hun

Tags: #clang-tools-extra

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

Modified:

clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp

clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst

clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-vector-operation.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp?rev=303157=303156=303157=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
 Tue May 16 05:39:55 2017
@@ -39,14 +39,14 @@ namespace {
 //   - VectorVarDeclName: 'v' in  (as VarDecl).
 //   - VectorVarDeclStmatName: The entire 'std::vector v;' statement (as
 // DeclStmt).
-//   - PushBackCallName: 'v.push_back(i)' (as cxxMemberCallExpr).
+//   - PushBackOrEmplaceBackCallName: 'v.push_back(i)' (as cxxMemberCallExpr).
 //   - LoopInitVarName: 'i' (as VarDecl).
 //   - LoopEndExpr: '10+1' (as Expr).
 static const char LoopCounterName[] = "for_loop_counter";
 static const char LoopParentName[] = "loop_parent";
 static const char VectorVarDeclName[] = "vector_var_decl";
 static const char VectorVarDeclStmtName[] = "vector_var_decl_stmt";
-static const char PushBackCallName[] = "push_back_call";
+static const char PushBackOrEmplaceBackCallName[] = "append_call";
 static const char LoopInitVarName[] = "loop_init_var";
 static const char LoopEndExprName[] = "loop_end_expr";
 
@@ -81,13 +81,13 @@ void InefficientVectorOperationCheck::re
   const auto VectorVarDecl =
   varDecl(hasInitializer(VectorDefaultConstructorCall))
   .bind(VectorVarDeclName);
-  const auto PushBackCallExpr =
+  const auto VectorAppendCallExpr =
   cxxMemberCallExpr(
-  callee(cxxMethodDecl(hasName("push_back"))), on(hasType(VectorDecl)),
+  callee(cxxMethodDecl(hasAnyName("push_back", "emplace_back"))),
+  on(hasType(VectorDecl)),
   onImplicitObjectArgument(declRefExpr(to(VectorVarDecl
-  .bind(PushBackCallName);
-  const auto PushBackCall =
-  expr(anyOf(PushBackCallExpr, exprWithCleanups(has(PushBackCallExpr;
+  .bind(PushBackOrEmplaceBackCallName);
+  const auto VectorAppendCall = expr(ignoringImplicit(VectorAppendCallExpr));
   const auto VectorVarDefStmt =
   declStmt(hasSingleDecl(equalsBoundNode(VectorVarDeclName)))
   .bind(VectorVarDeclStmtName);
@@ -98,9 +98,11 @@ void InefficientVectorOperationCheck::re
   const auto RefersToLoopVar = ignoringParenImpCasts(
   declRefExpr(to(varDecl(equalsBoundNode(LoopInitVarName);
 
-  // Matchers for the loop whose body has only 1 push_back calling statement.
-  const auto HasInterestingLoopBody = hasBody(anyOf(
-  compoundStmt(statementCountIs(1), has(PushBackCall)), PushBackCall));
+  // Matchers for the loop whose body has only 1 push_back/emplace_back calling
+  // statement.
+  const auto HasInterestingLoopBody =
+  hasBody(anyOf(compoundStmt(statementCountIs(1), has(VectorAppendCall)),
+VectorAppendCall));
   const auto InInterestingCompoundStmt =
   hasParent(compoundStmt(has(VectorVarDefStmt)).bind(LoopParentName));
 
@@ -145,8 +147,8 @@ void InefficientVectorOperationCheck::ch
   const auto *ForLoop = Result.Nodes.getNodeAs(LoopCounterName);
   const auto *RangeLoop =
   Result.Nodes.getNodeAs(RangeLoopName);
-  const auto *PushBackCall =
-  Result.Nodes.getNodeAs(PushBackCallName);
+  const auto *VectorAppendCall =
+  Result.Nodes.getNodeAs(PushBackOrEmplaceBackCallName);
   const auto *LoopEndExpr = Result.Nodes.getNodeAs(LoopEndExprName);
   const auto *LoopParent = 
Result.Nodes.getNodeAs(LoopParentName);
 
@@ -173,7 +175,7 @@ void InefficientVectorOperationCheck::ch
 
   llvm::StringRef VectorVarName = Lexer::getSourceText(
   CharSourceRange::getTokenRange(
-  PushBackCall->getImplicitObjectArgument()->getSourceRange()),
+  VectorAppendCall->getImplicitObjectArgument()->getSourceRange()),
   SM, Context->getLangOpts());
 
   std::string ReserveStmt;
@@ -197,9 +199,11 @@ void InefficientVectorOperationCheck::ch
 ReserveStmt = (VectorVarName + ".reserve(" + LoopEndSource + ");\n").str();
   }
 
-  auto Diag = diag(PushBackCall->getLocStart(),
-   "'push_back' is called inside a loop; "
-   

[PATCH] D33201: [ClangD] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

2017-05-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clangd/ClangdLSPServer.cpp:206
 
-std::vector ClangdLSPServer::codeComplete(PathRef File,
-  Position Pos) {
-  return Server.codeComplete(File, Pos);
+  // Set up JSONRPCDispatcher
+  LSPProtocolCallbacks Callbacks(*this);

nit: .



Comment at: clangd/ClangdLSPServer.cpp:211
+
+  // Run the Language Server loop
+  runLanguageServerLoop(In, Out, Dispatcher, IsDone);

nit: .



Comment at: clangd/ClangdLSPServer.h:33
+  /// each instance of ClangdLSPServer.
+  void run(std::istream );
 

It seems strange to have the In here and the Out in the constructor.



Comment at: clangd/ClangdLSPServer.h:49
   JSONOutput 
+  bool IsDone = false;
   ClangdServer Server;

This deserves a comment.


https://reviews.llvm.org/D33201



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


[PATCH] D25051: Fix PR 10758: Infinite recursion when dealing with copy-initialization

2017-05-16 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

I will commit it today.


Repository:
  rL LLVM

https://reviews.llvm.org/D25051



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


[PATCH] D33233: Restored r303067 and fixed failing test.

2017-05-16 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
Herald added a subscriber: mgorny.

This commit restores r303067(reverted by r303094) and fixes the 
'formatting.test'
failure.
The failure is due to destructors of `ClangdLSPServer`'s fields(`FixItsMap` and
`FixItsMutex`) being called before destructor of `Server`. It led to the worker
thread calling `consumeDiagnostics` after `FixItsMutex` and `FixItsMap`
destructors were called.
Also, clangd is now run with '-run-synchronously' flag in 'formatting.test'.


https://reviews.llvm.org/D33233

Files:
  clangd/ASTManager.cpp
  clangd/ASTManager.h
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdMain.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h
  clangd/DocumentStore.h
  clangd/DraftStore.cpp
  clangd/DraftStore.h
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  clangd/Path.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  test/clangd/formatting.test

Index: test/clangd/formatting.test
===
--- test/clangd/formatting.test
+++ test/clangd/formatting.test
@@ -1,4 +1,4 @@
-# RUN: clangd < %s | FileCheck %s
+# RUN: clangd -run-synchronously < %s | FileCheck %s
 # It is absolutely vital that this file has CRLF line endings.
 #
 Content-Length: 125
Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -22,8 +22,8 @@
 
 namespace clang {
 namespace clangd {
-class ASTManager;
-class DocumentStore;
+class ClangdLSPServer;
+class ClangdLSPServer;
 
 struct InitializeHandler : Handler {
   InitializeHandler(JSONOutput ) : Handler(Output) {}
@@ -56,83 +56,83 @@
 };
 
 struct TextDocumentDidOpenHandler : Handler {
-  TextDocumentDidOpenHandler(JSONOutput , DocumentStore )
-  : Handler(Output), Store(Store) {}
+  TextDocumentDidOpenHandler(JSONOutput , ClangdLSPServer )
+  : Handler(Output), AST(AST) {}
 
   void handleNotification(llvm::yaml::MappingNode *Params) override;
 
 private:
-  DocumentStore 
+  ClangdLSPServer 
 };
 
 struct TextDocumentDidChangeHandler : Handler {
-  TextDocumentDidChangeHandler(JSONOutput , DocumentStore )
-  : Handler(Output), Store(Store) {}
+  TextDocumentDidChangeHandler(JSONOutput , ClangdLSPServer )
+  : Handler(Output), AST(AST) {}
 
   void handleNotification(llvm::yaml::MappingNode *Params) override;
 
 private:
-  DocumentStore 
+  ClangdLSPServer 
 };
 
 struct TextDocumentDidCloseHandler : Handler {
-  TextDocumentDidCloseHandler(JSONOutput , DocumentStore )
-  : Handler(Output), Store(Store) {}
+  TextDocumentDidCloseHandler(JSONOutput , ClangdLSPServer )
+  : Handler(Output), AST(AST) {}
 
   void handleNotification(llvm::yaml::MappingNode *Params) override;
 
 private:
-  DocumentStore 
+  ClangdLSPServer 
 };
 
 struct TextDocumentOnTypeFormattingHandler : Handler {
-  TextDocumentOnTypeFormattingHandler(JSONOutput , DocumentStore )
-  : Handler(Output), Store(Store) {}
+  TextDocumentOnTypeFormattingHandler(JSONOutput , ClangdLSPServer )
+  : Handler(Output), AST(AST) {}
 
   void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
 
 private:
-  DocumentStore 
+  ClangdLSPServer 
 };
 
 struct TextDocumentRangeFormattingHandler : Handler {
-  TextDocumentRangeFormattingHandler(JSONOutput , DocumentStore )
-  : Handler(Output), Store(Store) {}
+  TextDocumentRangeFormattingHandler(JSONOutput , ClangdLSPServer )
+  : Handler(Output), AST(AST) {}
 
   void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
 
 private:
-  DocumentStore 
+  ClangdLSPServer 
 };
 
 struct TextDocumentFormattingHandler : Handler {
-  TextDocumentFormattingHandler(JSONOutput , DocumentStore )
-  : Handler(Output), Store(Store) {}
+  TextDocumentFormattingHandler(JSONOutput , ClangdLSPServer )
+  : Handler(Output), AST(AST) {}
 
   void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
 
 private:
-  DocumentStore 
+  ClangdLSPServer 
 };
 
 struct CodeActionHandler : Handler {
-  CodeActionHandler(JSONOutput , ASTManager )
+  CodeActionHandler(JSONOutput , ClangdLSPServer )
   : Handler(Output), AST(AST) {}
 
   void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
 
 private:
-  ASTManager 
+  ClangdLSPServer 
 };
 
 struct CompletionHandler : Handler {
-  CompletionHandler(JSONOutput , ASTManager )
+  CompletionHandler(JSONOutput , ClangdLSPServer )
   : Handler(Output), AST(AST) {}
 
   void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
 
  private:
-  ASTManager 
+  ClangdLSPServer 
 };
 
 } // namespace clangd
Index: clangd/ProtocolHandlers.cpp
===
--- 

[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-16 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:208
+   "consider pre-allocating the vector capacity before the loop")
+  << VectorAppendCall->getMethodDecl()->getDeclName();
 

hokein wrote:
> alexfh wrote:
> > Diagnostic builder should be able to format NamedDecls directly, this 
> > `->getDeclName()` is not necessary. The only difference is that it will 
> > likely add quotes around the name, which seems to be good anyway.
> I tried it, but I found the behavior between using `getDeclName()` and not 
> using `getDeclName()` is different when handling the template functions:
> 
> * `diag(...) << VectorAppendCall->getMethodDecl()` will print the function 
> name with instantiated template arguments like "emplace_back";
> *  `diag(...) << VectorAppendCall->getMethodDecl()->getDeclName()` will just 
> print the function name without template arguments, which is what we expect.
Good to know.



Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:50
+static const char PushBackOrEmplaceBackCallName[] =
+"push_back_or_emplace_back_call";
 static const char LoopInitVarName[] = "loop_init_var";

nit: No need for the actual strings to be that long, since you're only using 
the corresponding constant names in the code. Even though there's no small 
string optimization used for bound AST nodes (they are stored in a 
`std::map`), maps are frequently 
compared, which is less wasteful with shorter strings.

It would be interesting to see how large is the impact of longer or shorter 
string IDs, but until then we can still avoid overly long names.



Comment at: test/clang-tidy/performance-inefficient-vector-operation.cpp:158
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size());
+for (const auto  : t) {

This pattern is ambiguous. I'd use unique variable name for each test to avoid 
patterns matching incorrect lines.


https://reviews.llvm.org/D33209



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


[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-16 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG once the comments are addressed.


https://reviews.llvm.org/D33209



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


[clang-tools-extra] r303151 - Restored r303067 and fixed failing test.

2017-05-16 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue May 16 04:38:59 2017
New Revision: 303151

URL: http://llvm.org/viewvc/llvm-project?rev=303151=rev
Log:
Restored r303067 and fixed failing test.

Summary:
This commit restores r303067(reverted by r303094) and fixes the 
'formatting.test'
failure.
The failure is due to destructors of `ClangdLSPServer`'s fields(`FixItsMap` and
`FixItsMutex`) being called before destructor of `Server`. It led to the worker
thread calling `consumeDiagnostics` after `FixItsMutex` and `FixItsMap`
destructors were called.
Also, clangd is now run with '-run-synchronously' flag in 'formatting.test'.

Reviewers: bkramer, krasimir

Reviewed By: krasimir

Subscribers: mgorny, cfe-commits, klimek

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

Added:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
  - copied, changed from r303093, 
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
clang-tools-extra/trunk/clangd/DraftStore.cpp
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/DraftStore.cpp
clang-tools-extra/trunk/clangd/DraftStore.h
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/DraftStore.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
  - copied unchanged from r303093, 
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/clangd/Path.h
  - copied unchanged from r303093, clang-tools-extra/trunk/clangd/Path.h
Removed:
clang-tools-extra/trunk/clangd/ASTManager.cpp
clang-tools-extra/trunk/clangd/ASTManager.h
clang-tools-extra/trunk/clangd/DocumentStore.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdMain.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/test/clangd/formatting.test

Removed: clang-tools-extra/trunk/clangd/ASTManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.cpp?rev=303150=auto
==
--- clang-tools-extra/trunk/clangd/ASTManager.cpp (original)
+++ clang-tools-extra/trunk/clangd/ASTManager.cpp (removed)
@@ -1,440 +0,0 @@
-//===--- ASTManager.cpp - Clang AST manager 
---===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "ASTManager.h"
-#include "JSONRPCDispatcher.h"
-#include "Protocol.h"
-#include "clang/Frontend/ASTUnit.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Tooling/CompilationDatabase.h"
-#include "llvm/Support/Format.h"
-#include "llvm/Support/Path.h"
-#include 
-#include 
-using namespace clang;
-using namespace clangd;
-
-void DocData::setAST(std::unique_ptr AST) {
-  this->AST = std::move(AST);
-}
-
-ASTUnit *DocData::getAST() const { return AST.get(); }
-
-void DocData::cacheFixIts(DiagnosticToReplacementMap FixIts) {
-  this->FixIts = std::move(FixIts);
-}
-
-std::vector
-DocData::getFixIts(const clangd::Diagnostic ) const {
-  auto it = FixIts.find(D);
-  if (it != FixIts.end())
-return it->second;
-  return {};
-}
-
-ASTManagerRequest::ASTManagerRequest(ASTManagerRequestType Type,
- std::string File,
- DocVersion Version)
-: Type(Type), File(File), Version(Version) {}
-
-/// Retrieve a copy of the contents of every file in the store, for feeding 
into
-/// ASTUnit.
-static std::vector
-getRemappedFiles(const DocumentStore ) {
-  // FIXME: Use VFS instead. This would allow us to get rid of the chdir 

[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 99124.
hokein marked 3 inline comments as done.
hokein added a comment.

Improve tests.


https://reviews.llvm.org/D33209

Files:
  clang-tidy/performance/InefficientVectorOperationCheck.cpp
  docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
  test/clang-tidy/performance-inefficient-vector-operation.cpp

Index: test/clang-tidy/performance-inefficient-vector-operation.cpp
===
--- test/clang-tidy/performance-inefficient-vector-operation.cpp
+++ test/clang-tidy/performance-inefficient-vector-operation.cpp
@@ -35,6 +35,9 @@
   explicit vector(size_type n);
 
   void push_back(const T& val);
+
+  template  void emplace_back(Args &&... args);
+
   void reserve(size_t n);
   void resize(size_t n);
 
@@ -61,205 +64,214 @@
 
 void f(std::vector& t) {
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(10);
+std::vector v0;
+// CHECK-FIXES: v0.reserve(10);
 for (int i = 0; i < 10; ++i)
-  v.push_back(i);
+  v0.push_back(i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the vector capacity before the loop
   }
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(10);
+std::vector v1;
+// CHECK-FIXES: v1.reserve(10);
 for (int i = 0; i < 10; i++)
-  v.push_back(i);
+  v1.push_back(i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
   }
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(10);
+std::vector v2;
+// CHECK-FIXES: v2.reserve(10);
 for (int i = 0; i < 10; ++i)
-  v.push_back(0);
+  v2.push_back(0);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
   }
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(5);
+std::vector v3;
+// CHECK-FIXES: v3.reserve(5);
 for (int i = 0; i < 5; ++i) {
-  v.push_back(i);
+  v3.push_back(i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
 }
-// CHECK-FIXES-NOT: v.reserve(10);
+// CHECK-FIXES-NOT: v3.reserve(10);
 for (int i = 0; i < 10; ++i) {
   // No fix for this loop as we encounter the prior loops.
-  v.push_back(i);
+  v3.push_back(i);
 }
   }
   {
-std::vector v;
-std::vector v2;
-v2.reserve(3);
-// CHECK-FIXES: v.reserve(10);
+std::vector v4;
+std::vector v5;
+v5.reserve(3);
+// CHECK-FIXES: v4.reserve(10);
 for (int i = 0; i < 10; ++i)
-  v.push_back(i);
+  v4.push_back(i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
   }
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(t.size());
+std::vector v6;
+// CHECK-FIXES: v6.reserve(t.size());
 for (std::size_t i = 0; i < t.size(); ++i) {
-  v.push_back(t[i]);
+  v6.push_back(t[i]);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
 }
   }
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(t.size() - 1);
+std::vector v7;
+// CHECK-FIXES: v7.reserve(t.size() - 1);
 for (std::size_t i = 0; i < t.size() - 1; ++i) {
-  v.push_back(t[i]);
+  v7.push_back(t[i]);
 } // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
   }
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(t.size());
+std::vector v8;
+// CHECK-FIXES: v8.reserve(t.size());
 for (const auto  : t) {
-  v.push_back(e);
+  v8.push_back(e);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
 }
   }
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(t.size());
+std::vector v9;
+// CHECK-FIXES: v9.reserve(t.size());
 for (const auto  : t) {
-  v.push_back(Op(e));
+  v9.push_back(Op(e));
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
 }
   }
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(t.size());
+std::vector v10;
+// CHECK-FIXES: v10.reserve(t.size());
 for (const auto  : t) {
-  v.push_back(Foo(e));
+  v10.push_back(Foo(e));
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
 }
   }
   {
-std::vector v;
-// CHECK-FIXES: v.reserve(t.size());
+std::vector v11;
+// CHECK-FIXES: v11.reserve(t.size());
 for (const auto  : t) {
-  v.push_back(e);
+  v11.push_back(e);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
 }
   }
+  {
+std::vector v12;
+// CHECK-FIXES: v12.reserve(t.size());
+for (const auto  : t) {
+  v12.emplace_back(e);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'emplace_back' is called
+}
+  }
+
   //  Non-fixed Cases 
   {
-std::vector v;
-v.reserve(20);
-// CHECK-FIXES-NOT: v.reserve(10);
+std::vector z0;
+z0.reserve(20);
+// CHECK-FIXES-NOT: z0.reserve(10);
 // There is a "reserve" call already.
 for (int i = 0; i < 10; ++i) {
-  

[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:50
+static const char PushBackOrEmplaceBackCallName[] =
+"push_back_or_emplace_back_call";
 static const char LoopInitVarName[] = "loop_init_var";

alexfh wrote:
> nit: No need for the actual strings to be that long, since you're only using 
> the corresponding constant names in the code. Even though there's no small 
> string optimization used for bound AST nodes (they are stored in a 
> `std::map`), maps are frequently 
> compared, which is less wasteful with shorter strings.
> 
> It would be interesting to see how large is the impact of longer or shorter 
> string IDs, but until then we can still avoid overly long names.
Acknowledged. Thanks for the detailed explanation ;)



Comment at: test/clang-tidy/performance-inefficient-vector-operation.cpp:158
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size());
+for (const auto  : t) {

alexfh wrote:
> This pattern is ambiguous. I'd use unique variable name for each test to 
> avoid patterns matching incorrect lines.
Sounds good. Also applied the change to the whole test file.


https://reviews.llvm.org/D33209



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


[clang-tools-extra] r303154 - Fixing compilation failures on buildbots.

2017-05-16 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue May 16 05:06:20 2017
New Revision: 303154

URL: http://llvm.org/viewvc/llvm-project?rev=303154=rev
Log:
Fixing compilation failures on buildbots.

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/DraftStore.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=303154=303153=303154=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue May 16 05:06:20 2017
@@ -14,6 +14,7 @@
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/Support/FileSystem.h"
 
+using namespace clang;
 using namespace clang::clangd;
 
 WorkerRequest::WorkerRequest(WorkerRequestKind Kind, Path File,

Modified: clang-tools-extra/trunk/clangd/DraftStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/DraftStore.cpp?rev=303154=303153=303154=diff
==
--- clang-tools-extra/trunk/clangd/DraftStore.cpp (original)
+++ clang-tools-extra/trunk/clangd/DraftStore.cpp Tue May 16 05:06:20 2017
@@ -9,6 +9,7 @@
 
 #include "DraftStore.h"
 
+using namespace clang;
 using namespace clang::clangd;
 
 VersionedDraft DraftStore::getDraft(PathRef File) const {

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h?rev=303154=303153=303154=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h Tue May 16 
05:06:20 2017
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringMap.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 


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


r303156 - Fix PR 10758: Infinite recursion when dealing with copy-initialization

2017-05-16 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue May 16 05:23:58 2017
New Revision: 303156

URL: http://llvm.org/viewvc/llvm-project?rev=303156=rev
Log:
Fix PR 10758: Infinite recursion when dealing with copy-initialization

This commit fixes a bug that's tracked by PR 10758 and duplicates like PR 30343.
The bug causes clang to crash with a stack overflow while recursing infinitely
trying to perform copy-initialization on a type without a copy constructor but
with a constructor that accepts another type that can be constructed using the
original type.

The commit fixes this bug by detecting the recursive behavior and failing
correctly with an appropriate error message. It also tries to provide a
meaningful diagnostic note about the constructor which leads to this behavior.

rdar://28483944

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaCXX/constructor-initializer.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=303156=303155=303156=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue May 16 05:23:58 2017
@@ -1074,6 +1074,10 @@ public:
   /// correctly named definition after the renamed definition.
   llvm::SmallPtrSet TypoCorrectedFunctionDefinitions;
 
+  /// Stack of types that correspond to the parameter entities that are
+  /// currently being copy-initialized. Can be empty.
+  llvm::SmallVector CurrentParameterCopyTypes;
+
   void ReadMethodPool(Selector Sel);
   void updateOutOfDateSelector(Selector Sel);
 

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=303156=303155=303156=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue May 16 05:23:58 2017
@@ -8296,8 +8296,46 @@ Sema::PerformCopyInitialization(const In
AllowExplicit);
   InitializationSequence Seq(*this, Entity, Kind, InitE, TopLevelOfInitList);
 
+  // Prevent infinite recursion when performing parameter copy-initialization.
+  const bool ShouldTrackCopy =
+  Entity.isParameterKind() && Seq.isConstructorInitialization();
+  if (ShouldTrackCopy) {
+if (llvm::find(CurrentParameterCopyTypes, Entity.getType()) !=
+CurrentParameterCopyTypes.end()) {
+  Seq.SetOverloadFailure(
+  InitializationSequence::FK_ConstructorOverloadFailed,
+  OR_No_Viable_Function);
+
+  // Try to give a meaningful diagnostic note for the problematic
+  // constructor.
+  const auto LastStep = Seq.step_end() - 1;
+  assert(LastStep->Kind ==
+ InitializationSequence::SK_ConstructorInitialization);
+  const FunctionDecl *Function = LastStep->Function.Function;
+  auto Candidate =
+  llvm::find_if(Seq.getFailedCandidateSet(),
+[Function](const OverloadCandidate ) -> bool 
{
+  return Candidate.Viable &&
+ Candidate.Function == Function &&
+ Candidate.Conversions.size() > 0;
+});
+  if (Candidate != Seq.getFailedCandidateSet().end() &&
+  Function->getNumParams() > 0) {
+Candidate->Viable = false;
+Candidate->FailureKind = ovl_fail_bad_conversion;
+Candidate->Conversions[0].setBad(BadConversionSequence::no_conversion,
+ InitE,
+ Function->getParamDecl(0)->getType());
+  }
+}
+CurrentParameterCopyTypes.push_back(Entity.getType());
+  }
+
   ExprResult Result = Seq.Perform(*this, Entity, Kind, InitE);
 
+  if (ShouldTrackCopy)
+CurrentParameterCopyTypes.pop_back();
+
   return Result;
 }
 

Modified: cfe/trunk/test/SemaCXX/constructor-initializer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor-initializer.cpp?rev=303156=303155=303156=diff
==
--- cfe/trunk/test/SemaCXX/constructor-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor-initializer.cpp Tue May 16 05:23:58 2017
@@ -302,3 +302,22 @@ namespace PR14073 {
   struct S2 { union { union { int n; }; char c; }; S2() : n(n) {} };  // 
expected-warning {{field 'n' is uninitialized when used here}}
   struct S3 { struct { int n; }; S3() : n(n) {} };  // expected-warning 
{{field 'n' is uninitialized when used here}}
 }
+
+namespace PR10758 {
+struct A;
+struct B {
+  B (A const &); // expected-note 2 {{candidate constructor not viable: no 
known conversion from 'const PR10758::B' to 'const PR10758::A &' 

[PATCH] D25051: Fix PR 10758: Infinite recursion when dealing with copy-initialization

2017-05-16 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303156: Fix PR 10758: Infinite recursion when dealing with 
copy-initialization (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D25051?vs=96122=99125#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25051

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaInit.cpp
  cfe/trunk/test/SemaCXX/constructor-initializer.cpp


Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1074,6 +1074,10 @@
   /// correctly named definition after the renamed definition.
   llvm::SmallPtrSet TypoCorrectedFunctionDefinitions;
 
+  /// Stack of types that correspond to the parameter entities that are
+  /// currently being copy-initialized. Can be empty.
+  llvm::SmallVector CurrentParameterCopyTypes;
+
   void ReadMethodPool(Selector Sel);
   void updateOutOfDateSelector(Selector Sel);
 
Index: cfe/trunk/test/SemaCXX/constructor-initializer.cpp
===
--- cfe/trunk/test/SemaCXX/constructor-initializer.cpp
+++ cfe/trunk/test/SemaCXX/constructor-initializer.cpp
@@ -302,3 +302,22 @@
   struct S2 { union { union { int n; }; char c; }; S2() : n(n) {} };  // 
expected-warning {{field 'n' is uninitialized when used here}}
   struct S3 { struct { int n; }; S3() : n(n) {} };  // expected-warning 
{{field 'n' is uninitialized when used here}}
 }
+
+namespace PR10758 {
+struct A;
+struct B {
+  B (A const &); // expected-note 2 {{candidate constructor not viable: no 
known conversion from 'const PR10758::B' to 'const PR10758::A &' for 1st 
argument}}
+  B (B &); // expected-note 2 {{candidate constructor not viable: 1st argument 
('const PR10758::B') would lose const qualifier}}
+};
+struct A {
+  A (B); // expected-note 2 {{passing argument to parameter here}}
+};
+
+B f(B const ) {
+  return b; // expected-error {{no matching constructor for initialization of 
'PR10758::B'}}
+}
+
+A f2(const B ) {
+  return b; // expected-error {{no matching constructor for initialization of 
'PR10758::B'}}
+}
+}
Index: cfe/trunk/lib/Sema/SemaInit.cpp
===
--- cfe/trunk/lib/Sema/SemaInit.cpp
+++ cfe/trunk/lib/Sema/SemaInit.cpp
@@ -8296,8 +8296,46 @@
AllowExplicit);
   InitializationSequence Seq(*this, Entity, Kind, InitE, TopLevelOfInitList);
 
+  // Prevent infinite recursion when performing parameter copy-initialization.
+  const bool ShouldTrackCopy =
+  Entity.isParameterKind() && Seq.isConstructorInitialization();
+  if (ShouldTrackCopy) {
+if (llvm::find(CurrentParameterCopyTypes, Entity.getType()) !=
+CurrentParameterCopyTypes.end()) {
+  Seq.SetOverloadFailure(
+  InitializationSequence::FK_ConstructorOverloadFailed,
+  OR_No_Viable_Function);
+
+  // Try to give a meaningful diagnostic note for the problematic
+  // constructor.
+  const auto LastStep = Seq.step_end() - 1;
+  assert(LastStep->Kind ==
+ InitializationSequence::SK_ConstructorInitialization);
+  const FunctionDecl *Function = LastStep->Function.Function;
+  auto Candidate =
+  llvm::find_if(Seq.getFailedCandidateSet(),
+[Function](const OverloadCandidate ) -> bool 
{
+  return Candidate.Viable &&
+ Candidate.Function == Function &&
+ Candidate.Conversions.size() > 0;
+});
+  if (Candidate != Seq.getFailedCandidateSet().end() &&
+  Function->getNumParams() > 0) {
+Candidate->Viable = false;
+Candidate->FailureKind = ovl_fail_bad_conversion;
+Candidate->Conversions[0].setBad(BadConversionSequence::no_conversion,
+ InitE,
+ Function->getParamDecl(0)->getType());
+  }
+}
+CurrentParameterCopyTypes.push_back(Entity.getType());
+  }
+
   ExprResult Result = Seq.Perform(*this, Entity, Kind, InitE);
 
+  if (ShouldTrackCopy)
+CurrentParameterCopyTypes.pop_back();
+
   return Result;
 }
 


Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1074,6 +1074,10 @@
   /// correctly named definition after the renamed definition.
   llvm::SmallPtrSet TypoCorrectedFunctionDefinitions;
 
+  /// Stack of types that correspond to the parameter entities that are
+  /// currently being copy-initialized. Can be empty.
+  llvm::SmallVector CurrentParameterCopyTypes;
+
   void ReadMethodPool(Selector Sel);
   void 

[PATCH] D33207: Fix an assertion failure in FormatASTNodeDiagnosticArgument.

2017-05-16 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: test/SemaCXX/warn-shadow.cpp:214
+void handleLinkageSpec() {
+  typedef void externC; // expected-warning {{declaration shadows a typedef in 
linkage specification}}
+}

rsmith wrote:
> We should be producing a diagnostic talking about the enclosing namespace / 
> TU scope, not the linkage specification. Whoever is emitting the diagnostic 
> seems to be missing a call to `getRedeclContext()` -- although perhaps we 
> could do that in the diagnostic code instead.
I tried skipping transparent declaration contexts in 
`FormatASTNodeDiagnosticArgument`, but this causes three tests fail due to 
skipped enumeration names:
  error: 'error' diagnostics expected but not seen: 
File /src/tools/clang/test/Modules/Inputs/odr/b.h Line 5 (directive at 
/src/tools/clang/test/Modules/odr.cpp:21): 'E::e2' from module 'b' is not 
present in definition of 'E' in module 'a'
  error: 'error' diagnostics seen but not expected: 
File /src/tools/clang/test/Modules/Inputs/odr/b.h Line 5: 'E::e2' from 
module 'b' is not present in definition of the global namespace in module 'a'

  error: 'error' diagnostics expected but not seen: 
File /src/tools/clang/test/SemaCXX/nested-name-spec.cpp Line 434: no member 
named 'X2' in 'PR16951::enumerator_2'
  error: 'error' diagnostics seen but not expected: 
File /src/tools/clang/test/SemaCXX/nested-name-spec.cpp Line 434: no member 
named 'X2' in namespace 'PR16951'

  error: 'error' diagnostics expected but not seen: 
File /src/tools/clang/test/SemaTemplate/instantiate-non-dependent-types.cpp 
Line 26 (directive at 
/src/tools/clang/test/SemaTemplate/instantiate-non-dependent-types.cpp:25): no 
member named '~Colors' in 'Colors'
  error: 'error' diagnostics seen but not expected: 
File /src/tools/clang/test/SemaTemplate/instantiate-non-dependent-types.cpp 
Line 26: no member named '~Colors' in the global namespace

This doesn't seem right, so I changed the code emitting `-Wshadow` to use 
`getRedeclContext()` instead. PTAL


https://reviews.llvm.org/D33207



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1120
+address.getPointer()->getType()->getPointerElementType()->getPointerTo(
+getContext().getTargetAddressSpace(T.getAddressSpace())),
+/*non-null*/ true);

A lot of this line can be address.getElementType().



Comment at: lib/CodeGen/CodeGenTypes.cpp:95
 
-
 /// isRecordLayoutComplete - Return true if the specified type is already

Did you intend to change this file?



Comment at: lib/CodeGen/TargetInfo.cpp:7296
+  unsigned getASTAllocaAddressSpace() const override {
+return LangAS::Count + getABIInfo().getDataLayout().getAllocaAddrSpace();
+  }

Can we rename LangAS::Count to something more meaningful like 
LangAS::FirstTargetAddressSpace?  I think this would clarify a lot of code.

Is the OpenCL special case in ASTContext::getTargetAddressSpace still correct 
with this patch?  A pointer in LangAS::Default should be lowered as a generic 
pointer instead of a pointer into the alloca address space, right?


https://reviews.llvm.org/D32248



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


[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-16 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:208
+   "consider pre-allocating the vector capacity before the loop")
+  << VectorAppendCall->getMethodDecl()->getDeclName();
 

Diagnostic builder should be able to format NamedDecls directly, this 
`->getDeclName()` is not necessary. The only difference is that it will likely 
add quotes around the name, which seems to be good anyway.


Repository:
  rL LLVM

https://reviews.llvm.org/D33209



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


[PATCH] D33207: Fix an assertion failure in FormatASTNodeDiagnosticArgument.

2017-05-16 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh updated this revision to Diff 99112.
alexfh added a comment.
Herald added a subscriber: krytarowski.

Instead of handling LinkageSpecDecl, use getRedeclContext() when issuing 
-Wshadow diagnostic.


https://reviews.llvm.org/D33207

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/warn-shadow.cpp


Index: test/SemaCXX/warn-shadow.cpp
===
--- test/SemaCXX/warn-shadow.cpp
+++ test/SemaCXX/warn-shadow.cpp
@@ -206,3 +206,10 @@
 }
 
 }
+
+extern "C" {
+typedef int externC; // expected-note {{previous declaration is here}}
+}
+void handleLinkageSpec() {
+  typedef void externC; // expected-warning {{declaration shadows a typedef in 
the global namespace}}
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -6942,7 +6942,7 @@
 }
 }
 
-  DeclContext *OldDC = ShadowedDecl->getDeclContext();
+  DeclContext *OldDC = ShadowedDecl->getDeclContext()->getRedeclContext();
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;


Index: test/SemaCXX/warn-shadow.cpp
===
--- test/SemaCXX/warn-shadow.cpp
+++ test/SemaCXX/warn-shadow.cpp
@@ -206,3 +206,10 @@
 }
 
 }
+
+extern "C" {
+typedef int externC; // expected-note {{previous declaration is here}}
+}
+void handleLinkageSpec() {
+  typedef void externC; // expected-warning {{declaration shadows a typedef in the global namespace}}
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -6942,7 +6942,7 @@
 }
 }
 
-  DeclContext *OldDC = ShadowedDecl->getDeclContext();
+  DeclContext *OldDC = ShadowedDecl->getDeclContext()->getRedeclContext();
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-05-16 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki updated this revision to Diff 99114.
danielmarjamaki added a comment.

Fix review comments


Repository:
  rL LLVM

https://reviews.llvm.org/D31029

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  lib/StaticAnalyzer/Core/ExprEngineC.cpp


Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-Loc X = svalBuilder.makeNull();
+Loc X = svalBuilder.makeNullWithType(Ex->getType());
 Result = evalBinOp(state, BO_EQ, *LV, X, U->getType());
-  }
-  else if (Ex->getType()->isFloatingType()) {
+  } else if (Ex->getType()->isFloatingType()) {
 // FIXME: handle floating point types.
 Result = UnknownVal();
   } else {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -315,10 +315,15 @@
 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
   }
 
-  Loc makeNull() {
-return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
+  /// Create NULL pointer, with proper pointer bit-width for given address
+  /// space.
+  /// \param type pointer type.
+  Loc makeNullWithType(QualType type) {
+return loc::ConcreteInt(BasicVals.getZeroWithTypeSize(type));
   }
 
+  Loc makeNull() { return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth()); }
+
   Loc makeLoc(SymbolRef sym) {
 return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -180,7 +180,12 @@
 return getValue(X);
   }
 
-  inline const llvm::APSInt& getZeroWithPtrWidth(bool isUnsigned = true) {
+  inline const llvm::APSInt (QualType T) {
+assert(T->isScalarType());
+return getValue(0, Ctx.getTypeSize(T), true);
+  }
+
+  inline const llvm::APSInt (bool isUnsigned = true) {
 return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
   }
 


Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-Loc X = svalBuilder.makeNull();
+Loc X = svalBuilder.makeNullWithType(Ex->getType());
 Result = evalBinOp(state, BO_EQ, *LV, X, U->getType());
-  }
-  else if (Ex->getType()->isFloatingType()) {
+  } else if (Ex->getType()->isFloatingType()) {
 // FIXME: handle floating point types.
 Result = UnknownVal();
   } else {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -315,10 +315,15 @@
 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
   }
 
-  Loc makeNull() {
-return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
+  /// Create NULL pointer, with proper pointer bit-width for given address
+  /// space.
+  /// \param type pointer type.
+  Loc makeNullWithType(QualType type) {
+return loc::ConcreteInt(BasicVals.getZeroWithTypeSize(type));
   }
 
+  Loc makeNull() { return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth()); }
+
   Loc makeLoc(SymbolRef sym) {
 return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -180,7 +180,12 @@
 return getValue(X);
   }
 
-  inline const llvm::APSInt& getZeroWithPtrWidth(bool isUnsigned = true) {
+  inline const llvm::APSInt (QualType T) {
+assert(T->isScalarType());
+return getValue(0, Ctx.getTypeSize(T), true);
+  }
+
+  inline const llvm::APSInt (bool isUnsigned = true) {
 return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
   }
 
___

[PATCH] D33053: [PowerPC] Implement vec_xxpermdi builtin.

2017-05-16 Thread Tony Jiang via Phabricator via cfe-commits
jtony marked 6 inline comments as done.
jtony added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:8433
+if (getTarget().isLittleEndian()) {
+  switch (Index) {
+  case 0:

nemanjai wrote:
> The switch is overkill. You should just implement this in an obvious way 
> (i.e. the same way as described in the ISA).
> For big endian:
> `ElemIdx0 = (Index & 2;) >> 1`
> `ElemIdx1 = 2 + (Index & 1)`
> 
> For little endian:
> `ElemIdx0 = (~Index & 1) + 2;`
> `ElemIdx1 = ~Index & 2 >> 1;`
> 
> (of course, please verify the expressions).
Good call, fixed as suggested.


https://reviews.llvm.org/D33053



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


[libunwind] r303206 - [libunwind] Fix executable stack directive on Linux.

2017-05-16 Thread Manoj Gupta via cfe-commits
Author: manojgupta
Date: Tue May 16 15:18:57 2017
New Revision: 303206

URL: http://llvm.org/viewvc/llvm-project?rev=303206=rev
Log:
[libunwind] Fix executable stack directive on Linux.

Summary:
Disable executable stack on Linux. Also remove redundant Android check
as it is covered by Android.

Reviewers: phosek, compnerd, rs, rmaprath, EricWF, krytarowski

Reviewed By: krytarowski

Subscribers: srhines, llvm-commits, krytarowski

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

Modified:
libunwind/trunk/src/assembly.h

Modified: libunwind/trunk/src/assembly.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/assembly.h?rev=303206=303205=303206=diff
==
--- libunwind/trunk/src/assembly.h (original)
+++ libunwind/trunk/src/assembly.h Tue May 16 15:18:57 2017
@@ -47,8 +47,8 @@
 #define SYMBOL_IS_FUNC(name) .type name,@function
 #endif
 
-#if defined(__GNU__) || defined(__ANDROID__) || defined(__FreeBSD__) || \
-defined(__Fuchsia__)
+#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
+defined(__linux__)
 #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
 #else
 #define NO_EXEC_STACK_DIRECTIVE


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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:7296
+  unsigned getASTAllocaAddressSpace() const override {
+return LangAS::Count + getABIInfo().getDataLayout().getAllocaAddrSpace();
+  }

rjmccall wrote:
> yaxunl wrote:
> > rjmccall wrote:
> > > Can we rename LangAS::Count to something more meaningful like 
> > > LangAS::FirstTargetAddressSpace?  I think this would clarify a lot of 
> > > code.
> > > 
> > > Is the OpenCL special case in ASTContext::getTargetAddressSpace still 
> > > correct with this patch?  A pointer in LangAS::Default should be lowered 
> > > as a generic pointer instead of a pointer into the alloca address space, 
> > > right?
> > Will do.
> > 
> > The OpenCL special case in ASTContext::getTargetAddressSpace is still 
> > correct with this patch. In OpenCL private address space is still 
> > represented in AST by LangAS::Default, so a pointer in LangAS::Default 
> > should be lowered as a pointer to alloca address space.
> Then I don't understand.  If __private is always the alloca address space, 
> why does IRGen have to add addrspace casts after allocating local variables 
> in it?  IRGen's invariant is that the value stored in LocalDeclMap for a 
> variable of AST type T is a value of type [[T]] addrspace([[AS]]) *, where 
> [[T]] is the lowered IR type for T and [[AS]] is the target address space of 
> the variable.  For auto variables, AS is always LangAS::Default, which 
> according to you means that [[AS]] is always LLVM's notion of the alloca 
> address space, which is exactly the type produced by alloca.  So why is there 
> ever a cast?
> 
> My understanding was that, on your target, __private is (at least sometimes) 
> a 64-bit extension of the alloca address space, which is 32-bit.  But that 
> makes __private a different address space from the alloca address space, so 
> the special case in getTargetAddressSpace is still wrong, because that 
> special case means that a pointer-to-__private type will be lowered to be a 
> 32-bit pointer type.
> 
> Also, I'm not sure why the normal AddrSpaceMap mechanism isn't sufficient for 
> mapping LangAS::Default.
This work is mostly for C++.

For OpenCL, the default address space is mapped to alloca address space (5), 
there is no address space cast inserted.

For C++, the default address space is mapped to generic address space (0), 
therefore the address space cast is needed.


https://reviews.llvm.org/D32248



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


[libcxxabi] r303194 - [libcxxabi] Fix the test case committed in r303175.

2017-05-16 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue May 16 13:18:03 2017
New Revision: 303194

URL: http://llvm.org/viewvc/llvm-project?rev=303194=rev
Log:
[libcxxabi] Fix the test case committed in r303175.

Free the __cxa_exception object allocated with __cxa_allocate_exception.

This is an attempt to fix this asan bot:

http://lab.llvm.org:8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-asan/builds/560

Modified:
libcxxabi/trunk/test/exception_object_alignment.pass.cpp

Modified: libcxxabi/trunk/test/exception_object_alignment.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/exception_object_alignment.pass.cpp?rev=303194=303193=303194=diff
==
--- libcxxabi/trunk/test/exception_object_alignment.pass.cpp (original)
+++ libcxxabi/trunk/test/exception_object_alignment.pass.cpp Tue May 16 
13:18:03 2017
@@ -28,6 +28,7 @@ int main() {
   auto i = reinterpret_cast(p);
   auto a = std::alignment_of::value;
   assert(i % a == 0);
+  __cxxabiv1::__cxa_free_exception(p);
 #endif
   return 0;
 }


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


Re: r302966 - Remove unused tracking of owning module for MacroInfo objects.

2017-05-16 Thread Vitaly Buka via cfe-commits
The patch breaks this test
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/1349/steps/check-clang%20msan/logs/stdio

Script:
--
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm_build_msan/./bin/clang
-cc1 -internal-isystem
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm_build_msan/lib/clang/5.0.0/include
-nostdsysteminc -verify -fms-extensions -Wmicrosoft
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c
not
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm_build_msan/./bin/clang
-cc1 -internal-isystem
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm_build_msan/lib/clang/5.0.0/include
-nostdsysteminc -P -E -fms-extensions
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c
|
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm_build_msan/./bin/FileCheck
-strict-whitespace
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c
--
Exit Code: 1

Command Output (stderr):
--
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:35:1:
error: pasting formed '(baz', an invalid preprocessing token
bar(q) // expected-warning {{type specifier missing}} expected-error
{{invalid preprocessing token}} expected-error {{parameter list without
types}}
^
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:34:20:
note: expanded from macro 'bar'
#define bar(y) foo(##baz(y))
   ^
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:42:1:
error: pasting formed '1a-', an invalid preprocessing token
collapse_spaces(1a, b2, 3c, d4) // expected-error 4 {{invalid preprocessing
token}} expected-error {{expected function body}}
^
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:41:43:
note: expanded from macro 'collapse_spaces'
#define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d)
  ^
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:42:1:
error: pasting formed '-b2', an invalid preprocessing token
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:41:48:
note: expanded from macro 'collapse_spaces'
#define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d)
   ^
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:42:1:
error: pasting formed 'b2-', an invalid preprocessing token
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:41:53:
note: expanded from macro 'collapse_spaces'
#define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d)
^
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:42:1:
error: pasting formed '-3c', an invalid preprocessing token
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:41:58:
note: expanded from macro 'collapse_spaces'
#define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d)
 ^
5 errors generated.
/mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:44:11:
error: expected string not found in input
// CHECK: "1a-b2-3cd4"
  ^
:34:1: note: scanning from here
"1a-b2- 3cd4"
^


On Mon, May 15, 2017 at 10:28 AM Jordan Rose via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hi, Richard. Swift was using this information in order to put imported
> macros in a particular context. It wouldn't surprise me to hear that we
> were doing it wrong, and that there's a better way to go from a macro back
> to a module, but is there a recommended replacement?
>
> Thanks,
> Jordan
>
>
> > On May 12, 2017, at 16:40, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > Author: rsmith
> > Date: Fri May 12 18:40:52 2017
> > New Revision: 302966
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=302966=rev
> > Log:
> > Remove unused tracking of owning module for MacroInfo objects.
> >
> > Modified:
> >cfe/trunk/include/clang/Lex/MacroInfo.h
> >

[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/CodeGen/CodeGenTypes.cpp:95
 
-
 /// isRecordLayoutComplete - Return true if the specified type is already

Why this change?



Comment at: lib/CodeGen/TargetInfo.cpp:411
+CodeGen::CodeGenFunction , llvm::Value *Src, unsigned SrcAddr,
+unsigned DestAddr, llvm::Type *DestTy, bool isNonNull) const {
   // Since target may map different address spaces in AST to the same address

Seems like some parameters are unused.



Comment at: lib/Sema/SemaDecl.cpp:7206
+assert(T.getAddressSpace() != LangAS::opencl_constant);
+if (T.getAddressSpace() == LangAS::opencl_global) {
+  Diag(NewVD->getLocation(), diag::err_opencl_function_variable)

I think it was nicer that all OpenCL related changes were grouped in one spot 
under the same if statement. Even though it isn't quite done everywhere. But 
this change makes them even more scattered.



Comment at: test/CodeGenCXX/amdgcn-automatic-variable.cpp:25
+  // CHECK: store i32 2, i32* %[[r1]]
+  int lv1;
+  lv1 = 1;

yaxunl wrote:
> yaxunl wrote:
> > Anastasia wrote:
> > > I am wondering if all these different test cases are really needed. Are 
> > > we testing any different program paths from the patch?
> > > 
> > > Also would it make sense to add a test case with an object in an AS 
> > > different to 0 (i.e. with `__attribute__((address_space(n)))`)
> > I think at least I should cover the typical use cases of auto var.
> > 
> > I will add a test for __attribute__((address_space(n
> Sorry. I just checked that C++ does not allow 
> __attribute__((address_space(n))) on automatic var.
I thought address space was undocumented extension. So essentially you can't 
have a cast to any address space but a default here? Would it work for the C 
instead to add `attribute((address_space(n)))`?



Comment at: test/SemaOpenCL/storageclass-cl20.cl:16
+  global int L3;  // expected-error{{function 
scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L4; // expected-error{{automatic 
variable qualified with an invalid address space}}
 

I am guessing generic should be rejected here as well... although it should 
only apply to pointers. But it seems we don't handle this properly.


https://reviews.llvm.org/D32248



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


Re: r302966 - Remove unused tracking of owning module for MacroInfo objects.

2017-05-16 Thread Richard Smith via cfe-commits
On 16 May 2017 at 11:54, Vitaly Buka  wrote:

> The patch breaks this test http://lab.llvm.org:8011/
> builders/sanitizer-x86_64-linux-bootstrap/builds/1349/
> steps/check-clang%20msan/logs/stdio
>

Given the nature of this change, that's a surprise, but anything's
possible. How sure are you that it was this change?

Script:
> --
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm_build_msan/./bin/clang -cc1 -internal-isystem
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm_build_msan/lib/clang/5.0.0/include -nostdsysteminc
> -verify -fms-extensions -Wmicrosoft /mnt/b/sanitizer-buildbot2/
> sanitizer-x86_64-linux-bootstrap/build/llvm/tools/
> clang/test/Preprocessor/macro_paste_msextensions.c
> not /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm_build_msan/./bin/clang -cc1 -internal-isystem
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm_build_msan/lib/clang/5.0.0/include -nostdsysteminc
> -P -E -fms-extensions /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c
> | /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm_build_msan/./bin/FileCheck -strict-whitespace
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_
> paste_msextensions.c
> --
> Exit Code: 1
>
> Command Output (stderr):
> --
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:35:1:
> error: pasting formed '(baz', an invalid preprocessing token
> bar(q) // expected-warning {{type specifier missing}} expected-error
> {{invalid preprocessing token}} expected-error {{parameter list without
> types}}
> ^
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:34:20:
> note: expanded from macro 'bar'
> #define bar(y) foo(##baz(y))
>^
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:42:1:
> error: pasting formed '1a-', an invalid preprocessing token
> collapse_spaces(1a, b2, 3c, d4) // expected-error 4 {{invalid
> preprocessing token}} expected-error {{expected function body}}
> ^
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:41:43:
> note: expanded from macro 'collapse_spaces'
> #define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d)
>   ^
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:42:1:
> error: pasting formed '-b2', an invalid preprocessing token
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:41:48:
> note: expanded from macro 'collapse_spaces'
> #define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d)
>^
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:42:1:
> error: pasting formed 'b2-', an invalid preprocessing token
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:41:53:
> note: expanded from macro 'collapse_spaces'
> #define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d)
> ^
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:42:1:
> error: pasting formed '-3c', an invalid preprocessing token
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:41:58:
> note: expanded from macro 'collapse_spaces'
> #define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d)
>  ^
> 5 errors generated.
> /mnt/b/sanitizer-buildbot2/sanitizer-x86_64-linux-
> bootstrap/build/llvm/tools/clang/test/Preprocessor/macro_paste_msextensions.c:44:11:
> error: expected string not found in input
> // CHECK: "1a-b2-3cd4"
>   ^
> :34:1: note: scanning from here
> "1a-b2- 3cd4"
> ^
>
>
> On Mon, May 15, 2017 at 10:28 AM Jordan Rose via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Hi, Richard. Swift was using this information in order to put imported
>> macros in a particular context. It wouldn't surprise me to hear that we
>> were doing it wrong, and that there's a better way to go from a macro back
>> to a module, but is there a recommended replacement?
>>
>> Thanks,
>> Jordan
>>
>>
>> > On May 12, 

[PATCH] D32449: Modifying PthreadLockChecker.cpp to reduce false positives.

2017-05-16 Thread Malhar Thakkar via Phabricator via cfe-commits
malhar1995 updated this revision to Diff 99179.
malhar1995 added a comment.

Added context. 
Also, I removed the inclusion of iostream and also added the repetitive code to 
the function setAppropriateLockState.
Currently working on finding various corner cases and invariants.


Repository:
  rL LLVM

https://reviews.llvm.org/D32449

Files:
  .DS_Store
  lib/.DS_Store
  lib/StaticAnalyzer/.DS_Store
  lib/StaticAnalyzer/Checkers/.DS_Store
  lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp

Index: lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -25,30 +25,34 @@
 namespace {
 
 struct LockState {
-  enum Kind { Destroyed, Locked, Unlocked } K;
+  enum Kind { Destroyed, Locked, Unlocked, SchrodingerLocked, SchrodingerUnlocked } K;
 
 private:
   LockState(Kind K) : K(K) {}
 
 public:
   static LockState getLocked() { return LockState(Locked); }
   static LockState getUnlocked() { return LockState(Unlocked); }
   static LockState getDestroyed() { return LockState(Destroyed); }
+  static LockState getSchrodingerLocked() { return LockState(SchrodingerLocked); }
+  static LockState getSchrodingerUnlocked() { return LockState(SchrodingerUnlocked); }
 
   bool operator==(const LockState ) const {
 return K == X.K;
   }
 
   bool isLocked() const { return K == Locked; }
   bool isUnlocked() const { return K == Unlocked; }
   bool isDestroyed() const { return K == Destroyed; }
+  bool isSchrodingerLocked() const { return K == SchrodingerLocked; }
+  bool isSchrodingerUnlocked() const { return K == SchrodingerUnlocked; }
 
   void Profile(llvm::FoldingSetNodeID ) const {
 ID.AddInteger(K);
   }
 };
 
-class PthreadLockChecker : public Checker< check::PostStmt > {
+class PthreadLockChecker : public Checker< check::PostStmt, check::DeadSymbols > {
   mutable std::unique_ptr BT_doublelock;
   mutable std::unique_ptr BT_doubleunlock;
   mutable std::unique_ptr BT_destroylock;
@@ -61,21 +65,24 @@
   };
 public:
   void checkPostStmt(const CallExpr *CE, CheckerContext ) const;
+  void checkDeadSymbols(SymbolReaper , CheckerContext ) const;
 
   void AcquireLock(CheckerContext , const CallExpr *CE, SVal lock,
bool isTryLock, enum LockingSemantics semantics) const;
 
   void ReleaseLock(CheckerContext , const CallExpr *CE, SVal lock) const;
   void DestroyLock(CheckerContext , const CallExpr *CE, SVal Lock) const;
   void InitLock(CheckerContext , const CallExpr *CE, SVal Lock) const;
   void reportUseDestroyedBug(CheckerContext , const CallExpr *CE) const;
+  ProgramStateRef setAppropriateLockState(ProgramStateRef state, const MemRegion* lockR) const;
 };
 } // end anonymous namespace
 
 // GDM Entry for tracking lock state.
 REGISTER_LIST_WITH_PROGRAMSTATE(LockSet, const MemRegion *)
 
 REGISTER_MAP_WITH_PROGRAMSTATE(LockMap, const MemRegion *, LockState)
+REGISTER_MAP_WITH_PROGRAMSTATE(DestroyRetVal, const MemRegion *, SymbolRef)
 
 void PthreadLockChecker::checkPostStmt(const CallExpr *CE,
CheckerContext ) const {
@@ -120,16 +127,40 @@
 InitLock(C, CE, state->getSVal(CE->getArg(0), LCtx));
 }
 
+ProgramStateRef PthreadLockChecker::setAppropriateLockState(ProgramStateRef state, const MemRegion* lockR) const {
+  const SymbolRef* sym = state->get(lockR);
+  if(sym){
+const LockState* lstate = state->get(lockR);
+if(lstate){
+  ConstraintManager  = state->getConstraintManager();
+  ConditionTruthVal retZero = CMgr.isNull(state, *sym);
+  if(retZero.isConstrainedFalse()){
+if(lstate->isSchrodingerLocked())
+  state = state->set(lockR, LockState::getLocked());
+else if(lstate->isSchrodingerUnlocked())
+  state = state->set(lockR, LockState::getUnlocked());
+  }
+  else{
+if(!lstate || lstate->isSchrodingerLocked() || lstate->isSchrodingerUnlocked())
+  state = state->set(lockR, LockState::getDestroyed());
+  }
+}
+  }
+  return state;
+}
+
 void PthreadLockChecker::AcquireLock(CheckerContext , const CallExpr *CE,
  SVal lock, bool isTryLock,
  enum LockingSemantics semantics) const {
 
   const MemRegion *lockR = lock.getAsRegion();
   if (!lockR)
-return;
+return; 
 
   ProgramStateRef state = C.getState();
 
+  state = setAppropriateLockState(state, lockR);
+
   SVal X = state->getSVal(CE, C.getLocationContext());
   if (X.isUnknownOrUndef())
 return;
@@ -198,6 +229,8 @@
 
   ProgramStateRef state = C.getState();
 
+  state = setAppropriateLockState(state, lockR);
+
   if (const LockState *LState = state->get(lockR)) {
 if (LState->isUnlocked()) {
   if (!BT_doubleunlock)
@@ -253,9 +286,32 @@
 
   ProgramStateRef State = C.getState();
 
+  State = setAppropriateLockState(State, LockR);
+
+  // CHECK 

[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:7296
+  unsigned getASTAllocaAddressSpace() const override {
+return LangAS::Count + getABIInfo().getDataLayout().getAllocaAddrSpace();
+  }

yaxunl wrote:
> rjmccall wrote:
> > yaxunl wrote:
> > > rjmccall wrote:
> > > > Can we rename LangAS::Count to something more meaningful like 
> > > > LangAS::FirstTargetAddressSpace?  I think this would clarify a lot of 
> > > > code.
> > > > 
> > > > Is the OpenCL special case in ASTContext::getTargetAddressSpace still 
> > > > correct with this patch?  A pointer in LangAS::Default should be 
> > > > lowered as a generic pointer instead of a pointer into the alloca 
> > > > address space, right?
> > > Will do.
> > > 
> > > The OpenCL special case in ASTContext::getTargetAddressSpace is still 
> > > correct with this patch. In OpenCL private address space is still 
> > > represented in AST by LangAS::Default, so a pointer in LangAS::Default 
> > > should be lowered as a pointer to alloca address space.
> > Then I don't understand.  If __private is always the alloca address space, 
> > why does IRGen have to add addrspace casts after allocating local variables 
> > in it?  IRGen's invariant is that the value stored in LocalDeclMap for a 
> > variable of AST type T is a value of type [[T]] addrspace([[AS]]) *, where 
> > [[T]] is the lowered IR type for T and [[AS]] is the target address space 
> > of the variable.  For auto variables, AS is always LangAS::Default, which 
> > according to you means that [[AS]] is always LLVM's notion of the alloca 
> > address space, which is exactly the type produced by alloca.  So why is 
> > there ever a cast?
> > 
> > My understanding was that, on your target, __private is (at least 
> > sometimes) a 64-bit extension of the alloca address space, which is 32-bit. 
> >  But that makes __private a different address space from the alloca address 
> > space, so the special case in getTargetAddressSpace is still wrong, because 
> > that special case means that a pointer-to-__private type will be lowered to 
> > be a 32-bit pointer type.
> > 
> > Also, I'm not sure why the normal AddrSpaceMap mechanism isn't sufficient 
> > for mapping LangAS::Default.
> This work is mostly for C++.
> 
> For OpenCL, the default address space is mapped to alloca address space (5), 
> there is no address space cast inserted.
> 
> For C++, the default address space is mapped to generic address space (0), 
> therefore the address space cast is needed.
Wait, I think I might understand.  You're saying that, when you're compiling 
OpenCL, you want __private to just be the normal 32-bit address space, but when 
you're compiling other languages, you want LangAS::Default to be this 64-bit 
extension, probably because those other languages don't break things down in 
address spaces as consistently as OpenCL and so it's more important for 
LangAS::Default to be able to reach across address spaces.

I do not feel that it's correct for this to be hard-coded in ASTContext; it 
really seems like a target-specific policy that should just be reflected in 
AddrSpaceMap.  That does mean that you'll have to find some way of informing 
your TargetInfo that it's building OpenCL.  The normal design for something 
like that would be a target option that the driver would automatically set when 
it recognized that it was building OpenCL; or you could change 
getAddressSpaceMap to take a LangOptions.


https://reviews.llvm.org/D32248



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:411
+CodeGen::CodeGenFunction , llvm::Value *Src, unsigned SrcAddr,
+unsigned DestAddr, llvm::Type *DestTy, bool isNonNull) const {
   // Since target may map different address spaces in AST to the same address

Anastasia wrote:
> Seems like some parameters are unused.
This is just the default implementation.  The idea is that targets that need to 
do something more complex on a particular conversion — e.g. to make sure that 
null pointers are translated correctly when they have different bit-patterns — 
can easily do so.


https://reviews.llvm.org/D32248



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


Re: r302966 - Remove unused tracking of owning module for MacroInfo objects.

2017-05-16 Thread Richard Smith via cfe-commits
On 15 May 2017 at 10:28, Jordan Rose via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hi, Richard. Swift was using this information in order to put imported
> macros in a particular context. It wouldn't surprise me to hear that we
> were doing it wrong, and that there's a better way to go from a macro back
> to a module, but is there a recommended replacement?
>

The recommended way to connect macros to modules is via the ModuleMacro
objects, which represent a macro exported from a module. You can query the
exported macro for a (module, identifier) pair with
Preprocessor::getModuleMacro, or walk the ModuleMacro graph for an
identifier by starting from Preprocessor::getLeafModuleMacros.

If you alternatively want to know the set of macros that would be visible
with a given set of imports, after setting up that state you can walk the
range produced by Preprocessor::macros(true) and query
getActiveModuleMacros on each MacroState.

If you want to know "what is the set of macros exported directly by this
module?", we don't have a prebuilt mechanism for that, since no in-tree
client wants that information, but one way would be to walk macros(true)
and query getModuleMacro(module, identifier) on each one.

Thanks,
> Jordan
>
>
> > On May 12, 2017, at 16:40, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > Author: rsmith
> > Date: Fri May 12 18:40:52 2017
> > New Revision: 302966
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=302966=rev
> > Log:
> > Remove unused tracking of owning module for MacroInfo objects.
> >
> > Modified:
> >cfe/trunk/include/clang/Lex/MacroInfo.h
> >cfe/trunk/include/clang/Lex/Preprocessor.h
> >cfe/trunk/lib/Lex/MacroInfo.cpp
> >cfe/trunk/lib/Lex/PPDirectives.cpp
> >cfe/trunk/lib/Lex/Preprocessor.cpp
> >cfe/trunk/lib/Serialization/ASTReader.cpp
> >cfe/trunk/lib/Serialization/ASTWriter.cpp
> >
> > Modified: cfe/trunk/include/clang/Lex/MacroInfo.h
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Lex/MacroInfo.h?rev=302966=302965=302966=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
> > +++ cfe/trunk/include/clang/Lex/MacroInfo.h Fri May 12 18:40:52 2017
> > @@ -105,9 +105,6 @@ class MacroInfo {
> >   /// \brief Must warn if the macro is unused at the end of translation
> unit.
> >   bool IsWarnIfUnused : 1;
> >
> > -  /// \brief Whether this macro info was loaded from an AST file.
> > -  bool FromASTFile : 1;
> > -
> >   /// \brief Whether this macro was used as header guard.
> >   bool UsedForHeaderGuard : 1;
> >
> > @@ -264,34 +261,16 @@ public:
> > IsDisabled = true;
> >   }
> >
> > -  /// \brief Determine whether this macro info came from an AST file
> (such as
> > -  /// a precompiled header or module) rather than having been parsed.
> > -  bool isFromASTFile() const { return FromASTFile; }
> > -
> >   /// \brief Determine whether this macro was used for a header guard.
> >   bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; }
> >
> >   void setUsedForHeaderGuard(bool Val) { UsedForHeaderGuard = Val; }
> >
> > -  /// \brief Retrieve the global ID of the module that owns this
> particular
> > -  /// macro info.
> > -  unsigned getOwningModuleID() const {
> > -if (isFromASTFile())
> > -  return *(const unsigned *)(this + 1);
> > -
> > -return 0;
> > -  }
> > -
> >   void dump() const;
> >
> > private:
> >   unsigned getDefinitionLengthSlow(const SourceManager ) const;
> >
> > -  void setOwningModuleID(unsigned ID) {
> > -assert(isFromASTFile());
> > -*(unsigned *)(this + 1) = ID;
> > -  }
> > -
> >   friend class Preprocessor;
> > };
> >
> >
> > Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Lex/Preprocessor.h?rev=302966=302965=302966=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
> > +++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri May 12 18:40:52 2017
> > @@ -644,14 +644,6 @@ class Preprocessor {
> >   /// of that list.
> >   MacroInfoChain *MIChainHead;
> >
> > -  struct DeserializedMacroInfoChain {
> > -MacroInfo MI;
> > -unsigned OwningModuleID; // MUST be immediately after the MacroInfo
> object
> > - // so it can be accessed by
> MacroInfo::getOwningModuleID().
> > -DeserializedMacroInfoChain *Next;
> > -  };
> > -  DeserializedMacroInfoChain *DeserialMIChainHead;
> > -
> >   void updateOutOfDateIdentifier(IdentifierInfo ) const;
> >
> > public:
> > @@ -1669,10 +1661,6 @@ public:
> >   /// \brief Allocate a new MacroInfo object with the provided
> SourceLocation.
> >   MacroInfo *AllocateMacroInfo(SourceLocation L);
> >
> > -  /// \brief Allocate a new MacroInfo object loaded from an AST file.
> > -  MacroInfo 

[PATCH] D33259: Don't defer to the GCC driver for linking arm-baremetal

2017-05-16 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd requested changes to this revision.
compnerd added inline comments.
This revision now requires changes to proceed.



Comment at: cmake/caches/BaremetalARM.cmake:1
+set(LLVM_TARGETS_TO_BUILD ARM CACHE STRING "")
+

Please rename this file to `BareMetalARMv6.cmake`.  (I'm interested in the 
suffix primarily).



Comment at: lib/Driver/ToolChains/BareMetal.cpp:68
+  SmallString<128> Dir(getDriver().ResourceDir);
+  llvm::sys::path::append(Dir, "lib", "baremetal");
+  return Dir.str();

Why not just the standard `arm` directory?



Comment at: lib/Driver/ToolChains/BareMetal.cpp:74
+  SmallString<128> Dir(getDriver().ResourceDir);
+  llvm::sys::path::append(Dir, "include", "c++", "v1");
+  return Dir.str();

This seems wrong.  The libc++ headers should *not* be in the resource dir.  
This should be based off of the sysroot IMO.



Comment at: lib/Driver/ToolChains/BareMetal.cpp:107-108
+ArgStringList ) const {
+  CmdArgs.push_back("-lc++");
+  CmdArgs.push_back("-lc++abi");
+  CmdArgs.push_back("-lunwind");

I think that this is a bit extreme.  We already have `-stdlib=libc++` and 
`-stdlib=libstdc++`.  Why not just honor that?



Comment at: lib/Driver/ToolChains/BareMetal.h:42
+
+  const char *getDefaultLinker() const override { return "ld.lld"; }
+

I think that this really should be `ld` still, as that is the canonical name 
for the linker.



Comment at: lib/Driver/ToolChains/BareMetal.h:57
+ llvm::opt::ArgStringList ) const;
+protected:
+};

Unnecessary?



Comment at: lib/Driver/ToolChains/BareMetal.h:67
+public:
+  Linker(const ToolChain ) : Tool("baremetal::Linker", "ld.lld", TC) {}
+  bool isLinkJob() const override { return true; }

Update this accordingly.


https://reviews.llvm.org/D33259



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


r303228 - (1) Fixed mismatch in intrinsics names in declarations and in doxygen comments.

2017-05-16 Thread Ekaterina Romanova via cfe-commits
Author: kromanova
Date: Tue May 16 20:46:11 2017
New Revision: 303228

URL: http://llvm.org/viewvc/llvm-project?rev=303228=rev
Log:
(1) Fixed mismatch in intrinsics names in declarations and in doxygen comments.
(2) Removed uncessary anymore \c commands, since the same effect will be 
achived by  ...  sequence. 

I got an OK from Eric Christopher to commit doxygen comments without prior code
review upstream.



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

Modified: cfe/trunk/lib/Headers/xmmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/xmmintrin.h?rev=303228=303227=303228=diff
==
--- cfe/trunk/lib/Headers/xmmintrin.h (original)
+++ cfe/trunk/lib/Headers/xmmintrin.h Tue May 16 20:46:11 2017
@@ -2133,7 +2133,7 @@ void _mm_sfence(void);
 /// \headerfile 
 ///
 /// \code
-/// void _mm_extract_pi(__m64 a, int n);
+/// int _mm_extract_pi16(__m64 a, int n);
 /// \endcode
 ///
 /// This intrinsic corresponds to the  VPEXTRW / PEXTRW  instruction.
@@ -2157,7 +2157,7 @@ void _mm_sfence(void);
 /// \headerfile 
 ///
 /// \code
-/// void _mm_insert_pi(__m64 a, int d, int n);
+/// __m64 _mm_insert_pi16(__m64 a, int d, int n);
 /// \endcode
 ///
 /// This intrinsic corresponds to the  VPINSRW / PINSRW  instruction.
@@ -2680,8 +2680,7 @@ _mm_movelh_ps(__m128 __a, __m128 __b)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  CVTPI2PS + \c COMPOSITE 
-///   instruction.
+/// This intrinsic corresponds to the  CVTPI2PS + COMPOSITE  
instruction.
 ///
 /// \param __a
 ///A 64-bit vector of [4 x i16]. The elements of the destination are copied
@@ -2711,8 +2710,7 @@ _mm_cvtpi16_ps(__m64 __a)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  CVTPI2PS + \c COMPOSITE 
-///   instruction.
+/// This intrinsic corresponds to the  CVTPI2PS + COMPOSITE  
instruction.
 ///
 /// \param __a
 ///A 64-bit vector of 16-bit unsigned integer values. The elements of the
@@ -2741,8 +2739,7 @@ _mm_cvtpu16_ps(__m64 __a)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  CVTPI2PS + \c COMPOSITE 
-///   instruction.
+/// This intrinsic corresponds to the  CVTPI2PS + COMPOSITE  
instruction.
 ///
 /// \param __a
 ///A 64-bit vector of [8 x i8]. The elements of the destination are copied
@@ -2766,8 +2763,7 @@ _mm_cvtpi8_ps(__m64 __a)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  CVTPI2PS + \c COMPOSITE 
-///   instruction.
+/// This intrinsic corresponds to the  CVTPI2PS + COMPOSITE  
instruction.
 ///
 /// \param __a
 ///A 64-bit vector of unsigned 8-bit integer values. The elements of the
@@ -2791,8 +2787,7 @@ _mm_cvtpu8_ps(__m64 __a)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  CVTPI2PS + \c COMPOSITE 
-///   instruction.
+/// This intrinsic corresponds to the  CVTPI2PS + COMPOSITE  
instruction.
 ///
 /// \param __a
 ///A 64-bit vector of [2 x i32]. The lower elements of the destination are
@@ -2826,8 +2821,7 @@ _mm_cvtpi32x2_ps(__m64 __a, __m64 __b)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  CVTPS2PI + \c COMPOSITE 
-///   instruction.
+/// This intrinsic corresponds to the  CVTPS2PI + COMPOSITE  
instruction.
 ///
 /// \param __a
 ///A 128-bit floating-point vector of [4 x float].
@@ -2857,8 +2851,7 @@ _mm_cvtps_pi16(__m128 __a)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  CVTPS2PI + \c COMPOSITE 
-///   instruction.
+/// This intrinsic corresponds to the  CVTPS2PI + COMPOSITE  
instruction.
 ///
 /// \param __a
 ///128-bit floating-point vector of [4 x float].


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


[PATCH] D33201: [clangd] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

2017-05-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Looks good!




Comment at: clangd/ClangdLSPServer.h:33
+  /// each instance of ClangdLSPServer.
+  void run(std::istream );
 

ilya-biryukov wrote:
> krasimir wrote:
> > It seems strange to have the In here and the Out in the constructor.
> Didn't want to store unnecessary fields in the class, but we do need 
> JSONOutput  as a member, since there's consumeDiagnostics which uses it.
> Would you prefer std::istream  to be moved into a constructor parameter 
> and stored as a field?
I get it now. It's OK as it is now!


https://reviews.llvm.org/D33201



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


[PATCH] D32480: [clang-format] Add BinPackNamespaces option

2017-05-16 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

We have a large closed-source codebase with this style, and would welcome 
clang-format support.


https://reviews.llvm.org/D32480



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


[clang-tools-extra] r303173 - [clangd] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

2017-05-16 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue May 16 09:40:30 2017
New Revision: 303173

URL: http://llvm.org/viewvc/llvm-project?rev=303173=rev
Log:
[clangd] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

Summary:
A refactoring to decouple ProtocolHandlers and Language Server input parsing
loop from the ClangdLSPServer.
The input parsing was extracted from `main` to a 
function(runLanguageServerLoop).
ProtocolHandlers now provide an interface to handle various LSP methods,
this interface is used by ClangdLSPServer.
Methods for code formatting were moved from ProtocolHandlers to ClangdServer.
ClangdLSPServer now provides a cleaner interface that only runs Language Server
input loop.

Reviewers: bkramer, krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, klimek

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdMain.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=303173=303172=303173=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue May 16 09:40:30 2017
@@ -9,10 +9,35 @@
 
 #include "ClangdLSPServer.h"
 #include "JSONRPCDispatcher.h"
+#include "ProtocolHandlers.h"
 
 using namespace clang::clangd;
 using namespace clang;
 
+namespace {
+
+std::string
+replacementsToEdits(StringRef Code,
+const std::vector ) {
+  // Turn the replacements into the format specified by the Language Server
+  // Protocol. Fuse them into one big JSON array.
+  std::string Edits;
+  for (auto  : Replacements) {
+Range ReplacementRange = {
+offsetToPosition(Code, R.getOffset()),
+offsetToPosition(Code, R.getOffset() + R.getLength())};
+TextEdit TE = {ReplacementRange, R.getReplacementText()};
+Edits += TextEdit::unparse(TE);
+Edits += ',';
+  }
+  if (!Edits.empty())
+Edits.pop_back();
+
+  return Edits;
+}
+
+} // namespace
+
 class ClangdLSPServer::LSPDiagnosticsConsumer : public DiagnosticsConsumer {
 public:
   LSPDiagnosticsConsumer(ClangdLSPServer ) : Server(Server) {}
@@ -26,23 +51,170 @@ private:
   ClangdLSPServer 
 };
 
+class ClangdLSPServer::LSPProtocolCallbacks : public ProtocolCallbacks {
+public:
+  LSPProtocolCallbacks(ClangdLSPServer ) : LangServer(LangServer) {}
+
+  void onInitialize(StringRef ID, JSONOutput ) override;
+  void onShutdown(JSONOutput ) override;
+  void onDocumentDidOpen(DidOpenTextDocumentParams Params,
+ JSONOutput ) override;
+  void onDocumentDidChange(DidChangeTextDocumentParams Params,
+   JSONOutput ) override;
+  void onDocumentDidClose(DidCloseTextDocumentParams Params,
+  JSONOutput ) override;
+  void onDocumentOnTypeFormatting(DocumentOnTypeFormattingParams Params,
+  StringRef ID, JSONOutput ) override;
+  void onDocumentRangeFormatting(DocumentRangeFormattingParams Params,
+ StringRef ID, JSONOutput ) override;
+  void onDocumentFormatting(DocumentFormattingParams Params, StringRef ID,
+JSONOutput ) override;
+  void onCodeAction(CodeActionParams Params, StringRef ID,
+JSONOutput ) override;
+  void onCompletion(TextDocumentPositionParams Params, StringRef ID,
+JSONOutput ) override;
+
+private:
+  ClangdLSPServer 
+};
+
+void ClangdLSPServer::LSPProtocolCallbacks::onInitialize(StringRef ID,
+ JSONOutput ) {
+  Out.writeMessage(
+  R"({"jsonrpc":"2.0","id":)" + ID +
+  R"(,"result":{"capabilities":{
+  "textDocumentSync": 1,
+  "documentFormattingProvider": true,
+  "documentRangeFormattingProvider": true,
+  "documentOnTypeFormattingProvider": 
{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
+  "codeActionProvider": true,
+  "completionProvider": {"resolveProvider": false, 
"triggerCharacters": [".",">"]}
+}}})");
+}
+
+void ClangdLSPServer::LSPProtocolCallbacks::onShutdown(JSONOutput ) {
+  LangServer.IsDone = true;
+}
+
+void ClangdLSPServer::LSPProtocolCallbacks::onDocumentDidOpen(
+DidOpenTextDocumentParams Params, JSONOutput ) {
+  LangServer.Server.addDocument(Params.textDocument.uri.file,
+   

[clang-tools-extra] r303177 - Added missing includes in clangd to fix the build.

2017-05-16 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Tue May 16 10:23:55 2017
New Revision: 303177

URL: http://llvm.org/viewvc/llvm-project?rev=303177=rev
Log:
Added missing includes in clangd to fix the build.

This commit should fix buildbot failures.


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

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=303177=303176=303177=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Tue May 16 10:23:55 
2017
@@ -12,6 +12,8 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/YAMLParser.h"
+#include 
+
 using namespace clang;
 using namespace clangd;
 

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=303177=303176=303177=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Tue May 16 10:23:55 2017
@@ -13,6 +13,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/YAMLParser.h"
+#include 
 #include 
 
 namespace clang {


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


[PATCH] D33258: clang-cl: Fix path-based MSVC version detection

2017-05-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I'd rather not hardcode all the msvc archs. IMO we should just look up one 
level and check if that's called bin, and continue if so. I think I had:

  bool IsBin = llvm::sys::path::filename(PathEntry).compare_lower("bin");
  if (!IsBin) {
PathEntry = llvm::sys::path::parent_path(PathEntry);
IsBin = llvm::sys::path::filename(TestPath).compare_lower("bin");
  }
  if (IsBin) {
...

The compare_lower is also a fix, because my path looks like ".../VC/Bin".


https://reviews.llvm.org/D33258



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


[PATCH] D33259: Don't defer to the GCC driver for linking arm-baremetal

2017-05-16 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs updated this revision to Diff 99210.
jroelofs added a comment.

pass through linker flags, and remove my own paths from the test.


https://reviews.llvm.org/D33259

Files:
  cmake/caches/BaremetalARM.cmake
  lib/Driver/CMakeLists.txt
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/BareMetal.cpp
  lib/Driver/ToolChains/BareMetal.h
  test/Driver/baremetal.cpp

Index: test/Driver/baremetal.cpp
===
--- /dev/null
+++ test/Driver/baremetal.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target armv6m-none-eabi \
+// RUN: -T semihosted.lds \
+// RUN: -L some/directory/user/asked/for \
+// RUN:   | FileCheck --check-prefix=CHECK-V6M-C %s
+// CHECK-V6M-C: "[[PREFIX_DIR:.*]]/bin/clang" "-cc1" "-triple" "thumbv6m-none--eabi"
+// CHECK-V6M-C-SAME: "-resource-dir" "[[PREFIX_DIR]]/lib/clang/[[VERSION:[^"]*]]"
+// CHECK-V6M-C-SAME: "-internal-isystem" "[[PREFIX_DIR]]/lib/clang/[[VERSION]]/include/c++/v1"
+// CHECk-V6M-C-SAME: "-internal-isystem" "[[PREFIX_DIR]]/lib/clang/[[VERSION]]/include"
+// CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-V6M-C-NEXT: "[[PREFIX_DIR:.*]]/bin/ld.lld" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-C-SAME: "-L[[PREFIX_DIR]]/lib/clang/[[VERSION]]/lib/baremetal"
+// CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome/directory/user/asked/for"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a"
+// CHECK-V6M-C-SAME: "-o" "{{.*}}.o"
+
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target armv6m-none-eabi \
+// RUN:   | FileCheck --check-prefix=CHECK-V6M-CXX %s
+// CHECK-V6M-CXX: "[[PREFIX_DIR:.*]]/bin/ld.lld" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-CXX-SAME: "-L[[PREFIX_DIR]]/lib/clang/{{.*}}/lib/baremetal"
+// CHECK-V6M-CXX-SAME: "-lc++" "-lc++abi" "-lunwind"
+// CHECK-V6M-CXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a"
+// CHECK-V6M-CXX-SAME: "-o" "{{.*}}.o"
+
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target armv6m-none-eabi \
+// RUN: -nodefaultlibs \
+// RUN:   | FileCheck --check-prefix=CHECK-V6M-NDL %s
+// CHECK-V6M-NDL: "[[PREFIX_DIR:.*]]/bin/ld.lld" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-NDL-SAME: "-L[[PREFIX_DIR]]/lib/clang/{{.*}}/lib/baremetal" "-o" "{{.*}}.o"
Index: lib/Driver/ToolChains/BareMetal.h
===
--- /dev/null
+++ lib/Driver/ToolChains/BareMetal.h
@@ -0,0 +1,82 @@
+//===--- BareMetal.h - Bare Metal Tool and ToolChain -*- 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_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+#include 
+
+namespace clang {
+namespace driver {
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
+public:
+  BareMetal(const Driver , const llvm::Triple ,
+const llvm::opt::ArgList );
+  ~BareMetal() override;
+
+  static bool handlesTarget(const llvm::Triple );
+protected:
+  Tool *buildLinker() const override;
+
+public:
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return true; }
+  bool SupportsObjCGC() const override { return false; }
+
+  const char *getDefaultLinker() const override { return "ld.lld"; }
+
+  std::string getRuntimesDir() const;
+  std::string findLibCxxIncludePath() const;
+  void AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  void addClangTargetOptions(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddLinkRuntimeLib(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const;
+protected:
+};
+
+} // namespace toolchains
+
+namespace tools {
+namespace baremetal {
+
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("baremetal::Linker", "ld.lld", TC) {}
+  bool isLinkJob() const override { return true; }
+  bool hasIntegratedCPP() const override { return false; }
+  void ConstructJob(Compilation , 

[PATCH] D33258: clang-cl: Fix path-based MSVC version detection

2017-05-16 Thread Hans Wennborg via Phabricator via cfe-commits
hans updated this revision to Diff 99213.
hans added a comment.

Addressing comments.


https://reviews.llvm.org/D33258

Files:
  lib/Driver/ToolChains/MSVC.cpp


Index: lib/Driver/ToolChains/MSVC.cpp
===
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -125,8 +125,15 @@
 continue;
 
   // whatever/VC/bin --> old toolchain, VC dir is toolchain dir.
-  if (llvm::sys::path::filename(PathEntry) == "bin") {
-llvm::StringRef ParentPath = llvm::sys::path::parent_path(PathEntry);
+  llvm::StringRef TestPath = PathEntry;
+  bool IsBin = llvm::sys::path::filename(TestPath).equals_lower("bin");
+  if (!IsBin) {
+// Strip any architecture subdir like "amd64".
+TestPath = llvm::sys::path::parent_path(TestPath);
+IsBin = llvm::sys::path::filename(TestPath).equals_lower("bin");
+  }
+  if (IsBin) {
+llvm::StringRef ParentPath = llvm::sys::path::parent_path(TestPath);
 if (llvm::sys::path::filename(ParentPath) == "VC") {
   Path = ParentPath;
   IsVS2017OrNewer = false;


Index: lib/Driver/ToolChains/MSVC.cpp
===
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -125,8 +125,15 @@
 continue;
 
   // whatever/VC/bin --> old toolchain, VC dir is toolchain dir.
-  if (llvm::sys::path::filename(PathEntry) == "bin") {
-llvm::StringRef ParentPath = llvm::sys::path::parent_path(PathEntry);
+  llvm::StringRef TestPath = PathEntry;
+  bool IsBin = llvm::sys::path::filename(TestPath).equals_lower("bin");
+  if (!IsBin) {
+// Strip any architecture subdir like "amd64".
+TestPath = llvm::sys::path::parent_path(TestPath);
+IsBin = llvm::sys::path::filename(TestPath).equals_lower("bin");
+  }
+  if (IsBin) {
+llvm::StringRef ParentPath = llvm::sys::path::parent_path(TestPath);
 if (llvm::sys::path::filename(ParentPath) == "VC") {
   Path = ParentPath;
   IsVS2017OrNewer = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33258: clang-cl: Fix path-based MSVC version detection

2017-05-16 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.

The code wasn't taking the architecture-specific subdirectory into account.


https://reviews.llvm.org/D33258

Files:
  lib/Driver/ToolChains/MSVC.cpp


Index: lib/Driver/ToolChains/MSVC.cpp
===
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -124,9 +124,19 @@
   if (!llvm::sys::fs::exists(ExeTestPath))
 continue;
 
-  // whatever/VC/bin --> old toolchain, VC dir is toolchain dir.
-  if (llvm::sys::path::filename(PathEntry) == "bin") {
-llvm::StringRef ParentPath = llvm::sys::path::parent_path(PathEntry);
+  // Strip any architecture specific subdirectory.
+  llvm::StringRef TestPath = PathEntry;
+  if (llvm::sys::path::filename(TestPath) == "amd64" ||
+  llvm::sys::path::filename(TestPath) == "amd64_arm" ||
+  llvm::sys::path::filename(TestPath) == "amd64_x86" ||
+  llvm::sys::path::filename(TestPath) == "arm" ||
+  llvm::sys::path::filename(TestPath) == "x86_amd64" ||
+  llvm::sys::path::filename(TestPath) == "x86_arm")
+TestPath = llvm::sys::path::parent_path(TestPath);
+
+  // whatever/VC/bin --> old toolchain, // VC dir is toolchain dir.
+  if (llvm::sys::path::filename(TestPath) == "bin") {
+llvm::StringRef ParentPath = llvm::sys::path::parent_path(TestPath);
 if (llvm::sys::path::filename(ParentPath) == "VC") {
   Path = ParentPath;
   IsVS2017OrNewer = false;


Index: lib/Driver/ToolChains/MSVC.cpp
===
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -124,9 +124,19 @@
   if (!llvm::sys::fs::exists(ExeTestPath))
 continue;
 
-  // whatever/VC/bin --> old toolchain, VC dir is toolchain dir.
-  if (llvm::sys::path::filename(PathEntry) == "bin") {
-llvm::StringRef ParentPath = llvm::sys::path::parent_path(PathEntry);
+  // Strip any architecture specific subdirectory.
+  llvm::StringRef TestPath = PathEntry;
+  if (llvm::sys::path::filename(TestPath) == "amd64" ||
+  llvm::sys::path::filename(TestPath) == "amd64_arm" ||
+  llvm::sys::path::filename(TestPath) == "amd64_x86" ||
+  llvm::sys::path::filename(TestPath) == "arm" ||
+  llvm::sys::path::filename(TestPath) == "x86_amd64" ||
+  llvm::sys::path::filename(TestPath) == "x86_arm")
+TestPath = llvm::sys::path::parent_path(TestPath);
+
+  // whatever/VC/bin --> old toolchain, // VC dir is toolchain dir.
+  if (llvm::sys::path::filename(TestPath) == "bin") {
+llvm::StringRef ParentPath = llvm::sys::path::parent_path(TestPath);
 if (llvm::sys::path::filename(ParentPath) == "VC") {
   Path = ParentPath;
   IsVS2017OrNewer = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 99204.
yaxunl marked 4 inline comments as done.
yaxunl added a comment.
Herald added a subscriber: nhaehnle.

Removed special handling of OpenCL from getTargetAddressSpace.


https://reviews.llvm.org/D32248

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Basic/AddressSpaces.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ASTContext.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenTypeCache.h
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenOpenCL/amdgcn-automatic-variable.cl
  test/CodeGenOpenCL/amdgpu-alignment.cl
  test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
  test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
  test/CodeGenOpenCL/amdgpu-nullptr.cl
  test/CodeGenOpenCL/builtins-amdgcn.cl
  test/CodeGenOpenCL/byval.cl
  test/CodeGenOpenCL/size_t.cl
  test/Sema/sizeof-struct-non-zero-as-member.cl
  test/SemaOpenCL/storageclass-cl20.cl
  test/SemaOpenCL/storageclass.cl

Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -13,29 +13,37 @@
   constant int L1 = 0;
   local int L2;
 
-  auto int L3 = 7; // expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
-  global int L4;   // expected-error{{function scope variable cannot be declared in global address space}}
-
-  constant int L5 = x; // expected-error {{initializer element is not a compile-time constant}}
-  global int *constant L6 = 
-  private int *constant L7 =  // expected-error {{initializer element is not a compile-time constant}}
-  constant int *constant L8 = 
-  local int *constant L9 =  // expected-error {{initializer element is not a compile-time constant}}
+  auto int L3 = 7;// expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
+  global int L4;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L5; // expected-error{{automatic variable qualified with an invalid address space}}
+
+  constant int L6 = x;// expected-error {{initializer element is not a compile-time constant}}
+  global int *constant L7 = 
+  private int *constant L8 =   // expected-error {{initializer element is not a compile-time constant}}
+  constant int *constant L9 = 
+  local int *constant L10 =   // expected-error {{initializer element is not a compile-time constant}}
 }
 
 static void kernel bar() { // expected-error{{kernel functions cannot be declared static}}
 }
 
 void f() {
-  constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-  local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+  constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+  local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+  global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
+
   {
-constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+__attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
   }
-  global int L3; // expected-error{{function scope variable cannot be declared in global address space}}
-  extern constant float L4;
-  extern local float L5; // expected-error{{extern variable must reside in constant address space}}
-  static int L6 = 0; // expected-error{{variables in function scope cannot be declared static}}
-  static int L7; // expected-error{{variables in function 

[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:7294
   llvm::PointerType *T, QualType QT) const override;
+
 };

yaxunl wrote:
> rjmccall wrote:
> > Spurious newline?
> will remove it.
Sorry this line is needed to separate it from the next function.


https://reviews.llvm.org/D32248



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


[PATCH] D33258: clang-cl: Fix path-based MSVC version detection

2017-05-16 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a subscriber: thakis.
hans added a comment.

Nico asked about tests. This whole thing landed (r297851) without tests, and 
I'm not sure it's worth the effort adding one for this :-/


https://reviews.llvm.org/D33258



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


[PATCH] D31588: Fix PR25627: Certain constant local variables must be usable as template arguments (without being odr-used)

2017-05-16 Thread Richard Smith via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/Parse/ParseExpr.cpp:203-222
+  // Create the ExpressionEvaluationContext on the stack - but only if asked 
to.
+  struct EnterExpressionEvaluationContextConditionalRAII {
+llvm::AlignedCharArray
+MyStackStorage;
+const EnterExpressionEvaluationContext *const ConstantEvaluatedContext;
+EnterExpressionEvaluationContextConditionalRAII(bool CreateIt,

This seems more complexity than we need. How about factoring out a 
`ParseConstantExpressionInExprEvalContext` function that doesn't create a 
context, and then calling it from this function after creating the context?



Comment at: lib/Parse/ParseTemplate.cpp:1208-1233
   if (isCXXTypeId(TypeIdAsTemplateArgument)) {
 SourceLocation Loc = Tok.getLocation();
-TypeResult TypeArg = ParseTypeName(/*Range=*/nullptr,
-   Declarator::TemplateTypeArgContext);
+TypeResult TypeArg =
+ParseTypeName(/*Range=*/nullptr, Declarator::TemplateTypeArgContext);
 if (TypeArg.isInvalid())
   return ParsedTemplateArgument();
+

There's a bunch of whitespace changes here. I have no objection to them but 
they should be handled separately rather than mixed into this change.


https://reviews.llvm.org/D31588



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


[PATCH] D33259: Don't defer to the GCC driver for linking arm-baremetal

2017-05-16 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs created this revision.
Herald added subscribers: javed.absar, mgorny, rengolin, aemerson.

https://reviews.llvm.org/D33259

Files:
  cmake/caches/BaremetalARM.cmake
  lib/Driver/CMakeLists.txt
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/BareMetal.cpp
  lib/Driver/ToolChains/BareMetal.h
  test/Driver/baremetal.cpp

Index: test/Driver/baremetal.cpp
===
--- /dev/null
+++ test/Driver/baremetal.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target armv6m-none-eabi \
+// RUN:   | FileCheck --check-prefix=CHECK-V6M-C %s
+// CHECK-V6M-C: "[[PREFIX_DIR:.*]]/bin/clang" "-cc1" "-triple" "thumbv6m-none--eabi"
+// CHECK-V6M-C-SAME: "-resource-dir" "/scratch/jroelofs/arm-lite/./lib/clang/5.0.0"
+// CHECK-V6M-C-SAME: "-internal-isystem" "/scratch/jroelofs/arm-lite/./lib/clang/5.0.0/include/c++/v1"
+// CHECk-V6M-C-SAME: "-internal-isystem" "/scratch/jroelofs/arm-lite/./lib/clang/5.0.0/include"
+// CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal.cpp"
+// CHECK-V6M-C-NEXT: "[[PREFIX_DIR:.*]]/bin/ld.lld" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-C-SAME: "-L[[PREFIX_DIR]]/lib/clang/{{.*}}/lib/baremetal"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a"
+// CHECK-V6M-C-SAME: "-o" "{{.*}}.o"
+
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target armv6m-none-eabi \
+// RUN:   | FileCheck --check-prefix=CHECK-V6M-CXX %s
+// CHECK-V6M-CXX: "[[PREFIX_DIR:.*]]/bin/ld.lld" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-CXX-SAME: "-L[[PREFIX_DIR]]/lib/clang/{{.*}}/lib/baremetal"
+// CHECK-V6M-CXX-SAME: "-lc++" "-lc++abi" "-lunwind"
+// CHECK-V6M-CXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a"
+// CHECK-V6M-CXX-SAME: "-o" "{{.*}}.o"
+
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target armv6m-none-eabi \
+// RUN: -nodefaultlibs \
+// RUN:   | FileCheck --check-prefix=CHECK-V6M-NDL %s
+// CHECK-V6M-NDL: "[[PREFIX_DIR:.*]]/bin/ld.lld" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-NDL-SAME: "-L[[PREFIX_DIR]]/lib/clang/{{.*}}/lib/baremetal" "-o" "{{.*}}.o"
Index: lib/Driver/ToolChains/BareMetal.h
===
--- /dev/null
+++ lib/Driver/ToolChains/BareMetal.h
@@ -0,0 +1,82 @@
+//===--- BareMetal.h - Bare Metal Tool and ToolChain -*- 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_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+
+#include 
+
+namespace clang {
+namespace driver {
+
+namespace toolchains {
+
+class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
+public:
+  BareMetal(const Driver , const llvm::Triple ,
+const llvm::opt::ArgList );
+  ~BareMetal() override;
+
+  static bool handlesTarget(const llvm::Triple );
+protected:
+  Tool *buildLinker() const override;
+
+public:
+  bool useIntegratedAs() const override { return true; }
+  bool isCrossCompiling() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
+  bool SupportsProfiling() const override { return true; }
+  bool SupportsObjCGC() const override { return false; }
+
+  const char *getDefaultLinker() const override { return "ld.lld"; }
+
+  std::string getRuntimesDir() const;
+  std::string findLibCxxIncludePath() const;
+  void AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  void addClangTargetOptions(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const override;
+  void AddClangCXXStdlibIncludeArgs(
+  const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const override;
+  void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
+  void AddLinkRuntimeLib(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) const;
+protected:
+};
+
+} // namespace toolchains
+
+namespace tools {
+namespace baremetal {
+
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
+public:
+  Linker(const ToolChain ) : Tool("baremetal::Linker", "ld.lld", TC) {}
+  bool isLinkJob() const override { return true; }
+  bool hasIntegratedCPP() const override { return false; }
+  void ConstructJob(Compilation , const JobAction ,
+const InputInfo , const InputInfoList ,
+const llvm::opt::ArgList ,
+const char *LinkingOutput) const override;

[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 14 inline comments as done.
yaxunl added inline comments.



Comment at: lib/CodeGen/CodeGenTypes.cpp:95
 
-
 /// isRecordLayoutComplete - Return true if the specified type is already

Anastasia wrote:
> Why this change?
Will undo it.



Comment at: lib/CodeGen/TargetInfo.cpp:7294
   llvm::PointerType *T, QualType QT) const override;
+
 };

rjmccall wrote:
> Spurious newline?
will remove it.



Comment at: lib/Sema/SemaDecl.cpp:7206
+assert(T.getAddressSpace() != LangAS::opencl_constant);
+if (T.getAddressSpace() == LangAS::opencl_global) {
+  Diag(NewVD->getLocation(), diag::err_opencl_function_variable)

Anastasia wrote:
> I think it was nicer that all OpenCL related changes were grouped in one spot 
> under the same if statement. Even though it isn't quite done everywhere. But 
> this change makes them even more scattered.
Will move them down.



Comment at: test/CodeGenCXX/amdgcn-automatic-variable.cpp:25
+  // CHECK: store i32 2, i32* %[[r1]]
+  int lv1;
+  lv1 = 1;

Anastasia wrote:
> yaxunl wrote:
> > yaxunl wrote:
> > > Anastasia wrote:
> > > > I am wondering if all these different test cases are really needed. Are 
> > > > we testing any different program paths from the patch?
> > > > 
> > > > Also would it make sense to add a test case with an object in an AS 
> > > > different to 0 (i.e. with `__attribute__((address_space(n)))`)
> > > I think at least I should cover the typical use cases of auto var.
> > > 
> > > I will add a test for __attribute__((address_space(n
> > Sorry. I just checked that C++ does not allow 
> > __attribute__((address_space(n))) on automatic var.
> I thought address space was undocumented extension. So essentially you can't 
> have a cast to any address space but a default here? Would it work for the C 
> instead to add `attribute((address_space(n)))`?
As John pointed out, this due to the embedded C specification (ISO/IEC TR 
18037). Clang applies it to all languages except OpenCL.



Comment at: test/SemaOpenCL/storageclass-cl20.cl:16
+  global int L3;  // expected-error{{function 
scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L4; // expected-error{{automatic 
variable qualified with an invalid address space}}
 

Anastasia wrote:
> I am guessing generic should be rejected here as well... although it should 
> only apply to pointers. But it seems we don't handle this properly.
will add a line for generic.


https://reviews.llvm.org/D32248



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


[PATCH] D33263: [scan-build] Patch to scan-build tool to support "--target=" flag

2017-05-16 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

Looks good. Thank you! 
Do you have commit access or should we commit?


https://reviews.llvm.org/D33263



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


[PATCH] D33263: [scan-build] Patch to scan-build tool to support "--target=" flag

2017-05-16 Thread Haowei Wu via Phabricator via cfe-commits
haowei added a comment.

In https://reviews.llvm.org/D33263#756900, @zaks.anna wrote:

> Looks good. Thank you! 
>  Do you have commit access or should we commit?


I don't have commit access, so could you commit this patch?

Thanks.


https://reviews.llvm.org/D33263



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


[PATCH] D33259: Don't defer to the GCC driver for linking arm-baremetal

2017-05-16 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

> I would expect this to changes wildly depending on the specific environment.

My assertion is that our default "specific environment" ought to cater to using 
llvm's own tools... at least until someone comes along and says they actually 
want `-fuse-ld=gcc`, or whatever.


https://reviews.llvm.org/D33259



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


[PATCH] D33258: clang-cl: Fix path-based MSVC version detection

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

lgtm


https://reviews.llvm.org/D33258



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


r303222 - Fix scope of namespaced DISubprograms when the function definition is out-of-line.

2017-05-16 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Tue May 16 18:46:10 2017
New Revision: 303222

URL: http://llvm.org/viewvc/llvm-project?rev=303222=rev
Log:
Fix scope of namespaced DISubprograms when the function definition is 
out-of-line.
This fixes a regression introduced in r302915.

Using the lexical decl context is not necessary here for what r302915
wast trying to achieve. Not canonicalizing the NamespaceDecl in
getOrCreateNamespace is suficient.

rdar://problem/29339538

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=303222=303221=303222=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue May 16 18:46:10 2017
@@ -2860,7 +2860,7 @@ void CGDebugInfo::collectFunctionDeclPro
 
   if (DebugKind >= codegenoptions::LimitedDebugInfo) {
 if (const NamespaceDecl *NSDecl =
-dyn_cast_or_null(FD->getLexicalDeclContext()))
+dyn_cast_or_null(FD->getDeclContext()))
   FDContext = getOrCreateNamespace(NSDecl);
 else if (const RecordDecl *RDecl =
  dyn_cast_or_null(FD->getDeclContext())) {

Modified: cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp?rev=303222=303221=303222=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp Tue May 16 18:46:10 2017
@@ -60,6 +60,10 @@ void B::func_fwd() {
   anonymous = 0;
 }
 
+namespace C {
+  void c();
+}
+void C::c() {}
 
 // This should work even if 'i' and 'func' were declarations & not definitions,
 // but it doesn't yet.
@@ -114,6 +118,8 @@ void B::func_fwd() {
 // CHECK: [[M16]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[FUNC]], entity: [[FUNC_FWD:![0-9]+]]
 // CHECK: [[FUNC_FWD]] = distinct !DISubprogram(name: "func_fwd",{{.*}} line: 
53,{{.*}} isDefinition: true
 // CHECK: [[M17]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
[[CTXT]], entity: [[I]]
+// CHECK: distinct !DISubprogram(name: "c",{{.*}}, scope: 
![[C:[0-9]+]],{{.*}}, line: 60,{{.*}} isDefinition: true
+// CHECK: ![[C]] = !DINamespace(name: "C",
 
 // CHECK-GMLT: [[CU:![0-9]+]] = distinct !DICompileUnit(
 // CHECK-GMLT-SAME:emissionKind: LineTablesOnly,


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


r303224 - [modules] When creating a declaration, cache its owning module immediately

2017-05-16 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue May 16 19:24:14 2017
New Revision: 303224

URL: http://llvm.org/viewvc/llvm-project?rev=303224=rev
Log:
[modules] When creating a declaration, cache its owning module immediately
rather than waiting until it's queried.

Currently this is only applied to local submodule visibility mode, as we don't
yet allocate storage for the owning module in non-local-visibility modules
compilations.


This reinstates r302965, reverted in r303037, with a fix for the reported
crash, which occurred when reparenting a local declaration to be a child of
a hidden imported declaration (specifically during template instantiation).

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/Modules/Inputs/submodule-visibility/b.h
cfe/trunk/test/Modules/Inputs/submodule-visibility/other.h
cfe/trunk/test/Modules/submodule-visibility.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=303224=303223=303224=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue May 16 19:24:14 2017
@@ -301,16 +301,6 @@ public:
   using Decl::isModulePrivate;
   using Decl::setModulePrivate;
 
-  /// \brief Determine whether this declaration is hidden from name lookup.
-  bool isHidden() const { return Hidden; }
-
-  /// \brief Set whether this declaration is hidden from name lookup.
-  void setHidden(bool Hide) {
-assert((!Hide || isFromASTFile() || hasLocalOwningModuleStorage()) &&
-   "declaration with no owning module can't be hidden");
-Hidden = Hide;
-  }
-
   /// \brief Determine whether this declaration is a C++ class member.
   bool isCXXClassMember() const {
 const DeclContext *DC = getDeclContext();

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=303224=303223=303224=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Tue May 16 19:24:14 2017
@@ -706,6 +706,20 @@ public:
 reinterpret_cast(this)[-1] = M;
   }
 
+  Module *getOwningModule() const {
+return isFromASTFile() ? getImportedOwningModule() : 
getLocalOwningModule();
+  }
+
+  /// \brief Determine whether this declaration is hidden from name lookup.
+  bool isHidden() const { return Hidden; }
+
+  /// \brief Set whether this declaration is hidden from name lookup.
+  void setHidden(bool Hide) {
+assert((!Hide || isFromASTFile() || hasLocalOwningModuleStorage()) &&
+   "declaration with no owning module can't be hidden");
+Hidden = Hide;
+  }
+
   unsigned getIdentifierNamespace() const {
 return IdentifierNamespace;
   }

Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=303224=303223=303224=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Tue May 16 19:24:14 2017
@@ -166,6 +166,11 @@ public:
 return getCompilingModule() != CMK_None;
   }
 
+  /// Do we need to track the owning module for a local declaration?
+  bool trackLocalOwningModule() const {
+return ModulesLocalVisibility;
+  }
+
   bool isSignedOverflowDefined() const {
 return getSignedOverflowBehavior() == SOB_Defined;
   }

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=303224=303223=303224=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue May 16 19:24:14 2017
@@ -1467,11 +1467,9 @@ private:
 
   VisibleModuleSet VisibleModules;
 
-  Module *CachedFakeTopLevelModule;
-
 public:
   /// \brief Get the module owning an entity.
-  Module *getOwningModule(Decl *Entity);
+  Module *getOwningModule(Decl *Entity) { return Entity->getOwningModule(); }
 
   /// \brief Make a merged definition of an existing hidden definition \p ND
   /// visible at the specified location.

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=303224=303223=303224=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ 

[PATCH] D32248: CodeGen: Cast alloca to expected address space

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

Looks great, thank you for being patient.


https://reviews.llvm.org/D32248



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


[clang-tools-extra] r303230 - [clang-tidy] Optimize misc-unused-parameters. NFCI

2017-05-16 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue May 16 21:25:11 2017
New Revision: 303230

URL: http://llvm.org/viewvc/llvm-project?rev=303230=rev
Log:
[clang-tidy] Optimize misc-unused-parameters. NFCI

Don't traverse AST each time we need to find references to a certain function.
Traverse the AST once using RAV and cache the index of function references.

The speed up on a particular large file was about 1000x.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp?rev=303230=303229=303230=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp Tue May 
16 21:25:11 2017
@@ -9,8 +9,10 @@
 
 #include "UnusedParametersCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -27,7 +29,10 @@ bool isOverrideMethod(const FunctionDecl
 } // namespace
 
 void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(functionDecl().bind("function"), this);
+  Finder->addMatcher(
+  functionDecl(isDefinition(), hasBody(stmt()), hasAnyParameter(decl()))
+  .bind("function"),
+  this);
 }
 
 template 
@@ -65,21 +70,74 @@ static FixItHint removeArgument(const Ma
   Index + 1 < Call->getNumArgs() ? Call->getArg(Index + 1) : nullptr));
 }
 
+class UnusedParametersCheck::IndexerVisitor
+: public RecursiveASTVisitor {
+public:
+  IndexerVisitor(TranslationUnitDecl *Top) { TraverseDecl(Top); }
+
+  const std::unordered_set &
+  getFnCalls(const FunctionDecl *Fn) {
+return Index[Fn->getCanonicalDecl()].Calls;
+  }
+
+  const std::unordered_set &
+  getOtherRefs(const FunctionDecl *Fn) {
+return Index[Fn->getCanonicalDecl()].OtherRefs;
+  }
+
+  bool shouldTraversePostOrder() const { return true; }
+
+  bool WalkUpFromDeclRefExpr(DeclRefExpr *DeclRef) {
+if (const auto *Fn = dyn_cast(DeclRef->getDecl())) {
+  Fn = Fn->getCanonicalDecl();
+  Index[Fn].OtherRefs.insert(DeclRef);
+}
+return true;
+  }
+
+  bool WalkUpFromCallExpr(CallExpr *Call) {
+if (const auto *Fn =
+dyn_cast_or_null(Call->getCalleeDecl())) {
+  Fn = Fn->getCanonicalDecl();
+  if (const auto *Ref =
+  dyn_cast(Call->getCallee()->IgnoreImplicit())) {
+Index[Fn].OtherRefs.erase(Ref);
+  }
+  Index[Fn].Calls.insert(Call);
+}
+return true;
+  }
+
+private:
+  struct IndexEntry {
+std::unordered_set Calls;
+std::unordered_set OtherRefs;
+  };
+
+  std::unordered_map Index;
+};
+
+UnusedParametersCheck::~UnusedParametersCheck() = default;
+
+UnusedParametersCheck::UnusedParametersCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {}
+
 void UnusedParametersCheck::warnOnUnusedParameter(
 const MatchFinder::MatchResult , const FunctionDecl *Function,
 unsigned ParamIndex) {
   const auto *Param = Function->getParamDecl(ParamIndex);
   auto MyDiag = diag(Param->getLocation(), "parameter %0 is unused") << Param;
 
-  auto DeclRefExpr =
-  declRefExpr(to(equalsNode(Function)),
-  unless(hasAncestor(callExpr(callee(equalsNode(Function));
+  if (!Indexer) {
+Indexer = llvm::make_unique(
+Result.Context->getTranslationUnitDecl());
+  }
 
   // Comment out parameter name for non-local functions.
   if (Function->isExternallyVisible() ||
   !Result.SourceManager->isInMainFile(Function->getLocation()) ||
-  !ast_matchers::match(DeclRefExpr, *Result.Context).empty() ||
-  isOverrideMethod(Function)) {
+  !Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
 SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
 // Note: We always add a space before the '/*' to not accidentally create a
 // '*/*' for pointer types, which doesn't start a comment. clang-format 
will
@@ -95,19 +153,13 @@ void UnusedParametersCheck::warnOnUnused
   MyDiag << removeParameter(Result, FD, ParamIndex);
 
   // Fix all call sites.
-  auto CallMatches = ast_matchers::match(
-  decl(forEachDescendant(
-  callExpr(callee(functionDecl(equalsNode(Function.bind("x"))),
-  *Result.Context->getTranslationUnitDecl(), *Result.Context);
-  for (const auto  : CallMatches)
-MyDiag << removeArgument(Result, Match.getNodeAs("x"),
- ParamIndex);
+  for (const auto *Call : Indexer->getFnCalls(Function))
+MyDiag << removeArgument(Result, Call, 

r303231 - [ODRHash] Support more types in the ODR checker.

2017-05-16 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Tue May 16 21:29:02 2017
New Revision: 303231

URL: http://llvm.org/viewvc/llvm-project?rev=303231=rev
Log:
[ODRHash] Support more types in the ODR checker.

Added support for TagType, TypeWithKeyword, and all children types.

Modified:
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=303231=303230=303231=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Tue May 16 21:29:02 2017
@@ -335,6 +335,20 @@ public:
 Hash.AddQualType(T);
   }
 
+  void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
+Hash.AddBoolean(NNS);
+if (NNS) {
+  Hash.AddNestedNameSpecifier(NNS);
+}
+  }
+
+  void AddIdentifierInfo(const IdentifierInfo *II) {
+Hash.AddBoolean(II);
+if (II) {
+  Hash.AddIdentifierInfo(II);
+}
+  }
+
   void VisitQualifiers(Qualifiers Quals) {
 ID.AddInteger(Quals.getAsOpaqueValue());
   }
@@ -414,6 +428,42 @@ public:
 AddQualType(T->getDecl()->getUnderlyingType().getCanonicalType());
 VisitType(T);
   }
+
+  void VisitTagType(const TagType *T) {
+AddDecl(T->getDecl());
+VisitType(T);
+  }
+
+  void VisitRecordType(const RecordType *T) { VisitTagType(T); }
+  void VisitEnumType(const EnumType *T) { VisitTagType(T); }
+
+  void VisitTypeWithKeyword(const TypeWithKeyword *T) {
+ID.AddInteger(T->getKeyword());
+VisitType(T);
+  };
+
+  void VisitDependentNameType(const DependentNameType *T) {
+AddNestedNameSpecifier(T->getQualifier());
+AddIdentifierInfo(T->getIdentifier());
+VisitTypeWithKeyword(T);
+  }
+
+  void VisitDependentTemplateSpecializationType(
+  const DependentTemplateSpecializationType *T) {
+AddIdentifierInfo(T->getIdentifier());
+AddNestedNameSpecifier(T->getQualifier());
+ID.AddInteger(T->getNumArgs());
+for (const auto  : T->template_arguments()) {
+  Hash.AddTemplateArgument(TA);
+}
+VisitTypeWithKeyword(T);
+  }
+
+  void VisitElaboratedType(const ElaboratedType *T) {
+AddNestedNameSpecifier(T->getQualifier());
+AddQualType(T->getNamedType());
+VisitTypeWithKeyword(T);
+  }
 };
 
 void ODRHash::AddType(const Type *T) {

Modified: cfe/trunk/test/Modules/odr_hash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=303231=303230=303231=diff
==
--- cfe/trunk/test/Modules/odr_hash.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash.cpp Tue May 16 21:29:02 2017
@@ -634,6 +634,78 @@ S3 s3;
 #endif
 }  // namespace Using
 
+namespace RecordType {
+#if defined(FIRST)
+struct B1 {};
+struct S1 {
+  B1 x;
+};
+#elif defined(SECOND)
+struct A1 {};
+struct S1 {
+  A1 x;
+};
+#else
+S1 s1;
+// expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is 
not present in definition of 'RecordType::S1' in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'x' does not match}}
+#endif
+}
+
+namespace DependentType {
+#if defined(FIRST)
+template 
+class S1 {
+  typename T::typeA x;
+};
+#elif defined(SECOND)
+template 
+class S1 {
+  typename T::typeB x;
+};
+#else
+template
+using U1 = S1;
+// expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' 
is not present in definition of 'S1' in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'x' does not match}}
+#endif
+}
+
+namespace ElaboratedType {
+#if defined(FIRST)
+namespace N1 { using type = double; }
+struct S1 {
+  N1::type x;
+};
+#elif defined(SECOND)
+namespace N1 { using type = int; }
+struct S1 {
+  N1::type x;
+};
+#else
+S1 s1;
+// expected-error@first.h:* {{'ElaboratedType::S1::x' from module 
'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 
'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'x' does not match}}
+#endif
+}
+
+namespace Enum {
+#if defined(FIRST)
+enum A1 {};
+struct S1 {
+  A1 x;
+};
+#elif defined(SECOND)
+enum A2 {};
+struct S1 {
+  A2 x;
+};
+#else
+S1 s1;
+// expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not 
present in definition of 'Enum::S1' in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'x' does not match}}
+#endif
+}
 
 // Interesting cases that should not cause errors.  struct S should not error
 // while struct T should error at the access specifier mismatch at the end.


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