[PATCH] D27453: [OpenCL] Enable unroll hint for OpenCL 1.x.

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

https://reviews.llvm.org/D27453

Files:
  lib/Sema/SemaStmtAttr.cpp
  test/CodeGenOpenCL/unroll-hint.cl
  test/SemaOpenCL/unroll-hint.cl


Index: test/SemaOpenCL/unroll-hint.cl
===
--- test/SemaOpenCL/unroll-hint.cl
+++ test/SemaOpenCL/unroll-hint.cl
@@ -1,17 +1,5 @@
-//RUN: %clang_cc1 -O0 -fsyntax-only -verify %s
-//RUN: %clang_cc1 -O0 -cl-std=CL2.0 -fsyntax-only -verify -DCL20 %s
+//RUN: %clang_cc1 -O0 -cl-std=CL2.0 -fsyntax-only -verify %s
 
-kernel void D (global int *x) {
-  int i = 10;
-#ifndef CL20
-  // expected-error@+2 {{'opencl_unroll_hint' attribute requires OpenCL 
version 2.0 or above}}
-#endif
-  __attribute__((opencl_unroll_hint))
-  do {
-  } while(i--);
-}
-
-#ifdef CL20
 kernel void C (global int *x) {
   int I = 3;
   __attribute__((opencl_unroll_hint(I))) // expected-error 
{{'opencl_unroll_hint' attribute requires an integer constant}}
@@ -27,4 +15,3 @@
   __attribute__((opencl_unroll_hint(-1))) // expected-error 
{{'opencl_unroll_hint' attribute requires a positive integral compile time 
constant expression}}
   for(int i=0; i<100; i++);
 }
-#endif
Index: test/CodeGenOpenCL/unroll-hint.cl
===
--- test/CodeGenOpenCL/unroll-hint.cl
+++ test/CodeGenOpenCL/unroll-hint.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL1.2 -o - %s | FileCheck %s
 
 /*** for ***/
 void for_count()
Index: lib/Sema/SemaStmtAttr.cpp
===
--- lib/Sema/SemaStmtAttr.cpp
+++ lib/Sema/SemaStmtAttr.cpp
@@ -225,16 +225,12 @@
 
 static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const AttributeList &A,
 SourceRange Range) {
-  // OpenCL v2.0 s6.11.5 - opencl_unroll_hint can have 0 arguments (compiler
+  // Although the feature was introduced only in OpenCL C v2.0 s6.11.5, it's
+  // useful for OpenCL 1.x too and doesn't require HW support.
+  // opencl_unroll_hint can have 0 arguments (compiler
   // determines unrolling factor) or 1 argument (the unroll factor provided
   // by the user).
 
-  if (S.getLangOpts().OpenCLVersion < 200) {
-S.Diag(A.getLoc(), diag::err_attribute_requires_opencl_version)
-<< A.getName() << "2.0" << 1;
-return nullptr;
-  }
-
   unsigned NumArgs = A.getNumArgs();
 
   if (NumArgs > 1) {


Index: test/SemaOpenCL/unroll-hint.cl
===
--- test/SemaOpenCL/unroll-hint.cl
+++ test/SemaOpenCL/unroll-hint.cl
@@ -1,17 +1,5 @@
-//RUN: %clang_cc1 -O0 -fsyntax-only -verify %s
-//RUN: %clang_cc1 -O0 -cl-std=CL2.0 -fsyntax-only -verify -DCL20 %s
+//RUN: %clang_cc1 -O0 -cl-std=CL2.0 -fsyntax-only -verify %s
 
-kernel void D (global int *x) {
-  int i = 10;
-#ifndef CL20
-  // expected-error@+2 {{'opencl_unroll_hint' attribute requires OpenCL version 2.0 or above}}
-#endif
-  __attribute__((opencl_unroll_hint))
-  do {
-  } while(i--);
-}
-
-#ifdef CL20
 kernel void C (global int *x) {
   int I = 3;
   __attribute__((opencl_unroll_hint(I))) // expected-error {{'opencl_unroll_hint' attribute requires an integer constant}}
@@ -27,4 +15,3 @@
   __attribute__((opencl_unroll_hint(-1))) // expected-error {{'opencl_unroll_hint' attribute requires a positive integral compile time constant expression}}
   for(int i=0; i<100; i++);
 }
-#endif
Index: test/CodeGenOpenCL/unroll-hint.cl
===
--- test/CodeGenOpenCL/unroll-hint.cl
+++ test/CodeGenOpenCL/unroll-hint.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL1.2 -o - %s | FileCheck %s
 
 /*** for ***/
 void for_count()
Index: lib/Sema/SemaStmtAttr.cpp
===
--- lib/Sema/SemaStmtAttr.cpp
+++ lib/Sema/SemaStmtAttr.cpp
@@ -225,16 +225,12 @@
 
 static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const AttributeList &A,
 SourceRange Range) {
-  // OpenCL v2.0 s6.11.5 - opencl_unroll_hint can have 0 arguments (compiler
+  // Although the feature was introduced only in OpenCL C v2.0 s6.11.5, it's
+  // useful for OpenCL 1.x too and doesn't require HW support.
+  // opencl_unroll_hint can have 0 arguments (compiler
   // determines unrolling factor) or 1 argument (the unroll factor provided
   // by the user).
 
-  if (S.getLangOpts().OpenCLVersion < 200) {
-S.Diag(A.getLoc(), diag::err_attribute_requires_opencl_version)
-<< A.getName() << "2.0" << 1;
-return nullptr;
-  }
-
   unsigned NumArgs = A.getNumArgs();
 
   if (NumArgs > 1) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
ht

r288890 - [OpenCL] Fix SPIR version generation.

2016-12-07 Thread Alexey Bader via cfe-commits
Author: bader
Date: Wed Dec  7 02:38:24 2016
New Revision: 288890

URL: http://llvm.org/viewvc/llvm-project?rev=288890&view=rev
Log:
[OpenCL] Fix SPIR version generation.

Patch by Egor Churaev (echuraev).

Reviewers: Anastasia

Subscribers: bader, yaxunl, cfe-commits

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


Modified:
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGenOpenCL/spir_version.cl

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=288890&r1=29&r2=288890&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Dec  7 02:38:24 2016
@@ -7801,8 +7801,10 @@ void SPIRTargetCodeGenInfo::emitTargetMD
   // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
   // opencl.spir.version named metadata.
   llvm::Metadata *SPIRVerElts[] = {
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 2)),
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 0))};
+  llvm::ConstantAsMetadata::get(
+  llvm::ConstantInt::get(Int32Ty, CGM.getLangOpts().OpenCLVersion / 
100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (CGM.getLangOpts().OpenCLVersion / 100 > 1) ? 0 : 2))};
   llvm::NamedMDNode *SPIRVerMD =
   M.getOrInsertNamedMetadata("opencl.spir.version");
   SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));

Modified: cfe/trunk/test/CodeGenOpenCL/spir_version.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/spir_version.cl?rev=288890&r1=29&r2=288890&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/spir_version.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/spir_version.cl Wed Dec  7 02:38:24 2016
@@ -13,19 +13,22 @@ kernel void foo() {}
 
 // CHECK-SPIR-CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
 // CHECK-SPIR-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-SPIR-CL10: [[SPIR]] = !{i32 2, i32 0}
+// CHECK-SPIR-CL10: [[SPIR]] = !{i32 1, i32 2}
 // CHECK-SPIR-CL10: [[OCL]] = !{i32 1, i32 0}
-// CHECK-SPIR-CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-SPIR-CL12: [[SPIR]] = !{i32 2, i32 0}
-// CHECK-SPIR-CL12: [[OCL]] = !{i32 1, i32 2}
-// CHECK-SPIR-CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL20: [[SPIR]] = !{i32 2, i32 0}
+// CHECK-SPIR-CL12: !opencl.spir.version = !{[[VER:![0-9]+]]}
+// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[VER]]}
+// CHECK-SPIR-CL12: [[VER]] = !{i32 1, i32 2}
 
+// CHECK-SPIR-CL20: !opencl.spir.version = !{[[VER:![0-9]+]]}
+// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[VER]]}
+// CHECK-SPIR-CL20: [[VER]] = !{i32 2, i32 0}
+
+// CHECK-AMDGCN-CL10-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
 // CHECK-AMDGCN-CL10: [[OCL]] = !{i32 1, i32 0}
+// CHECK-AMDGCN-CL12-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
 // CHECK-AMDGCN-CL12: [[OCL]] = !{i32 1, i32 2}
+// CHECK-AMDGCN-CL20-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL20: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-AMDGCN-CL20: [[OCL]] = !{i32 2, i32 0}
\ No newline at end of file
+// CHECK-AMDGCN-CL20: [[OCL]] = !{i32 2, i32 0}


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


[PATCH] D27300: [OpenCL] Fix SPIR version generation.

2016-12-07 Thread Alexey Bader via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288890: [OpenCL] Fix SPIR version generation. (authored by 
bader).

Changed prior to commit:
  https://reviews.llvm.org/D27300?vs=80229&id=80548#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27300

Files:
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/test/CodeGenOpenCL/spir_version.cl


Index: cfe/trunk/test/CodeGenOpenCL/spir_version.cl
===
--- cfe/trunk/test/CodeGenOpenCL/spir_version.cl
+++ cfe/trunk/test/CodeGenOpenCL/spir_version.cl
@@ -13,19 +13,22 @@
 
 // CHECK-SPIR-CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
 // CHECK-SPIR-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-SPIR-CL10: [[SPIR]] = !{i32 2, i32 0}
+// CHECK-SPIR-CL10: [[SPIR]] = !{i32 1, i32 2}
 // CHECK-SPIR-CL10: [[OCL]] = !{i32 1, i32 0}
-// CHECK-SPIR-CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-SPIR-CL12: [[SPIR]] = !{i32 2, i32 0}
-// CHECK-SPIR-CL12: [[OCL]] = !{i32 1, i32 2}
-// CHECK-SPIR-CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL20: [[SPIR]] = !{i32 2, i32 0}
+// CHECK-SPIR-CL12: !opencl.spir.version = !{[[VER:![0-9]+]]}
+// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[VER]]}
+// CHECK-SPIR-CL12: [[VER]] = !{i32 1, i32 2}
 
+// CHECK-SPIR-CL20: !opencl.spir.version = !{[[VER:![0-9]+]]}
+// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[VER]]}
+// CHECK-SPIR-CL20: [[VER]] = !{i32 2, i32 0}
+
+// CHECK-AMDGCN-CL10-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
 // CHECK-AMDGCN-CL10: [[OCL]] = !{i32 1, i32 0}
+// CHECK-AMDGCN-CL12-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
 // CHECK-AMDGCN-CL12: [[OCL]] = !{i32 1, i32 2}
+// CHECK-AMDGCN-CL20-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL20: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-AMDGCN-CL20: [[OCL]] = !{i32 2, i32 0}
\ No newline at end of file
+// CHECK-AMDGCN-CL20: [[OCL]] = !{i32 2, i32 0}
Index: cfe/trunk/lib/CodeGen/TargetInfo.cpp
===
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp
@@ -7801,8 +7801,10 @@
   // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
   // opencl.spir.version named metadata.
   llvm::Metadata *SPIRVerElts[] = {
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 2)),
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 0))};
+  llvm::ConstantAsMetadata::get(
+  llvm::ConstantInt::get(Int32Ty, CGM.getLangOpts().OpenCLVersion / 
100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (CGM.getLangOpts().OpenCLVersion / 100 > 1) ? 0 : 2))};
   llvm::NamedMDNode *SPIRVerMD =
   M.getOrInsertNamedMetadata("opencl.spir.version");
   SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));


Index: cfe/trunk/test/CodeGenOpenCL/spir_version.cl
===
--- cfe/trunk/test/CodeGenOpenCL/spir_version.cl
+++ cfe/trunk/test/CodeGenOpenCL/spir_version.cl
@@ -13,19 +13,22 @@
 
 // CHECK-SPIR-CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
 // CHECK-SPIR-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-SPIR-CL10: [[SPIR]] = !{i32 2, i32 0}
+// CHECK-SPIR-CL10: [[SPIR]] = !{i32 1, i32 2}
 // CHECK-SPIR-CL10: [[OCL]] = !{i32 1, i32 0}
-// CHECK-SPIR-CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-SPIR-CL12: [[SPIR]] = !{i32 2, i32 0}
-// CHECK-SPIR-CL12: [[OCL]] = !{i32 1, i32 2}
-// CHECK-SPIR-CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]}
-// CHECK-SPIR-CL20: [[SPIR]] = !{i32 2, i32 0}
+// CHECK-SPIR-CL12: !opencl.spir.version = !{[[VER:![0-9]+]]}
+// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[VER]]}
+// CHECK-SPIR-CL12: [[VER]] = !{i32 1, i32 2}
 
+// CHECK-SPIR-CL20: !opencl.spir.version = !{[[VER:![0-9]+]]}
+// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[VER]]}
+// CHECK-SPIR-CL20: [[VER]] = !{i32 2, i32 0}
+
+// CHECK-AMDGCN-CL10-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
 // CHECK-AMDGCN-CL10: [[OCL]] = !{i32 1, i32 0}
+// CHECK-AMDGCN-CL12-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
 // CHECK-AMDGCN-CL12: [[OCL]] = !{i32 1, i32 2}
+// CHECK-AMDGCN-CL20-NOT: !opencl.spir.version
 // CHECK-AMDGCN-CL20: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
-// CHECK-AMDGCN-CL20: [[OCL]] = !{i32 2, i32 0}
\ No newline at end of file
+// CHECK-AMDGCN-CL20: [[OCL]] = !{i32 2, i32 0}
Index: cfe/trunk/lib/CodeGen/TargetInfo.cpp
===

r288891 - [OpenCL] Added a LIT test for ensuring address space mangling is done the same both in OpenCL1.2 and OpenCL2.0.

2016-12-07 Thread Alexey Bader via cfe-commits
Author: bader
Date: Wed Dec  7 02:43:49 2016
New Revision: 288891

URL: http://llvm.org/viewvc/llvm-project?rev=288891&view=rev
Log:
[OpenCL] Added a LIT test for ensuring address space mangling is done the same 
both in OpenCL1.2 and OpenCL2.0.

Patch by Egor Churaev (echuraev).

Reviewers: Anastasia

Subscribers: yaxunl, cfe-commits, bader

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

Modified:
cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl

Modified: cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl?rev=288891&r1=288890&r2=288891&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl Wed Dec  7 02:43:49 
2016
@@ -1,6 +1,10 @@
 // RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck -check-prefix=ASMANG %s
 // RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefix=NOASMANG 
%s
 
+// We check that the address spaces are mangled the same in both version of 
OpenCL
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL2.0 -emit-llvm -o 
- | FileCheck -check-prefix=OCL-20 %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL1.2 -emit-llvm -o 
- | FileCheck -check-prefix=OCL-12 %s
+
 // We can't name this f as private is equivalent to default
 // no specifier given address space so we get multiple definition
 // warnings, but we do want it for comparison purposes.
@@ -8,23 +12,33 @@ __attribute__((overloadable))
 void ff(int *arg) { }
 // ASMANG: @_Z2ffPi
 // NOASMANG: @_Z2ffPi
+// OCL-20-DAG: @_Z2ffPU3AS4i
+// OCL-12-DAG: @_Z2ffPi
 
 __attribute__((overloadable))
 void f(private int *arg) { }
 // ASMANG: @_Z1fPi
 // NOASMANG: @_Z1fPi
+// OCL-20-DAG: @_Z1fPi
+// OCL-12-DAG: @_Z1fPi
 
 __attribute__((overloadable))
 void f(global int *arg) { }
 // ASMANG: @_Z1fPU3AS1i
 // NOASMANG: @_Z1fPU8CLglobali
+// OCL-20-DAG: @_Z1fPU3AS1i
+// OCL-12-DAG: @_Z1fPU3AS1i
 
 __attribute__((overloadable))
 void f(local int *arg) { }
 // ASMANG: @_Z1fPU3AS2i
 // NOASMANG: @_Z1fPU7CLlocali
+// OCL-20-DAG: @_Z1fPU3AS2i
+// OCL-12-DAG: @_Z1fPU3AS2i
 
 __attribute__((overloadable))
 void f(constant int *arg) { }
 // ASMANG: @_Z1fPU3AS3i
 // NOASMANG: @_Z1fPU10CLconstanti
+// OCL-20-DAG: @_Z1fPU3AS3i
+// OCL-12-DAG: @_Z1fPU3AS3i


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


[PATCH] D27403: [OpenCL] Added a LIT test for ensuring address space mangling is done the same both in OpenCL1.2 and OpenCL2.0.

2016-12-07 Thread Alexey Bader via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288891: [OpenCL] Added a LIT test for ensuring address space 
mangling is done the same… (authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D27403?vs=80401&id=80549#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27403

Files:
  cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl


Index: cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl
===
--- cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl
+++ cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl
@@ -1,30 +1,44 @@
 // RUN: %clang_cc1 %s -ffake-address-space-map 
-faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | 
FileCheck -check-prefix=ASMANG %s
 // RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no 
-triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefix=NOASMANG 
%s
 
+// We check that the address spaces are mangled the same in both version of 
OpenCL
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL2.0 -emit-llvm -o 
- | FileCheck -check-prefix=OCL-20 %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL1.2 -emit-llvm -o 
- | FileCheck -check-prefix=OCL-12 %s
+
 // We can't name this f as private is equivalent to default
 // no specifier given address space so we get multiple definition
 // warnings, but we do want it for comparison purposes.
 __attribute__((overloadable))
 void ff(int *arg) { }
 // ASMANG: @_Z2ffPi
 // NOASMANG: @_Z2ffPi
+// OCL-20-DAG: @_Z2ffPU3AS4i
+// OCL-12-DAG: @_Z2ffPi
 
 __attribute__((overloadable))
 void f(private int *arg) { }
 // ASMANG: @_Z1fPi
 // NOASMANG: @_Z1fPi
+// OCL-20-DAG: @_Z1fPi
+// OCL-12-DAG: @_Z1fPi
 
 __attribute__((overloadable))
 void f(global int *arg) { }
 // ASMANG: @_Z1fPU3AS1i
 // NOASMANG: @_Z1fPU8CLglobali
+// OCL-20-DAG: @_Z1fPU3AS1i
+// OCL-12-DAG: @_Z1fPU3AS1i
 
 __attribute__((overloadable))
 void f(local int *arg) { }
 // ASMANG: @_Z1fPU3AS2i
 // NOASMANG: @_Z1fPU7CLlocali
+// OCL-20-DAG: @_Z1fPU3AS2i
+// OCL-12-DAG: @_Z1fPU3AS2i
 
 __attribute__((overloadable))
 void f(constant int *arg) { }
 // ASMANG: @_Z1fPU3AS3i
 // NOASMANG: @_Z1fPU10CLconstanti
+// OCL-20-DAG: @_Z1fPU3AS3i
+// OCL-12-DAG: @_Z1fPU3AS3i


Index: cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl
===
--- cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl
+++ cfe/trunk/test/CodeGenOpenCL/address-spaces-mangling.cl
@@ -1,30 +1,44 @@
 // RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=yes -triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefix=ASMANG %s
 // RUN: %clang_cc1 %s -ffake-address-space-map -faddress-space-map-mangling=no -triple %itanium_abi_triple -emit-llvm -o - | FileCheck -check-prefix=NOASMANG %s
 
+// We check that the address spaces are mangled the same in both version of OpenCL
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL2.0 -emit-llvm -o - | FileCheck -check-prefix=OCL-20 %s
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=CL1.2 -emit-llvm -o - | FileCheck -check-prefix=OCL-12 %s
+
 // We can't name this f as private is equivalent to default
 // no specifier given address space so we get multiple definition
 // warnings, but we do want it for comparison purposes.
 __attribute__((overloadable))
 void ff(int *arg) { }
 // ASMANG: @_Z2ffPi
 // NOASMANG: @_Z2ffPi
+// OCL-20-DAG: @_Z2ffPU3AS4i
+// OCL-12-DAG: @_Z2ffPi
 
 __attribute__((overloadable))
 void f(private int *arg) { }
 // ASMANG: @_Z1fPi
 // NOASMANG: @_Z1fPi
+// OCL-20-DAG: @_Z1fPi
+// OCL-12-DAG: @_Z1fPi
 
 __attribute__((overloadable))
 void f(global int *arg) { }
 // ASMANG: @_Z1fPU3AS1i
 // NOASMANG: @_Z1fPU8CLglobali
+// OCL-20-DAG: @_Z1fPU3AS1i
+// OCL-12-DAG: @_Z1fPU3AS1i
 
 __attribute__((overloadable))
 void f(local int *arg) { }
 // ASMANG: @_Z1fPU3AS2i
 // NOASMANG: @_Z1fPU7CLlocali
+// OCL-20-DAG: @_Z1fPU3AS2i
+// OCL-12-DAG: @_Z1fPU3AS2i
 
 __attribute__((overloadable))
 void f(constant int *arg) { }
 // ASMANG: @_Z1fPU3AS3i
 // NOASMANG: @_Z1fPU10CLconstanti
+// OCL-20-DAG: @_Z1fPU3AS3i
+// OCL-12-DAG: @_Z1fPU3AS3i
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27403: [OpenCL] Added a LIT test for ensuring address space mangling is done the same both in OpenCL1.2 and OpenCL2.0.

2016-12-07 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

@echuraev, please, request commit access as described here: 
http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access


Repository:
  rL LLVM

https://reviews.llvm.org/D27403



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


[PATCH] D27504: Compilation database test: don't try to output to CWD

2016-12-07 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.

Annoying. This test really shouldn't generate binary object files.

Can we check in this patch now to unblock stuff and then look into how to do a 
dry run with -MJ? Usually driver tests use `-###` for that but the code for -MJ 
explicitly disables itself when `-###` is found on the command line.




Comment at: test/Driver/compilation_database.c:2
+// RUN: cd "%T" && %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s 
-Wall -MJ - -no-canonical-prefixes 2>&1 | FileCheck %s
+// RUN: cd "%T" && not %clang -c -x c %s -MJ %s/non-existant 
-no-canonical-prefixes 2>&1 | FileCheck --check-prefix=ERROR %s
 

You can hoist the cd %T to a separate RUN line at the top instead of 
duplicating it.


https://reviews.llvm.org/D27504



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


[PATCH] D27504: Compilation database test: don't try to output to CWD

2016-12-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 80553.
sammccall added a comment.

Hoist cd %T to avoid repeating it.


https://reviews.llvm.org/D27504

Files:
  test/Driver/compilation_database.c


Index: test/Driver/compilation_database.c
===
--- test/Driver/compilation_database.c
+++ test/Driver/compilation_database.c
@@ -1,8 +1,9 @@
-// RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - 
2>&1 | FileCheck %s
-// RUN: not %clang -c -x c %s -MJ %s/non-existant 2>&1 | FileCheck 
--check-prefix=ERROR %s
+// RUN: cd "%T"
+// RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - 
-no-canonical-prefixes 2>&1 | FileCheck %s
+// RUN: not %clang -c -x c %s -MJ %s/non-existant -no-canonical-prefixes 2>&1 
| FileCheck --check-prefix=ERROR %s
 
-// CHECK: { "directory": "[[CWD:[^"]+]]",  "file": 
"[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": 
"compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", 
"[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
-// CHECK: { "directory": "[[CWD:[^"]+]]",  "file": 
"[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": 
"compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", 
"[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
+// CHECK: { "directory": "{{.*}}",  "file": 
"[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": 
"compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", 
"[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
+// CHECK: { "directory": "{{.*}}",  "file": 
"[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": 
"compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", 
"[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
 // ERROR: error: compilation database '{{.*}}/non-existant' could not be 
opened:
 
 int main(void) {


Index: test/Driver/compilation_database.c
===
--- test/Driver/compilation_database.c
+++ test/Driver/compilation_database.c
@@ -1,8 +1,9 @@
-// RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - 2>&1 | FileCheck %s
-// RUN: not %clang -c -x c %s -MJ %s/non-existant 2>&1 | FileCheck --check-prefix=ERROR %s
+// RUN: cd "%T"
+// RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - -no-canonical-prefixes 2>&1 | FileCheck %s
+// RUN: not %clang -c -x c %s -MJ %s/non-existant -no-canonical-prefixes 2>&1 | FileCheck --check-prefix=ERROR %s
 
-// CHECK: { "directory": "[[CWD:[^"]+]]",  "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
-// CHECK: { "directory": "[[CWD:[^"]+]]",  "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
+// CHECK: { "directory": "{{.*}}",  "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
+// CHECK: { "directory": "{{.*}}",  "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
 // ERROR: error: compilation database '{{.*}}/non-existant' could not be opened:
 
 int main(void) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27504: Compilation database test: don't try to output to CWD

2016-12-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added a comment.

Thanks! That makes sense.


https://reviews.llvm.org/D27504



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


[PATCH] D27504: Compilation database test: don't try to output to CWD

2016-12-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288892: Compilation database test: don't try to output to 
CWD (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D27504?vs=80553&id=80554#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27504

Files:
  cfe/trunk/test/Driver/compilation_database.c


Index: cfe/trunk/test/Driver/compilation_database.c
===
--- cfe/trunk/test/Driver/compilation_database.c
+++ cfe/trunk/test/Driver/compilation_database.c
@@ -1,8 +1,9 @@
-// RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - 
2>&1 | FileCheck %s
-// RUN: not %clang -c -x c %s -MJ %s/non-existant 2>&1 | FileCheck 
--check-prefix=ERROR %s
+// RUN: cd "%T"
+// RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - 
-no-canonical-prefixes 2>&1 | FileCheck %s
+// RUN: not %clang -c -x c %s -MJ %s/non-existant -no-canonical-prefixes 2>&1 
| FileCheck --check-prefix=ERROR %s
 
-// CHECK: { "directory": "[[CWD:[^"]+]]",  "file": 
"[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": 
"compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", 
"[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
-// CHECK: { "directory": "[[CWD:[^"]+]]",  "file": 
"[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": 
"compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", 
"[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
+// CHECK: { "directory": "{{.*}}",  "file": 
"[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": 
"compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", 
"[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
+// CHECK: { "directory": "{{.*}}",  "file": 
"[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": 
"compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", 
"[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
 // ERROR: error: compilation database '{{.*}}/non-existant' could not be 
opened:
 
 int main(void) {


Index: cfe/trunk/test/Driver/compilation_database.c
===
--- cfe/trunk/test/Driver/compilation_database.c
+++ cfe/trunk/test/Driver/compilation_database.c
@@ -1,8 +1,9 @@
-// RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - 2>&1 | FileCheck %s
-// RUN: not %clang -c -x c %s -MJ %s/non-existant 2>&1 | FileCheck --check-prefix=ERROR %s
+// RUN: cd "%T"
+// RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - -no-canonical-prefixes 2>&1 | FileCheck %s
+// RUN: not %clang -c -x c %s -MJ %s/non-existant -no-canonical-prefixes 2>&1 | FileCheck --check-prefix=ERROR %s
 
-// CHECK: { "directory": "[[CWD:[^"]+]]",  "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
-// CHECK: { "directory": "[[CWD:[^"]+]]",  "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
+// CHECK: { "directory": "{{.*}}",  "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
+// CHECK: { "directory": "{{.*}}",  "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]},
 // ERROR: error: compilation database '{{.*}}/non-existant' could not be opened:
 
 int main(void) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r288689 - Fix stack-use-after-scope in CheckExplicitlyDefaultedMemberExceptionSpec

2016-12-07 Thread Alex L via cfe-commits
On 6 December 2016 at 19:39, Vitaly Buka  wrote:

> Hi Alex,
>
>
>
> On Tue, Dec 6, 2016 at 11:14 AM Alex L  wrote:
>
> Hi Vitaly,
>
> I noticed that you posted this patch up for review at
> https://reviews.llvm.org/D27422, but then committed it instantly without
> waiting for approval (and you did the same for r288685 as well). Is there
> any particular reason why you did this? I think that you should've waited
> for approval before committing.
>
>
> We had broken build bots, so seem like this trivial change is better than
> reverting patches.
> No.3 of http://llvm.org/docs/DeveloperPolicy.html#code-reviews allows
> after commit review for changes like this.
>

Thanks for the clarification. Yes, the developer policy states that you can
commit small changes and get them reviewed after committing, so a commit
like this would've been perfect for a post-commit review. However, it also
says that "Specifically, once a patch is sent out for review, it needs an
explicit “looks good” before it is submitted". Please avoid submitting
patches for review if you know that you will commit them without waiting
for approval in the future.


>
>
> This patch is pretty small, and so it looks to me like it could have been
> reviewed after it was committed, but patches that get post-commit reviews
> shouldn't get explicit review requests like this one did.
>
>
> Sorry, probably I did the same few time before. I can't find exact details
> in the policy, but I assumed that was a reasonable approach.
> So what is the process for after commit review?
>

People usually read the commit logs and check which commits need
post-commit reviews, and then look at them. There's no need for an explicit
review request for commits like this.


>
>
>
> Alex
>
> On 5 December 2016 at 19:25, Vitaly Buka via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: vitalybuka
> Date: Mon Dec  5 13:25:00 2016
> New Revision: 288689
>
> URL: http://llvm.org/viewvc/llvm-project?rev=288689&view=rev
> Log:
> Fix stack-use-after-scope in CheckExplicitlyDefaultedMemberExceptionSpec
>
> Summary:
> Similar to r288685.
> getExceptionSpec returned structure with pointers to temporarily object
> created
> by computeImplicitExceptionSpec.
>
> Reviewers: rsmith
>
> Subscribers: aizatsky, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D27422
>
> Modified:
> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaDeclCXX.cpp?rev=288689&r1=288688&r2=288689&view=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Dec  5 13:25:00 2016
> @@ -6299,8 +6299,8 @@ void Sema::CheckExplicitlyDefaultedMembe
>CallingConv CC = Context.getDefaultCallingConvention(/*
> IsVariadic=*/false,
>
> /*IsCXXMethod=*/true);
>FunctionProtoType::ExtProtoInfo EPI(CC);
> -  EPI.ExceptionSpec = computeImplicitExceptionSpec(*this,
> MD->getLocation(), MD)
> -  .getExceptionSpec();
> +  auto IES = computeImplicitExceptionSpec(*this, MD->getLocation(), MD);
> +  EPI.ExceptionSpec = IES.getExceptionSpec();
>const FunctionProtoType *ImplicitType = cast(
>  Context.getFunctionType(Context.VoidTy, None, EPI));
>
>
>
> ___
> 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


[PATCH] D27478: Make ASTContext::getDeclAlign return the correct alignment for FunctionDecls

2016-12-07 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Does this happen with blocks as well?


https://reviews.llvm.org/D27478



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


[PATCH] D26922: [ObjC++] Don't enter a C++ declarator context when the current context is an Objective-C declaration

2016-12-07 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288893: [ObjC++] Don't enter a C++ declarator scope when the 
current context is (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D26922?vs=79722&id=80556#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26922

Files:
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
  cfe/trunk/test/SemaObjCXX/crash.mm


Index: cfe/trunk/test/SemaObjCXX/crash.mm
===
--- cfe/trunk/test/SemaObjCXX/crash.mm
+++ cfe/trunk/test/SemaObjCXX/crash.mm
@@ -25,3 +25,38 @@
 // expected-warning@-2 {{variadic templates are a C++11 extension}}
 #endif
 @end
+
+// rdar://20560175
+
+struct OuterType {
+  typedef int InnerType;
+};
+
+namespace ns {
+  typedef int InnerType;
+};
+
+@protocol InvalidProperties
+
+@property (nonatomic) (OuterType::InnerType) invalidTypeParens;
+// expected-error@-1 {{type name requires a specifier or qualifier}}
+// expected-error@-2 {{property requires fields to be named}}
+// expected-error@-3 {{expected ';' at end of declaration list}}
+// expected-error@-4 {{C++ requires a type specifier for all declarations}}
+// expected-error@-5 {{cannot declare variable inside @interface or @protocol}}
+
+@property (nonatomic) (ns::InnerType) invalidTypeParens2;
+// expected-error@-1 {{type name requires a specifier or qualifier}}
+// expected-error@-2 {{property requires fields to be named}}
+// expected-error@-3 {{expected ';' at end of declaration list}}
+// expected-error@-4 {{C++ requires a type specifier for all declarations}}
+// expected-error@-5 {{cannot declare variable inside @interface or @protocol}}
+
+@property (nonatomic) int OuterType::InnerType; // expected-error {{property 
requires fields to be named}}
+
+@property (nonatomic) int OuterType::InnerType foo; // expected-error 
{{property requires fields to be named}}
+// expected-error@-1 {{expected ';' at end of declaration list}}
+// expected-error@-2 {{C++ requires a type specifier for all declarations}}
+// expected-error@-3 {{cannot declare variable inside @interface or @protocol}}
+
+@end
Index: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
===
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
@@ -1001,6 +1001,11 @@
 bool Sema::ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
   assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
 
+  // Don't enter a declarator context when the current context is an 
Objective-C
+  // declaration.
+  if (isa(CurContext) || isa(CurContext))
+return false;
+
   NestedNameSpecifier *Qualifier = SS.getScopeRep();
 
   // There are only two places a well-formed program may qualify a
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -5264,6 +5264,14 @@
 // Change the declaration context for name lookup, until this function
 // is exited (and the declarator has been parsed).
 DeclScopeObj.EnterDeclaratorScope();
+  else if (getObjCDeclContext()) {
+// Ensure that we don't interpret the next token as an identifier when
+// dealing with declarations in an Objective-C container.
+D.SetIdentifier(nullptr, Tok.getLocation());
+D.setInvalidType(true);
+ConsumeToken();
+goto PastIdentifier;
+  }
 }
 
 // C++0x [dcl.fct]p14:


Index: cfe/trunk/test/SemaObjCXX/crash.mm
===
--- cfe/trunk/test/SemaObjCXX/crash.mm
+++ cfe/trunk/test/SemaObjCXX/crash.mm
@@ -25,3 +25,38 @@
 // expected-warning@-2 {{variadic templates are a C++11 extension}}
 #endif
 @end
+
+// rdar://20560175
+
+struct OuterType {
+  typedef int InnerType;
+};
+
+namespace ns {
+  typedef int InnerType;
+};
+
+@protocol InvalidProperties
+
+@property (nonatomic) (OuterType::InnerType) invalidTypeParens;
+// expected-error@-1 {{type name requires a specifier or qualifier}}
+// expected-error@-2 {{property requires fields to be named}}
+// expected-error@-3 {{expected ';' at end of declaration list}}
+// expected-error@-4 {{C++ requires a type specifier for all declarations}}
+// expected-error@-5 {{cannot declare variable inside @interface or @protocol}}
+
+@property (nonatomic) (ns::InnerType) invalidTypeParens2;
+// expected-error@-1 {{type name requires a specifier or qualifier}}
+// expected-error@-2 {{property requires fields to be named}}
+// expected-error@-3 {{expected ';' at end of declaration list}}
+// expected-error@-4 {{C++ requires a type specifier for all declarations}}
+// expected-error@-5 {{cannot declare variable inside @interface or @protocol}}
+
+@property (nonatomic) int OuterType::InnerType; // expected-error {{property re

r288893 - [ObjC++] Don't enter a C++ declarator scope when the current context is

2016-12-07 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Dec  7 04:24:44 2016
New Revision: 288893

URL: http://llvm.org/viewvc/llvm-project?rev=288893&view=rev
Log:
[ObjC++] Don't enter a C++ declarator scope when the current context is
an Objective-C declaration

This commit ensures that Sema won't enter a C++ declarator scope when the
current context is an Objective-C declaration. This prevents an assertion
failure in EnterDeclaratorContext that's used to ensure that current context
will be restored correctly after exiting the declarator context.

rdar://20560175

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

Modified:
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
cfe/trunk/test/SemaObjCXX/crash.mm

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=288893&r1=288892&r2=288893&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Dec  7 04:24:44 2016
@@ -5264,6 +5264,14 @@ void Parser::ParseDirectDeclarator(Decla
 // Change the declaration context for name lookup, until this function
 // is exited (and the declarator has been parsed).
 DeclScopeObj.EnterDeclaratorScope();
+  else if (getObjCDeclContext()) {
+// Ensure that we don't interpret the next token as an identifier when
+// dealing with declarations in an Objective-C container.
+D.SetIdentifier(nullptr, Tok.getLocation());
+D.setInvalidType(true);
+ConsumeToken();
+goto PastIdentifier;
+  }
 }
 
 // C++0x [dcl.fct]p14:

Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=288893&r1=288892&r2=288893&view=diff
==
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Wed Dec  7 04:24:44 2016
@@ -1001,6 +1001,11 @@ void Sema::RestoreNestedNameSpecifierAnn
 bool Sema::ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) {
   assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
 
+  // Don't enter a declarator context when the current context is an 
Objective-C
+  // declaration.
+  if (isa(CurContext) || isa(CurContext))
+return false;
+
   NestedNameSpecifier *Qualifier = SS.getScopeRep();
 
   // There are only two places a well-formed program may qualify a

Modified: cfe/trunk/test/SemaObjCXX/crash.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/crash.mm?rev=288893&r1=288892&r2=288893&view=diff
==
--- cfe/trunk/test/SemaObjCXX/crash.mm (original)
+++ cfe/trunk/test/SemaObjCXX/crash.mm Wed Dec  7 04:24:44 2016
@@ -25,3 +25,38 @@ template void f(Ts); // e
 // expected-warning@-2 {{variadic templates are a C++11 extension}}
 #endif
 @end
+
+// rdar://20560175
+
+struct OuterType {
+  typedef int InnerType;
+};
+
+namespace ns {
+  typedef int InnerType;
+};
+
+@protocol InvalidProperties
+
+@property (nonatomic) (OuterType::InnerType) invalidTypeParens;
+// expected-error@-1 {{type name requires a specifier or qualifier}}
+// expected-error@-2 {{property requires fields to be named}}
+// expected-error@-3 {{expected ';' at end of declaration list}}
+// expected-error@-4 {{C++ requires a type specifier for all declarations}}
+// expected-error@-5 {{cannot declare variable inside @interface or @protocol}}
+
+@property (nonatomic) (ns::InnerType) invalidTypeParens2;
+// expected-error@-1 {{type name requires a specifier or qualifier}}
+// expected-error@-2 {{property requires fields to be named}}
+// expected-error@-3 {{expected ';' at end of declaration list}}
+// expected-error@-4 {{C++ requires a type specifier for all declarations}}
+// expected-error@-5 {{cannot declare variable inside @interface or @protocol}}
+
+@property (nonatomic) int OuterType::InnerType; // expected-error {{property 
requires fields to be named}}
+
+@property (nonatomic) int OuterType::InnerType foo; // expected-error 
{{property requires fields to be named}}
+// expected-error@-1 {{expected ';' at end of declaration list}}
+// expected-error@-2 {{C++ requires a type specifier for all declarations}}
+// expected-error@-3 {{cannot declare variable inside @interface or @protocol}}
+
+@end


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


[PATCH] D26546: [PPC] Add vec_insert4b/vec_extract4b to altivec.h

2016-12-07 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai requested changes to this revision.
nemanjai added a comment.
This revision now requires changes to proceed.

The finalized wording for vec_insert4b:
Let W be the first doubleword element of ARG1, truncated to 32 bits.  The 
result vector is formed by inserting W into ARG2 at the byte position (0-12) 
specified by ARG3.

Given that wording, this implementation has almost the correct semantics. The 
only change required is that the source and target vectors need to be switched. 
Namely, a word is taken out of the first argument and inserted into the second 
argument. And it appears that the current implementation has that backwards.


Repository:
  rL LLVM

https://reviews.llvm.org/D26546



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


r288896 - Implement the -Wstrict-prototypes warning

2016-12-07 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Dec  7 04:52:18 2016
New Revision: 288896

URL: http://llvm.org/viewvc/llvm-project?rev=288896&view=rev
Log:
Implement the -Wstrict-prototypes warning

This commit fixes PR20796. It implements the C only -Wstrict-prototypes warning.
Clang now emits a warning for function declarations which have no parameters
specified and for K&R function definitions with more than 0 parameters that are
not preceded by a previous prototype declaration.

The patch was originally submitted by Paul Titei!

rdar://15060615

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

Added:
cfe/trunk/test/Sema/warn-strict-prototypes.c
cfe/trunk/test/Sema/warn-strict-prototypes.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=288896&r1=288895&r2=288896&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec  7 04:52:18 
2016
@@ -4411,6 +4411,10 @@ def warn_missing_prototype : Warning<
   InGroup>, DefaultIgnore;
 def note_declaration_not_a_prototype : Note<
   "this declaration is not a prototype; add 'void' to make it a prototype for 
a zero-parameter function">; 
+def warn_strict_prototypes : Warning<
+  "this %select{function declaration is not|"
+  "old-style function definition is not preceded by}0 a prototype">,
+  InGroup>, DefaultIgnore;
 def warn_missing_variable_declarations : Warning<
   "no previous extern declaration for non-static variable %0">,
   InGroup>, DefaultIgnore;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=288896&r1=288895&r2=288896&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Dec  7 04:52:18 2016
@@ -11878,6 +11878,21 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
 << FixItHint::CreateInsertion(FTL.getRParenLoc(), "void");
 }
   }
+
+  // GNU warning -Wstrict-prototypes
+  //   Warn if K&R function is defined without a previous declaration.
+  //   This warning is issued only if the definition itself does not 
provide
+  //   a prototype. Only K&R definitions do not provide a prototype.
+  //   An empty list in a function declarator that is part of a definition
+  //   of that function specifies that the function has no parameters
+  //   (C99 6.7.5.3p14)
+  if (!FD->hasWrittenPrototype() && FD->getNumParams() > 0 &&
+  !LangOpts.CPlusPlus) {
+TypeSourceInfo *TI = FD->getTypeSourceInfo();
+TypeLoc TL = TI->getTypeLoc();
+FunctionTypeLoc FTL = TL.castAs();
+Diag(FTL.getLParenLoc(), diag::warn_strict_prototypes) << 1;
+  }
 }
 
 if (auto *MD = dyn_cast(FD)) {

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=288896&r1=288895&r2=288896&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Dec  7 04:52:18 2016
@@ -4320,6 +4320,19 @@ static TypeSourceInfo *GetFullTypeForDec
   if (FTI.isAmbiguous)
 warnAboutAmbiguousFunction(S, D, DeclType, T);
 
+  // GNU warning -Wstrict-prototypes
+  //   Warn if a function declaration is without a prototype.
+  //   This warning is issued for all kinds of unprototyped function
+  //   declarations (i.e. function type typedef, function pointer etc.)
+  //   C99 6.7.5.3p14:
+  //   The empty list in a function declarator that is not part of a
+  //   definition of that function specifies that no information
+  //   about the number or types of the parameters is supplied.
+  if (D.getFunctionDefinitionKind() == FDK_Declaration &&
+  FTI.NumParams == 0 && !LangOpts.CPlusPlus)
+S.Diag(DeclType.Loc, diag::warn_strict_prototypes)
+<< 0 << FixItHint::CreateInsertion(FTI.getRParenLoc(), "void");
+
   FunctionType::ExtInfo EI(getCCForDeclaratorChunk(S, D, FTI, chunkIndex));
 
   if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus) {

Added: cfe/trunk/test/Sema/warn-strict-prototypes.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-strict-prototypes.c?rev=288896&view=auto
==
--- cfe/trunk/test/Sema/warn-strict-prototypes.c (added)
+++ cfe/trunk/test/Sema/warn-strict-prototypes.c Wed Dec  7 04:52:18 2016
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -fsyntax-only 

[PATCH] D16533: Bug 20796 - GCC's -Wstrict-prototypes warning not implemented in Clang

2016-12-07 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288896: Implement the -Wstrict-prototypes warning (authored 
by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D16533?vs=80285&id=80560#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D16533

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/Sema/warn-strict-prototypes.c
  cfe/trunk/test/Sema/warn-strict-prototypes.m

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4411,6 +4411,10 @@
   InGroup>, DefaultIgnore;
 def note_declaration_not_a_prototype : Note<
   "this declaration is not a prototype; add 'void' to make it a prototype for a zero-parameter function">; 
+def warn_strict_prototypes : Warning<
+  "this %select{function declaration is not|"
+  "old-style function definition is not preceded by}0 a prototype">,
+  InGroup>, DefaultIgnore;
 def warn_missing_variable_declarations : Warning<
   "no previous extern declaration for non-static variable %0">,
   InGroup>, DefaultIgnore;
Index: cfe/trunk/test/Sema/warn-strict-prototypes.m
===
--- cfe/trunk/test/Sema/warn-strict-prototypes.m
+++ cfe/trunk/test/Sema/warn-strict-prototypes.m
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify -fblocks %s
+
+@interface Foo
+
+@property (nonatomic, copy) void (^noProtoBlock)(); // expected-warning {{this function declaration is not a prototype}}
+@property (nonatomic, copy) void (^block)(void); // no warning
+
+- doStuff:(void (^)()) completionHandler; // expected-warning {{this function declaration is not a prototype}}
+- doOtherStuff:(void (^)(void)) completionHandler; // no warning
+
+@end
+
+void foo() {
+  void (^block)() = // expected-warning {{this function declaration is not a prototype}}
+^void(int arg) { // no warning
+  };
+  void (^block2)(void) = // no warning
+ ^void() { // expected-warning {{this function declaration is not a prototype}}
+  };
+}
Index: cfe/trunk/test/Sema/warn-strict-prototypes.c
===
--- cfe/trunk/test/Sema/warn-strict-prototypes.c
+++ cfe/trunk/test/Sema/warn-strict-prototypes.c
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+// function declaration with unspecified params
+void foo1(); // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:"void"
+// function declaration with 0 params
+void foo2(void);
+
+// function definition with 0 params(for both cases),
+// valid according to 6.7.5.3/14
+void foo1() {}
+void foo2(void) {}
+
+// function type typedef unspecified params
+typedef void foo3(); // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"
+
+// global fp unspecified params
+void (*foo4)(); // expected-warning {{this function declaration is not a prototype}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"void"
+
+// struct member fp unspecified params
+struct { void (*foo5)(); } s; // expected-warning {{this function declaration is not a prototype}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:23-[[@LINE-1]]:23}:"void"
+
+// param fp unspecified params
+void bar2(void (*foo6)()) { // expected-warning {{this function declaration is not a prototype}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:24-[[@LINE-1]]:24}:"void"
+  // local fp unspecified params
+  void (*foo7)() = 0; // expected-warning {{this function declaration is not a prototype}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"void"
+  // array fp unspecified params
+  void (*foo8[2])() = {0}; // expected-warning {{this function declaration is not a prototype}}
+   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"
+}
+
+// function type cast using using an anonymous function declaration
+void bar3(void) {
+  // casting function w/out prototype to unspecified params function type
+  (void)(void(*)()) foo1; // expected-warning {{this function declaration is not a prototype}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:18}:"void"
+  // .. specified params
+  (void)(void(*)(void)) foo1;
+}
+
+// K&R function definition not preceded by full prototype
+int foo9(a, b) // expected-warning {{old-style function d

[PATCH] D27515: [change-namespace] move template class forward-declarations and don't move fwd-decls in classes.

2016-12-07 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: bkramer.
ioeric added a subscriber: cfe-commits.

Forward declarations in moved namespaces should be moved back to the old
namespaces. We should also move template class forward declarations.

Also fix a bug that moves forward declarations of nested classes.


https://reviews.llvm.org/D27515

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

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -278,14 +278,16 @@
   std::string Code = "namespace na {\n"
  "namespace nb {\n"
  "class FWD;\n"
+ "class FWD2;\n"
  "class A {\n"
  "  FWD *fwd;\n"
  "};\n"
  "} // namespace nb\n"
  "} // namespace na\n";
   std::string Expected = "namespace na {\n"
  "namespace nb {\n"
  "class FWD;\n"
+ "class FWD2;\n"
  "} // namespace nb\n"
  "} // namespace na\n"
  "namespace x {\n"
@@ -299,6 +301,58 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, TemplateClassForwardDeclaration) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "class FWD;\n"
+ "template class FWD_TEMP;\n"
+ "class A {\n"
+ "  FWD *fwd;\n"
+ "};\n"
+ "template class TEMP {};\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace na {\n"
+ "namespace nb {\n"
+ "class FWD;\n"
+ "template class FWD_TEMP;\n"
+ "} // namespace nb\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "\n"
+ "class A {\n"
+ "  na::nb::FWD *fwd;\n"
+ "};\n"
+ "template class TEMP {};\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DontMoveForwardDeclarationInClass) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "class A {\n"
+ "  class FWD;\n"
+ "  FWD *fwd;\n"
+ "  template class FWD_TEMP;\n"
+ "};\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "\n\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "class A {\n"
+ "  class FWD;\n"
+ "  FWD *fwd;\n"
+ "  template class FWD_TEMP;\n"
+ "};\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveFunctions) {
   std::string Code = "namespace na {\n"
  "class C_A {};\n"
Index: change-namespace/ChangeNamespace.h
===
--- change-namespace/ChangeNamespace.h
+++ change-namespace/ChangeNamespace.h
@@ -64,7 +64,7 @@
 
   void moveClassForwardDeclaration(
   const ast_matchers::MatchFinder::MatchResult &Result,
-  const CXXRecordDecl *FwdDecl);
+  const NamedDecl *FwdDecl);
 
   void replaceQualifiedSymbolInDeclContext(
   const ast_matchers::MatchFinder::MatchResult &Result,
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -303,10 +303,18 @@
   .bind("old_ns"),
   this);
 
-  // Match forward-declarations in the old namespace.
+  // Match class forward-declarations in the old namespace.
+  // Note that forward-declarations in classes are not matched.
+  Finder->addMatcher(cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition())),
+   IsInMovedNs, hasParent(namespaceDecl()))
+ .bind("class_fwd_decl"),
+ this);
+
+  // Match template class forward-declarations in the 

[PATCH] D23130: [Clang-tidy] Add a check for definitions in the global namespace.

2016-12-07 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer updated this revision to Diff 80574.
bkramer marked 9 inline comments as done.
bkramer added a comment.
Herald added a subscriber: JDevlieghere.

- Moved external linkage check to matcher
- added msvcrt entry point check
- fixed comment typos.


https://reviews.llvm.org/D23130

Files:
  clang-tidy/google/CMakeLists.txt
  clang-tidy/google/GlobalNamesCheck.cpp
  clang-tidy/google/GlobalNamesCheck.h
  clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tidy/google/GoogleTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/google-global-names-in-headers.rst
  docs/clang-tidy/checks/google-global-names.rst
  test/clang-tidy/google-global-names.cpp
  unittests/clang-tidy/GoogleModuleTest.cpp

Index: unittests/clang-tidy/GoogleModuleTest.cpp
===
--- unittests/clang-tidy/GoogleModuleTest.cpp
+++ unittests/clang-tidy/GoogleModuleTest.cpp
@@ -1,6 +1,6 @@
 #include "ClangTidyTest.h"
 #include "google/ExplicitConstructorCheck.h"
-#include "google/GlobalNamesInHeadersCheck.h"
+#include "google/GlobalNamesCheck.h"
 #include "gtest/gtest.h"
 
 using namespace clang::tidy::google;
@@ -56,7 +56,7 @@
   "A(Foo);"));
 }
 
-class GlobalNamesInHeadersCheckTest : public ::testing::Test {
+class GlobalNamesCheckTest : public ::testing::Test {
 protected:
   bool runCheckOnCode(const std::string &Code, const std::string &Filename) {
 static const char *const Header = "namespace std {\n"
@@ -69,7 +69,7 @@
 if (!StringRef(Filename).endswith(".cpp")) {
   Args.emplace_back("-xc++-header");
 }
-test::runCheckOnCode(
+test::runCheckOnCode(
 Header + Code, &Errors, Filename, Args);
 if (Errors.empty())
   return false;
@@ -81,7 +81,7 @@
   }
 };
 
-TEST_F(GlobalNamesInHeadersCheckTest, UsingDeclarations) {
+TEST_F(GlobalNamesCheckTest, UsingDeclarations) {
   EXPECT_TRUE(runCheckOnCode("using std::string;", "foo.h"));
   EXPECT_FALSE(runCheckOnCode("using std::string;", "foo.cpp"));
   EXPECT_FALSE(runCheckOnCode("namespace my_namespace {\n"
@@ -91,7 +91,7 @@
   EXPECT_FALSE(runCheckOnCode("SOME_MACRO(std::string);", "foo.h"));
 }
 
-TEST_F(GlobalNamesInHeadersCheckTest, UsingDirectives) {
+TEST_F(GlobalNamesCheckTest, UsingDirectives) {
   EXPECT_TRUE(runCheckOnCode("using namespace std;", "foo.h"));
   EXPECT_FALSE(runCheckOnCode("using namespace std;", "foo.cpp"));
   EXPECT_FALSE(runCheckOnCode("namespace my_namespace {\n"
@@ -101,7 +101,7 @@
   EXPECT_FALSE(runCheckOnCode("SOME_MACRO(namespace std);", "foo.h"));
 }
 
-TEST_F(GlobalNamesInHeadersCheckTest, RegressionAnonymousNamespace) {
+TEST_F(GlobalNamesCheckTest, RegressionAnonymousNamespace) {
   EXPECT_FALSE(runCheckOnCode("namespace {}", "foo.h"));
 }
 
Index: test/clang-tidy/google-global-names.cpp
===
--- /dev/null
+++ test/clang-tidy/google-global-names.cpp
@@ -0,0 +1,46 @@
+// RUN: %check_clang_tidy %s google-global-names %t
+
+void f();
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'f' declared in the global namespace
+void f() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: 'f' declared in the global namespace
+class F;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'F' declared in the global namespace
+class F {};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'F' declared in the global namespace
+int i;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'i' declared in the global namespace
+extern int ii = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'ii' declared in the global namespace
+
+// No warnings below.
+extern "C" void g();
+extern "C" void h() {}
+extern "C++" void h2() {}
+
+#define VAR(v) v
+VAR(int m);
+
+extern "C" {
+void j() {}
+}
+
+struct Clike {
+  int i;
+};
+
+extern "C" int ik;
+extern "C" { int il; }
+
+void *operator new(__SIZE_TYPE__, int) { return 0; }
+void operator delete(void *, int) {}
+
+static void l() {}
+namespace {
+void m() {}
+}
+namespace x {
+void n() {}
+}
+
+int main() {}
Index: docs/clang-tidy/checks/google-global-names.rst
===
--- docs/clang-tidy/checks/google-global-names.rst
+++ docs/clang-tidy/checks/google-global-names.rst
@@ -1,10 +1,12 @@
-.. title:: clang-tidy - google-global-names-in-headers
+.. title:: clang-tidy - google-global-names
 
-google-global-names-in-headers
-==
+google-global-names
+===
 
-Flag global namespace pollution in header files. Right now it only triggers on
-``using`` declarations and directives.
+Flag global namespace pollution in header files.
+Right now it only triggers on using declarations and directives in header files
+and declarations and definitions of functions, classes and variables in the
+global namespace.
 
 The relevant style guide section is
 https://google.github.io/styleguide/cppguide.html#Namespaces.
Index: docs/ReleaseNotes.rst

[PATCH] D23130: [Clang-tidy] Add a check for definitions in the global namespace.

2016-12-07 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: clang-tidy/google/GlobalNamesCheck.cpp:90
+// extern "C" globals need to be in the global namespace.
+if (VDecl->isExternC())
+  return;

alexfh wrote:
> Is this already filtered-out by the matcher?
Nope.



Comment at: clang-tidy/google/GoogleTidyModule.cpp:68
+CheckFactories.registerCheck(
+"google-global-names");
 CheckFactories.registerCheck(

aaron.ballman wrote:
> Given that this was shipped under the old name, I think we need to figure out 
> our policy for how to handle this. It also comes up in D26511, so I would 
> like us to be consistent with what we do.
There was no special handling in D26511, so I left this as-is.


https://reviews.llvm.org/D23130



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


[PATCH] D27123: Add AVR target and toolchain to Clang

2016-12-07 Thread Senthil Kumar Selvaraj via Phabricator via cfe-commits
saaadhu updated this revision to Diff 80575.
saaadhu added a comment.

Thanks, setting DoubleFormat and LongDoubleFormat fixed the __DBL_ and __LDBL_ 
differences. Also, setting SigAtomicType fixed the __SIG_ATOMIC_ differences as 
well. I've added those defines to the test. Unrelated, but I also removed a 
redundant set of LongLongAlign and overriding of GetDefaultDwarfVersion 
(returning 2 wasn't necessary).

The only remaining  (textually) conflicting defines between "avr-gcc -dM -E" 
and "clang -dM -E" are

1. short vs int for a bunch of __xxx_TYPE__ defines, like say __CHAR16_TYPE__. 
short and int are both 2 bytes for the avr, so I think either one is ok.
2. Casts vs plain literals in the defines for double MIN, MAX values.  avr-gcc, 
for example, defines #define __DBL_MAX__ ((double)3.40282347e+38L), whereas 
clang does  #define __DBL_MAX__ 3.40282347e+38. Again, I think this shouldn't 
matter - I've added the literals sans the cast to the test.


https://reviews.llvm.org/D27123

Files:
  lib/Basic/Targets.cpp
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp
  lib/Driver/Tools.h
  test/Driver/avr-toolchain.c
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -9189,3 +9189,174 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple x86_64-windows-cygnus < /dev/null | FileCheck -match-full-lines -check-prefix CYGWIN-X64 %s
 // CYGWIN-X64: #define __USER_LABEL_PREFIX__
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=avr \
+// RUN:   < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix=AVR %s
+//
+// AVR:#define __ATOMIC_ACQUIRE 2
+// AVR:#define __ATOMIC_ACQ_REL 4
+// AVR:#define __ATOMIC_CONSUME 1
+// AVR:#define __ATOMIC_RELAXED 0
+// AVR:#define __ATOMIC_RELEASE 3
+// AVR:#define __ATOMIC_SEQ_CST 5
+// AVR:#define __AVR__ 1
+// AVR:#define __BIGGEST_ALIGNMENT__ 1
+// AVR:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+// AVR:#define __CHAR16_TYPE__ unsigned short
+// AVR:#define __CHAR32_TYPE__ long unsigned int
+// AVR:#define __CHAR_BIT__ 8
+// AVR:#define __DBL_DECIMAL_DIG__ 9
+// AVR:#define __DBL_DENORM_MIN__ 1.40129846e-45
+// AVR:#define __DBL_DIG__ 6
+// AVR:#define __DBL_EPSILON__ 1.19209290e-7
+// AVR:#define __DBL_HAS_DENORM__ 1
+// AVR:#define __DBL_HAS_INFINITY__ 1
+// AVR:#define __DBL_HAS_QUIET_NAN__ 1
+// AVR:#define __DBL_MANT_DIG__ 24
+// AVR:#define __DBL_MAX_10_EXP__ 38
+// AVR:#define __DBL_MAX_EXP__ 128
+// AVR:#define __DBL_MAX__ 3.40282347e+38
+// AVR:#define __DBL_MIN_10_EXP__ (-37)
+// AVR:#define __DBL_MIN_EXP__ (-125)
+// AVR:#define __DBL_MIN__ 1.17549435e-38
+// AVR:#define __FINITE_MATH_ONLY__ 0
+// AVR:#define __FLT_DECIMAL_DIG__ 9
+// AVR:#define __FLT_DENORM_MIN__ 1.40129846e-45F
+// AVR:#define __FLT_DIG__ 6
+// AVR:#define __FLT_EPSILON__ 1.19209290e-7F
+// AVR:#define __FLT_EVAL_METHOD__ 0
+// AVR:#define __FLT_HAS_DENORM__ 1
+// AVR:#define __FLT_HAS_INFINITY__ 1
+// AVR:#define __FLT_HAS_QUIET_NAN__ 1
+// AVR:#define __FLT_MANT_DIG__ 24
+// AVR:#define __FLT_MAX_10_EXP__ 38
+// AVR:#define __FLT_MAX_EXP__ 128
+// AVR:#define __FLT_MAX__ 3.40282347e+38F
+// AVR:#define __FLT_MIN_10_EXP__ (-37)
+// AVR:#define __FLT_MIN_EXP__ (-125)
+// AVR:#define __FLT_MIN__ 1.17549435e-38F
+// AVR:#define __FLT_RADIX__ 2
+// AVR:#define __GCC_ATOMIC_BOOL_LOCK_FREE 1
+// AVR:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 1
+// AVR:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 1
+// AVR:#define __GCC_ATOMIC_CHAR_LOCK_FREE 1
+// AVR:#define __GCC_ATOMIC_INT_LOCK_FREE 1
+// AVR:#define __GCC_ATOMIC_LLONG_LOCK_FREE 1
+// AVR:#define __GCC_ATOMIC_LONG_LOCK_FREE 1
+// AVR:#define __GCC_ATOMIC_POINTER_LOCK_FREE 1
+// AVR:#define __GCC_ATOMIC_SHORT_LOCK_FREE 1
+// AVR:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
+// AVR:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 1
+// AVR:#define __GXX_ABI_VERSION 1002
+// AVR:#define __INT16_C_SUFFIX__ 
+// AVR:#define __INT16_MAX__ 32767
+// AVR:#define __INT16_TYPE__ short
+// AVR:#define __INT32_C_SUFFIX__ L
+// AVR:#define __INT32_MAX__ 2147483647L
+// AVR:#define __INT32_TYPE__ long int
+// AVR:#define __INT64_C_SUFFIX__ LL
+// AVR:#define __INT64_MAX__ 9223372036854775807LL
+// AVR:#define __INT64_TYPE__ long long int
+// AVR:#define __INT8_C_SUFFIX__ 
+// AVR:#define __INT8_MAX__ 127
+// AVR:#define __INT8_TYPE__ signed char
+// AVR:#define __INTMAX_C_SUFFIX__ LL
+// AVR:#define __INTMAX_MAX__ 9223372036854775807LL
+// AVR:#define __INTMAX_TYPE__ long long int
+// AVR:#define __INTPTR_MAX__ 32767
+// AVR:#define __INTPTR_TYPE__ int
+// AVR:#define __INT_FAST16_MAX__ 32767
+// AVR:#define __INT_FAST16_TYPE__ short
+// AVR:#define __INT_FAST32_MAX__ 2147483647L
+// AVR:#define __INT_FAST32_TYPE__ long int
+// AVR:#define __INT_FAST64_MAX__ 9223372036854775807LL
+// AVR:#define __INT_FAST64_TYPE__ long long int
+// AVR:#define __INT_FAST8_MAX__ 127
+// AVR:#defi

[PATCH] D23130: [Clang-tidy] Add a check for definitions in the global namespace.

2016-12-07 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/google/GoogleTidyModule.cpp:68
+CheckFactories.registerCheck(
+"google-global-names");
 CheckFactories.registerCheck(

bkramer wrote:
> aaron.ballman wrote:
> > Given that this was shipped under the old name, I think we need to figure 
> > out our policy for how to handle this. It also comes up in D26511, so I 
> > would like us to be consistent with what we do.
> There was no special handling in D26511, so I left this as-is.
D26511 made the existing check documentation redirect to the new documentation.


https://reviews.llvm.org/D23130



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


[PATCH] D27515: [change-namespace] move template class forward-declarations and don't move fwd-decls in classes.

2016-12-07 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288908: [change-namespace] move template class 
forward-declarations and don't move fwd… (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D27515?vs=80571&id=80586#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27515

Files:
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
  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
@@ -278,14 +278,16 @@
   std::string Code = "namespace na {\n"
  "namespace nb {\n"
  "class FWD;\n"
+ "class FWD2;\n"
  "class A {\n"
  "  FWD *fwd;\n"
  "};\n"
  "} // namespace nb\n"
  "} // namespace na\n";
   std::string Expected = "namespace na {\n"
  "namespace nb {\n"
  "class FWD;\n"
+ "class FWD2;\n"
  "} // namespace nb\n"
  "} // namespace na\n"
  "namespace x {\n"
@@ -299,6 +301,58 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, TemplateClassForwardDeclaration) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "class FWD;\n"
+ "template class FWD_TEMP;\n"
+ "class A {\n"
+ "  FWD *fwd;\n"
+ "};\n"
+ "template class TEMP {};\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace na {\n"
+ "namespace nb {\n"
+ "class FWD;\n"
+ "template class FWD_TEMP;\n"
+ "} // namespace nb\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "\n"
+ "class A {\n"
+ "  na::nb::FWD *fwd;\n"
+ "};\n"
+ "template class TEMP {};\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DontMoveForwardDeclarationInClass) {
+  std::string Code = "namespace na {\n"
+ "namespace nb {\n"
+ "class A {\n"
+ "  class FWD;\n"
+ "  FWD *fwd;\n"
+ "  template class FWD_TEMP;\n"
+ "};\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "\n\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "class A {\n"
+ "  class FWD;\n"
+ "  FWD *fwd;\n"
+ "  template class FWD_TEMP;\n"
+ "};\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveFunctions) {
   std::string Code = "namespace na {\n"
  "class C_A {};\n"
Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
@@ -64,7 +64,7 @@
 
   void moveClassForwardDeclaration(
   const ast_matchers::MatchFinder::MatchResult &Result,
-  const CXXRecordDecl *FwdDecl);
+  const NamedDecl *FwdDecl);
 
   void replaceQualifiedSymbolInDeclContext(
   const ast_matchers::MatchFinder::MatchResult &Result,
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
@@ -303,10 +303,18 @@
   .bind("old_ns"),
   this);
 
-  // Match forward-declarations in the old namespace.
+  // Match class forward-declarations in the old namespace.
+  // Note that forward-declarations in classes are not matched.
+  Finder->ad

[clang-tools-extra] r288908 - [change-namespace] move template class forward-declarations and don't move fwd-decls in classes.

2016-12-07 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Wed Dec  7 08:20:52 2016
New Revision: 288908

URL: http://llvm.org/viewvc/llvm-project?rev=288908&view=rev
Log:
[change-namespace] move template class forward-declarations and don't move 
fwd-decls in classes.

Summary:
Forward declarations in moved namespaces should be moved back to the old
namespaces. We should also move template class forward declarations.

Also fix a bug that moves forward declarations of nested classes.

Reviewers: bkramer

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
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=288908&r1=288907&r2=288908&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Wed Dec  7 
08:20:52 2016
@@ -303,10 +303,18 @@ void ChangeNamespaceTool::registerMatche
   .bind("old_ns"),
   this);
 
-  // Match forward-declarations in the old namespace.
+  // Match class forward-declarations in the old namespace.
+  // Note that forward-declarations in classes are not matched.
+  Finder->addMatcher(cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition())),
+   IsInMovedNs, hasParent(namespaceDecl()))
+ .bind("class_fwd_decl"),
+ this);
+
+  // Match template class forward-declarations in the old namespace.
   Finder->addMatcher(
-  cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition())), IsInMovedNs)
-  .bind("fwd_decl"),
+  classTemplateDecl(unless(hasDescendant(cxxRecordDecl(isDefinition(,
+IsInMovedNs, hasParent(namespaceDecl()))
+  .bind("template_class_fwd_decl"),
   this);
 
   // Match references to types that are not defined in the old namespace.
@@ -401,8 +409,12 @@ void ChangeNamespaceTool::run(
  Result.Nodes.getNodeAs("old_ns")) {
 moveOldNamespace(Result, NsDecl);
   } else if (const auto *FwdDecl =
- Result.Nodes.getNodeAs("fwd_decl")) {
-moveClassForwardDeclaration(Result, FwdDecl);
+ Result.Nodes.getNodeAs("class_fwd_decl")) {
+moveClassForwardDeclaration(Result, cast(FwdDecl));
+  } else if (const auto *TemplateFwdDecl =
+ Result.Nodes.getNodeAs(
+ "template_class_fwd_decl")) {
+moveClassForwardDeclaration(Result, cast(TemplateFwdDecl));
   } else if (const auto *UsingWithShadow =
  Result.Nodes.getNodeAs("using_with_shadow")) {
 fixUsingShadowDecl(Result, UsingWithShadow);
@@ -539,7 +551,7 @@ void ChangeNamespaceTool::moveOldNamespa
 //   }  // x
 void ChangeNamespaceTool::moveClassForwardDeclaration(
 const ast_matchers::MatchFinder::MatchResult &Result,
-const CXXRecordDecl *FwdDecl) {
+const NamedDecl *FwdDecl) {
   SourceLocation Start = FwdDecl->getLocStart();
   SourceLocation End = FwdDecl->getLocEnd();
   SourceLocation AfterSemi = Lexer::findLocationAfterToken(

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.h?rev=288908&r1=288907&r2=288908&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.h (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.h Wed Dec  7 
08:20:52 2016
@@ -64,7 +64,7 @@ private:
 
   void moveClassForwardDeclaration(
   const ast_matchers::MatchFinder::MatchResult &Result,
-  const CXXRecordDecl *FwdDecl);
+  const NamedDecl *FwdDecl);
 
   void replaceQualifiedSymbolInDeclContext(
   const ast_matchers::MatchFinder::MatchResult &Result,

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=288908&r1=288907&r2=288908&view=diff
==
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
Wed Dec  7 08:20:52 2016
@@ -278,6 +278,7 @@ TEST_F(ChangeNamespaceTest, LeaveForward
   std::string Code = "namespace na {\n"
  "namespace nb {\n"
  "class FWD;\n"
+ "class FWD2;\n"
  "class A {\n"
  "  FWD 

[PATCH] D27520: [clang-tidy] Add check for redundant function pointer dereferences

2016-12-07 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: alexfh, aaron.ballman, hokein.
malcolm.parsons added a subscriber: cfe-commits.
Herald added subscribers: JDevlieghere, mgorny.

See https://youtu.be/6eX9gPithBo


https://reviews.llvm.org/D27520

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp
  clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-redundant-function-ptr-dereference.rst
  test/clang-tidy/readability-redundant-function-ptr-dereference.cpp

Index: test/clang-tidy/readability-redundant-function-ptr-dereference.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-redundant-function-ptr-dereference.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-redundant-function-ptr-dereference %t
+
+void f(int i);
+
+void positive() {
+  void (*p)(int) = f;
+
+  (**p)(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated dereference of function pointer [readability-redundant-function-ptr-dereference]
+  // CHECK-FIXES: (*p)(1);
+  (*p)(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: redundant repeated
+  // CHECK-MESSAGES: :[[@LINE-3]]:6: warning: redundant repeated
+  // CHECK-MESSAGES: :[[@LINE-4]]:7: warning: redundant repeated
+  // CHECK-FIXES: (*p)(2);
+}
+
+void negative() {
+  void (*q)(int) = &f;
+
+  q(1);
+  (*q)(2);
+}
Index: docs/clang-tidy/checks/readability-redundant-function-ptr-dereference.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-redundant-function-ptr-dereference.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - readability-redundant-function-ptr-dereference
+
+readability-redundant-function-ptr-dereference
+==
+
+Finds redundant dereferences of a function pointer.
+See https://youtu.be/6eX9gPithBo.
+
+Before:
+
+.. code-block:: c++
+
+  int f(int,int);
+  int (*p)(int, int) = &f;
+
+  int i = (**p)(10, 50);
+
+After:
+
+.. code-block:: c++
+
+  int f(int,int);
+  int (*p)(int, int) = &f;
+
+  int i = (*p)(10, 50);
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -138,6 +138,7 @@
readability-non-const-parameter
readability-redundant-control-flow
readability-redundant-declaration
+   readability-redundant-function-ptr-dereference
readability-redundant-member-init
readability-redundant-smartptr-get
readability-redundant-string-cstr
Index: clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h
===
--- /dev/null
+++ clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h
@@ -0,0 +1,35 @@
+//===--- RedundantFunctionPtrDereferenceCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_FUNCTION_PTR_DEREFERENCE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_FUNCTION_PTR_DEREFERENCE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Eliminate redundant dereferences of a function pointer.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-redundant-function-ptr-dereference.html
+class RedundantFunctionPtrDereferenceCheck : public ClangTidyCheck {
+public:
+  RedundantFunctionPtrDereferenceCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_FUNCTION_PTR_DEREFERENCE_H
Index: clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp
===
--- /dev/null
+++ clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp
@@ -0,0 +1,37 @@
+//===--- RedundantFunctionPtrDereferenceCheck.cpp - clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===-

[PATCH] D15994: Allow for unfinished #if blocks in preambles.

2016-12-07 Thread Erik Verbruggen via Phabricator via cfe-commits
erikjv marked 7 inline comments as done.
erikjv added inline comments.



Comment at: lib/Serialization/ASTReader.cpp:2816
+}
+PP.setReplayablePreambleConditionalStack(ConditionalStack);
+  }

rsmith wrote:
> Why can't we set the conditional stack on the `PPLexer` directly from here? 
> (Why do we need to store it separately?)
Because there is no PPLexer yet. The deserialization is kicked off by 
ASTUnit::CodeComplete in Act->BeginSourceFile, while the lexer is created in 
Act->Execute.


https://reviews.llvm.org/D15994



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


[PATCH] D15994: Allow for unfinished #if blocks in preambles.

2016-12-07 Thread Erik Verbruggen via Phabricator via cfe-commits
erikjv updated this revision to Diff 80589.

https://reviews.llvm.org/D15994

Files:
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorLexer.h
  include/clang/Lex/PreprocessorOptions.h
  include/clang/Serialization/ASTBitCodes.h
  lib/Frontend/ASTUnit.cpp
  lib/Lex/Lexer.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/Preprocessor.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/Lexer/preamble.c
  test/Lexer/preamble2.c

Index: test/Lexer/preamble2.c
===
--- /dev/null
+++ test/Lexer/preamble2.c
@@ -0,0 +1,19 @@
+// Preamble detection test: header with an include guard.
+#ifndef HEADER_H
+#define HEADER_H
+#include "foo"
+int bar;
+#endif
+
+// This test checks for detection of the preamble of a file, which
+// includes all of the starting comments and #includes.
+
+// RUN: %clang_cc1 -print-preamble %s > %t
+// RUN: echo END. >> %t
+// RUN: FileCheck < %t %s
+
+// CHECK: // Preamble detection test: header with an include guard.
+// CHECK-NEXT: #ifndef HEADER_H
+// CHECK-NEXT: #define HEADER_H
+// CHECK-NEXT: #include "foo"
+// CHECK-NEXT: END.
Index: test/Lexer/preamble.c
===
--- test/Lexer/preamble.c
+++ test/Lexer/preamble.c
@@ -9,15 +9,12 @@
 #pragma unknown
 #endif
 #ifdef WIBBLE
-#include "honk"
-#else
-int foo();
+#include "foo"
+int bar;
 #endif
 
 // This test checks for detection of the preamble of a file, which
-// includes all of the starting comments and #includes. Note that any
-// changes to the preamble part of this file must be mirrored in
-// Inputs/preamble.txt, since we diff against it.
+// includes all of the starting comments and #includes.
 
 // RUN: %clang_cc1 -print-preamble %s > %t
 // RUN: echo END. >> %t
@@ -33,4 +30,6 @@
 // CHECK-NEXT: #endif
 // CHECK-NEXT: #pragma unknown
 // CHECK-NEXT: #endif
+// CHECK-NEXT: #ifdef WIBBLE
+// CHECK-NEXT: #include "foo"
 // CHECK-NEXT: END.
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -1071,6 +1071,7 @@
   RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES);
   RECORD(DELETE_EXPRS_TO_ANALYZE);
   RECORD(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH);
+  RECORD(PP_CONDITIONAL_STACK);
 
   // SourceManager Block.
   BLOCK(SOURCE_MANAGER_BLOCK);
@@ -2233,6 +2234,17 @@
 Stream.EmitRecord(PP_COUNTER_VALUE, Record);
   }
 
+  if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) {
+for (const auto &Cond : PP.getPreambleConditionalStack()) {
+  AddSourceLocation(Cond.IfLoc, Record);
+  Record.push_back(Cond.WasSkipping);
+  Record.push_back(Cond.FoundNonSkip);
+  Record.push_back(Cond.FoundElse);
+}
+Stream.EmitRecord(PP_CONDITIONAL_STACK, Record);
+Record.clear();
+  }
+
   // Enter the preprocessor block.
   Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3);
 
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -2870,6 +2870,20 @@
   }
   break;
 
+case PP_CONDITIONAL_STACK:
+  if (!Record.empty()) {
+SmallVector ConditionalStack;
+for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) {
+  auto loc = ReadSourceLocation(F, Record, Idx);
+  bool WasSkipping = Record[Idx++];
+  bool FoundNonSkip = Record[Idx++];
+  bool FoundElse = Record[Idx++];
+  ConditionalStack.push_back({ loc, WasSkipping, FoundNonSkip, FoundElse });
+}
+PP.setReplayablePreambleConditionalStack(ConditionalStack);
+  }
+  break;
+
 case PP_COUNTER_VALUE:
   if (!Record.empty() && Listener)
 Listener->ReadCounter(F, Record[0]);
Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -150,6 +150,9 @@
 Ident_GetExceptionInfo = Ident_GetExceptionCode = nullptr;
 Ident_AbnormalTermination = nullptr;
   }
+
+  if (this->PPOpts->PreambleGeneration)
+PreambleConditionalStack.startRecording();
 }
 
 Preprocessor::~Preprocessor() {
Index: lib/Lex/PPLexerChange.cpp
===
--- lib/Lex/PPLexerChange.cpp
+++ lib/Lex/PPLexerChange.cpp
@@ -46,6 +46,12 @@
   });
 }
 
+bool Preprocessor::isInPreamble() const {
+  if (IsFileLexer())
+return IncludeMacroStack.size() == 1;
+  return false;
+}
+
 /// getCurrentLexer - Return the current file lexer being lexed from.  Note
 /// that this ignores any potentially active macro expansions and _Pragma
 /// expansions going on at the time.
@@ -129,6 +135,11 @@
 Callbacks->FileChanged(CurLexer->getFileLoc(),
PPCallbacks::EnterFile, FileType);
   }
+
+  if (PreambleConditional

[PATCH] D27523: [change-namespace] don't fix using shadow decls in classes.

2016-12-07 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: bkramer.
ioeric added a subscriber: cfe-commits.

Using shadow declarations in classes always refers to base class, which does not
need to be fixed/qualified since it can be inferred from inheritance.


https://reviews.llvm.org/D27523

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
@@ -425,6 +425,36 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, DontFixUsingShadowDeclInClasses) {
+  std::string Code = "namespace na {\n"
+ "class A {};\n"
+ "class Base { public: Base() {} void m() {} };\n"
+ "namespace nb {\n"
+ "class D : public Base {\n"
+ "public:\n"
+ "  using AA = A; using B = Base;\n"
+ "  using Base::m; using Base::Base;\n"
+ "};"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+
+  std::string Expected = "namespace na {\n"
+ "class A {};\n"
+ "class Base { public: Base() {} void m() {} };\n"
+ "\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "class D : public na::Base {\n"
+ "public:\n"
+ "  using AA = na::A; using B = na::Base;\n"
+ "  using Base::m; using Base::Base;\n"
+ "};"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, TypeInNestedNameSpecifier) {
   std::string Code =
   "namespace na {\n"
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -327,6 +327,11 @@
   hasAncestor(cxxRecordDecl()),
   allOf(IsInMovedNs, unless(cxxRecordDecl(unless(isDefinition(;
 
+  // Using shadow declarations in classes always refers to base class, which
+  // does not need to be qualified since it can be inferred from inheritance.
+  auto UsingShadowDeclInClass =
+  usingDecl(hasAnyUsingShadowDecl(decl()), hasParent(cxxRecordDecl()));
+
   // Match TypeLocs on the declaration. Carefully match only the outermost
   // TypeLoc and template specialization arguments (which are not outermost)
   // that are directly linked to types matching `DeclMatcher`. Nested name
@@ -337,28 +342,36 @@
   unless(anyOf(hasParent(typeLoc(loc(qualType(
allOf(hasDeclaration(DeclMatcher),
  unless(templateSpecializationType())),
-   hasParent(nestedNameSpecifierLoc(,
+   hasParent(nestedNameSpecifierLoc()),
+   hasAncestor(isImplicit()),
+   hasAncestor(UsingShadowDeclInClass))),
   hasAncestor(decl().bind("dc")))
   .bind("type"),
   this);
 
   // Types in `UsingShadowDecl` is not matched by `typeLoc` above, so we need to
   // special case it.
-  Finder->addMatcher(usingDecl(IsInMovedNs, hasAnyUsingShadowDecl(decl()))
+  // Since using declarations inside classes must have the base class in the
+  // nested name specifier, we leave it to the nested name specifier matcher.
+  Finder->addMatcher(usingDecl(IsInMovedNs, hasAnyUsingShadowDecl(decl()),
+   unless(UsingShadowDeclInClass))
  .bind("using_with_shadow"),
  this);
 
   // Handle types in nested name specifier. Specifiers that are in a TypeLoc
   // matched above are not matched, e.g. "A::" in "A::A" is not matched since
   // "A::A" would have already been fixed.
-  Finder->addMatcher(nestedNameSpecifierLoc(
- hasAncestor(decl(IsInMovedNs).bind("dc")),
- loc(nestedNameSpecifier(specifiesType(
- hasDeclaration(DeclMatcher.bind("from_decl"),
- unless(hasAncestor(typeLoc(loc(qualType(hasDeclaration(
- decl(equalsBoundNode("from_decl")
- .bind("nested_specifier_loc"),
- this);
+  Finder->addMatcher(
+  nestedNameSpecifierLoc(
+  hasAncestor(decl(IsInMovedNs).bind("dc")),
+  loc(nestedNameSpecifier(
+  speci

[PATCH] D27304: [PATCH] [Sema][X86] Don't allow floating-point return types when SSE is disabled

2016-12-07 Thread Visoiu Mistrih Francis via Phabricator via cfe-commits
thegameg added a comment.

LLVM patch here: https://reviews.llvm.org/D27522


https://reviews.llvm.org/D27304



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


[PATCH] D27123: Add AVR target and toolchain to Clang

2016-12-07 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs added a comment.

In https://reviews.llvm.org/D27123#615738, @saaadhu wrote:

> Thanks, setting DoubleFormat and LongDoubleFormat fixed the __DBL_ and 
> __LDBL_ differences. Also, setting SigAtomicType fixed the __SIG_ATOMIC_ 
> differences as well. I've added those defines to the test. Unrelated, but I 
> also removed a redundant set of LongLongAlign and overriding of 
> GetDefaultDwarfVersion (returning 2 wasn't necessary).
>
> The only remaining  (textually) conflicting defines between "avr-gcc -dM -E" 
> and "clang -dM -E" are
>
> 1. short vs int for a bunch of __xxx_TYPE__ defines, like say 
> __CHAR16_TYPE__. short and int are both 2 bytes for the avr, so I think 
> either one is ok.


This will bite you when it comes to C++. Those two types are mangled 
differently, so you'll get an ABI mismatch in overloads that use those typedefs.

> 2. Casts vs plain literals in the defines for double MIN, MAX values.  
> avr-gcc, for example, defines #define __DBL_MAX__ ((double)3.40282347e+38L), 
> whereas clang does  #define __DBL_MAX__ 3.40282347e+38. Again, I think this 
> shouldn't matter - I've added the literals sans the cast to the test.

That should be fine.


https://reviews.llvm.org/D27123



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


[PATCH] D26196: Add support for non-zero null pointer for C and OpenCL

2016-12-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 4 inline comments as done.
yaxunl added inline comments.



Comment at: lib/CodeGen/CGExprScalar.cpp:1532
+  return llvm::ConstantInt::get(ConvertType(DestTy),
+  CGF.getContext().getTargetNullPtrValue(E->getType()));
 assert(!DestTy->isBooleanType() && "bool should use PointerToBool");

rjmccall wrote:
> yaxunl wrote:
> > rjmccall wrote:
> > > Why is this necessary?  ptrtoint on the recursively-emitted null pointer 
> > > should do this automatically.
> > Since the target knows the value in the null pointers, it can fold a null 
> > pointer to integer literal directly.
> > 
> > The above code does that, e.g.
> > 
> > ```
> > void test_cast_null_pointer_to_sizet_calee(size_t arg_private,
> >size_t arg_local,
> >size_t arg_global,
> >size_t arg_constant,
> >size_t arg_generic);
> > 
> > // CHECK-LABEL: test_cast_null_pointer_to_sizet
> > // CHECK: call void @test_cast_null_pointer_to_sizet_calee(i64 -1, i64 -1, 
> > i64 0, i64 0, i64 0)
> > void test_cast_null_pointer_to_sizet(void) {
> >   test_cast_null_pointer_to_sizet_calee((size_t)((private char*)0),
> > (size_t)((local char*)0),
> > (size_t)((global char*)0),
> > (size_t)((constant char*)0),
> > (size_t)((generic char*)0));
> > }
> > 
> > ```
> > 
> > Without the above code, we only get ptrtoint instructions.
> Oh, does the constant folder not know how to fold ptrtoint(inttoptr(X)) -> X? 
>  I guess that's probably LLVM's nominal target-independence rearing its head.
> 
> Is getting a slightly LLVM constant actually important here?  I would prefer 
> to avoid this complexity (and unnecessary recursive walk) if possible.
Since it's target dependent, it won't be constant folded by the target agnostic 
passes until very late in the backend, which may lose optimization 
opportunities. I think it's better folded by FE like other constants.


https://reviews.llvm.org/D26196



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


r288914 - [analyzer] pr31226: Disable CastSizeChecker in C++ because it's not quite ready.

2016-12-07 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Dec  7 10:12:26 2016
New Revision: 288914

URL: http://llvm.org/viewvc/llvm-project?rev=288914&view=rev
Log:
[analyzer] pr31226: Disable CastSizeChecker in C++ because it's not quite ready.

Avoids a crash and a related false positive.

Investigation by Daniel Krupp!

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp
cfe/trunk/test/Analysis/malloc.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp?rev=288914&r1=288913&r2=288914&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp Wed Dec  7 
10:12:26 2016
@@ -140,5 +140,10 @@ void CastSizeChecker::checkPreStmt(const
 }
 
 void ento::registerCastSizeChecker(CheckerManager &mgr) {
-  mgr.registerChecker();
+  // PR31226: C++ is more complicated than what this checker currently 
supports.
+  // There are derived-to-base casts, there are different rules for 0-size
+  // structures, no flexible arrays, etc.
+  // FIXME: Disabled on C++ for now.
+  if (!mgr.getLangOpts().CPlusPlus)
+mgr.registerChecker();
 }

Modified: cfe/trunk/test/Analysis/malloc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.cpp?rev=288914&r1=288913&r2=288914&view=diff
==
--- cfe/trunk/test/Analysis/malloc.cpp (original)
+++ cfe/trunk/test/Analysis/malloc.cpp Wed Dec  7 10:12:26 2016
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc
 -analyzer-store=region -verify %s
+// RUN: %clang_cc1 -w -analyze 
-analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus.NewDelete
 -analyzer-store=region -verify %s
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -w -analyze 
-analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus.NewDelete
 -analyzer-store=region -verify %s
 
 typedef __typeof(sizeof(int)) size_t;
 void *malloc(size_t);
@@ -105,4 +106,22 @@ void appendWrapperNested(char *getterNam
 void fooNested(const char* name) {
   char* getterName = strdup(name);
   appendWrapperNested(getterName); // no-warning
-}
\ No newline at end of file
+}
+
+namespace PR31226 {
+  struct b2 {
+int f;
+  };
+
+  struct b1 : virtual b2 {
+void m();
+  };
+
+  struct d : b1, b2 {
+  };
+
+  void f() {
+d *p = new d();
+p->m(); // no-crash // no-warning
+  }
+}


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


[PATCH] D26503: [Parser][ObjC] Improve diagnostics and recovery when C++ keywords are used as identifiers in Objective-C++

2016-12-07 Thread Manman Ren via Phabricator via cfe-commits
manmanren accepted this revision.
manmanren added a comment.
This revision is now accepted and ready to land.

LGTM

Manman


Repository:
  rL LLVM

https://reviews.llvm.org/D26503



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


[PATCH] D26196: Add support for non-zero null pointer for C and OpenCL

2016-12-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated the summary for this revision.
yaxunl updated this revision to Diff 80600.
yaxunl marked an inline comment as done.
yaxunl added a comment.

Revised by John's comments.

Fixed typos.
Changed parameter of performAddrSpaceCast.
Fixed constant folding of ptrtoint with side effect and added a test.


https://reviews.llvm.org/D26196

Files:
  include/clang/AST/APValue.h
  include/clang/AST/ASTContext.h
  include/clang/Basic/TargetInfo.h
  lib/AST/APValue.cpp
  lib/AST/ASTContext.cpp
  lib/AST/ExprConstant.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/CodeGenTypes.h
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -0,0 +1,530 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -include opencl-c.h -triple amdgcn -fno-common -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -O0 -cl-std=CL2.0 -include opencl-c.h -triple amdgcn -fno-common -emit-llvm -o - | FileCheck --check-prefix=NOOPT %s
+
+typedef struct {
+  private char *p1;
+  local char *p2;
+  constant char *p3;
+  global char *p4;
+  generic char *p5;
+} StructTy1;
+
+typedef struct {
+  constant char *p3;
+  global char *p4;
+  generic char *p5;
+} StructTy2;
+
+// LLVM requests global variable with common linkage to be initialized with zeroinitializer, therefore use -fno-common
+// to suppress common linkage for tentative definition.
+
+// Test 0 as initializer.
+
+// CHECK: @private_p = local_unnamed_addr addrspace(1) global i8* addrspacecast (i8 addrspace(4)* null to i8*), align 4
+private char *private_p = 0;
+
+// CHECK: @local_p = local_unnamed_addr addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4
+local char *local_p = 0;
+
+// CHECK: @global_p = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 4
+global char *global_p = 0;
+
+// CHECK: @constant_p = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 4
+constant char *constant_p = 0;
+
+// CHECK: @generic_p = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 4
+generic char *generic_p = 0;
+
+// Test NULL as initializer.
+
+// CHECK: @private_p_NULL = local_unnamed_addr addrspace(1) global i8* addrspacecast (i8 addrspace(4)* null to i8*), align 4
+private char *private_p_NULL = NULL;
+
+// CHECK: @local_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4
+local char *local_p_NULL = NULL;
+
+// CHECK: @global_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 4
+global char *global_p_NULL = NULL;
+
+// CHECK: @constant_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 4
+constant char *constant_p_NULL = NULL;
+
+// CHECK: @generic_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 4
+generic char *generic_p_NULL = NULL;
+
+// Test constant folding of null pointer.
+// A null pointer should be folded to a null pointer in the target address space.
+
+// CHECK: @fold_generic = local_unnamed_addr addrspace(1) global i32 addrspace(4)* null, align 4
+generic int *fold_generic = (global int*)(generic float*)(private char*)0;
+
+// CHECK: @fold_priv = local_unnamed_addr addrspace(1) global i16* addrspacecast (i16 addrspace(4)* null to i16*), align 4
+private short *fold_priv = (private short*)(generic int*)(global void*)0;
+
+// CHECK: @fold_priv_arith = local_unnamed_addr addrspace(1) global i8* inttoptr (i32 9 to i8*), align 4
+private char *fold_priv_arith = (private char*)0 + 10;
+
+// CHECK: @fold_int = local_unnamed_addr addrspace(1) global i32 13, align 4
+int fold_int = (int)(private void*)(generic char*)(global int*)0 + 14;
+
+// CHECK: @fold_int2 = local_unnamed_addr addrspace(1) global i32 12, align 4
+int fold_int2 = (int) ((private void*)0 + 13);
+
+// CHECK: @fold_int3 = local_unnamed_addr addrspace(1) global i32 -1, align 4
+int fold_int3 = (int) ((private int*)0);
+
+// CHECK: @fold_int4 = local_unnamed_addr addrspace(1) global i32 7, align 4
+int fold_int4 = (int) &((private int*)0)[2];
+
+// CHECK: @fold_int5 = local_unnamed_addr addrspace(1) global i32 3, align 4
+int fold_int5 = (int) &((private StructTy1*)0)->p2;
+
+// Test static variable initialization.
+
+// NOOPT: @test_static_var.sp1 = internal addrspace(1) global i8* addrspacecast (i8 addrspace(4)* null to i8*), align 4
+// NOOPT: @test_static_var.sp2 = internal addrspace(1) global i8* addrspacecast (i8 addrspace(4)* null to i8*), align 4
+// NOOPT: @test_static_var.sp3 = internal addrspace(1) global i8* addrspacecast (i8 addrspace(4)* null to i8*), align 4
+// NOOPT: @test_sta

[PATCH] D27409: [analyzer] RetainCountChecker: The callback in dispatch_data_create() doesn't free the return symbol.

2016-12-07 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ retitled this revision from "[analyzer] RetainCountChecker: Improve support 
for libdispatch APIs." to "[analyzer] RetainCountChecker: The callback in 
dispatch_data_create() doesn't free the return symbol.".
NoQ updated the summary for this revision.
NoQ updated this revision to Diff 80606.
NoQ added a comment.

Revert the attempt to support dispatch_{retain,release}. Disable the relevant 
tests.

Move tests to `retain-release-arc.m`.


https://reviews.llvm.org/D27409

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  test/Analysis/retain-release-arc.m

Index: test/Analysis/retain-release-arc.m
===
--- test/Analysis/retain-release-arc.m
+++ test/Analysis/retain-release-arc.m
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -fobjc-arc -fblocks -verify -Wno-objc-root-class %s -analyzer-output=text
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -fblocks -verify -Wno-objc-root-class %s -analyzer-output=text
 
+typedef __typeof(sizeof(int)) size_t;
+
 #define HAS_ARC __has_feature(objc_arc)
 
 typedef unsigned long long CFOptionFlags;
@@ -45,6 +47,41 @@
 @interface NSDictionary : NSObject
 @end
 
+#define OS_OBJECT_RETURNS_RETAINED __attribute__((__ns_returns_retained__))
+#define DISPATCH_RETURNS_RETAINED OS_OBJECT_RETURNS_RETAINED
+
+@protocol OS_dispatch_object
+@end
+@protocol OS_dispatch_data 
+@end
+@protocol OS_dispatch_queue 
+@end
+
+typedef NSObject *dispatch_object_t;
+typedef NSObject *dispatch_data_t;
+typedef NSObject *dispatch_queue_t;
+
+typedef void (^dispatch_block_t)(void);
+
+dispatch_queue_t dispatch_get_main_queue(void);
+
+DISPATCH_RETURNS_RETAINED dispatch_data_t
+dispatch_data_create(const void *buffer, size_t size,
+ dispatch_queue_t _Nullable queue,
+ dispatch_block_t _Nullable destructor);
+
+void _dispatch_object_validate(dispatch_object_t object);
+
+#define dispatch_retain(object) \
+  __extension__({ dispatch_object_t _o = (object); \
+  _dispatch_object_validate(_o); \
+  (void)[_o retain]; })
+#define dispatch_release(object) \
+  __extension__({ dispatch_object_t _o = (object); \
+  _dispatch_object_validate(_o); \
+  [_o release]; })
+
+
 @interface SomeClass
 @end
 
@@ -84,3 +121,46 @@
 }
 @end
 
+int buf[1024];
+
+void libdispatch_leaked_data() {
+  dispatch_data_t data = dispatch_data_create(buf, 1024,
+  dispatch_get_main_queue(), ^{});
+}
+#if !HAS_ARC
+  // expected-warning@-2{{Potential leak of an object stored into 'data'}}
+  // expected-note@-5{{Call to function 'dispatch_data_create' returns an Objective-C object with a +1 retain count}}
+  // expected-note@-4{{Object leaked: object allocated and stored into 'data' is not referenced later in this execution path and has a retain count of +1}}
+#endif
+
+void libdispatch_dispatch_released_data() {
+  dispatch_data_t data = dispatch_data_create(buf, 1024,
+  dispatch_get_main_queue(), ^{});
+#if !HAS_ARC
+  dispatch_release(data); // no-warning
+#endif
+}
+
+void libdispatch_objc_released_data() {
+  dispatch_data_t data = dispatch_data_create(buf, 1024,
+  dispatch_get_main_queue(), ^{});
+#if !HAS_ARC
+  [data release]; // no-warning
+#endif
+}
+
+void libdispatch_leaked_retained_data() {
+  dispatch_data_t data = dispatch_data_create(buf, 1024,
+  dispatch_get_main_queue(), ^{});
+#if !HAS_ARC
+  dispatch_retain(data);
+  [data release];
+#endif
+}
+#if !HAS_ARC
+// expected-warning@-2{{Potential leak of an object stored into 'data'}}
+// expected-note@-9{{Call to function 'dispatch_data_create' returns an Objective-C object with a +1 retain count}}
+// expected-note@-7{{Reference count incremented. The object now has a +2 retain count}}
+// expected-note@-7{{Reference count decremented. The object now has a +1 retain count}}
+// expected-note@-6{{Object leaked: object allocated and stored into 'data' is not referenced later in this execution path and has a retain count of +1}}
+#endif
Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -953,7 +953,10 @@
   if (IdentifierInfo *Name = FC->getDecl()->getIdentifier()) {
 // When the CGBitmapContext is deallocated, the callback here will free
 // the associated data buffer.
-if (Name->isStr("CGBitmapContextCreateWithData"))
+// The callback in dispatch_data

[PATCH] D27438: clang-format-vsix: add a date stamp to the VSIX version number to ensure upgradability

2016-12-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D27438#615396, @amaiorano wrote:

> > Yes, I think this is still a worthwhile change. Let's add the hour and 
> > minute and get it landed.
>
> Alright, added hour and minute. How do we land this change? Is this something 
> I can now do myself? Or would you need to commit this for me again?
>
> I have a couple of more interesting changes coming. Perhaps it would make 
> sense to grant me commit rights?


It's worth a shot :-) Follow the instructions at 
http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access to ask Chris 
for commit access.


https://reviews.llvm.org/D27438



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


r288917 - [analyzer] Remove an unused enum value in RetainCountChecker.

2016-12-07 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Dec  7 10:51:54 2016
New Revision: 288917

URL: http://llvm.org/viewvc/llvm-project?rev=288917&view=rev
Log:
[analyzer] Remove an unused enum value in RetainCountChecker.

No functional change intended.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h?rev=288917&r1=288916&r2=288917&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h Wed Dec  
7 10:51:54 2016
@@ -120,9 +120,6 @@ public:
 NoRet,
 /// Indicates that the returned value is an owned (+1) symbol.
 OwnedSymbol,
-/// Indicates that the returned value is an owned (+1) symbol and
-/// that it should be treated as freshly allocated.
-OwnedAllocatedSymbol,
 /// Indicates that the returned value is an object with retain count
 /// semantics but that it is not owned (+0).  This is the default
 /// for getters, etc.
@@ -163,8 +160,7 @@ public:
   ObjKind getObjKind() const { return O; }
   
   bool isOwned() const {
-return K == OwnedSymbol || K == OwnedAllocatedSymbol ||
-K == OwnedWhenTrackedReceiver;
+return K == OwnedSymbol || K == OwnedWhenTrackedReceiver;
   }
   
   bool notOwned() const {
@@ -179,8 +175,8 @@ public:
 return RetEffect(OwnedWhenTrackedReceiver, ObjC);
   }
   
-  static RetEffect MakeOwned(ObjKind o, bool isAllocated = false) {
-return RetEffect(isAllocated ? OwnedAllocatedSymbol : OwnedSymbol, o);
+  static RetEffect MakeOwned(ObjKind o) {
+return RetEffect(OwnedSymbol, o);
   }
   static RetEffect MakeNotOwned(ObjKind o) {
 return RetEffect(NotOwnedSymbol, o);

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=288917&r1=288916&r2=288917&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Wed Dec  7 
10:51:54 2016
@@ -740,7 +740,7 @@ public:
  ObjCAllocRetE(gcenabled
 ? RetEffect::MakeGCNotOwned()
 : (usesARC ? RetEffect::MakeNotOwned(RetEffect::ObjC)
-   : RetEffect::MakeOwned(RetEffect::ObjC, true))),
+   : RetEffect::MakeOwned(RetEffect::ObjC))),
  ObjCInitRetE(gcenabled
 ? RetEffect::MakeGCNotOwned()
 : (usesARC ? RetEffect::MakeNotOwned(RetEffect::ObjC)
@@ -1086,7 +1086,7 @@ RetainSummaryManager::getFunctionSummary
FName == "IOOpenFirmwarePathMatching") {
   // Part of . (IOKit)
   // This should be addressed using a API table.
-  S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF, true),
+  S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF),
DoNothing, DoNothing);
 } else if (FName == "IOServiceGetMatchingService" ||
FName == "IOServiceGetMatchingServices") {
@@ -1116,7 +1116,7 @@ RetainSummaryManager::getFunctionSummary
   // passed to CGBitmapContextCreateWithData is released via
   // a callback and doing full IPA to make sure this is done correctly.
   ScratchArgs = AF.add(ScratchArgs, 8, StopTracking);
-  S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF, true),
+  S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF),
DoNothing, DoNothing);
 } else if (FName == "CVPixelBufferCreateWithPlanarBytes") {
   // FIXES: 
@@ -1292,7 +1292,7 @@ const RetainSummary *
 RetainSummaryManager::getCFSummaryCreateRule(const FunctionDecl *FD) {
   assert (ScratchArgs.isEmpty());
 
-  return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF, true));
+  return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF));
 }
 
 const RetainSummary *
@@ -1322,7 +1322,7 @@ RetainSummaryManager::getRetEffectFromAn
   }
 
   if (D->hasAttr())
-return RetEffect::MakeOwned(RetEffect::CF, true);
+return RetEffect::MakeOwned(RetEffect::CF);
 
   if (D->hasAttr())
 return RetEffect::MakeNotOwned(RetEffect::CF);
@@ -1435,7 +1435,7 @@ RetainSummaryManager::getStandardMethodS
   case OMF_new:
   case OMF_copy:
   case OMF_mutableCopy:
-ResultEff = RetEffect::MakeOwned(RetEffect::CF, true);
+ResultEff = RetEffect::MakeOwned(RetEffect::CF);
 break;
   

[PATCH] D27408: [analyzer] RetainCountChecker: remove unused enum value; NFC.

2016-12-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288917: [analyzer] Remove an unused enum value in 
RetainCountChecker. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D27408?vs=80431&id=80608#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27408

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h
  cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -740,7 +740,7 @@
  ObjCAllocRetE(gcenabled
 ? RetEffect::MakeGCNotOwned()
 : (usesARC ? RetEffect::MakeNotOwned(RetEffect::ObjC)
-   : RetEffect::MakeOwned(RetEffect::ObjC, true))),
+   : RetEffect::MakeOwned(RetEffect::ObjC))),
  ObjCInitRetE(gcenabled
 ? RetEffect::MakeGCNotOwned()
 : (usesARC ? RetEffect::MakeNotOwned(RetEffect::ObjC)
@@ -1086,7 +1086,7 @@
FName == "IOOpenFirmwarePathMatching") {
   // Part of . (IOKit)
   // This should be addressed using a API table.
-  S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF, true),
+  S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF),
DoNothing, DoNothing);
 } else if (FName == "IOServiceGetMatchingService" ||
FName == "IOServiceGetMatchingServices") {
@@ -1116,7 +1116,7 @@
   // passed to CGBitmapContextCreateWithData is released via
   // a callback and doing full IPA to make sure this is done correctly.
   ScratchArgs = AF.add(ScratchArgs, 8, StopTracking);
-  S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF, true),
+  S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF),
DoNothing, DoNothing);
 } else if (FName == "CVPixelBufferCreateWithPlanarBytes") {
   // FIXES: 
@@ -1292,7 +1292,7 @@
 RetainSummaryManager::getCFSummaryCreateRule(const FunctionDecl *FD) {
   assert (ScratchArgs.isEmpty());
 
-  return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF, true));
+  return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF));
 }
 
 const RetainSummary *
@@ -1322,7 +1322,7 @@
   }
 
   if (D->hasAttr())
-return RetEffect::MakeOwned(RetEffect::CF, true);
+return RetEffect::MakeOwned(RetEffect::CF);
 
   if (D->hasAttr())
 return RetEffect::MakeNotOwned(RetEffect::CF);
@@ -1435,7 +1435,7 @@
   case OMF_new:
   case OMF_copy:
   case OMF_mutableCopy:
-ResultEff = RetEffect::MakeOwned(RetEffect::CF, true);
+ResultEff = RetEffect::MakeOwned(RetEffect::CF);
 break;
   default:
 ResultEff = RetEffect::MakeNotOwned(RetEffect::CF);
@@ -1457,7 +1457,7 @@
   if (cocoa::isCocoaObjectRef(RetTy))
 ResultEff = ObjCAllocRetE;
   else if (coreFoundation::isCFObjectRef(RetTy))
-ResultEff = RetEffect::MakeOwned(RetEffect::CF, true);
+ResultEff = RetEffect::MakeOwned(RetEffect::CF);
   break;
 case OMF_autorelease:
   ReceiverEff = Autorelease;
@@ -1588,7 +1588,7 @@
   // The next methods are allocators.
   const RetainSummary *AllocSumm = getPersistentSummary(ObjCAllocRetE);
   const RetainSummary *CFAllocSumm =
-getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF, true));
+getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF));
 
   // Create the "retain" selector.
   RetEffect NoRet = RetEffect::MakeNoRet();
@@ -3076,7 +3076,6 @@
   // No work necessary.
   break;
 
-case RetEffect::OwnedAllocatedSymbol:
 case RetEffect::OwnedSymbol: {
   SymbolRef Sym = CallOrMsg.getReturnValue().getAsSymbol();
   if (!Sym)
Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h
@@ -120,9 +120,6 @@
 NoRet,
 /// Indicates that the returned value is an owned (+1) symbol.
 OwnedSymbol,
-/// Indicates that the returned value is an owned (+1) symbol and
-/// that it should be treated as freshly allocated.
-OwnedAllocatedSymbol,
 /// Indicates that the returned value is an object with retain count
 /// semantics but that it is not owned (+0).  This is the default
 /// for getters, etc.
@@ -163,8 +160,7 @@
   ObjKind getObjKind() const { return O; }
   
   bool isOwned() const {
-return K == OwnedSymbol || K == OwnedAllocatedSymbol ||
-K == OwnedWhenTrackedReceiver;
+return K == OwnedSymbol || K == 

[PATCH] D27523: [change-namespace] don't fix using shadow decls in classes.

2016-12-07 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added inline comments.
This revision is now accepted and ready to land.



Comment at: change-namespace/ChangeNamespace.cpp:331
+  // Using shadow declarations in classes always refers to base class, which
+  // does not need to be qualified since it can be inferred from inheritance.
+  auto UsingShadowDeclInClass =

Maybe add to this comment that you're matching non-alias using declarations.


https://reviews.llvm.org/D27523



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


[PATCH] D27523: [change-namespace] don't fix using shadow decls in classes.

2016-12-07 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 80613.
ioeric added a comment.

- address review comment.


https://reviews.llvm.org/D27523

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
@@ -425,6 +425,36 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, DontFixUsingShadowDeclInClasses) {
+  std::string Code = "namespace na {\n"
+ "class A {};\n"
+ "class Base { public: Base() {} void m() {} };\n"
+ "namespace nb {\n"
+ "class D : public Base {\n"
+ "public:\n"
+ "  using AA = A; using B = Base;\n"
+ "  using Base::m; using Base::Base;\n"
+ "};"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+
+  std::string Expected = "namespace na {\n"
+ "class A {};\n"
+ "class Base { public: Base() {} void m() {} };\n"
+ "\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "class D : public na::Base {\n"
+ "public:\n"
+ "  using AA = na::A; using B = na::Base;\n"
+ "  using Base::m; using Base::Base;\n"
+ "};"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, TypeInNestedNameSpecifier) {
   std::string Code =
   "namespace na {\n"
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -327,6 +327,12 @@
   hasAncestor(cxxRecordDecl()),
   allOf(IsInMovedNs, unless(cxxRecordDecl(unless(isDefinition(;
 
+  // Using shadow declarations in classes always refers to base class, which
+  // does not need to be qualified since it can be inferred from inheritance.
+  // Note that this does not match using alias declarations.
+  auto UsingShadowDeclInClass =
+  usingDecl(hasAnyUsingShadowDecl(decl()), hasParent(cxxRecordDecl()));
+
   // Match TypeLocs on the declaration. Carefully match only the outermost
   // TypeLoc and template specialization arguments (which are not outermost)
   // that are directly linked to types matching `DeclMatcher`. Nested name
@@ -337,28 +343,36 @@
   unless(anyOf(hasParent(typeLoc(loc(qualType(
allOf(hasDeclaration(DeclMatcher),
  unless(templateSpecializationType())),
-   hasParent(nestedNameSpecifierLoc(,
+   hasParent(nestedNameSpecifierLoc()),
+   hasAncestor(isImplicit()),
+   hasAncestor(UsingShadowDeclInClass))),
   hasAncestor(decl().bind("dc")))
   .bind("type"),
   this);
 
   // Types in `UsingShadowDecl` is not matched by `typeLoc` above, so we need to
   // special case it.
-  Finder->addMatcher(usingDecl(IsInMovedNs, hasAnyUsingShadowDecl(decl()))
+  // Since using declarations inside classes must have the base class in the
+  // nested name specifier, we leave it to the nested name specifier matcher.
+  Finder->addMatcher(usingDecl(IsInMovedNs, hasAnyUsingShadowDecl(decl()),
+   unless(UsingShadowDeclInClass))
  .bind("using_with_shadow"),
  this);
 
   // Handle types in nested name specifier. Specifiers that are in a TypeLoc
   // matched above are not matched, e.g. "A::" in "A::A" is not matched since
   // "A::A" would have already been fixed.
-  Finder->addMatcher(nestedNameSpecifierLoc(
- hasAncestor(decl(IsInMovedNs).bind("dc")),
- loc(nestedNameSpecifier(specifiesType(
- hasDeclaration(DeclMatcher.bind("from_decl"),
- unless(hasAncestor(typeLoc(loc(qualType(hasDeclaration(
- decl(equalsBoundNode("from_decl")
- .bind("nested_specifier_loc"),
- this);
+  Finder->addMatcher(
+  nestedNameSpecifierLoc(
+  hasAncestor(decl(IsInMovedNs).bind("dc")),
+  loc(nestedNameSpecifier(
+  specifiesType(hasDeclaration(DeclMatcher.bind("from_decl"),
+  unless(anyOf(hasAncestor(isIm

[clang-tools-extra] r288919 - [change-namespace] don't fix using shadow decls in classes.

2016-12-07 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Wed Dec  7 11:04:07 2016
New Revision: 288919

URL: http://llvm.org/viewvc/llvm-project?rev=288919&view=rev
Log:
[change-namespace] don't fix using shadow decls in classes.

Summary:
Using shadow declarations in classes always refers to base class, which does not
need to be fixed/qualified since it can be inferred from inheritance.

Reviewers: bkramer

Subscribers: cfe-commits

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

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=288919&r1=288918&r2=288919&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Wed Dec  7 
11:04:07 2016
@@ -327,6 +327,12 @@ void ChangeNamespaceTool::registerMatche
   hasAncestor(cxxRecordDecl()),
   allOf(IsInMovedNs, unless(cxxRecordDecl(unless(isDefinition(;
 
+  // Using shadow declarations in classes always refers to base class, which
+  // does not need to be qualified since it can be inferred from inheritance.
+  // Note that this does not match using alias declarations.
+  auto UsingShadowDeclInClass =
+  usingDecl(hasAnyUsingShadowDecl(decl()), hasParent(cxxRecordDecl()));
+
   // Match TypeLocs on the declaration. Carefully match only the outermost
   // TypeLoc and template specialization arguments (which are not outermost)
   // that are directly linked to types matching `DeclMatcher`. Nested name
@@ -337,28 +343,36 @@ void ChangeNamespaceTool::registerMatche
   unless(anyOf(hasParent(typeLoc(loc(qualType(
allOf(hasDeclaration(DeclMatcher),
  unless(templateSpecializationType())),
-   hasParent(nestedNameSpecifierLoc(,
+   hasParent(nestedNameSpecifierLoc()),
+   hasAncestor(isImplicit()),
+   hasAncestor(UsingShadowDeclInClass))),
   hasAncestor(decl().bind("dc")))
   .bind("type"),
   this);
 
   // Types in `UsingShadowDecl` is not matched by `typeLoc` above, so we need 
to
   // special case it.
-  Finder->addMatcher(usingDecl(IsInMovedNs, hasAnyUsingShadowDecl(decl()))
+  // Since using declarations inside classes must have the base class in the
+  // nested name specifier, we leave it to the nested name specifier matcher.
+  Finder->addMatcher(usingDecl(IsInMovedNs, hasAnyUsingShadowDecl(decl()),
+   unless(UsingShadowDeclInClass))
  .bind("using_with_shadow"),
  this);
 
   // Handle types in nested name specifier. Specifiers that are in a TypeLoc
   // matched above are not matched, e.g. "A::" in "A::A" is not matched since
   // "A::A" would have already been fixed.
-  Finder->addMatcher(nestedNameSpecifierLoc(
- hasAncestor(decl(IsInMovedNs).bind("dc")),
- loc(nestedNameSpecifier(specifiesType(
- hasDeclaration(DeclMatcher.bind("from_decl"),
- 
unless(hasAncestor(typeLoc(loc(qualType(hasDeclaration(
- decl(equalsBoundNode("from_decl")
- .bind("nested_specifier_loc"),
- this);
+  Finder->addMatcher(
+  nestedNameSpecifierLoc(
+  hasAncestor(decl(IsInMovedNs).bind("dc")),
+  loc(nestedNameSpecifier(
+  specifiesType(hasDeclaration(DeclMatcher.bind("from_decl"),
+  unless(anyOf(hasAncestor(isImplicit()),
+   hasAncestor(UsingShadowDeclInClass),
+   hasAncestor(typeLoc(loc(qualType(hasDeclaration(
+   decl(equalsBoundNode("from_decl"))
+  .bind("nested_specifier_loc"),
+  this);
 
   // Matches base class initializers in constructors. TypeLocs of base class
   // initializers do not need to be fixed. For example,

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=288919&r1=288918&r2=288919&view=diff
==
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
Wed Dec  7 11:04:07 2016
@@ -425,6 +425,36 @@ TEST_F(ChangeNamespaceTest, FixUsingShad
   EXPECT_EQ(format(Expected), runChang

[PATCH] D27523: [change-namespace] don't fix using shadow decls in classes.

2016-12-07 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288919: [change-namespace] don't fix using shadow decls in 
classes. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D27523?vs=80613&id=80615#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27523

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
@@ -327,6 +327,12 @@
   hasAncestor(cxxRecordDecl()),
   allOf(IsInMovedNs, unless(cxxRecordDecl(unless(isDefinition(;
 
+  // Using shadow declarations in classes always refers to base class, which
+  // does not need to be qualified since it can be inferred from inheritance.
+  // Note that this does not match using alias declarations.
+  auto UsingShadowDeclInClass =
+  usingDecl(hasAnyUsingShadowDecl(decl()), hasParent(cxxRecordDecl()));
+
   // Match TypeLocs on the declaration. Carefully match only the outermost
   // TypeLoc and template specialization arguments (which are not outermost)
   // that are directly linked to types matching `DeclMatcher`. Nested name
@@ -337,28 +343,36 @@
   unless(anyOf(hasParent(typeLoc(loc(qualType(
allOf(hasDeclaration(DeclMatcher),
  unless(templateSpecializationType())),
-   hasParent(nestedNameSpecifierLoc(,
+   hasParent(nestedNameSpecifierLoc()),
+   hasAncestor(isImplicit()),
+   hasAncestor(UsingShadowDeclInClass))),
   hasAncestor(decl().bind("dc")))
   .bind("type"),
   this);
 
   // Types in `UsingShadowDecl` is not matched by `typeLoc` above, so we need to
   // special case it.
-  Finder->addMatcher(usingDecl(IsInMovedNs, hasAnyUsingShadowDecl(decl()))
+  // Since using declarations inside classes must have the base class in the
+  // nested name specifier, we leave it to the nested name specifier matcher.
+  Finder->addMatcher(usingDecl(IsInMovedNs, hasAnyUsingShadowDecl(decl()),
+   unless(UsingShadowDeclInClass))
  .bind("using_with_shadow"),
  this);
 
   // Handle types in nested name specifier. Specifiers that are in a TypeLoc
   // matched above are not matched, e.g. "A::" in "A::A" is not matched since
   // "A::A" would have already been fixed.
-  Finder->addMatcher(nestedNameSpecifierLoc(
- hasAncestor(decl(IsInMovedNs).bind("dc")),
- loc(nestedNameSpecifier(specifiesType(
- hasDeclaration(DeclMatcher.bind("from_decl"),
- unless(hasAncestor(typeLoc(loc(qualType(hasDeclaration(
- decl(equalsBoundNode("from_decl")
- .bind("nested_specifier_loc"),
- this);
+  Finder->addMatcher(
+  nestedNameSpecifierLoc(
+  hasAncestor(decl(IsInMovedNs).bind("dc")),
+  loc(nestedNameSpecifier(
+  specifiesType(hasDeclaration(DeclMatcher.bind("from_decl"),
+  unless(anyOf(hasAncestor(isImplicit()),
+   hasAncestor(UsingShadowDeclInClass),
+   hasAncestor(typeLoc(loc(qualType(hasDeclaration(
+   decl(equalsBoundNode("from_decl"))
+  .bind("nested_specifier_loc"),
+  this);
 
   // Matches base class initializers in constructors. TypeLocs of base class
   // initializers do not need to be fixed. For example,
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
@@ -425,6 +425,36 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, DontFixUsingShadowDeclInClasses) {
+  std::string Code = "namespace na {\n"
+ "class A {};\n"
+ "class Base { public: Base() {} void m() {} };\n"
+ "namespace nb {\n"
+ "class D : public Base {\n"
+ "public:\n"
+ "  using AA = A; using B = Base;\n"
+ "  using Base::m; using Base::Base;\n"
+ "};"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+
+  std::string Expected = "namespace na {\n"
+  

[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-12-07 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

ping.


https://reviews.llvm.org/D27166



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


[PATCH] D27053: [CodeCompletion] Provide Objective-C class property completion results

2016-12-07 Thread Manman Ren via Phabricator via cfe-commits
manmanren accepted this revision.
manmanren added a comment.
This revision is now accepted and ready to land.

LGTM .

Manman




Comment at: lib/Sema/SemaCodeComplete.cpp:3763
+if (!M->getSelector().isUnarySelector() ||
+M->getReturnType()->isVoidType() || M->isInstanceMethod())
+  continue;

Can you put a comment here on the conditions?


Repository:
  rL LLVM

https://reviews.llvm.org/D27053



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


r288922 - [analyzer] Fix typo in nullability checker diagnostic

2016-12-07 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Wed Dec  7 11:36:27 2016
New Revision: 288922

URL: http://llvm.org/viewvc/llvm-project?rev=288922&view=rev
Log:
[analyzer] Fix typo in nullability checker diagnostic

'infered' --> 'inferred'

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp?rev=288922&r1=288921&r2=288922&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp Wed Dec  7 
11:36:27 2016
@@ -333,7 +333,7 @@ PathDiagnosticPiece *NullabilityChecker:
 
   std::string InfoText =
   (llvm::Twine("Nullability '") +
-   getNullabilityString(TrackedNullab->getValue()) + "' is infered")
+   getNullabilityString(TrackedNullab->getValue()) + "' is inferred")
   .str();
 
   // Generate the extra diagnostic.


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


[PATCH] D26742: [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator

2016-12-07 Thread Malcolm Parsons via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288923: [RecursiveASTVisitor] Fix post-order traversal of 
UnaryOperator (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D26742?vs=78165&id=80621#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26742

Files:
  cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
  cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp


Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -357,7 +357,8 @@
 #define OPERATOR(NAME) 
\
   bool TraverseUnary##NAME(UnaryOperator *S,   
\
DataRecursionQueue *Queue = nullptr) {  
\
-TRY_TO(WalkUpFromUnary##NAME(S));  
\
+if (!getDerived().shouldTraversePostOrder())   
\
+  TRY_TO(WalkUpFromUnary##NAME(S));
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());  
\
 return true;   
\
   }
\
Index: cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp
===
--- cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp
+++ cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp
@@ -34,6 +34,11 @@
 
 bool shouldTraversePostOrder() const { return VisitPostOrder; }
 
+bool VisitUnaryOperator(UnaryOperator *Op) {
+  VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode()));
+  return true;
+}
+
 bool VisitBinaryOperator(BinaryOperator *Op) {
   VisitedNodes.push_back(Op->getOpcodeStr());
   return true;
@@ -76,7 +81,7 @@
   auto ASTUnit = tooling::buildASTFromCode(
 "class A {"
 "  class B {"
-"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }"
+"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }"
 "  };"
 "};"
   );
@@ -87,7 +92,7 @@
   Visitor.TraverseTranslationUnitDecl(TU);
 
   std::vector expected = {
-"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
+"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", 
"A::B", "A"
   };
   // Compare the list of actually visited nodes
   // with the expected list of visited nodes.


Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -357,7 +357,8 @@
 #define OPERATOR(NAME) \
   bool TraverseUnary##NAME(UnaryOperator *S,   \
DataRecursionQueue *Queue = nullptr) {  \
-TRY_TO(WalkUpFromUnary##NAME(S));  \
+if (!getDerived().shouldTraversePostOrder())   \
+  TRY_TO(WalkUpFromUnary##NAME(S));\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());  \
 return true;   \
   }\
Index: cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp
===
--- cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp
+++ cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp
@@ -34,6 +34,11 @@
 
 bool shouldTraversePostOrder() const { return VisitPostOrder; }
 
+bool VisitUnaryOperator(UnaryOperator *Op) {
+  VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode()));
+  return true;
+}
+
 bool VisitBinaryOperator(BinaryOperator *Op) {
   VisitedNodes.push_back(Op->getOpcodeStr());
   return true;
@@ -76,7 +81,7 @@
   auto ASTUnit = tooling::buildASTFromCode(
 "class A {"
 "  class B {"
-"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }"
+"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }"
 "  };"
 "};"
   );
@@ -87,7 +92,7 @@
   Visitor.TraverseTranslationUnitDecl(TU);
 
   std::vector expected = {
-"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
+"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
   };
   // Compare the list of actually visited nodes
   // with the expected list of visited nodes.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
ht

r288923 - [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator

2016-12-07 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Dec  7 11:39:04 2016
New Revision: 288923

URL: http://llvm.org/viewvc/llvm-project?rev=288923&view=rev
Log:
[RecursiveASTVisitor] Fix post-order traversal of UnaryOperator

Reviewers: aaron.ballman, klimek, doug.gregor, teemperor, rsmith

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=288923&r1=288922&r2=288923&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Wed Dec  7 11:39:04 2016
@@ -357,7 +357,8 @@ public:
 #define OPERATOR(NAME) 
\
   bool TraverseUnary##NAME(UnaryOperator *S,   
\
DataRecursionQueue *Queue = nullptr) {  
\
-TRY_TO(WalkUpFromUnary##NAME(S));  
\
+if (!getDerived().shouldTraversePostOrder())   
\
+  TRY_TO(WalkUpFromUnary##NAME(S));
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());  
\
 return true;   
\
   }
\

Modified: cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp?rev=288923&r1=288922&r2=288923&view=diff
==
--- cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp (original)
+++ cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp Wed Dec  7 11:39:04 2016
@@ -34,6 +34,11 @@ namespace {
 
 bool shouldTraversePostOrder() const { return VisitPostOrder; }
 
+bool VisitUnaryOperator(UnaryOperator *Op) {
+  VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode()));
+  return true;
+}
+
 bool VisitBinaryOperator(BinaryOperator *Op) {
   VisitedNodes.push_back(Op->getOpcodeStr());
   return true;
@@ -76,7 +81,7 @@ TEST(RecursiveASTVisitor, PostOrderTrave
   auto ASTUnit = tooling::buildASTFromCode(
 "class A {"
 "  class B {"
-"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }"
+"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }"
 "  };"
 "};"
   );
@@ -87,7 +92,7 @@ TEST(RecursiveASTVisitor, PostOrderTrave
   Visitor.TraverseTranslationUnitDecl(TU);
 
   std::vector expected = {
-"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
+"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", 
"A::B", "A"
   };
   // Compare the list of actually visited nodes
   // with the expected list of visited nodes.


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


Re: r288923 - [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator

2016-12-07 Thread Richard Smith via cfe-commits
On 7 Dec 2016 9:49 am, "Malcolm Parsons via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

Author: malcolm.parsons
Date: Wed Dec  7 11:39:04 2016
New Revision: 288923

URL: http://llvm.org/viewvc/llvm-project?rev=288923&view=rev
Log:
[RecursiveASTVisitor] Fix post-order traversal of UnaryOperator

Reviewers: aaron.ballman, klimek, doug.gregor, teemperor, rsmith

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
clang/AST/RecursiveASTVisitor.h?rev=288923&r1=288922&r2=288923&view=diff

==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Wed Dec  7 11:39:04
2016
@@ -357,7 +357,8 @@ public:
 #define OPERATOR(NAME)
 \
   bool TraverseUnary##NAME(UnaryOperator *S,
 \
DataRecursionQueue *Queue = nullptr) {
\
-TRY_TO(WalkUpFromUnary##NAME(S));
\
+if (!getDerived().shouldTraversePostOrder())
 \
+  TRY_TO(WalkUpFromUnary##NAME(S));
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());
\
 return true;
 \
   }
\

Modified: cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/
AST/PostOrderASTVisitor.cpp?rev=288923&r1=288922&r2=288923&view=diff

==
--- cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp (original)
+++ cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp Wed Dec  7 11:39:04 2016
@@ -34,6 +34,11 @@ namespace {

 bool shouldTraversePostOrder() const { return VisitPostOrder; }

+bool VisitUnaryOperator(UnaryOperator *Op) {
+  VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode()));
+  return true;
+}
+
 bool VisitBinaryOperator(BinaryOperator *Op) {
   VisitedNodes.push_back(Op->getOpcodeStr());
   return true;
@@ -76,7 +81,7 @@ TEST(RecursiveASTVisitor, PostOrderTrave
   auto ASTUnit = tooling::buildASTFromCode(
 "class A {"
 "  class B {"
-"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }"
+"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) +
2; }"
 "  };"
 "};"
   );
@@ -87,7 +92,7 @@ TEST(RecursiveASTVisitor, PostOrderTrave
   Visitor.TraverseTranslationUnitDecl(TU);

   std::vector expected = {
-"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B",
"A"
+"4", "9", "i", "-",


Why does "i" not show up here twice? Do we not include DeclRefExprs in this
list? It looks like we're not testing the relative order of the unary
operator and its operand here.

"j", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
   };
   // Compare the list of actually visited nodes
   // with the expected list of visited nodes.


___
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


[PATCH] D26196: Add support for non-zero null pointer for C and OpenCL

2016-12-07 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGExprScalar.cpp:1532
+  return llvm::ConstantInt::get(ConvertType(DestTy),
+  CGF.getContext().getTargetNullPtrValue(E->getType()));
 assert(!DestTy->isBooleanType() && "bool should use PointerToBool");

yaxunl wrote:
> rjmccall wrote:
> > yaxunl wrote:
> > > rjmccall wrote:
> > > > Why is this necessary?  ptrtoint on the recursively-emitted null 
> > > > pointer should do this automatically.
> > > Since the target knows the value in the null pointers, it can fold a null 
> > > pointer to integer literal directly.
> > > 
> > > The above code does that, e.g.
> > > 
> > > ```
> > > void test_cast_null_pointer_to_sizet_calee(size_t arg_private,
> > >size_t arg_local,
> > >size_t arg_global,
> > >size_t arg_constant,
> > >size_t arg_generic);
> > > 
> > > // CHECK-LABEL: test_cast_null_pointer_to_sizet
> > > // CHECK: call void @test_cast_null_pointer_to_sizet_calee(i64 -1, i64 
> > > -1, i64 0, i64 0, i64 0)
> > > void test_cast_null_pointer_to_sizet(void) {
> > >   test_cast_null_pointer_to_sizet_calee((size_t)((private char*)0),
> > > (size_t)((local char*)0),
> > > (size_t)((global char*)0),
> > > (size_t)((constant char*)0),
> > > (size_t)((generic char*)0));
> > > }
> > > 
> > > ```
> > > 
> > > Without the above code, we only get ptrtoint instructions.
> > Oh, does the constant folder not know how to fold ptrtoint(inttoptr(X)) -> 
> > X?  I guess that's probably LLVM's nominal target-independence rearing its 
> > head.
> > 
> > Is getting a slightly LLVM constant actually important here?  I would 
> > prefer to avoid this complexity (and unnecessary recursive walk) if 
> > possible.
> Since it's target dependent, it won't be constant folded by the target 
> agnostic passes until very late in the backend, which may lose optimization 
> opportunities. I think it's better folded by FE like other constants.
Are you sure?  All of my attempts to produce these constants in LLVM seem to 
get instantly folded, even without a target set in the IR:
  i32 ptrtoint (i8* inttoptr (i32 -1 to i8*) to i32)
  i64 ptrtoint (i8* inttoptr (i64 -1 to i8*) to i64)
This folding literally occurs within ConstantExpr::getPtrToInt, without any 
passes running, and it seems to happen regardless of the pointer having an 
addrspace.

I suspect that the problem is that you additionally have an addrspacecast 
constant in place, which almost certainly does block the constant folder.  The 
right fix for that is to ensure that your target's implementation of 
performAddrSpaceCast makes an effort to peephole casts of Constants.



Comment at: lib/CodeGen/TargetInfo.h:236
+  virtual llvm::Value *performAddrSpaceCast(CodeGen::CodeGenFunction &CGF,
+  Expr *E, QualType DestTy) const;
+

rjmccall wrote:
> This should just take a Value* and the source and dest types.
Please also pass the source QualType.  The QualType is necessary to determine 
the source-language address space, which is how an implementation can correctly 
determine the null-pointer representation in the source type.


https://reviews.llvm.org/D26196



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


[PATCH] D27520: [clang-tidy] Add check for redundant function pointer dereferences

2016-12-07 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please mention this check in docs/ReleaseNotes.rst (in alphabetical order).




Comment at: 
docs/clang-tidy/checks/readability-redundant-function-ptr-dereference.rst:7
+Finds redundant dereferences of a function pointer.
+See https://youtu.be/6eX9gPithBo.
+

I think will be better o refer to textual representation if available.


https://reviews.llvm.org/D27520



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


[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-12-07 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 80623.
malcolm.parsons added a comment.

Remove hasReplacementType matcher.


https://reviews.llvm.org/D27166

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- test/clang-tidy/modernize-use-auto-cast.cpp
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -138,3 +138,72 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U &u);
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T &template_reference_cast(U &u);
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T &template_const_reference_cast(const U &u);
+
+template 
+T template_value_get(StringRef s);
+
+struct S {
+  template 
+  const T *template_member_get();
+};
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = template_value_cast(a);
+  B &b2 = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b3 = template_pointer_cast(a);
+  B &b4 = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = template_reference_cast(*a);
+  const B *b5 = template_const_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b5 = template_const_pointer_cast(a);
+  const B &b6 = template_const_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b6 = template_const_reference_cast(*a);
+  B *b7 = template_value_get("foo");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b7 = template_value_get("foo");
+
+  S s;
+  const B *b8 = s.template_member_get();
+
+  auto i2 = template_value_cast(d);
+  int i3 = max(i1, i2);
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -136,3 +136,64 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U &u);
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T &template_reference_cast(U &u);
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T &template_const_reference_cast(const U &u);
+
+template 
+T template_value_get(StringRef s);
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b1 = template_value_cast(a);
+  B &b2 = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  &b2 = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b3 = template_pointer_cast(a);
+  B &b4 = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK

[PATCH] D25809: [CUDA] Improved target attribute-based overloading.

2016-12-07 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D25809#615485, @jlebar wrote:

> If you would like me to have another look at this, is it possible to make an 
> interdiff of your changes between this and the last version I reviewed?  
> phab's interdiff is useless because it straddles a rebase.


I've reverted to 75652 which is the revision you've approved with a new if() to 
limit our overloading checks to FunctionDecls only.
It's a the very end of SemaCUDA.cpp (line 864):
https://reviews.llvm.org/differential/changeset/?ref=590934%2F556303&whitespace=ignore-most


https://reviews.llvm.org/D25809



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


Re: r288923 - [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator

2016-12-07 Thread Malcolm Parsons via cfe-commits
On 7 December 2016 at 17:56, Richard Smith  wrote:
> On 7 Dec 2016 9:49 am, "Malcolm Parsons via cfe-commits"
>  wrote:
>
> Author: malcolm.parsons
> Date: Wed Dec  7 11:39:04 2016
> New Revision: 288923
>
> URL: http://llvm.org/viewvc/llvm-project?rev=288923&view=rev
> Log:
> [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator
>
> Reviewers: aaron.ballman, klimek, doug.gregor, teemperor, rsmith
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D26742
>
> @@ -87,7 +92,7 @@ TEST(RecursiveASTVisitor, PostOrderTrave
>Visitor.TraverseTranslationUnitDecl(TU);
>
>std::vector expected = {
> -"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B",
> "A"
> +"4", "9", "i", "-",

> Why does "i" not show up here twice? Do we not include DeclRefExprs in this
> list? It looks like we're not testing the relative order of the unary
> operator and its operand here.

The test doesn't define VisitDeclRefExpr.

I can add it if you like.

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


[PATCH] D25809: [CUDA] Improved target attribute-based overloading.

2016-12-07 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

> I've reverted to 75652

Did you forget to arc diff?

Anyway if it's just that if statement, lgtm.


https://reviews.llvm.org/D25809



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


[PATCH] D27513: Refactor clang's ParseHelper into Support (clang part)

2016-12-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a subscriber: cfe-commits.
hans added a comment.

I've commented on the llvm side. Adding cfe-commits as well since it affects 
clang.


Repository:
  rL LLVM

https://reviews.llvm.org/D27513



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


[PATCH] D27501: clang-format-vsix: add command to format document

2016-12-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: tools/clang-format-vs/ClangFormat/ClangFormat.vsct:76
+
+  Clang Format Document
+

I think File would be better than Document when referring to source code.

But it seems a little annoying to need two menu alternatives. Could we make the 
regular "Clang Format" option just format the whole file if there is currently 
no selection, or would that be confusing?


https://reviews.llvm.org/D27501



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


r288962 - [CUDA] Improve target attribute checking for function templates.

2016-12-07 Thread Artem Belevich via cfe-commits
Author: tra
Date: Wed Dec  7 13:27:16 2016
New Revision: 288962

URL: http://llvm.org/viewvc/llvm-project?rev=288962&view=rev
Log:
[CUDA] Improve target attribute checking for function templates.

* __host__ __device__ functions are no longer considered to be
  redeclarations of __host__ or __device__ functions. This prevents
  unintentional merging of target attributes across them.
* Function target attributes are not considered (and must match) during
  explicit instantiation and specialization of function templates.

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

Added:
cfe/trunk/test/SemaCUDA/function-template-overload.cu
Removed:
cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaCUDA.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CodeGenCUDA/launch-bounds.cu
cfe/trunk/test/SemaCUDA/function-overload.cu

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=288962&r1=288961&r2=288962&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec  7 13:27:16 
2016
@@ -6821,6 +6821,11 @@ def err_cuda_host_shared : Error<
 "__shared__ local variables not allowed in "
 "%select{__device__|__global__|__host__|__host__ __device__}0 functions">;
 def err_cuda_nonglobal_constant : Error<"__constant__ variables must be 
global">;
+def err_cuda_ovl_target : Error<
+  "%select{__device__|__global__|__host__|__host__ __device__}0 function %1 "
+  "cannot overload %select{__device__|__global__|__host__|__host__ 
__device__}2 function %3">;
+def note_cuda_ovl_candidate_target_mismatch : Note<
+"candidate template ignored: target attributes do not match">;
 
 def warn_non_pod_vararg_with_format_string : Warning<
   "cannot pass %select{non-POD|non-trivial}0 object of type %1 to variadic "

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=288962&r1=288961&r2=288962&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Dec  7 13:27:16 2016
@@ -6568,7 +6568,9 @@ public:
 /// not be resolved to a suitable function.
 TDK_FailedOverloadResolution,
 /// \brief Deduction failed; that's all we know.
-TDK_MiscellaneousDeductionFailure
+TDK_MiscellaneousDeductionFailure,
+/// \brief CUDA Target attributes do not match.
+TDK_CUDATargetMismatch
   };
 
   TemplateDeductionResult
@@ -9419,6 +9421,7 @@ public:
   /// Use this rather than examining the function's attributes yourself -- you
   /// will get it wrong.  Returns CFT_Host if D is null.
   CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D);
+  CUDAFunctionTarget IdentifyCUDATarget(const AttributeList *Attr);
 
   /// Gets the CUDA target for the current context.
   CUDAFunctionTarget CurrentCUDATarget() {
@@ -9517,6 +9520,10 @@ public:
   bool isEmptyCudaConstructor(SourceLocation Loc, CXXConstructorDecl *CD);
   bool isEmptyCudaDestructor(SourceLocation Loc, CXXDestructorDecl *CD);
 
+  /// Check whether NewFD is a valid overload for CUDA. Emits
+  /// diagnostics and invalidates NewFD if not.
+  void checkCUDATargetOverload(FunctionDecl *NewFD, LookupResult &Previous);
+
   /// \name Code completion
   //@{
   /// \brief Describes the context in which code completion occurs.

Modified: cfe/trunk/lib/Sema/SemaCUDA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCUDA.cpp?rev=288962&r1=288961&r2=288962&view=diff
==
--- cfe/trunk/lib/Sema/SemaCUDA.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp Wed Dec  7 13:27:16 2016
@@ -54,6 +54,45 @@ ExprResult Sema::ActOnCUDAExecConfigExpr
/*IsExecConfig=*/true);
 }
 
+Sema::CUDAFunctionTarget Sema::IdentifyCUDATarget(const AttributeList *Attr) {
+  bool HasHostAttr = false;
+  bool HasDeviceAttr = false;
+  bool HasGlobalAttr = false;
+  bool HasInvalidTargetAttr = false;
+  while (Attr) {
+switch(Attr->getKind()){
+case AttributeList::AT_CUDAGlobal:
+  HasGlobalAttr = true;
+  break;
+case AttributeList::AT_CUDAHost:
+  HasHostAttr = true;
+  break;
+case AttributeList::AT_CUDADevice:
+  HasDeviceAttr = true;
+  break;
+case AttributeList::AT_CUDAInvalidTarget:
+  HasInvalidTargetAttr = true;
+  break;
+default:
+  break;
+}
+Attr = Attr->getNext();
+  }
+  if (HasInvalidTargetAttr)
+   

[PATCH] D27501: clang-format-vsix: add command to format document

2016-12-07 Thread Antonio Maiorano via Phabricator via cfe-commits
amaiorano added inline comments.



Comment at: tools/clang-format-vs/ClangFormat/ClangFormat.vsct:76
+
+  Clang Format Document
+

hans wrote:
> I think File would be better than Document when referring to source code.
> 
> But it seems a little annoying to need two menu alternatives. Could we make 
> the regular "Clang Format" option just format the whole file if there is 
> currently no selection, or would that be confusing?
The reason I chose "Document" is that it mimics the existing functionality in 
Visual Studio:
{F2661117}

As you can see, "Ctrl+K, Ctrl+F" is bound to format selection by default; which 
I assumed is the reason "Ctrl+R, Ctrl+F" was used for Clang Format (Selection). 
So along the same lines, I bound "Ctrl + R, Ctrl + D" to Clang Format Document.

I don't really have a problem with having multiple menu options, although we 
could have both of them underneath a "Clang Format" top menu, with "Format 
Selection" and "Format Document" as sub menu items.

As for annoyance in menus, I think most developers would reach for keyboard 
shortcuts in this case anyway. Furthermore, the next feature I want to add, 
building on top of this one, is allowing the user to enable "Format on Save", 
which would make this even easier to use.


https://reviews.llvm.org/D27501



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


[PATCH] D25809: [CUDA] Improved target attribute-based overloading.

2016-12-07 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288962: [CUDA] Improve target attribute checking for 
function templates. (authored by tra).

Changed prior to commit:
  https://reviews.llvm.org/D25809?vs=80522&id=80635#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25809

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaCUDA.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/lib/Sema/SemaTemplate.cpp
  cfe/trunk/test/CodeGenCUDA/launch-bounds.cu
  cfe/trunk/test/SemaCUDA/function-overload.cu
  cfe/trunk/test/SemaCUDA/function-template-overload.cu
  cfe/trunk/test/SemaCUDA/target_attr_inheritance.cu

Index: cfe/trunk/lib/Sema/SemaOverload.cpp
===
--- cfe/trunk/lib/Sema/SemaOverload.cpp
+++ cfe/trunk/lib/Sema/SemaOverload.cpp
@@ -580,6 +580,7 @@
   case Sema::TDK_TooManyArguments:
   case Sema::TDK_TooFewArguments:
   case Sema::TDK_MiscellaneousDeductionFailure:
+  case Sema::TDK_CUDATargetMismatch:
 Result.Data = nullptr;
 break;
 
@@ -647,6 +648,7 @@
   case Sema::TDK_TooFewArguments:
   case Sema::TDK_InvalidExplicitArguments:
   case Sema::TDK_FailedOverloadResolution:
+  case Sema::TDK_CUDATargetMismatch:
 break;
 
   case Sema::TDK_Inconsistent:
@@ -689,6 +691,7 @@
   case Sema::TDK_DeducedMismatch:
   case Sema::TDK_NonDeducedMismatch:
   case Sema::TDK_FailedOverloadResolution:
+  case Sema::TDK_CUDATargetMismatch:
 return TemplateParameter();
 
   case Sema::TDK_Incomplete:
@@ -720,6 +723,7 @@
   case Sema::TDK_Underqualified:
   case Sema::TDK_NonDeducedMismatch:
   case Sema::TDK_FailedOverloadResolution:
+  case Sema::TDK_CUDATargetMismatch:
 return nullptr;
 
   case Sema::TDK_DeducedMismatch:
@@ -747,6 +751,7 @@
   case Sema::TDK_InvalidExplicitArguments:
   case Sema::TDK_SubstitutionFailure:
   case Sema::TDK_FailedOverloadResolution:
+  case Sema::TDK_CUDATargetMismatch:
 return nullptr;
 
   case Sema::TDK_Inconsistent:
@@ -774,6 +779,7 @@
   case Sema::TDK_InvalidExplicitArguments:
   case Sema::TDK_SubstitutionFailure:
   case Sema::TDK_FailedOverloadResolution:
+  case Sema::TDK_CUDATargetMismatch:
 return nullptr;
 
   case Sema::TDK_Inconsistent:
@@ -1139,20 +1145,11 @@
 
 CUDAFunctionTarget NewTarget = IdentifyCUDATarget(New),
OldTarget = IdentifyCUDATarget(Old);
-if (NewTarget == CFT_InvalidTarget || NewTarget == CFT_Global)
+if (NewTarget == CFT_InvalidTarget)
   return false;
 
 assert((OldTarget != CFT_InvalidTarget) && "Unexpected invalid target.");
 
-// Don't allow HD and global functions to overload other functions with the
-// same signature.  We allow overloading based on CUDA attributes so that
-// functions can have different implementations on the host and device, but
-// HD/global functions "exist" in some sense on both the host and device, so
-// should have the same implementation on both sides.
-if ((NewTarget == CFT_HostDevice) || (OldTarget == CFT_HostDevice) ||
-(NewTarget == CFT_Global) || (OldTarget == CFT_Global))
-  return false;
-
 // Allow overloading of functions with same signature and different CUDA
 // target attributes.
 return NewTarget != OldTarget;
@@ -9713,6 +9710,10 @@
 S.Diag(Templated->getLocation(), diag::note_ovl_candidate_bad_deduction);
 MaybeEmitInheritedConstructorNote(S, Found);
 return;
+  case Sema::TDK_CUDATargetMismatch:
+S.Diag(Templated->getLocation(),
+   diag::note_cuda_ovl_candidate_target_mismatch);
+return;
   }
 }
 
@@ -9969,6 +9970,7 @@
   case Sema::TDK_DeducedMismatch:
   case Sema::TDK_NonDeducedMismatch:
   case Sema::TDK_MiscellaneousDeductionFailure:
+  case Sema::TDK_CUDATargetMismatch:
 return 3;
 
   case Sema::TDK_InstantiationDepth:
Index: cfe/trunk/lib/Sema/SemaTemplate.cpp
===
--- cfe/trunk/lib/Sema/SemaTemplate.cpp
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp
@@ -7043,6 +7043,19 @@
 continue;
   }
 
+  // Target attributes are part of function signature during cuda
+  // compilation, so deduced template must also have matching CUDA
+  // target. Given that regular template deduction does not take
+  // target attributes into account, we perform target match check
+  // here and reject candidates that have different target.
+  if (LangOpts.CUDA &&
+  IdentifyCUDATarget(Specialization) != IdentifyCUDATarget(FD)) {
+FailedCandidates.addCandidate().set(
+I.getPair(), FunTmpl->getTemplatedDecl(),
+MakeDeductionFailureInfo(Context, TDK_CUDATargetMismatch, Info));
+continue;
+  }
+
   // Record this candidate.
   if (ExplicitTemplateArgs)
 ConvertedTemplateArgs[Specialization] = std::mo

Re: r288923 - [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator

2016-12-07 Thread Richard Smith via cfe-commits
On 7 December 2016 at 10:11, Malcolm Parsons 
wrote:

> On 7 December 2016 at 17:56, Richard Smith  wrote:
> > On 7 Dec 2016 9:49 am, "Malcolm Parsons via cfe-commits"
> >  wrote:
> >
> > Author: malcolm.parsons
> > Date: Wed Dec  7 11:39:04 2016
> > New Revision: 288923
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=288923&view=rev
> > Log:
> > [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator
> >
> > Reviewers: aaron.ballman, klimek, doug.gregor, teemperor, rsmith
> >
> > Subscribers: cfe-commits
> >
> > Differential Revision: https://reviews.llvm.org/D26742
> >
> > @@ -87,7 +92,7 @@ TEST(RecursiveASTVisitor, PostOrderTrave
> >Visitor.TraverseTranslationUnitDecl(TU);
> >
> >std::vector expected = {
> > -"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo",
> "A::B",
> > "A"
> > +"4", "9", "i", "-",
>
> > Why does "i" not show up here twice? Do we not include DeclRefExprs in
> this
> > list? It looks like we're not testing the relative order of the unary
> > operator and its operand here.
>
> The test doesn't define VisitDeclRefExpr.
>
> I can add it if you like.


Perhaps a better approach would be to change the "-i" to "-5", so there's
no ambiguity as to what "i" means in the expected output.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26846: __uuidof() and declspec(uuid("...")) should be allowed on enumeration types

2016-12-07 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

This LGTM but Aaron should give the go ahead.


Repository:
  rL LLVM

https://reviews.llvm.org/D26846



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


[PATCH] D27529: Correct Vectorcall Register passing and HVA Behavior

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



Comment at: lib/CodeGen/TargetInfo.cpp:1688
+for (auto &I : FI.arguments()) {
+  if(Count < 6)
+I.info = reclassifyHvaArgType(I.type, State, I.info);

Formatting.



Comment at: lib/CodeGen/TargetInfo.cpp:3799-3804
+  } else if (IsReturnType)
+return ABIArgInfo::getExpand();
+  else if (!Ty->isBuiltinType() && !Ty->isVectorType())
+// HVAs are delayed and reclassified in the 2nd step.
+return ABIArgInfo::getIndirect(Align, /*ByVal=*/false);
 }

Please consistently brace here.



Comment at: lib/CodeGen/TargetInfo.cpp:3871
+for (auto &I : FI.arguments()) {
+  if (Count < 6)
+I.info = classify(I.type, FreeSSERegs, false, IsVectorCall, IsRegCall);

majnemer wrote:
> And here,
I was OK with `6` showing up in prior code because there was a comment but 
there isn't such a comment down here.  Maybe we should have this `6` live in an 
enum?



Comment at: lib/CodeGen/TargetInfo.cpp:3871-3879
+  if (Count < 6)
+I.info = classify(I.type, FreeSSERegs, false, IsVectorCall, IsRegCall);
+  else {
+// Since these cannot be passed in registers, pretend no registers
+// are left.
+unsigned ZeroSSERegsAvail= 0;
+I.info = classify(I.type, /*FreeSSERegs=*/ZeroSSERegsAvail, false,

And here,


https://reviews.llvm.org/D27529



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


[clang-tools-extra] r288969 - [change-namespace] always add a '::' prefix when a symbol reference needs to be fully-qualified.

2016-12-07 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Wed Dec  7 14:08:02 2016
New Revision: 288969

URL: http://llvm.org/viewvc/llvm-project?rev=288969&view=rev
Log:
[change-namespace] always add a '::' prefix when a symbol reference needs to be 
fully-qualified.

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
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=288969&r1=288968&r2=288969&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Wed Dec  7 
14:08:02 2016
@@ -663,6 +663,10 @@ void ChangeNamespaceTool::replaceQualifi
   // old namespace, we don't create replacement.
   if (NestedName == ReplaceName)
 return;
+  // If the reference need to be fully-qualified, add a leading "::" unless
+  // NewNamespace is the global namespace.
+  if (ReplaceName == FromDeclName && !NewNamespace.empty())
+ReplaceName = "::" + ReplaceName;
   auto R = createReplacement(Start, End, ReplaceName, *Result.SourceManager);
   auto Err = FileToReplacements[R.getFilePath()].add(R);
   if (Err)

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.h?rev=288969&r1=288968&r2=288969&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.h (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.h Wed Dec  7 
14:08:02 2016
@@ -24,6 +24,9 @@ namespace change_namespace {
 // namespaces while references to symbols (e.g. types, functions) which are not
 // defined in the changed namespace will be correctly qualified by prepending
 // namespace specifiers before them.
+// This will try to add shortest namespace specifiers possible. When a symbol
+// reference needs to be fully-qualified, this adds a "::" prefix to the
+// namespace specifiers unless the new namespace is the global namespace.
 // For classes, only classes that are declared/defined in the given namespace 
in
 // speficifed files will be moved: forward declarations will remain in the old
 // namespace.
@@ -38,7 +41,7 @@ namespace change_namespace {
 //   class FWD;
 //   }  // a
 //   namespace x {
-//   class A { a::FWD *fwd; }
+//   class A { ::a::FWD *fwd; }
 //   }  // x
 // FIXME: support moving typedef, enums across namespaces.
 class ChangeNamespaceTool : public ast_matchers::MatchFinder::MatchCallback {

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=288969&r1=288968&r2=288969&view=diff
==
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
Wed Dec  7 14:08:02 2016
@@ -174,6 +174,40 @@ TEST_F(ChangeNamespaceTest, MoveIntoAnot
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, MoveIntoExistingNamespaceAndShortenRefs) {
+  std::string Code = "namespace x {\n"
+ "namespace z {\n"
+ "class Z {};\n"
+ "} // namespace z\n"
+ "namespace y {\n"
+ "class T {};\n"
+ "} // namespace y\n"
+ "} // namespace x\n"
+ "namespace na {\n"
+ "class A{};\n"
+ "namespace nb {\n"
+ "class X { A a; x::z::Z zz; x::y::T t; };\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace x {\n"
+ "namespace z {\n"
+ "class Z {};\n"
+ "} // namespace z\n"
+ "namespace y {\n"
+ "class T {};\n"
+ "} // namespace y\n"
+ "} // namespace x\n"
+ "namespace na {\n"
+ "class A {};\n\n"
+ "} // namespace na\n"
+ "namespace x {\n"
+ "namespace y {\n"
+ "class X { ::na::A a; z::Z zz; T t; };\n"
+ "} // namespace y\n"
+ "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+

[PATCH] D27529: Correct Vectorcall Register passing and HVA Behavior

2016-12-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked an inline comment as done.
erichkeane added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:1688
+for (auto &I : FI.arguments()) {
+  if(Count < 6)
+I.info = reclassifyHvaArgType(I.type, State, I.info);

majnemer wrote:
> Formatting.
I don't see what you mean?  This area went through clang-format?  What did I 
miss?



Comment at: lib/CodeGen/TargetInfo.cpp:3871
+for (auto &I : FI.arguments()) {
+  if (Count < 6)
+I.info = classify(I.type, FreeSSERegs, false, IsVectorCall, IsRegCall);

majnemer wrote:
> majnemer wrote:
> > And here,
> I was OK with `6` showing up in prior code because there was a comment but 
> there isn't such a comment down here.  Maybe we should have this `6` live in 
> an enum?
Thats a good point.  Any reason it couldn't just be a static constant in each 
of the ABIInfos?  Or am I missing your point?


https://reviews.llvm.org/D27529



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


[PATCH] D27529: Correct Vectorcall Register passing and HVA Behavior

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



Comment at: lib/CodeGen/TargetInfo.cpp:1688
+for (auto &I : FI.arguments()) {
+  if(Count < 6)
+I.info = reclassifyHvaArgType(I.type, State, I.info);

erichkeane wrote:
> majnemer wrote:
> > Formatting.
> I don't see what you mean?  This area went through clang-format?  What did I 
> miss?
Your code has "if(Count < 6)", I'm incredibly surprised that clang-format would 
format your code like this. There should be a space after the if and before the 
left-parenthesis.


https://reviews.llvm.org/D27529



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


r288976 - [RecursiveASTVisitor] Improve post-order traversal unit test

2016-12-07 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Dec  7 14:38:20 2016
New Revision: 288976

URL: http://llvm.org/viewvc/llvm-project?rev=288976&view=rev
Log:
[RecursiveASTVisitor] Improve post-order traversal unit test

Modified:
cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp

Modified: cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp?rev=288976&r1=288975&r2=288976&view=diff
==
--- cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp (original)
+++ cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp Wed Dec  7 14:38:20 2016
@@ -81,7 +81,7 @@ TEST(RecursiveASTVisitor, PostOrderTrave
   auto ASTUnit = tooling::buildASTFromCode(
 "class A {"
 "  class B {"
-"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }"
+"int foo() { while(4) { int i = 9; int j = -5; } return (1 + 3) + 2; }"
 "  };"
 "};"
   );
@@ -91,9 +91,9 @@ TEST(RecursiveASTVisitor, PostOrderTrave
   RecordingVisitor Visitor(true);
   Visitor.TraverseTranslationUnitDecl(TU);
 
-  std::vector expected = {
-"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", 
"A::B", "A"
-  };
+  std::vector expected = {"4", "9",  "i", "5","-",
+   "j", "1",  "3", "+","2",
+   "+", "return", "A::B::foo", "A::B", 
"A"};
   // Compare the list of actually visited nodes
   // with the expected list of visited nodes.
   ASSERT_EQ(expected.size(), Visitor.VisitedNodes.size());


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


[PATCH] D27529: Correct Vectorcall Register passing and HVA Behavior

2016-12-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:1688
+for (auto &I : FI.arguments()) {
+  if(Count < 6)
+I.info = reclassifyHvaArgType(I.type, State, I.info);

majnemer wrote:
> erichkeane wrote:
> > majnemer wrote:
> > > Formatting.
> > I don't see what you mean?  This area went through clang-format?  What did 
> > I miss?
> Your code has "if(Count < 6)", I'm incredibly surprised that clang-format 
> would format your code like this. There should be a space after the if and 
> before the left-parenthesis.
Ah, thanks!  I do go through my patches and 'ctrl-K' for clang-format, so I 
don't know if I missed this section or what, but I've fixed it as a part of the 
other fixes here, and the re-clang-formatting took care of it.  Thanks for the 
clarification!


https://reviews.llvm.org/D27529



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


[PATCH] D27529: Correct Vectorcall Register passing and HVA Behavior

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



Comment at: lib/CodeGen/TargetInfo.cpp:3871
+for (auto &I : FI.arguments()) {
+  if (Count < 6)
+I.info = classify(I.type, FreeSSERegs, false, IsVectorCall, IsRegCall);

erichkeane wrote:
> majnemer wrote:
> > majnemer wrote:
> > > And here,
> > I was OK with `6` showing up in prior code because there was a comment but 
> > there isn't such a comment down here.  Maybe we should have this `6` live 
> > in an enum?
> Thats a good point.  Any reason it couldn't just be a static constant in each 
> of the ABIInfos?  Or am I missing your point?
It could be but LLVM usually prefers enums over class-scope static variables.  
They require an awkward definition somewhere should they be ODR used.


https://reviews.llvm.org/D27529



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


[PATCH] D27529: Correct Vectorcall Register passing and HVA Behavior

2016-12-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:3871
+for (auto &I : FI.arguments()) {
+  if (Count < 6)
+I.info = classify(I.type, FreeSSERegs, false, IsVectorCall, IsRegCall);

majnemer wrote:
> erichkeane wrote:
> > majnemer wrote:
> > > majnemer wrote:
> > > > And here,
> > > I was OK with `6` showing up in prior code because there was a comment 
> > > but there isn't such a comment down here.  Maybe we should have this `6` 
> > > live in an enum?
> > Thats a good point.  Any reason it couldn't just be a static constant in 
> > each of the ABIInfos?  Or am I missing your point?
> It could be but LLVM usually prefers enums over class-scope static variables. 
>  They require an awkward definition somewhere should they be ODR used.
I think some of us who have spent time implementing the C++ ABI rules around 
static const int data members feel that you should use an enumerator in an 
unnamed enum instead because the ABI rules are easier to follow. With static 
data members, you sometimes have to worry about providing a definition like so:
  struct A { static const int kThing = 42; }; // in a .h
  const int A::kThing; // in some .cc file, needed "sometimes"
Simpler:
  struct A { enum : int { kThing = 42 }; };


https://reviews.llvm.org/D27529



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


[PATCH] D27529: Correct Vectorcall Register passing and HVA Behavior

2016-12-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 80641.
erichkeane added a comment.

Fixing issues brought up by David.


https://reviews.llvm.org/D27529

Files:
  include/clang/CodeGen/CGFunctionInfo.h
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/vectorcall.c
  test/CodeGenCXX/homogeneous-aggregates.cpp

Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -870,6 +870,11 @@
   unsigned FreeSSERegs;
 };
 
+enum {
+  // Vectorcall only allows the first 6 parameters to be passed in registers.
+  VectorcallMaxParamNumAsReg = 6
+};
+
 /// X86_32ABIInfo - The X86-32 ABI information.
 class X86_32ABIInfo : public SwiftABIInfo {
   enum Class {
@@ -915,6 +920,8 @@
   Class classify(QualType Ty) const;
   ABIArgInfo classifyReturnType(QualType RetTy, CCState &State) const;
   ABIArgInfo classifyArgumentType(QualType RetTy, CCState &State) const;
+  ABIArgInfo reclassifyHvaArgType(QualType RetTy, CCState &State, 
+  const ABIArgInfo& current) const;
   /// \brief Updates the number of available free registers, returns 
   /// true if any registers were allocated.
   bool updateFreeRegs(QualType Ty, CCState &State) const;
@@ -1480,6 +1487,27 @@
   return true;
 }
 
+ABIArgInfo
+X86_32ABIInfo::reclassifyHvaArgType(QualType Ty, CCState &State,
+const ABIArgInfo ¤t) const {
+  // Assumes vectorCall calling convention.
+  const Type *Base = nullptr;
+  uint64_t NumElts = 0;
+
+  if (!Ty->isBuiltinType() && !Ty->isVectorType() &&
+  isHomogeneousAggregate(Ty, Base, NumElts)) {
+if (State.FreeSSERegs >= NumElts) {
+  // HVA types get passed directly in registers if there is room.
+  State.FreeSSERegs -= NumElts;
+  return ABIArgInfo::getDirectHva();
+}
+// If there's no room, the HVA gets passed as normal indirect
+// structure.
+return getIndirectResult(Ty, /*ByVal=*/false, State);
+  } 
+  return current;
+}
+
 ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
CCState &State) const {
   // FIXME: Set alignment on indirect arguments.
@@ -1499,19 +1527,34 @@
   }
 
   // vectorcall adds the concept of a homogenous vector aggregate, similar
-  // to other targets.
-  const Type *Base = nullptr;
-  uint64_t NumElts = 0;
-  if ((State.CC == llvm::CallingConv::X86_VectorCall ||
-   State.CC == llvm::CallingConv::X86_RegCall) &&
-  isHomogeneousAggregate(Ty, Base, NumElts)) {
-if (State.FreeSSERegs >= NumElts) {
-  State.FreeSSERegs -= NumElts;
-  if (Ty->isBuiltinType() || Ty->isVectorType())
+  // to other targets, regcall uses some of the HVA rules.
+  if (State.CC == llvm::CallingConv::X86_VectorCall ||
+  State.CC == llvm::CallingConv::X86_RegCall) {
+const Type *Base = nullptr;
+uint64_t NumElts = 0;
+bool IsHva = isHomogeneousAggregate(Ty, Base, NumElts);
+
+if (State.CC == llvm::CallingConv::X86_RegCall && IsHva) {
+  if (State.FreeSSERegs >= NumElts) {
+State.FreeSSERegs -= NumElts;
+if (Ty->isBuiltinType() || Ty->isVectorType())
+  return ABIArgInfo::getDirect();
+return ABIArgInfo::getExpand();
+
+  }
+  return getIndirectResult(Ty, /*ByVal=*/false, State);
+} else if (State.CC == llvm::CallingConv::X86_VectorCall && IsHva) {
+  if (State.FreeSSERegs >= NumElts && (Ty->isBuiltinType() || Ty->isVectorType())) {
+// Actual floating-point types get registers first time through if
+// there is registers available
+State.FreeSSERegs -= NumElts;
 return ABIArgInfo::getDirect();
-  return ABIArgInfo::getExpand();
+  }  else if (!Ty->isBuiltinType() && !Ty->isVectorType()) {
+// HVA Types only get registers after everything else has been
+// set, so it gets set as indirect for now.
+return ABIArgInfo::getIndirect(getContext().getTypeAlignInChars(Ty));
+  }
 }
-return getIndirectResult(Ty, /*ByVal=*/false, State);
   }
 
   if (isAggregateTypeForABI(Ty)) {
@@ -1624,9 +1667,40 @@
 ++State.FreeRegs;
 
   bool UsedInAlloca = false;
-  for (auto &I : FI.arguments()) {
-I.info = classifyArgumentType(I.type, State);
-UsedInAlloca |= (I.info.getKind() == ABIArgInfo::InAlloca);
+  if (State.CC == llvm::CallingConv::X86_VectorCall) {
+// Vectorcall only allows the first 6 parameters to be passed in registers,
+// and homogeneous vector aggregates are only put into registers as a second
+// priority.
+unsigned Count = 0;
+CCState ZeroState = State;
+ZeroState.FreeRegs = ZeroState.FreeSSERegs = 0;
+// HVAs must be done as a second priority for registers, so the deferred
+// items
+// are dealt with by going through the pattern a second time.
+for (auto &I : FI.arguments()) {
+  if (Count < VectorcallMaxParamNumAsReg)
+I.info = classifyArgumentTyp

[PATCH] D27529: Correct Vectorcall Register passing and HVA Behavior

2016-12-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 9 inline comments as done.
erichkeane added inline comments.



Comment at: lib/CodeGen/TargetInfo.cpp:3871
+for (auto &I : FI.arguments()) {
+  if (Count < 6)
+I.info = classify(I.type, FreeSSERegs, false, IsVectorCall, IsRegCall);

rnk wrote:
> majnemer wrote:
> > erichkeane wrote:
> > > majnemer wrote:
> > > > majnemer wrote:
> > > > > And here,
> > > > I was OK with `6` showing up in prior code because there was a comment 
> > > > but there isn't such a comment down here.  Maybe we should have this 
> > > > `6` live in an enum?
> > > Thats a good point.  Any reason it couldn't just be a static constant in 
> > > each of the ABIInfos?  Or am I missing your point?
> > It could be but LLVM usually prefers enums over class-scope static 
> > variables.  They require an awkward definition somewhere should they be ODR 
> > used.
> I think some of us who have spent time implementing the C++ ABI rules around 
> static const int data members feel that you should use an enumerator in an 
> unnamed enum instead because the ABI rules are easier to follow. With static 
> data members, you sometimes have to worry about providing a definition like 
> so:
>   struct A { static const int kThing = 42; }; // in a .h
>   const int A::kThing; // in some .cc file, needed "sometimes"
> Simpler:
>   struct A { enum : int { kThing = 42 }; };
Fair enough, thanks for the education guys!


https://reviews.llvm.org/D27529



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


[PATCH] D27520: [clang-tidy] Add check for redundant function pointer dereferences

2016-12-07 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 80642.
malcolm.parsons added a comment.

Add to release notes.
Remove youtube link.


https://reviews.llvm.org/D27520

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.cpp
  clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-redundant-function-ptr-dereference.rst
  test/clang-tidy/readability-redundant-function-ptr-dereference.cpp

Index: test/clang-tidy/readability-redundant-function-ptr-dereference.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-redundant-function-ptr-dereference.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-redundant-function-ptr-dereference %t
+
+void f(int i);
+
+void positive() {
+  void (*p)(int) = f;
+
+  (**p)(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated dereference of function pointer [readability-redundant-function-ptr-dereference]
+  // CHECK-FIXES: (*p)(1);
+  (*p)(2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated
+  // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: redundant repeated
+  // CHECK-MESSAGES: :[[@LINE-3]]:6: warning: redundant repeated
+  // CHECK-MESSAGES: :[[@LINE-4]]:7: warning: redundant repeated
+  // CHECK-FIXES: (*p)(2);
+}
+
+void negative() {
+  void (*q)(int) = &f;
+
+  q(1);
+  (*q)(2);
+}
Index: docs/clang-tidy/checks/readability-redundant-function-ptr-dereference.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-redundant-function-ptr-dereference.rst
@@ -0,0 +1,25 @@
+.. title:: clang-tidy - readability-redundant-function-ptr-dereference
+
+readability-redundant-function-ptr-dereference
+==
+
+Finds redundant dereferences of a function pointer.
+
+Before:
+
+.. code-block:: c++
+
+  int f(int,int);
+  int (*p)(int, int) = &f;
+
+  int i = (**p)(10, 50);
+
+After:
+
+.. code-block:: c++
+
+  int f(int,int);
+  int (*p)(int, int) = &f;
+
+  int i = (*p)(10, 50);
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -138,6 +138,7 @@
readability-non-const-parameter
readability-redundant-control-flow
readability-redundant-declaration
+   readability-redundant-function-ptr-dereference
readability-redundant-member-init
readability-redundant-smartptr-get
readability-redundant-string-cstr
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -141,6 +141,11 @@
 
   Finds redundant variable and function declarations.
 
+- New `readability-redundant-function-ptr-dereference
+  `_ check
+
+  Finds redundant function pointer dereferences.
+
 - New `readability-redundant-member-init
   `_ check
 
Index: clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h
===
--- /dev/null
+++ clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.h
@@ -0,0 +1,35 @@
+//===--- RedundantFunctionPtrDereferenceCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_FUNCTION_PTR_DEREFERENCE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_FUNCTION_PTR_DEREFERENCE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Eliminate redundant dereferences of a function pointer.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-redundant-function-ptr-dereference.html
+class RedundantFunctionPtrDereferenceCheck : public ClangTidyCheck {
+public:
+  RedundantFunctionPtrDereferenceCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_FUNCTION_PTR_DEREFERENCE_H
Index: clang-tidy/readability/RedundantFunctionPtrDereferenceCheck.c

[PATCH] D27039: [CodeCompletion] Autocomplete NS_DESIGNATED_INITIALIZER in initializers with arguments

2016-12-07 Thread Manman Ren via Phabricator via cfe-commits
manmanren accepted this revision.
manmanren added a comment.
This revision is now accepted and ready to land.

LGTM

Manman


Repository:
  rL LLVM

https://reviews.llvm.org/D27039



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


[PATCH] D27535: [analyzer] Add ObjCPropertyChecker - check for autosynthesized copy-properties of mutable types.

2016-12-07 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: zaks.anna, dcoughlin.
NoQ added a subscriber: cfe-commits.
Herald added a subscriber: mgorny.

When an ObjC property is declared as `(copy)`, and the type of the property is 
mutable (eg. `NSMutableSomething`), the autosynthesized code for the setter, 
which as usual copies the object by calling `-copy`, produces an immutable 
object (eg. `NSSomething`; cf. `-mutableCopy` which would actually produce 
`NSMutableSomething`), which would lead to unexpected results.

The checker is named to be a bit more generic, even though i have no particular 
plans for other checks at the moment.

Testing in progress.


https://reviews.llvm.org/D27535

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp
  test/Analysis/ObjCPropertiesSyntaxChecks.m

Index: test/Analysis/ObjCPropertiesSyntaxChecks.m
===
--- /dev/null
+++ test/Analysis/ObjCPropertiesSyntaxChecks.m
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -w -fblocks -analyze -analyzer-checker=osx.ObjCProperty %s -verify
+
+#include "Inputs/system-header-simulator-objc.h"
+
+@interface I : NSObject {
+  NSMutableString *_mutableExplicitStr;
+  NSMutableString *_trulyMutableStr;
+  NSMutableString *_trulyMutableExplicitStr;
+}
+@property(copy) NSString *str; // no-warning
+@property(copy) NSMutableString *mutableStr; // expected-warning{{Property of mutable type has copy attribute; an immutable object will be returned instead}}
+@property(copy) NSMutableString *mutableExplicitStr; // expected-warning{{Property of mutable type has copy attribute; an immutable object will be returned instead}}
+@property(copy) NSMutableString *trulyMutableStr; // no-warning
+@property(copy) NSMutableString *trulyMutableExplicitStr; // no-warning
+@end
+
+@implementation I
+@synthesize mutableExplicitStr = _mutableExplicitStr;
+- (NSMutableString *)trulyMutableStr {
+  return _trulyMutableStr;
+}
+- (void)setTrulyMutableStr: (NSMutableString *) S {
+  _trulyMutableStr = [S mutableCopy];
+}
+@dynamic trulyMutableExplicitStr;
+- (NSMutableString *)trulyMutableExplicitStr {
+  return _trulyMutableExplicitStr;
+}
+- (void)setTrulyMutableExplicitStr: (NSMutableString *) S {
+  _trulyMutableExplicitStr = [S mutableCopy];
+}
+@end
+
+void Foo(I *i) {
+  i.trulyMutableStr = @"hello world";
+}
Index: lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp
===
--- /dev/null
+++ lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp
@@ -0,0 +1,79 @@
+//==- ObjCPropertyChecker.cpp - Check ObjC properties *- C++ -*-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This checker finds issues with Objective-C properties.
+//  Currently finds only one kind of issue:
+//  - Find autosynthesized properties with copy attribute of
+//mutable NS collection types. Calling -copy on such collections
+//produces an immutable copy, which contradicts the type of
+//the property.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class ObjCPropertyChecker
+: public Checker> {
+public:
+  void checkASTDecl(const ObjCPropertyDecl *D, AnalysisManager &Mgr,
+BugReporter &BR) const;
+};
+} // end anonymous namespace.
+
+void ObjCPropertyChecker::checkASTDecl(const ObjCPropertyDecl *D,
+   AnalysisManager &Mgr,
+   BugReporter &BR) const {
+  if (D->getSetterKind() != ObjCPropertyDecl::Copy)
+return;
+
+  QualType T = D->getType();
+  if (!T->isObjCObjectPointerType())
+return;
+
+  StringRef PropTypeName(T->getPointeeType()
+ .getCanonicalType()
+ .getUnqualifiedType()
+ .getAsString());
+  if (!PropTypeName.startswith("NSMutable"))
+return;
+
+  const ObjCInterfaceDecl *IntD =
+  dyn_cast(D->getDeclContext());
+  if (!IntD)
+return;
+
+  const ObjCImplDecl *IntImplD = IntD->getImplementation();
+  if (!IntImplD)
+return;
+
+  ObjCPropertyImplDecl *ImplD = IntImplD->FindPropertyImplDecl(
+  D->getIdentifier(), D->isClassProperty()
+  ? ObjCPropertyQueryKind::OBJC_PR_query_class
+  : ObjCPropertyQueryKind::OBJC_PR_query_instance);
+  if (!ImplD ||
+  ImplD->getPropertyImplementation() == ObjCPropertyImplDecl::Dyn

[PATCH] D27501: clang-format-vsix: add command to format document

2016-12-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: tools/clang-format-vs/ClangFormat/ClangFormat.vsct:76
+
+  Clang Format Document
+

amaiorano wrote:
> hans wrote:
> > I think File would be better than Document when referring to source code.
> > 
> > But it seems a little annoying to need two menu alternatives. Could we make 
> > the regular "Clang Format" option just format the whole file if there is 
> > currently no selection, or would that be confusing?
> The reason I chose "Document" is that it mimics the existing functionality in 
> Visual Studio:
> {F2661117}
> 
> As you can see, "Ctrl+K, Ctrl+F" is bound to format selection by default; 
> which I assumed is the reason "Ctrl+R, Ctrl+F" was used for Clang Format 
> (Selection). So along the same lines, I bound "Ctrl + R, Ctrl + D" to Clang 
> Format Document.
> 
> I don't really have a problem with having multiple menu options, although we 
> could have both of them underneath a "Clang Format" top menu, with "Format 
> Selection" and "Format Document" as sub menu items.
> 
> As for annoyance in menus, I think most developers would reach for keyboard 
> shortcuts in this case anyway. Furthermore, the next feature I want to add, 
> building on top of this one, is allowing the user to enable "Format on Save", 
> which would make this even easier to use.
I see, I didn't realize they call it documents. And if they also have separate 
commands for formating selection and formating the whole file, maybe that makes 
sense for us too.

Right, I also imagine folks would use this from the keyboard, but there too 
it's annoying to have two shortcuts for the same thing. But again, if that's 
how it's generally done in VS...

I'd like to hear from Manuel on this patch too, though.


https://reviews.llvm.org/D27501



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


[PATCH] D27279: Store decls in prototypes on the declarator instead of in the AST

2016-12-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 80650.
rnk added a comment.

- Remove an assert and test that edge case


https://reviews.llvm.org/D27279

Files:
  include/clang/AST/Decl.h
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/Decl.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/Misc/ast-dump-decl.c
  test/PCH/decl-in-prototype.c
  test/Sema/decl-in-prototype.c
  test/SemaCXX/type-definition-in-specifier.cpp

Index: test/SemaCXX/type-definition-in-specifier.cpp
===
--- test/SemaCXX/type-definition-in-specifier.cpp
+++ test/SemaCXX/type-definition-in-specifier.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -verify %s
 
 struct S0;
 struct S1;
@@ -64,3 +64,6 @@
   short bar5 (struct foo4 {} bar2); // expected-error{{'foo4' cannot be defined in a parameter type}}
   long foo5 (float foo6 = foo4);  // expected-error{{use of undeclared identifier 'foo4'}}
 };
+
+void func_with_eh_and_type(struct type_in_eh {} o) throw(int) {} // expected-error{{cannot be defined in a parameter type}}
+struct type_in_eh {}; // no diagnostics
Index: test/Sema/decl-in-prototype.c
===
--- test/Sema/decl-in-prototype.c
+++ test/Sema/decl-in-prototype.c
@@ -1,13 +1,19 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+#define SA(n, c) int arr##n[(c) ? 1 : -1] = {}
+
 const int AA = 5;
 
 int f1(enum {AA,BB} E) { // expected-warning {{will not be visible outside of this function}}
-return BB;
+  SA(1, AA == 0);
+  SA(2, BB == 1);
+  return BB;
 }
 
 int f2(enum {AA=7,BB} E) { // expected-warning {{will not be visible outside of this function}}
-return AA;
+  SA(1, AA == 7);
+  SA(2, BB == 8);
+  return AA;
 }
 
 struct a {
@@ -38,3 +44,11 @@
 
 // Only warn once, even if we create two declarations.
 void f(struct q *, struct __attribute__((aligned(4))) q *); // expected-warning {{will not be visible outside}}
+
+// This enum inside the function pointer parameter shouldn't leak into the
+// function.
+enum { BB = 0 };
+void enum_in_fun_in_fun(void (*fp)(enum { AA, BB } e)) { // expected-warning {{will not be visible}}
+  SA(1, AA == 5);
+  SA(2, BB == 0);
+}
Index: test/PCH/decl-in-prototype.c
===
--- /dev/null
+++ test/PCH/decl-in-prototype.c
@@ -0,0 +1,27 @@
+// Test that we serialize the enum decl in the function prototype somehow.
+// These decls aren't serialized quite the same way as parameters.
+
+// Test this without pch.
+// RUN: %clang_cc1 -include %s -emit-llvm -o - %s | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: define i32 @main()
+// CHECK:   ret i32 1
+
+#ifndef HEADER
+#define HEADER
+
+static inline __attribute__((always_inline)) f(enum { x, y } p) {
+  return y;
+}
+
+#else
+
+int main() {
+  return f(0);
+}
+
+#endif
Index: test/Misc/ast-dump-decl.c
===
--- test/Misc/ast-dump-decl.c
+++ test/Misc/ast-dump-decl.c
@@ -106,8 +106,6 @@
   return x;
 }
 // CHECK:  FunctionDecl{{.*}} TestFunctionDecl 'int (int, enum {{.*}})'
-// CHECK-NEXT:   EnumDecl
-// CHECK-NEXT: EnumConstantDecl{{.*}} e
 // CHECK-NEXT:   ParmVarDecl{{.*}} x
 // CHECK-NEXT:   ParmVarDecl{{.*}} y
 // CHECK-NEXT:   CompoundStmt
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -718,6 +718,7 @@
   /*NumExceptions=*/0,
   /*NoexceptExpr=*/nullptr,
   /*ExceptionSpecTokens=*/nullptr,
+  /*DeclsInPrototype=*/None,
   loc, loc, declarator));
 
   // For consistency, make sure the state still has us as processing
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8222,8 +8222,9 @@
   // Copy the parameter declarations from the declarator D to the function
   // declaration NewFD, if they are available.  First scavenge them into Params.
   SmallVector Params;
-  if (D.isFunctionDeclarator()) {
-DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();
+  unsigned FTIIdx;
+  if (D.isFunctionDeclarator(FTIIdx)) {
+DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(FTIIdx).Fun;
 
 // Check for C99 6.7.5.3p10 - foo(void) is a non-varargs
 // function that takes no arguments, not a function that takes a
@@ -8241,6 +8242,18 @@
   NewFD->setInvalidDecl();
   }
 }
+
+// Find all the non-parameter declarations from the prototype and move them
+// into the new function decl context as well. Typ

[PATCH] D27434: [libc++abi] Disable failing test on Darwin

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

If this caused by a bug it should be marked `XFAIL` and have a comment 
explaining why it fails and links to the relevant PR's.

Feel free to commit after making those changes.


https://reviews.llvm.org/D27434



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


[PATCH] D27538: [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 1/7.

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

[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible 
loss of data", part 1/7.

Given `std::basic_streambuf::int_type __c`, `std::basic_string 
str_`,
and having checked `__c != std::basic_streambuf::traits_type::eof()` 
(substituting typedefs
for clarity), the line `str_.push_back(__c);` is safe according to humans, but 
truncates according
to compilers. `str_.push_back(static_cast(__c));` avoids that problem.


https://reviews.llvm.org/D27538

Files:
  test/std/input.output/iostream.format/ext.manip/put_time.pass.cpp
  
test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp
  
test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/bool.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/double.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/float.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/int.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_double.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_long.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/short.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_int.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long_long.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_short.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/basic_ios.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ios_base.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ostream.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.manip/endl.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.manip/ends.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.rvalue/CharT_pointer.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.unformatted/put.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp

Index: test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp
===
--- test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp
+++ test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp
@@ -39,7 +39,7 @@
 if (__c != base::traits_type::eof())
 {
 int n = static_cast(str_.size());
-str_.push_back(__c);
+str_.push_back(static_cast(__c));
 str_.resize(str_.capacity());
 base::setp(const_cast(str_.data()),
const_cast(str_.data() + str_.size()));
Index: test/std/input.output/iostream.format/output.streams/ostream.unformatted/put.pass.cpp
===
--- test/st

[PATCH] D27539: [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 2/7.

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

[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible 
loss of data", part 2/7.

These tests for some guy's transparent operator functors were needlessly 
truncating their
double results to int. Preserving the doubleness makes compilers happier. I'm 
following
existing practice by adding an "// exact in binary" comment when the result 
isn't a whole number.
(The changes from 6 to 6.0 and so forth are stylistic, not critical.)


https://reviews.llvm.org/D27539

Files:
  test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
  test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
  test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
  test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
  test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp


Index: test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
===
--- test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
@@ -35,7 +35,7 @@
 constexpr int foo = std::plus () (3, 2);
 static_assert ( foo == 5, "" );
 
-constexpr int bar = std::plus<> () (3.0, 2);
-static_assert ( bar == 5, "" );
+constexpr double bar = std::plus<> () (3.0, 2);
+static_assert ( bar == 5.0, "" );
 #endif
 }
Index: test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
===
--- test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
@@ -34,7 +34,7 @@
 constexpr int foo = std::negate () (3);
 static_assert ( foo == -3, "" );
 
-constexpr int bar = std::negate<> () (3.0);
-static_assert ( bar == -3, "" );
+constexpr double bar = std::negate<> () (3.0);
+static_assert ( bar == -3.0, "" );
 #endif
 }
Index: 
test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
===
--- 
test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
+++ 
test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
@@ -35,7 +35,7 @@
 constexpr int foo = std::multiplies () (3, 2);
 static_assert ( foo == 6, "" );
 
-constexpr int bar = std::multiplies<> () (3.0, 2);
-static_assert ( bar == 6, "" );
+constexpr double bar = std::multiplies<> () (3.0, 2);
+static_assert ( bar == 6.0, "" );
 #endif
 }
Index: test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
===
--- test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
@@ -35,7 +35,7 @@
 constexpr int foo = std::minus () (3, 2);
 static_assert ( foo == 1, "" );
 
-constexpr int bar = std::minus<> () (3.0, 2);
-static_assert ( bar == 1, "" );
+constexpr double bar = std::minus<> () (3.0, 2);
+static_assert ( bar == 1.0, "" );
 #endif
 }
Index: 
test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
===
--- test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
@@ -35,7 +35,7 @@
 constexpr int foo = std::divides () (3, 2);
 static_assert ( foo == 1, "" );
 
-constexpr int bar = std::divides<> () (3.0, 2);
-static_assert ( bar == 1, "" );
+constexpr double bar = std::divides<> () (3.0, 2);
+static_assert ( bar == 1.5, "" ); // exact in binary
 #endif
 }


Index: test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
===
--- test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
@@ -35,7 +35,7 @@
 constexpr int foo = std::plus () (3, 2);
 static_assert ( foo == 5, "" );
 
-constexpr int bar = std::plus<> () (3.0, 2);
-static_assert ( bar == 5, "" );
+constexpr double bar = std::plus<> () (3.0, 2);
+static_assert ( bar == 5.0, "" );
 #endif
 }
Index: test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
===
--- test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
@@ -34,7 +34,7 @@
 constexpr int foo = std::ne

[PATCH] D27540: [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 3/7.

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

[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible 
loss of data", part 3/7.

Add static_cast when constructing pair from (Something, 
int).


https://reviews.llvm.org/D27540

Files:
  
test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_rvalue.pass.cpp
  test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue.pass.cpp
  
test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_rvalue.pass.cpp
  
test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_rvalue.pass.cpp
  test/std/utilities/utility/pairs/pair.astuple/get_const.pass.cpp
  test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp
  test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
  test/std/utilities/utility/pairs/pair.astuple/get_rv.pass.cpp
  test/std/utilities/utility/pairs/pairs.pair/assign_const_pair_U_V.pass.cpp
  test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair_U_V.pass.cpp
  test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V_cxx03.pass.cpp
  test/std/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp
  test/std/utilities/utility/pairs/pairs.pair/move_ctor.pass.cpp
  test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp
  test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp
  test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp

Index: test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp
@@ -20,8 +20,8 @@
 {
 {
 typedef std::pair P1;
-P1 p1(3, 4);
-P1 p2(5, 6);
+P1 p1(3, static_cast(4));
+P1 p2(5, static_cast(6));
 swap(p1, p2);
 assert(p1.first == 5);
 assert(p1.second == 6);
Index: test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp
@@ -27,8 +27,8 @@
 {
 {
 typedef std::pair P;
-P p1(3, 4);
-P p2(3, 4);
+P p1(3, static_cast(4));
+P p2(3, static_cast(4));
 assert( (p1 == p2));
 assert(!(p1 != p2));
 assert(!(p1 <  p2));
@@ -38,8 +38,8 @@
 }
 {
 typedef std::pair P;
-P p1(2, 4);
-P p2(3, 4);
+P p1(2, static_cast(4));
+P p2(3, static_cast(4));
 assert(!(p1 == p2));
 assert( (p1 != p2));
 assert( (p1 <  p2));
@@ -49,8 +49,8 @@
 }
 {
 typedef std::pair P;
-P p1(3, 2);
-P p2(3, 4);
+P p1(3, static_cast(2));
+P p2(3, static_cast(4));
 assert(!(p1 == p2));
 assert( (p1 != p2));
 assert( (p1 <  p2));
@@ -60,8 +60,8 @@
 }
 {
 typedef std::pair P;
-P p1(3, 4);
-P p2(2, 4);
+P p1(3, static_cast(4));
+P p2(2, static_cast(4));
 assert(!(p1 == p2));
 assert( (p1 != p2));
 assert(!(p1 <  p2));
@@ -71,8 +71,8 @@
 }
 {
 typedef std::pair P;
-P p1(3, 4);
-P p2(3, 2);
+P p1(3, static_cast(4));
+P p2(3, static_cast(2));
 assert(!(p1 == p2));
 assert( (p1 != p2));
 assert(!(p1 <  p2));
@@ -84,8 +84,8 @@
 #if TEST_STD_VER > 11
 {
 typedef std::pair P;
-constexpr P p1(3, 4);
-constexpr P p2(3, 2);
+constexpr P p1(3, static_cast(4));
+constexpr P p2(3, static_cast(2));
 static_assert(!(p1 == p2), "");
 static_assert( (p1 != p2), "");
 static_assert(!(p1 <  p2), "");
Index: test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp
@@ -29,8 +29,8 @@
 {
 {
 typedef std::pair P1;
-P1 p1(3, 4);
-P1 p2(5, 6);
+P1 p1(3, static_cast(4));
+P1 p2(5, static_cast(6));
 p1.swap(p2);
 assert(p1.first == 5);
 assert(p1.second == 6);
Index: test/std/utilities/utility/pairs/pairs.pair/move_ctor.pass.cpp
===
--- test/std/utilities/utility/pairs/pairs.pair/move_ctor.pass.cpp
+++ test/std/utilities/utility/pairs/pairs.pair/move_ctor.pass.cpp
@@ -31,7 +31,7 @@
 {
 typedef std::pair P1;
 static_assert(std::is_move_constructible::value, "");
-P1 p1(3, 4);
+P1 p1(3, static_cast(4));
 P1 p2 = std::move(p1);

[PATCH] D27541: [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 4/7.

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

[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible 
loss of data", part 4/7.

Change char to long and remove some char casts. This preserves test coverage 
for tuple's
heterogeneous comparisons, while avoiding int-to-char truncation warnings.


https://reviews.llvm.org/D27541

Files:
  test/std/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp

Index: test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp
===
--- test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp
@@ -48,7 +48,7 @@
 assert( (t1 >= t2));
 }
 {
-typedef std::tuple T1;
+typedef std::tuple T1;
 typedef std::tuple T2;
 const T1 t1(1);
 const T2 t2(1);
@@ -58,7 +58,7 @@
 assert( (t1 >= t2));
 }
 {
-typedef std::tuple T1;
+typedef std::tuple T1;
 typedef std::tuple T2;
 const T1 t1(1);
 const T2 t2(0.9);
@@ -68,7 +68,7 @@
 assert( (t1 >= t2));
 }
 {
-typedef std::tuple T1;
+typedef std::tuple T1;
 typedef std::tuple T2;
 const T1 t1(1);
 const T2 t2(1.1);
@@ -78,118 +78,118 @@
 assert(!(t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2);
 const T2 t2(1, 2);
 assert(!(t1 <  t2));
 assert( (t1 <= t2));
 assert(!(t1 >  t2));
 assert( (t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2);
 const T2 t2(0.9, 2);
 assert(!(t1 <  t2));
 assert(!(t1 <= t2));
 assert( (t1 >  t2));
 assert( (t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2);
 const T2 t2(1.1, 2);
 assert( (t1 <  t2));
 assert( (t1 <= t2));
 assert(!(t1 >  t2));
 assert(!(t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2);
 const T2 t2(1, 1);
 assert(!(t1 <  t2));
 assert(!(t1 <= t2));
 assert( (t1 >  t2));
 assert( (t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2);
 const T2 t2(1, 3);
 assert( (t1 <  t2));
 assert( (t1 <= t2));
 assert(!(t1 >  t2));
 assert(!(t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2, 3);
 const T2 t2(1, 2, 3);
 assert(!(t1 <  t2));
 assert( (t1 <= t2));
 assert(!(t1 >  t2));
 assert( (t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2, 3);
 const T2 t2(0.9, 2, 3);
 assert(!(t1 <  t2));
 assert(!(t1 <= t2));
 assert( (t1 >  t2));
 assert( (t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2, 3);
 const T2 t2(1.1, 2, 3);
 assert( (t1 <  t2));
 assert( (t1 <= t2));
 assert(!(t1 >  t2));
 assert(!(t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2, 3);
 const T2 t2(1, 1, 3);
 assert(!(t1 <  t2));
 assert(!(t1 <= t2));
 assert( (t1 >  t2));
 assert( (t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2, 3);
 const T2 t2(1, 3, 3);
 assert( (t1 <  t2));
 assert( (t1 <= t2));
 assert(!(t1 >  t2));
 assert(!(t1 >= t2));
 }
 {
-typedef std::tuple T1;
-typedef std::tuple T2;
+typedef std::tuple T1;
+typedef std::tuple T2;
 const T1 t1(1, 2, 3);
 const T2 t2(1, 2, 2);
 assert(!(t1 <  t2));
 assert(!(t1 <= t2));
 assert( (t1 

[PATCH] D27542: [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 5/7.

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

[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible 
loss of data", part 5/7.

Instead of storing double in double and then truncating to int, store int in 
long
and then widen to long long. This preserves test coverage (as these tests are
interested in various tuple conversions) while avoiding truncation warnings.

test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp
Since we aren't physically truncating anymore, t1 is equal to p0.

test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp
One edit is different from the usual pattern. Previously, we were storing
double in double and then converting to A, which has an implicitly converting
constructor from int. Now, we're storing int in int and then converting to A,
avoiding the truncation.


https://reviews.llvm.org/D27542

Files:
  test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_const_pair.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_convert_copy.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp
  test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp

Index: test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp
===
--- test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move_pair.pass.cpp
@@ -38,9 +38,9 @@
 int main()
 {
 {
-typedef std::pair> T0;
-typedef std::tuple> T1;
-T0 t0(2.5, std::unique_ptr(new D(3)));
+typedef std::pair> T0;
+typedef std::tuple> T1;
+T0 t0(2, std::unique_ptr(new D(3)));
 T1 t1 = std::move(t0);
 assert(std::get<0>(t1) == 2);
 assert(std::get<1>(t1)->id_ == 3);
Index: test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp
===
--- test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp
@@ -48,44 +48,44 @@
 int main()
 {
 {
-typedef std::tuple T0;
-typedef std::tuple T1;
-T0 t0(2.5);
+typedef std::tuple T0;
+typedef std::tuple T1;
+T0 t0(2);
 T1 t1 = std::move(t0);
 assert(std::get<0>(t1) == 2);
 }
 {
-typedef std::tuple T0;
-typedef std::tuple T1;
-T0 t0(2.5, 'a');
+typedef std::tuple T0;
+typedef std::tuple T1;
+T0 t0(2, 'a');
 T1 t1 = std::move(t0);
 assert(std::get<0>(t1) == 2);
 assert(std::get<1>(t1) == int('a'));
 }
 {
-typedef std::tuple T0;
-typedef std::tuple T1;
-T0 t0(2.5, 'a', D(3));
+typedef std::tuple T0;
+typedef std::tuple T1;
+T0 t0(2, 'a', D(3));
 T1 t1 = std::move(t0);
 assert(std::get<0>(t1) == 2);
 assert(std::get<1>(t1) == int('a'));
 assert(std::get<2>(t1).id_ == 3);
 }
 {
 D d(3);
-typedef std::tuple T0;
-typedef std::tuple T1;
-T0 t0(2.5, 'a', d);
+typedef std::tuple T0;
+typedef std::tuple T1;
+T0 t0(2, 'a', d);
 T1 t1 = std::move(t0);
 d.id_ = 2;
 assert(std::get<0>(t1) == 2);
 assert(std::get<1>(t1) == int('a'));
 assert(std::get<2>(t1).id_ == 2);
 }
 {
-typedef std::tuple> T0;
-typedef std::tuple> T1;
-T0 t0(2.5, 'a', std::unique_ptr(new D(3)));
+typedef std::tuple> T0;
+typedef std::tuple> T1;
+T0 t0(2, 'a', std::unique_ptr(new D(3)));
 T1 t1 = std::move(t0);
 assert(std::get<0>(t1) == 2);
 assert(std::get<1>(t1) == int('a'));
Index: test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp
===
--- test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp
@@ -68,17 +68,17 @@
 int main()
 {
 {
-typedef std::tuple T0;
-typedef std::tuple T1;
-T0 t0(2.5);
+typedef std::tuple T0;
+typedef std::tuple T1;
+T0 t0(2);
 T1 t1 = t0;
 assert(std::get<0>(t1) == 2);
 }
 #if TEST_STD_VER > 11
 {
-typed

[PATCH] D27543: [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 6/7.

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

[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible 
loss of data", part 6/7.

test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp
(Affects 64-bit architectures.) Include  so we can take/return 
std::ptrdiff_t
(instead of int) in random_shuffle()'s RNG. (C++14 D.12 
[depr.alg.random.shuffle]/2 says that
difference_type is used, and we're shuffling a plain array.)

test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp
test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
(Affects 64-bit architectures.) Include  because we're already using 
iterator_traits.
Then, store the result of subtracting two RanIts as difference_type instead of 
long
(which truncates on LLP64 architectures like MSVC x64).

test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp
test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp
(Affects 64-bit architectures.) Include  so we can store the result of
subtracting two pointers as std::ptrdiff_t (instead of int).

test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp
(Affects 32-bit architectures.) Sometimes, size_t is too small. That's the case 
here,
where tellg() returns pos_type (N4606 27.7.2.3 [istream.unformatted]/39). 
Implementations can
have 64-bit pos_type (to handle large files) even when they have 32-bit size_t.


https://reviews.llvm.org/D27543

Files:
  
test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp
  test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp
  test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
  
test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp
  
test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp
  
test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp

Index: test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp
===
--- test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp
+++ test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp
@@ -27,8 +27,8 @@
 
 std::istringstream is(s);
 const unsigned int ignoreLen=10;
-size_t a=is.tellg();
+std::istringstream::pos_type a=is.tellg();
 is.ignore(ignoreLen);
-size_t b=is.tellg();
+std::istringstream::pos_type b=is.tellg();
 assert((b-a)==ignoreLen);
 }
Index: test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp
===
--- test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp
+++ test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp
@@ -14,15 +14,16 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 #include "min_allocator.h"
 
 typedef int T;
 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7};
 const T t2[] = {10, 11, 12};
-const int size_t1 = std::end(t1) - std::begin(t1);
-const int size_t2 = std::end(t2) - std::begin(t2);
+const std::ptrdiff_t size_t1 = std::end(t1) - std::begin(t1);
+const std::ptrdiff_t size_t2 = std::end(t2) - std::begin(t2);
 
 template 
 void
Index: test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp
===
--- test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp
+++ test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp
@@ -14,14 +14,15 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "min_allocator.h"
 
 typedef int T;
 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7};
 const T t2[] = {10, 11, 12, 13, 14, 15};
-const int size_t1 = std::end(t1) - std::begin(t1);
-const int size_t2 = std::end(t2) - std::begin(t2);
+const std::ptrdiff_t size_t1 = std::end(t1) - std::begin(t1);
+const std::ptrdiff_t size_t2 = std::end(t2) - std::begin(t2);
 
 template 
 void
Index: test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
===
--- test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
+++ test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
@@ -16,16 +16,19 @@
 //   stable_sort(Iter first, Iter last);
 
 #include 
+#include 
 #include 
 
 template 
 void
 test_sort_helper(RI f, RI l)
 {
 typedef typename std::iterator_traits::value_type value_type;
+typedef typename std::iterator_traits::difference_type difference_type;
+
 if (f != l)
 {
-l

[PATCH] D27544: [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 7/7.

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

[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible 
loss of data", part 7/7.

test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp
Add static_cast because basic_istream::get() returns int_type (N4606 
27.7.2.3 [istream.unformatted]/4).

test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp
Add static_cast because toupper() returns int (C11 7.4.2.2/1).

test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.ops/assign_t.pass.cpp
This test is intentionally writing doubles to ostream_iterator.
It's silencing -Wliteral-conversion for Clang, so I'm adding C4244 silencing 
for MSVC.

test/std/language.support/support.limits/limits/numeric.limits.members/infinity.pass.cpp
Given `extern float zero;`, the expression `1./zero` has type double, which 
emits a truncation warning
when being passed to test() taking float. The fix is to say `1.f/zero` 
which has type float.

test/std/numerics/complex.number/cmplx.over/arg.pass.cpp
test/std/numerics/complex.number/cmplx.over/norm.pass.cpp
These tests were constructing std::complex(x, 0), emitting truncation 
warnings when x is long long.
Saying static_cast(x) avoids this.

test/std/numerics/rand/rand.eng/rand.eng.lcong/seed_result_type.pass.cpp
This was using `int s` to construct and seed a linear_congruential_engine, where T is
unsigned short/unsigned int/unsigned long/unsigned long long. That emits a 
truncation warning in the
unsigned short case. Because the range [0, 20) is tiny and we aren't doing 
anything else with the index,
we can just iterate with `T s`.

test/std/re/re.traits/value.pass.cpp
regex_traits::value()'s first parameter is wchar_t (N4606 28.7 
[re.traits]/13). This loop is
using int to iterate through ['g', 0x), emitting a truncation warning from 
int to wchar_t
(which is 16-bit for some of us). static_cast fixes this.

test/std/strings/basic.string/string.cons/size_char_alloc.pass.cpp
This test is a little strange. It's trying to verify that basic_string's (InIt, 
InIt) range constructor
isn't confused by "N copies of C" when N and C have the same integral type. To 
do this, it was
testing (100, 65), but that eventually emits truncation warnings from int to 
char. There's a simple way
to avoid this - passing (static_cast(100), static_cast(65)) also 
exercises the disambiguation.
(And 100 is representable even when char has a signed range.)

test/std/strings/string.view/string.view.hash/string_view.pass.cpp
Add static_cast because `'0' + i` has type int.

test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp
What's more horrible than nested bind()? pow() overloads! This operator()(T a, 
T b) was assuming that
std::pow(a, b) can be returned as T. (In this case, T is int.) However, N4606 
26.9.1 [cmath.syn]/2
says that pow(int, int) returns double, so this was truncating double to int.
Adding static_cast silences this.

test/std/utilities/function.objects/unord.hash/integral.pass.cpp
This was iterating `for (int i = 0; i <= 5; ++i)` and constructing `T t(i);` 
but that's truncating
when T is short. (And super truncating when T is bool.) Adding static_cast 
silences this.

test/std/utilities/utility/exchange/exchange.pass.cpp
First, this was exchanging 67.2 into an int, but that's inherently truncating.
Changing this to static_cast(67) avoids the truncation while preserving 
the
"what if T and U are different" test coverage.
Second, this was exchanging {} with the explicit type float into an int, and 
that's also
inherently truncating. Specifying short is just as good.

test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp
Add static_cast. Note that this affects template argument deduction for 
make_pair(),
better fulfilling the test's intent. For example, this was saying
`typedef std::pair P1; P1 p1 = std::make_pair(3, 4);` but that was 
asking
make_pair() to return pair, which was then being converted to 
pair.
(pair's converting constructors are tested elsewhere.)
Now, std::make_pair(3, static_cast(4)) actually returns pair.
(There's still a conversion from pair to 
pair, short>.)


https://reviews.llvm.org/D27544

Files:
  
test/std/input.output/iostream.format/input.streams/istream.unformatted/get.pass.cpp
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp
  
test/std/iterators/stream.iterators/ostream.iterator/ostream.iterator.ops/assign_t.pass.cpp
  
test/std/language.support/support.limits/limits/numeric.limits.members/infinity.pass.cpp
  test/std/numerics/complex.number/cmplx.over/arg.pass.cpp
  test/std/numerics/complex.number/cmplx.over/norm.pass.cpp
  test/std/numerics/rand/rand.eng/rand.eng.lcong/seed_result_type.pass.cpp
  test/std/re/re.traits/value.pass.cpp
  test/std/strings/bas

[PATCH] D27545: Don't assert when redefining a built-in macro in a PCH, PR29119

2016-12-07 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: rnk.
thakis added subscribers: cfe-commits, rsmith.

PCH files store the macro history for a  given macro, and the whole history 
list for one identifier is given to the Preprocessor at once via 
Preprocessor::setLoadedMacroDirective(). This contained an assert that no macro 
history exists yet for that identifier. That's usually true, but it's not true 
for builtin macros, which are created in Preprocessor() before flags and pchs 
are processed. Luckily, ASTWriter stops writing macro history lists at builtins 
(see shouldIgnoreMacro() in ASTWriter.cpp), so the head of the history list was 
missing for builtin macros. So make the assert weaker, and splice the history 
list to the existing single define for builtins.


https://reviews.llvm.org/D27545

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/PPMacroExpansion.cpp
  lib/Serialization/ASTReader.cpp
  test/PCH/builtin-macro.c

Index: test/PCH/builtin-macro.c
===
--- test/PCH/builtin-macro.c
+++ test/PCH/builtin-macro.c
@@ -0,0 +1,33 @@
+
+// Test this without pch.
+// RUN: %clang_cc1 -D__DATE__= -D__TIMESTAMP__= -include %s -Wno-builtin-macro-redefined -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: %clang_cc1 -D__DATE__= -D__TIMESTAMP__= -Wno-builtin-macro-redefined -emit-pch -o %t %s
+// RUN: %clang_cc1 -D__DATE__= -D__TIMESTAMP__= -Wno-builtin-macro-redefined -include-pch %t -fsyntax-only -verify %s 
+
+#if !defined(HEADER)
+#define HEADER
+
+#define __TIME__
+
+#undef __TIMESTAMP__
+#define __TIMESTAMP__
+
+// FIXME: undefs don't work well with pchs yet, see PR31311
+// Once that's fixed, add -U__COUNTER__ to all command lines and check that
+// an attempt to use __COUNTER__ at the bottom produces an error in both non-pch
+// and pch case (works fine in the former case already).
+// Same for #undef __FILE__ right here and a use of that at the bottom.
+//#undef __FILE__
+
+// Also spot-check a predefine
+#undef __STDC_HOSTED__
+
+#else
+
+const char s[] = __DATE__ " " __TIME__ " " __TIMESTAMP__;
+
+const int d = __STDC_HOSTED__; // expected-error{{use of undeclared identifier '__STDC_HOSTED__'}}
+
+#endif
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -1953,7 +1953,7 @@
   }
 
   if (Latest)
-PP.setLoadedMacroDirective(II, Latest);
+PP.setLoadedMacroDirective(II, Earliest, Latest);
 }
 
 ASTReader::InputFileInfo
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -92,12 +92,33 @@
 }
 
 void Preprocessor::setLoadedMacroDirective(IdentifierInfo *II,
+   MacroDirective *ED,
MacroDirective *MD) {
+  // Normally, when a macro is defined, it goes through appendMacroDirective()
+  // above, which chains a macro to previous defines, undefs, etc.
+  // However, in a pch, the whole macro history up to the end of the pch is
+  // stored, so ASTReader goes through this function instead.
+  // However, built-in macros are already registered in the Preprocessor
+  // ctor, and ASTWriter stops writing the macro chain at built-in macros,
+  // so in that case the chain from the pch needs to be spliced to the existing
+  // built-in.
+
   assert(II && MD);
   MacroState &StoredMD = CurSubmoduleState->Macros[II];
-  assert(!StoredMD.getLatest() &&
- "the macro history was modified before initializing it from a pch");
-  StoredMD = MD;
+
+  if (auto *OldMD = StoredMD.getLatest()) {
+// FIXME: shouldIgnoreMacro() in ASTWriter also stops at macros from the
+// predefines buffer in module builds. Do we need to splice to those here
+// too?
+assert(OldMD->getMacroInfo()->isBuiltinMacro() &&
+   "only built-ins should have an entry here");
+assert(!OldMD->getPrevious() && "builtin should only have a singe entry");
+ED->setPrevious(OldMD);
+StoredMD.setLatest(MD);
+  } else {
+StoredMD = MD;
+  }
+
   // Setup the identifier as having associated macro history.
   II->setHasMacroDefinition(true);
   if (!MD->isDefined() && LeafModuleMacros.find(II) == LeafModuleMacros.end())
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -887,7 +887,8 @@
 return appendDefMacroDirective(II, MI, MI->getDefinitionLoc());
   }
   /// \brief Set a MacroDirective that was loaded from a PCH file.
-  void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *MD);
+  void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED,
+   MacroDirective *MD);
 
   /// \brief Register an exported macro for a module

[PATCH] D25417: [libcxxabi] Fix alignment of allocated exceptions in 32 bit builds

2016-12-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 80658.
EricWF added a comment.

- Use `_aligned_malloc` on windows.
- Ensure `posix_memalign` isn't called with a size of `0`. I'm 99% sure that's 
currently impossible but we might as well handle it.

I'll commit after testing on OS X.


https://reviews.llvm.org/D25417

Files:
  src/cxa_exception.cpp
  src/fallback_malloc.cpp
  test/test_exception_address_alignment.pass.cpp


Index: test/test_exception_address_alignment.pass.cpp
===
--- /dev/null
+++ test/test_exception_address_alignment.pass.cpp
@@ -0,0 +1,28 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// Test that the address of the exception object is properly aligned to the
+// largest supported alignment for the system.
+
+#include 
+#include 
+
+struct __attribute__((aligned)) AlignedType {};
+struct MinAligned {  };
+static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, "");
+
+int main() {
+  for (int i=0; i < 10; ++i) {
+try {
+  throw MinAligned{};
+} catch (MinAligned const& ref) {
+  assert(reinterpret_cast(&ref) % alignof(AlignedType) == 0);
+}
+  }
+}
Index: src/fallback_malloc.cpp
===
--- src/fallback_malloc.cpp
+++ src/fallback_malloc.cpp
@@ -193,11 +193,20 @@
 
 #pragma GCC visibility push(hidden)
 
+struct __attribute__((aligned)) __aligned_type  {};
+
 void * __malloc_with_fallback(size_t size) {
-void *ptr = std::malloc(size);
-if (NULL == ptr) // if malloc fails, fall back to emergency stash
-ptr = fallback_malloc(size);
-return ptr;
+#if defined(_WIN32)
+if (void *dest = _aligned_malloc(size, alignof(__aligned_type)))
+  return dest;
+#else
+if (size == 0)
+size = 1;
+void* dest;
+if (::posix_memalign(&dest, alignof(__aligned_type), size) == 0)
+return dest;
+#endif
+return fallback_malloc(size);
 }
 
 void * __calloc_with_fallback(size_t count, size_t size) {
Index: src/cxa_exception.cpp
===
--- src/cxa_exception.cpp
+++ src/cxa_exception.cpp
@@ -66,12 +66,16 @@
 return cxa_exception_from_thrown_object(unwind_exception + 1 );
 }
 
-static
-inline
-size_t
-cxa_exception_size_from_exception_thrown_size(size_t size)
-{
-return size + sizeof (__cxa_exception);
+// Round s up to next multiple of a.
+static inline
+size_t aligned_allocation_size(size_t s, size_t a) {
+return (s + a - 1) & ~(a - 1);
+}
+
+static inline
+size_t cxa_exception_size_from_exception_thrown_size(size_t size) {
+return aligned_allocation_size(size + sizeof (__cxa_exception),
+   alignof(__cxa_exception));
 }
 
 static void setExceptionClass(_Unwind_Exception* unwind_exception) {


Index: test/test_exception_address_alignment.pass.cpp
===
--- /dev/null
+++ test/test_exception_address_alignment.pass.cpp
@@ -0,0 +1,28 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// Test that the address of the exception object is properly aligned to the
+// largest supported alignment for the system.
+
+#include 
+#include 
+
+struct __attribute__((aligned)) AlignedType {};
+struct MinAligned {  };
+static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, "");
+
+int main() {
+  for (int i=0; i < 10; ++i) {
+try {
+  throw MinAligned{};
+} catch (MinAligned const& ref) {
+  assert(reinterpret_cast(&ref) % alignof(AlignedType) == 0);
+}
+  }
+}
Index: src/fallback_malloc.cpp
===
--- src/fallback_malloc.cpp
+++ src/fallback_malloc.cpp
@@ -193,11 +193,20 @@
 
 #pragma GCC visibility push(hidden)
 
+struct __attribute__((aligned)) __aligned_type  {};
+
 void * __malloc_with_fallback(size_t size) {
-void *ptr = std::malloc(size);
-if (NULL == ptr) // if malloc fails, fall back to emergency stash
-ptr = fallback_malloc(size);
-return ptr;
+#if defined(_WIN32)
+if (void *dest = _aligned_malloc(size, alignof(__aligned_type)))
+  return dest;
+#else
+if (size == 0)
+size = 1;
+void* dest;
+if (::posix_memalign(&dest, alignof(__aligned_type), size) == 0)
+return dest;
+#endif
+r

[PATCH] D27546: [ASTReader] Sort RawComments before merging

2016-12-07 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno created this revision.
bruno added reviewers: manmanren, akyrtzi, rsmith.
bruno added a subscriber: cfe-commits.

`RawComments` are sorted by comparing underlying `SourceLocation`'s. This is 
done by comparing `FileID` and `Offset`; when the `FileID` is the same it means
the locations are within the same TU and the `Offset` is used, etc.

FileID, from the source code: "A mostly-opaque identifier, where 0 is 
"invalid", >0 is this module, and <-1 is something loaded from another
module.". That said, when de-serializing SourceLocations, FileID's from 
RawComments loaded from other modules get negative IDs where previously they
were positive. This makes imported RawComments unsorted, leading to a wrong 
merge with other comments from the current TU. Fix that by sorting RawComments
properly after de-serialization and before merge.

This fixes an assertion in `ASTContext::getRawCommentForDeclNoCache`, which 
fires only in a debug build of clang. There's seems to be no reliable way to 
test this.
Additionally, I tried to use `llvm::array_pod_sort`, but that didn't seem to 
cope well with `BeforeThanCompare(SourceMgr)` or lambdas, and a 
`SourceMgr` is needed to perform the sort.


https://reviews.llvm.org/D27546

Files:
  lib/Serialization/ASTReader.cpp


Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -8481,6 +8481,10 @@
   }
 }
   NextCursor:
+// De-serialized SourceLocations get negative FileIDs for other modules,
+// potentially invalidating the original order. Sort it again.
+std::sort(Comments.begin(), Comments.end(),
+  BeforeThanCompare(SourceMgr));
 Context.Comments.addDeserializedComments(Comments);
   }
 }


Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -8481,6 +8481,10 @@
   }
 }
   NextCursor:
+// De-serialized SourceLocations get negative FileIDs for other modules,
+// potentially invalidating the original order. Sort it again.
+std::sort(Comments.begin(), Comments.end(),
+  BeforeThanCompare(SourceMgr));
 Context.Comments.addDeserializedComments(Comments);
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27279: Store decls in prototypes on the declarator instead of in the AST

2016-12-07 Thread Richard Smith via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Sema/DeclSpec.h:1240
+/// in the prototype. These are generally tag types or enumerators.
+unsigned NumDeclsInPrototype : 8;
+

It seems plausible that generated code could have more than 256 such 
declarations. This class has a pointer, a set of bit-fields, 12 `unsigned`s, 
and another pointer, so we could give this a full 32 bits without increasing 
the size of the class. Alternatively we could share the storage with 
`NumExceptions`, since this can only be non-zero in C and that can only be 
non-zero in C++.



Comment at: include/clang/Sema/DeclSpec.h:1311
+/// for lookup inside the function body, if one exists.
+NamedDecl **DeclsInPrototype;
+

Might make sense to put this into the preceding union, if we care about how big 
this type is.



Comment at: test/Misc/ast-dump-decl.c:109-110
 // CHECK:  FunctionDecl{{.*}} TestFunctionDecl 'int (int, enum {{.*}})'
-// CHECK-NEXT:   EnumDecl
-// CHECK-NEXT: EnumConstantDecl{{.*}} e
 // CHECK-NEXT:   ParmVarDecl{{.*}} x

Why is this not here any more? Looks like SemaDecl.cpp:8255 should have added 
it to this `DeclContext`. It'd be nice for `-ast-dump` to still dump these 
declarations somewhere.


https://reviews.llvm.org/D27279



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


[PATCH] D27486: Correct class-template deprecation behavior

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



Comment at: lib/Sema/SemaTemplate.cpp:2355
  Converted, nullptr);
+  if (auto *attr = ClassTemplate->getTemplatedDecl()
+   ->getAttr())

Please capitalize `Attr`.



Comment at: lib/Sema/SemaTemplate.cpp:2356
+  if (auto *attr = ClassTemplate->getTemplatedDecl()
+   ->getAttr())
+Decl->addAttr(attr->clone(Context));

I think you can remove the `clang::`


https://reviews.llvm.org/D27486



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


[PATCH] D27486: Correct class-template deprecation behavior

2016-12-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Thanks David!
To all - I'm actually doing my best to rewrite this based on Richard's 
suggestions, so look for a 'in progress' update to this review as soon as I get 
something that is reasonably presentable.


https://reviews.llvm.org/D27486



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


[PATCH] D27549: [DebugInfo] Add support for __fp16, float, and double constants.

2016-12-07 Thread Paul Robinson via Phabricator via cfe-commits
probinson added subscribers: cfe-commits, probinson.
probinson added a comment.

Hi David!
As this is a Clang patch, you should subscribe cfe-commits rather than 
llvm-commits.  I've done that for you.
See also inline comments.




Comment at: lib/CodeGen/CGDebugInfo.cpp:3765
+InitExpr =
+
DBuilder.createConstantValueExpression(Init.getFloat().bitcastToAPInt().getZExtValue());
   GV.reset(DBuilder.createGlobalVariable(

This line exceeds 80 columns.  clang-format is your friend.



Comment at: test/CodeGen/debug-info-static-const-fp.c:19
+// CHECK: !4 = distinct !DIGlobalVariable(name: "hVal", scope: !0, file: !1, 
line: 6, type: !5, isLocal: true, isDefinition: true, expr: !7)
+// CHECK: !7 = !DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
+// CHECK: !8 = distinct !DIGlobalVariable(name: "fVal", scope: !0, file: !1, 
line: 8, type: !9, isLocal: true, isDefinition: true, expr: !11)

Checking for the entire exact line for the variable is a bit fragile.  Really 
what you want to do is associate the variable with the correct expression, and 
ignore all the irrelevant details.  Something like this:
```
// CHECK: DIGlobalVariable(name: "hVal", {{.*}} expr: ![[HEXPR:{{[0-9]+}}]]
// CHECK: ![[HEXPR] = ! DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
```
And similar pairs for the other variables.  I'd use a different FileCheck 
variable for each case.



https://reviews.llvm.org/D27549



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


r288994 - [Driver] Add tests for default stack protector values on Darwin

2016-12-07 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Wed Dec  7 17:20:30 2016
New Revision: 288994

URL: http://llvm.org/viewvc/llvm-project?rev=288994&view=rev
Log:
[Driver] Add tests for default stack protector values on Darwin

Modified:
cfe/trunk/test/Driver/stack-protector.c

Modified: cfe/trunk/test/Driver/stack-protector.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/stack-protector.c?rev=288994&r1=288993&r2=288994&view=diff
==
--- cfe/trunk/test/Driver/stack-protector.c (original)
+++ cfe/trunk/test/Driver/stack-protector.c Wed Dec  7 17:20:30 2016
@@ -32,3 +32,18 @@
 // RUN: %clang -target x86_64-scei-ps4 -fstack-protector --param 
ssp-buffer-size=16 -### %s 2>&1 | FileCheck %s -check-prefix=SSP-PS4-BUF
 // SSP-PS4-BUF: "-stack-protector" "2"
 // SSP-PS4-BUF: "-stack-protector-buffer-size" "16"
+
+// Test default stack protector values for Darwin platforms
+
+// RUN: %clang -target armv7k-apple-watchos2.0 -### %s 2>&1 | FileCheck %s 
-check-prefix=SSP_WATCHOS
+// SSP_WATCHOS: "-stack-protector" "1"
+// RUN: %clang -target arm64-apple-ios8.0.0 -### %s 2>&1 | FileCheck %s 
-check-prefix=SSP_IOS
+// SSP_IOS: "-stack-protector" "1"
+// RUN: %clang -target x86_64-apple-darwin10 -mmacosx-version-min=10.6 -### %s 
2>&1 | FileCheck %s -check-prefix=SSP_MACOSX
+// SSP_MACOSX: "-stack-protector" "1"
+// RUN: %clang -target x86_64-apple-darwin10 -mmacosx-version-min=10.5 -### %s 
2>&1 | FileCheck %s -check-prefix=SSP_MACOSX_10_5
+// SSP_MACOSX_10_5: "-stack-protector" "1"
+// RUN: %clang -target x86_64-apple-darwin10 -mmacosx-version-min=10.5 
-mkernel -### %s 2>&1 | FileCheck %s -check-prefix=SSP_MACOSX_KERNEL
+// SSP_MACOSX_KERNEL-NOT: "-stack-protector"
+// RUN: %clang -target x86_64-apple-darwin10 -mmacosx-version-min=10.6 -### %s 
2>&1 | FileCheck %s -check-prefix=SSP_MACOSX_10_6_KERNEL
+// SSP_MACOSX_10_6_KERNEL: "-stack-protector" "1"


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


r288997 - Add more tests for MSVC version handling.

2016-12-07 Thread David L. Jones via cfe-commits
Author: dlj
Date: Wed Dec  7 17:39:44 2016
New Revision: 288997

URL: http://llvm.org/viewvc/llvm-project?rev=288997&view=rev
Log:
Add more tests for MSVC version handling.

Summary:
This change adds more test cases for the default MSVC compatibility version:
 1. When -fms-extensions is supplied, but -fmsc-version and
-fms-compatibility-version are not.
 2. With the target triple specifies an MSVC environment, but no other
-fms* flags.

Reviewers: rnk, llvm-commits

Subscribers: hans, compnerd, amccarth

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

Modified:
cfe/trunk/test/Driver/msc-version.c
cfe/trunk/test/Driver/msvc-triple.c

Modified: cfe/trunk/test/Driver/msc-version.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/msc-version.c?rev=288997&r1=288996&r2=288997&view=diff
==
--- cfe/trunk/test/Driver/msc-version.c (original)
+++ cfe/trunk/test/Driver/msc-version.c Wed Dec  7 17:39:44 2016
@@ -55,3 +55,12 @@
 // CHECK-MSC-15-NOT: "-fmsc-version=150020706"
 // CHECK-MSC-15: "-fms-compatibility-version=15.0.20706"
 
+//
+// Verify default version with -fms-extensions
+//
+
+// RUN: %clang -target i686-windows -fms-extensions -dM -E - http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/msvc-triple.c?rev=288997&r1=288996&r2=288997&view=diff
==
--- cfe/trunk/test/Driver/msvc-triple.c (original)
+++ cfe/trunk/test/Driver/msvc-triple.c Wed Dec  7 17:39:44 2016
@@ -1,7 +1,9 @@
 // RUN: %clang -target i686-pc-windows-msvc19 -S -emit-llvm %s -o - | 
FileCheck %s --check-prefix=TARGET-19
 // RUN: %clang -target i686-pc-windows-msvc   -S -emit-llvm %s -o - 
-fms-compatibility-version=19 | FileCheck %s --check-prefix=OVERRIDE-19
 // RUN: %clang -target i686-pc-windows-msvc-elf -S -emit-llvm %s -o - | 
FileCheck %s --check-prefix=ELF-DEFAULT
+// RUN: %clang -target i686-pc-windows-msvc   -S -emit-llvm %s -o - | 
FileCheck %s --check-prefix=DEFAULT
 
 // TARGET-19:   target triple = "i686-pc-windows-msvc19.0.0"
 // OVERRIDE-19: target triple = "i686-pc-windows-msvc19.0.0"
 // ELF-DEFAULT: target triple = "i686-pc-windows-msvc{{.*}}-elf"
+// DEFAULT: target triple = "i686-pc-windows-msvc{{[^-]+}}"


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


r288998 - Refactor how the MSVC toolchain searches for a compatibility version.

2016-12-07 Thread David L. Jones via cfe-commits
Author: dlj
Date: Wed Dec  7 17:41:58 2016
New Revision: 288998

URL: http://llvm.org/viewvc/llvm-project?rev=288998&view=rev
Log:
Refactor how the MSVC toolchain searches for a compatibility version.

Summary:
The MSVC toolchain and Clang driver combination currently uses a fairly complex
sequence of steps to determine the MS compatibility version to pass to cc1.
There is some oddness in this sequence currently, with some code which inspects
flags in the toolchain, and some code which inspects the triple and local
environment in the driver code.

This change is an attempt to consolidate most of this logic so that
Win32-specific code lives in MSVCToolChain.cpp. I'm not 100% happy with the
split, so any suggestions are welcome.

There are a few things you might want to watch for for specifically:

 - On all platforms, if MSVC compatibility flags are provided (and valid), use
   those.
 - The fallback sequence should be the same as before, but is now consolidated
   into MSVCToolChain::getMSVCVersion:
   - Otherwise, try to use the Triple.
   - Otherwise, on Windows, check the executable.
   - Otherwise, on Windows or with --fms-extensions, default to 18.
   - Otherwise, we can't determine the version.
 - MSVCToolChain::ComputeEffectiveTriple no longer calls the base
   ToolChain::ComputeEffectiveClangTriple. The only thing it would change for
   Windows the architecture, which we don't care about for the compatibility
   version.
- I'm not sure whether this is philosophically correct (but it should
  be easy to add back to MSVCToolChain::getMSVCVersionFromTriple if not).
- Previously, Tools.cpp just called getTriple() anyhow, so it doesn't look
  like the effective triple was always being used previously anyhow.

Reviewers: hans, compnerd, llvm-commits, rnk

Subscribers: amccarth

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

Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/MSVCToolChain.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Driver/Tools.h

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=288998&r1=288997&r2=288998&view=diff
==
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Wed Dec  7 17:41:58 2016
@@ -442,15 +442,15 @@ public:
   virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
 
+  /// \brief On Windows, returns the MSVC compatibility version.
+  virtual VersionTuple computeMSVCVersion(const Driver *D,
+  const llvm::opt::ArgList &Args) 
const;
+
   /// \brief Return sanitizers which are available in this toolchain.
   virtual SanitizerMask getSupportedSanitizers() const;
 
   /// \brief Return sanitizers which are enabled by default.
   virtual SanitizerMask getDefaultSanitizers() const { return 0; }
-
-  /// \brief On Windows, returns the version of cl.exe.  On other platforms,
-  /// returns an empty VersionTuple.
-  virtual VersionTuple getMSVCVersionFromExe() const { return VersionTuple(); }
 };
 
 /// Set a ToolChain's effective triple. Reset it when the registration object

Modified: cfe/trunk/lib/Driver/MSVCToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MSVCToolChain.cpp?rev=288998&r1=288997&r2=288998&view=diff
==
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp Wed Dec  7 17:41:58 2016
@@ -16,6 +16,7 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -472,6 +473,14 @@ bool MSVCToolChain::getVisualStudioBinar
   return true;
 }
 
+VersionTuple MSVCToolChain::getMSVCVersionFromTriple() const {
+  unsigned Major, Minor, Micro;
+  getTriple().getEnvironmentVersion(Major, Minor, Micro);
+  if (Major || Minor || Micro)
+return VersionTuple(Major, Minor, Micro);
+  return VersionTuple();
+}
+
 VersionTuple MSVCToolChain::getMSVCVersionFromExe() const {
   VersionTuple Version;
 #ifdef USE_WIN32
@@ -668,21 +677,34 @@ void MSVCToolChain::AddClangCXXStdlibInc
   // FIXME: There should probably be logic here to find libc++ on Windows.
 }
 
+VersionTuple MSVCToolChain::computeMSVCVersion(const Driver *D,
+   const ArgList &Args) const {
+  bool IsWindowsMSVC = getTriple().isWindowsMSVCEnvironment();
+  VersionTuple MSVT = ToolChain::computeMSVCVersion(D, Args);
+  if (MSVT.empty()) MSVT = getMS

[PATCH] D27279: Store decls in prototypes on the declarator instead of in the AST

2016-12-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk marked an inline comment as done.
rnk added inline comments.



Comment at: include/clang/Sema/DeclSpec.h:1240
+/// in the prototype. These are generally tag types or enumerators.
+unsigned NumDeclsInPrototype : 8;
+

rsmith wrote:
> It seems plausible that generated code could have more than 256 such 
> declarations. This class has a pointer, a set of bit-fields, 12 `unsigned`s, 
> and another pointer, so we could give this a full 32 bits without increasing 
> the size of the class. Alternatively we could share the storage with 
> `NumExceptions`, since this can only be non-zero in C and that can only be 
> non-zero in C++.
I did it as a union with the EH machinery initially, but it changes our 
behavior on this test case:
  void f(struct Foo {} o) {} // error in C++
  struct Foo {}; // follow on error for redefining type Foo

We actually have test cases for this at 
clang/test/SemaCXX/type-definition-in-specifier.cpp. I don't think it's 
important to preserve that exact behavior, though, so performance may be more 
important. I just did it this way to avoid premature optimization.



Comment at: test/Misc/ast-dump-decl.c:109-110
 // CHECK:  FunctionDecl{{.*}} TestFunctionDecl 'int (int, enum {{.*}})'
-// CHECK-NEXT:   EnumDecl
-// CHECK-NEXT: EnumConstantDecl{{.*}} e
 // CHECK-NEXT:   ParmVarDecl{{.*}} x

rsmith wrote:
> Why is this not here any more? Looks like SemaDecl.cpp:8255 should have added 
> it to this `DeclContext`. It'd be nice for `-ast-dump` to still dump these 
> declarations somewhere.
I changed things to dump non-parameter decls in the function now, but we only 
move NamedDecls into the function DeclContext, so the output is a little 
different. Think it matters?


https://reviews.llvm.org/D27279



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


[PATCH] D27279: Store decls in prototypes on the declarator instead of in the AST

2016-12-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 80682.
rnk marked an inline comment as done.
rnk added a comment.

- Allow more decls in prototypes, dump fd decls


https://reviews.llvm.org/D27279

Files:
  include/clang/AST/Decl.h
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/Decl.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/Misc/ast-dump-decl.c
  test/PCH/decl-in-prototype.c
  test/Sema/decl-in-prototype.c
  test/SemaCXX/type-definition-in-specifier.cpp

Index: test/SemaCXX/type-definition-in-specifier.cpp
===
--- test/SemaCXX/type-definition-in-specifier.cpp
+++ test/SemaCXX/type-definition-in-specifier.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -verify %s
 
 struct S0;
 struct S1;
@@ -64,3 +64,6 @@
   short bar5 (struct foo4 {} bar2); // expected-error{{'foo4' cannot be defined in a parameter type}}
   long foo5 (float foo6 = foo4);  // expected-error{{use of undeclared identifier 'foo4'}}
 };
+
+void func_with_eh_and_type(struct type_in_eh {} o) throw(int) {} // expected-error{{cannot be defined in a parameter type}}
+struct type_in_eh {}; // no diagnostics
Index: test/Sema/decl-in-prototype.c
===
--- test/Sema/decl-in-prototype.c
+++ test/Sema/decl-in-prototype.c
@@ -1,13 +1,19 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+#define SA(n, c) int arr##n[(c) ? 1 : -1] = {}
+
 const int AA = 5;
 
 int f1(enum {AA,BB} E) { // expected-warning {{will not be visible outside of this function}}
-return BB;
+  SA(1, AA == 0);
+  SA(2, BB == 1);
+  return BB;
 }
 
 int f2(enum {AA=7,BB} E) { // expected-warning {{will not be visible outside of this function}}
-return AA;
+  SA(1, AA == 7);
+  SA(2, BB == 8);
+  return AA;
 }
 
 struct a {
@@ -38,3 +44,11 @@
 
 // Only warn once, even if we create two declarations.
 void f(struct q *, struct __attribute__((aligned(4))) q *); // expected-warning {{will not be visible outside}}
+
+// This enum inside the function pointer parameter shouldn't leak into the
+// function.
+enum { BB = 0 };
+void enum_in_fun_in_fun(void (*fp)(enum { AA, BB } e)) { // expected-warning {{will not be visible}}
+  SA(1, AA == 5);
+  SA(2, BB == 0);
+}
Index: test/PCH/decl-in-prototype.c
===
--- /dev/null
+++ test/PCH/decl-in-prototype.c
@@ -0,0 +1,27 @@
+// Test that we serialize the enum decl in the function prototype somehow.
+// These decls aren't serialized quite the same way as parameters.
+
+// Test this without pch.
+// RUN: %clang_cc1 -include %s -emit-llvm -o - %s | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -include-pch %t -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: define i32 @main()
+// CHECK:   ret i32 1
+
+#ifndef HEADER
+#define HEADER
+
+static inline __attribute__((always_inline)) f(enum { x, y } p) {
+  return y;
+}
+
+#else
+
+int main() {
+  return f(0);
+}
+
+#endif
Index: test/Misc/ast-dump-decl.c
===
--- test/Misc/ast-dump-decl.c
+++ test/Misc/ast-dump-decl.c
@@ -106,12 +106,19 @@
   return x;
 }
 // CHECK:  FunctionDecl{{.*}} TestFunctionDecl 'int (int, enum {{.*}})'
+// CHECK-NEXT:   EnumConstantDecl{{.*}} e
+// CHECK-NEXT:   ParmVarDecl{{.*}} x
+// CHECK-NEXT:   ParmVarDecl{{.*}} y
+// CHECK-NEXT:   CompoundStmt
+
+int TestFunctionDecl2(enum Enum { e } x) { return x; }
+// CHECK:  FunctionDecl{{.*}} TestFunctionDecl2 'int (enum {{.*}})'
 // CHECK-NEXT:   EnumDecl
 // CHECK-NEXT: EnumConstantDecl{{.*}} e
 // CHECK-NEXT:   ParmVarDecl{{.*}} x
-// CHECK-NEXT:   ParmVarDecl{{.*}} y
 // CHECK-NEXT:   CompoundStmt
 
+
 int TestFunctionDeclProto(int x);
 // CHECK:  FunctionDecl{{.*}} TestFunctionDeclProto 'int (int)'
 // CHECK-NEXT:   ParmVarDecl{{.*}} x
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -718,6 +718,7 @@
   /*NumExceptions=*/0,
   /*NoexceptExpr=*/nullptr,
   /*ExceptionSpecTokens=*/nullptr,
+  /*DeclsInPrototype=*/None,
   loc, loc, declarator));
 
   // For consistency, make sure the state still has us as processing
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -8222,8 +8222,9 @@
   // Copy the parameter declarations from the declarator D to the function
   // declaration NewFD, if they are available.  First scavenge them into Params.
   SmallVector Params;
-  if (D.isFunctionDeclarator()) {
-DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();
+  unsigned

[PATCH] D27549: [DebugInfo] Add support for __fp16, float, and double constants.

2016-12-07 Thread David Gross via Phabricator via cfe-commits
dgross updated this revision to Diff 80683.
dgross added a comment.

Incorporate code review feedback.

- Reformat source.
- Make test pattern more general.


https://reviews.llvm.org/D27549

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGen/debug-info-static-const-fp.c


Index: test/CodeGen/debug-info-static-const-fp.c
===
--- /dev/null
+++ test/CodeGen/debug-info-static-const-fp.c
@@ -0,0 +1,27 @@
+// RUN: %clang -emit-llvm -O0 -S -g %s -o - | FileCheck %s
+
+// Per PR26619, check that for referenced static const of floating-point type,
+// we emit its constant value in debug info.  NOTE that PR26619 is not yet 
fixed for long double.
+
+static const __fp16 hVal = 29/13.0f;//2.2307692307692307692
 (2.23046875)
+
+static const float fVal = -147/17.0f;   //   -8.6470588235294117647
 (-8.64705849)
+
+static const double dVal = 19637/7.0;   // 2805.2857142857142857   
 (2805.2857142857142)
+
+static const long double ldVal = 3/1234567.0L;  //
2.4300017739012949479e-06 ()
+
+int main() {
+  return hVal + fVal + dVal + ldVal;
+}
+
+// CHECK: !DIGlobalVariable(name: "hVal", {{.*}}, isLocal: true, isDefinition: 
true, expr: ![[HEXPR:[0-9]+]]
+// CHECK: ![[HEXPR]] = !DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
+
+// CHECK: !DIGlobalVariable(name: "fVal", {{.*}}, isLocal: true, isDefinition: 
true, expr: ![[FEXPR:[0-9]+]]
+// CHECK: ![[FEXPR]] = !DIExpression(DW_OP_constu, 3238681178, 
DW_OP_stack_value)
+
+// CHECK: !DIGlobalVariable(name: "dVal", {{.*}}, isLocal: true, isDefinition: 
true, expr: ![[DEXPR:[0-9]+]]
+// CHECK: ![[DEXPR]] = !DIExpression(DW_OP_constu, 4658387303597904457, 
DW_OP_stack_value)
+
+// CHECK: !DIGlobalVariable(name: "ldVal", {{.*}}, isLocal: true, 
isDefinition: true)
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3760,6 +3760,9 @@
   if (Init.isInt())
 InitExpr =
 DBuilder.createConstantValueExpression(Init.getInt().getExtValue());
+  else if (Init.isFloat() && CGM.getContext().getTypeSize(VD->getType()) <= 64)
+InitExpr = DBuilder.createConstantValueExpression(
+Init.getFloat().bitcastToAPInt().getZExtValue());
   GV.reset(DBuilder.createGlobalVariable(
   DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
   true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),


Index: test/CodeGen/debug-info-static-const-fp.c
===
--- /dev/null
+++ test/CodeGen/debug-info-static-const-fp.c
@@ -0,0 +1,27 @@
+// RUN: %clang -emit-llvm -O0 -S -g %s -o - | FileCheck %s
+
+// Per PR26619, check that for referenced static const of floating-point type,
+// we emit its constant value in debug info.  NOTE that PR26619 is not yet fixed for long double.
+
+static const __fp16 hVal = 29/13.0f;//2.2307692307692307692 (2.23046875)
+
+static const float fVal = -147/17.0f;   //   -8.6470588235294117647 (-8.64705849)
+
+static const double dVal = 19637/7.0;   // 2805.2857142857142857(2805.2857142857142)
+
+static const long double ldVal = 3/1234567.0L;  //2.4300017739012949479e-06 ()
+
+int main() {
+  return hVal + fVal + dVal + ldVal;
+}
+
+// CHECK: !DIGlobalVariable(name: "hVal", {{.*}}, isLocal: true, isDefinition: true, expr: ![[HEXPR:[0-9]+]]
+// CHECK: ![[HEXPR]] = !DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
+
+// CHECK: !DIGlobalVariable(name: "fVal", {{.*}}, isLocal: true, isDefinition: true, expr: ![[FEXPR:[0-9]+]]
+// CHECK: ![[FEXPR]] = !DIExpression(DW_OP_constu, 3238681178, DW_OP_stack_value)
+
+// CHECK: !DIGlobalVariable(name: "dVal", {{.*}}, isLocal: true, isDefinition: true, expr: ![[DEXPR:[0-9]+]]
+// CHECK: ![[DEXPR]] = !DIExpression(DW_OP_constu, 4658387303597904457, DW_OP_stack_value)
+
+// CHECK: !DIGlobalVariable(name: "ldVal", {{.*}}, isLocal: true, isDefinition: true)
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3760,6 +3760,9 @@
   if (Init.isInt())
 InitExpr =
 DBuilder.createConstantValueExpression(Init.getInt().getExtValue());
+  else if (Init.isFloat() && CGM.getContext().getTypeSize(VD->getType()) <= 64)
+InitExpr = DBuilder.createConstantValueExpression(
+Init.getFloat().bitcastToAPInt().getZExtValue());
   GV.reset(DBuilder.createGlobalVariable(
   DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
   true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27549: [DebugInfo] Add support for __fp16, float, and double constants.

2016-12-07 Thread David Gross via Phabricator via cfe-commits
dgross added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:3765
+InitExpr =
+
DBuilder.createConstantValueExpression(Init.getFloat().bitcastToAPInt().getZExtValue());
   GV.reset(DBuilder.createGlobalVariable(

probinson wrote:
> This line exceeds 80 columns.  clang-format is your friend.
Done.  Is clang-format mentioned in any of the documentation that describes the 
development process?  I might have missed it (not that that's an excuse for a 
needless violation of the coding guidelines).



Comment at: test/CodeGen/debug-info-static-const-fp.c:19
+// CHECK: !4 = distinct !DIGlobalVariable(name: "hVal", scope: !0, file: !1, 
line: 6, type: !5, isLocal: true, isDefinition: true, expr: !7)
+// CHECK: !7 = !DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
+// CHECK: !8 = distinct !DIGlobalVariable(name: "fVal", scope: !0, file: !1, 
line: 8, type: !9, isLocal: true, isDefinition: true, expr: !11)

probinson wrote:
> Checking for the entire exact line for the variable is a bit fragile.  Really 
> what you want to do is associate the variable with the correct expression, 
> and ignore all the irrelevant details.  Something like this:
> ```
> // CHECK: DIGlobalVariable(name: "hVal", {{.*}} expr: ![[HEXPR:{{[0-9]+}}]]
> // CHECK: ![[HEXPR] = ! DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
> ```
> And similar pairs for the other variables.  I'd use a different FileCheck 
> variable for each case.
> 
Thanks for the suggestion.  I didn't realize FileCheck had variable support.


https://reviews.llvm.org/D27549



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


[PATCH] D25845: [CUDA] Ignore implicit target attributes during function template instantiation.

2016-12-07 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 80677.
tra marked 4 inline comments as done.
tra added a comment.

Addressed Justin's comments.


https://reviews.llvm.org/D25845

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaCUDA.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaTemplate.cpp
  test/SemaCUDA/function-template-overload.cu

Index: test/SemaCUDA/function-template-overload.cu
===
--- test/SemaCUDA/function-template-overload.cu
+++ test/SemaCUDA/function-template-overload.cu
@@ -31,7 +31,8 @@
 template  <> __host__ HType overload_h_d(long a); // OK. instantiates H
 
 
-// Can't overload HD template with H or D template, though functions are OK.
+// Can't overload HD template with H or D template, though
+// non-template functions are OK.
 template  __host__ __device__ HDType overload_hd(T a) { return HDType(); }
 // expected-note@-1 {{previous declaration is here}}
 // expected-note@-2 2 {{candidate template ignored: could not match 'HDType' against 'HType'}}
@@ -56,24 +57,54 @@
 template  __host__ __device__ HDType overload_h_d2(T a) { return HDType(); }
 template  __device__ DType overload_h_d2(T1 a) { T1 x; T2 y; return DType(); }
 
+// constexpr functions are implicitly HD, but explicit
+// instantiation/specialization must use target attributes as written.
+template  constexpr T overload_ce_implicit_hd(T a) { return a+1; }
+// expected-note@-1 3 {{candidate template ignored: target attributes do not match}}
+
+// These will not match the template.
+template __host__ __device__ int overload_ce_implicit_hd(int a);
+// expected-error@-1 {{explicit instantiation of 'overload_ce_implicit_hd' does not refer to a function template, variable template, member function, member class, or static data member}}
+template <> __host__ __device__ long overload_ce_implicit_hd(long a);
+// expected-error@-1 {{no function template matches function template specialization 'overload_ce_implicit_hd'}}
+template <> __host__ __device__ constexpr long overload_ce_implicit_hd(long a);
+// expected-error@-1 {{no function template matches function template specialization 'overload_ce_implicit_hd'}}
+
+// These should work, because template matching ignores implicit HD
+// attributes compiler gives to constexpr functions/templates so
+// 'overload_ce_implicit_hd' template will match __host__ functions
+// only.
+template __host__ int overload_ce_implicit_hd(int a);
+template <> __host__ long overload_ce_implicit_hd(long a);
+
+template float overload_ce_implicit_hd(float a);
+template <> float* overload_ce_implicit_hd(float *a);
+template <> constexpr double overload_ce_implicit_hd(double a) { return a + 3.0; };
+
 __host__ void hf() {
   overload_hd(13);
+  overload_ce_implicit_hd('h');// Implicitly instantiated
+  overload_ce_implicit_hd(1.0f);   // Explicitly instantiated
+  overload_ce_implicit_hd(2.0);// Explicitly specialized
 
   HType h = overload_h_d(10);
   HType h2i = overload_h_d2(11);
   HType h2ii = overload_h_d2(12);
 
   // These should be implicitly instantiated from __host__ template returning HType.
-  DType d = overload_h_d(20); // expected-error {{no viable conversion from 'HType' to 'DType'}}
-  DType d2i = overload_h_d2(21); // expected-error {{no viable conversion from 'HType' to 'DType'}}
+  DType d = overload_h_d(20);  // expected-error {{no viable conversion from 'HType' to 'DType'}}
+  DType d2i = overload_h_d2(21);  // expected-error {{no viable conversion from 'HType' to 'DType'}}
   DType d2ii = overload_h_d2(22); // expected-error {{no viable conversion from 'HType' to 'DType'}}
 }
 __device__ void df() {
   overload_hd(23);
+  overload_ce_implicit_hd('d');// Implicitly instantiated
+  overload_ce_implicit_hd(1.0f);   // Explicitly instantiated
+  overload_ce_implicit_hd(2.0);// Explicitly specialized
 
   // These should be implicitly instantiated from __device__ template returning DType.
-  HType h = overload_h_d(10); // expected-error {{no viable conversion from 'DType' to 'HType'}}
-  HType h2i = overload_h_d2(11); // expected-error {{no viable conversion from 'DType' to 'HType'}}
+  HType h = overload_h_d(10);  // expected-error {{no viable conversion from 'DType' to 'HType'}}
+  HType h2i = overload_h_d2(11);  // expected-error {{no viable conversion from 'DType' to 'HType'}}
   HType h2ii = overload_h_d2(12); // expected-error {{no viable conversion from 'DType' to 'HType'}}
 
   DType d = overload_h_d(20);
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -7049,7 +7049,9 @@
   // target attributes into account, we perform target match check
   // here and reject candidates that have different target.
   if (LangOpts.CUDA &&
-  IdentifyCUDATarget(Specialization) != IdentifyCUDATarget(FD)) {
+  IdentifyCUDATarget(Specialization,
+

[PATCH] D25845: [CUDA] Ignore implicit target attributes during function template instantiation.

2016-12-07 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: lib/Sema/SemaCUDA.cpp:99
+  if (!D->hasAttrs())
+return false;
+  for (Attr *Attribute : D->getAttrs()) {

jlebar wrote:
> Is this early return necessary?
Yes. Otherwise D->getAttrs() will trigger assert(hasAttrs) if we don't have any 
attributes.



Comment at: lib/Sema/SemaCUDA.cpp:107
+  }
+  return false;
+}

jlebar wrote:
> Could we write this function as
> 
>   return llvm::any_of(D->getAttrs(), [&](Attr *Attribute) {
> return isa(Attribute) && (!IgnoreImplicitAttr || 
> !Attribute->isImplicit()) });
Done.



Comment at: lib/Sema/SemaCUDA.cpp:896
+  // needed to ensure that FD and its template have the same
+  // effective target.
+  if (CUDAGlobalAttr *Attr = OldFD->getAttr()) {

jlebar wrote:
> This comment is confusing because this function's implementation doesn't have 
> anything to do with templates, but the first sentence says we're copying from 
> a template to "FD".
> 
> In addition to cleaning this up, maybe we should move the comment into Sema.h?
I've changed second argument type to `const FunctionTemplateDecl*` to reflect 
my intent a bit better.
Moved the comment to Sema.h.



Comment at: lib/Sema/SemaTemplate.cpp:7048
   // target attributes into account, we perform target match check
   // here and reject candidates that have different target.
   if (LangOpts.CUDA &&

jlebar wrote:
> Missing some articles:
> 
>   Target attributes are part of the cuda function signature, so the deduced 
> template's cuda target must match XXX [1].  Given that regular template 
> deduction [2] does not take target attributes into account, we reject 
> candidates here that have a different target.
> 
> [1] I am not sure what XXX should be.  The deduced template's cuda target 
> must match what, exactly?
> 
> [2] What is "regular template deduction"?
[1] it must match the target of its template.
[2] "C++ template deduction"
Rephrased the comment based on  IRL conversation w/ jlebar@.



Comment at: lib/Sema/SemaTemplate.cpp:7173
+  if (LangOpts.CUDA)
+inheritCUDATargetAttrs(FD, Specialization);
+

jlebar wrote:
> Isn't this backwards?  The function is `to, from`?  If this is a bug, can we 
> add a test to catch this?
The arguments have different types now, one of them const&, so it should be 
unambiguous what's input and what's output. 
As for order of inputs/outputs, my mental model is `result=input` as in 
memcpy(dest, src). Style guide does not seem to say anything on order of 
input/output arguments.


https://reviews.llvm.org/D25845



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


  1   2   >