[llvm-commits] CVS: llvm-gcc/gcc/llvm-types.c

John Criswell criswell at cs.uiuc.edu
Mon Nov 29 13:29:45 PST 2004



Changes in directory llvm-gcc/gcc:

llvm-types.c updated: 1.17 -> 1.18
---
Log message:

Fix a bug on Sparc where this memory allocation failed, preventing llvm-gcc
from compiling.
The original code would underflow if the number of elements was zero, and
there's at least one call to it in llvm-expand.c that does that.


---
Diffs of the changes:  (+12 -2)

Index: llvm-gcc/gcc/llvm-types.c
diff -u llvm-gcc/gcc/llvm-types.c:1.17 llvm-gcc/gcc/llvm-types.c:1.18
--- llvm-gcc/gcc/llvm-types.c:1.17	Sun Nov 28 15:17:34 2004
+++ llvm-gcc/gcc/llvm-types.c	Mon Nov 29 15:29:29 2004
@@ -302,8 +302,18 @@
 }
 
 llvm_type *llvm_type_create_struct(unsigned NumElements, unsigned Size) {
-  llvm_type *Result = (llvm_type*)xcalloc(1, sizeof(llvm_type) +
-					  (NumElements-1)*sizeof(llvm_type*));
+  /* The amount of space  we need to allocate for the type */
+  unsigned type_size;
+
+  /*
+   * Determine the amount of memory needed for the type.  Note that
+   * NumElements may be zero, so avoid integer underflow.
+   */
+  type_size = sizeof (llvm_type);
+  type_size += ((NumElements) ? (NumElements-1)*sizeof(llvm_type*) : 0);
+
+  /* Do the memory allocation and type initialization. */
+  llvm_type * Result = (llvm_type*)xcalloc(1, type_size);
   Result->ID = StructTyID;
   Result->NumElements = NumElements;
   Result->x.Struct.Size = Size;






More information about the llvm-commits mailing list