Expand Up
@@ -77,7 +77,7 @@ int Test1(const char* ptr) {
sum += sizeof (LEN + 1 );
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(K)'
sum += sizeof (sum, LEN);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(..., ...)'
// CHECK-MESSAGES: :[[@LINE-1]]:20 : warning: suspicious usage of 'sizeof(..., ...)'
sum += sizeof (AsBool ());
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer
sum += sizeof (AsInt ());
Expand All
@@ -103,41 +103,41 @@ int Test1(const char* ptr) {
sum += sizeof (LEN + - + -sizeof (X));
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(sizeof(...))'
sum += sizeof (char ) / sizeof (char );
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-1]]:23 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
sum += sizeof (A) / sizeof (S);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
// CHECK-MESSAGES: :[[@LINE-1]]:20 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
sum += sizeof (char ) / sizeof (int );
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
// CHECK-MESSAGES: :[[@LINE-1]]:23 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
sum += sizeof (char ) / sizeof (A);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
// CHECK-MESSAGES: :[[@LINE-1]]:23 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
sum += sizeof (B[0 ]) / sizeof (A);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
// CHECK-MESSAGES: :[[@LINE-1]]:23 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
sum += sizeof (ptr) / sizeof (char );
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
sum += sizeof (ptr) / sizeof (ptr[0 ]);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
sum += sizeof (ptr) / sizeof (char *);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
sum += sizeof (ptr) / sizeof (void *);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
sum += sizeof (ptr) / sizeof (const void volatile *);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
sum += sizeof (ptr) / sizeof (char );
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
sum += sizeof (ptr) / sizeof (ptr[0 ]);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
sum += sizeof (int ) * sizeof (char );
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious 'sizeof' by 'sizeof' multiplication
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious 'sizeof' by 'sizeof' multiplication
sum += sizeof (ptr) * sizeof (ptr[0 ]);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious 'sizeof' by 'sizeof' multiplication
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious 'sizeof' by 'sizeof' multiplication
sum += sizeof (int ) * (2 * sizeof (char ));
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious 'sizeof' by 'sizeof' multiplication
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious 'sizeof' by 'sizeof' multiplication
sum += (2 * sizeof (char )) * sizeof (int );
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious 'sizeof' by 'sizeof' multiplication
// CHECK-MESSAGES: :[[@LINE-1]]:29 : warning: suspicious 'sizeof' by 'sizeof' multiplication
if (sizeof (A) < 0x100000 ) sum += 42 ;
// CHECK-MESSAGES: :[[@LINE-1]]:7 : warning: suspicious comparison of 'sizeof(expr)' to a constant
// CHECK-MESSAGES: :[[@LINE-1]]:17 : warning: suspicious comparison of 'sizeof(expr)' to a constant
if (sizeof (A) <= 0xFFFFFFFEU ) sum += 42 ;
// CHECK-MESSAGES: :[[@LINE-1]]:7 : warning: suspicious comparison of 'sizeof(expr)' to a constant
// CHECK-MESSAGES: :[[@LINE-1]]:17 : warning: suspicious comparison of 'sizeof(expr)' to a constant
return sum;
}
Expand All
@@ -158,11 +158,11 @@ int CE4 = sizeof sizeof(MyConstChar);
int Test2 (MyConstChar* A) {
int sum = 0 ;
sum += sizeof (MyConstChar) / sizeof (char );
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-1]]:30 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
sum += sizeof (MyConstChar) / sizeof (MyChar);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-1]]:30 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
sum += sizeof (A[0 ]) / sizeof (char );
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-1]]:23 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
return sum;
}
Expand All
@@ -171,7 +171,7 @@ int Foo() { int A[T]; return sizeof(T); }
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of 'sizeof(K)'
template <typename T>
int Bar () { T A[5 ]; return sizeof (A[0 ]) / sizeof (T); }
// CHECK-MESSAGES: :[[@LINE-1]]:28 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-1]]:41 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
int Test3 () { return Foo<42 >() + Bar<char >(); }
static const char * kABC = " abc" ;
Expand Down
Expand Up
@@ -246,10 +246,10 @@ int Test5() {
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
sum += sizeof (PC) / sizeof (PtrArray[0 ]);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
// CHECK-MESSAGES: :[[@LINE-2]]:10 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-2]]:21 : warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
// CHECK-MESSAGES: :[[@LINE-3]]:23: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
sum += sizeof (ArrayC) / sizeof (PtrArray[0 ]);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
// CHECK-MESSAGES: :[[@LINE-1]]:25 : warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
// CHECK-MESSAGES: :[[@LINE-2]]:27: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
return sum;
Expand All
@@ -263,34 +263,34 @@ int Test6() {
sum += sizeof (struct S ) == P - Q;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
sum += 5 * sizeof (S) != P - Q;
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
// CHECK-MESSAGES: :[[@LINE-1]]:14 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
sum += sizeof (S) < P - Q;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
sum += 5 * sizeof (S) <= P - Q;
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
// CHECK-MESSAGES: :[[@LINE-1]]:14 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
sum += 5 * sizeof (*P) >= P - Q;
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
// CHECK-MESSAGES: :[[@LINE-1]]:14 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
sum += Q - P > 3 * sizeof (*P);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
// CHECK-MESSAGES: :[[@LINE-1]]:22 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
sum += sizeof (S) + (P - Q);
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
sum += 5 * sizeof (S) - (P - Q);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
// CHECK-MESSAGES: :[[@LINE-1]]:14 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
sum += (P - Q) / sizeof (S);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
// CHECK-MESSAGES: :[[@LINE-1]]:20 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
sum += (P - Q) / sizeof (*Q);
// CHECK-MESSAGES: :[[@LINE-1]]:10 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
// CHECK-MESSAGES: :[[@LINE-1]]:20 : warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
return sum;
}
#ifdef __SIZEOF_INT128__
template <__int128_t N>
template <__int128_t N>
#else
template <long N> // Fallback for platforms which do not define `__int128_t`
#endif
bool Baz () { return sizeof (A) < N; }
// CHECK-MESSAGES: :[[@LINE-1]]:21 : warning: suspicious comparison of 'sizeof(expr)' to a constant
// CHECK-MESSAGES: :[[@LINE-1]]:31 : warning: suspicious comparison of 'sizeof(expr)' to a constant
bool Test7 () { return Baz<-1 >(); }
int ValidExpressions () {
Expand Down