2017-03-23 26 views
2

我有两个全局结构类型声明,其中一个是另一个的“子类型”。我想定义一个全局变量,更具体的类型,但让全局变量有更多的普通型:在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*

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

回答

0

它的工作原理定义别名:

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

我不知道是否有是摒弃了中间值@foo的方式。