Re: [PATCH] D23602: Port tools/clang-format/git-clang-format to work Python beyond 2.7

2016-08-18 Thread Andreas Bergmeier via cfe-commits
abergmeier-dsfishlabs removed rL LLVM as the repository for this revision.
abergmeier-dsfishlabs updated this revision to Diff 68487.
abergmeier-dsfishlabs added a comment.

Removed unnecessary list conversion.


https://reviews.llvm.org/D23602

Files:
  tools/clang-format/git-clang-format

Index: tools/clang-format/git-clang-format
===
--- tools/clang-format/git-clang-format
+++ tools/clang-format/git-clang-format
@@ -20,9 +20,11 @@
 For further details, run:
 git clang-format -h  
  
-Requires Python 2.7  
+Requires a minimum of Python 2.7 
 """   
 
+from __future__ import print_function
+
 import argparse
 import collections
 import contextlib
@@ -128,15 +130,15 @@
   if opts.verbose >= 1:
 ignored_files.difference_update(changed_lines)
 if ignored_files:
-  print 'Ignoring changes in the following files (wrong extension):'
+  print('Ignoring changes in the following files (wrong extension):')
   for filename in ignored_files:
-print '   ', filename
+print('   ', filename)
 if changed_lines:
-  print 'Running clang-format on the following files:'
+  print('Running clang-format on the following files:')
   for filename in changed_lines:
-print '   ', filename
+print('   ', filename)
   if not changed_lines:
-print 'no modified files to format'
+print('no modified files to format')
 return
   # The computed diff outputs absolute paths, so we must cd before accessing
   # those files.
@@ -146,20 +148,20 @@
binary=opts.binary,
style=opts.style)
   if opts.verbose >= 1:
-print 'old tree:', old_tree
-print 'new tree:', new_tree
+print('old tree:', old_tree)
+print('new tree:', new_tree)
   if old_tree == new_tree:
 if opts.verbose >= 0:
-  print 'clang-format did not modify any files'
+  print('clang-format did not modify any files')
   elif opts.diff:
 print_diff(old_tree, new_tree)
   else:
 changed_files = apply_changes(old_tree, new_tree, force=opts.force,
   patch_mode=opts.patch)
 if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
-  print 'changed files:'
+  print('changed files:')
   for filename in changed_files:
-print '   ', filename
+print('   ', filename)
 
 
 def load_git_config(non_string_options=None):
@@ -323,7 +325,7 @@
 
   Returns the object ID (SHA-1) of the created tree."""
   def index_info_generator():
-for filename, line_ranges in changed_lines.iteritems():
+for filename, line_ranges in changed_lines.items():
   mode = oct(os.stat(filename).st_mode)
   blob_id = clang_format_to_blob(filename, line_ranges, binary=binary,
  style=style)
@@ -431,10 +433,10 @@
   if not force:
 unstaged_files = run('git', 'diff-files', '--name-status', *changed_files)
 if unstaged_files:
-  print >>sys.stderr, ('The following files would be modified but '
-   'have unstaged changes:')
-  print >>sys.stderr, unstaged_files
-  print >>sys.stderr, 'Please commit, stage, or stash them first.'
+  print(('The following files would be modified but '
+   'have unstaged changes:'), file=sys.stderr)
+  print(unstaged_files, file=sys.stderr)
+  print('Please commit, stage, or stash them first.', file=sys.stderr)
   sys.exit(2)
   if patch_mode:
 # In patch mode, we could just as well create an index from the new tree
@@ -464,20 +466,20 @@
   if p.returncode == 0:
 if stderr:
   if verbose:
-print >>sys.stderr, '`%s` printed to stderr:' % ' '.join(args)
-  print >>sys.stderr, stderr.rstrip()
+print('`%s` printed to stderr:' % ' '.join(args), file=sys.stderr)
+  print(stderr.rstrip(), file=sys.stderr)
 if strip:
   stdout = stdout.rstrip('\r\n')
 return stdout
   if verbose:
-print >>sys.stderr, '`%s` returned %s' % (' '.join(args), p.returncode)
+print('`%s` returned %s' % (' '.join(args), p.returncode), file=sys.stderr)
   if stderr:
-print >>sys.stderr, stderr.rstrip()
+print(stderr.rstrip(), file=sys.stderr)
   sys.exit(2)
 
 
 def die(message):
-  print >>sys.stderr, 'error:', message
+  print('error:', message, file=sys.stderr)
   sys.exit(2)
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23602: Port tools/clang-format/git-clang-format to work Python beyond 2.7

2016-08-18 Thread Andreas Bergmeier via cfe-commits
abergmeier-dsfishlabs set the repository for this revision to rL LLVM.
abergmeier-dsfishlabs updated this revision to Diff 68488.
abergmeier-dsfishlabs added a comment.

Proper patch of last version (hopefully)


Repository:
  rL LLVM

https://reviews.llvm.org/D23602

Files:
  tools/clang-format/git-clang-format

Index: tools/clang-format/git-clang-format
===
--- tools/clang-format/git-clang-format
+++ tools/clang-format/git-clang-format
@@ -20,9 +20,11 @@
 For further details, run:
 git clang-format -h  
  
-Requires Python 2.7  
+Requires a minimum of Python 2.7 
 """   
 
+from __future__ import print_function
+
 import argparse
 import collections
 import contextlib
@@ -128,15 +130,15 @@
   if opts.verbose >= 1:
 ignored_files.difference_update(changed_lines)
 if ignored_files:
-  print 'Ignoring changes in the following files (wrong extension):'
+  print('Ignoring changes in the following files (wrong extension):')
   for filename in ignored_files:
-print '   ', filename
+print('   ', filename)
 if changed_lines:
-  print 'Running clang-format on the following files:'
+  print('Running clang-format on the following files:')
   for filename in changed_lines:
-print '   ', filename
+print('   ', filename)
   if not changed_lines:
-print 'no modified files to format'
+print('no modified files to format')
 return
   # The computed diff outputs absolute paths, so we must cd before accessing
   # those files.
@@ -146,20 +148,20 @@
binary=opts.binary,
style=opts.style)
   if opts.verbose >= 1:
-print 'old tree:', old_tree
-print 'new tree:', new_tree
+print('old tree:', old_tree)
+print('new tree:', new_tree)
   if old_tree == new_tree:
 if opts.verbose >= 0:
-  print 'clang-format did not modify any files'
+  print('clang-format did not modify any files')
   elif opts.diff:
 print_diff(old_tree, new_tree)
   else:
 changed_files = apply_changes(old_tree, new_tree, force=opts.force,
   patch_mode=opts.patch)
 if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
-  print 'changed files:'
+  print('changed files:')
   for filename in changed_files:
-print '   ', filename
+print('   ', filename)
 
 
 def load_git_config(non_string_options=None):
@@ -323,7 +325,7 @@
 
   Returns the object ID (SHA-1) of the created tree."""
   def index_info_generator():
-for filename, line_ranges in changed_lines.iteritems():
+for filename, line_ranges in changed_lines.items():
   mode = oct(os.stat(filename).st_mode)
   blob_id = clang_format_to_blob(filename, line_ranges, binary=binary,
  style=style)
@@ -431,10 +433,10 @@
   if not force:
 unstaged_files = run('git', 'diff-files', '--name-status', *changed_files)
 if unstaged_files:
-  print >>sys.stderr, ('The following files would be modified but '
-   'have unstaged changes:')
-  print >>sys.stderr, unstaged_files
-  print >>sys.stderr, 'Please commit, stage, or stash them first.'
+  print(('The following files would be modified but '
+   'have unstaged changes:'), file=sys.stderr)
+  print(unstaged_files, file=sys.stderr)
+  print('Please commit, stage, or stash them first.', file=sys.stderr)
   sys.exit(2)
   if patch_mode:
 # In patch mode, we could just as well create an index from the new tree
@@ -464,20 +466,20 @@
   if p.returncode == 0:
 if stderr:
   if verbose:
-print >>sys.stderr, '`%s` printed to stderr:' % ' '.join(args)
-  print >>sys.stderr, stderr.rstrip()
+print('`%s` printed to stderr:' % ' '.join(args), file=sys.stderr)
+  print(stderr.rstrip(), file=sys.stderr)
 if strip:
   stdout = stdout.rstrip('\r\n')
 return stdout
   if verbose:
-print >>sys.stderr, '`%s` returned %s' % (' '.join(args), p.returncode)
+print('`%s` returned %s' % (' '.join(args), p.returncode), file=sys.stderr)
   if stderr:
-print >>sys.stderr, stderr.rstrip()
+print(stderr.rstrip(), file=sys.stderr)
   sys.exit(2)
 
 
 def die(message):
-  print >>sys.stderr, 'error:', message
+  print('error:', message, file=sys.stderr)
   sys.exit(2)
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r279024 - PR28438: Update the information on an identifier with local definitions before

2016-08-18 Thread Vassil Vassilev via cfe-commits

On 18/08/16 03:16, Richard Smith via cfe-commits wrote:

Author: rsmith
Date: Wed Aug 17 20:16:55 2016
New Revision: 279024

URL: http://llvm.org/viewvc/llvm-project?rev=279024&view=rev
Log:
PR28438: Update the information on an identifier with local definitions before
trying to write out its macro graph, in case we imported a module that added
another module macro between the most recent local definition and the end of
the module.

Added:
 cfe/trunk/test/Modules/Inputs/PR28438/
 cfe/trunk/test/Modules/Inputs/PR28438/a.h
 cfe/trunk/test/Modules/Inputs/PR28438/b1.h
 cfe/trunk/test/Modules/Inputs/PR28438/b2.h
 cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap
 cfe/trunk/test/Modules/pr28438.cpp
Modified:
 cfe/trunk/include/clang/Lex/Preprocessor.h
 cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=279024&r1=279023&r2=279024&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Aug 17 20:16:55 2016
@@ -398,6 +398,8 @@ class Preprocessor : public RefCountedBa
  
  ModuleMacroInfo *getModuleInfo(Preprocessor &PP,

 const IdentifierInfo *II) const {
+  if (II->isOutOfDate())
+PP.updateOutOfDateIdentifier(const_cast(*II));
// FIXME: Find a spare bit on IdentifierInfo and store a
//HasModuleMacros flag.
if (!II->hasMacroDefinition() ||
@@ -653,6 +655,8 @@ class Preprocessor : public RefCountedBa
};
DeserializedMacroInfoChain *DeserialMIChainHead;
  
+  void updateOutOfDateIdentifier(IdentifierInfo &II) const;

+
  public:
Preprocessor(IntrusiveRefCntPtr PPOpts,
 DiagnosticsEngine &diags, LangOptions &opts,
@@ -900,6 +904,8 @@ public:
  
/// \brief Get the list of leaf (non-overridden) module macros for a name.

ArrayRef getLeafModuleMacros(const IdentifierInfo *II) const {
+if (II->isOutOfDate())
+  updateOutOfDateIdentifier(const_cast(*II));
  auto I = LeafModuleMacros.find(II);
  if (I != LeafModuleMacros.end())
return I->second;

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=279024&r1=279023&r2=279024&view=diff
==
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Aug 17 20:16:55 2016
@@ -618,6 +618,11 @@ static diag::kind getFutureCompatDiagKin
"Keyword not known to come from a newer Standard or proposed Standard");
  }
  
+void Preprocessor::updateOutOfDateIdentifier(IdentifierInfo &II) const {

+  assert(II.isOutOfDate() && "not out of date");
+  getExternalSource()->updateOutOfDateIdentifier(II);
+}
+
  /// HandleIdentifier - This callback is invoked when the lexer reads an
  /// identifier.  This callback looks up the identifier in the map and/or
  /// potentially macro expands it or turns it into a named token (like 'for').
@@ -642,7 +647,7 @@ bool Preprocessor::HandleIdentifier(Toke
  if (&II == Ident__VA_ARGS__)
CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
  
-ExternalSource->updateOutOfDateIdentifier(II);

+updateOutOfDateIdentifier(II);
  Identifier.setKind(II.getTokenID());
  
  if (&II == Ident__VA_ARGS__)


Added: cfe/trunk/test/Modules/Inputs/PR28438/a.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28438/a.h?rev=279024&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR28438/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR28438/a.h Wed Aug 17 20:16:55 2016
@@ -0,0 +1 @@
+#define FOO

Added: cfe/trunk/test/Modules/Inputs/PR28438/b1.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28438/b1.h?rev=279024&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR28438/b1.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR28438/b1.h Wed Aug 17 20:16:55 2016
@@ -0,0 +1,2 @@
+#define FOO
+#include "a.h"

Added: cfe/trunk/test/Modules/Inputs/PR28438/b2.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28438/b2.h?rev=279024&view=auto
==
 (empty)

Added: cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap?rev=279024&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap Wed Aug 1

r279037 - [analyzer] Small cleanups when checkers retrieving statements from exploded

2016-08-18 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Thu Aug 18 02:54:50 2016
New Revision: 279037

URL: http://llvm.org/viewvc/llvm-project?rev=279037&view=rev
Log:
[analyzer] Small cleanups when checkers retrieving statements from exploded
nodes.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp?rev=279037&r1=279036&r2=279037&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp Thu Aug 18 
02:54:50 2016
@@ -107,12 +107,7 @@ PathDiagnosticPiece *DynamicTypeChecker:
 return nullptr;
 
   // Retrieve the associated statement.
-  const Stmt *S = nullptr;
-  ProgramPoint ProgLoc = N->getLocation();
-  if (Optional SP = ProgLoc.getAs()) {
-S = SP->getStmt();
-  }
-
+  const Stmt *S = PathDiagnosticLocation::getStmt(N);
   if (!S)
 return nullptr;
 

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp?rev=279037&r1=279036&r2=279037&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp Thu Aug 18 
02:54:50 2016
@@ -909,12 +909,7 @@ PathDiagnosticPiece *DynamicTypePropagat
 return nullptr;
 
   // Retrieve the associated statement.
-  const Stmt *S = nullptr;
-  ProgramPoint ProgLoc = N->getLocation();
-  if (Optional SP = ProgLoc.getAs()) {
-S = SP->getStmt();
-  }
-
+  const Stmt *S = PathDiagnosticLocation::getStmt(N);
   if (!S)
 return nullptr;
 

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp?rev=279037&r1=279036&r2=279037&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp Thu Aug 
18 02:54:50 2016
@@ -524,12 +524,7 @@ MacOSKeychainAPIChecker::generateAllocat
   // allocated, and only report a single path.
   PathDiagnosticLocation LocUsedForUniqueing;
   const ExplodedNode *AllocNode = getAllocationNode(N, AP.first, C);
-  const Stmt *AllocStmt = nullptr;
-  ProgramPoint P = AllocNode->getLocation();
-  if (Optional Exit = P.getAs())
-AllocStmt = Exit->getCalleeContext()->getCallSite();
-  else if (Optional PS = P.getAs())
-AllocStmt = PS->getStmt();
+  const Stmt *AllocStmt = PathDiagnosticLocation::getStmt(AllocNode);
 
   if (AllocStmt)
 LocUsedForUniqueing = PathDiagnosticLocation::createBegin(AllocStmt,

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=279037&r1=279036&r2=279037&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Thu Aug 18 02:54:50 
2016
@@ -2094,12 +2094,7 @@ void MallocChecker::reportLeak(SymbolRef
   const MemRegion *Region = nullptr;
   std::tie(AllocNode, Region) = getAllocationSite(N, Sym, C);
 
-  ProgramPoint P = AllocNode->getLocation();
-  const Stmt *AllocationStmt = nullptr;
-  if (Optional Exit = P.getAs())
-AllocationStmt = Exit->getCalleeContext()->getCallSite();
-  else if (Optional SP = P.getAs())
-AllocationStmt = SP->getStmt();
+  const Stmt *AllocationStmt = PathDiagnosticLocation::getStmt(AllocNode);
   if (AllocationStmt)
 LocUsedForUniqueing = PathDiagnosticLocation::createBegin(AllocationStmt,
   C.getSourceManager(),
@@ -2626,22 +2621,7 @@ MallocChecker::MallocBugVisitor::VisitNo
   if (!RS)
 return nullptr;
 
-  const Stmt *S = nullptr;
-  const char *Msg = nullptr;
-  StackHintGeneratorForSymbol *StackHint = nullptr;
-
-  // Retrieve the associated statement.
-  ProgramPoint ProgLoc = N->getLocation();
-  if (Optional SP = ProgLoc.getAs()) {
-S = SP->getStmt();
-  } else if (Optional Exit = ProgLoc.getAs()) {
-S = Exit->getCalleeC

Re: [PATCH] D23550: [analyzer] Small cleanups when checkers retrieving statements from exploded nodes.

2016-08-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279037: [analyzer] Small cleanups when checkers retrieving 
statements from exploded (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D23550?vs=68166&id=68492#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23550

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -325,10 +325,7 @@
   // Retrieve the associated statement.
   const Stmt *S = TrackedNullab->getNullabilitySource();
   if (!S) {
-ProgramPoint ProgLoc = N->getLocation();
-if (Optional SP = ProgLoc.getAs()) {
-  S = SP->getStmt();
-}
+S = PathDiagnosticLocation::getStmt(N);
   }
 
   if (!S)
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2094,12 +2094,7 @@
   const MemRegion *Region = nullptr;
   std::tie(AllocNode, Region) = getAllocationSite(N, Sym, C);
 
-  ProgramPoint P = AllocNode->getLocation();
-  const Stmt *AllocationStmt = nullptr;
-  if (Optional Exit = P.getAs())
-AllocationStmt = Exit->getCalleeContext()->getCallSite();
-  else if (Optional SP = P.getAs())
-AllocationStmt = SP->getStmt();
+  const Stmt *AllocationStmt = PathDiagnosticLocation::getStmt(AllocNode);
   if (AllocationStmt)
 LocUsedForUniqueing = PathDiagnosticLocation::createBegin(AllocationStmt,
   C.getSourceManager(),
@@ -2626,29 +2621,16 @@
   if (!RS)
 return nullptr;
 
-  const Stmt *S = nullptr;
-  const char *Msg = nullptr;
-  StackHintGeneratorForSymbol *StackHint = nullptr;
-
-  // Retrieve the associated statement.
-  ProgramPoint ProgLoc = N->getLocation();
-  if (Optional SP = ProgLoc.getAs()) {
-S = SP->getStmt();
-  } else if (Optional Exit = ProgLoc.getAs()) {
-S = Exit->getCalleeContext()->getCallSite();
-  } else if (Optional Edge = ProgLoc.getAs()) {
-// If an assumption was made on a branch, it should be caught
-// here by looking at the state transition.
-S = Edge->getSrc()->getTerminator();
-  }
-
+  const Stmt *S = PathDiagnosticLocation::getStmt(N);
   if (!S)
 return nullptr;
 
   // FIXME: We will eventually need to handle non-statement-based events
   // (__attribute__((cleanup))).
 
   // Find out if this is an interesting point and what is the kind.
+  const char *Msg = nullptr;
+  StackHintGeneratorForSymbol *StackHint = nullptr;
   if (Mode == Normal) {
 if (isAllocated(RS, RSPrev, S)) {
   Msg = "Memory is allocated";
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
@@ -909,12 +909,7 @@
 return nullptr;
 
   // Retrieve the associated statement.
-  const Stmt *S = nullptr;
-  ProgramPoint ProgLoc = N->getLocation();
-  if (Optional SP = ProgLoc.getAs()) {
-S = SP->getStmt();
-  }
-
+  const Stmt *S = PathDiagnosticLocation::getStmt(N);
   if (!S)
 return nullptr;
 
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypeChecker.cpp
@@ -107,12 +107,7 @@
 return nullptr;
 
   // Retrieve the associated statement.
-  const Stmt *S = nullptr;
-  ProgramPoint ProgLoc = N->getLocation();
-  if (Optional SP = ProgLoc.getAs()) {
-S = SP->getStmt();
-  }
-
+  const Stmt *S = PathDiagnosticLocation::getStmt(N);
   if (!S)
 return nullptr;
 
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -2418,12 +2418,7 @@
   // FIXME: This will crash the analyzer if an allocation comes from an
   // implicit call (ex: a destructor call).
   // (Currently there are no such allocations in Cocoa, though.)
-  const Stmt *AllocStmt = nullptr;
-  ProgramPoint P = AllocNode->get

r279041 - [analyzer] Added valist related checkers.

2016-08-18 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Thu Aug 18 03:43:26 2016
New Revision: 279041

URL: http://llvm.org/viewvc/llvm-project?rev=279041&view=rev
Log:
[analyzer] Added valist related checkers.

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-valist.h
cfe/trunk/test/Analysis/valist-uninitialized.c
cfe/trunk/test/Analysis/valist-unterminated.c
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=279041&r1=279040&r2=279041&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Thu Aug 18 
03:43:26 2016
@@ -43,6 +43,9 @@ def Nullability : Package<"nullability">
 def Cplusplus : Package<"cplusplus">;
 def CplusplusAlpha : Package<"cplusplus">, InPackage, Hidden;
 
+def Valist : Package<"valist">;
+def ValistAlpha : Package<"valist">, InPackage, Hidden;
+
 def DeadCode : Package<"deadcode">;
 def DeadCodeAlpha : Package<"deadcode">, InPackage, Hidden;
 
@@ -267,6 +270,27 @@ def VirtualCallChecker : Checker<"Virtua
 
 } // end: "alpha.cplusplus"
 
+
+//===--===//
+// Valist checkers.
+//===--===//
+
+let ParentPackage = ValistAlpha in {
+
+def UninitializedChecker : Checker<"Uninitialized">,
+  HelpText<"Check for usages of uninitialized (or already released) 
va_lists.">,
+  DescFile<"ValistChecker.cpp">;
+
+def UnterminatedChecker : Checker<"Unterminated">,
+  HelpText<"Check for va_lists which are not released by a va_end call.">,
+  DescFile<"ValistChecker.cpp">;
+
+def CopyToSelfChecker : Checker<"CopyToSelf">,
+  HelpText<"Check for va_lists which are copied onto itself.">,
+  DescFile<"ValistChecker.cpp">;
+
+} // end : "alpha.valist"
+
 
//===--===//
 // Deadcode checkers.
 
//===--===//

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=279041&r1=279040&r2=279041&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Thu Aug 18 03:43:26 
2016
@@ -81,6 +81,7 @@ add_clang_library(clangStaticAnalyzerChe
   UnreachableCodeChecker.cpp
   VforkChecker.cpp
   VLASizeChecker.cpp
+  ValistChecker.cpp
   VirtualCallChecker.cpp
 
   DEPENDS

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp?rev=279041&view=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp (added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp Thu Aug 18 03:43:26 
2016
@@ -0,0 +1,373 @@
+//== ValistChecker.cpp - stdarg.h macro usage checker ---*- C++ 
-*--==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This defines checkers which detect usage of uninitialized va_list values
+// and va_start calls with no matching va_end.
+//
+//===--===//
+
+#include "ClangSACheckers.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/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+
+using namespace clang;
+using namespace ento;
+
+REGISTER_SET_WITH_PROGRAMSTATE(InitializedVALists, const MemRegion *)
+
+namespace {
+typedef SmallVector RegionVector;
+
+class ValistChecker : public Checker,
+ check::DeadSymbols> {
+  mutable std::unique_ptr BT_leakedvalist, BT_uninitaccess;
+
+  struct VAListAccepter {
+CallDescription Func;
+int VAListPos;
+  };
+  static const SmallVector VAListAccepters;
+  static const CallDescription VaStart, VaEnd, VaCopy;
+
+public:
+  enum CheckKind {
+CK_Uninitialized,
+CK_Unterminated,
+CK_CopyTo

Re: [PATCH] D15227: [analyzer] Valist checkers.

2016-08-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279041: [analyzer] Added valist related checkers. (authored 
by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D15227?vs=68157&id=68497#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D15227

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
  cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
  cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-valist.h
  cfe/trunk/test/Analysis/valist-uninitialized.c
  cfe/trunk/test/Analysis/valist-unterminated.c

Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -43,6 +43,9 @@
 def Cplusplus : Package<"cplusplus">;
 def CplusplusAlpha : Package<"cplusplus">, InPackage, Hidden;
 
+def Valist : Package<"valist">;
+def ValistAlpha : Package<"valist">, InPackage, Hidden;
+
 def DeadCode : Package<"deadcode">;
 def DeadCodeAlpha : Package<"deadcode">, InPackage, Hidden;
 
@@ -267,6 +270,27 @@
 
 } // end: "alpha.cplusplus"
 
+
+//===--===//
+// Valist checkers.
+//===--===//
+
+let ParentPackage = ValistAlpha in {
+
+def UninitializedChecker : Checker<"Uninitialized">,
+  HelpText<"Check for usages of uninitialized (or already released) va_lists.">,
+  DescFile<"ValistChecker.cpp">;
+
+def UnterminatedChecker : Checker<"Unterminated">,
+  HelpText<"Check for va_lists which are not released by a va_end call.">,
+  DescFile<"ValistChecker.cpp">;
+
+def CopyToSelfChecker : Checker<"CopyToSelf">,
+  HelpText<"Check for va_lists which are copied onto itself.">,
+  DescFile<"ValistChecker.cpp">;
+
+} // end : "alpha.valist"
+
 //===--===//
 // Deadcode checkers.
 //===--===//
Index: cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-valist.h
===
--- cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-valist.h
+++ cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-valist.h
@@ -0,0 +1,30 @@
+// Like the compiler, the static analyzer treats some functions differently if
+// they come from a system header -- for example, it is assumed that system
+// functions do not arbitrarily free() their parameters, and that some bugs
+// found in system headers cannot be fixed by the user and should be
+// suppressed.
+
+#pragma clang system_header
+
+#ifdef __cplusplus
+#define restrict /*restrict*/
+#endif
+
+typedef __builtin_va_list va_list;
+
+#define va_start(ap, param) __builtin_va_start(ap, param)
+#define va_end(ap)  __builtin_va_end(ap)
+#define va_arg(ap, type)__builtin_va_arg(ap, type)
+#define va_copy(dst, src)   __builtin_va_copy(dst, src)
+
+int vprintf (const char *restrict format, va_list arg);
+
+int vsprintf (char *restrict s, const char *restrict format, va_list arg);
+
+int some_library_function(int n, va_list arg);
+
+// No warning from system header.
+inline void __impl_detail(int fst, ...) {
+  va_list va;
+  (void)va_arg(va, int);
+}
Index: cfe/trunk/test/Analysis/valist-uninitialized.c
===
--- cfe/trunk/test/Analysis/valist-uninitialized.c
+++ cfe/trunk/test/Analysis/valist-uninitialized.c
@@ -0,0 +1,178 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.valist.Uninitialized,alpha.valist.CopyToSelf -analyzer-output=text -analyzer-store=region -verify %s
+
+#include "Inputs/system-header-simulator-for-valist.h"
+
+void f1(int fst, ...) {
+  va_list va;
+  (void)va_arg(va, int); //expected-warning{{va_arg() is called on an uninitialized va_list}} expected-note{{va_arg() is called on an uninitialized va_list}}
+}
+
+int f2(int fst, ...) {
+  va_list va;
+  va_start(va, fst); // expected-note{{Initialized va_list}}
+  va_end(va); // expected-note{{Ended va_list}}
+  return va_arg(va, int); //expected-warning{{va_arg() is called on an uninitialized va_list}} expected-note{{va_arg() is called on an uninitialized va_list}}
+}
+
+void f3(int fst, ...) {
+  va_list va, va2;
+  va_start(va, fst);
+  va_copy(va2, va);
+  va_end(va);
+  (void)va_arg(va2, int);
+  va_end(va2);
+} //no-warning
+
+void f4(int cond, ...) {
+  va_list va;
+  if (cond) { // expected-note{{Assuming 'cond' is 0}} expected-note{{Taking false branch}}
+va_start(va, cond);
+(void)va_arg(va,int);
+  }
+  va_end(va); //expected-warning{{va_end() is called on an uninitialized va_list}} expected-note{{va_end() is called on an uninitialized va_list}}
+}
+
+void f

r279042 - test commit

2016-08-18 Thread Guy Blank via cfe-commits
Author: guyblank
Date: Thu Aug 18 03:44:33 2016
New Revision: 279042

URL: http://llvm.org/viewvc/llvm-project?rev=279042&view=rev
Log:
test commit

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

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=279042&r1=279041&r2=279042&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Aug 18 03:44:33 2016
@@ -806,7 +806,7 @@ public:
 this->SizeType = TargetInfo::UnsignedInt;
 this->PtrDiffType = TargetInfo::SignedInt;
 this->IntPtrType = TargetInfo::SignedInt;
-// RegParmMax is inherited from the underlying architecture
+// RegParmMax is inherited from the underlying architecture.
 this->LongDoubleFormat = &llvm::APFloat::IEEEdouble;
 if (Triple.getArch() == llvm::Triple::arm) {
   // Handled in ARM's setABI().


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


Re: [PATCH] D21959: [X86] Add xgetbv xsetbv intrinsics

2016-08-18 Thread Guy Blank via cfe-commits
guyblank added a comment.

Still, __XSAVE__ should have been defined when compiling for a target that 
supports the feature.

But anyway, the xsaveintrin.h is quite small so always including it shouldn't 
be an issue.
Are you ok with me removing the #if just for this header file, or would you 
like to wait for Nico?


Repository:
  rL LLVM

https://reviews.llvm.org/D21959



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


r279043 - revert [analyzer] Added valist related checkers.

2016-08-18 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Thu Aug 18 04:13:37 2016
New Revision: 279043

URL: http://llvm.org/viewvc/llvm-project?rev=279043&view=rev
Log:
revert [analyzer] Added valist related checkers.

Removed:
cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-valist.h
cfe/trunk/test/Analysis/valist-uninitialized.c
cfe/trunk/test/Analysis/valist-unterminated.c
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=279043&r1=279042&r2=279043&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Thu Aug 18 
04:13:37 2016
@@ -43,9 +43,6 @@ def Nullability : Package<"nullability">
 def Cplusplus : Package<"cplusplus">;
 def CplusplusAlpha : Package<"cplusplus">, InPackage, Hidden;
 
-def Valist : Package<"valist">;
-def ValistAlpha : Package<"valist">, InPackage, Hidden;
-
 def DeadCode : Package<"deadcode">;
 def DeadCodeAlpha : Package<"deadcode">, InPackage, Hidden;
 
@@ -270,27 +267,6 @@ def VirtualCallChecker : Checker<"Virtua
 
 } // end: "alpha.cplusplus"
 
-
-//===--===//
-// Valist checkers.
-//===--===//
-
-let ParentPackage = ValistAlpha in {
-
-def UninitializedChecker : Checker<"Uninitialized">,
-  HelpText<"Check for usages of uninitialized (or already released) 
va_lists.">,
-  DescFile<"ValistChecker.cpp">;
-
-def UnterminatedChecker : Checker<"Unterminated">,
-  HelpText<"Check for va_lists which are not released by a va_end call.">,
-  DescFile<"ValistChecker.cpp">;
-
-def CopyToSelfChecker : Checker<"CopyToSelf">,
-  HelpText<"Check for va_lists which are copied onto itself.">,
-  DescFile<"ValistChecker.cpp">;
-
-} // end : "alpha.valist"
-
 
//===--===//
 // Deadcode checkers.
 
//===--===//

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=279043&r1=279042&r2=279043&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Thu Aug 18 04:13:37 
2016
@@ -81,7 +81,6 @@ add_clang_library(clangStaticAnalyzerChe
   UnreachableCodeChecker.cpp
   VforkChecker.cpp
   VLASizeChecker.cpp
-  ValistChecker.cpp
   VirtualCallChecker.cpp
 
   DEPENDS

Removed: cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp?rev=279042&view=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp (removed)
@@ -1,373 +0,0 @@
-//== ValistChecker.cpp - stdarg.h macro usage checker ---*- C++ 
-*--==//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-//
-// This defines checkers which detect usage of uninitialized va_list values
-// and va_start calls with no matching va_end.
-//
-//===--===//
-
-#include "ClangSACheckers.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/CallEvent.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-
-using namespace clang;
-using namespace ento;
-
-REGISTER_SET_WITH_PROGRAMSTATE(InitializedVALists, const MemRegion *)
-
-namespace {
-typedef SmallVector RegionVector;
-
-class ValistChecker : public Checker,
- check::DeadSymbols> {
-  mutable std::unique_ptr BT_leakedvalist, BT_uninitaccess;
-
-  struct VAListAccepter {
-CallDescription Func;
-int VAListPos;
-  };
-  static const SmallVector VAListAccepters;
-  static const CallDescription VaStart, VaEnd, VaCopy;
-
-public:
-  enum CheckKind {
-CK_Uninitialized,
-CK_Unterminated,
-CK_CopyToSelf,
-CK_NumCheckKinds
-  };
-
-  DefaultBool ChecksE

Re: [PATCH] D23314: [analyzer] CloneDetector allows comparing clones for suspicious variable pattern errors.

2016-08-18 Thread Vassil Vassilev via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D23314



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


Re: [PATCH] D23528: [OpenMP] Sema and parsing for 'teams distribute simd' pragma

2016-08-18 Thread Diana Picus via cfe-commits
Hi,

I had to revert this (r279045) because it breaks some of our buildbots (e.g.
clang-cmake-aarch64-quick, clang-x86_64-linux-selfhost-modules).

The error is in OpenMP/teams_distribute_simd_ast_print.cpp:
clang:
/home/buildslave/buildslave/clang-cmake-aarch64-quick/llvm/include/llvm/ADT/DenseMap.h:527:
bool llvm::DenseMapBase::LookupBucketFor(const LookupKeyT&, const BucketT*&) const
[with LookupKeyT = clang::Stmt*; DerivedT = llvm::DenseMap;
KeyT = clang::Stmt*; ValueT = long unsigned int;
KeyInfoT = llvm::DenseMapInfo;
BucketT = llvm::detail::DenseMapPair]:

Assertion `!KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val,
TombstoneKey) &&
"Empty/Tombstone value shouldn't be inserted into map!"' failed.

On 18 August 2016 at 02:21, Phabricator via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> This revision was automatically updated to reflect the committed changes.
> Closed by commit rL279003: [OpenMP] Sema and parsing for 'teams distribute
> simd’ pragma (authored by kli).
>
> Changed prior to commit:
>   https://reviews.llvm.org/D23528?vs=68216&id=68448#toc
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D23528
>
> Files:
>   cfe/trunk/include/clang-c/Index.h
>   cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
>   cfe/trunk/include/clang/AST/StmtOpenMP.h
>   cfe/trunk/include/clang/Basic/OpenMPKinds.def
>   cfe/trunk/include/clang/Basic/StmtNodes.td
>   cfe/trunk/include/clang/Sema/Sema.h
>   cfe/trunk/include/clang/Serialization/ASTBitCodes.h
>   cfe/trunk/lib/AST/StmtOpenMP.cpp
>   cfe/trunk/lib/AST/StmtPrinter.cpp
>   cfe/trunk/lib/AST/StmtProfile.cpp
>   cfe/trunk/lib/Basic/OpenMPKinds.cpp
>   cfe/trunk/lib/CodeGen/CGStmt.cpp
>   cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
>   cfe/trunk/lib/CodeGen/CodeGenFunction.h
>   cfe/trunk/lib/Parse/ParseOpenMP.cpp
>   cfe/trunk/lib/Sema/SemaOpenMP.cpp
>   cfe/trunk/lib/Sema/TreeTransform.h
>   cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
>   cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
>   cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
>   cfe/trunk/test/OpenMP/nesting_of_regions.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_aligned_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_ast_print.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_collapse_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_default_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_dist_schedule_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_firstprivate_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_lastprivate_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_linear_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_loop_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_num_teams_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_private_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_reduction_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_safelen_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_shared_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_simdlen_messages.cpp
>   cfe/trunk/test/OpenMP/teams_distribute_simd_thread_limit_messages.cpp
>   cfe/trunk/tools/libclang/CIndex.cpp
>   cfe/trunk/tools/libclang/CXCursor.cpp
>
>
> ___
> 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


[PATCH] D23651: [clang-rename] improve performance for rename-all

2016-08-18 Thread Kirill Bobyrev via cfe-commits
omtcyfz created this revision.
omtcyfz added reviewers: alexfh, vmiklos.
omtcyfz added a subscriber: cfe-commits.

As Miklos Vajna [[ 
http://lists.llvm.org/pipermail/cfe-dev/2016-August/050398.html | noticed ]] 
`clang-rename rename-all` has significant performance problems, which exposed 
the fact that clang-rename parses translation unit **N** times where **N** 
stands for the number of `{offset | old-name} -> new-name` pairs.

This patch prevents clang-rename from parsing translation unit multiple times.

https://reviews.llvm.org/D23651

Files:
  clang-rename/USRFindingAction.cpp
  clang-rename/USRFindingAction.h
  clang-rename/tool/ClangRename.cpp

Index: clang-rename/tool/ClangRename.cpp
===
--- clang-rename/tool/ClangRename.cpp
+++ clang-rename/tool/ClangRename.cpp
@@ -175,11 +175,11 @@
   }
 
   // Check if NewNames is a valid identifier in C++17.
+  LangOptions Options;
+  Options.CPlusPlus = true;
+  Options.CPlusPlus1z = true;
+  IdentifierTable Table(Options);
   for (const auto &NewName : NewNames) {
-LangOptions Options;
-Options.CPlusPlus = true;
-Options.CPlusPlus1z = true;
-IdentifierTable Table(Options);
 auto NewNameTokKind = Table.get(NewName).getTokenID();
 if (!tok::isAnyIdentifier(NewNameTokKind)) {
   errs() << "ERROR: new name is not a valid identifier in C++17.\n\n";
@@ -203,32 +203,28 @@
 exit(1);
   }
 
-  std::vector> USRList;
-  std::vector PrevNames;
   auto Files = OP.getSourcePathList();
   tooling::RefactoringTool Tool(OP.getCompilations(), Files);
+
   unsigned Count = OldNames.size() ? OldNames.size() : SymbolOffsets.size();
+  std::vector SymbolOffsetsVector(Count, 0);
+  std::vector OldNamesVector(Count, "");
   for (unsigned I = 0; I < Count; ++I) {
-unsigned SymbolOffset = SymbolOffsets.empty() ? 0 : SymbolOffsets[I];
-const std::string &OldName = OldNames.empty() ? std::string() : OldNames[I];
-
-// Get the USRs.
-rename::USRFindingAction USRAction(SymbolOffset, OldName);
-
-// Find the USRs.
-Tool.run(tooling::newFrontendActionFactory(&USRAction).get());
-const auto &USRs = USRAction.getUSRs();
-USRList.push_back(USRs);
-const auto &PrevName = USRAction.getUSRSpelling();
-PrevNames.push_back(PrevName);
-
-if (PrevName.empty()) {
-  // An error should have already been printed.
-  exit(1);
+if (!SymbolOffsets.empty()) {
+  SymbolOffsetsVector[I] = SymbolOffsets[I];
+}
+if (!OldNames.empty()) {
+  OldNamesVector[I] = OldNames[I];
 }
+  }
 
-if (PrintName) {
-  errs() << "clang-rename: found name: " << PrevName << '\n';
+  rename::USRFindingAction USRAction(SymbolOffsetsVector, OldNamesVector);
+  Tool.run(tooling::newFrontendActionFactory(&USRAction).get());
+  std::vector> USRList = USRAction.getUSRList();
+  std::vector PrevNames = USRAction.getUSRSpellings();
+  if (PrintName) {
+for (const auto &PrevName : PrevNames) {
+  outs() << "clang-rename found name: " << PrevName << '\n';
 }
   }
 
Index: clang-rename/USRFindingAction.h
===
--- clang-rename/USRFindingAction.h
+++ clang-rename/USRFindingAction.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDING_ACTION_H_
 
 #include "clang/Frontend/FrontendAction.h"
+#include 
 
 namespace clang {
 class ASTConsumer;
@@ -25,20 +26,19 @@
 namespace rename {
 
 struct USRFindingAction {
-  USRFindingAction(unsigned Offset, const std::string &Name)
-  : SymbolOffset(Offset), OldName(Name) {}
+  USRFindingAction(std::vector &SymbolOffsets,
+   std::vector &OldNames)
+  : SymbolOffsets(SymbolOffsets), OldNames(OldNames) {}
   std::unique_ptr newASTConsumer();
 
-  // \brief get the spelling of the USR(s) as it would appear in source files.
-  const std::string &getUSRSpelling() { return SpellingName; }
-
-  const std::vector &getUSRs() { return USRs; }
+  const std::vector &getUSRSpellings() { return SpellingNames; }
+  const std::vector> &getUSRList() { return USRList; }
 
 private:
-  unsigned SymbolOffset;
-  std::string OldName;
-  std::string SpellingName;
-  std::vector USRs;
+  std::vector SymbolOffsets;
+  std::vector OldNames;
+  std::vector SpellingNames;
+  std::vector> USRList;
 };
 
 } // namespace rename
Index: clang-rename/USRFindingAction.cpp
===
--- clang-rename/USRFindingAction.cpp
+++ clang-rename/USRFindingAction.cpp
@@ -45,11 +45,10 @@
 // to virtual method.
 class AdditionalUSRFinder : public RecursiveASTVisitor {
 public:
-  explicit AdditionalUSRFinder(const Decl *FoundDecl, ASTContext &Context,
-   std::vector *USRs)
-  : FoundDecl(FoundDecl), Context(Context), USRs(USRs) {}
+  explicit AdditionalUSRFinder(const Decl *FoundDecl, ASTContext &Context)
+  : FoundDecl(FoundDecl), Context(Context) {}
 
-  void 

Re: [PATCH] D23651: [clang-rename] improve performance for rename-all

2016-08-18 Thread Kirill Bobyrev via cfe-commits
omtcyfz updated this revision to Diff 68503.
omtcyfz added a comment.

Prevent unnecessary `std::vector` copying. Explicitly write type.


https://reviews.llvm.org/D23651

Files:
  clang-rename/USRFindingAction.cpp
  clang-rename/USRFindingAction.h
  clang-rename/tool/ClangRename.cpp

Index: clang-rename/tool/ClangRename.cpp
===
--- clang-rename/tool/ClangRename.cpp
+++ clang-rename/tool/ClangRename.cpp
@@ -175,11 +175,11 @@
   }
 
   // Check if NewNames is a valid identifier in C++17.
+  LangOptions Options;
+  Options.CPlusPlus = true;
+  Options.CPlusPlus1z = true;
+  IdentifierTable Table(Options);
   for (const auto &NewName : NewNames) {
-LangOptions Options;
-Options.CPlusPlus = true;
-Options.CPlusPlus1z = true;
-IdentifierTable Table(Options);
 auto NewNameTokKind = Table.get(NewName).getTokenID();
 if (!tok::isAnyIdentifier(NewNameTokKind)) {
   errs() << "ERROR: new name is not a valid identifier in C++17.\n\n";
@@ -203,39 +203,36 @@
 exit(1);
   }
 
-  std::vector> USRList;
-  std::vector PrevNames;
   auto Files = OP.getSourcePathList();
   tooling::RefactoringTool Tool(OP.getCompilations(), Files);
+
   unsigned Count = OldNames.size() ? OldNames.size() : SymbolOffsets.size();
+  std::vector SymbolOffsetsVector(Count, 0);
+  std::vector OldNamesVector(Count, "");
   for (unsigned I = 0; I < Count; ++I) {
-unsigned SymbolOffset = SymbolOffsets.empty() ? 0 : SymbolOffsets[I];
-const std::string &OldName = OldNames.empty() ? std::string() : OldNames[I];
-
-// Get the USRs.
-rename::USRFindingAction USRAction(SymbolOffset, OldName);
-
-// Find the USRs.
-Tool.run(tooling::newFrontendActionFactory(&USRAction).get());
-const auto &USRs = USRAction.getUSRs();
-USRList.push_back(USRs);
-const auto &PrevName = USRAction.getUSRSpelling();
-PrevNames.push_back(PrevName);
-
-if (PrevName.empty()) {
-  // An error should have already been printed.
-  exit(1);
+if (!SymbolOffsets.empty()) {
+  SymbolOffsetsVector[I] = SymbolOffsets[I];
+}
+if (!OldNames.empty()) {
+  OldNamesVector[I] = OldNames[I];
 }
+  }
 
-if (PrintName) {
-  errs() << "clang-rename: found name: " << PrevName << '\n';
+  rename::USRFindingAction USRAction(SymbolOffsetsVector, OldNamesVector);
+  Tool.run(tooling::newFrontendActionFactory(&USRAction).get());
+  const std::vector> &USRList = USRAction.getUSRList();
+  const std::vector &PrevNames = USRAction.getUSRSpellings();
+  if (PrintName) {
+for (const auto &PrevName : PrevNames) {
+  outs() << "clang-rename found name: " << PrevName << '\n';
 }
   }
 
   // Perform the renaming.
   rename::RenamingAction RenameAction(NewNames, PrevNames, USRList,
   Tool.getReplacements(), PrintLocations);
-  auto Factory = tooling::newFrontendActionFactory(&RenameAction);
+  std::unique_ptr Factory =
+  tooling::newFrontendActionFactory(&RenameAction);
   int ExitCode;
 
   if (Inplace) {
Index: clang-rename/USRFindingAction.h
===
--- clang-rename/USRFindingAction.h
+++ clang-rename/USRFindingAction.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDING_ACTION_H_
 
 #include "clang/Frontend/FrontendAction.h"
+#include 
 
 namespace clang {
 class ASTConsumer;
@@ -25,20 +26,19 @@
 namespace rename {
 
 struct USRFindingAction {
-  USRFindingAction(unsigned Offset, const std::string &Name)
-  : SymbolOffset(Offset), OldName(Name) {}
+  USRFindingAction(std::vector &SymbolOffsets,
+   std::vector &OldNames)
+  : SymbolOffsets(SymbolOffsets), OldNames(OldNames) {}
   std::unique_ptr newASTConsumer();
 
-  // \brief get the spelling of the USR(s) as it would appear in source files.
-  const std::string &getUSRSpelling() { return SpellingName; }
-
-  const std::vector &getUSRs() { return USRs; }
+  const std::vector &getUSRSpellings() { return SpellingNames; }
+  const std::vector> &getUSRList() { return USRList; }
 
 private:
-  unsigned SymbolOffset;
-  std::string OldName;
-  std::string SpellingName;
-  std::vector USRs;
+  std::vector SymbolOffsets;
+  std::vector OldNames;
+  std::vector SpellingNames;
+  std::vector> USRList;
 };
 
 } // namespace rename
Index: clang-rename/USRFindingAction.cpp
===
--- clang-rename/USRFindingAction.cpp
+++ clang-rename/USRFindingAction.cpp
@@ -45,11 +45,10 @@
 // to virtual method.
 class AdditionalUSRFinder : public RecursiveASTVisitor {
 public:
-  explicit AdditionalUSRFinder(const Decl *FoundDecl, ASTContext &Context,
-   std::vector *USRs)
-  : FoundDecl(FoundDecl), Context(Context), USRs(USRs) {}
+  explicit AdditionalUSRFinder(const Decl *FoundDecl, ASTContext &Context)
+  : FoundDecl(FoundDecl), Context(Context) {}
 
- 

Re: [PATCH] D23651: [clang-rename] improve performance for rename-all

2016-08-18 Thread Miklos Vajna via cfe-commits
vmiklos added a comment.

I can confirm that with this, the test script from the mail thread shows that 
clang-rename is almost as fast as clang++ as expected. Thanks!


https://reviews.llvm.org/D23651



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


Re: [PATCH] D15332: new clang-tidy checker readability-non-const-parameter

2016-08-18 Thread Daniel Marjamäki via cfe-commits
danielmarjamaki marked 6 inline comments as done.


Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:95-98
@@ +94,6 @@
+const QualType T = VD->getType();
+if (T->isPointerType() && !T->getPointeeType().isConstQualified())
+  markCanNotBeConst(VD->getInit(), true);
+else if (T->isArrayType())
+  markCanNotBeConst(VD->getInit(), true);
+  }

alexfh wrote:
> danielmarjamaki wrote:
> > Prazek wrote:
> > > This looks like it could be in the same if.
> > Yes it could. But would it make the code more or less readable? It wouldn't 
> > be a 1-line condition anymore then.
> I also think that it makes sense to merge the conditions. The problem with 
> the current code is that it is suspicious ("Why is the same action is done in 
> two branches? Is it a bug?"). One line condition vs two lines seems secondary 
> in this case.
ok


Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:103
@@ +102,3 @@
+void NonConstParameterCheck::addParm(const ParmVarDecl *Parm) {
+  // Only add nonconst integer/float pointer parameters.
+  const QualType T = Parm->getType();

alexfh wrote:
> This seems too strict. What about other primitive types? 
I am not sure which type you are talking about. As far as I see we're writing 
warnings about bool,char,short,int,long,long long,float,double,long double,enum 
pointers.

I have intentionally avoided records now to start with. It should be added, but 
we need to be more careful when we do it.



Comment at: test/clang-tidy/readability-non-const-parameter.cpp:210
@@ +209,3 @@
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+int functionpointer2(int *p)
+{

alexfh wrote:
> Put braces on the previous line, please. A few other instances below.
sorry .. of course I should run clang-format on this.


https://reviews.llvm.org/D15332



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


Re: [PATCH] D23651: [clang-rename] improve performance for rename-all

2016-08-18 Thread Alexander Shaposhnikov via cfe-commits
alexshap added a subscriber: alexshap.


Comment at: clang-rename/USRFindingAction.h:38
@@ -37,5 +37,3 @@
 private:
-  unsigned SymbolOffset;
-  std::string OldName;
-  std::string SpellingName;
-  std::vector USRs;
+  std::vector SymbolOffsets;
+  std::vector OldNames;

in the constructor SymbolOffsets, OldNames are passed by non-constant reference
but then you make a copy.  


https://reviews.llvm.org/D23651



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


Re: [PATCH] D15227: [analyzer] Valist checkers.

2016-08-18 Thread Gábor Horváth via cfe-commits
xazax.hun reopened this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

It looks like it broke some of the build bots.

Error from the windows build bots:

  error: 'note' diagnostics expected but not seen: 
File 
C:\Buildbot\Slave\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Analysis\valist-uninitialized.c
 Line 96: va_list 'va' is copied onto itself
File 
C:\Buildbot\Slave\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Analysis\valist-uninitialized.c
 Line 102: va_list 'va' is copied onto itself
File 
C:\Buildbot\Slave\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\tools\clang\test\Analysis\valist-uninitialized.c
 Line 108: Initialized va_list 'va' is overwritten by an uninitialized one
  error: 'note' diagnostics seen but not expected: 
Line 96: va_list va' is copied onto itself
Line 102: va_list va' is copied onto itself
Line 108: Initialized va_list va' is overwritten by an uninitialized one
  12 errors generated.

Somehow the beginning single quote is missing from the generated message. It is 
very strange.

Error from other architectures:

  error: 'warning' diagnostics expected but not seen: 
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 27: Initialized va_list is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 39: Initialized va_list is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 110: Initialized va_list 'va_array[3]' is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 125: Initialized va_list 'mem[0]' is leaked
  error: 'warning' diagnostics seen but not expected: 
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 33: Initialized va_list 'fst' is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 110: Initialized va_list 'va_array' is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 125: Initialized va_list 'mem' is leaked
  error: 'note' diagnostics expected but not seen: 
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 26: Initialized va_list
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 27: Initialized va_list is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 36: Initialized va_list
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 39: Initialized va_list is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 110: Initialized va_list 'va_array[3]' is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 125: Initialized va_list 'mem[0]' is leaked
  error: 'note' diagnostics seen but not expected: 
Line 31: Initialized va_list
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 33: Initialized va_list 'fst' is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 110: Initialized va_list 'va_array' is leaked
File 
/var/lib/buildbot/slaves/hexagon-build-03/clang-hexagon-elf/llvm/tools/clang/test/Analysis/valist-unterminated.c
 Line 125: Initialized va_list 'mem' is leaked
  17 errors generated.

I suspect that slightly different AST is generated for those architectures that 
cause the different behavior. I will further investigate those problems.


Repository:
  rL LLVM

https://reviews.llvm.org/D15227



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


[clang-tools-extra] r279049 - [clang-tidy docs] Fix build errors on Sphinx 1.4.5

2016-08-18 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Aug 18 06:06:09 2016
New Revision: 279049

URL: http://llvm.org/viewvc/llvm-project?rev=279049&view=rev
Log:
[clang-tidy docs] Fix build errors on Sphinx 1.4.5

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-throw-by-value-catch-by-reference.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-nullptr.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-buffer-deref.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-braces-around-statements.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-function-size.rst
clang-tools-extra/trunk/docs/clang-tidy/index.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.rst?rev=279049&r1=279048&r2=279049&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.rst
 Thu Aug 18 06:06:09 2016
@@ -8,7 +8,7 @@ This check flags all array subscript exp
 are out of bounds (for ``std::array``). For out-of-bounds checking of static
 arrays, see the clang-diagnostic-array-bounds check.
 
-The check can generate fixes after the option :option:`GslHeader` has been set
+The check can generate fixes after the option `GslHeader` has been set
 to the name of the include file that contains ``gsl::at()``, e.g. 
`"gsl/gsl.h"`.
 
 This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, 
see

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst?rev=279049&r1=279048&r2=279049&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst 
Thu Aug 18 06:06:09 2016
@@ -11,8 +11,12 @@ builds.
 
 There are two options:
 
-  - :option:`AssertMacros`: A comma-separated list of the names of assert 
macros
-to be checked.
-  - :option:`CheckFunctionCalls`: Whether to treat non-const member and
-non-member functions as they produce side effects. Disabled by default
-because it can increase the number of false positive warnings.
+.. option:: AssertMacros
+
+   A comma-separated list of the names of assert macros to be checked.
+
+.. option:: CheckFunctionCalls
+
+   Whether to treat non-const member and non-member functions as they produce
+   side effects. Disabled by default because it can increase the number of 
false
+   positive warnings.

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-throw-by-value-catch-by-reference.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-throw-by-value-catch-by-reference.rst?rev=279049&r1=279048&r2=279049&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-throw-by-value-catch-by-reference.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-throw-by-value-catch-by-reference.rst
 Thu Aug 18 06:06:09 2016
@@ -5,11 +5,29 @@ misc-throw-by-value-catch-by-reference
 
 "cert-err61-cpp" redirects here as an alias for this check.
 
-Finds violations of the rule "Throw by value, catch by reference" presented 
for example in "C++ Coding Standards" by H. Sutter and A. Alexandrescu. This 
check also has the option to find violations of the rule "Throw anonymous 
temporaries" 
(https://www.securecoding.cert.org/confluence/display/cplusplus/ERR09-CPP.+Throw+anonymous+temporaries).
 The option is named :option:`CheckThrowTemporaries` and it's on by default.
+Finds violations of the rule "Throw by value, catch by reference" presented for
+example in "C++ Coding Standards" by H. Sutter and A. Alexandrescu.
 
 Exceptions:
-  * Throwing string literals will not be flagged despite being a pointer. They 
are not susceptible to slicing and the usage of string literals is idomatic.
-  * Catching character pointers (``char``, ``wchar_t``, unicode character 
types) will not be flagged to allow catching sting literals.
-  * Moved named values will not be flagged as not throwing an anonymous 
temporary. In this case we can be sure that the user knows that the object 
can't be accessed outside catch blocks handling the 

[clang-tools-extra] r279050 - [clang-tidy docs] Fix formatting.

2016-08-18 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Aug 18 06:10:52 2016
New Revision: 279050

URL: http://llvm.org/viewvc/llvm-project?rev=279050&view=rev
Log:
[clang-tidy docs] Fix formatting.

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst?rev=279050&r1=279049&r2=279050&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst Thu 
Aug 18 06:10:52 2016
@@ -9,6 +9,7 @@ standard (3.1) are verified by this chec
 datatypes and null pointer constants are skipped, in the course of 
verification.
 
 Example:
+
 .. code:: c++
 
   // In this case, the buffer type matches MPI datatype.


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


[clang-tools-extra] r279051 - [clang-tidy docs] Minor fix

2016-08-18 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Aug 18 06:12:03 2016
New Revision: 279051

URL: http://llvm.org/viewvc/llvm-project?rev=279051&view=rev
Log:
[clang-tidy docs] Minor fix

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst?rev=279051&r1=279050&r2=279051&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/mpi-type-mismatch.rst Thu 
Aug 18 06:12:03 2016
@@ -10,7 +10,7 @@ datatypes and null pointer constants are
 
 Example:
 
-.. code:: c++
+.. code-block:: c++
 
   // In this case, the buffer type matches MPI datatype.
   char buf;


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


[PATCH] D23653: Minor cleanup of SimpleTypoCorrector

2016-08-18 Thread Alexander Shaposhnikov via cfe-commits
alexshap created this revision.
alexshap added reviewers: gribozavr, bkramer.
alexshap added a subscriber: cfe-commits.
alexshap changed the visibility of this Differential Revision from "Public (No 
Login Required)" to "All Users".

Add the "explicit" specifier to the single-argument constructor of 
SimpleTypoCorrector.
Reorder the fields to remove excessive padding (8 bytes).

https://reviews.llvm.org/D23653

Files:
  lib/AST/CommentSema.cpp

Index: lib/AST/CommentSema.cpp
===
--- lib/AST/CommentSema.cpp
+++ lib/AST/CommentSema.cpp
@@ -950,18 +950,18 @@
 
 namespace {
 class SimpleTypoCorrector {
+  const NamedDecl *BestDecl;
   StringRef Typo;
   const unsigned MaxEditDistance;
-
-  const NamedDecl *BestDecl;
   unsigned BestEditDistance;
   unsigned BestIndex;
   unsigned NextIndex;
 
 public:
-  SimpleTypoCorrector(StringRef Typo) :
-  Typo(Typo), MaxEditDistance((Typo.size() + 2) / 3),
-  BestDecl(nullptr), BestEditDistance(MaxEditDistance + 1),
+  explicit SimpleTypoCorrector(StringRef Typo) :
+  BestDecl(nullptr), Typo(Typo),
+  MaxEditDistance((Typo.size() + 2) / 3), 
+  BestEditDistance(MaxEditDistance + 1),
   BestIndex(0), NextIndex(0)
   { }
 


Index: lib/AST/CommentSema.cpp
===
--- lib/AST/CommentSema.cpp
+++ lib/AST/CommentSema.cpp
@@ -950,18 +950,18 @@
 
 namespace {
 class SimpleTypoCorrector {
+  const NamedDecl *BestDecl;
   StringRef Typo;
   const unsigned MaxEditDistance;
-
-  const NamedDecl *BestDecl;
   unsigned BestEditDistance;
   unsigned BestIndex;
   unsigned NextIndex;
 
 public:
-  SimpleTypoCorrector(StringRef Typo) :
-  Typo(Typo), MaxEditDistance((Typo.size() + 2) / 3),
-  BestDecl(nullptr), BestEditDistance(MaxEditDistance + 1),
+  explicit SimpleTypoCorrector(StringRef Typo) :
+  BestDecl(nullptr), Typo(Typo),
+  MaxEditDistance((Typo.size() + 2) / 3), 
+  BestEditDistance(MaxEditDistance + 1),
   BestIndex(0), NextIndex(0)
   { }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23653: Minor cleanup of SimpleTypoCorrector

2016-08-18 Thread Alexander Shaposhnikov via cfe-commits
alexshap added a comment.

F2283280: Screen Shot 2016-08-18 at 4.29.34 AM.png 



https://reviews.llvm.org/D23653



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


Re: [PATCH] D23492: Make function local tags visible.

2016-08-18 Thread Vassil Vassilev via cfe-commits
v.g.vassilev added inline comments.


Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:3600-3605
@@ -3598,2 +3599,8 @@
   // which definitions should be visible.
+  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Function,
+Function->getInstantiatedFromMemberFunction(),
+ PatternDecl,
+ const_cast(PatternDecl),
+ TSK, /*Complain*/DefinitionRequired))
+ return;
 

rsmith wrote:
> I think this should be checked before we deal with late-parsed templates -- 
> if the template definition isn't visible, an attempt to instantiate it 
> shouldn't trigger it being parsed.
If I am to sink the diags under the // TODO: this might change behavior. The 
diagnostics may not kick-in properly in case of late template parsing (see 
around line 3594).


https://reviews.llvm.org/D23492



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


Re: [PATCH] D23651: [clang-rename] improve performance for rename-all

2016-08-18 Thread Kirill Bobyrev via cfe-commits
omtcyfz marked an inline comment as done.


Comment at: clang-rename/USRFindingAction.h:38-41
@@ -37,6 +37,6 @@
 private:
-  unsigned SymbolOffset;
-  std::string OldName;
-  std::string SpellingName;
-  std::vector USRs;
+  const std::vector &SymbolOffsets;
+  const std::vector &OldNames;
+  std::vector SpellingNames;
+  std::vector> USRList;
 };

Aw, you're right. Good catch, thanks!


https://reviews.llvm.org/D23651



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


Re: [PATCH] D23651: [clang-rename] improve performance for rename-all

2016-08-18 Thread Kirill Bobyrev via cfe-commits
omtcyfz updated this revision to Diff 68511.
omtcyfz added a comment.

Prevent std::vector from redundant copying.


https://reviews.llvm.org/D23651

Files:
  clang-rename/USRFindingAction.cpp
  clang-rename/USRFindingAction.h
  clang-rename/tool/ClangRename.cpp

Index: clang-rename/tool/ClangRename.cpp
===
--- clang-rename/tool/ClangRename.cpp
+++ clang-rename/tool/ClangRename.cpp
@@ -175,11 +175,11 @@
   }
 
   // Check if NewNames is a valid identifier in C++17.
+  LangOptions Options;
+  Options.CPlusPlus = true;
+  Options.CPlusPlus1z = true;
+  IdentifierTable Table(Options);
   for (const auto &NewName : NewNames) {
-LangOptions Options;
-Options.CPlusPlus = true;
-Options.CPlusPlus1z = true;
-IdentifierTable Table(Options);
 auto NewNameTokKind = Table.get(NewName).getTokenID();
 if (!tok::isAnyIdentifier(NewNameTokKind)) {
   errs() << "ERROR: new name is not a valid identifier in C++17.\n\n";
@@ -203,39 +203,36 @@
 exit(1);
   }
 
-  std::vector> USRList;
-  std::vector PrevNames;
   auto Files = OP.getSourcePathList();
   tooling::RefactoringTool Tool(OP.getCompilations(), Files);
+
   unsigned Count = OldNames.size() ? OldNames.size() : SymbolOffsets.size();
+  std::vector SymbolOffsetsVector(Count, 0);
+  std::vector OldNamesVector(Count, "");
   for (unsigned I = 0; I < Count; ++I) {
-unsigned SymbolOffset = SymbolOffsets.empty() ? 0 : SymbolOffsets[I];
-const std::string &OldName = OldNames.empty() ? std::string() : OldNames[I];
-
-// Get the USRs.
-rename::USRFindingAction USRAction(SymbolOffset, OldName);
-
-// Find the USRs.
-Tool.run(tooling::newFrontendActionFactory(&USRAction).get());
-const auto &USRs = USRAction.getUSRs();
-USRList.push_back(USRs);
-const auto &PrevName = USRAction.getUSRSpelling();
-PrevNames.push_back(PrevName);
-
-if (PrevName.empty()) {
-  // An error should have already been printed.
-  exit(1);
+if (!SymbolOffsets.empty()) {
+  SymbolOffsetsVector[I] = SymbolOffsets[I];
+}
+if (!OldNames.empty()) {
+  OldNamesVector[I] = OldNames[I];
 }
+  }
 
-if (PrintName) {
-  errs() << "clang-rename: found name: " << PrevName << '\n';
+  rename::USRFindingAction USRAction(SymbolOffsetsVector, OldNamesVector);
+  Tool.run(tooling::newFrontendActionFactory(&USRAction).get());
+  const std::vector> &USRList = USRAction.getUSRList();
+  const std::vector &PrevNames = USRAction.getUSRSpellings();
+  if (PrintName) {
+for (const auto &PrevName : PrevNames) {
+  outs() << "clang-rename found name: " << PrevName << '\n';
 }
   }
 
   // Perform the renaming.
   rename::RenamingAction RenameAction(NewNames, PrevNames, USRList,
   Tool.getReplacements(), PrintLocations);
-  auto Factory = tooling::newFrontendActionFactory(&RenameAction);
+  std::unique_ptr Factory =
+  tooling::newFrontendActionFactory(&RenameAction);
   int ExitCode;
 
   if (Inplace) {
Index: clang-rename/USRFindingAction.h
===
--- clang-rename/USRFindingAction.h
+++ clang-rename/USRFindingAction.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDING_ACTION_H_
 
 #include "clang/Frontend/FrontendAction.h"
+#include 
 
 namespace clang {
 class ASTConsumer;
@@ -25,20 +26,19 @@
 namespace rename {
 
 struct USRFindingAction {
-  USRFindingAction(unsigned Offset, const std::string &Name)
-  : SymbolOffset(Offset), OldName(Name) {}
+  USRFindingAction(const std::vector &SymbolOffsets,
+   const std::vector &OldNames)
+  : SymbolOffsets(SymbolOffsets), OldNames(OldNames) {}
   std::unique_ptr newASTConsumer();
 
-  // \brief get the spelling of the USR(s) as it would appear in source files.
-  const std::string &getUSRSpelling() { return SpellingName; }
-
-  const std::vector &getUSRs() { return USRs; }
+  const std::vector &getUSRSpellings() { return SpellingNames; }
+  const std::vector> &getUSRList() { return USRList; }
 
 private:
-  unsigned SymbolOffset;
-  std::string OldName;
-  std::string SpellingName;
-  std::vector USRs;
+  const std::vector &SymbolOffsets;
+  const std::vector &OldNames;
+  std::vector SpellingNames;
+  std::vector> USRList;
 };
 
 } // namespace rename
Index: clang-rename/USRFindingAction.cpp
===
--- clang-rename/USRFindingAction.cpp
+++ clang-rename/USRFindingAction.cpp
@@ -45,11 +45,10 @@
 // to virtual method.
 class AdditionalUSRFinder : public RecursiveASTVisitor {
 public:
-  explicit AdditionalUSRFinder(const Decl *FoundDecl, ASTContext &Context,
-   std::vector *USRs)
-  : FoundDecl(FoundDecl), Context(Context), USRs(USRs) {}
+  explicit AdditionalUSRFinder(const Decl *FoundDecl, ASTContext &Context)
+  : FoundDecl(FoundDecl), Context(Context) {}

Re: [PATCH] D22910: Add support for CXXOperatorCallExpr in Expr::HasSideEffects

2016-08-18 Thread Andi via cfe-commits
Abpostelnicu marked 2 inline comments as done.


Comment at: lib/AST/Expr.cpp:2868
@@ +2867,3 @@
+OverloadedOperatorKind binOp = 
cast(this)->getOperator();
+if (binOp == OO_Equal || (binOp >= OO_PlusEqual && binOp <= OO_PipeEqual)) 
{
+  return true;

rsmith wrote:
> Please don't hard-code the order of OO enumerators like this (and this isn't 
> even correct: you missed `<<=` and `>>=`). 
> 
> Instead, consider extending `BinaryOperator::isAssignmentOp` / 
> `BinaryOperator::getOverloadedOpcode` so you can use them for this.
i was thinking more on doing for this specific case since 
BinaryOperator::isAssignmentOp and BinaryOperator::getOverloadedOpcode only 
accepts binary op codes and CXXOperatorCallExpr incapsulates operators both 
binary and unary


Repository:
  rL LLVM

https://reviews.llvm.org/D22910



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


Re: [PATCH] D22910: Add support for CXXOperatorCallExpr in Expr::HasSideEffects

2016-08-18 Thread Andi via cfe-commits
Abpostelnicu removed rL LLVM as the repository for this revision.
Abpostelnicu updated this revision to Diff 68507.

https://reviews.llvm.org/D22910

Files:
  include/clang/AST/ExprCXX.h
  lib/AST/Expr.cpp

Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -2861,8 +2861,16 @@
 // These never have a side-effect.
 return false;
 
+  case CXXOperatorCallExprClass: {
+// If it is an operator call expr it can have side effects when the
+// underlaying operator is of assignment kind.
+// Othrwise fall through the rest of cases.
+OverloadedOperatorKind Op = cast(this)->getOperator();
+if (CXXOperatorCallExpr::isAssignmentOp(Op)) {
+  return true;
+}
+  }
   case CallExprClass:
-  case CXXOperatorCallExprClass:
   case CXXMemberCallExprClass:
   case CUDAKernelCallExprClass:
   case UserDefinedLiteralClass: {
Index: include/clang/AST/ExprCXX.h
===
--- include/clang/AST/ExprCXX.h
+++ include/clang/AST/ExprCXX.h
@@ -106,6 +106,16 @@
   // operations on floating point types.
   bool isFPContractable() const { return FPContractable; }
 
+  // Check to see if a given overloaded operator is of assignment kind
+  static bool isAssignmentOp(OverloadedOperatorKind Opc) {
+return Opc == OO_Equal || Opc == OO_StarEqual ||
+   Opc == OO_SlashEqual || Opc == OO_PercentEqual ||
+   Opc == OO_PlusEqual || Opc == OO_MinusEqual ||
+   Opc == OO_LessLessEqual || Opc == OO_GreaterGreaterEqual ||
+   Opc == OO_AmpEqual || Opc == OO_CaretEqual ||
+   Opc == OO_PipeEqual;
+  }
+  
   friend class ASTStmtReader;
   friend class ASTStmtWriter;
 };


Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -2861,8 +2861,16 @@
 // These never have a side-effect.
 return false;
 
+  case CXXOperatorCallExprClass: {
+// If it is an operator call expr it can have side effects when the
+// underlaying operator is of assignment kind.
+// Othrwise fall through the rest of cases.
+OverloadedOperatorKind Op = cast(this)->getOperator();
+if (CXXOperatorCallExpr::isAssignmentOp(Op)) {
+  return true;
+}
+  }
   case CallExprClass:
-  case CXXOperatorCallExprClass:
   case CXXMemberCallExprClass:
   case CUDAKernelCallExprClass:
   case UserDefinedLiteralClass: {
Index: include/clang/AST/ExprCXX.h
===
--- include/clang/AST/ExprCXX.h
+++ include/clang/AST/ExprCXX.h
@@ -106,6 +106,16 @@
   // operations on floating point types.
   bool isFPContractable() const { return FPContractable; }
 
+  // Check to see if a given overloaded operator is of assignment kind
+  static bool isAssignmentOp(OverloadedOperatorKind Opc) {
+return Opc == OO_Equal || Opc == OO_StarEqual ||
+   Opc == OO_SlashEqual || Opc == OO_PercentEqual ||
+   Opc == OO_PlusEqual || Opc == OO_MinusEqual ||
+   Opc == OO_LessLessEqual || Opc == OO_GreaterGreaterEqual ||
+   Opc == OO_AmpEqual || Opc == OO_CaretEqual ||
+   Opc == OO_PipeEqual;
+  }
+  
   friend class ASTStmtReader;
   friend class ASTStmtWriter;
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23641: [ASTMatchers] Fix documentation of is(Un)SignedInteger()

2016-08-18 Thread Visoiu Mistrih Francis via cfe-commits
thegameg created this revision.
thegameg added reviewers: aaron.ballman, courbet.
thegameg added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

The example is using `isInteger()` instead of `signed` / `unsigned` version.

https://reviews.llvm.org/D23641

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h

Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -4161,7 +4161,7 @@
 ///   void b(unsigned long);
 ///   void c(double);
 /// \endcode
-/// functionDecl(hasAnyParameter(hasType(isInteger(
+/// functionDecl(hasAnyParameter(hasType(isUnsignedInteger(
 /// matches "b(unsigned long)", but not "a(int)" and "c(double)".
 AST_MATCHER(QualType, isUnsignedInteger) {
 return Node->isUnsignedIntegerType();
@@ -4175,7 +4175,7 @@
 ///   void b(unsigned long);
 ///   void c(double);
 /// \endcode
-/// functionDecl(hasAnyParameter(hasType(isInteger(
+/// functionDecl(hasAnyParameter(hasType(isSignedInteger(
 /// matches "a(int)", but not "b(unsigned long)" and "c(double)".
 AST_MATCHER(QualType, isSignedInteger) {
 return Node->isSignedIntegerType();
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -3006,7 +3006,7 @@
   void a(int);
   void b(unsigned long);
   void c(double);
-functionDecl(hasAnyParameter(hasType(isInteger(
+functionDecl(hasAnyParameter(hasType(isSignedInteger(
 matches "a(int)", but not "b(unsigned long)" and "c(double)".
 
 
@@ -3018,7 +3018,7 @@
   void a(int);
   void b(unsigned long);
   void c(double);
-functionDecl(hasAnyParameter(hasType(isInteger(
+functionDecl(hasAnyParameter(hasType(isUnsignedInteger(
 matches "b(unsigned long)", but not "a(int)" and "c(double)".
 
 


Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -4161,7 +4161,7 @@
 ///   void b(unsigned long);
 ///   void c(double);
 /// \endcode
-/// functionDecl(hasAnyParameter(hasType(isInteger(
+/// functionDecl(hasAnyParameter(hasType(isUnsignedInteger(
 /// matches "b(unsigned long)", but not "a(int)" and "c(double)".
 AST_MATCHER(QualType, isUnsignedInteger) {
 return Node->isUnsignedIntegerType();
@@ -4175,7 +4175,7 @@
 ///   void b(unsigned long);
 ///   void c(double);
 /// \endcode
-/// functionDecl(hasAnyParameter(hasType(isInteger(
+/// functionDecl(hasAnyParameter(hasType(isSignedInteger(
 /// matches "a(int)", but not "b(unsigned long)" and "c(double)".
 AST_MATCHER(QualType, isSignedInteger) {
 return Node->isSignedIntegerType();
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -3006,7 +3006,7 @@
   void a(int);
   void b(unsigned long);
   void c(double);
-functionDecl(hasAnyParameter(hasType(isInteger(
+functionDecl(hasAnyParameter(hasType(isSignedInteger(
 matches "a(int)", but not "b(unsigned long)" and "c(double)".
 
 
@@ -3018,7 +3018,7 @@
   void a(int);
   void b(unsigned long);
   void c(double);
-functionDecl(hasAnyParameter(hasType(isInteger(
+functionDecl(hasAnyParameter(hasType(isUnsignedInteger(
 matches "b(unsigned long)", but not "a(int)" and "c(double)".
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23641: [ASTMatchers] Fix documentation of is(Un)SignedInteger()

2016-08-18 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


https://reviews.llvm.org/D23641



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


Re: [PATCH] D23641: [ASTMatchers] Fix documentation of is(Un)SignedInteger()

2016-08-18 Thread Visoiu Mistrih Francis via cfe-commits
thegameg added a comment.

Can you commit this for me, please? Thanks!


https://reviews.llvm.org/D23641



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


Re: [PATCH] D23112: [analyzer] Correctly add assumptions based on array bounds.

2016-08-18 Thread Artem Dergachev via cfe-commits
NoQ added a comment.

On second thought, in `RangeConstraintManager` we need a different 
functionality. In particular, from `4 * x < 1000` it does not follow that `x < 
250` in the general case (due to possible overflows). But in the case of this 
checker, it doesn't matter - we are always sure that any valid array address is 
never overflowing even when converted to bytes.

That said, it is still boilerplate. Some day i wish to consider adding the 
non-overflowing versions of common operations into the `SValBuilder`'s 
`evalBinOp()`, so that it could help checkers simplify various symbolic 
expressions. In my opinion, `evalBinOp()` should be as user-friendly as 
possible.

But that's another story, your approach looks good to me!


https://reviews.llvm.org/D23112



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


Re: [PATCH] D23641: [ASTMatchers] Fix documentation of is(Un)SignedInteger()

2016-08-18 Thread Aaron Ballman via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Commit in r279055


https://reviews.llvm.org/D23641



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


r279055 - Correct the documentation for isSignedInteger() and isUnsignedInteger().

2016-08-18 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Aug 18 07:26:17 2016
New Revision: 279055

URL: http://llvm.org/viewvc/llvm-project?rev=279055&view=rev
Log:
Correct the documentation for isSignedInteger() and isUnsignedInteger().

Patch by Visoiu Mistrih Francis

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=279055&r1=279054&r2=279055&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Aug 18 07:26:17 2016
@@ -3006,7 +3006,7 @@ Given
   void a(int);
   void b(unsigned long);
   void c(double);
-functionDecl(hasAnyParameter(hasType(isInteger(
+functionDecl(hasAnyParameter(hasType(isSignedInteger(
 matches "a(int)", but not "b(unsigned long)" and "c(double)".
 
 
@@ -3018,7 +3018,7 @@ Given
   void a(int);
   void b(unsigned long);
   void c(double);
-functionDecl(hasAnyParameter(hasType(isInteger(
+functionDecl(hasAnyParameter(hasType(isUnsignedInteger(
 matches "b(unsigned long)", but not "a(int)" and "c(double)".
 
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=279055&r1=279054&r2=279055&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Aug 18 07:26:17 2016
@@ -4161,7 +4161,7 @@ AST_MATCHER(QualType, isInteger) {
 ///   void b(unsigned long);
 ///   void c(double);
 /// \endcode
-/// functionDecl(hasAnyParameter(hasType(isInteger(
+/// functionDecl(hasAnyParameter(hasType(isUnsignedInteger(
 /// matches "b(unsigned long)", but not "a(int)" and "c(double)".
 AST_MATCHER(QualType, isUnsignedInteger) {
 return Node->isUnsignedIntegerType();
@@ -4175,7 +4175,7 @@ AST_MATCHER(QualType, isUnsignedInteger)
 ///   void b(unsigned long);
 ///   void c(double);
 /// \endcode
-/// functionDecl(hasAnyParameter(hasType(isInteger(
+/// functionDecl(hasAnyParameter(hasType(isSignedInteger(
 /// matches "a(int)", but not "b(unsigned long)" and "c(double)".
 AST_MATCHER(QualType, isSignedInteger) {
 return Node->isSignedIntegerType();


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


Re: [PATCH] D23314: [analyzer] CloneDetector allows comparing clones for suspicious variable pattern errors.

2016-08-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279056: [analyzer] Teach CloneDetector to find clones that 
look like copy-paste errors. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D23314?vs=68422&id=68518#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23314

Files:
  cfe/trunk/include/clang/Analysis/CloneDetection.h
  cfe/trunk/lib/Analysis/CloneDetection.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
  cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp

Index: cfe/trunk/include/clang/Analysis/CloneDetection.h
===
--- cfe/trunk/include/clang/Analysis/CloneDetection.h
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h
@@ -24,6 +24,7 @@
 
 class Stmt;
 class Decl;
+class VarDecl;
 class ASTContext;
 class CompoundStmt;
 
@@ -222,7 +223,43 @@
   ///   that were identified to be clones of each other.
   /// \param MinGroupComplexity Only return clones which have at least this
   ///   complexity value.
-  void findClones(std::vector &Result, unsigned MinGroupComplexity);
+  /// \param CheckPatterns Returns only clone groups in which the referenced
+  ///  variables follow the same pattern.
+  void findClones(std::vector &Result, unsigned MinGroupComplexity,
+  bool CheckPatterns = true);
+
+  /// \brief Describes two clones that reference their variables in a different
+  ///pattern which could indicate a programming error.
+  struct SuspiciousClonePair {
+/// \brief Utility class holding the relevant information about a single
+///clone in this pair.
+struct SuspiciousCloneInfo {
+  /// The variable which referencing in this clone was against the pattern.
+  const VarDecl *Variable;
+  /// Where the variable was referenced.
+  SourceRange VarRange;
+  /// The variable that should have been referenced to follow the pattern.
+  /// If Suggestion is a nullptr then it's not possible to fix the pattern
+  /// by referencing a different variable in this clone.
+  const VarDecl *Suggestion;
+  SuspiciousCloneInfo(const VarDecl *Variable, SourceRange Range,
+  const VarDecl *Suggestion)
+  : Variable(Variable), VarRange(Range), Suggestion(Suggestion) {}
+  SuspiciousCloneInfo() {}
+};
+/// The first clone in the pair which always has a suggested variable.
+SuspiciousCloneInfo FirstCloneInfo;
+/// This other clone in the pair which can have a suggested variable.
+SuspiciousCloneInfo SecondCloneInfo;
+  };
+
+  /// \brief Searches the provided statements for pairs of clones that don't
+  ///follow the same pattern when referencing variables.
+  /// \param Result Output parameter that will contain the clone pairs.
+  /// \param MinGroupComplexity Only clone pairs in which the clones have at
+  ///   least this complexity value.
+  void findSuspiciousClones(std::vector &Result,
+unsigned MinGroupComplexity);
 
 private:
   /// Stores all found clone groups including invalid groups with only a single
Index: cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp
===
--- cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp
+++ cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp
@@ -0,0 +1,97 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:ReportSuspiciousClones=true  -analyzer-config alpha.clone.CloneChecker:ReportNormalClones=false -verify %s
+
+// Tests finding a suspicious clone that references local variables.
+
+void log();
+
+int max(int a, int b) {
+  log();
+  if (a > b)
+return a;
+  return b; // expected-note{{suggestion is based on the usage of this variable in a similar piece of code}}
+}
+
+int maxClone(int x, int y, int z) {
+  log();
+  if (x > y)
+return x;
+  return z; // expected-warning{{suspicious code clone detected; did you mean to use 'y'?}}
+}
+
+// Tests finding a suspicious clone that references global variables.
+
+struct mutex {
+  bool try_lock();
+  void unlock();
+};
+
+mutex m1;
+mutex m2;
+int i;
+
+void busyIncrement() {
+  while (true) {
+if (m1.try_lock()) {
+  ++i;
+  m1.unlock(); // expected-note{{suggestion is based on the usage of this variable in a similar piece of code}}
+  if (i > 1000) {
+return;
+  }
+}
+  }
+}
+
+void faultyBusyIncrement() {
+  while (true) {
+if (m1.try_lock()) {
+  ++i;
+  m2.unlock();  // expected-warning{{suspicious code clone detected; did you mean to use 'm1'?}}
+  if (i > 1000) {
+return;
+  }
+}
+  }
+}
+
+// Tests that we provide two suggestions in cases where two fixes are possible.
+
+int foo(int a, int b, int c) {
+  a += b 

r279056 - [analyzer] Teach CloneDetector to find clones that look like copy-paste errors.

2016-08-18 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Aug 18 07:29:41 2016
New Revision: 279056

URL: http://llvm.org/viewvc/llvm-project?rev=279056&view=rev
Log:
[analyzer] Teach CloneDetector to find clones that look like copy-paste errors.

The original clone checker tries to find copy-pasted code that is exactly
identical to the original code, up to minor details.

As an example, if the copy-pasted code has all references to variable 'a'
replaced with references to variable 'b', it is still considered to be
an exact clone.

The new check finds copy-pasted code in which exactly one variable seems
out of place compared to the original code, which likely indicates
a copy-paste error (a variable was forgotten to be renamed in one place).

Patch by Raphael Isemann!

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

Added:
cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp
Modified:
cfe/trunk/include/clang/Analysis/CloneDetection.h
cfe/trunk/lib/Analysis/CloneDetection.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp

Modified: cfe/trunk/include/clang/Analysis/CloneDetection.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CloneDetection.h?rev=279056&r1=279055&r2=279056&view=diff
==
--- cfe/trunk/include/clang/Analysis/CloneDetection.h (original)
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h Thu Aug 18 07:29:41 2016
@@ -24,6 +24,7 @@ namespace clang {
 
 class Stmt;
 class Decl;
+class VarDecl;
 class ASTContext;
 class CompoundStmt;
 
@@ -222,7 +223,43 @@ public:
   ///   that were identified to be clones of each other.
   /// \param MinGroupComplexity Only return clones which have at least this
   ///   complexity value.
-  void findClones(std::vector &Result, unsigned 
MinGroupComplexity);
+  /// \param CheckPatterns Returns only clone groups in which the referenced
+  ///  variables follow the same pattern.
+  void findClones(std::vector &Result, unsigned MinGroupComplexity,
+  bool CheckPatterns = true);
+
+  /// \brief Describes two clones that reference their variables in a different
+  ///pattern which could indicate a programming error.
+  struct SuspiciousClonePair {
+/// \brief Utility class holding the relevant information about a single
+///clone in this pair.
+struct SuspiciousCloneInfo {
+  /// The variable which referencing in this clone was against the pattern.
+  const VarDecl *Variable;
+  /// Where the variable was referenced.
+  SourceRange VarRange;
+  /// The variable that should have been referenced to follow the pattern.
+  /// If Suggestion is a nullptr then it's not possible to fix the pattern
+  /// by referencing a different variable in this clone.
+  const VarDecl *Suggestion;
+  SuspiciousCloneInfo(const VarDecl *Variable, SourceRange Range,
+  const VarDecl *Suggestion)
+  : Variable(Variable), VarRange(Range), Suggestion(Suggestion) {}
+  SuspiciousCloneInfo() {}
+};
+/// The first clone in the pair which always has a suggested variable.
+SuspiciousCloneInfo FirstCloneInfo;
+/// This other clone in the pair which can have a suggested variable.
+SuspiciousCloneInfo SecondCloneInfo;
+  };
+
+  /// \brief Searches the provided statements for pairs of clones that don't
+  ///follow the same pattern when referencing variables.
+  /// \param Result Output parameter that will contain the clone pairs.
+  /// \param MinGroupComplexity Only clone pairs in which the clones have at
+  ///   least this complexity value.
+  void findSuspiciousClones(std::vector &Result,
+unsigned MinGroupComplexity);
 
 private:
   /// Stores all found clone groups including invalid groups with only a single

Modified: cfe/trunk/lib/Analysis/CloneDetection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CloneDetection.cpp?rev=279056&r1=279055&r2=279056&view=diff
==
--- cfe/trunk/lib/Analysis/CloneDetection.cpp (original)
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp Thu Aug 18 07:29:41 2016
@@ -88,8 +88,11 @@ class VariablePattern {
   struct VariableOccurence {
 /// The index of the associated VarDecl in the Variables vector.
 size_t KindID;
+/// The source range in the code where the variable was referenced.
+SourceRange Range;
 
-VariableOccurence(size_t KindID) : KindID(KindID) {}
+VariableOccurence(size_t KindID, SourceRange Range)
+: KindID(KindID), Range(Range) {}
   };
 
   /// All occurences of referenced variables in the order of appearance.
@@ -100,19 +103,20 @@ class VariablePattern {
 
   /// \brief Adds a new variable referenced to this pattern.
   /// \param VarDecl The declaration of the variable

[PATCH] D23657: Remove some false positives when taking the address of packed members

2016-08-18 Thread Roger Ferrer Ibanez via cfe-commits
rogfer01 created this revision.
rogfer01 added reviewers: aaron.ballman, rsmith.
rogfer01 added a subscriber: cfe-commits.

This change remove some false positives when taking the address of packed 
members.

- It silences the warning when a cast to uintptr_t/intptr_t happens.
- If the field is in a packed record that is overaligned, the field may still 
be in a suitable offset for the required alignment of the field. We now check 
this as well.

https://reviews.llvm.org/D23657

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/address-packed.c

Index: test/Sema/address-packed.c
===
--- test/Sema/address-packed.c
+++ test/Sema/address-packed.c
@@ -26,6 +26,7 @@
 struct Arguable *get_arguable();
 
 void to_void(void *);
+void to_intptr(intptr_t);
 
 void g0(void) {
   {
@@ -41,43 +42,48 @@
 
 f1((int *)(void *)&arguable.x); // no-warning
 to_void(&arguable.x);   // no-warning
-void *p = &arguable.x;  // no-warning;
+void *p = &arguable.x;  // no-warning
 to_void(p);
+to_intptr((intptr_t)p); // no-warning
   }
   {
 union UnionArguable arguable;
 f2(&arguable.c); // no-warning
 f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'UnionArguable'}}
 
-f1((int *)(void *)&arguable.x); // no-warning
-to_void(&arguable.x);   // no-warning
+f1((int *)(void *)&arguable.x);   // no-warning
+to_void(&arguable.x); // no-warning
+to_intptr((intptr_t)&arguable.x); // no-warning
   }
   {
 ArguableT arguable;
 f2(&arguable.c0); // no-warning
 f1(&arguable.x);  // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
 f2(&arguable.c1); // no-warning
 
-f1((int *)(void *)&arguable.x); // no-warning
-to_void(&arguable.x);   // no-warning
+f1((int *)(void *)&arguable.x);   // no-warning
+to_void(&arguable.x); // no-warning
+to_intptr((intptr_t)&arguable.x); // no-warning
   }
   {
 struct Arguable *arguable = get_arguable();
 f2(&arguable->c0); // no-warning
 f1(&arguable->x);  // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
 f2(&arguable->c1); // no-warning
 
-f1((int *)(void *)&arguable->x); // no-warning
-to_void(&arguable->c1);  // no-warning
+f1((int *)(void *)&arguable->x);// no-warning
+to_void(&arguable->c1); // no-warning
+to_intptr((intptr_t)&arguable->c1); // no-warning
   }
   {
 ArguableT *arguable = get_arguable();
 f2(&(arguable->c0)); // no-warning
 f1(&(arguable->x));  // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
 f2(&(arguable->c1)); // no-warning
 
-f1((int *)(void *)&(arguable->x)); // no-warning
-to_void(&(arguable->c1));  // no-warning
+f1((int *)(void *)&(arguable->x));  // no-warning
+to_void(&(arguable->c1));   // no-warning
+to_intptr((intptr_t)&(arguable->c1));   // no-warning
   }
 }
 
@@ -161,3 +167,18 @@
 {
 return (struct AlignedTo2Bis*)&s->x; // no-warning
 }
+
+struct S6 {
+int a;
+int _;
+int c;
+char __;
+int d;
+} __attribute__((packed, aligned(16))) s6;
+
+void foo()
+{ 
+f1(&s6.a); // no-warning
+f1(&s6.c); // no-warning
+f1(&s6.d); // expected-warning {{packed member 'd' of class or structure 'S6'}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11016,43 +11016,55 @@
 }
 
 void Sema::DiscardMisalignedMemberAddress(const Type *T, Expr *E) {
-  if (!T->isPointerType())
+  if (!T->isPointerType() && !T->isIntegerType())
 return;
   if (isa(E) &&
   cast(E)->getOpcode() == UO_AddrOf) {
 auto *Op = cast(E)->getSubExpr()->IgnoreParens();
 if (isa(Op)) {
   auto MA = std::find(MisalignedMembers.begin(), MisalignedMembers.end(),
   MisalignedMember(Op));
   if (MA != MisalignedMembers.end() &&
-  Context.getTypeAlignInChars(T->getPointeeType()) <= MA->Alignment)
+  (T->isIntegerType() ||
+   (T->isPointerType() &&
+Context.getTypeAlignInChars(T->getPointeeType()) <= MA->Alignment)))
 MisalignedMembers.erase(MA);
 }
   }
 }
 
 void Sema::RefersToMemberWithReducedAlignment(
 Expr *E,
 std::function Action) {
+  // return;
   const auto *ME = dyn_cast(E);
+  CharUnits RequiredAlignment;
   while (ME && isa(ME->getMemberDecl())) {
 QualType BaseType = ME->getBase()->getType();
 if (ME->isArrow())
   BaseType = BaseType->getPointeeType();
 RecordDecl *RD = BaseType->getAs()->getDecl();
 
 ValueDecl *MD = ME->getMemberDecl();
-bool ByteAligned = Context.getTypeAlignInChars(MD->getType()).isOne();
-if (ByteAligned) // Attribute packed does not have any effect.
-  break;
+a

Re: [PATCH] D15332: new clang-tidy checker readability-non-const-parameter

2016-08-18 Thread Daniel Marjamäki via cfe-commits
danielmarjamaki updated this revision to Diff 68528.
danielmarjamaki marked 2 inline comments as done.
danielmarjamaki added a comment.

Fixed review comments


https://reviews.llvm.org/D15332

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tidy/readability/NonConstParameterCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-non-const-parameter.rst
  test/clang-tidy/readability-non-const-parameter.cpp

Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -0,0 +1,279 @@
+// RUN: %check_clang_tidy %s readability-non-const-parameter %t
+
+// Currently the checker only warns about pointer arguments.
+//
+// It can be defined both that the data is const and that the pointer is const,
+// the checker only checks if the data can be const-specified.
+//
+// It does not warn about pointers to records or function pointers.
+
+// Some external function where first argument is nonconst and second is const.
+char *strcpy1(char *dest, const char *src);
+unsigned my_strcpy(char *buf, const char *s);
+unsigned my_strlen(const char *buf);
+
+// CHECK-MESSAGES: :[[@LINE+1]]:29: warning: pointer parameter 'last' can be pointer to const [readability-non-const-parameter]
+void warn1(int *first, int *last) {
+  // CHECK-FIXES: {{^}}void warn1(int *first, const int *last) {{{$}}
+  *first = 0;
+  if (first < last) {
+  } // <- last can be const
+}
+
+// TODO: warning should be written here
+void warn2(char *p) {
+  char buf[10];
+  strcpy1(buf, p);
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign1(int *p) {
+  // CHECK-FIXES: {{^}}void assign1(const int *p) {{{$}}
+  const int *q;
+  q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign2(int *p) {
+  // CHECK-FIXES: {{^}}void assign2(const int *p) {{{$}}
+  const int *q;
+  q = p + 1;
+}
+
+void assign3(int *p) {
+  *p = 0;
+}
+
+void assign4(int *p) {
+  *p += 2;
+}
+
+void assign5(char *p) {
+  p[0] = 0;
+}
+
+void assign6(int *p) {
+  int *q;
+  q = p++;
+}
+
+void assign7(char *p) {
+  char *a, *b;
+  a = b = p;
+}
+
+void assign8(char *a, char *b) {
+  char *x;
+  x = (a ? a : b);
+}
+
+void assign9(unsigned char *str, const unsigned int i) {
+  unsigned char *p;
+  for (p = str + i; *p;) {
+  }
+}
+
+void assign10(int *buf) {
+  int i, *p;
+  for (i = 0, p = buf; i < 10; i++, p++) {
+*p = 1;
+  }
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init1(int *p) {
+  // CHECK-FIXES: {{^}}void init1(const int *p) {{{$}}
+  const int *q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init2(int *p) {
+  // CHECK-FIXES: {{^}}void init2(const int *p) {{{$}}
+  const int *q = p + 1;
+}
+
+void init3(int *p) {
+  int *q = p;
+}
+
+void init4(float *p) {
+  int *q = (int *)p;
+}
+
+void init5(int *p) {
+  int *i = p ? p : 0;
+}
+
+void init6(int *p) {
+  int *a[] = {p, p, 0};
+}
+
+void init7(int *p, int x) {
+  for (int *q = p + x - 1; 0; q++)
+;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:18: warning: pointer parameter 'p' can be
+int return1(int *p) {
+  // CHECK-FIXES: {{^}}int return1(const int *p) {{{$}}
+  return *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return2(int *p) {
+  // CHECK-FIXES: {{^}}const int *return2(const int *p) {{{$}}
+  return p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return3(int *p) {
+  // CHECK-FIXES: {{^}}const int *return3(const int *p) {{{$}}
+  return p + 1;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+const char *return4(char *p) {
+  // CHECK-FIXES: {{^}}const char *return4(const char *p) {{{$}}
+  return p ? p : "";
+}
+
+char *return5(char *s) {
+  return s;
+}
+
+char *return6(char *s) {
+  return s + 1;
+}
+
+char *return7(char *a, char *b) {
+  return a ? a : b;
+}
+
+char return8(int *p) {
+  return ++(*p);
+}
+
+void dontwarn1(int *p) {
+  ++(*p);
+}
+
+void dontwarn2(int *p) {
+  (*p)++;
+}
+
+int dontwarn3(_Atomic(int) * p) {
+  return *p;
+}
+
+void callFunction1(char *p) {
+  strcpy1(p, "abc");
+}
+
+void callFunction2(char *p) {
+  strcpy1(&p[0], "abc");
+}
+
+void callFunction3(char *p) {
+  strcpy1(p + 2, "abc");
+}
+
+char *callFunction4(char *p) {
+  return strcpy1(p, "abc");
+}
+
+unsigned callFunction5(char *buf) {
+  unsigned len = my_strlen(buf);
+  return len + my_strcpy(buf, "abc");
+}
+
+void f6(int **p);
+void callFunction6(int *p) { f6(&p); }
+
+typedef union { void *v; } t;
+void f7(t obj);
+void callFunction7(int *p) {
+  f7((t){p});
+}
+
+void f8(int &x);
+void callFunct

Re: [PATCH] D15332: new clang-tidy checker readability-non-const-parameter

2016-08-18 Thread Daniel Marjamäki via cfe-commits
danielmarjamaki updated this revision to Diff 68531.
danielmarjamaki added a comment.

Fixed review comments about formatting in doc


https://reviews.llvm.org/D15332

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tidy/readability/NonConstParameterCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-non-const-parameter.rst
  test/clang-tidy/readability-non-const-parameter.cpp

Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -0,0 +1,279 @@
+// RUN: %check_clang_tidy %s readability-non-const-parameter %t
+
+// Currently the checker only warns about pointer arguments.
+//
+// It can be defined both that the data is const and that the pointer is const,
+// the checker only checks if the data can be const-specified.
+//
+// It does not warn about pointers to records or function pointers.
+
+// Some external function where first argument is nonconst and second is const.
+char *strcpy1(char *dest, const char *src);
+unsigned my_strcpy(char *buf, const char *s);
+unsigned my_strlen(const char *buf);
+
+// CHECK-MESSAGES: :[[@LINE+1]]:29: warning: pointer parameter 'last' can be pointer to const [readability-non-const-parameter]
+void warn1(int *first, int *last) {
+  // CHECK-FIXES: {{^}}void warn1(int *first, const int *last) {{{$}}
+  *first = 0;
+  if (first < last) {
+  } // <- last can be const
+}
+
+// TODO: warning should be written here
+void warn2(char *p) {
+  char buf[10];
+  strcpy1(buf, p);
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign1(int *p) {
+  // CHECK-FIXES: {{^}}void assign1(const int *p) {{{$}}
+  const int *q;
+  q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign2(int *p) {
+  // CHECK-FIXES: {{^}}void assign2(const int *p) {{{$}}
+  const int *q;
+  q = p + 1;
+}
+
+void assign3(int *p) {
+  *p = 0;
+}
+
+void assign4(int *p) {
+  *p += 2;
+}
+
+void assign5(char *p) {
+  p[0] = 0;
+}
+
+void assign6(int *p) {
+  int *q;
+  q = p++;
+}
+
+void assign7(char *p) {
+  char *a, *b;
+  a = b = p;
+}
+
+void assign8(char *a, char *b) {
+  char *x;
+  x = (a ? a : b);
+}
+
+void assign9(unsigned char *str, const unsigned int i) {
+  unsigned char *p;
+  for (p = str + i; *p;) {
+  }
+}
+
+void assign10(int *buf) {
+  int i, *p;
+  for (i = 0, p = buf; i < 10; i++, p++) {
+*p = 1;
+  }
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init1(int *p) {
+  // CHECK-FIXES: {{^}}void init1(const int *p) {{{$}}
+  const int *q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init2(int *p) {
+  // CHECK-FIXES: {{^}}void init2(const int *p) {{{$}}
+  const int *q = p + 1;
+}
+
+void init3(int *p) {
+  int *q = p;
+}
+
+void init4(float *p) {
+  int *q = (int *)p;
+}
+
+void init5(int *p) {
+  int *i = p ? p : 0;
+}
+
+void init6(int *p) {
+  int *a[] = {p, p, 0};
+}
+
+void init7(int *p, int x) {
+  for (int *q = p + x - 1; 0; q++)
+;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:18: warning: pointer parameter 'p' can be
+int return1(int *p) {
+  // CHECK-FIXES: {{^}}int return1(const int *p) {{{$}}
+  return *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return2(int *p) {
+  // CHECK-FIXES: {{^}}const int *return2(const int *p) {{{$}}
+  return p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return3(int *p) {
+  // CHECK-FIXES: {{^}}const int *return3(const int *p) {{{$}}
+  return p + 1;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+const char *return4(char *p) {
+  // CHECK-FIXES: {{^}}const char *return4(const char *p) {{{$}}
+  return p ? p : "";
+}
+
+char *return5(char *s) {
+  return s;
+}
+
+char *return6(char *s) {
+  return s + 1;
+}
+
+char *return7(char *a, char *b) {
+  return a ? a : b;
+}
+
+char return8(int *p) {
+  return ++(*p);
+}
+
+void dontwarn1(int *p) {
+  ++(*p);
+}
+
+void dontwarn2(int *p) {
+  (*p)++;
+}
+
+int dontwarn3(_Atomic(int) * p) {
+  return *p;
+}
+
+void callFunction1(char *p) {
+  strcpy1(p, "abc");
+}
+
+void callFunction2(char *p) {
+  strcpy1(&p[0], "abc");
+}
+
+void callFunction3(char *p) {
+  strcpy1(p + 2, "abc");
+}
+
+char *callFunction4(char *p) {
+  return strcpy1(p, "abc");
+}
+
+unsigned callFunction5(char *buf) {
+  unsigned len = my_strlen(buf);
+  return len + my_strcpy(buf, "abc");
+}
+
+void f6(int **p);
+void callFunction6(int *p) { f6(&p); }
+
+typedef union { void *v; } t;
+void f7(t obj);
+void callFunction7(int *p) {
+  f7((t){p});
+}
+
+void f8(int &x);
+void callFunction8(int *p) {
+  f8(*p);

Re: [PATCH] D20132: [libclang] Add clang_getAllSkippedRanges function

2016-08-18 Thread Cameron via cfe-commits
cameron314 added inline comments.


Comment at: unittests/libclang/LibclangTest.cpp:16-20
@@ -15,4 +15,7 @@
 #include "gtest/gtest.h"
 #include 
 #include 
+#include 
+#include 
+#include 
 #define DEBUG_TYPE "libclang-test"

rsmith wrote:
> Please put these in alphabetical order.
Will do!


https://reviews.llvm.org/D20132



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


Re: [PATCH] D23492: Make function local tags visible.

2016-08-18 Thread Vassil Vassilev via cfe-commits
v.g.vassilev updated this revision to Diff 68536.
v.g.vassilev marked 2 inline comments as done.
v.g.vassilev added a comment.

Add setHidden(false) and update fixme.


https://reviews.llvm.org/D23492

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/Modules/Inputs/PR28794/LibAHeader.h
  test/Modules/Inputs/PR28794/Subdir/Empty.h
  test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
  test/Modules/Inputs/PR28794/module.modulemap
  test/Modules/pr28794.cpp

Index: test/Modules/pr28794.cpp
===
--- /dev/null
+++ test/Modules/pr28794.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -I%S/Inputs/PR28794 -verify %s
+// RUN: %clang_cc1 -std=c++11 -fmodules -fmodule-map-file=%S/Inputs/PR28794/module.modulemap -fmodules-cache-path=%t -I%S/Inputs/PR28794/ -verify %s
+
+#include "Subdir/Empty.h"
+#include "LibAHeader.h"
+
+BumpPtrAllocatorImpl<> &getPreprocessorAllocator();
+class B {
+  struct ModuleMacroInfo {
+ModuleMacroInfo *getModuleInfo() {
+  return new (getPreprocessorAllocator()) ModuleMacroInfo();
+}
+  };
+};
+
+// expected-no-diagnostics
Index: test/Modules/Inputs/PR28794/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/PR28794/module.modulemap
@@ -0,0 +1,3 @@
+module M {
+  umbrella "Subdir" module * {export *}
+}
Index: test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
===
--- /dev/null
+++ test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
@@ -0,0 +1,12 @@
+#ifndef LIB_B_HEADER
+#define LIB_B_HEADER
+
+#include "LibAHeader.h"
+
+template 
+void *operator new(size_t, BumpPtrAllocatorImpl &) {
+  struct S {};
+  return (void*)0xdead;
+}
+
+#endif // LIB_B_HEADER
Index: test/Modules/Inputs/PR28794/Subdir/Empty.h
===
--- /dev/null
+++ test/Modules/Inputs/PR28794/Subdir/Empty.h
@@ -0,0 +1 @@
+
Index: test/Modules/Inputs/PR28794/LibAHeader.h
===
--- /dev/null
+++ test/Modules/Inputs/PR28794/LibAHeader.h
@@ -0,0 +1,12 @@
+#ifndef LIB_A_HEADER
+#define LIB_A_HEADER
+
+typedef __SIZE_TYPE__ size_t;
+
+template 
+class BumpPtrAllocatorImpl;
+
+template 
+void * operator new(size_t, BumpPtrAllocatorImpl &);
+
+#endif // LIB_A_HEADER
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3545,7 +3545,8 @@
 
   // Never instantiate an explicit specialization except if it is a class scope
   // explicit specialization.
-  if (Function->getTemplateSpecializationKind() == TSK_ExplicitSpecialization &&
+  TemplateSpecializationKind TSK = Function->getTemplateSpecializationKind();
+  if (TSK == TSK_ExplicitSpecialization &&
   !Function->getClassScopeSpecializationPattern())
 return;
 
@@ -3593,10 +3594,16 @@
 Pattern = PatternDecl->getBody(PatternDecl);
   }
 
-  // FIXME: Check that the definition is visible before trying to instantiate
-  // it. This requires us to track the instantiation stack in order to know
-  // which definitions should be visible.
+  // FIXME: We need to track the instantiation stack in order to know which
+  // definitions should be visible within this instantiation.
+  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Function,
+Function->getInstantiatedFromMemberFunction(),
+ PatternDecl, PatternDecl, TSK,
+ /*Complain*/DefinitionRequired))
+ return;
 
+  // FIXME: Check if we could sink these diagnostics in
+  // DiagnoseUninstantiableTemplate.
   if (!Pattern && !PatternDecl->isDefaulted()) {
 if (DefinitionRequired) {
   if (Function->getPrimaryTemplate())
@@ -3612,13 +3619,11 @@
 Diag(PatternDecl->getLocation(),
  diag::note_explicit_instantiation_here);
   Function->setInvalidDecl();
-} else if (Function->getTemplateSpecializationKind()
- == TSK_ExplicitInstantiationDefinition) {
+} else if (TSK == TSK_ExplicitInstantiationDefinition) {
   assert(!Recursive);
   PendingInstantiations.push_back(
 std::make_pair(Function, PointOfInstantiation));
-} else if (Function->getTemplateSpecializationKind()
- == TSK_ImplicitInstantiation) {
+} else if (TSK == TSK_ImplicitInstantiation) {
   if (AtEndOfTU && !getDiagnostics().hasErrorOccurred()) {
 Diag(PointOfInstantiation, diag::warn_func_template_missing)
   << Function;
@@ -3637,8 +3642,7 @@
   //   initializer or return value, and class template specializations, other
   //   explicit instantiation decla

Re: [PATCH] D23662: [libclang] Control whether crash recovery is enabled/disabled using function argument.

2016-08-18 Thread John Brawn via cfe-commits
john.brawn added a subscriber: john.brawn.
john.brawn added a comment.

> When my Java application calls clang_createIndex() with crash recovery 
> enabled it replaces the JVM's segfault handler with 
> CrashRecoverySignalHandler and now this handler gets all the segfault signals 
> that would have normally been sent to the JVM and when it does and tries to 
> restore the previous segfault hanlder (which is the JVMs) it doesn't install 
> the right one because the JVM ends up crashing and producing a core dump.


Surely the fix then is to make sure CrashRecoveryContext::Disable //does// 
reinstall the right signal handler?

> The only way to correctly solve my problem is to set the environment variable 
> 'LIBCLANG_DISABLE_CRASH_RECOVERY' but I find this to not be a very nice way 
> to control the program behaviour


Why not? Also I notice that using environment variables to control behaviour is 
used in a bunch of places in libclang so you're introducing some inconsistency 
here.


Repository:
  rL LLVM

https://reviews.llvm.org/D23662



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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: lib/CodeGen/CGExprScalar.cpp:1513
@@ -1512,2 +1512,3 @@
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+auto DestLLVMTy = ConvertType(DestTy);
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy);

Did you miss this changes in the original patch then?


Comment at: lib/CodeGen/CGExprScalar.cpp:2447
@@ -2443,3 +2446,3 @@
 bool isSigned = 
indexOperand->getType()->isSignedIntegerOrEnumerationType();
-index = CGF.Builder.CreateIntCast(index, CGF.PtrDiffTy, isSigned,
+index = CGF.Builder.CreateIntCast(index, DL.getIntPtrType(PtrTy), isSigned,
   "idx.ext");

No longer ptrdiff_t?


https://reviews.llvm.org/D23361



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


Re: [PATCH] D15332: new clang-tidy checker readability-non-const-parameter

2016-08-18 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG



Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:104
@@ +103,3 @@
+  const QualType T = Parm->getType();
+  if (!T->isPointerType() || T->getPointeeType().isConstQualified() ||
+  !(T->getPointeeType()->isIntegerType() ||

You're right. I was thinking about enums, but `isIntegerType` takes care of 
them too. As the next step, we should try to add all POD types, but that's a 
question for another patch.


Comment at: test/clang-tidy/readability-non-const-parameter.cpp:118-136
@@ +117,21 @@
+int return1(int *p) {
+  // CHECK-FIXES: {{^}}int return1(const int *p) {{{$}}
+  return *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return2(int *p) {
+  // CHECK-FIXES: {{^}}const int *return2(const int *p) {{{$}}
+  return p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return3(int *p) {
+  // CHECK-FIXES: {{^}}const int *return3(const int *p) {{{$}}
+  return p + 1;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+const char *return4(char *p) {
+  // CHECK-FIXES: {{^}}const char *return4(const char *p) {{{$}}
+  return p ? p : "";

`PointerParameterConstnessCheck` is not much better, IMO. Maybe 
`readability-use-pointer-to-const-parameter`? Or just leave it like this for 
now.


https://reviews.llvm.org/D15332



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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Yaxun Liu via cfe-commits
yaxunl marked an inline comment as done.


Comment at: lib/CodeGen/CGExprScalar.cpp:1513
@@ -1512,2 +1512,3 @@
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+auto DestLLVMTy = ConvertType(DestTy);
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy);

Anastasia wrote:
> Did you miss this changes in the original patch then?
Yes.


Comment at: lib/CodeGen/CGExprScalar.cpp:2447
@@ -2443,3 +2446,3 @@
 bool isSigned = 
indexOperand->getType()->isSignedIntegerOrEnumerationType();
-index = CGF.Builder.CreateIntCast(index, CGF.PtrDiffTy, isSigned,
+index = CGF.Builder.CreateIntCast(index, DL.getIntPtrType(PtrTy), isSigned,
   "idx.ext");

Anastasia wrote:
> No longer ptrdiff_t?
PtrDiffTy and IntPtrTy are members of an anonymous union

  /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
  union {
llvm::IntegerType *IntPtrTy;
llvm::IntegerType *SizeTy;
llvm::IntegerType *PtrDiffTy;
  };

so they are actually the same thing. 


https://reviews.llvm.org/D23361



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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Anastasia Stulova via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D23361



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


Re: [PATCH] D23651: [clang-rename] improve performance for rename-all

2016-08-18 Thread Alexander Kornienko via cfe-commits
alexfh requested changes to this revision.
This revision now requires changes to proceed.


Comment at: clang-rename/USRFindingAction.cpp:69
@@ -69,2 +68,3 @@
 }
-USRs->insert(USRs->end(), USRSet.begin(), USRSet.end());
+USRs.insert(USRs.end(), USRSet.begin(), USRSet.end());
+return USRs;

Should USRs be a local variable now?


Comment at: clang-rename/USRFindingAction.cpp:147
@@ +146,3 @@
+  explicit NamedDeclFindingConsumer(
+  const std::vector &SymbolOffsets,
+  const std::vector &OldNames,

Use `ArrayRef` here as well. BTW, if the code relies on `SymbolOffsets` and 
`OldNames` being of the same length, maybe a single collection of pairs would 
work better? Or define a structure for keeping offset and old name together?


Comment at: clang-rename/USRFindingAction.h:29
@@ -27,3 +28,3 @@
 struct USRFindingAction {
-  USRFindingAction(unsigned Offset, const std::string &Name)
-  : SymbolOffset(Offset), OldName(Name) {}
+  USRFindingAction(const std::vector &SymbolOffsets,
+   const std::vector &OldNames)

Use `ArrayRef` instead of `const vector<>&`. `ArrayRef<>` is less restrictive.


Comment at: clang-rename/USRFindingAction.h:30
@@ +29,3 @@
+  USRFindingAction(const std::vector &SymbolOffsets,
+   const std::vector &OldNames)
+  : SymbolOffsets(SymbolOffsets), OldNames(OldNames) {}

Use `ArrayRef`.


Comment at: clang-rename/USRFindingAction.h:38
@@ -37,5 +37,3 @@
 private:
-  unsigned SymbolOffset;
-  std::string OldName;
-  std::string SpellingName;
-  std::vector USRs;
+  const std::vector &SymbolOffsets;
+  const std::vector &OldNames;

omtcyfz wrote:
> Aw, you're right. Good catch, thanks!
Reference members always seem suspicious to me. One has to be really really 
careful not to mess up lifetimes. Are we actually saving much but not copying 
these vectors?


https://reviews.llvm.org/D23651



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


r279076 - [libclang] Add clang_getAllSkippedRanges function

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 10:43:55 2016
New Revision: 279076

URL: http://llvm.org/viewvc/llvm-project?rev=279076&view=rev
Log:
[libclang] Add clang_getAllSkippedRanges function

This complements the clang_getSkippedRanges function which returns skipped 
ranges filtered by a specific file.

This function is useful when all the ranges are desired (and a lot more 
efficient than the equivalent of asking for the ranges file by file, since the 
implementation of clang_getSkippedRanges iterates over all ranges anyway).

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

Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=279076&r1=279075&r2=279076&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Aug 18 10:43:55 2016
@@ -627,6 +627,15 @@ CINDEX_LINKAGE CXSourceRangeList *clang_
  CXFile file);
 
 /**
+ * \brief Retrieve all ranges from all files that were skipped by the
+ * preprocessor.
+ *
+ * The preprocessor will skip lines when they are surrounded by an
+ * if/ifdef/ifndef directive whose condition does not evaluate to true.
+ */
+CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit 
tu);
+
+/**
  * \brief Destroy the given \c CXSourceRangeList.
  */
 CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=279076&r1=279075&r2=279076&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 18 10:43:55 2016
@@ -7773,6 +7773,33 @@ CXSourceRangeList *clang_getSkippedRange
   return skipped;
 }
 
+CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) {
+  CXSourceRangeList *skipped = new CXSourceRangeList;
+  skipped->count = 0;
+  skipped->ranges = nullptr;
+
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return skipped;
+  }
+
+  ASTUnit *astUnit = cxtu::getASTUnit(TU);
+  PreprocessingRecord *ppRec = 
astUnit->getPreprocessor().getPreprocessingRecord();
+  if (!ppRec)
+return skipped;
+
+  ASTContext &Ctx = astUnit->getASTContext();
+
+  const std::vector &SkippedRanges = ppRec->getSkippedRanges();
+
+  skipped->count = SkippedRanges.size();
+  skipped->ranges = new CXSourceRange[skipped->count];
+  for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
+skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]);
+
+  return skipped;
+}
+
 void clang_disposeSourceRangeList(CXSourceRangeList *ranges) {
   if (ranges) {
 delete[] ranges->ranges;

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=279076&r1=279075&r2=279076&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 10:43:55 2016
@@ -14,6 +14,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
 #include 
+#include 
+#include 
+#include 
 #include 
 #define DEBUG_TYPE "libclang-test"
 
@@ -349,21 +352,25 @@ TEST(libclang, ModuleMapDescriptor) {
   clang_ModuleMapDescriptor_dispose(MMD);
 }
 
-class LibclangReparseTest : public ::testing::Test {
+class LibclangParseTest : public ::testing::Test {
   std::set Files;
+  typedef std::unique_ptr fixed_addr_string;
+  std::map UnsavedFileContents;
 public:
   std::string TestDir;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
+  std::vector UnsavedFiles;
 
   void SetUp() override {
 llvm::SmallString<256> Dir;
 ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir));
 TestDir = Dir.str();
 TUFlags = CXTranslationUnit_DetailedPreprocessingRecord |
-  clang_defaultEditingTranslationUnitOptions();
+  clang_defaultEditingTranslationUnitOptions();
 Index = clang_createIndex(0, 0);
+ClangTU = nullptr;
   }
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
@@ -384,6 +391,77 @@ public:
 OS << Contents;
 assert(OS.good());
   }
+  void MapUnsavedFile(std::string Filename, const std::string &Contents) {
+if (!llvm::sys::path::is_absolute(Filename)) {
+  llvm::SmallString<256> Path(TestDir);
+  llvm::sys::path::append(Path, Filename);
+  Filename = Path.str();
+}
+auto it = UnsavedFileContents.emplace(
+fixed_addr_string(new std::string(Filename)),
+   

Re: [PATCH] D20132: [libclang] Add clang_getAllSkippedRanges function

2016-08-18 Thread Cameron via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279076: [libclang] Add clang_getAllSkippedRanges function 
(authored by cameron314).

Changed prior to commit:
  https://reviews.llvm.org/D20132?vs=56964&id=68548#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D20132

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/unittests/libclang/LibclangTest.cpp

Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -7773,6 +7773,33 @@
   return skipped;
 }
 
+CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) {
+  CXSourceRangeList *skipped = new CXSourceRangeList;
+  skipped->count = 0;
+  skipped->ranges = nullptr;
+
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return skipped;
+  }
+
+  ASTUnit *astUnit = cxtu::getASTUnit(TU);
+  PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord();
+  if (!ppRec)
+return skipped;
+
+  ASTContext &Ctx = astUnit->getASTContext();
+
+  const std::vector &SkippedRanges = ppRec->getSkippedRanges();
+
+  skipped->count = SkippedRanges.size();
+  skipped->ranges = new CXSourceRange[skipped->count];
+  for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
+skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]);
+
+  return skipped;
+}
+
 void clang_disposeSourceRangeList(CXSourceRangeList *ranges) {
   if (ranges) {
 delete[] ranges->ranges;
Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -627,6 +627,15 @@
  CXFile file);
 
 /**
+ * \brief Retrieve all ranges from all files that were skipped by the
+ * preprocessor.
+ *
+ * The preprocessor will skip lines when they are surrounded by an
+ * if/ifdef/ifndef directive whose condition does not evaluate to true.
+ */
+CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit tu);
+
+/**
  * \brief Destroy the given \c CXSourceRangeList.
  */
 CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
Index: cfe/trunk/unittests/libclang/LibclangTest.cpp
===
--- cfe/trunk/unittests/libclang/LibclangTest.cpp
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp
@@ -14,6 +14,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
 #include 
+#include 
+#include 
+#include 
 #include 
 #define DEBUG_TYPE "libclang-test"
 
@@ -349,21 +352,25 @@
   clang_ModuleMapDescriptor_dispose(MMD);
 }
 
-class LibclangReparseTest : public ::testing::Test {
+class LibclangParseTest : public ::testing::Test {
   std::set Files;
+  typedef std::unique_ptr fixed_addr_string;
+  std::map UnsavedFileContents;
 public:
   std::string TestDir;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
+  std::vector UnsavedFiles;
 
   void SetUp() override {
 llvm::SmallString<256> Dir;
 ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir));
 TestDir = Dir.str();
 TUFlags = CXTranslationUnit_DetailedPreprocessingRecord |
-  clang_defaultEditingTranslationUnitOptions();
+  clang_defaultEditingTranslationUnitOptions();
 Index = clang_createIndex(0, 0);
+ClangTU = nullptr;
   }
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
@@ -384,6 +391,77 @@
 OS << Contents;
 assert(OS.good());
   }
+  void MapUnsavedFile(std::string Filename, const std::string &Contents) {
+if (!llvm::sys::path::is_absolute(Filename)) {
+  llvm::SmallString<256> Path(TestDir);
+  llvm::sys::path::append(Path, Filename);
+  Filename = Path.str();
+}
+auto it = UnsavedFileContents.emplace(
+fixed_addr_string(new std::string(Filename)),
+fixed_addr_string(new std::string(Contents)));
+UnsavedFiles.push_back({
+it.first->first->c_str(),   // filename
+it.first->second->c_str(),  // contents
+it.first->second->size()// length
+});
+  }
+  template
+  void Traverse(const F &TraversalFunctor) {
+CXCursor TuCursor = clang_getTranslationUnitCursor(ClangTU);
+std::reference_wrapper FunctorRef = std::cref(TraversalFunctor);
+clang_visitChildren(TuCursor,
+&TraverseStateless>,
+&FunctorRef);
+  }
+private:
+  template
+  static CXChildVisitResult TraverseStateless(CXCursor cx, CXCursor parent,
+  CXClientData data) {
+TState *State = static_cast(data);
+return State->get()(cx, parent);
+  }
+};
+
+TEST_F(LibclangParseTest, AllSkippedRanges) {
+  std::string Header = "header.h", Main = "main.cpp";
+  WriteFile(Header,
+"#ifdef MANGOS\n"
+"printf(\"mmm\");\n"
+"#endif")

Re: [PATCH] D21959: [X86] Add xgetbv xsetbv intrinsics

2016-08-18 Thread Reid Kleckner via cfe-commits
rnk added a comment.

Hm, resending my comments because it doesn't appear to work from email. I swear 
it used to...

In https://reviews.llvm.org/D21959#519179, @guyblank wrote:

> Still, __XSAVE__ should have been defined when compiling for a target that 
> supports the feature.


That's not how MSVC intrinsics (or icc intrinsics, right?) are supposed to 
work, though. In MSVC, all intrinsics are always available, regardless of 
subtarget options. Unfortunately, Clang is not very compatible in this area, 
because of the way that we map the vector intrinsics to our generic vector IR 
and then codegen that. In this case, we don't have any generic instruction to 
map to, so I think we should try to be compatible here.

> But anyway, the xsaveintrin.h is quite small so always including it shouldn't 
> be an issue.

>  Are you ok with me removing the #if just for this header file, or would you 
> like to wait for Nico?


I think removing the _MSC_VER check is probably OK, but will the new LLVM 
intrinsic you added generate correct code when the xsave feature is disabled, 
as I expect it is in Chromium?


Repository:
  rL LLVM

https://reviews.llvm.org/D21959



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


Re: r279035 - [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds

2016-08-18 Thread Richard Smith via cfe-commits
This doesn't work at all, llvm-config.h does not provide the relevant
configuration macros.

On 17 Aug 2016 11:56 p.m., "Vedant Kumar via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

> Author: vedantk
> Date: Thu Aug 18 01:43:07 2016
> New Revision: 279035
>
> URL: http://llvm.org/viewvc/llvm-project?rev=279035&view=rev
> Log:
> [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds
>
> llvm/Config/config.h has intentionally been excluded from llvm
> installations (see: llvm/CMakeLists.txt). Un-break out-of-tree builds
> post-r278882 by switching to llvm-config.h, which is exported.
>
> Suggested by Will Dietz!
>
> Modified:
> cfe/trunk/tools/driver/cc1_main.cpp
>
> Modified: cfe/trunk/tools/driver/cc1_main.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/
> driver/cc1_main.cpp?rev=279035&r1=279034&r2=279035&view=diff
> 
> ==
> --- cfe/trunk/tools/driver/cc1_main.cpp (original)
> +++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 01:43:07 2016
> @@ -25,7 +25,7 @@
>  #include "clang/Frontend/Utils.h"
>  #include "clang/FrontendTool/Utils.h"
>  #include "llvm/ADT/Statistic.h"
> -#include "llvm/Config/config.h"
> +#include "llvm/Config/llvm-config.h"
>  #include "llvm/LinkAllPasses.h"
>  #include "llvm/Option/ArgList.h"
>  #include "llvm/Option/OptTable.h"
>
>
> ___
> 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


r279085 - [libclang] Fixed signed/unsigned comparison warning introduced in my revision r279076

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 11:25:42 2016
New Revision: 279085

URL: http://llvm.org/viewvc/llvm-project?rev=279085&view=rev
Log:
[libclang] Fixed signed/unsigned comparison warning introduced in my revision 
r279076

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=279085&r1=279084&r2=279085&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 11:25:42 2016
@@ -439,7 +439,7 @@ TEST_F(LibclangParseTest, AllSkippedRang
nullptr, 0, TUFlags);
 
   CXSourceRangeList *Ranges = clang_getAllSkippedRanges(ClangTU);
-  EXPECT_EQ(2, Ranges->count);
+  EXPECT_EQ(2u, Ranges->count);
   
   CXSourceLocation cxl;
   unsigned line;


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


Re: r279035 - [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds

2016-08-18 Thread Reid Kleckner via cfe-commits
Clang isn't allowed to use LLVM's config.h, though, specifically to support
the standalone build.

You can either create equivalent LLVM_ prefixed macros in
llvm-config.h.cmake, or repeat the checks and define the same macros in
clang/include/clang/Config/config.h.cmake.

On Thu, Aug 18, 2016 at 9:25 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> This doesn't work at all, llvm-config.h does not provide the relevant
> configuration macros.
>
> On 17 Aug 2016 11:56 p.m., "Vedant Kumar via cfe-commits" <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: vedantk
>> Date: Thu Aug 18 01:43:07 2016
>> New Revision: 279035
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=279035&view=rev
>> Log:
>> [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds
>>
>> llvm/Config/config.h has intentionally been excluded from llvm
>> installations (see: llvm/CMakeLists.txt). Un-break out-of-tree builds
>> post-r278882 by switching to llvm-config.h, which is exported.
>>
>> Suggested by Will Dietz!
>>
>> Modified:
>> cfe/trunk/tools/driver/cc1_main.cpp
>>
>> Modified: cfe/trunk/tools/driver/cc1_main.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/
>> cc1_main.cpp?rev=279035&r1=279034&r2=279035&view=diff
>> 
>> ==
>> --- cfe/trunk/tools/driver/cc1_main.cpp (original)
>> +++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 01:43:07 2016
>> @@ -25,7 +25,7 @@
>>  #include "clang/Frontend/Utils.h"
>>  #include "clang/FrontendTool/Utils.h"
>>  #include "llvm/ADT/Statistic.h"
>> -#include "llvm/Config/config.h"
>> +#include "llvm/Config/llvm-config.h"
>>  #include "llvm/LinkAllPasses.h"
>>  #include "llvm/Option/ArgList.h"
>>  #include "llvm/Option/OptTable.h"
>>
>>
>> ___
>> 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


LLVM buildmaster will be restarted tonight

2016-08-18 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 6 PM Pacific time
today.

Thanks

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


Re: r279076 - [libclang] Add clang_getAllSkippedRanges function

2016-08-18 Thread H.J. Lu via cfe-commits
On Thu, Aug 18, 2016 at 8:43 AM, Cameron Desrochers via cfe-commits
 wrote:
> Author: cameron314
> Date: Thu Aug 18 10:43:55 2016
> New Revision: 279076
>
> URL: http://llvm.org/viewvc/llvm-project?rev=279076&view=rev
> Log:
> [libclang] Add clang_getAllSkippedRanges function
>
> This complements the clang_getSkippedRanges function which returns skipped 
> ranges filtered by a specific file.
>
> This function is useful when all the ranges are desired (and a lot more 
> efficient than the equivalent of asking for the ranges file by file, since 
> the implementation of clang_getSkippedRanges iterates over all ranges anyway).
>
> Differential Revision: https://reviews.llvm.org/D20132
>
> Modified:
> cfe/trunk/include/clang-c/Index.h
> cfe/trunk/tools/libclang/CIndex.cpp
> cfe/trunk/unittests/libclang/LibclangTest.cpp
>

libclangTests fails for me on Linux:

cd 
/export/build/gnu/llvm-clang/build-x86_64-linux/tools/clang/unittests/libclang
&& /usr/bin/cmake -E cmake_link_script
CMakeFiles/libclangTests.dir/link.txt --verbose=1
/usr/bin/g++  -m64   -fPIC -fvisibility-inlines-hidden -Wall -W
-Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wno-missing-field-initializers -pedantic -Wno-long-long
-Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment
-Werror=date-time -std=c++11 -ffunction-sections -fdata-sections
-fno-common -Woverloaded-virtual -fno-strict-aliasing -O2 -g -DNDEBUG
 -Wl,-allow-shlib-undefined  -Wl,-O3 -Wl,--gc-sections
CMakeFiles/libclangTests.dir/LibclangTest.cpp.o  -o libclangTests
../../../../lib/libLLVMSupport.a -lpthread
../../../../lib/libgtest_main.a ../../../../lib/libgtest.a -lpthread
../../../../lib/libclang.so.4.0 ../../../../lib/libLLVMSupport.a -lrt
-ldl -ltinfo -lpthread -lz -lm -lpthread -Wl,-rpath,"\$ORIGIN/../lib"
CMakeFiles/libclangTests.dir/LibclangTest.cpp.o: In function
`LibclangParseTest_AllSkippedRanges_Test::TestBody()':
/export/gnu/import/git/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:441:
undefined reference to `clang_getAllSkippedRanges'
collect2: error: ld returned 1 exit status
tools/clang/unittests/libclang/CMakeFiles/libclangTests.dir/build.make:99:
recipe for target 'tools/clang/unittests/libclang/libclangTests'
failed
gmake[4]: *** [tools/clang/unittests/libclang/libclangTests] Error 1
gmake[4]: Leaving directory '/export/build/gnu/llvm-clang/build-x86_64-linux'
CMakeFiles/Makefile2:32037: recipe for target
'tools/clang/unittests/libclang/CMakeFiles/libclangTests.dir/all'
failed

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


Re: Record ranges skipped by the preprocessor and expose them with libclang.

2016-08-18 Thread Will Dietz via cfe-commits
(Sending again, somehow the uiuc.edu mailing list address was in my
reply-all! Sorry for the duplicates :))

This breaks things for me, I think an entry in 'libclang.exports' is needed
for clang_getAllSkippedRanges ?

If that sounds right, can someone commit the fix?

Thanks! :)

~Will, he-who-builds-from-trunk-more-often-than-he-should

On Thu, Aug 18, 2016 at 11:48 AM Will Dietz  wrote:

>
>
> On Thu, Dec 5, 2013 at 2:25 AM Argyrios Kyrtzidis 
> wrote:
>
>>
>> On Nov 15, 2013, at 7:57 AM, Erik Verbruggen 
>> wrote:
>>
>> > Hi Argyrios,
>> >
>> > New patch attached. Your PCH comments do make sense, and I'll have to
>> ponder about it a bit for my integration :)
>>
>> Committed in r196487, thanks!
>>
>> >
>> > Cheers,
>> > Erik.
>> >
>> > Ps: sorry about not including the comments from your mail, but my
>> Mavericks upgrade managed to hose Mail.app or the index or something.
>> >
>> >
>> <0001-Record-ranges-skipped-by-the-preprocessor-and-expose.patch>___
>> > cfe-commits mailing list
>> > cfe-comm...@cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>> ___
>> cfe-commits mailing list
>> cfe-comm...@cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r279035 - [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds

2016-08-18 Thread Richard Smith via cfe-commits
On 18 Aug 2016 9:36 a.m., "Reid Kleckner"  wrote:
>
> Clang isn't allowed to use LLVM's config.h, though, specifically to
support the standalone build.
>
> You can either create equivalent LLVM_ prefixed macros in
llvm-config.h.cmake, or repeat the checks and define the same macros in
clang/include/clang/Config/config.h.cmake.

Perhaps the best thing would be to move this functionality into LLVM and
just call it from clang.

> On Thu, Aug 18, 2016 at 9:25 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:
>>
>> This doesn't work at all, llvm-config.h does not provide the relevant
configuration macros.
>>
>>
>> On 17 Aug 2016 11:56 p.m., "Vedant Kumar via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:
>>>
>>> Author: vedantk
>>> Date: Thu Aug 18 01:43:07 2016
>>> New Revision: 279035
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=279035&view=rev
>>> Log:
>>> [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds
>>>
>>> llvm/Config/config.h has intentionally been excluded from llvm
>>> installations (see: llvm/CMakeLists.txt). Un-break out-of-tree builds
>>> post-r278882 by switching to llvm-config.h, which is exported.
>>>
>>> Suggested by Will Dietz!
>>>
>>> Modified:
>>> cfe/trunk/tools/driver/cc1_main.cpp
>>>
>>> Modified: cfe/trunk/tools/driver/cc1_main.cpp
>>> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=279035&r1=279034&r2=279035&view=diff
>>>
==
>>> --- cfe/trunk/tools/driver/cc1_main.cpp (original)
>>> +++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 01:43:07 2016
>>> @@ -25,7 +25,7 @@
>>>  #include "clang/Frontend/Utils.h"
>>>  #include "clang/FrontendTool/Utils.h"
>>>  #include "llvm/ADT/Statistic.h"
>>> -#include "llvm/Config/config.h"
>>> +#include "llvm/Config/llvm-config.h"
>>>  #include "llvm/LinkAllPasses.h"
>>>  #include "llvm/Option/ArgList.h"
>>>  #include "llvm/Option/OptTable.h"
>>>
>>>
>>> ___
>>> 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


Re: Record ranges skipped by the preprocessor and expose them with libclang.

2016-08-18 Thread Cameron via cfe-commits
Ah, is that why! My fault, sorry. I couldn't figure out why it wouldn't
link on the build machines when it worked fine for me locally (on
Windows)...
Thank you, I will fix this shortly.

On Thu, Aug 18, 2016 at 12:52 PM, Will Dietz via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> (Sending again, somehow the uiuc.edu mailing list address was in my
> reply-all! Sorry for the duplicates :))
>
> This breaks things for me, I think an entry in 'libclang.exports' is
> needed for clang_getAllSkippedRanges ?
>
> If that sounds right, can someone commit the fix?
>
> Thanks! :)
>
> ~Will, he-who-builds-from-trunk-more-often-than-he-should
>
> On Thu, Aug 18, 2016 at 11:48 AM Will Dietz  wrote:
>
>>
>>
>> On Thu, Dec 5, 2013 at 2:25 AM Argyrios Kyrtzidis 
>> wrote:
>>
>>>
>>> On Nov 15, 2013, at 7:57 AM, Erik Verbruggen 
>>> wrote:
>>>
>>> > Hi Argyrios,
>>> >
>>> > New patch attached. Your PCH comments do make sense, and I'll have to
>>> ponder about it a bit for my integration :)
>>>
>>> Committed in r196487, thanks!
>>>
>>> >
>>> > Cheers,
>>> > Erik.
>>> >
>>> > Ps: sorry about not including the comments from your mail, but my
>>> Mavericks upgrade managed to hose Mail.app or the index or something.
>>> >
>>> > <0001-Record-ranges-skipped-by-the-preprocessor-and-
>>> expose.patch>___
>>> > cfe-commits mailing list
>>> > cfe-comm...@cs.uiuc.edu
>>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-comm...@cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/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


Re: [PATCH] D23316: [analyzer] Fixed the false-positives caused by macro generated code.

2016-08-18 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 68556.
teemperor added a comment.

- Added more documentation to the CloneSignature::Complexity field.
- Macros now have a complexity value of 1 + sum(ChildComplexityValues).
- Tests should be less cryptic now.


https://reviews.llvm.org/D23316

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  test/Analysis/copypaste/macro-complexity.cpp
  test/Analysis/copypaste/macros.cpp

Index: test/Analysis/copypaste/macros.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/macros.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// Tests that macros and non-macro clones aren't mixed into the same hash
+// group. This is currently necessary as all clones in a hash group need
+// to have the same complexity value. Macros have smaller complexity values
+// and need to be in their own hash group.
+
+int foo(int a) { // expected-warning{{Detected code clone.}}
+  a = a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+int fooClone(int a) { // expected-note{{Related code clone is here.}}
+  a = a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+// Below is the same AST as above but this time generated with macros. The
+// clones below should land in their own hash group for the reasons given above.
+
+#define ASSIGN(T, V) T = T + V
+
+int macro(int a) { // expected-warning{{Detected code clone.}}
+  ASSIGN(a, 1);
+  ASSIGN(a, 1 / 1);
+  ASSIGN(a, 1 + 1 + 1);
+  ASSIGN(a, 1 - 1 + 1 + 1);
+  ASSIGN(a, 1 * 1 + 1 + 1 + 1);
+  ASSIGN(a, 1 / 1 + 1 + 1 + 1);
+  return a;
+}
+
+int macroClone(int a) { // expected-note{{Related code clone is here.}}
+  ASSIGN(a, 1);
+  ASSIGN(a, 1 / 1);
+  ASSIGN(a, 1 + 1 + 1);
+  ASSIGN(a, 1 - 1 + 1 + 1);
+  ASSIGN(a, 1 * 1 + 1 + 1 + 1);
+  ASSIGN(a, 1 / 1 + 1 + 1 + 1);
+  return a;
+}
Index: test/Analysis/copypaste/macro-complexity.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/macro-complexity.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=10 -verify %s
+
+// Tests that the complexity value of a macro expansion is about the same as
+// the complexity value of a normal function call and the the macro body doesn't
+// influence the complexity. See the CloneSignature class in CloneDetection.h
+// for more information about complexity values of clones.
+
+#define MACRO_FOO(a, b) a > b ? -a * a : -b * b;
+
+// First, manually apply MACRO_FOO and see if the code gets detected as a clone.
+// This confirms that with the current configuration the macro body would be
+// considered large enough to pass the MinimumCloneComplexity constraint.
+
+int manualMacro(int a, int b) { // expected-warning{{Detected code clone.}}
+  return a > b ? -a * a : -b * b;
+}
+
+int manualMacroClone(int a, int b) { // expected-note{{Related code clone is here.}}
+  return a > b ? -a * a : -b * b;
+}
+
+// Now we actually use the macro to generate the same AST as above. They
+// shouldn't be reported because the macros only slighly increase the complexity
+// value and the resulting code will never pass the MinimumCloneComplexity
+// constraint.
+
+int macro(int a, int b) {
+  return MACRO_FOO(a, b);
+}
+
+int macroClone(int a, int b) {
+  return MACRO_FOO(a, b);
+}
+
+// So far we only tested that macros increase the complexity by a lesser amount
+// than normal code. We also need to be sure this amount is not zero because
+// we otherwise macro code would be 'invisible' for the CloneDetector.
+// This tests that it is possible to increase the reach the minimum complexity
+// by only using macros. This is only possible if the complexity value is bigger
+// than zero.
+
+#define NEG(A) -(A)
+
+int nestedMacros() { // expected-warning{{Detected code clone.}}
+  return NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(1));
+}
+
+int nestedMacrosClone() { // expected-note{{Related code clone is here.}}
+  return NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(1));
+}
Index: lib/Analysis/CloneDetection.cpp
===
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -17,7 +17,9 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 
@@ -175,6 +177,38 @@
 };
 }
 
+/// \brief Prints the macro name that contains the given SourceLocation into
+///the given raw_string_ostream.
+st

r279092 - [libclang] Added missing entry for newly introduced 'clang_getAllSkippedRanges' to libclang.exports

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 12:18:03 2016
New Revision: 279092

URL: http://llvm.org/viewvc/llvm-project?rev=279092&view=rev
Log:
[libclang] Added missing entry for newly introduced 'clang_getAllSkippedRanges' 
to libclang.exports

Modified:
cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=279092&r1=279091&r2=279092&view=diff
==
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Thu Aug 18 12:18:03 2016
@@ -142,6 +142,7 @@ clang_findReferencesInFile
 clang_findReferencesInFileWithBlock
 clang_formatDiagnostic
 clang_free
+clang_getAllSkippedRanges
 clang_getArgType
 clang_getArrayElementType
 clang_getArraySize


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


Re: [PATCH] D23316: [analyzer] Fixed the false-positives caused by macro generated code.

2016-08-18 Thread Raphael Isemann via cfe-commits
teemperor marked 10 inline comments as done.


Comment at: lib/Analysis/CloneDetection.cpp:436
@@ +435,3 @@
+if (IsInMacro) {
+  Signature.Complexity = 0;
+}

NoQ wrote:
> omtcyfz wrote:
> > omtcyfz wrote:
> > > omtcyfz wrote:
> > > > NoQ wrote:
> > > > > omtcyfz wrote:
> > > > > > Do I understand correctly that a code generated by a macro doesn't 
> > > > > > affect "complexity" at all then?
> > > > > > 
> > > > > > ```
> > > > > > TEST_F(QueryParserTest, Complete) {
> > > > > >   std::vector Comps =
> > > > > >   QueryParser::complete("", 0, QS);
> > > > > >   ASSERT_EQ(6u, Comps.size());
> > > > > >   EXPECT_EQ("help ", Comps[0].TypedText);
> > > > > >   EXPECT_EQ("help", Comps[0].DisplayText);
> > > > > >   EXPECT_EQ("let ", Comps[1].TypedText);
> > > > > >   EXPECT_EQ("let", Comps[1].DisplayText);
> > > > > >   EXPECT_EQ("match ", Comps[2].TypedText);
> > > > > >   EXPECT_EQ("match", Comps[2].DisplayText);
> > > > > >   EXPECT_EQ("set ", Comps[3].TypedText);
> > > > > >   EXPECT_EQ("set", Comps[3].DisplayText);
> > > > > >   EXPECT_EQ("unlet ", Comps[4].TypedText);
> > > > > >   EXPECT_EQ("unlet", Comps[4].DisplayText);
> > > > > >   EXPECT_EQ("quit", Comps[5].DisplayText);
> > > > > >   EXPECT_EQ("quit ", Comps[5].TypedText);
> > > > > > 
> > > > > >   Comps = QueryParser::complete("set o", 5, QS);
> > > > > >   ASSERT_EQ(1u, Comps.size());
> > > > > >   EXPECT_EQ("utput ", Comps[0].TypedText);
> > > > > >   EXPECT_EQ("output", Comps[0].DisplayText);
> > > > > > 
> > > > > >   Comps = QueryParser::complete("match while", 11, QS);
> > > > > >   ASSERT_EQ(1u, Comps.size());
> > > > > >   EXPECT_EQ("Stmt(", Comps[0].TypedText);
> > > > > >   EXPECT_EQ("Matcher whileStmt(Matcher...)",
> > > > > > Comps[0].DisplayText);
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > This is an actual piece of code from 
> > > > > > `extra/unittests/clang-query/QueryParserTest.cpp`. Yes, it is a 
> > > > > > test, but it still is a nice example of how many macros can be 
> > > > > > found in code (especially if we are talking about pure C or some 
> > > > > > weird C++).
> > > > > > 
> > > > > > Thus, I think it is reasonable to treat macro invocation as a 
> > > > > > `1`-"complexity" node.
> > > > > This "0" is not for the macro itself, but for the statements into 
> > > > > which it expands. Macro itself is not a statement. If we put "1" 
> > > > > here, it would produce a lot more complexity than you want.
> > > > > 
> > > > > That said, it's a good idea to treat every macro as a "complexity-1" 
> > > > > statement, just need to figure out how to implement that correctly :)
> > > > > 
> > > > > Perhaps scan the source range of the sequence for how many different 
> > > > > macro expansions are included, and add that number to complexity(?)
> > > > > This "0" is not for the macro itself, but for the statements into 
> > > > > which it expands. Macro itself is not a statement. If we put "1" 
> > > > > here, it would produce a lot more complexity than you want.
> > > > 
> > > > Sure, I understand that, this is why I didn't suggest putting `1` there.
> > > > 
> > > > > Perhaps scan the source range of the sequence for how many different 
> > > > > macro expansions are included, and add that number to complexity(?)
> > > > 
> > > > Yes, this is exactly the solution that would work. Since macros aren't 
> > > > in the AST we'd need to get through SourceRange anyway.
> > > Though, it has to be optimized in order to prevent parsing a 
> > > SourceLocation multiple times.
> > *visiting each SourceLocation
> Yeah, as a rough approximation we could count macro expansions within the 
> current statement's children...
I'm now checking all expanded macros of the start/end locations. This should 
handle everything if I see that correctly (beside empty non-function macros 
which I marked as false-positives - not sure how we best handle them).


Comment at: test/Analysis/copypaste/macros.cpp:11
@@ +10,3 @@
+int max(int a, int b) { // expected-warning{{Detected code clone.}}
+  return a > b ? a : b;
+}

v.g.vassilev wrote:
> Wouldn't it be a good idea to have a fixit hint, saying "Did you mean to use 
> ABS(a,b)". If the suggestion is applied, it would make the code more 
> consistent, however it would encourage using preprocessor tricks (which is 
> not always considered as good practice).
I don't think detecting clones between macro definitions and normal code is 
easily possible. Doing the same for functions however is certainly possible 
(i.e. "did you meant to call `max(a, b)`). I added that to the open points list.


https://reviews.llvm.org/D23316



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


Re: [PATCH] D23316: [analyzer] Fixed the false-positives caused by macro generated code.

2016-08-18 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 68568.
teemperor marked 2 inline comments as done.
teemperor added a comment.

- Added false-positives note for empty macros to the test suite.


https://reviews.llvm.org/D23316

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  test/Analysis/copypaste/macro-complexity.cpp
  test/Analysis/copypaste/macros.cpp

Index: test/Analysis/copypaste/macros.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/macros.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// Tests that macros and non-macro clones aren't mixed into the same hash
+// group. This is currently necessary as all clones in a hash group need
+// to have the same complexity value. Macros have smaller complexity values
+// and need to be in their own hash group.
+
+int foo(int a) { // expected-warning{{Detected code clone.}}
+  a = a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+int fooClone(int a) { // expected-note{{Related code clone is here.}}
+  a = a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+// Below is the same AST as above but this time generated with macros. The
+// clones below should land in their own hash group for the reasons given above.
+
+#define ASSIGN(T, V) T = T + V
+
+int macro(int a) { // expected-warning{{Detected code clone.}}
+  ASSIGN(a, 1);
+  ASSIGN(a, 1 / 1);
+  ASSIGN(a, 1 + 1 + 1);
+  ASSIGN(a, 1 - 1 + 1 + 1);
+  ASSIGN(a, 1 * 1 + 1 + 1 + 1);
+  ASSIGN(a, 1 / 1 + 1 + 1 + 1);
+  return a;
+}
+
+int macroClone(int a) { // expected-note{{Related code clone is here.}}
+  ASSIGN(a, 1);
+  ASSIGN(a, 1 / 1);
+  ASSIGN(a, 1 + 1 + 1);
+  ASSIGN(a, 1 - 1 + 1 + 1);
+  ASSIGN(a, 1 * 1 + 1 + 1 + 1);
+  ASSIGN(a, 1 / 1 + 1 + 1 + 1);
+  return a;
+}
+
+// FIXME: Macros with empty definitions in the AST are currently ignored.
+
+#define EMPTY
+
+int fooFalsePositiveClone(int a) { // expected-note{{Related code clone is here.}}
+  a = EMPTY a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+
Index: test/Analysis/copypaste/macro-complexity.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/macro-complexity.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=10 -verify %s
+
+// Tests that the complexity value of a macro expansion is about the same as
+// the complexity value of a normal function call and the the macro body doesn't
+// influence the complexity. See the CloneSignature class in CloneDetection.h
+// for more information about complexity values of clones.
+
+#define MACRO_FOO(a, b) a > b ? -a * a : -b * b;
+
+// First, manually apply MACRO_FOO and see if the code gets detected as a clone.
+// This confirms that with the current configuration the macro body would be
+// considered large enough to pass the MinimumCloneComplexity constraint.
+
+int manualMacro(int a, int b) { // expected-warning{{Detected code clone.}}
+  return a > b ? -a * a : -b * b;
+}
+
+int manualMacroClone(int a, int b) { // expected-note{{Related code clone is here.}}
+  return a > b ? -a * a : -b * b;
+}
+
+// Now we actually use the macro to generate the same AST as above. They
+// shouldn't be reported because the macros only slighly increase the complexity
+// value and the resulting code will never pass the MinimumCloneComplexity
+// constraint.
+
+int macro(int a, int b) {
+  return MACRO_FOO(a, b);
+}
+
+int macroClone(int a, int b) {
+  return MACRO_FOO(a, b);
+}
+
+// So far we only tested that macros increase the complexity by a lesser amount
+// than normal code. We also need to be sure this amount is not zero because
+// we otherwise macro code would be 'invisible' for the CloneDetector.
+// This tests that it is possible to increase the reach the minimum complexity
+// by only using macros. This is only possible if the complexity value is bigger
+// than zero.
+
+#define NEG(A) -(A)
+
+int nestedMacros() { // expected-warning{{Detected code clone.}}
+  return NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(1));
+}
+
+int nestedMacrosClone() { // expected-note{{Related code clone is here.}}
+  return NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(1));
+}
Index: lib/Analysis/CloneDetection.cpp
===
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -17,7 +17,9 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtVisitor.h"
+#in

Re: [PATCH] D23125: Modules: add command line option to support loading prebuilt modules on demand, without parsing any module map

2016-08-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279096: Module: add -fprebuilt-module-path to support 
loading prebuilt modules. (authored by mren).

Changed prior to commit:
  https://reviews.llvm.org/D23125?vs=68456&id=68570#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23125

Files:
  cfe/trunk/docs/Modules.rst
  cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Lex/HeaderSearch.h
  cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
  cfe/trunk/include/clang/Serialization/Module.h
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Frontend/ASTUnit.cpp
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Frontend/FrontendActions.cpp
  cfe/trunk/lib/Lex/HeaderSearch.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
  cfe/trunk/lib/Serialization/ModuleManager.cpp
  cfe/trunk/test/Driver/modules.m
  cfe/trunk/test/Modules/Inputs/prebuilt-module/a.h
  cfe/trunk/test/Modules/Inputs/prebuilt-module/module.modulemap
  cfe/trunk/test/Modules/prebuilt-module.m

Index: cfe/trunk/docs/Modules.rst
===
--- cfe/trunk/docs/Modules.rst
+++ cfe/trunk/docs/Modules.rst
@@ -213,6 +213,9 @@
 ``-fmodule-file=``
   Load the given precompiled module file.
 
+``-fprebuilt-module-path=``
+  Specify the path to the prebuilt modules. If specified, we will look for modules in this directory for a given top-level module name. We don't need a module map for loading prebuilt modules in this directory and the compiler will not try to rebuild these modules. This can be specified multiple times.
+
 Module Semantics
 
 
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -840,6 +840,9 @@
 def fmodules_user_build_path : Separate<["-"], "fmodules-user-build-path">, Group,
   Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the module user build path">;
+def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, Group,
+  Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
+  HelpText<"Specify the prebuilt module path">;
 def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, Group,
   Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the interval (in seconds) between attempts to prune the module cache">;
Index: cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
===
--- cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
+++ cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
@@ -93,6 +93,9 @@
   /// \brief The directory used for a user build.
   std::string ModuleUserBuildPath;
 
+  /// \brief The directories used to load prebuilt module files.
+  std::vector PrebuiltModulePaths;
+
   /// The module/pch container format.
   std::string ModuleFormat;
 
@@ -201,6 +204,10 @@
   void AddVFSOverlayFile(StringRef Name) {
 VFSOverlayFiles.push_back(Name);
   }
+
+  void AddPrebuiltModulePath(StringRef Name) {
+PrebuiltModulePaths.push_back(Name);
+  }
 };
 
 } // end namespace clang
Index: cfe/trunk/include/clang/Lex/HeaderSearch.h
===
--- cfe/trunk/include/clang/Lex/HeaderSearch.h
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h
@@ -481,9 +481,12 @@
   /// \param ModuleMapPath A path that when combined with \c ModuleName
   /// uniquely identifies this module. See Module::ModuleMap.
   ///
+  /// \param UsePrebuiltPath Whether we should use the prebuilt module path.
+  ///
   /// \returns The name of the module file that corresponds to this module,
   /// or an empty string if this module does not correspond to any module file.
-  std::string getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath);
+  std::string getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath,
+bool UsePrebuiltPath);
 
   /// \brief Lookup a module Search for a module with the given name.
   ///
Index: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
@@ -94,6 +94,8 @@
   "timed out waiting to acquire lock file for module '%0'">, DefaultFatal;
 def err_module_cycle : Error<"cyclic dependency in module '%0': %1">, 
   DefaultFatal;
+def err_module_prebuilt : Error<
+  "error in loading module '%0' from prebuilt module path">, DefaultFatal;
 def note_pragma_entered_here : Note<"#pragma entered here">;  
 def note_decl_hiding_tag_type : Note<
   "%1 %0 is hidden by a non-type declaration of %0 her

r279097 - Revert "[Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds"

2016-08-18 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Thu Aug 18 12:43:02 2016
New Revision: 279097

URL: http://llvm.org/viewvc/llvm-project?rev=279097&view=rev
Log:
Revert "[Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds"

This reverts commit r279035. According to Richard Smith, llvm-config.h
does not contain the right definitions.

Modified:
cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=279097&r1=279096&r2=279097&view=diff
==
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 12:43:02 2016
@@ -25,7 +25,7 @@
 #include "clang/Frontend/Utils.h"
 #include "clang/FrontendTool/Utils.h"
 #include "llvm/ADT/Statistic.h"
-#include "llvm/Config/llvm-config.h"
+#include "llvm/Config/config.h"
 #include "llvm/LinkAllPasses.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/OptTable.h"


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


r279096 - Module: add -fprebuilt-module-path to support loading prebuilt modules.

2016-08-18 Thread Manman Ren via cfe-commits
Author: mren
Date: Thu Aug 18 12:42:15 2016
New Revision: 279096

URL: http://llvm.org/viewvc/llvm-project?rev=279096&view=rev
Log:
Module: add -fprebuilt-module-path to support loading prebuilt modules.

In this mode, there is no need to load any module map and the programmer can
simply use "@import" syntax to load the module directly from a prebuilt
module path. When loading from prebuilt module path, we don't support
rebuilding of the module files and we ignore compatible configuration
mismatches.

rdar://27290316
Differential Revision: http://reviews.llvm.org/D23125

Added:
cfe/trunk/test/Modules/Inputs/prebuilt-module/
cfe/trunk/test/Modules/Inputs/prebuilt-module/a.h
cfe/trunk/test/Modules/Inputs/prebuilt-module/module.modulemap
cfe/trunk/test/Modules/prebuilt-module.m
Modified:
cfe/trunk/docs/Modules.rst
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
cfe/trunk/include/clang/Serialization/Module.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ModuleManager.cpp
cfe/trunk/test/Driver/modules.m

Modified: cfe/trunk/docs/Modules.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Modules.rst?rev=279096&r1=279095&r2=279096&view=diff
==
--- cfe/trunk/docs/Modules.rst (original)
+++ cfe/trunk/docs/Modules.rst Thu Aug 18 12:42:15 2016
@@ -213,6 +213,9 @@ Command-line parameters
 ``-fmodule-file=``
   Load the given precompiled module file.
 
+``-fprebuilt-module-path=``
+  Specify the path to the prebuilt modules. If specified, we will look for 
modules in this directory for a given top-level module name. We don't need a 
module map for loading prebuilt modules in this directory and the compiler will 
not try to rebuild these modules. This can be specified multiple times.
+
 Module Semantics
 
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=279096&r1=279095&r2=279096&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Thu Aug 18 12:42:15 
2016
@@ -94,6 +94,8 @@ def err_module_lock_timeout : Error<
   "timed out waiting to acquire lock file for module '%0'">, DefaultFatal;
 def err_module_cycle : Error<"cyclic dependency in module '%0': %1">, 
   DefaultFatal;
+def err_module_prebuilt : Error<
+  "error in loading module '%0' from prebuilt module path">, DefaultFatal;
 def note_pragma_entered_here : Note<"#pragma entered here">;  
 def note_decl_hiding_tag_type : Note<
   "%1 %0 is hidden by a non-type declaration of %0 here">;

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=279096&r1=279095&r2=279096&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Aug 18 12:42:15 2016
@@ -840,6 +840,9 @@ def fmodules_cache_path : Joined<["-"],
 def fmodules_user_build_path : Separate<["-"], "fmodules-user-build-path">, 
Group,
   Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the module user build path">;
+def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, 
Group,
+  Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
+  HelpText<"Specify the prebuilt module path">;
 def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, 
Group,
   Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the interval (in seconds) between attempts to prune the 
module cache">;

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=279096&r1=279095&r2=279096&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Thu Aug 18 12:42:15 2016
@@ -481,9 +481,12 @@ public:
   /// \param ModuleMapPath A path that when combined with \c ModuleName
   /// uniquely identifies this module. See Module::ModuleMap.
   ///
+  /// \param UsePrebuiltPath Whether we should use the prebuilt module path.
+  ///
   /// \returns The name of the module 

Re: r279035 - [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds

2016-08-18 Thread Vedant Kumar via cfe-commits
I shouldn't have assumed that this was correct because it built.

Reverted in r279097.

vedant

> On Aug 18, 2016, at 9:25 AM, Richard Smith  wrote:
> 
> This doesn't work at all, llvm-config.h does not provide the relevant 
> configuration macros.
> 
> 
> On 17 Aug 2016 11:56 p.m., "Vedant Kumar via cfe-commits" 
>  wrote:
> Author: vedantk
> Date: Thu Aug 18 01:43:07 2016
> New Revision: 279035
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=279035&view=rev
> Log:
> [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds
> 
> llvm/Config/config.h has intentionally been excluded from llvm
> installations (see: llvm/CMakeLists.txt). Un-break out-of-tree builds
> post-r278882 by switching to llvm-config.h, which is exported.
> 
> Suggested by Will Dietz!
> 
> Modified:
> cfe/trunk/tools/driver/cc1_main.cpp
> 
> Modified: cfe/trunk/tools/driver/cc1_main.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=279035&r1=279034&r2=279035&view=diff
> ==
> --- cfe/trunk/tools/driver/cc1_main.cpp (original)
> +++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 01:43:07 2016
> @@ -25,7 +25,7 @@
>  #include "clang/Frontend/Utils.h"
>  #include "clang/FrontendTool/Utils.h"
>  #include "llvm/ADT/Statistic.h"
> -#include "llvm/Config/config.h"
> +#include "llvm/Config/llvm-config.h"
>  #include "llvm/LinkAllPasses.h"
>  #include "llvm/Option/ArgList.h"
>  #include "llvm/Option/OptTable.h"
> 
> 
> ___
> 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


Re: [PATCH] D23602: Port tools/clang-format/git-clang-format to work Python beyond 2.7

2016-08-18 Thread Vedant Kumar via cfe-commits
vsk accepted this revision.
vsk added a reviewer: vsk.
vsk added a comment.
This revision is now accepted and ready to land.

This lgtm. I haven't touched clang-format before, so it would be good to 
double-check with the code owner before committing.


Repository:
  rL LLVM

https://reviews.llvm.org/D23602



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


Re: [PATCH] D23643: [Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64

2016-08-18 Thread Akira Hatanaka via cfe-commits
ahatanak added a subscriber: ahatanak.
ahatanak added a comment.

Thanks Vedant, this also fixes the crash that occurs when -mtune=native is 
provided.

https://reviews.llvm.org/D14471.



Comment at: lib/Driver/Tools.cpp:1163
@@ -1162,3 +1162,3 @@
   // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  if ((A = Args.getLastArg(options::OPT_arch)))
 return "cyclone";

Is there a test case for this change? I don't think this was needed to pass the 
tests you added?


https://reviews.llvm.org/D23643



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


Re: [PATCH] D23602: Port tools/clang-format/git-clang-format to work Python beyond 2.7

2016-08-18 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.

Looks good.


Repository:
  rL LLVM

https://reviews.llvm.org/D23602



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


Re: [PATCH] D23643: [Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64

2016-08-18 Thread Vedant Kumar via cfe-commits
vsk added inline comments.


Comment at: lib/Driver/Tools.cpp:1163
@@ -1162,3 +1162,3 @@
   // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  if ((A = Args.getLastArg(options::OPT_arch)))
 return "cyclone";

ahatanak wrote:
> Is there a test case for this change? I don't think this was needed to pass 
> the tests you added?
Good point, I'll work up a test case.


https://reviews.llvm.org/D23643



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


Re: [PATCH] D23628: Fix unittests after windows command line parsing

2016-08-18 Thread Alexander Kornienko 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/D23628



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


r279112 - Use __has_include rather than a configure-time macro to determine if

2016-08-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 18 13:22:22 2016
New Revision: 279112

URL: http://llvm.org/viewvc/llvm-project?rev=279112&view=rev
Log:
Use __has_include rather than a configure-time macro to determine if
 is available. This should fix out-of-tree builds, at the cost
of not providing the higher rlimits to stage 1 clang when built with an old
host compiler not implementing this feature yet (bootstrap builds should be
fine, though).

Modified:
cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=279112&r1=279111&r2=279112&view=diff
==
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 13:22:22 2016
@@ -37,9 +37,14 @@
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#if HAVE_SYS_RESOURCE_H
+
+#ifdef __has_include
+#if __has_include()
+#define HAVE_RLIMITS
 #include 
 #endif
+#endif
+
 using namespace clang;
 using namespace llvm::opt;
 
@@ -69,7 +74,7 @@ void initializePollyPasses(llvm::PassReg
 }
 #endif
 
-#if HAVE_SYS_RESOURCE_H && HAVE_GETRLIMIT && HAVE_SETRLIMIT
+#ifdef HAVE_RLIMITS
 // The amount of stack we think is "sufficient". If less than this much is
 // available, we may be unable to reach our template instantiation depth
 // limit and other similar limits.


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


Re: r278882 - If possible, set the stack rlimit to at least 8MiB on cc1 startup, and work

2016-08-18 Thread Richard Smith via cfe-commits
llvm-config.h doesn't provide the necessary macros. I've applied a
different fix for out-of-tree builds in r279112.

On Wed, Aug 17, 2016 at 11:51 PM, Vedant Kumar via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Done in clang/r279035.
>
> thanks,
> vedant
>
> > On Aug 17, 2016, at 7:43 AM, Will Dietz via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > (Seems to fix the build here, FWIW.  If sounds reasonable can someone
> commit this? Thanks!)
> >
> > ~Will
> >
> > On Wed, Aug 17, 2016 at 9:39 AM Will Dietz  wrote:
> > This is the first use of "llvm/Config/config.h" in the clang tree, which
> breaks out-of-tree builds for me (since llvm's config.h isn't installed).
> >
> > Would using "llvm/Config/llvm-config.h" suffice instead? I'm trying that
> now...
> >
> > ~Will
> >
> > On Wed, Aug 17, 2016 at 8:36 AM Joerg Sonnenberger via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> > On Wed, Aug 17, 2016 at 01:05:08AM -, Richard Smith via cfe-commits
> wrote:
> > > Author: rsmith
> > > Date: Tue Aug 16 20:05:07 2016
> > > New Revision: 278882
> > >
> > > URL: http://llvm.org/viewvc/llvm-project?rev=278882&view=rev
> > > Log:
> > > If possible, set the stack rlimit to at least 8MiB on cc1 startup, and
> work
> > > around a Linux kernel bug where the actual amount of available stack
> may be a
> > > *lot* lower than the rlimit.
> >
> > Can you please restrict this to Linux? I'm quite opposed to overriding
> > system default limits, they exist for a reason.
> >
> > Joerg
> > ___
> > 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
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r278882 - If possible, set the stack rlimit to at least 8MiB on cc1 startup, and work

2016-08-18 Thread Richard Smith via cfe-commits
On Wed, Aug 17, 2016 at 6:35 AM, Joerg Sonnenberger via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Wed, Aug 17, 2016 at 01:05:08AM -, Richard Smith via cfe-commits
> wrote:
> > Author: rsmith
> > Date: Tue Aug 16 20:05:07 2016
> > New Revision: 278882
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=278882&view=rev
> > Log:
> > If possible, set the stack rlimit to at least 8MiB on cc1 startup, and
> work
> > around a Linux kernel bug where the actual amount of available stack may
> be a
> > *lot* lower than the rlimit.
>
> Can you please restrict this to Linux? I'm quite opposed to overriding
> system default limits, they exist for a reason.


No, that wouldn't make any sense. It's not up to the operating system how
an application decides to allocate memory (on the heap versus on the
stack), and Clang's stack usage isn't going to be significantly lower on
other kernels. If some BSD kernel's VM is unable to cope with this, we
could spawn a thread with a suitable amount of stack space instead.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23643: [Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64

2016-08-18 Thread Vedant Kumar via cfe-commits
vsk added inline comments.


Comment at: lib/Driver/Tools.cpp:1163
@@ -1162,3 +1162,3 @@
   // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  if ((A = Args.getLastArg(options::OPT_arch)))
 return "cyclone";

vsk wrote:
> ahatanak wrote:
> > Is there a test case for this change? I don't think this was needed to pass 
> > the tests you added?
> Good point, I'll work up a test case.
Actually, none of the callers of `getAArch64TargetCPU' fail when CPU="cyclone" 
(afaict).

Do you have a suggestion for how I can test this? I made the change here to 
make the function's contract more consistent, but can leave it out if you 
object.


https://reviews.llvm.org/D23643



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


[PATCH] D23684: Resolve ambiguity in a declaration if global nested name specifier is used

2016-08-18 Thread Serge Pavlov via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: rsmith, doug.gregor.
sepavloff added a subscriber: cfe-commits.

If a declaration references a function from global namespace by its
qualified name and if that function return type is a class or enum, there
is possible ambiguity. The declaration:
```
friend A::B::C();
```
may be considered as a declaration of a function `::C()` that returns
`A::B`, or a function `::B::C()` that returns `A`.

With this change when the compiler sees 'A::B' while parsing decl-spec, it
tries to find `B` within 'A'. If it finds, 'A::B' is treated as a part of
qualified name. If it doesn't and the current declaration declares a
function, '::B' is assumed to be a part of declarator. For non-function
declarations 'B' can be searched for in the global namespace to improve
diagnostics.

This changes fixes https://llvm.org/bugs/show_bug.cgi?id=28422.

https://reviews.llvm.org/D23684

Files:
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/Parser.cpp
  lib/Parse/RAIIObjectsForParser.h
  lib/Sema/SemaCXXScopeSpec.cpp
  lib/Sema/TreeTransform.h
  test/CXX/drs/dr1xx.cpp
  test/CXX/drs/dr2xx.cpp
  test/Parser/cxx-decl.cpp
  test/SemaCXX/nested-name-spec2.cpp
  test/SemaCXX/pr18284-crash-on-invalid.cpp
  test/SemaCXX/typo-correction.cpp

Index: test/SemaCXX/typo-correction.cpp
===
--- test/SemaCXX/typo-correction.cpp
+++ test/SemaCXX/typo-correction.cpp
@@ -478,22 +478,17 @@
 }
 }
 
-namespace PR18213 {  // expected-note {{'PR18213' declared here}}
+namespace PR18213 {
 struct WrapperInfo {
   int i;
 };
 
 template  struct Wrappable {
   static WrapperInfo kWrapperInfo;
 };
 
-// Note the space before "::PR18213" is intended and needed, as it highlights
-// the actual typo, which is the leading "::".
-// TODO: Suggest removing the "::" from "::PR18213" (the right correction)
-// instead of incorrectly suggesting dropping "PR18213::WrapperInfo::".
 template <>
-PR18213::WrapperInfo ::PR18213::Wrappable::kWrapperInfo = { 0 };  // expected-error {{no member named 'PR18213' in 'PR18213::WrapperInfo'; did you mean simply 'PR18213'?}} \
-   // expected-error {{C++ requires a type specifier for all declarations}}
+PR18213::WrapperInfo ::PR18213::Wrappable::kWrapperInfo = { 0 };
 }
 
 namespace PR18651 {
Index: test/SemaCXX/pr18284-crash-on-invalid.cpp
===
--- test/SemaCXX/pr18284-crash-on-invalid.cpp
+++ test/SemaCXX/pr18284-crash-on-invalid.cpp
@@ -5,7 +5,7 @@
 class A { };
 class C { A a; };
 
-A::RunTest() {} // expected-error {{C++ requires a type specifier for all declarations}}
+A::RunTest() {} // expected-error {{definition or redeclaration of 'RunTest' cannot name the global scope}}
 
 void f() {
   new C;
@@ -16,7 +16,7 @@
 class A { };
 class C : public A { };
 
-A::RunTest() {} // expected-error {{C++ requires a type specifier for all declarations}}
+A::RunTest() {} // expected-error {{definition or redeclaration of 'RunTest' cannot name the global scope}}
 
 void f() {
   new C;
Index: test/SemaCXX/nested-name-spec2.cpp
===
--- /dev/null
+++ test/SemaCXX/nested-name-spec2.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+enum E1 { ABCD };
+
+struct C1 {
+  struct C2 {};
+  enum E2 { XYZ };
+};
+
+E1   func_01();
+E1 ::func_01();  // expected-warning{{extra qualification on member}}
+
+C1   func_02();
+C1 ::func_02();  // expected-warning{{extra qualification on member}}
+
+C1::C2   func_03();
+C1::C2 ::func_03();  // expected-warning{{extra qualification on member}}
+
+C1::E2   func_04();
+C1::E2 ::func_04();  // expected-warning{{extra qualification on member}}
+
+class C3 {
+  friend E1 ::func_01();
+  friend C1 ::func_02();
+  friend C1::C2 ::func_03();
+  friend C1::E2 ::func_04();
+};
+
+
+namespace N1 {
+  class C3 {
+friend ::E1 ::func_01();
+friend ::C1 ::func_02();
+friend ::C1::C2 ::func_03();
+friend ::C1::E2 ::func_04();
+  };
+}
+
+
+namespace N2 {
+  enum E1 { ABCD };
+
+  struct C1 {
+struct C2 {};
+enum E2 { XYZ };
+  };
+
+  E1 func_01();
+  C1 func_02();
+  C1::C2 func_03();
+  C1::E2 func_04();
+}
+
+namespace N3 {
+  class C4 {
+friend ::N2::E1 ::N2::func_01();
+friend ::N2::C1 ::N2::func_02();
+friend ::N2::C1::C2 ::N2::func_03();
+friend ::N2::C1::E2 ::N2::func_04();
+  };
+}
Index: test/Parser/cxx-decl.cpp
===
--- test/Parser/cxx-decl.cpp
+++ test/Parser/cxx-decl.cpp
@@ -249,8 +249,11 @@
 FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}}
 ~FooBar(); // 

[PATCH] D23685: [libcxx] [test] Include the iterator header for back_inserter.

2016-08-18 Thread Stephan T. Lavavej via cfe-commits
STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

Code was recently added to this test that uses std::back_inserter. Therefore, 
the header  must be included. (MSVC's STL demands this, as we don't 
otherwise drag in back_inserter.)

https://reviews.llvm.org/D23685

Files:
  test/std/containers/associative/map/map.cons/copy_assign.pass.cpp

Index: test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
===
--- test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
+++ test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 


Index: test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
===
--- test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
+++ test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r279114 - Removed use of 'emplace' on std::map, since not all buildbot slaves support it

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 13:41:41 2016
New Revision: 279114

URL: http://llvm.org/viewvc/llvm-project?rev=279114&view=rev
Log:
Removed use of 'emplace' on std::map, since not all buildbot slaves support it

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=279114&r1=279113&r2=279114&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 13:41:41 2016
@@ -397,9 +397,9 @@ public:
   llvm::sys::path::append(Path, Filename);
   Filename = Path.str();
 }
-auto it = UnsavedFileContents.emplace(
+auto it = UnsavedFileContents.insert(std::make_pair(
 fixed_addr_string(new std::string(Filename)),
-fixed_addr_string(new std::string(Contents)));
+fixed_addr_string(new std::string(Contents;
 UnsavedFiles.push_back({
 it.first->first->c_str(),   // filename
 it.first->second->c_str(),  // contents


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


[clang-tools-extra] r279115 - [clang-tidy docs] Move option descriptions to the Options section

2016-08-18 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Aug 18 13:43:47 2016
New Revision: 279115

URL: http://llvm.org/viewvc/llvm-project?rev=279115&view=rev
Log:
[clang-tidy docs] Move option descriptions to the Options section

+ random fixes

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst?rev=279115&r1=279114&r2=279115&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst 
Thu Aug 18 13:43:47 2016
@@ -9,7 +9,8 @@ The condition of ``assert()`` is evaluat
 condition with side effect can cause different behavior in debug / release
 builds.
 
-There are two options:
+Options
+---
 
 .. option:: AssertMacros
 

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst?rev=279115&r1=279114&r2=279115&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst Thu 
Aug 18 13:43:47 2016
@@ -3,15 +3,11 @@
 misc-dangling-handle
 
 
-Detect dangling references in value handlers like
+Detect dangling references in value handles like
 ``std::experimental::string_view``.
-These dangling references can come from constructing handles from temporary
+These dangling references can be a result of constructing handles from 
temporary
 values, where the temporary is destroyed soon after the handle is created.
 
-By default only ``std::experimental::basic_string_view`` is considered.
-This list can be modified by passing a `;` separated list of class names using
-the HandleClasses option.
-
 Examples:
 
 .. code-block:: c++
@@ -32,3 +28,11 @@ Examples:
 char Array[10]{};
 return Array;
   }
+
+Options
+---
+
+.. option:: HandleClasses
+
+   A semicolon-separated list of class names that should be treated as handles.
+   By default only ``std::experimental::basic_string_view`` is considered.

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst?rev=279115&r1=279114&r2=279115&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
Thu Aug 18 13:43:47 2016
@@ -13,12 +13,11 @@ because replacing ``insert`` with ``empl
 `speed regression 
`_,
 but it might get support with some addition flag in the future.
 
 By default only ``std::vector``, ``std::deque``, ``std::list`` are considered.
-This list can be modified by passing a semicolon-separated list of class names
-using the `ContainersWithPushBack` option.
+This list can be modified using the :option:`ContainersWithPushBack` option.
 
 Before:
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector v;
 v.push_back(MyClass(21, 37));
@@ -30,7 +29,7 @@ Before:
 
 After:
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector v;
 v.emplace_back(21, 37);
@@ -45,14 +44,14 @@ inside a container.
 
 Before:
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector > v;
 v.push_back("abc");
 
 After:
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector > v;
 v.emplace_back("abc");
@@ -62,7 +61,7 @@ In some cases the transformation would b
 wouldn't be exception safe.
 In this case the calls of ``push_back`` won't be replaced.
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector> v;
 v.push_back(std::unique_ptr(new int(0)));
@@ -70,16 +69,15 @@ In this case the calls of ``push_back``
 v.push_back(std::unique_ptr(ptr));
 
 This is because replacing it with ``emplace_back`` could cause a leak of this
-pointer if ``emplace_back`` would throw exception before emplacement
-(e.g. not enough memory to add new element).
+pointer if ``emplace_back`` would throw exception before emplacement (e.g. not
+enough memory to add new element).
 
-For more info read item 42 - "Consider emplacement instead of insertion."
-of Scott Meyers Effective Modern C++.
+For more info read item 42 - "Consider emplacemen

r279116 - [MS] Silence -Wextern-init on const selectany variables

2016-08-18 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Thu Aug 18 13:45:07 2016
New Revision: 279116

URL: http://llvm.org/viewvc/llvm-project?rev=279116&view=rev
Log:
[MS] Silence -Wextern-init on const selectany variables

In C, 'extern' is typically used to avoid tentative definitions when
declaring variables in headers, but adding an intializer makes it a
defintion. This is somewhat confusing, so GCC and Clang both warn on it.
In C++, 'extern' is often used to give implictly static 'const'
variables external linkage, so don't warn in that case. If selectany is
present, this might be header code intended for C and C++ inclusion, so
apply the C++ rules.

Added:
cfe/trunk/test/Sema/attr-selectany.c
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=279116&r1=279115&r2=279116&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Aug 18 13:45:07 2016
@@ -9938,10 +9938,17 @@ void Sema::AddInitializerToDecl(Decl *Re
   VDecl->setInvalidDecl();
 }
   } else if (VDecl->isFileVarDecl()) {
+// In C, extern is typically used to avoid tentative definitions when
+// declaring variables in headers, but adding an intializer makes it a
+// defintion. This is somewhat confusing, so GCC and Clang both warn on it.
+// In C++, extern is often used to give implictly static const variables
+// external linkage, so don't warn in that case. If selectany is present,
+// this might be header code intended for C and C++ inclusion, so apply the
+// C++ rules.
 if (VDecl->getStorageClass() == SC_Extern &&
-(!getLangOpts().CPlusPlus ||
- !(Context.getBaseElementType(VDecl->getType()).isConstQualified() ||
-   VDecl->isExternC())) &&
+((!getLangOpts().CPlusPlus && !VDecl->hasAttr()) ||
+ !Context.getBaseElementType(VDecl->getType()).isConstQualified()) &&
+!(getLangOpts().CPlusPlus && VDecl->isExternC()) &&
 !isTemplateInstantiation(VDecl->getTemplateSpecializationKind()))
   Diag(VDecl->getLocation(), diag::warn_extern_init);
 

Added: cfe/trunk/test/Sema/attr-selectany.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-selectany.c?rev=279116&view=auto
==
--- cfe/trunk/test/Sema/attr-selectany.c (added)
+++ cfe/trunk/test/Sema/attr-selectany.c Thu Aug 18 13:45:07 2016
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-extensions -verify %s
+
+extern __declspec(selectany) const int x1 = 1; // no warning, const means we 
need extern in C++
+
+// Should we really warn on this?
+extern __declspec(selectany) int x2 = 1; // expected-warning {{'extern' 
variable has an initializer}}
+
+__declspec(selectany) void foo() { } // expected-error{{'selectany' can only 
be applied to data items with external linkage}}


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


Re: [PATCH] D22910: Add support for CXXOperatorCallExpr in Expr::HasSideEffects

2016-08-18 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/AST/Expr.cpp:2865-2867
@@ +2864,5 @@
+  case CXXOperatorCallExprClass: {
+// If it is an operator call expr it can have side effects when the
+// underlaying operator is of assignment kind.
+// Othrwise fall through the rest of cases.
+OverloadedOperatorKind Op = cast(this)->getOperator();

Well, this is true for any overloaded operator. Perhaps something like

"When looking for potential side-effects, we assume that an overloaded 
assignment operator is intended to have a side-effect and other overloaded 
operators are not."


Comment at: lib/AST/Expr.cpp:2869-2871
@@ +2868,5 @@
+OverloadedOperatorKind Op = cast(this)->getOperator();
+if (CXXOperatorCallExpr::isAssignmentOp(Op)) {
+  return true;
+}
+  }

I think this should go after the check for a pure callee -- if for whatever 
reason someone has defined an `operator=` with `__attribute__((pure))`, we 
shouldn't claim it has a side-effect.



https://reviews.llvm.org/D22910



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


r279120 - Resubmit "[Tooling] Parse compilation database command lines on Windows."

2016-08-18 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Aug 18 14:31:48 2016
New Revision: 279120

URL: http://llvm.org/viewvc/llvm-project?rev=279120&view=rev
Log:
Resubmit "[Tooling] Parse compilation database command lines on Windows."

This patch introduced the ability to decide at runtime whether to parse
JSON compilation database command lines using Gnu syntax or Windows
syntax.  However, there were many existing unit tests written that
hardcoded Gnu-specific paths.  These tests were now failing because
the auto-detection logic was choosing to parse them using Windows
rules.

This resubmission of the patch fixes this by introducing an enum
which defines the syntax mode, which defaults to auto-detect, but
for which the unit tests force Gnu style parsing.

Reviewed By: alexfh
Differential Revision: https://reviews.llvm.org/D23628

Modified:
cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Modified: cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h?rev=279120&r1=279119&r2=279120&view=diff
==
--- cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h (original)
+++ cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h Thu Aug 18 
14:31:48 2016
@@ -55,6 +55,7 @@ namespace tooling {
 ///
 /// JSON compilation databases can for example be generated in CMake projects
 /// by setting the flag -DCMAKE_EXPORT_COMPILE_COMMANDS.
+enum class JSONCommandLineSyntax { Windows, Gnu, AutoDetect };
 class JSONCompilationDatabase : public CompilationDatabase {
 public:
   /// \brief Loads a JSON compilation database from the specified file.
@@ -62,13 +63,15 @@ public:
   /// Returns NULL and sets ErrorMessage if the database could not be
   /// loaded from the given file.
   static std::unique_ptr
-  loadFromFile(StringRef FilePath, std::string &ErrorMessage);
+  loadFromFile(StringRef FilePath, std::string &ErrorMessage,
+   JSONCommandLineSyntax Syntax);
 
   /// \brief Loads a JSON compilation database from a data buffer.
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be loaded.
   static std::unique_ptr
-  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage);
+  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage,
+ JSONCommandLineSyntax Syntax);
 
   /// \brief Returns all compile comamnds in which the specified file was
   /// compiled.
@@ -89,8 +92,9 @@ public:
 
 private:
   /// \brief Constructs a JSON compilation database on a memory buffer.
-  JSONCompilationDatabase(std::unique_ptr Database)
-  : Database(std::move(Database)),
+  JSONCompilationDatabase(std::unique_ptr Database,
+  JSONCommandLineSyntax Syntax)
+  : Database(std::move(Database)), Syntax(Syntax),
 YAMLStream(this->Database->getBuffer(), SM) {}
 
   /// \brief Parses the database file and creates the index.
@@ -123,6 +127,7 @@ private:
   FileMatchTrie MatchTrie;
 
   std::unique_ptr Database;
+  JSONCommandLineSyntax Syntax;
   llvm::SourceMgr SM;
   llvm::yaml::Stream YAMLStream;
 };

Modified: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp?rev=279120&r1=279119&r2=279120&view=diff
==
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp Thu Aug 18 14:31:48 2016
@@ -16,7 +16,10 @@
 #include "clang/Tooling/CompilationDatabasePluginRegistry.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 
 namespace clang {
@@ -111,8 +114,31 @@ class CommandLineArgumentParser {
   std::vector CommandLine;
 };
 
-std::vector unescapeCommandLine(
-StringRef EscapedCommandLine) {
+std::vector unescapeCommandLine(JSONCommandLineSyntax Syntax,
+ StringRef EscapedCommandLine) {
+  if (Syntax == JSONCommandLineSyntax::AutoDetect) {
+llvm::Triple Triple(llvm::sys::getProcessTriple());
+if (Triple.getOS() == llvm::Triple::OSType::Win32) {
+  // Assume Windows command line parsing on Win32 unless the triple
+  // explicitly
+  // tells us otherwise.
+  if (!Triple.hasEnvironment() ||
+  Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
+Syntax = JSONCommandLineSyntax::Windows;
+  else
+Syntax = JSONCommandLineSyntax::Gnu;
+}
+  }
+
+  if (Syntax == JSONCommandLineSyntax::Windows) {
+llvm::BumpPtrAllocator Alloc;
+llvm::StringSav

Re: [PATCH] D23628: Fix unittests after windows command line parsing

2016-08-18 Thread Zachary Turner via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279120: Resubmit "[Tooling] Parse compilation database 
command lines on Windows." (authored by zturner).

Changed prior to commit:
  https://reviews.llvm.org/D23628?vs=68426&id=68593#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23628

Files:
  cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
  cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
  cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Index: cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
===
--- cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
+++ cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
@@ -55,20 +55,23 @@
 ///
 /// JSON compilation databases can for example be generated in CMake projects
 /// by setting the flag -DCMAKE_EXPORT_COMPILE_COMMANDS.
+enum class JSONCommandLineSyntax { Windows, Gnu, AutoDetect };
 class JSONCompilationDatabase : public CompilationDatabase {
 public:
   /// \brief Loads a JSON compilation database from the specified file.
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be
   /// loaded from the given file.
   static std::unique_ptr
-  loadFromFile(StringRef FilePath, std::string &ErrorMessage);
+  loadFromFile(StringRef FilePath, std::string &ErrorMessage,
+   JSONCommandLineSyntax Syntax);
 
   /// \brief Loads a JSON compilation database from a data buffer.
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be loaded.
   static std::unique_ptr
-  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage);
+  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage,
+ JSONCommandLineSyntax Syntax);
 
   /// \brief Returns all compile comamnds in which the specified file was
   /// compiled.
@@ -89,8 +92,9 @@
 
 private:
   /// \brief Constructs a JSON compilation database on a memory buffer.
-  JSONCompilationDatabase(std::unique_ptr Database)
-  : Database(std::move(Database)),
+  JSONCompilationDatabase(std::unique_ptr Database,
+  JSONCommandLineSyntax Syntax)
+  : Database(std::move(Database)), Syntax(Syntax),
 YAMLStream(this->Database->getBuffer(), SM) {}
 
   /// \brief Parses the database file and creates the index.
@@ -123,6 +127,7 @@
   FileMatchTrie MatchTrie;
 
   std::unique_ptr Database;
+  JSONCommandLineSyntax Syntax;
   llvm::SourceMgr SM;
   llvm::yaml::Stream YAMLStream;
 };
Index: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
===
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
@@ -16,7 +16,10 @@
 #include "clang/Tooling/CompilationDatabasePluginRegistry.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 
 namespace clang {
@@ -111,8 +114,31 @@
   std::vector CommandLine;
 };
 
-std::vector unescapeCommandLine(
-StringRef EscapedCommandLine) {
+std::vector unescapeCommandLine(JSONCommandLineSyntax Syntax,
+ StringRef EscapedCommandLine) {
+  if (Syntax == JSONCommandLineSyntax::AutoDetect) {
+llvm::Triple Triple(llvm::sys::getProcessTriple());
+if (Triple.getOS() == llvm::Triple::OSType::Win32) {
+  // Assume Windows command line parsing on Win32 unless the triple
+  // explicitly
+  // tells us otherwise.
+  if (!Triple.hasEnvironment() ||
+  Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
+Syntax = JSONCommandLineSyntax::Windows;
+  else
+Syntax = JSONCommandLineSyntax::Gnu;
+}
+  }
+
+  if (Syntax == JSONCommandLineSyntax::Windows) {
+llvm::BumpPtrAllocator Alloc;
+llvm::StringSaver Saver(Alloc);
+llvm::SmallVector T;
+llvm::cl::TokenizeWindowsCommandLine(EscapedCommandLine, Saver, T);
+std::vector Result(T.begin(), T.end());
+return Result;
+  }
+  assert(Syntax == JSONCommandLineSyntax::Gnu);
   CommandLineArgumentParser parser(EscapedCommandLine);
   return parser.parse();
 }
@@ -123,7 +149,8 @@
 SmallString<1024> JSONDatabasePath(Directory);
 llvm::sys::path::append(JSONDatabasePath, "compile_commands.json");
 std::unique_ptr Database(
-JSONCompilationDatabase::loadFromFile(JSONDatabasePath, ErrorMessage));
+JSONCompilationDatabase::loadFromFile(
+JSONDatabasePath, ErrorMessage, JSONCommandLineSyntax::AutoDetect));
 if (!Database)
   return nullptr;
 return Database;
@@ -143,27 +170,29 @@
 
 std::unique_ptr
 JSONCompilationDatabase::loadFromFile(StringRef FilePath,
-  std::string &ErrorMessage) {
+

r279121 - [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Thu Aug 18 14:34:04 2016
New Revision: 279121

URL: http://llvm.org/viewvc/llvm-project?rev=279121&view=rev
Log:
[OpenCL] AMDGCN: Fix size_t type

Pointers of certain GPUs in AMDGCN target in private address space is 32 bit 
but pointers in other address spaces are 64 bit. size_t type should be defined 
as 64 bit for these GPUs so that it could hold pointers in all address spaces. 
Also fixed issues in pointer arithmetic codegen by using pointer specific 
intptr type.

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

Added:
cfe/trunk/test/CodeGenOpenCL/size_t.cl
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenTypeCache.h

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=279121&r1=279120&r2=279121&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Aug 18 14:34:04 2016
@@ -294,6 +294,11 @@ public:
 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
   }
 
+  /// \brief Return the maximum width of pointers on this target.
+  virtual uint64_t getMaxPointerWidth() const {
+return PointerWidth;
+  }
+
   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in 
bits.
   unsigned getBoolWidth() const { return BoolWidth; }
 

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=279121&r1=279120&r2=279121&view=diff
==
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Thu Aug 18 14:34:04 2016
@@ -306,8 +306,9 @@ void TargetInfo::adjust(const LangOption
 }
 LongDoubleWidth = LongDoubleAlign = 128;
 
-assert(PointerWidth == 32 || PointerWidth == 64);
-bool Is32BitArch = PointerWidth == 32;
+unsigned MaxPointerWidth = getMaxPointerWidth();
+assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
+bool Is32BitArch = MaxPointerWidth == 32;
 SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
 PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
 IntPtrType = Is32BitArch ? SignedInt : SignedLong;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=279121&r1=279120&r2=279121&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Aug 18 14:34:04 2016
@@ -2004,6 +2004,10 @@ public:
 }
   }
 
+  uint64_t getMaxPointerWidth() const override {
+return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
+  }
+
   const char * getClobbers() const override {
 return "";
   }

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=279121&r1=279120&r2=279121&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Aug 18 14:34:04 2016
@@ -787,7 +787,7 @@ Value *ScalarExprEmitter::EmitScalarConv
   // Handle pointer conversions next: pointers can only be converted to/from
   // other pointers and integers. Check for pointer types in terms of LLVM, as
   // some native types (like Obj-C id) may map to a pointer type.
-  if (isa(DstTy)) {
+  if (auto DstPT = dyn_cast(DstTy)) {
 // The source value may be an integer, or a pointer.
 if (isa(SrcTy))
   return Builder.CreateBitCast(Src, DstTy, "conv");
@@ -795,7 +795,7 @@ Value *ScalarExprEmitter::EmitScalarConv
 assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
 // First, convert to the correct width so that we control the kind of
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DstPT);
 bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
 Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
@@ -1510,12 +1510,13 @@ Value *ScalarExprEmitter::VisitCastExpr(
 
 // First, convert to the correct width so that we control the kind of
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+auto DestLLVMTy = ConvertType(DestTy);
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy);
 bool InputSigned = E->getType()->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
   Builder.CreateIntCast(Src, MiddleTy, InputSigne

Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Yaxun Liu via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rL279121: [OpenCL] AMDGCN: Fix size_t type (authored by 
yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D23361?vs=68360&id=68594#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23361

Files:
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/Basic/TargetInfo.cpp
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/CodeGen/CGExprScalar.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenTypeCache.h
  cfe/trunk/test/CodeGenOpenCL/size_t.cl

Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -294,6 +294,11 @@
 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
   }
 
+  /// \brief Return the maximum width of pointers on this target.
+  virtual uint64_t getMaxPointerWidth() const {
+return PointerWidth;
+  }
+
   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
   unsigned getBoolWidth() const { return BoolWidth; }
 
Index: cfe/trunk/test/CodeGenOpenCL/size_t.cl
===
--- cfe/trunk/test/CodeGenOpenCL/size_t.cl
+++ cfe/trunk/test/CodeGenOpenCL/size_t.cl
@@ -0,0 +1,110 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-llvm -O0 -triple spir-unknown-unknown -o - | FileCheck --check-prefix=SZ32 %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-llvm -O0 -triple spir64-unknown-unknown -o - | FileCheck --check-prefix=SZ64 --check-prefix=SZ64ONLY %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-llvm -O0 -triple amdgcn-- -o - | FileCheck --check-prefix=SZ64 --check-prefix=AMDONLY %s
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_private(i8* %x)
+//SZ32: ptrtoint i8* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_private(i8* %x)
+//SZ64: ptrtoint i8* %{{.*}} to i64
+size_t test_ptrtoint_private(private char* x) {
+  return (size_t)x;
+}
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_global(i8 addrspace(1)* %x)
+//SZ32: ptrtoint i8 addrspace(1)* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_global(i8 addrspace(1)* %x)
+//SZ64: ptrtoint i8 addrspace(1)* %{{.*}} to i64
+intptr_t test_ptrtoint_global(global char* x) {
+  return (intptr_t)x;
+}
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_constant(i8 addrspace(2)* %x)
+//SZ32: ptrtoint i8 addrspace(2)* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_constant(i8 addrspace(2)* %x)
+//SZ64: ptrtoint i8 addrspace(2)* %{{.*}} to i64
+uintptr_t test_ptrtoint_constant(constant char* x) {
+  return (uintptr_t)x;
+}
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_local(i8 addrspace(3)* %x)
+//SZ32: ptrtoint i8 addrspace(3)* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_local(i8 addrspace(3)* %x)
+//SZ64: ptrtoint i8 addrspace(3)* %{{.*}} to i64
+size_t test_ptrtoint_local(local char* x) {
+  return (size_t)x;
+}
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_generic(i8 addrspace(4)* %x)
+//SZ32: ptrtoint i8 addrspace(4)* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_generic(i8 addrspace(4)* %x)
+//SZ64: ptrtoint i8 addrspace(4)* %{{.*}} to i64
+size_t test_ptrtoint_generic(generic char* x) {
+  return (size_t)x;
+}
+
+//SZ32: define{{.*}} i8* @test_inttoptr_private(i32 %x)
+//SZ32: inttoptr i32 %{{.*}} to i8*
+//SZ64: define{{.*}} i8* @test_inttoptr_private(i64 %x)
+//AMDONLY: trunc i64 %{{.*}} to i32
+//AMDONLY: inttoptr i32 %{{.*}} to i8*
+//SZ64ONLY: inttoptr i64 %{{.*}} to i8*
+private char* test_inttoptr_private(size_t x) {
+  return (private char*)x;
+}
+
+//SZ32: define{{.*}} i8 addrspace(1)* @test_inttoptr_global(i32 %x)
+//SZ32: inttoptr i32 %{{.*}} to i8 addrspace(1)*
+//SZ64: define{{.*}} i8 addrspace(1)* @test_inttoptr_global(i64 %x)
+//SZ64: inttoptr i64 %{{.*}} to i8 addrspace(1)*
+global char* test_inttoptr_global(size_t x) {
+  return (global char*)x;
+}
+
+//SZ32: define{{.*}} i8 addrspace(3)* @test_add_local(i8 addrspace(3)* %x, i32 %y)
+//SZ32: getelementptr inbounds i8, i8 addrspace(3)* %{{.*}}, i32
+//SZ64: define{{.*}} i8 addrspace(3)* @test_add_local(i8 addrspace(3)* %x, i64 %y)
+//AMDONLY: trunc i64 %{{.*}} to i32
+//AMDONLY: getelementptr inbounds i8, i8 addrspace(3)* %{{.*}}, i32
+//SZ64ONLY: getelementptr inbounds i8, i8 addrspace(3)* %{{.*}}, i64
+local char* test_add_local(local char* x, ptrdiff_t y) {
+  return x + y;
+}
+
+//SZ32: define{{.*}} i8 addrspace(1)* @test_add_global(i8 addrspace(1)* %x, i32 %y)
+//SZ32: getelementptr inbounds i8, i8 addrspace(1)* %{{.*}}, i32
+//SZ64: define{{.*}} i8 addrspace(1)* @test_add_global(i8 addrspace(1)* %x, i64 %y)
+//SZ64: getelementptr inbounds i8, i8 addrspace(1)* %{{.*}}, i64
+global char* test_add_global(global char* x, ptrdiff_t y) {
+  return x + y;
+}
+
+//SZ32

r279122 - Fix json compilation database syntax on non-Windows.

2016-08-18 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Aug 18 14:42:00 2016
New Revision: 279122

URL: http://llvm.org/viewvc/llvm-project?rev=279122&view=rev
Log:
Fix json compilation database syntax on non-Windows.

Modified:
cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp

Modified: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp?rev=279122&r1=279121&r2=279122&view=diff
==
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp Thu Aug 18 14:42:00 2016
@@ -117,16 +117,14 @@ class CommandLineArgumentParser {
 std::vector unescapeCommandLine(JSONCommandLineSyntax Syntax,
  StringRef EscapedCommandLine) {
   if (Syntax == JSONCommandLineSyntax::AutoDetect) {
+Syntax = JSONCommandLineSyntax::Gnu;
 llvm::Triple Triple(llvm::sys::getProcessTriple());
 if (Triple.getOS() == llvm::Triple::OSType::Win32) {
   // Assume Windows command line parsing on Win32 unless the triple
-  // explicitly
-  // tells us otherwise.
+  // explicitly tells us otherwise.
   if (!Triple.hasEnvironment() ||
   Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
 Syntax = JSONCommandLineSyntax::Windows;
-  else
-Syntax = JSONCommandLineSyntax::Gnu;
 }
   }
 


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


Re: [PATCH] D23618: [LibTooling] Allow compilation database to explicitly specify compilation database file and source root

2016-08-18 Thread Alexander Kornienko via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

As discussed offline, since the functionality being added in this patch is only 
useful for tests, the related simplification of tests seems not worth the added 
complexity.


https://reviews.llvm.org/D23618



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


r279127 - Revert [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Thu Aug 18 15:01:06 2016
New Revision: 279127

URL: http://llvm.org/viewvc/llvm-project?rev=279127&view=rev
Log:
Revert [OpenCL] AMDGCN: Fix size_t type

due to regressions in test/CodeGen/exprs.c on certain platforms.

Removed:
cfe/trunk/test/CodeGenOpenCL/size_t.cl
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenTypeCache.h

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=279127&r1=279126&r2=279127&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Aug 18 15:01:06 2016
@@ -294,11 +294,6 @@ public:
 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
   }
 
-  /// \brief Return the maximum width of pointers on this target.
-  virtual uint64_t getMaxPointerWidth() const {
-return PointerWidth;
-  }
-
   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in 
bits.
   unsigned getBoolWidth() const { return BoolWidth; }
 

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=279127&r1=279126&r2=279127&view=diff
==
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Thu Aug 18 15:01:06 2016
@@ -306,9 +306,8 @@ void TargetInfo::adjust(const LangOption
 }
 LongDoubleWidth = LongDoubleAlign = 128;
 
-unsigned MaxPointerWidth = getMaxPointerWidth();
-assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
-bool Is32BitArch = MaxPointerWidth == 32;
+assert(PointerWidth == 32 || PointerWidth == 64);
+bool Is32BitArch = PointerWidth == 32;
 SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
 PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
 IntPtrType = Is32BitArch ? SignedInt : SignedLong;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=279127&r1=279126&r2=279127&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Aug 18 15:01:06 2016
@@ -2004,10 +2004,6 @@ public:
 }
   }
 
-  uint64_t getMaxPointerWidth() const override {
-return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
-  }
-
   const char * getClobbers() const override {
 return "";
   }

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=279127&r1=279126&r2=279127&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Aug 18 15:01:06 2016
@@ -787,7 +787,7 @@ Value *ScalarExprEmitter::EmitScalarConv
   // Handle pointer conversions next: pointers can only be converted to/from
   // other pointers and integers. Check for pointer types in terms of LLVM, as
   // some native types (like Obj-C id) may map to a pointer type.
-  if (auto DstPT = dyn_cast(DstTy)) {
+  if (isa(DstTy)) {
 // The source value may be an integer, or a pointer.
 if (isa(SrcTy))
   return Builder.CreateBitCast(Src, DstTy, "conv");
@@ -795,7 +795,7 @@ Value *ScalarExprEmitter::EmitScalarConv
 assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
 // First, convert to the correct width so that we control the kind of
 // extension.
-llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DstPT);
+llvm::Type *MiddleTy = CGF.IntPtrTy;
 bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
 Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
@@ -1510,13 +1510,12 @@ Value *ScalarExprEmitter::VisitCastExpr(
 
 // First, convert to the correct width so that we control the kind of
 // extension.
-auto DestLLVMTy = ConvertType(DestTy);
-llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy);
+llvm::Type *MiddleTy = CGF.IntPtrTy;
 bool InputSigned = E->getType()->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
   Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
 
-return Builder.CreateIntToPtr(IntResult, DestLLVMTy);
+return Builder.CreateIntToPtr(IntResult, ConvertType(DestTy));
   }
   case CK_PointerToIntegral:
 assert(!DestTy->isBooleanType() && "bool should use PointerToBool");
@@ -2427,7 +2426,6 @@ static Value *emitPointerArithmetic(

[PATCH] D23692: Interpret strlen as constexpr for GCC Compatibility

2016-08-18 Thread Erich Keane via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: cfe-commits, majnemer, vbyakovl, DavidKreitzer, 
andreybokhanko, rsmith.
erichkeane set the repository for this revision to rL LLVM.

GCC (and other compilers) treat strlen as a 'constexpr' function as an 
extension to the language.  Clang previously treated __builtin_strlen as a 
constexpr extension, so for this patch it was only necessary to remove the 
error-causing diagnostic for the strlen case, which falls through to the 
__builtin_strlen handling.

Additionally, the strlen test previously expected this error, so this patch 
removes the error-expectation from the test.

Repository:
  rL LLVM

https://reviews.llvm.org/D23692

Files:
  lib/AST/ExprConstant.cpp
  test/SemaCXX/constexpr-strlen.cpp

Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -7022,11 +7022,9 @@
   }
 
   case Builtin::BIstrlen:
-// A call to strlen is not a constant expression.
-if (Info.getLangOpts().CPlusPlus11)
-  Info.CCEDiag(E, diag::note_constexpr_invalid_function)
-<< /*isConstexpr*/0 << /*isConstructor*/0 << "'strlen'";
-else
+// As a GCC compatibility extension, we support strlen() 
+// as a constant expression.
+if (!Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 // Fall through.
   case Builtin::BI__builtin_strlen: {
Index: test/SemaCXX/constexpr-strlen.cpp
===
--- test/SemaCXX/constexpr-strlen.cpp
+++ test/SemaCXX/constexpr-strlen.cpp
@@ -8,7 +8,7 @@
 
 # 10 "SemaCXX/constexpr-strlen.cpp" 2
 constexpr int n = __builtin_strlen("hello"); // ok
-constexpr int m = strlen("hello"); // expected-error {{constant expression}} 
expected-note {{non-constexpr function 'strlen' cannot be used in a constant 
expression}}
+constexpr int m = strlen("hello"); // ok
 
 // Make sure we can evaluate a call to strlen.
 int arr[3]; // expected-note {{here}}


Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -7022,11 +7022,9 @@
   }
 
   case Builtin::BIstrlen:
-// A call to strlen is not a constant expression.
-if (Info.getLangOpts().CPlusPlus11)
-  Info.CCEDiag(E, diag::note_constexpr_invalid_function)
-<< /*isConstexpr*/0 << /*isConstructor*/0 << "'strlen'";
-else
+// As a GCC compatibility extension, we support strlen() 
+// as a constant expression.
+if (!Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 // Fall through.
   case Builtin::BI__builtin_strlen: {
Index: test/SemaCXX/constexpr-strlen.cpp
===
--- test/SemaCXX/constexpr-strlen.cpp
+++ test/SemaCXX/constexpr-strlen.cpp
@@ -8,7 +8,7 @@
 
 # 10 "SemaCXX/constexpr-strlen.cpp" 2
 constexpr int n = __builtin_strlen("hello"); // ok
-constexpr int m = strlen("hello"); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strlen' cannot be used in a constant expression}}
+constexpr int m = strlen("hello"); // ok
 
 // Make sure we can evaluate a call to strlen.
 int arr[3]; // expected-note {{here}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23627: [CUDA] Improve handling of math functions.

2016-08-18 Thread Justin Lebar via cfe-commits
jlebar added a comment.

These changes have always been kind of scary.  tra tested this against Thrust 
all combinations of CUDA 7.0/7.5, c++98/11, 
libc++/libstdc++{4.8.5/4.9.3,5.3.0}.  So we should be good here.  I hope.


https://reviews.llvm.org/D23627



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


r279140 - [CUDA] Improve handling of math functions.

2016-08-18 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Aug 18 15:43:13 2016
New Revision: 279140

URL: http://llvm.org/viewvc/llvm-project?rev=279140&view=rev
Log:
[CUDA] Improve handling of math functions.

Summary:
A bunch of related changes here to our CUDA math headers.

- The second arg to nexttoward is a double (well, technically, long
  double, but we don't have that), not a float.

- Add a forward-declare of llround(float), which is defined in the CUDA
  headers.  We need this for the same reason we need most of the other
  forward-declares: To prevent a constexpr function in our standard
  library from becoming host+device.

- Add nexttowardf implementation.

- Pull "foobarf" functions defined by the CUDA headers in the global
  namespace into namespace std.  This lets you do e.g. std::sinf.

- Add overloads for math functions accepting integer types.  This lets
  you do e.g. std::sin(0) without having an ambiguity between the
  overload that takes a float and the one that takes a double.

With these changes, we pass testcases derived from libc++ for cmath and
math.h.  We can check these testcases in to the test-suite once support
for CUDA lands there.

Reviewers: tra

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Headers/__clang_cuda_cmath.h
cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h

Modified: cfe/trunk/lib/Headers/__clang_cuda_cmath.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_cmath.h?rev=279140&r1=279139&r2=279140&view=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_cmath.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_cmath.h Thu Aug 18 15:43:13 2016
@@ -26,13 +26,15 @@
 #error "This file is for CUDA compilation only."
 #endif
 
+#include 
+
 // CUDA lets us use various std math functions on the device side.  This file
 // works in concert with __clang_cuda_math_forward_declares.h to make this 
work.
 //
 // Specifically, the forward-declares header declares __device__ overloads for
 // these functions in the global namespace, then pulls them into namespace std
 // with 'using' statements.  Then this file implements those functions, after
-// the implementations have been pulled in.
+// their implementations have been pulled in.
 //
 // It's important that we declare the functions in the global namespace and 
pull
 // them into namespace std with using statements, as opposed to simply 
declaring
@@ -120,12 +122,15 @@ __DEVICE__ float ldexp(float __arg, int
 __DEVICE__ float log(float __x) { return ::logf(__x); }
 __DEVICE__ float log10(float __x) { return ::log10f(__x); }
 __DEVICE__ float modf(float __x, float *__iptr) { return ::modff(__x, __iptr); 
}
-__DEVICE__ float nexttoward(float __from, float __to) {
+__DEVICE__ float nexttoward(float __from, double __to) {
   return __builtin_nexttowardf(__from, __to);
 }
 __DEVICE__ double nexttoward(double __from, double __to) {
   return __builtin_nexttoward(__from, __to);
 }
+__DEVICE__ float nexttowardf(float __from, double __to) {
+  return __builtin_nexttowardf(__from, __to);
+}
 __DEVICE__ float pow(float __base, float __exp) {
   return ::powf(__base, __exp);
 }
@@ -143,6 +148,280 @@ __DEVICE__ float sqrt(float __x) { retur
 __DEVICE__ float tan(float __x) { return ::tanf(__x); }
 __DEVICE__ float tanh(float __x) { return ::tanhf(__x); }
 
+// Now we've defined everything we promised we'd define in
+// __clang_cuda_math_forward_declares.h.  We need to do two additional things 
to
+// fix up our math functions.
+//
+// 1) Define __device__ overloads for e.g. sin(int).  The CUDA headers define
+//only sin(float) and sin(double), which means that e.g. sin(0) is
+//ambiguous.
+//
+// 2) Pull the __device__ overloads of "foobarf" math functions into namespace
+//std.  These are defined in the CUDA headers in the global namespace,
+//independent of everything else we've done here.
+
+// We can't use std::enable_if, because we want to be pre-C++11 compatible.  
But
+// we go ahead and unconditionally define functions that are only available 
when
+// compiling for C++11 to match the behavior of the CUDA headers.
+template
+struct __clang_cuda_enable_if {};
+
+template  struct __clang_cuda_enable_if {
+  typedef __T type;
+};
+
+// Defines an overload of __fn that accepts one integral argument, calls
+// __fn((double)x), and returns __retty.
+#define __CUDA_CLANG_FN_INTEGER_OVERLOAD_1(__retty, __fn)  
\
+  template   
\
+  __DEVICE__   
\
+  typename __clang_cuda_enable_if::is_integer,
\
+  __retty>::type   
\
+  __fn(__T __x) {  
\
+return ::__fn((double)__x);  

Re: [PATCH] D23627: [CUDA] Improve handling of math functions.

2016-08-18 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279140: [CUDA] Improve handling of math functions. (authored 
by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D23627?vs=68427&id=68600#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23627

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

Index: cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h
+++ cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h
@@ -140,6 +140,7 @@
 __DEVICE__ long lrint(float);
 __DEVICE__ long lround(double);
 __DEVICE__ long lround(float);
+__DEVICE__ long long llround(float); // No llround(double).
 __DEVICE__ double modf(double, double *);
 __DEVICE__ float modf(float, float *);
 __DEVICE__ double nan(const char *);
@@ -149,7 +150,8 @@
 __DEVICE__ double nextafter(double, double);
 __DEVICE__ float nextafter(float, float);
 __DEVICE__ double nexttoward(double, double);
-__DEVICE__ float nexttoward(float, float);
+__DEVICE__ float nexttoward(float, double);
+__DEVICE__ float nexttowardf(float, double);
 __DEVICE__ double pow(double, double);
 __DEVICE__ double pow(double, int);
 __DEVICE__ float pow(float, float);
@@ -235,6 +237,7 @@
 using ::logb;
 using ::lrint;
 using ::lround;
+using ::llround;
 using ::modf;
 using ::nan;
 using ::nanf;
Index: cfe/trunk/lib/Headers/__clang_cuda_cmath.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_cmath.h
+++ cfe/trunk/lib/Headers/__clang_cuda_cmath.h
@@ -26,13 +26,15 @@
 #error "This file is for CUDA compilation only."
 #endif
 
+#include 
+
 // CUDA lets us use various std math functions on the device side.  This file
 // works in concert with __clang_cuda_math_forward_declares.h to make this work.
 //
 // Specifically, the forward-declares header declares __device__ overloads for
 // these functions in the global namespace, then pulls them into namespace std
 // with 'using' statements.  Then this file implements those functions, after
-// the implementations have been pulled in.
+// their implementations have been pulled in.
 //
 // It's important that we declare the functions in the global namespace and pull
 // them into namespace std with using statements, as opposed to simply declaring
@@ -120,12 +122,15 @@
 __DEVICE__ float log(float __x) { return ::logf(__x); }
 __DEVICE__ float log10(float __x) { return ::log10f(__x); }
 __DEVICE__ float modf(float __x, float *__iptr) { return ::modff(__x, __iptr); }
-__DEVICE__ float nexttoward(float __from, float __to) {
+__DEVICE__ float nexttoward(float __from, double __to) {
   return __builtin_nexttowardf(__from, __to);
 }
 __DEVICE__ double nexttoward(double __from, double __to) {
   return __builtin_nexttoward(__from, __to);
 }
+__DEVICE__ float nexttowardf(float __from, double __to) {
+  return __builtin_nexttowardf(__from, __to);
+}
 __DEVICE__ float pow(float __base, float __exp) {
   return ::powf(__base, __exp);
 }
@@ -143,6 +148,280 @@
 __DEVICE__ float tan(float __x) { return ::tanf(__x); }
 __DEVICE__ float tanh(float __x) { return ::tanhf(__x); }
 
+// Now we've defined everything we promised we'd define in
+// __clang_cuda_math_forward_declares.h.  We need to do two additional things to
+// fix up our math functions.
+//
+// 1) Define __device__ overloads for e.g. sin(int).  The CUDA headers define
+//only sin(float) and sin(double), which means that e.g. sin(0) is
+//ambiguous.
+//
+// 2) Pull the __device__ overloads of "foobarf" math functions into namespace
+//std.  These are defined in the CUDA headers in the global namespace,
+//independent of everything else we've done here.
+
+// We can't use std::enable_if, because we want to be pre-C++11 compatible.  But
+// we go ahead and unconditionally define functions that are only available when
+// compiling for C++11 to match the behavior of the CUDA headers.
+template
+struct __clang_cuda_enable_if {};
+
+template  struct __clang_cuda_enable_if {
+  typedef __T type;
+};
+
+// Defines an overload of __fn that accepts one integral argument, calls
+// __fn((double)x), and returns __retty.
+#define __CUDA_CLANG_FN_INTEGER_OVERLOAD_1(__retty, __fn)  \
+  template   \
+  __DEVICE__   \
+  typename __clang_cuda_enable_if::is_integer,\
+  __retty>::type   \
+  __fn(__T __x) {  \
+return ::__fn((double)__x);\
+  }
+
+// Defines an overload of __fn that accepts one two arithmetic arguments, calls
+// __fn((double)x, (double)y), and

Re: [PATCH] D23692: Interpret strlen as constexpr for GCC Compatibility

2016-08-18 Thread Richard Smith via cfe-commits
rsmith requested changes to this revision.
rsmith added a comment.
This revision now requires changes to proceed.

This is not a conforming extension. We are explicitly not allowed to make 
standard library functions `constexpr` if the standard doesn't say they are; 
see [constexpr.functions] (17.6.5.6) in the C++ standard. Clang previously used 
to allow constant-folding `strlen` calls, but we removed that support 
intentionally for this reason.

It would seem reasonable for this constant-folding to be enabled for `strlen` 
if the callee was explicitly marked as `constexpr` in the source code. That 
way, if the standard library chooses to mark it as `constexpr` as a (currently) 
non-conforming extension, we would provide an optimized implementation.


Repository:
  rL LLVM

https://reviews.llvm.org/D23692



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


Re: [PATCH] D23692: Interpret strlen as constexpr for GCC Compatibility

2016-08-18 Thread Erich Keane via cfe-commits
erichkeane abandoned this revision.
erichkeane added a comment.

In https://reviews.llvm.org/D23692#520081, @rsmith wrote:

> This is not a conforming extension. We are explicitly not allowed to make 
> standard library functions `constexpr` if the standard doesn't say they are; 
> see [constexpr.functions] (17.6.5.6) in the C++ standard. Clang previously 
> used to allow constant-folding `strlen` calls, but we removed that support 
> intentionally for this reason.
>
> It would seem reasonable for this constant-folding to be enabled for `strlen` 
> if the callee was explicitly marked as `constexpr` in the source code. That 
> way, if the standard library chooses to mark it as `constexpr` as a 
> (currently) non-conforming extension, we would provide an optimized 
> implementation.


Ok, thank you for your prompt response.  I'll see if that is a viable solution 
for this case.

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D23692



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


r279145 - Fixed more signed/unsigned mismatch warnings introduced in my change at r279076

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 15:56:48 2016
New Revision: 279145

URL: http://llvm.org/viewvc/llvm-project?rev=279145&view=rev
Log:
Fixed more signed/unsigned mismatch warnings introduced in my change at r279076

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=279145&r1=279144&r2=279145&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 15:56:48 2016
@@ -439,23 +439,23 @@ TEST_F(LibclangParseTest, AllSkippedRang
nullptr, 0, TUFlags);
 
   CXSourceRangeList *Ranges = clang_getAllSkippedRanges(ClangTU);
-  EXPECT_EQ(2u, Ranges->count);
+  EXPECT_EQ(2U, Ranges->count);
   
   CXSourceLocation cxl;
   unsigned line;
   cxl = clang_getRangeStart(Ranges->ranges[0]);
   clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr);
-  EXPECT_EQ(1, line);
+  EXPECT_EQ(1U, line);
   cxl = clang_getRangeEnd(Ranges->ranges[0]);
   clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr);
-  EXPECT_EQ(3, line);
+  EXPECT_EQ(3U, line);
 
   cxl = clang_getRangeStart(Ranges->ranges[1]);
   clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr);
-  EXPECT_EQ(2, line);
+  EXPECT_EQ(2U, line);
   cxl = clang_getRangeEnd(Ranges->ranges[1]);
   clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr);
-  EXPECT_EQ(4, line);
+  EXPECT_EQ(4U, line);
 
   clang_disposeSourceRangeList(Ranges);
 }


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


Re: [PATCH] D23492: Make function local tags visible.

2016-08-18 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:3598-3603
@@ -3599,1 +3597,8 @@
+  // FIXME: We need to track the instantiation stack in order to know which
+  // definitions should be visible within this instantiation.
+  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Function,
+Function->getInstantiatedFromMemberFunction(),
+ PatternDecl, PatternDecl, TSK,
+ /*Complain*/DefinitionRequired))
+ return;
 

As long as we treat a late-parsed template as being defined, it should be fine 
(and looking at `FunctionDecl::isThisDeclarationADefinition`, we do). It's not 
correct to parse a late-parsed template that's not visible, so we need to move 
this check to before we handle late-parsed templates for correctness.


https://reviews.llvm.org/D23492



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


Re: [PATCH] D23684: Resolve ambiguity in a declaration if global nested name specifier is used

2016-08-18 Thread Richard Smith via cfe-commits
PR28422 is invalid. Giving better diagnostics in this case seems
reasonable, but we should not accept the ill-formed code.

On 18 Aug 2016 11:41 a.m., "Serge Pavlov"  wrote:

> sepavloff created this revision.
> sepavloff added reviewers: rsmith, doug.gregor.
> sepavloff added a subscriber: cfe-commits.
>
> If a declaration references a function from global namespace by its
> qualified name and if that function return type is a class or enum, there
> is possible ambiguity. The declaration:
> ```
> friend A::B::C();
> ```
> may be considered as a declaration of a function `::C()` that returns
> `A::B`, or a function `::B::C()` that returns `A`.
>
> With this change when the compiler sees 'A::B' while parsing decl-spec, it
> tries to find `B` within 'A'. If it finds, 'A::B' is treated as a part of
> qualified name. If it doesn't and the current declaration declares a
> function, '::B' is assumed to be a part of declarator. For non-function
> declarations 'B' can be searched for in the global namespace to improve
> diagnostics.
>
> This changes fixes https://llvm.org/bugs/show_bug.cgi?id=28422.
>
> https://reviews.llvm.org/D23684
>
> Files:
>   include/clang/Parse/Parser.h
>   include/clang/Sema/Sema.h
>   lib/Parse/ParseDecl.cpp
>   lib/Parse/ParseDeclCXX.cpp
>   lib/Parse/ParseExprCXX.cpp
>   lib/Parse/Parser.cpp
>   lib/Parse/RAIIObjectsForParser.h
>   lib/Sema/SemaCXXScopeSpec.cpp
>   lib/Sema/TreeTransform.h
>   test/CXX/drs/dr1xx.cpp
>   test/CXX/drs/dr2xx.cpp
>   test/Parser/cxx-decl.cpp
>   test/SemaCXX/nested-name-spec2.cpp
>   test/SemaCXX/pr18284-crash-on-invalid.cpp
>   test/SemaCXX/typo-correction.cpp
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23696: [CMake] Get libcxx building under LLVM/runtimes

2016-08-18 Thread Chris Bieneman via cfe-commits
beanz created this revision.
beanz added a reviewer: EricWF.
beanz added a subscriber: cfe-commits.

The new LLVM runtimes build directory requires some basic conventions across 
the runtime projects. These changes make libcxx build under the runtimes 
subdirectory. The general idea of the changes is that the runtimes subdirectory 
requires some conventions to be consistent across runtime projects.

I expect to have a few more small patches that build on this to tie up check 
targets and other things useful in development workflows.

Summary of changes in this patch:

* Renamed variable LLVM_CONFIG -> LLVM_CONFIG_PATH
* Renamed variable LIBCXX_BUILT_STANDALONE -> LIBCXX_STANDALONE_BUILD
* Add an include of AddLLVM in the tests subdirectory for add_lit_testsuite.

https://reviews.llvm.org/D23696

Files:
  CMakeLists.txt
  cmake/Modules/HandleOutOfTreeLLVM.cmake
  test/CMakeLists.txt

Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -1,3 +1,5 @@
+include(AddLLVM) # for add_lit_testsuite
+
 macro(pythonize_bool var)
   if (${var})
 set(${var} True)
Index: cmake/Modules/HandleOutOfTreeLLVM.cmake
===
--- cmake/Modules/HandleOutOfTreeLLVM.cmake
+++ cmake/Modules/HandleOutOfTreeLLVM.cmake
@@ -1,15 +1,17 @@
 macro(find_llvm_parts)
 # Rely on llvm-config.
   set(CONFIG_OUTPUT)
-  find_program(LLVM_CONFIG "llvm-config")
+  if(NOT LLVM_CONFIG_PATH)
+find_program(LLVM_CONFIG_PATH "llvm-config")
+  endif()
   if(DEFINED LLVM_PATH)
 set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
 set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
 set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
 set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
-  elseif(LLVM_CONFIG)
-message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
-set(CONFIG_COMMAND ${LLVM_CONFIG}
+  elseif(LLVM_CONFIG_PATH)
+message(STATUS "Found LLVM_CONFIG_PATH as ${LLVM_CONFIG_PATH}")
+set(CONFIG_COMMAND ${LLVM_CONFIG_PATH}
   "--includedir"
   "--prefix"
   "--src-root")
@@ -60,8 +62,8 @@
 endmacro(find_llvm_parts)
 
 
-if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
-  set(LIBCXX_BUILT_STANDALONE 1)
+if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR 
LIBCXX_STANDALONE_BUILD)
+  set(LIBCXX_STANDALONE_BUILD 1)
   message(STATUS "Configuring for standalone build.")
 
   find_llvm_parts()
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -22,16 +22,16 @@
 # Find the LLVM sources and simulate LLVM CMake options.
 include(HandleOutOfTreeLLVM)
 
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   project(libcxx CXX C)
 
   set(PACKAGE_NAME libcxx)
   set(PACKAGE_VERSION 4.0.0svn)
   set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
   set(PACKAGE_BUGREPORT "llvm-b...@lists.llvm.org")
 endif()
 
-if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND)
+if (LIBCXX_STANDALONE_BUILD AND NOT LLVM_FOUND)
   message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: "
   "llvm-config not found and LLVM_PATH not defined.\n"
   "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
@@ -81,7 +81,7 @@
 
 # Setup the default options if LIBCXX_CXX_ABI is not specified.
 if (NOT LIBCXX_CXX_ABI)
-  if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND
+  if (NOT DEFINED LIBCXX_STANDALONE_BUILD AND
   IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi")
 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
 set(LIBCXX_CXX_ABI_INCLUDE_PATHS 
"${CMAKE_SOURCE_DIR}/projects/libcxxabi/include")
@@ -367,9 +367,9 @@
 
 # Sanitizer flags =
 
-# Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do
+# Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do
 # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   set(LLVM_USE_SANITIZER "" CACHE STRING
   "Define the sanitizer used to build the library and tests")
   # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.


Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -1,3 +1,5 @@
+include(AddLLVM) # for add_lit_testsuite
+
 macro(pythonize_bool var)
   if (${var})
 set(${var} True)
Index: cmake/Modules/HandleOutOfTreeLLVM.cmake
===
--- cmake/Modules/HandleOutOfTreeLLVM.cmake
+++ cmake/Modules/HandleOutOfTreeLLVM.cmake
@@ -1,15 +1,17 @@
 macro(find_llvm_parts)
 # Rely on llvm-config.
   set(CONFIG_OUTPUT)
-  find_program(LLVM_CONFIG "llvm-config")
+  if(NOT LLVM_CONFIG_PATH)
+find_program(LLVM_CONFIG_PATH "llvm-config")

Re: [PATCH] D23696: [CMake] Get libcxx building under LLVM/runtimes

2016-08-18 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D23696



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


[libcxx] r279151 - [CMake] Get libcxx building under LLVM/runtimes

2016-08-18 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu Aug 18 16:31:51 2016
New Revision: 279151

URL: http://llvm.org/viewvc/llvm-project?rev=279151&view=rev
Log:
[CMake] Get libcxx building under LLVM/runtimes

Summary:
The new LLVM runtimes build directory requires some basic conventions across 
the runtime projects. These changes make libcxx build under the runtimes 
subdirectory. The general idea of the changes is that the runtimes subdirectory 
requires some conventions to be consistent across runtime projects.

I expect to have a few more small patches that build on this to tie up check 
targets and other things useful in development workflows.

Summary of changes in this patch:

* Renamed variable LLVM_CONFIG -> LLVM_CONFIG_PATH
* Renamed variable LIBCXX_BUILT_STANDALONE -> LIBCXX_STANDALONE_BUILD
* Add an include of AddLLVM in the tests subdirectory for add_lit_testsuite.

Reviewers: EricWF

Subscribers: cfe-commits

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

Modified:
libcxx/trunk/CMakeLists.txt
libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
libcxx/trunk/test/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=279151&r1=279150&r2=279151&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Thu Aug 18 16:31:51 2016
@@ -22,7 +22,7 @@ set(CMAKE_MODULE_PATH
 # Find the LLVM sources and simulate LLVM CMake options.
 include(HandleOutOfTreeLLVM)
 
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   project(libcxx CXX C)
 
   set(PACKAGE_NAME libcxx)
@@ -31,7 +31,7 @@ if (LIBCXX_BUILT_STANDALONE)
   set(PACKAGE_BUGREPORT "llvm-b...@lists.llvm.org")
 endif()
 
-if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND)
+if (LIBCXX_STANDALONE_BUILD AND NOT LLVM_FOUND)
   message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: "
   "llvm-config not found and LLVM_PATH not defined.\n"
   "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
@@ -81,7 +81,7 @@ set_property(CACHE LIBCXX_CXX_ABI PROPER
 
 # Setup the default options if LIBCXX_CXX_ABI is not specified.
 if (NOT LIBCXX_CXX_ABI)
-  if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND
+  if (NOT DEFINED LIBCXX_STANDALONE_BUILD AND
   IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi")
 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
 set(LIBCXX_CXX_ABI_INCLUDE_PATHS 
"${CMAKE_SOURCE_DIR}/projects/libcxxabi/include")
@@ -367,9 +367,9 @@ define_if(MSVC -D_CRT_SECURE_NO_WARNINGS
 
 # Sanitizer flags =
 
-# Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do
+# Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do
 # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   set(LLVM_USE_SANITIZER "" CACHE STRING
   "Define the sanitizer used to build the library and tests")
   # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.

Modified: libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake?rev=279151&r1=279150&r2=279151&view=diff
==
--- libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake (original)
+++ libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake Thu Aug 18 16:31:51 
2016
@@ -1,15 +1,17 @@
 macro(find_llvm_parts)
 # Rely on llvm-config.
   set(CONFIG_OUTPUT)
-  find_program(LLVM_CONFIG "llvm-config")
+  if(NOT LLVM_CONFIG_PATH)
+find_program(LLVM_CONFIG_PATH "llvm-config")
+  endif()
   if(DEFINED LLVM_PATH)
 set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
 set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
 set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
 set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
-  elseif(LLVM_CONFIG)
-message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
-set(CONFIG_COMMAND ${LLVM_CONFIG}
+  elseif(LLVM_CONFIG_PATH)
+message(STATUS "Found LLVM_CONFIG_PATH as ${LLVM_CONFIG_PATH}")
+set(CONFIG_COMMAND ${LLVM_CONFIG_PATH}
   "--includedir"
   "--prefix"
   "--src-root")
@@ -60,8 +62,8 @@ macro(find_llvm_parts)
 endmacro(find_llvm_parts)
 
 
-if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
-  set(LIBCXX_BUILT_STANDALONE 1)
+if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR 
LIBCXX_STANDALONE_BUILD)
+  set(LIBCXX_STANDALONE_BUILD 1)
   message(STATUS "Configuring for standalone build.")
 
   find_llvm_parts()

Modified: libcxx/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=279151&r1=279150&r2=279151&view=diff
===

  1   2   >