brintos

brintos / llvm-project-archived public Read only

0
0
Text · 697 B · 944328e Raw
23 lines · c
1// RUN: %check_clang_tidy -std=c11-or-later %s bugprone-sizeof-expression %t2 3#define alignof(type_name) _Alignof(type_name)4extern void sink(const void *P);5 6enum { BufferSize = 1024 };7 8struct S {9  long A, B, C;10};11 12void bad4d(void) {13  struct S Buffer[BufferSize];14 15  struct S *P = &Buffer[0];16  struct S *Q = P;17  while (Q < P + alignof(Buffer)) {18    // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: suspicious usage of 'alignof(...)' in pointer arithmetic; this scaled value will be scaled again by the '+' operator [bugprone-sizeof-expression]19    // CHECK-MESSAGES: :[[@LINE-2]]:16: note: '+' in pointer arithmetic internally scales with 'sizeof(struct S)' == {{[0-9]+}}20    sink(Q++);21  }22}23