Analysis: only query size of sized objects.

Recently we started looking into sret parameters, though the issue could crop
up elsewhere. If the pointee type is opaque, we should not try to compute its
size because that leads to an assertion failure.
This commit is contained in:
Tim Northover 2020-10-14 11:38:01 +01:00
parent af5be38a01
commit 630d264798
2 changed files with 13 additions and 1 deletions

View File

@ -678,7 +678,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitAllocaInst(AllocaInst &I) {
SizeOffsetType ObjectSizeOffsetVisitor::visitArgument(Argument &A) {
Type *MemoryTy = A.getPointeeInMemoryValueType();
// No interprocedural analysis is done at the moment.
if (!MemoryTy) {
if (!MemoryTy|| !MemoryTy->isSized()) {
++ObjectVisitorArgument;
return unknown();
}

View File

@ -0,0 +1,12 @@
; RUN: opt -instcombine -S %s | FileCheck %s
%opaque = type opaque
; CHECK: call i64 @llvm.objectsize.i64
define void @foo(%opaque* sret %in, i64* %sizeptr) {
%ptr = bitcast %opaque* %in to i8*
%size = call i64 @llvm.objectsize.i64(i8* %ptr, i1 0, i1 0, i1 0)
store i64 %size, i64* %sizeptr
ret void
}
declare i64 @llvm.objectsize.i64(i8*, i1, i1, i1)