llvm.org GIT mirror llvm / 71c1b22
Fix a disconcerting bug in Value::isUsedInBasicBlock, which gave wrong answers for blocks larger than 3 instrs. Also add a unit test. PR15727. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179370 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 6 years ago
3 changed file(s) with 48 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
117117 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
118118 if (std::find(I->op_begin(), I->op_end(), this) != I->op_end())
119119 return true;
120 if (MaxBlockSize-- == 0) // If the block is larger fall back to use_iterator
120 if (--MaxBlockSize == 0) // If the block is larger fall back to use_iterator
121121 break;
122122 }
123123
1515 TypeBuilderTest.cpp
1616 TypesTest.cpp
1717 ValueMapTest.cpp
18 ValueTest.cpp
1819 VerifierTest.cpp
1920 WaymarkTest.cpp
2021 )
0 //===- llvm/unittest/IR/ValueTest.cpp - Value unit tests ------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Assembly/Parser.h"
10 #include "llvm/IR/Function.h"
11 #include "llvm/IR/LLVMContext.h"
12 #include "llvm/IR/Module.h"
13 #include "llvm/IR/Value.h"
14 #include "llvm/Support/SourceMgr.h"
15 #include "gtest/gtest.h"
16 using namespace llvm;
17
18 namespace {
19
20 TEST(ValueTest, UsedInBasicBlock) {
21 LLVMContext C;
22
23 const char *ModuleString = "define void @f(i32 %x, i32 %y) {\n"
24 "bb0:\n"
25 " %y1 = add i32 %y, 1\n"
26 " %y2 = add i32 %y, 1\n"
27 " %y3 = add i32 %y, 1\n"
28 " %y4 = add i32 %y, 1\n"
29 " %y5 = add i32 %y, 1\n"
30 " %y6 = add i32 %y, 1\n"
31 " %y7 = add i32 %y, 1\n"
32 " %y8 = add i32 %x, 1\n"
33 " ret void\n"
34 "}\n";
35 SMDiagnostic Err;
36 Module *M = ParseAssemblyString(ModuleString, NULL, Err, C);
37
38 Function *F = M->getFunction("f");
39
40 EXPECT_FALSE(F->isUsedInBasicBlock(F->begin()));
41 EXPECT_TRUE((++F->arg_begin())->isUsedInBasicBlock(F->begin()));
42 EXPECT_TRUE(F->arg_begin()->isUsedInBasicBlock(F->begin()));
43 }
44
45 } // end anonymous namespace