1 #define _GLIBCXX_USE_CXX11_ABI 0
2 #define __STDC_FORMAT_MACROS
10 #include "../memcheck.h"
11 // Derived from test provided by Timur Iskhodzhanov (bug 280271)
19 { fprintf(stderr
, "destruct MyClass\n");
23 // Two hierarchies using MI, one with no fields,
24 // the other one with some data.
28 { fprintf(stderr
, "destruct Ae\n");
34 { fprintf(stderr
, "destruct Be\n");
37 struct Ce
: public Ae
, public Be
40 { fprintf(stderr
, "destruct Ce\n");
51 { fprintf(stderr
, "destruct A\n");
61 { fprintf(stderr
, "destruct B\n");
64 struct C
: public A
, public B
71 { fprintf(stderr
, "destruct C\n");
75 void* wrap64_malloc(int size
)
77 uint64_t *p
= (uint64_t*)malloc(size
+ 8);
83 void wrap64_free(void *p
)
85 uint64_t *p2
= (uint64_t*)p
;
102 char who_points_at_cmd
[100];
106 str
= "Valgrind"; // interior ptr.
108 ptr
= new MyClass
[3]; // interior ptr.
109 ptr64
= wrap64_malloc(23);
111 // prepare the who_points_at cmd we will run.
112 // Do it here to avoid having ptr or its exterior ptr kept in a register.
113 sprintf(who_points_at_cmd
, "who_points_at %#" PRIxPTR
" 20",
114 (uintptr_t) (char*)ptr
- sizeof(void*));
116 ptr2
= new MyClass
[0]; // "interior but exterior ptr".
117 // ptr2 points after the chunk, is wrongly considered by memcheck as definitely leaked.
119 ptrBCe
= new Ce
; // interior ptr.
120 ptrACe
= new Ce
; // not an interior pointer.
121 ptrBC
= new C
; // interior ptr.
122 ptrAC
= new C
; // not an interior pointer.
125 str2
+= " rocks (str2)\n"; // interior ptr.
132 (void) VALGRIND_MONITOR_COMMAND("v.set log_output");
134 fprintf(stderr
, "VALGRIND_DO_LEAK_CHECK\n");
135 VALGRIND_DO_LEAK_CHECK
; // All possible leaks should be detected, giving only reachable data.
137 // Check individually each heuristic
138 fprintf(stderr
, "leak_check summary heuristics multipleinheritance\n");
139 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics multipleinheritance");
140 fprintf(stderr
, "leak_check summary any heuristics newarray\n");
141 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics newarray");
142 fprintf(stderr
, "leak_check summary heuristics length64\n");
143 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics length64");
144 fprintf(stderr
, "leak_check summary heuristics stdstring\n");
145 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics stdstring");
147 // check all and none
148 fprintf(stderr
, "leak_check summary heuristics multipleinheritance,newarray,stdstring,length64\n");
149 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics multipleinheritance,newarray,stdstring,length64");
150 fprintf(stderr
, "leak_check summary heuristics all\n");
151 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics all");
152 fprintf(stderr
, "leak_check summary heuristics none\n");
153 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics none");
155 // Test the who_points_at when the block is pointed to with an interior ptr.
156 (void) VALGRIND_MONITOR_COMMAND(who_points_at_cmd
);
165 fprintf(stderr
, "Finished!\n");