In summary, here’s some things to always remember about the GetElementPtr instruction:html
- The GEP instruction never accesses memory, it only provides pointer computations.
- The first operand to the GEP instruction is always a pointer and it must be indexed.
- There are no superfluous indices for the GEP instruction.
- Trailing zero indices are superfluous for pointer aliasing, but not for the types of the pointers.
- Leading zero indices are not superfluous for pointer aliasing nor the types of the pointers.
這幾條是《The Often Misunderstood GEP Instruction》文檔最後對GEP指令的總結,原文檔地址爲:ide
http://llvm.org/docs/GetElementPtr.html
這幾天基本上涵蓋了GEP使用中須要注意的問題,現翻譯以下:
1. GEP指令毫不容許操做內存,它只能提供指針相關的計算。
2. GEP指令的第一個操做數一般是一個指針,並且它一般是能夠索引的。
3. GEP指令沒有多餘的無用的下標索引。
4. 下標索引尾部的0對指針的混用是沒區別的,可是對指針類型的混用確是有區別的。
(譯者注:此處指的是下標索引尾部有0和沒0的混用。)
5. 下標索引頭部的0對指針的混用和指針類型的混用都是有區別的。
(譯者注:此處指的是下標索引頭部有0和沒0的混用。)翻譯