File: test_interpose.cpp

package info (click to toggle)
rocthrust 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,588 kB
  • sloc: cpp: 66,309; ansic: 34,184; python: 1,519; sh: 331; xml: 212; makefile: 115
file content (113 lines) | stat: -rw-r--r-- 4,109 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// MIT License
//
// Copyright (c) 2023-2024 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <cstdint>
#include <cstdlib>
#include <malloc.h>
#include <new>

extern "C" void* __libc_calloc(std::size_t, std::size_t);
extern "C" void  __libc_cfree(void*);
extern "C" void  __libc_free(void*);
extern "C" void* __libc_malloc(std::size_t);
extern "C" void* __libc_memalign(std::size_t, std::size_t);
extern "C" void* __libc_realloc(void*, std::size_t);
extern "C" int   __posix_memalign(void**, std::size_t, std::size_t);

int main()
{
    try
    {
        if(auto p = std::aligned_alloc(8u, 42))
            std::free(p);
        if(auto p = std::calloc(1, 42))
            std::free(p);
        if(auto p = std::malloc(42))
            std::free(p);
        if(auto p = memalign(8, 42))
            std::free(p);
        if(void* p; posix_memalign(&p, 8, 42) == 0)
            std::free(p);
        if(auto p = std::realloc(std::malloc(42), 42))
            std::free(p);
        if(auto p = reallocarray(std::calloc(1, 42), 1, 42))
            std::free(p);
        if(auto p = new std::uint8_t)
            delete p;
        if(auto p = new(std::align_val_t {8}) std::uint8_t)
        {
            ::operator delete(p, std::align_val_t {8});
        }
        if(auto p = new(std::nothrow) std::uint8_t)
            delete p;
        if(auto p = new(std::align_val_t {8}, std::nothrow) std::uint8_t)
        {
            ::operator delete(p, std::align_val_t {8});
        }
        if(auto p = new std::uint8_t[42])
            delete[] p;
        if(auto p = new(std::align_val_t {8}) std::uint8_t[42])
        {
            ::operator delete[](p, std::align_val_t {8});
        }
        if(auto p = new(std::nothrow) std::uint8_t[42])
            delete[] p;
        if(auto p = new(std::align_val_t {8}, std::nothrow) std::uint8_t[42])
        {
            ::operator delete[](p, std::align_val_t {8});
        }
        if(auto p = __builtin_calloc(1, 42))
            __builtin_free(p);
        if(auto p = __builtin_malloc(42))
            __builtin_free(p);
        if(auto p = __builtin_operator_new(42))
            __builtin_operator_delete(p);
        if(auto p = __builtin_operator_new(42, std::align_val_t {8}))
        {
            __builtin_operator_delete(p, std::align_val_t {8});
        }
        if(auto p = __builtin_operator_new(42, std::nothrow))
        {
            __builtin_operator_delete(p);
        }
        if(auto p = __builtin_operator_new(42, std::align_val_t {8}, std::nothrow))
        {
            __builtin_operator_delete(p, std::align_val_t {8});
        }
        if(auto p = __builtin_realloc(__builtin_malloc(42), 41))
        {
            __builtin_free(p);
        }
        if(auto p = __libc_calloc(1, 42))
            __libc_free(p);
        if(auto p = __libc_malloc(42))
            __libc_free(p);
        if(auto p = __libc_memalign(8, 42))
            __libc_free(p);
    }
    catch(...)
    {
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}