Unsupport global vars with struct type including opaque
MODIFY
llvm_util/utils.cpp
llvm_util/utils.cpp
@@ -42,6 +42,20 @@ ostream *out;
const llvm::DataLayout *DL;
+bool hasOpaqueType(llvm::Type *ty) {
+ if (auto aty = llvm::dyn_cast<llvm::StructType>(ty)) {
+ if (aty->isOpaque())
+ return true;
+
+ for (auto elemty : aty->elements())
+ if (hasOpaqueType(elemty))
+ return true;
+ } else if (auto sty = llvm::dyn_cast<llvm::SequentialType>(ty))
+ return hasOpaqueType(sty->getElementType());
+
+ return false;
+}
+
}
namespace llvm_util {
@@ -255,11 +269,9 @@ Value* get_operand(llvm::Value *v,
if (gvar)
return gvar;
- if (auto st = dyn_cast<llvm::StructType>(gv->getValueType())) {
- if (st->isOpaque())
+ if (hasOpaqueType(gv->getValueType()))
// TODO: Global variable of opaque type is not supported.
return nullptr;
- }
unsigned size = DL->getTypeAllocSize(gv->getValueType());
unsigned align = gv->getPointerAlignment(*DL).valueOrOne().value();

ADD
tests/alive-tv/memory/aggregate-empty.src.ll
+@g7 = constant {[0 x i32], [0 x i8], {}*} { [0 x i32] undef, [0 x i8] undef, {}* null }
+
+define i64* @test_leading_zero_size_elems() {
+ %v = load i64*, i64** bitcast ({[0 x i32], [0 x i8], {}*}* @g7 to i64**)
+ ret i64* %v
+}
+
+

ADD
tests/alive-tv/memory/aggregate-empty.tgt.ll
+@g7 = constant {[0 x i32], [0 x i8], {}*} { [0 x i32] undef, [0 x i8] undef, {}* null }
+
+define i64* @test_leading_zero_size_elems() {
+ ret i64* null
+}

Unsupport global vars with struct type including opaque