我正在尝试在MinGW-64 lljvm下编译,这是一个不那么大的程序。但是我被困在一个让我疯狂的错误上。
代码如下:
backend.h
class JVMWritter {
...
static char id;
...
};
backend.cpp
char JVMWriter::id = 0;
JVMWriter::JVMWriter(): FunctionPass(&id) {}
现在,FunctionPass在Pass.h中声明如下:
Pass.h
class FunctionPass {
...
explicit FunctionPass (char &pid) : <initialization here> {}
...
};
当我尝试编译时,我不断收到以下错误:
backend.cpp:39:16: error: invalid conversion from 'char*' to 'char' [-fpermissive]
FunctionPass(&JVMWriter::id), targetData(td), out(o), classname(cls), debug(dbg) {
^~~~~~~~~~
In file included from D:/dev/msys64/mingw64/include/llvm/IR/DataLayout.h:27:0,
from D:/dev/msys64/mingw64/include/llvm/IR/Module.h:20,
from D:/dev/msys64/mingw64/include/llvm/IR/PassManager.h:46,
from D:/dev/msys64/mingw64/include/llvm/Analysis/LoopInfo.h:47,
from backend.h:29,
from backend.cpp:23:
D:/dev/msys64/mingw64/include/llvm/Pass.h:300:12: note: initializing argument 1 of 'llvm::FunctionPass::FunctionPass(char&)'
explicit FunctionPass(char &pid) : Pass(PT_Function, pid) {}
^~~~~~~~~~~~
backend.cpp:39:16: error: cannot bind rvalue '(char)(& JVMWriter::id)' to 'char&'
FunctionPass(&JVMWriter::id), targetData(td), out(o), classname(cls), debug(dbg) {
^~~~~~~~~~
In file included from D:/dev/msys64/mingw64/include/llvm/Pass.h:388:0,
from D:/dev/msys64/mingw64/include/llvm/IR/DataLayout.h:27,
from D:/dev/msys64/mingw64/include/llvm/IR/Module.h:20,
from D:/dev/msys64/mingw64/include/llvm/IR/PassManager.h:46,
from D:/dev/msys64/mingw64/include/llvm/Analysis/LoopInfo.h:47,
from backend.h:29,
from backend.cpp:23:
D:/dev/msys64/mingw64/include/llvm/PassAnalysisSupport.h: In instantiation of 'llvm::AnalysisUsage& llvm::AnalysisUsage::addRequired() [with PassClass = llvm::LoopInfo]':
backend.cpp:52:27: required from here
D:/dev/msys64/mingw64/include/llvm/PassAnalysisSupport.h:61:39: error: 'ID' is not a member of 'llvm::LoopInfo'
return addRequiredID(PassClass::ID);
我明显的问题:为什么抱怨我尝试进行无效转换?我看到这些片段没有这样的尝试。
答案 0 :(得分:0)
将FunctionPass(&id)
替换为FunctionPass(id)
。
答案 1 :(得分:0)
char & pid
声明pid
作为对char
的引用,同时传递&id
,这是指向char
的指针。