| 1 |
// RUN: %check_clang_tidy -check-suffixes=ALL,C -std=c99 %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64-unknown-unknown -x c |
| 2 |
// RUN: %check_clang_tidy -check-suffixes=ALL,CXX %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64-unknown-unknown -x c++ |
| 3 |
|
| 4 |
// RUN: %check_clang_tidy -check-suffixes=ALL,C -std=c99 %s bugprone-implicit-widening-of-multiplication-result %t -- \ |
| 5 |
// RUN: -config='{CheckOptions: { \ |
| 6 |
// RUN: bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources: false \ |
| 7 |
// RUN: }}' -- -target x86_64-unknown-unknown -x c |
| 8 |
// RUN: %check_clang_tidy -check-suffixes=ALL,C %s bugprone-implicit-widening-of-multiplication-result %t -- \ |
| 9 |
// RUN: -config='{CheckOptions: { \ |
| 10 |
// RUN: bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources: false \ |
| 11 |
// RUN: }}' -- -target x86_64-unknown-unknown -x c++ |
| 12 |
|
| 13 |
long t0(int a, int b) { |
| 14 |
return a * b; |
| 15 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'int' |
| 16 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning |
| 17 |
// CHECK-NOTES-C: (long)( ) |
| 18 |
// CHECK-NOTES-CXX: static_cast<long>( ) |
| 19 |
// CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type |
| 20 |
// CHECK-NOTES-C: (long) |
| 21 |
// CHECK-NOTES-CXX: static_cast<long>( ) |
| 22 |
} |
| 23 |
unsigned long t1(int a, int b) { |
| 24 |
return a * b; |
| 25 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'unsigned long' of a multiplication performed in type 'int' |
| 26 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning |
| 27 |
// CHECK-NOTES-C: (unsigned long)( ) |
| 28 |
// CHECK-NOTES-CXX: static_cast<unsigned long>( ) |
| 29 |
// CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type |
| 30 |
// CHECK-NOTES-C: (long) |
| 31 |
// CHECK-NOTES-CXX: static_cast<long>( ) |
| 32 |
} |
| 33 |
|
| 34 |
long t2(unsigned int a, int b) { |
| 35 |
return a * b; |
| 36 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'unsigned int' |
| 37 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning |
| 38 |
// CHECK-NOTES-C: (long)( ) |
| 39 |
// CHECK-NOTES-CXX: static_cast<long>( ) |
| 40 |
// CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type |
| 41 |
// CHECK-NOTES-C: (unsigned long) |
| 42 |
// CHECK-NOTES-CXX: static_cast<unsigned long>( ) |
| 43 |
} |
| 44 |
unsigned long t3(unsigned int a, int b) { |
| 45 |
return a * b; |
| 46 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'unsigned long' of a multiplication performed in type 'unsigned int' |
| 47 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning |
| 48 |
// CHECK-NOTES-C: (unsigned long)( ) |
| 49 |
// CHECK-NOTES-CXX: static_cast<unsigned long>( ) |
| 50 |
// CHECK-NOTES-ALL: :[[@LINE-5]]:10: note: perform multiplication in a wider type |
| 51 |
// CHECK-NOTES-C: (unsigned long) |
| 52 |
// CHECK-NOTES-CXX: static_cast<unsigned long>( ) |
| 53 |
} |
| 54 |
|
| 55 |
long t4(int a, unsigned int b) { |
| 56 |
return a * b; |
| 57 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'unsigned int' |
| 58 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning |
| 59 |
// CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type |
| 60 |
} |
| 61 |
unsigned long t5(int a, unsigned int b) { |
| 62 |
return a * b; |
| 63 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'unsigned long' of a multiplication performed in type 'unsigned int' |
| 64 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning |
| 65 |
// CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type |
| 66 |
} |
| 67 |
|
| 68 |
long t6(unsigned int a, unsigned int b) { |
| 69 |
return a * b; |
| 70 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'unsigned int' |
| 71 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning |
| 72 |
// CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type |
| 73 |
} |
| 74 |
unsigned long t7(unsigned int a, unsigned int b) { |
| 75 |
return a * b; |
| 76 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'unsigned long' of a multiplication performed in type 'unsigned int' |
| 77 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning |
| 78 |
// CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type |
| 79 |
} |
| 80 |
|
| 81 |
long t8(int a, int b) { |
| 82 |
return (a * b); |
| 83 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:11: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'int' |
| 84 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:11: note: make conversion explicit to silence this warning |
| 85 |
// CHECK-NOTES-ALL: :[[@LINE-3]]:11: note: perform multiplication in a wider type |
| 86 |
} |
| 87 |
long t9(int a, int b) { |
| 88 |
return (a)*b; |
| 89 |
// CHECK-NOTES-ALL: :[[@LINE-1]]:10: warning: performing an implicit widening conversion to type 'long' of a multiplication performed in type 'int' |
| 90 |
// CHECK-NOTES-ALL: :[[@LINE-2]]:10: note: make conversion explicit to silence this warning |
| 91 |
// CHECK-NOTES-ALL: :[[@LINE-3]]:10: note: perform multiplication in a wider type |
| 92 |
} |
| 93 |
long n10(int a, int b) { |
| 94 |
return (long)(a * b); |
| 95 |
} |
| 96 |
long n11(int a, int b) { |
| 97 |
return (unsigned long)(a * b); |
| 98 |
} |
| 99 |
|
| 100 |
long n12(long a, int b) { |
| 101 |
return a * b; |
| 102 |
} |
| 103 |
long n13(int a, long b) { |
| 104 |
return a * b; |
| 105 |
} |
| 106 |
|
| 107 |
long n14(int a, int b, int c) { |
| 108 |
return a + b * c; |
| 109 |
} |
| 110 |
long n15(int a, int b, int c) { |
| 111 |
return a * b + c; |
| 112 |
} |
| 113 |
|
| 114 |
#ifdef __cplusplus |
| 115 |
template <typename T1, typename T2> |
| 116 |
T2 template_test(T1 a, T1 b) { |
| 117 |
return a * b; |
| 118 |
} |
| 119 |
long template_test_instantiation(int a, int b) { |
| 120 |
return template_test<int, long>(a, b); |
| 121 |
} |
| 122 |
#endif |