How to preserve struct member identifiers when compiling to LLVM IR with Clang?

发布于 2022-09-06 08:44:57 字数 867 浏览 23 评论 0

Say I have the following C structure definition:

struct stringStructure
{
    char *stringVariable;
};

For the above, Clang produces the following LLVM IR:

%struct.stringStructure = type { i8* }

...which includes everything in my definition except the variable identifier stringVariable.

I'd like to find some way to export the identifier into the generated LLVM IR, so that I can refer to it by name from my application (which uses the LLVM C++ API).

I've tried adding the annotate attribute, as follows:

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

...but the annotation doesn't seem to make it through (the structure is still just defined as type { i8* }).

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪少女 2022-09-13 08:44:57

LLVM IR does not preserve many features of the source language. You can check this via the code like

struct Foo {
   char *a;
};

struct Bar {
   char *a;
};

Only one type will be emitted at all since types in LLVM are structurally equivalent. If you want to preserve arbitrary information about the constructs of your source code you have to emit/use debug information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文