2

假设我有以下 C 结构定义:

struct stringStructure
{
    char *stringVariable;
};

对于上述情况,Clang 生成以下 LLVM IR:

%struct.stringStructure = type { i8* }

...包括我定义中的所有内容,除了变量 identifier stringVariable

我想找到某种方法将标识符导出到生成的 LLVM IR 中,以便我可以从我的应用程序(使用 LLVM C++ API)中按名称引用它。

我试过添加annotate属性,如下:

    char *stringVariable __attribute__((annotate("stringVariable")));

...但是注释似乎没有通过(结构仍然只是定义为type { i8* })。

有任何想法吗?

4

1 回答 1

1

LLVM IR 没有保留源语言的许多特性。您可以通过以下代码进行检查

struct Foo {
   char *a;
};

struct Bar {
   char *a;
};

因为 LLVM 中的类型在结构上是等价的,所以只会发出一种类型。如果要保留有关源代码构造的任意信息,则必须发出/使用调试信息。

于 2011-02-07T07:23:07.937 回答