diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -6640,7 +6640,7 @@ 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 --- a/clang/include/clang/AST/TypeLoc.h +++ b/clang/include/clang/AST/TypeLoc.h @@ -240,6 +240,11 @@ 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 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3018,7 +3018,7 @@ auto *TInfo = (TypeSourceInfo*)BumpAlloc.Allocate(sizeof(TypeSourceInfo) + DataSize, 8); - new (TInfo) TypeSourceInfo(T); + new (TInfo) TypeSourceInfo(T, DataSize); return TInfo; }