Skip to content

Commit f9c3954

Browse files
committed
Fix for Bug 48055.
Differential Revision: https://reviews.llvm.org/D92599
1 parent 5ad6ed5 commit f9c3954

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

llvm/lib/Transforms/Utils/Evaluator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ evaluateBitcastFromPtr(Constant *Ptr, const DataLayout &DL,
183183
std::function<Constant *(Constant *)> Func) {
184184
Constant *Val;
185185
while (!(Val = Func(Ptr))) {
186-
// If Ty is a struct, we can convert the pointer to the struct
186+
// If Ty is a non-opaque struct, we can convert the pointer to the struct
187187
// into a pointer to its first member.
188188
// FIXME: This could be extended to support arrays as well.
189189
Type *Ty = cast<PointerType>(Ptr->getType())->getElementType();
190-
if (!isa<StructType>(Ty))
190+
if (!isa<StructType>(Ty) || cast<StructType>(Ty)->isOpaque())
191191
break;
192192

193193
IntegerType *IdxTy = IntegerType::get(Ty->getContext(), 32);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; PR48055. Check that this does not crash.
2+
; RUN: opt -globalopt %s -disable-output
3+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4+
target triple = "x86_64-unknown-linux-gnu"
5+
6+
%struct.g = type opaque
7+
%struct.a = type { i32 (...)** }
8+
9+
@l = dso_local global i32 0, align 4
10+
@h = external dso_local global %struct.g, align 1
11+
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_bug48055.cc, i8* null }]
12+
13+
; Function Attrs: uwtable
14+
define internal void @__cxx_global_var_init() {
15+
entry:
16+
%vtable = load i32 (%struct.a*)**, i32 (%struct.a*)*** bitcast (%struct.g* @h to i32 (%struct.a*)***), align 1
17+
%0 = load i32 (%struct.a*)*, i32 (%struct.a*)** %vtable, align 8
18+
%call = call i32 %0(%struct.a* nonnull dereferenceable(8) bitcast (%struct.g* @h to %struct.a*))
19+
store i32 %call, i32* @l, align 4
20+
ret void
21+
}
22+
23+
; Function Attrs: uwtable
24+
define internal void @_GLOBAL__sub_I_bug48055.cc() {
25+
entry:
26+
call void @__cxx_global_var_init()
27+
ret void
28+
}
29+

0 commit comments

Comments
 (0)