From 11898c48c5c7a29671642b92265d13a940daa11d Mon Sep 17 00:00:00 2001 From: Galina Kistanova Date: Thu, 8 Jun 2017 23:35:52 +0000 Subject: [PATCH] Fixed warning: dereferencing type-punned pointer will break strict-aliasing rules. No need in reinterpret_cast here, as struct coff_symbol Name is a unin with the member StringTableOffset Offset. This union member could be accessed directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305029 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/COFFImportFile.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Object/COFFImportFile.cpp b/lib/Object/COFFImportFile.cpp index 37962d84d85..740bf94d40e 100644 --- a/lib/Object/COFFImportFile.cpp +++ b/lib/Object/COFFImportFile.cpp @@ -285,11 +285,13 @@ ObjectFactory::createImportDescriptor(std::vector &Buffer) { IMAGE_SYM_CLASS_EXTERNAL, 0}, }; - reinterpret_cast(SymbolTable[0].Name).Offset = + // TODO: Name.Offset.Offset here and in the all similar places below + // suggests a names refactoring. Maybe StringTableOffset.Value? + SymbolTable[0].Name.Offset.Offset = sizeof(uint32_t); - reinterpret_cast(SymbolTable[5].Name).Offset = + SymbolTable[5].Name.Offset.Offset = sizeof(uint32_t) + ImportDescriptorSymbolName.length() + 1; - reinterpret_cast(SymbolTable[6].Name).Offset = + SymbolTable[6].Name.Offset.Offset = sizeof(uint32_t) + ImportDescriptorSymbolName.length() + 1 + NullImportDescriptorSymbolName.length() + 1; append(Buffer, SymbolTable); @@ -354,8 +356,7 @@ ObjectFactory::createNullImportDescriptor(std::vector &Buffer) { IMAGE_SYM_CLASS_EXTERNAL, 0}, }; - reinterpret_cast(SymbolTable[0].Name).Offset = - sizeof(uint32_t); + SymbolTable[0].Name.Offset.Offset = sizeof(uint32_t); append(Buffer, SymbolTable); // String Table @@ -437,8 +438,7 @@ NewArchiveMember ObjectFactory::createNullThunk(std::vector &Buffer) { IMAGE_SYM_CLASS_EXTERNAL, 0}, }; - reinterpret_cast(SymbolTable[0].Name).Offset = - sizeof(uint32_t); + SymbolTable[0].Name.Offset.Offset = sizeof(uint32_t); append(Buffer, SymbolTable); // String Table -- 2.50.1