[PATCH] D120426: [Sema] Mark the referenced destructor during transformation of a `CXXBindTemporaryExpr`

Argyrios Kyrtzidis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 24 10:51:28 PST 2022


akyrtzi updated this revision to Diff 411185.
akyrtzi added a comment.

Make sure to check the destructor decl pointer for nil before passing to `Sema::MarkFunctionReferenced()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120426

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp


Index: clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaTemplate/defaulted-destructor-in-temporary.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++11 %s -emit-llvm -o - | FileCheck %s
+
+// CHECK: define linkonce_odr {{.*}} @_ZN3StrD1Ev
+
+class A {
+public:
+  ~A();
+};
+class Str {
+  A d;
+
+public:
+  ~Str() = default;
+};
+class E {
+  Str s;
+  template <typename>
+  void h() {
+    s = {};
+  }
+  void f();
+};
+void E::f() {
+  h<int>();
+}
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -12748,6 +12748,9 @@
 template<typename Derived>
 ExprResult
 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+  if (auto *Dtor =
+          const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()))
+    SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Dtor);
   return getDerived().TransformExpr(E->getSubExpr());
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120426.411185.patch
Type: text/x-patch
Size: 1111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220224/e5bb9ab6/attachment-0001.bin>


More information about the cfe-commits mailing list