libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / plugin / copy_from_user-1.c
blob1acedc2e2ce8a77fd9d32d796f3a69b5cf800e40
1 /* { dg-do compile } */
2 /* { dg-options "-fanalyzer" } */
3 /* { dg-require-effective-target analyzer } */
5 typedef __SIZE_TYPE__ size_t;
7 #define __user
9 extern int copy_from_user(void *to, const void __user *from, long n)
10 __attribute__((access (write_only, 1, 3),
11 access (read_only, 2, 3)
12 ));
14 #define EFAULT 14
15 #define EINVAL 22
17 /* Taken from Linux: fs/binfmt_misc.c (GPL-2.0-only). */
19 int parse_command(const char __user *buffer, size_t count)
21 char s[4];
23 if (count > 3)
24 return -EINVAL;
25 if (copy_from_user(s, buffer, count))
26 return -EFAULT;
27 if (!count)
28 return 0;
29 if (s[count - 1] == '\n') /* { dg-bogus "uninit" } */
30 count--;
31 if (count == 1 && s[0] == '0') /* { dg-bogus "uninit" } */
32 return 1;
33 if (count == 1 && s[0] == '1') /* { dg-bogus "uninit" } */
34 return 2;
35 if (count == 2 && s[0] == '-' && s[1] == '1') /* { dg-bogus "uninit" } */
36 return 3;
37 return -EINVAL;
40 /* Not using return value from copy_from_user. */
42 int test_2 (const char __user *buffer, size_t count)
44 char s[4];
45 if (count > 3)
46 return -EINVAL;
47 copy_from_user(s, buffer, count);
48 return 0;