[PATCH] D44932: [CodeComplete] Fix completion in the middle of ident in ctor lists.

2018-04-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 143435.
ilya-biryukov added a comment.

- Fixed failing assert on the end of file. Added a test for that.


Repository:
  rC Clang

https://reviews.llvm.org/D44932

Files:
  lib/Lex/Lexer.cpp
  test/CodeCompletion/ctor-initializer.cpp
  test/CodeCompletion/end-of-file.cpp


Index: test/CodeCompletion/end-of-file.cpp
===
--- /dev/null
+++ test/CodeCompletion/end-of-file.cpp
@@ -0,0 +1,7 @@
+// Check that clang does not crash when completing at the last char in the
+// buffer.
+// NOTE: This file must *NOT* have newline at the end.
+// RUN: %clang_cc1 -code-completion-at=%s:7:2 %s | FileCheck %s
+// CHECK: COMPLETION: foo
+using foo = int***;
+f
\ No newline at end of file
Index: test/CodeCompletion/ctor-initializer.cpp
===
--- test/CodeCompletion/ctor-initializer.cpp
+++ test/CodeCompletion/ctor-initializer.cpp
@@ -58,5 +58,9 @@
   // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s 
-o - | FileCheck -check-prefix=CHECK-CC7 %s
   // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s 
-o - | FileCheck -check-prefix=CHECK-CC7 %s
   // CHECK-CC7: COMPLETION: Pattern : member1(<#args#>
+  // Check in the middle and at the end of identifier too.
+  // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s 
-o - | FileCheck -check-prefix=CHECK-CC8 %s
+  // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s 
-o - | FileCheck -check-prefix=CHECK-CC8 %s
+  // CHECK-CC8: COMPLETION: Pattern : member2(<#args#>
   int member1, member2;
 };
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -1656,7 +1656,21 @@
 && II->getObjCKeywordID() == tok::objc_not_keyword) {
   // Return the code-completion token.
   Result.setKind(tok::code_completion);
-  cutOffLexing();
+  // Skip the code-completion char and all immediate identifier characters.
+  // This ensures we get consistent behavior when completing at any point 
in
+  // an identifier (i.e. at the start, in the middle, at the end). Note 
that
+  // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code
+  // simpler.
+  assert(*CurPtr == 0 && "Completion character must be 0");
+  ++CurPtr;
+  // Note that code completion token is not added as a separate character
+  // when completion point is at the end of the buffer. Therefore, we need
+  // to check if the buffer has ended.
+  if (CurPtr < BufferEnd) {
+while (isIdentifierBody(*CurPtr))
+  ++CurPtr;
+  }
+  BufferPtr = CurPtr;
   return true;
 }
 return true;


Index: test/CodeCompletion/end-of-file.cpp
===
--- /dev/null
+++ test/CodeCompletion/end-of-file.cpp
@@ -0,0 +1,7 @@
+// Check that clang does not crash when completing at the last char in the
+// buffer.
+// NOTE: This file must *NOT* have newline at the end.
+// RUN: %clang_cc1 -code-completion-at=%s:7:2 %s | FileCheck %s
+// CHECK: COMPLETION: foo
+using foo = int***;
+f
\ No newline at end of file
Index: test/CodeCompletion/ctor-initializer.cpp
===
--- test/CodeCompletion/ctor-initializer.cpp
+++ test/CodeCompletion/ctor-initializer.cpp
@@ -58,5 +58,9 @@
   // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
   // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
   // CHECK-CC7: COMPLETION: Pattern : member1(<#args#>
+  // Check in the middle and at the end of identifier too.
+  // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s
+  // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s
+  // CHECK-CC8: COMPLETION: Pattern : member2(<#args#>
   int member1, member2;
 };
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -1656,7 +1656,21 @@
 && II->getObjCKeywordID() == tok::objc_not_keyword) {
   // Return the code-completion token.
   Result.setKind(tok::code_completion);
-  cutOffLexing();
+  // Skip the code-completion char and all immediate identifier characters.
+  // This ensures we get consistent behavior when completing at any point in
+  // an identifier (i.e. at the start, in the middle, at the end). Note that
+  // only simple cases (i.e. [a-zA-Z0-9_]) are supported to keep the code
+  // simpler.
+  assert(*CurPtr == 0 && "Completion character must be 0");
+  ++CurPtr;
+  

[PATCH] D44932: [CodeComplete] Fix completion in the middle of ident in ctor lists.

2018-04-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: lib/Lex/Lexer.cpp:1667-1668
+  assert(CurPtr < BufferEnd && "eof at completion point");
+  while (isIdentifierBody(*CurPtr))
+++CurPtr;
+  BufferPtr = CurPtr;

aaron.ballman wrote:
> You should continue to assert that `CurPtr < BufferEnd` in this loop, no?
AFAIK, all buffers end with `'\0'`, so lexer usually loops without doing bound 
checking, e.g. a similar loop is at Lexer.cpp:1623.

It turned out the completion token is not added when completion point is at the 
end of the buffer, though, fixed that.


Repository:
  rC Clang

https://reviews.llvm.org/D44932



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


[PATCH] D45776: [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py

2018-04-21 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis updated this revision to Diff 143436.
zinovy.nis marked 3 inline comments as done.
zinovy.nis added a comment.

- Applied the changes suggested by Alexander.


https://reviews.llvm.org/D45776

Files:
  docs/clang-tidy/index.rst
  test/clang-tidy/check_clang_tidy.cpp
  test/clang-tidy/check_clang_tidy.py

Index: test/clang-tidy/check_clang_tidy.py
===
--- test/clang-tidy/check_clang_tidy.py
+++ test/clang-tidy/check_clang_tidy.py
@@ -16,8 +16,9 @@
 This script runs clang-tidy in fix mode and verify fixes, messages or both.
 
 Usage:
-  check_clang_tidy.py [-resource-dir ] \
-[-assume-filename ] \
+  check_clang_tidy.py [-resource-dir=] \
+[-assume-filename=] \
+[-check-suffix=] \
\
 -- [optional clang-tidy arguments]
 
@@ -42,6 +43,7 @@
   parser.add_argument('-expect-clang-tidy-error', action='store_true')
   parser.add_argument('-resource-dir')
   parser.add_argument('-assume-filename')
+  parser.add_argument('-check-suffix', default='')
   parser.add_argument('input_file_name')
   parser.add_argument('check_name')
   parser.add_argument('temp_file_name')
@@ -70,6 +72,13 @@
   clang_tidy_extra_args.extend(
   ['-fobjc-abi-version=2', '-fobjc-arc'])
 
+  if args.check_suffix and not re.match('^[A-Z0-9\-]+$', args.check_suffix):
+sys.exit('Only A..Z, 0..9 and "-" are allowed in check suffix, but "%s" was given' % (args.check_suffix))
+
+  file_check_suffix = ('-' + args.check_suffix) if args.check_suffix else ''
+  check_fixes_prefix = 'CHECK-FIXES' + file_check_suffix
+  check_messages_prefix = 'CHECK-MESSAGES' + file_check_suffix
+
   # Tests should not rely on STL being available, and instead provide mock
   # implementations of relevant APIs.
   clang_tidy_extra_args.append('-nostdinc++')
@@ -80,17 +89,17 @@
   with open(input_file_name, 'r') as input_file:
 input_text = input_file.read()
 
-  has_check_fixes = input_text.find('CHECK-FIXES') >= 0
-  has_check_messages = input_text.find('CHECK-MESSAGES') >= 0
+  has_check_fixes = check_fixes_prefix in input_text
+  has_check_messages = check_messages_prefix in input_text
 
   if not has_check_fixes and not has_check_messages:
-sys.exit('Neither CHECK-FIXES nor CHECK-MESSAGES found in the input')
+sys.exit('Neither %s nor %s found in the input' % (check_fixes_prefix, check_messages_prefix) )
 
   # Remove the contents of the CHECK lines to avoid CHECKs matching on
   # themselves.  We need to keep the comments to preserve line numbers while
   # avoiding empty lines which could potentially trigger formatting-related
   # checks.
-  cleaned_test = re.sub('// *CHECK-[A-Z-]*:[^\r\n]*', '//', input_text)
+  cleaned_test = re.sub('// *CHECK-[A-Z0-9\-]*:[^\r\n]*', '//', input_text)
 
   write_file(temp_file_name, cleaned_test)
 
@@ -128,7 +137,7 @@
 try:
   subprocess.check_output(
   ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
-   '-check-prefix=CHECK-FIXES', '-strict-whitespace'],
+   '-check-prefix=' + check_fixes_prefix, '-strict-whitespace'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
   print('FileCheck failed:\n' + e.output.decode())
@@ -140,7 +149,7 @@
 try:
   subprocess.check_output(
   ['FileCheck', '-input-file=' + messages_file, input_file_name,
-   '-check-prefix=CHECK-MESSAGES',
+   '-check-prefix=' + check_messages_prefix,
'-implicit-check-not={{warning|error}}:'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError as e:
Index: test/clang-tidy/check_clang_tidy.cpp
===
--- test/clang-tidy/check_clang_tidy.cpp
+++ test/clang-tidy/check_clang_tidy.cpp
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy -check-suffix=USING-A %s misc-unused-using-decls %t -- -- -DUSING_A
+// RUN: %check_clang_tidy -check-suffix=USING-B %s misc-unused-using-decls %t -- -- -DUSING_B
+// RUN: %check_clang_tidy %s misc-unused-using-decls %t
+
+namespace a {class A {}; class B {}; class C {}; }
+namespace b {
+#if defined(USING_A)
+using a::A;
+#elif  defined(USING_B)
+using a::B;
+#else
+using a::C;
+#endif
+}
+namespace c {}
+// CHECK-MESSAGES-USING-A: :[[@LINE-8]]:10: warning: using decl 'A' {{.*}}
+// CHECK-MESSAGES-USING-B: :[[@LINE-7]]:10: warning: using decl 'B' {{.*}}
+// CHECK-MESSAGES: :[[@LINE-6]]:10: warning: using decl 'C' {{.*}}
+// CHECK-FIXES-USING-A-NOT: using a::A;$
+// CHECK-FIXES-USING-B-NOT: using a::B;$
+// CHECK-FIXES-NOT: using a::C;$
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -673,6 +673,27 @@
 // CHECK-FIXES: int b = a;
   }
 
+To check more than one scenario in the same test file use 
+``-check-suffix=SUFFIX-NAME`` on ``check_clang_tidy.py`` command line.
+With ``-check-suffix

[PATCH] D45718: Allow registering custom statically-linked analyzer checkers

2018-04-21 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

Tests would be nice, but on the other hand AFAIK we don't have unit tests for 
the analyzer. Maybe it's time we add those.


Repository:
  rC Clang

https://reviews.llvm.org/D45718



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


[PATCH] D45900: CodeGen: Fix invalid bitcast for lifetime.start/end

2018-04-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

These functions must predate the addition of CreateLifetimeStart and 
CreateLifetimeEnd methods on IRBuilder; we should just be calling those.


https://reviews.llvm.org/D45900



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


[PATCH] D44557: [analyzer] CStringChecker.cpp - Code refactoring on bug report.

2018-04-21 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov accepted this revision.
george.karpenkov added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D44557



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


[PATCH] D45839: [analyzer] Add support for WebKit "unified sources".

2018-04-21 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added inline comments.



Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h:144
+// includes the full path.
+if (SM.getFilename(IL).contains("UnifiedSource")) {
+  StringRef Name = SM.getFilename(SL);

NoQ wrote:
> george.karpenkov wrote:
> > Is this `if` really necessary? This logic has too much overfitting, and it 
> > seems that if someone decides to include `.cc` files, we should analyze 
> > them in any case, right? We also would prefer to not stop working if webkit 
> > decides on using a different naming for those.
> This is indeed an act of overfitting. But also there are very few reasons to 
> include a non-header file, and all of them are pretty exotic. I'm not sure we 
> want to analyze these files in all cases. So i want to play safe until we 
> gather more data.
I would still say that just analyzing included c++ files is a lesser evil.



Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h:145-147
+  if (Name.endswith_lower(".c") || Name.endswith_lower(".cpp") ||
+  Name.endswith_lower(".cc") || Name.endswith_lower(".cxx") ||
+  Name.endswith_lower(".m") || Name.endswith_lower(".mm")) {

NoQ wrote:
> majnemer wrote:
> > C++ source code is also found in files which end in .C, this code will 
> > match against strange file endings like .cXx and .mM
> > 
> > I think the above logic should be changed to match 
> > https://github.com/llvm-mirror/clang/blob/master/lib/Frontend/FrontendOptions.cpp#L27
> Aha, yeah, thanks, that's the place i was looking for.
Why not just use the included function then? It's static.


https://reviews.llvm.org/D45839



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


[PATCH] D45682: [analyzer] Move `TaintBugVisitor` from `GenericTaintChecker.cpp` to `BugReporterVisitors.h`.

2018-04-21 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

I'm new to the taint visitor, but I am quite confused by your change 
description.

> and many checkers rely on it

How can other checkers rely on it if it's private to the taint checker?

Also, it's probably to explicitly include BugReporterVisitors.h in the checker 
file then.


Repository:
  rC Clang

https://reviews.llvm.org/D45682



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


[PATCH] D45920: [analyzer] Move RangeSet related declarations into the RangedConstraintManager header.

2018-04-21 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs created this revision.
rnkovacs added reviewers: NoQ, george.karpenkov, dcoughlin.
Herald added subscribers: dkrupp, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun, whisperity.

I could also move `RangedConstraintManager.h` under `include/` if you agree as 
it seems slightly out of place under `lib/`.


Repository:
  rC Clang

https://reviews.llvm.org/D45920

Files:
  lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  lib/StaticAnalyzer/Core/RangedConstraintManager.h

Index: lib/StaticAnalyzer/Core/RangedConstraintManager.h
===
--- lib/StaticAnalyzer/Core/RangedConstraintManager.h
+++ lib/StaticAnalyzer/Core/RangedConstraintManager.h
@@ -15,12 +15,124 @@
 #define LLVM_CLANG_LIB_STATICANALYZER_CORE_RANGEDCONSTRAINTMANAGER_H
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SimpleConstraintManager.h"
 
 namespace clang {
 
 namespace ento {
 
+/// A Range represents the closed range [from, to].  The caller must
+/// guarantee that from <= to.  Note that Range is immutable, so as not
+/// to subvert RangeSet's immutability.
+class Range : public std::pair {
+public:
+  Range(const llvm::APSInt &from, const llvm::APSInt &to)
+  : std::pair(&from, &to) {
+assert(from <= to);
+  }
+  bool Includes(const llvm::APSInt &v) const {
+return *first <= v && v <= *second;
+  }
+  const llvm::APSInt &From() const { return *first; }
+  const llvm::APSInt &To() const { return *second; }
+  const llvm::APSInt *getConcreteValue() const {
+return &From() == &To() ? &From() : nullptr;
+  }
+
+  void Profile(llvm::FoldingSetNodeID &ID) const {
+ID.AddPointer(&From());
+ID.AddPointer(&To());
+  }
+};
+
+class RangeTrait : public llvm::ImutContainerInfo {
+public:
+  // When comparing if one Range is less than another, we should compare
+  // the actual APSInt values instead of their pointers.  This keeps the order
+  // consistent (instead of comparing by pointer values) and can potentially
+  // be used to speed up some of the operations in RangeSet.
+  static inline bool isLess(key_type_ref lhs, key_type_ref rhs) {
+return *lhs.first < *rhs.first ||
+   (!(*rhs.first < *lhs.first) && *lhs.second < *rhs.second);
+  }
+};
+
+/// RangeSet contains a set of ranges. If the set is empty, then
+///  there the value of a symbol is overly constrained and there are no
+///  possible values for that symbol.
+class RangeSet {
+  typedef llvm::ImmutableSet PrimRangeSet;
+  PrimRangeSet ranges; // no need to make const, since it is an
+   // ImmutableSet - this allows default operator=
+   // to work.
+public:
+  typedef PrimRangeSet::Factory Factory;
+  typedef PrimRangeSet::iterator iterator;
+
+  RangeSet(PrimRangeSet RS) : ranges(RS) {}
+
+  /// Create a new set with all ranges of this set and RS.
+  /// Possible intersections are not checked here.
+  RangeSet addRange(Factory &F, const RangeSet &RS) {
+PrimRangeSet Ranges(RS.ranges);
+for (const auto &range : ranges)
+  Ranges = F.add(Ranges, range);
+return RangeSet(Ranges);
+  }
+
+  iterator begin() const { return ranges.begin(); }
+  iterator end() const { return ranges.end(); }
+
+  bool isEmpty() const { return ranges.isEmpty(); }
+
+  /// Construct a new RangeSet representing '{ [from, to] }'.
+  RangeSet(Factory &F, const llvm::APSInt &from, const llvm::APSInt &to)
+  : ranges(F.add(F.getEmptySet(), Range(from, to))) {}
+
+  /// Profile - Generates a hash profile of this RangeSet for use
+  ///  by FoldingSet.
+  void Profile(llvm::FoldingSetNodeID &ID) const { ranges.Profile(ID); }
+
+  /// getConcreteValue - If a symbol is contrained to equal a specific integer
+  ///  constant then this method returns that value.  Otherwise, it returns
+  ///  NULL.
+  const llvm::APSInt *getConcreteValue() const {
+return ranges.isSingleton() ? ranges.begin()->getConcreteValue() : nullptr;
+  }
+
+private:
+  void IntersectInRange(BasicValueFactory &BV, Factory &F,
+const llvm::APSInt &Lower, const llvm::APSInt &Upper,
+PrimRangeSet &newRanges, PrimRangeSet::iterator &i,
+PrimRangeSet::iterator &e) const;
+
+  const llvm::APSInt &getMinValue() const;
+
+  bool pin(llvm::APSInt &Lower, llvm::APSInt &Upper) const;
+
+public:
+  RangeSet Intersect(BasicValueFactory &BV, Factory &F, llvm::APSInt Lower,
+ llvm::APSInt Upper) const;
+
+  void print(raw_ostream &os) const;
+
+  bool operator==(const RangeSet &other) const {
+return ranges == other.ranges;
+  }
+};
+
+
+class ConstraintRange {};
+using ConstraintRangeTy = llvm::ImmutableMap;
+
+template <>
+struct ProgramStateTrait
+  : public ProgramStatePartialTrait {
+  static void *GDMIndex() { static int Index; return &Index; }
+};
+
+

[PATCH] D45517: [analyzer] WIP: False positive refutation with Z3

2018-04-21 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs updated this revision to Diff 143440.

https://reviews.llvm.org/D45517

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/BugReporter.cpp
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  lib/StaticAnalyzer/Core/ProgramState.cpp
  lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Index: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
===
--- lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
+++ lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "RangedConstraintManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
@@ -915,6 +916,8 @@
   void print(ProgramStateRef St, raw_ostream &Out, const char *nl,
  const char *sep) override;
 
+  bool checkRangedStateConstraints(ProgramStateRef State) override;
+
   //===--===//
   // Implementation for interface from SimpleConstraintManager.
   //===--===//
@@ -1235,6 +1238,47 @@
   return State->set(CZ);
 }
 
+bool Z3ConstraintManager::checkRangedStateConstraints(ProgramStateRef State) {
+  Solver.reset();
+  ConstraintRangeTy CR = State->get();
+
+  for (ConstraintRangeTy::iterator I = CR.begin(), E = CR.end(); I != E; ++I) {
+SymbolRef Sym = I.getKey();
+
+for (const auto &Range : I.getData()) {
+  const llvm::APSInt &From = Range.From();
+  const llvm::APSInt &To = Range.To();
+
+  assert((getAPSIntType(From) == getAPSIntType(To)) &&
+ "Range values have different types!");
+  QualType RangeTy = getAPSIntType(From);
+  // Skip ranges whose endpoints cannot be converted to APSInts with
+  // a valid APSIntType.
+  if (RangeTy.isNull())
+continue;
+
+  QualType SymTy;
+  Z3Expr Exp = getZ3Expr(Sym, &SymTy);
+  bool isSignedTy = SymTy->isSignedIntegerOrEnumerationType();
+
+  Z3Expr FromExp = Z3Expr::fromAPSInt(From);
+  Z3Expr ToExp = Z3Expr::fromAPSInt(To);
+
+  if (From == To) {
+Z3Expr Eq = getZ3BinExpr(Exp, SymTy, BO_EQ, FromExp, RangeTy, nullptr);
+Solver.addConstraint(Eq);
+  } else {
+Z3Expr LHS = getZ3BinExpr(Exp, SymTy, BO_GE, FromExp, RangeTy, nullptr);
+Z3Expr RHS = getZ3BinExpr(Exp, SymTy, BO_LE, ToExp, RangeTy, nullptr);
+Solver.addConstraint(Z3Expr::fromBinOp(LHS, BO_LOr, RHS, isSignedTy));
+  }
+}
+  }
+  // If Z3 timeouts, Z3_L_UNDEF is returned, and we assume that the state
+  // is feasible.
+  return Solver.check() != Z3_L_FALSE;
+}
+
 //===--===//
 // Internal implementation.
 //===--===//
Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -13,6 +13,8 @@
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
@@ -78,6 +80,10 @@
 CallEventMgr(new CallEventManager(alloc)), Alloc(alloc) {
   StoreMgr = (*CreateSMgr)(*this);
   ConstraintMgr = (*CreateCMgr)(*this, SubEng);
+  AnalyzerOptions &Opts = SubEng->getAnalysisManager().getAnalyzerOptions();
+  RefutationMgr = Opts.shouldPostProcessBugReports()
+  ? CreateZ3ConstraintManager(*this, SubEng)
+  : nullptr;
 }
 
 
Index: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2333,3 +2333,26 @@
 
   return std::move(Piece);
 }
+
+std::shared_ptr
+FalsePositiveRefutationBRVisitor::VisitNode(const ExplodedNode *Succ,
+const ExplodedNode *Prev,
+BugReporterContext &BRC,
+BugReport &BR) {
+  if (isInvalidated)
+return nullptr;
+
+  if (Succ->getLocation().getKind() != P

[PATCH] D45517: [analyzer] WIP: False positive refutation with Z3

2018-04-21 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs added a comment.

In https://reviews.llvm.org/D45517#1074057, @NoQ wrote:

> > The visitor currently checks states appearing as block edges in the 
> > exploded graph. The first idea was to filter states based on the shape of 
> > the exploded graph, by checking the number of successors of the parent 
> > node, but surprisingly, both `succ_size()` and `pred_size()` seemed to 
> > return 1 for each node in the graph (except for the root), even if there 
> > clearly were branchings in the code (and on the `.dot` picture). To my 
> > understanding, the exploded graph is fully constructed at the stage where 
> > visitors are run, so I must be missing something.
>
> Aha, yep, that's probably because visitors are operating on the "trimmed" 
> exploded graph. You can paint it via the `-trim-egraph` flag or by calling 
> `ViewGraph(1)` in the debugger.


Oh, thanks! That explains a lot.

> So, yeah, that's a good optimization that we're not invoking the solver on 
> every node. But i don't think we should focus on improving this optimization 
> further; instead, i think the next obvious step here is to implement it in 
> such a way that we only needed to call the solver //once// for every report. 
> We could simply collect all constraints from all states along the path and 
> put them into the solver all together. This will work because symbols are not 
> mutable and they don't reincarnate.

Won't collecting all constraints and solving a ~100ish equations at once take a 
long time? Maybe the timeout limit for Z3 will need to be slightly increased 
for refutation then.

> Apart from that, the patch seems to be going in the right direction. It 
> should be possible to split up the `RangeSet` refactoring into a different 
> review, for easier reviewing and better commit history.

Done in https://reviews.llvm.org/D45920.

I'll update this patch shortly.


https://reviews.llvm.org/D45517



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


[PATCH] D45517: [analyzer] WIP: False positive refutation with Z3

2018-04-21 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs added a comment.

In https://reviews.llvm.org/D45517#1074057, @NoQ wrote:

> > The visitor currently checks states appearing as block edges in the 
> > exploded graph. The first idea was to filter states based on the shape of 
> > the exploded graph, by checking the number of successors of the parent 
> > node, but surprisingly, both `succ_size()` and `pred_size()` seemed to 
> > return 1 for each node in the graph (except for the root), even if there 
> > clearly were branchings in the code (and on the `.dot` picture). To my 
> > understanding, the exploded graph is fully constructed at the stage where 
> > visitors are run, so I must be missing something.
>
> Aha, yep, that's probably because visitors are operating on the "trimmed" 
> exploded graph. You can paint it via the `-trim-egraph` flag or by calling 
> `ViewGraph(1)` in the debugger.


Oh, thanks! That explains a lot.

> So, yeah, that's a good optimization that we're not invoking the solver on 
> every node. But i don't think we should focus on improving this optimization 
> further; instead, i think the next obvious step here is to implement it in 
> such a way that we only needed to call the solver //once// for every report. 
> We could simply collect all constraints from all states along the path and 
> put them into the solver all together. This will work because symbols are not 
> mutable and they don't reincarnate.

Won't collecting all constraints and solving a ~100ish equations at once take a 
long time? Maybe the timeout limit for Z3 will need to be slightly increased 
for refutation then.

> Apart from that, the patch seems to be going in the right direction. It 
> should be possible to split up the `RangeSet` refactoring into a different 
> review, for easier reviewing and better commit history.

Done in https://reviews.llvm.org/D45920.

I'll update this patch shortly.


https://reviews.llvm.org/D45517



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


[PATCH] D45517: [analyzer] WIP: False positive refutation with Z3

2018-04-21 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:284
+  /// \sa shouldPostProcessBugReports
+  Optional PostProcessBugReports;
+

The option name should be more self-explanatory, post-processing in general can 
mean anything



Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:586
+  /// which accepts the values "true" and "false".
+  bool shouldPostProcessBugReports();
+

Same here



Comment at: 
include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h:348
+: public BugReporterVisitorImpl {
+  bool isInvalidated = false;
+

LLVM coding standart mandates capital case for field names.



Comment at: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp:301
+  return getBooleanOption(PostProcessBugReports,
+  "postprocess-reports",
+  /* Default = */ false);

Same for the option name. "crosscheck-with-z3"?



Comment at: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:2342
+BugReport &BR) {
+  if (isInvalidated)
+return nullptr;

Is this field actually necessary? Do we ever check the same bug report with the 
same visitor multiple times?



Comment at: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:2351
+
+  if (!RefutationMgr.checkRangedStateConstraints(Succ->getState())) {
+const LocationContext *LC = Succ->getLocationContext();

For the initial version I would just do all work in the visitor, but that's a 
matter of taste.



Comment at: lib/StaticAnalyzer/Core/ProgramState.cpp:86
+  ? CreateZ3ConstraintManager(*this, SubEng)
+  : nullptr;
 }

Would then we crash on NPE if `getRefutationManager` is called? Getters should 
preferably not cause crashes.



Comment at: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp:1268
+  if (From == To) {
+Z3Expr Eq = getZ3BinExpr(Exp, SymTy, BO_EQ, FromExp, RangeTy, nullptr);
+Solver.addConstraint(Eq);

I wouldn't even bother with this branch, but again, a matter of taste.



Comment at: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp:1273
+Z3Expr RHS = getZ3BinExpr(Exp, SymTy, BO_LE, ToExp, RangeTy, nullptr);
+Solver.addConstraint(Z3Expr::fromBinOp(LHS, BO_LOr, RHS, isSignedTy));
+  }

Why `OR`? Shouldn't it be AND?


https://reviews.llvm.org/D45517



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


[PATCH] D45920: [analyzer] Move RangeSet related declarations into the RangedConstraintManager header.

2018-04-21 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

> I could also move RangedConstraintManager.h under include

We probably don't want to do that: currently it can only be imported by files 
in `Core`, and we probably should keep it that way




Comment at: lib/StaticAnalyzer/Core/RangedConstraintManager.h:130
+template <>
+struct ProgramStateTrait
+  : public ProgramStatePartialTrait {

Why not also `REGISTER_TRAIT_WITH_PROGRAMSTATE` here?


Repository:
  rC Clang

https://reviews.llvm.org/D45920



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


[PATCH] D45898: [SemaCXX] Mark destructor as referenced

2018-04-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added a reviewer: doug.gregor.
rjmccall added inline comments.



Comment at: lib/Sema/SemaInit.cpp:7074
+  if (RD->hasDefinition() && RD->hasNonTrivialDestructor())
+S.MarkFunctionReferenced(E->getExprLoc(), S.LookupDestructor(RD));
+

If we're actually using the destructor, we can't just look it up and mark it 
referenced; we have to call CheckDestructorAccess and DiagnoseUseOfDecl.

Walking the syntactic initializers like this seems wrong:
  - I don't know if we actually promise to rewrite these expressions to the 
actual recursive element initialization expression if the expression requires 
conversion.
  - This is going to miss implicitly-initialized elements, which can happen for 
a variety of reasons including (1) running out of explicit initializers and (2) 
designated initializers skipping a field.
  - We'll end up with redundant diagnostics from 
CheckDestructorAccess/DiagnoseUseOfDecl if the expression is an 
already-materialized temporary.
  - We'll end up with unwanted diagnostics from 
CheckDestructorAccess/DiagnoseUseOfDecl if the expression is a gl-value and 
actually part of a reference-initialization, where we don't actually use the 
destructor.

I think the right solution is probably that list-initialization needs to 
recognize that the initialization of a record needs to be treated as a 
potential use of the destructor even if we aren't supposed to bind it as a 
temporary, because once an object is initialized in the local context, there 
are all sorts of reasons why we might need to call its destructor before the 
initialization completes/transitions.  Basically every call to 
shouldBindAsTemporary in this file is suspect, because they're all places where 
we might need to check the destructor use even if we didn't make a temporary.

We seem to get this right in SK_UserConversion where we call 
shouldDestroyEntity, and the comment there is spot-on — it doesn't make sense 
for this code to be specific to SK_UserConversion at all.  My tentative 
suggestion would be to (1) make a helper function that does that exact "if 
should-bind then bind else if should-destroy then destroy" dance and then (2) 
look at all the should-bind checks and try to use your helper function instead. 
 But I'd really like Richard and/or Doug to weigh in.



Comment at: test/CodeGenObjCXX/arc-list-init-destruct.mm:1
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -std=c++1z -fobjc-arc 
-fobjc-exceptions -fcxx-exceptions -fexceptions -emit-llvm -o - %s | FileCheck 
%s
+

Does the corresponding C++ test case (replacing `Class0 *f;` with 
`HasExplicitNonTrivialDestructor f;`) not reproduce the problem?


Repository:
  rC Clang

https://reviews.llvm.org/D45898



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


[PATCH] D45920: [analyzer] Move RangeSet related declarations into the RangedConstraintManager header.

2018-04-21 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

Another approach would be to instead teach `RangedConstraintManager` to convert 
it's constraints to Z3. That would be an unwanted dependency, but the change 
would be much smaller, and the internals of the solver would not have to be 
exposed. @NoQ thoughts?


Repository:
  rC Clang

https://reviews.llvm.org/D45920



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


[PATCH] D44435: CUDA ctor/dtor Module-Unique Symbol Name

2018-04-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

This does not address my review.  My review is suggesting that we avoid this 
issue completely by fixing IRGen to use an external linkage for internal 
declarations in your emission mode.  That would allow you to just emit the 
module ctors as truly internal in the first place, removing any need to mangle 
them.


https://reviews.llvm.org/D44435



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


[PATCH] D45382: [CodeGen] Avoid destructing a struct type that has already been destructed by a delegated constructor

2018-04-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.
Herald added a reviewer: javed.absar.



Comment at: lib/CodeGen/CodeGenFunction.h:847
+CurrentCleanupStackDepth = C;
+  }
+

You don't need (or want) these accessors, I think; this is just private state 
of the CGF object, and nobody else should be using it.



Comment at: lib/CodeGen/CodeGenFunction.h:1112
+  llvm::DenseMap
+  CalleeDestructedParamCleanups;
+

It's too bad that we need this DenseMap in every CGF when actually only a very 
specific set of thunk functions will actually use it.  But I guess DenseMap is 
at least trivial to construct/destroy when empty, which will be the most common 
case.



Comment at: lib/CodeGen/CodeGenFunction.h:1116
+  EHScopeStack::stable_iterator CurrentCleanupStackDepth =
+  EHScopeStack::stable_end();
+

How about `CurrentCleanupScopeDepth`?  The current name makes it sound like 
it's the active depth of the cleanup stack.


Repository:
  rC Clang

https://reviews.llvm.org/D45382



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


[PATCH] D45451: [ItaniumMangle] Undeduced auto type doesn't belong in the substitution table

2018-04-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/AST/ItaniumMangle.cpp:2342
+  if (isa(Ty))
+return false;
   return true;

rjmccall wrote:
> I agree with your analysis that this shouldn't be a substitution candidate.  
> However, I think this probably needs an ABI-compatibility guard.
You should probably add a comment like "Prior to LLVM v6, Clang accidentally 
treated deduced auto types as substitution candidates."


https://reviews.llvm.org/D45451



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


[PATCH] D45451: [ItaniumMangle] Undeduced auto type doesn't belong in the substitution table

2018-04-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/AST/ItaniumMangle.cpp:2342
+  if (isa(Ty))
+return false;
   return true;

rjmccall wrote:
> rjmccall wrote:
> > I agree with your analysis that this shouldn't be a substitution candidate. 
> >  However, I think this probably needs an ABI-compatibility guard.
> You should probably add a comment like "Prior to LLVM v6, Clang accidentally 
> treated deduced auto types as substitution candidates."
Er, not "prior to", I guess.  "through", maybe, or "up to and including".


https://reviews.llvm.org/D45451



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


[PATCH] D45921: Add getDeserializationListener to ASTReader

2018-04-21 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.
yamaguchi added reviewers: v.g.vassilev, rsmith, dblaikie, thakis.

We need to know if ASTReader already has a DeserializationListner or
not, and this also helps to create a multiplexing deserialization
listener if there is one already attached.


https://reviews.llvm.org/D45921

Files:
  clang/include/clang/Serialization/ASTReader.h


Index: clang/include/clang/Serialization/ASTReader.h
===
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -1599,6 +1599,11 @@
   void setDeserializationListener(ASTDeserializationListener *Listener,
   bool TakeOwnership = false);
 
+  /// \brief Get the AST deserialization listener.
+  ASTDeserializationListener *getDeserializationListener() {
+return DeserializationListener;
+  }
+
   /// \brief Determine whether this AST reader has a global index.
   bool hasGlobalIndex() const { return (bool)GlobalIndex; }
 


Index: clang/include/clang/Serialization/ASTReader.h
===
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -1599,6 +1599,11 @@
   void setDeserializationListener(ASTDeserializationListener *Listener,
   bool TakeOwnership = false);
 
+  /// \brief Get the AST deserialization listener.
+  ASTDeserializationListener *getDeserializationListener() {
+return DeserializationListener;
+  }
+
   /// \brief Determine whether this AST reader has a global index.
   bool hasGlobalIndex() const { return (bool)GlobalIndex; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45776: [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py

2018-04-21 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D45776



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


[PATCH] D45807: [libclang] Fix test LibclangReparseTest.FileName when TMPDIR is set to a symbolic link

2018-04-21 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC330507: [libclang] Fix LibclangReparseTest.FileName when 
TMPDIR is set to a symlink (authored by petr.pavlu, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D45807

Files:
  unittests/libclang/LibclangTest.cpp


Index: unittests/libclang/LibclangTest.cpp
===
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "clang-c/Index.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -490,11 +491,11 @@
   CXFile cxf = clang_getFile(ClangTU, CppName.c_str());
 
   CXString cxname = clang_getFileName(cxf);
-  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  ASSERT_STREQ(clang_getCString(cxname), CppName.c_str());
   clang_disposeString(cxname);
 
   cxname = clang_File_tryGetRealPathName(cxf);
-  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  ASSERT_TRUE(llvm::StringRef(clang_getCString(cxname)).endswith("main.cpp"));
   clang_disposeString(cxname);
 }
 


Index: unittests/libclang/LibclangTest.cpp
===
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -8,6 +8,7 @@
 //===--===//
 
 #include "clang-c/Index.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -490,11 +491,11 @@
   CXFile cxf = clang_getFile(ClangTU, CppName.c_str());
 
   CXString cxname = clang_getFileName(cxf);
-  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  ASSERT_STREQ(clang_getCString(cxname), CppName.c_str());
   clang_disposeString(cxname);
 
   cxname = clang_File_tryGetRealPathName(cxf);
-  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  ASSERT_TRUE(llvm::StringRef(clang_getCString(cxname)).endswith("main.cpp"));
   clang_disposeString(cxname);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r330507 - [libclang] Fix LibclangReparseTest.FileName when TMPDIR is set to a symlink

2018-04-21 Thread Petr Pavlu via cfe-commits
Author: petr.pavlu
Date: Sat Apr 21 07:35:18 2018
New Revision: 330507

URL: http://llvm.org/viewvc/llvm-project?rev=330507&view=rev
Log:
[libclang] Fix LibclangReparseTest.FileName when TMPDIR is set to a symlink

Fix testing of clang_File_tryGetRealPathName() in
LibclangReparseTest.FileName when executing in an environment which has
TMPDIR set to a symbolic link that points to an actual directory. The
test would fail because the name returned by
clang_File_tryGetRealPathName() has the symlink resolved but the test
compared it to the original filename of a temporary file.

The patch addresses the problem by checking only that the value returned
by clang_File_tryGetRealPathName() ends with "main.cpp".

Additionally, the patch makes the previous assertion in the test that
checks result of clang_getFileName() stricter. It newly verifies that
the name returned by the function is exactly same as what was given to
clang_parseTranslationUnit()/clang_getFile().

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

Modified:
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=330507&r1=330506&r2=330507&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Sat Apr 21 07:35:18 2018
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "clang-c/Index.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -490,11 +491,11 @@ TEST_F(LibclangReparseTest, FileName) {
   CXFile cxf = clang_getFile(ClangTU, CppName.c_str());
 
   CXString cxname = clang_getFileName(cxf);
-  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  ASSERT_STREQ(clang_getCString(cxname), CppName.c_str());
   clang_disposeString(cxname);
 
   cxname = clang_File_tryGetRealPathName(cxf);
-  ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+  ASSERT_TRUE(llvm::StringRef(clang_getCString(cxname)).endswith("main.cpp"));
   clang_disposeString(cxname);
 }
 


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


[clang-tools-extra] r330509 - [clang-apply-replacements] Make clang-apply-replacements installable

2018-04-21 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Sat Apr 21 08:01:33 2018
New Revision: 330509

URL: http://llvm.org/viewvc/llvm-project?rev=330509&view=rev
Log:
[clang-apply-replacements] Make clang-apply-replacements installable

Add a new target for install: install-clang-apply-replacements.
So if you need clang-tidy and clang-apply-replacements tools only, 
you may build and install only these tools:

make install-clang-tidy install-clang-apply-replacements

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


Modified:
clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt?rev=330509&r1=330508&r2=330509&view=diff
==
--- clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt Sat 
Apr 21 08:01:33 2018
@@ -2,7 +2,7 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
-add_clang_executable(clang-apply-replacements
+add_clang_tool(clang-apply-replacements
   ClangApplyReplacementsMain.cpp
   )
 target_link_libraries(clang-apply-replacements


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


[PATCH] D45160: [clang-apply-replacements] Make clang-apply-replacements installable

2018-04-21 Thread Zinovy Nis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330509: [clang-apply-replacements] Make 
clang-apply-replacements installable (authored by zinovy.nis, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45160?vs=140616&id=143452#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45160

Files:
  clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt


Index: clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt
@@ -2,7 +2,7 @@
   Support
   )
 
-add_clang_executable(clang-apply-replacements
+add_clang_tool(clang-apply-replacements
   ClangApplyReplacementsMain.cpp
   )
 target_link_libraries(clang-apply-replacements


Index: clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-apply-replacements/tool/CMakeLists.txt
@@ -2,7 +2,7 @@
   Support
   )
 
-add_clang_executable(clang-apply-replacements
+add_clang_tool(clang-apply-replacements
   ClangApplyReplacementsMain.cpp
   )
 target_link_libraries(clang-apply-replacements
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r330511 - [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py

2018-04-21 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Sat Apr 21 08:23:56 2018
New Revision: 330511

URL: http://llvm.org/viewvc/llvm-project?rev=330511&view=rev
Log:
[clang-tidy] Customize FileCheck prefix in check_clang-tidy.py

The patch introduces a new command line option '-check-suffix' for 
check_clang_tidy.py 
to allow multiple %check_clang_tidy% in a single test file.

Sample:

// RUN: %check_clang_tidy -check-suffix=FLAG-1 %s misc-unused-using-decls %t -- 
-- 
// RUN: %check_clang_tidy -check-suffix=FLAG-2 %s misc-unused-using-decls %t -- 
--  
...
+// CHECK-MESSAGES-FLAG-1: :[[@LINE-4]]:10: warning: using decl 'B' is unused 
[misc-unused-using-decls]
+// CHECK-MESSAGES-FLAG-2: :[[@LINE-7]]:10: warning: using decl 'A' is unused 
[misc-unused-using-decls]
+// CHECK-FIXES-FLAG-1-NOT: using a::A;$
+// CHECK-FIXES-FLAG-2-NOT: using a::B;$

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

Added:
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp
Modified:
clang-tools-extra/trunk/docs/clang-tidy/index.rst
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py

Modified: clang-tools-extra/trunk/docs/clang-tidy/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/index.rst?rev=330511&r1=330510&r2=330511&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst Sat Apr 21 08:23:56 2018
@@ -673,6 +673,27 @@ source code is at `test/clang-tidy/googl
 // CHECK-FIXES: int b = a;
   }
 
+To check more than one scenario in the same test file use 
+``-check-suffix=SUFFIX-NAME`` on ``check_clang_tidy.py`` command line.
+With ``-check-suffix=SUFFIX-NAME`` you need to replace your ``CHECK-*`` 
+directives with ``CHECK-MESSAGES-SUFFIX-NAME`` and ``CHECK-FIXES-SUFFIX-NAME``.
+
+Here's an example:
+
+.. code-block:: c++
+
+   // RUN: %check_clang_tidy -check-suffix=USING-A %s misc-unused-using-decls 
%t -- -- -DUSING_A
+   // RUN: %check_clang_tidy -check-suffix=USING-B %s misc-unused-using-decls 
%t -- -- -DUSING_B
+   // RUN: %check_clang_tidy %s misc-unused-using-decls %t
+   ...
+   // CHECK-MESSAGES-USING-A: :[[@LINE-8]]:10: warning: using decl 'A' {{.*}}
+   // CHECK-MESSAGES-USING-B: :[[@LINE-7]]:10: warning: using decl 'B' {{.*}}
+   // CHECK-MESSAGES: :[[@LINE-6]]:10: warning: using decl 'C' {{.*}}
+   // CHECK-FIXES-USING-A-NOT: using a::A;$
+   // CHECK-FIXES-USING-B-NOT: using a::B;$
+   // CHECK-FIXES-NOT: using a::C;$
+
+
 There are many dark corners in the C++ language, and it may be difficult to 
make
 your check work perfectly in all cases, especially if it issues fix-it hints. 
The
 most frequent pitfalls are macros and templates:

Added: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp?rev=330511&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp Sat Apr 21 
08:23:56 2018
@@ -0,0 +1,21 @@
+// RUN: %check_clang_tidy -check-suffix=USING-A %s misc-unused-using-decls %t 
-- -- -DUSING_A
+// RUN: %check_clang_tidy -check-suffix=USING-B %s misc-unused-using-decls %t 
-- -- -DUSING_B
+// RUN: %check_clang_tidy %s misc-unused-using-decls %t
+
+namespace a {class A {}; class B {}; class C {}; }
+namespace b {
+#if defined(USING_A)
+using a::A;
+#elif  defined(USING_B)
+using a::B;
+#else
+using a::C;
+#endif
+}
+namespace c {}
+// CHECK-MESSAGES-USING-A: :[[@LINE-8]]:10: warning: using decl 'A' {{.*}}
+// CHECK-MESSAGES-USING-B: :[[@LINE-7]]:10: warning: using decl 'B' {{.*}}
+// CHECK-MESSAGES: :[[@LINE-6]]:10: warning: using decl 'C' {{.*}}
+// CHECK-FIXES-USING-A-NOT: using a::A;$
+// CHECK-FIXES-USING-B-NOT: using a::B;$
+// CHECK-FIXES-NOT: using a::C;$

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=330511&r1=330510&r2=330511&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Sat Apr 21 
08:23:56 2018
@@ -16,8 +16,9 @@ ClangTidy Test Helper
 This script runs clang-tidy in fix mode and verify fixes, messages or both.
 
 Usage:
-  check_clang_tidy.py [-resource-dir ] \
-[-assume-filename ] \
+  check_clang_tidy.py [-resource-dir=] \
+[-assume-filename=] \
+[-check-suffix=] \
\
 -- [optional clang-tidy arguments]
 
@@ -42,6 +43,7 @@ def main():
   parser.add_argument('-expect-clang-tidy-error', action='store_true')
   parser.add_argument('-resource-dir')
   parser.add_argument('-assume-filename')
+  par

[PATCH] D45776: [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py

2018-04-21 Thread Zinovy Nis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330511: [clang-tidy] Customize FileCheck prefix in 
check_clang-tidy.py (authored by zinovy.nis, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45776?vs=143436&id=143453#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45776

Files:
  clang-tools-extra/trunk/docs/clang-tidy/index.rst
  clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.cpp
  clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py

Index: clang-tools-extra/trunk/docs/clang-tidy/index.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/index.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/index.rst
@@ -673,6 +673,27 @@
 // CHECK-FIXES: int b = a;
   }
 
+To check more than one scenario in the same test file use 
+``-check-suffix=SUFFIX-NAME`` on ``check_clang_tidy.py`` command line.
+With ``-check-suffix=SUFFIX-NAME`` you need to replace your ``CHECK-*`` 
+directives with ``CHECK-MESSAGES-SUFFIX-NAME`` and ``CHECK-FIXES-SUFFIX-NAME``.
+
+Here's an example:
+
+.. code-block:: c++
+
+   // RUN: %check_clang_tidy -check-suffix=USING-A %s misc-unused-using-decls %t -- -- -DUSING_A
+   // RUN: %check_clang_tidy -check-suffix=USING-B %s misc-unused-using-decls %t -- -- -DUSING_B
+   // RUN: %check_clang_tidy %s misc-unused-using-decls %t
+   ...
+   // CHECK-MESSAGES-USING-A: :[[@LINE-8]]:10: warning: using decl 'A' {{.*}}
+   // CHECK-MESSAGES-USING-B: :[[@LINE-7]]:10: warning: using decl 'B' {{.*}}
+   // CHECK-MESSAGES: :[[@LINE-6]]:10: warning: using decl 'C' {{.*}}
+   // CHECK-FIXES-USING-A-NOT: using a::A;$
+   // CHECK-FIXES-USING-B-NOT: using a::B;$
+   // CHECK-FIXES-NOT: using a::C;$
+
+
 There are many dark corners in the C++ language, and it may be difficult to make
 your check work perfectly in all cases, especially if it issues fix-it hints. The
 most frequent pitfalls are macros and templates:
Index: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
@@ -16,8 +16,9 @@
 This script runs clang-tidy in fix mode and verify fixes, messages or both.
 
 Usage:
-  check_clang_tidy.py [-resource-dir ] \
-[-assume-filename ] \
+  check_clang_tidy.py [-resource-dir=] \
+[-assume-filename=] \
+[-check-suffix=] \
\
 -- [optional clang-tidy arguments]
 
@@ -42,6 +43,7 @@
   parser.add_argument('-expect-clang-tidy-error', action='store_true')
   parser.add_argument('-resource-dir')
   parser.add_argument('-assume-filename')
+  parser.add_argument('-check-suffix', default='')
   parser.add_argument('input_file_name')
   parser.add_argument('check_name')
   parser.add_argument('temp_file_name')
@@ -70,6 +72,13 @@
   clang_tidy_extra_args.extend(
   ['-fobjc-abi-version=2', '-fobjc-arc'])
 
+  if args.check_suffix and not re.match('^[A-Z0-9\-]+$', args.check_suffix):
+sys.exit('Only A..Z, 0..9 and "-" are allowed in check suffix, but "%s" was given' % (args.check_suffix))
+
+  file_check_suffix = ('-' + args.check_suffix) if args.check_suffix else ''
+  check_fixes_prefix = 'CHECK-FIXES' + file_check_suffix
+  check_messages_prefix = 'CHECK-MESSAGES' + file_check_suffix
+
   # Tests should not rely on STL being available, and instead provide mock
   # implementations of relevant APIs.
   clang_tidy_extra_args.append('-nostdinc++')
@@ -80,17 +89,17 @@
   with open(input_file_name, 'r') as input_file:
 input_text = input_file.read()
 
-  has_check_fixes = input_text.find('CHECK-FIXES') >= 0
-  has_check_messages = input_text.find('CHECK-MESSAGES') >= 0
+  has_check_fixes = check_fixes_prefix in input_text
+  has_check_messages = check_messages_prefix in input_text
 
   if not has_check_fixes and not has_check_messages:
-sys.exit('Neither CHECK-FIXES nor CHECK-MESSAGES found in the input')
+sys.exit('Neither %s nor %s found in the input' % (check_fixes_prefix, check_messages_prefix) )
 
   # Remove the contents of the CHECK lines to avoid CHECKs matching on
   # themselves.  We need to keep the comments to preserve line numbers while
   # avoiding empty lines which could potentially trigger formatting-related
   # checks.
-  cleaned_test = re.sub('// *CHECK-[A-Z-]*:[^\r\n]*', '//', input_text)
+  cleaned_test = re.sub('// *CHECK-[A-Z0-9\-]*:[^\r\n]*', '//', input_text)
 
   write_file(temp_file_name, cleaned_test)
 
@@ -128,7 +137,7 @@
 try:
   subprocess.check_output(
   ['FileCheck', '-input-file=' + temp_file_name, input_file_name,
-   '-check-prefix=CHECK-FIXES', '-strict-whitespace'],
+   '-check-prefix=' + check_fixes_prefix, '-strict-whitespace'],
   stderr=subprocess.STDOUT)
 except subprocess.CalledProcessError a

[PATCH] D41980: Add tests for llvm-bcanalyzer stream types

2018-04-21 Thread Brian Gesiak via Phabricator via cfe-commits
modocache updated this revision to Diff 143458.
modocache added a comment.
Herald added a reviewer: george.karpenkov.

Added `-fmodule-format=raw`.


Repository:
  rC Clang

https://reviews.llvm.org/D41980

Files:
  test/Misc/serialized-diags-bcanalyzer.c
  test/PCH/include-stream-type.cpp


Index: test/PCH/include-stream-type.cpp
===
--- /dev/null
+++ test/PCH/include-stream-type.cpp
@@ -0,0 +1,10 @@
+// Test that llvm-bcanalyzer recognizes the stream type of a PCH file.
+
+// RUN: mkdir -p %t-dir
+// Copying files allow for read-only checkouts to run this test.
+// RUN: cp %S/Inputs/pragma-once2-pch.h %t-dir
+// RUN: cp %S/Inputs/pragma-once2.h %t-dir
+// RUN: %clang_cc1 -x c++-header -emit-pch -fmodule-format=raw -o %t 
%t-dir/pragma-once2-pch.h
+// RUN: llvm-bcanalyzer -dump %t | FileCheck %s
+//
+// CHECK: Stream type: Clang Serialized AST
Index: test/Misc/serialized-diags-bcanalyzer.c
===
--- /dev/null
+++ test/Misc/serialized-diags-bcanalyzer.c
@@ -0,0 +1,3 @@
+// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t.diag > 
/dev/null 2>&1
+// RUN: llvm-bcanalyzer -dump %t.diag | FileCheck %s
+// CHECK: Stream type: Clang Serialized Diagnostics


Index: test/PCH/include-stream-type.cpp
===
--- /dev/null
+++ test/PCH/include-stream-type.cpp
@@ -0,0 +1,10 @@
+// Test that llvm-bcanalyzer recognizes the stream type of a PCH file.
+
+// RUN: mkdir -p %t-dir
+// Copying files allow for read-only checkouts to run this test.
+// RUN: cp %S/Inputs/pragma-once2-pch.h %t-dir
+// RUN: cp %S/Inputs/pragma-once2.h %t-dir
+// RUN: %clang_cc1 -x c++-header -emit-pch -fmodule-format=raw -o %t %t-dir/pragma-once2-pch.h
+// RUN: llvm-bcanalyzer -dump %t | FileCheck %s
+//
+// CHECK: Stream type: Clang Serialized AST
Index: test/Misc/serialized-diags-bcanalyzer.c
===
--- /dev/null
+++ test/Misc/serialized-diags-bcanalyzer.c
@@ -0,0 +1,3 @@
+// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t.diag > /dev/null 2>&1
+// RUN: llvm-bcanalyzer -dump %t.diag | FileCheck %s
+// CHECK: Stream type: Clang Serialized Diagnostics
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r330528 - Revert r330492: [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-21 Thread Chandler Carruth via cfe-commits
Author: chandlerc
Date: Sat Apr 21 16:27:34 2018
New Revision: 330528

URL: http://llvm.org/viewvc/llvm-project?rev=330528&view=rev
Log:
Revert r330492: [clang-tidy] add new check to find out objc ivars which do not 
have prefix '_'

This commit has been breaking most bots for a day now. There is a fix
proposed in https://reviews.llvm.org/D45912 but when I applied that
I just got different errors. Reverting to get our bots back to green.

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

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=330528&r1=330527&r2=330528&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
Sat Apr 21 16:27:34 2018
@@ -109,7 +109,6 @@ namespace readability {
 m(TemplateParameter) \
 m(TypeAlias) \
 m(MacroDefinition) \
-m(ObjcIvar) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -385,9 +384,6 @@ static StyleKind findStyleKind(
 const NamedDecl *D,
 const std::vector>
 &NamingStyles) {
-  if (isa(D) && NamingStyles[SK_ObjcIvar])
-return SK_ObjcIvar;
-
   if (isa(D) && NamingStyles[SK_Typedef])
 return SK_Typedef;
 

Removed: 
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m?rev=330527&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m 
(removed)
@@ -1,15 +0,0 @@
-// RUN: %check_clang_tidy %s readability-identifier-naming %t \
-// RUN: -config='{CheckOptions: \
-// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
-// RUN: --
-
-@interface Foo
-@end 
-
-@interface Foo () {
-int _bar;
-int barWithoutPrefix;
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc 
ivar 'barWithoutPrefix' [readability-identifier-naming]
-// CHECK-FIXES: int _barWithoutPrefix;
-}
-@end


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


Re: [clang-tools-extra] r330492 - [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-21 Thread Chandler Carruth via cfe-commits
Ok, this still isn't fixed a day later and over half our build bots are red
because of it. =/ I tried just applying the patch, and it doesn't seem to
fully fix the test as it results in a different error...

I've reverted in r330528 for now so that our bots are green. =] Feel free
to re-land once you've confirmed the tests are passing, and keep an eye on
the bots after it goes in. =D

On Fri, Apr 20, 2018 at 11:33 PM Chandler Carruth 
wrote:

> I see Alex already got it, but in the future, that kind of trivial test
> fix for a failing test is fine to just land, and it is more important to
> get the bots healthy. =]
>
> On Fri, Apr 20, 2018, 22:14 Yan Zhang via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> https://reviews.llvm.org/D45912 need someone to accept
>>
>> Best regards
>> Yan Zhang
>>
>> On Apr 20, 2018, at 19:08, Chandler Carruth  wrote:
>>
>> This has broken most of the build bots. Are you working on a fix or
>> revert?
>>
>> Might be useful to get on the IRC channel to help coordinate this kind of
>> thing.
>>
>> On Fri, Apr 20, 2018 at 4:45 PM Yan Zhang via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: wizard
>>> Date: Fri Apr 20 16:18:09 2018
>>> New Revision: 330492
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=330492&view=rev
>>> Log:
>>> [clang-tidy] add new check to find out objc ivars which do not have
>>> prefix '_'
>>>
>>> Summary:
>>> For code of ivar declaration:
>>>
>>>int barWithoutPrefix;
>>>
>>> The fix will be:
>>>
>>>int _barWithoutPrefix;
>>>
>>> Reviewers: benhamilton, hokein, alexfh, aaron.ballman, ilya-biryukov
>>>
>>> Reviewed By: alexfh
>>>
>>> Subscribers: Eugene.Zelenko, xazax.hun, klimek, mgorny, cfe-commits
>>>
>>> Tags: #clang-tools-extra
>>>
>>> Differential Revision: https://reviews.llvm.org/D45392
>>>
>>> Added:
>>>
>>> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>>> Modified:
>>>
>>> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
>>>
>>> Modified:
>>> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=330492&r1=330491&r2=330492&view=diff
>>>
>>> ==
>>> ---
>>> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
>>> (original)
>>> +++
>>> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
>>> Fri Apr 20 16:18:09 2018
>>> @@ -109,6 +109,7 @@ namespace readability {
>>>  m(TemplateParameter) \
>>>  m(TypeAlias) \
>>>  m(MacroDefinition) \
>>> +m(ObjcIvar) \
>>>
>>>  enum StyleKind {
>>>  #define ENUMERATE(v) SK_ ## v,
>>> @@ -384,6 +385,9 @@ static StyleKind findStyleKind(
>>>  const NamedDecl *D,
>>>  const
>>> std::vector>
>>>  &NamingStyles) {
>>> +  if (isa(D) && NamingStyles[SK_ObjcIvar])
>>> +return SK_ObjcIvar;
>>> +
>>>if (isa(D) && NamingStyles[SK_Typedef])
>>>  return SK_Typedef;
>>>
>>>
>>> Added:
>>> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m?rev=330492&view=auto
>>>
>>> ==
>>> ---
>>> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>>> (added)
>>> +++
>>> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>>> Fri Apr 20 16:18:09 2018
>>> @@ -0,0 +1,15 @@
>>> +// RUN: %check_clang_tidy %s readability-identifier-naming %t \
>>> +// RUN: -config='{CheckOptions: \
>>> +// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value:
>>> '_'}]}' \
>>> +// RUN: --
>>> +
>>> +@interface Foo
>>> +@end
>>> +
>>> +@interface Foo () {
>>> +int _bar;
>>> +int barWithoutPrefix;
>>> +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for
>>> objc ivar 'barWithoutPrefix' [readability-identifier-naming]
>>> +// CHECK-FIXES: int _barWithoutPrefix;
>>> +}
>>> +@end
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r330530 - Add tests for llvm-bcanalyzer stream types

2018-04-21 Thread Brian Gesiak via cfe-commits
Author: modocache
Date: Sat Apr 21 17:04:35 2018
New Revision: 330530

URL: http://llvm.org/viewvc/llvm-project?rev=330530&view=rev
Log:
Add tests for llvm-bcanalyzer stream types

Summary:
Add tests for the improved stream type detection added to
`llvm-bcanalyzer` in https://reviews.llvm.org/D41979.

Test Plan: `check-clang`

Reviewers: pcc, aprantl, mehdi_amini, george.karpenkov

Reviewed By: aprantl

Subscribers: cfe-commits, a.sidorin

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

Added:
cfe/trunk/test/Misc/serialized-diags-bcanalyzer.c
cfe/trunk/test/PCH/include-stream-type.cpp

Added: cfe/trunk/test/Misc/serialized-diags-bcanalyzer.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/serialized-diags-bcanalyzer.c?rev=330530&view=auto
==
--- cfe/trunk/test/Misc/serialized-diags-bcanalyzer.c (added)
+++ cfe/trunk/test/Misc/serialized-diags-bcanalyzer.c Sat Apr 21 17:04:35 2018
@@ -0,0 +1,3 @@
+// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t.diag > 
/dev/null 2>&1
+// RUN: llvm-bcanalyzer -dump %t.diag | FileCheck %s
+// CHECK: Stream type: Clang Serialized Diagnostics

Added: cfe/trunk/test/PCH/include-stream-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/include-stream-type.cpp?rev=330530&view=auto
==
--- cfe/trunk/test/PCH/include-stream-type.cpp (added)
+++ cfe/trunk/test/PCH/include-stream-type.cpp Sat Apr 21 17:04:35 2018
@@ -0,0 +1,10 @@
+// Test that llvm-bcanalyzer recognizes the stream type of a PCH file.
+
+// RUN: mkdir -p %t-dir
+// Copying files allow for read-only checkouts to run this test.
+// RUN: cp %S/Inputs/pragma-once2-pch.h %t-dir
+// RUN: cp %S/Inputs/pragma-once2.h %t-dir
+// RUN: %clang_cc1 -x c++-header -emit-pch -fmodule-format=raw -o %t 
%t-dir/pragma-once2-pch.h
+// RUN: llvm-bcanalyzer -dump %t | FileCheck %s
+//
+// CHECK: Stream type: Clang Serialized AST


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


[PATCH] D41980: Add tests for llvm-bcanalyzer stream types

2018-04-21 Thread Brian Gesiak via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC330530: Add tests for llvm-bcanalyzer stream types (authored 
by modocache, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41980?vs=143458&id=143464#toc

Repository:
  rC Clang

https://reviews.llvm.org/D41980

Files:
  test/Misc/serialized-diags-bcanalyzer.c
  test/PCH/include-stream-type.cpp


Index: test/PCH/include-stream-type.cpp
===
--- test/PCH/include-stream-type.cpp
+++ test/PCH/include-stream-type.cpp
@@ -0,0 +1,10 @@
+// Test that llvm-bcanalyzer recognizes the stream type of a PCH file.
+
+// RUN: mkdir -p %t-dir
+// Copying files allow for read-only checkouts to run this test.
+// RUN: cp %S/Inputs/pragma-once2-pch.h %t-dir
+// RUN: cp %S/Inputs/pragma-once2.h %t-dir
+// RUN: %clang_cc1 -x c++-header -emit-pch -fmodule-format=raw -o %t 
%t-dir/pragma-once2-pch.h
+// RUN: llvm-bcanalyzer -dump %t | FileCheck %s
+//
+// CHECK: Stream type: Clang Serialized AST
Index: test/Misc/serialized-diags-bcanalyzer.c
===
--- test/Misc/serialized-diags-bcanalyzer.c
+++ test/Misc/serialized-diags-bcanalyzer.c
@@ -0,0 +1,3 @@
+// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t.diag > 
/dev/null 2>&1
+// RUN: llvm-bcanalyzer -dump %t.diag | FileCheck %s
+// CHECK: Stream type: Clang Serialized Diagnostics


Index: test/PCH/include-stream-type.cpp
===
--- test/PCH/include-stream-type.cpp
+++ test/PCH/include-stream-type.cpp
@@ -0,0 +1,10 @@
+// Test that llvm-bcanalyzer recognizes the stream type of a PCH file.
+
+// RUN: mkdir -p %t-dir
+// Copying files allow for read-only checkouts to run this test.
+// RUN: cp %S/Inputs/pragma-once2-pch.h %t-dir
+// RUN: cp %S/Inputs/pragma-once2.h %t-dir
+// RUN: %clang_cc1 -x c++-header -emit-pch -fmodule-format=raw -o %t %t-dir/pragma-once2-pch.h
+// RUN: llvm-bcanalyzer -dump %t | FileCheck %s
+//
+// CHECK: Stream type: Clang Serialized AST
Index: test/Misc/serialized-diags-bcanalyzer.c
===
--- test/Misc/serialized-diags-bcanalyzer.c
+++ test/Misc/serialized-diags-bcanalyzer.c
@@ -0,0 +1,3 @@
+// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t.diag > /dev/null 2>&1
+// RUN: llvm-bcanalyzer -dump %t.diag | FileCheck %s
+// CHECK: Stream type: Clang Serialized Diagnostics
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r330492 - [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-21 Thread Yan Zhang via cfe-commits
Sorry I was out today. What is the new error? Can u send it to me?

Best regards
Yan Zhang

> On Apr 21, 2018, at 16:32, Chandler Carruth  wrote:
> 
> Ok, this still isn't fixed a day later and over half our build bots are red 
> because of it. =/ I tried just applying the patch, and it doesn't seem to 
> fully fix the test as it results in a different error...
> 
> I've reverted in r330528 for now so that our bots are green. =] Feel free to 
> re-land once you've confirmed the tests are passing, and keep an eye on the 
> bots after it goes in. =D
> 
>> On Fri, Apr 20, 2018 at 11:33 PM Chandler Carruth  
>> wrote:
>> I see Alex already got it, but in the future, that kind of trivial test fix 
>> for a failing test is fine to just land, and it is more important to get the 
>> bots healthy. =]
>> 
>>> On Fri, Apr 20, 2018, 22:14 Yan Zhang via cfe-commits 
>>>  wrote:
>>> https://reviews.llvm.org/D45912 need someone to accept 
>>> 
>>> Best regards
>>> Yan Zhang
>>> 
 On Apr 20, 2018, at 19:08, Chandler Carruth  wrote:
 
 This has broken most of the build bots. Are you working on a fix or revert?
 
 Might be useful to get on the IRC channel to help coordinate this kind of 
 thing.
 
> On Fri, Apr 20, 2018 at 4:45 PM Yan Zhang via cfe-commits 
>  wrote:
> Author: wizard
> Date: Fri Apr 20 16:18:09 2018
> New Revision: 330492
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=330492&view=rev
> Log:
> [clang-tidy] add new check to find out objc ivars which do not have 
> prefix '_'
> 
> Summary:
> For code of ivar declaration:
> 
>int barWithoutPrefix;
> 
> The fix will be:
> 
>int _barWithoutPrefix;
> 
> Reviewers: benhamilton, hokein, alexfh, aaron.ballman, ilya-biryukov
> 
> Reviewed By: alexfh
> 
> Subscribers: Eugene.Zelenko, xazax.hun, klimek, mgorny, cfe-commits
> 
> Tags: #clang-tools-extra
> 
> Differential Revision: https://reviews.llvm.org/D45392
> 
> Added:
> 
> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
> Modified:
> 
> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
> 
> Modified: 
> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=330492&r1=330491&r2=330492&view=diff
> ==
> --- 
> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
> (original)
> +++ 
> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
> Fri Apr 20 16:18:09 2018
> @@ -109,6 +109,7 @@ namespace readability {
>  m(TemplateParameter) \
>  m(TypeAlias) \
>  m(MacroDefinition) \
> +m(ObjcIvar) \
> 
>  enum StyleKind {
>  #define ENUMERATE(v) SK_ ## v,
> @@ -384,6 +385,9 @@ static StyleKind findStyleKind(
>  const NamedDecl *D,
>  const std::vector>
>  &NamingStyles) {
> +  if (isa(D) && NamingStyles[SK_ObjcIvar])
> +return SK_ObjcIvar;
> +
>if (isa(D) && NamingStyles[SK_Typedef])
>  return SK_Typedef;
> 
> 
> Added: 
> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m?rev=330492&view=auto
> ==
> --- 
> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>  (added)
> +++ 
> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>  Fri Apr 20 16:18:09 2018
> @@ -0,0 +1,15 @@
> +// RUN: %check_clang_tidy %s readability-identifier-naming %t \
> +// RUN: -config='{CheckOptions: \
> +// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: 
> '_'}]}' \
> +// RUN: --
> +
> +@interface Foo
> +@end 
> +
> +@interface Foo () {
> +int _bar;
> +int barWithoutPrefix;
> +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for 
> objc ivar 'barWithoutPrefix' [readability-identifier-naming]
> +// CHECK-FIXES: int _barWithoutPrefix;
> +}
> +@end
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-c

Re: [clang-tools-extra] r330492 - [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-21 Thread Chandler Carruth via cfe-commits
Should be able to reproduce it by patching it in and running the tests
yourself? Nothing configuration specific here. Still, no hurry.

On Sat, Apr 21, 2018 at 6:02 PM Yan Zhang via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Sorry I was out today. What is the new error? Can u send it to me?
>
> Best regards
> Yan Zhang
>
> On Apr 21, 2018, at 16:32, Chandler Carruth  wrote:
>
> Ok, this still isn't fixed a day later and over half our build bots are
> red because of it. =/ I tried just applying the patch, and it doesn't seem
> to fully fix the test as it results in a different error...
>
> I've reverted in r330528 for now so that our bots are green. =] Feel free
> to re-land once you've confirmed the tests are passing, and keep an eye on
> the bots after it goes in. =D
>
> On Fri, Apr 20, 2018 at 11:33 PM Chandler Carruth 
> wrote:
>
>> I see Alex already got it, but in the future, that kind of trivial test
>> fix for a failing test is fine to just land, and it is more important to
>> get the bots healthy. =]
>>
>> On Fri, Apr 20, 2018, 22:14 Yan Zhang via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> https://reviews.llvm.org/D45912 need someone to accept
>>>
>>> Best regards
>>> Yan Zhang
>>>
>>> On Apr 20, 2018, at 19:08, Chandler Carruth  wrote:
>>>
>>> This has broken most of the build bots. Are you working on a fix or
>>> revert?
>>>
>>> Might be useful to get on the IRC channel to help coordinate this kind
>>> of thing.
>>>
>>> On Fri, Apr 20, 2018 at 4:45 PM Yan Zhang via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: wizard
 Date: Fri Apr 20 16:18:09 2018
 New Revision: 330492

 URL: http://llvm.org/viewvc/llvm-project?rev=330492&view=rev
 Log:
 [clang-tidy] add new check to find out objc ivars which do not have
 prefix '_'

 Summary:
 For code of ivar declaration:

int barWithoutPrefix;

 The fix will be:

int _barWithoutPrefix;

 Reviewers: benhamilton, hokein, alexfh, aaron.ballman, ilya-biryukov

 Reviewed By: alexfh

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

 Tags: #clang-tools-extra

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

 Added:

 clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
 Modified:

 clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp

 Modified:
 clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=330492&r1=330491&r2=330492&view=diff

 ==
 ---
 clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
 (original)
 +++
 clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
 Fri Apr 20 16:18:09 2018
 @@ -109,6 +109,7 @@ namespace readability {
  m(TemplateParameter) \
  m(TypeAlias) \
  m(MacroDefinition) \
 +m(ObjcIvar) \

  enum StyleKind {
  #define ENUMERATE(v) SK_ ## v,
 @@ -384,6 +385,9 @@ static StyleKind findStyleKind(
  const NamedDecl *D,
  const
 std::vector>
  &NamingStyles) {
 +  if (isa(D) && NamingStyles[SK_ObjcIvar])
 +return SK_ObjcIvar;
 +
if (isa(D) && NamingStyles[SK_Typedef])
  return SK_Typedef;


 Added:
 clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
 URL:
 http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m?rev=330492&view=auto

 ==
 ---
 clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
 (added)
 +++
 clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
 Fri Apr 20 16:18:09 2018
 @@ -0,0 +1,15 @@
 +// RUN: %check_clang_tidy %s readability-identifier-naming %t \
 +// RUN: -config='{CheckOptions: \
 +// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value:
 '_'}]}' \
 +// RUN: --
 +
 +@interface Foo
 +@end
 +
 +@interface Foo () {
 +int _bar;
 +int barWithoutPrefix;
 +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for
 objc ivar 'barWithoutPrefix' [readability-identifier-naming]
 +// CHECK-FIXES: int _barWithoutPrefix;
 +}
 +@end


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

>>> ___
>>> cfe-commits mailing

Re: [clang-tools-extra] r330492 - [clang-tidy] add new check to find out objc ivars which do not have prefix '_'

2018-04-21 Thread Yan Zhang via cfe-commits
Hmm I have tested it locally before with 64-bit macOS and everything looks good.

Best regards
Yan Zhang

> On Apr 21, 2018, at 18:15, Chandler Carruth  wrote:
> 
> Should be able to reproduce it by patching it in and running the tests 
> yourself? Nothing configuration specific here. Still, no hurry.
> 
>> On Sat, Apr 21, 2018 at 6:02 PM Yan Zhang via cfe-commits 
>>  wrote:
>> Sorry I was out today. What is the new error? Can u send it to me?
>> 
>> Best regards
>> Yan Zhang
>> 
>>> On Apr 21, 2018, at 16:32, Chandler Carruth  wrote:
>>> 
>>> Ok, this still isn't fixed a day later and over half our build bots are red 
>>> because of it. =/ I tried just applying the patch, and it doesn't seem to 
>>> fully fix the test as it results in a different error...
>>> 
>>> I've reverted in r330528 for now so that our bots are green. =] Feel free 
>>> to re-land once you've confirmed the tests are passing, and keep an eye on 
>>> the bots after it goes in. =D
>>> 
 On Fri, Apr 20, 2018 at 11:33 PM Chandler Carruth  
 wrote:
 I see Alex already got it, but in the future, that kind of trivial test 
 fix for a failing test is fine to just land, and it is more important to 
 get the bots healthy. =]
 
> On Fri, Apr 20, 2018, 22:14 Yan Zhang via cfe-commits 
>  wrote:
> https://reviews.llvm.org/D45912 need someone to accept 
> 
> Best regards
> Yan Zhang
> 
>> On Apr 20, 2018, at 19:08, Chandler Carruth  wrote:
>> 
>> This has broken most of the build bots. Are you working on a fix or 
>> revert?
>> 
>> Might be useful to get on the IRC channel to help coordinate this kind 
>> of thing.
>> 
>>> On Fri, Apr 20, 2018 at 4:45 PM Yan Zhang via cfe-commits 
>>>  wrote:
>>> Author: wizard
>>> Date: Fri Apr 20 16:18:09 2018
>>> New Revision: 330492
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=330492&view=rev
>>> Log:
>>> [clang-tidy] add new check to find out objc ivars which do not have 
>>> prefix '_'
>>> 
>>> Summary:
>>> For code of ivar declaration:
>>> 
>>>int barWithoutPrefix;
>>> 
>>> The fix will be:
>>> 
>>>int _barWithoutPrefix;
>>> 
>>> Reviewers: benhamilton, hokein, alexfh, aaron.ballman, ilya-biryukov
>>> 
>>> Reviewed By: alexfh
>>> 
>>> Subscribers: Eugene.Zelenko, xazax.hun, klimek, mgorny, cfe-commits
>>> 
>>> Tags: #clang-tools-extra
>>> 
>>> Differential Revision: https://reviews.llvm.org/D45392
>>> 
>>> Added:
>>> 
>>> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>>> Modified:
>>> 
>>> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
>>> 
>>> Modified: 
>>> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=330492&r1=330491&r2=330492&view=diff
>>> ==
>>> --- 
>>> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
>>>  (original)
>>> +++ 
>>> clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
>>>  Fri Apr 20 16:18:09 2018
>>> @@ -109,6 +109,7 @@ namespace readability {
>>>  m(TemplateParameter) \
>>>  m(TypeAlias) \
>>>  m(MacroDefinition) \
>>> +m(ObjcIvar) \
>>> 
>>>  enum StyleKind {
>>>  #define ENUMERATE(v) SK_ ## v,
>>> @@ -384,6 +385,9 @@ static StyleKind findStyleKind(
>>>  const NamedDecl *D,
>>>  const 
>>> std::vector>
>>>  &NamingStyles) {
>>> +  if (isa(D) && NamingStyles[SK_ObjcIvar])
>>> +return SK_ObjcIvar;
>>> +
>>>if (isa(D) && NamingStyles[SK_Typedef])
>>>  return SK_Typedef;
>>> 
>>> 
>>> Added: 
>>> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m?rev=330492&view=auto
>>> ==
>>> --- 
>>> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>>>  (added)
>>> +++ 
>>> clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
>>>  Fri Apr 20 16:18:09 2018
>>> @@ -0,0 +1,15 @@
>>> +// RUN: %check_clang_tidy %s readability-identifier-naming %t \
>>> +// RUN: -config='{CheckOptions: \
>>> +// RUN:  [{key: readability-identifier-naming.ObjcIvarPrefix, value: 
>>> '_'}]}' \
>>> +// RUN: --
>>> +
>>> +@interface Foo
>>> +@end 
>>> +
>>> +@interface Foo () {
>>> +int _bar;
>>> +int barWith

[PATCH] D45927: [clang-tidy] [modernize-use-auto] Correct way to calculate a type name length for multi-token types

2018-04-21 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis created this revision.
zinovy.nis added reviewers: malcolm.parsons, alexfh.
zinovy.nis added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.

This patch is a fix for https://reviews.llvm.org/D45405 where spaces were also 
considered as a part of a type name. So length("int *") was 5 instead of 3 with 
RemoveStars=0 or 4 with RemoveStars=1.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45927

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  clang-tidy/modernize/UseAutoCheck.h
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-min-type-name-length.cpp

Index: test/clang-tidy/modernize-use-auto-min-type-name-length.cpp
===
--- test/clang-tidy/modernize-use-auto-min-type-name-length.cpp
+++ test/clang-tidy/modernize-use-auto-min-type-name-length.cpp
@@ -1,29 +1,82 @@
-// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
-// RUN:   -config="{CheckOptions: [{key: modernize-use-auto.MinTypeNameLength, value: '5'}]}" \
-// RUN:   -- -std=c++11 -frtti
+// RUN: %check_clang_tidy -check-suffix=0-0 %s modernize-use-auto %t  -- -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: 0}, {key: modernize-use-auto.MinTypeNameLength, value: 0}]}" -- --std=c++11 -frtti
+// RUN: %check_clang_tidy -check-suffix=0-5 %s modernize-use-auto %t  -- -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: 0}, {key: modernize-use-auto.MinTypeNameLength, value: 5}]}" -- --std=c++11 -frtti
+// RUN: %check_clang_tidy -check-suffix=1-0 %s modernize-use-auto %t  -- -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: 1}, {key: modernize-use-auto.MinTypeNameLength, value: 0}]}" -- --std=c++11 -frtti
+// RUN: %check_clang_tidy -check-suffix=1-5 %s modernize-use-auto %t  -- -config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: 1}, {key: modernize-use-auto.MinTypeNameLength, value: 5}]}" -- --std=c++11 -frtti
 
-extern int foo();
-
-using VeryVeryVeryLongTypeName = int;
+template 
+extern T foo();
 
 int bar() {
-  int a = static_cast(foo());
-  // strlen('int') = 4 <  5, so skip it,
-  // even strlen('VeryVeryVeryLongTypeName') > 5.
-
-  unsigned b = static_cast(foo());
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
-  // CHECK-FIXES: auto b = static_cast(foo());
-
-  bool c = static_cast(foo());
-  // strlen('bool') = 4 <  5, so skip it.
-
-  const bool c1 = static_cast(foo());
-  // strlen('bool') = 4 <  5, so skip it, even there's a 'const'.
-
-  unsigned long long ull = static_cast(foo());
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
-  // CHECK-FIXES: auto ull = static_cast(foo());
+  {
+using VeryVeryVeryLongTypeName = int;
+int i = static_cast(foo());
+// CHECK-FIXES-0-0: auto i = {{.*}}
+// CHECK-FIXES-0-5: int i = {{.*}}
+// CHECK-FIXES-1-0: auto  i = {{.*}}
+// CHECK-FIXES-1-5: int i = {{.*}}
+int *pi = static_cast(foo());
+// CHECK-FIXES-0-0: auto *pi = {{.*}}
+// CHECK-FIXES-0-5: int *pi = {{.*}}
+// CHECK-FIXES-1-0: auto pi = {{.*}}
+// CHECK-FIXES-1-5: int *pi = {{.*}}
+int **ppi = static_cast(foo());
+// CHECK-FIXES-0-0: auto **ppi = {{.*}}
+// CHECK-FIXES-0-5: int **ppi = {{.*}}
+// CHECK-FIXES-1-0: auto ppi = {{.*}}
+// CHECK-FIXES-1-5: auto ppi = {{.*}}
+}
+
+  {
+bool b = static_cast(foo());
+// CHECK-FIXES-0-0: auto b = {{.*}}
+// CHECK-FIXES-0-5: bool b = {{.*}}
+// CHECK-FIXES-1-0: auto  b = {{.*}}
+// CHECK-FIXES-1-5: bool b = {{.*}}
+bool *pb = static_cast(foo());
+// CHECK-FIXES-0-0: auto *pb = {{.*}}
+// CHECK-FIXES-0-5: bool *pb = {{.*}}
+// CHECK-FIXES-1-0: auto pb = {{.*}}
+// CHECK-FIXES-1-5: auto pb = {{.*}}
+  }
+
+  {
+const bool cb = static_cast(foo());
+// CHECK-FIXES-0-0: auto cb = {{.*}}
+// CHECK-FIXES-0-5: bool cb = {{.*}}
+// CHECK-FIXES-1-0: auto  cb = {{.*}}
+// CHECK-FIXES-1-5: bool cb = {{.*}}
+const bool *pcb = static_cast(foo());
+// CHECK-FIXES-0-0: const auto *pcb = {{.*}}
+// CHECK-FIXES-0-5: const bool *pcb = {{.*}}
+// CHECK-FIXES-1-0: const auto pcb = {{.*}}
+// CHECK-FIXES-1-5: const auto pcb = {{.*}}
+  }
+
+  {
+long int li = static_cast(foo());
+// CHECK-FIXES-0-0: auto li = {{.*}}
+// CHECK-FIXES-0-5: auto li = {{.*}}
+// CHECK-FIXES-1-0: auto  li = {{.*}}
+// CHECK-FIXES-1-5: auto  li = {{.*}}
+long int *pli = static_cast(foo());
+// CHECK-FIXES-0-0: auto *pli = {{.*}}
+// CHECK-FIXES-0-5: auto *pli = {{.*}}
+// CHECK-FIXES-1-0: auto pli = {{.*}}
+// CHECK-FIXES-1-5: auto pli = {{.*}}
+  }
+
+  {
+unsigned long long ull = static_cast(foo());
+// CHECK-FIXES-0-0: auto ull = {{.*}}
+