https://github.com/nataliakokoromyti updated 
https://github.com/llvm/llvm-project/pull/174082

>From 23ae304d290469973f718622f2dd73808489970d Mon Sep 17 00:00:00 2001
From: Natalia Kokoromyti <[email protected]>
Date: Wed, 31 Dec 2025 03:04:19 -0800
Subject: [PATCH] [clang][bytecode] Check if block is initialized before
 invoking destructor. Fixes #173950

---
 clang/lib/AST/ByteCode/Compiler.cpp  |  6 ++++--
 clang/test/AST/ByteCode/gh173950.cpp | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/AST/ByteCode/gh173950.cpp

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 4daab0702f147..0398f267c1be6 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4801,7 +4801,8 @@ VarCreationState Compiler<Emitter>::visitDecl(const 
VarDecl *VD,
       auto &GD = GlobalBlock->getBlockDesc<GlobalInlineDescriptor>();
 
       GD.InitState = GlobalInitState::InitializerFailed;
-      GlobalBlock->invokeDtor();
+      if (GlobalBlock->isInitialized())
+        GlobalBlock->invokeDtor();
     }
   }
 
@@ -4862,7 +4863,8 @@ bool Compiler<Emitter>::visitDeclAndReturn(const VarDecl 
*VD, const Expr *Init,
       auto &GD = GlobalBlock->getBlockDesc<GlobalInlineDescriptor>();
 
       GD.InitState = GlobalInitState::InitializerFailed;
-      GlobalBlock->invokeDtor();
+      if (GlobalBlock->isInitialized())
+        GlobalBlock->invokeDtor();
     }
     return false;
   }
diff --git a/clang/test/AST/ByteCode/gh173950.cpp 
b/clang/test/AST/ByteCode/gh173950.cpp
new file mode 100644
index 0000000000000..260523eddc22b
--- /dev/null
+++ b/clang/test/AST/ByteCode/gh173950.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only 
-fexperimental-new-constant-interpreter -verify %s
+// expected-no-diagnostics
+
+// Test for issue #173950: Assertion `IsInitialized' failed when evaluating
+// typeid on a reference to a dynamically allocated object.
+
+namespace std {
+class type_info {};
+}
+
+namespace GH173950 {
+struct A {
+  virtual void f();
+};
+
+static A &a = *new A;
+extern A &a;
+
+// This used to crash with: Assertion `IsInitialized' failed in invokeDtor()
+const std::type_info &a_ti = typeid(a);
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to