Author: Alexey Bataev Date: 2019-10-28T13:29:02-04:00 New Revision: 7c860698208aee32df1883601b94924fa4a3d531
URL: https://github.com/llvm/llvm-project/commit/7c860698208aee32df1883601b94924fa4a3d531 DIFF: https://github.com/llvm/llvm-project/commit/7c860698208aee32df1883601b94924fa4a3d531.diff LOG: [OPENMP]Fix PR43771: Do not capture contexprs variables. If the variable is a constexpr variable, it should not be captured in the OpenMP region. Added: clang/test/OpenMP/constexpr_capture.cpp Modified: clang/lib/Sema/SemaOpenMP.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index c7e0d2aee036..8b1fca89dee8 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 000000000000..9577f6e0c0fe --- /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() _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits