[PATCH] D95925: [clangd] Detect rename conflicits within enclosing scope

2021-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:333
+  // not invalidated.
+  DynTypedNodeList Parents(DynTypedNode::create(RenamedDecl));
+  auto GetSingleParent = [&](DynTypedNode Node) -> const DynTypedNode * {

If the intention is for storage, maybe call it Storage.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:334
+  DynTypedNodeList Parents(DynTypedNode::create(RenamedDecl));
+  auto GetSingleParent = [&](DynTypedNode Node) -> const DynTypedNode * {
+Parents = Ctx.getParents(Node);

`const DynTypedNode &`



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:362
+  for (const auto *Node : CS->children())
+return CheckDeclStmt(dyn_cast(Node), Name);
+return nullptr;

I think we need to iterate *all* children, rather than the first one. looks 
like our testcase doesn't cover this, maybe add one.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:372
+
+  // CompoundStmt is the most common enclosing scope. In the simplest case we
+  // just iterate through sibling DeclStmts and check for collisions.

 CompoundStmt is the most common enclosing scope for function-local symbols.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:378
+const auto *ScopeParent =
+GetSingleParent(DynTypedNode::create(*EnclosingCS));
+// CompoundStmt may be found within if/while/for. In these cases, rename 
can

maybe just `GetSingleParent(Parent)`, rather than creating a new DynTypeNode.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:390
+  if (const auto *Result =
+  CheckDeclStmt(dyn_cast(For->getInit()), NewName))
+return Result;

be careful about nullptr here, the init-statement could be a nullptr, which 
will trigger a crash in dyn_cast, thinking about the case below:

```
for (; ; ;) {
  int var; 
}
```

use `dyn_cast_or_null`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95925/new/

https://reviews.llvm.org/D95925

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


[PATCH] D95915: [clang][driver] Only warn once about invalid -stdlib value

2021-02-03 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In D95915#2541132 , @tbaeder wrote:

> That's what I was looking at right now as well, since using 
> `std::call_once()` already means the methods can't be `const` anymore anyway. 
> Might as well just cache the value.

You can make the caching members `mutable`, IIRC that's a common pattern in 
Clang code.

> It is still slightly ugly with the current code in that subclasses can 
> override them and then the caching is gone.

True, but not really of concern since their implementation is usually a 
constant value and not emitting warnings.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95915/new/

https://reviews.llvm.org/D95915

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


[PATCH] D95915: [clang][driver] Only warn once about invalid -stdlib value

2021-02-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D95915#2541129 , @Hahnfeld wrote:

> My proposal would be to cache the return value of the three routines in 
> `ToolChain`. This has the advantage that the values get parsed only once and 
> there is at most one warning. I don't know how this plays with 
> parallelization efforts, but I don't think we should worry about this right 
> now, given the current code.

That's what I was looking at right now as well, since using `std::call_once()` 
already means the methods can't be `const` anymore anyway. Might as well just 
cache the value. It is still slightly ugly with the current code in that 
subclasses can override them and then the caching is gone.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95915/new/

https://reviews.llvm.org/D95915

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


[clang] 3b9de99 - Give this test a target triple.

2021-02-03 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2021-02-03T23:38:52-08:00
New Revision: 3b9de993c9dffd0941ad79c80a2cb7785bc63f03

URL: 
https://github.com/llvm/llvm-project/commit/3b9de993c9dffd0941ad79c80a2cb7785bc63f03
DIFF: 
https://github.com/llvm/llvm-project/commit/3b9de993c9dffd0941ad79c80a2cb7785bc63f03.diff

LOG: Give this test a target triple.

Added: 


Modified: 
clang/test/CodeGenCXX/instantiate-init.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/instantiate-init.cpp 
b/clang/test/CodeGenCXX/instantiate-init.cpp
index dd8a1a13bdf0..d303938c0984 100644
--- a/clang/test/CodeGenCXX/instantiate-init.cpp
+++ b/clang/test/CodeGenCXX/instantiate-init.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++14 %s -emit-llvm -o - | FileCheck %s
-// RUN: %clang_cc1 -std=c++17 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++14 %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -std=c++17 %s -emit-llvm -o - | 
FileCheck %s
 
 namespace std {
   template class initializer_list {



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


[clang] cde8d2f - Fix miscompile when performing template instantiation of non-dependent

2021-02-03 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2021-02-03T23:38:02-08:00
New Revision: cde8d2fddbff55cae520d90f47f6faf124d3f953

URL: 
https://github.com/llvm/llvm-project/commit/cde8d2fddbff55cae520d90f47f6faf124d3f953
DIFF: 
https://github.com/llvm/llvm-project/commit/cde8d2fddbff55cae520d90f47f6faf124d3f953.diff

LOG: Fix miscompile when performing template instantiation of non-dependent
doubly-nested implicit CXXConstructExprs.

Ensure that we transform the parameter initializer using
TransformInitializer rather than TransformExpr so that we properly strip
down and rebuild the initialization, including any necessary
CXXBindTemporaryExprs. Otherwise we can end up forgetting to destroy
temporary objects used to construct a constructor parameter.

Added: 
clang/test/CodeGenCXX/instantiate-init.cpp

Modified: 
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 1bff267cffc8..1da28a3bb94c 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12241,7 +12241,8 @@ 
TreeTransform::TransformCXXConstructExpr(CXXConstructExpr *E) {
 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1 
&&
(!getDerived().DropCallArgument(E->getArg(0))) &&
!E->isListInitialization()))
-return getDerived().TransformExpr(E->getArg(0));
+return getDerived().TransformInitializer(E->getArg(0),
+ /*DirectInit*/ false);
 
   TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
 

diff  --git a/clang/test/CodeGenCXX/instantiate-init.cpp 
b/clang/test/CodeGenCXX/instantiate-init.cpp
new file mode 100644
index ..dd8a1a13bdf0
--- /dev/null
+++ b/clang/test/CodeGenCXX/instantiate-init.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -std=c++14 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 %s -emit-llvm -o - | FileCheck %s
+
+namespace std {
+  template class initializer_list {
+const T *data;
+__SIZE_TYPE__ size;
+
+  public:
+initializer_list();
+  };
+}
+
+namespace ParenBraceInitList {
+  struct Vector {
+Vector(std::initializer_list);
+~Vector();
+  };
+
+  struct Base { Base(Vector) {} };
+
+  // CHECK: define {{.*}}18ParenBraceInitList1fILi0EE
+  template void f() {
+// CHECK: call {{.*}}18ParenBraceInitList6VectorC1
+// CHECK: call {{.*}}18ParenBraceInitList6VectorD1
+Base({0});
+  }
+  template void f<0>();
+}



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


[PATCH] D95915: [clang][driver] Only warn once about invalid -stdlib value

2021-02-03 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

My proposal would be to cache the return value of the three routines in 
`ToolChain`. This has the advantage that the values get parsed only once and 
there is at most one warning. I don't know how this plays with parallelization 
efforts, but I don't think we should worry about this right now, given the 
current code.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95915/new/

https://reviews.llvm.org/D95915

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


[PATCH] D95915: [clang][driver] Only warn once about invalid -stdlib value

2021-02-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

In D95915#2539483 , @jdoerfert wrote:

> Also, now you don't warn for different missing runtimes, which seems odd.

What do you mean? Is the value returned from `GetRuntimeLibType()` ever going 
to change?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95915/new/

https://reviews.llvm.org/D95915

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


[PATCH] D96000: Don't emit coverage mapping for excluded functions

2021-02-03 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: davidxl, vsk.
Herald added a subscriber: wenlei.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When a function or a file is excluded using -fprofile-list= option,
don't emit coverage mapping as doing so confuses users since those
functions would always have zero count. This also reduces the binary
size considerably in cases where only a few functions or files are
being instrumented.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96000

Files:
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/CodeGen/profile-filter.c


Index: clang/test/CodeGen/profile-filter.c
===
--- clang/test/CodeGen/profile-filter.c
+++ clang/test/CodeGen/profile-filter.c
@@ -1,22 +1,31 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm %s 
-o - | FileCheck %s
 
 // RUN: echo "fun:test1" > %t-func.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-func.list 
-emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-fprofile-list=%t-func.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FUNC
 
 // RUN: echo "src:%s" | sed -e 's/\\//g' > %t-file.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-file.list 
-emit-llvm %s -o - | FileCheck %s --check-prefix=FILE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-fprofile-list=%t-file.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FILE
 
 // RUN: echo -e "[clang]\nfun:test1\n[llvm]\nfun:test2" > %t-section.list
 // RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t-section.list 
-emit-llvm %s -o - | FileCheck %s --check-prefix=SECTION
 
 // RUN: echo -e "fun:test*\n!fun:test1" > %t-exclude.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-exclude.list 
-emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-fprofile-list=%t-exclude.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=EXCLUDE
 
 // RUN: echo "!fun:test1" > %t-exclude-only.list
-// RUN: %clang_cc1 -fprofile-instrument=clang 
-fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=EXCLUDE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s 
--check-prefix=EXCLUDE
 
 unsigned i;
 
+// CHECK: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, 
i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// CHECK: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, 
i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// FUNC: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, 
i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// FUNC-NOT: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, 
i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// FILE: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, 
i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// FILE: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, 
i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// EXCLUDE: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, 
i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// EXCLUDE-NOT: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ 
i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+
 // CHECK-NOT: noprofile
 // CHECK: @test1
 // FUNC-NOT: noprofile
Index: clang/lib/CodeGen/CodeGenPGO.cpp
===
--- clang/lib/CodeGen/CodeGenPGO.cpp
+++ clang/lib/CodeGen/CodeGenPGO.cpp
@@ -811,10 +811,10 @@
   if (isa(D) && GD.getDtorType() != Dtor_Base)
 return;
 
+  CGM.ClearUnusedCoverageMapping(D);
   if (Fn->hasFnAttribute(llvm::Attribute::NoProfile))
 return;
 
-  CGM.ClearUnusedCoverageMapping(D);
   setFuncName(Fn);
 
   mapRegionCounters(D);


Index: clang/test/CodeGen/profile-filter.c
===
--- clang/test/CodeGen/profile-filter.c
+++ clang/test/CodeGen/profile-filter.c
@@ -1,22 +1,31 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm %s -o - | FileCheck %s
 
 // RUN: echo "fun:test1" > %t-func.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-func.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 

[PATCH] D69322: [hip][cuda] Enable extended lambda support on Windows.

2021-02-03 Thread Michael Liao via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa2fdf9d4d734: [hip][cuda] Enable extended lambda support on 
Windows. (authored by hliao).

Changed prior to commit:
  https://reviews.llvm.org/D69322?vs=320679=321316#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69322/new/

https://reviews.llvm.org/D69322

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/MangleNumberingContext.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/CXXABI.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ItaniumCXXABI.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGenCUDA/ms-linker-options.cu
  clang/test/CodeGenCUDA/unnamed-types.cu

Index: clang/test/CodeGenCUDA/unnamed-types.cu
===
--- clang/test/CodeGenCUDA/unnamed-types.cu
+++ clang/test/CodeGenCUDA/unnamed-types.cu
@@ -1,12 +1,17 @@
 // RUN: %clang_cc1 -std=c++11 -x hip -triple x86_64-linux-gnu -aux-triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST
+// RUN: %clang_cc1 -std=c++11 -x hip -triple x86_64-pc-windows-msvc -aux-triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s --check-prefix=MSVC
 // RUN: %clang_cc1 -std=c++11 -x hip -triple amdgcn-amd-amdhsa -fcuda-is-device -emit-llvm %s -o - | FileCheck %s --check-prefix=DEVICE
 
 #include "Inputs/cuda.h"
 
 // HOST: @0 = private unnamed_addr constant [43 x i8] c"_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_\00", align 1
+// HOST: @1 = private unnamed_addr constant [60 x i8] c"_Z2k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_\00", align 1
+// Check that, on MSVC, the same device kernel mangling name is generated.
+// MSVC: @0 = private unnamed_addr constant [43 x i8] c"_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_\00", align 1
+// MSVC: @1 = private unnamed_addr constant [60 x i8] c"_Z2k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_\00", align 1
 
 __device__ float d0(float x) {
-  return [](float x) { return x + 2.f; }(x);
+  return [](float x) { return x + 1.f; }(x);
 }
 
 __device__ float d1(float x) {
@@ -14,11 +19,21 @@
 }
 
 // DEVICE: amdgpu_kernel void @_Z2k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_(
+// DEVICE: define internal float @_ZZZ2f1PfENKUlS_E_clES_ENKUlfE_clEf(
 template 
 __global__ void k0(float *p, F f) {
   p[0] = f(p[0]) + d0(p[1]) + d1(p[2]);
 }
 
+// DEVICE: amdgpu_kernel void @_Z2k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_(
+// DEVICE: define internal float @_ZZ2f1PfENKUlfE_clEf(
+// DEVICE: define internal float @_ZZ2f1PfENKUlffE_clEff(
+// DEVICE: define internal float @_ZZ2f1PfENKUlfE0_clEf(
+template 
+__global__ void k1(float *p, F0 f0, F1 f1, F2 f2) {
+  p[0] = f0(p[0]) + f1(p[1], p[2]) + f2(p[3]);
+}
+
 void f0(float *p) {
   [](float *p) {
 *p = 1.f;
@@ -29,11 +44,17 @@
 // linkages are still required to keep the original `internal` linkage.
 
 // HOST: define internal void @_ZZ2f1PfENKUlS_E_clES_(
-// DEVICE: define internal float @_ZZZ2f1PfENKUlS_E_clES_ENKUlfE_clEf(
 void f1(float *p) {
   [](float *p) {
-k0<<<1,1>>>(p, [] __device__ (float x) { return x + 1.f; });
+k0<<<1,1>>>(p, [] __device__ (float x) { return x + 3.f; });
   }(p);
+  k1<<<1,1>>>(p,
+  [] __device__ (float x) { return x + 4.f; },
+  [] __device__ (float x, float y) { return x * y; },
+  [] __device__ (float x) { return x + 5.f; });
 }
 // HOST: @__hip_register_globals
 // HOST: __hipRegisterFunction{{.*}}@_Z17__device_stub__k0IZZ2f1PfENKUlS0_E_clES0_EUlfE_EvS0_T_{{.*}}@0
+// HOST: __hipRegisterFunction{{.*}}@_Z17__device_stub__k1IZ2f1PfEUlfE_Z2f1S0_EUlffE_Z2f1S0_EUlfE0_EvS0_T_T0_T1_{{.*}}@1
+// MSVC: __hipRegisterFunction{{.*}}@"??$k0@V@?0???R1?0??f1@@YAXPEAM@Z@QEBA@0@Z@@@YAXPEAMV@?0???R0?0??f1@@YAX0@Z@QEBA@0@Z@@Z{{.*}}@0
+// MSVC: __hipRegisterFunction{{.*}}@"??$k1@V@?0??f1@@YAXPEAM@Z@V@?0??2@YAX0@Z@V@?0??2@YAX0@Z@@@YAXPEAMV@?0??f1@@YAX0@Z@V@?0??1@YAX0@Z@V@?0??1@YAX0@Z@@Z{{.*}}@1
Index: clang/test/CodeGenCUDA/ms-linker-options.cu
===
--- clang/test/CodeGenCUDA/ms-linker-options.cu
+++ clang/test/CodeGenCUDA/ms-linker-options.cu
@@ -2,12 +2,12 @@
 // RUN:   -fno-autolink -triple amdgcn-amd-amdhsa \
 // RUN:   | FileCheck -check-prefix=DEV %s
 // RUN: %clang_cc1 -emit-llvm -o - -fms-extensions -x hip %s -triple \
-// RUN:x86_64-pc-windows-msvc | FileCheck -check-prefix=HOST %s
+// RUN:x86_64-pc-windows-msvc -aux-triple amdgcn | FileCheck -check-prefix=HOST %s
 // RUN: %clang_cc1 -emit-llvm 

[clang] a2fdf9d - [hip][cuda] Enable extended lambda support on Windows.

2021-02-03 Thread Michael Liao via cfe-commits

Author: Michael Liao
Date: 2021-02-04T01:38:29-05:00
New Revision: a2fdf9d4d734732a6fa9288f1ffdf12bf8618123

URL: 
https://github.com/llvm/llvm-project/commit/a2fdf9d4d734732a6fa9288f1ffdf12bf8618123
DIFF: 
https://github.com/llvm/llvm-project/commit/a2fdf9d4d734732a6fa9288f1ffdf12bf8618123.diff

LOG: [hip][cuda] Enable extended lambda support on Windows.

- On Windows, extended lambda has extra issues due to the numbering
  schemes are different between the host compilation (Microsoft C++ ABI)
  and the device compilation (Itanium C++ ABI. Additional device side
  lambda number is required per lambda for the host compilation to
  correctly mangle the device-side lambda name.
- A hybrid numbering context `MSHIPNumberingContext` is introduced to
  number a lambda for both host- and device-compilations.

Reviewed By: rnk

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/Mangle.h
clang/include/clang/AST/MangleNumberingContext.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/CXXABI.h
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/ItaniumCXXABI.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftCXXABI.cpp
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/CodeGenCUDA/ms-linker-options.cu
clang/test/CodeGenCUDA/unnamed-types.cu

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index ce47d54e44b0..ae69a68608b7 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -538,6 +538,9 @@ class ASTContext : public RefCountedBase {
   /// need them (like static local vars).
   llvm::MapVector MangleNumbers;
   llvm::MapVector StaticLocalNumbers;
+  /// Mapping the associated device lambda mangling number if present.
+  mutable llvm::DenseMap
+  DeviceLambdaManglingNumbers;
 
   /// Mapping that stores parameterIndex values for ParmVarDecls when
   /// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex.

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index e32101bb2276..89006b1cfa7f 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1735,6 +1735,12 @@ class CXXRecordDecl : public RecordDecl {
 getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage;
   }
 
+  /// Set the device side mangling number.
+  void setDeviceLambdaManglingNumber(unsigned Num) const;
+
+  /// Retrieve the device side mangling number.
+  unsigned getDeviceLambdaManglingNumber() const;
+
   /// Returns the inheritance model used for this record.
   MSInheritanceModel getMSInheritanceModel() const;
 

diff  --git a/clang/include/clang/AST/Mangle.h 
b/clang/include/clang/AST/Mangle.h
index 6506ad542cc3..13b436cdca3e 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -107,6 +107,9 @@ class MangleContext {
   virtual bool shouldMangleCXXName(const NamedDecl *D) = 0;
   virtual bool shouldMangleStringLiteral(const StringLiteral *SL) = 0;
 
+  virtual bool isDeviceMangleContext() const { return false; }
+  virtual void setDeviceMangleContext(bool) {}
+
   // FIXME: consider replacing raw_ostream & with something like SmallString &.
   void mangleName(GlobalDecl GD, raw_ostream &);
   virtual void mangleCXXName(GlobalDecl GD, raw_ostream &) = 0;

diff  --git a/clang/include/clang/AST/MangleNumberingContext.h 
b/clang/include/clang/AST/MangleNumberingContext.h
index f1ca6a05dbaf..eb33759682d6 100644
--- a/clang/include/clang/AST/MangleNumberingContext.h
+++ b/clang/include/clang/AST/MangleNumberingContext.h
@@ -52,6 +52,11 @@ class MangleNumberingContext {
   /// this context.
   virtual unsigned getManglingNumber(const TagDecl *TD,
  unsigned MSLocalManglingNumber) = 0;
+
+  /// Retrieve the mangling number of a new lambda expression with the
+  /// given call operator within the device context. No device number is
+  /// assigned if there's no device numbering context is associated.
+  virtual unsigned getDeviceManglingNumber(const CXXMethodDecl *) { return 0; }
 };
 
 } // end namespace clang

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2fca81d25345..1c4942a37112 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6558,7 +6558,7 @@ class Sema final {
   /// Number lambda for linkage purposes if necessary.
   void handleLambdaNumbering(
   CXXRecordDecl *Class, CXXMethodDecl *Method,
-  Optional> Mangling = None);
+  Optional> Mangling = None);
 
   

[PATCH] D95989: [ASTReader] Always rebuild a cached module that has errors

2021-02-03 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa2c1054c303f: [ASTReader] Always rebuild a cached module 
that has errors (authored by bnbarham, committed by akyrtzi).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95989/new/

https://reviews.llvm.org/D95989

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/Inputs/error.h
  clang/test/Modules/Inputs/error/error.h
  clang/test/Modules/Inputs/error/module.modulemap
  clang/test/Modules/Inputs/module.map
  clang/test/Modules/load-module-with-errors.m

Index: clang/test/Modules/load-module-with-errors.m
===
--- clang/test/Modules/load-module-with-errors.m
+++ clang/test/Modules/load-module-with-errors.m
@@ -1,25 +1,68 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
+// RUN: mkdir %t/prebuilt
 
-// Write out a module with errors make sure it can be read
 // RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -emit-module \
-// RUN:   -fmodule-name=error %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -I %S/Inputs \
-// RUN:   -fimplicit-module-maps -ast-print %s | FileCheck %s
+// RUN:   -fmodule-name=error -o %t/prebuilt/error.pcm \
+// RUN:   -x objective-c -emit-module %S/Inputs/error/module.modulemap
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodule-file=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodule-file=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// Shouldn't build the cached module (that has errors) when not allowing errors
+// RUN: not %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c %s
+// RUN: find %t -name "error-*.pcm" | not grep error
+
+// Should build the cached module when allowing errors
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
+// RUN: find %t -name "error-*.pcm" | grep error
+
+// Make sure there is still an error after the module is already in the cache
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
+
+// Should rebuild the cached module if it had an error (if it wasn't rebuilt
+// the verify would fail as it would be the PCH error instead)
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
 
 // allow-pcm-with-compiler-errors should also allow errors in PCH
-// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x c++ -emit-pch \
-// RUN:   -o %t/check.pch %S/Inputs/error.h
+// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x objective-c \
+// RUN:   -o %t/check.pch -emit-pch %S/Inputs/error/error.h
 
-@import error;
+// pcherror-error@* {{PCH file contains compiler errors}}
+@import error; // expected-error {{could not build module 'error'}}
 
-void test(id x) {
+void test(Error *x) {
   [x method];
 }
 
 // CHECK: @interface Error
 // CHECK-NEXT: - (int)method;
+// CHECK-NEXT: - (id)method2;
 // CHECK-NEXT: @end
-// CHECK: void test(id x)
+// CHECK: void test(Error *x)
Index: clang/test/Modules/Inputs/module.map
===
--- clang/test/Modules/Inputs/module.map
+++ clang/test/Modules/Inputs/module.map
@@ -483,4 +483,3 @@
   header "template-nontrivial1.h"
   export *
 }
-module error { header "error.h" }
Index: clang/test/Modules/Inputs/error/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/error/module.modulemap
@@ -0,0 +1,3 @@
+module error {
+  header 

[clang] a2c1054 - [ASTReader] Always rebuild a cached module that has errors

2021-02-03 Thread Argyrios Kyrtzidis via cfe-commits

Author: Ben Barham
Date: 2021-02-03T22:06:46-08:00
New Revision: a2c1054c303f20be006e9ef20739dbb88bd9ae02

URL: 
https://github.com/llvm/llvm-project/commit/a2c1054c303f20be006e9ef20739dbb88bd9ae02
DIFF: 
https://github.com/llvm/llvm-project/commit/a2c1054c303f20be006e9ef20739dbb88bd9ae02.diff

LOG: [ASTReader] Always rebuild a cached module that has errors

A module in the cache with an error should just be a cache miss. If
allowing errors (with -fallow-pcm-with-compiler-errors), a rebuild is
needed so that the appropriate diagnostics are output and in case search
paths have changed. If not allowing errors, the module was built
*allowing* errors and thus should be rebuilt regardless.

Reviewed By: akyrtzi

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

Added: 
clang/test/Modules/Inputs/error/error.h
clang/test/Modules/Inputs/error/module.modulemap

Modified: 
clang/lib/Serialization/ASTReader.cpp
clang/test/Modules/Inputs/module.map
clang/test/Modules/load-module-with-errors.m

Removed: 
clang/test/Modules/Inputs/error.h



diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 85add2e2740b..99579f7956ed 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2750,9 +2750,15 @@ ASTReader::ReadControlBlock(ModuleFile ,
   }
 
   bool hasErrors = Record[6];
-  if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) {
-Diag(diag::err_pch_with_compiler_errors);
-return HadErrors;
+  if (hasErrors && !DisableValidation) {
+// Always rebuild modules from the cache on an error
+if (F.Kind == MK_ImplicitModule)
+  return OutOfDate;
+
+if (!AllowASTWithCompilerErrors) {
+  Diag(diag::err_pch_with_compiler_errors);
+  return HadErrors;
+}
   }
   if (hasErrors) {
 Diags.ErrorOccurred = true;

diff  --git a/clang/test/Modules/Inputs/error.h 
b/clang/test/Modules/Inputs/error.h
deleted file mode 100644
index 7201003d28c3..
--- a/clang/test/Modules/Inputs/error.h
+++ /dev/null
@@ -1,8 +0,0 @@
-@import undefined
-
-@interface Error
-- (int)method;
-undefined
-@end
-
-undefined

diff  --git a/clang/test/Modules/Inputs/error/error.h 
b/clang/test/Modules/Inputs/error/error.h
new file mode 100644
index ..1b27b21dfd63
--- /dev/null
+++ b/clang/test/Modules/Inputs/error/error.h
@@ -0,0 +1,9 @@
+@import undefined;
+
+@interface Error
+- (int)method;
+- (undefined)method2;
+undefined;
+@end
+
+undefined

diff  --git a/clang/test/Modules/Inputs/error/module.modulemap 
b/clang/test/Modules/Inputs/error/module.modulemap
new file mode 100644
index ..e18239af113b
--- /dev/null
+++ b/clang/test/Modules/Inputs/error/module.modulemap
@@ -0,0 +1,3 @@
+module error {
+  header "error.h"
+}

diff  --git a/clang/test/Modules/Inputs/module.map 
b/clang/test/Modules/Inputs/module.map
index 2aa0733537bc..e7cb4b27bc08 100644
--- a/clang/test/Modules/Inputs/module.map
+++ b/clang/test/Modules/Inputs/module.map
@@ -483,4 +483,3 @@ module template_nontrivial1 {
   header "template-nontrivial1.h"
   export *
 }
-module error { header "error.h" }

diff  --git a/clang/test/Modules/load-module-with-errors.m 
b/clang/test/Modules/load-module-with-errors.m
index 64575482d091..3dceb545ad9c 100644
--- a/clang/test/Modules/load-module-with-errors.m
+++ b/clang/test/Modules/load-module-with-errors.m
@@ -1,25 +1,68 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
+// RUN: mkdir %t/prebuilt
 
-// Write out a module with errors make sure it can be read
 // RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -emit-module \
-// RUN:   -fmodule-name=error %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -I %S/Inputs \
-// RUN:   -fimplicit-module-maps -ast-print %s | FileCheck %s
+// RUN:   -fmodule-name=error -o %t/prebuilt/error.pcm \
+// RUN:   -x objective-c -emit-module %S/Inputs/error/module.modulemap
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// 

[PATCH] D95989: [ASTReader] Always rebuild a cached module that has errors

2021-02-03 Thread Ben Barham via Phabricator via cfe-commits
bnbarham updated this revision to Diff 321308.
bnbarham set the repository for this revision to rG LLVM Github Monorepo.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95989/new/

https://reviews.llvm.org/D95989

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/Inputs/error.h
  clang/test/Modules/Inputs/error/error.h
  clang/test/Modules/Inputs/error/module.modulemap
  clang/test/Modules/Inputs/module.map
  clang/test/Modules/load-module-with-errors.m

Index: clang/test/Modules/load-module-with-errors.m
===
--- clang/test/Modules/load-module-with-errors.m
+++ clang/test/Modules/load-module-with-errors.m
@@ -1,25 +1,68 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
+// RUN: mkdir %t/prebuilt
 
-// Write out a module with errors make sure it can be read
 // RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -emit-module \
-// RUN:   -fmodule-name=error %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -I %S/Inputs \
-// RUN:   -fimplicit-module-maps -ast-print %s | FileCheck %s
+// RUN:   -fmodule-name=error -o %t/prebuilt/error.pcm \
+// RUN:   -x objective-c -emit-module %S/Inputs/error/module.modulemap
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodule-file=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodule-file=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// Shouldn't build the cached module (that has errors) when not allowing errors
+// RUN: not %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c %s
+// RUN: find %t -name "error-*.pcm" | not grep error
+
+// Should build the cached module when allowing errors
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
+// RUN: find %t -name "error-*.pcm" | grep error
+
+// Make sure there is still an error after the module is already in the cache
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
+
+// Should rebuild the cached module if it had an error (if it wasn't rebuilt
+// the verify would fail as it would be the PCH error instead)
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
 
 // allow-pcm-with-compiler-errors should also allow errors in PCH
-// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x c++ -emit-pch \
-// RUN:   -o %t/check.pch %S/Inputs/error.h
+// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x objective-c \
+// RUN:   -o %t/check.pch -emit-pch %S/Inputs/error/error.h
 
-@import error;
+// pcherror-error@* {{PCH file contains compiler errors}}
+@import error; // expected-error {{could not build module 'error'}}
 
-void test(id x) {
+void test(Error *x) {
   [x method];
 }
 
 // CHECK: @interface Error
 // CHECK-NEXT: - (int)method;
+// CHECK-NEXT: - (id)method2;
 // CHECK-NEXT: @end
-// CHECK: void test(id x)
+// CHECK: void test(Error *x)
Index: clang/test/Modules/Inputs/module.map
===
--- clang/test/Modules/Inputs/module.map
+++ clang/test/Modules/Inputs/module.map
@@ -483,4 +483,3 @@
   header "template-nontrivial1.h"
   export *
 }
-module error { header "error.h" }
Index: clang/test/Modules/Inputs/error/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/error/module.modulemap
@@ -0,0 +1,3 @@
+module error {
+  header "error.h"
+}
Index: clang/test/Modules/Inputs/error/error.h
===
--- /dev/null
+++ 

[PATCH] D95989: [ASTReader] Always rebuild a cached module that has errors

2021-02-03 Thread Ben Barham via Phabricator via cfe-commits
bnbarham updated this revision to Diff 321305.
bnbarham added a comment.

Added a couple semi-colons to the test file


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95989/new/

https://reviews.llvm.org/D95989

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/Inputs/error.h
  clang/test/Modules/Inputs/error/error.h
  clang/test/Modules/Inputs/error/module.modulemap
  clang/test/Modules/Inputs/module.map
  clang/test/Modules/load-module-with-errors.m

Index: clang/test/Modules/load-module-with-errors.m
===
--- clang/test/Modules/load-module-with-errors.m
+++ clang/test/Modules/load-module-with-errors.m
@@ -1,25 +1,68 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
+// RUN: mkdir %t/prebuilt
 
-// Write out a module with errors make sure it can be read
 // RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -emit-module \
-// RUN:   -fmodule-name=error %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -I %S/Inputs \
-// RUN:   -fimplicit-module-maps -ast-print %s | FileCheck %s
+// RUN:   -fmodule-name=error -o %t/prebuilt/error.pcm \
+// RUN:   -x objective-c -emit-module %S/Inputs/error/module.modulemap
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodule-file=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodule-file=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// Shouldn't build the cached module (that has errors) when not allowing errors
+// RUN: not %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c %s
+// RUN: find %t -name "error-*.pcm" | not grep error
+
+// Should build the cached module when allowing errors
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
+// RUN: find %t -name "error-*.pcm" | grep error
+
+// Make sure there is still an error after the module is already in the cache
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
+
+// Should rebuild the cached module if it had an error (if it wasn't rebuilt
+// the verify would fail as it would be the PCH error instead)
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
 
 // allow-pcm-with-compiler-errors should also allow errors in PCH
-// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x c++ -emit-pch \
-// RUN:   -o %t/check.pch %S/Inputs/error.h
+// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x objective-c \
+// RUN:   -o %t/check.pch -emit-pch %S/Inputs/error/error.h
 
-@import error;
+// pcherror-error@* {{PCH file contains compiler errors}}
+@import error; // expected-error {{could not build module 'error'}}
 
-void test(id x) {
+void test(Error *x) {
   [x method];
 }
 
 // CHECK: @interface Error
 // CHECK-NEXT: - (int)method;
+// CHECK-NEXT: - (id)method2;
 // CHECK-NEXT: @end
-// CHECK: void test(id x)
+// CHECK: void test(Error *x)
Index: clang/test/Modules/Inputs/module.map
===
--- clang/test/Modules/Inputs/module.map
+++ clang/test/Modules/Inputs/module.map
@@ -483,4 +483,3 @@
   header "template-nontrivial1.h"
   export *
 }
-module error { header "error.h" }
Index: clang/test/Modules/Inputs/error/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/error/module.modulemap
@@ -0,0 +1,3 @@
+module error {
+  header "error.h"
+}
Index: clang/test/Modules/Inputs/error/error.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/error/error.h
@@ -0,0 

[PATCH] D95910: Fix the guaranteed alignment of memory returned by malloc/new on Darwin

2021-02-03 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaade0ec23b59: Fix the guaranteed alignment of memory 
returned by malloc/new on Darwin (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95910/new/

https://reviews.llvm.org/D95910

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/test/Preprocessor/init-aarch64.c
  clang/test/Preprocessor/init-arm.c


Index: clang/test/Preprocessor/init-arm.c
===
--- clang/test/Preprocessor/init-arm.c
+++ clang/test/Preprocessor/init-arm.c
@@ -196,6 +196,9 @@
 // ARM:#define __arm 1
 // ARM:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=armv7-apple-ios7.0 -x c++ < /dev/null | 
FileCheck -match-full-lines -check-prefix ARM-DARWIN-CXX %s
+// ARM-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -dM -ffreestanding -triple arm-none-none -target-abi 
apcs-gnu -E /dev/null -o - | FileCheck -match-full-lines -check-prefix 
ARM-APCS-GNU %s
 // ARM-APCS-GNU: #define __INTPTR_TYPE__ int
 // ARM-APCS-GNU: #define __PTRDIFF_TYPE__ int
Index: clang/test/Preprocessor/init-aarch64.c
===
--- clang/test/Preprocessor/init-aarch64.c
+++ clang/test/Preprocessor/init-aarch64.c
@@ -532,6 +532,9 @@
 // AARCH64-DARWIN: #define __WINT_WIDTH__ 32
 // AARCH64-DARWIN: #define __aarch64__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=aarch64-apple-ios7.0 -x c++ < /dev/null | 
FileCheck -match-full-lines -check-prefix AARCH64-DARWIN-CXX %s
+// AARCH64-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-windows-msvc < 
/dev/null | FileCheck -match-full-lines -check-prefix AARCH64-MSVC %s
 
 // AARCH64-MSVC: #define _INTEGRAL_MAX_BITS 64
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -67,9 +67,12 @@
   // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
   // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
   // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
-  // This alignment guarantee also applies to Windows and Android.
+  // This alignment guarantee also applies to Windows and Android. On Darwin,
+  // the alignment is 16 bytes on both 64-bit and 32-bit systems.
   if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
+  else if (T.isOSDarwin())
+NewAlign = 128;
   else
 NewAlign = 0; // Infer from basic type alignment.
   HalfWidth = 16;


Index: clang/test/Preprocessor/init-arm.c
===
--- clang/test/Preprocessor/init-arm.c
+++ clang/test/Preprocessor/init-arm.c
@@ -196,6 +196,9 @@
 // ARM:#define __arm 1
 // ARM:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=armv7-apple-ios7.0 -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix ARM-DARWIN-CXX %s
+// ARM-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -dM -ffreestanding -triple arm-none-none -target-abi apcs-gnu -E /dev/null -o - | FileCheck -match-full-lines -check-prefix ARM-APCS-GNU %s
 // ARM-APCS-GNU: #define __INTPTR_TYPE__ int
 // ARM-APCS-GNU: #define __PTRDIFF_TYPE__ int
Index: clang/test/Preprocessor/init-aarch64.c
===
--- clang/test/Preprocessor/init-aarch64.c
+++ clang/test/Preprocessor/init-aarch64.c
@@ -532,6 +532,9 @@
 // AARCH64-DARWIN: #define __WINT_WIDTH__ 32
 // AARCH64-DARWIN: #define __aarch64__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=aarch64-apple-ios7.0 -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix AARCH64-DARWIN-CXX %s
+// AARCH64-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-windows-msvc < /dev/null | FileCheck -match-full-lines -check-prefix AARCH64-MSVC %s
 
 // AARCH64-MSVC: #define _INTEGRAL_MAX_BITS 64
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -67,9 +67,12 @@
   // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
   // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
   // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
-  // This alignment guarantee also applies to Windows and Android.
+  // This alignment guarantee also applies to Windows and Android. On Darwin,
+  // the alignment is 16 bytes on both 64-bit and 32-bit systems.
   if (T.isGNUEnvironment() || 

[clang] aade0ec - Fix the guaranteed alignment of memory returned by malloc/new on Darwin

2021-02-03 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2021-02-03T19:40:51-08:00
New Revision: aade0ec23b5986a9c478c4093d029a5db8a2c012

URL: 
https://github.com/llvm/llvm-project/commit/aade0ec23b5986a9c478c4093d029a5db8a2c012
DIFF: 
https://github.com/llvm/llvm-project/commit/aade0ec23b5986a9c478c4093d029a5db8a2c012.diff

LOG: Fix the guaranteed alignment of memory returned by malloc/new on Darwin

The guaranteed alignment is 16 bytes on Darwin.

rdar://73431623

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

Added: 


Modified: 
clang/lib/Basic/TargetInfo.cpp
clang/test/Preprocessor/init-aarch64.c
clang/test/Preprocessor/init-arm.c

Removed: 




diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 642ee753d224..dc41357d78b9 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -67,9 +67,12 @@ TargetInfo::TargetInfo(const llvm::Triple ) : 
TargetOpts(), Triple(T) {
   // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
   // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
   // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
-  // This alignment guarantee also applies to Windows and Android.
+  // This alignment guarantee also applies to Windows and Android. On Darwin,
+  // the alignment is 16 bytes on both 64-bit and 32-bit systems.
   if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
+  else if (T.isOSDarwin())
+NewAlign = 128;
   else
 NewAlign = 0; // Infer from basic type alignment.
   HalfWidth = 16;

diff  --git a/clang/test/Preprocessor/init-aarch64.c 
b/clang/test/Preprocessor/init-aarch64.c
index 7f9ae3a5cf5b..3b6f4ddaabde 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -532,6 +532,9 @@
 // AARCH64-DARWIN: #define __WINT_WIDTH__ 32
 // AARCH64-DARWIN: #define __aarch64__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=aarch64-apple-ios7.0 -x c++ < /dev/null | 
FileCheck -match-full-lines -check-prefix AARCH64-DARWIN-CXX %s
+// AARCH64-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-windows-msvc < 
/dev/null | FileCheck -match-full-lines -check-prefix AARCH64-MSVC %s
 
 // AARCH64-MSVC: #define _INTEGRAL_MAX_BITS 64

diff  --git a/clang/test/Preprocessor/init-arm.c 
b/clang/test/Preprocessor/init-arm.c
index 1dff0b994ce0..32eb2c513f8b 100644
--- a/clang/test/Preprocessor/init-arm.c
+++ b/clang/test/Preprocessor/init-arm.c
@@ -196,6 +196,9 @@
 // ARM:#define __arm 1
 // ARM:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=armv7-apple-ios7.0 -x c++ < /dev/null | 
FileCheck -match-full-lines -check-prefix ARM-DARWIN-CXX %s
+// ARM-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -dM -ffreestanding -triple arm-none-none -target-abi 
apcs-gnu -E /dev/null -o - | FileCheck -match-full-lines -check-prefix 
ARM-APCS-GNU %s
 // ARM-APCS-GNU: #define __INTPTR_TYPE__ int
 // ARM-APCS-GNU: #define __PTRDIFF_TYPE__ int



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


[PATCH] D93446: [RISCV] Add vadd with mask and without mask builtin.

2021-02-03 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/test/CodeGen/RISCV/vadd.c:22
+{
+return __builtin_rvv_vadd_vv_i8m1_vl(arg_0, arg_1, arg_2);
+}

Jim wrote:
> Is it necessary with prefix "__builtin_"?
> Refer to 
> https://github.com/riscv/rvv-intrinsic-doc/blob/master/rvv_intrinsic_funcs_vl/06_vector_integer_arithmetic_functions.md.
rvvintrin.h or whatever it's called will define wrappers. Providing things 
under a name that's not prefixed by `__` can cause collisions with existing 
code that's not trying to use these intrinsics, since the names are technically 
available for it to use, though in practice that seems extremely unlikely for 
these names. However, using proper `__`-prefixed names is convention, as is 
using `__builtin_` for anything that's a compiler builtin. This is purely an 
implementation detail that the user should not need to care about unless they 
want to not include the header they're meant to include, at which point we 
provide no guarantees.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93446/new/

https://reviews.llvm.org/D93446

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


[PATCH] D93446: [RISCV] Add vadd with mask and without mask builtin.

2021-02-03 Thread Jim Lin via Phabricator via cfe-commits
Jim added inline comments.



Comment at: clang/test/CodeGen/RISCV/vadd.c:22
+{
+return __builtin_rvv_vadd_vv_i8m1_vl(arg_0, arg_1, arg_2);
+}

Is it necessary with prefix "__builtin_"?
Refer to 
https://github.com/riscv/rvv-intrinsic-doc/blob/master/rvv_intrinsic_funcs_vl/06_vector_integer_arithmetic_functions.md.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93446/new/

https://reviews.llvm.org/D93446

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


[PATCH] D95166: Disable rosegment for old Android versions.

2021-02-03 Thread Dan Albert via Phabricator via cfe-commits
danalbert added a comment.

In D95166#2540705 , @thakis wrote:

> In D95166#2540399 , @danalbert wrote:
>
>>> We've since added -fuse-ld=lld to the three CMAKE_*_FLAGS so I think we're 
>>> likely set on our end.
>>
>> https://reviews.llvm.org/D76452 not being accepted means that Android 
>> toolchains must have LLD installed as `ld`.
>
> If you pass `-fuse-ld=lld` everwhere, that's not needed, right (?)

Yes, but the defaults should work for the NDK.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95166/new/

https://reviews.llvm.org/D95166

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


[PATCH] D95971: [OpenMP][NVPTX] Take functions in `deviceRTLs` as `convergent`

2021-02-03 Thread Shilei Tian via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f0ce3c12ede: [OpenMP][NVPTX] Take functions in `deviceRTLs` 
as `convergent` (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95971/new/

https://reviews.llvm.org/D95971

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/OpenMP/target_attribute_convergent.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp

Index: openmp/libomptarget/test/offloading/bug49021.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/offloading/bug49021.cpp
@@ -0,0 +1,85 @@
+// RUN: %libomptarget-compilexx-aarch64-unknown-linux-gnu -O3 && %libomptarget-run-aarch64-unknown-linux-gnu
+// RUN: %libomptarget-compilexx-powerpc64-ibm-linux-gnu -O3 && %libomptarget-run-powerpc64-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-powerpc64le-ibm-linux-gnu -O3 && %libomptarget-run-powerpc64le-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-x86_64-pc-linux-gnu -O3 && %libomptarget-run-x86_64-pc-linux-gnu
+// RUN: %libomptarget-compilexx-nvptx64-nvidia-cuda -O3 && %libomptarget-run-nvptx64-nvidia-cuda
+
+#include 
+
+template  int test_map() {
+  std::cout << "map(complex<>)" << std::endl;
+  T a(0.2), a_check;
+#pragma omp target map(from : a_check)
+  { a_check = a; }
+
+  if (a_check != a) {
+std::cout << " wrong results";
+return 1;
+  }
+
+  return 0;
+}
+
+template  int test_reduction() {
+  std::cout << "flat parallelism" << std::endl;
+  T sum(0), sum_host(0);
+  const int size = 100;
+  T array[size];
+  for (int i = 0; i < size; i++) {
+array[i] = i;
+sum_host += array[i];
+  }
+
+#pragma omp target teams distribute parallel for map(to: array[:size]) \
+ reduction(+ : sum)
+  for (int i = 0; i < size; i++)
+sum += array[i];
+
+  if (sum != sum_host)
+std::cout << " wrong results " << sum << " host " << sum_host << std::endl;
+
+  std::cout << "hierarchical parallelism" << std::endl;
+  const int nblock(10), block_size(10);
+  T block_sum[nblock];
+#pragma omp target teams distribute map(to \
+: array[:size])\
+map(from   \
+: block_sum[:nblock])
+  for (int ib = 0; ib < nblock; ib++) {
+T partial_sum = 0;
+const int istart = ib * block_size;
+const int iend = (ib + 1) * block_size;
+#pragma omp parallel for reduction(+ : partial_sum)
+for (int i = istart; i < iend; i++)
+  partial_sum += array[i];
+block_sum[ib] = partial_sum;
+  }
+
+  sum = 0;
+  for (int ib = 0; ib < nblock; ib++) {
+sum += block_sum[ib];
+  }
+
+  if (sum != sum_host) {
+std::cout << " wrong results " << sum << " host " << sum_host << std::endl;
+return 1;
+  }
+
+  return 0;
+}
+
+template  int test_complex() {
+  int ret = 0;
+  ret |= test_map();
+  ret |= test_reduction();
+  return ret;
+}
+
+int main() {
+  int ret = 0;
+  std::cout << "Testing float" << std::endl;
+  ret |= test_complex();
+  std::cout << "Testing double" << std::endl;
+  ret |= test_complex();
+  return ret;
+}
Index: clang/test/OpenMP/target_attribute_convergent.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_attribute_convergent.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -o - | FileCheck %s
+// expected-no-diagnostics
+
+#pragma omp declare target
+
+void foo() {}
+
+#pragma omp end declare target
+
+// CHECK: Function Attrs: {{.*}}convergent{{.*}}
+// CHECK: define hidden void @_Z3foov() [[ATTRIBUTE_NUMBER:#[0-9]+]]
+// CHECK: attributes [[ATTRIBUTE_NUMBER]] = { {{.*}}convergent{{.*}} }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2441,6 +2441,8 @@
   bool IsTargetSpecified =
   Opts.OpenMPIsDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ);
 
+  Opts.ConvergentFunctions = Opts.ConvergentFunctions || Opts.OpenMPIsDevice;
+
   if (Opts.OpenMP || Opts.OpenMPSimd) {
 if (int Version = getLastArgIntValue(
 Args, OPT_fopenmp_version_EQ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0f0ce3c - [OpenMP][NVPTX] Take functions in `deviceRTLs` as `convergent`

2021-02-03 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2021-02-03T20:58:12-05:00
New Revision: 0f0ce3c12edefd25448e39c4d20718a10d3d42c1

URL: 
https://github.com/llvm/llvm-project/commit/0f0ce3c12edefd25448e39c4d20718a10d3d42c1
DIFF: 
https://github.com/llvm/llvm-project/commit/0f0ce3c12edefd25448e39c4d20718a10d3d42c1.diff

LOG: [OpenMP][NVPTX] Take functions in `deviceRTLs` as `convergent`

OpenMP device compiler (similar to other SPMD compilers) assumes that
functions are convergent by default to avoid invalid transformations, such as
the bug (https://bugs.llvm.org/show_bug.cgi?id=49021).

Reviewed By: jdoerfert

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

Added: 
clang/test/OpenMP/target_attribute_convergent.cpp
openmp/libomptarget/test/offloading/bug49021.cpp

Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2f712ed6c706..6dff00dfc308 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2441,6 +2441,8 @@ void CompilerInvocation::ParseLangArgs(LangOptions , 
ArgList ,
   bool IsTargetSpecified =
   Opts.OpenMPIsDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ);
 
+  Opts.ConvergentFunctions = Opts.ConvergentFunctions || Opts.OpenMPIsDevice;
+
   if (Opts.OpenMP || Opts.OpenMPSimd) {
 if (int Version = getLastArgIntValue(
 Args, OPT_fopenmp_version_EQ,

diff  --git a/clang/test/OpenMP/target_attribute_convergent.cpp 
b/clang/test/OpenMP/target_attribute_convergent.cpp
new file mode 100644
index ..932214e987c8
--- /dev/null
+++ b/clang/test/OpenMP/target_attribute_convergent.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-fopenmp-is-device -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple 
nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s 
-fopenmp-is-device -o - | FileCheck %s
+// expected-no-diagnostics
+
+#pragma omp declare target
+
+void foo() {}
+
+#pragma omp end declare target
+
+// CHECK: Function Attrs: {{.*}}convergent{{.*}}
+// CHECK: define hidden void @_Z3foov() [[ATTRIBUTE_NUMBER:#[0-9]+]]
+// CHECK: attributes [[ATTRIBUTE_NUMBER]] = { {{.*}}convergent{{.*}} }

diff  --git a/openmp/libomptarget/test/offloading/bug49021.cpp 
b/openmp/libomptarget/test/offloading/bug49021.cpp
new file mode 100644
index ..bcdbf68b10e0
--- /dev/null
+++ b/openmp/libomptarget/test/offloading/bug49021.cpp
@@ -0,0 +1,85 @@
+// RUN: %libomptarget-compilexx-aarch64-unknown-linux-gnu -O3 && 
%libomptarget-run-aarch64-unknown-linux-gnu
+// RUN: %libomptarget-compilexx-powerpc64-ibm-linux-gnu -O3 && 
%libomptarget-run-powerpc64-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-powerpc64le-ibm-linux-gnu -O3 && 
%libomptarget-run-powerpc64le-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-x86_64-pc-linux-gnu -O3 && 
%libomptarget-run-x86_64-pc-linux-gnu
+// RUN: %libomptarget-compilexx-nvptx64-nvidia-cuda -O3 && 
%libomptarget-run-nvptx64-nvidia-cuda
+
+#include 
+
+template  int test_map() {
+  std::cout << "map(complex<>)" << std::endl;
+  T a(0.2), a_check;
+#pragma omp target map(from : a_check)
+  { a_check = a; }
+
+  if (a_check != a) {
+std::cout << " wrong results";
+return 1;
+  }
+
+  return 0;
+}
+
+template  int test_reduction() {
+  std::cout << "flat parallelism" << std::endl;
+  T sum(0), sum_host(0);
+  const int size = 100;
+  T array[size];
+  for (int i = 0; i < size; i++) {
+array[i] = i;
+sum_host += array[i];
+  }
+
+#pragma omp target teams distribute parallel for map(to: array[:size]) 
\
+ reduction(+ : sum)
+  for (int i = 0; i < size; i++)
+sum += array[i];
+
+  if (sum != sum_host)
+std::cout << " wrong results " << sum << " host " << sum_host << std::endl;
+
+  std::cout << "hierarchical parallelism" << std::endl;
+  const int nblock(10), block_size(10);
+  T block_sum[nblock];
+#pragma omp target teams distribute map(to 
\
+: array[:size])
\
+map(from   
\
+: block_sum[:nblock])
+  for (int ib = 0; ib < nblock; ib++) {
+T partial_sum = 0;
+const int istart = ib * block_size;
+const int iend = (ib + 1) * block_size;
+#pragma omp parallel for reduction(+ : partial_sum)
+for (int i = istart; i < iend; i++)
+  partial_sum += array[i];
+block_sum[ib] = partial_sum;
+  }
+
+  sum = 0;
+  for (int ib = 0; ib < nblock; ib++) {
+sum += block_sum[ib];
+  }
+
+  if (sum != sum_host) {
+std::cout << " wrong results " << sum << " 

[PATCH] D95099: [clang-scan-deps] : Support -- in clang command lines.

2021-02-03 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95099/new/

https://reviews.llvm.org/D95099

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


[PATCH] D95989: [ASTReader] Always rebuild a cached module that has errors

2021-02-03 Thread Ben Barham via Phabricator via cfe-commits
bnbarham created this revision.
bnbarham added a reviewer: akyrtzi.
bnbarham requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A module in the cache with an error should just be a cache miss. If
allowing errors (with -fallow-pcm-with-compiler-errors), a rebuild is
needed so that the appropriate diagnostics are output and in case search
paths have changed. If not allowing errors, the module was built
*allowing* errors and thus should be rebuilt regardless.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95989

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Modules/Inputs/error.h
  clang/test/Modules/Inputs/error/error.h
  clang/test/Modules/Inputs/error/module.modulemap
  clang/test/Modules/Inputs/module.map
  clang/test/Modules/load-module-with-errors.m

Index: clang/test/Modules/load-module-with-errors.m
===
--- clang/test/Modules/load-module-with-errors.m
+++ clang/test/Modules/load-module-with-errors.m
@@ -1,25 +1,68 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
+// RUN: mkdir %t/prebuilt
 
-// Write out a module with errors make sure it can be read
 // RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -emit-module \
-// RUN:   -fmodule-name=error %S/Inputs/module.map
-// RUN: %clang_cc1 -fmodules -fallow-pcm-with-compiler-errors \
-// RUN:   -fmodules-cache-path=%t -x objective-c -I %S/Inputs \
-// RUN:   -fimplicit-module-maps -ast-print %s | FileCheck %s
+// RUN:   -fmodule-name=error -o %t/prebuilt/error.pcm \
+// RUN:   -x objective-c -emit-module %S/Inputs/error/module.modulemap
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fprebuilt-module-path=%t/prebuilt -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodule-file=error=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodule-file=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -ast-print %s | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodule-file=%t/prebuilt/error.pcm -fmodules-cache-path=%t \
+// RUN:   -verify=pcherror %s
+
+// Shouldn't build the cached module (that has errors) when not allowing errors
+// RUN: not %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c %s
+// RUN: find %t -name "error-*.pcm" | not grep error
+
+// Should build the cached module when allowing errors
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
+// RUN: find %t -name "error-*.pcm" | grep error
+
+// Make sure there is still an error after the module is already in the cache
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fallow-pcm-with-compiler-errors \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
+
+// Should rebuild the cached module if it had an error (if it wasn't rebuilt
+// the verify would fail as it would be the PCH error instead)
+// RUN: %clang_cc1 -fsyntax-only -fmodules \
+// RUN:   -fmodules-cache-path=%t -fimplicit-module-maps -I %S/Inputs/error \
+// RUN:   -x objective-c -verify %s
 
 // allow-pcm-with-compiler-errors should also allow errors in PCH
-// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x c++ -emit-pch \
-// RUN:   -o %t/check.pch %S/Inputs/error.h
+// RUN: %clang_cc1 -fallow-pcm-with-compiler-errors -x objective-c \
+// RUN:   -o %t/check.pch -emit-pch %S/Inputs/error/error.h
 
-@import error;
+// pcherror-error@* {{PCH file contains compiler errors}}
+@import error; // expected-error {{could not build module 'error'}}
 
-void test(id x) {
+void test(Error *x) {
   [x method];
 }
 
 // CHECK: @interface Error
 // CHECK-NEXT: - (int)method;
+// CHECK-NEXT: - (id)method2;
 // CHECK-NEXT: @end
-// CHECK: void test(id x)
+// CHECK: void test(Error *x)
Index: clang/test/Modules/Inputs/module.map
===
--- clang/test/Modules/Inputs/module.map
+++ clang/test/Modules/Inputs/module.map
@@ -483,4 +483,3 @@
   header "template-nontrivial1.h"
   export *
 }
-module error { header "error.h" }
Index: clang/test/Modules/Inputs/error/module.modulemap

[PATCH] D95166: Disable rosegment for old Android versions.

2021-02-03 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D95166#2540399 , @danalbert wrote:

>> We've since added -fuse-ld=lld to the three CMAKE_*_FLAGS so I think we're 
>> likely set on our end.
>
> https://reviews.llvm.org/D76452 not being accepted means that Android 
> toolchains must have LLD installed as `ld`.

If you pass `-fuse-ld=lld` everwhere, that's not needed, right (?)

>> If there's some way to build android compiler-rt runtimes as part of a 
>> regular linux llvm build, we'd love to learn about that :)
>
> afaik CMake makes this impossible because one build has exactly one target :(




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95166/new/

https://reviews.llvm.org/D95166

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


[PATCH] D71714: [Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array item

2021-02-03 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Hi,

this causes a warning in harfbuzz on code that looks like so:

  UChar decomposed[4];
  ...
  int len = unorm2_getRawDecomposition(...decomposed, ARRAY_LENGTH 
(decomposed)...)
  if (len == 1) {
U16_GET_UNSAFE (decomposed, 0, *a);

where `U16_GET_UNSAFE` looks like so:

  #define U16_GET_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
  (c)=(s)[i]; \
  if(U16_IS_SURROGATE(c)) { \
  if(U16_IS_SURROGATE_LEAD(c)) { \
  (c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)+1]); \
  } else { \
  (c)=U16_GET_SUPPLEMENTARY((s)[(i)-1], (c)); \
  } \
  } \
  } UPRV_BLOCK_MACRO_END

(The BLOCK_MACRO macros are just a way to spell `do...while(false)` as far as I 
understand.)

It's true that the else block in the macro evaluates to decomposed[0-1], which 
is out of bounds -- but it's also in a conditional, and in a macro. That seems 
like this can cause quite a few false positives. Maybe this warning should be 
suppressed in conditionals, or macros, or some such?

(50k/70k files of chromium built with this patch, this so far is the only 
instance it flagged, and that's a false positive.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71714/new/

https://reviews.llvm.org/D71714

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


[PATCH] D95714: [clang-tidy] fix modernize-use-nullptr false positive with spaceship operator comparisons

2021-02-03 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc added a comment.

In D95714#2540685 , @njames93 wrote:

> Can I ask if you could tidy the description of this, basically remove all the 
> stuff about hasGrandparent etc, probably best just remove everything after 
> `result = (a1 nullptr a2);` in the desc. It shows in the commit message and 
> its not strictly relevant.

Thanks, done. I never thought about all that showing up in the commit message, 
I'll be more concise.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95714/new/

https://reviews.llvm.org/D95714

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


[PATCH] D95714: [clang-tidy] fix modernize-use-nullptr false positive with spaceship operator comparisons

2021-02-03 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D95714#2540626 , @poelmanc wrote:

> Thanks for all the great feedback I received here. To give credit where 
> credit's due, this updated revision to UseNullptrCheck.cpp is now actually 
> 100% @steveire's //suggested// code. Even one of the tests cases was his. 
> Whenever it's ready to land I'd appreciate it if someone could push it as I 
> lack llvm-project commit access.

Can I ask if you could tidy the description of this, basically remove all the 
stuff about hasGrandparent etc, probably best just remove everything after 
`result = (a1 nullptr a2);` in the desc. It shows in the commit message and its 
not strictly relevant.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95714/new/

https://reviews.llvm.org/D95714

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


[PATCH] D93095: Introduce -Wreserved-identifier

2021-02-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

There is a GNU extension where the linker provides symbols for section / start 
end, and using these with this patch would produce a warning.
Example:

  `
  [[gnu::section(foo)]] void bar() {}
  extern "C" void __start_foo();
  extern "C" void __stop_foo();


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93095/new/

https://reviews.llvm.org/D93095

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


[PATCH] D95970: [HIP] Allow undefined symbols

2021-02-03 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D95970#2540414 , @yaxunl wrote:

> In D95970#2540303 , @tra wrote:
>
>> What's going to happen if you do have an undefined reference that's *not* to 
>> a `__managed__` variable?
>
> By default HIP toolchain uses -fvisibility hidden 
> -fapply-global-visibility-to-externs for device compilation. Undefined 
> variable symbols have protected visibility. Undefined function symbols have 
> hidden visibility. Since they are not allowed to be preempted, lld still 
> emits error if they are undefined. `__managed__` variables have default 
> visibility, therefore they are allowed to go through.

Is there a test that verifies/demonstrates how it's handled at compile time?

> We can let HIP runtime emit an error if there are undefined symbols other 
> than managed variables.

Detecting compilation errors at run-time is not very useful. The end user would 
likely have no idea what's going on.
I wonder if we can catch the errors earlier. E.g. w/o RDC, we can probably 
catch it in the codegen.
With RDC, only the linker will know it, so you would need some sort of custom 
plugin for that.

What if we actually resolve all `__managed__` references and point them to some 
sort of placeholder. 
E.g a weak symbol, that would be directed to the real location when the binary 
is loaded. 
Or, maybe, introduce an indirection and let the runtime handle managed 
variables as a special case 
and point the indirect links to the right locations. 
This way you can still run with `-no-undefined` and find all other unresolved 
references that should not be there.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95970/new/

https://reviews.llvm.org/D95970

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


[PATCH] D95691: Implement P2173 for attributes on lambdas

2021-02-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D95691#2540619 , @rsmith wrote:

> In D95691#2540450 , @rjmccall wrote:
>
>> The warning is a bit weird.  If we don't think it's certain that the 
>> committee will adopt this syntax, I don't think we should add this patch at 
>> all; it is not really acceptable to add it and then treat it as a Clang 
>> extension if the committee rejects it.  If we do think it's certain, we 
>> should go ahead and consider this a feature of the next major standard.
>
> I think it's quite unlikely that the committee would reject the feature at 
> this stage. Seems OK to me to jump the gun slightly and call this a C++23 
> extension.

SGTM, then.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95691/new/

https://reviews.llvm.org/D95691

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


[PATCH] D95910: Fix the guaranteed alignment of memory returned by malloc/new on Darwin

2021-02-03 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95910/new/

https://reviews.llvm.org/D95910

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


[PATCH] D90851: [clang-tidy] Extending bugprone-signal-handler with POSIX functions.

2021-02-03 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-posix-api.h:1
-//===--- signal.h - Stub header for tests ---*- C++ 
-*-===//
+//===--- system-header-posix-api.h - Stub header for tests --*- C++ 
-*-===//
 //

aaron.ballman wrote:
> balazske wrote:
> > aaron.ballman wrote:
> > > balazske wrote:
> > > > aaron.ballman wrote:
> > > > > I think we should strive to replicate the system headers rather than 
> > > > > fake up a system header (these headers can be used by more than one 
> > > > > check). So I think we want to keep signal.h and stdlib.h, and should 
> > > > > include the POSIX-specific functionality with a macro. This also 
> > > > > helps us test the behavior on systems like Windows which are not 
> > > > > POSIX systems.
> > > > My concern was to add these many small header files with just some 
> > > > functions in them. For `accept` more than one header is needed if we 
> > > > want to exactly replicate the system files. And data types like 
> > > > `size_t` should have a common header too. So I decided to have one 
> > > > header that contains all system functions and data types. This can be 
> > > > used by multiple tests and extended as needed.
> > > I don't think we're too worried about having a bunch of small test 
> > > headers around -- I think it's more important the headers used to check 
> > > system header behavior be understandable as to what you're getting from 
> > > them. For instance, there are clang-tidy checks for llvm-libc that may 
> > > have very different needs from what you're doing here.
> > > 
> > > What's more, these changes break existing tests -- I don't see any 
> > > companion changes to fix those up.
> > On my system (Ubuntu) I do not see failing tests, and these changes do not 
> > touch files that were created before D87449, no new problems should happen. 
> > I am not against "mirroring" the POSIX API header structure into the test 
> > stub header structure, only do not like the overhead of adding these many 
> > files with just 1-2 lines (that is needed for this test) in them. It is not 
> > done this way in the clang tests either (there are multiple 
> > "system-header-simulator" files that contain every declaration usable for 
> > specific purposes at one or more tests). Also I want to have the opinion of 
> > another reviewer for this question.
> > On my system (Ubuntu) I do not see failing tests, and these changes do not 
> > touch files that were created before D87449, no new problems should happen.
> 
> You renamed stdlib.h and `lllvmlibc-restrict-system-libc-headers.cpp` 
> includes `stdlib.h`, but after closer inspection, I see now that it's 
> including one from a different directory. So this doesn't break the things I 
> thought it was breaking, good!
> 
> > Also I want to have the opinion of another reviewer for this question.
> 
> I'm happy to go with whatever @alexfh thinks.
> 
Based on the experience with our internal set of checks and tests for them, I 
tend to think that keeping mock API definitions arranged in a similar way to 
the corresponding real library is a more sustainable way to manage mock 
headers. When arranged this way, it's easier to find the origins of, verify, 
and update definitions, when, for example, a higher fidelity replication of a 
system/STL/... entity becomes necessary. Dependencies between these mock 
headers (if necessary) can repeat those in the real library, and #includes of 
these mock headers can be composed in a similar way. Though the structure of 
the mock headers can start be approximate and the level of detail can be added 
when necessary. For example, one can start with a mock header for  that 
would contain initializer_list implementation. But when another test would need 
, the corresponding entities can be moved to a separate 
initializer_list header.

As for different header contents depending on target platform, preprocessor 
macros seem to be a better way to handle this than using separate mock headers.

The set of mock headers can be shared by all tests that examine the 
corresponding API. I don't see good reasons to keep different mocks of the same 
API for different tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90851/new/

https://reviews.llvm.org/D90851

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


[clang] b995314 - Revert "[InstrProfiling] Use !associated metadata for counters, data and values"

2021-02-03 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-02-03T19:14:34-05:00
New Revision: b9953141439b460f4023c2d684b7f789bebfc885

URL: 
https://github.com/llvm/llvm-project/commit/b9953141439b460f4023c2d684b7f789bebfc885
DIFF: 
https://github.com/llvm/llvm-project/commit/b9953141439b460f4023c2d684b7f789bebfc885.diff

LOG: Revert "[InstrProfiling] Use !associated metadata for counters, data and 
values"

This reverts commit 97ba5cde52664200819446c1a18de28faf2ed1c6.
Still breaks tests: https://reviews.llvm.org/D76802#2540647

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
compiler-rt/test/CMakeLists.txt
compiler-rt/test/profile/CMakeLists.txt
llvm/include/llvm/Transforms/Instrumentation.h
llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/icall.ll
llvm/test/Instrumentation/InstrProfiling/linkage.ll
llvm/test/Transforms/PGOProfile/counter_promo.ll
llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll

Removed: 
compiler-rt/test/profile/instrprof-gc-sections.c
llvm/test/Transforms/PGOProfile/associated.ll



diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index f995c4702419..52bcd971dc8c 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -615,9 +615,6 @@ getInstrProfOptions(const CodeGenOptions ,
   Options.NoRedZone = CodeGenOpts.DisableRedZone;
   Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
   Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
-  std::pair BinutilsVersion =
-  llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion);
-  Options.CounterLinkOrder = BinutilsVersion >= std::make_pair(2, 36);
   return Options;
 }
 

diff  --git a/compiler-rt/test/CMakeLists.txt b/compiler-rt/test/CMakeLists.txt
index 4d2a6ec2be10..0836005e10db 100644
--- a/compiler-rt/test/CMakeLists.txt
+++ b/compiler-rt/test/CMakeLists.txt
@@ -22,7 +22,7 @@ if(NOT ANDROID)
 # Use LLVM utils and Clang from the same build tree.
 list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS
   clang clang-resource-headers FileCheck count not llvm-config llvm-nm 
llvm-objdump
-  llvm-readelf llvm-readobj llvm-symbolizer compiler-rt-headers sancov)
+  llvm-readobj llvm-symbolizer compiler-rt-headers sancov)
 if (WIN32)
   list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS KillTheDoctor)
 endif()

diff  --git a/compiler-rt/test/profile/CMakeLists.txt 
b/compiler-rt/test/profile/CMakeLists.txt
index 446e850a3bc1..4b031306594f 100644
--- a/compiler-rt/test/profile/CMakeLists.txt
+++ b/compiler-rt/test/profile/CMakeLists.txt
@@ -5,9 +5,6 @@ set(PROFILE_TESTSUITES)
 set(PROFILE_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
 if(NOT COMPILER_RT_STANDALONE_BUILD)
   list(APPEND PROFILE_TEST_DEPS profile llvm-profdata llvm-cov)
-  if(NOT APPLE AND COMPILER_RT_HAS_LLD AND TARGET lld)
-list(APPEND PROFILE_TEST_DEPS lld)
-  endif()
 endif()
 
 set(PROFILE_TEST_ARCH ${PROFILE_SUPPORTED_ARCH})

diff  --git a/compiler-rt/test/profile/instrprof-gc-sections.c 
b/compiler-rt/test/profile/instrprof-gc-sections.c
deleted file mode 100644
index 2876be1cf01a..
--- a/compiler-rt/test/profile/instrprof-gc-sections.c
+++ /dev/null
@@ -1,91 +0,0 @@
-// REQUIRES: linux, lld-available
-
-// RUN: %clang_profgen=%t.profraw -fuse-ld=lld -fcoverage-mapping -mllvm 
-counter-link-order -mllvm -enable-name-compression=false -DCODE=1 
-ffunction-sections -fdata-sections -Wl,--gc-sections -o %t %s
-// RUN: %run %t
-// RUN: llvm-profdata merge -o %t.profdata %t.profraw
-// RUN: llvm-profdata show --all-functions %t.profdata | FileCheck %s 
-check-prefix=PROF
-// RUN: llvm-cov show %t -instr-profile %t.profdata | FileCheck %s 
-check-prefix=COV
-// RUN: llvm-nm %t | FileCheck %s -check-prefix=NM
-// RUN: llvm-readelf -x __llvm_prf_names %t | FileCheck %s 
-check-prefix=PRF_NAMES
-// RUN: llvm-readelf -x __llvm_prf_cnts %t | FileCheck %s 
-check-prefix=PRF_CNTS
-
-// RUN: %clang_lto_profgen=%t.lto.profraw -fuse-ld=lld -fcoverage-mapping 
-mllvm -counter-link-order -mllvm -enable-name-compression=false -DCODE=1 
-ffunction-sections -fdata-sections -Wl,--gc-sections -flto -o %t.lto %s
-// RUN: %run %t.lto
-// RUN: llvm-profdata merge -o %t.lto.profdata %t.lto.profraw
-// RUN: llvm-profdata show --all-functions %t.lto.profdata | FileCheck %s 
-check-prefix=PROF
-// RUN: llvm-cov show %t.lto -instr-profile %t.lto.profdata | FileCheck %s 
-check-prefix=COV
-// RUN: llvm-nm %t.lto | FileCheck %s -check-prefix=NM
-// RUN: llvm-readelf -x __llvm_prf_names %t.lto | FileCheck %s 
-check-prefix=PRF_NAMES
-// RUN: llvm-readelf -x __llvm_prf_cnts %t.lto | FileCheck %s 
-check-prefix=PRF_CNTS
-
-// Note: We expect foo() and some of the profiling data associated with it to
-// be garbage collected.
-
-// Note: When there is no code in 

[PATCH] D76802: [InstrProfiling] Use !associated metadata for counters, data and values

2021-02-03 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: compiler-rt/test/profile/instrprof-gc-sections.c:30
+// RUN: llvm-nm -jgU %t | grep -vE "main|_start|_IO_stdin_used|__libc_.*" > 
%t.code.syms
+// RUN: diff %t.nocode.syms %t.code.syms
+

phosek wrote:
> MaskRay wrote:
> > This fails on my machine (cc @akuegel). If I use `diff -u`:
> > 
> > ```
> > --- 
> > /tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.nocode.syms
> >2021-02-01 22:14:22.850222346 -0800
> > +++ 
> > /tmp/RelA/projects/compiler-rt/test/profile/Profile-x86_64/Output/instrprof-gc-sections.c.tmp.code.syms
> >  2021-02-01 22:14:22.854222358 -0800
> > @@ -3,6 +3,5 @@
> >  __prof_cnts_sect_data
> >  __prof_data_sect_data
> >  __prof_nms_sect_data
> > -__prof_orderfile_sect_data
> >  __prof_vnodes_sect_data
> >  lprofDirMode
> > ```
> > 
> > At the worst we can temporarily disable it (if others report issues as 
> > well).
> What's your build setup? I ran `check-profile` on my Linux workstation just 
> now but haven't seen this issue.
This also fails on my machine:
$ cmake -GNinja -DLLVM_ENABLE_PROJECTS='clang;compiler-rt;lld' 
-DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_LLD=ON ..
$ ninja check-profile


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76802/new/

https://reviews.llvm.org/D76802

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


[PATCH] D95691: Implement P2173 for attributes on lambdas

2021-02-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D95691#2540450 , @rjmccall wrote:

> The patch seems technically okay to me.  Do we need to recognize lambdas in 
> any tentative-parse situations, or is it always the reverse (e.g. recognizing 
> ObjC message sends as not-a-lambda)?

Disambiguation with ObjC message sends never looks past the `]` of the lambda 
introducer, so I think that's fine. And the disambiguation for `[[` won't kick 
in here, because we've already committed to the `[...] [[` introducing a lambda 
before we parse the attributes. The disambiguation for `int a[] = { [n] = 0 };` 
also looks OK: it looks for an `=` after the `]`, which we can still use to 
disambiguate as an array designator rather than a lambda.

I think the error recovery disambiguation logic for `delete [] { return p; } 
();` won't work if the lambda has attributes, but that seems fine: that's a 
best-effort recovery anyway.

> The warning is a bit weird.  If we don't think it's certain that the 
> committee will adopt this syntax, I don't think we should add this patch at 
> all; it is not really acceptable to add it and then treat it as a Clang 
> extension if the committee rejects it.  If we do think it's certain, we 
> should go ahead and consider this a feature of the next major standard.

I think it's quite unlikely that the committee would reject the feature at this 
stage. Seems OK to me to jump the gun slightly and call this a C++23 extension.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95691/new/

https://reviews.llvm.org/D95691

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


[PATCH] D95714: [clang-tidy] fix modernize-use-nullptr false positive with spaceship operator comparisons

2021-02-03 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc added a comment.

Thanks for all the great feedback I received here. To give credit where 
credit's due, this updated revision to UseNullptrCheck.cpp is now actually 100% 
@steveire's //suggested// code. Even one of the tests cases was his. Whenever 
it's ready to land I'd appreciate it if someone could push it as I lack 
llvm-project commit access.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95714/new/

https://reviews.llvm.org/D95714

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


[PATCH] D95910: Fix the guaranteed alignment of memory returned by malloc/new on Darwin

2021-02-03 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 321251.
ahatanak edited the summary of this revision.
ahatanak added a comment.

Make the alignment 16 bytes on 32-bit systems too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95910/new/

https://reviews.llvm.org/D95910

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/test/Preprocessor/init-aarch64.c
  clang/test/Preprocessor/init-arm.c


Index: clang/test/Preprocessor/init-arm.c
===
--- clang/test/Preprocessor/init-arm.c
+++ clang/test/Preprocessor/init-arm.c
@@ -196,6 +196,9 @@
 // ARM:#define __arm 1
 // ARM:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=armv7-apple-ios7.0 -x c++ < /dev/null | 
FileCheck -match-full-lines -check-prefix ARM-DARWIN-CXX %s
+// ARM-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -dM -ffreestanding -triple arm-none-none -target-abi 
apcs-gnu -E /dev/null -o - | FileCheck -match-full-lines -check-prefix 
ARM-APCS-GNU %s
 // ARM-APCS-GNU: #define __INTPTR_TYPE__ int
 // ARM-APCS-GNU: #define __PTRDIFF_TYPE__ int
Index: clang/test/Preprocessor/init-aarch64.c
===
--- clang/test/Preprocessor/init-aarch64.c
+++ clang/test/Preprocessor/init-aarch64.c
@@ -532,6 +532,9 @@
 // AARCH64-DARWIN: #define __WINT_WIDTH__ 32
 // AARCH64-DARWIN: #define __aarch64__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=aarch64-apple-ios7.0 -x c++ < /dev/null | 
FileCheck -match-full-lines -check-prefix AARCH64-DARWIN-CXX %s
+// AARCH64-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-windows-msvc < 
/dev/null | FileCheck -match-full-lines -check-prefix AARCH64-MSVC %s
 
 // AARCH64-MSVC: #define _INTEGRAL_MAX_BITS 64
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -67,9 +67,12 @@
   // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
   // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
   // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
-  // This alignment guarantee also applies to Windows and Android.
+  // This alignment guarantee also applies to Windows and Android. On Darwin,
+  // the alignment is 16 bytes on both 64-bit and 32-bit systems.
   if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
+  else if (T.isOSDarwin())
+NewAlign = 128;
   else
 NewAlign = 0; // Infer from basic type alignment.
   HalfWidth = 16;


Index: clang/test/Preprocessor/init-arm.c
===
--- clang/test/Preprocessor/init-arm.c
+++ clang/test/Preprocessor/init-arm.c
@@ -196,6 +196,9 @@
 // ARM:#define __arm 1
 // ARM:#define __arm__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=armv7-apple-ios7.0 -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix ARM-DARWIN-CXX %s
+// ARM-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -dM -ffreestanding -triple arm-none-none -target-abi apcs-gnu -E /dev/null -o - | FileCheck -match-full-lines -check-prefix ARM-APCS-GNU %s
 // ARM-APCS-GNU: #define __INTPTR_TYPE__ int
 // ARM-APCS-GNU: #define __PTRDIFF_TYPE__ int
Index: clang/test/Preprocessor/init-aarch64.c
===
--- clang/test/Preprocessor/init-aarch64.c
+++ clang/test/Preprocessor/init-aarch64.c
@@ -532,6 +532,9 @@
 // AARCH64-DARWIN: #define __WINT_WIDTH__ 32
 // AARCH64-DARWIN: #define __aarch64__ 1
 
+// RUN: %clang_cc1 -E -dM -triple=aarch64-apple-ios7.0 -x c++ < /dev/null | FileCheck -match-full-lines -check-prefix AARCH64-DARWIN-CXX %s
+// AARCH64-DARWIN-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=aarch64-windows-msvc < /dev/null | FileCheck -match-full-lines -check-prefix AARCH64-MSVC %s
 
 // AARCH64-MSVC: #define _INTEGRAL_MAX_BITS 64
Index: clang/lib/Basic/TargetInfo.cpp
===
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -67,9 +67,12 @@
   // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
   // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
   // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
-  // This alignment guarantee also applies to Windows and Android.
+  // This alignment guarantee also applies to Windows and Android. On Darwin,
+  // the alignment is 16 bytes on both 64-bit and 32-bit systems.
   if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
 NewAlign = Triple.isArch64Bit() ? 128 : 

[PATCH] D95771: [clang-tidy] fix modernize-loop-convert to retain needed array-like operator[]

2021-02-03 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc added a comment.

@njames93 Thanks for the review and for accepting this revision. I lack 
llvm-project commit access so if it's good to go I would greatly appreciate it 
if you or someone could push this whenever you have have a chance. Thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95771/new/

https://reviews.llvm.org/D95771

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


[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-02-03 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

I am planning to add more tests, figured it is better to put up the patch 
sooner rather than later.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95984/new/

https://reviews.llvm.org/D95984

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


[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-02-03 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added a reviewer: rjmccall.
varungandhi-apple requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

1. It should be mapped to LLVM's swifttailcc, which is now available.
2. We should make sure we generate a tail call instead of an ordinary call.

Fixes rdar://73762895.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95984

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c

Index: clang/test/CodeGen/swift-call-conv.c
===
--- clang/test/CodeGen/swift-call-conv.c
+++ clang/test/CodeGen/swift-call-conv.c
@@ -7,3 +7,5 @@
 void __attribute__((__swiftcall__)) f(void) {}
 // CHECK-LABEL: define dso_local swiftcc void @f()
 
+void __attribute__((__swiftasynccall__)) f_async(void) {}
+// CHECK-LABEL: define dso_local swifttailcc void @f_async()
Index: clang/test/CodeGen/swift-async-call-conv.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-call-conv.c
@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// Test tail call behavior when a swiftasynccall function is called
+// from another swiftasynccall function.
+
+#define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+// CHECK-LABEL: swifttailcc void @async_leaf1(i8* swiftasync
+SWIFTASYNCCALL void async_leaf1(char * ASYNC_CONTEXT ctx) {
+  *ctx += 1;
+}
+
+// CHECK-LABEL: swifttailcc void @async_leaf2(i8* swiftasync
+SWIFTASYNCCALL void async_leaf2(char * ASYNC_CONTEXT ctx) {
+  *ctx += 2;
+}
+
+// CHECK-LABEL: swifttailcc void @async_branch
+// CHECK: tail call swifttailcc void @async_leaf1
+// CHECK: tail call swifttailcc void @async_leaf2
+SWIFTASYNCCALL void async_branch(_Bool b, char * ASYNC_CONTEXT ctx) {
+  if (b) {
+return async_leaf1(ctx);
+  } else {
+return async_leaf2(ctx);
+  }
+}
+
+// CHECK-LABEL: swifttailcc void @async_loop
+// CHECK: tail call swifttailcc void @async_leaf1
+// CHECK: tail call swifttailcc void @async_leaf2
+// CHECK: tail call swifttailcc void @async_loop
+SWIFTASYNCCALL void async_loop(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_loop(u - 2, ctx);
+}
+
+// Forward-declaration + mutual recursion is okay.
+
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx);
+
+// CHECK: swifttailcc void @async_mutual_loop
+// CHECK: tail call swifttailcc void @async_leaf
+// CHECK: tail call swifttailcc void @async_leaf
+// CHECK: tail call swifttailcc void @async_mutual_loop
+SWIFTASYNCCALL void async_mutual_loop1(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_mutual_loop2(u - 2, ctx);
+}
+
+// CHECK: swifttailcc void @async_mutual_loop
+// CHECK: tail call swifttailcc void @async_leaf1
+// CHECK: tail call swifttailcc void @async_leaf2
+// CHECK: tail call swifttailcc void @async_mutual_loop1
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_mutual_loop1(u - 2, ctx);
+}
+
+// When swiftasynccall functions are called by non-swiftasynccall functions,
+// the call isn't marked as a tail call.
+
+// CHECK-LABEL: swiftcc i8 @sync_calling_async
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_branch
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_loop
+SWIFTCALL char sync_calling_async(_Bool b, unsigned u) {
+  char x = 'a';
+  async_branch(b, );
+  async_loop(u, );
+  return x;
+}
+
+// CHECK-LABEL: i8 @c_calling_async
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_branch
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_loop
+char c_calling_async(_Bool b, unsigned u) {
+  char x = 'a';
+  async_branch(b, );
+  async_loop(u, );
+  return x;
+}
+
Index: clang/test/CodeGen/arm-swiftcall.c
===
--- clang/test/CodeGen/arm-swiftcall.c
+++ clang/test/CodeGen/arm-swiftcall.c
@@ -27,9 +27,15 @@
 SWIFTCALL 

[PATCH] D93095: Introduce -Wreserved-identifier

2021-02-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/AST/Decl.cpp:1087
+  StringRef Name = II->getName();
+  // '_' is a reserved identifier, but it's use is so common (e.g. to store
+  // ignored values) that we don't warn on it.





Comment at: clang/lib/AST/Decl.cpp:1096
+// Walk up the lexical parents to determine if we're at TU level or not.
+const DeclContext * DC = getLexicalDeclContext();
+while(DC->isTransparentContext())

aaron.ballman wrote:
> You may want to run the patch through clang-format.
The lexical parent doesn't matter here; what we care about is whether this 
declaration would conflict with a declaration in the global namespace, which 
means we should check the semantic parent. So we want 
`getDeclContext()->getRedeclContext()->isTranslationUnit()`.

For a variable or function, you should also check `isExternC()`, because 
`extern "C"` functions and variables (declared in any scope) conflict with 
variables and functions with the same name declared in the global namespace 
scope.



Comment at: clang/lib/Sema/SemaDecl.cpp:5557-5558
+return;
+  if (!Context.getSourceManager().isInSystemHeader(D->getLocation()) &&
+  D->isReserved(getLangOpts()))
+Diag(D->getLocation(), diag::warn_reserved_identifier) << D;

Swap the order of these checks; the "is reserved" check is faster and will 
usually allow us to short-circuit, whereas we're probably usually not in a 
system header and that check involves nontrivial work recursively decomposing 
the given source location.



Comment at: clang/lib/Sema/SemaDecl.cpp:17114
 
+warnOnReservedIdentifier(FD);
+

It would be more consistent with the other calls to this function to call this 
when we create each individual field, not when we finalize the record 
definition.



Comment at: clang/lib/Sema/SemaDecl.cpp:13640
 
+  warnOnReservedIdentifier(New);
+

serge-sans-paille wrote:
> serge-sans-paille wrote:
> > rsmith wrote:
> > > Is there somewhere more central you can do this, rather than repeating it 
> > > once for each kind of declaration? (Eg, `PushOnScopeChains`)
> > That would be sane. I'll check that.
> I tried PushOnScopeChains, and this does not capture all the required 
> declarations. I failed to find another place :-/
What cases is it missing? Can we add calls to `PushOnScopeChains` to those 
cases (perhaps with a new flag to say "don't actually push it into scope"?) I'm 
not super happy about adding a new thing that all places that create 
declarations and add them to scope need to remember to do, to drive this 
warning. Cases are going to get forgotten that way.



Comment at: clang/lib/Sema/SemaTemplate.cpp:1680-1681
 
+  for (NamedDecl *P : Params)
+warnOnReservedIdentifier(P);
+

Again, it'd be more consistent to do this when we finish creating the 
declaration and push it into scope, for all kinds of declaration.



Comment at: clang/test/Sema/reserved-identifier.c:13
+
+void foo(unsigned int _Reserved) { // expected-warning {{'_Reserved' is a 
reserved identifier}}
+  unsigned int __1 =   // expected-warning {{'__1' is a reserved 
identifier}}

It'd be useful to test that we don't diagnose

```
void foo(unsigned int _not_reserved) { ... }
```



Comment at: clang/test/Sema/reserved-identifier.c:31
+struct _Zebulon; // expected-warning {{'_Zebulon' is a reserved identifier}}
+struct _Zebulon2 {}* p; // expected-warning {{'_Zebulon2' is a reserved 
identifier}}
+

You don't seem to have a test for `TUK_Reference`:

```
struct _Zebulon3 *p;
```

(Nor for `TUK_Friend`.)



Comment at: clang/test/Sema/reserved-identifier.c:49-50
+// FIXME: According to clang declaration context layering, _preserved belongs 
to
+// the translation unit, so we emit a warning. It's unclear that's what the
+// standard mandate, but it's such a corner case we can live with it.
+void func(struct _preserved { int a; } r) {} // expected-warning 
{{'_preserved' is a reserved identifier}}

aaron.ballman wrote:
> I think we're correct to warn on this. Because the type specifier appears 
> within the parameter list, it has function prototype scope per C2x 6.2.1p4. 
> However, the identifier `_preserved` is put into the struct name space, which 
> hits the "in the tag name spaces" part of: "All identifiers that begin with 
> an underscore are reserved for use as identifiers with file scope in both the 
> ordinary and tag name spaces".
`_preserved` is not an identifier with file scope, so I think we shouldn't warn 
here. Perhaps the problem is that we're doing this check before the struct gets 
reparented into the function declaration (which only happens after we finish 
parsing all the parameters and build the function declaration).

We 

[PATCH] D95403: [clang-tidy][analyzer][WIP] Clang-tidy reverse integration into Static Analyzer.

2021-02-03 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Artem, could you set the repository to `rG LLVM Github Monorepo` when uploading 
patches as mentioned in 
https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface
 ? This way you'll allow pre-merge checks to run.

In D95403#2534714 , @aaron.ballman 
wrote:

>> This patch introduces a frontend flag -analyzer-tidy-checker=...
>
> FWIW, the usual clang-tidy nomenclature is to call these "checks" rather than 
> "checkers", so it might make sense to expose `-analyzer-tidy-checks=...` to 
> be analogous to `clang-tidy -checks=...`

I vaguely remember discussing (most probably, with @gribozavr2) this difference 
and coming to a conclusion that there's no strong reason to keep the 
nomenclature difference between the static analyzer and clang-tidy. This didn't 
go much farther beyond creating the clang-tools-extra/test/clang-tidy/checkers/ 
directory, but we could revisit this, since we're looking into more interaction 
between the tools.




Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:54-60
+#include "../../clang-tools-extra/clang-tidy/ClangTidyCheck.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyForceLinker.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyModule.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyModuleRegistry.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyOptions.h"
+#include "../../clang-tools-extra/clang-tidy/ClangTidyProfiling.h"

NoQ wrote:
> alexfh wrote:
> > Isn't this a layering violation, since clang-tidy depends on 
> > clangStaticAnalyzerCore and clangStaticAnalyzerFrontend?
> Yes, absolutely.
> 
> That said, the only purpose of clang-tidy's dependency on libStaticAnalyzer* 
> is integration of static analyzer into clang tidy which is definitely not 
> something we want to enable when we're baking clang-tidy back into clang. It 
> never makes sense to run static analyzer through clang-tidy integration into 
> static analyzer.
> 
> So ideally these two dependencies are temporally separated. I could make 
> these dependencies mutually exclusive by making the upcoming option of baking 
> clang-tidy into clang explicitly incompatible with 
> `CLANG_TIDY_ENABLE_STATIC_ANALYZER`.
> 
> But if we want to support building both clang-tidy with static analyzer and 
> static analyzer with clang-tidy from the same sources into the same build 
> directory, that'll probably involve either building two variants of 
> clang-tidy (one with static analyzer for standalone clang-tidy binary and one 
> without to use inside clang binary only) or two variants of static analyzer 
> (one with clang-tidy for the clang binary and one without to use inside 
> clang-tidy binary only).
> 
> Do you have any preference on how should i untangle this?
I hope we could break the dependency cycle without "flipping" the direction of 
dependencies based on a CMake switch. This way it would be easier to replicate 
the dependency structure in other BUILD systems.

Now the dependencies look very roughly like this:
```
clangStaticAnalyzerCore:
clangStaticAnalyzerCheckers: clangStaticAnalyzerCore
clangStaticAnalyzerFrontend: clangStaticAnalyzerCheckers clangStaticAnalyzerCore
clangFrontendTool: clangStaticAnalyzerFrontend

clangTidy: clangStaticAnalyzerCore clangStaticAnalyzerFrontend
clang-tidy check libraries gathered under $ALL_CLANG_TIDY_CHECKS
clangTidyMain: clangTidy
clang-tidy: clangTidyMain clangTidy $ALL_CLANG_TIDY_CHECKS
```

Untangled version could look like this:
```
clangStaticAnalyzerCore:
clangStaticAnalyzerCheckers: clangStaticAnalyzerCore
clangStaticAnalyzerFrontend: clangStaticAnalyzerCheckers 
clangStaticAnalyzerCore clangTidyInterface
clangStaticAnalyzerFrontendWithClangTidy: clangTidyImpl $ALL_CLANG_TIDY_CHECKS
clangFrontendTool: clangStaticAnalyzerFrontendWithClangTidy

clangTidyInterface: (with ClangTidy.h, ClangTidyOptions.h, 
ClangTidyDiagnosticConsumer.h and ClangTidyProfiling.h, for example)
clangTidyImpl: clangTidyInterface clangStaticAnalyzerCore 
clangStaticAnalyzerFrontend
clang-tidy check libraries gathered under $ALL_CLANG_TIDY_CHECKS
clangTidyMain: clangTidyImpl
clang-tidy: clangTidyMain clangTidyImpl $ALL_CLANG_TIDY_CHECKS
```

What do you think?



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95403/new/

https://reviews.llvm.org/D95403

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


[clang] 26e9c99 - [Docs] Add some documentation for constructor homing, a debug info optimization (-fuse-ctor-homing)

2021-02-03 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-02-03T15:25:49-08:00
New Revision: 26e9c99010b6870ee5c8ce998a84214e06f3f3a9

URL: 
https://github.com/llvm/llvm-project/commit/26e9c99010b6870ee5c8ce998a84214e06f3f3a9
DIFF: 
https://github.com/llvm/llvm-project/commit/26e9c99010b6870ee5c8ce998a84214e06f3f3a9.diff

LOG: [Docs] Add some documentation for constructor homing, a debug info 
optimization (-fuse-ctor-homing)

Adding this, since there's currently no documentation about this.

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

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index b9024a3006f1..a2fc8c06dc6e 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2504,6 +2504,18 @@ below. If multiple flags are present, the last one is 
used.
**-fno-standalone-debug** option can be used to get to turn on the
vtable-based optimization described above.
 
+.. option:: -fuse-ctor-homing
+
+   This optimization is similar to the optimizations that are enabled as part
+   of -fno-standalone-debug. Here, Clang only emits type info for a
+   non-trivial, non-aggregate C++ class in the modules that contain a
+   definition of one of its constructors. This relies on the additional
+   assumption that all classes that are not trivially constructible have a
+   non-trivial constructor that is used somewhere.
+
+   This flag is not enabled by default, and needs to be used with -cc1 or
+   -Xclang.
+
 .. option:: -g
 
   Generate complete debug info.



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


[PATCH] D95911: [Docs] Add some documentation for constructor homing, a debug info optimization (-fuse-ctor-homing)

2021-02-03 Thread Amy Huang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG26e9c99010b6: [Docs] Add some documentation for constructor 
homing, a debug info optimization… (authored by akhuang).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95911/new/

https://reviews.llvm.org/D95911

Files:
  clang/docs/UsersManual.rst


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -2504,6 +2504,18 @@
**-fno-standalone-debug** option can be used to get to turn on the
vtable-based optimization described above.
 
+.. option:: -fuse-ctor-homing
+
+   This optimization is similar to the optimizations that are enabled as part
+   of -fno-standalone-debug. Here, Clang only emits type info for a
+   non-trivial, non-aggregate C++ class in the modules that contain a
+   definition of one of its constructors. This relies on the additional
+   assumption that all classes that are not trivially constructible have a
+   non-trivial constructor that is used somewhere.
+
+   This flag is not enabled by default, and needs to be used with -cc1 or
+   -Xclang.
+
 .. option:: -g
 
   Generate complete debug info.


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -2504,6 +2504,18 @@
**-fno-standalone-debug** option can be used to get to turn on the
vtable-based optimization described above.
 
+.. option:: -fuse-ctor-homing
+
+   This optimization is similar to the optimizations that are enabled as part
+   of -fno-standalone-debug. Here, Clang only emits type info for a
+   non-trivial, non-aggregate C++ class in the modules that contain a
+   definition of one of its constructors. This relies on the additional
+   assumption that all classes that are not trivially constructible have a
+   non-trivial constructor that is used somewhere.
+
+   This flag is not enabled by default, and needs to be used with -cc1 or
+   -Xclang.
+
 .. option:: -g
 
   Generate complete debug info.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94131: [clang-tidy] Use new mapping matchers

2021-02-03 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0199b2a2170: [clang-tidy] Use new mapping matchers 
(authored by stephenkelly).

Changed prior to commit:
  https://reviews.llvm.org/D94131?vs=321233=321244#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94131/new/

https://reviews.llvm.org/D94131

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp
@@ -0,0 +1,44 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-container-size-empty %t -- -- -fno-delayed-template-parsing
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+template 
+struct OpEqOnly {
+  OpEqOnly();
+  bool operator==(const OpEqOnly ) const;
+  unsigned long size() const;
+  bool empty() const;
+};
+
+template 
+struct HasSpaceshipMem {
+  HasSpaceshipMem();
+  bool operator<=>(const HasSpaceshipMem ) const = default;
+  unsigned long size() const;
+  bool empty() const;
+};
+
+void returnsVoid() {
+  OpEqOnly OEO;
+  HasSpaceshipMem HSM;
+
+  if (OEO != OpEqOnly())
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
+  // CHECK-FIXES: {{^  }}if (!OEO.empty()){{$}}
+  // CHECK-MESSAGES: :19:8: note: method 'OpEqOnly'::empty() defined here
+  if (HSM != HasSpaceshipMem())
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
+  // CHECK-FIXES: {{^  }}if (!HSM.empty()){{$}}
+  // CHECK-MESSAGES: :27:8: note: method 'HasSpaceshipMem'::empty() defined here
+}
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp
@@ -0,0 +1,60 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-loop-convert %t -- -- -I %S/Inputs/modernize-loop-convert
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct HasSpaceshipMem {
+  typedef int value_type;
+
+  struct iterator {
+value_type *();
+const value_type *() const;
+iterator ++();
+void insert(value_type);
+value_type X;
+constexpr auto operator<=>(const HasSpaceshipMem::iterator &) const = default;
+  };
+
+  iterator begin();
+  iterator end();
+};
+
+struct OpEqOnly {
+  typedef int value_type;
+  struct iterator {
+value_type *();
+const value_type *() const;
+iterator ++();
+bool operator==(const iterator ) const;
+void insert(value_type);
+value_type X;
+  };
+  iterator begin();
+  iterator end();
+};
+
+void rewritten() {
+  OpEqOnly Oeo;
+  for (OpEqOnly::iterator It = Oeo.begin(), E = Oeo.end(); It != E; ++It) {
+(void)*It;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & It : Oeo)
+  // CHECK-FIXES-NEXT: (void)It;
+
+  HasSpaceshipMem Hsm;
+  for (HasSpaceshipMem::iterator It = 

[clang-tools-extra] c0199b2 - [clang-tidy] Use new mapping matchers

2021-02-03 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-02-03T23:21:17Z
New Revision: c0199b2a21705747c999a59bfa77d7fc6e4500a5

URL: 
https://github.com/llvm/llvm-project/commit/c0199b2a21705747c999a59bfa77d7fc6e4500a5
DIFF: 
https://github.com/llvm/llvm-project/commit/c0199b2a21705747c999a59bfa77d7fc6e4500a5.diff

LOG: [clang-tidy] Use new mapping matchers

Use mapAnyOf() and matchers based on it.

Use of binaryOperation() means that modernize-loop-convert and
readability-container-size-empty can now be used with rewritten binary
operators.

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index bf1b51049c2c..777d309b5ccb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -21,9 +21,9 @@ namespace bugprone {
 
 static internal::Matcher
 loopEndingStmt(internal::Matcher Internal) {
-  return stmt(anyOf(breakStmt(Internal), returnStmt(Internal),
-gotoStmt(Internal), cxxThrowExpr(Internal),
-callExpr(Internal, callee(functionDecl(isNoReturn());
+  return stmt(anyOf(
+  mapAnyOf(breakStmt, returnStmt, gotoStmt, cxxThrowExpr).with(Internal),
+  callExpr(Internal, callee(functionDecl(isNoReturn());
 }
 
 /// Return whether `Var` was changed in `LoopStmt`.
@@ -122,8 +122,8 @@ void InfiniteLoopCheck::registerMatchers(MatchFinder 
*Finder) {
   unless(hasBody(hasDescendant(
   loopEndingStmt(forFunction(equalsBoundNode("func")));
 
-  Finder->addMatcher(stmt(anyOf(whileStmt(LoopCondition), 
doStmt(LoopCondition),
-forStmt(LoopCondition)))
+  Finder->addMatcher(mapAnyOf(whileStmt, doStmt, forStmt)
+ .with(LoopCondition)
  .bind("loop-stmt"),
  this);
 }

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
index 1a9bea6a5fc8..ee45461ed8f2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
@@ -59,34 +59,20 @@ void 
SpuriouslyWakeUpFunctionsCheck::registerMatchers(MatchFinder *Finder) {
   if (getLangOpts().CPlusPlus) {
 // Check for `CON54-CPP`
 Finder->addMatcher(
-ifStmt(
-allOf(HasWaitDescendantCpp,
-  unless(anyOf(hasDescendant(ifStmt(HasWaitDescendantCpp)),
-   hasDescendant(whileStmt(HasWaitDescendantCpp)),
-   hasDescendant(forStmt(HasWaitDescendantCpp)),
-   hasDescendant(doStmt(HasWaitDescendantCpp)
-
-),
+ifStmt(HasWaitDescendantCpp,
+   unless(hasDescendant(mapAnyOf(ifStmt, whileStmt, forStmt, 
doStmt)
+.with(HasWaitDescendantCpp,
 this);
   } else {
 // Check for `CON36-C`
 Finder->addMatcher(
-ifStmt(
-allOf(HasWaitDescendantC,
-  unless(anyOf(hasDescendant(ifStmt(HasWaitDescendantC)),
-   hasDescendant(whileStmt(HasWaitDescendantC)),
-   hasDescendant(forStmt(HasWaitDescendantC)),
-   hasDescendant(doStmt(HasWaitDescendantC)),
-   hasParent(whileStmt()),
-   hasParent(compoundStmt(hasParent(whileStmt(,
-   hasParent(forStmt()),

[PATCH] D95918: [Coverage] Propogate counter to condition of conditional operator

2021-02-03 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D95918#2540367 , @vsk wrote:

> How was the issue spotted? If there was a crash or an incorrect coverage bug 
> that's not triggered by one of the existing frontend tests, it'd be worth 
> adding a regression test. If the problem can't be replicated without 
> involving llvm-cov, this can be an integration test.

The issue was spotted by @pirama. But this doesn't completely solve the 
problem. When I was investigating the issue, I noticed condition expression of 
conditional operator was not given a counter. So, I sent this patch.

For the issue reported by @pirama, it is that llvm-cov shows following:

  1|   |#include 
  2|   |
  3|  1|int main() {
  4|  1|  return getenv(
  5|  0|  "TEST") ? 1
  6|  1|  : 0;
  7|  1|}

Here are the debug dump.

  Combined regions:
3:12 -> 7:2 (count=1)
4:10 -> 5:14 (count=1)
5:15 -> 5:17 (count=0)
5:17 -> 5:18 (count=0)
6:17 -> 6:18 (count=1)
  Segment at 3:12 (count = 1), RegionEntry
  Segment at 4:10 (count = 1), RegionEntry
  Segment at 5:14 (count = 1)
  Segment at 5:15 (count = 0), Gap
  Segment at 5:17 (count = 0), RegionEntry
  Segment at 5:18 (count = 1)
  Segment at 6:17 (count = 1), RegionEntry
  Segment at 6:18 (count = 1)
  Segment at 7:2 (count = 0), Skipped

I am working on this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95918/new/

https://reviews.llvm.org/D95918

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


[PATCH] D95971: [OpenMP][NVPTX] Take functions in `deviceRTLs` as `convergent`

2021-02-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG, please backport


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95971/new/

https://reviews.llvm.org/D95971

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


[PATCH] D95974: [CUDA, NVPTX] Allow targeting sm_86 GPUs.

2021-02-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D95974#2540352 , @tra wrote:

>> So we add ptx72 but it's not used with sm_86, interesting.
>
> `ptx71` is the minimum/default requited PTX version for sm_86. If we compile 
> with CUDA-11.2, clang will set the '+ptx72' as we may potentially need it in 
> order to link in libdevice bitcode or if source code (e.g CUDA headers) has 
> inline asm with instructions supported by CUDA-11.2.

I see, thanks :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95974/new/

https://reviews.llvm.org/D95974

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


[PATCH] D95911: [Docs] Add some documentation for constructor homing, a debug info optimization (-fuse-ctor-homing)

2021-02-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

lgtm too

In D95911#2538292 , @dblaikie wrote:

> (non-action idle thoughts: Might be worth revisiting this documentation to 
> make it a bit more direct/clearer that many of these optimizations (at least 
> the vtable and ctor homing) rely on the assumption that the class is 
> instantiated somewhere in the program (and that somewhere is built with debug 
> info enabled) (the wording you've got here "This relies on the additional 
> assumption that all classes that are not trivially constructible have a 
> non-trivial constructor that is used somewhere." but maybe 
> generalized/massaged a bit))

Yep. While looking at the existing documentation here, I kept thinking we need 
some standalone documentation on all the debug info features clang supports. 
There is a lot to cover.

- -gmodules
- -g0, -g1 / -gmlt / -gline-tables-only
- -fstandalone-debug
- this unused types thing
- DWARF versions
- PDBs and codeview
- -fno-inline-line-tables
- various attributes (nomerge, not_tail_called, nodebug/artificial)
- -gcolumn-info
- macro info
- -gcodeview-ghash
- fission / split dwarf
- gdb indexes
- pubnames
- -gz
- debugger tuning gdb/lldb
- others


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95911/new/

https://reviews.llvm.org/D95911

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


[clang] 1f06f41 - PR44325 (and duplicates): don't issue -Wzero-as-null-pointer-constant

2021-02-03 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2021-02-03T14:58:53-08:00
New Revision: 1f06f41993b6363e6b2c4f22a13488a3e687f31b

URL: 
https://github.com/llvm/llvm-project/commit/1f06f41993b6363e6b2c4f22a13488a3e687f31b
DIFF: 
https://github.com/llvm/llvm-project/commit/1f06f41993b6363e6b2c4f22a13488a3e687f31b.diff

LOG: PR44325 (and duplicates): don't issue -Wzero-as-null-pointer-constant
when rewriting 'a < b' as '(a <=> b) < 0'.

It's pretty common for comparison category types to use a pointer or
pointer-to-member type as their '0' parameter.

Added: 


Modified: 
clang/lib/Sema/Sema.cpp
clang/test/SemaCXX/cxx2a-three-way-comparison.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 55cb3aee6194..cb5a84a31235 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -537,6 +537,13 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, 
const Expr* E) {
   if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
 return;
 
+  // Don't diagnose the conversion from a 0 literal to a null pointer argument
+  // in a synthesized call to operator<=>.
+  if (!CodeSynthesisContexts.empty() &&
+  CodeSynthesisContexts.back().Kind ==
+  CodeSynthesisContext::RewritingOperatorAsSpaceship)
+return;
+
   // If it is a macro from system header, and if the macro name is not "NULL",
   // do not warn.
   SourceLocation MaybeMacroLoc = E->getBeginLoc();

diff  --git a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp 
b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
index 353360e052bb..b94225274fff 100644
--- a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
+++ b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++2a -verify %s
+// RUN: %clang_cc1 -std=c++2a -verify %s -Wzero-as-null-pointer-constant
 
 // Keep this test before any declarations of operator<=>.
 namespace PR44786 {
@@ -40,3 +40,21 @@ namespace PR47893 {
   int (...);
   int  = f(A(), A());
 }
+
+namespace PR44325 {
+  struct cmp_cat {};
+  bool operator<(cmp_cat, void*);
+  bool operator>(cmp_cat, int cmp_cat::*);
+
+  struct X {};
+  cmp_cat operator<=>(X, X);
+
+  bool b1 = X() < X(); // no warning
+  bool b2 = X() > X(); // no warning
+
+  // FIXME: It's not clear whether warning here is useful, but we can't really
+  // tell that this is a comparison category in general. This is probably OK,
+  // as comparisons against zero are only really intended for use in the
+  // implicit rewrite rules, not for explicit use by programs.
+  bool c = cmp_cat() < 0; // expected-warning {{zero as null pointer constant}}
+}



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


[PATCH] D62574: Add support for target-configurable address spaces.

2021-02-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Sorry for never actually reviewing this.  I have no objection to taking a 
refactor that implements the Embedded C address-space overlap rules even if we 
don't have an in-tree target that uses it.  I'll try to find time to review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62574/new/

https://reviews.llvm.org/D62574

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


[PATCH] D95624: [OpenCL][PR48896] Fix default address space in template argument deduction

2021-02-03 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95624/new/

https://reviews.llvm.org/D95624

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


[PATCH] D95691: Implement P2173 for attributes on lambdas

2021-02-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

The patch seems technically okay to me.  Do we need to recognize lambdas in any 
tentative-parse situations, or is it always the reverse (e.g. recognizing ObjC 
message sends as not-a-lambda)?

The warning is a bit weird.  If we don't think it's certain that the committee 
will adopt this syntax, I don't think we should add this patch at all; it is 
not really acceptable to add it and then treat it as a Clang extension if the 
committee rejects it.  If we do think it's certain, we should go ahead and 
consider this a feature of the next major standard.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95691/new/

https://reviews.llvm.org/D95691

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


[clang] b15cbaf - PR49020: Diagnose brace elision in designated initializers in C++.

2021-02-03 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2021-02-03T14:36:49-08:00
New Revision: b15cbaf5a03d0b32dbc32c37766e32ccf66e6c87

URL: 
https://github.com/llvm/llvm-project/commit/b15cbaf5a03d0b32dbc32c37766e32ccf66e6c87
DIFF: 
https://github.com/llvm/llvm-project/commit/b15cbaf5a03d0b32dbc32c37766e32ccf66e6c87.diff

LOG: PR49020: Diagnose brace elision in designated initializers in C++.

This is a corner of the differences between C99 designators and C++20
designators that we'd previously overlooked. As with other such cases,
this continues to be permitted as an extension and allowed by default,
behind the -Wc99-designators warning flag, except in cases where it
leads to a conformance difference (such as in overload resolution and in
a SFINAE context).

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d31cc76b04d1..61e8f7f28f1c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -214,6 +214,9 @@ def ext_designated_init_reordered : ExtWarn<
   SFINAEFailure;
 def note_previous_field_init : Note<
   "previous initialization for field %0 is here">;
+def ext_designated_init_brace_elision : ExtWarn<
+  "brace elision for designated initializer is a C99 extension">,
+  InGroup, SFINAEFailure;
 
 // Declarations.
 def ext_plain_complex : ExtWarn<

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 4e3547c5121f..640755cec222 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -315,7 +315,8 @@ class InitListChecker {
InitListExpr *IList, QualType ElemType,
unsigned ,
InitListExpr *StructuredList,
-   unsigned );
+   unsigned ,
+   bool DirectlyDesignated = false);
   void CheckComplexType(const InitializedEntity ,
 InitListExpr *IList, QualType DeclType,
 unsigned ,
@@ -1326,7 +1327,8 @@ void InitListChecker::CheckSubElementType(const 
InitializedEntity ,
   QualType ElemType,
   unsigned ,
   InitListExpr *StructuredList,
-  unsigned ) {
+  unsigned ,
+  bool DirectlyDesignated) {
   Expr *expr = IList->getInit(Index);
 
   if (ElemType->isReferenceType())
@@ -1462,6 +1464,20 @@ void InitListChecker::CheckSubElementType(const 
InitializedEntity ,
 CheckImplicitInitList(Entity, IList, ElemType, Index, StructuredList,
   StructuredIndex);
 ++StructuredIndex;
+
+// In C++20, brace elision is not permitted for a designated initializer.
+if (DirectlyDesignated && SemaRef.getLangOpts().CPlusPlus && !hadError) {
+  if (InOverloadResolution)
+hadError = true;
+  if (!VerifyOnly) {
+SemaRef.Diag(expr->getBeginLoc(),
+ diag::ext_designated_init_brace_elision)
+<< expr->getSourceRange()
+<< FixItHint::CreateInsertion(expr->getBeginLoc(), "{")
+<< FixItHint::CreateInsertion(
+   SemaRef.getLocForEndOfToken(expr->getEndLoc()), "}");
+  }
+}
   } else {
 if (!VerifyOnly) {
   // We cannot initialize this element, so let PerformCopyInitialization
@@ -2413,8 +2429,8 @@ InitListChecker::CheckDesignatedInitializer(const 
InitializedEntity ,
 unsigned OldIndex = Index;
 IList->setInit(OldIndex, DIE->getInit());
 
-CheckSubElementType(Entity, IList, CurrentObjectType, Index,
-StructuredList, StructuredIndex);
+CheckSubElementType(Entity, IList, CurrentObjectType, Index, 
StructuredList,
+StructuredIndex, /*DirectlyDesignated=*/true);
 
 // Restore the designated initializer expression in the syntactic
 // form of the initializer list.

diff  --git a/clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp 
b/clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
index 653fcf439c15..c6339116af8b 100644
--- a/clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ b/clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -54,6 +54,10 @@ A a5 = {
   .y = 1, // override-note {{previous}}
   .y = 1 // override-error {{overrides prior initialization}}
 };
+B b2 = {.a = 1}; // pedantic-error {{brace elision for designated initializer 
is a C99 extension}}
+B b3 = {.a = 1, 2}; // pedantic-error {{mixture of designated and 
non-designated}} pedantic-note {{first 

[PATCH] D95971: [OpenMP][NVPTX] Take functions in `deviceRTLs` as `convergent`

2021-02-03 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 321235.
tianshilei1992 added a comment.

Added a test case in FE


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95971/new/

https://reviews.llvm.org/D95971

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/OpenMP/target_attribute_convergent.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp

Index: openmp/libomptarget/test/offloading/bug49021.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/offloading/bug49021.cpp
@@ -0,0 +1,85 @@
+// RUN: %libomptarget-compilexx-aarch64-unknown-linux-gnu -O3 && %libomptarget-run-aarch64-unknown-linux-gnu
+// RUN: %libomptarget-compilexx-powerpc64-ibm-linux-gnu -O3 && %libomptarget-run-powerpc64-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-powerpc64le-ibm-linux-gnu -O3 && %libomptarget-run-powerpc64le-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-x86_64-pc-linux-gnu -O3 && %libomptarget-run-x86_64-pc-linux-gnu
+// RUN: %libomptarget-compilexx-nvptx64-nvidia-cuda -O3 && %libomptarget-run-nvptx64-nvidia-cuda
+
+#include 
+
+template  int test_map() {
+  std::cout << "map(complex<>)" << std::endl;
+  T a(0.2), a_check;
+#pragma omp target map(from : a_check)
+  { a_check = a; }
+
+  if (a_check != a) {
+std::cout << " wrong results";
+return 1;
+  }
+
+  return 0;
+}
+
+template  int test_reduction() {
+  std::cout << "flat parallelism" << std::endl;
+  T sum(0), sum_host(0);
+  const int size = 100;
+  T array[size];
+  for (int i = 0; i < size; i++) {
+array[i] = i;
+sum_host += array[i];
+  }
+
+#pragma omp target teams distribute parallel for map(to: array[:size]) \
+ reduction(+ : sum)
+  for (int i = 0; i < size; i++)
+sum += array[i];
+
+  if (sum != sum_host)
+std::cout << " wrong results " << sum << " host " << sum_host << std::endl;
+
+  std::cout << "hierarchical parallelism" << std::endl;
+  const int nblock(10), block_size(10);
+  T block_sum[nblock];
+#pragma omp target teams distribute map(to \
+: array[:size])\
+map(from   \
+: block_sum[:nblock])
+  for (int ib = 0; ib < nblock; ib++) {
+T partial_sum = 0;
+const int istart = ib * block_size;
+const int iend = (ib + 1) * block_size;
+#pragma omp parallel for reduction(+ : partial_sum)
+for (int i = istart; i < iend; i++)
+  partial_sum += array[i];
+block_sum[ib] = partial_sum;
+  }
+
+  sum = 0;
+  for (int ib = 0; ib < nblock; ib++) {
+sum += block_sum[ib];
+  }
+
+  if (sum != sum_host) {
+std::cout << " wrong results " << sum << " host " << sum_host << std::endl;
+return 1;
+  }
+
+  return 0;
+}
+
+template  int test_complex() {
+  int ret = 0;
+  ret |= test_map();
+  ret |= test_reduction();
+  return ret;
+}
+
+int main() {
+  int ret = 0;
+  std::cout << "Testing float" << std::endl;
+  ret |= test_complex();
+  std::cout << "Testing double" << std::endl;
+  ret |= test_complex();
+  return ret;
+}
Index: clang/test/OpenMP/target_attribute_convergent.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_attribute_convergent.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -o - | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -o - | FileCheck %s
+// expected-no-diagnostics
+
+#pragma omp declare target
+
+void foo() {}
+
+#pragma omp end declare target
+
+// CHECK: Function Attrs: {{.*}}convergent{{.*}}
+// CHECK: define hidden void @_Z3foov() [[ATTRIBUTE_NUMBER:#[0-9]+]]
+// CHECK: attributes [[ATTRIBUTE_NUMBER]] = { {{.*}}convergent{{.*}} }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2441,6 +2441,8 @@
   bool IsTargetSpecified =
   Opts.OpenMPIsDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ);
 
+  Opts.ConvergentFunctions = Opts.ConvergentFunctions || Opts.OpenMPIsDevice;
+
   if (Opts.OpenMP || Opts.OpenMPSimd) {
 if (int Version = getLastArgIntValue(
 Args, OPT_fopenmp_version_EQ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95910: Fix the guaranteed alignment of memory returned by malloc/new on Darwin

2021-02-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

It's 16 bytes on all Darwin platforms, including 32-bit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95910/new/

https://reviews.llvm.org/D95910

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


[PATCH] D95970: [HIP] Allow undefined symbols

2021-02-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D95970#2540303 , @tra wrote:

> What's going to happen if you do have an undefined reference that's *not* to 
> a `__managed__` variable?

By default HIP toolchain uses -fvisibility hidden 
-fapply-global-visibility-to-externs for device compilation. Undefined variable 
symbols have protected visibility. Undefined function symbols have hidden 
visibility. Since they are not allowed to be preempted, lld still emits error 
if they are undefined. `__managed__` variables have default visibility, 
therefore they are allowed to go through.

We can let HIP runtime emit an error if there are undefined symbols other than 
managed variables.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95970/new/

https://reviews.llvm.org/D95970

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


[PATCH] D94131: [clang-tidy] Use new mapAnyOf matcher

2021-02-03 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 321233.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94131/new/

https://reviews.llvm.org/D94131

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty-cxx20.cpp
@@ -0,0 +1,44 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-container-size-empty %t -- -- -fno-delayed-template-parsing
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+template 
+struct OpEqOnly {
+  OpEqOnly();
+  bool operator==(const OpEqOnly ) const;
+  unsigned long size() const;
+  bool empty() const;
+};
+
+template 
+struct HasSpaceshipMem {
+  HasSpaceshipMem();
+  bool operator<=>(const HasSpaceshipMem ) const = default;
+  unsigned long size() const;
+  bool empty() const;
+};
+
+void returnsVoid() {
+  OpEqOnly OEO;
+  HasSpaceshipMem HSM;
+
+  if (OEO != OpEqOnly())
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
+  // CHECK-FIXES: {{^  }}if (!OEO.empty()){{$}}
+  // CHECK-MESSAGES: :18:8: note: method 'OpEqOnly'::empty() defined here
+  if (HSM != HasSpaceshipMem())
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness
+  // CHECK-FIXES: {{^  }}if (!HSM.empty()){{$}}
+  // CHECK-MESSAGES: :25:8: note: method 'HasSpaceshipMem'::empty() defined here
+}
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-rewritten-binop.cpp
@@ -0,0 +1,60 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-loop-convert %t -- -- -I %S/Inputs/modernize-loop-convert
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+struct HasSpaceshipMem {
+  typedef int value_type;
+
+  struct iterator {
+value_type *();
+const value_type *() const;
+iterator ++();
+void insert(value_type);
+value_type X;
+constexpr auto operator<=>(const HasSpaceshipMem::iterator &) const = default;
+  };
+
+  iterator begin();
+  iterator end();
+};
+
+struct OpEqOnly {
+  typedef int value_type;
+  struct iterator {
+value_type *();
+const value_type *() const;
+iterator ++();
+bool operator==(const iterator ) const;
+void insert(value_type);
+value_type X;
+  };
+  iterator begin();
+  iterator end();
+};
+
+void rewritten() {
+  OpEqOnly Oeo;
+  for (OpEqOnly::iterator It = Oeo.begin(), E = Oeo.end(); It != E; ++It) {
+(void)*It;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & It : Oeo)
+  // CHECK-FIXES-NEXT: (void)It;
+
+  HasSpaceshipMem Hsm;
+  for (HasSpaceshipMem::iterator It = Hsm.begin(), E = Hsm.end(); It != E; ++It) {
+(void)*It;
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (int & It : Hsm)
+  // CHECK-FIXES-NEXT: (void)It;
+}
Index: 

[PATCH] D95166: Disable rosegment for old Android versions.

2021-02-03 Thread Dan Albert via Phabricator via cfe-commits
danalbert added a comment.

> We've since added -fuse-ld=lld to the three CMAKE_*_FLAGS so I think we're 
> likely set on our end.

https://reviews.llvm.org/D76452 not being accepted means that Android 
toolchains must have LLD installed as `ld`. I'm guessing this thread has shown 
that the patch is worth doing so I can fix this in a more compatible way.

> If there's some way to build android compiler-rt runtimes as part of a 
> regular linux llvm build, we'd love to learn about that :)

afaik CMake makes this impossible because one build has exactly one target :(


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95166/new/

https://reviews.llvm.org/D95166

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


[PATCH] D95918: [Coverage] Propogate counter to condition of conditional operator

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

How was the issue spotted? If there was a crash or an incorrect coverage bug 
that's not triggered by one of the existing frontend tests, it'd be worth 
adding a regression test. If the problem can't be replicated without involving 
llvm-cov, this can be an integration test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95918/new/

https://reviews.llvm.org/D95918

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


[PATCH] D69322: [hip][cuda] Enable extended lambda support on Windows.

2021-02-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

Looks good with one suggestion.




Comment at: clang/include/clang/AST/ASTContext.h:540
   llvm::MapVector MangleNumbers;
   llvm::MapVector StaticLocalNumbers;
 

This is a nit, but I'd group the device mangling number map here with the other 
mangling number side tables.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69322/new/

https://reviews.llvm.org/D69322

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


[PATCH] D95974: [CUDA, NVPTX] Allow targeting sm_86 GPUs.

2021-02-03 Thread Artem Belevich via Phabricator via cfe-commits
tra marked an inline comment as done.
tra added a comment.

> So we add ptx72 but it's not used with sm_86, interesting.

`ptx71` is the minimum/default requited PTX version for sm_86. If we compile 
with CUDA-11.2, clang will set the '+ptx72' as we may potentially need it in 
order to link in libdevice bitcode or if source code (e.g CUDA headers) has 
inline asm with instructions supported by CUDA-11.2.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95974/new/

https://reviews.llvm.org/D95974

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


[PATCH] D95974: [CUDA, NVPTX] Allow targeting sm_86 GPUs.

2021-02-03 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 321220.
tra edited the summary of this revision.
tra added a comment.

Removed debug printout


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95974/new/

https://reviews.llvm.org/D95974

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  llvm/lib/Target/NVPTX/NVPTX.td

Index: llvm/lib/Target/NVPTX/NVPTX.td
===
--- llvm/lib/Target/NVPTX/NVPTX.td
+++ llvm/lib/Target/NVPTX/NVPTX.td
@@ -57,6 +57,8 @@
  "Target SM 7.5">;
 def SM80 : SubtargetFeature<"sm_80", "SmVersion", "80",
  "Target SM 8.0">;
+def SM86 : SubtargetFeature<"sm_86", "SmVersion", "86",
+ "Target SM 8.6">;
 
 // PTX Versions
 def PTX32 : SubtargetFeature<"ptx32", "PTXVersion", "32",
@@ -83,6 +85,10 @@
  "Use PTX version 6.5">;
 def PTX70 : SubtargetFeature<"ptx70", "PTXVersion", "70",
  "Use PTX version 7.0">;
+def PTX71 : SubtargetFeature<"ptx71", "PTXVersion", "71",
+ "Use PTX version 7.1">;
+def PTX72 : SubtargetFeature<"ptx72", "PTXVersion", "72",
+ "Use PTX version 7.2">;
 
 //===--===//
 // NVPTX supported processors.
@@ -107,6 +113,7 @@
 def : Proc<"sm_72", [SM72, PTX61]>;
 def : Proc<"sm_75", [SM75, PTX63]>;
 def : Proc<"sm_80", [SM80, PTX70]>;
+def : Proc<"sm_86", [SM86, PTX71]>;
 
 def NVPTXInstrInfo : InstrInfo {
 }
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -75,6 +75,8 @@
 return CudaVersion::CUDA_102;
   if (raw_version < 11010)
 return CudaVersion::CUDA_110;
+  if (raw_version < 11020)
+return CudaVersion::CUDA_111;
   return CudaVersion::LATEST;
 }
 
@@ -724,6 +726,8 @@
 CudaVersionStr = #CUDA_VER;\
 PtxFeature = "+ptx" #PTX_VER;  \
 break;
+CASE_CUDA_VERSION(112, 72);
+CASE_CUDA_VERSION(111, 71);
 CASE_CUDA_VERSION(110, 70);
 CASE_CUDA_VERSION(102, 65);
 CASE_CUDA_VERSION(101, 64);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -4613,6 +4613,7 @@
   case CudaArch::SM_72:
   case CudaArch::SM_75:
   case CudaArch::SM_80:
+  case CudaArch::SM_86:
   case CudaArch::GFX600:
   case CudaArch::GFX601:
   case CudaArch::GFX602:
@@ -4680,6 +4681,7 @@
   case CudaArch::SM_72:
   case CudaArch::SM_75:
   case CudaArch::SM_80:
+  case CudaArch::SM_86:
 return {84, 32};
   case CudaArch::GFX600:
   case CudaArch::GFX601:
Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -45,6 +45,8 @@
 if (!Feature.startswith("+ptx"))
   continue;
 PTXVersion = llvm::StringSwitch(Feature)
+ .Case("+ptx72", 72)
+ .Case("+ptx71", 71)
  .Case("+ptx70", 70)
  .Case("+ptx65", 65)
  .Case("+ptx64", 64)
@@ -246,6 +248,8 @@
 return "750";
   case CudaArch::SM_80:
 return "800";
+  case CudaArch::SM_86:
+return "860";
   }
   llvm_unreachable("unhandled CudaArch");
 }();
Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -32,6 +32,10 @@
 return "10.2";
   case CudaVersion::CUDA_110:
 return "11.0";
+  case CudaVersion::CUDA_111:
+return "11.1";
+  case CudaVersion::CUDA_112:
+return "11.2";
   }
   llvm_unreachable("invalid enum");
 }
@@ -48,6 +52,8 @@
   .Case("10.1", CudaVersion::CUDA_101)
   .Case("10.2", CudaVersion::CUDA_102)
   .Case("11.0", CudaVersion::CUDA_110)
+  .Case("11.1", CudaVersion::CUDA_111)
+  .Case("11.2", CudaVersion::CUDA_112)
   .Default(CudaVersion::UNKNOWN);
 }
 
@@ -71,7 +77,7 @@
 SM(60), SM(61), SM(62),  // Pascal
 SM(70), SM(72),  // Volta
 SM(75),  // Turing
-SM(80),  // Ampere
+SM(80), SM(86),  // Ampere
 GFX(600),  // gfx600
 GFX(601),  // gfx601
 GFX(602),  // gfx602
@@ -164,6 +170,8 @@
 return CudaVersion::CUDA_100;
   

[PATCH] D95976: [OpenMP] Simplify offloading parallel call codegen

2021-02-03 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis created this revision.
Herald added subscribers: jfb, guansong, yaxunl.
ggeorgakoudis requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, openmp-commits, cfe-commits, sstefan1.
Herald added projects: clang, OpenMP, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95976

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
  openmp/libomptarget/deviceRTLs/common/src/parallel.cu
  openmp/libomptarget/deviceRTLs/common/src/support.cu
  openmp/libomptarget/deviceRTLs/common/support.h
  openmp/libomptarget/deviceRTLs/interface.h

Index: openmp/libomptarget/deviceRTLs/interface.h
===
--- openmp/libomptarget/deviceRTLs/interface.h
+++ openmp/libomptarget/deviceRTLs/interface.h
@@ -177,6 +177,7 @@
  * The struct is identical to the one in the kmp.h file.
  * We maintain the same data structure for compatibility.
  */
+typedef short kmp_int16;
 typedef int kmp_int32;
 typedef struct ident {
   kmp_int32 reserved_1; /**<  might be used in Fortran; see above  */
@@ -437,6 +438,23 @@
 EXTERN void __kmpc_end_sharing_variables();
 EXTERN void __kmpc_get_shared_variables(void ***GlobalArgs);
 
+/// Entry point to start a new parallel region.
+///
+/// \param ident   The source identifier.
+/// \param global_tid  The global thread ID.
+/// \param if_expr The if(expr), or 1 if none given.
+/// \param num_threads The num_threads(expr), or -1 if none given.
+/// \param proc_bind   The proc_bind, or `proc_bind_default` if none given.
+/// \param fn  The outlined parallel region function.
+/// \param wrapper_fn  The worker wrapper function for the outlined parallel
+/// region. \param argsThe pointer array of arguments to the outlined
+/// region function. \param nargs   The number of arguments to the outlined
+/// region function.
+EXTERN void __kmpc_parallel_51(ident_t *ident, kmp_int32 global_tid,
+   kmp_int32 if_expr, kmp_int32 num_threads,
+   int proc_bind, void *fn, void *wrapper_fn,
+   void **SharedArgs, size_t nArgs);
+
 // SPMD execution mode interrogation function.
 EXTERN int8_t __kmpc_is_spmd_exec_mode();
 
Index: openmp/libomptarget/deviceRTLs/common/support.h
===
--- openmp/libomptarget/deviceRTLs/common/support.h
+++ openmp/libomptarget/deviceRTLs/common/support.h
@@ -95,4 +95,9 @@
 DEVICE unsigned int *GetTeamsReductionTimestamp();
 DEVICE char *GetTeamsReductionScratchpad();
 
+// Invoke an outlined parallel function unwrapping global, shared arguments (up
+// to 16).
+DEVICE void __kmp_invoke_microtask(kmp_int32 global_tid, kmp_int32 bound_tid,
+   void *fn, void **args, size_t nargs);
+
 #endif
Index: openmp/libomptarget/deviceRTLs/common/src/support.cu
===
--- openmp/libomptarget/deviceRTLs/common/src/support.cu
+++ openmp/libomptarget/deviceRTLs/common/src/support.cu
@@ -265,4 +265,109 @@
   return static_cast(ReductionScratchpadPtr) + 256;
 }
 
+// Invoke an outlined parallel function unwrapping global, shared arguments (up to 16).
+DEVICE void __kmp_invoke_microtask(kmp_int32 global_tid, kmp_int32 bound_tid,
+   void *fn, void **args, size_t nargs) {
+  switch (nargs) {
+  case 0:
+((void (*)(kmp_int32 *, kmp_int32 *))fn)(_tid, _tid);
+break;
+  case 1:
+((void (*)(kmp_int32 *, kmp_int32 *, void *))fn)(_tid, _tid,
+ args[0]);
+break;
+  case 2:
+((void (*)(kmp_int32 *, kmp_int32 *, void *, void *))fn)(
+_tid, _tid, args[0], args[1]);
+break;
+  case 3:
+((void (*)(kmp_int32 *, kmp_int32 *, void *, void *, void *))fn)(
+_tid, _tid, args[0], args[1], args[2]);
+break;
+  case 4:
+((void (*)(kmp_int32 *, kmp_int32 *, void *, void *, void *, void *))fn)(
+_tid, _tid, args[0], args[1], args[2], args[3]);
+break;
+  case 5:
+((void (*)(kmp_int32 *, kmp_int32 *, void *, void *, void *, void *,
+   void *))fn)(_tid, _tid, args[0], args[1], args[2],
+   args[3], args[4]);
+break;
+  case 6:
+((void (*)(kmp_int32 *, kmp_int32 *, void *, void *, void *, void *, void *,
+   void *))fn)(_tid, _tid, args[0], args[1], args[2],
+   args[3], args[4], args[5]);
+break;
+  case 7:
+((void (*)(kmp_int32 *, kmp_int32 *, void *, void *, void *, void *, void *,
+   void *, void *))fn)(_tid, _tid, args[0], args[1],
+   args[2], args[3], args[4], args[5], args[6]);
+break;
+  case 8:
+((void (*)(kmp_int32 *, 

[PATCH] D95901: [CUDA][HIP] Fix device variable linkage

2021-02-03 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:11437-11443
+  return ((!getLangOpts().GPURelocatableDeviceCode &&
+   ((D->hasAttr() &&
+ !D->getAttr()->isImplicit()) ||
+(D->hasAttr() &&
+ !D->getAttr()->isImplicit( ||
   D->hasAttr()) &&
  isa(D) && cast(D)->getStorageClass() == SC_Static;

tra wrote:
> yaxunl wrote:
> > tra wrote:
> > > I can't parse it. :-( Perhaps we can split it.
> > revised
> I still can't read it. way too many nested operands to logical operators...
> 
> I was thinking of extracting parts of the equation into early returns or 
> intermediate variables.
> 
Thank you for refactoring this. Now it's soo much easier to see what's going on.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95901/new/

https://reviews.llvm.org/D95901

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


[PATCH] D91944: OpenMP 5.0 metadirective

2021-02-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.

Asssuming this passes the tests I'll merge it as is. There are unresolved 
review requests, e.g., custom implementation instead of balanced parenthesis 
trackers, the template support, etc.
but we decided we can make faster progress in tree once this is merged.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91944/new/

https://reviews.llvm.org/D91944

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


[PATCH] D95974: [CUDA, NVPTX] Allow targeting sm_86 GPUs.

2021-02-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

One nit below. Seems reasonable in general.

So we add ptx72 but it's not used with sm_86, interesting.




Comment at: clang/lib/Driver/ToolChains/Cuda.cpp:103
   Line->consumeInteger(10, RawVersion);
+  llvm::errs() << "raw = " << RawVersion << "\n";
   return {"cuda.h: CUDA_VERSION=" + Twine(RawVersion).str() + ".",

leftover?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95974/new/

https://reviews.llvm.org/D95974

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


[PATCH] D95970: [HIP] Allow undefined symbols

2021-02-03 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

What's going to happen if you do have an undefined reference that's *not* to a 
`__managed__` variable?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95970/new/

https://reviews.llvm.org/D95970

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


[PATCH] D95971: [OpenMP][NVPTX] Take functions in `deviceRTLs` as `convergent`

2021-02-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Please check in a clang FE test for the attribute as well, we have plenty test 
that use -fopenmp-is-device or add one as you see fit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95971/new/

https://reviews.llvm.org/D95971

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


[PATCH] D95166: Disable rosegment for old Android versions.

2021-02-03 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In D95166#2531194 , @danalbert wrote:

> In D95166#2530791 , @thakis wrote:
>
>> Landed revert in 1608ba09462d877111230e9461b895f696f8fcb1 
>> . 
>> Someone should file a PR to make sure that gets merged to the 12.0 branch.
>>
>> We can then reland on trunk once there are clear instructions for folks 
>> building with trunk clang but old NDK but without the toolchain file (either 
>> "use toolchain file" or "set LLVM_USE_LLD" or something like that, I'm 
>> guessing?)
>
> The instructions would be "use the whole toolchain, don't mix and match". 
> Where should that be documented?

I don't know what "use the whole toolchain, don't mix and match" means.

In our case, we were building compiler-rt for android by running

  cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON 
"-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;lld;chrometools;clang-tools-extra" 
"-DLLVM_TARGETS_TO_BUILD=AArch64;ARM;Mips;PowerPC;SystemZ;WebAssembly;X86" 
-DLLVM_ENABLE_PIC=OFF -DLLVM_ENABLE_UNWIND_TABLES=OFF 
-DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_Z3_SOLVER=OFF 
-DCLANG_PLUGIN_SUPPORT=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF 
-DCLANG_ENABLE_ARCMT=OFF "-DBUG_REPORT_URL=https://crbug.com and run 
tools/clang/scripts/process_crashreports.py (only works inside Google) which 
will upload a report" -DLLVM_INCLUDE_GO_TESTS=OFF 
-DENABLE_X86_RELAX_RELOCATIONS=NO -DLLVM_ENABLE_DIA_SDK=OFF 
-DLLVM_LOCAL_RPATH=$HOME/src/chrome/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/lib64
 
"-DCOMPILER_RT_TEST_COMPILER_CFLAGS=--gcc-toolchain=$HOME/src/chrome/src/third_party/llvm-build-tools/gcc-10.2.0-trusty
 
-Wl,-rpath,$HOME/src/chrome/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/lib64
 
-Wl,-rpath,$HOME/src/chrome/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/lib32"
 -DLLVM_ENABLE_LIBXML2=FORCE_ON 
-DCMAKE_C_COMPILER=$HOME/src/chrome/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/bin/gcc
 
-DCMAKE_CXX_COMPILER=$HOME/src/chrome/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/bin/g++
 
-DCMAKE_C_COMPILER=$HOME/src/chrome/src/third_party/llvm-build/Release+Asserts/bin/clang
 
-DCMAKE_CXX_COMPILER=$HOME/src/chrome/src/third_party/llvm-build/Release+Asserts/bin/clang++
 
-DLLVM_CONFIG_PATH=$HOME/src/chrome/src/third_party/llvm-build/Release+Asserts/bin/llvm-config
 "-DCMAKE_C_FLAGS=--target=aarch64-linux-android21 
--sysroot=$HOME/src/chrome/src/third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot
 
--gcc-toolchain=$HOME/src/chrome/src/third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64"
 "-DCMAKE_CXX_FLAGS=--target=aarch64-linux-android21 
--sysroot=$HOME/src/chrome/src/third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot
 
--gcc-toolchain=$HOME/src/chrome/src/third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64"
 "-DCMAKE_ASM_FLAGS=--target=aarch64-linux-android21 
--sysroot=$HOME/src/chrome/src/third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot
 
--gcc-toolchain=$HOME/src/chrome/src/third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64"
 -DCOMPILER_RT_BUILD_BUILTINS=OFF -DCOMPILER_RT_BUILD_CRT=OFF 
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF -DCOMPILER_RT_BUILD_MEMPROF=OFF 
-DCOMPILER_RT_BUILD_PROFILE=ON -DCOMPILER_RT_BUILD_SANITIZERS=ON 
-DCOMPILER_RT_BUILD_XRAY=OFF -DSANITIZER_CXX_ABI=libcxxabi 
-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-u__cxa_demangle -DANDROID=1 

in an `android-aarch64` subdir of a linux llvm build dir (and similar for other 
archs).

We've since added `-fuse-ld=lld` to the three `CMAKE_*_FLAGS` so I think we're 
likely set on our end.

If there's some way to build android compiler-rt runtimes as part of a regular 
linux llvm build, we'd love to learn about that :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95166/new/

https://reviews.llvm.org/D95166

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


[PATCH] D95974: [CUDA, NVPTX] Allow targeting sm_86 GPUs.

2021-02-03 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
tra added reviewers: yaxunl, jdoerfert.
Herald added subscribers: dexonsmith, bixia, hiraditya, jholewinski.
tra requested review of this revision.
Herald added projects: clang, LLVM.

The patch only plumbs through the option necessary for targeting sm_86 GPUs w/o 
adding any new functionality.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95974

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  llvm/lib/Target/NVPTX/NVPTX.td

Index: llvm/lib/Target/NVPTX/NVPTX.td
===
--- llvm/lib/Target/NVPTX/NVPTX.td
+++ llvm/lib/Target/NVPTX/NVPTX.td
@@ -57,6 +57,8 @@
  "Target SM 7.5">;
 def SM80 : SubtargetFeature<"sm_80", "SmVersion", "80",
  "Target SM 8.0">;
+def SM86 : SubtargetFeature<"sm_86", "SmVersion", "86",
+ "Target SM 8.6">;
 
 // PTX Versions
 def PTX32 : SubtargetFeature<"ptx32", "PTXVersion", "32",
@@ -83,6 +85,10 @@
  "Use PTX version 6.5">;
 def PTX70 : SubtargetFeature<"ptx70", "PTXVersion", "70",
  "Use PTX version 7.0">;
+def PTX71 : SubtargetFeature<"ptx71", "PTXVersion", "71",
+ "Use PTX version 7.1">;
+def PTX72 : SubtargetFeature<"ptx72", "PTXVersion", "72",
+ "Use PTX version 7.2">;
 
 //===--===//
 // NVPTX supported processors.
@@ -107,6 +113,7 @@
 def : Proc<"sm_72", [SM72, PTX61]>;
 def : Proc<"sm_75", [SM75, PTX63]>;
 def : Proc<"sm_80", [SM80, PTX70]>;
+def : Proc<"sm_86", [SM86, PTX71]>;
 
 def NVPTXInstrInfo : InstrInfo {
 }
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -75,6 +75,8 @@
 return CudaVersion::CUDA_102;
   if (raw_version < 11010)
 return CudaVersion::CUDA_110;
+  if (raw_version < 11020)
+return CudaVersion::CUDA_111;
   return CudaVersion::LATEST;
 }
 
@@ -98,6 +100,7 @@
 StartsWithWords(Input.ltrim(), {"#", "define", "CUDA_VERSION"})) {
   uint32_t RawVersion;
   Line->consumeInteger(10, RawVersion);
+  llvm::errs() << "raw = " << RawVersion << "\n";
   return {"cuda.h: CUDA_VERSION=" + Twine(RawVersion).str() + ".",
   getCudaVersion(RawVersion)};
 }
@@ -724,6 +727,8 @@
 CudaVersionStr = #CUDA_VER;\
 PtxFeature = "+ptx" #PTX_VER;  \
 break;
+CASE_CUDA_VERSION(112, 72);
+CASE_CUDA_VERSION(111, 71);
 CASE_CUDA_VERSION(110, 70);
 CASE_CUDA_VERSION(102, 65);
 CASE_CUDA_VERSION(101, 64);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -4613,6 +4613,7 @@
   case CudaArch::SM_72:
   case CudaArch::SM_75:
   case CudaArch::SM_80:
+  case CudaArch::SM_86:
   case CudaArch::GFX600:
   case CudaArch::GFX601:
   case CudaArch::GFX602:
@@ -4680,6 +4681,7 @@
   case CudaArch::SM_72:
   case CudaArch::SM_75:
   case CudaArch::SM_80:
+  case CudaArch::SM_86:
 return {84, 32};
   case CudaArch::GFX600:
   case CudaArch::GFX601:
Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -45,6 +45,8 @@
 if (!Feature.startswith("+ptx"))
   continue;
 PTXVersion = llvm::StringSwitch(Feature)
+ .Case("+ptx72", 72)
+ .Case("+ptx71", 71)
  .Case("+ptx70", 70)
  .Case("+ptx65", 65)
  .Case("+ptx64", 64)
@@ -246,6 +248,8 @@
 return "750";
   case CudaArch::SM_80:
 return "800";
+  case CudaArch::SM_86:
+return "860";
   }
   llvm_unreachable("unhandled CudaArch");
 }();
Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -32,6 +32,10 @@
 return "10.2";
   case CudaVersion::CUDA_110:
 return "11.0";
+  case CudaVersion::CUDA_111:
+return "11.1";
+  case CudaVersion::CUDA_112:
+return "11.2";
   }
   llvm_unreachable("invalid enum");
 }
@@ -48,6 +52,8 @@
   .Case("10.1", CudaVersion::CUDA_101)
   .Case("10.2", CudaVersion::CUDA_102)
   .Case("11.0", CudaVersion::CUDA_110)
+  .Case("11.1", CudaVersion::CUDA_111)
+   

[clang] 4dc08cc - [Coverage] Propogate counter to condition of conditional operator

2021-02-03 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2021-02-03T13:33:22-08:00
New Revision: 4dc08cc3aa41a28ca6ec82bb9c7183048761aad5

URL: 
https://github.com/llvm/llvm-project/commit/4dc08cc3aa41a28ca6ec82bb9c7183048761aad5
DIFF: 
https://github.com/llvm/llvm-project/commit/4dc08cc3aa41a28ca6ec82bb9c7183048761aad5.diff

LOG: [Coverage] Propogate counter to condition of conditional operator

Clang usually propagates counter mapping region for conditions of `if`, `while`,
`for`, etc from parent counter. We should do the same for condition of 
conditional operator.

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

Added: 


Modified: 
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/test/CoverageMapping/if.cpp
clang/test/CoverageMapping/macro-expressions.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 5c25c204cc0b..4ebdaf64879d 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1462,7 +1462,7 @@ struct CounterCoverageMappingBuilder
 Counter ParentCount = getRegion().getCounter();
 Counter TrueCount = getRegionCounter(E);
 
-Visit(E->getCond());
+propagateCounts(ParentCount, E->getCond());
 
 if (!isa(E)) {
   // The 'then' count applies to the area immediately after the condition.

diff  --git a/clang/test/CoverageMapping/if.cpp 
b/clang/test/CoverageMapping/if.cpp
index 0dd9b016a5ac..3c3a76a8c46a 100644
--- a/clang/test/CoverageMapping/if.cpp
+++ b/clang/test/CoverageMapping/if.cpp
@@ -3,7 +3,8 @@
 int nop() { return 0; }
 
 // CHECK-LABEL: _Z3foov:
-// CHECK-NEXT: [[@LINE+2]]:12 -> [[@LINE+7]]:2 
= #0
+// CHECK-NEXT: [[@LINE+3]]:12 -> [[@LINE+8]]:2 
= #0
+// CHECK-NEXT: [[@LINE+3]]:15 -> 
[[@LINE+3]]:19 = #0
 // CHECK-NEXT: Branch,File 0, [[@LINE+2]]:15 
-> [[@LINE+2]]:19 = 0, 0
 void foo() {// CHECK-NEXT: Gap,File 0, [[@LINE+1]]:20 -> 
[[@LINE+1]]:22 = #2
   if (int j = true ? nop()  // CHECK-NEXT: [[@LINE]]:22 -> [[@LINE]]:27 = 
#2
@@ -38,11 +39,13 @@ int main() {// CHECK: File 0, 
[[@LINE]]:12 -> {{[0-9]+}}:2 =
 i = 3;  // CHECK-NEXT: File 0, [[@LINE-1]]:10 -> 
[[@LINE+1]]:4 = (#0 - #4)
   }
 
+// CHECK-NEXT: File 0, [[@LINE+2]]:7 -> 
[[@LINE+2]]:13 = #0
 // CHECK-NEXT: Branch,File 0, [[@LINE+1]]:7 -> 
[[@LINE+1]]:13 = #5, (#0 - #5)
   i = i == 0?   // CHECK-NEXT: Gap,File 0, [[@LINE]]:13 -> 
[[@LINE+1]]:9 = #5
 i + 1 : // CHECK-NEXT: File 0, [[@LINE]]:9 -> 
[[@LINE]]:14 = #5
 i + 2;  // CHECK-NEXT: File 0, [[@LINE]]:9 -> 
[[@LINE]]:14 = (#0 - #5)
 
+// CHECK-NEXT: File 0, [[@LINE+4]]:7 -> 
[[@LINE+4]]:13 = #0
 // CHECK-NEXT: Branch,File 0, [[@LINE+3]]:7 -> 
[[@LINE+3]]:13 = #6, (#0 - #6)
 // CHECK-NEXT: Gap,File 0, [[@LINE+2]]:13 -> 
[[@LINE+2]]:14 = #6
 // CHECK-NEXT: File 0, [[@LINE+1]]:14 -> 
[[@LINE+1]]:20 = #6

diff  --git a/clang/test/CoverageMapping/macro-expressions.cpp 
b/clang/test/CoverageMapping/macro-expressions.cpp
index 18c2a7fa8e3a..2f509281274c 100644
--- a/clang/test/CoverageMapping/macro-expressions.cpp
+++ b/clang/test/CoverageMapping/macro-expressions.cpp
@@ -83,20 +83,23 @@ void foo(int i) {
   // CHECK: File 0, [[@LINE+1]]:42 -> [[@LINE+1]]:44 = #7
   for (DECL(int, j) : ARR(int, 1, 2, 3)) {}
 
+  // CHECK-NEXT: File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #0
   // CHECK-NEXT: Branch,File 0, [[@LINE+3]]:10 -> [[@LINE+3]]:11 = #8, (#0 - 
#8)
   // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:20 = #0
   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:23 -> [[@LINE+1]]:29 = #0
   (void)(i ? PRIo64 : PRIu64);
 
+  // CHECK-NEXT: File 0, [[@LINE+6]]:10 -> [[@LINE+6]]:11 = #0
   // CHECK: File 0, [[@LINE+5]]:14 -> [[@LINE+5]]:15 = #9
-  // CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:18 -> [[@LINE+4]]:22 = (#0 - #9)
-  // CHECK-NEXT: File 0, [[@LINE+3]]:22 -> [[@LINE+3]]:33 = (#0 - #9)
+  // CHECK-NEXT: File 0, [[@LINE+4]]:18 -> [[@LINE+4]]:33 = (#0 - #9)
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:18 -> [[@LINE+3]]:22 = (#0 - #9)
   // CHECK: File 0, [[@LINE+2]]:28 -> [[@LINE+2]]:29 = #10
   // CHECK-NEXT: File 0, [[@LINE+1]]:32 -> [[@LINE+1]]:33 = ((#0 - #9) - #10)
   (void)(i ? i : EXPR(i) ? i : 0);
+  // CHECK-NEXT: File 0, [[@LINE+5]]:10 -> [[@LINE+5]]:11 = #0
   // CHECK-NEXT: Branch,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #11, (#0 - 
#11)
-  // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:15 -> [[@LINE+3]]:19 = (#0 - 
#11)
-  // CHECK-NEXT: File 0, [[@LINE+2]]:19 -> [[@LINE+2]]:27 = (#0 - #11)
+  

[PATCH] D95918: [Coverage] Propogate counter to condition of conditional operator

2021-02-03 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4dc08cc3aa41: [Coverage] Propogate counter to condition of 
conditional operator (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95918/new/

https://reviews.llvm.org/D95918

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/if.cpp
  clang/test/CoverageMapping/macro-expressions.cpp


Index: clang/test/CoverageMapping/macro-expressions.cpp
===
--- clang/test/CoverageMapping/macro-expressions.cpp
+++ clang/test/CoverageMapping/macro-expressions.cpp
@@ -83,20 +83,23 @@
   // CHECK: File 0, [[@LINE+1]]:42 -> [[@LINE+1]]:44 = #7
   for (DECL(int, j) : ARR(int, 1, 2, 3)) {}
 
+  // CHECK-NEXT: File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #0
   // CHECK-NEXT: Branch,File 0, [[@LINE+3]]:10 -> [[@LINE+3]]:11 = #8, (#0 - 
#8)
   // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:20 = #0
   // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:23 -> [[@LINE+1]]:29 = #0
   (void)(i ? PRIo64 : PRIu64);
 
+  // CHECK-NEXT: File 0, [[@LINE+6]]:10 -> [[@LINE+6]]:11 = #0
   // CHECK: File 0, [[@LINE+5]]:14 -> [[@LINE+5]]:15 = #9
-  // CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:18 -> [[@LINE+4]]:22 = (#0 - #9)
-  // CHECK-NEXT: File 0, [[@LINE+3]]:22 -> [[@LINE+3]]:33 = (#0 - #9)
+  // CHECK-NEXT: File 0, [[@LINE+4]]:18 -> [[@LINE+4]]:33 = (#0 - #9)
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:18 -> [[@LINE+3]]:22 = (#0 - #9)
   // CHECK: File 0, [[@LINE+2]]:28 -> [[@LINE+2]]:29 = #10
   // CHECK-NEXT: File 0, [[@LINE+1]]:32 -> [[@LINE+1]]:33 = ((#0 - #9) - #10)
   (void)(i ? i : EXPR(i) ? i : 0);
+  // CHECK-NEXT: File 0, [[@LINE+5]]:10 -> [[@LINE+5]]:11 = #0
   // CHECK-NEXT: Branch,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #11, (#0 - 
#11)
-  // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:15 -> [[@LINE+3]]:19 = (#0 - 
#11)
-  // CHECK-NEXT: File 0, [[@LINE+2]]:19 -> [[@LINE+2]]:27 = (#0 - #11)
+  // CHECK-NEXT: File 0, [[@LINE+3]]:15 -> [[@LINE+3]]:27 = (#0 - #11)
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:19 = (#0 - 
#11)
   // CHECK-NEXT: File 0, [[@LINE+1]]:26 -> [[@LINE+1]]:27 = ((#0 - #11) - #12)
   (void)(i ?: EXPR(i) ?: 0);
 }
Index: clang/test/CoverageMapping/if.cpp
===
--- clang/test/CoverageMapping/if.cpp
+++ clang/test/CoverageMapping/if.cpp
@@ -3,7 +3,8 @@
 int nop() { return 0; }
 
 // CHECK-LABEL: _Z3foov:
-// CHECK-NEXT: [[@LINE+2]]:12 -> [[@LINE+7]]:2 
= #0
+// CHECK-NEXT: [[@LINE+3]]:12 -> [[@LINE+8]]:2 
= #0
+// CHECK-NEXT: [[@LINE+3]]:15 -> 
[[@LINE+3]]:19 = #0
 // CHECK-NEXT: Branch,File 0, [[@LINE+2]]:15 
-> [[@LINE+2]]:19 = 0, 0
 void foo() {// CHECK-NEXT: Gap,File 0, [[@LINE+1]]:20 -> 
[[@LINE+1]]:22 = #2
   if (int j = true ? nop()  // CHECK-NEXT: [[@LINE]]:22 -> [[@LINE]]:27 = 
#2
@@ -38,11 +39,13 @@
 i = 3;  // CHECK-NEXT: File 0, [[@LINE-1]]:10 -> 
[[@LINE+1]]:4 = (#0 - #4)
   }
 
+// CHECK-NEXT: File 0, [[@LINE+2]]:7 -> 
[[@LINE+2]]:13 = #0
 // CHECK-NEXT: Branch,File 0, [[@LINE+1]]:7 -> 
[[@LINE+1]]:13 = #5, (#0 - #5)
   i = i == 0?   // CHECK-NEXT: Gap,File 0, [[@LINE]]:13 -> 
[[@LINE+1]]:9 = #5
 i + 1 : // CHECK-NEXT: File 0, [[@LINE]]:9 -> 
[[@LINE]]:14 = #5
 i + 2;  // CHECK-NEXT: File 0, [[@LINE]]:9 -> 
[[@LINE]]:14 = (#0 - #5)
 
+// CHECK-NEXT: File 0, [[@LINE+4]]:7 -> 
[[@LINE+4]]:13 = #0
 // CHECK-NEXT: Branch,File 0, [[@LINE+3]]:7 -> 
[[@LINE+3]]:13 = #6, (#0 - #6)
 // CHECK-NEXT: Gap,File 0, [[@LINE+2]]:13 -> 
[[@LINE+2]]:14 = #6
 // CHECK-NEXT: File 0, [[@LINE+1]]:14 -> 
[[@LINE+1]]:20 = #6
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1462,7 +1462,7 @@
 Counter ParentCount = getRegion().getCounter();
 Counter TrueCount = getRegionCounter(E);
 
-Visit(E->getCond());
+propagateCounts(ParentCount, E->getCond());
 
 if (!isa(E)) {
   // The 'then' count applies to the area immediately after the condition.


Index: clang/test/CoverageMapping/macro-expressions.cpp
===
--- clang/test/CoverageMapping/macro-expressions.cpp
+++ clang/test/CoverageMapping/macro-expressions.cpp
@@ -83,20 +83,23 @@
   // CHECK: File 0, 

[PATCH] D95918: [Coverage] Propogate counter to condition of conditional operator

2021-02-03 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

I tested it locally. They are all passed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95918/new/

https://reviews.llvm.org/D95918

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


[PATCH] D95971: [OpenMP][NVPTX] Take functions in `deviceRTLs` as `convergent`

2021-02-03 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, JonChesterfield, ye-luo.
Herald added subscribers: guansong, yaxunl.
Herald added a reviewer: jansvoboda11.
tianshilei1992 requested review of this revision.
Herald added subscribers: openmp-commits, cfe-commits, sstefan1.
Herald added projects: clang, OpenMP.

OpenMP device compiler (similar to other SPMD compilers) assumes that
functions are convergent by default to avoid invalid transformations, such as
the bug (https://bugs.llvm.org/show_bug.cgi?id=49021).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95971

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp

Index: openmp/libomptarget/test/offloading/bug49021.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/offloading/bug49021.cpp
@@ -0,0 +1,85 @@
+// RUN: %libomptarget-compilexx-aarch64-unknown-linux-gnu -O3 && %libomptarget-run-aarch64-unknown-linux-gnu
+// RUN: %libomptarget-compilexx-powerpc64-ibm-linux-gnu -O3 && %libomptarget-run-powerpc64-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-powerpc64le-ibm-linux-gnu -O3 && %libomptarget-run-powerpc64le-ibm-linux-gnu
+// RUN: %libomptarget-compilexx-x86_64-pc-linux-gnu -O3 && %libomptarget-run-x86_64-pc-linux-gnu
+// RUN: %libomptarget-compilexx-nvptx64-nvidia-cuda -O3 && %libomptarget-run-nvptx64-nvidia-cuda
+
+#include 
+
+template  int test_map() {
+  std::cout << "map(complex<>)" << std::endl;
+  T a(0.2), a_check;
+#pragma omp target map(from : a_check)
+  { a_check = a; }
+
+  if (a_check != a) {
+std::cout << " wrong results";
+return 1;
+  }
+
+  return 0;
+}
+
+template  int test_reduction() {
+  std::cout << "flat parallelism" << std::endl;
+  T sum(0), sum_host(0);
+  const int size = 100;
+  T array[size];
+  for (int i = 0; i < size; i++) {
+array[i] = i;
+sum_host += array[i];
+  }
+
+#pragma omp target teams distribute parallel for map(to: array[:size]) \
+ reduction(+ : sum)
+  for (int i = 0; i < size; i++)
+sum += array[i];
+
+  if (sum != sum_host)
+std::cout << " wrong results " << sum << " host " << sum_host << std::endl;
+
+  std::cout << "hierarchical parallelism" << std::endl;
+  const int nblock(10), block_size(10);
+  T block_sum[nblock];
+#pragma omp target teams distribute map(to \
+: array[:size])\
+map(from   \
+: block_sum[:nblock])
+  for (int ib = 0; ib < nblock; ib++) {
+T partial_sum = 0;
+const int istart = ib * block_size;
+const int iend = (ib + 1) * block_size;
+#pragma omp parallel for reduction(+ : partial_sum)
+for (int i = istart; i < iend; i++)
+  partial_sum += array[i];
+block_sum[ib] = partial_sum;
+  }
+
+  sum = 0;
+  for (int ib = 0; ib < nblock; ib++) {
+sum += block_sum[ib];
+  }
+
+  if (sum != sum_host) {
+std::cout << " wrong results " << sum << " host " << sum_host << std::endl;
+return 1;
+  }
+
+  return 0;
+}
+
+template  int test_complex() {
+  int ret = 0;
+  ret |= test_map();
+  ret |= test_reduction();
+  return ret;
+}
+
+int main() {
+  int ret = 0;
+  std::cout << "Testing float" << std::endl;
+  ret |= test_complex();
+  std::cout << "Testing double" << std::endl;
+  ret |= test_complex();
+  return ret;
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2441,6 +2441,8 @@
   bool IsTargetSpecified =
   Opts.OpenMPIsDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ);
 
+  Opts.ConvergentFunctions = Opts.ConvergentFunctions || Opts.OpenMPIsDevice;
+
   if (Opts.OpenMP || Opts.OpenMPSimd) {
 if (int Version = getLastArgIntValue(
 Args, OPT_fopenmp_version_EQ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94472: [clang][cli] Command line round-trip for HeaderSearch options

2021-02-03 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

In D94472#2539685 , @jansvoboda11 
wrote:

> I've changed this patch so that the errors and debugging output goes to 
> `DiagnosticsEngine`.
>
> Also, I switched back to the original solution, where we always round-trip 
> when Clang is built certain way (this time not when CMake was configured with 
> `-DLLVM_ENABLE_ASSERTIONS=ON`, but with `-DCLANG_ROUND_TRIP_CC1_ARGS=ON`). 
> The problem with the previous solution (passing `-round-trip-args` from the 
> driver to `-cc1`) is that a lot of tests invoke `-cc1` directly, not through 
> the driver. We want to test round-tripping on such tests as well, but 
> shouldn't pollute them with `-round-trip-args` or force them to go through 
> the driver. I've considered enabling round-tripping through an environment 
> variable, but the problem is that the, the environment variable is not 
> propagated when running lit tests.

LGTM; I think this is fine as an incremental step, as long as the goal is to 
get this on in asserts builds once it's complete (we don't want another bot 
configuration with this...). Please add `-cc1` flags to override at least by 
the time you switch back to doing this for asserts builds. I've noted inline 
how you can do that (even though the clang driver idea doesn't work for this 
case).




Comment at: clang/lib/Frontend/CompilerInvocation.cpp:592-594
+#ifdef CLANG_ROUND_TRIP_CC1_ARGS
+  DoRoundTrip = true;
+#endif

It'd be good to the flags still available in `-cc1` as overrides.
```
bool RoundTripDefault = false;

// FIXME: Switch to '#ifndef NDEBUG' once it's ready.
#ifdef CLANG_ROUND_TRIP_CC1_ARGS
RoundTripDefault = true;
#endif

bool DoRoundTrip = Args.hasFlag(OPT_round_trip_args, OPT_no_round_trip_args,
RoundTripDefault);
```
But that's most compelling once this is in `NDEBUG`. If you'd rather leave that 
until then I'm fine with that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94472/new/

https://reviews.llvm.org/D94472

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


[PATCH] D95970: [HIP] Allow undefined symbols

2021-02-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

HIP managed variables need to be emitted as undefined symbols
since runtime needs to define them with managed memory
accessible by both device and host.

Let HIP toolchain allow that with lld.


https://reviews.llvm.org/D95970

Files:
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/hip-toolchain-device-only.hip
  clang/test/Driver/hip-toolchain-no-rdc.hip


Index: clang/test/Driver/hip-toolchain-no-rdc.hip
===
--- clang/test/Driver/hip-toolchain-no-rdc.hip
+++ clang/test/Driver/hip-toolchain-no-rdc.hip
@@ -50,7 +50,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_803:.*out]]" [[OBJ_DEV_A_803]]
 
 //
@@ -73,7 +73,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]
 
 //
@@ -113,7 +113,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_B_803:.*out]]" [[OBJ_DEV_B_803]]
 
 //
@@ -136,7 +136,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_B_900:.*out]]" [[OBJ_DEV_B_900]]
 
 //
Index: clang/test/Driver/hip-toolchain-device-only.hip
===
--- clang/test/Driver/hip-toolchain-device-only.hip
+++ clang/test/Driver/hip-toolchain-device-only.hip
@@ -12,7 +12,7 @@
 // CHECK-SAME: "-target-cpu" "gfx803"
 // CHECK-SAME: {{.*}} "-o" [[OBJ_DEV_A_803:".*o"]] "-x" "hip"
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_803:.*out]]" [[OBJ_DEV_A_803]]
 
 // CHECK: [[CLANG:".*clang.*"]] "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa"
@@ -21,7 +21,7 @@
 // CHECK-SAME: "-target-cpu" "gfx900"
 // CHECK-SAME: {{.*}} "-o" [[OBJ_DEV_A_900:".*o"]] "-x" "hip"
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]
 
 // CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -60,7 +60,9 @@
   const llvm::opt::ArgList ) 
const {
   // Construct lld command.
   // The output from ld.lld is an HSA code object file.
-  ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", "-shared",
+  // Do not use --no-undefined option since managed variables need to be 
emitted
+  // as undefined symbols.
+  ArgStringList LldArgs{"-flavor", "gnu", "-shared",
 "-plugin-opt=-amdgpu-internalize-symbols"};
 
   auto  = getToolChain();


Index: clang/test/Driver/hip-toolchain-no-rdc.hip
===
--- clang/test/Driver/hip-toolchain-no-rdc.hip
+++ clang/test/Driver/hip-toolchain-no-rdc.hip
@@ -50,7 +50,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD: ".*lld.*"]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_803:.*out]]" [[OBJ_DEV_A_803]]
 
 //
@@ -73,7 +73,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]
 
 //
@@ -113,7 +113,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_B_803:.*out]]" [[OBJ_DEV_B_803]]
 
 //
@@ -136,7 +136,7 @@
 // CHECK-NOT: {{".*opt"}}
 // CHECK-NOT: {{".*llc"}}
 
-// CHECK: [[LLD]] "-flavor" "gnu" "--no-undefined" "-shared"
+// CHECK: [[LLD]] "-flavor" "gnu" "-shared"
 // CHECK-SAME: "-o" "[[IMG_DEV_B_900:.*out]]" [[OBJ_DEV_B_900]]
 
 //
Index: clang/test/Driver/hip-toolchain-device-only.hip
===
--- clang/test/Driver/hip-toolchain-device-only.hip
+++ clang/test/Driver/hip-toolchain-device-only.hip
@@ -12,7 +12,7 @@
 // CHECK-SAME: "-target-cpu" "gfx803"
 // CHECK-SAME: {{.*}} "-o" [[OBJ_DEV_A_803:".*o"]] "-x" "hip"

[PATCH] D95901: [CUDA][HIP] Fix device variable linkage

2021-02-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 321203.
yaxunl added a comment.

clang-format the patch


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95901/new/

https://reviews.llvm.org/D95901

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/device-stub.cu
  clang/test/CodeGenCUDA/device-var-linkage.cu
  clang/test/CodeGenCUDA/managed-var.cu

Index: clang/test/CodeGenCUDA/managed-var.cu
===
--- clang/test/CodeGenCUDA/managed-var.cu
+++ clang/test/CodeGenCUDA/managed-var.cu
@@ -10,17 +10,19 @@
 
 // RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \
 // RUN:   -emit-llvm -o - -x hip %s | FileCheck \
-// RUN:   -check-prefixes=HOST %s
+// RUN:   -check-prefixes=HOST,NORDC %s
 
 // RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \
 // RUN:   -emit-llvm -fgpu-rdc -o - -x hip %s | FileCheck \
-// RUN:   -check-prefixes=HOST %s
+// RUN:   -check-prefixes=HOST,RDC %s
 
 #include "Inputs/cuda.h"
 
-// DEV-DAG: @x = {{.*}}addrspace(1) externally_initialized global i32 undef
-// HOST-DAG: @x = internal global i32 1
-// HOST-DAG: @x.managed = internal global i32* null
+// DEV-DAG: @x = external addrspace(1) externally_initialized global i32
+// NORDC-DAG: @x = internal global i32 1
+// RDC-DAG: @x = dso_local global i32 1
+// NORDC-DAG: @x.managed = internal global i32* null
+// RDC-DAG: @x.managed = dso_local global i32* null
 // HOST-DAG: @[[DEVNAMEX:[0-9]+]] = {{.*}}c"x\00"
 
 struct vec {
@@ -31,11 +33,28 @@
 __managed__ vec v[100];
 __managed__ vec v2[100] = {{1, 1, 1}};
 
+// DEV-DAG: @ex = external addrspace(1) global i32
+// HOST-DAG: @ex = external global i32
+extern __managed__ int ex;
+
+// DEV-DAG: @_ZL2sx = external addrspace(1) externally_initialized global i32
+// HOST-DAG: @_ZL2sx = internal global i32 1
+// HOST-DAG: @_ZL2sx.managed = internal global i32* null
+static __managed__ int sx = 1;
+
+// HOST-NOT: @ex.managed
+
+// Force ex and sx mitted in device compilation.
 __global__ void foo(int *z) {
-  *z = x;
+  *z = x + ex + sx;
   v[1].x = 2;
 }
 
+// Force ex and sx emitted in host compilatioin.
+int foo2() {
+  return ex + sx;
+}
+
 // HOST-LABEL: define {{.*}}@_Z4loadv()
 // HOST:  %ld.managed = load i32*, i32** @x.managed, align 4
 // HOST:  %0 = load i32, i32* %ld.managed, align 4
@@ -97,4 +116,6 @@
 }
 
 // HOST-DAG: __hipRegisterManagedVar({{.*}}@x.managed {{.*}}@x {{.*}}@[[DEVNAMEX]]{{.*}}, i64 4, i32 4)
+// HOST-DAG: __hipRegisterManagedVar({{.*}}@_ZL2sx.managed {{.*}}@_ZL2sx
+// HOST-NOT: __hipRegisterManagedVar({{.*}}@ex.managed {{.*}}@ex
 // HOST-DAG: declare void @__hipRegisterManagedVar(i8**, i8*, i8*, i8*, i64, i32)
Index: clang/test/CodeGenCUDA/device-var-linkage.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/device-var-linkage.cu
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
+// RUN:   -emit-llvm -o - -x hip %s \
+// RUN:   | FileCheck -check-prefixes=DEV,NORDC %s
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
+// RUN:   -fgpu-rdc -emit-llvm -o - -x hip %s \
+// RUN:   | FileCheck -check-prefixes=DEV,RDC %s
+// RUN: %clang_cc1 -triple nvptx \
+// RUN:   -emit-llvm -o - -x hip %s \
+// RUN:   | FileCheck -check-prefixes=HOST,NORDC-H %s
+// RUN: %clang_cc1 -triple nvptx \
+// RUN:   -fgpu-rdc -emit-llvm -o - -x hip %s \
+// RUN:   | FileCheck -check-prefixes=HOST,RDC-H %s
+
+#include "Inputs/cuda.h"
+
+// DEV-DAG: @v1 = dso_local addrspace(1) externally_initialized global i32 0
+// NORDC-H-DAG: @v1 = internal global i32 undef
+// RDC-H-DAG: @v1 = dso_local global i32 undef
+__device__ int v1;
+// DEV-DAG: @v2 = dso_local addrspace(4) externally_initialized global i32 0
+// NORDC-H-DAG: @v2 = internal global i32 undef
+// RDC-H-DAG: @v2 = dso_local global i32 undef
+__constant__ int v2;
+// DEV-DAG: @v3 = external addrspace(1) externally_initialized global i32
+// NORDC-H-DAG: @v3 = internal global i32 0
+// RDC-H-DAG: @v3 = dso_local global i32 0
+__managed__ int v3;
+
+// DEV-DAG: @ev1 = external addrspace(1) global i32
+// HOST-DAG: @ev1 = external global i32
+extern __device__ int ev1;
+// DEV-DAG: @ev2 = external addrspace(4) global i32
+// HOST-DAG: @ev2 = external global i32
+extern __constant__ int ev2;
+// DEV-DAG: @ev3 = external addrspace(1) global i32
+// HOST-DAG: @ev3 = external global i32
+extern __managed__ int ev3;
+
+// NORDC-DAG: @_ZL3sv1 = dso_local addrspace(1) externally_initialized global i32 0
+// RDC-DAG: @_ZL3sv1 = internal addrspace(1) global i32 0
+// HOST-DAG: @_ZL3sv1 = internal global i32 undef
+static __device__ int sv1;
+// NORDC-DAG: @_ZL3sv2 = dso_local addrspace(4) externally_initialized global i32 0
+// RDC-DAG: @_ZL3sv2 = internal addrspace(4) global i32 0
+// HOST-DAG: @_ZL3sv2 = internal global i32 undef
+static __constant__ int sv2;
+// DEV-DAG: @_ZL3sv3 = external addrspace(1) 

[PATCH] D91944: OpenMP 5.0 metadirective

2021-02-03 Thread Alok Mishra via Phabricator via cfe-commits
alokmishra.besu added a comment.

In D91944#2540178 , @jdoerfert wrote:

> There are no test cases anymore, as far as I can tell.

Updated patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91944/new/

https://reviews.llvm.org/D91944

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


[PATCH] D95792: [clang][cli] Report result of ParseLangArgs

2021-02-03 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95792/new/

https://reviews.llvm.org/D95792

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


[PATCH] D91944: OpenMP 5.0 metadirective

2021-02-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

There are no test cases anymore, as far as I can tell.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91944/new/

https://reviews.llvm.org/D91944

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


[PATCH] D91944: OpenMP 5.0 metadirective

2021-02-03 Thread Alok Mishra via Phabricator via cfe-commits
alokmishra.besu updated this revision to Diff 321202.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91944/new/

https://reviews.llvm.org/D91944

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/OpenMP/metadirective_ast_print.c
  clang/test/OpenMP/metadirective_device_kind_codegen.c
  clang/test/OpenMP/metadirective_device_kind_codegen.cpp
  clang/test/OpenMP/metadirective_empty.cpp
  clang/test/OpenMP/metadirective_implementation_codegen.c
  clang/test/OpenMP/metadirective_implementation_codegen.cpp
  clang/test/OpenMP/metadirective_messages.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -60,6 +60,7 @@
   let clangClass = "OMPCollapseClause";
   let flangClass = "ScalarIntConstantExpr";
 }
+def OMPC_When: Clause<"when"> {}
 def OMPC_Default : Clause<"default"> {
   let clangClass = "OMPDefaultClause";
   let flangClass = "OmpDefaultClause";
@@ -320,6 +321,14 @@
 // Definition of OpenMP directives
 //===--===//
 
+def OMP_Metadirective : Directive<"metadirective"> {
+  let allowedClauses = [
+VersionedClause
+  ];
+  let allowedOnceClauses = [
+VersionedClause
+  ];
+}
 def OMP_ThreadPrivate : Directive<"threadprivate"> {}
 def OMP_Parallel : Directive<"parallel"> {
   let allowedClauses = [
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -639,6 +639,9 @@
   case Stmt::MSDependentExistsStmtClass:
 K = CXCursor_UnexposedStmt;
 break;
+  case Stmt::OMPMetaDirectiveClass:
+K = CXCursor_OMPMetaDirective;
+break;
   case Stmt::OMPParallelDirectiveClass:
 K = CXCursor_OMPParallelDirective;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5524,6 +5524,8 @@
 return cxstring::createRef("CXXAccessSpecifier");
   case CXCursor_ModuleImportDecl:
 return cxstring::createRef("ModuleImport");
+  case CXCursor_OMPMetaDirective:
+return cxstring::createRef("OMPMetaDirective");
   case CXCursor_OMPParallelDirective:
 return cxstring::createRef("OMPParallelDirective");
   case CXCursor_OMPSimdDirective:
Index: clang/test/OpenMP/metadirective_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/metadirective_messages.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++14 -emit-llvm %s
+
+void foo() {
+#pragma omp metadirective // expected-error {{expected expression}}
+  ;
+#pragma omp metadirective when() // expected-error {{expected valid context selector in when clause}} expected-error {{expected expression}} expected-warning {{expected identifier or string literal describing a context set; set skipped}} expected-note {{context set options are: 'construct' 'device' 'implementation' 'user'}} expected-note {{the ignored set spans until here}}
+  ;
+#pragma omp metadirective when(device{}) // expected-warning {{expected '=' after the context set name "device"; '=' assumed}} expected-warning {{expected identifier or string literal describing a context selector; selector skipped}} expected-note {{context selector options are: 'kind' 'arch' 'isa'}} expected-note {{the ignored selector spans until here}} expected-error {{expected valid context selector in when clause}} expected-error {{expected expression}} 
+  ;
+#pragma omp metadirective when(device{arch(nvptx)}) // expected-error {{missing ':' in when clause}} expected-error {{expected expression}} expected-warning {{expected '=' after the context set name 

[PATCH] D69322: [hip][cuda] Enable extended lambda support on Windows.

2021-02-03 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

@rsmith, @rnk and @rjmccall, could you review the latest change addressing the 
memory usage issue?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69322/new/

https://reviews.llvm.org/D69322

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


[PATCH] D95901: [CUDA][HIP] Fix device variable linkage

2021-02-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 321198.
yaxunl marked an inline comment as done.
yaxunl added a comment.

Revised by Artem's comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95901/new/

https://reviews.llvm.org/D95901

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/device-stub.cu
  clang/test/CodeGenCUDA/device-var-linkage.cu
  clang/test/CodeGenCUDA/managed-var.cu

Index: clang/test/CodeGenCUDA/managed-var.cu
===
--- clang/test/CodeGenCUDA/managed-var.cu
+++ clang/test/CodeGenCUDA/managed-var.cu
@@ -10,17 +10,19 @@
 
 // RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \
 // RUN:   -emit-llvm -o - -x hip %s | FileCheck \
-// RUN:   -check-prefixes=HOST %s
+// RUN:   -check-prefixes=HOST,NORDC %s
 
 // RUN: %clang_cc1 -triple x86_64-gnu-linux -std=c++11 \
 // RUN:   -emit-llvm -fgpu-rdc -o - -x hip %s | FileCheck \
-// RUN:   -check-prefixes=HOST %s
+// RUN:   -check-prefixes=HOST,RDC %s
 
 #include "Inputs/cuda.h"
 
-// DEV-DAG: @x = {{.*}}addrspace(1) externally_initialized global i32 undef
-// HOST-DAG: @x = internal global i32 1
-// HOST-DAG: @x.managed = internal global i32* null
+// DEV-DAG: @x = external addrspace(1) externally_initialized global i32
+// NORDC-DAG: @x = internal global i32 1
+// RDC-DAG: @x = dso_local global i32 1
+// NORDC-DAG: @x.managed = internal global i32* null
+// RDC-DAG: @x.managed = dso_local global i32* null
 // HOST-DAG: @[[DEVNAMEX:[0-9]+]] = {{.*}}c"x\00"
 
 struct vec {
@@ -31,11 +33,28 @@
 __managed__ vec v[100];
 __managed__ vec v2[100] = {{1, 1, 1}};
 
+// DEV-DAG: @ex = external addrspace(1) global i32
+// HOST-DAG: @ex = external global i32
+extern __managed__ int ex;
+
+// DEV-DAG: @_ZL2sx = external addrspace(1) externally_initialized global i32
+// HOST-DAG: @_ZL2sx = internal global i32 1
+// HOST-DAG: @_ZL2sx.managed = internal global i32* null
+static __managed__ int sx = 1;
+
+// HOST-NOT: @ex.managed
+
+// Force ex and sx mitted in device compilation.
 __global__ void foo(int *z) {
-  *z = x;
+  *z = x + ex + sx;
   v[1].x = 2;
 }
 
+// Force ex and sx emitted in host compilatioin.
+int foo2() {
+  return ex + sx;
+}
+
 // HOST-LABEL: define {{.*}}@_Z4loadv()
 // HOST:  %ld.managed = load i32*, i32** @x.managed, align 4
 // HOST:  %0 = load i32, i32* %ld.managed, align 4
@@ -97,4 +116,6 @@
 }
 
 // HOST-DAG: __hipRegisterManagedVar({{.*}}@x.managed {{.*}}@x {{.*}}@[[DEVNAMEX]]{{.*}}, i64 4, i32 4)
+// HOST-DAG: __hipRegisterManagedVar({{.*}}@_ZL2sx.managed {{.*}}@_ZL2sx
+// HOST-NOT: __hipRegisterManagedVar({{.*}}@ex.managed {{.*}}@ex
 // HOST-DAG: declare void @__hipRegisterManagedVar(i8**, i8*, i8*, i8*, i64, i32)
Index: clang/test/CodeGenCUDA/device-var-linkage.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/device-var-linkage.cu
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
+// RUN:   -emit-llvm -o - -x hip %s \
+// RUN:   | FileCheck -check-prefixes=DEV,NORDC %s
+// RUN: %clang_cc1 -triple nvptx -fcuda-is-device \
+// RUN:   -fgpu-rdc -emit-llvm -o - -x hip %s \
+// RUN:   | FileCheck -check-prefixes=DEV,RDC %s
+// RUN: %clang_cc1 -triple nvptx \
+// RUN:   -emit-llvm -o - -x hip %s \
+// RUN:   | FileCheck -check-prefixes=HOST,NORDC-H %s
+// RUN: %clang_cc1 -triple nvptx \
+// RUN:   -fgpu-rdc -emit-llvm -o - -x hip %s \
+// RUN:   | FileCheck -check-prefixes=HOST,RDC-H %s
+
+#include "Inputs/cuda.h"
+
+// DEV-DAG: @v1 = dso_local addrspace(1) externally_initialized global i32 0
+// NORDC-H-DAG: @v1 = internal global i32 undef
+// RDC-H-DAG: @v1 = dso_local global i32 undef
+__device__ int v1;
+// DEV-DAG: @v2 = dso_local addrspace(4) externally_initialized global i32 0
+// NORDC-H-DAG: @v2 = internal global i32 undef
+// RDC-H-DAG: @v2 = dso_local global i32 undef
+__constant__ int v2;
+// DEV-DAG: @v3 = external addrspace(1) externally_initialized global i32
+// NORDC-H-DAG: @v3 = internal global i32 0
+// RDC-H-DAG: @v3 = dso_local global i32 0
+__managed__ int v3;
+
+// DEV-DAG: @ev1 = external addrspace(1) global i32
+// HOST-DAG: @ev1 = external global i32
+extern __device__ int ev1;
+// DEV-DAG: @ev2 = external addrspace(4) global i32
+// HOST-DAG: @ev2 = external global i32
+extern __constant__ int ev2;
+// DEV-DAG: @ev3 = external addrspace(1) global i32
+// HOST-DAG: @ev3 = external global i32
+extern __managed__ int ev3;
+
+// NORDC-DAG: @_ZL3sv1 = dso_local addrspace(1) externally_initialized global i32 0
+// RDC-DAG: @_ZL3sv1 = internal addrspace(1) global i32 0
+// HOST-DAG: @_ZL3sv1 = internal global i32 undef
+static __device__ int sv1;
+// NORDC-DAG: @_ZL3sv2 = dso_local addrspace(4) externally_initialized global i32 0
+// RDC-DAG: @_ZL3sv2 = internal addrspace(4) global i32 0
+// HOST-DAG: @_ZL3sv2 = internal global i32 undef
+static __constant__ int sv2;
+// DEV-DAG: 

[PATCH] D91944: OpenMP 5.0 metadirective

2021-02-03 Thread Alok Mishra via Phabricator via cfe-commits
alokmishra.besu updated this revision to Diff 321194.
alokmishra.besu added a comment.

I've rebase this patch with the latest git code.
All test cases pass.
I've also applied this patch to a new git clone. It applies and builds 
successfully.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91944/new/

https://reviews.llvm.org/D91944

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -60,6 +60,7 @@
   let clangClass = "OMPCollapseClause";
   let flangClass = "ScalarIntConstantExpr";
 }
+def OMPC_When: Clause<"when"> {}
 def OMPC_Default : Clause<"default"> {
   let clangClass = "OMPDefaultClause";
   let flangClass = "OmpDefaultClause";
@@ -320,6 +321,14 @@
 // Definition of OpenMP directives
 //===--===//
 
+def OMP_Metadirective : Directive<"metadirective"> {
+  let allowedClauses = [
+VersionedClause
+  ];
+  let allowedOnceClauses = [
+VersionedClause
+  ];
+}
 def OMP_ThreadPrivate : Directive<"threadprivate"> {}
 def OMP_Parallel : Directive<"parallel"> {
   let allowedClauses = [
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -639,6 +639,9 @@
   case Stmt::MSDependentExistsStmtClass:
 K = CXCursor_UnexposedStmt;
 break;
+  case Stmt::OMPMetaDirectiveClass:
+K = CXCursor_OMPMetaDirective;
+break;
   case Stmt::OMPParallelDirectiveClass:
 K = CXCursor_OMPParallelDirective;
 break;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5524,6 +5524,8 @@
 return cxstring::createRef("CXXAccessSpecifier");
   case CXCursor_ModuleImportDecl:
 return cxstring::createRef("ModuleImport");
+  case CXCursor_OMPMetaDirective:
+return cxstring::createRef("OMPMetaDirective");
   case CXCursor_OMPParallelDirective:
 return cxstring::createRef("OMPParallelDirective");
   case CXCursor_OMPSimdDirective:
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1292,6 +1292,7 @@
 case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass:
 case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
 case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
+case Stmt::OMPMetaDirectiveClass:
 case Stmt::CapturedStmtClass: {
   const ExplodedNode *node = Bldr.generateSink(S, Pred, Pred->getState());
   Engine.addAbortedBlock(node, currBldrCtx->getBlock());
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2176,6 +2176,13 @@
   Record.AddSourceLocation(E->getEndLoc());
 }
 
+void ASTStmtWriter::VisitOMPMetaDirective(OMPMetaDirective *D) {
+  VisitStmt(D);
+  Record.push_back(D->getNumClauses());
+  VisitOMPExecutableDirective(D);
+  Code = serialization::STMT_OMP_META_DIRECTIVE;
+}
+
 void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) {
   VisitStmt(D);
   Record.writeUInt32(D->getCollapsedNumber());
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2286,6 +2286,13 @@
   VisitOMPExecutableDirective(D);
 }
 
+void 

[PATCH] D95901: [CUDA][HIP] Fix device variable linkage

2021-02-03 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:11437-11443
+  return ((!getLangOpts().GPURelocatableDeviceCode &&
+   ((D->hasAttr() &&
+ !D->getAttr()->isImplicit()) ||
+(D->hasAttr() &&
+ !D->getAttr()->isImplicit( ||
   D->hasAttr()) &&
  isa(D) && cast(D)->getStorageClass() == SC_Static;

yaxunl wrote:
> tra wrote:
> > I can't parse it. :-( Perhaps we can split it.
> revised
I still can't read it. way too many nested operands to logical operators...

I was thinking of extracting parts of the equation into early returns or 
intermediate variables.



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95901/new/

https://reviews.llvm.org/D95901

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


[PATCH] D95948: Stop traping on sNaN in __builtin_isnan

2021-02-03 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:3011
+Builder.CreateSub(llvm::ConstantInt::get(IntTy, ExpMask), AbsV);
+V = Builder.CreateLShr(Sub, llvm::ConstantInt::get(IntTy, bitsize - 1));
+if (bitsize > 32)

thopre wrote:
> mibintc wrote:
> > the comment at line 3001 doesn't show the lshr or the compare to zero
> This logical right shift will move the sign bit to bit0 and set all other 
> bits to 0. The result will be 1 (true) if sign bit is set (sub is negative) 
> or 0 (false) otherwise. That matches the comment. Would you like me to add a 
> comment here to make it more explicit?
No, that's OK, you don't need to do that. thanks.  I'd like to see what other 
reviewers say, thanks for working on this!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95948/new/

https://reviews.llvm.org/D95948

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


[PATCH] D95901: [CUDA][HIP] Fix device variable linkage

2021-02-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:11437-11443
+  return ((!getLangOpts().GPURelocatableDeviceCode &&
+   ((D->hasAttr() &&
+ !D->getAttr()->isImplicit()) ||
+(D->hasAttr() &&
+ !D->getAttr()->isImplicit( ||
   D->hasAttr()) &&
  isa(D) && cast(D)->getStorageClass() == SC_Static;

tra wrote:
> I can't parse it. :-( Perhaps we can split it.
revised


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95901/new/

https://reviews.llvm.org/D95901

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


[PATCH] D95901: [CUDA][HIP] Fix device variable linkage

2021-02-03 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

In D95901#2539754 , @yaxunl wrote:

> For -fno-gpu-rdc, two TU's can have global device variables with the same 
> name, therefore the shadow variables need to be internalized, which is fine 
> since -fno-gpu-rdc is not supposed to access device variables across TU's. So 
> far users did not report issues about shadow var linkage for -fno-gpu-rdc 
> (they reported shadow var linkage issues for -fgpu-rdc only). Let the shadow 
> vars keep original linkage and use CUID to make them unique would be 
> unnecessary and clutter the IR.

I've checked what NVCC does in this case and their behavior appears to match 
your approach. Shadows are internalized w/o RDC and become visible when it's on.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95901/new/

https://reviews.llvm.org/D95901

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


[PATCH] D95458: [PowerPC] Exploit xxsplti32dx (constant materialization) for scalars

2021-02-03 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 321184.
Conanap added a comment.

Updated to ensure the shortcircuit protects against the destructive function.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95458/new/

https://reviews.llvm.org/D95458

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/constant-pool.ll
  llvm/test/CodeGen/PowerPC/p10-splatImm-CPload-pcrel.ll
  llvm/test/CodeGen/PowerPC/pcrel-call-linkage-leaf.ll
  llvm/test/CodeGen/PowerPC/pcrel-linkeropt.ll
  llvm/test/CodeGen/PowerPC/pcrel.ll

Index: llvm/test/CodeGen/PowerPC/pcrel.ll
===
--- llvm/test/CodeGen/PowerPC/pcrel.ll
+++ llvm/test/CodeGen/PowerPC/pcrel.ll
@@ -8,13 +8,14 @@
 
 ; Constant Pool Index.
 ; CHECK-S-LABEL: ConstPool
-; CHECK-S:   plfd f1, .LCPI0_0@PCREL(0), 1
+; CHECK-S:   xxsplti32dx vs1, 0, 1081002676
+; CHECK-S-NEXT:   xxsplti32dx vs1, 1, 962072674
 ; CHECK-S:   blr
 
 ; CHECK-O-LABEL: ConstPool
-; CHECK-O:   plfd 1, 0(0), 1
-; CHECK-O-NEXT:  R_PPC64_PCREL34  .rodata.cst8
-; CHECK-O:   blr
+; CHECK-O:   xxsplti32dx 1, 0, 1081002676
+; CHECK-O-NEXT:  xxsplti32dx 1, 1, 962072674
+; CHECK-O-NEXT:  blr
 define dso_local double @ConstPool() local_unnamed_addr {
   entry:
 ret double 0x406ECAB439581062
Index: llvm/test/CodeGen/PowerPC/pcrel-linkeropt.ll
===
--- llvm/test/CodeGen/PowerPC/pcrel-linkeropt.ll
+++ llvm/test/CodeGen/PowerPC/pcrel-linkeropt.ll
@@ -35,6 +35,9 @@
 @FuncPtrOut = external local_unnamed_addr global void (...)*, align 8
 
 define dso_local void @ReadWrite8() local_unnamed_addr #0 {
+; In this test the stb r3, 0(r4) cannot be optimized because it
+; uses the register r3 and that register is defined by lbz r3, 0(r3)
+; which is defined between the pld and the stb.
 ; CHECK-LABEL: ReadWrite8:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:pld r3, input8@got@pcrel(0), 1
@@ -42,9 +45,6 @@
 ; CHECK-NEXT:pld r4, output8@got@pcrel(0), 1
 ; CHECK-NEXT:.reloc .Lpcrel0-8,R_PPC64_PCREL_OPT,.-(.Lpcrel0-8)
 ; CHECK-NEXT:lbz r3, 0(r3)
-; In this test the stb r3, 0(r4) cannot be optimized because it
-; uses the register r3 and that register is defined by lbz r3, 0(r3)
-; which is defined between the pld and the stb.
 ; CHECK-NEXT:stb r3, 0(r4)
 ; CHECK-NEXT:blr
 entry:
@@ -54,6 +54,9 @@
 }
 
 define dso_local void @ReadWrite16() local_unnamed_addr #0 {
+; In this test the sth r3, 0(r4) cannot be optimized because it
+; uses the register r3 and that register is defined by lhz r3, 0(r3)
+; which is defined between the pld and the sth.
 ; CHECK-LABEL: ReadWrite16:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:pld r3, input16@got@pcrel(0), 1
@@ -61,9 +64,6 @@
 ; CHECK-NEXT:pld r4, output16@got@pcrel(0), 1
 ; CHECK-NEXT:.reloc .Lpcrel1-8,R_PPC64_PCREL_OPT,.-(.Lpcrel1-8)
 ; CHECK-NEXT:lhz r3, 0(r3)
-; In this test the sth r3, 0(r4) cannot be optimized because it
-; uses the register r3 and that register is defined by lhz r3, 0(r3)
-; which is defined between the pld and the sth.
 ; CHECK-NEXT:sth r3, 0(r4)
 ; CHECK-NEXT:blr
 entry:
@@ -144,7 +144,8 @@
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:pld r3, inputf64@got@pcrel(0), 1
 ; CHECK-NEXT:  .Lpcrel5:
-; CHECK-NEXT:plfd f1, .LCPI6_0@PCREL(0), 1
+; CHECK-NEXT:xxsplti32dx vs1, 0, 1075524403
+; CHECK-NEXT:xxsplti32dx vs1, 1, 858993459
 ; CHECK-NEXT:.reloc .Lpcrel5-8,R_PPC64_PCREL_OPT,.-(.Lpcrel5-8)
 ; CHECK-NEXT:lfd f0, 0(r3)
 ; CHECK-NEXT:pld r3, outputf64@got@pcrel(0), 1
@@ -286,8 +287,7 @@
 
 define dso_local void @FuncPtrCall() local_unnamed_addr #0 {
 ; CHECK-LABEL: FuncPtrCall:
-; CHECK: .localentry FuncPtrCall, 1
-; CHECK-NEXT:  # %bb.0: # %entry
+; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:pld r3, FuncPtrIn@got@pcrel(0), 1
 ; CHECK-NEXT:  .Lpcrel10:
 ; CHECK-NEXT:.reloc .Lpcrel10-8,R_PPC64_PCREL_OPT,.-(.Lpcrel10-8)
@@ -317,8 +317,7 @@
 
 define dso_local signext i32 @VecMultiUse() local_unnamed_addr #0 {
 ; CHECK-LABEL: VecMultiUse:
-; CHECK: .localentry VecMultiUse, 1
-; CHECK-NEXT:  # %bb.0: # %entry
+; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:mflr r0
 ; CHECK-NEXT:std r29, -24(r1) # 8-byte Folded Spill
 ; CHECK-NEXT:std r30, -16(r1) # 8-byte Folded Spill
@@ -355,8 +354,7 @@
 
 define dso_local signext i32 @UseAddr(i32 signext %a) local_unnamed_addr #0 {
 ; CHECK-LABEL: UseAddr:
-; CHECK: .localentry UseAddr, 1
-; CHECK-NEXT:  # %bb.0: # %entry
+; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:mflr r0
 ; CHECK-NEXT:std r30, -16(r1) # 8-byte Folded Spill
 ; CHECK-NEXT:std r0, 16(r1)
Index: llvm/test/CodeGen/PowerPC/pcrel-call-linkage-leaf.ll
===

[PATCH] D95695: [clang-tblgen] AnnotateAttr::printPretty has spurious comma when no variadic argument is specified

2021-02-03 Thread Félix Cloutier via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG554cf3729e65: [clang-tblgen] AnnotateAttr::printPretty has 
spurious comma when no variadic… (authored by fcloutier).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95695/new/

https://reviews.llvm.org/D95695

Files:
  clang/test/AST/ast-print-attr.c
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -773,10 +773,8 @@
 
 void writeValue(raw_ostream ) const override {
   OS << "\";\n";
-  OS << "  bool isFirst = true;\n"
- << "  for (const auto  : " << RangeName << "()) {\n"
- << "if (isFirst) isFirst = false;\n"
- << "else OS << \", \";\n";
+  OS << "  for (const auto  : " << RangeName << "()) {\n"
+ << "DelimitAttributeArgument(OS, IsFirstArgument);\n";
   writeValueImpl(OS);
   OS << "  }\n";
   OS << "  OS << \"";
@@ -1428,10 +1426,12 @@
 return;
   }
 
-  OS << "  switch (getAttributeSpellingListIndex()) {\n"
-"  default:\n"
-"llvm_unreachable(\"Unknown attribute spelling!\");\n"
-"break;\n";
+  OS << "  bool IsFirstArgument = true; (void)IsFirstArgument;\n"
+ << "  unsigned TrailingOmittedArgs = 0; (void)TrailingOmittedArgs;\n"
+ << "  switch (getAttributeSpellingListIndex()) {\n"
+ << "  default:\n"
+ << "llvm_unreachable(\"Unknown attribute spelling!\");\n"
+ << "break;\n";
 
   for (unsigned I = 0; I < Spellings.size(); ++ I) {
 llvm::SmallString<16> Prefix;
@@ -1476,12 +1476,10 @@
 
 Spelling += Name;
 
-OS <<
-  "  case " << I << " : {\n"
-  "OS << \"" << Prefix << Spelling;
+OS << "  case " << I << " : {\n"
+   << "OS << \"" << Prefix << Spelling << "\";\n";
 
 if (Variety == "Pragma") {
-  OS << "\";\n";
   OS << "printPrettyPragma(OS, Policy);\n";
   OS << "OS << \"\\n\";";
   OS << "break;\n";
@@ -1490,19 +1488,18 @@
 }
 
 if (Spelling == "availability") {
-  OS << "(";
+  OS << "OS << \"(";
   writeAvailabilityValue(OS);
-  OS << ")";
+  OS << ")\";\n";
 } else if (Spelling == "deprecated" || Spelling == "gnu::deprecated") {
-  OS << "(";
+  OS << "OS << \"(";
   writeDeprecatedAttrValue(OS, Variety);
-  OS << ")";
+  OS << ")\";\n";
 } else {
   // To avoid printing parentheses around an empty argument list or
   // printing spurious commas at the end of an argument list, we need to
   // determine where the last provided non-fake argument is.
   unsigned NonFakeArgs = 0;
-  unsigned TrailingOptArgs = 0;
   bool FoundNonOptArg = false;
   for (const auto  : llvm::reverse(Args)) {
 if (arg->isFake())
@@ -1516,61 +1513,33 @@
   FoundNonOptArg = true;
   continue;
 }
-if (!TrailingOptArgs++)
-  OS << "\";\n"
- << "unsigned TrailingOmittedArgs = 0;\n";
 OS << "if (" << arg->getIsOmitted() << ")\n"
<< "  ++TrailingOmittedArgs;\n";
   }
-  if (TrailingOptArgs)
-OS << "OS << \"";
-  if (TrailingOptArgs < NonFakeArgs)
-OS << "(";
-  else if (TrailingOptArgs)
-OS << "\";\n"
-   << "if (TrailingOmittedArgs < " << NonFakeArgs << ")\n"
-   << "   OS << \"(\";\n"
-   << "OS << \"";
   unsigned ArgIndex = 0;
   for (const auto  : Args) {
 if (arg->isFake())
   continue;
-if (ArgIndex) {
-  if (ArgIndex >= NonFakeArgs - TrailingOptArgs)
-OS << "\";\n"
-   << "if (" << ArgIndex << " < " << NonFakeArgs
-   << " - TrailingOmittedArgs)\n"
-   << "  OS << \", \";\n"
-   << "OS << \"";
-  else
-OS << ", ";
-}
 std::string IsOmitted = arg->getIsOmitted();
 if (arg->isOptional() && IsOmitted != "false")
-  OS << "\";\n"
- << "if (!(" << IsOmitted << ")) {\n"
- << "  OS << \"";
+  OS << "if (!(" << IsOmitted << ")) {\n";
+// Variadic arguments print their own leading comma.
+if (!arg->isVariadic())
+  OS << "DelimitAttributeArgument(OS, IsFirstArgument);\n";
+OS << "OS << \"";
 arg->writeValue(OS);
+OS << "\";\n";
 if (arg->isOptional() && IsOmitted != "false")
-  OS << "\";\n"
- << "}\n"
- << "OS << \"";
+  OS << "}\n";
 ++ArgIndex;
   }
-  if (TrailingOptArgs < NonFakeArgs)
-OS << ")";
-  else if 

[clang] 554cf37 - [clang-tblgen] AnnotateAttr::printPretty has spurious comma when no variadic argument is specified

2021-02-03 Thread Félix Cloutier via cfe-commits

Author: Félix Cloutier
Date: 2021-02-03T11:41:38-08:00
New Revision: 554cf3729e651b3b5416e081e63670fbe71cf91e

URL: 
https://github.com/llvm/llvm-project/commit/554cf3729e651b3b5416e081e63670fbe71cf91e
DIFF: 
https://github.com/llvm/llvm-project/commit/554cf3729e651b3b5416e081e63670fbe71cf91e.diff

LOG: [clang-tblgen] AnnotateAttr::printPretty has spurious comma when no 
variadic argument is specified

rdar://73742471
Differential Revision: https://reviews.llvm.org/D95695

Added: 


Modified: 
clang/test/AST/ast-print-attr.c
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/test/AST/ast-print-attr.c b/clang/test/AST/ast-print-attr.c
index 90a396303441..4140ae6ac11f 100644
--- a/clang/test/AST/ast-print-attr.c
+++ b/clang/test/AST/ast-print-attr.c
@@ -26,3 +26,9 @@ enum __attribute__((ns_error_domain(MyErrorDomain))) 
MyErrorEnum {
   MyErrFirst,
   MyErrSecond,
 };
+
+// CHECK: int *fun_returns() __attribute__((ownership_returns(fun_returns)));
+int *fun_returns() __attribute__((ownership_returns(fun_returns)));
+
+// CHECK: void fun_holds(int *a) __attribute__((ownership_holds(fun_holds, 
1)));
+void fun_holds(int *a) __attribute__((ownership_holds(fun_holds, 1)));

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index d435c5780531..aaef538e9bf9 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -773,10 +773,8 @@ namespace {
 
 void writeValue(raw_ostream ) const override {
   OS << "\";\n";
-  OS << "  bool isFirst = true;\n"
- << "  for (const auto  : " << RangeName << "()) {\n"
- << "if (isFirst) isFirst = false;\n"
- << "else OS << \", \";\n";
+  OS << "  for (const auto  : " << RangeName << "()) {\n"
+ << "DelimitAttributeArgument(OS, IsFirstArgument);\n";
   writeValueImpl(OS);
   OS << "  }\n";
   OS << "  OS << \"";
@@ -1428,10 +1426,12 @@ writePrettyPrintFunction(const Record ,
 return;
   }
 
-  OS << "  switch (getAttributeSpellingListIndex()) {\n"
-"  default:\n"
-"llvm_unreachable(\"Unknown attribute spelling!\");\n"
-"break;\n";
+  OS << "  bool IsFirstArgument = true; (void)IsFirstArgument;\n"
+ << "  unsigned TrailingOmittedArgs = 0; (void)TrailingOmittedArgs;\n"
+ << "  switch (getAttributeSpellingListIndex()) {\n"
+ << "  default:\n"
+ << "llvm_unreachable(\"Unknown attribute spelling!\");\n"
+ << "break;\n";
 
   for (unsigned I = 0; I < Spellings.size(); ++ I) {
 llvm::SmallString<16> Prefix;
@@ -1476,12 +1476,10 @@ writePrettyPrintFunction(const Record ,
 
 Spelling += Name;
 
-OS <<
-  "  case " << I << " : {\n"
-  "OS << \"" << Prefix << Spelling;
+OS << "  case " << I << " : {\n"
+   << "OS << \"" << Prefix << Spelling << "\";\n";
 
 if (Variety == "Pragma") {
-  OS << "\";\n";
   OS << "printPrettyPragma(OS, Policy);\n";
   OS << "OS << \"\\n\";";
   OS << "break;\n";
@@ -1490,19 +1488,18 @@ writePrettyPrintFunction(const Record ,
 }
 
 if (Spelling == "availability") {
-  OS << "(";
+  OS << "OS << \"(";
   writeAvailabilityValue(OS);
-  OS << ")";
+  OS << ")\";\n";
 } else if (Spelling == "deprecated" || Spelling == "gnu::deprecated") {
-  OS << "(";
+  OS << "OS << \"(";
   writeDeprecatedAttrValue(OS, Variety);
-  OS << ")";
+  OS << ")\";\n";
 } else {
   // To avoid printing parentheses around an empty argument list or
   // printing spurious commas at the end of an argument list, we need to
   // determine where the last provided non-fake argument is.
   unsigned NonFakeArgs = 0;
-  unsigned TrailingOptArgs = 0;
   bool FoundNonOptArg = false;
   for (const auto  : llvm::reverse(Args)) {
 if (arg->isFake())
@@ -1516,61 +1513,33 @@ writePrettyPrintFunction(const Record ,
   FoundNonOptArg = true;
   continue;
 }
-if (!TrailingOptArgs++)
-  OS << "\";\n"
- << "unsigned TrailingOmittedArgs = 0;\n";
 OS << "if (" << arg->getIsOmitted() << ")\n"
<< "  ++TrailingOmittedArgs;\n";
   }
-  if (TrailingOptArgs)
-OS << "OS << \"";
-  if (TrailingOptArgs < NonFakeArgs)
-OS << "(";
-  else if (TrailingOptArgs)
-OS << "\";\n"
-   << "if (TrailingOmittedArgs < " << NonFakeArgs << ")\n"
-   << "   OS << \"(\";\n"
-   << "OS << \"";
   unsigned ArgIndex = 0;
   for (const auto  : Args) {
 if (arg->isFake())
   continue;
-if (ArgIndex) {
-  if (ArgIndex >= NonFakeArgs - TrailingOptArgs)
-OS << "\";\n"
-   << "if (" << ArgIndex << " < " 

[PATCH] D95840: [CUDA][HIP] Fix checking dependent initalizer

2021-02-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/Sema/SemaCUDA.cpp:538
   AllowedInit =
-  ((VD->getType()->isDependentType() || Init->isValueDependent()) &&
-   VD->isConstexpr()) ||
+  (VD->getType()->isDependentType() || Init->isValueDependent()) ||
   Init->isConstantInitializer(Context,

tra wrote:
> Nit, no need for `()` any more, as all parts of the expression ar `||`-ed 
> together.
will do



Comment at: clang/test/SemaCUDA/dependent-device-var.cu:8
+__device__ int fun1(T x) {
+  static __device__ int a = sizeof(x);
+  static __device__ int b = x;

tra wrote:
> So, the patch now allows using type-dependent constant expressions now. 
> I'd add a comment highlighting this. It's not always obvious that the test's 
> purpose is to verify the absence of an error.
will do


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95840/new/

https://reviews.llvm.org/D95840

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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2021-02-03 Thread Adrien Guinet via Phabricator via cfe-commits
aguinet added a comment.

In D89490#2516255 , @rjmccall wrote:

> In D89490#2514695 , @aguinet wrote:
>
>>> I may be over-reacting to the way the patch seemed to be touching on the 
>>> C++ ABI in multiple places.  My understanding is that `ms_abi` is just a 
>>> calling-convention attribute; it's basically "use the (default) calling 
>>> convention that MSVC would use for this function".  If that's all you want, 
>>> then this is reasonable, although I am worried about creating a new 
>>> attribute for every system that Wine chooses to target.
>>
>> I literally based this patch on how ms_abi was implemented. It's 
>> unfortunately more than just teaching clang to change the calling convention 
>> on LLVM IR functions. The fact that ABI implementations are spread all over 
>> the place between various places in LLVM is, as far as I remember, a known 
>> problem discussed many times on llvm-dev, and looks like a hard one to fix.
>
> Right, I understand that — I've even given an LLVM talk about it.  I was just 
> confused about your intent because you made some effort to match other parts 
> of the ABI besides what we might traditionally consider the calling 
> convention.  I suppose some of those changes could be thought of as 
> feature-specific calling conventions, but I don't usually think of them that 
> way.

We could have a long discussion on what do we exactly call a "calling 
convention" :) IIRC I did implement a few C++ bits, but they could be removed 
from this patch for further implementation.

>>> About "darwin": technically, every Apple platform has a different ABI.  Our 
>>> current ARM64 platforms do all agree about things like the calling 
>>> convention, at least if you count newer watches (which use a 32-on-64 ABI 
>>> in userspace) as not ARM64.  That is not true of other architectures, most 
>>> notably on ARM32, where the 32-bit iOS ABI is very different from the 
>>> armv7k Apple Watch ABI; and it is certainly conceivable that Apple might 
>>> release a new ARM64 platform in the future with a different calling 
>>> convention.  The more technically correct and future-proof thing would be 
>>> to use the OS name (or maybe even the triple!) in the attribute, probably 
>>> as an argument to the attribute, like 
>>> `__attribute__((target_abi("arm64-apple-ios")))`.
>>
>> I'm a bit afraid that `__attribute__((target_abi(XX)))` would conflict with 
>> the existing `__attribute__((ms_abi))`.
>
> They don't *conflict*.  It's a more general scheme than the existing 
> attribute, but the existing attribute can be thought of as a shorthand for 
> one case of that more general scheme, so I don't see a problem here.  I would 
> like to not have to add a new attribute for every OS that Wine decides to 
> support.

You're right, let me rephrase what I wanted to say: with this, there will be 
two ways to target the windows ABI. I guess we can be fine with it, but that 
adds some kind of complexity that needs to be explained to the end user.

There is also the support the equivalent of the `__builtin_ms_va_list` type 
that needs to be considered, which would make a type that could look like 
`__builtin_abi_va_list_INSERT_TRIPLE_HERE`, with the fact that we can't have 
'-' in types. It might be better to do something similar than 
`ext_vector_type`, and have something like:

  typedef va_list __attribute__((target_abi("arm64-apple-ios"))) 
arm64_ios_abi_va_list; 

This means that `__builtin_ms_abi_va_list` would just be a typedef (and that 
might have some implication on legacy code?).

Another question I would have with that setup is how much this is "transposed" 
into the LLVM world. My feeling is that can be, at least as a first 
implementation, just a "frontend" to assign the darwin or MS ABI to functions.

>> About Apple that would create as much ABIs as products, I guess we have a 
>> living example: is the ABI for OSX/ARM64 different than the ABI for 
>> iOS/ARM64? I can't seem find any official documentation about this :/ (only 
>> talking about arm64 here, but I get your points about armv7 targets).
>
> No, we've used the same basic ABI on iOS, macOS, and tvOS for ARM64.  But 
> that's not surprising because those products were all released within a 
> relatively short period of time from each other, so we don't have much of a 
> laundry list of things we'd like to improve about them.

Okay, thanks for the information!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89490/new/

https://reviews.llvm.org/D89490

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


[PATCH] D95558: [NFC][CUDA] Refactor registering device variable

2021-02-03 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rG0b2af1a28894: [NFC][CUDA] Refactor registering device 
variable (authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D95558?vs=320526=321173#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95558/new/

https://reviews.llvm.org/D95558

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCUDARuntime.h
  clang/lib/CodeGen/CodeGenModule.cpp

Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4297,59 +4297,8 @@
   (D->hasAttr() || D->hasAttr()))
 GV->setExternallyInitialized(true);
 } else {
-  // Host-side shadows of external declarations of device-side
-  // global variables become internal definitions. These have to
-  // be internal in order to prevent name conflicts with global
-  // host variables with the same name in a different TUs.
-  if (D->hasAttr() || D->hasAttr()) {
-Linkage = llvm::GlobalValue::InternalLinkage;
-// Shadow variables and their properties must be registered with CUDA
-// runtime. Skip Extern global variables, which will be registered in
-// the TU where they are defined.
-//
-// Don't register a C++17 inline variable. The local symbol can be
-// discarded and referencing a discarded local symbol from outside the
-// comdat (__cuda_register_globals) is disallowed by the ELF spec.
-// TODO: Reject __device__ constexpr and __device__ inline in Sema.
-if (!D->hasExternalStorage() && !D->isInline())
-  getCUDARuntime().registerDeviceVar(D, *GV, !D->hasDefinition(),
- D->hasAttr());
-  } else if (D->hasAttr()) {
-// __shared__ variables are odd. Shadows do get created, but
-// they are not registered with the CUDA runtime, so they
-// can't really be used to access their device-side
-// counterparts. It's not clear yet whether it's nvcc's bug or
-// a feature, but we've got to do the same for compatibility.
-Linkage = llvm::GlobalValue::InternalLinkage;
-  } else if (D->getType()->isCUDADeviceBuiltinSurfaceType() ||
- D->getType()->isCUDADeviceBuiltinTextureType()) {
-// Builtin surfaces and textures and their template arguments are
-// also registered with CUDA runtime.
-Linkage = llvm::GlobalValue::InternalLinkage;
-const ClassTemplateSpecializationDecl *TD =
-cast(
-D->getType()->getAs()->getDecl());
-const TemplateArgumentList  = TD->getTemplateArgs();
-if (TD->hasAttr()) {
-  assert(Args.size() == 2 &&
- "Unexpected number of template arguments of CUDA device "
- "builtin surface type.");
-  auto SurfType = Args[1].getAsIntegral();
-  if (!D->hasExternalStorage())
-getCUDARuntime().registerDeviceSurf(D, *GV, !D->hasDefinition(),
-SurfType.getSExtValue());
-} else {
-  assert(Args.size() == 3 &&
- "Unexpected number of template arguments of CUDA device "
- "builtin texture type.");
-  auto TexType = Args[1].getAsIntegral();
-  auto Normalized = Args[2].getAsIntegral();
-  if (!D->hasExternalStorage())
-getCUDARuntime().registerDeviceTex(D, *GV, !D->hasDefinition(),
-   TexType.getSExtValue(),
-   Normalized.getZExtValue());
-}
-  }
+  getCUDARuntime().internalizeDeviceSideVar(D, Linkage);
+  getCUDARuntime().handleVarRegistration(D, *GV);
 }
   }
 
Index: clang/lib/CodeGen/CGCUDARuntime.h
===
--- clang/lib/CodeGen/CGCUDARuntime.h
+++ clang/lib/CodeGen/CGCUDARuntime.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_LIB_CODEGEN_CGCUDARUNTIME_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/IR/GlobalValue.h"
 
 namespace llvm {
 class Function;
@@ -80,12 +81,10 @@
 
   /// Emits a kernel launch stub.
   virtual void emitDeviceStub(CodeGenFunction , FunctionArgList ) = 0;
-  virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable ,
- bool Extern, bool Constant) = 0;
-  virtual void registerDeviceSurf(const VarDecl *VD, llvm::GlobalVariable ,
-  bool Extern, int Type) = 0;
-  virtual void registerDeviceTex(const VarDecl *VD, llvm::GlobalVariable ,
- bool Extern, int Type, bool Normalized) = 0;
+
+  /// Check whether a 

[clang] 0b2af1a - [NFC][CUDA] Refactor registering device variable

2021-02-03 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-02-03T14:29:51-05:00
New Revision: 0b2af1a2889423bb797856841ac81cf10d01c696

URL: 
https://github.com/llvm/llvm-project/commit/0b2af1a2889423bb797856841ac81cf10d01c696
DIFF: 
https://github.com/llvm/llvm-project/commit/0b2af1a2889423bb797856841ac81cf10d01c696.diff

LOG: [NFC][CUDA] Refactor registering device variable

Extract registering device variable to CUDA runtime codegen function since it
will be called in multiple places.

Reviewed by: Artem Belevich

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

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CGCUDARuntime.h
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 33a2d6f4483e..42105480eb7c 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -120,12 +120,8 @@ class CGNVCUDARuntime : public CGCUDARuntime {
   void emitDeviceStubBodyNew(CodeGenFunction , FunctionArgList );
   std::string getDeviceSideName(const NamedDecl *ND) override;
 
-public:
-  CGNVCUDARuntime(CodeGenModule );
-
-  void emitDeviceStub(CodeGenFunction , FunctionArgList ) override;
   void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable ,
- bool Extern, bool Constant) override {
+ bool Extern, bool Constant) {
 DeviceVars.push_back({,
   VD,
   {DeviceVarFlags::Variable, Extern, Constant,
@@ -133,7 +129,7 @@ class CGNVCUDARuntime : public CGCUDARuntime {
/*Normalized*/ false, 0}});
   }
   void registerDeviceSurf(const VarDecl *VD, llvm::GlobalVariable ,
-  bool Extern, int Type) override {
+  bool Extern, int Type) {
 DeviceVars.push_back({,
   VD,
   {DeviceVarFlags::Surface, Extern, /*Constant*/ false,
@@ -141,17 +137,27 @@ class CGNVCUDARuntime : public CGCUDARuntime {
/*Normalized*/ false, Type}});
   }
   void registerDeviceTex(const VarDecl *VD, llvm::GlobalVariable ,
- bool Extern, int Type, bool Normalized) override {
+ bool Extern, int Type, bool Normalized) {
 DeviceVars.push_back({,
   VD,
   {DeviceVarFlags::Texture, Extern, /*Constant*/ false,
/*Managed*/ false, Normalized, Type}});
   }
 
+public:
+  CGNVCUDARuntime(CodeGenModule );
+
+  void emitDeviceStub(CodeGenFunction , FunctionArgList ) override;
+  void handleVarRegistration(const VarDecl *VD,
+ llvm::GlobalVariable ) override;
+
   /// Creates module constructor function
   llvm::Function *makeModuleCtorFunction() override;
   /// Creates module destructor function
   llvm::Function *makeModuleDtorFunction() override;
+  void
+  internalizeDeviceSideVar(const VarDecl *D,
+   llvm::GlobalValue::LinkageTypes ) override;
 };
 
 }
@@ -915,3 +921,65 @@ llvm::Function *CGNVCUDARuntime::makeModuleDtorFunction() {
 CGCUDARuntime *CodeGen::CreateNVCUDARuntime(CodeGenModule ) {
   return new CGNVCUDARuntime(CGM);
 }
+
+void CGNVCUDARuntime::internalizeDeviceSideVar(
+const VarDecl *D, llvm::GlobalValue::LinkageTypes ) {
+  // Host-side shadows of external declarations of device-side
+  // global variables become internal definitions. These have to
+  // be internal in order to prevent name conflicts with global
+  // host variables with the same name in a 
diff erent TUs.
+  //
+  // __shared__ variables are odd. Shadows do get created, but
+  // they are not registered with the CUDA runtime, so they
+  // can't really be used to access their device-side
+  // counterparts. It's not clear yet whether it's nvcc's bug or
+  // a feature, but we've got to do the same for compatibility.
+  if (D->hasAttr() || D->hasAttr() ||
+  D->hasAttr() ||
+  D->getType()->isCUDADeviceBuiltinSurfaceType() ||
+  D->getType()->isCUDADeviceBuiltinTextureType()) {
+Linkage = llvm::GlobalValue::InternalLinkage;
+  }
+}
+
+void CGNVCUDARuntime::handleVarRegistration(const VarDecl *D,
+llvm::GlobalVariable ) {
+  if (D->hasAttr() || D->hasAttr()) {
+// Shadow variables and their properties must be registered with CUDA
+// runtime. Skip Extern global variables, which will be registered in
+// the TU where they are defined.
+//
+// Don't register a C++17 inline variable. The local symbol can be
+// discarded and referencing a discarded local symbol from outside the
+// comdat (__cuda_register_globals) is disallowed by the ELF spec.
+// TODO: Reject __device__ constexpr and __device__ inline in Sema.
+if (!D->hasExternalStorage() && 

[PATCH] D94973: [clang][OpenMP] Use OpenMPIRBuilder for workshare loops.

2021-02-03 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added inline comments.



Comment at: clang/lib/AST/Stmt.cpp:1275
-->isScalarType())) &&
-"captures by copy are expected to have a scalar type!");
 break;

jdoerfert wrote:
> Why does this have to go? Is that avoidable?
This is used to capture the loop counter (e.g. `__begin` for a CXXForRangeStmt) 
in front of the loop before it is modified. This can be an iterator whose copy 
constructor needs to be called and this assertion did restrict it to scalar 
types. It is used for the LoopVarFunc closure which is of the form 
`[__begin,&](LogicalIterationNumberTy indvar) { return *(__begin + indvar); }`
The alternative would be to introduce more implicit children of an 
OMPCanonicalLoop that declares a variable and assigns the initial loop counter 
value. I find the byval-capture much more elegant.

The code implementing the byval-capture is shared with the implementation of 
lambdas, so the only reason seems to be that there was no use case when 
introduced in D14940.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94973/new/

https://reviews.llvm.org/D94973

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


[PATCH] D95746: clang: Exclude efi_main from -Wmissing-prototypes

2021-02-03 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Please include test coverage


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95746/new/

https://reviews.llvm.org/D95746

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


[PATCH] D94973: [clang][OpenMP] Use OpenMPIRBuilder for workshare loops.

2021-02-03 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:17274
+  if (IsTopScope && Kind != Sema::TryCapture_Implicit) {
+ByRef = (Kind == Sema::TryCapture_ExplicitByRef);
+  } else if (S.getLangOpts().OpenMP && RSI->CapRegionKind == CR_OpenMP) {

jdoerfert wrote:
> This doesn't impact anyone else negatively? I don't understand why we need 
> this now.
This taken from how implicit lambda captures are handled: for nested lambdas, 
only the outermost lambda captures byval, the remaining use that existing copy. 
I think there are no other uses of CaptureStmt that have explicit captures, I 
am introducing the first.

With removing the assertion and therefore effectively allowing byval captures 
for CapturedStmts, I intended to make its behaviour resemble that of lambdas 
(`captureInLambda`).



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:986
+  if (BodyGenCB)
+BodyGenCB(CL->getBodyIP(), CL->getIndVar());
 

jdoerfert wrote:
> I'm unsure I understand when it would make sense to not have a body generator.
As done by EmitOMPCanonicalLoop, the body code can also added to 
`CL->getBodyIP()` to the CL returned by this function. Calling the callback is 
the last action done anyway, using the callback just makes the code harder to 
understand.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94973/new/

https://reviews.llvm.org/D94973

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


  1   2   3   >