[PATCH] D29480: C++11 Compatibility - OpenMP constant expressions

2017-02-02 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D29480



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


[PATCH] D25208: [libc++] Make _LIBCPP_TYPE_VIS export members

2017-02-02 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Ping.


https://reviews.llvm.org/D25208



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


[PATCH] D29157: [libc++] Make _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS export members

2017-02-02 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Ping.


https://reviews.llvm.org/D29157



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


[PATCH] D24933: Enable configuration files in clang

2017-02-02 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added inline comments.



Comment at: include/clang/Driver/Driver.h:219
+  /// This number may be smaller that \c NumConfigOptions if some options
+  /// requires separate arguments.
+  unsigned NumConfigArgs;

requires -> require



Comment at: lib/Driver/ToolChain.cpp:183
   std::string Target;
-  if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
+  if (!VerifyTarget || llvm::TargetRegistry::lookupTarget(Prefix, 
IgnoredError))
 Target = Prefix;

I don't think that we can do it this way; it is a behavior change (we now might 
try to set the target to some string which did not validate as a known target, 
whereas we did not previously).

How about you always return the prefix, but also return a boolean indicating 
whether or not the prefix is a valid target? Then, after processing the config 
file, you can clear out the string if it was not a valid target.



Comment at: tools/driver/driver.cpp:363
+   TargetAndMode.first + ".cfg");
+TargetAndMode.first.clear();
+  }

I don't think that you can clear the string here. We might need it later to 
call insertTargetAndModeArgs.



Comment at: tools/driver/driver.cpp:449
+  // there are options read from config file, put the options from "CL"
+  // after them, - config file is considered as a "patch" to compiler
+  // defaults.

Replace
  after them, - config file
with
  after them because the config file



https://reviews.llvm.org/D24933



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


Re: [PATCH] D29479: Driver: Do not warn about unused -pthread when linking on darwin

2017-02-02 Thread Duncan P. N. Exon Smith via cfe-commits
Seems reasonable to me.

I wonder, should this do something in the case where -nostdlib has been passed, 
so we're not linking against libc by default?  Or should it error/warning/etc.?

One comment inline below.

> On 2017-Feb-02, at 16:56, Matthias Braun via Phabricator 
>  wrote:
> 
> MatzeB created this revision.
> Herald added a subscriber: mcrosier.
> 
> While there is nothing to do at link time to get pthreads support on
> darwin, specifying -pthread is fine and should not produce a warning
> about unused arguments.
> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D29479
> 
> Files:
>  lib/Driver/Tools.cpp
>  test/Driver/darwin-ld-pthread.c
> 
> 
> Index: test/Driver/darwin-ld-pthread.c
> ===
> --- /dev/null
> +++ test/Driver/darwin-ld-pthread.c
> @@ -0,0 +1,5 @@
> +// RUN: %clang -target x86_64-apple-darwin -c -o %t.o %s

I *think* you can skip this command, and just pass /dev/null as the object file 
to the next driver command.

> +// RUN: %clang -Wunused-command-line-argument -pthread -target 
> x86_64-apple-darwin -### %t.o -o %t.bin 2>&1 | 
> FileCheck %s
> +
> +// There is nothing to do at link time to get pthread support. But do not 
> warn.
> +// CHECK-NOT: argument unused during compilation: '-pthread'
> Index: lib/Driver/Tools.cpp
> ===
> --- lib/Driver/Tools.cpp
> +++ lib/Driver/Tools.cpp
> @@ -8718,6 +8718,9 @@
> }
>   }
> 
> +  // No need to do anything for pthreads. Claim argument to avoid warning.
> +  Args.ClaimAllArgs(options::OPT_pthread);
> +
>   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
>   std::unique_ptr Cmd =
>   llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs);
> 
> 
> 

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


[PATCH] D24812: Lit C++11 Compatibility Patch #11

2017-02-02 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a reviewer: rjmccall.
probinson added a comment.

+rjmccall as CodeGen owner.


https://reviews.llvm.org/D24812



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


[PATCH] D29480: C++11 Compatibility - OpenMP constant expressions

2017-02-02 Thread Charles Li via Phabricator via cfe-commits
tigerleapgorge created this revision.

I am continuing to make Lit tests C++11 compatible.
This patch is a subset of the previous https://reviews.llvm.org/D20710
This patch contains 4 tests, the changes are nearly identical.
C++11 introduced constexpr, hence the change in diagnostics.

C++11 added 2 new Notes following the existing Warning.

  Existing: error: expression is not an integral constant expression
  C++11: note: non-constexpr function 'foobool' cannot be used in a constant 
expression
  C++11: note: declared here

Change in Error message.

  C++98: expression is not an integral constant expression
  C++11: integral constant expression must have integral or unscoped 
enumeration type, not 'char *'


https://reviews.llvm.org/D29480

Files:
  test/OpenMP/distribute_collapse_messages.cpp
  test/OpenMP/ordered_messages.cpp
  test/OpenMP/target_parallel_for_collapse_messages.cpp
  test/OpenMP/target_parallel_for_ordered_messages.cpp

Index: test/OpenMP/target_parallel_for_ordered_messages.cpp
===
--- test/OpenMP/target_parallel_for_ordered_messages.cpp
+++ test/OpenMP/target_parallel_for_ordered_messages.cpp
@@ -1,9 +1,14 @@
 // RUN: %clang_cc1 -verify -fopenmp %s
+// RUN: %clang_cc1 -verify -fopenmp -std=c++98 %s
+// RUN: %clang_cc1 -verify -fopenmp -std=c++11 %s
 
 void foo() {
 }
 
 bool foobool(int argc) {
+#if __cplusplus >= 201103L
+// expected-note@-2 4 {{declared here}}
+#endif
   return argc;
 }
 
@@ -36,6 +41,9 @@
 #pragma omp target parallel for ordered((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'ordered' clause}}
   for (int i = ST; i < N; i++)
 argv[0][i] = argv[0][i] - argv[0][i - ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp target parallel for', but found only 1}}
+#if __cplusplus >= 201103L
+// expected-note@+5 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
+#endif
 // expected-error@+3 2 {{directive '#pragma omp target parallel for' cannot contain more than one 'ordered' clause}}
 // expected-error@+2 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
 // expected-error@+1 2 {{expression is not an integral constant expression}}
@@ -45,7 +53,11 @@
 #pragma omp target parallel for ordered(S) // expected-error {{'S' does not refer to a value}}
   for (int i = ST; i < N; i++)
 argv[0][i] = argv[0][i] - argv[0][i - ST];
-// expected-error@+1 2 {{expression is not an integral constant expression}}
+#if __cplusplus >= 201103L
+  // expected-error@+4 2 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
+#else
+  // expected-error@+2 2 {{expression is not an integral constant expression}}
+#endif
 #pragma omp target parallel for ordered(argv[1] = 2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
   for (int i = ST; i < N; i++)
 argv[0][i] = argv[0][i] - argv[0][i - ST];
@@ -76,9 +88,15 @@
 #pragma omp target parallel for ordered(2 + 2))  // expected-warning {{extra tokens at the end of '#pragma omp target parallel for' are ignored}}  expected-note {{as specified in 'ordered' clause}}
   for (int i = 4; i < 12; i++)
 argv[0][i] = argv[0][i] - argv[0][i - 4];// expected-error {{expected 4 for loops after '#pragma omp target parallel for', but found only 1}}
+#if __cplusplus >= 201103L
+// expected-note@+2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
+#endif
 #pragma omp target parallel for ordered(foobool(1) > 0 ? 1 : 2) // expected-error {{expression is not an integral constant expression}}
   for (int i = 4; i < 12; i++)
 argv[0][i] = argv[0][i] - argv[0][i - 4];
+#if __cplusplus >= 201103L
+// expected-note@+5 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
+#endif
 // expected-error@+3 {{expression is not an integral constant expression}}
 // expected-error@+2 2 {{directive '#pragma omp target parallel for' cannot contain more than one 'ordered' clause}}
 // expected-error@+1 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
@@ -88,7 +106,11 @@
 #pragma omp target parallel for ordered(S1) // expected-error {{'S1' does not refer to a value}}
   for (int i = 4; i < 12; i++)
 argv[0][i] = argv[0][i] - argv[0][i - 4];
-// expected-error@+1 {{expression is not an integral constant expression}}
+#if __cplusplus >= 201103L
+  // expected-error@+4 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
+#else
+  // expected-error@+2 {{expression is not an integral constant expression}}
+#endif
 #pragma omp target parallel for ordered(argv[1] = 2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
   for (int i = 4; i < 12; i++)
 argv[0][i] = argv[0][i] - argv[0][i - 4];
Index: test/OpenMP/target_parallel_for_collapse_messages.cpp
=

[PATCH] D24812: Lit C++11 Compatibility Patch #11

2017-02-02 Thread Charles Li via Phabricator via cfe-commits
tigerleapgorge updated this revision to Diff 86923.
tigerleapgorge added a comment.

Revise again,

https://reviews.llvm.org/D28425 fixed 7 tests.
r290229 fixed 1 test.

Down to 8 tests.


https://reviews.llvm.org/D24812

Files:
  test/CodeGenCXX/linetable-cleanup.cpp
  test/CodeGenCXX/lpad-linetable.cpp
  test/CodeGenCXX/mangle-unnamed.cpp
  test/CodeGenCXX/static-init.cpp
  test/CodeGenCXX/volatile-1.cpp
  test/CodeGenCXX/volatile.cpp
  test/Index/comment-cplus-decls.cpp
  test/PCH/macro-undef.cpp

Index: test/PCH/macro-undef.cpp
===
--- test/PCH/macro-undef.cpp
+++ test/PCH/macro-undef.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fsyntax-only -include-pch %t %s -Wuninitialized -verify
-// RUN: %clang_cc1 -fsyntax-only -include-pch %t %s -Wuninitialized -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -std=c++98 -emit-pch -o %t %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -include-pch %t %s -Wuninitialized -verify
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -include-pch %t %s -Wuninitialized -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
 
 #ifndef HEADER
 #define HEADER
Index: test/Index/comment-cplus-decls.cpp
===
--- test/Index/comment-cplus-decls.cpp
+++ test/Index/comment-cplus-decls.cpp
@@ -2,9 +2,15 @@
 // RUN: mkdir %t
 // RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng -target x86_64-apple-darwin10 %s > %t/out
 // RUN: FileCheck %s < %t/out
+// RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng -target x86_64-apple-darwin10 -std=c++98 %s > %t/98
+// RUN: FileCheck %s < %t/98
+// RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng -target x86_64-apple-darwin10 -std=c++11 %s > %t/11
+// RUN: FileCheck %s < %t/11
 
 // Ensure that XML we generate is not invalid.
 // RUN: FileCheck %s -check-prefix=WRONG < %t/out
+// RUN: FileCheck %s -check-prefix=WRONG < %t/98
+// RUN: FileCheck %s -check-prefix=WRONG < %t/11
 // WRONG-NOT: CommentXMLInvalid
 // rdar://12378714
 
@@ -42,7 +48,7 @@
 // CHECK: class Test {}
 // CHECK: Test() : reserved(new Test::data()) {}
 // CHECK: unsigned int getID() const
-// CHECK: ~Test()
+// CHECK: ~Test(){{( noexcept)?}}
 // CHECK: Test::data *reserved
 
 
Index: test/CodeGenCXX/volatile.cpp
===
--- test/CodeGenCXX/volatile.cpp
+++ test/CodeGenCXX/volatile.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -std=c++98 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -std=c++11 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
 
 // Check that IR gen doesn't try to do an lvalue-to-rvalue conversion
 // on a volatile reference result.  rdar://problem/8338198
@@ -27,6 +28,7 @@
   // CHECK-LABEL: define void @_ZN5test14testEv()
   void test() {
 // CHECK:  [[TMP:%.*]] = load i32*, i32** @_ZN5test11xE, align 8
+// CHECK11:{{%.*}} = load volatile i32, i32* [[TMP]], align 4
 // CHECK-NEXT: ret void
 *x;
   }
Index: test/CodeGenCXX/volatile-1.cpp
===
--- test/CodeGenCXX/volatile-1.cpp
+++ test/CodeGenCXX/volatile-1.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -Wno-unused-value -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -Wno-unused-value -triple %itanium_abi_triple -emit-llvm %s -std=c++98 -o - | FileCheck %s
+// RUN: %clang_cc1 -Wno-unused-value -triple %itanium_abi_triple -emit-llvm %s -std=c++11 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
 
 // CHECK: @i = global [[INT:i[0-9]+]] 0
 volatile int i, j, k;
@@ -22,18 +23,22 @@
 
   asm("nop"); // CHECK: call void asm
 
-  // should not load
+  // should not load in C++98
   i;
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* @i
 
   (float)(ci);
   // CHECK-NEXT: load volatile [[INT]], [[INT]]* getelementptr inbounds ([[CINT]], [[CINT]]* @ci, i32 0, i32 0)
   // CHECK-NEXT: load volatile [[INT]], [[INT]]* getelementptr inbounds ([[CINT]], [[CINT]]* @ci, i32 0, i32 1)
   // CHECK-NEXT: sitofp [[INT]]
 
-  // These are not uses in C++:
+  // These are not uses in C++98:
   //   [expr.static.cast]p6:
   // The lvalue-to-rvalue . . . conversions are not applied to the expression.
   (void)ci;
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* getelementptr inbounds ([[CINT]], [[CINT]]* @ci, i32 0, i32 0)
+  // CHECK11-NEXT: load volatile [[INT]], [[INT]]* getelementptr inbounds ([[CINT]], [[CINT]]* @ci, i32 0, i32 1)
+
   (void)a;
 
   (void)(ci=ci);
@@ -126,7 +131,8 @@
   // CHECK-NEXT: load volatile
   // CHECK-NEX

[PATCH] D29479: Driver: Do not warn about unused -pthread when linking on darwin

2017-02-02 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB created this revision.
Herald added a subscriber: mcrosier.

While there is nothing to do at link time to get pthreads support on
darwin, specifying -pthread is fine and should not produce a warning
about unused arguments.


Repository:
  rL LLVM

https://reviews.llvm.org/D29479

Files:
  lib/Driver/Tools.cpp
  test/Driver/darwin-ld-pthread.c


Index: test/Driver/darwin-ld-pthread.c
===
--- /dev/null
+++ test/Driver/darwin-ld-pthread.c
@@ -0,0 +1,5 @@
+// RUN: %clang -target x86_64-apple-darwin -c -o %t.o %s
+// RUN: %clang -Wunused-command-line-argument -pthread -target 
x86_64-apple-darwin -### %t.o -o %t.bin 2>&1 | FileCheck %s
+
+// There is nothing to do at link time to get pthread support. But do not warn.
+// CHECK-NOT: argument unused during compilation: '-pthread'
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8718,6 +8718,9 @@
 }
   }
 
+  // No need to do anything for pthreads. Claim argument to avoid warning.
+  Args.ClaimAllArgs(options::OPT_pthread);
+
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   std::unique_ptr Cmd =
   llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs);


Index: test/Driver/darwin-ld-pthread.c
===
--- /dev/null
+++ test/Driver/darwin-ld-pthread.c
@@ -0,0 +1,5 @@
+// RUN: %clang -target x86_64-apple-darwin -c -o %t.o %s
+// RUN: %clang -Wunused-command-line-argument -pthread -target x86_64-apple-darwin -### %t.o -o %t.bin 2>&1 | FileCheck %s
+
+// There is nothing to do at link time to get pthread support. But do not warn.
+// CHECK-NOT: argument unused during compilation: '-pthread'
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8718,6 +8718,9 @@
 }
   }
 
+  // No need to do anything for pthreads. Claim argument to avoid warning.
+  Args.ClaimAllArgs(options::OPT_pthread);
+
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   std::unique_ptr Cmd =
   llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29476: Driver: Do not warn about unused -pthread when linking on darwin

2017-02-02 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB abandoned this revision.
MatzeB added a comment.

Abandoning in favor of https://reviews.llvm.org/D29479 because phabricator...


Repository:
  rL LLVM

https://reviews.llvm.org/D29476



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


Re: [PATCH] D29476: Driver: Do not warn about unused -pthread when linking on darwin

2017-02-02 Thread Duncan P. N. Exon Smith via cfe-commits
I think you need to close this phabricator revision and create a new one to get 
your initial comments and the patch onto cfe-commits.

> On 2017-Feb-02, at 16:18, Matthias Braun via Phabricator 
>  wrote:
> 
> MatzeB added a subscriber: cfe-commits.
> MatzeB added a comment.
> 
> Add cfe-commits.
> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D29476
> 
> 
> 

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


[PATCH] D25556: [Sema] Add variable captured by a block to the enclosing lambda's potential capture list

2017-02-02 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 86918.
ahatanak added a comment.

Rebase


https://reviews.llvm.org/D25556

Files:
  include/clang/Sema/Sema.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaObjCXX/blocks.mm


Index: test/SemaObjCXX/blocks.mm
===
--- test/SemaObjCXX/blocks.mm
+++ test/SemaObjCXX/blocks.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class 
-std=c++14 %s
 @protocol NSObject;
 
 void bar(id(^)(void));
@@ -144,3 +144,14 @@
 
   template void f(X);
 }
+
+namespace GenericLambdaCapture {
+  int test(int outerp) {
+auto lambda =[&](auto p) {
+  return ^{
+return p + outerp;
+  }();
+};
+return lambda(1);
+  }
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14273,8 +14273,9 @@
 (SemaRef.CurContext != Var->getDeclContext() &&
  Var->getDeclContext()->isFunctionOrMethod() && 
Var->hasLocalStorage());
 if (RefersToEnclosingScope) {
-  if (LambdaScopeInfo *const LSI =
-  SemaRef.getCurLambda(/*IgnoreCapturedRegions=*/true)) {
+  LambdaScopeInfo *const LSI =
+  SemaRef.getCurLambda(/*IgnoreNonLambdaCapturingScope=*/true);
+  if (LSI && !LSI->CallOperator->Encloses(Var->getDeclContext())) {
 // If a variable could potentially be odr-used, defer marking it so
 // until we finish analyzing the full expression for any
 // lvalue-to-rvalue
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1243,14 +1243,14 @@
   return CurBSI;
 }
 
-LambdaScopeInfo *Sema::getCurLambda(bool IgnoreCapturedRegions) {
+LambdaScopeInfo *Sema::getCurLambda(bool IgnoreNonLambdaCapturingScope) {
   if (FunctionScopes.empty())
 return nullptr;
 
   auto I = FunctionScopes.rbegin();
-  if (IgnoreCapturedRegions) {
+  if (IgnoreNonLambdaCapturingScope) {
 auto E = FunctionScopes.rend();
-while (I != E && isa(*I))
+while (I != E && isa(*I) && !isa(*I))
   ++I;
 if (I == E)
   return nullptr;
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -1235,9 +1235,11 @@
   sema::BlockScopeInfo *getCurBlock();
 
   /// Retrieve the current lambda scope info, if any.
-  /// \param IgnoreCapturedRegions true if should find the top-most lambda 
scope
-  /// info ignoring all inner captured regions scope infos.
-  sema::LambdaScopeInfo *getCurLambda(bool IgnoreCapturedRegions = false);
+  /// \param IgnoreNonLambdaCapturingScope true if should find the top-most
+  /// lambda scope info ignoring all inner capturing scopes that are not
+  /// lambda scopes.
+  sema::LambdaScopeInfo *
+  getCurLambda(bool IgnoreNonLambdaCapturingScope = false);
 
   /// \brief Retrieve the current generic lambda info, if any.
   sema::LambdaScopeInfo *getCurGenericLambda();


Index: test/SemaObjCXX/blocks.mm
===
--- test/SemaObjCXX/blocks.mm
+++ test/SemaObjCXX/blocks.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class -std=c++14 %s
 @protocol NSObject;
 
 void bar(id(^)(void));
@@ -144,3 +144,14 @@
 
   template void f(X);
 }
+
+namespace GenericLambdaCapture {
+  int test(int outerp) {
+auto lambda =[&](auto p) {
+  return ^{
+return p + outerp;
+  }();
+};
+return lambda(1);
+  }
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14273,8 +14273,9 @@
 (SemaRef.CurContext != Var->getDeclContext() &&
  Var->getDeclContext()->isFunctionOrMethod() && Var->hasLocalStorage());
 if (RefersToEnclosingScope) {
-  if (LambdaScopeInfo *const LSI =
-  SemaRef.getCurLambda(/*IgnoreCapturedRegions=*/true)) {
+  LambdaScopeInfo *const LSI =
+  SemaRef.getCurLambda(/*IgnoreNonLambdaCapturingScope=*/true);
+  if (LSI && !LSI->CallOperator->Encloses(Var->getDeclContext())) {
 // If a variable could potentially be odr-used, defer marking it so
 // until we finish analyzing the full expression for any
 // lvalue-to-rvalue
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1243,14 +1243,14 @@
   return CurBSI;
 }
 
-LambdaScopeInfo *Sema::getCurLambda(bool IgnoreCapturedRegions) {
+LambdaScopeInfo *Sema::getCurLambda(bool IgnoreNonLambdaCapturingScope) {
   if (FunctionScopes.empty())
 return n

[PATCH] D28365: [Driver] Updated for Visual Studio 2017

2017-02-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Doesn't your fix mean that the tests will fail on a Windows machine that 
doesn't have VS because LLVM was built with mingw? Usually in these situations 
we provide some way to provide a fake toolchain.


https://reviews.llvm.org/D28365



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


[PATCH] D29469: Fix PR31843: Clang-4.0 crashes/assert while evaluating __builtin_object_size

2017-02-02 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

>   My concern with that approach is that we'd just end up playing whack-a-bug. 
> It's possible that this fix puts us in a similar situation, but I'm honestly 
> at a loss for a better approach. ¯\_(ツ)_/¯ (...And I'd kinda prefer to play 
> whack-a-bug with "clang could do a better job in this case" reports, rather 
> than "clang crashes on my code" reports.)

Agree, thanks :)

This patch LGTM but I have little confidence in myself in this area of the 
compiler, so I rather have someone else stamping it!


https://reviews.llvm.org/D29469



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


[PATCH] D29476: Driver: Do not warn about unused -pthread when linking on darwin

2017-02-02 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB added a subscriber: cfe-commits.
MatzeB added a comment.

Add cfe-commits.


Repository:
  rL LLVM

https://reviews.llvm.org/D29476



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


[PATCH] D28365: [Driver] Updated for Visual Studio 2017

2017-02-02 Thread Hamza Sood via Phabricator via cfe-commits
hamzasood updated this revision to Diff 86900.
hamzasood added a comment.

In https://reviews.llvm.org/D28365#665183, @rnk wrote:

> I had to revert this because it doesn't pass tests on Linux. Can you look 
> into that and resubmit after fixing those test failures?


Really sorry about that, I stupidly only ran the tests on Windows.
The problem was caused by a change in behaviour when Clang is unable to find a 
Visual Studio installation. This patch made it emit an error and abort 
compilation in an attempt to be user friendly, which interferes with some tests 
if triggered (e.g. on Linux where there's no Visual Studio to find).
I've updated it to only emit a warning and continue compilation as usual, which 
seemed like a better option than removing it completely.


https://reviews.llvm.org/D28365

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/MSVCToolChain.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp
  test/Driver/cl-link-at-file.c

Index: test/Driver/cl-link-at-file.c
===
--- test/Driver/cl-link-at-file.c
+++ test/Driver/cl-link-at-file.c
@@ -13,7 +13,6 @@
 // be clueless and will emit "argument unused" warnings. If PR17239 is properly
 // fixed, this should not happen because the "/link" option is restricted to
 // consume only remaining args in its response file.
-// ARGS-NOT: warning
 // ARGS-NOT: argument unused during compilation
 // Identify the linker command
 // ARGS: link.exe
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -10888,19 +10888,12 @@
 // making sure that whatever executable that's found is not a same-named exe
 // from clang itself to prevent clang from falling back to itself.
 static std::string FindVisualStudioExecutable(const ToolChain &TC,
-  const char *Exe,
-  const char *ClangProgramPath) {
+  const char *Exe) {
   const auto &MSVC = static_cast(TC);
-  std::string visualStudioBinDir;
-  if (MSVC.getVisualStudioBinariesFolder(ClangProgramPath,
- visualStudioBinDir)) {
-SmallString<128> FilePath(visualStudioBinDir);
-llvm::sys::path::append(FilePath, Exe);
-if (llvm::sys::fs::can_execute(FilePath.c_str()))
-  return FilePath.str();
-  }
-
-  return Exe;
+  SmallString<128> FilePath(MSVC.getSubDirectoryPath(toolchains::MSVCToolChain
+ ::SubDirectoryType::Bin));
+  llvm::sys::path::append(FilePath, Exe);
+  return (llvm::sys::fs::can_execute(FilePath) ? FilePath.str() : Exe);
 }
 
 void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
@@ -10909,7 +10902,7 @@
 const ArgList &Args,
 const char *LinkingOutput) const {
   ArgStringList CmdArgs;
-  const ToolChain &TC = getToolChain();
+  auto &TC = static_cast(getToolChain());
 
   assert((Output.isFilename() || Output.isNothing()) && "invalid output");
   if (Output.isFilename())
@@ -10925,37 +10918,20 @@
 // did not run vcvarsall), try to build a consistent link environment.  If
 // the environment variable is set however, assume the user knows what
 // they're doing.
-std::string VisualStudioDir;
-const auto &MSVC = static_cast(TC);
-if (MSVC.getVisualStudioInstallDir(VisualStudioDir)) {
-  SmallString<128> LibDir(VisualStudioDir);
-  llvm::sys::path::append(LibDir, "VC", "lib");
-  switch (MSVC.getArch()) {
-  case llvm::Triple::x86:
-// x86 just puts the libraries directly in lib
-break;
-  case llvm::Triple::x86_64:
-llvm::sys::path::append(LibDir, "amd64");
-break;
-  case llvm::Triple::arm:
-llvm::sys::path::append(LibDir, "arm");
-break;
-  default:
-break;
-  }
-  CmdArgs.push_back(
-  Args.MakeArgString(std::string("-libpath:") + LibDir.c_str()));
+CmdArgs.push_back(Args.MakeArgString(
+  std::string("-libpath:")
+  + TC.getSubDirectoryPath(toolchains::MSVCToolChain
+   ::SubDirectoryType::Lib)));
 
-  if (MSVC.useUniversalCRT(VisualStudioDir)) {
-std::string UniversalCRTLibPath;
-if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath))
-  CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
-   UniversalCRTLibPath));
-  }
+if (TC.useUniversalCRT()) {
+  std::string UniversalCRTLibPath;
+  if (TC.getUniversalCRTLibraryPath(UniversalCRTLibPath))
+CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:")
+ + UniversalCRTLibP

[PATCH] D28526: [ARM] Add diagnostics when initialization global variables with ropi/rwpi

2017-02-02 Thread Weiming Zhao via Phabricator via cfe-commits
weimingz added a comment.

ping ?


https://reviews.llvm.org/D28526



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


[PATCH] D28365: [Driver] Updated for Visual Studio 2017

2017-02-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I had to revert this because it doesn't pass tests on Linux. Can you look into 
that and resubmit after fixing those test failures?


Repository:
  rL LLVM

https://reviews.llvm.org/D28365



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


[PATCH] D29469: Fix PR31843: Clang-4.0 crashes/assert while evaluating __builtin_object_size

2017-02-02 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv created this revision.

We're currently using a special EvaluationMode to determine whether
we're OK with invalid base expressions during objectsize evaluation.
Using it to figure out how we handle UB/etc. is fine, but I think it's
too far-reaching to use for checking whether we're OK with an invalid
base expression. This is because an EvaluationMode applies by default to
all subexpressions of the expression we're evaluating, which causes
issues like in https://llvm.org/bugs/show_bug.cgi?id=31843 .

What I think we actually want to do is allow this relaxed behavior only
for "top-level" member/pointer expressions. In other words, we should
only allow it when we're evaluating the top-level pointers/lvalues
involved in an expression. As soon as we need to evaluate something else
(an int, ...), we should drop these relaxed rules and go back to
stricter evaluation. For example, in:

foo(whatever->a ? b() : 1)->bar->baz.quux

We don't care if `whatever->a` is evaluated using these relaxed rules,
since the only invalid base that's actually useful to the objectsize
evaluator is `foo(...)->bar`.

...As a lower level issue, one idea I had to make this less awkward was
to just define `EvaluatePointer(const Expr *, LValue&, EvalInfo&)` as a
method on LValueExprEvaluator/PointerExprEvaluator that called
::EvaluatePointer with the right fourth arg, but that seemed a bit too
subtle to me. Happy to swap to it if you think it's better.

Finally, if we make this change, ISTM we can just replace OffsetFold
with ConstantFold. I'd rather to that in another patch, since whatever
we choose to do here gets put into 4.0.

--

With all of that said, if we want the minimal fix for PR31843, it's
adding an `InvalidBase` check or two to Evaluate. My concern with that
approach is that we'd just end up playing whack-a-bug. It's possible
that this fix puts us in a similar situation, but I'm honestly at a loss
for a better approach. ¯\_(ツ)_/¯ (...And I'd kinda prefer to play
whack-a-bug with "clang could do a better job in this case" reports,
rather than "clang crashes on my code" reports.)


https://reviews.llvm.org/D29469

Files:
  lib/AST/ExprConstant.cpp
  test/CodeGen/object-size.c
  test/Sema/builtin-object-size.c

Index: test/Sema/builtin-object-size.c
===
--- test/Sema/builtin-object-size.c
+++ test/Sema/builtin-object-size.c
@@ -76,3 +76,18 @@
   a += __builtin_object_size(p3->b, 0);
   return a;
 }
+
+int pr31843() {
+  int n = 0;
+
+  struct { int f; } a;
+  int b;
+  n += __builtin_object_size(({&(b ? &a : &a)->f; pr31843;}), 0); // expected-warning{{expression result unused}}
+
+  struct statfs { char f_mntonname[1024];};
+  struct statfs *outStatFSBuf;
+  n += __builtin_object_size(outStatFSBuf->f_mntonname ? "" : "", 1); // expected-warning{{address of array}}
+  n += __builtin_object_size(outStatFSBuf->f_mntonname ?: "", 1);
+
+  return n;
+}
Index: test/CodeGen/object-size.c
===
--- test/CodeGen/object-size.c
+++ test/CodeGen/object-size.c
@@ -549,3 +549,22 @@
   // CHECK: store i32 0
   gi = __builtin_object_size(incomplete_char_array, 3);
 }
+
+// Flips between the pointer and lvalue evaluator a lot.
+void deeply_nested() {
+  struct {
+struct {
+  struct {
+struct {
+  int e[2];
+  char f; // Inhibit our writing-off-the-end check
+} d[2];
+  } c[2];
+} b[2];
+  } *a;
+
+  // CHECK: store i32 4
+  gi = __builtin_object_size(&a->b[1].c[1].d[1].e[1], 1);
+  // CHECK: store i32 4
+  gi = __builtin_object_size(&a->b[1].c[1].d[1].e[1], 3);
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -604,10 +604,13 @@
   /// gets a chance to look at it.
   EM_PotentialConstantExpressionUnevaluated,
 
-  /// Evaluate as a constant expression. Continue evaluating if either:
-  /// - We find a MemberExpr with a base that can't be evaluated.
+  /// Evaluate as a constant expression. In certain scenarios, if:
+  /// - We find a MemberExpr with a base that can't be evaluated, or
   /// - We find a variable initialized with a call to a function that has
-  ///   the alloc_size attribute on it.
+  ///   the alloc_size attribute on it
+  ///
+  /// Then we may consider evaluation to have succeeded.
+  ///
   /// In either case, the LValue returned shall have an invalid base; in the
   /// former, the base will be the invalid MemberExpr, in the latter, the
   /// base will be either the alloc_size CallExpr or a CastExpr wrapping
@@ -890,10 +893,6 @@
   return KeepGoing;
 }
 
-bool allowInvalidBaseExpr() const {
-  return EvalMode == EM_OffsetFold;
-}
-
 class ArrayInitLoopIndex {
   EvalInfo &Info;
   uint64_t OuterIndex;
@@ -1394,8 +1393,10 @@
 

Re: Add warning for c++ member variable shadowing

2017-02-02 Thread Richard Smith via cfe-commits
Thanks, James! I think I have only one more substantive comment:

+  (Field->getAccess() == AS_public || Field->getAccess() ==
AS_protected)) {

Have you considered also taking into account the access of the inheritance
path? Eg, a public member of a private base class of a public base class is
typically inaccessible, even though it was declared public:

  struct A { int n; };
  struct B : private A {};
  struct C : B { int n; }; // A::n is not accessible here, should we
suppress the warning?

You can use CXXRecordDecl::MergeAccess to combine the access of the path
with the access of the field and compute the effective access of the field
in the derived class (and you should test to see if the resulting access is
AS_None to tell if the field is inaccessible; fields with effective access
of AS_Private -- such as public members of a private direct base class --
are accessible from the derived class). You'll need to set RecordPaths to
true in the CXXBasePaths object in order for lookupInBases to compute the
path access.

Oh, and you may as well use a range-based for loop here:

+auto Result = Base->lookup(FieldName);
+for (auto I = Result.begin(); I != Result.end(); ++I) {


On 2 February 2017 at 00:19, James Sun  wrote:

> Hi Richard
>
>
>
> Thanks for the feedback! Hopefully addressed!
>
>
>
> Thanks
>
>
>
> James
>
>
>
>
>
>
>
> *From: * on behalf of Richard Smith <
> rich...@metafoo.co.uk>
> *Date: *Wednesday, February 1, 2017 at 3:50 PM
> *To: *James Sun 
>
> *Cc: *Saleem Abdulrasool , "
> cfe-commits@lists.llvm.org" , Aaron Ballman <
> aa...@aaronballman.com>
> *Subject: *Re: Add warning for c++ member variable shadowing
>
>
>
> +  std::set bases;
>
> +const auto baseName = Specifier->getType()->
> getAsCXXRecordDecl()->getName();
>
>
>
> Please capitalize local variable names. Also, please don't use the record
> name as a key in your set; that's not guaranteed to be unique. Instead, you
> could either use a set of canonical types or of canonical CXXRecordDecl*s.
>
>
>
> +for (const auto *Field : Specifier->getType()->
> getAsCXXRecordDecl()->fields()) {
>
> +  if ((Field->getAccess() == AS_public || Field->getAccess() ==
> AS_protected) &&
>
> +  Field->getName() == FieldName) {
>
>
>
> Use Specifier->getType()->getAsCXXRecordDecl()->lookup(Field->getName())
> here to look up the field by name, rather than walking all the fields of
> all base classes and checking if each of them has the right name. You
> should also check for IndirectFieldDecls, for this case:
>
>
>
>   struct A {
>
> union { int x; float f; };
>
>   };
>
>   struct B : A {
>
> int x;
>
>   };
>
>
>
> +bases.emplace(baseName);
>
>
>
> It's more efficient to use insert rather than emplace when inserting an
> element into a set.
>
>
>
> +Diag(Loc, diag::warn_shadow_field)
>
> +  << FieldName << RD->getName() << baseName;
>
>
>
> It'd be nice to add a note here pointing at the base class member that was
> shadowed.
>
>
>
>
>
>
>
> On 31 January 2017 at 19:20, James Sun  wrote:
>
> Fixed!
>
>
>
> *From: *Saleem Abdulrasool 
> *Date: *Tuesday, January 31, 2017 at 6:53 PM
>
>
> *To: *James Sun 
> *Cc: *Richard Smith , "cfe-commits@lists.llvm.org"
> , Aaron Ballman 
> *Subject: *Re: Add warning for c++ member variable shadowing
>
>
>
> Hmm, the braces in the if (bases.find(...)...) are not needed.
>
>
>
> Could you also add a test case for virtual inheritance?
>
>
>
> On Mon, Jan 30, 2017 at 8:34 PM, James Sun  wrote:
>
> Hi Saleem
>
>
>
> Thanks for the quick response. A test case is added. It covers some
> ordinary cases as well as corner cases like multiple paths to the same base.
>
>
>
> Thanks
>
>
>
> James
>
>
>
> *From: *Saleem Abdulrasool 
> *Date: *Monday, January 30, 2017 at 6:50 PM
> *To: *James Sun 
> *Cc: *Richard Smith , "cfe-commits@lists.llvm.org"
> , Aaron Ballman 
>
>
> *Subject: *Re: Add warning for c++ member variable shadowing
>
>
>
> I think that the patch is starting to look pretty good!
>
>
>
> Can you add some test cases for the particular cases to diagnose in a
> separate test set to ensure that we have proper coverage of the various
> cases rather than relying on the existing test cases?  Something to make
> sure that we get the simple case right as well as the complex cases (e.g.
> we don't print duplicate warnings for multiple paths).
>
>
>
>
>
> On Mon, Jan 30, 2017 at 5:50 PM, James Sun  wrote:
>
> Hi Richard
>
>
>
> Sorry for the late reply. Thank you for giving the feedback! The updated
> version is attached. Please let me know if there is anything improper.
>
>
>
> Thanks
>
>
>
> James
>
>
>
> *From: * on behalf of Richard Smith <
> rich...@metafoo.co.uk>
> *Date: *Friday, January 27, 2017 at 3:03 PM
> *To: *James Sun 
> *Cc: *Saleem Abdulrasool , "
> cfe-commits@lists.llvm.org" , Aaron Ballman <
> aa...@aaronballman.com>
>
>
> *Subject: *Re: Add warning for c++ member variable shadowing
>
>
>
> +def warn_shadow_member_variable : Warning<
>
>

Re: [clang-tools-extra] r293909 - [change-namespace] fix unscoped enum constant references.

2017-02-02 Thread Eric Liu via cfe-commits
r293927 should appease bots.

On Thu, Feb 2, 2017 at 7:59 PM Eric Liu  wrote:

This is breaking build bots, and I am trying to fix it. Feel free to revert
the change if this blocks you.

On Thu, Feb 2, 2017 at 6:51 PM Eric Liu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

Author: ioeric
Date: Thu Feb  2 11:40:38 2017
New Revision: 293909

URL: http://llvm.org/viewvc/llvm-project?rev=293909&view=rev
Log:
[change-namespace] fix unscoped enum constant references.

Reviewers: bkramer

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp

clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL:
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=293909&r1=293908&r2=293909&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Feb  2
11:40:38 2017
@@ -282,6 +282,10 @@ bool isDeclVisibleAtLocation(const Sourc
   isNestedDeclContext(DeclCtx, D->getDeclContext()));
 }

+AST_MATCHER(EnumDecl, isScoped) {
+return Node.isScoped();
+}
+
 } // anonymous namespace

 ChangeNamespaceTool::ChangeNamespaceTool(
@@ -454,6 +458,17 @@ void ChangeNamespaceTool::registerMatche
  to(GlobalVarMatcher.bind("var_decl")))
  .bind("var_ref"),
  this);
+
+  // Handle unscoped enum constant.
+  auto UnscopedEnumMatcher = enumConstantDecl(hasParent(enumDecl(
+  hasParent(namespaceDecl()),
+  unless(anyOf(isScoped(), IsInMovedNs, hasAncestor(cxxRecordDecl()),
+   hasAncestor(namespaceDecl(isAnonymous(;
+  Finder->addMatcher(
+  declRefExpr(IsInMovedNs, hasAncestor(decl().bind("dc")),
+  to(UnscopedEnumMatcher.bind("enum_const_decl")))
+  .bind("enum_const_ref"),
+  this);
 }

 void ChangeNamespaceTool::run(
@@ -518,6 +533,21 @@ void ChangeNamespaceTool::run(
 assert(Context && "Empty decl context.");
 fixDeclRefExpr(Result, Context->getDeclContext(),
llvm::cast(Var), VarRef);
+  } else if (const auto *EnumConstRef =
+ Result.Nodes.getNodeAs("enum_const_ref")) {
+// Do not rename the reference if it is already scoped by the EnumDecl
name.
+if (EnumConstRef->hasQualifier() &&
+EnumConstRef->getQualifier()->getAsType()->isEnumeralType())
+  return;
+const auto *EnumConstDecl =
+Result.Nodes.getNodeAs("enum_const_decl");
+assert(EnumConstDecl);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+// FIXME: this would qualify "ns::VALUE" as "ns::EnumValue::VALUE".
Fix it
+// if it turns out to be an issue.
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(EnumConstDecl), EnumConstRef);
   } else if (const auto *FuncRef =
  Result.Nodes.getNodeAs("func_ref")) {
 // If this reference has been processed as a function call, we do not

Modified:
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
URL:
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=293909&r1=293908&r2=293909&view=diff
==
---
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
(original)
+++
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
Thu Feb  2 11:40:38 2017
@@ -1774,6 +1774,207 @@ TEST_F(ChangeNamespaceTest, ShortenNames
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }

+TEST_F(ChangeNamespaceTest, SimpleMoveEnum) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "enum class X { X1, X2 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "\n\nnamespace x {\n"
+ "namespace y {\n"
+ "enum class X { X1, X2 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, ReferencesToEnums) {
+  std::string Code = "enum Glob { G1, G2 };\n"
+ "namespace na {\n"
+ "enum class X { X1 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  Glob g1 = Glob:

[clang-tools-extra] r293927 - [change-namespace] trying to fix build bot failure caused by r293909.

2017-02-02 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Feb  2 13:46:12 2017
New Revision: 293927

URL: http://llvm.org/viewvc/llvm-project?rev=293927&view=rev
Log:
[change-namespace] trying to fix build bot failure caused by r293909.

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=293927&r1=293926&r2=293927&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Feb  2 
13:46:12 2017
@@ -537,6 +537,8 @@ void ChangeNamespaceTool::run(
  Result.Nodes.getNodeAs("enum_const_ref")) {
 // Do not rename the reference if it is already scoped by the EnumDecl 
name.
 if (EnumConstRef->hasQualifier() &&
+EnumConstRef->getQualifier()->getKind() ==
+NestedNameSpecifier::SpecifierKind::TypeSpec &&
 EnumConstRef->getQualifier()->getAsType()->isEnumeralType())
   return;
 const auto *EnumConstDecl =


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


[PATCH] D29197: Avoid implementation defined behavior in a test.

2017-02-02 Thread Dan Albert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293926: Avoid implementation defined behavior in a test. 
(authored by danalbert).

Changed prior to commit:
  https://reviews.llvm.org/D29197?vs=85961&id=86866#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29197

Files:
  
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp


Index: 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
===
--- 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
+++ 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
@@ -38,6 +38,12 @@
 char str[50];
 output_iterator iter = f.put(output_iterator(str), ios, 
'*', v);
 std::string ex(str, iter.base());
-assert(ex == "0x0" || ex == "(nil)");
+char expected_str[32] = {};
+// num_put::put uses %p for pointer types, but the exact format of %p 
is
+// implementation defined behavior for the C library. Compare output to
+// snprintf for portability.
+int rc = snprintf(expected_str, sizeof(expected_str), "%p", v);
+assert(rc > 0);
+assert(ex == expected_str);
 }
 }


Index: libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
===
--- libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
+++ libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
@@ -38,6 +38,12 @@
 char str[50];
 output_iterator iter = f.put(output_iterator(str), ios, '*', v);
 std::string ex(str, iter.base());
-assert(ex == "0x0" || ex == "(nil)");
+char expected_str[32] = {};
+// num_put::put uses %p for pointer types, but the exact format of %p is
+// implementation defined behavior for the C library. Compare output to
+// snprintf for portability.
+int rc = snprintf(expected_str, sizeof(expected_str), "%p", v);
+assert(rc > 0);
+assert(ex == expected_str);
 }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r293926 - Avoid implementation defined behavior in a test.

2017-02-02 Thread Dan Albert via cfe-commits
Author: danalbert
Date: Thu Feb  2 13:44:11 2017
New Revision: 293926

URL: http://llvm.org/viewvc/llvm-project?rev=293926&view=rev
Log:
Avoid implementation defined behavior in a test.

Summary:
num_put::put uses %p for pointer types, but the exact format of %p is
implementation defined behavior for the C library. Compare output to
snprintf for portability.

Reviewers: EricWF, mclow.lists

Reviewed By: EricWF

Subscribers: cfe-commits

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

Modified:

libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp

Modified: 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp?rev=293926&r1=293925&r2=293926&view=diff
==
--- 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_pointer.pass.cpp
 Thu Feb  2 13:44:11 2017
@@ -38,6 +38,12 @@ int main()
 char str[50];
 output_iterator iter = f.put(output_iterator(str), ios, 
'*', v);
 std::string ex(str, iter.base());
-assert(ex == "0x0" || ex == "(nil)");
+char expected_str[32] = {};
+// num_put::put uses %p for pointer types, but the exact format of %p 
is
+// implementation defined behavior for the C library. Compare output to
+// snprintf for portability.
+int rc = snprintf(expected_str, sizeof(expected_str), "%p", v);
+assert(rc > 0);
+assert(ex == expected_str);
 }
 }


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


r293924 - Revert "[Driver] Updated for Visual Studio 2017"

2017-02-02 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Thu Feb  2 13:36:22 2017
New Revision: 293924

URL: http://llvm.org/viewvc/llvm-project?rev=293924&view=rev
Log:
Revert "[Driver] Updated for Visual Studio 2017"

This reverts commit r293923. It causes test failures on Linux that need
time to debug.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/lib/Driver/MSVCToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=293924&r1=293923&r2=293924&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Feb  2 13:36:22 
2017
@@ -281,8 +281,4 @@ def warn_drv_ps4_sdk_dir : Warning<
 def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker 
option">;
 def err_drv_defsym_invalid_format : Error<"defsym must be of the form: 
sym=value: %0">;
 def err_drv_defsym_invalid_symval : Error<"Value is not an integer: %0">;
-
-def err_drv_msvc_not_found : Error<
-  "unable to find a Visual Studio installation; "
-  "try running Clang from a developer command prompt">;
 }

Modified: cfe/trunk/lib/Driver/MSVCToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MSVCToolChain.cpp?rev=293924&r1=293923&r2=293924&view=diff
==
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp Thu Feb  2 13:36:22 2017
@@ -23,23 +23,16 @@
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include 
 
+// Include the necessary headers to interface with the Windows registry and
+// environment.
 #if defined(LLVM_ON_WIN32)
-  #define USE_WIN32
-
-  // FIXME: Make this configurable with cmake when the final version of the API
-  //has been released.
-  #if 0
-#define USE_VS_SETUP_CONFIG
-  #endif
+#define USE_WIN32
 #endif
 
-// Include the necessary headers to interface with the Windows registry and
-// environment.
 #ifdef USE_WIN32
   #define WIN32_LEAN_AND_MEAN
   #define NOGDI
@@ -49,265 +42,20 @@
   #include 
 #endif
 
-// Include the headers needed for the setup config COM stuff and define
-// smart pointers for the interfaces we need.
-#ifdef USE_VS_SETUP_CONFIG
-  #include "clang/Basic/VirtualFileSystem.h"
-  #include "llvm/Support/COM.h"
-  #include 
-  #include 
-  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration,  __uuidof(ISetupConfiguration));
-  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
-  _COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
-  _COM_SMARTPTR_TYPEDEF(IEnumSetupInstances,  __uuidof(IEnumSetupInstances));
-  _COM_SMARTPTR_TYPEDEF(ISetupInstance,   __uuidof(ISetupInstance));
-  _COM_SMARTPTR_TYPEDEF(ISetupInstance2,  __uuidof(ISetupInstance2));
-#endif
-
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
 using namespace clang;
 using namespace llvm::opt;
 
-// Defined below.
-// Forward declare this so there aren't too many things above the constructor.
-static bool getSystemRegistryString(const char *keyPath, const char *valueName,
-std::string &value, std::string *phValue);
-
-// Check various environment variables to try and find a toolchain.
-static bool findVCToolChainViaEnvironment(std::string &Path,
-  bool &IsVS2017OrNewer) {
-  // These variables are typically set by vcvarsall.bat
-  // when launching a developer command prompt.
-  if (llvm::Optional VCToolsInstallDir =
-  llvm::sys::Process::GetEnv("VCToolsInstallDir")) {
-// This is only set by newer Visual Studios, and it leads straight to
-// the toolchain directory.
-Path = std::move(*VCToolsInstallDir);
-IsVS2017OrNewer = true;
-return true;
-  }
-  if (llvm::Optional VCInstallDir =
-  llvm::sys::Process::GetEnv("VCINSTALLDIR")) {
-// If the previous variable isn't set but this one is, then we've found
-// an older Visual Studio. This variable is set by newer Visual Studios 
too,
-// so this check has to appear second.
-// In older Visual Studios, the VC directory is the toolchain.
-Path = std::move(*VCInstallDir);
-IsVS2017OrNewer = false;
-return true;
-  }
-
-  // We couldn't find any VC environment variables. Let's walk through PATH and
-  // see if it leads us to a VC toolchain bin directory. If it does, pick the
-  // first one that we find.
-  if (llvm::Optional PathEnv =
-  llvm::sys::Process::GetEnv("PATH")) {
-llvm::SmallVector PathE

[PATCH] D28365: [Driver] Updated for Visual Studio 2017

2017-02-02 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293923: [Driver] Updated for Visual Studio 2017 (authored by 
rnk).

Changed prior to commit:
  https://reviews.llvm.org/D28365?vs=86502&id=86865#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28365

Files:
  cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
  cfe/trunk/lib/Driver/MSVCToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains.h
  cfe/trunk/lib/Driver/Tools.cpp

Index: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
@@ -281,4 +281,8 @@
 def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker option">;
 def err_drv_defsym_invalid_format : Error<"defsym must be of the form: sym=value: %0">;
 def err_drv_defsym_invalid_symval : Error<"Value is not an integer: %0">;
+
+def err_drv_msvc_not_found : Error<
+  "unable to find a Visual Studio installation; "
+  "try running Clang from a developer command prompt">;
 }
Index: cfe/trunk/lib/Driver/MSVCToolChain.cpp
===
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp
@@ -23,16 +23,23 @@
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include 
 
-// Include the necessary headers to interface with the Windows registry and
-// environment.
 #if defined(LLVM_ON_WIN32)
-#define USE_WIN32
+  #define USE_WIN32
+
+  // FIXME: Make this configurable with cmake when the final version of the API
+  //has been released.
+  #if 0
+#define USE_VS_SETUP_CONFIG
+  #endif
 #endif
 
+// Include the necessary headers to interface with the Windows registry and
+// environment.
 #ifdef USE_WIN32
   #define WIN32_LEAN_AND_MEAN
   #define NOGDI
@@ -42,20 +49,265 @@
   #include 
 #endif
 
+// Include the headers needed for the setup config COM stuff and define
+// smart pointers for the interfaces we need.
+#ifdef USE_VS_SETUP_CONFIG
+  #include "clang/Basic/VirtualFileSystem.h"
+  #include "llvm/Support/COM.h"
+  #include 
+  #include 
+  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration,  __uuidof(ISetupConfiguration));
+  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+  _COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+  _COM_SMARTPTR_TYPEDEF(IEnumSetupInstances,  __uuidof(IEnumSetupInstances));
+  _COM_SMARTPTR_TYPEDEF(ISetupInstance,   __uuidof(ISetupInstance));
+  _COM_SMARTPTR_TYPEDEF(ISetupInstance2,  __uuidof(ISetupInstance2));
+#endif
+
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
 using namespace clang;
 using namespace llvm::opt;
 
-MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
+// Defined below.
+// Forward declare this so there aren't too many things above the constructor.
+static bool getSystemRegistryString(const char *keyPath, const char *valueName,
+std::string &value, std::string *phValue);
+
+// Check various environment variables to try and find a toolchain.
+static bool findVCToolChainViaEnvironment(std::string &Path,
+  bool &IsVS2017OrNewer) {
+  // These variables are typically set by vcvarsall.bat
+  // when launching a developer command prompt.
+  if (llvm::Optional VCToolsInstallDir =
+  llvm::sys::Process::GetEnv("VCToolsInstallDir")) {
+// This is only set by newer Visual Studios, and it leads straight to
+// the toolchain directory.
+Path = std::move(*VCToolsInstallDir);
+IsVS2017OrNewer = true;
+return true;
+  }
+  if (llvm::Optional VCInstallDir =
+  llvm::sys::Process::GetEnv("VCINSTALLDIR")) {
+// If the previous variable isn't set but this one is, then we've found
+// an older Visual Studio. This variable is set by newer Visual Studios too,
+// so this check has to appear second.
+// In older Visual Studios, the VC directory is the toolchain.
+Path = std::move(*VCInstallDir);
+IsVS2017OrNewer = false;
+return true;
+  }
+
+  // We couldn't find any VC environment variables. Let's walk through PATH and
+  // see if it leads us to a VC toolchain bin directory. If it does, pick the
+  // first one that we find.
+  if (llvm::Optional PathEnv =
+  llvm::sys::Process::GetEnv("PATH")) {
+llvm::SmallVector PathEntries;
+llvm::StringRef(*PathEnv).split(PathEntries, llvm::sys::EnvPathSeparator);
+for (llvm::StringRef PathEntry : PathEntries) {
+  if (PathEntry.empty())
+continue;
+
+  llvm::SmallString<256> ExeTestPath;
+
+  // If cl.exe doesn't exist, then this definitely isn't a VC to

r293923 - [Driver] Updated for Visual Studio 2017

2017-02-02 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Thu Feb  2 13:29:46 2017
New Revision: 293923

URL: http://llvm.org/viewvc/llvm-project?rev=293923&view=rev
Log:
[Driver] Updated for Visual Studio 2017

Summary:
The patch updates the MSVC ToolChain for the changes made in Visual
Studio 2017[1].

Other notable changes:
  - Path handling code has been centralised to make potential future
changes less painful.
  - A compiler error is emitted if the driver is unable to locate a
usable MSVC toolchain. (Previously it'd fail with a cryptic error
such as "link.exe is not executable")
  - Support for the new Setup Config Server API[2] has been added,
albeit block commented out with a preprocessor conditional. This can
probably be re-evaluated when the API is officially released (it's
currently at the RC stage), but it's left in to make it easy for
anyone familiar with the API to give it a go with Clang.

Patch by Hamza Sood.

[1] 
https://blogs.msdn.microsoft.com/vcblog/2016/10/07/compiler-tools-layout-in-visual-studio-15/
[2] 
https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/

Reviewers: ruiu, hans, rnk

Reviewed By: rnk

Subscribers: awson, RKSimon, amccarth, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/lib/Driver/MSVCToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=293923&r1=293922&r2=293923&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Feb  2 13:29:46 
2017
@@ -281,4 +281,8 @@ def warn_drv_ps4_sdk_dir : Warning<
 def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker 
option">;
 def err_drv_defsym_invalid_format : Error<"defsym must be of the form: 
sym=value: %0">;
 def err_drv_defsym_invalid_symval : Error<"Value is not an integer: %0">;
+
+def err_drv_msvc_not_found : Error<
+  "unable to find a Visual Studio installation; "
+  "try running Clang from a developer command prompt">;
 }

Modified: cfe/trunk/lib/Driver/MSVCToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MSVCToolChain.cpp?rev=293923&r1=293922&r2=293923&view=diff
==
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp Thu Feb  2 13:29:46 2017
@@ -23,16 +23,23 @@
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include 
 
-// Include the necessary headers to interface with the Windows registry and
-// environment.
 #if defined(LLVM_ON_WIN32)
-#define USE_WIN32
+  #define USE_WIN32
+
+  // FIXME: Make this configurable with cmake when the final version of the API
+  //has been released.
+  #if 0
+#define USE_VS_SETUP_CONFIG
+  #endif
 #endif
 
+// Include the necessary headers to interface with the Windows registry and
+// environment.
 #ifdef USE_WIN32
   #define WIN32_LEAN_AND_MEAN
   #define NOGDI
@@ -42,20 +49,265 @@
   #include 
 #endif
 
+// Include the headers needed for the setup config COM stuff and define
+// smart pointers for the interfaces we need.
+#ifdef USE_VS_SETUP_CONFIG
+  #include "clang/Basic/VirtualFileSystem.h"
+  #include "llvm/Support/COM.h"
+  #include 
+  #include 
+  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration,  __uuidof(ISetupConfiguration));
+  _COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
+  _COM_SMARTPTR_TYPEDEF(ISetupHelper, __uuidof(ISetupHelper));
+  _COM_SMARTPTR_TYPEDEF(IEnumSetupInstances,  __uuidof(IEnumSetupInstances));
+  _COM_SMARTPTR_TYPEDEF(ISetupInstance,   __uuidof(ISetupInstance));
+  _COM_SMARTPTR_TYPEDEF(ISetupInstance2,  __uuidof(ISetupInstance2));
+#endif
+
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
 using namespace clang;
 using namespace llvm::opt;
 
-MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
+// Defined below.
+// Forward declare this so there aren't too many things above the constructor.
+static bool getSystemRegistryString(const char *keyPath, const char *valueName,
+std::string &value, std::string *phValue);
+
+// Check various environment variables to try and find a toolchain.
+static bool findVCToolChainViaEnvironment(std::string &Path,
+  bool &IsVS2017OrNewer) {
+  // These variables are typically set by vcvarsall.bat
+  // when launching a developer co

[PATCH] D20561: Warn when taking address of packed member

2017-02-02 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

Yes, the project is interested on reducing the number of false positives. The 
example you gave is *not* a FP, but exactly the kind of situation the warning 
is supposed to trigger on.


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



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


Re: [clang-tools-extra] r293909 - [change-namespace] fix unscoped enum constant references.

2017-02-02 Thread Eric Liu via cfe-commits
This is breaking build bots, and I am trying to fix it. Feel free to revert
the change if this blocks you.

On Thu, Feb 2, 2017 at 6:51 PM Eric Liu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ioeric
> Date: Thu Feb  2 11:40:38 2017
> New Revision: 293909
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293909&view=rev
> Log:
> [change-namespace] fix unscoped enum constant references.
>
> Reviewers: bkramer
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D29460
>
> Modified:
> clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
>
> clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
>
> Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=293909&r1=293908&r2=293909&view=diff
>
> ==
> --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
> +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Feb
> 2 11:40:38 2017
> @@ -282,6 +282,10 @@ bool isDeclVisibleAtLocation(const Sourc
>isNestedDeclContext(DeclCtx, D->getDeclContext()));
>  }
>
> +AST_MATCHER(EnumDecl, isScoped) {
> +return Node.isScoped();
> +}
> +
>  } // anonymous namespace
>
>  ChangeNamespaceTool::ChangeNamespaceTool(
> @@ -454,6 +458,17 @@ void ChangeNamespaceTool::registerMatche
>   to(GlobalVarMatcher.bind("var_decl")))
>   .bind("var_ref"),
>   this);
> +
> +  // Handle unscoped enum constant.
> +  auto UnscopedEnumMatcher = enumConstantDecl(hasParent(enumDecl(
> +  hasParent(namespaceDecl()),
> +  unless(anyOf(isScoped(), IsInMovedNs, hasAncestor(cxxRecordDecl()),
> +   hasAncestor(namespaceDecl(isAnonymous(;
> +  Finder->addMatcher(
> +  declRefExpr(IsInMovedNs, hasAncestor(decl().bind("dc")),
> +  to(UnscopedEnumMatcher.bind("enum_const_decl")))
> +  .bind("enum_const_ref"),
> +  this);
>  }
>
>  void ChangeNamespaceTool::run(
> @@ -518,6 +533,21 @@ void ChangeNamespaceTool::run(
>  assert(Context && "Empty decl context.");
>  fixDeclRefExpr(Result, Context->getDeclContext(),
> llvm::cast(Var), VarRef);
> +  } else if (const auto *EnumConstRef =
> + Result.Nodes.getNodeAs("enum_const_ref")) {
> +// Do not rename the reference if it is already scoped by the
> EnumDecl name.
> +if (EnumConstRef->hasQualifier() &&
> +EnumConstRef->getQualifier()->getAsType()->isEnumeralType())
> +  return;
> +const auto *EnumConstDecl =
> +Result.Nodes.getNodeAs("enum_const_decl");
> +assert(EnumConstDecl);
> +const auto *Context = Result.Nodes.getNodeAs("dc");
> +assert(Context && "Empty decl context.");
> +// FIXME: this would qualify "ns::VALUE" as "ns::EnumValue::VALUE".
> Fix it
> +// if it turns out to be an issue.
> +fixDeclRefExpr(Result, Context->getDeclContext(),
> +   llvm::cast(EnumConstDecl), EnumConstRef);
>} else if (const auto *FuncRef =
>   Result.Nodes.getNodeAs("func_ref")) {
>  // If this reference has been processed as a function call, we do not
>
> Modified:
> clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=293909&r1=293908&r2=293909&view=diff
>
> ==
> ---
> clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
> (original)
> +++
> clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
> Thu Feb  2 11:40:38 2017
> @@ -1774,6 +1774,207 @@ TEST_F(ChangeNamespaceTest, ShortenNames
>EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
>  }
>
> +TEST_F(ChangeNamespaceTest, SimpleMoveEnum) {
> +  std::string Code = "namespace na {\n"
> + "namespace nb {\n"
> + "enum class X { X1, X2 };\n"
> + "enum Y { Y1, Y2 };\n"
> + "} // namespace nb\n"
> + "} // namespace na\n";
> +  std::string Expected = "\n\nnamespace x {\n"
> + "namespace y {\n"
> + "enum class X { X1, X2 };\n"
> + "enum Y { Y1, Y2 };\n"
> + "} // namespace y\n"
> + "} // namespace x\n";
> +
> +  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
> +}
> +
> +TEST_F(ChangeNamespaceTest, ReferencesToEnums) {
> +  std::string Code = "enum Glob { G1, G2 };\n"
> + "namespace na {\n"
> + "enum class X { X1 };\n"
> +

[PATCH] D29464: [MinGWToolChain] Don't use GCC headers on Win32

2017-02-02 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

I don't know about Linux but on Windows this code was causing issue:

  #include 
  int main() { char buf[PATH_MAX]; }

Include order:

- Before patch: Clang limits.h (lib\\clang\\3.9.1\\include) -> GCC limits.h 
(lib\\gcc\\x86_64-w64-mingw32\\6.3.0\\include-fixed) here whole header is 
skipped due to the guards -> Clang limits.h



- After patch: Clang limits.h (lib\\clang\\3.9.1\\include) -> mingw-w64 
limits.h -> Clang limits.h

Before patch mingw-w64 limits.h weren't included so it was big problem.


https://reviews.llvm.org/D29464



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


[PATCH] D28365: [Driver] Updated for Visual Studio 2017

2017-02-02 Thread Hamza Sood via Phabricator via cfe-commits
hamzasood added a comment.

In https://reviews.llvm.org/D28365#664892, @rnk wrote:

> This is ready to land. Do you need someone to commit this?


I think so, yeah.


https://reviews.llvm.org/D28365



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


[PATCH] D29464: [MinGWToolChain] Don't use GCC headers on Win32

2017-02-02 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 created this revision.
mati865 added a project: clang-c.

Header guards in GCC limits.h were stopping Clang from going up one more level 
to the system limits.h


https://reviews.llvm.org/D29464

Files:
  lib/Driver/MinGWToolChain.cpp


Index: lib/Driver/MinGWToolChain.cpp
===
--- lib/Driver/MinGWToolChain.cpp
+++ lib/Driver/MinGWToolChain.cpp
@@ -208,6 +208,7 @@
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
 return;
 
+#ifndef LLVM_ON_WIN32
   if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) {
 llvm::SmallString<1024> IncludeDir(GccLibDir);
 llvm::sys::path::append(IncludeDir, "include");
@@ -218,6 +219,7 @@
  Base + Arch + "/sys-root/mingw/include");
 addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str());
   }
+#endif
   addSystemInclude(DriverArgs, CC1Args,
Base + Arch + llvm::sys::path::get_separator() + "include");
   addSystemInclude(DriverArgs, CC1Args, Base + "include");


Index: lib/Driver/MinGWToolChain.cpp
===
--- lib/Driver/MinGWToolChain.cpp
+++ lib/Driver/MinGWToolChain.cpp
@@ -208,6 +208,7 @@
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
 return;
 
+#ifndef LLVM_ON_WIN32
   if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) {
 llvm::SmallString<1024> IncludeDir(GccLibDir);
 llvm::sys::path::append(IncludeDir, "include");
@@ -218,6 +219,7 @@
  Base + Arch + "/sys-root/mingw/include");
 addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str());
   }
+#endif
   addSystemInclude(DriverArgs, CC1Args,
Base + Arch + llvm::sys::path::get_separator() + "include");
   addSystemInclude(DriverArgs, CC1Args, Base + "include");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29208: Prevent ICE in dllexport class with _Atomic() data member

2017-02-02 Thread Warren Ristow via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
wristow marked an inline comment as done.
Closed by commit rL293911: Prevent ICE in dllexport class with _Atomic data 
member (authored by wristow).

Changed prior to commit:
  https://reviews.llvm.org/D29208?vs=86767&id=86848#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29208

Files:
  cfe/trunk/lib/CodeGen/CGClass.cpp
  cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp


Index: cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp
===
--- cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp
+++ cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++11 
-fms-extensions -O0 -o - %s | FileCheck --check-prefix=M32 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++11 
-fms-extensions -O0 -o - %s | FileCheck --check-prefix=M64 %s
+
+struct __declspec(dllexport) SomeStruct {
+  // Copy assignment operator should be produced, and exported:
+  // M32: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) 
%struct.SomeStruct* @"\01??4SomeStruct@@QAEAAU0@ABU0@@Z"
+  // M64: define weak_odr dllexportdereferenceable({{[0-9]+}}) 
%struct.SomeStruct* @"\01??4SomeStruct@@QEAAAEAU0@AEBU0@@Z"
+  _Atomic(int) mData;
+};
Index: cfe/trunk/lib/CodeGen/CGClass.cpp
===
--- cfe/trunk/lib/CodeGen/CGClass.cpp
+++ cfe/trunk/lib/CodeGen/CGClass.cpp
@@ -1131,10 +1131,11 @@
   RHS = EC->getSubExpr();
 if (!RHS)
   return nullptr;
-MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
-  return nullptr;
-return Field;
+if (MemberExpr *ME2 = dyn_cast(RHS)) {
+  if (ME2->getMemberDecl() == Field)
+return Field;
+}
+return nullptr;
   } else if (CXXMemberCallExpr *MCE = dyn_cast(S)) {
 CXXMethodDecl *MD = dyn_cast(MCE->getCalleeDecl());
 if (!(MD && isMemcpyEquivalentSpecialMember(MD)))


Index: cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp
===
--- cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp
+++ cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++11 -fms-extensions -O0 -o - %s | FileCheck --check-prefix=M32 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++11 -fms-extensions -O0 -o - %s | FileCheck --check-prefix=M64 %s
+
+struct __declspec(dllexport) SomeStruct {
+  // Copy assignment operator should be produced, and exported:
+  // M32: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.SomeStruct* @"\01??4SomeStruct@@QAEAAU0@ABU0@@Z"
+  // M64: define weak_odr dllexportdereferenceable({{[0-9]+}}) %struct.SomeStruct* @"\01??4SomeStruct@@QEAAAEAU0@AEBU0@@Z"
+  _Atomic(int) mData;
+};
Index: cfe/trunk/lib/CodeGen/CGClass.cpp
===
--- cfe/trunk/lib/CodeGen/CGClass.cpp
+++ cfe/trunk/lib/CodeGen/CGClass.cpp
@@ -1131,10 +1131,11 @@
   RHS = EC->getSubExpr();
 if (!RHS)
   return nullptr;
-MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
-  return nullptr;
-return Field;
+if (MemberExpr *ME2 = dyn_cast(RHS)) {
+  if (ME2->getMemberDecl() == Field)
+return Field;
+}
+return nullptr;
   } else if (CXXMemberCallExpr *MCE = dyn_cast(S)) {
 CXXMethodDecl *MD = dyn_cast(MCE->getCalleeDecl());
 if (!(MD && isMemcpyEquivalentSpecialMember(MD)))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293911 - Prevent ICE in dllexport class with _Atomic data member

2017-02-02 Thread Warren Ristow via cfe-commits
Author: wristow
Date: Thu Feb  2 11:53:34 2017
New Revision: 293911

URL: http://llvm.org/viewvc/llvm-project?rev=293911&view=rev
Log:
Prevent ICE in dllexport class with _Atomic data member

Guard against a null pointer dereference that caused Clang to crash
when processing a class containing an _Atomic qualified data member,
and that is tagged with 'dllexport'.

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

Added:
cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=293911&r1=293910&r2=293911&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Feb  2 11:53:34 2017
@@ -1131,10 +1131,11 @@ namespace {
   RHS = EC->getSubExpr();
 if (!RHS)
   return nullptr;
-MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
-  return nullptr;
-return Field;
+if (MemberExpr *ME2 = dyn_cast(RHS)) {
+  if (ME2->getMemberDecl() == Field)
+return Field;
+}
+return nullptr;
   } else if (CXXMemberCallExpr *MCE = dyn_cast(S)) {
 CXXMethodDecl *MD = dyn_cast(MCE->getCalleeDecl());
 if (!(MD && isMemcpyEquivalentSpecialMember(MD)))

Added: cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp?rev=293911&view=auto
==
--- cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/atomic-dllexport.cpp Thu Feb  2 11:53:34 2017
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++11 
-fms-extensions -O0 -o - %s | FileCheck --check-prefix=M32 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++11 
-fms-extensions -O0 -o - %s | FileCheck --check-prefix=M64 %s
+
+struct __declspec(dllexport) SomeStruct {
+  // Copy assignment operator should be produced, and exported:
+  // M32: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) 
%struct.SomeStruct* @"\01??4SomeStruct@@QAEAAU0@ABU0@@Z"
+  // M64: define weak_odr dllexportdereferenceable({{[0-9]+}}) 
%struct.SomeStruct* @"\01??4SomeStruct@@QEAAAEAU0@AEBU0@@Z"
+  _Atomic(int) mData;
+};


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


[PATCH] D28365: [Driver] Updated for Visual Studio 2017

2017-02-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

This is ready to land. Do you need someone to commit this?


https://reviews.llvm.org/D28365



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


[PATCH] D29460: [change-namespace] fix unscoped enum constant references.

2017-02-02 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293909: [change-namespace] fix unscoped enum constant 
references. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D29460?vs=86835&id=86843#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29460

Files:
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
  clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
@@ -282,6 +282,10 @@
   isNestedDeclContext(DeclCtx, D->getDeclContext()));
 }
 
+AST_MATCHER(EnumDecl, isScoped) {
+return Node.isScoped();
+}
+
 } // anonymous namespace
 
 ChangeNamespaceTool::ChangeNamespaceTool(
@@ -454,6 +458,17 @@
  to(GlobalVarMatcher.bind("var_decl")))
  .bind("var_ref"),
  this);
+
+  // Handle unscoped enum constant.
+  auto UnscopedEnumMatcher = enumConstantDecl(hasParent(enumDecl(
+  hasParent(namespaceDecl()),
+  unless(anyOf(isScoped(), IsInMovedNs, hasAncestor(cxxRecordDecl()),
+   hasAncestor(namespaceDecl(isAnonymous(;
+  Finder->addMatcher(
+  declRefExpr(IsInMovedNs, hasAncestor(decl().bind("dc")),
+  to(UnscopedEnumMatcher.bind("enum_const_decl")))
+  .bind("enum_const_ref"),
+  this);
 }
 
 void ChangeNamespaceTool::run(
@@ -518,6 +533,21 @@
 assert(Context && "Empty decl context.");
 fixDeclRefExpr(Result, Context->getDeclContext(),
llvm::cast(Var), VarRef);
+  } else if (const auto *EnumConstRef =
+ Result.Nodes.getNodeAs("enum_const_ref")) {
+// Do not rename the reference if it is already scoped by the EnumDecl name.
+if (EnumConstRef->hasQualifier() &&
+EnumConstRef->getQualifier()->getAsType()->isEnumeralType())
+  return;
+const auto *EnumConstDecl =
+Result.Nodes.getNodeAs("enum_const_decl");
+assert(EnumConstDecl);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+// FIXME: this would qualify "ns::VALUE" as "ns::EnumValue::VALUE". Fix it
+// if it turns out to be an issue.
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(EnumConstDecl), EnumConstRef);
   } else if (const auto *FuncRef =
  Result.Nodes.getNodeAs("func_ref")) {
 // If this reference has been processed as a function call, we do not
Index: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -1774,6 +1774,207 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, SimpleMoveEnum) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "enum class X { X1, X2 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "\n\nnamespace x {\n"
+ "namespace y {\n"
+ "enum class X { X1, X2 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, ReferencesToEnums) {
+  std::string Code = "enum Glob { G1, G2 };\n"
+ "namespace na {\n"
+ "enum class X { X1 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  Glob g1 = Glob::G1;\n"
+ "  Glob g2 = G2;\n"
+ "  X x1 = X::X1;\n"
+ "  Y y1 = Y::Y1;\n"
+ "  Y y2 = Y2;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "enum Glob { G1, G2 };\n"
+ "namespace na {\n"
+ "enum class X { X1 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "void f() {\n"
+ "  Glob g1 = Glob::G1;\n"
+ "  Glob g2 = G2;\n"
+ 

[clang-tools-extra] r293909 - [change-namespace] fix unscoped enum constant references.

2017-02-02 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Feb  2 11:40:38 2017
New Revision: 293909

URL: http://llvm.org/viewvc/llvm-project?rev=293909&view=rev
Log:
[change-namespace] fix unscoped enum constant references.

Reviewers: bkramer

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=293909&r1=293908&r2=293909&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Feb  2 
11:40:38 2017
@@ -282,6 +282,10 @@ bool isDeclVisibleAtLocation(const Sourc
   isNestedDeclContext(DeclCtx, D->getDeclContext()));
 }
 
+AST_MATCHER(EnumDecl, isScoped) {
+return Node.isScoped();
+}
+
 } // anonymous namespace
 
 ChangeNamespaceTool::ChangeNamespaceTool(
@@ -454,6 +458,17 @@ void ChangeNamespaceTool::registerMatche
  to(GlobalVarMatcher.bind("var_decl")))
  .bind("var_ref"),
  this);
+
+  // Handle unscoped enum constant.
+  auto UnscopedEnumMatcher = enumConstantDecl(hasParent(enumDecl(
+  hasParent(namespaceDecl()),
+  unless(anyOf(isScoped(), IsInMovedNs, hasAncestor(cxxRecordDecl()),
+   hasAncestor(namespaceDecl(isAnonymous(;
+  Finder->addMatcher(
+  declRefExpr(IsInMovedNs, hasAncestor(decl().bind("dc")),
+  to(UnscopedEnumMatcher.bind("enum_const_decl")))
+  .bind("enum_const_ref"),
+  this);
 }
 
 void ChangeNamespaceTool::run(
@@ -518,6 +533,21 @@ void ChangeNamespaceTool::run(
 assert(Context && "Empty decl context.");
 fixDeclRefExpr(Result, Context->getDeclContext(),
llvm::cast(Var), VarRef);
+  } else if (const auto *EnumConstRef =
+ Result.Nodes.getNodeAs("enum_const_ref")) {
+// Do not rename the reference if it is already scoped by the EnumDecl 
name.
+if (EnumConstRef->hasQualifier() &&
+EnumConstRef->getQualifier()->getAsType()->isEnumeralType())
+  return;
+const auto *EnumConstDecl =
+Result.Nodes.getNodeAs("enum_const_decl");
+assert(EnumConstDecl);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+// FIXME: this would qualify "ns::VALUE" as "ns::EnumValue::VALUE". Fix it
+// if it turns out to be an issue.
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(EnumConstDecl), EnumConstRef);
   } else if (const auto *FuncRef =
  Result.Nodes.getNodeAs("func_ref")) {
 // If this reference has been processed as a function call, we do not

Modified: 
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=293909&r1=293908&r2=293909&view=diff
==
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
Thu Feb  2 11:40:38 2017
@@ -1774,6 +1774,207 @@ TEST_F(ChangeNamespaceTest, ShortenNames
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, SimpleMoveEnum) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "enum class X { X1, X2 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "\n\nnamespace x {\n"
+ "namespace y {\n"
+ "enum class X { X1, X2 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, ReferencesToEnums) {
+  std::string Code = "enum Glob { G1, G2 };\n"
+ "namespace na {\n"
+ "enum class X { X1 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  Glob g1 = Glob::G1;\n"
+ "  Glob g2 = G2;\n"
+ "  X x1 = X::X1;\n"
+ "  Y y1 = Y::Y1;\n"
+ "  Y y2 = Y2;\n"
+ "}\n"
+ "} // namespace nb\n"
+ 

[PATCH] D29460: [change-namespace] fix unscoped enum constant references.

2017-02-02 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D29460



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


[PATCH] D29460: [change-namespace] fi unscoped enum const^Ct references.

2017-02-02 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.

https://reviews.llvm.org/D29460

Files:
  change-namespace/ChangeNamespace.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -1774,6 +1774,207 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, SimpleMoveEnum) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "enum class X { X1, X2 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "\n\nnamespace x {\n"
+ "namespace y {\n"
+ "enum class X { X1, X2 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, ReferencesToEnums) {
+  std::string Code = "enum Glob { G1, G2 };\n"
+ "namespace na {\n"
+ "enum class X { X1 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  Glob g1 = Glob::G1;\n"
+ "  Glob g2 = G2;\n"
+ "  X x1 = X::X1;\n"
+ "  Y y1 = Y::Y1;\n"
+ "  Y y2 = Y2;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "enum Glob { G1, G2 };\n"
+ "namespace na {\n"
+ "enum class X { X1 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "void f() {\n"
+ "  Glob g1 = Glob::G1;\n"
+ "  Glob g2 = G2;\n"
+ "  ::na::X x1 = ::na::X::X1;\n"
+ "  ::na::Y y1 = ::na::Y::Y1;\n"
+ "  ::na::Y y2 = ::na::Y::Y2;\n"
+ "}\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, NoRedundantEnumUpdate) {
+  std::string Code = "namespace ns {\n"
+ "enum class X { X1 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace ns\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  ns::X x1 = ns::X::X1;\n"
+ "  ns::Y y1 = ns::Y::Y1;\n"
+ "  ns::Y y2 = ns::Y2;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace ns {\n"
+ "enum class X { X1 };\n"
+ "enum Y { Y1, Y2 };\n"
+ "} // namespace ns\n"
+ "\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "void f() {\n"
+ "  ns::X x1 = ns::X::X1;\n"
+ "  ns::Y y1 = ns::Y::Y1;\n"
+ // FIXME: this is redundant
+ "  ns::Y y2 = ::ns::Y::Y2;\n"
+ "}\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  ;
+
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, EnumsAndUsingShadows) {
+  std::string Code = "namespace ns {\n"
+ "enum class X { X1 };\n"
+ "enum Y { Y1, Y2, Y3 };\n"
+ "} // namespace ns\n"
+ "using ns::X;\n"
+ "using ns::Y;\n"
+ "using ns::Y::Y2;\n"
+ "using ns::Y::Y3;\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  X x1 = X::X1;\n"
+ "  Y y1 = Y::Y1;\n"
+ "  Y y2 = Y2;\n"
+ "  Y y3 = Y3;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace ns {\n"
+ "enum class X { X1 };\n"
+ "enum 

[PATCH] D21507: Changes after running check modernize-use-emplace (D20964)

2017-02-02 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

If you're still considering to submit this patch, could you rebase it (or maybe 
re-generate instead?) and split into easier to digest parts?

A couple of things I noticed:

1. `v.push_back(X);` -> `v.emplace_back(X);` pattern, where `X` has a type of 
element of `v`. Not sure whether `emplace_back` provides any benefit in this 
case.
2. a sub-case of 1 where `X` is `std::make_pair(...)`, in this case 
`emplace_back` makes sense, if `std::make_pair` is removed as well. I don't 
know whether it's practical to teach the check this pattern. Given its 
frequency, might well be good.




Comment at: lib/Bitcode/Reader/BitcodeReader.cpp:3903
   if (Record.size() > 10 && Record[10] != 0)
-FunctionPrologues.push_back(std::make_pair(Func, Record[10]-1));
+FunctionPrologues.emplace_back(std::make_pair(Func, Record[10]-1));
 

No `make_pair`.



Comment at: lib/Bitcode/Reader/BitcodeReader.cpp:3921
   if (Record.size() > 13 && Record[13] != 0)
-FunctionPrefixes.push_back(std::make_pair(Func, Record[13]-1));
+FunctionPrefixes.emplace_back(std::make_pair(Func, Record[13]-1));
 

ditto



Comment at: lib/Bitcode/Reader/BitcodeReader.cpp:3924
   if (Record.size() > 14 && Record[14] != 0)
-FunctionPersonalityFns.push_back(std::make_pair(Func, Record[14] - 1));
+FunctionPersonalityFns.emplace_back(std::make_pair(Func, Record[14] - 
1));
 

ditto



Comment at: lib/Bitcode/Reader/BitcodeReader.cpp:3989
   ValueList.push_back(NewGA);
-  IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
+  IndirectSymbolInits.emplace_back(std::make_pair(NewGA, Val));
   break;

ditto



Comment at: lib/Bitcode/Writer/ValueEnumerator.cpp:149
 if (OM.lookup(U.getUser()).first)
-  List.push_back(std::make_pair(&U, List.size()));
+  List.emplace_back(std::make_pair(&U, List.size()));
 

No `std::make_pair` needed.



Comment at: lib/Bitcode/Writer/ValueEnumerator.cpp:606
   else
-Worklist.push_back(std::make_pair(Op, Op->op_begin()));
+Worklist.emplace_back(std::make_pair(Op, Op->op_begin()));
   continue;

ditto



Comment at: lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp:50
   }
-  Ranges.push_back(std::make_pair(&MI, nullptr));
+  Ranges.emplace_back(std::make_pair(&MI, nullptr));
 }

No need for `std::make_pair`.



Comment at: lib/CodeGen/CGExprScalar.cpp:2755
   BaseCheck->addIncoming(ValidBase, CheckShiftBase);
-  Checks.push_back(std::make_pair(BaseCheck, SanitizerKind::ShiftBase));
+  Checks.emplace_back(std::make_pair(BaseCheck, SanitizerKind::ShiftBase));
 }

`make_pair` can be removed, IIUC.



Comment at: lib/CodeGen/CGVTables.cpp:948
   for (auto &&AP : VTLayout.getAddressPoints())
-BitsetEntries.push_back(std::make_pair(AP.first.getBase(), AP.second));
+BitsetEntries.emplace_back(std::make_pair(AP.first.getBase(), AP.second));
 

Not sure if it's practical to teach the check this pattern, but 
`std::make_pair` is not needed here.



Comment at: lib/CodeGen/ScheduleDAGInstrs.cpp:1498
   void visitCrossEdge(const SDep &PredDep, const SUnit *Succ) {
-ConnectionPairs.push_back(std::make_pair(PredDep.getSUnit(), Succ));
+ConnectionPairs.emplace_back(std::make_pair(PredDep.getSUnit(), Succ));
   }

No `make_pair` needed.



Comment at: lib/CodeGen/SelectionDAG/FastISel.cpp:2079
   }
-  FuncInfo.PHINodesToUpdate.push_back(std::make_pair(MBBI++, Reg));
+  FuncInfo.PHINodesToUpdate.emplace_back(std::make_pair(MBBI++, Reg));
   DbgLoc = DebugLoc();

No `make_pair` needed.


Repository:
  rL LLVM

https://reviews.llvm.org/D21507



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


r293904 - [index] Provide a more general index::generateUSRForMacro() that doesn't depend on having a PreprocessingRecord.

2017-02-02 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Thu Feb  2 10:13:10 2017
New Revision: 293904

URL: http://llvm.org/viewvc/llvm-project?rev=293904&view=rev
Log:
[index] Provide a more general index::generateUSRForMacro() that doesn't depend 
on having a PreprocessingRecord.

Modified:
cfe/trunk/include/clang/Index/USRGeneration.h
cfe/trunk/lib/Index/USRGeneration.cpp

Modified: cfe/trunk/include/clang/Index/USRGeneration.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/USRGeneration.h?rev=293904&r1=293903&r2=293904&view=diff
==
--- cfe/trunk/include/clang/Index/USRGeneration.h (original)
+++ cfe/trunk/include/clang/Index/USRGeneration.h Thu Feb  2 10:13:10 2017
@@ -16,6 +16,7 @@
 namespace clang {
 class Decl;
 class MacroDefinitionRecord;
+class SourceLocation;
 class SourceManager;
 
 namespace index {
@@ -54,6 +55,8 @@ void generateUSRForObjCProtocol(StringRe
 /// \returns true on error, false on success.
 bool generateUSRForMacro(const MacroDefinitionRecord *MD,
  const SourceManager &SM, SmallVectorImpl &Buf);
+bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
+ const SourceManager &SM, SmallVectorImpl &Buf);
 
 } // namespace index
 } // namespace clang

Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=293904&r1=293903&r2=293904&view=diff
==
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Thu Feb  2 10:13:10 2017
@@ -911,21 +911,30 @@ bool clang::index::generateUSRForDecl(co
 bool clang::index::generateUSRForMacro(const MacroDefinitionRecord *MD,
const SourceManager &SM,
SmallVectorImpl &Buf) {
+  if (!MD)
+return true;
+  return generateUSRForMacro(MD->getName()->getName(), MD->getLocation(),
+ SM, Buf);
+
+}
+
+bool clang::index::generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
+   const SourceManager &SM,
+   SmallVectorImpl &Buf) {
   // Don't generate USRs for things with invalid locations.
-  if (!MD || MD->getLocation().isInvalid())
+  if (MacroName.empty() || Loc.isInvalid())
 return true;
 
   llvm::raw_svector_ostream Out(Buf);
 
   // Assume that system headers are sane.  Don't put source location
   // information into the USR if the macro comes from a system header.
-  SourceLocation Loc = MD->getLocation();
   bool ShouldGenerateLocation = !SM.isInSystemHeader(Loc);
 
   Out << getUSRSpacePrefix();
   if (ShouldGenerateLocation)
 printLoc(Out, Loc, SM, /*IncludeOffset=*/true);
   Out << "@macro@";
-  Out << MD->getName()->getName();
+  Out << MacroName;
   return false;
 }


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


[PATCH] D20561: Warn when taking address of packed member

2017-02-02 Thread Roger via Phabricator via cfe-commits
royger added a comment.

Ping?

It's not clear to me whether upstream is going to do something about this or 
not. I would like to know in case I need to start passing 
"-Waddress-of-packed-member" around.


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



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


[PATCH] D29450: [clang-format] Don't reflow across comment pragmas.

2017-02-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293898: [clang-format] Don't reflow across comment pragmas. 
(authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29450?vs=86814&id=86816#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29450

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/lib/Format/BreakableToken.h
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.h
  cfe/trunk/unittests/Format/FormatTest.cpp

Index: cfe/trunk/lib/Format/BreakableToken.h
===
--- cfe/trunk/lib/Format/BreakableToken.h
+++ cfe/trunk/lib/Format/BreakableToken.h
@@ -21,6 +21,7 @@
 #include "Encoding.h"
 #include "TokenAnnotator.h"
 #include "WhitespaceManager.h"
+#include "llvm/Support/Regex.h"
 #include 
 
 namespace clang {
@@ -118,7 +119,8 @@
   /// needs to be reformatted before any breaks are made.
   virtual Split getSplitBefore(unsigned LineIndex,
unsigned PreviousEndColumn,
-   unsigned ColumnLimit) const {
+   unsigned ColumnLimit,
+   llvm::Regex& CommentPragmasRegex) const {
 return Split(StringRef::npos, 0);
   }
 
@@ -238,7 +240,8 @@
 
   // Checks if the content of line LineIndex may be reflown with the previous
   // line.
-  bool mayReflow(unsigned LineIndex) const;
+  virtual bool mayReflow(unsigned LineIndex,
+ llvm::Regex &CommentPragmasRegex) const = 0;
 
   // Contains the original text of the lines of the block comment.
   //
@@ -307,7 +310,8 @@
   void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split,
WhitespaceManager &Whitespaces) override;
   Split getSplitBefore(unsigned LineIndex, unsigned PreviousEndColumn,
-   unsigned ColumnLimit) const override;
+   unsigned ColumnLimit,
+   llvm::Regex &CommentPragmasRegex) const override;
   unsigned getLineLengthAfterSplitBefore(unsigned LineIndex,
  unsigned TailOffset,
  unsigned PreviousEndColumn,
@@ -317,6 +321,8 @@
unsigned ColumnLimit,
Split SplitBefore,
WhitespaceManager &Whitespaces) override;
+  bool mayReflow(unsigned LineIndex,
+ llvm::Regex &CommentPragmasRegex) const override;
 
 private:
   // Rearranges the whitespace between Lines[LineIndex-1] and Lines[LineIndex].
@@ -371,15 +377,18 @@
   void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split,
WhitespaceManager &Whitespaces) override;
   Split getSplitBefore(unsigned LineIndex, unsigned PreviousEndColumn,
-   unsigned ColumnLimit) const override;
+   unsigned ColumnLimit,
+   llvm::Regex &CommentPragmasRegex) const override;
   unsigned getLineLengthAfterSplitBefore(unsigned LineIndex, unsigned TailOffset,
  unsigned PreviousEndColumn,
  unsigned ColumnLimit,
  Split SplitBefore) const override;
   void replaceWhitespaceBefore(unsigned LineIndex, unsigned PreviousEndColumn,
unsigned ColumnLimit, Split SplitBefore,
WhitespaceManager &Whitespaces) override;
   void updateNextToken(LineState& State) const override;
+  bool mayReflow(unsigned LineIndex,
+ llvm::Regex &CommentPragmasRegex) const override;
 
 private:
   unsigned getContentStartColumn(unsigned LineIndex,
Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -321,13 +321,6 @@
  (!isPunctuation(Content[0]) || !isPunctuation(Content[1]));
 }
 
-bool BreakableComment::mayReflow(unsigned LineIndex) const {
-  return LineIndex > 0 && mayReflowContent(Content[LineIndex]) &&
- !Tok.Finalized && !switchesFormatting(tokenAt(LineIndex)) &&
- (!Tok.is(TT_LineComment) ||
-  OriginalPrefix[LineIndex] == OriginalPrefix[LineIndex - 1]);
-}
-
 BreakableBlockComment::BreakableBlockComment(
 const FormatToken &Token, unsigned StartColumn,
 unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
@@ -501,8 +494,9 @@
 BreakableToken::Split BreakableBlockComment::getSplitBefore(
 unsigned LineIndex,
 unsigned PreviousEndColumn,
-unsigned ColumnLimit) const {
-  if (!mayReflow(LineIndex))
+unsigned ColumnLimit,
+llvm::Regex &CommentPragmasRegex) const {
+  if (!mayReflow(LineIndex, Comme

r293898 - [clang-format] Don't reflow across comment pragmas.

2017-02-02 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Feb  2 09:32:19 2017
New Revision: 293898

URL: http://llvm.org/viewvc/llvm-project?rev=293898&view=rev
Log:
[clang-format] Don't reflow across comment pragmas.

Summary:
The comment reflower wasn't taking comment pragmas as reflow stoppers. This 
patch fixes that.

source:
```
// long long long long
// IWYU pragma:
```
format with column limit  = 20 before:
```
// long long long
// long IWYU pragma:
```
format with column limit  = 20 after:
```
// long long long
// long
// IWYU pragma:
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=293898&r1=293897&r2=293898&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Thu Feb  2 09:32:19 2017
@@ -321,13 +321,6 @@ static bool mayReflowContent(StringRef C
  (!isPunctuation(Content[0]) || !isPunctuation(Content[1]));
 }
 
-bool BreakableComment::mayReflow(unsigned LineIndex) const {
-  return LineIndex > 0 && mayReflowContent(Content[LineIndex]) &&
- !Tok.Finalized && !switchesFormatting(tokenAt(LineIndex)) &&
- (!Tok.is(TT_LineComment) ||
-  OriginalPrefix[LineIndex] == OriginalPrefix[LineIndex - 1]);
-}
-
 BreakableBlockComment::BreakableBlockComment(
 const FormatToken &Token, unsigned StartColumn,
 unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
@@ -501,8 +494,9 @@ void BreakableBlockComment::insertBreak(
 BreakableToken::Split BreakableBlockComment::getSplitBefore(
 unsigned LineIndex,
 unsigned PreviousEndColumn,
-unsigned ColumnLimit) const {
-  if (!mayReflow(LineIndex))
+unsigned ColumnLimit,
+llvm::Regex &CommentPragmasRegex) const {
+  if (!mayReflow(LineIndex, CommentPragmasRegex))
 return Split(StringRef::npos, 0);
   StringRef TrimmedContent = Content[LineIndex].ltrim(Blanks);
   return getReflowSplit(TrimmedContent, ReflowPrefix, PreviousEndColumn,
@@ -622,6 +616,19 @@ void BreakableBlockComment::replaceWhite
   InPPDirective, /*Newlines=*/1, ContentColumn[LineIndex] - Prefix.size());
 }
 
+bool BreakableBlockComment::mayReflow(unsigned LineIndex,
+  llvm::Regex &CommentPragmasRegex) const {
+  // Content[LineIndex] may exclude the indent after the '*' decoration. In 
that
+  // case, we compute the start of the comment pragma manually.
+  StringRef IndentContent = Content[LineIndex];
+  if (Lines[LineIndex].ltrim(Blanks).startswith("*")) {
+IndentContent = Lines[LineIndex].ltrim(Blanks).substr(1);
+  }
+  return LineIndex > 0 && !CommentPragmasRegex.match(IndentContent) &&
+ mayReflowContent(Content[LineIndex]) && !Tok.Finalized &&
+ !switchesFormatting(tokenAt(LineIndex));
+}
+
 unsigned
 BreakableBlockComment::getContentStartColumn(unsigned LineIndex,
  unsigned TailOffset) const {
@@ -748,10 +755,10 @@ void BreakableLineCommentSection::insert
 }
 
 BreakableComment::Split BreakableLineCommentSection::getSplitBefore(
-unsigned LineIndex,
-unsigned PreviousEndColumn,
-unsigned ColumnLimit) const {
-  if (!mayReflow(LineIndex)) return Split(StringRef::npos, 0);
+unsigned LineIndex, unsigned PreviousEndColumn, unsigned ColumnLimit,
+llvm::Regex &CommentPragmasRegex) const {
+  if (!mayReflow(LineIndex, CommentPragmasRegex))
+return Split(StringRef::npos, 0);
   return getReflowSplit(Content[LineIndex], ReflowPrefix, PreviousEndColumn,
 ColumnLimit);
 }
@@ -850,6 +857,20 @@ void BreakableLineCommentSection::update
   }
 }
 
+bool BreakableLineCommentSection::mayReflow(
+unsigned LineIndex, llvm::Regex &CommentPragmasRegex) const {
+  // Line comments have the indent as part of the prefix, so we need to
+  // recompute the start of the line.
+  StringRef IndentContent = Content[LineIndex];
+  if (Lines[LineIndex].startswith("//")) {
+IndentContent = Lines[LineIndex].substr(2);
+  }
+  return LineIndex > 0 && !CommentPragmasRegex.match(IndentContent) &&
+ mayReflowContent(Content[LineIndex]) && !Tok.Finalized &&
+ !switchesFormatting(tokenAt(LineIndex)) &&
+ OriginalPrefix[LineIndex] == OriginalPrefix[LineIndex - 1];
+}
+
 unsigned
 BreakableLineCommentSection::getContentStartColumn(unsigned LineIndex,
unsigned TailOffset) const {

Modified: cfe/trunk/lib/Format/BreakableToken

[PATCH] D29447: [change-namespace] check using shadow decl correctly when shortening namespace specifiers.

2017-02-02 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293897: [change-namespace] check using shadow decl correctly 
when shortening namespace… (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D29447?vs=86795&id=86815#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29447

Files:
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
  clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Index: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -1255,7 +1255,7 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
-TEST_F(ChangeNamespaceTest, UsingDeclInTheParentOfOldNamespace) {
+TEST_F(ChangeNamespaceTest, UsingShadowDeclInTheParentOfOldNamespace) {
   OldNamespace = "nb::nc";
   NewNamespace = "nb::nd";
   std::string Code = "namespace na { class A {}; }\n"
@@ -1277,6 +1277,74 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, UsingShadowDeclInOldNamespace) {
+  OldNamespace = "nb";
+  NewNamespace = "nc";
+  std::string Code = "namespace na { class A {}; }\n"
+ "namespace nb {\n"
+ "using na::A;\n"
+ "void d() { A a; }\n"
+ "struct X { A a; };\n"
+ "} // nb\n";
+
+  std::string Expected = "namespace na { class A {}; }\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::A;\n"
+ "void d() { A a; }\n"
+ "struct X { A a; };\n"
+ "} // namespace nc\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, UsingShadowDeclOfTemplateClass) {
+  OldNamespace = "nb";
+  NewNamespace = "nc";
+  std::string Code = "namespace na {\n"
+ "template \n"
+ "class A { T t; };\n"
+ "} // namespace na\n"
+ "namespace nb {\n"
+ "using na::A;\n"
+ "void d() { A a; }\n"
+ "} // nb\n";
+
+  std::string Expected = "namespace na {\n"
+ "template \n"
+ "class A { T t; };\n"
+ "} // namespace na\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::A;\n"
+ "void d() { A a; }\n"
+ "} // namespace nc\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, UsingShadowDeclOfTemplateFunction) {
+  OldNamespace = "nb";
+  NewNamespace = "nc";
+  std::string Code = "namespace na {\n"
+ "template \n"
+ "void f() { T t; };\n"
+ "} // namespace na\n"
+ "namespace nb {\n"
+ "using na::f;\n"
+ "void d() { f(); }\n"
+ "} // nb\n";
+
+  std::string Expected = "namespace na {\n"
+ "template \n"
+ "void f() { T t; };\n"
+ "} // namespace na\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::f;\n"
+ "void d() { f(); }\n"
+ "} // namespace nc\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, UsingAliasDecl) {
   std::string Code =
   "namespace nx { namespace ny { class X {}; } }\n"
Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
@@ -761,7 +761,8 @@
 if (isDeclVisibleAtLocation(*Result.SourceManager, Using, DeclCtx, Start)) {
   for (const auto *UsingShadow : Using->shadows()) {
 const auto *TargetDecl = UsingShadow->getTargetDecl();
-if (TargetDecl == FromDecl) {
+if (TargetDecl->getQualifiedNameAsString() ==
+FromDecl->getQualifiedNameAsString()) {
   ReplaceName = FromDecl->getNameAsString();
   Matched = true;
   break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r293897 - [change-namespace] check using shadow decl correctly when shortening namespace specifiers.

2017-02-02 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Feb  2 09:29:54 2017
New Revision: 293897

URL: http://llvm.org/viewvc/llvm-project?rev=293897&view=rev
Log:
[change-namespace] check using shadow decl correctly when shortening namespace 
specifiers.

Summary:
This fixes mismatch between template decls and template specialization decls.

Also added a few more test cases.

Reviewers: bkramer

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=293897&r1=293896&r2=293897&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Feb  2 
09:29:54 2017
@@ -761,7 +761,8 @@ void ChangeNamespaceTool::replaceQualifi
 if (isDeclVisibleAtLocation(*Result.SourceManager, Using, DeclCtx, Start)) 
{
   for (const auto *UsingShadow : Using->shadows()) {
 const auto *TargetDecl = UsingShadow->getTargetDecl();
-if (TargetDecl == FromDecl) {
+if (TargetDecl->getQualifiedNameAsString() ==
+FromDecl->getQualifiedNameAsString()) {
   ReplaceName = FromDecl->getNameAsString();
   Matched = true;
   break;

Modified: 
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=293897&r1=293896&r2=293897&view=diff
==
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
Thu Feb  2 09:29:54 2017
@@ -1255,7 +1255,7 @@ TEST_F(ChangeNamespaceTest, UsingDeclInM
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
-TEST_F(ChangeNamespaceTest, UsingDeclInTheParentOfOldNamespace) {
+TEST_F(ChangeNamespaceTest, UsingShadowDeclInTheParentOfOldNamespace) {
   OldNamespace = "nb::nc";
   NewNamespace = "nb::nd";
   std::string Code = "namespace na { class A {}; }\n"
@@ -1277,6 +1277,74 @@ TEST_F(ChangeNamespaceTest, UsingDeclInT
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, UsingShadowDeclInOldNamespace) {
+  OldNamespace = "nb";
+  NewNamespace = "nc";
+  std::string Code = "namespace na { class A {}; }\n"
+ "namespace nb {\n"
+ "using na::A;\n"
+ "void d() { A a; }\n"
+ "struct X { A a; };\n"
+ "} // nb\n";
+
+  std::string Expected = "namespace na { class A {}; }\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::A;\n"
+ "void d() { A a; }\n"
+ "struct X { A a; };\n"
+ "} // namespace nc\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, UsingShadowDeclOfTemplateClass) {
+  OldNamespace = "nb";
+  NewNamespace = "nc";
+  std::string Code = "namespace na {\n"
+ "template \n"
+ "class A { T t; };\n"
+ "} // namespace na\n"
+ "namespace nb {\n"
+ "using na::A;\n"
+ "void d() { A a; }\n"
+ "} // nb\n";
+
+  std::string Expected = "namespace na {\n"
+ "template \n"
+ "class A { T t; };\n"
+ "} // namespace na\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::A;\n"
+ "void d() { A a; }\n"
+ "} // namespace nc\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, UsingShadowDeclOfTemplateFunction) {
+  OldNamespace = "nb";
+  NewNamespace = "nc";
+  std::string Code = "namespace na {\n"
+ "template \n"
+ "void f() { T t; };\n"
+ "} // namespace na\n"
+ "namespace nb {\n"
+ "using na::f;\n"
+ "void d() { f(); }\n"
+ "} // nb\n";
+
+  std::string Expected = "namespace na {\n"
+ "template \n"
+ "void f() { T t; };\n"
+ "} // namespace na\n"
+ "\n"
+ "namespace nc {\n"
+   

[PATCH] D29450: [clang-format] Don't reflow across comment pragmas.

2017-02-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 86814.
krasimir added a comment.

- Merge branch 'master' into arcpatch-D29450_1


https://reviews.llvm.org/D29450

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2370,6 +2370,22 @@
"// XXX: long",
getLLVMStyleWithColumns(20)));
 
+  // Don't reflow comment pragmas.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// IWYU pragma:",
+format("// long long long long\n"
+   "// IWYU pragma:",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("/* long long long\n"
+" * long\n"
+" * IWYU pragma:\n"
+" */",
+format("/* long long long long\n"
+   " * IWYU pragma:\n"
+   " */",
+   getLLVMStyleWithColumns(20)));
+
   // Reflow lines that have a non-punctuation character among their first 2
   // characters.
   EXPECT_EQ("// long long long\n"
Index: lib/Format/UnwrappedLineParser.h
===
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -19,6 +19,7 @@
 #include "FormatToken.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Format/Format.h"
+#include "llvm/Support/Regex.h"
 #include 
 #include 
 
@@ -161,6 +162,8 @@
 
   const FormatStyle &Style;
   const AdditionalKeywords &Keywords;
+  
+  llvm::Regex CommentPragmasRegex;
 
   FormatTokenSource *Tokens;
   UnwrappedLineConsumer &Callback;
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -202,7 +202,8 @@
  ArrayRef Tokens,
  UnwrappedLineConsumer &Callback)
 : Line(new UnwrappedLine), MustBreakBeforeNextToken(false),
-  CurrentLines(&Lines), Style(Style), Keywords(Keywords), Tokens(nullptr),
+  CurrentLines(&Lines), Style(Style), Keywords(Keywords),
+  CommentPragmasRegex(Style.CommentPragmas), Tokens(nullptr),
   Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1) {}
 
 void UnwrappedLineParser::reset() {
@@ -2048,10 +2049,18 @@
 // Checks if \p FormatTok is a line comment that continues the line comment
 // section on \p Line.
 static bool continuesLineComment(const FormatToken &FormatTok,
- const UnwrappedLine &Line) {
+ const UnwrappedLine &Line,
+ llvm::Regex &CommentPragmasRegex) {
   if (Line.Tokens.empty())
 return false;
 
+  StringRef IndentContent = FormatTok.TokenText;
+  if (FormatTok.TokenText.startswith("//") ||
+  FormatTok.TokenText.startswith("/*"))
+IndentContent = FormatTok.TokenText.substr(2);
+  if (CommentPragmasRegex.match(IndentContent))
+return false;
+
   // If Line starts with a line comment, then FormatTok continues the comment
   // section if its original column is greater or equal to the original start
   // column of the line.
@@ -2162,7 +2171,8 @@
 //
 // FIXME: Consider putting separate line comment sections as children to the
 // unwrapped line instead.
-(*I)->ContinuesLineCommentSection = continuesLineComment(**I, *Line);
+(*I)->ContinuesLineCommentSection =
+continuesLineComment(**I, *Line, CommentPragmasRegex);
 if (isOnNewLine(**I) && JustComments && !(*I)->ContinuesLineCommentSection)
   addUnwrappedLine();
 pushToken(*I);
@@ -2230,7 +2240,7 @@
 if (!FormatTok->Tok.is(tok::comment))
   return;
 FormatTok->ContinuesLineCommentSection =
-continuesLineComment(*FormatTok, *Line);
+continuesLineComment(*FormatTok, *Line, CommentPragmasRegex);
 if (!FormatTok->ContinuesLineCommentSection &&
 (isOnNewLine(*FormatTok) || FormatTok->IsFirst)) {
   CommentsInCurrentLine = false;
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1213,7 +1213,7 @@
 BreakableToken::Split SplitBefore(StringRef::npos, 0);
 if (ReflowInProgress) {
   SplitBefore = Token->getSplitBefore(LineIndex, RemainingTokenColumns,
-  RemainingSpace);
+  RemainingSpace, CommentPragmasRegex);
 }
 ReflowInProgress = SplitBefore.first != StringRef::npos;
 unsigned TailOffset =
Index: lib/Format/BreakableToken.h

[PATCH] D29450: [clang-format] Don't reflow across comment pragmas.

2017-02-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 86813.
krasimir edited the summary of this revision.
krasimir added a comment.

- Add a break in line comment sections by pragmas


https://reviews.llvm.org/D29450

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2331,6 +2331,22 @@
"// XXX: long",
getLLVMStyleWithColumns(20)));
 
+  // Don't reflow comment pragmas.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// IWYU pragma:",
+format("// long long long long\n"
+   "// IWYU pragma:",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("/* long long long\n"
+" * long\n"
+" * IWYU pragma:\n"
+" */",
+format("/* long long long long\n"
+   " * IWYU pragma:\n"
+   " */",
+   getLLVMStyleWithColumns(20)));
+
   // Reflow lines that have a non-punctuation character among their first 2
   // characters.
   EXPECT_EQ("// long long long\n"
Index: lib/Format/UnwrappedLineParser.h
===
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -19,6 +19,7 @@
 #include "FormatToken.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Format/Format.h"
+#include "llvm/Support/Regex.h"
 #include 
 #include 
 
@@ -161,6 +162,8 @@
 
   const FormatStyle &Style;
   const AdditionalKeywords &Keywords;
+  
+  llvm::Regex CommentPragmasRegex;
 
   FormatTokenSource *Tokens;
   UnwrappedLineConsumer &Callback;
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -202,7 +202,8 @@
  ArrayRef Tokens,
  UnwrappedLineConsumer &Callback)
 : Line(new UnwrappedLine), MustBreakBeforeNextToken(false),
-  CurrentLines(&Lines), Style(Style), Keywords(Keywords), Tokens(nullptr),
+  CurrentLines(&Lines), Style(Style), Keywords(Keywords),
+  CommentPragmasRegex(Style.CommentPragmas), Tokens(nullptr),
   Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1) {}
 
 void UnwrappedLineParser::reset() {
@@ -2048,10 +2049,18 @@
 // Checks if \p FormatTok is a line comment that continues the line comment
 // section on \p Line.
 static bool continuesLineComment(const FormatToken &FormatTok,
- const UnwrappedLine &Line) {
+ const UnwrappedLine &Line,
+ llvm::Regex &CommentPragmasRegex) {
   if (Line.Tokens.empty())
 return false;
 
+  StringRef IndentContent = FormatTok.TokenText;
+  if (FormatTok.TokenText.startswith("//") ||
+  FormatTok.TokenText.startswith("/*"))
+IndentContent = FormatTok.TokenText.substr(2);
+  if (CommentPragmasRegex.match(IndentContent))
+return false;
+
   // If Line starts with a line comment, then FormatTok continues the comment
   // section if its original column is greater or equal to the original start
   // column of the line.
@@ -2066,31 +2075,58 @@
   // original start column of the min column token of the line.
   //
   // For example, the second line comment continues the first in these cases:
+  //
   // // first line
   // // second line
+  //
   // and:
+  //
   // // first line
   //  // second line
+  //
   // and:
+  //
   // int i; // first line
   //  // second line
+  //
   // and:
+  //
   // do { // first line
   //  // second line
   //   int i;
   // } while (true);
   //
+  // and:
+  //
+  // enum {
+  //   a, // first line
+  //// second line
+  //   b
+  // };
+  //
   // The second line comment doesn't continue the first in these cases:
+  //
   //   // first line
   //  // second line
+  //
   // and:
+  //
   // int i; // first line
   // // second line
+  //
   // and:
+  //
   // do { // first line
   //   // second line
   //   int i;
   // } while (true);
+  //
+  // and:
+  //
+  // enum {
+  //   a, // first line
+  //   // second line
+  // };
   const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
 
   // Scan for '{//'. If found, use the column of '{' as a min column for line
@@ -2103,6 +2139,11 @@
   break;
 }
 PreviousToken = Node.Tok;
+
+// Grab the last newline preceding a token in this unwrapped line.
+if (Node.Tok->NewlinesBefore > 0) {
+  MinColumnToken = Node.Tok;
+}
   }
   if (PreviousToken && PreviousToken->is(tok::l_brace)) {
 MinColumnToken = PreviousToken;
@@ -

[PATCH] D29447: [change-namespace] check using shadow decl correctly when shortening namespace specifiers.

2017-02-02 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D29447



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


[PATCH] D29450: [clang-format] Don't reflow across comment pragmas.

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

Makes sense.


https://reviews.llvm.org/D29450



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


[PATCH] D29450: [clang-format] Don't reflow across comment pragmas.

2017-02-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Ideally, we may try doing both: break a line comment section token steam and 
keep this too. What do you think?


https://reviews.llvm.org/D29450



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


r293891 - [clang-format] Fix breaking of comment sections in unwrapped lines containing newlines.

2017-02-02 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Feb  2 08:36:50 2017
New Revision: 293891

URL: http://llvm.org/viewvc/llvm-project?rev=293891&view=rev
Log:
[clang-format] Fix breaking of comment sections in unwrapped lines containing 
newlines.

Summary:
The breaking of line comment sections was misaligning the case where the first 
comment line is on an unwrapped line containing newlines. In this case, the 
breaking column must be based on the source column of the last token that is 
preceded by a newline, not on the first token of the unwrapped line.

source:
```
enum A {
  a, // line 1
  // line 2
};
```
format before:
```
enum A {
  a, // line 1
 // line 2
};
```
format after:
```
enum A {
  a, // line 1
  // line 2
};
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

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

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=293891&r1=293890&r2=293891&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Thu Feb  2 08:36:50 2017
@@ -695,7 +695,7 @@ BreakableLineCommentSection::BreakableLi
   Content[i] = Content[i].substr(0, EndOfLine);
 }
 LineTok = CurrentTok->Next;
-if (CurrentTok->Next && CurrentTok->Next->NewlinesBefore > 1) {
+if (CurrentTok->Next && !CurrentTok->Next->ContinuesLineCommentSection) {
   // A line comment section needs to broken by a line comment that is
   // preceded by at least two newlines. Note that we put this break here
   // instead of breaking at a previous stage during parsing, since that

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=293891&r1=293890&r2=293891&view=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Thu Feb  2 08:36:50 2017
@@ -261,6 +261,11 @@ struct FormatToken {
   /// Only set if \c Type == \c TT_StartOfName.
   bool PartOfMultiVariableDeclStmt = false;
 
+  /// \brief Does this line comment continue a line comment section?
+  ///
+  /// Only set to true if \c Type == \c TT_LineComment.
+  bool ContinuesLineCommentSection = false;
+
   /// \brief If this is a bracket, this points to the matching one.
   FormatToken *MatchingParen = nullptr;
 

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=293891&r1=293890&r2=293891&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Feb  2 08:36:50 2017
@@ -2066,31 +2066,58 @@ static bool continuesLineComment(const F
   // original start column of the min column token of the line.
   //
   // For example, the second line comment continues the first in these cases:
+  //
   // // first line
   // // second line
+  //
   // and:
+  //
   // // first line
   //  // second line
+  //
   // and:
+  //
   // int i; // first line
   //  // second line
+  //
   // and:
+  //
   // do { // first line
   //  // second line
   //   int i;
   // } while (true);
   //
+  // and:
+  //
+  // enum {
+  //   a, // first line
+  //// second line
+  //   b
+  // };
+  //
   // The second line comment doesn't continue the first in these cases:
+  //
   //   // first line
   //  // second line
+  //
   // and:
+  //
   // int i; // first line
   // // second line
+  //
   // and:
+  //
   // do { // first line
   //   // second line
   //   int i;
   // } while (true);
+  //
+  // and:
+  //
+  // enum {
+  //   a, // first line
+  //   // second line
+  // };
   const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
 
   // Scan for '{//'. If found, use the column of '{' as a min column for line
@@ -2103,6 +2130,11 @@ static bool continuesLineComment(const F
   break;
 }
 PreviousToken = Node.Tok;
+
+// Grab the last newline preceding a token in this unwrapped line.
+if (Node.Tok->NewlinesBefore > 0) {
+  MinColumnToken = Node.Tok;
+}
   }
   if (PreviousToken && PreviousToken->is(tok::l_brace)) {
 MinColumnToken = PreviousToken;
@@ -2130,7 +2162,8 @@ void UnwrappedLineParser::flushComments(
 //
 // FIXME: Consider putting separate line comment sections as children to 
the
 // unwrapped line instead.
-if (isOnNewLine(**I) && JustComments && !continuesLineComment(**I, *Line))
+(*I)->ContinuesLineCommentSection = continuesLineComment(**

[PATCH] D29444: [clang-format] Fix breaking of comment sections in unwrapped lines containing newlines.

2017-02-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293891: [clang-format] Fix breaking of comment sections in 
unwrapped lines containing… (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29444?vs=86790&id=86802#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29444

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/lib/Format/FormatToken.h
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp

Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -695,7 +695,7 @@
   Content[i] = Content[i].substr(0, EndOfLine);
 }
 LineTok = CurrentTok->Next;
-if (CurrentTok->Next && CurrentTok->Next->NewlinesBefore > 1) {
+if (CurrentTok->Next && !CurrentTok->Next->ContinuesLineCommentSection) {
   // A line comment section needs to broken by a line comment that is
   // preceded by at least two newlines. Note that we put this break here
   // instead of breaking at a previous stage during parsing, since that
Index: cfe/trunk/lib/Format/FormatToken.h
===
--- cfe/trunk/lib/Format/FormatToken.h
+++ cfe/trunk/lib/Format/FormatToken.h
@@ -261,6 +261,11 @@
   /// Only set if \c Type == \c TT_StartOfName.
   bool PartOfMultiVariableDeclStmt = false;
 
+  /// \brief Does this line comment continue a line comment section?
+  ///
+  /// Only set to true if \c Type == \c TT_LineComment.
+  bool ContinuesLineCommentSection = false;
+
   /// \brief If this is a bracket, this points to the matching one.
   FormatToken *MatchingParen = nullptr;
 
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -2066,31 +2066,58 @@
   // original start column of the min column token of the line.
   //
   // For example, the second line comment continues the first in these cases:
+  //
   // // first line
   // // second line
+  //
   // and:
+  //
   // // first line
   //  // second line
+  //
   // and:
+  //
   // int i; // first line
   //  // second line
+  //
   // and:
+  //
   // do { // first line
   //  // second line
   //   int i;
   // } while (true);
   //
+  // and:
+  //
+  // enum {
+  //   a, // first line
+  //// second line
+  //   b
+  // };
+  //
   // The second line comment doesn't continue the first in these cases:
+  //
   //   // first line
   //  // second line
+  //
   // and:
+  //
   // int i; // first line
   // // second line
+  //
   // and:
+  //
   // do { // first line
   //   // second line
   //   int i;
   // } while (true);
+  //
+  // and:
+  //
+  // enum {
+  //   a, // first line
+  //   // second line
+  // };
   const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
 
   // Scan for '{//'. If found, use the column of '{' as a min column for line
@@ -2103,6 +2130,11 @@
   break;
 }
 PreviousToken = Node.Tok;
+
+// Grab the last newline preceding a token in this unwrapped line.
+if (Node.Tok->NewlinesBefore > 0) {
+  MinColumnToken = Node.Tok;
+}
   }
   if (PreviousToken && PreviousToken->is(tok::l_brace)) {
 MinColumnToken = PreviousToken;
@@ -2130,7 +2162,8 @@
 //
 // FIXME: Consider putting separate line comment sections as children to the
 // unwrapped line instead.
-if (isOnNewLine(**I) && JustComments && !continuesLineComment(**I, *Line))
+(*I)->ContinuesLineCommentSection = continuesLineComment(**I, *Line);
+if (isOnNewLine(**I) && JustComments && !(*I)->ContinuesLineCommentSection)
   addUnwrappedLine();
 pushToken(*I);
   }
@@ -2196,7 +2229,9 @@
 
 if (!FormatTok->Tok.is(tok::comment))
   return;
-if (!continuesLineComment(*FormatTok, *Line) &&
+FormatTok->ContinuesLineCommentSection =
+continuesLineComment(*FormatTok, *Line);
+if (!FormatTok->ContinuesLineCommentSection &&
 (isOnNewLine(*FormatTok) || FormatTok->IsFirst)) {
   CommentsInCurrentLine = false;
 }
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -951,7 +951,46 @@
"  c\n"
"};",
getLLVMStyleWithColumns(20)));
-
+  EXPECT_EQ("enum A {\n"
+"  a, // line 1\n"
+"  // line 2\n"
+"};",
+format("enum A {\n"
+   "  a, // line 1\n"
+   "  // line 2\n"
+   "};",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("enum A {\n"
+"  a, // line 1\n"
+ 

[PATCH] D29450: [clang-format] Don't reflow across comment pragmas.

2017-02-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

That sounds reasonable. However it won't work with comment pragmas in newlines 
in block comments.
The root issue that I was looking at was a taze directive inside a block 
comment in a random typescript file, like:

  /* random stuff
* long long long long
* taze directive
*/


https://reviews.llvm.org/D29450



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


[PATCH] D29450: [clang-format] Don't reflow across comment pragmas.

2017-02-02 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

I am bit unsure about the design here. Could we instead match against the 
CommentPragmas and then not even create a BreakableToken (or reflow) if that 
matches?

I guess that would make us unable to reflow if only part of the comment is a 
pragma, but that seems ok (for now at least).


https://reviews.llvm.org/D29450



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


[PATCH] D29451: Add a prototype for clangd v0.1

2017-02-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

looks good!


https://reviews.llvm.org/D29451



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


[PATCH] D29451: Add a prototype for clangd v0.1

2017-02-02 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer created this revision.
Herald added a subscriber: mgorny.

clangd is a language server protocol implementation based on clang. It's
supposed to provide editor integration while not suffering from the
confined ABI of libclang.

This implementation is limited to the bare minimum functionality of
doing (whole-document) formatting and rangeFormatting. The JSON parsing
is based on LLVM's YAMLParser but yet most of the code of clangd is
currently dealing with JSON serialization and deserialization.

This was only tested with VS Code so far, mileage with other LSP clients
may vary.


https://reviews.llvm.org/D29451

Files:
  CMakeLists.txt
  clangd/CMakeLists.txt
  clangd/ClangDMain.cpp
  clangd/DocumentStore.h
  clangd/JSONRPCDispatcher.cpp
  clangd/JSONRPCDispatcher.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  test/clangd/formatting.txt

Index: test/clangd/formatting.txt
===
--- /dev/null
+++ test/clangd/formatting.txt
@@ -0,0 +1,53 @@
+# RUN: sed -e '/^#/d' %s | clangd | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+# CHECK: Content-Length: 191
+# CHECK: {"jsonrpc":"2.0","id":0,"result":{"capabilities":{
+# CHECK:  "textDocumentSync": 1,
+# CHECK:  "documentFormattingProvider": true,
+# CHECK:  "documentRangeFormattingProvider": true
+# CHECK:}}}
+#
+Content-Length: 193
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"int foo ( int x ) {\nx = x+1;\nreturn x;\n}"}}}
+#
+#
+Content-Length: 233
+
+{"jsonrpc":"2.0","id":1,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":1,"character":4},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}}
+# CHECK: {"jsonrpc":"2.0","id":1,"result":[{"range": {"start": {"line": 0, "character": 19}, "end": {"line": 1, "character": 4}}, "newText": "\n  "},{"range": {"start": {"line": 1, "character": 9}, "end": {"line": 1, "character": 9}}, "newText": " "},{"range": {"start": {"line": 1, "character": 10}, "end": {"line": 1, "character": 10}}, "newText": " "},{"range": {"start": {"line": 1, "character": 12}, "end": {"line": 2, "character": 4}}, "newText": "\n  "}]}
+#
+#
+Content-Length: 197
+
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///foo.c","version":5},"contentChanges":[{"text":"int foo ( int x ) {\n  x = x + 1;\n  return x;\n}"}]}}
+#
+#
+Content-Length: 233
+
+{"jsonrpc":"2.0","id":2,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"file:///foo.c"},"range":{"start":{"line":1,"character":2},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}}
+# CHECK: {"jsonrpc":"2.0","id":2,"result":[]}
+#
+Content-Length: 153
+
+{"jsonrpc":"2.0","id":3,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}}
+# CHECK: {"jsonrpc":"2.0","id":3,"result":[{"range": {"start": {"line": 0, "character": 7}, "end": {"line": 0, "character": 8}}, "newText": ""},{"range": {"start": {"line": 0, "character": 9}, "end": {"line": 0, "character": 10}}, "newText": ""},{"range": {"start": {"line": 0, "character": 15}, "end": {"line": 0, "character": 16}}, "newText": ""},{"range": {"start": {"line": 2, "character": 11}, "end": {"line": 3, "character": 4}}, "newText": "\n"}]}
+#
+#
+Content-Length: 190
+
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///foo.c","version":9},"contentChanges":[{"text":"int foo(int x) {\n  x = x + 1;\n  return x;\n}"}]}}
+#
+#
+Content-Length: 153
+
+{"jsonrpc":"2.0","id":4,"method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}}
+# CHECK: {"jsonrpc":"2.0","id":4,"result":[]}
+#
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
Index: clangd/ProtocolHandlers.h
===
--- /dev/null
+++ clangd/ProtocolHandlers.h
@@ -0,0 +1,100 @@
+//===--- ProtocolHandlers.h - LSP callbacks -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file contains the actions performed when the server gets a specific
+// request.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCO

[PATCH] D29444: [clang-format] Fix breaking of comment sections in unwrapped lines containing newlines.

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

Nice :)


https://reviews.llvm.org/D29444



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


[PATCH] D29447: [change-namespace] check using shadow decl correctly when shortening namespace specifiers.

2017-02-02 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.

This fixes mismatch between template decls and template specialization decls.

Also added a few more test cases.


https://reviews.llvm.org/D29447

Files:
  change-namespace/ChangeNamespace.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -1255,7 +1255,7 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
-TEST_F(ChangeNamespaceTest, UsingDeclInTheParentOfOldNamespace) {
+TEST_F(ChangeNamespaceTest, UsingShadowDeclInTheParentOfOldNamespace) {
   OldNamespace = "nb::nc";
   NewNamespace = "nb::nd";
   std::string Code = "namespace na { class A {}; }\n"
@@ -1277,6 +1277,74 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, UsingShadowDeclInOldNamespace) {
+  OldNamespace = "nb";
+  NewNamespace = "nc";
+  std::string Code = "namespace na { class A {}; }\n"
+ "namespace nb {\n"
+ "using na::A;\n"
+ "void d() { A a; }\n"
+ "struct X { A a; };\n"
+ "} // nb\n";
+
+  std::string Expected = "namespace na { class A {}; }\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::A;\n"
+ "void d() { A a; }\n"
+ "struct X { A a; };\n"
+ "} // namespace nc\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, UsingShadowDeclOfTemplateClass) {
+  OldNamespace = "nb";
+  NewNamespace = "nc";
+  std::string Code = "namespace na {\n"
+ "template \n"
+ "class A { T t; };\n"
+ "} // namespace na\n"
+ "namespace nb {\n"
+ "using na::A;\n"
+ "void d() { A a; }\n"
+ "} // nb\n";
+
+  std::string Expected = "namespace na {\n"
+ "template \n"
+ "class A { T t; };\n"
+ "} // namespace na\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::A;\n"
+ "void d() { A a; }\n"
+ "} // namespace nc\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, UsingShadowDeclOfTemplateFunction) {
+  OldNamespace = "nb";
+  NewNamespace = "nc";
+  std::string Code = "namespace na {\n"
+ "template \n"
+ "void f() { T t; };\n"
+ "} // namespace na\n"
+ "namespace nb {\n"
+ "using na::f;\n"
+ "void d() { f(); }\n"
+ "} // nb\n";
+
+  std::string Expected = "namespace na {\n"
+ "template \n"
+ "void f() { T t; };\n"
+ "} // namespace na\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::f;\n"
+ "void d() { f(); }\n"
+ "} // namespace nc\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, UsingAliasDecl) {
   std::string Code =
   "namespace nx { namespace ny { class X {}; } }\n"
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -761,7 +761,8 @@
 if (isDeclVisibleAtLocation(*Result.SourceManager, Using, DeclCtx, Start)) {
   for (const auto *UsingShadow : Using->shadows()) {
 const auto *TargetDecl = UsingShadow->getTargetDecl();
-if (TargetDecl == FromDecl) {
+if (TargetDecl->getQualifiedNameAsString() ==
+FromDecl->getQualifiedNameAsString()) {
   ReplaceName = FromDecl->getNameAsString();
   Matched = true;
   break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r293881 - Extend XFAIL to c++98.

2017-02-02 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Thu Feb  2 05:56:26 2017
New Revision: 293881

URL: http://llvm.org/viewvc/llvm-project?rev=293881&view=rev
Log:
Extend XFAIL to c++98.

NFC.

Modified:

libcxx/trunk/test/std/diagnostics/syserr/syserr.errcode/syserr.errcode.observers/bool.fail.cpp

Modified: 
libcxx/trunk/test/std/diagnostics/syserr/syserr.errcode/syserr.errcode.observers/bool.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/diagnostics/syserr/syserr.errcode/syserr.errcode.observers/bool.fail.cpp?rev=293881&r1=293880&r2=293881&view=diff
==
--- 
libcxx/trunk/test/std/diagnostics/syserr/syserr.errcode/syserr.errcode.observers/bool.fail.cpp
 (original)
+++ 
libcxx/trunk/test/std/diagnostics/syserr/syserr.errcode/syserr.errcode.observers/bool.fail.cpp
 Thu Feb  2 05:56:26 2017
@@ -7,7 +7,7 @@
 //
 
//===--===//
 
-// XFAIL: c++03
+// XFAIL: c++98, c++03
 
 // 
 


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


[PATCH] D29396: [clang-format] Don't reflow lines starting with TODO, FIXME or XXX.

2017-02-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293878: [clang-format] Don't reflow lines starting with 
TODO, FIXME or XXX. (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29396?vs=86643&id=86781#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29396

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -301,12 +301,21 @@
 
 static bool mayReflowContent(StringRef Content) {
   Content = Content.trim(Blanks);
+  // Lines starting with '@' commonly have special meaning.
+  static const SmallVector kSpecialMeaningPrefixes = {
+  "@", "TODO", "FIXME", "XXX"};
+  bool hasSpecialMeaningPrefix = false;
+  for (StringRef Prefix : kSpecialMeaningPrefixes) {
+if (Content.startswith(Prefix)) {
+  hasSpecialMeaningPrefix = true;
+  break;
+}
+  }
   // Simple heuristic for what to reflow: content should contain at least two
   // characters and either the first or second character must be
   // non-punctuation.
-  return Content.size() >= 2 &&
- // Lines starting with '@' commonly have special meaning.
- !Content.startswith("@") && !Content.endswith("\\") &&
+  return Content.size() >= 2 && !hasSpecialMeaningPrefix &&
+ !Content.endswith("\\") &&
  // Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is
  // true, then the first code point must be 1 byte long.
  (!isPunctuation(Content[0]) || !isPunctuation(Content[1]));
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -2306,6 +2306,30 @@
 format("// long long long long\n"
"// @param arg",
getLLVMStyleWithColumns(20)));
+  
+  // Don't reflow lines starting with 'TODO'.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// TODO: long",
+format("// long long long long\n"
+   "// TODO: long",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't reflow lines starting with 'FIXME'.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// FIXME: long",
+format("// long long long long\n"
+   "// FIXME: long",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't reflow lines starting with 'XXX'.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// XXX: long",
+format("// long long long long\n"
+   "// XXX: long",
+   getLLVMStyleWithColumns(20)));
 
   // Reflow lines that have a non-punctuation character among their first 2
   // characters.


Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -301,12 +301,21 @@
 
 static bool mayReflowContent(StringRef Content) {
   Content = Content.trim(Blanks);
+  // Lines starting with '@' commonly have special meaning.
+  static const SmallVector kSpecialMeaningPrefixes = {
+  "@", "TODO", "FIXME", "XXX"};
+  bool hasSpecialMeaningPrefix = false;
+  for (StringRef Prefix : kSpecialMeaningPrefixes) {
+if (Content.startswith(Prefix)) {
+  hasSpecialMeaningPrefix = true;
+  break;
+}
+  }
   // Simple heuristic for what to reflow: content should contain at least two
   // characters and either the first or second character must be
   // non-punctuation.
-  return Content.size() >= 2 &&
- // Lines starting with '@' commonly have special meaning.
- !Content.startswith("@") && !Content.endswith("\\") &&
+  return Content.size() >= 2 && !hasSpecialMeaningPrefix &&
+ !Content.endswith("\\") &&
  // Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is
  // true, then the first code point must be 1 byte long.
  (!isPunctuation(Content[0]) || !isPunctuation(Content[1]));
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -2306,6 +2306,30 @@
 format("// long long long long\n"
"// @param arg",
getLLVMStyleWithColumns(20)));
+  
+  // Don't reflow lines starting with 'TODO'.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// TODO: long",
+format("// long long long long\n"
+   "// TODO: long",
+   getLLVMStyleWithColumns(20)));
+
+  // 

r293878 - [clang-format] Don't reflow lines starting with TODO, FIXME or XXX.

2017-02-02 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Feb  2 04:52:08 2017
New Revision: 293878

URL: http://llvm.org/viewvc/llvm-project?rev=293878&view=rev
Log:
[clang-format] Don't reflow lines starting with TODO, FIXME or XXX.

Summary: These lines commonly carry a special meaning.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

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

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=293878&r1=293877&r2=293878&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Thu Feb  2 04:52:08 2017
@@ -301,12 +301,21 @@ const FormatToken &BreakableComment::tok
 
 static bool mayReflowContent(StringRef Content) {
   Content = Content.trim(Blanks);
+  // Lines starting with '@' commonly have special meaning.
+  static const SmallVector kSpecialMeaningPrefixes = {
+  "@", "TODO", "FIXME", "XXX"};
+  bool hasSpecialMeaningPrefix = false;
+  for (StringRef Prefix : kSpecialMeaningPrefixes) {
+if (Content.startswith(Prefix)) {
+  hasSpecialMeaningPrefix = true;
+  break;
+}
+  }
   // Simple heuristic for what to reflow: content should contain at least two
   // characters and either the first or second character must be
   // non-punctuation.
-  return Content.size() >= 2 &&
- // Lines starting with '@' commonly have special meaning.
- !Content.startswith("@") && !Content.endswith("\\") &&
+  return Content.size() >= 2 && !hasSpecialMeaningPrefix &&
+ !Content.endswith("\\") &&
  // Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is
  // true, then the first code point must be 1 byte long.
  (!isPunctuation(Content[0]) || !isPunctuation(Content[1]));

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293878&r1=293877&r2=293878&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Feb  2 04:52:08 2017
@@ -2306,6 +2306,30 @@ TEST_F(FormatTest, ReflowsComments) {
 format("// long long long long\n"
"// @param arg",
getLLVMStyleWithColumns(20)));
+  
+  // Don't reflow lines starting with 'TODO'.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// TODO: long",
+format("// long long long long\n"
+   "// TODO: long",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't reflow lines starting with 'FIXME'.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// FIXME: long",
+format("// long long long long\n"
+   "// FIXME: long",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't reflow lines starting with 'XXX'.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// XXX: long",
+format("// long long long long\n"
+   "// XXX: long",
+   getLLVMStyleWithColumns(20)));
 
   // Reflow lines that have a non-punctuation character among their first 2
   // characters.


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


r293877 - Improve docs: Add missing #pragma push directive.

2017-02-02 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Thu Feb  2 04:35:18 2017
New Revision: 293877

URL: http://llvm.org/viewvc/llvm-project?rev=293877&view=rev
Log:
Improve docs: Add missing #pragma push directive.

NFC.

Modified:
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=293877&r1=293876&r2=293877&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Thu Feb  2 04:35:18 2017
@@ -757,6 +757,7 @@ existed.
   #if foo
   #endif foo // warning: extra tokens at end of #endif directive
 
+  #pragma clang diagnostic push
   #pragma clang diagnostic ignored "-Wextra-tokens"
 
   #if foo


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


Re: r293787 - [CodeGen][ObjC] Avoid asserting on block pointer types in

2017-02-02 Thread Alex L via cfe-commits
Thanks!

On 1 February 2017 at 18:57, Hans Wennborg  wrote:

> OK. Merged in r293797.
>
> Thanks,
> Hans
>
> On Wed, Feb 1, 2017 at 9:50 AM, Alex L  wrote:
> > Hi Hans,
> >
> > Would it be possible to merge this for 4.0?
> >
> > Cheers,
> > Alex
> >
> > On 1 February 2017 at 17:37, Alex Lorenz via cfe-commits
> >  wrote:
> >>
> >> Author: arphaman
> >> Date: Wed Feb  1 11:37:28 2017
> >> New Revision: 293787
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=293787&view=rev
> >> Log:
> >> [CodeGen][ObjC] Avoid asserting on block pointer types in
> >> isPointerZeroInitializable
> >>
> >> rdar://30111891
> >>
> >> Added:
> >> cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m
> >> Modified:
> >> cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
> >>
> >> Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
> >> URL:
> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> CodeGenTypes.cpp?rev=293787&r1=293786&r2=293787&view=diff
> >>
> >> 
> ==
> >> --- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
> >> +++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Wed Feb  1 11:37:28 2017
> >> @@ -738,7 +738,7 @@ CodeGenTypes::getCGRecordLayout(const Re
> >>  }
> >>
> >>  bool CodeGenTypes::isPointerZeroInitializable(QualType T) {
> >> -  assert (T->isAnyPointerType() && "Invalid type");
> >> +  assert((T->isAnyPointerType() || T->isBlockPointerType()) && "Invalid
> >> type");
> >>return isZeroInitializable(T);
> >>  }
> >>
> >>
> >> Added: cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m
> >> URL:
> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGenObjC/block-ptr-type-crash.m?rev=293787&view=auto
> >>
> >> 
> ==
> >> --- cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m (added)
> >> +++ cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m Wed Feb  1
> 11:37:28
> >> 2017
> >> @@ -0,0 +1,28 @@
> >> +// RUN: %clang_cc1 -Wno-objc-root-class -fblocks -o /dev/null -triple
> >> x86_64-- -emit-llvm %s
> >> +// REQUIRES: asserts
> >> +// Verify there is no assertion.
> >> +
> >> +// rdar://30111891
> >> +
> >> +typedef unsigned long long uint64_t;
> >> +typedef enum AnEnum : uint64_t AnEnum;
> >> +enum AnEnum: uint64_t {
> >> +AnEnumA
> >> +};
> >> +
> >> +typedef void (^BlockType)();
> >> +@interface MyClass
> >> +@end
> >> +@implementation MyClass
> >> +- (void)_doStuff {
> >> +  struct {
> >> +int identifier;
> >> +AnEnum type;
> >> +BlockType handler;
> >> +  } var = {
> >> +"hello",
> >> +AnEnumA,
> >> +((void *)0)
> >> +  };
> >> +}
> >> +@end
> >>
> >>
> >> ___
> >> 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


r293875 - clang-format: Do not use two-argument/operand special case with no alignment

2017-02-02 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Feb  2 02:30:21 2017
New Revision: 293875

URL: http://llvm.org/viewvc/llvm-project?rev=293875&view=rev
Log:
clang-format: Do not use two-argument/operand special case with no alignment

Without alignment, there is no clean separation between the arguments, even if
there are only two.

Before:
  aa(
  , a +
  aa);

After:
  aa(,
 aaa +
 aa);

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=293875&r1=293874&r2=293875&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Feb  2 02:30:21 2017
@@ -429,7 +429,7 @@ void ContinuationIndenter::addTokenOnCur
 // does not help.
 bool HasTwoOperands =
 P->OperatorIndex == 0 && !P->NextOperator && 
!P->is(TT_ConditionalExpr);
-if ((!BreakBeforeOperator && !HasTwoOperands) ||
+if ((!BreakBeforeOperator && !(HasTwoOperands && Style.AlignOperands)) ||
 (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator))
   State.Stack.back().NoLineBreakInOperand = true;
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293875&r1=293874&r2=293875&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Feb  2 02:30:21 2017
@@ -4163,6 +4163,10 @@ TEST_F(FormatTest, EnforcedOperatorWraps
 TEST_F(FormatTest, NoOperandAlignment) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignOperands = false;
+  verifyFormat("aa(,\n"
+   "   a +\n"
+   "   aa);",
+   Style);
   Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
   verifyFormat("bool value = a\n"
"+ a\n"


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


[PATCH] D29384: [analyzer] Fix an assertion fail in CStringSyntaxChecker

2017-02-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293874: [analyzer] Fix an assertion fail in 
CStringSyntaxChecker. (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D29384?vs=86599&id=86773#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29384

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
  cfe/trunk/test/Analysis/cstring-syntax.c


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
@@ -36,25 +36,24 @@
   AnalysisDeclContext* AC;
 
   /// Check if two expressions refer to the same declaration.
-  inline bool sameDecl(const Expr *A1, const Expr *A2) {
-if (const DeclRefExpr *D1 = dyn_cast(A1->IgnoreParenCasts()))
-  if (const DeclRefExpr *D2 = 
dyn_cast(A2->IgnoreParenCasts()))
+  bool sameDecl(const Expr *A1, const Expr *A2) {
+if (const auto *D1 = dyn_cast(A1->IgnoreParenCasts()))
+  if (const auto *D2 = dyn_cast(A2->IgnoreParenCasts()))
 return D1->getDecl() == D2->getDecl();
 return false;
   }
 
   /// Check if the expression E is a sizeof(WithArg).
-  inline bool isSizeof(const Expr *E, const Expr *WithArg) {
-if (const UnaryExprOrTypeTraitExpr *UE =
-dyn_cast(E))
-  if (UE->getKind() == UETT_SizeOf)
+  bool isSizeof(const Expr *E, const Expr *WithArg) {
+if (const auto *UE = dyn_cast(E))
+  if (UE->getKind() == UETT_SizeOf && !UE->isArgumentType())
 return sameDecl(UE->getArgumentExpr(), WithArg);
 return false;
   }
 
   /// Check if the expression E is a strlen(WithArg).
-  inline bool isStrlen(const Expr *E, const Expr *WithArg) {
-if (const CallExpr *CE = dyn_cast(E)) {
+  bool isStrlen(const Expr *E, const Expr *WithArg) {
+if (const auto *CE = dyn_cast(E)) {
   const FunctionDecl *FD = CE->getDirectCallee();
   if (!FD)
 return false;
@@ -65,14 +64,14 @@
   }
 
   /// Check if the expression is an integer literal with value 1.
-  inline bool isOne(const Expr *E) {
-if (const IntegerLiteral *IL = dyn_cast(E))
+  bool isOne(const Expr *E) {
+if (const auto *IL = dyn_cast(E))
   return (IL->getValue().isIntN(1));
 return false;
   }
 
-  inline StringRef getPrintableName(const Expr *E) {
-if (const DeclRefExpr *D = dyn_cast(E->IgnoreParenCasts()))
+  StringRef getPrintableName(const Expr *E) {
+if (const auto *D = dyn_cast(E->IgnoreParenCasts()))
   return D->getDecl()->getName();
 return StringRef();
   }
@@ -82,8 +81,8 @@
   bool containsBadStrncatPattern(const CallExpr *CE);
 
 public:
-  WalkAST(const CheckerBase *checker, BugReporter &br, AnalysisDeclContext *ac)
-  : Checker(checker), BR(br), AC(ac) {}
+  WalkAST(const CheckerBase *Checker, BugReporter &BR, AnalysisDeclContext *AC)
+  : Checker(Checker), BR(BR), AC(AC) {}
 
   // Statement visitor methods.
   void VisitChildren(Stmt *S);
@@ -108,8 +107,7 @@
   const Expr *LenArg = CE->getArg(2);
 
   // Identify wrong size expressions, which are commonly used instead.
-  if (const BinaryOperator *BE =
-  dyn_cast(LenArg->IgnoreParenCasts())) {
+  if (const auto *BE = dyn_cast(LenArg->IgnoreParenCasts())) {
 // - sizeof(dst) - strlen(dst)
 if (BE->getOpcode() == BO_Sub) {
   const Expr *L = BE->getLHS();
Index: cfe/trunk/test/Analysis/cstring-syntax.c
===
--- cfe/trunk/test/Analysis/cstring-syntax.c
+++ cfe/trunk/test/Analysis/cstring-syntax.c
@@ -10,4 +10,6 @@
   strncat(dest, "AAA", sizeof(dest)); // 
expected-warning {{Potential buffer overflow. Replace with}}
   strncat(dest, "AAA", sizeof(dest) - 
strlen(dest)); // expected-warning {{Potential buffer overflow. Replace with}}
   strncat(dest, src, sizeof(src)); // expected-warning {{Potential buffer 
overflow. Replace with}}
+  // Should not crash when sizeof has a type argument.
+  strncat(dest, "AAA", sizeof(char));
 }


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
@@ -36,25 +36,24 @@
   AnalysisDeclContext* AC;
 
   /// Check if two expressions refer to the same declaration.
-  inline bool sameDecl(const Expr *A1, const Expr *A2) {
-if (const DeclRefExpr *D1 = dyn_cast(A1->IgnoreParenCasts()))
-  if (const DeclRefExpr *D2 = dyn_cast(A2->IgnoreParenCasts()))
+  bool sameDecl(const Expr *A1, const Expr *A2) {
+if (const auto *D1 = dyn_cast(A1->IgnoreParenCasts()))
+  if (const auto *D2 = dyn_cast(A2->IgnoreParenCasts()))
 return D1->getDecl()

r293874 - [analyzer] Fix an assertion fail in CStringSyntaxChecker.

2017-02-02 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Thu Feb  2 02:20:54 2017
New Revision: 293874

URL: http://llvm.org/viewvc/llvm-project?rev=293874&view=rev
Log:
[analyzer] Fix an assertion fail in CStringSyntaxChecker.

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


Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
cfe/trunk/test/Analysis/cstring-syntax.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp?rev=293874&r1=293873&r2=293874&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp Thu Feb  2 
02:20:54 2017
@@ -36,25 +36,24 @@ class WalkAST: public StmtVisitor(A1->IgnoreParenCasts()))
-  if (const DeclRefExpr *D2 = 
dyn_cast(A2->IgnoreParenCasts()))
+  bool sameDecl(const Expr *A1, const Expr *A2) {
+if (const auto *D1 = dyn_cast(A1->IgnoreParenCasts()))
+  if (const auto *D2 = dyn_cast(A2->IgnoreParenCasts()))
 return D1->getDecl() == D2->getDecl();
 return false;
   }
 
   /// Check if the expression E is a sizeof(WithArg).
-  inline bool isSizeof(const Expr *E, const Expr *WithArg) {
-if (const UnaryExprOrTypeTraitExpr *UE =
-dyn_cast(E))
-  if (UE->getKind() == UETT_SizeOf)
+  bool isSizeof(const Expr *E, const Expr *WithArg) {
+if (const auto *UE = dyn_cast(E))
+  if (UE->getKind() == UETT_SizeOf && !UE->isArgumentType())
 return sameDecl(UE->getArgumentExpr(), WithArg);
 return false;
   }
 
   /// Check if the expression E is a strlen(WithArg).
-  inline bool isStrlen(const Expr *E, const Expr *WithArg) {
-if (const CallExpr *CE = dyn_cast(E)) {
+  bool isStrlen(const Expr *E, const Expr *WithArg) {
+if (const auto *CE = dyn_cast(E)) {
   const FunctionDecl *FD = CE->getDirectCallee();
   if (!FD)
 return false;
@@ -65,14 +64,14 @@ class WalkAST: public StmtVisitor(E))
+  bool isOne(const Expr *E) {
+if (const auto *IL = dyn_cast(E))
   return (IL->getValue().isIntN(1));
 return false;
   }
 
-  inline StringRef getPrintableName(const Expr *E) {
-if (const DeclRefExpr *D = dyn_cast(E->IgnoreParenCasts()))
+  StringRef getPrintableName(const Expr *E) {
+if (const auto *D = dyn_cast(E->IgnoreParenCasts()))
   return D->getDecl()->getName();
 return StringRef();
   }
@@ -82,8 +81,8 @@ class WalkAST: public StmtVisitorgetArg(2);
 
   // Identify wrong size expressions, which are commonly used instead.
-  if (const BinaryOperator *BE =
-  dyn_cast(LenArg->IgnoreParenCasts())) {
+  if (const auto *BE = dyn_cast(LenArg->IgnoreParenCasts())) {
 // - sizeof(dst) - strlen(dst)
 if (BE->getOpcode() == BO_Sub) {
   const Expr *L = BE->getLHS();

Modified: cfe/trunk/test/Analysis/cstring-syntax.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cstring-syntax.c?rev=293874&r1=293873&r2=293874&view=diff
==
--- cfe/trunk/test/Analysis/cstring-syntax.c (original)
+++ cfe/trunk/test/Analysis/cstring-syntax.c Thu Feb  2 02:20:54 2017
@@ -10,4 +10,6 @@ void testStrncat(const char *src) {
   strncat(dest, "AAA", sizeof(dest)); // 
expected-warning {{Potential buffer overflow. Replace with}}
   strncat(dest, "AAA", sizeof(dest) - 
strlen(dest)); // expected-warning {{Potential buffer overflow. Replace with}}
   strncat(dest, src, sizeof(src)); // expected-warning {{Potential buffer 
overflow. Replace with}}
+  // Should not crash when sizeof has a type argument.
+  strncat(dest, "AAA", sizeof(char));
 }


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


[PATCH] D29437: [ubsan] Detect signed overflow UB in remainder operations

2017-02-02 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In https://reviews.llvm.org/D29437#664379, @regehr wrote:

> Does this check need to be sensitive to the dialect of C/C++ that the user 
> asked for? I know that it used to be the case that the standard could be read 
> either way for this case, but as you observe it is now unambiguously UB.


No, I don't think the check should be sensitive to language dialect.

You're right about the C99 spec not being very explicit about what 'a % b' 
means if 'a / b' is not representable. It's simply the "remainder" of 'a / b'. 
However, clang treats 'INT_MIN % -1' as having UB in C99 mode (rightly, imho), 
so it'd be nice to have a diagnostic for it.


https://reviews.llvm.org/D29437



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


Re: Add warning for c++ member variable shadowing

2017-02-02 Thread James Sun via cfe-commits
Hi Richard

Thanks for the feedback! Hopefully addressed!

Thanks

James



From:  on behalf of Richard Smith 
Date: Wednesday, February 1, 2017 at 3:50 PM
To: James Sun 
Cc: Saleem Abdulrasool , "cfe-commits@lists.llvm.org" 
, Aaron Ballman 
Subject: Re: Add warning for c++ member variable shadowing

+  std::set bases;
+const auto baseName = 
Specifier->getType()->getAsCXXRecordDecl()->getName();

Please capitalize local variable names. Also, please don't use the record name 
as a key in your set; that's not guaranteed to be unique. Instead, you could 
either use a set of canonical types or of canonical CXXRecordDecl*s.

+for (const auto *Field : 
Specifier->getType()->getAsCXXRecordDecl()->fields()) {
+  if ((Field->getAccess() == AS_public || Field->getAccess() == 
AS_protected) &&
+  Field->getName() == FieldName) {

Use Specifier->getType()->getAsCXXRecordDecl()->lookup(Field->getName()) here 
to look up the field by name, rather than walking all the fields of all base 
classes and checking if each of them has the right name. You should also check 
for IndirectFieldDecls, for this case:

  struct A {
union { int x; float f; };
  };
  struct B : A {
int x;
  };

+bases.emplace(baseName);

It's more efficient to use insert rather than emplace when inserting an element 
into a set.

+Diag(Loc, diag::warn_shadow_field)
+  << FieldName << RD->getName() << baseName;

It'd be nice to add a note here pointing at the base class member that was 
shadowed.



On 31 January 2017 at 19:20, James Sun 
mailto:james...@fb.com>> wrote:
Fixed!

From: Saleem Abdulrasool mailto:compn...@compnerd.org>>
Date: Tuesday, January 31, 2017 at 6:53 PM

To: James Sun mailto:james...@fb.com>>
Cc: Richard Smith mailto:rich...@metafoo.co.uk>>, 
"cfe-commits@lists.llvm.org" 
mailto:cfe-commits@lists.llvm.org>>, Aaron Ballman 
mailto:aa...@aaronballman.com>>
Subject: Re: Add warning for c++ member variable shadowing

Hmm, the braces in the if (bases.find(...)...) are not needed.

Could you also add a test case for virtual inheritance?

On Mon, Jan 30, 2017 at 8:34 PM, James Sun 
mailto:james...@fb.com>> wrote:
Hi Saleem

Thanks for the quick response. A test case is added. It covers some ordinary 
cases as well as corner cases like multiple paths to the same base.

Thanks

James

From: Saleem Abdulrasool mailto:compn...@compnerd.org>>
Date: Monday, January 30, 2017 at 6:50 PM
To: James Sun mailto:james...@fb.com>>
Cc: Richard Smith mailto:rich...@metafoo.co.uk>>, 
"cfe-commits@lists.llvm.org" 
mailto:cfe-commits@lists.llvm.org>>, Aaron Ballman 
mailto:aa...@aaronballman.com>>

Subject: Re: Add warning for c++ member variable shadowing

I think that the patch is starting to look pretty good!

Can you add some test cases for the particular cases to diagnose in a separate 
test set to ensure that we have proper coverage of the various cases rather 
than relying on the existing test cases?  Something to make sure that we get 
the simple case right as well as the complex cases (e.g. we don't print 
duplicate warnings for multiple paths).


On Mon, Jan 30, 2017 at 5:50 PM, James Sun 
mailto:james...@fb.com>> wrote:
Hi Richard

Sorry for the late reply. Thank you for giving the feedback! The updated 
version is attached. Please let me know if there is anything improper.

Thanks

James

From: mailto:meta...@gmail.com>> on behalf of Richard Smith 
mailto:rich...@metafoo.co.uk>>
Date: Friday, January 27, 2017 at 3:03 PM
To: James Sun mailto:james...@fb.com>>
Cc: Saleem Abdulrasool mailto:compn...@compnerd.org>>, 
"cfe-commits@lists.llvm.org" 
mailto:cfe-commits@lists.llvm.org>>, Aaron Ballman 
mailto:aa...@aaronballman.com>>

Subject: Re: Add warning for c++ member variable shadowing

+def warn_shadow_member_variable : Warning<
+  "shadowed variable '%0' in type '%1' inheriting from type '%2'">,

The phrasing of this is incorrect: the things you're warning about are not 
variables, they're non-static data members. Perhaps something like:

  "non-static data member '%0' of '%1' shadows member inherited from type '%2'"

+   InGroup;

Would it make sense to put this in a subgroup of -Wshadow so that it can be 
controlled separately?

+  /// Check if there is a member variable shadowing

Please end comments in a period.

+  void CheckShadowInheritedVariables(const SourceLocation &Loc,

Likewise, 'Variables' is wrong. We would typically use the C term 'Fields' for 
these cases within Clang sources.

+  for (const auto &Base : DC->bases()) {
+if (const auto *TSI = Base.getTypeSourceInfo())
+  if (const auto *BaseClass = TSI->getType()->getAsCXXRecordDecl()) {
+for (const auto *Field : BaseClass->fields())
+  if (Field->getName() == FieldName)
+Diag(Loc, diag::warn_shadow_member_variable)
+  << FieldName << RD->getName() << BaseClass->getName();
+   

r293871 - Fix typo. NFC

2017-02-02 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Thu Feb  2 01:53:55 2017
New Revision: 293871

URL: http://llvm.org/viewvc/llvm-project?rev=293871&view=rev
Log:
Fix typo. NFC

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

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=293871&r1=293870&r2=293871&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Feb  2 01:53:55 2017
@@ -9956,7 +9956,7 @@ bool Expr::EvalResult::isGlobalLValue()
 // Note that to reduce code duplication, this helper does no evaluation
 // itself; the caller checks whether the expression is evaluatable, and
 // in the rare cases where CheckICE actually cares about the evaluated
-// value, it calls into Evalute.
+// value, it calls into Evaluate.
 
 namespace {
 


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