You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LLVM 15.0.2中‘CurByte未声明’错误及等价代码替代方案

LLVM 15.0.2中STI.setByteCtr(CurByte)的等价替换方案

在LLVM 9.0.0的llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp文件中,存在代码STI.setByteCtr(CurByte);,用于更新MCSubtargetInfo类中要发射的实际字节数。但在LLVM 15.0.2版本中,CurByte变量被移除,部分场景下该参数被省略或替换为StartByte,以下是对应的等价命令分析:

LLVM 9.0.0相关代码片段

if ((TSFlags & X86II::OpMapMask) == X86II::ThreeDNow)
  EmitByte(X86II::getBaseOpcodeFor(TSFlags), CurByte, OS);

#ifndef NDEBUG
// FIXME: Verify.
if (/*!Desc.isVariadic() &&*/ CurOp != NumOps) {
  errs() << "Cannot encode all operands of: ";
  MI.dump();
  errs() << '\n';
  abort();
}
#endif

// Koo: Update the actual bytes to be emitted in MCSubtargetInfo class
STI.setByteCtr(CurByte);

LLVM 15.0.2对应代码片段

if ((TSFlags & X86II::OpMapMask) == X86II::ThreeDNow)
  emitByte(X86II::getBaseOpcodeFor(TSFlags), OS);

assert(OS.tell() - StartByte <= 15 &&
       "The size of instruction must be no longer than 15.");
#ifndef NDEBUG
// FIXME: Verify.
if (/*!Desc.isVariadic() &&*/ CurOp != NumOps) {
  errs() << "Cannot encode all operands of: ";
  MI.dump();
  errs() << '\n';
  abort();
}
#endif

// Koo: Update the actual bytes to be emitted in MCSubtargetInfo class
STI.setByteCtr(CurByte);

等价命令说明

从代码对比可以看出,LLVM 15.0.2中不再维护CurByte变量统计已发射字节数,转而通过输出流OS的当前位置与StartByte的差值计算指令长度(即OS.tell() - StartByte)。原STI.setByteCtr(CurByte);的等价命令为:

STI.setByteCtr(OS.tell() - StartByte);

注:你提供的LLVM 15.0.2代码片段中仍保留STI.setByteCtr(CurByte);,这属于未清理的遗留代码,实际逻辑中CurByte已被移除,正确的替换方式是使用OS.tell() - StartByte作为参数。

内容的提问来源于stack exchange,提问作者NobinPegasus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 17:52:47