llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/174317.diff


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+6-5) 


``````````diff
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.

``````````

</details>


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

Reply via email to