summaryrefslogtreecommitdiffstats
path: root/test/CodeGenCXX/alloc-size.cpp
diff options
context:
space:
mode:
authorJoel E. Denny <dennyje@ornl.gov>2018-03-02 19:03:22 +0000
committerJoel E. Denny <dennyje@ornl.gov>2018-03-02 19:03:22 +0000
commitaafdf027119f8fc6fd825b765905a0158d4e5df8 (patch)
tree09f81581d11817615ab62dbb6cc0577b64368f47 /test/CodeGenCXX/alloc-size.cpp
parent12b35567426747f88bbcc4b6d47924b9061d5e45 (diff)
[Attr] Fix parameter indexing for several attributes
The patch fixes a number of bugs related to parameter indexing in attributes: * Parameter indices in some attributes (argument_with_type_tag, pointer_with_type_tag, nonnull, ownership_takes, ownership_holds, and ownership_returns) are specified in source as one-origin including any C++ implicit this parameter, were stored as zero-origin excluding any this parameter, and were erroneously printing (-ast-print) and confusingly dumping (-ast-dump) as the stored values. * For alloc_size, the C++ implicit this parameter was not subtracted correctly in Sema, leading to assert failures or to silent failures of __builtin_object_size to compute a value. * For argument_with_type_tag, pointer_with_type_tag, and ownership_returns, the C++ implicit this parameter was not added back to parameter indices in some diagnostics. This patch fixes the above bugs and aims to prevent similar bugs in the future by introducing careful mechanisms for handling parameter indices in attributes. ParamIdx stores a parameter index and is designed to hide the stored encoding while providing accessors that require each use (such as printing) to make explicit the encoding that is needed. Attribute declarations declare parameter index arguments as [Variadic]ParamIdxArgument, which are exposed as ParamIdx[*]. This patch rewrites all attribute arguments that are processed by checkFunctionOrMethodParameterIndex in SemaDeclAttr.cpp to be declared as [Variadic]ParamIdxArgument. The only exception is xray_log_args's argument, which is encoded as a count not an index. Differential Revision: https://reviews.llvm.org/D43248 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326602 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/alloc-size.cpp')
-rw-r--r--test/CodeGenCXX/alloc-size.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/CodeGenCXX/alloc-size.cpp b/test/CodeGenCXX/alloc-size.cpp
index e93e231b70..137d4543dd 100644
--- a/test/CodeGenCXX/alloc-size.cpp
+++ b/test/CodeGenCXX/alloc-size.cpp
@@ -69,4 +69,22 @@ int testIt() {
__builtin_object_size(dependent_calloc<7, 8>(), 0) +
__builtin_object_size(dependent_calloc2<int, 9>(), 0);
}
+} // namespace templated_alloc_size
+
+class C {
+public:
+ void *my_malloc(int N) __attribute__((alloc_size(2)));
+ void *my_calloc(int N, int M) __attribute__((alloc_size(2, 3)));
+};
+
+// CHECK-LABEL: define i32 @_Z16callMemberMallocv
+int callMemberMalloc() {
+ // CHECK: ret i32 16
+ return __builtin_object_size(C().my_malloc(16), 0);
+}
+
+// CHECK-LABEL: define i32 @_Z16callMemberCallocv
+int callMemberCalloc() {
+ // CHECK: ret i32 32
+ return __builtin_object_size(C().my_calloc(16, 2), 0);
}