r360995 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-17 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri May 17 00:06:46 2019
New Revision: 360995

URL: http://llvm.org/viewvc/llvm-project?rev=360995&view=rev
Log:
Refactor constant evaluation of typeid(T) to track a symbolic type_info
object rather than tracking the originating expression.

This is groundwork for supporting polymorphic typeid expressions. (Note
that this somewhat regresses our support for DR1968, but it turns out
that that never actually worked anyway, at least in non-trivial cases.)

This reinstates r360974, reverted in r360988, with a fix for a
static_assert failure on 32-bit builds: force Type base class to have
8-byte alignment like the rest of Clang's AST nodes.

Modified:
cfe/trunk/include/clang/AST/APValue.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/APValue.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CXX/drs/dr19xx.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.cpp
cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
cfe/trunk/test/SemaCXX/typeid.cpp
cfe/trunk/www/cxx_dr_status.html

Modified: cfe/trunk/include/clang/AST/APValue.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360995&r1=360994&r2=360995&view=diff
==
--- cfe/trunk/include/clang/AST/APValue.h (original)
+++ cfe/trunk/include/clang/AST/APValue.h Fri May 17 00:06:46 2019
@@ -24,14 +24,52 @@ namespace clang {
   class AddrLabelExpr;
   class ASTContext;
   class CharUnits;
+  class CXXRecordDecl;
+  class Decl;
   class DiagnosticBuilder;
   class Expr;
   class FieldDecl;
-  class Decl;
+  struct PrintingPolicy;
+  class Type;
   class ValueDecl;
-  class CXXRecordDecl;
-  class QualType;
 
+/// Symbolic representation of typeid(T) for some type T.
+class TypeInfoLValue {
+  const Type *T;
+
+public:
+  TypeInfoLValue() : T() {}
+  explicit TypeInfoLValue(const Type *T);
+
+  const Type *getType() const { return T; }
+  explicit operator bool() const { return T; }
+
+  void *getOpaqueValue() { return const_cast(T); }
+  static TypeInfoLValue getFromOpaqueValue(void *Value) {
+TypeInfoLValue V;
+V.T = reinterpret_cast(Value);
+return V;
+  }
+
+  void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const;
+};
+}
+
+namespace llvm {
+template<> struct PointerLikeTypeTraits {
+  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
+return V.getOpaqueValue();
+  }
+  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
+return clang::TypeInfoLValue::getFromOpaqueValue(P);
+  }
+  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
+  // to include Type.h.
+  static constexpr int NumLowBitsAvailable = 3;
+};
+}
+
+namespace clang {
 /// APValue - This class implements a discriminated union of [uninitialized]
 /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
 /// [Vector: N * APValue], [Array: N * APValue]
@@ -56,14 +94,14 @@ public:
   };
 
   class LValueBase {
-  public:
-typedef llvm::PointerUnion PtrTy;
-
-LValueBase() : CallIndex(0), Version(0) {}
+typedef llvm::PointerUnion
+PtrTy;
 
-template 
-LValueBase(T P, unsigned I = 0, unsigned V = 0)
-: Ptr(P), CallIndex(I), Version(V) {}
+  public:
+LValueBase() : Local{} {}
+LValueBase(const ValueDecl *P, unsigned I = 0, unsigned V = 0);
+LValueBase(const Expr *P, unsigned I = 0, unsigned V = 0);
+static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo);
 
 template 
 bool is() const { return Ptr.is(); }
@@ -78,28 +116,13 @@ public:
 
 bool isNull() const;
 
-explicit operator bool () const;
-
-PtrTy getPointer() const {
-  return Ptr;
-}
-
-unsigned getCallIndex() const {
-  return CallIndex;
-}
+explicit operator bool() const;
 
-void setCallIndex(unsigned Index) {
-  CallIndex = Index;
-}
+unsigned getCallIndex() const;
+unsigned getVersion() const;
+QualType getTypeInfoType() const;
 
-unsigned getVersion() const {
-  return Version;
-}
-
-friend bool operator==(const LValueBase &LHS, const LValueBase &RHS) {
-  return LHS.Ptr == RHS.Ptr && LHS.CallIndex == RHS.CallIndex &&
- LHS.Version == RHS.Version;
-}
+friend bool operator==(const LValueBase &LHS, const LValueBase &RHS);
 friend bool operator!=(const LValueBase &LHS, const LValueBase &RHS) {
   return !(LHS == RHS);
 }
@@ -107,7 +130,14 @@ public:
 
   private:
 PtrTy Ptr;
-unsigned CallIndex, Version;
+struct LocalState {
+  unsigned CallIndex, Version;
+};
+union {
+  LocalState Local;
+  /// The type std::type_info, if this is a TypeInfoLValue.
+  void *TypeInfoType;
+};
   };
 
   /// A FieldDecl or CXXRecordDecl, along with a flag ind

r360996 - [ClangFormat] Editor integrations inherit default style from clang-format binary

2019-05-17 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri May 17 00:22:55 2019
New Revision: 360996

URL: http://llvm.org/viewvc/llvm-project?rev=360996&view=rev
Log:
[ClangFormat] Editor integrations inherit default style from clang-format binary

Summary:
This allows downstream customizations to the default style to work without
needing to also modify the editor integrations.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

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

Modified:
cfe/trunk/tools/clang-format/clang-format-sublime.py
cfe/trunk/tools/clang-format/clang-format-test.el
cfe/trunk/tools/clang-format/clang-format.el
cfe/trunk/tools/clang-format/clang-format.py

Modified: cfe/trunk/tools/clang-format/clang-format-sublime.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format-sublime.py?rev=360996&r1=360995&r2=360996&view=diff
==
--- cfe/trunk/tools/clang-format/clang-format-sublime.py (original)
+++ cfe/trunk/tools/clang-format/clang-format-sublime.py Fri May 17 00:22:55 
2019
@@ -24,7 +24,7 @@ binary = 'clang-format'
 # 'clang-format --help' for a list of supported styles. The default looks for
 # a '.clang-format' or '_clang-format' file to indicate the style that should 
be
 # used.
-style = 'file'
+style = None
 
 class ClangFormatCommand(sublime_plugin.TextCommand):
   def run(self, edit):
@@ -32,7 +32,9 @@ class ClangFormatCommand(sublime_plugin.
 if encoding == 'Undefined':
   encoding = 'utf-8'
 regions = []
-command = [binary, '-style', style]
+command = [binary]
+if style:
+  command.extend(['-style', style])
 for region in self.view.sel():
   regions.append(region)
   region_offset = min(region.a, region.b)

Modified: cfe/trunk/tools/clang-format/clang-format-test.el
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format-test.el?rev=360996&r1=360995&r2=360996&view=diff
==
--- cfe/trunk/tools/clang-format/clang-format-test.el (original)
+++ cfe/trunk/tools/clang-format/clang-format-test.el Fri May 17 00:22:55 2019
@@ -58,7 +58,6 @@
(should-not display)
(should (equal args
   '("-output-replacements-xml" "-assume-filename" "foo.cpp"
-"-style" "file"
 ;; Beginning of buffer, no byte-order mark.
 "-offset" "0"
 ;; We have two lines with 2×2 bytes for the umlauts,

Modified: cfe/trunk/tools/clang-format/clang-format.el
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.el?rev=360996&r1=360995&r2=360996&view=diff
==
--- cfe/trunk/tools/clang-format/clang-format.el (original)
+++ cfe/trunk/tools/clang-format/clang-format.el Fri May 17 00:22:55 2019
@@ -45,14 +45,14 @@ A string containing the name or the full
   :type '(file :must-match t)
   :risky t)
 
-(defcustom clang-format-style "file"
+(defcustom clang-format-style nil
   "Style argument to pass to clang-format.
 
 By default clang-format will load the style configuration from
 a file named .clang-format located in one of the parent directories
 of the buffer."
   :group 'clang-format
-  :type 'string
+  :type '(choice (string) (const nil))
   :safe #'stringp)
 (make-variable-buffer-local 'clang-format-style)
 
@@ -160,7 +160,7 @@ uses the function `buffer-file-name'."
;; https://bugs.llvm.org/show_bug.cgi?id=34667
,@(and assume-file-name
   (list "-assume-filename" 
assume-file-name))
-   "-style" ,style
+   ,@(and style (list "-style" style))
"-offset" ,(number-to-string file-start)
"-length" ,(number-to-string (- file-end 
file-start))
"-cursor" ,(number-to-string cursor

Modified: cfe/trunk/tools/clang-format/clang-format.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.py?rev=360996&r1=360995&r2=360996&view=diff
==
--- cfe/trunk/tools/clang-format/clang-format.py (original)
+++ cfe/trunk/tools/clang-format/clang-format.py Fri May 17 00:22:55 2019
@@ -44,7 +44,7 @@ if vim.eval('exists("g:clang_format_path
 # 'clang-format --help' for a list of supported styles. The default looks for
 # a '.clang-format' or '_clang-format' file to indicate the style that should 
be
 # used.
-style = 'file'
+style = None
 fallback_style = None
 if vim.eval('exists("g:clang_format_fallback_style")') == "1":
   fallback_style = vim.eval('g:clang_format_fallback_style')
@@ -91,9

[PATCH] D49719: [ClangFormat] Editor integrations inherit default style from clang-format binary

2019-05-17 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC360996: [ClangFormat] Editor integrations inherit default 
style from clang-format binary (authored by sammccall, committed by ).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D49719?vs=156974&id=199986#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D49719

Files:
  tools/clang-format/clang-format-sublime.py
  tools/clang-format/clang-format-test.el
  tools/clang-format/clang-format.el
  tools/clang-format/clang-format.py


Index: tools/clang-format/clang-format.el
===
--- tools/clang-format/clang-format.el
+++ tools/clang-format/clang-format.el
@@ -45,14 +45,14 @@
   :type '(file :must-match t)
   :risky t)
 
-(defcustom clang-format-style "file"
+(defcustom clang-format-style nil
   "Style argument to pass to clang-format.
 
 By default clang-format will load the style configuration from
 a file named .clang-format located in one of the parent directories
 of the buffer."
   :group 'clang-format
-  :type 'string
+  :type '(choice (string) (const nil))
   :safe #'stringp)
 (make-variable-buffer-local 'clang-format-style)
 
@@ -160,7 +160,7 @@
;; https://bugs.llvm.org/show_bug.cgi?id=34667
,@(and assume-file-name
   (list "-assume-filename" 
assume-file-name))
-   "-style" ,style
+   ,@(and style (list "-style" style))
"-offset" ,(number-to-string file-start)
"-length" ,(number-to-string (- file-end 
file-start))
"-cursor" ,(number-to-string cursor
Index: tools/clang-format/clang-format-test.el
===
--- tools/clang-format/clang-format-test.el
+++ tools/clang-format/clang-format-test.el
@@ -58,7 +58,6 @@
(should-not display)
(should (equal args
   '("-output-replacements-xml" "-assume-filename" "foo.cpp"
-"-style" "file"
 ;; Beginning of buffer, no byte-order mark.
 "-offset" "0"
 ;; We have two lines with 2×2 bytes for the umlauts,
Index: tools/clang-format/clang-format.py
===
--- tools/clang-format/clang-format.py
+++ tools/clang-format/clang-format.py
@@ -44,7 +44,7 @@
 # 'clang-format --help' for a list of supported styles. The default looks for
 # a '.clang-format' or '_clang-format' file to indicate the style that should 
be
 # used.
-style = 'file'
+style = None
 fallback_style = None
 if vim.eval('exists("g:clang_format_fallback_style")') == "1":
   fallback_style = vim.eval('g:clang_format_fallback_style')
@@ -91,9 +91,11 @@
 startupinfo.wShowWindow = subprocess.SW_HIDE
 
   # Call formatter.
-  command = [binary, '-style', style, '-cursor', str(cursor)]
+  command = [binary, '-cursor', str(cursor)]
   if lines != ['-lines', 'all']:
 command += lines
+  if style:
+command.extend(['-style', style])
   if fallback_style:
 command.extend(['-fallback-style', fallback_style])
   if vim.current.buffer.name:
Index: tools/clang-format/clang-format-sublime.py
===
--- tools/clang-format/clang-format-sublime.py
+++ tools/clang-format/clang-format-sublime.py
@@ -24,7 +24,7 @@
 # 'clang-format --help' for a list of supported styles. The default looks for
 # a '.clang-format' or '_clang-format' file to indicate the style that should 
be
 # used.
-style = 'file'
+style = None
 
 class ClangFormatCommand(sublime_plugin.TextCommand):
   def run(self, edit):
@@ -32,7 +32,9 @@
 if encoding == 'Undefined':
   encoding = 'utf-8'
 regions = []
-command = [binary, '-style', style]
+command = [binary]
+if style:
+  command.extend(['-style', style])
 for region in self.view.sel():
   regions.append(region)
   region_offset = min(region.a, region.b)


Index: tools/clang-format/clang-format.el
===
--- tools/clang-format/clang-format.el
+++ tools/clang-format/clang-format.el
@@ -45,14 +45,14 @@
   :type '(file :must-match t)
   :risky t)
 
-(defcustom clang-format-style "file"
+(defcustom clang-format-style nil
   "Style argument to pass to clang-format.
 
 By default clang-format will load the style configuration from
 a file named .clang-format located in one of the parent directories
 of the buffer."
   :group 'clang-format
-  :type 'string
+  :type '(choice (string) (const nil))
   :safe #'stringp)
 (make-variable-buffer-local 'clang-format-style)
 
@@ -160,7 +160,7 @@

r360997 - Fix alignment check to check the alignment of the intended type.

2019-05-17 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri May 17 00:28:41 2019
New Revision: 360997

URL: http://llvm.org/viewvc/llvm-project?rev=360997&view=rev
Log:
Fix alignment check to check the alignment of the intended type.

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

Modified: cfe/trunk/lib/AST/APValue.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/APValue.cpp?rev=360997&r1=360996&r2=360997&view=diff
==
--- cfe/trunk/lib/AST/APValue.cpp (original)
+++ cfe/trunk/lib/AST/APValue.cpp Fri May 17 00:28:41 2019
@@ -34,7 +34,7 @@ void TypeInfoLValue::print(llvm::raw_ost
 
 static_assert(
 1 << llvm::PointerLikeTypeTraits::NumLowBitsAvailable <=
-alignof(const Type *),
+alignof(Type),
 "Type is insufficiently aligned");
 
 APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)


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


r360998 - Fix crash if, during evaluation of __builtin_object_size, we try to load

2019-05-17 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri May 17 01:01:34 2019
New Revision: 360998

URL: http://llvm.org/viewvc/llvm-project?rev=360998&view=rev
Log:
Fix crash if, during evaluation of __builtin_object_size, we try to load
through an invalid base.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=360998&r1=360997&r2=360998&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 17 01:01:34 2019
@@ -3285,6 +3285,11 @@ static bool AreElementsOfSameArray(QualT
 static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E,
  AccessKinds AK, const LValue &LVal,
  QualType LValType) {
+  if (LVal.InvalidBase) {
+Info.FFDiag(E);
+return CompleteObject();
+  }
+
   if (!LVal.Base) {
 Info.FFDiag(E, diag::note_constexpr_access_null) << AK;
 return CompleteObject();

Modified: cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp?rev=360998&r1=360997&r2=360998&view=diff
==
--- cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp (original)
+++ cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp Fri May 17 01:01:34 
2019
@@ -97,3 +97,10 @@ void tooSmallBuf() {
   copy5CharsIntoStrict(small.buf); // expected-error{{no matching function for 
call}}
 }
 }
+
+namespace InvalidBase {
+  // Ensure this doesn't crash.
+  struct S { const char *name; };
+  S invalid_base();
+  constexpr long bos_name = __builtin_object_size(invalid_base().name, 1);
+}


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


r360999 - Suppress false-positive GCC -Wreturn-type warning.

2019-05-17 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri May 17 01:06:49 2019
New Revision: 360999

URL: http://llvm.org/viewvc/llvm-project?rev=360999&view=rev
Log:
Suppress false-positive GCC -Wreturn-type warning.

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

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=360999&r1=360998&r2=360999&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri May 17 01:06:49 2019
@@ -4207,6 +4207,7 @@ public:
 case Column:
   return false;
 }
+llvm_unreachable("unknown source location expression kind");
   }
   bool isIntType() const LLVM_READONLY { return !isStringType(); }
 


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


[PATCH] D61522: Added an assertion to constant evaluation enty points that prohibits dependent expressions

2019-05-17 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

@ABataev @rsmith Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61522



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


[PATCH] D61522: Added an assertion to constant evaluation enty points that prohibits dependent expressions

2019-05-17 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:6369
 // very difficult. Ideally, we should handle them more gracefully.
-if (!EIA->getCond()->EvaluateWithSubstitution(
+if (EIA->getCond()->isValueDependent() ||
+!EIA->getCond()->EvaluateWithSubstitution(

gribozavr wrote:
> rsmith wrote:
> > This is treating value-dependent `enable_if` conditions as having failed. 
> > Is that really appropriate? (When do we call this with value-depnedent 
> > `enable_if` attributes? I'd expect it to only be called after substitution)
> This test case in `llvm-project/clang/test/SemaCXX/enable_if.cpp` passes a 
> dependent condition:
> 
> ```
> void h(int);
> template  void outer() {
>   void local_function() __attribute__((enable_if(::h(T()), "")));
>   local_function();
> };
> ```
> 
> According to https://reviews.llvm.org/D20130, it seems like it was decided to 
> document implementation details as specification, and say that `enable_if` is 
> evaluated during overload resolution, whenever that happens to happen.
Hm. Yeah, I suppose we disable `enable_if` functions if the condition can't be 
evaluated, and this is a "can't be evaluated" case in some sense. I don't like 
it (the right thing would be to treat this as a dependent overload resolution), 
but as a short-term fix for this patch I suppose it's the right local choice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61522



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


[PATCH] D62056: Use ASTDumper to dump the AST from clang-query

2019-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This way, the output is not limited by the various API differences
between the dump() member functions.  For example, all dumps are now in
color, while that used to be the case only for Decls and Stmts, but not
Types.

Additionally, while DynTypedNode::dump (which was used up to now) was
limited to dumping only Decls, Stmts and Types, this makes clang-query
support everything ASTNodeTraverser supports.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D62056

Files:
  clang-query/Query.cpp


Index: clang-query/Query.cpp
===
--- clang-query/Query.cpp
+++ clang-query/Query.cpp
@@ -8,6 +8,7 @@
 
 #include "Query.h"
 #include "QuerySession.h"
+#include "clang/AST/ASTDumper.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/TextDiagnostic.h"
@@ -128,7 +129,11 @@
 }
 if (QS.DetailedASTOutput) {
   OS << "Binding for \"" << BI->first << "\":\n";
-  BI->second.dump(OS, AST->getSourceManager());
+  const ASTContext &Ctx = AST->getASTContext();
+  const SourceManager &SM = Ctx.getSourceManager();
+  ASTDumper Dumper(OS, &Ctx.getCommentCommandTraits(), &SM,
+SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
+  Dumper.Visit(BI->second);
   OS << "\n";
 }
   }


Index: clang-query/Query.cpp
===
--- clang-query/Query.cpp
+++ clang-query/Query.cpp
@@ -8,6 +8,7 @@
 
 #include "Query.h"
 #include "QuerySession.h"
+#include "clang/AST/ASTDumper.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/TextDiagnostic.h"
@@ -128,7 +129,11 @@
 }
 if (QS.DetailedASTOutput) {
   OS << "Binding for \"" << BI->first << "\":\n";
-  BI->second.dump(OS, AST->getSourceManager());
+  const ASTContext &Ctx = AST->getASTContext();
+  const SourceManager &SM = Ctx.getSourceManager();
+  ASTDumper Dumper(OS, &Ctx.getCommentCommandTraits(), &SM,
+SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
+  Dumper.Visit(BI->second);
   OS << "\n";
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 11.
ilya-biryukov added a comment.

- Fix compilation of a clang-tidy check, add a FIXME to stop reporting those 
tokens


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885

Files:
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/Token.h
  clang/include/clang/Lex/TokenLexer.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Lex/MacroArgs.cpp
  clang/lib/Lex/PPCaching.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Lex/TokenLexer.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/ParseStmtAsm.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Rewrite/HTMLRewrite.cpp

Index: clang/lib/Rewrite/HTMLRewrite.cpp
===
--- clang/lib/Rewrite/HTMLRewrite.cpp
+++ clang/lib/Rewrite/HTMLRewrite.cpp
@@ -572,7 +572,7 @@
 
   // Enter the tokens we just lexed.  This will cause them to be macro expanded
   // but won't enter sub-files (because we removed #'s).
-  TmpPP.EnterTokenStream(TokenStream, false);
+  TmpPP.EnterTokenStream(TokenStream, false, /*IsReinject=*/false);
 
   TokenConcatenation ConcatInfo(TmpPP);
 
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -1545,7 +1545,7 @@
   if (PP.isBacktrackEnabled())
 PP.RevertCachedTokens(1);
   else
-PP.EnterToken(Tok);
+PP.EnterToken(Tok, /*IsReinject=*/true);
   Tok.setKind(tok::annot_cxxscope);
   Tok.setAnnotationValue(Actions.SaveNestedNameSpecifierAnnotation(SS));
   Tok.setAnnotationRange(SS.getRange());
@@ -1764,7 +1764,7 @@
   Token TypedefToken;
   PP.Lex(TypedefToken);
   bool Result = TryAnnotateTypeOrScopeToken();
-  PP.EnterToken(Tok);
+  PP.EnterToken(Tok, /*IsReinject=*/true);
   Tok = TypedefToken;
   if (!Result)
 Diag(Tok.getLocation(), diag::warn_expected_qualified_after_typename);
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -919,7 +919,7 @@
 PrevTokLocation = RAngleLoc;
   } else {
 PrevTokLocation = TokBeforeGreaterLoc;
-PP.EnterToken(Tok);
+PP.EnterToken(Tok, /*IsReinject=*/true);
 Tok = Greater;
   }
 
@@ -1402,7 +1402,7 @@
   // Append the current token at the end of the new token stream so that it
   // doesn't get lost.
   LPT.Toks.push_back(Tok);
-  PP.EnterTokenStream(LPT.Toks, true);
+  PP.EnterTokenStream(LPT.Toks, true, /*IsReinject*/true);
 
   // Consume the previously pushed token.
   ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -213,7 +213,8 @@
   // Also copy the current token over.
   LineToks.push_back(Tok);
 
-  PP.EnterTokenStream(LineToks, /*DisableMacroExpansions*/ true);
+  PP.EnterTokenStream(LineToks, /*DisableMacroExpansions*/ true,
+  /*IsReinject*/ true);
 
   // Clear the current token and advance to the first token in LineToks.
   ConsumeAnyToken();
Index: clang/lib/Parse/ParsePragma.cpp
===
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -117,7 +117,8 @@
 Toks[0].setAnnotationEndLoc(Tok.getLocation());
 Toks[0].setAnnotationValue(reinterpret_cast(
static_cast(OOS)));
-PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true);
+PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true,
+/*IsReinject=*/false);
   }
 };
 
@@ -739,7 +740,8 @@
   // Grab the tokens out of the annotation and enter them into the stream.
   auto TheTokens =
   (std::pair, size_t> *)Tok.getAnnotationValue();
-  PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second, true);
+  PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second, true,
+  /*IsReinject=*/true);
   SourceLocation PragmaLocation = ConsumeAnnotationToken();
   assert(Tok.isAnyIdentifier());
   StringRef PragmaName = Tok.getIdentifierInfo()->getName();
@@ -,7 +1113,8 @@
 Hint.StateLoc = IdentifierLoc::cre

[PATCH] D61834: Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 12.
steveire added a comment.

Update


Repository:
  rC Clang

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

https://reviews.llvm.org/D61834

Files:
  include/clang/AST/ASTNodeTraverser.h
  unittests/AST/ASTTraverserTest.cpp
  unittests/AST/CMakeLists.txt

Index: unittests/AST/CMakeLists.txt
===
--- unittests/AST/CMakeLists.txt
+++ unittests/AST/CMakeLists.txt
@@ -12,6 +12,7 @@
   ASTImporterTest.cpp
   ASTImporterGenericRedeclTest.cpp
   ASTImporterVisibilityTest.cpp
+  ASTTraverserTest.cpp
   ASTTypeTraitsTest.cpp
   ASTVectorTest.cpp
   CommentLexer.cpp
Index: unittests/AST/ASTTraverserTest.cpp
===
--- /dev/null
+++ unittests/AST/ASTTraverserTest.cpp
@@ -0,0 +1,220 @@
+//===- unittests/AST/ASTTraverserTest.h===//
+//
+// 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 "clang/AST/ASTContext.h"
+#include "clang/AST/ASTNodeTraverser.h"
+#include "clang/AST/TextNodeDumper.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang::tooling;
+using namespace clang::ast_matchers;
+
+namespace clang {
+
+class NodeTreePrinter : public TextTreeStructure {
+  llvm::raw_ostream &OS;
+
+public:
+  NodeTreePrinter(llvm::raw_ostream &OS)
+  : TextTreeStructure(OS, /* showColors */ false), OS(OS) {}
+
+  void Visit(const Decl *D) { OS << D->getDeclKindName() << "Decl"; }
+
+  void Visit(const Stmt *S) { OS << S->getStmtClassName(); }
+
+  void Visit(QualType QT) {
+OS << "QualType " << QT.split().Quals.getAsString();
+  }
+
+  void Visit(const Type *T) { OS << T->getTypeClassName() << "Type"; }
+
+  void Visit(const comments::Comment *C, const comments::FullComment *FC) {
+OS << C->getCommentKindName();
+  }
+
+  void Visit(const CXXCtorInitializer *Init) { OS << "CXXCtorInitializer"; }
+
+  void Visit(const Attr *A) {
+switch (A->getKind()) {
+#define ATTR(X)\
+  case attr::X:\
+OS << #X;  \
+break;
+#include "clang/Basic/AttrList.inc"
+}
+OS << "Attr";
+  }
+
+  void Visit(const OMPClause *C) { OS << "OMPClause"; }
+  void Visit(const TemplateArgument &A, SourceRange R = {},
+ const Decl *From = nullptr, const char *Label = nullptr) {
+OS << "TemplateArgument";
+  }
+
+  template  void Visit(T...) {}
+};
+
+class TestASTDumper : public ASTNodeTraverser {
+
+  NodeTreePrinter MyNodeRecorder;
+
+public:
+  TestASTDumper(llvm::raw_ostream &OS) : MyNodeRecorder(OS) {}
+  NodeTreePrinter &doGetNodeDelegate() { return MyNodeRecorder; }
+};
+
+template  std::string dumpASTString(NodeType &&... N) {
+  std::string Buffer;
+  llvm::raw_string_ostream OS(Buffer);
+
+  TestASTDumper Dumper(OS);
+
+  OS << "\n";
+
+  Dumper.Visit(std::forward(N)...);
+
+  return OS.str();
+}
+
+const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,
+const std::string &name) {
+  auto Result = ast_matchers::match(functionDecl(hasName(name)).bind("fn"),
+AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+template  struct Verifier {
+  static void withDynNode(T Node, const std::string &dumpString) {
+EXPECT_EQ(dumpASTString(ast_type_traits::DynTypedNode::create(Node)),
+  dumpString);
+  }
+};
+
+template  struct Verifier {
+  static void withDynNode(T *Node, const std::string &dumpString) {
+EXPECT_EQ(dumpASTString(ast_type_traits::DynTypedNode::create(*Node)),
+  dumpString);
+  }
+};
+
+template 
+void verifyWithDynNode(T Node, const std::string &dumpString) {
+  EXPECT_EQ(dumpASTString(Node), dumpString);
+
+  Verifier::withDynNode(Node, dumpString);
+}
+
+TEST(Traverse, Dump) {
+
+  auto AST = buildASTFromCode(R"cpp(
+struct A {
+  int m_number;
+
+  /// CTor
+  A() : m_number(42) {}
+
+  [[nodiscard]] const int func() {
+return 42;
+  }
+
+};
+
+template
+struct templ
+{ 
+};
+
+template<>
+struct templ
+{ 
+};
+
+)cpp");
+
+  const FunctionDecl *Func = getFunctionNode(AST.get(), "func");
+
+  verifyWithDynNode(Func,
+R"cpp(
+CXXMethodDecl
+|-CompoundStmt
+| `-ReturnStmt
+|   `-IntegerLiteral
+`-WarnUnusedResultAttr
+)cpp");
+
+  Stmt *Body = Func->getBody();
+
+  verifyWithDynNode(Body,
+R"cpp(
+C

[PATCH] D61816: [CFG] [analyzer] pr41300: Add a branch to skip virtual base initializers when they are handled by the superclass.

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



Comment at: clang/lib/Analysis/CFG.cpp:1434-1438
+  // For C++ constructor add initializers to CFG. Virtual base classes may have
+  // already been initialized by the superclass. Make a branch so that it was
+  // possible to jump straight to non-virtual bases and fields, skipping
+  // virtual bases. We only need to do this once because all virtual base
+  // initializers go all together before all other initializers.

Szelethus wrote:
> I find this a little too vague. The standard states:
> 
> > First, and only for the constructor of the most derived class (4.5) , 
> > virtual base classes are initialized in the order they appear on a 
> > depth-first left-to-right traversal of the directed acyclic graph of base 
> > classes, where “left-to-right” is the order of appearance of the base 
> > classes in the derived class base-specifier-list.
> >
> > Then, direct base classes are initialized in declaration order as they 
> > appear in the (regardless of the order of the mem-initializer s).
> >
> > Then, non-static data members are initialized in the order they were 
> > declared in the class definition (again regardless of the order of the 
> > mem-initializer s).
> >
> > Finally, the base-specifier-list compound-statement of the constructor body 
> > is executed.
> 
> This would be an overkill here, but how does this sound like:
> 
> > Constructor delegations are ignored to virtual bases unless the object is 
> > of the most derived class.
> >
> >  class VBase { VBase() = default; VBase(int) {} };
> >  class A : virtual public VBase { A() : VBase(0) {} };
> >  class B : public A {};
> >
> >  B b; // Constructor calls in order: VBase(), A(), B().
> >   // VBase(int) is ignored, B isn't the most derived class that
> >   // delegates to the virtual base.
> >
> > This may result in the virtual base(s) being already initialized at this 
> > point, in which case we should jump right onto non-virtual bases and 
> > fields. To handle this, make a CFG branch. We only need to do this once, 
> > since the standard states that all virtual bases shall be initialized 
> > before non-virtual bases and direct data members.
> 
> Also, the comment of mine complementing this inline raises a concern about 
> "doing this only once", can you specify?
Mind you, this is the order of initialization for non-delegating constructors!


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

https://reviews.llvm.org/D61816



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


[PATCH] D61774: [LibTooling] Add RangeSelector library for defining source ranges based on bound AST nodes.

2019-05-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as done.
ilya-biryukov added inline comments.



Comment at: clang/include/clang/Tooling/Refactoring/RangeSelector.h:29
+
+namespace range_selector {
+inline RangeSelector charRange(CharSourceRange R) {

ymandel wrote:
> ilya-biryukov wrote:
> > Maybe try putting it into the tooling namespace directly?
> > Or are there immediate and unfortunate conflicts with existing names?
> > 
> > 
> No conflicts. Was just being cautious.
I can see why a separate namespace would make sense, but since the `tooling` 
namespace  is not densely populated I hope we can get away with putting things 
here directly and saving some typing on the use-sites.

Hope that does not backfire in the future, though.



Comment at: clang/include/clang/Tooling/Refactoring/RangeSelector.h:53
+/// token of the relevant name, not including qualifiers.
+RangeSelector name(StringRef Id);
+

ymandel wrote:
> ilya-biryukov wrote:
> > NIT: this is super-specialized, but has a very generic name, therefore 
> > might cause confusion. Maybe call it `ctorInitializerName`?
> It works with others as well, particularly NamedDecl. This is one place where 
> typed node ids would be nice, b/c that would allow us to make this interface 
> typed, like the matchers.
> 
> I kept the name but tried to clarify the comments.  WDYT?
Ah, sorry, misread the original comment. The name actually makes sense in that 
case.
Am I correct to assume it will only select the final identifier of a qualified 
name, but not the qualifier?
E.g. for `::foo::bar::baz`, it would only select `baz`, right?
What happens when we also have template args? E.g. for `::foo::bar::baz`, 
it would only select `baz`, right?

Maybe add those examples to the documentation? It's something that's very easy 
to get wrong.



Comment at: clang/include/clang/Tooling/Refactoring/RangeSelector.h:57
+// arguments (all source between the call's parentheses).
+RangeSelector args(StringRef Id);
+

ymandel wrote:
> ilya-biryukov wrote:
> > Same thing, maybe rename to `callExprArgs`?
> > And other nodes too
> i'd like to keep these as lightweight as possible. Compromised on callArgs?
`callArgs` LG, thanks!



Comment at: clang/unittests/Tooling/RangeSelectorTest.cpp:39
+llvm::Optional matchAny(StringRef Code, M Matcher) {
+  auto AstUnit = buildASTFromCode(Code);
+  if (AstUnit == nullptr) {

NIT: use `ASTUnit` to match LLVM naming rules



Comment at: clang/unittests/Tooling/RangeSelectorTest.cpp:143
+  // Node-id specific version:
+  test(Matcher, range(Arg0, Arg1), Code, "3, 7");
+  // General version:

Consider restructuring the code to place assertions into the test function 
itself.
This wildly improves locations reported in case of test failures and makes 
tests easier to read.

I.e. having something like
```
auto AST = buildASTAndMatch(Code, Matcher);
EXPECT_EQ(applySelector(range(Arg0, Arg1), AST),  "3, 7");
```
is arguably both easier to read and produces better location information on 
failures than a function that runs the test.
Even though it's a bit more code.


Note that it's a bit more complicated if you need to deal with `Expected<>` 
return types, but still possible:
```
EXPECT_THAT_EXPECTED(applySelector(range(Arg0, Arg1), AST),  HasValue("3, 7"));
EXPECT_THAT_EXPECTED(applySelector(range(Arg1, Arg0), AST),  Failed());
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61774



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


[PATCH] D61522: Added an assertion to constant evaluation enty points that prohibits dependent expressions

2019-05-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61522



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


[PATCH] D59555: [analyzer] Add yaml parser to GenericTaintChecker

2019-05-17 Thread Borsik Gábor via Phabricator via cfe-commits
boga95 updated this revision to Diff 10.
boga95 edited the summary of this revision.
boga95 added a comment.

I changed the parsing, therefore the return value index is represented by -1.
I added a test configuration file and parse it when testing to prove the 
configuration doesn't break the code.


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

https://reviews.llvm.org/D59555

Files:
  lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  test/Analysis/Inputs/taint-generic-config.yaml
  test/Analysis/taint-generic.c

Index: test/Analysis/taint-generic.c
===
--- test/Analysis/taint-generic.c
+++ test/Analysis/taint-generic.c
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1  -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -Wno-format-security -verify %s
-// RUN: %clang_analyze_cc1  -DFILE_IS_STRUCT -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -Wno-format-security -verify %s
+// RUN: %clang_analyze_cc1  -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -analyzer-config alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml -Wno-format-security -verify %s
+// RUN: %clang_analyze_cc1  -DFILE_IS_STRUCT -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -analyzer-config alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml -Wno-format-security -verify %s
 
 int scanf(const char *restrict format, ...);
 char *gets(char *str);
Index: test/Analysis/Inputs/taint-generic-config.yaml
===
--- /dev/null
+++ test/Analysis/Inputs/taint-generic-config.yaml
@@ -0,0 +1,51 @@
+# A list of source/propagation function
+Propagations:
+  # int x = mySource1(); // x is tainted
+  - Name: mySource1
+DstArgs:  [-1] # Index for return value
+
+  # int x;
+  # mySource2(&x); // x is tainted
+  - Name: mySource2
+DstArgs:  [0]
+
+  # int x, y;
+  # myScanf("%d %d", &x, &y); // x and y are tainted
+  - Name: myScanf
+VarType:  Dst
+VarIndex: 1
+
+  # int x; // x is tainted
+  # int y;
+  # myPropagator(x, &y); // y is tainted
+  - Name: myPropagator
+SrcArgs:  [0]
+DstArgs:  [1]
+
+  # constexpr unsigned size = 100;
+  # char buf[size];
+  # int x, y;
+  # int n = mySprintf(buf, size, "%d %d", x, y); // If size, x or y is tainted
+  # // the return value and the buf will be tainted
+  - Name: mySnprintf
+SrcArgs:  [1]
+DstArgs:  [0, -1]
+VarType:  Src
+VarIndex: 3
+
+# A list of filter functions
+Filters:
+  # int x; // x is tainted
+  # myFilter(&x); // x is not tainted anymore
+  - Name: myFilter
+Args: [0]
+
+# A list of sink functions
+Sinks:
+  # int x, y; // x and y are tainted
+  # mySink(x, 0, 1); // It will warn
+  # mySink(0, 1, y); // It will warn
+  # mySink(0, x, 1); // It won't warn
+  - Name: mySink
+Args: [0, 2]
+
Index: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -15,16 +15,17 @@
 //===--===//
 
 #include "Taint.h"
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/AST/Attr.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/YAMLTraits.h"
 #include 
-#include 
 #include 
 
 using namespace clang;
@@ -44,14 +45,45 @@
 
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
-  void printState(raw_ostream &Out, ProgramStateRef State,
-  const char *NL, const char *Sep) const override;
+  void printState(raw_ostream &Out, ProgramStateRef State, const char *NL,
+  const char *Sep) const override;
 
-private:
-  static const unsigned InvalidArgIndex = UINT_MAX;
+  using ArgVector = SmallVector;
+  using SignedArgVector = SmallVector;
+
+  enum class VariadicType { None, Src, Dst };
+
+  /// The ``TaintConfiguration`` is used to parse configuration file.
+  struct TaintConfiguration {
+using NameArgsPair = std::pair;
+
+struct Propagation {
+  std::string Name;
+  SignedArgVector SrcArgs;
+  SignedArgVector DstArgs;
+  VariadicType VarType;
+  unsigned VarIndex;
+};
+
+std::vector Propagations;
+std::vector Filters;
+std::vector Sinks;
+  };
+
+  /// Get and read the config file.
+  

[PATCH] D61335: [LibTooling] Add support to Transformer for composing rules as an ordered choice.

2019-05-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/include/clang/Tooling/Refactoring/Transformer.h:278
+/// Builds the matcher needed for registration.
+ast_matchers::internal::DynTypedMatcher buildMatcher(const RewriteRule &Rule);
+

ymandel wrote:
> ilya-biryukov wrote:
> > Can it be declared in `.cpp` file instead? Or is it used in `clang-tidy` 
> > integration? 
> `buildMatcher` and `findSelectedCase` will be used in the clang-tidy 
> integration and in the apply-rule-to-single-node function that I'm planning.
I'd say this makes these functions a public interface of rewrite rule, albeit 
it's an "advanced" use-case.
It's probably ok to keep them in `detail` namespace for now, but would be nice 
to come up with a proper public functions that allow us to implement those 
use-cases.
(Or declare these function public and well-supported and move them out of 
`detail` at some point)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61335



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


[PATCH] D41005: Reuse preamble even if an unsaved file does not exist

2019-05-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

Thanks! LGTM


Repository:
  rC Clang

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

https://reviews.llvm.org/D41005



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


[PATCH] D60763: Prototype OpenCL BIFs using Tablegen

2019-05-17 Thread Pierre via Phabricator via cfe-commits
Pierre updated this revision to Diff 18.
Pierre marked 14 inline comments as done.
Pierre added a comment.

Corrections from the comments on the previous version.


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

https://reviews.llvm.org/D60763

Files:
  clang/include/clang/Basic/CMakeLists.txt
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/OpenCLBuiltins.td
  clang/include/clang/Driver/CC1Options.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/builtin-new.cl
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -80,6 +80,7 @@
 void EmitTestPragmaAttributeSupportedAttributes(llvm::RecordKeeper &Records,
 llvm::raw_ostream &OS);
 
+void EmitClangOpenCLBuiltins(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 } // end namespace clang
 
 #endif
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -61,7 +61,8 @@
   GenDiagDocs,
   GenOptDocs,
   GenDataCollectors,
-  GenTestPragmaAttributeSupportedAttributes
+  GenTestPragmaAttributeSupportedAttributes,
+  GenClangOpenCLBuiltins,
 };
 
 namespace {
@@ -163,7 +164,9 @@
 clEnumValN(GenTestPragmaAttributeSupportedAttributes,
"gen-clang-test-pragma-attribute-supported-attributes",
"Generate a list of attributes supported by #pragma clang "
-   "attribute for testing purposes")));
+   "attribute for testing purposes"),
+clEnumValN(GenClangOpenCLBuiltins, "gen-clang-opencl-builtins",
+   "Generate OpenCL builtin handlers")));
 
 cl::opt
 ClangComponent("clang-component",
@@ -293,6 +296,9 @@
   case GenTestPragmaAttributeSupportedAttributes:
 EmitTestPragmaAttributeSupportedAttributes(Records, OS);
 break;
+  case GenClangOpenCLBuiltins:
+EmitClangOpenCLBuiltins(Records, OS);
+break;
   }
 
   return false;
Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- /dev/null
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -0,0 +1,328 @@
+//===- ClangOpenCLBuiltinEmitter.cpp - Generate Clang OpenCL Builtin handling
+//=-*- C++ -*--=//
+//
+// The LLVM Compiler Infrastructure
+//
+// 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 tablegen backend emits code allowing to check whether a function
+// belongs to OpenCL builtin functions. In the following case, all overloads
+// of this function are added to the LookupResult.
+// The code is generated in "OpenCLBuiltins.inc" and included by Clang
+// SemaLookup.cpp
+//
+// The resolution of a function name and its overload is follwing these steps:
+// for the function "cos", which has the overloads:
+//- float   cos(float)
+//- double  cos(double)
+//
+// 1-  = isOpenCLBuiltin("cos")
+// 2- OpenCLBuiltins[Index - Index + Len] contains the pairs
+//   of the overloads of "cos".
+// 3- OpenCLSignature[SignatureIndex, SignatureIndex + SignatureLen] contains
+//  one of the signaures of "cos". This OpenCLSignature table can be
+//  referenced by other functions, i.e. "sin", since multiple functions
+//  can have the same signature.
+//===--===//
+
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/StringMatcher.h"
+#include "llvm/TableGen/TableGenBackend.h"
+#include 
+
+using namespace llvm;
+
+namespace {
+class BuiltinNameEmitter {
+public:
+  BuiltinNameEmitter(RecordKeeper &Records, raw_ostream &OS)
+  : Records(Records), OS(OS) {}
+
+  // Entrypoint to generate the functions/ structures allowing to check
+  // whether a function is part of OpenCL builtin functions.
+  void Emit();
+
+private:
+  // Contains OpenCL builtin functions and related information, stored as
+  // Record instances. They are coming from the associated TableGen file.
+  R

[PATCH] D60763: Prototype OpenCL BIFs using Tablegen

2019-05-17 Thread Pierre via Phabricator via cfe-commits
Pierre added inline comments.



Comment at: clang/include/clang/Basic/OpenCLBuiltins.td:17
+//
+// Builtin functions are instances of the Builtin class.
+// Prototypes are defined as a list of Type classes (or its subclasses).

Anastasia wrote:
> Can you explain this comment please? At this point it almost feels like you 
> are adding Clang Builtin here. May be you should refer to definition of 
> OpenCL Builtin in this file.
I deleted this comment aswell, I feel it only adds confusion


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

https://reviews.llvm.org/D60763



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


r361004 - [NFC] Fix line endings in OpenCL tests

2019-05-17 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Fri May 17 02:25:38 2019
New Revision: 361004

URL: http://llvm.org/viewvc/llvm-project?rev=361004&view=rev
Log:
[NFC] Fix line endings in OpenCL tests

Modified:
cfe/trunk/test/CodeGenOpenCL/no-signed-zeros.cl
cfe/trunk/test/SemaOpenCL/array-init.cl

Modified: cfe/trunk/test/CodeGenOpenCL/no-signed-zeros.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/no-signed-zeros.cl?rev=361004&r1=361003&r2=361004&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/no-signed-zeros.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/no-signed-zeros.cl Fri May 17 02:25:38 2019
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s -check-prefix=NORMAL
-// RUN: %clang_cc1 %s -emit-llvm -cl-no-signed-zeros -o - | FileCheck %s 
-check-prefix=NO-SIGNED-ZEROS
-
-float signedzeros(float a) {
-  return a;
-}
-
-// CHECK: attributes
-// NORMAL: "no-signed-zeros-fp-math"="false"
-// NO-SIGNED-ZEROS: "no-signed-zeros-fp-math"="true"
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s -check-prefix=NORMAL
+// RUN: %clang_cc1 %s -emit-llvm -cl-no-signed-zeros -o - | FileCheck %s 
-check-prefix=NO-SIGNED-ZEROS
+
+float signedzeros(float a) {
+  return a;
+}
+
+// CHECK: attributes
+// NORMAL: "no-signed-zeros-fp-math"="false"
+// NO-SIGNED-ZEROS: "no-signed-zeros-fp-math"="true"

Modified: cfe/trunk/test/SemaOpenCL/array-init.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/array-init.cl?rev=361004&r1=361003&r2=361004&view=diff
==
--- cfe/trunk/test/SemaOpenCL/array-init.cl (original)
+++ cfe/trunk/test/SemaOpenCL/array-init.cl Fri May 17 02:25:38 2019
@@ -1,20 +1,20 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
-// expected-no-diagnostics
-
-__kernel void k1(queue_t q1, queue_t q2) {
-  queue_t q[] = {q1, q2};
-}
-
-__kernel void k2(read_only pipe int p) {
-  reserve_id_t i1 = reserve_read_pipe(p, 1);
-  reserve_id_t i2 = reserve_read_pipe(p, 1);
-  reserve_id_t i[] = {i1, i2};
-}
-
-event_t create_event();
-__kernel void k3() {
-  event_t e1 = create_event();
-  event_t e2 = create_event();
-  event_t e[] = {e1, e2};
-}
-
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// expected-no-diagnostics
+
+__kernel void k1(queue_t q1, queue_t q2) {
+  queue_t q[] = {q1, q2};
+}
+
+__kernel void k2(read_only pipe int p) {
+  reserve_id_t i1 = reserve_read_pipe(p, 1);
+  reserve_id_t i2 = reserve_read_pipe(p, 1);
+  reserve_id_t i[] = {i1, i2};
+}
+
+event_t create_event();
+__kernel void k3() {
+  event_t e1 = create_event();
+  event_t e2 = create_event();
+  event_t e[] = {e1, e2};
+}
+


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


r361006 - [analyzer] Insert checker options into AnalyzerOption::ConfigTable

2019-05-17 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Fri May 17 02:29:44 2019
New Revision: 361006

URL: http://llvm.org/viewvc/llvm-project?rev=361006&view=rev
Log:
[analyzer] Insert checker options into AnalyzerOption::ConfigTable

The more entries we have in AnalyzerOptions::ConfigTable, the more helpful
debug.ConfigDumper is. With this patch, I'm pretty confident that it'll now emit
the entire state of the analyzer, minus the frontend flags.

It would be nice to reserve the config table specifically to checker options
only, as storing the regular analyzer configs is kinda redundant.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
cfe/trunk/test/Analysis/analyzer-config.c
cfe/trunk/test/Analysis/checker-plugins.c

Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=361006&r1=361005&r2=361006&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Fri May 17 02:29:44 
2019
@@ -163,7 +163,7 @@ int AnalyzerOptions::getCheckerIntegerOp
   bool HasFailed = getCheckerStringOption(CheckerName, OptionName,
   std::to_string(DefaultVal),
   SearchInParents)
- .getAsInteger(10, Ret);
+ .getAsInteger(0, Ret);
   assert(!HasFailed && "analyzer-config option should be numeric");
   (void)HasFailed;
   return Ret;

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp?rev=361006&r1=361005&r2=361006&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp Fri May 17 
02:29:44 2019
@@ -309,27 +309,31 @@ void CheckerRegistry::addDependency(Stri
 template 
 static void
 insertOptionToCollection(StringRef FullName, T &Collection,
- const CheckerRegistry::CmdLineOption &&Option) {
+ const CheckerRegistry::CmdLineOption &Option,
+ AnalyzerOptions &AnOpts) {
   auto It = binaryFind(Collection, FullName);
   assert(It != Collection.end() &&
  "Failed to find the checker while attempting to add a command line "
  "option to it!");
 
-  It->CmdLineOptions.emplace_back(std::move(Option));
+  AnOpts.Config.insert(
+  {(FullName + ":" + Option.OptionName).str(), Option.DefaultValStr});
+
+  It->CmdLineOptions.emplace_back(Option);
 }
 
 void CheckerRegistry::resolveCheckerAndPackageOptions() {
   for (const std::pair &CheckerOptEntry :
CheckerOptions) {
 insertOptionToCollection(CheckerOptEntry.first, Checkers,
- std::move(CheckerOptEntry.second));
+ CheckerOptEntry.second, AnOpts);
   }
   CheckerOptions.clear();
 
   for (const std::pair &PackageOptEntry :
PackageOptions) {
 insertOptionToCollection(PackageOptEntry.first, Checkers,
- std::move(PackageOptEntry.second));
+ PackageOptEntry.second, AnOpts);
   }
   PackageOptions.clear();
 }

Modified: cfe/trunk/test/Analysis/analyzer-config.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=361006&r1=361005&r2=361006&view=diff
==
--- cfe/trunk/test/Analysis/analyzer-config.c (original)
+++ cfe/trunk/test/Analysis/analyzer-config.c Fri May 17 02:29:44 2019
@@ -1,8 +1,13 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 %s -o /dev/null 
-analyzer-checker=core,osx.cocoa,debug.ConfigDumper -analyzer-max-loop 34 > %t 
2>&1
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ConfigDumper > %t 2>&1
 // RUN: FileCheck --input-file=%t %s --match-full-lines
 
 // CHECK: [config]
 // CHECK-NEXT: aggressive-binary-operation-simplification = false
+// CHECK-NEXT: alpha.clone.CloneChecker:IgnoredFilesPattern = ""
+// CHECK-NEXT: alpha.clone.CloneChecker:MinimumCloneComplexity = 50
+// CHECK-NEXT: alpha.clone.CloneChecker:ReportNormalClones = true
+// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtExec = 0x04
+// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtRead = 0x01
 // CHECK-NEXT: avoid-suppressing-null-argument-paths = false
 // CHECK-NEXT: c++-allocator-inlining = true
 // CHECK-NEXT: c++-container-inlining = false
@@ -18,9 +23,26 @@
 // CHECK-NEXT: cfg-rich-constructors = true
 // CHECK-NEXT: cfg-scopes = false
 // CHECK-NEXT: cfg-temporary-dtors = true
+// CHE

[PATCH] D57922: [analyzer] Insert checker options into AnalyzerOption::ConfigTable

2019-05-17 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Szelethus marked an inline comment as done.
Closed by commit rL361006: [analyzer] Insert checker options into 
AnalyzerOption::ConfigTable (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D57922?vs=190991&id=21#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D57922

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
  cfe/trunk/test/Analysis/analyzer-config.c
  cfe/trunk/test/Analysis/checker-plugins.c

Index: cfe/trunk/test/Analysis/analyzer-config.c
===
--- cfe/trunk/test/Analysis/analyzer-config.c
+++ cfe/trunk/test/Analysis/analyzer-config.c
@@ -1,8 +1,13 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 %s -o /dev/null -analyzer-checker=core,osx.cocoa,debug.ConfigDumper -analyzer-max-loop 34 > %t 2>&1
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ConfigDumper > %t 2>&1
 // RUN: FileCheck --input-file=%t %s --match-full-lines
 
 // CHECK: [config]
 // CHECK-NEXT: aggressive-binary-operation-simplification = false
+// CHECK-NEXT: alpha.clone.CloneChecker:IgnoredFilesPattern = ""
+// CHECK-NEXT: alpha.clone.CloneChecker:MinimumCloneComplexity = 50
+// CHECK-NEXT: alpha.clone.CloneChecker:ReportNormalClones = true
+// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtExec = 0x04
+// CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtRead = 0x01
 // CHECK-NEXT: avoid-suppressing-null-argument-paths = false
 // CHECK-NEXT: c++-allocator-inlining = true
 // CHECK-NEXT: c++-container-inlining = false
@@ -18,9 +23,26 @@
 // CHECK-NEXT: cfg-rich-constructors = true
 // CHECK-NEXT: cfg-scopes = false
 // CHECK-NEXT: cfg-temporary-dtors = true
+// CHECK-NEXT: cplusplus.Move:WarnOn = KnownsAndLocals
 // CHECK-NEXT: crosscheck-with-z3 = false
 // CHECK-NEXT: ctu-dir = ""
 // CHECK-NEXT: ctu-index-name = externalDefMap.txt
+// CHECK-NEXT: debug.AnalysisOrder:* = false
+// CHECK-NEXT: debug.AnalysisOrder:Bind = false
+// CHECK-NEXT: debug.AnalysisOrder:EndFunction = false
+// CHECK-NEXT: debug.AnalysisOrder:LiveSymbols = false
+// CHECK-NEXT: debug.AnalysisOrder:NewAllocator = false
+// CHECK-NEXT: debug.AnalysisOrder:PostCall = false
+// CHECK-NEXT: debug.AnalysisOrder:PostStmtArraySubscriptExpr = false
+// CHECK-NEXT: debug.AnalysisOrder:PostStmtCXXNewExpr = false
+// CHECK-NEXT: debug.AnalysisOrder:PostStmtCastExpr = false
+// CHECK-NEXT: debug.AnalysisOrder:PostStmtOffsetOfExpr = false
+// CHECK-NEXT: debug.AnalysisOrder:PreCall = false
+// CHECK-NEXT: debug.AnalysisOrder:PreStmtArraySubscriptExpr = false
+// CHECK-NEXT: debug.AnalysisOrder:PreStmtCXXNewExpr = false
+// CHECK-NEXT: debug.AnalysisOrder:PreStmtCastExpr = false
+// CHECK-NEXT: debug.AnalysisOrder:PreStmtOffsetOfExpr = false
+// CHECK-NEXT: debug.AnalysisOrder:RegionChanges = false
 // CHECK-NEXT: display-ctu-progress = false
 // CHECK-NEXT: eagerly-assume = true
 // CHECK-NEXT: elide-constructors = true
@@ -40,7 +62,19 @@
 // CHECK-NEXT: mode = deep
 // CHECK-NEXT: model-path = ""
 // CHECK-NEXT: notes-as-events = false
+// CHECK-NEXT: nullability:NoDiagnoseCallsToSystemHeaders = false
 // CHECK-NEXT: objc-inlining = true
+// CHECK-NEXT: optin.cplusplus.UninitializedObject:CheckPointeeInitialization = false
+// CHECK-NEXT: optin.cplusplus.UninitializedObject:IgnoreGuardedFields = false
+// CHECK-NEXT: optin.cplusplus.UninitializedObject:IgnoreRecordsWithField = ""
+// CHECK-NEXT: optin.cplusplus.UninitializedObject:NotesAsWarnings = false
+// CHECK-NEXT: optin.cplusplus.UninitializedObject:Pedantic = false
+// CHECK-NEXT: optin.cplusplus.VirtualCall:PureOnly = false
+// CHECK-NEXT: optin.osx.cocoa.localizability.NonLocalizedStringChecker:AggressiveReport = false
+// CHECK-NEXT: optin.performance.Padding:AllowedPad = 24
+// CHECK-NEXT: osx.NumberObjectConversion:Pedantic = false
+// CHECK-NEXT: osx.cocoa.RetainCount:CheckOSObject = true
+// CHECK-NEXT: osx.cocoa.RetainCount:TrackNSCFStartParam = false
 // CHECK-NEXT: prune-paths = true
 // CHECK-NEXT: region-store-small-struct-limit = 2
 // CHECK-NEXT: report-in-main-source-file = false
@@ -49,7 +83,8 @@
 // CHECK-NEXT: suppress-c++-stdlib = true
 // CHECK-NEXT: suppress-inlined-defensive-checks = true
 // CHECK-NEXT: suppress-null-return-paths = true
+// CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 49
+// CHECK-NEXT: num-entries = 84
Index: cfe/trunk/test/Analysis/checker-plugins.c
===
--- cfe/trunk/test/Analysi

r361007 - [Lex] Allow to consume tokens while preprocessing

2019-05-17 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri May 17 02:32:05 2019
New Revision: 361007

URL: http://llvm.org/viewvc/llvm-project?rev=361007&view=rev
Log:
[Lex] Allow to consume tokens while preprocessing

Summary:
By adding a hook to consume all tokens produced by the preprocessor.
The intention of this change is to make it possible to consume the
expanded tokens without re-runnig the preprocessor with minimal changes
to the preprocessor and minimal performance penalty when preprocessing
without recording the tokens.

The added hook is very low-level and reconstructing the expanded token
stream requires more work in the client code, the actual algorithm to
collect the tokens using this hook can be found in the follow-up change.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: eraman, nemanjai, kbarton, jsji, riccibruno, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Lex/Token.h
cfe/trunk/include/clang/Lex/TokenLexer.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Lex/MacroArgs.cpp
cfe/trunk/lib/Lex/PPCaching.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Lex/TokenLexer.cpp
cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/lib/Parse/ParseStmtAsm.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=361007&r1=361006&r2=361007&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri May 17 02:32:05 2019
@@ -33,6 +33,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerUnion.h"
@@ -48,8 +49,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -124,6 +125,7 @@ class Preprocessor {
   friend class VAOptDefinitionContext;
   friend class VariadicMacroScopeGuard;
 
+  llvm::unique_function OnToken;
   std::shared_ptr PPOpts;
   DiagnosticsEngine*Diags;
   LangOptions   &LangOpts;
@@ -998,6 +1000,13 @@ public:
   }
   /// \}
 
+  /// Register a function that would be called on each token in the final
+  /// expanded token stream.
+  /// This also reports annotation tokens produced by the parser.
+  void setTokenWatcher(llvm::unique_function F) {
+OnToken = std::move(F);
+  }
+
   bool isMacroDefined(StringRef Id) {
 return isMacroDefined(&Identifiers.get(Id));
   }
@@ -1282,6 +1291,7 @@ public:
   void EnterMacro(Token &Tok, SourceLocation ILEnd, MacroInfo *Macro,
   MacroArgs *Args);
 
+private:
   /// Add a "macro" context to the top of the include stack,
   /// which will cause the lexer to start returning the specified tokens.
   ///
@@ -1293,18 +1303,24 @@ public:
   /// of tokens has a permanent owner somewhere, so they do not need to be
   /// copied. If it is true, it assumes the array of tokens is allocated with
   /// \c new[] and the Preprocessor will delete[] it.
-private:
+  ///
+  /// If \p IsReinject the resulting tokens will have Token::IsReinjected flag
+  /// set, see the flag documentation for details.
   void EnterTokenStream(const Token *Toks, unsigned NumToks,
-bool DisableMacroExpansion, bool OwnsTokens);
+bool DisableMacroExpansion, bool OwnsTokens,
+bool IsReinject);
 
 public:
   void EnterTokenStream(std::unique_ptr Toks, unsigned NumToks,
-bool DisableMacroExpansion) {
-EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion, true);
+bool DisableMacroExpansion, bool IsReinject) {
+EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion, true,
+ IsReinject);
   }
 
-  void EnterTokenStream(ArrayRef Toks, bool DisableMacroExpansion) {
-EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion, false);
+  void EnterTokenStream(ArrayRef Toks, bool DisableMacroExpansion,
+bool IsReinject) {
+EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansio

[clang-tools-extra] r361007 - [Lex] Allow to consume tokens while preprocessing

2019-05-17 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri May 17 02:32:05 2019
New Revision: 361007

URL: http://llvm.org/viewvc/llvm-project?rev=361007&view=rev
Log:
[Lex] Allow to consume tokens while preprocessing

Summary:
By adding a hook to consume all tokens produced by the preprocessor.
The intention of this change is to make it possible to consume the
expanded tokens without re-runnig the preprocessor with minimal changes
to the preprocessor and minimal performance penalty when preprocessing
without recording the tokens.

The added hook is very low-level and reconstructing the expanded token
stream requires more work in the client code, the actual algorithm to
collect the tokens using this hook can be found in the follow-up change.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: eraman, nemanjai, kbarton, jsji, riccibruno, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp?rev=361007&r1=361006&r2=361007&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
Fri May 17 02:32:05 2019
@@ -175,7 +175,9 @@ classifyToken(const FunctionDecl &F, Pre
   Token End;
   End.setKind(tok::eof);
   SmallVector Stream{Tok, End};
-  PP.EnterTokenStream(Stream, false);
+
+  // FIXME: do not report these token to Preprocessor.TokenWatcher.
+  PP.EnterTokenStream(Stream, false, /*IsReinject=*/false);
   while (true) {
 Token T;
 PP.Lex(T);


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


[PATCH] D57922: [analyzer] Insert checker options into AnalyzerOption::ConfigTable

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

I committed but changed the moves to copies. Singel 
`CheckerRegisrty::CmdLineOption` is only filled with `StringRef`s, it shouldn't 
really matter.




Comment at: lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp:314
 insertOptionToCollection(StringRef FullName, T &Collection,
- const CheckerRegistry::CmdLineOption &&Option) {
+ const CheckerRegistry::CmdLineOption &&Option,
+ AnalyzerOptions &AnOpts) {

NoQ wrote:
> Mmm, const rvalue reference? Is this even a thing?
Apparently :D


Repository:
  rL LLVM

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

https://reviews.llvm.org/D57922



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


[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC361007: [Lex] Allow to consume tokens while preprocessing 
(authored by ibiryukov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D59885?vs=11&id=22#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D59885

Files:
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/Token.h
  include/clang/Lex/TokenLexer.h
  include/clang/Parse/Parser.h
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Lex/MacroArgs.cpp
  lib/Lex/PPCaching.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/PPMacroExpansion.cpp
  lib/Lex/Pragma.cpp
  lib/Lex/Preprocessor.cpp
  lib/Lex/TokenLexer.cpp
  lib/Parse/ParseCXXInlineMethods.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseObjc.cpp
  lib/Parse/ParseOpenMP.cpp
  lib/Parse/ParsePragma.cpp
  lib/Parse/ParseStmtAsm.cpp
  lib/Parse/ParseTemplate.cpp
  lib/Parse/Parser.cpp
  lib/Rewrite/HTMLRewrite.cpp

Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -33,6 +33,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerUnion.h"
@@ -48,8 +49,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -124,6 +125,7 @@
   friend class VAOptDefinitionContext;
   friend class VariadicMacroScopeGuard;
 
+  llvm::unique_function OnToken;
   std::shared_ptr PPOpts;
   DiagnosticsEngine*Diags;
   LangOptions   &LangOpts;
@@ -998,6 +1000,13 @@
   }
   /// \}
 
+  /// Register a function that would be called on each token in the final
+  /// expanded token stream.
+  /// This also reports annotation tokens produced by the parser.
+  void setTokenWatcher(llvm::unique_function F) {
+OnToken = std::move(F);
+  }
+
   bool isMacroDefined(StringRef Id) {
 return isMacroDefined(&Identifiers.get(Id));
   }
@@ -1282,6 +1291,7 @@
   void EnterMacro(Token &Tok, SourceLocation ILEnd, MacroInfo *Macro,
   MacroArgs *Args);
 
+private:
   /// Add a "macro" context to the top of the include stack,
   /// which will cause the lexer to start returning the specified tokens.
   ///
@@ -1293,18 +1303,24 @@
   /// of tokens has a permanent owner somewhere, so they do not need to be
   /// copied. If it is true, it assumes the array of tokens is allocated with
   /// \c new[] and the Preprocessor will delete[] it.
-private:
+  ///
+  /// If \p IsReinject the resulting tokens will have Token::IsReinjected flag
+  /// set, see the flag documentation for details.
   void EnterTokenStream(const Token *Toks, unsigned NumToks,
-bool DisableMacroExpansion, bool OwnsTokens);
+bool DisableMacroExpansion, bool OwnsTokens,
+bool IsReinject);
 
 public:
   void EnterTokenStream(std::unique_ptr Toks, unsigned NumToks,
-bool DisableMacroExpansion) {
-EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion, true);
+bool DisableMacroExpansion, bool IsReinject) {
+EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion, true,
+ IsReinject);
   }
 
-  void EnterTokenStream(ArrayRef Toks, bool DisableMacroExpansion) {
-EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion, false);
+  void EnterTokenStream(ArrayRef Toks, bool DisableMacroExpansion,
+bool IsReinject) {
+EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion, false,
+ IsReinject);
   }
 
   /// Pop the current lexer/macro exp off the top of the lexer stack.
@@ -1449,15 +1465,18 @@
   ///
   /// If BackTrack() is called afterwards, the token will remain at the
   /// insertion point.
-  void EnterToken(const Token &Tok) {
+  /// If \p IsReinject is true, resulting token will have Token::IsReinjected
+  /// flag set. See the flag documentation for details.
+  void EnterToken(const Token &Tok, bool IsReinject) {
 if (LexLevel) {
   // It's not correct in general to enter caching lex mode while in the
   // middle of a nested lexing action.
   auto TokCopy = llvm::make_unique(1);
   TokCopy[0] = Tok;
-  EnterTokenStream(std::move(TokCopy), 1, true);
+  EnterTokenStream(std::move(TokCopy), 1, true, IsReinject);
 } else {
   EnterCachingLexMode();
+  assert(IsReinject && "new tokens in the middle of cached stream");
   CachedTokens.insert(CachedTokens.begin()+CachedLexPos, Tok);
 }
   }
@@ -2136,7 +2155,7 @@
 
   //===--

r361011 - [analyzer] Validate checker option names and values

2019-05-17 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Fri May 17 02:51:59 2019
New Revision: 361011

URL: http://llvm.org/viewvc/llvm-project?rev=361011&view=rev
Log:
[analyzer] Validate checker option names and values

Validate whether the option exists, and also whether the supplied value is of
the correct type. With this patch, invoking the analyzer should be, at least
in the frontend mode, a lot safer.

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
cfe/trunk/test/Analysis/checker-plugins.c
cfe/trunk/test/Analysis/invalid-checker-option.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=361011&r1=361010&r2=361011&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Fri May 17 02:51:59 
2019
@@ -307,6 +307,8 @@ def err_analyzer_config_multiple_values
 def err_analyzer_config_invalid_input : Error<
   "invalid input for analyzer-config option '%0', that expects %1 value">;
 def err_analyzer_config_unknown : Error<"unknown analyzer-config '%0'">;
+def err_analyzer_checker_option_unknown : Error<
+  "checker '%0' has no option called '%1'">;
 def err_analyzer_checker_option_invalid_input : Error<
   "invalid input for checker option '%0', that expects %1">;
 

Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h?rev=361011&r1=361010&r2=361011&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h Fri May 
17 02:51:59 2019
@@ -107,6 +107,17 @@ public:
   assert((OptionType == "bool" || OptionType == "string" ||
   OptionType == "int") &&
  "Unknown command line option type!");
+
+  assert((OptionType != "bool" ||
+  (DefaultValStr == "true" || DefaultValStr == "false")) &&
+ "Invalid value for boolean command line option! Maybe incorrect "
+ "parameters to the addCheckerOption or addPackageOption method?");
+
+  int Tmp;
+  assert((OptionType != "int" || !DefaultValStr.getAsInteger(0, Tmp)) &&
+ "Invalid value for integer command line option! Maybe incorrect "
+ "parameters to the addCheckerOption or addPackageOption method?");
+  (void)Tmp;
 }
   };
 
@@ -150,6 +161,12 @@ public:
   return State == StateFromCmdLine::State_Disabled && ShouldRegister(LO);
 }
 
+// Since each checker must have a different full name, we can identify
+// CheckerInfo objects by them.
+bool operator==(const CheckerInfo &Rhs) const {
+  return FullName == Rhs.FullName;
+}
+
 CheckerInfo(InitializationFunction Fn, ShouldRegisterFunction sfn,
 StringRef Name, StringRef Desc, StringRef DocsUri,
 bool IsHidden)

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp?rev=361011&r1=361010&r2=361011&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp Fri May 17 
02:51:59 2019
@@ -9,6 +9,7 @@
 #include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
@@ -306,18 +307,61 @@ void CheckerRegistry::addDependency(Stri
   Dependencies.emplace_back(FullName, Dependency);
 }
 
+/// Insert the checker/package option to AnalyzerOptions' config table, and
+/// validate it, if the user supplied it on the command line.
+static void insertAndValidate(StringRef FullName,
+  const CheckerRegistry::CmdLineOption &Option,
+  AnalyzerOptions &AnOpts,
+  DiagnosticsEngine &Diags) {
+
+  std::string FullOption = (FullName + ":" + Option.OptionName).str();
+
+  auto It = AnOpts.Config.insert({FullOption, Option.DefaultValStr});
+
+  // Insertation was successful -- CmdLineOption's constructor will validate
+  // whether values received from plugins or TableGen files are correc

[PATCH] D60672: [libclang] visit c++14 lambda capture init expressions

2019-05-17 Thread Milian Wolff via Phabricator via cfe-commits
milianw added a comment.

@nik odd, it works for me, I just switched to master (previously I used the 8x 
release branch) and applied this patch and build it all. Then I run:

  $ make && ./bin/llvm-lit 
~/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp
  makeobj[0]: Entering directory `/home/milian/projects/build/llvm-project'
  ninja: no work to do.
  makeobj[0]: Leaving directory `/home/milian/projects/build/llvm-project'
  llvm-lit: 
/home/milian/projects/src/llvm-project/llvm/utils/lit/lit/llvm/config.py:340: 
note: using clang: /home/milian/projects/build/llvm-project/bin/clang
  -- Testing: 1 tests, single process --
  PASS: Clang :: Index/cxx14-lambdas.cpp (1 of 1)
  Testing Time: 0.09s
Expected Passes: 1

Are you sure you have compiled this patch? If I comment out the visit of the 
InitExpr in CIndex.cpp again, then I get the same failure as you:

  $ make && ./bin/llvm-lit -a 
~/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp
  makeobj[0]: Entering directory `/home/milian/projects/build/llvm-project'
  ninja: no work to do.
  makeobj[0]: Leaving directory `/home/milian/projects/build/llvm-project'
  llvm-lit: 
/home/milian/projects/src/llvm-project/llvm/utils/lit/lit/llvm/config.py:340: 
note: using clang: /home/milian/projects/build/llvm-project/bin/clang
  -- Testing: 1 tests, single process --
  FAIL: Clang :: Index/cxx14-lambdas.cpp (1 of 1)
   TEST 'Clang :: Index/cxx14-lambdas.cpp' FAILED 

  Script:
  --
  : 'RUN: at line 13';   
/home/milian/projects/build/llvm-project/bin/c-index-test -test-load-source all 
-std=c++14 
/home/milian/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp | 
/home/milian/projects/build/llvm-project/bin/FileCheck -check-prefix=CHECK-LOAD 
/home/milian/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp
  : 'RUN: at line 30';   env CINDEXTEST_INDEXLOCALSYMBOLS=1 
/home/milian/projects/build/llvm-project/bin/c-index-test -index-file 
-std=c++14 
/home/milian/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp | 
/home/milian/projects/build/llvm-project/bin/FileCheck 
-check-prefix=CHECK-INDEX 
/home/milian/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  
/home/milian/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp:22:16:
 error: CHECK-LOAD: expected string not found in input
  // CHECK-LOAD: cxx14-lambdas.cpp:7:27: DeclRefExpr=localA:6:9 Extent=[7:27 - 
7:33]
 ^
  :390:1: note: scanning from here
  // CHECK: cxx14-lambdas.cpp:7:59: ParmDecl=x:7:59 (Definition) Extent=[7:51 - 
7:60]
  ^
  :402:11: note: possible intended match here
  // CHECK: cxx14-lambdas.cpp:8:21: DeclRefExpr=copy:7:35 Extent=[8:21 - 8:25]
^
  
  --
  
  
  Testing Time: 0.07s
  
  Failing Tests (1):
  Clang :: Index/cxx14-lambdas.cpp
  
Unexpected Failures: 1

Re-enabling the code and building again, it works fine again:

  $ make && ./bin/llvm-lit -a 
~/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp
  makeobj[0]: Entering directory `/home/milian/projects/build/llvm-project'
  [5/5] Linking CXX executable bin/c-index-test
  makeobj[0]: Leaving directory `/home/milian/projects/build/llvm-project'
  llvm-lit: 
/home/milian/projects/src/llvm-project/llvm/utils/lit/lit/llvm/config.py:340: 
note: using clang: /home/milian/projects/build/llvm-project/bin/clang
  -- Testing: 1 tests, single process --
  PASS: Clang :: Index/cxx14-lambdas.cpp (1 of 1)
  Script:
  --
  : 'RUN: at line 13';   
/home/milian/projects/build/llvm-project/bin/c-index-test -test-load-source all 
-std=c++14 
/home/milian/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp | 
/home/milian/projects/build/llvm-project/bin/FileCheck -check-prefix=CHECK-LOAD 
/home/milian/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp
  : 'RUN: at line 30';   env CINDEXTEST_INDEXLOCALSYMBOLS=1 
/home/milian/projects/build/llvm-project/bin/c-index-test -index-file 
-std=c++14 
/home/milian/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp | 
/home/milian/projects/build/llvm-project/bin/FileCheck 
-check-prefix=CHECK-INDEX 
/home/milian/projects/src/llvm-project/clang/test/Index/cxx14-lambdas.cpp
  --
  Exit Code: 0
  
  
  
  Testing Time: 0.14s
Expected Passes: 1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60672



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


[PATCH] D57860: [analyzer] Validate checker option names and values

2019-05-17 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL361011: [analyzer] Validate checker option names and values 
(authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D57860?vs=190992&id=25#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D57860

Files:
  cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
  cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
  cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
  cfe/trunk/test/Analysis/checker-plugins.c
  cfe/trunk/test/Analysis/invalid-checker-option.c

Index: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
@@ -107,6 +107,17 @@
   assert((OptionType == "bool" || OptionType == "string" ||
   OptionType == "int") &&
  "Unknown command line option type!");
+
+  assert((OptionType != "bool" ||
+  (DefaultValStr == "true" || DefaultValStr == "false")) &&
+ "Invalid value for boolean command line option! Maybe incorrect "
+ "parameters to the addCheckerOption or addPackageOption method?");
+
+  int Tmp;
+  assert((OptionType != "int" || !DefaultValStr.getAsInteger(0, Tmp)) &&
+ "Invalid value for integer command line option! Maybe incorrect "
+ "parameters to the addCheckerOption or addPackageOption method?");
+  (void)Tmp;
 }
   };
 
@@ -150,6 +161,12 @@
   return State == StateFromCmdLine::State_Disabled && ShouldRegister(LO);
 }
 
+// Since each checker must have a different full name, we can identify
+// CheckerInfo objects by them.
+bool operator==(const CheckerInfo &Rhs) const {
+  return FullName == Rhs.FullName;
+}
+
 CheckerInfo(InitializationFunction Fn, ShouldRegisterFunction sfn,
 StringRef Name, StringRef Desc, StringRef DocsUri,
 bool IsHidden)
Index: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
@@ -307,6 +307,8 @@
 def err_analyzer_config_invalid_input : Error<
   "invalid input for analyzer-config option '%0', that expects %1 value">;
 def err_analyzer_config_unknown : Error<"unknown analyzer-config '%0'">;
+def err_analyzer_checker_option_unknown : Error<
+  "checker '%0' has no option called '%1'">;
 def err_analyzer_checker_option_invalid_input : Error<
   "invalid input for checker option '%0', that expects %1">;
 
Index: cfe/trunk/test/Analysis/checker-plugins.c
===
--- cfe/trunk/test/Analysis/checker-plugins.c
+++ cfe/trunk/test/Analysis/checker-plugins.c
@@ -62,3 +62,35 @@
 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-CHECKER-OPTION-TRUE
 
 // CHECK-CHECKER-OPTION-TRUE: example.MyChecker:ExampleOption = true
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
+// RUN:   -analyzer-checker=example.MyChecker \
+// RUN:   -analyzer-config example.MyChecker:Example=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-NON-EXISTENT-CHECKER-OPTION
+
+// CHECK-NON-EXISTENT-CHECKER-OPTION: (frontend): checker 'example.MyChecker'
+// CHECK-NON-EXISTENT-CHECKER-OPTION-SAME: has no option called 'Example'
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
+// RUN:   -analyzer-checker=example.MyChecker \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config example.MyChecker:Example=true
+
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
+// RUN:   -analyzer-checker=example.MyChecker \
+// RUN:   -analyzer-config example.MyChecker:ExampleOption=example \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-BOOL-VALUE
+
+// CHECK-INVALID-BOOL-VALUE: (frontend): invalid input for checker option
+// CHECK-INVALID-BOOL-VALUE-SAME: 'example.MyChecker:ExampleOption', that
+// CHECK-INVALID-BOOL-VALUE-SAME: expects a boolean value
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -load %llvmshlibdir/CheckerOptionHandlingAnalyzerPlugin%pluginext\
+// RUN:   -analyzer-checker=example.MyChecker \
+// RUN:   -analyzer-config-compatibility-mode=true \
+// RUN:   -analyzer-config example.MyChecker:ExampleOption=example
Inde

[PATCH] D61974: [ObjC] Fix encoding of ObjC pointer types that are pointers to typedefs

2019-05-17 Thread David Chisnall via Phabricator via cfe-commits
theraven added inline comments.



Comment at: lib/AST/ASTContext.cpp:6973
 QualType PointeeTy = OPT->getPointeeType();
-if (!Options.EncodingProperty() &&
+if (getLangOpts().ObjCRuntime.isGNUFamily() &&
+!Options.EncodingProperty() &&

ahatanak wrote:
> theraven wrote:
> > Please can we at least make this check just for the GCC runtime?  I'm not 
> > sure it's even needed there.  I've previously had to write code that works 
> > around this and have always considered it a bug in GCC, rather than a 
> > feature that I'd like us to copy, so I'd also be happy with just deleting 
> > this code path entirely.
> > 
> Are we allowed to delete the code path entirely? That would clean up the code 
> a bit, but I assume it would also break GCC runtime users' code.
I'd be happy with deleting it entirely.  Nothing in the gcc runtime itself 
depends on it and all of the code that I've dealt with that works with the GCC 
runtime and this functionality has explicit work arounds for this behaviour in 
GCC.



Repository:
  rC Clang

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

https://reviews.llvm.org/D61974



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


[PATCH] D59887: [Syntax] Introduce TokenBuffer, start clangToolingSyntax library

2019-05-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 200019.
ilya-biryukov added a comment.

- Remove the function that maps tokens to offsets


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59887

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/Syntax/CMakeLists.txt
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/Syntax/CMakeLists.txt
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -0,0 +1,620 @@
+//===- TokensTest.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
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Tokens.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/Expr.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.def"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/Utils.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/raw_os_ostream.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock-more-matchers.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang;
+using namespace clang::syntax;
+
+using llvm::ValueIs;
+using ::testing::AllOf;
+using ::testing::Contains;
+using ::testing::ElementsAre;
+using ::testing::Matcher;
+using ::testing::Not;
+using ::testing::StartsWith;
+
+namespace {
+// Checks the passed ArrayRef has the same begin() and end() iterators as the
+// argument.
+MATCHER_P(SameRange, A, "") {
+  return A.begin() == arg.begin() && A.end() == arg.end();
+}
+// Matchers for syntax::Token.
+MATCHER_P(Kind, K, "") { return arg.kind() == K; }
+MATCHER_P2(HasText, Text, SourceMgr, "") {
+  return arg.text(*SourceMgr) == Text;
+}
+/// Checks the start and end location of a token are equal to SourceRng.
+MATCHER_P(RangeIs, SourceRng, "") {
+  return arg.location() == SourceRng.first &&
+ arg.endLocation() == SourceRng.second;
+}
+
+class TokenCollectorTest : public ::testing::Test {
+public:
+  /// Run the clang frontend, collect the preprocessed tokens from the frontend
+  /// invocation and store them in this->Buffer.
+  /// This also clears SourceManager before running the compiler.
+  void recordTokens(llvm::StringRef Code) {
+class RecordTokens : public ASTFrontendAction {
+public:
+  explicit RecordTokens(TokenBuffer &Result) : Result(Result) {}
+
+  bool BeginSourceFileAction(CompilerInstance &CI) override {
+assert(!Collector && "expected only a single call to BeginSourceFile");
+Collector.emplace(CI.getPreprocessor());
+return true;
+  }
+  void EndSourceFileAction() override {
+assert(Collector && "BeginSourceFileAction was never called");
+Result = std::move(*Collector).consume();
+  }
+
+  std::unique_ptr
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+return llvm::make_unique();
+  }
+
+private:
+  TokenBuffer &Result;
+  llvm::Optional Collector;
+};
+
+constexpr const char *FileName = "./input.cpp";
+FS->addFile(FileName, time_t(), llvm::MemoryBuffer::getMemBufferCopy(""));
+// Prepare to run a compiler.
+std::vector Args = {"tok-test", "-std=c++03", "-fsyntax-only",
+  FileName};
+auto CI = createInvocationFromCommandLine(Args, Diags, FS);
+assert(CI);
+CI->getFrontendOpts().DisableFree = false;
+CI->getPreprocessorOpts().addRemappedFile(
+ 

r360984 - [ELF] Implement Dependent Libraries Feature

2019-05-17 Thread Ben Dunbobbin via cfe-commits
Author: bd1976llvm
Date: Thu May 16 20:44:15 2019
New Revision: 360984

URL: http://llvm.org/viewvc/llvm-project?rev=360984&view=rev
Log:
[ELF] Implement Dependent Libraries Feature

This patch implements a limited form of autolinking primarily designed to allow
either the --dependent-library compiler option, or "comment lib" pragmas (
https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=vs-2017) in
C/C++ e.g. #pragma comment(lib, "foo"), to cause an ELF linker to automatically
add the specified library to the link when processing the input file generated
by the compiler.

Currently this extension is unique to LLVM and LLD. However, care has been taken
to design this feature so that it could be supported by other ELF linkers.

The design goals were to provide:

- A simple linking model for developers to reason about.
- The ability to to override autolinking from the linker command line.
- Source code compatibility, where possible, with "comment lib" pragmas in other
  environments (MSVC in particular).

Dependent library support is implemented differently for ELF platforms than on
the other platforms. Primarily this difference is that on ELF we pass the
dependent library specifiers directly to the linker without manipulating them.
This is in contrast to other platforms where they are mapped to a specific
linker option by the compiler. This difference is a result of the greater
variety of ELF linkers and the fact that ELF linkers tend to handle libraries in
a more complicated fashion than on other platforms. This forces us to defer
handling the specifiers to the linker.

In order to achieve a level of source code compatibility with other platforms
we have restricted this feature to work with libraries that meet the following
"reasonable" requirements:

1. There are no competing defined symbols in a given set of libraries, or
   if they exist, the program owner doesn't care which is linked to their
   program.
2. There may be circular dependencies between libraries.

The binary representation is a mergeable string section (SHF_MERGE,
SHF_STRINGS), called .deplibs, with custom type SHT_LLVM_DEPENDENT_LIBRARIES
(0x6fff4c04). The compiler forms this section by concatenating the arguments of
the "comment lib" pragmas and --dependent-library options in the order they are
encountered. Partial (-r, -Ur) links are handled by concatenating .deplibs
sections with the normal mergeable string section rules. As an example, #pragma
comment(lib, "foo") would result in:

.section ".deplibs","MS",@llvm_dependent_libraries,1
 .asciz "foo"

For LTO, equivalent information to the contents of a the .deplibs section can be
retrieved by the LLD for bitcode input files.

LLD processes the dependent library specifiers in the following way:

1. Dependent libraries which are found from the specifiers in .deplibs sections
   of relocatable object files are added when the linker decides to include that
   file (which could itself be in a library) in the link. Dependent libraries
   behave as if they were appended to the command line after all other options. 
As
   a consequence the set of dependent libraries are searched last to resolve
   symbols.
2. It is an error if a file cannot be found for a given specifier.
3. Any command line options in effect at the end of the command line parsing 
apply
   to the dependent libraries, e.g. --whole-archive.
4. The linker tries to add a library or relocatable object file from each of the
   strings in a .deplibs section by; first, handling the string as if it was
   specified on the command line; second, by looking for the string in each of 
the
   library search paths in turn; third, by looking for a lib.a or
   lib.so (depending on the current mode of the linker) in each of the
   library search paths.
5. A new command line option --no-dependent-libraries tells LLD to ignore the
   dependent libraries.

Rationale for the above points:

1. Adding the dependent libraries last makes the process simple to understand
   from a developers perspective. All linkers are able to implement this scheme.
2. Error-ing for libraries that are not found seems like better behavior than
   failing the link during symbol resolution.
3. It seems useful for the user to be able to apply command line options which
   will affect all of the dependent libraries. There is a potential problem of
   surprise for developers, who might not realize that these options would apply
   to these "invisible" input files; however, despite the potential for 
surprise,
   this is easy for developers to reason about and gives developers the control
   that they may require.
4. This algorithm takes into account all of the different ways that ELF linkers
   find input files. The different search methods are tried by the linker in 
most
   obvious to least obvious order.
5. I considered adding finer grained control over which dependent libraries were
   ignored (e.g. MSVC has /nodefaultlib:); however, I concluded t

[PATCH] D62009: [clang] perform semantic checking in constant context

2019-05-17 Thread Tyker via Phabricator via cfe-commits
Tyker added a comment.

I checked how we can propagate the information about constant context through 
semantic checking.
there are issues with using ConstantExpr to mark expressions as constant for 
semantic checking:

- #1 multpile Expr::Ignore* operation remove ConstantExpr from the expression.
- #2 Semantic checking Traverses the AST so all methods that only mark the 
top-level Node not will fail.
- #3 at short term: adding ConstantExpr modifies the AST structure, so adding 
it everywhere it is needed for semantic checking will require changing a lot of 
code that depend closely on the AST structure.

Note: the limitation #2 also applies to the bit in ExprBitfield solution in its 
current form.

propagating constant context to the expression evaluator via a boolean value 
will be a lot of boilerplate and in my opinion this should be propagated more 
"automatically".
 so I think the best solutions are:

- push a ExpressionEvaluationContext::ConstantEvaluated so Sema will propagate 
it and propagate from Sema to the expression evaluator via boolean values.
- put all semantic checking function's in a SemaCheckContext class and 
propagate via this class to the expression evaluator. this class will be usable 
to propagate Sema and probably other informations.
- keep the bit in ExprBitfield but make all nodes created in 
ExpressionEvaluationContext::ConstantEvaluated marked for constant evaluation 
to fixes limitation #2.


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

https://reviews.llvm.org/D62009



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


Re: r360946 - Add Clang shared library with C++ exports

2019-05-17 Thread Nico Weber via cfe-commits
Thanks! Bots are happy with the reland. Thanks for taking the time to
explain the object library stuff!

*From: *Chris Bieneman 
*Date: *Thu, May 16, 2019 at 11:24 PM
*To: *Nico Weber
*Cc: *cfe-commits

I’ll re-land disabling if PIC is off.
>
> This doesn’t replace the static libraries with object libraries, it just
> creates an object library target (named obj.${name}) for each static
> library. That allows the objects to be referenced separately from the
> archives, so we don’t have to do the -load-all/—whole-archive stuff we do
> for libLLVM.
>
> -Chris
>
> On May 16, 2019, at 6:40 PM, Nico Weber  wrote:
>
> To not keep the build broken over night, and since it's a small change
> that should be easy to reland, I've reverted this for now in r360973.
>
> On Thu, May 16, 2019 at 8:52 PM Nico Weber  wrote:
>
>> Hello,
>>
>> this breaks building with -DLLVM_ENABLE_PIC=OFF. Maybe the new target
>> shouldn't be build in those builds?
>>
>>
>> Also, if I read this right, this makes static libraries for clang always
>> be object libraries. Is that correct? If so, this likely makes the normal
>> clang binary larger and less efficient than before: Normal static libraries
>> only get referenced .o files in them loaded, while all files in object
>> libraries are loaded by the linker. In theory, --gc-sections should drop
>> the ones that aren't needed, but due to static initializers and so on that
>> doesn't always work. (When we moved Chrome's build to GN, the thinking was
>> for a long time that we'd use object libraries instead of static libraries
>> everywhere. Turns out that made the binary 10% larger and slower and we had
>> to paddle back.)
>>
>>
>>
>> [2523/2887] Linking CXX shared library lib/libclang_shared.so.9svn
>> FAILED: lib/libclang_shared.so.9svn
>> ...
>> /usr/bin/ld:
>> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:
>> relocation R_X86_64_32 against
>> `.rodata._ZZNR4llvm15optional_detail15OptionalStorageIiLb1EE8getValueEvE19__PRETTY_FUNCTION__'
>> can not be used when making a shared object; recompile with -fPIC
>> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:
>> error adding symbols: Bad value
>> collect2: error: ld returned 1 exit status
>>
>> On Thu, May 16, 2019 at 6:03 PM Chris Bieneman via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: cbieneman
>>> Date: Thu May 16 15:06:07 2019
>>> New Revision: 360946
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=360946&view=rev
>>> Log:
>>> Add Clang shared library with C++ exports
>>>
>>> Summary:
>>> This patch adds a libClang_shared library on *nix systems which exports
>>> the entire C++ API. In order to support this on Windows we should really
>>> refactor llvm-shlib and share code between the two.
>>>
>>> This also uses a slightly different method for generating the shared
>>> library, which I should back-port to llvm-shlib. Instead of linking the
>>> static archives and passing linker flags to force loading the whole
>>> libraries, this patch creates object libraries for every library (which has
>>> no cost in the build system), and link the object libraries.
>>>
>>> Reviewers: tstellar, winksaville
>>>
>>> Subscribers: mgorny, cfe-commits
>>>
>>> Tags: #clang
>>>
>>> Differential Revision: https://reviews.llvm.org/D61909
>>>
>>> Added:
>>> cfe/trunk/tools/clang-shlib/
>>> cfe/trunk/tools/clang-shlib/CMakeLists.txt
>>> cfe/trunk/tools/clang-shlib/clang-shlib.cpp
>>> Modified:
>>> cfe/trunk/cmake/modules/AddClang.cmake
>>> cfe/trunk/tools/CMakeLists.txt
>>>
>>> Modified: cfe/trunk/cmake/modules/AddClang.cmake
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946&r1=360945&r2=360946&view=diff
>>>
>>> ==
>>> --- cfe/trunk/cmake/modules/AddClang.cmake (original)
>>> +++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 15:06:07 2019
>>> @@ -81,9 +81,12 @@ macro(add_clang_library name)
>>>)
>>>endif()
>>>if(ARG_SHARED)
>>> -set(ARG_ENABLE_SHARED SHARED)
>>> +set(LIBTYPE SHARED)
>>> +  else()
>>> +set(LIBTYPE STATIC OBJECT)
>>> +set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
>>>endif()
>>> -  llvm_add_library(${name} ${ARG_ENABLE_SHARED}
>>> ${ARG_UNPARSED_ARGUMENTS} ${srcs})
>>> +  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
>>>
>>>if(TARGET ${name})
>>>  target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
>>>
>>> Modified: cfe/trunk/tools/CMakeLists.txt
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360946&r1=360945&r2=360946&view=diff
>>>
>>> ==
>>> --- cfe/trunk/tools/CMakeLists.txt (original)
>>> +++ cfe/trunk/tools/CMakeLists.txt Thu May 16 15:06:07 2019
>>> @@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
>>>
>>>  add_clang_

[PATCH] D61837: Make it possible control matcher traversal kind with ASTContext

2019-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire marked an inline comment as done.
steveire added inline comments.



Comment at: lib/ASTMatchers/ASTMatchersInternal.cpp:240
+
+  assert(RestrictKind.isBaseOf(NodeKind));
+  if (Implementation->dynMatches(N, Finder, Builder)) {

aaron.ballman wrote:
> Add an assertion message?
Saying what? The original code doesn't have one. Let's avoid round trips in 
review comments :).


Repository:
  rC Clang

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

https://reviews.llvm.org/D61837



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


[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-17 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

This LGTM me, @tra or @efriedma any objections?


Repository:
  rC Clang

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

https://reviews.llvm.org/D62046



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


[PATCH] D61835: Extract ASTDumper to a header file

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

In D61835#1505388 , @steveire wrote:

> In D61835#1505314 , @aaron.ballman 
> wrote:
>
> > In D61835#1505280 , @steveire 
> > wrote:
> >
> > > In D61835#1505228 , 
> > > @aaron.ballman wrote:
> > >
> > > > In D61835#1505202 , @steveire 
> > > > wrote:
> > > >
> > > > > 3. Anyone who wants traversal in the same way that dumping is done 
> > > > > and who needs to call API on the instance which is provided by 
> > > > > ASTNodeTraverser (which ASTDumper inherits) needs to use ASTDumper. 
> > > > > For example my UI. See my EuroLLVM talk for more: 
> > > > > https://steveire.wordpress.com/2019/04/30/the-future-of-ast-matching-refactoring-tools-eurollvm-and-accu/
> > > >
> > > >
> > > > Do they? Why is the `ASTNodeTraverser` insufficient?
> > >
> > >
> > > It doesn't have the same behavior as `ASTDumper`, because `ASTDumper` 
> > > "overrides" some `Visit` metthods.
> >
> >
> > I'm aware that they're different, but I may not have been sufficiently 
> > clear. I'm saying that the only public APIs I think a user should be 
> > calling are inherited from `ASTNodeTraverser` and not `ASTDumper`, so it is 
> > not required to expose `ASTDumper` directly, only a way to get an 
> > `ASTNodeTraverser` reference/pointer to an `ASTDumper` instance so that you 
> > get the correct virtual dispatch. e.g., `ASTNodeTraverser 
> > *getSomethingThatActsLikeAnASTDumper() { return new ASTDumper; }`
>
>
> Perhaps. One way to implement the 'less noise' version of AST output (ie 
> removing pointer addresses etc http://ce.steveire.com/z/HaCLeO ) is to make 
> it an API on the `TextNodeDumper`. Then `ASTDumper` would need a forwarding 
> API for it.
>
> Anyway, your argument also applies to `JSONNodeDumper`, but you put that in a 
> header file.


Yeah, and I was unhappy about doing so, but the alternative was to put it into 
ASTDumper.cpp as a local class and that felt even worse.

> That was sane. We should move `ASTDumper` to a header similarly. (Perhaps a 
> rename of the class would help though?)

Yeah, I'd be fine with renaming it to be a bit less general than `ASTDumper`.

This LGTM. It's not a particularly clean interface, but I can see the utility 
in exposing it for D62056 .


Repository:
  rC Clang

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

https://reviews.llvm.org/D61835



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


[PATCH] D61335: [LibTooling] Add support to Transformer for composing rules as an ordered choice.

2019-05-17 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 2 inline comments as done.
ymandel added inline comments.



Comment at: clang/include/clang/Tooling/Refactoring/Transformer.h:278
+/// Builds the matcher needed for registration.
+ast_matchers::internal::DynTypedMatcher buildMatcher(const RewriteRule &Rule);
+

ilya-biryukov wrote:
> ymandel wrote:
> > ilya-biryukov wrote:
> > > Can it be declared in `.cpp` file instead? Or is it used in `clang-tidy` 
> > > integration? 
> > `buildMatcher` and `findSelectedCase` will be used in the clang-tidy 
> > integration and in the apply-rule-to-single-node function that I'm planning.
> I'd say this makes these functions a public interface of rewrite rule, albeit 
> it's an "advanced" use-case.
> It's probably ok to keep them in `detail` namespace for now, but would be 
> nice to come up with a proper public functions that allow us to implement 
> those use-cases.
> (Or declare these function public and well-supported and move them out of 
> `detail` at some point)
Agreed. I noted this explicitly with a FIXME, reworded the comments to 
explicitly associate these with `RewriteRule` and moved them to immediately 
after the other `RewriteRule` functions.  `Transformer` is now the last 
declaration in the file (and should probably be split into its own header at 
this point, being just one interpreter of `RewriteRule` among many).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61335



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


[PATCH] D61335: [LibTooling] Add support to Transformer for composing rules as an ordered choice.

2019-05-17 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 200026.
ymandel marked 2 inline comments as done.
ymandel added a comment.

updated comments; moved some decls.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61335

Files:
  clang/include/clang/Tooling/Refactoring/Transformer.h
  clang/lib/Tooling/Refactoring/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -116,7 +116,8 @@
 };
   }
 
-  void testRule(RewriteRule Rule, StringRef Input, StringRef Expected) {
+  template 
+  void testRule(R Rule, StringRef Input, StringRef Expected) {
 Transformer T(std::move(Rule), consumer());
 T.registerMatchers(&MatchFinder);
 compareSnippets(Expected, rewrite(Input));
@@ -147,7 +148,7 @@
  .bind(StringExpr)),
   callee(cxxMethodDecl(hasName("c_str")),
   change("REPLACED"));
-  R.Explanation = text("Use size() method directly on string.");
+  R.Cases[0].Explanation = text("Use size() method directly on string.");
   return R;
 }
 
@@ -375,6 +376,92 @@
Input, Expected);
 }
 
+TEST_F(TransformerTest, OrderedRuleUnrelated) {
+  StringRef Flag = "flag";
+  RewriteRule FlagRule = makeRule(
+  cxxMemberCallExpr(on(expr(hasType(cxxRecordDecl(
+hasName("proto::ProtoCommandLineFlag"
+   .bind(Flag)),
+unless(callee(cxxMethodDecl(hasName("GetProto"),
+  change(Flag, "PROTO"));
+
+  std::string Input = R"cc(
+proto::ProtoCommandLineFlag flag;
+int x = flag.foo();
+int y = flag.GetProto().foo();
+int f(string s) { return strlen(s.c_str()); }
+  )cc";
+  std::string Expected = R"cc(
+proto::ProtoCommandLineFlag flag;
+int x = PROTO.foo();
+int y = flag.GetProto().foo();
+int f(string s) { return REPLACED; }
+  )cc";
+
+  testRule(applyFirst({ruleStrlenSize(), FlagRule}), Input, Expected);
+}
+
+// Version of ruleStrlenSizeAny that inserts a method with a different name than
+// ruleStrlenSize, so we can tell their effect apart.
+RewriteRule ruleStrlenSizeDistinct() {
+  StringRef S;
+  return makeRule(
+  callExpr(callee(functionDecl(hasName("strlen"))),
+   hasArgument(0, cxxMemberCallExpr(
+  on(expr().bind(S)),
+  callee(cxxMethodDecl(hasName("c_str")),
+  change("DISTINCT"));
+}
+
+TEST_F(TransformerTest, OrderedRuleRelated) {
+  std::string Input = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return strlen(s.c_str()); }
+}  // namespace foo
+int g(string s) { return strlen(s.c_str()); }
+  )cc";
+  std::string Expected = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return DISTINCT; }
+}  // namespace foo
+int g(string s) { return REPLACED; }
+  )cc";
+
+  testRule(applyFirst({ruleStrlenSize(), ruleStrlenSizeDistinct()}), Input,
+   Expected);
+}
+
+// Change the order of the rules to get a different result.
+TEST_F(TransformerTest, OrderedRuleRelatedSwapped) {
+  std::string Input = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return strlen(s.c_str()); }
+}  // namespace foo
+int g(string s) { return strlen(s.c_str()); }
+  )cc";
+  std::string Expected = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return DISTINCT; }
+}  // namespace foo
+int g(string s) { return DISTINCT; }
+  )cc";
+
+  testRule(applyFirst({ruleStrlenSizeDistinct(), ruleStrlenSize()}), Input,
+   Expected);
+}
+
 //
 // Negative tests (where we expect no transformation to occur).
 //
Index: clang/lib/Tooling/Refactoring/Transformer.cpp
===
--- clang/lib/Tooling/Refactoring/Transformer.cpp
+++ clang/lib/Tooling/Refactoring/Transformer.cpp
@@ -28,6 +28,7 @@
 using namespace tooling;
 
 using ast_matchers::MatchFinder;
+using ast_matchers::internal::DynTypedMatcher;
 using ast_type_traits::ASTNodeKind;
 using ast_type_traits::DynTypedNode;
 using llvm::Error;
@@ -144,9 +145,9 @@
   llvm_unreachable("Unexpected case in NodePart type.");
 }
 
-Expected>
-tooling::translateEdits(const MatchResult &Result,
-llvm::ArrayRef Edits) {
+Expected>
+tooling::detail::translateEdits(const MatchResult &Result,
+llvm::ArrayRef Edits) {
   SmallVector Transformations;
   auto &NodesMap = Result.Nodes.getMap();
   for (const auto &Edit : Edits) {
@@ -1

Re: r361011 - [analyzer] Validate checker option names and values

2019-05-17 Thread Nico Weber via cfe-commits
It looks like this change is making gcc-7 crash on these (and other
http://lab.llvm.org:8011/console) bots:

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/18639
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/33837/

[100/212] Building CXX object
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o
FAILED:
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[101/212] Building CXX object
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersTraversalTest.cpp.o
FAILED:
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersTraversalTest.cpp.o

...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[102/212] Building CXX object
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNarrowingTest.cpp.o
FAILED:
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNarrowingTest.cpp.o

...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[103/212] Building CXX object
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNodeTest.cpp.o
FAILED:
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNodeTest.cpp.o

...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[104/212] Building CXX object
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/CommentHandlerTest.cpp.o
FAILED:
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/CommentHandlerTest.cpp.o

...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[105/212] Building CXX object
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ExecutionTest.cpp.o
FAILED:
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ExecutionTest.cpp.o

...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[106/212] Building CXX object
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterVisibilityTest.cpp.o
FAILED:
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterVisibilityTest.cpp.o

...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.

*From: *Kristof Umann via cfe-commits 
*Date: *Fri, May 17, 2019 at 5:49 AM
*To: * 

Author: szelethus
> Date: Fri May 17 02:51:59 2019
> New Revision: 361011
>
> URL: http://llvm.org/viewvc/llvm-project?rev=361011&view=rev
> Log:
> [analyzer] Validate checker option names and values
>
> Validate whether the option exists, and also whether the supplied value is
> of
> the correct type. With this patch, invoking the analyzer should be, at
> least
> in the frontend mode, a lot safer.
>
> Differential Revision: https://reviews.llvm.org/D57860
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
> cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
> cfe/trunk/test/Analysis/checker-plugins.c
> cfe/trunk/test/Analysis/invalid-checker-option.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=361011&r1=361010&r2=361011&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Fri May 17
> 02:51:59 2019
> @@ -307,6 +307,8 @@ def err_analyzer_config_multiple_values
>  def err_analyzer_config_invalid_input : Error<
>"invalid input for analyzer-config option '%0', that expects %1 value">;
>  def err_analyzer_config_unknown : Error<"unknown analyzer-config '%0'">;
> +def err_analyzer_checker_option_unknown : Error<
> +  "checker '%0' has no option called '%1'">;
>  def err_analyzer_checker_option_invalid_input : Error<
>"invalid input for checker option '%0', that expects %1">;
>
>
> Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h?rev=361011&r1=361010&r2=361011&view=diff
>
> ==
> --- cfe/trunk/include/clang/StaticAnalyzer/Fron

[PATCH] D59887: [Syntax] Introduce TokenBuffer, start clangToolingSyntax library

2019-05-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 200030.
ilya-biryukov added a comment.

- Skip annotation tokens, some of them are reported by the preprocessor but we 
don't want them in the final expanded stream.
- Add functions to compute FileRange of tokens, add tests for it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59887

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/Syntax/CMakeLists.txt
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/Syntax/CMakeLists.txt
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -0,0 +1,672 @@
+//===- TokensTest.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
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Tokens.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/Expr.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.def"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/Utils.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/raw_os_ostream.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock-more-matchers.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang;
+using namespace clang::syntax;
+
+using llvm::ValueIs;
+using ::testing::AllOf;
+using ::testing::Contains;
+using ::testing::ElementsAre;
+using ::testing::Matcher;
+using ::testing::Not;
+using ::testing::StartsWith;
+
+namespace {
+// Checks the passed ArrayRef has the same begin() and end() iterators as the
+// argument.
+MATCHER_P(SameRange, A, "") {
+  return A.begin() == arg.begin() && A.end() == arg.end();
+}
+// Matchers for syntax::Token.
+MATCHER_P(Kind, K, "") { return arg.kind() == K; }
+MATCHER_P2(HasText, Text, SourceMgr, "") {
+  return arg.text(*SourceMgr) == Text;
+}
+/// Checks the start and end location of a token are equal to SourceRng.
+MATCHER_P(RangeIs, SourceRng, "") {
+  return arg.location() == SourceRng.first &&
+ arg.endLocation() == SourceRng.second;
+}
+
+class TokenCollectorTest : public ::testing::Test {
+public:
+  /// Run the clang frontend, collect the preprocessed tokens from the frontend
+  /// invocation and store them in this->Buffer.
+  /// This also clears SourceManager before running the compiler.
+  void recordTokens(llvm::StringRef Code) {
+class RecordTokens : public ASTFrontendAction {
+public:
+  explicit RecordTokens(TokenBuffer &Result) : Result(Result) {}
+
+  bool BeginSourceFileAction(CompilerInstance &CI) override {
+assert(!Collector && "expected only a single call to BeginSourceFile");
+Collector.emplace(CI.getPreprocessor());
+return true;
+  }
+  void EndSourceFileAction() override {
+assert(Collector && "BeginSourceFileAction was never called");
+Result = std::move(*Collector).consume();
+  }
+
+  std::unique_ptr
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+return llvm::make_unique();
+  }
+
+private:
+  TokenBuffer &Result;
+  llvm::Optional Collector;
+};
+
+constexpr const char *FileName = "./input.cpp";
+FS->addFile(FileName, time_t(), llvm::MemoryBuffer::getMemBufferCopy(""));
+// Prepare to run a compiler.
+std::vector Args = {"tok-test", "-std=c++03", "-fsyntax-only",
+  FileName};
+auto CI = createInvocationFromCom

[PATCH] D61837: Make it possible control matcher traversal kind with ASTContext

2019-05-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/AST/ASTContext.cpp:120
+ASTContext::TraverseIgnored(const ast_type_traits::DynTypedNode &N) {
+  if (auto E = N.get()) {
+return ast_type_traits::DynTypedNode::create(*TraverseIgnored(E));

aaron.ballman wrote:
> `auto *`
The formatting is wrong here -- be sure to run the patch through clang-format 
before committing.



Comment at: lib/ASTMatchers/ASTMatchersInternal.cpp:240
+
+  assert(RestrictKind.isBaseOf(NodeKind));
+  if (Implementation->dynMatches(N, Finder, Builder)) {

steveire wrote:
> aaron.ballman wrote:
> > Add an assertion message?
> Saying what? The original code doesn't have one. Let's avoid round trips in 
> review comments :).
This isn't a "round trip"; it's not unreasonable to ask people to NFC improve 
the code they're touching (it's akin to saying "Because you figured out this 
complex piece of code does X, can you add a comment to it so others don't have 
to do that work next time.").

As best I can tell, this assertion exists because this function is meant to 
mirror `matches()` without this base check in release mode. You've lost that 
mirroring with your refactoring, which looks suspicious. Is there a reason this 
function deviates from `matches()` now?

As for the assertion message itself, how about "matched a node of an unexpected 
derived kind"?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61837



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


[PATCH] D61333: [ASTImporter] Fix LLDB lookup in transparent ctx and with ext src

2019-05-17 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 200031.
martong added a comment.

- Rebase to master
- Rebase to D62061 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61333

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  lldb/packages/Python/lldbsuite/test/lang/c/ast/Makefile
  lldb/packages/Python/lldbsuite/test/lang/c/ast/TestAST.py
  lldb/packages/Python/lldbsuite/test/lang/c/ast/main.c
  lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -637,18 +637,6 @@
 
 m_ast_importer_sp->RequireCompleteType(copied_field_type);
   }
-
-  DeclContext *decl_context_non_const =
-  const_cast(decl_context);
-
-  if (copied_decl->getDeclContext() != decl_context) {
-if (copied_decl->getDeclContext()->containsDecl(copied_decl))
-  copied_decl->getDeclContext()->removeDecl(copied_decl);
-copied_decl->setDeclContext(decl_context_non_const);
-  }
-
-  if (!decl_context_non_const->containsDecl(copied_decl))
-decl_context_non_const->addDeclInternal(copied_decl);
 }
   }
 
Index: lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
===
--- lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
+++ lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
@@ -5,11 +5,11 @@
 typedef struct {
 int a;
 int b;
-} FILE;
+} MYFILE;
 
 int main()
 {
-FILE *myFile = malloc(sizeof(FILE));
+MYFILE *myFile = malloc(sizeof(MYFILE));
 
 myFile->a = 5;
 myFile->b = 9;
Index: lldb/packages/Python/lldbsuite/test/lang/c/ast/main.c
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/ast/main.c
@@ -0,0 +1,5 @@
+int main()
+{
+int a = 0; // Set breakpoint 0 here.
+return 0;
+}
Index: lldb/packages/Python/lldbsuite/test/lang/c/ast/TestAST.py
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/ast/TestAST.py
@@ -0,0 +1,77 @@
+"""Test that importing modules in C works as expected."""
+
+from __future__ import print_function
+
+
+from distutils.version import StrictVersion
+import os
+import time
+import platform
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class CModulesTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIfFreeBSD
+@skipIfLinux
+@skipIfWindows
+@skipIfNetBSD
+@skipIf(macos_version=["<", "10.12"])
+def test_expr(self):
+self.build()
+exe = self.getBuildArtifact("a.out")
+self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
+
+self.runCmd("run", RUN_SUCCEEDED)
+
+# The stop reason of the thread should be breakpoint.
+self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+substrs=['stopped',
+ 'stop reason = breakpoint'])
+
+# The breakpoint should have a hit count of 1.
+self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
+substrs=[' resolved, hit count = 1'])
+
+# Enable logging of the imported AST.
+log_file = os.path.join(self.getBuildDir(), "lldb-ast-log.txt")
+self.runCmd("log enable lldb ast -f '%s'" % log_file)
+
+self.expect(
+"expr -l objc++ -- @import Darwin; 3",
+VARIABLES_DISPLAYED_CORRECTLY,
+substrs=[
+"int",
+"3"])
+
+# This expr command imports __sFILE with definition
+# (FILE is a typedef to __sFILE.)
+self.expect(
+"expr *fopen(\"/dev/zero\", \"w\")",
+VARIABLES_DISPLAYED_CORRECTLY,
+substrs=[
+"FILE",
+"_close"]
+)
+
+# Check that the AST log contains exactly one definition of __sFILE.
+f = open(log_file)
+log_lines = f.readlines()
+f.close()
+os.remove(log_file)
+self.assertEqual(" ".join(log_lines).count("struct __sFILE definition"), 1)
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Find the line number to break inside main().
+self.line = line_number('main.c', '// Set breakpoint 0 here.')
Index: lldb/pack

[PATCH] D61333: [ASTImporter] Fix LLDB lookup in transparent ctx and with ext src

2019-05-17 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added inline comments.



Comment at: lldb/source/Symbol/ClangASTImporter.cpp:922
+
+  Log *log_ast(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_AST));
+  if (log_ast) {

shafik wrote:
> I am going to say that the logging change is an excellent additions and 
> stands alone from this change. Although I realize the test depends on this 
> new feature. It makes sense to add the logging in a separate PR.
> 
> I also say this b/c I found a regression and it would be nice to get the 
> logging in while we resolve the regression.
Ok, I have created a new patch for logging (https://reviews.llvm.org/D62061).
I made this patch to be the child of that and rebased to that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61333



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


[PATCH] D61333: [ASTImporter] Fix LLDB lookup in transparent ctx and with ext src

2019-05-17 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 200033.
martong added a comment.

- se -> so


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61333

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  lldb/packages/Python/lldbsuite/test/lang/c/ast/Makefile
  lldb/packages/Python/lldbsuite/test/lang/c/ast/TestAST.py
  lldb/packages/Python/lldbsuite/test/lang/c/ast/main.c
  lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -637,18 +637,6 @@
 
 m_ast_importer_sp->RequireCompleteType(copied_field_type);
   }
-
-  DeclContext *decl_context_non_const =
-  const_cast(decl_context);
-
-  if (copied_decl->getDeclContext() != decl_context) {
-if (copied_decl->getDeclContext()->containsDecl(copied_decl))
-  copied_decl->getDeclContext()->removeDecl(copied_decl);
-copied_decl->setDeclContext(decl_context_non_const);
-  }
-
-  if (!decl_context_non_const->containsDecl(copied_decl))
-decl_context_non_const->addDeclInternal(copied_decl);
 }
   }
 
Index: lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
===
--- lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
+++ lldb/packages/Python/lldbsuite/test/lang/c/modules/main.c
@@ -5,11 +5,11 @@
 typedef struct {
 int a;
 int b;
-} FILE;
+} MYFILE;
 
 int main()
 {
-FILE *myFile = malloc(sizeof(FILE));
+MYFILE *myFile = malloc(sizeof(MYFILE));
 
 myFile->a = 5;
 myFile->b = 9;
Index: lldb/packages/Python/lldbsuite/test/lang/c/ast/main.c
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/ast/main.c
@@ -0,0 +1,5 @@
+int main()
+{
+int a = 0; // Set breakpoint 0 here.
+return 0;
+}
Index: lldb/packages/Python/lldbsuite/test/lang/c/ast/TestAST.py
===
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/ast/TestAST.py
@@ -0,0 +1,77 @@
+"""Test that importing modules in C works as expected."""
+
+from __future__ import print_function
+
+
+from distutils.version import StrictVersion
+import os
+import time
+import platform
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class CModulesTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+@skipIfFreeBSD
+@skipIfLinux
+@skipIfWindows
+@skipIfNetBSD
+@skipIf(macos_version=["<", "10.12"])
+def test_expr(self):
+self.build()
+exe = self.getBuildArtifact("a.out")
+self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
+
+self.runCmd("run", RUN_SUCCEEDED)
+
+# The stop reason of the thread should be breakpoint.
+self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+substrs=['stopped',
+ 'stop reason = breakpoint'])
+
+# The breakpoint should have a hit count of 1.
+self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
+substrs=[' resolved, hit count = 1'])
+
+# Enable logging of the imported AST.
+log_file = os.path.join(self.getBuildDir(), "lldb-ast-log.txt")
+self.runCmd("log enable lldb ast -f '%s'" % log_file)
+
+self.expect(
+"expr -l objc++ -- @import Darwin; 3",
+VARIABLES_DISPLAYED_CORRECTLY,
+substrs=[
+"int",
+"3"])
+
+# This expr command imports __sFILE with definition
+# (FILE is a typedef to __sFILE.)
+self.expect(
+"expr *fopen(\"/dev/zero\", \"w\")",
+VARIABLES_DISPLAYED_CORRECTLY,
+substrs=[
+"FILE",
+"_close"]
+)
+
+# Check that the AST log contains exactly one definition of __sFILE.
+f = open(log_file)
+log_lines = f.readlines()
+f.close()
+os.remove(log_file)
+self.assertEqual(" ".join(log_lines).count("struct __sFILE definition"), 1)
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Find the line number to break inside main().
+self.line = line_number('main.c', '// Set breakpoint 0 here.')
Index: lldb/packages/Python/lldbsuite/test/lang/c/ast/Makefile
==

[PATCH] D61743: New clang option -MD-filter=prefix to filter files from make dependencies

2019-05-17 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

@dexonsmith Can you take a look at this patch or recommend someone who can 
review it?  Many thanks. --Melanie


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

https://reviews.llvm.org/D61743



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


[PATCH] D61834: Add a Visit overload for DynTypedNode to ASTNodeTraverser

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

In D61834#1505418 , @steveire wrote:

> In D61834#1505124 , @aaron.ballman 
> wrote:
>
> > In D61834#1505056 , @steveire 
> > wrote:
> >
> > > In D61834#1504665 , 
> > > @aaron.ballman wrote:
> > >
> > > > What will be making use of/testing this new functionality?
> > >
> > >
> > > Any code which has a `DynTypedNode` and wishes to traverse it.
> > >
> > > I envisage this as a more-flexible `DynTypedNode::dump` that the user 
> > > does not have to implement themselves in order to use the 
> > > `ASTNodeTraverser`.
> >
> >
> > Do we currently have any such code that's using this functionality, though? 
> > I'm mostly concerned that this is dead code with no testing, currently. The 
> > functionality itself seems reasonable enough and the code looks correct 
> > enough, so if this is part of a series of planned changes, that'd be good 
> > information to have for the review.
>
>
> Ah, yes. This is supposed to be 'useful public API' like the other Visit 
> methods for use inside and outside the codebase. A follow-up patch will use 
> it, but it's provided for external use too anyway.
>
> I'll add a unit test.


Ahh, thank you! It makes a lot more sense to me now. LGTM aside from some nits.




Comment at: include/clang/AST/ASTNodeTraverser.h:208
 
+  void Visit(const ast_type_traits::DynTypedNode &N) {
+if (const auto *D = N.get())

Can you add a comment here: `// FIXME: Improve this with a switch or a visitor 
pattern.` (We have a similar comment in similar-looking code in 
ASTMatchFinder.cpp:476.)



Comment at: unittests/AST/ASTTraverserTest.cpp:75
+
+template  std::string dumpASTString(NodeType &&... N) {
+  std::string Buffer;

Did clang-format produce this formatting? (If not, run through clang-format.)



Comment at: unittests/AST/ASTTraverserTest.cpp:89
+const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,
+const std::string &name) {
+  auto Result = ast_matchers::match(functionDecl(hasName(name)).bind("fn"),

`Name` instead



Comment at: unittests/AST/ASTTraverserTest.cpp:97
+template  struct Verifier {
+  static void withDynNode(T Node, const std::string &dumpString) {
+EXPECT_EQ(dumpASTString(ast_type_traits::DynTypedNode::create(Node)),

`DumpString` -- same elsewhere.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61834



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


r361032 - Fix Wdocumentation warnings. NFCI.

2019-05-17 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Fri May 17 06:42:16 2019
New Revision: 361032

URL: http://llvm.org/viewvc/llvm-project?rev=361032&view=rev
Log:
Fix Wdocumentation warnings. NFCI.

Modified:
cfe/trunk/include/clang/Sema/Sema.h

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=361032&r1=361031&r2=361032&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri May 17 06:42:16 2019
@@ -4618,11 +4618,7 @@ public:
 SourceLocation BuiltinLoc,
 SourceLocation RPLoc);
 
-  /// Build a potentially resolved SourceLocExpr.
-  ///
-  /// \param SubExpr - null when the SourceLocExpr is unresolved, otherwise
-  /// SubExpr will be a literal expression representing the value of the
-  /// builtin call.
+  // Build a potentially resolved SourceLocExpr.
   ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
 SourceLocation BuiltinLoc, SourceLocation 
RPLoc,
 DeclContext *ParentContext);


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


[PATCH] D59628: Add support for __attribute__((objc_class_stub))

2019-05-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:292
+  // "LangOpts" bound.
+  string CustomCode = customCode;
 }

If this is code, should it be using a `code` type rather than a `string` type?



Comment at: clang/include/clang/Basic/AttrDocs.td:1101
+implementations defined for them. This attribute is intended for use in
+Swift generated headers for classes defined in Swift.
+

Swift generated -> Swift-generated



Comment at: clang/lib/CodeGen/CGObjCMac.cpp:736
+llvm::Type *params[] = { Int8PtrPtrTy };
+auto F = CGM.CreateRuntimeFunction(
+llvm::FunctionType::get(ClassnfABIPtrTy, params, false),

Please spell the type out explicitly rather than use `auto` here.



Comment at: clang/lib/CodeGen/CGObjCMac.cpp:7325
NotForDefinition);
+  assert(ClassGV->getType() == ObjCTypes.ClassnfABIPtrTy);
 }

Can you add a message to this assertion so that when it triggers, users get 
something more helpful to report?



Comment at: clang/lib/CodeGen/CGObjCMac.cpp:7366
   if (!Entry) {
-auto ClassGV = GetClassGlobal(ID, /*metaclass*/ false, NotForDefinition);
+auto ClassGV = GetClassGlobalForClassRef(ID);
 std::string SectionName =

Can you spell out the type here, since you're changing the initialization 
already?



Comment at: clang/lib/CodeGen/CGObjCMac.cpp:7410-7411
   if (ID->isWeakImported()) {
-auto ClassGV = GetClassGlobal(ID, /*metaclass*/ false, NotForDefinition);
+llvm::Constant *ClassGV = GetClassGlobal(ID, /*metaclass*/ false,
+ NotForDefinition);
 (void)ClassGV;

I'm not opposed to this change, but it seems unrelated to the patch. Feel free 
to commit separately as an NFC.


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

https://reviews.llvm.org/D59628



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


r361033 - Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-17 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Fri May 17 06:55:28 2019
New Revision: 361033

URL: http://llvm.org/viewvc/llvm-project?rev=361033&view=rev
Log:
Add a Visit overload for DynTypedNode to ASTNodeTraverser

Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

Added:
cfe/trunk/unittests/AST/ASTTraverserTest.cpp
Modified:
cfe/trunk/include/clang/AST/ASTNodeTraverser.h
cfe/trunk/unittests/AST/CMakeLists.txt

Modified: cfe/trunk/include/clang/AST/ASTNodeTraverser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTNodeTraverser.h?rev=361033&r1=361032&r2=361033&view=diff
==
--- cfe/trunk/include/clang/AST/ASTNodeTraverser.h (original)
+++ cfe/trunk/include/clang/AST/ASTNodeTraverser.h Fri May 17 06:55:28 2019
@@ -205,6 +205,24 @@ public:
 });
   }
 
+  void Visit(const ast_type_traits::DynTypedNode &N) {
+// FIXME: Improve this with a switch or a visitor pattern.
+if (const auto *D = N.get())
+  Visit(D);
+else if (const auto *S = N.get())
+  Visit(S);
+else if (const auto *QT = N.get())
+  Visit(*QT);
+else if (const auto *T = N.get())
+  Visit(T);
+else if (const auto *C = N.get())
+  Visit(C);
+else if (const auto *C = N.get())
+  Visit(C);
+else if (const auto *T = N.get())
+  Visit(*T);
+  }
+
   void dumpDeclContext(const DeclContext *DC) {
 if (!DC)
   return;

Added: cfe/trunk/unittests/AST/ASTTraverserTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTTraverserTest.cpp?rev=361033&view=auto
==
--- cfe/trunk/unittests/AST/ASTTraverserTest.cpp (added)
+++ cfe/trunk/unittests/AST/ASTTraverserTest.cpp Fri May 17 06:55:28 2019
@@ -0,0 +1,220 @@
+//===- 
unittests/AST/ASTTraverserTest.h===//
+//
+// 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 "clang/AST/ASTContext.h"
+#include "clang/AST/ASTNodeTraverser.h"
+#include "clang/AST/TextNodeDumper.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang::tooling;
+using namespace clang::ast_matchers;
+
+namespace clang {
+
+class NodeTreePrinter : public TextTreeStructure {
+  llvm::raw_ostream &OS;
+
+public:
+  NodeTreePrinter(llvm::raw_ostream &OS)
+  : TextTreeStructure(OS, /* showColors */ false), OS(OS) {}
+
+  void Visit(const Decl *D) { OS << D->getDeclKindName() << "Decl"; }
+
+  void Visit(const Stmt *S) { OS << S->getStmtClassName(); }
+
+  void Visit(QualType QT) {
+OS << "QualType " << QT.split().Quals.getAsString();
+  }
+
+  void Visit(const Type *T) { OS << T->getTypeClassName() << "Type"; }
+
+  void Visit(const comments::Comment *C, const comments::FullComment *FC) {
+OS << C->getCommentKindName();
+  }
+
+  void Visit(const CXXCtorInitializer *Init) { OS << "CXXCtorInitializer"; }
+
+  void Visit(const Attr *A) {
+switch (A->getKind()) {
+#define ATTR(X)
\
+  case attr::X:
\
+OS << #X;  
\
+break;
+#include "clang/Basic/AttrList.inc"
+}
+OS << "Attr";
+  }
+
+  void Visit(const OMPClause *C) { OS << "OMPClause"; }
+  void Visit(const TemplateArgument &A, SourceRange R = {},
+ const Decl *From = nullptr, const char *Label = nullptr) {
+OS << "TemplateArgument";
+  }
+
+  template  void Visit(T...) {}
+};
+
+class TestASTDumper : public ASTNodeTraverser {
+
+  NodeTreePrinter MyNodeRecorder;
+
+public:
+  TestASTDumper(llvm::raw_ostream &OS) : MyNodeRecorder(OS) {}
+  NodeTreePrinter &doGetNodeDelegate() { return MyNodeRecorder; }
+};
+
+template  std::string dumpASTString(NodeType &&... N) {
+  std::string Buffer;
+  llvm::raw_string_ostream OS(Buffer);
+
+  TestASTDumper Dumper(OS);
+
+  OS << "\n";
+
+  Dumper.Visit(std::forward(N)...);
+
+  return OS.str();
+}
+
+const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,
+const std::string &Name) {
+  auto Result = ast_matchers::match(functionDecl(hasName(Name)).bind("fn"),
+AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+template  struct Verifier {
+  static void withDynNode(T Node, const std::string &DumpString) {
+EXPECT_EQ(dumpASTString(ast_type_traits::DynTypedN

[PATCH] D61834: Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire marked 5 inline comments as done.
steveire added inline comments.



Comment at: unittests/AST/ASTTraverserTest.cpp:75
+
+template  std::string dumpASTString(NodeType &&... N) {
+  std::string Buffer;

aaron.ballman wrote:
> Did clang-format produce this formatting? (If not, run through clang-format.)
Yep, clang-format made it like this.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61834



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


[PATCH] D61834: Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
steveire marked an inline comment as done.
Closed by commit rL361033: Add a Visit overload for DynTypedNode to 
ASTNodeTraverser (authored by steveire, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61834?vs=12&id=200036#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61834

Files:
  cfe/trunk/include/clang/AST/ASTNodeTraverser.h
  cfe/trunk/unittests/AST/ASTTraverserTest.cpp
  cfe/trunk/unittests/AST/CMakeLists.txt

Index: cfe/trunk/unittests/AST/CMakeLists.txt
===
--- cfe/trunk/unittests/AST/CMakeLists.txt
+++ cfe/trunk/unittests/AST/CMakeLists.txt
@@ -12,6 +12,7 @@
   ASTImporterTest.cpp
   ASTImporterGenericRedeclTest.cpp
   ASTImporterVisibilityTest.cpp
+  ASTTraverserTest.cpp
   ASTTypeTraitsTest.cpp
   ASTVectorTest.cpp
   CommentLexer.cpp
Index: cfe/trunk/unittests/AST/ASTTraverserTest.cpp
===
--- cfe/trunk/unittests/AST/ASTTraverserTest.cpp
+++ cfe/trunk/unittests/AST/ASTTraverserTest.cpp
@@ -0,0 +1,220 @@
+//===- unittests/AST/ASTTraverserTest.h===//
+//
+// 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 "clang/AST/ASTContext.h"
+#include "clang/AST/ASTNodeTraverser.h"
+#include "clang/AST/TextNodeDumper.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang::tooling;
+using namespace clang::ast_matchers;
+
+namespace clang {
+
+class NodeTreePrinter : public TextTreeStructure {
+  llvm::raw_ostream &OS;
+
+public:
+  NodeTreePrinter(llvm::raw_ostream &OS)
+  : TextTreeStructure(OS, /* showColors */ false), OS(OS) {}
+
+  void Visit(const Decl *D) { OS << D->getDeclKindName() << "Decl"; }
+
+  void Visit(const Stmt *S) { OS << S->getStmtClassName(); }
+
+  void Visit(QualType QT) {
+OS << "QualType " << QT.split().Quals.getAsString();
+  }
+
+  void Visit(const Type *T) { OS << T->getTypeClassName() << "Type"; }
+
+  void Visit(const comments::Comment *C, const comments::FullComment *FC) {
+OS << C->getCommentKindName();
+  }
+
+  void Visit(const CXXCtorInitializer *Init) { OS << "CXXCtorInitializer"; }
+
+  void Visit(const Attr *A) {
+switch (A->getKind()) {
+#define ATTR(X)\
+  case attr::X:\
+OS << #X;  \
+break;
+#include "clang/Basic/AttrList.inc"
+}
+OS << "Attr";
+  }
+
+  void Visit(const OMPClause *C) { OS << "OMPClause"; }
+  void Visit(const TemplateArgument &A, SourceRange R = {},
+ const Decl *From = nullptr, const char *Label = nullptr) {
+OS << "TemplateArgument";
+  }
+
+  template  void Visit(T...) {}
+};
+
+class TestASTDumper : public ASTNodeTraverser {
+
+  NodeTreePrinter MyNodeRecorder;
+
+public:
+  TestASTDumper(llvm::raw_ostream &OS) : MyNodeRecorder(OS) {}
+  NodeTreePrinter &doGetNodeDelegate() { return MyNodeRecorder; }
+};
+
+template  std::string dumpASTString(NodeType &&... N) {
+  std::string Buffer;
+  llvm::raw_string_ostream OS(Buffer);
+
+  TestASTDumper Dumper(OS);
+
+  OS << "\n";
+
+  Dumper.Visit(std::forward(N)...);
+
+  return OS.str();
+}
+
+const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,
+const std::string &Name) {
+  auto Result = ast_matchers::match(functionDecl(hasName(Name)).bind("fn"),
+AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+template  struct Verifier {
+  static void withDynNode(T Node, const std::string &DumpString) {
+EXPECT_EQ(dumpASTString(ast_type_traits::DynTypedNode::create(Node)),
+  DumpString);
+  }
+};
+
+template  struct Verifier {
+  static void withDynNode(T *Node, const std::string &DumpString) {
+EXPECT_EQ(dumpASTString(ast_type_traits::DynTypedNode::create(*Node)),
+  DumpString);
+  }
+};
+
+template 
+void verifyWithDynNode(T Node, const std::string &DumpString) {
+  EXPECT_EQ(dumpASTString(Node), DumpString);
+
+  Verifier::withDynNode(Node, DumpString);
+}
+
+TEST(Traverse, Dump) {
+
+  auto AST = buildASTFromCode(R"cpp(
+struct A {
+  int m_number;
+
+  /// CTor
+  A() : m_number(42) {}
+
+  [[nodiscard]] const int func() {

r361034 - Extract ASTDumper to a header file

2019-05-17 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Fri May 17 06:59:15 2019
New Revision: 361034

URL: http://llvm.org/viewvc/llvm-project?rev=361034&view=rev
Log:
Extract ASTDumper to a header file

Summary:
This class has member APIs which are useful to clients.  Make it
possible to use those APIs without adding them to dump() member
functions.  Doing so does not scale.  The optional arguments to dump()
should be designed to be useful in a debugging context.

Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

Added:
cfe/trunk/include/clang/AST/ASTDumper.h
Modified:
cfe/trunk/lib/AST/ASTDumper.cpp

Added: cfe/trunk/include/clang/AST/ASTDumper.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTDumper.h?rev=361034&view=auto
==
--- cfe/trunk/include/clang/AST/ASTDumper.h (added)
+++ cfe/trunk/include/clang/AST/ASTDumper.h Fri May 17 06:59:15 2019
@@ -0,0 +1,56 @@
+//===--- ASTDumper.h - Dumping implementation for ASTs 
===//
+//
+// 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 LLVM_CLANG_AST_ASTDUMPER_H
+#define LLVM_CLANG_AST_ASTDUMPER_H
+
+#include "clang/AST/ASTNodeTraverser.h"
+#include "clang/AST/TextNodeDumper.h"
+
+namespace clang {
+
+class ASTDumper : public ASTNodeTraverser {
+
+  TextNodeDumper NodeDumper;
+
+  raw_ostream &OS;
+
+  const bool ShowColors;
+
+public:
+  ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
+const SourceManager *SM)
+  : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) 
{}
+
+  ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
+const SourceManager *SM, bool ShowColors)
+  : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
+  ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
+const SourceManager *SM, bool ShowColors,
+const PrintingPolicy &PrintPolicy)
+  : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
+ShowColors(ShowColors) {}
+
+  TextNodeDumper &doGetNodeDelegate() { return NodeDumper; }
+
+  void dumpLookups(const DeclContext *DC, bool DumpDecls);
+
+  template 
+  void dumpTemplateDeclSpecialization(const SpecializationDecl *D,
+  bool DumpExplicitInst, bool DumpRefOnly);
+  template 
+  void dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
+
+  void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
+  void VisitClassTemplateDecl(const ClassTemplateDecl *D);
+  void VisitVarTemplateDecl(const VarTemplateDecl *D);
+};
+
+} // namespace clang
+
+#endif

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=361034&r1=361033&r2=361034&view=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Fri May 17 06:59:15 2019
@@ -11,11 +11,10 @@
 //
 
//===--===//
 
+#include "clang/AST/ASTDumper.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/ASTNodeTraverser.h"
 #include "clang/AST/DeclLookups.h"
 #include "clang/AST/JSONNodeDumper.h"
-#include "clang/AST/TextNodeDumper.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
@@ -23,50 +22,6 @@
 using namespace clang;
 using namespace clang::comments;
 
-//===--===//
-// ASTDumper Visitor
-//===--===//
-
-namespace  {
-
-class ASTDumper : public ASTNodeTraverser {
-
-  TextNodeDumper NodeDumper;
-
-  raw_ostream &OS;
-
-  const bool ShowColors;
-
-public:
-  ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
-const SourceManager *SM)
-  : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) 
{}
-
-  ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
-const SourceManager *SM, bool ShowColors)
-  : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
-  ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
-const SourceManager *SM, bool ShowColors,
-const PrintingPolicy &PrintPolicy)
-  : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
-ShowColors(ShowColors) {}
-
-  TextNodeDumper &doGetNodeDelegate() { return NodeDumper; }
-
-  void dumpLookups(const DeclContext *DC, bool DumpDecls);
-
-  template 
-  void dumpTemplateDeclSpecialization(const Spe

Re: r361011 - [analyzer] Validate checker option names and values

2019-05-17 Thread Kristof Umann via cfe-commits
I'll take a look.


From: Nico Weber 
Sent: 17 May 2019 15:09:18
To: Kristof Umann
Cc: cfe-commits
Subject: Re: r361011 - [analyzer] Validate checker option names and values

It looks like this change is making gcc-7 crash on these (and other 
http://lab.llvm.org:8011/console) bots:

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/18639
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/33837/

[100/212] Building CXX object 
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o
FAILED: tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[101/212] Building CXX object 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersTraversalTest.cpp.o
FAILED: 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersTraversalTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[102/212] Building CXX object 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNarrowingTest.cpp.o
FAILED: 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNarrowingTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[103/212] Building CXX object 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNodeTest.cpp.o
FAILED: 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNodeTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[104/212] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/CommentHandlerTest.cpp.o
FAILED: 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/CommentHandlerTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[105/212] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ExecutionTest.cpp.o
FAILED: 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ExecutionTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[106/212] Building CXX object 
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterVisibilityTest.cpp.o
FAILED: 
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterVisibilityTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.

From: Kristof Umann via cfe-commits 
mailto:cfe-commits@lists.llvm.org>>
Date: Fri, May 17, 2019 at 5:49 AM
To: mailto:cfe-commits@lists.llvm.org>>

Author: szelethus
Date: Fri May 17 02:51:59 2019
New Revision: 361011

URL: http://llvm.org/viewvc/llvm-project?rev=361011&view=rev
Log:
[analyzer] Validate checker option names and values

Validate whether the option exists, and also whether the supplied value is of
the correct type. With this patch, invoking the analyzer should be, at least
in the frontend mode, a lot safer.

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
cfe/trunk/test/Analysis/checker-plugins.c
cfe/trunk/test/Analysis/invalid-checker-option.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=361011&r1=361010&r2=361011&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Fri May 17 02:51:59 
2019
@@ -307,6 +307,8 @@ def err_analyzer_config_multiple_values
 def err_analyzer_config_invalid_input : Error<
   "invalid input for analyzer-config option '%0', that expects %1 value">;
 def err_analyzer_config_unknown : Error<"unknown analyzer-config '%0'">;
+def err_analyzer_checker_option_unknown : Error<
+  "checker '%0' has no option called '%1'">;
 def err_analyzer_checker_option_invalid_input : Error<
   "invalid input for checker option '%0', that expects %1">;


Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyz

[PATCH] D61508: [clang-tidy] bugprone-header-guard : a simple version of llvm-header-guard

2019-05-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/bugprone/HeaderGuardCheck.cpp:50
+
+  } else {
+if (OldGuard.size())

I think this should be an `else if` rather than an `else`. I'd like to see us 
diagnose unknown guard styles so that we only accept "llvm" and "" as guard 
styles; this makes it easier to add new guard styles in the future.



Comment at: docs/clang-tidy/checks/bugprone-header-guard.rst:11
+
+.. option:: HeaderFileExtensions
+

Should we be documenting the `GuardStyle` option here as well? We could 
document "llvm" as the only available option currently and mention the 
llvm-header-guard check as an alias which enables this style.



Comment at: test/clang-tidy/bugprone-header-guard.cpp:1-3
+// RUN: %check_clang_tidy %s bugprone-header-guard %t -- \
+// RUN:   -config="{CheckOptions: [{key: 
bugprone-header-guard.HeaderFileExtensions, value: 'cpp'}]}" \
+// RUN:   -header-filter=.* --

Can you add a test for the `GuardStyle` option? Both when specifying `llvm` and 
some random unsupported string.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61508



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


[PATCH] D61835: Extract ASTDumper to a header file

2019-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

Great, thanks.

I'm going to investigate whether we can move the `dump` method implementations 
to their respective class files, and then look into a rename for this to 
`StreamNodeDumper` or so (name tbd).


Repository:
  rC Clang

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

https://reviews.llvm.org/D61835



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


[PATCH] D61835: Extract ASTDumper to a header file

2019-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC361034: Extract ASTDumper to a header file (authored by 
steveire, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61835?vs=199179&id=200038#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D61835

Files:
  include/clang/AST/ASTDumper.h
  lib/AST/ASTDumper.cpp

Index: include/clang/AST/ASTDumper.h
===
--- include/clang/AST/ASTDumper.h
+++ include/clang/AST/ASTDumper.h
@@ -0,0 +1,56 @@
+//===--- ASTDumper.h - Dumping implementation for ASTs ===//
+//
+// 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 LLVM_CLANG_AST_ASTDUMPER_H
+#define LLVM_CLANG_AST_ASTDUMPER_H
+
+#include "clang/AST/ASTNodeTraverser.h"
+#include "clang/AST/TextNodeDumper.h"
+
+namespace clang {
+
+class ASTDumper : public ASTNodeTraverser {
+
+  TextNodeDumper NodeDumper;
+
+  raw_ostream &OS;
+
+  const bool ShowColors;
+
+public:
+  ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
+const SourceManager *SM)
+  : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) {}
+
+  ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
+const SourceManager *SM, bool ShowColors)
+  : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
+  ASTDumper(raw_ostream &OS, const comments::CommandTraits *Traits,
+const SourceManager *SM, bool ShowColors,
+const PrintingPolicy &PrintPolicy)
+  : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
+ShowColors(ShowColors) {}
+
+  TextNodeDumper &doGetNodeDelegate() { return NodeDumper; }
+
+  void dumpLookups(const DeclContext *DC, bool DumpDecls);
+
+  template 
+  void dumpTemplateDeclSpecialization(const SpecializationDecl *D,
+  bool DumpExplicitInst, bool DumpRefOnly);
+  template 
+  void dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
+
+  void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
+  void VisitClassTemplateDecl(const ClassTemplateDecl *D);
+  void VisitVarTemplateDecl(const VarTemplateDecl *D);
+};
+
+} // namespace clang
+
+#endif
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -11,11 +11,10 @@
 //
 //===--===//
 
+#include "clang/AST/ASTDumper.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/ASTNodeTraverser.h"
 #include "clang/AST/DeclLookups.h"
 #include "clang/AST/JSONNodeDumper.h"
-#include "clang/AST/TextNodeDumper.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
@@ -23,50 +22,6 @@
 using namespace clang;
 using namespace clang::comments;
 
-//===--===//
-// ASTDumper Visitor
-//===--===//
-
-namespace  {
-
-class ASTDumper : public ASTNodeTraverser {
-
-  TextNodeDumper NodeDumper;
-
-  raw_ostream &OS;
-
-  const bool ShowColors;
-
-public:
-  ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
-const SourceManager *SM)
-  : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) {}
-
-  ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
-const SourceManager *SM, bool ShowColors)
-  : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
-  ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
-const SourceManager *SM, bool ShowColors,
-const PrintingPolicy &PrintPolicy)
-  : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
-ShowColors(ShowColors) {}
-
-  TextNodeDumper &doGetNodeDelegate() { return NodeDumper; }
-
-  void dumpLookups(const DeclContext *DC, bool DumpDecls);
-
-  template 
-  void dumpTemplateDeclSpecialization(const SpecializationDecl *D,
-  bool DumpExplicitInst, bool DumpRefOnly);
-  template 
-  void dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
-
-  void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
-  void VisitClassTemplateDecl(const ClassTemplateDecl *D);
-  void VisitVarTemplateDecl(const VarTemplateDecl *D);
-};
-} // namespace
-
 void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
   NodeDumper.AddChild([=] {
 OS << "StoredDeclsMap ";
___
cfe-commits mailing

[PATCH] D61834: Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: unittests/AST/ASTTraverserTest.cpp:75
+
+template  std::string dumpASTString(NodeType &&... N) {
+  std::string Buffer;

steveire wrote:
> aaron.ballman wrote:
> > Did clang-format produce this formatting? (If not, run through 
> > clang-format.)
> Yep, clang-format made it like this.
Weird that it added the extra whitespace -- I think this is the only instance 
where we have whitespace to either side of the adornments, which is what caught 
me by surprise.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D61834



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


[PATCH] D61335: [LibTooling] Add support to Transformer for composing rules as an ordered choice.

2019-05-17 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 200042.
ymandel marked an inline comment as done.
ymandel added a comment.

Synced to HEAD in preparation for committing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61335

Files:
  clang/include/clang/Tooling/Refactoring/Transformer.h
  clang/lib/Tooling/Refactoring/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -116,7 +116,8 @@
 };
   }
 
-  void testRule(RewriteRule Rule, StringRef Input, StringRef Expected) {
+  template 
+  void testRule(R Rule, StringRef Input, StringRef Expected) {
 Transformer T(std::move(Rule), consumer());
 T.registerMatchers(&MatchFinder);
 compareSnippets(Expected, rewrite(Input));
@@ -147,7 +148,7 @@
  .bind(StringExpr)),
   callee(cxxMethodDecl(hasName("c_str")),
   change("REPLACED"));
-  R.Explanation = text("Use size() method directly on string.");
+  R.Cases[0].Explanation = text("Use size() method directly on string.");
   return R;
 }
 
@@ -375,6 +376,92 @@
Input, Expected);
 }
 
+TEST_F(TransformerTest, OrderedRuleUnrelated) {
+  StringRef Flag = "flag";
+  RewriteRule FlagRule = makeRule(
+  cxxMemberCallExpr(on(expr(hasType(cxxRecordDecl(
+hasName("proto::ProtoCommandLineFlag"
+   .bind(Flag)),
+unless(callee(cxxMethodDecl(hasName("GetProto"),
+  change(Flag, "PROTO"));
+
+  std::string Input = R"cc(
+proto::ProtoCommandLineFlag flag;
+int x = flag.foo();
+int y = flag.GetProto().foo();
+int f(string s) { return strlen(s.c_str()); }
+  )cc";
+  std::string Expected = R"cc(
+proto::ProtoCommandLineFlag flag;
+int x = PROTO.foo();
+int y = flag.GetProto().foo();
+int f(string s) { return REPLACED; }
+  )cc";
+
+  testRule(applyFirst({ruleStrlenSize(), FlagRule}), Input, Expected);
+}
+
+// Version of ruleStrlenSizeAny that inserts a method with a different name than
+// ruleStrlenSize, so we can tell their effect apart.
+RewriteRule ruleStrlenSizeDistinct() {
+  StringRef S;
+  return makeRule(
+  callExpr(callee(functionDecl(hasName("strlen"))),
+   hasArgument(0, cxxMemberCallExpr(
+  on(expr().bind(S)),
+  callee(cxxMethodDecl(hasName("c_str")),
+  change("DISTINCT"));
+}
+
+TEST_F(TransformerTest, OrderedRuleRelated) {
+  std::string Input = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return strlen(s.c_str()); }
+}  // namespace foo
+int g(string s) { return strlen(s.c_str()); }
+  )cc";
+  std::string Expected = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return DISTINCT; }
+}  // namespace foo
+int g(string s) { return REPLACED; }
+  )cc";
+
+  testRule(applyFirst({ruleStrlenSize(), ruleStrlenSizeDistinct()}), Input,
+   Expected);
+}
+
+// Change the order of the rules to get a different result.
+TEST_F(TransformerTest, OrderedRuleRelatedSwapped) {
+  std::string Input = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return strlen(s.c_str()); }
+}  // namespace foo
+int g(string s) { return strlen(s.c_str()); }
+  )cc";
+  std::string Expected = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return DISTINCT; }
+}  // namespace foo
+int g(string s) { return DISTINCT; }
+  )cc";
+
+  testRule(applyFirst({ruleStrlenSizeDistinct(), ruleStrlenSize()}), Input,
+   Expected);
+}
+
 //
 // Negative tests (where we expect no transformation to occur).
 //
Index: clang/lib/Tooling/Refactoring/Transformer.cpp
===
--- clang/lib/Tooling/Refactoring/Transformer.cpp
+++ clang/lib/Tooling/Refactoring/Transformer.cpp
@@ -28,6 +28,7 @@
 using namespace tooling;
 
 using ast_matchers::MatchFinder;
+using ast_matchers::internal::DynTypedMatcher;
 using ast_type_traits::ASTNodeKind;
 using ast_type_traits::DynTypedNode;
 using llvm::Error;
@@ -144,9 +145,9 @@
   llvm_unreachable("Unexpected case in NodePart type.");
 }
 
-Expected>
-tooling::translateEdits(const MatchResult &Result,
-llvm::ArrayRef Edits) {
+Expected>
+tooling::detail::translateEdits(const MatchResult &Result,
+llvm::ArrayRef Edits) {
   SmallVector Transformations;
   auto &NodesMap = Result.Nodes.getMap();
   for (const auto &Edit : Edit

[PATCH] D62064: [ASTImporter] Fix unhandled cases in ASTImporterLookupTable

2019-05-17 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added a reviewer: a_sidorin.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.

In most cases the FriendDecl contains the declaration of the befriended
class as a child node, so it is discovered during the recursive
visitation. However, there are cases when the befriended class is not a
child, thus it must be fetched explicitly from the FriendDecl, and only
then can we add it to the lookup table.
(Note, this does affect only CTU and does not affect LLDB, because we
cannot and do not use the ASTImporterLookupTable in LLDB.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62064

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

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4246,13 +4246,27 @@
   ASSERT_EQ(Res.size(), 0u);
 }
 
+static QualType getUnderlyingType(const TypedefType *TDT) {
+  QualType T = TDT->getDecl()->getUnderlyingType();
+
+  if (const auto *Inner = dyn_cast(T.getTypePtr()))
+return getUnderlyingType(Inner);
+
+  return T;
+}
+
 static const RecordDecl * getRecordDeclOfFriend(FriendDecl *FD) {
   QualType Ty = FD->getFriendType()->getType();
-  QualType NamedTy = cast(Ty)->getNamedType();
-  return cast(NamedTy)->getDecl();
+  if (auto *Inner = dyn_cast(Ty.getTypePtr())) {
+Ty = getUnderlyingType(Inner);
+  }
+  if (isa(Ty))
+Ty = cast(Ty)->getNamedType();
+  return cast(Ty)->getDecl();
 }
 
-TEST_P(ASTImporterLookupTableTest, LookupFindsFwdFriendClassDecl) {
+TEST_P(ASTImporterLookupTableTest,
+   LookupFindsFwdFriendClassDeclWithElaboratedType) {
   TranslationUnitDecl *ToTU = getToTuDecl(
   R"(
   class Y { friend class F; };
@@ -4276,6 +4290,52 @@
   EXPECT_EQ(Res.size(), 0u);
 }
 
+TEST_P(ASTImporterLookupTableTest,
+   LookupFindsFwdFriendClassDeclWithUnelaboratedType) {
+  TranslationUnitDecl *ToTU = getToTuDecl(
+  R"(
+  class F;
+  class Y { friend F; };
+  )",
+  Lang_CXX11);
+
+  // In this case, the CXXRecordDecl is hidden, the FriendDecl is not a parent.
+  // So we must dig up the underlying CXXRecordDecl.
+  ASTImporterLookupTable LT(*ToTU);
+  auto *FriendD = FirstDeclMatcher().match(ToTU, friendDecl());
+  const RecordDecl *RD = getRecordDeclOfFriend(FriendD);
+  auto *Y = FirstDeclMatcher().match(ToTU, cxxRecordDecl(hasName("Y")));
+
+  DeclarationName Name = RD->getDeclName();
+  auto Res = LT.lookup(ToTU, Name);
+  EXPECT_EQ(Res.size(), 1u);
+  EXPECT_EQ(*Res.begin(), RD);
+
+  Res = LT.lookup(Y, Name);
+  EXPECT_EQ(Res.size(), 0u);
+}
+
+TEST_P(ASTImporterLookupTableTest,
+   LookupFindsFriendClassDeclWithTypeAliasDoesNotAssert) {
+  TranslationUnitDecl *ToTU = getToTuDecl(
+  R"(
+  class F;
+  using alias_of_f = F;
+  class Y { friend alias_of_f; };
+  )",
+  Lang_CXX11);
+
+  // ASTImporterLookupTable constructor handles using declarations correctly,
+  // no assert is expected.
+  ASTImporterLookupTable LT(*ToTU);
+
+  auto *Alias = FirstDeclMatcher().match(
+  ToTU, typeAliasDecl(hasName("alias_of_f")));
+  DeclarationName Name = Alias->getDeclName();
+  auto Res = LT.lookup(ToTU, Name);
+  EXPECT_EQ(Res.count(Alias), 1u);
+}
+
 TEST_P(ASTImporterLookupTableTest, LookupFindsFwdFriendClassTemplateDecl) {
   TranslationUnitDecl *ToTU = getToTuDecl(
   R"(
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -26,17 +26,30 @@
 LT.add(D);
 return true;
   }
+  // In most cases the FriendDecl contains the declaration of the befriended
+  // class as a child node, so it is discovered during the recursive
+  // visitation. However, there are cases when the befriended class is not a
+  // child, thus it must be fetched explicitly from the FriendDecl, and only
+  // then can we add it to the lookup table.
   bool VisitFriendDecl(FriendDecl *D) {
 if (D->getFriendType()) {
   QualType Ty = D->getFriendType()->getType();
-  // FIXME Can this be other than elaborated?
-  QualType NamedTy = cast(Ty)->getNamedType();
-  if (!NamedTy->isDependentType()) {
-if (const auto *RTy = dyn_cast(NamedTy))
+  if (isa(Ty))
+Ty = cast(Ty)->getNamedType();
+  // A FriendDecl with a dependent type (e.g. ClassTemplateSpecialization)
+  // always has that decl as child node.
+  // However, there are non-dependent cases which does not have the
+  // type as a child node. We have to dig up that type now.
+  if (!Ty->isDependentType()) {
+if (const auto *RTy = dyn_cast(Ty)

[PATCH] D58035: [clang/DIVar] Emit flag for params that have unchanged values

2019-05-17 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro marked 3 inline comments as done.
djtodoro added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:4537
+  CGM.getLangOpts().Optimize) {
+for (auto &SP : DeclCache) {
+  auto *D = SP.first;

aprantl wrote:
> djtodoro wrote:
> > aprantl wrote:
> > > Just looking at the type declarations in CGDebugInfo.h: Why not iterate 
> > > over the `SPCache`  directly? Shouldn't that contain all Function 
> > > declarations only?
> > I tried it, but `SPCache` is empty at this point.
> Where is it emptied? Just grepping through CGDebugInfo did not make this 
> obvious to me.
The `SPCache` actually gets filled only in the case of `CXXMemberFunction`.
In the other cases of `SP` production there is only filling of `DeclCache`.
Should we use it like this or ?



Comment at: lib/CodeGen/CGDebugInfo.cpp:3885
+  if (CGM.getCodeGenOpts().EnableDebugEntryValues &&
+  CGM.getLangOpts().Optimize && ArgNo) {
+if (auto *PD = dyn_cast(VD))

aprantl wrote:
> We shouldn't query CGM.getLangOpts().Optimize. If we don't want this to 
> happen at -O0, we shouldn't set EnableDebugEntryValues at a higher level 
> (Driver, CompilerInvocation, ...) ..Otherwise inevitably someone will query 
> one but not the other and things will go out of sync.
I agree. Thanks!



Comment at: lib/CodeGen/CGDebugInfo.cpp:4535
   DBuilder.retainType(cast(MD));
 
+  if (CGM.getCodeGenOpts().EnableDebugEntryValues &&

aprantl wrote:
> Please add either a top-level comment about what this block is doing or 
> perhaps factor this out into a descriptively named static function.
Sure.


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

https://reviews.llvm.org/D58035



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


r361037 - [LibTooling] Add support to Transformer for composing rules as an ordered choice.

2019-05-17 Thread Yitzhak Mandelbaum via cfe-commits
Author: ymandel
Date: Fri May 17 07:23:33 2019
New Revision: 361037

URL: http://llvm.org/viewvc/llvm-project?rev=361037&view=rev
Log:
[LibTooling] Add support to Transformer for composing rules as an ordered 
choice.

This revision updates `RewriteRule` to support multiple subrules that are
interpreted as an ordered-choice (apply the first one that matches). With this
feature, users can write the rules that appear later in the list of subrules
knowing that previous rules' patterns *have not matched*, freeing them from
reasoning about those cases in the current pattern.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h
cfe/trunk/lib/Tooling/Refactoring/Transformer.cpp
cfe/trunk/unittests/Tooling/TransformerTest.cpp

Modified: cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h?rev=361037&r1=361036&r2=361037&view=diff
==
--- cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h (original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Transformer.h Fri May 17 
07:23:33 2019
@@ -145,8 +145,8 @@ template  ASTEdit change(std
 
 /// Description of a source-code transformation.
 //
-// A *rewrite rule* describes a transformation of source code. It has the
-// following components:
+// A *rewrite rule* describes a transformation of source code. A simple rule
+// contains each of the following components:
 //
 // * Matcher: the pattern term, expressed as clang matchers (with Transformer
 //   extensions).
@@ -156,30 +156,31 @@ template  ASTEdit change(std
 // * Explanation: explanation of the rewrite.  This will be displayed to the
 //   user, where possible; for example, in clang-tidy diagnostics.
 //
-// Rules have an additional, implicit, component: the parameters. These are
-// portions of the pattern which are left unspecified, yet named so that we can
-// reference them in the replacement term.  The structure of parameters can be
-// partially or even fully specified, in which case they serve just to identify
-// matched nodes for later reference rather than abstract over portions of the
-// AST.  However, in all cases, we refer to named portions of the pattern as
-// parameters.
+// However, rules can also consist of (sub)rules, where the first that matches
+// is applied and the rest are ignored.  So, the above components are gathered
+// as a `Case` and a rule is a list of cases.
+//
+// Rule cases have an additional, implicit, component: the parameters. These 
are
+// portions of the pattern which are left unspecified, yet bound in the pattern
+// so that we can reference them in the edits.
 //
-// The \c Transformer class should be used to apply the rewrite rule and obtain
-// the corresponding replacements.
+// The \c Transformer class can be used to apply the rewrite rule and obtain 
the
+// corresponding replacements.
 struct RewriteRule {
-  // `Matcher` describes the context of this rule. It should always be bound to
-  // at least `RootId`.
-  ast_matchers::internal::DynTypedMatcher Matcher;
-  SmallVector Edits;
-  TextGenerator Explanation;
+  struct Case {
+ast_matchers::internal::DynTypedMatcher Matcher;
+SmallVector Edits;
+TextGenerator Explanation;
+  };
+  // We expect RewriteRules will most commonly include only one case.
+  SmallVector Cases;
 
   // Id used as the default target of each match. The node described by the
   // matcher is should always be bound to this id.
   static constexpr llvm::StringLiteral RootId = "___root___";
 };
 
-/// Convenience function for constructing a \c RewriteRule. Takes care of
-/// binding the matcher to RootId.
+/// Convenience function for constructing a simple \c RewriteRule.
 RewriteRule makeRule(ast_matchers::internal::DynTypedMatcher M,
  SmallVector Edits);
 
@@ -191,12 +192,73 @@ inline RewriteRule makeRule(ast_matchers
   return makeRule(std::move(M), std::move(Edits));
 }
 
+/// Applies the first rule whose pattern matches; other rules are ignored.
+///
+/// N.B. All of the rules must use the same kind of matcher (that is, share a
+/// base class in the AST hierarchy).  However, this constraint is caused by an
+/// implementation detail and should be lifted in the future.
+//
+// `applyFirst` is like an `anyOf` matcher with an edit action attached to each
+// of its cases. Anywhere you'd use `anyOf(m1.bind("id1"), m2.bind("id2"))` and
+// then dispatch on those ids in your code for control flow, `applyFirst` lifts
+// that behavior to the rule level.  So, you can write 
`applyFirst({makeRule(m1,
+// action1), makeRule(m2, action2), ...});`
+//
+// For example, consider a type `T` with a deterministic serialization 
function,
+// `serialize()`.  For performance reasons, we would

[PATCH] D61335: [LibTooling] Add support to Transformer for composing rules as an ordered choice.

2019-05-17 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC361037: [LibTooling] Add support to Transformer for 
composing rules as an ordered… (authored by ymandel, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61335?vs=200042&id=200044#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D61335

Files:
  include/clang/Tooling/Refactoring/Transformer.h
  lib/Tooling/Refactoring/Transformer.cpp
  unittests/Tooling/TransformerTest.cpp

Index: lib/Tooling/Refactoring/Transformer.cpp
===
--- lib/Tooling/Refactoring/Transformer.cpp
+++ lib/Tooling/Refactoring/Transformer.cpp
@@ -28,6 +28,7 @@
 using namespace tooling;
 
 using ast_matchers::MatchFinder;
+using ast_matchers::internal::DynTypedMatcher;
 using ast_type_traits::ASTNodeKind;
 using ast_type_traits::DynTypedNode;
 using llvm::Error;
@@ -144,9 +145,9 @@
   llvm_unreachable("Unexpected case in NodePart type.");
 }
 
-Expected>
-tooling::translateEdits(const MatchResult &Result,
-llvm::ArrayRef Edits) {
+Expected>
+tooling::detail::translateEdits(const MatchResult &Result,
+llvm::ArrayRef Edits) {
   SmallVector Transformations;
   auto &NodesMap = Result.Nodes.getMap();
   for (const auto &Edit : Edits) {
@@ -171,18 +172,113 @@
   return Transformations;
 }
 
-RewriteRule tooling::makeRule(ast_matchers::internal::DynTypedMatcher M,
+RewriteRule tooling::makeRule(DynTypedMatcher M,
   SmallVector Edits) {
+  return RewriteRule{
+  {RewriteRule::Case{std::move(M), std::move(Edits), nullptr}}};
+}
+
+// Determines whether A is a base type of B in the class hierarchy, including
+// the implicit relationship of Type and QualType.
+static bool isBaseOf(ASTNodeKind A, ASTNodeKind B) {
+  static auto TypeKind = ASTNodeKind::getFromNodeKind();
+  static auto QualKind = ASTNodeKind::getFromNodeKind();
+  /// Mimic the implicit conversions of Matcher<>.
+  /// - From Matcher to Matcher
+  /// - From Matcher to Matcher
+  return (A.isSame(TypeKind) && B.isSame(QualKind)) || A.isBaseOf(B);
+}
+
+// Try to find a common kind to which all of the rule's matchers can be
+// converted.
+static ASTNodeKind
+findCommonKind(const SmallVectorImpl &Cases) {
+  assert(!Cases.empty() && "Rule must have at least one case.");
+  ASTNodeKind JoinKind = Cases[0].Matcher.getSupportedKind();
+  // Find a (least) Kind K, for which M.canConvertTo(K) holds, for all matchers
+  // M in Rules.
+  for (const auto &Case : Cases) {
+auto K = Case.Matcher.getSupportedKind();
+if (isBaseOf(JoinKind, K)) {
+  JoinKind = K;
+  continue;
+}
+if (K.isSame(JoinKind) || isBaseOf(K, JoinKind))
+  // JoinKind is already the lowest.
+  continue;
+// K and JoinKind are unrelated -- there is no least common kind.
+return ASTNodeKind();
+  }
+  return JoinKind;
+}
+
+// Binds each rule's matcher to a unique (and deterministic) tag based on
+// `TagBase`.
+static std::vector
+taggedMatchers(StringRef TagBase,
+   const SmallVectorImpl &Cases) {
+  std::vector Matchers;
+  Matchers.reserve(Cases.size());
+  size_t count = 0;
+  for (const auto &Case : Cases) {
+std::string Tag = (TagBase + Twine(count)).str();
+++count;
+auto M = Case.Matcher.tryBind(Tag);
+assert(M && "RewriteRule matchers should be bindable.");
+Matchers.push_back(*std::move(M));
+  }
+  return Matchers;
+}
+
+// Simply gathers the contents of the various rules into a single rule. The
+// actual work to combine these into an ordered choice is deferred to matcher
+// registration.
+RewriteRule tooling::applyFirst(ArrayRef Rules) {
+  RewriteRule R;
+  for (auto &Rule : Rules)
+R.Cases.append(Rule.Cases.begin(), Rule.Cases.end());
+  return R;
+}
+
+static DynTypedMatcher joinCaseMatchers(const RewriteRule &Rule) {
+  assert(!Rule.Cases.empty() && "Rule must have at least one case.");
+  if (Rule.Cases.size() == 1)
+return Rule.Cases[0].Matcher;
+
+  auto CommonKind = findCommonKind(Rule.Cases);
+  assert(!CommonKind.isNone() && "Cases must have compatible matchers.");
+  return DynTypedMatcher::constructVariadic(
+  DynTypedMatcher::VO_AnyOf, CommonKind, taggedMatchers("Tag", Rule.Cases));
+}
+
+DynTypedMatcher tooling::detail::buildMatcher(const RewriteRule &Rule) {
+  DynTypedMatcher M = joinCaseMatchers(Rule);
   M.setAllowBind(true);
   // `tryBind` is guaranteed to succeed, because `AllowBind` was set to true.
-  return RewriteRule{*M.tryBind(RewriteRule::RootId), std::move(Edits),
- nullptr};
+  return *M.tryBind(RewriteRule::RootId);
+}
+
+// Finds the case that was "selected" -- that is, whose matcher triggered the
+// `MatchResult`.
+const RewriteRule::Case &
+tooling::detail::findSelectedCase(const MatchResult &Result,
+  c

[PATCH] D59887: [Syntax] Introduce TokenBuffer, start clangToolingSyntax library

2019-05-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:49
+
+/// A half-open range inside a particular file, the start offset is included 
and
+/// the end offset is excluded from the range.

nit: character range (just to be totally explicit)?



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:115
+  /// expansion.
+  llvm::Optional range(const SourceManager &SM) const;
+

I think this might need a more explicit name. It's reasonably obvious that this 
needs to be optional for some cases (token pasting), but it's not obvious at 
callsites that (or why) we don't use the spelling location for macro-expanded 
tokens.

One option would be just do that and add an expandedFromMacro() helper so the 
no-macros version is easy to express too.
If we can't do that, maybe `directlySpelledRange` or something?



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:121
+  /// are from different files or \p Last is located before \p First.
+  static llvm::Optional range(const SourceManager &SM,
+ const syntax::Token &First,

similar to above, I'd naively expect this to return a valid range, given the 
tokens expanded from `assert(X && [[Y.z()]] )`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59887



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


[PATCH] D62065: Move dump method implementations to their respective class files

2019-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There is no need to group them together.


Repository:
  rC Clang

https://reviews.llvm.org/D62065

Files:
  lib/AST/ASTDumper.cpp
  lib/AST/Comment.cpp
  lib/AST/DeclBase.cpp
  lib/AST/Stmt.cpp
  lib/AST/Type.cpp

Index: lib/AST/Type.cpp
===
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -44,6 +44,7 @@
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
+#include "clang/AST/ASTDumper.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
 #include 
@@ -53,6 +54,25 @@
 
 using namespace clang;
 
+void QualType::dump(const char *msg) const {
+  if (msg)
+llvm::errs() << msg << ": ";
+  dump();
+}
+
+LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
+
+LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
+  ASTDumper Dumper(OS, nullptr, nullptr);
+  Dumper.Visit(*this);
+}
+
+LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
+
+LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
+  QualType(this, 0).dump(OS);
+}
+
 bool Qualifiers::isStrictSupersetOf(Qualifiers Other) const {
   return (*this != Other) &&
 // CVR qualifiers superset
Index: lib/AST/Stmt.cpp
===
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
+#include "clang/AST/ASTDumper.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtOpenMP.h"
@@ -1292,3 +1293,27 @@
 
   return false;
 }
+
+LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
+  dump(llvm::errs(), SM);
+}
+
+LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
+  ASTDumper P(OS, nullptr, &SM);
+  P.Visit(this);
+}
+
+LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
+  ASTDumper P(OS, nullptr, nullptr);
+  P.Visit(this);
+}
+
+LLVM_DUMP_METHOD void Stmt::dump() const {
+  ASTDumper P(llvm::errs(), nullptr, nullptr);
+  P.Visit(this);
+}
+
+LLVM_DUMP_METHOD void Stmt::dumpColor() const {
+  ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
+  P.Visit(this);
+}
Index: lib/AST/DeclBase.cpp
===
--- lib/AST/DeclBase.cpp
+++ lib/AST/DeclBase.cpp
@@ -19,6 +19,8 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclContextInternals.h"
 #include "clang/AST/DeclFriend.h"
+#include "clang/AST/JSONNodeDumper.h"
+#include "clang/AST/ASTDumper.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclOpenMP.h"
 #include "clang/AST/DeclTemplate.h"
@@ -1969,3 +1971,48 @@
 
   return DD;
 }
+
+LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
+
+LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize,
+ ASTDumpOutputFormat Format) const {
+  const ASTContext &Ctx = getASTContext();
+  const SourceManager &SM = Ctx.getSourceManager();
+
+  if (ADOF_JSON == Format) {
+JSONDumper P(OS, SM, Ctx.getPrintingPolicy());
+(void)Deserialize; // FIXME?
+P.Visit(this);
+  } else {
+ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
+SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
+P.setDeserialize(Deserialize);
+P.Visit(this);
+  }
+}
+
+LLVM_DUMP_METHOD void Decl::dumpColor() const {
+  const ASTContext &Ctx = getASTContext();
+  ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
+  &Ctx.getSourceManager(), /*ShowColors*/ true,
+  Ctx.getPrintingPolicy());
+  P.Visit(this);
+}
+
+LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
+  dumpLookups(llvm::errs());
+}
+
+LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
+   bool DumpDecls,
+   bool Deserialize) const {
+  const DeclContext *DC = this;
+  while (!DC->isTranslationUnit())
+DC = DC->getParent();
+  ASTContext &Ctx = cast(DC)->getASTContext();
+  const SourceManager &SM = Ctx.getSourceManager();
+  ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
+  SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
+  P.setDeserialize(Deserialize);
+  P.dumpLookups(this, DumpDecls);
+}
Index: lib/AST/Comment.cpp
===
--- lib/AST/Comment.cpp
+++ lib/AST/Comment.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/AST/ASTDumper.h"
 #include "llvm/Support/ErrorHandling.h"
 
 namespace clang {
@@ -374,6 +375,32 @@
   return "";
 }
 
+LLVM_DUMP_M

[PATCH] D62066: [ASTImporter] Enable disabled but passing tests

2019-05-17 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added a reviewer: a_sidorin.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62066

Files:
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp


Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -300,8 +300,7 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
-TEST_F(StructuralEquivalenceFunctionTest, DISABLED_NoexceptNonMatch) {
-  // The expression is not checked yet.
+TEST_F(StructuralEquivalenceFunctionTest, NoexceptNonMatch) {
   auto t = makeNamedDecls("void foo() noexcept(false);",
   "void foo() noexcept(true);", Lang_CXX11);
   EXPECT_FALSE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -2362,12 +2362,7 @@
   EXPECT_EQ(ToFD->getPreviousDecl(), ImportedD);
 }
 
-// Disabled temporarily, because the new structural equivalence check
-// (https://reviews.llvm.org/D48628) breaks it.
-// PreviousDecl is not set because there is no structural match.
-// FIXME Enable!
-TEST_P(ImportFriendFunctions,
-DISABLED_ImportFriendFunctionRedeclChainDefWithClass) {
+TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainDefWithClass) {
   auto Pattern = functionDecl(hasName("f"));
 
   Decl *FromTU = getTuDecl(
@@ -2395,12 +2390,8 @@
 (*ImportedD->param_begin())->getOriginalType());
 }
 
-// Disabled temporarily, because the new structural equivalence check
-// (https://reviews.llvm.org/D48628) breaks it.
-// PreviousDecl is not set because there is no structural match.
-// FIXME Enable!
 TEST_P(ImportFriendFunctions,
-DISABLED_ImportFriendFunctionRedeclChainDefWithClass_ImportTheProto) {
+   ImportFriendFunctionRedeclChainDefWithClass_ImportTheProto) {
   auto Pattern = functionDecl(hasName("f"));
 
   Decl *FromTU = getTuDecl(


Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -300,8 +300,7 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
-TEST_F(StructuralEquivalenceFunctionTest, DISABLED_NoexceptNonMatch) {
-  // The expression is not checked yet.
+TEST_F(StructuralEquivalenceFunctionTest, NoexceptNonMatch) {
   auto t = makeNamedDecls("void foo() noexcept(false);",
   "void foo() noexcept(true);", Lang_CXX11);
   EXPECT_FALSE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -2362,12 +2362,7 @@
   EXPECT_EQ(ToFD->getPreviousDecl(), ImportedD);
 }
 
-// Disabled temporarily, because the new structural equivalence check
-// (https://reviews.llvm.org/D48628) breaks it.
-// PreviousDecl is not set because there is no structural match.
-// FIXME Enable!
-TEST_P(ImportFriendFunctions,
-DISABLED_ImportFriendFunctionRedeclChainDefWithClass) {
+TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainDefWithClass) {
   auto Pattern = functionDecl(hasName("f"));
 
   Decl *FromTU = getTuDecl(
@@ -2395,12 +2390,8 @@
 (*ImportedD->param_begin())->getOriginalType());
 }
 
-// Disabled temporarily, because the new structural equivalence check
-// (https://reviews.llvm.org/D48628) breaks it.
-// PreviousDecl is not set because there is no structural match.
-// FIXME Enable!
 TEST_P(ImportFriendFunctions,
-DISABLED_ImportFriendFunctionRedeclChainDefWithClass_ImportTheProto) {
+   ImportFriendFunctionRedeclChainDefWithClass_ImportTheProto) {
   auto Pattern = functionDecl(hasName("f"));
 
   Decl *FromTU = getTuDecl(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61837: Make it possible control matcher traversal kind with ASTContext

2019-05-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire marked an inline comment as done.
steveire added inline comments.



Comment at: lib/ASTMatchers/ASTMatchersInternal.cpp:240
+
+  assert(RestrictKind.isBaseOf(NodeKind));
+  if (Implementation->dynMatches(N, Finder, Builder)) {

aaron.ballman wrote:
> steveire wrote:
> > aaron.ballman wrote:
> > > Add an assertion message?
> > Saying what? The original code doesn't have one. Let's avoid round trips in 
> > review comments :).
> This isn't a "round trip"; it's not unreasonable to ask people to NFC improve 
> the code they're touching (it's akin to saying "Because you figured out this 
> complex piece of code does X, can you add a comment to it so others don't 
> have to do that work next time.").
> 
> As best I can tell, this assertion exists because this function is meant to 
> mirror `matches()` without this base check in release mode. You've lost that 
> mirroring with your refactoring, which looks suspicious. Is there a reason 
> this function deviates from `matches()` now?
> 
> As for the assertion message itself, how about "matched a node of an 
> unexpected derived kind"?
Hmm, maybe that was a misunderstanding. Your note about an assertion message 
was not clear, so I asked you what you suggest the message should be. No need 
for offense :)


Repository:
  rC Clang

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

https://reviews.llvm.org/D61837



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


[PATCH] D60568: [OpenMP] Add support for registering requires directives with the runtime

2019-05-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea marked an inline comment as done.
gtbercea added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:10364
+  if (const auto *FD = dyn_cast(D)) {
+if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(FD)) {
+  HasEmittedDeclareTargetRegion = true;

ABataev wrote:
> gtbercea wrote:
> > ABataev wrote:
> > > ABataev wrote:
> > > > No need for the braces
> > > What if `declare target` is used only for variabes but not for the 
> > > functions?
> > Even more reason to error in that case since it may contain clauses like 
> > link or to which need for requires directives to be used consistently.
> But I don't see that your patch works in this situation. Currently, it will 
> emit the error only if the declare target function is found, no?
Actually it will work even when just variables are used in the declare target 
region. There is another problem which I have a fix for. I will update the 
patch in a bit. 


Repository:
  rC Clang

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

https://reviews.llvm.org/D60568



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


[PATCH] D37813: clang-format: better handle namespace macros

2019-05-17 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.
Herald added a project: clang.

ping ?


Repository:
  rC Clang

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

https://reviews.llvm.org/D37813



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


[PATCH] D60953: [clangd] Respect clang-tidy suppression comments

2019-05-17 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Could someone merge this and D61841  now that 
they're approved? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60953



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


Re: r361011 - [analyzer] Validate checker option names and values

2019-05-17 Thread Kristof Umann via cfe-commits
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick seems to be doing 
fine now, http://lab.llvm.org:8011/builders/clang-ppc64be-linux seems to crash 
on files totally unrelated to mine.


From: Kristof Umann
Sent: 17 May 2019 15:59:28
To: Nico Weber
Cc: cfe-commits
Subject: Re: r361011 - [analyzer] Validate checker option names and values


I'll take a look.


From: Nico Weber 
Sent: 17 May 2019 15:09:18
To: Kristof Umann
Cc: cfe-commits
Subject: Re: r361011 - [analyzer] Validate checker option names and values

It looks like this change is making gcc-7 crash on these (and other 
http://lab.llvm.org:8011/console) bots:

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/18639
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/33837/

[100/212] Building CXX object 
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o
FAILED: tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[101/212] Building CXX object 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersTraversalTest.cpp.o
FAILED: 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersTraversalTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[102/212] Building CXX object 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNarrowingTest.cpp.o
FAILED: 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNarrowingTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[103/212] Building CXX object 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNodeTest.cpp.o
FAILED: 
tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNodeTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[104/212] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/CommentHandlerTest.cpp.o
FAILED: 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/CommentHandlerTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[105/212] Building CXX object 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ExecutionTest.cpp.o
FAILED: 
tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ExecutionTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
[106/212] Building CXX object 
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterVisibilityTest.cpp.o
FAILED: 
tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterVisibilityTest.cpp.o
...
g++-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.

From: Kristof Umann via cfe-commits 
mailto:cfe-commits@lists.llvm.org>>
Date: Fri, May 17, 2019 at 5:49 AM
To: mailto:cfe-commits@lists.llvm.org>>

Author: szelethus
Date: Fri May 17 02:51:59 2019
New Revision: 361011

URL: http://llvm.org/viewvc/llvm-project?rev=361011&view=rev
Log:
[analyzer] Validate checker option names and values

Validate whether the option exists, and also whether the supplied value is of
the correct type. With this patch, invoking the analyzer should be, at least
in the frontend mode, a lot safer.

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
cfe/trunk/test/Analysis/checker-plugins.c
cfe/trunk/test/Analysis/invalid-checker-option.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=361011&r1=361010&r2=361011&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Fri May 17 02:51:59 
2019
@@ -307,6 +307,8 @@ def err_analyzer_config_multiple_values
 def err_analyzer_config_invalid_input : Error<
   "invalid input for analyzer-config option '%0', that expects %1 value">;
 def err_analyzer_config_unknown : Error<"unknown analyzer-c

[PATCH] D60568: [OpenMP] Add support for registering requires directives with the runtime

2019-05-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:10364
+  if (const auto *FD = dyn_cast(D)) {
+if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(FD)) {
+  HasEmittedDeclareTargetRegion = true;

gtbercea wrote:
> ABataev wrote:
> > gtbercea wrote:
> > > ABataev wrote:
> > > > ABataev wrote:
> > > > > No need for the braces
> > > > What if `declare target` is used only for variabes but not for the 
> > > > functions?
> > > Even more reason to error in that case since it may contain clauses like 
> > > link or to which need for requires directives to be used consistently.
> > But I don't see that your patch works in this situation. Currently, it will 
> > emit the error only if the declare target function is found, no?
> Actually it will work even when just variables are used in the declare target 
> region. There is another problem which I have a fix for. I will update the 
> patch in a bit. 
Why will it work in this case? If you have just a declare target region in the 
code for the variables and nothing else. You don't have target regions, declare 
target functions etc. It won't work in this case.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60568



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


[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 200048.
gtbercea added a comment.

- update patch


Repository:
  rC Clang

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

https://reviews.llvm.org/D62046

Files:
  lib/Headers/__clang_cuda_cmath.h
  lib/Headers/__clang_cuda_math_forward_declares.h


Index: lib/Headers/__clang_cuda_math_forward_declares.h
===
--- lib/Headers/__clang_cuda_math_forward_declares.h
+++ lib/Headers/__clang_cuda_math_forward_declares.h
@@ -42,6 +42,10 @@
 __DEVICE__ double abs(double);
 __DEVICE__ float abs(float);
 #endif
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const double abs(const double);
+__DEVICE__ const float abs(const float);
+#endif
 __DEVICE__ int abs(int) __NOEXCEPT;
 __DEVICE__ double acos(double);
 __DEVICE__ float acos(float);
@@ -144,6 +148,9 @@
 __DEVICE__ float log2(float);
 __DEVICE__ double logb(double);
 __DEVICE__ float logb(float);
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ long double log(long double);
+#endif
 __DEVICE__ double log(double);
 __DEVICE__ float log(float);
 __DEVICE__ long lrint(double);
Index: lib/Headers/__clang_cuda_cmath.h
===
--- lib/Headers/__clang_cuda_cmath.h
+++ lib/Headers/__clang_cuda_cmath.h
@@ -51,6 +51,10 @@
 __DEVICE__ float abs(float __x) { return ::fabsf(__x); }
 __DEVICE__ double abs(double __x) { return ::fabs(__x); }
 #endif
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const float abs(const float __x) { return ::fabsf((float)__x); }
+__DEVICE__ const double abs(const double __x) { return ::fabs((double)__x); }
+#endif
 __DEVICE__ float acos(float __x) { return ::acosf(__x); }
 __DEVICE__ float asin(float __x) { return ::asinf(__x); }
 __DEVICE__ float atan(float __x) { return ::atanf(__x); }


Index: lib/Headers/__clang_cuda_math_forward_declares.h
===
--- lib/Headers/__clang_cuda_math_forward_declares.h
+++ lib/Headers/__clang_cuda_math_forward_declares.h
@@ -42,6 +42,10 @@
 __DEVICE__ double abs(double);
 __DEVICE__ float abs(float);
 #endif
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const double abs(const double);
+__DEVICE__ const float abs(const float);
+#endif
 __DEVICE__ int abs(int) __NOEXCEPT;
 __DEVICE__ double acos(double);
 __DEVICE__ float acos(float);
@@ -144,6 +148,9 @@
 __DEVICE__ float log2(float);
 __DEVICE__ double logb(double);
 __DEVICE__ float logb(float);
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ long double log(long double);
+#endif
 __DEVICE__ double log(double);
 __DEVICE__ float log(float);
 __DEVICE__ long lrint(double);
Index: lib/Headers/__clang_cuda_cmath.h
===
--- lib/Headers/__clang_cuda_cmath.h
+++ lib/Headers/__clang_cuda_cmath.h
@@ -51,6 +51,10 @@
 __DEVICE__ float abs(float __x) { return ::fabsf(__x); }
 __DEVICE__ double abs(double __x) { return ::fabs(__x); }
 #endif
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const float abs(const float __x) { return ::fabsf((float)__x); }
+__DEVICE__ const double abs(const double __x) { return ::fabs((double)__x); }
+#endif
 __DEVICE__ float acos(float __x) { return ::acosf(__x); }
 __DEVICE__ float asin(float __x) { return ::asinf(__x); }
 __DEVICE__ float atan(float __x) { return ::atanf(__x); }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

@tra I eliminated the long double definition for log and only left the 
declaration.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62046



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


[PATCH] D60568: [OpenMP] Add support for registering requires directives with the runtime

2019-05-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea marked an inline comment as done.
gtbercea added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:10364
+  if (const auto *FD = dyn_cast(D)) {
+if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(FD)) {
+  HasEmittedDeclareTargetRegion = true;

ABataev wrote:
> gtbercea wrote:
> > ABataev wrote:
> > > gtbercea wrote:
> > > > ABataev wrote:
> > > > > ABataev wrote:
> > > > > > No need for the braces
> > > > > What if `declare target` is used only for variabes but not for the 
> > > > > functions?
> > > > Even more reason to error in that case since it may contain clauses 
> > > > like link or to which need for requires directives to be used 
> > > > consistently.
> > > But I don't see that your patch works in this situation. Currently, it 
> > > will emit the error only if the declare target function is found, no?
> > Actually it will work even when just variables are used in the declare 
> > target region. There is another problem which I have a fix for. I will 
> > update the patch in a bit. 
> Why will it work in this case? If you have just a declare target region in 
> the code for the variables and nothing else. You don't have target regions, 
> declare target functions etc. It won't work in this case.
It will work because the OffloadEntriesInfoManager.empty() will return false in 
that case.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60568



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


r361042 - [analyzer] Remove the default value arg from getChecker*Option

2019-05-17 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Fri May 17 08:52:13 2019
New Revision: 361042

URL: http://llvm.org/viewvc/llvm-project?rev=361042&view=rev
Log:
[analyzer] Remove the default value arg from getChecker*Option

Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.

By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.

This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
cfe/trunk/test/Analysis/checker-plugins.c
cfe/trunk/test/Analysis/invalid-checker-option.c

cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp
cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=361042&r1=361041&r2=361042&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Fri May 17 
08:52:13 2019
@@ -281,18 +281,14 @@ public:
   /// Checker options are retrieved in the following format:
   /// `-analyzer-config CheckerName:OptionName=Value.
   /// @param [in] OptionName Name for option to retrieve.
-  /// @param [in] DefaultVal Default value returned if no such option was
-  /// specified.
   /// @param [in] SearchInParents If set to true and the searched option was 
not
   /// specified for the given checker the options for the parent packages will
   /// be searched as well. The inner packages take precedence over the outer
   /// ones.
   bool getCheckerBooleanOption(StringRef CheckerName, StringRef OptionName,
-   bool DefaultVal,
bool SearchInParents = false) const;
 
   bool getCheckerBooleanOption(const ento::CheckerBase *C, StringRef 
OptionName,
-   bool DefaultVal,
bool SearchInParents = false) const;
 
   /// Interprets an option's string value as an integer value.
@@ -305,18 +301,14 @@ public:
   /// Checker options are retrieved in the following format:
   /// `-analyzer-config CheckerName:OptionName=Value.
   /// @param [in] OptionName Name for option to retrieve.
-  /// @param [in] DefaultVal Default value returned if no such option was
-  /// specified.
   /// @param [in] SearchInParents If set to true and the searched option was 
not
   /// specified for the given checker the options for the parent packages will
   /// be searched as well. The inner packages take precedence over the outer
   /// ones.
   int getCheckerIntegerOption(StringRef CheckerName, StringRef OptionName,
-  int DefaultVal,
   bool SearchInParents = false) const;
 
   int getCheckerIntegerOption(const ento::CheckerBase *C, StringRef OptionName,
-  int DefaultVal,
   bool SearchInParents = false) const;
 
   /// Query an option's string value.
@@ -329,18 +321,15 @@ public:
   /// Checker options are retrieved in the following format:
   /// `-analyzer-config CheckerName:OptionName=Value.
   /// @param [in] OptionName Name for option to retrieve.
-  /// @param [in] DefaultVal Default value returned if no such option was
-  /// specified.
   /// @param [in] SearchInParents If set to true and the searched option was 
not
   /// specified for the given checker the options for the p

[PATCH] D59195: [analyzer] Remove the default value arg from getChecker*Option

2019-05-17 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL361042: [analyzer] Remove the default value arg from 
getChecker*Option (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59195?vs=190996&id=200052#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59195

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  cfe/trunk/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/MoveChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
  cfe/trunk/test/Analysis/checker-plugins.c
  cfe/trunk/test/Analysis/invalid-checker-option.c
  
cfe/trunk/test/Analysis/plugins/CheckerOptionHandling/CheckerOptionHandling.cpp
  cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -324,7 +324,9 @@
 return;
 
   // Insertion failed, the user supplied this package/checker option on the
-  // command line. If the supplied value is invalid, we'll emit an error.
+  // command line. If the supplied value is invalid, we'll restore the option
+  // to it's default value, and if we're in non-compatibility mode, we'll also
+  // emit an error.
 
   StringRef SuppliedValue = It.first->getValue();
 
@@ -334,6 +336,8 @@
 Diags.Report(diag::err_analyzer_checker_option_invalid_input)
 << FullOption << "a boolean value";
   }
+
+  It.first->setValue(Option.DefaultValStr);
 }
 return;
   }
@@ -346,6 +350,8 @@
 Diags.Report(diag::err_analyzer_checker_option_invalid_input)
 << FullOption << "an integer value";
   }
+
+  It.first->setValue(Option.DefaultValStr);
 }
 return;
   }
Index: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -103,8 +103,7 @@
 
 StringRef AnalyzerOptions::getCheckerStringOption(StringRef CheckerName,
   StringRef OptionName,
-  StringRef DefaultVal,
-  bool SearchInParents ) const {
+  bool SearchInParents) const {
   assert(!CheckerName.empty() &&
  "Empty checker name! Make sure the checker object (including it's "
  "bases!) if fully initialized before calling this function!");
@@ -117,62 +116,66 @@
   return StringRef(I->getValue());
 size_t Pos = CheckerName.rfind('.');
 if (Pos == StringRef::npos)
-  return DefaultVal;
+  break;
+
 CheckerName = CheckerName.substr(0, Pos);
   } while (!CheckerName.empty() && SearchInParents);
-  return DefaultVal;
+
+  llvm_unreachable("Unknown checker option! Did you call getChecker*Option "
+   "with incorrect parameters? User input must've been "
+   "verified by CheckerRegistry.");
+
+  return "";
 }
 
 StringRef AnalyzerOptions::getCheckerStringOption(const ento::CheckerBase *C,
   StringRef OptionName,
-  StringRef DefaultVal,
-  bool SearchInParents ) const {
+  bool SearchInParents) const {
   return getCheckerStringOption(
- C->getTagDescription(), OptionName, DefaultVal, SearchInParents);
+   C->getTagDescription(), OptionName, SearchInParents);
 }
 
 bool AnalyzerOptions::getCheckerBooleanOption(StringRef CheckerName,
   StringRef OptionName,
-  bool DefaultVal,
-  

[PATCH] D60568: [OpenMP] Add support for registering requires directives with the runtime

2019-05-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:9291
+  if (CGM.getLangOpts().OpenMPSimd || CGM.getLangOpts().OpenMPIsDevice ||
+  (OffloadEntriesInfoManager.empty() && !HasEmittedDeclareTargetRegion))
+return nullptr;

Missed check for `HasEmittedTargetRegion` here



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:9312
+// contain at least 1 target region.
+if ((HasEmittedTargetRegion || HasEmittedDeclareTargetRegion) &&
+HasRequiresUnifiedSharedMemory)

The first part of the condition is excessive. You have early exit from the 
function. Instead of the condition, use 
`assert((!OffloadEntriesInfoManager.empty() || HasEmittedDeclareTargetRegion || 
HasEmittedTargetRegion) && "Expected bla-bla-bla");`



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:10364
+  if (const auto *FD = dyn_cast(D)) {
+if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(FD)) {
+  HasEmittedDeclareTargetRegion = true;

gtbercea wrote:
> ABataev wrote:
> > gtbercea wrote:
> > > ABataev wrote:
> > > > gtbercea wrote:
> > > > > ABataev wrote:
> > > > > > ABataev wrote:
> > > > > > > No need for the braces
> > > > > > What if `declare target` is used only for variabes but not for the 
> > > > > > functions?
> > > > > Even more reason to error in that case since it may contain clauses 
> > > > > like link or to which need for requires directives to be used 
> > > > > consistently.
> > > > But I don't see that your patch works in this situation. Currently, it 
> > > > will emit the error only if the declare target function is found, no?
> > > Actually it will work even when just variables are used in the declare 
> > > target region. There is another problem which I have a fix for. I will 
> > > update the patch in a bit. 
> > Why will it work in this case? If you have just a declare target region in 
> > the code for the variables and nothing else. You don't have target regions, 
> > declare target functions etc. It won't work in this case.
> It will work because the OffloadEntriesInfoManager.empty() will return false 
> in that case.
But you don't have a check for `OffloadEntriesInfoManager.empty() ` when you 
set `Flags` for `__tgt_register_requires` function call.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60568



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


Re: r361033 - Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-17 Thread Yitzhak Mandelbaum via cfe-commits
Looks like this caused a breakage:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/18641/steps/ninja%20check%201/logs/stdio

On Fri, May 17, 2019 at 9:52 AM Stephen Kelly via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: steveire
> Date: Fri May 17 06:55:28 2019
> New Revision: 361033
>
> URL: http://llvm.org/viewvc/llvm-project?rev=361033&view=rev
> Log:
> Add a Visit overload for DynTypedNode to ASTNodeTraverser
>
> Reviewers: aaron.ballman
>
> Subscribers: cfe-commits
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D61834
>
> Added:
> cfe/trunk/unittests/AST/ASTTraverserTest.cpp
> Modified:
> cfe/trunk/include/clang/AST/ASTNodeTraverser.h
> cfe/trunk/unittests/AST/CMakeLists.txt
>
> Modified: cfe/trunk/include/clang/AST/ASTNodeTraverser.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTNodeTraverser.h?rev=361033&r1=361032&r2=361033&view=diff
>
> ==
> --- cfe/trunk/include/clang/AST/ASTNodeTraverser.h (original)
> +++ cfe/trunk/include/clang/AST/ASTNodeTraverser.h Fri May 17 06:55:28 2019
> @@ -205,6 +205,24 @@ public:
>  });
>}
>
> +  void Visit(const ast_type_traits::DynTypedNode &N) {
> +// FIXME: Improve this with a switch or a visitor pattern.
> +if (const auto *D = N.get())
> +  Visit(D);
> +else if (const auto *S = N.get())
> +  Visit(S);
> +else if (const auto *QT = N.get())
> +  Visit(*QT);
> +else if (const auto *T = N.get())
> +  Visit(T);
> +else if (const auto *C = N.get())
> +  Visit(C);
> +else if (const auto *C = N.get())
> +  Visit(C);
> +else if (const auto *T = N.get())
> +  Visit(*T);
> +  }
> +
>void dumpDeclContext(const DeclContext *DC) {
>  if (!DC)
>return;
>
> Added: cfe/trunk/unittests/AST/ASTTraverserTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTTraverserTest.cpp?rev=361033&view=auto
>
> ==
> --- cfe/trunk/unittests/AST/ASTTraverserTest.cpp (added)
> +++ cfe/trunk/unittests/AST/ASTTraverserTest.cpp Fri May 17 06:55:28 2019
> @@ -0,0 +1,220 @@
> +//===-
> unittests/AST/ASTTraverserTest.h===//
> +//
> +// 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 "clang/AST/ASTContext.h"
> +#include "clang/AST/ASTNodeTraverser.h"
> +#include "clang/AST/TextNodeDumper.h"
> +#include "clang/ASTMatchers/ASTMatchFinder.h"
> +#include "clang/ASTMatchers/ASTMatchers.h"
> +#include "clang/Tooling/Tooling.h"
> +#include "gmock/gmock.h"
> +#include "gtest/gtest.h"
> +
> +using namespace clang::tooling;
> +using namespace clang::ast_matchers;
> +
> +namespace clang {
> +
> +class NodeTreePrinter : public TextTreeStructure {
> +  llvm::raw_ostream &OS;
> +
> +public:
> +  NodeTreePrinter(llvm::raw_ostream &OS)
> +  : TextTreeStructure(OS, /* showColors */ false), OS(OS) {}
> +
> +  void Visit(const Decl *D) { OS << D->getDeclKindName() << "Decl"; }
> +
> +  void Visit(const Stmt *S) { OS << S->getStmtClassName(); }
> +
> +  void Visit(QualType QT) {
> +OS << "QualType " << QT.split().Quals.getAsString();
> +  }
> +
> +  void Visit(const Type *T) { OS << T->getTypeClassName() << "Type"; }
> +
> +  void Visit(const comments::Comment *C, const comments::FullComment *FC)
> {
> +OS << C->getCommentKindName();
> +  }
> +
> +  void Visit(const CXXCtorInitializer *Init) { OS <<
> "CXXCtorInitializer"; }
> +
> +  void Visit(const Attr *A) {
> +switch (A->getKind()) {
> +#define ATTR(X)
>   \
> +  case attr::X:
>   \
> +OS << #X;
>   \
> +break;
> +#include "clang/Basic/AttrList.inc"
> +}
> +OS << "Attr";
> +  }
> +
> +  void Visit(const OMPClause *C) { OS << "OMPClause"; }
> +  void Visit(const TemplateArgument &A, SourceRange R = {},
> + const Decl *From = nullptr, const char *Label = nullptr) {
> +OS << "TemplateArgument";
> +  }
> +
> +  template  void Visit(T...) {}
> +};
> +
> +class TestASTDumper : public ASTNodeTraverser NodeTreePrinter> {
> +
> +  NodeTreePrinter MyNodeRecorder;
> +
> +public:
> +  TestASTDumper(llvm::raw_ostream &OS) : MyNodeRecorder(OS) {}
> +  NodeTreePrinter &doGetNodeDelegate() { return MyNodeRecorder; }
> +};
> +
> +template  std::string dumpASTString(NodeType &&...
> N) {
> +  std::string Buffer;
> +  llvm::raw_string_ostream OS(Buffer);
> +
> +  TestASTDumper Dumper(OS);
> +
> +  OS << "\n";
> +
> +  Dumper.Visit(std::forward(N)...);
> +
> +  return OS.str();
> +}
> +
> +const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,
> +  

Re: r361011 - [analyzer] Validate checker option names and values

2019-05-17 Thread Nico Weber via cfe-commits
Looks like your r361042 fixed the ppc64be bot nonetheless. Maybe it was
related after all :)

*From: *Kristof Umann 
*Date: *Fri, May 17, 2019 at 11:10 AM
*To: *Nico Weber
*Cc: *cfe-commits

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick seems to be
> doing fine now, http://lab.llvm.org:8011/builders/clang-ppc64be-linux seems
> to crash on files totally unrelated to mine.
> --
> *From:* Kristof Umann
> *Sent:* 17 May 2019 15:59:28
> *To:* Nico Weber
> *Cc:* cfe-commits
> *Subject:* Re: r361011 - [analyzer] Validate checker option names and
> values
>
>
> I'll take a look.
> --
> *From:* Nico Weber 
> *Sent:* 17 May 2019 15:09:18
> *To:* Kristof Umann
> *Cc:* cfe-commits
> *Subject:* Re: r361011 - [analyzer] Validate checker option names and
> values
>
> It looks like this change is making gcc-7 crash on these (and other
> http://lab.llvm.org:8011/console) bots:
>
> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/18639
> http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/33837/
>
> [100/212] Building CXX object
> tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o
> FAILED:
> tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterTest.cpp.o
> ...
> g++-7: internal compiler error: Killed (program cc1plus)
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
> [101/212] Building CXX object
> tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersTraversalTest.cpp.o
> FAILED:
> tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersTraversalTest.cpp.o
>
> ...
> g++-7: internal compiler error: Killed (program cc1plus)
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
> [102/212] Building CXX object
> tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNarrowingTest.cpp.o
> FAILED:
> tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNarrowingTest.cpp.o
>
> ...
> g++-7: internal compiler error: Killed (program cc1plus)
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
> [103/212] Building CXX object
> tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNodeTest.cpp.o
> FAILED:
> tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersNodeTest.cpp.o
>
> ...
> g++-7: internal compiler error: Killed (program cc1plus)
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
> [104/212] Building CXX object
> tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/CommentHandlerTest.cpp.o
> FAILED:
> tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/CommentHandlerTest.cpp.o
>
> ...
> g++-7: internal compiler error: Killed (program cc1plus)
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
> [105/212] Building CXX object
> tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ExecutionTest.cpp.o
> FAILED:
> tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/ExecutionTest.cpp.o
>
> ...
> g++-7: internal compiler error: Killed (program cc1plus)
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
> [106/212] Building CXX object
> tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterVisibilityTest.cpp.o
> FAILED:
> tools/clang/unittests/AST/CMakeFiles/ASTTests.dir/ASTImporterVisibilityTest.cpp.o
>
> ...
> g++-7: internal compiler error: Killed (program cc1plus)
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
>
> *From: *Kristof Umann via cfe-commits 
> *Date: *Fri, May 17, 2019 at 5:49 AM
> *To: *
>
> Author: szelethus
> Date: Fri May 17 02:51:59 2019
> New Revision: 361011
>
> URL: http://llvm.org/viewvc/llvm-project?rev=361011&view=rev
> Log:
> [analyzer] Validate checker option names and values
>
> Validate whether the option exists, and also whether the supplied value is
> of
> the correct type. With this patch, invoking the analyzer should be, at
> least
> in the frontend mode, a lot safer.
>
> Differential Revision: https://reviews.llvm.org/D57860
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistry.h
> cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
> cfe/trunk/test/Analysis/checker-plugins.c
> cfe/trunk/test/Analysis/invalid-checker-option.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=361011&r1=361010&r2=361011&view=diff
>
> ==
> --- cfe/trunk/include/clang/Ba

[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-17 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

I'd add a comment with a brief explanation for the const variant and a TODO() 
to remove it.

Looks OK to me otherwise.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62046



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


[PATCH] D59887: [Syntax] Introduce TokenBuffer, start clangToolingSyntax library

2019-05-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:115
+  /// expansion.
+  llvm::Optional range(const SourceManager &SM) const;
+

sammccall wrote:
> I think this might need a more explicit name. It's reasonably obvious that 
> this needs to be optional for some cases (token pasting), but it's not 
> obvious at callsites that (or why) we don't use the spelling location for 
> macro-expanded tokens.
> 
> One option would be just do that and add an expandedFromMacro() helper so the 
> no-macros version is easy to express too.
> If we can't do that, maybe `directlySpelledRange` or something?
As mentioned in the offline conversation, the idea is that mapping from a token 
inside a macro expansion to a spelled token should be handled by `TokenBuffer` 
and these two functions is really just a convenience helper to get to a range 
*after* the mapping.

This change has been boiling for some time and I think the other bits of it 
seem to be non-controversial and agreed upon.
Would it be ok if we land it with this function using a more concrete name 
(`directlySpelledRange` or something else) or move it into a separate change?

There's a follow-up change that adds an 'expand macro' action to clangd, which 
both has a use-site for these method and provides a functional feature based on 
`TokenBuffer`. Iterating on the design with (even a single) use-case should be 
simpler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59887



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


[PATCH] D61774: [LibTooling] Add RangeSelector library for defining source ranges based on bound AST nodes.

2019-05-17 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 200061.
ymandel marked 4 inline comments as done.
ymandel added a comment.

Restructured tests to simplify.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61774

Files:
  clang/include/clang/Tooling/Refactoring/RangeSelector.h
  clang/lib/Tooling/Refactoring/CMakeLists.txt
  clang/lib/Tooling/Refactoring/RangeSelector.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/RangeSelectorTest.cpp

Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -0,0 +1,497 @@
+//===- unittest/Tooling/RangeSelectorTest.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
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/RangeSelector.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/FixIt.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace tooling;
+using namespace ast_matchers;
+
+namespace {
+using ::testing::AllOf;
+using ::testing::HasSubstr;
+using MatchResult = MatchFinder::MatchResult;
+using ::llvm::Expected;
+using ::llvm::Failed;
+using ::llvm::HasValue;
+using ::llvm::StringError;
+
+struct TestMatch {
+  // The AST unit from which `result` is built. We bundle it because it backs
+  // the result. Users are not expected to access it.
+  std::unique_ptr ASTUnit;
+  // The result to use in the test. References `ast_unit`.
+  MatchResult Result;
+};
+
+template  TestMatch matchCode(StringRef Code, M Matcher) {
+  auto ASTUnit = buildASTFromCode(Code);
+  assert(ASTUnit != nullptr && "AST construction failed");
+
+  ASTContext &Context = ASTUnit->getASTContext();
+  assert(!Context.getDiagnostics().hasErrorOccurred() && "Compilation error");
+
+  auto Matches = ast_matchers::match(Matcher, Context);
+  // We expect a single, exact match.
+  assert(Matches.size() != 0 && "no matches found");
+  assert(Matches.size() == 1 && "too many matches");
+
+  return TestMatch{std::move(ASTUnit), MatchResult(Matches[0], &Context)};
+}
+
+// Applies \p Selector to \p Match and, on success, returns the selected source.
+Expected apply(RangeSelector Selector, const TestMatch &Match) {
+  Expected Range = Selector(Match.Result);
+  if (!Range)
+return Range.takeError();
+  return fixit::internal::getText(*Range, *Match.Result.Context);
+}
+
+// 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) {
+  // 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 =
+  matchCode("static int x = 0;", varDecl().bind("bound_node_id"));
+  return Selector(Match.Result);
+}
+
+// Matches the message expected for unbound-node failures.
+testing::Matcher withUnboundNodeMessage() {
+  return testing::Property(
+  &StringError::getMessage,
+  AllOf(HasSubstr("unbound_id"), HasSubstr("not bound")));
+}
+
+// Applies \p Selector to code containing assorted node types, where the match
+// 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) {
+  StringRef Code = R"cc(
+  struct A {};
+  class F : public A {
+   public:
+F(int) {}
+  };
+  void g() { F f(1); }
+)cc";
+
+  auto Matcher =
+  compoundStmt(
+  hasDescendant(
+  cxxConstructExpr(
+  hasDeclaration(
+  decl(hasDescendant(cxxCtorInitializer(isBaseInitializer())
+ .bind("init")))
+  .bind("decl")))
+  .bind("expr")))
+  .bind("stmt");
+
+  return Selector(matchCode(Code, Matcher).Result);
+}
+
+// Matches the message expected for type-error failures.
+testing::Matcher withTypeErrorMessage(StringRef NodeID) {
+  return testing::Property(
+  &StringError::getMessage,
+  AllOf(HasSubstr(NodeID), HasSubstr("mismatched type")));
+}
+
+TEST(RangeSelectorTest, UnboundNode) {
+  EXPECT_THAT_EXPECTED(applyToTrivial(node("unbound_id")),
+   Failed(withUnboundNodeMessage()));
+}
+
+TEST(RangeSelectorTest, Ra

[PATCH] D61774: [LibTooling] Add RangeSelector library for defining source ranges based on bound AST nodes.

2019-05-17 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 7 inline comments as done.
ymandel added inline comments.



Comment at: clang/include/clang/Tooling/Refactoring/RangeSelector.h:29
+
+namespace range_selector {
+inline RangeSelector charRange(CharSourceRange R) {

ilya-biryukov wrote:
> ymandel wrote:
> > ilya-biryukov wrote:
> > > Maybe try putting it into the tooling namespace directly?
> > > Or are there immediate and unfortunate conflicts with existing names?
> > > 
> > > 
> > No conflicts. Was just being cautious.
> I can see why a separate namespace would make sense, but since the `tooling` 
> namespace  is not densely populated I hope we can get away with putting 
> things here directly and saving some typing on the use-sites.
> 
> Hope that does not backfire in the future, though.
SGTM. 



Comment at: clang/unittests/Tooling/RangeSelectorTest.cpp:143
+  // Node-id specific version:
+  test(Matcher, range(Arg0, Arg1), Code, "3, 7");
+  // General version:

ilya-biryukov wrote:
> Consider restructuring the code to place assertions into the test function 
> itself.
> This wildly improves locations reported in case of test failures and makes 
> tests easier to read.
> 
> I.e. having something like
> ```
> auto AST = buildASTAndMatch(Code, Matcher);
> EXPECT_EQ(applySelector(range(Arg0, Arg1), AST),  "3, 7");
> ```
> is arguably both easier to read and produces better location information on 
> failures than a function that runs the test.
> Even though it's a bit more code.
> 
> 
> Note that it's a bit more complicated if you need to deal with `Expected<>` 
> return types, but still possible:
> ```
> EXPECT_THAT_EXPECTED(applySelector(range(Arg0, Arg1), AST),  HasValue("3, 
> 7"));
> EXPECT_THAT_EXPECTED(applySelector(range(Arg1, Arg0), AST),  Failed());
> ```
Thanks for the suggestion. Thoroughly reworked the tests along these lines. I 
think the result is much clearer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61774



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


[PATCH] D58035: [clang/DIVar] Emit flag for params that have unchanged values

2019-05-17 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:4537
+  CGM.getLangOpts().Optimize) {
+for (auto &SP : DeclCache) {
+  auto *D = SP.first;

djtodoro wrote:
> aprantl wrote:
> > djtodoro wrote:
> > > aprantl wrote:
> > > > Just looking at the type declarations in CGDebugInfo.h: Why not iterate 
> > > > over the `SPCache`  directly? Shouldn't that contain all Function 
> > > > declarations only?
> > > I tried it, but `SPCache` is empty at this point.
> > Where is it emptied? Just grepping through CGDebugInfo did not make this 
> > obvious to me.
> The `SPCache` actually gets filled only in the case of `CXXMemberFunction`.
> In the other cases of `SP` production there is only filling of `DeclCache`.
> Should we use it like this or ?
If the number of entries in the DeclCache is much larger than the size of 
SPCache, we should keep them separate to speed up this loop. Otherwise we 
should join them to conserve memory.


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

https://reviews.llvm.org/D58035



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


[PATCH] D59887: [Syntax] Introduce TokenBuffer, start clangToolingSyntax library

2019-05-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:115
+  /// expansion.
+  llvm::Optional range(const SourceManager &SM) const;
+

ilya-biryukov wrote:
> sammccall wrote:
> > I think this might need a more explicit name. It's reasonably obvious that 
> > this needs to be optional for some cases (token pasting), but it's not 
> > obvious at callsites that (or why) we don't use the spelling location for 
> > macro-expanded tokens.
> > 
> > One option would be just do that and add an expandedFromMacro() helper so 
> > the no-macros version is easy to express too.
> > If we can't do that, maybe `directlySpelledRange` or something?
> As mentioned in the offline conversation, the idea is that mapping from a 
> token inside a macro expansion to a spelled token should be handled by 
> `TokenBuffer` and these two functions is really just a convenience helper to 
> get to a range *after* the mapping.
> 
> This change has been boiling for some time and I think the other bits of it 
> seem to be non-controversial and agreed upon.
> Would it be ok if we land it with this function using a more concrete name 
> (`directlySpelledRange` or something else) or move it into a separate change?
> 
> There's a follow-up change that adds an 'expand macro' action to clangd, 
> which both has a use-site for these method and provides a functional feature 
> based on `TokenBuffer`. Iterating on the design with (even a single) use-case 
> should be simpler.
If we do want to reflect expanded/spelled as types, this will rapidly get 
harder to change. But we do need to make progress here.

If passing spelled tokens is the intended/well-understood use, let's just 
assert on that and not return Optional. Then I'm less worried about the name: 
misuse will be reliably punished.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59887



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


[PATCH] D61522: Added an assertion to constant evaluation enty points that prohibits dependent expressions

2019-05-17 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL361050: Added an assertion to constant evaluation enty 
points that prohibits dependent… (authored by gribozavr, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61522?vs=198603&id=200062#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61522

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

Index: cfe/trunk/lib/AST/Expr.cpp
===
--- cfe/trunk/lib/AST/Expr.cpp
+++ cfe/trunk/lib/AST/Expr.cpp
@@ -2974,6 +2974,9 @@
 
 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
Index: cfe/trunk/lib/AST/ExprConstant.cpp
===
--- cfe/trunk/lib/AST/ExprConstant.cpp
+++ cfe/trunk/lib/AST/ExprConstant.cpp
@@ -11642,6 +11642,8 @@
 /// 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::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::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::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::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::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx,
  const VarDecl *VD,
 SmallVectorImpl &Notes) const {
+  assert(!isValueDependent() &&
+ "Expression evaluator can't be called on a dependent expression.");
+
   // FIXME: Evaluating initializers for large array and record types can cause
   // performance problems. Only do so in C++11 for now.
   if (isRValue() && (getType()->isArrayType() || getType()->isRecordType()) &&
@@ -11752,6 +11772,9 @@
 /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
 /// constant folded, but discard the result.
 bool Expr::isEvaluatable(const ASTContext &Ctx, SideEffectsKind SEK) const {
+  assert(!isValueDependent() &&
+ "Expressio

Re: r360998 - Fix crash if, during evaluation of __builtin_object_size, we try to load

2019-05-17 Thread Nico Weber via cfe-commits
The test fails on Windows:


*From: *Richard Smith via cfe-commits 
*Date: *Fri, May 17, 2019 at 3:58 AM
*To: * 

Author: rsmith
> Date: Fri May 17 01:01:34 2019
> New Revision: 360998
>
> URL: http://llvm.org/viewvc/llvm-project?rev=360998&view=rev
> Log:
> Fix crash if, during evaluation of __builtin_object_size, we try to load
> through an invalid base.
>
> Modified:
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=360998&r1=360997&r2=360998&view=diff
>
> ==
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 17 01:01:34 2019
> @@ -3285,6 +3285,11 @@ static bool AreElementsOfSameArray(QualT
>  static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E,
>   AccessKinds AK, const LValue
> &LVal,
>   QualType LValType) {
> +  if (LVal.InvalidBase) {
> +Info.FFDiag(E);
> +return CompleteObject();
> +  }
> +
>if (!LVal.Base) {
>  Info.FFDiag(E, diag::note_constexpr_access_null) << AK;
>  return CompleteObject();
>
> Modified: cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp?rev=360998&r1=360997&r2=360998&view=diff
>
> ==
> --- cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp (original)
> +++ cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp Fri May 17
> 01:01:34 2019
> @@ -97,3 +97,10 @@ void tooSmallBuf() {
>copy5CharsIntoStrict(small.buf); // expected-error{{no matching
> function for call}}
>  }
>  }
> +
> +namespace InvalidBase {
> +  // Ensure this doesn't crash.
> +  struct S { const char *name; };
> +  S invalid_base();
> +  constexpr long bos_name = __builtin_object_size(invalid_base().name, 1);
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r360998 - Fix crash if, during evaluation of __builtin_object_size, we try to load

2019-05-17 Thread Nico Weber via cfe-commits
-- Testing: 49966 tests, 32 threads --
Testing: 0 .. 10.. 20..
FAIL: Clang :: SemaCXX/builtin-object-size-cxx14.cpp (14324 of 49966)
 TEST 'Clang :: SemaCXX/builtin-object-size-cxx14.cpp'
FAILED 
Script:
--
: 'RUN: at line 1';
c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\bin\clang.exe -cc1
-internal-isystem
c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\lib\clang\9.0.0\include
-nostdsysteminc -fsyntax-only -verify -std=c++14
C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp
--
Exit Code: 1

Command Output (stdout):
--
$ ":" "RUN: at line 1"
$ "c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\bin\clang.exe" "-cc1"
"-internal-isystem"
"c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\lib\clang\9.0.0\include"
"-nostdsysteminc" "-fsyntax-only" "-verify" "-std=c++14"
"C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp"
# command stderr:
error: 'warning' diagnostics seen but not expected:
  File
C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp
Line 105: implicit conversion from 'unsigned long long' to 'const long'
changes value from 18446744073709551615 to -1
1 error generated.

error: command failed with exit status: 1

https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8913196957157807760/+/steps/package_clang/0/stdout

*From: *Nico Weber 
*Date: *Fri, May 17, 2019 at 1:13 PM
*To: *Richard Smith
*Cc: *cfe-commits

The test fails on Windows:
>
>
> *From: *Richard Smith via cfe-commits 
> *Date: *Fri, May 17, 2019 at 3:58 AM
> *To: * 
>
> Author: rsmith
>> Date: Fri May 17 01:01:34 2019
>> New Revision: 360998
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=360998&view=rev
>> Log:
>> Fix crash if, during evaluation of __builtin_object_size, we try to load
>> through an invalid base.
>>
>> Modified:
>> cfe/trunk/lib/AST/ExprConstant.cpp
>> cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
>>
>> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=360998&r1=360997&r2=360998&view=diff
>>
>> ==
>> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
>> +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 17 01:01:34 2019
>> @@ -3285,6 +3285,11 @@ static bool AreElementsOfSameArray(QualT
>>  static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E,
>>   AccessKinds AK, const LValue
>> &LVal,
>>   QualType LValType) {
>> +  if (LVal.InvalidBase) {
>> +Info.FFDiag(E);
>> +return CompleteObject();
>> +  }
>> +
>>if (!LVal.Base) {
>>  Info.FFDiag(E, diag::note_constexpr_access_null) << AK;
>>  return CompleteObject();
>>
>> Modified: cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp?rev=360998&r1=360997&r2=360998&view=diff
>>
>> ==
>> --- cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp Fri May 17
>> 01:01:34 2019
>> @@ -97,3 +97,10 @@ void tooSmallBuf() {
>>copy5CharsIntoStrict(small.buf); // expected-error{{no matching
>> function for call}}
>>  }
>>  }
>> +
>> +namespace InvalidBase {
>> +  // Ensure this doesn't crash.
>> +  struct S { const char *name; };
>> +  S invalid_base();
>> +  constexpr long bos_name = __builtin_object_size(invalid_base().name,
>> 1);
>> +}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
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

Re: r360998 - Fix crash if, during evaluation of __builtin_object_size, we try to load

2019-05-17 Thread Nico Weber via cfe-commits
Also on the LLVM waterfall:
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/6937/steps/stage%201%20check/logs/stdio

(Same error.)

*From: *Nico Weber 
*Date: *Fri, May 17, 2019 at 1:14 PM
*To: *Richard Smith
*Cc: *cfe-commits

-- Testing: 49966 tests, 32 threads --
> Testing: 0 .. 10.. 20..
> FAIL: Clang :: SemaCXX/builtin-object-size-cxx14.cpp (14324 of 49966)
>  TEST 'Clang :: SemaCXX/builtin-object-size-cxx14.cpp'
> FAILED 
> Script:
> --
> : 'RUN: at line 1';
> c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\bin\clang.exe -cc1
> -internal-isystem
> c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\lib\clang\9.0.0\include
> -nostdsysteminc -fsyntax-only -verify -std=c++14
> C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp
> --
> Exit Code: 1
>
> Command Output (stdout):
> --
> $ ":" "RUN: at line 1"
> $ "c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\bin\clang.exe" "-cc1"
> "-internal-isystem"
> "c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\lib\clang\9.0.0\include"
> "-nostdsysteminc" "-fsyntax-only" "-verify" "-std=c++14"
> "C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp"
> # command stderr:
> error: 'warning' diagnostics seen but not expected:
>   File
> C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp
> Line 105: implicit conversion from 'unsigned long long' to 'const long'
> changes value from 18446744073709551615 to -1
> 1 error generated.
>
> error: command failed with exit status: 1
>
>
> https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8913196957157807760/+/steps/package_clang/0/stdout
>
> *From: *Nico Weber 
> *Date: *Fri, May 17, 2019 at 1:13 PM
> *To: *Richard Smith
> *Cc: *cfe-commits
>
> The test fails on Windows:
>>
>>
>> *From: *Richard Smith via cfe-commits 
>> *Date: *Fri, May 17, 2019 at 3:58 AM
>> *To: * 
>>
>> Author: rsmith
>>> Date: Fri May 17 01:01:34 2019
>>> New Revision: 360998
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=360998&view=rev
>>> Log:
>>> Fix crash if, during evaluation of __builtin_object_size, we try to load
>>> through an invalid base.
>>>
>>> Modified:
>>> cfe/trunk/lib/AST/ExprConstant.cpp
>>> cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
>>>
>>> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=360998&r1=360997&r2=360998&view=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
>>> +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 17 01:01:34 2019
>>> @@ -3285,6 +3285,11 @@ static bool AreElementsOfSameArray(QualT
>>>  static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E,
>>>   AccessKinds AK, const LValue
>>> &LVal,
>>>   QualType LValType) {
>>> +  if (LVal.InvalidBase) {
>>> +Info.FFDiag(E);
>>> +return CompleteObject();
>>> +  }
>>> +
>>>if (!LVal.Base) {
>>>  Info.FFDiag(E, diag::note_constexpr_access_null) << AK;
>>>  return CompleteObject();
>>>
>>> Modified: cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp?rev=360998&r1=360997&r2=360998&view=diff
>>>
>>> ==
>>> --- cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp (original)
>>> +++ cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp Fri May 17
>>> 01:01:34 2019
>>> @@ -97,3 +97,10 @@ void tooSmallBuf() {
>>>copy5CharsIntoStrict(small.buf); // expected-error{{no matching
>>> function for call}}
>>>  }
>>>  }
>>> +
>>> +namespace InvalidBase {
>>> +  // Ensure this doesn't crash.
>>> +  struct S { const char *name; };
>>> +  S invalid_base();
>>> +  constexpr long bos_name = __builtin_object_size(invalid_base().name,
>>> 1);
>>> +}
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r361054 - Attempt to fix test on Windows after r360998

2019-05-17 Thread Nico Weber via cfe-commits
Author: nico
Date: Fri May 17 10:33:54 2019
New Revision: 361054

URL: http://llvm.org/viewvc/llvm-project?rev=361054&view=rev
Log:
Attempt to fix test on Windows after r360998

Modified:
cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp

Modified: cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp?rev=361054&r1=361053&r2=361054&view=diff
==
--- cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp (original)
+++ cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp Fri May 17 10:33:54 
2019
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
 
+typedef __SIZE_TYPE__ size_t;
+
 namespace basic {
 // Ensuring that __bos can be used in constexpr functions without anything
 // sketchy going on...
@@ -102,5 +104,5 @@ namespace InvalidBase {
   // Ensure this doesn't crash.
   struct S { const char *name; };
   S invalid_base();
-  constexpr long bos_name = __builtin_object_size(invalid_base().name, 1);
+  constexpr size_t bos_name = __builtin_object_size(invalid_base().name, 1);
 }


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


Re: r360998 - Fix crash if, during evaluation of __builtin_object_size, we try to load

2019-05-17 Thread Nico Weber via cfe-commits
I attempted to fix this in 361054.

*From: *Nico Weber 
*Date: *Fri, May 17, 2019 at 1:16 PM
*To: *Richard Smith
*Cc: *cfe-commits

Also on the LLVM waterfall:
> http://lab.llvm.org:8011/builders/clang-x64-windows-msvc
>
> http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/6937/steps/stage%201%20check/logs/stdio
>
> (Same error.)
>
> *From: *Nico Weber 
> *Date: *Fri, May 17, 2019 at 1:14 PM
> *To: *Richard Smith
> *Cc: *cfe-commits
>
> -- Testing: 49966 tests, 32 threads --
>> Testing: 0 .. 10.. 20..
>> FAIL: Clang :: SemaCXX/builtin-object-size-cxx14.cpp (14324 of 49966)
>>  TEST 'Clang ::
>> SemaCXX/builtin-object-size-cxx14.cpp' FAILED 
>> Script:
>> --
>> : 'RUN: at line 1';
>> c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\bin\clang.exe -cc1
>> -internal-isystem
>> c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\lib\clang\9.0.0\include
>> -nostdsysteminc -fsyntax-only -verify -std=c++14
>> C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp
>> --
>> Exit Code: 1
>>
>> Command Output (stdout):
>> --
>> $ ":" "RUN: at line 1"
>> $ "c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\bin\clang.exe" "-cc1"
>> "-internal-isystem"
>> "c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\lib\clang\9.0.0\include"
>> "-nostdsysteminc" "-fsyntax-only" "-verify" "-std=c++14"
>> "C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp"
>> # command stderr:
>> error: 'warning' diagnostics seen but not expected:
>>   File
>> C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp
>> Line 105: implicit conversion from 'unsigned long long' to 'const long'
>> changes value from 18446744073709551615 to -1
>> 1 error generated.
>>
>> error: command failed with exit status: 1
>>
>>
>> https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8913196957157807760/+/steps/package_clang/0/stdout
>>
>> *From: *Nico Weber 
>> *Date: *Fri, May 17, 2019 at 1:13 PM
>> *To: *Richard Smith
>> *Cc: *cfe-commits
>>
>> The test fails on Windows:
>>>
>>>
>>> *From: *Richard Smith via cfe-commits 
>>> *Date: *Fri, May 17, 2019 at 3:58 AM
>>> *To: * 
>>>
>>> Author: rsmith
 Date: Fri May 17 01:01:34 2019
 New Revision: 360998

 URL: http://llvm.org/viewvc/llvm-project?rev=360998&view=rev
 Log:
 Fix crash if, during evaluation of __builtin_object_size, we try to load
 through an invalid base.

 Modified:
 cfe/trunk/lib/AST/ExprConstant.cpp
 cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp

 Modified: cfe/trunk/lib/AST/ExprConstant.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=360998&r1=360997&r2=360998&view=diff

 ==
 --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
 +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 17 01:01:34 2019
 @@ -3285,6 +3285,11 @@ static bool AreElementsOfSameArray(QualT
  static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E,
   AccessKinds AK, const LValue
 &LVal,
   QualType LValType) {
 +  if (LVal.InvalidBase) {
 +Info.FFDiag(E);
 +return CompleteObject();
 +  }
 +
if (!LVal.Base) {
  Info.FFDiag(E, diag::note_constexpr_access_null) << AK;
  return CompleteObject();

 Modified: cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp?rev=360998&r1=360997&r2=360998&view=diff

 ==
 --- cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp (original)
 +++ cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp Fri May 17
 01:01:34 2019
 @@ -97,3 +97,10 @@ void tooSmallBuf() {
copy5CharsIntoStrict(small.buf); // expected-error{{no matching
 function for call}}
  }
  }
 +
 +namespace InvalidBase {
 +  // Ensure this doesn't crash.
 +  struct S { const char *name; };
 +  S invalid_base();
 +  constexpr long bos_name = __builtin_object_size(invalid_base().name,
 1);
 +}


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

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


Re: r361033 - Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-17 Thread Stephen Kelly via cfe-commits
Hmm, thanks for letting me know!

Is that an old compiler?

I'm not near a computer for the weekend.

Can someone fix or revert?

Thanks,

Stephen.

On Fri 17 May 2019, 17:11 Yitzhak Mandelbaum,  wrote:

> Looks like this caused a breakage:
> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/18641/steps/ninja%20check%201/logs/stdio
>
> On Fri, May 17, 2019 at 9:52 AM Stephen Kelly via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: steveire
>> Date: Fri May 17 06:55:28 2019
>> New Revision: 361033
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=361033&view=rev
>> Log:
>> Add a Visit overload for DynTypedNode to ASTNodeTraverser
>>
>> Reviewers: aaron.ballman
>>
>> Subscribers: cfe-commits
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D61834
>>
>> Added:
>> cfe/trunk/unittests/AST/ASTTraverserTest.cpp
>> Modified:
>> cfe/trunk/include/clang/AST/ASTNodeTraverser.h
>> cfe/trunk/unittests/AST/CMakeLists.txt
>>
>> Modified: cfe/trunk/include/clang/AST/ASTNodeTraverser.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTNodeTraverser.h?rev=361033&r1=361032&r2=361033&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/AST/ASTNodeTraverser.h (original)
>> +++ cfe/trunk/include/clang/AST/ASTNodeTraverser.h Fri May 17 06:55:28
>> 2019
>> @@ -205,6 +205,24 @@ public:
>>  });
>>}
>>
>> +  void Visit(const ast_type_traits::DynTypedNode &N) {
>> +// FIXME: Improve this with a switch or a visitor pattern.
>> +if (const auto *D = N.get())
>> +  Visit(D);
>> +else if (const auto *S = N.get())
>> +  Visit(S);
>> +else if (const auto *QT = N.get())
>> +  Visit(*QT);
>> +else if (const auto *T = N.get())
>> +  Visit(T);
>> +else if (const auto *C = N.get())
>> +  Visit(C);
>> +else if (const auto *C = N.get())
>> +  Visit(C);
>> +else if (const auto *T = N.get())
>> +  Visit(*T);
>> +  }
>> +
>>void dumpDeclContext(const DeclContext *DC) {
>>  if (!DC)
>>return;
>>
>> Added: cfe/trunk/unittests/AST/ASTTraverserTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTTraverserTest.cpp?rev=361033&view=auto
>>
>> ==
>> --- cfe/trunk/unittests/AST/ASTTraverserTest.cpp (added)
>> +++ cfe/trunk/unittests/AST/ASTTraverserTest.cpp Fri May 17 06:55:28 2019
>> @@ -0,0 +1,220 @@
>> +//===-
>> unittests/AST/ASTTraverserTest.h===//
>> +//
>> +// 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 "clang/AST/ASTContext.h"
>> +#include "clang/AST/ASTNodeTraverser.h"
>> +#include "clang/AST/TextNodeDumper.h"
>> +#include "clang/ASTMatchers/ASTMatchFinder.h"
>> +#include "clang/ASTMatchers/ASTMatchers.h"
>> +#include "clang/Tooling/Tooling.h"
>> +#include "gmock/gmock.h"
>> +#include "gtest/gtest.h"
>> +
>> +using namespace clang::tooling;
>> +using namespace clang::ast_matchers;
>> +
>> +namespace clang {
>> +
>> +class NodeTreePrinter : public TextTreeStructure {
>> +  llvm::raw_ostream &OS;
>> +
>> +public:
>> +  NodeTreePrinter(llvm::raw_ostream &OS)
>> +  : TextTreeStructure(OS, /* showColors */ false), OS(OS) {}
>> +
>> +  void Visit(const Decl *D) { OS << D->getDeclKindName() << "Decl"; }
>> +
>> +  void Visit(const Stmt *S) { OS << S->getStmtClassName(); }
>> +
>> +  void Visit(QualType QT) {
>> +OS << "QualType " << QT.split().Quals.getAsString();
>> +  }
>> +
>> +  void Visit(const Type *T) { OS << T->getTypeClassName() << "Type"; }
>> +
>> +  void Visit(const comments::Comment *C, const comments::FullComment
>> *FC) {
>> +OS << C->getCommentKindName();
>> +  }
>> +
>> +  void Visit(const CXXCtorInitializer *Init) { OS <<
>> "CXXCtorInitializer"; }
>> +
>> +  void Visit(const Attr *A) {
>> +switch (A->getKind()) {
>> +#define ATTR(X)
>>   \
>> +  case attr::X:
>>   \
>> +OS << #X;
>>   \
>> +break;
>> +#include "clang/Basic/AttrList.inc"
>> +}
>> +OS << "Attr";
>> +  }
>> +
>> +  void Visit(const OMPClause *C) { OS << "OMPClause"; }
>> +  void Visit(const TemplateArgument &A, SourceRange R = {},
>> + const Decl *From = nullptr, const char *Label = nullptr) {
>> +OS << "TemplateArgument";
>> +  }
>> +
>> +  template  void Visit(T...) {}
>> +};
>> +
>> +class TestASTDumper : public ASTNodeTraverser> NodeTreePrinter> {
>> +
>> +  NodeTreePrinter MyNodeRecorder;
>> +
>> +public:
>> +  TestASTDumper(llvm::raw_ostream &OS) : MyNodeRecorder(OS) {}
>> +  NodeTreePrinter &doGetNodeDelegate() { return MyNodeRecorder; }
>> +};
>

Re: r361033 - Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-17 Thread Yitzhak Mandelbaum via cfe-commits
i'll see if i can repro on my build and fix if so.

On Fri, May 17, 2019 at 1:56 PM Stephen Kelly  wrote:

> Hmm, thanks for letting me know!
>
> Is that an old compiler?
>
> I'm not near a computer for the weekend.
>
> Can someone fix or revert?
>
> Thanks,
>
> Stephen.
>
> On Fri 17 May 2019, 17:11 Yitzhak Mandelbaum,  wrote:
>
>> Looks like this caused a breakage:
>> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/18641/steps/ninja%20check%201/logs/stdio
>>
>> On Fri, May 17, 2019 at 9:52 AM Stephen Kelly via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: steveire
>>> Date: Fri May 17 06:55:28 2019
>>> New Revision: 361033
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=361033&view=rev
>>> Log:
>>> Add a Visit overload for DynTypedNode to ASTNodeTraverser
>>>
>>> Reviewers: aaron.ballman
>>>
>>> Subscribers: cfe-commits
>>>
>>> Tags: #clang
>>>
>>> Differential Revision: https://reviews.llvm.org/D61834
>>>
>>> Added:
>>> cfe/trunk/unittests/AST/ASTTraverserTest.cpp
>>> Modified:
>>> cfe/trunk/include/clang/AST/ASTNodeTraverser.h
>>> cfe/trunk/unittests/AST/CMakeLists.txt
>>>
>>> Modified: cfe/trunk/include/clang/AST/ASTNodeTraverser.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTNodeTraverser.h?rev=361033&r1=361032&r2=361033&view=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/AST/ASTNodeTraverser.h (original)
>>> +++ cfe/trunk/include/clang/AST/ASTNodeTraverser.h Fri May 17 06:55:28
>>> 2019
>>> @@ -205,6 +205,24 @@ public:
>>>  });
>>>}
>>>
>>> +  void Visit(const ast_type_traits::DynTypedNode &N) {
>>> +// FIXME: Improve this with a switch or a visitor pattern.
>>> +if (const auto *D = N.get())
>>> +  Visit(D);
>>> +else if (const auto *S = N.get())
>>> +  Visit(S);
>>> +else if (const auto *QT = N.get())
>>> +  Visit(*QT);
>>> +else if (const auto *T = N.get())
>>> +  Visit(T);
>>> +else if (const auto *C = N.get())
>>> +  Visit(C);
>>> +else if (const auto *C = N.get())
>>> +  Visit(C);
>>> +else if (const auto *T = N.get())
>>> +  Visit(*T);
>>> +  }
>>> +
>>>void dumpDeclContext(const DeclContext *DC) {
>>>  if (!DC)
>>>return;
>>>
>>> Added: cfe/trunk/unittests/AST/ASTTraverserTest.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTTraverserTest.cpp?rev=361033&view=auto
>>>
>>> ==
>>> --- cfe/trunk/unittests/AST/ASTTraverserTest.cpp (added)
>>> +++ cfe/trunk/unittests/AST/ASTTraverserTest.cpp Fri May 17 06:55:28 2019
>>> @@ -0,0 +1,220 @@
>>> +//===-
>>> unittests/AST/ASTTraverserTest.h===//
>>> +//
>>> +// 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 "clang/AST/ASTContext.h"
>>> +#include "clang/AST/ASTNodeTraverser.h"
>>> +#include "clang/AST/TextNodeDumper.h"
>>> +#include "clang/ASTMatchers/ASTMatchFinder.h"
>>> +#include "clang/ASTMatchers/ASTMatchers.h"
>>> +#include "clang/Tooling/Tooling.h"
>>> +#include "gmock/gmock.h"
>>> +#include "gtest/gtest.h"
>>> +
>>> +using namespace clang::tooling;
>>> +using namespace clang::ast_matchers;
>>> +
>>> +namespace clang {
>>> +
>>> +class NodeTreePrinter : public TextTreeStructure {
>>> +  llvm::raw_ostream &OS;
>>> +
>>> +public:
>>> +  NodeTreePrinter(llvm::raw_ostream &OS)
>>> +  : TextTreeStructure(OS, /* showColors */ false), OS(OS) {}
>>> +
>>> +  void Visit(const Decl *D) { OS << D->getDeclKindName() << "Decl"; }
>>> +
>>> +  void Visit(const Stmt *S) { OS << S->getStmtClassName(); }
>>> +
>>> +  void Visit(QualType QT) {
>>> +OS << "QualType " << QT.split().Quals.getAsString();
>>> +  }
>>> +
>>> +  void Visit(const Type *T) { OS << T->getTypeClassName() << "Type"; }
>>> +
>>> +  void Visit(const comments::Comment *C, const comments::FullComment
>>> *FC) {
>>> +OS << C->getCommentKindName();
>>> +  }
>>> +
>>> +  void Visit(const CXXCtorInitializer *Init) { OS <<
>>> "CXXCtorInitializer"; }
>>> +
>>> +  void Visit(const Attr *A) {
>>> +switch (A->getKind()) {
>>> +#define ATTR(X)
>>> \
>>> +  case attr::X:
>>> \
>>> +OS << #X;
>>> \
>>> +break;
>>> +#include "clang/Basic/AttrList.inc"
>>> +}
>>> +OS << "Attr";
>>> +  }
>>> +
>>> +  void Visit(const OMPClause *C) { OS << "OMPClause"; }
>>> +  void Visit(const TemplateArgument &A, SourceRange R = {},
>>> + const Decl *From = nullptr, const char *Label = nullptr) {
>>> +OS << "TemplateArgument";
>>> +  }
>>> +
>>> +  template  void Visit(T...) {}
>>> +};
>>> 

Re: r360998 - Fix crash if, during evaluation of __builtin_object_size, we try to load

2019-05-17 Thread Richard Smith via cfe-commits
Looks good, thanks :)

On Fri, 17 May 2019, 10:31 Nico Weber via cfe-commits, <
cfe-commits@lists.llvm.org> wrote:

> I attempted to fix this in 361054.
>
> *From: *Nico Weber 
> *Date: *Fri, May 17, 2019 at 1:16 PM
> *To: *Richard Smith
> *Cc: *cfe-commits
>
> Also on the LLVM waterfall:
>> http://lab.llvm.org:8011/builders/clang-x64-windows-msvc
>>
>> http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/6937/steps/stage%201%20check/logs/stdio
>>
>> (Same error.)
>>
>> *From: *Nico Weber 
>> *Date: *Fri, May 17, 2019 at 1:14 PM
>> *To: *Richard Smith
>> *Cc: *cfe-commits
>>
>> -- Testing: 49966 tests, 32 threads --
>>> Testing: 0 .. 10.. 20..
>>> FAIL: Clang :: SemaCXX/builtin-object-size-cxx14.cpp (14324 of 49966)
>>>  TEST 'Clang ::
>>> SemaCXX/builtin-object-size-cxx14.cpp' FAILED 
>>> Script:
>>> --
>>> : 'RUN: at line 1';
>>> c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\bin\clang.exe -cc1
>>> -internal-isystem
>>> c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\lib\clang\9.0.0\include
>>> -nostdsysteminc -fsyntax-only -verify -std=c++14
>>> C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp
>>> --
>>> Exit Code: 1
>>>
>>> Command Output (stdout):
>>> --
>>> $ ":" "RUN: at line 1"
>>> $ "c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\bin\clang.exe" "-cc1"
>>> "-internal-isystem"
>>> "c:\b\s\w\ir\k\src\third_party\llvm-bootstrap\lib\clang\9.0.0\include"
>>> "-nostdsysteminc" "-fsyntax-only" "-verify" "-std=c++14"
>>> "C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp"
>>> # command stderr:
>>> error: 'warning' diagnostics seen but not expected:
>>>   File
>>> C:\b\s\w\ir\k\src\third_party\llvm\tools\clang\test\SemaCXX\builtin-object-size-cxx14.cpp
>>> Line 105: implicit conversion from 'unsigned long long' to 'const long'
>>> changes value from 18446744073709551615 to -1
>>> 1 error generated.
>>>
>>> error: command failed with exit status: 1
>>>
>>>
>>> https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8913196957157807760/+/steps/package_clang/0/stdout
>>>
>>> *From: *Nico Weber 
>>> *Date: *Fri, May 17, 2019 at 1:13 PM
>>> *To: *Richard Smith
>>> *Cc: *cfe-commits
>>>
>>> The test fails on Windows:


 *From: *Richard Smith via cfe-commits 
 *Date: *Fri, May 17, 2019 at 3:58 AM
 *To: * 

 Author: rsmith
> Date: Fri May 17 01:01:34 2019
> New Revision: 360998
>
> URL: http://llvm.org/viewvc/llvm-project?rev=360998&view=rev
> Log:
> Fix crash if, during evaluation of __builtin_object_size, we try to
> load
> through an invalid base.
>
> Modified:
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=360998&r1=360997&r2=360998&view=diff
>
> ==
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 17 01:01:34 2019
> @@ -3285,6 +3285,11 @@ static bool AreElementsOfSameArray(QualT
>  static CompleteObject findCompleteObject(EvalInfo &Info, const Expr
> *E,
>   AccessKinds AK, const LValue
> &LVal,
>   QualType LValType) {
> +  if (LVal.InvalidBase) {
> +Info.FFDiag(E);
> +return CompleteObject();
> +  }
> +
>if (!LVal.Base) {
>  Info.FFDiag(E, diag::note_constexpr_access_null) << AK;
>  return CompleteObject();
>
> Modified: cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp?rev=360998&r1=360997&r2=360998&view=diff
>
> ==
> --- cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp (original)
> +++ cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp Fri May 17
> 01:01:34 2019
> @@ -97,3 +97,10 @@ void tooSmallBuf() {
>copy5CharsIntoStrict(small.buf); // expected-error{{no matching
> function for call}}
>  }
>  }
> +
> +namespace InvalidBase {
> +  // Ensure this doesn't crash.
> +  struct S { const char *name; };
> +  S invalid_base();
> +  constexpr long bos_name =
> __builtin_object_size(invalid_base().name, 1);
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
 ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists

[PATCH] D62049: [clang-tidy] Add a close-on-exec check on pipe2() in Android module.

2019-05-17 Thread Jian Cai via Phabricator via cfe-commits
jcai19 updated this revision to Diff 200066.
jcai19 added a comment.

Update based on comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62049

Files:
  clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/clang-tidy/android/CloexecPipe2Check.cpp
  clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe2.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp

Index: clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp
@@ -0,0 +1,68 @@
+// RUN: %check_clang_tidy %s android-cloexec-pipe2 %t
+
+#define O_NONBLOCK 1
+#define __O_CLOEXEC 3
+#define O_CLOEXEC __O_CLOEXEC
+#define TEMP_FAILURE_RETRY(exp) \
+  ({\
+int _rc;\
+do {\
+  _rc = (exp);  \
+} while (_rc == -1);\
+  })
+#define NULL 0
+
+extern "C" int pipe2(int pipefd[2], int flags);
+
+void a() {
+  int pipefd[2];
+  pipe2(pipefd, O_NONBLOCK);
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'pipe2' should use O_CLOEXEC where possible [android-cloexec-pipe2]
+  // CHECK-FIXES: pipe2(pipefd, O_NONBLOCK | O_CLOEXEC);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK));
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: 'pipe2'
+  // CHECK-FIXES: TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK | O_CLOEXEC));
+}
+
+void f() {
+  int pipefd[2];
+  pipe2(pipefd, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'pipe2'
+  // CHECK-FIXES: pipe2(pipefd, 3 | O_CLOEXEC);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, 3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: 'pipe2'
+  // CHECK-FIXES: TEMP_FAILURE_RETRY(pipe2(pipefd, 3 | O_CLOEXEC));
+
+  int flag = O_NONBLOCK;
+  pipe2(pipefd, flag);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, flag));
+}
+
+namespace i {
+int pipe2(int pipefd[2], int flags);
+
+void d() {
+  int pipefd[2];
+  pipe2(pipefd, O_NONBLOCK);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK));
+}
+
+} // namespace i
+
+void e() {
+  int pipefd[2];
+  pipe2(pipefd, O_CLOEXEC);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, O_CLOEXEC));
+  pipe2(pipefd, O_NONBLOCK | O_CLOEXEC);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK | O_CLOEXEC));
+}
+
+class G {
+public:
+  int pipe2(int pipefd[2], int flags);
+  void d() {
+int pipefd[2];
+pipe2(pipefd, O_NONBLOCK);
+TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK));
+  }
+};
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -32,6 +32,7 @@
android-cloexec-inotify-init1
android-cloexec-memfd-create
android-cloexec-open
+   android-cloexec-pipe2
android-cloexec-socket
android-comparison-in-temp-failure-retry
boost-use-to-string
Index: clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe2.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe2.rst
@@ -0,0 +1,19 @@
+.. title:: clang-tidy - android-cloexec-pipe2
+
+android-cloexec-pipe2
+=
+
+Checks if the required file flag ``O_CLOEXEC`` is present in the argument of
+``pipe2()``. ``pipe2()`` should include ``O_CLOEXEC`` in its type argument to
+avoid the file descriptor leakage. Without this flag, an opened sensitive file
+would remain open across a ``fork``+``exec`` to a lower-privileged SELinux domain.
+
+Examples:
+
+.. code-block:: c++
+
+  pipe2(pipefd, O_NONBLOCK);
+
+  // becomes
+
+  pipe2(pipefd, O_CLOEXEC);
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -101,6 +101,12 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`android-cloexec-pipe
+  ` check.
+
+  Checks if the required file flag ``O_CLOEXEC`` is present in the argument of
+  ``pipe2()``.
+
 - New :doc:`bugprone-unhandled-self-assignment
   ` check.
 
Index: clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
@@ -0,0 +1,34 @@
+//===--- CloexecPipe2Check.h - clang-tidy*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See ht

[PATCH] D61967: [clang-tidy] Add a close-on-exec check on pipe() in Android module.

2019-05-17 Thread Jian Cai via Phabricator via cfe-commits
jcai19 updated this revision to Diff 200068.
jcai19 marked an inline comment as done.
jcai19 added a comment.

Update based on comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61967

Files:
  clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
  clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp

Index: clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s android-cloexec-pipe %t
+
+extern "C" int pipe(int pipefd[2]);
+
+void f() {
+  int pipefd[2];
+  pipe(pipefd);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer pipe2() to pipe() because pipe2() allows O_CLOEXEC [android-cloexec-pipe]
+  // CHECK-FIXES: pipe2(pipefd, O_CLOEXEC);
+}
+
+namespace i {
+int pipe(int pipefd[2]);
+void g() {
+  int pipefd[2];
+  pipe(pipefd);
+}
+} // namespace i
+
+class C {
+public:
+  int pipe(int pipefd[2]);
+  void h() {
+int pipefd[2];
+pipe(pipefd);
+  }
+};
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -32,6 +32,7 @@
android-cloexec-inotify-init1
android-cloexec-memfd-create
android-cloexec-open
+   android-cloexec-pipe
android-cloexec-socket
android-comparison-in-temp-failure-retry
boost-use-to-string
Index: clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - android-cloexec-pipe
+
+android-cloexec-pipe
+
+
+Detects usage of ``pipe()``. The usage of ``pipe()`` is not recommended, it's better to use ``pipe2()``.
+Without this flag, an opened sensitive file descriptor would remain open across
+a ``fork``+``exec`` to a lower-privileged SELinux domain.
+
+Examples:
+
+.. code-block:: c++
+
+  pipe(pipefd);
+
+  // becomes
+
+  pipe2(pipefd, O_CLOEXEC);
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -101,6 +101,11 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`android-cloexec-pipe
+  ` check.
+
+  Detects usage of ``pipe()``.
+
 - New :doc:`bugprone-unhandled-self-assignment
   ` check.
 
Index: clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
@@ -0,0 +1,34 @@
+//===--- CloexecPipeCheck.h - clang-tidy-*- 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 LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// pipe() is better to be replaced by pipe2().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-pipe.html
+class CloexecPipeCheck : public CloexecCheck {
+public:
+  CloexecPipeCheck(StringRef Name, ClangTidyContext *Context)
+  : CloexecCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
Index: clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
@@ -0,0 +1,37 @@
+//===--- CloexecPipeCheck.cpp - clang-tidy-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

[PATCH] D61909: Add Clang shared library with C++ exports

2019-05-17 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

@beanz @tstellar 
I am wondering what to do wrt apt.llvm.org 
should it be part of libclang or create a libclang++ package
what do you think?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61909



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


[PATCH] D61909: Add Clang shared library with C++ exports

2019-05-17 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

I would leave it out of any distribution (at least for now).


Repository:
  rC Clang

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

https://reviews.llvm.org/D61909



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


  1   2   >