[LLVMbugs] [Bug 54] C front-end miscompiles unsigned enums whose LLVM types are signed

bugzilla-daemon at zion.cs.uiuc.edu bugzilla-daemon at zion.cs.uiuc.edu
Mon Nov 17 22:22:10 PST 2003


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

sabre at nondot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         OS/Version|Linux                       |All
           Platform|PC                          |All
         Resolution|                            |FIXED
            Summary|GNU Make is miscompiled     |C front-end miscompiles
                   |                            |unsigned enums whose LLVM
                   |                            |types are signed
   Target Milestone|---                         |1.1
            Version|trunk                       |1.0



------- Additional Comments From sabre at nondot.org  2003-11-18 00:22 -------


Here's the fix:

$ diff -u llvm-expand.c~ llvm-expand.c
--- llvm-expand.c~      2003-11-13 10:24:18.000000000 -0600
+++ llvm-expand.c       2003-11-18 00:17:24.000000000 -0600
@@ -4972,8 +4972,20 @@
       op0 = llvm_expand_lvalue_expr(Fn, exp, &BitStart, &BitSize);
 
       if (!isDestTyComposite) {  /* Return a normal scalar by loading it */
+        unsigned ResultBitSize;
         Result = append_inst(Fn, create_load_inst("tmp", op0, expVolatile));
 
+        ResultBitSize = llvm_type_get_size(Result->Ty)*8;
+
+        if (BitStart != 0 || BitStart+BitSize != ResultBitSize) {
+          llvm_type *ResultTy = llvm_type_get_integer(ResultBitSize,
+                                                TREE_UNSIGNED(TREE_TYPE(exp)));
+          /* Make sure that the value we are dealing with is of the right
+           * signedness.
+           */
+          Result = cast_if_type_not_equal(Fn, Result, ResultTy);
+        }
+
         /* If this is a read of a bitfield value, we have to mask and shift the
          * cruft out.
          */

We now happily compile this to:
int %main(int %argc.1, sbyte** %argv.1) {
entry:
        call void %__main( )
        %tmp.18 = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([4 x
sbyte]* %.str_1, long 0, long 0) )             ; <int> [#uses=0]
        ret int 0
}

Which is just as optimized, but actually correct this time. :)

MAJOR thanks to Brian for reducing this nasty nasty bug for me!

-Chris




------- 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