diff --git a/llvm/docs/LangRef.html b/llvm/docs/LangRef.html index b4751e8189e3..fb1c768d8f6e 100644 --- a/llvm/docs/LangRef.html +++ b/llvm/docs/LangRef.html @@ -5119,43 +5119,44 @@ int *foo(struct ST *s) { } -
The LLVM code generated by the GCC frontend is:
+The LLVM code generated by Clang is:
-%RT = type { i8 , [10 x [20 x i32]], i8 } -%ST = type { i32, double, %RT } +%struct.RT = type { i8, [10 x [20 x i32]], i8 } +%struct.ST = type { i32, double, %struct.RT } -define i32* @foo(%ST* %s) { +define i32* @foo(%struct.ST* %s) nounwind uwtable readnone optsize ssp { entry: - %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13 - ret i32* %reg + %arrayidx = getelementptr inbounds %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13 + ret i32* %arrayidx }
In the example above, the first index is indexing into the '%ST*' - type, which is a pointer, yielding a '%ST' = '{ i32, double, %RT - }' type, a structure. The second index indexes into the third element - of the structure, yielding a '%RT' = '{ i8 , [10 x [20 x i32]], - i8 }' type, another structure. The third index indexes into the second - element of the structure, yielding a '[10 x [20 x i32]]' type, an - array. The two dimensions of the array are subscripted into, yielding an - 'i32' type. The 'getelementptr' instruction returns a - pointer to this element, thus computing a value of 'i32*' type.
+In the example above, the first index is indexing into the + '%struct.ST*' type, which is a pointer, yielding a + '%struct.ST' = '{ i32, double, %struct.RT }' type, a + structure. The second index indexes into the third element of the structure, + yielding a '%struct.RT' = '{ i8 , [10 x [20 x i32]], i8 }' + type, another structure. The third index indexes into the second element of + the structure, yielding a '[10 x [20 x i32]]' type, an array. The + two dimensions of the array are subscripted into, yielding an 'i32' + type. The 'getelementptr' instruction returns a pointer to this + element, thus computing a value of 'i32*' type.
Note that it is perfectly legal to index partially through a structure, returning a pointer to an inner element. Because of this, the LLVM code for the given testcase is equivalent to:
-- define i32* @foo(%ST* %s) { - %t1 = getelementptr %ST* %s, i32 1 ; yields %ST*:%t1 - %t2 = getelementptr %ST* %t1, i32 0, i32 2 ; yields %RT*:%t2 - %t3 = getelementptr %RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3 - %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4 - %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5 - ret i32* %t5 - } ++define i32* @foo(%struct.ST* %s) { + %t1 = getelementptr %struct.ST* %s, i32 1 ; yields %struct.ST*:%t1 + %t2 = getelementptr %struct.ST* %t1, i32 0, i32 2 ; yields %struct.RT*:%t2 + %t3 = getelementptr %struct.RT* %t2, i32 0, i32 1 ; yields [10 x [20 x i32]]*:%t3 + %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 ; yields [20 x i32]*:%t4 + %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 ; yields i32*:%t5 + ret i32* %t5 +}If the inbounds keyword is present, the result value of the