diff options
| author | Alexey Bataev <a.bataev@hotmail.com> | 2017-11-02 18:55:05 +0000 |
|---|---|---|
| committer | Alexey Bataev <a.bataev@hotmail.com> | 2017-11-02 18:55:05 +0000 |
| commit | 5d2c9a46fc3a9eeaede74ec89bdc1392eff09638 (patch) | |
| tree | 1fb3c0587d04e73e19c464ccaf2e74b6c7b460e2 | |
| parent | fb7bf1d7f263fea43212ae283b52fd9432402185 (diff) | |
| download | bcm5719-llvm-5d2c9a46fc3a9eeaede74ec89bdc1392eff09638.tar.gz bcm5719-llvm-5d2c9a46fc3a9eeaede74ec89bdc1392eff09638.zip | |
[OPENMP] Fix PR35152: Do not use getInvokeDest() function for EH checks.
The compiler may crash under some conditions if the getInvokeDest() is
used, but later it is not used. Fixed this problem in OpenMP.
llvm-svn: 317227
| -rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 3 | ||||
| -rw-r--r-- | clang/test/OpenMP/openmp_win_codegen.cpp | 35 |
2 files changed, 31 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 779617adc21..ce7fe9364b9 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1451,7 +1451,8 @@ llvm::Value *CGOpenMPRuntime::getThreadID(CodeGenFunction &CGF, return ThreadID; } // If exceptions are enabled, do not use parameter to avoid possible crash. - if (!CGF.getInvokeDest() || + if (!CGF.EHStack.requiresLandingPad() || !CGF.getLangOpts().Exceptions || + !CGF.getLangOpts().CXXExceptions || CGF.Builder.GetInsertBlock() == CGF.AllocaInsertPt->getParent()) { if (auto *OMPRegionInfo = dyn_cast_or_null<CGOpenMPRegionInfo>(CGF.CapturedStmtInfo)) { diff --git a/clang/test/OpenMP/openmp_win_codegen.cpp b/clang/test/OpenMP/openmp_win_codegen.cpp index cdad7e29ccb..45b2c185cb8 100644 --- a/clang/test/OpenMP/openmp_win_codegen.cpp +++ b/clang/test/OpenMP/openmp_win_codegen.cpp @@ -1,13 +1,36 @@ -// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-pc-windows-msvc18.0.0 -std=c++11 -fms-compatibility-version=18 -fms-extensions -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s +// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-pc-windows-msvc18.0.0 -std=c++11 -fms-compatibility-version=18 -fms-extensions -emit-llvm %s -fexceptions -fcxx-exceptions -o - -O1 | FileCheck %s // REQUIRES: x86-registered-target // expected-no-diagnostics void foo(); void bar(); +struct Test { + static void main() { + int failed = 0; + int j = 2; + +#pragma omp parallel + { + int local_j = 3; +#pragma omp single copyprivate(local_j) + { + local_j = 4; + } + + // Assure reports a data race, but value written to "j" + // should always be the same. + j = local_j; + } + + } +}; + // CHECK-LABEL: @main int main() { - // CHECK: call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%ident_t* @0, i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OUTLINED:@.+]] to void (i32*, i32*, ...)*)) + // CHECK: call void @{{.+}}main + Test::main(); + // CHECK: call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%ident_t* {{.*}}@0, i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OUTLINED:@.+]] to void (i32*, i32*, ...)*)) #pragma omp parallel { try { @@ -24,15 +47,15 @@ int main() { } // CHECK: define internal void [[OUTLINED]]( -// CHECK: [[GID:%.+]] = call i32 @__kmpc_global_thread_num(%ident_t* @0) +// CHECK: [[GID:%.+]] = {{.*}}call i32 @__kmpc_global_thread_num(%ident_t* {{.*}}@0) // CHECK: invoke void @{{.+}}foo // CHECK: catchswitch within // CHECK: catchpad within -// CHECK: call void @__kmpc_critical(%ident_t* @0, i32 [[GID]], +// CHECK: call void @__kmpc_critical(%ident_t* {{.*}}@0, i32 [[GID]], // CHECK: invoke void @{{.+}}bar -// CHECK: call void @__kmpc_end_critical(%ident_t* @0, i32 [[GID]], +// CHECK: call void @__kmpc_end_critical(%ident_t* {{.*}}@0, i32 [[GID]], // CHECK: catchret from // CHECK: cleanuppad within -// CHECK: call void @__kmpc_end_critical(%ident_t* @0, i32 [[GID]], +// CHECK: call void @__kmpc_end_critical(%ident_t* {{.*}}@0, i32 [[GID]], // CHECK: cleanupret from |

