summaryrefslogtreecommitdiffstats
path: root/gcc/testsuite/gcc.dg/builtins-13.c
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-04-14 02:55:31 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-04-14 02:55:31 +0000
commit32ef1cd2a46ec9149543ffcd1f58ed438546c634 (patch)
treedd3d088e82001ccf169ac01fc9027aa8ec737b49 /gcc/testsuite/gcc.dg/builtins-13.c
parent83cdf34abdf3d9d6751156e88b38fa429c8f1db7 (diff)
downloadppe42-gcc-32ef1cd2a46ec9149543ffcd1f58ed438546c634.tar.gz
ppe42-gcc-32ef1cd2a46ec9149543ffcd1f58ed438546c634.zip
* builtin-types.def (BT_FN_STRING_CONST_STRING): New builtin type.
(BT_FN_PTR_SIZE_SIZE): Likewise. * builtins.def (BUILT_IN_MALLOC, BUILT_IN_CALLOC, BUILT_IN_STRDUP): New built-in functions for malloc, calloc and strdup respectively. * calls.c (special_function_p): No need to handle malloc-like functions any longer. ECF_MALLOC is set via built-in attributes. * c-decl.c (duplicate_decls): Preserve pure and malloc attributes. * cp/decl.c (duplicate_decls): Preserve pure and malloc attributes. * f/com.c (duplicate_decls): Preserve pure and malloc attributes. * doc/extend.texi: Document these new built-in functions. * gcc.dg/builtins-13.c: New test case. * gcc.dg/builtins-14.c: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@65560 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/builtins-13.c')
-rw-r--r--gcc/testsuite/gcc.dg/builtins-13.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/builtins-13.c b/gcc/testsuite/gcc.dg/builtins-13.c
new file mode 100644
index 00000000000..befcd3447ad
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtins-13.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2003 Free Software Foundation.
+
+ Verify that the malloc-like __builtin_ allocation functions are
+ correctly aliased by the compiler.
+
+ Written by Roger Sayle, 12th April 2003. */
+
+/* { dg-do link } */
+
+typedef __SIZE_TYPE__ size_t;
+
+extern void abort (void);
+extern void *malloc (size_t);
+extern void *calloc (size_t,size_t);
+
+extern void link_error (void);
+
+static int x;
+
+void test1(void)
+{
+ int *ptr1, *ptr2;
+
+ ptr1 = &x;
+ ptr2 = (int*) malloc (sizeof (int));
+
+ *ptr1 = 12;
+ *ptr2 = 8;
+
+ if (*ptr1 != 12)
+ link_error();
+}
+
+void test2(void)
+{
+ int *ptr1, *ptr2;
+
+ ptr1 = &x;
+ ptr2 = (int*) calloc (1, sizeof (int));
+
+ *ptr1 = 12;
+ *ptr2 = 8;
+
+ if (*ptr1 != 12)
+ link_error ();
+}
+
+int main()
+{
+ test1 ();
+ test2 ();
+ return 0;
+}
+
+#ifndef __OPTIMIZE__
+void link_error (void)
+{
+ abort ();
+}
+#endif
+
OpenPOWER on IntegriCloud