[AST/Interp] Fix latent unitialized use of memory bug in D64146
authorFangrui Song <i@maskray.me>
Thu, 8 Sep 2022 20:39:30 +0000 (13:39 -0700)
committerFangrui Song <i@maskray.me>
Thu, 8 Sep 2022 20:39:30 +0000 (13:39 -0700)
Exposed by D132727: clang/test/AST/Interp/arrays.cpp fails with --config=msan

clang/lib/AST/Interp/Descriptor.cpp

index 5c1a8a9..2098ae7 100644 (file)
@@ -259,9 +259,7 @@ SourceLocation Descriptor::getLocation() const {
 }
 
 InitMap::InitMap(unsigned N) : UninitFields(N) {
-  for (unsigned I = 0; I < N / PER_FIELD; ++I) {
-    data()[I] = 0;
-  }
+  std::fill_n(data(), (N + PER_FIELD - 1) / PER_FIELD, 0);
 }
 
 InitMap::T *InitMap::data() {