0

I have cases where I need to alloca space for an object with size, layout, and alignment that is unknown at compile time. These values are accessible at runtime, but as far as I can tell, the align attribute on an alloca instruction must be compile-time constant, rather than an instruction argument.

How can I safely obtain an align value which will be strict enough to align to any primitive data type on the target platform? (The equivalent of this in C++ would be alignof(std::max_align_t)).

trbabb
  • 1,894
  • 18
  • 35
  • The alignment [is available at compile time](https://llvm.org/doxygen/classllvm_1_1Module.html#a6d883605206368bc536cc9ded97209b8), you have to write a loop and compute the maximum yourself. – arnt Sep 24 '20 at 06:54
  • @arnt What would I loop over? What's sufficient to find the maximum alignment? – trbabb Sep 24 '20 at 07:14
  • The types in your language, and in the loop you can [ask DataLayout about that type's alignment](https://llvm.org/doxygen/classllvm_1_1DataLayout.html#a086b669374187a18c0744d8373bcfd1a). – arnt Sep 24 '20 at 07:18

0 Answers0