llvm.org GIT mirror llvm / 4400825
Dan noticed that the verifier wasn't thoroughly checking uses of invoke results (see the testcases). Tighten up the checking. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72586 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 11 years ago
4 changed file(s) with 101 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
12431243 if (!isa(I)) { // Check that non-phi nodes are not self referential
12441244 for (Value::use_iterator UI = I.use_begin(), UE = I.use_end();
12451245 UI != UE; ++UI)
1246 Assert1(*UI != (User*)&I ||
1247 !DT->dominates(&BB->getParent()->getEntryBlock(), BB),
1246 Assert1(*UI != (User*)&I || !DT->isReachableFromEntry(BB),
12481247 "Only PHI nodes may reference their own value!", &I);
12491248 }
12501249
13051304 BasicBlock *OpBlock = Op->getParent();
13061305
13071306 // Check that a definition dominates all of its uses.
1308 if (!isa(I)) {
1307 if (InvokeInst *II = dyn_cast(Op)) {
13091308 // Invoke results are only usable in the normal destination, not in the
13101309 // exceptional destination.
1311 if (InvokeInst *II = dyn_cast(Op)) {
1312 OpBlock = II->getNormalDest();
1313
1314 Assert2(OpBlock != II->getUnwindDest(),
1315 "No uses of invoke possible due to dominance structure!",
1316 Op, II);
1317
1310 BasicBlock *NormalDest = II->getNormalDest();
1311
1312 Assert2(NormalDest != II->getUnwindDest(),
1313 "No uses of invoke possible due to dominance structure!",
1314 Op, &I);
1315
1316 // PHI nodes differ from other nodes because they actually "use" the
1317 // value in the predecessor basic blocks they correspond to.
1318 BasicBlock *UseBlock = BB;
1319 if (isa(I))
1320 UseBlock = cast(I.getOperand(i+1));
1321
1322 if (isa(I) && UseBlock == OpBlock) {
1323 // Special case of a phi node in the normal destination or the unwind
1324 // destination.
1325 Assert2(BB == NormalDest || !DT->isReachableFromEntry(UseBlock),
1326 "Invoke result not available in the unwind destination!",
1327 Op, &I);
1328 } else {
1329 Assert2(DT->dominates(NormalDest, UseBlock) ||
1330 !DT->isReachableFromEntry(UseBlock),
1331 "Invoke result does not dominate all uses!", Op, &I);
1332
13181333 // If the normal successor of an invoke instruction has multiple
1319 // predecessors, then the normal edge from the invoke is critical, so
1320 // the invoke value can only be live if the destination block
1321 // dominates all of it's predecessors (other than the invoke) or if
1322 // the invoke value is only used by a phi in the successor.
1323 if (!OpBlock->getSinglePredecessor() &&
1324 DT->dominates(&BB->getParent()->getEntryBlock(), BB)) {
1325 // The first case we allow is if the use is a PHI operand in the
1326 // normal block, and if that PHI operand corresponds to the invoke's
1327 // block.
1328 bool Bad = true;
1329 if (PHINode *PN = dyn_cast(&I))
1330 if (PN->getParent() == OpBlock &&
1331 PN->getIncomingBlock(i/2) == Op->getParent())
1332 Bad = false;
1333
1334 // predecessors, then the normal edge from the invoke is critical,
1335 // so the invoke value can only be live if the destination block
1336 // dominates all of it's predecessors (other than the invoke).
1337 if (!NormalDest->getSinglePredecessor() &&
1338 DT->isReachableFromEntry(UseBlock))
13341339 // If it is used by something non-phi, then the other case is that
1335 // 'OpBlock' dominates all of its predecessors other than the
1340 // 'NormalDest' dominates all of its predecessors other than the
13361341 // invoke. In this case, the invoke value can still be used.
1337 if (Bad) {
1338 Bad = false;
1339 for (pred_iterator PI = pred_begin(OpBlock),
1340 E = pred_end(OpBlock); PI != E; ++PI) {
1341 if (*PI != II->getParent() && !DT->dominates(OpBlock, *PI)) {
1342 Bad = true;
1343 break;
1344 }
1342 for (pred_iterator PI = pred_begin(NormalDest),
1343 E = pred_end(NormalDest); PI != E; ++PI)
1344 if (*PI != II->getParent() && !DT->dominates(NormalDest, *PI) &&
1345 DT->isReachableFromEntry(*PI)) {
1346 CheckFailed("Invoke result does not dominate all uses!", Op,&I);
1347 return;
13451348 }
1346 }
1347 Assert2(!Bad,
1348 "Invoke value defined on critical edge but not dead!", &I,
1349 Op);
1350 }
1351 } else if (OpBlock == BB) {
1352 // If they are in the same basic block, make sure that the definition
1353 // comes before the use.
1354 Assert2(InstsInThisBlock.count(Op) ||
1355 !DT->dominates(&BB->getParent()->getEntryBlock(), BB),
1356 "Instruction does not dominate all uses!", Op, &I);
13571349 }
1358
1359 // Definition must dominate use unless use is unreachable!
1360 Assert2(InstsInThisBlock.count(Op) || DT->dominates(Op, &I) ||
1361 !DT->dominates(&BB->getParent()->getEntryBlock(), BB),
1362 "Instruction does not dominate all uses!", Op, &I);
1363 } else {
1350 } else if (isa(I)) {
13641351 // PHI nodes are more difficult than other nodes because they actually
13651352 // "use" the value in the predecessor basic blocks they correspond to.
13661353 BasicBlock *PredBB = cast(I.getOperand(i+1));
13671354 Assert2(DT->dominates(OpBlock, PredBB) ||
1368 !DT->dominates(&BB->getParent()->getEntryBlock(), PredBB),
1355 !DT->isReachableFromEntry(PredBB),
1356 "Instruction does not dominate all uses!", Op, &I);
1357 } else {
1358 if (OpBlock == BB) {
1359 // If they are in the same basic block, make sure that the definition
1360 // comes before the use.
1361 Assert2(InstsInThisBlock.count(Op) || !DT->isReachableFromEntry(BB),
1362 "Instruction does not dominate all uses!", Op, &I);
1363 }
1364
1365 // Definition must dominate use unless use is unreachable!
1366 Assert2(InstsInThisBlock.count(Op) || DT->dominates(Op, &I) ||
1367 !DT->isReachableFromEntry(BB),
13691368 "Instruction does not dominate all uses!", Op, &I);
13701369 }
13711370 } else if (isa(I.getOperand(i))) {
0 ; RUN: not llvm-as < %s >& /dev/null
1
2 declare i32 @v()
3
4 define i32 @f() {
5 e:
6 %r = invoke i32 @v()
7 to label %c unwind label %u ; [#uses=2]
8
9 c: ; preds = %e
10 ret i32 %r
11
12 u: ; preds = %e
13 ret i32 %r
14 }
0 ; RUN: not llvm-as < %s >& /dev/null
1
2 declare i32 @v()
3
4 define i32 @g() {
5 e:
6 %s = invoke i32 @v()
7 to label %c unwind label %u ; [#uses=2]
8
9 c: ; preds = %e
10 ret i32 %s
11
12 u: ; preds = %e
13 %t = phi i32 [ %s, %e ] ; [#uses=1]
14 ret i32 %t
15 }
0 ; RUN: not llvm-as < %s >& /dev/null
1
2 declare i32 @v()
3
4 define i32 @h() {
5 e:
6 %s = invoke i32 @v()
7 to label %c unwind label %u ; [#uses=2]
8
9 c: ; preds = %e
10 br label %d
11
12 d: ; preds = %u, %c
13 %p = phi i32 [ %s, %c ], [ %s, %u ] ; [#uses=1]
14 ret i32 %p
15
16 u: ; preds = %e
17 br label %d
18 }