[PATCH] D150504: [AST] Construct Capture objects before use

Vitaly Buka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 12 18:44:34 PDT 2023


vitalybuka created this revision.
Herald added a project: All.
vitalybuka requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Msan reports https://reviews.llvm.org/P8308
So the reason is if PointerIntPair is not properly
constructed, setPointer uses Info::updatePointer
on uninitialized value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150504

Files:
  clang/include/clang/AST/Stmt.h
  clang/lib/AST/Stmt.cpp


Index: clang/lib/AST/Stmt.cpp
===================================================================
--- clang/lib/AST/Stmt.cpp
+++ clang/lib/AST/Stmt.cpp
@@ -1345,6 +1345,11 @@
   : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
     CapDeclAndKind(nullptr, CR_Default) {
   getStoredStmts()[NumCaptures] = nullptr;
+
+  // Construct default capture objects.
+  Capture *Buffer = getStoredCaptures();
+  for (unsigned I = 0, N = NumCaptures; I != N; ++I)
+    new (Buffer++) Capture();
 }
 
 CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S,
Index: clang/include/clang/AST/Stmt.h
===================================================================
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -3587,8 +3587,11 @@
     llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
     SourceLocation Loc;
 
+    Capture() = default;
+
   public:
     friend class ASTStmtReader;
+    friend class CapturedStmt;
 
     /// Create a new capture.
     ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150504.521858.patch
Type: text/x-patch
Size: 1017 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230513/c26e97f6/attachment.bin>


More information about the cfe-commits mailing list