[clang-tools-extra] r354992 - Added more detailed documentation for clangd

2019-02-27 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Feb 27 07:53:05 2019
New Revision: 354992

URL: http://llvm.org/viewvc/llvm-project?rev=354992&view=rev
Log:
Added more detailed documentation for clangd

Summary:
The text was written mostly by Sam McCall, screenshots are mostly made
by me.

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, jdoerfert, 
cfe-commits

Tags: #clang

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

Added:
clang-tools-extra/trunk/docs/_static/
clang-tools-extra/trunk/docs/_static/clang-tools-extra-styles.css
clang-tools-extra/trunk/docs/_templates/
clang-tools-extra/trunk/docs/_templates/layout.html
clang-tools-extra/trunk/docs/clangd/ApplyClangTidyFixInVSCode.gif   (with 
props)
clang-tools-extra/trunk/docs/clangd/ApplyFixInVSCode.gif   (with props)
clang-tools-extra/trunk/docs/clangd/CodeCompletionInEmacsCompanyMode.png   
(with props)
clang-tools-extra/trunk/docs/clangd/CodeCompletionInSublimeText.png   (with 
props)
clang-tools-extra/trunk/docs/clangd/CodeCompletionInVSCode.png   (with 
props)
clang-tools-extra/trunk/docs/clangd/CodeCompletionInYCM.png   (with props)

clang-tools-extra/trunk/docs/clangd/CodeCompletionInsertsNamespaceQualifiersInVSCode.gif
   (with props)
clang-tools-extra/trunk/docs/clangd/DeveloperDocumentation.rst
clang-tools-extra/trunk/docs/clangd/DiagnosticsInEmacsEglot.png   (with 
props)
clang-tools-extra/trunk/docs/clangd/ErrorsInVSCode.png   (with props)
clang-tools-extra/trunk/docs/clangd/Extensions.rst
clang-tools-extra/trunk/docs/clangd/Features.rst
clang-tools-extra/trunk/docs/clangd/FindAllReferencesInVSCode.gif   (with 
props)
clang-tools-extra/trunk/docs/clangd/FormatSelectionInVSCode.gif   (with 
props)
clang-tools-extra/trunk/docs/clangd/GoToDefinitionInVSCode.gif   (with 
props)
clang-tools-extra/trunk/docs/clangd/Installation.rst
clang-tools-extra/trunk/docs/clangd/NavigationWithBreadcrumbsInVSCode.gif   
(with props)
clang-tools-extra/trunk/docs/clangd/OutlineInVSCode.png   (with props)
clang-tools-extra/trunk/docs/clangd/SignatureHelpInVSCode.gif   (with props)
Modified:
clang-tools-extra/trunk/docs/clangd/index.rst
clang-tools-extra/trunk/docs/conf.py
clang-tools-extra/trunk/docs/index.rst

Added: clang-tools-extra/trunk/docs/_static/clang-tools-extra-styles.css
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/_static/clang-tools-extra-styles.css?rev=354992&view=auto
==
--- clang-tools-extra/trunk/docs/_static/clang-tools-extra-styles.css (added)
+++ clang-tools-extra/trunk/docs/_static/clang-tools-extra-styles.css Wed Feb 
27 07:53:05 2019
@@ -0,0 +1,23 @@
+details {
+  background-color: rgba(50, 150, 220, 0.08);
+  margin-bottom: 0.5em;
+  padding: 0 1em;
+  overflow-y: hidden; /* Suppress margin-collapsing */
+}
+details[open] {
+  border-bottom: 1px solid rgba(0, 0, 128, 0.2);
+  margin-bottom: 1em;
+}
+details summary {
+  font-weight: bold;
+  background-color: rgba(50, 150, 220, 0.1);
+  border-color: rgba(0, 0, 128, 0.2);
+  border-width: 1px;
+  border-style: solid none;
+  padding: 0.2em;
+  margin: 0 -1em;
+}
+details summary:hover {
+  background-color: rgba(50, 150, 220, 0.2);
+  cursor: pointer;
+}

Added: clang-tools-extra/trunk/docs/_templates/layout.html
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/_templates/layout.html?rev=354992&view=auto
==
--- clang-tools-extra/trunk/docs/_templates/layout.html (added)
+++ clang-tools-extra/trunk/docs/_templates/layout.html Wed Feb 27 07:53:05 2019
@@ -0,0 +1,3 @@
+{% extends "!layout.html" %}
+
+{% set css_files = css_files + ['_static/clang-tools-extra-styles.css'] %}

Added: clang-tools-extra/trunk/docs/clangd/ApplyClangTidyFixInVSCode.gif
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clangd/ApplyClangTidyFixInVSCode.gif?rev=354992&view=auto
==
Binary file - no diff available.

Propchange: clang-tools-extra/trunk/docs/clangd/ApplyClangTidyFixInVSCode.gif
--
svn:mime-type = application/octet-stream

Added: clang-tools-extra/trunk/docs/clangd/ApplyFixInVSCode.gif
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clangd/ApplyFixInVSCode.gif?rev=354992&view=auto
==
Binary file - no diff available.

Propchange: clang-tools-extra/trunk/docs/clangd/ApplyFixInVSCode.gif
--
svn:mime-type = application/octet-stream

Added: clang-tools-extra/trunk/docs/clangd/CodeCompletionInEmacsCompanyMode.png
URL: 
http://llvm.org/vi

[clang-tools-extra] r354994 - Added documentation for clangd v9+ features

2019-02-27 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Feb 27 08:08:04 2019
New Revision: 354994

URL: http://llvm.org/viewvc/llvm-project?rev=354994&view=rev
Log:
Added documentation for clangd v9+ features

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, jdoerfert, 
cfe-commits

Tags: #clang

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

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

Modified: clang-tools-extra/trunk/docs/clangd/Features.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clangd/Features.rst?rev=354994&r1=354993&r2=354994&view=diff
==
--- clang-tools-extra/trunk/docs/clangd/Features.rst (original)
+++ clang-tools-extra/trunk/docs/clangd/Features.rst Wed Feb 27 08:08:04 2019
@@ -38,6 +38,30 @@ clangd can update the code for you.
 
 :raw-html:``
 
+**(New in v9)**
+If a missing symbol was seen in a file you've edited recently, clangd will
+suggest inserting it.
+
+clang-tidy checks
+-
+
+**(New in v9)**
+clangd embeds `clang-tidy `__
+which provides extra hints about code problems: bug-prone patterns,
+performance traps, and style issues.
+
+:raw-html:`Animated demo`
+
+.. image:: ApplyClangTidyFixInVSCode.gif
+   :align: center
+   :alt: Applying a fix suggested by the compiler
+
+:raw-html:``
+
+clangd respects your project's ``.clang-tidy`` file which controls the checks
+to run. Not all checks work within clangd.  You must pass the ``-clang-tidy``
+flag to enable this feature.
+
 Code completion
 ===
 
@@ -92,6 +116,9 @@ The following features let you navigate
 If there is no project-wide index, cross-references work across the files
 you have opened.
 
+**(New in v9)**
+clangd will also automatically index your whole project.
+
 Find definition/declaration
 ---
 
@@ -105,6 +132,13 @@ Jump to the definition or declaration of
 
 :raw-html:``
 
+**(New in v9)**
+Some editors only expose "find definition"; use "find definition" on the
+definition to jump to the declaration.
+
+"Find definition" also works on ``#include`` lines, to jump to the included
+file.
+
 Find references
 ---
 


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


[clang-tools-extra] r355081 - Moved DenseMap support for SymbolID into SymbolID.h

2019-02-28 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Feb 28 03:00:44 2019
New Revision: 355081

URL: http://llvm.org/viewvc/llvm-project?rev=355081&view=rev
Log:
Moved DenseMap support for SymbolID into SymbolID.h

Modified:
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/SymbolID.h

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=355081&r1=355080&r2=355081&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Thu Feb 28 03:00:44 2019
@@ -94,31 +94,6 @@ inline bool operator<(const SymbolLocati
 }
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolLocation &);
 
-} // namespace clangd
-} // namespace clang
-namespace llvm {
-// Support SymbolIDs as DenseMap keys.
-template <> struct DenseMapInfo {
-  static inline clang::clangd::SymbolID getEmptyKey() {
-static clang::clangd::SymbolID EmptyKey("EMPTYKEY");
-return EmptyKey;
-  }
-  static inline clang::clangd::SymbolID getTombstoneKey() {
-static clang::clangd::SymbolID TombstoneKey("TOMBSTONEKEY");
-return TombstoneKey;
-  }
-  static unsigned getHashValue(const clang::clangd::SymbolID &Sym) {
-return hash_value(Sym);
-  }
-  static bool isEqual(const clang::clangd::SymbolID &LHS,
-  const clang::clangd::SymbolID &RHS) {
-return LHS == RHS;
-  }
-};
-} // namespace llvm
-namespace clang {
-namespace clangd {
-
 // Describes the source of information about a symbol.
 // Mainly useful for debugging, e.g. understanding code completion reuslts.
 // This is a bitfield as information can be combined from several sources.

Modified: clang-tools-extra/trunk/clangd/index/SymbolID.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolID.h?rev=355081&r1=355080&r2=355081&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolID.h (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolID.h Thu Feb 28 03:00:44 2019
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOLID_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOLID_H
 
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
@@ -61,4 +62,25 @@ llvm::raw_ostream &operator<<(llvm::raw_
 } // namespace clangd
 } // namespace clang
 
+namespace llvm {
+// Support SymbolIDs as DenseMap keys.
+template <> struct DenseMapInfo {
+  static inline clang::clangd::SymbolID getEmptyKey() {
+static clang::clangd::SymbolID EmptyKey("EMPTYKEY");
+return EmptyKey;
+  }
+  static inline clang::clangd::SymbolID getTombstoneKey() {
+static clang::clangd::SymbolID TombstoneKey("TOMBSTONEKEY");
+return TombstoneKey;
+  }
+  static unsigned getHashValue(const clang::clangd::SymbolID &Sym) {
+return hash_value(Sym);
+  }
+  static bool isEqual(const clang::clangd::SymbolID &LHS,
+  const clang::clangd::SymbolID &RHS) {
+return LHS == RHS;
+  }
+};
+} // namespace llvm
+
 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOLID_H


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


[clang-tools-extra] r355082 - Moved SymbolLocation into its own header and implementation file

2019-02-28 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Feb 28 03:02:01 2019
New Revision: 355082

URL: http://llvm.org/viewvc/llvm-project?rev=355082&view=rev
Log:
Moved SymbolLocation into its own header and implementation file

Reviewers: ioeric

Subscribers: mgorny, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Added:
clang-tools-extra/trunk/clangd/index/SymbolLocation.cpp
clang-tools-extra/trunk/clangd/index/SymbolLocation.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/Serialization.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=355082&r1=355081&r2=355082&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Feb 28 03:02:01 2019
@@ -63,6 +63,7 @@ add_clang_library(clangDaemon
   index/MemIndex.cpp
   index/Merge.cpp
   index/SymbolID.cpp
+  index/SymbolLocation.cpp
   index/Serialization.cpp
   index/SymbolCollector.cpp
   index/YAMLSerialization.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=355082&r1=355081&r2=355082&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Thu Feb 28 03:02:01 2019
@@ -10,8 +10,8 @@
 #include "Logger.h"
 #include "SourceCode.h"
 #include "URI.h"
-#include "index/Index.h"
 #include "index/Merge.h"
+#include "index/SymbolLocation.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Index/IndexDataConsumer.h"

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=355082&r1=355081&r2=355082&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Thu Feb 28 03:02:01 2019
@@ -16,30 +16,6 @@
 namespace clang {
 namespace clangd {
 
-constexpr uint32_t SymbolLocation::Position::MaxLine;
-constexpr uint32_t SymbolLocation::Position::MaxColumn;
-void SymbolLocation::Position::setLine(uint32_t L) {
-  if (L > MaxLine) {
-Line = MaxLine;
-return;
-  }
-  Line = L;
-}
-void SymbolLocation::Position::setColumn(uint32_t Col) {
-  if (Col > MaxColumn) {
-Column = MaxColumn;
-return;
-  }
-  Column = Col;
-}
-
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolLocation &L) {
-  if (!L)
-return OS << "(none)";
-  return OS << L.FileURI << "[" << L.Start.line() << ":" << L.Start.column()
-<< "-" << L.End.line() << ":" << L.End.column() << ")";
-}
-
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SymbolOrigin O) {
   if (O == SymbolOrigin::Unknown)
 return OS << "unknown";

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=355082&r1=355081&r2=355082&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Thu Feb 28 03:02:01 2019
@@ -11,6 +11,7 @@
 
 #include "ExpectedTypes.h"
 #include "SymbolID.h"
+#include "SymbolLocation.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/ADT/DenseMap.h"
@@ -30,70 +31,6 @@
 namespace clang {
 namespace clangd {
 
-struct SymbolLocation {
-  // Specify a position (Line, Column) of symbol. Using Line/Column allows us 
to
-  // build LSP responses without reading the file content.
-  //
-  // Position is encoded into 32 bits to save space.
-  // If Line/Column overflow, the value will be their maximum value.
-  struct Position {
-Position() : Line(0), Column(0) {}
-void setLine(uint32_t Line);
-uint32_t line() const { return Line; }
-void setColumn(uint32_t Column);
-uint32_t column() const { return Column; }
-
-bool hasOverflow() const {
-  return Line >= MaxLine || Column >= MaxColumn;
-}
-
-static constexpr uint32_t MaxLine = (1 << 20) - 1;
-static constexpr uint32_t MaxColumn = (1 << 12) - 1;
-
-  private:
-uint32_t Line : 20; // 0-based
-// Using U

[clang-tools-extra] r355086 - Moved SymbolOrigin into its own header and implementation file

2019-02-28 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Feb 28 04:31:49 2019
New Revision: 355086

URL: http://llvm.org/viewvc/llvm-project?rev=355086&view=rev
Log:
Moved SymbolOrigin into its own header and implementation file

Reviewers: ioeric

Subscribers: mgorny, jkorous, arphaman, kadircet, jdoerfert, cfe-commits

Tags: #clang

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

Added:
clang-tools-extra/trunk/clangd/index/SymbolOrigin.cpp
clang-tools-extra/trunk/clangd/index/SymbolOrigin.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.h
clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=355086&r1=355085&r2=355086&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Feb 28 04:31:49 2019
@@ -62,10 +62,11 @@ add_clang_library(clangDaemon
   index/IndexAction.cpp
   index/MemIndex.cpp
   index/Merge.cpp
-  index/SymbolID.cpp
-  index/SymbolLocation.cpp
   index/Serialization.cpp
   index/SymbolCollector.cpp
+  index/SymbolID.cpp
+  index/SymbolLocation.cpp
+  index/SymbolOrigin.cpp
   index/YAMLSerialization.cpp
 
   index/dex/Dex.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=355086&r1=355085&r2=355086&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.h (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.h Thu Feb 28 04:31:49 2019
@@ -21,6 +21,7 @@
 #include "Path.h"
 #include "Protocol.h"
 #include "index/Index.h"
+#include "index/SymbolOrigin.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/CodeCompleteOptions.h"

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=355086&r1=355085&r2=355086&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Thu Feb 28 04:31:49 2019
@@ -14,6 +14,7 @@
 #include "index/Index.h"
 #include "index/MemIndex.h"
 #include "index/Merge.h"
+#include "index/SymbolOrigin.h"
 #include "index/dex/Dex.h"
 #include "clang/Index/IndexingAction.h"
 #include "clang/Lex/MacroInfo.h"

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=355086&r1=355085&r2=355086&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Thu Feb 28 04:31:49 2019
@@ -16,16 +16,6 @@
 namespace clang {
 namespace clangd {
 
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SymbolOrigin O) {
-  if (O == SymbolOrigin::Unknown)
-return OS << "unknown";
-  constexpr static char Sigils[] = "ADSM4567";
-  for (unsigned I = 0; I < sizeof(Sigils); ++I)
-if (static_cast(O) & 1u << I)
-  OS << Sigils[I];
-  return OS;
-}
-
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, Symbol::SymbolFlag F) {
   if (F == Symbol::None)
 return OS << "None";

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=355086&r1=355085&r2=355086&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Thu Feb 28 04:31:49 2019
@@ -12,6 +12,7 @@
 #include "ExpectedTypes.h"
 #include "SymbolID.h"
 #include "SymbolLocation.h"
+#include "SymbolOrigin.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/ADT/DenseMap.h"
@@ -31,30 +32,6 @@
 namespace clang {
 namespace clangd {
 
-// Describes the source of information about a symbol.
-// Mainly useful for debugging, e.g. understanding code completion reuslts.
-// This is a bitfield as information can be combined from several sources.
-enum class SymbolOrigin : uint8_t {
-  Unknown = 0,
-  AST = 1 << 0, // Directly from the

[clang-tools-extra] r355088 - Moved Symbol into its own header and implementation file

2019-02-28 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Feb 28 05:23:03 2019
New Revision: 355088

URL: http://llvm.org/viewvc/llvm-project?rev=355088&view=rev
Log:
Moved Symbol into its own header and implementation file

Reviewers: ioeric

Subscribers: mgorny, jkorous, arphaman, kadircet, jdoerfert, cfe-commits

Tags: #clang

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

Added:
clang-tools-extra/trunk/clangd/index/Symbol.cpp
clang-tools-extra/trunk/clangd/index/Symbol.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/Headers.h
clang-tools-extra/trunk/clangd/IncludeFixer.cpp
clang-tools-extra/trunk/clangd/IncludeFixer.h
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/Serialization.h

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=355088&r1=355087&r2=355088&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Feb 28 05:23:03 2019
@@ -63,6 +63,7 @@ add_clang_library(clangDaemon
   index/MemIndex.cpp
   index/Merge.cpp
   index/Serialization.cpp
+  index/Symbol.cpp
   index/SymbolCollector.cpp
   index/SymbolID.cpp
   index/SymbolLocation.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=355088&r1=355087&r2=355088&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Feb 28 05:23:03 2019
@@ -34,6 +34,7 @@
 #include "Trace.h"
 #include "URI.h"
 #include "index/Index.h"
+#include "index/Symbol.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/Basic/LangOptions.h"

Modified: clang-tools-extra/trunk/clangd/CodeComplete.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=355088&r1=355087&r2=355088&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.h (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.h Thu Feb 28 05:23:03 2019
@@ -21,6 +21,7 @@
 #include "Path.h"
 #include "Protocol.h"
 #include "index/Index.h"
+#include "index/Symbol.h"
 #include "index/SymbolOrigin.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Sema/CodeCompleteConsumer.h"

Modified: clang-tools-extra/trunk/clangd/Headers.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=355088&r1=355087&r2=355088&view=diff
==
--- clang-tools-extra/trunk/clangd/Headers.h (original)
+++ clang-tools-extra/trunk/clangd/Headers.h Thu Feb 28 05:23:03 2019
@@ -12,7 +12,7 @@
 #include "Path.h"
 #include "Protocol.h"
 #include "SourceCode.h"
-#include "index/Index.h"
+#include "index/Symbol.h"
 #include "clang/Format/Format.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/PPCallbacks.h"

Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=355088&r1=355087&r2=355088&view=diff
==
--- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Thu Feb 28 05:23:03 2019
@@ -13,6 +13,7 @@
 #include "SourceCode.h"
 #include "Trace.h"
 #include "index/Index.h"
+#include "index/Symbol.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/NestedNameSpecifier.h"

Modified: clang-tools-extra/trunk/clangd/IncludeFixer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.h?rev=355088&r1=355087&r2=355088&view=diff
==
--- clang-tools-extra/trunk/clangd/IncludeFixer.h (original)
+++ clang-tools-extra/trunk/clangd/IncludeFixer.h Thu Feb 28 05:23:03 2019
@@ -12,6 +12,7 @@
 #include "Diagnostics.h"
 #include "Headers.h"
 #include "index/Index.h"
+#include "index/Symbol.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceLocation.h"

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Back

[clang-tools-extra] r355090 - Moved Ref into its own header and implementation file

2019-02-28 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Feb 28 05:49:25 2019
New Revision: 355090

URL: http://llvm.org/viewvc/llvm-project?rev=355090&view=rev
Log:
Moved Ref into its own header and implementation file

Reviewers: ioeric

Subscribers: mgorny, jkorous, mgrang, arphaman, kadircet, cfe-commits

Tags: #clang

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

Added:
clang-tools-extra/trunk/clangd/index/Ref.cpp
clang-tools-extra/trunk/clangd/index/Ref.h
Modified:
clang-tools-extra/trunk/clangd/AST.h
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/IncludeFixer.cpp
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp

Modified: clang-tools-extra/trunk/clangd/AST.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.h?rev=355090&r1=355089&r2=355090&view=diff
==
--- clang-tools-extra/trunk/clangd/AST.h (original)
+++ clang-tools-extra/trunk/clangd/AST.h Thu Feb 28 05:49:25 2019
@@ -13,9 +13,10 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_AST_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_AST_H_
 
-#include "index/Index.h"
+#include "index/SymbolID.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/MacroInfo.h"
 
 namespace clang {
 class SourceManager;

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=355090&r1=355089&r2=355090&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Feb 28 05:49:25 2019
@@ -62,6 +62,7 @@ add_clang_library(clangDaemon
   index/IndexAction.cpp
   index/MemIndex.cpp
   index/Merge.cpp
+  index/Ref.cpp
   index/Serialization.cpp
   index/Symbol.cpp
   index/SymbolCollector.cpp

Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=355090&r1=355089&r2=355090&view=diff
==
--- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Thu Feb 28 05:49:25 2019
@@ -24,6 +24,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Scope.h"

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=355090&r1=355089&r2=355090&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Thu Feb 28 05:49:25 2019
@@ -13,7 +13,6 @@
 #include "Protocol.h"
 #include "Logger.h"
 #include "URI.h"
-#include "index/Index.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallString.h"

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=355090&r1=355089&r2=355090&view=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Thu Feb 28 05:49:25 2019
@@ -5,11 +5,12 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 
//===--===//
+
 #include "Quality.h"
 #include "AST.h"
 #include "FileDistance.h"
 #include "URI.h"
-#include "index/Index.h"
+#include "index/Symbol.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"

Modified: clang-tools-extra/trunk/clangd/index/Index.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.cpp?rev=355090&r1=355089&r2=355090&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Index.cpp Thu Feb 28 05:49:25 2019
@@ -12,57 +12,11 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 namespace clang {
 namespace clangd {
 
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, RefKind K) {
-  if (K == RefKind::Unknown)
-return OS << "Unknown";
-  static const std:

[clang-tools-extra] r355091 - Use ArrayRef::copy, instead of copying data manually

2019-02-28 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Feb 28 06:00:26 2019
New Revision: 355091

URL: http://llvm.org/viewvc/llvm-project?rev=355091&view=rev
Log:
Use ArrayRef::copy, instead of copying data manually

Reviewers: ioeric

Subscribers: jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/index/Ref.cpp

Modified: clang-tools-extra/trunk/clangd/index/Ref.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Ref.cpp?rev=355091&r1=355090&r2=355091&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Ref.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Ref.cpp Thu Feb 28 06:00:26 2019
@@ -51,9 +51,7 @@ RefSlab RefSlab::Builder::build() && {
 SymRefs.erase(std::unique(SymRefs.begin(), SymRefs.end()), SymRefs.end());
 
 NumRefs += SymRefs.size();
-auto *Array = Arena.Allocate(SymRefs.size());
-std::uninitialized_copy(SymRefs.begin(), SymRefs.end(), Array);
-Result.emplace_back(Sym.first, llvm::ArrayRef(Array, SymRefs.size()));
+Result.emplace_back(Sym.first, llvm::ArrayRef(SymRefs).copy(Arena));
   }
   return RefSlab(std::move(Result), std::move(Arena), NumRefs);
 }


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


[clang-tools-extra] r355092 - Added missing license headers

2019-02-28 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Feb 28 06:01:11 2019
New Revision: 355092

URL: http://llvm.org/viewvc/llvm-project?rev=355092&view=rev
Log:
Added missing license headers

Reviewers: ioeric

Subscribers: jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/ExpectedTypes.cpp
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/xpc/framework/ClangdXPC.cpp
clang-tools-extra/trunk/clangd/xpc/test-client/ClangdXPCTestClient.cpp

Modified: clang-tools-extra/trunk/clangd/ExpectedTypes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ExpectedTypes.cpp?rev=355092&r1=355091&r2=355092&view=diff
==
--- clang-tools-extra/trunk/clangd/ExpectedTypes.cpp (original)
+++ clang-tools-extra/trunk/clangd/ExpectedTypes.cpp Thu Feb 28 06:01:11 2019
@@ -1,3 +1,11 @@
+//===--- ExpectedTypes.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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
 #include "ExpectedTypes.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Type.h"

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.cpp?rev=355092&r1=355091&r2=355092&view=diff
==
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp Thu Feb 28 06:01:11 
2019
@@ -1,5 +1,12 @@
-#include "IndexAction.h"
+//===--- IndexAction.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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
 
+#include "IndexAction.h"
 #include "index/SymbolOrigin.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Index/IndexDataConsumer.h"

Modified: clang-tools-extra/trunk/clangd/xpc/framework/ClangdXPC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/xpc/framework/ClangdXPC.cpp?rev=355092&r1=355091&r2=355092&view=diff
==
--- clang-tools-extra/trunk/clangd/xpc/framework/ClangdXPC.cpp (original)
+++ clang-tools-extra/trunk/clangd/xpc/framework/ClangdXPC.cpp Thu Feb 28 
06:01:11 2019
@@ -1,3 +1,10 @@
+//===--- ClangXPC.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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
 
 /// Returns the bundle identifier of the Clangd XPC service.
 extern "C" const char *clangd_xpc_get_bundle_identifier() {

Modified: clang-tools-extra/trunk/clangd/xpc/test-client/ClangdXPCTestClient.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/xpc/test-client/ClangdXPCTestClient.cpp?rev=355092&r1=355091&r2=355092&view=diff
==
--- clang-tools-extra/trunk/clangd/xpc/test-client/ClangdXPCTestClient.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/xpc/test-client/ClangdXPCTestClient.cpp Thu 
Feb 28 06:01:11 2019
@@ -1,3 +1,11 @@
+//===--- ClangXPCTestClient.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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
 #include "xpc/Conversion.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/SmallString.h"


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


r355395 - [ASTMatchers] Improved formatting in a documentation comment

2019-03-05 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Tue Mar  5 04:38:18 2019
New Revision: 355395

URL: http://llvm.org/viewvc/llvm-project?rev=355395&view=rev
Log:
[ASTMatchers] Improved formatting in a documentation comment

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=355395&r1=355394&r2=355395&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Tue Mar  5 
04:38:18 2019
@@ -1547,8 +1547,7 @@ inline bool ValueEqualsMatcher record;
+///   const VariadicDynCastAllOfMatcher record;
 /// Creates a functor record(...) that creates a Matcher given
 /// a variable number of arguments of type Matcher.
 /// The returned matcher matches if the given Decl can by dynamically


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


r358134 - Check i < FD->getNumParams() before querying

2019-04-10 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Apr 10 13:25:07 2019
New Revision: 358134

URL: http://llvm.org/viewvc/llvm-project?rev=358134&view=rev
Log:
Check i < FD->getNumParams() before querying

Summary:
As was already stated in a previous comment, the parameter isn't
necessarily referring to one of the DeclContext's parameter. We
should check the index is within the range to avoid out-of-boundary
access.

Reviewers: gribozavr, rsmith, lebedev.ri

Reviewed By: gribozavr, rsmith

Subscribers: lebedev.ri, cfe-commits

Tags: #clang

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

Patch by Violet.

Added:
cfe/trunk/test/SemaCXX/PR41139.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=358134&r1=358133&r2=358134&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Apr 10 13:25:07 2019
@@ -2892,7 +2892,7 @@ static const Decl *getCanonicalParmVarDe
   unsigned i = PV->getFunctionScopeIndex();
   // This parameter might be from a freestanding function type within the
   // function and isn't necessarily referring to one of FD's parameters.
-  if (FD->getParamDecl(i) == PV)
+  if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
 return FD->getCanonicalDecl()->getParamDecl(i);
 }
   }

Added: cfe/trunk/test/SemaCXX/PR41139.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR41139.cpp?rev=358134&view=auto
==
--- cfe/trunk/test/SemaCXX/PR41139.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR41139.cpp Wed Apr 10 13:25:07 2019
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+
+// expected-no-diagnostics
+
+// This test should not crash.
+int f1( unsigned ) { return 0; }
+
+template 
+struct S1 {
+S1( R(*f)(Args...) ) {}
+};
+
+int main() {
+S1 s1( f1 );
+}

Modified: cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp?rev=358134&r1=358133&r2=358134&view=diff
==
--- cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-generic-lambdas.cpp Wed Apr 10 13:25:07 2019
@@ -944,6 +944,15 @@ namespace PR22117 {
   }(0)(0);
 }
 
+namespace PR41139 {
+  int y = [](auto outer) {
+return [](auto inner) {
+  using T = int(decltype(outer), decltype(inner));
+  return 0;
+};
+  }(0)(0);
+}
+
 namespace PR23716 {
 template
 auto f(T x) {


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


r359876 - Added an AST matcher for declarations that are in the `std` namespace

2019-05-03 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri May  3 05:50:00 2019
New Revision: 359876

URL: http://llvm.org/viewvc/llvm-project?rev=359876&view=rev
Log:
Added an AST matcher for declarations that are in the `std` namespace

Reviewers: alexfh

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=359876&r1=359875&r2=359876&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Fri May  3 05:50:00 2019
@@ -2827,6 +2827,29 @@ by the compiler (eg. implicit default/co
 
 
 
+MatcherDecl>isInStdNamespace
+Matches 
declarations in the namespace `std`, but not in nested namespaces.
+
+Given
+  class vector {};
+  namespace foo {
+class vector {};
+namespace std {
+  class vector {};
+}
+  }
+  namespace std {
+inline namespace __1 {
+  class vector {}; // #1
+  namespace experimental {
+class vector {};
+  }
+}
+  }
+cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
+
+
+
 MatcherDecl>isPrivate
 Matches private C++ 
declarations.
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=359876&r1=359875&r2=359876&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri May  3 05:50:00 2019
@@ -6212,6 +6212,29 @@ AST_MATCHER(NamespaceDecl, isAnonymous)
   return Node.isAnonymousNamespace();
 }
 
+/// Matches declarations in the namespace `std`, but not in nested namespaces.
+///
+/// Given
+/// \code
+///   class vector {};
+///   namespace foo {
+/// class vector {};
+/// namespace std {
+///   class vector {};
+/// }
+///   }
+///   namespace std {
+/// inline namespace __1 {
+///   class vector {}; // #1
+///   namespace experimental {
+/// class vector {};
+///   }
+/// }
+///   }
+/// \endcode
+/// cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
+AST_MATCHER(Decl, isInStdNamespace) { return Node.isInStdNamespace(); }
+
 /// If the given case statement does not use the GNU case range
 /// extension, matches the constant given in the statement.
 ///

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=359876&r1=359875&r2=359876&view=diff
==
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Fri May  3 05:50:00 2019
@@ -354,7 +354,8 @@ bool Decl::isInAnonymousNamespace() cons
 }
 
 bool Decl::isInStdNamespace() const {
-  return getDeclContext()->isStdNamespace();
+  const DeclContext *DC = getDeclContext();
+  return DC && DC->isStdNamespace();
 }
 
 TranslationUnitDecl *Decl::getTranslationUnitDecl() {

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=359876&r1=359875&r2=359876&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Fri May  3 05:50:00 2019
@@ -366,6 +366,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(isExternC);
   REGISTER_MATCHER(isFinal);
   REGISTER_MATCHER(isImplicit);
+  REGISTER_MATCHER(isInStdNamespace);
   REGISTER_MATCHER(isInTemplateInstantiation);
   REGISTER_MATCHER(isInline);
   REGISTER_MATCHER(isInstanceMessage);

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=359876&r1=359875&r2=359876&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Fri May  3 
05:50:00 2019
@@ -2031,6 +2031,57 @@ TEST(NS, Anonymous) {
   EXPECT_TRUE(matches("namespace {}", namespaceDecl(isAnonymous(;
 }
 
+TEST(DeclarationMatcher, InStdNamespace) {
+  EXPECT_TRUE(notMatches("class vector {};"
+   

[clang-tools-extra] r359876 - Added an AST matcher for declarations that are in the `std` namespace

2019-05-03 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri May  3 05:50:00 2019
New Revision: 359876

URL: http://llvm.org/viewvc/llvm-project?rev=359876&view=rev
Log:
Added an AST matcher for declarations that are in the `std` namespace

Reviewers: alexfh

Subscribers: cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/InaccurateEraseCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/InaccurateEraseCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/InaccurateEraseCheck.cpp?rev=359876&r1=359875&r2=359876&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/InaccurateEraseCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/InaccurateEraseCheck.cpp Fri 
May  3 05:50:00 2019
@@ -17,10 +17,6 @@ namespace clang {
 namespace tidy {
 namespace bugprone {
 
-namespace {
-AST_MATCHER(Decl, isInStdNamespace) { return Node.isInStdNamespace(); }
-}
-
 void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matchers for C++; the functionality currently does not
   // provide any benefit to other languages, despite being benign.


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


[clang-tools-extra] r360247 - Documentation for bugprone-inaccurate-erase: added an example of a bug that this checker catches

2019-05-08 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed May  8 05:02:31 2019
New Revision: 360247

URL: http://llvm.org/viewvc/llvm-project?rev=360247&view=rev
Log:
Documentation for bugprone-inaccurate-erase: added an example of a bug that 
this checker catches

Reviewers: alexfh

Subscribers: cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst?rev=360247&r1=360246&r2=360247&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst 
(original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst 
Wed May  8 05:02:31 2019
@@ -11,3 +11,19 @@ container but return an iterator to the
 of the container. These redundant elements must be removed using the
 ``erase()`` method. This check warns when not all of the elements will be
 removed due to using an inappropriate overload.
+
+For example, the following code erases only one element:
+
+.. code-block:: c++
+
+  std::vector xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10));
+
+Call the two-argument overload of ``erase()`` to remove the subrange:
+
+.. code-block:: c++
+
+  std::vector xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10), xs.end());


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


[clang-tools-extra] r360358 - check_clang_tidy.py now passes `-format-style=none` to clang_tidy

2019-05-09 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu May  9 10:08:10 2019
New Revision: 360358

URL: http://llvm.org/viewvc/llvm-project?rev=360358&view=rev
Log:
check_clang_tidy.py now passes `-format-style=none` to clang_tidy

Summary:
If the test does not specify a formatting style, force "none"; otherwise
autodetection logic can discover a ".clang-tidy" file that is not
related to the test.

Reviewers: alexfh

Subscribers: cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=360358&r1=360357&r2=360358&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Thu May  9 
10:08:10 2019
@@ -69,20 +69,32 @@ def main():
   temp_file_name = temp_file_name + extension
 
   clang_tidy_extra_args = extra_args
-  if len(clang_tidy_extra_args) == 0:
-clang_tidy_extra_args = ['--']
+  clang_extra_args = []
+  if '--' in extra_args:
+i = clang_tidy_extra_args.index('--')
+clang_extra_args = clang_tidy_extra_args[i + 1:]
+clang_tidy_extra_args = clang_tidy_extra_args[:i]
+
+  # If the test does not specify a formatting style, force "none"; otherwise
+  # autodetection logic can discover a ".clang-tidy" file that is not related 
to
+  # the test.
+  if not any(
+  [arg.startswith('-format-style=') for arg in clang_tidy_extra_args]):
+clang_tidy_extra_args.append('-format-style=none')
+
+  if len(clang_extra_args) == 0:
 if extension in ['.cpp', '.hpp', '.mm']:
-  clang_tidy_extra_args.append('--std=c++11')
+  clang_extra_args.append('--std=c++11')
 if extension in ['.m', '.mm']:
-  clang_tidy_extra_args.extend(
+  clang_extra_args.extend(
   ['-fobjc-abi-version=2', '-fobjc-arc'])
 
   # Tests should not rely on STL being available, and instead provide mock
   # implementations of relevant APIs.
-  clang_tidy_extra_args.append('-nostdinc++')
+  clang_extra_args.append('-nostdinc++')
 
   if resource_dir is not None:
-clang_tidy_extra_args.append('-resource-dir=%s' % resource_dir)
+clang_extra_args.append('-resource-dir=%s' % resource_dir)
 
   with open(input_file_name, 'r') as input_file:
 input_text = input_file.read()
@@ -138,7 +150,7 @@ def main():
   write_file(original_file_name, cleaned_test)
 
   args = ['clang-tidy', temp_file_name, '-fix', '--checks=-*,' + check_name] + 
\
-clang_tidy_extra_args
+  clang_tidy_extra_args + ['--'] + clang_extra_args
   if expect_clang_tidy_error:
 args.insert(0, 'not')
   print('Running ' + repr(args) + '...')


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


[clang-tools-extra] r354777 - Removed an unhelpful comment in index.rst

2019-02-25 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Feb 25 04:48:52 2019
New Revision: 354777

URL: http://llvm.org/viewvc/llvm-project?rev=354777&view=rev
Log:
Removed an unhelpful comment in index.rst

Reviewers: ilya-biryukov

Subscribers: arphaman, jdoerfert, cfe-commits

Tags: #clang

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

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

Modified: clang-tools-extra/trunk/docs/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/index.rst?rev=354777&r1=354776&r2=354777&view=diff
==
--- clang-tools-extra/trunk/docs/index.rst (original)
+++ clang-tools-extra/trunk/docs/index.rst Mon Feb 25 04:48:52 2019
@@ -1,8 +1,3 @@
-.. Extra Clang Tools documentation master file, created by
-   sphinx-quickstart on Wed Feb 13 10:00:18 2013.
-   You can adapt this file completely to your liking, but it should at least
-   contain the root `toctree` directive.
-
 .. title:: Welcome to Extra Clang Tools's documentation!
 
 Introduction


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


[clang-tools-extra] r354778 - Fixed grammar in index.rst

2019-02-25 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Feb 25 04:49:27 2019
New Revision: 354778

URL: http://llvm.org/viewvc/llvm-project?rev=354778&view=rev
Log:
Fixed grammar in index.rst

Subscribers: arphaman, cfe-commits

Tags: #clang

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

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

Modified: clang-tools-extra/trunk/docs/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/index.rst?rev=354778&r1=354777&r2=354778&view=diff
==
--- clang-tools-extra/trunk/docs/index.rst (original)
+++ clang-tools-extra/trunk/docs/index.rst Mon Feb 25 04:49:27 2019
@@ -3,7 +3,7 @@
 Introduction
 
 Welcome to the clang-tools-extra project which contains extra tools built using
-Clang's tooling API's.
+Clang's tooling APIs.
 
 .. toctree::
:maxdepth: 1


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


[clang-tools-extra] r354779 - Updated the documentation build instructions for the current CMake build system

2019-02-25 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Feb 25 05:03:44 2019
New Revision: 354779

URL: http://llvm.org/viewvc/llvm-project?rev=354779&view=rev
Log:
Updated the documentation build instructions for the current CMake build system

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/docs/README.txt

Modified: clang-tools-extra/trunk/docs/README.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/README.txt?rev=354779&r1=354778&r2=354779&view=diff
==
--- clang-tools-extra/trunk/docs/README.txt (original)
+++ clang-tools-extra/trunk/docs/README.txt Mon Feb 25 05:03:44 2019
@@ -1,11 +1,10 @@
--
-Documentation for the tools of clang-tools-extra repo project
--
+--
+Documentation in clang-tools-extra
+--
 
-Sphinx and doxygen documentation is generated by executing make.
+To generate documentation in HTML format from files in clang-tools-extra/docs,
+build the docs-clang-tools-html target.
 
-Sphinx html files can be generated separately using make html.
+To generate documentation from the source code using Doxygen, build the
+doxygen-clang-tools target.
 
-Doxygen html files can also be generated using make doxygen.
-
-The generated documentation will be placed in _build/html.


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


r354785 - Fixed typos in tests: s/CHEKC/CHECK/

2019-02-25 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Feb 25 05:41:59 2019
New Revision: 354785

URL: http://llvm.org/viewvc/llvm-project?rev=354785&view=rev
Log:
Fixed typos in tests: s/CHEKC/CHECK/

Reviewers: ilya-biryukov

Subscribers: nemanjai, javed.absar, jsji, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Modified:
cfe/trunk/test/CodeGenObjC/dllstorage.m
cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m

Modified: cfe/trunk/test/CodeGenObjC/dllstorage.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/dllstorage.m?rev=354785&r1=354784&r2=354785&view=diff
==
--- cfe/trunk/test/CodeGenObjC/dllstorage.m (original)
+++ cfe/trunk/test/CodeGenObjC/dllstorage.m Mon Feb 25 05:41:59 2019
@@ -85,7 +85,7 @@ __declspec(dllimport)
 }
 @end
 
-// CHEKC-FW-DAG: @_OBJC_CLASS_M = external dllimport global i32
+// CHECK-FW-DAG: @_OBJC_CLASS_M = external dllimport global i32
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
 

Modified: cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m?rev=354785&r1=354784&r2=354785&view=diff
==
--- cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m (original)
+++ cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m Mon Feb 25 05:41:59 
2019
@@ -5,7 +5,7 @@
 // to a protocol in a binary.
 
 // CHECK: @._OBJC_PROTOCOL_Y = global 
-// CHEKC-SAME: section "__objc_protocols", comdat, align 8
+// CHECK-SAME: section "__objc_protocols", comdat, align 8
 
 
 @interface X


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


[clang-tools-extra] r354786 - Moved clangd docs to a separate directory in preparation to restructure them into multiple files

2019-02-25 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Feb 25 05:43:48 2019
New Revision: 354786

URL: http://llvm.org/viewvc/llvm-project?rev=354786&view=rev
Log:
Moved clangd docs to a separate directory in preparation to restructure them 
into multiple files

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, jdoerfert, 
cfe-commits

Tags: #clang

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

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

Modified: clang-tools-extra/trunk/docs/clangd.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clangd.rst?rev=354786&r1=354785&r2=354786&view=diff
==
--- clang-tools-extra/trunk/docs/clangd.rst (original)
+++ clang-tools-extra/trunk/docs/clangd.rst Mon Feb 25 05:43:48 2019
@@ -1,180 +1,3 @@
-
-Clangd
-
+:orphan:
 
-.. contents::
-
-.. toctree::
-   :maxdepth: 1
-
-:program:`Clangd` is an implementation of the `Language Server Protocol
-`_ leveraging Clang.
-Clangd's goal is to provide language "smartness" features like code completion,
-find references, etc. for clients such as C/C++ Editors.
-
-Using Clangd
-==
-
-:program:`Clangd` is not meant to be used by C/C++ developers directly but
-rather from a client implementing the protocol. A client would be typically
-implemented in an IDE or an editor.
-
-At the moment, `Visual Studio Code `_ is mainly
-used in order to test :program:`Clangd` but more clients are likely to make
-use of :program:`Clangd` in the future as it matures and becomes a production
-quality tool. If you are interested in trying :program:`Clangd` in combination
-with Visual Studio Code, you can start by `installing Clangd`_ or
-`building Clangd`_, then open Visual Studio Code in the clangd-vscode folder 
and
-launch the extension.
-
-Installing Clangd
-==
-
-Packages are available for debian-based distributions, see the `LLVM packages
-page `_. :program:`Clangd` is included in the
-`clang-tools` package.
-However, it is a good idea to check your distribution's packaging system first
-as it might already be available.
-
-Otherwise, you can install :program:`Clangd` by `building Clangd`_ first.
-
-Building Clangd
-==
-
-You can follow the instructions for `building Clang
-`_ but "extra Clang tools" is **not**
-optional.
-
-Current Status
-==
-
-Many features could be implemented in :program:`Clangd`.
-Here is a list of features that could be useful with the status of whether or
-not they are already implemented in :program:`Clangd` and specified in the
-Language Server Protocol. Note that for some of the features, it is not clear
-whether or not they should be part of the Language Server Protocol, so those
-features might be eventually developed outside :program:`Clangd` or as an
-extension to the protocol.
-
-+-++--+
-| C/C++ Editor feature|  LSP   |  Clangd  |
-+=++==+
-| Formatting  | Yes|   Yes|
-+-++--+
-| Completion  | Yes|   Yes|
-+-++--+
-| Diagnostics | Yes|   Yes|
-+-++--+
-| Fix-its | Yes|   Yes|
-+-++--+
-| Go to Definition| Yes|   Yes|
-+-++--+
-| Signature Help  | Yes|   Yes|
-+-++--+
-| Document Highlights | Yes|   Yes|
-+-++--+
-| Rename  | Yes|   Yes|
-+-++--+
-| Source hover| Yes|   Yes|
-+-++--+
-| Find References | Yes|   No |
-+-++--+
-| Code Lens   | Yes|   No |
-+-++--+
-| Document Symbols| Yes|   Yes|
-+-++--+
-| Workspace Symbols   

[clang-tools-extra] r363047 - Fixed google-readability-casting test to work in c++17

2019-06-11 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Tue Jun 11 03:59:22 2019
New Revision: 363047

URL: http://llvm.org/viewvc/llvm-project?rev=363047&view=rev
Log:
Fixed google-readability-casting test to work in c++17

Summary: Fixed google-readability-casting.cpp to get tests working in c++17

Reviewers: gribozavr, hokein

Reviewed By: gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Patch by Shaurya Gupta.

Modified:
clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp

Modified: clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp?rev=363047&r1=363046&r2=363047&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp Tue Jun 
11 03:59:22 2019
@@ -86,6 +86,10 @@ void AvoidCStyleCastsCheck::check(const
   bool FnToFnCast =
   isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten);
 
+  const bool ConstructorCast = !CastExpr->getTypeAsWritten().hasQualifiers() &&
+  DestTypeAsWritten->isRecordType() &&
+  !DestTypeAsWritten->isElaboratedTypeSpecifier();
+
   if (CastExpr->getCastKind() == CK_NoOp && !FnToFnCast) {
 // Function pointer/reference casts may be needed to resolve ambiguities in
 // case of overloaded functions, so detection of redundant casts is 
trickier
@@ -144,19 +148,19 @@ void AvoidCStyleCastsCheck::check(const
 Diag << CastType;
 ReplaceWithCast((CastType + "<" + DestTypeString + ">").str());
   };
-
+  auto ReplaceWithConstructorCall = [&]() {
+Diag << "constructor call syntax";
+// FIXME: Validate DestTypeString, maybe.
+ReplaceWithCast(DestTypeString.str());
+  };
   // Suggest appropriate C++ cast. See [expr.cast] for cast notation semantics.
   switch (CastExpr->getCastKind()) {
   case CK_FunctionToPointerDecay:
 ReplaceWithNamedCast("static_cast");
 return;
   case CK_ConstructorConversion:
-if (!CastExpr->getTypeAsWritten().hasQualifiers() &&
-DestTypeAsWritten->isRecordType() &&
-!DestTypeAsWritten->isElaboratedTypeSpecifier()) {
-  Diag << "constructor call syntax";
-  // FIXME: Validate DestTypeString, maybe.
-  ReplaceWithCast(DestTypeString.str());
+if (ConstructorCast) {
+  ReplaceWithConstructorCall();
 } else {
   ReplaceWithNamedCast("static_cast");
 }
@@ -176,6 +180,10 @@ void AvoidCStyleCastsCheck::check(const
   ReplaceWithNamedCast("const_cast");
   return;
 }
+if (ConstructorCast) {
+  ReplaceWithConstructorCall();
+  return;
+}
 if (DestType->isReferenceType()) {
   QualType Dest = DestType.getNonReferenceType();
   QualType Source = SourceType.getNonReferenceType();

Modified: clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp?rev=363047&r1=363046&r2=363047&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp Tue 
Jun 11 03:59:22 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s google-readability-casting %t
+// RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t
 // FIXME: Fix the checker to work in C++17 mode.
 
 bool g() { return false; }


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


[clang-tools-extra] r363133 - Fixed a crash in misc-redundant-expression ClangTidy checker

2019-06-12 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Jun 12 01:40:53 2019
New Revision: 363133

URL: http://llvm.org/viewvc/llvm-project?rev=363133&view=rev
Log:
Fixed a crash in misc-redundant-expression ClangTidy checker

Summary: It was trying to pass a dependent expression into constant evaluator.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp?rev=363133&r1=363132&r2=363133&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp Wed 
Jun 12 01:40:53 2019
@@ -555,10 +555,14 @@ static bool areSidesBinaryConstExpressio
   if (!LhsBinOp || !RhsBinOp)
 return false;
 
-  if ((LhsBinOp->getLHS()->isIntegerConstantExpr(*AstCtx) ||
-   LhsBinOp->getRHS()->isIntegerConstantExpr(*AstCtx)) &&
-  (RhsBinOp->getLHS()->isIntegerConstantExpr(*AstCtx) ||
-   RhsBinOp->getRHS()->isIntegerConstantExpr(*AstCtx)))
+  auto IsIntegerConstantExpr = [AstCtx](const Expr *E) {
+return !E->isValueDependent() && E->isIntegerConstantExpr(*AstCtx);
+  };
+
+  if ((IsIntegerConstantExpr(LhsBinOp->getLHS()) ||
+   IsIntegerConstantExpr(LhsBinOp->getRHS())) &&
+  (IsIntegerConstantExpr(RhsBinOp->getLHS()) ||
+   IsIntegerConstantExpr(RhsBinOp->getRHS(
 return true;
   return false;
 }
@@ -580,12 +584,14 @@ static bool retrieveConstExprFromBothSid
   const auto *BinOpLhs = cast(BinOp->getLHS());
   const auto *BinOpRhs = cast(BinOp->getRHS());
 
-  LhsConst = BinOpLhs->getLHS()->isIntegerConstantExpr(*AstCtx)
- ? BinOpLhs->getLHS()
- : BinOpLhs->getRHS();
-  RhsConst = BinOpRhs->getLHS()->isIntegerConstantExpr(*AstCtx)
- ? BinOpRhs->getLHS()
- : BinOpRhs->getRHS();
+  auto IsIntegerConstantExpr = [AstCtx](const Expr *E) {
+return !E->isValueDependent() && E->isIntegerConstantExpr(*AstCtx);
+  };
+
+  LhsConst = IsIntegerConstantExpr(BinOpLhs->getLHS()) ? BinOpLhs->getLHS()
+   : BinOpLhs->getRHS();
+  RhsConst = IsIntegerConstantExpr(BinOpRhs->getLHS()) ? BinOpRhs->getLHS()
+   : BinOpRhs->getRHS();
 
   if (!LhsConst || !RhsConst)
 return false;

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp?rev=363133&r1=363132&r2=363133&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp Wed 
Jun 12 01:40:53 2019
@@ -84,6 +84,14 @@ int TestSimpleEquivalent(int X, int Y) {
   return 0;
 }
 
+template 
+int TestSimpleEquivalentDependent() {
+  if (DX > 0 && DX > 0) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: both sides of operator are 
equivalent
+
+  return 0;
+}
+
 int Valid(int X, int Y) {
   if (X != Y) return 1;
   if (X == Y + 0) return 1;
@@ -670,7 +678,7 @@ int TestWithMinMaxInt(int X) {
 #define FLAG3 4
 #define FLAGS (FLAG1 | FLAG2 | FLAG3)
 #define NOTFLAGS !(FLAG1 | FLAG2 | FLAG3)
-int operatorConfusion(int X, int Y, long Z)
+int TestOperatorConfusion(int X, int Y, long Z)
 {
   // Ineffective & expressions.
   Y = (Y << 8) & 0xff;
@@ -722,6 +730,12 @@ int operatorConfusion(int X, int Y, long
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: ineffective logical negation 
operator
   // CHECK-FIXES: {{^}}  return ~(1 | 2 | 4);{{$}}
 }
+
+template 
+int TestOperatorConfusionDependent(int Y) {
+  int r1 = (Y << Shift) & 0xff;
+  int r2 = (Y << 8) & Mask;
+}
 #undef FLAG1
 #undef FLAG2
 #undef FLAG3


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


r363262 - Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 06:48:24 2019
New Revision: 363262

URL: http://llvm.org/viewvc/llvm-project?rev=363262&view=rev
Log:
Added AST matcher for ignoring elidable constructors

Summary: Added AST matcher for ignoring elidable move constructors

Reviewers: hokein, gribozavr

Reviewed By: hokein, gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=363262&r1=363261&r2=363262&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Jun 13 06:48:24 2019
@@ -5728,6 +5728,32 @@ Example matches x (matcher = expr(hasTyp
 
 
 
+MatcherExpr>ignoringElidableConstructorCallast_matchers::MatcherExpr> 
InnerMatcher
+Matches expressions that match 
InnerMatcher that are possibly wrapped in an
+elidable constructor.
+
+In C++17 copy elidable constructors are no longer being
+generated in the AST as it is not permitted by the standard. They are
+however part of the AST in C++14 and earlier. Therefore, to write a matcher
+that works in all language modes, the matcher has to skip elidable
+constructor AST nodes if they appear in the AST. This matcher can be used to
+skip those elidable constructors.
+
+Given
+
+struct H {};
+H G();
+void f() {
+  H D = G();
+}
+
+``varDecl(hasInitializer(any(
+  ignoringElidableConstructorCall(callExpr()),
+  exprWithCleanups(ignoringElidableConstructorCall(callExpr()``
+matches ``H D = G()``
+
+
+
 MatcherExpr>ignoringImpCastsMatcherExpr> 
InnerMatcher
 Matches 
expressions that match InnerMatcher after any implicit casts
 are stripped off.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=363262&r1=363261&r2=363262&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Jun 13 06:48:24 2019
@@ -6452,6 +6452,44 @@ AST_MATCHER(FunctionDecl, hasTrailingRet
   return false;
 }
 
+/// Matches expressions that match InnerMatcher that are possibly wrapped in an
+/// elidable constructor.
+///
+/// In C++17 copy elidable constructors are no longer being
+/// generated in the AST as it is not permitted by the standard. They are
+/// however part of the AST in C++14 and earlier. Therefore, to write a matcher
+/// that works in all language modes, the matcher has to skip elidable
+/// constructor AST nodes if they appear in the AST. This matcher can be used 
to
+/// skip those elidable constructors.
+///
+/// Given
+///
+/// \code
+/// struct H {};
+/// H G();
+/// void f() {
+///   H D = G();
+/// }
+/// \endcode
+///
+/// ``varDecl(hasInitializer(any(
+///   ignoringElidableConstructorCall(callExpr()),
+///   exprWithCleanups(ignoringElidableConstructorCall(callExpr()``
+/// matches ``H D = G()``
+AST_MATCHER_P(Expr, ignoringElidableConstructorCall,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  if (const auto *CtorExpr = dyn_cast(&Node)) {
+if (CtorExpr->isElidable()) {
+  if (const auto *MaterializeTemp =
+  dyn_cast(CtorExpr->getArg(0))) {
+return InnerMatcher.matches(*MaterializeTemp->GetTemporaryExpr(),
+Finder, Builder);
+  }
+}
+  }
+  return InnerMatcher.matches(Node, Finder, Builder);
+}
+
 
////
 // OpenMP handling.
 
////

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=363262&r1=363261&r2=363262&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Thu Jun 13 06:48:24 2019
@@ -320,6 +320,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasUnqualifiedDesugaredType);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
+  REGI

[clang-tools-extra] r363263 - [clang-tidy] Fixed abseil-duration-unnecessary-conversion tests for c++17

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 06:52:45 2019
New Revision: 363263

URL: http://llvm.org/viewvc/llvm-project?rev=363263&view=rev
Log:
[clang-tidy] Fixed abseil-duration-unnecessary-conversion tests for c++17

Summary: Fixed abseil-duration-unnecessary-conversion tests for c++17

Reviewers: hokein, gribozavr

Reviewed By: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:

clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp?rev=363263&r1=363262&r2=363263&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
 Thu Jun 13 06:52:45 2019
@@ -30,10 +30,9 @@ void DurationUnnecessaryConversionCheck:
 
 // Matcher which matches the current scale's factory with a `1` argument,
 // e.g. `absl::Seconds(1)`.
-auto factory_matcher = cxxConstructExpr(hasArgument(
-0,
+auto factory_matcher = ignoringElidableConstructorCall(
 callExpr(callee(functionDecl(hasName(DurationFactory))),
- hasArgument(0, 
ignoringImpCasts(integerLiteral(equals(1)));
+ hasArgument(0, ignoringImpCasts(integerLiteral(equals(1));
 
 // Matcher which matches either inverse function and binds its argument,
 // e.g. `absl::ToDoubleSeconds(dur)`.

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp?rev=363263&r1=363262&r2=363263&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
 Thu Jun 13 06:52:45 2019
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s 
abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
 
 #include "absl/time/time.h"
 


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


[clang-tools-extra] r363270 - [clang-tidy] Made abseil-upgrade-duration-conversions tests pass on c++17

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 07:27:54 2019
New Revision: 363270

URL: http://llvm.org/viewvc/llvm-project?rev=363270&view=rev
Log:
[clang-tidy] Made abseil-upgrade-duration-conversions tests pass on c++17

Summary: Made abseil-upgrade-duration-conversions tests pass on c++17

Reviewers: hokein, gribozavr

Reviewed By: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:

clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp?rev=363270&r1=363269&r2=363270&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp 
Thu Jun 13 07:27:54 2019
@@ -40,7 +40,8 @@ void UpgradeDurationConversionsCheck::re
   callee(functionDecl(
   hasParent(functionTemplateDecl()),
   unless(hasTemplateArgument(0, refersToType(builtinType(,
-  hasAnyName("operator*=", "operator/=",
+  hasAnyName("operator*=", "operator/="
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a.operator*=(b)` and `a.operator/=(b)` where `a`
@@ -52,7 +53,8 @@ void UpgradeDurationConversionsCheck::re
   hasParent(functionTemplateDecl()),
   unless(hasTemplateArgument(0, refersToType(builtinType(,
   hasAnyName("operator*=", "operator/="))),
-  argumentCountIs(1), hasArgument(0, expr().bind("arg"))),
+  argumentCountIs(1), hasArgument(0, expr().bind("arg")))
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a * b`, `a / b`, `operator*(a, b)`, and
@@ -66,7 +68,8 @@ void UpgradeDurationConversionsCheck::re
argumentCountIs(2),
hasArgument(0, expr(hasType(
   
cxxRecordDecl(hasName("::absl::Duration"),
-   hasArgument(1, expr().bind("arg"))),
+   hasArgument(1, expr().bind("arg")))
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a * b` and `operator*(a, b)` where `a` is not of a
@@ -77,8 +80,9 @@ void UpgradeDurationConversionsCheck::re
unless(hasTemplateArgument(0, refersToType(builtinType(,
hasName("::absl::operator*"))),
argumentCountIs(2), hasArgument(0, expr().bind("arg")),
-   hasArgument(1, expr(hasType(cxxRecordDecl(
-  hasName("::absl::Duration")),
+   hasArgument(1, expr(hasType(
+  
cxxRecordDecl(hasName("::absl::Duration"))
+  .bind("OuterExpr"),
   this);
 
   // For the factory functions, we match only the non-templated overloads that
@@ -103,8 +107,9 @@ void UpgradeDurationConversionsCheck::re
 has(implicitCastExpr(hasCastKind(CK_UserDefinedConversion,
   hasParent(callExpr(
   callee(functionDecl(DurationFactoryFunction(),
-  unless(hasParent(functionTemplateDecl(),
-  hasArgument(0, expr().bind("arg"),
+  unless(hasParent(functionTemplateDecl(),
+  hasArgument(0, expr().bind("arg")
+  .bind("OuterExpr"),
   this);
 }
 
@@ -117,7 +122,10 @@ void UpgradeDurationConversionsCheck::ch
   const auto *ArgExpr = Result.Nodes.getNodeAs("arg");
   SourceLocation Loc = ArgExpr->getBeginLoc();
 
-  if (!match(isInTemplateInstantiation(), *ArgExpr, *Result.Context).empty()) {
+  const auto *OuterExpr = Result.Nodes.getNodeAs("OuterExpr");
+
+  if (!match(isInTemplateInstantiation(), *OuterExpr, *Result.Context)
+   .empty()) {
 if (MatchedTemplateLocations.count(Loc.getRawEncoding()) == 0) {
   // For each location matched in a template instantiation, we check if the
   // location can also be found in `MatchedTemplateLocations`. If it is not

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp?rev=363270&r1=363269&r2=363270&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp 
Thu Jun 13 07:27:54 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy

[clang-tools-extra] r363272 - [clang-tidy] Fixed abseil-time-subtraction to work on C++17

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 08:11:02 2019
New Revision: 363272

URL: http://llvm.org/viewvc/llvm-project?rev=363272&view=rev
Log:
[clang-tidy] Fixed abseil-time-subtraction to work on C++17

Summary: Fixed abseil-time-subtraction to work on C++17

Reviewers: hokein, gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp

Modified: clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp?rev=363272&r1=363271&r2=363272&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp Thu Jun 
13 08:11:02 2019
@@ -29,33 +29,52 @@ static bool InsideMacroDefinition(const
 
 static bool isConstructorAssignment(const MatchFinder::MatchResult &Result,
 const Expr *Node) {
+  // For C++14 and earlier there are elidable constructors that must be matched
+  // in hasParent. The elidable constructors do not exist in C++17 and later 
and
+  // therefore an additional check that does not match against the elidable
+  // constructors are needed for this case.
   return selectFirst(
- "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
- cxxConstructExpr(hasParent(exprWithCleanups(
- hasParent(varDecl()
-.bind("e"),
-*Node, *Result.Context)) != nullptr;
+ "e",
+ match(expr(anyOf(
+   callExpr(hasParent(materializeTemporaryExpr(hasParent(
+
cxxConstructExpr(hasParent(exprWithCleanups(
+hasParent(varDecl()
+   .bind("e"),
+   callExpr(hasParent(varDecl())).bind("e"))),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool isArgument(const MatchFinder::MatchResult &Result,
const Expr *Node) {
+  // For the same reason as in isConstructorAssignment two AST shapes need to 
be
+  // matched here.
   return selectFirst(
  "e",
- match(expr(hasParent(
-
materializeTemporaryExpr(hasParent(cxxConstructExpr(
-hasParent(callExpr()),
-unless(hasParent(cxxOperatorCallExpr(
-   .bind("e"),
-   *Node, *Result.Context)) != nullptr;
+ match(
+ expr(anyOf(
+ expr(hasParent(materializeTemporaryExpr(
+  hasParent(cxxConstructExpr(
+  hasParent(callExpr()),
+  unless(hasParent(cxxOperatorCallExpr(
+ .bind("e"),
+ expr(hasParent(callExpr()),
+  unless(hasParent(cxxOperatorCallExpr(
+ .bind("e"))),
+ *Node, *Result.Context)) != nullptr;
 }
 
 static bool isReturn(const MatchFinder::MatchResult &Result, const Expr *Node) 
{
+  // For the same reason as in isConstructorAssignment two AST shapes need to 
be
+  // matched here.
   return selectFirst(
- "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
- cxxConstructExpr(hasParent(exprWithCleanups(
- hasParent(returnStmt()
-.bind("e"),
-*Node, *Result.Context)) != nullptr;
+ "e",
+ match(expr(anyOf(
+   expr(hasParent(materializeTemporaryExpr(hasParent(
+cxxConstructExpr(hasParent(exprWithCleanups(
+hasParent(returnStmt()
+   .bind("e"),
+   expr(hasParent(returnStmt())).bind("e"))),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool parensRequired(const MatchFinder::MatchResult &Result,

Modified: clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp?rev=363272&r1=363271&r2=363272&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-ti

[clang-tools-extra] r363273 - [clang-tidy] Made abseil-faster-strsplit-delimiter tests pass on C++17

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 08:16:44 2019
New Revision: 363273

URL: http://llvm.org/viewvc/llvm-project?rev=363273&view=rev
Log:
[clang-tidy] Made abseil-faster-strsplit-delimiter tests pass on C++17

Reviewers: hokein, gribozavr

Reviewed By: hokein, gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp?rev=363273&r1=363272&r2=363273&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp 
Thu Jun 13 08:16:44 2019
@@ -20,21 +20,6 @@ namespace {
 
 AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
 
-::internal::Matcher
-constructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  auto ConstrExpr = cxxConstructExpr(hasType(recordDecl(hasName(ClassName))),
- hasArgument(0, ignoringParenCasts(Arg)));
-
-  return anyOf(ConstrExpr, cxxBindTemporaryExpr(has(ConstrExpr)));
-}
-
-::internal::Matcher
-copyConstructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  return constructExprWithArg(ClassName, constructExprWithArg(ClassName, Arg));
-}
-
 llvm::Optional makeCharacterLiteral(const StringLiteral *Literal) 
{
   std::string Result;
   {
@@ -74,11 +59,17 @@ void FasterStrsplitDelimiterCheck::regis
 
   // Binds to a string_view (either absl or std) that was passed by value and
   // contructed from string literal.
-  auto StringViewArg =
-  copyConstructExprWithArg("::absl::string_view", SingleChar);
+  auto StringViewArg = ignoringElidableConstructorCall(ignoringImpCasts(
+  cxxConstructExpr(hasType(recordDecl(hasName("::absl::string_view"))),
+   hasArgument(0, ignoringParenImpCasts(SingleChar);
 
+  // Need to ignore the elidable constructor as otherwise there is no match for
+  // c++14 and earlier.
   auto ByAnyCharArg =
-  expr(copyConstructExprWithArg("::absl::ByAnyChar", StringViewArg))
+  expr(has(ignoringElidableConstructorCall(
+   ignoringParenCasts(cxxBindTemporaryExpr(has(cxxConstructExpr(
+   hasType(recordDecl(hasName("::absl::ByAnyChar"))),
+   hasArgument(0, StringViewArg
   .bind("ByAnyChar");
 
   // Find uses of absl::StrSplit(..., "x") and absl::StrSplit(...,

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp?rev=363273&r1=363272&r2=363273&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp 
Thu Jun 13 08:16:44 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-faster-strsplit-delimiter 
%t
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-faster-strsplit-delimiter %t
 // FIXME: Fix the checker to work in C++17 mode.
 
 namespace absl {


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


r367809 - Adds a warning when an inline Doxygen comment has no argument

2019-08-05 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Aug  5 01:05:16 2019
New Revision: 367809

URL: http://llvm.org/viewvc/llvm-project?rev=367809&view=rev
Log:
Adds a warning when an inline Doxygen comment has no argument

Summary:
It warns for for comments like
/** \pre \em */

where \em has no argument

This warning is enabled with the -Wdocumentation option.

Reviewers: gribozavr, rsmith

Reviewed By: gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Patch by Mark de Wever.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td
cfe/trunk/lib/AST/CommentParser.cpp
cfe/trunk/test/Sema/warn-documentation.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td?rev=367809&r1=367808&r2=367809&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td Mon Aug  5 01:05:16 
2019
@@ -153,6 +153,12 @@ def warn_doc_deprecated_not_sync : Warni
 def note_add_deprecation_attr : Note<
   "add a deprecation attribute to the declaration to silence this warning">;
 
+// inline contents commands
+
+def warn_doc_inline_contents_no_argument : Warning<
+  "'%select{\\|@}0%1' command does not have an argument">,
+  InGroup, DefaultIgnore;
+
 // verbatim block commands
 
 def warn_verbatim_block_end_without_start : Warning<

Modified: cfe/trunk/lib/AST/CommentParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentParser.cpp?rev=367809&r1=367808&r2=367809&view=diff
==
--- cfe/trunk/lib/AST/CommentParser.cpp (original)
+++ cfe/trunk/lib/AST/CommentParser.cpp Mon Aug  5 01:05:16 2019
@@ -422,6 +422,12 @@ InlineCommandComment *Parser::parseInlin
 IC = S.actOnInlineCommand(CommandTok.getLocation(),
   CommandTok.getEndLocation(),
   CommandTok.getCommandID());
+
+Diag(CommandTok.getEndLocation().getLocWithOffset(1),
+ diag::warn_doc_inline_contents_no_argument)
+<< CommandTok.is(tok::at_command)
+<< Traits.getCommandInfo(CommandTok.getCommandID())->Name
+<< SourceRange(CommandTok.getLocation(), CommandTok.getEndLocation());
   }
 
   Retokenizer.putBackLeftoverTokens();

Modified: cfe/trunk/test/Sema/warn-documentation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=367809&r1=367808&r2=367809&view=diff
==
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation.cpp Mon Aug  5 01:05:16 2019
@@ -1044,6 +1044,48 @@ template <>
 template 
 void test_attach38::test_attach39(int, B);
 
+// The inline comments expect a string after the command.
+// expected-warning@+1 {{'\a' command does not have an argument}}
+/// \a
+int test_inline_no_argument_a_bad(int);
+
+/// \a A
+int test_inline_no_argument_a_good(int);
+
+// expected-warning@+1 {{'@b' command does not have an argument}}
+/// @b
+int test_inline_no_argument_b_bad(int);
+
+/// @b A
+int test_inline_no_argument_b_good(int);
+
+// expected-warning@+1 {{'\c' command does not have an argument}}
+/// \c
+int test_inline_no_argument_c_bad(int);
+
+/// \c A
+int test_inline_no_argument_c_good(int);
+
+// expected-warning@+1 {{'\e' command does not have an argument}}
+/// \e
+int test_inline_no_argument_e_bad(int);
+
+/// \e A
+int test_inline_no_argument_e_good(int);
+
+// expected-warning@+1 {{'\em' command does not have an argument}}
+/// \em
+int test_inline_no_argument_em_bad(int);
+
+/// \em A
+int test_inline_no_argument_em_good(int);
+
+// expected-warning@+1 {{'\p' command does not have an argument}}
+/// \p
+int test_inline_no_argument_p_bad(int);
+
+/// \p A
+int test_inline_no_argument_p_good(int);
 
 // PR13411, reduced.  We used to crash on this.
 /**


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


r368132 - Remove inclusion of a private gmock header from a test

2019-08-07 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Aug  7 01:16:29 2019
New Revision: 368132

URL: http://llvm.org/viewvc/llvm-project?rev=368132&view=rev
Log:
Remove inclusion of a private gmock header from a test

Modified:
cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp

Modified: cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp?rev=368132&r1=368131&r2=368132&view=diff
==
--- cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp Wed Aug  7 01:16:29 2019
@@ -14,7 +14,6 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/STLExtras.h"
-#include "gmock/gmock-generated-matchers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 


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


r368399 - Use ASSERT_THAT_ERROR instead of logAllUnhandledErrors/exit

2019-08-08 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug  8 23:14:54 2019
New Revision: 368399

URL: http://llvm.org/viewvc/llvm-project?rev=368399&view=rev
Log:
Use ASSERT_THAT_ERROR instead of logAllUnhandledErrors/exit

Summary: ASSERT_THAT_ERROR looks like the intended helper for use in tests.

Reviewers: plotfi, jkorous, compnerd

Subscribers: mgorny, dexonsmith, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/unittests/DirectoryWatcher/CMakeLists.txt
cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Modified: cfe/trunk/unittests/DirectoryWatcher/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/DirectoryWatcher/CMakeLists.txt?rev=368399&r1=368398&r2=368399&view=diff
==
--- cfe/trunk/unittests/DirectoryWatcher/CMakeLists.txt (original)
+++ cfe/trunk/unittests/DirectoryWatcher/CMakeLists.txt Thu Aug  8 23:14:54 2019
@@ -10,8 +10,9 @@ if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "L
 
   target_link_libraries(DirectoryWatcherTests
 PRIVATE
+LLVMTestingSupport
 clangDirectoryWatcher
 clangBasic
 )
 
-endif()
\ No newline at end of file
+endif()

Modified: cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp?rev=368399&r1=368398&r2=368399&view=diff
==
--- cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp (original)
+++ cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp Thu Aug  8 
23:14:54 2019
@@ -10,6 +10,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -284,12 +285,7 @@ TEST(DirectoryWatcherTest, InitialScanSy
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -322,12 +318,7 @@ TEST(DirectoryWatcherTest, InitialScanAs
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/false);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -349,12 +340,7 @@ TEST(DirectoryWatcherTest, AddFiles) {
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   fixture.addFile("a");
   fixture.addFile("b");
@@ -381,12 +367,7 @@ TEST(DirectoryWatcherTest, ModifyFile) {
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   // modify the file
   {
@@ -418,12 +399,7 @@ TEST(DirectoryWatcherTest, DeleteFile) {
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   fixture.deleteFile("a");
 
@@ -446,12 +422,7 @@ TEST(DirectoryWatcherTest, DeleteWatched
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   remove_directories(fixture.TestWatchedDir);
 
@@ -473,12 +444,7 @@ TEST(DirectoryWatcherTest, InvalidatedWa
   TestConsumer.consume(Events, IsInitial);
 },
 /*waitForInitialSync=*/true);
-if (!DW) {
-  logAllUnhandledErrors(
-  DW.takeError(), llvm::errs(),
-  "DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-  exit(EXIT_FAILURE);
-}
+

r368738 - Revert "Fix crash on switch conditions of non-integer types in templates"

2019-08-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Tue Aug 13 12:07:28 2019
New Revision: 368738

URL: http://llvm.org/viewvc/llvm-project?rev=368738&view=rev
Log:
Revert "Fix crash on switch conditions of non-integer types in templates"

This reverts commit r368706. It broke ClangTidy tests.

Removed:
cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaTemplate/dependent-names.cpp
cfe/trunk/test/SemaTemplate/enum-argument.cpp
cfe/trunk/test/SemaTemplate/member-access-expr.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=368738&r1=368737&r2=368738&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Aug 13 12:07:28 2019
@@ -1669,15 +1669,6 @@ MemberExpr *MemberExpr::Create(
   MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl,
NameInfo, T, VK, OK, NOUR);
 
-  if (FieldDecl *Field = dyn_cast(MemberDecl)) {
-DeclContext *DC = MemberDecl->getDeclContext();
-// dyn_cast_or_null is used to handle objC variables which do not
-// have a declaration context.
-CXXRecordDecl *RD = dyn_cast_or_null(DC);
-if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC))
-  E->setTypeDependent(T->isDependentType());
-  }
-
   if (HasQualOrFound) {
 // FIXME: Wrong. We should be looking at the member declaration we found.
 if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) {

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=368738&r1=368737&r2=368738&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Aug 13 12:07:28 2019
@@ -14288,8 +14288,6 @@ void Sema::RefersToMemberWithReducedAlig
   bool AnyIsPacked = false;
   do {
 QualType BaseType = ME->getBase()->getType();
-if (BaseType->isDependentType())
-  return;
 if (ME->isArrow())
   BaseType = BaseType->getPointeeType();
 RecordDecl *RD = BaseType->getAs()->getDecl();

Modified: cfe/trunk/test/SemaTemplate/dependent-names.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-names.cpp?rev=368738&r1=368737&r2=368738&view=diff
==
--- cfe/trunk/test/SemaTemplate/dependent-names.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-names.cpp Tue Aug 13 12:07:28 2019
@@ -273,6 +273,9 @@ namespace PR10187 {
   }
   int e[10];
 };
+void g() {
+  S().f(); // expected-note {{here}}
+}
   }
 
   namespace A2 {

Modified: cfe/trunk/test/SemaTemplate/enum-argument.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/enum-argument.cpp?rev=368738&r1=368737&r2=368738&view=diff
==
--- cfe/trunk/test/SemaTemplate/enum-argument.cpp (original)
+++ cfe/trunk/test/SemaTemplate/enum-argument.cpp Tue Aug 13 12:07:28 2019
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
 
 enum Enum { val = 1 };
 template  struct C {
@@ -30,7 +31,7 @@ namespace rdar8020920 {
 unsigned long long bitfield : e0;
 
 void f(int j) {
-  bitfield + j; // expected-warning {{expression result unused}}
+  bitfield + j;
 }
   };
 }

Modified: cfe/trunk/test/SemaTemplate/member-access-expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/member-access-expr.cpp?rev=368738&r1=368737&r2=368738&view=diff
==
--- cfe/trunk/test/SemaTemplate/member-access-expr.cpp (original)
+++ cfe/trunk/test/SemaTemplate/member-access-expr.cpp Tue Aug 13 12:07:28 2019
@@ -156,7 +156,7 @@ namespace test6 {
 void get(B **ptr) {
   // It's okay if at some point we figure out how to diagnose this
   // at instantiation time.
-  *ptr = field; // expected-error {{assigning to 'test6::B *' from 
incompatible type 'test6::A *}}
+  *ptr = field;
 }
   };
 }

Removed: cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp?rev=368737&view=auto
==
--- cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp (original)
+++ cfe/trunk/test/SemaTemplate/non-integral-switch-cond.cpp (removed)
@@ -1,14 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-struct NOT_AN_INTEGRAL_TYPE {};
-
-template 
-struct foo {
-  NOT_AN_INTEGRAL_TYPE Bad;
-  void run() 

r368805 - Removed dead code from clang/tools/libclang/CXIndexDataConsumer.{cpp, h}

2019-08-14 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Aug 14 00:32:51 2019
New Revision: 368805

URL: http://llvm.org/viewvc/llvm-project?rev=368805&view=rev
Log:
Removed dead code from clang/tools/libclang/CXIndexDataConsumer.{cpp,h}

Reviewers: jkorous

Subscribers: dexonsmith, arphaman, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
cfe/trunk/tools/libclang/CXIndexDataConsumer.h

Modified: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp?rev=368805&r1=368804&r2=368805&view=diff
==
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp (original)
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp Wed Aug 14 00:32:51 2019
@@ -633,12 +633,6 @@ bool CXIndexDataConsumer::handleField(co
   return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
 }
 
-bool CXIndexDataConsumer::handleMSProperty(const MSPropertyDecl *D) {
-  DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true,
- /*isContainer=*/false);
-  return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
-}
-
 bool CXIndexDataConsumer::handleEnumerator(const EnumConstantDecl *D) {
   DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true,
  /*isContainer=*/false);
@@ -889,20 +883,6 @@ bool CXIndexDataConsumer::handleTypeAlia
 }
 
 bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation 
Loc,
-  const NamedDecl *Parent,
-  const DeclContext *DC,
-  const Expr *E,
-  CXIdxEntityRefKind Kind,
-  CXSymbolRole Role) {
-  if (!D || !DC)
-return false;
-
-  CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
-  : getRefCursor(D, Loc);
-  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role);
-}
-
-bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation 
Loc,
   CXCursor Cursor,
   const NamedDecl *Parent,
   const DeclContext *DC,

Modified: cfe/trunk/tools/libclang/CXIndexDataConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXIndexDataConsumer.h?rev=368805&r1=368804&r2=368805&view=diff
==
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.h (original)
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.h Wed Aug 14 00:32:51 2019
@@ -372,25 +372,6 @@ public:
 
   void startedTranslationUnit();
 
-  void indexDecl(const Decl *D);
-
-  void indexTagDecl(const TagDecl *D);
-
-  void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent,
-   const DeclContext *DC = nullptr);
-
-  void indexTypeLoc(TypeLoc TL, const NamedDecl *Parent,
-const DeclContext *DC = nullptr);
-
-  void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
-   const NamedDecl *Parent,
-   const DeclContext *DC = nullptr);
-
-  void indexDeclContext(const DeclContext *DC);
-  
-  void indexBody(const Stmt *S, const NamedDecl *Parent,
- const DeclContext *DC = nullptr);
-
   void indexDiagnostics();
 
   void handleDiagnosticSet(CXDiagnosticSet CXDiagSet);
@@ -401,8 +382,6 @@ public:
 
   bool handleField(const FieldDecl *D);
 
-  bool handleMSProperty(const MSPropertyDecl *D);
-
   bool handleEnumerator(const EnumConstantDecl *D);
 
   bool handleTagDecl(const TagDecl *D);
@@ -438,18 +417,8 @@ public:
CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
CXSymbolRole Role = CXSymbolRole_None);
 
-  bool handleReference(const NamedDecl *D, SourceLocation Loc,
-   const NamedDecl *Parent,
-   const DeclContext *DC,
-   const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
-   CXSymbolRole Role = CXSymbolRole_None);
-
   bool isNotFromSourceFile(SourceLocation Loc) const;
 
-  void indexTopLevelDecl(const Decl *D);
-  void indexDeclGroupRef(DeclGroupRef DG);
-
   void translateLoc(SourceLocation Loc, CXIdxClientFile *indexFile, CXFile 
*file,
 unsigned *line, unsigned *column, unsigned *offset);
 


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


r368827 - Improved the doc comment for getCommentsInFile

2019-08-14 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Aug 14 04:11:52 2019
New Revision: 368827

URL: http://llvm.org/viewvc/llvm-project?rev=368827&view=rev
Log:
Improved the doc comment for getCommentsInFile

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/AST/RawCommentList.h

Modified: cfe/trunk/include/clang/AST/RawCommentList.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RawCommentList.h?rev=368827&r1=368826&r2=368827&view=diff
==
--- cfe/trunk/include/clang/AST/RawCommentList.h (original)
+++ cfe/trunk/include/clang/AST/RawCommentList.h Wed Aug 14 04:11:52 2019
@@ -199,7 +199,8 @@ public:
   void addComment(const RawComment &RC, const CommentOptions &CommentOpts,
   llvm::BumpPtrAllocator &Allocator);
 
-  /// \returns nullptr in case there are no comments in in \p File.
+  /// \returns A mapping from an offset of the start of the comment to the
+  /// comment itself, or nullptr in case there are no comments in \p File.
   const std::map *getCommentsInFile(FileID File) const;
 
   bool empty() const;


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


r368832 - Removed ToolExecutor::isSingleProcess, it is not used by anything

2019-08-14 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Aug 14 04:35:04 2019
New Revision: 368832

URL: http://llvm.org/viewvc/llvm-project?rev=368832&view=rev
Log:
Removed ToolExecutor::isSingleProcess, it is not used by anything

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Tooling/AllTUsExecution.h
cfe/trunk/include/clang/Tooling/Execution.h
cfe/trunk/include/clang/Tooling/StandaloneExecution.h
cfe/trunk/unittests/Tooling/ExecutionTest.cpp

Modified: cfe/trunk/include/clang/Tooling/AllTUsExecution.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/AllTUsExecution.h?rev=368832&r1=368831&r2=368832&view=diff
==
--- cfe/trunk/include/clang/Tooling/AllTUsExecution.h (original)
+++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h Wed Aug 14 04:35:04 2019
@@ -44,8 +44,6 @@ public:
 
   StringRef getExecutorName() const override { return ExecutorName; }
 
-  bool isSingleProcess() const override { return true; }
-
   using ToolExecutor::execute;
 
   llvm::Error

Modified: cfe/trunk/include/clang/Tooling/Execution.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Execution.h?rev=368832&r1=368831&r2=368832&view=diff
==
--- cfe/trunk/include/clang/Tooling/Execution.h (original)
+++ cfe/trunk/include/clang/Tooling/Execution.h Wed Aug 14 04:35:04 2019
@@ -115,13 +115,6 @@ public:
   /// Returns the name of a specific executor.
   virtual StringRef getExecutorName() const = 0;
 
-  /// Should return true iff executor runs all actions in a single process.
-  /// Clients can use this signal to find out if they can collect results
-  /// in-memory (e.g. to avoid serialization costs of using ToolResults).
-  /// The single-process executors can still run multiple threads, but all
-  /// executions are guaranteed to share the same memory.
-  virtual bool isSingleProcess() const = 0;
-
   /// Executes each action with a corresponding arguments adjuster.
   virtual llvm::Error
   execute(llvm::ArrayRef<

Modified: cfe/trunk/include/clang/Tooling/StandaloneExecution.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/StandaloneExecution.h?rev=368832&r1=368831&r2=368832&view=diff
==
--- cfe/trunk/include/clang/Tooling/StandaloneExecution.h (original)
+++ cfe/trunk/include/clang/Tooling/StandaloneExecution.h Wed Aug 14 04:35:04 
2019
@@ -52,8 +52,6 @@ public:
 
   StringRef getExecutorName() const override { return ExecutorName; }
 
-  bool isSingleProcess() const override { return true; }
-
   using ToolExecutor::execute;
 
   llvm::Error

Modified: cfe/trunk/unittests/Tooling/ExecutionTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ExecutionTest.cpp?rev=368832&r1=368831&r2=368832&view=diff
==
--- cfe/trunk/unittests/Tooling/ExecutionTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/ExecutionTest.cpp Wed Aug 14 04:35:04 2019
@@ -95,8 +95,6 @@ public:
 
   StringRef getExecutorName() const override { return ExecutorName; }
 
-  bool isSingleProcess() const override { return true; }
-
   llvm::Error
   execute(llvm::ArrayRef,
ArgumentsAdjuster>>) override {


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


r369380 - Removed the 'id' AST matcher, which is superseded by '.bind()'

2019-08-20 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Tue Aug 20 06:02:28 2019
New Revision: 369380

URL: http://llvm.org/viewvc/llvm-project?rev=369380&view=rev
Log:
Removed the 'id' AST matcher, which is superseded by '.bind()'

Summary:
The 'id' matcher is not even included in the AST Matchers Reference
document, so I don't expect there to be a significant number of users.

There's no reason to provide two ways to do the exact same thing that
only have a minor syntactic difference.

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=369380&r1=369379&r2=369380&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Aug 20 06:02:28 2019
@@ -19,15 +19,15 @@
 //
 //  For more complicated match expressions we're often interested in accessing
 //  multiple parts of the matched AST nodes once a match is found. In that 
case,
-//  use the id(...) matcher around the match expressions that match the nodes
-//  you want to access.
+//  call `.bind("name")` on match expressions that match the nodes you want to
+//  access.
 //
 //  For example, when we're interested in child classes of a certain class, we
 //  would write:
-//cxxRecordDecl(hasName("MyClass"), has(id("child", recordDecl(
+//cxxRecordDecl(hasName("MyClass"), has(recordDecl().bind("child")))
 //  When the match is found via the MatchFinder, a user provided callback will
 //  be called with a BoundNodes instance that contains a mapping from the
-//  strings that we provided for the id(...) calls to the nodes that were
+//  strings that we provided for the `.bind()` calls to the nodes that were
 //  matched.
 //  In the given example, each time our matcher finds a match we get a callback
 //  where "child" is bound to the RecordDecl node of the matching child
@@ -131,15 +131,6 @@ private:
   internal::BoundNodesMap MyBoundNodes;
 };
 
-/// If the provided matcher matches a node, binds the node to \c ID.
-///
-/// FIXME: Do we want to support this now that we have bind()?
-template 
-internal::Matcher id(StringRef ID,
-const internal::BindableMatcher &InnerMatcher) {
-  return InnerMatcher.bind(ID);
-}
-
 /// Types of matchers for the top-level classes in the AST class
 /// hierarchy.
 /// @{

Modified: cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp?rev=369380&r1=369379&r2=369380&view=diff
==
--- cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp Tue Aug 20 
06:02:28 2019
@@ -38,28 +38,28 @@ TEST(RefactoringCallbacksTest, ReplacesS
   std::string Code = "void f() { int i = 1; }";
   std::string Expected = "void f() { ; }";
   ReplaceStmtWithText Callback("id", ";");
-  expectRewritten(Code, Expected, id("id", declStmt()), Callback);
+  expectRewritten(Code, Expected, declStmt().bind("id"), Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesStmtsInCalledMacros) {
   std::string Code = "#define A void f() { int i = 1; }\nA";
   std::string Expected = "#define A void f() { ; }\nA";
   ReplaceStmtWithText Callback("id", ";");
-  expectRewritten(Code, Expected, id("id", declStmt()), Callback);
+  expectRewritten(Code, Expected, declStmt().bind("id"), Callback);
 }
 
 TEST(RefactoringCallbacksTest, IgnoresStmtsInUncalledMacros) {
   std::string Code = "#define A void f() { int i = 1; }";
   std::string Expected = "#define A void f() { int i = 1; }";
   ReplaceStmtWithText Callback("id", ";");
-  expectRewritten(Code, Expected, id("id", declStmt()), Callback);
+  expectRewritten(Code, Expected, declStmt().bind("id"), Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesInteger) {
   std::string Code = "void f() { int i = 1; }";
   std::string Expected = "void f() { int i = 2; }";
   ReplaceStmtWithText Callback("id", "2");
-  expectRewritten(Code, Expected, id("id", expr(integerLiteral())), Callback);
+  expectRewritten(Code, Expected, expr(integerLiteral()).bind("id"), Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesStmtWithStmt) {
@@ -68,9 +68,9 @@ TEST(RefactoringCallbacksTest, ReplacesS
   ReplaceStmtWithStmt Callback("always-false", "should-be");
   expectRewritten(
   Code, Expected,
-  id("always-false",
- conditionalOperator(hasCondition(cxxBoolLiteral(equals(false))),
- hasFalseExpression(id("should-be", expr(),
+  conditionalOperator(hasCondition(

[clang-tools-extra] r365007 - [clang-tidy] new check: bugprone-posix-return

2019-07-03 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Jul  3 02:20:18 2019
New Revision: 365007

URL: http://llvm.org/viewvc/llvm-project?rev=365007&view=rev
Log:
[clang-tidy] new check: bugprone-posix-return

Summary:
Checks if any calls to posix functions (except posix_openpt) expect negative 
return values.
These functions return either 0 on success or an errno on failure, which is 
positive only.

Reviewers: JonasToth, gribozavr, alexfh, hokein

Reviewed By: gribozavr

Subscribers: Eugene.Zelenko, lebedev.ri, llozano, george.burgess.iv, xazax.hun, 
srhines, mgorny, cfe-commits

Tags: #clang

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

Patch by Jian Cai.

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-posix-return.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-posix-return.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=365007&r1=365006&r2=365007&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Wed Jul  
3 02:20:18 2019
@@ -31,6 +31,7 @@
 #include "MoveForwardingReferenceCheck.h"
 #include "MultipleStatementMacroCheck.h"
 #include "ParentVirtualCallCheck.h"
+#include "PosixReturnCheck.h"
 #include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
 #include "StringConstructorCheck.h"
@@ -104,6 +105,8 @@ public:
 "bugprone-narrowing-conversions");
 CheckFactories.registerCheck(
 "bugprone-parent-virtual-call");
+CheckFactories.registerCheck(
+"bugprone-posix-return");
 CheckFactories.registerCheck(
 "bugprone-sizeof-container");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=365007&r1=365006&r2=365007&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Wed Jul  3 
02:20:18 2019
@@ -23,6 +23,7 @@ add_clang_library(clangTidyBugproneModul
   MoveForwardingReferenceCheck.cpp
   MultipleStatementMacroCheck.cpp
   ParentVirtualCallCheck.cpp
+  PosixReturnCheck.cpp
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp
   StringConstructorCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp?rev=365007&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp Wed Jul  3 
02:20:18 2019
@@ -0,0 +1,82 @@
+//===--- PosixReturnCheck.cpp - 
clang-tidy-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PosixReturnCheck.h"
+#include "../utils/Matchers.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+static StringRef getFunctionSpelling(const MatchFinder::MatchResult &Result,
+ const char *BindingStr) {
+  const CallExpr *MatchedCall = cast(
+  (Result.Nodes.getNodeAs(BindingStr))->getLHS());
+  const SourceManager &SM = *Result.SourceManager;
+  return Lexer::getSourceText(CharSourceRange::getTokenRange(
+  MatchedCall->getCallee()->getSourceRange()),
+  SM, Result.Context->getLangOpts());
+}
+
+void PosixReturnCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(binaryOperator(hasOperatorName("<"),
+hasLHS(callExpr(callee(functionDecl(
+matchesName("^::posix_"),
+unless(hasName("::posix_openpt")),
+h

[clang-tools-extra] r365078 - Fixed a link in ReleaseNotes.rst (follow-up to r365007)

2019-07-03 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Jul  3 13:18:34 2019
New Revision: 365078

URL: http://llvm.org/viewvc/llvm-project?rev=365078&view=rev
Log:
Fixed a link in ReleaseNotes.rst (follow-up to r365007)

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

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=365078&r1=365077&r2=365078&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Wed Jul  3 13:18:34 2019
@@ -126,7 +126,7 @@ Improvements to clang-tidy
   branches in conditional operators.
 
 - New :doc:`bugprone-posix-return
-  ` check.
+  ` check.
 
   Checks if any calls to POSIX functions (except ``posix_openpt``) expect 
negative
   return values.


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


[clang-tools-extra] r365463 - Enhance abseil-faster-strsplit-delimiter to handle other non-printable characters.

2019-07-09 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Tue Jul  9 04:04:04 2019
New Revision: 365463

URL: http://llvm.org/viewvc/llvm-project?rev=365463&view=rev
Log:
Enhance abseil-faster-strsplit-delimiter to handle other non-printable 
characters.

Summary:
Currently it fails on cases like '\001'.

Note: Since `StringLiteral::outputString` dumps most nonprintable
characters in octal value, the exact string literal format isn't preserved,
e.g. `"\x01"` becomes `'\001'`.

Reviewers: gribozavr

Reviewed By: gribozavr

Subscribers: lebedev.ri, Eugene.Zelenko, cfe-commits

Tags: #clang

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

Patch by Xiaoyi Zhang.

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp?rev=365463&r1=365462&r2=365463&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp 
Tue Jul  9 04:04:04 2019
@@ -9,6 +9,7 @@
 #include "FasterStrsplitDelimiterCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
 
 using namespace clang::ast_matchers;
 
@@ -20,23 +21,29 @@ namespace {
 
 AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
 
-llvm::Optional makeCharacterLiteral(const StringLiteral *Literal) 
{
-  std::string Result;
-  {
+llvm::Optional makeCharacterLiteral(const StringLiteral *Literal,
+ const ASTContext &Context) {
+  assert(Literal->getLength() == 1 &&
+ "Only single character string should be matched");
+  assert(Literal->getCharByteWidth() == 1 &&
+ "StrSplit doesn't support wide char");
+  std::string Result = clang::tooling::fixit::getText(*Literal, Context).str();
+  bool IsRawStringLiteral = StringRef(Result).startswith(R"(R")");
+  // Since raw string literal might contain unescaped non-printable characters,
+  // we normalize them using `StringLiteral::outputString`.
+  if (IsRawStringLiteral) {
+Result.clear();
 llvm::raw_string_ostream Stream(Result);
 Literal->outputString(Stream);
   }
-
   // Special case: If the string contains a single quote, we just need to 
return
   // a character of the single quote. This is a special case because we need to
   // escape it in the character literal.
   if (Result == R"("'")")
 return std::string(R"('\'')");
 
-  assert(Result.size() == 3 || (Result.size() == 4 && Result.substr(0, 2) == 
"\"\\"));
-
   // Now replace the " with '.
-  auto Pos = Result.find_first_of('"');
+  std::string::size_type Pos = Result.find_first_of('"');
   if (Pos == Result.npos)
 return llvm::None;
   Result[Pos] = '\'';
@@ -98,7 +105,8 @@ void FasterStrsplitDelimiterCheck::check
   if (Literal->getBeginLoc().isMacroID() || Literal->getEndLoc().isMacroID())
 return;
 
-  llvm::Optional Replacement = makeCharacterLiteral(Literal);
+  llvm::Optional Replacement =
+  makeCharacterLiteral(Literal, *Result.Context);
   if (!Replacement)
 return;
   SourceRange Range = Literal->getSourceRange();

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp?rev=365463&r1=365462&r2=365463&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp 
Tue Jul  9 04:04:04 2019
@@ -44,6 +44,31 @@ void SplitDelimiters() {
   // CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a 
string literal consisting of a single character; consider using the character 
overload [abseil-faster-strsplit-delimiter]
   // CHECK-FIXES: absl::StrSplit("ABC", 'A');
 
+  absl::StrSplit("ABC", "\x01");
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a 
string literal consisting of a single character; consider using the character 
overload [abseil-faster-strsplit-delimiter]
+  // CHECK-FIXES: absl::StrSplit("ABC", '\x01');
+
+  absl::StrSplit("ABC", "\001");
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a 
string literal consisting of a single character; consider using the character 
overload [abseil-faster-strsplit-delimiter]
+  // CHECK-FIXES: absl::StrSplit("ABC", '\001');
+
+  absl::StrSplit("ABC", R"(A)");
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a 

r360406 - Added an assert in `isConstantInitializer`: initializer lists must be in semantic form

2019-05-09 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu May  9 23:39:20 2019
New Revision: 360406

URL: http://llvm.org/viewvc/llvm-project?rev=360406&view=rev
Log:
Added an assert in `isConstantInitializer`: initializer lists must be in 
semantic form

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=360406&r1=360405&r2=360406&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu May  9 23:39:20 2019
@@ -2947,6 +2947,7 @@ bool Expr::isConstantInitializer(ASTCont
   }
   case InitListExprClass: {
 const InitListExpr *ILE = cast(this);
+assert(ILE->isSemanticForm() && "InitListExpr must be in semantic form");
 if (ILE->getType()->isArrayType()) {
   unsigned numInits = ILE->getNumInits();
   for (unsigned i = 0; i < numInits; i++) {


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


r361050 - Added an assertion to constant evaluation enty points that prohibits dependent expressions

2019-05-17 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri May 17 10:16:53 2019
New Revision: 361050

URL: http://llvm.org/viewvc/llvm-project?rev=361050&view=rev
Log:
Added an assertion to constant evaluation enty points that prohibits dependent 
expressions

Summary:
Constant evaluator does not work on value-dependent or type-dependent
expressions.

Also fixed bugs uncovered by these assertions.

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=361050&r1=361049&r2=361050&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri May 17 10:16:53 2019
@@ -2974,6 +2974,9 @@ bool Expr::hasAnyTypeDependentArguments(
 
 bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef,
  const Expr **Culprit) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
+
   // This function is attempting whether an expression is an initializer
   // which can be evaluated at compile-time. It very closely parallels
   // ConstExprEmitter in CGExprConstant.cpp; if they don't match, it

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=361050&r1=361049&r2=361050&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 17 10:16:53 2019
@@ -11642,6 +11642,8 @@ static bool EvaluateAsFixedPoint(const E
 /// will be applied to the result.
 bool Expr::EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx,
 bool InConstantContext) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
   EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
   Info.InConstantContext = InConstantContext;
   return ::EvaluateAsRValue(this, Result, Ctx, Info);
@@ -11649,6 +11651,8 @@ bool Expr::EvaluateAsRValue(EvalResult &
 
 bool Expr::EvaluateAsBooleanCondition(bool &Result,
   const ASTContext &Ctx) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
   EvalResult Scratch;
   return EvaluateAsRValue(Scratch, Ctx) &&
  HandleConversionToBool(Scratch.Val, Result);
@@ -11656,18 +11660,25 @@ bool Expr::EvaluateAsBooleanCondition(bo
 
 bool Expr::EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
  SideEffectsKind AllowSideEffects) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
   EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
   return ::EvaluateAsInt(this, Result, Ctx, AllowSideEffects, Info);
 }
 
 bool Expr::EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx,
 SideEffectsKind AllowSideEffects) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
   EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
   return ::EvaluateAsFixedPoint(this, Result, Ctx, AllowSideEffects, Info);
 }
 
 bool Expr::EvaluateAsFloat(APFloat &Result, const ASTContext &Ctx,
SideEffectsKind AllowSideEffects) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
+
   if (!getType()->isRealFloatingType())
 return false;
 
@@ -11681,6 +11692,9 @@ bool Expr::EvaluateAsFloat(APFloat &Resu
 }
 
 bool Expr::EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
+
   EvalInfo Info(Ctx, Result, EvalInfo::EM_ConstantFold);
 
   LValue LV;
@@ -11696,6 +11710,9 @@ bool Expr::EvaluateAsLValue(EvalResult &
 
 bool Expr::EvaluateAsConstantExpr(EvalResult &Result, ConstExprUsage Usage,
   const ASTContext &Ctx) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
+
   EvalInfo::EvaluationMode EM = EvalInfo::EM_ConstantExpression;
   EvalInfo Info(Ctx, Result, EM);
   Info.InConstantContext = true;
@@ -11710,6 +11727,9 @@ bool Expr::EvaluateAsConstantExpr(EvalRe
 bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx,
  const VarDecl *VD,
 SmallVectorImpl &Notes) const 
{
+  assert(!i

[clang-tools-extra] r361163 - Disable the modernize-use-trailing-return-type.cpp test in C++2a mode

2019-05-20 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon May 20 08:12:12 2019
New Revision: 361163

URL: http://llvm.org/viewvc/llvm-project?rev=361163&view=rev
Log:
Disable the modernize-use-trailing-return-type.cpp test in C++2a mode

It is performing a use-of-uninitialized-value, as detected by MSan.

Modified:

clang-tools-extra/trunk/test/clang-tidy/modernize-use-trailing-return-type.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-trailing-return-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-trailing-return-type.cpp?rev=361163&r1=361162&r2=361163&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-trailing-return-type.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/modernize-use-trailing-return-type.cpp 
Mon May 20 08:12:12 2019
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy -std=c++14-or-later %s 
modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions
+// RUN: %check_clang_tidy -std=c++14,c++17 %s 
modernize-use-trailing-return-type %t -- -- -fdeclspec -fexceptions
+// FIXME: Fix the checker to work in C++2a mode, it is performing a
+// use-of-uninitialized-value.
 
 namespace std {
 template 


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


r361170 - Renamed `apply` to `select` to avoid ADL conflict with `std::apply`

2019-05-20 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon May 20 09:30:49 2019
New Revision: 361170

URL: http://llvm.org/viewvc/llvm-project?rev=361170&view=rev
Log:
Renamed `apply` to `select` to avoid ADL conflict with `std::apply`

Summary:
`std::apply` in C++14 and above is defined with two unrestricted arguments, and
it wins overload resolution in this case.

Reviewers: ilya-biryukov

Subscribers: cfe-commits, ymandel

Tags: #clang

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

Modified:
cfe/trunk/unittests/Tooling/RangeSelectorTest.cpp

Modified: cfe/trunk/unittests/Tooling/RangeSelectorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RangeSelectorTest.cpp?rev=361170&r1=361169&r2=361170&view=diff
==
--- cfe/trunk/unittests/Tooling/RangeSelectorTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RangeSelectorTest.cpp Mon May 20 09:30:49 2019
@@ -53,7 +53,7 @@ template  TestMatch matchCod
 }
 
 // Applies \p Selector to \p Match and, on success, returns the selected 
source.
-Expected apply(RangeSelector Selector, const TestMatch &Match) {
+Expected select(RangeSelector Selector, const TestMatch &Match) {
   Expected Range = Selector(Match.Result);
   if (!Range)
 return Range.takeError();
@@ -62,7 +62,7 @@ Expected apply(RangeSelector
 
 // Applies \p Selector to a trivial match with only a single bound node with id
 // "bound_node_id".  For use in testing unbound-node errors.
-Expected applyToTrivial(const RangeSelector &Selector) {
+Expected selectFromTrivial(const RangeSelector &Selector) {
   // We need to bind the result to something, or the match will fail. Use a
   // binding that is not used in the unbound node tests.
   TestMatch Match =
@@ -81,7 +81,7 @@ testing::Matcher withUnboun
 // binds each one: a statement ("stmt"), a (non-member) ctor-initializer
 // ("init"), an expression ("expr") and a (nameless) declaration ("decl").  
Used
 // to test failures caused by applying selectors to nodes of the wrong type.
-Expected applyToAssorted(RangeSelector Selector) {
+Expected selectFromAssorted(RangeSelector Selector) {
   StringRef Code = R"cc(
   struct A {};
   class F : public A {
@@ -113,7 +113,7 @@ testing::Matcher withTypeEr
 }
 
 TEST(RangeSelectorTest, UnboundNode) {
-  EXPECT_THAT_EXPECTED(applyToTrivial(node("unbound_id")),
+  EXPECT_THAT_EXPECTED(selectFromTrivial(node("unbound_id")),
Failed(withUnboundNodeMessage()));
 }
 
@@ -131,9 +131,9 @@ TEST(RangeSelectorTest, RangeOp) {
   TestMatch Match = matchCode(Code, Matcher);
 
   // Node-id specific version:
-  EXPECT_THAT_EXPECTED(apply(range(Arg0, Arg1), Match), HasValue("3, 7"));
+  EXPECT_THAT_EXPECTED(select(range(Arg0, Arg1), Match), HasValue("3, 7"));
   // General version:
-  EXPECT_THAT_EXPECTED(apply(range(node(Arg0), node(Arg1)), Match),
+  EXPECT_THAT_EXPECTED(select(range(node(Arg0), node(Arg1)), Match),
HasValue("3, 7"));
 }
 
@@ -141,21 +141,21 @@ TEST(RangeSelectorTest, NodeOpStatement)
   StringRef Code = "int f() { return 3; }";
   StringRef ID = "id";
   TestMatch Match = matchCode(Code, returnStmt().bind(ID));
-  EXPECT_THAT_EXPECTED(apply(node(ID), Match), HasValue("return 3;"));
+  EXPECT_THAT_EXPECTED(select(node(ID), Match), HasValue("return 3;"));
 }
 
 TEST(RangeSelectorTest, NodeOpExpression) {
   StringRef Code = "int f() { return 3; }";
   StringRef ID = "id";
   TestMatch Match = matchCode(Code, expr().bind(ID));
-  EXPECT_THAT_EXPECTED(apply(node(ID), Match), HasValue("3"));
+  EXPECT_THAT_EXPECTED(select(node(ID), Match), HasValue("3"));
 }
 
 TEST(RangeSelectorTest, StatementOp) {
   StringRef Code = "int f() { return 3; }";
   StringRef ID = "id";
   TestMatch Match = matchCode(Code, expr().bind(ID));
-  EXPECT_THAT_EXPECTED(apply(statement(ID), Match), HasValue("3;"));
+  EXPECT_THAT_EXPECTED(select(statement(ID), Match), HasValue("3;"));
 }
 
 TEST(RangeSelectorTest, MemberOp) {
@@ -170,7 +170,7 @@ TEST(RangeSelectorTest, MemberOp) {
   )cc";
   StringRef ID = "id";
   TestMatch Match = matchCode(Code, memberExpr().bind(ID));
-  EXPECT_THAT_EXPECTED(apply(member(ID), Match), HasValue("member"));
+  EXPECT_THAT_EXPECTED(select(member(ID), Match), HasValue("member"));
 }
 
 // Tests that member does not select any qualifiers on the member name.
@@ -189,7 +189,7 @@ TEST(RangeSelectorTest, MemberOpQualifie
   )cc";
   StringRef ID = "id";
   TestMatch Match = matchCode(Code, memberExpr().bind(ID));
-  EXPECT_THAT_EXPECTED(apply(member(ID), Match), HasValue("member"));
+  EXPECT_THAT_EXPECTED(select(member(ID), Match), HasValue("member"));
 }
 
 TEST(RangeSelectorTest, MemberOpTemplate) {
@@ -205,7 +205,7 @@ TEST(RangeSelectorTest, MemberOpTemplate
 
   StringRef ID = "id";
   TestMatch Match = matchCode(Code, memberExpr().bind(ID));
-  EXPECT_THAT_EXPECTED(apply(member(ID), Match), HasValue("foo"));
+  EXPECT_THAT_EXPECTED(select(member(ID), Match), HasV

r361353 - Fixed a -Wunused-variable warning when assertions are disabled

2019-05-21 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Tue May 21 23:57:23 2019
New Revision: 361353

URL: http://llvm.org/viewvc/llvm-project?rev=361353&view=rev
Log:
Fixed a -Wunused-variable warning when assertions are disabled

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=361353&r1=361352&r2=361353&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue May 21 23:57:23 2019
@@ -5033,6 +5033,7 @@ static bool HandleUnionActiveMemberChang
 break;
   for (const CXXBaseSpecifier *Elt : ICE->path()) {
 --PathLength;
+(void)Elt;
 assert(declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(),
   LHS.Designator.Entries[PathLength]
   .getAsBaseOrMember().getPointer()));


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


r361411 - Fixed a -Wunused-variable warning when assertions are disabled

2019-05-22 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed May 22 10:45:24 2019
New Revision: 361411

URL: http://llvm.org/viewvc/llvm-project?rev=361411&view=rev
Log:
Fixed a -Wunused-variable warning when assertions are disabled

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=361411&r1=361410&r2=361411&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed May 22 10:45:24 2019
@@ -4357,6 +4357,7 @@ void CGDebugInfo::EmitGlobalVariable(con
   if (const auto *ECD = dyn_cast(VD)) {
 const auto *ED = cast(ECD->getDeclContext());
 assert(isa(ED->getTypeForDecl()) && "Enum without EnumType?");
+(void)ED;
 return;
   }
 


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


r361468 - Delete default constructors, copy constructors, move constructors, copy assignment, move assignment operators on Expr, Stmt and Decl

2019-05-23 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu May 23 02:22:43 2019
New Revision: 361468

URL: http://llvm.org/viewvc/llvm-project?rev=361468&view=rev
Log:
Delete default constructors, copy constructors, move constructors, copy 
assignment, move assignment operators on Expr, Stmt and Decl

Reviewers: ilya-biryukov, rsmith

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=361468&r1=361467&r2=361468&view=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu May 23 02:22:43 2019
@@ -368,6 +368,13 @@ private:
 return ModuleOwnershipKind::Unowned;
   }
 
+public:
+  Decl() = delete;
+  Decl(const Decl&) = delete;
+  Decl(Decl &&) = delete;
+  Decl &operator=(const Decl&) = delete;
+  Decl &operator=(Decl&&) = delete;
+
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=361468&r1=361467&r2=361468&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu May 23 02:22:43 2019
@@ -108,6 +108,13 @@ struct SubobjectAdjustment {
 class Expr : public ValueStmt {
   QualType TR;
 
+public:
+  Expr() = delete;
+  Expr(const Expr&) = delete;
+  Expr(Expr &&) = delete;
+  Expr &operator=(const Expr&) = delete;
+  Expr &operator=(Expr&&) = delete;
+
 protected:
   Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=361468&r1=361467&r2=361468&view=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Thu May 23 02:22:43 2019
@@ -1040,6 +1040,12 @@ protected:
   explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
 
 public:
+  Stmt() = delete;
+  Stmt(const Stmt &) = delete;
+  Stmt(Stmt &&) = delete;
+  Stmt &operator=(const Stmt &) = delete;
+  Stmt &operator=(Stmt &&) = delete;
+
   Stmt(StmtClass SC) {
 static_assert(sizeof(*this) <= 8,
   "changing bitfields changed sizeof(Stmt)");
@@ -1054,11 +1060,6 @@ public:
 return static_cast(StmtBits.sClass);
   }
 
-  Stmt(const Stmt &) = delete;
-  Stmt(Stmt &&) = delete;
-  Stmt &operator=(const Stmt &) = delete;
-  Stmt &operator=(Stmt &&) = delete;
-
   const char *getStmtClassName() const;
 
   bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=361468&r1=361467&r2=361468&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu May 23 02:22:43 2019
@@ -1134,9 +1134,10 @@ llvm::Function *CodeGenFunction::generat
 return F;
 
   llvm::SmallVector ArgTys;
-  llvm::SmallVector Params;
-  Params.emplace_back(Ctx, nullptr, SourceLocation(), 
&Ctx.Idents.get("buffer"),
-  Ctx.VoidPtrTy, ImplicitParamDecl::Other);
+  FunctionArgList Args;
+  Args.push_back(ImplicitParamDecl::Create(
+  Ctx, nullptr, SourceLocation(), &Ctx.Idents.get("buffer"), Ctx.VoidPtrTy,
+  ImplicitParamDecl::Other));
   ArgTys.emplace_back(Ctx.VoidPtrTy);
 
   for (unsigned int I = 0, E = Layout.Items.size(); I < E; ++I) {
@@ -1145,17 +1146,13 @@ llvm::Function *CodeGenFunction::generat
   continue;
 
 QualType ArgTy = getOSLogArgType(Ctx, Size);
-Params.emplace_back(
+Args.push_back(ImplicitParamDecl::Create(
 Ctx, nullptr, SourceLocation(),
 &Ctx.Idents.get(std::string("arg") + llvm::to_string(I)), ArgTy,
-ImplicitParamDecl::Other);
+ImplicitParamDecl::Other));
 ArgTys.emplace_back(ArgTy);
   }
 
-  FunctionArgList Args;
-  for (auto &P : Params)
-Args.push_back(&P);
-
   QualType ReturnTy = Ctx.VoidTy;
   QualType FuncionTy = Ctx.getFunctionType(ReturnTy, ArgTys, {});
 
@@ -1188,7 +1185,7 @@ llvm::Function *CodeGenFunction::generat
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   CharUnits Offset;
-  Address BufAddr(Builder.CreateLoad(GetAddrOfLocalVar(&Params[0]), "buf"),
+  Address 

[clang-tools-extra] r361487 - [clang-tidy] New check calling out uses of +new in Objective-C code

2019-05-23 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu May 23 05:01:26 2019
New Revision: 361487

URL: http://llvm.org/viewvc/llvm-project?rev=361487&view=rev
Log:
[clang-tidy] New check calling out uses of +new in Objective-C code

Summary:
Google's Objective-C style guide forbids calling or overriding +new to 
instantiate objects. This check warns on violations.

Style guide reference: 
https://google.github.io/styleguide/objcguide.html#do-not-use-new

Patch by Michael Wyman.

Reviewers: benhamilton, aaron.ballman, JonasToth, gribozavr, ilya-biryukov, 
stephanemoore, mwyman

Reviewed By: aaron.ballman, gribozavr, stephanemoore, mwyman

Subscribers: stephanemoore, xazax.hun, Eugene.Zelenko, mgorny, cfe-commits

Tags: #clang, #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/google/AvoidNSObjectNewCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/AvoidNSObjectNewCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/google-objc-avoid-nsobject-new.rst
clang-tools-extra/trunk/test/clang-tidy/google-objc-avoid-nsobject-new.m
Modified:
clang-tools-extra/trunk/clang-tidy/google/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Added: clang-tools-extra/trunk/clang-tidy/google/AvoidNSObjectNewCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/AvoidNSObjectNewCheck.cpp?rev=361487&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/google/AvoidNSObjectNewCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/google/AvoidNSObjectNewCheck.cpp Thu May 
23 05:01:26 2019
@@ -0,0 +1,130 @@
+//===--- AvoidNSObjectNewCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "AvoidNSObjectNewCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "llvm/Support/FormatVariadic.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace google {
+namespace objc {
+
+static bool isMessageExpressionInsideMacro(const ObjCMessageExpr *Expr) {
+  SourceLocation ReceiverLocation = Expr->getReceiverRange().getBegin();
+  if (ReceiverLocation.isMacroID())
+return true;
+
+  SourceLocation SelectorLocation = Expr->getSelectorStartLoc();
+  if (SelectorLocation.isMacroID())
+return true;
+
+  return false;
+}
+
+// Walk up the class hierarchy looking for an -init method, returning true
+// if one is found and has not been marked unavailable.
+static bool isInitMethodAvailable(const ObjCInterfaceDecl *ClassDecl) {
+  while (ClassDecl != nullptr) {
+for (const auto *MethodDecl : ClassDecl->instance_methods()) {
+  if (MethodDecl->getSelector().getAsString() == "init")
+return !MethodDecl->isUnavailable();
+}
+ClassDecl = ClassDecl->getSuperClass();
+  }
+
+  // No -init method found in the class hierarchy. This should occur only 
rarely
+  // in Objective-C code, and only really applies to classes not derived from
+  // NSObject.
+  return false;
+}
+
+// Returns the string for the Objective-C message receiver. Keeps any generics
+// included in the receiver class type, which are stripped if the class type is
+// used. While the generics arguments will not make any difference to the
+// returned code at this time, the style guide allows them and they should be
+// left in any fix-it hint.
+static StringRef getReceiverString(SourceRange ReceiverRange,
+   const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(ReceiverRange), SM, LangOpts);
+  return Lexer::getSourceText(CharRange, SM, LangOpts);
+}
+
+static FixItHint getCallFixItHint(const ObjCMessageExpr *Expr,
+  const SourceManager &SM,
+  const LangOptions &LangOpts) {
+  // Check whether the messaged class has a known factory method to use instead
+  // of -init.
+  StringRef Receiver =
+  getReceiverString(Expr->getReceiverRange(), SM, LangOpts);
+  // Some classes should use standard factory methods instead of alloc/init.
+  std::map ClassToFactoryMethodMap = {{"NSDate", "date"},
+{"NSNull", 
"null"}};
+  auto FoundClassFactory

[clang-tools-extra] r361628 - Made cppcoreguidelines-pro-type-member-init-use-assignment run in all language modes

2019-05-24 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri May 24 03:39:00 2019
New Revision: 361628

URL: http://llvm.org/viewvc/llvm-project?rev=361628&view=rev
Log:
Made cppcoreguidelines-pro-type-member-init-use-assignment run in all language 
modes

Modified:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp?rev=361628&r1=361627&r2=361628&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
 Fri May 24 03:39:00 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- 
-config="{CheckOptions: [{key: 
"cppcoreguidelines-pro-type-member-init.UseAssignment", value: 1}]}" -- 
-std=c++11
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- 
-config="{CheckOptions: [{key: 
"cppcoreguidelines-pro-type-member-init.UseAssignment", value: 1}]}"
 
 struct T {
   int i;


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


[clang-tools-extra] r361629 - Make cppcoreguidelines-pro-type-member-init-use-assignment.cpp pass on platforms where char is unsigned

2019-05-24 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri May 24 03:50:15 2019
New Revision: 361629

URL: http://llvm.org/viewvc/llvm-project?rev=361629&view=rev
Log:
Make cppcoreguidelines-pro-type-member-init-use-assignment.cpp pass on 
platforms where char is unsigned

The other options are to completely specify the triple (reduces test
coverage), or to specify a regex that allows either '0' or '0U' for char
initializers, however, that relaxes the test.

Modified:

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp?rev=361629&r1=361628&r2=361629&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
 Fri May 24 03:50:15 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- 
-config="{CheckOptions: [{key: 
"cppcoreguidelines-pro-type-member-init.UseAssignment", value: 1}]}"
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- 
-config="{CheckOptions: [{key: 
"cppcoreguidelines-pro-type-member-init.UseAssignment", value: 1}]}" -- 
-fsigned-char
 
 struct T {
   int i;


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


r371598 - Revert "clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM"

2019-09-11 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Sep 11 02:16:17 2019
New Revision: 371598

URL: http://llvm.org/viewvc/llvm-project?rev=371598&view=rev
Log:
Revert "clang-misexpect: Profile Guided Validation of Performance Annotations 
in LLVM"

This reverts commit r371584. It introduced a dependency from compiler-rt
to llvm/include/ADT, which is problematic for multiple reasons.

One is that it is a novel dependency edge, which needs cross-compliation
machinery for llvm/include/ADT (yes, it is true that right now
compiler-rt included only header-only libraries, however, if we allow
compiler-rt to depend on anything from ADT, other libraries will
eventually get used).

Secondly, depending on ADT from compiler-rt exposes ADT symbols from
compiler-rt, which would cause ODR violations when Clang is built with
the profile library.

Removed:
cfe/trunk/test/Profile/Inputs/misexpect-branch-nonconst-expect-arg.proftext
cfe/trunk/test/Profile/Inputs/misexpect-branch.proftext
cfe/trunk/test/Profile/Inputs/misexpect-switch-default-only.proftext
cfe/trunk/test/Profile/Inputs/misexpect-switch-default.proftext
cfe/trunk/test/Profile/Inputs/misexpect-switch-nonconst.proftext
cfe/trunk/test/Profile/Inputs/misexpect-switch.proftext
cfe/trunk/test/Profile/misexpect-branch-cold.c
cfe/trunk/test/Profile/misexpect-branch-nonconst-expected-val.c
cfe/trunk/test/Profile/misexpect-branch-unpredictable.c
cfe/trunk/test/Profile/misexpect-branch.c
cfe/trunk/test/Profile/misexpect-switch-default.c
cfe/trunk/test/Profile/misexpect-switch-nonconst.c
cfe/trunk/test/Profile/misexpect-switch-only-default-case.c
cfe/trunk/test/Profile/misexpect-switch.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=371598&r1=371597&r2=371598&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Wed Sep 11 
02:16:17 2019
@@ -275,12 +275,7 @@ def warn_profile_data_missing : Warning<
 def warn_profile_data_unprofiled : Warning<
   "no profile data available for file \"%0\"">,
   InGroup;
-def warn_profile_data_misexpect : Warning<
-  "Potential performance regression from use of __builtin_expect(): "
-  "Annotation was correct on %0 of profiled executions.">,
-  BackendInfo,
-  InGroup,
-  DefaultIgnore;
+
 } // end of instrumentation issue category
 
 }

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=371598&r1=371597&r2=371598&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Sep 11 02:16:17 2019
@@ -1042,7 +1042,6 @@ def BackendOptimizationFailure : DiagGro
 def ProfileInstrMissing : DiagGroup<"profile-instr-missing">;
 def ProfileInstrOutOfDate : DiagGroup<"profile-instr-out-of-date">;
 def ProfileInstrUnprofiled : DiagGroup<"profile-instr-unprofiled">;
-def MisExpect : DiagGroup<"misexpect">;
 
 // AddressSanitizer frontend instrumentation remarks.
 def SanitizeAddressRemarks : DiagGroup<"sanitize-address">;

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=371598&r1=371597&r2=371598&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Wed Sep 11 02:16:17 2019
@@ -14,7 +14,6 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclGroup.h"
-#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangStandard.h"
 #include "clang/Basic/SourceManager.h"
@@ -366,9 +365,6 @@ namespace clang {
 bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D);
 /// Specialized handler for unsupported backend feature diagnostic.
 void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D);
-/// Specialized handler for misexpect warnings.
-/// Note that misexpect remarks are emitted through ORE
-void MisExpectDiagHandler(const llvm::DiagnosticInfoMisExpect &D);
 /// Specialized handlers for optimization remarks.
 /// Note that these handlers only accept remarks and they always handle
 /// them.
@@ -621,25 +617,6 @@ void BackendConsumer::UnsupportedDiagHan
 << Filename << Line << Column;
 }
 
-void Backend

r371723 - Removed dead code from DiagnosticBuilder

2019-09-12 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Sep 12 03:39:53 2019
New Revision: 371723

URL: http://llvm.org/viewvc/llvm-project?rev=371723&view=rev
Log:
Removed dead code from DiagnosticBuilder

Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=371723&r1=371722&r2=371723&view=diff
==
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Sep 12 03:39:53 2019
@@ -1127,11 +1127,6 @@ public:
 Emit();
   }
 
-  /// Retrieve an empty diagnostic builder.
-  static DiagnosticBuilder getEmpty() {
-return {};
-  }
-
   /// Forces the diagnostic to be emitted.
   const DiagnosticBuilder &setForceEmit() const {
 IsForceEmit = true;


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


r371731 - Removed some questionable default arguments from setters

2019-09-12 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Sep 12 05:16:43 2019
New Revision: 371731

URL: http://llvm.org/viewvc/llvm-project?rev=371731&view=rev
Log:
Removed some questionable default arguments from setters

Summary:
They can be confusing -- what does it mean to call a setter without a
value? Also, some setters, like `setPrintTemplateTree` had `false` as
the default value!

The callers are largely not using these default arguments anyway.

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/ARCMigrate/ARCMT.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Sema/Sema.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=371731&r1=371730&r2=371731&view=diff
==
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Sep 12 05:16:43 2019
@@ -632,24 +632,22 @@ public:
   /// Suppress all diagnostics, to silence the front end when we
   /// know that we don't want any more diagnostics to be passed along to the
   /// client
-  void setSuppressAllDiagnostics(bool Val = true) {
-SuppressAllDiagnostics = Val;
-  }
+  void setSuppressAllDiagnostics(bool Val) { SuppressAllDiagnostics = Val; }
   bool getSuppressAllDiagnostics() const { return SuppressAllDiagnostics; }
 
   /// Set type eliding, to skip outputting same types occurring in
   /// template types.
-  void setElideType(bool Val = true) { ElideType = Val; }
+  void setElideType(bool Val) { ElideType = Val; }
   bool getElideType() { return ElideType; }
 
   /// Set tree printing, to outputting the template difference in a
   /// tree format.
-  void setPrintTemplateTree(bool Val = false) { PrintTemplateTree = Val; }
+  void setPrintTemplateTree(bool Val) { PrintTemplateTree = Val; }
   bool getPrintTemplateTree() { return PrintTemplateTree; }
 
   /// Set color printing, so the type diffing will inject color markers
   /// into the output.
-  void setShowColors(bool Val = false) { ShowColors = Val; }
+  void setShowColors(bool Val) { ShowColors = Val; }
   bool getShowColors() { return ShowColors; }
 
   /// Specify which overload candidates to show when overload resolution
@@ -667,7 +665,7 @@ public:
   /// the middle of another diagnostic.
   ///
   /// This can be used by clients who suppress diagnostics themselves.
-  void setLastDiagnosticIgnored(bool Ignored = true) {
+  void setLastDiagnosticIgnored(bool Ignored) {
 if (LastDiagLevel == DiagnosticIDs::Fatal)
   FatalErrorOccurred = true;
 LastDiagLevel = Ignored ? DiagnosticIDs::Ignored : DiagnosticIDs::Warning;

Modified: cfe/trunk/lib/ARCMigrate/ARCMT.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMT.cpp?rev=371731&r1=371730&r2=371731&view=diff
==
--- cfe/trunk/lib/ARCMigrate/ARCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ARCMT.cpp Thu Sep 12 05:16:43 2019
@@ -139,7 +139,7 @@ public:
 }
 
 // Non-ARC warnings are ignored.
-Diags.setLastDiagnosticIgnored();
+Diags.setLastDiagnosticIgnored(true);
   }
 };
 

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=371731&r1=371730&r2=371731&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Thu Sep 12 05:16:43 2019
@@ -928,7 +928,7 @@ void PrintDependencyDirectivesSourceMini
 // 'expected' comments.
 if (CI.getDiagnosticOpts().VerifyDiagnostics) {
   // Make sure we don't emit new diagnostics!
-  CI.getDiagnostics().setSuppressAllDiagnostics();
+  CI.getDiagnostics().setSuppressAllDiagnostics(true);
   Preprocessor &PP = getCompilerInstance().getPreprocessor();
   PP.EnterMainSourceFile();
   Token Tok;

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=371731&r1=371730&r2=371731&view=diff
==
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Thu Sep 12 05:16:43 2019
@@ -1307,7 +1307,7 @@ void Sema::EmitCurrentDiagnostic(unsigne
PartialDiagnostic(DiagInfo, 
Context.getDiagAllocator()));
   }
 
-  Diags.setLastDiagnosticIgnored();
+  Diags.setLastDiagnosticIgnored(true);
   Diags.Clear();
   return;
 
@@ -1332,7 +1332,7 @@ void Sema::EmitCurrentDiagnostic(unsigne
PartialDiagnostic(DiagInfo, 
Context.getDiagAllocator()));
   }
 
-  Diags.setLastDiagnosticIgnored();
+  Diags.setLastDia

[clang-tools-extra] r372388 - [clang-tidy] Fix relative path in header-filter.

2019-09-20 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri Sep 20 06:19:32 2019
New Revision: 372388

URL: http://llvm.org/viewvc/llvm-project?rev=372388&view=rev
Log:
[clang-tidy] Fix relative path in header-filter.

Summary:
Clang-tidy supports output diagnostics from header files if user
specifies --header-filter. But it can't handle relative path well.
For example, the folder structure of a project is:

```
// a.h is in /src/a/a.h

// b.h is in /src/b/b.h
...

// c.cpp is in /src/c.cpp

```

Now, we set --header-filter as --header-filter=/a/. That means we only
want to check header files under /src/a/ path, and ignore header files
uder /src/b/ path, but in current implementation, clang-tidy will check
/src/b/b.h also, because the name of b.h used in clang-tidy is
/src/a/../b/b.h.

This change tries to fix this issue.

Reviewers: alexfh, hokein, aaron.ballman, gribozavr

Reviewed By: gribozavr

Subscribers: MyDeveloperDay, xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

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

Patch by Yubo Xie.

Added:
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_a/

clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_a/header_a.h
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_b/

clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_b/header_b.h
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_c/

clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_c/header_c.h
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=372388&r1=372387&r2=372388&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Fri Sep 
20 06:19:32 2019
@@ -551,7 +551,9 @@ void ClangTidyDiagnosticConsumer::checkF
 return;
   }
 
-  StringRef FileName(File->getName());
+  StringRef FileName = File->tryGetRealPathName();
+  if (FileName.empty())
+FileName = File->getName();
   LastErrorRelatesToUserCode = LastErrorRelatesToUserCode ||
Sources.isInMainFile(Location) ||
getHeaderFilter()->match(FileName);

Added: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_a/header_a.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_a/header_a.h?rev=372388&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_a/header_a.h
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_a/header_a.h
 Fri Sep 20 06:19:32 2019
@@ -0,0 +1,3 @@
+#include "../subfolder_b/header_b.h"
+
+class SA { SA(int); };

Added: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_b/header_b.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_b/header_b.h?rev=372388&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_b/header_b.h
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_b/header_b.h
 Fri Sep 20 06:19:32 2019
@@ -0,0 +1 @@
+class SB { SB(int); };

Added: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_c/header_c.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_c/header_c.h?rev=372388&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_c/header_c.h
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_c/header_c.h
 Fri Sep 20 06:19:32 2019
@@ -0,0 +1 @@
+class SC { SC(int); };

Modified: clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp?rev=372388&r1=372387&r2=372388&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp Fri Sep 20 06:19:32 
2019
@@ -9,6 +9,12 @@
 //   file-filter\header*.h due to code order between '/' and '\\'.
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='.*' -system-headers %s -- -I %S/Inputs/file-filter/system/.. 
-isyst

[clang-tools-extra] r372593 - Removed an incorred namespace-end comment

2019-09-23 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Sep 23 05:07:10 2019
New Revision: 372593

URL: http://llvm.org/viewvc/llvm-project?rev=372593&view=rev
Log:
Removed an incorred namespace-end comment

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp?rev=372593&r1=372592&r2=372593&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ArgumentCommentCheck.cpp Mon 
Sep 23 05:07:10 2019
@@ -324,7 +324,7 @@ void ArgumentCommentCheck::checkCallArgs
   << FixItHint::CreateInsertion(Args[I]->getBeginLoc(), ArgComment);
 }
   }
-} // namespace bugprone
+}
 
 void ArgumentCommentCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *E = Result.Nodes.getNodeAs("expr");


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


r372594 - Removed dead code from Stencil.h

2019-09-23 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Sep 23 05:15:48 2019
New Revision: 372594

URL: http://llvm.org/viewvc/llvm-project?rev=372594&view=rev
Log:
Removed dead code from Stencil.h

Modified:
cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h

Modified: cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h?rev=372594&r1=372593&r2=372594&view=diff
==
--- cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h (original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h Mon Sep 23 05:15:48 
2019
@@ -153,16 +153,6 @@ inline StencilPart node(llvm::StringRef
   return selection(tooling::node(Id));
 }
 
-/// Variant of \c node() that identifies the node as a statement, for purposes
-/// of deciding whether to include any trailing semicolon.  Only relevant for
-/// Expr nodes, which, by default, are *not* considered as statements.
-/// \returns the source corresponding to the identified node, considered as a
-/// statement.
-/// FIXME: Deprecated. Write `selection(statement(Id))` instead.
-inline StencilPart sNode(llvm::StringRef Id) {
-  return selection(tooling::statement(Id));
-}
-
 /// For debug use only; semantics are not guaranteed.
 ///
 /// \returns the string resulting from calling the node's print() method.


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


[clang-tools-extra] r372601 - Revert "[clang-tidy] Fix relative path in header-filter."

2019-09-23 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Sep 23 06:06:25 2019
New Revision: 372601

URL: http://llvm.org/viewvc/llvm-project?rev=372601&view=rev
Log:
Revert "[clang-tidy] Fix relative path in header-filter."

This reverts commit r372388. It made '-header-filter' inconsistent with
paths printed in diagnostics.

Removed:
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_a/
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_b/
clang-tools-extra/trunk/test/clang-tidy/Inputs/file-filter/subfolder_c/
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=372601&r1=372600&r2=372601&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Mon Sep 
23 06:06:25 2019
@@ -551,9 +551,7 @@ void ClangTidyDiagnosticConsumer::checkF
 return;
   }
 
-  StringRef FileName = File->tryGetRealPathName();
-  if (FileName.empty())
-FileName = File->getName();
+  StringRef FileName(File->getName());
   LastErrorRelatesToUserCode = LastErrorRelatesToUserCode ||
Sources.isInMainFile(Location) ||
getHeaderFilter()->match(FileName);

Modified: clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp?rev=372601&r1=372600&r2=372601&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp Mon Sep 23 06:06:25 
2019
@@ -9,12 +9,6 @@
 //   file-filter\header*.h due to code order between '/' and '\\'.
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='.*' -system-headers %s -- -I %S/Inputs/file-filter/system/.. 
-isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4 %s
 // RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='.*' -system-headers -quiet %s -- -I 
%S/Inputs/file-filter/system/.. -isystem %S/Inputs/file-filter/system 2>&1 | 
FileCheck --check-prefix=CHECK4-QUIET %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='subfolder_a' %s -- -I %S/Inputs/file-filter -isystem 
%S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK5 %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='subfolder_a' -quiet %s -- -I %S/Inputs/file-filter -isystem 
%S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK5-QUIET %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='subfolder_b' %s -- -I %S/Inputs/file-filter -isystem 
%S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK6 %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='subfolder_b' -quiet %s -- -I %S/Inputs/file-filter -isystem 
%S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK6-QUIET %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='subfolder_c' %s -- -I %S/Inputs/file-filter -isystem 
%S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK7 %s
-// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='subfolder_c' -quiet %s -- -I %S/Inputs/file-filter -isystem 
%S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK7-QUIET %s
 
 #include "header1.h"
 // CHECK-NOT: warning:
@@ -25,12 +19,6 @@
 // CHECK3-QUIET-NOT: warning:
 // CHECK4: header1.h:1:12: warning: single-argument constructors
 // CHECK4-QUIET: header1.h:1:12: warning: single-argument constructors
-// CHECK5-NOT: warning:
-// CHECK5-QUIET-NOT: warning:
-// CHECK6-NOT: warning:
-// CHECK6-QUIET-NOT: warning:
-// CHECK7-NOT: warning:
-// CHECK7-QUIET-NOT: warning:
 
 #include "header2.h"
 // CHECK-NOT: warning:
@@ -41,44 +29,6 @@
 // CHECK3-QUIET: header2.h:1:12: warning: single-argument constructors
 // CHECK4: header2.h:1:12: warning: single-argument constructors
 // CHECK4-QUIET: header2.h:1:12: warning: single-argument constructors
-// CHECK5-NOT: warning:
-// CHECK5-QUIET-NOT: warning:
-// CHECK6-NOT: warning:
-// CHECK6-QUIET-NOT: warning:
-// CHECK7-NOT: warning:
-// CHECK7-QUIET-NOT: warning:
-
-#include "subfolder_a/header_a.h"
-// CHECK-NOT: warning:
-// CHECK-QUIET-NOT: warning:
-// CHECK2: header_b.h:1:12: warning: single-argument constructors must be 
marked explicit
-// CHECK2-QUIET: header_b.h:1:12: warning: single-argument constructors must 
be marked explicit
-// CHECK3-NOT: warning:
-// CHECK3-

[clang-tools-extra] r372607 - Added a test for agreement between paths used in ClangTidy's diagnostics and header filter

2019-09-23 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Mon Sep 23 06:44:42 2019
New Revision: 372607

URL: http://llvm.org/viewvc/llvm-project?rev=372607&view=rev
Log:
Added a test for agreement between paths used in ClangTidy's diagnostics and 
header filter

This test would have been broken by r372388.

Added:
clang-tools-extra/trunk/test/clang-tidy/file-filter-symlinks.cpp

Added: clang-tools-extra/trunk/test/clang-tidy/file-filter-symlinks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/file-filter-symlinks.cpp?rev=372607&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/file-filter-symlinks.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/file-filter-symlinks.cpp Mon Sep 23 
06:44:42 2019
@@ -0,0 +1,19 @@
+// REQUIRES: shell
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/dir1/dir2
+// RUN: echo 'class A { A(int); };' > %t/dir1/header.h
+// RUN: ln -s %t/dir1/header.h %t/dir1/header_alias.h
+//
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='dir1/dir2/\.\./header_alias\.h' %s -- -I %t 2>&1 | FileCheck 
--check-prefix=CHECK_HEADER_ALIAS %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='dir1/dir2/\.\./header_alias\.h' -quiet %s -- -I %t 2>&1 | 
FileCheck --check-prefix=CHECK_HEADER_ALIAS %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='header_alias\.h' %s -- -I %t 2>&1 | FileCheck 
--check-prefix=CHECK_HEADER_ALIAS %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='header_alias\.h' -quiet %s -- -I %t 2>&1 | FileCheck 
--check-prefix=CHECK_HEADER_ALIAS %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='header\.h' %s -- -I %t 2>&1 | FileCheck 
--check-prefix=CHECK_HEADER %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' 
-header-filter='header\.h' -quiet %s -- -I %t 2>&1 | FileCheck 
--check-prefix=CHECK_HEADER %s
+
+// Check that `-header-filter` operates on the same file paths as paths in
+// diagnostics printed by ClangTidy.
+#include "dir1/dir2/../header_alias.h"
+// CHECK_HEADER_ALIAS: dir1/dir2/../header_alias.h:1:11: warning: 
single-argument constructors
+// CHECK_HEADER-NOT: warning:


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


[clang-tools-extra] r372978 - Use std::unique_ptr in ClangTidyCheckFactories

2019-09-26 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Sep 26 06:47:29 2019
New Revision: 372978

URL: http://llvm.org/viewvc/llvm-project?rev=372978&view=rev
Log:
Use std::unique_ptr in ClangTidyCheckFactories

I had to explicitly define some destructors that could only be defined
in the corresponding .cpp files.

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h?rev=372978&r1=372977&r2=372978&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h Thu Sep 26 06:47:29 
2019
@@ -13,6 +13,7 @@
 #include "llvm/ADT/StringRef.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -25,9 +26,8 @@ namespace tidy {
 /// this object.
 class ClangTidyCheckFactories {
 public:
-  typedef std::function
-  CheckFactory;
+  using CheckFactory = std::function(
+  StringRef Name, ClangTidyContext *Context)>;
 
   /// Registers check \p Factory with name \p Name.
   ///
@@ -58,7 +58,7 @@ public:
   template  void registerCheck(StringRef CheckName) {
 registerCheckFactory(CheckName,
  [](StringRef Name, ClangTidyContext *Context) {
-   return new CheckType(Name, Context);
+   return std::make_unique(Name, Context);
  });
   }
 

Modified: clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp?rev=372978&r1=372977&r2=372978&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp Thu Sep 26 
06:47:29 2019
@@ -55,6 +55,8 @@ TodoCommentCheck::TodoCommentCheck(Strin
   Handler(std::make_unique(
   *this, Context->getOptions().User)) {}
 
+TodoCommentCheck::~TodoCommentCheck() = default;
+
 void TodoCommentCheck::registerPPCallbacks(const SourceManager &SM,
Preprocessor *PP,
Preprocessor *ModuleExpanderPP) {

Modified: clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h?rev=372978&r1=372977&r2=372978&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h Thu Sep 26 
06:47:29 2019
@@ -22,6 +22,8 @@ namespace readability {
 class TodoCommentCheck : public ClangTidyCheck {
 public:
   TodoCommentCheck(StringRef Name, ClangTidyContext *Context);
+  ~TodoCommentCheck();
+
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
 

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=372978&r1=372977&r2=372978&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
Thu Sep 26 06:47:29 2019
@@ -193,6 +193,8 @@ IdentifierNamingCheck::IdentifierNamingC
   IgnoreFailedSplit = Options.get("IgnoreFailedSplit", 0);
 }
 
+IdentifierNamingCheck::~IdentifierNamingCheck() = default;
+
 void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   auto const toString = [](CaseType Type) {
 switch (Type) {

Modified: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h?rev=372978&r1=372977&r2=372978&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h Thu 
Sep 26 06:47:29 2019
@@ -34,6 +34,7 @@ namespace readability {
 class IdentifierNamingCheck : public ClangTidyCheck {
 public:
   IdentifierNamingCheck(StringRef Name

[clang-tools-extra] r372979 - Return results by value from ClangTidyCheckFactories::createChecks

2019-09-26 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Sep 26 06:55:01 2019
New Revision: 372979

URL: http://llvm.org/viewvc/llvm-project?rev=372979&view=rev
Log:
Return results by value from ClangTidyCheckFactories::createChecks

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
clang-tools-extra/trunk/clangd/ParsedAST.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=372979&r1=372978&r2=372979&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu Sep 26 06:55:01 2019
@@ -384,8 +384,8 @@ ClangTidyASTConsumerFactory::CreateASTCo
   if (WorkingDir)
 Context.setCurrentBuildDirectory(WorkingDir.get());
 
-  std::vector> Checks;
-  CheckFactories->createChecks(&Context, Checks);
+  std::vector> Checks =
+  CheckFactories->createChecks(&Context);
 
   ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
 
@@ -459,8 +459,8 @@ std::vector ClangTidyASTCon
 
 ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
   ClangTidyOptions::OptionMap Options;
-  std::vector> Checks;
-  CheckFactories->createChecks(&Context, Checks);
+  std::vector> Checks =
+  CheckFactories->createChecks(&Context);
   for (const auto &Check : Checks)
 Check->storeOptions(Options);
   return Options;

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp?rev=372979&r1=372978&r2=372979&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp Thu Sep 26 06:55:01 
2019
@@ -20,13 +20,14 @@ void ClangTidyCheckFactories::registerCh
   Factories[Name] = std::move(Factory);
 }
 
-void ClangTidyCheckFactories::createChecks(
-ClangTidyContext *Context,
-std::vector> &Checks) {
+std::vector>
+ClangTidyCheckFactories::createChecks(ClangTidyContext *Context) {
+  std::vector> Checks;
   for (const auto &Factory : Factories) {
 if (Context->isCheckEnabled(Factory.first))
   Checks.emplace_back(Factory.second(Factory.first, Context));
   }
+  return Checks;
 }
 
 ClangTidyOptions ClangTidyModule::getModuleOptions() {

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h?rev=372979&r1=372978&r2=372979&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h Thu Sep 26 06:55:01 
2019
@@ -62,12 +62,9 @@ public:
  });
   }
 
-  /// Create instances of all checks matching \p CheckRegexString and
-  /// store them in \p Checks.
-  ///
-  /// The caller takes ownership of the return \c ClangTidyChecks.
-  void createChecks(ClangTidyContext *Context,
-std::vector> &Checks);
+  /// Create instances of checks that are enabled.
+  std::vector>
+  createChecks(ClangTidyContext *Context);
 
   typedef std::map FactoryMap;
   FactoryMap::const_iterator begin() const { return Factories.begin(); }

Modified: clang-tools-extra/trunk/clangd/ParsedAST.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ParsedAST.cpp?rev=372979&r1=372978&r2=372979&view=diff
==
--- clang-tools-extra/trunk/clangd/ParsedAST.cpp (original)
+++ clang-tools-extra/trunk/clangd/ParsedAST.cpp Thu Sep 26 06:55:01 2019
@@ -261,7 +261,7 @@ ParsedAST::build(std::unique_ptrsetDiagnosticsEngine(&Clang->getDiagnostics());
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
-CTFactories.createChecks(CTContext.getPointer(), CTChecks);
+CTChecks = CTFactories.createChecks(CTContext.getPointer());
 ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) {
   if (CTContext) {


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


[clang-tools-extra] r373032 - Revert "[clang-tidy] New check to warn when storing dispatch_once_t in non-static, non-global storage"

2019-09-26 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Sep 26 16:28:31 2019
New Revision: 373032

URL: http://llvm.org/viewvc/llvm-project?rev=373032&view=rev
Log:
Revert "[clang-tidy] New check to warn when storing dispatch_once_t in 
non-static, non-global storage"

This reverts commit r373028, because the new test fails on Linux.

Removed:
clang-tools-extra/trunk/clang-tidy/darwin/

clang-tools-extra/trunk/docs/clang-tidy/checks/darwin-dispatch-once-nonstatic.rst
clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h
clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=373032&r1=373031&r2=373032&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Thu Sep 26 16:28:31 2019
@@ -43,7 +43,6 @@ add_subdirectory(boost)
 add_subdirectory(bugprone)
 add_subdirectory(cert)
 add_subdirectory(cppcoreguidelines)
-add_subdirectory(darwin)
 add_subdirectory(fuchsia)
 add_subdirectory(google)
 add_subdirectory(hicpp)

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h?rev=373032&r1=373031&r2=373032&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h Thu Sep 26 
16:28:31 2019
@@ -50,11 +50,6 @@ extern volatile int CppCoreGuidelinesMod
 static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
 CppCoreGuidelinesModuleAnchorSource;
 
-// This anchor is used to force the linker to link the DarwinModule.
-extern volatile int DarwinModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED DarwinModuleAnchorDestination =
-DarwinModuleAnchorSource;
-
 // This anchor is used to force the linker to link the FuchsiaModule.
 extern volatile int FuchsiaModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination =

Modified: clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt?rev=373032&r1=373031&r2=373032&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt Thu Sep 26 
16:28:31 2019
@@ -14,7 +14,6 @@ add_clang_library(clangTidyPlugin
   clangTidyBugproneModule
   clangTidyCERTModule
   clangTidyCppCoreGuidelinesModule
-  clangTidyDarwinModule
   clangTidyFuchsiaModule
   clangTidyGoogleModule
   clangTidyHICPPModule

Modified: clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt?rev=373032&r1=373031&r2=373032&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt Thu Sep 26 16:28:31 
2019
@@ -23,7 +23,6 @@ target_link_libraries(clang-tidy
   clangTidyBugproneModule
   clangTidyCERTModule
   clangTidyCppCoreGuidelinesModule
-  clangTidyDarwinModule
   clangTidyFuchsiaModule
   clangTidyGoogleModule
   clangTidyHICPPModule

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=373032&r1=373031&r2=373032&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Sep 26 16:28:31 2019
@@ -123,7 +123,6 @@ add_clang_library(clangDaemon
   clangTidyBugproneModule
   clangTidyCERTModule
   clangTidyCppCoreGuidelinesModule
-  clangTidyDarwinModule
   clangTidyFuchsiaModule
   clangTidyGoogleModule
   clangTidyHICPPModule

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=373032&r1=373031&r2=373032&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Se

[clang-tools-extra] r373065 - [clang-tidy] New check to warn when storing dispatch_once_t in non-static, non-global storage.

2019-09-27 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri Sep 27 03:49:12 2019
New Revision: 373065

URL: http://llvm.org/viewvc/llvm-project?rev=373065&view=rev
Log:
[clang-tidy] New check to warn when storing dispatch_once_t in non-static, 
non-global storage.

Summary:
Creates a new darwin ClangTidy module and adds the 
darwin-dispatch-once-nonstatic check that warns about dispatch_once_t variables 
not in static or global storage. This catches a missing static for local 
variables in e.g. singleton initialization behavior, and also warns on storing 
dispatch_once_t values in Objective-C instance variables. C/C++ struct/class 
instances may potentially live in static/global storage, and are ignored for 
this check.

The osx.API static analysis checker can find the non-static storage use of 
dispatch_once_t; I thought it useful to also catch this issue in clang-tidy 
when possible.

This is a re-land of https://reviews.llvm.org/D67567

Reviewers: thakis, gribozavr, stephanemoore

Subscribers: Eugene.Zelenko, mgorny, xazax.hun, jkorous, arphaman, kadircet, 
usaxena95

Tags: #clang-tools-extra, #clang, #llvm

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

Added:
clang-tools-extra/trunk/clang-tidy/darwin/
clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/darwin/DispatchOnceNonstaticCheck.cpp
clang-tools-extra/trunk/clang-tidy/darwin/DispatchOnceNonstaticCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/darwin-dispatch-once-nonstatic.rst
clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h
clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=373065&r1=373064&r2=373065&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Fri Sep 27 03:49:12 2019
@@ -43,6 +43,7 @@ add_subdirectory(boost)
 add_subdirectory(bugprone)
 add_subdirectory(cert)
 add_subdirectory(cppcoreguidelines)
+add_subdirectory(darwin)
 add_subdirectory(fuchsia)
 add_subdirectory(google)
 add_subdirectory(hicpp)

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h?rev=373065&r1=373064&r2=373065&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h Fri Sep 27 
03:49:12 2019
@@ -50,6 +50,11 @@ extern volatile int CppCoreGuidelinesMod
 static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
 CppCoreGuidelinesModuleAnchorSource;
 
+// This anchor is used to force the linker to link the DarwinModule.
+extern volatile int DarwinModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED DarwinModuleAnchorDestination =
+DarwinModuleAnchorSource;
+
 // This anchor is used to force the linker to link the FuchsiaModule.
 extern volatile int FuchsiaModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination =

Added: clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt?rev=373065&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt Fri Sep 27 
03:49:12 2019
@@ -0,0 +1,15 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyDarwinModule
+  DarwinTidyModule.cpp
+  DispatchOnceNonstaticCheck.cpp
+
+  LINK_LIBS
+  clangAnalysis
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangLex
+  clangTidy
+  clangTidyUtils
+  )

Added: clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp?rev=373065&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp Fri Sep 27 
03:49:12 2019
@@ -0,0 +1,37 @@
+//===--- MiscTidyModule.cpp - clang-tidy 
--===//
+//
+// Part 

[clang-tools-extra] r373066 - Moved -fblocks from an individual test to check_clang_tidy.py

2019-09-27 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri Sep 27 03:54:28 2019
New Revision: 373066

URL: http://llvm.org/viewvc/llvm-project?rev=373066&view=rev
Log:
Moved -fblocks from an individual test to check_clang_tidy.py

This way, all tests will benefit from it and will not have to worry
about setting up language options properly.

Modified:
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=373066&r1=373065&r2=373066&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Fri Sep 27 
03:54:28 2019
@@ -69,7 +69,8 @@ def run_test_once(args, extra_args):
 clang_tidy_extra_args.append('-format-style=none')
 
   if extension in ['.m', '.mm']:
-clang_extra_args = ['-fobjc-abi-version=2', '-fobjc-arc'] + 
clang_extra_args
+clang_extra_args = ['-fobjc-abi-version=2', '-fobjc-arc', '-fblocks'] + \
+clang_extra_args
 
   if extension in ['.cpp', '.hpp', '.mm']:
 clang_extra_args.append('-std=' + std)

Modified: 
clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm?rev=373066&r1=373065&r2=373066&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm 
Fri Sep 27 03:54:28 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s darwin-dispatch-once-nonstatic %t -- -- -fblocks
+// RUN: %check_clang_tidy %s darwin-dispatch-once-nonstatic %t
 
 typedef int dispatch_once_t;
 extern void dispatch_once(dispatch_once_t *pred, void(^block)(void));


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


[clang-tools-extra] r373068 - Fixed indentation in a ClangTidy test

2019-09-27 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri Sep 27 03:58:10 2019
New Revision: 373068

URL: http://llvm.org/viewvc/llvm-project?rev=373068&view=rev
Log:
Fixed indentation in a ClangTidy test

Modified:

clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm

Modified: 
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm?rev=373068&r1=373067&r2=373068&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm
 Fri Sep 27 03:58:10 2019
@@ -6,5 +6,5 @@ static NSString* const myConstString = @
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
 class MyTest {
-static int not_objc_style;
+  static int not_objc_style;
 };


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


[clang-tools-extra] r373304 - [clang-tidy] Fix module registry name and description for Darwin clang-tidy module.

2019-10-01 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Tue Oct  1 00:17:26 2019
New Revision: 373304

URL: http://llvm.org/viewvc/llvm-project?rev=373304&view=rev
Log:
[clang-tidy] Fix module registry name and description for Darwin clang-tidy 
module.

Summary: When creating the module, must have copy-pasted from the misc module, 
and forgotten to update the name/description of the module in the registry.

Reviewers: stephanemoore, benhamilton, gribozavr

Reviewed By: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra, #llvm

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

Modified:
clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp

Modified: clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp?rev=373304&r1=373303&r2=373304&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp Tue Oct  1 
00:17:26 2019
@@ -27,7 +27,7 @@ public:
 
 // Register the DarwinTidyModule using this statically initialized variable.
 static ClangTidyModuleRegistry::Add
-X("misc-module", "Adds miscellaneous lint checks.");
+X("darwin-module", "Adds Darwin-specific lint checks.");
 
 // This anchor is used to force the linker to link in the generated object file
 // and thus register the DarwinModule.


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


[clang-tools-extra] r374549 - [ClangTidy] Separate tests for infrastructure and checkers, fixup

2019-10-11 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri Oct 11 06:16:49 2019
New Revision: 374549

URL: http://llvm.org/viewvc/llvm-project?rev=374549&view=rev
Log:
[ClangTidy] Separate tests for infrastructure and checkers, fixup

Renamed a file that I missed in r374540.

Added:
clang-tools-extra/trunk/test/clang-tidy/checkers/Inputs/Headers/stdio.h
Removed:

clang-tools-extra/trunk/test/clang-tidy/infrastructure/Inputs/Headers/stdio.h

Added: clang-tools-extra/trunk/test/clang-tidy/checkers/Inputs/Headers/stdio.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/checkers/Inputs/Headers/stdio.h?rev=374549&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/checkers/Inputs/Headers/stdio.h 
(added)
+++ clang-tools-extra/trunk/test/clang-tidy/checkers/Inputs/Headers/stdio.h Fri 
Oct 11 06:16:49 2019
@@ -0,0 +1,18 @@
+//===--- stdio.h - Stub header for tests *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _STDIO_H_
+#define _STDIO_H_
+
+// A header intended to contain C standard input and output library
+// declarations.
+
+int printf(const char *, ...);
+
+#endif // _STDIO_H_
+

Removed: 
clang-tools-extra/trunk/test/clang-tidy/infrastructure/Inputs/Headers/stdio.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/infrastructure/Inputs/Headers/stdio.h?rev=374548&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/infrastructure/Inputs/Headers/stdio.h 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/infrastructure/Inputs/Headers/stdio.h 
(removed)
@@ -1,18 +0,0 @@
-//===--- stdio.h - Stub header for tests *- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef _STDIO_H_
-#define _STDIO_H_
-
-// A header intended to contain C standard input and output library
-// declarations.
-
-int printf(const char *, ...);
-
-#endif // _STDIO_H_
-


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


[clang-tools-extra] r374551 - Updated add_new_check.py to create checker tests in the new directory

2019-10-11 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Fri Oct 11 06:46:55 2019
New Revision: 374551

URL: http://llvm.org/viewvc/llvm-project?rev=374551&view=rev
Log:
Updated add_new_check.py to create checker tests in the new directory

Modified:
clang-tools-extra/trunk/clang-tidy/add_new_check.py

Modified: clang-tools-extra/trunk/clang-tidy/add_new_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/add_new_check.py?rev=374551&r1=374550&r2=374551&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py Fri Oct 11 06:46:55 2019
@@ -269,7 +269,7 @@ def add_release_notes(module_path, modul
 # Adds a test for the check.
 def write_test(module_path, module, check_name, test_extension):
   check_name_dashes = module + '-' + check_name
-  filename = os.path.normpath(os.path.join(module_path, 
'../../test/clang-tidy',
+  filename = os.path.normpath(os.path.join(module_path, 
'../../test/clang-tidy/checkers',
check_name_dashes + '.' + 
test_extension))
   print('Creating %s...' % filename)
   with open(filename, 'w') as f:


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


[clang] 3785eb8 - Add support for binary operators in Syntax Trees

2020-05-26 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-05-26T12:25:58+02:00
New Revision: 3785eb83af4161bd52ed993ef3a2184c998071e6

URL: 
https://github.com/llvm/llvm-project/commit/3785eb83af4161bd52ed993ef3a2184c998071e6
DIFF: 
https://github.com/llvm/llvm-project/commit/3785eb83af4161bd52ed993ef3a2184c998071e6.diff

LOG: Add support for binary operators in Syntax Trees

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index f4d482bb848c..5db99d4b9e35 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -40,6 +40,7 @@ enum class NodeKind : uint16_t {
 
   // Expressions.
   UnknownExpression,
+  BinaryOperatorExpression,
 
   // Statements.
   UnknownStatement,
@@ -104,6 +105,9 @@ enum class NodeRole : uint8_t {
   BodyStatement,
 
   // Roles specific to particular node kinds.
+  BinaryOperatorExpression_leftHandSide,
+  BinaryOperatorExpression_operatorToken,
+  BinaryOperatorExpression_rightHandSide,
   CaseStatement_value,
   IfStatement_thenStatement,
   IfStatement_elseKeyword,
@@ -158,6 +162,24 @@ class UnknownExpression final : public Expression {
   }
 };
 
+///   
+///
+/// For example:
+///   a + b
+///   a bitor 1
+///   a |= b
+///   a and_eq b
+class BinaryOperatorExpression final : public Expression {
+public:
+  BinaryOperatorExpression() : Expression(NodeKind::BinaryOperatorExpression) 
{}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::BinaryOperatorExpression;
+  }
+  syntax::Expression *lhs();
+  syntax::Leaf *operatorToken();
+  syntax::Expression *rhs();
+};
+
 /// An abstract node for C++ statements, e.g. 'while', 'if', etc.
 /// FIXME: add accessors for semicolon of statements that have it.
 class Statement : public Tree {

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 11058edec615..8fee44cdbf10 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TypeLoc.h"
@@ -594,10 +595,7 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   for (auto *D : DS->decls())
 Builder.noticeDeclWithoutSemicolon(D);
 } else if (auto *E = llvm::dyn_cast_or_null(S)) {
-  // Do not recurse into subexpressions.
-  // We do not have syntax trees for expressions yet, so we only want to 
see
-  // the first top-level expression.
-  return WalkUpFromExpr(E->IgnoreImplicit());
+  return RecursiveASTVisitor::TraverseStmt(E->IgnoreImplicit());
 }
 return RecursiveASTVisitor::TraverseStmt(S);
   }
@@ -610,6 +608,19 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool WalkUpFromBinaryOperator(BinaryOperator *S) {
+Builder.markExprChild(
+S->getLHS(), syntax::NodeRole::BinaryOperatorExpression_leftHandSide);
+Builder.markChildToken(
+S->getOperatorLoc(),
+syntax::NodeRole::BinaryOperatorExpression_operatorToken);
+Builder.markExprChild(
+S->getRHS(), syntax::NodeRole::BinaryOperatorExpression_rightHandSide);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::BinaryOperatorExpression, S);
+return true;
+  }
+
   bool WalkUpFromNamespaceDecl(NamespaceDecl *S) {
 auto Tokens = Builder.getDeclarationRange(S);
 if (Tokens.front().kind() == tok::coloncolon) {

diff  --git a/clang/lib/Tooling/Syntax/Nodes.cpp 
b/clang/lib/Tooling/Syntax/Nodes.cpp
index 75f025e5f853..84c0143db81d 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, 
NodeKind K) {
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::BinaryOperatorExpression:
+return OS << "BinaryOperatorExpression";
   case NodeKind::UnknownStatement:
 return OS << "UnknownStatement";
   case NodeKind::DeclarationStatement:
@@ -110,6 +112,12 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream 
&OS, NodeRole R) {
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
+  case syntax::NodeRole::BinaryOperatorEx

[clang] 461af57 - Add support for UnaryOperator in SyntaxTree

2020-05-27 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-05-27T17:12:46+02:00
New Revision: 461af57de78155ee5d1dc1969b81dd019d228538

URL: 
https://github.com/llvm/llvm-project/commit/461af57de78155ee5d1dc1969b81dd019d228538
DIFF: 
https://github.com/llvm/llvm-project/commit/461af57de78155ee5d1dc1969b81dd019d228538.diff

LOG: Add support for UnaryOperator in SyntaxTree

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index 5db99d4b9e35..e240becbf883 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -40,6 +40,8 @@ enum class NodeKind : uint16_t {
 
   // Expressions.
   UnknownExpression,
+  PrefixUnaryOperatorExpression,
+  PostfixUnaryOperatorExpression,
   BinaryOperatorExpression,
 
   // Statements.
@@ -105,6 +107,8 @@ enum class NodeRole : uint8_t {
   BodyStatement,
 
   // Roles specific to particular node kinds.
+  UnaryOperatorExpression_operatorToken,
+  UnaryOperatorExpression_operand,
   BinaryOperatorExpression_leftHandSide,
   BinaryOperatorExpression_operatorToken,
   BinaryOperatorExpression_rightHandSide,
@@ -162,6 +166,50 @@ class UnknownExpression final : public Expression {
   }
 };
 
+/// An abstract class for prefix and postfix unary operators.
+class UnaryOperatorExpression : public Expression {
+public:
+  UnaryOperatorExpression(NodeKind K) : Expression(K) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::PrefixUnaryOperatorExpression ||
+   N->kind() == NodeKind::PostfixUnaryOperatorExpression;
+  }
+  syntax::Leaf *operatorToken();
+  syntax::Expression *operand();
+};
+
+///  
+///
+/// For example:
+///   +a  -b
+///   !c  not c
+///   ~d  compl d
+///   *e  &f
+///   ++h --h
+///   __real i__imag i
+class PrefixUnaryOperatorExpression final : public UnaryOperatorExpression {
+public:
+  PrefixUnaryOperatorExpression()
+  : UnaryOperatorExpression(NodeKind::PrefixUnaryOperatorExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::PrefixUnaryOperatorExpression;
+  }
+};
+
+///  
+///
+/// For example:
+///   a++
+///   b--
+class PostfixUnaryOperatorExpression final : public UnaryOperatorExpression {
+public:
+  PostfixUnaryOperatorExpression()
+  : UnaryOperatorExpression(NodeKind::PostfixUnaryOperatorExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::PostfixUnaryOperatorExpression;
+  }
+};
+
 ///   
 ///
 /// For example:

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 8fee44cdbf10..60c6b3f88509 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -608,6 +608,25 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool WalkUpFromUnaryOperator(UnaryOperator *S) {
+Builder.markChildToken(
+S->getOperatorLoc(),
+syntax::NodeRole::UnaryOperatorExpression_operatorToken);
+Builder.markExprChild(S->getSubExpr(),
+  syntax::NodeRole::UnaryOperatorExpression_operand);
+
+if (S->isPostfix())
+  Builder.foldNode(Builder.getExprRange(S),
+   new (allocator()) 
syntax::PostfixUnaryOperatorExpression,
+   S);
+else
+  Builder.foldNode(Builder.getExprRange(S),
+   new (allocator()) syntax::PrefixUnaryOperatorExpression,
+   S);
+
+return true;
+  }
+
   bool WalkUpFromBinaryOperator(BinaryOperator *S) {
 Builder.markExprChild(
 S->getLHS(), syntax::NodeRole::BinaryOperatorExpression_leftHandSide);

diff  --git a/clang/lib/Tooling/Syntax/Nodes.cpp 
b/clang/lib/Tooling/Syntax/Nodes.cpp
index 84c0143db81d..f0f1a8ed13c2 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,10 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, 
NodeKind K) {
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::PrefixUnaryOperatorExpression:
+return OS << "PrefixUnaryOperatorExpression";
+  case NodeKind::PostfixUnaryOperatorExpression:
+return OS << "PostfixUnaryOperatorExpression";
   case NodeKind::BinaryOperatorExpression:
 return OS << "BinaryOperatorExpression";
   case NodeKind::UnknownStatement:
@@ -112,6 +116,10 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream 
&OS, NodeRol

[clang] 3549227 - Remove WrapperMatcherInterface

2020-05-28 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-05-28T17:58:29+02:00
New Revision: 35492270ed705ea9ac98ba04c6fda1adafef613a

URL: 
https://github.com/llvm/llvm-project/commit/35492270ed705ea9ac98ba04c6fda1adafef613a
DIFF: 
https://github.com/llvm/llvm-project/commit/35492270ed705ea9ac98ba04c6fda1adafef613a.diff

LOG: Remove WrapperMatcherInterface

Summary:
WrapperMatcherInterface is an abstraction over a member variable -- in
other words, not much of an abstraction at all. I think it makes code
harder to read more than in helps with deduplication. Not to even
mention the questionable usage of the ~Interface suffix for a type with
state.

Reviewers: ymandel

Reviewed By: ymandel

Subscribers: arichardson, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchersInternal.h

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index ac8469bded53..e064b28b84f9 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -489,19 +489,6 @@ class DynTypedMatcher {
   IntrusiveRefCntPtr Implementation;
 };
 
-/// Wrapper base class for a wrapping matcher.
-///
-/// This is just a container for a DynTypedMatcher that can be used as a base
-/// class for another matcher.
-template 
-class WrapperMatcherInterface : public MatcherInterface {
-protected:
-  explicit WrapperMatcherInterface(DynTypedMatcher &&InnerMatcher)
-  : InnerMatcher(std::move(InnerMatcher)) {}
-
-  const DynTypedMatcher InnerMatcher;
-};
-
 /// Wrapper of a MatcherInterface *that allows copying.
 ///
 /// A Matcher can be used anywhere a Matcher is
@@ -572,10 +559,12 @@ class Matcher {
   /// does only matches in the absence of qualifiers, or not, i.e. simply
   /// ignores any qualifiers.
   template 
-  class TypeToQualType : public WrapperMatcherInterface {
+  class TypeToQualType : public MatcherInterface {
+const DynTypedMatcher InnerMatcher;
+
   public:
 TypeToQualType(const Matcher &InnerMatcher)
-: TypeToQualType::WrapperMatcherInterface(InnerMatcher) {}
+: InnerMatcher(InnerMatcher) {}
 
 bool matches(const QualType &Node, ASTMatchFinder *Finder,
  BoundNodesTreeBuilder *Builder) const override {
@@ -764,13 +753,15 @@ Matcher hasAnySelectorFunc(
 /// Type argument DeclMatcherT is required by PolymorphicMatcherWithParam1 but
 /// not actually used.
 template 
-class HasDeclarationMatcher : public WrapperMatcherInterface {
+class HasDeclarationMatcher : public MatcherInterface {
   static_assert(std::is_same>::value,
 "instantiated with wrong types");
 
+  const DynTypedMatcher InnerMatcher;
+
 public:
   explicit HasDeclarationMatcher(const Matcher &InnerMatcher)
-  : HasDeclarationMatcher::WrapperMatcherInterface(InnerMatcher) {}
+  : InnerMatcher(InnerMatcher) {}
 
   bool matches(const T &Node, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const override {
@@ -1181,14 +1172,14 @@ struct ArgumentAdaptingMatcherFunc {
   }
 };
 
-template 
-class TraversalMatcher : public WrapperMatcherInterface {
+template  class TraversalMatcher : public MatcherInterface {
+  const DynTypedMatcher InnerMatcher;
   clang::TraversalKind Traversal;
 
 public:
-  explicit TraversalMatcher(clang::TraversalKind TK, const Matcher 
&ChildMatcher)
-  : TraversalMatcher::WrapperMatcherInterface(ChildMatcher), Traversal(TK) 
{
-  }
+  explicit TraversalMatcher(clang::TraversalKind TK,
+const Matcher &InnerMatcher)
+  : InnerMatcher(InnerMatcher), Traversal(TK) {}
 
   bool matches(const T &Node, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const override {
@@ -1337,10 +1328,12 @@ class BindableMatcher : public Matcher {
 ///
 /// ChildT must be an AST base type.
 template 
-class HasMatcher : public WrapperMatcherInterface {
+class HasMatcher : public MatcherInterface {
+  const DynTypedMatcher InnerMatcher;
+
 public:
-  explicit HasMatcher(const Matcher &ChildMatcher)
-  : HasMatcher::WrapperMatcherInterface(ChildMatcher) {}
+  explicit HasMatcher(const Matcher &InnerMatcher)
+  : InnerMatcher(InnerMatcher) {}
 
   bool matches(const T &Node, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const override {
@@ -1356,16 +1349,18 @@ class HasMatcher : public WrapperMatcherInterface {
 /// As opposed to the HasMatcher, the ForEachMatcher will produce a match
 /// for each child that matches.
 template 
-class ForEachMatcher : public WrapperMatcherInterface {
+class ForEachMatcher : public MatcherInterface {
   static_assert(IsBaseType::value,
 "for each only accepts base type matcher");
 
- public:
-   explicit ForEachMatcher(const Matcher

[clang] eca4191 - Improve test infrastructure in SyntaxTree

2020-05-28 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-05-28T21:35:12+02:00
New Revision: eca41919d28b0616140a63c6a97483098ec1ffee

URL: 
https://github.com/llvm/llvm-project/commit/eca41919d28b0616140a63c6a97483098ec1ffee
DIFF: 
https://github.com/llvm/llvm-project/commit/eca41919d28b0616140a63c6a97483098ec1ffee.diff

LOG: Improve test infrastructure in SyntaxTree

Summary:
* Test if the code sourcing the SyntaxTree compiles
* Output compiler errors and warnings to err
* Fix tests with code that did not compile

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index e81e3c2b8354..7051074d3b33 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
@@ -97,8 +98,12 @@ class SyntaxTreeTest : public ::testing::Test {
 
 constexpr const char *FileName = "./input.cpp";
 FS->addFile(FileName, time_t(), llvm::MemoryBuffer::getMemBufferCopy(""));
+
 if (!Diags->getClient())
-  Diags->setClient(new IgnoringDiagConsumer);
+  Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), 
DiagOpts.get()));
+Diags->setSeverityForGroup(diag::Flavor::WarningOrError, "unused-value",
+   diag::Severity::Ignored, SourceLocation());
+
 // Prepare to run a compiler.
 std::vector Args = {
 "syntax-test", "-target",   Target.c_str(),
@@ -117,7 +122,11 @@ class SyntaxTreeTest : public ::testing::Test {
 
 syntax::TranslationUnit *Root = nullptr;
 BuildSyntaxTreeAction Recorder(Root, this->Arena);
-if (!Compiler.ExecuteAction(Recorder)) {
+
+// Action could not be executed but the frontend didn't identify any errors
+// in the code ==> problem in setting up the action.
+if (!Compiler.ExecuteAction(Recorder) &&
+Diags->getClient()->getNumErrors() == 0) {
   ADD_FAILURE() << "failed to run the frontend";
   std::abort();
 }
@@ -143,6 +152,8 @@ class SyntaxTreeTest : public ::testing::Test {
 continue;
   }
   auto *Root = buildTree(Code, Target);
+  EXPECT_EQ(Diags->getClient()->getNumErrors(), 0u)
+  << "Source file has syntax errors, they were printed to the test 
log";
   std::string Actual = std::string(StringRef(Root->dump(*Arena)).trim());
   EXPECT_EQ(Expected, Actual)
   << "for target " << Target << " the resulting dump is:\n"
@@ -180,8 +191,10 @@ class SyntaxTreeTest : public ::testing::Test {
   }
 
   // Data fields.
+  llvm::IntrusiveRefCntPtr DiagOpts =
+  new DiagnosticOptions();
   llvm::IntrusiveRefCntPtr Diags =
-  new DiagnosticsEngine(new DiagnosticIDs, new DiagnosticOptions);
+  new DiagnosticsEngine(new DiagnosticIDs, DiagOpts.get());
   IntrusiveRefCntPtr FS =
   new llvm::vfs::InMemoryFileSystem;
   llvm::IntrusiveRefCntPtr FileMgr =
@@ -517,11 +530,11 @@ TEST_F(SyntaxTreeTest, UnhandledStatement) {
   // Unhandled statements should end up as 'unknown statement'.
   // This example uses a 'label statement', which does not yet have a syntax
   // counterpart.
-  expectTreeDumpEqual("void main() { foo: return 100; }",
+  expectTreeDumpEqual("int main() { foo: return 100; }",
   R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
-  |-void
+  |-int
   |-SimpleDeclarator
   | |-main
   | `-ParametersAndQualifiers
@@ -1166,7 +1179,7 @@ TEST_F(SyntaxTreeTest, FreeStandingClasses) {
   // Free-standing classes, must live inside a SimpleDeclaration.
   expectTreeDumpEqual(
   R"cpp(
-sturct X;
+struct X;
 struct X {};
 
 struct Y *y1;
@@ -1177,7 +1190,7 @@ struct {} *a1;
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
-| |-sturct
+| |-struct
 | |-X
 | `-;
 |-SimpleDeclaration
@@ -1660,7 +1673,7 @@ TEST_F(SyntaxTreeTest, ArraySubscriptsInDeclarators) {
 int a[10];
 int b[1][2][3];
 int c[] = {1,2,3};
-void f(int xs[static 10]);
+// void f(int xs[static 10]);
 )cpp",
   R"txt(
 *: TranslationUnit
@@ -1694,163 +1707,146 @@ void f(int xs[static 10]);
 | |   | `-3
 | |   `-]
 | `-;
-|-SimpleDeclaration
-| |-int
-| |-SimpleDeclarator
-| | |-c
-| | |-ArraySubscript
-| | | |-[
-| | | `-]
-| | |-=
-| | `-UnknownExpression
-| |   `-UnknownExpression
-| | |-{
-| | |-UnknownExpression
-| | | `-1
-| | |-,
-| | |-UnknownExpression
-| | | `-2
-| | |-,
-| | |-UnknownEx

[clang] d4ef654 - Rename APIs in unittests/AST/Language.h in preparation to share them

2020-05-29 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-05-29T14:25:20+02:00
New Revision: d4ef654673a921878ba5aedb9725b2ac32681f01

URL: 
https://github.com/llvm/llvm-project/commit/d4ef654673a921878ba5aedb9725b2ac32681f01
DIFF: 
https://github.com/llvm/llvm-project/commit/d4ef654673a921878ba5aedb9725b2ac32681f01.diff

LOG: Rename APIs in unittests/AST/Language.h in preparation to share them

Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.

Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.

Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".

Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").

Reviewers: shafik, rengolin, sammccall

Reviewed By: sammccall

Subscribers: gribozavr2, sammccall, martong, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/AST/ASTImporterFixtures.cpp
clang/unittests/AST/ASTImporterFixtures.h
clang/unittests/AST/ASTImporterODRStrategiesTest.cpp
clang/unittests/AST/ASTImporterTest.cpp
clang/unittests/AST/ASTImporterVisibilityTest.cpp
clang/unittests/AST/Language.cpp
clang/unittests/AST/Language.h
clang/unittests/AST/MatchVerifier.h
clang/unittests/AST/StructuralEquivalenceTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/ASTImporterFixtures.cpp 
b/clang/unittests/AST/ASTImporterFixtures.cpp
index 36732ee712f3..897b370dd3cd 100644
--- a/clang/unittests/AST/ASTImporterFixtures.cpp
+++ b/clang/unittests/AST/ASTImporterFixtures.cpp
@@ -38,7 +38,8 @@ void createVirtualFileIfNeeded(ASTUnit *ToAST, StringRef 
FileName,
llvm::MemoryBuffer::getMemBuffer(Code));
 }
 
-ASTImporterTestBase::TU::TU(StringRef Code, StringRef FileName, ArgVector Args,
+ASTImporterTestBase::TU::TU(StringRef Code, StringRef FileName,
+std::vector Args,
 ImporterConstructor C,
 ASTImporter::ODRHandlingType ODRHandling)
 : Code(std::string(Code)), FileName(std::string(FileName)),
@@ -112,11 +113,12 @@ void 
ASTImporterTestBase::lazyInitSharedState(TranslationUnitDecl *ToTU) {
 SharedStatePtr = std::make_shared(*ToTU);
 }
 
-void ASTImporterTestBase::lazyInitToAST(Language ToLang, StringRef ToSrcCode,
+void ASTImporterTestBase::lazyInitToAST(TestLanguage ToLang,
+StringRef ToSrcCode,
 StringRef FileName) {
   if (ToAST)
 return;
-  ArgVector ToArgs = getArgVectorForLanguage(ToLang);
+  std::vector ToArgs = getCommandLineArgsForLanguage(ToLang);
   // Source code must be a valid live buffer through the tests lifetime.
   ToCode = std::string(ToSrcCode);
   // Build the AST from an empty file.
@@ -136,12 +138,11 @@ ASTImporterTestBase::TU 
*ASTImporterTestBase::findFromTU(Decl *From) {
   return &*It;
 }
 
-std::tuple
-ASTImporterTestBase::getImportedDecl(StringRef FromSrcCode, Language FromLang,
- StringRef ToSrcCode, Language ToLang,
- StringRef Identifier) {
-  ArgVector FromArgs = getArgVectorForLanguage(FromLang),
-ToArgs = getArgVectorForLanguage(ToLang);
+std::tuple ASTImporterTestBase::getImportedDecl(
+StringRef FromSrcCode, TestLanguage FromLang, StringRef ToSrcCode,
+TestLanguage ToLang, StringRef Identifier) {
+  std::vector FromArgs = getCommandLineArgsForLanguage(FromLang);
+  std::vector ToArgs = getCommandLineArgsForLanguage(ToLang);
 
   FromTUs.emplace_back(FromSrcCode, InputFileName, FromArgs, Creator,
ODRHandling);
@@ -170,13 +171,13 @@ ASTImporterTestBase::getImportedDecl(StringRef 
FromSrcCode, Language FromLang,
 }
 
 TranslationUnitDecl *ASTImporterTestBase::getTuDecl(StringRef SrcCode,
-Language Lang,
+TestLanguage Lang,
 StringRef FileName) {
   assert(llvm::find_if(FromTUs, [FileName](const TU &E) {
return E.FileName == FileName;
  }) == FromTUs.end());
 
-  ArgVector Args = getArgVectorForLanguage(Lang);
+  std::vector Args = getCommandLineArgsForLanguage(Lang);
   FromTUs.emplace_back(SrcCode, FileName, Args, Creator, ODRHandling);
   TU &Tu = FromTUs.back();
 
@@ -184

[clang] 0e265e3 - Move unittest helpers to a shared location

2020-05-29 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-05-29T16:47:33+02:00
New Revision: 0e265e315784b4e47f984f8ed9fb7586130bacdc

URL: 
https://github.com/llvm/llvm-project/commit/0e265e315784b4e47f984f8ed9fb7586130bacdc
DIFF: 
https://github.com/llvm/llvm-project/commit/0e265e315784b4e47f984f8ed9fb7586130bacdc.diff

LOG: Move unittest helpers to a shared location

Summary:
unittests/AST/Language.h defines some helpers that we would like to
reuse in other tests, for example, in tests for syntax trees.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: mgorny, martong, cfe-commits

Tags: #clang

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

Added: 
clang/include/clang/Testing/CommandLineArgs.h
clang/lib/Testing/CMakeLists.txt
clang/lib/Testing/CommandLineArgs.cpp

Modified: 
clang/include/clang/module.modulemap
clang/lib/CMakeLists.txt
clang/unittests/AST/ASTImporterFixtures.h
clang/unittests/AST/CMakeLists.txt
clang/unittests/AST/MatchVerifier.h
clang/unittests/AST/StructuralEquivalenceTest.cpp

Removed: 
clang/unittests/AST/Language.cpp
clang/unittests/AST/Language.h



diff  --git a/clang/unittests/AST/Language.h 
b/clang/include/clang/Testing/CommandLineArgs.h
similarity index 76%
rename from clang/unittests/AST/Language.h
rename to clang/include/clang/Testing/CommandLineArgs.h
index da200ec8719f..0d2267f63ac5 100644
--- a/clang/unittests/AST/Language.h
+++ b/clang/include/clang/Testing/CommandLineArgs.h
@@ -1,4 +1,4 @@
-//===-- unittest/AST/Language.h - AST unit test support 
---===//
+//===--- CommandLineArgs.h 
===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,15 +6,15 @@
 //
 
//===--===//
 //
-//  This file defines language options for AST unittests.
+//  This file defines language options for Clang unittests.
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_UNITTESTS_AST_LANGUAGE_H
-#define LLVM_CLANG_UNITTESTS_AST_LANGUAGE_H
+#ifndef LLVM_CLANG_TESTING_COMMANDLINEARGS_H
+#define LLVM_CLANG_TESTING_COMMANDLINEARGS_H
 
-#include 
 #include 
+#include 
 
 namespace clang {
 

diff  --git a/clang/include/clang/module.modulemap 
b/clang/include/clang/module.modulemap
index 15f891c15340..7549ff2e3bcd 100644
--- a/clang/include/clang/module.modulemap
+++ b/clang/include/clang/module.modulemap
@@ -152,6 +152,12 @@ module Clang_StaticAnalyzer_Frontend {
   module * { export * }
 }
 
+module Clang_Testing {
+  requires cplusplus
+  umbrella "Testing"
+  module * { export * }
+}
+
 module Clang_Tooling {
   requires cplusplus umbrella "Tooling" module * { export * }
   // FIXME: Exclude these headers to avoid pulling all of the AST matchers

diff  --git a/clang/lib/CMakeLists.txt b/clang/lib/CMakeLists.txt
index 0c03f5972b09..c2b6a5a4d5d4 100644
--- a/clang/lib/CMakeLists.txt
+++ b/clang/lib/CMakeLists.txt
@@ -24,3 +24,4 @@ if(CLANG_ENABLE_STATIC_ANALYZER)
   add_subdirectory(StaticAnalyzer)
 endif()
 add_subdirectory(Format)
+add_subdirectory(Testing)

diff  --git a/clang/lib/Testing/CMakeLists.txt 
b/clang/lib/Testing/CMakeLists.txt
new file mode 100644
index ..4a8d436aab66
--- /dev/null
+++ b/clang/lib/Testing/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_library(clangTesting
+  CommandLineArgs.cpp
+  )

diff  --git a/clang/unittests/AST/Language.cpp 
b/clang/lib/Testing/CommandLineArgs.cpp
similarity index 83%
rename from clang/unittests/AST/Language.cpp
rename to clang/lib/Testing/CommandLineArgs.cpp
index 3dd9659fc00e..58a61dade2ea 100644
--- a/clang/unittests/AST/Language.cpp
+++ b/clang/lib/Testing/CommandLineArgs.cpp
@@ -1,16 +1,12 @@
-//===-- unittest/AST/Language.cpp - AST unit test support 
-===//
+//===--- CommandLineArgs.cpp 
--===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 
//===--===//
-//
-//  This file defines language options for AST unittests.
-//
-//===--===//
 
-#include "Language.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace clang {

diff  --git a/clang/unittests/AST/ASTImporterFixtures.h 
b/clang/unittests/AST/ASTImporterFixtures.h
index 619c3f590be4..4fbceef39384 100644
--- a/clang/unittests/AST/ASTImporterFixtures.h
+++ b/clang/unittests/AST/ASTImporterFixtures.h
@@ -19,11 +19,11 @@
 #include "

[clang] 3a574a6 - Add support for Overloaded Binary Operators in SyntaxTree

2020-05-29 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-05-29T20:03:59+02:00
New Revision: 3a574a6cb35953e538e577a88f62af8dd01432c7

URL: 
https://github.com/llvm/llvm-project/commit/3a574a6cb35953e538e577a88f62af8dd01432c7
DIFF: 
https://github.com/llvm/llvm-project/commit/3a574a6cb35953e538e577a88f62af8dd01432c7.diff

LOG: Add support for Overloaded Binary Operators in SyntaxTree

Reviewers: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 60c6b3f88509..2b312cdde1d6 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -640,6 +640,24 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool WalkUpFromCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
+if (S->isInfixBinaryOp()) {
+  Builder.markExprChild(
+  S->getArg(0),
+  syntax::NodeRole::BinaryOperatorExpression_leftHandSide);
+  Builder.markChildToken(
+  S->getOperatorLoc(),
+  syntax::NodeRole::BinaryOperatorExpression_operatorToken);
+  Builder.markExprChild(
+  S->getArg(1),
+  syntax::NodeRole::BinaryOperatorExpression_rightHandSide);
+  Builder.foldNode(Builder.getExprRange(S),
+   new (allocator()) syntax::BinaryOperatorExpression, S);
+  return true;
+}
+return RecursiveASTVisitor::WalkUpFromCXXOperatorCallExpr(S);
+  }
+
   bool WalkUpFromNamespaceDecl(NamespaceDecl *S) {
 auto Tokens = Builder.getDeclarationRange(S);
 if (Tokens.front().kind() == tok::coloncolon) {

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 7051074d3b33..04786257c434 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -993,6 +993,134 @@ void test(int a, int b) {
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, UserDefinedBinaryOperator) {
+  expectTreeDumpEqual(
+  R"cpp(
+struct X {
+  X& operator=(const X&);
+  friend X operator+(X, const X&);
+  friend bool operator<(const X&, const X&);
+};
+void test(X x, X y) {
+  x = y;
+  x + y;
+  x < y;
+}
+  )cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-X
+| | |-SimpleDeclarator
+| | | |-&
+| | | |-operator
+| | | |-=
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   |-SimpleDeclaration
+| | |   | |-const
+| | |   | |-X
+| | |   | `-SimpleDeclarator
+| | |   |   `-&
+| | |   `-)
+| | `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-X
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-+
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | `-X
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-UnknownDeclaration
+| | `-SimpleDeclaration
+| |   |-friend
+| |   |-bool
+| |   |-SimpleDeclarator
+| |   | |-operator
+| |   | |-<
+| |   | `-ParametersAndQualifiers
+| |   |   |-(
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   |-,
+| |   |   |-SimpleDeclaration
+| |   |   | |-const
+| |   |   | |-X
+| |   |   | `-SimpleDeclarator
+| |   |   |   `-&
+| |   |   `-)
+| |   `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-y
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-x
+| | |-UnknownExpression
+| | | `-=
+| | `-UnknownExpression
+| |   `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-UnknownExpression
+| | |   `-x
+| | |-UnknownExpression
+| | | `-+
+| | `-UnknownExpression
+| |   `-y
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-x
+| | |-UnknownExpression
+| | | `-<
+| | `-UnknownExpression
+| |   `-y
+| `-;
+`-}
+)txt");
+}
+
 TEST_F(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   expectTreeDumpEqual(
   R"cpp(



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


[clang] 44f989e - Run syntax tree tests in many language modes

2020-06-02 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-02T10:30:01+02:00
New Revision: 44f989e7809633f13bd0420cc1d79660ad982173

URL: 
https://github.com/llvm/llvm-project/commit/44f989e7809633f13bd0420cc1d79660ad982173
DIFF: 
https://github.com/llvm/llvm-project/commit/44f989e7809633f13bd0420cc1d79660ad982173.diff

LOG: Run syntax tree tests in many language modes

Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: gribozavr2, mgorny, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/Tooling/Syntax/CMakeLists.txt
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/unittests/Tooling/Syntax/CMakeLists.txt 
b/clang/unittests/Tooling/Syntax/CMakeLists.txt
index 5de7d24e2675..62d1ecc81cad 100644
--- a/clang/unittests/Tooling/Syntax/CMakeLists.txt
+++ b/clang/unittests/Tooling/Syntax/CMakeLists.txt
@@ -14,6 +14,7 @@ clang_target_link_libraries(SyntaxTests
   clangFrontend
   clangLex
   clangSerialization
+  clangTesting
   clangTooling
   clangToolingCore
   clangToolingSyntax

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 04786257c434..705cb872c6a4 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
 #include "clang/Tooling/Syntax/Mutations.h"
@@ -25,6 +26,7 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
@@ -45,12 +47,71 @@ static llvm::ArrayRef tokens(syntax::Node 
*N) {
 T->lastLeaf()->token() + 1);
 }
 
-class SyntaxTreeTest : public ::testing::Test {
+struct TestClangConfig {
+  TestLanguage Language;
+  std::string Target;
+
+  bool isCXX() const {
+return Language == Lang_CXX || Language == Lang_CXX11 ||
+   Language == Lang_CXX14 || Language == Lang_CXX17 ||
+   Language == Lang_CXX2a;
+  }
+
+  bool isCXX11OrLater() const {
+return Language == Lang_CXX11 || Language == Lang_CXX14 ||
+   Language == Lang_CXX17 || Language == Lang_CXX2a;
+  }
+
+  bool hasDelayedTemplateParsing() const {
+return Target == "x86_64-pc-win32-msvc";
+  }
+
+  std::vector getCommandLineArgs() const {
+std::vector Result = getCommandLineArgsForTesting(Language);
+Result.push_back("-target");
+Result.push_back(Target);
+return Result;
+  }
+
+  std::string toString() const {
+std::string Result;
+llvm::raw_string_ostream OS(Result);
+OS << "{ Language=" << Language << ", Target=" << Target << " }";
+return OS.str();
+  }
+
+  friend std::ostream &operator<<(std::ostream &OS,
+  const TestClangConfig &ClangConfig) {
+return OS << ClangConfig.toString();
+  }
+
+  static std::vector &allConfigs() {
+static std::vector all_configs = []() {
+  std::vector all_configs;
+  for (TestLanguage lang : {Lang_C, Lang_C89, Lang_CXX, Lang_CXX11,
+Lang_CXX14, Lang_CXX17, Lang_CXX2a}) {
+TestClangConfig config;
+config.Language = lang;
+config.Target = "x86_64-pc-linux-gnu";
+all_configs.push_back(config);
+
+// Windows target is interesting to test because it enables
+// `-fdelayed-template-parsing`.
+config.Target = "x86_64-pc-win32-msvc";
+all_configs.push_back(config);
+  }
+  return all_configs;
+}();
+return all_configs;
+  }
+};
+
+class SyntaxTreeTest : public ::testing::Test,
+   public ::testing::WithParamInterface {
 protected:
   // Build a syntax tree for the code.
-  syntax::TranslationUnit *
-  buildTree(llvm::StringRef Code,
-const std::string &Target = "x86_64-pc-linux-gnu") {
+  syntax::TranslationUnit *buildTree(llvm::StringRef Code,
+ const TestClangConfig &ClangConfig) {
 // FIXME: this code is almost the identical to the one in TokensTest. Share
 //it.
 class BuildSyntaxTree : public ASTConsumer {
@@ -105,11 +166,19 @@ class SyntaxTreeTest : public ::testing::Test {
diag::Severity::Ignored, SourceLocation());
 
 // Prepare to run a compiler.
-std::vector Args = {
-"syntax-test", "-target",   Target.c_str(),
-FileName,  "-fsyntax-only", "-std=c++17",
+std::vector Args = {
+"syntax-test",
+"-fsyntax-only",

[clang] 53c29a4 - Reinstate the syntax tree test for 'static' in an array subscript

2020-06-02 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-02T17:01:51+02:00
New Revision: 53c29a42d044b167f6b5f28e096c8d9e50d6edc7

URL: 
https://github.com/llvm/llvm-project/commit/53c29a42d044b167f6b5f28e096c8d9e50d6edc7
DIFF: 
https://github.com/llvm/llvm-project/commit/53c29a42d044b167f6b5f28e096c8d9e50d6edc7.diff

LOG: Reinstate the syntax tree test for 'static' in an array subscript

Reviewers: eduucaldas

Reviewed By: eduucaldas

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index bcfb2f7614e8..a7de4b909cb4 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -51,6 +51,8 @@ struct TestClangConfig {
   TestLanguage Language;
   std::string Target;
 
+  bool isC99OrLater() const { return Language == Lang_C99; }
+
   bool isCXX() const {
 return Language == Lang_CXX03 || Language == Lang_CXX11 ||
Language == Lang_CXX14 || Language == Lang_CXX17 ||
@@ -1903,7 +1905,6 @@ TEST_P(SyntaxTreeTest, ArraySubscriptsInDeclarators) {
 int a[10];
 int b[1][2][3];
 int c[] = {1,2,3};
-// void f(int xs[static 10]);
 )cpp",
   R"txt(
 *: TranslationUnit
@@ -1960,6 +1961,36 @@ int c[] = {1,2,3};
   `-;   )txt");
 }
 
+TEST_P(SyntaxTreeTest, StaticArraySubscriptsInDeclarators) {
+  if (!GetParam().isC99OrLater()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void f(int xs[static 10]);
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-f
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   |-xs
+  |   |   `-ArraySubscript
+  |   | |-[
+  |   | |-static
+  |   | |-UnknownExpression
+  |   | | `-10
+  |   | `-]
+  |   `-)
+  `-;   )txt");
+}
+
 TEST_P(SyntaxTreeTest, ParameterListsInDeclarators) {
   if (!GetParam().isCXX()) {
 // TODO: Split parts that depend on C++ into a separate test.



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


[clang] b34b769 - Syntax tree: ignore implicit expressions at the top level of statements

2020-06-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-03T10:58:12+02:00
New Revision: b34b7691facd89022e7fee174debdbd2bf7920f3

URL: 
https://github.com/llvm/llvm-project/commit/b34b7691facd89022e7fee174debdbd2bf7920f3
DIFF: 
https://github.com/llvm/llvm-project/commit/b34b7691facd89022e7fee174debdbd2bf7920f3.diff

LOG: Syntax tree: ignore implicit expressions at the top level of statements

Summary:
I changed `markStmtChild` to ignore implicit expressions the same way as
`markExprChild` does it already. The test that I modified crashes
without this change.

Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 2b312cdde1d6..1c473d872034 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1044,17 +1044,18 @@ void syntax::TreeBuilder::markStmtChild(Stmt *Child, 
NodeRole Role) {
   if (!Child)
 return;
 
-  syntax::Tree *ChildNode = Mapping.find(Child);
-  assert(ChildNode != nullptr);
-
-  // This is an expression in a statement position, consume the trailing
-  // semicolon and form an 'ExpressionStatement' node.
-  if (isa(Child)) {
-setRole(ChildNode, NodeRole::ExpressionStatement_expression);
+  syntax::Tree *ChildNode;
+  if (Expr *ChildExpr = dyn_cast(Child)) {
+// This is an expression in a statement position, consume the trailing
+// semicolon and form an 'ExpressionStatement' node.
+markExprChild(ChildExpr, NodeRole::ExpressionStatement_expression);
 ChildNode = new (allocator()) syntax::ExpressionStatement;
 // (!) 'getStmtRange()' ensures this covers a trailing semicolon.
 Pending.foldChildren(Arena, getStmtRange(Child), ChildNode);
+  } else {
+ChildNode = Mapping.find(Child);
   }
+  assert(ChildNode != nullptr);
   setRole(ChildNode, Role);
 }
 

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index a7de4b909cb4..0592d8f44b4e 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -705,20 +705,16 @@ void test(int a) {
 }
 
 TEST_P(SyntaxTreeTest, PrefixUnaryOperator) {
-  if (!GetParam().isCXX()) {
-// TODO: Split parts that depend on C++ into a separate test.
-return;
-  }
   expectTreeDumpEqual(
   R"cpp(
-void test(int a, int *ap, bool b) {
+void test(int a, int *ap) {
   --a; ++a;
-  ~a; compl a;
+  ~a;
   -a;
   +a;
   &a;
   *ap;
-  !b; not b;
+  !a;
   __real a; __imag a;
 }
 )cpp",
@@ -740,11 +736,6 @@ void test(int a, int *ap, bool b) {
   |   | `-SimpleDeclarator
   |   |   |-*
   |   |   `-ap
-  |   |-,
-  |   |-SimpleDeclaration
-  |   | |-bool
-  |   | `-SimpleDeclarator
-  |   |   `-b
   |   `-)
   `-CompoundStatement
 |-{
@@ -768,12 +759,6 @@ void test(int a, int *ap, bool b) {
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-compl
-| | `-UnknownExpression
-| |   `-a
-| `-;
-|-ExpressionStatement
-| |-PrefixUnaryOperatorExpression
 | | |--
 | | `-UnknownExpression
 | |   `-a
@@ -800,26 +785,67 @@ void test(int a, int *ap, bool b) {
 | |-PrefixUnaryOperatorExpression
 | | |-!
 | | `-UnknownExpression
-| |   `-b
+| |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-not
+| | |-__real
 | | `-UnknownExpression
-| |   `-b
+| |   `-a
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-__real
+| | |-__imag
 | | `-UnknownExpression
 | |   `-a
 | `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, PrefixUnaryOperatorCxx) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a, bool b) {
+  compl a;
+  not b;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-bool
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-__imag
+| | |-compl
 | | `-UnknownExpression
 | |   `-a
 | `-;
+|-ExpressionStatement
+| |-PrefixUnaryOperatorExpression
+| | |-not
+| | `-UnknownExpression
+| |   `-b
+| `-;
 `-}
 )txt");
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.o

[clang] d7d5dd3 - Split syntax tree tests into more granular ones

2020-06-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-03T11:17:11+02:00
New Revision: d7d5dd31fc6f05daf4758e1523c86401aa4e3f2a

URL: 
https://github.com/llvm/llvm-project/commit/d7d5dd31fc6f05daf4758e1523c86401aa4e3f2a
DIFF: 
https://github.com/llvm/llvm-project/commit/d7d5dd31fc6f05daf4758e1523c86401aa4e3f2a.diff

LOG: Split syntax tree tests into more granular ones

Summary:
Doing so allows us to increase test coverage by removing unnecessary
language restrictions.

Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 0592d8f44b4e..24943acf733e 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -64,6 +64,11 @@ struct TestClangConfig {
Language == Lang_CXX17 || Language == Lang_CXX20;
   }
 
+  bool supportsCXXDynamicExceptionSpecification() const {
+return Language == Lang_CXX03 || Language == Lang_CXX11 ||
+   Language == Lang_CXX14;
+  }
+
   bool hasDelayedTemplateParsing() const {
 return Target == "x86_64-pc-win32-msvc";
   }
@@ -851,10 +856,6 @@ void test(int a, bool b) {
 }
 
 TEST_P(SyntaxTreeTest, BinaryOperator) {
-  if (!GetParam().isCXX()) {
-// TODO: Split parts that depend on C++ into a separate test.
-return;
-  }
   expectTreeDumpEqual(
   R"cpp(
 void test(int a) {
@@ -862,15 +863,9 @@ void test(int a) {
   1 == 2;
   a = 1;
   a <<= 1;
-
-  true || false;
-  true or false;
-
+  1 || 0;
   1 & 2;
-  1 bitand 2;
-
   a ^= 3;
-  a xor_eq 3;
 }
 )cpp",
   R"txt(
@@ -923,42 +918,82 @@ void test(int a) {
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
+| | | `-1
 | | |-||
 | | `-UnknownExpression
-| |   `-false
+| |   `-0
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-true
-| | |-or
+| | | `-1
+| | |-&
 | | `-UnknownExpression
-| |   `-false
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-&
+| | | `-a
+| | |-^=
 | | `-UnknownExpression
-| |   `-2
+| |   `-3
 | `-;
+`-}
+)txt");
+}
+
+TEST_P(SyntaxTreeTest, BinaryOperatorCxx) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test(int a) {
+  true || false;
+  true or false;
+  1 bitand 2;
+  a xor_eq 3;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-1
-| | |-bitand
+| | | `-true
+| | |-||
 | | `-UnknownExpression
-| |   `-2
+| |   `-false
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
 | | |-UnknownExpression
-| | | `-a
-| | |-^=
+| | | `-true
+| | |-or
 | | `-UnknownExpression
-| |   `-3
+| |   `-false
+| `-;
+|-ExpressionStatement
+| |-BinaryOperatorExpression
+| | |-UnknownExpression
+| | | `-1
+| | |-bitand
+| | `-UnknownExpression
+| |   `-2
 | `-;
 |-ExpressionStatement
 | |-BinaryOperatorExpression
@@ -2017,21 +2052,202 @@ void f(int xs[static 10]);
   `-;   )txt");
 }
 
-TEST_P(SyntaxTreeTest, ParameterListsInDeclarators) {
+TEST_P(SyntaxTreeTest, ParametersAndQualifiersInFreeFunctions) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+int func1();
+int func2a(int a);
+int func2b(int);
+int func3a(int *ap);
+int func3b(int *);
+int func4a(int a, float b);
+int func4b(int, float);
+  )cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func1
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   `-a
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func2b
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-int
+| |   `-)
+| `-;
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-func3a
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | |-int
+| |   | `-SimpleDeclarator
+| |   |   |-*
+| |   |   `-ap

[clang-tools-extra] c1911fc - Replaced C++2a with C++20 in clang-tools-extra

2020-06-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-03T14:54:10+02:00
New Revision: c1911fcb0664417cbf75b11315bdba39bd6d6390

URL: 
https://github.com/llvm/llvm-project/commit/c1911fcb0664417cbf75b11315bdba39bd6d6390
DIFF: 
https://github.com/llvm/llvm-project/commit/c1911fcb0664417cbf75b11315bdba39bd6d6390.diff

LOG: Replaced C++2a with C++20 in clang-tools-extra

Reviewers: hlopko, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: wuzish, aaron.ballman, nemanjai, kbarton, jkorous, arphaman, 
kadircet, usaxena95, cfe-commits

Tags: #clang

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init-cxx20.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
clang-tools-extra/docs/clang-tidy/checks/portability-simd-intrinsics.rst
clang-tools-extra/test/clang-tidy/check_clang_tidy.py
clang-tools-extra/test/clang-tidy/checkers/cert-mem57-cpp-cpp17.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-make-unique-inaccessible-ctors.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-raw-string-literal.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init-bitfield.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-use-default-member-init.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
clang-tools-extra/test/clang-tidy/checkers/performance-no-automatic-move.cpp

clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-ppc.cpp

clang-tools-extra/test/clang-tidy/checkers/portability-simd-intrinsics-x86.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-use-anyofallof-cpp20.cpp

Removed: 

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init-cxx2a.cpp



diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index 22373439083e..a223d215af1b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -454,7 +454,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
   return;
 // Don't suggest fixes for enums because we don't know a good default.
 // Don't suggest fixes for bitfields because in-class initialization is not
-// possible until C++2a.
+// possible until C++20.
 if (F->getType()->isEnumeralType() ||
 (!getLangOpts().CPlusPlus20 && F->isBitField()))
   return;

diff  --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp 
b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
index 2b014ac0a69b..dea783f049e3 100644
--- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -441,7 +441,7 @@ TEST_F(DocumentSymbolsTest, DeclarationDefinition) {
 }
 
 TEST_F(DocumentSymbolsTest, Concepts) {
-  CDB.ExtraClangFlags = {"-std=c++2a"};
+  CDB.ExtraClangFlags = {"-std=c++20"};
   std::string FilePath = testPath("foo.cpp");
   addFile(FilePath,
   "template  concept C = requires(T t) { t.foo(); };");

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 26fdcd886f62..bf5cc62411b7 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -401,7 +401,7 @@ TEST_F(TargetDeclTest, Concept) {
   t.foo();
 }
   )cpp";
-  Flags.push_back("-std=c++2a");
+  Flags.push_back("-std=c++20");
   EXPECT_DECLS(
   "ConceptSpecializationExpr",
   // FIXME: Should we truncate the pretty-printed form of a concept decl
@@ -642,7 +642,7 @@ class FindExplicitReferencesTest : public ::testing::Test {
 // FIXME: Auto-completion in a template requires disabling delayed template
 // parsing.
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
-TU.ExtraArgs.push_back("-std=c++2a");
+TU.ExtraArgs.push_back("-std=c++20");
 TU.ExtraArgs.push_back("-xobjective-c++");
 
 auto AST = TU.build();

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 2b4c306c5163..98080e98ca17 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -115,7 +115,7 @@ void

[clang] 007098d - Add support for `nullptr` in SyntaxTrees

2020-06-03 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-06-03T15:52:33+02:00
New Revision: 007098d7e6b8cf2cf1f1142908840a378d60c545

URL: 
https://github.com/llvm/llvm-project/commit/007098d7e6b8cf2cf1f1142908840a378d60c545
DIFF: 
https://github.com/llvm/llvm-project/commit/007098d7e6b8cf2cf1f1142908840a378d60c545.diff

LOG: Add support for `nullptr` in SyntaxTrees

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index e240becbf883..ce4dc35977f1 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -43,6 +43,7 @@ enum class NodeKind : uint16_t {
   PrefixUnaryOperatorExpression,
   PostfixUnaryOperatorExpression,
   BinaryOperatorExpression,
+  CxxNullPtrExpression,
 
   // Statements.
   UnknownStatement,
@@ -112,6 +113,7 @@ enum class NodeRole : uint8_t {
   BinaryOperatorExpression_leftHandSide,
   BinaryOperatorExpression_operatorToken,
   BinaryOperatorExpression_rightHandSide,
+  CxxNullPtrExpression_keyword,
   CaseStatement_value,
   IfStatement_thenStatement,
   IfStatement_elseKeyword,
@@ -166,6 +168,16 @@ class UnknownExpression final : public Expression {
   }
 };
 
+/// C++11 'nullptr' expression.
+class CxxNullPtrExpression final : public Expression {
+public:
+  CxxNullPtrExpression() : Expression(NodeKind::CxxNullPtrExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::CxxNullPtrExpression;
+  }
+  syntax::Leaf *nullPtrKeyword();
+};
+
 /// An abstract class for prefix and postfix unary operators.
 class UnaryOperatorExpression : public Expression {
 public:

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 1c473d872034..dcc7b3e19390 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -608,6 +608,14 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
+Builder.markChildToken(S->getLocation(),
+   syntax::NodeRole::CxxNullPtrExpression_keyword);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::CxxNullPtrExpression, S);
+return true;
+  }
+
   bool WalkUpFromUnaryOperator(UnaryOperator *S) {
 Builder.markChildToken(
 S->getOperatorLoc(),

diff  --git a/clang/lib/Tooling/Syntax/Nodes.cpp 
b/clang/lib/Tooling/Syntax/Nodes.cpp
index f0f1a8ed13c2..3311b8df034c 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -18,6 +18,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, 
NodeKind K) {
 return OS << "TranslationUnit";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
+  case NodeKind::CxxNullPtrExpression:
+return OS << "CxxNullPtrExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -116,6 +118,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream 
&OS, NodeRole R) {
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
+  case syntax::NodeRole::CxxNullPtrExpression_keyword:
+return OS << "CxxNullPtrExpression_keyword";
   case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
 return OS << "UnaryOperatorExpression_operatorToken";
   case syntax::NodeRole::UnaryOperatorExpression_operand:
@@ -158,6 +162,11 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream 
&OS, NodeRole R) {
   llvm_unreachable("invalid role");
 }
 
+syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));
+}
+
 syntax::Expression *syntax::BinaryOperatorExpression::lhs() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::BinaryOperatorExpression_leftHandSide));

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 24943acf733e..b8a188a1a76b 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -670,6 +670,35 @@ void test() {
 )txt");
 }
 
+TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  expectTreeDumpEqual(
+  R"cpp(
+void test() {
+  nullptr;
+}
+)cpp",
+  R"txt(
+*: Translat

[clang] 4f244c4 - Use TestClangConfig in AST Matchers tests and run them in more configurations

2020-07-16 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-16T18:36:53+02:00
New Revision: 4f244c4b42b096a55f2e7f719e1101c6fd26c034

URL: 
https://github.com/llvm/llvm-project/commit/4f244c4b42b096a55f2e7f719e1101c6fd26c034
DIFF: 
https://github.com/llvm/llvm-project/commit/4f244c4b42b096a55f2e7f719e1101c6fd26c034.diff

LOG: Use TestClangConfig in AST Matchers tests and run them in more 
configurations

Summary:
I am changing tests for AST Matchers to run in multiple language standards
versions, and under multiple triples that have different behavior with regards
to templates. This change is similar to https://reviews.llvm.org/D82179.

To keep the size of the patch manageable, in this patch I'm only migrating one
file to get the process started and get feedback on this approach.

Reviewers: ymandel

Reviewed By: ymandel

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Testing/TestClangConfig.h
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
clang/unittests/ASTMatchers/ASTMatchersTest.h

Removed: 




diff  --git a/clang/include/clang/Testing/TestClangConfig.h 
b/clang/include/clang/Testing/TestClangConfig.h
index eefa36dc2ebb..5d6be4f65d0a 100644
--- a/clang/include/clang/Testing/TestClangConfig.h
+++ b/clang/include/clang/Testing/TestClangConfig.h
@@ -51,6 +51,8 @@ struct TestClangConfig {
 return Language == Lang_CXX17 || Language == Lang_CXX20;
   }
 
+  bool isCXX20OrLater() const { return Language == Lang_CXX20; }
+
   bool supportsCXXDynamicExceptionSpecification() const {
 return Language == Lang_CXX03 || Language == Lang_CXX11 ||
Language == Lang_CXX14;

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index c249410201ba..36e92c632c03 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -18,7 +18,7 @@
 namespace clang {
 namespace ast_matchers {
 
-TEST(IsExpandedFromMacro, ShouldMatchInFile) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesInFile) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 void Test() { MY_MACRO(4); }
@@ -26,7 +26,7 @@ TEST(IsExpandedFromMacro, ShouldMatchInFile) {
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("MY_MACRO";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchNested) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesNested) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 #define WRAPPER(a) MY_MACRO(a)
@@ -35,7 +35,7 @@ TEST(IsExpandedFromMacro, ShouldMatchNested) {
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("MY_MACRO";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchIntermediate) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesIntermediate) {
   StringRef input = R"cc(
 #define IMPL(a) (4 + (a))
 #define MY_MACRO(a) IMPL(a)
@@ -45,7 +45,7 @@ TEST(IsExpandedFromMacro, ShouldMatchIntermediate) {
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("MY_MACRO";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchTransitive) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesTransitive) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 #define WRAPPER(a) MY_MACRO(a)
@@ -54,7 +54,7 @@ TEST(IsExpandedFromMacro, ShouldMatchTransitive) {
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("WRAPPER";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchArgument) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesArgument) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 void Test() {
@@ -65,9 +65,9 @@ TEST(IsExpandedFromMacro, ShouldMatchArgument) {
   EXPECT_TRUE(matches(input, declRefExpr(isExpandedFromMacro("MY_MACRO";
 }
 
-// Like IsExpandedFromMacroShouldMatchArgumentMacro, but the argument is itself
-// a macro.
-TEST(IsExpandedFromMacro, ShouldMatchArgumentMacroExpansion) {
+// Like IsExpandedFromMacro_MatchesArgument, but the argument is itself a
+// macro.
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesArgumentMacroExpansion) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 #define IDENTITY(a) (a)
@@ -78,7 +78,7 @@ TEST(IsExpandedFromMacro, ShouldMatchArgumentMacroExpansion) {
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("IDENTITY";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchWhenInArgument) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesWhenInArgument) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 #define IDENTITY(a) (a)
@@ -89,7 +89,7 @@ TEST(IsExpandedFromMacro, ShouldMatchWhenInArgument) {
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("MY_MACRO";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchObjectMacro) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesObjectMacro) {
   StringRef input = 

[clang] b6073ee - Enable the test for hasArraySize() AST matcher in all language modes

2020-07-20 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-20T10:23:00+02:00
New Revision: b6073ee9ae842d1999fd7798a0aac0f8427d6aea

URL: 
https://github.com/llvm/llvm-project/commit/b6073ee9ae842d1999fd7798a0aac0f8427d6aea
DIFF: 
https://github.com/llvm/llvm-project/commit/b6073ee9ae842d1999fd7798a0aac0f8427d6aea.diff

LOG: Enable the test for hasArraySize() AST matcher in all language modes

Summary:
In C++11 and later Clang generates an implicit conversion from int to
size_t in the AST.

Reviewers: ymandel, hokein

Reviewed By: hokein

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 36e92c632c03..4bd50191e163 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3219,13 +3219,13 @@ TEST_P(ASTMatchersTest, IsArray) {
 }
 
 TEST_P(ASTMatchersTest, HasArraySize) {
-  if (GetParam().Language != Lang_CXX03) {
-// FIXME: Fix this test to work in all C++ language modes.
+  if (!GetParam().isCXX()) {
 return;
   }
 
   EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
-  cxxNewExpr(hasArraySize(integerLiteral(equals(10));
+  cxxNewExpr(hasArraySize(
+  
ignoringParenImpCasts(integerLiteral(equals(10)));
 }
 
 TEST_P(ASTMatchersTest, HasDefinition_MatchesStructDefinition) {



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


[Differential] D83966: Enable the test for hasArraySize() AST matcher in all language modes

2020-07-20 Thread Dmitri Gribenko via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb6073ee9ae84: Enable the test for hasArraySize() AST matcher 
in all language modes (authored by gribozavr).

Repository:
  rG LLVM Github Monorepo

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


  https://reviews.llvm.org/D83966

Files:
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp



Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3219,13 +3219,13 @@
 }
 
 TEST_P(ASTMatchersTest, HasArraySize) {
-  if (GetParam().Language != Lang_CXX03) {
-// FIXME: Fix this test to work in all C++ language modes.
+  if (!GetParam().isCXX()) {
 return;
   }
 
   EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
-  cxxNewExpr(hasArraySize(integerLiteral(equals(10));
+  cxxNewExpr(hasArraySize(
+  
ignoringParenImpCasts(integerLiteral(equals(10)));
 }
 
 TEST_P(ASTMatchersTest, HasDefinition_MatchesStructDefinition) {


Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3219,13 +3219,13 @@
 }
 
 TEST_P(ASTMatchersTest, HasArraySize) {
-  if (GetParam().Language != Lang_CXX03) {
-// FIXME: Fix this test to work in all C++ language modes.
+  if (!GetParam().isCXX()) {
 return;
   }
 
   EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
-  cxxNewExpr(hasArraySize(integerLiteral(equals(10));
+  cxxNewExpr(hasArraySize(
+  ignoringParenImpCasts(integerLiteral(equals(10)));
 }
 
 TEST_P(ASTMatchersTest, HasDefinition_MatchesStructDefinition) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1bf055c - [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer

2020-04-07 Thread Dmitri Gribenko via cfe-commits

Author: Marcel Hlopko
Date: 2020-04-07T15:07:16+02:00
New Revision: 1bf055c9891f1a5ab2ff6a04348bd83fcc0a9cde

URL: 
https://github.com/llvm/llvm-project/commit/1bf055c9891f1a5ab2ff6a04348bd83fcc0a9cde
DIFF: 
https://github.com/llvm/llvm-project/commit/1bf055c9891f1a5ab2ff6a04348bd83fcc0a9cde.diff

LOG: [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer

Summary:
Same restrictions apply as in the other direction: macro arguments are
not supported yet, only full macro expansions can be mapped.

Taking over from https://reviews.llvm.org/D72581.

Reviewers: gribozavr2, sammccall

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Tokens.h
clang/lib/Tooling/Syntax/Tokens.cpp
clang/unittests/Tooling/Syntax/TokensTest.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Tokens.h 
b/clang/include/clang/Tooling/Syntax/Tokens.h
index 7e50892284f4..a7f9369ddfff 100644
--- a/clang/include/clang/Tooling/Syntax/Tokens.h
+++ b/clang/include/clang/Tooling/Syntax/Tokens.h
@@ -171,7 +171,6 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const 
Token &T);
 /// To build a token buffer use the TokenCollector class. You can also compute
 /// the spelled tokens of a file using the tokenize() helper.
 ///
-/// FIXME: allow to map from spelled to expanded tokens when use-case shows up.
 /// FIXME: allow mappings into macro arguments.
 class TokenBuffer {
 public:
@@ -228,6 +227,36 @@ class TokenBuffer {
   llvm::Optional>
   spelledForExpanded(llvm::ArrayRef Expanded) const;
 
+  /// Find the subranges of expanded tokens, corresponding to \p Spelled.
+  ///
+  /// Some spelled tokens may not be present in the expanded token stream, so
+  /// this function can return an empty vector, e.g. for tokens of macro
+  /// directives or disabled preprocessor branches.
+  ///
+  /// Some spelled tokens can be duplicated in the expanded token stream
+  /// multiple times and this function will return multiple results in those
+  /// cases. This happens when \p Spelled is inside a macro argument.
+  ///
+  /// FIXME: return correct results on macro arguments. For now, we return an
+  ///empty list.
+  ///
+  /// (!) will return empty vector on tokens from #define body:
+  /// E.g. for the following example:
+  ///
+  ///   #define FIRST(A) f1 A = A f2
+  ///   #define SECOND s
+  ///
+  ///   a FIRST(arg) b SECOND c // expanded tokens are: a f1 arg = arg f2 b s
+  /// The results would be
+  ///   spelled   => expanded
+  ///   
+  ///   #define FIRST => {}
+  ///   a FIRST(arg)  => {a f1 arg = arg f2}
+  ///   arg   => {arg, arg} // arg #1 is before `=` and arg #2 is
+  ///   // after `=` in the expanded tokens.
+  llvm::SmallVector, 1>
+  expandedForSpelled(llvm::ArrayRef Spelled) const;
+
   /// An expansion produced by the preprocessor, includes macro expansions and
   /// preprocessor directives. Preprocessor always maps a non-empty range of
   /// spelled tokens to a (possibly empty) range of expanded tokens. Here is a
@@ -317,6 +346,12 @@ class TokenBuffer {
   std::pair
   spelledForExpandedToken(const syntax::Token *Expanded) const;
 
+  /// Returns a mapping starting before \p Spelled token, or nullptr if no
+  /// such mapping exists.
+  static const Mapping *
+  mappingStartingBeforeSpelled(const MarkedFile &F,
+   const syntax::Token *Spelled);
+
   /// Token stream produced after preprocessing, conceputally this captures the
   /// same stream as 'clang -E' (excluding the preprocessor directives like
   /// #file, etc.).

diff  --git a/clang/lib/Tooling/Syntax/Tokens.cpp 
b/clang/lib/Tooling/Syntax/Tokens.cpp
index f214afb5c85e..1464d97d037d 100644
--- a/clang/lib/Tooling/Syntax/Tokens.cpp
+++ b/clang/lib/Tooling/Syntax/Tokens.cpp
@@ -213,19 +213,109 @@ TokenBuffer::spelledForExpandedToken(const syntax::Token 
*Expanded) const {
   // Our token could only be produced by the previous mapping.
   if (It == File.Mappings.begin()) {
 // No previous mapping, no need to modify offsets.
-return {&File.SpelledTokens[ExpandedIndex - File.BeginExpanded], nullptr};
+return {&File.SpelledTokens[ExpandedIndex - File.BeginExpanded],
+/*Mapping=*/nullptr};
   }
   --It; // 'It' now points to last mapping that started before our token.
 
   // Check if the token is part of the mapping.
   if (ExpandedIndex < It->EndExpanded)
-return {&File.SpelledTokens[It->BeginSpelled], /*Mapping*/ &*It};
+return {&File.SpelledTokens[It->BeginSpelled], /*Mapping=*/&*It};
 
   // Not part of the mapping, use the index from previous mapping to compute 
the
   // corresponding spelled token.
   return {

[clang] 06cf7ad - Make syntax tree test print the line number when it fails

2020-06-04 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-04T10:42:44+02:00
New Revision: 06cf7adcc88178f887984fa74cdefb20cd8cd124

URL: 
https://github.com/llvm/llvm-project/commit/06cf7adcc88178f887984fa74cdefb20cd8cd124
DIFF: 
https://github.com/llvm/llvm-project/commit/06cf7adcc88178f887984fa74cdefb20cd8cd124.diff

LOG: Make syntax tree test print the line number when it fails

Summary:
The syntax tree test uses a helper function that executes all testing
assertions. When an assertion fails, the only line number that gets
printed to the log refers to the helper function. After this change, we
would also get the line number of the EXPECT_TRUE macro invocation
(unfortunately, the line number of the last token of it, not the first
one, but there's not much I can do about it).

Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index b8a188a1a76b..c7a2b14b4f3f 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -209,15 +209,22 @@ class SyntaxTreeTest : public ::testing::Test,
 return Root;
   }
 
-  void expectTreeDumpEqual(StringRef Code, StringRef Tree) {
+  ::testing::AssertionResult treeDumpEqual(StringRef Code, StringRef Tree) {
 SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " "));
-SCOPED_TRACE(Code);
 
 auto *Root = buildTree(Code, GetParam());
-EXPECT_EQ(Diags->getClient()->getNumErrors(), 0u)
-<< "Source file has syntax errors, they were printed to the test log";
+if (Diags->getClient()->getNumErrors() != 0) {
+  return ::testing::AssertionFailure()
+ << "Source file has syntax errors, they were printed to the test "
+"log";
+}
 std::string Actual = std::string(StringRef(Root->dump(*Arena)).trim());
+// EXPECT_EQ shows the 
diff  between the two strings if they are 
diff erent.
 EXPECT_EQ(Tree.trim().str(), Actual);
+if (Actual != Tree.trim().str()) {
+  return ::testing::AssertionFailure();
+}
+return ::testing::AssertionSuccess();
   }
 
   // Adds a file to the test VFS.
@@ -266,11 +273,11 @@ class SyntaxTreeTest : public ::testing::Test,
 };
 
 TEST_P(SyntaxTreeTest, Simple) {
-  expectTreeDumpEqual(
+  EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 int main() {}
 void foo() {}
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
@@ -293,15 +300,15 @@ void foo() {}
   `-CompoundStatement
 |-{
 `-}
-)txt");
+)txt"));
 }
 
 TEST_P(SyntaxTreeTest, SimpleVariable) {
-  expectTreeDumpEqual(
+  EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 int a;
 int b = 42;
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
@@ -317,14 +324,14 @@ int b = 42;
   | `-UnknownExpression
   |   `-42
   `-;
-)txt");
+)txt"));
 }
 
 TEST_P(SyntaxTreeTest, SimpleFunction) {
-  expectTreeDumpEqual(
+  EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 void foo(int a, int b) {}
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
@@ -346,17 +353,17 @@ void foo(int a, int b) {}
   `-CompoundStatement
 |-{
 `-}
-)txt");
+)txt"));
 }
 
 TEST_P(SyntaxTreeTest, If) {
-  expectTreeDumpEqual(
+  EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 int main() {
   if (1) {}
   if (1) {} else if (0) {}
 }
-)cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
@@ -397,11 +404,11 @@ int main() {
 | |-{
 | `-}
 `-}
-)txt");
+)txt"));
 }
 
 TEST_P(SyntaxTreeTest, For) {
-  expectTreeDumpEqual(
+  EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 void test() {
   for (;;)  {}
@@ -428,21 +435,21 @@ void test() {
 |   |-{
 |   `-}
 `-}
-)txt");
+)txt"));
 }
 
 TEST_P(SyntaxTreeTest, RangeBasedFor) {
   if (!GetParam().isCXX11OrLater()) {
 return;
   }
-  expectTreeDumpEqual(
+  EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 void test() {
   int a[3];
   for (int x : a)
 ;
 }
-  )cpp",
+)cpp",
   R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
@@ -479,12 +486,17 @@ void test() {
 | `-EmptyStatement
 |   `-;
 `-}
-   )txt");
+)txt"));
 }
 
 TEST_P(SyntaxTreeTest, DeclarationStatement) {
-  expectTreeDumpEqual("void test() { int a = 10; }",
-  R"txt(
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test() {
+  int a = 10;
+}
+)cpp",
+  R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -505,11 +517,11 @@ TEST_P(SyntaxTreeTest, DeclarationStatement) {
 | | `-10
 | `-;
 `-}
-)txt");
+)txt"));
 }
 
 TEST_P(SyntaxTreeTest, Switch) {
-  expectTreeDumpEqual(
+  EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 void test() {
   switch (1) {
@@

[clang] 3b73969 - Add support for IntegerLiteral in SyntaxTree

2020-06-04 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-06-04T14:05:31+02:00
New Revision: 3b739690b01e595f6da412316b58a0a291702049

URL: 
https://github.com/llvm/llvm-project/commit/3b739690b01e595f6da412316b58a0a291702049
DIFF: 
https://github.com/llvm/llvm-project/commit/3b739690b01e595f6da412316b58a0a291702049.diff

LOG: Add support for IntegerLiteral in SyntaxTree

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index ce4dc35977f1..bf0308c95ba4 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -44,6 +44,7 @@ enum class NodeKind : uint16_t {
   PostfixUnaryOperatorExpression,
   BinaryOperatorExpression,
   CxxNullPtrExpression,
+  IntegerLiteralExpression,
 
   // Statements.
   UnknownStatement,
@@ -114,6 +115,7 @@ enum class NodeRole : uint8_t {
   BinaryOperatorExpression_operatorToken,
   BinaryOperatorExpression_rightHandSide,
   CxxNullPtrExpression_keyword,
+  IntegerLiteralExpression_literalToken,
   CaseStatement_value,
   IfStatement_thenStatement,
   IfStatement_elseKeyword,
@@ -178,6 +180,16 @@ class CxxNullPtrExpression final : public Expression {
   syntax::Leaf *nullPtrKeyword();
 };
 
+/// Expression for integer literals.
+class IntegerLiteralExpression final : public Expression {
+public:
+  IntegerLiteralExpression() : Expression(NodeKind::IntegerLiteralExpression) 
{}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::IntegerLiteralExpression;
+  }
+  syntax::Leaf *literalToken();
+};
+
 /// An abstract class for prefix and postfix unary operators.
 class UnaryOperatorExpression : public Expression {
 public:

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index dcc7b3e19390..1f81cb4a12b0 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -608,6 +608,15 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
+Builder.markChildToken(
+S->getLocation(),
+syntax::NodeRole::IntegerLiteralExpression_literalToken);
+Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::IntegerLiteralExpression, S);
+return true;
+  }
+
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
 Builder.markChildToken(S->getLocation(),
syntax::NodeRole::CxxNullPtrExpression_keyword);

diff  --git a/clang/lib/Tooling/Syntax/Nodes.cpp 
b/clang/lib/Tooling/Syntax/Nodes.cpp
index 3311b8df034c..d70b89b07200 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -20,6 +20,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, 
NodeKind K) {
 return OS << "UnknownExpression";
   case NodeKind::CxxNullPtrExpression:
 return OS << "CxxNullPtrExpression";
+  case NodeKind::IntegerLiteralExpression:
+return OS << "IntegerLiteralExpression";
   case NodeKind::PrefixUnaryOperatorExpression:
 return OS << "PrefixUnaryOperatorExpression";
   case NodeKind::PostfixUnaryOperatorExpression:
@@ -118,6 +120,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream 
&OS, NodeRole R) {
 return OS << "IfStatement_elseKeyword";
   case syntax::NodeRole::IfStatement_elseStatement:
 return OS << "IfStatement_elseStatement";
+  case syntax::NodeRole::IntegerLiteralExpression_literalToken:
+return OS << "IntegerLiteralExpression_literalToken";
   case syntax::NodeRole::CxxNullPtrExpression_keyword:
 return OS << "CxxNullPtrExpression_keyword";
   case syntax::NodeRole::UnaryOperatorExpression_operatorToken:
@@ -162,6 +166,11 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream 
&OS, NodeRole R) {
   llvm_unreachable("invalid role");
 }
 
+syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
+  return llvm::cast_or_null(
+  findChild(syntax::NodeRole::IntegerLiteralExpression_literalToken));
+}
+
 syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::CxxNullPtrExpression_keyword));

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index c7a2b14b4f3f..49fdcb7a9c54 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -64,6 +64,11 @@ struct TestClangConfig {
Language == Lang_CXX17 || Language == Lang_CXX20;
   }

[clang] 62305f6 - Rename arrow -> arrowToken for unified naming

2020-06-04 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-06-04T16:12:16+02:00
New Revision: 62305f6db4ed642c6b2b005dcb7951eb38342dca

URL: 
https://github.com/llvm/llvm-project/commit/62305f6db4ed642c6b2b005dcb7951eb38342dca
DIFF: 
https://github.com/llvm/llvm-project/commit/62305f6db4ed642c6b2b005dcb7951eb38342dca.diff

LOG: Rename arrow -> arrowToken for unified naming

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/Nodes.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index bf0308c95ba4..7d0c4439e279 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -639,7 +639,7 @@ class TrailingReturnType final : public Tree {
 return N->kind() == NodeKind::TrailingReturnType;
   }
   // TODO: add accessors for specifiers.
-  syntax::Leaf *arrow();
+  syntax::Leaf *arrowToken();
   syntax::SimpleDeclarator *declarator();
 };
 

diff  --git a/clang/lib/Tooling/Syntax/Nodes.cpp 
b/clang/lib/Tooling/Syntax/Nodes.cpp
index d70b89b07200..bad902b8c6d7 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -400,7 +400,7 @@ syntax::Leaf *syntax::ArraySubscript::rbracket() {
   findChild(syntax::NodeRole::CloseParen));
 }
 
-syntax::Leaf *syntax::TrailingReturnType::arrow() {
+syntax::Leaf *syntax::TrailingReturnType::arrowToken() {
   return llvm::cast_or_null(
   findChild(syntax::NodeRole::TrailingReturnType_arrow));
 }



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


[clang] b5fc1de - Use libClangTesting in the unittest for AST matchers

2020-06-04 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-04T17:40:39+02:00
New Revision: b5fc1deb5ba1f3cd432ecb8b86c2536470463163

URL: 
https://github.com/llvm/llvm-project/commit/b5fc1deb5ba1f3cd432ecb8b86c2536470463163
DIFF: 
https://github.com/llvm/llvm-project/commit/b5fc1deb5ba1f3cd432ecb8b86c2536470463163.diff

LOG: Use libClangTesting in the unittest for AST matchers

Summary:
The unittest for AST matchers has its own way to specify language
standards. I unified it with the shared infrastructure from
libClangTesting.

Reviewers: jdoerfert, hlopko

Reviewed By: hlopko

Subscribers: mgorny, sstefan1, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Testing/CommandLineArgs.h
clang/lib/Testing/CommandLineArgs.cpp
clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
clang/unittests/ASTMatchers/ASTMatchersTest.h
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
clang/unittests/ASTMatchers/CMakeLists.txt
clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
clang/unittests/Sema/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Testing/CommandLineArgs.h 
b/clang/include/clang/Testing/CommandLineArgs.h
index 432a112b2e15..95979a2bfb80 100644
--- a/clang/include/clang/Testing/CommandLineArgs.h
+++ b/clang/include/clang/Testing/CommandLineArgs.h
@@ -13,6 +13,8 @@
 #ifndef LLVM_CLANG_TESTING_COMMANDLINEARGS_H
 #define LLVM_CLANG_TESTING_COMMANDLINEARGS_H
 
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/StringRef.h"
 #include 
 #include 
 
@@ -32,6 +34,8 @@ enum TestLanguage {
 
 std::vector getCommandLineArgsForTesting(TestLanguage Lang);
 
+StringRef getFilenameForTesting(TestLanguage Lang);
+
 } // end namespace clang
 
 #endif

diff  --git a/clang/lib/Testing/CommandLineArgs.cpp 
b/clang/lib/Testing/CommandLineArgs.cpp
index 1d12187494be..7375dbc6ee70 100644
--- a/clang/lib/Testing/CommandLineArgs.cpp
+++ b/clang/lib/Testing/CommandLineArgs.cpp
@@ -45,4 +45,25 @@ std::vector 
getCommandLineArgsForTesting(TestLanguage Lang) {
   return Args;
 }
 
+StringRef getFilenameForTesting(TestLanguage Lang) {
+  switch (Lang) {
+  case Lang_C89:
+  case Lang_C99:
+return "input.c";
+
+  case Lang_CXX03:
+  case Lang_CXX11:
+  case Lang_CXX14:
+  case Lang_CXX17:
+  case Lang_CXX20:
+return "input.cc";
+
+  case Lang_OpenCL:
+return "input.cl";
+
+  case Lang_OBJCXX:
+return "input.mm";
+  }
+}
+
 } // end namespace clang

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
index 2886481ea262..2354f45de409 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
@@ -212,18 +212,18 @@ TEST(Matcher, IsExpansionInMainFileMatcher) {
   M.push_back(std::make_pair("/other", "class X {};"));
   EXPECT_TRUE(matchesConditionally("#include \n",
recordDecl(isExpansionInMainFile()), false,
-   "-isystem/", M));
+   {"-isystem/"}, M));
 }
 
 TEST(Matcher, IsExpansionInSystemHeader) {
   FileContentMappings M;
   M.push_back(std::make_pair("/other", "class X {};"));
-  EXPECT_TRUE(matchesConditionally(
-  "#include \"other\"\n", recordDecl(isExpansionInSystemHeader()), true,
-  "-isystem/", M));
   EXPECT_TRUE(matchesConditionally("#include \"other\"\n",
recordDecl(isExpansionInSystemHeader()),
-   false, "-I/", M));
+   true, {"-isystem/"}, M));
+  EXPECT_TRUE(matchesConditionally("#include \"other\"\n",
+   recordDecl(isExpansionInSystemHeader()),
+   false, {"-I/"}, M));
   EXPECT_TRUE(notMatches("class X {};",
  recordDecl(isExpansionInSystemHeader(;
   EXPECT_TRUE(notMatches("", recordDecl(isExpansionInSystemHeader(;
@@ -238,13 +238,13 @@ TEST(Matcher, IsExpansionInFileMatching) {
   "#include \n"
   "class X {};",
   recordDecl(isExpansionInFileMatching("b.*"), hasName("B")), true,
-  "-isystem/", M));
+  {"-isystem/"}, M));
   EXPECT_TRUE(matchesConditionally(
   "#include \n"
   "#include \n"
   "class X {};",
   recordDecl(isExpansionInFileMatching("f.*"), hasName("X")), false,
-  "-isystem/", M));
+  {"-isystem/"}, M));
 }
 
 #endif // _WIN32

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 80eebf227a31..fa5c61eece29 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatcher

[clang] 42f6fec - Propose naming principle for NodeRole and apply it

2020-06-04 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-06-04T20:08:35+02:00
New Revision: 42f6fec3878d708f2791ab0be3a060b07dac9d76

URL: 
https://github.com/llvm/llvm-project/commit/42f6fec3878d708f2791ab0be3a060b07dac9d76
DIFF: 
https://github.com/llvm/llvm-project/commit/42f6fec3878d708f2791ab0be3a060b07dac9d76.diff

LOG: Propose naming principle for NodeRole and apply it

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index 7d0c4439e279..7e05aa968f02 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -91,6 +91,23 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, 
NodeKind K);
 
 /// A relation between a parent and child node, e.g. 'left-hand-side of
 /// a binary expression'. Used for implementing accessors.
+///
+/// Some roles describe parent/child relations that occur multiple times in
+/// language grammar. We define only one role to describe all instances of such
+/// recurring relations. For example, grammar for both "if" and "while"
+/// statements requires an opening paren and a closing paren. The opening
+/// paren token is assigned the OpenParen role regardless of whether it appears
+/// as a child of IfStatement or WhileStatement node. More generally, when
+/// grammar requires a certain fixed token (like a specific keyword, or an
+/// opening paren), we define a role for this token and use it across all
+/// grammar rules with the same requirement. Names of such reusable roles end
+/// with a ~Token or a ~Keyword suffix.
+///
+/// Some roles are assigned only to child nodes of one specific parent syntax
+/// node type. Names of such roles start with the name of the parent syntax 
tree
+/// node type. For example, a syntax node with a role
+/// BinaryOperatorExpression_leftHandSide can only appear as a child of a
+/// BinaryOperatorExpression node.
 enum class NodeRole : uint8_t {
   // Roles common to multiple node kinds.
   /// A node without a parent
@@ -103,19 +120,21 @@ enum class NodeRole : uint8_t {
   CloseParen,
   /// A keywords that introduces some grammar construct, e.g. 'if', 'try', etc.
   IntroducerKeyword,
+  /// A token that represents a literal, e.g. 'nullptr', '1', 'true', etc.
+  LiteralToken,
+  /// Tokens or Keywords
+  ArrowToken,
+  ExternKeyword,
   /// An inner statement for those that have only a single child of kind
   /// statement, e.g. loop body for while, for, etc; inner statement for case,
   /// default, etc.
   BodyStatement,
 
   // Roles specific to particular node kinds.
-  UnaryOperatorExpression_operatorToken,
+  OperatorExpression_operatorToken,
   UnaryOperatorExpression_operand,
   BinaryOperatorExpression_leftHandSide,
-  BinaryOperatorExpression_operatorToken,
   BinaryOperatorExpression_rightHandSide,
-  CxxNullPtrExpression_keyword,
-  IntegerLiteralExpression_literalToken,
   CaseStatement_value,
   IfStatement_thenStatement,
   IfStatement_elseKeyword,
@@ -127,10 +146,8 @@ enum class NodeRole : uint8_t {
   StaticAssertDeclaration_message,
   SimpleDeclaration_declarator,
   TemplateDeclaration_declaration,
-  ExplicitTemplateInstantiation_externKeyword,
   ExplicitTemplateInstantiation_declaration,
   ArraySubscript_sizeExpression,
-  TrailingReturnType_arrow,
   TrailingReturnType_declarator,
   ParametersAndQualifiers_parameter,
   ParametersAndQualifiers_trailingReturn

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 1f81cb4a12b0..9ce12ac21f8b 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -609,26 +609,22 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool WalkUpFromIntegerLiteral(IntegerLiteral *S) {
-Builder.markChildToken(
-S->getLocation(),
-syntax::NodeRole::IntegerLiteralExpression_literalToken);
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::IntegerLiteralExpression, S);
 return true;
   }
 
   bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
-Builder.markChildToken(S->getLocation(),
-   syntax::NodeRole::CxxNullPtrExpression_keyword);
+Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
 Builder.foldNode(Builder.getExprRange(S),
  new (allocator()) syntax::CxxNullPtrExpression, S);
 return true;
   }
 
   bool WalkUpFromUnaryOperator(UnaryOperator *S) {
-Builder.markChildTo

[clang] a180d54 - AST Matchers test: use arrays instead of vectors

2020-06-04 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-06-04T21:40:30+02:00
New Revision: a180d5409f218d933bec99bc28f7a9970fb293d4

URL: 
https://github.com/llvm/llvm-project/commit/a180d5409f218d933bec99bc28f7a9970fb293d4
DIFF: 
https://github.com/llvm/llvm-project/commit/a180d5409f218d933bec99bc28f7a9970fb293d4.diff

LOG: AST Matchers test: use arrays instead of vectors

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/ASTMatchers/ASTMatchersTest.h

Removed: 




diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index 54f73826af60..11aedf65ec29 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -59,24 +59,23 @@ class VerifyMatch : public MatchFinder::MatchCallback {
 };
 
 inline ArrayRef langCxx11OrLater() {
-  static std::vector Result = {Lang_CXX11, Lang_CXX14, 
Lang_CXX17,
- Lang_CXX20};
+  static const TestLanguage Result[] = {Lang_CXX11, Lang_CXX14, Lang_CXX17,
+Lang_CXX20};
   return Result;
 }
 
 inline ArrayRef langCxx14OrLater() {
-  static std::vector Result = {Lang_CXX14, Lang_CXX17,
- Lang_CXX20};
+  static const TestLanguage Result[] = {Lang_CXX14, Lang_CXX17, Lang_CXX20};
   return Result;
 }
 
 inline ArrayRef langCxx17OrLater() {
-  static std::vector Result = {Lang_CXX17, Lang_CXX20};
+  static const TestLanguage Result[] = {Lang_CXX17, Lang_CXX20};
   return Result;
 }
 
 inline ArrayRef langCxx20OrLater() {
-  static std::vector Result = {Lang_CXX20};
+  static const TestLanguage Result[] = {Lang_CXX20};
   return Result;
 }
 



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


[clang] 7988969 - Added tests for RecursiveASTVisitor for AST nodes that are special cased

2020-07-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-03T13:03:18+02:00
New Revision: 79889691430d8e76e908706170102a8b46432a07

URL: 
https://github.com/llvm/llvm-project/commit/79889691430d8e76e908706170102a8b46432a07
DIFF: 
https://github.com/llvm/llvm-project/commit/79889691430d8e76e908706170102a8b46432a07.diff

LOG: Added tests for RecursiveASTVisitor for AST nodes that are special cased

Summary:
RecursiveASTVisitor has special code for handling operator AST nodes,
specifically, unary, binary, and compound assignment operators. In this
change I'm adding tests for operator AST nodes that follow the existing
pattern of tests for the CallExpr node (an AST node that triggers the
common code path).

Reviewers: ymandel, eduucaldas

Reviewed By: ymandel, eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Removed: 




diff  --git a/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
index 0eb9a43ecb14..66aa1d763833 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
@@ -41,6 +41,11 @@ class RecordingVisitorBase : public TestVisitor {
 if (IntegerLiteral *IL = dyn_cast(S)) {
   return (ClassName + "(" + IL->getValue().toString(10, false) + 
")").str();
 }
+if (UnaryOperator *UO = dyn_cast(S)) {
+  return (ClassName + "(" + UnaryOperator::getOpcodeStr(UO->getOpcode()) +
+  ")")
+  .str();
+}
 if (BinaryOperator *BO = dyn_cast(S)) {
   return (ClassName + "(" + BinaryOperator::getOpcodeStr(BO->getOpcode()) +
   ")")
@@ -390,15 +395,15 @@ WalkUpFromStmt CompoundStmt
 )txt"));
 }
 
-TEST(RecursiveASTVisitor, StmtCallbacks_TraverseBinaryOperator) {
+TEST(RecursiveASTVisitor, StmtCallbacks_TraverseUnaryOperator) {
   class RecordingVisitor : public RecordingVisitorBase {
   public:
 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
 : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
 
-bool TraverseBinaryOperator(BinaryOperator *BO) {
-  recordCallback(__func__, BO, [&]() {
-RecordingVisitorBase::TraverseBinaryOperator(BO);
+bool TraverseUnaryOperator(UnaryOperator *UO) {
+  recordCallback(__func__, UO, [&]() {
+RecordingVisitorBase::TraverseUnaryOperator(UO);
   });
   return true;
 }
@@ -411,27 +416,24 @@ TEST(RecursiveASTVisitor, 
StmtCallbacks_TraverseBinaryOperator) {
   };
 
   StringRef Code = R"cpp(
-void add(int, int);
 void test() {
   1;
-  2 + 3;
-  add(4, 5);
+  -2;
+  3;
 }
 )cpp";
 
+  // TraverseUnaryOperator is not called because RecursiveASTVisitor treats
+  // individual operators as subclasses, for which it calls their Traverse
+  // methods.
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::No), Code,
   R"txt(
 WalkUpFromStmt CompoundStmt
 WalkUpFromStmt IntegerLiteral(1)
-WalkUpFromStmt BinaryOperator(+)
+WalkUpFromStmt UnaryOperator(-)
 WalkUpFromStmt IntegerLiteral(2)
 WalkUpFromStmt IntegerLiteral(3)
-WalkUpFromStmt CallExpr(add)
-WalkUpFromStmt ImplicitCastExpr
-WalkUpFromStmt DeclRefExpr(add)
-WalkUpFromStmt IntegerLiteral(4)
-WalkUpFromStmt IntegerLiteral(5)
 )txt"));
 
   EXPECT_TRUE(visitorCallbackLogEqual(
@@ -439,27 +441,22 @@ WalkUpFromStmt IntegerLiteral(5)
   R"txt(
 WalkUpFromStmt IntegerLiteral(1)
 WalkUpFromStmt IntegerLiteral(2)
+WalkUpFromStmt UnaryOperator(-)
 WalkUpFromStmt IntegerLiteral(3)
-WalkUpFromStmt BinaryOperator(+)
-WalkUpFromStmt DeclRefExpr(add)
-WalkUpFromStmt ImplicitCastExpr
-WalkUpFromStmt IntegerLiteral(4)
-WalkUpFromStmt IntegerLiteral(5)
-WalkUpFromStmt CallExpr(add)
 WalkUpFromStmt CompoundStmt
 )txt"));
 }
 
 TEST(RecursiveASTVisitor,
- StmtCallbacks_TraverseBinaryOperator_WalkUpFromBinaryOperator) {
+ StmtCallbacks_TraverseUnaryOperator_WalkUpFromUnaryOperator) {
   class RecordingVisitor : public RecordingVisitorBase {
   public:
 RecordingVisitor(ShouldTraversePostOrder ShouldTraversePostOrderValue)
 : RecordingVisitorBase(ShouldTraversePostOrderValue) {}
 
-bool TraverseBinaryOperator(BinaryOperator *BO) {
-  recordCallback(__func__, BO, [&]() {
-RecordingVisitorBase::TraverseBinaryOperator(BO);
+bool TraverseUnaryOperator(UnaryOperator *UO) {
+  recordCallback(__func__, UO, [&]() {
+RecordingVisitorBase::TraverseUnaryOperator(UO);
   });
   return true;
 }
@@ -476,49 +473,38 @@ TEST(RecursiveASTVisitor,
   return true;
 }
 
-bool WalkUpFromBinaryOperator(BinaryOperator *BO) {
-  recordCallback(__func__, BO, [&]() {
-RecordingVisitorBase::WalkUpFromBinaryOperator(BO);
+bool W

[clang] 7b0be96 - Make RecursiveASTVisitor call WalkUpFrom for unary and binary operators in post-order traversal mode

2020-07-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-03T13:03:19+02:00
New Revision: 7b0be962d681c408c8ecf7180c6ad8f9fbcdaf2d

URL: 
https://github.com/llvm/llvm-project/commit/7b0be962d681c408c8ecf7180c6ad8f9fbcdaf2d
DIFF: 
https://github.com/llvm/llvm-project/commit/7b0be962d681c408c8ecf7180c6ad8f9fbcdaf2d.diff

LOG: Make RecursiveASTVisitor call WalkUpFrom for unary and binary operators in 
post-order traversal mode

Reviewers: ymandel, eduucaldas, rsmith

Reviewed By: eduucaldas, rsmith

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 821a6c549b71..3d7cb73a471c 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -589,7 +589,6 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt *S,
 
   BINOP_LIST()
 #undef OPERATOR
-#undef BINOP_LIST
 
 #define OPERATOR(NAME) 
\
   case BO_##NAME##Assign:  
\
@@ -597,7 +596,6 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt *S,
 
   CAO_LIST()
 #undef OPERATOR
-#undef CAO_LIST
 }
   } else if (UnaryOperator *UnOp = dyn_cast(S)) {
 switch (UnOp->getOpcode()) {
@@ -607,7 +605,6 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt *S,
 
   UNARYOP_LIST()
 #undef OPERATOR
-#undef UNARYOP_LIST
 }
   }
 
@@ -629,27 +626,68 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt 
*S,
 
 template 
 bool RecursiveASTVisitor::PostVisitStmt(Stmt *S) {
+  // In pre-order traversal mode, each Traverse##STMT method is responsible for
+  // calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT and
+  // does not call the default implementation, the WalkUpFrom callback is not
+  // called. Post-order traversal mode should provide the same behavior
+  // regarding method overrides.
+  //
+  // In post-order traversal mode the Traverse##STMT method, when it receives a
+  // DataRecursionQueue, can't call WalkUpFrom after traversing children 
because
+  // it only enqueues the children and does not traverse them. TraverseStmt
+  // traverses the enqueued children, and we call WalkUpFrom here.
+  //
+  // However, to make pre-order and post-order modes identical with regards to
+  // whether they call WalkUpFrom at all, we call WalkUpFrom if and only if the
+  // user did not override the Traverse##STMT method. We implement the override
+  // check with isSameMethod calls below.
+
+  if (BinaryOperator *BinOp = dyn_cast(S)) {
+switch (BinOp->getOpcode()) {
+#define OPERATOR(NAME) 
\
+  case BO_##NAME:  
\
+if (isSameMethod(&RecursiveASTVisitor::TraverseBin##NAME,  
\
+ &Derived::TraverseBin##NAME)) {   
\
+  TRY_TO(WalkUpFromBin##NAME(static_cast(S)));   
\
+}  
\
+return true;
+
+  BINOP_LIST()
+#undef OPERATOR
+
+#define OPERATOR(NAME) 
\
+  case BO_##NAME##Assign:  
\
+if (isSameMethod(&RecursiveASTVisitor::TraverseBin##NAME##Assign,  
\
+ &Derived::TraverseBin##NAME##Assign)) {   
\
+  TRY_TO(WalkUpFromBin##NAME##Assign(  
\
+  static_cast(S)));  
\
+}  
\
+return true;
+
+  CAO_LIST()
+#undef OPERATOR
+}
+  } else if (UnaryOperator *UnOp = dyn_cast(S)) {
+switch (UnOp->getOpcode()) {
+#define OPERATOR(NAME) 
\
+  case UO_##NAME:  
\
+if (isSameMethod(&RecursiveASTVisitor::TraverseUnary##NAME,
\
+ &Derived::TraverseUnary##NAME)) { 
\
+  TRY_TO(WalkUpFromUnary##NAME(static_cast(S)));  
\
+}  
\
+return true;
+
+  UNARYOP_LIST()
+#undef OPERATOR
+}
+  }
+
   switch (S->getStmtClass()) {
   case Stmt::NoStmtClass:
 break;
 #define ABSTRACT_STMT(STMT)
 #define STMT(CLASS, PARENT)
\
   case Stmt::CLASS##Class: 
\
-/* In pre-

[clang] 8bf4c40 - Make RecursiveASTVisitor call WalkUpFrom for operators when the data recursion queue is absent

2020-07-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-03T13:03:19+02:00
New Revision: 8bf4c40af813e73de77739b33b8808f6bd13497b

URL: 
https://github.com/llvm/llvm-project/commit/8bf4c40af813e73de77739b33b8808f6bd13497b
DIFF: 
https://github.com/llvm/llvm-project/commit/8bf4c40af813e73de77739b33b8808f6bd13497b.diff

LOG: Make RecursiveASTVisitor call WalkUpFrom for operators when the data 
recursion queue is absent

Reviewers: eduucaldas, ymandel, rsmith

Reviewed By: eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3d7cb73a471c..ba36d5b23fc6 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -412,6 +412,8 @@ template  class RecursiveASTVisitor {
 if (!getDerived().shouldTraversePostOrder())   
\
   TRY_TO(WalkUpFromUnary##NAME(S));
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());  
\
+if (!Queue && getDerived().shouldTraversePostOrder())  
\
+  TRY_TO(WalkUpFromUnary##NAME(S));
\
 return true;   
\
   }
\
   bool WalkUpFromUnary##NAME(UnaryOperator *S) {   
\
@@ -433,6 +435,8 @@ template  class RecursiveASTVisitor {
   TRY_TO(WalkUpFromBin##NAME(S));  
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS());  
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS());  
\
+if (!Queue && getDerived().shouldTraversePostOrder())  
\
+  TRY_TO(WalkUpFromBin##NAME(S));  
\
 return true;   
\
   }
\
   bool WalkUpFromBin##NAME(BINOP_TYPE *S) {
\

diff  --git a/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
index 0a4e9aa1e9e8..70c7eb37ad4c 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
@@ -606,14 +606,13 @@ TraverseUnaryMinus UnaryOperator(-)
 WalkUpFromStmt IntegerLiteral(3)
 )txt"));
 
-  // FIXME: The following log should include a call to WalkUpFromStmt for
-  // UnaryOperator(-).
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
   R"txt(
 WalkUpFromStmt IntegerLiteral(1)
 TraverseUnaryMinus UnaryOperator(-)
   WalkUpFromStmt IntegerLiteral(2)
+  WalkUpFromStmt UnaryOperator(-)
 WalkUpFromStmt IntegerLiteral(3)
 WalkUpFromStmt CompoundStmt
 )txt"));
@@ -675,7 +674,6 @@ WalkUpFromExpr IntegerLiteral(3)
   WalkUpFromStmt IntegerLiteral(3)
 )txt"));
 
-  // FIXME: The following log should include a call to WalkUpFromUnaryMinus.
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
   R"txt(
@@ -684,6 +682,9 @@ WalkUpFromExpr IntegerLiteral(1)
 TraverseUnaryMinus UnaryOperator(-)
   WalkUpFromExpr IntegerLiteral(2)
 WalkUpFromStmt IntegerLiteral(2)
+  WalkUpFromUnaryMinus UnaryOperator(-)
+WalkUpFromExpr UnaryOperator(-)
+  WalkUpFromStmt UnaryOperator(-)
 WalkUpFromExpr IntegerLiteral(3)
   WalkUpFromStmt IntegerLiteral(3)
 WalkUpFromStmt CompoundStmt
@@ -996,8 +997,6 @@ TraverseBinAdd BinaryOperator(+)
 WalkUpFromStmt IntegerLiteral(4)
 )txt"));
 
-  // FIXME: The following log should include a call to WalkUpFromStmt for
-  // BinaryOperator(+).
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
   R"txt(
@@ -1005,6 +1004,7 @@ WalkUpFromStmt IntegerLiteral(1)
 TraverseBinAdd BinaryOperator(+)
   WalkUpFromStmt IntegerLiteral(2)
   WalkUpFromStmt IntegerLiteral(3)
+  WalkUpFromStmt BinaryOperator(+)
 WalkUpFromStmt IntegerLiteral(4)
 WalkUpFromStmt CompoundStmt
 )txt"));
@@ -1067,7 +1067,6 @@ WalkUpFromExpr IntegerLiteral(4)
   WalkUpFromStmt IntegerLiteral(4)
 )txt"));
 
-  // FIXME: The following log should include a call to WalkUpFromBinAdd.
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
   R"txt(
@@ -1078,6 +1077,9 @@ TraverseBinAdd BinaryOperator(+)
 WalkUpFromStmt Inte

[clang] 9445444 - RecursiveASTVisitor: don't call WalkUp unnecessarily in post-order traversal

2020-07-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-03T13:03:19+02:00
New Revision: 94454442c3c15a67ae70ef3a73616632968973fc

URL: 
https://github.com/llvm/llvm-project/commit/94454442c3c15a67ae70ef3a73616632968973fc
DIFF: 
https://github.com/llvm/llvm-project/commit/94454442c3c15a67ae70ef3a73616632968973fc.diff

LOG: RecursiveASTVisitor: don't call WalkUp unnecessarily in post-order 
traversal

Summary:
How does RecursiveASTVisitor call the WalkUp callback for expressions?

* In pre-order traversal mode, RecursiveASTVisitor calls the WalkUp
  callback from the default implementation of Traverse callbacks.

* In post-order traversal mode when we don't have a DataRecursionQueue,
  RecursiveASTVisitor also calls the WalkUp callback from the default
  implementation of Traverse callbacks.

* However, in post-order traversal mode when we have a DataRecursionQueue,
  RecursiveASTVisitor calls the WalkUp callback from PostVisitStmt.

As a result, when the user overrides the Traverse callback, in pre-order
traversal mode they never get the corresponding WalkUp callback. However
in the post-order traversal mode the WalkUp callback is invoked or not
depending on whether the data recursion optimization could be applied.

I had to adjust the implementation of TraverseCXXForRangeStmt in the
syntax tree builder to call the WalkUp method directly, as it was
relying on this behavior. There is an existing test for this
functionality and it prompted me to make this extra fix.

In addition, I had to fix the default implementation implementation of
RecursiveASTVisitor::TraverseSynOrSemInitListExpr to call WalkUpFrom in
the same manner as the implementation generated by the DEF_TRAVERSE_STMT
macro. Without this fix, the InitListExprIsPostOrderNoQueueVisitedTwice
test was failing because WalkUpFromInitListExpr was never called.

Reviewers: eduucaldas, ymandel

Reviewed By: eduucaldas, ymandel

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index b16c1ae1e483..821a6c549b71 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -331,6 +331,32 @@ template  class RecursiveASTVisitor {
   struct has_same_member_pointer_type
   : std::true_type {};
 
+  template  struct is_same_method_impl {
+template 
+static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
+ SecondMethodPtrTy SecondMethodPtr) {
+  return false;
+}
+  };
+
+  template <> struct is_same_method_impl {
+template 
+static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
+ SecondMethodPtrTy SecondMethodPtr) {
+  return FirstMethodPtr == SecondMethodPtr;
+}
+  };
+
+  /// Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr
+  /// are pointers to the same non-static member function.
+  template 
+  bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
+SecondMethodPtrTy SecondMethodPtr) {
+return is_same_method_impl<
+has_same_member_pointer_type::
+value>::isSameMethod(FirstMethodPtr, SecondMethodPtr);
+  }
+
   // Traverse the given statement. If the most-derived traverse function takes 
a
   // data recursion queue, pass it on; otherwise, discard it. Note that the
   // first branch of this conditional must compile whether or not the derived
@@ -609,17 +635,38 @@ bool RecursiveASTVisitor::PostVisitStmt(Stmt *S) 
{
 #define ABSTRACT_STMT(STMT)
 #define STMT(CLASS, PARENT)
\
   case Stmt::CLASS##Class: 
\
-TRY_TO(WalkUpFrom##CLASS(static_cast(S))); break;
+/* In pre-order traversal mode, each Traverse##STMT method is responsible  
\
+ * for calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT 
\
+ * and does not call the default implementation, the WalkUpFrom callback   
\
+ * is not called. Post-order traversal mode should provide the same
\
+ * behavior regarding method overrides.
\
+ * 
\
+ * In post-order traversal mode the Traverse##STMT method, when it 
\
+ * receives a DataRecursionQueue, can't call WalkUpFrom after traversing   
\
+ * children because it only enqueues the children and does not traverse
\
+ * them. TraverseStmt traverses the enqueued children, and we call 
\
+ * WalkUpFrom here.   

[clang] 19eaff6 - Revert RecursiveASTVisitor fixes.

2020-07-03 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-03T13:48:24+02:00
New Revision: 19eaff650c9c091e844f0a342540f1d10573772c

URL: 
https://github.com/llvm/llvm-project/commit/19eaff650c9c091e844f0a342540f1d10573772c
DIFF: 
https://github.com/llvm/llvm-project/commit/19eaff650c9c091e844f0a342540f1d10573772c.diff

LOG: Revert RecursiveASTVisitor fixes.

This reverts commit 8bf4c40af813e73de77739b33b8808f6bd13497b.
This reverts commit 7b0be962d681c408c8ecf7180c6ad8f9fbcdaf2d.
This reverts commit 94454442c3c15a67ae70ef3a73616632968973fc.

Some compilers on some buildbots didn't accept the specialization of
is_same_method_impl in a non-namespace scope.

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index ba36d5b23fc6..b16c1ae1e483 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -331,32 +331,6 @@ template  class RecursiveASTVisitor {
   struct has_same_member_pointer_type
   : std::true_type {};
 
-  template  struct is_same_method_impl {
-template 
-static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
- SecondMethodPtrTy SecondMethodPtr) {
-  return false;
-}
-  };
-
-  template <> struct is_same_method_impl {
-template 
-static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
- SecondMethodPtrTy SecondMethodPtr) {
-  return FirstMethodPtr == SecondMethodPtr;
-}
-  };
-
-  /// Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr
-  /// are pointers to the same non-static member function.
-  template 
-  bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
-SecondMethodPtrTy SecondMethodPtr) {
-return is_same_method_impl<
-has_same_member_pointer_type::
-value>::isSameMethod(FirstMethodPtr, SecondMethodPtr);
-  }
-
   // Traverse the given statement. If the most-derived traverse function takes 
a
   // data recursion queue, pass it on; otherwise, discard it. Note that the
   // first branch of this conditional must compile whether or not the derived
@@ -412,8 +386,6 @@ template  class RecursiveASTVisitor {
 if (!getDerived().shouldTraversePostOrder())   
\
   TRY_TO(WalkUpFromUnary##NAME(S));
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());  
\
-if (!Queue && getDerived().shouldTraversePostOrder())  
\
-  TRY_TO(WalkUpFromUnary##NAME(S));
\
 return true;   
\
   }
\
   bool WalkUpFromUnary##NAME(UnaryOperator *S) {   
\
@@ -435,8 +407,6 @@ template  class RecursiveASTVisitor {
   TRY_TO(WalkUpFromBin##NAME(S));  
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS());  
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS());  
\
-if (!Queue && getDerived().shouldTraversePostOrder())  
\
-  TRY_TO(WalkUpFromBin##NAME(S));  
\
 return true;   
\
   }
\
   bool WalkUpFromBin##NAME(BINOP_TYPE *S) {
\
@@ -593,6 +563,7 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt *S,
 
   BINOP_LIST()
 #undef OPERATOR
+#undef BINOP_LIST
 
 #define OPERATOR(NAME) 
\
   case BO_##NAME##Assign:  
\
@@ -600,6 +571,7 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt *S,
 
   CAO_LIST()
 #undef OPERATOR
+#undef CAO_LIST
 }
   } else if (UnaryOperator *UnOp = dyn_cast(S)) {
 switch (UnOp->getOpcode()) {
@@ -609,6 +581,7 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt *S,
 
   UNARYOP_LIST()
 #undef OPERATOR
+#undef UNARYOP_LIST
 }
   }
 
@@ -630,84 +603,23 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt 
*S,
 
 template 
 bool RecursiveASTVisitor::PostVisitStmt(Stmt *S) {
-  // In pre-order traversal mode, each Traverse##STMT method is responsible for
-  // calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT and
-  // does not call the default implementation, the WalkUpFrom callback is not
-  // called. Post-order traversal mode should provide the same behavior
-  // 

[clang] c19c6b1 - Make RecursiveASTVisitor call WalkUpFrom for unary and binary operators in post-order traversal mode

2020-07-06 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-06T13:38:01+02:00
New Revision: c19c6b1722e5f71200c09cdb096245b98f03dce0

URL: 
https://github.com/llvm/llvm-project/commit/c19c6b1722e5f71200c09cdb096245b98f03dce0
DIFF: 
https://github.com/llvm/llvm-project/commit/c19c6b1722e5f71200c09cdb096245b98f03dce0.diff

LOG: Make RecursiveASTVisitor call WalkUpFrom for unary and binary operators in 
post-order traversal mode

Reviewers: ymandel, eduucaldas, rsmith

Reviewed By: eduucaldas, rsmith

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 464a80d15cef..9d93f1e99666 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -593,7 +593,6 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt *S,
 
   BINOP_LIST()
 #undef OPERATOR
-#undef BINOP_LIST
 
 #define OPERATOR(NAME) 
\
   case BO_##NAME##Assign:  
\
@@ -601,7 +600,6 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt *S,
 
   CAO_LIST()
 #undef OPERATOR
-#undef CAO_LIST
 }
   } else if (UnaryOperator *UnOp = dyn_cast(S)) {
 switch (UnOp->getOpcode()) {
@@ -611,7 +609,6 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt *S,
 
   UNARYOP_LIST()
 #undef OPERATOR
-#undef UNARYOP_LIST
 }
   }
 
@@ -633,27 +630,70 @@ bool RecursiveASTVisitor::dataTraverseNode(Stmt 
*S,
 
 template 
 bool RecursiveASTVisitor::PostVisitStmt(Stmt *S) {
+  // In pre-order traversal mode, each Traverse##STMT method is responsible for
+  // calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT and
+  // does not call the default implementation, the WalkUpFrom callback is not
+  // called. Post-order traversal mode should provide the same behavior
+  // regarding method overrides.
+  //
+  // In post-order traversal mode the Traverse##STMT method, when it receives a
+  // DataRecursionQueue, can't call WalkUpFrom after traversing children 
because
+  // it only enqueues the children and does not traverse them. TraverseStmt
+  // traverses the enqueued children, and we call WalkUpFrom here.
+  //
+  // However, to make pre-order and post-order modes identical with regards to
+  // whether they call WalkUpFrom at all, we call WalkUpFrom if and only if the
+  // user did not override the Traverse##STMT method. We implement the override
+  // check with isSameMethod calls below.
+
+  if (BinaryOperator *BinOp = dyn_cast(S)) {
+switch (BinOp->getOpcode()) {
+#define OPERATOR(NAME) 
\
+  case BO_##NAME:  
\
+if (::clang::detail::isSameMethod(&RecursiveASTVisitor::TraverseBin##NAME, 
\
+  &Derived::TraverseBin##NAME)) {  
\
+  TRY_TO(WalkUpFromBin##NAME(static_cast(S)));   
\
+}  
\
+return true;
+
+  BINOP_LIST()
+#undef OPERATOR
+
+#define OPERATOR(NAME) 
\
+  case BO_##NAME##Assign:  
\
+if (::clang::detail::isSameMethod( 
\
+&RecursiveASTVisitor::TraverseBin##NAME##Assign,   
\
+&Derived::TraverseBin##NAME##Assign)) {
\
+  TRY_TO(WalkUpFromBin##NAME##Assign(  
\
+  static_cast(S)));  
\
+}  
\
+return true;
+
+  CAO_LIST()
+#undef OPERATOR
+}
+  } else if (UnaryOperator *UnOp = dyn_cast(S)) {
+switch (UnOp->getOpcode()) {
+#define OPERATOR(NAME) 
\
+  case UO_##NAME:  
\
+if (::clang::detail::isSameMethod( 
\
+&RecursiveASTVisitor::TraverseUnary##NAME, 
\
+&Derived::TraverseUnary##NAME)) {  
\
+  TRY_TO(WalkUpFromUnary##NAME(static_cast(S)));  
\
+}  
\
+return true;
+
+  UNARYOP_LIST()
+#undef OPERATOR
+}
+  }
+
   switch (S->getStmtClass()) {
   case Stmt::NoStmtClass:
 break;
 #define ABSTRACT_STMT(STMT)
 #define STMT(C

[clang] 5689b38 - Removed a RecursiveASTVisitor feature to visit operator kinds with different methods

2020-07-06 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-06T13:38:01+02:00
New Revision: 5689b38c6a4220cc5f6ba68a56486229b10071bf

URL: 
https://github.com/llvm/llvm-project/commit/5689b38c6a4220cc5f6ba68a56486229b10071bf
DIFF: 
https://github.com/llvm/llvm-project/commit/5689b38c6a4220cc5f6ba68a56486229b10071bf.diff

LOG: Removed a RecursiveASTVisitor feature to visit operator kinds with 
different methods

Summary:
This feature was only used in two places, but contributed a non-trivial
amount to the complexity of RecursiveASTVisitor, and was buggy (see my
recent patches where I was fixing the bugs that I noticed). I don't
think the convenience benefit of this feature is worth the complexity.

Besides complexity, another issue with the current state of
RecursiveASTVisitor is the non-uniformity in how it handles different
AST nodes. All AST nodes follow a regular pattern, but operators are
special -- and this special behavior not documented. Correct usage of
RecursiveASTVisitor relies on shadowing member functions with specific
names and signatures. Near misses don't cause any compile-time errors,
incorrectly named or typed methods are just silently ignored. Therefore,
predictability of RecursiveASTVisitor API is quite important.

This change reduces the size of the `clang` binary by 38 KB (0.2%) in
release mode, and by 7 MB (0.3%) in debug mode. The `clang-tidy` binary
is reduced by 205 KB (0.3%) in release mode, and by 5 MB (0.4%) in debug
mode. I don't think these code size improvements are significant enough
to justify this change on its own (for me, the primary motivation is
reducing code complexity), but they I think are a nice side-effect.

Reviewers: rsmith, sammccall, ymandel, aaron.ballman

Reviewed By: rsmith, sammccall, ymandel, aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/RecursiveASTVisitor.h
clang/lib/ARCMigrate/TransProperties.cpp
clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 67f281b3ed1f..56d4cceb6002 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -500,7 +500,7 @@ void ForLoopIndexUseVisitor::addUsage(const Usage &U) {
 /// int k = *i + 2;
 ///   }
 /// \endcode
-bool ForLoopIndexUseVisitor::TraverseUnaryDeref(UnaryOperator *Uop) {
+bool ForLoopIndexUseVisitor::TraverseUnaryOperator(UnaryOperator *Uop) {
   // If we dereference an iterator that's actually a pointer, count the
   // occurrence.
   if (isDereferenceOfUop(Uop, IndexVar)) {

diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
index b2cba8c0172a..4f75c9c7522f 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
@@ -346,7 +346,7 @@ class ForLoopIndexUseVisitor
   bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
  Expr *Init);
   bool TraverseMemberExpr(MemberExpr *Member);
-  bool TraverseUnaryDeref(UnaryOperator *Uop);
+  bool TraverseUnaryOperator(UnaryOperator *Uop);
   bool VisitDeclRefExpr(DeclRefExpr *E);
   bool VisitDeclStmt(DeclStmt *S);
   bool TraverseStmt(Stmt *S);

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0328b0ef54c..8a9a58aa01f8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -243,6 +243,34 @@ These are major API changes that have happened since the 
10.0.0 release of
 Clang. If upgrading an external codebase that uses Clang as a library,
 this section should help get you past the largest hurdles of upgrading.
 
+- ``RecursiveASTVisitor`` no longer calls separate methods to visit specific
+  operator kinds. Previously, ``RecursiveASTVisitor`` treated unary, binary,
+  and compound assignment operators as if they were subclasses of the
+  corresponding AST node. For example, the binary operator plus was treated as
+  if it was a ``BinAdd`` subclass of the ``BinaryOperator`` class: during AST
+  traversal of a ``BinaryOperator`` AST node that had a ``BO_Add`` opcode,
+  ``RecursiveASTVisitor`` was calling the ``TraverseBinAdd`` method instead of
+  ``TraverseBinaryOperator``. This feature was contributing a non-trivial
+  amount of complexity to the implementation of ``RecursiveASTVisitor``, it was
+  used only in a minor way in Clang, was not tested, and as a result it was
+  buggy. Furthermore, this feature was creating a non-uni

[clang] 8e750b1 - Make RecursiveASTVisitor call WalkUpFrom for operators when the data recursion queue is absent

2020-07-06 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-06T13:38:01+02:00
New Revision: 8e750b1f0a2b6b5174dc49adf20e6f863c28e3cd

URL: 
https://github.com/llvm/llvm-project/commit/8e750b1f0a2b6b5174dc49adf20e6f863c28e3cd
DIFF: 
https://github.com/llvm/llvm-project/commit/8e750b1f0a2b6b5174dc49adf20e6f863c28e3cd.diff

LOG: Make RecursiveASTVisitor call WalkUpFrom for operators when the data 
recursion queue is absent

Reviewers: eduucaldas, ymandel, rsmith

Reviewed By: eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 9d93f1e99666..0d7c2b81512c 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -416,6 +416,8 @@ template  class RecursiveASTVisitor {
 if (!getDerived().shouldTraversePostOrder())   
\
   TRY_TO(WalkUpFromUnary##NAME(S));
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());  
\
+if (!Queue && getDerived().shouldTraversePostOrder())  
\
+  TRY_TO(WalkUpFromUnary##NAME(S));
\
 return true;   
\
   }
\
   bool WalkUpFromUnary##NAME(UnaryOperator *S) {   
\
@@ -437,6 +439,8 @@ template  class RecursiveASTVisitor {
   TRY_TO(WalkUpFromBin##NAME(S));  
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS());  
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS());  
\
+if (!Queue && getDerived().shouldTraversePostOrder())  
\
+  TRY_TO(WalkUpFromBin##NAME(S));  
\
 return true;   
\
   }
\
   bool WalkUpFromBin##NAME(BINOP_TYPE *S) {
\

diff  --git a/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
index 0a4e9aa1e9e8..70c7eb37ad4c 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
@@ -606,14 +606,13 @@ TraverseUnaryMinus UnaryOperator(-)
 WalkUpFromStmt IntegerLiteral(3)
 )txt"));
 
-  // FIXME: The following log should include a call to WalkUpFromStmt for
-  // UnaryOperator(-).
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
   R"txt(
 WalkUpFromStmt IntegerLiteral(1)
 TraverseUnaryMinus UnaryOperator(-)
   WalkUpFromStmt IntegerLiteral(2)
+  WalkUpFromStmt UnaryOperator(-)
 WalkUpFromStmt IntegerLiteral(3)
 WalkUpFromStmt CompoundStmt
 )txt"));
@@ -675,7 +674,6 @@ WalkUpFromExpr IntegerLiteral(3)
   WalkUpFromStmt IntegerLiteral(3)
 )txt"));
 
-  // FIXME: The following log should include a call to WalkUpFromUnaryMinus.
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
   R"txt(
@@ -684,6 +682,9 @@ WalkUpFromExpr IntegerLiteral(1)
 TraverseUnaryMinus UnaryOperator(-)
   WalkUpFromExpr IntegerLiteral(2)
 WalkUpFromStmt IntegerLiteral(2)
+  WalkUpFromUnaryMinus UnaryOperator(-)
+WalkUpFromExpr UnaryOperator(-)
+  WalkUpFromStmt UnaryOperator(-)
 WalkUpFromExpr IntegerLiteral(3)
   WalkUpFromStmt IntegerLiteral(3)
 WalkUpFromStmt CompoundStmt
@@ -996,8 +997,6 @@ TraverseBinAdd BinaryOperator(+)
 WalkUpFromStmt IntegerLiteral(4)
 )txt"));
 
-  // FIXME: The following log should include a call to WalkUpFromStmt for
-  // BinaryOperator(+).
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
   R"txt(
@@ -1005,6 +1004,7 @@ WalkUpFromStmt IntegerLiteral(1)
 TraverseBinAdd BinaryOperator(+)
   WalkUpFromStmt IntegerLiteral(2)
   WalkUpFromStmt IntegerLiteral(3)
+  WalkUpFromStmt BinaryOperator(+)
 WalkUpFromStmt IntegerLiteral(4)
 WalkUpFromStmt CompoundStmt
 )txt"));
@@ -1067,7 +1067,6 @@ WalkUpFromExpr IntegerLiteral(4)
   WalkUpFromStmt IntegerLiteral(4)
 )txt"));
 
-  // FIXME: The following log should include a call to WalkUpFromBinAdd.
   EXPECT_TRUE(visitorCallbackLogEqual(
   RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
   R"txt(
@@ -1078,6 +1077,9 @@ TraverseBinAdd BinaryOperator(+)
 WalkUpFromStmt Inte

[clang] 7349479 - RecursiveASTVisitor: don't call WalkUp unnecessarily in post-order traversal

2020-07-06 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-06T13:38:01+02:00
New Revision: 7349479f2244c32c0184ca545af04adb171c8077

URL: 
https://github.com/llvm/llvm-project/commit/7349479f2244c32c0184ca545af04adb171c8077
DIFF: 
https://github.com/llvm/llvm-project/commit/7349479f2244c32c0184ca545af04adb171c8077.diff

LOG: RecursiveASTVisitor: don't call WalkUp unnecessarily in post-order 
traversal

Summary:
How does RecursiveASTVisitor call the WalkUp callback for expressions?

* In pre-order traversal mode, RecursiveASTVisitor calls the WalkUp
  callback from the default implementation of Traverse callbacks.

* In post-order traversal mode when we don't have a DataRecursionQueue,
  RecursiveASTVisitor also calls the WalkUp callback from the default
  implementation of Traverse callbacks.

* However, in post-order traversal mode when we have a DataRecursionQueue,
  RecursiveASTVisitor calls the WalkUp callback from PostVisitStmt.

As a result, when the user overrides the Traverse callback, in pre-order
traversal mode they never get the corresponding WalkUp callback. However
in the post-order traversal mode the WalkUp callback is invoked or not
depending on whether the data recursion optimization could be applied.

I had to adjust the implementation of TraverseCXXForRangeStmt in the
syntax tree builder to call the WalkUp method directly, as it was
relying on this behavior. There is an existing test for this
functionality and it prompted me to make this extra fix.

In addition, I had to fix the default implementation implementation of
RecursiveASTVisitor::TraverseSynOrSemInitListExpr to call WalkUpFrom in
the same manner as the implementation generated by the DEF_TRAVERSE_STMT
macro. Without this fix, the InitListExprIsPostOrderNoQueueVisitedTwice
test was failing because WalkUpFromInitListExpr was never called.

Reviewers: eduucaldas, ymandel

Reviewed By: eduucaldas, ymandel

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index b16c1ae1e483..464a80d15cef 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -83,6 +83,42 @@ namespace clang {
   return false;
\
   } while (false)
 
+namespace detail {
+
+template 
+struct has_same_member_pointer_type : std::false_type {};
+template 
+struct has_same_member_pointer_type
+: std::true_type {};
+
+template  struct is_same_method_impl {
+  template 
+  static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
+   SecondMethodPtrTy SecondMethodPtr) {
+return false;
+  }
+};
+
+template <> struct is_same_method_impl {
+  template 
+  static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
+   SecondMethodPtrTy SecondMethodPtr) {
+return FirstMethodPtr == SecondMethodPtr;
+  }
+};
+
+/// Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr
+/// are pointers to the same non-static member function.
+template 
+bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
+  SecondMethodPtrTy SecondMethodPtr) {
+  return is_same_method_impl::value>::isSameMethod(FirstMethodPtr, 
SecondMethodPtr);
+}
+
+} // end namespace detail
+
 /// A class that does preorder or postorder
 /// depth-first traversal on the entire Clang AST and visits each node.
 ///
@@ -325,23 +361,17 @@ template  class RecursiveASTVisitor {
   Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); }
 
 private:
-  template
-  struct has_same_member_pointer_type : std::false_type {};
-  template
-  struct has_same_member_pointer_type
-  : std::true_type {};
-
   // Traverse the given statement. If the most-derived traverse function takes 
a
   // data recursion queue, pass it on; otherwise, discard it. Note that the
   // first branch of this conditional must compile whether or not the derived
   // class can take a queue, so if we're taking the second arm, make the first
   // arm call our function rather than the derived class version.
 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE)
\
-  (has_same_member_pointer_type::value 
\
+  (::clang::detail::has_same_member_pointer_type<  
\
+   decltype(&RecursiveASTVisitor::Traverse##NAME), 
\
+   decltype(&Derived::Traverse##NAME)>::value  
\
? static_cast::value,   
\
  Derived &, RecursiveASTVisitor &>>(*this) 
\
@@ -609,17 +

[clang] 3cca818 - Refactored NumericLiteralParser to not require a Preprocessor

2020-07-09 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-09T17:33:58+02:00
New Revision: 3cca818efabbccdde36b06609cf75ee7caa8e012

URL: 
https://github.com/llvm/llvm-project/commit/3cca818efabbccdde36b06609cf75ee7caa8e012
DIFF: 
https://github.com/llvm/llvm-project/commit/3cca818efabbccdde36b06609cf75ee7caa8e012.diff

LOG: Refactored NumericLiteralParser to not require a Preprocessor

Summary:
We would like to use NumericLiteralParser in the implementation of the
syntax tree builder, and plumbing a preprocessor there seems
inconvenient and superfluous.

Reviewers: eduucaldas

Reviewed By: eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Lex/LiteralSupport.h
clang/lib/Lex/LiteralSupport.cpp
clang/lib/Lex/PPExpressions.cpp
clang/lib/Lex/Preprocessor.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 6829771b2830..0c4f0fe277b7 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -40,7 +40,9 @@ void expandUCNs(SmallVectorImpl &Buf, StringRef Input);
 /// of a ppnumber, classifying it as either integer, floating, or erroneous,
 /// determines the radix of the value and can convert it to a useful value.
 class NumericLiteralParser {
-  Preprocessor &PP; // needed for diagnostics
+  const SourceManager &SM;
+  const LangOptions &LangOpts;
+  DiagnosticsEngine &Diags;
 
   const char *const ThisTokBegin;
   const char *const ThisTokEnd;
@@ -54,9 +56,9 @@ class NumericLiteralParser {
   SmallString<32> UDSuffixBuf;
 
 public:
-  NumericLiteralParser(StringRef TokSpelling,
-   SourceLocation TokLoc,
-   Preprocessor &PP);
+  NumericLiteralParser(StringRef TokSpelling, SourceLocation TokLoc,
+   const SourceManager &SM, const LangOptions &LangOpts,
+   const TargetInfo &Target, DiagnosticsEngine &Diags);
   bool hadError : 1;
   bool isUnsigned : 1;
   bool isLong : 1;  // This is *not* set for long long.

diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index f44614b4bec4..eb16bc8c7da2 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -525,8 +525,12 @@ static void EncodeUCNEscape(const char *ThisTokBegin, 
const char *&ThisTokBuf,
 ///
 NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
SourceLocation TokLoc,
-   Preprocessor &PP)
-  : PP(PP), ThisTokBegin(TokSpelling.begin()), ThisTokEnd(TokSpelling.end()) {
+   const SourceManager &SM,
+   const LangOptions &LangOpts,
+   const TargetInfo &Target,
+   DiagnosticsEngine &Diags)
+: SM(SM), LangOpts(LangOpts), Diags(Diags),
+  ThisTokBegin(TokSpelling.begin()), ThisTokEnd(TokSpelling.end()) {
 
   // This routine assumes that the range begin/end matches the regex for 
integer
   // and FP constants (specifically, the 'pp-number' regex), and assumes that
@@ -572,7 +576,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   checkSeparator(TokLoc, s, CSK_AfterDigits);
 
   // Initial scan to lookahead for fixed point suffix.
-  if (PP.getLangOpts().FixedPoint) {
+  if (LangOpts.FixedPoint) {
 for (const char *c = s; c != ThisTokEnd; ++c) {
   if (*c == 'r' || *c == 'k' || *c == 'R' || *c == 'K') {
 saw_fixed_point_suffix = true;
@@ -592,14 +596,16 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
 switch (*s) {
 case 'R':
 case 'r':
-  if (!PP.getLangOpts().FixedPoint) break;
+  if (!LangOpts.FixedPoint)
+break;
   if (isFract || isAccum) break;
   if (!(saw_period || saw_exponent)) break;
   isFract = true;
   continue;
 case 'K':
 case 'k':
-  if (!PP.getLangOpts().FixedPoint) break;
+  if (!LangOpts.FixedPoint)
+break;
   if (isFract || isAccum) break;
   if (!(saw_period || saw_exponent)) break;
   isAccum = true;
@@ -607,7 +613,8 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
 case 'h':  // FP Suffix for "half".
 case 'H':
   // OpenCL Extension v1.2 s9.5 - h or H suffix for half type.
-  if (!(PP.getLangOpts().Half || PP.getLangOpts().FixedPoint)) break;
+  if (!(LangOpts.Half || LangOpts.FixedPoint))
+break;
   if (isIntegerLiteral()) break;  // Error for integer constant.
   if (isHalf || isFloat || isLong) break; // HH, FH, LH invalid.
   isHalf = true;
@@ -621,8 +628,8 @@ NumericLiteralParser::N

[clang] 8978032 - Fix test for the hasExternalFormalLinkage matcher

2020-07-14 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2020-07-14T15:44:53+02:00
New Revision: 8978032a17cd0f1c3925ecb1752fdf59de7f7967

URL: 
https://github.com/llvm/llvm-project/commit/8978032a17cd0f1c3925ecb1752fdf59de7f7967
DIFF: 
https://github.com/llvm/llvm-project/commit/8978032a17cd0f1c3925ecb1752fdf59de7f7967.diff

LOG: Fix test for the hasExternalFormalLinkage matcher

Summary:
Names of local variables have no linkage (see C++20 [basic.link] p8).

Names of variables in unnamed namespace have internal linkage (see C++20
[basic.link] p4).

Reviewers: aaron.ballman, rsmith, ymandel

Reviewed By: ymandel

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 687908043a8d..c249410201ba 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2534,19 +2534,16 @@ TEST(NullPointerConstants, Basic) {
 }
 
 TEST(HasExternalFormalLinkage, Basic) {
-  EXPECT_TRUE(matches("int a = 0;", namedDecl(hasExternalFormalLinkage(;
-  EXPECT_TRUE(
-  notMatches("static int a = 0;", namedDecl(hasExternalFormalLinkage(;
+  EXPECT_TRUE(matches("int a = 0;",
+  namedDecl(hasName("a"), hasExternalFormalLinkage(;
+  EXPECT_TRUE(notMatches("static int a = 0;",
+ namedDecl(hasName("a"), hasExternalFormalLinkage(;
   EXPECT_TRUE(notMatches("static void f(void) { int a = 0; }",
- namedDecl(hasExternalFormalLinkage(;
-  EXPECT_TRUE(matches("void f(void) { int a = 0; }",
-  namedDecl(hasExternalFormalLinkage(;
-
-  // Despite having internal semantic linkage, the anonymous namespace member
-  // has external linkage because the member has a unique name in all
-  // translation units.
-  EXPECT_TRUE(matches("namespace { int a = 0; }",
-  namedDecl(hasExternalFormalLinkage(;
+ namedDecl(hasName("a"), hasExternalFormalLinkage(;
+  EXPECT_TRUE(notMatches("void f(void) { int a = 0; }",
+ namedDecl(hasName("a"), hasExternalFormalLinkage(;
+  EXPECT_TRUE(notMatches("namespace { int a = 0; }",
+ namedDecl(hasName("a"), hasExternalFormalLinkage(;
 }
 
 TEST(HasDefaultArgument, Basic) {



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


[clang] 1b2f6b4 - Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

2020-06-18 Thread Dmitri Gribenko via cfe-commits

Author: Eduardo Caldas
Date: 2020-06-18T21:05:23+02:00
New Revision: 1b2f6b4a08ba74d965dcf7c9fee97d286c0250f8

URL: 
https://github.com/llvm/llvm-project/commit/1b2f6b4a08ba74d965dcf7c9fee97d286c0250f8
DIFF: 
https://github.com/llvm/llvm-project/commit/1b2f6b4a08ba74d965dcf7c9fee97d286c0250f8.diff

LOG: Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: hlopko, gribozavr2, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index 7e05aa968f02..139ac9aa8eca 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -45,6 +45,7 @@ enum class NodeKind : uint16_t {
   BinaryOperatorExpression,
   CxxNullPtrExpression,
   IntegerLiteralExpression,
+  IdExpression,
 
   // Statements.
   UnknownStatement,
@@ -84,7 +85,10 @@ enum class NodeKind : uint16_t {
   ArraySubscript,
   TrailingReturnType,
   ParametersAndQualifiers,
-  MemberPointer
+  MemberPointer,
+  NestedNameSpecifier,
+  NameSpecifier,
+  UnqualifiedId
 };
 /// For debugging purposes.
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NodeKind K);
@@ -150,7 +154,10 @@ enum class NodeRole : uint8_t {
   ArraySubscript_sizeExpression,
   TrailingReturnType_declarator,
   ParametersAndQualifiers_parameter,
-  ParametersAndQualifiers_trailingReturn
+  ParametersAndQualifiers_trailingReturn,
+  IdExpression_id,
+  IdExpression_qualifier,
+  NestedNameSpecifier_specifier
 };
 /// For debugging purposes.
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NodeRole R);
@@ -177,6 +184,56 @@ class Expression : public Tree {
   }
 };
 
+/// A sequence of these specifiers make a `nested-name-specifier`.
+/// e.g. the `std::` or `vector::` in `std::vector::size`.
+class NameSpecifier final : public Tree {
+public:
+  NameSpecifier() : Tree(NodeKind::NameSpecifier) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::NameSpecifier;
+  }
+};
+
+/// Models a `nested-name-specifier`. C++ [expr.prim.id.qual]
+/// e.g. the `std::vector::` in `std::vector::size`.
+class NestedNameSpecifier final : public Tree {
+public:
+  NestedNameSpecifier() : Tree(NodeKind::NestedNameSpecifier) {}
+  static bool classof(const Node *N) {
+return N->kind() <= NodeKind::NestedNameSpecifier;
+  }
+  std::vector specifiers();
+};
+
+/// Models an `unqualified-id`. C++ [expr.prim.id.unqual]
+/// e.g. the `size` in `std::vector::size`.
+class UnqualifiedId final : public Tree {
+public:
+  UnqualifiedId() : Tree(NodeKind::UnqualifiedId) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::UnqualifiedId;
+  }
+};
+
+/// Models an `id-expression`, e.g. `std::vector::size`.
+/// C++ [expr.prim.id]
+/// id-expression:
+///   unqualified-id
+///   qualified-id
+/// qualified-id:
+///   nested-name-specifier template_opt unqualified-id
+class IdExpression final : public Expression {
+public:
+  IdExpression() : Expression(NodeKind::IdExpression) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::IdExpression;
+  }
+  syntax::NestedNameSpecifier *qualifier();
+  // TODO after expose `id-expression` from `DependentScopeDeclRefExpr`:
+  // Add accessor for `template_opt`.
+  syntax::UnqualifiedId *unqualifiedId();
+};
+
 /// An expression of an unknown kind, i.e. one not currently handled by the
 /// syntax tree.
 class UnknownExpression final : public Expression {

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 9ce12ac21f8b..3ee66aabfb6d 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -608,6 +608,45 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  syntax::NestedNameSpecifier *
+  BuildNestedNameSpecifier(NestedNameSpecifierLoc QualifierLoc) {
+if (!QualifierLoc)
+  return nullptr;
+for (auto it = QualifierLoc; it; it = it.getPrefix()) {
+  auto *NS = new (allocator()) syntax::NameSpecifier;
+  Builder.foldNode(Builder.getRange(it.getLocalSourceRange()), NS, 
nullptr);
+  Builder.markChild(NS, syntax::NodeRole::NestedNameSpecifier_specifier);
+}
+auto *NNS = new (allocator()) syntax::NestedNameSpecifier;
+Builder.foldNode(Builder.getRange(QualifierLoc.getSourceRange()), NNS,
+ nullptr);
+return NNS;
+  }
+
+  bool WalkUpFromDeclRefExpr(DeclRefExpr *S) {
+if (auto *NNS = BuildNestedNameSpecifier(S->getQualifierLoc()))
+  Builder.markChild(NNS, synta

  1   2   3   >