How to distinguish signed and unsigned integer in LLVM

后端 未结 1 1213
-上瘾入骨i
-上瘾入骨i 2020-12-17 19:48

The LLVM project does not distinguish between signed and unsigned integers as described here. There are situations where you need to know if a particular variable should be

相关标签:
1条回答
  • 2020-12-17 20:12

    First of all, you have to be sure that you need inserting extra type meta-data since Clang already handles signed integer operations appropriately for example by using sdiv and srem rather than udev and urem.

    Additionally, It's possible to utilize that to implement some lightweight type-inference based on how the variables are accessed in the IR. Note that an operation like add doesn't need signdness info since it is based on two-complement representation.

    Otherwise, I think that the best way to do that is to modify the front-end (Clang) to add some custom DWARF debug info. Here is a link that might get you started.

    UPDATE: If your goal is to implement static-analysis directly on LLVM IR. This paper can offer a thorough discussion.

    Navas, J.A., Schachte, P., Søndergaard, H., Stuckey, P.J.: Signedness-agnostic program analysis: Precise integer bounds for low-level code. In: Jhala, R., Igarashi, A. (eds.) APLAS 2012. LNCS, vol. 7705, pp. 115–130. Springer, Heidelberg (2012)

    0 讨论(0)
提交回复
热议问题