r290084 - clang-format: Allow "single column" list layout even if that violates the

2016-12-18 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Dec 19 01:26:11 2016
New Revision: 290084

URL: http://llvm.org/viewvc/llvm-project?rev=290084=rev
Log:
clang-format: Allow "single column" list layout even if that violates the
column limit.

Single-column layout basically means that we format the list with one
element per line. Not doing that when there is a column limit violation
doesn't change the fact that there is an item that doesn't fit within
the column limit.

Before (with a column limit of 30):
  std::vector a = {
  , ,
  , ,
  aa, ,
  aaa};

After:
  std::vector a = {
  ,
  ,
  ,
  ,
  aa,
  ,
  aaa};

(and previously we would have formatted like "After" it wasn't for the one
item that is too long)

Modified:
cfe/trunk/lib/Format/FormatToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/FormatToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=290084=290083=290084=diff
==
--- cfe/trunk/lib/Format/FormatToken.cpp (original)
+++ cfe/trunk/lib/Format/FormatToken.cpp Mon Dec 19 01:26:11 2016
@@ -273,7 +273,7 @@ void CommaSeparatedList::precomputeForma
   continue;
 
 // Ignore layouts that are bound to violate the column limit.
-if (Format.TotalWidth > Style.ColumnLimit)
+if (Format.TotalWidth > Style.ColumnLimit && Columns > 1)
   continue;
 
 Formats.push_back(Format);
@@ -287,7 +287,7 @@ CommaSeparatedList::getColumnFormat(unsi
I = Formats.rbegin(),
E = Formats.rend();
I != E; ++I) {
-if (I->TotalWidth <= RemainingCharacters) {
+if (I->TotalWidth <= RemainingCharacters || I->Columns == 1) {
   if (BestFormat && I->LineCount > BestFormat->LineCount)
 break;
   BestFormat = &*I;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=290084=290083=290084=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Dec 19 01:26:11 2016
@@ -6779,6 +6779,18 @@ TEST_F(FormatTest, FormatsBracedListsInC
   "  1, 22, 333, , 5, 66, 777,\n"
   "  1, 22, 333, , 5, 66, 777,\n"
   "  1, 22, 333, , 5, 66, 777});");
+
+  // Allow "single-column" layout even if that violates the column limit. There
+  // isn't going to be a better way.
+  verifyFormat("std::vector a = {\n"
+   ",\n"
+   ",\n"
+   ",\n"
+   ",\n"
+   "aa,\n"
+   ",\n"
+   "aaa};",
+   getLLVMStyleWithColumns(30));
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {


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


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

2016-12-18 Thread Mads Ravn via cfe-commits
Hi Piotr,

Thank you for your detailed comments :)

I would love some help with the other fixit. I have some notes on it at
home. But my main catch is that is an implicit cast to boolean from
str.compare(str) with maybe an ! in front of it. And I need to fix that to
str.compare(str) == 0 or str.compare(str) != 0.

Where should I put the warning in a static const global variable? Is it
still in StringCompare.cpp or do we have a  joint files for these?

Best regards,
Mads Ravn

On Sun, Dec 18, 2016 at 11:26 PM Piotr Padlewski via Phabricator <
revi...@reviews.llvm.org> wrote:

> Prazek added a comment.
>
> Do you need some help with implementing the other fixit, or you just need
> some extra time? It seems to be almost the same as your second fixit
>
>
>
> 
> Comment at: clang-tidy/misc/StringCompareCheck.cpp:69-70
> +diag(Matched->getLocStart(),
> + "do not use 'compare' to test equality of strings; "
> + "use the string equality operator instead");
> +
> 
> Take this warning to some static const global variable
>
>
> 
> Comment at: clang-tidy/misc/StringCompareCheck.cpp:71
> + "use the string equality operator instead");
> +
> +  if (const auto *Matched = Result.Nodes.getNodeAs("match2")) {
> 
> match1 and match2 are in different matchers (passed to register matchers)?
>
> If so put return here after diag to finish control flow for this case.
>
>
> 
> Comment at: clang-tidy/misc/StringCompareCheck.cpp:81
> +  auto Diag = diag(Matched->getLocStart(),
> +   "do not use 'compare' to test equality of strings;
> "
> +   "use the string equality operator instead");
> 
> and use it here
>
>
> 
> Comment at: clang-tidy/misc/StringCompareCheck.h:10-11
> +
> +#ifndef STRING_COMPARE_CHECK_H
> +#define STRING_COMPARE_CHECK_H
> +
> 
> This should be much longer string. Do you know about ./add_new_check?
>
> Please make one similar to other checks
>
>
> 
> Comment at: clang-tidy/misc/StringCompareCheck.h:36
> +
> +#endif // STRING_COMPARE_CHECK_H
> 
> DITTO
>
>
> 
> Comment at: test/clang-tidy/misc-string-compare.cpp:35-40
> +  if (str1.compare(str2)) {
> +  }
> +  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test
> equality of strings; use the string equality operator instead
> [misc-string-compare]
> +  if (!str1.compare(str2)) {
> +  }
> +  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test
> equality of strings; use the string equality operator instead
> [misc-string-compare]
> 
> Why this one doesn't have fixit hint?
>
>
> 
> Comment at: test/clang-tidy/misc-string-compare.cpp:70
> +  }
> +  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test
> equality of strings;
> +  if (str3->compare(str2) == 0) {
> 
> no fixit?
>
>
> https://reviews.llvm.org/D27210
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27569: [OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand.

2016-12-18 Thread Egor Churaev via Phabricator via cfe-commits
echuraev updated this revision to Diff 81917.
echuraev marked an inline comment as done.

https://reviews.llvm.org/D27569

Files:
  include/clang/AST/OperationKinds.def
  include/clang/Sema/Initialization.h
  include/clang/Sema/Overload.h
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaOverload.cpp
  test/CodeGenOpenCL/null_queue.cl
  test/SemaOpenCL/null_queue.cl
  test/SemaOpenCL/queue_t_overload.cl

Index: test/SemaOpenCL/queue_t_overload.cl
===
--- /dev/null
+++ test/SemaOpenCL/queue_t_overload.cl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
+
+void __attribute__((overloadable)) foo(queue_t, __local char *); // expected-note {{candidate function not viable: no known conversion from 'int' to 'queue_t' for 1st argument}} // expected-note {{candidate function}}
+void __attribute__((overloadable)) foo(queue_t, __local float *); // expected-note {{candidate function not viable: no known conversion from 'int' to 'queue_t' for 1st argument}} // expected-note {{candidate function}}
+
+void kernel ker(__local char *src1, __local float *src2, __global int *src3) {
+  queue_t q;
+  foo(q, src1);
+  foo(0, src2);
+  foo(q, src3); // expected-error {{call to 'foo' is ambiguous}}
+  foo(1, src3); // expected-error {{no matching function for call to 'foo'}}
+}
Index: test/SemaOpenCL/null_queue.cl
===
--- /dev/null
+++ test/SemaOpenCL/null_queue.cl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
+extern queue_t get_default_queue();
+
+bool compare() {
+  return 1 == get_default_queue() && // expected-error{{invalid operands to binary expression ('int' and 'queue_t')}}
+ get_default_queue() == 1; // expected-error{{invalid operands to binary expression ('queue_t' and 'int')}}
+}
+
+void init() {
+  queue_t q1 = 1; // expected-error{{initializing 'queue_t' with an expression of incompatible type 'int'}}
+  queue_t q = 0;
+}
Index: test/CodeGenOpenCL/null_queue.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/null_queue.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0  -emit-llvm %s -o - | FileCheck %s
+extern queue_t get_default_queue();
+
+bool compare() {
+  return 0 == get_default_queue() &&
+ get_default_queue() == 0;
+  // CHECK: icmp eq %opencl.queue_t* null, %{{.*}}
+  // CHECK: icmp eq %opencl.queue_t* %{{.*}}, null
+}
+
+void func(queue_t q);
+
+void init() {
+  queue_t q = 0;
+  func(0);
+  // CHECK: store %opencl.queue_t* null, %opencl.queue_t** %q
+  // CHECK: call void @func(%opencl.queue_t* null)
+}
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -1781,6 +1781,11 @@
  From->EvaluateKnownConstInt(S.getASTContext()) == 0) {
 SCS.Second = ICK_Zero_Event_Conversion;
 FromType = ToType;
+  } else if (ToType->isQueueT() &&
+ From->isIntegerConstantExpr(S.getASTContext()) &&
+ (From->EvaluateKnownConstInt(S.getASTContext()) == 0)) {
+SCS.Second = ICK_Zero_Queue_Conversion;
+FromType = ToType;
   } else {
 // No second conversion required.
 SCS.Second = ICK_Identity;
@@ -5155,6 +5160,7 @@
   case ICK_Function_Conversion:
   case ICK_Integral_Promotion:
   case ICK_Integral_Conversion: // Narrowing conversions are checked elsewhere.
+  case ICK_Zero_Queue_Conversion:
 return true;
 
   case ICK_Boolean_Conversion:
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -3073,6 +3073,7 @@
   case SK_StdInitializerListConstructorCall:
   case SK_OCLSamplerInit:
   case SK_OCLZeroEvent:
+  case SK_OCLZeroQueue:
 break;
 
   case SK_ConversionSequence:
@@ -3334,6 +3335,13 @@
   Steps.push_back(S);
 }
 
+void InitializationSequence::AddOCLZeroQueueStep(QualType T) {
+  Step S;
+  S.Kind = SK_OCLZeroQueue;
+  S.Type = T;
+  Steps.push_back(S);
+}
+
 void InitializationSequence::RewrapReferenceInitList(QualType T,
  InitListExpr *Syntactic) {
   assert(Syntactic->getNumInits() == 1 &&
@@ -4981,6 +4989,20 @@
   return true;
 }
 
+static bool TryOCLZeroQueueInitialization(Sema ,
+  InitializationSequence ,
+  QualType DestType,
+  Expr *Initializer) {
+  if (!S.getLangOpts().OpenCL || S.getLangOpts().OpenCLVersion < 200 ||
+  !DestType->isQueueT() ||
+  !Initializer->isIntegerConstantExpr(S.getASTContext()) ||
+  

[PATCH] D16171: Warning on redeclaring with a conflicting asm label

2016-12-18 Thread Leslie Zhai via Phabricator via cfe-commits
xiangzhai added a comment.

LLVMBUG-31017 https://llvm.org/bugs/show_bug.cgi?id=31017#c4

In https://reviews.llvm.org/D16171#540261, @phabricss wrote:

> On 09/12/2016 01:26 PM, Nick Lewycky wrote:
>
> > Firstly, I thought glibc had applied a patch to fix this bug? As in, the 
> > error is correct and glibc fixed their bug?
>
> I can confirm that the bug still exists in glibc 2.24 and HEAD from glibc 
> git.  Also it appears that the issue on the llvm mailing list was just 
> dropped without any resolution:
>
> r255371 - Error on redeclaring with a conflicting asm label 
> 
>
>   ../include/sys/stat.h:16:15: error: cannot apply asm label to function 
> after its first use
>   hidden_proto (__fxstat)
>   ~~^
>   ./../include/libc-symbols.h:420:19: note: expanded from macro 'hidden_proto'
> __hidden_proto (name, , __GI_##name, ##attrs)
> ^
>   ./../include/libc-symbols.h:424:33: note: expanded from macro 
> '__hidden_proto'
> extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) 
> \
>
>
> As far as your review of the patch by weimingz, that is beyond my skill level 
> so I will let him reply.  Thanks!





https://reviews.llvm.org/D16171



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


r290082 - Add __cpp_structured_bindings feature test macro for structured bindings, per

2016-12-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Dec 18 22:21:36 2016
New Revision: 290082

URL: http://llvm.org/viewvc/llvm-project?rev=290082=rev
Log:
Add __cpp_structured_bindings feature test macro for structured bindings, per
latest (provisional) draft of SD-6.

Modified:
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Lexer/cxx-features.cpp

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=290082=290081=290082=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Sun Dec 18 22:21:36 2016
@@ -519,6 +519,7 @@ static void InitializeCPlusPlusFeatureTe
 Builder.defineMacro("__cpp_nested_namespace_definitions", "201411");
 Builder.defineMacro("__cpp_variadic_using", "201611");
 Builder.defineMacro("__cpp_aggregate_bases", "201603");
+Builder.defineMacro("__cpp_structured_bindings", "201606");
 Builder.defineMacro("__cpp_nontype_template_args", "201411");
 Builder.defineMacro("__cpp_fold_expressions", "201603");
   }

Modified: cfe/trunk/test/Lexer/cxx-features.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/cxx-features.cpp?rev=290082=290081=290082=diff
==
--- cfe/trunk/test/Lexer/cxx-features.cpp (original)
+++ cfe/trunk/test/Lexer/cxx-features.cpp Sun Dec 18 22:21:36 2016
@@ -78,11 +78,15 @@
 #error "wrong value for __cpp_nested_namespace_definitions"
 #endif
 
+// inheriting_constructors checked below
+
 #if check(aggregate_bases, 0, 0, 0, 201603)
 #error "wrong value for __cpp_aggregate_bases"
 #endif
 
-// FIXME: structured_bindings / decomposition_decl name not yet settled
+#if check(structured_bindings, 0, 0, 0, 201606)
+#error "wrong value for __cpp_structured_bindings"
+#endif
 
 #if check(nontype_template_args, 0, 0, 0, 201411)
 #error "wrong value for __cpp_nontype_template_args"


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


r290081 - [c++1z] cxx_status: mark p0195r2 as done.

2016-12-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Dec 18 22:16:03 2016
New Revision: 290081

URL: http://llvm.org/viewvc/llvm-project?rev=290081=rev
Log:
[c++1z] cxx_status: mark p0195r2 as done.

Modified:
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/Lexer/cxx-features.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=290081=290080=290081=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Sun Dec 18 22:16:03 2016
@@ -517,6 +517,7 @@ static void InitializeCPlusPlusFeatureTe
 Builder.defineMacro("__cpp_namespace_attributes", "201411");
 Builder.defineMacro("__cpp_enumerator_attributes", "201411");
 Builder.defineMacro("__cpp_nested_namespace_definitions", "201411");
+Builder.defineMacro("__cpp_variadic_using", "201611");
 Builder.defineMacro("__cpp_aggregate_bases", "201603");
 Builder.defineMacro("__cpp_nontype_template_args", "201411");
 Builder.defineMacro("__cpp_fold_expressions", "201603");

Modified: cfe/trunk/test/Lexer/cxx-features.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/cxx-features.cpp?rev=290081=290080=290081=diff
==
--- cfe/trunk/test/Lexer/cxx-features.cpp (original)
+++ cfe/trunk/test/Lexer/cxx-features.cpp Sun Dec 18 22:16:03 2016
@@ -22,6 +22,10 @@
 
 // --- C++17 features ---
 
+#if check(variadic_using, 0, 0, 0, 201611) // FIXME: provisional name
+#error "wrong value for __cpp_variadic_using"
+#endif
+
 #if check(hex_float, 0, 0, 0, 201603)
 #error "wrong value for __cpp_hex_float"
 #endif
@@ -78,8 +82,7 @@
 #error "wrong value for __cpp_aggregate_bases"
 #endif
 
-// FIXME: structured_bindings / decomposition_decl name not yet settled, and
-// Clang implementation is incomplete.
+// FIXME: structured_bindings / decomposition_decl name not yet settled
 
 #if check(nontype_template_args, 0, 0, 0, 201411)
 #error "wrong value for __cpp_nontype_template_args"

Modified: cfe/trunk/www/cxx_status.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=290081=290080=290081=diff
==
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Sun Dec 18 22:16:03 2016
@@ -743,7 +743,7 @@ as the draft C++1z standard evolves.
 
   Pack expansions in using-declarations
   http://wg21.link/p0195r2;>P0195R2
-  No
+  SVN
 
 
 


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


r290080 - [c++1z] P0195R2: Support pack-expansion of using-declarations.

2016-12-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Dec 18 22:08:53 2016
New Revision: 290080

URL: http://llvm.org/viewvc/llvm-project?rev=290080=rev
Log:
[c++1z] P0195R2: Support pack-expansion of using-declarations.

This change introduces UsingPackDecl as a marker for the set of UsingDecls
produced by pack expansion of a single (unresolved) using declaration. This is
not strictly necessary (we just need to be able to map from the original using
declaration to its expansions somehow), but it's useful to maintain the
invariant that each declaration reference instantiates to refer to one
declaration.

Added:
cfe/trunk/test/PCH/cxx1z-using-declaration.cpp
cfe/trunk/test/SemaTemplate/cxx1z-using-declaration.cpp
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/DeclNodes.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Sema/Template.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/Parser/cxx1z-using-declaration.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=290080=290079=290080=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sun Dec 18 22:08:53 2016
@@ -3140,6 +3140,77 @@ public:
   friend class ASTDeclWriter;
 };
 
+/// Represents a pack of using declarations that a single
+/// using-declarator pack-expanded into.
+///
+/// \code
+/// template struct X : T... {
+///   using T::operator()...;
+///   using T::operator T...;
+/// };
+/// \endcode
+///
+/// In the second case above, the UsingPackDecl will have the name
+/// 'operator T' (which contains an unexpanded pack), but the individual
+/// UsingDecls and UsingShadowDecls will have more reasonable names.
+class UsingPackDecl final
+: public NamedDecl, public Mergeable,
+  private llvm::TrailingObjects {
+  void anchor() override;
+
+  /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
+  /// which this waas instantiated.
+  NamedDecl *InstantiatedFrom;
+
+  /// The number of using-declarations created by this pack expansion.
+  unsigned NumExpansions;
+
+  UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
+ArrayRef UsingDecls)
+  : NamedDecl(UsingPack, DC,
+  InstantiatedFrom ? InstantiatedFrom->getLocation()
+   : SourceLocation(),
+  InstantiatedFrom ? InstantiatedFrom->getDeclName()
+   : DeclarationName()),
+InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
+std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
+getTrailingObjects());
+  }
+
+public:
+  /// Get the using declaration from which this was instantiated. This will
+  /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
+  /// that is a pack expansion.
+  NamedDecl *getInstantiatedFromUsingDecl() { return InstantiatedFrom; }
+
+  /// Get the set of using declarations that this pack expanded into. Note that
+  /// some of these may still be unresolved.
+  ArrayRef expansions() const {
+return llvm::makeArrayRef(getTrailingObjects(), 
NumExpansions);
+  }
+
+  static UsingPackDecl *Create(ASTContext , DeclContext *DC,
+   NamedDecl *InstantiatedFrom,
+   ArrayRef UsingDecls);
+
+  static UsingPackDecl *CreateDeserialized(ASTContext , unsigned ID,
+   unsigned NumExpansions);
+
+  SourceRange getSourceRange() const override LLVM_READONLY {
+return InstantiatedFrom->getSourceRange();
+  }
+
+  UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); }
+  const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
+
+  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
+  static bool classofKind(Kind K) { return K == UsingPack; }
+
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
+  friend 

r290075 - Add a lit test for PR31374

2016-12-18 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Sun Dec 18 20:55:53 2016
New Revision: 290075

URL: http://llvm.org/viewvc/llvm-project?rev=290075=rev
Log:
Add a lit test for PR31374

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

Added:
cfe/trunk/test/CodeGenObjC/nullptr-assert.m

Added: cfe/trunk/test/CodeGenObjC/nullptr-assert.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/nullptr-assert.m?rev=290075=auto
==
--- cfe/trunk/test/CodeGenObjC/nullptr-assert.m (added)
+++ cfe/trunk/test/CodeGenObjC/nullptr-assert.m Sun Dec 18 20:55:53 2016
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -Wno-objc-root-class -o /dev/null -triple x86_64-- 
-emit-llvm %s
+// REQUIRES: asserts
+// Verify there is no assertion.
+
+@interface A
+@end
+
+extern A *a;
+
+@interface X
+@end
+
+@implementation X
+
+-(void)test {
+  struct S {
+A *a;
+int b;
+  };
+  struct S s[] = {{a, 0}, {(void *)0, 0}};
+}
+@end


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


[PATCH] D27909: Add a lit test for PR31374

2016-12-18 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL290075: Add a lit test for PR31374 (authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D27909?vs=81907=81910#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27909

Files:
  cfe/trunk/test/CodeGenObjC/nullptr-assert.m


Index: cfe/trunk/test/CodeGenObjC/nullptr-assert.m
===
--- cfe/trunk/test/CodeGenObjC/nullptr-assert.m
+++ cfe/trunk/test/CodeGenObjC/nullptr-assert.m
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -Wno-objc-root-class -o /dev/null -triple x86_64-- 
-emit-llvm %s
+// REQUIRES: asserts
+// Verify there is no assertion.
+
+@interface A
+@end
+
+extern A *a;
+
+@interface X
+@end
+
+@implementation X
+
+-(void)test {
+  struct S {
+A *a;
+int b;
+  };
+  struct S s[] = {{a, 0}, {(void *)0, 0}};
+}
+@end


Index: cfe/trunk/test/CodeGenObjC/nullptr-assert.m
===
--- cfe/trunk/test/CodeGenObjC/nullptr-assert.m
+++ cfe/trunk/test/CodeGenObjC/nullptr-assert.m
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -Wno-objc-root-class -o /dev/null -triple x86_64-- -emit-llvm %s
+// REQUIRES: asserts
+// Verify there is no assertion.
+
+@interface A
+@end
+
+extern A *a;
+
+@interface X
+@end
+
+@implementation X
+
+-(void)test {
+  struct S {
+A *a;
+int b;
+  };
+  struct S s[] = {{a, 0}, {(void *)0, 0}};
+}
+@end
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27909: Add a lit test for PR31374

2016-12-18 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Thanks!




Comment at: test/CodeGenObjC/nullptr-assert.m:1
+// RUN: %clang_cc1 -Wno-objc-root-class -triple x86_64-- -emit-llvm -o - %s
+// REQUIRES: asserts

If the output isn't used, I think you can `-o /dev/null`, then running the test 
manually via `llvm-lit` isn't so wordy


https://reviews.llvm.org/D27909



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


[PATCH] D27909: Add a lite test for PR31374

2016-12-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: thakis.
yaxunl added a subscriber: cfe-commits.

https://reviews.llvm.org/D27909

Files:
  test/CodeGenObjC/nullptr-assert.m


Index: test/CodeGenObjC/nullptr-assert.m
===
--- /dev/null
+++ test/CodeGenObjC/nullptr-assert.m
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -Wno-objc-root-class -triple x86_64-- -emit-llvm -o - %s
+// REQUIRES: asserts
+// Verify there is no assertion.
+
+@interface A
+@end
+
+extern A *a;
+
+@protocol X
+@end
+
+@interface X
+@end
+
+@implementation X
+
+-(void)test {
+  struct S {
+A *a;
+int b;
+  };
+  struct S s[] = {{a, 0}, {(void *)0, 0}};
+}
+@end


Index: test/CodeGenObjC/nullptr-assert.m
===
--- /dev/null
+++ test/CodeGenObjC/nullptr-assert.m
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -Wno-objc-root-class -triple x86_64-- -emit-llvm -o - %s
+// REQUIRES: asserts
+// Verify there is no assertion.
+
+@interface A
+@end
+
+extern A *a;
+
+@protocol X
+@end
+
+@interface X
+@end
+
+@implementation X
+
+-(void)test {
+  struct S {
+A *a;
+int b;
+  };
+  struct S s[] = {{a, 0}, {(void *)0, 0}};
+}
+@end
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

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

Do you need some help with implementing the other fixit, or you just need some 
extra time? It seems to be almost the same as your second fixit




Comment at: clang-tidy/misc/StringCompareCheck.cpp:69-70
+diag(Matched->getLocStart(),
+ "do not use 'compare' to test equality of strings; "
+ "use the string equality operator instead");
+

Take this warning to some static const global variable



Comment at: clang-tidy/misc/StringCompareCheck.cpp:71
+ "use the string equality operator instead");
+
+  if (const auto *Matched = Result.Nodes.getNodeAs("match2")) {

match1 and match2 are in different matchers (passed to register matchers)?

If so put return here after diag to finish control flow for this case.



Comment at: clang-tidy/misc/StringCompareCheck.cpp:81
+  auto Diag = diag(Matched->getLocStart(),
+   "do not use 'compare' to test equality of strings; "
+   "use the string equality operator instead");

and use it here



Comment at: clang-tidy/misc/StringCompareCheck.h:10-11
+
+#ifndef STRING_COMPARE_CHECK_H
+#define STRING_COMPARE_CHECK_H
+

This should be much longer string. Do you know about ./add_new_check?

Please make one similar to other checks



Comment at: clang-tidy/misc/StringCompareCheck.h:36
+
+#endif // STRING_COMPARE_CHECK_H

DITTO



Comment at: test/clang-tidy/misc-string-compare.cpp:35-40
+  if (str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test 
equality of strings; use the string equality operator instead 
[misc-string-compare]
+  if (!str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test 
equality of strings; use the string equality operator instead 
[misc-string-compare]

Why this one doesn't have fixit hint?



Comment at: test/clang-tidy/misc-string-compare.cpp:70
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test 
equality of strings;
+  if (str3->compare(str2) == 0) {

no fixit?


https://reviews.llvm.org/D27210



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


r290072 - Fix name hiding and redeclaration checking for dependent local

2016-12-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Dec 18 16:01:46 2016
New Revision: 290072

URL: http://llvm.org/viewvc/llvm-project?rev=290072=rev
Log:
Fix name hiding and redeclaration checking for dependent local
using-declarations.

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=290072=290071=290072=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Dec 18 16:01:46 2016
@@ -9247,6 +9247,8 @@ bool Sema::CheckUsingDeclRedeclaration(S
const CXXScopeSpec ,
SourceLocation NameLoc,
const LookupResult ) {
+  NestedNameSpecifier *Qual = SS.getScopeRep();
+
   // C++03 [namespace.udecl]p8:
   // C++0x [namespace.udecl]p10:
   //   A using-declaration is a declaration and can therefore be used
@@ -9254,10 +9256,28 @@ bool Sema::CheckUsingDeclRedeclaration(S
   //   allowed.
   //
   // That's in non-member contexts.
-  if (!CurContext->getRedeclContext()->isRecord())
+  if (!CurContext->getRedeclContext()->isRecord()) {
+// A dependent qualifier outside a class can only ever resolve to an
+// enumeration type. Therefore it conflicts with any other non-type
+// declaration in the same scope.
+// FIXME: How should we check for dependent type-type conflicts at block
+// scope?
+if (Qual->isDependent() && !HasTypenameKeyword) {
+  for (auto *D : Prev) {
+if (!isa(D) && !isa(D)) {
+  bool OldCouldBeEnumerator =
+  isa(D) || isa(D);
+  Diag(NameLoc,
+   OldCouldBeEnumerator ? diag::err_redefinition
+: diag::err_redefinition_different_kind)
+  << Prev.getLookupName();
+  Diag(D->getLocation(), diag::note_previous_definition);
+  return true;
+}
+  }
+}
 return false;
-
-  NestedNameSpecifier *Qual = SS.getScopeRep();
+  }
 
   for (LookupResult::iterator I = Prev.begin(), E = Prev.end(); I != E; ++I) {
 NamedDecl *D = *I;
@@ -9275,19 +9295,7 @@ bool Sema::CheckUsingDeclRedeclaration(S
  = dyn_cast(D)) {
   DTypename = true;
   DQual = UD->getQualifier();
-} else if (!isa(D) && Qual->isDependent() &&
-   !HasTypenameKeyword) {
-  // A dependent qualifier outside a class can only ever resolve to an
-  // enumeration type. Therefore it conflicts with any other non-type
-  // declaration in the same scope.
-  // FIXME: How should we check for dependent type-type conflicts at block
-  // scope?
-  Diag(NameLoc, diag::err_redefinition_different_kind)
-  << Prev.getLookupName();
-  Diag(D->getLocation(), diag::note_previous_definition);
-  return true;
-}
-else continue;
+} else continue;
 
 // using decls differ if one says 'typename' and the other doesn't.
 // FIXME: non-dependent using decls?

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=290072=290071=290072=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Sun Dec 18 16:01:46 2016
@@ -450,15 +450,18 @@ static bool canHideTag(NamedDecl *D) {
   //   Given a set of declarations in a single declarative region [...]
   //   exactly one declaration shall declare a class name or enumeration name
   //   that is not a typedef name and the other declarations shall all refer to
-  //   the same variable or enumerator, or all refer to functions and function
-  //   templates; in this case the class name or enumeration name is hidden.
+  //   the same variable, non-static data member, or enumerator, or all refer
+  //   to functions and function templates; in this case the class name or
+  //   enumeration name is hidden.
   // C++ [basic.scope.hiding]p2:
   //   A class name or enumeration name can be hidden by the name of a
   //   variable, data member, function, or enumerator declared in the same
   //   scope.
+  // An UnresolvedUsingValueDecl always instantiates to one of these.
   D = D->getUnderlyingDecl();
   return isa(D) || isa(D) || isa(D) ||
- isa(D) || isa(D);
+ isa(D) || isa(D) ||
+ isa(D);
 }
 
 /// Resolves the result kind of this lookup.

Modified: 
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp?rev=290072=290071=290072=diff

r290071 - Fix some interactions between C++11 and C++14 features and using-declarations:

2016-12-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Dec 18 15:39:37 2016
New Revision: 290071

URL: http://llvm.org/viewvc/llvm-project?rev=290071=rev
Log:
Fix some interactions between C++11 and C++14 features and using-declarations:

 * a dependent non-type using-declaration within a function template can be
   valid, as it can refer to an enumerator, so don't reject it in the template
   definition
 * we can partially substitute into a dependent using-declaration if it appears
   within a (local class in a) generic lambda within a function template, which
   means an UnresolvedUsing*Decl doesn't necessarily instantiate to a UsingDecl.

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=290071=290070=290071=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sun Dec 18 15:39:37 2016
@@ -398,11 +398,11 @@ private:
   llvm::DenseMap
   TemplateOrInstantiation;
 
-  /// \brief Keeps track of the declaration from which a UsingDecl was
+  /// \brief Keeps track of the declaration from which a using declaration was
   /// created during instantiation.
   ///
-  /// The source declaration is always a UsingDecl, an 
UnresolvedUsingValueDecl,
-  /// or an UnresolvedUsingTypenameDecl.
+  /// The source and target declarations are always a UsingDecl, an
+  /// UnresolvedUsingValueDecl, or an UnresolvedUsingTypenameDecl.
   ///
   /// For example:
   /// \code
@@ -421,7 +421,7 @@ private:
   ///
   /// This mapping will contain an entry that maps from the UsingDecl in
   /// B to the UnresolvedUsingDecl in B.
-  llvm::DenseMap InstantiatedFromUsingDecl;
+  llvm::DenseMap InstantiatedFromUsingDecl;
 
   llvm::DenseMap
 InstantiatedFromUsingShadowDecl;
@@ -849,11 +849,11 @@ public:
   /// \brief If the given using decl \p Inst is an instantiation of a
   /// (possibly unresolved) using decl from a template instantiation,
   /// return it.
-  NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
+  NamedDecl *getInstantiatedFromUsingDecl(NamedDecl *Inst);
 
   /// \brief Remember that the using decl \p Inst is an instantiation
   /// of the using decl \p Pattern of a class template.
-  void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
+  void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern);
 
   void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
   UsingShadowDecl *Pattern);

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=290071=290070=290071=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sun Dec 18 15:39:37 2016
@@ -4317,6 +4317,7 @@ public:
SourceLocation NameLoc,
const LookupResult );
   bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
+   bool HasTypename,
const CXXScopeSpec ,
const DeclarationNameInfo ,
SourceLocation NameLoc);

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=290071=290070=290071=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Dec 18 15:39:37 2016
@@ -1270,9 +1270,8 @@ void ASTContext::setClassScopeSpecializa
 }
 
 NamedDecl *
-ASTContext::getInstantiatedFromUsingDecl(UsingDecl *UUD) {
-  llvm::DenseMap::const_iterator Pos
-= InstantiatedFromUsingDecl.find(UUD);
+ASTContext::getInstantiatedFromUsingDecl(NamedDecl *UUD) {
+  auto Pos = InstantiatedFromUsingDecl.find(UUD);
   if (Pos == InstantiatedFromUsingDecl.end())
 return nullptr;
 
@@ -1280,11 +1279,15 @@ ASTContext::getInstantiatedFromUsingDecl
 }
 
 void
-ASTContext::setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern) {
+ASTContext::setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern) {
   assert((isa(Pattern) ||
   isa(Pattern) ||
   isa(Pattern)) && 
  "pattern decl is not a using decl");
+  assert((isa(Inst) ||
+  isa(Inst) ||
+  isa(Inst)) && 
+ "instantiation did not produce a using decl");
   

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

2016-12-18 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:433-434
 void CGDebugInfo::CreateCompileUnit() {
+   SmallString<32> Checksum;
+  llvm::DIFile::ChecksumKind CSKind = llvm::DIFile::CSK_None;
 

Formatting looks wrong


https://reviews.llvm.org/D27641



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


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

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

Small changes made by suggestions. strCompare is now with uppercase: StrCompare

Checking for str.compare(str) == {-1,1} as well.


https://reviews.llvm.org/D27210

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

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,121 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template , typename A = std::allocator>
+class basic_string {
+public:
+  basic_string();
+  basic_string(const C *, unsigned int size);
+  int compare(const basic_string ) const;
+  int compare(const C *) const;
+  int compare(int, int, const basic_string ) const;
+  bool empty();
+};
+bool operator==(const basic_string , const basic_string );
+bool operator!=(const basic_string , const basic_string );
+bool operator==(const basic_string , const char *);
+typedef basic_string string;
+}
+
+void func(bool b);
+
+std::string comp() {
+  std::string str("a", 1);
+  return str;
+}
+
+void Test() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+
+  if (str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (!str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (str1.compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == str2) {
+  if (str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 != str2) {
+  if (str1.compare("foo") == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == "foo") {
+  if (0 == str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == str1) {
+  if (0 != str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 != str1) {
+  func(str1.compare(str2));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: do not use 'compare' to test equality of strings;
+  if (str2.empty() || str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:23: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2.empty() || str1 != str2) {
+  std::string *str3 = 
+  if (str3->compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  if (str3->compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (*str3 == str2) {
+  if (str2.compare(*str3) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == *str3) {
+  if (comp().compare(str1) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (comp() == str1) {
+  if (str1.compare(comp()) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == comp()) {
+  if (str1.compare(comp())) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  if (str1.compare(str2) == 1) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: 'compare' is not guaranteed to return -1 or 1; check for bigger or smaller than 0 instead
+  if (str1.compare(str2) == -1) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: 'compare' is not guaranteed to return -1 or 1;
+}
+
+void Valid() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+  if (str1 == str2) {
+  }
+  if (str1 != str2) {
+  }
+  if (str1.compare(str2) == str1.compare(str2)) {
+  }
+  if (0 == 0) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(1, 3, str2)) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(str2) < 0) {
+  }
+  if (str1.compare(str2) == 2) {
+  }
+  if (str1.compare(str2) == -3) {
+  }
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst

[PATCH] D25659: [clang-tidy] Avoid running aliased checks twice

2016-12-18 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons abandoned this revision.
malcolm.parsons added a comment.

Abandon until we have a plan.


https://reviews.llvm.org/D25659



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


r290063 - Wdocumentation fix

2016-12-18 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Sun Dec 18 08:12:38 2016
New Revision: 290063

URL: http://llvm.org/viewvc/llvm-project?rev=290063=rev
Log:
Wdocumentation fix

Modified:
cfe/trunk/include/clang/Basic/OpenCLOptions.h

Modified: cfe/trunk/include/clang/Basic/OpenCLOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenCLOptions.h?rev=290063=290062=290063=diff
==
--- cfe/trunk/include/clang/Basic/OpenCLOptions.h (original)
+++ cfe/trunk/include/clang/Basic/OpenCLOptions.h Sun Dec 18 08:12:38 2016
@@ -70,7 +70,7 @@ public:
   /// \brief Enable or disable support for OpenCL extensions
   /// \param Ext name of the extension optionally prefixed with
   ///'+' or '-'
-  /// \param Enable used when \p Ext is not prefixed by '+' or '-'
+  /// \param V used when \p Ext is not prefixed by '+' or '-'
   void support(llvm::StringRef Ext, bool V = true) {
 assert(!Ext.empty() && "Extension is empty.");
 


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


[PATCH] D27440: clang-format-vsix: fail when clang-format outputs to stderr

2016-12-18 Thread Antonio Maiorano via Phabricator via cfe-commits
amaiorano added a comment.

In https://reviews.llvm.org/D27440#624917, @djasper wrote:

> Yes.. return non-zero seems right. This is an error condition.


Hi @djasper ,

I started looking into making the changes to clang-format to have it return an 
error code when it's unable to parse the .clang-format file, but I'm not quite 
sure what the best approach is. The function that needs modifying is getStyle 
. 
There are multiple places in there where it outputs to stderr (llvm::errs()) 
when something goes wrong, like here 
.

So here's what I'm thinking in terms of solutions when an error occurs in 
getStyle:

1. Throw an exception. This is unidiomatic in clang-format, and isn't something 
I'm particularly fond of, but it means not modifying the return type, and not 
having to modify the tests since they assume the green path.

2. Return an llvm::ErrorOr. Of course, this changes the signature, which means 
changing the few places that call getStyle. From what I can tell, it's only 
being called in a couple of places, and in the tests, so perhaps it's not 
terrible.

3. Return an llvm::Optional. This is similar to ErrorOr, except that it may 
allow us to codify the fallback behaviour on the outside of this call. What I 
mean is that with Optional, we wouldn't have to pass in the fallback style, but 
rather, the function could return an error when the input style isn't found or 
parsed correctly, etc., and the calling code can decide what to do with the 
error: either stop right there (return an error code from main), or it can try 
to get the fallback style. Something like:



  // The case where we don't care about errors and want to use a fallback style:
  FormatStyle fallbackStyle = getLLVMStyle();
  FormatStyle formatStyle = getStyle("", fileName).getValueOr(fallbackStyle);
  
  
  // The case where we do care about errors
  auto maybeFormatStyle = getStyle("", fileName);
  if (!maybeFormatStyle)
  return 0;
  
  FormatStyle formatStyle = maybeFormatStyle.getValue();

Obviously this third option would change the most code, but maybe it makes more 
sense for getStyle to not have this notion of fallback style within it, as it 
effectively hides errors.

Would love to hear your thoughts.


https://reviews.llvm.org/D27440



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


[PATCH] D27898: [compiler-rt] [builtins] Implement __floattitf() & __floatuntitf()

2016-12-18 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: sdmitrouk, rengolin, zatrazz.
mgorny added a subscriber: cfe-commits.
Herald added subscribers: dberris, aemerson.

Implement the missing __floattitf() and __floatuntitf() functions, to
convert 128-bit (unsigned) integers to quad-precision floating-point
types. This is needed e.g. on AArch64 where 'long double' is
a quad-precision type.

The code is based on the existing code for __floattixf()
and __floatuntixf(), updated to account for different bit field lengths
of quad-precision float. The tests are also copied, with the rounding
tests adjusted for longer mantissa.

(tested on AArch64)


https://reviews.llvm.org/D27898

Files:
  lib/builtins/CMakeLists.txt
  lib/builtins/floattitf.c
  lib/builtins/floatuntitf.c
  test/builtins/Unit/floattitf_test.c
  test/builtins/Unit/floatuntitf_test.c

Index: test/builtins/Unit/floatuntitf_test.c
===
--- /dev/null
+++ test/builtins/Unit/floatuntitf_test.c
@@ -0,0 +1,223 @@
+//===-- floatuntitf.c - Test __floatuntitf ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file tests __floatuntitf for the compiler_rt library.
+//
+//===--===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+#include "int_lib.h"
+#include 
+#include 
+
+#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+
+/* Returns: convert a tu_int to a fp_t, rounding toward even. */
+
+/* Assumption: fp_t is a IEEE 128 bit floating point type
+ * tu_int is a 128 bit integral type
+ */
+
+/* seee        |         |
+ *         |        
+ */
+
+COMPILER_RT_ABI fp_t __floatuntitf(tu_int a);
+
+int test__floatuntitf(tu_int a, fp_t expected)
+{
+fp_t x = __floatuntitf(a);
+if (x != expected)
+{
+utwords at;
+at.all = a;
+printf("error in __floatuntitf(0x%.16llX%.16llX) = %LA, expected %LA\n",
+   at.s.high, at.s.low, x, expected);
+}
+return x != expected;
+}
+
+char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
+char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
+char assumption_3[sizeof(fp_t)*CHAR_BIT == 128] = {0};
+
+#endif
+
+int main()
+{
+#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+if (test__floatuntitf(0, 0.0))
+return 1;
+
+if (test__floatuntitf(1, 1.0))
+return 1;
+if (test__floatuntitf(2, 2.0))
+return 1;
+if (test__floatuntitf(20, 20.0))
+return 1;
+
+if (test__floatuntitf(0x7F80ULL, 0x1.FEp+62))
+return 1;
+if (test__floatuntitf(0x7800ULL, 0x1.Ep+62))
+return 1;
+if (test__floatuntitf(0x7F00ULL, 0x1.FCp+62))
+return 1;
+if (test__floatuntitf(0x7000ULL, 0x1.Cp+62))
+return 1;
+if (test__floatuntitf(0x7FFFULL, 0xF.FFEp+59L))
+return 1;
+if (test__floatuntitf(0xFFFEULL, 0xF.FFEp+60L))
+return 1;
+if (test__floatuntitf(0xULL, 0xF.FFFp+60L))
+return 1;
+
+if (test__floatuntitf(0x8080ULL, 0x8.08p+60))
+return 1;
+if (test__floatuntitf(0x8800ULL, 0x8.8p+60))
+return 1;
+if (test__floatuntitf(0x8100ULL, 0x8.1p+60))
+return 1;
+if (test__floatuntitf(0x80001000ULL, 0x8.0001p+60))
+return 1;
+
+if (test__floatuntitf(0x8000ULL, 0x8p+60))
+return 1;
+if (test__floatuntitf(0x8001ULL, 0x8.001p+60L))
+return 1;
+
+if (test__floatuntitf(0x0007FB72E800LL, 0x1.FEDCBAp+50))
+return 1;
+
+if (test__floatuntitf(0x0007FB72EA00LL, 0x1.FEDCBA8p+50))
+return 1;
+if (test__floatuntitf(0x0007FB72EB00LL, 0x1.FEDCBACp+50))
+return 1;
+if (test__floatuntitf(0x0007FB72EBFFLL, 0x1.FEDCBAFFCp+50))
+return 1;
+if (test__floatuntitf(0x0007FB72EC00LL, 0x1.FEDCBBp+50))
+return 1;
+if (test__floatuntitf(0x0007FB72E801LL, 0x1.FEDCBA004p+50))
+return 1;
+
+if (test__floatuntitf(0x0007FB72E600LL, 0x1.FEDCB98p+50))
+return 1;
+if (test__floatuntitf(0x0007FB72E700LL, 0x1.FEDCB9Cp+50))
+return 1;
+if (test__floatuntitf(0x0007FB72E7FFLL, 0x1.FEDCB9FFCp+50))
+return 1;
+if (test__floatuntitf(0x0007FB72E401LL, 0x1.FEDCB9004p+50))
+