[PATCH] D65180: [analyzer] VirtualCallChecker: Improve warning messages.

2019-07-24 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Yay!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65180/new/

https://reviews.llvm.org/D65180



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


[clang-tools-extra] r366873 - [clangd] Implement "prepareRename"

2019-07-24 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jul 24 00:49:23 2019
New Revision: 366873

URL: http://llvm.org/viewvc/llvm-project?rev=366873&view=rev
Log:
[clangd] Implement "prepareRename"

Summary:
- "prepareRename" request is added in LSP v3.12.0
- also update the vscode-client dependency to pick-up the rename bug fix[1]

[1]: https://github.com/microsoft/vscode-languageserver-node/issues/447

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
clang-tools-extra/trunk/clangd/test/rename.test

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=366873&r1=366872&r2=366873&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Jul 24 00:49:23 2019
@@ -382,6 +382,14 @@ void ClangdLSPServer::onInitialize(const
   SupportFileStatus = Params.initializationOptions.FileStatus;
   HoverContentFormat = Params.capabilities.HoverContentFormat;
   SupportsOffsetsInSignatureHelp = Params.capabilities.OffsetsInSignatureHelp;
+
+  // Per LSP, renameProvider can be either boolean or RenameOptions.
+  // RenameOptions will be specified if the client states it supports prepare.
+  llvm::json::Value RenameProvider =
+  llvm::json::Object{{"prepareProvider", true}};
+  if (!Params.capabilities.RenamePrepareSupport) // Only boolean allowed per 
LSP
+RenameProvider = true;
+
   llvm::json::Object Result{
   {{"capabilities",
 llvm::json::Object{
@@ -409,7 +417,7 @@ void ClangdLSPServer::onInitialize(const
 {"definitionProvider", true},
 {"documentHighlightProvider", true},
 {"hoverProvider", true},
-{"renameProvider", true},
+{"renameProvider", std::move(RenameProvider)},
 {"documentSymbolProvider", true},
 {"workspaceSymbolProvider", true},
 {"referencesProvider", true},
@@ -568,6 +576,12 @@ void ClangdLSPServer::onWorkspaceSymbol(
   std::move(Reply)));
 }
 
+void ClangdLSPServer::onPrepareRename(const TextDocumentPositionParams &Params,
+  Callback> Reply) {
+  Server->prepareRename(Params.textDocument.uri.file(), Params.position,
+std::move(Reply));
+}
+
 void ClangdLSPServer::onRename(const RenameParams &Params,
Callback Reply) {
   Path File = Params.textDocument.uri.file();
@@ -1015,6 +1029,7 @@ ClangdLSPServer::ClangdLSPServer(
   MsgHandler->bind("textDocument/declaration", 
&ClangdLSPServer::onGoToDeclaration);
   MsgHandler->bind("textDocument/references", &ClangdLSPServer::onReference);
   MsgHandler->bind("textDocument/switchSourceHeader", 
&ClangdLSPServer::onSwitchSourceHeader);
+  MsgHandler->bind("textDocument/prepareRename", 
&ClangdLSPServer::onPrepareRename);
   MsgHandler->bind("textDocument/rename", &ClangdLSPServer::onRename);
   MsgHandler->bind("textDocument/hover", &ClangdLSPServer::onHover);
   MsgHandler->bind("textDocument/documentSymbol", 
&ClangdLSPServer::onDocumentSymbol);

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=366873&r1=366872&r2=366873&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Wed Jul 24 00:49:23 2019
@@ -95,6 +95,8 @@ private:
   void onCommand(const ExecuteCommandParams &, Callback);
   void onWorkspaceSymbol(const WorkspaceSymbolParams &,
  Callback>);
+  void onPrepareRename(const TextDocumentPositionParams &,
+   Callback>);
   void onRename(const RenameParams &, Callback);
   void onHover(const TextDocumentPositionParams &,
Callback>);

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=366873&r1=366872&r2=366873&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Jul 24 00:49:23 2019
@@ -292,6 +292,35 @@ ClangdServer::formatOnType(llvm::StringR
   retu

[PATCH] D65183: [Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCI

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

I haven't really understood D65043  yet, but I 
think this is a good change either way.




Comment at: lib/Format/TokenAnnotator.cpp:2862
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard == FormatStyle::LS_Cpp03 || Style.SpacesInAngles);
   }

modocache wrote:
> Just a note: I don't know what the original intent of 
> https://github.com/llvm/llvm-project/commit/dd978ae0e11 was, but in D65043 I 
> modified this condition to be `Style.Standard == FormatStyle::LS_Cpp03 || 
> Style.Standard == FormatStyle::LS_Auto`, because I believe that mirrors the 
> current behavior exactly. With this change, a user that specified a standard 
> of `FormatStyle::LS_Auto` will experience a change in behavior.
If I'm reading the code right, `Formatter::analyze`calls `deriveLocalStyle` 
first, which replaces `LS_Auto` with a concrete style. Then later, it calls 
`TokenAnnotator::calculateFormattingInformation` which is what ultimately calls 
`spaceRequiredBefore`. So I think we never see `Auto` here, and the two forms 
are equivalent.



Comment at: lib/Format/TokenAnnotator.cpp:2862
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard == FormatStyle::LS_Cpp03 || Style.SpacesInAngles);
   }

sammccall wrote:
> modocache wrote:
> > Just a note: I don't know what the original intent of 
> > https://github.com/llvm/llvm-project/commit/dd978ae0e11 was, but in D65043 
> > I modified this condition to be `Style.Standard == FormatStyle::LS_Cpp03 || 
> > Style.Standard == FormatStyle::LS_Auto`, because I believe that mirrors the 
> > current behavior exactly. With this change, a user that specified a 
> > standard of `FormatStyle::LS_Auto` will experience a change in behavior.
> If I'm reading the code right, `Formatter::analyze`calls `deriveLocalStyle` 
> first, which replaces `LS_Auto` with a concrete style. Then later, it calls 
> `TokenAnnotator::calculateFormattingInformation` which is what ultimately 
> calls `spaceRequiredBefore`. So I think we never see `Auto` here, and the two 
> forms are equivalent.
nit: consider `< Cpp11`, or `<= Cpp03`? Fits in the spirit of this patch :-)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65183/new/

https://reviews.llvm.org/D65183



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


[PATCH] D63126: [clangd] Implement "prepareRename"

2019-07-24 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366873: [clangd] Implement "prepareRename" 
(authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63126?vs=211302&id=211435#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63126/new/

https://reviews.llvm.org/D63126

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdLSPServer.h
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/Protocol.cpp
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
  clang-tools-extra/trunk/clangd/test/rename.test

Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -382,6 +382,14 @@
   SupportFileStatus = Params.initializationOptions.FileStatus;
   HoverContentFormat = Params.capabilities.HoverContentFormat;
   SupportsOffsetsInSignatureHelp = Params.capabilities.OffsetsInSignatureHelp;
+
+  // Per LSP, renameProvider can be either boolean or RenameOptions.
+  // RenameOptions will be specified if the client states it supports prepare.
+  llvm::json::Value RenameProvider =
+  llvm::json::Object{{"prepareProvider", true}};
+  if (!Params.capabilities.RenamePrepareSupport) // Only boolean allowed per LSP
+RenameProvider = true;
+
   llvm::json::Object Result{
   {{"capabilities",
 llvm::json::Object{
@@ -409,7 +417,7 @@
 {"definitionProvider", true},
 {"documentHighlightProvider", true},
 {"hoverProvider", true},
-{"renameProvider", true},
+{"renameProvider", std::move(RenameProvider)},
 {"documentSymbolProvider", true},
 {"workspaceSymbolProvider", true},
 {"referencesProvider", true},
@@ -568,6 +576,12 @@
   std::move(Reply)));
 }
 
+void ClangdLSPServer::onPrepareRename(const TextDocumentPositionParams &Params,
+  Callback> Reply) {
+  Server->prepareRename(Params.textDocument.uri.file(), Params.position,
+std::move(Reply));
+}
+
 void ClangdLSPServer::onRename(const RenameParams &Params,
Callback Reply) {
   Path File = Params.textDocument.uri.file();
@@ -1015,6 +1029,7 @@
   MsgHandler->bind("textDocument/declaration", &ClangdLSPServer::onGoToDeclaration);
   MsgHandler->bind("textDocument/references", &ClangdLSPServer::onReference);
   MsgHandler->bind("textDocument/switchSourceHeader", &ClangdLSPServer::onSwitchSourceHeader);
+  MsgHandler->bind("textDocument/prepareRename", &ClangdLSPServer::onPrepareRename);
   MsgHandler->bind("textDocument/rename", &ClangdLSPServer::onRename);
   MsgHandler->bind("textDocument/hover", &ClangdLSPServer::onHover);
   MsgHandler->bind("textDocument/documentSymbol", &ClangdLSPServer::onDocumentSymbol);
Index: clang-tools-extra/trunk/clangd/Protocol.h
===
--- clang-tools-extra/trunk/clangd/Protocol.h
+++ clang-tools-extra/trunk/clangd/Protocol.h
@@ -422,6 +422,10 @@
   /// The content format that should be used for Hover requests.
   /// textDocument.hover.contentEncoding
   MarkupKind HoverContentFormat = MarkupKind::PlainText;
+
+  /// The client supports testing for validity of rename operations
+  /// before execution.
+  bool RenamePrepareSupport = false;
 };
 bool fromJSON(const llvm::json::Value &, ClientCapabilities &);
 
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h
@@ -95,6 +95,8 @@
   void onCommand(const ExecuteCommandParams &, Callback);
   void onWorkspaceSymbol(const WorkspaceSymbolParams &,
  Callback>);
+  void onPrepareRename(const TextDocumentPositionParams &,
+   Callback>);
   void onRename(const RenameParams &, Callback);
   void onHover(const TextDocumentPositionParams &,
Callback>);
Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -241,6 +241,10 @@
  PathRef File, Position Pos,
  StringRef TriggerText);
 
+  /// Test the validity of a rename operation.
+  void prepareRename(PathRef File, Position Pos,
+ Callback

[clang-tools-extra] r366875 - [clangd] Update a stale comment, NFC.

2019-07-24 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jul 24 00:57:25 2019
New Revision: 366875

URL: http://llvm.org/viewvc/llvm-project?rev=366875&view=rev
Log:
[clangd] Update a stale comment, NFC.

Modified:
clang-tools-extra/trunk/clangd/refactor/tweaks/ExpandAutoType.cpp

Modified: clang-tools-extra/trunk/clangd/refactor/tweaks/ExpandAutoType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/ExpandAutoType.cpp?rev=366875&r1=366874&r2=366875&view=diff
==
--- clang-tools-extra/trunk/clangd/refactor/tweaks/ExpandAutoType.cpp (original)
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/ExpandAutoType.cpp Wed Jul 
24 00:57:25 2019
@@ -1,4 +1,4 @@
-//===--- ReplaceAutoType.cpp -*- 
C++-*-===//
+//===--- ExpandAutoType.cpp --*- 
C++-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.


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


[PATCH] D65183: [Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCI

2019-07-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 211436.
MaskRay added a comment.

Change to `< Cpp11`


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65183/new/

https://reviews.llvm.org/D65183

Files:
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2859,7 +2859,7 @@
 (Style.Language == FormatStyle::LK_Proto && Left.is(TT_DictLiteral)))
   return !Style.Cpp11BracedListStyle;
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard == FormatStyle::LS_Cpp03 || Style.SpacesInAngles);
   }
   if (Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
   Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
@@ -2878,7 +2878,7 @@
 return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
 return (Left.is(TT_TemplateOpener) &&
-Style.Standard == FormatStyle::LS_Cpp03) ||
+Style.Standard < FormatStyle::LS_Cpp11) ||
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
   tok::kw___super, TT_TemplateCloser,
   TT_TemplateOpener)) ||
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -2366,10 +2366,10 @@
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus17 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus2a = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2859,7 +2859,7 @@
 (Style.Language == FormatStyle::LK_Proto && Left.is(TT_DictLiteral)))
   return !Style.Cpp11BracedListStyle;
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard == FormatStyle::LS_Cpp03 || Style.SpacesInAngles);
   }
   if (Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
   Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
@@ -2878,7 +2878,7 @@
 return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
 return (Left.is(TT_TemplateOpener) &&
-Style.Standard == FormatStyle::LS_Cpp03) ||
+Style.Standard < FormatStyle::LS_Cpp11) ||
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
   tok::kw___super, TT_TemplateCloser,
   TT_TemplateOpener)) ||
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -2366,10 +2366,10 @@
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus17 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus2a = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r366876 - [Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCI

2019-07-24 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Wed Jul 24 01:04:29 2019
New Revision: 366876

URL: http://llvm.org/viewvc/llvm-project?rev=366876&view=rev
Log:
[Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCI

Preparatory change for D65043.

We current use `!=LS_Cpp03` to enable language standards 11,14,17, and
2a. `>=LS_Cpp11` is better if we decide to add new LanguageStandard in
the future.

Reviewed By: sammccall

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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=366876&r1=366875&r2=366876&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jul 24 01:04:29 2019
@@ -2366,10 +2366,10 @@ tooling::Replacements sortUsingDeclarati
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus17 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus2a = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=366876&r1=366875&r2=366876&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jul 24 01:04:29 2019
@@ -2859,7 +2859,7 @@ bool TokenAnnotator::spaceRequiredBefore
 (Style.Language == FormatStyle::LK_Proto && Left.is(TT_DictLiteral)))
   return !Style.Cpp11BracedListStyle;
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard < FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
   }
   if (Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
   Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
@@ -2878,7 +2878,7 @@ bool TokenAnnotator::spaceRequiredBefore
 return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
 return (Left.is(TT_TemplateOpener) &&
-Style.Standard == FormatStyle::LS_Cpp03) ||
+Style.Standard < FormatStyle::LS_Cpp11) ||
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
   tok::kw___super, TT_TemplateCloser,
   TT_TemplateOpener)) ||


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


[PATCH] D65183: [Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCI

2019-07-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:2862
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard == FormatStyle::LS_Cpp03 || Style.SpacesInAngles);
   }

sammccall wrote:
> sammccall wrote:
> > modocache wrote:
> > > Just a note: I don't know what the original intent of 
> > > https://github.com/llvm/llvm-project/commit/dd978ae0e11 was, but in 
> > > D65043 I modified this condition to be `Style.Standard == 
> > > FormatStyle::LS_Cpp03 || Style.Standard == FormatStyle::LS_Auto`, because 
> > > I believe that mirrors the current behavior exactly. With this change, a 
> > > user that specified a standard of `FormatStyle::LS_Auto` will experience 
> > > a change in behavior.
> > If I'm reading the code right, `Formatter::analyze`calls `deriveLocalStyle` 
> > first, which replaces `LS_Auto` with a concrete style. Then later, it calls 
> > `TokenAnnotator::calculateFormattingInformation` which is what ultimately 
> > calls `spaceRequiredBefore`. So I think we never see `Auto` here, and the 
> > two forms are equivalent.
> nit: consider `< Cpp11`, or `<= Cpp03`? Fits in the spirit of this patch :-)
@modocache `LS_Auto` will be changed here:

```
// lib/Format/Formt.cpp:1348
if (Style.Standard == FormatStyle::LS_Auto)
  Style.Standard = hasCpp03IncompatibleFormat(AnnotatedLines)
   ? FormatStyle::LS_Cpp11
   : FormatStyle::LS_Cpp03;
```

So when you add Cpp2a, be careful here :)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65183/new/

https://reviews.llvm.org/D65183



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


[PATCH] D65183: [Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCI

2019-07-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 211437.
MaskRay added a comment.

Fix another place that should use `< FormatStyle::LS_Cpp11` instead`


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65183/new/

https://reviews.llvm.org/D65183

Files:
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2859,7 +2859,7 @@
 (Style.Language == FormatStyle::LK_Proto && Left.is(TT_DictLiteral)))
   return !Style.Cpp11BracedListStyle;
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard < FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
   }
   if (Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
   Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
@@ -2878,7 +2878,7 @@
 return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
 return (Left.is(TT_TemplateOpener) &&
-Style.Standard == FormatStyle::LS_Cpp03) ||
+Style.Standard < FormatStyle::LS_Cpp11) ||
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
   tok::kw___super, TT_TemplateCloser,
   TT_TemplateOpener)) ||
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -2366,10 +2366,10 @@
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus17 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus2a = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2859,7 +2859,7 @@
 (Style.Language == FormatStyle::LK_Proto && Left.is(TT_DictLiteral)))
   return !Style.Cpp11BracedListStyle;
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard < FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
   }
   if (Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
   Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
@@ -2878,7 +2878,7 @@
 return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
 return (Left.is(TT_TemplateOpener) &&
-Style.Standard == FormatStyle::LS_Cpp03) ||
+Style.Standard < FormatStyle::LS_Cpp11) ||
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
   tok::kw___super, TT_TemplateCloser,
   TT_TemplateOpener)) ||
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -2366,10 +2366,10 @@
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus17 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus2a = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65183: [Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCI

2019-07-24 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366876: [Format] Make it easy to add new 
format::FormatStyle::LanguageStandard. NFCI (authored by MaskRay, committed by 
).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65183/new/

https://reviews.llvm.org/D65183

Files:
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Format/TokenAnnotator.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2859,7 +2859,7 @@
 (Style.Language == FormatStyle::LK_Proto && Left.is(TT_DictLiteral)))
   return !Style.Cpp11BracedListStyle;
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard < FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
   }
   if (Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
   Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
@@ -2878,7 +2878,7 @@
 return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
 return (Left.is(TT_TemplateOpener) &&
-Style.Standard == FormatStyle::LS_Cpp03) ||
+Style.Standard < FormatStyle::LS_Cpp11) ||
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
   tok::kw___super, TT_TemplateCloser,
   TT_TemplateOpener)) ||
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -2366,10 +2366,10 @@
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus17 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus2a = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2859,7 +2859,7 @@
 (Style.Language == FormatStyle::LK_Proto && Left.is(TT_DictLiteral)))
   return !Style.Cpp11BracedListStyle;
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
-   (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
+   (Style.Standard < FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
   }
   if (Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
   Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
@@ -2878,7 +2878,7 @@
 return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
 return (Left.is(TT_TemplateOpener) &&
-Style.Standard == FormatStyle::LS_Cpp03) ||
+Style.Standard < FormatStyle::LS_Cpp11) ||
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
   tok::kw___super, TT_TemplateCloser,
   TT_TemplateOpener)) ||
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -2366,10 +2366,10 @@
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus17 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus2a = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.C

[clang-tools-extra] r366877 - [clangd] Bump vscode-clangd v0.0.16

2019-07-24 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jul 24 01:14:29 2019
New Revision: 366877

URL: http://llvm.org/viewvc/llvm-project?rev=366877&view=rev
Log:
[clangd] Bump vscode-clangd v0.0.16

CHANGELOG:
- detect C++ language based on some well-known file paths
- upgrade the lsp-client and lsp-server dependencies

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package-lock.json
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/package-lock.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/package-lock.json?rev=366877&r1=366876&r2=366877&view=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package-lock.json 
(original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package-lock.json Wed 
Jul 24 01:14:29 2019
@@ -1,6 +1,6 @@
 {
 "name": "vscode-clangd",
-"version": "0.0.13",
+"version": "0.0.16",
 "lockfileVersion": 1,
 "requires": true,
 "dependencies": {
@@ -22,10 +22,10 @@
 "integrity": 
"sha512-eqxCp82P+JfqL683wwsL73XmFs1eG6qjw+RD3YHx+Jll1r0jNd4dh8QG9NYAeNGA/hnZjeEDgtTskgJULbxpWQ==",
 "dev": true,
 "requires": {
-"fast-deep-equal": "^2.0.1",
-"fast-json-stable-stringify": "^2.0.0",
-"json-schema-traverse": "^0.4.1",
-"uri-js": "^4.2.2"
+"fast-deep-equal": "2.0.1",
+"fast-json-stable-stringify": "2.0.0",
+"json-schema-traverse": "0.4.1",
+"uri-js": "4.2.2"
 }
 },
 "ansi-cyan": {
@@ -58,7 +58,7 @@
 "integrity": "sha1-2CIM9GYIFSXv6lBhTz3mUU36WPE=",
 "dev": true,
 "requires": {
-"buffer-equal": "^1.0.0"
+"buffer-equal": "1.0.0"
 }
 },
 "arr-diff": {
@@ -67,8 +67,8 @@
 "integrity": "sha1-aHwydYFjWI/vfeezb6vklesaOZo=",
 "dev": true,
 "requires": {
-"arr-flatten": "^1.0.1",
-"array-slice": "^0.2.3"
+"arr-flatten": "1.1.0",
+"array-slice": "0.2.3"
 }
 },
 "arr-flatten": {
@@ -101,7 +101,7 @@
 "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=",
 "dev": true,
 "requires": {
-"array-uniq": "^1.0.1"
+"array-uniq": "1.0.3"
 }
 },
 "array-uniq": {
@@ -122,7 +122,7 @@
 "integrity": 
"sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==",
 "dev": true,
 "requires": {
-"safer-buffer": "~2.1.0"
+"safer-buffer": "2.1.2"
 }
 },
 "assert-plus": {
@@ -161,7 +161,7 @@
 "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=",
 "dev": true,
 "requires": {
-"tweetnacl": "^0.14.3"
+"tweetnacl": "0.14.5"
 }
 },
 "block-stream": {
@@ -170,7 +170,7 @@
 "integrity": "sha1-E+v+d4oDIFz+A3UUgeu0szAMEmo=",
 "dev": true,
 "requires": {
-"inherits": "~2.0.0"
+"inherits": "2.0.3"
 }
 },
 "brace-expansion": {
@@ -179,7 +179,7 @@
 "integrity": 
"sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
 "dev": true,
 "requires": {
-"balanced-match": "^1.0.0",
+"balanced-match": "1.0.0",
 "concat-map": "0.0.1"
 }
 },
@@ -237,9 +237,9 @@
 "integrity": 
"sha512-Bq6+4t+lbM8vhTs/Bef5c5AdEMtapp/iFb6+s4/Hh9MVTt8OLKH7ZOOZSCT+Ys7hsHvqv0GuMPJ1lnQJVHvxpg==",
 "dev": true,
 "requires": {
-"inherits": "^2.0.1",
-"process-nextick-args": "^2.0.0",
-"readable-stream": "^2.3.5"
+"inherits": "2.0.3",
+"process-nextick-args": "2.0.0",
+"readable-stream": "2.3.6"
 }
 },
 "combined-stream": {
@@ -248,7 +248,7 @@
 "integrity": 
"sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==",
 "dev": true,
 "requires": {
-"delayed-stream": "~1.0.0"
+"delayed-stream": "1.0.0"
 }
 },
 "commander": {
@@ -269,7 +269,7 @@
 "integrity": 
"sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==",
 "dev": true,
 "requires": {
-"safe-buffer": "~5.1.1"
+"safe-buffer": "5.1

[PATCH] D65182: [analyzer] WIP: Add fix-it hint support.

2019-07-24 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Woah, nice! How does an `-analyzer-config fixits-as-warnings` option sound like 
for more readable tests?

  01 Obj obj6 = /**/; // expected-warning{{Value stored to 'obj6' during its 
initialization is never read}}
  02  // expected-warning@-1{{FixIt: Remove range 
(:1:1, :1:16)}}


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65182/new/

https://reviews.llvm.org/D65182



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


[PATCH] D65183: [Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCI

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: lib/Format/Format.cpp:2369
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus17 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
-  LangOpts.CPlusPlus2a = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;

Looking at this more, this is pretty subtle: `Style` *can* be `LS_Auto` here. 
So we're relying on the fact that Auto is the max value in the enum.

It's probably worth making this more explicit, e.g.
```
LanguageStandard LexingStd = Style.Standard == LS_Auto ? LS_Cpp20 : 
Style.Standard;
LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
etc
```
(a comment would also be fine, but I think the code is at least as clear here)


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65183/new/

https://reviews.llvm.org/D65183



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


r366878 - [SVE][Inline-Asm] Add support to specify SVE registers in the clobber list

2019-07-24 Thread Sander de Smalen via cfe-commits
Author: s.desmalen
Date: Wed Jul 24 01:42:34 2019
New Revision: 366878

URL: http://llvm.org/viewvc/llvm-project?rev=366878&view=rev
Log:
[SVE][Inline-Asm] Add support to specify SVE registers in the clobber list

Adds the SVE vector and predicate registers to the list of known registers.

Patch by Kerry McLaughlin.

Reviewers: erichkeane, sdesmalen, rengolin

Reviewed By: sdesmalen

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

Added:
cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c
Modified:
cfe/trunk/lib/Basic/Targets/AArch64.cpp

Modified: cfe/trunk/lib/Basic/Targets/AArch64.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.cpp?rev=366878&r1=366877&r2=366878&view=diff
==
--- cfe/trunk/lib/Basic/Targets/AArch64.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/AArch64.cpp Wed Jul 24 01:42:34 2019
@@ -351,10 +351,19 @@ const char *const AArch64TargetInfo::GCC
 "d12", "d13", "d14", "d15", "d16", "d17", "d18", "d19", "d20", "d21", 
"d22",
 "d23", "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
 
-// Vector registers
+// Neon vector registers
 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", 
"v22",
-"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
+"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
+
+// SVE vector registers
+"z0",  "z1",  "z2",  "z3",  "z4",  "z5",  "z6",  "z7",  "z8",  "z9",  
"z10",
+"z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", 
"z21",
+"z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
+
+// SVE predicate registers
+"p0",  "p1",  "p2",  "p3",  "p4",  "p5",  "p6",  "p7",  "p8",  "p9",  
"p10",
+"p11", "p12", "p13", "p14", "p15"
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {

Added: cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c?rev=366878&view=auto
==
--- cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c (added)
+++ cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c Wed Jul 24 01:42:34 2019
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | 
FileCheck %s -check-prefix=CHECK
+
+void test_sve_asm() {
+  asm volatile(
+  "ptrue p0.d\n"
+  "ptrue p15.d\n"
+  "add z0.d, p0/m, z0.d, z0.d\n"
+  "add z31.d, p0/m, z31.d, z31.d\n"
+  :
+  :
+  : "z0", "z31", "p0", "p15");
+  // CHECK: "~{z0},~{z31},~{p0},~{p15}"
+}


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


[PATCH] D64739: [SVE][Inline-Asm] Add support to specify SVE registers in the clobber list

2019-07-24 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366878: [SVE][Inline-Asm] Add support to specify SVE 
registers in the clobber list (authored by s.desmalen, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64739?vs=211264&id=211442#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64739/new/

https://reviews.llvm.org/D64739

Files:
  cfe/trunk/lib/Basic/Targets/AArch64.cpp
  cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c


Index: cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c
===
--- cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c
+++ cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | 
FileCheck %s -check-prefix=CHECK
+
+void test_sve_asm() {
+  asm volatile(
+  "ptrue p0.d\n"
+  "ptrue p15.d\n"
+  "add z0.d, p0/m, z0.d, z0.d\n"
+  "add z31.d, p0/m, z31.d, z31.d\n"
+  :
+  :
+  : "z0", "z31", "p0", "p15");
+  // CHECK: "~{z0},~{z31},~{p0},~{p15}"
+}
Index: cfe/trunk/lib/Basic/Targets/AArch64.cpp
===
--- cfe/trunk/lib/Basic/Targets/AArch64.cpp
+++ cfe/trunk/lib/Basic/Targets/AArch64.cpp
@@ -351,10 +351,19 @@
 "d12", "d13", "d14", "d15", "d16", "d17", "d18", "d19", "d20", "d21", 
"d22",
 "d23", "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
 
-// Vector registers
+// Neon vector registers
 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", 
"v22",
-"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
+"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
+
+// SVE vector registers
+"z0",  "z1",  "z2",  "z3",  "z4",  "z5",  "z6",  "z7",  "z8",  "z9",  
"z10",
+"z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", 
"z21",
+"z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
+
+// SVE predicate registers
+"p0",  "p1",  "p2",  "p3",  "p4",  "p5",  "p6",  "p7",  "p8",  "p9",  
"p10",
+"p11", "p12", "p13", "p14", "p15"
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {


Index: cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c
===
--- cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c
+++ cfe/trunk/test/CodeGen/aarch64-sve-inline-asm.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK
+
+void test_sve_asm() {
+  asm volatile(
+  "ptrue p0.d\n"
+  "ptrue p15.d\n"
+  "add z0.d, p0/m, z0.d, z0.d\n"
+  "add z31.d, p0/m, z31.d, z31.d\n"
+  :
+  :
+  : "z0", "z31", "p0", "p15");
+  // CHECK: "~{z0},~{z31},~{p0},~{p15}"
+}
Index: cfe/trunk/lib/Basic/Targets/AArch64.cpp
===
--- cfe/trunk/lib/Basic/Targets/AArch64.cpp
+++ cfe/trunk/lib/Basic/Targets/AArch64.cpp
@@ -351,10 +351,19 @@
 "d12", "d13", "d14", "d15", "d16", "d17", "d18", "d19", "d20", "d21", "d22",
 "d23", "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
 
-// Vector registers
+// Neon vector registers
 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22",
-"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
+"v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
+
+// SVE vector registers
+"z0",  "z1",  "z2",  "z3",  "z4",  "z5",  "z6",  "z7",  "z8",  "z9",  "z10",
+"z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21",
+"z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
+
+// SVE predicate registers
+"p0",  "p1",  "p2",  "p3",  "p4",  "p5",  "p6",  "p7",  "p8",  "p9",  "p10",
+"p11", "p12", "p13", "p14", "p15"
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65194: [Format] Make getFormattingLangOpts clear LS_Auto uses LS_Cpp11 lexing rule

2019-07-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: modocache, sammccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Suggested by sammccall in post-commit review of D65183 



Repository:
  rC Clang

https://reviews.llvm.org/D65194

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -2365,11 +2365,14 @@
 
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
+  FormatStyle::LanguageStandard LexingStd =
+  Style.Standard == FormatStyle::LS_Auto ? FormatStyle::LS_Cpp11
+ : Style.Standard;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = LexingStd >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -2365,11 +2365,14 @@
 
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
+  FormatStyle::LanguageStandard LexingStd =
+  Style.Standard == FormatStyle::LS_Auto ? FormatStyle::LS_Cpp11
+ : Style.Standard;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = LexingStd >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65194: [Format] Make getFormattingLangOpts clear LS_Auto uses LS_Cpp11 lexing rule

2019-07-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

`getFormattingLangOpts` is called with unadjusted FormatStyle 
(`deriveLocalStyle` doesn't modify `Style`). For example, GoogleStyle uses 
`FormatStyle::LS_Auto`. We're relying on `FormatStyle::LS_Auto` being larger 
than `FormatStyle::LS_Cpp11`, which is brittle.

Below is a case `getFormattingLangOpts` is called with `LS_Auto`:

  TEST_F(CleanUpReplacementsTest, InsertMultipleIncludesGoogleStyle) {
  ...
Style = format::getGoogleStyle(format::FormatStyle::LanguageKind::LK_Cpp);
EXPECT_EQ(Expected, apply(Code, Replaces));


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65194/new/

https://reviews.llvm.org/D65194



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


[PATCH] D65043: [Format] Add C++20 standard to style options

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

So there's precedent for this in rL185149  
(D1028 ). @klimek may have historical context. 
Overall, this makes sense.
Since the coroutines flag flip landed on the 9.x release branch, we may want 
this merged into the branch too.

The configuration (and particularly defaults) is difficult though. I think due 
to some excessive cleverness in the past, we're dug into a bit of a hole.

- the default behavior needs to work well for projects using c++20. Given 
ambiguous input (e.g. use of `co_yield`, with `LS_Auto`), we should resolve in 
favor of this being C++20 rather than a funny-named identifier. 5 years from 
now, the former is going to be **much** more common than the latter, and 
there's no better time than now to switch the default. The most obvious 
implementation of this is having `LS_Auto` run the lexer in C++20 mode, and 
requiring users who don't want that to specify C++1x.
- By bucketing C++11/14/17 together, the LS option has effectively evolved into 
a tristate: "old/new/detect". The result is we're not capturing user intent 
well: lots of `.clang-format` files specify `Cpp11` to mean "new". If we're 
going to add a `Cpp20` option, our only sane alternative is to disable C++20 
features for such people. It's not actually a backwards-incompatible change at 
this point (assuming we get this on the 9.x branch), but it's an unfortunate 
situation and it's our fault. We need to improve the system so users have 
better options, because next time (when C++23 rolls around) things will be more 
complicated. Or if we need to change the behavior for C++17 vs 11...

I think the user intents we should capture here are:

1. pinning to **any** specific version, that's what the codebase uses and we 
have a process for bumping it
2. (maybe) floating with the latest language version, the codebase continuously 
adopts new constructs and fixes conflicts in old code
3. I don't know/haven't bothered to configure

The reason I'm unsure about 2 is I don't know whether the people setting 
`Cpp11` today (in projects using post-C++11 features) have a specific standard 
in mind. Maybe we should be conservative and leave it out for now.

This would lead to something like:

  enum LanguageStandard {
// Default: attempt to guess based on the file.
// Lexer always runs in the latest standard.
// Preserves backwards-compatible formatting (e.g. vector >) if 
the
// input uses it consistently.
LS_Auto,
  
LS_Cpp03, // Parse and format in C++03-compatible mode
LS_Cpp11, // No longer enables C++14 in the lexer
LS_Cpp14,
LS_Cpp17, // Equivalent to today's Cpp11!
LS_Cpp2a, // Later to be renamed to Cpp23, but we'll keep accepting `Cpp2a` 
in the config parser forever
  };

The obvious problem here is that this may well break existing projects that use 
`Cpp11` and C++14/17 features.
I think we can punt on this by making Cpp11/14 still enable 14/17 in LangOpts 
for now (so we don't change behavior, just give people a better way to specify 
their intent) and change it later if needed.

What do you think?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65043/new/

https://reviews.llvm.org/D65043



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


[clang-tools-extra] r366880 - [clangd] Reformat use of cl::opt: use unqualified name and don't bin-pack attributes. NFC

2019-07-24 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Wed Jul 24 02:33:27 2019
New Revision: 366880

URL: http://llvm.org/viewvc/llvm-project?rev=366880&view=rev
Log:
[clangd] Reformat use of cl::opt: use unqualified name and don't bin-pack 
attributes. NFC

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=366880&r1=366879&r2=366880&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Wed Jul 24 02:33:27 2019
@@ -36,128 +36,161 @@
 namespace clang {
 namespace clangd {
 
-static llvm::cl::opt CompileCommandsDir(
+using llvm::cl::cat;
+using llvm::cl::CommaSeparated;
+using llvm::cl::desc;
+using llvm::cl::Hidden;
+using llvm::cl::init;
+using llvm::cl::list;
+using llvm::cl::opt;
+using llvm::cl::values;
+
+static opt CompileCommandsDir{
 "compile-commands-dir",
-llvm::cl::desc("Specify a path to look for compile_commands.json. If path "
-   "is invalid, clangd will look in the current directory and "
-   "parent paths of each source file"));
-
-static llvm::cl::opt
-WorkerThreadsCount("j",
-   llvm::cl::desc("Number of async workers used by 
clangd"),
-   llvm::cl::init(getDefaultAsyncThreadsCount()));
+desc("Specify a path to look for compile_commands.json. If path "
+ "is invalid, clangd will look in the current directory and "
+ "parent paths of each source file"),
+};
+
+static opt WorkerThreadsCount{
+"j",
+desc("Number of async workers used by clangd"),
+init(getDefaultAsyncThreadsCount()),
+};
 
 // FIXME: also support "plain" style where signatures are always omitted.
 enum CompletionStyleFlag { Detailed, Bundled };
-static llvm::cl::opt CompletionStyle(
+static opt CompletionStyle{
 "completion-style",
-llvm::cl::desc("Granularity of code completion suggestions"),
-llvm::cl::values(
-clEnumValN(Detailed, "detailed",
-   "One completion item for each semantically distinct "
-   "completion, with full type information"),
-clEnumValN(Bundled, "bundled",
-   "Similar completion items (e.g. function overloads) are "
-   "combined. Type information shown where possible")));
+desc("Granularity of code completion suggestions"),
+values(clEnumValN(Detailed, "detailed",
+  "One completion item for each semantically distinct "
+  "completion, with full type information"),
+   clEnumValN(Bundled, "bundled",
+  "Similar completion items (e.g. function overloads) are "
+  "combined. Type information shown where possible")),
+};
 
 // FIXME: Flags are the wrong mechanism for user preferences.
 // We should probably read a dotfile or similar.
-static llvm::cl::opt IncludeIneligibleResults(
+static opt IncludeIneligibleResults{
 "include-ineligible-results",
-llvm::cl::desc(
-"Include ineligible completion results (e.g. private members)"),
-llvm::cl::init(CodeCompleteOptions().IncludeIneligibleResults),
-llvm::cl::Hidden);
-
-static llvm::cl::opt InputStyle(
-"input-style", llvm::cl::desc("Input JSON stream encoding"),
-llvm::cl::values(
+desc("Include ineligible completion results (e.g. private members)"),
+init(CodeCompleteOptions().IncludeIneligibleResults),
+Hidden,
+};
+
+static opt InputStyle{
+"input-style",
+desc("Input JSON stream encoding"),
+values(
 clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP 
protocol"),
 clEnumValN(JSONStreamStyle::Delimited, "delimited",
"messages delimited by --- lines, with # comment support")),
-llvm::cl::init(JSONStreamStyle::Standard), llvm::cl::Hidden);
-
-static llvm::cl::opt
-PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"),
-llvm::cl::init(false));
-
-static llvm::cl::opt LogLevel(
-"log", llvm::cl::desc("Verbosity of log messages written to stderr"),
-llvm::cl::values(clEnumValN(Logger::Error, "error", "Error messages only"),
- clEnumValN(Logger::Info, "info",
-"High level execution tracing"),
- clEnumValN(Logger::Debug, "verbose", "Low level 
details")),
-llvm::cl::init(Logger::Info));
-
-static llvm::cl::opt
-Test("lit-test",
- llvm::cl::desc("Abbreviation for -input-style=delimited -pretty -sync 
"
-"-enable-test-scheme -log=verbose."
-  

[PATCH] D64753: [CrossTU][NFCI] Refactor loadExternalAST function

2019-07-24 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

I have a feeling that LoadPass and LoagGuard could be (should be) merged 
together, other than that we are getting close.




Comment at: clang/include/clang/CrossTU/CrossTranslationUnit.h:185
+
+  /// Cached access to ASTUnit mapping information is implemented in this
+  /// section.

Perhaps this comment is not necessary, because it is not obvious where does the 
mentioned "section" ends and this is a bit redundant with the comments for the 
classes below.



Comment at: clang/include/clang/CrossTU/CrossTranslationUnit.h:229
+
+  /// The thresholding of AST-loads is implemented in this section.
+

We may not need this comment.



Comment at: clang/include/clang/CrossTU/CrossTranslationUnit.h:233
+  /// counter on successful load. Member `CanBegin` is used to signal, that the
+  /// import attempt should be made at the beginning. Member `WasSuccesful`
+  /// signifies whether the load is successfully finished. The counter is

Could you please add these descriptions above the member declarations?



Comment at: clang/include/clang/CrossTU/CrossTranslationUnit.h:245
+unsigned &NumASTLoaded;
+bool CanBegin;
+bool WasSuccessful;

This name `CanBegin` sounds strange to me. Perhaps `Enabled`?



Comment at: clang/include/clang/CrossTU/CrossTranslationUnit.h:251
+  /// it is responsible for handing out LoadPass instances.
+  class LoadGuard {
+  public:

I have a feeling that LoadPass and LoagGuard could be (should be) merged 
together.



Comment at: clang/lib/CrossTU/CrossTranslationUnit.cpp:352
+
+CrossTranslationUnitContext::LoadPass::LoadPass(unsigned &NumASTLoaded,
+bool CanBegin)

I think you could leave the implementation of LoadPass:: member functions in 
the header, because they are so small. And that way I think code comprehension 
could improve.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64753/new/

https://reviews.llvm.org/D64753



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


[PATCH] D65194: [Format] Make getFormattingLangOpts clear LS_Auto uses LS_Cpp11 lexing rule

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks! (Sorry for the comment arriving late, didn't expect you to be awake!)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65194/new/

https://reviews.llvm.org/D65194



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


[PATCH] D65154: [clangd] Reformat use of cl::opt: use unqualified name and don't bin-pack attributes. NFC

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366880: [clangd] Reformat use of cl::opt: use unqualified 
name and don't bin-pack… (authored by sammccall, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65154?vs=211308&id=211448#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65154/new/

https://reviews.llvm.org/D65154

Files:
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -36,128 +36,161 @@
 namespace clang {
 namespace clangd {
 
-static llvm::cl::opt CompileCommandsDir(
+using llvm::cl::cat;
+using llvm::cl::CommaSeparated;
+using llvm::cl::desc;
+using llvm::cl::Hidden;
+using llvm::cl::init;
+using llvm::cl::list;
+using llvm::cl::opt;
+using llvm::cl::values;
+
+static opt CompileCommandsDir{
 "compile-commands-dir",
-llvm::cl::desc("Specify a path to look for compile_commands.json. If path "
-   "is invalid, clangd will look in the current directory and "
-   "parent paths of each source file"));
-
-static llvm::cl::opt
-WorkerThreadsCount("j",
-   llvm::cl::desc("Number of async workers used by clangd"),
-   llvm::cl::init(getDefaultAsyncThreadsCount()));
+desc("Specify a path to look for compile_commands.json. If path "
+ "is invalid, clangd will look in the current directory and "
+ "parent paths of each source file"),
+};
+
+static opt WorkerThreadsCount{
+"j",
+desc("Number of async workers used by clangd"),
+init(getDefaultAsyncThreadsCount()),
+};
 
 // FIXME: also support "plain" style where signatures are always omitted.
 enum CompletionStyleFlag { Detailed, Bundled };
-static llvm::cl::opt CompletionStyle(
+static opt CompletionStyle{
 "completion-style",
-llvm::cl::desc("Granularity of code completion suggestions"),
-llvm::cl::values(
-clEnumValN(Detailed, "detailed",
-   "One completion item for each semantically distinct "
-   "completion, with full type information"),
-clEnumValN(Bundled, "bundled",
-   "Similar completion items (e.g. function overloads) are "
-   "combined. Type information shown where possible")));
+desc("Granularity of code completion suggestions"),
+values(clEnumValN(Detailed, "detailed",
+  "One completion item for each semantically distinct "
+  "completion, with full type information"),
+   clEnumValN(Bundled, "bundled",
+  "Similar completion items (e.g. function overloads) are "
+  "combined. Type information shown where possible")),
+};
 
 // FIXME: Flags are the wrong mechanism for user preferences.
 // We should probably read a dotfile or similar.
-static llvm::cl::opt IncludeIneligibleResults(
+static opt IncludeIneligibleResults{
 "include-ineligible-results",
-llvm::cl::desc(
-"Include ineligible completion results (e.g. private members)"),
-llvm::cl::init(CodeCompleteOptions().IncludeIneligibleResults),
-llvm::cl::Hidden);
-
-static llvm::cl::opt InputStyle(
-"input-style", llvm::cl::desc("Input JSON stream encoding"),
-llvm::cl::values(
+desc("Include ineligible completion results (e.g. private members)"),
+init(CodeCompleteOptions().IncludeIneligibleResults),
+Hidden,
+};
+
+static opt InputStyle{
+"input-style",
+desc("Input JSON stream encoding"),
+values(
 clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"),
 clEnumValN(JSONStreamStyle::Delimited, "delimited",
"messages delimited by --- lines, with # comment support")),
-llvm::cl::init(JSONStreamStyle::Standard), llvm::cl::Hidden);
+init(JSONStreamStyle::Standard),
+Hidden,
+};
+
+static opt PrettyPrint{
+"pretty",
+desc("Pretty-print JSON output"),
+init(false),
+};
+
+static opt LogLevel{
+"log",
+desc("Verbosity of log messages written to stderr"),
+values(clEnumValN(Logger::Error, "error", "Error messages only"),
+   clEnumValN(Logger::Info, "info", "High level execution tracing"),
+   clEnumValN(Logger::Debug, "verbose", "Low level details")),
+init(Logger::Info),
+};
 
-static llvm::cl::opt
-PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"),
-llvm::cl::init(false));
-
-static llvm::cl::opt LogLevel(
-"log", llvm::cl::desc("Verbosity of log messages written to stderr"),
-llvm::cl::values(clEnumValN(Logger::Error, "error", "Error messages only"),
- clEnumValN

[clang-tools-extra] r366882 - [clangd] Fix SelectionTree traversal of qualified types

2019-07-24 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Wed Jul 24 02:39:11 2019
New Revision: 366882

URL: http://llvm.org/viewvc/llvm-project?rev=366882&view=rev
Log:
[clangd] Fix SelectionTree traversal of qualified types

Summary:
QualifiedTypeLoc isn't treated like a regular citizen by RecursiveASTVisitor.
This meant we weren't intercepting the traversal of its inner TypeLoc.

Most of the changes here are about exposing kind() so we can improve the
precision of our tests.

This should fix the issue raised in D65067.

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/Selection.cpp
clang-tools-extra/trunk/clangd/Selection.h
clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp

Modified: clang-tools-extra/trunk/clangd/Selection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Selection.cpp?rev=366882&r1=366881&r2=366882&view=diff
==
--- clang-tools-extra/trunk/clangd/Selection.cpp (original)
+++ clang-tools-extra/trunk/clangd/Selection.cpp Wed Jul 24 02:39:11 2019
@@ -63,10 +63,8 @@ private:
   std::vector> Ranges; // Always sorted.
 };
 
-// Dump a node for debugging.
-// DynTypedNode::print() doesn't include the kind of node, which is useful.
-void printNode(llvm::raw_ostream &OS, const DynTypedNode &N,
-   const PrintingPolicy &PP) {
+// Show the type of a node for debugging.
+void printNodeKind(llvm::raw_ostream &OS, const DynTypedNode &N) {
   if (const TypeLoc *TL = N.get()) {
 // TypeLoc is a hierarchy, but has only a single ASTNodeKind.
 // Synthesize the name from the Type subclass (except for 
QualifiedTypeLoc).
@@ -77,14 +75,13 @@ void printNode(llvm::raw_ostream &OS, co
   } else {
 OS << N.getNodeKind().asStringRef();
   }
-  OS << " ";
-  N.print(OS, PP);
 }
 
 std::string printNodeToString(const DynTypedNode &N, const PrintingPolicy &PP) 
{
   std::string S;
   llvm::raw_string_ostream OS(S);
-  printNode(OS, N, PP);
+  printNodeKind(OS, N);
+  OS << " ";
   return std::move(OS.str());
 }
 
@@ -155,6 +152,15 @@ public:
 pop();
 return true;
   }
+  // QualifiedTypeLoc is handled strangely in RecursiveASTVisitor: the derived
+  // TraverseTypeLoc is not called for the inner UnqualTypeLoc.
+  // This means we'd never see 'int' in 'const int'! Work around that here.
+  // (The reason for the behavior is to avoid traversing the nested Type twice,
+  // but we ignore TraverseType anyway).
+  bool TraverseQualifiedTypeLoc(QualifiedTypeLoc QX) {
+return traverseNode(
+&QX, [&] { return TraverseTypeLoc(QX.getUnqualifiedLoc()); });
+  }
   // Uninteresting parts of the AST that don't have locations within them.
   bool TraverseNestedNameSpecifier(NestedNameSpecifier *) { return true; }
   bool TraverseType(QualType) { return true; }
@@ -361,12 +367,21 @@ void SelectionTree::print(llvm::raw_ostr
 : '.');
   else
 OS.indent(Indent);
-  printNode(OS, N.ASTNode, PrintPolicy);
+  printNodeKind(OS, N.ASTNode);
+  OS << ' ';
+  N.ASTNode.print(OS, PrintPolicy);
   OS << "\n";
   for (const Node *Child : N.Children)
 print(OS, *Child, Indent + 2);
 }
 
+std::string SelectionTree::Node::kind() const {
+  std::string S;
+  llvm::raw_string_ostream OS(S);
+  printNodeKind(OS, ASTNode);
+  return std::move(OS.str());
+}
+
 // Decide which selection emulates a "point" query in between characters.
 static std::pair pointBounds(unsigned Offset, FileID FID,
  ASTContext &AST) {

Modified: clang-tools-extra/trunk/clangd/Selection.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Selection.h?rev=366882&r1=366881&r2=366882&view=diff
==
--- clang-tools-extra/trunk/clangd/Selection.h (original)
+++ clang-tools-extra/trunk/clangd/Selection.h Wed Jul 24 02:39:11 2019
@@ -96,6 +96,8 @@ public:
 // Walk up the AST to get the DeclContext of this Node,
 // which is not the node itself.
 const DeclContext& getDeclContext() const;
+// Printable node kind, like "CXXRecordDecl" or "AutoTypeLoc".
+std::string kind() const;
   };
   // The most specific common ancestor of all the selected nodes.
   // If there is no selection, this is nullptr.

Modified: clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp?rev=366882&r1=366881&r2=366882&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp Wed Jul 24 
02:39:11 2019
@@ -49,9 

[PATCH] D65100: [clangd] Fix SelectionTree traversal of qualified types

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366882: [clangd] Fix SelectionTree traversal of qualified 
types (authored by sammccall, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65100?vs=211130&id=211450#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65100/new/

https://reviews.llvm.org/D65100

Files:
  clang-tools-extra/trunk/clangd/Selection.cpp
  clang-tools-extra/trunk/clangd/Selection.h
  clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp

Index: clang-tools-extra/trunk/clangd/Selection.cpp
===
--- clang-tools-extra/trunk/clangd/Selection.cpp
+++ clang-tools-extra/trunk/clangd/Selection.cpp
@@ -63,10 +63,8 @@
   std::vector> Ranges; // Always sorted.
 };
 
-// Dump a node for debugging.
-// DynTypedNode::print() doesn't include the kind of node, which is useful.
-void printNode(llvm::raw_ostream &OS, const DynTypedNode &N,
-   const PrintingPolicy &PP) {
+// Show the type of a node for debugging.
+void printNodeKind(llvm::raw_ostream &OS, const DynTypedNode &N) {
   if (const TypeLoc *TL = N.get()) {
 // TypeLoc is a hierarchy, but has only a single ASTNodeKind.
 // Synthesize the name from the Type subclass (except for QualifiedTypeLoc).
@@ -77,14 +75,13 @@
   } else {
 OS << N.getNodeKind().asStringRef();
   }
-  OS << " ";
-  N.print(OS, PP);
 }
 
 std::string printNodeToString(const DynTypedNode &N, const PrintingPolicy &PP) {
   std::string S;
   llvm::raw_string_ostream OS(S);
-  printNode(OS, N, PP);
+  printNodeKind(OS, N);
+  OS << " ";
   return std::move(OS.str());
 }
 
@@ -155,6 +152,15 @@
 pop();
 return true;
   }
+  // QualifiedTypeLoc is handled strangely in RecursiveASTVisitor: the derived
+  // TraverseTypeLoc is not called for the inner UnqualTypeLoc.
+  // This means we'd never see 'int' in 'const int'! Work around that here.
+  // (The reason for the behavior is to avoid traversing the nested Type twice,
+  // but we ignore TraverseType anyway).
+  bool TraverseQualifiedTypeLoc(QualifiedTypeLoc QX) {
+return traverseNode(
+&QX, [&] { return TraverseTypeLoc(QX.getUnqualifiedLoc()); });
+  }
   // Uninteresting parts of the AST that don't have locations within them.
   bool TraverseNestedNameSpecifier(NestedNameSpecifier *) { return true; }
   bool TraverseType(QualType) { return true; }
@@ -361,12 +367,21 @@
 : '.');
   else
 OS.indent(Indent);
-  printNode(OS, N.ASTNode, PrintPolicy);
+  printNodeKind(OS, N.ASTNode);
+  OS << ' ';
+  N.ASTNode.print(OS, PrintPolicy);
   OS << "\n";
   for (const Node *Child : N.Children)
 print(OS, *Child, Indent + 2);
 }
 
+std::string SelectionTree::Node::kind() const {
+  std::string S;
+  llvm::raw_string_ostream OS(S);
+  printNodeKind(OS, ASTNode);
+  return std::move(OS.str());
+}
+
 // Decide which selection emulates a "point" query in between characters.
 static std::pair pointBounds(unsigned Offset, FileID FID,
  ASTContext &AST) {
Index: clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
@@ -49,9 +49,7 @@
 }
 
 std::string nodeKind(const SelectionTree::Node *N) {
-  if (!N)
-return "";
-  return N->ASTNode.getNodeKind().asStringRef().str();
+  return N ? N->kind() : "";
 }
 
 std::vector allNodes(const SelectionTree &T) {
@@ -102,14 +100,14 @@
 struct AAA { struct BBB { static int ccc(); };};
 int x = AAA::[[B^B^B]]::ccc();
   )cpp",
-  "TypeLoc",
+  "RecordTypeLoc",
   },
   {
   R"cpp(
 struct AAA { struct BBB { static int ccc(); };};
 int x = AAA::[[B^BB^]]::ccc();
   )cpp",
-  "TypeLoc",
+  "RecordTypeLoc",
   },
   {
   R"cpp(
@@ -182,19 +180,19 @@
   R"cpp(
 [[^void]] (*S)(int) = nullptr;
   )cpp",
-  "TypeLoc",
+  "BuiltinTypeLoc",
   },
   {
   R"cpp(
 [[void (*S)^(int)]] = nullptr;
   )cpp",
-  "TypeLoc",
+  "FunctionProtoTypeLoc",
   },
   {
   R"cpp(
 [[void (^*S)(int)]] = nullptr;
   )cpp",
-  "TypeLoc",
+  "FunctionProtoTypeLoc",
   },
   {
   R"cpp(
@@ -206,7 +204,7 @@
   R"cpp(
 [[void ^(*S)(int)]] = nullptr;
   )cpp",
-  "TypeLoc",
+  "FunctionProtoTypeLoc",
   },
 
   // Point selections.
@@ -218,8 +216,8 @@
   {"int bar; void foo() [[{ foo (); }]]^", "Compound

[PATCH] D64753: [CrossTU][NFCI] Refactor loadExternalAST function

2019-07-24 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked 11 inline comments as done.
gamesh411 added a comment.

Thanks for pointing out these issues. Most of them are agreed. Merging the RAII 
counter with the threshold checker class, however, does not seem like a good 
decision for me. What would be the benefits of merging the two?




Comment at: clang/include/clang/CrossTU/CrossTranslationUnit.h:233
+  /// counter on successful load. Member `CanBegin` is used to signal, that the
+  /// import attempt should be made at the beginning. Member `WasSuccesful`
+  /// signifies whether the load is successfully finished. The counter is

martong wrote:
> Could you please add these descriptions above the member declarations?
Good point! Will do that.



Comment at: clang/include/clang/CrossTU/CrossTranslationUnit.h:245
+unsigned &NumASTLoaded;
+bool CanBegin;
+bool WasSuccessful;

martong wrote:
> This name `CanBegin` sounds strange to me. Perhaps `Enabled`?
First I was thinking about making the variable names "read" as an english 
sentence. However CanBegin does not appear during use, so it is fair that 
Enable is a better name. Changing it...



Comment at: clang/include/clang/CrossTU/CrossTranslationUnit.h:251
+  /// it is responsible for handing out LoadPass instances.
+  class LoadGuard {
+  public:

martong wrote:
> I have a feeling that LoadPass and LoagGuard could be (should be) merged 
> together.
LoadPass is the RAII object, the other is decider whether the threshold is 
reached. Note also that LoadGuard owns the loaded-counter variable. IMHO these 
should be two separate classes, and I think if they were to be implemented in 
the header these two would be simple, and easy-to-understand classes.



Comment at: clang/lib/CrossTU/CrossTranslationUnit.cpp:352
+
+CrossTranslationUnitContext::LoadPass::LoadPass(unsigned &NumASTLoaded,
+bool CanBegin)

martong wrote:
> I think you could leave the implementation of LoadPass:: member functions in 
> the header, because they are so small. And that way I think code 
> comprehension could improve.
Good point!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64753/new/

https://reviews.llvm.org/D64753



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


r366883 - [Format] getFormattingLangOpts: make LS_Auto uses LS_Cpp11 lexing rule

2019-07-24 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Wed Jul 24 02:50:56 2019
New Revision: 366883

URL: http://llvm.org/viewvc/llvm-project?rev=366883&view=rev
Log:
[Format] getFormattingLangOpts: make LS_Auto uses LS_Cpp11 lexing rule

Suggested by sammccall in post-commit review of D65183

Reviewed By: sammccall

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

Modified:
cfe/trunk/lib/Format/Format.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=366883&r1=366882&r2=366883&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jul 24 02:50:56 2019
@@ -2365,11 +2365,14 @@ tooling::Replacements sortUsingDeclarati
 
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
+  FormatStyle::LanguageStandard LexingStd =
+  Style.Standard == FormatStyle::LS_Auto ? FormatStyle::LS_Cpp11
+ : Style.Standard;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = LexingStd >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;


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


[PATCH] D65194: [Format] Make getFormattingLangOpts clear LS_Auto uses LS_Cpp11 lexing rule

2019-07-24 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366883: [Format] getFormattingLangOpts: make LS_Auto uses 
LS_Cpp11 lexing rule (authored by MaskRay, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65194/new/

https://reviews.llvm.org/D65194

Files:
  cfe/trunk/lib/Format/Format.cpp


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -2365,11 +2365,14 @@
 
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
+  FormatStyle::LanguageStandard LexingStd =
+  Style.Standard == FormatStyle::LS_Auto ? FormatStyle::LS_Cpp11
+ : Style.Standard;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = LexingStd >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -2365,11 +2365,14 @@
 
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
+  FormatStyle::LanguageStandard LexingStd =
+  Style.Standard == FormatStyle::LS_Auto ? FormatStyle::LS_Cpp11
+ : Style.Standard;
   LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus2a = LexingStd >= FormatStyle::LS_Cpp11;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65064: [CrossTU] Add a function to retrieve original source location.

2019-07-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 211454.
balazske added a comment.

Update diff to one commit with all changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65064/new/

https://reviews.llvm.org/D65064

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -28,13 +28,18 @@
   : CTU(CI), Success(Success) {}
 
   void HandleTranslationUnit(ASTContext &Ctx) {
+auto FindFInTU = [](const TranslationUnitDecl *TU) {
+  const FunctionDecl *FD = nullptr;
+  for (const Decl *D : TU->decls()) {
+FD = dyn_cast(D);
+if (FD && FD->getName() == "f")
+  break;
+  }
+  return FD;
+};
+
 const TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
-const FunctionDecl *FD = nullptr;
-for (const Decl *D : TU->decls()) {
-  FD = dyn_cast(D);
-  if (FD && FD->getName() == "f")
-break;
-}
+const FunctionDecl *FD = FindFInTU(TU);
 assert(FD && FD->getName() == "f");
 bool OrigFDHasBody = FD->hasBody();
 
@@ -78,6 +83,28 @@
 if (NewFDorError) {
   const FunctionDecl *NewFD = *NewFDorError;
   *Success = NewFD && NewFD->hasBody() && !OrigFDHasBody;
+
+  if (NewFD) {
+// Check GetImportedFromSourceLocation.
+llvm::Optional> SLocResult =
+CTU.getImportedFromSourceLocation(NewFD->getLocation());
+EXPECT_TRUE(SLocResult);
+if (SLocResult) {
+  SourceLocation OrigSLoc = (*SLocResult).first;
+  ASTUnit *OrigUnit = (*SLocResult).second;
+  // OrigUnit is created internally by CTU (is not the
+  // ASTWithDefinition).
+  TranslationUnitDecl *OrigTU =
+  OrigUnit->getASTContext().getTranslationUnitDecl();
+  const FunctionDecl *FDWithDefinition = FindFInTU(OrigTU);
+  EXPECT_TRUE(FDWithDefinition);
+  if (FDWithDefinition) {
+EXPECT_EQ(FDWithDefinition->getName(), "f");
+EXPECT_TRUE(FDWithDefinition->isThisDeclarationADefinition());
+EXPECT_EQ(OrigSLoc, FDWithDefinition->getLocation());
+  }
+}
+  }
 }
   }
 
Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -295,7 +295,7 @@
 
   TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
   if (const T *ResultDecl = findDefInDeclContext(TU, LookupName))
-return importDefinition(ResultDecl);
+return importDefinition(ResultDecl, Unit);
   return llvm::make_error(index_error_code::failed_import);
 }
 
@@ -411,10 +411,13 @@
 
 template 
 llvm::Expected
-CrossTranslationUnitContext::importDefinitionImpl(const T *D) {
+CrossTranslationUnitContext::importDefinitionImpl(const T *D, ASTUnit *Unit) {
   assert(hasBodyOrInit(D) && "Decls to be imported should have body or init.");
 
-  ASTImporter &Importer = getOrCreateASTImporter(D->getASTContext());
+  assert(&D->getASTContext() == &Unit->getASTContext() &&
+ "ASTContext of Decl and the unit should match.");
+  ASTImporter &Importer = getOrCreateASTImporter(Unit);
+
   auto ToDeclOrError = Importer.Import(D);
   if (!ToDeclOrError) {
 handleAllErrors(ToDeclOrError.takeError(),
@@ -441,13 +444,15 @@
 }
 
 llvm::Expected
-CrossTranslationUnitContext::importDefinition(const FunctionDecl *FD) {
-  return importDefinitionImpl(FD);
+CrossTranslationUnitContext::importDefinition(const FunctionDecl *FD,
+  ASTUnit *Unit) {
+  return importDefinitionImpl(FD, Unit);
 }
 
 llvm::Expected
-CrossTranslationUnitContext::importDefinition(const VarDecl *VD) {
-  return importDefinitionImpl(VD);
+CrossTranslationUnitContext::importDefinition(const VarDecl *VD,
+  ASTUnit *Unit) {
+  return importDefinitionImpl(VD, Unit);
 }
 
 void CrossTranslationUnitContext::lazyInitImporterSharedSt(
@@ -457,7 +462,9 @@
 }
 
 ASTImporter &
-CrossTranslationUnitContext::getOrCreateASTImporter(ASTContext &From) {
+CrossTranslationUnitContext::getOrCreateASTImporter(ASTUnit *Unit) {
+  ASTContext &From = Unit->getASTContext();
+
   auto I = ASTUnitImporterMap.find(From.getTranslationUnitDecl());
   if (I != ASTUnitImporterMap.end())
 return *I->second;
@@ -465,9 +472,32 @@
   ASTImporter *NewImporter = new ASTImporter(
   Context, Context.getSourceManager().getFileManager(), From,
   From.getSourceManager().getFileManager(), false,

[PATCH] D65102: [OpenCL] Rename lang mode flag for C++ mode

2019-07-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh accepted this revision.
svenvh added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: include/clang/Frontend/LangStandards.def:177
 LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0")
+LANGSTANDARD_ALIAS_DEPR(openclcpp, "CLC++")
 

It surprised me that the capitalized aliases for the (non-C++) CL standards are 
considered deprecated, because the OpenCL spec only mentions the capitalized 
variants.  The deprecation was introduced by 59456511f4 ("Improve diagnostics 
for bad -std= flag.", 2017-04-27).  It doesn't seem to have any practical 
implications though.

The convention for non-OpenCL standards seems to be all lowercase though (e.g. 
`c99`, `c++14`, so it sounds reasonable to mark the capitalized `CLC++` as 
deprecated.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65102/new/

https://reviews.llvm.org/D65102



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


r366884 - [CrossTU] Add a function to retrieve original source location.

2019-07-24 Thread Balazs Keri via cfe-commits
Author: balazske
Date: Wed Jul 24 03:16:37 2019
New Revision: 366884

URL: http://llvm.org/viewvc/llvm-project?rev=366884&view=rev
Log:
[CrossTU] Add a function to retrieve original source location.

Summary:
A new function will be added to get the original SourceLocation
for a SourceLocation that was imported as result of getCrossTUDefinition.
The returned SourceLocation is in the context of the (original)
SourceManager for the original source file. Additionally the
ASTUnit object for that source file is returned. This is needed
to get a SourceManager to operate on with the returned source location.

The new function works if multiple different source files are loaded
with the same CrossTU context.

Reviewers: martong, shafik

Reviewed By: martong

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/AST/ASTImporter.h
cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp

Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=366884&r1=366883&r2=366884&view=diff
==
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Wed Jul 24 03:16:37 2019
@@ -87,6 +87,8 @@ class TypeSourceInfo;
 using NonEquivalentDeclSet = llvm::DenseSet>;
 using ImportedCXXBaseSpecifierMap =
 llvm::DenseMap;
+using FileIDImportHandlerType =
+std::function;
 
 // An ImportPath is the list of the AST nodes which we visit during an
 // Import call.
@@ -210,6 +212,8 @@ class TypeSourceInfo;
 };
 
   private:
+FileIDImportHandlerType FileIDImportHandler;
+
 std::shared_ptr SharedState = nullptr;
 
 /// The path which we go through during the import of a given AST node.
@@ -310,6 +314,14 @@ class TypeSourceInfo;
 
 virtual ~ASTImporter();
 
+/// Set a callback function for FileID import handling.
+/// The function is invoked when a FileID is imported from the From 
context.
+/// The imported FileID in the To context and the original FileID in the
+/// From context is passed to it.
+void setFileIDImportHandler(FileIDImportHandlerType H) {
+  FileIDImportHandler = H;
+}
+
 /// Whether the importer will perform a minimal import, creating
 /// to-be-completed forward declarations when possible.
 bool isMinimalImport() const { return Minimal; }

Modified: cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h?rev=366884&r1=366883&r2=366884&view=diff
==
--- cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h (original)
+++ cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h Wed Jul 24 03:16:37 
2019
@@ -153,8 +153,10 @@ public:
   ///was passed to the constructor.
   ///
   /// \return Returns the resulting definition or an error.
-  llvm::Expected importDefinition(const FunctionDecl 
*FD);
-  llvm::Expected importDefinition(const VarDecl *VD);
+  llvm::Expected importDefinition(const FunctionDecl *FD,
+ASTUnit *Unit);
+  llvm::Expected importDefinition(const VarDecl *VD,
+   ASTUnit *Unit);
 
   /// Get a name to identify a named decl.
   static std::string getLookupName(const NamedDecl *ND);
@@ -162,9 +164,23 @@ public:
   /// Emit diagnostics for the user for potential configuration errors.
   void emitCrossTUDiagnostics(const IndexError &IE);
 
+  /// Determine the original source location in the original TU for an
+  /// imported source location.
+  /// \p ToLoc Source location in the imported-to AST.
+  /// \return Source location in the imported-from AST and the corresponding
+  /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit
+  /// object that is returned here).
+  /// If any error happens (ToLoc is a non-imported source location) empty is
+  /// returned.
+  llvm::Optional>
+  getImportedFromSourceLocation(const clang::SourceLocation &ToLoc) const;
+
 private:
+  using ImportedFileIDMap =
+  llvm::DenseMap>;
+
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
-  ASTImporter &getOrCreateASTImporter(ASTContext &From);
+  ASTImporter &getOrCreateASTImporter(ASTUnit *Unit);
   template 
   llvm::Expected getCrossTUDefinitionImpl(const T *D,
  StringRef CrossTUDir,
@@ -174,7 +190,7 @@ private:
   const T *findDefInDeclContext(const DeclContext *DC,
 StringRef

[PATCH] D65064: [CrossTU] Add a function to retrieve original source location.

2019-07-24 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366884: [CrossTU] Add a function to retrieve original source 
location. (authored by balazske, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65064?vs=211454&id=211456#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65064/new/

https://reviews.llvm.org/D65064

Files:
  cfe/trunk/include/clang/AST/ASTImporter.h
  cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
  cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
===
--- cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
+++ cfe/trunk/include/clang/CrossTU/CrossTranslationUnit.h
@@ -153,8 +153,10 @@
   ///was passed to the constructor.
   ///
   /// \return Returns the resulting definition or an error.
-  llvm::Expected importDefinition(const FunctionDecl *FD);
-  llvm::Expected importDefinition(const VarDecl *VD);
+  llvm::Expected importDefinition(const FunctionDecl *FD,
+ASTUnit *Unit);
+  llvm::Expected importDefinition(const VarDecl *VD,
+   ASTUnit *Unit);
 
   /// Get a name to identify a named decl.
   static std::string getLookupName(const NamedDecl *ND);
@@ -162,9 +164,23 @@
   /// Emit diagnostics for the user for potential configuration errors.
   void emitCrossTUDiagnostics(const IndexError &IE);
 
+  /// Determine the original source location in the original TU for an
+  /// imported source location.
+  /// \p ToLoc Source location in the imported-to AST.
+  /// \return Source location in the imported-from AST and the corresponding
+  /// ASTUnit object (the AST was loaded from a file using an internal ASTUnit
+  /// object that is returned here).
+  /// If any error happens (ToLoc is a non-imported source location) empty is
+  /// returned.
+  llvm::Optional>
+  getImportedFromSourceLocation(const clang::SourceLocation &ToLoc) const;
+
 private:
+  using ImportedFileIDMap =
+  llvm::DenseMap>;
+
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
-  ASTImporter &getOrCreateASTImporter(ASTContext &From);
+  ASTImporter &getOrCreateASTImporter(ASTUnit *Unit);
   template 
   llvm::Expected getCrossTUDefinitionImpl(const T *D,
  StringRef CrossTUDir,
@@ -174,7 +190,7 @@
   const T *findDefInDeclContext(const DeclContext *DC,
 StringRef LookupName);
   template 
-  llvm::Expected importDefinitionImpl(const T *D);
+  llvm::Expected importDefinitionImpl(const T *D, ASTUnit *Unit);
 
   llvm::StringMap> FileASTUnitMap;
   llvm::StringMap NameASTUnitMap;
@@ -184,6 +200,15 @@
   CompilerInstance &CI;
   ASTContext &Context;
   std::shared_ptr ImporterSharedSt;
+  /// Map of imported FileID's (in "To" context) to FileID in "From" context
+  /// and the ASTUnit for the From context.
+  /// This map is used by getImportedFromSourceLocation to lookup a FileID and
+  /// its Preprocessor when knowing only the FileID in the 'To' context. The
+  /// FileID could be imported by any of multiple 'From' ASTImporter objects.
+  /// we do not want to loop over all ASTImporter's to find the one that
+  /// imported the FileID.
+  ImportedFileIDMap ImportedFileIDs;
+
   /// \p CTULoadTreshold should serve as an upper limit to the number of TUs
   /// imported in order to reduce the memory footprint of CTU analysis.
   const unsigned CTULoadThreshold;
Index: cfe/trunk/include/clang/AST/ASTImporter.h
===
--- cfe/trunk/include/clang/AST/ASTImporter.h
+++ cfe/trunk/include/clang/AST/ASTImporter.h
@@ -87,6 +87,8 @@
 using NonEquivalentDeclSet = llvm::DenseSet>;
 using ImportedCXXBaseSpecifierMap =
 llvm::DenseMap;
+using FileIDImportHandlerType =
+std::function;
 
 // An ImportPath is the list of the AST nodes which we visit during an
 // Import call.
@@ -210,6 +212,8 @@
 };
 
   private:
+FileIDImportHandlerType FileIDImportHandler;
+
 std::shared_ptr SharedState = nullptr;
 
 /// The path which we go through during the import of a given AST node.
@@ -310,6 +314,14 @@
 
 virtual ~ASTImporter();
 
+/// Set a callback function for FileID import handling.
+/// The function is invoked when a FileID is imported from the From context.
+/// The imported FileID in the To context and the original FileID in the
+/// From context is passed to it.
+void setFileIDImportHandler(FileIDImportHandlerType H) {
+  FileIDImportHandler = H;
+}
+
 /// Whether the importer will perform a minimal im

[PATCH] D65196: [CFG] Introduce CFGElementRef, a wrapper that knows it's position in a CFGBlock

2019-07-24 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, baloghadamsoftware, Charusso, 
dcoughlin, rnkovacs, a_sidorin.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp.

Previously, collecting `CFGElement`s in a set was practially impossible, 
because both `CFGBlock::operator[]` and both the iterators returned it by 
value. One workaround would be to collect the iterators instead, but they don't 
really capture the concept of an element, and elements from different iterator 
types are incomparable.

This patch introduces `CFGElementRef`, a wrapper around a `(CFGBlock, Index)` 
pair, and a variety of new iterators and iterator ranges  to solve this problem.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65196

Files:
  clang/include/clang/Analysis/CFG.h
  clang/lib/Analysis/CFG.cpp
  clang/unittests/Analysis/CFGTest.cpp

Index: clang/unittests/Analysis/CFGTest.cpp
===
--- clang/unittests/Analysis/CFGTest.cpp
+++ clang/unittests/Analysis/CFGTest.cpp
@@ -67,6 +67,139 @@
   expectLinear(true,  "void foo() { foo(); }"); // Recursion is not our problem.
 }
 
+TEST(CFG, ElementRefIterator) {
+  const char *Code = R"(void f() {
+  int i;
+  int j;
+  i = 5;
+  i = 6;
+  j = 7;
+})";
+
+  BuildResult B = BuildCFG(Code);
+  EXPECT_EQ(BuildResult::BuiltCFG, B.getStatus());
+  CFG *Cfg = B.getCFG();
+
+  // [B2 (ENTRY)]
+  //   Succs (1): B1
+
+  // [B1]
+  //   1: int i;
+  //   2: int j;
+  //   3: i = 5
+  //   4: i = 6
+  //   5: j = 7
+  //   Preds (1): B2
+  //   Succs (1): B0
+
+  // [B0 (EXIT)]
+  //   Preds (1): B1
+  CFGBlock *MainBlock = *(Cfg->begin() + 1);
+
+  constexpr CFGBlock::ref_iterator::difference_type MainBlockSize = 4;
+
+  // The rest of this test looks totally insane, but there iterators are
+  // templates under the hood, to it's important to instantiate everything for
+  // proper converage.
+
+  // Non-reverse, non-const version
+  long Index = 0;
+  for (CFGBlock::CFGElementRef ElementRef : MainBlock->refs()) {
+EXPECT_EQ(ElementRef.getParent(), MainBlock);
+EXPECT_EQ(ElementRef.getIndexInBlock(), Index);
+EXPECT_TRUE(ElementRef->getAs());
+EXPECT_TRUE((*ElementRef).getAs());
+EXPECT_EQ(ElementRef.getParent(), MainBlock);
+++Index;
+  }
+  EXPECT_TRUE(*MainBlock->ref_begin() < *(MainBlock->ref_begin() + 1));
+  EXPECT_TRUE(*MainBlock->ref_begin() == *MainBlock->ref_begin());
+  EXPECT_FALSE(*MainBlock->ref_begin() != *MainBlock->ref_begin());
+
+  EXPECT_TRUE(MainBlock->ref_begin() < MainBlock->ref_begin() + 1);
+  EXPECT_TRUE(MainBlock->ref_begin() == MainBlock->ref_begin());
+  EXPECT_FALSE(MainBlock->ref_begin() != MainBlock->ref_begin());
+  EXPECT_EQ(MainBlock->ref_end() - MainBlock->ref_begin(), MainBlockSize + 1);
+  EXPECT_EQ(MainBlock->ref_end() - MainBlockSize - 1, MainBlock->ref_begin());
+  EXPECT_EQ(MainBlock->ref_begin() + MainBlockSize + 1, MainBlock->ref_end());
+  EXPECT_EQ(MainBlock->ref_begin()++, MainBlock->ref_begin());
+  EXPECT_EQ(++(MainBlock->ref_begin()), MainBlock->ref_begin() + 1);
+
+  // Non-reverse, non-const version
+  const CFGBlock *CMainBlock = MainBlock;
+  Index = 0;
+  for (CFGBlock::ConstCFGElementRef ElementRef : CMainBlock->refs()) {
+EXPECT_EQ(ElementRef.getParent(), CMainBlock);
+EXPECT_EQ(ElementRef.getIndexInBlock(), Index);
+EXPECT_TRUE(ElementRef->getAs());
+EXPECT_TRUE((*ElementRef).getAs());
+EXPECT_EQ(ElementRef.getParent(), MainBlock);
+++Index;
+  }
+  EXPECT_TRUE(*CMainBlock->ref_begin() < *(CMainBlock->ref_begin() + 1));
+  EXPECT_TRUE(*CMainBlock->ref_begin() == *CMainBlock->ref_begin());
+  EXPECT_FALSE(*CMainBlock->ref_begin() != *CMainBlock->ref_begin());
+
+  EXPECT_TRUE(CMainBlock->ref_begin() < CMainBlock->ref_begin() + 1);
+  EXPECT_TRUE(CMainBlock->ref_begin() == CMainBlock->ref_begin());
+  EXPECT_FALSE(CMainBlock->ref_begin() != CMainBlock->ref_begin());
+  EXPECT_EQ(CMainBlock->ref_end() - CMainBlock->ref_begin(), MainBlockSize + 1);
+  EXPECT_EQ(CMainBlock->ref_end() - MainBlockSize - 1, CMainBlock->ref_begin());
+  EXPECT_EQ(CMainBlock->ref_begin() + MainBlockSize + 1, CMainBlock->ref_end());
+  EXPECT_EQ(CMainBlock->ref_begin()++, CMainBlock->ref_begin());
+  EXPECT_EQ(++(CMainBlock->ref_begin()), CMainBlock->ref_begin() + 1);
+
+  // Reverse, non-const version
+  Index = MainBlockSize;
+  for (CFGBlock::CFGElementRef ElementRef : MainBlock->rrefs()) {
+llvm::errs() << Index << '\n';
+EXPECT_EQ(ElementRef.getParent(), MainBlock);
+EXPECT_EQ(ElementRef.getIndexInBlock(), Index);
+EXPECT_TRUE(ElementRef->getAs());
+EXPECT_TRUE((*ElementRef).getAs());
+EXPECT_EQ(ElementRef.getParent(), MainBlock);
+--Index;
+  }
+  EXPECT_FALSE(*MainBlock->rref_begin() < *(MainBlock

[PATCH] D64991: [analyzer][WIP] Implement a primitive reaching definitions analysis

2019-07-24 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 211457.
Szelethus added a comment.

Rebase on top of D65196 .


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64991/new/

https://reviews.llvm.org/D64991

Files:
  clang/include/clang/Analysis/Analyses/ReachingDefinitions.h
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Analysis/ReachingDefinitions.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
  clang/test/Analysis/dump-definitions.cpp

Index: clang/test/Analysis/dump-definitions.cpp
===
--- /dev/null
+++ clang/test/Analysis/dump-definitions.cpp
@@ -0,0 +1,386 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=debug.DumpCFG \
+// RUN:   -analyzer-checker=debug.DumpGenSets \
+// RUN:   -analyzer-checker=debug.DumpKillSets \
+// RUN:   -analyzer-checker=debug.DumpReachingDefinitions \
+// RUN:   2>&1 | FileCheck %s
+
+int global_var;
+
+int getInt();
+int *getIntPtr();
+bool coin();
+
+
+void single_vardecl_in_declstmt() {
+  int *ptr = getIntPtr();
+}
+// [B2 (ENTRY)] -> [B1] -> [B0 (EXIT)]
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 1 (global_var, [1, 2])
+// CHECK-NEXT: 1 (ptr, [1, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (global_var, [1, 2])
+// CHECK-NEXT: 0 IN (ptr, [1, 3])
+// CHECK-NEXT: 0 OUT (global_var, [1, 2])
+// CHECK-NEXT: 0 OUT (ptr, [1, 3])
+// CHECK-NEXT: 1 OUT (global_var, [1, 2])
+// CHECK-NEXT: 1 OUT (ptr, [1, 3])
+
+void multiple_vardecl_in_declstmt() {
+  int *ptr = getIntPtr(), i;
+}
+// [B2 (ENTRY)] -> [B1] -> [B0 (EXIT)]
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 1 (global_var, [1, 2])
+// CHECK-NEXT: 1 (ptr, [1, 3])
+// CHECK-NEXT: 1 (i, [1, 4])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (global_var, [1, 2])
+// CHECK-NEXT: 0 IN (ptr, [1, 3])
+// CHECK-NEXT: 0 IN (i, [1, 4])
+// CHECK-NEXT: 0 OUT (global_var, [1, 2])
+// CHECK-NEXT: 0 OUT (ptr, [1, 3])
+// CHECK-NEXT: 0 OUT (i, [1, 4])
+// CHECK-NEXT: 1 OUT (global_var, [1, 2])
+// CHECK-NEXT: 1 OUT (ptr, [1, 3])
+// CHECK-NEXT: 1 OUT (i, [1, 4])
+
+void function_and_vardecl_in_declstmt() {
+  int *ptr = getIntPtr(), a();
+}
+// [B2 (ENTRY)] -> [B1] -> [B0 (EXIT)]
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 1 (global_var, [1, 2])
+// CHECK-NEXT: 1 (ptr, [1, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (global_var, [1, 2])
+// CHECK-NEXT: 0 IN (ptr, [1, 3])
+// CHECK-NEXT: 0 OUT (global_var, [1, 2])
+// CHECK-NEXT: 0 OUT (ptr, [1, 3])
+// CHECK-NEXT: 1 OUT (global_var, [1, 2])
+// CHECK-NEXT: 1 OUT (ptr, [1, 3])
+
+void single_def_in_same_block() {
+  int *ptr = getIntPtr();
+
+  if (coin())
+ptr = 0;
+
+  if (!ptr)
+*ptr = 5;
+}
+//-> [B3] ->-> [B1] ->
+//   /  \  /  \
+// [B5 (ENTRY)] -> [B4] --> [B2] ---> [B0 (EXIT)]
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 3 (ptr, [3, 3])
+// CHECK-NEXT: 4 (global_var, [4, 6])
+// CHECK-NEXT: 4 (ptr, [4, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 3 (ptr, [4, 3])
+// CHECK-NEXT: 4 (ptr, [3, 3])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (global_var, [4, 6])
+// CHECK-NEXT: 0 IN (ptr, [3, 3])
+// CHECK-NEXT: 0 OUT (global_var, [4, 6])
+// CHECK-NEXT: 0 OUT (ptr, [3, 3])
+// CHECK-NEXT: 1 IN (global_var, [4, 6])
+// CHECK-NEXT: 1 IN (ptr, [3, 3])
+// CHECK-NEXT: 1 OUT (global_var, [4, 6])
+// CHECK-NEXT: 1 OUT (ptr, [3, 3])
+// CHECK-NEXT: 2 IN (global_var, [4, 6])
+// CHECK-NEXT: 2 IN (ptr, [3, 3])
+// CHECK-NEXT: 2 OUT (global_var, [4, 6])
+// CHECK-NEXT: 2 OUT (ptr, [3, 3])
+// CHECK-NEXT: 3 IN (global_var, [4, 6])
+// CHECK-NEXT: 3 IN (ptr, [4, 3])
+// CHECK-NEXT: 3 OUT (global_var, [4, 6])
+// CHECK-NEXT: 3 OUT (ptr, [3, 3])
+// CHECK-NEXT: 4 OUT (global_var, [4, 6])
+// CHECK-NEXT: 4 OUT (ptr, [4, 3])
+
+void different_assignments() {
+  int i = getInt();
+
+  if (coin())
+i = 0;
+
+  i += 3;
+
+  if (!coin())
+i -= 2;
+
+  i *= 9;
+
+  if (i = 0)
+;
+}
+//-> [B5] ->-> [B3] ->-> [B1] ->
+//   /  \  /  \  /  \
+// [B7 (ENTRY)] -> [B6] --> [B4] ---> [B2] ---> [B0 (EXIT)]
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 2 (i, [2, 5])
+// CHECK-NEXT: 3 (i, [3, 2])
+// CHECK-

[PATCH] D65101: [clangd] SelectionTree treats TranslationUnitDecl consistently with other containers.

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 211458.
sammccall added a comment.

Reverted commonAncestor() back to a pointer, return null if ancestor is TUDecl.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65101/new/

https://reviews.llvm.org/D65101

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -266,16 +266,16 @@
   llvm::StringLiteral ID = "ShowSelectionTree";
 
   checkAvailable(ID, "^int f^oo() { re^turn 2 ^+ 2; }");
-  checkNotAvailable(ID, "/*c^omment*/ int foo() return 2 ^ + 2; }");
+  checkAvailable(ID, "/*c^omment*/ int foo() return 2 ^ + 2; }");
 
   const char *Input = "int fcall(int); int x = fca[[ll(2 +]]2);";
-  const char *Output = R"(TranslationUnitDecl 
-  VarDecl int x = fcall(2 + 2)
-   .CallExpr fcall(2 + 2)
-  ImplicitCastExpr fcall
-   .DeclRefExpr fcall
- .BinaryOperator 2 + 2
-   *IntegerLiteral 2
+  const char *Output = R"( TranslationUnitDecl 
+   VarDecl int x = fcall(2 + 2)
+.CallExpr fcall(2 + 2)
+   ImplicitCastExpr fcall
+.DeclRefExpr fcall
+  .BinaryOperator 2 + 2
+*IntegerLiteral 2
 )";
   EXPECT_EQ(Output, getMessage(ID, Input));
 }
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -9,6 +9,8 @@
 #include "Selection.h"
 #include "SourceCode.h"
 #include "TestTU.h"
+#include "clang/AST/Decl.h"
+#include "llvm/Support/Casting.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -40,6 +42,8 @@
   const SourceManager &SM = AST.getSourceManager();
   const LangOptions &LangOpts = AST.getASTContext().getLangOpts();
   StringRef Buffer = SM.getBufferData(SM.getMainFileID());
+  if (llvm::isa_and_nonnull(N->ASTNode.get()))
+return Range{Position{}, offsetToPosition(Buffer, Buffer.size())};
   auto FileRange =
   toHalfOpenFileRange(SM, LangOpts, N->ASTNode.getSourceRange());
   assert(FileRange && "We should be able to get the File Range");
@@ -53,7 +57,7 @@
 }
 
 std::vector allNodes(const SelectionTree &T) {
-  std::vector Result = {T.root()};
+  std::vector Result = {&T.root()};
   for (unsigned I = 0; I < Result.size(); ++I) {
 const SelectionTree::Node *N = Result[I];
 Result.insert(Result.end(), N->Children.begin(), N->Children.end());
@@ -63,16 +67,16 @@
 
 // Returns true if Common is a descendent of Root.
 // Verifies nothing is selected above Common.
-bool verifyCommonAncestor(const SelectionTree::Node *Root,
+bool verifyCommonAncestor(const SelectionTree::Node &Root,
   const SelectionTree::Node *Common,
   StringRef MarkedCode) {
-  if (Root == Common)
+  if (&Root == Common)
 return true;
-  if (Root->Selected)
+  if (Root.Selected)
 ADD_FAILURE() << "Selected nodes outside common ancestor\n" << MarkedCode;
   bool Seen = false;
-  for (const SelectionTree::Node *Child : Root->Children)
-if (verifyCommonAncestor(Child, Common, MarkedCode)) {
+  for (const SelectionTree::Node *Child : Root.Children)
+if (verifyCommonAncestor(*Child, Common, MarkedCode)) {
   if (Seen)
 ADD_FAILURE() << "Saw common ancestor twice\n" << MarkedCode;
   Seen = true;
@@ -239,6 +243,9 @@
   {"int x = 42;^", nullptr},
   {"int x = 42^;", nullptr},
 
+  // Common ancestor is logically TUDecl, but we never return that.
+  {"^int x; int y;^", nullptr},
+
   // Node types that have caused problems in the past.
   {"template  void foo() { [[^T]] t; }",
"TemplateTypeParmTypeLoc"},
@@ -256,18 +263,17 @@
 Annotations Test(C.Code);
 auto AST = TestTU::withCode(Test.code()).build();
 auto T = makeSelectionTree(C.Code, AST);
+EXPECT_EQ("TranslationUnitDecl", nodeKind(&T.root())) << C.Code;
 
 if (Test.ranges().empty()) {
   // If no [[range]] is marked in the example, there should be no selection.
   EXPECT_FALSE(T.commonAncestor()) << C.Code << "\n" << T;
-  EXPECT_FALSE(T.root()) << C.Code << "\n" << T;
 } else {
-  // If there is an expected selection, both common ancestor and root
-  // should exist with the appropriate node types in them.
+  // If there is an expected selection, common ancestor should exist
+  // with the appropriate node type.
   EXPECT_EQ(C.CommonAncestorKind, nodeKind(T.commonAncestor()))
   << C.Code << "\n"
   << T;
-  EXPECT_EQ("TranslationUnitDecl", nodeK

[PATCH] D65101: [clangd] SelectionTree treats TranslationUnitDecl consistently with other containers.

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 3 inline comments as done.
sammccall added inline comments.



Comment at: 
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp:47
   // Narrow the traversal scope to the selected node.
   Inputs.AST.getASTContext().setTraversalScope(
   {const_cast(InterestedDecl)});

hokein wrote:
> we'll get a TUDecl if the whole file is selected, however this tweak doesn't 
> want to traversal the whole TU (otherwise we will generate highlighting 
> tokens for #included files), we only interested in the top level decls of the 
> main file. 
Right! We discussed this further offline, and came to the conclusions that:
 - traversing the whole TU is undesirable almost always
 - it's already possible to get the whole TU from commonAncestor today (by 
selecting multiple top-level decls), and there are resulting bugs
 - returning null instead of TU from commonAncestor() is a safer default



Comment at: clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp:38
  N = N->Parent)
-  if (dumpable(N->ASTNode))
+  if (N->Parent && dumpable(N->ASTNode))
 Node = N->ASTNode;

hokein wrote:
> Is the `N->Parent` intended?  this seems like we'd exclude the TUDecl?
This is obsolete now, but was useful to flag: it's exactly the type of question 
that tweaks shouldn't have to worry about by default.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65101/new/

https://reviews.llvm.org/D65101



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


[PATCH] D65101: [clangd] SelectionTree treats TranslationUnitDecl consistently with other containers.

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 211459.
sammccall marked 3 inline comments as done.
sammccall added a comment.

doc selectiontree's interactions with preprocessor


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65101/new/

https://reviews.llvm.org/D65101

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -266,16 +266,16 @@
   llvm::StringLiteral ID = "ShowSelectionTree";
 
   checkAvailable(ID, "^int f^oo() { re^turn 2 ^+ 2; }");
-  checkNotAvailable(ID, "/*c^omment*/ int foo() return 2 ^ + 2; }");
+  checkAvailable(ID, "/*c^omment*/ int foo() return 2 ^ + 2; }");
 
   const char *Input = "int fcall(int); int x = fca[[ll(2 +]]2);";
-  const char *Output = R"(TranslationUnitDecl 
-  VarDecl int x = fcall(2 + 2)
-   .CallExpr fcall(2 + 2)
-  ImplicitCastExpr fcall
-   .DeclRefExpr fcall
- .BinaryOperator 2 + 2
-   *IntegerLiteral 2
+  const char *Output = R"( TranslationUnitDecl 
+   VarDecl int x = fcall(2 + 2)
+.CallExpr fcall(2 + 2)
+   ImplicitCastExpr fcall
+.DeclRefExpr fcall
+  .BinaryOperator 2 + 2
+*IntegerLiteral 2
 )";
   EXPECT_EQ(Output, getMessage(ID, Input));
 }
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -9,6 +9,8 @@
 #include "Selection.h"
 #include "SourceCode.h"
 #include "TestTU.h"
+#include "clang/AST/Decl.h"
+#include "llvm/Support/Casting.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -40,6 +42,8 @@
   const SourceManager &SM = AST.getSourceManager();
   const LangOptions &LangOpts = AST.getASTContext().getLangOpts();
   StringRef Buffer = SM.getBufferData(SM.getMainFileID());
+  if (llvm::isa_and_nonnull(N->ASTNode.get()))
+return Range{Position{}, offsetToPosition(Buffer, Buffer.size())};
   auto FileRange =
   toHalfOpenFileRange(SM, LangOpts, N->ASTNode.getSourceRange());
   assert(FileRange && "We should be able to get the File Range");
@@ -53,7 +57,7 @@
 }
 
 std::vector allNodes(const SelectionTree &T) {
-  std::vector Result = {T.root()};
+  std::vector Result = {&T.root()};
   for (unsigned I = 0; I < Result.size(); ++I) {
 const SelectionTree::Node *N = Result[I];
 Result.insert(Result.end(), N->Children.begin(), N->Children.end());
@@ -63,16 +67,16 @@
 
 // Returns true if Common is a descendent of Root.
 // Verifies nothing is selected above Common.
-bool verifyCommonAncestor(const SelectionTree::Node *Root,
+bool verifyCommonAncestor(const SelectionTree::Node &Root,
   const SelectionTree::Node *Common,
   StringRef MarkedCode) {
-  if (Root == Common)
+  if (&Root == Common)
 return true;
-  if (Root->Selected)
+  if (Root.Selected)
 ADD_FAILURE() << "Selected nodes outside common ancestor\n" << MarkedCode;
   bool Seen = false;
-  for (const SelectionTree::Node *Child : Root->Children)
-if (verifyCommonAncestor(Child, Common, MarkedCode)) {
+  for (const SelectionTree::Node *Child : Root.Children)
+if (verifyCommonAncestor(*Child, Common, MarkedCode)) {
   if (Seen)
 ADD_FAILURE() << "Saw common ancestor twice\n" << MarkedCode;
   Seen = true;
@@ -239,6 +243,9 @@
   {"int x = 42;^", nullptr},
   {"int x = 42^;", nullptr},
 
+  // Common ancestor is logically TUDecl, but we never return that.
+  {"^int x; int y;^", nullptr},
+
   // Node types that have caused problems in the past.
   {"template  void foo() { [[^T]] t; }",
"TemplateTypeParmTypeLoc"},
@@ -256,18 +263,17 @@
 Annotations Test(C.Code);
 auto AST = TestTU::withCode(Test.code()).build();
 auto T = makeSelectionTree(C.Code, AST);
+EXPECT_EQ("TranslationUnitDecl", nodeKind(&T.root())) << C.Code;
 
 if (Test.ranges().empty()) {
   // If no [[range]] is marked in the example, there should be no selection.
   EXPECT_FALSE(T.commonAncestor()) << C.Code << "\n" << T;
-  EXPECT_FALSE(T.root()) << C.Code << "\n" << T;
 } else {
-  // If there is an expected selection, both common ancestor and root
-  // should exist with the appropriate node types in them.
+  // If there is an expected selection, common ancestor should exist
+  // with the appropriate node type.
   EXPECT_EQ(C.CommonAncestorKind, nodeKind(T.commonAncestor()))
   << C.Code << "\n"
   << T;
-  EXPECT_EQ("TranslationU

[PATCH] D65102: [OpenCL] Rename lang mode flag for C++ mode

2019-07-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia marked an inline comment as done.
Anastasia added inline comments.



Comment at: include/clang/Frontend/LangStandards.def:177
 LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0")
+LANGSTANDARD_ALIAS_DEPR(openclcpp, "CLC++")
 

svenvh wrote:
> It surprised me that the capitalized aliases for the (non-C++) CL standards 
> are considered deprecated, because the OpenCL spec only mentions the 
> capitalized variants.  The deprecation was introduced by 59456511f4 ("Improve 
> diagnostics for bad -std= flag.", 2017-04-27).  It doesn't seem to have any 
> practical implications though.
> 
> The convention for non-OpenCL standards seems to be all lowercase though 
> (e.g. `c99`, `c++14`, so it sounds reasonable to mark the capitalized `CLC++` 
> as deprecated.
Yeah, a misalignment indeed.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65102/new/

https://reviews.llvm.org/D65102



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


[PATCH] D65101: [clangd] SelectionTree treats TranslationUnitDecl consistently with other containers.

2019-07-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

looks good!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65101/new/

https://reviews.llvm.org/D65101



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


[PATCH] D64744: #pragma clang loop vectorize_predicate(enable|disable)

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

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64744/new/

https://reviews.llvm.org/D64744



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


[PATCH] D65104: [clang-tidy] Add FixItHint for performance-noexcept-move-constructor

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

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65104/new/

https://reviews.llvm.org/D65104



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


[PATCH] D65176: [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

2019-07-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Driver/Types.def:39-45
+// Some of the options in Flags have been removed, so far those are:
+//  a - The type should only be assembled: Now, check that Phases contains
+//  phases::Assemble but not phases::Compile or phases::Backend.
+//  p - The type should only be precompiled: Now, check that Phases contains
+//  phases::Precompile but that Flags does not contain 'm'.
+//  m - Precompiling this type produces a module file: Now, check that
+//  isPrepeocessedModuleType.

Why should we document the removed flags, since users cannot write them anyway?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65176/new/

https://reviews.llvm.org/D65176



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


Re: [PATCH] D59254: [RFC] Implementation of Clang randstruct

2019-07-24 Thread Aaron Ballman via cfe-commits
On Tue, Jul 23, 2019 at 9:17 PM Connor Kuehl via Phabricator
 wrote:
>
> connorkuehl added a comment.
>
> In D59254#1429401 , @jfb wrote:
>
> > I find it easier to understand the code by looking at the tests. When you 
> > add tests, please make sure you test for:
> >
> > - Bit-fields
> > - Zero-width bit-field
>
>
> Hi JF,
>
> Could you elaborate on what I should be testing for here regarding the 
> zero-width bit-field? I'm not sure zero-width bit-fields are a concern since 
> I think they're illegal. I just tried compiling a "hello world" program with 
> a struct that has a zero width bit-field as one of its members and the 
> compiler emitted an error pointing at it.
>
>   error: named bit-field 'z' has zero width
>   int z : 0;
>   ^
>   1 error generated.

Zero-width bit-fields are not illegal, but they must be unnamed. e.g.,

struct S {
  int a : 1;
  int : 0;
  int b : 1;
};

See C17 6.7.2.1p12 for more details about zero-width bit-fields, but
essentially, the above declaration will pack a and b into separate
allocation units.

~Aaron

>
> For regular bit-fields the current implementation will keep adjacent 
> bit-fields together and will preserve their original order but the overall 
> group of adjacent bit-fields may relocate. My next revision will have a unit 
> test describing and testing this behavior.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D59254/new/
>
> https://reviews.llvm.org/D59254
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65200: [clangd] Add categories to help options, and only show clangd options.

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Restricting the categories prevents extra unwanted options from creeping into
help (D60663 ), and removes a bunch of noise 
from --help-hidden.

While here, remove `static` from the opts in favor of an anon namespace, to
reduce the noise level.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65200

Files:
  clang-tools-extra/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -35,6 +35,7 @@
 
 namespace clang {
 namespace clangd {
+namespace {
 
 using llvm::cl::cat;
 using llvm::cl::CommaSeparated;
@@ -43,25 +44,38 @@
 using llvm::cl::init;
 using llvm::cl::list;
 using llvm::cl::opt;
+using llvm::cl::OptionCategory;
 using llvm::cl::values;
 
-static opt CompileCommandsDir{
+// All flags must be placed in a category, or they will be shown neither in
+// --help, nor --help-hidden!
+OptionCategory Features("clangd feature options");
+OptionCategory Protocol("clangd protocol and logging options");
+OptionCategory CompileCommands("clangd compilation flags options");
+OptionCategory Misc("clangd miscellaneous options");
+const OptionCategory *ClangdCategories[] = {&Features, &Protocol,
+&CompileCommands, &Misc};
+
+opt CompileCommandsDir{
 "compile-commands-dir",
+cat(CompileCommands),
 desc("Specify a path to look for compile_commands.json. If path "
  "is invalid, clangd will look in the current directory and "
  "parent paths of each source file"),
 };
 
-static opt WorkerThreadsCount{
+opt WorkerThreadsCount{
 "j",
+cat(Misc),
 desc("Number of async workers used by clangd"),
 init(getDefaultAsyncThreadsCount()),
 };
 
 // FIXME: also support "plain" style where signatures are always omitted.
 enum CompletionStyleFlag { Detailed, Bundled };
-static opt CompletionStyle{
+opt CompletionStyle{
 "completion-style",
+cat(Features),
 desc("Granularity of code completion suggestions"),
 values(clEnumValN(Detailed, "detailed",
   "One completion item for each semantically distinct "
@@ -73,15 +87,17 @@
 
 // FIXME: Flags are the wrong mechanism for user preferences.
 // We should probably read a dotfile or similar.
-static opt IncludeIneligibleResults{
+opt IncludeIneligibleResults{
 "include-ineligible-results",
+cat(Features),
 desc("Include ineligible completion results (e.g. private members)"),
 init(CodeCompleteOptions().IncludeIneligibleResults),
 Hidden,
 };
 
-static opt InputStyle{
+opt InputStyle{
 "input-style",
+cat(Protocol),
 desc("Input JSON stream encoding"),
 values(
 clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"),
@@ -91,14 +107,16 @@
 Hidden,
 };
 
-static opt PrettyPrint{
+opt PrettyPrint{
 "pretty",
+cat(Protocol),
 desc("Pretty-print JSON output"),
 init(false),
 };
 
-static opt LogLevel{
+opt LogLevel{
 "log",
+cat(Protocol),
 desc("Verbosity of log messages written to stderr"),
 values(clEnumValN(Logger::Error, "error", "Error messages only"),
clEnumValN(Logger::Info, "info", "High level execution tracing"),
@@ -106,25 +124,28 @@
 init(Logger::Info),
 };
 
-static opt Test{
+opt Test{
 "lit-test",
+cat(Misc),
 desc("Abbreviation for -input-style=delimited -pretty -sync "
- "-enable-test-scheme -log=verbose."
+ "-enable-test-scheme -log=verbose. "
  "Intended to simplify lit tests"),
 init(false),
 Hidden,
 };
 
-static opt EnableTestScheme{
+opt EnableTestScheme{
 "enable-test-uri-scheme",
+cat(Protocol),
 desc("Enable 'test:' URI scheme. Only use in lit tests"),
 init(false),
 Hidden,
 };
 
 enum PCHStorageFlag { Disk, Memory };
-static opt PCHStorage{
+opt PCHStorage{
 "pch-storage",
+cat(Misc),
 desc("Storing PCHs in memory increases memory usages, but may "
  "improve performance"),
 values(
@@ -133,36 +154,41 @@
 init(PCHStorageFlag::Disk),
 };
 
-static opt LimitResults{
+opt LimitResults{
 "limit-results",
+cat(Features),
 desc("Limit the number of results returned by clangd. "
  "0 means no limit (default=100)"),
 init(100),
 };
 
-static opt Sync{
+opt Sync{
 "sync",
+cat(Misc),
 desc("Parse on main thread. If set, -j is ignored"),
 init(false),
 Hidden,
 };
 
-static opt ResourceDir{
+opt ResourceDir{
 "resource-dir",
+cat(CompileCommands),
 desc("Directory for system clang headers"),
 init(""),
 Hidden,
 };
 
-static opt InputMirrorFile{
+opt InputMir

[PATCH] D65092: [clang] Add isDirectlyDerivedFrom AST Matcher.

2019-07-24 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev added a comment.

Manuel, would you mind taking another look at the change please?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65092/new/

https://reviews.llvm.org/D65092



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


[PATCH] D65201: [clangd] Provide help text to users who run `clangd` in a terminal.

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65201

Files:
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -423,6 +423,11 @@
   if (Tracer)
 TracingSession.emplace(*Tracer);
 
+  // If a user ran `clangd` in a terminal without redirecting anything,
+  // it's somewhat likely they're confused about how to use clangd.
+  // Show them the help overview, which explains.
+  if (llvm::outs().is_displayed() && llvm::errs().is_displayed())
+llvm::errs() << Overview << "\n";
   // Use buffered stream to stderr (we still flush each log message). 
Unbuffered
   // stream can cause significant (non-deterministic) latency for the logger.
   llvm::errs().SetBuffered();


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -423,6 +423,11 @@
   if (Tracer)
 TracingSession.emplace(*Tracer);
 
+  // If a user ran `clangd` in a terminal without redirecting anything,
+  // it's somewhat likely they're confused about how to use clangd.
+  // Show them the help overview, which explains.
+  if (llvm::outs().is_displayed() && llvm::errs().is_displayed())
+llvm::errs() << Overview << "\n";
   // Use buffered stream to stderr (we still flush each log message). Unbuffered
   // stream can cause significant (non-deterministic) latency for the logger.
   llvm::errs().SetBuffered();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63954: Add lifetime categories attributes

2019-07-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2771
+  let Spellings = [CXX11<"gsl", "Owner">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let Args = [TypeArgument<"DerefType", /*opt=*/1>];

This subject should be `Struct` and same below.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2516
   "%0 and %1 attributes are not compatible">;
+def err_attribute_invalid_argument : Error<
+  "%0 is an invalid argument to attribute %1">;

mgehre wrote:
> aaron.ballman wrote:
> > Can you combine this one with `err_attribute_argument_vec_type_hint`?
> I'm not sure: vec_type_hint reads `"invalid attribute argument %0 - expecting 
> a vector or vectorizable scalar type"` and here `""%0 is an invalid argument 
> to attribute %1"`, i.e. one is positive ("expecting ...") and the other is 
> negative ("%0 is an invalid argument").
> 
> I don't know how to describe "not void, not reference, not array type" in 
> terms of "expecting ...", and I think that we should keep "expecting a vector 
> or vectorizable scalar type" on the  VecTypeHint attribute diagnostic.
I had figured it would be something like `%select{'void'|a reference type|an 
array type|a non-vector or non-vectorizable scalar type}0 is an invalid 
argument to attribute %1` but I am not strongly opposed if you want to keep the 
diagnostics separate.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2933
+  "|non-K&R-style functions"
+  "|classes}1">,
   InGroup;

You can drop this change when the `Subjects` field is fixed above.



Comment at: clang/include/clang/Sema/ParsedAttr.h:1037
   ExpectedFunctionWithProtoType,
+  ExpectedClass,
 };

Same



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4538-4542
+  if (!RD || RD->isUnion()) {
+S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
+<< AL << ExpectedClass;
+return;
+  }

You can drop this bit when the Subjects field is fixed above.



Comment at: clang/test/Misc/pragma-attribute-supported-attributes-list.test:119
 // CHECK-NEXT: Overloadable (SubjectMatchRule_function)
+// CHECK-NEXT: Owner (SubjectMatchRule_record)
 // CHECK-NEXT: ParamTypestate (SubjectMatchRule_variable_is_parameter)

These will also wind up needing to be updated when switching the `Subjects` 
field.



Comment at: clang/test/SemaCXX/attr-gsl-owner-pointer-parsing.cpp:2
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int [[gsl::Owner]] i;

This file tests part of parsing and part of Sema somewhat interchangeably. I'm 
not strictly opposed to it being that way, but it would be a bit cleaner to 
have the parsing tests in the Parser directory and the rest in SemaCXX (that 
also reduces the confusion from the file name).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63954/new/

https://reviews.llvm.org/D63954



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


[clang-tools-extra] r366893 - [clangd] SelectionTree treats TranslationUnitDecl (mostly) consistently with other containers.

2019-07-24 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Wed Jul 24 05:14:56 2019
New Revision: 366893

URL: http://llvm.org/viewvc/llvm-project?rev=366893&view=rev
Log:
[clangd] SelectionTree treats TranslationUnitDecl (mostly) consistently with 
other containers.

Summary:
Previously TranslationUnitDecl would never be selected.
This means root() is never null, and returns a reference.

commonAncestor() is in principle never null also, but returning TUDecl
here requires tweaks to be careful not to traverse it (this was already
possible when selecting multiple top-level decls, and there are associated 
bugs!)
Instead, never allow commonAncestor() to return TUDecl, return null instead.

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/Selection.cpp
clang-tools-extra/trunk/clangd/Selection.h
clang-tools-extra/trunk/clangd/refactor/tweaks/DumpAST.cpp
clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp

Modified: clang-tools-extra/trunk/clangd/Selection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Selection.cpp?rev=366893&r1=366892&r2=366893&view=diff
==
--- clang-tools-extra/trunk/clangd/Selection.cpp (original)
+++ clang-tools-extra/trunk/clangd/Selection.cpp Wed Jul 24 05:14:56 2019
@@ -103,8 +103,14 @@ public:
 V.TraverseAST(AST);
 assert(V.Stack.size() == 1 && "Unpaired push/pop?");
 assert(V.Stack.top() == &V.Nodes.front());
-if (V.Nodes.size() == 1) // TUDecl, but no nodes under it.
-  V.Nodes.clear();
+// We selected TUDecl if characters were unclaimed (or the file is empty).
+if (V.Nodes.size() == 1 || V.Claimed.add(Begin, End)) {
+  StringRef FileContent = AST.getSourceManager().getBufferData(File);
+  // Don't require the trailing newlines to be selected.
+  bool SelectedAll = Begin == 0 && End >= FileContent.rtrim().size();
+  V.Stack.top()->Selected =
+  SelectedAll ? SelectionTree::Complete : SelectionTree::Partial;
+}
 return std::move(V.Nodes);
   }
 
@@ -424,12 +430,13 @@ SelectionTree::SelectionTree(ASTContext
 : SelectionTree(AST, Offset, Offset) {}
 
 const Node *SelectionTree::commonAncestor() const {
-  if (!Root)
-return nullptr;
   const Node *Ancestor = Root;
   while (Ancestor->Children.size() == 1 && !Ancestor->Selected)
 Ancestor = Ancestor->Children.front();
-  return Ancestor;
+  // Returning nullptr here is a bit unprincipled, but it makes the API safer:
+  // the TranslationUnitDecl contains all of the preamble, so traversing it is 
a
+  // performance cliff. Callers can check for null and use root() if they want.
+  return Ancestor != Root ? Ancestor : nullptr;
 }
 
 const DeclContext& SelectionTree::Node::getDeclContext() const {

Modified: clang-tools-extra/trunk/clangd/Selection.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Selection.h?rev=366893&r1=366892&r2=366893&view=diff
==
--- clang-tools-extra/trunk/clangd/Selection.h (original)
+++ clang-tools-extra/trunk/clangd/Selection.h Wed Jul 24 05:14:56 2019
@@ -54,6 +54,11 @@ class ParsedAST;
 //  - if you want to traverse the selected nodes, they are all under
 //commonAncestor() in the tree.
 //
+// SelectionTree tries to behave sensibly in the presence of macros, but does
+// not model any preprocessor concepts: the output is a subset of the AST.
+// Currently comments, directives etc are treated as part of the lexically
+// containing AST node, (though we may want to change this in future).
+//
 // The SelectionTree owns the Node structures, but the ASTNode attributes
 // point back into the AST it was constructed with.
 class SelectionTree {
@@ -100,11 +105,11 @@ public:
 std::string kind() const;
   };
   // The most specific common ancestor of all the selected nodes.
-  // If there is no selection, this is nullptr.
+  // Returns nullptr if the common ancestor is the root.
+  // (This is to avoid accidentally traversing the TUDecl and thus preamble).
   const Node *commonAncestor() const;
   // The selection node corresponding to TranslationUnitDecl.
-  // If there is no selection, this is nullptr.
-  const Node *root() const { return Root; }
+  const Node &root() const { return *Root; }
 
 private:
   std::deque Nodes; // Stable-pointer storage.
@@ -114,10 +119,7 @@ private:
   void print(llvm::raw_ostream &OS, const Node &N, int Indent) const;
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const SelectionTree &T) {
-if (auto R = T.root())
-  T.print(OS, *R, 0);
-else
-  OS << "(empty selection)\n";
+T.print(OS, T.root(), 1);
 return OS;
   }
 };

[PATCH] D65101: [clangd] SelectionTree treats TranslationUnitDecl consistently with other containers.

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366893: [clangd] SelectionTree treats TranslationUnitDecl 
(mostly) consistently with… (authored by sammccall, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65101?vs=211459&id=211471#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65101/new/

https://reviews.llvm.org/D65101

Files:
  clang-tools-extra/trunk/clangd/Selection.cpp
  clang-tools-extra/trunk/clangd/Selection.h
  clang-tools-extra/trunk/clangd/refactor/tweaks/DumpAST.cpp
  clang-tools-extra/trunk/clangd/unittests/SelectionTests.cpp
  clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/trunk/clangd/refactor/tweaks/DumpAST.cpp
===
--- clang-tools-extra/trunk/clangd/refactor/tweaks/DumpAST.cpp
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/DumpAST.cpp
@@ -84,9 +84,7 @@
 public:
   const char *id() const override final;
 
-  bool prepare(const Selection &Inputs) override {
-return Inputs.ASTSelection.root() != nullptr;
-  }
+  bool prepare(const Selection &Inputs) override { return true; }
   Expected apply(const Selection &Inputs) override {
 return Effect::showMessage(llvm::to_string(Inputs.ASTSelection));
   }
Index: clang-tools-extra/trunk/clangd/Selection.h
===
--- clang-tools-extra/trunk/clangd/Selection.h
+++ clang-tools-extra/trunk/clangd/Selection.h
@@ -54,6 +54,11 @@
 //  - if you want to traverse the selected nodes, they are all under
 //commonAncestor() in the tree.
 //
+// SelectionTree tries to behave sensibly in the presence of macros, but does
+// not model any preprocessor concepts: the output is a subset of the AST.
+// Currently comments, directives etc are treated as part of the lexically
+// containing AST node, (though we may want to change this in future).
+//
 // The SelectionTree owns the Node structures, but the ASTNode attributes
 // point back into the AST it was constructed with.
 class SelectionTree {
@@ -100,11 +105,11 @@
 std::string kind() const;
   };
   // The most specific common ancestor of all the selected nodes.
-  // If there is no selection, this is nullptr.
+  // Returns nullptr if the common ancestor is the root.
+  // (This is to avoid accidentally traversing the TUDecl and thus preamble).
   const Node *commonAncestor() const;
   // The selection node corresponding to TranslationUnitDecl.
-  // If there is no selection, this is nullptr.
-  const Node *root() const { return Root; }
+  const Node &root() const { return *Root; }
 
 private:
   std::deque Nodes; // Stable-pointer storage.
@@ -114,10 +119,7 @@
   void print(llvm::raw_ostream &OS, const Node &N, int Indent) const;
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const SelectionTree &T) {
-if (auto R = T.root())
-  T.print(OS, *R, 0);
-else
-  OS << "(empty selection)\n";
+T.print(OS, T.root(), 1);
 return OS;
   }
 };
Index: clang-tools-extra/trunk/clangd/Selection.cpp
===
--- clang-tools-extra/trunk/clangd/Selection.cpp
+++ clang-tools-extra/trunk/clangd/Selection.cpp
@@ -103,8 +103,14 @@
 V.TraverseAST(AST);
 assert(V.Stack.size() == 1 && "Unpaired push/pop?");
 assert(V.Stack.top() == &V.Nodes.front());
-if (V.Nodes.size() == 1) // TUDecl, but no nodes under it.
-  V.Nodes.clear();
+// We selected TUDecl if characters were unclaimed (or the file is empty).
+if (V.Nodes.size() == 1 || V.Claimed.add(Begin, End)) {
+  StringRef FileContent = AST.getSourceManager().getBufferData(File);
+  // Don't require the trailing newlines to be selected.
+  bool SelectedAll = Begin == 0 && End >= FileContent.rtrim().size();
+  V.Stack.top()->Selected =
+  SelectedAll ? SelectionTree::Complete : SelectionTree::Partial;
+}
 return std::move(V.Nodes);
   }
 
@@ -424,12 +430,13 @@
 : SelectionTree(AST, Offset, Offset) {}
 
 const Node *SelectionTree::commonAncestor() const {
-  if (!Root)
-return nullptr;
   const Node *Ancestor = Root;
   while (Ancestor->Children.size() == 1 && !Ancestor->Selected)
 Ancestor = Ancestor->Children.front();
-  return Ancestor;
+  // Returning nullptr here is a bit unprincipled, but it makes the API safer:
+  // the TranslationUnitDecl contains all of the preamble, so traversing it is a
+  // performance cliff. Callers can check for null and use root() if they want.
+  return Ancestor != Root ? Ancestor : nullptr;
 }
 
 const DeclContext& SelectionTree::Node::getDeclContext() const {
Index: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
===
--- clang-tools

[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev created this revision.
anton-afanasyev added a reviewer: sammccall.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.

Move `-ftime-trace-granularity` option to frontend options. Without patch
this option is showed up in the help for any tool that links libSupport.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65202

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/check-time-trace.cpp
  clang/tools/driver/cc1_main.cpp
  llvm/include/llvm/Support/TimeProfiler.h
  llvm/lib/Support/TimeProfiler.cpp

Index: llvm/lib/Support/TimeProfiler.cpp
===
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -24,11 +24,8 @@
 
 namespace llvm {
 
-static cl::opt TimeTraceGranularity(
-"time-trace-granularity",
-cl::desc(
-"Minimum time granularity (in microseconds) traced by time profiler"),
-cl::init(500));
+// Minimum time granularity (in microseconds) traced by time profiler
+unsigned TimeTraceGranularity = 500;
 
 TimeTraceProfiler *TimeTraceProfilerInstance = nullptr;
 
@@ -163,10 +160,11 @@
   time_point StartTime;
 };
 
-void timeTraceProfilerInitialize() {
+void timeTraceProfilerInitialize(unsigned TimeTraceGranularity_) {
   assert(TimeTraceProfilerInstance == nullptr &&
  "Profiler should not be initialized");
   TimeTraceProfilerInstance = new TimeTraceProfiler();
+  TimeTraceGranularity = TimeTraceGranularity_;
 }
 
 void timeTraceProfilerCleanup() {
Index: llvm/include/llvm/Support/TimeProfiler.h
===
--- llvm/include/llvm/Support/TimeProfiler.h
+++ llvm/include/llvm/Support/TimeProfiler.h
@@ -19,7 +19,7 @@
 /// Initialize the time trace profiler.
 /// This sets up the global \p TimeTraceProfilerInstance
 /// variable to be the profiler instance.
-void timeTraceProfilerInitialize();
+void timeTraceProfilerInitialize(unsigned TimeTraceGranularity);
 
 /// Cleanup the time trace profiler, if it was initialized.
 void timeTraceProfilerCleanup();
Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -216,9 +216,10 @@
   bool Success = CompilerInvocation::CreateFromArgs(
   Clang->getInvocation(), Argv.begin(), Argv.end(), Diags);
 
-  if (Clang->getFrontendOpts().TimeTrace)
-llvm::timeTraceProfilerInitialize();
-
+  if (Clang->getFrontendOpts().TimeTrace) {
+llvm::timeTraceProfilerInitialize(
+Clang->getFrontendOpts().TimeTraceGranularity);
+  }
   // --print-supported-cpus takes priority over the actual compilation.
   if (Clang->getFrontendOpts().PrintSupportedCPUs)
 return PrintSupportedCPUs(Clang->getTargetOpts().Triple);
Index: clang/test/Driver/check-time-trace.cpp
===
--- clang/test/Driver/check-time-trace.cpp
+++ clang/test/Driver/check-time-trace.cpp
@@ -1,5 +1,5 @@
 // REQUIRES: shell
-// RUN: %clangxx -S -ftime-trace -mllvm --time-trace-granularity=0 -o %T/check-time-trace %s
+// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o %T/check-time-trace %s
 // RUN: cat %T/check-time-trace.json \
 // RUN:   | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1769,6 +1769,8 @@
   Opts.ShowTimers = Args.hasArg(OPT_ftime_report);
   Opts.PrintSupportedCPUs = Args.hasArg(OPT_print_supported_cpus);
   Opts.TimeTrace = Args.hasArg(OPT_ftime_trace);
+  Opts.TimeTraceGranularity =
+  getLastArgIntValue(Args, OPT_ftime_trace_granularity_EQ, 500, Diags);
   Opts.ShowVersion = Args.hasArg(OPT_version);
   Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4575,6 +4575,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
+  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
 
Index: clang/inc

[PATCH] D64678: [Sema] Fix -Wuninitialized for struct assignment from GNU C statement expression

2019-07-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from a comment request.




Comment at: clang/lib/Sema/SemaDecl.cpp:11258
   // are handled by a dataflow analysis.
-  if (!VDecl->hasLocalStorage() || VDecl->getType()->isRecordType() ||
-  VDecl->getType()->isReferenceType()) {
-CheckSelfReference(*this, RealDecl, Init, DirectInit);
+  if (getLangOpts().CPlusPlus) {
+if (!VDecl->hasLocalStorage() || VDecl->getType()->isRecordType() ||

This should probably have a comment explaining why we only do it in C++ mode.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64678/new/

https://reviews.llvm.org/D64678



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


[PATCH] D60663: Time profiler: small fixes and optimizations

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev marked 2 inline comments as done.
anton-afanasyev added inline comments.



Comment at: llvm/trunk/lib/Support/TimeProfiler.cpp:27
 
+static cl::opt TimeTraceGranularity(
+"time-trace-granularity",

sammccall wrote:
> I know this is late, but... this shows up in the help for any tool that links 
> in libSupport, many of which don't support the time profiler. Can you mark 
> this as hidden or (preferably) move this to cc1_main?
@sammccall Yes, thanks! Here is the fix https://reviews.llvm.org/D65202 , 
please, review it.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60663/new/

https://reviews.llvm.org/D60663



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


[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang/docs/ClangCommandLineReference.rst:1943-1947
 .. option:: -ftime-report
 
+.. option:: -ftime-trace
+
+Turn on time profiler

While there add a description to `-ftime-report` and document how they are 
different?



Comment at: clang/include/clang/Driver/Options.td:1759-1761
 def ftime_report : Flag<["-"], "ftime-report">, Group, 
Flags<[CC1Option]>;
-def ftime_trace : Flag<["-"], "ftime-trace">, Group, 
Flags<[CC1Option, CoreOption]>;
+def ftime_trace : Flag<["-"], "ftime-trace">, Group,
+  HelpText<"Turn on time profiler">, Flags<[CC1Option, CoreOption]>;

While there add description to `ftime_report` and document their difference?



Comment at: llvm/lib/Support/TimeProfiler.cpp:27-30
+// Minimum time granularity (in microseconds) traced by time profiler
+unsigned TimeTraceGranularity = 500;
 
 TimeTraceProfiler *TimeTraceProfilerInstance = nullptr;

Can `TimeTraceGranularity` perhaps be stored in `TimeTraceProfilerInstance`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202



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


[PATCH] D65201: [clangd] Provide help text to users who run `clangd` in a terminal.

2019-07-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:430
+  if (llvm::outs().is_displayed() && llvm::errs().is_displayed())
+llvm::errs() << Overview << "\n";
   // Use buffered stream to stderr (we still flush each log message). 
Unbuffered

do we want to exit clangd for this case?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65201/new/

https://reviews.llvm.org/D65201



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


[PATCH] D65200: [clangd] Add categories to help options, and only show clangd options.

2019-07-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:59
+
+opt CompileCommandsDir{
 "compile-commands-dir",

maybe also group these options by the their categories?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65200/new/

https://reviews.llvm.org/D65200



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


[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/docs/ClangCommandLineReference.rst:1951
+
+Minimum time granularity (in microseconds) traced by time profiler
+

is there any possibility of wanting a granularity <1ms in the future? This sets 
up a backward-compatibility trap if so.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1772
   Opts.TimeTrace = Args.hasArg(OPT_ftime_trace);
+  Opts.TimeTraceGranularity =
+  getLastArgIntValue(Args, OPT_ftime_trace_granularity_EQ, 500, Diags);

You've got the default repeated here. Is it possible to set this conditionally 
here, or use the existing value as default like

`Opts.TTG = getLastArgIntValue(Args, OPT_fttg_EQ, Opts.TTG, Diags)`



Comment at: llvm/lib/Support/TimeProfiler.cpp:28
+// Minimum time granularity (in microseconds) traced by time profiler
+unsigned TimeTraceGranularity = 500;
 

why does this have a default value?  It shouldn't be possible to use it without 
overwriting it, IIUC



Comment at: llvm/lib/Support/TimeProfiler.cpp:28
+// Minimum time granularity (in microseconds) traced by time profiler
+unsigned TimeTraceGranularity = 500;
 

sammccall wrote:
> why does this have a default value?  It shouldn't be possible to use it 
> without overwriting it, IIUC
static


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202



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


[PATCH] D64638: [CrossTU] Fix plist macro expansion if macro in other file.

2019-07-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

The Frontend is needed because "ASTUnit.h" is added now into 
PlistDiagnostics.cpp. The `ASTUnit` object is used to pass information out from 
`getImportedFromSourceLocation`. The StaticAnalyzerCore library uses CrossTU 
library, and CrossTU uses Frontend, so I think it may be not a problem if 
StaticAnalyzerCore will use directly Frontend. Otherwise the 
`getImportedFromSourceLocation` can return the `Preprocessor` (and 
`ASTContext`) (in a tuple) instead of an `ASTUnit` and use of `ASTUnit` is not 
needed. (Patch in D65064  contains a test that 
does work only if the TranslationUnitDecl of the imported-from AST is known, to 
get this value an `ASTUnit` or `ASTContext` must be returned from 
`getImportedFromSourceLocation`.)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64638/new/

https://reviews.llvm.org/D64638



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


[PATCH] D65139: [clangd] Support extraction of binary "subexpressions" like a + [[b + c]].

2019-07-24 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:210
+//  - we don't look inside macro expansions in the subexpressions
+//  - we only adjust the extracted range, so references in the unselected parts
+//of the AST expression (e.g. `a`) are still considered referenced for

A related FIXME would be helpful since it's pretty easy to fix(I think?) and 
seems like something important.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:213
+//the purposes of calculating the insertion point.
+namespace {
+

Why do we need an anon namespace inside another anon namespace?



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:217
+// It can represent either an overloaded or built-in operator.
+struct ParsedBinaryOperator {
+  BinaryOperatorKind Kind;

Wouldn't it make more sense this to have this in some other place (maybe 
Selection) because other refactorings might want to make use of this feature?



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:235
+N.ASTNode.get())) {
+  if (Op->isInfixBinaryOp()) {
+Kind = BinaryOperator::getOverloadedOpcode(Op->getOperator());

Can we negate this if to reduce nesting?



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:283
+const SelectionTree::Node *getEndpoint(const SelectionTree::Node &N,
+   BinaryOperatorKind OuterOp, bool 
IsStart,
+   const SourceManager &SM) {

We're considering the case where all the operators are the same. Isn't it true 
that in that case, the End will be the the first 'selected RHS' that we find 
during the traversal? If so, can't we just get rid of the IsStart?



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:393
   std::string VarName = "dummy";
+  SourceRange Range = Target->getExtractionChars();
   // insert new variable declaration

Why not just compute this inside ExtractionContext?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65139/new/

https://reviews.llvm.org/D65139



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


[PATCH] D60663: Time profiler: small fixes and optimizations

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: llvm/trunk/lib/Support/TimeProfiler.cpp:27
 
+static cl::opt TimeTraceGranularity(
+"time-trace-granularity",

anton-afanasyev wrote:
> sammccall wrote:
> > I know this is late, but... this shows up in the help for any tool that 
> > links in libSupport, many of which don't support the time profiler. Can you 
> > mark this as hidden or (preferably) move this to cc1_main?
> @sammccall Yes, thanks! Here is the fix https://reviews.llvm.org/D65202 , 
> please, review it.
Thanks! A few nits but that's a big improvement I think.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60663/new/

https://reviews.llvm.org/D60663



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


[PATCH] D65203: [ASTImporter] Do not import FunctionTemplateDecl in record twice.

2019-07-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.

For functions there is a check to not duplicate the declaration if it is in a
record (class). For function templates there was no similar check, if a
template (in the same class) was imported multiple times the
FunctionTemplateDecl was created multiple times with the same templated
FunctionDecl. This can result in problems with the declaration chain.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65203

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -2389,6 +2389,47 @@
 functionDecl(hasName("f"), hasDescendant(declRefExpr()));
 }
 
+TEST_P(ImportFunctionTemplates, ImportFunctionTemplateInRecordDeclTwice) {
+  auto Code =
+  R"(
+  class X {
+template 
+void f(T t);
+  };
+  )";
+  Decl *FromTU1 = getTuDecl(Code, Lang_CXX, "input1.cc");
+  auto *FromD1 = FirstDeclMatcher().match(
+  FromTU1, functionTemplateDecl(hasName("f")));
+  auto *ToD1 = Import(FromD1, Lang_CXX);
+  Decl *FromTU2 = getTuDecl(Code, Lang_CXX, "input2.cc");
+  auto *FromD2 = FirstDeclMatcher().match(
+  FromTU2, functionTemplateDecl(hasName("f")));
+  auto *ToD2 = Import(FromD2, Lang_CXX);
+  EXPECT_EQ(ToD1, ToD2);
+}
+
+TEST_P(ImportFunctionTemplates,
+   ImportFunctionTemplateWithDefInRecordDeclTwice) {
+  auto Code =
+  R"(
+  class X {
+template 
+void f(T t);
+  };
+  template 
+  void X::f(T t) {};
+  )";
+  Decl *FromTU1 = getTuDecl(Code, Lang_CXX, "input1.cc");
+  auto *FromD1 = FirstDeclMatcher().match(
+  FromTU1, functionTemplateDecl(hasName("f")));
+  auto *ToD1 = Import(FromD1, Lang_CXX);
+  Decl *FromTU2 = getTuDecl(Code, Lang_CXX, "input2.cc");
+  auto *FromD2 = FirstDeclMatcher().match(
+  FromTU2, functionTemplateDecl(hasName("f")));
+  auto *ToD2 = Import(FromD2, Lang_CXX);
+  EXPECT_EQ(ToD1, ToD2);
+}
+
 struct ImportFriendFunctions : ImportFunctions {};
 
 TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainProto) {
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3066,9 +3066,19 @@
   if (FoundByLookup) {
 if (isa(FoundByLookup)) {
   if (D->getLexicalDeclContext() == D->getDeclContext()) {
-if (!D->doesThisDeclarationHaveABody())
+if (!D->doesThisDeclarationHaveABody()) {
+  if (FunctionTemplateDecl *DescribedD =
+  D->getDescribedFunctionTemplate()) {
+// Handle a "templated" function together with its described
+// template. This avoids need for a similar check at import of the
+// described template.
+assert(FoundByLookup->getDescribedFunctionTemplate() &&
+   "Templated function mapped to non-templated?");
+Importer.MapImported(DescribedD,
+ 
FoundByLookup->getDescribedFunctionTemplate());
+  }
   return Importer.MapImported(D, FoundByLookup);
-else {
+} else {
   // Let's continue and build up the redecl chain in this case.
   // FIXME Merge the functions into one decl.
 }
@@ -5550,14 +5560,14 @@
 }
   }
 
-  auto ParamsOrErr = import(D->getTemplateParameters());
-  if (!ParamsOrErr)
-return ParamsOrErr.takeError();
-
   FunctionDecl *TemplatedFD;
   if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
 return std::move(Err);
 
+  auto ParamsOrErr = import(D->getTemplateParameters());
+  if (!ParamsOrErr)
+return ParamsOrErr.takeError();
+
   FunctionTemplateDecl *ToFunc;
   if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, 
Name,
   *ParamsOrErr, TemplatedFD))


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -2389,6 +2389,47 @@
 functionDecl(hasName("f"), hasDescendant(declRefExpr()));
 }
 
+TEST_P(ImportFunctionTemplates, ImportFunctionTemplateInRecordDeclTwice) {
+  auto Code =
+  R"(
+  class X {
+template 
+void f(T t);
+  };
+  )";
+  Decl *FromTU1 = getTuDecl(Code, Lang_CXX, "input1.cc");
+  auto *FromD1 = FirstDeclMatcher().match(
+  FromTU1, functionTemplateDecl(hasName("f")));
+  auto *ToD1 = Import(FromD1, Lang_CXX);
+  Decl *FromTU2 = getTuDecl(Code, Lang_CXX, "input2.cc"

[PATCH] D65200: [clangd] Add categories to help options, and only show clangd options.

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:59
+
+opt CompileCommandsDir{
 "compile-commands-dir",

hokein wrote:
> maybe also group these options by the their categories?
Done, and sorted by name. Bye bye version history, though :-/


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65200/new/

https://reviews.llvm.org/D65200



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


[clang-tools-extra] r366900 - [clangd] Add categories to help options, and only show clangd options.

2019-07-24 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Wed Jul 24 05:41:52 2019
New Revision: 366900

URL: http://llvm.org/viewvc/llvm-project?rev=366900&view=rev
Log:
[clangd] Add categories to help options, and only show clangd options.

Summary:
Restricting the categories prevents extra unwanted options from creeping into
help (D60663), and removes a bunch of noise from --help-hidden.

While here, remove `static` from the opts in favor of an anon namespace, to
reduce the noise level.

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=366900&r1=366899&r2=366900&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Wed Jul 24 05:41:52 2019
@@ -35,6 +35,7 @@
 
 namespace clang {
 namespace clangd {
+namespace {
 
 using llvm::cl::cat;
 using llvm::cl::CommaSeparated;
@@ -43,151 +44,153 @@ using llvm::cl::Hidden;
 using llvm::cl::init;
 using llvm::cl::list;
 using llvm::cl::opt;
+using llvm::cl::OptionCategory;
 using llvm::cl::values;
 
-static opt CompileCommandsDir{
+// All flags must be placed in a category, or they will be shown neither in
+// --help, nor --help-hidden!
+OptionCategory CompileCommands("clangd compilation flags options");
+OptionCategory Features("clangd feature options");
+OptionCategory Misc("clangd miscellaneous options");
+OptionCategory Protocol("clangd protocol and logging options");
+const OptionCategory *ClangdCategories[] = {&Features, &Protocol,
+&CompileCommands, &Misc};
+
+enum CompileArgsFrom { LSPCompileArgs, FilesystemCompileArgs };
+opt CompileArgsFrom{
+"compile_args_from",
+cat(CompileCommands),
+desc("The source of compile commands"),
+values(clEnumValN(LSPCompileArgs, "lsp",
+  "All compile commands come from LSP and "
+  "'compile_commands.json' files are ignored"),
+   clEnumValN(FilesystemCompileArgs, "filesystem",
+  "All compile commands come from the "
+  "'compile_commands.json' files")),
+init(FilesystemCompileArgs),
+Hidden,
+};
+
+opt CompileCommandsDir{
 "compile-commands-dir",
+cat(CompileCommands),
 desc("Specify a path to look for compile_commands.json. If path "
  "is invalid, clangd will look in the current directory and "
  "parent paths of each source file"),
 };
 
-static opt WorkerThreadsCount{
-"j",
-desc("Number of async workers used by clangd"),
-init(getDefaultAsyncThreadsCount()),
+opt ResourceDir{
+"resource-dir",
+cat(CompileCommands),
+desc("Directory for system clang headers"),
+init(""),
+Hidden,
 };
 
-// FIXME: also support "plain" style where signatures are always omitted.
-enum CompletionStyleFlag { Detailed, Bundled };
-static opt CompletionStyle{
-"completion-style",
-desc("Granularity of code completion suggestions"),
-values(clEnumValN(Detailed, "detailed",
-  "One completion item for each semantically distinct "
-  "completion, with full type information"),
-   clEnumValN(Bundled, "bundled",
-  "Similar completion items (e.g. function overloads) are "
-  "combined. Type information shown where possible")),
+list QueryDriverGlobs{
+"query-driver",
+cat(CompileCommands),
+desc(
+"Comma separated list of globs for white-listing gcc-compatible "
+"drivers that are safe to execute. Drivers matching any of these globs 
"
+"will be used to extract system includes. e.g. "
+"/usr/bin/**/clang-*,/path/to/repo/**/g++-*"),
+CommaSeparated,
 };
 
 // FIXME: Flags are the wrong mechanism for user preferences.
 // We should probably read a dotfile or similar.
-static opt IncludeIneligibleResults{
-"include-ineligible-results",
-desc("Include ineligible completion results (e.g. private members)"),
-init(CodeCompleteOptions().IncludeIneligibleResults),
-Hidden,
-};
-
-static opt InputStyle{
-"input-style",
-desc("Input JSON stream encoding"),
-values(
-clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP 
protocol"),
-clEnumValN(JSONStreamStyle::Delimited, "delimited",
-   "messages delimited by --- lines, with # comment support")),
-init(JSONStreamStyle::Standard),
-Hidden,
-};
-
-static opt PrettyPrint{
-"pretty",
-desc("Pretty-print JSON output"),
-init(false),
-};
-
-static opt LogLevel{
-"log",
-desc("Verbosity of log messages wri

[PATCH] D65200: [clangd] Add categories to help options, and only show clangd options.

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366900: [clangd] Add categories to help options, and only 
show clangd options. (authored by sammccall, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65200?vs=211469&id=211477#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65200/new/

https://reviews.llvm.org/D65200

Files:
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -35,6 +35,7 @@
 
 namespace clang {
 namespace clangd {
+namespace {
 
 using llvm::cl::cat;
 using llvm::cl::CommaSeparated;
@@ -43,151 +44,153 @@
 using llvm::cl::init;
 using llvm::cl::list;
 using llvm::cl::opt;
+using llvm::cl::OptionCategory;
 using llvm::cl::values;
 
-static opt CompileCommandsDir{
+// All flags must be placed in a category, or they will be shown neither in
+// --help, nor --help-hidden!
+OptionCategory CompileCommands("clangd compilation flags options");
+OptionCategory Features("clangd feature options");
+OptionCategory Misc("clangd miscellaneous options");
+OptionCategory Protocol("clangd protocol and logging options");
+const OptionCategory *ClangdCategories[] = {&Features, &Protocol,
+&CompileCommands, &Misc};
+
+enum CompileArgsFrom { LSPCompileArgs, FilesystemCompileArgs };
+opt CompileArgsFrom{
+"compile_args_from",
+cat(CompileCommands),
+desc("The source of compile commands"),
+values(clEnumValN(LSPCompileArgs, "lsp",
+  "All compile commands come from LSP and "
+  "'compile_commands.json' files are ignored"),
+   clEnumValN(FilesystemCompileArgs, "filesystem",
+  "All compile commands come from the "
+  "'compile_commands.json' files")),
+init(FilesystemCompileArgs),
+Hidden,
+};
+
+opt CompileCommandsDir{
 "compile-commands-dir",
+cat(CompileCommands),
 desc("Specify a path to look for compile_commands.json. If path "
  "is invalid, clangd will look in the current directory and "
  "parent paths of each source file"),
 };
 
-static opt WorkerThreadsCount{
-"j",
-desc("Number of async workers used by clangd"),
-init(getDefaultAsyncThreadsCount()),
+opt ResourceDir{
+"resource-dir",
+cat(CompileCommands),
+desc("Directory for system clang headers"),
+init(""),
+Hidden,
 };
 
-// FIXME: also support "plain" style where signatures are always omitted.
-enum CompletionStyleFlag { Detailed, Bundled };
-static opt CompletionStyle{
-"completion-style",
-desc("Granularity of code completion suggestions"),
-values(clEnumValN(Detailed, "detailed",
-  "One completion item for each semantically distinct "
-  "completion, with full type information"),
-   clEnumValN(Bundled, "bundled",
-  "Similar completion items (e.g. function overloads) are "
-  "combined. Type information shown where possible")),
+list QueryDriverGlobs{
+"query-driver",
+cat(CompileCommands),
+desc(
+"Comma separated list of globs for white-listing gcc-compatible "
+"drivers that are safe to execute. Drivers matching any of these globs "
+"will be used to extract system includes. e.g. "
+"/usr/bin/**/clang-*,/path/to/repo/**/g++-*"),
+CommaSeparated,
 };
 
 // FIXME: Flags are the wrong mechanism for user preferences.
 // We should probably read a dotfile or similar.
-static opt IncludeIneligibleResults{
-"include-ineligible-results",
-desc("Include ineligible completion results (e.g. private members)"),
-init(CodeCompleteOptions().IncludeIneligibleResults),
-Hidden,
-};
-
-static opt InputStyle{
-"input-style",
-desc("Input JSON stream encoding"),
-values(
-clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"),
-clEnumValN(JSONStreamStyle::Delimited, "delimited",
-   "messages delimited by --- lines, with # comment support")),
-init(JSONStreamStyle::Standard),
-Hidden,
-};
-
-static opt PrettyPrint{
-"pretty",
-desc("Pretty-print JSON output"),
-init(false),
-};
-
-static opt LogLevel{
-"log",
-desc("Verbosity of log messages written to stderr"),
-values(clEnumValN(Logger::Error, "error", "Error messages only"),
-   clEnumValN(Logger::Info, "info", "High level execution tracing"),
-   clEnumValN(Logger::Debug, "verbose", "Low level details")),
-init(Logger::Info),
-};
-
-static opt Test{
-"lit-test",
-desc("Abbreviation for -input-style=delimite

[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev added inline comments.



Comment at: clang/docs/ClangCommandLineReference.rst:1951
+
+Minimum time granularity (in microseconds) traced by time profiler
+

sammccall wrote:
> is there any possibility of wanting a granularity <1ms in the future? This 
> sets up a backward-compatibility trap if so.
Does it really make sense? One can use `-ftime-trace-granularity=0`, which can 
show all events.



Comment at: llvm/lib/Support/TimeProfiler.cpp:27-30
+// Minimum time granularity (in microseconds) traced by time profiler
+unsigned TimeTraceGranularity = 500;
 
 TimeTraceProfiler *TimeTraceProfilerInstance = nullptr;

lebedev.ri wrote:
> Can `TimeTraceGranularity` perhaps be stored in `TimeTraceProfilerInstance`?
Sure, thanks.



Comment at: llvm/lib/Support/TimeProfiler.cpp:28
+// Minimum time granularity (in microseconds) traced by time profiler
+unsigned TimeTraceGranularity = 500;
 

sammccall wrote:
> sammccall wrote:
> > why does this have a default value?  It shouldn't be possible to use it 
> > without overwriting it, IIUC
> static
Moved to `struct TimeProfiler` member.



Comment at: llvm/lib/Support/TimeProfiler.cpp:28
+// Minimum time granularity (in microseconds) traced by time profiler
+unsigned TimeTraceGranularity = 500;
 

anton-afanasyev wrote:
> sammccall wrote:
> > sammccall wrote:
> > > why does this have a default value?  It shouldn't be possible to use it 
> > > without overwriting it, IIUC
> > static
> Moved to `struct TimeProfiler` member.
Hmm, ok, removing default value.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202



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


[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev updated this revision to Diff 211481.
anton-afanasyev marked 8 inline comments as done.
anton-afanasyev added a comment.

Update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/check-time-trace.cpp
  clang/tools/driver/cc1_main.cpp
  llvm/include/llvm/Support/TimeProfiler.h
  llvm/lib/Support/TimeProfiler.cpp

Index: llvm/lib/Support/TimeProfiler.cpp
===
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -24,12 +24,6 @@
 
 namespace llvm {
 
-static cl::opt TimeTraceGranularity(
-"time-trace-granularity",
-cl::desc(
-"Minimum time granularity (in microseconds) traced by time profiler"),
-cl::init(500));
-
 TimeTraceProfiler *TimeTraceProfilerInstance = nullptr;
 
 typedef duration DurationType;
@@ -161,12 +155,16 @@
   SmallVector Entries;
   StringMap CountAndTotalPerName;
   time_point StartTime;
+
+  // Minimum time granularity (in microseconds)
+  unsigned TimeTraceGranularity;
 };
 
-void timeTraceProfilerInitialize() {
+void timeTraceProfilerInitialize(unsigned TimeTraceGranularity) {
   assert(TimeTraceProfilerInstance == nullptr &&
  "Profiler should not be initialized");
   TimeTraceProfilerInstance = new TimeTraceProfiler();
+  TimeTraceProfilerInstance->TimeTraceGranularity = TimeTraceGranularity;
 }
 
 void timeTraceProfilerCleanup() {
Index: llvm/include/llvm/Support/TimeProfiler.h
===
--- llvm/include/llvm/Support/TimeProfiler.h
+++ llvm/include/llvm/Support/TimeProfiler.h
@@ -19,7 +19,7 @@
 /// Initialize the time trace profiler.
 /// This sets up the global \p TimeTraceProfilerInstance
 /// variable to be the profiler instance.
-void timeTraceProfilerInitialize();
+void timeTraceProfilerInitialize(unsigned TimeTraceGranularity);
 
 /// Cleanup the time trace profiler, if it was initialized.
 void timeTraceProfilerCleanup();
Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -216,9 +216,10 @@
   bool Success = CompilerInvocation::CreateFromArgs(
   Clang->getInvocation(), Argv.begin(), Argv.end(), Diags);
 
-  if (Clang->getFrontendOpts().TimeTrace)
-llvm::timeTraceProfilerInitialize();
-
+  if (Clang->getFrontendOpts().TimeTrace) {
+llvm::timeTraceProfilerInitialize(
+Clang->getFrontendOpts().TimeTraceGranularity);
+  }
   // --print-supported-cpus takes priority over the actual compilation.
   if (Clang->getFrontendOpts().PrintSupportedCPUs)
 return PrintSupportedCPUs(Clang->getTargetOpts().Triple);
Index: clang/test/Driver/check-time-trace.cpp
===
--- clang/test/Driver/check-time-trace.cpp
+++ clang/test/Driver/check-time-trace.cpp
@@ -1,5 +1,5 @@
 // REQUIRES: shell
-// RUN: %clangxx -S -ftime-trace -mllvm --time-trace-granularity=0 -o %T/check-time-trace %s
+// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o %T/check-time-trace %s
 // RUN: cat %T/check-time-trace.json \
 // RUN:   | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1769,6 +1769,8 @@
   Opts.ShowTimers = Args.hasArg(OPT_ftime_report);
   Opts.PrintSupportedCPUs = Args.hasArg(OPT_print_supported_cpus);
   Opts.TimeTrace = Args.hasArg(OPT_ftime_trace);
+  Opts.TimeTraceGranularity =
+  getLastArgIntValue(Args, OPT_ftime_trace_granularity_EQ, 500, Diags);
   Opts.ShowVersion = Args.hasArg(OPT_version);
   Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4575,6 +4575,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
+  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
 
Index: clang/include/clang/Frontend/FrontendO

[PATCH] D64914: Implement P1771

2019-07-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 211482.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64914/new/

https://reviews.llvm.org/D64914

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
  clang/test/Preprocessor/has_attribute.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -664,7 +664,7 @@
 

 http://wg21.link/p1771r1";>P1771R1 (DR)
-No
+SVN
   
 
   [[maybe_unused]] attribute
Index: clang/test/Preprocessor/has_attribute.cpp
===
--- clang/test/Preprocessor/has_attribute.cpp
+++ clang/test/Preprocessor/has_attribute.cpp
@@ -63,7 +63,7 @@
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
 // WINDOWS: no_unique_address: 0
-// CHECK: nodiscard: 201603L
+// CHECK: nodiscard: 201907L
 // CHECK: noreturn: 200809L
 // FIXME(201803L) CHECK: unlikely: 0
 
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
@@ -80,6 +80,48 @@
   conflicting_reason(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: special reason}}
 }
 
+namespace p1771 {
+struct[[nodiscard("Don't throw me away!")]] ConvertTo{};
+struct S {
+  [[nodiscard]] S();
+  [[nodiscard("Don't let that S-Char go!")]] S(char);
+  S(int);
+  [[gnu::warn_unused_result]] S(double);
+  operator ConvertTo();
+  [[nodiscard]] operator int();
+};
+
+struct[[nodiscard("Don't throw me away either!")]] Y{};
+
+void usage() {
+  S();// expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+  S('A'); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't let that S-Char go!}}
+  S(1);
+  S(2.2);
+  Y(); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away either!}}
+  S s;
+  ConvertTo{}; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
+
+// AST is different in C++20 mode, pre-2017 a move ctor for ConvertTo is there
+// as well, hense the constructor warning.
+#if __cplusplus >= 201703L
+// expected-warning@+4 {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
+#else
+// expected-warning@+2 {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away!}}
+#endif
+  (ConvertTo) s;
+  (int)s; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  (S)'c'; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't let that S-Char go!}}
+#if __cplusplus >= 201703L
+// expected-warning@+4 {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
+#else
+// expected-warning@+2 {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away!}}
+#endif
+  static_cast(s);
+  static_cast(s); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+}
+}; // namespace p1771
+
 #ifdef EXT
 // expected-warning@5 {{use of the 'nodiscard' attribute is a C++17 extension}}
 // expected-warning@9 {{use of the 'nodiscard' attribute is a C++17 extension}}
@@ -91,4 +133,9 @@
 // expected-warning@71 {{use of the 'nodiscard' attribute is a C++2a extension}}
 // expected-warning@73 {{use of the 'nodiscard' attribute is a C++2a extension}}
 // expected-warning@74 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@84 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@86 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@87 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@91 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@94 {{use of the 'nodiscard' attribute is a C++2a extension}}
 #endif
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -284,6 +284,30 @@
 return;
   }
 }
+  } else if (const auto *CE = dyn_cast(E)) {
+if (const CXXConstructorDecl *Ctor = CE->getConstructor()) {
+  const auto *A = Ctor->getAttr();
+  A = A ?

[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Looks ok




Comment at: clang/docs/ClangCommandLineReference.rst:1943-1947
 .. option:: -ftime-report
 
+.. option:: -ftime-trace
+
+Turn on time profiler

lebedev.ri wrote:
> While there add a description to `-ftime-report` and document how they are 
> different?
I mean, state that one is chrome json trace and another is console table output


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202



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


[PATCH] D64914: Implement P1771

2019-07-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Disregard that last commit... i ended up breaking stuff apparently.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64914/new/

https://reviews.llvm.org/D64914



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


[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev added a comment.

Hi all! Could it be accepted or reviewed more?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63325/new/

https://reviews.llvm.org/D63325



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


[PATCH] D65206: [analyzer] Fix text range end columns in SARIF to be exclusive

2019-07-24 Thread Joe Ranieri via Phabricator via cfe-commits
jranieri-grammatech created this revision.
jranieri-grammatech added reviewers: george.karpenkov, NoQ, aaron.ballman.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

According to the SARIF specification, "a text region does not include the 
character specified by endColumn".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65206

Files:
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  
clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
  
clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif

Index: clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
===
--- clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
+++ clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
@@ -64,7 +64,7 @@
 "fileIndex": 0,
   },
   "region": {
-"endColumn": 5,
+"endColumn": 6,
 "endLine": 24,
 "startColumn": 3,
 "startLine": 24
@@ -83,7 +83,7 @@
 "fileIndex": 0,
   },
   "region": {
-"endColumn": 17,
+"endColumn": 18,
 "endLine": 9,
 "startColumn": 11,
 "startLine": 9
@@ -103,7 +103,7 @@
   "fileIndex": 0,
 },
 "region": {
-  "endColumn": 17,
+  "endColumn": 18,
   "endLine": 9,
   "startColumn": 11,
   "startLine": 9
@@ -134,7 +134,7 @@
 "fileIndex": 0,
   },
   "region": {
-"endColumn": 5,
+"endColumn": 6,
 "endLine": 25,
 "startColumn": 3,
 "startLine": 25
@@ -153,7 +153,7 @@
 "fileIndex": 0,
   },
   "region": {
-"endColumn": 10,
+"endColumn": 11,
 "endLine": 13,
 "startColumn": 3,
 "startLine": 13
@@ -172,7 +172,7 @@
 "fileIndex": 0,
   },
   "region": {
-"endColumn": 8,
+"endColumn": 9,
 "endLine": 14,
 "startColumn": 3,
 "startLine": 14
@@ -192,7 +192,7 @@
   "fileIndex": 0,
 },
 "region": {
-  "endColumn": 8,
+  "endColumn": 9,
   "endLine": 14,
   "startColumn": 3,
   "startLine": 14
@@ -223,7 +223,7 @@
 "fileIndex": 0,
   },
   "region": {
-"endColumn": 12,
+"endColumn": 13,
 "endLine": 18,
 "startColumn": 7,
 "startLine": 18
@@ -243,7 +243,6 @@
   },
   "region": {
 "endColumn": 3,
-"endLine": 18,
 "startColumn": 3,
 "startLine": 18
   }
@@ -262,7 +261,6 @@
   },
   "region": {
 "endColumn": 14,
-"endLine": 19,
 "startColumn": 14,
 "startLine": 19
   }
@@ -282,7 +280,6 @@
 },
 "region": {
   "endColumn": 14,
-  "endLine": 19,
   "startColumn": 14,
   "startLine": 19
 }
Index: clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
===
--- clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
+++ clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
@@ -44,

[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev marked an inline comment as done.
anton-afanasyev added a subscriber: aras-p.
anton-afanasyev added inline comments.



Comment at: clang/docs/ClangCommandLineReference.rst:1943-1947
 .. option:: -ftime-report
 
+.. option:: -ftime-trace
+
+Turn on time profiler

lebedev.ri wrote:
> lebedev.ri wrote:
> > While there add a description to `-ftime-report` and document how they are 
> > different?
> I mean, state that one is chrome json trace and another is console table 
> output
The difference is actually deeper at the moment. `-ftime-report` output is 
buggy, short and uninformative (as noted by @aras-p in his blog post 
http://aras-p.info/blog/2019/01/12/Investigating-compile-times-and-Clang-ftime-report/).
 I would like just to remove `-ftime-report` option as obsolete and unsupported.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202



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


r366904 - Test commit. NFC.

2019-07-24 Thread Sjoerd Meijer via cfe-commits
Author: sjoerdmeijer
Date: Wed Jul 24 06:30:36 2019
New Revision: 366904

URL: http://llvm.org/viewvc/llvm-project?rev=366904&view=rev
Log:
Test commit. NFC.

Removed 2 trailing whitespaces in 2 files that used to be in different
repos to test my new github monorepo workflow.

Modified:
cfe/trunk/lib/Basic/Targets/X86.cpp

Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=366904&r1=366903&r2=366904&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/X86.cpp Wed Jul 24 06:30:36 2019
@@ -895,7 +895,7 @@ bool X86TargetInfo::handleTargetFeatures
 /// definitions for this particular subtarget.
 void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
-  // Inline assembly supports X86 flag outputs. 
+  // Inline assembly supports X86 flag outputs.
   Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
 
   std::string CodeModel = getTargetOpts().CodeModel;


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


[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev marked 2 inline comments as done.
anton-afanasyev added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1772
   Opts.TimeTrace = Args.hasArg(OPT_ftime_trace);
+  Opts.TimeTraceGranularity =
+  getLastArgIntValue(Args, OPT_ftime_trace_granularity_EQ, 500, Diags);

sammccall wrote:
> You've got the default repeated here. Is it possible to set this 
> conditionally here, or use the existing value as default like
> 
> `Opts.TTG = getLastArgIntValue(Args, OPT_fttg_EQ, Opts.TTG, Diags)`
Ok, done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202



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


[PATCH] D65092: [clang] Add isDirectlyDerivedFrom AST Matcher.

2019-07-24 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

So, I did like the more exhaustive doc, I thought you'd move it to the code so 
it also shows up in the generated doc page :) (sorry for not being clearer here)




Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2637
   internal::Matcher, Base) {
-  return Finder->classIsDerivedFrom(&Node, Base, Builder);
+  return Finder->classIsDerivedFrom(&Node, Base, Builder, /*Directly*/ false);
 }

If you say /*Directly=*/false, you should
a) not get a space from clang-format
b) clang-tidy can check it's the right parameter name :)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65092/new/

https://reviews.llvm.org/D65092



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


[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev updated this revision to Diff 211489.
anton-afanasyev marked an inline comment as done.
anton-afanasyev added a comment.

Remove default repeat


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/check-time-trace.cpp
  clang/tools/driver/cc1_main.cpp
  llvm/include/llvm/Support/TimeProfiler.h
  llvm/lib/Support/TimeProfiler.cpp

Index: llvm/lib/Support/TimeProfiler.cpp
===
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -24,12 +24,6 @@
 
 namespace llvm {
 
-static cl::opt TimeTraceGranularity(
-"time-trace-granularity",
-cl::desc(
-"Minimum time granularity (in microseconds) traced by time profiler"),
-cl::init(500));
-
 TimeTraceProfiler *TimeTraceProfilerInstance = nullptr;
 
 typedef duration DurationType;
@@ -161,12 +155,16 @@
   SmallVector Entries;
   StringMap CountAndTotalPerName;
   time_point StartTime;
+
+  // Minimum time granularity (in microseconds)
+  unsigned TimeTraceGranularity;
 };
 
-void timeTraceProfilerInitialize() {
+void timeTraceProfilerInitialize(unsigned TimeTraceGranularity) {
   assert(TimeTraceProfilerInstance == nullptr &&
  "Profiler should not be initialized");
   TimeTraceProfilerInstance = new TimeTraceProfiler();
+  TimeTraceProfilerInstance->TimeTraceGranularity = TimeTraceGranularity;
 }
 
 void timeTraceProfilerCleanup() {
Index: llvm/include/llvm/Support/TimeProfiler.h
===
--- llvm/include/llvm/Support/TimeProfiler.h
+++ llvm/include/llvm/Support/TimeProfiler.h
@@ -19,7 +19,7 @@
 /// Initialize the time trace profiler.
 /// This sets up the global \p TimeTraceProfilerInstance
 /// variable to be the profiler instance.
-void timeTraceProfilerInitialize();
+void timeTraceProfilerInitialize(unsigned TimeTraceGranularity);
 
 /// Cleanup the time trace profiler, if it was initialized.
 void timeTraceProfilerCleanup();
Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -216,9 +216,10 @@
   bool Success = CompilerInvocation::CreateFromArgs(
   Clang->getInvocation(), Argv.begin(), Argv.end(), Diags);
 
-  if (Clang->getFrontendOpts().TimeTrace)
-llvm::timeTraceProfilerInitialize();
-
+  if (Clang->getFrontendOpts().TimeTrace) {
+llvm::timeTraceProfilerInitialize(
+Clang->getFrontendOpts().TimeTraceGranularity);
+  }
   // --print-supported-cpus takes priority over the actual compilation.
   if (Clang->getFrontendOpts().PrintSupportedCPUs)
 return PrintSupportedCPUs(Clang->getTargetOpts().Triple);
Index: clang/test/Driver/check-time-trace.cpp
===
--- clang/test/Driver/check-time-trace.cpp
+++ clang/test/Driver/check-time-trace.cpp
@@ -1,5 +1,5 @@
 // REQUIRES: shell
-// RUN: %clangxx -S -ftime-trace -mllvm --time-trace-granularity=0 -o %T/check-time-trace %s
+// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o %T/check-time-trace %s
 // RUN: cat %T/check-time-trace.json \
 // RUN:   | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN:   | FileCheck %s
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1769,6 +1769,8 @@
   Opts.ShowTimers = Args.hasArg(OPT_ftime_report);
   Opts.PrintSupportedCPUs = Args.hasArg(OPT_print_supported_cpus);
   Opts.TimeTrace = Args.hasArg(OPT_ftime_trace);
+  Opts.TimeTraceGranularity = getLastArgIntValue(
+  Args, OPT_ftime_trace_granularity_EQ, Opts.TimeTraceGranularity, Diags);
   Opts.ShowVersion = Args.hasArg(OPT_version);
   Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4575,6 +4575,7 @@
   Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
+  Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
 
Index: 

[PATCH] D65092: [clang] Add isDirectlyDerivedFrom AST Matcher.

2019-07-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2672
+   BaseName, 1) {
+  assert(!BaseName.empty());
+  return isDirectlyDerivedFrom(hasName(BaseName))

I don't think this assertion is reasonable -- we should instead test this as a 
predicate and return false if the base name is empty.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65092/new/

https://reviews.llvm.org/D65092



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


[PATCH] D65209: [analyzer] Fix a SARIF exporter crash with macro expansions

2019-07-24 Thread Joe Ranieri via Phabricator via cfe-commits
jranieri-grammatech created this revision.
jranieri-grammatech added reviewers: NoQ, george.karpenkov, aaron.ballman.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.
jranieri-grammatech added a parent revision: D65206: [analyzer] Fix text range 
end columns in SARIF to be exclusive.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65209

Files:
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  
clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
  clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c

Index: clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
===
--- clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
+++ clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
@@ -1,5 +1,7 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest,unix.Malloc %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
 #include "../Inputs/system-header-simulator.h"
+#include "../Inputs/system-header-simulator-for-malloc.h"
+#define ERR -1
 
 int atoi(const char *nptr);
 
@@ -20,10 +22,19 @@
   return 0;
 }
 
+int leak(int i) {
+  void *mem = malloc(8);
+  if (i < 4)
+return ERR; // expected-warning {{Potential leak of memory pointed to by 'mem'}}
+  free(mem);
+  return 0;
+}
+
 int main(void) {
   f();
   g();
   h(0);
+  leak(0);
   return 0;
 }
 
Index: clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
===
--- clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
+++ clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
@@ -6,7 +6,7 @@
 {
   "fileLocation": {
   },
-  "length": 686,
+  "length": 951,
   "mimeType": "text/plain",
   "roles": [
 "resultFile"
@@ -43,6 +43,16 @@
 "name": {
   "text": "core.DivideZero"
 }
+  },
+  {
+"fullDescription": {
+  "text": "Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free()."
+},
+"helpUri": "https://clang-analyzer.llvm.org/available_checks.html#unix.Malloc";,
+"id": "unix.Malloc",
+"name": {
+  "text": "unix.Malloc"
+}
   }
 ]
   },
@@ -65,9 +75,9 @@
   },
   "region": {
 "endColumn": 6,
-"endLine": 24,
+"endLine": 34,
 "startColumn": 3,
-"startLine": 24
+"startLine": 34
   }
 }
   }
@@ -84,9 +94,9 @@
   },
   "region": {
 "endColumn": 18,
-"endLine": 9,
+"endLine": 11,
 "startColumn": 11,
-"startLine": 9
+"startLine": 11
   }
 }
   }
@@ -104,9 +114,9 @@
 },
 "region": {
   "endColumn": 18,
-  "endLine": 9,
+  "endLine": 11,
   "startColumn": 11,
-  "startLine": 9
+  "startLine": 11
 }
   }
 }
@@ -135,9 +145,9 @@
   },
   "region": {
 "endColumn": 6,
-"endLine": 25,
+"endLine": 35,
 "startColumn": 3,
-"startLine": 25
+"startLine": 35
   }
 }
   }
@@ -154,9 +164,9 @@
   },
   "region": {
 "endColumn": 11,
-"endLine": 13,
+"endLine": 15,
 "startColumn": 3,
-"startLine": 13
+"startLine"

[PATCH] D65043: [Format] Add C++20 standard to style options

2019-07-24 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

Peanut gallery says: A priori, I don't see any reason for clang-format's 
`LanguageStandard` options to diverge from Clang's own `-std=` options. It 
sounds like currently they're very different, and you're proposing to make them 
basically the same. I think that's a good thing.

GCC and Clang still treat "lack of any `-std=` option" as a synonym for 
"`-std=c++03`". A priori this is an absolutely terrible default, but there 
would be some logic in making clang-format follow their lead. The only sensible 
alternative, IMHO, would be for you to treat "lack of any `-std=` option" as a 
synonym for MSVC's `-std:c++latest`, which means "`-std=c++2a` today and 
`-std=c++2b` tomorrow."




Comment at: clang/docs/ClangFormatStyleOptions.rst:2227
+  * ``LS_Cpp20`` (in configuration: ``Cpp20``)
+Use features of C++20 and C++2a (e.g.: treating ``co_yield`` as a keyword,
+not an identifier, so ``co_yield++ i`` is formatted as ``co_yield ++i``).

C++2a //will// be C++20, barring any radically unforeseen events. So saying 
"C++20 and C++2a" is redundant. Personally I would follow GCC/Clang's lead and 
say "C++2a" until the standard is actually out.



Comment at: clang/include/clang/Format/Format.h:1878
 LS_Cpp11,
+/// Use features of C++20 and C++2a (e.g.: treating ``co_yield`` as a
+/// keyword, not an identifier, so ``co_yield++ i`` is formatted as

Again, C++2a is likely a synonym for C++20.
Three lines earlier, you might want to change "C++1z" to "C++17" (and grep the 
codebase for other instances of "1z").



Comment at: clang/unittests/Format/FormatTest.cpp:3721
+  "aa) <= >\n"
+  "5) {\n"
   "}");

This doesn't seem to test what you set out to test, does it? `(x) <= > 5` isn't 
a valid C++ expression anyway. Maybe what you want to test here is that 
clang-format is willing to reformat pre-C++2a code

LongName<&LongerName::operator<=> x;

into

LongName<
&LongerName::operator<=
> x;

(that is, that it's willing to insert a line break between `<=` and `>`). 
However, if clang-format //refused// to insert a line break in that one 
position even in C++11 mode, would anything of value really be lost?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65043/new/

https://reviews.llvm.org/D65043



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


[PATCH] D65211: [analyzer] Update the SARIF exporter to SARIF 2.1

2019-07-24 Thread Joe Ranieri via Phabricator via cfe-commits
jranieri-grammatech created this revision.
jranieri-grammatech added reviewers: NoQ, george.karpenkov, aaron.ballman.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.
jranieri-grammatech added a parent revision: D65209: [analyzer] Fix a SARIF 
exporter crash with macro expansions.

This updates the SARIF exporter to produce SARIF 2.1 output. The bulk of the 
diffs come from two changes to SARIF:

- Rename run.files to run.artifacts, fileLocation to artifactLocation 

- Define tool component object to represent tool driver and its 
extensions/plugins 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65211

Files:
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
  
clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif
  
clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
  clang/test/Analysis/lit.local.cfg

Index: clang/test/Analysis/lit.local.cfg
===
--- clang/test/Analysis/lit.local.cfg
+++ clang/test/Analysis/lit.local.cfg
@@ -22,7 +22,7 @@
 "grep -Ev '^[[:space:]]*(%s|%s|%s)[[:space:]]*$'" %
 ('"uri": "file:.*%basename_t"',
  '"version": ".* version .*"',
- '"version": "2\.0\.0-csd\.[0-9]*\.beta\.[0-9-]{10}"')))
+ '"version": "2.1.0"')))
 
 if not config.root.clang_staticanalyzer:
 config.unsupported = True
Index: clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
===
--- clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
+++ clang/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif
@@ -1,61 +1,18 @@
 {
-  "$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2018-11-28";,
+  "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json";,
   "runs": [
 {
-  "files": [  
+  "artifacts": [
 {
-  "fileLocation": {
-  },
   "length": 951,
+  "location": {
+  },
   "mimeType": "text/plain",
   "roles": [
 "resultFile"
   ]
 }
   ],
-  "resources": {
-"rules": [
-  {
-"fullDescription": {
-  "text": "Mark tainted symbols as such."
-},
-"id": "debug.TaintTest",
-"name": {
-  "text": "debug.TaintTest"
-}
-  },
-  {
-"fullDescription": {
-  "text": "Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers)"
-},
-"helpUri": "https://clang-analyzer.llvm.org/available_checks.html#core.CallAndMessage";,
-"id": "core.CallAndMessage",
-"name": {
-  "text": "core.CallAndMessage"
-}
-  },
-  {
-"fullDescription": {
-  "text": "Check for division by zero"
-},
-"helpUri": "https://clang-analyzer.llvm.org/available_checks.html#core.DivideZero";,
-"id": "core.DivideZero",
-"name": {
-  "text": "core.DivideZero"
-}
-  },
-  {
-"fullDescription": {
-  "text": "Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free()."
-},
-"helpUri": "https://clang-analyzer.llvm.org/available_checks.html#unix.Malloc";,
-"id": "unix.Malloc",
-"name": {
-  "text": "unix.Malloc"
-}
-  }
-]
-  },
   "results": [
 {
   "codeFlows": [
@@ -70,8 +27,8 @@
   "text": "Calling 'f'"
 },
 "physicalLocation": {
-  "fileLocation": {
-"fileIndex": 0,
+  "artifactLocation": {
+"index": 0,
   },
   "region": {
 "endColumn": 6,
@@ -89,8 +46,8 @@
   "text": "tainted"
 },
 "physicalLocation": {
-  "fileLocation": {
-"fileIndex": 0,
+  "artifactLocation": {
+"index": 0,
   },
   "region": {
 "endColumn": 

[PATCH] D65210: [clangd] Fix the annotate tweak after rL366893

2019-07-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

After rL366893 , the annoate tweak is not 
activated when we select the
whole file (the commonAncestor is TUDecl but we intend to return null).

This patch fixes this, and also avoid traversing the TUDecl.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65210

Files:
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -487,6 +487,7 @@
 TEST(TweakTest, AnnotateHighlightings) {
   llvm::StringLiteral ID = "AnnotateHighlightings";
   checkAvailable(ID, "^vo^id^ ^f(^) {^}^"); // available everywhere.
+  checkAvailable(ID, "[[int a; int b;]]");
   const char *Input = "void ^f() {}";
   const char *Output = "void /* entity.name.function.cpp */f() {}";
   checkTransform(ID, Input, Output);
Index: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -24,6 +24,7 @@
   const char *id() const override final;
 
   bool prepare(const Selection &Inputs) override {
+InterestedDecl = Inputs.ASTSelection.root().ASTNode.get();
 for (auto N = Inputs.ASTSelection.commonAncestor(); N && !InterestedDecl;
  N = N->Parent)
   InterestedDecl = N->ASTNode.get();
@@ -41,15 +42,22 @@
 REGISTER_TWEAK(AnnotateHighlightings)
 
 Expected AnnotateHighlightings::apply(const Selection &Inputs) {
-  // Store the existing scopes.
-  const auto &BackupScopes = Inputs.AST.getASTContext().getTraversalScope();
-  // Narrow the traversal scope to the selected node.
-  Inputs.AST.getASTContext().setTraversalScope(
-  {const_cast(InterestedDecl)});
-  auto HighlightingTokens = getSemanticHighlightings(Inputs.AST);
-  // Restore the traversal scope.
-  Inputs.AST.getASTContext().setTraversalScope(BackupScopes);
-
+  std::vector HighlightingTokens;
+  if (llvm::isa(InterestedDecl)) {
+// We only annotate tokens in the main file, if InterestedDecl is a TUDecl,
+// we use the default traversal scope (which is the top level decls of the
+// main file).
+HighlightingTokens = getSemanticHighlightings(Inputs.AST);
+  } else {
+// Store the existing scopes.
+const auto &BackupScopes = Inputs.AST.getASTContext().getTraversalScope();
+// Narrow the traversal scope to the selected node.
+Inputs.AST.getASTContext().setTraversalScope(
+{const_cast(InterestedDecl)});
+HighlightingTokens = getSemanticHighlightings(Inputs.AST);
+// Restore the traversal scope.
+Inputs.AST.getASTContext().setTraversalScope(BackupScopes);
+  }
   auto &SM = Inputs.AST.getSourceManager();
   tooling::Replacements Result;
   for (const auto &Token : HighlightingTokens) {


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -487,6 +487,7 @@
 TEST(TweakTest, AnnotateHighlightings) {
   llvm::StringLiteral ID = "AnnotateHighlightings";
   checkAvailable(ID, "^vo^id^ ^f(^) {^}^"); // available everywhere.
+  checkAvailable(ID, "[[int a; int b;]]");
   const char *Input = "void ^f() {}";
   const char *Output = "void /* entity.name.function.cpp */f() {}";
   checkTransform(ID, Input, Output);
Index: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -24,6 +24,7 @@
   const char *id() const override final;
 
   bool prepare(const Selection &Inputs) override {
+InterestedDecl = Inputs.ASTSelection.root().ASTNode.get();
 for (auto N = Inputs.ASTSelection.commonAncestor(); N && !InterestedDecl;
  N = N->Parent)
   InterestedDecl = N->ASTNode.get();
@@ -41,15 +42,22 @@
 REGISTER_TWEAK(AnnotateHighlightings)
 
 Expected AnnotateHighlightings::apply(const Selection &Inputs) {
-  // Store the existing scopes.
-  const auto &BackupScopes = Inputs.AST.getASTContext().getTraversalScope();
-  // Narrow the traversal scope to the selected node.
-  Inputs.AST.getASTContext().setTraversalScope(
-  {const_cast(InterestedDecl)});
-  auto HighlightingTokens = getSemanticHighlightings(Inputs.AST);
-  // Restore the traversal scope.
-  Inputs.AST.getASTCont

[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev marked an inline comment as done.
anton-afanasyev added inline comments.



Comment at: clang/docs/ClangCommandLineReference.rst:1951
+
+Minimum time granularity (in microseconds) traced by time profiler
+

anton-afanasyev wrote:
> sammccall wrote:
> > is there any possibility of wanting a granularity <1ms in the future? This 
> > sets up a backward-compatibility trap if so.
> Does it really make sense? One can use `-ftime-trace-granularity=0`, which 
> can show all events.
To be more correct, this granularity value (`-ftime-trace-granularity=0`) will 
work after this old patch https://reviews.llvm.org/D63325 is commited.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202



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


[PATCH] D65212: [analyzer] Fix exporting SARIF files from scan-build on Windows

2019-07-24 Thread Joe Ranieri via Phabricator via cfe-commits
jranieri-grammatech created this revision.
jranieri-grammatech added reviewers: NoQ, jordan_rose, dcoughlin, 
george.karpenkov, aaron.ballman.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

In Perl, -z is defined as checking if a "file has zero size" and makes no 
mention what it does when given a directory. It looks like the behavior differs 
across platforms, which is why on Windows the SARIF file was always being 
deleted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65212

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


Index: clang/tools/scan-build/libexec/ccc-analyzer
===
--- clang/tools/scan-build/libexec/ccc-analyzer
+++ clang/tools/scan-build/libexec/ccc-analyzer
@@ -752,7 +752,7 @@
DIR => $HtmlDir);
 $ResultFile = $f;
 # If the HtmlDir is not set, we should clean up the plist files.
-if (!defined $HtmlDir || -z $HtmlDir) {
+if (!defined $HtmlDir || $HtmlDir eq "") {
   $CleanupFile = $f;
 }
   }


Index: clang/tools/scan-build/libexec/ccc-analyzer
===
--- clang/tools/scan-build/libexec/ccc-analyzer
+++ clang/tools/scan-build/libexec/ccc-analyzer
@@ -752,7 +752,7 @@
DIR => $HtmlDir);
 $ResultFile = $f;
 # If the HtmlDir is not set, we should clean up the plist files.
-if (!defined $HtmlDir || -z $HtmlDir) {
+if (!defined $HtmlDir || $HtmlDir eq "") {
   $CleanupFile = $f;
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65210: [clangd] Fix the annotate tweak after rL366893

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp:31
   InterestedDecl = N->ASTNode.get();
 return InterestedDecl;
   }

this is now always true. Just return true (maybe with a comment) and move the 
InterestedDecl stuff to apply?



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:493
   const char *Output = "void /* entity.name.function.cpp */f() {}";
   checkTransform(ID, Input, Output);
 }

check input/output for TUDecl since it's a different codepath?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65210/new/

https://reviews.llvm.org/D65210



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


[PATCH] D64914: Implement P1771

2019-07-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 211504.
erichkeane added a comment.

Casting implementation had to happen in SemaStmt, because other 'warn unused 
result' stuff depends on them being the way they are.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64914/new/

https://reviews.llvm.org/D64914

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
  clang/test/Preprocessor/has_attribute.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -664,7 +664,7 @@
 

 http://wg21.link/p1771r1";>P1771R1 (DR)
-No
+SVN
   
 
   [[maybe_unused]] attribute
Index: clang/test/Preprocessor/has_attribute.cpp
===
--- clang/test/Preprocessor/has_attribute.cpp
+++ clang/test/Preprocessor/has_attribute.cpp
@@ -63,7 +63,7 @@
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
 // WINDOWS: no_unique_address: 0
-// CHECK: nodiscard: 201603L
+// CHECK: nodiscard: 201907L
 // CHECK: noreturn: 200809L
 // FIXME(201803L) CHECK: unlikely: 0
 
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
@@ -80,6 +80,48 @@
   conflicting_reason(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: special reason}}
 }
 
+namespace p1771 {
+struct[[nodiscard("Don't throw me away!")]] ConvertTo{};
+struct S {
+  [[nodiscard]] S();
+  [[nodiscard("Don't let that S-Char go!")]] S(char);
+  S(int);
+  [[gnu::warn_unused_result]] S(double);
+  operator ConvertTo();
+  [[nodiscard]] operator int();
+};
+
+struct[[nodiscard("Don't throw me away either!")]] Y{};
+
+void usage() {
+  S();// expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
+  S('A'); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't let that S-Char go!}}
+  S(1);
+  S(2.2);
+  Y(); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away either!}}
+  S s;
+  ConvertTo{}; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
+
+// AST is different in C++20 mode, pre-2017 a move ctor for ConvertTo is there
+// as well, hense the constructor warning.
+#if __cplusplus >= 201703L
+// expected-warning@+4 {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
+#else
+// expected-warning@+2 {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away!}}
+#endif
+  (ConvertTo) s;
+  (int)s; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  (S)'c'; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't let that S-Char go!}}
+#if __cplusplus >= 201703L
+// expected-warning@+4 {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
+#else
+// expected-warning@+2 {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away!}}
+#endif
+  static_cast(s);
+  static_cast(s); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+}
+}; // namespace p1771
+
 #ifdef EXT
 // expected-warning@5 {{use of the 'nodiscard' attribute is a C++17 extension}}
 // expected-warning@9 {{use of the 'nodiscard' attribute is a C++17 extension}}
@@ -91,4 +133,9 @@
 // expected-warning@71 {{use of the 'nodiscard' attribute is a C++2a extension}}
 // expected-warning@73 {{use of the 'nodiscard' attribute is a C++2a extension}}
 // expected-warning@74 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@84 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@86 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@87 {{use of the 'nodiscard' attribute is a C++2a extension}}
+// expected-warning@91 {{use of the 'nodiscard' attribute is a C++17 extension}}
+// expected-warning@94 {{use of the 'nodiscard' attribute is a C++2a extension}}
 #endif
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -254,6 +254,11 @@
 return;
 
   E = WarnExpr;
+  if

[PATCH] D58531: [clang] Specify type of pthread_create builtin

2019-07-24 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a reviewer: jdoerfert.
probinson added a comment.

We've started running into this too in building the PS4 system. +jdoerfert who 
added pthread_create to the builtin list.

Looking at the patch, it seems straightforward enough although clearly needs 
clang-format-diff run over it.
I don't touch Clang that much so I'm reluctant to okay it myself.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58531/new/

https://reviews.llvm.org/D58531



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


[PATCH] D65043: [Format] Add C++20 standard to style options

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D65043#1599148 , @Quuxplusone wrote:

> Peanut gallery says: A priori, I don't see any reason for clang-format's 
> `LanguageStandard` options to diverge from Clang's own `-std=` options. It 
> sounds like currently they're very different, and you're proposing to make 
> them basically the same. I think that's a good thing.


+1. (It'd be nice to canonically spell these 'c++11' instead of 'Cpp11', but 
that's a different patch.)
Exception: 'Auto' is important for clang-format but doesn't/shouldn't exist in 
clang.

> GCC and Clang still treat "lack of any `-std=` option" as a synonym for 
> "`-std=c++03`".

Clang actually defaults to c++14 since clang 6. (CompilerInvocation.cpp near 
`CLANG_DEFAULT_STD_CXX`)

> A priori this is an absolutely terrible default, but there would be some 
> logic in making clang-format follow their lead. The only sensible 
> alternative, IMHO, would be for you to treat "lack of any `-std=` option" as 
> a synonym for MSVC's `-std:c++latest`, which means "`-std=c++2a` today and 
> `-std=c++2b` tomorrow."

It's important that clang-format works sensibly with minimal configuration on 
as much code as possible.
This means both:

- when running on pre-11 code that uses `vector >` consistently, it 
should preserve that c++03-compatible syntax
- when running on post-11 code that uses `vector>` in some places, 
it should fix the formatting to use it everywhere

This behavior is an important default, and doesn't correspond to any one 
version of C++. So neither "latest" nor "c++14" is an acceptable default. 
(Though c++14 should certainly be an option, and latest should possibly be one 
too)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65043/new/

https://reviews.llvm.org/D65043



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


[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev added a comment.

Hi @lebedev.ri, could you please lgtm this or elaborate on possible issue with 
this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63325/new/

https://reviews.llvm.org/D63325



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


r366911 - [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Anton Afanasyev via cfe-commits
Author: anton-afanasyev
Date: Wed Jul 24 07:55:40 2019
New Revision: 366911

URL: http://llvm.org/viewvc/llvm-project?rev=366911&view=rev
Log:
[Support] Fix `-ftime-trace-granularity` option

Summary:
Move `-ftime-trace-granularity` option to frontend options. Without patch
this option is showed up in the help for any tool that links libSupport.

Reviewers: sammccall

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Modified:
cfe/trunk/docs/ClangCommandLineReference.rst
cfe/trunk/include/clang/Basic/CodeGenOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/check-time-trace.cpp
cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=366911&r1=366910&r2=366911&view=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Wed Jul 24 07:55:40 2019
@@ -1944,6 +1944,14 @@ Perform ThinLTO importing using provided
 
 .. option:: -ftime-report
 
+.. option:: -ftime-trace
+
+Turn on time profiler
+
+.. option:: -ftime-trace-granularity=
+
+Minimum time granularity (in microseconds) traced by time profiler
+
 .. option:: -ftls-model=
 
 .. option:: -ftrap-function=

Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.def?rev=366911&r1=366910&r2=366911&view=diff
==
--- cfe/trunk/include/clang/Basic/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.def Wed Jul 24 07:55:40 2019
@@ -225,6 +225,8 @@ CODEGENOPT(StrictEnums   , 1, 0) ///
 CODEGENOPT(StrictVTablePointers, 1, 0) ///< Optimize based on the strict 
vtable pointers
 CODEGENOPT(TimePasses, 1, 0) ///< Set when -ftime-report is enabled.
 CODEGENOPT(TimeTrace , 1, 0) ///< Set when -ftime-trace is enabled.
+VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500) ///< Minimum time granularity 
(in microseconds),
+   ///< traced by time profiler
 CODEGENOPT(UnrollLoops   , 1, 0) ///< Control whether loops are unrolled.
 CODEGENOPT(RerollLoops   , 1, 0) ///< Control whether loops are rerolled.
 CODEGENOPT(NoUseJumpTables   , 1, 0) ///< Set when -fno-jump-tables is enabled.

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=366911&r1=366910&r2=366911&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Jul 24 07:55:40 2019
@@ -1757,7 +1757,11 @@ def Wframe_larger_than_EQ : Joined<["-"]
 def : Flag<["-"], "fterminated-vtables">, Alias;
 def fthreadsafe_statics : Flag<["-"], "fthreadsafe-statics">, Group;
 def ftime_report : Flag<["-"], "ftime-report">, Group, 
Flags<[CC1Option]>;
-def ftime_trace : Flag<["-"], "ftime-trace">, Group, 
Flags<[CC1Option, CoreOption]>;
+def ftime_trace : Flag<["-"], "ftime-trace">, Group,
+  HelpText<"Turn on time profiler">, Flags<[CC1Option, CoreOption]>;
+def ftime_trace_granularity_EQ : Joined<["-"], "ftime-trace-granularity=">, 
Group,
+  HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
+  Flags<[CC1Option, CoreOption]>;
 def ftlsmodel_EQ : Joined<["-"], "ftls-model=">, Group, 
Flags<[CC1Option]>;
 def ftrapv : Flag<["-"], "ftrapv">, Group, Flags<[CC1Option]>,
   HelpText<"Trap on integer overflow">;

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=366911&r1=366910&r2=366911&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Wed Jul 24 07:55:40 2019
@@ -451,6 +451,9 @@ public:
   /// Filename to write statistics to.
   std::string StatsFile;
 
+  /// Minimum time granularity (in microseconds) traced by time profiler.
+  unsigned TimeTraceGranularity;
+
 public:
   FrontendOptions()
   : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
@@ -461,7 +464,7 @@ public:
 UseGlobalModuleIndex(true), GenerateGlobalModuleIndex(true),
 ASTDumpDecls(false), ASTDumpLookups(false),
 BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
-IncludeTimestamps(true) {}
+IncludeTimestamps(t

[PATCH] D65092: [clang] Add isDirectlyDerivedFrom AST Matcher.

2019-07-24 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2672
+   BaseName, 1) {
+  assert(!BaseName.empty());
+  return isDirectlyDerivedFrom(hasName(BaseName))

aaron.ballman wrote:
> I don't think this assertion is reasonable -- we should instead test this as 
> a predicate and return false if the base name is empty.
It's done in the same way as for existing isDerivedFrom and isSameOrDerivedFrom 
matchers. Maybe it would make sense to change all of them, but I guess it 
should rather be a separate commit.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65092/new/

https://reviews.llvm.org/D65092



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


[PATCH] D64991: [analyzer][WIP] Implement a primitive reaching definitions analysis

2019-07-24 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 211509.
Szelethus added a comment.

Use the correct sorting for the GEN, KILL, IN and OUT sets.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64991/new/

https://reviews.llvm.org/D64991

Files:
  clang/include/clang/Analysis/Analyses/ReachingDefinitions.h
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Analysis/ReachingDefinitions.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
  clang/test/Analysis/dump-definitions.cpp

Index: clang/test/Analysis/dump-definitions.cpp
===
--- /dev/null
+++ clang/test/Analysis/dump-definitions.cpp
@@ -0,0 +1,402 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=debug.DumpCFG \
+// RUN:   -analyzer-checker=debug.DumpGenSets \
+// RUN:   -analyzer-checker=debug.DumpKillSets \
+// RUN:   -analyzer-checker=debug.DumpReachingDefinitions \
+// RUN:   2>&1 | FileCheck %s
+
+int global_var;
+
+int getInt();
+int *getIntPtr();
+bool coin();
+
+
+void single_vardecl_in_declstmt() {
+  int *ptr = getIntPtr();
+}
+// [B2 (ENTRY)] -> [B1] -> [B0 (EXIT)]
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 1 (global_var, [1, 2])
+// CHECK-NEXT: 1 (ptr, [1, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (global_var, [1, 2])
+// CHECK-NEXT: 0 IN (ptr, [1, 3])
+// CHECK-NEXT: 0 OUT (global_var, [1, 2])
+// CHECK-NEXT: 0 OUT (ptr, [1, 3])
+// CHECK-NEXT: 1 OUT (global_var, [1, 2])
+// CHECK-NEXT: 1 OUT (ptr, [1, 3])
+
+void multiple_vardecl_in_declstmt() {
+  int *ptr = getIntPtr(), i;
+}
+// [B2 (ENTRY)] -> [B1] -> [B0 (EXIT)]
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 1 (global_var, [1, 2])
+// CHECK-NEXT: 1 (ptr, [1, 3])
+// CHECK-NEXT: 1 (i, [1, 4])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (global_var, [1, 2])
+// CHECK-NEXT: 0 IN (ptr, [1, 3])
+// CHECK-NEXT: 0 IN (i, [1, 4])
+// CHECK-NEXT: 0 OUT (global_var, [1, 2])
+// CHECK-NEXT: 0 OUT (ptr, [1, 3])
+// CHECK-NEXT: 0 OUT (i, [1, 4])
+// CHECK-NEXT: 1 OUT (global_var, [1, 2])
+// CHECK-NEXT: 1 OUT (ptr, [1, 3])
+// CHECK-NEXT: 1 OUT (i, [1, 4])
+
+void function_and_vardecl_in_declstmt() {
+  int *ptr = getIntPtr(), a();
+}
+// [B2 (ENTRY)] -> [B1] -> [B0 (EXIT)]
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 1 (global_var, [1, 2])
+// CHECK-NEXT: 1 (ptr, [1, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (global_var, [1, 2])
+// CHECK-NEXT: 0 IN (ptr, [1, 3])
+// CHECK-NEXT: 0 OUT (global_var, [1, 2])
+// CHECK-NEXT: 0 OUT (ptr, [1, 3])
+// CHECK-NEXT: 1 OUT (global_var, [1, 2])
+// CHECK-NEXT: 1 OUT (ptr, [1, 3])
+
+void single_def_in_same_block() {
+  int *ptr = getIntPtr();
+
+  if (coin())
+ptr = 0;
+
+  if (!ptr)
+*ptr = 5;
+}
+//-> [B3] ->-> [B1] ->
+//   /  \  /  \
+// [B5 (ENTRY)] -> [B4] --> [B2] ---> [B0 (EXIT)]
+
+// CHECK:  GEN sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 3 (ptr, [3, 3])
+// CHECK-NEXT: 4 (global_var, [4, 6])
+// CHECK-NEXT: 4 (ptr, [4, 3])
+// CHECK-NEXT: KILL sets: blockid (varname [blockid, elementid])
+// CHECK-NEXT: 3 (ptr, [4, 3])
+// CHECK-NEXT: 4 (ptr, [3, 3])
+// CHECK-NEXT: Reaching definition sets: blockid IN/OUT (varname [blockid, elementid])
+// CHECK-NEXT: 0 IN (global_var, [4, 6])
+// CHECK-NEXT: 0 IN (ptr, [3, 3])
+// CHECK-NEXT: 0 IN (ptr, [4, 3])
+// CHECK-NEXT: 0 OUT (global_var, [4, 6])
+// CHECK-NEXT: 0 OUT (ptr, [3, 3])
+// CHECK-NEXT: 0 OUT (ptr, [4, 3])
+// CHECK-NEXT: 1 IN (global_var, [4, 6])
+// CHECK-NEXT: 1 IN (ptr, [3, 3])
+// CHECK-NEXT: 1 IN (ptr, [4, 3])
+// CHECK-NEXT: 1 OUT (global_var, [4, 6])
+// CHECK-NEXT: 1 OUT (ptr, [3, 3])
+// CHECK-NEXT: 1 OUT (ptr, [4, 3])
+// CHECK-NEXT: 2 IN (global_var, [4, 6])
+// CHECK-NEXT: 2 IN (ptr, [3, 3])
+// CHECK-NEXT: 2 IN (ptr, [4, 3])
+// CHECK-NEXT: 2 OUT (global_var, [4, 6])
+// CHECK-NEXT: 2 OUT (ptr, [3, 3])
+// CHECK-NEXT: 2 OUT (ptr, [4, 3])
+// CHECK-NEXT: 3 IN (global_var, [4, 6])
+// CHECK-NEXT: 3 IN (ptr, [4, 3])
+// CHECK-NEXT: 3 OUT (global_var, [4, 6])
+// CHECK-NEXT: 3 OUT (ptr, [3, 3])
+// CHECK-NEXT: 4 OUT (global_var, [4, 6])
+// CHECK-NEXT: 4 OUT (ptr, [4, 3])
+
+void different_assignments() {
+  int i = getInt();
+
+  if (coin())
+i = 0;
+
+  i += 3;
+
+  if (!coin())
+i -= 2;
+
+  i *= 9;
+
+  if (i = 0)
+;
+}
+//-> [B5] ->-> [B3] ->-> [B1] ->
+//   /  \  /  \  /

[PATCH] D65202: [Support] Fix `-ftime-trace-granularity` option

2019-07-24 Thread Anton Afanasyev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366911: [Support] Fix `-ftime-trace-granularity` option 
(authored by anton-afanasyev, committed by ).
Herald added a subscriber: kristina.

Changed prior to commit:
  https://reviews.llvm.org/D65202?vs=211489&id=211510#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65202/new/

https://reviews.llvm.org/D65202

Files:
  cfe/trunk/docs/ClangCommandLineReference.rst
  cfe/trunk/include/clang/Basic/CodeGenOptions.def
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/FrontendOptions.h
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/Driver/check-time-trace.cpp
  cfe/trunk/tools/driver/cc1_main.cpp
  llvm/trunk/include/llvm/Support/TimeProfiler.h
  llvm/trunk/lib/Support/TimeProfiler.cpp

Index: llvm/trunk/include/llvm/Support/TimeProfiler.h
===
--- llvm/trunk/include/llvm/Support/TimeProfiler.h
+++ llvm/trunk/include/llvm/Support/TimeProfiler.h
@@ -19,7 +19,7 @@
 /// Initialize the time trace profiler.
 /// This sets up the global \p TimeTraceProfilerInstance
 /// variable to be the profiler instance.
-void timeTraceProfilerInitialize();
+void timeTraceProfilerInitialize(unsigned TimeTraceGranularity);
 
 /// Cleanup the time trace profiler, if it was initialized.
 void timeTraceProfilerCleanup();
Index: llvm/trunk/lib/Support/TimeProfiler.cpp
===
--- llvm/trunk/lib/Support/TimeProfiler.cpp
+++ llvm/trunk/lib/Support/TimeProfiler.cpp
@@ -24,12 +24,6 @@
 
 namespace llvm {
 
-static cl::opt TimeTraceGranularity(
-"time-trace-granularity",
-cl::desc(
-"Minimum time granularity (in microseconds) traced by time profiler"),
-cl::init(500));
-
 TimeTraceProfiler *TimeTraceProfilerInstance = nullptr;
 
 typedef duration DurationType;
@@ -161,12 +155,16 @@
   SmallVector Entries;
   StringMap CountAndTotalPerName;
   time_point StartTime;
+
+  // Minimum time granularity (in microseconds)
+  unsigned TimeTraceGranularity;
 };
 
-void timeTraceProfilerInitialize() {
+void timeTraceProfilerInitialize(unsigned TimeTraceGranularity) {
   assert(TimeTraceProfilerInstance == nullptr &&
  "Profiler should not be initialized");
   TimeTraceProfilerInstance = new TimeTraceProfiler();
+  TimeTraceProfilerInstance->TimeTraceGranularity = TimeTraceGranularity;
 }
 
 void timeTraceProfilerCleanup() {
Index: cfe/trunk/tools/driver/cc1_main.cpp
===
--- cfe/trunk/tools/driver/cc1_main.cpp
+++ cfe/trunk/tools/driver/cc1_main.cpp
@@ -216,9 +216,10 @@
   bool Success = CompilerInvocation::CreateFromArgs(
   Clang->getInvocation(), Argv.begin(), Argv.end(), Diags);
 
-  if (Clang->getFrontendOpts().TimeTrace)
-llvm::timeTraceProfilerInitialize();
-
+  if (Clang->getFrontendOpts().TimeTrace) {
+llvm::timeTraceProfilerInitialize(
+Clang->getFrontendOpts().TimeTraceGranularity);
+  }
   // --print-supported-cpus takes priority over the actual compilation.
   if (Clang->getFrontendOpts().PrintSupportedCPUs)
 return PrintSupportedCPUs(Clang->getTargetOpts().Triple);
Index: cfe/trunk/docs/ClangCommandLineReference.rst
===
--- cfe/trunk/docs/ClangCommandLineReference.rst
+++ cfe/trunk/docs/ClangCommandLineReference.rst
@@ -1944,6 +1944,14 @@
 
 .. option:: -ftime-report
 
+.. option:: -ftime-trace
+
+Turn on time profiler
+
+.. option:: -ftime-trace-granularity=
+
+Minimum time granularity (in microseconds) traced by time profiler
+
 .. option:: -ftls-model=
 
 .. option:: -ftrap-function=
Index: cfe/trunk/include/clang/Basic/CodeGenOptions.def
===
--- cfe/trunk/include/clang/Basic/CodeGenOptions.def
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.def
@@ -225,6 +225,8 @@
 CODEGENOPT(StrictVTablePointers, 1, 0) ///< Optimize based on the strict vtable pointers
 CODEGENOPT(TimePasses, 1, 0) ///< Set when -ftime-report is enabled.
 CODEGENOPT(TimeTrace , 1, 0) ///< Set when -ftime-trace is enabled.
+VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500) ///< Minimum time granularity (in microseconds),
+   ///< traced by time profiler
 CODEGENOPT(UnrollLoops   , 1, 0) ///< Control whether loops are unrolled.
 CODEGENOPT(RerollLoops   , 1, 0) ///< Control whether loops are rerolled.
 CODEGENOPT(NoUseJumpTables   , 1, 0) ///< Set when -fno-jump-tables is enabled.
Index: cfe/trunk/include/clang/Frontend/FrontendOptions.h
===
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h
@@ -451,6 +451,9 @

[PATCH] D65092: [clang] Add isDirectlyDerivedFrom AST Matcher.

2019-07-24 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 211508.
AntonBikineev marked an inline comment as done.
AntonBikineev added a comment.

Thanks for the comments!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65092/new/

https://reviews.llvm.org/D65092

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -331,6 +331,16 @@
   EXPECT_TRUE(notMatches("class Y;", IsDerivedFromX));
   EXPECT_TRUE(notMatches("", IsDerivedFromX));
 
+  DeclarationMatcher IsDirectlyDerivedFromX =
+  cxxRecordDecl(isDirectlyDerivedFrom("X"));
+
+  EXPECT_TRUE(
+  matches("class X {}; class Y : public X {};", IsDirectlyDerivedFromX));
+  EXPECT_TRUE(notMatches("class X {};", IsDirectlyDerivedFromX));
+  EXPECT_TRUE(notMatches("class X;", IsDirectlyDerivedFromX));
+  EXPECT_TRUE(notMatches("class Y;", IsDirectlyDerivedFromX));
+  EXPECT_TRUE(notMatches("", IsDirectlyDerivedFromX));
+
   DeclarationMatcher IsAX = cxxRecordDecl(isSameOrDerivedFrom("X"));
 
   EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsAX));
@@ -341,13 +351,22 @@
 
   DeclarationMatcher ZIsDerivedFromX =
 cxxRecordDecl(hasName("Z"), isDerivedFrom("X"));
+  DeclarationMatcher ZIsDirectlyDerivedFromX =
+  cxxRecordDecl(hasName("Z"), isDirectlyDerivedFrom("X"));
   EXPECT_TRUE(
 matches("class X {}; class Y : public X {}; class Z : public Y {};",
 ZIsDerivedFromX));
+  EXPECT_TRUE(
+  notMatches("class X {}; class Y : public X {}; class Z : public Y {};",
+ ZIsDirectlyDerivedFromX));
   EXPECT_TRUE(
 matches("class X {};"
   "template class Y : public X {};"
   "class Z : public Y {};", ZIsDerivedFromX));
+  EXPECT_TRUE(notMatches("class X {};"
+ "template class Y : public X {};"
+ "class Z : public Y {};",
+ ZIsDirectlyDerivedFromX));
   EXPECT_TRUE(matches("class X {}; template class Z : public X {};",
   ZIsDerivedFromX));
   EXPECT_TRUE(
@@ -411,6 +430,9 @@
 matches("class X {}; class Y : public X {}; "
   "typedef Y V; typedef V W; class Z : public W {};",
 ZIsDerivedFromX));
+  EXPECT_TRUE(notMatches("class X {}; class Y : public X {}; "
+ "typedef Y V; typedef V W; class Z : public W {};",
+ ZIsDirectlyDerivedFromX));
   EXPECT_TRUE(
 matches("template class X {}; "
   "template class A { class Z : public X {}; };",
@@ -467,6 +489,14 @@
   "template<> struct X<0> : public A {};"
   "struct B : public X<42> {};",
 cxxRecordDecl(hasName("B"), isDerivedFrom(recordDecl(hasName("A"));
+  EXPECT_TRUE(notMatches(
+  "struct A {};"
+  "template struct X;"
+  "template struct X : public X {};"
+  "template<> struct X<0> : public A {};"
+  "struct B : public X<42> {};",
+  cxxRecordDecl(hasName("B"),
+isDirectlyDerivedFrom(recordDecl(hasName("A"));
 
   // FIXME: Once we have better matchers for template type matching,
   // get rid of the Variable(...) matching and match the right template
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -430,7 +430,8 @@
 
   bool classIsDerivedFrom(const CXXRecordDecl *Declaration,
   const Matcher &Base,
-  BoundNodesTreeBuilder *Builder) override;
+  BoundNodesTreeBuilder *Builder,
+  bool Directly) override;
 
   // Implements ASTMatchFinder::matchesChildOf.
   bool matchesChildOf(const ast_type_traits::DynTypedNode &Node,
@@ -817,7 +818,8 @@
 // derived from itself.
 bool MatchASTVisitor::classIsDerivedFrom(const CXXRecordDecl *Declaration,
  const Matcher &Base,
- BoundNodesTreeBuilder *Builder) {
+ BoundNodesTreeBuilder *Builder,
+ bool Directly) {
   if (!Declaration->hasDefinition())
 return false;
   for (const auto &It : Declaration->bases()) {
@@ -842,7 +844,7 @@
   *Builder = std::move(Result);
   return true;
 }
-if (classIsDerivedFrom(ClassDecl, Base, Builder))
+if (!Directly && classIsDerivedFrom(ClassDecl, Base, Builder, Directly))
   return true;
   }
   return false;
In

[PATCH] D65092: [clang] Add isDirectlyDerivedFrom AST Matcher.

2019-07-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2672
+   BaseName, 1) {
+  assert(!BaseName.empty());
+  return isDirectlyDerivedFrom(hasName(BaseName))

AntonBikineev wrote:
> aaron.ballman wrote:
> > I don't think this assertion is reasonable -- we should instead test this 
> > as a predicate and return false if the base name is empty.
> It's done in the same way as for existing isDerivedFrom and 
> isSameOrDerivedFrom matchers. Maybe it would make sense to change all of 
> them, but I guess it should rather be a separate commit.
I'm fine with doing it in a follow-up commit, but it should be done (it 
shouldn't assert on invalid input, only on thought-to-be impossible situations, 
generally speaking).



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2682
+/// \endcode
+AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isDirectlyDerivedFrom,
+   internal::Matcher, Base, 0) {

You should register this in Registry.cpp as an overload, like we do for 
`isDerivedFrom()` and `isSameOrDerivedFrom()`.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65092/new/

https://reviews.llvm.org/D65092



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


[PATCH] D65092: [clang] Add isDirectlyDerivedFrom AST Matcher.

2019-07-24 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 211513.
AntonBikineev marked an inline comment as not done.
AntonBikineev added a comment.

Missed that, thanks for the point!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65092/new/

https://reviews.llvm.org/D65092

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -331,6 +331,16 @@
   EXPECT_TRUE(notMatches("class Y;", IsDerivedFromX));
   EXPECT_TRUE(notMatches("", IsDerivedFromX));
 
+  DeclarationMatcher IsDirectlyDerivedFromX =
+  cxxRecordDecl(isDirectlyDerivedFrom("X"));
+
+  EXPECT_TRUE(
+  matches("class X {}; class Y : public X {};", IsDirectlyDerivedFromX));
+  EXPECT_TRUE(notMatches("class X {};", IsDirectlyDerivedFromX));
+  EXPECT_TRUE(notMatches("class X;", IsDirectlyDerivedFromX));
+  EXPECT_TRUE(notMatches("class Y;", IsDirectlyDerivedFromX));
+  EXPECT_TRUE(notMatches("", IsDirectlyDerivedFromX));
+
   DeclarationMatcher IsAX = cxxRecordDecl(isSameOrDerivedFrom("X"));
 
   EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsAX));
@@ -341,13 +351,22 @@
 
   DeclarationMatcher ZIsDerivedFromX =
 cxxRecordDecl(hasName("Z"), isDerivedFrom("X"));
+  DeclarationMatcher ZIsDirectlyDerivedFromX =
+  cxxRecordDecl(hasName("Z"), isDirectlyDerivedFrom("X"));
   EXPECT_TRUE(
 matches("class X {}; class Y : public X {}; class Z : public Y {};",
 ZIsDerivedFromX));
+  EXPECT_TRUE(
+  notMatches("class X {}; class Y : public X {}; class Z : public Y {};",
+ ZIsDirectlyDerivedFromX));
   EXPECT_TRUE(
 matches("class X {};"
   "template class Y : public X {};"
   "class Z : public Y {};", ZIsDerivedFromX));
+  EXPECT_TRUE(notMatches("class X {};"
+ "template class Y : public X {};"
+ "class Z : public Y {};",
+ ZIsDirectlyDerivedFromX));
   EXPECT_TRUE(matches("class X {}; template class Z : public X {};",
   ZIsDerivedFromX));
   EXPECT_TRUE(
@@ -411,6 +430,9 @@
 matches("class X {}; class Y : public X {}; "
   "typedef Y V; typedef V W; class Z : public W {};",
 ZIsDerivedFromX));
+  EXPECT_TRUE(notMatches("class X {}; class Y : public X {}; "
+ "typedef Y V; typedef V W; class Z : public W {};",
+ ZIsDirectlyDerivedFromX));
   EXPECT_TRUE(
 matches("template class X {}; "
   "template class A { class Z : public X {}; };",
@@ -467,6 +489,14 @@
   "template<> struct X<0> : public A {};"
   "struct B : public X<42> {};",
 cxxRecordDecl(hasName("B"), isDerivedFrom(recordDecl(hasName("A"));
+  EXPECT_TRUE(notMatches(
+  "struct A {};"
+  "template struct X;"
+  "template struct X : public X {};"
+  "template<> struct X<0> : public A {};"
+  "struct B : public X<42> {};",
+  cxxRecordDecl(hasName("B"),
+isDirectlyDerivedFrom(recordDecl(hasName("A"));
 
   // FIXME: Once we have better matchers for template type matching,
   // get rid of the Variable(...) matching and match the right template
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -108,6 +108,7 @@
   REGISTER_OVERLOADED_2(hasType);
   REGISTER_OVERLOADED_2(ignoringParens);
   REGISTER_OVERLOADED_2(isDerivedFrom);
+  REGISTER_OVERLOADED_2(isDirectlyDerivedFrom);
   REGISTER_OVERLOADED_2(isSameOrDerivedFrom);
   REGISTER_OVERLOADED_2(loc);
   REGISTER_OVERLOADED_2(pointsTo);
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -430,7 +430,8 @@
 
   bool classIsDerivedFrom(const CXXRecordDecl *Declaration,
   const Matcher &Base,
-  BoundNodesTreeBuilder *Builder) override;
+  BoundNodesTreeBuilder *Builder,
+  bool Directly) override;
 
   // Implements ASTMatchFinder::matchesChildOf.
   bool matchesChildOf(const ast_type_traits::DynTypedNode &Node,
@@ -817,7 +818,8 @@
 // derived from itself.
 bool MatchASTVisitor::classIsDerivedFrom(const CXXRecordDecl *Declaration,
  const Matcher &Base,
-   

[PATCH] D65176: [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

2019-07-24 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: clang/include/clang/Driver/Types.def:39-45
+// Some of the options in Flags have been removed, so far those are:
+//  a - The type should only be assembled: Now, check that Phases contains
+//  phases::Assemble but not phases::Compile or phases::Backend.
+//  p - The type should only be precompiled: Now, check that Phases contains
+//  phases::Precompile but that Flags does not contain 'm'.
+//  m - Precompiling this type produces a module file: Now, check that
+//  isPrepeocessedModuleType.

aaron.ballman wrote:
> Why should we document the removed flags, since users cannot write them 
> anyway?
Actually, that makes sense to me.  The reasoning for it (and the key thing to 
note about the documentation) is that it helps downstream forks as it indicates 
how to migrate.  Now, if you believe that this bit of functionality is unlikely 
to be used, thats a different story.  But, I don't think that it hurts to have 
the documentation in the commit message instead.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65176/new/

https://reviews.llvm.org/D65176



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


[PATCH] D65149: [Format] Add test demonstrating PR42722

2019-07-24 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

We don't normally commit a failing test alone, otherwise the build machines 
will be broken until it gets fixed.. just add this test with your fix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65149/new/

https://reviews.llvm.org/D65149



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


[PATCH] D65139: [clangd] Support extraction of binary "subexpressions" like a + [[b + c]].

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 6 inline comments as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:213
+//the purposes of calculating the insertion point.
+namespace {
+

SureYeaah wrote:
> Why do we need an anon namespace inside another anon namespace?
Oops, forgot we already were in one.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:217
+// It can represent either an overloaded or built-in operator.
+struct ParsedBinaryOperator {
+  BinaryOperatorKind Kind;

SureYeaah wrote:
> Wouldn't it make more sense this to have this in some other place (maybe 
> Selection) because other refactorings might want to make use of this feature?
It's possible, but I think we should cross that bridge when we come to it, 
because it's not obvious what those other refactorings are.

There might be some subtle ways in which I've specialized the code for this use 
case, and it's easier to see that and polish it when we have more use cases in 
hand.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:283
+const SelectionTree::Node *getEndpoint(const SelectionTree::Node &N,
+   BinaryOperatorKind OuterOp, bool 
IsStart,
+   const SourceManager &SM) {

SureYeaah wrote:
> We're considering the case where all the operators are the same. Isn't it 
> true that in that case, the End will be the the first 'selected RHS' that we 
> find during the traversal? If so, can't we just get rid of the IsStart?
Oh, right - I'm assuming a much more general tree than can actually exist.
This code is trying to handle an arbitrary binary tree of binops, but of course 
each actual operator is either left-associative or right-associative, and so 
it's a linked-list-shaped binary tree.
And the actual code is pretty simple, but the explanation sure is complicated.

And in fact, all the operators are left-associative! I didn't really want to 
hard-code that, but it'll simplify the code a lot I think.

So this should probably just be a simple loop:
```
findEndpoints(L, R):
  while (LL, RL) = parseBinop(L):
L = (LL is selected) ? LL : RL
  return (L, R)
```

I'll rewrite this tomorrow. Thanks for the hint!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65139/new/

https://reviews.llvm.org/D65139



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


[PATCH] D65139: [clangd] Support extraction of binary "subexpressions" like a + [[b + c]].

2019-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 211521.
sammccall marked an inline comment as done.
sammccall added a comment.

Address minor comments, but not tree-traversal simplification yet.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65139/new/

https://reviews.llvm.org/D65139

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -444,6 +444,47 @@
   // FIXME: Doesn't work correctly for \[\[clang::uninitialized\]\] int
   // b = [[1]]; since the attr is inside the DeclStmt and the bounds of
   // DeclStmt don't cover the attribute
+
+  // Binary subexpressions
+  {R"cpp(void f() {
+   int x = 1 + [[2 + 3 + 4]] + 5;
+ })cpp",
+   R"cpp(void f() {
+   auto dummy = 2 + 3 + 4; int x = 1 + dummy + 5;
+ })cpp"},
+  // Non-associative operations have no special support
+  {R"cpp(void f() {
+   int x = 1 - [[2 - 3 - 4]] - 5;
+ })cpp",
+   R"cpp(void f() {
+   auto dummy = 1 - 2 - 3 - 4; int x = dummy - 5;
+ })cpp"},
+  // A mix of associative operators isn't associative.
+  {R"cpp(void f() {
+   int x = 1 * [[2 + 3 * 4]] + 5;
+ })cpp",
+   R"cpp(void f() {
+   auto dummy = 1 * 2 + 3 * 4; int x = dummy + 5;
+ })cpp"},
+  // Overloaded operators are supported, we assume associativity
+  // as if they were built-in.
+  {R"cpp(struct S {
+   S(int);
+ };
+ S operator+(S, S);
+
+ void f() {
+   S x = S(1) + [[S(2) + S(3) + S(4)]] + S(5);
+ })cpp",
+   R"cpp(struct S {
+   S(int);
+ };
+ S operator+(S, S);
+
+ void f() {
+   auto dummy = S(2) + S(3) + S(4); S x = S(1) + dummy + S(5);
+ })cpp"},
+
   };
   for (const auto &IO : InputOutputs) {
 checkTransform(ID, IO.first, IO.second);
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -335,6 +335,23 @@
   }
 }
 
+TEST(SelectionTest, Implicit) {
+  const char* Test = R"cpp(
+struct S { S(const char*); };
+int f(S);
+int x = f("^");
+  )cpp";
+  auto AST = TestTU::withCode(Annotations(Test).code()).build();
+  auto T = makeSelectionTree(Test, AST);
+
+  const SelectionTree::Node *Str = T.commonAncestor();
+  EXPECT_EQ("StringLiteral", nodeKind(Str)) << "Implicit selected?";
+  EXPECT_EQ("ImplicitCastExpr", nodeKind(Str->Parent));
+  EXPECT_EQ("CXXConstructExpr", nodeKind(Str->Parent->Parent));
+  EXPECT_EQ(Str, &Str->Parent->Parent->ignoreImplicit())
+  << "Didn't unwrap " << nodeKind(&Str->Parent->Parent->ignoreImplicit());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -13,7 +13,9 @@
 #include "refactor/Tweak.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
@@ -26,6 +28,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
@@ -38,10 +41,14 @@
   const clang::Expr *getExpr() const { return Expr; }
   const SelectionTree::Node *getExprNode() const { return ExprNode; }
   bool isExtractable() const { return Extractable; }
+  // The half-open range for the expression to be extracted.
+  SourceRange getExtractionChars() const;
   // Generate Replacement for replacing selected expression with given VarName
-  tooling::Replacement replaceWithVar(llvm::StringRef VarName) const;
+  tooling::Replacement replaceWithVar(SourceRange Chars,
+  llvm::StringRef VarName) const;
   // Generate Replacement for decla

[PATCH] D64386: CodeGen: Use memset in initializers for non-zeros

2019-07-24 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added inline comments.



Comment at: clang/test/CodeGen/init-memset.c:29
   char a[] = "aa";
-  // CHECK: call void @llvm.memcpy.{{.*}}
+  // CHECK: call void @llvm.memset.{{.*}}
   use(a);

I'd be more comfortable if the test here actually checked the length and the 
value in the memset call here and below.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64386/new/

https://reviews.llvm.org/D64386



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


[PATCH] D65043: [Format] Add C++20 standard to style options

2019-07-24 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/Format.cpp:76
+IO.enumCase(Value, "C++20", FormatStyle::LS_Cpp20);
 IO.enumCase(Value, "Auto", FormatStyle::LS_Auto);
   }

Prior to C++20 being confirmed and given the line 2373 being 
LangOpts.CPlusPlus2a, it feels a little wrong to introduce anything here other 
than Cpp2a into what is effectively the .clang-format file format.

In the rare event that Cpp2a becomes something other than 20, this would leave 
us with .clang-format files out there defining something that doesn't really 
exist, but regardless of the assignment of Cpp2a to what it might become

```
IO.enumCase(Value, "Cpp2a", FormatStyle::LS_Cpp2a); 
```

will always be correct, meaning Clang-Format files with Cpp2a would be correct 
for whatever it became Cpp20  or Cpp21

When 2a becomes something real, there will likely be a change in clang to 
change LangOptions.. this feels like the correct time to add

```

LS_Cpp20 ~= LS_Cpp2a

and 

IO.enumCase(Value, "Cpp2a", FormatStyle::LS_Cpp20);
IO.enumCase(Value, "Cpp20", FormatStyle::LS_Cpp20);
IO.enumCase(Value, "C++20", FormatStyle::LS_Cpp20);
```

along with the corresponding changes to all uses of LS_Cpp2a upgraded to the 
correct version.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65043/new/

https://reviews.llvm.org/D65043



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


[PATCH] D65127: Even more warnings utilizing gsl::Owner/gsl::Pointer annotations

2019-07-24 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

I have run this successfully on ~192 open source projects.

The results so far:

  1.
  https://github.com/ANTsX/ANTs/blob/master/Examples/sccan.cxx#L2899
  /home/tgahor/data/projects/ANTs/Examples/sccan.cxx:2899:34: warning: object 
backing the pointer will be destroyed at the end of the full-expression 
[-Wdangling]
  const char *longName = ( ( *it )->GetLongName() ).c_str();
   ^~
  This seems to be a true positive given how LongName is defined with this 
macro: 
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkMacro.h#L944
  Here: 
https://github.com/ANTsX/ANTs/blob/15f4e4013ed33b9d226c8d1b7d9509b2a8b19ba2/Utilities/antsCommandLineOption.h#L179
  This problem has also other instances in this project. True positives, yay!
  
  2.
  
https://github.com/mgbellemare/Arcade-Learning-Environment/blob/master/ale_python_interface/ale_c_wrapper.h#L10
  In file included from 
/home/tgahor/data/projects/Arcade-Learning-Environment/ale_python_interface/ale_c_wrapper.cpp:1:
  
/home/tgahor/data/projects/Arcade-Learning-Environment/ale_python_interface/ale_c_wrapper.h:10:68:
 warning: returning address of local temporary object [-Wreturn-stack-address]
const char *getString(ALEInterface *ale, const char *key){return 
ale->getString(key).c_str();}
 
^~
  This also is a true positive!
  
  3.
  https://github.com/assimp/assimp/blob/master/code/Step/STEPFile.h#L910
  /home/tgahor/data/projects/assimp/./code/Step/STEPFile.h:910:26: warning: 
returning address of local temporary object [-Wreturn-stack-address]
  return (*it).second;
   ^~
  /home/tgahor/data/projects/assimp/./code/Step/STEPFile.h:908:45: note: via 
initialization of variable 'it' here
  const ObjectMap::const_iterator it = objects.find(id);
  
  This one seems to be a false positive, will look into what is the root cause. 
Very similar false positives appear on jsoncpp, bamtools, gtest, cppcheck, 
Urho3D projects.
  
  4.
  
https://github.com/openscenegraph/OpenSceneGraph/blob/master/include/osg/io_utils#L69
  /home/tgahor/data/projects/OpenSceneGraph/include/osg/io_utils:69:51: 
warning: returning address of local temporary object [-Wreturn-stack-address]
  inline const char* c_str() const { return sstream.str().c_str(); }
^
  This also is a true positive!

Conclusion: it does find true positives! All of the false positives should have 
the same root cause and I will look into fixing that soon. After the fix I will 
rerun this on even more projects, but I think this already starts to show the 
value of these warnings. I believe we will be able to find all the errors I 
reported and have 0 false positives.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65127/new/

https://reviews.llvm.org/D65127



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


  1   2   >