smeenai created this revision.
smeenai added reviewers: rnk, rsmith.

EmitInlinedInheritingCXXConstructorCall may result in a CallBaseDtor
cleanup being pushed. That cleanup would then be popped when the CGF's
CurCodeDecl no longer points to the method which triggered the cleanup,
leading to a failed cast. Create a new cleanup scope to ensure that the
cleanup gets popped while the CurCodeDecl still points to the method.
Fixes PR36748.


Repository:
  rC Clang

https://reviews.llvm.org/D44619

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/inheriting-constructor-cleanup.cpp


Index: test/CodeGenCXX/inheriting-constructor-cleanup.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/inheriting-constructor-cleanup.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fexceptions -emit-llvm -o - %s | 
FileCheck %s
+
+// PR36748
+struct S {
+  ~S() {}
+};
+
+struct T {
+  T(int, ...) {}
+};
+
+struct U : public S, public T {
+  using T::T;
+};
+
+void f() {
+  U(0);
+}
+
+// ~S cleanup should be emitted rather than crashing
+// CHECK-LABEL: define void @_Z1fv
+// CHECK: call void @_ZN1SD2Ev
Index: lib/CodeGen/CGClass.cpp
===================================================================
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -2180,6 +2180,7 @@
   GlobalDecl GD(Ctor, CtorType);
   InlinedInheritingConstructorScope Scope(*this, GD);
   ApplyInlineDebugLocation DebugScope(*this, GD);
+  RunCleanupsScope CleanupScope(*this);
 
   // Save the arguments to be passed to the inherited constructor.
   CXXInheritedCtorInitExprArgs = Args;


Index: test/CodeGenCXX/inheriting-constructor-cleanup.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/inheriting-constructor-cleanup.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fexceptions -emit-llvm -o - %s | FileCheck %s
+
+// PR36748
+struct S {
+  ~S() {}
+};
+
+struct T {
+  T(int, ...) {}
+};
+
+struct U : public S, public T {
+  using T::T;
+};
+
+void f() {
+  U(0);
+}
+
+// ~S cleanup should be emitted rather than crashing
+// CHECK-LABEL: define void @_Z1fv
+// CHECK: call void @_ZN1SD2Ev
Index: lib/CodeGen/CGClass.cpp
===================================================================
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -2180,6 +2180,7 @@
   GlobalDecl GD(Ctor, CtorType);
   InlinedInheritingConstructorScope Scope(*this, GD);
   ApplyInlineDebugLocation DebugScope(*this, GD);
+  RunCleanupsScope CleanupScope(*this);
 
   // Save the arguments to be passed to the inherited constructor.
   CXXInheritedCtorInitExprArgs = Args;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D44619: [... Shoaib Meenai via Phabricator via cfe-commits

Reply via email to