Author: Vitaly Buka Date: 2023-05-25T09:53:17-07:00 New Revision: 4498663f3de0857359502469bb93fb850b0a8c2e
URL: https://github.com/llvm/llvm-project/commit/4498663f3de0857359502469bb93fb850b0a8c2e DIFF: https://github.com/llvm/llvm-project/commit/4498663f3de0857359502469bb93fb850b0a8c2e.diff LOG: [AST] Initialized data after TypeSourceInfo There is no initialization of the data between allocation and first getBeginLoc call. allocation: llvm-project/clang/lib/AST/ASTContext.cpp:3022 use: llvm-project/clang/lib/AST/TypeLoc.cpp:222 Msan report https://reviews.llvm.org/P8306 Reviewed By: thurston Differential Revision: https://reviews.llvm.org/D150499 Added: Modified: clang/include/clang/AST/Type.h clang/include/clang/AST/TypeLoc.h clang/lib/AST/ASTContext.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index 7ce1ad9b9099..a95728bb6893 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -6640,7 +6640,7 @@ class alignas(8) TypeSourceInfo { QualType Ty; - TypeSourceInfo(QualType ty) : Ty(ty) {} + TypeSourceInfo(QualType ty, size_t DataSize); // implemented in TypeLoc.h public: /// Return the type wrapped by this type source info. diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h index 8bf64dc6158c..27f714b7c983 100644 --- a/clang/include/clang/AST/TypeLoc.h +++ b/clang/include/clang/AST/TypeLoc.h @@ -240,6 +240,11 @@ class TypeLoc { static SourceRange getLocalSourceRangeImpl(TypeLoc TL); }; +inline TypeSourceInfo::TypeSourceInfo(QualType ty, size_t DataSize) : Ty(ty) { + // Init data attached to the object. See getTypeLoc. + memset(this + 1, 0, DataSize); +} + /// Return the TypeLoc for a type source info. inline TypeLoc TypeSourceInfo::getTypeLoc() const { // TODO: is this alignment already sufficient? diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 2307c33c5900..7758c30725a3 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3018,7 +3018,7 @@ TypeSourceInfo *ASTContext::CreateTypeSourceInfo(QualType T, auto *TInfo = (TypeSourceInfo*)BumpAlloc.Allocate(sizeof(TypeSourceInfo) + DataSize, 8); - new (TInfo) TypeSourceInfo(T); + new (TInfo) TypeSourceInfo(T, DataSize); return TInfo; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits