Skip to content

Commit 4498663

Browse files
committed
[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
1 parent 9ceb0a7 commit 4498663

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

clang/include/clang/AST/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6640,7 +6640,7 @@ class alignas(8) TypeSourceInfo {
66406640

66416641
QualType Ty;
66426642

6643-
TypeSourceInfo(QualType ty) : Ty(ty) {}
6643+
TypeSourceInfo(QualType ty, size_t DataSize); // implemented in TypeLoc.h
66446644

66456645
public:
66466646
/// Return the type wrapped by this type source info.

clang/include/clang/AST/TypeLoc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ class TypeLoc {
240240
static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
241241
};
242242

243+
inline TypeSourceInfo::TypeSourceInfo(QualType ty, size_t DataSize) : Ty(ty) {
244+
// Init data attached to the object. See getTypeLoc.
245+
memset(this + 1, 0, DataSize);
246+
}
247+
243248
/// Return the TypeLoc for a type source info.
244249
inline TypeLoc TypeSourceInfo::getTypeLoc() const {
245250
// TODO: is this alignment already sufficient?

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3018,7 +3018,7 @@ TypeSourceInfo *ASTContext::CreateTypeSourceInfo(QualType T,
30183018

30193019
auto *TInfo =
30203020
(TypeSourceInfo*)BumpAlloc.Allocate(sizeof(TypeSourceInfo) + DataSize, 8);
3021-
new (TInfo) TypeSourceInfo(T);
3021+
new (TInfo) TypeSourceInfo(T, DataSize);
30223022
return TInfo;
30233023
}
30243024

0 commit comments

Comments
 (0)