Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / Linux / b64.cpp
blob39f3d8cf0da0ff321770b1b0e7f8f4e0eb734982
1 // RUN: %clangxx_msan -O0 %s -o %t && %run %t
2 // RUN: not %run %t NTOP_READ 2>&1 | FileCheck %s --check-prefix=NTOP_READ
3 // RUN: not %run %t PTON_READ 2>&1 | FileCheck %s --check-prefix=PTON_READ
5 #include <assert.h>
6 #include <resolv.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/types.h>
11 #include <sanitizer/msan_interface.h>
13 int main(int iArgc, char *szArgv[]) {
14 char* test = nullptr;
15 if (iArgc > 1) {
16 test = szArgv[1];
19 if (test == nullptr) {
20 // Check NTOP writing
21 const char *src = "base64 test data";
22 size_t src_len = strlen(src);
23 size_t dst_len = ((src_len + 2) / 3) * 4 + 1;
24 char dst[dst_len];
25 int res = b64_ntop(reinterpret_cast<const unsigned char *>(src), src_len,
26 dst, dst_len);
27 assert(res >= 0);
28 __msan_check_mem_is_initialized(dst, res);
30 // Check PTON writing
31 unsigned char target[dst_len];
32 res = b64_pton(dst, target, dst_len);
33 assert(res >= 0);
34 __msan_check_mem_is_initialized(target, res);
36 // Check NTOP writing for zero length src
37 src = "";
38 src_len = strlen(src);
39 assert(((src_len + 2) / 3) * 4 + 1 < dst_len);
40 res = b64_ntop(reinterpret_cast<const unsigned char *>(src), src_len,
41 dst, dst_len);
42 assert(res >= 0);
43 __msan_check_mem_is_initialized(dst, res);
45 // Check PTON writing for zero length src
46 dst[0] = '\0';
47 res = b64_pton(dst, target, dst_len);
48 assert(res >= 0);
49 __msan_check_mem_is_initialized(target, res);
51 return 0;
54 if (strcmp(test, "NTOP_READ") == 0) {
55 // Check NTOP reading
56 size_t src_len = 80;
57 char src[src_len];
58 __msan_poison(src, src_len);
59 size_t dst_len = ((src_len + 2) / 3) * 4 + 1;
60 char dst[dst_len];
61 int res = b64_ntop(reinterpret_cast<const unsigned char *>(src), src_len,
62 dst, dst_len);
63 // NTOP_READ: Uninitialized bytes in __b64_ntop
64 return 0;
67 if (strcmp(test, "PTON_READ") == 0) {
68 // Check PTON reading
69 size_t src_len = 80;
70 char src[src_len];
71 strcpy(src, "junk longer than zero");
72 // pretend it is uninitialized
73 __msan_poison(src, src_len);
74 unsigned char target[src_len];
75 int res = b64_pton(src, target, src_len);
76 // PTON_READ: Uninitialized bytes in __b64_pton
77 return 0;
80 return 0;