summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2017-11-02 14:25:34 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2017-11-02 14:25:34 +0000
commite70ad5241cb2dd0fe883ffacdfa8a839fce108ce (patch)
treedb8cd0efb0b5b0e2ef08edf3fb4384c2253336d4
parent8148ea17f5b960f0cb6457b9e4906da119f3b1f8 (diff)
[OPENMP] Fix PR35156: Get correct thread id with windows exceptions.
If the thread id is requested in windows mode within funclets, we may generate incorrect function call that could lead to broken codegen. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317208 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGOpenMPRuntime.cpp14
-rw-r--r--test/OpenMP/critical_codegen.cpp2
-rw-r--r--test/OpenMP/for_codegen.cpp2
-rw-r--r--test/OpenMP/for_simd_codegen.cpp2
-rw-r--r--test/OpenMP/master_codegen.cpp2
-rw-r--r--test/OpenMP/openmp_win_codegen.cpp38
-rw-r--r--test/OpenMP/parallel_for_codegen.cpp2
-rw-r--r--test/OpenMP/parallel_for_simd_codegen.cpp2
-rw-r--r--test/OpenMP/parallel_sections_codegen.cpp2
-rw-r--r--test/OpenMP/sections_codegen.cpp2
-rw-r--r--test/OpenMP/single_codegen.cpp2
-rw-r--r--test/OpenMP/taskgroup_codegen.cpp2
12 files changed, 56 insertions, 16 deletions
diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp
index 35929af95e..779617adc2 100644
--- a/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/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.getInvokeDest() ||
+ CGF.Builder.GetInsertBlock() == CGF.AllocaInsertPt->getParent()) {
if (auto *OMPRegionInfo =
dyn_cast_or_null<CGOpenMPRegionInfo>(CGF.CapturedStmtInfo)) {
if (OMPRegionInfo->getThreadIDVariable()) {
@@ -1475,12 +1476,13 @@ llvm::Value *CGOpenMPRuntime::getThreadID(CodeGenFunction &CGF,
// function.
CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
CGF.Builder.SetInsertPoint(CGF.AllocaInsertPt);
- ThreadID =
- CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_global_thread_num),
- emitUpdateLocation(CGF, Loc));
+ auto *Call = CGF.Builder.CreateCall(
+ createRuntimeFunction(OMPRTL__kmpc_global_thread_num),
+ emitUpdateLocation(CGF, Loc));
+ Call->setCallingConv(CGF.getRuntimeCC());
auto &Elem = OpenMPLocThreadIDMap.FindAndConstruct(CGF.CurFn);
- Elem.second.ThreadID = ThreadID;
- return ThreadID;
+ Elem.second.ThreadID = Call;
+ return Call;
}
void CGOpenMPRuntime::functionFinished(CodeGenFunction &CGF) {
diff --git a/test/OpenMP/critical_codegen.cpp b/test/OpenMP/critical_codegen.cpp
index 964c91f45a..f4e449a223 100644
--- a/test/OpenMP/critical_codegen.cpp
+++ b/test/OpenMP/critical_codegen.cpp
@@ -78,7 +78,7 @@ void critical_ref(S &s) {
void parallel_critical() {
#pragma omp parallel
#pragma omp critical
- // TERM_DEBUG: __kmpc_global_thread_num
+ // TERM_DEBUG-NOT: __kmpc_global_thread_num
// TERM_DEBUG: call void @__kmpc_critical({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
// TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
diff --git a/test/OpenMP/for_codegen.cpp b/test/OpenMP/for_codegen.cpp
index 0d5972f7d0..9ea167fb1f 100644
--- a/test/OpenMP/for_codegen.cpp
+++ b/test/OpenMP/for_codegen.cpp
@@ -355,7 +355,7 @@ int foo() {return 0;};
void parallel_for(float *a) {
#pragma omp parallel
#pragma omp for schedule(static, 5)
- // TERM_DEBUG: __kmpc_global_thread_num
+ // TERM_DEBUG-NOT: __kmpc_global_thread_num
// TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
// TERM_DEBUG: invoke i32 {{.*}}foo{{.*}}()
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
diff --git a/test/OpenMP/for_simd_codegen.cpp b/test/OpenMP/for_simd_codegen.cpp
index e33bfe4a57..89f779db33 100644
--- a/test/OpenMP/for_simd_codegen.cpp
+++ b/test/OpenMP/for_simd_codegen.cpp
@@ -673,7 +673,7 @@ int bar() {return 0;};
void parallel_simd(float *a) {
#pragma omp parallel
#pragma omp for simd
- // TERM_DEBUG: __kmpc_global_thread_num
+ // TERM_DEBUG-NOT: __kmpc_global_thread_num
// TERM_DEBUG: invoke i32 {{.*}}bar{{.*}}()
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
// TERM_DEBUG-NOT: __kmpc_global_thread_num
diff --git a/test/OpenMP/master_codegen.cpp b/test/OpenMP/master_codegen.cpp
index d61b476756..ad92a13e14 100644
--- a/test/OpenMP/master_codegen.cpp
+++ b/test/OpenMP/master_codegen.cpp
@@ -49,7 +49,7 @@ int main() {
void parallel_master() {
#pragma omp parallel
#pragma omp master
- // TERM_DEBUG: __kmpc_global_thread_num
+ // TERM_DEBUG-NOT: __kmpc_global_thread_num
// TERM_DEBUG: call i32 @__kmpc_master({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
// TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
diff --git a/test/OpenMP/openmp_win_codegen.cpp b/test/OpenMP/openmp_win_codegen.cpp
new file mode 100644
index 0000000000..cdad7e29cc
--- /dev/null
+++ b/test/OpenMP/openmp_win_codegen.cpp
@@ -0,0 +1,38 @@
+// 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
+// REQUIRES: x86-registered-target
+// expected-no-diagnostics
+
+void foo();
+void bar();
+
+// 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*, ...)*))
+#pragma omp parallel
+ {
+ try {
+ foo();
+ } catch (int t) {
+#pragma omp critical
+ {
+ bar();
+ };
+ }
+ };
+ // CHECK: ret i32 0
+ return 0;
+}
+
+// CHECK: define internal void [[OUTLINED]](
+// 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: invoke void @{{.+}}bar
+// 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: cleanupret from
+
diff --git a/test/OpenMP/parallel_for_codegen.cpp b/test/OpenMP/parallel_for_codegen.cpp
index bc04532bd1..1773619bce 100644
--- a/test/OpenMP/parallel_for_codegen.cpp
+++ b/test/OpenMP/parallel_for_codegen.cpp
@@ -348,7 +348,7 @@ int foo() {return 0;};
void parallel_for(float *a, int n) {
float arr[n];
#pragma omp parallel for schedule(static, 5) private(arr)
- // TERM_DEBUG: __kmpc_global_thread_num
+ // TERM_DEBUG-NOT: __kmpc_global_thread_num
// TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
// TERM_DEBUG: invoke i32 {{.*}}foo{{.*}}()
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
diff --git a/test/OpenMP/parallel_for_simd_codegen.cpp b/test/OpenMP/parallel_for_simd_codegen.cpp
index 9112635855..369ea17844 100644
--- a/test/OpenMP/parallel_for_simd_codegen.cpp
+++ b/test/OpenMP/parallel_for_simd_codegen.cpp
@@ -668,7 +668,7 @@ int bar() {return 0;};
// TERM_DEBUG-LABEL: parallel_simd
void parallel_simd(float *a) {
#pragma omp parallel for simd
- // TERM_DEBUG: __kmpc_global_thread_num
+ // TERM_DEBUG-NOT: __kmpc_global_thread_num
// TERM_DEBUG: invoke i32 {{.*}}bar{{.*}}()
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
// TERM_DEBUG-NOT: __kmpc_global_thread_num
diff --git a/test/OpenMP/parallel_sections_codegen.cpp b/test/OpenMP/parallel_sections_codegen.cpp
index afbc6e4d5e..a261473036 100644
--- a/test/OpenMP/parallel_sections_codegen.cpp
+++ b/test/OpenMP/parallel_sections_codegen.cpp
@@ -74,7 +74,7 @@ int main() {
// CHECK-LABEL: tmain
// CHECK: call void {{.*}} @__kmpc_fork_call(
-// CHECK: __kmpc_global_thread_num
+// CHECK-NOT: __kmpc_global_thread_num
// CHECK: call void @__kmpc_for_static_init_4(
// CHECK: invoke void @{{.*}}foo{{.*}}()
// CHECK-NEXT: unwind label %[[TERM_LPAD:.+]]
diff --git a/test/OpenMP/sections_codegen.cpp b/test/OpenMP/sections_codegen.cpp
index 0ed87e4035..94ded37db9 100644
--- a/test/OpenMP/sections_codegen.cpp
+++ b/test/OpenMP/sections_codegen.cpp
@@ -84,7 +84,7 @@ int main() {
// CHECK-LABEL: tmain
// CHECK: call void {{.*}} @__kmpc_fork_call(
-// CHECK: __kmpc_global_thread_num
+// CHECK-NOT: __kmpc_global_thread_num
// CHECK: call void @__kmpc_for_static_init_4(
// CHECK: invoke void @{{.*}}foo{{.*}}()
// CHECK-NEXT: unwind label %[[TERM_LPAD:.+]]
diff --git a/test/OpenMP/single_codegen.cpp b/test/OpenMP/single_codegen.cpp
index 4feb3bdac3..892e160324 100644
--- a/test/OpenMP/single_codegen.cpp
+++ b/test/OpenMP/single_codegen.cpp
@@ -190,7 +190,7 @@ int main() {
void parallel_single() {
#pragma omp parallel
#pragma omp single
- // TERM_DEBUG: __kmpc_global_thread_num
+ // TERM_DEBUG-NOT: __kmpc_global_thread_num
// TERM_DEBUG: call i32 @__kmpc_single({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
// TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
diff --git a/test/OpenMP/taskgroup_codegen.cpp b/test/OpenMP/taskgroup_codegen.cpp
index 3dd41a1f82..4b7d89e703 100644
--- a/test/OpenMP/taskgroup_codegen.cpp
+++ b/test/OpenMP/taskgroup_codegen.cpp
@@ -40,7 +40,7 @@ int main() {
void parallel_taskgroup() {
#pragma omp parallel
#pragma omp taskgroup
- // TERM_DEBUG: __kmpc_global_thread_num
+ // TERM_DEBUG-NOT: __kmpc_global_thread_num
// TERM_DEBUG: call void @__kmpc_taskgroup({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
// TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
// TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],