C++ 所有东西都是LLVM IR中的指针吗?

C++ 所有东西都是LLVM IR中的指针吗?,c++,llvm,llvm-ir,C++,Llvm,Llvm Ir,我迭代了程序的全局变量,并对它们的类型感兴趣 对于测试,例如: #include <stdio.h> int i=0; int main(){ printf("lala %d \n",i); return 0; } 我的代码: for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { std::cout << I-&

我迭代了程序的全局变量,并对它们的类型感兴趣

对于测试,例如:

#include <stdio.h>

int i=0;
int main(){
    printf("lala %d \n",i);
    return 0;
}
我的代码:

for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
            std::cout << I->getName().str() << " Type: "<< I->getType()->getTypeID() << std::endl;

            if (I->getType()->isPointerTy() ) {
                std::string o1;
                {
                    raw_string_ostream os1(o1);
                    I->printAsOperand(os1, true);
                }
                char* stackLoc = new char[50];
                sprintf(stackLoc, "Stack%d", StackCounter++);
                errs() << "StackLock: " << stackLoc << "\n";
                errs() << "Function Argument: " << o1 << "\n";
            }

        }
for(Module::global_迭代器I=M.global_begin(),E=M.global_end();I!=E;++I){
std::cout getName().str()getTypeID()getType()->isPointerTy()){
std::字符串o1;
{
原始字符串os1(o1);
I->printAsOperand(os1,true);
}
char*stackLoc=新字符[50];
sprintf(stackLoc,“堆栈%d”,StackCounter++);
errs()根据,全局变量定义在编译时而不是运行时分配的内存区域,并且它们必须初始化

作为SSA值,全局变量定义位于 范围(即它们支配)程序中的所有基本块。全局 变量总是定义指向其“内容”类型的指针,因为它们 描述一个内存区域,LLVM中的所有内存对象都是 通过指针访问


要获取全局变量的实际类型,由于全局变量的LLVM IR内部类型是指针,因此
可用于获取指针的指针对象类型,因为指针类型是派生类型。

尝试打印由Clang生成的程序集。您将看到全局变量和大多数局部变量都是通过指针访问的内存区域。
for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
            std::cout << I->getName().str() << " Type: "<< I->getType()->getTypeID() << std::endl;

            if (I->getType()->isPointerTy() ) {
                std::string o1;
                {
                    raw_string_ostream os1(o1);
                    I->printAsOperand(os1, true);
                }
                char* stackLoc = new char[50];
                sprintf(stackLoc, "Stack%d", StackCounter++);
                errs() << "StackLock: " << stackLoc << "\n";
                errs() << "Function Argument: " << o1 << "\n";
            }

        }