[clang] 8826cd5 - [AST] Construct Capture objects before use
Vitaly Buka via cfe-commits
cfe-commits at lists.llvm.org
Wed May 24 17:09:50 PDT 2023
Author: Vitaly Buka
Date: 2023-05-24T17:09:45-07:00
New Revision: 8826cd57825d829121ad7fb73fab0a6cf30f29f6
URL: https://github.com/llvm/llvm-project/commit/8826cd57825d829121ad7fb73fab0a6cf30f29f6
DIFF: https://github.com/llvm/llvm-project/commit/8826cd57825d829121ad7fb73fab0a6cf30f29f6.diff
LOG: [AST] Construct Capture objects before use
Msan reports https://reviews.llvm.org/P8308
The reason is if PointerIntPair is not properly
constructed, setPointer uses Info::updatePointer
on uninitialized value.
Reviewed By: #clang, rsmith
Differential Revision: https://reviews.llvm.org/D150504
Added:
Modified:
clang/include/clang/AST/Stmt.h
clang/lib/AST/Stmt.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index e466aa1755daf..7e72e44f178a9 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -3587,8 +3587,11 @@ class CapturedStmt : public Stmt {
llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
SourceLocation Loc;
+ Capture() = default;
+
public:
friend class ASTStmtReader;
+ friend class CapturedStmt;
/// Create a new capture.
///
diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp
index 8744bba6c6d9d..c31fb48a2addf 100644
--- a/clang/lib/AST/Stmt.cpp
+++ b/clang/lib/AST/Stmt.cpp
@@ -1345,6 +1345,11 @@ CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
: 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,
More information about the cfe-commits
mailing list