summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2019-10-25 16:35:32 -0400
committerAlexey Bataev <a.bataev@hotmail.com>2019-10-28 13:29:02 -0400
commit7c860698208aee32df1883601b94924fa4a3d531 (patch)
tree32fff89a522d03650e005445be26a37b3dc42513
parent80cb2cecc65753aa1de09a09f3750408913f6450 (diff)
downloadbcm5719-llvm-7c860698208aee32df1883601b94924fa4a3d531.tar.gz
bcm5719-llvm-7c860698208aee32df1883601b94924fa4a3d531.zip
[OPENMP]Fix PR43771: Do not capture contexprs variables.
If the variable is a constexpr variable, it should not be captured in the OpenMP region.
-rw-r--r--clang/lib/Sema/SemaOpenMP.cpp6
-rw-r--r--clang/test/OpenMP/constexpr_capture.cpp21
2 files changed, 26 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index c7e0d2aee03..8b1fca89dee 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -1894,6 +1894,11 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo,
assert(LangOpts.OpenMP && "OpenMP is not allowed");
D = getCanonicalDecl(D);
+ auto *VD = dyn_cast<VarDecl>(D);
+ // Do not capture constexpr variables.
+ if (VD && VD->isConstexpr())
+ return nullptr;
+
// If we want to determine whether the variable should be captured from the
// perspective of the current capturing scope, and we've already left all the
// capturing scopes of the top directive on the stack, check from the
@@ -1904,7 +1909,6 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo,
// If we are attempting to capture a global variable in a directive with
// 'target' we return true so that this global is also mapped to the device.
//
- auto *VD = dyn_cast<VarDecl>(D);
if (VD && !VD->hasLocalStorage() &&
(getCurCapturedRegion() || getCurBlock() || getCurLambda())) {
if (isInOpenMPDeclareTargetContext()) {
diff --git a/clang/test/OpenMP/constexpr_capture.cpp b/clang/test/OpenMP/constexpr_capture.cpp
new file mode 100644
index 00000000000..9577f6e0c0f
--- /dev/null
+++ b/clang/test/OpenMP/constexpr_capture.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-linux -S -emit-llvm %s -o - -std=c++11 2>&1 | FileCheck %s
+// expected-no-diagnostics
+
+template <int __v> struct integral_constant {
+ static constexpr int value = __v;
+};
+
+template <typename _Tp, int v = 0, bool _IsArray = integral_constant<v>::value>
+struct decay {
+ typedef int type;
+};
+struct V {
+ template <typename TArg0 = int, typename = typename decay<TArg0>::type> V();
+};
+int main() {
+#pragma omp target
+ V v;
+ return 0;
+}
+
+// CHECK: call void @__omp_offloading_{{.+}}_main_l16()
OpenPOWER on IntegriCloud