Re: [PATCH] D18551: Added Fixer implementation and fix() interface in clang-format for removing redundant code.

2016-04-05 Thread Daniel Jasper via cfe-commits
djasper added inline comments.


Comment at: lib/Format/Format.cpp:1654
@@ +1653,3 @@
+UnwrappedLines.push_back(SmallVector());
+  }
+

That I don't understand. Almost all fixers (cleaning up commas, constructor 
initializers, etc.) will only ever look at a single line.

The matchers that do make multiline fixes (empty namespaces, empty 
public/private sections) only look at complete lines, i.e. only ever use 
AnnotatedLine::startsWith(...) and don't iterate over the tokens, AFAICT.

I really think that giving the option to iterate over all tokens of multiple 
lines does more harm than good. Among several other things, error recovery is 
made harder. It never makes sense for the ctor-initializer fixer to leave its 
line (or else you'll just ignore some nice error recovery already implemented 
in the UnwrappedLineParser). 


Comment at: lib/Format/Format.cpp:1693
@@ +1692,3 @@
+// FIXME: we need better way to determine wether to delete this token.
+if (!AnnotatedLines[CurrentLine]->Affected && !Forced) return;
+Tok->Deleted = true;

I have a comment here (and in some other places), but I think this will be 
different anyway if we move to line-based fixers. So I am holding off with 
those comments for now.


Comment at: lib/Format/Format.cpp:1718
@@ +1717,3 @@
+  void skipParens() {
+assert(CurrentToken->is(tok::l_paren));
+nextToken();

Just go to CurrentToken->MatchingParen!?


Comment at: lib/Format/Format.cpp:1824
@@ +1823,3 @@
+  // Returns true if the namespace is empty .
+  bool checkEmptyNamespace() {
+assert(CurrentToken->is(tok::kw_namespace));

I am happy to show you how the implementation here gets much simpler if you 
only iterate over AnnotatedLines.


Comment at: lib/Format/Format.cpp:1916
@@ +1915,3 @@
+  FormatToken *CurrentToken;
+  // Redundant tokens to be deleted.
+  std::set RedundantTokens;

I think "redundant" is the wrong word here. How about DeletedTokens?


http://reviews.llvm.org/D18551



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


Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-05 Thread Eric Christopher via cfe-commits
echristo added inline comments.


Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:477-479
@@ -476,2 +476,5 @@
+  unsigned DebugCUs = 0;
   for (MDNode *N : CU_Nodes->operands()) {
 auto *CUNode = cast(N);
+if (CUNode->getEmissionKind() == DICompileUnit::NoDebug)
+  continue;

Instead of this pattern would it make more sense to have an iterator over the 
nodes that checks for !NoDebug?


Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1127-1128
@@ -1115,3 +1126,4 @@
   if (!MMI->hasDebugInfo() || LScopes.empty() ||
-  !MF->getFunction()->getSubprogram()) {
+  !MF->getFunction()->getSubprogram() ||
+  !SPMap.lookup(MF->getFunction()->getSubprogram())) {
 // If we don't have a lexical scope for this function then there will

Comment.


Repository:
  rL LLVM

http://reviews.llvm.org/D18808



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


[PATCH] D18815: [ObjC] Enter a new evaluation context before calling BuildBlockForLambdaConversion.

2016-04-05 Thread Akira Hatanaka via cfe-commits
ahatanak created this revision.
ahatanak added a subscriber: cfe-commits.

Currently, when clang compiles the following code,

id test() {
  return @{@"a": [](){}, @"b": [](){}};
}

it builds an AST that is incorrect:

ReturnStmt 0x10d080448
`-ExprWithCleanups 0x10d080428
|-cleanup Block 0x10d0801f0 // points to the second BlockDecl
  ...
  -BlockDecl 0x10d07f150 // First block
  ...
  -BlockDecl 0x10d0801f0 // Second block
  ...
`-ExprWithCleanups 0x10d0801d0
   |-cleanup Block 0x10d07f150 // points to the first BlockDecl

The ExprWithCleanups for the ReturnStmt has only one block (the second block) 
in its cleanup list. The other block (the first block) is in the cleanup list 
of the ExprWithCleanups attached to the second block. This happens because 
Sema::ExprCleanupObjects is false when MaybeCreateExprWithCleanups is called in 
Sema::ActOnFinishFullExpr the first time, but is true when the function is 
called the second time (Sema::BuildBlockForLambdaConversion sets 
ExprCleanupObjects to true when it builds the block for the first lambda).

To fix this bug, this patch pushes a new evaluation context before calling 
BuildBlockForLambdaConversion. This ensures that Sema::ExprCleanupObjects is 
false when MaybeCreateExprWithCleanups is called the second time too.

http://reviews.llvm.org/D18815

Files:
  lib/Sema/SemaExprCXX.cpp
  test/SemaObjCXX/block-cleanup.mm

Index: test/SemaObjCXX/block-cleanup.mm
===
--- /dev/null
+++ test/SemaObjCXX/block-cleanup.mm
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.11.0 -std=gnu++11 -o 
/dev/null -x objective-c++ -fblocks -ast-dump %s 2>&1 | FileCheck %s
+
+// CHECK:  -FunctionDecl {{.*}} test 'id (void)'
+// CHECK-NEXT:   -CompoundStmt
+// CHECK-NEXT: -ReturnStmt
+// CHECK-NEXT:   -ExprWithCleanups
+// CHECK-NEXT: -cleanup Block
+// CHECK-NEXT: -cleanup Block
+
+@interface NSDictionary
++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys 
count:(unsigned long)cnt;
+@end
+
+id test() {
+  return @{@"a": [](){}, @"b": [](){}};
+}
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -6233,9 +6233,12 @@
   // follows the normal lifetime rules for block literals instead of being
   // autoreleased.
   DiagnosticErrorTrap Trap(Diags);
+  PushExpressionEvaluationContext(PotentiallyEvaluated);
   ExprResult Exp = BuildBlockForLambdaConversion(E->getExprLoc(),
  E->getExprLoc(),
  Method, E);
+  PopExpressionEvaluationContext();
+
   if (Exp.isInvalid())
 Diag(E->getExprLoc(), diag::note_lambda_to_block_conv);
   return Exp;


Index: test/SemaObjCXX/block-cleanup.mm
===
--- /dev/null
+++ test/SemaObjCXX/block-cleanup.mm
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.11.0 -std=gnu++11 -o /dev/null -x objective-c++ -fblocks -ast-dump %s 2>&1 | FileCheck %s
+
+// CHECK:  -FunctionDecl {{.*}} test 'id (void)'
+// CHECK-NEXT:   -CompoundStmt
+// CHECK-NEXT: -ReturnStmt
+// CHECK-NEXT:   -ExprWithCleanups
+// CHECK-NEXT: -cleanup Block
+// CHECK-NEXT: -cleanup Block
+
+@interface NSDictionary
++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
+@end
+
+id test() {
+  return @{@"a": [](){}, @"b": [](){}};
+}
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -6233,9 +6233,12 @@
   // follows the normal lifetime rules for block literals instead of being
   // autoreleased.
   DiagnosticErrorTrap Trap(Diags);
+  PushExpressionEvaluationContext(PotentiallyEvaluated);
   ExprResult Exp = BuildBlockForLambdaConversion(E->getExprLoc(),
  E->getExprLoc(),
  Method, E);
+  PopExpressionEvaluationContext();
+
   if (Exp.isInvalid())
 Diag(E->getExprLoc(), diag::note_lambda_to_block_conv);
   return Exp;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-05 Thread Duncan P. N. Exon Smith via cfe-commits
IR changes LGTM, if you add the missing verifier check (I'm surprised
this *ever* passed the verifier...)

Someone else will have to look at DwarfDebug.cpp.


> On 2016-Apr-05, at 16:55, Adrian Prantl  wrote:
> 
> aprantl created this revision.
> aprantl added reviewers: dblaikie, echristo, dexonsmith.
> aprantl added subscribers: davide, llvm-commits, cfe-commits.
> aprantl set the repository for this revision to rL LLVM.
> 
> As indicated in D18612, sample-based profiling and optimization remarks 
> currently remove DICompileUnits from llvm.dbg.cu to suppress the emission of 
> debug info from them. This is somewhat of a hack and only borderline legal IR.
> 
> This patch uses the recently introduced NoDebug emission kind in 
> DICompileUnit to achieve the same result without breaking the Verifier. A 
> nice side-effect of this change is that it is now possible to combine NoDebug 
> and regular compile units under LTO.
> 
> For simplicity I combined the llvm and cfe patches into one review.
> 
> Repository:
>  rL LLVM
> 
> http://reviews.llvm.org/D18808
> 
> Files:
>  include/llvm/IR/DIBuilder.h
>  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>  lib/IR/DIBuilder.cpp
>  test/DebugInfo/X86/mixed-nodebug-cu.ll
>  tools/clang/lib/CodeGen/CGDebugInfo.cpp
>  tools/clang/test/Frontend/optimization-remark.c
>  tools/clang/test/Frontend/profile-sample-use-loc-tracking.c
> 
> 

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


Re: [PATCH] D18073: Add memory allocating functions

2016-04-05 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

> So for _wcsdup_dbg, I should leave only testWinWcsdupDbg?


Yes.

Also, since there will be many of these "alternate" functions, could you create 
a separate test file for them?


http://reviews.llvm.org/D18073



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


Re: [PATCH] D17412: PR19957: [OpenCL] incorrectly accepts implicit address space conversion with ternary operator

2016-04-05 Thread Xiuli PAN via cfe-commits
pxli168 accepted this revision.
pxli168 added a comment.

LGTM!
Thanks!


http://reviews.llvm.org/D17412



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


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

2016-04-05 Thread Peter Collingbourne via cfe-commits
pcc updated this revision to Diff 52759.
pcc added a comment.

- New implementation


http://reviews.llvm.org/D18635

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

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

Re: [PATCH] D18073: Add memory allocating functions

2016-04-05 Thread Alexander Riccio via cfe-commits
ariccio added a comment.

Maybe I'm being thick headed and I can't see it - sorry if I am - but I'm still 
a bit confused. Can you tell me what I should do in the `_wcsdup_dbg` example?


http://reviews.llvm.org/D18073



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


Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-05 Thread Jakub Staroń via cfe-commits
staronj retitled this revision from "[clang-tidy] Adds misc-use-bool-literals 
check." to "[clang-tidy] Adds modernize-use-bool-literals check.".
staronj updated this revision to Diff 52739.
staronj added a comment.

1. Name changed from misc-use-bool-literals to modernize-use-bool-literals.
2. Code clang-formatted.
3. Check ran on LLVM code.


http://reviews.llvm.org/D18745

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-bool-literals.rst
  test/clang-tidy/modernize-use-bool-literals.cpp

Index: test/clang-tidy/modernize-use-bool-literals.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-bool-literals.cpp
@@ -0,0 +1,41 @@
+// RUN: %check_clang_tidy %s modernize-use-bool-literals %t
+
+bool bar1 = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: implicitly converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool bar1 = true;{{$}}
+
+bool bar2 = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool bar2 = false;{{$}}
+
+bool bar3 = 0x123ABCLL;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool bar3 = true;{{$}}
+
+#define TRUE_FALSE 1
+
+bool bar4 = TRUE_FALSE;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: implicitly converting integer literal to bool inside macro, use bool literal instead [modernize-use-bool-literals]
+
+#define TRUE_FALSE2 bool(1) // OK
+
+bool bar6 = true; // OK
+
+void foo4(bool bar) {
+
+}
+
+char bar7 = 0;
+unsigned long long bar8 = 1;
+
+int main() {
+  foo4(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}
+  // CHECK-FIXES: {{^}}  foo4(true);{{$}}
+
+  foo4(false); // OK
+
+  bar1 = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: {{.*}}
+  // CHECK-FIXES: {{^}}  bar1 = false;{{$}}
+}
Index: docs/clang-tidy/checks/modernize-use-bool-literals.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-bool-literals.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - modernize-use-bool-literals
+
+modernize-use-bool-literals
+===
+
+Finds integer literals, which are implicitly cast to bool.
+
+.. code-block:: c++
+
+  bool p = 1;
+  std::ios_base::sync_with_stdio(0);
+
+  // transforms to
+
+  bool p = true;
+  std::ios_base::sync_with_stdio(false);
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
@@ -85,6 +85,7 @@
modernize-replace-auto-ptr
modernize-shrink-to-fit
modernize-use-auto
+   modernize-use-bool-literals
modernize-use-default
modernize-use-nullptr
modernize-use-override
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -119,6 +119,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-bool-literals
+  `_ check
+
+  Finds integer literals, which are implicitly cast to bool.
+
 - New `performance-faster-string-find
   `_ check
 
Index: clang-tidy/modernize/UseBoolLiteralsCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseBoolLiteralsCheck.h
@@ -0,0 +1,35 @@
+//===--- UseBoolLiteralsCheck.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_MODERNIZE_USE_BOOL_LITERALS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_BOOL_LITERALS_H
+
+#include "../ClangTidy.h"
+

Re: [PATCH] D18584: Complete support for C++ Core Guidelines Type.6: Always initialize a member variable.

2016-04-05 Thread Michael Miller via cfe-commits
michael_miller updated this revision to Diff 52752.
michael_miller added a comment.

Addressed comments.
Moved isTriviallyDefaultConstructible into utils/TypeTraits.
Moved AST matchers into utils/Matchers.h.
Enclosed all source-local functions in an anonymous namespace and removed 
static.
Replaced stray ands and ors with && and ||.


http://reviews.llvm.org/D18584

Files:
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
  clang-tidy/utils/Matchers.h
  clang-tidy/utils/TypeTraits.cpp
  clang-tidy/utils/TypeTraits.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
  test/clang-tidy/cppcoreguidelines-pro-type-member-init-cxx98.cpp
  test/clang-tidy/cppcoreguidelines-pro-type-member-init-delayed.cpp
  test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -4,13 +4,13 @@
   int F;
   // CHECK-FIXES: int F{};
   PositiveFieldBeforeConstructor() {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these built-in/pointer fields: F
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
   // CHECK-FIXES: PositiveFieldBeforeConstructor() {}
 };
 
 struct PositiveFieldAfterConstructor {
   PositiveFieldAfterConstructor() {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these built-in/pointer fields: F, G
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F, G
   // CHECK-FIXES: PositiveFieldAfterConstructor() {}
   int F;
   // CHECK-FIXES: int F{};
@@ -26,12 +26,12 @@
 };
 
 PositiveSeparateDefinition::PositiveSeparateDefinition() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these built-in/pointer fields: F
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
 // CHECK-FIXES: PositiveSeparateDefinition::PositiveSeparateDefinition() {}
 
 struct PositiveMixedFieldOrder {
   PositiveMixedFieldOrder() : J(0) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these built-in/pointer fields: I, K
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: I, K
   // CHECK-FIXES: PositiveMixedFieldOrder() : J(0) {}
   int I;
   // CHECK-FIXES: int I{};
@@ -43,7 +43,7 @@
 template 
 struct Template {
   Template() {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these built-in/pointer fields: F
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
   int F;
   // CHECK-FIXES: int F{};
   T T1;
@@ -67,7 +67,6 @@
 };
 NegativeFieldInitializedInDefinition::NegativeFieldInitializedInDefinition() : F() {}
 
-
 struct NegativeInClassInitialized {
   int F = 0;
 
@@ -87,25 +86,249 @@
 };
 
 #define UNINITIALIZED_FIELD_IN_MACRO_BODY(FIELD) \
-  struct UninitializedField##FIELD {		 \
-UninitializedField##FIELD() {}		 \
-int FIELD;	 \
-  };		 \
+  struct UninitializedField##FIELD { \
+UninitializedField##FIELD() {}   \
+int FIELD;   \
+  }; \
 // Ensure FIELD is not initialized since fixes inside of macros are disabled.
 // CHECK-FIXES: int FIELD;
 
 UNINITIALIZED_FIELD_IN_MACRO_BODY(F);
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these built-in/pointer fields: F
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
 UNINITIALIZED_FIELD_IN_MACRO_BODY(G);
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these built-in/pointer fields: G
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: G
 
 #define UNINITIALIZED_FIELD_IN_MACRO_ARGUMENT(ARGUMENT) \
-  ARGUMENT		\
+  ARGUMENT
 
 UNINITIALIZED_FIELD_IN_MACRO_ARGUMENT(struct UninitializedFieldInMacroArg {
   UninitializedFieldInMacroArg() {}
   int Field;
 });
-// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: constructor does not initialize these built-in/pointer fields: Field
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: constructor does not initialize these fields: Field
 // Ensure FIELD is not initialized since fixes inside of macros are disabled.
 // CHECK-FIXES: int Field;
+
+struct NegativeAggregateType {
+  int X;
+  int Y;
+  int Z;
+};
+
+struct PositiveTrivialType {
+  PositiveTrivialType() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields: F
+
+  NegativeAggregateType F;
+  // CHECK-FIXES: NegativeAggregateType F{};
+};
+
+struct NegativeNonTrivialType {
+ 

[PATCH] D18810: [Clang-tidy] Fix readability-static-definition-in-anonymous-namespace warnings; other minor fixes.

2016-04-05 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko created this revision.
Eugene.Zelenko added reviewers: alexfh, aaron.ballman.
Eugene.Zelenko added a subscriber: cfe-commits.
Eugene.Zelenko set the repository for this revision to rL LLVM.

Some Include What You Use suggestions were used too.

I checked this patch on my own build on RHEL 6. Regressions were OK.

Repository:
  rL LLVM

http://reviews.llvm.org/D18810

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tidy/misc/DanglingHandleCheck.cpp
  clang-tidy/performance/FasterStringFindCheck.cpp

Index: clang-tidy/performance/FasterStringFindCheck.cpp
===
--- clang-tidy/performance/FasterStringFindCheck.cpp
+++ clang-tidy/performance/FasterStringFindCheck.cpp
@@ -11,7 +11,11 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -21,7 +25,7 @@
 
 namespace {
 
-static const char StringLikeClassesDelimiter[] = ";";
+const char StringLikeClassesDelimiter[] = ";";
 
 std::vector ParseClasses(StringRef Option) {
   SmallVector Classes;
@@ -59,7 +63,7 @@
 hasDescendant(substTemplateTypeParmType();
 }
 
-} // namespace
+} // anonymous namespace
 
 FasterStringFindCheck::FasterStringFindCheck(StringRef Name,
  ClangTidyContext *Context)
Index: clang-tidy/misc/DanglingHandleCheck.cpp
===
--- clang-tidy/misc/DanglingHandleCheck.cpp
+++ clang-tidy/misc/DanglingHandleCheck.cpp
@@ -10,6 +10,10 @@
 #include "DanglingHandleCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -19,13 +23,13 @@
 
 namespace {
 
-static const char HandleClassesDelimiter[] = ";";
+const char HandleClassesDelimiter[] = ";";
 
 std::vector parseClasses(StringRef Option) {
   SmallVector Classes;
   Option.split(Classes, HandleClassesDelimiter);
   std::vector Result;
-  for (StringRef &Class : Classes) {
+  for (auto &Class : Classes) {
 Class = Class.trim();
 if (!Class.empty())
   Result.push_back(Class);
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -13,6 +13,10 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include 
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 using llvm::SmallPtrSet;
@@ -28,7 +32,7 @@
   return Node.isUserProvided();
 }
 
-static void
+void
 fieldsRequiringInit(const RecordDecl::field_range &Fields,
 SmallPtrSetImpl &FieldsToInit) {
   for (const FieldDecl *F : Fields) {
@@ -166,7 +170,7 @@
   return OrderedFields;
 }
 
-} // namespace
+} // anonymous namespace
 
 void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxConstructorDecl(isDefinition(), isUserProvided(),
Index: clang-tidy/ClangTidy.cpp
===
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -36,6 +36,8 @@
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/ReplacementsYaml.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
 #include 
@@ -52,9 +54,10 @@
 namespace tidy {
 
 namespace {
-static const char *AnalyzerCheckNamePrefix = "clang-analyzer-";
 
-static const StringRef StaticAnalyzerChecks[] = {
+const char *AnalyzerCheckNamePrefix = "clang-analyzer-";
+
+const StringRef StaticAnalyzerChecks[] = {
 #define GET_CHECKERS
 #define CHECKER(FULLNAME, CLASS, DESCFILE, HELPTEXT, GROUPINDEX, HIDDEN)   \
   FULLNAME,
@@ -213,7 +216,7 @@
   std::vector> Checks;
 };
 
-} // namespace
+} // anonymous namespace
 
 ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
 ClangTidyContext &Context)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-05 Thread Adrian Prantl via cfe-commits
aprantl created this revision.
aprantl added reviewers: dblaikie, echristo, dexonsmith.
aprantl added subscribers: davide, llvm-commits, cfe-commits.
aprantl set the repository for this revision to rL LLVM.

As indicated in D18612, sample-based profiling and optimization remarks 
currently remove DICompileUnits from llvm.dbg.cu to suppress the emission of 
debug info from them. This is somewhat of a hack and only borderline legal IR.

This patch uses the recently introduced NoDebug emission kind in DICompileUnit 
to achieve the same result without breaking the Verifier. A nice side-effect of 
this change is that it is now possible to combine NoDebug and regular compile 
units under LTO.

For simplicity I combined the llvm and cfe patches into one review.

Repository:
  rL LLVM

http://reviews.llvm.org/D18808

Files:
  include/llvm/IR/DIBuilder.h
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  lib/IR/DIBuilder.cpp
  test/DebugInfo/X86/mixed-nodebug-cu.ll
  tools/clang/lib/CodeGen/CGDebugInfo.cpp
  tools/clang/test/Frontend/optimization-remark.c
  tools/clang/test/Frontend/profile-sample-use-loc-tracking.c

Index: tools/clang/test/Frontend/profile-sample-use-loc-tracking.c
===
--- tools/clang/test/Frontend/profile-sample-use-loc-tracking.c
+++ tools/clang/test/Frontend/profile-sample-use-loc-tracking.c
@@ -10,9 +10,10 @@
 // CHECK: , !dbg !
 // CHECK-NOT: DW_TAG_base_type
 
-// But llvm.dbg.cu should be missing (to prevent writing debug info to
+// The CU should be marked NoDebug (to prevent writing debug info to
 // the final output).
-// CHECK-NOT: !llvm.dbg.cu = !{
+// CHECK: !llvm.dbg.cu = !{![[CU:.*]]}
+// CHECK: ![[CU]] = distinct !DICompileUnit({{.*}}emissionKind: NoDebug
 
 int bar(int j) {
   return (j + j - 2) * (j - 2) * j;
Index: tools/clang/test/Frontend/optimization-remark.c
===
--- tools/clang/test/Frontend/optimization-remark.c
+++ tools/clang/test/Frontend/optimization-remark.c
@@ -27,9 +27,10 @@
 // CHECK: , !dbg !
 // CHECK-NOT: DW_TAG_base_type
 
-// But llvm.dbg.cu should be missing (to prevent writing debug info to
+// The CU should be marked NoDebug (to prevent writing debug info to
 // the final output).
-// CHECK-NOT: !llvm.dbg.cu = !{
+// CHECK: !llvm.dbg.cu = !{![[CU:.*]]}
+// CHECK: ![[CU]] = distinct !DICompileUnit({{.*}}emissionKind: NoDebug
 
 int foo(int x, int y) __attribute__((always_inline));
 int foo(int x, int y) { return x + y; }
Index: tools/clang/lib/CodeGen/CGDebugInfo.cpp
===
--- tools/clang/lib/CodeGen/CGDebugInfo.cpp
+++ tools/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -396,16 +396,27 @@
   if (LO.ObjC1)
 RuntimeVers = LO.ObjCRuntime.isNonFragile() ? 2 : 1;
 
+  llvm::DICompileUnit::DebugEmissionKind EmissionKind;
+  switch (DebugKind) {
+  case codegenoptions::NoDebugInfo:
+  case codegenoptions::LocTrackingOnly:
+EmissionKind = llvm::DICompileUnit::NoDebug;
+break;
+  case codegenoptions::DebugLineTablesOnly:
+EmissionKind = llvm::DICompileUnit::LineTablesOnly;
+break;
+  case codegenoptions::LimitedDebugInfo:
+  case codegenoptions::FullDebugInfo:
+EmissionKind = llvm::DICompileUnit::FullDebug;
+break;
+  }
+
   // Create new compile unit.
   // FIXME - Eliminate TheCU.
   TheCU = DBuilder.createCompileUnit(
   LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
-  CGM.getCodeGenOpts().SplitDwarfFile,
-  DebugKind <= codegenoptions::DebugLineTablesOnly
-  ? llvm::DICompileUnit::LineTablesOnly
-  : llvm::DICompileUnit::FullDebug,
-  0 /* DWOid */, DebugKind != codegenoptions::LocTrackingOnly);
+  CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
Index: test/DebugInfo/X86/mixed-nodebug-cu.ll
===
--- /dev/null
+++ test/DebugInfo/X86/mixed-nodebug-cu.ll
@@ -0,0 +1,50 @@
+; RUN: llc %s -o %t -filetype=obj
+; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s
+; CHECK: DW_TAG_compile_unit
+; CHECK:   DW_TAG_subprogram
+; CHECK: DW_AT_name{{.*}}"f"
+; CHECK-NOT: DW_TAG_compile_unit
+;
+; created from
+;   void f() {} // compile with -g
+;   void g() {} // compile with -Rpass=inline
+; and llvm-linking the result.
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+; Function Attrs: nounwind ssp uwtable
+define void @f() #0 !dbg !4 {
+entry:
+  ret void, !dbg !15
+}
+
+; Function Attrs: nounwind ssp uwtable
+define void @g() #0 !dbg !9 {
+entry:
+  ret void, !dbg !16
+}
+
+attributes #0 = { nounwind ssp uwtable }
+
+!llvm.dbg.cu = !{!0, !7}
+!llvm.ident = !{!11, !11}
+!llvm.module.flags = !{!12, !13, !14}
+
+!0 = distin

r265488 - Update testing cases after backend changes.

2016-04-05 Thread Manman Ren via cfe-commits
Author: mren
Date: Tue Apr  5 18:27:51 2016
New Revision: 265488

URL: http://llvm.org/viewvc/llvm-project?rev=265488&view=rev
Log:
Update testing cases after backend changes.

Modified:
cfe/trunk/test/CodeGen/arm-swiftcall.c
cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp

Modified: cfe/trunk/test/CodeGen/arm-swiftcall.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-swiftcall.c?rev=265488&r1=265487&r2=265488&view=diff
==
--- cfe/trunk/test/CodeGen/arm-swiftcall.c (original)
+++ cfe/trunk/test/CodeGen/arm-swiftcall.c Tue Apr  5 18:27:51 2016
@@ -47,7 +47,7 @@ void test_context_error_1() {
 // CHECK:   [[TEMP:%.*]] = alloca swifterror float*, align 4
 // CHECK:   [[T0:%.*]] = load float*, float** [[ERROR]], align 4
 // CHECK:   store float* [[T0]], float** [[TEMP]], align 4
-// CHECK:   call [[SWIFTCC:cc16]] void @context_error_1(i32* swiftself 
[[X]], float** swifterror [[TEMP]])
+// CHECK:   call [[SWIFTCC:swiftcc]] void @context_error_1(i32* swiftself 
[[X]], float** swifterror [[TEMP]])
 // CHECK:   [[T0:%.*]] = load float*, float** [[TEMP]], align 4
 // CHECK:   store float* [[T0]], float** [[ERROR]], align 4
 

Modified: cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp?rev=265488&r1=265487&r2=265488&view=diff
==
--- cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp Tue Apr  5 18:27:51 2016
@@ -77,7 +77,7 @@ TEST(struct_1);
 // CHECK:   ret void
 // CHECK-LABEL: define void @test_struct_1()
 // CHECK:   [[TMP:%.*]] = alloca [[REC]], align 4
-// CHECK:   [[CALL:%.*]] = call [[SWIFTCC:cc16]] [[UAGG]] @return_struct_1()
+// CHECK:   [[CALL:%.*]] = call [[SWIFTCC:swiftcc]] [[UAGG]] @return_struct_1()
 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*
 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* 
[[CAST_TMP]], i32 0, i32 0
 // CHECK:   [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0


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


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

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

In http://reviews.llvm.org/D18708#390166, @rsmith wrote:

>   we'll likely be changing the default C++ language mode soon.)


Privately, PS4 defaults to C++11; we haven't sent that patch upstream because 
it would make tests fail on the PS4 bot. :-)  This is the work Charles Li has 
been doing, to get the tests ready for the dialect change.


Repository:
  rL LLVM

http://reviews.llvm.org/D18708



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


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

2016-04-05 Thread Warren Ristow via cfe-commits
wristow added a subscriber: wristow.
wristow added a comment.

In http://reviews.llvm.org/D18708#390183, @dyung wrote:

> In http://reviews.llvm.org/D18708#390166, @rsmith wrote:
>
> > In http://reviews.llvm.org/D18708#390150, @dyung wrote:
> >
> > > From my understanding, there are 2 issues that block us. The first is 
> > > that we currently do not ship all of the header files for C11. The second 
> > > is that we do not yet fully have C11 library support yet for our platform.
> >
> >
> > How do things go wrong if Clang is used in C11 mode against a C99 library? 
> > Do you have code that conditionally uses C11 library features if they're 
> > available? (And thanks for explaining, by the way; this is useful 
> > information for when we next consider changing the default language mode -- 
> > we'll likely be changing the default C++ language mode soon.)
> >
> > Anyway, it seems reasonable for the PS4 toolchain to control its defaults 
> > here, and the patch itself LGTM.
>
>
> My understanding is that we currently do not ship all of the headers required 
> for C11, so if users tried to use anything from those, they would be unable 
> to do so. I am also under the impression that C11 requires some library 
> support which we do not yet provide.


To confirm and more directly answer your questions, we haven't encountered any 
situations where things have gone wrong when compiling in C11 mode against a 
C99 library.  As far as we're aware, Clang doesn't have any problems in that 
area (e.g., we don't know of any situations where Clang in C11 mode is 
rejecting valid C99 code).  We're just being conservative, in that since we 
don't provide C11 libraries and headers (and therefore we officially tell our 
customers we don't support C11), we don't want to run into situations where 
customers might conditionally enable a C11 library feature.  We may revisit 
that approach sometime in the future depending on customer demand for C11 
features, but at this point, we're defaulting to C99 just to be conservative.


Repository:
  rL LLVM

http://reviews.llvm.org/D18708



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


Re: [PATCH] D18565: Implement an "I'm dtrace, please retain all debug types" option.

2016-04-05 Thread Adrian Prantl via cfe-commits
aprantl abandoned this revision.
aprantl added a comment.

Meanwhile I made an experiment and compiled XNU with 
http://reviews.llvm.org/D18477 and compared the debug info from before and 
after and found no missing types at all. It is plausible that r107027 was added 
to work around the fact that six years ago LLVM was a lot worse at preserving 
debug info for local variables. It is also possible that the call graph of the 
kernel changed in the mean time or a combination of both.


Repository:
  rL LLVM

http://reviews.llvm.org/D18565



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


[PATCH] D18806: [clang-tidy] filter plugins and plugin arguments of the command-line

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

This patch remove the plugin argument from the command-line.

Loading plugins was making clang-tidy to fail when running over chromium 
(linux).

Example of a command-line executed when running clang-tidy over chromium (from 
the compilation database).

```
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF 
obj/third_party/WebKit/Source/core/fetch/webcore_shared.Resource.o.d 
-DV8_DEPRECATION_WARNINGS -DCLD_VERSION=2 -D_FILE_OFFSET_BITS=64 
-DCHROMIUM_BUILD -DCR_CLANG_REVISION=264915-1 -DCOMPONENT_BUILD 
-DUI_COMPOSITOR_IMAGE_TRANSPORT -DUSE_AURA=1 -DUSE_PANGO=1 -DUSE_CAIRO=1 
-DUSE_DEFAULT_RENDER_THEME=1 -DUSE_LIBJPEG_TURBO=1 -DUSE_X11=1 
-DUSE_CLIPBOARD_AURAX11=1 -DENABLE_WEBRTC=1 -DENABLE_MEDIA_ROUTER=1 
-DENABLE_PEPPER_CDMS -DENABLE_NOTIFICATIONS -DENABLE_TOPCHROME_MD=1 -DUSE_UDEV 
-DFIELDTRIAL_TESTING_ENABLED -DENABLE_TASK_MANAGER=1 -DENABLE_EXTENSIONS=1 
-DENABLE_PDF=1 -DENABLE_PLUGINS=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_THEMES=1 
-DENABLE_AUTOFILL_DIALOG=1 -DENABLE_PRINTING=1 -DENABLE_BASIC_PRINTING=1 
-DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 
-DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_APP_LIST=1 -DENABLE_SETTINGS_APP=1 
-DENABLE_SUPERVISED_USERS=1 -DENABLE_MDNS=1 -DENABLE_SERVICE_DISCOVERY=1 
-DV8_USE_EXTERNAL_STARTUP_DATA -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD 
-DSAFE_BROWSING_DB_LOCAL -DBLINK_CORE_IMPLEMENTATION=1 -DBLINK_IMPLEMENTATION=1 
-DINSIDE_BLINK -DGL_GLEXT_PROTOTYPES -DMOJO_USE_SYSTEM_IMPL 
-DCHROME_PNG_WRITE_SUPPORT -DPNG_USER_CONFIG 
-DENABLE_LAYOUT_UNIT_IN_INLINE_BOXES=0 -DENABLE_OILPAN=1 
-DWTF_USE_CONCATENATED_IMPULSE_RESPONSES=1 -DENABLE_INPUT_MULTIPLE_FIELDS_UI=1 
-DWTF_USE_ICCJPEG=1 -DWTF_USE_QCMSLIB=1 -DWTF_USE_WEBAUDIO_FFMPEG=1 
-DWTF_USE_DEFAULT_RENDER_THEME=1 -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 
-DU_NOEXCEPT= -DSKIA_DLL -DGR_GL_IGNORE_ES3_MSAA=0 -DSK_SUPPORT_GPU=1 
-DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS -DLIBXML_STATIC -DLIBXSLT_STATIC 
-DV8_SHARED -DUSING_V8_SHARED -DUSE_LIBPCI=1 -DUSE_OPENSSL=1 -DUSE_GLIB=1 
-DUSE_NSS_CERTS=1 -DUSE_NSS_VERIFIER=1 -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -DDYNAMIC_ANNOTATIONS_ENABLED=1 
-DWTF_USE_DYNAMIC_ANNOTATIONS=1 -D_DEBUG -D_GLIBCXX_DEBUG=1 -Igen 
-I../../third_party/WebKit/Source -Igen/blink -I../../third_party/WebKit 
-I../../third_party/WebKit/Source/core/testing 
-I../../third_party/WebKit/Source/core/testing/v8 -I../.. -I../../skia/config 
-I../../third_party/khronos -I../../gpu -Igen/angle 
-I../../third_party/angle/include -I../../third_party/ffmpeg 
-Igen/third_party/WebKit -I../../third_party/iccjpeg -I../../third_party/libpng 
-I../../third_party/libwebp -I../../third_party/ots/include 
-I../../third_party/zlib -I../../third_party/libjpeg_turbo 
-I../../third_party/icu/source/i18n -I../../third_party/icu/source/common 
-I../../skia/ext -I../../third_party/skia/include/core 
-I../../third_party/skia/include/effects -I../../third_party/skia/include/pdf 
-I../../third_party/skia/include/gpu -I../../third_party/skia/include/lazy 
-I../../third_party/skia/include/pathops -I../../third_party/skia/include/pipe 
-I../../third_party/skia/include/ports -I../../third_party/skia/include/utils 
-I../../third_party/libxml/linux/include -I../../third_party/libxml/src/include 
-I../../third_party/libxslt -I../../third_party/npapi 
-I../../third_party/npapi/bindings -I../../third_party/qcms/src 
-I../../third_party/snappy/linux -I../../third_party/snappy/src 
-I../../v8/include -fstack-protector --param=ssp-buffer-size=4 -Werror -pthread 
-fno-strict-aliasing -Wall -Wextra -Wno-unused-parameter 
-Wno-missing-field-initializers -fvisibility=hidden -pipe -fPIC -Xclang -load 
-Xclang 
/home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so
 -Xclang -add-plugin -Xclang find-bad-constructs -Xclang 
-plugin-arg-find-bad-constructs -Xclang check-templates -Xclang 
-plugin-arg-find-bad-constructs -Xclang follow-macro-expansion 
-fcolor-diagnostics 
-B/home/etienneb/chromium/src/third_party/binutils/Linux_x64/Release/bin 
-Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration 
-Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing 
-Wno-deprecated-register -Wno-inconsistent-missing-override 
-Wno-shift-negative-value -Wglobal-constructors -Wexit-time-destructors 
-fno-strict-aliasing -Xclang -load -Xclang 
/home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libBlinkGCPlugin.so
 -Xclang -add-plugin -Xclang blink-gc-plugin -Xclang 
-plugin-arg-blink-gc-plugin -Xclang enable-oilpan -Xclang 
-plugin-arg-blink-gc-plugin -Xclang warn-raw-ptr -pthread 
-I/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysroot/usr/include/glib-2.0
 
-I/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/glib-2.0/include
 -m64 -march=x86-64 
--sysroot=/home/etienneb/chromium/src/buil

r265467 - Fix a crash on invalid with template handling

2016-04-05 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Tue Apr  5 16:13:54 2016
New Revision: 265467

URL: http://llvm.org/viewvc/llvm-project?rev=265467&view=rev
Log:
Fix a crash on invalid with template handling

This is a fix for https://llvm.org/bugs/show_bug.cgi?id=25561 which was a
crash on invalid.  Change the handling of invalid decls to have a catch-all
case to prevent unexpecting decls from triggering an assertion.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/using-decl-templates.cpp
cfe/trunk/test/SemaTemplate/template-id-expr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=265467&r1=265466&r2=265467&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr  5 16:13:54 
2016
@@ -4322,7 +4322,7 @@ def err_redefinition_different_typedef :
   "%select{typedef|type alias|type alias template}0 "
   "redefinition with different types%diff{ ($ vs $)|}1,2">;
 def err_tag_reference_non_tag : Error<
-  "elaborated type refers to %select{a non-tag type|a typedef|a type alias|a 
template|a type alias template}0">;
+  "elaborated type refers to %select{a non-tag type|a typedef|a type alias|a 
template|a type alias template|a template template argument}0">;
 def err_tag_reference_conflict : Error<
   "implicit declaration introduced by elaborated type conflicts with "
   "%select{a declaration|a typedef|a type alias|a template}0 of the same 
name">;

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=265467&r1=265466&r2=265467&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Apr  5 16:13:54 2016
@@ -7277,15 +7277,21 @@ Sema::ActOnExplicitInstantiation(Scope *
   assert(Kind != TTK_Enum &&
  "Invalid enum tag in class template explicit instantiation!");
 
-  if (isa(TD)) {
-  Diag(KWLoc, diag::err_tag_reference_non_tag) << Kind;
-  Diag(TD->getTemplatedDecl()->getLocation(),
-   diag::note_previous_use);
+  ClassTemplateDecl *ClassTemplate = dyn_cast(TD);
+
+  if (!ClassTemplate) {
+unsigned ErrorKind = 0;
+if (isa(TD)) {
+  ErrorKind = 4;
+} else if (isa(TD)) {
+  ErrorKind = 5;
+}
+
+Diag(TemplateNameLoc, diag::err_tag_reference_non_tag) << ErrorKind;
+Diag(TD->getLocation(), diag::note_previous_use);
 return true;
   }
 
-  ClassTemplateDecl *ClassTemplate = cast(TD);
-
   if (!isAcceptableTagRedeclaration(ClassTemplate->getTemplatedDecl(),
 Kind, /*isDefinition*/false, KWLoc,
 ClassTemplate->getIdentifier())) {

Modified: cfe/trunk/test/SemaCXX/using-decl-templates.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/using-decl-templates.cpp?rev=265467&r1=265466&r2=265467&view=diff
==
--- cfe/trunk/test/SemaCXX/using-decl-templates.cpp (original)
+++ cfe/trunk/test/SemaCXX/using-decl-templates.cpp Tue Apr  5 16:13:54 2016
@@ -90,5 +90,5 @@ namespace aliastemplateinst {
   template struct A { };
   template using APtr = A; // expected-note{{previous use is 
here}}
 
-  template struct APtr; // expected-error{{elaborated type refers to a 
non-tag type}}
+  template struct APtr; // expected-error{{elaborated type refers to a 
type alias template}}
 }

Modified: cfe/trunk/test/SemaTemplate/template-id-expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/template-id-expr.cpp?rev=265467&r1=265466&r2=265467&view=diff
==
--- cfe/trunk/test/SemaTemplate/template-id-expr.cpp (original)
+++ cfe/trunk/test/SemaTemplate/template-id-expr.cpp Tue Apr  5 16:13:54 2016
@@ -96,3 +96,9 @@ void f5() {
 }
 
 template void f5<0>(); // expected-note {{in instantiation of function 
template specialization 'f5<0>' requested here}}
+
+class C {};
+template  class D>  // expected-note{{previous use is 
here}}
+class E {
+  template class D;  // expected-error {{elaborated type refers to a 
template template argument}}
+};


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


Re: r265195 - [modules] Start moving the code for encoding AST records out of ASTWriter into

2016-04-05 Thread Adrian Prantl via cfe-commits
Hi Richard,

it looks like this commit has caused a 6% size regression when building a PCH 
from OS X’s Cocoa.h. When comparing the llvm-bcanalyzer output for r265187 and 
r265195 the most noticeable diff is in the DECLTYPES_BLOCK:

   Block ID #11 (DECLTYPES_BLOCK):
   Num Instances: 1
- Total Size: 50609331b/6326166.38B/1581541W
-Percent of file: 42.1507%
+ Total Size: 55982899b/6997862.38B/1749465W
+Percent of file: 44.6289%
   Num SubBlocks: 0
 Num Abbrevs: 16
 Num Records: 192517
-Percent Abbrevs: 40.5408%
+Percent Abbrevs: 20.3540%

And it looks like the only part of the commit that was not obviously NFC is 
also in ASTWriter::WriteDecl().

Could you please have a look?

Let me know if I can help provide any other diagnostics or testcases. Thanks,
Adrian

> On Apr 1, 2016, at 3:52 PM, Richard Smith via cfe-commits 
>  wrote:
> 
> Author: rsmith
> Date: Fri Apr  1 17:52:03 2016
> New Revision: 265195
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=265195&view=rev
> Log:
> [modules] Start moving the code for encoding AST records out of ASTWriter into
> a separate class. The goal is for this class to have a separate lifetime from
> the AST writer so that it can meaningfully track pending statement nodes and
> context for more compact encoding of various types.
> 
> Modified:
>cfe/trunk/include/clang/Serialization/ASTWriter.h
>cfe/trunk/lib/Serialization/ASTWriter.cpp
>cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
> 
> Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=265195&r1=265194&r2=265195&view=diff
> ==
> --- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTWriter.h Fri Apr  1 17:52:03 2016
> @@ -90,6 +90,7 @@ public:
> 
>   friend class ASTDeclWriter;
>   friend class ASTStmtWriter;
> +  friend class ASTRecordWriter;
> private:
>   /// \brief Map that provides the ID numbers of each type within the
>   /// output stream, plus those deserialized from a chained PCH.
> @@ -523,7 +524,6 @@ private:
>   void WriteReferencedSelectorsPool(Sema &SemaRef);
>   void WriteIdentifierTable(Preprocessor &PP, IdentifierResolver &IdResolver,
> bool IsModule);
> -  void WriteAttributes(ArrayRef Attrs, RecordDataImpl &Record);
>   void WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord);
>   void WriteDeclContextVisibleUpdate(const DeclContext *DC);
>   void WriteFPPragmaOptions(const FPOptions &Opts);
> @@ -555,7 +555,7 @@ private:
> 
>   void WriteDeclAbbrevs();
>   void WriteDecl(ASTContext &Context, Decl *D);
> -  void AddFunctionDefinition(const FunctionDecl *FD, RecordData &Record);
> +  void AddFunctionDefinition(const FunctionDecl *FD, RecordDataImpl &Record);
> 
>   uint64_t WriteASTCore(Sema &SemaRef,
> StringRef isysroot, const std::string &OutputFile,
> @@ -684,6 +684,8 @@ public:
>   /// declaration.
>   serialization::DeclID getDeclID(const Decl *D);
> 
> +  void AddAttributes(ArrayRef Attrs, RecordDataImpl &Record);
> +
>   /// \brief Emit a declaration name.
>   void AddDeclarationName(DeclarationName Name, RecordDataImpl &Record);
>   void AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc,
> @@ -864,6 +866,219 @@ public:
>   const RecordDecl *Record) override;
> };
> 
> +/// \brief An object for streaming information to a record.
> +class ASTRecordWriter {
> +  ASTWriter *Writer;
> +  ASTWriter::RecordDataImpl *Record;
> +
> +public:
> +  /// Construct a ASTRecordWriter that uses the default encoding scheme.
> +  ASTRecordWriter(ASTWriter &Writer, ASTWriter::RecordDataImpl &Record)
> +  : Writer(&Writer), Record(&Record) {}
> +
> +  /// Construct a ASTRecordWriter that uses the same encoding scheme as 
> another
> +  /// ASTRecordWriter.
> +  ASTRecordWriter(ASTRecordWriter &Parent, ASTWriter::RecordDataImpl &Record)
> +  : Writer(Parent.Writer), Record(&Record) {}
> +
> +  /// \brief Extract the underlying record storage.
> +  ASTWriter::RecordDataImpl &getRecordData() const { return *Record; }
> +
> +  /// \brief Minimal vector-like interface.
> +  /// @{
> +  void push_back(uint64_t N) { Record->push_back(N); }
> +  template
> +  void append(InputIterator begin, InputIterator end) {
> +Record->append(begin, end);
> +  }
> +  bool empty() const { return Record->empty(); }
> +  size_t size() const { return Record->size(); }
> +  uint64_t &operator[](size_t N) { return (*Record)[N]; }
> +  /// @}
> +
> +
> +  /// \brief Emit the record to the stream, and return its offset.
> +  // FIXME: Allow record producers to suggest Abbrevs.
> +  uint64_t Emit(unsigned Code, unsigned Abbrev = 0) {
> +uint64_t Offset = Writer->Stream.GetCurrentBitNo();

Re: [PATCH] D18424: [Clang] Fix Clang-tidy modernize-deprecated-headers warnings; other minor fixes

2016-04-05 Thread Aaron Ballman via cfe-commits
On Tue, Apr 5, 2016 at 4:32 PM, Eugene Zelenko  wrote:
> Eugene.Zelenko added inline comments.
>
> 
> Comment at: include/clang-c/Index.h:19
> @@ -18,1 +18,3 @@
>
> +#ifdef __cplusplus
> +#include 
> 
> aaron.ballman wrote:
>> Is this produced by the deprecated headers check? If not, what value does 
>> ctime add over time.h?
> Yes, since file is include from C and C++.

Ugh, so basically the deprecated headers check will always bark about
this inclusion, despite time.h being a simpler alternative. I'm not
too keen on that behavior of the check in this case -- I would prefer
to leave it as time.h if possible, but don't want the clang-tidy check
to always diagnose this case. Thoughts?

~Aaron

>
> 
> Comment at: lib/Lex/ModuleMap.cpp:1286
> @@ -1284,3 +1285,3 @@
>};
> -}
> +} // end anonymous namespaces
>
> 
> aaron.ballman wrote:
>> namespace instead of namespaces
> Will fix in commit.
>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D18424
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18424: [Clang] Fix Clang-tidy modernize-deprecated-headers warnings; other minor fixes

2016-04-05 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added inline comments.


Comment at: include/clang-c/Index.h:19
@@ -18,1 +18,3 @@
 
+#ifdef __cplusplus
+#include 

aaron.ballman wrote:
> Is this produced by the deprecated headers check? If not, what value does 
> ctime add over time.h?
Yes, since file is include from C and C++. 


Comment at: lib/Lex/ModuleMap.cpp:1286
@@ -1284,3 +1285,3 @@
   };
-}
+} // end anonymous namespaces
 

aaron.ballman wrote:
> namespace instead of namespaces
Will fix in commit.


Repository:
  rL LLVM

http://reviews.llvm.org/D18424



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


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

2016-04-05 Thread Peter Collingbourne via cfe-commits
pcc updated this revision to Diff 52732.
pcc added a comment.

- Update command line flag docs


http://reviews.llvm.org/D18635

Files:
  docs/ControlFlowIntegrity.rst
  docs/LTOVisibility.rst
  docs/UsersManual.rst
  docs/index.rst
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  include/clang/Sema/AttributeList.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  runtime/CMakeLists.txt
  runtime/vtables_blacklist.txt
  test/CodeGenCXX/bitset-blacklist.cpp
  test/CodeGenCXX/bitset-inference.cpp
  test/CodeGenCXX/bitsets.cpp
  test/CodeGenCXX/cfi-blacklist.cpp
  test/CodeGenCXX/cfi-cast.cpp
  test/CodeGenCXX/cfi-nvcall.cpp
  test/CodeGenCXX/cfi-stats.cpp
  test/Driver/default-class-scope.c
  test/Driver/fsanitize.c
  test/Driver/whole-program-vtables.c
  test/Frontend/default-class-scope.c
  test/SemaCXX/attr-linkage-unit-scope.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -2527,6 +2527,7 @@
 case ObjCProtocol | ObjCInterface:
   return "ExpectedObjectiveCInterfaceOrProtocol";
 case Field | Var: return "ExpectedFieldOrGlobalVar";
+case GenericRecord | Namespace: return "ExpectedRecordOrNamespace";
   }
 
   PrintFatalError(S.getLoc(),
Index: test/SemaCXX/attr-linkage-unit-scope.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-linkage-unit-scope.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -DATTR=linkage_unit_scope %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -DATTR=global_scope %s
+
+int i [[clang::ATTR]]; // expected-warning {{attribute only applies to struct, union, class or namespace}}
+typedef int t [[clang::ATTR]]; // expected-warning {{attribute only applies to struct, union, class or namespace}}
+[[clang::ATTR]] void f(); // expected-warning {{attribute only applies to struct, union, class or namespace}}
+void f() [[clang::ATTR]]; // expected-error {{attribute cannot be applied to types}}
+
+struct [[clang::ATTR]] s1 {
+  int i [[clang::ATTR]]; // expected-warning {{attribute only applies to struct, union, class or namespace}}
+  [[clang::ATTR]] void f(); // expected-warning {{attribute only applies to struct, union, class or namespace}}
+};
+
+struct [[clang::ATTR(1)]] s2 { // expected-error {{attribute takes no arguments}}
+  virtual void f();
+};
+
+struct
+[[clang::linkage_unit_scope]] // expected-error{{'linkage_unit_scope' and 'global_scope' attributes are not compatible}}
+[[clang::global_scope]] // expected-note{{conflicting attribute is here}}
+s3 {};
+
+struct
+[[clang::global_scope]] // expected-error{{'global_scope' and 'linkage_unit_scope' attributes are not compatible}}
+[[clang::linkage_unit_scope]] // expected-note{{conflicting attribute is here}}
+s4 {};
+
+struct [[clang::ATTR]] s5;
+struct s5 {};
+
+struct s6;
+struct [[clang::ATTR]] s6 {};
+
+struct [[clang::ATTR]] s7;
+struct s7;
+struct s7 {};
+
+struct [[clang::ATTR]] s8;
+struct s8;
+struct [[clang::ATTR]] s8 {};
+
+struct s9;
+struct [[clang::ATTR]] s9;
+
+struct [[clang::linkage_unit_scope]] s10; //expected-error{{attributes are not compatible}}
+struct [[clang::global_scope]] s10 {}; // expected-note{{conflicting attribute is here}}
+
+namespace [[clang::ATTR]] ns1 {}
+
+namespace [[clang::linkage_unit_scope]] ns2 {} // expected-error{{attributes are not compatible}}
+namespace [[clang::global_scope]] ns2 {} // expected-note{{conflicting attribute is here}}
Index: test/Frontend/default-class-scope.c
===
--- /dev/null
+++ test/Frontend/default-class-scope.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fdefault-class-scope=global %s
+// RUN: %clang_cc1 -fdefault-class-scope=attrs %s
+// RUN: %clang_cc1 -fdefault-class-scope=linkage-unit %s
+
+// RUN: not %clang_cc1 -fdefault-class-scope=foo %s 2>&1 | FileCheck %s
+// CHECK: error: invalid value 'foo' in '-fdefault-class-scope=foo'
Index: test/Driver/whole-program-vtables.c
===
--- test/Driver/whole-program-vtables.c
+++ test/Driver/whole-program-vtables.c
@@ -1,11 +1,2 @@
 // RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables -### %s 2>&1 | FileCheck --check-prefix=NO-LTO %s
 // NO-LTO: invalid argument '-fwhole-program-vtables' only allowed with '-flto'
-
-// RUN: %clan

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

2016-04-05 Thread Peter Collingbourne via cfe-commits
pcc added a comment.

I have updated the documentation for the new design; PTAL before I proceed with 
implementation.


http://reviews.llvm.org/D18635



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


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

2016-04-05 Thread Peter Collingbourne via cfe-commits
pcc updated this revision to Diff 52730.
pcc added a comment.

- Rewrite docs


http://reviews.llvm.org/D18635

Files:
  docs/ControlFlowIntegrity.rst
  docs/LTOVisibility.rst
  docs/UsersManual.rst
  docs/index.rst
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  include/clang/Sema/AttributeList.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  runtime/CMakeLists.txt
  runtime/vtables_blacklist.txt
  test/CodeGenCXX/bitset-blacklist.cpp
  test/CodeGenCXX/bitset-inference.cpp
  test/CodeGenCXX/bitsets.cpp
  test/CodeGenCXX/cfi-blacklist.cpp
  test/CodeGenCXX/cfi-cast.cpp
  test/CodeGenCXX/cfi-nvcall.cpp
  test/CodeGenCXX/cfi-stats.cpp
  test/Driver/default-class-scope.c
  test/Driver/fsanitize.c
  test/Driver/whole-program-vtables.c
  test/Frontend/default-class-scope.c
  test/SemaCXX/attr-linkage-unit-scope.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -2527,6 +2527,7 @@
 case ObjCProtocol | ObjCInterface:
   return "ExpectedObjectiveCInterfaceOrProtocol";
 case Field | Var: return "ExpectedFieldOrGlobalVar";
+case GenericRecord | Namespace: return "ExpectedRecordOrNamespace";
   }
 
   PrintFatalError(S.getLoc(),
Index: test/SemaCXX/attr-linkage-unit-scope.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-linkage-unit-scope.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -DATTR=linkage_unit_scope %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -DATTR=global_scope %s
+
+int i [[clang::ATTR]]; // expected-warning {{attribute only applies to struct, union, class or namespace}}
+typedef int t [[clang::ATTR]]; // expected-warning {{attribute only applies to struct, union, class or namespace}}
+[[clang::ATTR]] void f(); // expected-warning {{attribute only applies to struct, union, class or namespace}}
+void f() [[clang::ATTR]]; // expected-error {{attribute cannot be applied to types}}
+
+struct [[clang::ATTR]] s1 {
+  int i [[clang::ATTR]]; // expected-warning {{attribute only applies to struct, union, class or namespace}}
+  [[clang::ATTR]] void f(); // expected-warning {{attribute only applies to struct, union, class or namespace}}
+};
+
+struct [[clang::ATTR(1)]] s2 { // expected-error {{attribute takes no arguments}}
+  virtual void f();
+};
+
+struct
+[[clang::linkage_unit_scope]] // expected-error{{'linkage_unit_scope' and 'global_scope' attributes are not compatible}}
+[[clang::global_scope]] // expected-note{{conflicting attribute is here}}
+s3 {};
+
+struct
+[[clang::global_scope]] // expected-error{{'global_scope' and 'linkage_unit_scope' attributes are not compatible}}
+[[clang::linkage_unit_scope]] // expected-note{{conflicting attribute is here}}
+s4 {};
+
+struct [[clang::ATTR]] s5;
+struct s5 {};
+
+struct s6;
+struct [[clang::ATTR]] s6 {};
+
+struct [[clang::ATTR]] s7;
+struct s7;
+struct s7 {};
+
+struct [[clang::ATTR]] s8;
+struct s8;
+struct [[clang::ATTR]] s8 {};
+
+struct s9;
+struct [[clang::ATTR]] s9;
+
+struct [[clang::linkage_unit_scope]] s10; //expected-error{{attributes are not compatible}}
+struct [[clang::global_scope]] s10 {}; // expected-note{{conflicting attribute is here}}
+
+namespace [[clang::ATTR]] ns1 {}
+
+namespace [[clang::linkage_unit_scope]] ns2 {} // expected-error{{attributes are not compatible}}
+namespace [[clang::global_scope]] ns2 {} // expected-note{{conflicting attribute is here}}
Index: test/Frontend/default-class-scope.c
===
--- /dev/null
+++ test/Frontend/default-class-scope.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fdefault-class-scope=global %s
+// RUN: %clang_cc1 -fdefault-class-scope=attrs %s
+// RUN: %clang_cc1 -fdefault-class-scope=linkage-unit %s
+
+// RUN: not %clang_cc1 -fdefault-class-scope=foo %s 2>&1 | FileCheck %s
+// CHECK: error: invalid value 'foo' in '-fdefault-class-scope=foo'
Index: test/Driver/whole-program-vtables.c
===
--- test/Driver/whole-program-vtables.c
+++ test/Driver/whole-program-vtables.c
@@ -1,11 +1,2 @@
 // RUN: %clang -target x86_64-unknown-linux -fwhole-program-vtables -### %s 2>&1 | FileCheck --check-prefix=NO-LTO %s
 // NO-LTO: invalid argument '-fwhole-program-vtables' only allowed with '-flto'
-
-// RUN: %clang -target x86_64-

[PATCH] D18803: [clang-tidy] fix building clang-tidy documentation.

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

The clang-tidy documentation can't be generated because of broken links.

```
Warning, treated as error:
/home/etienneb/llvm/llvm/tools/clang/tools/extra/docs/clang-tidy/checks/google-readability-function-size.rst::
 WARNING: document isn't included in any toctree
```

http://reviews.llvm.org/D18803

Files:
  docs/clang-tidy/checks/list.rst
  
docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst

Index: 
docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
===
--- 
docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
+++ 
docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
@@ -9,6 +9,7 @@
 visibility of definitions to a single translation unit.
 
 .. code:: c++
+
   namespace {
 static int a = 1; // Warning.
 static const b = 1; // Warning.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to 
readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to 
readability-braces-around-statements) 

google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 

+   google-readability-function-size (redirects to readability-function-size) 

google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo


Index: docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
===
--- docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
+++ docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
@@ -9,6 +9,7 @@
 visibility of definitions to a single translation unit.
 
 .. code:: c++
+
   namespace {
 static int a = 1; // Warning.
 static const b = 1; // Warning.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17043: Check that the result of a library call w/o side effects is used

2016-04-05 Thread Aaron Ballman via cfe-commits
On Tue, Apr 5, 2016 at 3:13 PM, Richard Smith via cfe-commits
 wrote:
> rsmith added a comment.
>
> The version of this attribute that was voted into the C++ standard 
> (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0189r1.pdf) does 
> not support a message, and I expect that is the version that libc++ will want 
> to use.
>
> I think we should at least improve Clang's diagnostic message here, maybe 
> something like:
>
>   warning: value returned by call to function 'blah' should always be used
>   note: 'blah' declared with attribute 'nodiscard' here

I think this sounds perfectly reasonable. The logic is local to
Sema::DiagnoseUnusedExprResult() IIRC, if the OP would like to take a
crack at it. Otherwise, it would be handy to file a PR so we track the
request.

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


Re: [PATCH] D17043: Check that the result of a library call w/o side effects is used

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

The version of this attribute that was voted into the C++ standard 
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0189r1.pdf) does not 
support a message, and I expect that is the version that libc++ will want to 
use.

I think we should at least improve Clang's diagnostic message here, maybe 
something like:

  warning: value returned by call to function 'blah' should always be used
  note: 'blah' declared with attribute 'nodiscard' here

It would also seem sensible to propose extending the standard attribute with an 
optional message.


http://reviews.llvm.org/D17043



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


r265439 - Fix broken tests from no-jump-table commit

2016-04-05 Thread Nirav Dave via cfe-commits
Author: niravd
Date: Tue Apr  5 13:59:37 2016
New Revision: 265439

URL: http://llvm.org/viewvc/llvm-project?rev=265439&view=rev
Log:
Fix broken tests from no-jump-table commit

Summary: Fix failing tests from no-jump-table flag addition

Reviewers: jyknight

Subscribers: llvm-commits

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

Modified:
cfe/trunk/test/CodeGen/cfi-check-fail.c
cfe/trunk/test/CodeGen/cfi-check-fail2.c
cfe/trunk/test/CodeGenCXX/2009-05-04-PureConstNounwind.cpp
cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp
cfe/trunk/test/CodeGenObjCXX/personality-abuse.mm

Modified: cfe/trunk/test/CodeGen/cfi-check-fail.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfi-check-fail.c?rev=265439&r1=265438&r2=265439&view=diff
==
--- cfe/trunk/test/CodeGen/cfi-check-fail.c (original)
+++ cfe/trunk/test/CodeGen/cfi-check-fail.c Tue Apr  5 13:59:37 2016
@@ -7,7 +7,7 @@ void caller(void (*f)()) {
   f();
 }
 
-// CHECK: define weak_odr hidden void @__cfi_check_fail(i8*, i8*) {
+// CHECK: define weak_odr hidden void @__cfi_check_fail(i8*, i8*)
 // CHECK: store i8* %0, i8** %[[ALLOCA0:.*]], align 8
 // CHECK: store i8* %1, i8** %[[ALLOCA1:.*]], align 8
 // CHECK: %[[DATA:.*]] = load i8*, i8** %[[ALLOCA0]], align 8

Modified: cfe/trunk/test/CodeGen/cfi-check-fail2.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfi-check-fail2.c?rev=265439&r1=265438&r2=265439&view=diff
==
--- cfe/trunk/test/CodeGen/cfi-check-fail2.c (original)
+++ cfe/trunk/test/CodeGen/cfi-check-fail2.c Tue Apr  5 13:59:37 2016
@@ -7,7 +7,7 @@ void caller(void (*f)()) {
   f();
 }
 
-// CHECK: define weak_odr hidden void @__cfi_check_fail(i8*, i8*) {
+// CHECK: define weak_odr hidden void @__cfi_check_fail(i8*, i8*)
 // CHECK: store i8* %0, i8** %[[ALLOCA0:.*]], align 8
 // CHECK: store i8* %1, i8** %[[ALLOCA1:.*]], align 8
 // CHECK: %[[DATA:.*]] = load i8*, i8** %[[ALLOCA0]], align 8

Modified: cfe/trunk/test/CodeGenCXX/2009-05-04-PureConstNounwind.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/2009-05-04-PureConstNounwind.cpp?rev=265439&r1=265438&r2=265439&view=diff
==
--- cfe/trunk/test/CodeGenCXX/2009-05-04-PureConstNounwind.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/2009-05-04-PureConstNounwind.cpp Tue Apr  5 
13:59:37 2016
@@ -12,10 +12,11 @@ int f(void) {
 
 // CHECK: declare i32 @_Z1cv() [[NUW_RN:#[0-9]+]]
 // CHECK: declare i32 @_Z1pv() [[NUW_RO:#[0-9]+]]
-// CHECK: declare i32 @_Z1tv() [[TF]]
+// CHECK: declare i32 @_Z1tv() [[TF2:#[0-9]+]]
 
 // CHECK: attributes [[TF]] = { {{.*}} }
 // CHECK: attributes [[NUW_RN]] = { nounwind readnone{{.*}} }
 // CHECK: attributes [[NUW_RO]] = { nounwind readonly{{.*}} }
+// CHECK: attributes [[TF2]] = { {{.*}} }
 // CHECK: attributes [[NUW_RN_CALL]] = { nounwind readnone }
 // CHECK: attributes [[NUW_RO_CALL]] = { nounwind readonly }

Modified: cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp?rev=265439&r1=265438&r2=265439&view=diff
==
--- cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx11-exception-spec.cpp Tue Apr  5 13:59:37 2016
@@ -70,37 +70,37 @@ void h() {
 
 // CHECK: define {{.*}} @_Z1iv
 void i() {
-  // CHECK: declare {{.*}} @_Z1gIiEvv() [[NUW]]
+  // CHECK: declare {{.*}} @_Z1gIiEvv() [[NUW2:#[0-9]+]]
   g();
   // CHECK: declare {{.*}} @_Z1gIA2_iEvv()
   // CHECK-NOT: [[NUW]]
   g();
 
-  // CHECK: declare {{.*}} @_ZN1SIiE1gEv() [[NUW]]
+  // CHECK: declare {{.*}} @_ZN1SIiE1gEv() [[NUW2]]
   S::g();
   // CHECK: declare {{.*}} @_ZN1SIA2_iE1gEv()
   // CHECK-NOT: [[NUW]]
   S::g();
 
-  // CHECK: declare {{.*}} @_Z1gIfEvv() [[NUW]]
+  // CHECK: declare {{.*}} @_Z1gIfEvv() [[NUW2]]
   void (*g1)() = &g;
   // CHECK: declare {{.*}} @_Z1gIdEvv()
   // CHECK-NOT: [[NUW]]
   void (*g2)() = &g;
 
-  // CHECK: declare {{.*}} @_ZN1SIfE1gEv() [[NUW]]
+  // CHECK: declare {{.*}} @_ZN1SIfE1gEv() [[NUW2]]
   void (*g3)() = &S::g;
   // CHECK: declare {{.*}} @_ZN1SIdE1gEv()
   // CHECK-NOT: [[NUW]]
   void (*g4)() = &S::g;
 
-  // CHECK: declare {{.*}} @_Z1gIA4_cEvv() [[NUW]]
+  // CHECK: declare {{.*}} @_Z1gIA4_cEvv() [[NUW2]]
   (void)&g;
   // CHECK: declare {{.*}} @_Z1gIcEvv()
   // CHECK-NOT: [[NUW]]
   (void)&g;
 
-  // CHECK: declare {{.*}} @_ZN1SIA4_cE1gEv() [[NUW]]
+  // CHECK: declare {{.*}} @_ZN1SIA4_cE1gEv() [[NUW2]]
   (void)&S::g;
   // CHECK: declare {{.*}} @_ZN1SIcE1gEv()
   // CHECK-NOT: [[NUW]]
@@ -116,12 +116,15 @@ void j() {
   // CHECK: declare {{.*}} @_ZN6NestedIiE1fILb1EcEEvv(
   // CHECK-NOT: [[NUW]]

r265436 - [CUDA] Show --cuda-gpu-arch option in clang --help.

2016-04-05 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Tue Apr  5 13:26:25 2016
New Revision: 265436

URL: http://llvm.org/viewvc/llvm-project?rev=265436&view=rev
Log:
[CUDA] Show --cuda-gpu-arch option in clang --help.

For some reason it was hidden.

Modified:
cfe/trunk/include/clang/Driver/Options.td

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=265436&r1=265435&r2=265436&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Apr  5 13:26:25 2016
@@ -374,8 +374,8 @@ def c : Flag<["-"], "c">, Flags<[DriverO
   HelpText<"Only run preprocess, compile, and assemble steps">;
 def cuda_device_only : Flag<["--"], "cuda-device-only">,
   HelpText<"Do device-side CUDA compilation only">;
-def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">,
-  Flags<[DriverOption, HelpHidden]>, HelpText<"CUDA GPU architecture">;
+def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[DriverOption]>,
+  HelpText<"CUDA GPU architecture (e.g. sm_35).  May be specified more than 
once.">;
 def cuda_host_only : Flag<["--"], "cuda-host-only">,
   HelpText<"Do host-side CUDA compilation only">;
 def cuda_noopt_device_debug : Flag<["--"], "cuda-noopt-device-debug">,


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


Re: [PATCH] D18671: [CUDA] Add --cuda-flush-denormals-to-zero.

2016-04-05 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL265435: [CUDA] Add -fcuda-flush-denormals-to-zero. (authored 
by jlebar).

Changed prior to commit:
  http://reviews.llvm.org/D18671?vs=52310&id=52718#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18671

Files:
  cfe/trunk/include/clang/Basic/LangOptions.def
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/Driver/ToolChains.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGenCUDA/flush-denormals.cu

Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -382,6 +382,9 @@
   HelpText<"Enable device-side debug info generation. Disables ptxas optimizations.">;
 def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group,
   HelpText<"CUDA installation path">;
+def fcuda_flush_denormals_to_zero : Flag<["-"], "fcuda-flush-denormals-to-zero">,
+  Flags<[CC1Option]>, HelpText<"Flush denormal floating point values to zero in CUDA device mode.">;
+def fno_cuda_flush_denormals_to_zero : Flag<["-"], "fno-cuda-flush-denormals-to-zero">;
 def dA : Flag<["-"], "dA">, Group;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;
Index: cfe/trunk/include/clang/Basic/LangOptions.def
===
--- cfe/trunk/include/clang/Basic/LangOptions.def
+++ cfe/trunk/include/clang/Basic/LangOptions.def
@@ -173,6 +173,7 @@
 LANGOPT(CUDAIsDevice  , 1, 0, "compiling for CUDA device")
 LANGOPT(CUDAAllowVariadicFunctions, 1, 0, "allowing variadic functions in CUDA device code")
 LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "treating unattributed constexpr functions as __host__ __device__")
+LANGOPT(CUDADeviceFlushDenormalsToZero, 1, 0, "flushing denormals to zero")
 
 LANGOPT(AssumeSaneOperatorNew , 1, 1, "implicit __attribute__((malloc)) for C++'s new operators")
 LANGOPT(SizedDeallocation , 1, 0, "enable sized deallocation functions")
Index: cfe/trunk/test/CodeGenCUDA/flush-denormals.cu
===
--- cfe/trunk/test/CodeGenCUDA/flush-denormals.cu
+++ cfe/trunk/test/CodeGenCUDA/flush-denormals.cu
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fcuda-is-device \
+// RUN:   -triple nvptx-nvidia-cuda -emit-llvm -o - %s | FileCheck %s -check-prefix NOFTZ
+// RUN: %clang_cc1 -fcuda-is-device -fcuda-flush-denormals-to-zero \
+// RUN:   -triple nvptx-nvidia-cuda -emit-llvm -o - %s | FileCheck %s -check-prefix FTZ
+
+#include "Inputs/cuda.h"
+
+// Checks that device function calls get emitted with the "ntpvx-f32ftz"
+// attribute set to "true" when we compile CUDA device code with
+// -fcuda-flush-denormals-to-zero.  Further, check that we reflect the presence
+// or absence of -fcuda-flush-denormals-to-zero in a module flag.
+
+// CHECK: define void @foo() #0
+extern "C" __device__ void foo() {}
+
+// FTZ: attributes #0 = {{.*}} "nvptx-f32ftz"="true"
+// NOFTZ-NOT: attributes #0 = {{.*}} "nvptx-f32ftz"
+
+// FTZ:!llvm.module.flags = !{[[MODFLAG:![0-9]+]]}
+// FTZ:[[MODFLAG]] = !{i32 4, !"nvvm-reflect-ftz", i32 1}
+
+// NOFTZ:!llvm.module.flags = !{[[MODFLAG:![0-9]+]]}
+// NOFTZ:[[MODFLAG]] = !{i32 4, !"nvvm-reflect-ftz", i32 0}
Index: cfe/trunk/lib/Driver/ToolChains.cpp
===
--- cfe/trunk/lib/Driver/ToolChains.cpp
+++ cfe/trunk/lib/Driver/ToolChains.cpp
@@ -4208,6 +4208,10 @@
   Linux::addClangTargetOptions(DriverArgs, CC1Args);
   CC1Args.push_back("-fcuda-is-device");
 
+  if (DriverArgs.hasFlag(options::OPT_fcuda_flush_denormals_to_zero,
+ options::OPT_fno_cuda_flush_denormals_to_zero, false))
+CC1Args.push_back("-fcuda-flush-denormals-to-zero");
+
   if (DriverArgs.hasArg(options::OPT_nocudalib))
 return;
 
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -1571,6 +1571,9 @@
   if (Args.hasArg(OPT_fno_cuda_host_device_constexpr))
 Opts.CUDAHostDeviceConstexpr = 0;
 
+  if (Opts.CUDAIsDevice && Args.hasArg(OPT_fcuda_flush_denormals_to_zero))
+Opts.CUDADeviceFlushDenormalsToZero = 1;
+
   if (Opts.ObjC1) {
 if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
   StringRef value = arg->getValue();
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -472,6 +472,14 @@
 getModule().addModuleFlag(llvm::Module::Override, "Cross-DSO CFI", 1);
   }
 
+  if (LangOpts.CUDAIsDevic

r265435 - [CUDA] Add -fcuda-flush-denormals-to-zero.

2016-04-05 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Tue Apr  5 13:26:20 2016
New Revision: 265435

URL: http://llvm.org/viewvc/llvm-project?rev=265435&view=rev
Log:
[CUDA] Add -fcuda-flush-denormals-to-zero.

Summary:
Setting this flag causes all functions are annotated with the
"nvvm-f32ftz" = "true" attribute.

In addition, we annotate the module with "nvvm-reflect-ftz" set
to 0 or 1, depending on whether -cuda-flush-denormals-to-zero is set.
This is read by the NVVMReflect pass.

Reviewers: tra, rnk

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CodeGenCUDA/flush-denormals.cu
Modified:
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=265435&r1=265434&r2=265435&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Tue Apr  5 13:26:20 2016
@@ -173,6 +173,7 @@ LANGOPT(OpenMPIsDevice, 1, 0, "Gener
 LANGOPT(CUDAIsDevice  , 1, 0, "compiling for CUDA device")
 LANGOPT(CUDAAllowVariadicFunctions, 1, 0, "allowing variadic functions in CUDA 
device code")
 LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "treating unattributed constexpr 
functions as __host__ __device__")
+LANGOPT(CUDADeviceFlushDenormalsToZero, 1, 0, "flushing denormals to zero")
 
 LANGOPT(AssumeSaneOperatorNew , 1, 1, "implicit __attribute__((malloc)) for 
C++'s new operators")
 LANGOPT(SizedDeallocation , 1, 0, "enable sized deallocation functions")

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=265435&r1=265434&r2=265435&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Apr  5 13:26:20 2016
@@ -382,6 +382,9 @@ def cuda_noopt_device_debug : Flag<["--"
   HelpText<"Enable device-side debug info generation. Disables ptxas 
optimizations.">;
 def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group,
   HelpText<"CUDA installation path">;
+def fcuda_flush_denormals_to_zero : Flag<["-"], 
"fcuda-flush-denormals-to-zero">,
+  Flags<[CC1Option]>, HelpText<"Flush denormal floating point values to zero 
in CUDA device mode.">;
+def fno_cuda_flush_denormals_to_zero : Flag<["-"], 
"fno-cuda-flush-denormals-to-zero">;
 def dA : Flag<["-"], "dA">, Group;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=265435&r1=265434&r2=265435&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Apr  5 13:26:20 2016
@@ -1768,6 +1768,10 @@ void CodeGenModule::ConstructAttributeLi
 // __syncthreads(), and so can't have certain optimizations applied around
 // them).  LLVM will remove this attribute where it safely can.
 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
+
+// Respect -fcuda-flush-denormals-to-zero.
+if (getLangOpts().CUDADeviceFlushDenormalsToZero)
+  FuncAttrs.addAttribute("nvptx-f32ftz", "true");
   }
 
   ClangToLLVMArgMapping IRFunctionArgs(getContext(), FI);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=265435&r1=265434&r2=265435&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr  5 13:26:20 2016
@@ -472,6 +472,14 @@ void CodeGenModule::Release() {
 getModule().addModuleFlag(llvm::Module::Override, "Cross-DSO CFI", 1);
   }
 
+  if (LangOpts.CUDAIsDevice && getTarget().getTriple().isNVPTX()) {
+// Indicate whether __nvvm_reflect should be configured to flush denormal
+// floating point values to 0.  (This corresponds to its "__CUDA_FTZ"
+// property.)
+getModule().addModuleFlag(llvm::Module::Override, "nvvm-reflect-ftz",
+  LangOpts.CUDADeviceFlushDenormalsToZero ? 1 : 0);
+  }
+
   if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
 llvm::PICLevel::Level PL = llvm::PICLevel::Default;
 switch (PLevel) {

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=265435&r1=2

Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-04-05 Thread don hinton via cfe-commits
hintonda added a comment.

I moved over the weekend, but will try to take a look at this tonight and 
address all your comments.  Thanks again...


http://reviews.llvm.org/D18575



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


r265432 - Fix missing period in no-jump-table flag comment. NFC.

2016-04-05 Thread Nirav Dave via cfe-commits
Author: niravd
Date: Tue Apr  5 13:11:01 2016
New Revision: 265432

URL: http://llvm.org/viewvc/llvm-project?rev=265432&view=rev
Log:
Fix missing period in no-jump-table flag comment. NFC.

Modified:
cfe/trunk/include/clang/Frontend/CodeGenOptions.def

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=265432&r1=265431&r2=265432&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Apr  5 13:11:01 2016
@@ -149,7 +149,7 @@ CODEGENOPT(UnitAtATime   , 1, 1) ///
  ///< selection.
 CODEGENOPT(UnrollLoops   , 1, 0) ///< Control whether loops are unrolled.
 CODEGENOPT(RerollLoops   , 1, 0) ///< Control whether loops are rerolled.
-CODEGENOPT(NoUseJumpTables   , 1, 0) ///< Set when -fno-jump-tables is enabled
+CODEGENOPT(NoUseJumpTables   , 1, 0) ///< Set when -fno-jump-tables is enabled.
 CODEGENOPT(UnsafeFPMath  , 1, 0) ///< Allow unsafe floating point optzns.
 CODEGENOPT(UnwindTables  , 1, 0) ///< Emit unwind tables.
 CODEGENOPT(VectorizeBB   , 1, 0) ///< Run basic block vectorizer.


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


Re: [PATCH] D18671: [CUDA] Add --cuda-flush-denormals-to-zero.

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

Yep, lgtm


http://reviews.llvm.org/D18671



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


Re: [PATCH] D18713: [OpenCL] Generate bitcast when target address space does not change.

2016-04-05 Thread Yaxun Liu via cfe-commits
yaxunl added a comment.

> If I check online I can still see it on line 1414: 
> http://clang.llvm.org/doxygen/CGExprScalar_8cpp_source.html


This is the only place CreateAddrSpaceCast showing up and being fixed by this 
patch.


http://reviews.llvm.org/D18713



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


Re: r265425 - Add -fno-jump-tables and-fjump-tables flags

2016-04-05 Thread Hans Wennborg via cfe-commits
On Tue, Apr 5, 2016 at 10:50 AM, Nirav Dave via cfe-commits
 wrote:
> Author: niravd
> Date: Tue Apr  5 12:50:43 2016
> New Revision: 265425
>
> URL: http://llvm.org/viewvc/llvm-project?rev=265425&view=rev
> Log:
> Add -fno-jump-tables and-fjump-tables flags
>
> Add no-jump-tables flag to disable use of jump tables when lowering
> switch statements
>
> Reviewers: echristo, hans
>
> Subscribers: llvm-commits
>
> Differential Revision: http://reviews.llvm.org/D18407

[...]

> --- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
> +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Apr  5 12:50:43 
> 2016
> @@ -149,6 +149,7 @@ CODEGENOPT(UnitAtATime   , 1, 1) ///
>   ///< selection.
>  CODEGENOPT(UnrollLoops   , 1, 0) ///< Control whether loops are unrolled.
>  CODEGENOPT(RerollLoops   , 1, 0) ///< Control whether loops are rerolled.
> +CODEGENOPT(NoUseJumpTables   , 1, 0) ///< Set when -fno-jump-tables is 
> enabled

In the review, I asked for a period at the end of sentence here.

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


Re: [PATCH] D18671: [CUDA] Add --cuda-flush-denormals-to-zero.

2016-04-05 Thread Justin Lebar via cfe-commits
jlebar added a comment.

Reid, are we good here?


http://reviews.llvm.org/D18671



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


r265425 - Add -fno-jump-tables and-fjump-tables flags

2016-04-05 Thread Nirav Dave via cfe-commits
Author: niravd
Date: Tue Apr  5 12:50:43 2016
New Revision: 265425

URL: http://llvm.org/viewvc/llvm-project?rev=265425&view=rev
Log:
Add -fno-jump-tables and-fjump-tables flags

Add no-jump-tables flag to disable use of jump tables when lowering
switch statements

Reviewers: echristo, hans

Subscribers: llvm-commits

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

Added:
cfe/trunk/test/CodeGen/nousejumptable.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=265425&r1=265424&r2=265425&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Apr  5 12:50:43 2016
@@ -586,6 +586,9 @@ def fno_math_errno : Flag<["-"], "fno-ma
 def fbracket_depth_EQ : Joined<["-"], "fbracket-depth=">, Group;
 def fsignaling_math : Flag<["-"], "fsignaling-math">, Group;
 def fno_signaling_math : Flag<["-"], "fno-signaling-math">, Group;
+def fjump_tables : Flag<["-"], "fjump-tables">, Group;
+def fno_jump_tables : Flag<["-"], "fno-jump-tables">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Do not use jump tables for lowering switches">;
 def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, Group,
Flags<[CC1Option, CoreOption]>, MetaVarName<"">,
HelpText<"Turn on runtime checks for various forms of 
undefined "

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=265425&r1=265424&r2=265425&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Apr  5 12:50:43 2016
@@ -149,6 +149,7 @@ CODEGENOPT(UnitAtATime   , 1, 1) ///
  ///< selection.
 CODEGENOPT(UnrollLoops   , 1, 0) ///< Control whether loops are unrolled.
 CODEGENOPT(RerollLoops   , 1, 0) ///< Control whether loops are rerolled.
+CODEGENOPT(NoUseJumpTables   , 1, 0) ///< Set when -fno-jump-tables is enabled
 CODEGENOPT(UnsafeFPMath  , 1, 0) ///< Allow unsafe floating point optzns.
 CODEGENOPT(UnwindTables  , 1, 0) ///< Emit unwind tables.
 CODEGENOPT(VectorizeBB   , 1, 0) ///< Run basic block vectorizer.

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=265425&r1=265424&r2=265425&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Apr  5 12:50:43 2016
@@ -711,6 +711,10 @@ void CodeGenFunction::StartFunction(Glob
   Fn->addFnAttr(llvm::Attribute::NoInline);
   }
 
+  // Add no-jump-tables value.
+  Fn->addFnAttr("no-jump-tables",
+llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables));
+
   if (getLangOpts().OpenCL) {
 // Add metadata for a kernel function.
 if (const FunctionDecl *FD = dyn_cast_or_null(D))

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=265425&r1=265424&r2=265425&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Apr  5 12:50:43 2016
@@ -3891,6 +3891,10 @@ void Clang::ConstructJob(Compilation &C,
 A->claim();
   }
 
+  if (!Args.hasFlag(options::OPT_fjump_tables, options::OPT_fno_jump_tables,
+true))
+CmdArgs.push_back("-fno-jump-tables");
+
   if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
 CmdArgs.push_back("-mregparm");
 CmdArgs.push_back(A->getValue());

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=265425&r1=265424&r2=265425&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Apr  5 12:50:43 2016
@@ -606,6 +606,8 @@ static bool ParseCodeGenArgs(CodeGenOpti
 
   Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
 
+  Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
+
   Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
   const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ);
   Opts.EmitSummaryIndex = A && A->containsValue("thin");

Added: cfe/trunk/tes

Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

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

In http://reviews.llvm.org/D18783#392486, @bcraig wrote:

> Is this checker able to connect a std::string with a pre-declared string 
> literal (i.e. constant propagation)?  For example...
>
>   const char *bad_chars = "\0\1\2\3";
>   std::string bad_str = bad_chars;
>  
>
>
> I've had real code make that mistake before.


Not yet, but I already started working in it.
There is more false-positive to remove first. It will follow this patch soon.


http://reviews.llvm.org/D18783



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


[PATCH] D18797: [Clang-tidy] Mention readability-static-definition-in-anonymous-namespace in release notes

2016-04-05 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko created this revision.
Eugene.Zelenko added reviewers: alexfh, hokein.
Eugene.Zelenko added a subscriber: cfe-commits.
Eugene.Zelenko set the repository for this revision to rL LLVM.

Repository:
  rL LLVM

http://reviews.llvm.org/D18797

Files:
  docs/ReleaseNotes.rst

Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -153,6 +153,11 @@
 
   Finds unnecessary string initializations.
 
+- New `readability-static-definition-in-anonymous-namespace
+  
`_
 check
+
+  Finds static function and variable definitions in anonymous namespace.
+
 Fixed bugs:
 
 - Crash when running on compile database with relative source files paths.


Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -153,6 +153,11 @@
 
   Finds unnecessary string initializations.
 
+- New `readability-static-definition-in-anonymous-namespace
+  `_ check
+
+  Finds static function and variable definitions in anonymous namespace.
+
 Fixed bugs:
 
 - Crash when running on compile database with relative source files paths.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-05 Thread Ben Craig via cfe-commits
bcraig added a subscriber: bcraig.
bcraig added a comment.

Is this checker able to connect a std::string with a pre-declared string 
literal (i.e. constant propagation)?  For example...

  const char *bad_chars = "\0\1\2\3";
  std::string bad_str = bad_chars;

I've had real code make that mistake before.


http://reviews.llvm.org/D18783



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


Re: [PATCH] D18713: [OpenCL] Generate bitcast when target address space does not change.

2016-04-05 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

In http://reviews.llvm.org/D18713#391406, @yaxunl wrote:

> > Btw, there is another place in lib/CodeGen/CGExprScalar.cpp with 
> > CreateAddrSpaceCast call too. I am wondering if that could have the same 
> > issue... if yes, may be we should fix it already now.
>
>
> I cannot find another CreateAddrSpaceCast in lib/CodeGen/CGExprScalar.cpp 
> with the latest commit 885217218dd21498430d50c5a2f6dd8e329add4b. Do you have 
> the commit hash and line number?
>
> Thanks.


If I check online I can still see it on line 1414: 
http://clang.llvm.org/doxygen/CGExprScalar_8cpp_source.html


http://reviews.llvm.org/D18713



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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-05 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 52710.
etienneb added a comment.

alpha ordering


http://reviews.llvm.org/D18783

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
  test/clang-tidy/misc-string-literal-with-embedded-nul.cpp

Index: test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
@@ -0,0 +1,85 @@
+// RUN: %check_clang_tidy %s misc-string-literal-with-embedded-nul %t
+
+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());
+
+  _Type& operator+=(const C* s);
+  _Type& operator=(const C* s);
+};
+
+typedef basic_string, std::allocator> string;
+typedef basic_string, std::allocator> wstring;
+}
+
+bool operator==(const std::string&, const char*);
+bool operator==(const char*, const std::string&);
+
+
+const char Valid[] = "This is valid \x12.";
+const char Strange[] = "This is strange \0x12 and must be fixed";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: suspicious embedded NUL character [misc-string-literal-with-embedded-nul]
+
+const char textA[] = "\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious embedded NUL character
+const wchar_t textW[] = L"\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious embedded NUL character
+
+const char A[] = "\0";
+const char B[] = "\0x";
+const char C[] = "\0x1";
+const char D[] = "\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+const wchar_t E[] = L"\0";
+const wchar_t F[] = L"\0x";
+const wchar_t G[] = L"\0x1";
+const wchar_t H[] = L"\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious embedded NUL character
+
+const char I[] = "\000\000\000\000";
+const char J[] = "\0\0\0\0\0\0";
+const char K[] = "";
+
+const char L[] = "\0x12" "\0x12" "\0x12" "\0x12";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+void TestA() {
+  std::string str1 = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str2 = "\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str3("\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+  std::string str4{"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+
+  std::string str;
+  str += "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: truncated string literal
+  str = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: truncated string literal
+
+  if (str == "abc\0def") return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: truncated string literal
+  if ("abc\0def" == str) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: truncated string literal
+}
+
+void TestW() {
+  std::wstring str1 = L"abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str2 = L"\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str3(L"\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+  std::wstring str4{L"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+}
Index: docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
@@ -0,0 +1,37 @@
+.. title:: clang-tidy - misc-string-literal-with-embedded-nul
+
+misc-string-literal-with-embedded-nul
+=
+
+Find occurences of string literal with embedded NUL character and validate
+their usage.
+
+
+Invalid escaping
+
+
+Special characters can be escaped within a string literal by using their
+hexadecimal encoding like ``\x42``. A common mistake is to escape them
+like this ``\0x42`` where the ``\0`` stands for the NUL character.
+
+.. code:: c++
+
+  const char* Example[] = "Invalid character: \0x12 should be \x12";
+  const char* Bytes[] = "\x03\0x02\0x01\0x00\0xFF\0xFF\0xFF";
+
+
+Truncated literal
+^
+
+String-like classes can manipulate strings with embedded NUL as they are
+keeping track of the bytes and the length. This is not the case for an
+``char*`` (NUL-terminated) string.
+
+A common mistake is to pass a string-literal (NUL-terminated) to a string
+constructor. The bytes after the first NUL character are truncated.
+
+.. code:: c++
+
+  std::string

Re: [PATCH] D17043: Check that the result of a library call w/o side effects is used

2016-04-05 Thread Sidney San Martín via cfe-commits
sidney added a comment.

In http://reviews.llvm.org/D17043#390188, @alexfh wrote:

> What's the status of this patch? Do you still want to continue working on it 
> or are you fine with the warn_unused_result/nodiscard-based solution?


I'm still interested in working on this, but I was waiting for y'all (maybe 
Richard?).

IMHO, the current diagnostic for `warn_unused_result` is confusing (see the 
Google search and examples above ). 
Adding a parameter sounds great as long as it supports both canned answers 
(e.g. `nodiscard(nosideeffects)`), to avoid having the same message in many 
places, and literal strings (`e.g. nodiscard("recv() returns the length of the 
received message, its return value should always be used.")`).

If that won't happen and you all don't have a better idea, I can keep working 
on this patch.


http://reviews.llvm.org/D17043



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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-05 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added inline comments.


Comment at: docs/ReleaseNotes.rst:161
@@ -156,1 +160,3 @@
+  truncation or invalid character escaping.
+
 Fixed bugs:

I think will be good idea to sort check alphabetically. At least I did so :-)


http://reviews.llvm.org/D18783



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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-05 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 52708.
etienneb added a comment.

add missing reference in release-notes.


http://reviews.llvm.org/D18783

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
  test/clang-tidy/misc-string-literal-with-embedded-nul.cpp

Index: test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
@@ -0,0 +1,85 @@
+// RUN: %check_clang_tidy %s misc-string-literal-with-embedded-nul %t
+
+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());
+
+  _Type& operator+=(const C* s);
+  _Type& operator=(const C* s);
+};
+
+typedef basic_string, std::allocator> string;
+typedef basic_string, std::allocator> wstring;
+}
+
+bool operator==(const std::string&, const char*);
+bool operator==(const char*, const std::string&);
+
+
+const char Valid[] = "This is valid \x12.";
+const char Strange[] = "This is strange \0x12 and must be fixed";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: suspicious embedded NUL character [misc-string-literal-with-embedded-nul]
+
+const char textA[] = "\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious embedded NUL character
+const wchar_t textW[] = L"\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious embedded NUL character
+
+const char A[] = "\0";
+const char B[] = "\0x";
+const char C[] = "\0x1";
+const char D[] = "\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+const wchar_t E[] = L"\0";
+const wchar_t F[] = L"\0x";
+const wchar_t G[] = L"\0x1";
+const wchar_t H[] = L"\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious embedded NUL character
+
+const char I[] = "\000\000\000\000";
+const char J[] = "\0\0\0\0\0\0";
+const char K[] = "";
+
+const char L[] = "\0x12" "\0x12" "\0x12" "\0x12";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+void TestA() {
+  std::string str1 = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str2 = "\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str3("\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+  std::string str4{"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+
+  std::string str;
+  str += "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: truncated string literal
+  str = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: truncated string literal
+
+  if (str == "abc\0def") return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: truncated string literal
+  if ("abc\0def" == str) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: truncated string literal
+}
+
+void TestW() {
+  std::wstring str1 = L"abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str2 = L"\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str3(L"\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+  std::wstring str4{L"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+}
Index: docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
@@ -0,0 +1,37 @@
+.. title:: clang-tidy - misc-string-literal-with-embedded-nul
+
+misc-string-literal-with-embedded-nul
+=
+
+Find occurences of string literal with embedded NUL character and validate
+their usage.
+
+
+Invalid escaping
+
+
+Special characters can be escaped within a string literal by using their
+hexadecimal encoding like ``\x42``. A common mistake is to escape them
+like this ``\0x42`` where the ``\0`` stands for the NUL character.
+
+.. code:: c++
+
+  const char* Example[] = "Invalid character: \0x12 should be \x12";
+  const char* Bytes[] = "\x03\0x02\0x01\0x00\0xFF\0xFF\0xFF";
+
+
+Truncated literal
+^
+
+String-like classes can manipulate strings with embedded NUL as they are
+keeping track of the bytes and the length. This is not the case for an
+``char*`` (NUL-terminated) string.
+
+A common mistake is to pass a string-literal (NUL-terminated) to a string
+constructor. The bytes after the first NUL character are truncated.
+
+.. co

Re: [PATCH] D18793: fix for 19986, extra spacing around c++14 lambda capture with initializer

2016-04-05 Thread Daniel Jasper via cfe-commits
djasper added a comment.

Please add tests in unittests/Format/FormatTest.cpp.



Comment at: lib/Format/UnwrappedLineParser.cpp:1086
@@ +1085,3 @@
+  int parens = 0;
+  while (!eof()) {
+if (FormatTok->isOneOf(tok::l_paren, tok::l_square)) {

We need to be much more error resilient here as people will frequently call 
clang-format with mismatched parentheses and such. I am actually quite 
skeptical about having yet another instance of parentheses counting. Maybe just 
call parseParens() instead?


Comment at: lib/Format/UnwrappedLineParser.cpp:1094
@@ +1093,3 @@
+} else if (!FormatTok->isOneOf(tok::identifier, tok::coloncolon)) {
+  return false;
+}

This seems wrong. Even in the case of the bug you say you are fixing, the "23" 
is neither an identifier nor a coloncolon..


http://reviews.llvm.org/D18793



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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-05 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a subscriber: Eugene.Zelenko.
Eugene.Zelenko added a comment.

Please mention this check in docs/ReleaseNotes.rst.


http://reviews.llvm.org/D18783



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


Re: [PATCH] D18765: [clang-tidy] Don't complain about const pass_object_size params in declarations

2016-04-05 Thread George Burgess IV via cfe-commits
george.burgess.iv abandoned this revision.
george.burgess.iv added a comment.

> There's a principal difference between top-level const on parameters in 
> definitions and in declarations: in definitions const has an effect, as it 
> makes the variable constant, but in declarations it has absolutely no effect 
> [...] it's considered useless and misleading when used on declarations


Yup! I didn't realize it was considered misleading, though -- good to know.

> Long story short, I don't see any value in this change.


Yeah, the more I think about it, the more I agree that this doesn't clearly add 
value, so I'll drop it. Thanks for the review :)


http://reviews.llvm.org/D18765



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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-05 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 52707.
etienneb marked an inline comment as done.
etienneb added a comment.

fix comments.


http://reviews.llvm.org/D18783

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
  test/clang-tidy/misc-string-literal-with-embedded-nul.cpp

Index: test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
@@ -0,0 +1,86 @@
+// RUN: %check_clang_tidy %s misc-string-literal-with-embedded-nul %t
+
+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());
+
+  _Type& operator+=(const C* s);
+  _Type& operator=(const C* s);
+};
+
+typedef basic_string, std::allocator> string;
+typedef basic_string, std::allocator> wstring;
+}
+
+bool operator==(const std::string&, const char*);
+bool operator==(const char*, const std::string&);
+
+
+const char Valid[] = "This is valid \x12.";
+const char Strange[] = "This is strange \0x12 and must be fixed";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: suspicious embedded NUL character [misc-string-literal-with-embedded-nul]
+
+const char textA[] = "\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious embedded NUL character
+const wchar_t textW[] = L"\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious embedded NUL character
+
+const char A[] = "\0";
+const char B[] = "\0x";
+const char C[] = "\0x1";
+const char D[] = "\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+const wchar_t E[] = L"\0";
+const wchar_t F[] = L"\0x";
+const wchar_t G[] = L"\0x1";
+const wchar_t H[] = L"\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious embedded NUL character
+
+const char I[] = "\000\000\000\000";
+const char J[] = "\0\0\0\0\0\0";
+const char K[] = "";
+
+const char L[] = "\0x12" "\0x12" "\0x12" "\0x12";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+void TestA() {
+  std::string str1 = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str2 = "\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str3("\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+  std::string str4{"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+
+  std::string str;
+  str += "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: truncated string literal
+  str = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: truncated string literal
+
+  if (str == "abc\0def") return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: truncated string literal
+  if ("abc\0def" == str) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: truncated string literal
+}
+
+void TestW() {
+  std::wstring str1 = L"abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str2 = L"\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str3(L"\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+  std::wstring str4{L"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+}
+
Index: docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
@@ -0,0 +1,39 @@
+.. title:: clang-tidy - misc-string-literal-with-embedded-nul
+
+misc-string-literal-with-embedded-nul
+=
+
+Find occurences of string literal with embedded NUL character and validate
+their usage.
+
+
+Invalid escaping
+
+
+Special characters can be escaped within a string literal by using their
+hexadecimal encoding like ``\x42``. A common mistake is to escape them
+like this ``\0x42`` where the ``\0`` stands for the NUL character.
+
+.. code:: c++
+
+  const char* Example[] = "Invalid character: \0x12 should be \x12";
+  const char* Bytes[] = "\x03\0x02\0x01\0x00\0xFF\0xFF\0xFF";
+
+
+Truncated literal
+^
+
+String-like classes can manipulate strings with embedded NUL as they are
+keeping track of the bytes and the length. This is not the case for an
+``char*`` (NUL-terminated) string.
+
+A common mistake is to pass a string-literal (NUL-terminated) to a string
+constructor. The bytes after the first NUL character are truncated.
+
+.. code:: 

Re: [PATCH] D18575: [clang-tidy] New checker to replace deprecated throw() specifications

2016-04-05 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.


Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:16
@@ +15,3 @@
+
+// FIXME: Should this be moved to ASTMatchers.h?
+namespace ast_matchers {

alexfh wrote:
> Yes, it might make sense to move it to ASTMatchers.h.
Yes, please (along with tests and documentation, etc).


Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:94
@@ +93,3 @@
+
+  const FunctionDecl *FuncDecl =
+  Result.Nodes.getNodeAs("functionDecl");

Can use `auto` here to not repeat the type name from the initializer.


Comment at: clang-tidy/modernize/UseNoexceptCheck.cpp:148
@@ +147,3 @@
+CurrentLoc = Tok.getLocation();
+  }
+

I think all of this custom logic can be replaced by looking at the 
FunctionType. If it has a dynamic exception specification 
(`hasDynamicExceptionSpec()`) then whether it is throwing or not throwing 
(`isNothrow()`) determines whether you replace with `noexcept(false)`  or 
`noexcept`. But then you don't have to go back to the source to see what is 
written.


http://reviews.llvm.org/D18575



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


Re: [clang-tools-extra] r264563 - clang-tidy: Fix broken buildbot

2016-04-05 Thread Richard via cfe-commits

In article ,
Alexander Kornienko  writes:
> 
> On Mon, Mar 28, 2016 at 6:15 AM, Richard Thomson via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> 
> > Author: legalize
> > Date: Sun Mar 27 23:15:41 2016
> > New Revision: 264563
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=264563&view=rev
> > Log:
> > clang-tidy: Fix broken buildbot
> >
> > VS 2013 does not support char16_t or char32_t

> I'm not sure I understand what this test has to do with VS2013.

I incorrectly stated it as VS 2013 and not the Windows buildbot
configuration as being the root cause.

If you look at the failed build message, it is clearly saying "error:
unknown type name 'char16_t'" and "error: unknown type name 'char32_t'".


I could either do something that would fix the build quickly (which is
what I chose to do), or I could reverse out the entire changeset.

I chose the former as the best means of getting the builds green
again.  The existing raw string literal check doesn't yet process
character literals other than ASCII literals, so there is nothing lost
in commenting out these lines of the test file.

> Clang-tidy
> should be able to parse this code, and if it doesn't (e.g. due to
> -fms-compatibility being turned on by default on windows), we should put
> unsupported constructs under an appropriate #ifdef, not comment them out
> completely.

That is why I added a TODO comment instead of just removing the lines.

Feel free to patch it such that it does some kind of CMake based
feature check for char16_t and char32_t and then configures a header
file with HAS_xxx style check macros, include that generated header
file in the test sources and then use the preprocessor to conditionally
include the lines in the test file based on compiler support.

To me, that is a significant chunk of work, which is why I opted
instead for commenting out these (not too important yet) lines of test
code and add a TODO comment.  That TODO can be addressed when the
check is expanded to handle non-ASCII string literals.
-- 
"The Direct3D Graphics Pipeline" free book 
 The Computer Graphics Museum 
 The Terminals Wiki 
  Legalize Adulthood! (my blog) 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18584: Complete support for C++ Core Guidelines Type.6: Always initialize a member variable.

2016-04-05 Thread Aaron Ballman via cfe-commits
aaron.ballman added a subscriber: aaron.ballman.
aaron.ballman requested changes to this revision.
aaron.ballman added a reviewer: aaron.ballman.
This revision now requires changes to proceed.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:25
@@ -24,3 +24,3 @@
 
-namespace {
 

Please do not remove the unnamed namespace; it is preferable to using static 
functions.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:30
@@ +29,3 @@
+  const auto *ClassDecl = dyn_cast(&RecordDecl);
+  // Non-C++ records are always trivially constructible
+  if (!ClassDecl)

Missing a period at the end of the sentence.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:33
@@ +32,3 @@
+return true;
+  // A class is trivially constructible if it has a default constructor.
+  if (ClassDecl->hasUserProvidedDefaultConstructor())

This comment doesn't match the behavior of the code below.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:104
@@ -35,3 +103,3 @@
 QualType Type = F->getType();
-if (Type->isPointerType() || Type->isBuiltinType())
+if (!F->hasInClassInitializer() and isTriviallyConstructible(Context, 
Type))
   FieldsToInit.insert(F);

Please use `&&` instead of `and`.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:152
@@ +151,3 @@
+
+AST_MATCHER(CXXConstructorDecl, isUserProvided) {
+  return Node.isUserProvided();

This should probably be made more generally available as an AST matcher.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:156
@@ +155,3 @@
+
+AST_MATCHER(RecordDecl, isTriviallyDefaultConstructible) {
+  return isTriviallyConstructible(Finder->getASTContext(), Node);

I think this matcher logic should go into utils\TypeTraits.cpp as it seems more 
generally useful than just this check.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:160
@@ +159,3 @@
+
+AST_MATCHER(CXXConstructorDecl, isDelegatingConstructor) {
+  return Node.isDelegatingConstructor();

As should this.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:187
@@ -87,5 +186,3 @@
  const CXXConstructorDecl &Constructor) const {
-if (InitializerBefore != nullptr) {
-  return Lexer::getLocForEndOfToken(InitializerBefore->getRParenLoc(), 0,
-Context.getSourceManager(),
-Context.getLangOpts());
+assert(Where != nullptr or Placement == InitializerPlacement::New);
+SourceLocation Location;

Please use `||` instead of `or`. Also, asserts should usually have `&& "Some 
explanatory text"` for when the assert is triggered.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:243
@@ +242,3 @@
+// initializer.
+static const NamedDecl *getInitializerDecl(const CXXCtorInitializer *Init) {
+  if (Init->isMemberInitializer())

Since this function is only used once, I think it should be lowered into its 
use as a ternary conditional.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:256
@@ +255,3 @@
+  SmallVector Insertions;
+  Insertions.push_back({InitializerPlacement::New, nullptr, {}});
+

Please do not use an initializer list like this, I believe it won't work in 
MSVC 2013. (Here and elsewhere as well.)


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:258
@@ -142,1 +257,3 @@
+
+  auto Decl = std::begin(OrderedDecls);
   for (const CXXCtorInitializer *Init : Inits) {

Please only use `auto` when the type name is spelled out as part of the 
initializer, or it is used as a for-range initializer.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:296
@@ +295,3 @@
+  Decls.clear();
+  for (const CXXBaseSpecifier &Base : ClassDecl->bases())
+Decls.emplace_back(getRecordDecl(Base.getType()));

Can use `const auto &` here instead.


Comment at: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:323
@@ -171,5 +322,3 @@
 void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(cxxConstructorDecl(isDefinition(), isUserProvided(),
-unless(isInstantiated()))
- .bind("ctor"),
- this);
+  auto IsUserProvidedNonDelegatingConstructor =
+  allOf(isUserProvided(),

Since this is a C++ core guideline, I think the matchers should only be 
registered when compiling for C++. It may make sense to use a similar check in 
C mode, but we can cross that bridge when we 

Re: [PATCH] D17821: [OpenCL] Complete image types support

2016-04-05 Thread Alexey Bader via cfe-commits
bader added inline comments.


Comment at: include/clang/AST/ASTContext.h:903
@@ +902,3 @@
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
+  CanQualType SingletonId;
+#include "clang/AST/OpenCLImageTypes.def"

mgrang wrote:
> remove extra spacing in front of the \
Sorry for delay...
I used clang-format tool to format that code. I expect it to be in agreement 
with LLVM coding style guide.
Did I miss something or it's clang-format bug?


http://reviews.llvm.org/D17821



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


Re: [PATCH] D18766: [clang-tidy] Add check misc-multiple-statement-macro

2016-04-05 Thread Samuel Benzaquen via cfe-commits
sbenza added inline comments.


Comment at: docs/clang-tidy/checks/misc-multiple-statement-macro.rst:15
@@ +14,3 @@
+  if (do_increment)
+INCREMENT_TWO(a, b);
+

hokein wrote:
> Would be better to add a comment to explain the sample.
The sentence just before the example explains what the problem is.


http://reviews.llvm.org/D18766



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


Re: [PATCH] D18766: [clang-tidy] Add check misc-multiple-statement-macro

2016-04-05 Thread Samuel Benzaquen via cfe-commits
sbenza updated this revision to Diff 52702.
sbenza marked 2 inline comments as done and an inline comment as not done.
sbenza added a comment.

Minor fixes


http://reviews.llvm.org/D18766

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/MultipleStatementMacroCheck.cpp
  clang-tidy/misc/MultipleStatementMacroCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-multiple-statement-macro.rst
  test/clang-tidy/misc-multiple-statement-macro.cpp

Index: test/clang-tidy/misc-multiple-statement-macro.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-multiple-statement-macro.cpp
@@ -0,0 +1,85 @@
+// RUN: %check_clang_tidy %s misc-multiple-statement-macro %t
+
+void F();
+
+#define BAD_MACRO(x) \
+  F();   \
+  F()
+
+#define GOOD_MACRO(x) \
+  do {\
+F();  \
+F();  \
+  } while (0)
+
+#define GOOD_MACRO2(x) F()
+
+#define GOOD_MACRO3(x) F();
+
+#define MACRO_ARG_MACRO(X) \
+  if (54)  \
+  X(2)
+
+#define ALL_IN_MACRO(X) \
+  if (43)   \
+F();\
+  F()
+
+#define GOOD_NESTED(x)   \
+  if (x)\
+GOOD_MACRO3(x); \
+  F();
+
+#define IF(x) if(x)
+
+void positives() {
+  if (1)
+BAD_MACRO(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple statement macro spans unbraced conditional and the following statement [misc-multiple-statement-macro]
+  if (1) {
+  } else
+BAD_MACRO(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple statement macro spans
+  while (1)
+BAD_MACRO(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple statement macro spans
+  for (;;)
+BAD_MACRO(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple statement macro spans
+
+  MACRO_ARG_MACRO(BAD_MACRO);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: multiple statement macro spans
+  MACRO_ARG_MACRO(F(); int);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: multiple statement macro spans
+  IF(1) BAD_MACRO(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: multiple statement macro spans
+}
+
+void negatives() {
+  if (1) {
+BAD_MACRO(1);
+  } else {
+BAD_MACRO(1);
+  }
+  while (1) {
+BAD_MACRO(1);
+  }
+  for (;;) {
+BAD_MACRO(1);
+  }
+
+  if (1)
+GOOD_MACRO(1);
+  if (1) {
+GOOD_MACRO(1);
+  }
+  if (1)
+GOOD_MACRO2(1);
+  if (1)
+GOOD_MACRO3(1);
+
+  MACRO_ARG_MACRO(GOOD_MACRO);
+  ALL_IN_MACRO(1);
+
+  IF(1) GOOD_MACRO(1);
+}
Index: docs/clang-tidy/checks/misc-multiple-statement-macro.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-multiple-statement-macro.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - misc-multiple-statement-macro
+
+misc-multiple-statement-macro
+=
+
+Detect multiple statement macros that are used in unbraced conditionals.
+Only the first statement of the macro will be inside the conditional and the other ones will be executed unconditionally.
+
+Example:
+
+.. code:: c++
+
+  #define INCREMENT_TWO(x, y) (x)++; (y)++
+  if (do_increment)
+INCREMENT_TWO(a, b);
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -60,6 +60,7 @@
misc-macro-repeated-side-effects
misc-misplaced-widening-cast
misc-move-constructor-init
+   misc-multiple-statement-macro
misc-new-delete-overloads
misc-noexcept-move-constructor
misc-non-copyable-objects
Index: clang-tidy/misc/MultipleStatementMacroCheck.h
===
--- /dev/null
+++ clang-tidy/misc/MultipleStatementMacroCheck.h
@@ -0,0 +1,37 @@
+//===--- MultipleStatementMacroCheck.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_MULTIPLE_STATEMENT_MACRO_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MULTIPLE_STATEMENT_MACRO_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// Detect multiple statement macros that are used in unbraced conditionals.
+/// Only the first statement of the macro will be inside the conditional and the
+/// other ones will be executed unconditionally.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/misc-multiple-statement-macro.html
+class MultipleStatementMacroCheck : public ClangTidyCheck {
+public:
+  MultipleStatementMacroCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_match

Re: [PATCH] Windows support for ObjC DLLIMPORT

2016-04-05 Thread Aaron Ballman via cfe-commits
On Mon, Apr 4, 2016 at 3:34 PM, Wes Witt via cfe-commits
 wrote:
> Please accept this diff as a change to support dllimport of objective c
> interfaces on windows. I’ve included a new test and changes to an existing
> test as well. All clang tests pass on Linux & Windows. This change is
> required for Microsoft’s use of the clang compiler in support of objective c
> on windows.

Thank you for working on this! Some comments below:

> diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
> index c7a797c..dc22b27 100644
> --- a/include/clang/Basic/Attr.td
> +++ b/include/clang/Basic/Attr.td
> @@ -2023,7 +2023,8 @@ def DLLExport : InheritableAttr, 
> TargetSpecificAttr {
>
>  def DLLImport : InheritableAttr, TargetSpecificAttr {
>let Spellings = [Declspec<"dllimport">, GCC<"dllimport">];
> -  let Subjects = SubjectList<[Function, Var, CXXRecord]>;
> +  let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface], 
> WarnDiag,
> + "ExpectedFunctionVariableOrClass">;

The diagnostic for this won't indicate that it's also okay to play on
an Objective-C interface decl; is that intentional?

>let Documentation = [Undocumented];

It would be nice to add some documentation to this, instead of leaving
it totally undocumented. The docs can basically point to MSDN on
__declspec(dllimport), but this would be a good place to let users
know about the Objective-C behavior as well.

>  }
>
> diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
> index ea164aa..9d2b2f9 100644
> --- a/lib/CodeGen/CGBlocks.cpp
> +++ b/lib/CodeGen/CGBlocks.cpp
> @@ -2334,5 +2334,9 @@ llvm::Constant 
> *CodeGenModule::getNSConcreteStackBlock() {
> Int8PtrTy->getPointerTo(),
> nullptr);
>configureBlocksRuntimeObject(*this, NSConcreteStackBlock);
> +  if (getContext().getLangOpts().MSVCCompat) {
> +auto *GV = 
> cast(NSConcreteStackBlock->stripPointerCasts());
> +GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
> +  }
>return NSConcreteStackBlock;
>  }
> diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
> index bbe1b8b..dcb3a7d 100644
> --- a/lib/CodeGen/CGObjCGNU.cpp
> +++ b/lib/CodeGen/CGObjCGNU.cpp
> @@ -472,7 +472,7 @@ protected:
>
>/// Emits a pointer to the named class
>virtual llvm::Value *GetClassNamed(CodeGenFunction &CGF,
> - const std::string &Name, bool isWeak);
> + StringRef Name, bool isWeak, bool 
> isDLLImport);
>
>/// Looks up the method for sending a message to the specified object.  
> This
>/// mechanism differs between the GCC and GNU runtimes, so this method 
> must be
> @@ -866,21 +866,24 @@ protected:
>  }
>
>llvm::Value *GetClassNamed(CodeGenFunction &CGF,
> - const std::string &Name, bool isWeak) override {
> + StringRef Name, bool isWeak, bool isDLLImport) 
> override {
>  if (isWeak)
> -  return CGObjCGNU::GetClassNamed(CGF, Name, isWeak);
> +  return CGObjCGNU::GetClassNamed(CGF, Name, isWeak, isDLLImport);
>
>  EmitClassRef(Name);
>
> -std::string SymbolName = "_OBJC_CLASS_" + Name;
> +std::string SymbolName = "_OBJC_CLASS_" + Name.str();
>
>  llvm::GlobalVariable *ClassSymbol = 
> TheModule.getGlobalVariable(SymbolName);
>
> -if (!ClassSymbol)
> +if (!ClassSymbol) {
>ClassSymbol = new llvm::GlobalVariable(TheModule, LongTy, false,
>   
> llvm::GlobalValue::ExternalLinkage,
>   nullptr, SymbolName);
> -
> +  if (isDLLImport)
> +
> ClassSymbol->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
> +}
> +
>  return ClassSymbol;
>}
>
> @@ -1054,8 +1057,8 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned 
> runtimeABIVersion,
>  }
>
>  llvm::Value *CGObjCGNU::GetClassNamed(CodeGenFunction &CGF,
> -  const std::string &Name,
> -  bool isWeak) {
> +  StringRef Name,
> +  bool isWeak, bool isDLLImport) {
>llvm::Constant *ClassName = MakeConstantString(Name);
>// With the incompatible ABI, this will need to be replaced with a direct
>// reference to the class symbol.  For the compatible nonfragile ABI we are
> @@ -1077,11 +1080,12 @@ llvm::Value *CGObjCGNU::GetClassNamed(CodeGenFunction 
> &CGF,
>  // techniques can modify the name -> class mapping.
>  llvm::Value *CGObjCGNU::GetClass(CodeGenFunction &CGF,
>   const ObjCInterfaceDecl *OID) {
> -  return GetClassNamed(CGF, OID->getNameAsString(), OID->isWeakImported());
> +  return GetClassNamed(CGF, OID->getNameAsString(), OID->isWeakImported(),
> +  

Re: [PATCH] D18649: [clang-tidy] cppcoreguidelines-interfaces-global-init

2016-04-05 Thread Clement Courbet via cfe-commits
courbet updated this revision to Diff 52696.
courbet marked an inline comment as done.
courbet added a comment.

cosmetics


http://reviews.llvm.org/D18649

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.cpp
  clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-interfaces-global-init.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp

Index: test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp
@@ -0,0 +1,77 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-interfaces-global-init %t
+
+constexpr int makesInt() { return 3; }
+constexpr int takesInt(int i) { return i + 1; }
+constexpr int takesIntPtr(int *i) { return *i; }
+
+extern int ExternGlobal;
+static int GlobalScopeBadInit1 = ExternGlobal;
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+static int GlobalScopeBadInit2 = takesInt(ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+static int GlobalScopeBadInit3 = takesIntPtr(&ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+static int GlobalScopeBadInit4 = 3 * (ExternGlobal + 2);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+
+namespace ns {
+static int NamespaceScope = makesInt();
+static int NamespaceScopeBadInit = takesInt(ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+
+struct A {
+  static int ClassScope;
+  static int ClassScopeBadInit;
+};
+
+int A::ClassScopeBadInit = takesInt(ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:8: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+
+static int FromClassBadInit = takesInt(A::ClassScope);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ClassScope'
+} // namespace ns
+
+// "const int B::I;" is fine, it just ODR-defines B::I. See [9.4.3] Static
+// members [class.static]. However the ODR-definitions are not in the right
+// order (C::I after C::J, see [3.6.2.3]).
+class B1 {
+  static const int I = 0;
+  static const int J = I;
+};
+const int B1::J;
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'I'
+const int B1::I;
+
+void f() {
+  // This is fine, it's executed after dynamic initialization occurs.
+  static int G = takesInt(ExternGlobal);
+}
+
+// Defined global variables are fine:
+static int GlobalScope = makesInt();
+static int GlobalScopeBadInit = takesInt(GlobalScope);
+static int GlobalScope2 = takesInt(ns::NamespaceScope);
+// Enums are fine.
+enum Enum { kEnumValue = 1 };
+static int GlobalScopeFromEnum = takesInt(kEnumValue);
+
+// Leave constexprs alone.
+extern constexpr int GlobalScopeConstexpr = makesInt();
+static constexpr int GlobalScopeConstexprOk =
+takesInt(GlobalScopeConstexpr);
+
+// This is a pretty common instance: People are usually not using constexpr, but
+// this is what they should write:
+static constexpr const char kValue[] = "value";
+constexpr int Fingerprint(const char *value) { return 0; }
+static int kFingerprint = Fingerprint(kValue);
+
+// This is fine because the ODR-definitions are in the right order (C::J after
+// C::I).
+class B2 {
+  static const int I = 0;
+  static const int J = I;
+};
+const int B2::I;
+const int B2::J;
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -16,6 +16,7 @@
cert-fio38-c (redirects to misc-non-copyable-objects) 
cert-flp30-c
cert-oop11-cpp (redirects to misc-move-constructor-init) 
+   cppcoreguidelines-interfaces-global-init
cppcoreguidelines-pro-bounds-array-to-pointer-decay
cppcoreguidelines-pro-bounds-constant-array-index
cppcoreguidelines-pro-bounds-pointer-arithmetic
Index: docs/clang-tidy/checks/cppcoreguidelines-interfaces-global-init.rst
===
--- /dev/null
+++ do

Re: [PATCH] D18793: fix for 19986, extra spacing around c++14 lambda capture with initializer

2016-04-05 Thread Meador Inge via cfe-commits
meadori added a subscriber: meadori.
meadori added a comment.

This needs a test case.


http://reviews.llvm.org/D18793



___
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-05 Thread Aaron Ballman via cfe-commits
aaron.ballman added a subscriber: aaron.ballman.


Comment at: clang-tidy/misc/FoldInitTypeCheck.cpp:21
@@ +20,3 @@
+/// Returns the value_type for an InputIterator type.
+static QualType getInputIteratorValueType(const Type &IteratorType,
+  const ASTContext &context) {

alexfh wrote:
> I suspect, a significant part of this could be done in the matcher. I might 
> be wrong, but it seems worth trying. The resulting code is usually much 
> shorter and cleaner.
I kind of wonder if it would be generally useful as a matcher helper utility -- 
expose everything from `std::iterator_traits` with a nice AST matcher 
interface. Something that can be used like: 
`iteratorTrait(hasValueType(), hasPointerType())` Or is that 
overkill?


Comment at: clang-tidy/misc/FoldInitTypeCheck.cpp:23
@@ +22,3 @@
+  const ASTContext &context) {
+  if (IteratorType.isPointerType()) {
+return IteratorType.getPointeeType().getCanonicalType();

Should elide the braces (here and elsewhere).


Comment at: clang-tidy/misc/FoldInitTypeCheck.cpp:43
@@ +42,3 @@
+
+/// Returns true if ValueType is allwed to fold into InitType.
+static bool isValidBuiltinFold(const BuiltinType &ValueType,

s/allwed/allowed.

Also, may want to clarify what "fold" means in this context (can be confusing 
because there are fold expressions as well as constant folding).


Comment at: clang-tidy/misc/FoldInitTypeCheck.cpp:79
@@ +78,3 @@
+  callExpr(callee(functionDecl(
+   hasName("std::accumulate"),
+   hasParameter(0, parmVarDecl().bind("iterator")),

Are there plans to apply this to other STL algorithms, like `inner_product`, 
`reduce`, etc? If so, it may be good to add a chunk of those up front.

Also, the name we should check should be `::std::accumulate`. May want to 
include a test like:
```
namespace blah {
namespace std {
template 
T accumulate(Iter, Iter, T); // We should not care about this one.
}
}
```


Comment at: clang-tidy/misc/FoldInitTypeCheck.cpp:118
@@ +117,3 @@
+   "loss of precision")
+  << ValueBuiltingType->getName(Policy)
+  << InitBuiltinType->getName(Policy);

You should be able to just pass the type directly into the diagnostic engine 
instead of mucking about with the printing policy directly.


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] D18596: [MSVC] PR27132: Proper mangling for __unaligned qualifier

2016-04-05 Thread David Majnemer via cfe-commits
majnemer added a comment.

In http://reviews.llvm.org/D18596#392098, @andreybokhanko wrote:

> In http://reviews.llvm.org/D18596#388295, @aaron.ballman wrote:
>
> > Regression is a bit of a question mark, to me depending on the diagnostic. 
> > I think warning the user "this has absolutely no effect" is a reasonable 
> > diagnostic for that situation -- the user wrote something, possibly 
> > expecting it to have an effect, and it turns out that it does absolutely 
> > nothing (including in the compiler that implements the language extension). 
> > If MSVC were to ever add semantic effect in those cases (diverging from 
> > what Clang implements), the diagnostic becomes even more important for 
> > Clang users. So I think it's fine to accept __unaligned for non-pointer 
> > types, but issue an "attribute ignored" warning diagnostic.
>
>
> As David wrote, __unaligned is a qualifier in MSVC, so MS accepts the 
> following:
>
> __unaligned int *p;
>
> as a correct usage (and does mangling for __unaligned).
>
> We model it as an attribute, so we create a new AttributedType for int, not 
> for the pointer. This is OK, since our mangling code takes PointeeType and 
> checks presence of the attribute. Unfortunately, this means that we can't 
> issue warnings, as it's impossible (to the best of my knowledge) to 
> distinguish between
>
> __unaligned int *p;
>  __unaligned int p;
>
> in processTypeAttrs function.
>
> As I said before, the purpose of this patch is to implement correct mangling 
> (and thus, improve object level compatibility with MSVC), not to provide a 
> fully correct implementation of __unaligned.
>
> Another alternative is to model __unaligned as a qualifier, but this would 
> require addition of an extra field to TypeBitfields.


That's OK.  We have plenty of bits in the "address_space" field to steal from.

> Do we want to do this for an ignored qualifier? I don't see any practical 
> purpose.


It's not ignored for Windows on ARM.

> Andrey



http://reviews.llvm.org/D18596



___
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-assign-operator-return

2016-04-05 Thread Samuel Benzaquen via cfe-commits
sbenza added inline comments.


Comment at: clang-tidy/misc/AssignOperatorCheck.cpp:63
@@ +62,3 @@
+
+  Finder->addMatcher(returnStmt(IsBadReturnStatement, 
hasAncestor(IsGoodAssign))
+ .bind("returnStmt"),

baloghadamsoftware wrote:
> sbenza wrote:
> > I dislike these uses of hasAnscestor. They are kind of slow.
> > But more importantly, they break with nested functions/types.
> > This particular example is not checking that the return statement is from 
> > the assignment operator, only that it is within it. For example, it would 
> > match a lambda.
> > I think this would trip the check:
> > 
> > F& operator=(const F& o) {
> >   std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; });
> >   return *this;
> > }
> I can change it to hasDescendant if it is faster, but it does not solve the 
> lambda problem. No solution for that comes to my mind with the existing 
> matchers. Maybe a new matcher hasDescendantStatement could help which only 
> traverses statements down the AST. Is this the right way to go?
hasDescendant has the same problem has hasAnscestor.
I think the best is to write a matcher like:

AST_MATCHER_P(ReturnStmt, forFunction, internal::Matcher, 
InnerMatcher) {
  ...
}

In there we can find the right FunctionDecl that encloses the return statement 
and apply the matcher.
This matcher seems like a good candidate to add to ASTMatchers.h


http://reviews.llvm.org/D18265



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


r265405 - [X86] Introduction of -march=lakemont.

2016-04-05 Thread Andrey Turetskiy via cfe-commits
Author: aturetsk
Date: Tue Apr  5 10:04:26 2016
New Revision: 265405

URL: http://llvm.org/viewvc/llvm-project?rev=265405&view=rev
Log:
[X86] Introduction of -march=lakemont.

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

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/CodeGen/attr-target-x86.c
cfe/trunk/test/Preprocessor/predefined-arch-macros.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=265405&r1=265404&r2=265405&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Apr  5 10:04:26 2016
@@ -2239,6 +2239,10 @@ class X86TargetInfo : public TargetInfo
 /// Knights Landing processor.
 CK_KNL,
 
+/// \name Lakemont
+/// Lakemont microarchitecture based processors.
+CK_Lakemont,
+
 /// \name K6
 /// K6 architecture processors.
 //@{
@@ -2343,6 +2347,7 @@ class X86TargetInfo : public TargetInfo
 .Case("skx", CK_SkylakeServer) // Legacy name.
 .Case("cannonlake", CK_Cannonlake)
 .Case("knl", CK_KNL)
+.Case("lakemont", CK_Lakemont)
 .Case("k6", CK_K6)
 .Case("k6-2", CK_K6_2)
 .Case("k6-3", CK_K6_3)
@@ -2490,6 +2495,7 @@ public:
 case CK_C3_2:
 case CK_Pentium4:
 case CK_Pentium4M:
+case CK_Lakemont:
 case CK_Prescott:
 case CK_K6:
 case CK_K6_2:
@@ -2588,10 +2594,13 @@ bool X86TargetInfo::initFeatureMap(
   if (getTriple().getArch() == llvm::Triple::x86_64)
 setFeatureEnabledImpl(Features, "sse2", true);
 
-  // Enable X87 for all X86 processors.
-  setFeatureEnabledImpl(Features, "x87", true);
+  const CPUKind Kind = getCPUKind(CPU);
+
+  // Enable X87 for all X86 processors but Lakemont.
+  if (Kind != CK_Lakemont)
+setFeatureEnabledImpl(Features, "x87", true);
 
-  switch (getCPUKind(CPU)) {
+  switch (Kind) {
   case CK_Generic:
   case CK_i386:
   case CK_i486:
@@ -2599,6 +2608,7 @@ bool X86TargetInfo::initFeatureMap(
   case CK_Pentium:
   case CK_i686:
   case CK_PentiumPro:
+  case CK_Lakemont:
 break;
   case CK_PentiumMMX:
   case CK_Pentium2:
@@ -3253,6 +3263,9 @@ void X86TargetInfo::getTargetDefines(con
   case CK_KNL:
 defineCPUMacros(Builder, "knl");
 break;
+  case CK_Lakemont:
+Builder.defineMacro("__tune_lakemont__");
+break;
   case CK_K6_2:
 Builder.defineMacro("__k6_2__");
 Builder.defineMacro("__tune_k6_2__");

Modified: cfe/trunk/test/CodeGen/attr-target-x86.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-target-x86.c?rev=265405&r1=265404&r2=265405&view=diff
==
--- cfe/trunk/test/CodeGen/attr-target-x86.c (original)
+++ cfe/trunk/test/CodeGen/attr-target-x86.c Tue Apr  5 10:04:26 2016
@@ -18,6 +18,8 @@ int __attribute__((target("no-aes, arch=
 
 int __attribute__((target("no-mmx"))) qq(int a) { return 40; }
 
+int __attribute__((target("arch=lakemont"))) lake(int a) { return 4; }
+
 // Check that we emit the additional subtarget and cpu features for foo and 
not for baz or bar.
 // CHECK: baz{{.*}} #0
 // CHECK: foo{{.*}} #1
@@ -31,9 +33,11 @@ int __attribute__((target("no-mmx"))) qq
 // CHECK: qux{{.*}} #1
 // CHECK: qax{{.*}} #4
 // CHECK: qq{{.*}} #5
+// CHECK: lake{{.*}} #6
 // CHECK: #0 = {{.*}}"target-cpu"="x86-64" 
"target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
 // CHECK: #1 = {{.*}}"target-cpu"="ivybridge" 
"target-features"="+aes,+avx,+cx16,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt"
 // CHECK: #2 = {{.*}}"target-cpu"="x86-64" 
"target-features"="+fxsr,+mmx,+sse,+x87,-aes,-avx,-avx2,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vl,-f16c,-fma,-fma4,-pclmul,-sha,-sse2,-sse3,-sse4.1,-sse4.2,-sse4a,-ssse3,-xop,-xsave,-xsaveopt"
 // CHECK: #3 = {{.*}}"target-cpu"="x86-64" 
"target-features"="+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
 // CHECK: #4 = {{.*}}"target-cpu"="ivybridge" 
"target-features"="+avx,+cx16,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt,-aes"
 // CHECK: #5 = {{.*}}"target-cpu"="x86-64" 
"target-features"="+fxsr,+sse,+sse2,+x87,-3dnow,-3dnowa,-mmx"
+// CHECK: #6 = {{.*}}"target-cpu"="lakemont" 
"target-features"="+mmx,+sse,+sse2"

Modified: cfe/trunk/test/Preprocessor/predefined-arch-macros.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/predefined-arch-macros.c?rev=265405&r1=265404&r2=265405&view=diff
==
--- cfe/trunk/test/Preprocessor/predefined-arch-macros.c (original)
+++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c Tue Apr  5 10:04:26 
2016
@@ -1004,6 +1004,18 @@
 // CHECK_SLM_M64: #define

Re: [PATCH] D18651: [X86] Introduction of -march=lakemont

2016-04-05 Thread Andrey Turetskiy via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL265405: [X86] Introduction of -march=lakemont. (authored by 
aturetsk).

Changed prior to commit:
  http://reviews.llvm.org/D18651?vs=52220&id=52692#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18651

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/CodeGen/attr-target-x86.c
  cfe/trunk/test/Preprocessor/predefined-arch-macros.c

Index: cfe/trunk/test/CodeGen/attr-target-x86.c
===
--- cfe/trunk/test/CodeGen/attr-target-x86.c
+++ cfe/trunk/test/CodeGen/attr-target-x86.c
@@ -18,6 +18,8 @@
 
 int __attribute__((target("no-mmx"))) qq(int a) { return 40; }
 
+int __attribute__((target("arch=lakemont"))) lake(int a) { return 4; }
+
 // Check that we emit the additional subtarget and cpu features for foo and not for baz or bar.
 // CHECK: baz{{.*}} #0
 // CHECK: foo{{.*}} #1
@@ -31,9 +33,11 @@
 // CHECK: qux{{.*}} #1
 // CHECK: qax{{.*}} #4
 // CHECK: qq{{.*}} #5
+// CHECK: lake{{.*}} #6
 // CHECK: #0 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
 // CHECK: #1 = {{.*}}"target-cpu"="ivybridge" "target-features"="+aes,+avx,+cx16,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt"
 // CHECK: #2 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+x87,-aes,-avx,-avx2,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vl,-f16c,-fma,-fma4,-pclmul,-sha,-sse2,-sse3,-sse4.1,-sse4.2,-sse4a,-ssse3,-xop,-xsave,-xsaveopt"
 // CHECK: #3 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
 // CHECK: #4 = {{.*}}"target-cpu"="ivybridge" "target-features"="+avx,+cx16,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt,-aes"
 // CHECK: #5 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+sse,+sse2,+x87,-3dnow,-3dnowa,-mmx"
+// CHECK: #6 = {{.*}}"target-cpu"="lakemont" "target-features"="+mmx,+sse,+sse2"
Index: cfe/trunk/test/Preprocessor/predefined-arch-macros.c
===
--- cfe/trunk/test/Preprocessor/predefined-arch-macros.c
+++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c
@@ -1004,6 +1004,18 @@
 // CHECK_SLM_M64: #define __x86_64 1
 // CHECK_SLM_M64: #define __x86_64__ 1
 //
+// RUN: %clang -march=lakemont -m32 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck %s -check-prefix=CHECK_LMT_M32
+// CHECK_LMT_M32: #define __i386 1
+// CHECK_LMT_M32: #define __i386__ 1
+// CHECK_LMT_M32: #define __tune_lakemont__ 1
+// CHECK_LMT_M32: #define i386 1
+// RUN: not %clang -march=lakemont -m64 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck %s -check-prefix=CHECK_LMT_M64
+// CHECK_LMT_M64: error:
+//
 // RUN: %clang -march=geode -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_GEODE_M32
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2239,6 +2239,10 @@
 /// Knights Landing processor.
 CK_KNL,
 
+/// \name Lakemont
+/// Lakemont microarchitecture based processors.
+CK_Lakemont,
+
 /// \name K6
 /// K6 architecture processors.
 //@{
@@ -2343,6 +2347,7 @@
 .Case("skx", CK_SkylakeServer) // Legacy name.
 .Case("cannonlake", CK_Cannonlake)
 .Case("knl", CK_KNL)
+.Case("lakemont", CK_Lakemont)
 .Case("k6", CK_K6)
 .Case("k6-2", CK_K6_2)
 .Case("k6-3", CK_K6_3)
@@ -2490,6 +2495,7 @@
 case CK_C3_2:
 case CK_Pentium4:
 case CK_Pentium4M:
+case CK_Lakemont:
 case CK_Prescott:
 case CK_K6:
 case CK_K6_2:
@@ -2588,17 +2594,21 @@
   if (getTriple().getArch() == llvm::Triple::x86_64)
 setFeatureEnabledImpl(Features, "sse2", true);
 
-  // Enable X87 for all X86 processors.
-  setFeatureEnabledImpl(Features, "x87", true);
+  const CPUKind Kind = getCPUKind(CPU);
+
+  // Enable X87 for all X86 processors but Lakemont.
+  if (Kind != CK_Lakemont)
+setFeatureEnabledImpl(Features, "x87", true);
 
-  switch (getCPUKind(CPU)) {
+  switch (Kind) {
   case CK_Generic:
   case CK_i386:
   case CK_i486:
   case CK_i586:
   case CK_Pentium:
   case CK_i686:
   case CK_PentiumPro:
+  case CK_Lakemont:
 break;
   case CK_PentiumMMX:
   case CK_Pentium2:
@@ -3253,6 +3263,9 @@
   case CK_KNL:
 defineCPUMacros(Builder, "knl");
 break;
+  case CK_Lakemont:
+Builder.defineMacro("__tune_lakemont__");
+break;
   case CK_K6_2:
 Builder.defineMacro("__k6_2__");
 Builder.defineMacro("__tune_k6_2__");
___

[PATCH] D18793: fix for 19986, extra spacing around c++14 lambda capture with initializer

2016-04-05 Thread Jacek Sieka via cfe-commits
arnetheduck created this revision.
arnetheduck added a reviewer: djasper.
arnetheduck added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Here's a little one-off patch that fixes
https://llvm.org/bugs/show_bug.cgi?id=19986 for me, by allowing a few
more things inside [] when trying to match a lambda capture section.

I hope someone can help it find its way into the main repo.


http://reviews.llvm.org/D18793

Files:
  lib/Format/UnwrappedLineParser.cpp

Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1080,8 +1080,25 @@
 if (!FormatTok->isOneOf(tok::identifier, tok::kw_this))
   return false;
 nextToken();
-if (FormatTok->is(tok::ellipsis))
+if (FormatTok->is(tok::equal)) {
   nextToken();
+  int parens = 0;
+  while (!eof()) {
+if (FormatTok->isOneOf(tok::l_paren, tok::l_square)) {
+  ++parens;
+} else if (parens && FormatTok->isOneOf(tok::r_paren, tok::r_square)) {
+  --parens;
+} else if (FormatTok->isOneOf(tok::comma, tok::r_square)) {
+  break;
+} else if (!FormatTok->isOneOf(tok::identifier, tok::coloncolon)) {
+  return false;
+}
+
+nextToken();
+  }
+} else if (FormatTok->is(tok::ellipsis)) {
+  nextToken();
+}
 if (FormatTok->is(tok::comma)) {
   nextToken();
 } else if (FormatTok->is(tok::r_square)) {


Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1080,8 +1080,25 @@
 if (!FormatTok->isOneOf(tok::identifier, tok::kw_this))
   return false;
 nextToken();
-if (FormatTok->is(tok::ellipsis))
+if (FormatTok->is(tok::equal)) {
   nextToken();
+  int parens = 0;
+  while (!eof()) {
+if (FormatTok->isOneOf(tok::l_paren, tok::l_square)) {
+  ++parens;
+} else if (parens && FormatTok->isOneOf(tok::r_paren, tok::r_square)) {
+  --parens;
+} else if (FormatTok->isOneOf(tok::comma, tok::r_square)) {
+  break;
+} else if (!FormatTok->isOneOf(tok::identifier, tok::coloncolon)) {
+  return false;
+}
+
+nextToken();
+  }
+} else if (FormatTok->is(tok::ellipsis)) {
+  nextToken();
+}
 if (FormatTok->is(tok::comma)) {
   nextToken();
 } else if (FormatTok->is(tok::r_square)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18649: [clang-tidy] cppcoreguidelines-interfaces-global-init

2016-04-05 Thread Aaron Ballman via cfe-commits
aaron.ballman added a subscriber: aaron.ballman.
aaron.ballman added a reviewer: aaron.ballman.


Comment at: clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.cpp:27
@@ +26,3 @@
+unless(isConstexpr()));
+  const auto IsNotDefined = unless(isDefinition());
+

This can be moved into `ReferencesUndefinedGlobalVar`


http://reviews.llvm.org/D18649



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


Re: [PATCH] D18649: [clang-tidy] cppcoreguidelines-interfaces-global-init

2016-04-05 Thread Clement Courbet via cfe-commits
courbet updated this revision to Diff 52688.
courbet added a comment.

Update naming to be constistent with the standard: use "non-local" instead of 
"global" (or "static" in my case, as I started from classes and the name stuck).


http://reviews.llvm.org/D18649

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.cpp
  clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-interfaces-global-init.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp

Index: test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp
@@ -0,0 +1,77 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-interfaces-global-init %t
+
+constexpr int makesInt() { return 3; }
+constexpr int takesInt(int i) { return i + 1; }
+constexpr int takesIntPtr(int *i) { return *i; }
+
+extern int ExternGlobal;
+static int GlobalScopeBadInit1 = ExternGlobal;
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+static int GlobalScopeBadInit2 = takesInt(ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+static int GlobalScopeBadInit3 = takesIntPtr(&ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+static int GlobalScopeBadInit4 = 3 * (ExternGlobal + 2);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+
+namespace ns {
+static int NamespaceScope = makesInt();
+static int NamespaceScopeBadInit = takesInt(ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+
+struct A {
+  static int ClassScope;
+  static int ClassScopeBadInit;
+};
+
+int A::ClassScopeBadInit = takesInt(ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:8: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ExternGlobal'
+
+static int FromClassBadInit = takesInt(A::ClassScope);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'ClassScope'
+} // namespace ns
+
+// "const int B::I;" is fine, it just ODR-defines B::I. See [9.4.3] Static
+// members [class.static]. However the ODR-definitions are not in the right
+// order (C::I after C::J, see [3.6.2.3]).
+class B1 {
+  static const int I = 0;
+  static const int J = I;
+};
+const int B1::J;
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'I'
+const int B1::I;
+
+void f() {
+  // This is fine, it's executed after dynamic initialization occurs.
+  static int G = takesInt(ExternGlobal);
+}
+
+// Defined global variables are fine:
+static int GlobalScope = makesInt();
+static int GlobalScopeBadInit = takesInt(GlobalScope);
+static int GlobalScope2 = takesInt(ns::NamespaceScope);
+// Enums are fine.
+enum Enum { kEnumValue = 1 };
+static int GlobalScopeFromEnum = takesInt(kEnumValue);
+
+// Leave constexprs alone.
+extern constexpr int GlobalScopeConstexpr = makesInt();
+static constexpr int GlobalScopeConstexprOk =
+takesInt(GlobalScopeConstexpr);
+
+// This is a pretty common instance: People are usually not using constexpr, but
+// this is what they should write:
+static constexpr const char kValue[] = "value";
+constexpr int Fingerprint(const char *value) { return 0; }
+static int kFingerprint = Fingerprint(kValue);
+
+// This is fine because the ODR-definitions are in the right order (C::J after
+// C::I).
+class B2 {
+  static const int I = 0;
+  static const int J = I;
+};
+const int B2::I;
+const int B2::J;
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -16,6 +16,7 @@
cert-fio38-c (redirects to misc-non-copyable-objects) 
cert-flp30-c
cert-oop11-cpp (redirects to misc-move-constructor-init) 
+   cppcoreguidelines-interfaces-global-init
cppcoreguidelines-pro-bounds-array-to-pointer-decay
cppcoreguidelines-pro-bounds-constant-array-index
cppcoreguidelines-pro-bounds-pointer-arithmetic
Index: docs/clang-tidy/checks/cppcoreguidelines-interfa

Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

2016-04-05 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 52690.
DmitryPolukhin marked 8 inline comments as done.
DmitryPolukhin added a comment.

- fixed all comments
- rebase

Aaron and Alexey, thank you for the review!


http://reviews.llvm.org/D18542

Files:
  include/clang/AST/ASTMutationListener.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/OpenMPKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTWriter.h
  lib/AST/ASTContext.cpp
  lib/AST/DeclPrinter.cpp
  lib/Basic/OpenMPKinds.cpp
  lib/Frontend/MultiplexConsumer.cpp
  lib/Parse/ParseOpenMP.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Serialization/ASTCommon.h
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/OpenMP/declare_target_ast_print.cpp
  test/OpenMP/declare_target_messages.cpp

Index: test/OpenMP/declare_target_messages.cpp
===
--- /dev/null
+++ test/OpenMP/declare_target_messages.cpp
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - %s
+
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+
+int a, b; // expected-warning {{declaration is not declared in any declare target region}}
+__thread int t; // expected-note {{defined as threadprivate or thread local}}
+#pragma omp declare target private(a) // expected-warning {{extra tokens at the end of '#pragma omp declare target' are ignored}}
+void f();
+#pragma omp end declare target shared(a) // expected-warning {{extra tokens at the end of '#pragma omp end declare target' are ignored}}
+void c(); // expected-warning {{declaration is not declared in any declare target region}}
+
+extern int b;
+
+struct NonT {
+  int a;
+};
+
+typedef int sint;
+
+#pragma omp declare target // expected-note {{to match this '#pragma omp declare target'}}
+#pragma omp threadprivate(a) // expected-note {{defined as threadprivate or thread local}}
+extern int b;
+int g;
+
+struct T { // expected-note {{mappable type cannot be polymorphic}}
+  int a;
+  virtual int method();
+};
+
+class VC { // expected-note {{mappable type cannot be polymorphic}}
+  T member;
+  NonT member1;
+  public:
+virtual int method() { T a; return 0; } // expected-error {{type 'T' is not mappable to target}}
+};
+
+struct C {
+  NonT a;
+  sint b;
+  int method();
+  int method1();
+};
+
+int C::method1() {
+  return 0;
+}
+
+void foo() {
+  a = 0; // expected-error {{threadprivate variables cannot be used in target constructs}}
+  b = 0; // expected-note {{used here}}
+  t = 1; // expected-error {{threadprivate variables cannot be used in target constructs}}
+  C object;
+  VC object1; // expected-error {{type 'VC' is not mappable to target}}
+  g = object.method();
+  g += object.method1();
+  g += object1.method();
+  f();
+  c(); // expected-note {{used here}}
+}
+#pragma omp declare target // expected-error {{expected '#pragma omp end declare target'}}
+void foo1() {}
+#pragma omp end declare target
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+
+int C::method() {
+  return 0;
+}
+
+struct S {
+#pragma omp declare target // expected-error {{directive must be at file or namespace scope}}
+  int v;
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+};
+
+int main (int argc, char **argv) {
+#pragma omp declare target // expected-error {{unexpected OpenMP directive '#pragma omp declare target'}}
+  int v;
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+  foo();
+  return (0);
+}
+
+namespace {
+#pragma omp declare target // expected-note {{to match this '#pragma omp declare target'}}
+  int x;
+} //  expected-error {{expected '#pragma omp end declare target'}}
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+
+#pragma omp declare target // expected-error {{expected '#pragma omp end declare target'}} expected-note {{to match this '#pragma omp declare target'}}
Index: test/OpenMP/declare_target_ast_print.cpp
===
--- /dev/null
+++ test/OpenMP/declare_target_ast_print.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+#pragma omp declare target
+// CHECK: 

Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

2016-04-05 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

Just some very minor nits, otherwise LGTM!



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7931
@@ +7930,3 @@
+def err_omp_enclosed_declare_target : Error<
+  "declare target region may not be enclosed into another declare target 
region">;
+def warn_omp_not_in_target_context : Warning<

s/into/within


Comment at: include/clang/Sema/Sema.h:7925
@@ +7924,3 @@
+  /// Return true inside OpenMP target region.
+  bool isInOpenMPDeclareTargetContext() {
+return IsInOpenMPDeclareTargetContext;

This method should be marked `const`.


Comment at: lib/Frontend/MultiplexConsumer.cpp:225
@@ +224,3 @@
+const Decl *D) {
+  for (size_t i = 0, e = Listeners.size(); i != e; ++i)
+Listeners[i]->DeclarationMarkedOpenMPDeclareTarget(D);

Use std::for_each (or at least a range-based for loop) over Listeners.


Comment at: lib/Sema/SemaOpenMP.cpp:10405
@@ +10404,3 @@
+  D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(SemaRef.Context));
+  if (auto *ML = SemaRef.Context.getASTMutationListener())
+ML->DeclarationMarkedOpenMPDeclareTarget(D);

Please do not use `auto` since the type is not spelled anywhere else in the 
expression.


Comment at: lib/Sema/SemaOpenMP.cpp:10420
@@ +10419,3 @@
+  D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(SemaRef.Context));
+  if (auto *ML = SemaRef.Context.getASTMutationListener())
+ML->DeclarationMarkedOpenMPDeclareTarget(D);

Please do not use `auto` since the type is not spelled anywhere else in the 
expression.


Comment at: lib/Sema/SemaOpenMP.cpp:10450
@@ +10449,3 @@
+D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(SemaRef.Context));
+if (auto *ML = SemaRef.Context.getASTMutationListener())
+  ML->DeclarationMarkedOpenMPDeclareTarget(D);

Please do not use `auto` since the type is not spelled anywhere else in the 
expression.


Comment at: lib/Sema/SemaOpenMP.cpp:10486
@@ +10485,3 @@
+VD->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(Context));
+if (auto *ML = Context.getASTMutationListener())
+  ML->DeclarationMarkedOpenMPDeclareTarget(VD);

Please do not use `auto` since the type is not spelled anywhere else in the 
expression.


Comment at: lib/Sema/SemaOpenMP.cpp:10497
@@ +10496,3 @@
+  D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(Context));
+  if (auto *ML = Context.getASTMutationListener())
+ML->DeclarationMarkedOpenMPDeclareTarget(D);

Please do not use `auto` since the type is not spelled anywhere else in the 
expression.


http://reviews.llvm.org/D18542



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


Re: [PATCH] D18649: [clang-tidy] cppcoreguidelines-interfaces-global-init

2016-04-05 Thread Clement Courbet via cfe-commits
courbet updated this revision to Diff 52684.
courbet added a comment.

Fix 5 of the 8 false positives. Add tests.


http://reviews.llvm.org/D18649

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.cpp
  clang-tidy/cppcoreguidelines/InterfacesGlobalInitCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-interfaces-global-init.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp

Index: test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-interfaces-global-init.cpp
@@ -0,0 +1,77 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-interfaces-global-init %t
+
+constexpr int makesInt() { return 3; }
+constexpr int takesInt(int i) { return i + 1; }
+constexpr int takesIntPtr(int *i) { return *i; }
+
+extern int ExternGlobal;
+static int GlobalScopeBadInit1 = ExternGlobal;
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing static variable with non-const expression depending on static variable 'ExternGlobal'
+static int GlobalScopeBadInit2 = takesInt(ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing static variable with non-const expression depending on static variable 'ExternGlobal'
+static int GlobalScopeBadInit3 = takesIntPtr(&ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing static variable with non-const expression depending on static variable 'ExternGlobal'
+static int GlobalScopeBadInit4 = 3 * (ExternGlobal + 2);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing static variable with non-const expression depending on static variable 'ExternGlobal'
+
+namespace ns {
+static int NamespaceScope = makesInt();
+static int NamespaceScopeBadInit = takesInt(ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing static variable with non-const expression depending on static variable 'ExternGlobal'
+
+struct A {
+  static int ClassScope;
+  static int ClassScopeBadInit;
+};
+
+int A::ClassScopeBadInit = takesInt(ExternGlobal);
+// CHECK-MESSAGES: [[@LINE-1]]:8: warning: initializing static variable with non-const expression depending on static variable 'ExternGlobal'
+
+static int FromClassBadInit = takesInt(A::ClassScope);
+// CHECK-MESSAGES: [[@LINE-1]]:12: warning: initializing static variable with non-const expression depending on static variable 'ClassScope'
+} // namespace ns
+
+// "const int B::I;" is fine, it just ODR-defines B::I. See [9.4.3] Static
+// members [class.static]. However the ODR-definitions are not in the right
+// order (C::I after C::J, see [3.6.2.3]).
+class B1 {
+  static const int I = 0;
+  static const int J = I;
+};
+const int B1::J;
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: initializing static variable with non-const expression depending on static variable 'I'
+const int B1::I;
+
+void f() {
+  // This is fine, it's executed after dynamic initialization occurs.
+  static int G = takesInt(ExternGlobal);
+}
+
+// Defined global variables are fine:
+static int GlobalScope = makesInt();
+static int GlobalScopeBadInit = takesInt(GlobalScope);
+static int GlobalScope2 = takesInt(ns::NamespaceScope);
+// Enums are fine.
+enum Enum { kEnumValue = 1 };
+static int GlobalScopeFromEnum = takesInt(kEnumValue);
+
+// Leave constexprs alone.
+extern constexpr int GlobalScopeConstexpr = makesInt();
+static constexpr int GlobalScopeConstexprOk =
+takesInt(GlobalScopeConstexpr);
+
+// This is a pretty common instance: People are usually not using constexpr, but
+// this is what they should write:
+static constexpr const char kValue[] = "value";
+constexpr int Fingerprint(const char *value) { return 0; }
+static int kFingerprint = Fingerprint(kValue);
+
+// This is fine because the ODR-definitions are in the right order (C::J after
+// C::I).
+class B2 {
+  static const int I = 0;
+  static const int J = I;
+};
+const int B2::I;
+const int B2::J;
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -16,6 +16,7 @@
cert-fio38-c (redirects to misc-non-copyable-objects) 
cert-flp30-c
cert-oop11-cpp (redirects to misc-move-constructor-init) 
+   cppcoreguidelines-interfaces-global-init
cppcoreguidelines-pro-bounds-array-to-pointer-decay
cppcoreguidelines-pro-bounds-constant-array-index
cppcoreguidelines-pro-bounds-pointer-arithmetic
Index: docs/clang-tidy/checks/cppcoreguidelines-interfaces-global-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-interfaces-global-init.rst
@@ -0,0 +1,14 @@
+.. title:: clang-tidy - cppcoreguidelines-interfaces-global-init
+
+cppcoreguidelines

Re: [PATCH] D18265: [clang-tidy] New: checker misc-assign-operator-return

2016-04-05 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware added a comment.

And what about the final name?


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] D18265: [clang-tidy] New: checker misc-assign-operator-return

2016-04-05 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware added inline comments.


Comment at: clang-tidy/misc/AssignOperatorCheck.cpp:63
@@ +62,3 @@
+
+  Finder->addMatcher(returnStmt(IsBadReturnStatement, 
hasAncestor(IsGoodAssign))
+ .bind("returnStmt"),

sbenza wrote:
> I dislike these uses of hasAnscestor. They are kind of slow.
> But more importantly, they break with nested functions/types.
> This particular example is not checking that the return statement is from the 
> assignment operator, only that it is within it. For example, it would match a 
> lambda.
> I think this would trip the check:
> 
> F& operator=(const F& o) {
>   std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; });
>   return *this;
> }
I can change it to hasDescendant if it is faster, but it does not solve the 
lambda problem. No solution for that comes to my mind with the existing 
matchers. Maybe a new matcher hasDescendantStatement could help which only 
traverses statements down the AST. Is this the right way to go?


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] D17586: Add a new check, readability-redundant-string-init, that checks unnecessary string initializations.

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

Shuai, if you have time, could you take a look at http://llvm.org/PR27087?

Thanks!


Repository:
  rL LLVM

http://reviews.llvm.org/D17586



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


Re: [clang-tools-extra] r264563 - clang-tidy: Fix broken buildbot

2016-04-05 Thread Alexander Kornienko via cfe-commits
I'm not sure I understand what this test has to do with VS2013. Clang-tidy
should be able to parse this code, and if it doesn't (e.g. due to
-fms-compatibility being turned on by default on windows), we should put
unsupported constructs under an appropriate #ifdef, not comment them out
completely.

On Mon, Mar 28, 2016 at 6:15 AM, Richard Thomson via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: legalize
> Date: Sun Mar 27 23:15:41 2016
> New Revision: 264563
>
> URL: http://llvm.org/viewvc/llvm-project?rev=264563&view=rev
> Log:
> clang-tidy: Fix broken buildbot
>
> VS 2013 does not support char16_t or char32_t
>
> Modified:
>
> clang-tools-extra/trunk/test/clang-tidy/modernize-raw-string-literal.cpp
>
> Modified:
> clang-tools-extra/trunk/test/clang-tidy/modernize-raw-string-literal.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-raw-string-literal.cpp?rev=264563&r1=264562&r2=264563&view=diff
>
> ==
> ---
> clang-tools-extra/trunk/test/clang-tidy/modernize-raw-string-literal.cpp
> (original)
> +++
> clang-tools-extra/trunk/test/clang-tidy/modernize-raw-string-literal.cpp
> Sun Mar 27 23:15:41 2016
> @@ -46,10 +46,12 @@ char const *const TrailingNewLine("A sin
>  char const *const AlreadyRaw(R"(foobie\\bletch)");
>  char const *const UTF8Literal(u8"foobie\\bletch");
>  char const *const UTF8RawLiteral(u8R"(foobie\\bletch)");
> -char16_t const *const UTF16Literal(u"foobie\\bletch");
> -char16_t const *const UTF16RawLiteral(uR"(foobie\\bletch)");
> -char32_t const *const UTF32Literal(U"foobie\\bletch");
> -char32_t const *const UTF32RawLiteral(UR"(foobie\\bletch)");
> +// TODO: enable these tests once all supported compilers
> +// support char16_t and char32_t (VS2013 does not)
> +// char16_t const *const UTF16Literal(u"foobie\\bletch");
> +// char16_t const *const UTF16RawLiteral(uR"(foobie\\bletch)");
> +// char32_t const *const UTF32Literal(U"foobie\\bletch");
> +// char32_t const *const UTF32RawLiteral(UR"(foobie\\bletch)");
>  wchar_t const *const WideLiteral(L"foobie\\bletch");
>  wchar_t const *const WideRawLiteral(LR"(foobie\\bletch)");
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18551: Added Fixer implementation and fix() interface in clang-format for removing redundant code.

2016-04-05 Thread Eric Liu via cfe-commits
ioeric added inline comments.


Comment at: lib/Format/Format.cpp:1596
@@ +1595,3 @@
+
+class Fixer : public UnwrappedLineConsumer {
+public:

djasper wrote:
> I am not sure, this is the right class to pull out. It still has a lot of 
> overlap with formatter. Maybe it is instead a better idea to pull out each 
> fixer into its own class and pull them into the formatter.
But I'm not quite sure if implementing the fixer in formatter works better 
since they look like two parallel classes to me. And it might make the 
formatter more complicated to use if we mix it with fixer. I think adding 
another layer of abstraction might be one way to reduce duplication? 


Comment at: lib/Format/Format.cpp:1654
@@ +1653,3 @@
+
+while (CurrentToken->isNot(tok::eof)) {
+  switch (CurrentToken->Tok.getKind()) {

djasper wrote:
> I am not (yet) convinced that the fundamental design here makes sense. So far 
> it seems to me that all fixers will either operate within a single line (ctor 
> fixer and probably most others) or that they do something specific on 
> multiple lines (namespace fixer and empty public/private section fixer and 
> maybe others). Creating a new way to iterate over all tokens of all lines 
> doesn't really add useful functionality here AFAICT.
I've also considered the way formatter does, which iterates over lines. But it 
seems to be easier to write fixer, especially multi-line fixer, if we can just 
ignore lines. Working with lines seems to add another layer of complexity here?


http://reviews.llvm.org/D18551



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


Re: [PATCH] D18551: Added Fixer implementation and fix() interface in clang-format for removing redundant code.

2016-04-05 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 52676.
ioeric marked 14 inline comments as done.
ioeric added a comment.

- Refactored the code to reduce code duplication. Code styling. Moved test 
cases for Fixer into a new file FixTest.cpp.
- Added RangeManager to manage affected ranges. make empty namespace fixer 
delete tokens not in an affected line.


http://reviews.llvm.org/D18551

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  unittests/Format/CMakeLists.txt
  unittests/Format/FixTest.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11274,6 +11274,44 @@
   Code, formatReplacements(Code, Replaces, Style)));
 }
 
+TEST_F(ReplacementTest, FixCodeAfterReplacements) {
+  std::string Code = "class A {\n"
+ "  A() : X(0), Y(0) { }\n"
+ "};";
+  std::string Expected = "class A {\n"
+ "  A() : X(0) {}\n"
+ "};";
+  FileID ID = Context.createInMemoryFile("format.cpp", Code);
+  tooling::Replacements Replaces;
+  Replaces.insert(tooling::Replacement(
+  Context.Sources, Context.getLocation(ID, 2, 15), 4, ""));
+
+  format::FormatStyle Style = format::getLLVMStyle();
+  auto FinalReplaces =
+  formatReplacements(Code, fixReplacements(Code, Replaces, Style), Style);
+  EXPECT_EQ(Expected, applyAllReplacements(Code, FinalReplaces));
+}
+
+TEST_F(ReplacementTest, DoNotReformatCodeNotAffectedByReplacements) {
+  std::string Code = "class A {\n"
+ "  A() : X(0), Y(0) {}\n"
+ "  f( intx)= 0;"
+ "};";
+  std::string Expected = "class A {\n"
+ "  A() : X(0) {}\n"
+ "  f( intx)= 0;"
+ "};";
+  FileID ID = Context.createInMemoryFile("format.cpp", Code);
+  tooling::Replacements Replaces;
+  Replaces.insert(tooling::Replacement(Context.Sources,
+   Context.getLocation(ID, 2, 15), 4, ""));
+
+  format::FormatStyle Style = format::getLLVMStyle();
+  auto FinalReplaces =
+  formatReplacements(Code, fixReplacements(Code, Replaces, Style), Style);
+  EXPECT_EQ(Expected, applyAllReplacements(Code, FinalReplaces));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: unittests/Format/FixTest.cpp
===
--- /dev/null
+++ unittests/Format/FixTest.cpp
@@ -0,0 +1,178 @@
+//===- unittest/Format/FixTest.cpp - Code fixing unit tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "clang/Tooling/Core/Replacement.h"
+
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace format {
+namespace {
+
+class FixTest : public ::testing::Test {
+protected:
+  std::string fix(llvm::StringRef Code,
+  const std::vector &Ranges,
+  const FormatStyle &Style = getLLVMStyle()) {
+tooling::Replacements Replaces = format::fix(Style, Code, Ranges);
+
+std::string Result = applyAllReplacements(Code, Replaces);
+EXPECT_NE("", Result);
+return Result;
+  }
+};
+
+TEST_F(FixTest, CtorInitializationSimpleRedundantComma) {
+  std::string Code = "class A {\nA() : , {} };";
+  std::string Expected = "class A {\nA()  {} };";
+  std::vector Ranges;
+  Ranges.push_back(tooling::Range(17, 0));
+  Ranges.push_back(tooling::Range(19, 0));
+  std::string Result = fix(Code, Ranges);
+  EXPECT_EQ(Expected, Result);
+
+  Code = "class A {\nA() : x(1), {} };";
+  Expected = "class A {\nA() : x(1) {} };";
+  Ranges.clear();
+  Ranges.push_back(tooling::Range(23, 0));
+  Result = fix(Code, Ranges);
+  EXPECT_EQ(Expected, Result);
+}
+
+TEST_F(FixTest, CtorInitializationBracesInParens) {
+  std::string Code = "class A {\nA() : x({1}),, {} };";
+  std::string Expected = "class A {\nA() : x({1}) {} };";
+  std::vector Ranges;
+  Ranges.push_back(tooling::Range(24, 0));
+  Ranges.push_back(tooling::Range(26, 0));
+  std::string Result = fix(Code, Ranges);
+  EXPECT_EQ(Expected, Result);
+}
+
+TEST_F(FixTest, RedundantCommaNotInAffectedRanges) {
+  std::string Code =
+  "class A {\nA() : x({1}), /* comment */, { int x = 0; } };";
+  std::string Expected =
+  "class A {\nA() : x({1}), /* comment */, { int x = 0; } };";
+  // Set the affected range to be "int x = 0", which does not intercept the
+  // constructor initialization list.
+  std::vector Ranges(1, tooling::Range(42, 9));
+  std::string Result = fix(Code, Ranges);
+  EXPECT_EQ(Exp

r265385 - clang-format: Fix cast detection on "this".

2016-04-05 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Apr  5 06:46:06 2016
New Revision: 265385

URL: http://llvm.org/viewvc/llvm-project?rev=265385&view=rev
Log:
clang-format: Fix cast detection on "this".

Before:
  auto x = (X) this;

After:
  auto x = (X)this;

This fixes llvm.org/PR27198.

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=265385&r1=265384&r2=265385&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Apr  5 06:46:06 2016
@@ -1172,9 +1172,9 @@ private:
 if (!LeftOfParens)
   return false;
 
-// If the following token is an identifier, this is a cast. All cases where
-// this can be something else are handled above.
-if (Tok.Next->is(tok::identifier))
+// If the following token is an identifier or 'this', this is a cast. All
+// cases where this can be something else are handled above.
+if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
   return true;
 
 if (!Tok.Next->Next)

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=265385&r1=265384&r2=265385&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Apr  5 06:46:06 2016
@@ -5984,6 +5984,7 @@ TEST_F(FormatTest, FormatsCasts) {
   verifyFormat("my_int a = (my_int)(my_int)-1;");
   verifyFormat("my_int a = (ns::my_int)-2;");
   verifyFormat("case (my_int)ONE:");
+  verifyFormat("auto x = (X)this;");
 
   // FIXME: single value wrapped with paren will be treated as cast.
   verifyFormat("void f(int i = (kValue)*kMask) {}");


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


[clang-tools-extra] r265384 - [clang-tidy] Add a check to detect static definitions in anonymous namespace.

2016-04-05 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Apr  5 06:42:08 2016
New Revision: 265384

URL: http://llvm.org/viewvc/llvm-project?rev=265384&view=rev
Log:
[clang-tidy] Add a check to detect static definitions in anonymous namespace.

Summary: Fixes PR26595

Reviewers: alexfh

Subscribers: cfe-commits

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

Added:

clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp

clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst

clang-tools-extra/trunk/test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt?rev=265384&r1=265383&r2=265384&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt Tue Apr  5 
06:42:08 2016
@@ -17,6 +17,7 @@ add_clang_library(clangTidyReadabilityMo
   RedundantSmartptrGetCheck.cpp
   RedundantStringInitCheck.cpp
   SimplifyBooleanExprCheck.cpp
+  StaticDefinitionInAnonymousNamespaceCheck.cpp
   UniqueptrDeleteReleaseCheck.cpp
 
   LINK_LIBS

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp?rev=265384&r1=265383&r2=265384&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp 
Tue Apr  5 06:42:08 2016
@@ -24,6 +24,7 @@
 #include "RedundantStringCStrCheck.h"
 #include "RedundantStringInitCheck.h"
 #include "SimplifyBooleanExprCheck.h"
+#include "StaticDefinitionInAnonymousNamespaceCheck.h"
 #include "UniqueptrDeleteReleaseCheck.h"
 
 namespace clang {
@@ -49,6 +50,8 @@ public:
 "readability-implicit-bool-cast");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
+CheckFactories.registerCheck(
+"readability-static-definition-in-anonymous-namespace");
 CheckFactories.registerCheck(
 "readability-named-parameter");
 CheckFactories.registerCheck(

Added: 
clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp?rev=265384&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
 (added)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
 Tue Apr  5 06:42:08 2016
@@ -0,0 +1,72 @@
+//===--- StaticDefinitionInAnonymousNamespaceCheck.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 "StaticDefinitionInAnonymousNamespaceCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+namespace {
+AST_POLYMORPHIC_MATCHER(isStatic, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+  VarDecl)) {
+  return Node.getStorageClass() == SC_Static;
+}
+} // namespace
+
+void StaticDefinitionInAnonymousNamespaceCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(namedDecl(anyOf(functionDecl(isDefinition(), isStatic()),
+ varDecl(isDefinition(), isStatic())),
+   hasParent(namespaceDecl(isAnonymous(
+ .bind("static-def"),
+ this);
+}
+
+void StaticDefinitionInAnonymousNamespaceCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *Def = Result.Nodes.getNodeAs("static-def");
+  // Skips all static definitions defined in Macro.
+  if (Def->getLocation().isMacroID())
+return;
+
+  // Skips all static definitions in func

Re: [PATCH] D18180: [clang-tidy] Add a check to detect static definitions in anonymous namespace.

2016-04-05 Thread Haojian Wu via cfe-commits
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rL265384: [clang-tidy] Add a check to detect static 
definitions in anonymous namespace. (authored by hokein).

Changed prior to commit:
  http://reviews.llvm.org/D18180?vs=52663&id=52671#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18180

Files:
  clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
  
clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
  
clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
  
clang-tools-extra/trunk/test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp

Index: clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
+++ clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
@@ -0,0 +1,35 @@
+//===--- StaticDefinitionInAnonymousNamespaceCheck.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_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Finds static function and variable definitions in anonymous namespace.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.html
+class StaticDefinitionInAnonymousNamespaceCheck : public ClangTidyCheck {
+public:
+  StaticDefinitionInAnonymousNamespaceCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
Index: clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -24,6 +24,7 @@
 #include "RedundantStringCStrCheck.h"
 #include "RedundantStringInitCheck.h"
 #include "SimplifyBooleanExprCheck.h"
+#include "StaticDefinitionInAnonymousNamespaceCheck.h"
 #include "UniqueptrDeleteReleaseCheck.h"
 
 namespace clang {
@@ -49,6 +50,8 @@
 "readability-implicit-bool-cast");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
+CheckFactories.registerCheck(
+"readability-static-definition-in-anonymous-namespace");
 CheckFactories.registerCheck(
 "readability-named-parameter");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
@@ -0,0 +1,72 @@
+//===--- StaticDefinitionInAnonymousNamespaceCheck.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 "StaticDefinitionInAnonymousNamespaceCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+namespace {
+AST_POLYMORPHIC_MATCHER(isStatic, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+  VarDecl)) {
+  return Node.getStorageClass() == SC_Static;
+}
+} // namespace
+
+void StaticDefinitionInAnonymousNamespaceCheck::reg

Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

2016-04-05 Thread Alexey Bataev via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


http://reviews.llvm.org/D18542



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


Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

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

Alexey, please review OpenMP specific things.

Aaron, are you OK with the attribute implementation and printing approach?


http://reviews.llvm.org/D18542



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


Re: [PATCH] D18766: [clang-tidy] Add check misc-multiple-statement-macro

2016-04-05 Thread Haojian Wu via cfe-commits
hokein added a comment.

Nice check! I like the check, it would be very helpful. (I have struggled with 
this kind of bug before)



Comment at: clang-tidy/misc/MultipleStatementMacroCheck.cpp:33
@@ +32,3 @@
+
+namespace {
+

I think you can put this anonymous namespace into the above one.


Comment at: clang-tidy/misc/MultipleStatementMacroCheck.cpp:37
@@ +36,3 @@
+const Stmt *nextStmt(const MatchFinder::MatchResult &Result, const Stmt *S) {
+  const Stmt *Parent = Result.Context->getParents(*S)[0].get();
+  if (!Parent)

Should we check the result returned by `Result.Context->getParents` is valid or 
not?


Comment at: docs/clang-tidy/checks/misc-multiple-statement-macro.rst:15
@@ +14,3 @@
+  if (do_increment)
+INCREMENT_TWO(a, b);
+

Would be better to add a comment to explain the sample.


http://reviews.llvm.org/D18766



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


Re: [PATCH] D18765: [clang-tidy] Don't complain about const pass_object_size params in declarations

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

To clarify: the `pass_object_size` attribute is not the only reason to mark 
parameter `const` in the definition. However, there's no reason to also mark 
them `const` in declarations, since that `const` is not a part of the 
function's interface.


http://reviews.llvm.org/D18765



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


Re: [PATCH] D18765: [clang-tidy] Don't complain about const pass_object_size params in declarations

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

There's a principal difference between top-level `const` on parameters in 
definitions and in declarations: in definitions `const` has an effect, as it 
makes the variable constant, but in declarations it has absolutely no effect. 
Since declarations usually represent the function's interface, and top-level 
`const` on parameters doesn't change the function's signature, it's considered 
useless and misleading when used on declarations. Long story short, I don't see 
any value in this change.


http://reviews.llvm.org/D18765



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


Re: [PATCH] D18110: [OpenMP] Fix SEMA bug in the capture of global variables in template functions.

2016-04-05 Thread Alexey Bataev via cfe-commits
I think this code must be removed and we need to start with the basic 
general solution. I missed this part of the code accidentally, but it 
does not mean that I agree with it.

Best regards,
Alexey Bataev
=
Software Engineer
Intel Compiler Team

05.04.2016 0:39, Samuel Antao пишет:
> sfantao added a comment.
>
> I just wanted to add to what Carlo just said, that the feature to capture by 
> value is already used in the offloading upstreamed code. This is not a new 
> feature we are proposing , it is already there used in the code and tested in 
> relevant regression tests. This patch is just about fixing a bug that we 
> identified related to that.
>
> Changing back to capture everything by reference will require 
> reverting/refactor code that is already upstreamed and functional. On top of 
> that, as per the spec and also because of the aforementioned performance 
> issues, we would have to go to capture things by value anyway. So, it looks 
> to me that what you are suggesting is to move backwards, so I'd rather 
> discuss what are the specific concerns with this patch or the by-value 
> captures, so that we can properly address them instead of just delaying the 
> discussion and have to move backwards in the meantime.
>
> Thanks!
> Samuel
>
>
> http://reviews.llvm.org/D18110
>
>
>

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


Re: [PATCH] D18110: [OpenMP] Fix SEMA bug in the capture of global variables in template functions.

2016-04-05 Thread Alexey Bataev via cfe-commits
Carlo,
I don't agree with your analysis.
1. This is how it works now. It does not say that the argument must be 
passed by value. Later we may add some generic optimization to optimize 
not only target specific code, but also non-target specific code.
2. In this case such constructs must be gathered in an implicit 
OMPFirstprivateClause to be handled automatically by the existing codegen.
3. It just means this is variable must be gathered in an implicit 
OMPPrivateClause and handled by automatic codegen procedure.

Again, I think you must start with basic implementation. I think if we 
will start from the basic implementation, some problems may be solved 
without any preliminary optimizations.
That's why I insist on non-optimized version of the code as the first step.

Best regards,
Alexey Bataev
=
Software Engineer
Intel Compiler Team

04.04.2016 18:35, Carlo Bertolli пишет:
> carlo.bertolli added a comment.
>
> Hi Alexey
>
> I understand your concerns and share the danger of working on optimizations 
> before a correct implementation is actually in place.
> I do not think this is the case. My comment was very precise about the 
> cause-effect: the OpenMP specification was defined in a certain way, and that 
> is what we should implement, and the consequence of that is an optimized 
> implementation compared to what we had in OpenMP 4.0.
>
> Here are the passages of the OpenMP specifications where I think this is 
> specified (from OpenMP 4.5 specification text):
>
> - Page 197, description of firstprivate: "A list item that appears in a 
> firstprivate clause is subject to the private clause semantics described in 
> Section 2.15.3.3 on page 192, except as noted. In addition,** the new list 
> item is initialized from the original list item existing before the 
> construct**."
>
> - Page 105, restrictions of target: "If an array section is a list item in a 
> map clause and the array section is derived from a variable for which the 
> type is pointer then the data-sharing attribute for that variable in the 
> construct is firstprivate. Prior to the execution of the construct, **the 
> private variable is initialized with the address of the storage location of 
> the corresponding array section in the device data environment**."
>
> - Page 105, following paragraph: "If a zero-length array section is a list 
> item in a map clause, and the array section is derived from a variable for 
> the which the type is pointer then** that variable is initialized with the 
> address of the corresponding storage location in the device data 
> environment**."
>
> In this I read that whenever we have a map with an array section, or a map on 
> a zero-length array section, or a firstprivate on any kind of variable, we 
> need to copy the value of the variable (scalar, pointer) into the 
> corresponding private variable.
>
> Implementing this with references would work indeed, but it would be like 
> implementing pass-by-value using references.
>
> We had long discussion about this with various members of the OpenMP 
> committee on how to implement this correctly. This is why I am insisting on 
> this not being an optimization.
>
> However, this may not apply here (that is why I conditioned by previous 
> comment) or you still think that we should always pass references for any 
> kind of argument to target regions. It is your call, but I wanted to make 
> sure that this is put in the right light.
>
> Thanks!
>
> - Carlo
>
>
> http://reviews.llvm.org/D18110
>
>
>

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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-05 Thread Benjamin Kramer via cfe-commits
bkramer added a subscriber: bkramer.


Comment at: clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp:21
@@ +20,3 @@
+// Retrieve the character at offset |offset| of the string literal |SL|.
+static unsigned int GetCharAt(const StringLiteral *SL, size_t offset) {
+  if (offset >= SL->getLength()) return 0;

Isn't this identical to StringLiteral::getCodeUnit? Also returning 0 for 
unknown sizes is not a good idea imo.


http://reviews.llvm.org/D18783



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


r265381 - Consolidate and improve the handling of built-in feature-like macros

2016-04-05 Thread Andy Gibbs via cfe-commits
Author: andyg
Date: Tue Apr  5 03:36:47 2016
New Revision: 265381

URL: http://llvm.org/viewvc/llvm-project?rev=265381&view=rev
Log:
Consolidate and improve the handling of built-in feature-like macros

Summary:
The parsing logic has been separated out from the macro implementation logic, 
leading to a number of improvements:

* Gracefully handle unexpected/invalid tokens, too few, too many and nested 
parameters
* Provide consistent behaviour between all built-in feature-like macros
* Simplify the implementation of macro logic
* Fix __is_identifier to correctly return '0' for non-identifiers

Reviewers: doug.gregor, rsmith

Subscribers: rsmith, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/test/Preprocessor/feature_tests.c
cfe/trunk/test/Preprocessor/invalid-__has_warning1.c
cfe/trunk/test/Preprocessor/invalid-__has_warning2.c
cfe/trunk/test/Preprocessor/warning_tests.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=265381&r1=265380&r2=265381&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Apr  5 03:36:47 2016
@@ -401,6 +401,7 @@ def err_pp_expected_rparen : Error<"expe
 def err_pp_expected_eol : Error<
   "expected end of line in preprocessor expression">;
 def err_pp_expected_after : Error<"missing %1 after %0">;
+def err_pp_nested_paren : Error<"nested parentheses not permitted in %0">;
 def err_pp_colon_without_question : Error<"':' without preceding '?'">;
 def err_pp_division_by_zero : Error<
   "division by zero in preprocessor expression">;

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=265381&r1=265380&r2=265381&view=diff
==
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Tue Apr  5 03:36:47 2016
@@ -1053,9 +1053,8 @@ static void ComputeDATE_TIME(SourceLocat
 
 /// HasFeature - Return true if we recognize and implement the feature
 /// specified by the identifier as a standard language feature.
-static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) {
+static bool HasFeature(const Preprocessor &PP, StringRef Feature) {
   const LangOptions &LangOpts = PP.getLangOpts();
-  StringRef Feature = II->getName();
 
   // Normalize the feature name, __foo__ becomes foo.
   if (Feature.startswith("__") && Feature.endswith("__") && Feature.size() >= 
4)
@@ -1229,8 +1228,8 @@ static bool HasFeature(const Preprocesso
 /// HasExtension - Return true if we recognize and implement the feature
 /// specified by the identifier, either as an extension or a standard language
 /// feature.
-static bool HasExtension(const Preprocessor &PP, const IdentifierInfo *II) {
-  if (HasFeature(PP, II))
+static bool HasExtension(const Preprocessor &PP, StringRef Extension) {
+  if (HasFeature(PP, Extension))
 return true;
 
   // If the use of an extension results in an error diagnostic, extensions are
@@ -1240,7 +1239,6 @@ static bool HasExtension(const Preproces
 return false;
 
   const LangOptions &LangOpts = PP.getLangOpts();
-  StringRef Extension = II->getName();
 
   // Normalize the extension name, __foo__ becomes foo.
   if (Extension.startswith("__") && Extension.endswith("__") &&
@@ -1424,48 +1422,120 @@ static bool EvaluateHasIncludeNext(Token
   return EvaluateHasIncludeCommon(Tok, II, PP, Lookup, LookupFromFile);
 }
 
-/// \brief Process __building_module(identifier) expression.
-/// \returns true if we are building the named module, false otherwise.
-static bool EvaluateBuildingModule(Token &Tok,
-   IdentifierInfo *II, Preprocessor &PP) {
-  // Get '('.
-  PP.LexNonComment(Tok);
-
-  // Ensure we have a '('.
+/// \brief Process single-argument builtin feature-like macros that return
+/// integer values.
+static void EvaluateFeatureLikeBuiltinMacro(llvm::raw_svector_ostream& OS,
+Token &Tok, IdentifierInfo *II,
+Preprocessor &PP,
+llvm::function_ref<
+  int(Token &Tok,
+  bool &HasLexedNextTok)> Op) {
+  // Parse the initial '('.
+  PP.LexUnexpandedToken(Tok);
   if (Tok.isNot(tok::l_paren)) {
 PP.Diag(Tok.getLocation(), diag::err_pp_expected_after) << II
 << tok::l_paren;
-return false;
+
+// Provide a dummy '0' value on ou

Re: [PATCH] D17149: Consolidate and improve the handling of built-in feature-like macros

2016-04-05 Thread Andy Gibbs via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL265381: Consolidate and improve the handling of built-in 
feature-like macros (authored by AndyG).

Changed prior to commit:
  http://reviews.llvm.org/D17149?vs=52535&id=52664#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17149

Files:
  cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
  cfe/trunk/lib/Lex/PPMacroExpansion.cpp
  cfe/trunk/test/Preprocessor/feature_tests.c
  cfe/trunk/test/Preprocessor/invalid-__has_warning1.c
  cfe/trunk/test/Preprocessor/invalid-__has_warning2.c
  cfe/trunk/test/Preprocessor/warning_tests.c

Index: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
@@ -401,6 +401,7 @@
 def err_pp_expected_eol : Error<
   "expected end of line in preprocessor expression">;
 def err_pp_expected_after : Error<"missing %1 after %0">;
+def err_pp_nested_paren : Error<"nested parentheses not permitted in %0">;
 def err_pp_colon_without_question : Error<"':' without preceding '?'">;
 def err_pp_division_by_zero : Error<
   "division by zero in preprocessor expression">;
Index: cfe/trunk/test/Preprocessor/invalid-__has_warning2.c
===
--- cfe/trunk/test/Preprocessor/invalid-__has_warning2.c
+++ cfe/trunk/test/Preprocessor/invalid-__has_warning2.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -verify %s
 
 // These must be the last lines in this test.
-// expected-error@+1{{expected string literal}} expected-error@+1{{expected}}
+// expected-error@+1{{too few arguments}}
 int i = __has_warning();
Index: cfe/trunk/test/Preprocessor/warning_tests.c
===
--- cfe/trunk/test/Preprocessor/warning_tests.c
+++ cfe/trunk/test/Preprocessor/warning_tests.c
@@ -12,7 +12,7 @@
 #endif
 
 // expected-error@+2 {{expected string literal in '__has_warning'}}
-// expected-error@+1 {{expected value in expression}}
+// expected-error@+1 {{missing ')'}} expected-note@+1 {{match}}
 #if __has_warning(-Wfoo)
 #endif
 
@@ -22,8 +22,7 @@
 #warning Not a valid warning flag
 #endif
 
-// expected-error@+2 {{builtin warning check macro requires a parenthesized string}}
-// expected-error@+1 {{invalid token}}
+// expected-error@+1 {{missing '(' after '__has_warning'}}
 #if __has_warning "not valid"
 #endif
 
@@ -33,7 +32,7 @@
 
 #define MY_ALIAS "-Wparentheses"
 
-// expected-error@+1 2{{expected}}
+// expected-error@+1 {{expected}}
 #if __has_warning(MY_ALIAS)
 #error Alias expansion not allowed
 #endif
Index: cfe/trunk/test/Preprocessor/feature_tests.c
===
--- cfe/trunk/test/Preprocessor/feature_tests.c
+++ cfe/trunk/test/Preprocessor/feature_tests.c
@@ -55,8 +55,50 @@
 #endif
 
 #ifdef VERIFY
-// expected-error@+2 {{builtin feature check macro requires a parenthesized identifier}}
-// expected-error@+1 {{expected value in expression}}
+// expected-error@+1 {{builtin feature check macro requires a parenthesized identifier}}
 #if __has_feature('x')
 #endif
+
+// The following are not identifiers:
+_Static_assert(!__is_identifier("string"), "oops");
+_Static_assert(!__is_identifier('c'), "oops");
+_Static_assert(!__is_identifier(123), "oops");
+_Static_assert(!__is_identifier(int), "oops");
+
+// The following are:
+_Static_assert(__is_identifier(abc /* comment */), "oops");
+_Static_assert(__is_identifier /* comment */ (xyz), "oops");
+
+// expected-error@+1 {{too few arguments}}
+#if __is_identifier()
+#endif
+
+// expected-error@+1 {{too many arguments}}
+#if __is_identifier(,())
+#endif
+
+// expected-error@+1 {{missing ')' after 'abc'}} 
+#if __is_identifier(abc xyz) // expected-note {{to match this '('}}
+#endif
+
+// expected-error@+1 {{missing ')' after 'abc'}} 
+#if __is_identifier(abc())   // expected-note {{to match this '('}}
+#endif
+
+// expected-error@+1 {{missing ')' after '.'}} 
+#if __is_identifier(.abc)// expected-note {{to match this '('}}
+#endif
+
+// expected-error@+1 {{nested parentheses not permitted in '__is_identifier'}} 
+#if __is_identifier((abc))
+#endif
+
+// expected-error@+1 {{missing '(' after '__is_identifier'}} expected-error@+1 {{expected value}}
+#if __is_identifier
+#endif
+
+// expected-error@+1 {{unterminated}} expected-error@+1 {{expected value}}
+#if __is_identifier(
+#endif
+
 #endif
Index: cfe/trunk/test/Preprocessor/invalid-__has_warning1.c
===
--- cfe/trunk/test/Preprocessor/invalid-__has_warning1.c
+++ cfe/trunk/test/Preprocessor/invalid-__has_warning1.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -verify %s
 
 // These must be the last lines in this test.
-// expected-error@+1{{expected string literal}} expected-error@+1 2{{expected}}
+// expected-error@+1{{untermina

Re: clang-format: fix for 19986, extra spacing around c++14 lambda capture with initializer

2016-04-05 Thread Daniel Jasper via cfe-commits
Please use reviews.llvm.org to send out clang-format patches.

On Mon, Apr 4, 2016 at 10:03 AM, Jacek Sieka via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hello,
>
> Here's a little one-off patch that fixes
> https://llvm.org/bugs/show_bug.cgi?id=19986 for me, by allowing a few
> more things inside [] when trying to match a lambda capture section.
>
> I hope someone can help it find its way into the main repo.
>
> Cheers,
> Jacek
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18180: [clang-tidy] Add a check to detect static definitions in anonymous namespace.

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

Awesome. Thank you!
LG


http://reviews.llvm.org/D18180



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


Re: [PATCH] D18180: [clang-tidy] Add a check to detect static definitions in anonymous namespace.

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

- fix inline code snippet in rst.
- Add check-message for macro in test code.


http://reviews.llvm.org/D18180

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
  clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
  docs/clang-tidy/checks/list.rst
  
docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
  test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp

Index: test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp
@@ -0,0 +1,49 @@
+// RUN: %check_clang_tidy %s readability-static-definition-in-anonymous-namespace %t
+
+namespace {
+
+int a = 1;
+const int b = 1;
+static int c = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'c' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]
+// CHECK-FIXES: {{^}}int c = 1;
+static const int d = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'd' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}const int d = 1;
+const static int e = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'e' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}const int e = 1;
+
+void f() {
+  int a = 1;
+  static int b = 1;
+}
+
+static int g() {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'g' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}int g() {
+  return 1;
+}
+
+#define DEFINE_STATIC static
+// CHECK-FIXES: {{^}}#define DEFINE_STATIC static
+DEFINE_STATIC int h = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'h' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}DEFINE_STATIC int h = 1;
+
+#define DEFINE_STATIC_VAR(x) static int x = 2
+// CHECK-FIXES: {{^}}#define DEFINE_STATIC_VAR(x) static int x = 2
+DEFINE_STATIC_VAR(i);
+// CHECK-FIXES: {{^}}DEFINE_STATIC_VAR(i);
+
+} // namespace
+
+namespace N {
+
+int a = 1;
+const int b = 1;
+static int c = 1;
+static const int d = 1;
+const static int e = 1;
+
+} // namespace N
Index: docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - readability-static-definition-in-anonymous-namespace
+
+readability-static-definition-in-anonymous-namespace
+
+
+Finds static function and variable definitions in anonymous namespace.
+
+In this case, ``static`` is redundant, because anonymous namespace limits the
+visibility of definitions to a single translation unit.
+
+.. code:: c++
+  namespace {
+static int a = 1; // Warning.
+static const b = 1; // Warning.
+  }
+
+The check will apply a fix by removing the redundant ``static`` qualifier.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -101,4 +101,5 @@
readability-redundant-string-cstr
readability-redundant-string-init
readability-simplify-boolean-expr
+   readability-static-definition-in-anonymous-namespace
readability-uniqueptr-delete-release
Index: clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
===
--- /dev/null
+++ clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
@@ -0,0 +1,35 @@
+//===--- StaticDefinitionInAnonymousNamespaceCheck.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_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Finds static function and variable definitions in anonymous namespace.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.html
+class StaticDefinitionInAnonymousNamespaceCheck : public ClangTidyCheck {
+public:
+  StaticDefinitionInAnonymousNamespaceCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {

Re: [PATCH] D18596: [MSVC] PR27132: Proper mangling for __unaligned qualifier

2016-04-05 Thread Andrey Bokhanko via cfe-commits
andreybokhanko added a comment.

In http://reviews.llvm.org/D18596#388295, @aaron.ballman wrote:

> Regression is a bit of a question mark, to me depending on the diagnostic. I 
> think warning the user "this has absolutely no effect" is a reasonable 
> diagnostic for that situation -- the user wrote something, possibly expecting 
> it to have an effect, and it turns out that it does absolutely nothing 
> (including in the compiler that implements the language extension). If MSVC 
> were to ever add semantic effect in those cases (diverging from what Clang 
> implements), the diagnostic becomes even more important for Clang users. So I 
> think it's fine to accept __unaligned for non-pointer types, but issue an 
> "attribute ignored" warning diagnostic.


As David wrote, __unaligned is a qualifier in MSVC, so MS accepts the following:

__unaligned int *p;

as a correct usage (and does mangling for __unaligned).

We model it as an attribute, so we create a new AttributedType for int, not for 
the pointer. This is OK, since our mangling code takes PointeeType and checks 
presence of the attribute. Unfortunately, this means that we can't issue 
warnings, as it's impossible (to the best of my knowledge) to distinguish 
between

__unaligned int *p;
__unaligned int p;

in processTypeAttrs function.

As I said before, the purpose of this patch is to implement correct mangling 
(and thus, improve object level compatibility with MSVC), not to provide a 
fully correct implementation of __unaligned.

Another alternative is to model __unaligned as a qualifier, but this would 
require addition of an extra field to TypeBitfields. Do we want to do this for 
an ignored qualifier? I don't see any practical purpose.

Andrey


http://reviews.llvm.org/D18596



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


Re: [PATCH] D18596: [MSVC] PR27132: Proper mangling for __unaligned qualifier

2016-04-05 Thread Andrey Bokhanko via cfe-commits
andreybokhanko updated this revision to Diff 52662.
andreybokhanko added a comment.

Added Sema test, as per Aaron's and Reid's request.


http://reviews.llvm.org/D18596

Files:
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCXX/mangle-ms-cxx11.cpp
  test/SemaCXX/MicrosoftExtensions.cpp

Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -1413,6 +1413,11 @@
 
   if (HasRestrict)
 Out << 'I';
+
+  if (!PointeeType.isNull())
+if (auto AT = PointeeType->getAs())
+  if (AT->getAttrKind() == AttributedType::attr_unaligned)
+Out << 'F';
 }
 
 void MicrosoftCXXNameMangler::manglePointerCVQualifiers(Qualifiers Quals) {
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -1156,6 +1156,7 @@
 case AttributedType::attr_ptr64: OS << " __ptr64"; break;
 case AttributedType::attr_sptr: OS << " __sptr"; break;
 case AttributedType::attr_uptr: OS << " __uptr"; break;
+case AttributedType::attr_unaligned: OS << " __unaligned"; break;
 }
 spaceBeforePlaceHolder(OS);
   }
Index: lib/AST/Type.cpp
===
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -3003,6 +3003,7 @@
   case AttributedType::attr_sptr:
   case AttributedType::attr_uptr:
   case AttributedType::attr_objc_kindof:
+  case AttributedType::attr_unaligned:
 return false;
   }
   llvm_unreachable("bad attributed type kind");
@@ -3015,6 +3016,7 @@
   case attr_ptr64:
   case attr_sptr:
   case attr_uptr:
+  case attr_unaligned:
 return true;
   }
   llvm_unreachable("invalid attr kind");
@@ -3039,6 +3041,7 @@
   case attr_nullable:
   case attr_null_unspecified:
   case attr_objc_kindof:
+  case attr_unaligned:
 return false;
 
   case attr_pcs:
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -120,7 +120,8 @@
 case AttributeList::AT_Ptr32: \
 case AttributeList::AT_Ptr64: \
 case AttributeList::AT_SPtr: \
-case AttributeList::AT_UPtr
+case AttributeList::AT_UPtr: \
+case AttributeList::AT_Unaligned
 
 // Nullability qualifiers.
 #define NULLABILITY_TYPE_ATTRS_CASELIST \
@@ -4538,6 +4539,8 @@
 return AttributeList::AT_TypeNullUnspecified;
   case AttributedType::attr_objc_kindof:
 return AttributeList::AT_ObjCKindOf;
+  case AttributedType::attr_unaligned:
+return AttributeList::AT_Unaligned;
   }
   llvm_unreachable("unexpected attribute kind!");
 }
@@ -5548,7 +5551,7 @@
 
   // Pointer type qualifiers can only operate on pointer types, but not
   // pointer-to-member types.
-  if (!isa(Desugared)) {
+  if (!isa(Desugared) && (Kind != AttributeList::AT_Unaligned)) {
 if (Type->isMemberPointerType())
   S.Diag(Attr.getLoc(), diag::err_attribute_no_member_pointers)
   << Attr.getName();
@@ -5565,6 +5568,7 @@
   case AttributeList::AT_Ptr64: TAK = AttributedType::attr_ptr64; break;
   case AttributeList::AT_SPtr: TAK = AttributedType::attr_sptr; break;
   case AttributeList::AT_UPtr: TAK = AttributedType::attr_uptr; break;
+  case AttributeList::AT_Unaligned: TAK = AttributedType::attr_unaligned; break;
   }
 
   Type = S.Context.getAttributedType(TAK, Type, Type);
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -3639,6 +3639,7 @@
 attr_null_unspecified,
 attr_objc_kindof,
 attr_objc_inert_unsafe_unretained,
+attr_unaligned,
   };
 
 private:
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -1957,3 +1957,18 @@
   The system will crash if the wrong handler is used.
   }];
 }
+
+def UnalignedDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``__unaligned`` modifier declares a pointer with an unaligned address.
+It is available under the ``-fms-extensions`` flag for MSVC compatibility.
+See the documentation for `__unaligned`_ on MSDN.
+
+.. _`__unaligned`: https://msdn.microsoft.com/en-us/library/ms177389.aspx 
+
+Clang supports proper mangling of the variables with ``unaligned`` modifier,
+but it doesn't affect generated code in any other way.
+  }];
+}
+
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -2075,8 +2075,10 @@
   }];
 }
 
-def Unaligned : IgnoredAttr {
+def Unaligned : TypeAttr {
   let Spellings = [Keyw

Re: [PATCH] D18180: [clang-tidy] Add a check to detect static definitions in anonymous namespace.

2016-04-05 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: 
docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst:9
@@ +8,3 @@
+In this case, `static` is redundant, because anonymous namespace limits the
+visibility of definitions to a single translation unit.
+

This is still not done.


Comment at: 
test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp:34
@@ +33,3 @@
+#define DEFINE_STATIC_VAR(x) static int x = 2
+DEFINE_STATIC_VAR(i);
+// CHECK-FIXES: {{^}}DEFINE_STATIC_VAR(i);

hokein wrote:
> Oops. I misunderstood your comment. Done now.
Sorry for being unclear again: please add

  // CHECK-FIXES: #define DEFINE_STATIC_VAR(x) static int x = 2

to verify that the check doesn't unintentionally remove `static` from the macro 
definition. Same for the macro above.


http://reviews.llvm.org/D18180



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


Re: [PATCH] D18180: [clang-tidy] Add a check to detect static definitions in anonymous namespace.

2016-04-05 Thread Haojian Wu via cfe-commits
hokein marked 2 inline comments as done.


Comment at: 
test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp:34
@@ +33,3 @@
+#define DEFINE_STATIC_VAR(x) static int x = 2
+DEFINE_STATIC_VAR(i);
+// CHECK-FIXES: {{^}}DEFINE_STATIC_VAR(i);

Oops. I misunderstood your comment. Done now.


http://reviews.llvm.org/D18180



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


Re: [PATCH] D18180: [clang-tidy] Add a check to detect static definitions in anonymous namespace.

2016-04-05 Thread Haojian Wu via cfe-commits
hokein updated this revision to Diff 52661.
hokein added a comment.

Update


http://reviews.llvm.org/D18180

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
  clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
  docs/clang-tidy/checks/list.rst
  
docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
  test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp

Index: test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-static-definition-in-anonymous-namespace.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s readability-static-definition-in-anonymous-namespace %t
+
+namespace {
+
+int a = 1;
+const int b = 1;
+static int c = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'c' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]
+// CHECK-FIXES: {{^}}int c = 1;
+static const int d = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'd' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}const int d = 1;
+const static int e = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'e' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}const int e = 1;
+
+void f() {
+  int a = 1;
+  static int b = 1;
+}
+
+static int g() {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'g' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}int g() {
+  return 1;
+}
+
+#define DEFINE_STATIC static
+DEFINE_STATIC int h = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'h' is a static definition in anonymous namespace
+// CHECK-FIXES: {{^}}DEFINE_STATIC int h = 1;
+
+#define DEFINE_STATIC_VAR(x) static int x = 2
+DEFINE_STATIC_VAR(i);
+// CHECK-FIXES: {{^}}DEFINE_STATIC_VAR(i);
+
+} // namespace
+
+namespace N {
+
+int a = 1;
+const int b = 1;
+static int c = 1;
+static const int d = 1;
+const static int e = 1;
+
+} // namespace N
Index: docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - readability-static-definition-in-anonymous-namespace
+
+readability-static-definition-in-anonymous-namespace
+
+
+Finds static function and variable definitions in anonymous namespace.
+
+In this case, `static` is redundant, because anonymous namespace limits the
+visibility of definitions to a single translation unit.
+
+.. code:: c++
+  namespace {
+static int a = 1; // Warning.
+static const b = 1; // Warning.
+  }
+
+The check will apply a fix by removing the redundant `static` qualifier.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -101,4 +101,5 @@
readability-redundant-string-cstr
readability-redundant-string-init
readability-simplify-boolean-expr
+   readability-static-definition-in-anonymous-namespace
readability-uniqueptr-delete-release
Index: clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
===
--- /dev/null
+++ clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.h
@@ -0,0 +1,35 @@
+//===--- StaticDefinitionInAnonymousNamespaceCheck.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_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STATIC_DEFINITION_IN_ANONYMOUS_NAMESPACE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Finds static function and variable definitions in anonymous namespace.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.html
+class StaticDefinitionInAnonymousNamespaceCheck : public ClangTidyCheck {
+public:
+  StaticDefinitionInAnonymousNamespaceCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endi