summaryrefslogtreecommitdiff
path: root/test/Sema
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2019-09-19 02:59:43 +0000
committerYonghong Song <yhs@fb.com>2019-09-19 02:59:43 +0000
commitbf89fb7d86986de60e99a96104c2cc97b3d56230 (patch)
treebbcd189ce0c95278a082df3cbac623aaee74b1fc /test/Sema
parenta1445cd0340006d7635101c4c2b27ae51328642c (diff)
downloadclang-bf89fb7d86986de60e99a96104c2cc97b3d56230.tar.gz
[CLANG][BPF] change __builtin_preserve_access_index() signature
The clang intrinsic __builtin_preserve_access_index() currently has signature: const void * __builtin_preserve_access_index(const void * ptr) This may cause compiler warning when: - parameter type is "volatile void *" or "const volatile void *", or - the assign-to type of the intrinsic does not have "const" qualifier. Further, this signature does not allow dereference of the builtin result pointer as it is a "const void *" type, which adds extra step for the user to do type casting. Let us change the signature to: PointerT __builtin_preserve_access_index(PointerT ptr) such that the result and argument types are the same. With this, directly dereferencing the builtin return value becomes possible. Differential Revision: https://reviews.llvm.org/D67734 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372294 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema')
-rw-r--r--test/Sema/builtin-preserve-access-index.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/test/Sema/builtin-preserve-access-index.c b/test/Sema/builtin-preserve-access-index.c
index c10ceb5145..71da8457fa 100644
--- a/test/Sema/builtin-preserve-access-index.c
+++ b/test/Sema/builtin-preserve-access-index.c
@@ -4,10 +4,28 @@ const void *invalid1(const int *arg) {
return __builtin_preserve_access_index(&arg[1], 1); // expected-error {{too many arguments to function call, expected 1, have 2}}
}
-void *invalid2(const int *arg) {
- return __builtin_preserve_access_index(&arg[1]); // expected-warning {{returning 'const void *' from a function with result type 'void *' discards qualifiers}}
+const void *invalid2(const int *arg) {
+ return __builtin_preserve_access_index(1); // expected-error {{__builtin_preserve_access_index argument must a pointer type instead of 'int'}}
}
-const void *invalid3(const int *arg) {
- return __builtin_preserve_access_index(1); // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *'}}
+void *invalid3(const int *arg) {
+ return __builtin_preserve_access_index(&arg[1]); // expected-warning {{returning 'const int *' from a function with result type 'void *' discards qualifiers}}
+}
+
+const void *invalid4(volatile const int *arg) {
+ return __builtin_preserve_access_index(arg); // expected-warning {{returning 'const volatile int *' from a function with result type 'const void *' discards qualifiers}}
+}
+
+int *valid5(int *arg) {
+ return __builtin_preserve_access_index(arg);
+}
+
+int valid6(const volatile int *arg) {
+ return *__builtin_preserve_access_index(arg);
+}
+
+struct s { int a; int b; };
+
+int valid7(struct s *arg) {
+ return *__builtin_preserve_access_index(&arg->b);
}