[cfe-commits] r109762 - in /cfe/trunk: lib/CodeGen/TargetInfo.cpp test/CodeGen/x86_64-arguments.c

Chris Lattner sabre at nondot.org
Thu Jul 29 10:34:39 PDT 2010


Author: lattner
Date: Thu Jul 29 12:34:39 2010
New Revision: 109762

URL: http://llvm.org/viewvc/llvm-project?rev=109762&view=rev
Log:
handle a case where we could access off the end of a function
that Eli pointed out, rdar://8249586

Modified:
    cfe/trunk/lib/CodeGen/TargetInfo.cpp
    cfe/trunk/test/CodeGen/x86_64-arguments.c

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=109762&r1=109761&r2=109762&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Thu Jul 29 12:34:39 2010
@@ -1358,18 +1358,15 @@
   
   // Okay, we don't have any better idea of what to pass, so we pass this in an
   // integer register that isn't too big to fit the rest of the struct.
-  uint64_t TySizeInBytes =
-    getContext().getTypeSizeInChars(SourceTy).getQuantity();
+  unsigned TySizeInBytes =
+    (unsigned)getContext().getTypeSizeInChars(SourceTy).getQuantity();
 
+  assert(TySizeInBytes != SourceOffset && "Empty field?");
+  
   // It is always safe to classify this as an integer type up to i64 that
   // isn't larger than the structure.
-  switch (unsigned(TySizeInBytes-SourceOffset)) {
-  case 1:  return llvm::Type::getInt8Ty(getVMContext());
-  case 2:  return llvm::Type::getInt16Ty(getVMContext());
-  case 3:
-  case 4:  return llvm::Type::getInt32Ty(getVMContext());
-  default: return llvm::Type::getInt64Ty(getVMContext());
-  }  
+  return llvm::IntegerType::get(getVMContext(),
+                                std::min(TySizeInBytes-SourceOffset, 8U)*8);
 }
 
 ABIArgInfo X86_64ABIInfo::

Modified: cfe/trunk/test/CodeGen/x86_64-arguments.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86_64-arguments.c?rev=109762&r1=109761&r2=109762&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/x86_64-arguments.c (original)
+++ cfe/trunk/test/CodeGen/x86_64-arguments.c Thu Jul 29 12:34:39 2010
@@ -204,3 +204,9 @@
 void f29a(struct f29a A) {
   // CHECK: define void @f29a(double %A.coerce0, i32 %A.coerce1)
 }
+
+// rdar://8249586
+struct S0 { char f0[8]; char f2; char f3; char f4; };
+void f30(struct S0 p_4) {
+  // CHECK: define void @f30(i64 %p_4.coerce0, i24 %p_4.coerce1)
+}





More information about the cfe-commits mailing list