https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/174317

The original problem description sounded sane but it was lacking a bit. What 
happens where is that the global block is ultimately not initialized simply 
because it was already created before and its initializer failed, causing us to 
call invokeDtor() in a previous evaluation.

Check for the initialion state earlier and abort there instead of accessing the 
(now uninitialized) data of the block, causing msan failures.

See the failed msan build at 
https://lab.llvm.org/buildbot/#/builders/164/builds/17206

>From 3ca6033ccd4b20274f2ab9d5c6c377b42caa2e56 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Sun, 4 Jan 2026 08:54:35 +0100
Subject: [PATCH] [clang][bytecode] Fix typeid test under msan

The original problem description sounded sane but it was lacking a bit.
What happens where is that the global block is ultimately not
initialized simply because it was already created before and its
initializer failed, causing us to call invokeDtor() in a previous
evaluation.

Check for the initialion state earlier and abort there instead of
accessing the (now uninitialized) data of the block, causing msan
failures.

See the failed msan build at 
https://lab.llvm.org/buildbot/#/builders/164/builds/17206
---
 clang/lib/AST/ByteCode/Compiler.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 4518c587ceca7..f2021ef9456b7 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4803,8 +4803,7 @@ VarCreationState Compiler<Emitter>::visitDecl(const 
VarDecl *VD,
       auto &GD = GlobalBlock->getBlockDesc<GlobalInlineDescriptor>();
 
       GD.InitState = GlobalInitState::InitializerFailed;
-      if (GlobalBlock->isInitialized())
-        GlobalBlock->invokeDtor();
+      GlobalBlock->invokeDtor();
     }
   }
 
@@ -4865,8 +4864,7 @@ bool Compiler<Emitter>::visitDeclAndReturn(const VarDecl 
*VD, const Expr *Init,
       auto &GD = GlobalBlock->getBlockDesc<GlobalInlineDescriptor>();
 
       GD.InitState = GlobalInitState::InitializerFailed;
-      if (GlobalBlock->isInitialized())
-        GlobalBlock->invokeDtor();
+      GlobalBlock->invokeDtor();
     }
     return false;
   }
@@ -4902,8 +4900,11 @@ Compiler<Emitter>::visitVarDecl(const VarDecl *VD, const 
Expr *Init,
 
     UnsignedOrNone GlobalIndex = P.getGlobal(VD);
     if (GlobalIndex) {
+      // The global was previously created but the initializer failed.
+      if (!P.getGlobal(*GlobalIndex)->isInitialized())
+        return false;
       // We've already seen and initialized this global.
-      if (P.getPtrGlobal(*GlobalIndex).isInitialized())
+      if (P.isGlobalInitialized(*GlobalIndex))
         return checkDecl();
       // The previous attempt at initialization might've been unsuccessful,
       // so let's try this one.

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

Reply via email to