How to tell clang that my LLVM Target should use 16-bit 'int'?

笑着哭i 提交于 2019-12-06 08:49:12

SOLVED: clang takes the size of int (and other types) from its own Target, defined in clang/lib/Basics/Targets.cpp. The native size setting "-n16" is not sufficient to override the (default?) i32 setting. Instead:

IntWidth = 32;
IntAlign = 32;

in my target's constructor does the trick.

This also solves the strange 'unhandled return type i16' issue. Don't know why.

I strongly suggest making a habit of using the ISO/IEC 9899 include files <stdint.h> and <stdbool.h>. In your case, you can then declare

int16_t foo(int16_t a, int16_t b) { return a + b; }

and you are guaranteed that the variables and return values are 16-bit signed integers, irrespective of the target processor. Look at the file contents, or the ISO document appendix B.17 (search for ISO/IEC 9899 and you will find the pdf document easily), to see all the type options.

These include files (together with prefixes on variable names like u16foo and i32bar to clarify to me the size and signedness of identifiers) have saved my skin too many times to count.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!