xref: /aosp_15_r20/external/compiler-rt/test/msan/mktime.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
2*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -O0 -g -DUNINIT %s -o %t && not %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot 
4*7c3d14c8STreehugger Robot #include <assert.h>
5*7c3d14c8STreehugger Robot #include <time.h>
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot #include <sanitizer/msan_interface.h>
8*7c3d14c8STreehugger Robot 
main(void)9*7c3d14c8STreehugger Robot int main(void) {
10*7c3d14c8STreehugger Robot   struct tm tm;
11*7c3d14c8STreehugger Robot   tm.tm_year = 2014;
12*7c3d14c8STreehugger Robot   tm.tm_mon = 3;
13*7c3d14c8STreehugger Robot   tm.tm_mday = 28;
14*7c3d14c8STreehugger Robot #ifndef UNINIT
15*7c3d14c8STreehugger Robot   tm.tm_hour = 13;
16*7c3d14c8STreehugger Robot #endif
17*7c3d14c8STreehugger Robot   tm.tm_min = 4;
18*7c3d14c8STreehugger Robot   tm.tm_sec = 42;
19*7c3d14c8STreehugger Robot   tm.tm_isdst = -1;
20*7c3d14c8STreehugger Robot   time_t t = mktime(&tm);
21*7c3d14c8STreehugger Robot   // CHECK: MemorySanitizer: use-of-uninitialized-value
22*7c3d14c8STreehugger Robot   // CHECK: in main{{.*}}mktime.cc:[[@LINE-2]]
23*7c3d14c8STreehugger Robot   assert(t != -1);
24*7c3d14c8STreehugger Robot   assert(__msan_test_shadow(&tm, sizeof(tm)) == -1);
25*7c3d14c8STreehugger Robot   return 0;
26*7c3d14c8STreehugger Robot }
27