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];
103 char who_points_at_cmd_brackets
[100]; /* Same but with brackets. */
107 str
= "Valgrind"; // interior ptr.
109 ptr
= new MyClass
[3]; // interior ptr.
110 ptr64
= wrap64_malloc(23);
112 // prepare the who_points_at cmd we will run.
113 // Do it here to avoid having ptr or its exterior ptr kept in a register.
114 sprintf(who_points_at_cmd
, "who_points_at %#" PRIxPTR
" 20",
115 (uintptr_t) (char*)ptr
- sizeof(void*));
116 sprintf(who_points_at_cmd_brackets
, "who_points_at %#" PRIxPTR
"[20]",
117 (uintptr_t) (char*)ptr
- sizeof(void*));
119 ptr2
= new MyClass
[0]; // "interior but exterior ptr".
120 // ptr2 points after the chunk, is wrongly considered by memcheck as definitely leaked.
122 ptrBCe
= new Ce
; // interior ptr.
123 ptrACe
= new Ce
; // not an interior pointer.
124 ptrBC
= new C
; // interior ptr.
125 ptrAC
= new C
; // not an interior pointer.
128 str2
+= " rocks (str2)\n"; // interior ptr.
135 (void) VALGRIND_MONITOR_COMMAND("v.set log_output");
137 fprintf(stderr
, "VALGRIND_DO_LEAK_CHECK\n");
138 VALGRIND_DO_LEAK_CHECK
; // All possible leaks should be detected, giving only reachable data.
140 // Check individually each heuristic
141 fprintf(stderr
, "leak_check summary heuristics multipleinheritance\n");
142 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics multipleinheritance");
143 fprintf(stderr
, "leak_check summary any heuristics newarray\n");
144 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics newarray");
145 fprintf(stderr
, "leak_check summary heuristics length64\n");
146 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics length64");
147 fprintf(stderr
, "leak_check summary heuristics stdstring\n");
148 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics stdstring");
150 // check all and none
151 fprintf(stderr
, "leak_check summary heuristics multipleinheritance,newarray,stdstring,length64\n");
152 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics multipleinheritance,newarray,stdstring,length64");
153 fprintf(stderr
, "leak_check summary heuristics all\n");
154 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics all");
155 fprintf(stderr
, "leak_check summary heuristics none\n");
156 (void) VALGRIND_MONITOR_COMMAND("leak_check summary heuristics none");
158 // Test the who_points_at when the block is pointed to with an interior ptr.
159 (void) VALGRIND_MONITOR_COMMAND(who_points_at_cmd
);
160 // Same but with the bracket syntax.
161 (void) VALGRIND_MONITOR_COMMAND(who_points_at_cmd_brackets
);
170 fprintf(stderr
, "Finished!\n");