在LLVM IR中转换全局定义

时间:2017-03-23 17:20:24

标签: casting llvm llvm-ir

我有两个全局结构类型声明,其中一个是另一个的“子类型”。我想用更具体的类型定义一个全局变量,但让全局变量具有更通用的类型:

我试过了:

%hs = type { %hs* (%hs*)* }
%dc = type { %hs* (%hs*)*, i64, [1 x %hs*] }

@boring = constant %hs { %hs* (%hs*)* null }

; this works, but has type %dc* instead of %hs*
@foo = constant %dc { %hs* (%hs*)* null, i64 1, [1 x %hs*] [ %hs* @boring ] }

; this does not
@bar = constant %hs bitcast (%dc @foo to %hs)

; this tests that @bar indeed has the desired type
@test = constant %dc { %hs* (%hs*)* null, i64 1, [1 x %hs*] [ %hs* @bar ] }

但是

失败了
llc-4.0: foo.ll:10:34: error: global variable reference must have pointer type
@bar = constant %hs bitcast (%dc @foo to %hs)

是否可以按上述方式定义@bar,但类型为hs*

理想情况下,在一个定义中?

1 个答案:

答案 0 :(得分:0)

它可以定义别名:

@bar = alias %hs, %hs* bitcast (%dc* @foo to %hs*)

我不知道是否有办法取消中间值@foo