This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/20638] New: [3.4,4.0,4.1] gcc doesn't take advantage of attribute malloc on alloca
- From: "ghazi at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 25 Mar 2005 20:02:20 -0000
- Subject: [Bug middle-end/20638] New: [3.4,4.0,4.1] gcc doesn't take advantage of attribute malloc on alloca
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The alloca builtin has the attribute __malloc__ set on it but GCC doesn't seem
to take advantage of that fact for optimization. The testcase gcc.dg/builtins-
13.c tests an optimization when calling the malloc/calloc functions. When I
try a similar case for alloca such as in the patch below, the testcase fails.
diff -rup orig/egcc-CVS20050323/gcc/testsuite/gcc.dg/builtins-13.c egcc-
CVS20050323/gcc/testsuite/gcc.dg/builtins-13.c
--- orig/egcc-CVS20050323/gcc/testsuite/gcc.dg/builtins-13.c 2003-04-13
22:55:31.000000000 -0400
+++ egcc-CVS20050323/gcc/testsuite/gcc.dg/builtins-13.c 2005-03-24
17:16:50.098461000 -0500
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 Free Software Foundation.
+/* Copyright (C) 2003, 2005 Free Software Foundation.
Verify that the malloc-like __builtin_ allocation functions are
correctly aliased by the compiler.
@@ -12,6 +12,7 @@ typedef __SIZE_TYPE__ size_t;
extern void abort (void);
extern void *malloc (size_t);
extern void *calloc (size_t,size_t);
+extern void *alloca (size_t);
extern void link_error (void);
@@ -45,10 +46,25 @@ void test2(void)
link_error ();
}
+void test3(void)
+{
+ int *ptr1, *ptr2;
+
+ ptr1 = &x;
+ ptr2 = (int*) alloca (sizeof (int));
+
+ *ptr1 = 12;
+ *ptr2 = 8;
+
+ if (*ptr1 != 12)
+ link_error();
+}
+
int main()
{
test1 ();
test2 ();
+ test3 ();
return 0;
}
--
Summary: [3.4,4.0,4.1] gcc doesn't take advantage of attribute
malloc on alloca
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ghazi at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org,roger at eyesopen dot
com
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20638