Re: [PATCH] D19451: [clang-tidy] New checker for redundant expressions.

2016-04-26 Thread Etienne Bergeron via cfe-commits
etienneb added inline comments.


Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:21
@@ +20,3 @@
+
+static bool AreIdenticalExpr(const Expr *Left, const Expr *Right) {
+  if (!Left || !Right)

alexfh wrote:
> This is to some degree similar to comparing `llvm::FoldingSetNodeIDs` created 
> using `Stmt::Profile`. However it's only useful to check for identical 
> expressions and won't work, if you're going to extend this to equivalent 
> expressions.
Exact. There is plan to extend the notion of "equivalent".
I think we should lift this to "utils", and maybe we can also provide a 
"isIdenticalExpression" based on FoldingSet.


http://reviews.llvm.org/D19451



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


[PATCH] D19539: Fix a crash in cppcoreguidelines-pro-type-member-init when checking a type with a template parameter as a base class.

2016-04-26 Thread Michael Miller via cfe-commits
michael_miller created this revision.
michael_miller added reviewers: hokein, aaron.ballman, alexfh.
michael_miller added a subscriber: cfe-commits.

Fixed a crash in cppcoreguidelines-pro-type-member-init when encountering a 
type that uses one of its template parameters as a base when compiling for 
C++98.

http://reviews.llvm.org/D19539

Files:
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp
@@ -70,26 +70,36 @@
   int Z;
 };
 
-struct NonTrivialType {
+struct TrivialType {
   int X;
   int Y;
 };
 
 struct PositiveUninitializedBaseOrdering : public NegativeAggregateType,
-   public NonTrivialType {
-  PositiveUninitializedBaseOrdering() : NegativeAggregateType(), 
NonTrivialType(), B() {}
+   public TrivialType {
+  PositiveUninitializedBaseOrdering() : NegativeAggregateType(), 
TrivialType(), B() {}
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize 
these fields: A
-  // CHECK-FIXES: PositiveUninitializedBaseOrdering() : 
NegativeAggregateType(), NonTrivialType(), A(), B() {}
+  // CHECK-FIXES: PositiveUninitializedBaseOrdering() : 
NegativeAggregateType(), TrivialType(), A(), B() {}
 
   // This is somewhat pathological with the base class initializer at the 
end...
-  PositiveUninitializedBaseOrdering(int) : B(), NonTrivialType(), A() {}
+  PositiveUninitializedBaseOrdering(int) : B(), TrivialType(), A() {}
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize 
these bases: NegativeAggregateType
-  // CHECK-FIXES: PositiveUninitializedBaseOrdering(int) : B(), 
NegativeAggregateType(), NonTrivialType(), A() {}
+  // CHECK-FIXES: PositiveUninitializedBaseOrdering(int) : B(), 
NegativeAggregateType(), TrivialType(), A() {}
 
   PositiveUninitializedBaseOrdering(float) : NegativeAggregateType(), A() {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize 
these bases: NonTrivialType
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize 
these bases: TrivialType
   // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: constructor does not initialize 
these fields: B
-  // CHECK-FIXES: PositiveUninitializedBaseOrdering(float) : 
NegativeAggregateType(), NonTrivialType(), A(), B() {}
+  // CHECK-FIXES: PositiveUninitializedBaseOrdering(float) : 
NegativeAggregateType(), TrivialType(), A(), B() {}
 
   int A, B;
 };
+
+template 
+class PositiveTemplateBase : T {
+public:
+  PositiveTemplateBase() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize 
these fields: X
+  // CHECK-FIXES: PositiveTemplateBase() : X() {}
+
+  int X;
+};
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -208,8 +208,12 @@
 void getInitializationsInOrder(const CXXRecordDecl *ClassDecl,
SmallVectorImpl &Decls) {
   Decls.clear();
-  for (const auto &Base : ClassDecl->bases())
-Decls.emplace_back(getCanonicalRecordDecl(Base.getType()));
+  for (const auto &Base : ClassDecl->bases()) {
+// Decl may be null if the base class is a template parameter.
+if (const NamedDecl *Decl = getCanonicalRecordDecl(Base.getType())) {
+  Decls.emplace_back(Decl);
+}
+  }
   Decls.append(ClassDecl->fields().begin(), ClassDecl->fields().end());
 }
 


Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp
@@ -70,26 +70,36 @@
   int Z;
 };
 
-struct NonTrivialType {
+struct TrivialType {
   int X;
   int Y;
 };
 
 struct PositiveUninitializedBaseOrdering : public NegativeAggregateType,
-   public NonTrivialType {
-  PositiveUninitializedBaseOrdering() : NegativeAggregateType(), NonTrivialType(), B() {}
+   public TrivialType {
+  PositiveUninitializedBaseOrdering() : NegativeAggregateType(), TrivialType(), B() {}
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: A
-  // CHECK-FIXES: PositiveUninitializedBaseOrdering() : NegativeAggregateType(), NonTrivialType(), A(), B() {}
+  // CHECK-FIXES: PositiveUninitializedBaseOrdering() : NegativeAggregateType(), TrivialType(), A(), B() {}
 
   // This is somewhat pathologica

[PATCH] D19541: Fix generation of documentation for UndefinedBehaviorSanitizer.

2016-04-26 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

The text is mis-aligned.

http://reviews.llvm.org/D19541

Files:
  docs/UndefinedBehaviorSanitizer.rst

Index: docs/UndefinedBehaviorSanitizer.rst
===
--- docs/UndefinedBehaviorSanitizer.rst
+++ docs/UndefinedBehaviorSanitizer.rst
@@ -93,13 +93,13 @@
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
  reference.
   -  ``-fsanitize=object-size``: An attempt to potentially use bytes which
-the optimizer can determine are not part of the object being accessed.
-This will also detect some types of undefined behavior that may not
-directly access memory, but are provably incorrect given the size of
-the objects involved, such as invalid downcasts and calling methods on
-invalid pointers. These checks are made in terms of
-``__builtin_object_size``, and consequently may be able to detect more
-problems at higher optimization levels.
+ the optimizer can determine are not part of the object being accessed.
+ This will also detect some types of undefined behavior that may not
+ directly access memory, but are provably incorrect given the size of
+ the objects involved, such as invalid downcasts and calling methods on
+ invalid pointers. These checks are made in terms of
+ ``__builtin_object_size``, and consequently may be able to detect more
+ problems at higher optimization levels.
   -  ``-fsanitize=return``: In C++, reaching the end of a
  value-returning function without returning a value.
   -  ``-fsanitize=returns-nonnull-attribute``: Returning null pointer


Index: docs/UndefinedBehaviorSanitizer.rst
===
--- docs/UndefinedBehaviorSanitizer.rst
+++ docs/UndefinedBehaviorSanitizer.rst
@@ -93,13 +93,13 @@
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
  reference.
   -  ``-fsanitize=object-size``: An attempt to potentially use bytes which
-the optimizer can determine are not part of the object being accessed.
-This will also detect some types of undefined behavior that may not
-directly access memory, but are provably incorrect given the size of
-the objects involved, such as invalid downcasts and calling methods on
-invalid pointers. These checks are made in terms of
-``__builtin_object_size``, and consequently may be able to detect more
-problems at higher optimization levels.
+ the optimizer can determine are not part of the object being accessed.
+ This will also detect some types of undefined behavior that may not
+ directly access memory, but are provably incorrect given the size of
+ the objects involved, such as invalid downcasts and calling methods on
+ invalid pointers. These checks are made in terms of
+ ``__builtin_object_size``, and consequently may be able to detect more
+ problems at higher optimization levels.
   -  ``-fsanitize=return``: In C++, reaching the end of a
  value-returning function without returning a value.
   -  ``-fsanitize=returns-nonnull-attribute``: Returning null pointer
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19541: Fix generation of documentation for UndefinedBehaviorSanitizer.

2016-04-26 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

This got fixed.
Abandoning this change.


http://reviews.llvm.org/D19541



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


[clang-tools-extra] r267574 - [clang-tidy] New checker for redundant expressions.

2016-04-26 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Tue Apr 26 12:30:30 2016
New Revision: 267574

URL: http://llvm.org/viewvc/llvm-project?rev=267574&view=rev
Log:
[clang-tidy] New checker for redundant expressions.

Summary:
This checker finds redundant expression on both side of a binary operator.

The current implementation provide a function to check whether expressions
are equivalent. This implementation is able to recognize the common
subset encounter in C++ program. Side-effects like "x++" are not considered
to be equivalent.

There are many False Positives related to macros and to floating point
computations (detecting NaN). The checker is ignoring these cases.

Example:
```
if( !dst || dst->depth != desired_depth ||
dst->nChannels != desired_num_channels ||
dst_size.width != src_size.width ||
dst_size.height != dst_size.height )<<--- bug
{
```

Reviewers: alexfh

Subscribers: danielmarjamaki, fahlgren, jordan_rose, zaks.anna, Eugene.Zelenko, 
cfe-commits

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

Added:
clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-redundant-expression.rst
clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=267574&r1=267573&r2=267574&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Tue Apr 26 12:30:30 
2016
@@ -23,6 +23,7 @@ add_clang_library(clangTidyMiscModule
   NoexceptMoveConstructorCheck.cpp
   NonCopyableObjects.cpp
   PointerAndIntegralOperationCheck.cpp
+  RedundantExpressionCheck.cpp
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp
   StaticAssertCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=267574&r1=267573&r2=267574&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Tue Apr 26 
12:30:30 2016
@@ -31,6 +31,7 @@
 #include "NoexceptMoveConstructorCheck.h"
 #include "NonCopyableObjects.h"
 #include "PointerAndIntegralOperationCheck.h"
+#include "RedundantExpressionCheck.h"
 #include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
 #include "StaticAssertCheck.h"
@@ -98,6 +99,8 @@ public:
 "misc-non-copyable-objects");
 CheckFactories.registerCheck(
 "misc-pointer-and-integral-operation");
+CheckFactories.registerCheck(
+"misc-redundant-expression");
 
CheckFactories.registerCheck("misc-sizeof-container");
 CheckFactories.registerCheck(
 "misc-sizeof-expression");

Added: clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp?rev=267574&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantExpressionCheck.cpp Tue 
Apr 26 12:30:30 2016
@@ -0,0 +1,133 @@
+//===--- RedundantExpressionCheck.cpp - 
clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "RedundantExpressionCheck.h"
+#include "../utils/Matchers.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+static bool AreIdenticalExpr(const Expr *Left, const Expr *Right) {
+  if (!Left || !Right)
+return !Left && !Right;
+
+  Left = Left->IgnoreParens();
+  Right = Right->IgnoreParens();
+
+  // Compare classes.
+  if (Left->getStmtClass() != Right->getStmtClass())
+return false;
+
+  // Compare children.
+  Expr::const_child_iterator LeftIter = Left->child_begin();
+  Expr::const_child_iterator RightIter = Right->child_begin();
+  while (LeftIter != Left->child_end() && RightIter != Right->child_end()) {

[clang-tools-extra] r267576 - [Release notes] Mention Clang-tidy misc-fold-init-type check.

2016-04-26 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Tue Apr 26 12:54:00 2016
New Revision: 267576

URL: http://llvm.org/viewvc/llvm-project?rev=267576&view=rev
Log:
[Release notes] Mention Clang-tidy misc-fold-init-type check.

Highlighting consistency in Clang-tidy misc-fold-init-type check documentation.

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-fold-init-type.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=267576&r1=267575&r2=267576&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Apr 26 12:54:00 2016
@@ -92,6 +92,12 @@ identified.  The improvements since the
   Detects dangling references in value handlers like
   ``std::experimental::string_view``.
 
+- New `misc-fold-init-type
+  `_ 
check
+
+  The check flags type mismatches in `folds` like ``std::accumulate`` that 
might
+  result in loss of precision.
+
 - New `misc-forward-declaration-namespace
   
`_
 check
 

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-fold-init-type.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-fold-init-type.rst?rev=267576&r1=267575&r2=267576&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-fold-init-type.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-fold-init-type.rst Tue 
Apr 26 12:54:00 2016
@@ -5,13 +5,13 @@ misc-fold-init-type
 
 The check flags type mismatches in
 `folds `_
-like `std::accumulate` that might result in loss of precision.
-`std::accumulate` folds an input range into an initial value using the type of
-the latter, with `operator+` by default. This can cause loss of precision
+like ``std::accumulate`` that might result in loss of precision.
+``std::accumulate`` folds an input range into an initial value using the type 
of
+the latter, with ``operator+`` by default. This can cause loss of precision
 through:
 
 - Truncation: The following code uses a floating point range and an int
-  initial value, so trucation wil happen at every application of `operator+`
+  initial value, so trucation wil happen at every application of ``operator+``
   and the result will be `0`, which might not be what the user expected.
 
 .. code:: c++


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


Re: [PATCH] D18271: Avoid -Wshadow warnings about constructor parameters named after fields

2016-04-26 Thread Reid Kleckner via cfe-commits
rnk updated this revision to Diff 55044.
rnk added a comment.

- Implement suggestions to avoid warning twice


http://reviews.llvm.org/D18271

Files:
  include/clang/Basic/Diagnostic.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/AnalysisBasedWarnings.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/warn-shadow.cpp

Index: test/SemaCXX/warn-shadow.cpp
===
--- test/SemaCXX/warn-shadow.cpp
+++ test/SemaCXX/warn-shadow.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only -Wshadow %s
+// RUN: %clang_cc1 -verify -fsyntax-only -Wshadow-all %s
 
 namespace {
   int i; // expected-note {{previous declaration is here}}
@@ -29,7 +29,23 @@
 
 class A {
   static int data; // expected-note {{previous declaration}}
-  int field; // expected-note {{previous declaration}}
+  // expected-note@+1 {{previous declaration}}
+  int field;
+  int f1, f2, f3, f4; // expected-note 8 {{previous declaration is here}}
+
+  // The initialization is safe, but the modifications are not.
+  A(int f1, int f2, int f3, int f4) // expected-note-re 4 {{variable 'f{{[0-4]}}' is declared here}}
+	  : f1(f1) {
+f1 = 3; // expected-warning {{modifying constructor parameter 'f1' that shadows a field of 'A'}}
+f1 = 4; // one warning per shadow
+f2++; // expected-warning {{modifying constructor parameter 'f2' that shadows a field of 'A'}}
+--f3; // expected-warning {{modifying constructor parameter 'f3' that shadows a field of 'A'}}
+f4 += 2; // expected-warning {{modifying constructor parameter 'f4' that shadows a field of 'A'}}
+  }
+
+  // The initialization is safe, but the modifications are not.
+  // expected-warning-re@+1 4 {{constructor parameter 'f{{[0-4]}}' shadows the field 'f{{[0-9]}}' of 'A'}}
+  A(int f1, int f2, int f3, int f4, double overload_dummy) {}
 
   void test() {
 char *field; // expected-warning {{declaration shadows a field of 'A'}}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -9733,6 +9733,9 @@
 /// emit an error and return true.  If so, return false.
 static bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) {
   assert(!E->hasPlaceholderType(BuiltinType::PseudoObject));
+
+  S.CheckShadowingDeclModification(E, Loc);
+
   SourceLocation OrigLoc = Loc;
   Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context,
   &Loc);
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -1609,9 +1609,19 @@
 // If this was a forward reference to a label, verify it was defined.
 if (LabelDecl *LD = dyn_cast(D))
   CheckPoppedLabel(LD, *this);
-
-// Remove this name from our lexical scope.
+
+// Remove this name from our lexical scope, and warn on it if we haven't
+// already.
 IdResolver.RemoveDecl(D);
+auto ShadowI = ShadowingDecls.find(D);
+if (ShadowI != ShadowingDecls.end()) {
+  if (const auto *FD = dyn_cast(ShadowI->second)) {
+Diag(D->getLocation(), diag::warn_ctor_parm_shadows_field)
+<< D << FD << FD->getParent();
+Diag(FD->getLocation(), diag::note_previous_declaration);
+  }
+  ShadowingDecls.erase(ShadowI);
+}
   }
 }
 
@@ -6382,6 +6392,17 @@
   return NewVD;
 }
 
+/// Enum describing the %select options in diag::warn_decl_shadow.
+enum ShadowedDeclKind { SDK_Local, SDK_Global, SDK_StaticMember, SDK_Field };
+
+/// Determine what kind of declaration we're shadowing.
+static ShadowedDeclKind computeShadowedDeclKind(const NamedDecl *ShadowedDecl,
+const DeclContext *OldDC) {
+  if (isa(OldDC))
+return isa(ShadowedDecl) ? SDK_Field : SDK_StaticMember;
+  return OldDC->isFileContext() ? SDK_Global : SDK_Local;
+}
+
 /// \brief Diagnose variable or built-in function shadowing.  Implements
 /// -Wshadow.
 ///
@@ -6410,12 +6431,23 @@
   if (!isa(ShadowedDecl) && !isa(ShadowedDecl))
 return;
 
-  // Fields are not shadowed by variables in C++ static methods.
-  if (isa(ShadowedDecl))
+  if (FieldDecl *FD = dyn_cast(ShadowedDecl)) {
+// Fields are not shadowed by variables in C++ static methods.
 if (CXXMethodDecl *MD = dyn_cast(NewDC))
   if (MD->isStatic())
 return;
 
+// Fields shadowed by constructor parameters are a special case. Usually
+// the constructor initializes the field with the parameter.
+if (isa(NewDC) && isa(D)) {
+  // Remember that this was shadowed so we can either warn about its
+  // modification or its existance depending on warning settings.
+  D = D->getCanonicalDecl();
+  ShadowingDecls.insert({D, FD});
+  return;
+}
+  }
+
   if (

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

2016-04-26 Thread Sanjay Patel via cfe-commits
spatel abandoned this revision.
spatel added a comment.

Abandoning.

The feedback on the dev list was that handling the builtin_expect() in clang is 
ugly, so it's better to pay a small cost in LLVM to do it.

Note that the current llvm.expect lowering pass doesn't actually work for 
anything but the simplest cases. The pass needs to be enhanced to handle 
patterns like:

  int foo(int x, int y) {
if (__builtin_expect(x, 20) > 10) return 234;  // expected value is not 1
return 2;
  }

or:

  int foo(int n) {
int b = __builtin_expect(n, 1);  // expect is not directly used in 
comparison
if (b) return 24;
return 234;
  }

Currently, the llvm.expect is discarded in these cases without generating any 
metadata.


http://reviews.llvm.org/D19299



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


[PATCH] D19547: [clang-tidy] Add FixIt for swapping arguments in string-constructor-checker.

2016-04-26 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

Arguments can be swapped using fixit when they are not in macros.
This is the same implementation than SwappedArguments. Some code 
got lifted to be reused.

Others checks are not safe to be fixed as they tend to be bugs or errors.
It is better to let the user manually review them.

http://reviews.llvm.org/D19547

Files:
  clang-tidy/misc/StringConstructorCheck.cpp
  clang-tidy/misc/SwappedArgumentsCheck.cpp
  clang-tidy/utils/FixItHintUtils.cpp
  clang-tidy/utils/FixItHintUtils.h
  test/clang-tidy/misc-string-constructor.cpp

Index: test/clang-tidy/misc-string-constructor.cpp
===
--- test/clang-tidy/misc-string-constructor.cpp
+++ test/clang-tidy/misc-string-constructor.cpp
@@ -22,8 +22,10 @@
 void Test() {
   std::string str('x', 4);
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor parameters are probably swapped [misc-string-constructor]
+  // CHECK-FIXES: std::string str(4, 'x');  
   std::wstring wstr(L'x', 4);
   // CHECK-MESSAGES: [[@LINE-1]]:16: warning: constructor parameters are probably swapped
+  // CHECK-FIXES: std::wstring wstr(4, L'x');
   std::string s0(0, 'x');
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
   std::string s1(-4, 'x');
Index: clang-tidy/utils/FixItHintUtils.h
===
--- clang-tidy/utils/FixItHintUtils.h
+++ clang-tidy/utils/FixItHintUtils.h
@@ -24,6 +24,9 @@
 /// \brief Creates fix to make VarDecl const qualified.
 FixItHint changeVarDeclToConst(const VarDecl &Var);
 
+/// \brief Get a StringRef representing a SourceRange.
+StringRef getSourceRangeAsString(const ASTContext &Context, SourceRange R);
+
 } // namespace create_fix_it
 } // utils
 } // namespace tidy
Index: clang-tidy/utils/FixItHintUtils.cpp
===
--- clang-tidy/utils/FixItHintUtils.cpp
+++ clang-tidy/utils/FixItHintUtils.cpp
@@ -30,6 +30,21 @@
   return FixItHint::CreateInsertion(Var.getTypeSpecStartLoc(), "const ");
 }
 
+StringRef getSourceRangeAsString(const ASTContext &Context, SourceRange R) {
+  const SourceManager &SM = Context.getSourceManager();
+  // Don't even try to resolve macro or include contraptions. Not worth emitting
+  // a fixit for.
+  if (R.getBegin().isMacroID() ||
+  !SM.isWrittenInSameFile(R.getBegin(), R.getEnd()))
+return StringRef();
+
+  const char *Begin = SM.getCharacterData(R.getBegin());
+  const char *End = SM.getCharacterData(
+  Lexer::getLocForEndOfToken(R.getEnd(), 0, SM, Context.getLangOpts()));
+
+  return StringRef(Begin, End - Begin);
+}
+
 } // namespace create_fix_it
 } // namespace utils
 } // namespace tidy
Index: clang-tidy/misc/SwappedArgumentsCheck.cpp
===
--- clang-tidy/misc/SwappedArgumentsCheck.cpp
+++ clang-tidy/misc/SwappedArgumentsCheck.cpp
@@ -8,6 +8,7 @@
 //===--===//
 
 #include "SwappedArgumentsCheck.h"
+#include "../utils/FixItHintUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -46,24 +47,8 @@
  Cast->getCastKind() == CK_PointerToBoolean;
 }
 
-/// \brief Get a StringRef representing a SourceRange.
-static StringRef getAsString(const MatchFinder::MatchResult &Result,
- SourceRange R) {
-  const SourceManager &SM = *Result.SourceManager;
-  // Don't even try to resolve macro or include contraptions. Not worth emitting
-  // a fixit for.
-  if (R.getBegin().isMacroID() ||
-  !SM.isWrittenInSameFile(R.getBegin(), R.getEnd()))
-return StringRef();
-
-  const char *Begin = SM.getCharacterData(R.getBegin());
-  const char *End = SM.getCharacterData(Lexer::getLocForEndOfToken(
-  R.getEnd(), 0, SM, Result.Context->getLangOpts()));
-
-  return StringRef(Begin, End - Begin);
-}
-
 void SwappedArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Ctx = *Result.Context;
   auto *Call = Result.Nodes.getStmtAs("call");
 
   llvm::SmallPtrSet UsedArgs;
@@ -108,8 +93,10 @@
 << LHS->getType() << LHSFrom->getType() << RHS->getType()
 << RHSFrom->getType() << LHSRange << RHSRange;
 
-StringRef RHSString = getAsString(Result, RHSRange);
-StringRef LHSString = getAsString(Result, LHSRange);
+StringRef RHSString =
+utils::create_fix_it::getSourceRangeAsString(Ctx, RHSRange);
+StringRef LHSString =
+utils::create_fix_it::getSourceRangeAsString(Ctx, LHSRange);
 if (!LHSString.empty() && !RHSString.empty()) {
   D << FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(LHSRange), RHSString)
Index: clang-tidy/misc/StringConstructorCheck.cpp
==

Re: [PATCH] D17820: Clang Code Completion Filtering

2016-04-26 Thread Ben Langmuir via cfe-commits
benlangmuir added a comment.

Overall approach seems good to me, but this needs tests.  Other feedback inline.



Comment at: include/clang/Sema/CodeCompleteConsumer.h:920
@@ +919,3 @@
+CodeCompletionResult Results) {
+return true;
+  }

I would expect the default to be `false`, since if you don't implement 
filtering presumably you want every result.

Also: Please fix alignment of the results parameter.


Comment at: lib/Sema/CodeCompleteConsumer.cpp:435
@@ +434,3 @@
+  case CodeCompletionResult::RK_Declaration: {
+return !(Result.Declaration &&
+(*Result.Declaration).getIdentifier() &&

Can `Declaration` ever be legitimately null?  We're going to unconditionally 
filter it out if so, which seems odd.  Same applies to the other cases below.


Comment at: lib/Sema/CodeCompleteConsumer.cpp:450
@@ +449,3 @@
+  }
+  return false;
+}

Is this reachable?  If not, consider using `llvm_unreachable()` instead of 
`return`.


Repository:
  rL LLVM

http://reviews.llvm.org/D17820



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


Re: r267496 - [lanai] Update handling of structs in arguments to be passed in registers.

2016-04-26 Thread Kostya Serebryany via cfe-commits
On Tue, Apr 26, 2016 at 6:49 AM, Jacques Pienaar 
wrote:

> Thanks for fixing this. My apologies for breaking this and not noticing &
> fixing it earlier.
>

no problem.


> Is there any way to test the Windows build without a Windows machine at my
> disposal?
>

Not that I know of. My workflow for windows is the same -- commit, watch
the bots, make a guess-based fix if bots got broken.
That's unfortunate, I would rather prefer trybots, but we don't have them
for any platform...

--kcc


>
> On Mon, Apr 25, 2016 at 6:59 PM, Kostya Serebryany  wrote:
>
>> Hopefully fixed by r267513.
>>
>> On Mon, Apr 25, 2016 at 6:46 PM, Kostya Serebryany 
>> wrote:
>>
>>> +rnk
>>>
>>> On Mon, Apr 25, 2016 at 5:09 PM, Jacques Pienaar via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: jpienaar
 Date: Mon Apr 25 19:09:29 2016
 New Revision: 267496

 URL: http://llvm.org/viewvc/llvm-project?rev=267496&view=rev
 Log:
 [lanai] Update handling of structs in arguments to be passed in
 registers.

 Previously aggregate types were passed byval, change the ABI to pass
 these in registers instead.


 Modified:
 cfe/trunk/lib/CodeGen/TargetInfo.cpp
 cfe/trunk/test/CodeGen/lanai-arguments.c

 Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=267496&r1=267495&r2=267496&view=diff

 ==
 --- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
 +++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Apr 25 19:09:29 2016
 @@ -6691,6 +6691,7 @@ public:
I.info = classifyArgumentType(I.type, State);
}

 +  ABIArgInfo getIndirectResult(QualType Ty, bool ByVal, CCState
 &State) const;
ABIArgInfo classifyArgumentType(QualType RetTy, CCState &State)
 const;
  };
  } // end anonymous namespace
 @@ -6712,21 +6713,72 @@ bool LanaiABIInfo::shouldUseInReg(QualTy
return true;
  }

 +ABIArgInfo LanaiABIInfo::getIndirectResult(QualType Ty, bool ByVal,
 +   CCState &State) const {
 +  if (!ByVal) {
 +if (State.FreeRegs) {
 +  --State.FreeRegs; // Non-byval indirects just use one pointer.
 +  return getNaturalAlignIndirectInReg(Ty);
 +}
 +return getNaturalAlignIndirect(Ty, false);
 +  }
 +
 +  // Compute the byval alignment.
 +  constexpr unsigned MinABIStackAlignInBytes = 4;

>>>
>>> This broke the build on Windows;
>>>
>>> C:\b\slave\sanitizer-windows\llvm\tools\clang\lib\CodeGen\TargetInfo.cpp(6727)
>>>  : error C2065: 'constexpr' : undeclared identifier
>>>
>>>
>>>
>>>
>>>
 +  unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8;
 +  return ABIArgInfo::getIndirect(CharUnits::fromQuantity(4),
 /*ByVal=*/true,
 + /*Realign=*/TypeAlign >
 + MinABIStackAlignInBytes);
 +}
 +
  ABIArgInfo LanaiABIInfo::classifyArgumentType(QualType Ty,
CCState &State) const {
 -  if (isAggregateTypeForABI(Ty))
 -return getNaturalAlignIndirect(Ty);
 +  // Check with the C++ ABI first.
 +  const RecordType *RT = Ty->getAs();
 +  if (RT) {
 +CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI());
 +if (RAA == CGCXXABI::RAA_Indirect) {
 +  return getIndirectResult(Ty, /*ByVal=*/false, State);
 +} else if (RAA == CGCXXABI::RAA_DirectInMemory) {
 +  return getNaturalAlignIndirect(Ty, /*ByRef=*/true);
 +}
 +  }
 +
 +  if (isAggregateTypeForABI(Ty)) {
 +// Structures with flexible arrays are always indirect.
 +if (RT && RT->getDecl()->hasFlexibleArrayMember())
 +  return getIndirectResult(Ty, /*ByVal=*/true, State);
 +
 +// Ignore empty structs/unions.
 +if (isEmptyRecord(getContext(), Ty, true))
 +  return ABIArgInfo::getIgnore();
 +
 +llvm::LLVMContext &LLVMContext = getVMContext();
 +unsigned SizeInRegs = (getContext().getTypeSize(Ty) + 31) / 32;
 +if (SizeInRegs <= State.FreeRegs) {
 +  llvm::IntegerType *Int32 = llvm::Type::getInt32Ty(LLVMContext);
 +  SmallVector Elements(SizeInRegs, Int32);
 +  llvm::Type *Result = llvm::StructType::get(LLVMContext,
 Elements);
 +  State.FreeRegs -= SizeInRegs;
 +  return ABIArgInfo::getDirectInReg(Result);
 +} else {
 +  State.FreeRegs = 0;
 +}
 +return getIndirectResult(Ty, true, State);
 +  }

// Treat an enum type as its underlying type.
if (const auto *EnumTy = Ty->getAs())
  Ty = EnumTy->getDecl()->getIntegerType();

 -  if (shouldUseInReg(Ty, State))
 -r

r267584 - [CMake] Use just-built clang and build iOS support when building stage2

2016-04-26 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Tue Apr 26 13:39:20 2016
New Revision: 267584

URL: http://llvm.org/viewvc/llvm-project?rev=267584&view=rev
Log:
[CMake] Use just-built clang and build iOS support when building stage2

The Apple stage2 build should include compiler-rt iOS libraries and be built 
with the stage2 compiler. This matches Apple's production clang builds.

Modified:
cfe/trunk/cmake/caches/Apple-stage2.cmake

Modified: cfe/trunk/cmake/caches/Apple-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Apple-stage2.cmake?rev=267584&r1=267583&r2=267584&view=diff
==
--- cfe/trunk/cmake/caches/Apple-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/Apple-stage2.cmake Tue Apr 26 13:39:20 2016
@@ -17,6 +17,9 @@ set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL
 set(BUG_REPORT_URL "http://developer.apple.com/bugreporter/"; CACHE STRING "")
 set(LLVM_ENABLE_TIMESTAMPS OFF CACHE BOOL "Don't time-stamp shipping builds - 
this makes builds reproducible")
 
+set(LLVM_BUILD_EXTERNAL_COMPILER_RT ON CACHE BOOL "Build Compiler-RT with 
just-built clang")
+set(COMPILER_RT_ENABLE_IOS ON CACHE BOOL "Build iOS Compiler-RT libraries")
+
 # Make unit tests (if present) part of the ALL target
 set(LLVM_BUILD_TESTS ON CACHE BOOL "")
 # Don't build or run the compiler-rt tests


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


[clang-tools-extra] r267587 - [clang-tidy] Added misc-move-const-arg docs.

2016-04-26 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Apr 26 13:48:59 2016
New Revision: 267587

URL: http://llvm.org/viewvc/llvm-project?rev=267587&view=rev
Log:
[clang-tidy] Added misc-move-const-arg docs.

Added:
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst
Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=267587&r1=267586&r2=267587&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Tue Apr 26 13:48:59 
2016
@@ -61,6 +61,7 @@ Clang-Tidy Checks
misc-macro-parentheses
misc-macro-repeated-side-effects
misc-misplaced-widening-cast
+   misc-move-const-arg
misc-move-constructor-init
misc-multiple-statement-macro
misc-new-delete-overloads
@@ -76,7 +77,7 @@ Clang-Tidy Checks
misc-string-literal-with-embedded-nul
misc-suspicious-missing-comma
misc-suspicious-semicolon
-   misc-suspicious-string-compare   
+   misc-suspicious-string-compare
misc-swapped-arguments
misc-throw-by-value-catch-by-reference
misc-undelegated-constructor

Added: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst?rev=267587&view=auto
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst 
(added)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst Tue 
Apr 26 13:48:59 2016
@@ -0,0 +1,15 @@
+.. title:: clang-tidy - misc-move-const-arg
+
+misc-move-const-arg
+===
+
+The check warns if the result of ``std::move(x)`` is bound to a constant
+reference argument, e.g.:
+
+.. code:: c++
+
+  void f(const string&);
+  void g() {
+string s;
+F(std::move(s));  // Warning here. std::move() is not moving anything.
+  }


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


r267590 - [OpenCL] Add predefined macros.

2016-04-26 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Tue Apr 26 14:25:46 2016
New Revision: 267590

URL: http://llvm.org/viewvc/llvm-project?rev=267590&view=rev
Log:
[OpenCL] Add predefined macros.

OpenCL spec requires __OPENCL_C_VERSION__ to be defined based on -cl-std 
option. This patch implements that.

The patch also defines __FAST_RELAXED_MATH__ based on -cl-fast-relaxed-math 
option.

Also fixed a test using -std=c99 for OpenCL program. Limit allowed language 
standard of OpenCL to be OpenCL standards.

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

Removed:
cfe/trunk/test/Frontend/std.cl
Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Frontend/stdlang.c
cfe/trunk/test/Preprocessor/predefined-macros.c

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=267590&r1=267589&r2=267590&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Apr 26 14:25:46 2016
@@ -1495,9 +1495,8 @@ static void ParseLangArgs(LangOptions &O
 << A->getAsString(Args) << "C++/ObjC++";
 break;
   case IK_OpenCL:
-if (!Std.isC99())
-  Diags.Report(diag::err_drv_argument_not_allowed_with)
-<< A->getAsString(Args) << "OpenCL";
+Diags.Report(diag::err_drv_argument_not_allowed_with)
+  << A->getAsString(Args) << "OpenCL";
 break;
   case IK_CUDA:
   case IK_PreprocessedCuda:

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=267590&r1=267589&r2=267590&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Tue Apr 26 14:25:46 2016
@@ -408,6 +408,39 @@ static void InitializeStandardPredefined
   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, __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;
+case 120:
+  Builder.defineMacro("__OPENCL_C_VERSION__", "120");
+  break;
+case 200:
+  Builder.defineMacro("__OPENCL_C_VERSION__", "200");
+  break;
+default:
+  llvm_unreachable("Unsupported OpenCL version");
+}
+Builder.defineMacro("CL_VERSION_1_0", "100");
+Builder.defineMacro("CL_VERSION_1_1", "110");
+Builder.defineMacro("CL_VERSION_1_2", "120");
+Builder.defineMacro("CL_VERSION_2_0", "200");
+
+if (LangOpts.FastRelaxedMath)
+  Builder.defineMacro("__FAST_RELAXED_MATH__");
+  }
   // Not "standard" per se, but available even with the -undef flag.
   if (LangOpts.AsmPreprocessor)
 Builder.defineMacro("__ASSEMBLER__");

Removed: cfe/trunk/test/Frontend/std.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/std.cl?rev=267589&view=auto
==
--- cfe/trunk/test/Frontend/std.cl (original)
+++ cfe/trunk/test/Frontend/std.cl (removed)
@@ -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

Modified: cfe/trunk/test/Frontend/stdlang.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/stdlang.c?rev=267590&r1=267589&r2=267590&view=diff
==
--- cfe/trunk/test/Frontend/stdlang.c (original)
+++ cfe/trunk/test/Frontend/stdlang.c Tue Apr 26 14:25:46 2016
@@ -1,6 +1,13 @@
 // RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s
-// RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -x cl -DOPENCL %s
+// RUN: %clang_cc1 -x cl -cl-std=CL -DOPENCL %s
+// RUN: %clang_cc1 -x cl -cl-std=

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

2016-04-26 Thread Yaxun Liu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL267590: [OpenCL] Add predefined macros. (authored by yaxunl).

Changed prior to commit:
  http://reviews.llvm.org/D19071?vs=55016&id=55066#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19071

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

Index: cfe/trunk/test/Preprocessor/predefined-macros.c
===
--- cfe/trunk/test/Preprocessor/predefined-macros.c
+++ cfe/trunk/test/Preprocessor/predefined-macros.c
@@ -146,3 +146,40 @@
 // 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-CL10-NOT: #define __FAST_RELAXED_MATH__ 1
+// 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-CL11-NOT: #define __FAST_RELAXED_MATH__ 1
+// 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-CL12-NOT: #define __FAST_RELAXED_MATH__ 1
+// 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-CL20-NOT: #define __FAST_RELAXED_MATH__ 1
+// CHECK-FRM: #define __FAST_RELAXED_MATH__ 1
+
Index: cfe/trunk/test/Frontend/stdlang.c
===
--- cfe/trunk/test/Frontend/stdlang.c
+++ cfe/trunk/test/Frontend/stdlang.c
@@ -1,6 +1,13 @@
 // RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s
-// RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -x cl -DOPENCL %s
+// RUN: %clang_cc1 -x cl -cl-std=CL -DOPENCL %s
+// RUN: %clang_cc1 -x cl -cl-std=CL1.1 -DOPENCL %s
+// RUN: %clang_cc1 -x cl -cl-std=CL1.2 -DOPENCL %s
+// RUN: %clang_cc1 -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'
 
 #if defined(CUDA)
   __attribute__((device)) void f_device();
Index: cfe/trunk/test/Frontend/std.cl
===
--- cfe/trunk/test/Frontend/std.cl
+++ cfe/trunk/test/Frontend/std.cl
@@ -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: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -1495,9 +1495,8 @@
 << A->getAsString(Args) << "C++/ObjC++";
 break;
   case IK_OpenCL:
-if (!Std.isC99())
-  Diags.Report(diag::err_drv_argument_not_allowed_with)
-<< A->getAsString(Args) << "OpenCL";
+Diags.Report(diag::err_drv_argument_not_allowed_with)
+  << A->getAsString(Args) << "OpenCL";
 break;
   case IK_CUDA:
   case IK_PreprocessedCuda:
Index: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
==

[libcxx] r267591 - Apparently XFAIL tests that are supposed to fail to compile can be problematic. They still get compiled, and if the compile succeeds, the buildbots complain. Replace the XFAIL with

2016-04-26 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Tue Apr 26 14:29:35 2016
New Revision: 267591

URL: http://llvm.org/viewvc/llvm-project?rev=267591&view=rev
Log:
Apparently XFAIL tests that are supposed to fail to compile can be problematic. 
They still get compiled, and if the compile succeeds, the buildbots complain. 
Replace the XFAIL with #error.

Modified:
libcxx/trunk/test/std/re/re.alg/re.alg.match/basic.fail.cpp
libcxx/trunk/test/std/re/re.alg/re.alg.search/basic.fail.cpp
libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.cnstr/cnstr.fail.cpp
libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/array.fail.cpp
libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/init.fail.cpp
libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/int.fail.cpp
libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.fail.cpp

Modified: libcxx/trunk/test/std/re/re.alg/re.alg.match/basic.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.alg/re.alg.match/basic.fail.cpp?rev=267591&r1=267590&r2=267591&view=diff
==
--- libcxx/trunk/test/std/re/re.alg/re.alg.match/basic.fail.cpp (original)
+++ libcxx/trunk/test/std/re/re.alg/re.alg.match/basic.fail.cpp Tue Apr 26 
14:29:35 2016
@@ -18,12 +18,14 @@
 //regex_constants::match_flag_type = 
 //  regex_constants::match_default) = delete;
 
-// XFAIL: C++98, c++03, c++11
-
 #include 
 #include 
 #include "test_macros.h"
 
+#if TEST_STD_VER < 14
+#error
+#endif
+
 int main()
 {
 {

Modified: libcxx/trunk/test/std/re/re.alg/re.alg.search/basic.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.alg/re.alg.search/basic.fail.cpp?rev=267591&r1=267590&r2=267591&view=diff
==
--- libcxx/trunk/test/std/re/re.alg/re.alg.search/basic.fail.cpp (original)
+++ libcxx/trunk/test/std/re/re.alg/re.alg.search/basic.fail.cpp Tue Apr 26 
14:29:35 2016
@@ -18,12 +18,14 @@
 // regex_constants::match_flag_type = 
 //   regex_constants::match_default) = delete;
 
-// XFAIL: C++98, c++03, c++11
-
 #include 
 #include 
 #include "test_macros.h"
 
+#if TEST_STD_VER < 14
+#error
+#endif
+
 int main()
 {
 {

Modified: 
libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.cnstr/cnstr.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.cnstr/cnstr.fail.cpp?rev=267591&r1=267590&r2=267591&view=diff
==
--- libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.cnstr/cnstr.fail.cpp 
(original)
+++ libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.cnstr/cnstr.fail.cpp 
Tue Apr 26 14:29:35 2016
@@ -17,12 +17,14 @@
 //  regex_constants::match_flag_type m =
 //regex_constants::match_default) = delete;
 
-// XFAIL: C++98, c++03, c++11
-
 #include 
 #include 
 #include "test_macros.h"
 
+#if TEST_STD_VER < 14
+#error
+#endif
+
 int main()
 {
 {

Modified: 
libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/array.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/array.fail.cpp?rev=267591&r1=267590&r2=267591&view=diff
==
--- libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/array.fail.cpp 
(original)
+++ libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/array.fail.cpp 
Tue Apr 26 14:29:35 2016
@@ -18,13 +18,15 @@
 //  regex_constants::match_flag_type m =
 //  
regex_constants::match_default);
 
-// XFAIL: C++98, c++03, c++11
-
 #include 
 #include 
 #include 
 #include "test_macros.h"
 
+#if TEST_STD_VER < 14
+#error
+#endif
+
 int main()
 {
 {

Modified: 
libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/init.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/init.fail.cpp?rev=267591&r1=267590&r2=267591&view=diff
==
--- libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/init.fail.cpp 
(original)
+++ libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/init.fail.cpp 
Tue Apr 26 14:29:35 2016
@@ -17,12 +17,14 @@
 //  regex_constants::match_flag_type m =
 //  
regex_constants::match_default);
 
-// XFAIL: C++98, c++03, c++11
-
 #include 
 #include 
 #include "test_macros.h"
 
+#if TEST_STD_VER < 14
+#error
+#endif
+
 int main()
 {
 {

Modified: 
libcxx/trunk/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/int.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-

[clang-tools-extra] r267592 - [clang-tidy] Now adding correct misc-move-const-arg documentation ; ]

2016-04-26 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Apr 26 14:33:49 2016
New Revision: 267592

URL: http://llvm.org/viewvc/llvm-project?rev=267592&view=rev
Log:
[clang-tidy] Now adding correct misc-move-const-arg documentation ;]

+ brushed the code a bit and renamed the test file to match the check name

Added:
clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp
  - copied, changed from r267587, 
clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp
Removed:
clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst

Modified: clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp?rev=267592&r1=267591&r2=267592&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp Tue 
Apr 26 14:33:49 2016
@@ -20,16 +20,15 @@ using namespace ast_matchers;
 void MoveConstantArgumentCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus)
 return;
-  Finder->addMatcher(callExpr(unless(isInTemplateInstantiation()),
-  callee(functionDecl(hasName("::std::move"
+  Finder->addMatcher(callExpr(callee(functionDecl(hasName("::std::move"))),
+  argumentCountIs(1),
+  unless(isInTemplateInstantiation()))
  .bind("call-move"),
  this);
 }
 
 void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *CallMove = Result.Nodes.getNodeAs("call-move");
-  if (CallMove->getNumArgs() != 1)
-return;
   const Expr *Arg = CallMove->getArg(0);
   SourceManager &SM = Result.Context->getSourceManager();
 
@@ -43,12 +42,12 @@ void MoveConstantArgumentCheck::check(co
 if (!FileMoveRange.isValid())
   return;
 bool IsVariable = isa(Arg);
-auto Diag =
-diag(FileMoveRange.getBegin(), "std::move of the %select{|const }0"
-   "%select{expression|variable}1 "
-   "%select{|of trivially-copyable type }2"
-   "has no effect; remove std::move()")
-<< IsConstArg << IsVariable << IsTriviallyCopyable;
+auto Diag = diag(FileMoveRange.getBegin(),
+ "std::move of the %select{|const }0"
+ "%select{expression|variable}1 "
+ "%select{|of a trivially-copyable type }2"
+ "has no effect; remove std::move()")
+<< IsConstArg << IsVariable << IsTriviallyCopyable;
 
 auto BeforeArgumentsRange = Lexer::makeFileCharRange(
 CharSourceRange::getCharRange(CallMove->getLocStart(),

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst?rev=267592&r1=267591&r2=267592&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-const-arg.rst Tue 
Apr 26 14:33:49 2016
@@ -3,13 +3,13 @@
 misc-move-const-arg
 ===
 
-The check warns if the result of ``std::move(x)`` is bound to a constant
-reference argument, e.g.:
+The check warns if ``std::move()`` is called with a constant argument or an
+argument of a trivially-copyable type, e.g.:
 
 .. code:: c++
 
-  void f(const string&);
-  void g() {
-string s;
-F(std::move(s));  // Warning here. std::move() is not moving anything.
-  }
+  const string s;
+  return std::move(s);  // Warning: std::move of the const variable has no 
effect
+
+  int x;
+  return std::move(x);  // Warning: std::move of the variable of a 
trivially-copyable type has no effect

Copied: clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp (from 
r267587, clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp?p2=clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp&p1=clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp&r1=267587&r2=267592&rev=267592&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/move-const-arg.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp Tue Apr 26 
14:33:49 2016
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-move-const-arg %t -- -- -std=c+

[PATCH] D19552: Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4

2016-04-26 Thread Sunil Srivastava via cfe-commits
Sunil_Srivastava created this revision.
Sunil_Srivastava added a reviewer: dim.
Sunil_Srivastava added a subscriber: cfe-commits.
Herald added a subscriber: emaste.

This is an addendum to r229921.


http://reviews.llvm.org/D19552

Files:
  lib/Analysis/FormatString.cpp
  test/Sema/format-strings-freebsd.c

Index: test/Sema/format-strings-freebsd.c
===
--- test/Sema/format-strings-freebsd.c
+++ test/Sema/format-strings-freebsd.c
@@ -1,10 +1,11 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-scei-ps4 %s
 
 // Test FreeBSD kernel printf extensions.
 int freebsd_kernel_printf(const char *, ...) 
__attribute__((__format__(__freebsd_kprintf__, 1, 2)));
 
-void check_freebsd_kernel_extensions(int i, long l, char *s)
+void check_freebsd_kernel_extensions(int i, long l, char *s, short h)
 {
   // %b expects an int and a char *
   freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning
@@ -32,6 +33,10 @@
   freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 
'long' but the argument has type 'int'}}
   freebsd_kernel_printf("%lr", l); // no-warning
 
+  // h modifier expects a short
+  freebsd_kernel_printf("%hr", i); // expected-warning{{format specifies type 
'short' but the argument has type 'int'}}
+  freebsd_kernel_printf("%hr", h); // no-warning
+
   // %y expects an int
   freebsd_kernel_printf("%y", i); // no-warning
   freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 
'int' but the argument has type 'long'}}
Index: lib/Analysis/FormatString.cpp
===
--- lib/Analysis/FormatString.cpp
+++ lib/Analysis/FormatString.cpp
@@ -694,7 +694,7 @@
   return true;
 case ConversionSpecifier::FreeBSDrArg:
 case ConversionSpecifier::FreeBSDyArg:
-  return Target.getTriple().isOSFreeBSD();
+  return Target.getTriple().isOSFreeBSD() || 
Target.getTriple().isPS4();
 default:
   return false;
   }
@@ -727,7 +727,7 @@
   return true;
 case ConversionSpecifier::FreeBSDrArg:
 case ConversionSpecifier::FreeBSDyArg:
-  return Target.getTriple().isOSFreeBSD();
+  return Target.getTriple().isOSFreeBSD() || 
Target.getTriple().isPS4();
 default:
   return false;
   }


Index: test/Sema/format-strings-freebsd.c
===
--- test/Sema/format-strings-freebsd.c
+++ test/Sema/format-strings-freebsd.c
@@ -1,10 +1,11 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-scei-ps4 %s
 
 // Test FreeBSD kernel printf extensions.
 int freebsd_kernel_printf(const char *, ...) __attribute__((__format__(__freebsd_kprintf__, 1, 2)));
 
-void check_freebsd_kernel_extensions(int i, long l, char *s)
+void check_freebsd_kernel_extensions(int i, long l, char *s, short h)
 {
   // %b expects an int and a char *
   freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning
@@ -32,6 +33,10 @@
   freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
   freebsd_kernel_printf("%lr", l); // no-warning
 
+  // h modifier expects a short
+  freebsd_kernel_printf("%hr", i); // expected-warning{{format specifies type 'short' but the argument has type 'int'}}
+  freebsd_kernel_printf("%hr", h); // no-warning
+
   // %y expects an int
   freebsd_kernel_printf("%y", i); // no-warning
   freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}}
Index: lib/Analysis/FormatString.cpp
===
--- lib/Analysis/FormatString.cpp
+++ lib/Analysis/FormatString.cpp
@@ -694,7 +694,7 @@
   return true;
 case ConversionSpecifier::FreeBSDrArg:
 case ConversionSpecifier::FreeBSDyArg:
-  return Target.getTriple().isOSFreeBSD();
+  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4();
 default:
   return false;
   }
@@ -727,7 +727,7 @@
   return true;
 case ConversionSpecifier::FreeBSDrArg:
 case ConversionSpecifier::FreeBSDyArg:
-  return Target.getTriple().isOSFreeBSD();
+  return Target.getTriple().isOSFreeBSD() || Target.getTriple().isPS4();
 default:
   return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18136: boost-use-to-string check

2016-04-26 Thread Piotr Padlewski via cfe-commits
Prazek marked 5 inline comments as done.


Comment at: clang-tidy/boost/UseToStringCheck.cpp:60
@@ +59,3 @@
+  else
+return;
+

alexfh wrote:
> Please add a reduced test case for this.
I don't see it crashing right now on the same test when it was crashing before, 
so I guess it won't be needed


http://reviews.llvm.org/D18136



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


Re: [PATCH] D18136: boost-use-to-string check

2016-04-26 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 55077.
Prazek marked an inline comment as done.
Prazek added a comment.

I hope it is final


http://reviews.llvm.org/D18136

Files:
  clang-tidy/boost/BoostTidyModule.cpp
  clang-tidy/boost/CMakeLists.txt
  clang-tidy/boost/UseToStringCheck.cpp
  clang-tidy/boost/UseToStringCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/boost-use-to-string.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/boost-use-to-string.cpp

Index: test/clang-tidy/boost-use-to-string.cpp
===
--- /dev/null
+++ test/clang-tidy/boost-use-to-string.cpp
@@ -0,0 +1,149 @@
+// RUN: %check_clang_tidy %s boost-use-to-string %t
+
+namespace std {
+
+template 
+class basic_string {};
+
+using string = basic_string;
+using wstring = basic_string;
+}
+
+namespace boost {
+template 
+T lexical_cast(const V &) {
+  return T();
+};
+}
+
+struct my_weird_type {};
+
+std::string fun(const std::string &) {}
+
+void test_to_string1() {
+
+  auto xa = boost::lexical_cast(5);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::to_string instead of boost::lexical_cast [boost-use-to-string]
+  // CHECK-FIXES: auto xa = std::to_string(5);
+
+  auto z = boost::lexical_cast(42LL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use std::to_string {{..}}
+  // CHECK-FIXES: auto z = std::to_string(42LL);
+
+  // this should not trigger
+  fun(boost::lexical_cast(42.0));
+  auto non = boost::lexical_cast(42);
+  boost::lexical_cast("12");
+}
+
+void test_to_string2() {
+  int a;
+  long b;
+  long long c;
+  unsigned d;
+  unsigned long e;
+  unsigned long long f;
+  float g;
+  double h;
+  long double i;
+  bool j;
+
+  fun(boost::lexical_cast(a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+  // CHECK-FIXES: fun(std::to_string(a));
+  fun(boost::lexical_cast(b));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+  // CHECK-FIXES: fun(std::to_string(b));
+  fun(boost::lexical_cast(c));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+  // CHECK-FIXES: fun(std::to_string(c));
+  fun(boost::lexical_cast(d));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+  // CHECK-FIXES: fun(std::to_string(d));
+  fun(boost::lexical_cast(e));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+  // CHECK-FIXES: fun(std::to_string(e));
+  fun(boost::lexical_cast(f));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+  // CHECK-FIXES: fun(std::to_string(f));
+
+  // No change for floating numbers.
+  fun(boost::lexical_cast(g));
+  fun(boost::lexical_cast(h));
+  fun(boost::lexical_cast(i));
+  // And bool.
+  fun(boost::lexical_cast(j));
+}
+
+std::string fun(const std::wstring &) {}
+
+void test_to_wstring() {
+  int a;
+  long b;
+  long long c;
+  unsigned d;
+  unsigned long e;
+  unsigned long long f;
+  float g;
+  double h;
+  long double i;
+  bool j;
+
+  fun(boost::lexical_cast(a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring instead of boost::lexical_cast [boost-use-to-string]
+  // CHECK-FIXES: fun(std::to_wstring(a));
+  fun(boost::lexical_cast(b));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+  // CHECK-FIXES: fun(std::to_wstring(b));
+  fun(boost::lexical_cast(c));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+  // CHECK-FIXES: fun(std::to_wstring(c));
+  fun(boost::lexical_cast(d));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+  // CHECK-FIXES: fun(std::to_wstring(d));
+  fun(boost::lexical_cast(e));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+  // CHECK-FIXES: fun(std::to_wstring(e));
+  fun(boost::lexical_cast(f));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+  // CHECK-FIXES: fun(std::to_wstring(f));
+
+  // No change for floating numbers
+  fun(boost::lexical_cast(g));
+  fun(boost::lexical_cast(h));
+  fun(boost::lexical_cast(i));
+  // and bool.
+  fun(boost::lexical_cast(j));
+}
+
+const auto glob = boost::lexical_cast(42);
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use std::to_string{{..}}
+// CHECK-FIXES: const auto glob = std::to_string(42);
+
+template 
+void string_as_T(T t = T()) {
+  boost::lexical_cast(42);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use std::to_string{{..}}
+  // CHECK-FIXES: std::to_string(42);
+
+  boost::lexical_cast(42);
+  string_as_T(boost::lexical_cast(42));
+  auto p = boost::lexical_cast(42);
+  auto p2 = (T)boost::lexical_cast(42);
+  auto p3 = static_cast(boost::lexical_cast(42));
+}
+
+#define my_to_string boost::lexical_cast
+
+void no_fixup_inside_macro() {
+  my_to_string(12);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use std::to_string{{..}}
+}
+
+void no_warnings() {
+  fun(boost::lexical_cast("abc"));
+  fun(boost::lexical_cast("abc"));
+  fun(boost::lexical_cast(m

Re: [PATCH] D18136: boost-use-to-string check

2016-04-26 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

Alex, if you accept this revision, please accept this also
http://reviews.llvm.org/D18274


http://reviews.llvm.org/D18136



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


Re: [PATCH] D19552: Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4

2016-04-26 Thread Dimitry Andric via cfe-commits
dim accepted this revision.
dim added a comment.
This revision is now accepted and ready to land.

LGTM.



Comment at: test/Sema/format-strings-freebsd.c:39
@@ -35,1 +38,3 @@
+  freebsd_kernel_printf("%hr", h); // no-warning
+
   // %y expects an int

It's nice to add these for %r, but is there any reason you didn't add similar 
ones for %y? (This is just a minor nit.)


http://reviews.llvm.org/D19552



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


r267601 - Try to get at_file_missing.c passing after LLVM r267556.

2016-04-26 Thread Nico Weber via cfe-commits
Author: nico
Date: Tue Apr 26 15:40:23 2016
New Revision: 267601

URL: http://llvm.org/viewvc/llvm-project?rev=267601&view=rev
Log:
Try to get at_file_missing.c passing after LLVM r267556.

r267556 made backslashes escape the next character
unconditionally in rsp files.  This test echos a path into
a rsp file, and paths contain backslashes on Windows. Since
it's not important for this test to get the filename from
the rsp file, just pass it regularly.

Modified:
cfe/trunk/test/Driver/at_file_missing.c

Modified: cfe/trunk/test/Driver/at_file_missing.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/at_file_missing.c?rev=267601&r1=267600&r2=267601&view=diff
==
--- cfe/trunk/test/Driver/at_file_missing.c (original)
+++ cfe/trunk/test/Driver/at_file_missing.c Tue Apr 26 15:40:23 2016
@@ -1,7 +1,7 @@
 // Make sure that arguments that begin with @ are left as is in the argument
 // stream, and also that @file arguments continue to be processed.
 
-// RUN: echo "%s -D FOO" > %t.args
-// RUN: %clang -rpath @executable_path/../lib @%t.args -### 2>&1 | FileCheck %s
+// RUN: echo "-D FOO" > %t.args
+// RUN: %clang -rpath @executable_path/../lib @%t.args %s -### 2>&1 | 
FileCheck %s
 // CHECK: "-D" "FOO"
 // CHECK: "-rpath" "@executable_path/../lib"


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


Re: [PATCH] D19175: Fix for PR27015 (variable template initialized with a generic lambda expression)

2016-04-26 Thread Akira Hatanaka via cfe-commits
ahatanak added a comment.

I'm looking for a way to avoid the assert in Sema::PerformDependentDiagnostics 
that is fired when a template parameter doesn't have a name.

In order to avoid the assert, CXXRecordDecl::isDependentLambda() should return 
true for the old lambda class, and in order to do that, somehow I have to set 
KnownDependent to true in Sema::ActOnStartOfLambdaDefinition when the lambda is 
used to initialize a variable template.

I can think of two ways to fix this:

1. Make changes in Sema::ActOnTypeParameter to call S->AddDecl(Param) 
regardless of whether Param has a name. This looks harmless to me because the 
list of Scope's decls is used just to see if a declaration belongs to a certain 
scope.

2. Add a field to Scope that indicates whether a variable template is being 
parsed.

Does this sound like a good idea or are there other ways to do what I'm trying 
to do?


http://reviews.llvm.org/D19175



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


r267604 - Test commit

2016-04-26 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Tue Apr 26 15:55:48 2016
New Revision: 267604

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

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

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=267604&r1=267603&r2=267604&view=diff
==
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Apr 26 15:55:48 2016
@@ -37,6 +37,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
+
 using namespace clang;
 using namespace sema;
 


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


Re: [PATCH] D19175: Fix for PR27015 (variable template initialized with a generic lambda expression)

2016-04-26 Thread Richard Smith via cfe-commits
On Tue, Apr 26, 2016 at 1:55 PM, Akira Hatanaka via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> ahatanak added a comment.
>
> I'm looking for a way to avoid the assert in
> Sema::PerformDependentDiagnostics that is fired when a template parameter
> doesn't have a name.
>
> In order to avoid the assert, CXXRecordDecl::isDependentLambda() should
> return true for the old lambda class, and in order to do that, somehow I
> have to set KnownDependent to true in Sema::ActOnStartOfLambdaDefinition
> when the lambda is used to initialize a variable template.
>
> I can think of two ways to fix this:
>
> 1. Make changes in Sema::ActOnTypeParameter to call S->AddDecl(Param)
> regardless of whether Param has a name. This looks harmless to me because
> the list of Scope's decls is used just to see if a declaration belongs to a
> certain scope.
>
> 2. Add a field to Scope that indicates whether a variable template is
> being parsed.
>

I would expect this to go wrong in other contexts too. For instance:
"template void f(int a = []{ return 0; }()) {}"

Does this sound like a good idea or are there other ways to do what I'm
> trying to do?


This is going wrong in SemaLambda.cpp:818 -- it's trying to figure out
whether the lambda appears within a template, but gets the computation
wrong if no template parameters are in scope. (The decls_empty() check is
trying to distinguish between an explicit specialization scope and a "real"
template parameter scope.)

Ultimately, I think this is a bug in the parser -- it's using a single
template parameter scope for a multi-level template parameter list, and
also for the case of an explicit specialization. In the former case, there
should be multiple template parameter scopes, and in the latter case there
should be no scope. I don't think the reuse of the template parameter scope
for a multi-level list matters, but we shouldn't have a template parameter
scope at all if the only template headers are explicit specialization
headers.

You could change Parser::ParseTemplateDeclarationOrSpecialization to track
whether it's only seen explicit specialization 'template<>' headers, and
call 'TemplateParmScope.setFlags(0)' if so. Then remove the decls_empty()
check from SemaLambda.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17933: Set MaxAtomicInlineWidth properly for i386, i486, and x86-64 cpus without cmpxchg16b.

2016-04-26 Thread James Y Knight via cfe-commits
jyknight added a comment.

ping again.


http://reviews.llvm.org/D17933



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


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

2016-04-26 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 55103.
apelete added a comment.

[scan-build] fix logic error warnings emitted on clang code base

Chnages since last revision:

- lib/Format/Format.cpp: removed all changes, redenderd obsolete by upstream.


http://reviews.llvm.org/D19385

Files:
  lib/AST/DeclObjC.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaLookup.cpp
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -297,6 +297,7 @@
   if (!Diags.empty())
 SM = &Diags.front()->path.front()->getLocation().getManager();
 
+  assert(SM && "SourceManager is NULL, cannot iterate through the 
diagnostics");
 
   for (std::vector::iterator DI = Diags.begin(),
DE = Diags.end(); DI != DE; ++DI) {
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -3744,6 +3744,7 @@
   bool AnyVisibleDecls = !NewDecls.empty();
 
   for (/**/; DI != DE; ++DI) {
+assert(*DI && "TypoCorrection iterator cannot be NULL");
 NamedDecl *VisibleDecl = *DI;
 if (!LookupResult::isVisible(SemaRef, *DI))
   VisibleDecl = findAcceptableDecl(SemaRef, *DI);
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -398,8 +398,10 @@
 SourceLocation TypeidLoc,
 Expr *E,
 SourceLocation RParenLoc) {
+  assert(E && "expression operand is NULL, cannot build C++ typeid 
expression");
+
   bool WasEvaluated = false;
-  if (E && !E->isTypeDependent()) {
+  if (!E->isTypeDependent()) {
 if (E->getType()->isPlaceholderType()) {
   ExprResult result = CheckPlaceholderExpr(E);
   if (result.isInvalid()) return ExprError();
Index: lib/Frontend/CompilerInstance.cpp
===
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -742,7 +742,7 @@
 
   // Figure out where to get and map in the main file.
   if (InputFile != "-") {
-const FileEntry *File;
+const FileEntry *File = nullptr;
 if (Opts.FindPchSource.empty()) {
   File = FileMgr.getFile(InputFile, /*OpenFile=*/true);
 } else {
@@ -760,13 +760,14 @@
   SmallVector, 16>
   Includers;
   Includers.push_back(std::make_pair(FindFile, FindFile->getDir()));
-  File = HS->LookupFile(InputFile, SourceLocation(), /*isAngled=*/false,
-/*FromDir=*/nullptr,
-/*CurDir=*/UnusedCurDir, Includers,
-/*SearchPath=*/nullptr,
-/*RelativePath=*/nullptr,
-/*RequestingModule=*/nullptr,
-/*SuggestedModule=*/nullptr, /*SkipCache=*/true);
+  if (HS)
+File = HS->LookupFile(InputFile, SourceLocation(), /*isAngled=*/false,
+  /*FromDir=*/nullptr,
+  /*CurDir=*/UnusedCurDir, Includers,
+  /*SearchPath=*/nullptr,
+  /*RelativePath=*/nullptr,
+  /*RequestingModule=*/nullptr,
+  /*SuggestedModule=*/nullptr, /*SkipCache=*/true);
   // Also add the header to /showIncludes output.
   if (File)
 DepOpts.ShowIncludesPretendHeader = File->getName();
Index: lib/AST/DeclObjC.cpp
===
--- lib/AST/DeclObjC.cpp
+++ lib/AST/DeclObjC.cpp
@@ -1577,8 +1577,10 @@
   data().IvarList = layout[0].Ivar; Ix++;
   curIvar = data().IvarList;
 }
-for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++)
+for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++) {
+  assert(curIvar && "instance variable is NULL, stop iterating through 
layout");
   curIvar->setNextIvar(layout[Ix].Ivar);
+}
   }
 }
   }


Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -297,6 +297,7 @@
   if (!Diags.empty())
 SM = &Diags.front()->path.front()->getLocation().getManager();
 
+  assert(SM && "SourceManager is NULL, cannot iterate through the diagnostics");
 
   for (std::vector::iterator DI = Diags.begin(),
DE = Diags.end(); DI != DE; ++DI) {
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -3744,6 +3744,7 @@
   bo

r267611 - Module debugging: Use the definition to determine module-defined types.

2016-04-26 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Tue Apr 26 16:58:18 2016
New Revision: 267611

URL: http://llvm.org/viewvc/llvm-project?rev=267611&view=rev
Log:
Module debugging: Use the definition to determine module-defined types.

Follow-up to r267464. Thanks to Richard Smith for pointing this out!

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/Modules/ExtDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=267611&r1=267610&r2=267611&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Apr 26 16:58:18 2016
@@ -1516,9 +1516,7 @@ static bool hasExplicitMemberDefinition(
 
 /// Does a type definition exist in an imported clang module?
 static bool isDefinedInClangModule(const RecordDecl *RD) {
-  if (!RD->isFromASTFile())
-return false;
-  if (!RD->getDefinition())
+  if (!RD || !RD->isFromASTFile())
 return false;
   if (!RD->isExternallyVisible() && RD->getName().empty())
 return false;
@@ -1535,7 +1533,7 @@ static bool isDefinedInClangModule(const
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
  bool DebugTypeExtRefs, const RecordDecl *RD,
  const LangOptions &LangOpts) {
-  if (DebugTypeExtRefs && isDefinedInClangModule(RD))
+  if (DebugTypeExtRefs && isDefinedInClangModule(RD->getDefinition()))
 return true;
 
   if (DebugKind > codegenoptions::LimitedDebugInfo)

Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=267611&r1=267610&r2=267611&view=diff
==
--- cfe/trunk/test/Modules/ExtDebugInfo.cpp (original)
+++ cfe/trunk/test/Modules/ExtDebugInfo.cpp Tue Apr 26 16:58:18 2016
@@ -51,6 +51,10 @@ TypedefFwdDeclTemplate tdfdt;
 
 InAnonymousNamespace anon;
 
+// Forward-declared in the module.
+struct PureFwdDecl { int i; };
+PureFwdDecl definedLocally;
+
 void foo() {
   anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
 }
@@ -133,6 +137,11 @@ void foo() {
 // CHECK-SAME: templateParams:
 // CHECK-SAME: identifier: "_ZTS15FwdDeclTemplateIiE")
 
+// This type is defined locally and forward-declare in the module.
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PureFwdDecl",
+// CHECK-SAME: elements:
+// CHECK-SAME: identifier: "_ZTS11PureFwdDecl")
+
 // CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: 
![[ANON_ENUM:[0-9]+]]
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
 // CHECK-SAME: line: 16


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


r267612 - Module debugging: Add testcase for member classes of class template specializations.

2016-04-26 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Tue Apr 26 16:58:23 2016
New Revision: 267612

URL: http://llvm.org/viewvc/llvm-project?rev=267612&view=rev
Log:
Module debugging: Add testcase for member classes of class template 
specializations.

Modified:
cfe/trunk/test/Modules/ExtDebugInfo.cpp
cfe/trunk/test/Modules/Inputs/DebugCXX.h

Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=267612&r1=267611&r2=267612&view=diff
==
--- cfe/trunk/test/Modules/ExtDebugInfo.cpp (original)
+++ cfe/trunk/test/Modules/ExtDebugInfo.cpp Tue Apr 26 16:58:23 2016
@@ -55,6 +55,9 @@ InAnonymousNamespace anon;
 struct PureFwdDecl { int i; };
 PureFwdDecl definedLocally;
 
+struct Specialized::Member { int i; };
+struct Specialized::Member definedLocally2;
+
 void foo() {
   anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
 }
@@ -137,11 +140,16 @@ void foo() {
 // CHECK-SAME: templateParams:
 // CHECK-SAME: identifier: "_ZTS15FwdDeclTemplateIiE")
 
-// This type is defined locally and forward-declare in the module.
+// This type is defined locally and forward-declared in the module.
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PureFwdDecl",
 // CHECK-SAME: elements:
 // CHECK-SAME: identifier: "_ZTS11PureFwdDecl")
 
+// This type is defined locally and forward-declared in the module.
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
+// CHECK-SAME: elements:
+// CHECK-SAME: identifier: "_ZTSN11SpecializedIiE6MemberE")
+
 // CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: 
![[ANON_ENUM:[0-9]+]]
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
 // CHECK-SAME: line: 16

Modified: cfe/trunk/test/Modules/Inputs/DebugCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DebugCXX.h?rev=267612&r1=267611&r2=267612&view=diff
==
--- cfe/trunk/test/Modules/Inputs/DebugCXX.h (original)
+++ cfe/trunk/test/Modules/Inputs/DebugCXX.h Tue Apr 26 16:58:23 2016
@@ -95,3 +95,12 @@ extern template class Template1;
 
 template  class FwdDeclTemplate;
 typedef FwdDeclTemplate TypedefFwdDeclTemplate;
+
+// Member classes of class template specializations.
+template  struct Specialized {
+};
+
+template <> struct Specialized { 
+struct Member;// { int i; };
+};
+


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


Re: r267464 - Module Debugging: Fix the condition for determining whether a template

2016-04-26 Thread Adrian Prantl via cfe-commits

> On Apr 25, 2016, at 5:34 PM, Richard Smith  wrote:
> 
> On Mon, Apr 25, 2016 at 1:52 PM, Adrian Prantl via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: adrian
> Date: Mon Apr 25 15:52:40 2016
> New Revision: 267464
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=267464&view=rev 
> 
> Log:
> Module Debugging: Fix the condition for determining whether a template
> instantiation is in a module.
> 
> This patch fixes the condition for determining whether the debug info for a
> template instantiation will exist in an imported clang module by:
> 
> - checking whether the ClassTemplateSpecializationDecl is complete and
> - checking that the instantiation was in a module by looking at the first 
> field.
> 
> I also added a negative check to make sure that a typedef to a 
> forward-declared
> template (with the definition outside of the module) is handled correctly.
> 
> http://reviews.llvm.org/D19443 
> rdar://problem/25553724
> 
> Modified:
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> cfe/trunk/test/Modules/ExtDebugInfo.cpp
> cfe/trunk/test/Modules/Inputs/DebugCXX.h
> cfe/trunk/test/Modules/ModuleDebugInfo.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=267464&r1=267463&r2=267464&view=diff
>  
> 
> ==
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Apr 25 15:52:40 2016
> @@ -1514,12 +1514,28 @@ static bool hasExplicitMemberDefinition(
>return false;
>  }
> 
> +/// Does a type definition exist in an imported clang module?
> +static bool isDefinedInClangModule(const RecordDecl *RD) {
> +  if (!RD->isFromASTFile())
> +return false;
> +  if (!RD->getDefinition())
> +return false;
> +  if (!RD->isExternallyVisible() && RD->getName().empty())
> +return false;
> +  if (auto *CTSD = dyn_cast(RD)) {
> 
> The same issue also affects member classes of class template specializations 
> (you can detect them with RD->getInstantiatedFromMemberClass(), or detect all 
> the relevant cases at once with RD->getTemplateSpecializationKind()).

I added a testcase for this r267612, but I couldn’t reproduce the situation 
that you were describing here. Do you have an example of what you had in mind?
> 
> +if (!CTSD->isCompleteDefinition())
> +  return false;
> 
> You already checked this a few lines above. Actually, the two checks do 
> different things depending on whether RD or some other declaration is the 
> definition; did you really mean to treat a (non-template) class that's 
> defined locally but forward-declared within a module as being defined in that 
> module? (It might make more sense to map to the definition upfront and do all 
> your queries on that if that's what you intend to check.)

Thanks! I changed this in r267611 to always pass RD->getDefinition() into 
isDefinedInClangModule. Does this make the check for isCompleteDefinition() 
redundant? Looking at the source for TagDecl::getDefinition() I’m not sure.

-- adrian

>  
> +// Make sure the instantiation is actually in a module.
> +if (CTSD->field_begin() != CTSD->field_end())
> +  return CTSD->field_begin()->isFromASTFile();
> +  }
> +  return true;
> +}
> +
>  static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
>   bool DebugTypeExtRefs, const RecordDecl *RD,
>   const LangOptions &LangOpts) {
> -  // Does the type exist in an imported clang module?
> -  if (DebugTypeExtRefs && RD->isFromASTFile() && RD->getDefinition() &&
> -  (RD->isExternallyVisible() || !RD->getName().empty()))
> +  if (DebugTypeExtRefs && isDefinedInClangModule(RD))
>  return true;
> 
>if (DebugKind > codegenoptions::LimitedDebugInfo)
> 
> Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=267464&r1=267463&r2=267464&view=diff
>  
> 
> ==
> --- cfe/trunk/test/Modules/ExtDebugInfo.cpp (original)
> +++ cfe/trunk/test/Modules/ExtDebugInfo.cpp Mon Apr 25 15:52:40 2016
> @@ -2,7 +2,7 @@
>  // Test that only forward declarations are emitted for types dfined in 
> modules.
> 
>  // Modules:
> -// RUN: %clang_cc1 -x objective-c++ -std=c++11 -debug-info-kind=limited \
> +// RUN: %clang_cc1 -x objective-c++ -std=c++11 -debug-info-kind=standalone \
>  // RUN: -dwarf-ext-refs -fmodules   \
>  // 

Re: [PATCH] D19552: Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4

2016-04-26 Thread Sunil Srivastava via cfe-commits
Sunil_Srivastava added a comment.

I had put these 'h' test lines to test the first of my changes, and this 
sufficed, but you are correct. I should add %y too. I am going to add '%hr' and 
'%hy'.



Comment at: test/Sema/format-strings-freebsd.c:39
@@ -35,1 +38,3 @@
+  freebsd_kernel_printf("%hr", h); // no-warning
+
   // %y expects an int

dim wrote:
> It's nice to add these for %r, but is there any reason you didn't add similar 
> ones for %y? (This is just a minor nit.)
I had put these lines to test the first of my changes, and this sufficed, but 
you are correct. I should  add %y too.  I am going to add '%hr' and '%hy'.


http://reviews.llvm.org/D19552



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


[PATCH] D19565: [libc++] Fix an accidental assignment within assert() that should have been equality.

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

[libc++] Fix an accidental assignment within assert() that should have been 
equality.

Fixes MSVC "warning C4706: assignment within conditional expression".

http://reviews.llvm.org/D19565

Files:
  test/std/containers/associative/map/compare.pass.cpp

Index: test/std/containers/associative/map/compare.pass.cpp
===
--- test/std/containers/associative/map/compare.pass.cpp
+++ test/std/containers/associative/map/compare.pass.cpp
@@ -44,7 +44,7 @@
 MapT map;
 IterBool result = map.insert(std::make_pair(Key(0), 42));
 assert(result.second);
-assert(result.first->second = 42);
+assert(result.first->second == 42);
 IterBool result2 = map.insert(std::make_pair(Key(0), 43));
 assert(!result2.second);
 assert(map[Key(0)] == 42);


Index: test/std/containers/associative/map/compare.pass.cpp
===
--- test/std/containers/associative/map/compare.pass.cpp
+++ test/std/containers/associative/map/compare.pass.cpp
@@ -44,7 +44,7 @@
 MapT map;
 IterBool result = map.insert(std::make_pair(Key(0), 42));
 assert(result.second);
-assert(result.first->second = 42);
+assert(result.first->second == 42);
 IterBool result2 = map.insert(std::make_pair(Key(0), 43));
 assert(!result2.second);
 assert(map[Key(0)] == 42);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r267464 - Module Debugging: Fix the condition for determining whether a template

2016-04-26 Thread Richard Smith via cfe-commits
On Tue, Apr 26, 2016 at 3:10 PM, Adrian Prantl via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> On Apr 25, 2016, at 5:34 PM, Richard Smith  wrote:
>
> On Mon, Apr 25, 2016 at 1:52 PM, Adrian Prantl via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: adrian
>> Date: Mon Apr 25 15:52:40 2016
>> New Revision: 267464
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=267464&view=rev
>> Log:
>> Module Debugging: Fix the condition for determining whether a template
>> instantiation is in a module.
>>
>> This patch fixes the condition for determining whether the debug info for
>> a
>> template instantiation will exist in an imported clang module by:
>>
>> - checking whether the ClassTemplateSpecializationDecl is complete and
>> - checking that the instantiation was in a module by looking at the first
>> field.
>>
>> I also added a negative check to make sure that a typedef to a
>> forward-declared
>> template (with the definition outside of the module) is handled correctly.
>>
>> http://reviews.llvm.org/D19443
>> rdar://problem/25553724
>>
>> Modified:
>> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>> cfe/trunk/test/Modules/ExtDebugInfo.cpp
>> cfe/trunk/test/Modules/Inputs/DebugCXX.h
>> cfe/trunk/test/Modules/ModuleDebugInfo.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=267464&r1=267463&r2=267464&view=diff
>>
>> ==
>> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Apr 25 15:52:40 2016
>> @@ -1514,12 +1514,28 @@ static bool hasExplicitMemberDefinition(
>>return false;
>>  }
>>
>> +/// Does a type definition exist in an imported clang module?
>> +static bool isDefinedInClangModule(const RecordDecl *RD) {
>> +  if (!RD->isFromASTFile())
>> +return false;
>> +  if (!RD->getDefinition())
>> +return false;
>> +  if (!RD->isExternallyVisible() && RD->getName().empty())
>> +return false;
>> +  if (auto *CTSD = dyn_cast(RD)) {
>>
>
> The same issue also affects member classes of class template
> specializations (you can detect them with
> RD->getInstantiatedFromMemberClass(), or detect all the relevant cases at
> once with RD->getTemplateSpecializationKind()).
>
>
> I added a testcase for this r267612, but I couldn’t reproduce the
> situation that you were describing here. Do you have an example of what you
> had in mind?
>

Something just like your testcase for class template specializations should
work:

// DebugCXX.h
template  class FwdDeclTemplateMember { class Member; };
typedef FwdDeclTemplateMember::Member TypedefFwdDeclTemplateMember;

// ExtDebugInfo.cpp
template  class FwdDeclTemplateMember::Member { T t; };
TypedefFwdDeclTemplateMember tdfdtm;

> +if (!CTSD->isCompleteDefinition())
>> +  return false;
>>
>
> You already checked this a few lines above. Actually, the two checks do
> different things depending on whether RD or some other declaration is the
> definition; did you really mean to treat a (non-template) class that's
> defined locally but forward-declared within a module as being defined in
> that module? (It might make more sense to map to the definition upfront and
> do all your queries on that if that's what you intend to check.)
>
>
> Thanks! I changed this in r267611 to always pass RD->getDefinition() into
> isDefinedInClangModule. Does this make the check for isCompleteDefinition()
> redundant?
>

Yes. The only other possibility here is that the class is currently being
defined (we're between the open and close braces), but as far as I know you
shouldn't ever see such a class from here, and you should certainly never
see one where the partial definition is imported from an AST file. You
could assert isCompleteDefinition() if you're worried that we might give
you a bad AST.

-- adrian
>
>
>
>> +// Make sure the instantiation is actually in a module.
>> +if (CTSD->field_begin() != CTSD->field_end())
>> +  return CTSD->field_begin()->isFromASTFile();
>> +  }
>> +  return true;
>> +}
>> +
>>  static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
>>   bool DebugTypeExtRefs, const
>> RecordDecl *RD,
>>   const LangOptions &LangOpts) {
>> -  // Does the type exist in an imported clang module?
>> -  if (DebugTypeExtRefs && RD->isFromASTFile() && RD->getDefinition() &&
>> -  (RD->isExternallyVisible() || !RD->getName().empty()))
>> +  if (DebugTypeExtRefs && isDefinedInClangModule(RD))
>>  return true;
>>
>>if (DebugKind > codegenoptions::LimitedDebugInfo)
>>
>> Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=267464&r1=267463&r2=267464&view=diff
>>
>> =

r267625 - Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4

2016-04-26 Thread Sunil Srivastava via cfe-commits
Author: ssrivastava
Date: Tue Apr 26 18:19:00 2016
New Revision: 267625

URL: http://llvm.org/viewvc/llvm-project?rev=267625&view=rev
Log:
Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4

This is an addendum to r229921.

Modified:
cfe/trunk/lib/Analysis/FormatString.cpp
cfe/trunk/test/Sema/format-strings-freebsd.c

Modified: cfe/trunk/lib/Analysis/FormatString.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/FormatString.cpp?rev=267625&r1=267624&r2=267625&view=diff
==
--- cfe/trunk/lib/Analysis/FormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/FormatString.cpp Tue Apr 26 18:19:00 2016
@@ -694,7 +694,7 @@ bool FormatSpecifier::hasValidLengthModi
   return true;
 case ConversionSpecifier::FreeBSDrArg:
 case ConversionSpecifier::FreeBSDyArg:
-  return Target.getTriple().isOSFreeBSD();
+  return Target.getTriple().isOSFreeBSD() || 
Target.getTriple().isPS4();
 default:
   return false;
   }
@@ -727,7 +727,7 @@ bool FormatSpecifier::hasValidLengthModi
   return true;
 case ConversionSpecifier::FreeBSDrArg:
 case ConversionSpecifier::FreeBSDyArg:
-  return Target.getTriple().isOSFreeBSD();
+  return Target.getTriple().isOSFreeBSD() || 
Target.getTriple().isPS4();
 default:
   return false;
   }

Modified: cfe/trunk/test/Sema/format-strings-freebsd.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-freebsd.c?rev=267625&r1=267624&r2=267625&view=diff
==
--- cfe/trunk/test/Sema/format-strings-freebsd.c (original)
+++ cfe/trunk/test/Sema/format-strings-freebsd.c Tue Apr 26 18:19:00 2016
@@ -1,10 +1,11 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-scei-ps4 %s
 
 // Test FreeBSD kernel printf extensions.
 int freebsd_kernel_printf(const char *, ...) 
__attribute__((__format__(__freebsd_kprintf__, 1, 2)));
 
-void check_freebsd_kernel_extensions(int i, long l, char *s)
+void check_freebsd_kernel_extensions(int i, long l, char *s, short h)
 {
   // %b expects an int and a char *
   freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning
@@ -32,6 +33,12 @@ void check_freebsd_kernel_extensions(int
   freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 
'long' but the argument has type 'int'}}
   freebsd_kernel_printf("%lr", l); // no-warning
 
+  // h modifier expects a short
+  freebsd_kernel_printf("%hr", i); // expected-warning{{format specifies type 
'short' but the argument has type 'int'}}
+  freebsd_kernel_printf("%hr", h); // no-warning
+  freebsd_kernel_printf("%hy", i); // expected-warning{{format specifies type 
'short' but the argument has type 'int'}}
+  freebsd_kernel_printf("%hy", h); // no-warning
+
   // %y expects an int
   freebsd_kernel_printf("%y", i); // no-warning
   freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 
'int' but the argument has type 'long'}}


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


Re: [PATCH] D19412: [libcxx] Refactor pthread usage - II

2016-04-26 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 55119.
rmaprath added a comment.

Addressing review comments from @bcraig:

In the earlier patch, I tried to keep the `__os_support` header to a minimum by 
not exposing the internal pthread dependencies (in library sources) in this 
header. This however blew up on me when externalizing the threading support in 
http://reviews.llvm.org/D19415, where I ended up sprinkling a lot of:

  #if defined(_LIBCPP_THREAD_API_PTHREAD)
// Do pthread thing
  #elif defined(_LIBCPP_THREAD_API_EXTERNAL)
// Do other thing
  #else
// Fault
  #endif

Perhaps the mistake was to view these two threading APIs as unrelated. After 
hiding all pthread dependencies behind the corresponding `__os_` functions 
(as suggested), everything falls into place (http://reviews.llvm.org/D19415 
trivially becomes the list of `__os_` function declarations).

I have addressed the remaining review comments along the way. Will update 
http://reviews.llvm.org/D19415 soon.

@bcraig: Hope this is much better?


http://reviews.llvm.org/D19412

Files:
  include/__config
  include/__mutex_base
  include/__os_support
  include/mutex
  include/thread
  src/algorithm.cpp
  src/condition_variable.cpp
  src/memory.cpp
  src/mutex.cpp
  src/thread.cpp

Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -37,6 +37,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+using namespace __libcpp_os_support;
+
 thread::~thread()
 {
 if (__t_ != 0)
@@ -46,7 +48,7 @@
 void
 thread::join()
 {
-int ec = pthread_join(__t_, 0);
+int ec = __os_thread_join(&__t_);
 #ifndef _LIBCPP_NO_EXCEPTIONS
 if (ec)
 throw system_error(error_code(ec, system_category()), "thread::join failed");
@@ -62,7 +64,7 @@
 int ec = EINVAL;
 if (__t_ != 0)
 {
-ec = pthread_detach(__t_);
+ec = __os_thread_detach(&__t_);
 if (ec == 0)
 __t_ = 0;
 }
Index: src/mutex.cpp
===
--- src/mutex.cpp
+++ src/mutex.cpp
@@ -21,15 +21,17 @@
 const try_to_lock_t try_to_lock = {};
 const adopt_lock_t  adopt_lock = {};
 
+using namespace __libcpp_os_support;
+
 mutex::~mutex()
 {
-pthread_mutex_destroy(&__m_);
+__os_mutex_destroy(&__m_);
 }
 
 void
 mutex::lock()
 {
-int ec = pthread_mutex_lock(&__m_);
+int ec = __os_mutex_lock(&__m_);
 if (ec)
 __throw_system_error(ec, "mutex lock failed");
 }
@@ -37,13 +39,13 @@
 bool
 mutex::try_lock() _NOEXCEPT
 {
-return pthread_mutex_trylock(&__m_) == 0;
+return __os_mutex_trylock(&__m_) == 0;
 }
 
 void
 mutex::unlock() _NOEXCEPT
 {
-int ec = pthread_mutex_unlock(&__m_);
+int ec = __os_mutex_unlock(&__m_);
 (void)ec;
 assert(ec == 0);
 }
@@ -52,36 +54,14 @@
 
 recursive_mutex::recursive_mutex()
 {
-pthread_mutexattr_t attr;
-int ec = pthread_mutexattr_init(&attr);
-if (ec)
-goto fail;
-ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-if (ec)
-{
-pthread_mutexattr_destroy(&attr);
-goto fail;
-}
-ec = pthread_mutex_init(&__m_, &attr);
+int ec = __os_mutex_init(&__m_, true);
 if (ec)
-{
-pthread_mutexattr_destroy(&attr);
-goto fail;
-}
-ec = pthread_mutexattr_destroy(&attr);
-if (ec)
-{
-pthread_mutex_destroy(&__m_);
-goto fail;
-}
-return;
-fail:
-__throw_system_error(ec, "recursive_mutex constructor failed");
+__throw_system_error(ec, "recursive_mutex constructor failed");
 }
 
 recursive_mutex::~recursive_mutex()
 {
-int e = pthread_mutex_destroy(&__m_);
+int e = __os_mutex_destroy(&__m_);
 (void)e;
 assert(e == 0);
 }
@@ -89,7 +69,7 @@
 void
 recursive_mutex::lock()
 {
-int ec = pthread_mutex_lock(&__m_);
+int ec = __os_mutex_lock(&__m_);
 if (ec)
 __throw_system_error(ec, "recursive_mutex lock failed");
 }
@@ -97,7 +77,7 @@
 void
 recursive_mutex::unlock() _NOEXCEPT
 {
-int e = pthread_mutex_unlock(&__m_);
+int e = __os_mutex_unlock(&__m_);
 (void)e;
 assert(e == 0);
 }
@@ -105,7 +85,7 @@
 bool
 recursive_mutex::try_lock() _NOEXCEPT
 {
-return pthread_mutex_trylock(&__m_) == 0;
+return __os_mutex_trylock(&__m_) == 0;
 }
 
 // timed_mutex
@@ -165,9 +145,9 @@
 void
 recursive_timed_mutex::lock()
 {
-pthread_t id = pthread_self();
+__libcpp_thread_id id = __os_thread_get_current_id();
 unique_lock lk(__m_);
-if (pthread_equal(id, __id_))
+if (__os_thread_id_compare(id, __id_) == 0)
 {
 if (__count_ == numeric_limits::max())
 __throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached");
@@ -183,9 +163,9 @@
 bool
 recursive_timed_mutex::try_lock() _NOEXCEPT
 {
-pthread_t id = pthread_self();
+__libcpp_thread_id id = __os_thread_get_current_id();
 unique_lock lk(__m_, try_to_lock);
-if (lk.ow

r267630 - Module debugging: Also correctly handle typedef'd foward-declared members.

2016-04-26 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Tue Apr 26 18:37:38 2016
New Revision: 267630

URL: http://llvm.org/viewvc/llvm-project?rev=267630&view=rev
Log:
Module debugging: Also correctly handle typedef'd foward-declared members.
Thanks again to Richard Smith for pointing this out.

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/Modules/ExtDebugInfo.cpp
cfe/trunk/test/Modules/Inputs/DebugCXX.h
cfe/trunk/test/Modules/ModuleDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=267630&r1=267629&r2=267630&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Apr 26 18:37:38 2016
@@ -1520,13 +1520,12 @@ static bool isDefinedInClangModule(const
 return false;
   if (!RD->isExternallyVisible() && RD->getName().empty())
 return false;
-  if (auto *CTSD = dyn_cast(RD)) {
-if (!CTSD->isCompleteDefinition())
-  return false;
-// Make sure the instantiation is actually in a module.
-if (CTSD->field_begin() != CTSD->field_end())
-  return CTSD->field_begin()->isFromASTFile();
-  }
+  if (auto *CXXDecl = dyn_cast(RD))
+if (CXXDecl->getTemplateSpecializationKind() != TSK_Undeclared)
+  // Make sure the instantiation is actually in a module.
+  if (CXXDecl->field_begin() != CXXDecl->field_end())
+return CXXDecl->field_begin()->isFromASTFile();
+
   return true;
 }
 

Modified: cfe/trunk/test/Modules/ExtDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ExtDebugInfo.cpp?rev=267630&r1=267629&r2=267630&view=diff
==
--- cfe/trunk/test/Modules/ExtDebugInfo.cpp (original)
+++ cfe/trunk/test/Modules/ExtDebugInfo.cpp Tue Apr 26 18:37:38 2016
@@ -28,6 +28,8 @@ using DebugCXX::Struct;
 
 Struct s;
 DebugCXX::Enum e;
+
+// Template instantiations.
 DebugCXX::Template implicitTemplate;
 DebugCXX::Template explicitTemplate;
 DebugCXX::FloatInstantiation typedefTemplate;
@@ -51,13 +53,16 @@ TypedefFwdDeclTemplate tdfdt;
 
 InAnonymousNamespace anon;
 
-// Forward-declared in the module.
+// Types that are forward-declared in the module and defined here.
 struct PureFwdDecl { int i; };
 PureFwdDecl definedLocally;
 
 struct Specialized::Member { int i; };
 struct Specialized::Member definedLocally2;
 
+template  struct FwdDeclTemplateMember::Member { T t; };
+TypedefFwdDeclTemplateMember tdfdtm;
+
 void foo() {
   anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
 }
@@ -150,6 +155,12 @@ void foo() {
 // CHECK-SAME: elements:
 // CHECK-SAME: identifier: "_ZTSN11SpecializedIiE6MemberE")
 
+// This type is defined locally and forward-declared in the module.
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
+// CHECK-SAME: elements:
+// CHECK-SAME: identifier: 
"_ZTSN21FwdDeclTemplateMemberIiE6MemberE")
+
+
 // CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: 
![[ANON_ENUM:[0-9]+]]
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
 // CHECK-SAME: line: 16

Modified: cfe/trunk/test/Modules/Inputs/DebugCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DebugCXX.h?rev=267630&r1=267629&r2=267630&view=diff
==
--- cfe/trunk/test/Modules/Inputs/DebugCXX.h (original)
+++ cfe/trunk/test/Modules/Inputs/DebugCXX.h Tue Apr 26 18:37:38 2016
@@ -97,10 +97,11 @@ template  class FwdDeclTemplate
 typedef FwdDeclTemplate TypedefFwdDeclTemplate;
 
 // Member classes of class template specializations.
-template  struct Specialized {
-};
+template  struct Specialized {};
 
-template <> struct Specialized { 
-struct Member;// { int i; };
+template <> struct Specialized {
+  struct Member;
 };
 
+template  struct FwdDeclTemplateMember { struct Member; };
+typedef FwdDeclTemplateMember::Member TypedefFwdDeclTemplateMember;

Modified: cfe/trunk/test/Modules/ModuleDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ModuleDebugInfo.cpp?rev=267630&r1=267629&r2=267630&view=diff
==
--- cfe/trunk/test/Modules/ModuleDebugInfo.cpp (original)
+++ cfe/trunk/test/Modules/ModuleDebugInfo.cpp Tue Apr 26 18:37:38 2016
@@ -130,5 +130,9 @@
 // CHECK-SAME: flags: DIFlagFwdDecl
 // CHECK-SAME: identifier: "_ZTS15FwdDeclTemplateIiE")
 
+// Forward-declared member of a template.
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
+// CHECK-SAME: flags: DIFlagFwdDecl
+// CHECK-SAME: identifier: 
"_ZTSN21FwdDeclTemplateMemberIiE6MemberE")
 
 // CHECK-NEG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: 
"PureFor

r267632 - PR27513: When determining which declaration to put into an exported lookup

2016-04-26 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Apr 26 18:40:43 2016
New Revision: 267632

URL: http://llvm.org/viewvc/llvm-project?rev=267632&view=rev
Log:
PR27513: When determining which declaration to put into an exported lookup
table for a module / PCH, never map from a normal declaration of a class to an
injected-class-name declaration (or vice versa). Those declarations live in
distinct lookup tables and should not be confused.

We really shouldn't be using a CXXRecordDecl to represent an
injected-class-name in the first place; I've filed PR27532 so we don't forget.

Added:
cfe/trunk/test/Modules/Inputs/PR27513/
cfe/trunk/test/Modules/Inputs/PR27513/a.h
cfe/trunk/test/Modules/Inputs/PR27513/b.h
cfe/trunk/test/Modules/Inputs/PR27513/b1.h
cfe/trunk/test/Modules/Inputs/PR27513/b11.h
cfe/trunk/test/Modules/Inputs/PR27513/b111.h
cfe/trunk/test/Modules/Inputs/PR27513/b.h
cfe/trunk/test/Modules/Inputs/PR27513/b1112.h
cfe/trunk/test/Modules/Inputs/PR27513/b2.h
cfe/trunk/test/Modules/Inputs/PR27513/c.h
cfe/trunk/test/Modules/Inputs/PR27513/module.modulemap
cfe/trunk/test/Modules/Inputs/PR27513/mystring.h
cfe/trunk/test/Modules/pr27513.cpp
Modified:
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=267632&r1=267631&r2=267632&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Apr 26 18:40:43 2016
@@ -3107,11 +3107,20 @@ static NamedDecl *getDeclForLocalLookup(
   if (Decl *Redecl = D->getPreviousDecl()) {
 // For Redeclarable decls, a prior declaration might be local.
 for (; Redecl; Redecl = Redecl->getPreviousDecl()) {
-  if (!Redecl->isFromASTFile())
+  // If we find a local decl, we're done.
+  if (!Redecl->isFromASTFile()) {
+// Exception: in very rare cases (for injected-class-names), not all
+// redeclarations are in the same semantic context. Skip ones in a
+// different context. They don't go in this lookup table at all.
+if (!Redecl->getDeclContext()->getRedeclContext()->Equals(
+D->getDeclContext()->getRedeclContext()))
+  continue;
 return cast(Redecl);
+  }
+
   // If we find a decl from a (chained-)PCH stop since we won't find a
   // local one.
-  if (D->getOwningModuleID() == 0)
+  if (Redecl->getOwningModuleID() == 0)
 break;
 }
   } else if (Decl *First = D->getCanonicalDecl()) {

Added: cfe/trunk/test/Modules/Inputs/PR27513/a.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/a.h?rev=267632&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR27513/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/a.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1,5 @@
+#include "b.h"
+
+inline void f() { basic_string s; }
+
+#include "c.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b.h?rev=267632&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR27513/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1,3 @@
+#include "mystring.h"
+#include "b1.h"
+#include "b2.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b1.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b1.h?rev=267632&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR27513/b1.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b1.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1 @@
+#include "b11.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b11.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b11.h?rev=267632&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR27513/b11.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b11.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1,2 @@
+#include "mystring.h"
+#include "b111.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b111.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b111.h?rev=267632&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR27513/b111.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27513/b111.h Tue Apr 26 18:40:43 2016
@@ -0,0 +1,3 @@
+#include "mystring.h"
+#include "b.h"
+#include "b1112.h"

Added: cfe/trunk/test/Modules/Inputs/PR27513/b.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27513/b.h?rev=267632&view=auto
===

r267633 - Module debugging: Add an assertion.

2016-04-26 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Tue Apr 26 18:42:43 2016
New Revision: 267633

URL: http://llvm.org/viewvc/llvm-project?rev=267633&view=rev
Log:
Module debugging: Add an assertion.

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=267633&r1=267632&r2=267633&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Apr 26 18:42:43 2016
@@ -1520,11 +1520,13 @@ static bool isDefinedInClangModule(const
 return false;
   if (!RD->isExternallyVisible() && RD->getName().empty())
 return false;
-  if (auto *CXXDecl = dyn_cast(RD))
+  if (auto *CXXDecl = dyn_cast(RD)) {
+assert(CXXDecl->isCompleteDefinition() && "incomplete record definition");
 if (CXXDecl->getTemplateSpecializationKind() != TSK_Undeclared)
   // Make sure the instantiation is actually in a module.
   if (CXXDecl->field_begin() != CXXDecl->field_end())
 return CXXDecl->field_begin()->isFromASTFile();
+  }
 
   return true;
 }


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


Re: [PATCH] D19415: [libcxx][rfc] Externalized threading support

2016-04-26 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 55127.
rmaprath added a comment.

Addressing review comments from @bcraig:

Adjusted according to the changes of http://reviews.llvm.org/D19412. This patch 
is now mostly trivial.

There is a small catch in that, this version of the API takes 
pointer-to-pointer type arguments for most `__os_xxx` functions. This is partly 
because we need to use opaque pointer types to hide the underlying 
implementation details from libcxx internals. This can be worked-around by 
using some template hackery (along the lines of `is_pointer`), but I thought to 
leave it as it is to avoid cluttering up the sources for the normal use case.


http://reviews.llvm.org/D19415

Files:
  include/__os_support

Index: include/__os_support
===
--- include/__os_support
+++ include/__os_support
@@ -186,7 +186,71 @@
 pthread_setspecific(__key, __p);
 }
 
-#else // !_LIBCPP_THREAD_API_PTHREAD
+#elif defined(_LIBCPP_THREAD_API_EXTERNAL)
+
+// Mutex
+#define __OS_MUTEX_INITIALIZER 0
+struct __libcpp_mutex_external;
+typedef __libcpp_mutex_external* __libcpp_mutex;
+
+int __os_mutex_init(__libcpp_mutex* __m, bool is_recursive);
+
+int __os_mutex_lock(__libcpp_mutex* __m);
+
+int __os_mutex_trylock(__libcpp_mutex* __m);
+
+int __os_mutex_unlock(__libcpp_mutex* __m);
+
+int __os_mutex_destroy(__libcpp_mutex* __m);
+
+// Condition variable
+#define __OS_COND_INITIALIZER 0
+struct __libcpp_condvar_external;
+typedef __libcpp_condvar_external* __libcpp_condvar;
+
+int __os_condvar_signal(__libcpp_condvar* __cv);
+
+int __os_condvar_broadcast(__libcpp_condvar* __cv);
+
+int __os_condvar_wait(__libcpp_condvar* __cv, __libcpp_mutex* __m);
+
+int __os_condvar_timedwait(__libcpp_condvar* __cv, __libcpp_mutex* __m, 
timespec* __ts);
+
+int __os_condvar_destroy(__libcpp_condvar* __cv);
+
+// Thread id
+typedef unsigned long __libcpp_thread_id;
+
+int __os_thread_id_compare(__libcpp_thread_id t1, __libcpp_thread_id t2);
+
+// Thread
+struct __libcpp_thread_external;
+typedef __libcpp_thread_external* __libcpp_thread;
+
+template
+int __os_thread_create(__libcpp_thread* __t, _Func&& __f, _Arg&& __arg);
+
+__libcpp_thread_id __os_thread_get_current_id();
+
+__libcpp_thread_id __os_thread_get_id(const __libcpp_thread* __t);
+
+int __os_thread_join(__libcpp_thread* __t);
+
+int __os_thread_detach(__libcpp_thread* __t);
+
+void __os_thread_yield();
+
+// Thread local storage
+typedef unsigned long __libcpp_tl_key;
+
+template
+int __os_tl_create(__libcpp_tl_key* __key, _Func&& __at_exit);
+
+void* __os_tl_get(__libcpp_tl_key __key);
+
+void __os_tl_set(__libcpp_tl_key __key, void* __p);
+
+#else
   #error "No thread API selected."
 #endif
 


Index: include/__os_support
===
--- include/__os_support
+++ include/__os_support
@@ -186,7 +186,71 @@
 pthread_setspecific(__key, __p);
 }
 
-#else // !_LIBCPP_THREAD_API_PTHREAD
+#elif defined(_LIBCPP_THREAD_API_EXTERNAL)
+
+// Mutex
+#define __OS_MUTEX_INITIALIZER 0
+struct __libcpp_mutex_external;
+typedef __libcpp_mutex_external* __libcpp_mutex;
+
+int __os_mutex_init(__libcpp_mutex* __m, bool is_recursive);
+
+int __os_mutex_lock(__libcpp_mutex* __m);
+
+int __os_mutex_trylock(__libcpp_mutex* __m);
+
+int __os_mutex_unlock(__libcpp_mutex* __m);
+
+int __os_mutex_destroy(__libcpp_mutex* __m);
+
+// Condition variable
+#define __OS_COND_INITIALIZER 0
+struct __libcpp_condvar_external;
+typedef __libcpp_condvar_external* __libcpp_condvar;
+
+int __os_condvar_signal(__libcpp_condvar* __cv);
+
+int __os_condvar_broadcast(__libcpp_condvar* __cv);
+
+int __os_condvar_wait(__libcpp_condvar* __cv, __libcpp_mutex* __m);
+
+int __os_condvar_timedwait(__libcpp_condvar* __cv, __libcpp_mutex* __m, timespec* __ts);
+
+int __os_condvar_destroy(__libcpp_condvar* __cv);
+
+// Thread id
+typedef unsigned long __libcpp_thread_id;
+
+int __os_thread_id_compare(__libcpp_thread_id t1, __libcpp_thread_id t2);
+
+// Thread
+struct __libcpp_thread_external;
+typedef __libcpp_thread_external* __libcpp_thread;
+
+template
+int __os_thread_create(__libcpp_thread* __t, _Func&& __f, _Arg&& __arg);
+
+__libcpp_thread_id __os_thread_get_current_id();
+
+__libcpp_thread_id __os_thread_get_id(const __libcpp_thread* __t);
+
+int __os_thread_join(__libcpp_thread* __t);
+
+int __os_thread_detach(__libcpp_thread* __t);
+
+void __os_thread_yield();
+
+// Thread local storage
+typedef unsigned long __libcpp_tl_key;
+
+template
+int __os_tl_create(__libcpp_tl_key* __key, _Func&& __at_exit);
+
+void* __os_tl_get(__libcpp_tl_key __key);
+
+void __os_tl_set(__libcpp_tl_key __key, void* __p);
+
+#else
   #error "No thread API selected."
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r267464 - Module Debugging: Fix the condition for determining whether a template

2016-04-26 Thread Adrian Prantl via cfe-commits

> On Apr 26, 2016, at 4:11 PM, Richard Smith  wrote:
> 
> On Tue, Apr 26, 2016 at 3:10 PM, Adrian Prantl via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> 
>> On Apr 25, 2016, at 5:34 PM, Richard Smith > > wrote:
>> 
>> On Mon, Apr 25, 2016 at 1:52 PM, Adrian Prantl via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> Author: adrian
>> Date: Mon Apr 25 15:52:40 2016
>> New Revision: 267464
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=267464&view=rev 
>> 
>> Log:
>> Module Debugging: Fix the condition for determining whether a template
>> instantiation is in a module.
>> 
>> This patch fixes the condition for determining whether the debug info for a
>> template instantiation will exist in an imported clang module by:
>> 
>> - checking whether the ClassTemplateSpecializationDecl is complete and
>> - checking that the instantiation was in a module by looking at the first 
>> field.
>> 
>> I also added a negative check to make sure that a typedef to a 
>> forward-declared
>> template (with the definition outside of the module) is handled correctly.
>> 
>> http://reviews.llvm.org/D19443 
>> rdar://problem/25553724 <>
>> 
>> Modified:
>> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>> cfe/trunk/test/Modules/ExtDebugInfo.cpp
>> cfe/trunk/test/Modules/Inputs/DebugCXX.h
>> cfe/trunk/test/Modules/ModuleDebugInfo.cpp
>> 
>> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=267464&r1=267463&r2=267464&view=diff
>>  
>> 
>> ==
>> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Apr 25 15:52:40 2016
>> @@ -1514,12 +1514,28 @@ static bool hasExplicitMemberDefinition(
>>return false;
>>  }
>> 
>> +/// Does a type definition exist in an imported clang module?
>> +static bool isDefinedInClangModule(const RecordDecl *RD) {
>> +  if (!RD->isFromASTFile())
>> +return false;
>> +  if (!RD->getDefinition())
>> +return false;
>> +  if (!RD->isExternallyVisible() && RD->getName().empty())
>> +return false;
>> +  if (auto *CTSD = dyn_cast(RD)) {
>> 
>> The same issue also affects member classes of class template specializations 
>> (you can detect them with RD->getInstantiatedFromMemberClass(), or detect 
>> all the relevant cases at once with RD->getTemplateSpecializationKind()).
> 
> I added a testcase for this r267612, but I couldn’t reproduce the situation 
> that you were describing here. Do you have an example of what you had in mind?
> 
> Something just like your testcase for class template specializations should 
> work:
> 
> // DebugCXX.h
> template  class FwdDeclTemplateMember { class Member; };
> typedef FwdDeclTemplateMember::Member TypedefFwdDeclTemplateMember;
> 
> // ExtDebugInfo.cpp
> template  class FwdDeclTemplateMember::Member { T t; };
> TypedefFwdDeclTemplateMember tdfdtm;

Thanks, that does the trick! Fixed in r267630.

>> +if (!CTSD->isCompleteDefinition())
>> +  return false;
>> 
>> You already checked this a few lines above. Actually, the two checks do 
>> different things depending on whether RD or some other declaration is the 
>> definition; did you really mean to treat a (non-template) class that's 
>> defined locally but forward-declared within a module as being defined in 
>> that module? (It might make more sense to map to the definition upfront and 
>> do all your queries on that if that's what you intend to check.)
> 
> Thanks! I changed this in r267611 to always pass RD->getDefinition() into 
> isDefinedInClangModule. Does this make the check for isCompleteDefinition() 
> redundant?
> 
> Yes. The only other possibility here is that the class is currently being 
> defined (we're between the open and close braces), but as far as I know you 
> shouldn't ever see such a class from here, and you should certainly never see 
> one where the partial definition is imported from an AST file. You could 
> assert isCompleteDefinition() if you're worried that we might give you a bad 
> AST.

I added the assertion in r267633.

-- adrian
> 
>>  
>> +// Make sure the instantiation is actually in a module.
>> +if (CTSD->field_begin() != CTSD->field_end())
>> +  return CTSD->field_begin()->isFromASTFile();
>> +  }
>> +  return true;
>> +}
>> +
>>  static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
>>   bool DebugTypeExtRefs, const RecordDecl 
>> *RD,
>>   const LangOptions &LangOpts) {
>> -  // Does the type exist in an imported clang module?
>> -  if (DebugTypeExtRefs && RD->isFromASTFile() && RD->getDefinit

[PATCH] D19567: PR21823: 'nodebug' attribute on global/static variables

2016-04-26 Thread Paul Robinson via cfe-commits
probinson created this revision.
probinson added reviewers: dblaikie, aprantl.
probinson added a subscriber: cfe-commits.

'nodebug' on a function will currently suppress all debug info for the function 
and its contents.
'nodebug on a static-duration variable will currently suppress debug info for 
the associated static initializer function (if any).
This patch suppresses all debug info for the variable, as requested in PR21823.

As a follow-up I'd like to expand applicability of 'nodebug' to any variable, 
and non-static data members.


http://reviews.llvm.org/D19567

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGenCXX/debug-info-nodebug.cpp

Index: test/CodeGenCXX/debug-info-nodebug.cpp
===
--- test/CodeGenCXX/debug-info-nodebug.cpp
+++ test/CodeGenCXX/debug-info-nodebug.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -DSETNODEBUG=0 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=YESINFO
+// RUN: %clang_cc1 -DSETNODEBUG=1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=NOINFO
+
+#if SETNODEBUG
+#define NODEBUG __attribute__((nodebug))
+#else
+#define NODEBUG
+#endif
+
+// Simple global variable declaration and definition.
+// Use the declaration so it gets emitted.
+NODEBUG int global_int_decl;
+NODEBUG int global_int_def = global_int_decl;
+// YESINFO-DAG: !DIGlobalVariable(name: "global_int_decl"
+// NOINFO-NOT:  !DIGlobalVariable(name: "global_int_decl"
+// YESINFO-DAG: !DIGlobalVariable(name: "global_int_def"
+// NOINFO-NOT:  !DIGlobalVariable(name: "global_int_def"
+
+// Const global variable. Use it so it gets emitted.
+NODEBUG static const int const_global_int_def = 1;
+void func1(int);
+void func2() { func1(const_global_int_def); }
+// YESINFO-DAG: !DIGlobalVariable(name: "const_global_int_def"
+// NOINFO-NOT:  !DIGlobalVariable(name: "const_global_int_def"
+
+// Global variable with a more involved type.
+// If the variable has no debug info, the type should not appear either.
+struct S1 {
+  int a;
+  int b;
+};
+NODEBUG S1 global_struct = { 2, 3 };
+// YESINFO-DAG: !DICompositeType({{.*}} name: "S1"
+// NOINFO-NOT:  !DICompositeType({{.*}} name: "S1"
+// YESINFO-DAG: !DIGlobalVariable(name: "global_struct"
+// NOINFO-NOT:  !DIGlobalVariable(name: "global_struct"
+
+// Static data members. Const member needs a use.
+struct S2 {
+  NODEBUG static int static_member;
+  NODEBUG static const int static_const_member = 4;
+};
+int S2::static_member = 5;
+int junk = S2::static_const_member;
+// YESINFO-DAG: !DIGlobalVariable(name: "static_member"
+// NOINFO-NOT:  !DIGlobalVariable(name: "static_member"
+// YESINFO-DAG: !DIDerivedType({{.*}} name: "static_const_member"
+// NOINFO-NOT:  !DIDerivedType({{.*}} name: "static_const_member"
+
+// Function-local static variable.
+void func3() {
+  NODEBUG static int func_local = 6;
+}
+// YESINFO-DAG: !DIGlobalVariable(name: "func_local"
+// NOINFO-NOT:  !DIGlobalVariable(name: "func_local"
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -1014,6 +1014,8 @@
 // the corresponding declarations in the source program.
 for (const auto *I : record->decls())
   if (const auto *V = dyn_cast(I)) {
+if (V->hasAttr())
+  continue;
 // Reuse the existing static member declaration if one exists
 auto MI = StaticDataMemberCache.find(V->getCanonicalDecl());
 if (MI != StaticDataMemberCache.end()) {
@@ -3391,6 +3393,8 @@
 void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
  const VarDecl *D) {
   assert(DebugKind >= codegenoptions::LimitedDebugInfo);
+  if (D->hasAttr())
+return;
   // Create global variable debug descriptor.
   llvm::DIFile *Unit = nullptr;
   llvm::DIScope *DContext = nullptr;
@@ -3423,6 +3427,8 @@
 void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD,
  llvm::Constant *Init) {
   assert(DebugKind >= codegenoptions::LimitedDebugInfo);
+  if (VD->hasAttr())
+return;
   // Create the descriptor for the variable.
   llvm::DIFile *Unit = getOrCreateFile(VD->getLocation());
   StringRef Name = VD->getName();
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -494,6 +494,15 @@
   }];
 }
 
+def NoDebugDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``nodebug`` attribute allows you to suppress debugging information for a
+function, or for a variable declared with static storage duration, such as
+globals, class static data members, and static locals.
+  }];
+}
+
 def NoDuplicateDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
Index: in

Re: [PATCH] D19567: PR21823: 'nodebug' attribute on global/static variables

2016-04-26 Thread Aaron Ballman via cfe-commits
aaron.ballman added a subscriber: aaron.ballman.
aaron.ballman accepted this revision.
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM on the attribute part. Someone else should pipe up if the debug info part 
looks incorrect, but it looks reasonable to me.



Comment at: include/clang/Basic/Attr.td:976
@@ -975,3 +975,3 @@
   let Spellings = [GCC<"nodebug">];
-  let Documentation = [Undocumented];
+  let Documentation = [NoDebugDocs];
 }

This isn't your problem to fix (though I would not complain if you did fix 
it!), but the lack of a Subjects line should be fixed at some point.


http://reviews.llvm.org/D19567



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


Re: [PATCH] D19552: Check 'r' and 'y specifiers of freebsd_kernel_printf format strings on PS4

2016-04-26 Thread Sunil Srivastava via cfe-commits
Sunil_Srivastava closed this revision.
Sunil_Srivastava added a comment.

Submitted as r267625.


http://reviews.llvm.org/D19552



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


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

2016-04-26 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/Sema/SemaDecl.cpp:5044-5045
@@ -5043,4 +5043,4 @@
   // 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

Can we delete the invalid-decl check entirely here? If it's doing something 
important, we need to figure out what and make sure we preserve that intent if 
it's important, but either way it doesn't make a lot of sense to me for this to 
depend on whether the declaration has a definition.


http://reviews.llvm.org/D19327



___
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-26 Thread Paul Robinson via cfe-commits
probinson accepted this revision.
probinson added a reviewer: probinson.
probinson added a comment.
This revision is now accepted and ready to land.

LGTM.


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: r267534 - [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-26 Thread Richard Smith via cfe-commits
As noted in PR27337, this only occurs in one WTL sample, and we have no
evidence that it actually occurs in real code. Have you seen uses of this
in the wild? We generally don't want to add compatibility for MSVC bugs
unless there's some real-world motivation.

On Tue, Apr 26, 2016 at 2:21 AM, Dmitry Polukhin via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: dpolukhin
> Date: Tue Apr 26 04:21:17 2016
> New Revision: 267534
>
> URL: http://llvm.org/viewvc/llvm-project?rev=267534&view=rev
> Log:
> [MSVC] PR27337: allow static_cast from private base to derived for WTL
>
> MSVC doesn't report even warning for cast from private base class to
> derived.
>
> Differential Revision: http://reviews.llvm.org/D19477
>
> Added:
> cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp   (with props)
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaCast.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267534&r1=267533&r2=267534&view=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 26
> 04:21:17 2016
> @@ -5764,6 +5764,9 @@ def err_static_downcast_via_virtual : Er
>"cannot cast %0 to %1 via virtual base %2">;
>  def err_downcast_from_inaccessible_base : Error<
>"cannot cast %select{private|protected}2 base class %1 to %0">;
> +def ext_ms_downcast_from_inaccessible_base : ExtWarn<
> +  "casting from %select{private|protected}2 base class %1 to derived
> class %0 is a Microsoft extension">,
> +  InGroup;
>  def err_upcast_to_inaccessible_base : Error<
>"cannot cast %0 to its %select{private|protected}2 base class %1">;
>  def err_bad_dynamic_cast_not_ref_or_ptr : Error<
>
> Modified: cfe/trunk/lib/Sema/SemaCast.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=267534&r1=267533&r2=267534&view=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaCast.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaCast.cpp Tue Apr 26 04:21:17 2016
> @@ -1344,10 +1344,11 @@ TryStaticDowncast(Sema &Self, CanQualTyp
>}
>
>if (!CStyle) {
> -switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
> -  SrcType, DestType,
> -  Paths.front(),
> -
> diag::err_downcast_from_inaccessible_base)) {
> +unsigned Diag = Self.getLangOpts().MSVCCompat
> +? diag::ext_ms_downcast_from_inaccessible_base
> +: diag::err_downcast_from_inaccessible_base;
> +switch (Self.CheckBaseClassAccess(OpRange.getBegin(), SrcType,
> DestType,
> +  Paths.front(), Diag)) {
>  case Sema::AR_accessible:
>  case Sema::AR_delayed: // be optimistic
>  case Sema::AR_dependent:   // be optimistic
>
> Added: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp?rev=267534&view=auto
>
> ==
> --- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp (added)
> +++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp Tue Apr 26 04:21:17 2016
> @@ -0,0 +1,40 @@
> +// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s
> +// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s
> +
> +// Minimal reproducer.
> +class A {};
> +class B : A {}; // expected-note 2 {{implicitly declared private here}}
> +
> +B* foo(A* p) {
> +  return static_cast(p);
> +#ifdef NO_MS_COMPATIBILITY
> +  // expected-error@-2 {{cannot cast private base class 'A' to 'B'}}
> +#else
> +  // expected-warning@-4 {{casting from private base class 'A' to
> derived class 'B' is a Microsoft extension}}
> +#endif
> +}
> +
> +A* bar(B* p) {
> +  return static_cast(p); // expected-error {{cannot cast 'B' to its
> private base class 'A'}}
> +}
> +
> +// from atlframe.h
> +template 
> +class CUpdateUI {
> +public:
> +  CUpdateUI() {
> +T* pT = static_cast(this);
> +#ifdef NO_MS_COMPATIBILITY
> +// expected-error@-2 {{cannot cast private base class}}
> +#else
> +// expected-warning@-4 {{casting from private base class
> 'CUpdateUI' to derived class 'CMDIFrame' is a Microsoft
> extension}}
> +#endif
> +  }
> +};
> +
> +// from sample WTL/MDIDocVw (mainfrm.h
> +class CMDIFrame : CUpdateUI {};
> +// expected-note@-1 {{implicitly declared private here}}
> +// expected-note@-2 {{in instantiation of member function}}
> +
> +CMDIFrame wndMain;
>
> Propchange: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
>
> --
> svn:eol-style = native
>
> Propchange: cfe/trunk/test/S

Re: [PATCH] D19565: [libc++] Fix an accidental assignment within assert() that should have been equality.

2016-04-26 Thread Marshall Clow via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.
This revision is now accepted and ready to land.

Whoops!  LGTM.


http://reviews.llvm.org/D19565



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


Re: [PATCH] D18641: [PP] Handle #include_next after include found relative to current one same as GCC

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

I'm a little concerned about the possibility of this breaking uses of this 
feature on platforms where Clang is the system compiler. For instance, this 
pattern would be broken by your change:

  // stddef.h
  #include "stddef-helper.h"
  
  // stddef-helper.h
  #include_next 

Conversely, I don't think any important library is likely to be relying on the 
GCC behavior, because compilations with "gcc -I-" would get the current Clang 
behavior (because relative-looking paths would be found in the relevant include 
search path rather than as relative paths).

Is there some way we can gain confidence we're not breaking things here?



Comment at: include/clang/Basic/DiagnosticLexKinds.td:268-269
@@ -267,4 +267,4 @@
   "the #__include_macros directive is only for internal use by -imacros">;
-def pp_include_next_absolute_path : Warning<
-  "#include_next with absolute path">,
+def pp_include_next_without_state : Warning<
+  "#include_next without previous state, searching from the beginning of the 
include directories list">,
   InGroup>;

Can you distinguish between the two cases here and give better diagnostics for 
both?

  "#include_next in file found by relative path, searching from [...]"
  "#include_next with absolute path, searching from [...]"

would be an improvement on this.


http://reviews.llvm.org/D18641



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


[libcxx] r267654 - Fix = that should have been == in test. Thanks to STL@microsoft for the catch

2016-04-26 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Tue Apr 26 20:46:43 2016
New Revision: 267654

URL: http://llvm.org/viewvc/llvm-project?rev=267654&view=rev
Log:
Fix = that should have been == in test. Thanks to STL@microsoft for the catch

Modified:
libcxx/trunk/test/std/containers/associative/map/compare.pass.cpp

Modified: libcxx/trunk/test/std/containers/associative/map/compare.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/map/compare.pass.cpp?rev=267654&r1=267653&r2=267654&view=diff
==
--- libcxx/trunk/test/std/containers/associative/map/compare.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/associative/map/compare.pass.cpp Tue Apr 
26 20:46:43 2016
@@ -44,7 +44,7 @@ int main()
 MapT map;
 IterBool result = map.insert(std::make_pair(Key(0), 42));
 assert(result.second);
-assert(result.first->second = 42);
+assert(result.first->second == 42);
 IterBool result2 = map.insert(std::make_pair(Key(0), 43));
 assert(!result2.second);
 assert(map[Key(0)] == 42);


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


Re: [PATCH] D19565: [libc++] Fix an accidental assignment within assert() that should have been equality.

2016-04-26 Thread Marshall Clow via cfe-commits
mclow.lists closed this revision.
mclow.lists added a comment.

Committed as revision 267654.


http://reviews.llvm.org/D19565



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


Re: r267534 - [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-26 Thread David Majnemer via cfe-commits
Visual Studio 2015 (19.00.23720.0) reports:

error C2243: 'static_cast': conversion from 'B *' to 'A *' exists, but is
inaccessible

On Tue, Apr 26, 2016 at 6:33 PM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> As noted in PR27337, this only occurs in one WTL sample, and we have no
> evidence that it actually occurs in real code. Have you seen uses of this
> in the wild? We generally don't want to add compatibility for MSVC bugs
> unless there's some real-world motivation.
>
>
> On Tue, Apr 26, 2016 at 2:21 AM, Dmitry Polukhin via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: dpolukhin
>> Date: Tue Apr 26 04:21:17 2016
>> New Revision: 267534
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=267534&view=rev
>> Log:
>> [MSVC] PR27337: allow static_cast from private base to derived for WTL
>>
>> MSVC doesn't report even warning for cast from private base class to
>> derived.
>>
>> Differential Revision: http://reviews.llvm.org/D19477
>>
>> Added:
>> cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp   (with props)
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/lib/Sema/SemaCast.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267534&r1=267533&r2=267534&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 26
>> 04:21:17 2016
>> @@ -5764,6 +5764,9 @@ def err_static_downcast_via_virtual : Er
>>"cannot cast %0 to %1 via virtual base %2">;
>>  def err_downcast_from_inaccessible_base : Error<
>>"cannot cast %select{private|protected}2 base class %1 to %0">;
>> +def ext_ms_downcast_from_inaccessible_base : ExtWarn<
>> +  "casting from %select{private|protected}2 base class %1 to derived
>> class %0 is a Microsoft extension">,
>> +  InGroup;
>>  def err_upcast_to_inaccessible_base : Error<
>>"cannot cast %0 to its %select{private|protected}2 base class %1">;
>>  def err_bad_dynamic_cast_not_ref_or_ptr : Error<
>>
>> Modified: cfe/trunk/lib/Sema/SemaCast.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=267534&r1=267533&r2=267534&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaCast.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaCast.cpp Tue Apr 26 04:21:17 2016
>> @@ -1344,10 +1344,11 @@ TryStaticDowncast(Sema &Self, CanQualTyp
>>}
>>
>>if (!CStyle) {
>> -switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
>> -  SrcType, DestType,
>> -  Paths.front(),
>> -
>> diag::err_downcast_from_inaccessible_base)) {
>> +unsigned Diag = Self.getLangOpts().MSVCCompat
>> +? diag::ext_ms_downcast_from_inaccessible_base
>> +: diag::err_downcast_from_inaccessible_base;
>> +switch (Self.CheckBaseClassAccess(OpRange.getBegin(), SrcType,
>> DestType,
>> +  Paths.front(), Diag)) {
>>  case Sema::AR_accessible:
>>  case Sema::AR_delayed: // be optimistic
>>  case Sema::AR_dependent:   // be optimistic
>>
>> Added: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp?rev=267534&view=auto
>>
>> ==
>> --- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp (added)
>> +++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp Tue Apr 26 04:21:17 2016
>> @@ -0,0 +1,40 @@
>> +// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s
>> +// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s
>> +
>> +// Minimal reproducer.
>> +class A {};
>> +class B : A {}; // expected-note 2 {{implicitly declared private here}}
>> +
>> +B* foo(A* p) {
>> +  return static_cast(p);
>> +#ifdef NO_MS_COMPATIBILITY
>> +  // expected-error@-2 {{cannot cast private base class 'A' to 'B'}}
>> +#else
>> +  // expected-warning@-4 {{casting from private base class 'A' to
>> derived class 'B' is a Microsoft extension}}
>> +#endif
>> +}
>> +
>> +A* bar(B* p) {
>> +  return static_cast(p); // expected-error {{cannot cast 'B' to its
>> private base class 'A'}}
>> +}
>> +
>> +// from atlframe.h
>> +template 
>> +class CUpdateUI {
>> +public:
>> +  CUpdateUI() {
>> +T* pT = static_cast(this);
>> +#ifdef NO_MS_COMPATIBILITY
>> +// expected-error@-2 {{cannot cast private base class}}
>> +#else
>> +// expected-warning@-4 {{casting from private base class
>> 'CUpdateUI' to derived class 'CMDIFrame' is a Microsoft
>> extension}}
>> +#endif
>> +  }
>> +};
>> +
>> +// from sample WTL/MDIDocVw (mainfrm.h
>> +class CMDIFrame : CUp

Re: r267534 - [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-26 Thread Richard Smith via cfe-commits
On Tue, Apr 26, 2016 at 7:04 PM, David Majnemer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Visual Studio 2015 (19.00.23720.0) reports:
>
> error C2243: 'static_cast': conversion from 'B *' to 'A *' exists, but is
> inaccessible
>

Right, it's the other direction ('A *' to 'B *') that this patch is
permitting.


> On Tue, Apr 26, 2016 at 6:33 PM, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> As noted in PR27337, this only occurs in one WTL sample, and we have no
>> evidence that it actually occurs in real code. Have you seen uses of this
>> in the wild? We generally don't want to add compatibility for MSVC bugs
>> unless there's some real-world motivation.
>>
>>
>> On Tue, Apr 26, 2016 at 2:21 AM, Dmitry Polukhin via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: dpolukhin
>>> Date: Tue Apr 26 04:21:17 2016
>>> New Revision: 267534
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=267534&view=rev
>>> Log:
>>> [MSVC] PR27337: allow static_cast from private base to derived for WTL
>>>
>>> MSVC doesn't report even warning for cast from private base class to
>>> derived.
>>>
>>> Differential Revision: http://reviews.llvm.org/D19477
>>>
>>> Added:
>>> cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp   (with props)
>>> Modified:
>>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> cfe/trunk/lib/Sema/SemaCast.cpp
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267534&r1=267533&r2=267534&view=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 26
>>> 04:21:17 2016
>>> @@ -5764,6 +5764,9 @@ def err_static_downcast_via_virtual : Er
>>>"cannot cast %0 to %1 via virtual base %2">;
>>>  def err_downcast_from_inaccessible_base : Error<
>>>"cannot cast %select{private|protected}2 base class %1 to %0">;
>>> +def ext_ms_downcast_from_inaccessible_base : ExtWarn<
>>> +  "casting from %select{private|protected}2 base class %1 to derived
>>> class %0 is a Microsoft extension">,
>>> +  InGroup;
>>>  def err_upcast_to_inaccessible_base : Error<
>>>"cannot cast %0 to its %select{private|protected}2 base class %1">;
>>>  def err_bad_dynamic_cast_not_ref_or_ptr : Error<
>>>
>>> Modified: cfe/trunk/lib/Sema/SemaCast.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=267534&r1=267533&r2=267534&view=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/Sema/SemaCast.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaCast.cpp Tue Apr 26 04:21:17 2016
>>> @@ -1344,10 +1344,11 @@ TryStaticDowncast(Sema &Self, CanQualTyp
>>>}
>>>
>>>if (!CStyle) {
>>> -switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
>>> -  SrcType, DestType,
>>> -  Paths.front(),
>>> -
>>> diag::err_downcast_from_inaccessible_base)) {
>>> +unsigned Diag = Self.getLangOpts().MSVCCompat
>>> +? diag::ext_ms_downcast_from_inaccessible_base
>>> +: diag::err_downcast_from_inaccessible_base;
>>> +switch (Self.CheckBaseClassAccess(OpRange.getBegin(), SrcType,
>>> DestType,
>>> +  Paths.front(), Diag)) {
>>>  case Sema::AR_accessible:
>>>  case Sema::AR_delayed: // be optimistic
>>>  case Sema::AR_dependent:   // be optimistic
>>>
>>> Added: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp?rev=267534&view=auto
>>>
>>> ==
>>> --- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp (added)
>>> +++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp Tue Apr 26 04:21:17 2016
>>> @@ -0,0 +1,40 @@
>>> +// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s
>>> +// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s
>>> +
>>> +// Minimal reproducer.
>>> +class A {};
>>> +class B : A {}; // expected-note 2 {{implicitly declared private here}}
>>> +
>>> +B* foo(A* p) {
>>> +  return static_cast(p);
>>> +#ifdef NO_MS_COMPATIBILITY
>>> +  // expected-error@-2 {{cannot cast private base class 'A' to 'B'}}
>>> +#else
>>> +  // expected-warning@-4 {{casting from private base class 'A' to
>>> derived class 'B' is a Microsoft extension}}
>>> +#endif
>>> +}
>>> +
>>> +A* bar(B* p) {
>>> +  return static_cast(p); // expected-error {{cannot cast 'B' to its
>>> private base class 'A'}}
>>> +}
>>> +
>>> +// from atlframe.h
>>> +template 
>>> +class CUpdateUI {
>>> +public:
>>> +  CUpdateUI() {
>>> +T* pT = static_cast(this);
>>> +#ifdef NO_MS_COMPATIBILITY
>>>

Re: [PATCH] D19524: [OpenCL] Fix pipe type dump.

2016-04-26 Thread Xiuli PAN via cfe-commits
pxli168 added a comment.

I will add a test and send a new version.


http://reviews.llvm.org/D19524



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


[PATCH] D19577: [clang-tidy] Enhance misc-suspicious-string-compare by matching string.compare

2016-04-26 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

This patch added the support for method "compare" on string-like classes.

The LLVM stringRef is supported. The checker assume that StringRef is returning 
-1, 0 or 1.
Which is not the case for other functions returning <0, 0 or >0.

http://reviews.llvm.org/D19577

Files:
  clang-tidy/misc/SuspiciousStringCompareCheck.cpp
  test/clang-tidy/misc-suspicious-string-compare.cpp

Index: test/clang-tidy/misc-suspicious-string-compare.cpp
===
--- test/clang-tidy/misc-suspicious-string-compare.cpp
+++ test/clang-tidy/misc-suspicious-string-compare.cpp
@@ -6,6 +6,34 @@
 
 typedef __SIZE_TYPE__ size;
 
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template 
+struct basic_string {
+  typedef basic_string _Type;
+  basic_string();
+  basic_string(const C *p, const A &a = A());
+
+  int compare(const C* s) const;
+};
+
+typedef basic_string, std::allocator > string;
+typedef basic_string, std::allocator > wstring;
+}
+
+namespace llvm {
+struct StringRef {
+  StringRef();
+  StringRef(const char*);
+  int compare(StringRef RHS);
+  int compare_lower(StringRef RHS);
+  int compare_numeric(StringRef RHS);
+};
+}
+
 struct locale_t {
   void* dummy;
 } locale;
@@ -335,3 +363,56 @@
 
   return 1;
 }
+
+int test_string_patterns() {
+  std::string str;
+  if (str.compare("a"))
+return 0;
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'compare' is called without explicitly comparing result
+  // CHECK-FIXES: if (str.compare("a") != 0)
+
+  if (str.compare("a") == 0 ||
+  str.compare("b"))
+return 0;
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'compare' is called without explicitly comparing result
+  // CHECK-FIXES: str.compare("b") != 0)
+
+  if (str.compare("a") == 1)
+return 0;
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'compare' is compared to a suspicious constant
+
+  if (str.compare("a") == 2)
+return 0;
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'compare' is compared to a suspicious constant
+}
+
+int test_llvm_patterns() {
+  llvm::StringRef str;
+  if (str.compare("a"))
+return 0;
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'compare' is called without explicitly comparing result
+  // CHECK-FIXES: if (str.compare("a") != 0)
+
+  if (str.compare_lower("a"))
+return 0;
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'compare_lower' is called without explicitly comparing result
+  // CHECK-FIXES: if (str.compare_lower("a") != 0)   
+
+  if (str.compare("a") == 0 ||
+  str.compare("b"))
+return 0;
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'compare' is called without explicitly comparing result
+  // CHECK-FIXES: str.compare("b") != 0)
+ 
+  if (str.compare("a") == 2)
+return 0;
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'compare' is compared to a suspicious constant
+
+  // The following calls are valid.
+  if (str.compare("a") == 1) return 0;
+  if (str.compare("a") != 1) return 0;
+  if (str.compare("a") == 0) return 0;
+  if (str.compare("a") != 0) return 0;
+  if (str.compare("a") == -1) return 0;
+  if (str.compare("a") != -1) return 0;
+}
Index: clang-tidy/misc/SuspiciousStringCompareCheck.cpp
===
--- clang-tidy/misc/SuspiciousStringCompareCheck.cpp
+++ clang-tidy/misc/SuspiciousStringCompareCheck.cpp
@@ -8,10 +8,10 @@
 //===--===//
 
 #include "SuspiciousStringCompareCheck.h"
+#include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
-#include "../utils/Matchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -106,20 +106,37 @@
   ParseFunctionNames(KnownStringCompareFunctions, &FunctionNames);
   ParseFunctionNames(StringCompareLikeFunctions, &FunctionNames);
 
-  // Match a call to a string compare functions.
+  // Match a std::string::compare call.
+  const auto StdStringCompareCallExpr =
+  cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(hasName("basic_string")),
+ hasName("compare"))
+   .bind("decl")))
+  .bind("call");
+
+  // Match llvm strings variants.
+  const auto LLVMStringCompareCallExpr =
+  cxxMemberCallExpr(
+  callee(cxxMethodDecl(hasAnyName("::llvm::StringRef::compare",
+  "::llvm::StringRef::compare_lower",
+  "::llvm::StringRef::compare_numeric"))
+ .bind("decl")))
+  .bind("call");
+
+  // Match a call to a string compare functions (i.e. strcmp).
   const auto FunctionCompareDecl =
   functionDecl(hasAnyName(std::vector(FunctionNames.begin(

Re: [PATCH] D19524: [OpenCL] Fix pipe type dump.

2016-04-26 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 55161.
pxli168 added a comment.

Add test and fix some old test.


http://reviews.llvm.org/D19524

Files:
  lib/AST/ASTDumper.cpp
  lib/AST/TypePrinter.cpp
  test/Misc/ast-dump-pipe.cl
  test/SemaOpenCL/invalid-access-qualifier.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -7,5 +7,5 @@
 void test3(int pipe p){// expected-error {{cannot combine with previous 'int' 
declaration specifier}}
 }
 void test4() {
-  pipe int p; // expected-error {{type 'pipe' can only be used as a function 
parameter}}
+  pipe int p; // expected-error {{type 'pipe int' can only be used as a 
function parameter}}
 }
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- test/SemaOpenCL/invalid-access-qualifier.cl
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -8,7 +8,7 @@
 void test3(read_only read_only image1d_t i){} // expected-error{{multiple 
access qualifiers}}
 
 #ifdef CL20
-void test4(read_write pipe int i){} // expected-error{{access qualifier 
'read_write' can not be used for 'pipe'}}
+void test4(read_write pipe int i){} // expected-error{{access qualifier 
'read_write' can not be used for 'pipe int'}}
 #else
 void test4(__read_write image1d_t i) {} // expected-error{{access qualifier 
'__read_write' can not be used for '__read_write image1d_t' earlier than 
OpenCL2.0 version}}
 #endif
Index: test/Misc/ast-dump-pipe.cl
===
--- /dev/null
+++ test/Misc/ast-dump-pipe.cl
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter 
pipetype %s | FileCheck -strict-whitespace %s
+typedef pipe int pipetype;
+// CHECK:  PipeType {{.*}} 'pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -404,6 +404,9 @@
 void VisitAtomicType(const AtomicType *T) {
   dumpTypeAsChild(T->getValueType());
 }
+void VisitPipeType(const PipeType *T) {
+  dumpTypeAsChild(T->getElementType());
+}
 void VisitAdjustedType(const AdjustedType *T) {
   dumpTypeAsChild(T->getOriginalType());
 }


Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -7,5 +7,5 @@
 void test3(int pipe p){// expected-error {{cannot combine with previous 'int' declaration specifier}}
 }
 void test4() {
-  pipe int p; // expected-error {{type 'pipe' can only be used as a function parameter}}
+  pipe int p; // expected-error {{type 'pipe int' can only be used as a function parameter}}
 }
Index: test/SemaOpenCL/invalid-access-qualifier.cl
===
--- test/SemaOpenCL/invalid-access-qualifier.cl
+++ test/SemaOpenCL/invalid-access-qualifier.cl
@@ -8,7 +8,7 @@
 void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
 
 #ifdef CL20
-void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe'}}
+void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}}
 #else
 void test4(__read_write image1d_t i) {} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL2.0 version}}
 #endif
Index: test/Misc/ast-dump-pipe.cl
===
--- /dev/null
+++ test/Misc/ast-dump-pipe.cl
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter pipetype %s | FileCheck -strict-whitespace %s
+typedef pipe int pipetype;
+// CHECK:  PipeType {{.*}} 'pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: lib

Re: [PATCH] D19311: [analyzer] Self Assignment Checker

2016-04-26 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware updated this revision to Diff 54968.
baloghadamsoftware added a comment.

Initial comments added to the checker and tests are converted from  
(DOS) to  (Unix) format.


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 &rhs) : str(strdup(rhs.str)) {}
+  ~String();
+  String& operator=(const String &rhs);
+  operator const char*() const;
+private:
+  char *str;
+};
+
+String::~String() {
+  free(str);
+}
+
+String& String::operator=(const String &rhs) {
+  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 &rhs) : str(strdup(rhs.str)) {}
+  ~String();
+  String& operator=(const String &rhs);
+  operator const char*() const;
+private:
+  char *str;
+};
+
+String::~String() {
+  free(str);
+}
+
+String& String::operator=(const String &rhs) {
+  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)&&isa(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,58 @@
+//=== SelfAssignmentChecker.cpp *- C++ -*--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file defines SelfAssignmentChecker, which checks all custom defined
+// copy and move assignment operators for the case of self assignment, thus
+// where the parameter refers to the same location where the this pointer
+// points to.
+//
+//===--===//
+
+#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 &C) const;
+};
+}
+
+SelfAssignmentChecker::SelfAssignmentChecker() {}
+
+void SelfAssignmentChecker::checkBeginFunction(CheckerContext &C) const {
+  if (!C.inTopFrame())
+return;
+  const auto *LCtx = C.getLocationContext();
+  const auto *MD = dyn_cast(LCtx->getDecl());
+  if (!MD)
+return;
+  if (

Re: [PATCH] D18442: A clang-tidy check for std:accumulate.

2016-04-26 Thread Clement Courbet via cfe-commits
courbet updated this revision to Diff 54969.
courbet marked 2 inline comments as done.
courbet added a comment.

Fix doc formatting and add more doc.


http://reviews.llvm.org/D18442

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/FoldInitTypeCheck.cpp
  clang-tidy/misc/FoldInitTypeCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-fold-init-type.rst
  test/clang-tidy/misc-fold-init-type.cpp

Index: test/clang-tidy/misc-fold-init-type.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-fold-init-type.cpp
@@ -0,0 +1,158 @@
+// RUN: %check_clang_tidy %s misc-fold-init-type %t
+
+namespace std {
+template 
+T accumulate(InputIt first, InputIt last, T init);
+
+template 
+T reduce(InputIt first, InputIt last, T init);
+template 
+T reduce(ExecutionPolicy &&policy,
+ InputIt first, InputIt last, T init);
+
+struct parallel_execution_policy {};
+constexpr parallel_execution_policy par{};
+
+template 
+T inner_product(InputIt1 first1, InputIt1 last1,
+InputIt2 first2, T value);
+
+template 
+T inner_product(ExecutionPolicy &&policy, InputIt1 first1, InputIt1 last1,
+InputIt2 first2, T value);
+
+} // namespace std
+
+struct FloatIterator {
+  typedef float value_type;
+};
+template 
+struct TypedefTemplateIterator { typedef ValueType value_type; };
+template 
+struct UsingTemplateIterator { using value_type = ValueType; };
+template 
+struct DependentTypedefTemplateIterator { typedef typename ValueType::value_type value_type; };
+template 
+struct DependentUsingTemplateIterator : public TypedefTemplateIterator { using typename TypedefTemplateIterator::value_type; };
+using TypedeffedIterator = FloatIterator;
+
+// Positives.
+
+int accumulatePositive1() {
+  float a[1] = {0.5f};
+  return std::accumulate(a, a + 1, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'float' into type 'int'
+}
+
+int accumulatePositive2() {
+  FloatIterator it;
+  return std::accumulate(it, it, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'float' into type 'int'
+}
+
+int accumulatePositive3() {
+  double a[1] = {0.0};
+  return std::accumulate(a, a + 1, 0.0f);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'double' into type 'float'
+}
+
+int accumulatePositive4() {
+  TypedefTemplateIterator it;
+  return std::accumulate(it, it, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'unsigned int' into type 'int'
+}
+
+int accumulatePositive5() {
+  UsingTemplateIterator it;
+  return std::accumulate(it, it, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'unsigned int' into type 'int'
+}
+
+int accumulatePositive6() {
+  DependentTypedefTemplateIterator> it;
+  return std::accumulate(it, it, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'unsigned int' into type 'int'
+}
+
+int accumulatePositive7() {
+  TypedeffedIterator it;
+  return std::accumulate(it, it, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'float' into type 'int'
+}
+
+int accumulatePositive8() {
+  DependentUsingTemplateIterator it;
+  return std::accumulate(it, it, 0);
+  // FIXME: this one should trigger too.
+}
+
+int reducePositive1() {
+  float a[1] = {0.5f};
+  return std::reduce(a, a + 1, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'float' into type 'int'
+}
+
+int reducePositive2() {
+  float a[1] = {0.5f};
+  return std::reduce(std::par, a, a + 1, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'float' into type 'int'
+}
+
+int innerProductPositive1() {
+  float a[1] = {0.5f};
+  int b[1] = {1};
+  return std::inner_product(std::par, a, a + 1, b, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'float' into type 'int'
+}
+
+int innerProductPositive2() {
+  float a[1] = {0.5f};
+  int b[1] = {1};
+  return std::inner_product(std::par, a, a + 1, b, 0);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: folding type 'float' into type 'int'
+}
+
+// Negatives.
+
+int negative1() {
+  float a[1] = {0.5f};
+  // This is OK because types match.
+  return std::accumulate(a, a + 1, 0.0);
+}
+
+int negative2() {
+  float a[1] = {0.5f};
+  // This is OK because double is bigger than float.
+  return std::accumulate(a, a + 1, 0.0);
+}
+
+int negative3() {
+  float a[1] = {0.5f};
+  // This is OK because the user explicitly specified T.
+  return std::accumulate(a, a + 1, 0);
+}
+
+int negative4() {
+  TypedefTemplateIterator it;
+  // For now this is OK.
+  return std::accumulate(it, it, 0.0);
+}
+
+int negative5() {
+  float a[1] = {0.5f};
+  float b[1] = {1.0f};
+  return std::inner_product(std::par, a, a + 1, b, 0.0f);
+}
+
+namespace blah {
+namespace std {
+template 
+T accumulate(InputIt, InputIt, T); // We should not care about this one.
+}
+
+int negative5() {
+  float a[1] = {0.5f};
+  // Note that this is using blah::std::accumulate.
+  retur

Re: [PATCH] D18442: A clang-tidy check for std:accumulate.

2016-04-26 Thread Clement Courbet via cfe-commits
courbet added inline comments.


Comment at: docs/clang-tidy/checks/misc-fold-init-type.rst:16-17
@@ +15,4 @@
+
+.. code:: c++
+  auto a = {0.5f, 0.5f, 0.5f, 0.5f};
+  return std::accumulate(std::begin(a), std::end(a), 0);

alexfh wrote:
> Prazek wrote:
> > Doesn't .. code node need new line?
> Yes, it needs a new-line. Also, please verify the documentation actually 
> builds with sphinx. On Ubuntu it should boil down to these commands:
> 
>   $ sudo apt-get install python-sphinx
>   $ mkdir -p /some/build/directory && cd /some/build/directory
>   $ cmake /path/to/llvm/ -DLLVM_ENABLE_SPHINX=ON
>   $ make docs-clang-tools-html
> 
Thanks for the catch.


Comment at: docs/clang-tidy/checks/misc-fold-init-type.rst:16-17
@@ +15,4 @@
+
+.. code:: c++
+  auto a = {0.5f, 0.5f, 0.5f, 0.5f};
+  return std::accumulate(std::begin(a), std::end(a), 0);

courbet wrote:
> alexfh wrote:
> > Prazek wrote:
> > > Doesn't .. code node need new line?
> > Yes, it needs a new-line. Also, please verify the documentation actually 
> > builds with sphinx. On Ubuntu it should boil down to these commands:
> > 
> >   $ sudo apt-get install python-sphinx
> >   $ mkdir -p /some/build/directory && cd /some/build/directory
> >   $ cmake /path/to/llvm/ -DLLVM_ENABLE_SPHINX=ON
> >   $ make docs-clang-tools-html
> > 
> Thanks for the catch.
Thanks.


http://reviews.llvm.org/D18442



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


[PATCH] D19524: [OpenCL] Fix pipe type dump.

2016-04-26 Thread Xiuli PAN via cfe-commits
pxli168 created this revision.
pxli168 added reviewers: Anastasia, yaxunl.
pxli168 added subscribers: bader, cfe-commits.

Fix the dump of PipeType.
Now we will have "pipe int" and element type.

http://reviews.llvm.org/D19524

Files:
  lib/AST/ASTDumper.cpp
  lib/AST/TypePrinter.cpp

Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -404,6 +404,9 @@
 void VisitAtomicType(const AtomicType *T) {
   dumpTypeAsChild(T->getValueType());
 }
+void VisitPipeType(const PipeType *T) {
+  dumpTypeAsChild(T->getElementType());
+}
 void VisitAdjustedType(const AdjustedType *T) {
   dumpTypeAsChild(T->getOriginalType());
 }


Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -404,6 +404,9 @@
 void VisitAtomicType(const AtomicType *T) {
   dumpTypeAsChild(T->getValueType());
 }
+void VisitPipeType(const PipeType *T) {
+  dumpTypeAsChild(T->getElementType());
+}
 void VisitAdjustedType(const AdjustedType *T) {
   dumpTypeAsChild(T->getOriginalType());
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19524: [OpenCL] Fix pipe type dump.

2016-04-26 Thread Alexey Bader via cfe-commits
bader added a comment.

LGTM.
Probably it would be forth to add a simple test.


http://reviews.llvm.org/D19524



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


Re: [PATCH] D19478: Remove assert mandating you can only use SPIR target with OpenCL

2016-04-26 Thread Neil Henning via cfe-commits
sheredom added a comment.

So we build a bunch of internal libraries in a mix of OpenCL and C++, and then 
link them all together to create SPIR libraries that can be fed to calls to 
clLinkProgram and linked against user kernels.

I don't have commit writes to Clang - if the patch is ok to go could one of you 
bring the patch in for me?


http://reviews.llvm.org/D19478



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


r267534 - [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-26 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Tue Apr 26 04:21:17 2016
New Revision: 267534

URL: http://llvm.org/viewvc/llvm-project?rev=267534&view=rev
Log:
[MSVC] PR27337: allow static_cast from private base to derived for WTL

MSVC doesn't report even warning for cast from private base class to
derived.

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

Added:
cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp   (with props)
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaCast.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267534&r1=267533&r2=267534&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 26 04:21:17 
2016
@@ -5764,6 +5764,9 @@ def err_static_downcast_via_virtual : Er
   "cannot cast %0 to %1 via virtual base %2">;
 def err_downcast_from_inaccessible_base : Error<
   "cannot cast %select{private|protected}2 base class %1 to %0">;
+def ext_ms_downcast_from_inaccessible_base : ExtWarn<
+  "casting from %select{private|protected}2 base class %1 to derived class %0 
is a Microsoft extension">,
+  InGroup;
 def err_upcast_to_inaccessible_base : Error<
   "cannot cast %0 to its %select{private|protected}2 base class %1">;
 def err_bad_dynamic_cast_not_ref_or_ptr : Error<

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=267534&r1=267533&r2=267534&view=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Tue Apr 26 04:21:17 2016
@@ -1344,10 +1344,11 @@ TryStaticDowncast(Sema &Self, CanQualTyp
   }
 
   if (!CStyle) {
-switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
-  SrcType, DestType,
-  Paths.front(),
-diag::err_downcast_from_inaccessible_base)) {
+unsigned Diag = Self.getLangOpts().MSVCCompat
+? diag::ext_ms_downcast_from_inaccessible_base
+: diag::err_downcast_from_inaccessible_base;
+switch (Self.CheckBaseClassAccess(OpRange.getBegin(), SrcType, DestType,
+  Paths.front(), Diag)) {
 case Sema::AR_accessible:
 case Sema::AR_delayed: // be optimistic
 case Sema::AR_dependent:   // be optimistic

Added: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp?rev=267534&view=auto
==
--- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp (added)
+++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp Tue Apr 26 04:21:17 2016
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s
+
+// Minimal reproducer.
+class A {};
+class B : A {}; // expected-note 2 {{implicitly declared private here}}
+
+B* foo(A* p) {
+  return static_cast(p);
+#ifdef NO_MS_COMPATIBILITY
+  // expected-error@-2 {{cannot cast private base class 'A' to 'B'}}
+#else
+  // expected-warning@-4 {{casting from private base class 'A' to derived 
class 'B' is a Microsoft extension}}
+#endif
+}
+
+A* bar(B* p) {
+  return static_cast(p); // expected-error {{cannot cast 'B' to its 
private base class 'A'}}
+}
+
+// from atlframe.h
+template 
+class CUpdateUI {
+public:
+  CUpdateUI() {
+T* pT = static_cast(this);
+#ifdef NO_MS_COMPATIBILITY
+// expected-error@-2 {{cannot cast private base class}}
+#else
+// expected-warning@-4 {{casting from private base class 
'CUpdateUI' to derived class 'CMDIFrame' is a Microsoft extension}}
+#endif
+  }
+};
+
+// from sample WTL/MDIDocVw (mainfrm.h
+class CMDIFrame : CUpdateUI {};
+// expected-note@-1 {{implicitly declared private here}}
+// expected-note@-2 {{in instantiation of member function}}
+
+CMDIFrame wndMain;

Propchange: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
--
svn:eol-style = native

Propchange: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
--
svn:keywords = "Author Date Id Rev URL"

Propchange: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
--
svn:mime-type = text/plain


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


Re: [PATCH] D19477: [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-26 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL267534: [MSVC] PR27337: allow static_cast from private base 
to derived for WTL (authored by dpolukhin).

Changed prior to commit:
  http://reviews.llvm.org/D19477?vs=54829&id=54975#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19477

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaCast.cpp
  cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5764,6 +5764,9 @@
   "cannot cast %0 to %1 via virtual base %2">;
 def err_downcast_from_inaccessible_base : Error<
   "cannot cast %select{private|protected}2 base class %1 to %0">;
+def ext_ms_downcast_from_inaccessible_base : ExtWarn<
+  "casting from %select{private|protected}2 base class %1 to derived class %0 
is a Microsoft extension">,
+  InGroup;
 def err_upcast_to_inaccessible_base : Error<
   "cannot cast %0 to its %select{private|protected}2 base class %1">;
 def err_bad_dynamic_cast_not_ref_or_ptr : Error<
Index: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
===
--- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
+++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s
+
+// Minimal reproducer.
+class A {};
+class B : A {}; // expected-note 2 {{implicitly declared private here}}
+
+B* foo(A* p) {
+  return static_cast(p);
+#ifdef NO_MS_COMPATIBILITY
+  // expected-error@-2 {{cannot cast private base class 'A' to 'B'}}
+#else
+  // expected-warning@-4 {{casting from private base class 'A' to derived 
class 'B' is a Microsoft extension}}
+#endif
+}
+
+A* bar(B* p) {
+  return static_cast(p); // expected-error {{cannot cast 'B' to its 
private base class 'A'}}
+}
+
+// from atlframe.h
+template 
+class CUpdateUI {
+public:
+  CUpdateUI() {
+T* pT = static_cast(this);
+#ifdef NO_MS_COMPATIBILITY
+// expected-error@-2 {{cannot cast private base class}}
+#else
+// expected-warning@-4 {{casting from private base class 
'CUpdateUI' to derived class 'CMDIFrame' is a Microsoft extension}}
+#endif
+  }
+};
+
+// from sample WTL/MDIDocVw (mainfrm.h
+class CMDIFrame : CUpdateUI {};
+// expected-note@-1 {{implicitly declared private here}}
+// expected-note@-2 {{in instantiation of member function}}
+
+CMDIFrame wndMain;
Index: cfe/trunk/lib/Sema/SemaCast.cpp
===
--- cfe/trunk/lib/Sema/SemaCast.cpp
+++ cfe/trunk/lib/Sema/SemaCast.cpp
@@ -1344,10 +1344,11 @@
   }
 
   if (!CStyle) {
-switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
-  SrcType, DestType,
-  Paths.front(),
-diag::err_downcast_from_inaccessible_base)) {
+unsigned Diag = Self.getLangOpts().MSVCCompat
+? diag::ext_ms_downcast_from_inaccessible_base
+: diag::err_downcast_from_inaccessible_base;
+switch (Self.CheckBaseClassAccess(OpRange.getBegin(), SrcType, DestType,
+  Paths.front(), Diag)) {
 case Sema::AR_accessible:
 case Sema::AR_delayed: // be optimistic
 case Sema::AR_dependent:   // be optimistic


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5764,6 +5764,9 @@
   "cannot cast %0 to %1 via virtual base %2">;
 def err_downcast_from_inaccessible_base : Error<
   "cannot cast %select{private|protected}2 base class %1 to %0">;
+def ext_ms_downcast_from_inaccessible_base : ExtWarn<
+  "casting from %select{private|protected}2 base class %1 to derived class %0 is a Microsoft extension">,
+  InGroup;
 def err_upcast_to_inaccessible_base : Error<
   "cannot cast %0 to its %select{private|protected}2 base class %1">;
 def err_bad_dynamic_cast_not_ref_or_ptr : Error<
Index: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
===
--- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
+++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s
+
+// Minimal reproducer.
+class A {};
+class B : A {}; // expected-note 2 {{implicitly declared private here}}
+
+B* foo(A* p) {
+  return static_cast(p);
+#ifdef NO_MS_COMPATIBILITY
+  // expected-error@-2 {{cannot cast private base class 'A' to

Re: [PATCH] D19477: [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-26 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

Thank you for the review!


Repository:
  rL LLVM

http://reviews.llvm.org/D19477



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


Re: [PATCH] D18641: [PP] Handle #include_next after include found relative to current one same as GCC

2016-04-26 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

Richard, friendly ping, PTAL!


http://reviews.llvm.org/D18641



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


Re: [PATCH] D18442: A clang-tidy check for std:accumulate.

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

Looks good now. Thank you for the new check!

Do you need me to submit the patch for you?


http://reviews.llvm.org/D18442



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


Re: [PATCH] D19259: Initial version of misc-unused-using-decl check

2016-04-26 Thread Alexander Kornienko via cfe-commits
alexfh closed this revision.
alexfh added a comment.

This seems to have been committed as r266735.


http://reviews.llvm.org/D19259



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


Re: [PATCH] D18265: [clang-tidy] New: checker misc-unconventional-assign-operator replacing misc-assign-operator-signature

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

There still seem to be a few comments from sbenza and myself that need to be 
resolved.


http://reviews.llvm.org/D18265



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


Re: [PATCH] D18300: [clang-tidy] ProTypeMemberInitCheck - check that field decls do not have in-class initializer

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

Felix, do you have time to commit the patch or should I do this for you?


Repository:
  rL LLVM

http://reviews.llvm.org/D18300



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


Re: [PATCH] D18442: A clang-tidy check for std:accumulate.

2016-04-26 Thread Clement Courbet via cfe-commits
courbet added a comment.

In http://reviews.llvm.org/D18442#411785, @alexfh wrote:

> Looks good now. Thank you for the new check!


Thanks for the review.

> Do you need me to submit the patch for you?


Yes, please.


http://reviews.llvm.org/D18442



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


Re: r264417 - [ASTMatchers] Add own version of VariadicFunction.

2016-04-26 Thread Alexander Kornienko via cfe-commits
BTW, this commit removes  the last usage of llvm/ADT/VariadicFunction.h.
Should we kill this header?

On Fri, Mar 25, 2016 at 8:51 PM, Mehdi Amini via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Thanks!
>
> On Mar 25, 2016, at 12:47 PM, Samuel Benzaquen  wrote:
>
> Fixed in r264453.
> Sorry for the inconvenience.
>
> _Sam
>
> On Fri, Mar 25, 2016 at 3:31 PM, Samuel Benzaquen 
> wrote:
>
>> Sorry, this is an unrelated problem.
>> It is using brace-init lists and the supported MSVC version does not
>> support them.
>> I'll fix that.
>>
>>
>> On Fri, Mar 25, 2016 at 3:27 PM, Mehdi Amini 
>> wrote:
>>
>>> The link I provided is testing r264430...
>>>
>>> --
>>> Mehdi
>>>
>>> On Mar 25, 2016, at 12:25 PM, Samuel Benzaquen 
>>> wrote:
>>>
>>> I believe r264428 fixes this problem.
>>>
>>> On Fri, Mar 25, 2016 at 2:18 PM, Mehdi Amini 
>>> wrote:
>>>
 Hi,

 I think this broke clang-tidy somehow:
 http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10881/steps/build%20stage%201/logs/stdio

 --
 Mehdi




 > On Mar 25, 2016, at 9:29 AM, Samuel Benzaquen via cfe-commits <
 cfe-commits@lists.llvm.org> wrote:
 >
 > Author: sbenza
 > Date: Fri Mar 25 11:29:30 2016
 > New Revision: 264417
 >
 > URL: http://llvm.org/viewvc/llvm-project?rev=264417&view=rev
 > Log:
 > [ASTMatchers] Add own version of VariadicFunction.
 >
 > Summary:
 > llvm::VariadicFunction is only being used by ASTMatchers.
 > Having our own copy here allows us to remove the other one from
 llvm/ADT.
 > Also, we can extend the API to meet our needs without modifying the
 common
 > implementation.
 >
 > Reviewers: alexfh
 >
 > Subscribers: klimek, cfe-commits
 >
 > Differential Revision: http://reviews.llvm.org/D18275
 >
 > Modified:
 >cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
 >cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
 >cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
 >cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
 >
 > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
 > URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=264417&r1=264416&r2=264417&view=diff
 >
 ==
 > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
 > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar 25
 11:29:30 2016
 > @@ -1990,8 +1990,8 @@ inline internal::Matcher hasN
 > /// \code
 > /// anyOf(hasName(a), hasName(b), hasName(c))
 > /// \endcode
 > -const llvm::VariadicFunction, StringRef,
 > - internal::hasAnyNameFunc>
 > +const internal::VariadicFunction,
 StringRef,
 > + internal::hasAnyNameFunc>
 > hasAnyName = {};
 >
 > /// \brief Matches NamedDecl nodes whose fully qualified names contain
 >
 > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
 > URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=264417&r1=264416&r2=264417&view=diff
 >
 ==
 > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
 (original)
 > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Mar
 25 11:29:30 2016
 > @@ -46,8 +46,9 @@
 > #include "clang/AST/StmtCXX.h"
 > #include "clang/AST/StmtObjC.h"
 > #include "clang/AST/Type.h"
 > +#include "llvm/ADT/ArrayRef.h"
 > #include "llvm/ADT/Optional.h"
 > -#include "llvm/ADT/VariadicFunction.h"
 > +#include "llvm/ADT/SmallVector.h"
 > #include "llvm/Support/ManagedStatic.h"
 > #include 
 > #include 
 > @@ -60,6 +61,39 @@ class BoundNodes;
 >
 > namespace internal {
 >
 > +/// \brief Variadic function object.
 > +///
 > +/// Most of the functions below that use VariadicFunction could be
 implemented
 > +/// using plain C++11 variadic functions, but the function object
 allows us to
 > +/// capture it on the dynamic matcher registry.
 > +template >>> > +  ResultT (*Func)(ArrayRef)>
 > +struct VariadicFunction {
 > +  ResultT operator()() const { return Func({}); }
 > +
 > +  template 
 > +  ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
 > +return Execute(Arg1, static_cast(Args)...);
 > +  }
 > +
 > +  // We also allow calls with an already created array, in case the
 caller
 > +  // already had it.
 > +  ResultT operator()(ArrayRef Args) const {
 > +SmallVector InnerArgs;
 > +for (const ArgT &Arg : Args)
 > +  InnerArgs.push_back(&Arg);

[clang-tools-extra] r267542 - A clang-tidy check for std:accumulate.

2016-04-26 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Apr 26 05:05:45 2016
New Revision: 267542

URL: http://llvm.org/viewvc/llvm-project?rev=267542&view=rev
Log:
A clang-tidy check for std:accumulate.

Summary:
For folds (e.g. std::accumulate), check matches between the provided init value 
and the range's value_type. A typical error is "std::accumulate(begin, end, 
0);", where begin and end have float value_type. See the documentation for more 
examples.

For now we check std::accumulate, std::reduce and std::inner_product.

Reviewers: hokein, alexfh

Subscribers: Prazek, aaron.ballman, cfe-commits, courbet

Patch by Clément Courbet!

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

Added:
clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-fold-init-type.rst
clang-tools-extra/trunk/test/clang-tidy/misc-fold-init-type.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=267542&r1=267541&r2=267542&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Tue Apr 26 05:05:45 
2016
@@ -7,6 +7,7 @@ add_clang_library(clangTidyMiscModule
   BoolPointerImplicitConversionCheck.cpp
   DanglingHandleCheck.cpp
   DefinitionsInHeadersCheck.cpp
+  FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectRoundings.cpp

Added: clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.cpp?rev=267542&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.cpp Tue Apr 26 
05:05:45 2016
@@ -0,0 +1,140 @@
+//===--- FoldInitTypeCheck.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "FoldInitTypeCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+void FoldInitTypeCheck::registerMatchers(MatchFinder *Finder) {
+  // We match functions of interest and bind the iterator and init value types.
+  // Note: Right now we check only builtin types.
+  const auto BuiltinTypeWithId = [](const char *ID) {
+return hasCanonicalType(builtinType().bind(ID));
+  };
+  const auto IteratorWithValueType = [&BuiltinTypeWithId](const char *ID) {
+return anyOf(
+// Pointer types.
+pointsTo(BuiltinTypeWithId(ID)),
+// Iterator types.
+recordType(hasDeclaration(has(typedefNameDecl(
+hasName("value_type"), hasType(BuiltinTypeWithId(ID)));
+  };
+
+  const auto IteratorParam = parmVarDecl(
+  hasType(hasCanonicalType(IteratorWithValueType("IterValueType";
+  const auto Iterator2Param = parmVarDecl(
+  hasType(hasCanonicalType(IteratorWithValueType("Iter2ValueType";
+  const auto InitParam = parmVarDecl(hasType(BuiltinTypeWithId("InitType")));
+
+  // std::accumulate, std::reduce.
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(
+   hasAnyName("::std::accumulate", "::std::reduce"),
+   hasParameter(0, IteratorParam), hasParameter(2, 
InitParam))),
+   argumentCountIs(3))
+  .bind("Call"),
+  this);
+  // std::inner_product.
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(hasName("::std::inner_product"),
+   hasParameter(0, IteratorParam),
+   hasParameter(2, Iterator2Param),
+   hasParameter(3, InitParam))),
+   argumentCountIs(4))
+  .bind("Call"),
+  this);
+  // std::reduce with a policy.
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(hasName("::std::reduce"),
+   hasParameter(1, IteratorParam),
+   hasParameter(3, InitParam))),
+   argumentCountIs(4))
+  .bind("Call"),
+  this);
+  // std::inner_product with a policy.
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(hasName(":

Re: [PATCH] D18442: A clang-tidy check for std:accumulate.

2016-04-26 Thread Alexander Kornienko via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL267542: A clang-tidy check for std:accumulate. (authored by 
alexfh).

Changed prior to commit:
  http://reviews.llvm.org/D18442?vs=54969&id=54978#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18442

Files:
  clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.cpp
  clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.h
  clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-fold-init-type.rst
  clang-tools-extra/trunk/test/clang-tidy/misc-fold-init-type.cpp

Index: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
@@ -16,6 +16,7 @@
 #include "BoolPointerImplicitConversionCheck.h"
 #include "DanglingHandleCheck.h"
 #include "DefinitionsInHeadersCheck.h"
+#include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "InaccurateEraseCheck.h"
 #include "IncorrectRoundings.h"
@@ -67,6 +68,8 @@
 "misc-dangling-handle");
 CheckFactories.registerCheck(
 "misc-definitions-in-headers");
+CheckFactories.registerCheck(
+"misc-fold-init-type");
 CheckFactories.registerCheck(
 "misc-forward-declaration-namespace");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.h
+++ clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.h
@@ -0,0 +1,44 @@
+//===--- FoldInitTypeCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_FOLD_INIT_TYPE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_FOLD_INIT_TYPE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// Find and flag invalid initializer values in folds, e.g. std::accumulate.
+/// Example:
+/// \code
+///   auto v = {65536L * 65536 * 65536};
+///   std::accumulate(begin(v), end(v), 0 /* int type is too small */);
+/// \endcode
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/misc-fold-init-type.html
+class FoldInitTypeCheck : public ClangTidyCheck {
+public:
+  FoldInitTypeCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  void doCheck(const BuiltinType &IterValueType, const BuiltinType &InitType,
+   const ASTContext &Context, const CallExpr &CallNode);
+};
+
+} // namespace misc
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_FOLD_INIT_TYPE_H
Index: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
@@ -7,6 +7,7 @@
   BoolPointerImplicitConversionCheck.cpp
   DanglingHandleCheck.cpp
   DefinitionsInHeadersCheck.cpp
+  FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectRoundings.cpp
Index: clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/FoldInitTypeCheck.cpp
@@ -0,0 +1,140 @@
+//===--- FoldInitTypeCheck.cpp - clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "FoldInitTypeCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+void FoldInitTypeCheck::registerMatchers(MatchFinder *Finder) {
+  // We match functions of interest and bind the iterator and init value types.
+  // Note: Right now we check only builtin types.
+  const auto BuiltinTypeWithId = [

Re: [PATCH] D18265: [clang-tidy] New: checker misc-unconventional-assign-operator replacing misc-assign-operator-signature

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

Wait, I probably was looking at an older diff somehow. After returning to the 
page I don't see any unresolved comments. Reviewing...


http://reviews.llvm.org/D18265



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


Re: [PATCH] D19479: 26748 - clang-cl fails to compile atlctrlw.h header from WTL

2016-04-26 Thread Andrew V. Tischenko via cfe-commits
avt77 added a comment.

OK, I'll try to implement something like a DependentScopeDeclRefExpr but 
because of the latest changes in Intel I'm afraid it will take some more time 
from me.


http://reviews.llvm.org/D19479



___
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-26 Thread Andrew V. Tischenko via cfe-commits
avt77 added a comment.

It seems it will be even shorter if we do it via 
Sema::checkClassLevelDLLAttribute. Tnx.


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] D18953: [ms][dll] #26935 Defining a dllimport function should cause it to be exported

2016-04-26 Thread Andrew V. Tischenko via cfe-commits
avt77 added a comment.

In fact you introduced the plan of actions to fix the issue. Tnx.


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] D19415: [libcxx][rfc] Externalized threading support

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

I forgot to mention that we will need a similar (although much smaller) porting 
layer for `libcxxabi` and `libunwind`, as those too currently have a pthread 
dependency.


http://reviews.llvm.org/D19415



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


Re: [PATCH] D18265: [clang-tidy] New: checker misc-unconventional-assign-operator replacing misc-assign-operator-signature

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

No objections from me, but please wait for Samuel's review.


http://reviews.llvm.org/D18265



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


Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-04-26 Thread Krystyna via cfe-commits
krystyna updated this revision to Diff 54974.
krystyna marked an inline comment as done.

Repository:
  rL LLVM

http://reviews.llvm.org/D18919

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseUsingCheck.cpp
  clang-tidy/modernize/UseUsingCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-using.rst
  test/clang-tidy/modernize-use-using.cpp

Index: test/clang-tidy/modernize-use-using.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-using.cpp
@@ -0,0 +1,83 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t
+
+
+typedef int Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Type = int;
+
+typedef long LL;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using LL = long;
+
+typedef int Bla;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Bla = int;
+
+typedef Bla Bla2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Bla2 = Bla;
+
+typedef void (*type)(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using type = void (*)(int);
+
+typedef void (*type2)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using type2 = void (*)();
+
+class Class {
+typedef long long Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef [modernize-use-using]
+	// CHECK-FIXES: using Type = long long;
+};
+
+typedef void (Class::* MyPtrType)(Bla) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using MyPtrType = void (Class::*)(Bla) const;
+
+class Iterable {
+public:
+	class Iterator {};
+};
+
+template
+class Test {
+typedef typename T::iterator Iter;
+	// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef [modernize-use-using]
+	// CHECK-FIXES: using Iter = typename T::iterator;
+};
+
+using balba = long long;
+
+union A {};
+
+typedef void (A::*PtrType)(int, int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using PtrType = void (A::*)(int, int) const;
+
+typedef Class some_class;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using some_class = Class;
+
+typedef Class Cclass;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Cclass = Class;
+typedef Cclass cclass2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using cclass2 = Cclass;
+
+class cclass {
+
+};
+
+typedef void (cclass::* MyPtrType3)(Bla);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla);
+
+using my_class = int;
+
+typedef Test another;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using another = Test;
+
+
Index: docs/clang-tidy/checks/modernize-use-using.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-using.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - modernize-use-using
+
+modernize-use-using
+===
+
+Use C++11's ``using`` instead of ``typedef``.
+
+Before:
+
+.. code:: c++
+
+  typedef int variable;
+
+  class Class{};
+  typedef void (Class::* MyPtrType)() const;
+
+After:
+
+.. code:: c++
+
+  using varible = int;
+
+  class Class{};
+  using MyPtrType = void (Class::*)() const;
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -85,6 +85,7 @@
modernize-use-default
modernize-use-nullptr
modernize-use-override
+   modernize-use-using
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
Index: clang-tidy/modernize/UseUsingCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseUsingCheck.h
@@ -0,0 +1,35 @@
+//===--- UseUsingCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOO

Re: [PATCH] D19458: Add address space 258 to Clang documentation

2016-04-26 Thread Michael Kuperstein via cfe-commits
mkuper added a comment.

LGTM


http://reviews.llvm.org/D19458



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


Re: [PATCH] D19482: [include-fixer] Add a find-all-symbols tool for include-fixer.

2016-04-26 Thread Benjamin Kramer via cfe-commits
bkramer added a comment.

First, please run this through clang-format with LLVM style. This aligns all 
the & and * to the name instead of the type. There are also some 
underscore_names left that need conversion to PascalCase.



Comment at: include-fixer/find-all-symbols/FindAllSymbols.cpp:168
@@ +167,3 @@
+  const clang::SourceManager *SM = Result.SourceManager;
+  // Ignore STL header for now.
+  if (SM->isInSystemHeader(ND->getLocStart()))

Why?


Comment at: include-fixer/find-all-symbols/FindAllSymbols.h:26
@@ +25,3 @@
+
+virtual void ReportResult(const std::string &file_name,
+  const SymbolInfo& Symbol) = 0;

StringRef for the argument. we also start methods with a small letter in LLVM 
(reportResult).


Comment at: include-fixer/find-all-symbols/SymbolInfo.cpp:104
@@ +103,3 @@
+bool SymbolInfo::operator<(const SymbolInfo& Symbol) const {
+  if (Identifier != Symbol.Identifier)
+return Identifier < Symbol.Identifier;

This could be written as std::tie(Identifier, FilePath, LineNumber) < 
std::tie(Symbol.Identifier, Symbol.FilePath, Symbol.LineNumber)


Comment at: include-fixer/find-all-symbols/SymbolInfo.cpp:111
@@ +110,3 @@
+
+std::string SymbolInfoToYaml(SymbolInfo Symbol) {
+  std::string S;

Please write directly to the stream instead of going through std::string.


Repository:
  rL LLVM

http://reviews.llvm.org/D19482



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


Re: [PATCH] D18694: [ClangTidy] Add an 'explain-checks' option to diagnose where each checks comes from.

2016-04-26 Thread Haojian Wu via cfe-commits
hokein updated this revision to Diff 54996.
hokein marked an inline comment as done.
hokein added a comment.

- VS2013 doesn't support constexpr.
- Don't make test read external .clang-tidy file.


http://reviews.llvm.org/D18694

Files:
  clang-tidy/ClangTidyOptions.cpp
  clang-tidy/ClangTidyOptions.h
  clang-tidy/tool/ClangTidyMain.cpp
  test/clang-tidy/Inputs/explain-config/.clang-tidy
  test/clang-tidy/explain-checks.cpp

Index: test/clang-tidy/explain-checks.cpp
===
--- /dev/null
+++ test/clang-tidy/explain-checks.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-tidy -checks=-*,modernize-use-nullptr -explain-config | FileCheck --check-prefix=CHECK-MESSAGE1 %s
+// RUN: clang-tidy -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE2 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE3 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,-modernize-use-nullptr'}" %S/Inputs/explain-config/a.cc -explain-config | FileCheck --check-prefix=CHECK-MESSAGE4 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-*'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE5 %s
+// RUN: clang-tidy -config="{Checks: 'modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE6 %s
+// RUN: clang-tidy -explain-config %S/Inputs/explain-config/a.cc | grep "'modernize-use-nullptr' is enabled in the %S/Inputs/explain-config/.clang-tidy."
+
+// CHECK-MESSAGE1: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE2: 'modernize-use-nullptr' is enabled in the command-line option '-config'.
+// CHECK-MESSAGE3: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE4: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE5: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE6: 'clang-analyzer-unix.API' is enabled in the clang-tidy binary.
Index: test/clang-tidy/Inputs/explain-config/.clang-tidy
===
--- /dev/null
+++ test/clang-tidy/Inputs/explain-config/.clang-tidy
@@ -0,0 +1 @@
+Checks: '-*,modernize-use-nullptr'
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -128,6 +128,12 @@
 )"),
 cl::init(false), cl::cat(ClangTidyCategory));
 
+static cl::opt ExplainConfig("explain-config", cl::desc(R"(
+for each enabled check explains, where it is enabled, i.e. in clang-tidy binary,
+command line or a specific configuration file.
+)"),
+   cl::init(false), cl::cat(ClangTidyCategory));
+
 static cl::opt Config("config", cl::desc(R"(
 Specifies a configuration in YAML/JSON format:
   -config="{Checks: '*',
@@ -280,11 +286,10 @@
   if (!Config.empty()) {
 if (llvm::ErrorOr ParsedConfig =
 parseConfiguration(Config)) {
-  return llvm::make_unique(
-  GlobalOptions, ClangTidyOptions::getDefaults()
- .mergeWith(DefaultOptions)
- .mergeWith(*ParsedConfig)
- .mergeWith(OverrideOptions));
+  return llvm::make_unique(
+  GlobalOptions,
+  ClangTidyOptions::getDefaults().mergeWith(DefaultOptions),
+  *ParsedConfig, OverrideOptions);
 } else {
   llvm::errs() << "Error: invalid configuration specified.\n"
<< ParsedConfig.getError().message() << "\n";
@@ -311,6 +316,23 @@
   ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName);
   std::vector EnabledChecks = getCheckNames(EffectiveOptions);
 
+  if (ExplainConfig) {
+// FIXME: Figure out a more elegant way to show other ClangTidyOptions'
+// fields like ExtraArg.
+std::vector
+RawOptions = OptionsProvider->getRawOptions(FileName);
+for (const std::string &Check : EnabledChecks) {
+  for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
+if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
+  llvm::outs() << "'" << Check << "' is enabled in the " << It->second
+   << ".\n";
+  break;
+}
+  }
+}
+return 0;
+  }
+
   if (ListChecks) {
 llvm::outs() << "Enabled checks:";
 for (auto CheckName : EnabledChecks)
Index: clang-tidy/ClangTidyOptions.h
===
--- clang-tidy/ClangTidyOptions.h
+++ clang-tidy/ClangTidyOptions.h
@@ -99,14 +99,35 @@
 /// \brief Abstract interface for retrieving various ClangTidy options.
 class ClangTidyOptionsProvider {
 p

Re: [PATCH] D18694: [ClangTidy] Add an 'explain-checks' option to diagnose where each checks comes from.

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

Sorry for the long delay. This is getting closer. A few more comments though.



Comment at: clang-tidy/ClangTidyOptions.cpp:224
@@ +223,3 @@
+  DefaultOptionsProvider::getRawOptions(FileName);
+  OptionsSource CommandLineOptions =
+  OptionsSource(OverrideOptions, OptionsSourceTypeCheckCommandLineOption);

s/ = \s*OptionsSource//


Comment at: clang-tidy/ClangTidyOptions.cpp:235
@@ +234,3 @@
+if (Iter != CachedOptions.end()) {
+  RawOptions.push_back(Iter->second);
+  break;

This seems to be changing the caching logic. Consider this directory structure:

  a/
 .clang-tidy
 b/
c/

And consequtive `getRawOptions` calls with:
  1. "a/some_file"
  2. "a/b/c/some_file"
  3. "a/b/some_file".

What would happen previously:
  1. after call 1 `CachedOptions` would contain an entry for "a"
  2. call 2 would find an entry for "a" and copy it for "a/b" and "a/b/c"
  3. call 3 would just use the cache entry for "a/b"

Now step 2 doesn't copy the cache entry to "a/b" and "a/b/c".

Is there any specific reason to change this? This is benign given that the 
lookups happen in memory, but then the code needs to be consistent and avoid 
replicating cache entries to intermediate directories in all cases.


Comment at: clang-tidy/ClangTidyOptions.h:102
@@ -101,1 +101,3 @@
 public:
+  static constexpr char OptionsSourceTypeDefaultBinary[] = "clang-tidy binary";
+  static constexpr char OptionsSourceTypeCheckCommandLineOption[] =

As we figured out with another patch, `constexpr` is not supported by VS2013. 
Sorry for pushing you in a wrong direction.


Comment at: clang-tidy/ClangTidyOptions.h:115
@@ +114,3 @@
+  //
+  /// clang-tidy has 3 types of the sources (from low to top):
+  ///* clang-tidy binary

s/from low to top/in order of increasing priority/


Comment at: clang-tidy/ClangTidyOptions.h:117
@@ +116,3 @@
+  ///* clang-tidy binary
+  ///* '-config' commandline option or a specific configuration file
+  ///* '-checks' commandline option

This item should make it clear how a config file relates to the '-config' 
option in terms of priority. The easiest way to make the order clear is 
probably to split the item in two (and update the "3 types of the sources" 
above).


Comment at: clang-tidy/ClangTidyOptions.h:127
@@ -108,2 +126,3 @@
   /// specified \p FileName.
-  virtual ClangTidyOptions getOptions(llvm::StringRef FileName) = 0;
+  ClangTidyOptions getOptions(llvm::StringRef FileName) {
+ClangTidyOptions Result;

Let's move the implementation to the .cpp file. It's only used by a small 
fraction of translation units including this header, and it doesn't seem to be 
performance-critical to make this method inline.


Comment at: clang-tidy/ClangTidyOptions.h:145
@@ -121,4 +144,3 @@
   }
-  ClangTidyOptions getOptions(llvm::StringRef /*FileName*/) override {
-return DefaultOptions;
-  }
+  std::vector getRawOptions(
+  llvm::StringRef FileName) override;

clang-format?

A few more instances below.


Comment at: clang-tidy/ClangTidyOptions.h:161
@@ +160,3 @@
+const ClangTidyOptions &OverrideOptions);
+  std::vector getRawOptions(
+  llvm::StringRef FileName) override;

clang-format?


Comment at: clang-tidy/tool/ClangTidyMain.cpp:320
@@ +319,3 @@
+  if (ExplainConfig) {
+// FIXME: Figure out a more elegant way to show other ClangTidyOptions'
+// fields like ExtraArg.

"a more elegant way" seems to suggest that currently this already happens, but 
in a not elegant fashion. As far as I understand, we're not doing this at all ;)


http://reviews.llvm.org/D18694



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


Re: [PATCH] D19497: [clang-tidy] Enhance misc-suspicious-string-compare to move down false-positives.

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

LG with one nit.



Comment at: clang-tidy/misc/SuspiciousStringCompareCheck.cpp:215
@@ +214,3 @@
+  if (Result.Nodes.getNodeAs("suspicious-operator")) {
+diag(Call->getLocStart(), "suspicious usage of function %0") << Decl;
+  }

Can you make the message more specific? It should make it clear, what exactly 
is "suspicious" in this usage.


http://reviews.llvm.org/D19497



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


Re: [PATCH] D17416: [libcxx] Reorganize locale extension fallbacks. NFCI

2016-04-26 Thread Ben Craig via cfe-commits
bcraig added a comment.

ping @danalbert, @mclow.lists


http://reviews.llvm.org/D17416



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


Re: [PATCH] D19451: [clang-tidy] New checker for redundant expressions.

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

BTW, have you seen the `alpha.core.IdenticalExpr` static analyzer checker?


http://reviews.llvm.org/D19451



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


Re: [PATCH] D19451: [clang-tidy] New checker for redundant expressions.

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

Awesome idea!

LG with a couple of nits.

In http://reviews.llvm.org/D19451#410064, @etienneb wrote:

> Tested over LLVM code, no false positives.
>
> Two catches:
>  http://reviews.llvm.org/D19460
>  http://reviews.llvm.org/D19451


The second link refers to this revision ;)



Comment at: clang-tidy/misc/RedundantExpressionCheck.cpp:21
@@ +20,3 @@
+
+static bool AreIdenticalExpr(const Expr *Left, const Expr *Right) {
+  if (!Left || !Right)

This is to some degree similar to comparing `llvm::FoldingSetNodeIDs` created 
using `Stmt::Profile`. However it's only useful to check for identical 
expressions and won't work, if you're going to extend this to equivalent 
expressions.


Comment at: docs/clang-tidy/checks/misc-redundant-expression.rst:10
@@ +9,3 @@
+  * redundant,
+  * always be true,
+  * always be false,

Please enclose `true` and `false` in backquotes.


http://reviews.llvm.org/D19451



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


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

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

Ping?


http://reviews.llvm.org/D19327



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


Re: [PATCH] D18300: [clang-tidy] ProTypeMemberInitCheck - check that field decls do not have in-class initializer

2016-04-26 Thread Felix Berger via cfe-commits
I should free up again soon, just caught the flu though. Maybe next week?
Feel free to commit before then.

On Tue, Apr 26, 2016 at 5:52 AM, Alexander Kornienko 
wrote:

> alexfh added a comment.
>
> Felix, do you have time to commit the patch or should I do this for you?
>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D18300
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18963: PR27216: Only define __ARM_FEATURE_FMA when the target has VFPv4

2016-04-26 Thread Renato Golin via cfe-commits
rengolin added inline comments.


Comment at: lib/Basic/Targets.cpp:4710
@@ -4709,1 +4709,3 @@
  const std::vector &FeaturesVec) const override {
+if (CPU == "")
+  CPU = "generic";

This change is unrelated and may bring side effects into clang. I'd keep this 
out and investigate it in another patch with the appropriate tests. If you just 
force the target-feature in the test, this corner case won't be relevant in 
this patch.


Comment at: test/Sema/arm_vfma.c:1
@@ -1,2 +1,2 @@
-// RUN: %clang_cc1 -triple thumbv7s-apple-ios7.0 -target-feature +neon 
-fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple thumbv7s-apple-ios7.0 -fsyntax-only -verify %s
 #include 

This test should not be relying on the front-end getting the feature right, it 
should be forcing the vfpv4 target feature on a base arch like "arm-none-eabi".


Comment at: test/Sema/neon-vector-types-support.c:1
@@ -1,2 +1,2 @@
-// RUN: %clang_cc1 %s -triple armv7 -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple armv7 -target-feature -neon -fsyntax-only -verify
 

This change seems unrelated?


http://reviews.llvm.org/D18963



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


Re: [PATCH] D19412: [libcxx] Refactor pthread usage - II

2016-04-26 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 54999.
rmaprath added a comment.

Minor cleanup + Gentle ping.


http://reviews.llvm.org/D19412

Files:
  include/__config
  include/__mutex_base
  include/__os_support
  include/mutex
  include/thread
  src/algorithm.cpp
  src/condition_variable.cpp
  src/memory.cpp
  src/mutex.cpp
  src/thread.cpp

Index: src/thread.cpp
===
--- src/thread.cpp
+++ src/thread.cpp
@@ -37,6 +37,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+using namespace __libcpp_os_support;
+
 thread::~thread()
 {
 if (__t_ != 0)
@@ -46,7 +48,11 @@
 void
 thread::join()
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 int ec = pthread_join(__t_, 0);
+#else
+#error "Not implemented for the selected thread API."
+#endif
 #ifndef _LIBCPP_NO_EXCEPTIONS
 if (ec)
 throw system_error(error_code(ec, system_category()), "thread::join failed");
@@ -62,7 +68,11 @@
 int ec = EINVAL;
 if (__t_ != 0)
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 ec = pthread_detach(__t_);
+#else
+#error "Not implemented for the selected thread API."
+#endif
 if (ec == 0)
 __t_ = 0;
 }
Index: src/mutex.cpp
===
--- src/mutex.cpp
+++ src/mutex.cpp
@@ -21,37 +21,56 @@
 const try_to_lock_t try_to_lock = {};
 const adopt_lock_t  adopt_lock = {};
 
+using namespace __libcpp_os_support;
+
 mutex::~mutex()
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 pthread_mutex_destroy(&__m_);
+#else
+#error "Not implemented for the selected thread API."
+#endif
 }
 
 void
 mutex::lock()
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 int ec = pthread_mutex_lock(&__m_);
+#else
+#error "Not implemented for the selected thread API."
+#endif
 if (ec)
 __throw_system_error(ec, "mutex lock failed");
 }
 
 bool
 mutex::try_lock() _NOEXCEPT
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 return pthread_mutex_trylock(&__m_) == 0;
+#else
+#error "Not implemented for the selected thread API."
+#endif
 }
 
 void
 mutex::unlock() _NOEXCEPT
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 int ec = pthread_mutex_unlock(&__m_);
+#else
+#error "Not implemented for the selected thread API."
+#endif
 (void)ec;
 assert(ec == 0);
 }
 
 // recursive_mutex
 
 recursive_mutex::recursive_mutex()
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 pthread_mutexattr_t attr;
 int ec = pthread_mutexattr_init(&attr);
 if (ec)
@@ -77,35 +96,54 @@
 return;
 fail:
 __throw_system_error(ec, "recursive_mutex constructor failed");
+#else
+#error "Not implemented for the selected thread API."
+#endif
 }
 
 recursive_mutex::~recursive_mutex()
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 int e = pthread_mutex_destroy(&__m_);
+#else
+#error "Not implemented for the selected thread API."
+#endif
 (void)e;
 assert(e == 0);
 }
 
 void
 recursive_mutex::lock()
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 int ec = pthread_mutex_lock(&__m_);
+#else
+#error "Not implemented for the selected thread API."
+#endif
 if (ec)
 __throw_system_error(ec, "recursive_mutex lock failed");
 }
 
 void
 recursive_mutex::unlock() _NOEXCEPT
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 int e = pthread_mutex_unlock(&__m_);
+#else
+#error "Not implemented for the selected thread API."
+#endif
 (void)e;
 assert(e == 0);
 }
 
 bool
 recursive_mutex::try_lock() _NOEXCEPT
 {
+#if defined(_LIBCPP_THREAD_API_PTHREAD)
 return pthread_mutex_trylock(&__m_) == 0;
+#else
+#error "Not implemented for the selected thread API."
+#endif
 }
 
 // timed_mutex
@@ -165,9 +203,9 @@
 void
 recursive_timed_mutex::lock()
 {
-pthread_t id = pthread_self();
+__os_thread_id id = __os_thread_get_current_id();
 unique_lock lk(__m_);
-if (pthread_equal(id, __id_))
+if (__os_thread_id_compare(id, __id_) == 0)
 {
 if (__count_ == numeric_limits::max())
 __throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached");
@@ -183,9 +221,9 @@
 bool
 recursive_timed_mutex::try_lock() _NOEXCEPT
 {
-pthread_t id = pthread_self();
+__os_thread_id id = __os_thread_get_current_id();
 unique_lock lk(__m_, try_to_lock);
-if (lk.owns_lock() && (__count_ == 0 || pthread_equal(id, __id_)))
+if (lk.owns_lock() && (__count_ == 0 || __os_thread_id_compare(id, __id_) == 0))
 {
 if (__count_ == numeric_limits::max())
 return false;
@@ -210,13 +248,12 @@
 
 #endif // !_LIBCPP_HAS_NO_THREADS
 
+#if !defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_THREAD_API_PTHREAD)
 // If dispatch_once_f ever handles C++ exceptions, and if one can get to it
 // without illegal macros (unexpected macros not beginning with _UpperCase or
 // __lowercase), and if it stops spinning waiting threads, then call_once should
 // call into dispatch_once_f instead of here. Relevant radar this code

Re: [PATCH] D18963: PR27216: Only define __ARM_FEATURE_FMA when the target has VFPv4

2016-04-26 Thread silviu.bara...@arm.com via cfe-commits
sbaranga added inline comments.


Comment at: lib/Basic/Targets.cpp:4710
@@ -4709,1 +4709,3 @@
  const std::vector &FeaturesVec) const override {
+if (CPU == "")
+  CPU = "generic";

rengolin wrote:
> This change is unrelated and may bring side effects into clang. I'd keep this 
> out and investigate it in another patch with the appropriate tests. If you 
> just force the target-feature in the test, this corner case won't be relevant 
> in this patch.
Ok, that makes sense. I'll revert to the previous revision of this patch.


http://reviews.llvm.org/D18963



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


Re: [PATCH] D19451: [clang-tidy] New checker for redundant expressions.

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

In http://reviews.llvm.org/D19451#411990, @alexfh wrote:

> BTW, have you seen the `alpha.core.IdenticalExpr` static analyzer checker?


Anna, Jordan, and whoever else is interested in the `alpha.core.IdenticalExpr` 
checker (lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp), it looks like 
Etienne has reinvented a large part of this checker as a clang-tidy check. I'm 
not sure which of these supports more cases and has more false positives (given 
that the `alpha.core.IdenticalExpr` checker was there for quite a while, but 
IIUC, this clang-tidy check has been tested on a huge code base with pretty 
good results).

A few questions to all of you:

1. is the `alpha.core.IdenticalExpr` checker going to be released in the near 
future?
2. is anyone actively working on it?
3. given that Etienne seems to be planning to continue actively working on the 
clang-tidy analog of that static analyzer checker, are you fine to move all of 
this checker's (`alpha.core.IdenticalExpr`) functionality to clang-tidy?
4. more generally, should we officially recommend to use clang-tidy (instead of 
the static analyzer) for writing AST-based checks that don't require any 
path-based analysis?


http://reviews.llvm.org/D19451



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


Re: [PATCH] D18694: [ClangTidy] Add an 'explain-checks' option to diagnose where each checks comes from.

2016-04-26 Thread Haojian Wu via cfe-commits
hokein updated this revision to Diff 55001.
hokein marked 8 inline comments as done.
hokein added a comment.

Address comments.


http://reviews.llvm.org/D18694

Files:
  clang-tidy/ClangTidyOptions.cpp
  clang-tidy/ClangTidyOptions.h
  clang-tidy/tool/ClangTidyMain.cpp
  test/clang-tidy/Inputs/explain-config/.clang-tidy
  test/clang-tidy/explain-checks.cpp

Index: test/clang-tidy/explain-checks.cpp
===
--- /dev/null
+++ test/clang-tidy/explain-checks.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-tidy -checks=-*,modernize-use-nullptr -explain-config | FileCheck --check-prefix=CHECK-MESSAGE1 %s
+// RUN: clang-tidy -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE2 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE3 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,-modernize-use-nullptr'}" %S/Inputs/explain-config/a.cc -explain-config | FileCheck --check-prefix=CHECK-MESSAGE4 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-*'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE5 %s
+// RUN: clang-tidy -config="{Checks: 'modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE6 %s
+// RUN: clang-tidy -explain-config %S/Inputs/explain-config/a.cc | grep "'modernize-use-nullptr' is enabled in the %S/Inputs/explain-config/.clang-tidy."
+
+// CHECK-MESSAGE1: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE2: 'modernize-use-nullptr' is enabled in the command-line option '-config'.
+// CHECK-MESSAGE3: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE4: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE5: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE6: 'clang-analyzer-unix.API' is enabled in the clang-tidy binary.
Index: test/clang-tidy/Inputs/explain-config/.clang-tidy
===
--- /dev/null
+++ test/clang-tidy/Inputs/explain-config/.clang-tidy
@@ -0,0 +1 @@
+Checks: '-*,modernize-use-nullptr'
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -128,6 +128,12 @@
 )"),
 cl::init(false), cl::cat(ClangTidyCategory));
 
+static cl::opt ExplainConfig("explain-config", cl::desc(R"(
+for each enabled check explains, where it is enabled, i.e. in clang-tidy binary,
+command line or a specific configuration file.
+)"),
+   cl::init(false), cl::cat(ClangTidyCategory));
+
 static cl::opt Config("config", cl::desc(R"(
 Specifies a configuration in YAML/JSON format:
   -config="{Checks: '*',
@@ -280,11 +286,10 @@
   if (!Config.empty()) {
 if (llvm::ErrorOr ParsedConfig =
 parseConfiguration(Config)) {
-  return llvm::make_unique(
-  GlobalOptions, ClangTidyOptions::getDefaults()
- .mergeWith(DefaultOptions)
- .mergeWith(*ParsedConfig)
- .mergeWith(OverrideOptions));
+  return llvm::make_unique(
+  GlobalOptions,
+  ClangTidyOptions::getDefaults().mergeWith(DefaultOptions),
+  *ParsedConfig, OverrideOptions);
 } else {
   llvm::errs() << "Error: invalid configuration specified.\n"
<< ParsedConfig.getError().message() << "\n";
@@ -311,6 +316,21 @@
   ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName);
   std::vector EnabledChecks = getCheckNames(EffectiveOptions);
 
+  if (ExplainConfig) {
+std::vector
+RawOptions = OptionsProvider->getRawOptions(FileName);
+for (const std::string &Check : EnabledChecks) {
+  for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
+if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
+  llvm::outs() << "'" << Check << "' is enabled in the " << It->second
+   << ".\n";
+  break;
+}
+  }
+}
+return 0;
+  }
+
   if (ListChecks) {
 llvm::outs() << "Enabled checks:";
 for (auto CheckName : EnabledChecks)
Index: clang-tidy/ClangTidyOptions.h
===
--- clang-tidy/ClangTidyOptions.h
+++ clang-tidy/ClangTidyOptions.h
@@ -99,14 +99,33 @@
 /// \brief Abstract interface for retrieving various ClangTidy options.
 class ClangTidyOptionsProvider {
 public:
+  static const char OptionsSourceTypeDefaultBinary[];
+  static const char OptionsSourceTypeCheckCommandLineOption[];
+  static const char OptionsSourceTypeConfigComma

Re: [PATCH] D19249: Fix include path in ClangTidy.cpp.

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

In http://reviews.llvm.org/D19249#408437, @chh wrote:

> This change depends on http://reviews.llvm.org/D19393.


I'm personally fine with the solution in http://reviews.llvm.org/D19393. 
Removing this from my dashboard until that patch lands.


http://reviews.llvm.org/D19249



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


Re: [PATCH] D18694: [ClangTidy] Add an 'explain-checks' option to diagnose where each checks comes from.

2016-04-26 Thread Haojian Wu via cfe-commits
hokein added inline comments.


Comment at: clang-tidy/ClangTidyOptions.cpp:235
@@ +234,3 @@
+if (Iter != CachedOptions.end()) {
+  RawOptions.push_back(Iter->second);
+  break;

alexfh wrote:
> This seems to be changing the caching logic. Consider this directory 
> structure:
> 
>   a/
>  .clang-tidy
>  b/
> c/
> 
> And consequtive `getRawOptions` calls with:
>   1. "a/some_file"
>   2. "a/b/c/some_file"
>   3. "a/b/some_file".
> 
> What would happen previously:
>   1. after call 1 `CachedOptions` would contain an entry for "a"
>   2. call 2 would find an entry for "a" and copy it for "a/b" and "a/b/c"
>   3. call 3 would just use the cache entry for "a/b"
> 
> Now step 2 doesn't copy the cache entry to "a/b" and "a/b/c".
> 
> Is there any specific reason to change this? This is benign given that the 
> lookups happen in memory, but then the code needs to be consistent and avoid 
> replicating cache entries to intermediate directories in all cases.
Oh, I add a `break` statement here accidently. Remove it, and keep the caching 
logic here now. 


Comment at: clang-tidy/ClangTidyOptions.h:115
@@ +114,3 @@
+  ///* clang-tidy binary
+  ///* '-config' commandline option or a specific configuration file
+  ///* '-checks' commandline option

Explaining the priority of `config` option and config file is't reasonable here 
since clang-tidy only takes one of them. If the config option is specified, 
clang-tidy just ignores the config file.


http://reviews.llvm.org/D18694



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


Re: r267496 - [lanai] Update handling of structs in arguments to be passed in registers.

2016-04-26 Thread Jacques Pienaar via cfe-commits
Thanks for fixing this. My apologies for breaking this and not noticing &
fixing it earlier. Is there any way to test the Windows build without a
Windows machine at my disposal?

On Mon, Apr 25, 2016 at 6:59 PM, Kostya Serebryany  wrote:

> Hopefully fixed by r267513.
>
> On Mon, Apr 25, 2016 at 6:46 PM, Kostya Serebryany  wrote:
>
>> +rnk
>>
>> On Mon, Apr 25, 2016 at 5:09 PM, Jacques Pienaar via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: jpienaar
>>> Date: Mon Apr 25 19:09:29 2016
>>> New Revision: 267496
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=267496&view=rev
>>> Log:
>>> [lanai] Update handling of structs in arguments to be passed in
>>> registers.
>>>
>>> Previously aggregate types were passed byval, change the ABI to pass
>>> these in registers instead.
>>>
>>>
>>> Modified:
>>> cfe/trunk/lib/CodeGen/TargetInfo.cpp
>>> cfe/trunk/test/CodeGen/lanai-arguments.c
>>>
>>> Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
>>> TargetInfo.cpp?rev=267496&r1=267495&r2=267496&view=diff
>>> 
>>> ==
>>> --- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
>>> +++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Apr 25 19:09:29 2016
>>> @@ -6691,6 +6691,7 @@ public:
>>>I.info = classifyArgumentType(I.type, State);
>>>}
>>>
>>> +  ABIArgInfo getIndirectResult(QualType Ty, bool ByVal, CCState &State)
>>> const;
>>>ABIArgInfo classifyArgumentType(QualType RetTy, CCState &State) const;
>>>  };
>>>  } // end anonymous namespace
>>> @@ -6712,21 +6713,72 @@ bool LanaiABIInfo::shouldUseInReg(QualTy
>>>return true;
>>>  }
>>>
>>> +ABIArgInfo LanaiABIInfo::getIndirectResult(QualType Ty, bool ByVal,
>>> +   CCState &State) const {
>>> +  if (!ByVal) {
>>> +if (State.FreeRegs) {
>>> +  --State.FreeRegs; // Non-byval indirects just use one pointer.
>>> +  return getNaturalAlignIndirectInReg(Ty);
>>> +}
>>> +return getNaturalAlignIndirect(Ty, false);
>>> +  }
>>> +
>>> +  // Compute the byval alignment.
>>> +  constexpr unsigned MinABIStackAlignInBytes = 4;
>>>
>>
>> This broke the build on Windows;
>>
>> C:\b\slave\sanitizer-windows\llvm\tools\clang\lib\CodeGen\TargetInfo.cpp(6727)
>>  : error C2065: 'constexpr' : undeclared identifier
>>
>>
>>
>>
>>
>>> +  unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8;
>>> +  return ABIArgInfo::getIndirect(CharUnits::fromQuantity(4),
>>> /*ByVal=*/true,
>>> + /*Realign=*/TypeAlign >
>>> + MinABIStackAlignInBytes);
>>> +}
>>> +
>>>  ABIArgInfo LanaiABIInfo::classifyArgumentType(QualType Ty,
>>>CCState &State) const {
>>> -  if (isAggregateTypeForABI(Ty))
>>> -return getNaturalAlignIndirect(Ty);
>>> +  // Check with the C++ ABI first.
>>> +  const RecordType *RT = Ty->getAs();
>>> +  if (RT) {
>>> +CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI());
>>> +if (RAA == CGCXXABI::RAA_Indirect) {
>>> +  return getIndirectResult(Ty, /*ByVal=*/false, State);
>>> +} else if (RAA == CGCXXABI::RAA_DirectInMemory) {
>>> +  return getNaturalAlignIndirect(Ty, /*ByRef=*/true);
>>> +}
>>> +  }
>>> +
>>> +  if (isAggregateTypeForABI(Ty)) {
>>> +// Structures with flexible arrays are always indirect.
>>> +if (RT && RT->getDecl()->hasFlexibleArrayMember())
>>> +  return getIndirectResult(Ty, /*ByVal=*/true, State);
>>> +
>>> +// Ignore empty structs/unions.
>>> +if (isEmptyRecord(getContext(), Ty, true))
>>> +  return ABIArgInfo::getIgnore();
>>> +
>>> +llvm::LLVMContext &LLVMContext = getVMContext();
>>> +unsigned SizeInRegs = (getContext().getTypeSize(Ty) + 31) / 32;
>>> +if (SizeInRegs <= State.FreeRegs) {
>>> +  llvm::IntegerType *Int32 = llvm::Type::getInt32Ty(LLVMContext);
>>> +  SmallVector Elements(SizeInRegs, Int32);
>>> +  llvm::Type *Result = llvm::StructType::get(LLVMContext,
>>> Elements);
>>> +  State.FreeRegs -= SizeInRegs;
>>> +  return ABIArgInfo::getDirectInReg(Result);
>>> +} else {
>>> +  State.FreeRegs = 0;
>>> +}
>>> +return getIndirectResult(Ty, true, State);
>>> +  }
>>>
>>>// Treat an enum type as its underlying type.
>>>if (const auto *EnumTy = Ty->getAs())
>>>  Ty = EnumTy->getDecl()->getIntegerType();
>>>
>>> -  if (shouldUseInReg(Ty, State))
>>> -return ABIArgInfo::getDirectInReg();
>>> -
>>> -  if (Ty->isPromotableIntegerType())
>>> +  bool InReg = shouldUseInReg(Ty, State);
>>> +  if (Ty->isPromotableIntegerType()) {
>>> +if (InReg)
>>> +  return ABIArgInfo::getDirectInReg();
>>>  return ABIArgInfo::getExtend();
>>> -
>>> +  }
>>> +  if (InReg)
>>> +return ABIArgInfo::getDirectInReg();
>>>return ABIArgInfo::getDirect();
>>>  }
>>>
>>>
>>> Modified: cfe/trunk/test/

Re: [PATCH] D18694: [ClangTidy] Add an 'explain-checks' option to diagnose where each checks comes from.

2016-04-26 Thread Haojian Wu via cfe-commits
hokein marked an inline comment as done.
hokein added a comment.

http://reviews.llvm.org/D18694



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


  1   2   >