blob: 7f62449842cead897c73999eb9281f1e7bfae4bf [file] [log] [blame]
Evgeniy Stepanov96284be2013-05-31 12:04:08 +00001// Build a library with origin tracking and an executable w/o origin tracking.
2// Test that origin tracking is enabled at runtime.
Alexey Samsonovd06aa3d2015-03-02 19:34:27 +00003// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -DBUILD_SO -fPIC -shared -o %t-so.so
4// RUN: %clangxx_msan -O0 %s %t-so.so -o %t && not %run %t 2>&1 | FileCheck %s
Evgeniy Stepanov96284be2013-05-31 12:04:08 +00005
Alexey Samsonovefe78282014-07-07 20:37:12 +00006#ifdef BUILD_SO
7
Evgeniy Stepanov96284be2013-05-31 12:04:08 +00008#include <stdlib.h>
9
Alexey Samsonovefe78282014-07-07 20:37:12 +000010extern "C" {
11void my_access(int *p) {
12 volatile int tmp;
13 // Force initialize-ness check.
14 if (*p)
15 tmp = 1;
16}
17
18void *my_alloc(unsigned sz) {
19 return malloc(sz);
20}
21} // extern "C"
22
23#else // BUILD_SO
24
25#include <stdlib.h>
26
27extern "C" {
28void my_access(int *p);
29void *my_alloc(unsigned sz);
30}
Evgeniy Stepanov96284be2013-05-31 12:04:08 +000031
32int main(int argc, char **argv) {
33 int *x = (int *)my_alloc(sizeof(int));
34 my_access(x);
35 delete x;
36
37 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
Alexey Samsonovefe78282014-07-07 20:37:12 +000038 // CHECK: {{#0 0x.* in my_access .*dso-origin.cc:}}
Evgeniy Stepanov96284be2013-05-31 12:04:08 +000039 // CHECK: {{#1 0x.* in main .*dso-origin.cc:}}[[@LINE-5]]
40 // CHECK: Uninitialized value was created by a heap allocation
41 // CHECK: {{#0 0x.* in .*malloc}}
Alexey Samsonovefe78282014-07-07 20:37:12 +000042 // CHECK: {{#1 0x.* in my_alloc .*dso-origin.cc:}}
Evgeniy Stepanov96284be2013-05-31 12:04:08 +000043 // CHECK: {{#2 0x.* in main .*dso-origin.cc:}}[[@LINE-10]]
Alexey Samsonovefe78282014-07-07 20:37:12 +000044 // CHECK: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*dso-origin.cc:.* my_access}}
Evgeniy Stepanov96284be2013-05-31 12:04:08 +000045 return 0;
46}
Alexey Samsonovefe78282014-07-07 20:37:12 +000047
48#endif // BUILD_SO