| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 
 | // 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
// RUN: %check_clang_tidy -check-suffixes=ALL,CXX %s bugprone-implicit-widening-of-multiplication-result %t -- -- -target x86_64-unknown-unknown -x c++
// RUN: %check_clang_tidy -check-suffixes=ALL,C -std=c99 %s bugprone-implicit-widening-of-multiplication-result %t -- \
// RUN:     -config='{CheckOptions: [ \
// RUN:         {key: bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources, value: false} \
// RUN:     ]}' -- -target x86_64-unknown-unknown -x c
// RUN: %check_clang_tidy -check-suffixes=ALL,C %s bugprone-implicit-widening-of-multiplication-result %t -- \
// RUN:     -config='{CheckOptions: [ \
// RUN:         {key: bugprone-implicit-widening-of-multiplication-result.UseCXXStaticCastsInCppSources, value: false} \
// RUN:     ]}' -- -target x86_64-unknown-unknown -x c++
char *t0(char *base, int a, int b) {
  return &base[a * b];
  // CHECK-NOTES-ALL: :[[@LINE-1]]:11: warning: result of multiplication in type 'int' is used as a pointer offset after an implicit widening conversion to type 'ptrdiff_t'
  // CHECK-NOTES-ALL: :[[@LINE-2]]:16: note: make conversion explicit to silence this warning
  // CHECK-NOTES-C:                    (ptrdiff_t)( )
  // CHECK-NOTES-CXX:                  static_cast<ptrdiff_t>( )
  // CHECK-NOTES-ALL: :[[@LINE-5]]:16: note: perform multiplication in a wider type
  // CHECK-NOTES-C:                    (ptrdiff_t)
  // CHECK-NOTES-CXX:                  static_cast<ptrdiff_t>()
}
void *t1(char *base, int a, int b) {
  return &((a * b)[base]);
  // CHECK-NOTES-ALL: :[[@LINE-1]]:12: warning: result of multiplication in type 'int' is used as a pointer offset after an implicit widening conversion to type 'ptrdiff_t'
  // CHECK-NOTES-ALL: :[[@LINE-2]]:13: note: make conversion explicit to silence this warning
  // CHECK-NOTES-ALL: :[[@LINE-3]]:13: note: perform multiplication in a wider type
}
char *t2(char *base, unsigned int a, int b) {
  return &base[a * b];
  // CHECK-NOTES-ALL: :[[@LINE-1]]:11: warning: result of multiplication in type 'unsigned int' is used as a pointer offset after an implicit widening conversion to type 'size_t'
  // CHECK-NOTES-ALL: :[[@LINE-2]]:16: note: make conversion explicit to silence this warning
  // CHECK-NOTES-C:                    (size_t)
  // CHECK-NOTES-CXX:                  static_cast<size_t>( )
  // CHECK-NOTES-ALL: :[[@LINE-5]]:16: note: perform multiplication in a wider type
  // CHECK-NOTES-C:                    (size_t)
  // CHECK-NOTES-CXX:                  static_cast<size_t>()
}
char *t3(char *base, int a, unsigned int b) {
  return &base[a * b];
  // CHECK-NOTES-ALL: :[[@LINE-1]]:11: warning: result of multiplication in type 'unsigned int' is used as a pointer offset after an implicit widening conversion to type 'size_t'
  // CHECK-NOTES-ALL: :[[@LINE-2]]:16: note: make conversion explicit to silence this warning
  // CHECK-NOTES-ALL: :[[@LINE-3]]:16: note: perform multiplication in a wider type
}
char *t4(char *base, unsigned int a, unsigned int b) {
  return &base[a * b];
  // CHECK-NOTES-ALL: :[[@LINE-1]]:11: warning: result of multiplication in type 'unsigned int' is used as a pointer offset after an implicit widening conversion to type 'size_t'
  // CHECK-NOTES-ALL: :[[@LINE-2]]:16: note: make conversion explicit to silence this warning
  // CHECK-NOTES-ALL: :[[@LINE-3]]:16: note: perform multiplication in a wider type
}
char *n5(char *base, int a, int b, int c) {
  return &base[a * b + c];
}
char *n6(char *base, int a, int b, int c) {
  return &base[a + b * c];
}
char *t7(char *base, int a, int b) {
  return &base[(a * b)];
  // CHECK-NOTES-ALL: :[[@LINE-1]]:11: warning: result of multiplication in type 'int' is used as a pointer offset after an implicit widening conversion to type 'ptrdiff_t'
  // CHECK-NOTES-ALL: :[[@LINE-2]]:17: note: make conversion explicit to silence this warning
  // CHECK-NOTES-ALL: :[[@LINE-3]]:17: note: perform multiplication in a wider type
}
char *n8(char *base, int a, int b, int c) {
  return &base[(a * b + c)];
}
char *n9(char *base, int a, int b, int c) {
  return &base[(a * b) + c];
}
char *n10(char *base, int a, int b) {
  return &base[(long)(a * b)];
}
char *n11(char *base, int a, int b) {
  return &base[(unsigned long)(a * b)];
}
#ifdef __cplusplus
template <typename T>
char *template_test(char *base, T a, T b) {
  return &base[a * b];
}
char *template_test_instantiation(char *base, int a, int b) {
  return template_test(base, a, b);
}
#endif
 |