[PATCH] D157566: [SEH] fix assertion when -fasy-exceptions is used.

Jennifer Yu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 10 21:59:29 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG33e3b2c46084: Fix assertion when -fasy-exception is used. (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157566/new/

https://reviews.llvm.org/D157566

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/test/CodeGen/windows-seh-async-exceptions.cpp


Index: clang/test/CodeGen/windows-seh-async-exceptions.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGen/windows-seh-async-exceptions.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -x c++ \
+// RUN:  -emit-llvm %s -o -| FileCheck %s
+
+extern "C" int printf(const char*,...);
+class PrintfArg
+{
+public:
+  PrintfArg();
+  PrintfArg(const char* s);
+
+  // compiler crash fixed if this destructor removed
+  ~PrintfArg() {int x; printf("ddd\n");  }
+};
+
+void devif_Warning(const char* fmt, PrintfArg arg1 = PrintfArg());
+// CHECK-NOT: invoke void @llvm.seh.scope.begin()
+// CHECK-NOT: invoke void @llvm.seh.scope.end()
+unsigned myfunc(unsigned index)
+{
+  devif_Warning("");
+  return 0;
+}
Index: clang/lib/CodeGen/CGCleanup.cpp
===================================================================
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -207,8 +207,13 @@
     Scope->setLifetimeMarker();
 
   // With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
+  // If exceptions are disabled/ignored and SEH is not in use, then there is no
+  // invoke destination. SEH "works" even if exceptions are off. In practice,
+  // this means that C++ destructors and other EH cleanups don't run, which is
+  // consistent with MSVC's behavior, except in the presence of -EHa.
+  // Check getInvokeDest() to generate llvm.seh.scope.begin() as needed.
   if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
-      CGF->getTarget().getCXXABI().isMicrosoft())
+      CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest())
     CGF->EmitSehCppScopeBegin();
 
   return Scope->getCleanupBuffer();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157566.549242.patch
Type: text/x-patch
Size: 1755 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230811/644c5219/attachment-0001.bin>


More information about the cfe-commits mailing list