[PATCH] D26564: Use PIC relocation mode by default for PowerPC64 ELF

2016-12-13 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel accepted this revision.
hfinkel added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D26564



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


[clang-tools-extra] r289637 - [clang-tidy] Suggest including if necessary in type-promotion-in-math-fn-check.

2016-12-13 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Wed Dec 14 00:52:23 2016
New Revision: 289637

URL: http://llvm.org/viewvc/llvm-project?rev=289637=rev
Log:
[clang-tidy] Suggest including  if necessary in 
type-promotion-in-math-fn-check.

Reviewers: alexfh

Subscribers: JDevlieghere, cfe-commits

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

Modified:

clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h

clang-tools-extra/trunk/test/clang-tidy/performance-type-promotion-in-math-fn.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp?rev=289637=289636=289637=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp 
Wed Dec 14 00:52:23 2016
@@ -10,6 +10,8 @@
 #include "TypePromotionInMathFnCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/StringSet.h"
 
 using namespace clang::ast_matchers;
@@ -27,6 +29,26 @@ AST_MATCHER_P(Type, isBuiltinType, Built
 }
 } // anonymous namespace
 
+TypePromotionInMathFnCheck::TypePromotionInMathFnCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.get("IncludeStyle", "llvm"))) {}
+
+void TypePromotionInMathFnCheck::registerPPCallbacks(
+CompilerInstance ) {
+  IncludeInserter = llvm::make_unique(
+  Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle);
+  Compiler.getPreprocessor().addPPCallbacks(
+  IncludeInserter->CreatePPCallbacks());
+}
+
+void TypePromotionInMathFnCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "IncludeStyle",
+utils::IncludeSorter::toString(IncludeStyle));
+}
+
 void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) {
   constexpr BuiltinType::Kind IntTy = BuiltinType::Int;
   constexpr BuiltinType::Kind LongTy = BuiltinType::Long;
@@ -153,18 +175,29 @@ void TypePromotionInMathFnCheck::check(c
   bool StdFnRequiresCpp11 = Cpp11OnlyFns.count(OldFnName);
 
   std::string NewFnName;
+  bool FnInCmath = false;
   if (getLangOpts().CPlusPlus &&
-  (!StdFnRequiresCpp11 || getLangOpts().CPlusPlus11))
+  (!StdFnRequiresCpp11 || getLangOpts().CPlusPlus11)) {
 NewFnName = ("std::" + OldFnName).str();
-  else
+FnInCmath = true;
+  } else {
 NewFnName = (OldFnName + "f").str();
+  }
 
-  diag(Call->getExprLoc(), "call to '%0' promotes float to double")
-  << OldFnName << FixItHint::CreateReplacement(
-  Call->getCallee()->getSourceRange(), NewFnName);
-
-  // FIXME: Perhaps we should suggest #include  if we suggest a cmath
-  // function and cmath is not already included.
+  auto Diag = diag(Call->getExprLoc(), "call to '%0' promotes float to double")
+  << OldFnName
+  << FixItHint::CreateReplacement(
+ Call->getCallee()->getSourceRange(), NewFnName);
+
+  // Suggest including  if the function we're suggesting is declared in
+  //  and it's not already included.  We never have to suggest including
+  // , because the functions we're suggesting moving away from are all
+  // declared in .
+  if (FnInCmath)
+if (auto IncludeFixit = IncludeInserter->CreateIncludeInsertion(
+Result.Context->getSourceManager().getFileID(Call->getLocStart()),
+"cmath", /*IsAngled=*/true))
+  Diag << *IncludeFixit;
 }
 
 } // namespace performance

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h?rev=289637=289636=289637=diff
==
--- clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h 
Wed Dec 14 00:52:23 2016
@@ -11,6 +11,7 @@
 #define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_TYPE_PROMOTION_IN_MATH_FN_H
 
 #include "../ClangTidy.h"
+#include "../utils/IncludeInserter.h"
 
 namespace clang {
 namespace tidy {
@@ -27,10 +28,16 @@ namespace performance {
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/performance-type-promotion-in-math-fn.html
 class TypePromotionInMathFnCheck : public ClangTidyCheck {
 public:
-  TypePromotionInMathFnCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, 

[PATCH] D27748: [clang-tidy] Suggest including if necessary in type-promotion-in-math-fn-check.

2016-12-13 Thread Justin Lebar via Phabricator via cfe-commits
jlebar marked 2 inline comments as done.
jlebar added a comment.

Thank you for the review, @alexfh.  I will commit with these changes.




Comment at: 
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp:198
+Result.Context->getSourceManager().getFileID(Call->getLocStart()),
+"cmath", /* IsAngled = */ true))
+  D << *IncludeFixit;

alexfh wrote:
> Remove all spaces inside the argument comment, it's more common that way and 
> clang-format understand it better.
Done, but FWIW it seems that clang-format will not insert a linebreak between 
the comment and the arg even with the spaces.  It is much more common in llvm, 
though, as you say.


https://reviews.llvm.org/D27748



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


[PATCH] D27748: [clang-tidy] Suggest including if necessary in type-promotion-in-math-fn-check.

2016-12-13 Thread Justin Lebar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jlebar marked an inline comment as done.
Closed by commit rL289637: [clang-tidy] Suggest including  if necessary 
in type-promotion-in-math… (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D27748?vs=81347=81348#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27748

Files:
  clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h
  
clang-tools-extra/trunk/test/clang-tidy/performance-type-promotion-in-math-fn.cpp

Index: clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h
+++ clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_TYPE_PROMOTION_IN_MATH_FN_H
 
 #include "../ClangTidy.h"
+#include "../utils/IncludeInserter.h"
 
 namespace clang {
 namespace tidy {
@@ -27,10 +28,16 @@
 /// http://clang.llvm.org/extra/clang-tidy/checks/performance-type-promotion-in-math-fn.html
 class TypePromotionInMathFnCheck : public ClangTidyCheck {
 public:
-  TypePromotionInMathFnCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  TypePromotionInMathFnCheck(StringRef Name, ClangTidyContext *Context);
+
+  void registerPPCallbacks(CompilerInstance ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+
+private:
+  std::unique_ptr IncludeInserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
 };
 
 } // namespace performance
Index: clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
@@ -10,6 +10,8 @@
 #include "TypePromotionInMathFnCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/StringSet.h"
 
 using namespace clang::ast_matchers;
@@ -27,6 +29,26 @@
 }
 } // anonymous namespace
 
+TypePromotionInMathFnCheck::TypePromotionInMathFnCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.get("IncludeStyle", "llvm"))) {}
+
+void TypePromotionInMathFnCheck::registerPPCallbacks(
+CompilerInstance ) {
+  IncludeInserter = llvm::make_unique(
+  Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle);
+  Compiler.getPreprocessor().addPPCallbacks(
+  IncludeInserter->CreatePPCallbacks());
+}
+
+void TypePromotionInMathFnCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "IncludeStyle",
+utils::IncludeSorter::toString(IncludeStyle));
+}
+
 void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) {
   constexpr BuiltinType::Kind IntTy = BuiltinType::Int;
   constexpr BuiltinType::Kind LongTy = BuiltinType::Long;
@@ -153,18 +175,29 @@
   bool StdFnRequiresCpp11 = Cpp11OnlyFns.count(OldFnName);
 
   std::string NewFnName;
+  bool FnInCmath = false;
   if (getLangOpts().CPlusPlus &&
-  (!StdFnRequiresCpp11 || getLangOpts().CPlusPlus11))
+  (!StdFnRequiresCpp11 || getLangOpts().CPlusPlus11)) {
 NewFnName = ("std::" + OldFnName).str();
-  else
+FnInCmath = true;
+  } else {
 NewFnName = (OldFnName + "f").str();
+  }
 
-  diag(Call->getExprLoc(), "call to '%0' promotes float to double")
-  << OldFnName << FixItHint::CreateReplacement(
-  Call->getCallee()->getSourceRange(), NewFnName);
-
-  // FIXME: Perhaps we should suggest #include  if we suggest a cmath
-  // function and cmath is not already included.
+  auto Diag = diag(Call->getExprLoc(), "call to '%0' promotes float to double")
+  << OldFnName
+  << FixItHint::CreateReplacement(
+ Call->getCallee()->getSourceRange(), NewFnName);
+
+  // Suggest including  if the function we're suggesting is declared in
+  //  and it's not already included.  We never have to suggest including
+  // , because the functions we're suggesting moving away from are all
+  // declared in .
+  if (FnInCmath)
+if (auto IncludeFixit = IncludeInserter->CreateIncludeInsertion(
+Result.Context->getSourceManager().getFileID(Call->getLocStart()),
+"cmath", /*IsAngled=*/true))
+  Diag << *IncludeFixit;
 }
 
 } // namespace 

[PATCH] D27377: clang-format: Support the Java 8 'default' method modifier

2016-12-13 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good. Thank you!


https://reviews.llvm.org/D27377



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


[PATCH] D27748: [clang-tidy] Suggest including if necessary in type-promotion-in-math-fn-check.

2016-12-13 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

LG with a couple of nits.


https://reviews.llvm.org/D27748



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


[PATCH] D27748: [clang-tidy] Suggest including if necessary in type-promotion-in-math-fn-check.

2016-12-13 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp:187
 
-  diag(Call->getExprLoc(), "call to '%0' promotes float to double")
-  << OldFnName << FixItHint::CreateReplacement(
-  Call->getCallee()->getSourceRange(), NewFnName);
+  auto D = diag(Call->getExprLoc(), "call to '%0' promotes float to double")
+   << OldFnName << FixItHint::CreateReplacement(

s/D/Diag/



Comment at: 
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp:198
+Result.Context->getSourceManager().getFileID(Call->getLocStart()),
+"cmath", /* IsAngled = */ true))
+  D << *IncludeFixit;

Remove all spaces inside the argument comment, it's more common that way and 
clang-format understand it better.


https://reviews.llvm.org/D27748



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


[PATCH] D27284: [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-12-13 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

Sent https://reviews.llvm.org/D27748 for #include suggestion.


Repository:
  rL LLVM

https://reviews.llvm.org/D27284



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


[PATCH] D27748: [clang-tidy] Suggest including if necessary in type-promotion-in-math-fn-check.

2016-12-13 Thread Justin Lebar via Phabricator via cfe-commits
jlebar created this revision.
jlebar added a reviewer: alexfh.
jlebar added a subscriber: cfe-commits.
Herald added a subscriber: JDevlieghere.

https://reviews.llvm.org/D27748

Files:
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
  clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp

Index: clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
===
--- clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
+++ clang-tools-extra/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
@@ -1,5 +1,7 @@
 // RUN: %check_clang_tidy %s performance-type-promotion-in-math-fn %t
 
+// CHECK-FIXES: #include 
+
 double acos(double);
 double acosh(double);
 double asin(double);
Index: clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
===
--- clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
+++ clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.h
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_TYPE_PROMOTION_IN_MATH_FN_H
 
 #include "../ClangTidy.h"
+#include "../utils/IncludeInserter.h"
 
 namespace clang {
 namespace tidy {
@@ -27,10 +28,16 @@
 /// http://clang.llvm.org/extra/clang-tidy/checks/performance-type-promotion-in-math-fn.html
 class TypePromotionInMathFnCheck : public ClangTidyCheck {
 public:
-  TypePromotionInMathFnCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  TypePromotionInMathFnCheck(StringRef Name, ClangTidyContext *Context);
+
+  void registerPPCallbacks(CompilerInstance ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
+
+private:
+  std::unique_ptr IncludeInserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
 };
 
 } // namespace performance
Index: clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
@@ -10,6 +10,8 @@
 #include "TypePromotionInMathFnCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/StringSet.h"
 
 using namespace clang::ast_matchers;
@@ -27,6 +29,26 @@
 }
 } // anonymous namespace
 
+TypePromotionInMathFnCheck::TypePromotionInMathFnCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.get("IncludeStyle", "llvm"))) {}
+
+void TypePromotionInMathFnCheck::registerPPCallbacks(
+CompilerInstance ) {
+  IncludeInserter = llvm::make_unique(
+  Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle);
+  Compiler.getPreprocessor().addPPCallbacks(
+  IncludeInserter->CreatePPCallbacks());
+}
+
+void TypePromotionInMathFnCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "IncludeStyle",
+utils::IncludeSorter::toString(IncludeStyle));
+}
+
 void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) {
   constexpr BuiltinType::Kind IntTy = BuiltinType::Int;
   constexpr BuiltinType::Kind LongTy = BuiltinType::Long;
@@ -153,18 +175,28 @@
   bool StdFnRequiresCpp11 = Cpp11OnlyFns.count(OldFnName);
 
   std::string NewFnName;
+  bool FnInCmath = false;
   if (getLangOpts().CPlusPlus &&
-  (!StdFnRequiresCpp11 || getLangOpts().CPlusPlus11))
+  (!StdFnRequiresCpp11 || getLangOpts().CPlusPlus11)) {
 NewFnName = ("std::" + OldFnName).str();
-  else
+FnInCmath = true;
+  } else {
 NewFnName = (OldFnName + "f").str();
+  }
 
-  diag(Call->getExprLoc(), "call to '%0' promotes float to double")
-  << OldFnName << FixItHint::CreateReplacement(
-  Call->getCallee()->getSourceRange(), NewFnName);
+  auto D = diag(Call->getExprLoc(), "call to '%0' promotes float to double")
+   << OldFnName << FixItHint::CreateReplacement(
+   Call->getCallee()->getSourceRange(), NewFnName);
 
-  // FIXME: Perhaps we should suggest #include  if we suggest a cmath
-  // function and cmath is not already included.
+  // Suggest including  if the function we're suggesting is declared in
+  //  and it's not already included.  We never have to suggest including
+  // , because the functions we're suggesting moving away from are all
+  // declared in .
+  if (FnInCmath)
+if (auto 

[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-13 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.

LGTM other than a few style comments. Please clang-format before committing. 
Some of the formatting looks off (although that might just be my phone).




Comment at: lib/Support/PrettyStackTrace.cpp:152
+  va_start(ap, format);
+  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
+  va_end(ap);

Your variable names are very LLDB-esque. Please follow the LLVM style guide, 
which is CamelCase.


Repository:
  rL LLVM

https://reviews.llvm.org/D27683



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


[PATCH] D23096: [Sema] Pass CombineWithOuterScope = true to constructor of LocalInstantiationScope

2016-12-13 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff accepted this revision.
sepavloff added a comment.
This revision is now accepted and ready to land.

Looks good. Thank you!


https://reviews.llvm.org/D23096



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


r289276 - [modules] Add optional out-param to ASTReader::ReadAST for imported submodules.

2016-12-13 Thread Graydon Hoare via cfe-commits
Author: graydon
Date: Fri Dec  9 15:45:49 2016
New Revision: 289276

URL: http://llvm.org/viewvc/llvm-project?rev=289276=rev
Log:
[modules] Add optional out-param to ASTReader::ReadAST for imported submodules.

Summary:
The Swift frontend is acquiring the ability to load non-module PCH files 
containing
bridging definitions from C/ObjC. As part of this work, it needs to know which 
submodules
were imported by a PCH in order to wrap them in local Swift modules. This 
information
is collected by ASTReader::ReadAST in a local vector, but is currently kept 
private.

The change here is just to make the type of the vector elements public, and 
provide
an optional out-parameter to the ReadAST method to provide the vector's 
contents to
a caller after a successful read.

Reviewers: manmanren, rsmith, doug.gregor

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=289276=289275=289276=diff
==
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri Dec  9 15:45:49 2016
@@ -821,6 +821,7 @@ private:
   // \brief A list of late parsed template function data.
   SmallVector LateParsedTemplates;
 
+public:
   struct ImportedSubmodule {
 serialization::SubmoduleID ID;
 SourceLocation ImportLoc;
@@ -829,6 +830,7 @@ private:
   : ID(ID), ImportLoc(ImportLoc) {}
   };
 
+private:
   /// \brief A list of modules that were imported by precompiled headers or
   /// any other non-module AST file.
   SmallVector ImportedModules;
@@ -1404,9 +1406,13 @@ public:
   /// \param ClientLoadCapabilities The set of client load-failure
   /// capabilities, represented as a bitset of the enumerators of
   /// LoadFailureCapabilities.
+  ///
+  /// \param Imported optional out-parameter to append the list of modules
+  /// that were imported by precompiled headers or any other non-module AST 
file
   ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
 SourceLocation ImportLoc,
-unsigned ClientLoadCapabilities);
+unsigned ClientLoadCapabilities,
+SmallVectorImpl *Imported = 
nullptr);
 
   /// \brief Make the entities in the given module and any of its 
(non-explicit)
   /// submodules visible to name lookup.

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=289276=289275=289276=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Dec  9 15:45:49 2016
@@ -3578,7 +3578,8 @@ static bool SkipCursorToBlock(BitstreamC
 ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
 ModuleKind Type,
 SourceLocation ImportLoc,
-unsigned ClientLoadCapabilities) {
+unsigned ClientLoadCapabilities,
+SmallVectorImpl 
*Imported) {
   llvm::SaveAndRestore
 SetCurImportLocRAII(CurrentImportLoc, ImportLoc);
 
@@ -3744,6 +3745,10 @@ ASTReader::ASTReadResult ASTReader::Read
   }
   UnresolvedModuleRefs.clear();
 
+  if (Imported)
+Imported->append(ImportedModules.begin(),
+ ImportedModules.end());
+
   // FIXME: How do we load the 'use'd modules? They may not be submodules.
   // Might be unnecessary as use declarations are only used to build the
   // module itself.


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


r289536 - [OpenCL] Improve address space diagnostics.

2016-12-13 Thread Egor Churaev via cfe-commits
Author: echuraev
Date: Tue Dec 13 08:07:23 2016
New Revision: 289536

URL: http://llvm.org/viewvc/llvm-project?rev=289536=rev
Log:
[OpenCL] Improve address space diagnostics.

Reviewers: Anastasia

Subscribers: bader, yaxunl, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/invalid-kernel.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=289536=289535=289536=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 13 08:07:23 
2016
@@ -8076,8 +8076,9 @@ def err_static_kernel : Error<
   "kernel functions cannot be declared static">;
 def err_opencl_ptrptr_kernel_param : Error<
   "kernel parameter cannot be declared as a pointer to a pointer">;
-def err_opencl_private_ptr_kernel_param : Error<
-  "kernel parameter cannot be declared as a pointer to the __private address 
space">;
+def err_kernel_arg_address_space : Error<
+  "pointer arguments to kernel functions must reside in '__global', "
+  "'__constant' or '__local' address space">;
 def err_opencl_function_variable : Error<
   "%select{non-kernel function|function scope}0 variable cannot be declared in 
%1 address space">;
 def err_static_function_scope : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=289536=289535=289536=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Dec 13 08:07:23 2016
@@ -7586,7 +7586,7 @@ enum OpenCLParamType {
   ValidKernelParam,
   PtrPtrKernelParam,
   PtrKernelParam,
-  PrivatePtrKernelParam,
+  InvalidAddrSpacePtrKernelParam,
   InvalidKernelParam,
   RecordKernelParam
 };
@@ -7596,8 +7596,10 @@ static OpenCLParamType getOpenCLKernelPa
 QualType PointeeType = PT->getPointeeType();
 if (PointeeType->isPointerType())
   return PtrPtrKernelParam;
-return PointeeType.getAddressSpace() == 0 ? PrivatePtrKernelParam
-  : PtrKernelParam;
+if (PointeeType.getAddressSpace() == LangAS::opencl_generic ||
+PointeeType.getAddressSpace() == 0)
+  return InvalidAddrSpacePtrKernelParam;
+return PtrKernelParam;
   }
 
   // TODO: Forbid the other integer types (size_t, ptrdiff_t...) when they can
@@ -7645,11 +7647,12 @@ static void checkIsValidOpenCLKernelPara
 D.setInvalidType();
 return;
 
-  case PrivatePtrKernelParam:
-// OpenCL v1.2 s6.9.a:
-// A kernel function argument cannot be declared as a
-// pointer to the private address space.
-S.Diag(Param->getLocation(), diag::err_opencl_private_ptr_kernel_param);
+  case InvalidAddrSpacePtrKernelParam:
+// OpenCL v1.0 s6.5:
+// __kernel function arguments declared to be a pointer of a type can point
+// to one of the following address spaces only : __global, __local or
+// __constant.
+S.Diag(Param->getLocation(), diag::err_kernel_arg_address_space);
 D.setInvalidType();
 return;
 
@@ -7736,7 +7739,7 @@ static void checkIsValidOpenCLKernelPara
   // do not allow OpenCL objects to be passed as elements of the struct or
   // union.
   if (ParamType == PtrKernelParam || ParamType == PtrPtrKernelParam ||
-  ParamType == PrivatePtrKernelParam) {
+  ParamType == InvalidAddrSpacePtrKernelParam) {
 S.Diag(Param->getLocation(),
diag::err_record_with_pointers_kernel_param)
   << PT->isUnionType()

Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel.cl?rev=289536=289535=289536=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-kernel.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel.cl Tue Dec 13 08:07:23 2016
@@ -1,10 +1,11 @@
 // RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -verify %s
 
-kernel void no_ptrptr(global int **i) { } // expected-error{{kernel parameter 
cannot be declared as a pointer to a pointer}}
+kernel void no_ptrptr(global int * global *i) { } // expected-error{{kernel 
parameter cannot be declared as a pointer to a pointer}}
 
-__kernel void no_privateptr(__private int *i) { } // expected-error {{kernel 
parameter cannot be declared as a pointer to the __private address space}}
+__kernel void no_privateptr(__private int *i) { } // expected-error {{pointer 
arguments to kernel functions must reside in '__global', '__constant' or 
'__local' address space}}
 
-__kernel void 

r289535 - [OpenCL] Enable unroll hint for OpenCL 1.x.

2016-12-13 Thread Egor Churaev via cfe-commits
Author: echuraev
Date: Tue Dec 13 08:02:35 2016
New Revision: 289535

URL: http://llvm.org/viewvc/llvm-project?rev=289535=rev
Log:
[OpenCL] Enable unroll hint for OpenCL 1.x.

Summary: Although the feature was introduced only in OpenCL C v2.0 spec., it's 
useful for OpenCL 1.x too and doesn't require HW support.

Reviewers: Anastasia

Subscribers: yaxunl, cfe-commits, bader

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

Modified:
cfe/trunk/lib/Sema/SemaStmtAttr.cpp
cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl
cfe/trunk/test/SemaOpenCL/unroll-hint.cl

Modified: cfe/trunk/lib/Sema/SemaStmtAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAttr.cpp?rev=289535=289534=289535=diff
==
--- cfe/trunk/lib/Sema/SemaStmtAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAttr.cpp Tue Dec 13 08:02:35 2016
@@ -225,16 +225,12 @@ CheckForIncompatibleAttributes(Sema ,
 
 static Attr *handleOpenCLUnrollHint(Sema , Stmt *St, const AttributeList ,
 SourceRange Range) {
-  // OpenCL v2.0 s6.11.5 - opencl_unroll_hint can have 0 arguments (compiler
+  // Although the feature was introduced only in OpenCL C v2.0 s6.11.5, it's
+  // useful for OpenCL 1.x too and doesn't require HW support.
+  // opencl_unroll_hint can have 0 arguments (compiler
   // determines unrolling factor) or 1 argument (the unroll factor provided
   // by the user).
 
-  if (S.getLangOpts().OpenCLVersion < 200) {
-S.Diag(A.getLoc(), diag::err_attribute_requires_opencl_version)
-<< A.getName() << "2.0" << 1;
-return nullptr;
-  }
-
   unsigned NumArgs = A.getNumArgs();
 
   if (NumArgs > 1) {

Modified: cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl?rev=289535=289534=289535=diff
==
--- cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/unroll-hint.cl Tue Dec 13 08:02:35 2016
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL1.2 -o - %s | FileCheck %s
 
 /*** for ***/
 void for_count()

Modified: cfe/trunk/test/SemaOpenCL/unroll-hint.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/unroll-hint.cl?rev=289535=289534=289535=diff
==
--- cfe/trunk/test/SemaOpenCL/unroll-hint.cl (original)
+++ cfe/trunk/test/SemaOpenCL/unroll-hint.cl Tue Dec 13 08:02:35 2016
@@ -1,17 +1,5 @@
-//RUN: %clang_cc1 -O0 -fsyntax-only -verify %s
-//RUN: %clang_cc1 -O0 -cl-std=CL2.0 -fsyntax-only -verify -DCL20 %s
+//RUN: %clang_cc1 -O0 -cl-std=CL2.0 -fsyntax-only -verify %s
 
-kernel void D (global int *x) {
-  int i = 10;
-#ifndef CL20
-  // expected-error@+2 {{'opencl_unroll_hint' attribute requires OpenCL 
version 2.0 or above}}
-#endif
-  __attribute__((opencl_unroll_hint))
-  do {
-  } while(i--);
-}
-
-#ifdef CL20
 kernel void C (global int *x) {
   int I = 3;
   __attribute__((opencl_unroll_hint(I))) // expected-error 
{{'opencl_unroll_hint' attribute requires an integer constant}}
@@ -27,4 +15,3 @@ kernel void F() {
   __attribute__((opencl_unroll_hint(-1))) // expected-error 
{{'opencl_unroll_hint' attribute requires a positive integral compile time 
constant expression}}
   for(int i=0; i<100; i++);
 }
-#endif


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


Re: [PATCH] D21695: [clang] Version support for UBSan handlers

2016-12-13 Thread Andrew Ford via cfe-commits
It does have c++11, but some functions are missing.  I don't know the
details of which ones are missing or why, have only seen std::to_string be
a problem so far.

On Mon, Dec 12, 2016 at 11:05 AM Filipe Cabecinhas <
filcab+llvm.phabrica...@gmail.com> wrote:

> Thanks Vedant!
> Andrew: does Android not support C++11? I don't understand why it wouldn't
> have these funcions.
>
> Thank you,
>
>  Filipe
>
> On Mon, 12 Dec 2016 at 18:58, Vedant Kumar  wrote:
>
>
>
> > On Dec 12, 2016, at 10:17 AM, Andrew Ford via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
> >
>
> > andrewford added a comment.
>
> >
>
> > This broke the build on android due to use of std::to_string. Would
> someone mind changing it to llvm::to_string, I don't have commit access to
> change it myself. Thanks!
>
>
>
> Should be done with r289452.
>
>
>
> vedant
>
>
>
> >
>
> >
>
> > Repository:
>
> >  rL LLVM
>
> >
>
> > https://reviews.llvm.org/D21695
>
> >
>
> >
>
> >
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r289630 - [c++1z] P0217R3: Allow by-value structured binding of arrays.

2016-12-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Dec 13 21:22:16 2016
New Revision: 289630

URL: http://llvm.org/viewvc/llvm-project?rev=289630=rev
Log:
[c++1z] P0217R3: Allow by-value structured binding of arrays.

Modified:
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p2.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/Sema/Initialization.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=289630=289629=289630=diff
==
--- cfe/trunk/include/clang/Sema/Initialization.h (original)
+++ cfe/trunk/include/clang/Sema/Initialization.h Tue Dec 13 21:22:16 2016
@@ -732,8 +732,9 @@ public:
 /// \brief Array initialization by elementwise copy.
 SK_ArrayLoopInit,
 /// \brief Array initialization (from an array rvalue).
-/// This is a GNU C extension.
 SK_ArrayInit,
+/// \brief Array initialization (from an array rvalue) as a GNU extension.
+SK_GNUArrayInit,
 /// \brief Array initialization from a parenthesized initializer list.
 /// This is a GNU C++ extension.
 SK_ParenthesizedArrayInit,
@@ -1123,7 +1124,7 @@ public:
   void AddArrayInitLoopStep(QualType T, QualType EltTy);
 
   /// \brief Add an array initialization step.
-  void AddArrayInitStep(QualType T);
+  void AddArrayInitStep(QualType T, bool IsGNUExtension);
 
   /// \brief Add a parenthesized array initialization step.
   void AddParenthesizedArrayInitStep(QualType T);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=289630=289629=289630=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Dec 13 21:22:16 2016
@@ -9653,9 +9653,6 @@ QualType Sema::deduceVarTypeFromInitiali
 
   VarDeclOrName VN{VDecl, Name};
 
-  // FIXME: Deduction for a decomposition declaration does weird things if the
-  // initializer is an array.
-
   ArrayRef DeduceInits = Init;
   if (DirectInit) {
 if (auto *PL = dyn_cast(Init))
@@ -9704,6 +9701,15 @@ QualType Sema::deduceVarTypeFromInitiali
 DefaultedAnyToId = true;
   }
 
+  // C++ [dcl.decomp]p1:
+  //   If the assignment-expression [...] has array type A and no ref-qualifier
+  //   is present, e has type cv A
+  if (VDecl && isa(VDecl) &&
+  Context.hasSameUnqualifiedType(Type, Context.getAutoDeductType()) &&
+  DeduceInit->getType()->isConstantArrayType())
+return Context.getQualifiedType(DeduceInit->getType(),
+Type.getQualifiers());
+
   QualType DeducedType;
   if (DeduceAutoType(TSI, DeduceInit, DeducedType) == DAR_Failed) {
 if (!IsInitCapture)

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=289630=289629=289630=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Dec 13 21:22:16 2016
@@ -3068,6 +3068,7 @@ void InitializationSequence::Step::Destr
   case SK_ArrayLoopIndex:
   case SK_ArrayLoopInit:
   case SK_ArrayInit:
+  case SK_GNUArrayInit:
   case SK_ParenthesizedArrayInit:
   case SK_PassByIndirectCopyRestore:
   case SK_PassByIndirectRestore:
@@ -3302,9 +3303,9 @@ void InitializationSequence::AddObjCObje
   Steps.push_back(S);
 }
 
-void InitializationSequence::AddArrayInitStep(QualType T) {
+void InitializationSequence::AddArrayInitStep(QualType T, bool IsGNUExtension) 
{
   Step S;
-  S.Kind = SK_ArrayInit;
+  S.Kind = IsGNUExtension ? SK_GNUArrayInit : SK_ArrayInit;
   S.Type = T;
   Steps.push_back(S);
 }
@@ -5217,8 +5218,7 @@ void InitializationSequence::InitializeF
 canPerformArrayCopy(Entity)) {
   // If source is a prvalue, use it directly.
   if (Initializer->getValueKind() == VK_RValue) {
-// FIXME: This produces a bogus extwarn
-AddArrayInitStep(DestType);
+AddArrayInitStep(DestType, /*IsGNUExtension*/false);
 return;
   }
 
@@ -5251,7 +5251,7 @@ void InitializationSequence::InitializeF
   else if (Initializer->HasSideEffects(S.Context))
 SetFailed(FK_NonConstantArrayInit);
   else {
-AddArrayInitStep(DestType);
+AddArrayInitStep(DestType, /*IsGNUExtension*/true);
   }
 }
 // Note: as a GNU C++ extension, we allow list-initialization of a
@@ -6520,6 +6520,7 @@ InitializationSequence::Perform(Sema ,
   case SK_ArrayLoopIndex:
   case SK_ArrayLoopInit:
   case SK_ArrayInit:
+  case SK_GNUArrayInit:
   case SK_ParenthesizedArrayInit:
   case SK_PassByIndirectCopyRestore:
   case SK_PassByIndirectRestore:
@@ -7011,13 +7012,14 @@ InitializationSequence::Perform(Sema ,
   break;
 }
 
-case 

[PATCH] D27284: [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-12-13 Thread Justin Lebar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289627: [ClangTidy] Add new 
performance-type-promotion-in-math-fn check. (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D27284?vs=80011=81339#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27284

Files:
  clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst
  
clang-tools-extra/trunk/test/clang-tidy/performance-type-promotion-in-math-fn.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
@@ -0,0 +1,314 @@
+// RUN: %check_clang_tidy %s performance-type-promotion-in-math-fn %t
+
+double acos(double);
+double acosh(double);
+double asin(double);
+double asinh(double);
+double atan2(double, double);
+double atan(double);
+double atanh(double);
+double cbrt(double);
+double ceil(double);
+double copysign(double, double);
+double cos(double);
+double cosh(double);
+double erfc(double);
+double erf(double);
+double exp2(double);
+double exp(double);
+double expm1(double);
+double fabs(double);
+double fdim(double, double);
+double floor(double);
+double fma(double, double, double);
+double fmax(double, double);
+double fmin(double, double);
+double fmod(double, double);
+double frexp(double, int *);
+double hypot(double, double);
+double ilogb(double);
+double ldexp(double, double);
+double lgamma(double);
+long long llrint(double);
+double log10(double);
+double log1p(double);
+double log2(double);
+double logb(double);
+double log(double);
+long lrint(double);
+double modf(double);
+double nearbyint(double);
+double nextafter(double, double);
+double nexttoward(double, long double);
+double pow(double, double);
+double remainder(double, double);
+double remquo(double, double, int *);
+double rint(double);
+double round(double);
+double scalbln(double, long);
+double scalbn(double, int);
+double sin(double);
+double sinh(double);
+double sqrt(double);
+double tan(double);
+double tanh(double);
+double tgamma(double);
+double trunc(double);
+long long llround(double);
+long lround(double);
+
+void check_all_fns() {
+  float a, b, c;
+  int i;
+  long l;
+  int *int_ptr;
+
+  acos(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acos' promotes float to double [performance-type-promotion-in-math-fn]
+  // CHECK-FIXES: {{^}}  std::acos(a);{{$}}
+  acosh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'acosh'
+  // CHECK-FIXES: {{^}}  std::acosh(a);{{$}}
+  asin(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asin'
+  // CHECK-FIXES: {{^}}  std::asin(a);{{$}}
+  asinh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'asinh'
+  // CHECK-FIXES: {{^}}  std::asinh(a);{{$}}
+  atan2(a, b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan2'
+  // CHECK-FIXES: {{^}}  std::atan2(a, b);{{$}}
+  atan(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atan'
+  // CHECK-FIXES: {{^}}  std::atan(a);{{$}}
+  atanh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'atanh'
+  // CHECK-FIXES: {{^}}  std::atanh(a);{{$}}
+  cbrt(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cbrt'
+  // CHECK-FIXES: {{^}}  std::cbrt(a);{{$}}
+  ceil(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'ceil'
+  // CHECK-FIXES: {{^}}  std::ceil(a);{{$}}
+  copysign(a, b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'copysign'
+  // CHECK-FIXES: {{^}}  std::copysign(a, b);{{$}}
+  cos(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cos'
+  // CHECK-FIXES: {{^}}  std::cos(a);{{$}}
+  cosh(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'cosh'
+  // CHECK-FIXES: {{^}}  std::cosh(a);{{$}}
+  erf(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'erf'
+  // CHECK-FIXES: {{^}}  std::erf(a);{{$}}
+  erfc(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'erfc'
+  // CHECK-FIXES: {{^}}  std::erfc(a);{{$}}
+  exp2(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'exp2'
+  // CHECK-FIXES: {{^}}  std::exp2(a);{{$}}
+  exp(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'exp'
+  // CHECK-FIXES: {{^}}  std::exp(a);{{$}}
+  expm1(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: call to 'expm1'
+  // CHECK-FIXES: {{^}}  std::expm1(a);{{$}}
+  fabs(a);
+  // 

[clang-tools-extra] r289627 - [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-12-13 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Tue Dec 13 21:15:01 2016
New Revision: 289627

URL: http://llvm.org/viewvc/llvm-project?rev=289627=rev
Log:
[ClangTidy] Add new performance-type-promotion-in-math-fn check.

Summary:
This checks for calls to double-precision math.h with single-precision
arguments.  For example, it suggests replacing ::sin(0.f) with
::sinf(0.f).

Subscribers: mgorny, cfe-commits

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

Added:

clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst

clang-tools-extra/trunk/test/clang-tidy/performance-type-promotion-in-math-fn.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt?rev=289627=289626=289627=diff
==
--- clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/CMakeLists.txt Tue Dec 13 
21:15:01 2016
@@ -6,6 +6,7 @@ add_clang_library(clangTidyPerformanceMo
   ImplicitCastInLoopCheck.cpp
   InefficientStringConcatenationCheck.cpp
   PerformanceTidyModule.cpp
+  TypePromotionInMathFnCheck.cpp
   UnnecessaryCopyInitialization.cpp
   UnnecessaryValueParamCheck.cpp
 

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp?rev=289627=289626=289627=diff
==
--- clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/performance/PerformanceTidyModule.cpp 
Tue Dec 13 21:15:01 2016
@@ -10,11 +10,11 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "InefficientStringConcatenationCheck.h"
-
 #include "FasterStringFindCheck.h"
 #include "ForRangeCopyCheck.h"
 #include "ImplicitCastInLoopCheck.h"
+#include "InefficientStringConcatenationCheck.h"
+#include "TypePromotionInMathFnCheck.h"
 #include "UnnecessaryCopyInitialization.h"
 #include "UnnecessaryValueParamCheck.h"
 
@@ -33,6 +33,8 @@ public:
 "performance-implicit-cast-in-loop");
 CheckFactories.registerCheck(
 "performance-inefficient-string-concatenation");
+CheckFactories.registerCheck(
+"performance-type-promotion-in-math-fn");
 CheckFactories.registerCheck(
 "performance-unnecessary-copy-initialization");
 CheckFactories.registerCheck(

Added: 
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp?rev=289627=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp 
(added)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp 
Tue Dec 13 21:15:01 2016
@@ -0,0 +1,172 @@
+//===--- TypePromotionInMathFnCheck.cpp - 
clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TypePromotionInMathFnCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace performance {
+
+namespace {
+AST_MATCHER_P(Type, isBuiltinType, BuiltinType::Kind, Kind) {
+  if (const auto *BT = dyn_cast()) {
+return BT->getKind() == Kind;
+  }
+  return false;
+}
+} // anonymous namespace
+
+void TypePromotionInMathFnCheck::registerMatchers(MatchFinder *Finder) {
+  constexpr BuiltinType::Kind IntTy = BuiltinType::Int;
+  constexpr BuiltinType::Kind LongTy = BuiltinType::Long;
+  constexpr BuiltinType::Kind FloatTy = BuiltinType::Float;
+  constexpr BuiltinType::Kind DoubleTy = BuiltinType::Double;
+  constexpr BuiltinType::Kind LongDoubleTy = BuiltinType::LongDouble;
+
+  auto hasBuiltinTyParam = [](int Pos, BuiltinType::Kind Kind) {
+return hasParameter(Pos, hasType(isBuiltinType(Kind)));
+  };
+  auto hasBuiltinTyArg = 

[PATCH] D27284: [ClangTidy] Add new performance-type-promotion-in-math-fn check.

2016-12-13 Thread Justin Lebar via Phabricator via cfe-commits
jlebar marked an inline comment as done.
jlebar added a comment.

In https://reviews.llvm.org/D27284#621052, @malcolm.parsons wrote:

> In https://reviews.llvm.org/D27284#609937, @Eugene.Zelenko wrote:
>
> > Please mention this check in docs/ReleaseNotes.rst (in alphabetical order).
>
>
> This has not been done.


Indeed, sorry I missed that.  Done now, will be reflected when I submit.




Comment at: 
clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp:167-168
+
+  // FIXME: Perhaps we should suggest #include  if we suggest a cmath
+  // function and cmath is not already included.
+}

alexfh wrote:
> We definitely should. See the use of IncludeInserter in 
> UnnecessaryValueParamCheck, for example. Fine for a follow-up.
OK, would rather send a followup because this patch is already nontrivial.  
I'll get to work on that -- thank you for the pointer.


https://reviews.llvm.org/D27284



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


r289625 - [PS4] Undo dialect tweak for Objective-C.

2016-12-13 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Tue Dec 13 20:06:11 2016
New Revision: 289625

URL: http://llvm.org/viewvc/llvm-project?rev=289625=rev
Log:
[PS4] Undo dialect tweak for Objective-C.

In r267772, we had set the PS4's default dialect for both C and
Objective-C to gnu99.  Make that change only for C; we don't really
support Objective-C/C++ so there's no point fiddling the dialect.

Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/SemaObjC/objcbridge-attribute-arc.m

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=289625=289624=289625=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Dec 13 20:06:11 2016
@@ -1558,14 +1558,16 @@ void CompilerInvocation::setLangDefaults
 case IK_Asm:
 case IK_C:
 case IK_PreprocessedC:
-case IK_ObjC:
-case IK_PreprocessedObjC:
   // The PS4 uses C99 as the default C standard.
   if (T.isPS4())
 LangStd = LangStandard::lang_gnu99;
   else
 LangStd = LangStandard::lang_gnu11;
   break;
+case IK_ObjC:
+case IK_PreprocessedObjC:
+  LangStd = LangStandard::lang_gnu11;
+  break;
 case IK_CXX:
 case IK_PreprocessedCXX:
 case IK_ObjCXX:

Modified: cfe/trunk/test/SemaObjC/objcbridge-attribute-arc.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objcbridge-attribute-arc.m?rev=289625=289624=289625=diff
==
--- cfe/trunk/test/SemaObjC/objcbridge-attribute-arc.m (original)
+++ cfe/trunk/test/SemaObjC/objcbridge-attribute-arc.m Tue Dec 13 20:06:11 2016
@@ -23,10 +23,7 @@ typedef struct __CFSetRef * CFSetRef __a
 
 typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; 
// expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used 
on a typedef}}
 
-// This error requires C11.
-#if __STDC_VERSION__ > 199901L
-typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; 
// expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used 
on a typedef}}
-#endif
+typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; 
// expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used 
on a typedef}}
 
 typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; 
// expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used 
on a typedef}}
 


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


[PATCH] D27744: Create SampleProfileLoader pass in llvm instead of clang

2016-12-13 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh created this revision.
danielcdh added reviewers: dnovillo, tejohnson, davidxl.
danielcdh added a subscriber: cfe-commits.
Herald added a subscriber: mehdi_amini.

We used to create SampleProfileLoader pass in clang. This makes LTO/ThinLTO 
unable to add this pass in the linker plugin. This patch moves the 
SampleProfileLoader pass creation from
clang to llvm pass manager builder.


https://reviews.llvm.org/D27744

Files:
  lib/CodeGen/BackendUtil.cpp


Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -464,10 +464,8 @@
   if (CodeGenOpts.hasProfileIRUse())
 PMBuilder.PGOInstrUse = CodeGenOpts.ProfileInstrumentUsePath;
 
-  if (!CodeGenOpts.SampleProfileFile.empty()) {
-MPM.add(createPruneEHPass());
-MPM.add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
-  }
+  if (!CodeGenOpts.SampleProfileFile.empty())
+PMBuilder.PGOSampleUse = CodeGenOpts.SampleProfileFile;
 
   PMBuilder.populateFunctionPassManager(FPM);
   PMBuilder.populateModulePassManager(MPM);


Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -464,10 +464,8 @@
   if (CodeGenOpts.hasProfileIRUse())
 PMBuilder.PGOInstrUse = CodeGenOpts.ProfileInstrumentUsePath;
 
-  if (!CodeGenOpts.SampleProfileFile.empty()) {
-MPM.add(createPruneEHPass());
-MPM.add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
-  }
+  if (!CodeGenOpts.SampleProfileFile.empty())
+PMBuilder.PGOSampleUse = CodeGenOpts.SampleProfileFile;
 
   PMBuilder.populateFunctionPassManager(FPM);
   PMBuilder.populateModulePassManager(MPM);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r289623 - When emitting a multidimensional array copy, only emit a single flattened

2016-12-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Dec 13 19:32:13 2016
New Revision: 289623

URL: http://llvm.org/viewvc/llvm-project?rev=289623=rev
Log:
When emitting a multidimensional array copy, only emit a single flattened
cleanup loop for exception handling.

Modified:
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=289623=289622=289623=diff
==
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Tue Dec 13 19:32:13 2016
@@ -164,7 +164,8 @@ public:
   void VisitAbstractConditionalOperator(const AbstractConditionalOperator *CO);
   void VisitChooseExpr(const ChooseExpr *CE);
   void VisitInitListExpr(InitListExpr *E);
-  void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E);
+  void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E,
+  llvm::Value *outerBegin = nullptr);
   void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
   void VisitNoInitExpr(NoInitExpr *E) { } // Do nothing.
   void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
@@ -1309,7 +1310,8 @@ void AggExprEmitter::VisitInitListExpr(I
 cleanupDominator->eraseFromParent();
 }
 
-void AggExprEmitter::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
+void AggExprEmitter::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E,
+llvm::Value *outerBegin) {
   // Emit the common subexpression.
   CodeGenFunction::OpaqueValueMapping binding(CGF, E->getCommonExpr());
 
@@ -1319,15 +1321,18 @@ void AggExprEmitter::VisitArrayInitLoopE
   if (!numElements)
 return;
 
-  // FIXME: Dig through nested ArrayInitLoopExprs to find the overall array
-  // size, and only emit a single loop for a multidimensional array.
-
   // destPtr is an array*. Construct an elementType* by drilling down a level.
   llvm::Value *zero = llvm::ConstantInt::get(CGF.SizeTy, 0);
   llvm::Value *indices[] = {zero, zero};
   llvm::Value *begin = Builder.CreateInBoundsGEP(destPtr.getPointer(), indices,
  "arrayinit.begin");
 
+  // Prepare to special-case multidimensional array initialization: we avoid
+  // emitting multiple destructor loops in that case.
+  if (!outerBegin)
+outerBegin = begin;
+  ArrayInitLoopExpr *InnerLoop = dyn_cast(E->getSubExpr());
+
   QualType elementType =
   CGF.getContext().getAsArrayType(E->getType())->getElementType();
   CharUnits elementSize = CGF.getContext().getTypeSizeInChars(elementType);
@@ -1347,9 +1352,12 @@ void AggExprEmitter::VisitArrayInitLoopE
   // Prepare for a cleanup.
   QualType::DestructionKind dtorKind = elementType.isDestructedType();
   EHScopeStack::stable_iterator cleanup;
-  if (CGF.needsEHCleanup(dtorKind)) {
-CGF.pushRegularPartialArrayCleanup(
-begin, element, elementType, elementAlign, CGF.getDestroyer(dtorKind));
+  if (CGF.needsEHCleanup(dtorKind) && !InnerLoop) {
+if (outerBegin->getType() != element->getType())
+  outerBegin = Builder.CreateBitCast(outerBegin, element->getType());
+CGF.pushRegularPartialArrayCleanup(outerBegin, element, elementType,
+   elementAlign,
+   CGF.getDestroyer(dtorKind));
 cleanup = CGF.EHStack.stable_begin();
   } else {
 dtorKind = QualType::DK_none;
@@ -1363,7 +1371,16 @@ void AggExprEmitter::VisitArrayInitLoopE
 CodeGenFunction::ArrayInitLoopExprScope Scope(CGF, index);
 LValue elementLV =
 CGF.MakeAddrLValue(Address(element, elementAlign), elementType);
-EmitInitializationToLValue(E->getSubExpr(), elementLV);
+
+if (InnerLoop) {
+  // If the subexpression is an ArrayInitLoopExpr, share its cleanup.
+  auto elementSlot = AggValueSlot::forLValue(
+  elementLV, AggValueSlot::IsDestructed,
+  AggValueSlot::DoesNotNeedGCBarriers, AggValueSlot::IsNotAliased);
+  AggExprEmitter(CGF, elementSlot, false)
+  .VisitArrayInitLoopExpr(InnerLoop, outerBegin);
+} else
+  EmitInitializationToLValue(E->getSubExpr(), elementLV);
   }
 
   // Move on to the next element.

Modified: cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp?rev=289623=289622=289623=diff
==
--- cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp Tue Dec 13 19:32:13 2016
@@ -140,7 +140,7 @@ namespace pr28595 {
 // CHECK: call {{.*}}after_init
 after_init();
 
-// CHECK: %[[DST_0:.*]] = getelementptr inbounds [3 x [5 x %[[A, 
{{.*}}, i64 0, i64 0
+// CHECK: %[[DST_0:.*]] = getelementptr {{.*}} [3 x [5 x %[[A* 

r289621 - LTO: Add support for multi-module bitcode files.

2016-12-13 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Dec 13 19:17:59 2016
New Revision: 289621

URL: http://llvm.org/viewvc/llvm-project?rev=289621=rev
Log:
LTO: Add support for multi-module bitcode files.

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

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/CodeGen/thinlto_backend.ll

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=289621=289620=289621=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Dec 13 19:17:59 2016
@@ -753,7 +753,7 @@ static void runThinLTOBackend(const Code
 ImportList);
 
   std::vector OwnedImports;
-  MapVector ModuleMap;
+  MapVector ModuleMap;
 
   for (auto  : ImportList) {
 ErrorOr MBOrErr =
@@ -763,7 +763,34 @@ static void runThinLTOBackend(const Code
  << "': " << MBOrErr.getError().message() << "\n";
   return;
 }
-ModuleMap[I.first()] = (*MBOrErr)->getMemBufferRef();
+
+Expected BMsOrErr =
+getBitcodeModuleList(**MBOrErr);
+if (!BMsOrErr) {
+  handleAllErrors(BMsOrErr.takeError(), [&](ErrorInfoBase ) {
+errs() << "Error loading imported file '" << I.first()
+   << "': " << EIB.message() << '\n';
+  });
+  return;
+}
+
+// The bitcode file may contain multiple modules, we want the one with a
+// summary.
+bool FoundModule = false;
+for (BitcodeModule  : *BMsOrErr) {
+  Expected HasSummary = BM.hasSummary();
+  if (HasSummary && *HasSummary) {
+ModuleMap.insert({I.first(), BM});
+FoundModule = true;
+break;
+  }
+}
+if (!FoundModule) {
+  errs() << "Error loading imported file '" << I.first()
+ << "': Could not find module summary\n";
+  return;
+}
+
 OwnedImports.push_back(std::move(*MBOrErr));
   }
   auto AddStream = [&](size_t Task) {

Modified: cfe/trunk/test/CodeGen/thinlto_backend.ll
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto_backend.ll?rev=289621=289620=289621=diff
==
--- cfe/trunk/test/CodeGen/thinlto_backend.ll (original)
+++ cfe/trunk/test/CodeGen/thinlto_backend.ll Tue Dec 13 19:17:59 2016
@@ -9,8 +9,8 @@
 ; CHECK-WARNING: error: invalid argument '-fthinlto-index={{.*}}' only allowed 
with '-x ir'
 
 ; Ensure we get expected error for missing index file
-; RUN: %clang -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 
| FileCheck %s -check-prefix=CHECK-ERROR
-; CHECK-ERROR: Error loading index file 'bad.thinlto.bc'
+; RUN: %clang -O2 -o %t4.o -x ir %t1.o -c -fthinlto-index=bad.thinlto.bc 2>&1 
| FileCheck %s -check-prefix=CHECK-ERROR1
+; CHECK-ERROR1: Error loading index file 'bad.thinlto.bc'
 
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
@@ -18,6 +18,11 @@
 ; CHECK-OBJ: T f1
 ; CHECK-OBJ-NOT: U f2
 
+; Ensure we get expected error for input files without summaries
+; RUN: opt -o %t2.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
+; CHECK-ERROR2: Error loading imported file '{{.*}}': Could not find module 
summary
+
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 


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


[PATCH] D27597: [DebugInfo] Restore test case for long double constants.

2016-12-13 Thread Paul Robinson via Phabricator via cfe-commits
probinson accepted this revision.
probinson added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D27597#621618, @dgross wrote:

> So would a Python equivalent of the Perl be acceptable?  I think this is an 
> academic question -- better to explicitly test multiple triples.


There are a small number of tests that run Python scripts, but they are 
generally doing something really unusual (I admit I haven't gone to look, but 
that's my recollection).  If you can get proper coverage without Python, and it 
doesn't require standing on your head, people generally prefer that.  In this 
case, multiple RUNs with different triples will do the job, so that's 
preferable.

LGTM.


https://reviews.llvm.org/D27597



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


[PATCH] D27740: [analyzer] Include type name in Retain Count Checker diagnostics

2016-12-13 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna created this revision.
zaks.anna added a reviewer: dcoughlin.
zaks.anna added subscribers: cfe-commits, dcoughlin.

The more detailed diagnostic will make identifying which object the diagnostics 
refer to easier.


https://reviews.llvm.org/D27740

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  test/Analysis/edges-new.mm
  test/Analysis/inlining/path-notes.m
  test/Analysis/objc-arc.m
  test/Analysis/plist-output-alternate.m
  test/Analysis/plist-output.m
  test/Analysis/retain-release-arc.m
  test/Analysis/retain-release-path-notes-gc.m
  test/Analysis/retain-release-path-notes.m

Index: test/Analysis/retain-release-path-notes.m
===
--- test/Analysis/retain-release-path-notes.m
+++ test/Analysis/retain-release-path-notes.m
@@ -44,100 +44,100 @@
 
 
 void creationViaAlloc () {
-  id leaked = [[NSObject alloc] init]; // expected-note{{Method returns an Objective-C object with a +1 retain count}}
+  id leaked = [[NSObject alloc] init]; // expected-note{{Method returns an instance of NSObject * with a +1 retain count}}
   return; // expected-warning{{leak}} expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}}
 }
 
 void creationViaCFCreate () {
-  CFTypeRef leaked = CFCreateSomething(); // expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation object with a +1 retain count}}
+  CFTypeRef leaked = CFCreateSomething(); // expected-note{{Call to function 'CFCreateSomething' returns a Core Foundation object of type CFTypeRef with a +1 retain count}}
   return; // expected-warning{{leak}} expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}}
 }
 
 void acquisitionViaMethod (Foo *foo) {
-  id leaked = [foo methodWithValue]; // expected-note{{Method returns an Objective-C object with a +0 retain count}}
+  id leaked = [foo methodWithValue]; // expected-note{{Method returns an instance of id with a +0 retain count}}
   [leaked retain]; // expected-note{{Reference count incremented. The object now has a +1 retain count}}
   [leaked retain]; // expected-note{{Reference count incremented. The object now has a +2 retain count}}
   [leaked release]; // expected-note{{Reference count decremented. The object now has a +1 retain count}}
   return; // expected-warning{{leak}} expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}}
 }
 
 void acquisitionViaProperty (Foo *foo) {
-  id leaked = foo.propertyValue; // expected-note{{Property returns an Objective-C object with a +0 retain count}}
+  id leaked = foo.propertyValue; // expected-note{{Property returns an instance of id with a +0 retain count}}
   [leaked retain]; // expected-note{{Reference count incremented. The object now has a +1 retain count}}
   return; // expected-warning{{leak}} expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}}
 }
 
 void acquisitionViaCFFunction () {
-  CFTypeRef leaked = CFGetSomething(); // expected-note{{Call to function 'CFGetSomething' returns a Core Foundation object with a +0 retain count}}
+  CFTypeRef leaked = CFGetSomething(); // expected-note{{Call to function 'CFGetSomething' returns a Core Foundation object of type CFTypeRef with a +0 retain count}}
   CFRetain(leaked); // expected-note{{Reference count incremented. The object now has a +1 retain count}}
   return; // expected-warning{{leak}} expected-note{{Object leaked: object allocated and stored into 'leaked' is not referenced later in this execution path and has a retain count of +1}}
 }
 
 void explicitDealloc () {
-  id object = [[NSObject alloc] init]; // expected-note{{Method returns an Objective-C object with a +1 retain count}}
+  id object = [[NSObject alloc] init]; // expected-note{{Method returns an instance of NSObject * with a +1 retain count}}
   [object dealloc]; // expected-note{{Object released by directly sending the '-dealloc' message}}
   [object class]; // expected-warning{{Reference-counted object is used after it is released}} // expected-note{{Reference-counted object is used after it is released}}
 }
 
 void implicitDealloc () {
-  id object = [[NSObject alloc] init]; // expected-note{{Method returns an Objective-C object with a +1 retain count}}
+  id object = [[NSObject alloc] init]; // expected-note{{Method returns an instance of NSObject * with a +1 retain count}}
   [object release]; // expected-note{{Object released}}
   [object class]; // expected-warning{{Reference-counted object is used after it is released}} // expected-note{{Reference-counted object is used after it is released}}
 }
 
 void overAutorelease () {
-  id object = [[NSObject alloc] init]; // 

r289618 - Remove custom handling of array copies in lambda by-value array capture and

2016-12-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Dec 13 18:03:17 2016
New Revision: 289618

URL: http://llvm.org/viewvc/llvm-project?rev=289618=rev
Log:
Remove custom handling of array copies in lambda by-value array capture and
copy constructors of classes with array members, instead using
ArrayInitLoopExpr to represent the initialization loop.

This exposed a bug in the static analyzer where it was unable to differentiate
between zero-initialized and unknown array values, which has also been fixed
here.

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
cfe/trunk/test/CXX/special/class.copy/implicit-move-def.cpp
cfe/trunk/test/CodeGenCXX/constructor-init.cpp
cfe/trunk/test/CodeGenCXX/implicit-copy-constructor.cpp
cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp
cfe/trunk/test/CodeGenObjCXX/arc-special-member-functions.mm
cfe/trunk/test/CodeGenObjCXX/implicit-copy-constructor.mm
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=289618=289617=289618=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Tue Dec 13 18:03:17 2016
@@ -1928,8 +1928,7 @@ public:
 ///   B(A& a) : A(a), f(3.14159) { }
 /// };
 /// \endcode
-class CXXCtorInitializer final
-: private llvm::TrailingObjects {
+class CXXCtorInitializer final {
   /// \brief Either the base class name/delegating constructor type (stored as
   /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
   /// (IndirectFieldDecl*) being initialized.
@@ -1967,14 +1966,8 @@ class CXXCtorInitializer final
   unsigned IsWritten : 1;
 
   /// If IsWritten is true, then this number keeps track of the textual order
-  /// of this initializer in the original sources, counting from 0; otherwise,
-  /// it stores the number of array index variables stored after this object
-  /// in memory.
-  unsigned SourceOrderOrNumArrayIndices : 13;
-
-  CXXCtorInitializer(ASTContext , FieldDecl *Member,
- SourceLocation MemberLoc, SourceLocation L, Expr *Init,
- SourceLocation R, VarDecl **Indices, unsigned NumIndices);
+  /// of this initializer in the original sources, counting from 0.
+  unsigned SourceOrder : 13;
 
 public:
   /// \brief Creates a new base-class initializer.
@@ -2000,13 +1993,6 @@ public:
   CXXCtorInitializer(ASTContext , TypeSourceInfo *TInfo,
  SourceLocation L, Expr *Init, SourceLocation R);
 
-  /// \brief Creates a new member initializer that optionally contains
-  /// array indices used to describe an elementwise initialization.
-  static CXXCtorInitializer *Create(ASTContext , FieldDecl *Member,
-SourceLocation MemberLoc, SourceLocation L,
-Expr *Init, SourceLocation R,
-VarDecl **Indices, unsigned NumIndices);
-
   /// \brief Determine whether this initializer is initializing a base class.
   bool isBaseInitializer() const {
 return Initializee.is() && !IsDelegating;
@@ -2111,7 +2097,7 @@ public:
   /// \brief Return the source position of the initializer, counting from 0.
   /// If the initializer was implicit, -1 is returned.
   int getSourceOrder() const {
-return IsWritten ? static_cast(SourceOrderOrNumArrayIndices) : -1;
+return IsWritten ? static_cast(SourceOrder) : -1;
   }
 
   /// \brief Set the source order of this initializer.
@@ -2121,49 +2107,22 @@ public:
   ///
   /// This assumes that the initializer was written in the source code, and
   /// ensures that isWritten() returns true.
-  void setSourceOrder(int pos) {
+  void setSourceOrder(int Pos) {
 assert(!IsWritten &&
+   "setSourceOrder() used on implicit initializer");
+assert(SourceOrder == 0 &&
"calling twice setSourceOrder() on the 

[PATCH] D27597: [DebugInfo] Restore test case for long double constants.

2016-12-13 Thread David Gross via Phabricator via cfe-commits
dgross updated this revision to Diff 81321.
dgross added a comment.

Incorporate code review comments.

- Use %clang_cc1 not %clang
- Rather than trying to determine long double size for target, compile and 
check multiple times, and only check behavior of long double for known targets


https://reviews.llvm.org/D27597

Files:
  test/CodeGen/debug-info-static-const-fp.c


Index: test/CodeGen/debug-info-static-const-fp.c
===
--- test/CodeGen/debug-info-static-const-fp.c
+++ test/CodeGen/debug-info-static-const-fp.c
@@ -1,15 +1,33 @@
-// RUN: %clang -emit-llvm -O0 -S -g %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -debug-info-kind=limited %s -o - | \
+// RUN:   FileCheck --check-prefixes CHECK %s
+
+// RUN: %clang_cc1 -triple hexagon-unknown--elf -emit-llvm -O0 
-debug-info-kind=limited %s -o - | \
+// RUN:   FileCheck --check-prefixes CHECK,CHECK-LDsm %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 
-debug-info-kind=limited %s -o - | \
+// RUN:   FileCheck --check-prefixes CHECK,CHECK-LDlg %s
 
 // Per PR26619, check that for referenced static const of floating-point type,
-// we emit its constant value in debug info.  NOTE that PR26619 is not yet 
fixed for long double.
+// we emit its constant value in debug info.
+//
+// NOTE that __fp16 is assumed to be 16 bits, float is assumed to be
+// 32 bits, and double is assumed to be 64 bits.  Size of long double
+// is not known (for example, it is 64 bits for hexagon-unknown--elf,
+// but 128 bits for x86_64-unknown-linux-gnu).  Therefore, we specify
+// target triples where it has a known size, and check accordingly:
+// for the absence of a constant (CHECK-LDlg) when the size exceeds 64
+// bits, and for the presence of a constant (CHECK-LDsm) but not its
+// value when the size does not exceed 64 bits.
+//
+// NOTE that PR26619 is not yet fixed for types greater than 64 bits.
 
 static const __fp16 hVal = 29/13.0f;//2.2307692307692307692
 (2.23046875)
 
 static const float fVal = -147/17.0f;   //   -8.6470588235294117647
 (-8.64705849)
 
 static const double dVal = 19637/7.0;   // 2805.2857142857142857   
 (2805.2857142857142)
 
-static const long double ldVal = 3/1234567.0L;  //
2.4300017739012949479e-06 ()
+static const long double ldVal = 3/1234567.0L;  //
2.4300017739012949479e-06 ()
 
 int main() {
   return hVal + fVal + dVal + ldVal;
@@ -24,8 +42,5 @@
 // CHECK: !DIGlobalVariable(name: "dVal", {{.*}}, isLocal: true, isDefinition: 
true, expr: ![[DEXPR:[0-9]+]]
 // CHECK: ![[DEXPR]] = !DIExpression(DW_OP_constu, 4658387303597904457, 
DW_OP_stack_value)
 
-// Temporarily removing this check -- for some targets (such as
-// "--target=hexagon-unknown-elf"), long double does not exceed 64
-// bits, and so we actually do get the constant value (expr) emitted.
-//
-// DO-NOT-CHECK: !DIGlobalVariable(name: "ldVal", {{.*}}, isLocal: true, 
isDefinition: true)
+// CHECK-LDlg: !DIGlobalVariable(name: "ldVal", {{.*}}, isLocal: true, 
isDefinition: true)
+// CHECK-LDsm: !DIGlobalVariable(name: "ldVal", {{.*}}, isLocal: true, 
isDefinition: true, expr:


Index: test/CodeGen/debug-info-static-const-fp.c
===
--- test/CodeGen/debug-info-static-const-fp.c
+++ test/CodeGen/debug-info-static-const-fp.c
@@ -1,15 +1,33 @@
-// RUN: %clang -emit-llvm -O0 -S -g %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -debug-info-kind=limited %s -o - | \
+// RUN:   FileCheck --check-prefixes CHECK %s
+
+// RUN: %clang_cc1 -triple hexagon-unknown--elf -emit-llvm -O0 -debug-info-kind=limited %s -o - | \
+// RUN:   FileCheck --check-prefixes CHECK,CHECK-LDsm %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -O0 -debug-info-kind=limited %s -o - | \
+// RUN:   FileCheck --check-prefixes CHECK,CHECK-LDlg %s
 
 // Per PR26619, check that for referenced static const of floating-point type,
-// we emit its constant value in debug info.  NOTE that PR26619 is not yet fixed for long double.
+// we emit its constant value in debug info.
+//
+// NOTE that __fp16 is assumed to be 16 bits, float is assumed to be
+// 32 bits, and double is assumed to be 64 bits.  Size of long double
+// is not known (for example, it is 64 bits for hexagon-unknown--elf,
+// but 128 bits for x86_64-unknown-linux-gnu).  Therefore, we specify
+// target triples where it has a known size, and check accordingly:
+// for the absence of a constant (CHECK-LDlg) when the size exceeds 64
+// bits, and for the presence of a constant (CHECK-LDsm) but not its
+// value when the size does not exceed 64 bits.
+//
+// NOTE that PR26619 is not yet fixed for types greater than 64 bits.
 
 static const __fp16 hVal = 29/13.0f;//2.2307692307692307692 (2.23046875)
 
 static const float fVal = -147/17.0f;   //   -8.6470588235294117647 (-8.64705849)
 
 static const 

r289615 - [CodeGen][ObjC] Emit objc_unsafeClaimAutoreleasedReturnValue for

2016-12-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Dec 13 17:32:22 2016
New Revision: 289615

URL: http://llvm.org/viewvc/llvm-project?rev=289615=rev
Log:
[CodeGen][ObjC] Emit objc_unsafeClaimAutoreleasedReturnValue for
fragile runtime too.

Follow-up to r258962.

rdar://problem/29269006

Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m

Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=289615=289614=289615=diff
==
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Tue Dec 13 17:32:22 2016
@@ -312,6 +312,7 @@ public:
   bool hasARCUnsafeClaimAutoreleasedReturnValue() const {
 switch (getKind()) {
 case MacOSX:
+case FragileMacOSX:
   return getVersion() >= VersionTuple(10, 11);
 case iOS:
   return getVersion() >= VersionTuple(9);

Modified: cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m?rev=289615=289614=289615=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m Tue Dec 13 17:32:22 2016
@@ -1,6 +1,9 @@
 //   Make sure it works on x86-64.
 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime=macosx-10.11 
-fobjc-arc -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK 
-check-prefix=CHECK-UNOPTIMIZED
 
+//   Make sure it works on x86-32.
+// RUN: %clang_cc1 -triple i386-apple-darwin11 
-fobjc-runtime=macosx-fragile-10.11 -fobjc-arc -emit-llvm -o - %s | FileCheck 
%s -check-prefix=CHECK -check-prefix=CHECK-UNOPTIMIZED 
-check-prefix=CHECK-MARKED
+
 //   Make sure it works on ARM.
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc 
-emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK 
-check-prefix=CHECK-UNOPTIMIZED -check-prefix=CHECK-MARKED
 // RUN: %clang_cc1 -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc 
-O -disable-llvm-optzns -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK 
-check-prefix=CHECK-OPTIMIZED


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


r289614 - Add support for Samsung Exynos M3 (NFC)

2016-12-13 Thread Evandro Menezes via cfe-commits
Author: evandro
Date: Tue Dec 13 17:31:57 2016
New Revision: 289614

URL: http://llvm.org/viewvc/llvm-project?rev=289614=rev
Log:
Add support for Samsung Exynos M3 (NFC)

Modified:
cfe/trunk/test/CodeGen/arm-target-features.c
cfe/trunk/test/Driver/aarch64-cpus.c
cfe/trunk/test/Driver/arm-cortex-cpus.c
cfe/trunk/test/Preprocessor/aarch64-target-features.c

Modified: cfe/trunk/test/CodeGen/arm-target-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-target-features.c?rev=289614=289613=289614=diff
==
--- cfe/trunk/test/CodeGen/arm-target-features.c (original)
+++ cfe/trunk/test/CodeGen/arm-target-features.c Tue Dec 13 17:31:57 2016
@@ -30,6 +30,7 @@
 // RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu cortex-a73 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
 // RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu exynos-m1 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
 // RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu exynos-m2 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
+// RUN: %clang_cc1 -triple thumbv8-linux-gnueabihf -target-cpu exynos-m3 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-BASIC-V8
 // CHECK-BASIC-V8: 
"target-features"="+crc,+crypto,+dsp,+fp-armv8,+hwdiv,+hwdiv-arm,+neon"
 
 

Modified: cfe/trunk/test/Driver/aarch64-cpus.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-cpus.c?rev=289614=289613=289614=diff
==
--- cfe/trunk/test/Driver/aarch64-cpus.c (original)
+++ cfe/trunk/test/Driver/aarch64-cpus.c Tue Dec 13 17:31:57 2016
@@ -104,6 +104,14 @@
 // RUN: %clang -target aarch64_be -mlittle-endian -mtune=exynos-m2 -### -c %s 
2>&1 | FileCheck -check-prefix=M2 %s
 // M2: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "exynos-m2"
 
+// RUN: %clang -target aarch64_be -mcpu=exynos-m3 -### -c %s 2>&1 | FileCheck 
-check-prefix=M3 %s
+// RUN: %clang -target aarch64 -mbig-endian -mcpu=exynos-m3 -### -c %s 2>&1 | 
FileCheck -check-prefix=M3 %s
+// RUN: %clang -target aarch64_be -mbig-endian -mcpu=exynos-m3 -### -c %s 2>&1 
| FileCheck -check-prefix=M3 %s
+// RUN: %clang -target aarch64_be -mtune=exynos-m3 -### -c %s 2>&1 | FileCheck 
-check-prefix=M3 %s
+// RUN: %clang -target aarch64 -mbig-endian -mtune=exynos-m3 -### -c %s 2>&1 | 
FileCheck -check-prefix=M3 %s
+// RUN: %clang -target aarch64_be -mbig-endian -mtune=exynos-m3 -### -c %s 
2>&1 | FileCheck -check-prefix=M3 %s
+// M3: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" "exynos-m3"
+
 // RUN: %clang -target arm64 -mcpu=exynos-m1 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-M1 %s
 // RUN: %clang -target arm64 -mlittle-endian -mcpu=exynos-m1 -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-M1 %s
 // RUN: %clang -target arm64 -mtune=exynos-m1 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-M1 %s
@@ -116,6 +124,12 @@
 // RUN: %clang -target arm64 -mlittle-endian -mtune=exynos-m2 -### -c %s 2>&1 
| FileCheck -check-prefix=ARM64-M2 %s
 // ARM64-M2: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "exynos-m2"
 
+// RUN: %clang -target arm64 -mcpu=exynos-m3 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-M3 %s
+// RUN: %clang -target arm64 -mlittle-endian -mcpu=exynos-m3 -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-M3 %s
+// RUN: %clang -target arm64 -mtune=exynos-m3 -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-M3 %s
+// RUN: %clang -target arm64 -mlittle-endian -mtune=exynos-m3 -### -c %s 2>&1 
| FileCheck -check-prefix=ARM64-M3 %s
+// ARM64-M3: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "exynos-m3"
+
 // RUN: %clang -target aarch64 -mcpu=falkor -### -c %s 2>&1 | FileCheck 
-check-prefix=FALKOR %s
 // RUN: %clang -target aarch64 -mlittle-endian -mcpu=falkor -### -c %s 2>&1 | 
FileCheck -check-prefix=FALKOR %s
 // RUN: %clang -target aarch64 -mtune=falkor -### -c %s 2>&1 | FileCheck 
-check-prefix=FALKOR %s
@@ -215,6 +229,14 @@
 // RUN: %clang -target aarch64_be -mbig-endian -mtune=exynos-m2 -### -c %s 
2>&1 | FileCheck -check-prefix=M2-BE %s
 // M2-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" "exynos-m2"
 
+// RUN: %clang -target aarch64_be -mcpu=exynos-m3 -### -c %s 2>&1 | FileCheck 
-check-prefix=M3-BE %s
+// RUN: %clang -target aarch64 -mbig-endian -mcpu=exynos-m3 -### -c %s 2>&1 | 
FileCheck -check-prefix=M3-BE %s
+// RUN: %clang -target aarch64_be -mbig-endian -mcpu=exynos-m3 -### -c %s 2>&1 
| FileCheck -check-prefix=M3-BE %s
+// RUN: %clang -target aarch64_be -mtune=exynos-m3 -### -c %s 2>&1 | FileCheck 
-check-prefix=M3-BE %s
+// RUN: %clang -target aarch64 -mbig-endian -mtune=exynos-m3 -### -c %s 2>&1 | 
FileCheck -check-prefix=M3-BE %s
+// RUN: %clang -target aarch64_be -mbig-endian -mtune=exynos-m3 -### -c %s 
2>&1 | FileCheck -check-prefix=M3-BE %s
+// M3-BE: 

[PATCH] D27597: [DebugInfo] Restore test case for long double constants.

2016-12-13 Thread David Gross via Phabricator via cfe-commits
dgross added a comment.

In https://reviews.llvm.org/D27597#621596, @probinson wrote:

> As dblaikie said in email, probably better to make this X86-specific; if 
> long-double varies by OS you can put in a specific triple.


I think with this approach I'd want two test cases that are identical except 
for consideration of long double size: One that specifies a target where long 
double is "small" and one where it is "large".  Actually, I guess I could make 
this a single test case, but have two compile and two filecheck lines, 
specifying different triples, as you suggest.  Or even three: One for whatever 
the default target is (doesn't check long double), one for a triple where long 
double is small, and one for a triple where long double is large.

> FTR we don't rely on Perl being available everywhere, anything that does this 
> kind of scripty stuff uses Python.

So would a Python equivalent of the Perl be acceptable?  I think this is an 
academic question -- better to explicitly test multiple triples.


https://reviews.llvm.org/D27597



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


[PATCH] D27641: DebugInfo: Added support for Checksum debug info feature (Clang part)

2016-12-13 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:350
+  std::string Checksum;
+  SM.getChecksumMD5(SM.getFileID(Loc), Checksum);
+

rnk wrote:
> We should only do this if `CGM.getCodeGenOpts().EmitCodeView`, or we will 
> regress compile time on other platforms without any added functionality.
Eventually we'll want it for DWARF 5 also, but for now conditioning on CodeView 
is fine.


https://reviews.llvm.org/D27641



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


[PATCH] D27597: [DebugInfo] Restore test case for long double constants.

2016-12-13 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

As dblaikie said in email, probably better to make this X86-specific; if 
long-double varies by OS you can put in a specific triple.

FTR we don't rely on Perl being available everywhere, anything that does this 
kind of scripty stuff uses Python.




Comment at: test/CodeGen/debug-info-static-const-fp.c:1
-// RUN: %clang -emit-llvm -O0 -S -g %s -o - | FileCheck %s
+// RUN: %clang -emit-llvm -O0 -S -g %s -o %t
+// RUN: perl <%t >%t-check-prefix -n -e  \

Sorry didn't notice this before, %clang is for driver tests only; use 
%clang_cc1 here.


https://reviews.llvm.org/D27597



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


[PATCH] D27627: Allow target to specify default address space for codegen

2016-12-13 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 81309.
yaxunl added a comment.

Cast alloca to default address space.


https://reviews.llvm.org/D27627

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/TargetInfo.h
  lib/AST/ASTContext.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/default-addr-space.cpp

Index: test/CodeGen/default-addr-space.cpp
===
--- /dev/null
+++ test/CodeGen/default-addr-space.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -O0 -std=c++11 -emit-llvm -o - -triple amdgcn-- %s | FileCheck %s
+
+// CHECK: %struct.ATy = type { i32 addrspace(4)* }
+struct ATy {
+  int *p;
+};
+
+// CHECK-LABEL: @_Z1fPi(i32 addrspace(4)* %a)
+void f(int* a) {
+  // CHECK: %[[a_addr_0:.*]] = alloca i32 addrspace(4)*
+  // CHECK: %[[a_addr:.*]] = addrspacecast i32 addrspace(4)** %[[a_addr_0]] to i32 addrspace(4)* addrspace(4)*
+  // CHECK: %[[b0:.*]] = alloca i32
+  // CHECK: %[[b:.*]] = addrspacecast i32* %[[b0]] to i32 addrspace(4)*
+  // CHECK: %[[A0:.*]] = alloca %struct.ATy, align 4
+  // CHECK: %[[A:.*]] = addrspacecast %struct.ATy* %[[A0]] to %struct.ATy addrspace(4)*
+
+  // CHECK:  store i32 addrspace(4)* %a, i32 addrspace(4)* addrspace(4)* %[[a_addr]]
+
+  // CHECK:  store i32 1, i32 addrspace(4)* %[[b]]
+  int b = 1;
+
+  // CHECK: %[[p:.*]] = getelementptr inbounds %struct.ATy, %struct.ATy addrspace(4)* %[[A]], i32 0, i32 0
+  // CHECK: store i32 addrspace(4)* %[[b]], i32 addrspace(4)* addrspace(4)* %[[p]], align 4
+  ATy A{};
+
+  // CHECK: %[[r0:.*]] = load i32, i32 addrspace(4)* %b
+  // CHECK: %[[r1:.*]] = load i32 addrspace(4)*, i32 addrspace(4)* addrspace(4)* %[[a_addr]]
+  // CHECK: store i32 %[[r0]], i32 addrspace(4)* %[[r1]]
+  *a = b;
+
+  // CHECK: store i32 addrspace(4)* %[[b]], i32 addrspace(4)* addrspace(4)* %[[a_addr]], align 4
+  a = 
+}
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -344,7 +344,7 @@
   };
 
   /// i32s containing the indexes of the cleanup destinations.
-  llvm::AllocaInst *NormalCleanupDest;
+  llvm::Instruction *NormalCleanupDest;
 
   unsigned NextCleanupDestIndex;
 
@@ -359,8 +359,8 @@
   llvm::Value *ExceptionSlot;
 
   /// The selector slot.  Under the MandatoryCleanup model, all landing pads
-  /// write the current selector value into this alloca.
-  llvm::AllocaInst *EHSelectorSlot;
+  /// write the current selector value into this instruction.
+  llvm::Instruction *EHSelectorSlot;
 
   /// A stack of exception code slots. Entering an __except block pushes a slot
   /// on the stack and leaving pops one. The __exception_code() intrinsic loads
@@ -395,11 +395,11 @@
 
 /// An i1 variable indicating whether or not the @finally is
 /// running for an exception.
-llvm::AllocaInst *ForEHVar;
+llvm::Instruction *ForEHVar;
 
 /// An i8* variable into which the exception pointer to rethrow
 /// has been saved.
-llvm::AllocaInst *SavedExnVar;
+llvm::Instruction *SavedExnVar;
 
   public:
 void enter(CodeGenFunction , const Stmt *Finally,
@@ -1788,14 +1788,23 @@
 AlignmentSource *Source = nullptr);
   LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy);
 
+  /// Create an alloca instruction. If the default address space is not 0,
+  /// insert addrspacecast instruction which casts the alloca instruction
+  /// to the default address space.
+  llvm::Instruction *CreateAlloca(llvm::Type *Ty, const Twine  = "tmp",
+  llvm::Instruction *InsertPos = nullptr);
   /// CreateTempAlloca - This creates a alloca and inserts it into the entry
   /// block. The caller is responsible for setting an appropriate alignment on
-  /// the alloca.
-  llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty,
- const Twine  = "tmp");
+  /// the alloca. If the default address space is not 0, insert addrspacecast.
+  llvm::Instruction *CreateTempAlloca(llvm::Type *Ty,
+  const Twine  = "tmp");
   Address CreateTempAlloca(llvm::Type *Ty, CharUnits align,
const Twine  = "tmp");
 
+  /// Get alloca instruction operand of an addrspacecast instruction.
+  /// If \p Inst is alloca instruction, returns \p Inst;
+  llvm::AllocaInst *getAddrSpaceCastedAlloca(llvm::Instruction *Inst) const;
+
   /// CreateDefaultAlignedTempAlloca - This creates an alloca with the
   /// default ABI alignment of the given LLVM type.
   ///
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -59,16 +59,37 @@
 /// block.
 Address CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align,
 

[PATCH] D26750: [clang-tidy] Add modernize-use-default-member-init check

2016-12-13 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: docs/clang-tidy/checks/modernize-use-default-member-init.rst:29
+
+.. note::
+  Only converts member initializers for built-in types, enums and pointers.

alexfh wrote:
> Is an empty line needed after this?
modernize-use-equals-default.rst doesn't have one.


https://reviews.llvm.org/D26750



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


[PATCH] D26750: [clang-tidy] Add modernize-use-default-member-init check

2016-12-13 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 81310.
malcolm.parsons added a comment.

Rename function.
Use isInstantiated().
Reduce variable scope.


https://reviews.llvm.org/D26750

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
  clang-tidy/modernize/UseDefaultMemberInitCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-default-member-init.rst
  test/clang-tidy/modernize-use-default-member-init-assignment.cpp
  test/clang-tidy/modernize-use-default-member-init.cpp

Index: test/clang-tidy/modernize-use-default-member-init.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-default-member-init.cpp
@@ -0,0 +1,264 @@
+// RUN: %check_clang_tidy %s modernize-use-default-member-init %t -- -- -std=c++11
+
+struct S {
+};
+
+struct PositiveValueInt {
+  PositiveValueInt() : i() {}
+  // CHECK-FIXES: PositiveValueInt()  {}
+  const int i;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use default member initializer for 'i' [modernize-use-default-member-init]
+  // CHECK-FIXES: const int i{};
+};
+
+struct PositiveInt {
+  PositiveInt() : j(1) {}
+  // CHECK-FIXES: PositiveInt()  {}
+  int j;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
+  // CHECK-FIXES: int j{1};
+};
+
+struct PositiveUnaryMinusInt {
+  PositiveUnaryMinusInt() : j(-1) {}
+  // CHECK-FIXES: PositiveUnaryMinusInt()  {}
+  int j;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
+  // CHECK-FIXES: int j{-1};
+};
+
+struct PositiveUnaryPlusInt {
+  PositiveUnaryPlusInt() : j(+1) {}
+  // CHECK-FIXES: PositiveUnaryPlusInt()  {}
+  int j;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j'
+  // CHECK-FIXES: int j{+1};
+};
+
+struct PositiveValueDouble {
+  PositiveValueDouble() : d() {}
+  // CHECK-FIXES: PositiveValueDouble()  {}
+  double d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'd'
+  // CHECK-FIXES: double d{};
+};
+
+struct PositiveDouble {
+  PositiveDouble() : f(2.5463e43) {}
+  // CHECK-FIXES: PositiveDouble()  {}
+  double f;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
+  // CHECK-FIXES: double f{2.5463e43};
+};
+
+struct PositiveUnaryMinusDouble {
+  PositiveUnaryMinusDouble() : f(-2.5463e43) {}
+  // CHECK-FIXES: PositiveUnaryMinusDouble()  {}
+  double f;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
+  // CHECK-FIXES: double f{-2.5463e43};
+};
+
+struct PositiveUnaryPlusDouble {
+  PositiveUnaryPlusDouble() : f(+2.5463e43) {}
+  // CHECK-FIXES: PositiveUnaryPlusDouble()  {}
+  double f;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f'
+  // CHECK-FIXES: double f{+2.5463e43};
+};
+
+struct PositiveValueBool {
+  PositiveValueBool() : b() {}
+  // CHECK-FIXES: PositiveValueBool()  {}
+  bool b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'b'
+  // CHECK-FIXES: bool b{};
+};
+
+struct PositiveBool {
+  PositiveBool() : a(true) {}
+  // CHECK-FIXES: PositiveBool()  {}
+  bool a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'a'
+  // CHECK-FIXES: bool a{true};
+};
+
+struct PositiveValuePointer {
+  PositiveValuePointer() : p() {}
+  // CHECK-FIXES: PositiveValuePointer()  {}
+  int *p;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'p'
+  // CHECK-FIXES: int *p{};
+};
+
+struct PositiveNullPointer {
+  PositiveNullPointer() : q(nullptr) {}
+  // CHECK-FIXES: PositiveNullPointer()  {}
+  int *q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'q'
+  // CHECK-FIXES: int *q{nullptr};
+};
+
+enum Enum { Foo, Bar };
+struct PositiveEnum {
+  PositiveEnum() : e(Foo) {}
+  // CHECK-FIXES: PositiveEnum()  {}
+  Enum e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e'
+  // CHECK-FIXES: Enum e{Foo};
+};
+
+template 
+struct NegativeTemplate {
+NegativeTemplate() : t() {}
+T t;
+};
+
+NegativeTemplate nti;
+NegativeTemplate ntd;
+
+struct NegativeDefaultMember {
+  NegativeDefaultMember() {}
+  int i = 2;
+};
+
+struct NegativeClass : S {
+  NegativeClass() : s() {}
+  S s;
+};
+
+struct NegativeBase : S {
+  NegativeBase() : S() {}
+};
+
+struct NegativeDefaultOtherMember{
+  NegativeDefaultOtherMember() : i(3) {}
+  int i = 4;
+};
+
+struct NegativeUnion {
+  NegativeUnion() : d(5.0) {}
+  union {
+int i;
+double d;
+  };
+};
+
+struct NegativeBitField
+{
+  NegativeBitField() : i(6) {}
+  int i : 5;
+};
+
+struct NegativeNotDefaultInt
+{
+  NegativeNotDefaultInt(int) : i(7) {}
+  int i;
+};
+
+struct ExistingInt {
+  ExistingInt(short) : e1(), e2(), e3(), e4(), 

[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-13 Thread Sean Callanan via Phabricator via cfe-commits
spyffe added a comment.

The LLDB side of this is https://reviews.llvm.org/D27735


Repository:
  rL LLVM

https://reviews.llvm.org/D27683



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


[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-13 Thread Sean Callanan via Phabricator via cfe-commits
spyffe retitled this revision from "Fix the linkage for __crashtracer_info__" 
to "Prepare PrettyStackTrace for LLDB adoption".
spyffe updated the summary for this revision.
spyffe updated this revision to Diff 81304.

Repository:
  rL LLVM

https://reviews.llvm.org/D27683

Files:
  include/llvm/Support/PrettyStackTrace.h
  lib/Support/PrettyStackTrace.cpp


Index: lib/Support/PrettyStackTrace.cpp
===
--- lib/Support/PrettyStackTrace.cpp
+++ lib/Support/PrettyStackTrace.cpp
@@ -89,7 +89,7 @@
 = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
 }
 #elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
-static const char *__crashreporter_info__ = 0;
+extern "C" const char *__crashreporter_info__ 
__attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");
 #endif
 
@@ -145,6 +145,28 @@
   OS << Str << "\n";
 }
 
+PrettyStackTraceFormat::PrettyStackTraceFormat(const char *format, ...) {
+  va_list ap;
+
+  va_start(ap, format);
+  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
+  va_end(ap);
+
+  if (size_or_error < 0) {
+return;
+  }
+
+  const int size = size_or_error + 1; // '\0'
+
+  Str.resize(size);
+
+  va_start(ap, format);
+  vsnprintf(Str.data(), size, format, ap);
+  va_end(ap);
+}
+
+void PrettyStackTraceFormat::print(raw_ostream ) const { OS << Str << "\n"; 
}
+
 void PrettyStackTraceProgram::print(raw_ostream ) const {
   OS << "Program arguments: ";
   // Print the argument list.
Index: include/llvm/Support/PrettyStackTrace.h
===
--- include/llvm/Support/PrettyStackTrace.h
+++ include/llvm/Support/PrettyStackTrace.h
@@ -16,6 +16,7 @@
 #ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H
 #define LLVM_SUPPORT_PRETTYSTACKTRACE_H
 
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 
 namespace llvm {
@@ -55,6 +56,16 @@
 void print(raw_ostream ) const override;
   };
 
+  /// PrettyStackTraceFormat - This object prints a string (which may use
+  /// printf-style formatting but should not contain newlines) to the stream
+  /// as the stack trace when a crash occurs.
+  class PrettyStackTraceFormat : public PrettyStackTraceEntry {
+llvm::SmallVector Str;
+  public:
+PrettyStackTraceFormat(const char *format, ...);
+void print(raw_ostream ) const override;
+  };
+
   /// PrettyStackTraceProgram - This object prints a specified program 
arguments
   /// to the stream as the stack trace when a crash occurs.
   class PrettyStackTraceProgram : public PrettyStackTraceEntry {


Index: lib/Support/PrettyStackTrace.cpp
===
--- lib/Support/PrettyStackTrace.cpp
+++ lib/Support/PrettyStackTrace.cpp
@@ -89,7 +89,7 @@
 = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
 }
 #elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
-static const char *__crashreporter_info__ = 0;
+extern "C" const char *__crashreporter_info__ __attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");
 #endif
 
@@ -145,6 +145,28 @@
   OS << Str << "\n";
 }
 
+PrettyStackTraceFormat::PrettyStackTraceFormat(const char *format, ...) {
+  va_list ap;
+
+  va_start(ap, format);
+  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
+  va_end(ap);
+
+  if (size_or_error < 0) {
+return;
+  }
+
+  const int size = size_or_error + 1; // '\0'
+
+  Str.resize(size);
+
+  va_start(ap, format);
+  vsnprintf(Str.data(), size, format, ap);
+  va_end(ap);
+}
+
+void PrettyStackTraceFormat::print(raw_ostream ) const { OS << Str << "\n"; }
+
 void PrettyStackTraceProgram::print(raw_ostream ) const {
   OS << "Program arguments: ";
   // Print the argument list.
Index: include/llvm/Support/PrettyStackTrace.h
===
--- include/llvm/Support/PrettyStackTrace.h
+++ include/llvm/Support/PrettyStackTrace.h
@@ -16,6 +16,7 @@
 #ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H
 #define LLVM_SUPPORT_PRETTYSTACKTRACE_H
 
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 
 namespace llvm {
@@ -55,6 +56,16 @@
 void print(raw_ostream ) const override;
   };
 
+  /// PrettyStackTraceFormat - This object prints a string (which may use
+  /// printf-style formatting but should not contain newlines) to the stream
+  /// as the stack trace when a crash occurs.
+  class PrettyStackTraceFormat : public PrettyStackTraceEntry {
+llvm::SmallVector Str;
+  public:
+PrettyStackTraceFormat(const char *format, ...);
+void print(raw_ostream ) const override;
+  };
+
   /// PrettyStackTraceProgram - This object prints a specified program arguments
   /// to the stream as the stack trace when a crash occurs.
   class PrettyStackTraceProgram : public PrettyStackTraceEntry {
___
cfe-commits mailing list

[libunwind] r289601 - Creating release candidate final from release_391 branch

2016-12-13 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Dec 13 16:00:29 2016
New Revision: 289601

URL: http://llvm.org/viewvc/llvm-project?rev=289601=rev
Log:
Creating release candidate final from release_391 branch

Added:
libunwind/tags/RELEASE_391/final/   (props changed)
  - copied from r289600, libunwind/branches/release_39/

Propchange: libunwind/tags/RELEASE_391/final/
--
svn:mergeinfo = /libunwind/trunk:276128,277868,278029


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


[libcxxabi] r289595 - Creating release candidate final from release_391 branch

2016-12-13 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Dec 13 16:00:03 2016
New Revision: 289595

URL: http://llvm.org/viewvc/llvm-project?rev=289595=rev
Log:
Creating release candidate final from release_391 branch

Added:
libcxxabi/tags/RELEASE_391/final/   (props changed)
  - copied from r289594, libcxxabi/branches/release_39/

Propchange: libcxxabi/tags/RELEASE_391/final/
--
svn:mergeinfo = /libcxxabi/trunk:278030,278579


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


[libcxx] r289594 - Creating release candidate final from release_391 branch

2016-12-13 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Dec 13 16:00:00 2016
New Revision: 289594

URL: http://llvm.org/viewvc/llvm-project?rev=289594=rev
Log:
Creating release candidate final from release_391 branch

Added:
libcxx/tags/RELEASE_391/final/   (props changed)
  - copied from r289593, libcxx/branches/release_39/

Propchange: libcxx/tags/RELEASE_391/final/
--
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Dec 13 16:00:00 2016
@@ -0,0 +1,2 @@
+/libcxx/branches/apple:136569-137939
+/libcxx/trunk:278282,278357,278387,278904,279008


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


[PATCH] D27627: Allow target to specify default address space for codegen

2016-12-13 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D27627#621473, @rjmccall wrote:

> In https://reviews.llvm.org/D27627#619928, @yaxunl wrote:
>
> > > Because, notably, if you do that, then an attempt to pass  as an int* 
> > > will fail, which means this isn't really C++ anymore... and yet that 
> > > appears to be exactly what you want.
> >
> > How about when generating alloca instruction, I insert addrspacecast to the 
> > default address space, then everything is in default address space.
>
>
> My question is really about your language design.  You have multiple address 
> spaces in the implementation, but you're (apparently?) pretending that 
> they're all part of the same address space in the source language.  How is 
> that expected to work?  Does the default address space embed all other 
> address spaces?


Yes the default address space embeds all other address spaces.


https://reviews.llvm.org/D27627



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


[PATCH] D27726: [analyzer] Refer to macro names in diagnostics for macros representing a literal

2016-12-13 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

The diagnostics look great to me and the macro logic seems reasonable.




Comment at: test/Analysis/diagnostics/macros.cpp:49
+}
\ No newline at end of file


Missing newline?


https://reviews.llvm.org/D27726



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


[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-12-13 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 81300.
malcolm.parsons added a comment.

Split up matcher.
Add tests.
Improve doc.


https://reviews.llvm.org/D27166

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- test/clang-tidy/modernize-use-auto-cast.cpp
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -138,3 +138,86 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U );
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T _reference_cast(U );
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T _const_reference_cast(const U );
+
+template 
+T template_value_get(StringRef s);
+
+struct S {
+  template 
+  const T *template_member_get();
+};
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = template_value_cast(a);
+  B  = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b3 = template_pointer_cast(a);
+  B  = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  = template_reference_cast(*a);
+  const B *b5 = template_const_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b5 = template_const_pointer_cast(a);
+  const B  = template_const_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto  = template_const_reference_cast(*a);
+  B *b7 = template_value_get("foo");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b7 = template_value_get("foo");
+  B *b8 = template_value_get("foo"), *b9 = template_value_get("bar");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b8 = template_value_get("foo"), *b9 = template_value_get("bar");
+
+  S s;
+  const B *b10 = s.template_member_get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b10 = s.template_member_get();
+
+  // Don't warn when auto is already being used.
+  auto i2 = template_value_cast(d);
+
+  // Don't warn for implicit template arguments.
+  int i3 = max(i1, i2);
+
+  // Don't warn for mismatched var and initializer types.
+  A *a1 = template_value_cast(a);
+
+  // Don't warn for mismatched var types.
+  B *b11 = template_value_get("foo"), b12 = template_value_get("bar");
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -44,7 +44,7 @@
 
   const B *b3 = static_cast(a);
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
-  // CHECK-FIXES: auto b3 = static_cast(a);
+  // CHECK-FIXES: const auto b3 = static_cast(a);
 
   B  = static_cast(*a);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
@@ -58,6 +58,9 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
   // CHECK-FIXES: auto   = static_cast(*a),  = static_cast(*a);
 
+  // Don't warn when non-cast involved
+  long double cast = static_cast(l), noncast = 5;
+
   // Don't warn when auto is already being used.
   auto i3 = static_cast(l);
   auto *b8 = static_cast(a);
@@ 

[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-12-13 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/modernize/UseAutoCheck.cpp:173-177
+/// Matches the type that was substituted for the template parameter.
+AST_MATCHER_P(SubstTemplateTypeParmType, hasReplacementType,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node.getReplacementType(), Finder, Builder);
+}

Prazek wrote:
> alexfh wrote:
> > Ideally, this should go to ASTMatchers.h (with a proper test and 
> > documentation).
> I agree 
@Prazek Are you talking about `hasReplacementType` or `hasExplicitTemplateArgs`?


https://reviews.llvm.org/D27166



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


[PATCH] D26082: Support for Python 3 in libclang python bindings

2016-12-13 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe added a comment.

Hi Mathieu,
What platform did you run the tests on? How did you run them? I don't get any 
failures when running tests on macOS 10.12.1.

command: `env PYTHONPATH=`pwd` 
LD_LIBRARY_PATH=/Users/jon/DEV/LLVM/build-ninja/lib nosetests-3.4 .`

python: Python 3.5.2 (default, Oct 11 2016, 04:59:56) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin

Python installed using homebrew.

I'm keen to get to the bottom of this failure. I've been distracted by other 
things recently.


Repository:
  rL LLVM

https://reviews.llvm.org/D26082



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


RE: r289225 - Store decls in prototypes on the declarator instead of in the AST

2016-12-13 Thread Yung, Douglas via cfe-commits
Hi Reid,

Following this change, we started seeing an assertion failure in one of our C 
tests. I have filed bug 31366 for the issue. Can you take a look?

Douglas Yung

> -Original Message-
> From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf
> Of Reid Kleckner via cfe-commits
> Sent: Friday, December 09, 2016 9:14
> To: cfe-commits@lists.llvm.org
> Subject: r289225 - Store decls in prototypes on the declarator instead
> of in the AST
> 
> Author: rnk
> Date: Fri Dec  9 11:14:05 2016
> New Revision: 289225
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=289225=rev
> Log:
> Store decls in prototypes on the declarator instead of in the AST
> 
> This saves two pointers from FunctionDecl that were being used for some
> rare and questionable C-only functionality.  The DeclsInPrototypeScope
> ArrayRef was added in r151712 in order to parse this kind of C code:
> 
> enum e {x, y};
> int f(enum {y, x} n) {
>  return x; // should return 1, not 0
> }
> 
> The challenge is that we parse 'int f(enum {y, x} n)' it its own
> function prototype scope that gets popped before we build the
> FunctionDecl for 'f'. The original change was doing two questionable
> things:
> 
> 1. Saving all tag decls introduced in prototype scope on a TU-global
> Sema variable. This is problematic when you have cases like this, where
> 'x' and 'y' shouldn't be visible in 'f':
> void f(void (*fp)(enum { x, y } e)) { /* no x */ } This patch fixes
> that, so now 'f' can't see 'x', which is consistent with GCC.
> 
> 2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that
> they could be used in ActOnStartOfFunctionDef. This is just an
> inefficient way to move information around. The AST lives forever, but
> the list of non-parameter decls in prototype scope is short lived.
> 
> Moving these things to the Declarator solves both of these issues.
> 
> Reviewers: rsmith
> 
> Subscribers: jmolloy, cfe-commits
> 
> Differential Revision: https://reviews.llvm.org/D27279
> 
> Added:
> cfe/trunk/test/PCH/decl-in-prototype.c
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/include/clang/Sema/DeclSpec.h
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/AST/ASTDumper.cpp
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/Parse/ParseDecl.cpp
> cfe/trunk/lib/Parse/ParseExpr.cpp
> cfe/trunk/lib/Parse/ParseExprCXX.cpp
> cfe/trunk/lib/Sema/DeclSpec.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
> cfe/trunk/lib/Sema/SemaType.cpp
> cfe/trunk/test/Misc/ast-dump-decl.c
> cfe/trunk/test/Sema/decl-in-prototype.c
> cfe/trunk/test/SemaCXX/type-definition-in-specifier.cpp
> 
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/include/clang/AST/Decl.h?rev=289225=289224=2892
> 25=diff
> ===
> ===
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri Dec  9 11:14:05 2016
> @@ -1601,11 +1601,6 @@ private:
>/// no formals.
>ParmVarDecl **ParamInfo;
> 
> -  /// DeclsInPrototypeScope - Array of pointers to NamedDecls for
> -  /// decls defined in the function prototype that are not parameters.
> E.g.
> -  /// 'enum Y' in 'void f(enum Y {AA} x) {}'.
> -  ArrayRef DeclsInPrototypeScope;
> -
>LazyDeclStmtPtr Body;
> 
>// FIXME: This can be packed into the bitfields in DeclContext.
> @@ -2050,11 +2045,6 @@ public:
>  setParams(getASTContext(), NewParamInfo);
>}
> 
> -  ArrayRef getDeclsInPrototypeScope() const {
> -return DeclsInPrototypeScope;
> -  }
> -  void setDeclsInPrototypeScope(ArrayRef NewDecls);
> -
>/// getMinRequiredArguments - Returns the minimum number of
> arguments
>/// needed to call this function. This may be fewer than the number
> of
>/// function parameters, if some of the parameters have default
> 
> Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=289225=289224
> =289225=diff
> ===
> ===
> --- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
> +++ cfe/trunk/include/clang/Sema/DeclSpec.h Fri Dec  9 11:14:05 2016
> @@ -1248,9 +1248,10 @@ struct DeclaratorChunk {
>  /// declarator.
>  unsigned NumParams;
> 
> -/// NumExceptions - This is the number of types in the dynamic-
> exception-
> -/// decl, if the function has one.
> -unsigned NumExceptions;
> +/// NumExceptionsOrDecls - This is the number of types in the
> +/// dynamic-exception-decl, if the function has one. In C, this is
> the
> +/// number of declarations in the function prototype.
> +unsigned NumExceptionsOrDecls;
> 
>  /// \brief The location of the ref-qualifier, if any.
>  ///
> @@ -1300,6 +1301,11 @@ struct 

[PATCH] D27627: Allow target to specify default address space for codegen

2016-12-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D27627#619928, @yaxunl wrote:

> > Because, notably, if you do that, then an attempt to pass  as an int* 
> > will fail, which means this isn't really C++ anymore... and yet that 
> > appears to be exactly what you want.
>
> How about when generating alloca instruction, I insert addrspacecast to the 
> default address space, then everything is in default address space.


My question is really about your language design.  You have multiple address 
spaces in the implementation, but you're (apparently?) pretending that they're 
all part of the same address space in the source language.  How is that 
expected to work?  Does the default address space embed all other address 
spaces?


https://reviews.llvm.org/D27627



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


[PATCH] D27606: [libcxx] Fix tuple construction/assignment from types derived from tuple/pair/array.

2016-12-13 Thread Michael Park via Phabricator via cfe-commits
mpark added inline comments.



Comment at: include/tuple:568
+using _QualType = typename _Deduced::_QualType;
+   static_assert(__tuple_like::value, "");
+return __tuple_constructible<_QualType, tuple>::value

indentation?



Comment at: include/tuple:871
 template ,
+  class _TupBase = typename _Deduced::_QualType,

indentation?



Comment at: include/tuple:906
 template ,
+  class _QualTupleBase = typename _Deducer::_QualType,

`s/_Deducer/_Deduced/`



Comment at: include/tuple:907
+  class _Deducer = __deduce_tuple_like<_Tuple>,
+  class _QualTupleBase = typename _Deducer::_QualType,
   class = typename enable_if

`s/_QualTupleBase/_TupBase/`



Comment at: include/tuple:915
 tuple&
-operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable::value))
+operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable::value))
 {

A general comment about using the `base` in noexcept condition. I remember for 
`variant` we wanted to express it directly rather than delegating it to the 
"base". Does that also apply here?



Comment at: include/tuple:917
 {
-base_.operator=(_VSTD::forward<_Tuple>(__t));
+base_.operator=(_VSTD::forward<_QualTupleBase>(__t));
 return *this;

Here and elsewhere, why do we bother with `base_.operator=(...);` as opposed to 
just `base_ = ...;`?


https://reviews.llvm.org/D27606



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


[PATCH] D24431: CodeGen: Start using inrange annotations on vtable getelementptr.

2016-12-13 Thread Peter Collingbourne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289585: CodeGen: Start using inrange annotations on vtable 
getelementptr. (authored by pcc).

Changed prior to commit:
  https://reviews.llvm.org/D24431?vs=75494=81289#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24431

Files:
  cfe/trunk/lib/CodeGen/CGVTT.cpp
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
  cfe/trunk/test/CodeGenCXX/constructor-init.cpp
  cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
  cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-interface.cpp
  cfe/trunk/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
  cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp
  cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
  cfe/trunk/test/CodeGenCXX/vtable-pointer-initialization.cpp
  cfe/trunk/test/CodeGenCXX/vtt-layout.cpp

Index: cfe/trunk/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
===
--- cfe/trunk/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
+++ cfe/trunk/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
@@ -27,7 +27,7 @@
 };
 
 // CHECK-LABEL: define void @_ZN5Test21AD2Ev
-// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test21AE, i32 0, i32 0, i32 2) to i32 (...)**), i32 (...)***
+// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test21AE, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)***
 A::~A() {
   f();
 }
@@ -50,7 +50,7 @@
 };
 
 // CHECK-LABEL: define void @_ZN5Test31AD2Ev
-// CHECK-NOT: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test31AE, i32 0, i32 0, i32 2) to i32 (...)**), i32 (...)***
+// CHECK-NOT: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test31AE, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)***
 A::~A() {
   
 }
@@ -76,7 +76,7 @@
 };
 
 // CHECK-LABEL: define void @_ZN5Test41AD2Ev
-// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test41AE, i32 0, i32 0, i32 2) to i32 (...)**), i32 (...)***
+// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test41AE, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)***
 A::~A()
 {
 }
@@ -100,7 +100,7 @@
 };
 
 // CHECK-LABEL: define void @_ZN5Test51AD2Ev
-// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test51AE, i32 0, i32 0, i32 2) to i32 (...)**), i32 (...)***
+// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test51AE, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)***
 A::~A()
 {
 }
@@ -128,7 +128,7 @@
 };
 
 // CHECK-LABEL: define void @_ZN5Test61AD2Ev
-// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test61AE, i32 0, i32 0, i32 2) to i32 (...)**), i32 (...)***
+// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test61AE, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)***
 A::~A()
 {
 }
@@ -154,7 +154,7 @@
 };
 
 // CHECK-LABEL: define void @_ZN5Test71AD2Ev
-// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test71AE, i32 0, i32 0, i32 2) to i32 (...)**), i32 (...)***
+// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test71AE, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)***
 A::~A()
 {
 }
@@ -180,7 +180,7 @@
 };
 
 // CHECK-LABEL: define void @_ZN5Test81AD2Ev
-// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test81AE, i32 0, i32 0, i32 2) to i32 (...)**), i32 (...)***
+// CHECK: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN5Test81AE, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)***
 A::~A()
 {
 }
Index: cfe/trunk/test/CodeGenCXX/constructor-init.cpp
===
--- cfe/trunk/test/CodeGenCXX/constructor-init.cpp
+++ cfe/trunk/test/CodeGenCXX/constructor-init.cpp
@@ -95,22 +95,22 @@
 
   // CHECK-LABEL: define void @_ZN10InitVTable1BC2Ev(%"struct.InitVTable::B"* %this) unnamed_addr
   // CHECK:  [[T0:%.*]] = bitcast [[B:%.*]]* [[THIS:%.*]] to i32 (...)***
-  // CHECK-NEXT: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN10InitVTable1BE, i32 0, i32 0, i32 2) to i32 (...)**), i32 (...)*** [[T0]]
+  // CHECK-NEXT: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTVN10InitVTable1BE, i32 0, inrange i32 0, i32 2) to i32 

r289585 - CodeGen: Start using inrange annotations on vtable getelementptr.

2016-12-13 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Tue Dec 13 14:50:44 2016
New Revision: 289585

URL: http://llvm.org/viewvc/llvm-project?rev=289585=rev
Log:
CodeGen: Start using inrange annotations on vtable getelementptr.

This annotation allows the optimizer to split vtable groups, as permitted by
a change to the Itanium ABI [1] that prevents compilers from adjusting virtual
table pointers between virtual tables.

[1] https://github.com/MentorEmbedded/cxx-abi/pull/7

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

Modified:
cfe/trunk/lib/CodeGen/CGVTT.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
cfe/trunk/test/CodeGenCXX/constructor-init.cpp
cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis.cpp
cfe/trunk/test/CodeGenCXX/microsoft-interface.cpp
cfe/trunk/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp
cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
cfe/trunk/test/CodeGenCXX/vtable-pointer-initialization.cpp
cfe/trunk/test/CodeGenCXX/vtt-layout.cpp

Modified: cfe/trunk/lib/CodeGen/CGVTT.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTT.cpp?rev=289585=289584=289585=diff
==
--- cfe/trunk/lib/CodeGen/CGVTT.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTT.cpp Tue Dec 13 14:50:44 2016
@@ -80,8 +80,9 @@ CodeGenVTables::EmitVTTDefinition(llvm::
llvm::ConstantInt::get(Int32Ty, AddressPoint.AddressPointIndex),
  };
 
- llvm::Constant *Init = llvm::ConstantExpr::getInBoundsGetElementPtr(
- VTable->getValueType(), VTable, Idxs);
+ llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr(
+ VTable->getValueType(), VTable, Idxs, /*InBounds=*/true,
+ /*InRangeIndex=*/1);
 
  Init = llvm::ConstantExpr::getBitCast(Init, Int8PtrTy);
 

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=289585=289584=289585=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Tue Dec 13 14:50:44 2016
@@ -1549,8 +1549,9 @@ ItaniumCXXABI::getVTableAddressPoint(Bas
 llvm::ConstantInt::get(CGM.Int32Ty, AddressPoint.AddressPointIndex),
   };
 
-  return llvm::ConstantExpr::getInBoundsGetElementPtr(VTable->getValueType(),
-  VTable, Indices);
+  return llvm::ConstantExpr::getGetElementPtr(VTable->getValueType(), VTable,
+  Indices, /*InBounds=*/true,
+  /*InRangeIndex=*/1);
 }
 
 llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(

Modified: cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp?rev=289585=289584=289585=diff
==
--- cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp Tue Dec 13 14:50:44 2016
@@ -343,13 +343,13 @@ namespace VirtualMembers {
 constexpr E() : B(3), c{'b','y','e'} {}
 char c[3];
   };
-  // CHECK: @_ZN14VirtualMembers1eE = global { i8**, double, i32, i8**, 
double, [5 x i8], i16, i8**, double, [5 x i8], [3 x i8] } { i8** getelementptr 
inbounds ({ [3 x i8*], [4 x i8*], [4 x i8*] }, { [3 x i8*], [4 x i8*], [4 x 
i8*] }* @_ZTVN14VirtualMembers1EE, i32 0, i32 0, i32 2), double 1.00e+00, 
i32 64, i8** getelementptr inbounds ({ [3 x i8*], [4 x i8*], [4 x i8*] }, { [3 
x i8*], [4 x i8*], [4 x i8*] }* @_ZTVN14VirtualMembers1EE, i32 0, i32 1, i32 
2), double 2.00e+00, [5 x i8] c"hello", i16 5, i8** getelementptr inbounds 
({ [3 x i8*], [4 x i8*], [4 x i8*] }, { [3 x i8*], [4 x i8*], [4 x i8*] }* 
@_ZTVN14VirtualMembers1EE, i32 0, i32 2, i32 2), double 3.00e+00, [5 x i8] 
c"world", [3 x i8] c"bye" }
+  // CHECK: @_ZN14VirtualMembers1eE = global { i8**, double, i32, i8**, 
double, [5 x i8], i16, i8**, double, [5 x i8], [3 x i8] } { i8** getelementptr 
inbounds ({ [3 x i8*], [4 x i8*], [4 x i8*] }, { [3 x i8*], [4 x i8*], [4 x 
i8*] }* @_ZTVN14VirtualMembers1EE, i32 0, inrange i32 0, i32 2), double 
1.00e+00, i32 64, i8** getelementptr inbounds ({ [3 x i8*], [4 x i8*], [4 x 
i8*] }, { [3 x i8*], [4 x i8*], [4 x i8*] }* @_ZTVN14VirtualMembers1EE, i32 0, 
inrange i32 1, i32 2), double 2.00e+00, [5 x i8] c"hello", i16 5, i8** 
getelementptr inbounds ({ [3 x i8*], [4 x i8*], [4 x i8*] }, { [3 x i8*], [4 x 
i8*], [4 x i8*] }* @_ZTVN14VirtualMembers1EE, i32 0, inrange i32 2, i32 2), 
double 3.00e+00, [5 x i8] c"world", [3 x i8] c"bye" }
   E e;
 
   struct nsMemoryImpl {
 virtual void 

[PATCH] D22296: CodeGen: New vtable group representation: struct of vtable arrays.

2016-12-13 Thread Peter Collingbourne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
pcc marked an inline comment as done.
Closed by commit rL289584: CodeGen: New vtable group representation: struct of 
vtable arrays. (authored by pcc).

Changed prior to commit:
  https://reviews.llvm.org/D22296?vs=81264=81288#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22296

Files:
  cfe/trunk/include/clang/AST/VTableBuilder.h
  cfe/trunk/include/clang/Basic/LLVM.h
  cfe/trunk/lib/AST/VTableBuilder.cpp
  cfe/trunk/lib/CodeGen/CGCXX.cpp
  cfe/trunk/lib/CodeGen/CGVTT.cpp
  cfe/trunk/lib/CodeGen/CGVTables.cpp
  cfe/trunk/lib/CodeGen/CGVTables.h
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
  cfe/trunk/test/CodeGenCXX/PR26569.cpp
  cfe/trunk/test/CodeGenCXX/apple-kext-indirect-call-2.cpp
  cfe/trunk/test/CodeGenCXX/apple-kext-indirect-call.cpp
  cfe/trunk/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  cfe/trunk/test/CodeGenCXX/cfi-cross-dso.cpp
  cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
  cfe/trunk/test/CodeGenCXX/constructor-init.cpp
  cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
  cfe/trunk/test/CodeGenCXX/copy-constructor-synthesis.cpp
  cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp
  cfe/trunk/test/CodeGenCXX/dllexport.cpp
  cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp
  cfe/trunk/test/CodeGenCXX/dllimport.cpp
  cfe/trunk/test/CodeGenCXX/invariant.group-for-vptrs.cpp
  cfe/trunk/test/CodeGenCXX/key-function-vtable.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-constexpr-vs-inheritance.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-extern-template.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-vftables.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-return-thunks.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-interface.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-no-rtti-data.cpp
  cfe/trunk/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
  cfe/trunk/test/CodeGenCXX/strict-vtable-pointers.cpp
  cfe/trunk/test/CodeGenCXX/vtable-align.cpp
  cfe/trunk/test/CodeGenCXX/vtable-assume-load.cpp
  cfe/trunk/test/CodeGenCXX/vtable-pointer-initialization.cpp
  cfe/trunk/test/CodeGenCXX/vtt-layout.cpp

Index: cfe/trunk/include/clang/AST/VTableBuilder.h
===
--- cfe/trunk/include/clang/AST/VTableBuilder.h
+++ cfe/trunk/include/clang/AST/VTableBuilder.h
@@ -218,52 +218,77 @@
 class VTableLayout {
 public:
   typedef std::pair VTableThunkTy;
-  typedef llvm::DenseMap AddressPointsMapTy;
+  struct AddressPointLocation {
+unsigned VTableIndex, AddressPointIndex;
+  };
+  typedef llvm::DenseMap
+  AddressPointsMapTy;
 
 private:
-  uint64_t NumVTableComponents;
-  std::unique_ptr VTableComponents;
+  // Stores the component indices of the first component of each virtual table in
+  // the virtual table group. To save a little memory in the common case where
+  // the vtable group contains a single vtable, an empty vector here represents
+  // the vector {0}.
+  OwningArrayRef VTableIndices;
+
+  OwningArrayRef VTableComponents;
 
   /// \brief Contains thunks needed by vtables, sorted by indices.
-  uint64_t NumVTableThunks;
-  std::unique_ptr VTableThunks;
+  OwningArrayRef VTableThunks;
 
   /// \brief Address points for all vtables.
   AddressPointsMapTy AddressPoints;
 
-  bool IsMicrosoftABI;
-
 public:
-  VTableLayout(uint64_t NumVTableComponents,
-   const VTableComponent *VTableComponents,
-   uint64_t NumVTableThunks,
-   const VTableThunkTy *VTableThunks,
-   const AddressPointsMapTy ,
-   bool IsMicrosoftABI);
+  VTableLayout(ArrayRef VTableIndices,
+   ArrayRef VTableComponents,
+   ArrayRef VTableThunks,
+   const AddressPointsMapTy );
   ~VTableLayout();
 
   ArrayRef vtable_components() const {
-return {VTableComponents.get(), size_t(NumVTableComponents)};
+return VTableComponents;
   }
 
   ArrayRef vtable_thunks() const {
-return {VTableThunks.get(), size_t(NumVTableThunks)};
+return VTableThunks;
   }
 
-  uint64_t getAddressPoint(BaseSubobject Base) const {
-assert(AddressPoints.count(Base) &&
-   "Did not find address point!");
-
-uint64_t AddressPoint = AddressPoints.lookup(Base);
-assert(AddressPoint != 0 || IsMicrosoftABI);
-(void)IsMicrosoftABI;
-
-return AddressPoint;
+  AddressPointLocation getAddressPoint(BaseSubobject Base) const {
+assert(AddressPoints.count(Base) && 

[PATCH] D27726: [analyzer] Refer to macro names in diagnostics for macros representing a literal

2016-12-13 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna created this revision.
zaks.anna added reviewers: dergachev.a, dcoughlin.
zaks.anna added a subscriber: cfe-commits.

When a macro expending to a literal is used in a comparison, use the macro name 
in the diagnostic rather than the literal. This improves readability of path 
notes.

Added tests for various macro literals that could occur. Only BOOl, Int, and 
NULL tests have changed behavior with this patch.


https://reviews.llvm.org/D27726

Files:
  include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  test/Analysis/Inputs/system-header-simulator-objc.h
  test/Analysis/Inputs/system-header-simulator.h
  test/Analysis/diagnostics/macros.cpp
  test/Analysis/diagnostics/macros.m

Index: test/Analysis/diagnostics/macros.m
===
--- /dev/null
+++ test/Analysis/diagnostics/macros.m
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx -fblocks -analyzer-output=text -verify %s
+
+#include "../Inputs/system-header-simulator-objc.h"
+
+@interface NSDictionary : NSObject
+- (NSUInteger)count;
+- (id)objectForKey:(id)aKey;
+- (NSEnumerator *)keyEnumerator;
+@end
+@interface NSMutableDictionary : NSDictionary
+- (void)setObject:(id)anObject forKey:(id )aKey;
+@end
+
+void testBOOLMacro(BOOL b) {
+  if (b == YES) { // expected-note {{Assuming 'b' is equal to YES}}
+  // expected-note@-1 {{Taking true branch}}
+char *p = NULL;// expected-note {{'p' initialized to a null pointer value}}
+*p = 7;  // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
+ // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
+  }
+}
+
+void testNilMacro(NSMutableDictionary *d, NSObject *o) {
+  if (o == nil) // expected-note {{Assuming 'o' is equal to nil}}
+// expected-note@-1 {{Taking true branch}}
+[d setObject:o forKey:[o description]]; // expected-warning {{Key argument to 'setObject:forKey:' cannot be nil}}
+// expected-note@-1 {{'description' not called because the receiver is nil}}
+// expected-note@-2 {{Key argument to 'setObject:forKey:' cannot be nil}}
+
+  return;
+}
Index: test/Analysis/diagnostics/macros.cpp
===
--- /dev/null
+++ test/Analysis/diagnostics/macros.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=core,osx -analyzer-output=text -verify %s
+
+#include "../Inputs/system-header-simulator.h"
+#include "../Inputs/system-header-simulator-cxx.h"
+
+void testIntMacro(unsigned int i) {
+  if (i == UINT32_MAX) { // expected-note {{Assuming 'i' is equal to UINT32_MAX}}
+ // expected-note@-1 {{Taking true branch}}
+char *p = NULL; // expected-note {{'p' initialized to a null pointer value}}
+*p = 7;  // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
+ // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
+  }
+}
+
+void testNULLMacro(int *p) {
+  if (p == NULL) { // expected-note {{Assuming 'p' is equal to NULL}}
+   // expected-note@-1 {{Taking true branch}}
+*p = 7;  // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
+ // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
+  }
+}
+
+void testnullptrMacro(int *p) {
+  if (p == nullptr) { // expected-note {{Assuming pointer value is null}}
+  // expected-note@-1 {{Taking true branch}}
+*p = 7;  // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
+ // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
+  }
+}
+
+// There are no path notes on the comparison to float types.
+void testDoubleMacro(double d) {
+  if (d == DBL_MAX) { // expected-note {{Taking true branch}}
+
+char *p = NULL; // expected-note {{'p' initialized to a null pointer value}}
+*p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
+// expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
+  }
+}
+
+void testboolMacro(bool b, int *p) {
+  p = nullptr;  // expected-note {{Null pointer value stored to 'p'}}
+  if (b == false) { // expected-note {{Assuming the condition is true}}
+// expected-note@-1 {{Taking true branch}}
+*p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}}
+// expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}}
+  }
+}
\ No newline at end of file
Index: test/Analysis/Inputs/system-header-simulator.h
===
--- 

[PATCH] D27680: [CodeGen] Move lifetime.start of a variable when goto jumps back past its declaration

2016-12-13 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 81284.
ahatanak added a comment.

Address review comment. Use llvm::is_contained instead of std::find.


https://reviews.llvm.org/D27680

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/lifetime2.c

Index: test/CodeGen/lifetime2.c
===
--- test/CodeGen/lifetime2.c
+++ test/CodeGen/lifetime2.c
@@ -19,11 +19,11 @@
 
 // CHECK-LABEL: @no_goto_bypass
 void no_goto_bypass() {
+  // O2: @llvm.lifetime.start(i64 5
   // O2: @llvm.lifetime.start(i64 1
   char x;
 l1:
   bar(, 1);
-  // O2: @llvm.lifetime.start(i64 5
   // O2: @llvm.lifetime.end(i64 5
   char y[5];
   bar(y, 5);
@@ -89,3 +89,27 @@
 L:
   bar(, 1);
 }
+
+// O2: %[[ALLOCA:[a-z0-9]+]] = alloca i32, align 4
+// O2: %[[BITCAST:[0-9]+]] = bitcast i32* %[[ALLOCA]] to i8*
+// O2: call void @llvm.lifetime.start(i64 4, i8* nonnull %[[BITCAST]])
+// O2: [[DESTLABEL:[a-z0-9]+]]:
+// O2: br {{.*}} label %[[DESTLABEL]]
+
+extern void foo2(int p);
+
+int move_lifetime_start(int a) {
+  int *p = 0;
+ label1:
+  if (p) {
+foo2(*p);
+return 0;
+  }
+
+  int i = 999;
+  if (a != 2) {
+p = 
+goto label1;
+  }
+  return -1;
+}
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -322,14 +322,20 @@
   class CallLifetimeEnd final : public EHScopeStack::Cleanup {
 llvm::Value *Addr;
 llvm::Value *Size;
+llvm::CallInst *LifetimeStart;
 
   public:
-CallLifetimeEnd(Address addr, llvm::Value *size)
-: Addr(addr.getPointer()), Size(size) {}
+CallLifetimeEnd(Address addr, llvm::Value *size,
+llvm::CallInst *lifetimeStart = nullptr)
+: Addr(addr.getPointer()), Size(size), LifetimeStart(lifetimeStart) {}
 
 void Emit(CodeGenFunction , Flags flags) override {
   CGF.EmitLifetimeEnd(Size, Addr);
 }
+
+llvm::CallInst *() {
+  return LifetimeStart;
+}
   };
 
   /// Header for data within LifetimeExtendedCleanupStack.
@@ -497,10 +503,10 @@
   /// \brief Enters a new scope for capturing cleanups, all of which
   /// will be executed once the scope is exited.
   class RunCleanupsScope {
-EHScopeStack::stable_iterator CleanupStackDepth;
 size_t LifetimeExtendedCleanupStackSize;
 bool OldDidCallStackSave;
   protected:
+EHScopeStack::stable_iterator CleanupStackDepth;
 bool PerformCleanup;
   private:
 
@@ -552,6 +558,7 @@
 SourceRange Range;
 SmallVector Labels;
 LexicalScope *ParentScope;
+llvm::BasicBlock *BB;
 
 LexicalScope(const LexicalScope &) = delete;
 void operator=(const LexicalScope &) = delete;
@@ -563,13 +570,27 @@
   CGF.CurLexicalScope = this;
   if (CGDebugInfo *DI = CGF.getDebugInfo())
 DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin());
+  CGF.EnsureInsertPoint();
+  BB = CGF.Builder.GetInsertBlock();
 }
 
 void addLabel(const LabelDecl *label) {
   assert(PerformCleanup && "adding label to dead scope?");
   Labels.push_back(label);
 }
 
+EHScopeStack::stable_iterator getCleanupStackDepth() const {
+  return CleanupStackDepth;
+}
+
+llvm::BasicBlock *getBasicBlock() const {
+  return BB;
+}
+
+LexicalScope *getParentScope() const {
+  return ParentScope;
+}
+
 /// \brief Exit this cleanup scope, emitting any accumulated
 /// cleanups.
 ~LexicalScope() {
@@ -594,6 +615,10 @@
 rescopeLabels();
 }
 
+bool hasLabel(const LabelDecl *LD) const {
+  return llvm::is_contained(Labels, LD);
+}
+
 void rescopeLabels();
   };
 
@@ -2124,7 +2149,7 @@
   void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType,
 Address Ptr);
 
-  llvm::Value *EmitLifetimeStart(uint64_t Size, llvm::Value *Addr);
+  llvm::CallInst *EmitLifetimeStart(uint64_t Size, llvm::Value *Addr);
   void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
@@ -2253,27 +2278,30 @@
 bool IsConstantAggregate;
 
 /// Non-null if we should use lifetime annotations.
-llvm::Value *SizeForLifetimeMarkers;
+llvm::CallInst *LifetimeStart;
 
 struct Invalid {};
 AutoVarEmission(Invalid) : Variable(nullptr), Addr(Address::invalid()) {}
 
 AutoVarEmission(const VarDecl )
   : Variable(), Addr(Address::invalid()), NRVOFlag(nullptr),
-IsByRef(false), IsConstantAggregate(false),
-SizeForLifetimeMarkers(nullptr) {}
+IsByRef(false), IsConstantAggregate(false), LifetimeStart(nullptr) {}
 
 bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
 
   public:
 static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
 
 bool useLifetimeMarkers() const {
-  return SizeForLifetimeMarkers != 

[clang-tools-extra] r289581 - [powerpc] deactivate readability-identifier-naming.cpp test on powerpc64le

2016-12-13 Thread Bill Seurer via cfe-commits
Author: seurer
Date: Tue Dec 13 14:26:35 2016
New Revision: 289581

URL: http://llvm.org/viewvc/llvm-project?rev=289581=rev
Log:
[powerpc] deactivate readability-identifier-naming.cpp test on powerpc64le

The test case clang-tidy/readability-identifier-naming.cpp segfaults on
powerpc64 little endian (starting with r288563) when a bootstrap build/test
is done.  To get the buildbot running again deactivate the test.
When the issue is resolved reactivate it.


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

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp?rev=289581=289580=289581=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp 
Tue Dec 13 14:26:35 2016
@@ -1,3 +1,6 @@
+// Remove UNSUPPORTED for powerpc64le when the problem introduced by
+// r288563 is resolved.
+// UNSUPPORTED: powerpc64le
 // RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
 // RUN:   -config='{CheckOptions: [ \
 // RUN: {key: readability-identifier-naming.AbstractClassCase, value: 
CamelCase}, \


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


[clang-tools-extra] r289580 - Fix size_t typdef in new cppcoreguidelines-no-malloc.cpp test

2016-12-13 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Dec 13 14:25:47 2016
New Revision: 289580

URL: http://llvm.org/viewvc/llvm-project?rev=289580=rev
Log:
Fix size_t typdef in new cppcoreguidelines-no-malloc.cpp test

Modified:
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp?rev=289580=289579=289580=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp Tue 
Dec 13 14:25:47 2016
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s cppcoreguidelines-no-malloc %t
 
-using size_t = unsigned long;
+using size_t = __SIZE_TYPE__;
 
 void *malloc(size_t size);
 void *calloc(size_t num, size_t size);


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


[PATCH] D26167: [Clang-tidy] check for malloc, realloc and free calls

2016-12-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

nit: All of the new files had UTF-8 BOMs, which I don't think we usually add.




Comment at: test/clang-tidy/cppcoreguidelines-no-malloc.cpp:3
+
+using size_t = unsigned long;
+

This test did not pass on 32-bit Windows. I will change it to:
  using size_t = __SIZE_TYPE__;


Repository:
  rL LLVM

https://reviews.llvm.org/D26167



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-13 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

Do the fixits work when the object is a pointer to a string?
`pstr1->compare(str2) == 0`
Does the warning work when the argument is a pointer to a string?
`str1.compare(*pstr2) == 0`
Does the warning work when the argument is the result of a function call?
Does the warning work when the object is the result of a function call?


https://reviews.llvm.org/D27210



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


[PATCH] D27377: clang-format: Support the Java 8 'default' method modifier

2016-12-13 Thread Luis Héctor Chávez via Phabricator via cfe-commits
lhchavez marked 3 inline comments as done.
lhchavez added inline comments.



Comment at: lib/Format/UnwrappedLineParser.cpp:870
+}
+// 'default' can appear in a Java 8 declaration. Parse it as such.
+break;

djasper wrote:
> Is there a test case that hits this codepath? IIUC, it would need to have a 
> "default" of a declaration that's not at the start of the line.
Added two more test cases.


https://reviews.llvm.org/D27377



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


[PATCH] D27377: clang-format: Support the Java 8 'default' method modifier

2016-12-13 Thread Luis Héctor Chávez via Phabricator via cfe-commits
lhchavez updated this revision to Diff 81280.
lhchavez added a comment.

Addressed feedback


https://reviews.llvm.org/D27377

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestJava.cpp


Index: unittests/Format/FormatTestJava.cpp
===
--- unittests/Format/FormatTestJava.cpp
+++ unittests/Format/FormatTestJava.cpp
@@ -515,5 +515,22 @@
"  void f() {}"));
 }
 
+TEST_F(FormatTestJava, UnderstandsDefaultModifier) {
+  verifyFormat("class SomeClass {\n"
+   "  default void f() {}\n"
+   "  public default void g() {}\n"
+   "  default public void h() {}\n"
+   "  int i() {\n"
+   "switch (0) {\n"
+   "  case 0:\n"
+   "break;\n"
+   "  default:\n"
+   "break;\n"
+   "}\n"
+   "  }\n"
+   "}",
+   getGoogleStyle(FormatStyle::LK_Java));
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -294,6 +294,11 @@
   addUnwrappedLine();
   break;
 case tok::kw_default:
+  if (Style.Language == FormatStyle::LK_Java && Line->MustBeDeclaration) {
+parseStructuralElement();
+break;
+  }
+  // fallthrough
 case tok::kw_case:
   if (!SwitchLabelEncountered &&
   (Style.IndentCaseLabels || (Line->InPPDirective && Line->Level == 
1)))
@@ -853,6 +858,8 @@
 parseSwitch();
 return;
   case tok::kw_default:
+if (Style.Language == FormatStyle::LK_Java && Line->MustBeDeclaration)
+  break;
 nextToken();
 parseLabel();
 return;


Index: unittests/Format/FormatTestJava.cpp
===
--- unittests/Format/FormatTestJava.cpp
+++ unittests/Format/FormatTestJava.cpp
@@ -515,5 +515,22 @@
"  void f() {}"));
 }
 
+TEST_F(FormatTestJava, UnderstandsDefaultModifier) {
+  verifyFormat("class SomeClass {\n"
+   "  default void f() {}\n"
+   "  public default void g() {}\n"
+   "  default public void h() {}\n"
+   "  int i() {\n"
+   "switch (0) {\n"
+   "  case 0:\n"
+   "break;\n"
+   "  default:\n"
+   "break;\n"
+   "}\n"
+   "  }\n"
+   "}",
+   getGoogleStyle(FormatStyle::LK_Java));
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -294,6 +294,11 @@
   addUnwrappedLine();
   break;
 case tok::kw_default:
+  if (Style.Language == FormatStyle::LK_Java && Line->MustBeDeclaration) {
+parseStructuralElement();
+break;
+  }
+  // fallthrough
 case tok::kw_case:
   if (!SwitchLabelEncountered &&
   (Style.IndentCaseLabels || (Line->InPPDirective && Line->Level == 1)))
@@ -853,6 +858,8 @@
 parseSwitch();
 return;
   case tok::kw_default:
+if (Style.Language == FormatStyle::LK_Java && Line->MustBeDeclaration)
+  break;
 nextToken();
 parseLabel();
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r289544 - Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64.

2016-12-13 Thread Tom Stellard via cfe-commits
On Tue, Dec 13, 2016 at 04:22:50PM -, Neil Hickey via cfe-commits wrote:
> Author: neil.hickey
> Date: Tue Dec 13 10:22:50 2016
> New Revision: 289544
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=289544=rev
> Log:
> Improve handling of floating point literals in OpenCL to only use double 
> precision if the target supports fp64.
> 
> This change makes sure single-precision floating point types are used if the 
> cl_fp64 extension is not supported by the target.
> 
> Also removed the check to see whether the OpenCL version is >= 1.2, as this 
> has
> been incorporated into the extension setting code.
> 
> Differential Revision: https://reviews.llvm.org/D24235
> 
> 

This patch causes a crash when compiling libclc.  You can reproduce by
compiling this function:

int isnan(float x){ return __builtin_isnan(x); }

As I recall there is some weirdness with how clang does type
deduction for these builtins, but the compiler shouldn't be crashing.

-Tom


> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/lib/Sema/SemaType.cpp
> cfe/trunk/test/CodeGenOpenCL/fpmath.cl
> cfe/trunk/test/SemaOpenCL/extensions.cl
> 
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=289544=289543=289544=diff
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec 13 10:22:50 2016
> @@ -3748,12 +3748,13 @@ bool Sema::SemaBuiltinFPClassification(C
>  diag::err_typecheck_call_invalid_unary_fp)
><< OrigArg->getType() << OrigArg->getSourceRange();
>  
> -  // If this is an implicit conversion from float -> double, remove it.
> +  // If this is an implicit conversion from float -> float or double, remove 
> it.
>if (ImplicitCastExpr *Cast = dyn_cast(OrigArg)) {
>  Expr *CastArg = Cast->getSubExpr();
>  if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) {
> -  assert(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) &&
> - "promotion from float to double is the only expected cast 
> here");
> +assert((Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) 
> ||
> +Cast->getType()->isSpecificBuiltinType(BuiltinType::Float)) 
> &&
> + "promotion from float to either float or double is the only 
> expected cast here");
>Cast->setSubExpr(nullptr);
>TheCall->setArg(NumArgs-1, CastArg);
>  }
> 
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=289544=289543=289544=diff
> ==
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Dec 13 10:22:50 2016
> @@ -817,8 +817,16 @@ ExprResult Sema::DefaultArgumentPromotio
>// double.
>const BuiltinType *BTy = Ty->getAs();
>if (BTy && (BTy->getKind() == BuiltinType::Half ||
> -  BTy->getKind() == BuiltinType::Float))
> -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get();
> +  BTy->getKind() == BuiltinType::Float)) {
> +if (getLangOpts().OpenCL &&
> +!(getOpenCLOptions().cl_khr_fp64)) {
> +if (BTy->getKind() == BuiltinType::Half) {
> +E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get();
> +}
> +} else {
> +  E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get();
> +}
> +  }
>  
>// C++ performs lvalue-to-rvalue conversion as a default argument
>// promotion, even on class types, but note:
> @@ -3397,10 +3405,13 @@ ExprResult Sema::ActOnNumericConstant(co
>  
>  if (Ty == Context.DoubleTy) {
>if (getLangOpts().SinglePrecisionConstants) {
> -Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
> +const BuiltinType *BTy = Ty->getAs();
> +if (BTy->getKind() != BuiltinType::Float) {
> +  Res = ImpCastExprToType(Res, Context.FloatTy, 
> CK_FloatingCast).get();
> +}
>} else if (getLangOpts().OpenCL &&
> - !((getLangOpts().OpenCLVersion >= 120) ||
> -   getOpenCLOptions().cl_khr_fp64)) {
> + !(getOpenCLOptions().cl_khr_fp64)) {
> +// Impose single-precision float type when cl_khr_fp64 is not 
> enabled.
>  Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64);
>  Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
>}
> 
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=289544=289543=289544=diff
> ==
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ 

r289575 - Align EvalInfo in ExprConstant to avoid PointerUnion assertions

2016-12-13 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Dec 13 13:48:32 2016
New Revision: 289575

URL: http://llvm.org/viewvc/llvm-project?rev=289575=rev
Log:
Align EvalInfo in ExprConstant to avoid PointerUnion assertions

32-bit MSVC doesn't provide more than 4 byte stack alignment by default.
This conflicts with PointerUnion's attempt to make assertions about
alignment. This fixes the problem by explicitly asking the compiler for
8 byte alignment.

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

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=289575=289574=289575=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Dec 13 13:48:32 2016
@@ -433,7 +433,7 @@ namespace {
   /// rules.  For example, the RHS of (0 && foo()) is not evaluated.  We can
   /// evaluate the expression regardless of what the RHS is, but C only allows
   /// certain things in certain situations.
-  struct EvalInfo {
+  struct LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) EvalInfo {
 ASTContext 
 
 /// EvalStatus - Contains information about the evaluation.


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


[PATCH] D25263: [Driver] Allow setting the default linker during build

2016-12-13 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 81276.
phosek marked 3 inline comments as done.

Repository:
  rL LLVM

https://reviews.llvm.org/D25263

Files:
  CMakeLists.txt
  include/clang/Config/config.h.cmake
  include/clang/Driver/ToolChain.h
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h

Index: lib/Driver/ToolChains.h
===
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -961,6 +961,10 @@
  : RuntimeLibType::RLT_CompilerRT;
   }
 
+  const char *getDefaultLinker() const override {
+return "lld";
+  }
+
 private:
   Multilib SelectedMultilib;
   std::string LibSuffix;
@@ -1090,6 +1094,10 @@
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
+  const char *getDefaultLinker() const override {
+return "lld";
+  }
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
@@ -1289,6 +1297,10 @@
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
 
+  const char *getDefaultLinker() const override {
+return "lld";
+  }
+
   Tool *buildLinker() const override;
 };
 
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -3059,9 +3059,6 @@
   LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple);
   getFilePaths().clear();
   getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix);
-
-  // Use LLD by default.
-  DefaultLinker = "lld";
 }
 
 void MipsLLVMToolChain::AddClangSystemIncludeArgs(
@@ -4749,9 +4746,6 @@
 
   getFilePaths().push_back(D.SysRoot + "/lib");
   getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
-
-  // Use LLD by default.
-  DefaultLinker = "lld";
 }
 
 Tool *Fuchsia::buildAssembler() const {
@@ -5173,9 +5167,6 @@
   assert(Triple.isArch32Bit() != Triple.isArch64Bit());
   getFilePaths().push_back(
   getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64"));
-
-  // Use LLD by default.
-  DefaultLinker = "lld";
 }
 
 bool WebAssembly::IsMathErrnoDefault() const { return false; }
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -351,33 +351,31 @@
 }
 
 std::string ToolChain::GetLinkerPath() const {
-  if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
-StringRef UseLinker = A->getValue();
-
-if (llvm::sys::path::is_absolute(UseLinker)) {
-  // If we're passed -fuse-ld= with what looks like an absolute path,
-  // don't attempt to second-guess that.
-  if (llvm::sys::fs::exists(UseLinker))
-return UseLinker;
-} else {
-  // If we're passed -fuse-ld= with no argument, or with the argument ld,
-  // then use whatever the default system linker is.
-  if (UseLinker.empty() || UseLinker == "ld")
-return GetProgramPath("ld");
-
-  llvm::SmallString<8> LinkerName("ld.");
-  LinkerName.append(UseLinker);
-
-  std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
-  if (llvm::sys::fs::exists(LinkerPath))
-return LinkerPath;
-}
+  const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ);
+  StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
+
+  if (llvm::sys::path::is_absolute(UseLinker)) {
+// If we're passed what looks like an absolute path, don't attempt to
+// second-guess that.
+if (llvm::sys::fs::exists(UseLinker))
+  return UseLinker;
+  } else if (UseLinker.empty() || UseLinker == "ld") {
+// If we're passed -fuse-ld= with no argument, or with the argument ld,
+// then use whatever the default system linker is.
+return GetProgramPath(getDefaultLinker());
+  } else {
+llvm::SmallString<8> LinkerName("ld.");
+LinkerName.append(UseLinker);
+
+std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
+if (llvm::sys::fs::exists(LinkerPath))
+  return LinkerPath;
+  }
 
+  if (A)
 getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
-return "";
-  }
 
-  return GetProgramPath(DefaultLinker);
+  return GetProgramPath(getDefaultLinker());
 }
 
 types::ID ToolChain::LookupTypeForExtension(StringRef Ext) const {
Index: include/clang/Driver/ToolChain.h
===
--- include/clang/Driver/ToolChain.h
+++ include/clang/Driver/ToolChain.h
@@ -105,7 +105,6 @@
 
 protected:
   MultilibSet Multilibs;
-  const char *DefaultLinker = "ld";
 
   ToolChain(const Driver , const llvm::Triple ,
 const llvm::opt::ArgList );
@@ -272,6 +271,11 @@
 return 0;
   }
 
+  /// GetDefaultLinker - Get the default linker to use.
+  virtual const char *getDefaultLinker() const {
+return "ld";
+  }
+
   /// 

Re: r289413 - Add two new AST nodes to represent initialization of an array in terms of

2016-12-13 Thread Reid Kleckner via cfe-commits
Aha, you have activated the win32 stack alignment trap card. By adding a
uint64_t to EvalInfo, you have increased its alignment to 8. Unfortunately,
MSVC doesn't actually align stack objects to more than 4 unless you really
ask it to with __declspec(align). Normally this stuff flies under the
radar, but PointerUnion makes assertions about alignment. A possible fix:

diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 61bb2b9..e18caff 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -433,7 +433,7 @@ namespace {
   /// rules.  For example, the RHS of (0 && foo()) is not evaluated.  We
can
   /// evaluate the expression regardless of what the RHS is, but C only
allows
   /// certain things in certain situations.
-  struct EvalInfo {
+  struct LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) EvalInfo {
 ASTContext 

 /// EvalStatus - Contains information about the evaluation.

This has the downside that it will emit more stack realignment prologues
for MSVC x86 builds. I know Sony cares about MSVC-built clang performance,
but I don't know if they ship 32-bit or 64-bit binaries.

On Tue, Dec 13, 2016 at 11:43 AM, Reid Kleckner  wrote:

> It's probably this change:
>
> $ "C:/src/llvm/build_x86/./bin/clang.EXE" "-cc1" "-internal-isystem"
> "C:\src\llvm\build_x86\bin\..\lib\clang\4.0.0\include" "-nostdsysteminc"
> "-fsyntax-only" "-Wno-everything" "-Wobjc-literal-compare" "-Dnil=(id)0"
> "-verify" "C:\src\llvm\tools\clang\test\SemaObjC\objc-literal-
> comparison.m"
> # command stderr:
> Assertion failed: (PtrWord & ~PointerBitMask) == 0 && "Pointer is not
> sufficiently aligned", file C:\src\llvm\include\llvm/ADT/PointerIntPair.h,
> line 160
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D22296: CodeGen: New vtable group representation: struct of vtable arrays.

2016-12-13 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


https://reviews.llvm.org/D22296



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


r289571 - [Sema] Prefer SmallVector over `new`ed memory blocks. NFC.

2016-12-13 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Tue Dec 13 13:22:56 2016
New Revision: 289571

URL: http://llvm.org/viewvc/llvm-project?rev=289571=rev
Log:
[Sema] Prefer SmallVector over `new`ed memory blocks. NFC.

Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=289571=289570=289571=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Dec 13 13:22:56 2016
@@ -12749,9 +12749,9 @@ Sema::BuildCallToObjectOfClassType(Scope
 
   // Build the full argument list for the method call (the implicit object
   // parameter is placed at the beginning of the list).
-  std::unique_ptr MethodArgs(new Expr *[Args.size() + 1]);
+  SmallVector MethodArgs(Args.size() + 1);
   MethodArgs[0] = Object.get();
-  std::copy(Args.begin(), Args.end(), [1]);
+  std::copy(Args.begin(), Args.end(), MethodArgs.begin() + 1);
 
   // Once we've built TheCall, all of the expressions are properly
   // owned.
@@ -12760,10 +12760,8 @@ Sema::BuildCallToObjectOfClassType(Scope
   ResultTy = ResultTy.getNonLValueExprType(Context);
 
   CXXOperatorCallExpr *TheCall = new (Context)
-  CXXOperatorCallExpr(Context, OO_Call, NewFn.get(),
-  llvm::makeArrayRef(MethodArgs.get(), Args.size() + 
1),
-  ResultTy, VK, RParenLoc, false);
-  MethodArgs.reset();
+  CXXOperatorCallExpr(Context, OO_Call, NewFn.get(), MethodArgs, ResultTy,
+  VK, RParenLoc, false);
 
   if (CheckCallReturnType(Method->getReturnType(), LParenLoc, TheCall, Method))
 return true;


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


[PATCH] D27377: clang-format: Support the Java 8 'default' method modifier

2016-12-13 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added inline comments.



Comment at: lib/Format/UnwrappedLineParser.cpp:297
 case tok::kw_default:
+  if (Style.Language != FormatStyle::LK_Java || !Line->MustBeDeclaration) {
+if (!SwitchLabelEncountered &&

Same as below.



Comment at: lib/Format/UnwrappedLineParser.cpp:865
   case tok::kw_default:
-nextToken();
-parseLabel();
-return;
+if (Style.Language != FormatStyle::LK_Java || !Line->MustBeDeclaration) {
+  nextToken();

Change the order here. I.e.

  if (Style.Language == FormatStyle::LK_Java && Line->MustBeDeclaration)
break;
  ...

I think then you almost don't even need the comment.



Comment at: lib/Format/UnwrappedLineParser.cpp:870
+}
+// 'default' can appear in a Java 8 declaration. Parse it as such.
+break;

Is there a test case that hits this codepath? IIUC, it would need to have a 
"default" of a declaration that's not at the start of the line.


https://reviews.llvm.org/D27377



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


[PATCH] D22296: CodeGen: New vtable group representation: struct of vtable arrays.

2016-12-13 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc marked 3 inline comments as done.
pcc added inline comments.



Comment at: clang/include/clang/AST/VTableBuilder.h:255
+operator ArrayRef() const { return {data(), size()}; };
+  };
+

rjmccall wrote:
> Maybe this ought to be in LLVM as OwnedArrayRef?  And the more minimal 
> implementation approach would be to inherit from MutableArrayRef and just 
> add a destructor and a move constructor.
> 
> The implicit conversion to ArrayRef is dangerous, but only in ways that 
> ArrayRef is already dangerous.
Good suggestions -- sent out D27723.


https://reviews.llvm.org/D22296



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


[PATCH] D22296: CodeGen: New vtable group representation: struct of vtable arrays.

2016-12-13 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc updated this revision to Diff 81264.
pcc added a comment.

- Address review comments


https://reviews.llvm.org/D22296

Files:
  clang/include/clang/AST/VTableBuilder.h
  clang/include/clang/Basic/LLVM.h
  clang/lib/AST/VTableBuilder.cpp
  clang/lib/CodeGen/CGCXX.cpp
  clang/lib/CodeGen/CGVTT.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CGVTables.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/PR26569.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call-2.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-call.cpp
  clang/test/CodeGenCXX/apple-kext-indirect-virtual-dtor-call.cpp
  clang/test/CodeGenCXX/cfi-cross-dso.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/constructor-init.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
  clang/test/CodeGenCXX/copy-constructor-synthesis.cpp
  clang/test/CodeGenCXX/ctor-dtor-alias.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport-rtti.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/invariant.group-for-vptrs.cpp
  clang/test/CodeGenCXX/key-function-vtable.cpp
  clang/test/CodeGenCXX/microsoft-abi-constexpr-vs-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-abi-extern-template.cpp
  clang/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp
  clang/test/CodeGenCXX/microsoft-abi-vftables.cpp
  clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-abi-vtables-return-thunks.cpp
  clang/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-interface.cpp
  clang/test/CodeGenCXX/microsoft-no-rtti-data.cpp
  clang/test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
  clang/test/CodeGenCXX/strict-vtable-pointers.cpp
  clang/test/CodeGenCXX/vtable-align.cpp
  clang/test/CodeGenCXX/vtable-assume-load.cpp
  clang/test/CodeGenCXX/vtable-pointer-initialization.cpp
  clang/test/CodeGenCXX/vtt-layout.cpp

Index: clang/test/CodeGenCXX/vtt-layout.cpp
===
--- clang/test/CodeGenCXX/vtt-layout.cpp
+++ clang/test/CodeGenCXX/vtt-layout.cpp
@@ -78,11 +78,12 @@
   }
 }
 
-// CHECK: @_ZTTN5Test11BE = unnamed_addr constant [1 x i8*] [i8* bitcast (i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @_ZTVN5Test11BE, i32 0, i32 3) to i8*)]
-// CHECK: @_ZTVN5Test51AE = unnamed_addr constant [4 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTIN5Test51AE to i8*), i8* bitcast (void ()* @__cxa_pure_virtual to i8*), i8* bitcast (void (%"struct.Test5::A"*)* @_ZN5Test51A6anchorEv to i8*)]
-// CHECK: @_ZTVN5Test61AE = unnamed_addr constant [4 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTIN5Test61AE to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to i8*), i8* bitcast (void (%"struct.Test6::A"*)* @_ZN5Test61A6anchorEv to i8*)]
-// CHECK: @_ZTTN5Test21CE = linkonce_odr unnamed_addr constant [2 x i8*] [i8* bitcast (i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @_ZTVN5Test21CE, i32 0, i32 4) to i8*), i8* bitcast (i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @_ZTVN5Test21CE, i32 0, i32 4) to i8*)] 
-// CHECK: @_ZTTN5Test31DE = linkonce_odr unnamed_addr constant [13 x i8*] [i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i32 0, i32 5) to i8*), i8* bitcast (i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @_ZTCN5Test31DE0_NS_2C1E, i32 0, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @_ZTCN5Test31DE0_NS_2C1E, i32 0, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ([14 x i8*], [14 x i8*]* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ([14 x i8*], [14 x i8*]* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 6) to i8*), i8* bitcast (i8** getelementptr inbounds ([14 x i8*], [14 x i8*]* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 10) to i8*), i8* bitcast (i8** getelementptr inbounds ([14 x i8*], [14 x i8*]* @_ZTCN5Test31DE16_NS_2C2E, i32 0, i32 13) to i8*), i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i32 0, i32 15) to i8*), i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i32 0, i32 11) to i8*), i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i32 0, i32 11) to i8*), i8* bitcast (i8** getelementptr inbounds ([19 x i8*], [19 x i8*]* @_ZTVN5Test31DE, i64 1, i32 0) to i8*), i8* bitcast (i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @_ZTCN5Test31DE64_NS_2V2E, i32 0, i32 3) to i8*), i8* bitcast (i8** getelementptr inbounds ([7 x i8*], [7 x i8*]* @_ZTCN5Test31DE64_NS_2V2E, i32 0, i32 6) to i8*)] 
-// CHECK: @_ZTTN5Test41DE = linkonce_odr unnamed_addr constant [19 x i8*] [i8* bitcast (i8** getelementptr inbounds ([25 x i8*], [25 x i8*]* @_ZTVN5Test41DE, i32 0, 

[PATCH] D27377: clang-format: Support the Java 8 'default' method modifier

2016-12-13 Thread Mark Lodato via Phabricator via cfe-commits
lodato resigned from this revision.
lodato removed a reviewer: lodato.
lodato added a comment.

I know nothing about the C++ code. I only know the git-clang-format script.


https://reviews.llvm.org/D27377



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-13 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 81260.
madsravn added a comment.

Updated matcher.

Made fixits for some cases

Updated the documentation.


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringCompareCheck.cpp
  clang-tidy/misc/StringCompareCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,82 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template , typename A = std::allocator>
+class basic_string {
+public:
+  basic_string();
+  basic_string(const C *, unsigned int size);
+  int compare(const basic_string ) const;
+  int compare(const C *) const;
+  int compare(int, int, const basic_string ) const;
+  bool empty();
+};
+bool operator==(const basic_string , const basic_string );
+bool operator!=(const basic_string , const basic_string );
+typedef basic_string string;
+}
+
+void func(bool b);
+
+void Test() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+
+  if (str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (!str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (str1.compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == str2) {
+  if (str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 != str2) {
+  if (str1.compare("foo") == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == "foo") {
+  if (0 == str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == str1) {
+  if (0 != str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 != str1) {
+  func(str1.compare(str2));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: do not use 'compare' to test equality of strings;
+  if (str2.empty() || str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:23: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2.empty() || str1 != str2) {
+}
+
+void Valid() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+  if (str1 == str2) {
+  }
+  if (str1 != str2) {
+  }
+  if (str1.compare(str2) == 1) {
+  }
+  if (str1.compare(str2) == str1.compare(str2)) {
+  }
+  if (0 == 0) {
+  }
+  if (1 == str1.compare(str2)) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(1, 3, str2)) {
+  }
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,54 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===
+
+Finds string comparisons using the compare method.
+
+A common mistake is to use the string's ``compare`` method instead of using the 
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns a negative number, a positive number or 
+zero depending on the lexicographical relationship between the strings compared. 
+If an equality or inequality check can suffice, that is recommended. This is 
+recommended to avoid the risk of incorrect interpretation of the return value
+and to simplify the code. The string equality and inequality operators can
+also be faster than the ``compare`` method due to early termination.
+
+Examples:
+
+.. code-block:: c++
+
+  std::string str1{"a"};
+  std::string str2{"b"};
+
+  // use str1 != str2 instead.
+  if (str1.compare(str2)) {
+  }
+
+  // use str1 == str2 instead.
+  if (!str1.compare(str2)) {
+  }
+
+  // use str1 == str2 instead.
+  if (str1.compare(str2) == 0) {
+  }
+
+  // use str1 != str2 instead.
+  if (str1.compare(str2) != 0) {
+  }
+
+  // use str1 == str2 instead.
+  if (0 == str1.compare(str2)) {
+  }
+
+  // use str1 != str2 instead.
+  if (0 != str1.compare(str2)) {
+  }
+
+  // Use str1 == "foo" instead.
+  if (str1.compare("foo") == 0) {
+  }
+
+The above code examples shows the 

[PATCH] D27424: Add the diagnose_if attribute to clang.

2016-12-13 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv updated this revision to Diff 81259.
george.burgess.iv marked an inline comment as done.
george.burgess.iv added a comment.

Addressed alignment comment. Thanks! (Late parsing is still to-be-done)


https://reviews.llvm.org/D27424

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/Sema/diagnose_if.c
  test/SemaCXX/diagnose_if.cpp

Index: test/SemaCXX/diagnose_if.cpp
===
--- /dev/null
+++ test/SemaCXX/diagnose_if.cpp
@@ -0,0 +1,352 @@
+// RUN: %clang_cc1 %s -verify -fno-builtin -std=c++11
+
+#define _diagnose_if(...) __attribute__((diagnose_if(__VA_ARGS__)))
+
+namespace type_dependent {
+template 
+void neverok() _diagnose_if(!T(), "oh no", "error") {} // expected-note 4{{from diagnose_if}}
+
+template 
+void alwaysok() _diagnose_if(T(), "oh no", "error") {}
+
+template 
+void alwayswarn() _diagnose_if(!T(), "oh no", "warning") {} // expected-note 4{{from diagnose_if}}
+
+template 
+void neverwarn() _diagnose_if(T(), "oh no", "warning") {}
+
+void runAll() {
+  alwaysok();
+  alwaysok();
+
+  {
+void (*pok)() = alwaysok;
+pok = ;
+  }
+
+  neverok(); // expected-error{{oh no}}
+  neverok(); // expected-error{{oh no}}
+
+  {
+void (*pok)() = neverok; // expected-error{{oh no}}
+  }
+  {
+void (*pok)();
+pok = ; // expected-error{{oh no}}
+  }
+
+  alwayswarn(); // expected-warning{{oh no}}
+  alwayswarn(); // expected-warning{{oh no}}
+  {
+void (*pok)() = alwayswarn; // expected-warning{{oh no}}
+pok = ; // expected-warning{{oh no}}
+  }
+
+  neverwarn();
+  neverwarn();
+  {
+void (*pok)() = neverwarn;
+pok = ;
+  }
+}
+
+template 
+void errorIf(T a) _diagnose_if(T() != a, "oh no", "error") {} // expected-note {{candidate disabled: oh no}}
+
+template 
+void warnIf(T a) _diagnose_if(T() != a, "oh no", "warning") {} // expected-note {{from diagnose_if}}
+
+void runIf() {
+  errorIf(0);
+  errorIf(1); // expected-error{{call to unavailable function}}
+
+  warnIf(0);
+  warnIf(1); // expected-warning{{oh no}}
+}
+}
+
+namespace value_dependent {
+template 
+void neverok() _diagnose_if(N == 0 || N != 0, "oh no", "error") {} // expected-note 4{{from diagnose_if}}
+
+template 
+void alwaysok() _diagnose_if(N == 0 && N != 0, "oh no", "error") {}
+
+template 
+void alwayswarn() _diagnose_if(N == 0 || N != 0, "oh no", "warning") {} // expected-note 4{{from diagnose_if}}
+
+template 
+void neverwarn() _diagnose_if(N == 0 && N != 0, "oh no", "warning") {}
+
+void runAll() {
+  alwaysok<0>();
+  alwaysok<1>();
+
+  {
+void (*pok)() = alwaysok<0>;
+pok = <0>;
+  }
+
+  neverok<0>(); // expected-error{{oh no}}
+  neverok<1>(); // expected-error{{oh no}}
+
+  {
+void (*pok)() = neverok<0>; // expected-error{{oh no}}
+  }
+  {
+void (*pok)();
+pok = <0>; // expected-error{{oh no}}
+  }
+
+  alwayswarn<0>(); // expected-warning{{oh no}}
+  alwayswarn<1>(); // expected-warning{{oh no}}
+  {
+void (*pok)() = alwayswarn<0>; // expected-warning{{oh no}}
+pok = <0>; // expected-warning{{oh no}}
+  }
+
+  neverwarn<0>();
+  neverwarn<1>();
+  {
+void (*pok)() = neverwarn<0>;
+pok = <0>;
+  }
+}
+
+template 
+void errorIf(int a) _diagnose_if(N != a, "oh no", "error") {} // expected-note {{candidate disabled: oh no}}
+
+template 
+void warnIf(int a) _diagnose_if(N != a, "oh no", "warning") {} // expected-note {{from diagnose_if}}
+
+void runIf() {
+  errorIf<0>(0);
+  errorIf<0>(1); // expected-error{{call to unavailable function}}
+
+  warnIf<0>(0);
+  warnIf<0>(1); // expected-warning{{oh no}}
+}
+}
+
+namespace no_overload_interaction {
+void foo(int) _diagnose_if(1, "oh no", "error"); // expected-note{{from diagnose_if}}
+void foo(short);
+
+void bar(int);
+void bar(short) _diagnose_if(1, "oh no", "error");
+
+void fooArg(int a) _diagnose_if(a, "oh no", "error"); // expected-note{{candidate disabled: oh no}}
+void fooArg(short); // expected-note{{candidate function}}
+
+void barArg(int);
+void barArg(short a) _diagnose_if(a, "oh no", "error");
+
+void runAll() {
+  foo(1); // expected-error{{oh no}}
+  bar(1);
+
+  fooArg(1); // expected-error{{call to unavailable function}}
+  barArg(1);
+
+  auto p = foo; // expected-error{{incompatible initializer of type ''}}
+}
+}
+
+// We have some inline space craziness going on. This is meant to go over that
+// in hopes of hitting some edge cases. At the time of writing, our inline
+// buffer can support 16 DiagnoseIfAttr*s. If a function only has one attr, no
+// allocation is done.
+namespace overloading_multiple_coverage {
+#define _diagnose_thirteen_times \
+  

[PATCH] D26846: __uuidof() and declspec(uuid("...")) should be allowed on enumeration types

2016-12-13 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289567: __uuidof() and declspec(uuid("...")) should be 
allowed on enumeration types (authored by rnk).

Changed prior to commit:
  https://reviews.llvm.org/D26846?vs=78569=81258#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26846

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/AttributeList.h
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaExprCXX.cpp
  cfe/trunk/test/Parser/MicrosoftExtensions.cpp

Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -4666,12 +4666,6 @@
 return;
   }
 
-  if (!isa(D)) {
-S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
-  << Attr.getName() << ExpectedClass;
-return;
-  }
-
   StringRef StrRef;
   SourceLocation LiteralLoc;
   if (!S.checkStringLiteralArgumentAttr(Attr, 0, StrRef, ))
Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -520,17 +520,17 @@
   else if (QT->isArrayType())
 Ty = Ty->getBaseElementTypeUnsafe();
 
-  const auto *RD = Ty->getAsCXXRecordDecl();
-  if (!RD)
+  const auto *TD = Ty->getAsTagDecl();
+  if (!TD)
 return;
 
-  if (const auto *Uuid = RD->getMostRecentDecl()->getAttr()) {
+  if (const auto *Uuid = TD->getMostRecentDecl()->getAttr()) {
 UuidAttrs.insert(Uuid);
 return;
   }
 
   // __uuidof can grab UUIDs from template arguments.
-  if (const auto *CTSD = dyn_cast(RD)) {
+  if (const auto *CTSD = dyn_cast(TD)) {
 const TemplateArgumentList  = CTSD->getTemplateArgs();
 for (const TemplateArgument  : TAL.asArray()) {
   const UuidAttr *UuidForTA = nullptr;
Index: cfe/trunk/include/clang/Sema/AttributeList.h
===
--- cfe/trunk/include/clang/Sema/AttributeList.h
+++ cfe/trunk/include/clang/Sema/AttributeList.h
@@ -925,7 +925,8 @@
   ExpectedVariableEnumFieldOrTypedef,
   ExpectedFunctionMethodEnumOrClass,
   ExpectedStructClassVariableFunctionOrInlineNamespace,
-  ExpectedForMaybeUnused
+  ExpectedForMaybeUnused,
+  ExpectedEnumOrClass,
 };
 
 }  // end namespace clang
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2650,7 +2650,8 @@
   "|variables, enums, fields and typedefs"
   "|functions, methods, enums, and classes"
   "|structs, classes, variables, functions, and inline namespaces"
-  "|variables, functions, methods, types, enumerations, enumerators, labels, and non-static data members}1">,
+  "|variables, functions, methods, types, enumerations, enumerators, labels, and non-static data members"
+  "|classes and enumerations}1">,
   InGroup;
 def err_attribute_wrong_decl_type : Error;
 def warn_type_attribute_wrong_type : Warning<
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -1618,7 +1618,9 @@
 def Uuid : InheritableAttr {
   let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
   let Args = [StringArgument<"Guid">];
-//  let Subjects = SubjectList<[CXXRecord]>;
+  let Subjects = SubjectList<[Record, Enum], WarnDiag, "ExpectedEnumOrClass">;
+  // FIXME: Allow expressing logical AND for LangOpts. Our condition should be:
+  // CPlusPlus && (MicrosoftExt || Borland)
   let LangOpts = [MicrosoftExt, Borland];
   let Documentation = [Undocumented];
 }
Index: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
===
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp
@@ -65,6 +65,12 @@
 struct
 struct_with_uuid2 {} ;
 
+enum __declspec(uuid("00A0---C000-0046"))
+enum_with_uuid { };
+enum enum_without_uuid { };
+
+int __declspec(uuid("00A0---C000-0046")) inappropriate_uuid; // expected-warning {{'uuid' attribute only applies to classes and enumerations}}
+
 int uuid_sema_test()
 {
struct_with_uuid var_with_uuid[1];
@@ -81,6 +87,15 @@
__uuidof(const struct_with_uuid[1][1]);
__uuidof(const struct_with_uuid*[1][1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
 
+   __uuidof(enum_with_uuid);
+   __uuidof(enum_without_uuid); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
+   __uuidof(enum_with_uuid*);
+   __uuidof(enum_without_uuid*); // expected-error {{cannot call operator __uuidof on a type with no 

[PATCH] D26846: __uuidof() and declspec(uuid("...")) should be allowed on enumeration types

2016-12-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

FYI I had to make a few changes so that we still error out on __uuid in C mode.


Repository:
  rL LLVM

https://reviews.llvm.org/D26846



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


r289567 - __uuidof() and declspec(uuid("...")) should be allowed on enumeration types

2016-12-13 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Dec 13 12:58:09 2016
New Revision: 289567

URL: http://llvm.org/viewvc/llvm-project?rev=289567=rev
Log:
__uuidof() and declspec(uuid("...")) should be allowed on enumeration types

Although not specifically mentioned in the documentation, MSVC accepts
__uuidof(…) and declspec(uuid("…")) attributes on enumeration types in
addition to structs/classes. This is meaningful, as such types *do* have
associated UUIDs in ActiveX typelibs, and such attributes are included
by default in the wrappers generated by their #import construct, so they
are not particularly unusual.

clang currently rejects the declspec with a –Wignored-attributes
warning, and errors on __uuidof() with “cannot call operator __uuidof on
a type with no GUID” (because it rejected the uuid attribute, and
therefore finds no value). This is causing problems for us while trying
to use clang-tidy on a codebase that makes heavy use of ActiveX.

I believe I have found the relevant places to add this functionality,
this patch adds this case to clang’s implementation of these MS
extensions.  patch is against r285994 (or actually the git mirror
80464680ce).

Both include an update to test/Parser/MicrosoftExtensions.cpp to
exercise the new functionality.

This is my first time contributing to LLVM, so if I’ve missed anything
else needed to prepare this for review just let me know!

__uuidof: https://msdn.microsoft.com/en-us/library/zaah6a61.aspx
declspec(uuid("…")): https://msdn.microsoft.com/en-us/library/3b6wkewa.aspx
 #import: https://msdn.microsoft.com/en-us/library/8etzzkb6.aspx

Reviewers: aaron.ballman, majnemer, rnk

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

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=289567=289566=289567=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Dec 13 12:58:09 2016
@@ -1618,7 +1618,9 @@ def Used : InheritableAttr {
 def Uuid : InheritableAttr {
   let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
   let Args = [StringArgument<"Guid">];
-//  let Subjects = SubjectList<[CXXRecord]>;
+  let Subjects = SubjectList<[Record, Enum], WarnDiag, "ExpectedEnumOrClass">;
+  // FIXME: Allow expressing logical AND for LangOpts. Our condition should be:
+  // CPlusPlus && (MicrosoftExt || Borland)
   let LangOpts = [MicrosoftExt, Borland];
   let Documentation = [Undocumented];
 }

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=289567=289566=289567=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 13 12:58:09 
2016
@@ -2650,7 +2650,8 @@ def warn_attribute_wrong_decl_type : War
   "|variables, enums, fields and typedefs"
   "|functions, methods, enums, and classes"
   "|structs, classes, variables, functions, and inline namespaces"
-  "|variables, functions, methods, types, enumerations, enumerators, labels, 
and non-static data members}1">,
+  "|variables, functions, methods, types, enumerations, enumerators, labels, 
and non-static data members"
+  "|classes and enumerations}1">,
   InGroup;
 def err_attribute_wrong_decl_type : Error;
 def warn_type_attribute_wrong_type : Warning<

Modified: cfe/trunk/include/clang/Sema/AttributeList.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=289567=289566=289567=diff
==
--- cfe/trunk/include/clang/Sema/AttributeList.h (original)
+++ cfe/trunk/include/clang/Sema/AttributeList.h Tue Dec 13 12:58:09 2016
@@ -925,7 +925,8 @@ enum AttributeDeclKind {
   ExpectedVariableEnumFieldOrTypedef,
   ExpectedFunctionMethodEnumOrClass,
   ExpectedStructClassVariableFunctionOrInlineNamespace,
-  ExpectedForMaybeUnused
+  ExpectedForMaybeUnused,
+  ExpectedEnumOrClass,
 };
 
 }  // end namespace clang

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=289567=289566=289567=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Dec 13 12:58:09 2016
@@ -4666,12 +4666,6 @@ static void handleUuidAttr(Sema , Decl
 return;
   }
 
-  if (!isa(D)) {
-S.Diag(Attr.getLoc(), 

[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-13 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: docs/clang-tidy/checks/misc-string-compare.rst:12
+zero depending on the lexicographical relationship between the strings 
compared. 
+If an equality or inequality check can suffice, that is recommended.
+

alexfh wrote:
> The documentation doesn't explain why is using `compare` for equality 
> comparison should be avoided. Maybe `that is recommended to avoid the risk of 
> incorrect interpretation of the return value and simplify the code`?
Also, a string equality check can be faster than compare as it can exit early 
when the strings aren't the same length.


https://reviews.llvm.org/D27210



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


[PATCH] D27655: Fix modernize-deprecated-headers clang-tidy warnings

2016-12-13 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Yes, IWYU is useful tool, but please note that it's not ideal, so will be good 
idea to check proposed changes manually.

You could build IWYU in-tree with Clang or Clang extra tools.


https://reviews.llvm.org/D27655



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


[PATCH] D27717: [analyzer] Suppress a leak false positive in Qt's QObject::connectImpl()

2016-12-13 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin accepted this revision.
a.sidorin added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!




Comment at: lib/StaticAnalyzer/Checkers/MallocChecker.cpp:2577
 
   if (FName == "postEvent" &&
   FD->getQualifiedNameAsString() == "QCoreApplication::postEvent") {

Sorry for disturbing you for code which is not yours but this line looks 
exactly like the line upper and seems to be a dead/useless code.


https://reviews.llvm.org/D27717



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


r289554 - [analyzer] Detect ObjC properties that are both (copy) and Mutable.

2016-12-13 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Tue Dec 13 11:19:18 2016
New Revision: 289554

URL: http://llvm.org/viewvc/llvm-project?rev=289554=rev
Log:
[analyzer] Detect ObjC properties that are both (copy) and Mutable.

When an Objective-C property has a (copy) attribute, the default setter
for this property performs a -copy on the object assigned.

Calling -copy on a mutable NS object such as NSMutableString etc.
produces an immutable object, NSString in our example.
Hence the getter becomes type-incorrect.

rdar://problem/21022397

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

Added:
cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp
cfe/trunk/test/Analysis/ObjCPropertiesSyntaxChecks.m
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=289554=289553=289554=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Tue Dec 13 
11:19:18 2016
@@ -480,20 +480,21 @@ def CStringNotNullTerm : Checker<"NotNul
 let ParentPackage = OSX in {
 
 def NumberObjectConversionChecker : Checker<"NumberObjectConversion">,
-  InPackage,
   HelpText<"Check for erroneous conversions of objects representing numbers 
into numbers">,
   DescFile<"NumberObjectConversionChecker.cpp">;
 
 def MacOSXAPIChecker : Checker<"API">,
-  InPackage,
   HelpText<"Check for proper uses of various Apple APIs">,
   DescFile<"MacOSXAPIChecker.cpp">;
 
 def MacOSKeychainAPIChecker : Checker<"SecKeychainAPI">,
-  InPackage,
   HelpText<"Check for proper uses of Secure Keychain APIs">,
   DescFile<"MacOSKeychainAPIChecker.cpp">;
 
+def ObjCPropertyChecker : Checker<"ObjCProperty">,
+  HelpText<"Check for proper uses of Objective-C properties">,
+  DescFile<"ObjCPropertyChecker.cpp">;
+
 } // end "osx"
 
 let ParentPackage = Cocoa in {

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=289554=289553=289554=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Tue Dec 13 11:19:18 
2016
@@ -59,6 +59,7 @@ add_clang_library(clangStaticAnalyzerChe
   ObjCContainersASTChecker.cpp
   ObjCContainersChecker.cpp
   ObjCMissingSuperCallChecker.cpp
+  ObjCPropertyChecker.cpp
   ObjCSelfInitChecker.cpp
   ObjCSuperDeallocChecker.cpp
   ObjCUnusedIVarsChecker.cpp

Added: cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp?rev=289554=auto
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp (added)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp Tue Dec 13 
11:19:18 2016
@@ -0,0 +1,82 @@
+//==- ObjCPropertyChecker.cpp - Check ObjC properties *- C++ 
-*-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This checker finds issues with Objective-C properties.
+//  Currently finds only one kind of issue:
+//  - Find synthesized properties with copy attribute of mutable NS collection
+//types. Calling -copy on such collections produces an immutable copy,
+//which contradicts the type of the property.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class ObjCPropertyChecker
+: public Checker {
+  void checkCopyMutable(const ObjCPropertyDecl *D, BugReporter ) const;
+
+public:
+  void checkASTDecl(const ObjCPropertyDecl *D, AnalysisManager ,
+BugReporter ) const;
+};
+} // end anonymous namespace.
+
+void ObjCPropertyChecker::checkASTDecl(const ObjCPropertyDecl *D,
+   AnalysisManager ,
+   BugReporter ) const {
+  checkCopyMutable(D, BR);
+}
+
+void ObjCPropertyChecker::checkCopyMutable(const ObjCPropertyDecl *D,
+   BugReporter ) const {
+  if (D->isReadOnly() || D->getSetterKind() != ObjCPropertyDecl::Copy)
+return;
+
+  

[PATCH] D27717: [analyzer] Suppress a leak false positive in Qt's QObject::connectImpl()

2016-12-13 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: zaks.anna, dcoughlin, xazax.hun, a.sidorin.
NoQ added a subscriber: cfe-commits.

A quick fix to address the false positive posted by Tiago Macarios in the 
mailing lists: http://lists.llvm.org/pipermail/cfe-dev/2016-December/051738.html

MallocChecker processes pointer escapes heuristically rather than regularly. 
Force it to treat the pointers passed to `connectImpl()` as escaping.

I dislike a few things about this patch - we're patching against implementation 
details and hardcoding names of private methods in an external library. I don't 
see a significantly better solution within the current approach though.

See also https://reviews.llvm.org/D27599 - a similar hack for another function.


https://reviews.llvm.org/D27717

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  test/Analysis/Inputs/qt-simulator.h
  test/Analysis/qt_malloc.cpp


Index: test/Analysis/qt_malloc.cpp
===
--- test/Analysis/qt_malloc.cpp
+++ test/Analysis/qt_malloc.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus
 -analyzer-store=region -verify %s
+// RUN: %clang_cc1 -std=c++11 -analyze 
-analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus
 -analyzer-store=region -verify %s
 // expected-no-diagnostics
 #include "Inputs/qt-simulator.h"
 
@@ -13,3 +13,9 @@
   QEvent *e4 = new QEvent(QEvent::None);
   QApplication::postEvent(obj, e4);
 }
+
+void connect(QObject *obj) {
+  obj->connectImpl(nullptr, nullptr, nullptr, nullptr,
+   new QtPrivate::QSlotObjectBase(), (Qt::ConnectionType)0,
+   nullptr, nullptr);
+}
Index: test/Analysis/Inputs/qt-simulator.h
===
--- test/Analysis/Inputs/qt-simulator.h
+++ test/Analysis/Inputs/qt-simulator.h
@@ -1,6 +1,23 @@
 #pragma clang system_header
 
+namespace QtPrivate {
+struct QSlotObjectBase {};
+}
+
+namespace Qt {
+enum ConnectionType {};
+}
+
+struct QMetaObject {
+  struct Connection {};
+};
+
 struct QObject {
+  static QMetaObject::Connection connectImpl(const QObject *, void **,
+ const QObject *, void **,
+ QtPrivate::QSlotObjectBase *,
+ Qt::ConnectionType,
+ const int *, const QMetaObject *);
 };
 
 struct QEvent {
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2579,6 +2579,11 @@
 return true;
   }
 
+  if (FName == "connectImpl" &&
+  FD->getQualifiedNameAsString() == "QObject::connectImpl") {
+return true;
+  }
+
   // Handle cases where we know a buffer's /address/ can escape.
   // Note that the above checks handle some special cases where we know that
   // even though the address escapes, it's still our responsibility to free the


Index: test/Analysis/qt_malloc.cpp
===
--- test/Analysis/qt_malloc.cpp
+++ test/Analysis/qt_malloc.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus -analyzer-store=region -verify %s
+// RUN: %clang_cc1 -std=c++11 -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus -analyzer-store=region -verify %s
 // expected-no-diagnostics
 #include "Inputs/qt-simulator.h"
 
@@ -13,3 +13,9 @@
   QEvent *e4 = new QEvent(QEvent::None);
   QApplication::postEvent(obj, e4);
 }
+
+void connect(QObject *obj) {
+  obj->connectImpl(nullptr, nullptr, nullptr, nullptr,
+   new QtPrivate::QSlotObjectBase(), (Qt::ConnectionType)0,
+   nullptr, nullptr);
+}
Index: test/Analysis/Inputs/qt-simulator.h
===
--- test/Analysis/Inputs/qt-simulator.h
+++ test/Analysis/Inputs/qt-simulator.h
@@ -1,6 +1,23 @@
 #pragma clang system_header
 
+namespace QtPrivate {
+struct QSlotObjectBase {};
+}
+
+namespace Qt {
+enum ConnectionType {};
+}
+
+struct QMetaObject {
+  struct Connection {};
+};
+
 struct QObject {
+  static QMetaObject::Connection connectImpl(const QObject *, void **,
+ const QObject *, void **,
+ QtPrivate::QSlotObjectBase *,
+ Qt::ConnectionType,
+ const int *, const QMetaObject *);
 };
 
 struct QEvent {
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp

r289553 - Update for clang after llvm::StringLiteral.

2016-12-13 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Tue Dec 13 11:10:16 2016
New Revision: 289553

URL: http://llvm.org/viewvc/llvm-project?rev=289553=rev
Log:
Update for clang after llvm::StringLiteral.

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

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=289553=289552=289553=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Dec 13 11:10:16 2016
@@ -4189,7 +4189,7 @@ static Value *EmitSpecialRegisterBuiltin
 
   if (SysReg.empty()) {
 const Expr *SysRegStrExpr = E->getArg(0)->IgnoreParenCasts();
-SysReg = cast(SysRegStrExpr)->getString();
+SysReg = cast(SysRegStrExpr)->getString();
   }
 
   llvm::Metadata *Ops[] = { llvm::MDString::get(Context, SysReg) };


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


r289552 - Fixing build failure by adding triple option to new test condition.

2016-12-13 Thread Neil Hickey via cfe-commits
Author: neil.hickey
Date: Tue Dec 13 11:04:33 2016
New Revision: 289552

URL: http://llvm.org/viewvc/llvm-project?rev=289552=rev
Log:
Fixing build failure by adding triple option to new test condition.

Adding -triple option to ensure target supports double for fpmath test.


Modified:
cfe/trunk/test/CodeGenOpenCL/fpmath.cl

Modified: cfe/trunk/test/CodeGenOpenCL/fpmath.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/fpmath.cl?rev=289552=289551=289552=diff
==
--- cfe/trunk/test/CodeGenOpenCL/fpmath.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/fpmath.cl Tue Dec 13 11:04:33 2016
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck 
--check-prefix=CHECK --check-prefix=NODIVOPT %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown 
-cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK 
--check-prefix=DIVOPT %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.2 -triple 
r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck 
--check-prefix=CHECK-FLT %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -DFP64 -cl-std=CL1.2 -pedantic | 
FileCheck --check-prefix=CHECK-DBL %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -DFP64 -cl-std=CL1.2 -triple 
spir-unknown-unknown -pedantic | FileCheck --check-prefix=CHECK-DBL %s
 
 typedef __attribute__(( ext_vector_type(4) )) float float4;
 


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


[PATCH] D26167: [Clang-tidy] check for malloc, realloc and free calls

2016-12-13 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Committed in r289546.


Repository:
  rL LLVM

https://reviews.llvm.org/D26167



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


[clang-tools-extra] r289549 - Fix sphinx build.

2016-12-13 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Dec 13 10:49:10 2016
New Revision: 289549

URL: http://llvm.org/viewvc/llvm-project?rev=289549=rev
Log:
Fix sphinx build.

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-no-malloc.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-no-malloc.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-no-malloc.rst?rev=289549=289548=289549=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-no-malloc.rst 
(original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-no-malloc.rst 
Tue Dec 13 10:49:10 2016
@@ -7,7 +7,7 @@ This check handles C-Style memory manage
 ``calloc()`` and ``free()``. It warns about its use and tries to suggest the 
use
 of an appropriate RAII object.
 See `C++ Core Guidelines
-
+`.
 
 There is no attempt made to provide fixit hints, since manual resource 
management isn't
 easily transformed automatically into RAII.


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


[PATCH] D21698: [OpenCL] Allow disabling types and declarations associated with extensions

2016-12-13 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: include/clang/Sema/Sema.h:8081
+  /// \brief Set current OpenCL extensions for a type which can only be used
+  /// when these OpenCL extensions are enabled. If current OpenCL Extsion is
+  /// empty, do nothing.

Extsion -> extension



Comment at: include/clang/Sema/Sema.h:8120
 
+  /// Checks if a type or declaration is disabled due to the owning extension
+  /// is disabled, and emits diagnostic messages if it is disabled.

or declaration -> or a declaration



Comment at: include/clang/Sema/Sema.h:8121
+  /// Checks if a type or declaration is disabled due to the owning extension
+  /// is disabled, and emits diagnostic messages if it is disabled.
+  /// \param D type or declaration to be checked.

is disabled -> being disabled



Comment at: lib/Serialization/ASTReader.cpp:3167
 case OPENCL_EXTENSIONS:
-  // Later tables overwrite earlier ones.
-  OpenCLExtensions.swap(Record);

Btw, OpenCLTypeExtMap and OpenCLTypeDeclMap don't have to be serialized?



Comment at: test/Parser/opencl-atomics-cl20.cl:51
 // expected-error@-28 {{use of type 'atomic_double' (aka '_Atomic(double)') 
requires cl_khr_int64_extended_atomics extension to be enabled}}
-// expected-error-re@-27 {{use of type 'atomic_intptr_t' (aka 
'_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}}
-// expected-error-re@-28 {{use of type 'atomic_intptr_t' (aka 
'_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be 
enabled}}
-// expected-error-re@-28 {{use of type 'atomic_uintptr_t' (aka 
'_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}}
-// expected-error-re@-29 {{use of type 'atomic_uintptr_t' (aka 
'_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be 
enabled}}
-// expected-error-re@-29 {{use of type 'atomic_size_t' (aka '_Atomic({{.+}})') 
requires cl_khr_int64_base_atomics extension to be enabled}}
-// expected-error-re@-30 {{use of type 'atomic_size_t' (aka '_Atomic({{.+}})') 
requires cl_khr_int64_extended_atomics extension to be enabled}}
-// expected-error-re@-30 {{use of type 'atomic_ptrdiff_t' (aka 
'_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}}
-// expected-error-re@-31 {{use of type 'atomic_ptrdiff_t' (aka 
'_Atomic({{.+}})') requires cl_khr_int64_extended_atomics extension to be 
enabled}}
+#if __LP64__
+// expected-error-re@-28 {{use of type 'atomic_intptr_t' (aka 
'_Atomic({{.+}})') requires cl_khr_int64_base_atomics extension to be enabled}}

yaxunl wrote:
> Anastasia wrote:
> > Why this change?
> atomic_intptr_t etc. requires cl_khr_int64_extended_atomics only on 64 bit 
> platforms.
> 
> This is a bug which was fixed by this patch.
The spec says:
"If the device address space is 64-bits, the data types atomic_intptr_t, 
atomic_uintptr_t,
atomic_size_t and atomic_ptrdiff_t are supported if the 
cl_khr_int64_base_atomics and
cl_khr_int64_extended_atomics extensions are supported."

This seems to be the same as long and double?


https://reviews.llvm.org/D21698



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


[PATCH] D26750: [clang-tidy] Add modernize-use-default-member-init check

2016-12-13 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons planned changes to this revision.
malcolm.parsons added inline comments.



Comment at: clang-tidy/modernize/UseDefaultMemberInitCheck.cpp:21
+
+static StringRef getValueInit(const CXXCtorInitializer *Init) {
+  switch (Init->getInit()->getType()->getScalarTypeKind()) {

alexfh wrote:
> The function name doesn't make it clear that the value is returned for 
> zero-initialization.
`getValueOfValueInit`?


https://reviews.llvm.org/D26750



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


[clang-tools-extra] r289547 - Remove trailing whitespace in docs and clang-tidy sources.

2016-12-13 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Dec 13 10:38:45 2016
New Revision: 289547

URL: http://llvm.org/viewvc/llvm-project?rev=289547=rev
Log:
Remove trailing whitespace in docs and clang-tidy sources.

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/trunk/docs/ModularizeUsage.rst
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err34-c.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-no-malloc.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-sizeof-expression.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-pass-by-value.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-transparent-functors.rst
clang-tools-extra/trunk/docs/clang-tidy/index.rst
clang-tools-extra/trunk/test/clang-tidy/boost-use-to-string.cpp

clang-tools-extra/trunk/test/clang-tidy/misc-forward-declaration-namespace.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-sizeof-expression.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-string-constructor.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-swapped-arguments.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-shrink-to-fit.cpp

clang-tools-extra/trunk/test/clang-tidy/modernize-use-transparent-functors.cpp
clang-tools-extra/trunk/test/clang-tidy/static-analyzer-config.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=289547=289546=289547=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Tue Dec 
13 10:38:45 2016
@@ -14,7 +14,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
-#include "clang/Lex/Lexer.h" 
+#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=289547=289546=289547=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Tue Dec 
13 10:38:45 2016
@@ -14,7 +14,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TokenKinds.h"
-#include "clang/Lex/Lexer.h" 
+#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/StringRef.h"

Modified: clang-tools-extra/trunk/docs/ModularizeUsage.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ModularizeUsage.rst?rev=289547=289546=289547=diff
==
--- clang-tools-extra/trunk/docs/ModularizeUsage.rst (original)
+++ clang-tools-extra/trunk/docs/ModularizeUsage.rst Tue Dec 13 10:38:45 2016
@@ -59,7 +59,7 @@ Modularize Command Line Options
 
   Generate a module map and output it to the given file. See the description
   in :ref:`module-map-generation`.
-  
+
 .. option:: -problem-files-list=
 
   For use only with module map assistant. Input list of files that

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=289547=289546=289547=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Dec 13 10:38:45 2016
@@ -81,7 +81,7 @@ Improvements to clang-tidy
   Warns if an object is used after it has been moved, without an intervening
   reinitialization.
 
-- New `cppcoreguidelines-no-malloc 
+- New `cppcoreguidelines-no-malloc
   
`_
 check
   warns if C-style memory management is used and suggests the use of RAII.
 

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err34-c.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err34-c.rst?rev=289547=289546=289547=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err34-c.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err34-c.rst 

[clang-tools-extra] r289546 - [Clang-tidy] check for malloc, realloc and free calls

2016-12-13 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Dec 13 10:38:18 2016
New Revision: 289546

URL: http://llvm.org/viewvc/llvm-project?rev=289546=rev
Log:
[Clang-tidy] check for malloc, realloc and free calls

Summary:
This checker flags the use of C-style memory management functionality and notes 
about modern alternatives.
In an earlier revision it tried to autofix some kind of patterns, but that was 
a bad idea. Since memory management can be so widespread in a program, manual 
updating is most likely necessary.
Maybe for special cases, there could be later additions to this basic checker.

This is the first checker I wrote and I never did something with clang (only 
compiling programs). So whenever I missed conventions or did plain retarded 
stuff, feel free to point it out! I am willing to fix them and write a better 
checker.

I hope the patch does work, I never did this either. On a testapply in my 
repository it did, but I am pretty unconfident in my patching skills :)

Reviewers: aaron.ballman, hokein, alexfh, malcolm.parsons

Subscribers: cfe-commits, JDevlieghere, nemanjai, Eugene.Zelenko, Prazek, 
mgorny, modocache

Tags: #clang-tools-extra

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

Patch by Jonas Toth!

Added:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-no-malloc.rst
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-no-malloc.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt?rev=289546=289545=289546=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt Tue Dec 
13 10:38:18 2016
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
 add_clang_library(clangTidyCppCoreGuidelinesModule
   CppCoreGuidelinesTidyModule.cpp
   InterfacesGlobalInitCheck.cpp
+  NoMallocCheck.cpp
   ProBoundsArrayToPointerDecayCheck.cpp
   ProBoundsConstantArrayIndexCheck.cpp
   ProBoundsPointerArithmeticCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=289546=289545=289546=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Tue Dec 13 10:38:18 2016
@@ -12,6 +12,7 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "InterfacesGlobalInitCheck.h"
+#include "NoMallocCheck.h"
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsConstantArrayIndexCheck.h"
 #include "ProBoundsPointerArithmeticCheck.h"
@@ -35,6 +36,7 @@ public:
   void addCheckFactories(ClangTidyCheckFactories ) override {
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
+CheckFactories.registerCheck("cppcoreguidelines-no-malloc");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
 CheckFactories.registerCheck(

Added: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp?rev=289546=auto
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/NoMallocCheck.cpp Tue 
Dec 13 10:38:18 2016
@@ -0,0 +1,62 @@
+//===--- NoMallocCheck.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "NoMallocCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+void 

[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

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

LG modulo comment.




Comment at: clang-tidy/utils/DeclRefExprUtils.cpp:127
+  match(findAll(declRefExpr(equalsNode(),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),

flx wrote:
> alexfh wrote:
> > flx wrote:
> > > alexfh wrote:
> > > > How will this work with lambdas / local classes declared inside a loop? 
> > > > Not sure if this case is going to happen in real code, but we'd better 
> > > > be clear about the limitations of the implementation.
> > > Why would this not work? Could you give an example? The way the function 
> > > is written it handles my the use case for identifying when moving the 
> > > parameter is not safe, so I could also just move it into the 
> > > UnnecessaryValueParamCheck.
> > I was thinking about a case where a loop this matcher finds is outside of 
> > the function definition and shouldn't be considered:
> > 
> >   void F() {
> > for (;;) {
> >   struct C {
> > void f(ExpensiveMovableType E) {
> >   auto F = E;
> > }
> >   };
> > }
> >   }
> > 
> This case is not an issue in the check as we're passing f's body statement to 
> the hasLoopStmtAncestor function, so the search is scoped to f's body.
> 
> If you're concerned about the case where someone calls this with  F's body 
> but expects it to be scoped to f I can just move this function into the check 
> and make it an implementation detail.
Making it an implementation detail until other potential users appear sounds 
good.


https://reviews.llvm.org/D27187



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


RE: r286815 - Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64.

2016-12-13 Thread Neil Hickey via cfe-commits
I looked into this, and for C, clang converts the literal to inf in the first 
case.
OpenCL spec doesn't mention anything different so I presume the behaviour 
should match Cs behaviour, which is does with this change.

More exhaustive tests could be implemented to ensure this though.

Neil

> -Original Message-
> From: sca...@apple.com [mailto:sca...@apple.com]
> Sent: 15 November 2016 13:20
> To: Neil Hickey
> Cc: cfe-commits@lists.llvm.org; nd
> Subject: Re: r286815 - Improve handling of floating point literals in OpenCL 
> to
> only use double precision if the target supports fp64.
> 
> The reason these commits bring it up is that I don’t see it clearly documented
> whether:
> 
>   float x = 340282356779733661637539395458142568447.0;
> 
> is interpreted as
> 
>   float x = 340282356779733661637539395458142568447.0f; // x is
> FLT_MAX
> 
> or as
> 
>   float x = (float)(340282356779733661637539395458142568447.0); // x
> is INFINITY
> 
> when the no-fp64 mode is active.  I assume that only one of these is the
> correct behavior, and we should have a regression test that will flag the 
> error
> if it changes.
> 
> – Steve
> 
> > On Nov 15, 2016, at 4:51 AM, Neil Hickey  wrote:
> >
> > It would be valuable to perform that test, if clang tests don't already do
> this, though I'm not sure it should be part of this particular commit as all 
> this
> commit should do is change the casts if the target doesn't support double.
> >
> > Neil
> >
> >> -Original Message-
> >> From: sca...@apple.com [mailto:sca...@apple.com]
> >> Sent: 14 November 2016 16:01
> >> To: Neil Hickey
> >> Cc: cfe-commits@lists.llvm.org
> >> Subject: Re: r286815 - Improve handling of floating point literals in
> >> OpenCL to only use double precision if the target supports fp64.
> >>
> >> Can you add some non-trivial test cases that exercise
> >> double-rounding, especially near the overflow boundary?
> >>
> >> e.g. What is the expected value of x if the target does not support fp64?:
> >>
> >>float x = 340282356779733661637539395458142568447.0;
> >>
> >> – Steve
> >>
> >>> On Nov 14, 2016, at 6:15 AM, Neil Hickey via cfe-commits  >> comm...@lists.llvm.org> wrote:
> >>>
> >>> Author: neil.hickey
> >>> Date: Mon Nov 14 05:15:51 2016
> >>> New Revision: 286815
> >>>
> >>> URL: http://llvm.org/viewvc/llvm-project?rev=286815=rev
> >>> Log:
> >>> Improve handling of floating point literals in OpenCL to only use
> >>> double
> >> precision if the target supports fp64.
> >>>
> >>> This change makes sure single-precision floating point types are
> >>> used if the
> >>> cl_fp64 extension is not supported by the target.
> >>>
> >>> Also removed the check to see whether the OpenCL version is >= 1.2,
> >>> as this has been incorporated into the extension setting code.
> >>>
> >>> Differential Revision: https://reviews.llvm.org/D24235
> >>>
> >>>
> >>> Modified:
> >>>  cfe/trunk/lib/Sema/SemaExpr.cpp
> >>>  cfe/trunk/lib/Sema/SemaType.cpp
> >>>  cfe/trunk/test/CodeGenOpenCL/fpmath.cl
> >>>  cfe/trunk/test/SemaOpenCL/extensions.cl
> >>>
> >>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> >>> URL:
> >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?
> >>> re v=286815=286814=286815=diff
> >>>
> >>
> ==
> >> 
> >>> 
> >>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> >>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Nov 14 05:15:51 2016
> >>> @@ -705,9 +705,13 @@ ExprResult Sema::DefaultLvalueConversion  if
> >>> (getLangOpts().ObjCAutoRefCount &&
> >>> E->getType().getObjCLifetime() == Qualifiers::OCL_Weak)
> >>>   Cleanup.setExprNeedsCleanups(true);
> >>> +
> >>> +  ExprResult Res = E;
> >>>
> >>> -  ExprResult Res = ImplicitCastExpr::Create(Context, T,
> >> CK_LValueToRValue, E,
> >>> -nullptr, VK_RValue);
> >>> +  if ( T != E->getType()) {
> >>> +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E,
> >>> +   nullptr, VK_RValue);  }
> >>>
> >>> // C11 6.3.2.1p2:
> >>> //   ... if the lvalue has atomic type, the value has the non-atomic 
> >>> version
> >>> @@ -817,8 +821,16 @@ ExprResult Sema::DefaultArgumentPromotio  //
> >>> double.
> >>> const BuiltinType *BTy = Ty->getAs();  if (BTy &&
> >>> (BTy->getKind() == BuiltinType::Half ||
> >>> -  BTy->getKind() == BuiltinType::Float))
> >>> -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get();
> >>> +  BTy->getKind() == BuiltinType::Float)) {
> >>> +if (getLangOpts().OpenCL &&
> >>> +!(getOpenCLOptions().cl_khr_fp64)) {
> >>> +if (BTy->getKind() == BuiltinType::Half) {
> >>> +E = ImpCastExprToType(E, Context.FloatTy,
> CK_FloatingCast).get();
> >>> +}
> >>> +} else {
> >>> +  E = ImpCastExprToType(E, Context.DoubleTy,
> CK_FloatingCast).get();
> >>> +}
> >>> +  }
> >>>
> >>> 

[PATCH] D27424: Add the diagnose_if attribute to clang.

2016-12-13 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: include/clang/Sema/Overload.h:754
+unsigned NumInlineBytesUsed;
+llvm::AlignedCharArray
 InlineSpace;

I guess you could use "void *" instead of ImplicitConversionSequence for the 
alignment to make it clear that this has the alignment of a pointer type (or 
the larger of alignof(ImplicitConversionSequence) and alignof(DiagnoseIfAttr 
*))?


https://reviews.llvm.org/D27424



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


[PATCH] D26167: [Clang-tidy] check for malloc, realloc and free calls

2016-12-13 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In https://reviews.llvm.org/D26167#621106, @alexfh wrote:

> Jonas, do you need someone to commit the patch for you?


i think so, yes. can i trigger somehow automatically, that this will go into 
the code base somehow?


Repository:
  rL LLVM

https://reviews.llvm.org/D26167



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


[PATCH] D24235: [OpenCL] Improve floating point literal handling

2016-12-13 Thread Neil Hickey via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289544: Improve handling of floating point literals in 
OpenCL to only use double… (authored by neil.hickey).

Changed prior to commit:
  https://reviews.llvm.org/D24235?vs=77975=81235#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24235

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/CodeGenOpenCL/fpmath.cl
  cfe/trunk/test/SemaOpenCL/extensions.cl

Index: cfe/trunk/test/CodeGenOpenCL/fpmath.cl
===
--- cfe/trunk/test/CodeGenOpenCL/fpmath.cl
+++ cfe/trunk/test/CodeGenOpenCL/fpmath.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.2 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-FLT %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -DFP64 -cl-std=CL1.2 -pedantic | FileCheck --check-prefix=CHECK-DBL %s
 
 typedef __attribute__(( ext_vector_type(4) )) float float4;
 
@@ -21,14 +23,26 @@
   return a / b;
 }
 
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#if __OPENCL_C_VERSION__ >=120
+void printf(constant char* fmt, ...);
+
+void testdbllit(long *val) {
+  // CHECK-FLT: float 2.00e+01
+  // CHECK-DBL: double 2.00e+01
+  printf("%f", 20.0);
+}
 
+#endif
+
+#ifndef NOFP64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 double dpscalardiv(double a, double b) {
   // CHECK: @dpscalardiv
   // CHECK: #[[ATTR]]
   // CHECK-NOT: !fpmath
   return a / b;
 }
+#endif
 
 // CHECK: attributes #[[ATTR]] = {
 // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false"
Index: cfe/trunk/test/SemaOpenCL/extensions.cl
===
--- cfe/trunk/test/SemaOpenCL/extensions.cl
+++ cfe/trunk/test/SemaOpenCL/extensions.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64
 
 // Test with a target not supporting fp64.
 // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16
@@ -23,10 +24,16 @@
 
 
 
+#ifdef FP64
+// expected-no-diagnostics
+#endif
+
+#if __OPENCL_C_VERSION__ < 120
 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
   (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
 }
+#endif
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
 #ifdef NOFP64
@@ -45,16 +52,19 @@
 #endif
 
   (void) 1.0;
+
 #ifdef NOFP64
-// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}}
+// expected-warning@-3{{double precision constant requires cl_khr_fp64, casting to single precision}}
 #endif
 }
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : disable
 #ifdef NOFP64
 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}}
 #endif
 
+#if __OPENCL_C_VERSION__ < 120
 void f3(void) {
   double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
 }
+#endif
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -817,8 +817,16 @@
   // double.
   const BuiltinType *BTy = Ty->getAs();
   if (BTy && (BTy->getKind() == BuiltinType::Half ||
-  BTy->getKind() == BuiltinType::Float))
-E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get();
+  BTy->getKind() == BuiltinType::Float)) {
+if (getLangOpts().OpenCL &&
+!(getOpenCLOptions().cl_khr_fp64)) {
+if (BTy->getKind() == BuiltinType::Half) {
+E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get();
+}
+} else {
+  E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get();
+}
+  }
 
   // C++ performs lvalue-to-rvalue conversion as a default argument
   // promotion, even on class types, but note:
@@ -3397,10 +3405,13 @@
 
 if (Ty == Context.DoubleTy) {
   if (getLangOpts().SinglePrecisionConstants) {
-Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
+const BuiltinType *BTy = Ty->getAs();
+if (BTy->getKind() != BuiltinType::Float) {
+  Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
+}
   } 

[PATCH] D26167: [Clang-tidy] check for malloc, realloc and free calls

2016-12-13 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

tbh. i dont know anything how the clang workflow works :)

do i need to ask someone to commit, or what be my next step?


Repository:
  rL LLVM

https://reviews.llvm.org/D26167



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


r289544 - Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64.

2016-12-13 Thread Neil Hickey via cfe-commits
Author: neil.hickey
Date: Tue Dec 13 10:22:50 2016
New Revision: 289544

URL: http://llvm.org/viewvc/llvm-project?rev=289544=rev
Log:
Improve handling of floating point literals in OpenCL to only use double 
precision if the target supports fp64.

This change makes sure single-precision floating point types are used if the 
cl_fp64 extension is not supported by the target.

Also removed the check to see whether the OpenCL version is >= 1.2, as this has
been incorporated into the extension setting code.

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


Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CodeGenOpenCL/fpmath.cl
cfe/trunk/test/SemaOpenCL/extensions.cl

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=289544=289543=289544=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec 13 10:22:50 2016
@@ -3748,12 +3748,13 @@ bool Sema::SemaBuiltinFPClassification(C
 diag::err_typecheck_call_invalid_unary_fp)
   << OrigArg->getType() << OrigArg->getSourceRange();
 
-  // If this is an implicit conversion from float -> double, remove it.
+  // If this is an implicit conversion from float -> float or double, remove 
it.
   if (ImplicitCastExpr *Cast = dyn_cast(OrigArg)) {
 Expr *CastArg = Cast->getSubExpr();
 if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) {
-  assert(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) &&
- "promotion from float to double is the only expected cast here");
+assert((Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) ||
+Cast->getType()->isSpecificBuiltinType(BuiltinType::Float)) &&
+ "promotion from float to either float or double is the only 
expected cast here");
   Cast->setSubExpr(nullptr);
   TheCall->setArg(NumArgs-1, CastArg);
 }

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=289544=289543=289544=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Dec 13 10:22:50 2016
@@ -817,8 +817,16 @@ ExprResult Sema::DefaultArgumentPromotio
   // double.
   const BuiltinType *BTy = Ty->getAs();
   if (BTy && (BTy->getKind() == BuiltinType::Half ||
-  BTy->getKind() == BuiltinType::Float))
-E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get();
+  BTy->getKind() == BuiltinType::Float)) {
+if (getLangOpts().OpenCL &&
+!(getOpenCLOptions().cl_khr_fp64)) {
+if (BTy->getKind() == BuiltinType::Half) {
+E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get();
+}
+} else {
+  E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get();
+}
+  }
 
   // C++ performs lvalue-to-rvalue conversion as a default argument
   // promotion, even on class types, but note:
@@ -3397,10 +3405,13 @@ ExprResult Sema::ActOnNumericConstant(co
 
 if (Ty == Context.DoubleTy) {
   if (getLangOpts().SinglePrecisionConstants) {
-Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
+const BuiltinType *BTy = Ty->getAs();
+if (BTy->getKind() != BuiltinType::Float) {
+  Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
+}
   } else if (getLangOpts().OpenCL &&
- !((getLangOpts().OpenCLVersion >= 120) ||
-   getOpenCLOptions().cl_khr_fp64)) {
+ !(getOpenCLOptions().cl_khr_fp64)) {
+// Impose single-precision float type when cl_khr_fp64 is not enabled.
 Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64);
 Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
   }

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=289544=289543=289544=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Dec 13 10:22:50 2016
@@ -1403,8 +1403,7 @@ static QualType ConvertDeclSpecToType(Ty
   Result = Context.DoubleTy;
 
 if (S.getLangOpts().OpenCL &&
-!((S.getLangOpts().OpenCLVersion >= 120) ||
-  S.getOpenCLOptions().cl_khr_fp64)) {
+!(S.getOpenCLOptions().cl_khr_fp64)) {
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension)
   << Result << "cl_khr_fp64";
   declarator.setInvalidType(true);

Modified: cfe/trunk/test/CodeGenOpenCL/fpmath.cl
URL: 

[PATCH] D26167: [Clang-tidy] check for malloc, realloc and free calls

2016-12-13 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Jonas, do you need someone to commit the patch for you?


Repository:
  rL LLVM

https://reviews.llvm.org/D26167



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


r289543 - Remove deprecated methods ast_matchers::BoundNodes::{getStmtAs, getDeclAs}

2016-12-13 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Dec 13 10:19:34 2016
New Revision: 289543

URL: http://llvm.org/viewvc/llvm-project?rev=289543=rev
Log:
Remove deprecated methods ast_matchers::BoundNodes::{getStmtAs,getDeclAs}

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp
cfe/trunk/unittests/AST/DeclPrinterTest.cpp
cfe/trunk/unittests/AST/StmtPrinterTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=289543=289542=289543=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Dec 13 10:19:34 2016
@@ -75,18 +75,6 @@ public:
 return MyBoundNodes.getNodeAs(ID);
   }
 
-  /// \brief Deprecated. Please use \c getNodeAs instead.
-  /// @{
-  template 
-  const T *getDeclAs(StringRef ID) const {
-return getNodeAs(ID);
-  }
-  template 
-  const T *getStmtAs(StringRef ID) const {
-return getNodeAs(ID);
-  }
-  /// @}
-
   /// \brief Type of mapping from binding identifiers to bound nodes. This type
   /// is an associative container with a key type of \c std::string and a value
   /// type of \c clang::ast_type_traits::DynTypedNode

Modified: cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp?rev=289543=289542=289543=diff
==
--- cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp (original)
+++ cfe/trunk/lib/Tooling/RefactoringCallbacks.cpp Tue Dec 13 10:19:34 2016
@@ -39,7 +39,7 @@ ReplaceStmtWithText::ReplaceStmtWithText
 
 void ReplaceStmtWithText::run(
 const ast_matchers::MatchFinder::MatchResult ) {
-  if (const Stmt *FromMatch = Result.Nodes.getStmtAs(FromId)) {
+  if (const Stmt *FromMatch = Result.Nodes.getNodeAs(FromId)) {
 auto Err = Replace.add(tooling::Replacement(
 *Result.SourceManager,
 CharSourceRange::getTokenRange(FromMatch->getSourceRange()), ToText));
@@ -56,8 +56,8 @@ ReplaceStmtWithStmt::ReplaceStmtWithStmt
 
 void ReplaceStmtWithStmt::run(
 const ast_matchers::MatchFinder::MatchResult ) {
-  const Stmt *FromMatch = Result.Nodes.getStmtAs(FromId);
-  const Stmt *ToMatch = Result.Nodes.getStmtAs(ToId);
+  const Stmt *FromMatch = Result.Nodes.getNodeAs(FromId);
+  const Stmt *ToMatch = Result.Nodes.getNodeAs(ToId);
   if (FromMatch && ToMatch) {
 auto Err = Replace.add(
 replaceStmtWithStmt(*Result.SourceManager, *FromMatch, *ToMatch));
@@ -75,7 +75,7 @@ ReplaceIfStmtWithItsBody::ReplaceIfStmtW
 
 void ReplaceIfStmtWithItsBody::run(
 const ast_matchers::MatchFinder::MatchResult ) {
-  if (const IfStmt *Node = Result.Nodes.getStmtAs(Id)) {
+  if (const IfStmt *Node = Result.Nodes.getNodeAs(Id)) {
 const Stmt *Body = PickTrueBranch ? Node->getThen() : Node->getElse();
 if (Body) {
   auto Err =

Modified: cfe/trunk/unittests/AST/DeclPrinterTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/DeclPrinterTest.cpp?rev=289543=289542=289543=diff
==
--- cfe/trunk/unittests/AST/DeclPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/DeclPrinterTest.cpp Tue Dec 13 10:19:34 2016
@@ -45,7 +45,7 @@ public:
   PrintMatch() : NumFoundDecls(0) {}
 
   void run(const MatchFinder::MatchResult ) override {
-const Decl *D = Result.Nodes.getDeclAs("id");
+const Decl *D = Result.Nodes.getNodeAs("id");
 if (!D || D->isImplicit())
   return;
 NumFoundDecls++;

Modified: cfe/trunk/unittests/AST/StmtPrinterTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/StmtPrinterTest.cpp?rev=289543=289542=289543=diff
==
--- cfe/trunk/unittests/AST/StmtPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/StmtPrinterTest.cpp Tue Dec 13 10:19:34 2016
@@ -45,7 +45,7 @@ public:
   PrintMatch() : NumFoundStmts(0) {}
 
   void run(const MatchFinder::MatchResult ) override {
-const Stmt *S = Result.Nodes.getStmtAs("id");
+const Stmt *S = Result.Nodes.getNodeAs("id");
 if (!S)
   return;
 NumFoundStmts++;


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


[clang-tools-extra] r289542 - Remove deprecated methods ast_matchers::BoundNodes::{getStmtAs, getDeclAs}

2016-12-13 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Dec 13 10:19:19 2016
New Revision: 289542

URL: http://llvm.org/viewvc/llvm-project?rev=289542=rev
Log:
Remove deprecated methods ast_matchers::BoundNodes::{getStmtAs,getDeclAs}

Modified:

clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp
clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp
clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp
clang-tools-extra/trunk/unittests/clang-tidy/IncludeInserterTest.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp?rev=289542=289541=289542=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp 
Tue Dec 13 10:19:19 2016
@@ -32,8 +32,8 @@ void BoolPointerImplicitConversionCheck:
 
 void BoolPointerImplicitConversionCheck::check(
 const MatchFinder::MatchResult ) {
-  auto *If = Result.Nodes.getStmtAs("if");
-  auto *Var = Result.Nodes.getStmtAs("expr");
+  auto *If = Result.Nodes.getNodeAs("if");
+  auto *Var = Result.Nodes.getNodeAs("expr");
 
   // Ignore macros.
   if (Var->getLocStart().isMacroID())

Modified: clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp?rev=289542=289541=289542=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp Tue Dec 13 
10:19:19 2016
@@ -60,7 +60,7 @@ void IncorrectRoundings::registerMatcher
 }
 
 void IncorrectRoundings::check(const MatchFinder::MatchResult ) {
-  const auto *CastExpr = Result.Nodes.getStmtAs("CastExpr");
+  const auto *CastExpr = Result.Nodes.getNodeAs("CastExpr");
   diag(CastExpr->getLocStart(),
"casting (double + 0.5) to integer leads to incorrect rounding; "
"consider using lround (#include ) instead");

Modified: clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp?rev=289542=289541=289542=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/SwappedArgumentsCheck.cpp Tue Dec 
13 10:19:19 2016
@@ -49,7 +49,7 @@ static bool isImplicitCastCandidate(cons
 
 void SwappedArgumentsCheck::check(const MatchFinder::MatchResult ) {
   const ASTContext  = *Result.Context;
-  const auto *Call = Result.Nodes.getStmtAs("call");
+  const auto *Call = Result.Nodes.getNodeAs("call");
 
   llvm::SmallPtrSet UsedArgs;
   for (unsigned I = 1, E = Call->getNumArgs(); I < E; ++I) {

Modified: clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp?rev=289542=289541=289542=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp Tue Dec 
13 10:19:19 2016
@@ -74,7 +74,7 @@ void UndelegatedConstructorCheck::regist
 
 void UndelegatedConstructorCheck::check(
 const MatchFinder::MatchResult ) {
-  const auto *E = Result.Nodes.getStmtAs("construct");
+  const auto *E = Result.Nodes.getNodeAs("construct");
   diag(E->getLocStart(), "did you intend to call a delegated constructor? "
  "A temporary object is created here instead");
 }

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp?rev=289542=289541=289542=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp Tue Dec 13 
10:19:19 2016
@@ -48,7 +48,7 @@ void UnusedRAIICheck::registerMatchers(M
 }
 
 void UnusedRAIICheck::check(const MatchFinder::MatchResult ) {
-  const auto *E = 

[PATCH] D26750: [clang-tidy] Add modernize-use-default-member-init check

2016-12-13 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/modernize/UseDefaultMemberInitCheck.cpp:21
+
+static StringRef getValueInit(const CXXCtorInitializer *Init) {
+  switch (Init->getInit()->getType()->getScalarTypeKind()) {

The function name doesn't make it clear that the value is returned for 
zero-initialization.



Comment at: clang-tidy/modernize/UseDefaultMemberInitCheck.cpp:137
+  isDefaultConstructor(),
+  unless(ast_matchers::isTemplateInstantiation()),
+  forEachConstructorInitializer(allOf(

`isInTemplateInstantiation()` is usually a better choice, since it also checks 
for ancestors being templates.



Comment at: clang-tidy/modernize/UseDefaultMemberInitCheck.cpp:157-161
+  const auto *Default = Result.Nodes.getNodeAs("default");
+  const auto *Existing = 
Result.Nodes.getNodeAs("existing");
+
+  if (Default)
+checkDefaultInit(Result, Default);

This is a more common way to do this in LLVM:
```
if (const auto *Default = Result.Nodes.getNodeAs<...>("default"))
  checkDefaultInit(Result, Default);
else if (const auto *Existing = ...)
  checkExistingInit(...);
else
  llvm_unreachable(...);
```



Comment at: docs/clang-tidy/checks/modernize-use-default-member-init.rst:29
+
+.. note::
+  Only converts member initializers for built-in types, enums and pointers.

Is an empty line needed after this?


https://reviews.llvm.org/D26750



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


[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-12-13 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D27166#617696, @malcolm.parsons wrote:

> In https://reviews.llvm.org/D27166#617621, @Prazek wrote:.
>
> > Does it work for cases like?
>
>
> Yes; `replaceExpr()` checks that the variable has the same unqualified type 
> as the initializer and the same canonical type as other variables in the 
> declaration.


Can you add this small test?




Comment at: clang-tidy/modernize/UseAutoCheck.cpp:173-177
+/// Matches the type that was substituted for the template parameter.
+AST_MATCHER_P(SubstTemplateTypeParmType, hasReplacementType,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node.getReplacementType(), Finder, Builder);
+}

alexfh wrote:
> Ideally, this should go to ASTMatchers.h (with a proper test and 
> documentation).
I agree 



Comment at: clang-tidy/modernize/UseAutoCheck.cpp:256-264
+  return declStmt(
+ 
unless(has(varDecl(unless(hasInitializer(ignoringImplicit(callExpr(
+ anyOf(has(memberExpr(hasExplicitTemplateArgs())),
+   has(ignoringImpCasts(
+   declRefExpr(hasExplicitTemplateArgs(),
+ callee(functionDecl(
+ hasTemplateArgument(0,

Can you split this matcher into 3 matchers? It is so large that even 
clang-format doesn't help with it.
And also because of that I can't come up with good auto variables to use here, 
because I don't know where the parens ends.



Comment at: docs/clang-tidy/checks/modernize-use-auto.rst:165
+that behave as casts, such as ``llvm::dyn_cast``, ``boost::lexical_cast`` and
+``gsl::narrow_cast``.
 

I would add to that what functions are considered (functions returning type 
chosen as first template parameter or something similar). Now someone could 
think that there is hardcoded list somewhere.


https://reviews.llvm.org/D27166



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


[PATCH] D27700: [clang-tidy] refactor ExprSequence out of misc-use-after-move check

2016-12-13 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added inline comments.



Comment at: clang-tidy/utils/ExprSequence.cpp:52
+
+bool isDescendantOrEqual(const Stmt *Descendant, const Stmt *Ancestor,
+ ASTContext *Context) {

staronj wrote:
> Shouldn't isDescendantOrEqual be static or in inline namespace?
Goot catch. I guess putting it with getParentStmts into anonymous namespace is 
the best solution.
btw inline namespace is not the same as anonymous namespace :)


https://reviews.llvm.org/D27700



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


  1   2   >