[PATCH] D32089: [ValueTracking] Avoid undefined behavior in unittest by not making a named ArrayRef from a std::initializer_list

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 10:53:33 PDT 2017


craig.topper created this revision.

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.


https://reviews.llvm.org/D32089

Files:
  unittests/Analysis/ValueTrackingTest.cpp


Index: unittests/Analysis/ValueTrackingTest.cpp
===================================================================
--- unittests/Analysis/ValueTrackingTest.cpp
+++ unittests/Analysis/ValueTrackingTest.cpp
@@ -219,7 +219,7 @@
   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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32089.95315.patch
Type: text/x-patch
Size: 532 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170414/948e1b39/attachment.bin>


More information about the llvm-commits mailing list