[PATCH] D150486: Initialize PunnedPointer

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 14:38:15 PDT 2023


vitalybuka created this revision.
Herald added a project: All.
vitalybuka requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

D124571 <https://reviews.llvm.org/D124571> regressed PointerIntPair behaviour. Previsoly
default constructor initialized value to 0.

  =3335740==WARNING: MemorySanitizer: use-of-uninitialized-value
      #0 0x55d655b5f8ff in llvm::PointerIntPair<clang::VarDecl*, 2u, clang::CapturedStmt::VariableCaptureKind, llvm::PointerLikeTypeTraits<clang::VarDecl*>, llvm::PointerIntPairInfo<clang::VarDecl*, 2u, llvm::PointerLikeTypeTraits<clang::VarDecl*>>>::setPointer(clang::VarDecl*) & llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:99:13
      #1 0x55d655b5f679 in clang::ASTStmtReader::VisitCapturedStmt(clang::CapturedStmt*) llvm-project/clang/lib/Serialization/ASTReaderStmt.cpp:519:18
      #2 0x55d655b78f19 in clang::ASTReader::ReadStmtFromStream(clang::serialization::ModuleFile&) llvm-project/clang/lib/Serialization/ASTReaderStmt.cpp:4085:14
      #3 0x55d655a326eb in clang::ASTReader::GetExternalDeclStmt(unsigned long) llvm-project/clang/lib/Serialization/ASTReader.cpp:7671:10
      #4 0x55d65a394a87 in clang::LazyOffsetPtr<clang::Stmt, unsigned long, &clang::ExternalASTSource::GetExternalDeclStmt(unsigned long)>::get(clang::ExternalASTSource*) const llvm-project/clang/include/clang/AST/ExternalASTSource.h:378:40
      #5 0x55d6549b9612 in clang::FunctionDecl::getBody() const llvm-project/clang/include/clang/AST/Decl.h:2204:12
      #6 0x55d65471993f in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1403:24
      #7 0x55d654636a02 in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5426:26
      #8 0x55d6546276cc in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3668:12
      #9 0x55d65460c656 in clang::CodeGen::CodeGenModule::EmitDeferred() llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2820:5
      #10 0x55d654607029 in clang::CodeGen::CodeGenModule::Release() llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:535:3
      #11 0x55d655976559 in (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:287:18
      #12 0x55d65596e951 in clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:309:14
      #13 0x55d658674441 in clang::ParseAST(clang::Sema&, bool, bool) llvm-project/clang/lib/Parse/ParseAST.cpp:176:13
      #14 0x55d6557dcf63 in clang::FrontendAction::Execute() llvm-project/clang/lib/Frontend/FrontendAction.cpp:1056:8
      #15 0x55d6556cac9a in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1049:33
      #16 0x55d65595c61f in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:264:25
      #17 0x55d64f6c9b8b in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) llvm-project/clang/tools/driver/cc1_main.cpp:251:15
      #18 0x55d64f6b9b12 in ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) llvm-project/clang/tools/driver/driver.cpp:366:12
      #19 0x55d64f6b492d in clang_main(int, char**, llvm::ToolContext const&) llvm-project/clang/tools/driver/driver.cpp:407:12
      #20 0x55d64f6e7141 in main /usr/local/google/home/vitalybuka/tmp/bot/llvm_build_msan_track_origins/tools/clang/tools/driver/clang-driver.cpp:15:10
      #21 0x7f918acf9189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
      #22 0x7f918acf9244 in __libc_start_main csu/../csu/libc-start.c:381:3
      #23 0x55d64f6297e0 in _start (/usr/local/google/home/vitalybuka/tmp/bot/llvm_build_msan_track_origins/bin/clang-17+0x611d7e0)
  
    Memory was marked as uninitialized
      #0 0x55d64f65edcd in __msan_allocated_memory /usr/local/google/home/vitalybuka/tmp/bot/llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:940:5
      #1 0x55d64f997049 in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>::Allocate(unsigned long, llvm::Align) llvm-project/llvm/include/llvm/Support/Allocator.h
      #2 0x55d64f996d3e in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>::Allocate(unsigned long, unsigned long) llvm-project/llvm/include/llvm/Support/Allocator.h:209:12
      #3 0x55d65a8203e2 in Allocate llvm-project/clang/include/clang/AST/ASTContext.h:705:22
      #4 0x55d65a8203e2 in clang::CapturedStmt::CreateDeserialized(clang::ASTContext const&, unsigned int) llvm-project/clang/lib/AST/Stmt.cpp:1387:23
      #5 0x55d655b76984 in clang::ASTReader::ReadStmtFromStream(clang::serialization::ModuleFile&) llvm-project/clang/lib/Serialization/ASTReaderStmt.cpp:2915:11
      #6 0x55d655a326eb in clang::ASTReader::GetExternalDeclStmt(unsigned long) llvm-project/clang/lib/Serialization/ASTReader.cpp:7671:10
      #7 0x55d65a394a87 in clang::LazyOffsetPtr<clang::Stmt, unsigned long, &clang::ExternalASTSource::GetExternalDeclStmt(unsigned long)>::get(clang::ExternalASTSource*) const llvm-project/clang/include/clang/AST/ExternalASTSource.h:378:40
      #8 0x55d6549b9612 in clang::FunctionDecl::getBody() const llvm-project/clang/include/clang/AST/Decl.h:2204:12
      #9 0x55d65471993f in clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1403:24
      #10 0x55d654636a02 in clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5426:26
      #11 0x55d6546276cc in clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3668:12
      #12 0x55d65460c656 in clang::CodeGen::CodeGenModule::EmitDeferred() llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2820:5
      #13 0x55d654607029 in clang::CodeGen::CodeGenModule::Release() llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:535:3
      #14 0x55d655976559 in (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:287:18
      #15 0x55d65596e951 in clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:309:14
      #16 0x55d658674441 in clang::ParseAST(clang::Sema&, bool, bool) llvm-project/clang/lib/Parse/ParseAST.cpp:176:13
      #17 0x55d6557dcf63 in clang::FrontendAction::Execute() llvm-project/clang/lib/Frontend/FrontendAction.cpp:1056:8
      #18 0x55d6556cac9a in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1049:33
      #19 0x55d65595c61f in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:264:25
      #20 0x55d64f6c9b8b in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) llvm-project/clang/tools/driver/cc1_main.cpp:251:15


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150486

Files:
  llvm/include/llvm/ADT/PointerIntPair.h


Index: llvm/include/llvm/ADT/PointerIntPair.h
===================================================================
--- llvm/include/llvm/ADT/PointerIntPair.h
+++ llvm/include/llvm/ADT/PointerIntPair.h
@@ -53,7 +53,7 @@
   const Ptr *getPointerAddress() const { return reinterpret_cast<Ptr *>(Data); }
 
 private:
-  alignas(Ptr) unsigned char Data[sizeof(Ptr)];
+  alignas(Ptr) unsigned char Data[sizeof(Ptr)] = {};
 };
 } // namespace detail
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150486.521800.patch
Type: text/x-patch
Size: 444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230512/67663eca/attachment.bin>


More information about the llvm-commits mailing list