[llvm] 630d264 - Analysis: only query size of sized objects.
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 14 04:16:14 PDT 2020
Author: Tim Northover
Date: 2020-10-14T12:16:05+01:00
New Revision: 630d2647986aa6d672dce184460d7ca3349eb006
URL: https://github.com/llvm/llvm-project/commit/630d2647986aa6d672dce184460d7ca3349eb006
DIFF: https://github.com/llvm/llvm-project/commit/630d2647986aa6d672dce184460d7ca3349eb006.diff
LOG: 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.
Added:
llvm/test/Transforms/InstCombine/object-size-opaque.ll
Modified:
llvm/lib/Analysis/MemoryBuiltins.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 402a2bcadf5f..cbb54e8efdc0 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -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();
}
diff --git a/llvm/test/Transforms/InstCombine/object-size-opaque.ll b/llvm/test/Transforms/InstCombine/object-size-opaque.ll
new file mode 100644
index 000000000000..741586fead1f
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/object-size-opaque.ll
@@ -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)
More information about the llvm-commits
mailing list