[llvm] 789de76 - [NFC,SHT_LLVM_BB_ADDR_MAP] Fix undefined behaviour in ELF.cpp. (#115830)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 12 09:49:59 PST 2024


Author: Rahman Lavaee
Date: 2024-11-12T09:49:56-08:00
New Revision: 789de766b5fc9c8ffa6e808a8baf0e585ac2e818

URL: https://github.com/llvm/llvm-project/commit/789de766b5fc9c8ffa6e808a8baf0e585ac2e818
DIFF: https://github.com/llvm/llvm-project/commit/789de766b5fc9c8ffa6e808a8baf0e585ac2e818.diff

LOG: [NFC,SHT_LLVM_BB_ADDR_MAP] Fix undefined behaviour in ELF.cpp. (#115830)

`BBEntries` is defined outside of the loop and is used after move which
is undefined behavior.

Added: 
    

Modified: 
    llvm/lib/Object/ELF.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 9a9e762d1e51d6..545a672c05c8a3 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -823,7 +823,6 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
     uint32_t NumBlocksInBBRange = 0;
     uint32_t NumBBRanges = 1;
     typename ELFFile<ELFT>::uintX_t RangeBaseAddress = 0;
-    std::vector<BBAddrMap::BBEntry> BBEntries;
     if (FeatEnable.MultiBBRange) {
       NumBBRanges = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
       if (!Cur || ULEBSizeErr)
@@ -851,6 +850,7 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
         RangeBaseAddress = *AddressOrErr;
         NumBlocksInBBRange = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
       }
+      std::vector<BBAddrMap::BBEntry> BBEntries;
       for (uint32_t BlockIndex = 0; !MetadataDecodeErr && !ULEBSizeErr && Cur &&
                                     (BlockIndex < NumBlocksInBBRange);
            ++BlockIndex) {


        


More information about the llvm-commits mailing list