[libcxx] r266956 - [libc++] fix macro redef warning when exception is disabled

2016-04-20 Thread Weiming Zhao via cfe-commits
Author: weimingz
Date: Thu Apr 21 00:28:18 2016
New Revision: 266956

URL: http://llvm.org/viewvc/llvm-project?rev=266956=rev
Log:
[libc++] fix macro redef warning when exception is disabled

Summary:
 when setting LIBCXX_ENABLE_EXCEPTIONS=false, _LIBCPP_NO_EXCEPTIONS wil be 
defined in both commandline and _config

Reviewers: bcraig, EricWF

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19344

Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=266956=266955=266956=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Thu Apr 21 00:28:18 2016
@@ -297,7 +297,7 @@ typedef __char16_t char16_t;
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 


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


Re: [PATCH] D19344: [libc++] fix macro redef warning when exception is disabled

2016-04-20 Thread Weiming Zhao via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266956: [libc++] fix macro redef warning when exception is 
disabled (authored by weimingz).

Changed prior to commit:
  http://reviews.llvm.org/D19344?vs=54457=54459#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19344

Files:
  libcxx/trunk/include/__config

Index: libcxx/trunk/include/__config
===
--- libcxx/trunk/include/__config
+++ libcxx/trunk/include/__config
@@ -297,7 +297,7 @@
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 


Index: libcxx/trunk/include/__config
===
--- libcxx/trunk/include/__config
+++ libcxx/trunk/include/__config
@@ -297,7 +297,7 @@
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19344: [libc++] fix macro redef warning when exception is disabled

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

LGTM.

Normally system header would simply ignore this problem. However it's valuable 
to compile libc++ as a non-system header for both users and developers.

Than you for the patch.


http://reviews.llvm.org/D19344



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


Re: [PATCH] D19344: [libc++] fix macro redef warning when exception is disabled

2016-04-20 Thread Weiming Zhao via cfe-commits
weimingz retitled this revision from "[libc++] fix constexpr error when build 
with MUSL and macro redef warning when no exception" to "[libc++] fix macro 
redef warning when exception is disabled".
weimingz updated the summary for this revision.
weimingz updated this revision to Diff 54457.

http://reviews.llvm.org/D19344

Files:
  include/__config

Index: include/__config
===
--- include/__config
+++ include/__config
@@ -297,7 +297,7 @@
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 


Index: include/__config
===
--- include/__config
+++ include/__config
@@ -297,7 +297,7 @@
 typedef __char32_t char32_t;
 #endif
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC

2016-04-20 Thread Hubert Tong via cfe-commits
hubert.reinterpretcast updated this revision to Diff 54456.
hubert.reinterpretcast added a comment.

Actually add parens this time


http://reviews.llvm.org/D19322

Files:
  include/clang/AST/DeclTemplate.h
  lib/AST/DeclTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp

Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -4034,8 +4034,8 @@
  nullptr, false, false);
   QualType TemplArg = QualType(TemplParam->getTypeForDecl(), 0);
   NamedDecl *TemplParamPtr = TemplParam;
-  FixedSizeTemplateParameterListStorage<1> TemplateParamsSt(
-  Loc, Loc, TemplParamPtr, Loc);
+  FixedSizeTemplateParameterListStorage<1, false> TemplateParamsSt(
+  Loc, Loc, TemplParamPtr, Loc, nullptr);
 
   QualType FuncParam = SubstituteAutoTransform(*this, TemplArg).Apply(Type);
   assert(!FuncParam.isNull() &&
Index: lib/AST/DeclTemplate.cpp
===
--- lib/AST/DeclTemplate.cpp
+++ lib/AST/DeclTemplate.cpp
@@ -31,9 +31,11 @@
 TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc,
  SourceLocation LAngleLoc,
  ArrayRef Params,
- SourceLocation RAngleLoc)
+ SourceLocation RAngleLoc,
+ Expr *RequiresClause)
   : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
-NumParams(Params.size()), ContainsUnexpandedParameterPack(false) {
+NumParams(Params.size()), ContainsUnexpandedParameterPack(false),
+HasRequiresClause(static_cast(RequiresClause)) {
   assert(this->NumParams == NumParams && "Too many template parameters");
   for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
 NamedDecl *P = Params[Idx];
@@ -52,15 +54,21 @@
   // template parameter list does too.
 }
   }
+  if (RequiresClause) {
+*getTrailingObjects() = RequiresClause;
+  }
 }
 
-TemplateParameterList *TemplateParameterList::Create(
-const ASTContext , SourceLocation TemplateLoc, SourceLocation LAngleLoc,
-ArrayRef Params, SourceLocation RAngleLoc) {
-  void *Mem = C.Allocate(totalSizeToAlloc(Params.size()),
+TemplateParameterList *
+TemplateParameterList::Create(const ASTContext , SourceLocation TemplateLoc,
+  SourceLocation LAngleLoc,
+  ArrayRef Params,
+  SourceLocation RAngleLoc, Expr *RequiresClause) {
+  void *Mem = C.Allocate(totalSizeToAlloc(
+ Params.size(), RequiresClause ? 1u : 0u),
  llvm::alignOf());
   return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
- RAngleLoc);
+ RAngleLoc, RequiresClause);
 }
 
 unsigned TemplateParameterList::getMinRequiredArguments() const {
Index: include/clang/AST/DeclTemplate.h
===
--- include/clang/AST/DeclTemplate.h
+++ include/clang/AST/DeclTemplate.h
@@ -46,7 +46,8 @@
 /// \brief Stores a list of template parameters for a TemplateDecl and its
 /// derived classes.
 class TemplateParameterList final
-: private llvm::TrailingObjects {
+: private llvm::TrailingObjects {
 
   /// The location of the 'template' keyword.
   SourceLocation TemplateLoc;
@@ -56,26 +57,36 @@
 
   /// The number of template parameters in this template
   /// parameter list.
-  unsigned NumParams : 31;
+  unsigned NumParams : 30;
 
   /// Whether this template parameter list contains an unexpanded parameter
   /// pack.
   unsigned ContainsUnexpandedParameterPack : 1;
 
+  /// Whether this template parameter list has an associated requires-clause
+  unsigned HasRequiresClause : 1;
+
 protected:
   size_t numTrailingObjects(OverloadToken) const {
 return NumParams;
   }
 
+  size_t numTrailingObjects(OverloadToken) const {
+return HasRequiresClause;
+  }
+
   TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc,
-ArrayRef Params, SourceLocation RAngleLoc);
+ArrayRef Params, SourceLocation RAngleLoc,
+Expr *RequiresClause);
 
 public:
+  // FIXME: remove default argument for RequiresClause
   static TemplateParameterList *Create(const ASTContext ,
SourceLocation TemplateLoc,
SourceLocation LAngleLoc,
ArrayRef Params,
-   SourceLocation RAngleLoc);
+ 

Re: [PATCH] D19322: Concepts: Create space for requires-clause in TemplateParameterList; NFC

2016-04-20 Thread Hubert Tong via cfe-commits
hubert.reinterpretcast updated this revision to Diff 54455.
hubert.reinterpretcast added a comment.

Store the RequiresClause expression into the created storage;
add accessor;
add unnecessary parens to silence warning


http://reviews.llvm.org/D19322

Files:
  include/clang/AST/DeclTemplate.h
  lib/AST/DeclTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp

Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -4034,8 +4034,8 @@
  nullptr, false, false);
   QualType TemplArg = QualType(TemplParam->getTypeForDecl(), 0);
   NamedDecl *TemplParamPtr = TemplParam;
-  FixedSizeTemplateParameterListStorage<1> TemplateParamsSt(
-  Loc, Loc, TemplParamPtr, Loc);
+  FixedSizeTemplateParameterListStorage<1, false> TemplateParamsSt(
+  Loc, Loc, TemplParamPtr, Loc, nullptr);
 
   QualType FuncParam = SubstituteAutoTransform(*this, TemplArg).Apply(Type);
   assert(!FuncParam.isNull() &&
Index: lib/AST/DeclTemplate.cpp
===
--- lib/AST/DeclTemplate.cpp
+++ lib/AST/DeclTemplate.cpp
@@ -31,9 +31,11 @@
 TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc,
  SourceLocation LAngleLoc,
  ArrayRef Params,
- SourceLocation RAngleLoc)
+ SourceLocation RAngleLoc,
+ Expr *RequiresClause)
   : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
-NumParams(Params.size()), ContainsUnexpandedParameterPack(false) {
+NumParams(Params.size()), ContainsUnexpandedParameterPack(false),
+HasRequiresClause(static_cast(RequiresClause)) {
   assert(this->NumParams == NumParams && "Too many template parameters");
   for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
 NamedDecl *P = Params[Idx];
@@ -52,15 +54,21 @@
   // template parameter list does too.
 }
   }
+  if (RequiresClause) {
+*getTrailingObjects() = RequiresClause;
+  }
 }
 
-TemplateParameterList *TemplateParameterList::Create(
-const ASTContext , SourceLocation TemplateLoc, SourceLocation LAngleLoc,
-ArrayRef Params, SourceLocation RAngleLoc) {
-  void *Mem = C.Allocate(totalSizeToAlloc(Params.size()),
+TemplateParameterList *
+TemplateParameterList::Create(const ASTContext , SourceLocation TemplateLoc,
+  SourceLocation LAngleLoc,
+  ArrayRef Params,
+  SourceLocation RAngleLoc, Expr *RequiresClause) {
+  void *Mem = C.Allocate(totalSizeToAlloc(
+ Params.size(), RequiresClause ? 1u : 0u),
  llvm::alignOf());
   return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
- RAngleLoc);
+ RAngleLoc, RequiresClause);
 }
 
 unsigned TemplateParameterList::getMinRequiredArguments() const {
Index: include/clang/AST/DeclTemplate.h
===
--- include/clang/AST/DeclTemplate.h
+++ include/clang/AST/DeclTemplate.h
@@ -46,7 +46,8 @@
 /// \brief Stores a list of template parameters for a TemplateDecl and its
 /// derived classes.
 class TemplateParameterList final
-: private llvm::TrailingObjects {
+: private llvm::TrailingObjects {
 
   /// The location of the 'template' keyword.
   SourceLocation TemplateLoc;
@@ -56,26 +57,36 @@
 
   /// The number of template parameters in this template
   /// parameter list.
-  unsigned NumParams : 31;
+  unsigned NumParams : 30;
 
   /// Whether this template parameter list contains an unexpanded parameter
   /// pack.
   unsigned ContainsUnexpandedParameterPack : 1;
 
+  /// Whether this template parameter list has an associated requires-clause
+  unsigned HasRequiresClause : 1;
+
 protected:
   size_t numTrailingObjects(OverloadToken) const {
 return NumParams;
   }
 
+  size_t numTrailingObjects(OverloadToken) const {
+return HasRequiresClause;
+  }
+
   TemplateParameterList(SourceLocation TemplateLoc, SourceLocation LAngleLoc,
-ArrayRef Params, SourceLocation RAngleLoc);
+ArrayRef Params, SourceLocation RAngleLoc,
+Expr *RequiresClause);
 
 public:
+  // FIXME: remove default argument for RequiresClause
   static TemplateParameterList *Create(const ASTContext ,
SourceLocation TemplateLoc,
SourceLocation LAngleLoc,
ArrayRef 

Re: [PATCH] D19344: [libc++] fix constexpr error when build with MUSL and macro redef warning when no exception

2016-04-20 Thread Eric Fiselier via cfe-commits
EricWF added inline comments.


Comment at: include/__config:300
@@ -299,3 +299,3 @@
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS

weimingz wrote:
> Is this change OK?
Yes. 


Comment at: include/__mutex_base:43
@@ -42,3 +42,3 @@
 _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR
  constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}

weimingz wrote:
> EricWF wrote:
> > This is not OK. It's critical that mutex have a constexpr constructor that 
> > it runs during the "Constant initialization" phase of static initialization.
> > Heres an example of the difference this makes: https://godbolt.org/g/3cvlMJ
> > 
> > Also the constructor is specified as being constexpr in C++11. We can't 
> > turn that off. 
> > 
> > If one particular pthread implementation is broken then we need a fix 
> > targeted to only that implementation.  However this seems like a pthread 
> > bug and not a libc++ bug.
> The macro has an "#else" part.  I'm not familiar with this, but it seems the 
> constexpr an "optional feature".
> 
> 
> 
So `_LIBCPP_HAS_NO_CONSTEXPR` checks for the presence of C++11 constexpr 
semantics. In C++14 support for `constexpr` was greatly increased, allowing 
many more expressions to be considered "constant expressions".  The original 
macro, and `_LIBCPP_HAS_NO_CXX14_CONSTXPR` check if a compiler has completely 
implemented the C++11 or C++14 constexpr requirements respectively. In your 
case `PTHREAD_MUTEX_INITIALIZER` is defined in such a way that it requires the 
C++14 definition of `constexpr`. 


http://reviews.llvm.org/D19344



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


Re: [PATCH] D19344: [libc++] fix constexpr error when build with MUSL and macro redef warning when no exception

2016-04-20 Thread Weiming Zhao via cfe-commits
weimingz added inline comments.


Comment at: include/__config:300
@@ -299,3 +299,3 @@
 
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
 #define _LIBCPP_NO_EXCEPTIONS

Is this change OK?


Comment at: include/__mutex_base:43
@@ -42,3 +42,3 @@
 _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR
  constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}

EricWF wrote:
> This is not OK. It's critical that mutex have a constexpr constructor that it 
> runs during the "Constant initialization" phase of static initialization.
> Heres an example of the difference this makes: https://godbolt.org/g/3cvlMJ
> 
> Also the constructor is specified as being constexpr in C++11. We can't turn 
> that off. 
> 
> If one particular pthread implementation is broken then we need a fix 
> targeted to only that implementation.  However this seems like a pthread bug 
> and not a libc++ bug.
The macro has an "#else" part.  I'm not familiar with this, but it seems the 
constexpr an "optional feature".





http://reviews.llvm.org/D19344



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


r266945 - [modules] Make the tweak to avoid circular inclusion of emmintrin.h and

2016-04-20 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Apr 20 20:46:37 2016
New Revision: 266945

URL: http://llvm.org/viewvc/llvm-project?rev=266945=rev
Log:
[modules] Make the tweak to avoid circular inclusion of emmintrin.h and
xmmintrin.h a bit more directed. If for whatever reason modules are enabled but
we textually include one of these headers, don't deploy the special case for
modules. To make this work cleanly, extend __building_module to be defined
even when modules is disabled.

Modified:
cfe/trunk/lib/Headers/xmmintrin.h
cfe/trunk/lib/Lex/PPMacroExpansion.cpp

Modified: cfe/trunk/lib/Headers/xmmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/xmmintrin.h?rev=266945=266944=266945=diff
==
--- cfe/trunk/lib/Headers/xmmintrin.h (original)
+++ cfe/trunk/lib/Headers/xmmintrin.h Wed Apr 20 20:46:37 2016
@@ -1946,7 +1946,7 @@ do { \
 #undef __DEFAULT_FN_ATTRS
 
 /* Ugly hack for backwards-compatibility (compatible with gcc) */
-#if defined(__SSE2__) && !__has_feature(modules)
+#if defined(__SSE2__) && !__building_module(_Builtin_intrinsics)
 #include 
 #endif
 

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=266945=266944=266945=diff
==
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Wed Apr 20 20:46:37 2016
@@ -330,18 +330,11 @@ void Preprocessor::RegisterBuiltinMacros
   Ident__is_identifier= RegisterBuiltinMacro(*this, "__is_identifier");
 
   // Modules.
-  if (LangOpts.Modules) {
-Ident__building_module  = RegisterBuiltinMacro(*this, "__building_module");
-
-// __MODULE__
-if (!LangOpts.CurrentModule.empty())
-  Ident__MODULE__ = RegisterBuiltinMacro(*this, "__MODULE__");
-else
-  Ident__MODULE__ = nullptr;
-  } else {
-Ident__building_module = nullptr;
+  Ident__building_module  = RegisterBuiltinMacro(*this, "__building_module");
+  if (!LangOpts.CurrentModule.empty())
+Ident__MODULE__ = RegisterBuiltinMacro(*this, "__MODULE__");
+  else
 Ident__MODULE__ = nullptr;
-  }
 }
 
 /// isTrivialSingleTokenExpansion - Return true if MI, which has a single token


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


Re: [PATCH] D19344: [libc++] fix constexpr error when build with MUSL and macro redef warning when no exception

2016-04-20 Thread Eric Fiselier via cfe-commits
EricWF requested changes to this revision.
This revision now requires changes to proceed.


Comment at: include/__mutex_base:43
@@ -42,3 +42,3 @@
 _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR
  constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}

This is not OK. It's critical that mutex have a constexpr constructor that it 
runs during the "Constant initialization" phase of static initialization.
Heres an example of the difference this makes: https://godbolt.org/g/3cvlMJ

Also the constructor is specified as being constexpr in C++11. We can't turn 
that off. 

If one particular pthread implementation is broken then we need a fix targeted 
to only that implementation.  However this seems like a pthread bug and not a 
libc++ bug.


Comment at: include/__mutex_base:282
@@ -281,3 +281,3 @@
 _LIBCPP_INLINE_VISIBILITY
-#ifndef _LIBCPP_HAS_NO_CONSTEXPR
+#ifndef _LIBCPP_HAS_NO_CXX14_CONSTEXPR
 constexpr condition_variable() : __cv_(PTHREAD_COND_INITIALIZER) {}

Same as above.


http://reviews.llvm.org/D19344



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


r266938 - Remove the (ignored) -Wreceived-is-weak diagnostic.

2016-04-20 Thread Bob Wilson via cfe-commits
Author: bwilson
Date: Wed Apr 20 19:11:24 2016
New Revision: 266938

URL: http://llvm.org/viewvc/llvm-project?rev=266938=rev
Log:
Remove the (ignored) -Wreceived-is-weak diagnostic.

We kept this around for a while since Xcode 6 and earlier had a build
setting for this warning. It was removed in Xcode 7 so there should be
no need for this warning now.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/test/SemaObjC/iboutlet.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=266938=266937=266938=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Apr 20 19:11:24 2016
@@ -286,8 +286,6 @@ def : DiagGroup<"overflow">;
 def ForwardClassReceiver : DiagGroup<"receiver-forward-class">;
 def MethodAccess : DiagGroup<"objc-method-access">;
 def ObjCReceiver : DiagGroup<"receiver-expr">;
-// FIXME: Remove this when Xcode removes the warning setting.
-def : DiagGroup<"receiver-is-weak">;
 def OperatorNewReturnsNull : DiagGroup<"new-returns-null">;
 def OverlengthStrings : DiagGroup<"overlength-strings">;
 def OverloadedVirtual : DiagGroup<"overloaded-virtual">;

Modified: cfe/trunk/test/SemaObjC/iboutlet.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/iboutlet.m?rev=266938=266937=266938=diff
==
--- cfe/trunk/test/SemaObjC/iboutlet.m (original)
+++ cfe/trunk/test/SemaObjC/iboutlet.m Wed Apr 20 19:11:24 2016
@@ -1,7 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -Wno-objc-root-class 
-Wreceiver-is-weak -Warc-repeated-use-of-weak -fobjc-runtime-has-weak -verify %s
-// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -fobjc-arc 
-Wno-objc-root-class -Wreceiver-is-weak -Warc-repeated-use-of-weak 
-fobjc-runtime-has-weak -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -Wno-objc-root-class 
-Warc-repeated-use-of-weak -fobjc-runtime-has-weak -verify %s
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -fobjc-arc 
-Wno-objc-root-class -Warc-repeated-use-of-weak -fobjc-runtime-has-weak -verify 
%s
 // rdar://11448209
-// rdar://20259376
 
 #define READONLY readonly
 


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


Re: [PATCH] D18635: Rework interface for bitset-using features to use a notion of LTO visibility.

2016-04-20 Thread Peter Collingbourne via cfe-commits
pcc updated this revision to Diff 54439.
pcc marked 2 inline comments as done.
pcc added a comment.

- Address review comments


http://reviews.llvm.org/D18635

Files:
  docs/ControlFlowIntegrity.rst
  docs/LTOVisibility.rst
  docs/UsersManual.rst
  docs/index.rst
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  runtime/CMakeLists.txt
  runtime/vtables_blacklist.txt
  test/CodeGenCXX/bitset-blacklist.cpp
  test/CodeGenCXX/bitset-inference.cpp
  test/CodeGenCXX/bitsets.cpp
  test/CodeGenCXX/cfi-blacklist.cpp
  test/CodeGenCXX/cfi-cast.cpp
  test/CodeGenCXX/cfi-cross-dso.cpp
  test/CodeGenCXX/cfi-ms-rtti.cpp
  test/CodeGenCXX/cfi-nvcall.cpp
  test/CodeGenCXX/cfi-stats.cpp
  test/Driver/cl-runtime-flags.c
  test/Driver/fsanitize.c
  test/Driver/whole-program-vtables.c
  test/Frontend/dependency-gen.c
  test/SemaCXX/attr-lto-visibility-public.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -2524,6 +2524,7 @@
 case ObjCProtocol | ObjCInterface:
   return "ExpectedObjectiveCInterfaceOrProtocol";
 case Field | Var: return "ExpectedFieldOrGlobalVar";
+case GenericRecord | Namespace: return "ExpectedRecordOrNamespace";
   }
 
   PrintFatalError(S.getLoc(),
Index: test/SemaCXX/attr-lto-visibility-public.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-lto-visibility-public.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+int i [[clang::lto_visibility_public]]; // expected-warning {{'lto_visibility_public' attribute only applies to struct, union or class}}
+typedef int t [[clang::lto_visibility_public]]; // expected-warning {{'lto_visibility_public' attribute only applies to struct, union or class}}
+[[clang::lto_visibility_public]] void f(); // expected-warning {{'lto_visibility_public' attribute only applies to struct, union or class}}
+void f() [[clang::lto_visibility_public]]; // expected-error {{'lto_visibility_public' attribute cannot be applied to types}}
+
+struct [[clang::lto_visibility_public]] s1 {
+  int i [[clang::lto_visibility_public]]; // expected-warning {{'lto_visibility_public' attribute only applies to struct, union or class}}
+  [[clang::lto_visibility_public]] void f(); // expected-warning {{'lto_visibility_public' attribute only applies to struct, union or class}}
+};
+
+struct [[clang::lto_visibility_public(1)]] s2 { // expected-error {{'lto_visibility_public' attribute takes no arguments}}
+};
Index: test/Frontend/dependency-gen.c
===
--- test/Frontend/dependency-gen.c
+++ test/Frontend/dependency-gen.c
@@ -21,7 +21,7 @@
 // RUN: %clang -MD -MF - %s -fsyntax-only -I ./ | FileCheck -check-prefix=CHECK-SIX %s
 // CHECK-SIX: {{ }}x.h
 // RUN: echo "fun:foo" > %t.blacklist
-// RUN: %clang -MD -MF - %s -fsyntax-only -fsanitize=cfi-vcall -flto -fsanitize-blacklist=%t.blacklist -I ./ | FileCheck -check-prefix=CHECK-SEVEN %s
+// RUN: %clang -MD -MF - %s -fsyntax-only -fsanitize=cfi-vcall -flto -fvisibility=hidden -fsanitize-blacklist=%t.blacklist -I ./ | FileCheck -check-prefix=CHECK-SEVEN %s
 // CHECK-SEVEN: .blacklist
 // CHECK-SEVEN: {{ }}x.h
 #ifndef INCLUDE_FLAG_TEST
Index: test/Driver/whole-program-vtables.c
===
--- test/Driver/whole-program-vtables.c
+++ test/Driver/whole-program-vtables.c
@@ -1,11 +1,2 @@
 // RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables -### %s 2>&1 | FileCheck --check-prefix=NO-LTO %s
 // NO-LTO: invalid argument '-fwhole-program-vtables' only allowed with '-flto'
-
-// RUN: %clang -target x86_64-unknown-linux -resource-dir=%S/Inputs/resource_dir -flto -fwhole-program-vtables -### -c %s 2>&1 | FileCheck --check-prefix=BLACKLIST %s
-// BLACKLIST: "-fwhole-program-vtables-blacklist={{.*}}vtables_blacklist.txt"
-
-// RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables-blacklist=nonexistent.txt -flto -fwhole-program-vtables -### -c %s 2>&1 | FileCheck --check-prefix=NON-EXISTENT-BLACKLIST %s
-// NON-EXISTENT-BLACKLIST: no such file or directory: 'nonexistent.txt'
-
-// RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables-blacklist=%S/Inputs/resource_dir/vtables_blacklist.txt -flto -fwhole-program-vtables -### -c %s 2>&1 | FileCheck --check-prefix=CUSTOM-BLACKLIST %s
-// 

Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread Adam Nemet via cfe-commits
anemet added a comment.

Rong, do you have full paths or just the filename?


http://reviews.llvm.org/D18624



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


Re: r266719 - Warn if function or variable cannot be implicitly instantiated

2016-04-20 Thread Sean Silva via cfe-commits
On Tue, Apr 19, 2016 at 7:28 AM, Nico Weber via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> (sorry, accidentally sent this mid-mail)
>
> ../../v8/src/crankshaft/lithium.h:322:45: error: instantiation of variable
> 'v8::internal::LSubKindOperand 128>::cache' required here, but no definition is available
> [-Werror,-Wundefined-var-template]
> if (index < kNumCachedOperands) return [index];
> ^
> ../../v8/src/crankshaft/x64/lithium-x64.cc:334:30: note: in instantiation
> of member function
> 'v8::internal::LSubKindOperand 128>::Create' requested here
> return LDoubleStackSlot::Create(index, zone());
>  ^
> ../../v8/src/crankshaft/lithium.h:335:27: note: forward declaration of
> template entity is here
>   static LSubKindOperand* cache;
>   ^
> ../../v8/src/crankshaft/lithium.h:322:45: note: add an explicit
> instantiation declaration to suppress this warning if
> 'v8::internal::LSubKindOperand 128>::cache' is explicitly instantiated in another translation unit
> if (index < kNumCachedOperands) return [index];
> ^
>
> I don't understand what this warning wants to tell me, or what it wants me
> to do. What is this warning good for? Neither warning text nor commit
> message explain that.
>

Yes, the diagnostics here can be substantially improved I think.
Richard's comment https://llvm.org/bugs/show_bug.cgi?id=24425#c2 gives more
insight into the part of the standard that this comes from.

-- Sean Silva



>
> On Tue, Apr 19, 2016 at 10:27 AM, Nico Weber  wrote:
>
>> Hi Serge,
>>
>> this complains on this snippet from v8:
>>
>> template 
>> class LSubKindOperand final : public LOperand {
>>  public:
>>   static LSubKindOperand* Create(int index, Zone* zone) {
>> if (index < kNumCachedOperands) return [index];
>> return new(zone) LSubKindOperand(index);
>>   }
>>  private:
>>   static LSubKindOperand* cache;
>>   explicit LSubKindOperand(int index);
>> };
>>
>>
>>
>> On Tue, Apr 19, 2016 at 2:19 AM, Serge Pavlov via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: sepavloff
>>> Date: Tue Apr 19 01:19:52 2016
>>> New Revision: 266719
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=266719=rev
>>> Log:
>>> Warn if function or variable cannot be implicitly instantiated
>>>
>>> With this patch compiler emits warning if it tries to make implicit
>>> instantiation
>>> of a template but cannot find the template definition. The warning can
>>> be suppressed
>>> by explicit instantiation declaration or by command line options
>>> -Wundefined-var-template and -Wundefined-func-template. The
>>> implementation follows
>>> the discussion of http://reviews.llvm.org/D12326.
>>>
>>> Differential Revision: http://reviews.llvm.org/D16396
>>>
>>> Added:
>>> cfe/trunk/test/SemaTemplate/undefined-template.cpp
>>> Modified:
>>> cfe/trunk/include/clang/AST/DeclBase.h
>>> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> cfe/trunk/include/clang/Sema/Sema.h
>>> cfe/trunk/lib/AST/DeclBase.cpp
>>> cfe/trunk/lib/Sema/SemaOverload.cpp
>>> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>>> cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p1.cpp
>>> cfe/trunk/test/OpenMP/parallel_ast_print.cpp
>>> cfe/trunk/test/OpenMP/parallel_sections_ast_print.cpp
>>> cfe/trunk/test/OpenMP/target_parallel_ast_print.cpp
>>> cfe/trunk/test/OpenMP/task_ast_print.cpp
>>> cfe/trunk/test/OpenMP/teams_ast_print.cpp
>>> cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp
>>> cfe/trunk/test/SemaCXX/PR10177.cpp
>>> cfe/trunk/test/SemaCXX/undefined-internal.cpp
>>>
>>> Modified: cfe/trunk/include/clang/AST/DeclBase.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=266719=266718=266719=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/AST/DeclBase.h (original)
>>> +++ cfe/trunk/include/clang/AST/DeclBase.h Tue Apr 19 01:19:52 2016
>>> @@ -52,6 +52,7 @@ struct PrintingPolicy;
>>>  class RecordDecl;
>>>  class Stmt;
>>>  class StoredDeclsMap;
>>> +class TemplateDecl;
>>>  class TranslationUnitDecl;
>>>  class UsingDirectiveDecl;
>>>  }
>>> @@ -905,6 +906,10 @@ public:
>>> DeclKind == FunctionTemplate;
>>>}
>>>
>>> +  /// \brief If this is a declaration that describes some template, this
>>> +  /// method returns that template declaration.
>>> +  TemplateDecl *getDescribedTemplate() const;
>>> +
>>>/// \brief Returns the function itself, or the templated function if
>>> this is a
>>>/// function template.
>>>FunctionDecl *getAsFunction() 

Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread Rong Xu via cfe-commits
xur added a comment.

these two patches work fine in my build. My llvm was on top ov r265491. The
opt remarks in the last email were emitted by the compiler.

I'll try to reproduce with r266465.


http://reviews.llvm.org/D18624



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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread Rong Xu via cfe-commits
these two patches work fine in my build. My llvm was on top ov r265491. The
opt remarks in the last email were emitted by the compiler.

I'll try to reproduce with r266465.


On Apr 20, 2016 4:00 PM, "Adam Nemet"  wrote:

> anemet added a comment.
>
> Still does not to work.  The metadata has the full path for the file while
> the prof data only has the filename.
>
> FTR, I applied this and the ICP patch on top of r266465.
>
>
> http://reviews.llvm.org/D18624
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r266719 - Warn if function or variable cannot be implicitly instantiated

2016-04-20 Thread Sean Silva via cfe-commits
On Tue, Apr 19, 2016 at 7:28 AM, Nico Weber via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> (sorry, accidentally sent this mid-mail)
>
> ../../v8/src/crankshaft/lithium.h:322:45: error: instantiation of variable
> 'v8::internal::LSubKindOperand 128>::cache' required here, but no definition is available
> [-Werror,-Wundefined-var-template]
> if (index < kNumCachedOperands) return [index];
> ^
> ../../v8/src/crankshaft/x64/lithium-x64.cc:334:30: note: in instantiation
> of member function
> 'v8::internal::LSubKindOperand 128>::Create' requested here
> return LDoubleStackSlot::Create(index, zone());
>  ^
> ../../v8/src/crankshaft/lithium.h:335:27: note: forward declaration of
> template entity is here
>   static LSubKindOperand* cache;
>   ^
> ../../v8/src/crankshaft/lithium.h:322:45: note: add an explicit
> instantiation declaration to suppress this warning if
> 'v8::internal::LSubKindOperand 128>::cache' is explicitly instantiated in another translation unit
> if (index < kNumCachedOperands) return [index];
> ^
>
> I don't understand what this warning wants to tell me, or what it wants me
> to do. What is this warning good for? Neither warning text nor commit
> message explain that.
>


+1

I'm seeing a similar error in an internal codebase for a Singleton class.

Something like:

template 
struct Singleton {
... other stuff ...
  T *getInstance();
private:
  static T *instance;
};

And `instance` is defined in a .cpp file somewhere.

This seems to be deliberate.

-- Sean Silva


>
> On Tue, Apr 19, 2016 at 10:27 AM, Nico Weber  wrote:
>
>> Hi Serge,
>>
>> this complains on this snippet from v8:
>>
>> template 
>> class LSubKindOperand final : public LOperand {
>>  public:
>>   static LSubKindOperand* Create(int index, Zone* zone) {
>> if (index < kNumCachedOperands) return [index];
>> return new(zone) LSubKindOperand(index);
>>   }
>>  private:
>>   static LSubKindOperand* cache;
>>   explicit LSubKindOperand(int index);
>> };
>>
>>
>>
>> On Tue, Apr 19, 2016 at 2:19 AM, Serge Pavlov via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: sepavloff
>>> Date: Tue Apr 19 01:19:52 2016
>>> New Revision: 266719
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=266719=rev
>>> Log:
>>> Warn if function or variable cannot be implicitly instantiated
>>>
>>> With this patch compiler emits warning if it tries to make implicit
>>> instantiation
>>> of a template but cannot find the template definition. The warning can
>>> be suppressed
>>> by explicit instantiation declaration or by command line options
>>> -Wundefined-var-template and -Wundefined-func-template. The
>>> implementation follows
>>> the discussion of http://reviews.llvm.org/D12326.
>>>
>>> Differential Revision: http://reviews.llvm.org/D16396
>>>
>>> Added:
>>> cfe/trunk/test/SemaTemplate/undefined-template.cpp
>>> Modified:
>>> cfe/trunk/include/clang/AST/DeclBase.h
>>> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> cfe/trunk/include/clang/Sema/Sema.h
>>> cfe/trunk/lib/AST/DeclBase.cpp
>>> cfe/trunk/lib/Sema/SemaOverload.cpp
>>> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>>> cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p1.cpp
>>> cfe/trunk/test/OpenMP/parallel_ast_print.cpp
>>> cfe/trunk/test/OpenMP/parallel_sections_ast_print.cpp
>>> cfe/trunk/test/OpenMP/target_parallel_ast_print.cpp
>>> cfe/trunk/test/OpenMP/task_ast_print.cpp
>>> cfe/trunk/test/OpenMP/teams_ast_print.cpp
>>> cfe/trunk/test/OpenMP/threadprivate_ast_print.cpp
>>> cfe/trunk/test/SemaCXX/PR10177.cpp
>>> cfe/trunk/test/SemaCXX/undefined-internal.cpp
>>>
>>> Modified: cfe/trunk/include/clang/AST/DeclBase.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=266719=266718=266719=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/AST/DeclBase.h (original)
>>> +++ cfe/trunk/include/clang/AST/DeclBase.h Tue Apr 19 01:19:52 2016
>>> @@ -52,6 +52,7 @@ struct PrintingPolicy;
>>>  class RecordDecl;
>>>  class Stmt;
>>>  class StoredDeclsMap;
>>> +class TemplateDecl;
>>>  class TranslationUnitDecl;
>>>  class UsingDirectiveDecl;
>>>  }
>>> @@ -905,6 +906,10 @@ public:
>>> DeclKind == FunctionTemplate;
>>>}
>>>
>>> +  /// \brief If this is a declaration that describes some template, this
>>> +  /// method returns that template declaration.
>>> +  TemplateDecl *getDescribedTemplate() const;
>>> +
>>>/// \brief Returns the function itself, or the templated function if
>>> this 

Re: [libunwind] r266926 - unwind: unify the definition of _LIBUNWIND_SUPPORT_FRAME_APIS

2016-04-20 Thread Richard Smith via cfe-commits
On Wed, Apr 20, 2016 at 3:31 PM, Richard Smith 
wrote:

> On Wed, Apr 20, 2016 at 3:18 PM, Saleem Abdulrasool via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: compnerd
>> Date: Wed Apr 20 17:18:47 2016
>> New Revision: 266926
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=266926=rev
>> Log:
>> unwind: unify the definition of _LIBUNWIND_SUPPORT_FRAME_APIS
>>
>> Unify the definition of the _LIBUNWIND_SUPPORT_FRAME_APIS macro.  This is
>> in
>> preparation to remove another instance of -Wexpansion-to-defined.  NFC.
>>
>> Modified:
>> libunwind/trunk/src/config.h
>>
>> Modified: libunwind/trunk/src/config.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=266926=266925=266926=diff
>>
>> ==
>> --- libunwind/trunk/src/config.h (original)
>> +++ libunwind/trunk/src/config.h Wed Apr 20 17:18:47 2016
>> @@ -40,8 +40,6 @@
>>#endif
>>
>>#define _LIBUNWIND_BUILD_SJLJ_APIS  defined(__arm__)
>> -  #define _LIBUNWIND_SUPPORT_FRAME_APIS   (defined(__i386__) || \
>> -   defined(__x86_64__))
>>#define _LIBUNWIND_EXPORT
>>  __attribute__((visibility("default")))
>>#define _LIBUNWIND_HIDDEN
>>  __attribute__((visibility("hidden")))
>>#define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg,
>> __VA_ARGS__)
>> @@ -68,8 +66,6 @@
>>}
>>
>>#define _LIBUNWIND_BUILD_SJLJ_APIS  0
>> -  #define _LIBUNWIND_SUPPORT_FRAME_APIS   (defined(__i386__) || \
>> -   defined(__x86_64__))
>>#define _LIBUNWIND_EXPORT
>>  __attribute__((visibility("default")))
>>#define _LIBUNWIND_HIDDEN
>>  __attribute__((visibility("hidden")))
>>#define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg,
>> __VA_ARGS__)
>> @@ -86,6 +82,8 @@
>>#endif
>>  #endif
>>
>> +#define _LIBUNWIND_SUPPORT_FRAME_APIS (defined(__i386__) ||
>> defined(__x86_64__))
>>
>
> Producing a 'defined' token by macro expansion isn't required to work
> (Clang will warn on it; some compilers won't handle it as a 'defined'
> operator at all). Instead, this should be defined by
>
> #if defined(__i386) || defined(__x86_64__)
> #define _LIBUNWIND_SUPPORT_FRAME_APIS 1
> #endif
>
> or similar.
>

Ha, and your commit message clearly points out that this was a step towards
fixing this issue I described. Sorry for the noise! :)


> +
>>  #if defined(__i386__) || defined(__x86_64__) ||
>>   \
>>  (!defined(__APPLE__) && defined(__arm__)) ||
>>\
>>  (defined(__arm64__) || defined(__aarch64__)) ||
>>   \
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libunwind] r266926 - unwind: unify the definition of _LIBUNWIND_SUPPORT_FRAME_APIS

2016-04-20 Thread Richard Smith via cfe-commits
On Wed, Apr 20, 2016 at 3:18 PM, Saleem Abdulrasool via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: compnerd
> Date: Wed Apr 20 17:18:47 2016
> New Revision: 266926
>
> URL: http://llvm.org/viewvc/llvm-project?rev=266926=rev
> Log:
> unwind: unify the definition of _LIBUNWIND_SUPPORT_FRAME_APIS
>
> Unify the definition of the _LIBUNWIND_SUPPORT_FRAME_APIS macro.  This is
> in
> preparation to remove another instance of -Wexpansion-to-defined.  NFC.
>
> Modified:
> libunwind/trunk/src/config.h
>
> Modified: libunwind/trunk/src/config.h
> URL:
> http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=266926=266925=266926=diff
>
> ==
> --- libunwind/trunk/src/config.h (original)
> +++ libunwind/trunk/src/config.h Wed Apr 20 17:18:47 2016
> @@ -40,8 +40,6 @@
>#endif
>
>#define _LIBUNWIND_BUILD_SJLJ_APIS  defined(__arm__)
> -  #define _LIBUNWIND_SUPPORT_FRAME_APIS   (defined(__i386__) || \
> -   defined(__x86_64__))
>#define _LIBUNWIND_EXPORT
>  __attribute__((visibility("default")))
>#define _LIBUNWIND_HIDDEN
>  __attribute__((visibility("hidden")))
>#define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg,
> __VA_ARGS__)
> @@ -68,8 +66,6 @@
>}
>
>#define _LIBUNWIND_BUILD_SJLJ_APIS  0
> -  #define _LIBUNWIND_SUPPORT_FRAME_APIS   (defined(__i386__) || \
> -   defined(__x86_64__))
>#define _LIBUNWIND_EXPORT
>  __attribute__((visibility("default")))
>#define _LIBUNWIND_HIDDEN
>  __attribute__((visibility("hidden")))
>#define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg,
> __VA_ARGS__)
> @@ -86,6 +82,8 @@
>#endif
>  #endif
>
> +#define _LIBUNWIND_SUPPORT_FRAME_APIS (defined(__i386__) ||
> defined(__x86_64__))
>

Producing a 'defined' token by macro expansion isn't required to work
(Clang will warn on it; some compilers won't handle it as a 'defined'
operator at all). Instead, this should be defined by

#if defined(__i386) || defined(__x86_64__)
#define _LIBUNWIND_SUPPORT_FRAME_APIS 1
#endif

or similar.


> +
>  #if defined(__i386__) || defined(__x86_64__) ||
>   \
>  (!defined(__APPLE__) && defined(__arm__)) ||
>  \
>  (defined(__arm64__) || defined(__aarch64__)) ||
>   \
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] r266927 - unwind: remove another instance of -Wexpansion-to-defined

2016-04-20 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Wed Apr 20 17:18:50 2016
New Revision: 266927

URL: http://llvm.org/viewvc/llvm-project?rev=266927=rev
Log:
unwind: remove another instance of -Wexpansion-to-defined

Remove the use of undefined behaviour in the c preprocessor by always defining
the value according to the state that was being checked.  NFC.

Modified:
libunwind/trunk/src/config.h

Modified: libunwind/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=266927=266926=266927=diff
==
--- libunwind/trunk/src/config.h (original)
+++ libunwind/trunk/src/config.h Wed Apr 20 17:18:50 2016
@@ -82,7 +82,11 @@
   #endif
 #endif
 
-#define _LIBUNWIND_SUPPORT_FRAME_APIS (defined(__i386__) || 
defined(__x86_64__))
+#if defined(__i386__) || defined(__x86_64__)
+#define _LIBUNWIND_SUPPORT_FRAME_APIS 1
+#else
+#define _LIBUNWIND_SUPPORT_FRAME_APIS 0
+#endif
 
 #if defined(__i386__) || defined(__x86_64__) ||
\
 (!defined(__APPLE__) && defined(__arm__)) ||   
\


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


[libunwind] r266926 - unwind: unify the definition of _LIBUNWIND_SUPPORT_FRAME_APIS

2016-04-20 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Wed Apr 20 17:18:47 2016
New Revision: 266926

URL: http://llvm.org/viewvc/llvm-project?rev=266926=rev
Log:
unwind: unify the definition of _LIBUNWIND_SUPPORT_FRAME_APIS

Unify the definition of the _LIBUNWIND_SUPPORT_FRAME_APIS macro.  This is in
preparation to remove another instance of -Wexpansion-to-defined.  NFC.

Modified:
libunwind/trunk/src/config.h

Modified: libunwind/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=266926=266925=266926=diff
==
--- libunwind/trunk/src/config.h (original)
+++ libunwind/trunk/src/config.h Wed Apr 20 17:18:47 2016
@@ -40,8 +40,6 @@
   #endif
 
   #define _LIBUNWIND_BUILD_SJLJ_APIS  defined(__arm__)
-  #define _LIBUNWIND_SUPPORT_FRAME_APIS   (defined(__i386__) || \
-   defined(__x86_64__))
   #define _LIBUNWIND_EXPORT   
__attribute__((visibility("default")))
   #define _LIBUNWIND_HIDDEN   __attribute__((visibility("hidden")))
   #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, 
__VA_ARGS__)
@@ -68,8 +66,6 @@
   }
 
   #define _LIBUNWIND_BUILD_SJLJ_APIS  0
-  #define _LIBUNWIND_SUPPORT_FRAME_APIS   (defined(__i386__) || \
-   defined(__x86_64__))
   #define _LIBUNWIND_EXPORT   
__attribute__((visibility("default")))
   #define _LIBUNWIND_HIDDEN   __attribute__((visibility("hidden")))
   #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, 
__VA_ARGS__)
@@ -86,6 +82,8 @@
   #endif
 #endif
 
+#define _LIBUNWIND_SUPPORT_FRAME_APIS (defined(__i386__) || 
defined(__x86_64__))
+
 #if defined(__i386__) || defined(__x86_64__) ||
\
 (!defined(__APPLE__) && defined(__arm__)) ||   
\
 (defined(__arm64__) || defined(__aarch64__)) ||
\


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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread Rong Xu via cfe-commits
xur added a comment.

the reason for splitting the check is we don't need this check at all in
llvm instrument,-- as it's done per function. but I guess it does not
matter much to move it in to create -- it's only called once per function.


http://reviews.llvm.org/D18624



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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread Rong Xu via cfe-commits
the reason for splitting the check is we don't need this check at all in
llvm instrument,-- as it's done per function. but I guess it does not
matter much to move it in to create -- it's only called once per function.





On Wed, Apr 20, 2016 at 3:04 PM, David Li  wrote:

> davidxl added inline comments.
>
> 
> Comment at: lib/CodeGen/CodeGenPGO.cpp:47
> @@ +46,3 @@
> +  // Create PGOFuncName meta data.
> +  if (!llvm::getPGOFuncNameMetadata(*Fn))
> +llvm::createPGOFuncNameMetadata(*Fn);
> 
> This check be folded into the creator. The creator interface name also
> needs to be changed properly (created when needed)
>
>
> http://reviews.llvm.org/D18624
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18652: [Inline asm] Correctly parse GCC-style asm line following MS-style asm line

2016-04-20 Thread Denis Zobnin via cfe-commits
d.zobnin.bugzilla added a comment.

Richard, Eric,

Please take a look at the patch.

Thank you,
Denis Zobnin


http://reviews.llvm.org/D18652



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


Re: [PATCH] D19253: [Tooling] Fix getting fully qualified names of template alias types.

2016-04-20 Thread Chaoren Lin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266925: [Tooling] Fix getting fully qualified names of 
template alias types. (authored by chaoren).

Changed prior to commit:
  http://reviews.llvm.org/D19253?vs=54225=54435#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19253

Files:
  cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
  cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp

Index: cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
===
--- cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
+++ cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
@@ -304,6 +304,8 @@
 Decl = TDT->getDecl();
   } else if (const auto *TagDeclType = dyn_cast(TypePtr)) {
 Decl = TagDeclType->getDecl();
+  } else if (const auto *TST = dyn_cast(TypePtr)) {
+Decl = TST->getTemplateName().getAsTemplateDecl();
   } else {
 Decl = TypePtr->getAsCXXRecordDecl();
   }
Index: cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
===
--- cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
+++ cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
@@ -87,13 +87,19 @@
   Visitor.ExpectedQualTypeNames["non_dependent_type_var"] =
   "Foo::non_dependent_type";
   Visitor.ExpectedQualTypeNames["AnEnumVar"] = "EnumScopeClass::AnEnum";
+  Visitor.ExpectedQualTypeNames["AliasTypeVal"] = "A::B::C::InnerAlias";
   Visitor.runOver(
   "int CheckInt;\n"
+  "template \n"
+  "class OuterTemplateClass { };\n"
   "namespace A {\n"
   " namespace B {\n"
   "   class Class0 { };\n"
   "   namespace C {\n"
   " typedef int MyInt;"
+  " template \n"
+  " using InnerAlias = OuterTemplateClass;\n"
+  " InnerAlias AliasTypeVal;\n"
   "   }\n"
   "   template class Template0;"
   "   template class Template1;"
@@ -148,7 +154,8 @@
   "public:\n"
   "  enum AnEnum { ZERO, ONE };\n"
   "};\n"
-  "EnumScopeClass::AnEnum AnEnumVar;\n"
+  "EnumScopeClass::AnEnum AnEnumVar;\n",
+  TypeNameVisitor::Lang_CXX11
 );
 
   TypeNameVisitor Complex;


Index: cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
===
--- cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
+++ cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
@@ -304,6 +304,8 @@
 Decl = TDT->getDecl();
   } else if (const auto *TagDeclType = dyn_cast(TypePtr)) {
 Decl = TagDeclType->getDecl();
+  } else if (const auto *TST = dyn_cast(TypePtr)) {
+Decl = TST->getTemplateName().getAsTemplateDecl();
   } else {
 Decl = TypePtr->getAsCXXRecordDecl();
   }
Index: cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
===
--- cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
+++ cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
@@ -87,13 +87,19 @@
   Visitor.ExpectedQualTypeNames["non_dependent_type_var"] =
   "Foo::non_dependent_type";
   Visitor.ExpectedQualTypeNames["AnEnumVar"] = "EnumScopeClass::AnEnum";
+  Visitor.ExpectedQualTypeNames["AliasTypeVal"] = "A::B::C::InnerAlias";
   Visitor.runOver(
   "int CheckInt;\n"
+  "template \n"
+  "class OuterTemplateClass { };\n"
   "namespace A {\n"
   " namespace B {\n"
   "   class Class0 { };\n"
   "   namespace C {\n"
   " typedef int MyInt;"
+  " template \n"
+  " using InnerAlias = OuterTemplateClass;\n"
+  " InnerAlias AliasTypeVal;\n"
   "   }\n"
   "   template class Template0;"
   "   template class Template1;"
@@ -148,7 +154,8 @@
   "public:\n"
   "  enum AnEnum { ZERO, ONE };\n"
   "};\n"
-  "EnumScopeClass::AnEnum AnEnumVar;\n"
+  "EnumScopeClass::AnEnum AnEnumVar;\n",
+  TypeNameVisitor::Lang_CXX11
 );
 
   TypeNameVisitor Complex;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18953: [ms][dll] #26935 Defining a dllimport function should cause it to be exported

2016-04-20 Thread Richard Smith via cfe-commits
rsmith added a comment.

In http://reviews.llvm.org/D18953#397279, @rnk wrote:

> Richard, do you think we should be handling this by rewriting the AST-level 
> attribute in Sema or by changing our interpretation of things in CodeGen? 
> We're already creating a bunch of implicit attributes to implement 
> class-level import/export.


Sorry, I forgot to answer this directly. I'm fine with either approach; they 
both seem to preserve source fidelity and allow AST clients to figure out 
what's going on without too much complexity.


http://reviews.llvm.org/D18953



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


r266925 - [Tooling] Fix getting fully qualified names of template alias types.

2016-04-20 Thread Chaoren Lin via cfe-commits
Author: chaoren
Date: Wed Apr 20 17:12:07 2016
New Revision: 266925

URL: http://llvm.org/viewvc/llvm-project?rev=266925=rev
Log:
[Tooling] Fix getting fully qualified names of template alias types.

Reviewers: rsmith, rnk

Subscribers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D19253

Modified:
cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp

Modified: cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp?rev=266925=266924=266925=diff
==
--- cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp (original)
+++ cfe/trunk/lib/Tooling/Core/QualTypeNames.cpp Wed Apr 20 17:12:07 2016
@@ -304,6 +304,8 @@ static NestedNameSpecifier *createNested
 Decl = TDT->getDecl();
   } else if (const auto *TagDeclType = dyn_cast(TypePtr)) {
 Decl = TagDeclType->getDecl();
+  } else if (const auto *TST = dyn_cast(TypePtr)) {
+Decl = TST->getTemplateName().getAsTemplateDecl();
   } else {
 Decl = TypePtr->getAsCXXRecordDecl();
   }

Modified: cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp?rev=266925=266924=266925=diff
==
--- cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp Wed Apr 20 17:12:07 2016
@@ -87,13 +87,19 @@ TEST(QualTypeNameTest, getFullyQualified
   Visitor.ExpectedQualTypeNames["non_dependent_type_var"] =
   "Foo::non_dependent_type";
   Visitor.ExpectedQualTypeNames["AnEnumVar"] = "EnumScopeClass::AnEnum";
+  Visitor.ExpectedQualTypeNames["AliasTypeVal"] = "A::B::C::InnerAlias";
   Visitor.runOver(
   "int CheckInt;\n"
+  "template \n"
+  "class OuterTemplateClass { };\n"
   "namespace A {\n"
   " namespace B {\n"
   "   class Class0 { };\n"
   "   namespace C {\n"
   " typedef int MyInt;"
+  " template \n"
+  " using InnerAlias = OuterTemplateClass;\n"
+  " InnerAlias AliasTypeVal;\n"
   "   }\n"
   "   template class Template0;"
   "   template class Template1;"
@@ -148,7 +154,8 @@ TEST(QualTypeNameTest, getFullyQualified
   "public:\n"
   "  enum AnEnum { ZERO, ONE };\n"
   "};\n"
-  "EnumScopeClass::AnEnum AnEnumVar;\n"
+  "EnumScopeClass::AnEnum AnEnumVar;\n",
+  TypeNameVisitor::Lang_CXX11
 );
 
   TypeNameVisitor Complex;


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


r266887 - Add warning about CR+LF line endings on Windows.

2016-04-20 Thread Adrian McCarthy via cfe-commits
Author: amccarth
Date: Wed Apr 20 11:43:34 2016
New Revision: 266887

URL: http://llvm.org/viewvc/llvm-project?rev=266887=rev
Log:
Add warning about CR+LF line endings on Windows.

s/checkout/check out/ when used as a verb.

Differential Revision: http://reviews.llvm.org/D19285

Modified:
cfe/trunk/www/get_started.html

Modified: cfe/trunk/www/get_started.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/get_started.html?rev=266887=266886=266887=diff
==
--- cfe/trunk/www/get_started.html (original)
+++ cfe/trunk/www/get_started.html Wed Apr 20 11:43:34 2016
@@ -47,20 +47,20 @@ follows:
   http://www.cmake.org/download
   
 
-  Checkout LLVM:
+  Check out LLVM:
   
 Change directory to where you want the llvm directory placed.
 svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
   
   
-  Checkout Clang:
+  Check out Clang:
   
 cd llvm/tools
 svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
 cd ../..
   
   
-  Checkout extra Clang Tools: (optional)
+  Check out extra Clang tools: (optional)
   
 cd llvm/tools/clang/tools
 svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk
@@ -68,7 +68,7 @@ follows:
 cd ../../../..
   
   
-  Checkout Compiler-RT (optional):
+  Check out Compiler-RT (optional):
   
 cd llvm/projects
 svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk
@@ -76,7 +76,7 @@ follows:
 cd ../..
   
   
-  Checkout libcxx: (only required to build and run Compiler-RT tests on OS 
X, optional otherwise)
+  Check out libcxx: (only required to build and run Compiler-RT tests on 
OS X, optional otherwise)
   
 cd llvm/projects
 svn co http://llvm.org/svn/llvm-project/libcxx/trunk
@@ -124,13 +124,13 @@ follows:
 checkout is at the same revision as your Clang checkout. LLVM's interfaces
 change over time, and mismatched revisions are not expected to work
 together.
-  
+
 Simultaneously Building Clang and LLVM:
 
 Once you have checked out Clang into the llvm source tree it will build 
along
 with the rest of llvm. To build all of LLVM and Clang together all at
 once simply run make from the root LLVM directory.
-
+
 Note: Observe that Clang is technically part of a separate
 Subversion repository. As mentioned above, the latest Clang sources are tied to
 the latest sources in the LLVM tree. You can update your toplevel LLVM project
@@ -169,16 +169,19 @@ Visual Studio:
   
   
 
-  Checkout LLVM:
+  Check out LLVM:
   
 svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
   
   
-  Checkout Clang:
+  Check out Clang:
   
  cd llvm\tools
  svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
   
+  Note:  Some Clang tests are sensitive to the line endings.  
Ensure
+ that checking out the files does not convert LF line endings to CR+LF.
+ If you use git-svn, make sure your core.autocrlf setting is 
false.
   
   Run CMake to generate the Visual Studio solution and project files:
   


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


Re: [PATCH] D19003: Set C99 as default C Standard for PS4 target

2016-04-20 Thread Paul Robinson via cfe-commits
probinson added a subscriber: probinson.


Comment at: test/Sema/attr-deprecated.c:124
@@ -123,1 +123,3 @@
 
+// This note requires C11.
+#if __STDC_VERSION__ > 199901L

Just the note? Or the warning?


Comment at: test/Sema/nullability.c:30
@@ -25,1 +29,3 @@
 // Conflicting nullability specifiers via a typedef are not.
+// These errors require C11.
+#if __STDC_VERSION__ > 199901L

*Some* of these errors require C11.


Comment at: test/Sema/nullability.c:81
@@ -71,1 +80,3 @@
 typedef int * _Nonnull ambiguous_int_ptr;
+// These errors require C11.
+#if __STDC_VERSION__ > 199901L

Not seeing any errors here?


Comment at: test/SemaObjC/objcbridge-attribute-arc.m:26
@@ -25,2 +25,3 @@
 
-typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; 
// expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used 
on a typedef}}
+// This note requires C11.
+#if __STDC_VERSION__ > 199901L

This *error* requires C11.


http://reviews.llvm.org/D19003



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


Re: [PATCH] D19331: [Clang-tidy] Fix for crash in modernize-raw-string-literal check

2016-04-20 Thread Marek via cfe-commits
edyp87 marked an inline comment as done.
edyp87 added a comment.

1. Extended diff has been generated - sorry, I am new to Phabricator.
2. AST for this case looks like this:

> AST for crashing case:

> 

>   -VarDecl 0x2b27370  col:19 function 'const char *const' 
> callinit

>`-ImplicitCastExpr 0x2b274c0  'const char *' 

>  `-PredefinedExpr 0x2b27470  'const char [1]' lvalue __FUNCTION__

>`-StringLiteral 0x2b27448  'const char [1]' lvalue ""

> 

> Valid case:

> 

>   -VarDecl 0x2b26660  col:19 HexPrintable 'const char 
> *const' callinit

>`-ImplicitCastExpr 0x2b26718  'const char *' 

>  `-StringLiteral 0x2b266b8  'const char [3]' lvalue "@\\"


For `StringExpr` whose parent is `PredefinedExpr` `Lexer::getSourceText` 
returns this expr literally (`__FUNCTION__`) instead of evaluated function 
name. 
I was wondering whether there is another case which results in such assert 
(lack of quote in string) but I could not came with an idea of such scenario.
Another approach would be just returning from `check()` method while evaluating 
"quote-less" string but I thought that it would be less elegant.


http://reviews.llvm.org/D19331



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


Re: [PATCH] D19299: lower __builtin_expect() directly to prof metadata instead of LLVM intrinsic

2016-04-20 Thread Amaury SECHET via cfe-commits
deadalnix added a comment.

In http://reviews.llvm.org/D19299#406517, @spatel wrote:

> Rereading your question, I'm now wondering if you are asking if we can get 
> rid of the source level builtin_unpredictable() ? I had not considered that, 
> but I think that is also possible if we add a flag to builtin_expect() to 
> mean 'this branch is unpredictable'.
>
> Please let me know if I answered the correct question. :)


You did answer my question. I don't really mind source level intrinsic, I'm 
more concerned about the IR and how they are lowered. Overall I like where this 
is going. It looks like @davidxl is on it for the review, and he seems to have 
a good idea of where this should go, so I'll defer to him for acceptance/change 
requests.


http://reviews.llvm.org/D19299



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


Re: [PATCH] D19331: [Clang-tidy] Fix for crash in modernize-raw-string-literal check

2016-04-20 Thread Marek via cfe-commits
edyp87 removed rL LLVM as the repository for this revision.
edyp87 updated this revision to Diff 54401.
edyp87 added a comment.

Extended diff range + removed unnecessary variable.


http://reviews.llvm.org/D19331

Files:
  clang-tidy/modernize/RawStringLiteralCheck.cpp
  test/clang-tidy/modernize-raw-string-literal.cpp

Index: test/clang-tidy/modernize-raw-string-literal.cpp
===
--- test/clang-tidy/modernize-raw-string-literal.cpp
+++ test/clang-tidy/modernize-raw-string-literal.cpp
@@ -91,6 +91,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw 
string literal
 // CHECK-FIXES: {{^}}char const *const HexPrintable(R"(@\)");{{$}}
 
+char const *const prettyFunction(__PRETTY_FUNCTION__);
+char const *const function(__FUNCTION__);
+char const *const func(__func__);
+
 #define TRICK(arg_) #arg_
 char const *const MacroBody = TRICK(foo\\bar);
 
Index: clang-tidy/modernize/RawStringLiteralCheck.cpp
===
--- clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -108,7 +108,10 @@
 }
 
 void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(stringLiteral().bind("lit"), this);
+
+  Finder->addMatcher(
+  stringLiteral(unless(hasParent(predefinedExpr(.bind("lit"),
+  this);
 }
 
 void RawStringLiteralCheck::check(const MatchFinder::MatchResult ) {


Index: test/clang-tidy/modernize-raw-string-literal.cpp
===
--- test/clang-tidy/modernize-raw-string-literal.cpp
+++ test/clang-tidy/modernize-raw-string-literal.cpp
@@ -91,6 +91,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal
 // CHECK-FIXES: {{^}}char const *const HexPrintable(R"(@\)");{{$}}
 
+char const *const prettyFunction(__PRETTY_FUNCTION__);
+char const *const function(__FUNCTION__);
+char const *const func(__func__);
+
 #define TRICK(arg_) #arg_
 char const *const MacroBody = TRICK(foo\\bar);
 
Index: clang-tidy/modernize/RawStringLiteralCheck.cpp
===
--- clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -108,7 +108,10 @@
 }
 
 void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(stringLiteral().bind("lit"), this);
+
+  Finder->addMatcher(
+  stringLiteral(unless(hasParent(predefinedExpr(.bind("lit"),
+  this);
 }
 
 void RawStringLiteralCheck::check(const MatchFinder::MatchResult ) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18823: Implementation of VlA of GNU C++ extension

2016-04-20 Thread Vladimir Yakovlev via cfe-commits
vbyakovl added a comment.

Richard, now my changes are good for you?


http://reviews.llvm.org/D18823



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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread David Li via cfe-commits
davidxl added inline comments.


Comment at: lib/CodeGen/CodeGenPGO.cpp:47
@@ +46,3 @@
+  // Create PGOFuncName meta data.
+  if (!llvm::getPGOFuncNameMetadata(*Fn))
+llvm::createPGOFuncNameMetadata(*Fn);

This check be folded into the creator. The creator interface name also needs to 
be changed properly (created when needed)


http://reviews.llvm.org/D18624



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


Re: [PATCH] D19331: [Clang-tidy] Fix for crash in modernize-raw-string-literal check

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

Thank you for the explanation! The change looks good now. Do you need me to 
submit the patch for you?

As for other cases that can lead to this, it might be possible to achieve the 
same effect using macros. However, we could address this in a separate patch.


http://reviews.llvm.org/D19331



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


Re: [PATCH] D19299: lower __builtin_expect() directly to prof metadata instead of LLVM intrinsic

2016-04-20 Thread Sanjay Patel via cfe-commits
spatel updated this revision to Diff 54423.
spatel added a comment.

Patch updated:

1. Fixed/removed comments
2. Changed likely/unlikely profile weights to be min/max values. I'm not sure 
why 4 and 64 were used in LowerExpectIntrinsics, but that may not trigger the 
programmer's intent with builtin_expect().


http://reviews.llvm.org/D19299

Files:
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CodeGenFunction.cpp
  test/CodeGen/builtin-expect.c

Index: test/CodeGen/builtin-expect.c
===
--- test/CodeGen/builtin-expect.c
+++ test/CodeGen/builtin-expect.c
@@ -1,13 +1,15 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O1 -disable-llvm-optzns | FileCheck %s --check-prefix=ALL --check-prefix=O1
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O0 | FileCheck %s --check-prefix=ALL --check-prefix=O0
 
-// In all tests, make sure that no expect is generated if optimizations are off.
-// If optimizations are on, generate the correct expect and preserve other necessary operations.
+// In all tests, make sure that the builtin is gone.
+// If optimizations are on, generate the correct expect metadata and preserve other necessary operations.
+// If optimizations are off, no expect metadata is generated but other operations should be preserved.
 
 int expect_taken(int x) {
 // ALL-LABEL: define i32 @expect_taken
-// O1:call i64 @llvm.expect.i64(i64 {{%.*}}, i64 1)
-// O0-NOT:@llvm.expect
+// ALL-NOT:   builtin_expect
+// O1:!prof [[BR_TRUE_METADATA:.+]]
+// O0-NOT:!prof
 
   if (__builtin_expect (x, 1))
 return 0;
@@ -17,8 +19,9 @@
 
 int expect_not_taken(int x) {
 // ALL-LABEL: define i32 @expect_not_taken
-// O1:call i64 @llvm.expect.i64(i64 {{%.*}}, i64 0)
-// O0-NOT:@llvm.expect
+// ALL-NOT:   builtin_expect
+// O1:!prof [[BR_FALSE_METADATA:.+]]
+// O0-NOT:!prof
 
   if (__builtin_expect (x, 0))
 return 0;
@@ -33,9 +36,10 @@
 void expect_value_side_effects() {
 // ALL-LABEL: define void @expect_value_side_effects()
 // ALL:   [[CALL:%.*]] = call i32 @y
+// ALL-NOT:   builtin_expect
 // O1:[[SEXT:%.*]] = sext i32 [[CALL]] to i64
-// O1:call i64 @llvm.expect.i64(i64 {{%.*}}, i64 [[SEXT]])
-// O0-NOT:@llvm.expect
+// O1:!prof [[BR_TRUE_METADATA:.+]]
+// O0-NOT:!prof
 
   if (__builtin_expect (x, y()))
 foo ();
@@ -52,17 +56,18 @@
 // ALL-LABEL: define i32 @main()
 // ALL:   call void @isigprocmask()
 // ALL:   [[CALL:%.*]] = call i64 (...) @bar()
-// O1:call i64 @llvm.expect.i64(i64 0, i64 [[CALL]])
-// O0-NOT:@llvm.expect
+// ALL-NOT:   builtin_expect
+// ALL-NOT:   !prof
 
   (void) __builtin_expect((isigprocmask(), 0), bar());
 }
 
 
 int switch_cond(int x) {
 // ALL-LABEL: define i32 @switch_cond
-// O1:call i64 @llvm.expect.i64(i64 {{%.*}}, i64 5)
-// O0-NOT:@llvm.expect
+// ALL-NOT:   builtin_expect
+// O1:!prof [[SWITCH_METADATA:.+]]
+// O0-NOT:!prof
 
   switch(__builtin_expect(x, 5)) {
   default:
@@ -78,3 +83,7 @@
   return 0;
 }
 
+// O1: [[BR_TRUE_METADATA]] = !{!"branch_weights", i32 -1, i32 0}
+// O1: [[BR_FALSE_METADATA]] = !{!"branch_weights", i32 0, i32 -1}
+// O1: [[SWITCH_METADATA]] = !{!"branch_weights", i32 0, i32 0, i32 0, i32 0, i32 -1}
+
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1309,24 +1309,45 @@
 return;
   }
 
-  // If the branch has a condition wrapped by __builtin_unpredictable,
-  // create metadata that specifies that the branch is unpredictable.
-  // Don't bother if not optimizing because that metadata would not be used.
   llvm::MDNode *Unpredictable = nullptr;
+  llvm::MDNode *Weights = nullptr;
   auto *Call = dyn_cast(Cond);
+
+  // If the branch has a condition wrapped by __builtin_unpredictable,
+  // create metadata that specifies that the branch is unpredictable.
+  //
+  // If the branch has a condition wrapped by __builtin_expect, create
+  // metadata that sets the profile weights to the extreme values.
+  //
+  // But don't add performance metadata if not optimizing because that metadata
+  // would not be used anyway.
   if (Call && CGM.getCodeGenOpts().OptimizationLevel != 0) {
-auto *FD = dyn_cast_or_null(Call->getCalleeDecl());
-if (FD && FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
+if (auto *FD = dyn_cast_or_null(Call->getCalleeDecl())) {
   llvm::MDBuilder MDHelper(getLLVMContext());
-  Unpredictable = MDHelper.createUnpredictable();
+  if (FD->getBuiltinID() == Builtin::BI__builtin_unpredictable) {
+Unpredictable = MDHelper.createUnpredictable();
+  } else if (FD->getBuiltinID() == Builtin::BI__builtin_expect) {
+const int LikelyWeight = ~0;
+const int UnlikelyWeight = 0;
+
+

Re: [PATCH] D19299: lower __builtin_expect() directly to prof metadata instead of LLVM intrinsic

2016-04-20 Thread Sanjay Patel via cfe-commits
spatel marked 4 inline comments as done.


Comment at: lib/CodeGen/CGBuiltin.cpp:636
@@ -640,1 +635,3 @@
+  case Builtin::BI__builtin_unpredictable:
   case Builtin::BI__builtin_expect: {
+// Always return the first argument. LLVM does not handle these builtins.

davidxl wrote:
> Can this be reordered with unpredicatle case so that it can handle arg 1 and 
> fall through?
I had coded it that way initially, but I think we must emit the expression for 
arg0 *before* the expression for arg1.

The ordering is checked by the 'main()' test in the regression test file. If 
you see a way to code around that, please let me know.



http://reviews.llvm.org/D19299



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


[libunwind] r266915 - unwind: remove an instance of -Wexpansion-to-defined

2016-04-20 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Wed Apr 20 15:54:51 2016
New Revision: 266915

URL: http://llvm.org/viewvc/llvm-project?rev=266915=rev
Log:
unwind: remove an instance of -Wexpansion-to-defined

This follows the pattern in the Apple clause duplicating a tuple of definitions.
However, it will define them to a value rather than a defined check to remove
the `-Wexpansion-to-defined` warning (which may be treated as an error).

This also opens the door to unifying the two code paths into one.

NFC.

Modified:
libunwind/trunk/src/config.h

Modified: libunwind/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=266915=266914=266915=diff
==
--- libunwind/trunk/src/config.h (original)
+++ libunwind/trunk/src/config.h Wed Apr 20 15:54:51 2016
@@ -75,10 +75,15 @@
   #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, 
__VA_ARGS__)
   #define _LIBUNWIND_ABORT(msg) assert_rtn(__func__, __FILE__, __LINE__, msg)
 
-  #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
-  #define _LIBUNWIND_SUPPORT_DWARF_UNWIND !defined(__arm__) || \
-  defined(__ARM_DWARF_EH__)
-  #define _LIBUNWIND_SUPPORT_DWARF_INDEX _LIBUNWIND_SUPPORT_DWARF_UNWIND
+  #if defined(__ARM_DWARF_EH__) || !defined(__arm__)
+#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
+#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 1
+#define _LIBUNWIND_SUPPORT_DWARF_INDEX 1
+  #else
+#define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
+#define _LIBUNWIND_SUPPORT_DWARF_UNWIND 0
+#define _LIBUNWIND_SUPPORT_DWARF_INDEX 0
+  #endif
 #endif
 
 #define _LIBUNWIND_BUILD_ZERO_COST_APIS
\


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


[libunwind] r266916 - unwind: remove a second instance of -Wexpansion-to-defined

2016-04-20 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Wed Apr 20 15:54:55 2016
New Revision: 266916

URL: http://llvm.org/viewvc/llvm-project?rev=266916=rev
Log:
unwind: remove a second instance of -Wexpansion-to-defined

Remove the use of undefined behaviour in the c preprocessor by always defining
the value according to the state that was being checked.  NFC.

Modified:
libunwind/trunk/src/config.h

Modified: libunwind/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=266916=266915=266916=diff
==
--- libunwind/trunk/src/config.h (original)
+++ libunwind/trunk/src/config.h Wed Apr 20 15:54:55 2016
@@ -86,11 +86,14 @@
   #endif
 #endif
 
-#define _LIBUNWIND_BUILD_ZERO_COST_APIS
\
-  (defined(__i386__) || defined(__x86_64__) || 
\
-   (!defined(__APPLE__) && defined(__arm__)) ||
\
-   (defined(__arm64__) || defined(__aarch64__)) || 
\
-   (defined(__APPLE__) && defined(__mips__)))
+#if defined(__i386__) || defined(__x86_64__) ||
\
+(!defined(__APPLE__) && defined(__arm__)) ||   
\
+(defined(__arm64__) || defined(__aarch64__)) ||
\
+(defined(__APPLE__) && defined(__mips__))
+#define _LIBUNWIND_BUILD_ZERO_COST_APIS 1
+#else
+#define _LIBUNWIND_BUILD_ZERO_COST_APIS 0
+#endif
 
 // Macros that define away in non-Debug builds
 #ifdef NDEBUG


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


[libunwind] r266913 - unwind: unify _LIBUNWIND_SUPPORT_DWARF_UNWIND

2016-04-20 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Wed Apr 20 15:53:40 2016
New Revision: 266913

URL: http://llvm.org/viewvc/llvm-project?rev=266913=rev
Log:
unwind: unify _LIBUNWIND_SUPPORT_DWARF_UNWIND

Join the two paths for this macro.  At the end of the day, the difference was
that MIPS and ARM on Apple have different behaviour.  This is a setup change to
remove an instance of -Wexpansion-to-defined.  NFC.

Modified:
libunwind/trunk/src/config.h

Modified: libunwind/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=266913=266912=266913=diff
==
--- libunwind/trunk/src/config.h (original)
+++ libunwind/trunk/src/config.h Wed Apr 20 15:53:40 2016
@@ -39,10 +39,6 @@
 }
   #endif
 
-  #define _LIBUNWIND_BUILD_ZERO_COST_APIS (defined(__i386__) || \
-   defined(__x86_64__) || \
-   defined(__arm64__) || \
-   defined(__mips__))
   #define _LIBUNWIND_BUILD_SJLJ_APIS  defined(__arm__)
   #define _LIBUNWIND_SUPPORT_FRAME_APIS   (defined(__i386__) || \
defined(__x86_64__))
@@ -71,10 +67,6 @@
 abort();
   }
 
-  #define _LIBUNWIND_BUILD_ZERO_COST_APIS (defined(__i386__) || \
-   defined(__x86_64__) || \
-   defined(__arm__) || \
-   defined(__aarch64__))
   #define _LIBUNWIND_BUILD_SJLJ_APIS  0
   #define _LIBUNWIND_SUPPORT_FRAME_APIS   (defined(__i386__) || \
defined(__x86_64__))
@@ -89,6 +81,11 @@
   #define _LIBUNWIND_SUPPORT_DWARF_INDEX _LIBUNWIND_SUPPORT_DWARF_UNWIND
 #endif
 
+#define _LIBUNWIND_BUILD_ZERO_COST_APIS
\
+  (defined(__i386__) || defined(__x86_64__) || 
\
+   (!defined(__APPLE__) && defined(__arm__)) ||
\
+   (defined(__arm64__) || defined(__aarch64__)) || 
\
+   (defined(__APPLE__) && defined(__mips__)))
 
 // Macros that define away in non-Debug builds
 #ifdef NDEBUG


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


Re: [PATCH] D19336: Repair redeclaration chain of friend template functions.

2016-04-20 Thread Richard Smith via cfe-commits
rsmith added a comment.

Sorry, I don't think this approach can work. Consider:

  template struct X {
template friend void f(T);
template friend void f(U);
  };

These two friend declarations declare different friend function templates, but 
this transformation would incorrectly make them have the same type and be 
redeclarations of each other.

I think the right thing here is to just accept that a friend function template 
declared within a class template will not be part of the corresponding 
redeclaration chain. But that's fine, so long as we don't try to inject the 
function template into the surrounding scope -- when we come to instantiate the 
class template, the instantiated friend function template will have the right 
type and will be part of the relevant redeclaration chain.


http://reviews.llvm.org/D19336



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


Re: [PATCH] D19071: [OpenCL] Add predefined macros.

2016-04-20 Thread Yaxun Liu via cfe-commits
yaxunl updated this revision to Diff 54404.
yaxunl added a comment.

Fix test/preprocessor/predefined_macros.c.

Merge test/frontend/std.cl into langstd.c since they are similar.


http://reviews.llvm.org/D19071

Files:
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/InitPreprocessor.cpp
  test/Frontend/std.cl
  test/Frontend/stdlang.c
  test/Preprocessor/predefined-macros.c

Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -146,3 +146,36 @@
 // CHECK-SYNC_CAS_MIPS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
 // CHECK-SYNC_CAS_MIPS32-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
 // CHECK-SYNC_CAS_MIPS64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x cl \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-CL10
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.1 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-CL11
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.2 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-CL12
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-CL20
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-fast-relaxed-math \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-FRM
+// CHECK-CL10: #define CL_VERSION_1_0 100
+// CHECK-CL10: #define CL_VERSION_1_1 110
+// CHECK-CL10: #define CL_VERSION_1_2 120
+// CHECK-CL10: #define CL_VERSION_2_0 200
+// CHECK-CL10: #define __OPENCL_C_VERSION__ 100
+// CHECK-CL11: #define CL_VERSION_1_0 100
+// CHECK-CL11: #define CL_VERSION_1_1 110
+// CHECK-CL11: #define CL_VERSION_1_2 120
+// CHECK-CL11: #define CL_VERSION_2_0 200
+// CHECK-CL11: #define __OPENCL_C_VERSION__ 110
+// CHECK-CL12: #define CL_VERSION_1_0 100
+// CHECK-CL12: #define CL_VERSION_1_1 110
+// CHECK-CL12: #define CL_VERSION_1_2 120
+// CHECK-CL12: #define CL_VERSION_2_0 200
+// CHECK-CL12: #define __OPENCL_C_VERSION__ 120
+// CHECK-CL20: #define CL_VERSION_1_0 100
+// CHECK-CL20: #define CL_VERSION_1_1 110
+// CHECK-CL20: #define CL_VERSION_1_2 120
+// CHECK-CL20: #define CL_VERSION_2_0 200
+// CHECK-CL20: #define __OPENCL_C_VERSION__ 200
+// CHECK-FRM: #define __FAST_RELAXED_MATH__ 1
+
Index: test/Frontend/stdlang.c
===
--- test/Frontend/stdlang.c
+++ test/Frontend/stdlang.c
@@ -1,5 +1,13 @@
-// RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s
-// RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %s
+// RUN: %clang_cc1 -verify -x cuda -std=c++11 -DCUDA %s
+// RUN: %clang_cc1 -verify -x cl -DOPENCL %s
+// RUN: %clang_cc1 -verify -x cl -cl-std=CL -DOPENCL %s
+// RUN: %clang_cc1 -verify -x cl -cl-std=CL1.1 -DOPENCL %s
+// RUN: %clang_cc1 -verify -x cl -cl-std=CL1.2 -DOPENCL %s
+// RUN: %clang_cc1 -verify -x cl -cl-std=CL2.0 -DOPENCL %s
+// RUN: not %clang_cc1 -x cl -std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s
+// RUN: not %clang_cc1 -x cl -cl-std=invalid -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID %s
+// CHECK-C99: error: invalid argument '-std=c99' not allowed with 'OpenCL'
+// CHECK-INVALID: error: invalid value 'invalid' in '-cl-std=invalid'
 // expected-no-diagnostics
 
 #if defined(CUDA)
Index: test/Frontend/std.cl
===
--- test/Frontend/std.cl
+++ /dev/null
@@ -1,9 +0,0 @@
-// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL
-// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.1
-// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.2
-// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL2.0
-// RUN: not %clang_cc1 %s -fsyntax-only -cl-std=invalid -DINVALID 2>&1 | FileCheck %s
-
-#ifdef INVALID 
-// CHECK: invalid value 'invalid' in '-cl-std=invalid'
-#endif
Index: lib/Frontend/InitPreprocessor.cpp
===
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -408,6 +408,39 @@
   if (LangOpts.ObjC1)
 Builder.defineMacro("__OBJC__");
 
+  // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros.
+  if (LangOpts.OpenCL) {
+// OpenCL v1.0 and v1.1 do not have a predefined macro to indicate the
+// language standard with which the program is compiled. __OPENCL_VERSION__
+// is for the OpenCL version supported by the OpenCL device, which is not
+// necessarily the language standard with which the program is compiled.
+// A shared OpenCL header file requires a macro to indicate the language
+// standard. As a workaround, __CLANG_OPENCL_C_VERSION__ is defined for
+// OpenCL v1.0 and v1.1.
+switch (LangOpts.OpenCLVersion) {
+case 100:
+  Builder.defineMacro("__OPENCL_C_VERSION__", "100");
+  break;
+case 110:
+  Builder.defineMacro("__OPENCL_C_VERSION__", "110");
+  break;
+

Re: [PATCH] D19331: [Clang-tidy] Fix for crash in modernize-raw-string-literal check

2016-04-20 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

1. Please generate diffs with full context when sending patches. Use any of the 
methods described in http://llvm.org/docs/Phabricator.html.



Comment at: clang-tidy/modernize/RawStringLiteralCheck.cpp:111
@@ -110,2 +110,3 @@
 void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(stringLiteral().bind("lit"), this);
+  const auto IsNotPredefinedExpr = unless(hasParent(predefinedExpr()));
+

No need in this variable.


Repository:
  rL LLVM

http://reviews.llvm.org/D19331



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


Re: [PATCH] D19331: [Clang-tidy] Fix for crash in modernize-raw-string-literal check

2016-04-20 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

(hit Submit early...)

2. How does AST look for these test cases? I wonder whether there are any 
similar cases not covered by PredefinedExpr.

And thank you for the patch!


Repository:
  rL LLVM

http://reviews.llvm.org/D19331



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


Re: [PATCH] D19048: Test for a module related crash in CGDebugInfo.cpp

2016-04-20 Thread Douglas Yung via cfe-commits
dyung added a comment.

Any thoughts on this test?


http://reviews.llvm.org/D19048



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


Re: [PATCH] D18953: [ms][dll] #26935 Defining a dllimport function should cause it to be exported

2016-04-20 Thread Reid Kleckner via cfe-commits
rnk added a comment.

I think this generally seems right, but we should make sure our behavior is 
more consistent in the case of a template definition.



Comment at: lib/Sema/SemaDecl.cpp:5570-5571
@@ -5565,4 +5569,4 @@
   // exceptions being inline function definitions, local extern declarations,
-  // and qualified friend declarations.
-  // NB: MSVC converts such a declaration to dllexport.
+  // qualified friend declarations or special MSVC extension: in the last case,
+  // the declaration is treated as if it were marked dllexport.
   bool IsInline = false, IsStaticDataMember = false, IsQualifiedFriend = false;

This comment is a run-on, maybe try this:

If a redeclaration drops the dllimport attribute, we usually ignore the 
previous attribute with a warning.
If the redeclaration is an inline definition, a local extern declaration, or a 
qualified friend declaration, we do nothing.
If this declaration is a plain, non-inline definition, then we translate 
dllimport to dllexport and warn the user.


Comment at: lib/Sema/SemaDecl.cpp:5595
@@ +5594,3 @@
+  NewDecl->addAttr(::new (S.Context) DLLExportAttr(
+  NewImportAttr->getRange(), S.Context,
+  NewImportAttr->getSpellingListIndex()));

In CodeGen, when we make decisions about the actual LLVM IR dll storage class, 
we should call Decl::getMostRecentDecl, and look at the attributes on that.

I think we can defer fixing this. You can see instances of the same problem 
below where we drop dllimport from previous declarations. We shouldn't be doing 
that.


Comment at: lib/Sema/SemaDecl.cpp:5600-5602
@@ +5599,5 @@
+ diag::warn_redeclaration_without_attribute_prev_attribute_ignored)
+  << NewDecl << OldImportAttr;
+  S.Diag(OldDecl->getLocation(), diag::note_previous_declaration);
+  S.Diag(OldImportAttr->getLocation(), diag::note_previous_attribute);
+  OldDecl->dropAttr();

Use DLLExportAttr::CreateImplicit or Attr->setImplicit(true).


Comment at: test/Sema/dllimport.c:52
@@ +51,3 @@
+__declspec(dllimport) int GlobalDeclInit; // expected-note{{previous 
declaration is here}}
+#ifdef MS
+// expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' 
attribute: 'dllexport' attribute added}}

We've already got one test for the difference between MSVC and GNU mode. I 
think the rest of these test cases can skip the ifdefs and look for the common 
prefix instead, like this:
  // expected-warning {{'GlobalDeclInit' redeclared without 'dllimport' 
attribute}}


Comment at: test/SemaCXX/dllimport.cpp:62
@@ +61,3 @@
+__declspec(dllimport) int GlobalDeclInit; // expected-note{{previous 
declaration is here}}
+#ifdef MS
+// expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' 
attribute: 'dllexport' attribute added}}

ditto, after the first MS-specific diagnostic test case we don't need the 
duplication


Comment at: test/SemaCXX/dllimport.cpp:179
@@ -140,1 +178,3 @@
+template 
+int ExternVarTmplDeclInit = 1;
 

Can you check with MSVC 2015 update 2 actually does with definitions of 
dllimport variable templates? I bet it doesn't export them.


Comment at: test/SemaCXX/dllimport.cpp:1137
@@ -1017,1 +1136,3 @@
+template 
+void ImportClassTmplMembers::normalDef() {}
 #ifdef GNU

I'm pretty sure MSVC considers all free function templates to be 'inline', i.e. 
they put them in comdats. I doubt MSVC exports these. Can you verify what it 
does?


http://reviews.llvm.org/D18953



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


Re: [PATCH] D19003: Set C99 as default C Standard for PS4 target

2016-04-20 Thread Douglas Yung via cfe-commits
dyung added a comment.

Ping


http://reviews.llvm.org/D19003



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


[PATCH] D19336: Repair redeclaration chain of friend template functions.

2016-04-20 Thread Serge Pavlov via cfe-commits
sepavloff created this revision.
sepavloff added a reviewer: rsmith.
sepavloff added a subscriber: cfe-commits.

When friend template function is parsed, it obtains wrong type. For
instance, in the code:

template void func(T1 *x);
template struct C1 {
template void func(T1 *x);
};

the friend function func gets canonical type 'void (template-param-1-0)',
while type of the same function  declared at file level is
'void (template-param-0-0)'. As a result, these two declarations are not
connected into redeclaration chain.

It occurs because beginning of template friend is parsed in the same way
as a declaration of member template. So template parameters get canonical
types as for a member template. Whether the declaration is a friend or
not can be determined only after declspec is parsed. It is too late, and
use of token look ahead is impractical to determine how parameters should
be handled. Type parameters should be fixed after friend declaration is
seen. They require shift of template parameter depth downward. It the
example above the shift would convert the type 'void (template-param-1-0)'
into 'void (template-param-0-0)'. However this change cannot be made for
all instances of template parameter, because friend function body may use
befriending class parameters as well, after the shift they would have the
same canonical representation as the friend function template parameters.

The fix implements update of canonical representation of friend template
function type. It allows to build up redeclaration chain correctly and
still does not break body of the friend function.

http://reviews.llvm.org/D19336

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaTemplate.cpp
  test/SemaTemplate/friend-template-redecl.cpp

Index: test/SemaTemplate/friend-template-redecl.cpp
===
--- /dev/null
+++ test/SemaTemplate/friend-template-redecl.cpp
@@ -0,0 +1,171 @@
+// RUN: %clang_cc1 -ast-dump -std=c++11 %s | FileCheck %s
+
+
+// Friend function signature does not depend on befriending class
+// template parameters. Such function must be in redeclaration chain.
+//
+namespace N1 {
+// CHECK-LABEL: NamespaceDecl {{.*}} N1
+
+template void func_01(T *x);
+// CHECK: FunctionTemplateDecl [[FWD:0x[0-9a-f]+]]
+// CHECK-NOT: prev
+// CHECK-SAME: func_01
+
+template class C1 {
+// CHECK: ClassTemplateDecl {{.*}} C1
+
+  template friend void func_01(T1 *x);
+  // CHECK: FriendDecl
+  // CHECK-NEXT: FunctionTemplateDecl [[FRIEND:0x[0-9a-f]+]]
+  // CHECK-SAME: prev [[FWD]]
+  // CHECK-SAME: func_01
+};
+
+template void func_01(T1 *x) {}
+// CHECK: FunctionTemplateDecl
+// CHECK-SAME: prev [[FRIEND]]
+// CHECK-SAME: func_01
+
+}
+
+
+// Friend function return type depends on befriending class
+// template parameters. Such function does not participate in
+// redeclaration chain.
+//
+namespace N2 {
+// CHECK-LABEL: NamespaceDecl {{.*}} N2
+
+template T *func_02(T *x);
+// CHECK: FunctionTemplateDecl [[FWD:0x[0-9a-f]+]]
+// CHECK-NOT: prev
+// CHECK-SAME: func_02
+
+template class C2 {
+// CHECK: ClassTemplateDecl {{.*}} C2
+
+  template friend T *func_02(T1 *x);
+  // CHECK: FriendDecl
+  // CHECK-NEXT: FunctionTemplateDecl [[FRIEND:0x[0-9a-f]+]]
+  // CHECK-NOT: prev
+  // CHECK-SAME: func_02
+};
+
+template T1 *func_02(T1 *x) {}
+// CHECK: FunctionTemplateDecl
+// CHECK-SAME: prev [[FWD]]
+// CHECK-SAME: func_02
+
+}
+
+
+// Friend function signature does not depend on befriending class
+// template parameters. Such function must be in redeclaration chain.
+//
+namespace N3 {
+// CHECK-LABEL: NamespaceDecl {{.*}} N3
+
+template void func_01(T x1, T *x2, T , T &);
+// CHECK: FunctionTemplateDecl [[FWD:0x[0-9a-f]+]]
+// CHECK-NOT: prev
+// CHECK-SAME: func_01
+
+template class C1 {
+// CHECK: ClassTemplateDecl {{.*}} C1
+
+  template friend void func_01(T1, T1 *, T1 &, T1 &&);
+  // CHECK: FriendDecl
+  // CHECK-NEXT: FunctionTemplateDecl [[FRIEND:0x[0-9a-f]+]]
+  // CHECK-SAME: prev [[FWD]]
+  // CHECK-SAME: func_01
+};
+
+template void func_01(T1 x1, T1 *x2, T1 , T1 &) {}
+// CHECK: FunctionTemplateDecl
+// CHECK-SAME: prev [[FRIEND]]
+// CHECK-SAME: func_01
+
+}
+ 
+
+namespace N4 {
+// CHECK-LABEL: NamespaceDecl {{.*}} N4
+
+template void func_01(const T *, T *, T&, const T&);
+// CHECK: FunctionTemplateDecl
+// CHECK-SAME: func_01
+template void func_01(T *, const T *, const T&, T&);
+// CHECK: FunctionTemplateDecl [[FWD:0x[0-9a-f]+]]
+// CHECK-NOT: prev
+// CHECK-SAME: func_01
+
+template class C1 {
+// CHECK: ClassTemplateDecl {{.*}} C1
+
+  template friend void func_01(T1 *x1, const T1 *x2, const T1 , T1 );
+  // CHECK: FriendDecl
+  // CHECK-NEXT: FunctionTemplateDecl [[FRIEND:0x[0-9a-f]+]]
+  // CHECK-SAME: prev [[FWD]]
+  // CHECK-SAME: func_01
+};
+
+template void func_01(T1 *x1, const T1 *x2, const T1 , T1 ) {}
+// CHECK: FunctionTemplateDecl
+// CHECK-SAME: prev [[FRIEND]]
+// CHECK-SAME: func_01
+
+}
+
+
+namespace N5 {
+// 

Re: [PATCH] D19324: [ASTMatchers] new forEachOverriden matcher

2016-04-20 Thread Mandeep Singh Grang via cfe-commits
mgrang added a subscriber: mgrang.


Comment at: include/clang/ASTMatchers/ASTMatchers.h:3719
@@ +3718,3 @@
+///   matches twice, once with "b" binding "A1::f" and "d" binding "C::f", and
+///   once with "b" binding "A2::f" and "d" binding "C::f", and
+AST_MATCHER_P(CXXMethodDecl, forEachOverridden,

Extraneous ", and" at the end of comment.


http://reviews.llvm.org/D19324



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


Re: [PATCH] D19299: lower __builtin_expect() directly to prof metadata instead of LLVM intrinsic

2016-04-20 Thread Sanjay Patel via cfe-commits
spatel added inline comments.


Comment at: lib/CodeGen/CGStmt.cpp:1562
@@ +1561,3 @@
+
+// FIXME: builtin_expect should use the same metadata type as
+// builtin_unpredictable and be handled above. For now, we're mimicking

davidxl wrote:
> I am not sure about this. builtin_expect can be used to do general value 
> profiling annotation (single value). For instance,
> 
> if (builtin_expect(a, 20) > 10) {
> }
> 
> should have same effect as
> 
> if (builtin_expect(a > 10), true) {
> 
> }
> 
> The above can be handled by gcc, but not LLVM.
> 
> 
> It can be useful for switch case annotation:
> 
> switch (__builtin_expect(v, 20) ) {
>  case 10: ...
>  case 20: ...
>  ...
> }
> where compiler can do switch peeling.
> 
> Longer term, I am thinking extending builtin_expect to take list of values 
> with probabilities and predicatibiity hint.
Ah, I hadn't considered extending builtin_expect in that way. In that case, it 
does make sense to leave it as-is here and use prof metadata because it's 
already set up for a list of values.

I'll clean up and re-post the patch. Thanks everyone for the reviews!


http://reviews.llvm.org/D19299



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


Re: [PATCH] D19253: [Tooling] Fix getting fully qualified names of template alias types.

2016-04-20 Thread Reid Kleckner via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


http://reviews.llvm.org/D19253



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


Re: [PATCH] D19156: [ms][dll] #27212: Generating of implicit special members should take into account MSVC compatibility version

2016-04-20 Thread Reid Kleckner via cfe-commits
rnk requested changes to this revision.
rnk added a comment.
This revision now requires changes to proceed.

As mentioned twice in https://llvm.org/bugs/show_bug.cgi?id=27212, I don't 
think this is the right direction. To my knowledge, this only causes an ABI 
break when importing a class. I think we should change 
Sema::checkClassLevelDLLAttribute to not apply dllimport to implicit move 
special members instead.


http://reviews.llvm.org/D19156



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


Re: [PATCH] D19312: Warn about UB at member function calls from base class ctor initializers.

2016-04-20 Thread Filipe Cabecinhas via cfe-commits
filcab added a comment.

I meant changing the diff, but if you prefer to have a smaller comment, I'm ok 
with the different "paths" in the standards being mentioned only in the commit 
message.



Comment at: lib/Sema/SemaDeclCXX.cpp:3941
@@ +3940,3 @@
+  // Calling a member function from a ctor-initializer
+  // before the base class results in undefined behavior [12.6.2 16].
+  // FIXME: We only check for member functions directly called from this

For someone reading the source code, it's probably best to mention the 
different "paths" in the standards here too.
For my usual source browsing, as long as it's in the comment *or* the commit 
message, I'll eventually see it. But it might throw some people off when they 
look at C++11, and there's no p16 in that place :-)


http://reviews.llvm.org/D19312



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


Re: [PATCH] D19299: lower __builtin_expect() directly to prof metadata instead of LLVM intrinsic

2016-04-20 Thread David Li via cfe-commits
davidxl added inline comments.


Comment at: lib/CodeGen/CGBuiltin.cpp:636
@@ -640,1 +635,3 @@
+  case Builtin::BI__builtin_unpredictable:
   case Builtin::BI__builtin_expect: {
+// Always return the first argument. LLVM does not handle these builtins.

Can this be reordered with unpredicatle case so that it can handle arg 1 and 
fall through?


Comment at: lib/CodeGen/CGStmt.cpp:1550
@@ -1549,3 +1549,3 @@
 
   // If the switch has a condition wrapped by __builtin_unpredictable,
   // create metadata that specifies that the switch is unpredictable.

update the comment here.


Comment at: lib/CodeGen/CGStmt.cpp:1562
@@ +1561,3 @@
+
+// FIXME: builtin_expect should use the same metadata type as
+// builtin_unpredictable and be handled above. For now, we're mimicking

I am not sure about this. builtin_expect can be used to do general value 
profiling annotation (single value). For instance,

if (builtin_expect(a, 20) > 10) {
}

should have same effect as

if (builtin_expect(a > 10), true) {

}

The above can be handled by gcc, but not LLVM.


It can be useful for switch case annotation:

switch (__builtin_expect(v, 20) ) {
 case 10: ...
 case 20: ...
 ...
}
where compiler can do switch peeling.

Longer term, I am thinking extending builtin_expect to take list of values with 
probabilities and predicatibiity hint.


Comment at: lib/CodeGen/CGStmt.cpp:1566
@@ +1565,3 @@
+
+// HACK: Hardcode the taken/not-taken weights based on the existing 
LLVM
+// default values. This code is expected to be very temporary. Once we

Unpredicable meta data is probably not suitable for switch annotation. 
builtin_expect can be used to specify one case that is more likely to be taken 
thus helping switch lowering decision (not used in the cases such as if 
conversion).


Comment at: lib/CodeGen/CodeGenFunction.cpp:1312
@@ -1311,3 +1311,3 @@
 
   // If the branch has a condition wrapped by __builtin_unpredictable,
   // create metadata that specifies that the branch is unpredictable.

Update comment here.


Comment at: lib/CodeGen/CodeGenFunction.cpp:1325
@@ +1324,3 @@
+
+// FIXME: builtin_expect should use the same metadata type as
+// builtin_unpredictable and be handled above. For now, we're mimicking

I suggest removing these comments.


http://reviews.llvm.org/D19299



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


Re: [PATCH] D19071: [OpenCL] Add predefined macros.

2016-04-20 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: lib/Frontend/InitPreprocessor.cpp:421
@@ +420,3 @@
+switch (LangOpts.OpenCLVersion) {
+case 100:
+  Builder.defineMacro("__OPENCL_C_VERSION__", "100");

Yes, perfectly makes sense. I don't think passing C std flag should be allowed 
since OpenCL is based strictly on C99 and use of other versions are not 
possible anyways.

Nice cleanup!


Comment at: lib/Frontend/InitPreprocessor.cpp:439
@@ +438,3 @@
+Builder.defineMacro("CL_VERSION_1_2", "120");
+Builder.defineMacro("CL_VERSION_2_0", "200");
+

Could you update the test please. 


Comment at: test/Frontend/stdlang.c:10
@@ -3,1 +9,3 @@
+#ifndef OPENCL_C99
 // expected-no-diagnostics
+#endif

I think expected-no-diagnostics is only used if -verify is passed.


http://reviews.llvm.org/D19071



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


Re: [PATCH] D19278: [scan-build] fix logic error warnings emitted on clang code base

2016-04-20 Thread John McCall via cfe-commits
rjmccall added a comment.

LGTM, thanks.


http://reviews.llvm.org/D19278



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


[PATCH] D19327: Keep invalid function body as part of the AST

2016-04-20 Thread Olivier Goffart via cfe-commits
ogoffart created this revision.
ogoffart added reviewers: cfe-commits, rsmith.


struct XX {
   double foo(invalid_type xx);
};
double XX::foo(invalid_type xx)
{ 
   return 45; 
}

We should keep XX::foo and its function body as part of the AST so tools can 
still do something with the body even if the definition is wrong.
Inline function would already be kept, but not when they are redeclarations.

http://reviews.llvm.org/D19327

Files:
  lib/Sema/SemaDecl.cpp
  test/Misc/ast-dump-invalid.cpp

Index: test/Misc/ast-dump-invalid.cpp
===
--- test/Misc/ast-dump-invalid.cpp
+++ test/Misc/ast-dump-invalid.cpp
@@ -41,3 +41,24 @@
 // CHECK-NEXT: `-ImplicitCastExpr {{.*}}  'int' 

 // CHECK-NEXT:   `-DeclRefExpr {{.*}}  'int' lvalue ParmVar 
{{.*}} 'i' 'int'
 
+
+namespace TestInvalidFunctionDecl {
+struct Str {
+   double foo1(double, invalid_type);
+};
+double Str::foo1(double, invalid_type)
+{ return 45; }
+}
+// CHECK: NamespaceDecl {{.*}} <{{.*}}> {{.*}} TestInvalidFunctionDecl
+// CHECK-NEXT: |-CXXRecordDecl {{.*}}  line:46:8 struct 
Str definition
+// CHECK-NEXT: | |-CXXRecordDecl {{.*}}  col:8 implicit struct 
Str
+// CHECK-NEXT: | `-CXXMethodDecl {{.*}}  col:11 invalid 
foo1 'double (double, int)'
+// CHECK-NEXT: |   |-ParmVarDecl {{.*}}  col:22 'double'
+// CHECK-NEXT: |   `-ParmVarDecl {{.*}}  col:36 
invalid 'int'
+// CHECK-NEXT: `-CXXMethodDecl {{.*}} parent {{.*}}  
line:49:13 invalid foo1 'double (double, int)'
+// CHECK-NEXT:   |-ParmVarDecl {{.*}}  col:24 'double'
+// CHECK-NEXT:   |-ParmVarDecl {{.*}}  col:38 invalid 
'int'
+// CHECK-NEXT:   `-CompoundStmt {{.*}} 
+// CHECK-NEXT: `-ReturnStmt {{.*}} 
+// CHECK-NEXT:   `-ImplicitCastExpr {{.*}}  'double' 

+// CHECK-NEXT: `-IntegerLiteral {{.*}}  'int' 45
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -5041,8 +5041,8 @@
 
   // If this has an identifier and is not an invalid redeclaration or 
   // function template specialization, add it to the scope stack.
-  if (New->getDeclName() && AddToScope &&
-   !(D.isRedeclaration() && New->isInvalidDecl())) {
+  if (New->getDeclName() && AddToScope && !(D.isRedeclaration()
+  && New->isInvalidDecl() && !D.isFunctionDefinition())) {
 // Only make a locally-scoped extern declaration visible if it is the first
 // declaration of this entity. Qualified lookup for such an entity should
 // only find this declaration if there is no visible declaration of it.


Index: test/Misc/ast-dump-invalid.cpp
===
--- test/Misc/ast-dump-invalid.cpp
+++ test/Misc/ast-dump-invalid.cpp
@@ -41,3 +41,24 @@
 // CHECK-NEXT: `-ImplicitCastExpr {{.*}}  'int' 
 // CHECK-NEXT:   `-DeclRefExpr {{.*}}  'int' lvalue ParmVar {{.*}} 'i' 'int'
 
+
+namespace TestInvalidFunctionDecl {
+struct Str {
+   double foo1(double, invalid_type);
+};
+double Str::foo1(double, invalid_type)
+{ return 45; }
+}
+// CHECK: NamespaceDecl {{.*}} <{{.*}}> {{.*}} TestInvalidFunctionDecl
+// CHECK-NEXT: |-CXXRecordDecl {{.*}}  line:46:8 struct Str definition
+// CHECK-NEXT: | |-CXXRecordDecl {{.*}}  col:8 implicit struct Str
+// CHECK-NEXT: | `-CXXMethodDecl {{.*}}  col:11 invalid foo1 'double (double, int)'
+// CHECK-NEXT: |   |-ParmVarDecl {{.*}}  col:22 'double'
+// CHECK-NEXT: |   `-ParmVarDecl {{.*}}  col:36 invalid 'int'
+// CHECK-NEXT: `-CXXMethodDecl {{.*}} parent {{.*}}  line:49:13 invalid foo1 'double (double, int)'
+// CHECK-NEXT:   |-ParmVarDecl {{.*}}  col:24 'double'
+// CHECK-NEXT:   |-ParmVarDecl {{.*}}  col:38 invalid 'int'
+// CHECK-NEXT:   `-CompoundStmt {{.*}} 
+// CHECK-NEXT: `-ReturnStmt {{.*}} 
+// CHECK-NEXT:   `-ImplicitCastExpr {{.*}}  'double' 
+// CHECK-NEXT: `-IntegerLiteral {{.*}}  'int' 45
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -5041,8 +5041,8 @@
 
   // If this has an identifier and is not an invalid redeclaration or 
   // function template specialization, add it to the scope stack.
-  if (New->getDeclName() && AddToScope &&
-   !(D.isRedeclaration() && New->isInvalidDecl())) {
+  if (New->getDeclName() && AddToScope && !(D.isRedeclaration()
+  && New->isInvalidDecl() && !D.isFunctionDefinition())) {
 // Only make a locally-scoped extern declaration visible if it is the first
 // declaration of this entity. Qualified lookup for such an entity should
 // only find this declaration if there is no visible declaration of it.

Re: [PATCH] D19299: lower __builtin_expect() directly to prof metadata instead of LLVM intrinsic

2016-04-20 Thread Amaury SECHET via cfe-commits
deadalnix added a subscriber: deadalnix.


Comment at: lib/CodeGen/CGStmt.cpp:1560-1588
@@ -1560,1 +1559,31 @@
+MDHelper.createUnpredictable());
+  } else if (FD->getBuiltinID() == Builtin::BI__builtin_expect) {
+
+// FIXME: builtin_expect should use the same metadata type as
+// builtin_unpredictable and be handled above. For now, we're mimicking
+// the LLVM behavior of the 'LowerExpectIntrinsic' pass.
+
+// HACK: Hardcode the taken/not-taken weights based on the existing 
LLVM
+// default values. This code is expected to be very temporary. Once we
+// have prepared LLVM to handle builtin_expect using 'unpredictable'
+// metadata, this gets deleted.
+
+const int LikelyWeight = 64;
+const int UnlikelyWeight = 4;
+
+llvm::Value *ExpectedVal = EmitScalarExpr(Call->getArg(1));
+if (auto *ExpectConst = dyn_cast(ExpectedVal)) {
+  // The +1 is for the default case.
+  SmallVector Weights(SwitchInsn->getNumCases() + 1,
+UnlikelyWeight);
+  auto ExpectedCase = SwitchInsn->findCaseValue(ExpectConst);
+  if (ExpectedCase == SwitchInsn->case_default())
+Weights[0] = LikelyWeight;
+  else
+Weights[ExpectedCase.getCaseIndex() + 1] = LikelyWeight;
+
+  SwitchInsn->setMetadata(llvm::LLVMContext::MD_prof,
+  MDHelper.createBranchWeights(Weights));
+}
+  }
 }

If I understand properly this is transitional and eventually, you want to 
remove the intrinsic ? I think I like it, having 2 ways to hint here is only 
making things more complicated without adding much value.


http://reviews.llvm.org/D19299



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


Re: [PATCH] D19299: lower __builtin_expect() directly to prof metadata instead of LLVM intrinsic

2016-04-20 Thread Sanjay Patel via cfe-commits
spatel added a comment.

[reposting this as a general comment because the inline comment did not seem to 
make it to the mailing list]

Yes, I want to merge the handling of builtin_expect and builtin_unpredictable. 
Currently, the 'unpredictable' metadata has no parameters; it is an empty 
string like:

  br i1 %or.cond, label %bb3, label %bb4, !unpredictable !2
  ...
  !2 = !{}

In http://reviews.llvm.org/D12341, we considered having an integer parameter 
value that would be a measure of the unpredictability. For example, this could 
be used with PGO if someone had collected branch mispredict data as part of a 
profiling run.

So as a first proposal, let's say we add an integer parameter for 
predictability for this metadata type. We could define '-1' to mean 'perfectly 
predictable' and so builtin_expect would map to this:

  !2 = !{-1 42}   <--- perfectly predictable with expected value of '42'

Rereading your question, I'm now wondering if you are asking if we can get rid 
of the source level builtin_unpredictable() ? I had not considered that, but I 
think that is also possible if we add a flag to builtin_expect() to mean 'this 
branch is unpredictable'.

Please let me know if I answered the correct question. :)

So, yes this patch is transitional - hopefully, no more than a few days. I'm 
going to audit where we actually use profile data to make transform decisions. 
Once those places (I'm assuming they actually exist!) are updated to look at 
the unpredictable metadata, we can fix up this clang code to match the 
optimizer's algorithms.


http://reviews.llvm.org/D19299



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


Re: [PATCH] D19312: Warn about UB at member function calls from base class ctor initializers.

2016-04-20 Thread Filipe Cabecinhas via cfe-commits
filcab added a subscriber: filcab.
filcab added a comment.

You might want to mention that it's 12.6.2p16 in C++14/17 but p13 in C++11.
I wonder if we should have the example in the standard, verbatim. (Plus the 
added tests you made)


http://reviews.llvm.org/D19312



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


[clang-tools-extra] r266874 - IncludeFixerTest.cpp: Tweak not to assume clang-tools-extra were onto clang/tools/extra.

2016-04-20 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Wed Apr 20 09:14:16 2016
New Revision: 266874

URL: http://llvm.org/viewvc/llvm-project?rev=266874=rev
Log:
IncludeFixerTest.cpp: Tweak not to assume clang-tools-extra were onto 
clang/tools/extra.

Modified:
clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp

Modified: clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt?rev=266874=266873=266874=diff
==
--- clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt Wed Apr 20 
09:14:16 2016
@@ -8,6 +8,9 @@ include_directories(
   ${INCLUDE_FIXER_SOURCE_DIR}
   )
 
+# We'd like to clang/unittests/Tooling/RewriterTestContext.h in the test.
+include_directories(${CLANG_SOURCE_DIR})
+
 add_extra_unittest(IncludeFixerTests
   IncludeFixerTest.cpp
   )

Modified: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp?rev=266874=266873=266874=diff
==
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp Wed 
Apr 20 09:14:16 2016
@@ -7,7 +7,7 @@
 //
 
//===--===//
 
-#include "../../../../unittests/Tooling/RewriterTestContext.h"
+#include "unittests/Tooling/RewriterTestContext.h"
 #include "InMemoryXrefsDB.h"
 #include "IncludeFixer.h"
 #include "clang/Tooling/Tooling.h"


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


[PATCH] D19324: [ASTMatchers] new forEachOverriden matcher

2016-04-20 Thread Clement Courbet via cfe-commits
courbet created this revision.
courbet added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Matches methods overridden by the given method.

http://reviews.llvm.org/D19324

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -2069,6 +2069,47 @@
   notMatches("class X { virtual void f(); };", cxxMethodDecl(isFinal(;
 }
 
+TEST(Matcher, ForEachOverriden) {
+  const auto ForEachOverriddenInClass = [](const char *ClassName) {
+return cxxMethodDecl(ofClass(hasName(ClassName)), isVirtual(),
+ forEachOverridden(cxxMethodDecl().bind("overridden")))
+.bind("override");
+  };
+  constexpr const char Code1[] = "class A { virtual void f(); };"
+ "class B : public A { void f(); };"
+ "class C : public B { void f(); };";
+  // C::f overrides A::f.
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  Code1, ForEachOverriddenInClass("C"),
+  new VerifyIdIsBoundTo("override", "f", 1)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  Code1, ForEachOverriddenInClass("C"),
+  new VerifyIdIsBoundTo("overridden", "f", 1)));
+  // B::f overrides A::f.
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  Code1, ForEachOverriddenInClass("B"),
+  new VerifyIdIsBoundTo("override", "f", 1)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  Code1, ForEachOverriddenInClass("B"),
+  new VerifyIdIsBoundTo("overridden", "f", 1)));
+  // A::f overrides nothing.
+  EXPECT_TRUE(notMatches(Code1, ForEachOverriddenInClass("A")));
+
+  constexpr const char Code2[] =
+  "class A1 { virtual void f(); };"
+  "class A2 { virtual void f(); };"
+  "class B : public A1, public A2 { void f(); };";
+  // B::f overrides A1::f and A2::f. This produces two matches.
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  Code2, ForEachOverriddenInClass("B"),
+  new VerifyIdIsBoundTo("override", "f", 2)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  Code2, ForEachOverriddenInClass("B"),
+  new VerifyIdIsBoundTo("overridden", "f", 2)));
+  // A1::f overrides nothing.
+  EXPECT_TRUE(notMatches(Code2, ForEachOverriddenInClass("A1")));
+}
+
 TEST(Matcher, MatchesVirtualMethod) {
   EXPECT_TRUE(matches("class X { virtual int f(); };",
   cxxMethodDecl(isVirtual(), hasName("::X::f";
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -182,6 +182,7 @@
   REGISTER_MATCHER(forEachArgumentWithParam);
   REGISTER_MATCHER(forEachConstructorInitializer);
   REGISTER_MATCHER(forEachDescendant);
+  REGISTER_MATCHER(forEachOverridden);
   REGISTER_MATCHER(forEachSwitchCase);
   REGISTER_MATCHER(forField);
   REGISTER_MATCHER(forStmt);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3693,6 +3693,48 @@
   InnerMatcher.matches(*Parent, Finder, Builder));
 }
 
+/// \brief Matches each method overriden by the given method. This matcher may
+/// produce multiple matches.
+///
+/// Given
+/// \code
+///   class A { virtual void f(); };
+///   class B : public A { void f(); };
+///   class C : public B { void f(); };
+/// \endcode
+/// cxxMethodDecl(ofClass(hasName("C")),
+///   forEachOverridden(cxxMethodDecl().bind("b"))).bind("d")
+///   matches once, with "b" binding "A::f" and "d" binding "C::f" (Note
+///   that B::f is not overridden by C::f).
+///
+/// The check can produce multiple matches in case of multiple inheritance, e.g.
+/// \code
+///   class A1 { virtual void f(); };
+///   class A2 { virtual void f(); };
+///   class C : public A1, public A2 { void f(); };
+/// \endcode
+/// cxxMethodDecl(ofClass(hasName("C")),
+///   forEachOverridden(cxxMethodDecl().bind("b"))).bind("d")
+///   matches twice, once with "b" binding "A1::f" and "d" binding "C::f", and
+///   once with "b" binding "A2::f" and "d" binding "C::f", and
+AST_MATCHER_P(CXXMethodDecl, forEachOverridden,
+  internal::Matcher, InnerMatcher) {
+  BoundNodesTreeBuilder Result;
+  bool Matched = false;
+  for (auto It = Node.begin_overridden_methods();
+   It != Node.end_overridden_methods(); ++It) {
+BoundNodesTreeBuilder OverriddenBuilder(*Builder);
+const bool OverriddenMatched =
+InnerMatcher.matches(**It, Finder, );
+if (OverriddenMatched) {
+  Matched = true;
+  Result.addMatch(OverriddenBuilder);
+}
+  }
+  *Builder = std::move(Result);
+  return Matched;
+}
+
 /// 

Re: [PATCH] D19323: Fix cast compiler warning message in include-fixer.

2016-04-20 Thread Benjamin Kramer via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

Looks good, thanks!


Repository:
  rL LLVM

http://reviews.llvm.org/D19323



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


[clang-tools-extra] r266870 - [include-fixer] Add a prototype for a new include fixing tool.

2016-04-20 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Apr 20 07:43:43 2016
New Revision: 266870

URL: http://llvm.org/viewvc/llvm-project?rev=266870=rev
Log:
[include-fixer] Add a prototype for a new include fixing tool.

Summary:
The goal of this tool is fairly simple, look up unknown identifiers in a
global database and add the corresponding #include line. It accomplishes
this by hooking into Sema as an ExternalSemaSource and responding to typo
correction callbacks. This means we can see the unknown identifier before
it's being munged by error recovery.

This doesn't work perfectly yet as some typo corrections don't emit
callbacks (delayed typos), but I think this is fixable. We also handle
only one include at a time as this is meant to be run directly from
the editing environment eventually. Adding multiple includes at the same
time is tricky because of error recovery.

This version only has a a dummy database, so all you can do is fixing
missing includes of , but the indexer to build a database will
follow soon.

Reviewers: djasper

Subscribers: ioeric, hokein, cfe-commits

Differential Revision: http://reviews.llvm.org/D19314

Added:
clang-tools-extra/trunk/include-fixer/
clang-tools-extra/trunk/include-fixer/CMakeLists.txt
clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp
clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.h
clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
clang-tools-extra/trunk/include-fixer/IncludeFixer.h
clang-tools-extra/trunk/include-fixer/XrefsDB.h
clang-tools-extra/trunk/include-fixer/tool/
clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
clang-tools-extra/trunk/unittests/include-fixer/
clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
Modified:
clang-tools-extra/trunk/CMakeLists.txt
clang-tools-extra/trunk/unittests/CMakeLists.txt

Modified: clang-tools-extra/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=266870=266869=266870=diff
==
--- clang-tools-extra/trunk/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/CMakeLists.txt Wed Apr 20 07:43:43 2016
@@ -6,6 +6,7 @@ add_subdirectory(clang-tidy)
 endif()
 
 add_subdirectory(clang-query)
+add_subdirectory(include-fixer)
 add_subdirectory(pp-trace)
 add_subdirectory(tool-template)
 

Added: clang-tools-extra/trunk/include-fixer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/CMakeLists.txt?rev=266870=auto
==
--- clang-tools-extra/trunk/include-fixer/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/include-fixer/CMakeLists.txt Wed Apr 20 07:43:43 
2016
@@ -0,0 +1,20 @@
+set(LLVM_LINK_COMPONENTS
+  support
+  )
+
+add_clang_library(clangIncludeFixer
+  IncludeFixer.cpp
+  InMemoryXrefsDB.cpp
+
+  LINK_LIBS
+  clangAST
+  clangBasic
+  clangFrontend
+  clangLex
+  clangParse
+  clangSema
+  clangTooling
+  clangToolingCore
+  )
+
+add_subdirectory(tool)

Added: clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp?rev=266870=auto
==
--- clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp (added)
+++ clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp Wed Apr 20 
07:43:43 2016
@@ -0,0 +1,23 @@
+//===-- InMemoryXrefsDB.cpp 
---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "InMemoryXrefsDB.h"
+
+namespace clang {
+namespace include_fixer {
+
+std::vector InMemoryXrefsDB::search(llvm::StringRef Identifier) {
+  auto I = LookupTable.find(Identifier);
+  if (I != LookupTable.end())
+return I->second;
+  return {};
+}
+
+} // namespace include_fixer
+} // namespace clang

Added: clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.h?rev=266870=auto
==
--- clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.h (added)
+++ clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.h Wed Apr 20 07:43:43 
2016
@@ -0,0 +1,36 @@
+//===-- InMemoryXrefsDB.h ---*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// 

Re: [PATCH] D19314: [include-fixer] Add a prototype for a new include fixing tool.

2016-04-20 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266870: [include-fixer] Add a prototype for a new include 
fixing tool. (authored by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D19314?vs=54344=54350#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19314

Files:
  clang-tools-extra/trunk/CMakeLists.txt
  clang-tools-extra/trunk/include-fixer/CMakeLists.txt
  clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp
  clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.h
  clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
  clang-tools-extra/trunk/include-fixer/IncludeFixer.h
  clang-tools-extra/trunk/include-fixer/XrefsDB.h
  clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
  clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
  clang-tools-extra/trunk/unittests/CMakeLists.txt
  clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
  clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp

Index: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
===
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
@@ -0,0 +1,87 @@
+//===-- IncludeFixerTest.cpp - Include fixer unit tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../../../../unittests/Tooling/RewriterTestContext.h"
+#include "InMemoryXrefsDB.h"
+#include "IncludeFixer.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+using namespace clang;
+
+namespace clang {
+namespace include_fixer {
+namespace {
+
+static bool runOnCode(tooling::ToolAction *ToolAction, StringRef Code,
+  StringRef FileName) {
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new vfs::InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  tooling::ToolInvocation Invocation(
+  {std::string("include_fixer"), std::string("-fsyntax-only"),
+   FileName.str()},
+  ToolAction, Files.get(), std::make_shared());
+
+  InMemoryFileSystem->addFile(FileName, 0,
+  llvm::MemoryBuffer::getMemBuffer(Code));
+
+  InMemoryFileSystem->addFile("foo.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+  InMemoryFileSystem->addFile("bar.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+  return Invocation.run();
+}
+
+static std::string runIncludeFixer(StringRef Code) {
+  std::map XrefsMap = {
+  {"std::string", {""}}, {"std::string::size_type", {""}}};
+  auto XrefsDB =
+  llvm::make_unique(std::move(XrefsMap));
+  std::vector Replacements;
+  IncludeFixerActionFactory Factory(*XrefsDB, Replacements);
+  runOnCode(, Code, "input.cc");
+  clang::RewriterTestContext Context;
+  clang::FileID ID = Context.createInMemoryFile("input.cc", Code);
+  clang::tooling::applyAllReplacements(Replacements, Context.Rewrite);
+  return Context.getRewrittenText(ID);
+}
+
+TEST(IncludeFixer, Typo) {
+  EXPECT_EQ("#include \nstd::string foo;\n",
+runIncludeFixer("std::string foo;\n"));
+
+  EXPECT_EQ(
+  "// comment\n#include \n#include \"foo.h\"\nstd::string foo;\n"
+  "#include \"bar.h\"\n",
+  runIncludeFixer("// comment\n#include \"foo.h\"\nstd::string foo;\n"
+  "#include \"bar.h\"\n"));
+
+  EXPECT_EQ("#include \n#include \"foo.h\"\nstd::string foo;\n",
+runIncludeFixer("#include \"foo.h\"\nstd::string foo;\n"));
+
+  EXPECT_EQ(
+  "#include \n#include \"foo.h\"\nstd::string::size_type foo;\n",
+  runIncludeFixer("#include \"foo.h\"\nstd::string::size_type foo;\n"));
+
+  // The fixed xrefs db doesn't know how to handle string without std::.
+  EXPECT_EQ("string foo;\n", runIncludeFixer("string foo;\n"));
+}
+
+TEST(IncludeFixer, IncompleteType) {
+  EXPECT_EQ(
+  "#include \n#include \"foo.h\"\n"
+  "namespace std {\nclass string;\n}\nstring foo;\n",
+  runIncludeFixer("#include \"foo.h\"\n"
+  "namespace std {\nclass string;\n}\nstring foo;\n"));
+}
+
+} // namespace
+} // namespace include_fixer
+} // namespace clang
Index: clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
===
--- clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
+++ clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
@@ -0,0 +1,22 @@
+set(LLVM_LINK_COMPONENTS
+  support
+  )
+
+get_filename_component(INCLUDE_FIXER_SOURCE_DIR
+  

Re: [PATCH] D19314: [include-fixer] Add a prototype for a new include fixing tool.

2016-04-20 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a reviewer: klimek.
klimek added a comment.
This revision is now accepted and ready to land.

Cool, lg.



Comment at: include-fixer/IncludeFixer.cpp:133
@@ +132,3 @@
+  StringRef filename() const { return Filename; }
+
+  /// Called for each include file we discover is in the file.

Ah, right, didn't see that it's all in the cpp.


http://reviews.llvm.org/D19314



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


Re: [PATCH] D19314: [include-fixer] Add a prototype for a new include fixing tool.

2016-04-20 Thread Benjamin Kramer via cfe-commits
bkramer marked 8 inline comments as done.


Comment at: include-fixer/IncludeFixer.cpp:132
@@ +131,3 @@
+
+private:
+  /// Query the database for a given identifier.

klimek wrote:
> Can we sort this so the public interface comes first? Also, why is the public 
> interface so large?
Sorted. Most of it is dealing with clang callbacks. I also don't consider this 
to be a public interface as it's all in the cpp file.


Comment at: include-fixer/IncludeFixer.cpp:184-190
@@ +183,9 @@
+   std::vector ) {
+for (const auto  : Untried) {
+  DEBUG(llvm::dbgs() << "Adding include " << ToTry << "\n");
+  std::string ToAdd = "\n#include " + ToTry;
+  // If this is the only include in the file, add the newline after it, not
+  // before.
+  if (LastIncludeOffset == 0)
+std::rotate(ToAdd.begin(), ToAdd.begin() + 1, ToAdd.end());
+

klimek wrote:
> Can we reuse functionality from clang-format here?
Yes we should. I changed it to insert new includes before the first include, 
clang-format will clean up the rest. clang-format isn't wired up to the tool 
yet, I'd like to use the new applyAllReplacements with formatting tools for 
that, should be ready soon.


Comment at: include-fixer/IncludeFixer.h:26
@@ +25,3 @@
+  IncludeFixerActionFactory(
+  std::unique_ptr Xrefs,
+  std::vector );

klimek wrote:
> Why are we passing ownership?
Taking a reference now.


Comment at: include-fixer/IncludeFixer.h:36
@@ +35,3 @@
+
+  XrefsDB *getXrefsDB() const { return Xrefs.get(); }
+

klimek wrote:
> That also seems weird in the interface here.
Removed.


http://reviews.llvm.org/D19314



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


Re: [PATCH] D19314: [include-fixer] Add a prototype for a new include fixing tool.

2016-04-20 Thread Benjamin Kramer via cfe-commits
bkramer updated this revision to Diff 54344.
bkramer added a comment.

From now on you shall be known as InMemoryXrefsDB.


http://reviews.llvm.org/D19314

Files:
  CMakeLists.txt
  include-fixer/CMakeLists.txt
  include-fixer/InMemoryXrefsDB.cpp
  include-fixer/InMemoryXrefsDB.h
  include-fixer/IncludeFixer.cpp
  include-fixer/IncludeFixer.h
  include-fixer/XrefsDB.h
  include-fixer/tool/CMakeLists.txt
  include-fixer/tool/ClangIncludeFixer.cpp
  unittests/CMakeLists.txt
  unittests/include-fixer/CMakeLists.txt
  unittests/include-fixer/IncludeFixerTest.cpp

Index: unittests/include-fixer/IncludeFixerTest.cpp
===
--- /dev/null
+++ unittests/include-fixer/IncludeFixerTest.cpp
@@ -0,0 +1,87 @@
+//===-- IncludeFixerTest.cpp - Include fixer unit tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../../../../unittests/Tooling/RewriterTestContext.h"
+#include "InMemoryXrefsDB.h"
+#include "IncludeFixer.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+using namespace clang;
+
+namespace clang {
+namespace include_fixer {
+namespace {
+
+static bool runOnCode(tooling::ToolAction *ToolAction, StringRef Code,
+  StringRef FileName) {
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new vfs::InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  tooling::ToolInvocation Invocation(
+  {std::string("include_fixer"), std::string("-fsyntax-only"),
+   FileName.str()},
+  ToolAction, Files.get(), std::make_shared());
+
+  InMemoryFileSystem->addFile(FileName, 0,
+  llvm::MemoryBuffer::getMemBuffer(Code));
+
+  InMemoryFileSystem->addFile("foo.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+  InMemoryFileSystem->addFile("bar.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+  return Invocation.run();
+}
+
+static std::string runIncludeFixer(StringRef Code) {
+  std::map XrefsMap = {
+  {"std::string", {""}}, {"std::string::size_type", {""}}};
+  auto XrefsDB =
+  llvm::make_unique(std::move(XrefsMap));
+  std::vector Replacements;
+  IncludeFixerActionFactory Factory(*XrefsDB, Replacements);
+  runOnCode(, Code, "input.cc");
+  clang::RewriterTestContext Context;
+  clang::FileID ID = Context.createInMemoryFile("input.cc", Code);
+  clang::tooling::applyAllReplacements(Replacements, Context.Rewrite);
+  return Context.getRewrittenText(ID);
+}
+
+TEST(IncludeFixer, Typo) {
+  EXPECT_EQ("#include \nstd::string foo;\n",
+runIncludeFixer("std::string foo;\n"));
+
+  EXPECT_EQ(
+  "// comment\n#include \n#include \"foo.h\"\nstd::string foo;\n"
+  "#include \"bar.h\"\n",
+  runIncludeFixer("// comment\n#include \"foo.h\"\nstd::string foo;\n"
+  "#include \"bar.h\"\n"));
+
+  EXPECT_EQ("#include \n#include \"foo.h\"\nstd::string foo;\n",
+runIncludeFixer("#include \"foo.h\"\nstd::string foo;\n"));
+
+  EXPECT_EQ(
+  "#include \n#include \"foo.h\"\nstd::string::size_type foo;\n",
+  runIncludeFixer("#include \"foo.h\"\nstd::string::size_type foo;\n"));
+
+  // The fixed xrefs db doesn't know how to handle string without std::.
+  EXPECT_EQ("string foo;\n", runIncludeFixer("string foo;\n"));
+}
+
+TEST(IncludeFixer, IncompleteType) {
+  EXPECT_EQ(
+  "#include \n#include \"foo.h\"\n"
+  "namespace std {\nclass string;\n}\nstring foo;\n",
+  runIncludeFixer("#include \"foo.h\"\n"
+  "namespace std {\nclass string;\n}\nstring foo;\n"));
+}
+
+} // namespace
+} // namespace include_fixer
+} // namespace clang
Index: unittests/include-fixer/CMakeLists.txt
===
--- /dev/null
+++ unittests/include-fixer/CMakeLists.txt
@@ -0,0 +1,22 @@
+set(LLVM_LINK_COMPONENTS
+  support
+  )
+
+get_filename_component(INCLUDE_FIXER_SOURCE_DIR
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../include-fixer REALPATH)
+include_directories(
+  ${INCLUDE_FIXER_SOURCE_DIR}
+  )
+
+add_extra_unittest(IncludeFixerTests
+  IncludeFixerTest.cpp
+  )
+
+target_link_libraries(IncludeFixerTests
+  clangBasic
+  clangFrontend
+  clangIncludeFixer
+  clangRewrite
+  clangTooling
+  clangToolingCore
+  )
Index: unittests/CMakeLists.txt
===
--- unittests/CMakeLists.txt
+++ unittests/CMakeLists.txt
@@ -9,3 +9,4 @@
 add_subdirectory(clang-rename)
 add_subdirectory(clang-query)
 add_subdirectory(clang-tidy)
+add_subdirectory(include-fixer)
Index: include-fixer/tool/ClangIncludeFixer.cpp

Re: [PATCH] D19312: Warn about UB at member function calls from base class ctor initializers.

2016-04-20 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 54343.
teemperor added a comment.

- Fixed indentation


http://reviews.llvm.org/D19312

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/ctor-init-with-member-call.cpp

Index: test/SemaCXX/ctor-init-with-member-call.cpp
===
--- /dev/null
+++ test/SemaCXX/ctor-init-with-member-call.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wmember-call-in-ctor-init
+
+// Helper class for the following test cases.
+class A {
+public:
+  A(int i) {
+  }
+};
+
+// Calling member functions before bass class initialized is undefined behavior.
+class B : public A {
+public:
+
+  B() : A(1 + get_i()) { // expected-warning {{member function call this->get_i() in ctor-initializer for base class 'A' results in undefined behavior}}
+  }
+
+  int get_i() {
+return 2;
+  }
+};
+
+// Same as previous test but with explicit this.
+class C : public A {
+public:
+  C() : A(this->get_i() + 1) { // expected-warning {{member function call this->get_i() in ctor-initializer for base class 'A' results in undefined behavior}}
+  }
+
+  int get_i() {
+return 2;
+  }
+};
+
+// Check that the whole ctor-initializer is checked for member calls.
+class OtherA {
+public:
+  OtherA(int i) {
+  }
+};
+
+class D : public OtherA, public A {
+public:
+  D() : OtherA(this->get_i() + 1), A(this->get_i() + 1) { // expected-warning {{member function call this->get_i() in ctor-initializer for base class 'OtherA' results in undefined behavior}} \
+  // expected-warning {{member function call this->get_i() in ctor-initializer for base class 'A' results in undefined behavior}}
+  }
+
+  int get_i() {
+return 2;
+  }
+};
+
+// Calling static functions of this class is not undefined behavior.
+class E : public A {
+public:
+  E() : A(this->get_i() + 1) { // no-warning
+  }
+
+  static int get_i() {
+return 2;
+  }
+};
+
+
+// Calling other functions of this class is not undefined behavior.
+int other_foo() {
+  return 2;
+}
+class F : public A {
+public:
+  F() : A(other_foo()) {} // no-warning
+};
+
+
+// Calling member functions of other classes is not undefined behavior.
+class G : public A {
+public:
+  G(B& b) : A(b.get_i()) {} // no-warning
+};
\ No newline at end of file
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -3873,6 +3873,35 @@
   return false;
 }
 
+namespace {
+  /// \brief Searches for the first member function call to a given class.
+  class HasMemberCall : public RecursiveASTVisitor {
+CXXRecordDecl* OnlyForClass;
+CXXMemberCallExpr *FoundMemberCall = nullptr;
+
+  public:
+explicit HasMemberCall(CXXRecordDecl* OnlyForClass)
+  : OnlyForClass(OnlyForClass) {
+}
+
+/// \brief Returns the found member function call or 0 if
+/// no fitting member function call was found.
+CXXMemberCallExpr *getFoundMemberCall() {
+  return FoundMemberCall;
+}
+
+bool VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
+  // Check if member call is actually to the given class.
+  if (E->getRecordDecl() == nullptr
+  || E->getRecordDecl()->getCanonicalDecl() == OnlyForClass) {
+FoundMemberCall = E;
+return false;
+  }
+  return true;
+}
+  };
+}
+
 bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
ArrayRef Initializers) {
   if (Constructor->isDependentContext()) {
@@ -3907,9 +3936,24 @@
   for (unsigned i = 0; i < Initializers.size(); i++) {
 CXXCtorInitializer *Member = Initializers[i];
 
-if (Member->isBaseInitializer())
+if (Member->isBaseInitializer()) {
+  // Calling a member function from a ctor-initializer
+  // before the base class results in undefined behavior [12.6.2 16].
+  // FIXME: We only check for member functions directly called from this
+  // CtorInitializer and not for indirectly called functions.
+  HasMemberCall Finder(ClassDecl);
+  Finder.TraverseStmt(Member->getInit());
+
+  if (Finder.getFoundMemberCall()) {
+Diag(Member->getSourceLocation(), diag::warn_member_call_in_ctor_init)
+  << Finder.getFoundMemberCall()
+  << Member->getBaseClass()->getAsCXXRecordDecl();
+  }
+
+
+
   Info.AllBaseFields[Member->getBaseClass()->getAs()] = Member;
-else {
+} else {
   Info.AllBaseFields[Member->getAnyMember()->getCanonicalDecl()] = Member;
 
   if (IndirectFieldDecl *F = Member->getIndirectMember()) {
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6791,6 +6791,10 @@
   "will never be used">,
 

Re: [PATCH] D19314: [include-fixer] Add a prototype for a new include fixing tool.

2016-04-20 Thread Benjamin Kramer via cfe-commits
bkramer updated this revision to Diff 54342.
bkramer added a comment.

- FixedXrefsDB -> FakeXrefsDB
- FakeXrefsDB is now configurable
- Cosmetic & comment fixes.
- Moved query to private methods.
- Always insert new includes at the top, let clang-format sort out the rest 
(not yet implemented in the tool, pending fixReplacements)
- Don't take ownership of XrefsDB


http://reviews.llvm.org/D19314

Files:
  CMakeLists.txt
  include-fixer/CMakeLists.txt
  include-fixer/FakeXrefsDB.cpp
  include-fixer/FakeXrefsDB.h
  include-fixer/IncludeFixer.cpp
  include-fixer/IncludeFixer.h
  include-fixer/XrefsDB.h
  include-fixer/tool/CMakeLists.txt
  include-fixer/tool/ClangIncludeFixer.cpp
  unittests/CMakeLists.txt
  unittests/include-fixer/CMakeLists.txt
  unittests/include-fixer/IncludeFixerTest.cpp

Index: unittests/include-fixer/IncludeFixerTest.cpp
===
--- /dev/null
+++ unittests/include-fixer/IncludeFixerTest.cpp
@@ -0,0 +1,87 @@
+//===-- IncludeFixerTest.cpp - Include fixer unit tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../../../../unittests/Tooling/RewriterTestContext.h"
+#include "FakeXrefsDB.h"
+#include "IncludeFixer.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+using namespace clang;
+
+namespace clang {
+namespace include_fixer {
+namespace {
+
+static bool runOnCode(tooling::ToolAction *ToolAction, StringRef Code,
+  StringRef FileName) {
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new vfs::InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  tooling::ToolInvocation Invocation(
+  {std::string("include_fixer"), std::string("-fsyntax-only"),
+   FileName.str()},
+  ToolAction, Files.get(), std::make_shared());
+
+  InMemoryFileSystem->addFile(FileName, 0,
+  llvm::MemoryBuffer::getMemBuffer(Code));
+
+  InMemoryFileSystem->addFile("foo.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+  InMemoryFileSystem->addFile("bar.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+  return Invocation.run();
+}
+
+static std::string runIncludeFixer(StringRef Code) {
+  std::map XrefsMap = {
+  {"std::string", {""}}, {"std::string::size_type", {""}}};
+  auto XrefsDB =
+  llvm::make_unique(std::move(XrefsMap));
+  std::vector Replacements;
+  IncludeFixerActionFactory Factory(*XrefsDB, Replacements);
+  runOnCode(, Code, "input.cc");
+  clang::RewriterTestContext Context;
+  clang::FileID ID = Context.createInMemoryFile("input.cc", Code);
+  clang::tooling::applyAllReplacements(Replacements, Context.Rewrite);
+  return Context.getRewrittenText(ID);
+}
+
+TEST(IncludeFixer, Typo) {
+  EXPECT_EQ("#include \nstd::string foo;\n",
+runIncludeFixer("std::string foo;\n"));
+
+  EXPECT_EQ(
+  "// comment\n#include \n#include \"foo.h\"\nstd::string foo;\n"
+  "#include \"bar.h\"\n",
+  runIncludeFixer("// comment\n#include \"foo.h\"\nstd::string foo;\n"
+  "#include \"bar.h\"\n"));
+
+  EXPECT_EQ("#include \n#include \"foo.h\"\nstd::string foo;\n",
+runIncludeFixer("#include \"foo.h\"\nstd::string foo;\n"));
+
+  EXPECT_EQ(
+  "#include \n#include \"foo.h\"\nstd::string::size_type foo;\n",
+  runIncludeFixer("#include \"foo.h\"\nstd::string::size_type foo;\n"));
+
+  // The fixed xrefs db doesn't know how to handle string without std::.
+  EXPECT_EQ("string foo;\n", runIncludeFixer("string foo;\n"));
+}
+
+TEST(IncludeFixer, IncompleteType) {
+  EXPECT_EQ(
+  "#include \n#include \"foo.h\"\n"
+  "namespace std {\nclass string;\n}\nstring foo;\n",
+  runIncludeFixer("#include \"foo.h\"\n"
+  "namespace std {\nclass string;\n}\nstring foo;\n"));
+}
+
+} // namespace
+} // namespace include_fixer
+} // namespace clang
Index: unittests/include-fixer/CMakeLists.txt
===
--- /dev/null
+++ unittests/include-fixer/CMakeLists.txt
@@ -0,0 +1,22 @@
+set(LLVM_LINK_COMPONENTS
+  support
+  )
+
+get_filename_component(INCLUDE_FIXER_SOURCE_DIR
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../include-fixer REALPATH)
+include_directories(
+  ${INCLUDE_FIXER_SOURCE_DIR}
+  )
+
+add_extra_unittest(IncludeFixerTests
+  IncludeFixerTest.cpp
+  )
+
+target_link_libraries(IncludeFixerTests
+  clangBasic
+  clangFrontend
+  clangIncludeFixer
+  clangRewrite
+  clangTooling
+  clangToolingCore
+  )
Index: unittests/CMakeLists.txt
===
--- unittests/CMakeLists.txt
+++ 

Re: [PATCH] D18081: Make sizeof and alignof a CXCursor_UnaryExpr

2016-04-20 Thread Olivier Goffart via cfe-commits
ogoffart added a comment.

Ping?


http://reviews.llvm.org/D18081



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


Re: [PATCH] D18080: CIndex: add support for static_assert

2016-04-20 Thread Olivier Goffart via cfe-commits
ogoffart added a comment.

Ping?


http://reviews.llvm.org/D18080



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


[clang-tools-extra] r266866 - clang-tidy: [misc-unused-using-decls] Support template types.

2016-04-20 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Apr 20 04:48:56 2016
New Revision: 266866

URL: http://llvm.org/viewvc/llvm-project?rev=266866=rev
Log:
clang-tidy: [misc-unused-using-decls] Support template types.

This fixes llvm.org/PR27429.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp?rev=266866=266865=266866=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp Wed Apr 
20 04:48:56 2016
@@ -20,8 +20,9 @@ namespace misc {
 
 void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind("using"), this);
-  Finder->addMatcher(recordType(hasDeclaration(namedDecl().bind("used"))),
- this);
+  auto DeclMatcher = hasDeclaration(namedDecl().bind("used"));
+  Finder->addMatcher(loc(recordType(DeclMatcher)), this);
+  Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
 }
 
 void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult ) {
@@ -34,7 +35,7 @@ void UnusedUsingDeclsCheck::check(const
 Using->shadow_begin()->getTargetDecl()->getCanonicalDecl();
 
 // FIXME: Handle other target types.
-if (!isa(TargetDecl))
+if (!isa(TargetDecl) && !isa(TargetDecl))
   return;
 
 FoundDecls[TargetDecl] = Using;
@@ -53,6 +54,9 @@ void UnusedUsingDeclsCheck::check(const
   // FIXME: This currently doesn't look at whether the type reference is
   // actually found with the help of the using declaration.
   if (const auto *Used = Result.Nodes.getNodeAs("used")) {
+if (const auto *Specialization =
+dyn_cast(Used))
+  Used = Specialization->getSpecializedTemplate();
 auto I = FoundDecls.find(Used->getCanonicalDecl());
 if (I != FoundDecls.end())
   I->second = nullptr;

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp?rev=266866=266865=266866=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp Wed Apr 
20 04:48:56 2016
@@ -8,6 +8,8 @@ class B;
 class C;
 class D;
 class D { public: static int i; };
+template  class E {};
+template  class F {};
 }
 
 // - Using declarations -
@@ -18,11 +20,16 @@ using n::A; // A
 using n::B;
 using n::C;
 using n::D;
+using n::E; // E
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'E' is unused
+// CHECK-FIXES: {{^}}// E
+using n::F;
 
 // - Usages -
 void f(B b);
 void g() {
   vector data;
   D::i = 1;
+  F f;
 }
 


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


[clang-tools-extra] r266864 - clang-tidy: [misc-unused-using-decls] Always use the canonical decl to

2016-04-20 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Apr 20 03:58:27 2016
New Revision: 266864

URL: http://llvm.org/viewvc/llvm-project?rev=266864=rev
Log:
clang-tidy: [misc-unused-using-decls] Always use the canonical decl to
identify things.

This fixes llvm.org/PR27430.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h
clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp?rev=266864=266863=266864=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp Wed Apr 
20 03:58:27 2016
@@ -30,7 +30,8 @@ void UnusedUsingDeclsCheck::check(const
 // than one shadow.
 if (Using->shadow_size() != 1)
   return;
-const auto* TargetDecl = Using->shadow_begin()->getTargetDecl();
+const auto *TargetDecl =
+Using->shadow_begin()->getTargetDecl()->getCanonicalDecl();
 
 // FIXME: Handle other target types.
 if (!isa(TargetDecl))
@@ -52,8 +53,9 @@ void UnusedUsingDeclsCheck::check(const
   // FIXME: This currently doesn't look at whether the type reference is
   // actually found with the help of the using declaration.
   if (const auto *Used = Result.Nodes.getNodeAs("used")) {
-if (FoundDecls.find(Used) != FoundDecls.end())
-  FoundDecls[Used] = nullptr;
+auto I = FoundDecls.find(Used->getCanonicalDecl());
+if (I != FoundDecls.end())
+  I->second = nullptr;
   }
 }
 

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h?rev=266864=266863=266864=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.h Wed Apr 20 
03:58:27 2016
@@ -30,8 +30,8 @@ public:
   void onEndOfTranslationUnit() override;
 
 private:
-  llvm::DenseMap FoundDecls;
-  llvm::DenseMap FoundRanges;
+  llvm::DenseMap FoundDecls;
+  llvm::DenseMap FoundRanges;
 };
 
 } // namespace misc

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp?rev=266864=266863=266864=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-using-decls.cpp Wed Apr 
20 03:58:27 2016
@@ -6,6 +6,7 @@ namespace n {
 class A;
 class B;
 class C;
+class D;
 class D { public: static int i; };
 }
 


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


[PATCH] D19312: Warn about UB at member function calls from base class ctor initializers.

2016-04-20 Thread Raphael Isemann via cfe-commits
teemperor created this revision.
teemperor added a reviewer: rsmith.
teemperor added a subscriber: cfe-commits.

  According to [12.6.2 p16] calling member functions of the current
  class before all the base classes are initialized is undefined behavior.
  Some compilers (such as GCC 5.3 + ubsan) can produce a segfaulting code 
  in the program when such code is encountered (see GCC bug #70035),
  so clang should generate a warning about the UB.

http://reviews.llvm.org/D19312

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/ctor-init-with-member-call.cpp

Index: test/SemaCXX/ctor-init-with-member-call.cpp
===
--- /dev/null
+++ test/SemaCXX/ctor-init-with-member-call.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wmember-call-in-ctor-init
+
+// Helper class for the following test cases.
+class A {
+public:
+  A(int i) {
+  }
+};
+
+// Calling member functions before bass class initialized is undefined behavior.
+class B : public A {
+public:
+
+  B() : A(1 + get_i()) { // expected-warning {{member function call this->get_i() in ctor-initializer for base class 'A' results in undefined behavior}}
+  }
+
+  int get_i() {
+return 2;
+  }
+};
+
+// Same as previous test but with explicit this.
+class C : public A {
+public:
+C() : A(this->get_i() + 1) { // expected-warning {{member function call this->get_i() in ctor-initializer for base class 'A' results in undefined behavior}}
+}
+
+int get_i() {
+  return 2;
+}
+};
+
+// Check that the whole ctor-initializer is checked for member calls.
+class OtherA {
+public:
+OtherA(int i) {
+}
+};
+
+class D : public OtherA, public A {
+public:
+D() : OtherA(this->get_i() + 1), A(this->get_i() + 1) { // expected-warning {{member function call this->get_i() in ctor-initializer for base class 'OtherA' results in undefined behavior}} \
+// expected-warning {{member function call this->get_i() in ctor-initializer for base class 'A' results in undefined behavior}}
+}
+
+int get_i() {
+return 2;
+}
+};
+
+// Calling static functions of this class is not undefined behavior.
+class E : public A {
+public:
+E() : A(this->get_i() + 1) { // no-warning
+}
+
+static int get_i() {
+return 2;
+}
+};
+
+
+// Calling other functions of this class is not undefined behavior.
+int other_foo() {
+  return 2;
+}
+class F : public A {
+public:
+F() : A(other_foo()) {} // no-warning
+};
+
+
+// Calling member functions of other classes is not undefined behavior.
+class G : public A {
+public:
+G(B& b) : A(b.get_i()) {} // no-warning
+};
\ No newline at end of file
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -3873,6 +3873,35 @@
   return false;
 }
 
+namespace {
+/// \brief Searches for the first member function call to a given class.
+class HasMemberCall : public RecursiveASTVisitor {
+CXXRecordDecl* OnlyForClass;
+CXXMemberCallExpr *FoundMemberCall = nullptr;
+
+public:
+explicit HasMemberCall(CXXRecordDecl* OnlyForClass)
+  : OnlyForClass(OnlyForClass) {
+}
+
+/// \brief Returns the found member function call or 0 if
+/// no fitting member function call was found.
+CXXMemberCallExpr *getFoundMemberCall() {
+  return FoundMemberCall;
+}
+
+bool VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
+  // Check if member call is actually to the given class.
+  if (E->getRecordDecl() == nullptr
+  || E->getRecordDecl()->getCanonicalDecl() == OnlyForClass) {
+FoundMemberCall = E;
+return false;
+  }
+  return true;
+}
+};
+}
+
 bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
ArrayRef Initializers) {
   if (Constructor->isDependentContext()) {
@@ -3907,9 +3936,24 @@
   for (unsigned i = 0; i < Initializers.size(); i++) {
 CXXCtorInitializer *Member = Initializers[i];
 
-if (Member->isBaseInitializer())
+if (Member->isBaseInitializer()) {
+  // Calling a member function from a ctor-initializer
+  // before the base class results in undefined behavior [12.6.2 16].
+  // FIXME: We only check for member functions directly called from this
+  // CtorInitializer and not for indirectly called functions.
+  HasMemberCall Finder(ClassDecl);
+  Finder.TraverseStmt(Member->getInit());
+
+  if (Finder.getFoundMemberCall()) {
+Diag(Member->getSourceLocation(), diag::warn_member_call_in_ctor_init)
+  << Finder.getFoundMemberCall()
+  << Member->getBaseClass()->getAsCXXRecordDecl();
+  }
+
+
+
   

Re: [PATCH] D11781: Refactored pthread usage in libcxx

2016-04-20 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In http://reviews.llvm.org/D11781#403349, @rmaprath wrote:

> In http://reviews.llvm.org/D11781#403343, @theraven wrote:
>
> > In http://reviews.llvm.org/D11781#403335, @rmaprath wrote:
> >
> > > For us (ARM), a threads porting layer is important on several RTOSes 
> > > (where a full-blown pthreads implementations is not available). I will 
> > > see if I can publish one of those porting layer implementations, but 
> > > perhaps a windows porting layer is more interesting to the community, in 
> > > which case I'll look into hacking one up (unless of course, if 
> > > @espositofulvio has already got one).
> >
> >
> > I'd be equally interested (and willing to review) an mbed implementation.
>
>
> Thanks!
>
> If you meant the mbed OS [1], I think it is still single-threaded (although 
> that might change in the near future [2]). Most of our customers (of 
> armclang) have proprietary RTOSes, but we might be able upstream a sample 
> implementation (I'm thinking Keil RTX [3], but need to double check a few 
> things), if it seems generally useful to the community.
>
> Cheers,
>
> / Asiri
>
> [1] https://www.mbed.com/
>  [2] https://www.mbed.com/en/development/software/mbed-os/ ("...we intend to 
> re-introduce it in 2016")
>  [3] http://www.keil.com/rl-arm/kernel.asp


I stand corrected, mbed already has an RTOS layer: 
https://developer.mbed.org/handbook/RTOS. I'm not very familiar with mbed 
(obviously). I will do some digging to see how difficult it would be to port 
libcxx to mbed (we already build libcxx for cortex-m bare-metal systems, so 
this shouldn't be that hard).

After reading through the past threads, providing a windows thread porting 
layer sounds like a useless thing, given that getting libcxx to build on 
windows itself is a rather large piece of work.

Cheers,

- Asiri


Repository:
  rL LLVM

http://reviews.llvm.org/D11781



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


[clang-tools-extra] r266862 - Fix a crash in cppcoreguidelines-pro-type-member-init related to missing constructor bodies.

2016-04-20 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Apr 20 03:29:08 2016
New Revision: 266862

URL: http://llvm.org/viewvc/llvm-project?rev=266862=rev
Log:
Fix a crash in cppcoreguidelines-pro-type-member-init related to missing 
constructor bodies.

Summary: Fixes a crash in cppcoreguidelines-pro-type-member-init when checking 
some record types with a constructor without a body. We now check to make sure 
the constructor has a body before looking for missing members and base 
initializers.

Patch by Michael Miller!

Reviewers: aaron.ballman, alexfh, hokein

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19270

Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp?rev=266862=266861=266862=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp 
Wed Apr 20 03:29:08 2016
@@ -285,6 +285,9 @@ void ProTypeMemberInitCheck::registerMat
 
 void ProTypeMemberInitCheck::check(const MatchFinder::MatchResult ) {
   if (const auto *Ctor = Result.Nodes.getNodeAs("ctor")) {
+// Skip declarations delayed by late template parsing without a body.
+if (!Ctor->getBody())
+  return;
 checkMissingMemberInitializer(*Result.Context, Ctor);
 checkMissingBaseClassInitializer(*Result.Context, Ctor);
   } else if (const auto *Var = Result.Nodes.getNodeAs("var")) {
@@ -304,11 +307,6 @@ void ProTypeMemberInitCheck::checkMissin
   if (IsUnion && ClassDecl->hasInClassInitializer())
 return;
 
-  // Skip declarations delayed by late template parsing without a body.
-  const Stmt *Body = Ctor->getBody();
-  if (!Body)
-return;
-
   SmallPtrSet FieldsToInit;
   fieldsRequiringInit(ClassDecl->fields(), Context, FieldsToInit);
   if (FieldsToInit.empty())
@@ -323,7 +321,7 @@ void ProTypeMemberInitCheck::checkMissin
   FieldsToInit.erase(Init->getMember());
 }
   }
-  removeFieldsInitializedInBody(*Body, Context, FieldsToInit);
+  removeFieldsInitializedInBody(*Ctor->getBody(), Context, FieldsToInit);
 
   // Collect all fields in order, both direct fields and indirect fields from
   // anonmyous record types.

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp?rev=266862=266861=266862=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
 Wed Apr 20 03:29:08 2016
@@ -331,3 +331,10 @@ struct PositiveAnonymousUnionAndStruct {
   int X;
   // CHECK-FIXES: int X{};
 };
+
+// This check results in a CXXConstructorDecl with no body.
+struct NegativeDeletedConstructor : NegativeAggregateType {
+  NegativeDeletedConstructor() = delete;
+
+  Template F;
+};


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


Re: [PATCH] D19270: Fix a crash in cppcoreguidelines-pro-type-member-init related to missing constructor bodies.

2016-04-20 Thread Haojian Wu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266862: Fix a crash in 
cppcoreguidelines-pro-type-member-init related to missing… (authored by hokein).

Changed prior to commit:
  http://reviews.llvm.org/D19270?vs=54210=54327#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19270

Files:
  
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Index: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -331,3 +331,10 @@
   int X;
   // CHECK-FIXES: int X{};
 };
+
+// This check results in a CXXConstructorDecl with no body.
+struct NegativeDeletedConstructor : NegativeAggregateType {
+  NegativeDeletedConstructor() = delete;
+
+  Template F;
+};
Index: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -285,6 +285,9 @@
 
 void ProTypeMemberInitCheck::check(const MatchFinder::MatchResult ) {
   if (const auto *Ctor = Result.Nodes.getNodeAs("ctor")) {
+// Skip declarations delayed by late template parsing without a body.
+if (!Ctor->getBody())
+  return;
 checkMissingMemberInitializer(*Result.Context, Ctor);
 checkMissingBaseClassInitializer(*Result.Context, Ctor);
   } else if (const auto *Var = Result.Nodes.getNodeAs("var")) {
@@ -304,11 +307,6 @@
   if (IsUnion && ClassDecl->hasInClassInitializer())
 return;
 
-  // Skip declarations delayed by late template parsing without a body.
-  const Stmt *Body = Ctor->getBody();
-  if (!Body)
-return;
-
   SmallPtrSet FieldsToInit;
   fieldsRequiringInit(ClassDecl->fields(), Context, FieldsToInit);
   if (FieldsToInit.empty())
@@ -323,7 +321,7 @@
   FieldsToInit.erase(Init->getMember());
 }
   }
-  removeFieldsInitializedInBody(*Body, Context, FieldsToInit);
+  removeFieldsInitializedInBody(*Ctor->getBody(), Context, FieldsToInit);
 
   // Collect all fields in order, both direct fields and indirect fields from
   // anonmyous record types.


Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -331,3 +331,10 @@
   int X;
   // CHECK-FIXES: int X{};
 };
+
+// This check results in a CXXConstructorDecl with no body.
+struct NegativeDeletedConstructor : NegativeAggregateType {
+  NegativeDeletedConstructor() = delete;
+
+  Template F;
+};
Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -285,6 +285,9 @@
 
 void ProTypeMemberInitCheck::check(const MatchFinder::MatchResult ) {
   if (const auto *Ctor = Result.Nodes.getNodeAs("ctor")) {
+// Skip declarations delayed by late template parsing without a body.
+if (!Ctor->getBody())
+  return;
 checkMissingMemberInitializer(*Result.Context, Ctor);
 checkMissingBaseClassInitializer(*Result.Context, Ctor);
   } else if (const auto *Var = Result.Nodes.getNodeAs("var")) {
@@ -304,11 +307,6 @@
   if (IsUnion && ClassDecl->hasInClassInitializer())
 return;
 
-  // Skip declarations delayed by late template parsing without a body.
-  const Stmt *Body = Ctor->getBody();
-  if (!Body)
-return;
-
   SmallPtrSet FieldsToInit;
   fieldsRequiringInit(ClassDecl->fields(), Context, FieldsToInit);
   if (FieldsToInit.empty())
@@ -323,7 +321,7 @@
   FieldsToInit.erase(Init->getMember());
 }
   }
-  removeFieldsInitializedInBody(*Body, Context, FieldsToInit);
+  removeFieldsInitializedInBody(*Ctor->getBody(), Context, FieldsToInit);
 
   // Collect all fields in order, both direct fields and indirect fields from
   // anonmyous record types.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16989: Change interpretation of function definition in friend declaration of template class.

2016-04-20 Thread Serge Pavlov via cfe-commits
2016-03-29 1:08 GMT+06:00 Serge Pavlov :

> 2016-03-18 20:50 GMT+06:00 Richard Smith :
>
>> rsmith added a comment.
>>
>> Can we instead not add the function to the redeclaration chain until it's
>> instantiated (like we do if it's dependent)?
>>
>>
> I prepared implementation that uses this approach. In this variant
> information about potential definitions is lost, in some cases it makes
> difficult to make analysis. For instance we can diagnose misfit of
> declarations in the code:
> ```
> void func9(int);  // expected-note{{previous declaration is here}}
> template struct C9a {
>   friend int func9(int);  // expected-error{{functions that differ only in
> their return type cannot be overloaded}}
> };
> ```
> but not in the case:
> ```
> template struct C9a {
>   friend int func9(int);
> };
> void func9(int);
> ```
> Otherwise both approaches seem almost equivalent.
>

It looks like this is not an issue. In http://reviews.llvm.org/D16579
dependent friend are stored in a set for subsequent analysis. Nothing
prevents from using the same approach for all friend functions.

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


[PATCH] D19311: Self Assignment Checker

2016-04-20 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added a reviewer: dcoughlin.
baloghadamsoftware added subscribers: cfe-commits, xazax.hun, o.gyorgy.

This checker checks copy and move assignment operators whether they are 
protected against self-assignment. Since C++ core guidelines discourages 
explicit checking for ``==this`` in general we take a different approach: 
in top-frame analysis we branch the exploded graph for two cases, where 
==this and !=this and let existing checkers (e.g. unix.Malloc) do the 
rest of the work. It is important that we check all copy and move assignment 
operator in top frame even if we checked them already since self-assignments 
may happen undetected even in the same translation unit (e.g. using random 
indices for an array what may or may not be the same).

http://reviews.llvm.org/D19311

Files:
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/SelfAssignmentChecker.cpp
  lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  test/Analysis/self-assign-unused.cpp
  test/Analysis/self-assign-used.cpp

Index: test/Analysis/self-assign-used.cpp
===
--- /dev/null
+++ test/Analysis/self-assign-used.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,cplusplus,unix.Malloc,debug.ExprInspection %s -verify
+
+extern "C" char *strdup(const char* s);
+extern "C" void free(void* ptr);
+
+class String {
+public:
+  String(const char *s = "") : str(strdup(s)) {}
+  String(const String ) : str(strdup(rhs.str)) {}
+  ~String();
+  String& operator=(const String );
+  operator const char*() const;
+private:
+  char *str;
+};
+
+String::~String() {
+  free(str);
+}
+
+String& String::operator=(const String ) {
+  free(str);
+  str = strdup(rhs.str); // expected-warning{{Use of memory after it is freed}}
+  return *this;
+}
+
+String::operator const char*() const {
+  return str;
+}
+
+int main() {
+  String s1 ("test"), s2;
+  s2 = s1;
+  return 0;
+}
Index: test/Analysis/self-assign-unused.cpp
===
--- /dev/null
+++ test/Analysis/self-assign-unused.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,cplusplus,unix.Malloc,debug.ExprInspection %s -verify
+
+extern "C" char *strdup(const char* s);
+extern "C" void free(void* ptr);
+
+class String {
+public:
+  String(const char *s = "") : str(strdup(s)) {}
+  String(const String ) : str(strdup(rhs.str)) {}
+  ~String();
+  String& operator=(const String );
+  operator const char*() const;
+private:
+  char *str;
+};
+
+String::~String() {
+  free(str);
+}
+
+String& String::operator=(const String ) {
+  free(str);
+  str = strdup(rhs.str); // expected-warning{{Use of memory after it is freed}}
+  return *this;
+}
+
+String::operator const char*() const {
+  return str;
+}
+
+int main() {
+  return 0;
+}
Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -432,6 +432,10 @@
   //   Count naming convention errors more aggressively.
   if (isa(D))
 return false;
+  if (const auto *MD = dyn_cast(D)) {
+if(MD->isCopyAssignmentOperator()||MD->isMoveAssignmentOperator())
+  return false;
+  }
 
   // Otherwise, if we visited the function before, do not reanalyze it.
   return Visited.count(D);
@@ -443,9 +447,7 @@
   // We want to reanalyze all ObjC methods as top level to report Retain
   // Count naming convention errors more aggressively. But we should tune down
   // inlining when reanalyzing an already inlined function.
-  if (Visited.count(D)) {
-assert(isa(D) &&
-   "We are only reanalyzing ObjCMethods.");
+  if (Visited.count(D)&(D)) {
 const ObjCMethodDecl *ObjCM = cast(D);
 if (ObjCM->getMethodFamily() != OMF_init)
   return ExprEngine::Inline_Minimal;
Index: lib/StaticAnalyzer/Checkers/SelfAssignmentChecker.cpp
===
--- /dev/null
+++ lib/StaticAnalyzer/Checkers/SelfAssignmentChecker.cpp
@@ -0,0 +1,42 @@
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+
+class SelfAssignmentChecker : public Checker {
+public:
+  SelfAssignmentChecker();
+  void checkBeginFunction(CheckerContext ) const;
+};
+}
+
+SelfAssignmentChecker::SelfAssignmentChecker() {}
+
+void SelfAssignmentChecker::checkBeginFunction(CheckerContext ) const {
+  if (!C.inTopFrame())
+return;
+  const auto *LCtx = C.getLocationContext();
+  const auto *MD = dyn_cast(LCtx->getDecl());
+  if (!MD)
+return;
+  if (!MD->isCopyAssignmentOperator() && !MD->isMoveAssignmentOperator())
+return;
+  auto 

Re: [PATCH] D19270: Fix a crash in cppcoreguidelines-pro-type-member-init related to missing constructor bodies.

2016-04-20 Thread Haojian Wu via cfe-commits
hokein accepted this revision.
hokein added a comment.

LGTM. Thanks.


http://reviews.llvm.org/D19270



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