[llvm] r300354 - [ValueTracking] Avoid undefined behavior in unittest by not making a named ArrayRef from a std::initializer_list

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 10:59:19 PDT 2017


Author: ctopper
Date: Fri Apr 14 12:59:19 2017
New Revision: 300354

URL: http://llvm.org/viewvc/llvm-project?rev=300354&view=rev
Log:
[ValueTracking] Avoid undefined behavior in unittest by not making a named ArrayRef from a std::initializer_list

One of the ValueTracking unittests creates a named ArrayRef initialized by a std::initializer_list. The underlying array for an std::initializer_list is only guaranteed to have a lifetime as long as the initializer_list object itself. So this can leave the ArrayRef pointing at an array that no long exists.

This fixes this to just create an explicit array instead of an ArrayRef.

Differential Revision: https://reviews.llvm.org/D32089



Modified:
    llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp

Modified: llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp?rev=300354&r1=300353&r2=300354&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/ValueTrackingTest.cpp Fri Apr 14 12:59:19 2017
@@ -219,7 +219,7 @@ TEST(ValueTracking, GuaranteedToTransfer
   assert(F && "Bad assembly?");
 
   auto &BB = F->getEntryBlock();
-  ArrayRef<bool> ExpectedAnswers = {
+  bool ExpectedAnswers[] = {
       true,  // call void @nounwind_readonly(i32* %p)
       true,  // call void @nounwind_argmemonly(i32* %p)
       false, // call void @throws_but_readonly(i32* %p)




More information about the llvm-commits mailing list