Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
andyarvanitis committed Jul 17, 2012
2 parents daaef1c + 6cfa78f commit aadc131ed92829de7c7e99558efe1bcbb15b1a03
Showing with 1,321 additions and 522 deletions.
  1. +9 −0 docs/UsersManual.html
  2. +2 −1 include/clang/AST/Comment.h
  3. +1 −0 include/clang/AST/ExprCXX.h
  4. +10 −2 include/clang/AST/RecursiveASTVisitor.h
  5. +1 −1 include/clang/AST/Type.h
  6. +90 −0 include/clang/ASTMatchers/RefactoringCallbacks.h
  7. +3 −3 include/clang/Basic/DiagnosticSemaKinds.td
  8. +7 −14 include/clang/Sema/Sema.h
  9. +80 −0 include/clang/Tooling/CommandLineClangTool.h
  10. +4 −2 include/clang/Tooling/Tooling.h
  11. +11 −4 lib/AST/ASTContext.cpp
  12. +1 −0 lib/ASTMatchers/CMakeLists.txt
  13. +78 −0 lib/ASTMatchers/RefactoringCallbacks.cpp
  14. +225 −228 lib/Analysis/UninitializedValues.cpp
  15. +29 −0 lib/CodeGen/CGBuiltin.cpp
  16. +1 −0 lib/CodeGen/CodeGenFunction.h
  17. +4 −0 lib/Edit/CMakeLists.txt
  18. +26 −27 lib/Frontend/TextDiagnostic.cpp
  19. +5 −1 lib/Rewrite/RewriteModernObjC.cpp
  20. +1 −0 lib/Sema/AnalysisBasedWarnings.cpp
  21. +3 −0 lib/Sema/SemaCast.cpp
  22. +16 −24 lib/Sema/SemaChecking.cpp
  23. +3 −2 lib/Sema/SemaExpr.cpp
  24. +7 −10 lib/Sema/SemaTemplate.cpp
  25. +10 −5 lib/Sema/SemaTemplateDeduction.cpp
  26. +46 −56 lib/Sema/SemaTemplateInstantiate.cpp
  27. +1 −1 lib/Sema/SemaTemplateInstantiateDecl.cpp
  28. +11 −11 lib/StaticAnalyzer/Core/ExprEngineC.cpp
  29. +13 −0 lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  30. +5 −0 lib/Tooling/CMakeLists.txt
  31. +80 −0 lib/Tooling/CommandLineClangTool.cpp
  32. +27 −8 test/Analysis/new.cpp
  33. +2 −2 test/CMakeLists.txt
  34. +13 −0 test/CodeGen/builtins-mips-ovld.c
  35. +19 −1 test/FixIt/fixit-unicode.c
  36. +2 −3 test/Index/recursive-cxx-member-calls.cpp
  37. +18 −0 test/Sema/uninit-variables.c
  38. +2 −3 test/SemaCXX/deleted-function.cpp
  39. +6 −0 test/SemaCXX/uninit-variables.cpp
  40. +43 −5 test/SemaTemplate/alias-templates.cpp
  41. +19 −0 test/SemaTemplate/instantiation-backtrace.cpp
  42. +23 −0 test/Tooling/clang-ast-dump.cpp
  43. +1 −0 tools/CMakeLists.txt
  44. +1 −1 tools/Makefile
  45. +8 −0 tools/clang-ast-dump/CMakeLists.txt
  46. +141 −0 tools/clang-ast-dump/ClangASTDump.cpp
  47. +23 −0 tools/clang-ast-dump/Makefile
  48. +18 −56 tools/clang-check/ClangCheck.cpp
  49. +2 −2 tools/libclang/CIndex.cpp
  50. +5 −1 tools/scan-build/set-xcode-analyzer
  51. +2 −1 unittests/ASTMatchers/CMakeLists.txt
  52. +98 −0 unittests/ASTMatchers/RefactoringCallbacksTest.cpp
  53. +62 −44 utils/analyzer/CmpRuns.py
  54. +1 −1 utils/analyzer/SATestBuild.py
  55. +1 −1 www/analyzer/latest_checker.html.incl
  56. +1 −1 www/analyzer/release_notes.html
View
@@ -229,6 +229,9 @@ <h4 id="cl_diag_formatting">Formatting of Diagnostics</h4>
<p>When this is disabled, Clang will print "test.c:28: warning..." with no
column number.</p>
+
+<p>The printed column numbers count bytes from the beginning of the line; take
+care if your source contains multibyte characters.</p>
</dd>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
@@ -395,6 +398,9 @@ <h4 id="cl_diag_formatting">Formatting of Diagnostics</h4>
</pre>
<p>The {}'s are generated by -fdiagnostics-print-source-range-info.</p>
+
+<p>The printed column numbers count bytes from the beginning of the line; take
+care if your source contains multibyte characters.</p>
</dd>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
@@ -415,6 +421,9 @@ <h4 id="cl_diag_formatting">Formatting of Diagnostics</h4>
&quot;\\&quot;), tabs (as &quot;\t&quot;), newlines (as &quot;\n&quot;), double
quotes(as &quot;\&quot;&quot;) and non-printable characters (as octal
&quot;\xxx&quot;).</p>
+
+<p>The printed column numbers count bytes from the beginning of the line; take
+care if your source contains multibyte characters.</p>
</dd>
<dt id="opt_fno-elide-type">
@@ -510,7 +510,8 @@ class BlockCommandComment : public BlockContentComment {
}
static bool classof(const Comment *C) {
- return C->getCommentKind() == BlockCommandCommentKind;
+ return C->getCommentKind() >= FirstBlockCommandCommentConstant &&
+ C->getCommentKind() <= LastBlockCommandCommentConstant;
}
static bool classof(const BlockCommandComment *) { return true; }
@@ -1001,6 +1001,7 @@ class CXXConstructExpr : public Expr {
SourceRange getSourceRange() const LLVM_READONLY;
SourceRange getParenRange() const { return ParenRange; }
+ void setParenRange(SourceRange Range) { ParenRange = Range; }
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXConstructExprClass ||
@@ -464,12 +464,19 @@ template<typename Derived>
bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
bool &EnqueueChildren) {
+// The cast for DISPATCH_WALK is needed for older versions of g++, but causes
+// problems for MSVC. So we'll skip the cast entirely for MSVC.
+#if defined(_MSC_VER)
+ #define GCC_CAST(CLASS)
+#else
+ #define GCC_CAST(CLASS) (bool (RecursiveASTVisitor::*)(CLASS*))
+#endif
+
// Dispatch to the corresponding WalkUpFrom* function only if the derived
// class didn't override Traverse* (and thus the traversal is trivial).
- // The cast here is necessary to work around a bug in old versions of g++.
#define DISPATCH_WALK(NAME, CLASS, VAR) \
if (&RecursiveASTVisitor::Traverse##NAME == \
- (bool (RecursiveASTVisitor::*)(CLASS*))&Derived::Traverse##NAME) \
+ GCC_CAST(CLASS)&Derived::Traverse##NAME) \
return getDerived().WalkUpFrom##NAME(static_cast<CLASS*>(VAR)); \
EnqueueChildren = false; \
return getDerived().Traverse##NAME(static_cast<CLASS*>(VAR));
@@ -509,6 +516,7 @@ bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
}
#undef DISPATCH_WALK
+#undef GCC_CAST
return true;
}
View
@@ -4105,7 +4105,7 @@ class PackExpansionType : public Type, public llvm::FoldingSetNode {
PackExpansionType(QualType Pattern, QualType Canon,
llvm::Optional<unsigned> NumExpansions)
- : Type(PackExpansion, Canon, /*Dependent=*/true,
+ : Type(PackExpansion, Canon, /*Dependent=*/Pattern->isDependentType(),
/*InstantiationDependent=*/true,
/*VariableModified=*/Pattern->isVariablyModifiedType(),
/*ContainsUnexpandedParameterPack=*/false),
@@ -0,0 +1,90 @@
+//===--- RefactoringCallbacks.h - Structural query framework ----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Provides callbacks to make common kinds of refactorings easy.
+//
+// The general idea is to construct a matcher expression that describes a
+// subtree match on the AST and then replace the corresponding source code
+// either by some specific text or some other AST node.
+//
+// Example:
+// int main(int argc, char **argv) {
+// ClangTool Tool(argc, argv);
+// MatchFinder Finder;
+// ReplaceStmtWithText Callback("integer", "42");
+// Finder.AddMatcher(id("integer", expression(integerLiteral())), Callback);
+// return Tool.run(newFrontendActionFactory(&Finder));
+// }
+//
+// This will replace all integer literals with "42".
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_MATCHERS_REFACTORING_CALLBACKS_H
+#define LLVM_CLANG_AST_MATCHERS_REFACTORING_CALLBACKS_H
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/Refactoring.h"
+
+namespace clang {
+namespace ast_matchers {
+
+/// \brief Base class for RefactoringCallbacks.
+///
+/// Collects \c tooling::Replacements while running.
+class RefactoringCallback : public MatchFinder::MatchCallback {
+public:
+ RefactoringCallback();
+ tooling::Replacements &getReplacements();
+
+protected:
+ tooling::Replacements Replace;
+};
+
+/// \brief Replace the text of the statement bound to \c FromId with the text in
+/// \c ToText.
+class ReplaceStmtWithText : public RefactoringCallback {
+public:
+ ReplaceStmtWithText(StringRef FromId, StringRef ToText);
+ virtual void run(const MatchFinder::MatchResult &Result);
+
+private:
+ std::string FromId;
+ std::string ToText;
+};
+
+/// \brief Replace the text of the statement bound to \c FromId with the text of
+/// the statement bound to \c ToId.
+class ReplaceStmtWithStmt : public RefactoringCallback {
+public:
+ ReplaceStmtWithStmt(StringRef FromId, StringRef ToId);
+ virtual void run(const MatchFinder::MatchResult &Result);
+
+private:
+ std::string FromId;
+ std::string ToId;
+};
+
+/// \brief Replace an if-statement bound to \c Id with the outdented text of its
+/// body, choosing the consequent or the alternative based on whether
+/// \c PickTrueBranch is true.
+class ReplaceIfStmtWithItsBody : public RefactoringCallback {
+public:
+ ReplaceIfStmtWithItsBody(StringRef Id, bool PickTrueBranch);
+ virtual void run(const MatchFinder::MatchResult &Result);
+
+private:
+ std::string Id;
+ const bool PickTrueBranch;
+};
+
+} // end namespace ast_matchers
+} // end namespace clang
+
+#endif // LLVM_CLANG_AST_MATCHERS_REFACTORING_CALLBACKS_H
@@ -1149,7 +1149,7 @@ def err_init_conversion_failed : Error<
"exception object|a member subobject|an array element|a new value|a value|a "
"base class|a constructor delegation|a vector element}0 "
"%diff{of type $ with an %select{rvalue|lvalue}2 of type $|"
- "with an %select{rvalue|lvalue} of incompatible type}1,3"
+ "with an %select{rvalue|lvalue}2 of incompatible type}1,3"
"%select{|: different classes%diff{ ($ vs $)|}5,6"
"|: different number of parameters (%5 vs %6)"
"|: type mismatch at %ordinal5 parameter%diff{ ($ vs $)|}6,7"
@@ -4580,7 +4580,7 @@ def err_typecheck_convert_incompatible : Error<
"|%diff{returning $ from a function with incompatible result type $|"
"returning type from a function with incompatible result type}0,1"
"|%diff{converting $ to incompatible type $|"
- "converting type to incompatible type}"
+ "converting type to incompatible type}0,1"
"|%diff{initializing $ with an expression of incompatible type $|"
"initializing type with an expression of incompatible type}0,1"
"|%diff{sending $ to parameter of incompatible type $|"
@@ -4613,7 +4613,7 @@ def warn_incompatible_qualified_id : Warning<
"|%diff{returning $ from a function with incompatible result type $|"
"returning type from a function with incompatible result type}0,1"
"|%diff{converting $ to incompatible type $|"
- "converting type to incompatible type}"
+ "converting type to incompatible type}0,1"
"|%diff{initializing $ with an expression of incompatible type $|"
"initializing type with an expression of incompatible type}0,1"
"|%diff{sending $ to parameter of incompatible type $|"
View
@@ -5691,16 +5691,14 @@ class Sema {
/// template-id.
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
TemplateDecl *Template,
- const TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs,
+ ArrayRef<TemplateArgument> TemplateArgs,
SourceRange InstantiationRange = SourceRange());
/// \brief Note that we are instantiating a default argument in a
/// template-id.
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
FunctionTemplateDecl *FunctionTemplate,
- const TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs,
+ ArrayRef<TemplateArgument> TemplateArgs,
ActiveTemplateInstantiation::InstantiationKind Kind,
sema::TemplateDeductionInfo &DeductionInfo,
SourceRange InstantiationRange = SourceRange());
@@ -5710,40 +5708,35 @@ class Sema {
/// specialization.
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
ClassTemplatePartialSpecializationDecl *PartialSpec,
- const TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs,
+ ArrayRef<TemplateArgument> TemplateArgs,
sema::TemplateDeductionInfo &DeductionInfo,
SourceRange InstantiationRange = SourceRange());
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
ParmVarDecl *Param,
- const TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs,
+ ArrayRef<TemplateArgument> TemplateArgs,
SourceRange InstantiationRange = SourceRange());
/// \brief Note that we are substituting prior template arguments into a
/// non-type or template template parameter.
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
NamedDecl *Template,
NonTypeTemplateParmDecl *Param,
- const TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs,
+ ArrayRef<TemplateArgument> TemplateArgs,
SourceRange InstantiationRange);
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
NamedDecl *Template,
TemplateTemplateParmDecl *Param,
- const TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs,
+ ArrayRef<TemplateArgument> TemplateArgs,
SourceRange InstantiationRange);
/// \brief Note that we are checking the default template argument
/// against the template parameter for a given template-id.
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
TemplateDecl *Template,
NamedDecl *Param,
- const TemplateArgument *TemplateArgs,
- unsigned NumTemplateArgs,
+ ArrayRef<TemplateArgument> TemplateArgs,
SourceRange InstantiationRange);
@@ -0,0 +1,80 @@
+//===- CommandLineClangTool.h - command-line clang tools driver -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the CommandLineClangTool class used to run clang
+// tools as separate command-line applications with a consistent common
+// interface for handling compilation database and input files.
+//
+// It provides a common subset of command-line options, common algorithm
+// for locating a compilation database and source files, and help messages
+// for the basic command-line interface.
+//
+// It creates a CompilationDatabase, initializes a ClangTool and runs a
+// user-specified FrontendAction over all TUs in which the given files are
+// compiled.
+//
+// This class uses the Clang Tooling infrastructure, see
+// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
+// for details on setting it up with LLVM source tree.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMANDLINECLANGTOOL_H
+#define LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMANDLINECLANGTOOL_H
+
+#include "llvm/Support/CommandLine.h"
+#include "clang/Tooling/CompilationDatabase.h"
+
+namespace clang {
+
+namespace tooling {
+
+class CompilationDatabase;
+class FrontendActionFactory;
+
+/// \brief A common driver for command-line Clang tools.
+///
+/// Parses a common subset of command-line arguments, locates and loads a
+/// compilation commands database, runs a tool with user-specified action. It
+/// also contains a help message for the common command-line options.
+/// An example of usage:
+/// @code
+/// int main(int argc, const char **argv) {
+/// CommandLineClangTool Tool;
+/// cl::extrahelp MoreHelp("\nMore help text...");
+/// Tool.initialize(argc, argv);
+/// return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>());
+/// }
+/// @endcode
+///
+class CommandLineClangTool {
+public:
+ /// Sets up command-line options and help messages.
+ /// Add your own help messages after constructing this tool.
+ CommandLineClangTool();
+
+ /// Parses command-line, initializes a compilation database.
+ /// This method exits program in case of error.
+ void initialize(int argc, const char **argv);
+
+ /// Runs a clang tool with an action created by \c ActionFactory.
+ int run(FrontendActionFactory *ActionFactory);
+
+private:
+ llvm::OwningPtr<CompilationDatabase> Compilations;
+ llvm::cl::opt<std::string> BuildPath;
+ llvm::cl::list<std::string> SourcePaths;
+ llvm::cl::extrahelp MoreHelp;
+};
+
+} // namespace tooling
+
+} // namespace clang
+
+#endif // LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMANDLINECLANGTOOL_H
@@ -86,7 +86,8 @@ FrontendActionFactory *newFrontendActionFactory();
/// FrontendActionFactory *FactoryAdapter =
/// newFrontendActionFactory(&Factory);
template <typename FactoryT>
-FrontendActionFactory *newFrontendActionFactory(FactoryT *ConsumerFactory);
+inline FrontendActionFactory *newFrontendActionFactory(
+ FactoryT *ConsumerFactory);
/// \brief Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag.
///
@@ -202,7 +203,8 @@ FrontendActionFactory *newFrontendActionFactory() {
}
template <typename FactoryT>
-FrontendActionFactory *newFrontendActionFactory(FactoryT *ConsumerFactory) {
+inline FrontendActionFactory *newFrontendActionFactory(
+ FactoryT *ConsumerFactory) {
class FrontendActionFactoryAdapter : public FrontendActionFactory {
public:
explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory)
View
@@ -2892,10 +2892,17 @@ QualType ASTContext::getPackExpansionType(QualType Pattern,
QualType Canon;
if (!Pattern.isCanonical()) {
- Canon = getPackExpansionType(getCanonicalType(Pattern), NumExpansions);
-
- // Find the insert position again.
- PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos);
+ Canon = getCanonicalType(Pattern);
+ // The canonical type might not contain an unexpanded parameter pack, if it
+ // contains an alias template specialization which ignores one of its
+ // parameters.
+ if (Canon->containsUnexpandedParameterPack()) {
+ Canon = getPackExpansionType(getCanonicalType(Pattern), NumExpansions);
+
+ // Find the insert position again, in case we inserted an element into
+ // PackExpansionTypes and invalidated our insert position.
+ PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos);
+ }
}
T = new (*this) PackExpansionType(Pattern, Canon, NumExpansions);
Oops, something went wrong.

0 comments on commit aadc131

Please sign in to comment.