1*fb0ef6b6SCarlos Galvez // RUN: %check_clang_tidy %s bugprone-bitwise-pointer-cast %t 2*fb0ef6b6SCarlos Galvez 3*fb0ef6b6SCarlos Galvez void memcpy(void* to, void* dst, unsigned long long size) 4*fb0ef6b6SCarlos Galvez { 5*fb0ef6b6SCarlos Galvez // Dummy implementation for the purpose of the test 6*fb0ef6b6SCarlos Galvez } 7*fb0ef6b6SCarlos Galvez 8*fb0ef6b6SCarlos Galvez namespace std 9*fb0ef6b6SCarlos Galvez { 10*fb0ef6b6SCarlos Galvez using ::memcpy; 11*fb0ef6b6SCarlos Galvez } 12*fb0ef6b6SCarlos Galvez 13*fb0ef6b6SCarlos Galvez void pointer2pointer() 14*fb0ef6b6SCarlos Galvez { 15*fb0ef6b6SCarlos Galvez int x{}; 16*fb0ef6b6SCarlos Galvez int* px{}; 17*fb0ef6b6SCarlos Galvez float y{}; 18*fb0ef6b6SCarlos Galvez float* py{}; 19*fb0ef6b6SCarlos Galvez 20*fb0ef6b6SCarlos Galvez memcpy(&py, &px, sizeof(px)); 21*fb0ef6b6SCarlos Galvez // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use 'memcpy' to cast between pointers [bugprone-bitwise-pointer-cast] 22*fb0ef6b6SCarlos Galvez std::memcpy(&py, &px, sizeof(px)); 23*fb0ef6b6SCarlos Galvez // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use 'memcpy' to cast between pointers [bugprone-bitwise-pointer-cast] 24*fb0ef6b6SCarlos Galvez 25*fb0ef6b6SCarlos Galvez std::memcpy(&y, &x, sizeof(x)); 26*fb0ef6b6SCarlos Galvez } 27*fb0ef6b6SCarlos Galvez 28*fb0ef6b6SCarlos Galvez // Pointer-integer conversions are allowed by this check 29*fb0ef6b6SCarlos Galvez void int2pointer() 30*fb0ef6b6SCarlos Galvez { 31*fb0ef6b6SCarlos Galvez unsigned long long addr{}; 32*fb0ef6b6SCarlos Galvez float* p{}; 33*fb0ef6b6SCarlos Galvez std::memcpy(&p, &addr, sizeof(addr)); 34*fb0ef6b6SCarlos Galvez } 35*fb0ef6b6SCarlos Galvez 36*fb0ef6b6SCarlos Galvez void pointer2int() 37*fb0ef6b6SCarlos Galvez { 38*fb0ef6b6SCarlos Galvez unsigned long long addr{}; 39*fb0ef6b6SCarlos Galvez float* p{}; 40*fb0ef6b6SCarlos Galvez std::memcpy(&addr, &p, sizeof(p)); 41*fb0ef6b6SCarlos Galvez } 42