[Evaluator] Bitcast result of pointer stripping

Trying to evaluate a GEP would assert with
  "Ty == cast<PointerType>(C->getType()->getScalarType())->getElementType()"
because the type of the pointer we would evaluate the GEP argument to
would be a different type than the GEP was expecting. We should treat
pointer stripping as a bitcast.

The test adds a redundant GEP that would crash due to type mismatch.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D100970
This commit is contained in:
Arthur Eubanks 2021-04-21 09:41:17 -07:00
parent 5d1c43f333
commit b606e2df4d
2 changed files with 4 additions and 2 deletions

View File

@ -566,6 +566,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
<< "Stripped pointer casts for alias analysis for "
"intrinsic call.\n");
StrippedPointerCastsForAliasAnalysis = true;
InstResult = ConstantExpr::getBitCast(InstResult, II->getType());
} else {
LLVM_DEBUG(dbgs() << "Unknown intrinsic. Cannot evaluate.\n");
return false;

View File

@ -32,9 +32,10 @@ enter:
%0 = bitcast i32* %valptr to i8*
%barr = call i8* @llvm.launder.invariant.group(i8* %0)
%1 = bitcast i8* %barr to i32*
%1 = getelementptr i8, i8* %barr, i32 0
%2 = bitcast i8* %1 to i32*
%val2 = load i32, i32* %1
%val2 = load i32, i32* %2
store i32 %val2, i32* @tmp2
ret void
}