[llvm-branch-commits] [llvm-gcc-branch] r69003 - /llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp

Bill Wendling isanbard at gmail.com
Mon Apr 13 16:26:17 PDT 2009


Author: void
Date: Mon Apr 13 18:26:13 2009
New Revision: 69003

URL: http://llvm.org/viewvc/llvm-project?rev=69003&view=rev
Log:
--- Merging (from foreign repository) r68968 into '.':
U    gcc/llvm-convert.cpp

fix TreeConstantToLLVM::ConvertINTEGER_CST to correctly handle
INTEGER_CST's that are 128-bits in size instead of silently
discarding the top bits.  This allows us to compile:

__uint128_t test2() {
  const __uint128_t c_zero = ~0;
  return c_zero;
}
__uint128_t test1() {
  const __uint128_t c_zero = 1234;
  return c_zero;
}

into:

define i128 @test2() nounwind readnone {
entry:
        ret i128 -1
}

define i128 @test1() nounwind readnone {
entry:
        ret i128 1234
}

instead of:

define i128 @test2() nounwind readnone {
entry:
        ret i128 18446744073709551615
}
define i128 @test1() nounwind readnone {
entry:
        ret i128 1234
}

This fixes PR3975.

Modified:
    llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp?rev=69003&r1=69002&r2=69003&view=diff

==============================================================================
--- llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/branches/Apple/Dib/gcc/llvm-convert.cpp Mon Apr 13 18:26:13 2009
@@ -6435,12 +6435,22 @@
 }
 
 Constant *TreeConstantToLLVM::ConvertINTEGER_CST(tree exp) {
-  // Convert it to a uint64_t.
-  uint64_t IntValue = getINTEGER_CSTVal(exp);
+  const Type *Ty = ConvertType(TREE_TYPE(exp));
+  
+  // Handle i128 specially.
+  if (const IntegerType *IT = dyn_cast<IntegerType>(Ty)) {
+    if (IT->getBitWidth() == 128) {
+      // GCC only supports i128 on 64-bit systems.
+      assert(HOST_BITS_PER_WIDE_INT == 64 &&
+             "i128 only supported on 64-bit system");
+      uint64_t Bits[] = { TREE_INT_CST_LOW(exp), TREE_INT_CST_HIGH(exp) };
+      return ConstantInt::get(APInt(128, 2, Bits));
+    }
+  }
   
   // Build the value as a ulong constant, then constant fold it to the right
   // type.  This handles overflow and other things appropriately.
-  const Type *Ty = ConvertType(TREE_TYPE(exp));
+  uint64_t IntValue = getINTEGER_CSTVal(exp);
   ConstantInt *C = ConstantInt::get(Type::Int64Ty, IntValue);
   // The destination type can be a pointer, integer or floating point 
   // so we need a generalized cast here





More information about the llvm-branch-commits mailing list