[clang] 1d0bd8e - [MSABI] Remove comdat attribute for inheriting ctor.

2023-08-28 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-08-28T15:19:23-07:00
New Revision: 1d0bd8e51be2627f79bede54735c38b917ea04ee

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

LOG: [MSABI] Remove comdat attribute for inheriting ctor.

Currently, for MS, the linkage for the inheriting constructors is set to
internal.  However, the comdat attribute is also set like:

define internal noundef ptr @"??0?$B@_N@@qeaa@AEBVF@@aebua@@@z"(ptr noundef 
nonnull returned align 1 dereferenceable(1) %this, ptr noundef nonnull align 1 
dereferenceable(1) %0, ptr noundef nonnull align 1 dereferenceable(1) %1) 
unnamed_addr comdat

This could cause linker to fail.

The change is to remove comdat attribute for the inheriting constructor
to make linker happy.

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

Added: 
clang/test/CodeGenCXX/ms-inheriting-ctor.cpp

Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 42cc68c9b66285..8ab499be1ed2c7 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -11688,6 +11688,14 @@ static GVALinkage basicGVALinkageForFunction(const 
ASTContext ,
   if (FD->isMSExternInline())
 return GVA_StrongODR;
 
+  if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
+  isa(FD) &&
+  cast(FD)->isInheritingConstructor())
+// Our approach to inheriting constructors is fundamentally 
diff erent from
+// that used by the MS ABI, so keep our inheriting constructor thunks
+// internal rather than trying to pick an unambiguous mangling for them.
+return GVA_Internal;
+
   return GVA_DiscardableODR;
 }
 

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 9b241165b7c579..08bc1a8d018606 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1970,15 +1970,6 @@ CodeGenModule::getFunctionLinkage(GlobalDecl GD) {
   if (const auto *Dtor = dyn_cast(D))
 return getCXXABI().getCXXDestructorLinkage(Linkage, Dtor, 
GD.getDtorType());
 
-  if (isa(D) &&
-  cast(D)->isInheritingConstructor() &&
-  Context.getTargetInfo().getCXXABI().isMicrosoft()) {
-// Our approach to inheriting constructors is fundamentally 
diff erent from
-// that used by the MS ABI, so keep our inheriting constructor thunks
-// internal rather than trying to pick an unambiguous mangling for them.
-return llvm::GlobalValue::InternalLinkage;
-  }
-
   return getLLVMLinkageForDeclarator(D, Linkage);
 }
 

diff  --git a/clang/test/CodeGenCXX/ms-inheriting-ctor.cpp 
b/clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
new file mode 100644
index 00..6c6cdcf2c358c2
--- /dev/null
+++ b/clang/test/CodeGenCXX/ms-inheriting-ctor.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc -emit-llvm %s 
-o - | FileCheck %s
+
+class F {
+public:
+  F(wchar_t *);
+};
+using a = F;
+struct A {};
+struct b {
+  b(a, F, A);
+};
+template  struct c : b {
+  c(const a , const A ) : b(p1, 0, d) {}
+};
+template  struct B : c {
+  using c::c;
+};
+class f {
+public:
+  f(...);
+}
+
+typedef g;
+class C {
+public:
+  C(g, f);
+};
+static wchar_t h;
+class D {
+public:
+  static C E();
+};
+
+C D::E() {
+  C i(B(, {}), f());
+  return i;
+}
+
+// Inheriting ctor has internal linkage without comdat.
+
+// CHECK-LABEL: define internal noundef ptr @"??0?$B@_N@@QEAA@AEBVF@@AEBUA@@@Z"
+// CHECK-NOT:comdat
+// CHECK-SAME: {{\{$}}
+
+// non-inheriting ctro should has linkonce_odr with comdat attribute.
+
+// CHECK-LABEL: define linkonce_odr dso_local noundef ptr 
@"??0?$c@_NUbQEAA@AEBVF@@AEBUA@@@Z"
+// CHECK:comdat
+// CHECK-SAME: {{\{$}}



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


[clang] ff08c8e - [SEH] Fix wrong argument passes to the call of OutlinedFinally.

2023-08-21 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-08-21T17:07:38-07:00
New Revision: ff08c8e57e39d7970b65637595cdc221901f4ed1

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

LOG: [SEH] Fix wrong argument passes to the call of OutlinedFinally.

When return out of __try block.  In this test case, currently "false" is
passed to OutlinedFinally's call.  "true" should be passed to indicate
abnormal terminations.

The rule: Except _leave and fall-through at the end, all other exits
in a _try (return/goto/continue/break) are considered as abnormal
terminations, NormalCleanupDestSlot is used to indicate abnormal
terminations.

The problem is, during the processing abnormal terminations,
the ExitSwitch is used.  However, in this case, Existswitch is route out.

One way to fix is to skip route it without a switch. So proper
abnormal termination's code could be generated.

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

Added: 


Modified: 
clang/lib/CodeGen/CGCleanup.cpp
clang/test/CodeGen/exceptions-seh-finally.c
clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index cd51024a2b32d9..f87caf050eeaa7 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -873,8 +873,13 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
 
   // If there's exactly one branch-after and no other threads,
   // we can route it without a switch.
+  // Skip for SEH, since ExitSwitch is used to generate code to indicate
+  // abnormal termination. (SEH: Except _leave and fall-through at
+  // the end, all other exits in a _try (return/goto/continue/break)
+  // are considered as abnormal terminations, using NormalCleanupDestSlot
+  // to indicate abnormal termination)
   if (!Scope.hasBranchThroughs() && !HasFixups && !HasFallthrough &&
-  Scope.getNumBranchAfters() == 1) {
+  !currentFunctionUsesSEHTry() && Scope.getNumBranchAfters() == 1) {
 assert(!BranchThroughDest || !IsActive);
 
 // Clean up the possibly dead store to the cleanup dest slot.

diff  --git a/clang/test/CodeGen/exceptions-seh-finally.c 
b/clang/test/CodeGen/exceptions-seh-finally.c
index 8ef5ca807b1d3b..0cdf2303112500 100644
--- a/clang/test/CodeGen/exceptions-seh-finally.c
+++ b/clang/test/CodeGen/exceptions-seh-finally.c
@@ -154,8 +154,11 @@ int finally_with_return(void) {
   }
 }
 // CHECK-LABEL: define dso_local i32 @finally_with_return()
+// CHECK: store i32 1, ptr %cleanup.dest.slot
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: icmp ne i32 %cleanup.dest
 // CHECK: call void @"?fin$0@0@finally_with_return@@"({{.*}})
-// CHECK-NEXT: ret i32 42
+// CHECK: ret i32 42
 
 // CHECK: define internal void @"?fin$0@0@finally_with_return@@"({{.*}})
 // CHECK-SAME: [[finally_attrs]]

diff  --git a/clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp 
b/clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
index 4494e284b462c2..fab567e763df44 100644
--- a/clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
+++ b/clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions 
-fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S 
-emit-llvm %s -o - | FileCheck %s
 
+// CHECK-LABEL: @main()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
@@ -40,3 +41,29 @@ int main() {
   }
   return 0;
 }
+
+// CHECK-LABEL:@"?foo@@YAXXZ"()
+// CHECK: invoke.cont:
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: store volatile i32 1, ptr %cleanup.dest.slot
+// CHECK: invoke void @llvm.seh.try.end()
+// CHECK: invoke.cont2:
+// CHECK: %cleanup.dest = load i32, ptr %cleanup.dest.slot
+// CHECK: %1 = icmp ne i32 %cleanup.dest, 0
+// CHECK: %2 = zext i1 %1 to i8
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef %2, ptr noundef %0)
+// CHECK: ehcleanup:
+// CHECK: call void @"?fin$0@0@foo@@"(i8 noundef 1, ptr noundef %4)
+void foo()
+{
+  __try {
+return;
+  }
+  __finally {
+if (_abnormal_termination()) {
+  printf("Passed\n");
+} else {
+  printf("Failed\n");
+}
+  }
+}



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


[clang] 33e3b2c - Fix assertion when -fasy-exception is used.

2023-08-10 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-08-10T21:54:32-07:00
New Revision: 33e3b2c46084bc47ef4067ed487b24b58934d044

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

LOG: Fix assertion when -fasy-exception is used.

The assertion only happens with use of -fasy-exception without
-fexcessions.

The assertion appen during the call to generate SehScopeBegin(), where
assert with:
assert(CGF.Builder.GetInsertBlock() && InvokeDest);
InvokeDest is null. Because exceptions are disabled, and SEH is not
in use.
The fix is before call EmitSehCppScopeBegin check getInvokeDest(),
to avoid assert during the emit llvm.seh.scope.begin()

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

Added: 
clang/test/CodeGen/windows-seh-async-exceptions.cpp

Modified: 
clang/lib/CodeGen/CGCleanup.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 0bbab283603d98..cd51024a2b32d9 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -207,8 +207,13 @@ void *EHScopeStack::pushCleanup(CleanupKind Kind, size_t 
Size) {
 Scope->setLifetimeMarker();
 
   // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
+  // If exceptions are disabled/ignored and SEH is not in use, then there is no
+  // invoke destination. SEH "works" even if exceptions are off. In practice,
+  // this means that C++ destructors and other EH cleanups don't run, which is
+  // consistent with MSVC's behavior, except in the presence of -EHa.
+  // Check getInvokeDest() to generate llvm.seh.scope.begin() as needed.
   if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
-  CGF->getTarget().getCXXABI().isMicrosoft())
+  CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest())
 CGF->EmitSehCppScopeBegin();
 
   return Scope->getCleanupBuffer();

diff  --git a/clang/test/CodeGen/windows-seh-async-exceptions.cpp 
b/clang/test/CodeGen/windows-seh-async-exceptions.cpp
new file mode 100644
index 00..8d78373151a00b
--- /dev/null
+++ b/clang/test/CodeGen/windows-seh-async-exceptions.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -x c++ \
+// RUN:  -emit-llvm %s -o -| FileCheck %s
+
+extern "C" int printf(const char*,...);
+class PrintfArg
+{
+public:
+  PrintfArg();
+  PrintfArg(const char* s);
+
+  // compiler crash fixed if this destructor removed
+  ~PrintfArg() {int x; printf("ddd\n");  }
+};
+
+void devif_Warning(const char* fmt, PrintfArg arg1 = PrintfArg());
+// CHECK-NOT: invoke void @llvm.seh.scope.begin()
+// CHECK-NOT: invoke void @llvm.seh.scope.end()
+unsigned myfunc(unsigned index)
+{
+  devif_Warning("");
+  return 0;
+}



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


[clang] 852fe30 - [OPENMP52] Deprecation of 'depend' clause in ordered directive.

2023-07-07 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-07-07T13:07:17-07:00
New Revision: 852fe30b687e1df9f67007944a90c748ea77f587

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

LOG: [OPENMP52] Deprecation of 'depend' clause in ordered directive.

BTW, I need change test ordered_doacross_codegen.c since I can not use
macro _OPENMP >= 202111 due to use of -fopenmp-simd.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseOpenMP.cpp
clang/test/OpenMP/ordered_doacross_codegen.c
clang/test/OpenMP/ordered_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 40e1a381eb77f6..4b1dcc89e7cae8 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1529,6 +1529,8 @@ def err_omp_requires_out_inout_depend_type : Error<
 def warn_omp_more_one_omp_all_memory : Warning<
   "reserved locator 'omp_all_memory' cannot be specified more than once">,
   InGroup;
+def warn_omp_depend_in_ordered_deprecated : Warning<"'depend' clause for"
+  " 'ordered' is deprecated; use 'doacross' instead">, InGroup;
 
 // Pragma loop support.
 def err_pragma_loop_missing_argument : Error<

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index fc7f0070ff06a3..96d2e2cede6289 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -3367,6 +3367,9 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind 
DKind,
   case OMPC_exclusive:
   case OMPC_affinity:
   case OMPC_doacross:
+if (getLangOpts().OpenMP >= 52 && DKind == OMPD_ordered &&
+CKind == OMPC_depend)
+  Diag(Tok, diag::warn_omp_depend_in_ordered_deprecated);
 Clause = ParseOpenMPVarListClause(DKind, CKind, WrongDirective);
 break;
   case OMPC_sizes:

diff  --git a/clang/test/OpenMP/ordered_doacross_codegen.c 
b/clang/test/OpenMP/ordered_doacross_codegen.c
index 48e075346ca11a..1a22c13f287622 100644
--- a/clang/test/OpenMP/ordered_doacross_codegen.c
+++ b/clang/test/OpenMP/ordered_doacross_codegen.c
@@ -2,21 +2,21 @@
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -triple x86_64-unknown-unknown -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
 
-// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm 
%s -o - -fopenmp-version=52 | FileCheck %s --check-prefixes=CHECK,CHECK-NORMAL
+// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -emit-llvm 
%s -o - -fopenmp-version=52 -DOMP52 | FileCheck %s 
--check-prefixes=CHECK,CHECK-NORMAL
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-IRBUILDER
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -fopenmp-version=52 -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -fopenmp-version=52 -DOMP52 -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -triple 
x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
%s --check-prefixes=CHECK,CHECK-IRBUILDER
 
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder 
-triple x86_64-unknown-unknown -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -fopenmp-enable-irbuilder 
-triple x86_64-unknown-unknown -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 
-fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -DOMP52 
-fopenmp-enable-irbuilder -triple x86_64-unknown-unknown -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-IRBUILDER
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -DOMP52 -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 
%s
 // RUN: 

[clang] f70967f - [OPENMP52] Support Support omp_cur_iteration modifier for doacross

2023-07-06 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-07-06T11:40:02-07:00
New Revision: f70967fdc4736a5c5150db294be55fa9e7792bb8

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

LOG: [OPENMP52] Support Support omp_cur_iteration modifier for doacross
clause.

This is just syntax to make it easier for the user. It doesn't add any
new functionality.

for
doacross(sink: omp_cur_iteration - 1)
Equivalent to
doacross(sink: ConterVar - 1, ...)

doacross(source: omp_cur_iteration)
Equivalent to
doacross(source)

And restriction is:
OMP5.2 p.327

If vector is specified with the omp_cur_iteration keyword and with
sink as the dependence-type then it must be omp_cur_iteration - 1.

If vector is specified with source as the dependence-type then it must be
omp_cur_iteration.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/lib/AST/OpenMPClause.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/ordered_ast_print.cpp
clang/test/OpenMP/ordered_doacross_codegen.c
clang/test/OpenMP/ordered_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 4a375bb5c66552..40e1a381eb77f6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1363,6 +1363,7 @@ def err_omp_expected_punc_after_iterator : Error<
   "expected ',' or ')' after iterator specifier">;
 def err_omp_decl_in_declare_simd_variant : Error<
   "function declaration is expected after 'declare %select{simd|variant}0' 
directive">;
+def err_omp_sink_and_source_iteration_not_allowd: Error<" '%0 
%select{sink:|source:}1' must be with '%select{omp_cur_iteration - 
1|omp_cur_iteration}1'">;
 def err_omp_unknown_map_type : Error<
   "incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 
'release', or 'delete'">;
 def err_omp_unknown_map_type_modifier : Error<

diff  --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index eb5037c629dbf7..c999b8b9c4ff59 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -207,6 +207,8 @@ OPENMP_NUMTASKS_MODIFIER(strict)
 // Modifiers for the 'doacross' clause.
 OPENMP_DOACROSS_MODIFIER(source)
 OPENMP_DOACROSS_MODIFIER(sink)
+OPENMP_DOACROSS_MODIFIER(sink_omp_cur_iteration)
+OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)
 
 #undef OPENMP_NUMTASKS_MODIFIER
 #undef OPENMP_GRAINSIZE_MODIFIER

diff  --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index 4fc63093a87133..98870b368789c2 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2513,7 +2513,23 @@ void OMPClausePrinter::VisitOMPXDynCGroupMemClause(
 void OMPClausePrinter::VisitOMPDoacrossClause(OMPDoacrossClause *Node) {
   OS << "doacross(";
   OpenMPDoacrossClauseModifier DepType = Node->getDependenceType();
-  OS << (DepType == OMPC_DOACROSS_source ? "source:" : "sink:");
+
+  switch (DepType) {
+  case OMPC_DOACROSS_source:
+OS << "source:";
+break;
+  case OMPC_DOACROSS_sink:
+OS << "sink:";
+break;
+  case OMPC_DOACROSS_source_omp_cur_iteration:
+OS << "source: omp_cur_iteration";
+break;
+  case OMPC_DOACROSS_sink_omp_cur_iteration:
+OS << "sink: omp_cur_iteration - 1";
+break;
+  default:
+llvm_unreachable("unknown docaross modifier");
+  }
   VisitOMPClauseList(Node, ' ');
   OS << ")";
 }

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.h 
b/clang/lib/CodeGen/CGOpenMPRuntime.h
index 20525feca05c32..af801e312c966d 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -2310,10 +2310,12 @@ template <> class OMPDoacrossKind {
 template <> class OMPDoacrossKind {
 public:
   bool isSource(const OMPDoacrossClause *C) {
-return (C->getDependenceType() == OMPC_DOACROSS_source);
+return C->getDependenceType() == OMPC_DOACROSS_source ||
+   C->getDependenceType() == OMPC_DOACROSS_source_omp_cur_iteration;
   }
   bool isSink(const OMPDoacrossClause *C) {
-return (C->getDependenceType() == OMPC_DOACROSS_sink);
+return C->getDependenceType() == OMPC_DOACROSS_sink ||
+   C->getDependenceType() == OMPC_DOACROSS_sink_omp_cur_iteration;
   }
 };
 } // namespace

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 8c4cf306bde2c4..fc7f0070ff06a3 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4410,16 +4410,55 @@ bool 

[clang] 35041a4 - [OPENMP52] Codegen support for doacross clause.

2023-07-03 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-07-03T15:24:05-07:00
New Revision: 35041a435def860e2b1b99133b934632a9d634ac

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

LOG: [OPENMP52] Codegen support for doacross clause.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/ordered_doacross_codegen.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 32964aa7d7e39e..188b21e3a88949 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11381,8 +11381,10 @@ void CGOpenMPRuntime::emitDoacrossInit(CodeGenFunction 
,
  llvm::ArrayRef(FiniArgs));
 }
 
-void CGOpenMPRuntime::emitDoacrossOrdered(CodeGenFunction ,
-  const OMPDependClause *C) {
+template 
+static void EmitDoacrossOrdered(CodeGenFunction , CodeGenModule ,
+const T *C, llvm::Value *ULoc,
+llvm::Value *ThreadID) {
   QualType Int64Ty =
   CGM.getContext().getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1);
   llvm::APInt Size(/*numBits=*/32, C->getNumLoops());
@@ -11399,21 +11401,35 @@ void 
CGOpenMPRuntime::emitDoacrossOrdered(CodeGenFunction ,
   /*Volatile=*/false, Int64Ty);
   }
   llvm::Value *Args[] = {
-  emitUpdateLocation(CGF, C->getBeginLoc()),
-  getThreadID(CGF, C->getBeginLoc()),
-  CGF.Builder.CreateConstArrayGEP(CntAddr, 0).getPointer()};
+  ULoc, ThreadID, CGF.Builder.CreateConstArrayGEP(CntAddr, 
0).getPointer()};
   llvm::FunctionCallee RTLFn;
-  if (C->getDependencyKind() == OMPC_DEPEND_source) {
+  llvm::OpenMPIRBuilder  = CGM.getOpenMPRuntime().getOMPBuilder();
+  OMPDoacrossKind ODK;
+  if (ODK.isSource(C)) {
 RTLFn = OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(),
   OMPRTL___kmpc_doacross_post);
   } else {
-assert(C->getDependencyKind() == OMPC_DEPEND_sink);
+assert(ODK.isSink(C) && "Expect sink modifier.");
 RTLFn = OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(),
   OMPRTL___kmpc_doacross_wait);
   }
   CGF.EmitRuntimeCall(RTLFn, Args);
 }
 
+void CGOpenMPRuntime::emitDoacrossOrdered(CodeGenFunction ,
+  const OMPDependClause *C) {
+  return EmitDoacrossOrdered(
+  CGF, CGM, C, emitUpdateLocation(CGF, C->getBeginLoc()),
+  getThreadID(CGF, C->getBeginLoc()));
+}
+
+void CGOpenMPRuntime::emitDoacrossOrdered(CodeGenFunction ,
+  const OMPDoacrossClause *C) {
+  return EmitDoacrossOrdered(
+  CGF, CGM, C, emitUpdateLocation(CGF, C->getBeginLoc()),
+  getThreadID(CGF, C->getBeginLoc()));
+}
+
 void CGOpenMPRuntime::emitCall(CodeGenFunction , SourceLocation Loc,
llvm::FunctionCallee Callee,
ArrayRef Args) const {
@@ -12400,6 +12416,11 @@ void 
CGOpenMPSIMDRuntime::emitDoacrossOrdered(CodeGenFunction ,
   llvm_unreachable("Not supported in SIMD-only mode");
 }
 
+void CGOpenMPSIMDRuntime::emitDoacrossOrdered(CodeGenFunction ,
+  const OMPDoacrossClause *C) {
+  llvm_unreachable("Not supported in SIMD-only mode");
+}
+
 const VarDecl *
 CGOpenMPSIMDRuntime::translateParameter(const FieldDecl *FD,
 const VarDecl *NativeParam) const {

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.h 
b/clang/lib/CodeGen/CGOpenMPRuntime.h
index 4370c95e03feac..e346ef2b49a0ec 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -1487,6 +1487,11 @@ class CGOpenMPRuntime {
   virtual void emitDoacrossOrdered(CodeGenFunction ,
const OMPDependClause *C);
 
+  /// Emit code for doacross ordered directive with 'doacross' clause.
+  /// \param C 'doacross' clause with 'sink|source' dependence type.
+  virtual void emitDoacrossOrdered(CodeGenFunction ,
+   const OMPDoacrossClause *C);
+
   /// Translates the native parameter of outlined function if this is required
   /// for target.
   /// \param FD Field decl from captured record for the parameter.
@@ -2240,6 +2245,11 @@ class CGOpenMPSIMDRuntime final : public CGOpenMPRuntime 
{
   void emitDoacrossOrdered(CodeGenFunction ,
const OMPDependClause *C) override;
 
+  /// Emit code for doacross ordered directive with 'doacross' clause.
+ 

[clang] 085845a - [OMP5.2] Initial support for doacross clause.

2023-06-29 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-06-29T11:58:17-07:00
New Revision: 085845a2acbefd26d5c229338225dfd76e2c2df3

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

LOG: [OMP5.2] Initial support for doacross clause.

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Basic/OpenMPKinds.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/ordered_ast_print.cpp
clang/test/OpenMP/ordered_messages.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 627e9025c11289..0bea21270692cf 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -9046,6 +9046,132 @@ class OMPXDynCGroupMemClause
   Expr *getSize() const { return getStmtAs(); }
 };
 
+/// This represents the 'doacross' clause for the '#pragma omp ordered'
+/// directive.
+///
+/// \code
+/// #pragma omp ordered doacross(sink: i-1, j-1)
+/// \endcode
+/// In this example directive '#pragma omp ordered' with clause 'doacross' with
+/// a dependence-type 'sink' and loop-iteration vector expressions i-1 and j-1.
+class OMPDoacrossClause final
+: public OMPVarListClause,
+  private llvm::TrailingObjects {
+  friend class OMPClauseReader;
+  friend OMPVarListClause;
+  friend TrailingObjects;
+
+  /// Dependence type (sink or source).
+  OpenMPDoacrossClauseModifier DepType = OMPC_DOACROSS_unknown;
+
+  /// Dependence type location.
+  SourceLocation DepLoc;
+
+  /// Colon location.
+  SourceLocation ColonLoc;
+
+  /// Number of loops, associated with the doacross clause.
+  unsigned NumLoops = 0;
+
+  /// Build clause with number of expressions \a N.
+  ///
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  /// \param N Number of expressions in the clause.
+  /// \param NumLoops Number of loops associated with the clause.
+  OMPDoacrossClause(SourceLocation StartLoc, SourceLocation LParenLoc,
+SourceLocation EndLoc, unsigned N, unsigned NumLoops)
+  : OMPVarListClause(llvm::omp::OMPC_doacross, StartLoc,
+LParenLoc, EndLoc, N),
+NumLoops(NumLoops) {}
+
+  /// Build an empty clause.
+  ///
+  /// \param N Number of expressions in the clause.
+  /// \param NumLoops Number of loops associated with the clause.
+  explicit OMPDoacrossClause(unsigned N, unsigned NumLoops)
+  : OMPVarListClause(llvm::omp::OMPC_doacross,
+SourceLocation(), SourceLocation(),
+SourceLocation(), N),
+NumLoops(NumLoops) {}
+
+  /// Set dependence type.
+  void setDependenceType(OpenMPDoacrossClauseModifier M) { DepType = M; }
+
+  /// Set dependence type location.
+  void setDependenceLoc(SourceLocation Loc) { DepLoc = Loc; }
+
+  /// Set colon location.
+  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
+
+public:
+  /// Creates clause with a list of expressions \a VL.
+  ///
+  /// \param C AST context.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  /// \param DepType The dependence type.
+  /// \param DepLoc Location of the dependence type.
+  /// \param ColonLoc Location of ':'.
+  /// \param VL List of references to the expressions.
+  /// \param NumLoops Number of loops that associated with the clause.
+  static OMPDoacrossClause *
+  Create(const ASTContext , SourceLocation StartLoc, SourceLocation 
LParenLoc,
+ SourceLocation EndLoc, OpenMPDoacrossClauseModifier DepType,
+ SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef VL,
+ unsigned NumLoops);
+
+  /// Creates an empty clause with \a N expressions.
+  ///
+  /// \param C AST context.
+  /// \param N The number of expressions.
+  /// \param NumLoops Number of loops that is associated with this clause.
+  static OMPDoacrossClause *CreateEmpty(const ASTContext , unsigned N,
+unsigned NumLoops);
+
+  /// Get dependence type.
+  

[clang] aaa33b6 - Fix assert "DeclRefExpr for Decl not entered in LocalDeclMap?"

2023-05-30 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-05-30T16:40:06-07:00
New Revision: aaa33b6a98de2be7cdc827b13e60c103206d6461

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

LOG: Fix assert "DeclRefExpr for Decl not entered in LocalDeclMap?"

Currently compiler assert when passing variable "memspace" in
omp_init_allocator.

omp_allocator_handle_t alloc=omp_init_allocator(memspace,1,traits)

The problem is memspace is not mapping to the target region.  During
the call to emitAllocatorInit, calls to EmitVarDecl for "alloc", then
emit initialization of "alloc" that cause to assert.

If I understant correct, it is not necessary to emit variable
initialization, since "allocator" is private to target region.

To fix this call CGF.EmitAutoVarAlloca(allocator) instead
CGF.EmitVarDecl(allocator).

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_uses_allocators.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 1f1db83378233..5957e59097709 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6041,7 +6041,7 @@ void 
CGOpenMPRuntime::emitUsesAllocatorsInit(CodeGenFunction ,
   CGM.getModule(), OMPRTL___kmpc_init_allocator),
   {ThreadId, MemSpaceHandle, NumTraits, Traits});
   // Store to allocator.
-  CGF.EmitVarDecl(*cast(
+  CGF.EmitAutoVarAlloca(*cast(
   cast(Allocator->IgnoreParenImpCasts())->getDecl()));
   LValue AllocatorLVal = CGF.EmitLValue(Allocator->IgnoreParenImpCasts());
   AllocatorVal =

diff  --git a/clang/test/OpenMP/target_uses_allocators.c 
b/clang/test/OpenMP/target_uses_allocators.c
index eab202671e793..0352a5874bf12 100644
--- a/clang/test/OpenMP/target_uses_allocators.c
+++ b/clang/test/OpenMP/target_uses_allocators.c
@@ -64,6 +64,35 @@ void fie(void) {
   {}
 }
 
+typedef enum omp_memspace_handle_t {
+  omp_default_mem_space = 0,
+  omp_large_cap_mem_space = 1,
+  omp_const_mem_space = 2,
+  omp_high_bw_mem_space = 3,
+  omp_low_lat_mem_space = 4,
+  llvm_omp_target_host_mem_space = 100,
+  llvm_omp_target_shared_mem_space = 101,
+  llvm_omp_target_device_mem_space = 102,
+  KMP_MEMSPACE_MAX_HANDLE = __UINTPTR_MAX__
+} omp_memspace_handle_t;
+
+extern omp_allocator_handle_t
+omp_init_allocator(omp_memspace_handle_t memspace, int ntraits,
+   const omp_alloctrait_t traits[]);
+
+void *omp_aligned_alloc(unsigned long alignment, unsigned long size,
+omp_allocator_handle_t allocator);
+extern void * omp_alloc(int size, omp_allocator_handle_t a);
+#define N 1024
+
+void foo() {
+  int errors = 0;
+  omp_memspace_handle_t  memspace = omp_default_mem_space;
+  omp_alloctrait_t   traits[1] = {{omp_atk_alignment, 64}};
+  omp_allocator_handle_t alloc = omp_init_allocator(memspace,1,traits);
+  #pragma omp target map(tofrom: errors) uses_allocators(alloc(traits))
+  { }
+}
 #endif
 
 // CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
@@ -140,3 +169,15 @@ void fie(void) {
 // CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
 // CHECK: [[CONV:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
 // CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV]])
+
+// CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
+// CHECK: [[MY_ALLOCATOR_ADDR:%alloc]] = alloca i64,
+// CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 1, ptr [[TRAITS_ADDR]])
+// CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
+// CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
+
+// Destroy allocator upon exit from the region.
+// CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
+// CHECK: [[CONV1:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
+// CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV1]])



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


[clang] a419ec4 - Fix runtime crash inside __kmpc_init_allocator

2023-05-26 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-05-26T16:03:01-07:00
New Revision: a419ec4f256d279c91746a3962dd6dd2da45c304

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

LOG: Fix runtime crash inside __kmpc_init_allocator

It seems load of traits.addr should be passed in runtime call.  Currently
the load of load traits.addr gets passed cause runtime to fail.

To fix this, skip the call to EmitLoadOfScalar for extra load.

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

Added: 
openmp/libomptarget/test/mapping/target_uses_allocator.c

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
clang/test/OpenMP/target_simd_uses_allocators_codegen.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_uses_allocators_codegen.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_uses_allocators_codegen.cpp
clang/test/OpenMP/target_teams_distribute_simd_uses_allocators_codegen.cpp
clang/test/OpenMP/target_teams_distribute_uses_allocators_codegen.cpp
clang/test/OpenMP/target_teams_uses_allocators_codegen.cpp
clang/test/OpenMP/target_uses_allocators.c
clang/test/OpenMP/target_uses_allocators_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index ff6d1d4ed869f..1f1db83378233 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6034,8 +6034,7 @@ void 
CGOpenMPRuntime::emitUsesAllocatorsInit(CodeGenFunction ,
   AllocatorTraitsLVal = CGF.MakeAddrLValue(Addr, CGF.getContext().VoidPtrTy,
AllocatorTraitsLVal.getBaseInfo(),
AllocatorTraitsLVal.getTBAAInfo());
-  llvm::Value *Traits =
-  CGF.EmitLoadOfScalar(AllocatorTraitsLVal, AllocatorTraits->getExprLoc());
+  llvm::Value *Traits = Addr.getPointer();
 
   llvm::Value *AllocatorVal =
   CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(

diff  --git 
a/clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp 
b/clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
index 2bcd9e7221f4d..c471c3c78cf30 100644
--- a/clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
+++ b/clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
@@ -79,8 +79,7 @@ void foo() {
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 

diff  --git a/clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp 
b/clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
index 03a5f9f3b7287..3a11323ee2d6d 100644
--- a/clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
+++ b/clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
@@ -79,8 +79,7 @@ void foo() {
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS]])
+// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS_ADDR]])
 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
 

diff  --git a/clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp 
b/clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
index faa44d2da50bd..51c5f9219c6c4 100644
--- a/clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
+++ b/clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
@@ -78,8 +78,7 @@ void foo() {
 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
-// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
-// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr 
null, i32 10, ptr [[TRAITS]])
+// 

[clang] acb1b4f - Fix wrong error message when compiling C souce code:

2023-05-26 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-05-26T10:14:52-07:00
New Revision: acb1b4fbb7939faa369337b9b26b960fdc91e4b8

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

LOG: Fix wrong error message when compiling C souce code:
Currently emit error for uses_allocators(alloc(traits)):

called object type 'omp_allocator_handle_t' (aka
'enum omp_allocator_handle_t') is not a function or function pointer

To fix this, since "alloc" is Id expresison(spce 5.2), during the parser
(in ParseOpenMP.cpp), using tryParseCXXIdExpression instead of
ParseExpression for C.

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

Added: 


Modified: 
clang/lib/Parse/ParseOpenMP.cpp
clang/test/OpenMP/target_uses_allocators.c

Removed: 




diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index a7db7a1c2582..8c57dc9e071f 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -3103,8 +3103,13 @@ OMPClause 
*Parser::ParseOpenMPUsesAllocatorClause(OpenMPDirectiveKind DKind) {
 return nullptr;
   SmallVector Data;
   do {
+CXXScopeSpec SS;
+Token Replacement;
 ExprResult Allocator =
-getLangOpts().CPlusPlus ? ParseCXXIdExpression() : ParseExpression();
+getLangOpts().CPlusPlus
+? ParseCXXIdExpression()
+: tryParseCXXIdExpression(SS, /*isAddressOfOperand=*/false,
+  Replacement);
 if (Allocator.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
 StopBeforeMatch);

diff  --git a/clang/test/OpenMP/target_uses_allocators.c 
b/clang/test/OpenMP/target_uses_allocators.c
index f096c4a3f275..566fa51686db 100644
--- a/clang/test/OpenMP/target_uses_allocators.c
+++ b/clang/test/OpenMP/target_uses_allocators.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50  -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -verify 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-include-pch %t %s -emit-llvm -o - | FileCheck %s
 
 #ifndef HEADER
 #define HEADER
@@ -19,9 +21,27 @@ typedef enum omp_allocator_handle_t {
   KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
 } omp_allocator_handle_t;
 
+typedef enum omp_alloctrait_key_t { omp_atk_sync_hint = 1,
+omp_atk_alignment = 2,
+omp_atk_access = 3,
+omp_atk_pool_size = 4,
+omp_atk_fallback = 5,
+omp_atk_fb_data = 6,
+omp_atk_pinned = 7,
+omp_atk_partition = 8
+} omp_alloctrait_key_t;
+
+typedef struct omp_alloctrait_t {
+  omp_alloctrait_key_t key;
+  __UINTPTR_TYPE__ value;
+} omp_alloctrait_t;
+
+
 // CHECK: define {{.*}}[[FIE:@.+]]()
 void fie(void) {
   int x;
+  omp_allocator_handle_t my_allocator;
+  omp_alloctrait_t traits[10];
   #pragma omp target uses_allocators(omp_null_allocator) 
allocate(omp_null_allocator: x) firstprivate(x)
   {}
   #pragma omp target uses_allocators(omp_default_mem_alloc) 
allocate(omp_default_mem_alloc: x) firstprivate(x)
@@ -40,6 +60,8 @@ void fie(void) {
   {}
   #pragma omp target uses_allocators(omp_thread_mem_alloc) 
allocate(omp_thread_mem_alloc: x) firstprivate(x) // expected-warning 
{{allocator with the 'thread' trait access has unspecified behavior on 'target' 
directive}}
   {}
+#pragma omp target uses_allocators(omp_null_allocator, omp_thread_mem_alloc, 
my_allocator(traits))
+  {}
 }
 
 #endif
@@ -106,3 +128,16 @@ void fie(void) {
 // CHECK-NEXT: %[[#R1:]] = load i32, ptr %x.addr, align 4
 // CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
 // CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr 
inttoptr (i64 8 to ptr))
+
+// CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
+// CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
+// CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
+// CHECK: [[TRAITS:%.+]] = load ptr, ptr [[TRAITS_ADDR]],
+// CHECK: [[ALLOCATOR:%.+]] = call ptr 

[clang] 691927c - Fix assertion when try is used inside catch(...) block

2023-05-17 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-05-17T14:42:39-07:00
New Revision: 691927c904ede183461610387402f5c19dbb3de0

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

LOG: Fix assertion when try is used inside catch(...) block

Current assert wiht /EHa:
A single unwind edge may only enter one EH pad
  invoke void @llvm.seh.try.begin()
  to label %invoke.cont1 unwind label %catch.dispatch2

Current IR:
%1 = catchpad within %0 [ptr null, i32 0, ptr null]
   invoke void @llvm.seh.try.begin()
   to label %invoke.cont5 unwind label %catch.dispatch2

The problem is the invoke to llvm.seh.try.begin() missing "funclet"

Accodring: https://llvm.org/docs/LangRef.html#ob-funclet
If any "funclet" EH pads have been entered but not exited (per the
description in the EH doc), it is undefined behavior to execute a
call or invoke.

To fix the problem, when emit seh_try_begin,  call EmitSehTryScopeBegin,
instead of calling EmitRuntimeCallOrInvoke for proper "funclet"
gerenration.

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

Added: 


Modified: 
clang/lib/CodeGen/CGException.cpp
clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 3707c87924916..8b0776b9a52b0 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -646,7 +646,7 @@ void CodeGenFunction::EnterCXXTryStmt(const CXXTryStmt , 
bool IsFnTryBlock) {
   // Under async exceptions, catch(...) need to catch HW exception too
   // Mark scope with SehTryBegin as a SEH __try scope
   if (getLangOpts().EHAsynch)
-EmitRuntimeCallOrInvoke(getSehTryBeginFn(CGM));
+EmitSehTryScopeBegin();
 }
   }
 }

diff  --git a/clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp 
b/clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
index 047894c395bb4..c9e6c9925edd4 100644
--- a/clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
+++ b/clang/test/CodeGen/windows-seh-EHa-CppCatchDotDotDot.cpp
@@ -9,11 +9,21 @@
 // CHECK: %[[dst1:[0-9-]+]] = catchpad within %[[dst]] [ptr null, i32 0, ptr 
null]
 // CHECK: "funclet"(token %[[dst1]])
 
+// CHECK: define dso_local void @"?bar@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @_CxxThrowException
+// CHECK: %[[dst:[0-9-]+]] = catchpad within %0 [ptr null, i32 0, ptr null]
+// CHECK: invoke void @llvm.seh.try.begin() [ "funclet"(token %[[dst]]) ]
+
 // CHECK: invoke void @llvm.seh.try.begin()
 // CHECK: %[[src:[0-9-]+]] = load volatile i32, ptr %i
 // CHECK-NEXT: invoke void @"?crash@@YAXH@Z"(i32 noundef %[[src]])
 // CHECK: invoke void @llvm.seh.try.end()
 
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke void @"?bar@@YAXXZ"()
+// CHECK: invoke void @llvm.seh.try.end()
+
 // 
*
 // Abstract: Test CPP catch(...) under SEH -EHa option
 
@@ -46,6 +56,18 @@ void crash(int i) {
   }
 }
 
+void bar() {
+  try {
+throw 1;
+  } catch(...) {
+try {
+  *NullPtr = 0;
+} catch (...) {
+   throw 1;
+}
+  }
+}
+
 int main() {
   for (int i = 0; i < 2; i++) {
 __try {
@@ -54,5 +76,10 @@ int main() {
   printf(" Test CPP unwind: in except handler i = %d \n", i);
 }
   }
+  __try {
+   bar();
+  } __except (1) {
+printf("Test CPP unwind: in except handler \n");
+  }
   return 0;
 }



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


[clang] 3d9880e - [OpenMP]Skip generating this[:1] map info for non-member variable.

2023-03-14 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-03-14T09:09:20-07:00
New Revision: 3d9880ebbcb7d458753ac73a65b401af94c7b762

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

LOG: [OpenMP]Skip generating this[:1] map info for non-member variable.

My change of D14093 is only fixed problem for "pragma target data".

The problem still here for "pragma target"
what I am missing is:
When processing "pragma target data", the VD is passed when call to
emitCombinedEntry, so check VD is null as map for this pointer.

But when processing "pragma target" the VD is passed as nullptr, so
check VD is null is not working.

To fix this I add a new parameter IsMapThis. During the call to
emitCombinedEntry passes true if it is capturing this pointer and use
that instead check of "!VD".

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_map_member_expr_codegen.cpp
openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 60e03320a391c..8ebdad4c63ee3 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -8378,7 +8378,8 @@ class MappableExprsHandler {
   // individual members mapped. Emit an extra combined entry.
   if (PartialStruct.Base.isValid()) {
 CurInfo.NonContigInfo.Dims.push_back(0);
-emitCombinedEntry(CombinedInfo, CurInfo.Types, PartialStruct, VD);
+emitCombinedEntry(CombinedInfo, CurInfo.Types, PartialStruct,
+  /*IsMapThis*/ !VD, VD);
   }
 
   // We need to append the results of this capture to what we already
@@ -8444,7 +8445,7 @@ class MappableExprsHandler {
   /// individual struct members.
   void emitCombinedEntry(MapCombinedInfoTy ,
  MapFlagsArrayTy ,
- const StructRangeInfoTy ,
+ const StructRangeInfoTy , bool 
IsMapThis,
  const ValueDecl *VD = nullptr,
  bool NotTargetParams = true) const {
 if (CurTypes.size() == 1 &&
@@ -8466,8 +8467,7 @@ class MappableExprsHandler {
 const CXXMethodDecl *MD =
 CGF.CurFuncDecl ? dyn_cast(CGF.CurFuncDecl) : nullptr;
 const CXXRecordDecl *RD = MD ? MD->getParent() : nullptr;
-// When VD is not null, it is not field of class, skip generating this[:1].
-bool HasBaseClass = RD && !VD ? RD->getNumBases() > 0 : false;
+bool HasBaseClass = RD && IsMapThis ? RD->getNumBases() > 0 : false;
 // There should not be a mapper for a combined entry.
 if (HasBaseClass) {
   // OpenMP 5.2 148:21:
@@ -10052,8 +10052,8 @@ void CGOpenMPRuntime::emitTargetCall(
   if (PartialStruct.Base.isValid()) {
 CombinedInfo.append(PartialStruct.PreliminaryMapData);
 MEHandler.emitCombinedEntry(
-CombinedInfo, CurInfo.Types, PartialStruct, nullptr,
-!PartialStruct.PreliminaryMapData.BasePointers.empty());
+CombinedInfo, CurInfo.Types, PartialStruct, CI->capturesThis(),
+nullptr, !PartialStruct.PreliminaryMapData.BasePointers.empty());
   }
 
   // We need to append the results of this capture to what we already have.

diff  --git a/clang/test/OpenMP/target_map_member_expr_codegen.cpp 
b/clang/test/OpenMP/target_map_member_expr_codegen.cpp
index fa47fcee41a4c..26676ad7c3832 100644
--- a/clang/test/OpenMP/target_map_member_expr_codegen.cpp
+++ b/clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -56,6 +56,9 @@ class C : public BASE
for (int i = 0; i < Csize; ++i)
   d.C[i] = 1;
  }
+ #pragma omp target map(from:d.C[0:Csize])
+   for (int i = 0; i < Csize; ++i)
+  d.C[i] = 1;
}
 };
 
@@ -66,9 +69,11 @@ void foo() {
   descriptor d;
   c.bar(d);
 }
+
 // CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, 
i64 4, i64 4, i64 4]
 // CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 
0, i64 4, i64 4, i64 4]
-
+// CHECK: @.offload_sizes.4 = private unnamed_addr constant [3 x i64] [i64 4, 
i64 0, i64 0]
+// CHECK-NOT: @.offload_sizes.4 = private unnamed_addr constant [3 x i64] [i64 
4, i64 1, i64 0]
 // CHECK-LABEL: define {{[^@]+}}@_Z3foov
 // CHECK-SAME: () #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:
@@ -189,6 +194,12 @@ void foo() {
 // CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS9:%.*]] = alloca [2 x ptr], align 8
 // CHECK-NEXT:[[DOTOFFLOAD_PTRS10:%.*]] = alloca [2 x ptr], align 8
 // CHECK-NEXT:[[DOTOFFLOAD_MAPPERS11:%.*]] = alloca [2 x ptr], align 8
+// CHECK-NEXT:[[_TMP12:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[CSIZE_CASTED13:%.*]] 

[clang] 8da99b4 - Revert "Revert "Add map info for dereference pointer.""

2023-03-09 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-03-09T10:59:59-08:00
New Revision: 8da99b44b6a5a2c9033e38828858cbadad425204

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

LOG: Revert "Revert "Add map info for dereference pointer.""

This reverts commit 8cf85a0cadb033fed3d96aa5283deb4bfbbaf2c8.

This is add back change of "Add map info for dereference pointer."

In addition turn off test run on amdgpu, since I don't know the way to
reprodue the problem.

Added: 
clang/test/OpenMP/target_map_deref_array_codegen.cpp
openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/target_update_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index ff2e9423b6b2e..60e03320a391c 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7163,6 +7163,7 @@ class MappableExprsHandler {
 // double d;
 // int i[100];
 // float *p;
+// int **a = 
 //
 // struct S1 {
 //   int i;
@@ -7196,6 +7197,14 @@ class MappableExprsHandler {
 // in unified shared memory mode or for local pointers
 // p, [1], 24*sizeof(float), TARGET_PARAM | TO | FROM
 //
+// map((*a)[0:3])
+// &(*a), &(*a), sizeof(pointer), TARGET_PARAM | TO | FROM
+// &(*a), &(*a)[0], 3*sizeof(int), PTR_AND_OBJ | TO | FROM
+//
+// map(**a)
+// &(*a), &(*a), sizeof(pointer), TARGET_PARAM | TO | FROM
+// &(*a), &(**a), sizeof(int), PTR_AND_OBJ | TO | FROM
+//
 // map(s)
 // , , sizeof(S2), TARGET_PARAM | TO | FROM
 //
@@ -7488,7 +7497,9 @@ class MappableExprsHandler {
   bool IsMemberReference = isa(I->getAssociatedExpression()) &&
MapDecl &&
MapDecl->getType()->isLValueReferenceType();
-  bool IsNonDerefPointer = IsPointer && !UO && !BO && !IsNonContiguous;
+  bool IsNonDerefPointer = IsPointer &&
+   !(UO && UO->getOpcode() != UO_Deref) && !BO &&
+   !IsNonContiguous;
 
   if (OASE)
 ++DimSize;

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index b87732ac195a2..e193fa3d19d5c 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2203,11 +2203,14 @@ bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, 
unsigned Level,
   ++EI;
   if (EI == EE)
 return false;
-
-  if (isa(EI->getAssociatedExpression()) ||
-  isa(EI->getAssociatedExpression()) ||
+  auto Last = std::prev(EE);
+  const auto *UO =
+  dyn_cast(Last->getAssociatedExpression());
+  if ((UO && UO->getOpcode() == UO_Deref) ||
+  isa(Last->getAssociatedExpression()) ||
+  isa(Last->getAssociatedExpression()) ||
   isa(EI->getAssociatedExpression()) ||
-  isa(EI->getAssociatedExpression())) {
+  isa(Last->getAssociatedExpression())) {
 IsVariableAssociatedWithSection = true;
 // There is nothing more we need to know about this variable.
 return true;

diff  --git a/clang/test/OpenMP/target_map_deref_array_codegen.cpp 
b/clang/test/OpenMP/target_map_deref_array_codegen.cpp
new file mode 100644
index 0..40b3b5f1a6f2c
--- /dev/null
+++ b/clang/test/OpenMP/target_map_deref_array_codegen.cpp
@@ -0,0 +1,315 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ 
-std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ 
-triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s 
-emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern void *malloc (int __size) throw () __attribute__ ((__malloc__));
+
+void foo(int **t1d)
+{
+  *t1d = (int *) malloc(3 * sizeof(int));
+  for (int j=0; j < 3; j++)
+(*t1d)[j] = 1;
+  #pragma omp target map(to: (*t1d)[0:3])
+(*t1d)[2] = 2;
+  #pragma omp target map(tofrom : (**t1d))
+(*t1d)[0] = 3;
+  int a = 0, b = 0;
+  #pragma omp target map(tofrom : (*(*(t1d+a)+b)))
+   

[clang] 0f2f378 - Add map info for dereference pointer.

2023-03-08 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-03-08T17:43:43-08:00
New Revision: 0f2f378425821de77e50a0dcb67c4504389a56e8

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

LOG: Add map info for dereference pointer.

This is to fix run time problem when use:

int **a;
map((*a)[:3]), (*a)[1] or map(**a).

current we skip generate map info for dereference pointer:
&(*a), &(*a)[0], 3*sizeof(int), TARGET_PARAM | TO | FROM

One way to fix runtime problem is to generate map info for dereference
pointer.

map((*a)[:3]):
&(*a), &(*a), sizeof(pointer),  TARGET_PARAM | TO | FROM
&(*a), &(*a)[0], 3*sizeof(int),  PTR_AND_OBJ | TO | FROM

map(**a):
&(*a), &(*a), sizeof(pointer),  TARGET_PARAM | TO | FROM
&(*a), &(**a), sizeof(int),  PTR_AND_OBJ | TO | FROM

The change in CGOpenMPRuntime.cpp add that.

The change in SemaOpenMP is to fix variable of dereference pointer to array
captured by reference.  That is wrong. That cause run time to fail.

The rule is:
If variable is identified in a map clause it is always captured by
reference except if it is a pointer that is dereferenced somehow.

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

Added: 
clang/test/OpenMP/target_map_deref_array_codegen.cpp
openmp/libomptarget/test/mapping/target_derefence_array_pointrs.cpp

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/target_update_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index ff2e9423b6b2..60e03320a391 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7163,6 +7163,7 @@ class MappableExprsHandler {
 // double d;
 // int i[100];
 // float *p;
+// int **a = 
 //
 // struct S1 {
 //   int i;
@@ -7196,6 +7197,14 @@ class MappableExprsHandler {
 // in unified shared memory mode or for local pointers
 // p, [1], 24*sizeof(float), TARGET_PARAM | TO | FROM
 //
+// map((*a)[0:3])
+// &(*a), &(*a), sizeof(pointer), TARGET_PARAM | TO | FROM
+// &(*a), &(*a)[0], 3*sizeof(int), PTR_AND_OBJ | TO | FROM
+//
+// map(**a)
+// &(*a), &(*a), sizeof(pointer), TARGET_PARAM | TO | FROM
+// &(*a), &(**a), sizeof(int), PTR_AND_OBJ | TO | FROM
+//
 // map(s)
 // , , sizeof(S2), TARGET_PARAM | TO | FROM
 //
@@ -7488,7 +7497,9 @@ class MappableExprsHandler {
   bool IsMemberReference = isa(I->getAssociatedExpression()) &&
MapDecl &&
MapDecl->getType()->isLValueReferenceType();
-  bool IsNonDerefPointer = IsPointer && !UO && !BO && !IsNonContiguous;
+  bool IsNonDerefPointer = IsPointer &&
+   !(UO && UO->getOpcode() != UO_Deref) && !BO &&
+   !IsNonContiguous;
 
   if (OASE)
 ++DimSize;

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index b87732ac195a..e193fa3d19d5 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2203,11 +2203,14 @@ bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, 
unsigned Level,
   ++EI;
   if (EI == EE)
 return false;
-
-  if (isa(EI->getAssociatedExpression()) ||
-  isa(EI->getAssociatedExpression()) ||
+  auto Last = std::prev(EE);
+  const auto *UO =
+  dyn_cast(Last->getAssociatedExpression());
+  if ((UO && UO->getOpcode() == UO_Deref) ||
+  isa(Last->getAssociatedExpression()) ||
+  isa(Last->getAssociatedExpression()) ||
   isa(EI->getAssociatedExpression()) ||
-  isa(EI->getAssociatedExpression())) {
+  isa(Last->getAssociatedExpression())) {
 IsVariableAssociatedWithSection = true;
 // There is nothing more we need to know about this variable.
 return true;

diff  --git a/clang/test/OpenMP/target_map_deref_array_codegen.cpp 
b/clang/test/OpenMP/target_map_deref_array_codegen.cpp
new file mode 100644
index ..40b3b5f1a6f2
--- /dev/null
+++ b/clang/test/OpenMP/target_map_deref_array_codegen.cpp
@@ -0,0 +1,315 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ 
-std=c++11 -triple 

[clang] 1b72a32 - Skip using this[:1] map info for non-member variable.

2023-02-23 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-02-23T09:27:56-08:00
New Revision: 1b72a32762436aad1b7064a8d44681300fd8e380

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

LOG: Skip using this[:1] map info for non-member variable.

This fix runtime problem due to generate this[:1] map info for non member
variable.
To fix this check VD, if VD is not null, it is not member from current
or base classes.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_map_member_expr_codegen.cpp
openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 2d762c6eb17c7..ff2e9423b6b2e 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -8455,7 +8455,8 @@ class MappableExprsHandler {
 const CXXMethodDecl *MD =
 CGF.CurFuncDecl ? dyn_cast(CGF.CurFuncDecl) : nullptr;
 const CXXRecordDecl *RD = MD ? MD->getParent() : nullptr;
-bool HasBaseClass = RD ? RD->getNumBases() > 0 : false;
+// When VD is not null, it is not field of class, skip generating this[:1].
+bool HasBaseClass = RD && !VD ? RD->getNumBases() > 0 : false;
 // There should not be a mapper for a combined entry.
 if (HasBaseClass) {
   // OpenMP 5.2 148:21:

diff  --git a/clang/test/OpenMP/target_map_member_expr_codegen.cpp 
b/clang/test/OpenMP/target_map_member_expr_codegen.cpp
index c4dace141fc4d..fa47fcee41a4c 100644
--- a/clang/test/OpenMP/target_map_member_expr_codegen.cpp
+++ b/clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -1,20 +1,11 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
 // RUN:  -x c++ -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - \
 // RUN:   | FileCheck %s
 
 // expected-no-diagnostics
 
-// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, 
i64 4, i64 4, i64 4]
-// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 
0, i64 4, i64 4, i64 4]
 
-// CHECK-LABEL: define {{[^@]+}}@_Z3foov(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
-// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 
dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
-// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 
dereferenceable(12) [[B]])
-// CHECK-NEXT:ret void
-//
 class A {
 protected:
   int X;
@@ -29,28 +20,91 @@ class B : public A {
   using A::Y;
 public:
   int res;
-// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii(
+  B (int x, int y) : A(x,y), res{0} {}
+  void run (void) {
+  #pragma omp target
+ res = X + Y;
+  }
+};
+
+template
+struct descriptor
+{
+  T *A;
+  T *C;
+  T *C_ref;
+  unsigned M;
+  unsigned K;
+  unsigned N;
+};
+
+class BASE
+{
+};
+
+//template
+class C : public BASE
+{
+public:
+  void bar (descriptor )
+  {
+ auto Asize = d.M * d.K;
+ auto Csize = d.M * d.N;
+ #pragma omp target data map(to:d.A[0:Asize]) map(from:d.C[0:Csize])
+ {
+   #pragma omp target teams firstprivate(Csize)
+   for (int i = 0; i < Csize; ++i)
+  d.C[i] = 1;
+ }
+   }
+};
+
+void foo() {
+  B b(2, 3);
+  b.run();
+  C c;
+  descriptor d;
+  c.bar(d);
+}
+// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, 
i64 4, i64 4, i64 4]
+// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 
0, i64 4, i64 4, i64 4]
+
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
+// CHECK-NEXT:[[C:%.*]] = alloca [[CLASS_C:%.*]], align 1
+// CHECK-NEXT:[[D:%.*]] = alloca [[STRUCT_DESCRIPTOR:%.*]], align 8
+// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 
dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
+// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 
dereferenceable(12) [[B]])
+// CHECK-NEXT:call void @_ZN1C3barER10descriptorIfE(ptr noundef nonnull 
align 1 dereferenceable(1) [[C]], ptr noundef nonnull align 8 
dereferenceable(40) [[D]])
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(12) [[THIS:%.*]], 
i32 

[clang] fe29a16 - This is to fix runtime problem for member data used in target region.

2023-01-10 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-01-10T16:59:49-08:00
New Revision: fe29a1695a6c69eb6616db01a559a3804d55fde8

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

LOG: This is to fix runtime problem for member data used in target region.

The problem is happened when base class member field is used in target
region , the size is wrong, cause runtime to fail. Currently the size of
calculation is depended on index of field, since field is in base class,
the calculation is wrong.

According OpenMP 5.2 148:21:
If the target construct is within a class non-static member function,
and a variable is an accessible data member of the object for which the
non-static data member function is invoked, the variable is treated as
if the this[:1] expression had appeared in a map clause with a map-type
of tofrom.

One way to fix this is emitting code to generate this[:1] instead only
when class has any base class.

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

Added: 
clang/test/OpenMP/target_map_member_expr_codegen.cpp
openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index c0893d70340d9..c2328d28ec50a 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -8444,19 +8444,39 @@ class MappableExprsHandler {
 CombinedInfo.BasePointers.push_back(PartialStruct.Base.getPointer());
 // Pointer is the address of the lowest element
 llvm::Value *LB = LBAddr.getPointer();
-CombinedInfo.Pointers.push_back(LB);
+const CXXMethodDecl *MD =
+CGF.CurFuncDecl ? dyn_cast(CGF.CurFuncDecl) : nullptr;
+const CXXRecordDecl *RD = MD ? MD->getParent() : nullptr;
+bool HasBaseClass = RD ? RD->getNumBases() > 0 : false;
 // There should not be a mapper for a combined entry.
+if (HasBaseClass) {
+  // OpenMP 5.2 148:21:
+  // If the target construct is within a class non-static member function,
+  // and a variable is an accessible data member of the object for which 
the
+  // non-static data member function is invoked, the variable is treated as
+  // if the this[:1] expression had appeared in a map clause with a 
map-type
+  // of tofrom.
+  // Emit this[:1]
+  CombinedInfo.Pointers.push_back(PartialStruct.Base.getPointer());
+  QualType Ty = MD->getThisType()->getPointeeType();
+  llvm::Value *Size =
+  CGF.Builder.CreateIntCast(CGF.getTypeSize(Ty), CGF.Int64Ty,
+/*isSigned=*/true);
+  CombinedInfo.Sizes.push_back(Size);
+} else {
+  CombinedInfo.Pointers.push_back(LB);
+  // Size is (addr of {highest+1} element) - (addr of lowest element)
+  llvm::Value *HB = HBAddr.getPointer();
+  llvm::Value *HAddr = CGF.Builder.CreateConstGEP1_32(
+  HBAddr.getElementType(), HB, /*Idx0=*/1);
+  llvm::Value *CLAddr = CGF.Builder.CreatePointerCast(LB, CGF.VoidPtrTy);
+  llvm::Value *CHAddr = CGF.Builder.CreatePointerCast(HAddr, 
CGF.VoidPtrTy);
+  llvm::Value *Diff = CGF.Builder.CreatePtrDiff(CGF.Int8Ty, CHAddr, 
CLAddr);
+  llvm::Value *Size = CGF.Builder.CreateIntCast(Diff, CGF.Int64Ty,
+/*isSigned=*/false);
+  CombinedInfo.Sizes.push_back(Size);
+}
 CombinedInfo.Mappers.push_back(nullptr);
-// Size is (addr of {highest+1} element) - (addr of lowest element)
-llvm::Value *HB = HBAddr.getPointer();
-llvm::Value *HAddr =
-CGF.Builder.CreateConstGEP1_32(HBAddr.getElementType(), HB, 
/*Idx0=*/1);
-llvm::Value *CLAddr = CGF.Builder.CreatePointerCast(LB, CGF.VoidPtrTy);
-llvm::Value *CHAddr = CGF.Builder.CreatePointerCast(HAddr, CGF.VoidPtrTy);
-llvm::Value *Diff = CGF.Builder.CreatePtrDiff(CGF.Int8Ty, CHAddr, CLAddr);
-llvm::Value *Size = CGF.Builder.CreateIntCast(Diff, CGF.Int64Ty,
-  /*isSigned=*/false);
-CombinedInfo.Sizes.push_back(Size);
 // Map type is always TARGET_PARAM, if generate info for captures.
 CombinedInfo.Types.push_back(
 NotTargetParams ? OpenMPOffloadMappingFlags::OMP_MAP_NONE

diff  --git a/clang/test/OpenMP/target_map_member_expr_codegen.cpp 
b/clang/test/OpenMP/target_map_member_expr_codegen.cpp
new file mode 100644
index 0..2d9777197a791
--- /dev/null
+++ b/clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -0,0 +1,122 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
+// RUN:  -x c++ -triple x86_64-unknown-linux-gnu 

[clang] af781f7 - [OPENMP51]Codegen for error directive.

2022-12-08 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-12-08T13:07:08-08:00
New Revision: af781f7042392910c4cf70106c6a0c2244c69478

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

LOG: [OPENMP51]Codegen for error directive.

Added codegen for `omp error` directive.
This is to generate IR to call:
void __kmpc_error(ident_t *loc, int severity, const char *message);

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

Added: 
clang/test/OpenMP/error_codegen.cpp

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 10c88964da0ed..396075183102d 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1363,10 +1363,11 @@ static StringRef 
getIdentStringFromSourceLocation(CodeGenFunction ,
 
 llvm::Value *CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction ,
  SourceLocation Loc,
- unsigned Flags) {
+ unsigned Flags, bool EmitLoc) 
{
   uint32_t SrcLocStrSize;
   llvm::Constant *SrcLocStr;
-  if (CGM.getCodeGenOpts().getDebugInfo() == codegenoptions::NoDebugInfo ||
+  if ((!EmitLoc &&
+   CGM.getCodeGenOpts().getDebugInfo() == codegenoptions::NoDebugInfo) ||
   Loc.isInvalid()) {
 SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize);
   } else {
@@ -2557,6 +2558,22 @@ void CGOpenMPRuntime::emitBarrierCall(CodeGenFunction 
, SourceLocation Loc,
   Args);
 }
 
+void CGOpenMPRuntime::emitErrorCall(CodeGenFunction , SourceLocation Loc,
+Expr *ME, bool IsFatal) {
+  llvm::Value *MVL =
+  ME ? CGF.EmitStringLiteralLValue(cast(ME)).getPointer(CGF)
+ : llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
+  // Build call void __kmpc_error(ident_t *loc, int severity, const char
+  // *message)
+  llvm::Value *Args[] = {
+  emitUpdateLocation(CGF, Loc, /*Flags=*/0, /*GenLoc=*/true),
+  llvm::ConstantInt::get(CGM.Int32Ty, IsFatal ? 2 : 1),
+  CGF.Builder.CreatePointerCast(MVL, CGM.Int8PtrTy)};
+  CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
+  CGM.getModule(), OMPRTL___kmpc_error),
+  Args);
+}
+
 /// Map the OpenMP loop schedule to the runtime enumeration.
 static OpenMPSchedType getRuntimeSchedule(OpenMPScheduleClauseKind 
ScheduleKind,
   bool Chunked, bool Ordered) {

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.h 
b/clang/lib/CodeGen/CGOpenMPRuntime.h
index ee3211858fe18..e7c1a098c7689 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.h
@@ -329,9 +329,10 @@ class CGOpenMPRuntime {
 
   /// Emits object of ident_t type with info for source location.
   /// \param Flags Flags for OpenMP location.
+  /// \param EmitLoc emit source location with debug-info is off.
   ///
   llvm::Value *emitUpdateLocation(CodeGenFunction , SourceLocation Loc,
-  unsigned Flags = 0);
+  unsigned Flags = 0, bool EmitLoc = false);
 
   /// Emit the number of teams for a target directive.  Inspect the num_teams
   /// clause associated with a teams construct combined or closely nested
@@ -822,6 +823,11 @@ class CGOpenMPRuntime {
   /// Emits code for a taskyield directive.
   virtual void emitTaskyieldCall(CodeGenFunction , SourceLocation Loc);
 
+  /// Emit __kmpc_error call for error directive
+  /// extern void __kmpc_error(ident_t *loc, int severity, const char 
*message);
+  virtual void emitErrorCall(CodeGenFunction , SourceLocation Loc, Expr 
*ME,
+ bool IsFatal);
+
   /// Emit a taskgroup region.
   /// \param TaskgroupOpGen Generator for the statement associated with the
   /// given taskgroup region.

diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index b84fee77c66dd..cf9b704e0ae6f 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5246,7 +5246,13 @@ void CodeGenFunction::EmitOMPTaskyieldDirective(
 }
 
 void CodeGenFunction::EmitOMPErrorDirective(const OMPErrorDirective ) {
-  llvm_unreachable("CodeGen for 'omp error' is not supported yet.");
+  const OMPMessageClause *MC = S.getSingleClause();
+  Expr *ME = MC ? MC->getMessageString() : nullptr;
+  const OMPSeverityClause *SC = S.getSingleClause();
+  bool IsFatal = false;
+  if (!SC || SC->getSeverityKind() == OMPC_SEVERITY_fatal)
+IsFatal = 

[clang] 9d90cf2 - [OPENMP5.1] Initial support for message clause.

2022-11-18 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-11-18T17:59:23-08:00
New Revision: 9d90cf2fca4446f5c227f6e3217e96c00665cb72

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

LOG: [OPENMP5.1] Initial support for message clause.

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/error_ast_print.cpp
clang/test/OpenMP/error_message.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 21d9f740eddf1..2bf3e91a15a20 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -1722,6 +1722,72 @@ class OMPSeverityClause final : public OMPClause {
   }
 };
 
+/// This represents 'message' clause in the '#pragma omp error' directive
+///
+/// \code
+/// #pragma omp error message("GNU compiler required.")
+/// \endcode
+/// In this example directive '#pragma omp error' has simple
+/// 'message' clause with user error message of "GNU compiler required.".
+class OMPMessageClause final : public OMPClause {
+  friend class OMPClauseReader;
+
+  /// Location of '('
+  SourceLocation LParenLoc;
+
+  // Expression of the 'message' clause.
+  Stmt *MessageString = nullptr;
+
+  /// Set message string of the clause.
+  void setMessageString(Expr *MS) { MessageString = MS; }
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+public:
+  /// Build 'message' clause with message string argument
+  ///
+  /// \param A Argument of the clause (message string).
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc,
+   SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_message, StartLoc, EndLoc),
+LParenLoc(LParenLoc), MessageString(MS) {}
+
+  /// Build an empty clause.
+  OMPMessageClause()
+  : OMPClause(llvm::omp::OMPC_message, SourceLocation(), SourceLocation()) 
{
+  }
+
+  /// Returns the locaiton of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns message string of the clause.
+  Expr *getMessageString() const { return cast_or_null(MessageString); }
+
+  child_range children() {
+return child_range(,  + 1);
+  }
+
+  const_child_range children() const {
+return const_child_range(,  + 1);
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_message;
+  }
+};
+
 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
 ///
 /// \code

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 9baee8b72fa11..7475d29cd98d0 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3320,6 +3320,12 @@ bool 
RecursiveASTVisitor::VisitOMPSeverityClause(OMPSeverityClause *) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPMessageClause(OMPMessageClause *C) {
+  TRY_TO(TraverseStmt(C->getMessageString()));
+  return true;
+}
+
 template 
 bool
 RecursiveASTVisitor::VisitOMPScheduleClause(OMPScheduleClause *C) {

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6f46ede56f66c..ffbc859162270 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1342,6 +1342,8 @@ def err_omp_unexpected_directive : Error<
   "unexpected OpenMP directive %select{|'#pragma omp %1'}0">;
 def err_omp_expected_punc : Error<
   "expected ',' or ')' in '%0' %select{clause|directive}1">;
+def warn_clause_expected_string : Warning<
+  "expected string literal in 'clause %0' - ignoring">, 
InGroup;
 def err_omp_unexpected_clause : Error<
   "unexpected OpenMP clause '%0' in directive '#pragma omp %1'">;
 

[clang] 1e054e6 - [OPENMP5.1] Initial support for severity clause

2022-11-17 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-11-17T16:05:02-08:00
New Revision: 1e054e6b522b3f7e13c30caebfa63aafc7173220

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

LOG: [OPENMP5.1] Initial support for severity clause

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

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Basic/OpenMPKinds.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/error_ast_print.cpp
clang/test/OpenMP/error_message.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index ac0a6aa240aff..e7dc5e72b3a82 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -1642,6 +1642,86 @@ class OMPAtClause final : public OMPClause {
   }
 };
 
+/// This represents 'severity' clause in the '#pragma omp error' directive
+///
+/// \code
+/// #pragma omp error severity(fatal)
+/// \endcode
+/// In this example directive '#pragma omp error' has simple
+/// 'severity' clause with kind 'fatal'.
+class OMPSeverityClause final : public OMPClause {
+  friend class OMPClauseReader;
+
+  /// Location of '('
+  SourceLocation LParenLoc;
+
+  /// A kind of the 'severity' clause.
+  OpenMPSeverityClauseKind Kind = OMPC_SEVERITY_unknown;
+
+  /// Start location of the kind in source code.
+  SourceLocation KindKwLoc;
+
+  /// Set kind of the clause.
+  ///
+  /// \param K Kind of clause.
+  void setSeverityKind(OpenMPSeverityClauseKind K) { Kind = K; }
+
+  /// Set clause kind location.
+  ///
+  /// \param KLoc Kind location.
+  void setSeverityKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+public:
+  /// Build 'severity' clause with argument \a A ('fatal' or 'warning').
+  ///
+  /// \param A Argument of the clause ('fatal' or 'warning').
+  /// \param ALoc Starting location of the argument.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPSeverityClause(OpenMPSeverityClauseKind A, SourceLocation ALoc,
+SourceLocation StartLoc, SourceLocation LParenLoc,
+SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_severity, StartLoc, EndLoc),
+LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
+
+  /// Build an empty clause.
+  OMPSeverityClause()
+  : OMPClause(llvm::omp::OMPC_severity, SourceLocation(),
+  SourceLocation()) {}
+
+  /// Returns the locaiton of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns kind of the clause.
+  OpenMPSeverityClauseKind getSeverityKind() const { return Kind; }
+
+  /// Returns location of clause kind.
+  SourceLocation getSeverityKindKwLoc() const { return KindKwLoc; }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_severity;
+  }
+};
+
 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
 ///
 /// \code

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index b7c7e77d1d97e..9baee8b72fa11 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3315,6 +3315,11 @@ bool 
RecursiveASTVisitor::VisitOMPAtClause(OMPAtClause *) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPSeverityClause(OMPSeverityClause *) 
{
+  return true;
+}
+
 template 
 bool
 RecursiveASTVisitor::VisitOMPScheduleClause(OMPScheduleClause *C) {

diff  --git a/clang/include/clang/Basic/OpenMPKinds.def 

[clang] de14bef - Remove redundant loads.

2022-11-04 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-11-04T15:22:25-07:00
New Revision: de14befa7730093ff3d46c7628fa1084f251e98d

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

LOG: Remove redundant loads.

It is caused by regenerate captured var value when processing the
has_device_addr, the captured var value has been generated in
GenerateOpenMPCapturedVars and passed as Arg in generateInfoForCapture.
The fix just use Arg instead regenerated just same as is_device_ptr

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_has_device_addr_codegen.cpp
clang/test/OpenMP/target_has_device_addr_codegen_01.cpp
openmp/libomptarget/test/mapping/has_device_addr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e52989b7c139b..b87e69b641a63 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -8739,7 +8739,7 @@ class MappableExprsHandler {
 // 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 (VD && DevPointersMap.count(VD)) {
+if (VD && (DevPointersMap.count(VD) || HasDevAddrsMap.count(VD))) {
   CombinedInfo.Exprs.push_back(VD);
   CombinedInfo.BasePointers.emplace_back(Arg, VD);
   CombinedInfo.Pointers.push_back(Arg);
@@ -8752,30 +8752,6 @@ class MappableExprsHandler {
   CombinedInfo.Mappers.push_back(nullptr);
   return;
 }
-if (VD && HasDevAddrsMap.count(VD)) {
-  auto I = HasDevAddrsMap.find(VD);
-  CombinedInfo.Exprs.push_back(VD);
-  Expr *E = nullptr;
-  for (auto  : I->second) {
-E = MCL.begin()->getAssociatedExpression();
-break;
-  }
-  llvm::Value *Ptr = nullptr;
-  if (E->isGLValue())
-Ptr = CGF.EmitLValue(E).getPointer(CGF);
-  else
-Ptr = CGF.EmitScalarExpr(E);
-  CombinedInfo.BasePointers.emplace_back(Ptr, VD);
-  CombinedInfo.Pointers.push_back(Ptr);
-  CombinedInfo.Sizes.push_back(CGF.Builder.CreateIntCast(
-  CGF.getTypeSize(CGF.getContext().VoidPtrTy), CGF.Int64Ty,
-  /*isSigned=*/true));
-  CombinedInfo.Types.push_back(
-  (Cap->capturesVariable() ? OMP_MAP_TO : OMP_MAP_LITERAL) |
-  OMP_MAP_TARGET_PARAM);
-  CombinedInfo.Mappers.push_back(nullptr);
-  return;
-}
 
 using MapData =
 std::tuplehttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ea64e66 - [OPENMP]Initial support for error directive.

2022-11-02 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-11-02T14:25:28-07:00
New Revision: ea64e66f7b71dfd52e9701a080b8216052344962

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

LOG: [OPENMP]Initial support for error directive.

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

Added: 
clang/test/OpenMP/error_ast_print.cpp
clang/test/OpenMP/error_message.cpp

Modified: 
clang/include/clang-c/Index.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/StmtOpenMP.h
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/StmtOpenMP.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.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

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 2cd2d499ab53d..e0f6f1c73549f 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -1978,7 +1978,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPParallelMaskedTaskLoopSimdDirective = 304,
 
-  CXCursor_LastStmt = CXCursor_OMPParallelMaskedTaskLoopSimdDirective,
+  /** OpenMP error directive.
+   */
+  CXCursor_OMPErrorDirective = 305,
+
+  CXCursor_LastStmt = CXCursor_OMPErrorDirective,
 
   /**
* Cursor that represents the translation unit itself.

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 5eb8e0353ffd8..3d10d3bf98b29 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3153,6 +3153,10 @@ DEF_TRAVERSE_STMT(OMPParallelGenericLoopDirective,
 
 DEF_TRAVERSE_STMT(OMPTargetParallelGenericLoopDirective,
   { TRY_TO(TraverseOMPExecutableDirective(S)); })
+
+DEF_TRAVERSE_STMT(OMPErrorDirective,
+  { TRY_TO(TraverseOMPExecutableDirective(S)); })
+
 // OpenMP clauses.
 template 
 bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) {

diff  --git a/clang/include/clang/AST/StmtOpenMP.h 
b/clang/include/clang/AST/StmtOpenMP.h
index 702a82537ab2d..baa5e0ed7b63f 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -6220,6 +6220,51 @@ class OMPTargetParallelGenericLoopDirective final : 
public OMPLoopDirective {
 return T->getStmtClass() == OMPTargetParallelGenericLoopDirectiveClass;
   }
 };
+
+/// This represents '#pragma omp error' directive.
+///
+/// \code
+/// #pragma omp error
+/// \endcode
+class OMPErrorDirective final : public OMPExecutableDirective {
+  friend class ASTStmtReader;
+  friend class OMPExecutableDirective;
+  /// Build directive with the given start and end location.
+  ///
+  /// \param StartLoc Starting location of the directive kind.
+  /// \param EndLoc Ending location of the directive.
+  ///
+  OMPErrorDirective(SourceLocation StartLoc, SourceLocation EndLoc)
+  : OMPExecutableDirective(OMPErrorDirectiveClass, llvm::omp::OMPD_error,
+   StartLoc, EndLoc) {}
+  /// Build an empty directive.
+  ///
+  explicit OMPErrorDirective()
+  : OMPExecutableDirective(OMPErrorDirectiveClass, llvm::omp::OMPD_error,
+   SourceLocation(), SourceLocation()) {}
+
+public:
+  ///
+  /// \param C AST context.
+  /// \param StartLoc Starting location of the directive kind.
+  /// \param EndLoc Ending Location of the directive.
+  /// \param Clauses List of clauses.
+  ///
+  static OMPErrorDirective *Create(const ASTContext , SourceLocation 
StartLoc,
+   SourceLocation EndLoc,
+   ArrayRef Clauses);
+
+  /// Creates an empty directive.
+  ///
+  /// \param C AST context.
+  ///
+  static OMPErrorDirective *CreateEmpty(const ASTContext ,
+unsigned NumClauses, EmptyShell);
+
+  static bool classof(const Stmt *T) {
+return T->getStmtClass() == OMPErrorDirectiveClass;
+  }
+};
 } // end namespace clang
 
 #endif

diff  --git a/clang/include/clang/Basic/StmtNodes.td 
b/clang/include/clang/Basic/StmtNodes.td
index ebbd8db313428..c434b07c95a40 100644
--- a/clang/include/clang/Basic/StmtNodes.td
+++ 

[clang] 30cc712 - [Clang][OpenMP] Fix run time crash when use_device_addr is used.

2022-09-27 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-09-27T11:53:57-07:00
New Revision: 30cc712eb6f23a5c7beaae669bf2ab6beede7f20

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

LOG: [Clang][OpenMP] Fix run time crash when use_device_addr is used.

It is data mapping ordering problem.

According omp spec
If one or more map clauses are present, the list item conversions that
are performed for any use_device_ptr or use_device_addr clause occur
after all variables are mapped on entry to the region according to those
map clauses.

The change is to put mapping data for use_device_addr at end of data
mapping array.

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

Added: 
openmp/libomptarget/test/mapping/target_use_device_addr.c

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_data_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 6ff36c72e0319..5bf0e0815111e 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -8547,49 +8547,92 @@ class MappableExprsHandler {
   }
 }
 
-// Look at the use_device_ptr clause information and mark the existing map
-// entries as such. If there is no map information for an entry in the
-// use_device_ptr list, we create one with map type 'alloc' and zero size
-// section. It is the user fault if that was not mapped before. If there is
-// no map information and the pointer is a struct member, then we defer the
-// emission of that entry until the whole struct has been processed.
+// Look at the use_device_ptr and use_device_addr clauses information and
+// mark the existing map entries as such. If there is no map information 
for
+// an entry in the use_device_ptr and use_device_addr list, we create one
+// with map type 'alloc' and zero size section. It is the user fault if 
that
+// was not mapped before. If there is no map information and the pointer is
+// a struct member, then we defer the emission of that entry until the 
whole
+// struct has been processed.
 llvm::MapVector,
 SmallVector>
 DeferredInfo;
-MapCombinedInfoTy UseDevicePtrCombinedInfo;
+MapCombinedInfoTy UseDeviceDataCombinedInfo;
+
+auto & =
+[](const ValueDecl *VD, llvm::Value *Ptr,
+ CodeGenFunction ) {
+  UseDeviceDataCombinedInfo.Exprs.push_back(VD);
+  UseDeviceDataCombinedInfo.BasePointers.emplace_back(Ptr, VD);
+  UseDeviceDataCombinedInfo.Pointers.push_back(Ptr);
+  UseDeviceDataCombinedInfo.Sizes.push_back(
+  llvm::Constant::getNullValue(CGF.Int64Ty));
+  UseDeviceDataCombinedInfo.Types.push_back(OMP_MAP_RETURN_PARAM);
+  UseDeviceDataCombinedInfo.Mappers.push_back(nullptr);
+};
 
-for (const auto *Cl : Clauses) {
-  const auto *C = dyn_cast(Cl);
-  if (!C)
-continue;
-  for (const auto L : C->component_lists()) {
-OMPClauseMappableExprCommon::MappableExprComponentListRef Components =
-std::get<1>(L);
-assert(!Components.empty() &&
-   "Not expecting empty list of components!");
-const ValueDecl *VD = Components.back().getAssociatedDeclaration();
-VD = cast(VD->getCanonicalDecl());
-const Expr *IE = Components.back().getAssociatedExpression();
-// If the first component is a member expression, we have to look into
-// 'this', which maps to null in the map of map information. Otherwise
-// look directly for the information.
-auto It = Info.find(isa(IE) ? nullptr : VD);
-
-// We potentially have map information for this declaration already.
-// Look for the first set of components that refer to it.
-if (It != Info.end()) {
-  bool Found = false;
-  for (auto  : It->second) {
-auto *CI = llvm::find_if(Data, [VD](const MapInfo ) {
-  return MI.Components.back().getAssociatedDeclaration() == VD;
-});
-// If we found a map entry, signal that the pointer has to be
-// returned and move on to the next declaration. Exclude cases 
where
-// the base pointer is mapped as array subscript, array section or
-// array shaping. The base address is passed as a pointer to base 
in
-// this case and cannot be used as a base for use_device_ptr list
-// item.
-if (CI != Data.end()) {
+auto & =
+[, ,
+ ](CodeGenFunction , const Expr *IE, const ValueDecl *VD,
+   OMPClauseMappableExprCommon::MappableExprComponentListRef
+   

[clang] 2ca2720 - [OpenMP] Fix segmentation fault when data field is used in is_device_pt

2022-08-12 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-08-12T17:10:26-07:00
New Revision: 2ca27206f9739bffb50b999bdfb76fec1d7e62a8

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

LOG: [OpenMP] Fix segmentation fault when data field is used in is_device_pt

Currently, the field just emit map info for this pointer variable. It is
failed at run time. For the fields, the PartialStruct is created and it
needs call to emitCombinedEntry which create the base that covers all
the pieces.

The change is to generate map info as regular fields.

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

Added: 
openmp/libomptarget/test/mapping/is_device_ptr.cpp

Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_is_device_ptr_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 9fc7360e92472..a2d36e7df6f12 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9052,7 +9052,7 @@ class MappableExprsHandler {
 // 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 @@ class MappableExprsHandler {
OpenMPMapClauseKind, ArrayRef, bool,
const ValueDecl *, const Expr *>;
 SmallVector DeclComponentLists;
+// For member fields list in is_device_ptr, store it in
+// DeclComponentLists for generating components info.
+auto It = DevPointersMap.find(VD);
+if (It != DevPointersMap.end())
+  for (const auto MCL : It->second)
+DeclComponentLists.emplace_back(
+MCL, OMPC_MAP_to, OMPC_MAP_MODIFIER_unknown, /*IsImpicit = */ true,
+nullptr, nullptr);
 assert(CurDir.is() &&
"Expect a executable directive");
 const auto *CurExecDir = CurDir.get();

diff  --git a/clang/test/OpenMP/target_is_device_ptr_codegen.cpp 
b/clang/test/OpenMP/target_is_device_ptr_codegen.cpp
index ee09c1b606133..6a5375a528a99 100644
--- a/clang/test/OpenMP/target_is_device_ptr_codegen.cpp
+++ b/clang/test/OpenMP/target_is_device_ptr_codegen.cpp
@@ -252,12 +252,13 @@ struct ST {
 // 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 @@ struct ST {
 // 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]]
 

[clang] a7bca18 - Fix assert during the call to getCanonicalDecl.

2022-08-03 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-08-03T09:14:28-07:00
New Revision: a7bca18bc50cd2483fded0c77706980b2721ce6a

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

LOG: Fix assert during the call to getCanonicalDecl.
https://github.com/llvm/llvm-project/issues/56884

The root problem is in isOpenMPRebuildMemberExpr, it is only need to rebuild
for field expression.  No need for member function call.

The fix is to check field for member expression and skip rebuild for member
function call.

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

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/parallel_default_messages.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index dc1470bf7a9d..a92fec6a0232 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2270,6 +2270,9 @@ bool Sema::isInOpenMPTargetExecutionDirective() const {
 }
 
 bool Sema::isOpenMPRebuildMemberExpr(ValueDecl *D) {
+  // Only rebuild for Field.
+  if (!dyn_cast(D))
+return false;
   DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
   D,
   [](OpenMPClauseKind C, bool AppliedToPointee,

diff  --git a/clang/test/OpenMP/parallel_default_messages.cpp 
b/clang/test/OpenMP/parallel_default_messages.cpp
index 7db15d726731..65e0d92c32fc 100644
--- a/clang/test/OpenMP/parallel_default_messages.cpp
+++ b/clang/test/OpenMP/parallel_default_messages.cpp
@@ -49,3 +49,10 @@ int main(int argc, char **argv) {
 
   return 0;
 }
+
+class A{
+  void a() {
+#pragma omp parallel
+a(b); // expected-error {{use of undeclared identifier 'b'}}
+ }
+};



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


[clang] 927156a - Generate the capture for the field when the field is used in openmp

2022-07-01 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-07-01T17:09:01-07:00
New Revision: 927156a67445a6edb1b09e3d6246b0e5a9cf8a16

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

LOG: Generate the capture for the field when the field is used in openmp
region with implicit default inside the member function.

This is to fix assert when field is referenced in OpenMP region with
default (first|private) clause inside member function.

The problem of assert is that the capture is not generated for the field.

This patch is to generate capture when the field is used with implicit
default, use it in the code, and save the capture off to make sure it is
considered from that point and add first/private clauses.

1> Add new field ImplicitDefaultFirstprivateFDs in SharingMapTy, used to
   store generated capture fields info.
2> In function isOpenMPCaptureDecl: the caputer is generated and saved
   in ImplicitDefaultFirstprivateFDs.
3> Add new help functions:
   getImplicitFDCapExprDecl
   isImplicitDefaultFirstprivateFD
   addImplicitDefaultFirstprivateFD
4> Add addition argument in hasDSA to check default attribute for
   default(first|private).
5> The isImplicitDefaultFirstprivateFD is used in VisitDeclRefExpr to
   build the implicit clause.
6> Add new parameter "Context" for buildCaptureDecl, due to when capture
   field, the parent context is needed to be used.
7> Change in isOpenMPPrivateDecl where stop propagate the capture from
   the enclosing region for private variable.
8> In ActOnOpenMPFirstprivate/ActOnOpenMPPrivate, using captured info
   to generate first|private clause.
9> Add new function isOpenMPRebuildMemberExpr: use to determine if field
   needs to be rebuild during template instantiation.

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/test/OpenMP/default_firstprivate_ast_print.cpp
clang/test/OpenMP/default_private_ast_print.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 17c9b1c2a5d32..ac241cf0515d4 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10725,6 +10725,13 @@ class Sema final {
   /// constructs.
   VarDecl *isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo = false,
 unsigned StopAt = 0);
+
+  /// The member expression(this->fd) needs to be rebuilt in the template
+  /// instantiation to generate private copy for OpenMP when default
+  /// clause is used. The function will return true if default
+  /// cluse is used.
+  bool isOpenMPRebuildMemberExpr(ValueDecl *D);
+
   ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK,
ExprObjectKind OK, SourceLocation Loc);
 

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 3b8f22201d824..117fec4c54194 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -196,6 +196,22 @@ class DSAStackTy {
 llvm::DenseSet> UsedInScanDirective;
 llvm::DenseMap, UsesAllocatorsDeclKind>
 UsesAllocatorsDecls;
+/// Data is required on creating capture fields for implicit
+/// default first|private clause.
+struct ImplicitDefaultFDInfoTy {
+  /// Field decl.
+  const FieldDecl *FD = nullptr;
+  /// Nesting stack level
+  size_t StackLevel = 0;
+  /// Capture variable decl.
+  VarDecl *VD = nullptr;
+  ImplicitDefaultFDInfoTy(const FieldDecl *FD, size_t StackLevel,
+  VarDecl *VD)
+  : FD(FD), StackLevel(StackLevel), VD(VD) {}
+};
+/// List of captured fields
+llvm::SmallVector
+ImplicitDefaultFirstprivateFDs;
 Expr *DeclareMapperVar = nullptr;
 SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name,
  Scope *CurScope, SourceLocation Loc)
@@ -577,7 +593,9 @@ class DSAStackTy {
   /// predicate.
   const DSAVarData
   hasDSA(ValueDecl *D,
- const llvm::function_ref CPred,
+ const llvm::function_ref
+ CPred,
  const llvm::function_ref DPred,
  bool FromParent) const;
   /// Checks if the specified variables has data-sharing attributes which
@@ -1120,6 +1138,52 @@ class DSAStackTy {
 const SharingMapTy *Top = getTopOfStackOrNull();
 return Top ? Top->DeclareMapperVar : nullptr;
   }
+  /// get captured field from ImplicitDefaultFirstprivateFDs
+  VarDecl *getImplicitFDCapExprDecl(const FieldDecl *FD) const {
+const_iterator I = begin();
+const_iterator EndI = end();
+size_t StackLevel = getStackSize();
+for (; I != EndI; ++I) {
+  if (I->DefaultAttr == 

[clang] bb83f8e - [OpenMP] Initial parsing and sema for 'parallel masked' construct

2022-06-16 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-06-16T18:01:15-07:00
New Revision: bb83f8e70bd1d56152f02307adacd718cd67e312

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

LOG: [OpenMP] Initial parsing and sema for 'parallel masked' construct

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

Added: 
clang/test/OpenMP/parallel_masked_ast_print.cpp
clang/test/OpenMP/parallel_masked_copyin_messages.cpp
clang/test/OpenMP/parallel_masked_default_messages.cpp
clang/test/OpenMP/parallel_masked_firstprivate_messages.cpp
clang/test/OpenMP/parallel_masked_if_messages.cpp
clang/test/OpenMP/parallel_masked_message.cpp
clang/test/OpenMP/parallel_masked_num_threads_messages.cpp
clang/test/OpenMP/parallel_masked_private_messages.cpp
clang/test/OpenMP/parallel_masked_proc_bind_messages.cpp
clang/test/OpenMP/parallel_masked_reduction_messages.cpp
clang/test/OpenMP/parallel_masked_shared_messages.cpp

Modified: 
clang/bindings/python/clang/cindex.py
clang/include/clang-c/Index.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/StmtOpenMP.h
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/StmtOpenMP.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmt.cpp
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/Analysis/cfg-openmp.cpp
clang/test/OpenMP/nesting_of_regions.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 44bfba494df21..597dc5dd49738 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1312,7 +1312,7 @@ def __repr__(self):
 #
 # The translation unit cursor exists primarily to act as the root cursor for
 # traversing the contents of a translation unit.
-CursorKind.TRANSLATION_UNIT = CursorKind(300)
+CursorKind.TRANSLATION_UNIT = CursorKind(350)
 
 ###
 # Attributes

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 70de5195d0580..4ad7cebb04dcf 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2626,7 +2626,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPTargetParallelGenericLoopDirective = 299,
 
-  CXCursor_LastStmt = CXCursor_OMPTargetParallelGenericLoopDirective,
+  /** OpenMP parallel masked directive.
+   */
+  CXCursor_OMPParallelMaskedDirective = 300,
+
+  CXCursor_LastStmt = CXCursor_OMPParallelMaskedDirective,
 
   /**
* Cursor that represents the translation unit itself.
@@ -2634,7 +2638,7 @@ enum CXCursorKind {
* The translation unit cursor exists primarily to act as the root
* cursor for traversing the contents of a translation unit.
*/
-  CXCursor_TranslationUnit = 300,
+  CXCursor_TranslationUnit = 350,
 
   /* Attributes */
   CXCursor_FirstAttr = 400,

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index c6d74d94194bd..e5acaec7358e1 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2994,6 +2994,9 @@ DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
 DEF_TRAVERSE_STMT(OMPParallelMasterDirective,
   { TRY_TO(TraverseOMPExecutableDirective(S)); })
 
+DEF_TRAVERSE_STMT(OMPParallelMaskedDirective,
+  { TRY_TO(TraverseOMPExecutableDirective(S)); })
+
 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
   { TRY_TO(TraverseOMPExecutableDirective(S)); })
 

diff  --git a/clang/include/clang/AST/StmtOpenMP.h 
b/clang/include/clang/AST/StmtOpenMP.h
index 4ebe7f44aa7ad..0482e6a3b7d3d 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -2304,6 +2304,69 @@ class OMPParallelMasterDirective : public 
OMPExecutableDirective {
   }
 };
 
+/// This represents '#pragma omp parallel masked' directive.
+///
+/// \code
+/// #pragma omp parallel masked filter(tid)
+/// \endcode
+/// In this example directive '#pragma omp parallel masked' has a clause
+/// 'filter' with the variable tid
+///
+class OMPParallelMaskedDirective final : public OMPExecutableDirective {
+  friend class ASTStmtReader;
+  friend class OMPExecutableDirective;
+
+  OMPParallelMaskedDirective(SourceLocation 

[clang] 7aa9c39 - [Clang][[OpenMP5.1] Initial parser/sema for default(private) clause

2022-05-19 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-05-19T12:43:13-07:00
New Revision: 7aa9c39381989134e5d36ec1ea859dc6dc44d8eb

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

LOG: [Clang][[OpenMP5.1] Initial parser/sema for default(private) clause

This implements the default(private) clause as defined in OMP5.1

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

Added: 
clang/test/OpenMP/default_firstprivate_ast_print.cpp
clang/test/OpenMP/default_private_ast_print.cpp

Modified: 
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/distribute_parallel_for_default_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_default_messages.cpp
clang/test/OpenMP/parallel_default_messages.cpp
clang/test/OpenMP/parallel_for_default_messages.cpp
clang/test/OpenMP/parallel_for_simd_default_messages.cpp
clang/test/OpenMP/parallel_master_codegen.cpp
clang/test/OpenMP/parallel_master_default_messages.cpp
clang/test/OpenMP/parallel_sections_default_messages.cpp
clang/test/OpenMP/target_parallel_default_messages.cpp
clang/test/OpenMP/target_parallel_for_default_messages.cpp
clang/test/OpenMP/target_parallel_for_simd_default_messages.cpp
clang/test/OpenMP/target_teams_default_messages.cpp
clang/test/OpenMP/target_teams_distribute_default_messages.cpp
clang/test/OpenMP/target_teams_distribute_parallel_for_default_messages.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_default_messages.cpp
clang/test/OpenMP/task_default_messages.cpp
clang/test/OpenMP/teams_default_messages.cpp
clang/test/OpenMP/teams_distribute_default_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_default_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_default_messages.cpp
clang/test/OpenMP/teams_distribute_simd_default_messages.cpp
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index b6dcf26ec..c206c63e84acb 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1231,11 +1231,12 @@ Node Matchers
 
   #pragma omp parallel default(none)
   #pragma omp parallel default(shared)
+  #pragma omp parallel default(private)
   #pragma omp parallel default(firstprivate)
   #pragma omp parallel
 
-``ompDefaultClause()`` matches ``default(none)``, ``default(shared)``, and
-``default(firstprivate)``
+``ompDefaultClause()`` matches ``default(none)``, ``default(shared)``,
+``default(private)`` and ``default(firstprivate)``
 
 
 
@@ -4715,6 +4716,22 @@ Narrowing Matchers
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html;>OMPDefaultClauseisFirstPrivateKind
+Matches if the OpenMP 
``default`` clause has ``private`` kind
+specified.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel default(none)
+  #pragma omp parallel default(shared)
+  #pragma omp parallel default(private)
+  #pragma omp parallel default(firstprivate)
+
+``ompDefaultClause(isFirstPrivateKind())`` matches only
+``default(private)``.
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1OMPDefaultClause.html;>OMPDefaultClauseisFirstPrivateKind
 Matches if the 
OpenMP ``default`` clause has ``firstprivate`` kind
 specified.
@@ -4724,6 +4741,7 @@ Narrowing Matchers
   #pragma omp parallel
   #pragma omp parallel default(none)
   #pragma omp parallel default(shared)
+  #pragma omp parallel default(private)
   #pragma omp parallel default(firstprivate)
 
 ``ompDefaultClause(isFirstPrivateKind())`` matches only
@@ -4739,6 +4757,7 @@ Narrowing Matchers
   #pragma omp parallel
   #pragma omp parallel default(none)
   #pragma omp parallel default(shared)
+  #pragma omp parallel default(private)
   #pragma omp parallel default(firstprivate)
 
 ``ompDefaultClause(isNoneKind())`` matches only ``default(none)``.
@@ -4753,6 +4772,7 @@ Narrowing Matchers
   #pragma omp parallel
   #pragma omp parallel default(none)
   #pragma omp parallel default(shared)
+  #pragma omp parallel default(private)
   #pragma omp parallel default(firstprivate)
 
 ``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``.

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index d2bffe8fef491..0b51c2b463bd0 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -8303,12 +8303,13 @@ AST_MATCHER_P(OMPExecutableDirective, 

[clang] 187ccc6 - [clang][OpenMP5.1] Initial parsing/sema for has_device_addr

2022-04-08 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-04-08T21:19:38-07:00
New Revision: 187ccc66fa5d0b04189cdbd8266fc386e60f48aa

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

LOG: [clang][OpenMP5.1] Initial parsing/sema for has_device_addr

Added basic parsing/sema/ support for the 'has_device_addr' clause.

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

Added: 
clang/test/OpenMP/target_has_device_addr_ast_print.cpp
clang/test/OpenMP/target_has_device_addr_messages.cpp

Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/Analysis/cfg-openmp.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 3ecc1d40fafc6..3103f61d4248d 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7416,6 +7416,110 @@ class OMPIsDevicePtrClause final
   }
 };
 
+/// This represents clause 'has_device_ptr' in the '#pragma omp ...'
+/// directives.
+///
+/// \code
+/// #pragma omp target has_device_addr(a,b)
+/// \endcode
+/// In this example directive '#pragma omp target' has clause
+/// 'has_device_ptr' with the variables 'a' and 'b'.
+class OMPHasDeviceAddrClause final
+: public OMPMappableExprListClause,
+  private llvm::TrailingObjects<
+  OMPHasDeviceAddrClause, Expr *, ValueDecl *, unsigned,
+  OMPClauseMappableExprCommon::MappableComponent> {
+  friend class OMPClauseReader;
+  friend OMPMappableExprListClause;
+  friend OMPVarListClause;
+  friend TrailingObjects;
+
+  /// Build clause with number of variables \a NumVars.
+  ///
+  /// \param Locs Locations needed to build a mappable clause. It includes 1)
+  /// StartLoc: starting location of the clause (the clause keyword); 2)
+  /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
+  /// \param Sizes All required sizes to build a mappable clause. It includes 
1)
+  /// NumVars: number of expressions listed in this clause; 2)
+  /// NumUniqueDeclarations: number of unique base declarations in this clause;
+  /// 3) NumComponentLists: number of component lists in this clause; and 4)
+  /// NumComponents: total number of expression components in the clause.
+  explicit OMPHasDeviceAddrClause(const OMPVarListLocTy ,
+  const OMPMappableExprListSizeTy )
+  : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr, Locs,
+  Sizes) {}
+
+  /// Build an empty clause.
+  ///
+  /// \param Sizes All required sizes to build a mappable clause. It includes 
1)
+  /// NumVars: number of expressions listed in this clause; 2)
+  /// NumUniqueDeclarations: number of unique base declarations in this clause;
+  /// 3) NumComponentLists: number of component lists in this clause; and 4)
+  /// NumComponents: total number of expression components in the clause.
+  explicit OMPHasDeviceAddrClause(const OMPMappableExprListSizeTy )
+  : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr,
+  OMPVarListLocTy(), Sizes) {}
+
+  /// Define the sizes of each trailing object array except the last one. This
+  /// is required for TrailingObjects to work properly.
+  size_t numTrailingObjects(OverloadToken) const {
+return varlist_size();
+  }
+  size_t numTrailingObjects(OverloadToken) const {
+return getUniqueDeclarationsNum();
+  }
+  size_t numTrailingObjects(OverloadToken) const {
+return getUniqueDeclarationsNum() + getTotalComponentListNum();
+  }
+
+public:
+  /// Creates clause with a list of variables \a Vars.
+  ///
+  /// \param C AST context.
+  /// \param Locs Locations needed to build a mappable clause. It includes 1)
+  /// StartLoc: starting location of the clause (the clause keyword); 2)
+  /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
+  /// \param Vars The original expression used in the clause.
+  /// \param Declarations Declarations used in the clause.
+  /// \param ComponentLists Component lists used in the clause.
+  static OMPHasDeviceAddrClause *
+  Create(const ASTContext , const OMPVarListLocTy ,
+ ArrayRef Vars, ArrayRef Declarations,
+ MappableExprComponentListsRef 

[clang] a6cdac4 - Eliminate extra set of simd variant function attribute.

2022-03-24 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-03-24T13:27:28-07:00
New Revision: a6cdac48ffaf1aba9c2055db0ea92f8d25e629d8

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

LOG: Eliminate extra set of simd variant function attribute.

Current clang generates extra set of simd variant function attribute
with extra 'v' encoding.
For example:
_ZGVbN2v__Z5add_1Pf vs _ZGVbN2vv__Z5add_1Pf
The problem is due to declaration of ParamAttrs following:
llvm::SmallVector ParamAttrs(ParamPositions.size());
where ParamPositions.size() is grown after following assignment:
Pos = ParamPositions[PVD];
So the PVD is not find in ParamPositions.

The problem is ParamPositions need to set for each FD decl. To fix this

Move ParamPositions's init inside while loop for each FD.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/declare_simd_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index cb7ab2273a300..eb547be057cb9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11939,16 +11939,16 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
   llvm::Function *Fn) {
   ASTContext  = CGM.getContext();
   FD = FD->getMostRecentDecl();
-  // Map params to their positions in function decl.
-  llvm::DenseMap ParamPositions;
-  if (isa(FD))
-ParamPositions.try_emplace(FD, 0);
-  unsigned ParamPos = ParamPositions.size();
-  for (const ParmVarDecl *P : FD->parameters()) {
-ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
-++ParamPos;
-  }
   while (FD) {
+// Map params to their positions in function decl.
+llvm::DenseMap ParamPositions;
+if (isa(FD))
+  ParamPositions.try_emplace(FD, 0);
+unsigned ParamPos = ParamPositions.size();
+for (const ParmVarDecl *P : FD->parameters()) {
+  ParamPositions.try_emplace(P->getCanonicalDecl(), ParamPos);
+  ++ParamPos;
+}
 for (const auto *Attr : FD->specific_attrs()) {
   llvm::SmallVector ParamAttrs(ParamPositions.size());
   // Mark uniform parameters.
@@ -11960,7 +11960,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
-  Pos = ParamPositions[PVD];
+  auto It = ParamPositions.find(PVD);
+  assert(It != ParamPositions.end() && "Function parameter not found");
+  Pos = It->second;
 }
 ParamAttrs[Pos].Kind = Uniform;
   }
@@ -11976,7 +11978,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
-  Pos = ParamPositions[PVD];
+  auto It = ParamPositions.find(PVD);
+  assert(It != ParamPositions.end() && "Function parameter not found");
+  Pos = It->second;
   ParmTy = PVD->getType();
 }
 ParamAttrs[Pos].Alignment =
@@ -12000,7 +12004,9 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
 } else {
   const auto *PVD = cast(cast(E)->getDecl())
 ->getCanonicalDecl();
-  Pos = ParamPositions[PVD];
+  auto It = ParamPositions.find(PVD);
+  assert(It != ParamPositions.end() && "Function parameter not found");
+  Pos = It->second;
   if (auto *P = dyn_cast(PVD->getType()))
 PtrRescalingFactor = CGM.getContext()
  .getTypeSizeInChars(P->getPointeeType())
@@ -12018,8 +12024,10 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const 
FunctionDecl *FD,
   if (const auto *StridePVD =
   dyn_cast(DRE->getDecl())) {
 ParamAttr.Kind = LinearWithVarStride;
-ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(
-ParamPositions[StridePVD->getCanonicalDecl()]);
+auto It = ParamPositions.find(StridePVD->getCanonicalDecl());
+assert(It != ParamPositions.end() &&
+   "Function parameter not found");
+ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(It->second);
   }
 }
   } else {

diff  --git a/clang/test/OpenMP/declare_simd_codegen.cpp 
b/clang/test/OpenMP/declare_simd_codegen.cpp
index 1967f3b248dc5..bd5a9679175f3 100644
--- a/clang/test/OpenMP/declare_simd_codegen.cpp
+++ b/clang/test/OpenMP/declare_simd_codegen.cpp
@@ 

[clang] 140a6b1 - [clang][OpenMP5.1] Initial parsing/sema for 'indirect' clause

2022-01-10 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2022-01-10T16:58:56-08:00
New Revision: 140a6b1e5c6857617a83f66680b4829ff2b08d82

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

LOG: [clang][OpenMP5.1] Initial parsing/sema for 'indirect' clause

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

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/AttrImpl.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/OpenMP/declare_target_ast_print.cpp
clang/test/OpenMP/declare_target_messages.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 10c5c7f1b879a..b071ebb4d576b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3686,6 +3686,8 @@ def OMPDeclareTargetDecl : InheritableAttr {
 EnumArgument<"DevType", "DevTypeTy",
  [ "host", "nohost", "any" ],
  [ "DT_Host", "DT_NoHost", "DT_Any" ]>,
+ExprArgument<"IndirectExpr">,
+BoolArgument<"Indirect">,
 UnsignedArgument<"Level">
   ];
   let AdditionalMembers = [{

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 9dc036c03faa8..193dff8b9c8f6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1344,15 +1344,17 @@ def warn_omp_unknown_assumption_clause_without_args
 def note_omp_assumption_clause_continue_here
 : Note<"the ignored tokens spans until here">;
 def err_omp_declare_target_unexpected_clause: Error<
-  "unexpected '%0' clause, only %select{'device_type'|'to' or 'link'|'to', 
'link' or 'device_type'}1 clauses expected">;
+  "unexpected '%0' clause, only %select{'device_type'|'to' or 'link'|'to', 
'link' or 'device_type'|'device_type', 'indirect'|'to', 'link', 'device_type' 
or 'indirect'}1 clauses expected">;
 def err_omp_begin_declare_target_unexpected_implicit_to_clause: Error<
   "unexpected '(', only 'to', 'link' or 'device_type' clauses expected for 
'begin declare target' directive">;
 def err_omp_declare_target_unexpected_clause_after_implicit_to: Error<
   "unexpected clause after an implicit 'to' clause">;
 def err_omp_declare_target_missing_to_or_link_clause: Error<
-  "expected at least one 'to' or 'link' clause">;
+  "expected at least one %select{'to' or 'link'|'to', 'link' or 'indirect'}0 
clause">;
 def err_omp_declare_target_multiple : Error<
   "%0 appears multiple times in clauses on the same declare target directive">;
+def err_omp_declare_target_indirect_device_type: Error<
+  "only 'device_type(any)' clause is allowed with indirect clause">;
 def err_omp_expected_clause: Error<
   "expected at least one clause on '#pragma omp %0' directive">;
 def err_omp_mapper_illegal_identifier : Error<

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index a98ad78401f02..74935c8900178 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3316,6 +3316,11 @@ class Parser : public CodeCompletionHandler {
   /// nullptr.
   ///
   OMPClause *ParseOpenMPSimpleClause(OpenMPClauseKind Kind, bool ParseOnly);
+  /// Parses indirect clause
+  /// \param ParseOnly true to skip the clause's semantic actions and return
+  // false;
+  bool ParseOpenMPIndirectClause(Sema::DeclareTargetContextInfo ,
+ bool ParseOnly);
   /// Parses clause with a single expression and an additional argument
   /// of a kind \a Kind.
   ///

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9b6d9d20ca431..f1e90356c8367 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10333,6 +10333,9 @@ class Sema final {
 /// The directive kind, `begin declare target` or `declare target`.
 OpenMPDirectiveKind Kind;
 
+/// The directive with indirect clause.
+Optional Indirect;
+
 /// The directive location.
 SourceLocation Loc;
 
@@ -10639,7 +10642,7 @@ class Sema final {
   /// Called on correct id-expression from the '#pragma omp declare target'.
   void ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc,
 OMPDeclareTargetDeclAttr::MapTypeTy MT,
-OMPDeclareTargetDeclAttr::DevTypeTy DT);
+DeclareTargetContextInfo 

[clang] a4743eb - Fix assert of "Unable to find base lambda address" from

2021-10-06 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-10-06T14:14:28-07:00
New Revision: a4743eba3c13799e66764554fd44ccc6a33a

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

LOG: Fix assert of "Unable to find base lambda address" from
adjustMemberOfForLambdaCaptures.

The problem is happening when user passes lambda function with reference
type in the map clause.

The natural of the problem when processing generateInfoForCapture,
the BasePointer is generated with new load for a lambda variable with
reference type.  It is not expected in adjustMemberOfForLambdaCaptures.

One way to fix this is to skipping call to generateInfoForCapture for
map(to:lambda).  The map info will be generated later in the call to
generateDefaultMapInfo samiler as firsprivate clase.

This to fix https://bugs.llvm.org/show_bug.cgi?id=52071

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e51d196b870f..bf72897d81b0 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7481,6 +7481,9 @@ class MappableExprsHandler {
   SmallVector>
   DevPointersMap;
 
+  /// Map between lambda declarations and their map type.
+  llvm::DenseMap LambdasMap;
+
   llvm::Value *getExprTypeSize(const Expr *E) const {
 QualType ExprTy = E->getType().getCanonicalType();
 
@@ -8442,6 +8445,15 @@ class MappableExprsHandler {
   return MappableExprsHandler::OMP_MAP_PRIVATE |
  MappableExprsHandler::OMP_MAP_TO;
 }
+auto I = LambdasMap.find(Cap.getCapturedVar()->getCanonicalDecl());
+if (I != LambdasMap.end())
+  // for map(to: lambda): using user specified map type.
+  return getMapTypeBits(
+  I->getSecond()->getMapType(), I->getSecond()->getMapTypeModifiers(),
+  /*MotionModifiers=*/llvm::None, I->getSecond()->isImplicit(),
+  /*AddPtrFlag=*/false,
+  /*AddIsTargetParamFlag=*/false,
+  /*isNonContiguous=*/false);
 return MappableExprsHandler::OMP_MAP_TO |
MappableExprsHandler::OMP_MAP_FROM;
   }
@@ -8906,6 +8918,21 @@ class MappableExprsHandler {
 for (const auto *C : Dir.getClausesOfKind())
   for (auto L : C->component_lists())
 DevPointersMap[std::get<0>(L)].push_back(std::get<1>(L));
+// Extract map information.
+for (const auto *C : Dir.getClausesOfKind()) {
+  if (C->getMapType() != OMPC_MAP_to)
+continue;
+  for (auto L : C->component_lists()) {
+const ValueDecl *VD = std::get<0>(L);
+const auto *RD = VD ? VD->getType()
+  .getCanonicalType()
+  .getNonReferenceType()
+  ->getAsCXXRecordDecl()
+: nullptr;
+if (RD && RD->isLambda())
+  LambdasMap.try_emplace(std::get<0>(L), C);
+  }
+}
   }
 
   /// Constructor for the declare mapper directive.
@@ -9118,6 +9145,11 @@ class MappableExprsHandler {
   ? nullptr
   : Cap->getCapturedVar()->getCanonicalDecl();
 
+// for map(to: lambda): skip here, processing it in
+// generateDefaultMapInfo
+if (LambdasMap.count(VD))
+  return;
+
 // 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.

diff  --git a/clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp 
b/clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
index 544158ba4594..7c7e27239680 100644
--- a/clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
+++ b/clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
@@ -15,6 +15,10 @@
 // CHECK-DAG: [[TYPES_TEMPLATE:@.+]] = private {{.+}} constant [5 x i64] [i64 
800, i64 800, i64 673, i64 844424930132752, i64 844424930132752]
 // CHECK-DAG: [[SIZES:@.+]] = private {{.+}} constant [3 x i[[PTRSZ:32|64]]] 
[i{{32|64}} {{8|16}}, i{{32|64}} 0, i{{32|64}} 0]
 // CHECK-DAG: [[TYPES:@.+]] = private {{.+}} constant [3 x i64] [i64 673, i64 
281474976711440, i64 281474976711440]
+// CHECK-DAG: [[TYPES3:@.+]] = private {{.+}} constant [3 x i64] [i64 545, i64 
281474976711440, i64 800]
+// CHECK-DAG: [[TYPES11:@.+]] = private {{.+}} constant [5 x i64] [i64 800, 
i64 800, i64 549, i64 844424930132752, i64 844424930132752]
+// CHECK-DAG: [[TYPES13:@.+]] = private {{.+}} constant [2 x i64] [i64 545, 
i64 281474976711440]
+// CHECK-DAG: [[TYPES15:@.+]] = private {{.+}} constant [2 x i64] [i64 673, 
i64 281474976711440]
 
 template 
 void 

[clang] c274b19 - Add implicit map for a list item appears in a reduction clause.

2021-08-19 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-08-19T12:53:47-07:00
New Revision: c274b198668040acc239b349ef1f7820c91a95c8

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

LOG: Add implicit map for a list item appears in a reduction clause.

A new rule is added in 5.0:
If a list item appears in a reduction, lastprivate or linear clause
on a combined target construct then it is treated as if it also appears
in a map clause with a map-type of tofrom.

Currently map clauses for all capture variables are added implicitly.
But missing for list item of expression for array elements or array
sections.

The change is to add implicit map clause for array of elements used in
reduction clause. Skip adding map clause if the expression is not
mappable.
Noted: For linear and lastprivate, since only variable name is
accepted, the map has been added though capture variables.

To do so:
During the mappable checking, if error, ignore diagnose and skip
adding implicit map clause.

The changes:
1> Add code to generate implicit map in ActOnOpenMPExecutableDirective,
   for omp 5.0 and up.
2> Add extra default parameter NoDiagnose in ActOnOpenMPMapClause:
Use that to skip error as well as skip adding implicit map during the
mappable checking.

Note: there are only tow places need to be check for NoDiagnose. Rest
of them either the check is for < omp 5.0 or the error already generated for
reduction clause.

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

Added: 
clang/test/OpenMP/reduction_implicit_map.cpp
openmp/libomptarget/test/mapping/reduction_implicit_map.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e38f50733bebe..0205c28c48569 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11246,15 +11246,14 @@ class Sema final {
  SourceLocation ModifierLoc,
  SourceLocation EndLoc);
   /// Called on well-formed 'map' clause.
-  OMPClause *
-  ActOnOpenMPMapClause(ArrayRef MapTypeModifiers,
-   ArrayRef MapTypeModifiersLoc,
-   CXXScopeSpec ,
-   DeclarationNameInfo ,
-   OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
-   SourceLocation MapLoc, SourceLocation ColonLoc,
-   ArrayRef VarList, const OMPVarListLocTy ,
-   ArrayRef UnresolvedMappers = llvm::None);
+  OMPClause *ActOnOpenMPMapClause(
+  ArrayRef MapTypeModifiers,
+  ArrayRef MapTypeModifiersLoc,
+  CXXScopeSpec , DeclarationNameInfo ,
+  OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
+  SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef VarList,
+  const OMPVarListLocTy , bool NoDiagnose = false,
+  ArrayRef UnresolvedMappers = llvm::None);
   /// Called on well-formed 'num_teams' clause.
   OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
SourceLocation LParenLoc,

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index b09bda1138cc6..a64e5855441fc 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5812,6 +5812,31 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
 ErrorFound = true;
   }
 }
+// OpenMP 5.0 [2.19.7]
+// If a list item appears in a reduction, lastprivate or linear
+// clause on a combined target construct then it is treated as
+// if it also appears in a map clause with a map-type of tofrom
+if (getLangOpts().OpenMP >= 50 && Kind != OMPD_target &&
+isOpenMPTargetExecutionDirective(Kind)) {
+  SmallVector ImplicitExprs;
+  for (OMPClause *C : Clauses) {
+if (auto *RC = dyn_cast(C))
+  for (Expr *E : RC->varlists())
+if (!isa(E->IgnoreParenImpCasts()))
+  ImplicitExprs.emplace_back(E);
+  }
+  if (!ImplicitExprs.empty()) {
+ArrayRef Exprs = ImplicitExprs;
+CXXScopeSpec MapperIdScopeSpec;
+DeclarationNameInfo MapperId;
+if (OMPClause *Implicit = ActOnOpenMPMapClause(
+OMPC_MAP_MODIFIER_unknown, SourceLocation(), MapperIdScopeSpec,
+MapperId, OMPC_MAP_tofrom,
+/*IsMapTypeImplicit=*/true, SourceLocation(), SourceLocation(),
+Exprs, OMPVarListLocTy(), /*NoDiagnose=*/true))
+  ClausesWithImplicit.emplace_back(Implicit);
+  }
+}
 for (unsigned I = 0, E = DefaultmapKindNum; I < E; ++I) {
   int ClauseKindCnt = -1;
   for (ArrayRef 

[clang] 6b0f359 - Fix signal during the call to checkOpenMPLoop.

2021-08-05 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-08-05T08:59:35-07:00
New Revision: 6b0f35931a44b0fbd27297f83087d3a4c352e83f

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

LOG: Fix signal during the call to checkOpenMPLoop.

The root problem is a null pointer is accessed during the call to
checkOpenMPLoop, because loop up bound expr is an error expression
due to error diagnostic was emit early.

To fix this, in setLCDeclAndLB, setUB and setStep instead return false,
return true when LB, UB or Step contains Error, so that the checking is
stopped in checkOpenMPLoop.

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

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/teams_distribute_loop_messages.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index f093e6263e97d..b09bda1138cc6 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -7342,7 +7342,7 @@ bool 
OpenMPIterationSpaceChecker::setLCDeclAndLB(ValueDecl *NewLCDecl,
   // State consistency checking to ensure correct usage.
   assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr &&
  UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp);
-  if (!NewLCDecl || !NewLB)
+  if (!NewLCDecl || !NewLB || NewLB->containsErrors())
 return true;
   LCDecl = getCanonicalDecl(NewLCDecl);
   LCRef = NewLCRefExpr;
@@ -7365,7 +7365,7 @@ bool OpenMPIterationSpaceChecker::setUB(Expr *NewUB,
   // State consistency checking to ensure correct usage.
   assert(LCDecl != nullptr && LB != nullptr && UB == nullptr &&
  Step == nullptr && !TestIsLessOp && !TestIsStrictOp);
-  if (!NewUB)
+  if (!NewUB || NewUB->containsErrors())
 return true;
   UB = NewUB;
   if (LessOp)
@@ -7380,7 +7380,7 @@ bool OpenMPIterationSpaceChecker::setUB(Expr *NewUB,
 bool OpenMPIterationSpaceChecker::setStep(Expr *NewStep, bool Subtract) {
   // State consistency checking to ensure correct usage.
   assert(LCDecl != nullptr && LB != nullptr && Step == nullptr);
-  if (!NewStep)
+  if (!NewStep || NewStep->containsErrors())
 return true;
   if (!NewStep->isValueDependent()) {
 // Check that the step is integer expression.

diff  --git a/clang/test/OpenMP/teams_distribute_loop_messages.cpp 
b/clang/test/OpenMP/teams_distribute_loop_messages.cpp
index 36f3830829c5e..e115d7498017e 100644
--- a/clang/test/OpenMP/teams_distribute_loop_messages.cpp
+++ b/clang/test/OpenMP/teams_distribute_loop_messages.cpp
@@ -721,4 +721,15 @@ void test_nowait() {
   for (int i = 0; i < 16; ++i)
 ;
 }
+//expected-note@+1 {{candidate function not viable: requires single argument 
'device_Id', but no arguments were provided}}
+int foo(int device_Id) {
+  return 2;
+}
+
+int main() {
+// expected-error@+1 {{no matching function for call to 'foo'}}
+  const int globalWI{ foo() };
+#pragma omp target teams distribute
+  for (int i=0 ; ihttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 656d022 - Stop emit incomplete type error for a variable in a map clause

2021-08-03 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-08-03T10:51:32-07:00
New Revision: 656d02233170e1707d3534b042960b71cf6eb98b

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

LOG: Stop emit incomplete type error for a variable in a map clause
where should not.

Currently we are using QTy->isIncompleteType() to check incomplete
type.  But before doing that, need to instantiate for a class template
specialization or a class member of a class template specialization,
or an array with known size of such..., so that we know it is really
incomplete type.

To fix this using RequireCompleteType instead.

The new test is added into "test/OpenMP/target_update_messages.cpp"

The different of using RequireCompleteType is when emit incomplete type,
an additional note is also emitted to point to where incomplete type
is declared.  Because this change, many tests are needed to be fixed
by adding additional note.

This is to fix https://bugs.llvm.org/show_bug.cgi?id=50508

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

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/distribute_firstprivate_messages.cpp
clang/test/OpenMP/distribute_parallel_for_firstprivate_messages.cpp
clang/test/OpenMP/distribute_parallel_for_lastprivate_messages.cpp
clang/test/OpenMP/distribute_parallel_for_reduction_messages.cpp
clang/test/OpenMP/distribute_parallel_for_shared_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_linear_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
clang/test/OpenMP/distribute_parallel_for_simd_shared_messages.cpp
clang/test/OpenMP/distribute_simd_aligned_messages.cpp
clang/test/OpenMP/distribute_simd_firstprivate_messages.cpp
clang/test/OpenMP/distribute_simd_lastprivate_messages.cpp
clang/test/OpenMP/distribute_simd_linear_messages.cpp
clang/test/OpenMP/distribute_simd_reduction_messages.cpp
clang/test/OpenMP/target_map_messages.cpp
clang/test/OpenMP/target_parallel_for_map_messages.cpp
clang/test/OpenMP/target_parallel_for_simd_map_messages.cpp
clang/test/OpenMP/target_parallel_map_messages.cpp
clang/test/OpenMP/target_simd_map_messages.cpp
clang/test/OpenMP/target_teams_distribute_map_messages.cpp
clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
clang/test/OpenMP/target_teams_map_messages.cpp
clang/test/OpenMP/target_update_from_messages.cpp
clang/test/OpenMP/target_update_messages.cpp
clang/test/OpenMP/target_update_to_messages.cpp
clang/test/OpenMP/teams_distribute_firstprivate_messages.cpp
clang/test/OpenMP/teams_distribute_lastprivate_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_firstprivate_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_lastprivate_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_reduction_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_shared_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp

clang/test/OpenMP/teams_distribute_parallel_for_simd_firstprivate_messages.cpp

clang/test/OpenMP/teams_distribute_parallel_for_simd_lastprivate_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_linear_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_reduction_messages.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_shared_messages.cpp
clang/test/OpenMP/teams_distribute_reduction_messages.cpp
clang/test/OpenMP/teams_distribute_shared_messages.cpp
clang/test/OpenMP/teams_distribute_simd_aligned_messages.cpp
clang/test/OpenMP/teams_distribute_simd_firstprivate_messages.cpp
clang/test/OpenMP/teams_distribute_simd_lastprivate_messages.cpp
clang/test/OpenMP/teams_distribute_simd_linear_messages.cpp
clang/test/OpenMP/teams_distribute_simd_reduction_messages.cpp
clang/test/OpenMP/teams_distribute_simd_shared_messages.cpp
clang/test/OpenMP/teams_firstprivate_messages.cpp
clang/test/OpenMP/teams_reduction_messages.cpp
clang/test/OpenMP/teams_shared_messages.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index c0cd2bf18a77..f093e6263e97 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -18443,11 +18443,8 @@ OMPClause 

[clang] 5285748 - Fix assert on the variable which is used in omp clause is not marked

2021-05-04 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-05-04T09:07:35-07:00
New Revision: 5285748c2c764c1d7fb3f882ba9f11ed79f676a1

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

LOG: Fix assert on the variable which is used in omp clause is not marked
as used.

The problem only happens with constexpr variable, for constexpr variable,
variable is not marked during parser variable.   This is because compiler
might find some var's associate expressions may not actully an odr-used
later,  the variables get kept in MaybeODRUseExprs, in normal case, at
end of process fullExpr, the variable will be marked during the call to
CleanupVarDeclMarking(). Since we are processing expression of OpenMP
clauses, and the ActOnFinishFullExpr is not getting called that casue
variable is not get marked.

One way to fix this is to call CleanupVarDeclMarking() in EndOpenMPClause
for each omp directive.

This to fix https://bugs.llvm.org/show_bug.cgi?id=50206

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

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/constexpr_capture.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 25ee46d95aa55..9ac3e48781849 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2527,6 +2527,7 @@ void Sema::StartOpenMPClause(OpenMPClauseKind K) {
 
 void Sema::EndOpenMPClause() {
   DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown);
+  CleanupVarDeclMarking();
 }
 
 static std::pair

diff  --git a/clang/test/OpenMP/constexpr_capture.cpp 
b/clang/test/OpenMP/constexpr_capture.cpp
index 9577f6e0c0fe2..ba404d7fdafd0 100644
--- a/clang/test/OpenMP/constexpr_capture.cpp
+++ b/clang/test/OpenMP/constexpr_capture.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-linux 
-S -emit-llvm %s -o - -std=c++11 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++  
-fopenmp-targets=x86_64-pc-linux-gnu -triple powerpc64le-unknown-linux -S 
-emit-llvm %s -o - -std=c++11 2>&1 | FileCheck %s
 // expected-no-diagnostics
 
 template  struct integral_constant {
@@ -12,10 +13,24 @@ struct decay {
 struct V {
   template ::type> V();
 };
+
+constexpr double h_chebyshev_coefs[] = {
+1.020784639703, 0.0021491446496202074};
+
+void test(double *d_value)
+{
+#pragma omp target map(tofrom  \
+   : d_value [0:1]) map(always, to \
+: h_chebyshev_coefs [0:2])
+  *d_value = h_chebyshev_coefs[1];  return;
+}
+
+// CHECK: void @__omp_offloading_{{.+}}test{{.+}}(double* %0)
+
 int main() {
 #pragma omp target
   V v;
   return 0;
 }
 
-// CHECK: call void @__omp_offloading_{{.+}}_main_l16()
+// CHECK: call void @__omp_offloading_{{.+}}_main_{{.+}}()



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


[clang] ebf2dc3 - Fix missing generate capture expression for novariants condition.

2021-04-07 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-04-07T12:35:49-07:00
New Revision: ebf2dc33287ea414059d3b2f3568f6653ddd4b51

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

LOG: Fix missing generate capture expression for novariants condition.

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/dispatch_ast_print.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index c285ce32aea7..2d2f02c7ed90 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14905,6 +14905,7 @@ OMPClause *Sema::ActOnOpenMPNovariantsClause(Expr 
*Condition,
 if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) {
   ValExpr = MakeFullExpr(ValExpr).get();
   llvm::MapVector Captures;
+  ValExpr = tryBuildCapture(*this, ValExpr, Captures).get();
   HelperValStmt = buildPreInits(Context, Captures);
 }
   }

diff  --git a/clang/test/OpenMP/dispatch_ast_print.cpp 
b/clang/test/OpenMP/dispatch_ast_print.cpp
index e44c48946bb7..11c0ed82fa90 100644
--- a/clang/test/OpenMP/dispatch_ast_print.cpp
+++ b/clang/test/OpenMP/dispatch_ast_print.cpp
@@ -56,6 +56,9 @@ void test_one()
   //DUMP: OMPDependClause
   //DUMP: OMPNowaitClause
   //DUMP: OMPNovariantsClause
+  //DUMP: DeclRefExpr {{.*}} 'bool' lvalue OMPCapturedExpr
+  //DUMP: OMPNocontextClause
+  //DUMP: DeclRefExpr {{.*}} 'bool' lvalue OMPCapturedExpr
   #pragma omp dispatch depend(in:var) nowait novariants(aaa > 5) nocontext(bbb 
> 5)
   foo(aaa, );
 
@@ -66,6 +69,9 @@ void test_one()
   //DUMP: OMPDeviceClause
   //DUMP: OMPIs_device_ptrClause
   //DUMP: OMPNovariantsClause
+  //DUMP: DeclRefExpr {{.*}} 'bool' lvalue OMPCapturedExpr
+  //DUMP: OMPNocontextClause
+  //DUMP: DeclRefExpr {{.*}} 'bool' lvalue OMPCapturedExpr
   #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10) 
nocontext(dev > 5)
   foo(aaa, dp);
 



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


[clang] 7078ef4 - [OPENMP51]Initial support for nocontext clause.

2021-04-05 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-04-05T11:45:49-07:00
New Revision: 7078ef47225091a9a42357b9ebf92e83a5665d43

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

LOG: [OPENMP51]Initial support for nocontext clause.

Added basic parsing/sema/serialization support for the 'nocontext' clause.

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

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/dispatch_ast_print.cpp
clang/test/OpenMP/dispatch_messages.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 4d5cdffba8919..11eb453a02060 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7720,6 +7720,75 @@ class OMPNovariantsClause final : public OMPClause,
   }
 };
 
+/// This represents 'nocontext' clause in the '#pragma omp ...' directive.
+///
+/// \code
+/// #pragma omp dispatch nocontext(a > 5)
+/// \endcode
+/// In this example directive '#pragma omp dispatch' has simple 'nocontext'
+/// clause with condition 'a > 5'.
+class OMPNocontextClause final : public OMPClause, public OMPClauseWithPreInit 
{
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Condition of the 'if' clause.
+  Stmt *Condition = nullptr;
+
+  /// Set condition.
+  void setCondition(Expr *Cond) { Condition = Cond; }
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+public:
+  /// Build 'nocontext' clause with condition \a Cond.
+  ///
+  /// \param Cond Condition of the clause.
+  /// \param HelperCond Helper condition for the construct.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPNocontextClause(Expr *Cond, Stmt *HelperCond,
+ OpenMPDirectiveKind CaptureRegion, SourceLocation 
StartLoc,
+ SourceLocation LParenLoc, SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_nocontext, StartLoc, EndLoc),
+OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) {
+setPreInitStmt(HelperCond, CaptureRegion);
+  }
+
+  /// Build an empty clause.
+  OMPNocontextClause()
+  : OMPClause(llvm::omp::OMPC_nocontext, SourceLocation(),
+  SourceLocation()),
+OMPClauseWithPreInit(this) {}
+
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns condition.
+  Expr *getCondition() const { return cast_or_null(Condition); }
+
+  child_range children() { return child_range(,  + 1); }
+
+  const_child_range children() const {
+return const_child_range(,  + 1);
+  }
+
+  child_range used_children();
+  const_child_range used_children() const {
+auto Children = const_cast(this)->used_children();
+return const_child_range(Children.begin(), Children.end());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_nocontext;
+  }
+};
+
 /// This represents 'detach' clause in the '#pragma omp task' directive.
 ///
 /// \code

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index cdedbe22f9ed0..8ca7c509776b4 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3226,6 +3226,14 @@ bool 
RecursiveASTVisitor::VisitOMPNovariantsClause(
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPNocontextClause(
+OMPNocontextClause *C) {
+  TRY_TO(VisitOMPClauseWithPreInit(C));
+  TRY_TO(TraverseStmt(C->getCondition()));
+  return true;
+}
+
 template 
 template 
 bool RecursiveASTVisitor::VisitOMPClauseList(T *Node) {

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e0973171be937..8f6e6baaea62b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11014,6 +11014,11 @@ class Sema final {
  SourceLocation 

[clang] 0fe8af9 - Fix build bot problem with missing OMPC_novariants in switch.

2021-04-02 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-04-02T13:58:39-07:00
New Revision: 0fe8af94688aa03c01913c2001d6a1a911f42ce6

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

LOG: Fix build bot problem with missing OMPC_novariants in switch.

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 02d4f6b3c315..acc3261a1fe6 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -5612,6 +5612,7 @@ static void emitOMPAtomicExpr(CodeGenFunction , 
OpenMPClauseKind Kind,
   case OMPC_notinbranch:
   case OMPC_link:
   case OMPC_use:
+  case OMPC_novariants:
 llvm_unreachable("Clause is not allowed in 'omp atomic'.");
   }
 }



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


[clang] cb424fe - [OPENMP5.1]Initial support for novariants clause.

2021-04-02 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-04-02T13:19:01-07:00
New Revision: cb424fee3d6b27dbd38de666382b702100935286

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

LOG: [OPENMP5.1]Initial support for novariants clause.
Added basic parsing/sema/serialization support for the 'novariants' clause.

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/dispatch_ast_print.cpp
clang/test/OpenMP/dispatch_messages.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index f71eb15feea2..4d5cdffba891 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7649,6 +7649,77 @@ class OMPDestroyClause final : public OMPClause {
   }
 };
 
+/// This represents 'novariants' clause in the '#pragma omp ...' directive.
+///
+/// \code
+/// #pragma omp dispatch novariants(a > 5)
+/// \endcode
+/// In this example directive '#pragma omp dispatch' has simple 'novariants'
+/// clause with condition 'a > 5'.
+class OMPNovariantsClause final : public OMPClause,
+  public OMPClauseWithPreInit {
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Condition of the 'if' clause.
+  Stmt *Condition = nullptr;
+
+  /// Set condition.
+  void setCondition(Expr *Cond) { Condition = Cond; }
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+public:
+  /// Build 'novariants' clause with condition \a Cond.
+  ///
+  /// \param Cond Condition of the clause.
+  /// \param HelperCond Helper condition for the construct.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPNovariantsClause(Expr *Cond, Stmt *HelperCond,
+  OpenMPDirectiveKind CaptureRegion,
+  SourceLocation StartLoc, SourceLocation LParenLoc,
+  SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_novariants, StartLoc, EndLoc),
+OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) {
+setPreInitStmt(HelperCond, CaptureRegion);
+  }
+
+  /// Build an empty clause.
+  OMPNovariantsClause()
+  : OMPClause(llvm::omp::OMPC_novariants, SourceLocation(),
+  SourceLocation()),
+OMPClauseWithPreInit(this) {}
+
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns condition.
+  Expr *getCondition() const { return cast_or_null(Condition); }
+
+  child_range children() { return child_range(,  + 1); }
+
+  const_child_range children() const {
+return const_child_range(,  + 1);
+  }
+
+  child_range used_children();
+  const_child_range used_children() const {
+auto Children = const_cast(this)->used_children();
+return const_child_range(Children.begin(), Children.end());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_novariants;
+  }
+};
+
 /// This represents 'detach' clause in the '#pragma omp task' directive.
 ///
 /// \code

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 23864819bc07..cdedbe22f9ed 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3218,6 +3218,14 @@ bool 
RecursiveASTVisitor::VisitOMPDestroyClause(OMPDestroyClause *C) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPNovariantsClause(
+OMPNovariantsClause *C) {
+  TRY_TO(VisitOMPClauseWithPreInit(C));
+  TRY_TO(TraverseStmt(C->getCondition()));
+  return true;
+}
+
 template 
 template 
 bool RecursiveASTVisitor::VisitOMPClauseList(T *Node) {

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b5c8d3d292fc..5f514d5f6a1d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11017,7 +11017,11 @@ class Sema final {
   SourceLocation LParenLoc,

[clang] f8d5b49 - Fix missing error for use of 128-bit integer inside SPIR64 device code.

2020-12-07 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2020-12-07T10:42:32-08:00
New Revision: f8d5b49c786f5766aa89b59606bd4c4ae10b46f6

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

LOG: Fix missing error for use of 128-bit integer inside SPIR64 device code.
Emit error for use of 128-bit integer inside device code had been
already implemented in https://reviews.llvm.org/D74387.  However,
the error is not emitted for SPIR64, because for SPIR64, hasInt128Type
return true.

hasInt128Type: is also used to control generation of certain 128-bit
predefined macros, initializer predefined 128-bit integer types and
build 128-bit ArithmeticTypes.  Except predefined macros, only the
device target is considered, since error only emit when 128-bit
integer is used inside device code, the host target (auxtarget) also
needs to be considered.

The change address:
1. (SPIR.h) Correct hasInt128Type() for SPIR targets.
2. Sema.cpp and SemaOverload.cpp: Add additional check to consider host
   target(auxtarget) when call to hasInt128Type.  So that __int128_t
   and __int128() are allowed to avoid error when they used outside
   device code.
3. SemaType.cpp: add check for SYCLIsDevice to delay the error message.
   The error will be emitted if the use of 128-bit integer in the device
   code.

   Reviewed By: Johannes Doerfert and Aaron Ballman

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

Added: 
clang/test/SemaSYCL/int128.cpp

Modified: 
clang/lib/Basic/Targets/SPIR.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGen/ext-int-cc.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index 6473138982c1..130ce1872dce 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -104,6 +104,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public 
TargetInfo {
   }
 
   bool hasExtIntType() const override { return true; }
+
+  bool hasInt128Type() const override { return false; }
 };
 class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
 public:

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 3901c5e1fec8..b99dc33d8748 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -236,7 +236,9 @@ void Sema::Initialize() {
 return;
 
   // Initialize predefined 128-bit integer types, if needed.
-  if (Context.getTargetInfo().hasInt128Type()) {
+  if (Context.getTargetInfo().hasInt128Type() ||
+  (Context.getAuxTargetInfo() &&
+   Context.getAuxTargetInfo()->hasInt128Type())) {
 // If either of the 128-bit integer types are unavailable to name lookup,
 // define them now.
 DeclarationName Int128 = ("__int128_t");

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 02638beb6627..ff010fd6e4df 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -8187,12 +8187,16 @@ class BuiltinOperatorOverloadBuilder {
 ArithmeticTypes.push_back(S.Context.IntTy);
 ArithmeticTypes.push_back(S.Context.LongTy);
 ArithmeticTypes.push_back(S.Context.LongLongTy);
-if (S.Context.getTargetInfo().hasInt128Type())
+if (S.Context.getTargetInfo().hasInt128Type() ||
+(S.Context.getAuxTargetInfo() &&
+ S.Context.getAuxTargetInfo()->hasInt128Type()))
   ArithmeticTypes.push_back(S.Context.Int128Ty);
 ArithmeticTypes.push_back(S.Context.UnsignedIntTy);
 ArithmeticTypes.push_back(S.Context.UnsignedLongTy);
 ArithmeticTypes.push_back(S.Context.UnsignedLongLongTy);
-if (S.Context.getTargetInfo().hasInt128Type())
+if (S.Context.getTargetInfo().hasInt128Type() ||
+(S.Context.getAuxTargetInfo() &&
+ S.Context.getAuxTargetInfo()->hasInt128Type()))
   ArithmeticTypes.push_back(S.Context.UnsignedInt128Ty);
 LastPromotedIntegralType = ArithmeticTypes.size();
 LastPromotedArithmeticType = ArithmeticTypes.size();

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index a8ba0643d41d..0d80bce10ffd 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1515,6 +1515,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState 
) {
   }
   case DeclSpec::TST_int128:
 if (!S.Context.getTargetInfo().hasInt128Type() &&
+!S.getLangOpts().SYCLIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__int128";

diff  --git a/clang/test/CodeGen/ext-int-cc.c b/clang/test/CodeGen/ext-int-cc.c
index 02e2f3aef274..dd21845592a8 100644
--- a/clang/test/CodeGen/ext-int-cc.c
+++ b/clang/test/CodeGen/ext-int-cc.c
@@ -43,7 +43,7 @@ void ParamPassing(_ExtInt(129) 

[clang] 6cf0dac - orrectly generate invert xor value for Binary Atomics of int size > 64

2020-07-07 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2020-07-07T10:20:14-07:00
New Revision: 6cf0dac1ca3fd56c51f6a60f0be01cc25a1a2c6a

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

LOG: orrectly generate invert xor value for Binary Atomics of int size > 64

When using __sync_nand_and_fetch with __int128, a problem is found that
the wrong value for the 'invert' value gets emitted to the xor in case
where the int size is greater than 64 bits.

This is because uses of llvm::ConstantInt::get which zero extends the
greater than 64 bits, so instead -1 that we require, it end up
getting 18446744073709551615

This patch replaces the call to llvm::ConstantInt::get with the call
to llvm::Constant::getAllOnesValue which works for all integer types.

Reviewers: jfp, erichkeane, rjmccall, hfinkel

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/Atomics.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 91969267cdb9..1d81ede5dc31 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -219,8 +219,9 @@ static RValue EmitBinaryAtomicPost(CodeGenFunction ,
   Kind, Args[0], Args[1], llvm::AtomicOrdering::SequentiallyConsistent);
   Result = CGF.Builder.CreateBinOp(Op, Result, Args[1]);
   if (Invert)
-Result = CGF.Builder.CreateBinOp(llvm::Instruction::Xor, Result,
- llvm::ConstantInt::get(IntType, -1));
+Result =
+CGF.Builder.CreateBinOp(llvm::Instruction::Xor, Result,
+llvm::ConstantInt::getAllOnesValue(IntType));
   Result = EmitFromInt(CGF, Result, T, ValueType);
   return RValue::get(Result);
 }

diff  --git a/clang/test/CodeGen/Atomics.c b/clang/test/CodeGen/Atomics.c
index d960ac6df2f9..ebc9c139775a 100644
--- a/clang/test/CodeGen/Atomics.c
+++ b/clang/test/CodeGen/Atomics.c
@@ -10,6 +10,8 @@ signed int si;
 unsigned int ui;
 signed long long sll;
 unsigned long long ull;
+__int128 s128;
+unsigned  __int128 u128;
 
 void test_op_ignore (void) // CHECK-LABEL: define void @test_op_ignore
 {
@@ -48,6 +50,8 @@ void test_op_ignore (void) // CHECK-LABEL: define void 
@test_op_ignore
   (void) __sync_fetch_and_xor (, 1); // CHECK: atomicrmw xor i32
   (void) __sync_fetch_and_xor (, 1); // CHECK: atomicrmw xor i64
   (void) __sync_fetch_and_xor (, 1); // CHECK: atomicrmw xor i64
+  (void) __sync_fetch_and_xor (, 1); // CHECK: atomicrmw xor i128
+  (void) __sync_fetch_and_xor (, 1); // CHECK: atomicrmw xor i128
 
   (void) __sync_fetch_and_nand (, 1); // CHECK: atomicrmw nand i8
   (void) __sync_fetch_and_nand (, 1); // CHECK: atomicrmw nand i8
@@ -168,27 +172,43 @@ void test_op_and_fetch (void)
   sc = __sync_nand_and_fetch (, uc); // CHECK: atomicrmw nand
 // CHECK: and
 // CHECK: xor
+// CHECK: -1
   uc = __sync_nand_and_fetch (, uc); // CHECK: atomicrmw nand
 // CHECK: and
 // CHECK: xor
+// CHECK: -1
   ss = __sync_nand_and_fetch (, uc); // CHECK: atomicrmw nand
 // CHECK: and
 // CHECK: xor
+// CHECK: -1
   us = __sync_nand_and_fetch (, uc); // CHECK: atomicrmw nand
 // CHECK: and
 // CHECK: xor
+// CHECK: -1
   si = __sync_nand_and_fetch (, uc); // CHECK: atomicrmw nand
 // CHECK: and
 // CHECK: xor
+// CHECK: -1
   ui = __sync_nand_and_fetch (, uc); // CHECK: atomicrmw nand
 // CHECK: and
 // CHECK: xor
+// CHECK: -1
   sll = __sync_nand_and_fetch (, uc); // CHECK: atomicrmw nand
   // CHECK: and
   // CHECK: xor
+  // CHECK: -1
   ull = __sync_nand_and_fetch (, uc); // CHECK: atomicrmw nand
   // CHECK: and
   // CHECK: xor
+  // CHECK: -1
+  u128 = __sync_nand_and_fetch (, uc); // CHECK: atomicrmw nand
+  // CHECK: and
+  // CHECK: xor
+

r362410 - Re-check in clang support gun asm goto after fixing tests.

2019-06-03 Thread Jennifer Yu via cfe-commits
Author: jyu2
Date: Mon Jun  3 08:57:25 2019
New Revision: 362410

URL: http://llvm.org/viewvc/llvm-project?rev=362410=rev
Log:
Re-check in clang support gun asm goto after fixing tests.

Added:
cfe/trunk/test/Analysis/asm-goto.cpp
cfe/trunk/test/CodeGen/asm-goto.c
cfe/trunk/test/Parser/asm-goto.c
cfe/trunk/test/Parser/asm-goto.cpp
cfe/trunk/test/Sema/asm-goto.cpp
Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Stmt.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/Parse/ParseStmtAsm.cpp
cfe/trunk/lib/Sema/JumpDiagnostics.cpp
cfe/trunk/lib/Sema/SemaStmtAsm.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/CodeGen/asm.c
cfe/trunk/test/CodeGen/inline-asm-mixed-style.c
cfe/trunk/test/Coverage/c-language-features.inc
cfe/trunk/test/PCH/asm.h
cfe/trunk/test/Sema/asm.c
cfe/trunk/test/Sema/inline-asm-validate-tmpl.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=362410=362409=362410=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Mon Jun  3 08:57:25 2019
@@ -46,6 +46,7 @@ class Attr;
 class CapturedDecl;
 class Decl;
 class Expr;
+class AddrLabelExpr;
 class LabelDecl;
 class ODRHash;
 class PrinterHelper;
@@ -2816,13 +2817,15 @@ class GCCAsmStmt : public AsmStmt {
   StringLiteral **Constraints = nullptr;
   StringLiteral **Clobbers = nullptr;
   IdentifierInfo **Names = nullptr;
+  unsigned NumLabels = 0;
 
 public:
   GCCAsmStmt(const ASTContext , SourceLocation asmloc, bool issimple,
  bool isvolatile, unsigned numoutputs, unsigned numinputs,
  IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
  StringLiteral *asmstr, unsigned numclobbers,
- StringLiteral **clobbers, SourceLocation rparenloc);
+ StringLiteral **clobbers, unsigned numlabels,
+ SourceLocation rparenloc);
 
   /// Build an empty inline-assembly statement.
   explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
@@ -2947,6 +2950,51 @@ public:
 return const_cast(this)->getInputExpr(i);
   }
 
+  //===--- Labels ---===//
+
+  bool isAsmGoto() const {
+return NumLabels > 0;
+  }
+
+  unsigned getNumLabels() const {
+return NumLabels;
+  }
+
+  IdentifierInfo *getLabelIdentifier(unsigned i) const {
+return Names[i + NumInputs];
+  }
+
+  AddrLabelExpr *getLabelExpr(unsigned i) const;
+  StringRef getLabelName(unsigned i) const;
+  using labels_iterator = CastIterator;
+  using const_labels_iterator = ConstCastIterator;
+  using labels_range = llvm::iterator_range;
+  using labels_const_range = llvm::iterator_range;
+
+  labels_iterator begin_labels() {
+return [0] + NumInputs;
+  }
+
+  labels_iterator end_labels() {
+return [0] + NumInputs + NumLabels;
+  }
+
+  labels_range labels() {
+return labels_range(begin_labels(), end_labels());
+  }
+
+  const_labels_iterator begin_labels() const {
+return [0] + NumInputs;
+  }
+
+  const_labels_iterator end_labels() const {
+return [0] + NumInputs + NumLabels;
+  }
+
+  labels_const_range labels() const {
+return labels_const_range(begin_labels(), end_labels());
+  }
+
 private:
   void setOutputsAndInputsAndClobbers(const ASTContext ,
   IdentifierInfo **Names,
@@ -2954,6 +3002,7 @@ private:
   Stmt **Exprs,
   unsigned NumOutputs,
   unsigned NumInputs,
+  unsigned NumLabels,
   StringLiteral **Clobbers,
   unsigned NumClobbers);
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=362410=362409=362410=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Mon Jun  3 08:57:25 
2019
@@ -27,8 +27,8 @@ def err_msasm_unable_to_create_target :
   "MS-style inline assembly is not available: %0">;
 def err_gnu_inline_asm_disabled : Error<
   "GNU-style inline assembly is disabled">;
-def err_asm_goto_not_supported_yet : Error<
-  "'asm goto' constructs are not 

r362045 - clang support gnu asm goto.

2019-05-29 Thread Jennifer Yu via cfe-commits
Author: jyu2
Date: Wed May 29 18:05:46 2019
New Revision: 362045

URL: http://llvm.org/viewvc/llvm-project?rev=362045=rev
Log:
clang support gnu asm goto.
Syntax:
  asm [volatile] goto ( AssemblerTemplate
  :
  : InputOperands
  : Clobbers
  : GotoLabels)

https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

New llvm IR is "callbr" for inline asm goto instead "call" for inline asm
For:
asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop);
IR:
callbr void asm sideeffect "testl $0, $0; jne ${1:l};", 
"r,X,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@foo, 
%label_true), i8* blockaddress(@foo, %loop)) #1
  to label %asm.fallthrough [label %label_true, label %loop], !srcloc !3

asm.fallthrough:

Compiler need to generate:
1> a dummy constarint 'X' for each label.
2> an unique fallthrough label for each asm goto stmt " asm.fallthrough%number".


Diagnostic 
1>  duplicate asm operand name are used in output, input and label.
2>  goto out of scope.


Added:
cfe/trunk/test/Analysis/asm-goto.cpp
cfe/trunk/test/CodeGen/asm-goto.c
cfe/trunk/test/Sema/asm-goto.cpp
Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Stmt.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/Parse/ParseStmtAsm.cpp
cfe/trunk/lib/Sema/JumpDiagnostics.cpp
cfe/trunk/lib/Sema/SemaStmtAsm.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/CodeGen/asm.c
cfe/trunk/test/CodeGen/inline-asm-mixed-style.c
cfe/trunk/test/Coverage/c-language-features.inc
cfe/trunk/test/PCH/asm.h
cfe/trunk/test/Parser/asm.c
cfe/trunk/test/Parser/asm.cpp
cfe/trunk/test/Sema/asm.c
cfe/trunk/test/Sema/inline-asm-validate-tmpl.cpp
cfe/trunk/test/Sema/scope-check.c

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=362045=362044=362045=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed May 29 18:05:46 2019
@@ -46,6 +46,7 @@ class Attr;
 class CapturedDecl;
 class Decl;
 class Expr;
+class AddrLabelExpr;
 class LabelDecl;
 class ODRHash;
 class PrinterHelper;
@@ -2816,13 +2817,15 @@ class GCCAsmStmt : public AsmStmt {
   StringLiteral **Constraints = nullptr;
   StringLiteral **Clobbers = nullptr;
   IdentifierInfo **Names = nullptr;
+  unsigned NumLabels = 0;
 
 public:
   GCCAsmStmt(const ASTContext , SourceLocation asmloc, bool issimple,
  bool isvolatile, unsigned numoutputs, unsigned numinputs,
  IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
  StringLiteral *asmstr, unsigned numclobbers,
- StringLiteral **clobbers, SourceLocation rparenloc);
+ StringLiteral **clobbers, unsigned numlabels,
+ SourceLocation rparenloc);
 
   /// Build an empty inline-assembly statement.
   explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
@@ -2947,6 +2950,51 @@ public:
 return const_cast(this)->getInputExpr(i);
   }
 
+  //===--- Labels ---===//
+
+  bool isAsmGoto() const {
+return NumLabels > 0;
+  }
+
+  unsigned getNumLabels() const {
+return NumLabels;
+  }
+
+  IdentifierInfo *getLabelIdentifier(unsigned i) const {
+return Names[i + NumInputs];
+  }
+
+  AddrLabelExpr *getLabelExpr(unsigned i) const;
+  StringRef getLabelName(unsigned i) const;
+  using labels_iterator = CastIterator;
+  using const_labels_iterator = ConstCastIterator;
+  using labels_range = llvm::iterator_range;
+  using labels_const_range = llvm::iterator_range;
+
+  labels_iterator begin_labels() {
+return [0] + NumInputs;
+  }
+
+  labels_iterator end_labels() {
+return [0] + NumInputs + NumLabels;
+  }
+
+  labels_range labels() {
+return labels_range(begin_labels(), end_labels());
+  }
+
+  const_labels_iterator begin_labels() const {
+return [0] + NumInputs;
+  }
+
+  const_labels_iterator end_labels() const {
+return [0] + NumInputs + NumLabels;
+  }
+
+  labels_const_range labels() const {
+return labels_const_range(begin_labels(), end_labels());
+  }
+
 private:
   void setOutputsAndInputsAndClobbers(const ASTContext ,
   IdentifierInfo **Names,
@@ -2954,6 +3002,7 @@ private:
   Stmt **Exprs,
   unsigned 

r359212 - Fix bug 37903:MS ABI: handle inline static data member and inline variable as template static data member

2019-04-25 Thread Jennifer Yu via cfe-commits
Author: jyu2
Date: Thu Apr 25 10:45:45 2019
New Revision: 359212

URL: http://llvm.org/viewvc/llvm-project?rev=359212=rev
Log:
Fix bug 37903:MS ABI: handle inline static data member and inline variable as 
template static data member

Added:
cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
Modified:
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/test/Modules/initializers.cpp

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=359212=359211=359212=diff
==
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Thu Apr 25 10:45:45 2019
@@ -467,7 +467,8 @@ CodeGenModule::EmitCXXGlobalVarDeclInitF
   } else if (auto *IPA = D->getAttr()) {
 OrderGlobalInits Key(IPA->getPriority(), PrioritizedCXXGlobalInits.size());
 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
-  } else if (isTemplateInstantiation(D->getTemplateSpecializationKind())) {
+  } else if (isTemplateInstantiation(D->getTemplateSpecializationKind()) ||
+ getContext().GetGVALinkageForVariable(D) == GVA_DiscardableODR) {
 // C++ [basic.start.init]p2:
 //   Definitions of explicitly specialized class template static data
 //   members have ordered initialization. Other class template static data
@@ -481,6 +482,11 @@ CodeGenModule::EmitCXXGlobalVarDeclInitF
 // minor startup time optimization.  In the MS C++ ABI, there are no guard
 // variables, so this COMDAT key is required for correctness.
 AddGlobalCtor(Fn, 65535, COMDATKey);
+if (getTarget().getCXXABI().isMicrosoft() && COMDATKey) {
+  // In The MS C++, MS add template static data member in the linker
+  // drective.
+  addUsedGlobal(COMDATKey);
+}
   } else if (D->hasAttr()) {
 // SelectAny globals will be comdat-folded. Put the initializer into a
 // COMDAT group associated with the global, so the initializers get folded

Added: cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp?rev=359212=auto
==
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp Thu Apr 25 
10:45:45 2019
@@ -0,0 +1,92 @@
+// RUN: %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-pc-win32 -fms-extensions -emit-llvm -o - 
| FileCheck %s
+// RUN: %clang_cc1 %s -triple=i686-pc-windows-msvc -fms-extensions -emit-llvm 
-o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-pc-windows-msvc  -fms-extensions 
-emit-llvm -o - | FileCheck %s
+
+struct S {
+  S();
+  ~S();
+};
+
+template  struct __declspec(dllexport) ExportedTemplate {
+  static S s;
+};
+template  S ExportedTemplate::s;
+void useExportedTemplate(ExportedTemplate x) {
+  (void)x.s;
+}
+int f();
+namespace selectany_init {
+// MS don't put selectany static var in the linker directive, init routine
+// f() is not getting called if x is not referenced.
+int __declspec(selectany) x = f();
+inline int __declspec(selectany) x1 = f();
+}
+
+namespace explicit_template_instantiation {
+template  struct A { static  int x; };
+template  int A::x = f();
+template struct A;
+}
+
+namespace implicit_template_instantiation {
+template  struct A { static  int x; };
+template   int A::x = f();
+int g() { return A::x; }
+}
+
+
+template 
+struct X_ {
+  static T ioo;
+  static T init();
+};
+template  T X_::ioo = X_::init();
+template struct X_;
+
+template 
+struct X {
+  static T ioo;
+  static T init();
+};
+// template specialized static data don't need in llvm.used,
+// the static init routine get call from _GLOBAL__sub_I_ routines.
+template <> int X::ioo = X::init();
+template struct X;
+class a {
+public:
+  a();
+};
+// For the static var inside unnamed namespace, the object is local to TU.
+// No need to put static var in the linker directive.
+// The static init routine is called before main.
+namespace {
+template  class aj {
+public:
+  static a al;
+};
+template  a aj::al;
+class b : aj<3> {
+  void c();
+};
+void b::c() { al; }
+}
+
+// C++17, inline static data member also need to use
+struct A
+{
+  A();
+  ~A();
+};
+
+struct S1
+{
+  inline static A aoo; // C++17 inline variable, thus also a definition
+};
+
+int foo();
+inline int zoo = foo();
+inline static int boo = foo();
+
+
+// CHECK: @llvm.used = appending global [7 x i8*] [i8* bitcast (i32* 
@"?x1@selectany_init@@3HA" to i8*), i8* bitcast (i32* 
@"?x@?$A@H@explicit_template_instantiation@@2HA" to i8*), i8* bitcast (i32* 
@"?ioo@?$X_@H@@2HA" to i8*), i8* getelementptr inbounds (%struct.A, %struct.A* 
@"?aoo@S1@@2UA@@A", i32 0, i32 0), i8* bitcast (i32* 

r357610 - Bug-40323: MS ABI adding template static member in the linker directive section to make sure init function can be called before main.

2019-04-03 Thread Jennifer Yu via cfe-commits
Author: jyu2
Date: Wed Apr  3 10:21:40 2019
New Revision: 357610

URL: http://llvm.org/viewvc/llvm-project?rev=357610=rev
Log:
Bug-40323: MS ABI adding template static member in the linker directive section 
to make sure init function can be called before main.

Added:
cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
Modified:
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=357610=357609=357610=diff
==
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Wed Apr  3 10:21:40 2019
@@ -481,6 +481,12 @@ CodeGenModule::EmitCXXGlobalVarDeclInitF
 // minor startup time optimization.  In the MS C++ ABI, there are no guard
 // variables, so this COMDAT key is required for correctness.
 AddGlobalCtor(Fn, 65535, COMDATKey);
+if (getTarget().getCXXABI().isMicrosoft()) {
+  // In The MS C++, MS add template static data member in the linker
+  // drective.
+  assert(COMDATKey);
+  addUsedGlobal(COMDATKey);
+}
   } else if (D->hasAttr()) {
 // SelectAny globals will be comdat-folded. Put the initializer into a
 // COMDAT group associated with the global, so the initializers get folded

Added: cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp?rev=357610=auto
==
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp Wed Apr  3 
10:21:40 2019
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-pc-win32 -fms-extensions -emit-llvm -o - 
| FileCheck %s
+// RUN: %clang_cc1 %s -triple=i686-pc-windows-msvc -fms-extensions -emit-llvm 
-o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-pc-windows-msvc -fms-extensions 
-emit-llvm -o - | FileCheck %s
+
+struct S {
+  S();
+  ~S();
+};
+
+template  struct __declspec(dllexport) ExportedTemplate {
+  static S s;
+};
+template  S ExportedTemplate::s;
+void useExportedTemplate(ExportedTemplate x) {
+  (void)x.s;
+}
+int f();
+namespace selectany_init {
+// MS don't put selectany static var in the linker directive, init routine
+// f() is not getting called if x is not referenced.
+int __declspec(selectany) x = f();
+}
+
+namespace explicit_template_instantiation {
+template  struct A { static  int x; };
+template  int A::x = f();
+template struct A;
+}
+
+namespace implicit_template_instantiation {
+template  struct A { static  int x; };
+template   int A::x = f();
+int g() { return A::x; }
+}
+
+
+template 
+struct X_ {
+  static T ioo;
+  static T init();
+};
+template  T X_::ioo = X_::init();
+template struct X_;
+
+template 
+struct X {
+  static T ioo;
+  static T init();
+};
+// template specialized static data don't need in llvm.used,
+// the static init routine get call from _GLOBAL__sub_I_ routines.
+template <> int X::ioo = X::init();
+template struct X;
+// CHECK: @llvm.global_ctors = appending global [6 x { i32, void ()*, i8* }] 
[{ i32, void ()*, i8* } { i32 65535, void ()* @"??__Ex@selectany_init@@YAXXZ", 
i8* bitcast (i32* @"?x@selectany_init@@3HA" to i8*) }, { i32, void ()*, i8* } { 
i32 65535, void ()* 
@"??__E?x@?$A@H@explicit_template_instantiation@@2HA@@YAXXZ", i8* bitcast (i32* 
@"?x@?$A@H@explicit_template_instantiation@@2HA" to i8*) }, { i32, void ()*, 
i8* } { i32 65535, void ()* @"??__E?ioo@?$X_@H@@2HA@@YAXXZ", i8* bitcast (i32* 
@"?ioo@?$X_@H@@2HA" to i8*) }, { i32, void ()*, i8* } { i32 65535, void ()* 
@"??__E?s@?$ExportedTemplate@H@@2US@@A@@YAXXZ", i8* getelementptr inbounds 
(%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0) }, { 
i32, void ()*, i8* } { i32 65535, void ()* 
@"??__E?x@?$A@H@implicit_template_instantiation@@2HA@@YAXXZ", i8* bitcast (i32* 
@"?x@?$A@H@implicit_template_instantiation@@2HA" to i8*) }, { i32, void ()*, 
i8* } { i32 65535, void ()* 
@_GLOBAL__sub_I_microsoft_abi_template_static_init.cpp, i8* null }]
+// CHECK: @llvm.used = appending global [4 x i8*] [i8* bitcast (i32* 
@"?x@?$A@H@explicit_template_instantiation@@2HA" to i8*), i8* bitcast (i32* 
@"?ioo@?$X_@H@@2HA" to i8*), i8* getelementptr inbounds (%struct.S, %struct.S* 
@"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0), i8* bitcast (i32* 
@"?x@?$A@H@implicit_template_instantiation@@2HA" to i8*)], section 
"llvm.metadata"
+


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


r356628 - Remove extra white spaces

2019-03-20 Thread Jennifer Yu via cfe-commits
Author: jyu2
Date: Wed Mar 20 16:05:18 2019
New Revision: 356628

URL: http://llvm.org/viewvc/llvm-project?rev=356628=rev
Log:
Remove extra white spaces

Modified:
cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp?rev=356628=356627=356628=diff
==
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp Wed Mar 20 16:05:18 
2019
@@ -293,7 +293,7 @@ struct class_0 : class_1 {
 };
 
 class_0::class_0() {
-  // WIN32: define dso_local x86_thiscallcc %struct.class_0* 
@"??0class_0@@QAE@XZ"(%struct.class_0* returned %this, i32 %is_most_derived) 
+  // WIN32: define dso_local x86_thiscallcc %struct.class_0* 
@"??0class_0@@QAE@XZ"(%struct.class_0* returned %this, i32 %is_most_derived)
   // WIN32: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], 
align 4
   // WIN32: %[[IS_MOST_DERIVED_VAL:.*]] = load i32, i32* 
%[[IS_MOST_DERIVED_VAR]]
   // WIN32: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 
%[[IS_MOST_DERIVED_VAL]], 0
@@ -304,7 +304,7 @@ class_0::class_0() {
 // ehcleanup:
   // WIN32: %[[CLEANUPPAD:.*]] = cleanuppad within none []
   // WIN32-NEXT: bitcast %{{.*}}* %{{.*}} to i8*
-  // WIN32-NEXT: getelementptr inbounds i8, i8* %{{.*}}, i{{.*}} {{.}} 
+  // WIN32-NEXT: getelementptr inbounds i8, i8* %{{.*}}, i{{.*}} {{.}}
   // WIN32-NEXT: bitcast i8* %{{.*}} to %{{.*}}*
   // WIN32-NEXT: %[[SHOULD_CALL_VBASE_DTOR:.*]] = icmp ne i32 
%[[IS_MOST_DERIVED_VAL]], 0
   // WIN32-NEXT: br i1 %[[SHOULD_CALL_VBASE_DTOR]], label %[[DTOR_VBASE:.*]], 
label %[[SKIP_VBASE:.*]]


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