r292590 - [OPENMP] Fix for PR31643: Clang crashes when compiling code on Windows

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 20 00:57:28 PST 2017


Author: abataev
Date: Fri Jan 20 02:57:28 2017
New Revision: 292590

URL: http://llvm.org/viewvc/llvm-project?rev=292590&view=rev
Log:
[OPENMP] Fix for PR31643: Clang crashes when compiling code on Windows
with SEH and openmp

In some cituations (during codegen for Windows SEH constructs)
CodeGenFunction instance may have CurFn equal to nullptr. OpenMP related
code does not expect such situation during cleanup.

Added:
    cfe/trunk/test/OpenMP/openmp_seh.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=292590&r1=292589&r2=292590&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Jan 20 02:57:28 2017
@@ -112,9 +112,8 @@ CodeGenFunction::~CodeGenFunction() {
   if (FirstBlockInfo)
     destroyBlockInfos(FirstBlockInfo);
 
-  if (getLangOpts().OpenMP) {
+  if (getLangOpts().OpenMP && CurFn)
     CGM.getOpenMPRuntime().functionFinished(*this);
-  }
 }
 
 CharUnits CodeGenFunction::getNaturalPointeeTypeAlignment(QualType T,

Added: cfe/trunk/test/OpenMP/openmp_seh.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/openmp_seh.c?rev=292590&view=auto
==============================================================================
--- cfe/trunk/test/OpenMP/openmp_seh.c (added)
+++ cfe/trunk/test/OpenMP/openmp_seh.c Fri Jan 20 02:57:28 2017
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify -triple x86_64-pc-windows-msvc19.0.0 -fopenmp -fms-compatibility -x c++ -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+// REQUIRES: x86-registered-target
+extern "C" {
+void __cpuid(int[4], int);
+}
+
+// CHECK-LABEL: @main
+int main(void) {
+  __try {
+    int info[4];
+    __cpuid(info, 1);
+  } __except (1) {
+  }
+
+  return 0;
+}
+




More information about the cfe-commits mailing list