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
This commit is contained in:
Bill Wendling
2011-12-13 01:07:07 +00:00
parent d56ef8d709
commit a349539f87

View File

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