[JITLink] Don't initialize local ArrayRefs with initializer lists.
authorLang Hames <lhames@gmail.com>
Sun, 12 Feb 2023 00:52:33 +0000 (16:52 -0800)
committerLang Hames <lhames@gmail.com>
Sun, 12 Feb 2023 01:13:25 +0000 (17:13 -0800)
This can lead to use-after-free errors (see e.g.
https://lab.llvm.org/buildbot/#/builders/168/builds/11848).

llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp

index 90353b5..80f5571 100644 (file)
@@ -721,9 +721,9 @@ TEST(LinkGraphTest, GraphAllocationMethods) {
   EXPECT_EQ(Buf1.size(), 10U);
 
   // Test allocation of content-backed buffer.
-  ArrayRef<char> Buf2Src = {1, static_cast<char>(-1), 0, 42};
-  auto Buf2 = G.allocateContent(Buf2Src);
-  EXPECT_EQ(Buf2, Buf2Src);
+  char Buf2Src[] = {1, static_cast<char>(-1), 0, 42};
+  auto Buf2 = G.allocateContent(ArrayRef<char>(Buf2Src));
+  EXPECT_EQ(Buf2, ArrayRef<char>(Buf2Src));
 
   // Test c-string allocation from StringRef.
   StringRef Buf3Src = "hello";
@@ -739,8 +739,8 @@ TEST(LinkGraphTest, IsCStringBlockTest) {
   auto &Sec =
       G.createSection("__data", orc::MemProt::Read | orc::MemProt::Write);
 
-  ArrayRef<char> CString = "hello, world!";
-  ArrayRef<char> NotACString = {0, 1, 0, 1, 0};
+  char CString[] = "hello, world!";
+  char NotACString[] = {0, 1, 0, 1, 0};
 
   auto &CStringBlock =
       G.createContentBlock(Sec, CString, orc::ExecutorAddr(), 1, 0);