Document gcov-io (PR gcov-profile/84735).
[official-gcc.git] / gcc / testsuite / gcc.dg / pr38902.c
blobd406526242fa8036d693d827dd95948f323f87bf
1 /* PR target/38902 */
2 /* { dg-do run } */
3 /* { dg-options "-O2 -fstack-protector" } */
4 /* { dg-require-effective-target fstack_protector } */
6 #ifdef DEBUG
7 #include <stdio.h>
8 #define debug(format, args...) printf (format , ## args)
9 #else
10 extern int sprintf (char *, const char *, ...);
11 #define debug(format, args...)
12 #endif
14 extern void abort (void);
18 Copyright (C) 2009 Canonical, Ltd.
19 Author: Kees Cook <kees@ubuntu.com>
20 License: GPLv3
22 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38616
23 https://bugs.launchpad.net/ubuntu/+source/gcc-4.3/+bug/316019
24 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38902
26 gcc -O2 -fstack-protector truncate.c -o truncate
28 Broken:
30 Only the first operation fails, so create a new function for each test.
31 Source must be local (literal or stack)
33 __builtin_memmove
34 __builtin_memcpy
35 __builtin_strcpy (optimized to __builtin_memcpy?)
36 sprintf (direct) (optmized to __builtin_strcpy?)
37 sprintf (via %s) (optmized to __builtin_strcpy?)
39 OK:
40 __builtin_strcat
41 sprintf (complex format)
45 char *heap = "1234567890abcdefghijklmnopqrstuvwxyz";
47 int failed = 0;
49 #define CHECK(count, a...) \
50 void test##count (void) \
51 { \
52 char *local = "1234567890abcdefghijklmnopqrstuvwxyz"; \
53 char buffer[1024]=""; \
54 a; \
55 if (__builtin_strcmp(buffer, heap) == 0) { \
56 debug("Okay(%d):\n\t%s\n", count, # a); \
57 } \
58 else { \
59 debug("Failed(%d):\n\t%s\n", count, # a); \
60 failed++; \
61 } \
65 CHECK( 0, __builtin_memcpy (buffer, "1234567890abcdefghijklmnopqrstuvwxyz", __builtin_strlen("1234567890abcdefghijklmnopqrstuvwxyz")+1); );
66 CHECK( 1, __builtin_memcpy (buffer, local, __builtin_strlen(local)+1); );
67 CHECK( 2, __builtin_memcpy (buffer, heap, __builtin_strlen(heap)+1); );
69 CHECK( 3, __builtin_memmove (buffer, "1234567890abcdefghijklmnopqrstuvwxyz", __builtin_strlen("1234567890abcdefghijklmnopqrstuvwxyz")+1); );
70 CHECK( 4, __builtin_memmove (buffer, local, __builtin_strlen(local)+1); );
71 CHECK( 5, __builtin_memmove (buffer, heap, __builtin_strlen(heap)+1); );
73 CHECK( 6, __builtin_strcpy (buffer, "1234567890abcdefghijklmnopqrstuvwxyz"); );
74 CHECK( 7, __builtin_strcpy (buffer, local); );
75 CHECK( 8, __builtin_strcpy (buffer, heap); );
77 CHECK( 9, sprintf (buffer, "1234567890abcdefghijklmnopqrstuvwxyz"); );
78 CHECK(10, sprintf (buffer, local); );
79 CHECK(11, sprintf (buffer, heap); );
81 CHECK(12, sprintf (buffer, "%s", "1234567890abcdefghijklmnopqrstuvwxyz"); );
82 CHECK(13, sprintf (buffer, "%s", local); );
83 CHECK(14, sprintf (buffer, "%s", heap); );
85 CHECK(15, __builtin_strcat (buffer, "1234567890abcdefghijklmnopqrstuvwxyz"); );
86 CHECK(16, __builtin_strcat (buffer, local); );
87 CHECK(17, __builtin_strcat (buffer, heap); );
89 void mongoose(void)
91 char buffer[1024]="";
92 sprintf (buffer, "%s", "1234567890abcdefghijklmnopqrstuvwxyz");;
93 if (__builtin_strcmp(buffer, heap) == 0) {
94 debug("Okay(%d):\n\t%s\n", -1, "sprintf (buffer, \"%s\", \"1234567890abcdefghijklmnopqrstuvwxyz\");");
96 else {
97 debug("Failed(%d):\n\t%s\n", -1, "sprintf (buffer, \"%s\", \"1234567890abcdefghijklmnopqrstuvwxyz\");");
98 failed++;
102 int main (int argc, char *argv[])
104 test0();
105 test1();
106 test2();
107 test3();
108 test4();
109 test5();
110 test6();
111 test7();
112 test8();
113 test9();
114 test10();
115 test11();
117 // wtf, why are these different?!
118 test12();
119 mongoose();
121 test13();
122 test14();
123 test15();
124 test16();
125 test17();
127 if (failed)
128 abort ();
130 return 0;