1 // RUN: %check_clang_tidy %s performance-no-int-to-ptr %t
2 
3 // can't implicitly cast int to a pointer.
4 // can't use static_cast<>() to cast integer to a pointer.
5 // can't use dynamic_cast<>() to cast integer to a pointer.
6 // can't use const_cast<>() to cast integer to a pointer.
7 
t0(long long int x)8 void *t0(long long int x) {
9   return (void *)x;
10   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
11 }
12 
t1(int x)13 void *t1(int x) {
14   return reinterpret_cast<void *>(x);
15   // CHECK-MESSAGES: [[@LINE-1]]:10: warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
16 }
17 
18 // Don't diagnose casts from integer literals.
19 // It's a widely-used technique in embedded/microcontroller/hardware interfacing.
t3(long long int x)20 void *t3(long long int x) {
21   return (void *)0xFEEDFACE;
22 }
23