1// REQUIRES: sunrpc
2
3// RUN: %clangxx_msan -g -O0 -DTYPE=int -DFN=xdr_int %s -o %t && \
4// RUN: %run %t 2>&1
5// RUN: %clangxx_msan -g -O0 -DTYPE=int -DFN=xdr_int -DUNINIT=1 %s -o %t && \
6// RUN: not %run %t 2>&1 | FileCheck %s
7// RUN: %clangxx_msan -g -O0 -DTYPE=double -DFN=xdr_double %s -o %t && \
8// RUN: %run %t 2>&1
9// RUN: %clangxx_msan -g -O0 -DTYPE=double -DFN=xdr_double -DUNINIT=1 %s -o %t && \
10// RUN: not %run %t 2>&1 | FileCheck %s
11// RUN: %clangxx_msan -g -O0 -DTYPE=u_quad_t -DFN=xdr_u_longlong_t %s -o %t && \
12// RUN: %run %t 2>&1
13// RUN: %clangxx_msan -g -O0 -DTYPE=u_quad_t -DFN=xdr_u_longlong_t -DUNINIT=1 %s -o %t && \
14// RUN: not %run %t 2>&1 | FileCheck %s
15
16#include <assert.h>
17#include <rpc/xdr.h>
18
19#include <sanitizer/msan_interface.h>
20
21int main(int argc, char *argv[]) {
22 XDR xdrs;
23 char buf[100];
24 xdrmem_create(&xdrs, buf, sizeof(buf), XDR_ENCODE);
25 TYPE x;
26#ifndef UNINIT
27 x = 42;
28#endif
29 bool_t res = FN(&xdrs, &x);
30 // CHECK: MemorySanitizer: use-of-uninitialized-value
31 // CHECK: {{in main.*sunrpc.cpp:}}[[@LINE-2]]
32 assert(res == TRUE);
33 xdr_destroy(&xdrs);
34
35 xdrmem_create(&xdrs, buf, sizeof(buf), XDR_DECODE);
36 TYPE y;
37 res = FN(&xdrs, &y);
38 assert(res == TRUE);
39 assert(__msan_test_shadow(&y, sizeof(y)) == -1);
40 xdr_destroy(&xdrs);
41 return 0;
42}
43

source code of compiler-rt/test/msan/Linux/sunrpc.cpp