2017-03-23 24 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的方式。