| 1 |
// RUN: %clang_cc1 -x c -triple x86_64-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
const void *invalid1(const int *arg) { |
| 4 |
return __builtin_preserve_access_index(&arg[1], 1); // expected-error {{too many arguments to function call, expected 1, have 2}} |
| 5 |
} |
| 6 |
|
| 7 |
int valid2(void) { |
| 8 |
return __builtin_preserve_access_index(1); |
| 9 |
} |
| 10 |
|
| 11 |
void *invalid3(const int *arg) { |
| 12 |
return __builtin_preserve_access_index(&arg[1]); // expected-warning {{returning 'const int *' from a function with result type 'void *' discards qualifiers}} |
| 13 |
} |
| 14 |
|
| 15 |
const void *invalid4(volatile const int *arg) { |
| 16 |
return __builtin_preserve_access_index(arg); // expected-warning {{returning 'const volatile int *' from a function with result type 'const void *' discards qualifiers}} |
| 17 |
} |
| 18 |
|
| 19 |
int *valid5(int *arg) { |
| 20 |
return __builtin_preserve_access_index(arg); |
| 21 |
} |
| 22 |
|
| 23 |
int valid6(const volatile int *arg) { |
| 24 |
return *__builtin_preserve_access_index(arg); |
| 25 |
} |
| 26 |
|
| 27 |
struct s { int a; int b; }; |
| 28 |
|
| 29 |
int valid7(struct s *arg) { |
| 30 |
return *__builtin_preserve_access_index(&arg->b); |
| 31 |
} |
| 32 |
|
| 33 |
int valid8(struct s *arg) { |
| 34 |
return __builtin_preserve_access_index(arg->a + arg->b); |
| 35 |
} |
| 36 |
|
| 37 |
int valid9(struct s *arg) { |
| 38 |
return __builtin_preserve_access_index(({arg->a = 2; arg->b = 3; })); |
| 39 |
} |