[llvm] [ThinLTO] Use StringRef instead of std::string (PR #97963)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 8 13:32:57 PDT 2024


luxufan wrote:

Thanks for your explanation and example!

Yes, there is no documentation says BitcodeModule must not be released after being read. However, releasing the BitcodeModule after being read is problematic. 
See https://github.com/llvm/llvm-project/blob/d358151a4fe94c72186d58f8903f044a116d0fa8/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L7336-L7353
The name is a direct reference to the string table of the BitcodeModule. Then it is stored in the GlobalValueSummaryInfo. If the BitcodeModule is released after being read, then the name field in GlobalValueSummaryInfo may point to the memory that has been freed.

So I think the interface llvm::readModuleSummaryIndex is not correct.

Maybe we can try one of these solutions:
1. Add an argument that indicates if the BitcodeModule is retained after being read. If not, then always call Index->saveString.
2. Add some words in the documentation that the BitcodeModule should not be released after being read.

https://github.com/llvm/llvm-project/pull/97963


More information about the llvm-commits mailing list