【问题标题】:Cast a global definition in LLVM IR在 LLVM IR 中投射全局定义
【发布时间】:2017-08-16 09:47:57
【问题描述】:

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

我试过了:

%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*

理想情况下是一个定义?

【问题讨论】:

    标签: casting llvm llvm-ir


    【解决方案1】:

    它可以定义一个别名:

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

    不知道有没有办法去掉中间值@foo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-17
      相关资源
      最近更新 更多