[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-19 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In D129608#3735496 , @jyu2 wrote:

> Hi @alexfh,
>
> How could I reproduce the problem?  Thanks.
> Thanks.
>
> Jennifer

It should be reproducible by running the tests with the address sanitizer 
enabled. But it looks like this might have already been fixed in 
f385eaf48f5c4123b61272cd243c339d6f8526ed 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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


[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-19 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

Hi @alexfh,

How could I reproduce the problem?  Thanks.
Thanks.

Jennifer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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


[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-19 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

It looks like this commit introduces an AddressSanitizer: stack-use-after-scope 
error:

  ==2796==ERROR: AddressSanitizer: stack-use-after-scope on address 
0x7f544e9acc20 at pc 0x55f1f7f4b83e bp 0x7ffdfb37c560 sp 0x7ffdfb37c558
  READ of size 4 at 0x7f544e9acc20 thread T0
  #0 0x55f1f7f4b83d in find 
toolchain/bin/../include/c++/v1/__algorithm/find.h:25:9
  #1 0x55f1f7f4b83d in 
is_contained &, 
clang::OpenMPMapModifierKind> 
llvm-project/llvm/include/llvm/ADT/STLExtras.h:1684:10
  #2 0x55f1f7f4b83d in (anonymous 
namespace)::MappableExprsHandler::getMapTypeBits(clang::OpenMPMapClauseKind, 
llvm::ArrayRef, 
llvm::ArrayRef, bool, bool, bool, bool) const 
llvm-project/clang/lib/CodeGen/CGOpenMPRuntime.cpp:7507:9
  #3 0x55f1f7f460b5 in (anonymous 
namespace)::MappableExprsHandler::generateInfoForComponentList(clang::OpenMPMapClauseKind,
 llvm::ArrayRef, 
llvm::ArrayRef, 
llvm::ArrayRef, 
(anonymous namespace)::MappableExprsHandler::MapCombinedInfoTy&, (anonymous 
namespace)::MappableExprsHandler::StructRangeInfoTy&, bool, bool, 
clang::ValueDecl const*, bool, clang::ValueDecl const*, clang::Expr const*, 
llvm::ArrayRef>)
 const llvm-project/clang/lib/CodeGen/CGOpenMPRuntime.cpp:8078:45
  #4 0x55f1f7f592f7 in generateInfoForCapture 
llvm-project/clang/lib/CodeGen/CGOpenMPRuntime.cpp:9272:9
  #5 0x55f1f7f592f7 in 
clang::CodeGen::CGOpenMPRuntime::emitTargetCall(clang::CodeGen::CodeGenFunction&,
 clang::OMPExecutableDirective const&, llvm::Function*, llvm::Value*, 
clang::Expr const*, llvm::PointerIntPair, llvm::PointerIntPairInfo>>, 
llvm::function_ref)::$_22::operator()(clang::CodeGen::CodeGenFunction&, 
clang::CodeGen::PrePostActionTy&) const 
llvm-project/clang/lib/CodeGen/CGOpenMPRuntime.cpp:10411:19
  #6 0x55f1f7ec9f8b in 
clang::CodeGen::RegionCodeGenTy::operator()(clang::CodeGen::CodeGenFunction&) 
const llvm-project/clang/lib/CodeGen/CGOpenMPRuntime.cpp:603:5
  #7 0x55f1f7f20fb5 in 
clang::CodeGen::CGOpenMPRuntime::emitTargetCall(clang::CodeGen::CodeGenFunction&,
 clang::OMPExecutableDirective const&, llvm::Function*, llvm::Value*, 
clang::Expr const*, llvm::PointerIntPair, llvm::PointerIntPairInfo>>, 
llvm::function_ref) 
llvm-project/clang/lib/CodeGen/CGOpenMPRuntime.cpp:10497:7
  #8 0x55f1f7dbbad3 in 
emitCommonOMPTargetDirective(clang::CodeGen::CodeGenFunction&, 
clang::OMPExecutableDirective const&, clang::CodeGen::RegionCodeGenTy const&) 
llvm-project/clang/lib/CodeGen/CGStmtOpenMP.cpp:6639:26
  #9 0x55f1f7ddb476 in 
clang::CodeGen::CodeGenFunction::EmitOMPTargetDirective(clang::OMPTargetDirective
 const&) llvm-project/clang/lib/CodeGen/CGStmtOpenMP.cpp:6675:3
  #10 0x55f1f7d877db in 
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
 const&, bool, clang::CodeGen::AggValueSlot) 
llvm-project/clang/lib/CodeGen/CGStmt.cpp:531:7
  #11 0x55f1f822ede6 in 
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) 
llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1234:5
  #12 0x55f1f82304de in 
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, 
llvm::Function*, clang::CodeGen::CGFunctionInfo const&) 
llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1442:5
  #13 0x55f1f826ebdf in 
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, 
llvm::GlobalValue*) llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5243:26
  #14 0x55f1f8261f55 in 
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, 
llvm::GlobalValue*) llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3510:9
  #15 0x55f1f824b75d in clang::CodeGen::CodeGenModule::EmitDeferred() 
llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2681:5
  #16 0x55f1f824b79d in clang::CodeGen::CodeGenModule::EmitDeferred() 
llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2687:7
  #17 0x55f1f824742e in clang::CodeGen::CodeGenModule::Release() 
llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:526:3
  #18 0x55f1f848b03f in (anonymous 
namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) 
llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:286:18
  #19 0x55f1f7b5cf7a in 
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) 
llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:306:14
  #20 0x55f1f96d724a in clang::ParseAST(clang::Sema&, bool, bool) 
llvm-project/clang/lib/Parse/ParseAST.cpp:198:13
  #21 0x55f1f7b5816f in clang::CodeGenAction::ExecuteAction() 
llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1144:30
  #22 0x55f1f923f912 in clang::FrontendAction::Execute() 
llvm-project/clang/lib/Frontend/FrontendAction.cpp:1037:8
  #23 0x55f1f916e16d in 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1035:33
  #24 0x55f1f742275c in 
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) 

[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-12 Thread Jennifer Yu 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 rG2ca27206f973: [OpenMP] Fix segmentation fault when data 
field is used in is_device_pt (authored by jyu2).

Changed prior to commit:
  https://reviews.llvm.org/D129608?vs=452272=452335#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_is_device_ptr_codegen.cpp
  openmp/libomptarget/test/mapping/is_device_ptr.cpp

Index: openmp/libomptarget/test/mapping/is_device_ptr.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/is_device_ptr.cpp
@@ -0,0 +1,31 @@
+// RUN: %libomptarget-compilexx-run-and-check-generic
+
+#include 
+#include 
+#include 
+
+struct view {
+  const int size = 10;
+  int *data_host;
+  int *data_device;
+  void foo() {
+std::size_t bytes = size * sizeof(int);
+const int host_id = omp_get_initial_device();
+const int device_id = omp_get_default_device();
+data_host = (int *)malloc(bytes);
+data_device = (int *)omp_target_alloc(bytes, device_id);
+#pragma omp target teams distribute parallel for is_device_ptr(data_device)
+for (int i = 0; i < size; ++i)
+  data_device[i] = i;
+omp_target_memcpy(data_host, data_device, bytes, 0, 0, host_id, device_id);
+for (int i = 0; i < size; ++i)
+  assert(data_host[i] == i);
+  }
+};
+
+int main() {
+  view a;
+  a.foo();
+  // CHECK: PASSED
+  printf("PASSED\n");
+}
Index: clang/test/OpenMP/target_is_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_is_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_is_device_ptr_codegen.cpp
@@ -252,12 +252,13 @@
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[A:%.*]] = getelementptr inbounds [[STRUCT_ST:%.*]], %struct.ST* [[THIS1:%.+]], i32 0, i32 0
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG: store [[ST]]* [[THIS1]], [[ST]]** [[CBP0]]
+// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double**
+// CK2-DAG: store double** [[A]], double*** [[CP0]]
 #pragma omp target is_device_ptr(a)
 {
   a++;
@@ -268,15 +269,21 @@
 // CK2-DAG: store i8** [[BPGEP:%.+]], i8*** [[BPARG]]
 // CK2-DAG: [[PARG:%.+]] = getelementptr inbounds {{.+}}[[ARGS]], i32 0, i32 3
 // CK2-DAG: store i8** [[PGEP:%.+]], i8*** [[PARG]]
+// CK2-DAG: [[SARG:%.+]] = getelementptr inbounds {{.+}}[[ARGS]], i32 0, i32 4
+// CK2-DAG: store i64* [[SIZE:%.+]], i64** [[SARG]]
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[S:%[^,]+]] = sdiv exact i64 [[SZ:%.+]], ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i64)
+// CK2-DAG: [[SIZE:%[^,]+]] = getelementptr inbounds [2 x i64], [2 x i64]* %.offload_sizes, i32 0, i32 0
+// CK2-DAG: store i64 [[S]], i64* [[SIZE]]
+// CK2-DAG: [[B:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 1
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG:  store %struct.ST* [[THIS1]], %struct.ST** [[CBP0]]
+// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double***
+// CK2-DAG: store double*** [[B]], double [[CP0]]
 #pragma omp target is_device_ptr(b)
 {
   b++;
@@ -287,15 +294,22 @@
 // CK2-DAG: store i8** [[BPGEP:%.+]], i8*** [[BPARG]]
 // CK2-DAG: [[PARG:%.+]] = getelementptr inbounds {{.+}}[[ARGS]], i32 0, i32 3
 // CK2-DAG: store i8** [[PGEP:%.+]], i8*** [[PARG]]
+// CK2-DAG: [[SARG:%.+]] = getelementptr inbounds {{.+}}[[ARGS]], i32 0, i32 4
+// CK2-DAG: store i64* [[SIZE:%.+]], i64** [[SARG]]
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[A8:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 0
+// CK2-DAG: [[B9:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 1
+// CK2-DAG: [[S:%[^,]+]] = sdiv exact i64 

[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

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

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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


[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-12 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/test/OpenMP/target_is_device_ptr_codegen.cpp:296
+// CK2-DAG: [[A8:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* 
[[THIS1]], i32 0, i32 0
+// CK2-DAG: [[B9:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* 
[[THIS1]], i32 0, i32 1
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, 
i{{.+}} 0

ABataev wrote:
> What about this one? Is it used in the test?
Th B9 is used for size calculate.  But I did not check that.  So I removed.  
Thanks.  Jennifer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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


[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-12 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 452272.
jyu2 added a comment.

Fix test problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_is_device_ptr_codegen.cpp
  openmp/libomptarget/test/mapping/is_device_ptr.cpp

Index: openmp/libomptarget/test/mapping/is_device_ptr.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/is_device_ptr.cpp
@@ -0,0 +1,32 @@
+// RUN: %libomptarget-compilexx-run-and-check-generic
+
+#include 
+#include 
+#include 
+
+struct view {
+  const int size = 10;
+  int *data_host;
+  int *data_device;
+  void foo() {
+std::size_t bytes = size * sizeof(int);
+const int host_id = omp_get_initial_device();
+const int device_id = omp_get_default_device();
+data_host = (int *)malloc(bytes);
+data_device = (int *)omp_target_alloc(bytes, device_id);
+#pragma omp target teams distribute parallel for is_device_ptr(data_device)
+for (int i = 0; i < size; ++i)
+  data_device[i] = i;
+omp_target_memcpy(data_host, data_device, bytes, 0, 0, host_id, device_id);
+for (int i = 0; i < size; ++i)
+  assert(data_host[i] == i);
+  }
+};
+
+int main() {
+  view a;
+  a.foo();
+  // CHECK: PASSED
+  printf("PASSED\n");
+}
+
Index: clang/test/OpenMP/target_is_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_is_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_is_device_ptr_codegen.cpp
@@ -252,12 +252,13 @@
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[A:%.*]] = getelementptr inbounds [[STRUCT_ST:%.*]], %struct.ST* [[THIS1:%.+]], i32 0, i32 0
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG: store [[ST]]* [[THIS1]], [[ST]]** [[CBP0]]
+// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double**
+// CK2-DAG: store double** [[A]], double*** [[CP0]]
 #pragma omp target is_device_ptr(a)
 {
   a++;
@@ -268,15 +269,21 @@
 // CK2-DAG: store i8** [[BPGEP:%.+]], i8*** [[BPARG]]
 // CK2-DAG: [[PARG:%.+]] = getelementptr inbounds {{.+}}[[ARGS]], i32 0, i32 3
 // CK2-DAG: store i8** [[PGEP:%.+]], i8*** [[PARG]]
+// CK2-DAG: [[SARG:%.+]] = getelementptr inbounds {{.+}}[[ARGS]], i32 0, i32 4
+// CK2-DAG: store i64* [[SIZE:%.+]], i64** [[SARG]]
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[S:%[^,]+]] = sdiv exact i64 [[SZ:%.+]], ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i64)
+// CK2-DAG: [[SIZE:%[^,]+]] = getelementptr inbounds [2 x i64], [2 x i64]* %.offload_sizes, i32 0, i32 0
+// CK2-DAG: store i64 [[S]], i64* [[SIZE]]
+// CK2-DAG: [[B:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 1
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG:  store %struct.ST* [[THIS1]], %struct.ST** [[CBP0]]
+// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double***
+// CK2-DAG: store double*** [[B]], double [[CP0]]
 #pragma omp target is_device_ptr(b)
 {
   b++;
@@ -287,15 +294,22 @@
 // CK2-DAG: store i8** [[BPGEP:%.+]], i8*** [[BPARG]]
 // CK2-DAG: [[PARG:%.+]] = getelementptr inbounds {{.+}}[[ARGS]], i32 0, i32 3
 // CK2-DAG: store i8** [[PGEP:%.+]], i8*** [[PARG]]
+// CK2-DAG: [[SARG:%.+]] = getelementptr inbounds {{.+}}[[ARGS]], i32 0, i32 4
+// CK2-DAG: store i64* [[SIZE:%.+]], i64** [[SARG]]
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[A8:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 0
+// CK2-DAG: [[B9:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 1
+// CK2-DAG: [[S:%[^,]+]] = sdiv exact i64 [[SZ:%.+]], ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i64)
+// CK2-DAG: store i64 [[S]], i64* [[SIZE:%.+]]
+
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds 

[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-11 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/target_is_device_ptr_codegen.cpp:296
+// CK2-DAG: [[A8:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* 
[[THIS1]], i32 0, i32 0
+// CK2-DAG: [[B9:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* 
[[THIS1]], i32 0, i32 1
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, 
i{{.+}} 0

What about this one? Is it used in the test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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


[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-11 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 451959.
jyu2 added a comment.

Thanks Alexey.  This to fix test format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_is_device_ptr_codegen.cpp
  openmp/libomptarget/test/mapping/is_device_ptr.cpp

Index: openmp/libomptarget/test/mapping/is_device_ptr.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/is_device_ptr.cpp
@@ -0,0 +1,32 @@
+// RUN: %libomptarget-compilexx-run-and-check-generic
+
+#include 
+#include 
+#include 
+
+struct view {
+  const int size = 10;
+  int *data_host;
+  int *data_device;
+  void foo() {
+std::size_t bytes = size * sizeof(int);
+const int host_id = omp_get_initial_device();
+const int device_id = omp_get_default_device();
+data_host = (int *)malloc(bytes);
+data_device = (int *)omp_target_alloc(bytes, device_id);
+#pragma omp target teams distribute parallel for is_device_ptr(data_device)
+for (int i = 0; i < size; ++i)
+  data_device[i] = i;
+omp_target_memcpy(data_host, data_device, bytes, 0, 0, host_id, device_id);
+for (int i = 0; i < size; ++i)
+  assert(data_host[i] == i);
+  }
+};
+
+int main() {
+  view a;
+  a.foo();
+  // CHECK: PASSED
+  printf("PASSED\n");
+}
+
Index: clang/test/OpenMP/target_is_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_is_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_is_device_ptr_codegen.cpp
@@ -252,12 +252,13 @@
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[A:%.*]] = getelementptr inbounds [[STRUCT_ST:%.*]], %struct.ST* [[THIS1:%.+]], i32 0, i32 0
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG: store [[ST]]* [[THIS1]], [[ST]]** [[CBP0]]
+// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double**
+// CK2-DAG: store double** [[A]], double*** [[CP0]]
 #pragma omp target is_device_ptr(a)
 {
   a++;
@@ -271,12 +272,13 @@
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[B:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 1
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG:  store %struct.ST* [[THIS1]], %struct.ST** [[CBP0]]
+// CH2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double***
+// CK2-DAG: store double*** [[B]], double [[CP0]]
 #pragma omp target is_device_ptr(b)
 {
   b++;
@@ -290,12 +292,14 @@
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[A8:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 0
+// CK2-DAG: [[B9:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 1
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG:  store %struct.ST* [[THIS1]], %struct.ST** [[CBP0]]
+// CH2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to to double***
+// CK2-DAG: store double** [[A8]], double*** [[TMP64:%.+]]
 #pragma omp target is_device_ptr(a, b)
 {
   a++;
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9052,7 +9052,7 @@
 // If this declaration appears in a is_device_ptr clause we just have to
 // pass the pointer by value. If it is a reference to a declaration, we just
 // pass its value.
-if (DevPointersMap.count(VD)) {
+if (VD && DevPointersMap.count(VD)) {
   CombinedInfo.Exprs.push_back(VD);
   

[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-11 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9080
+DeclComponentLists.emplace_back(
+MCL, OMPC_MAP_to, OMPC_MAP_MODIFIER_unknown, /*IsImpicit = */ true,
+nullptr, nullptr);

Shall it be `OMP_MAP_LITERAL`? Previously we emitted `OMP_MAP_LITERAL` for such 
items (line 9062)



Comment at: clang/test/OpenMP/target_is_device_ptr_codegen.cpp:260
+// CK2-DAG: store [[ST]]* [[THIS1]], [[ST]]** [[CBP0]]
+// CK2-DAG: store double** %a, double*** [[TMP3:%.+]]
 #pragma omp target is_device_ptr(a)

```
// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to double**
// CK2-DAG: store double** [[A]], double*** [[CP0]]
```
?



Comment at: clang/test/OpenMP/target_is_device_ptr_codegen.cpp:278-279
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG:  store %struct.ST* [[THIS1]], %struct.ST** [[CBP0]]
+// CK2-DAG: store double*** [[B]], double [[TMP30:%.+]]
 #pragma omp target is_device_ptr(b)

Format and checks.



Comment at: clang/test/OpenMP/target_is_device_ptr_codegen.cpp:299
+// CK2-DAG:  store %struct.ST* [[THIS1]], %struct.ST** [[CBP0]]
+// CK2-DAG: store double** [[A8]], double*** [[TMP64:%.+]]
 #pragma omp target is_device_ptr(a, b)

same


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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


[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-11 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9076
+// DeclComponentLists for generating components info.
+auto It = DevPointersMap.find(VD);
+if (It != DevPointersMap.end())

ABataev wrote:
> VD is still nullptr here, why do we need to lookup for it?
VD is nullptr, it represent of this pointer.  And it is DevPointersMap.  Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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


[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-11 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9076
+// DeclComponentLists for generating components info.
+auto It = DevPointersMap.find(VD);
+if (It != DevPointersMap.end())

VD is still nullptr here, why do we need to lookup for it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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


[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-11 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9073
 SmallVector DeclComponentLists;
+if (DevPointersMap.count(VD)) {
+  // For member fields list in is_device_ptr, store it in

ABataev wrote:
> If VD is nullptr, why do we need this check?
Yes.  You are right.  It is unnecessary change.  I removed.  Thanks.  Jennifer 



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9080
+  DeclComponentLists.emplace_back(MCL, OMPC_MAP_to,
+  OMPC_MAP_MODIFIER_unknown, true,
+  nullptr, nullptr);

ABataev wrote:
> comment with the name of parameter, associated with `true` value.
Sorry.  Added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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


[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-11 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 451939.
jyu2 added a comment.

Thanks Alexey!  Address the comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_is_device_ptr_codegen.cpp
  openmp/libomptarget/test/mapping/is_device_ptr.cpp

Index: openmp/libomptarget/test/mapping/is_device_ptr.cpp
===
--- /dev/null
+++ openmp/libomptarget/test/mapping/is_device_ptr.cpp
@@ -0,0 +1,32 @@
+// RUN: %libomptarget-compilexx-run-and-check-generic
+
+#include 
+#include 
+#include 
+
+struct view {
+  const int size = 10;
+  int *data_host;
+  int *data_device;
+  void foo() {
+std::size_t bytes = size * sizeof(int);
+const int host_id = omp_get_initial_device();
+const int device_id = omp_get_default_device();
+data_host = (int *)malloc(bytes);
+data_device = (int *)omp_target_alloc(bytes, device_id);
+#pragma omp target teams distribute parallel for is_device_ptr(data_device)
+for (int i = 0; i < size; ++i)
+  data_device[i] = i;
+omp_target_memcpy(data_host, data_device, bytes, 0, 0, host_id, device_id);
+for (int i = 0; i < size; ++i)
+  assert(data_host[i] == i);
+  }
+};
+
+int main() {
+  view a;
+  a.foo();
+  // CHECK: PASSED
+  printf("PASSED\n");
+}
+
Index: clang/test/OpenMP/target_is_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_is_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_is_device_ptr_codegen.cpp
@@ -252,12 +252,12 @@
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[A:%.*]] = getelementptr inbounds [[STRUCT_ST:%.*]], %struct.ST* [[THIS1:%.+]], i32 0, i32 0
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG: store [[ST]]* [[THIS1]], [[ST]]** [[CBP0]]
+// CK2-DAG: store double** %a, double*** [[TMP3:%.+]]
 #pragma omp target is_device_ptr(a)
 {
   a++;
@@ -271,12 +271,12 @@
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[B:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 1
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG:  store %struct.ST* [[THIS1]], %struct.ST** [[CBP0]]
+// CK2-DAG: store double*** [[B]], double [[TMP30:%.+]]
 #pragma omp target is_device_ptr(b)
 {
   b++;
@@ -290,12 +290,13 @@
 // CK2-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
 // CK2-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
 
+// CK2-DAG: [[A8:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 0
+// CK2-DAG: [[B9:%.*]] = getelementptr inbounds [[STRUCT_ST]], %struct.ST* [[THIS1]], i32 0, i32 1
 // CK2-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
 // CK2-DAG: [[CBP0:%.+]] = bitcast i8** [[BP0]] to [[ST]]**
-// CK2-DAG: [[CP0:%.+]] = bitcast i8** [[P0]] to [[ST]]**
-// CK2-DAG: store [[ST]]* [[VAR0:%.+]], [[ST]]** [[CBP0]]
-// CK2-DAG: store [[ST]]* [[VAR0]], [[ST]]** [[CP0]]
+// CK2-DAG:  store %struct.ST* [[THIS1]], %struct.ST** [[CBP0]]
+// CK2-DAG: store double** [[A8]], double*** [[TMP64:%.+]]
 #pragma omp target is_device_ptr(a, b)
 {
   a++;
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9052,7 +9052,7 @@
 // If this declaration appears in a is_device_ptr clause we just have to
 // pass the pointer by value. If it is a reference to a declaration, we just
 // pass its value.
-if (DevPointersMap.count(VD)) {
+if (VD && DevPointersMap.count(VD)) {
   CombinedInfo.Exprs.push_back(VD);
   CombinedInfo.BasePointers.emplace_back(Arg, VD);
   CombinedInfo.Pointers.push_back(Arg);
@@ -9071,6 +9071,14 @@
OpenMPMapClauseKind, ArrayRef, bool,
   

[PATCH] D129608: [Clang][OpenMP] Fix segmentation fault when data field is used in is_device_pt.

2022-08-11 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9073
 SmallVector DeclComponentLists;
+if (DevPointersMap.count(VD)) {
+  // For member fields list in is_device_ptr, store it in

If VD is nullptr, why do we need this check?



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:9080
+  DeclComponentLists.emplace_back(MCL, OMPC_MAP_to,
+  OMPC_MAP_MODIFIER_unknown, true,
+  nullptr, nullptr);

comment with the name of parameter, associated with `true` value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129608

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