llvm: `module.NewTypeDef` has unexpected side effects

The following code has unexpected side effects on the convenience types:

m.NewTypeDef("hello", types.I64)

Because NewTypeDef sets the type’s name. Which is okay, but next time if I use types.I64 it will have name hello since, the convenience type is a pointer. To be honest, I don’t really have an idea how to solve this. But it took me about 3 hours of debugging till I figured out why my i64 types called hello in LLVM IR.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

hey Robin, no worries, I will work around it 😃 thanks much.

Genius. I totally overlooked the fact that types.Type is an interface that can be implemented. Thanks so much for the example! Yeah sure, I just open-sourced it here: https://github.com/klvnptr/k I welcome any feedback.

Hey @mewmew

Highly appreciate your feedback. Yes, I’m writing an LLVM frontend for my hobby programming language 😃 Btw. your library is pretty stunning. I wouldn’t even try to guess how much time it takes to map out the entire LLVM IR syntax.

Thanks for the suggestion. I will go with types.NewInt(64).

While we are at it. Whats to way to create an alias of an alias? Similar to this.

typedef i64 hello;
typedef hello world;

Thanks Peter

wow, I don’t even remember there has NewInt(64)

Cloning is painful in Go, this is also why we have no idea how to provide a general solution in this case.