From a349539f8732a90c13bdc8bf3e9760a8fbdad14c Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 13 Dec 2011 01:07:07 +0000 Subject: [PATCH] Use the example from clang, not the GCC frontend, which doesn't exist anymore. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146461 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/LangRef.html | 49 ++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/LangRef.html b/docs/LangRef.html index b4751e8189e..fb1c768d8f6 100644 --- a/docs/LangRef.html +++ b/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
 }
 
Semantics:
-

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