[LLVMbugs] [Bug 84] C front-end doesn't emit getelementptr for address of array element

bugzilla-daemon at zion.cs.uiuc.edu bugzilla-daemon at zion.cs.uiuc.edu
Sat Nov 8 15:07:50 PST 2003


http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=84

sabre at nondot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From sabre at nondot.org  2003-11-08 17:07 -------
Wow, this is certainly QUITE amazing.  The reason that the problem resurfaced in
the C++ front-end is that it contains a COPY of a huge amount of code from the C
frontend, including this hunk of code.  Nasty nasty nasty.  At least this one
was easy to fix.

Here's the patch:

$ diff -u cp/typeck.c~ cp/typeck.c
--- typeck.c~   2003-08-27 16:50:48.000000000 -0500
+++ typeck.c    2003-11-08 17:05:24.000000000 -0600
@@ -3882,7 +3882,7 @@
        }
 
       /* For &x[y], return x+y */
-      if (TREE_CODE (arg) == ARRAY_REF)
+      if (TREE_CODE (arg) == ARRAY_REF && !EMIT_LLVM)
        {
          if (!cxx_mark_addressable (TREE_OPERAND (arg, 0)))
            return error_mark_node;


The second testcase now generates the following code:
sbyte* %_ZN3foo7getAddrEj(%struct.foo* %this.1, uint %i.1) {
entry:          ; No predecessors!
        %tmp.3 = cast uint %i.1 to long         ; <long> [#uses=1]
        %tmp.4 = getelementptr %struct.foo* %this.1, long 0, ubyte 0, long
%tmp.3               ; <int*> [#uses=1]
        %tmp.5 = cast int* %tmp.4 to sbyte*             ; <sbyte*> [#uses=1]
        ret sbyte* %tmp.5
}




------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the llvm-bugs mailing list